1 /**
2 Helper tool to access and edit $(D Mesh) data.
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.meshdatatool;
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.classdb;
23 import godot.reference;
24 import godot.arraymesh;
25 import godot.material;
26 /**
27 Helper tool to access and edit $(D Mesh) data.
28 
29 The MeshDataTool provides access to individual vertices in a $(D Mesh). It allows users to read and edit vertex data of meshes. It also creates an array of faces and edges.
30 To use the MeshDataTool, load a mesh with $(D createFromSurface). When you are finished editing the data commit the data to a mesh with $(D commitToSurface).
31 Below is an example of how the MeshDataTool may be used.
32 
33 
34 var mdt = MeshDataTool.new()
35 mdt.create_from_surface(mesh, 0)
36 for i in range(mdt.get_vertex_count()):
37 	var vertex = mdt.get_vertex(i)
38 	...
39 	mdt.set_vertex(i, vertex)
40 mesh.surface_remove(0)
41 mdt.commit_to_surface(mesh)
42 
43 
44 */
45 @GodotBaseClass struct MeshDataTool
46 {
47 	enum string _GODOT_internal_name = "MeshDataTool";
48 public:
49 @nogc nothrow:
50 	union { godot_object _godot_object; Reference _GODOT_base; }
51 	alias _GODOT_base this;
52 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
53 	package(godot) __gshared bool _classBindingInitialized = false;
54 	package(godot) static struct _classBinding
55 	{
56 		__gshared:
57 		@GodotName("clear") GodotMethod!(void) clear;
58 		@GodotName("create_from_surface") GodotMethod!(GodotError, ArrayMesh, long) createFromSurface;
59 		@GodotName("commit_to_surface") GodotMethod!(GodotError, ArrayMesh) commitToSurface;
60 		@GodotName("get_format") GodotMethod!(long) getFormat;
61 		@GodotName("get_vertex_count") GodotMethod!(long) getVertexCount;
62 		@GodotName("get_edge_count") GodotMethod!(long) getEdgeCount;
63 		@GodotName("get_face_count") GodotMethod!(long) getFaceCount;
64 		@GodotName("set_vertex") GodotMethod!(void, long, Vector3) setVertex;
65 		@GodotName("get_vertex") GodotMethod!(Vector3, long) getVertex;
66 		@GodotName("set_vertex_normal") GodotMethod!(void, long, Vector3) setVertexNormal;
67 		@GodotName("get_vertex_normal") GodotMethod!(Vector3, long) getVertexNormal;
68 		@GodotName("set_vertex_tangent") GodotMethod!(void, long, Plane) setVertexTangent;
69 		@GodotName("get_vertex_tangent") GodotMethod!(Plane, long) getVertexTangent;
70 		@GodotName("set_vertex_uv") GodotMethod!(void, long, Vector2) setVertexUv;
71 		@GodotName("get_vertex_uv") GodotMethod!(Vector2, long) getVertexUv;
72 		@GodotName("set_vertex_uv2") GodotMethod!(void, long, Vector2) setVertexUv2;
73 		@GodotName("get_vertex_uv2") GodotMethod!(Vector2, long) getVertexUv2;
74 		@GodotName("set_vertex_color") GodotMethod!(void, long, Color) setVertexColor;
75 		@GodotName("get_vertex_color") GodotMethod!(Color, long) getVertexColor;
76 		@GodotName("set_vertex_bones") GodotMethod!(void, long, PoolIntArray) setVertexBones;
77 		@GodotName("get_vertex_bones") GodotMethod!(PoolIntArray, long) getVertexBones;
78 		@GodotName("set_vertex_weights") GodotMethod!(void, long, PoolRealArray) setVertexWeights;
79 		@GodotName("get_vertex_weights") GodotMethod!(PoolRealArray, long) getVertexWeights;
80 		@GodotName("set_vertex_meta") GodotMethod!(void, long, Variant) setVertexMeta;
81 		@GodotName("get_vertex_meta") GodotMethod!(Variant, long) getVertexMeta;
82 		@GodotName("get_vertex_edges") GodotMethod!(PoolIntArray, long) getVertexEdges;
83 		@GodotName("get_vertex_faces") GodotMethod!(PoolIntArray, long) getVertexFaces;
84 		@GodotName("get_edge_vertex") GodotMethod!(long, long, long) getEdgeVertex;
85 		@GodotName("get_edge_faces") GodotMethod!(PoolIntArray, long) getEdgeFaces;
86 		@GodotName("set_edge_meta") GodotMethod!(void, long, Variant) setEdgeMeta;
87 		@GodotName("get_edge_meta") GodotMethod!(Variant, long) getEdgeMeta;
88 		@GodotName("get_face_vertex") GodotMethod!(long, long, long) getFaceVertex;
89 		@GodotName("get_face_edge") GodotMethod!(long, long, long) getFaceEdge;
90 		@GodotName("set_face_meta") GodotMethod!(void, long, Variant) setFaceMeta;
91 		@GodotName("get_face_meta") GodotMethod!(Variant, long) getFaceMeta;
92 		@GodotName("get_face_normal") GodotMethod!(Vector3, long) getFaceNormal;
93 		@GodotName("set_material") GodotMethod!(void, Material) setMaterial;
94 		@GodotName("get_material") GodotMethod!(Material) getMaterial;
95 	}
96 	bool opEquals(in MeshDataTool other) const { return _godot_object.ptr is other._godot_object.ptr; }
97 	MeshDataTool opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
98 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
99 	mixin baseCasts;
100 	static MeshDataTool _new()
101 	{
102 		static godot_class_constructor constructor;
103 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("MeshDataTool");
104 		if(constructor is null) return typeof(this).init;
105 		return cast(MeshDataTool)(constructor());
106 	}
107 	@disable new(size_t s);
108 	/**
109 	Clears all data currently in MeshDataTool.
110 	*/
111 	void clear()
112 	{
113 		checkClassBinding!(typeof(this))();
114 		ptrcall!(void)(_classBinding.clear, _godot_object);
115 	}
116 	/**
117 	Uses specified surface of given $(D Mesh) to populate data for MeshDataTool.
118 	Requires $(D Mesh) with primitive type `PRIMITIVE_TRIANGLES`.
119 	*/
120 	GodotError createFromSurface(ArrayMesh mesh, in long surface)
121 	{
122 		checkClassBinding!(typeof(this))();
123 		return ptrcall!(GodotError)(_classBinding.createFromSurface, _godot_object, mesh, surface);
124 	}
125 	/**
126 	Adds a new surface to specified $(D Mesh) with edited data.
127 	*/
128 	GodotError commitToSurface(ArrayMesh mesh)
129 	{
130 		checkClassBinding!(typeof(this))();
131 		return ptrcall!(GodotError)(_classBinding.commitToSurface, _godot_object, mesh);
132 	}
133 	/**
134 	Returns format of $(D Mesh). Format is an integer made up of $(D Mesh) format flags combined together. For example, a mesh containing both vertices and normals would return a format of `3` becuase `ARRAY_FORMAT_VERTEX` is `1` and `ARRAY_FORMAT_NORMAL` is `2`.
135 	For list of format flags see $(D ArrayMesh).
136 	*/
137 	long getFormat() const
138 	{
139 		checkClassBinding!(typeof(this))();
140 		return ptrcall!(long)(_classBinding.getFormat, _godot_object);
141 	}
142 	/**
143 	Returns the total number of vertices in $(D Mesh).
144 	*/
145 	long getVertexCount() const
146 	{
147 		checkClassBinding!(typeof(this))();
148 		return ptrcall!(long)(_classBinding.getVertexCount, _godot_object);
149 	}
150 	/**
151 	Returns the number of edges in this $(D Mesh).
152 	*/
153 	long getEdgeCount() const
154 	{
155 		checkClassBinding!(typeof(this))();
156 		return ptrcall!(long)(_classBinding.getEdgeCount, _godot_object);
157 	}
158 	/**
159 	Returns the number of faces in this $(D Mesh).
160 	*/
161 	long getFaceCount() const
162 	{
163 		checkClassBinding!(typeof(this))();
164 		return ptrcall!(long)(_classBinding.getFaceCount, _godot_object);
165 	}
166 	/**
167 	Sets the position of given vertex.
168 	*/
169 	void setVertex(in long idx, in Vector3 vertex)
170 	{
171 		checkClassBinding!(typeof(this))();
172 		ptrcall!(void)(_classBinding.setVertex, _godot_object, idx, vertex);
173 	}
174 	/**
175 	Returns the vertex at given index.
176 	*/
177 	Vector3 getVertex(in long idx) const
178 	{
179 		checkClassBinding!(typeof(this))();
180 		return ptrcall!(Vector3)(_classBinding.getVertex, _godot_object, idx);
181 	}
182 	/**
183 	Sets the normal of given vertex.
184 	*/
185 	void setVertexNormal(in long idx, in Vector3 normal)
186 	{
187 		checkClassBinding!(typeof(this))();
188 		ptrcall!(void)(_classBinding.setVertexNormal, _godot_object, idx, normal);
189 	}
190 	/**
191 	Returns normal of given vertex.
192 	*/
193 	Vector3 getVertexNormal(in long idx) const
194 	{
195 		checkClassBinding!(typeof(this))();
196 		return ptrcall!(Vector3)(_classBinding.getVertexNormal, _godot_object, idx);
197 	}
198 	/**
199 	Sets the tangent of given vertex.
200 	*/
201 	void setVertexTangent(in long idx, in Plane tangent)
202 	{
203 		checkClassBinding!(typeof(this))();
204 		ptrcall!(void)(_classBinding.setVertexTangent, _godot_object, idx, tangent);
205 	}
206 	/**
207 	Returns tangent of given vertex.
208 	*/
209 	Plane getVertexTangent(in long idx) const
210 	{
211 		checkClassBinding!(typeof(this))();
212 		return ptrcall!(Plane)(_classBinding.getVertexTangent, _godot_object, idx);
213 	}
214 	/**
215 	Sets the UV of given vertex.
216 	*/
217 	void setVertexUv(in long idx, in Vector2 uv)
218 	{
219 		checkClassBinding!(typeof(this))();
220 		ptrcall!(void)(_classBinding.setVertexUv, _godot_object, idx, uv);
221 	}
222 	/**
223 	Returns UV of given vertex.
224 	*/
225 	Vector2 getVertexUv(in long idx) const
226 	{
227 		checkClassBinding!(typeof(this))();
228 		return ptrcall!(Vector2)(_classBinding.getVertexUv, _godot_object, idx);
229 	}
230 	/**
231 	Sets the UV2 of given vertex.
232 	*/
233 	void setVertexUv2(in long idx, in Vector2 uv2)
234 	{
235 		checkClassBinding!(typeof(this))();
236 		ptrcall!(void)(_classBinding.setVertexUv2, _godot_object, idx, uv2);
237 	}
238 	/**
239 	Returns UV2 of given vertex.
240 	*/
241 	Vector2 getVertexUv2(in long idx) const
242 	{
243 		checkClassBinding!(typeof(this))();
244 		return ptrcall!(Vector2)(_classBinding.getVertexUv2, _godot_object, idx);
245 	}
246 	/**
247 	Sets the color of given vertex.
248 	*/
249 	void setVertexColor(in long idx, in Color color)
250 	{
251 		checkClassBinding!(typeof(this))();
252 		ptrcall!(void)(_classBinding.setVertexColor, _godot_object, idx, color);
253 	}
254 	/**
255 	Returns the color of the given vertex.
256 	*/
257 	Color getVertexColor(in long idx) const
258 	{
259 		checkClassBinding!(typeof(this))();
260 		return ptrcall!(Color)(_classBinding.getVertexColor, _godot_object, idx);
261 	}
262 	/**
263 	Sets the bones of given vertex.
264 	*/
265 	void setVertexBones(in long idx, in PoolIntArray bones)
266 	{
267 		checkClassBinding!(typeof(this))();
268 		ptrcall!(void)(_classBinding.setVertexBones, _godot_object, idx, bones);
269 	}
270 	/**
271 	Returns the bones of the given vertex.
272 	*/
273 	PoolIntArray getVertexBones(in long idx) const
274 	{
275 		checkClassBinding!(typeof(this))();
276 		return ptrcall!(PoolIntArray)(_classBinding.getVertexBones, _godot_object, idx);
277 	}
278 	/**
279 	Sets the bone weights of given vertex.
280 	*/
281 	void setVertexWeights(in long idx, in PoolRealArray weights)
282 	{
283 		checkClassBinding!(typeof(this))();
284 		ptrcall!(void)(_classBinding.setVertexWeights, _godot_object, idx, weights);
285 	}
286 	/**
287 	Returns bone weights of given vertex.
288 	*/
289 	PoolRealArray getVertexWeights(in long idx) const
290 	{
291 		checkClassBinding!(typeof(this))();
292 		return ptrcall!(PoolRealArray)(_classBinding.getVertexWeights, _godot_object, idx);
293 	}
294 	/**
295 	Sets the meta data associated with given vertex.
296 	*/
297 	void setVertexMeta(VariantArg1)(in long idx, in VariantArg1 meta)
298 	{
299 		checkClassBinding!(typeof(this))();
300 		ptrcall!(void)(_classBinding.setVertexMeta, _godot_object, idx, meta);
301 	}
302 	/**
303 	Returns meta data associated with given vertex.
304 	*/
305 	Variant getVertexMeta(in long idx) const
306 	{
307 		checkClassBinding!(typeof(this))();
308 		return ptrcall!(Variant)(_classBinding.getVertexMeta, _godot_object, idx);
309 	}
310 	/**
311 	Returns array of edges that share given vertex.
312 	*/
313 	PoolIntArray getVertexEdges(in long idx) const
314 	{
315 		checkClassBinding!(typeof(this))();
316 		return ptrcall!(PoolIntArray)(_classBinding.getVertexEdges, _godot_object, idx);
317 	}
318 	/**
319 	Returns array of faces that share given vertex.
320 	*/
321 	PoolIntArray getVertexFaces(in long idx) const
322 	{
323 		checkClassBinding!(typeof(this))();
324 		return ptrcall!(PoolIntArray)(_classBinding.getVertexFaces, _godot_object, idx);
325 	}
326 	/**
327 	Returns index of specified vertex connected to given edge.
328 	Vertex argument can only be 0 or 1 because edges are comprised of two vertices.
329 	*/
330 	long getEdgeVertex(in long idx, in long vertex) const
331 	{
332 		checkClassBinding!(typeof(this))();
333 		return ptrcall!(long)(_classBinding.getEdgeVertex, _godot_object, idx, vertex);
334 	}
335 	/**
336 	Returns array of faces that touch given edge.
337 	*/
338 	PoolIntArray getEdgeFaces(in long idx) const
339 	{
340 		checkClassBinding!(typeof(this))();
341 		return ptrcall!(PoolIntArray)(_classBinding.getEdgeFaces, _godot_object, idx);
342 	}
343 	/**
344 	Sets the meta data of given edge.
345 	*/
346 	void setEdgeMeta(VariantArg1)(in long idx, in VariantArg1 meta)
347 	{
348 		checkClassBinding!(typeof(this))();
349 		ptrcall!(void)(_classBinding.setEdgeMeta, _godot_object, idx, meta);
350 	}
351 	/**
352 	Returns meta information assigned to given edge.
353 	*/
354 	Variant getEdgeMeta(in long idx) const
355 	{
356 		checkClassBinding!(typeof(this))();
357 		return ptrcall!(Variant)(_classBinding.getEdgeMeta, _godot_object, idx);
358 	}
359 	/**
360 	Returns specified vertex of given face.
361 	Vertex argument must be 2 or less becuase faces contain three vertices.
362 	*/
363 	long getFaceVertex(in long idx, in long vertex) const
364 	{
365 		checkClassBinding!(typeof(this))();
366 		return ptrcall!(long)(_classBinding.getFaceVertex, _godot_object, idx, vertex);
367 	}
368 	/**
369 	Returns specified edge associated with given face.
370 	Edge argument must 2 or less becuase a face only has three edges.
371 	*/
372 	long getFaceEdge(in long idx, in long edge) const
373 	{
374 		checkClassBinding!(typeof(this))();
375 		return ptrcall!(long)(_classBinding.getFaceEdge, _godot_object, idx, edge);
376 	}
377 	/**
378 	Sets the meta data of given face.
379 	*/
380 	void setFaceMeta(VariantArg1)(in long idx, in VariantArg1 meta)
381 	{
382 		checkClassBinding!(typeof(this))();
383 		ptrcall!(void)(_classBinding.setFaceMeta, _godot_object, idx, meta);
384 	}
385 	/**
386 	Returns meta data associated with given face.
387 	*/
388 	Variant getFaceMeta(in long idx) const
389 	{
390 		checkClassBinding!(typeof(this))();
391 		return ptrcall!(Variant)(_classBinding.getFaceMeta, _godot_object, idx);
392 	}
393 	/**
394 	Calculates and returns face normal of given face.
395 	*/
396 	Vector3 getFaceNormal(in long idx) const
397 	{
398 		checkClassBinding!(typeof(this))();
399 		return ptrcall!(Vector3)(_classBinding.getFaceNormal, _godot_object, idx);
400 	}
401 	/**
402 	Sets the material to be used by newly constructed $(D Mesh).
403 	*/
404 	void setMaterial(Material material)
405 	{
406 		checkClassBinding!(typeof(this))();
407 		ptrcall!(void)(_classBinding.setMaterial, _godot_object, material);
408 	}
409 	/**
410 	Returns material assigned to the $(D Mesh).
411 	*/
412 	Ref!Material getMaterial() const
413 	{
414 		checkClassBinding!(typeof(this))();
415 		return ptrcall!(Material)(_classBinding.getMaterial, _godot_object);
416 	}
417 }