SurfaceTool

Helper tool to create geometry.

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

More...

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Functions

addBones
void addBones(PoolIntArray bones)

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

addColor
void addColor(Color color)

Specifies a Color to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all. Note: The material must have SpatialMaterial.vertexColorUseAsAlbedo enabled for the vertex color to be visible.

addIndex
void addIndex(long index)

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

addNormal
void addNormal(Vector3 normal)

Specifies a normal to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.

addSmoothGroup
void addSmoothGroup(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.

addTangent
void addTangent(Plane tangent)

Specifies a tangent to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.

addTriangleFan
void addTriangleFan(PoolVector3Array vertices, PoolVector2Array uvs, PoolColorArray colors, PoolVector2Array uv2s, PoolVector3Array normals, Array tangents)

Inserts a triangle fan made of array data into Mesh being constructed. Requires the primitive type be set to constant Mesh.PRIMITIVE_TRIANGLES.

addUv
void addUv(Vector2 uv)

Specifies a set of UV coordinates to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.

addUv2
void addUv2(Vector2 uv2)

Specifies an optional second set of UV coordinates to use for the next vertex. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.

addVertex
void addVertex(Vector3 vertex)

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

addWeights
void addWeights(PoolRealArray weights)

Specifies weight values to use for the next vertex. weights must contain 4 values. If every vertex needs to have this information set and you fail to submit it for the first vertex, this information may not be used at all.

appendFrom
void appendFrom(Mesh existing, long surface, Transform transform)

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

begin
void begin(long primitive)

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

clear
void clear()

Clear all information passed into the surface tool so far.

commit
Ref!ArrayMesh commit(ArrayMesh existing, long flags)

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. Default flag is constant Mesh.ARRAY_COMPRESS_DEFAULT. See ARRAY_COMPRESS_* constants in Mesh.arrayformat for other flags.

commitToArrays
Array commitToArrays()

Commits the data to the same format used by ArrayMesh.addSurfaceFromArrays. This way you can further process the mesh data using the ArrayMesh API.

createFrom
void createFrom(Mesh existing, long surface)

Creates a vertex array from an existing Mesh.

createFromBlendShape
void createFromBlendShape(Mesh existing, long surface, String 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.

deindex
void deindex()

Removes the index array by expanding the vertex array.

generateNormals
void generateNormals(bool flip)

Generates normals from vertices so you do not have to do it manually. If flip is true, the resulting normals will be inverted. generateNormals should be called after generating geometry and before committing the mesh using commit or commitToArrays. Note: generateNormals only works if the primitive type to be set to constant Mesh.PRIMITIVE_TRIANGLES.

generateTangents
void generateTangents()

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

index
void index()

Shrinks the vertex array by creating an index array. This can improve performance by avoiding vertex reuse.

opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(SurfaceTool other)
opEquals
bool opEquals(typeof(null) n)
setMaterial
void setMaterial(Material material)

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

toHash
size_t toHash()

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Static functions

_new
SurfaceTool _new()

Construct a new instance of SurfaceTool. Note: use memnew!SurfaceTool instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Detailed Description

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 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 addUv or addColor, then the last values would be used. Vertex attributes must be passed before calling addVertex. 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, ImmediateGeometry and MeshDataTool for procedural geometry generation. Note: Godot uses clockwise url=https://learnopengl.com/Advanced-OpenGL/Face-cullingwinding order/url for front faces of triangle primitive modes.

Meta