W3cubDocs

/Godot 3.0

SurfaceTool

Inherits: Reference < Object

Category: Core

Brief Description

Helper tool to create geometry.

Member Functions

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_to_format ( int flags )
void add_triangle_fan ( PoolVector3Array vertexes, 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 ( int primitive )
void clear ( )
ArrayMesh commit ( ArrayMesh existing=null, int flags=97792 )
void create_from ( Mesh existing, int surface )
void deindex ( )
void generate_normals ( )
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.

Member Function Description

void add_bones ( PoolIntArray bones )

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.

void add_to_format ( int flags )

void add_triangle_fan ( PoolVector3Array vertexes, PoolVector2Array uvs=PoolVector2Array( ), PoolColorArray colors=PoolColorArray( ), PoolVector2Array uv2s=PoolVector2Array( ), PoolVector3Array normals=PoolVector3Array( ), Array tangents=[ ] )

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

void add_uv ( Vector2 uv )

Specify UV Coordinate for next Vertex to use.

void add_uv2 ( Vector2 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 ( PoolRealArray weights )

Specify weight value for next Vertex to use.

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

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.

ArrayMesh commit ( ArrayMesh existing=null, int flags=97792 )

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 )

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

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.

© 2014–2018 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.
http://docs.godotengine.org/en/3.0/classes/class_surfacetool.html