:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.5/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/SurfaceTool.xml. .. _class_SurfaceTool: SurfaceTool =========== **Inherits:** :ref:`Reference` **<** :ref:`Object` Helper tool to create geometry. .. rst-class:: classref-introduction-group Description ----------- The **SurfaceTool** is used to construct a :ref:`Mesh` by specifying vertex attributes individually. It can be used to construct a :ref:`Mesh` from a script. All properties except indices need to be added before calling :ref:`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 :ref:`Color`. If another vertex were added without calling :ref:`add_uv` or :ref:`add_color`, then the last values would be used. Vertex attributes must be passed **before** calling :ref:`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 :ref:`ArrayMesh`, :ref:`ImmediateGeometry` and :ref:`MeshDataTool` for procedural geometry generation. \ **Note:** Godot uses clockwise `winding order `__ for front faces of triangle primitive modes. .. rst-class:: classref-introduction-group Tutorials --------- - `3D Voxel Demo `__ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_bones` **(** :ref:`PoolIntArray` bones **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_color` **(** :ref:`Color` color **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_index` **(** :ref:`int` index **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_normal` **(** :ref:`Vector3` normal **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_smooth_group` **(** :ref:`bool` smooth **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_tangent` **(** :ref:`Plane` tangent **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_triangle_fan` **(** :ref:`PoolVector3Array` vertices, :ref:`PoolVector2Array` uvs=PoolVector2Array( ), :ref:`PoolColorArray` colors=PoolColorArray( ), :ref:`PoolVector2Array` uv2s=PoolVector2Array( ), :ref:`PoolVector3Array` normals=PoolVector3Array( ), :ref:`Array` tangents=[ ] **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_uv` **(** :ref:`Vector2` uv **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_uv2` **(** :ref:`Vector2` uv2 **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_vertex` **(** :ref:`Vector3` vertex **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_weights` **(** :ref:`PoolRealArray` weights **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`append_from` **(** :ref:`Mesh` existing, :ref:`int` surface, :ref:`Transform` transform **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`begin` **(** :ref:`PrimitiveType` primitive **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear` **(** **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`ArrayMesh` | :ref:`commit` **(** :ref:`ArrayMesh` existing=null, :ref:`int` flags=2194432 **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`commit_to_arrays` **(** **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`create_from` **(** :ref:`Mesh` existing, :ref:`int` surface **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`create_from_blend_shape` **(** :ref:`Mesh` existing, :ref:`int` surface, :ref:`String` blend_shape **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`deindex` **(** **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`generate_normals` **(** :ref:`bool` flip=false **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`generate_tangents` **(** **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`index` **(** **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_material` **(** :ref:`Material` material **)** | +-----------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_SurfaceTool_method_add_bones: .. rst-class:: classref-method void **add_bones** **(** :ref:`PoolIntArray` bones **)** Specifies an array of bones to use for the *next* vertex. ``bones`` must contain 4 integers. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_color: .. rst-class:: classref-method void **add_color** **(** :ref:`Color` color **)** Specifies a :ref:`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 :ref:`SpatialMaterial.vertex_color_use_as_albedo` enabled for the vertex color to be visible. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_index: .. rst-class:: classref-method void **add_index** **(** :ref:`int` index **)** Adds an index to index array if you are using indexed vertices. Does not need to be called before adding vertices. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_normal: .. rst-class:: classref-method void **add_normal** **(** :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_smooth_group: .. rst-class:: classref-method void **add_smooth_group** **(** :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_tangent: .. rst-class:: classref-method void **add_tangent** **(** :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_triangle_fan: .. rst-class:: classref-method void **add_triangle_fan** **(** :ref:`PoolVector3Array` vertices, :ref:`PoolVector2Array` uvs=PoolVector2Array( ), :ref:`PoolColorArray` colors=PoolColorArray( ), :ref:`PoolVector2Array` uv2s=PoolVector2Array( ), :ref:`PoolVector3Array` normals=PoolVector3Array( ), :ref:`Array` tangents=[ ] **)** Inserts a triangle fan made of array data into :ref:`Mesh` being constructed. Requires the primitive type be set to :ref:`Mesh.PRIMITIVE_TRIANGLES`. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_uv: .. rst-class:: classref-method void **add_uv** **(** :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_uv2: .. rst-class:: classref-method void **add_uv2** **(** :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_vertex: .. rst-class:: classref-method void **add_vertex** **(** :ref:`Vector3` vertex **)** Specifies the position of current vertex. Should be called after specifying other vertex properties (e.g. Color, UV). .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_add_weights: .. rst-class:: classref-method void **add_weights** **(** :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_append_from: .. rst-class:: classref-method void **append_from** **(** :ref:`Mesh` existing, :ref:`int` surface, :ref:`Transform` transform **)** Append vertices from a given :ref:`Mesh` surface onto the current vertex array with specified :ref:`Transform`. \ **Note:** Using :ref:`append_from` on a :ref:`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 :ref:`ArrayMesh` and adding vertices manually instead. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_begin: .. rst-class:: classref-method void **begin** **(** :ref:`PrimitiveType` primitive **)** Called before adding any vertices. Takes the primitive type as an argument (e.g. :ref:`Mesh.PRIMITIVE_TRIANGLES`). .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_clear: .. rst-class:: classref-method void **clear** **(** **)** Clear all information passed into the surface tool so far. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_commit: .. rst-class:: classref-method :ref:`ArrayMesh` **commit** **(** :ref:`ArrayMesh` existing=null, :ref:`int` flags=2194432 **)** Returns a constructed :ref:`ArrayMesh` from current information passed in. If an existing :ref:`ArrayMesh` is passed in as an argument, will add an extra surface to the existing :ref:`ArrayMesh`. Default flag is :ref:`Mesh.ARRAY_COMPRESS_DEFAULT` if compression is enabled. If compression is disabled the default flag is :ref:`Mesh.ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION`. See ``ARRAY_COMPRESS_*`` constants in :ref:`ArrayFormat` for other flags. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_commit_to_arrays: .. rst-class:: classref-method :ref:`Array` **commit_to_arrays** **(** **)** Commits the data to the same format used by :ref:`ArrayMesh.add_surface_from_arrays`. This way you can further process the mesh data using the :ref:`ArrayMesh` API. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_create_from: .. rst-class:: classref-method void **create_from** **(** :ref:`Mesh` existing, :ref:`int` surface **)** Creates a vertex array from an existing :ref:`Mesh`. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_create_from_blend_shape: .. rst-class:: classref-method void **create_from_blend_shape** **(** :ref:`Mesh` existing, :ref:`int` surface, :ref:`String` blend_shape **)** Creates a vertex array from the specified blend shape of an existing :ref:`Mesh`. This can be used to extract a specific pose from a blend shape. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_deindex: .. rst-class:: classref-method void **deindex** **(** **)** Removes the index array by expanding the vertex array. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_generate_normals: .. rst-class:: classref-method void **generate_normals** **(** :ref:`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. :ref:`generate_normals` should be called *after* generating geometry and *before* committing the mesh using :ref:`commit` or :ref:`commit_to_arrays`. For correct display of normal-mapped surfaces, you will also have to generate tangents using :ref:`generate_tangents`. \ **Note:** :ref:`generate_normals` only works if the primitive type to be set to :ref:`Mesh.PRIMITIVE_TRIANGLES`. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_generate_tangents: .. rst-class:: classref-method void **generate_tangents** **(** **)** Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already (see :ref:`generate_normals`). .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_index: .. rst-class:: classref-method void **index** **(** **)** Shrinks the vertex array by creating an index array. This can improve performance by avoiding vertex reuse. .. rst-class:: classref-item-separator ---- .. _class_SurfaceTool_method_set_material: .. rst-class:: classref-method void **set_material** **(** :ref:`Material` material **)** Sets :ref:`Material` to be used by the :ref:`Mesh` you are constructing. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`