1 /**
2 A $(D Resource) that contains vertex-array based geometry.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.mesh;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.resource;
23 import godot.material;
24 import godot.shape;
25 import godot.trianglemesh;
26 import godot.reference;
27 /**
28 A $(D Resource) that contains vertex-array based geometry.
29 
30 Mesh is a type of $(D Resource) that contains vertex-array based geometry, divided in $(I surfaces). Each surface contains a completely separate array and a material used to draw it. Design wise, a mesh with multiple surfaces is preferred to a single surface, because objects created in 3D editing software commonly contain multiple materials.
31 */
32 @GodotBaseClass struct Mesh
33 {
34 	enum string _GODOT_internal_name = "Mesh";
35 public:
36 @nogc nothrow:
37 	union { godot_object _godot_object; Resource _GODOT_base; }
38 	alias _GODOT_base this;
39 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
40 	package(godot) __gshared bool _classBindingInitialized = false;
41 	package(godot) static struct _classBinding
42 	{
43 		__gshared:
44 		@GodotName("set_lightmap_size_hint") GodotMethod!(void, Vector2) setLightmapSizeHint;
45 		@GodotName("get_lightmap_size_hint") GodotMethod!(Vector2) getLightmapSizeHint;
46 		@GodotName("get_surface_count") GodotMethod!(long) getSurfaceCount;
47 		@GodotName("surface_get_arrays") GodotMethod!(Array, long) surfaceGetArrays;
48 		@GodotName("surface_get_blend_shape_arrays") GodotMethod!(Array, long) surfaceGetBlendShapeArrays;
49 		@GodotName("surface_get_material") GodotMethod!(Material, long) surfaceGetMaterial;
50 		@GodotName("create_trimesh_shape") GodotMethod!(Shape) createTrimeshShape;
51 		@GodotName("create_convex_shape") GodotMethod!(Shape) createConvexShape;
52 		@GodotName("create_outline") GodotMethod!(Mesh, double) createOutline;
53 		@GodotName("get_faces") GodotMethod!(PoolVector3Array) getFaces;
54 		@GodotName("generate_triangle_mesh") GodotMethod!(TriangleMesh) generateTriangleMesh;
55 	}
56 	bool opEquals(in Mesh other) const { return _godot_object.ptr is other._godot_object.ptr; }
57 	Mesh opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
58 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
59 	mixin baseCasts;
60 	static Mesh _new()
61 	{
62 		static godot_class_constructor constructor;
63 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Mesh");
64 		if(constructor is null) return typeof(this).init;
65 		return cast(Mesh)(constructor());
66 	}
67 	@disable new(size_t s);
68 	/// 
69 	enum BlendShapeMode : int
70 	{
71 		/**
72 		
73 		*/
74 		blendShapeModeNormalized = 0,
75 		/**
76 		
77 		*/
78 		blendShapeModeRelative = 1,
79 	}
80 	/// 
81 	enum PrimitiveType : int
82 	{
83 		/**
84 		Render array as points (one vertex equals one point).
85 		*/
86 		primitivePoints = 0,
87 		/**
88 		Render array as lines (every two vertices a line is created).
89 		*/
90 		primitiveLines = 1,
91 		/**
92 		Render array as line strip.
93 		*/
94 		primitiveLineStrip = 2,
95 		/**
96 		Render array as line loop (like line strip, but closed).
97 		*/
98 		primitiveLineLoop = 3,
99 		/**
100 		Render array as triangles (every three vertices a triangle is created).
101 		*/
102 		primitiveTriangles = 4,
103 		/**
104 		Render array as triangle strips.
105 		*/
106 		primitiveTriangleStrip = 5,
107 		/**
108 		Render array as triangle fans.
109 		*/
110 		primitiveTriangleFan = 6,
111 	}
112 	/// 
113 	enum ArrayFormat : int
114 	{
115 		/**
116 		
117 		*/
118 		arrayFormatVertex = 1,
119 		/**
120 		
121 		*/
122 		arrayFormatNormal = 2,
123 		/**
124 		
125 		*/
126 		arrayFormatTangent = 4,
127 		/**
128 		
129 		*/
130 		arrayFormatColor = 8,
131 		/**
132 		
133 		*/
134 		arrayCompressBase = 9,
135 		/**
136 		
137 		*/
138 		arrayFormatTexUv = 16,
139 		/**
140 		
141 		*/
142 		arrayFormatTexUv2 = 32,
143 		/**
144 		
145 		*/
146 		arrayFormatBones = 64,
147 		/**
148 		
149 		*/
150 		arrayFormatWeights = 128,
151 		/**
152 		
153 		*/
154 		arrayFormatIndex = 256,
155 		/**
156 		
157 		*/
158 		arrayCompressVertex = 512,
159 		/**
160 		
161 		*/
162 		arrayCompressNormal = 1024,
163 		/**
164 		
165 		*/
166 		arrayCompressTangent = 2048,
167 		/**
168 		
169 		*/
170 		arrayCompressColor = 4096,
171 		/**
172 		
173 		*/
174 		arrayCompressTexUv = 8192,
175 		/**
176 		
177 		*/
178 		arrayCompressTexUv2 = 16384,
179 		/**
180 		
181 		*/
182 		arrayCompressBones = 32768,
183 		/**
184 		
185 		*/
186 		arrayCompressWeights = 65536,
187 		/**
188 		
189 		*/
190 		arrayCompressDefault = 97280,
191 		/**
192 		
193 		*/
194 		arrayCompressIndex = 131072,
195 		/**
196 		
197 		*/
198 		arrayFlagUse2dVertices = 262144,
199 		/**
200 		
201 		*/
202 		arrayFlagUse16BitBones = 524288,
203 	}
204 	/// 
205 	enum ArrayType : int
206 	{
207 		/**
208 		Array of vertices.
209 		*/
210 		arrayVertex = 0,
211 		/**
212 		Array of normals.
213 		*/
214 		arrayNormal = 1,
215 		/**
216 		Array of tangents as an array of floats, 4 floats per tangent.
217 		*/
218 		arrayTangent = 2,
219 		/**
220 		Array of colors.
221 		*/
222 		arrayColor = 3,
223 		/**
224 		Array of UV coordinates.
225 		*/
226 		arrayTexUv = 4,
227 		/**
228 		Array of second set of UV coordinates.
229 		*/
230 		arrayTexUv2 = 5,
231 		/**
232 		Array of bone data.
233 		*/
234 		arrayBones = 6,
235 		/**
236 		Array of weights.
237 		*/
238 		arrayWeights = 7,
239 		/**
240 		Array of indices.
241 		*/
242 		arrayIndex = 8,
243 		/**
244 		
245 		*/
246 		arrayMax = 9,
247 	}
248 	/// 
249 	enum Constants : int
250 	{
251 		blendShapeModeNormalized = 0,
252 		arrayVertex = 0,
253 		primitivePoints = 0,
254 		arrayFormatVertex = 1,
255 		blendShapeModeRelative = 1,
256 		primitiveLines = 1,
257 		arrayNormal = 1,
258 		arrayTangent = 2,
259 		primitiveLineStrip = 2,
260 		arrayFormatNormal = 2,
261 		primitiveLineLoop = 3,
262 		arrayColor = 3,
263 		arrayTexUv = 4,
264 		arrayFormatTangent = 4,
265 		primitiveTriangles = 4,
266 		arrayTexUv2 = 5,
267 		primitiveTriangleStrip = 5,
268 		primitiveTriangleFan = 6,
269 		arrayBones = 6,
270 		arrayWeights = 7,
271 		arrayIndex = 8,
272 		arrayFormatColor = 8,
273 		arrayCompressBase = 9,
274 		arrayMax = 9,
275 		arrayFormatTexUv = 16,
276 		arrayFormatTexUv2 = 32,
277 		arrayFormatBones = 64,
278 		arrayFormatWeights = 128,
279 		arrayFormatIndex = 256,
280 		arrayCompressVertex = 512,
281 		arrayCompressNormal = 1024,
282 		arrayCompressTangent = 2048,
283 		arrayCompressColor = 4096,
284 		arrayCompressTexUv = 8192,
285 		arrayCompressTexUv2 = 16384,
286 		arrayCompressBones = 32768,
287 		arrayCompressWeights = 65536,
288 		arrayCompressDefault = 97280,
289 		arrayCompressIndex = 131072,
290 		arrayFlagUse2dVertices = 262144,
291 		arrayFlagUse16BitBones = 524288,
292 	}
293 	/**
294 	
295 	*/
296 	void setLightmapSizeHint(in Vector2 size)
297 	{
298 		checkClassBinding!(typeof(this))();
299 		ptrcall!(void)(_classBinding.setLightmapSizeHint, _godot_object, size);
300 	}
301 	/**
302 	
303 	*/
304 	Vector2 getLightmapSizeHint() const
305 	{
306 		checkClassBinding!(typeof(this))();
307 		return ptrcall!(Vector2)(_classBinding.getLightmapSizeHint, _godot_object);
308 	}
309 	/**
310 	Return the amount of surfaces that the `Mesh` holds.
311 	*/
312 	long getSurfaceCount() const
313 	{
314 		checkClassBinding!(typeof(this))();
315 		return ptrcall!(long)(_classBinding.getSurfaceCount, _godot_object);
316 	}
317 	/**
318 	Returns the arrays for the vertices, normals, uvs, etc. that make up the requested surface (see $(D ArrayMesh.addSurfaceFromArrays)).
319 	*/
320 	Array surfaceGetArrays(in long surf_idx) const
321 	{
322 		checkClassBinding!(typeof(this))();
323 		return ptrcall!(Array)(_classBinding.surfaceGetArrays, _godot_object, surf_idx);
324 	}
325 	/**
326 	Returns the blend shape arrays for the requested surface.
327 	*/
328 	Array surfaceGetBlendShapeArrays(in long surf_idx) const
329 	{
330 		checkClassBinding!(typeof(this))();
331 		return ptrcall!(Array)(_classBinding.surfaceGetBlendShapeArrays, _godot_object, surf_idx);
332 	}
333 	/**
334 	Return a $(D Material) in a given surface. Surface is rendered using this material.
335 	*/
336 	Ref!Material surfaceGetMaterial(in long surf_idx) const
337 	{
338 		checkClassBinding!(typeof(this))();
339 		return ptrcall!(Material)(_classBinding.surfaceGetMaterial, _godot_object, surf_idx);
340 	}
341 	/**
342 	Calculate a $(D ConcavePolygonShape) from the mesh.
343 	*/
344 	Ref!Shape createTrimeshShape() const
345 	{
346 		checkClassBinding!(typeof(this))();
347 		return ptrcall!(Shape)(_classBinding.createTrimeshShape, _godot_object);
348 	}
349 	/**
350 	Calculate a $(D ConvexPolygonShape) from the mesh.
351 	*/
352 	Ref!Shape createConvexShape() const
353 	{
354 		checkClassBinding!(typeof(this))();
355 		return ptrcall!(Shape)(_classBinding.createConvexShape, _godot_object);
356 	}
357 	/**
358 	Calculate an outline mesh at a defined offset (margin) from the original mesh. Note: Typically returns the vertices in reverse order (e.g. clockwise to anti-clockwise).
359 	*/
360 	Ref!Mesh createOutline(in double margin) const
361 	{
362 		checkClassBinding!(typeof(this))();
363 		return ptrcall!(Mesh)(_classBinding.createOutline, _godot_object, margin);
364 	}
365 	/**
366 	Returns all the vertices that make up the faces of the mesh. Each three vertices represent one triangle.
367 	*/
368 	PoolVector3Array getFaces() const
369 	{
370 		checkClassBinding!(typeof(this))();
371 		return ptrcall!(PoolVector3Array)(_classBinding.getFaces, _godot_object);
372 	}
373 	/**
374 	Generate a $(D TriangleMesh) from the mesh.
375 	*/
376 	Ref!TriangleMesh generateTriangleMesh() const
377 	{
378 		checkClassBinding!(typeof(this))();
379 		return ptrcall!(TriangleMesh)(_classBinding.generateTriangleMesh, _godot_object);
380 	}
381 	/**
382 	
383 	*/
384 	@property Vector2 lightmapSizeHint()
385 	{
386 		return getLightmapSizeHint();
387 	}
388 	/// ditto
389 	@property void lightmapSizeHint(Vector2 v)
390 	{
391 		setLightmapSizeHint(v);
392 	}
393 }