SurfaceTool

    Category: Core

    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 script. All properties except index need to be added before a call to . For example adding vertex colors and UVs looks like

    The now contains one vertex of a triangle which has a UV coordinate and a specified Color. If another vertex were added without calls to or add_color then the last values would be used.

    It is very important that vertex attributes are passed before the call to , failure to do this 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.

    Add an array of bones for the next Vertex to use. Array must contain 4 integers.


    • void add_color ( color )

    Specify a Color for the next Vertex to use.


    • void add_index ( index )

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



    • void add_smooth_group ( bool smooth )

    Specify whether current Vertex (if using only Vertex arrays) or current index (if also using index arrays) should utilize smooth normals for normal calculation.


    • void add_tangent ( tangent )

    Specify a Tangent for the next Vertex to use.


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

    Requires primitive type be set to .


    Specify UV Coordinate for next Vertex to use.


    • void add_uv2 ( uv2 )

    Specify an optional second set of UV coordinates for next Vertex to use.


    • void add_vertex ( Vector3 vertex )

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


    • void add_weights ( weights )

    Specify weight values for next Vertex to use. Array must contain 4 values.


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



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


    • void create_from ( existing, int surface )

    Creates a vertex array from an existing .


    • void deindex ( )

    Removes index array by expanding Vertex array.


    • void generate_normals ( bool flip=false )

    Generates normals from Vertices so you do not have to do it manually.

    Setting to inverts the resulting normals.

    Requires primitive type to be set to .


    • void generate_tangents ( )

    Generates a tangent vector for each vertex.

    Requires that each vertex have UVs and normals set already.



    • void set_material ( Material material )

    Sets to be used by the Mesh you are constructing.