SurfaceTool

    Helper tool to create geometry.

    The is used to construct a 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 . For example, to add vertex colors and UVs:

    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 or add_color, then the last values would be used.

    Vertex attributes must be passed before calling . 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, and MeshDataTool for procedural geometry generation.

    Note: Godot uses clockwise for front faces of triangle primitive modes.

    • void add_bones ( bones )

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


    • void add_color ( Color color )

    Specifies a for the next vertex to use.

    Note: The material must have SpatialMaterial.vertex_color_use_as_albedo enabled for the vertex color to be visible.


    • void add_index ( index )

    Specifies a normal for the next vertex to use.


    • void add_smooth_group ( 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.


    • void add_tangent ( tangent )

    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 .


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


    • void add_uv2 ( uv2 )

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


    • void add_vertex ( Vector3 vertex )

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


    • void add_weights ( weights )

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


    • void append_from ( Mesh existing, surface, Transform transform )

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



    • void clear ( )

    Clear all information passed into the surface tool so far.


    • commit ( ArrayMesh existing=null, flags=97280 )

    Returns a constructed ArrayMesh from current information passed in. If an existing is passed in as an argument, will add an extra surface to the existing ArrayMesh.

    Default flag is . See constants in ArrayFormat for other flags.


    • commit_to_arrays ( )

    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 API.


    • void create_from ( Mesh existing, surface )

    Creates a vertex array from an existing Mesh.


    • void create_from_blend_shape ( existing, int surface, blend_shape )

    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.


    • void deindex ( )

    Removes the index array by expanding the vertex array.


    • void generate_normals ( flip=false )

    Generates normals from vertices so you do not have to do it manually. If flip is , the resulting normals will be inverted.

    Requires the primitive type to be set to Mesh.PRIMITIVE_TRIANGLES.


    • void generate_tangents ( )

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



    • void set_material ( material )

    Sets Material to be used by the you are constructing.