/
SurfaceTool.hx
321 lines (257 loc) · 16.8 KB
/
SurfaceTool.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// Automatically generated Godot externs: DO NOT EDIT
// MIT licensed, see LICENSE.md
package godot;
import cs.system.*;
/**
The `godot.SurfaceTool` is used to construct a `godot.Mesh` by specifying vertex attributes individually. It can be used to construct a `godot.Mesh` from a script. All properties except indices need to be added before calling `godot.SurfaceTool.addVertex`. For example, to add vertex colors and UVs:
```
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_color(Color(1, 0, 0))
st.add_uv(Vector2(0, 0))
st.add_vertex(Vector3(0, 0, 0))
```
The above `godot.SurfaceTool` now contains one vertex of a triangle which has a UV coordinate and a specified `godot.Color`. If another vertex were added without calling `godot.SurfaceTool.addUv` or `godot.SurfaceTool.addColor`, then the last values would be used.
Vertex attributes must be passed before calling `godot.SurfaceTool.addVertex`. Failure to do so will result in an error when committing the vertex information to a mesh.
Additionally, the attributes used before the first vertex is added determine the format of the mesh. For example, if you only add UVs to the first vertex, you cannot add color to any of the subsequent vertices.
See also `godot.ArrayMesh`, `godot.ImmediateGeometry` and `godot.MeshDataTool` 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.SurfaceTool")
@:autoBuild(godot.Godot.buildUserClass())
extern class SurfaceTool extends godot.Reference {
@:native("new")
public function new():Void;
/**
Called before adding any vertices. Takes the primitive type as an argument (e.g. `godot.Mesh_PrimitiveType.triangles`).
**/
@:native("Begin")
public function begin(primitive:godot.Mesh_PrimitiveType):Void;
/**
Specifies the position of current vertex. Should be called after specifying other vertex properties (e.g. Color, UV).
**/
@:native("AddVertex")
public function addVertex(vertex:godot.Vector3):Void;
/**
Specifies a `godot.Color` to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.
Note: The material must have `godot.SpatialMaterial.vertexColorUseAsAlbedo` enabled for the vertex color to be visible.
**/
@:native("AddColor")
public function addColor(color:godot.Color):Void;
/**
Specifies a normal to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.
**/
@:native("AddNormal")
public function addNormal(normal:godot.Vector3):Void;
/**
Specifies a tangent to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.
**/
@:native("AddTangent")
public function addTangent(tangent:godot.Plane):Void;
/**
Specifies a set of UV coordinates to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.
**/
@:native("AddUv")
public function addUv(uv:godot.Vector2):Void;
/**
Specifies an optional second set of UV coordinates to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.
**/
@:native("AddUv2")
public function addUv2(uv2:godot.Vector2):Void;
/**
Specifies an array of bones to use for the next vertex. `bones` must contain 4 integers.
**/
@:native("AddBones")
public function addBones(bones:HaxeArray<Int>):Void;
/**
Specifies weight values to use for the next vertex. `weights` must contain 4 values. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.
**/
@:native("AddWeights")
public function addWeights(weights:HaxeArray<Single>):Void;
/**
Specifies whether the current vertex (if using only vertex arrays) or current index (if also using index arrays) should use smooth normals for normal calculation.
**/
@:native("AddSmoothGroup")
public function addSmoothGroup(smooth:Bool):Void;
#if doc_gen
/**
Inserts a triangle fan made of array data into `godot.Mesh` being constructed.
Requires the primitive type be set to `godot.Mesh_PrimitiveType.triangles`.
@param uvs If the parameter is null, then the default value is Array.Empty<Vector2>()
@param colors If the parameter is null, then the default value is Array.Empty<Color>()
@param uv2s If the parameter is null, then the default value is Array.Empty<Vector2>()
@param normals If the parameter is null, then the default value is Array.Empty<Vector3>()
@param tangents If the parameter is null, then the default value is new Godot.Collections.Array { }
**/
@:native("AddTriangleFan")
public function addTriangleFan(vertices:std.Array<godot.Vector3>, ?uvs:std.Array<godot.Vector2>, ?colors:std.Array<godot.Color>, ?uv2s:std.Array<godot.Vector2>, ?normals:std.Array<godot.Vector3>, ?tangents:godot.collections.Array):Void;
#else
/**
Inserts a triangle fan made of array data into `godot.Mesh` being constructed.
Requires the primitive type be set to `godot.Mesh_PrimitiveType.triangles`.
@param uvs If the parameter is null, then the default value is Array.Empty<Vector2>()
@param colors If the parameter is null, then the default value is Array.Empty<Color>()
@param uv2s If the parameter is null, then the default value is Array.Empty<Vector2>()
@param normals If the parameter is null, then the default value is Array.Empty<Vector3>()
@param tangents If the parameter is null, then the default value is new Godot.Collections.Array { }
**/
@:native("AddTriangleFan")
public overload function addTriangleFan(vertices:HaxeArray<godot.Vector3>):Void;
/**
Inserts a triangle fan made of array data into `godot.Mesh` being constructed.
Requires the primitive type be set to `godot.Mesh_PrimitiveType.triangles`.
@param uvs If the parameter is null, then the default value is Array.Empty<Vector2>()
@param colors If the parameter is null, then the default value is Array.Empty<Color>()
@param uv2s If the parameter is null, then the default value is Array.Empty<Vector2>()
@param normals If the parameter is null, then the default value is Array.Empty<Vector3>()
@param tangents If the parameter is null, then the default value is new Godot.Collections.Array { }
**/
@:native("AddTriangleFan")
public overload function addTriangleFan(vertices:HaxeArray<godot.Vector3>, uvs:HaxeArray<godot.Vector2>):Void;
/**
Inserts a triangle fan made of array data into `godot.Mesh` being constructed.
Requires the primitive type be set to `godot.Mesh_PrimitiveType.triangles`.
@param uvs If the parameter is null, then the default value is Array.Empty<Vector2>()
@param colors If the parameter is null, then the default value is Array.Empty<Color>()
@param uv2s If the parameter is null, then the default value is Array.Empty<Vector2>()
@param normals If the parameter is null, then the default value is Array.Empty<Vector3>()
@param tangents If the parameter is null, then the default value is new Godot.Collections.Array { }
**/
@:native("AddTriangleFan")
public overload function addTriangleFan(vertices:HaxeArray<godot.Vector3>, uvs:HaxeArray<godot.Vector2>, colors:HaxeArray<godot.Color>):Void;
/**
Inserts a triangle fan made of array data into `godot.Mesh` being constructed.
Requires the primitive type be set to `godot.Mesh_PrimitiveType.triangles`.
@param uvs If the parameter is null, then the default value is Array.Empty<Vector2>()
@param colors If the parameter is null, then the default value is Array.Empty<Color>()
@param uv2s If the parameter is null, then the default value is Array.Empty<Vector2>()
@param normals If the parameter is null, then the default value is Array.Empty<Vector3>()
@param tangents If the parameter is null, then the default value is new Godot.Collections.Array { }
**/
@:native("AddTriangleFan")
public overload function addTriangleFan(vertices:HaxeArray<godot.Vector3>, uvs:HaxeArray<godot.Vector2>, colors:HaxeArray<godot.Color>, uv2s:HaxeArray<godot.Vector2>):Void;
/**
Inserts a triangle fan made of array data into `godot.Mesh` being constructed.
Requires the primitive type be set to `godot.Mesh_PrimitiveType.triangles`.
@param uvs If the parameter is null, then the default value is Array.Empty<Vector2>()
@param colors If the parameter is null, then the default value is Array.Empty<Color>()
@param uv2s If the parameter is null, then the default value is Array.Empty<Vector2>()
@param normals If the parameter is null, then the default value is Array.Empty<Vector3>()
@param tangents If the parameter is null, then the default value is new Godot.Collections.Array { }
**/
@:native("AddTriangleFan")
public overload function addTriangleFan(vertices:HaxeArray<godot.Vector3>, uvs:HaxeArray<godot.Vector2>, colors:HaxeArray<godot.Color>, uv2s:HaxeArray<godot.Vector2>, normals:HaxeArray<godot.Vector3>):Void;
/**
Inserts a triangle fan made of array data into `godot.Mesh` being constructed.
Requires the primitive type be set to `godot.Mesh_PrimitiveType.triangles`.
@param uvs If the parameter is null, then the default value is Array.Empty<Vector2>()
@param colors If the parameter is null, then the default value is Array.Empty<Color>()
@param uv2s If the parameter is null, then the default value is Array.Empty<Vector2>()
@param normals If the parameter is null, then the default value is Array.Empty<Vector3>()
@param tangents If the parameter is null, then the default value is new Godot.Collections.Array { }
**/
@:native("AddTriangleFan")
public overload function addTriangleFan(vertices:HaxeArray<godot.Vector3>, uvs:HaxeArray<godot.Vector2>, colors:HaxeArray<godot.Color>, uv2s:HaxeArray<godot.Vector2>, normals:HaxeArray<godot.Vector3>, tangents:godot.collections.Array):Void;
#end
/**
Adds an index to index array if you are using indexed vertices. Does not need to be called before adding vertices.
**/
@:native("AddIndex")
public function addIndex(index:Int):Void;
/**
Shrinks the vertex array by creating an index array. This can improve performance by avoiding vertex reuse.
**/
@:native("Index")
public function index():Void;
/**
Removes the index array by expanding the vertex array.
**/
@:native("Deindex")
public function deindex():Void;
#if doc_gen
/**
Generates normals from vertices so you do not have to do it manually. If `flip` is `true`, the resulting normals will be inverted. `godot.SurfaceTool.generateNormals` should be called after generating geometry and before committing the mesh using `godot.SurfaceTool.commit` or `godot.SurfaceTool.commitToArrays`. For correct display of normal-mapped surfaces, you will also have to generate tangents using `godot.SurfaceTool.generateTangents`.
Note: `godot.SurfaceTool.generateNormals` only works if the primitive type to be set to `godot.Mesh_PrimitiveType.triangles`.
**/
@:native("GenerateNormals")
public function generateNormals(?flip:Bool):Void;
#else
/**
Generates normals from vertices so you do not have to do it manually. If `flip` is `true`, the resulting normals will be inverted. `godot.SurfaceTool.generateNormals` should be called after generating geometry and before committing the mesh using `godot.SurfaceTool.commit` or `godot.SurfaceTool.commitToArrays`. For correct display of normal-mapped surfaces, you will also have to generate tangents using `godot.SurfaceTool.generateTangents`.
Note: `godot.SurfaceTool.generateNormals` only works if the primitive type to be set to `godot.Mesh_PrimitiveType.triangles`.
**/
@:native("GenerateNormals")
public overload function generateNormals():Void;
/**
Generates normals from vertices so you do not have to do it manually. If `flip` is `true`, the resulting normals will be inverted. `godot.SurfaceTool.generateNormals` should be called after generating geometry and before committing the mesh using `godot.SurfaceTool.commit` or `godot.SurfaceTool.commitToArrays`. For correct display of normal-mapped surfaces, you will also have to generate tangents using `godot.SurfaceTool.generateTangents`.
Note: `godot.SurfaceTool.generateNormals` only works if the primitive type to be set to `godot.Mesh_PrimitiveType.triangles`.
**/
@:native("GenerateNormals")
public overload function generateNormals(flip:Bool):Void;
#end
/**
Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already (see `godot.SurfaceTool.generateNormals`).
**/
@:native("GenerateTangents")
public function generateTangents():Void;
/**
Sets `godot.Material` to be used by the `godot.Mesh` you are constructing.
**/
@:native("SetMaterial")
public function setMaterial(material:godot.Material):Void;
/**
Clear all information passed into the surface tool so far.
**/
@:native("Clear")
public function clear():Void;
/**
Creates a vertex array from an existing `godot.Mesh`.
**/
@:native("CreateFrom")
public function createFrom(existing:godot.Mesh, surface:Int):Void;
/**
Creates a vertex array from the specified blend shape of an existing `godot.Mesh`. This can be used to extract a specific pose from a blend shape.
**/
@:native("CreateFromBlendShape")
public function createFromBlendShape(existing:godot.Mesh, surface:Int, blendShape:std.String):Void;
/**
Append vertices from a given `godot.Mesh` surface onto the current vertex array with specified `godot.Transform`.
Note: Using `godot.SurfaceTool.appendFrom` on a `godot.Thread` is much slower as the GPU must communicate data back to the CPU, while also causing the main thread to stall (as OpenGL is not thread-safe). Consider requesting a copy of the mesh, converting it to an `godot.ArrayMesh` and adding vertices manually instead.
**/
@:native("AppendFrom")
public function appendFrom(existing:godot.Mesh, surface:Int, transform:godot.Transform):Void;
#if doc_gen
/**
Returns a constructed `godot.ArrayMesh` from current information passed in. If an existing `godot.ArrayMesh` is passed in as an argument, will add an extra surface to the existing `godot.ArrayMesh`.
Default flag is `godot.Mesh_ArrayFormat.compressDefault` if compression is enabled. If compression is disabled the default flag is `godot.Mesh_ArrayFormat.flagUseOctahedralCompression`. See `ARRAY_COMPRESS_*` constants in `godot.Mesh_ArrayFormat` for other flags.
**/
@:native("Commit")
public function commit(?existing:godot.ArrayMesh, ?flags:UInt):godot.ArrayMesh;
#else
/**
Returns a constructed `godot.ArrayMesh` from current information passed in. If an existing `godot.ArrayMesh` is passed in as an argument, will add an extra surface to the existing `godot.ArrayMesh`.
Default flag is `godot.Mesh_ArrayFormat.compressDefault` if compression is enabled. If compression is disabled the default flag is `godot.Mesh_ArrayFormat.flagUseOctahedralCompression`. See `ARRAY_COMPRESS_*` constants in `godot.Mesh_ArrayFormat` for other flags.
**/
@:native("Commit")
public overload function commit():godot.ArrayMesh;
/**
Returns a constructed `godot.ArrayMesh` from current information passed in. If an existing `godot.ArrayMesh` is passed in as an argument, will add an extra surface to the existing `godot.ArrayMesh`.
Default flag is `godot.Mesh_ArrayFormat.compressDefault` if compression is enabled. If compression is disabled the default flag is `godot.Mesh_ArrayFormat.flagUseOctahedralCompression`. See `ARRAY_COMPRESS_*` constants in `godot.Mesh_ArrayFormat` for other flags.
**/
@:native("Commit")
public overload function commit(existing:godot.ArrayMesh):godot.ArrayMesh;
/**
Returns a constructed `godot.ArrayMesh` from current information passed in. If an existing `godot.ArrayMesh` is passed in as an argument, will add an extra surface to the existing `godot.ArrayMesh`.
Default flag is `godot.Mesh_ArrayFormat.compressDefault` if compression is enabled. If compression is disabled the default flag is `godot.Mesh_ArrayFormat.flagUseOctahedralCompression`. See `ARRAY_COMPRESS_*` constants in `godot.Mesh_ArrayFormat` for other flags.
**/
@:native("Commit")
public overload function commit(existing:godot.ArrayMesh, flags:UInt):godot.ArrayMesh;
#end
/**
Commits the data to the same format used by `godot.ArrayMesh.addSurfaceFromArrays`. This way you can further process the mesh data using the `godot.ArrayMesh` API.
**/
@:native("CommitToArrays")
public function commitToArrays():godot.collections.Array;
}