Struct SurfaceTool
Helper tool to create geometry.
struct SurfaceTool
;
The SurfaceTool
is used to construct a Mesh
by specifying vertex attributes individually. It can be used to construct a Mesh
from a script. All properties except indices need to be added before calling 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 SurfaceTool
now contains one vertex of a triangle which has a UV coordinate and a specified Color
. If another vertex were added without calling addUv
or addColor
, then the last values would be used.
Vertex attributes must be passed before calling 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.
Methods
Name | Description |
---|---|
addBones
|
Adds an array of bones for the next vertex to use. bones must contain 4 integers.
|
addColor
|
Specifies a Color for the next vertex to use.
|
addIndex
|
Adds an index to index array if you are using indexed vertices. Does not need to be called before adding vertices. |
addNormal
|
Specifies a normal for the next vertex to use. |
addSmoothGroup
|
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. |
addTangent
|
Specifies a tangent for the next vertex to use. |
addTriangleFan
|
Inserts a triangle fan made of array data into Mesh being constructed.
Requires the primitive type be set to constant Mesh .
|
addUv
|
Specifies a set of UV coordinates to use for the next vertex. |
addUv2
|
Specifies an optional second set of UV coordinates to use for the next vertex. |
addVertex
|
Specifies the position of current vertex. Should be called after specifying other vertex properties (e.g. Color, UV). |
addWeights
|
Specifies weight values for next vertex to use. weights must contain 4 values.
|
appendFrom
|
Append vertices from a given Mesh surface onto the current vertex array with specified Transform .
|
begin
|
Called before adding any vertices. Takes the primitive type as an argument (e.g. constant Mesh ).
|
clear
|
Clear all information passed into the surface tool so far. |
commit
|
Returns a constructed ArrayMesh from current information passed in. If an existing ArrayMesh is passed in as an argument, will add an extra surface to the existing ArrayMesh .
Default flag is constant Mesh . See ARRAY_COMPRESS_* constants in Mesh for other flags.
|
commitToArrays
|
Commits the data to the same format used by ArrayMesh . This way you can further process the mesh data using the ArrayMesh API.
|
createFrom
|
Creates a vertex array from an existing Mesh .
|
createFromBlendShape
|
Creates a vertex array from the specified blend shape of an existing Mesh . This can be used to extract a specific pose from a blend shape.
|
deindex
|
Removes the index array by expanding the vertex array. |
generateNormals
|
Generates normals from vertices so you do not have to do it manually. If flip is true , the resulting normals will be inverted.
Requires the primitive type to be set to constant Mesh .
|
generateTangents
|
Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already. |
index
|
Shrinks the vertex array by creating an index array (avoids reusing vertices). |
setMaterial
|
Sets Material to be used by the Mesh you are constructing.
|