SurfaceTool¶
Inherits: RefCounted < Object
Helper tool to create geometry.
Description¶
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.set_color(Color(1, 0, 0))
st.set_uv(Vector2(0, 0))
st.add_vertex(Vector3(0, 0, 0))
var st = new SurfaceTool();
st.Begin(Mesh.PrimitiveType.Triangles);
st.SetColor(new Color(1, 0, 0));
st.SetUV(new Vector2(0, 0));
st.AddVertex(new 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 set_uv or set_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, ImmediateMesh and MeshDataTool for procedural geometry generation.
Note: Godot uses clockwise winding order for front faces of triangle primitive modes.
Tutorials¶
Methods¶
void |
|
void |
add_triangle_fan ( PackedVector3Array vertices, PackedVector2Array uvs=PackedVector2Array(), PackedColorArray colors=PackedColorArray(), PackedVector2Array uv2s=PackedVector2Array(), PackedVector3Array normals=PackedVector3Array(), Plane[] tangents=[] ) |
void |
add_vertex ( Vector3 vertex ) |
void |
append_from ( Mesh existing, int surface, Transform3D transform ) |
void |
begin ( PrimitiveType primitive ) |
void |
clear ( ) |
commit_to_arrays ( ) |
|
void |
create_from ( Mesh existing, int surface ) |
void |
create_from_blend_shape ( Mesh existing, int surface, String blend_shape ) |
void |
deindex ( ) |
generate_lod ( float nd_threshold, int target_index_count=3 ) |
|
void |
generate_normals ( bool flip=false ) |
void |
|
get_aabb ( ) const |
|
get_custom_format ( int channel_index ) const |
|
get_primitive_type ( ) const |
|
get_skin_weight_count ( ) const |
|
void |
index ( ) |
void |
|
void |