Helper tool to create geometry.
    public class SurfaceTool : Reference

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(Godot.Vector3). For example, to add vertex colors and UVs:

[codeblock]

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))

[/codeblock]

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(Godot.Vector2) or AddColor(Godot.Color), then the last values would be used.

Vertex attributes must be passed before calling AddVertex(Godot.Vector3). 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.

Inheritance Chain

Constructors

    public SurfaceTool()

Methods

    public void AddBones(int[] bones)

Adds an array of bones for the next vertex to use. bones must contain 4 integers.

    public void AddColor(Color color)

Specifies a Color for the next vertex to use.

    public void AddIndex(int index)

Adds an index to index array if you are using indexed vertices. Does not need to be called before adding vertices.

    public void AddNormal(Vector3 normal)

Specifies a normal for the next vertex to use.

    public void AddSmoothGroup(bool smooth)

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.

    public void AddTangent(Plane tangent)

Specifies a tangent for the next vertex to use.

    public void AddTriangleFan(Vector3[] vertices, Vector2[] uvs = null, Color[] colors = null, Vector2[] uv2s = null, Vector3[] normals = null, Godot.Collections.Array tangents = null)

Inserts a triangle fan made of array data into Mesh being constructed.

Requires the primitive type be set to [constant Mesh.PRIMITIVE_TRIANGLES].

    public void AddUv(Vector2 uv)

Specifies a set of UV coordinates to use for the next vertex.

    public void AddUv2(Vector2 uv2)

Specifies an optional second set of UV coordinates to use for the next vertex.

    public void AddVertex(Vector3 vertex)

Specifies the position of current vertex. Should be called after specifying other vertex properties (e.g. Color, UV).

    public void AddWeights(float[] weights)

Specifies weight values for next vertex to use. weights must contain 4 values.

    public void AppendFrom(Mesh existing, int surface, Transform transform)

Append vertices from a given Mesh surface onto the current vertex array with specified Transform.

    public void Begin(Mesh.PrimitiveType primitive)

Called before adding any vertices. Takes the primitive type as an argument (e.g. [constant Mesh.PRIMITIVE_TRIANGLES]).

    public void Clear()

Clear all information passed into the surface tool so far.

    public ArrayMesh Commit(ArrayMesh existing = null, uint flags = 97280u)

    public Godot.Collections.Array CommitToArrays()

    public void CreateFrom(Mesh existing, int surface)

Creates a vertex array from an existing Mesh.

    public void CreateFromBlendShape(Mesh existing, int surface, string blendShape)

    public void Deindex()

Removes the index array by expanding the vertex array.

    public void GenerateNormals(bool flip = false)

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.PRIMITIVE_TRIANGLES].

    public void GenerateTangents()

Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already.

    public void Index()

Shrinks the vertex array by creating an index array (avoids reusing vertices).

    public void SetMaterial(Material material)

Sets Material to be used by the Mesh you are constructing.

Tags: