SurfaceTool

Inherits: Reference < Object

Category: Core

Brief Description

Helper tool to create geometry.

Member Functions

void add_bones ( IntArray 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 ( Vector3Array vertexes, Vector2Array uvs=Vector2Array([]), ColorArray colors=ColorArray([ColorArray]), Vector2Array uv2s=Vector2Array([]), Vector3Array normals=Vector3Array([]), Array tangents=Array() )
void add_uv ( Vector2 uv )
void add_uv2 ( Vector2 uv2 )
void add_vertex ( Vector3 vertex )
void add_weights ( RealArray weights )
void begin ( int primitive )
void clear ( )
Mesh commit ( Mesh existing=NULL )
void deindex ( )
void generate_normals ( )
void index ( )
void set_material ( Material material )

Description

The SurfaceTool is used to construct a Mesh 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 add_vertex. For example adding vertex colors and UVs looks like

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 SurfaceTool now contains one vertex of a triangle which has a UV coordinate and a specified Color. If another vertex were added without calls to add_uv or add_color then the last values would be used.

It is very important that vertex attributes are passed before the call to add_vertex, failure to do this will result in an error when committing the vertex information to a mesh.

Member Function Description

Add an array of bones for the next Vertex to use.

  • void add_color ( Color color )

Specify a Color for the next Vertex to use.

  • void add_index ( int index )

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

  • void add_normal ( Vector3 normal )

Specify a normal for the next Vertex to use.

  • 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 ( Plane tangent )

Specify a Tangent for the next Vertex to use.

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

Specify UV Coordinate for next Vertex to use.

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

Specify weight value for next Vertex to use.

  • void begin ( int primitive )

Called before adding any Vertices. Takes the primitive type as an argument (e.g. Mesh.PRIMITIVE_TRIANGLES).

  • void clear ( )

Clear all information passed into the surface tool so far.

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

  • void deindex ( )

Removes index array by expanding Vertex array.

  • void generate_normals ( )

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

  • void index ( )

Shrinks Vertex array by creating an index array. Avoids reusing Vertices.

  • void set_material ( Material material )

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