/
MeshDataTool.hx
288 lines (236 loc) · 7.83 KB
/
MeshDataTool.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Automatically generated Godot externs: DO NOT EDIT
// MIT licensed, see LICENSE.md
package godot;
import cs.system.*;
/**
MeshDataTool provides access to individual vertices in a `godot.Mesh`. It allows users to read and edit vertex data of meshes. It also creates an array of faces and edges.
To use MeshDataTool, load a mesh with `godot.MeshDataTool.createFromSurface`. When you are finished editing the data commit the data to a mesh with `godot.MeshDataTool.commitToSurface`.
Below is an example of how MeshDataTool may be used.
```
var mesh = ArrayMesh.new()
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, CubeMesh.new().get_mesh_arrays())
var mdt = MeshDataTool.new()
mdt.create_from_surface(mesh, 0)
for i in range(mdt.get_vertex_count()):
var vertex = mdt.get_vertex(i)
# In this example we extend the mesh by one unit, which results in separated faces as it is flat shaded.
vertex += mdt.get_vertex_normal(i)
# Save your change.
mdt.set_vertex(i, vertex)
mesh.surface_remove(0)
mdt.commit_to_surface(mesh)
var mi = MeshInstance.new()
mi.mesh = mesh
add_child(mi)
```
See also `godot.ArrayMesh`, `godot.ImmediateGeometry` and `godot.SurfaceTool` for procedural geometry generation.
Note: Godot uses clockwise [https://learnopengl.com/Advanced-OpenGL/Face-culling](winding order) for front faces of triangle primitive modes.
**/
@:libType
@:csNative
@:native("Godot.MeshDataTool")
@:autoBuild(godot.Godot.buildUserClass())
extern class MeshDataTool extends godot.Reference {
@:native("new")
public function new():Void;
/**
Clears all data currently in MeshDataTool.
**/
@:native("Clear")
public function clear():Void;
/**
Uses specified surface of given `godot.Mesh` to populate data for MeshDataTool.
Requires `godot.Mesh` with primitive type `godot.Mesh_PrimitiveType.triangles`.
**/
@:native("CreateFromSurface")
public function createFromSurface(mesh:godot.ArrayMesh, surface:Int):godot.Error;
/**
Adds a new surface to specified `godot.Mesh` with edited data.
**/
@:native("CommitToSurface")
public function commitToSurface(mesh:godot.ArrayMesh):godot.Error;
/**
Returns the `godot.Mesh`'s format. Format is an integer made up of `godot.Mesh` format flags combined together. For example, a mesh containing both vertices and normals would return a format of `3` because `godot.ArrayMesh_ArrayFormat.vertex` is `1` and `godot.ArrayMesh_ArrayFormat.normal` is `2`.
See `godot.ArrayMesh_ArrayFormat` for a list of format flags.
**/
@:native("GetFormat")
public function getFormat():Int;
/**
Returns the total number of vertices in `godot.Mesh`.
**/
@:native("GetVertexCount")
public function getVertexCount():Int;
/**
Returns the number of edges in this `godot.Mesh`.
**/
@:native("GetEdgeCount")
public function getEdgeCount():Int;
/**
Returns the number of faces in this `godot.Mesh`.
**/
@:native("GetFaceCount")
public function getFaceCount():Int;
/**
Sets the position of the given vertex.
**/
@:native("SetVertex")
public function setVertex(idx:Int, vertex:godot.Vector3):Void;
/**
Returns the vertex at given index.
**/
@:native("GetVertex")
public function getVertex(idx:Int):godot.Vector3;
/**
Sets the normal of the given vertex.
**/
@:native("SetVertexNormal")
public function setVertexNormal(idx:Int, normal:godot.Vector3):Void;
/**
Returns the normal of the given vertex.
**/
@:native("GetVertexNormal")
public function getVertexNormal(idx:Int):godot.Vector3;
/**
Sets the tangent of the given vertex.
**/
@:native("SetVertexTangent")
public function setVertexTangent(idx:Int, tangent:godot.Plane):Void;
/**
Returns the tangent of the given vertex.
**/
@:native("GetVertexTangent")
public function getVertexTangent(idx:Int):godot.Plane;
/**
Sets the UV of the given vertex.
**/
@:native("SetVertexUv")
public function setVertexUv(idx:Int, uv:godot.Vector2):Void;
/**
Returns the UV of the given vertex.
**/
@:native("GetVertexUv")
public function getVertexUv(idx:Int):godot.Vector2;
/**
Sets the UV2 of the given vertex.
**/
@:native("SetVertexUv2")
public function setVertexUv2(idx:Int, uv2:godot.Vector2):Void;
/**
Returns the UV2 of the given vertex.
**/
@:native("GetVertexUv2")
public function getVertexUv2(idx:Int):godot.Vector2;
/**
Sets the color of the given vertex.
**/
@:native("SetVertexColor")
public function setVertexColor(idx:Int, color:godot.Color):Void;
/**
Returns the color of the given vertex.
**/
@:native("GetVertexColor")
public function getVertexColor(idx:Int):godot.Color;
/**
Sets the bones of the given vertex.
**/
@:native("SetVertexBones")
public function setVertexBones(idx:Int, bones:HaxeArray<Int>):Void;
/**
Returns the bones of the given vertex.
**/
public extern inline function getVertexBones(idx:Int):std.Array<Int> {
return cs.Lib.array(cs.Syntax.code("{0}.GetVertexBones({1})", this, idx));
}
/**
Sets the bone weights of the given vertex.
**/
@:native("SetVertexWeights")
public function setVertexWeights(idx:Int, weights:HaxeArray<Single>):Void;
/**
Returns bone weights of the given vertex.
**/
public extern inline function getVertexWeights(idx:Int):std.Array<Single> {
return cs.Lib.array(cs.Syntax.code("{0}.GetVertexWeights({1})", this, idx));
}
/**
Sets the metadata associated with the given vertex.
**/
@:native("SetVertexMeta")
public function setVertexMeta(idx:Int, meta:Dynamic):Void;
/**
Returns the metadata associated with the given vertex.
**/
@:native("GetVertexMeta")
public function getVertexMeta(idx:Int):Dynamic;
/**
Returns an array of edges that share the given vertex.
**/
public extern inline function getVertexEdges(idx:Int):std.Array<Int> {
return cs.Lib.array(cs.Syntax.code("{0}.GetVertexEdges({1})", this, idx));
}
/**
Returns an array of faces that share the given vertex.
**/
public extern inline function getVertexFaces(idx:Int):std.Array<Int> {
return cs.Lib.array(cs.Syntax.code("{0}.GetVertexFaces({1})", this, idx));
}
/**
Returns index of specified vertex connected to given edge.
Vertex argument can only be 0 or 1 because edges are comprised of two vertices.
**/
@:native("GetEdgeVertex")
public function getEdgeVertex(idx:Int, vertex:Int):Int;
/**
Returns array of faces that touch given edge.
**/
public extern inline function getEdgeFaces(idx:Int):std.Array<Int> {
return cs.Lib.array(cs.Syntax.code("{0}.GetEdgeFaces({1})", this, idx));
}
/**
Sets the metadata of the given edge.
**/
@:native("SetEdgeMeta")
public function setEdgeMeta(idx:Int, meta:Dynamic):Void;
/**
Returns meta information assigned to given edge.
**/
@:native("GetEdgeMeta")
public function getEdgeMeta(idx:Int):Dynamic;
/**
Returns the specified vertex of the given face.
Vertex argument must be either 0, 1, or 2 because faces contain three vertices.
**/
@:native("GetFaceVertex")
public function getFaceVertex(idx:Int, vertex:Int):Int;
/**
Returns specified edge associated with given face.
Edge argument must be either 0, 1, or 2 because a face only has three edges.
**/
@:native("GetFaceEdge")
public function getFaceEdge(idx:Int, edge:Int):Int;
/**
Sets the metadata of the given face.
**/
@:native("SetFaceMeta")
public function setFaceMeta(idx:Int, meta:Dynamic):Void;
/**
Returns the metadata associated with the given face.
**/
@:native("GetFaceMeta")
public function getFaceMeta(idx:Int):Dynamic;
/**
Calculates and returns the face normal of the given face.
**/
@:native("GetFaceNormal")
public function getFaceNormal(idx:Int):godot.Vector3;
/**
Sets the material to be used by newly-constructed `godot.Mesh`.
**/
@:native("SetMaterial")
public function setMaterial(material:godot.Material):Void;
/**
Returns the material assigned to the `godot.Mesh`.
**/
@:native("GetMaterial")
public function getMaterial():godot.Material;
}