Helper tool to create geometry.
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 add_vertex. 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 add_uv or add_color, then the last values would be used.
Vertex attributes must be passed before calling add_vertex. 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 ArrayMesh, ImmediateGeometry and MeshDataTool for procedural geometry generation.
Note: Godot uses clockwise winding order for front faces of triangle primitive modes.
void | add_bones ( PoolIntArray bones ) |
void | add_color ( Color color ) |
void | add_index ( int index ) |
void | add_normal ( Vector3 normal ) |
void | add_smooth_group ( bool smooth ) |
void | add_tangent ( Plane tangent ) |
void | add_triangle_fan ( PoolVector3Array vertices, PoolVector2Array uvs=PoolVector2Array( ), PoolColorArray colors=PoolColorArray( ), PoolVector2Array uv2s=PoolVector2Array( ), PoolVector3Array normals=PoolVector3Array( ), Array tangents=[ ] ) |
void | add_uv ( Vector2 uv ) |
void | add_uv2 ( Vector2 uv2 ) |
void | add_vertex ( Vector3 vertex ) |
void | add_weights ( PoolRealArray weights ) |
void | append_from ( Mesh existing, int surface, Transform transform ) |
void | begin ( PrimitiveType primitive ) |
void | clear ( ) |
ArrayMesh | commit ( ArrayMesh existing=null, int flags=97280 ) |
Array | commit_to_arrays ( ) |
void | create_from ( Mesh existing, int surface ) |
void | create_from_blend_shape ( Mesh existing, int surface, String blend_shape ) |
void | deindex ( ) |
void | generate_normals ( bool flip=false ) |
void | generate_tangents ( ) |
void | index ( ) |
void | set_material ( Material material ) |
Adds an array of bones for the next vertex to use. bones
must contain 4 integers.
Specifies a Color for the next vertex to use.
Adds an index to index array if you are using indexed vertices. Does not need to be called before adding vertices.
Specifies a normal for the next vertex to use.
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.
Specifies a tangent for the next vertex to use.
Inserts a triangle fan made of array data into Mesh being constructed.
Requires the primitive type be set to Mesh.PRIMITIVE_TRIANGLES.
Specifies a set of UV coordinates to use for the next vertex.
Specifies an optional second set of UV coordinates to use for the next vertex.
Specifies the position of current vertex. Should be called after specifying other vertex properties (e.g. Color, UV).
Specifies weight values for next vertex to use. weights
must contain 4 values.
Append vertices from a given Mesh surface onto the current vertex array with specified Transform.
Called before adding any vertices. Takes the primitive type as an argument (e.g. Mesh.PRIMITIVE_TRIANGLES).
Clear all information passed into the surface tool so far.
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 Mesh.ARRAY_COMPRESS_DEFAULT. See ARRAY_COMPRESS_*
constants in ArrayFormat for other flags.
Commits the data to the same format used by ArrayMesh.add_surface_from_arrays. This way you can further process the mesh data using the ArrayMesh API.
Creates a vertex array from an existing Mesh.
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.
Removes the index array by expanding the vertex array.
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 Mesh.PRIMITIVE_TRIANGLES.
Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already.
Shrinks the vertex array by creating an index array (avoids reusing vertices).
Sets Material to be used by the Mesh you are constructing.
© 2014–2020 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.
https://docs.godotengine.org/en/3.2/classes/class_surfacetool.html