SurfaceTool

Inherits: Reference < Object

Category: Core

Brief Description

Helper tool to create geometry.

Methods

void add_bones ( PoolIntArray 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 ( PoolVector3Array vertices, PoolVector2Array uvs=PoolVector2Array( ), PoolColorArray colors=PoolColorArray( ), PoolVector2Array uv2s=PoolVector2Array( ), PoolVector3Array normals=PoolVector3Array( ), Array tangents=[ ] )
void add_uv ( Vector2 uv )
void add_uv2 ( Vector2 uv2 )
void add_vertex ( Vector3 vertex )
void add_weights ( PoolRealArray weights )
void append_from ( Mesh existing, int surface, Transform transform )
void begin ( PrimitiveType primitive )
void clear ( )
ArrayMesh commit ( ArrayMesh existing=null, int flags=97280 )
void create_from ( Mesh existing, int surface )
void deindex ( )
void generate_normals ( bool flip=false )
void generate_tangents ( )
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.

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.

Method Descriptions

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


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

Requires primitive type be set to Mesh.PRIMITIVE_TRIANGLES.


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


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 ArrayMesh from current information passed in. If an existing ArrayMesh is passed in as an argument, will add an extra surface to the existing ArrayMesh.


  • void create_from ( Mesh existing, int surface )

Creates a vertex array from an existing Mesh.


  • 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 flip to true inverts the resulting normals.

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