SurfaceTool¶
Herramienta de ayuda para crear geometría.
Descripción¶
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 add_vertex. For example, to add vertex colors and UVs:
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 add_uv or add_color, then the last values would be used.
Vertex attributes must be passed before calling add_vertex. 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 winding order for front faces of triangle primitive modes.
Tutoriales¶
Métodos¶
void |
add_bones ( PoolIntArray bones ) |
void |
|
void |
|
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 |
|
void |
|
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 ( ) |
commit_to_arrays ( ) |
|
void |
create_from ( Mesh existing, int surface ) |
void |
create_from_blend_shape ( Mesh existing, int surface, String blend_shape ) |
void |
deindex ( ) |
void |
generate_normals ( bool flip=false ) |
void |
|
void |
index ( ) |
void |
set_material ( Material material ) |
Descripciones de Métodos¶
void add_bones ( PoolIntArray bones )
Specifies an array of bones to use for the next vertex. bones
must contain 4 integers.
void add_color ( 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.vertex_color_use_as_albedo enabled for the vertex color to be visible.
void add_index ( int index )
Añade un índice a un array de índices si está usando vértices indexados. No es necesario llamar antes de añadir los vértices.
void add_normal ( 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.
void add_smooth_group ( bool smooth )
Especifica si el vértice actual (si se utilizan sólo arrays de vértices) o el índice actual (si también se utilizan arrays de índices) debe utilizar normales suaves para el cálculo normal.
void add_tangent ( 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.
void add_triangle_fan ( PoolVector3Array vertices, PoolVector2Array uvs=PoolVector2Array( ), PoolColorArray colors=PoolColorArray( ), PoolVector2Array uv2s=PoolVector2Array( ), PoolVector3Array normals=PoolVector3Array( ), Array tangents=[ ] )
Inserta un triangulo fan hecho de un array de datos en la Mesh que se está construyendo.
Requiere que el tipo primitivo se establezca en Mesh.PRIMITIVE_TRIANGLES.
void add_uv ( 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.
void add_uv2 ( 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.
void add_vertex ( Vector3 vertex )
Especifica la posición del vértice actual. Debe ser llamado después de especificar otras propiedades del vértice (por ejemplo, Color, UV).
void add_weights ( 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.
Append vertices from a given Mesh surface onto the current vertex array with specified Transform.
Note: Using append_from on a Thread is much slower as the GPU must communicate data back to the CPU, while also causing the main thread to stall (as OpenGL is not thread-safe). Consider requesting a copy of the mesh, converting it to an ArrayMesh and adding vertices manually instead.
void begin ( PrimitiveType primitive )
Llamado antes de añadir cualquier vértice. Toma el tipo primitivo como argumento (por ejemplo, Mesh.PRIMITIVE_TRIANGLES).
void clear ( )
Despeja toda la información pasada a la herramienta de la superficie hasta ahora.
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 Mesh.ARRAY_COMPRESS_DEFAULT if compression is enabled. If compression is disabled the default flag is Mesh.ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION. See ARRAY_COMPRESS_*
constants in ArrayFormat for other flags.
Array commit_to_arrays ( )
Confirma los datos al mismo formato utilizado por el ArrayMesh.add_surface_from_arrays. De esta manera se puede seguir procesando los datos de la malla usando la API ArrayMesh.
Crea un array de vértices a partir de una Mesh existente.
Crea un array de vértices a partir de la forma de mezcla especificada de una Mesh existente. Esto puede ser usado para extraer una pose específica de una forma de mezcla.
void deindex ( )
Elimina el array de índices expandiendo el array de vértices.
void generate_normals ( bool flip=false )
Generates normals from vertices so you do not have to do it manually. If flip
is true
, the resulting normals will be inverted. generate_normals should be called after generating geometry and before committing the mesh using commit or commit_to_arrays. For correct display of normal-mapped surfaces, you will also have to generate tangents using generate_tangents.
Note: generate_normals only works if the 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 (see generate_normals).
void index ( )
Shrinks the vertex array by creating an index array. This can improve performance by avoiding vertex reuse.
void set_material ( Material material )
Establece Material para ser usado por la Mesh que estás construyendo.