2017-09-12 22:42:36 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-03-01 01:44:37 +01:00
<class name= "SurfaceTool" inherits= "RefCounted" version= "4.1" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 22:42:36 +02:00
<brief_description >
Helper tool to create geometry.
</brief_description>
<description >
2019-06-22 01:04:47 +02:00
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 [method add_vertex]. For example, to add vertex colors and UVs:
2020-11-28 00:33:15 +01:00
[codeblocks]
[gdscript]
2017-09-12 22:42:36 +02:00
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
2020-12-04 15:54:48 +01:00
st.set_color(Color(1, 0, 0))
st.set_uv(Vector2(0, 0))
2022-02-22 18:43:07 +01:00
st.add_vertex(Vector3(0, 0, 0))
2020-11-28 00:33:15 +01:00
[/gdscript]
[csharp]
var st = new SurfaceTool();
st.Begin(Mesh.PrimitiveType.Triangles);
st.SetColor(new Color(1, 0, 0));
2023-03-29 12:19:34 +02:00
st.SetUV(new Vector2(0, 0));
2022-02-22 18:43:07 +01:00
st.AddVertex(new Vector3(0, 0, 0));
2020-11-28 00:33:15 +01:00
[/csharp]
[/codeblocks]
2020-12-04 15:54:48 +01:00
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 [method set_uv] or [method set_color], then the last values would be used.
2019-06-22 01:04:47 +02:00
Vertex attributes must be passed [b]before[/b] calling [method 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.
2021-06-30 03:55:11 +02:00
See also [ArrayMesh], [ImmediateMesh] and [MeshDataTool] for procedural geometry generation.
2020-04-19 23:21:42 +02:00
[b]Note:[/b] Godot uses clockwise [url=https://learnopengl.com/Advanced-OpenGL/Face-culling]winding order[/url] for front faces of triangle primitive modes.
2017-09-12 22:42:36 +02:00
</description>
<tutorials >
2020-10-01 10:34:47 +02:00
<link title= "3D Voxel Demo" > https://godotengine.org/asset-library/asset/676</link>
2017-09-12 22:42:36 +02:00
</tutorials>
<methods >
<method name= "add_index" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "index" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2022-06-12 01:15:44 +02:00
Adds a vertex to index array if you are using indexed vertices. Does not need to be called before adding vertices.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "add_triangle_fan" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "vertices" type= "PackedVector3Array" />
<param index= "1" name= "uvs" type= "PackedVector2Array" default= "PackedVector2Array()" />
<param index= "2" name= "colors" type= "PackedColorArray" default= "PackedColorArray()" />
<param index= "3" name= "uv2s" type= "PackedVector2Array" default= "PackedVector2Array()" />
<param index= "4" name= "normals" type= "PackedVector3Array" default= "PackedVector3Array()" />
2023-04-25 00:21:32 +02:00
<param index= "5" name= "tangents" type= "Plane[]" default= "[]" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Inserts a triangle fan made of array data into [Mesh] being constructed.
Requires the primitive type be set to [constant Mesh.PRIMITIVE_TRIANGLES].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "add_vertex" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "vertex" type= "Vector3" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Specifies the position of current vertex. Should be called after specifying other vertex properties (e.g. Color, UV).
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "append_from" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "existing" type= "Mesh" />
<param index= "1" name= "surface" type= "int" />
<param index= "2" name= "transform" type= "Transform3D" />
2017-09-12 22:42:36 +02:00
<description >
2020-05-03 10:27:36 +02:00
Append vertices from a given [Mesh] surface onto the current vertex array with specified [Transform3D].
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "begin" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "primitive" type= "int" enum= "Mesh.PrimitiveType" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Called before adding any vertices. Takes the primitive type as an argument (e.g. [constant Mesh.PRIMITIVE_TRIANGLES]).
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "clear" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
Clear all information passed into the surface tool so far.
</description>
</method>
<method name= "commit" >
2021-07-30 15:28:05 +02:00
<return type= "ArrayMesh" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "existing" type= "ArrayMesh" default= "null" />
<param index= "1" name= "flags" type= "int" default= "0" />
2017-09-12 22:42:36 +02:00
<description >
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].
2022-08-10 04:00:19 +02:00
[b]FIXME:[/b] Document possible values for [param flags], it changed in 4.0. Likely some combinations of [enum Mesh.ArrayFormat].
2017-09-12 22:42:36 +02:00
</description>
</method>
2019-05-28 18:08:13 +02:00
<method name= "commit_to_arrays" >
2021-07-30 15:28:05 +02:00
<return type= "Array" />
2019-05-28 18:08:13 +02:00
<description >
2020-01-26 06:59:51 +01:00
Commits the data to the same format used by [method ArrayMesh.add_surface_from_arrays]. This way you can further process the mesh data using the [ArrayMesh] API.
2019-05-28 18:08:13 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "create_from" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "existing" type= "Mesh" />
<param index= "1" name= "surface" type= "int" />
2017-09-12 22:42:36 +02:00
<description >
2018-10-25 15:14:36 +02:00
Creates a vertex array from an existing [Mesh].
2017-09-12 22:42:36 +02:00
</description>
</method>
2019-05-28 18:08:13 +02:00
<method name= "create_from_blend_shape" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "existing" type= "Mesh" />
<param index= "1" name= "surface" type= "int" />
<param index= "2" name= "blend_shape" type= "String" />
2019-05-28 18:08:13 +02:00
<description >
2020-01-26 06:59:51 +01:00
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.
2019-05-28 18:08:13 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "deindex" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2019-06-22 01:04:47 +02:00
Removes the index array by expanding the vertex array.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-01-04 14:33:44 +01:00
<method name= "generate_lod" >
2021-07-30 15:28:05 +02:00
<return type= "PackedInt32Array" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "nd_threshold" type= "float" />
<param index= "1" name= "target_index_count" type= "int" default= "3" />
2021-01-04 14:33:44 +01:00
<description >
2022-08-10 04:00:19 +02:00
Generates a LOD for a given [param nd_threshold] in linear units (square root of quadric error metric), using at most [param target_index_count] indices.
2022-06-12 01:15:44 +02:00
Deprecated. Unused internally and neglects to preserve normals or UVs. Consider using [method ImporterMesh.generate_lods] instead.
2021-01-04 14:33:44 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "generate_normals" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "flip" type= "bool" default= "false" />
2017-09-12 22:42:36 +02:00
<description >
2022-08-10 04:00:19 +02:00
Generates normals from vertices so you do not have to do it manually. If [param flip] is [code]true[/code], the resulting normals will be inverted. [method generate_normals] should be called [i]after[/i] generating geometry and [i]before[/i] committing the mesh using [method commit] or [method commit_to_arrays]. For correct display of normal-mapped surfaces, you will also have to generate tangents using [method generate_tangents].
2021-02-07 16:09:01 +01:00
[b]Note:[/b] [method generate_normals] only works if the primitive type to be set to [constant Mesh.PRIMITIVE_TRIANGLES].
2022-10-29 22:37:09 +02:00
[b]Note:[/b] [method generate_normals] takes smooth groups into account. To generate smooth normals, set the smooth group to a value greater than or equal to [code]0[/code] using [method set_smooth_group] or leave the smooth group at the default of [code]0[/code]. To generate flat normals, set the smooth group to [code]-1[/code] using [method set_smooth_group] prior to adding vertices.
2017-09-12 22:42:36 +02:00
</description>
</method>
<method name= "generate_tangents" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2021-10-01 17:20:25 +02:00
Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already (see [method generate_normals]).
2017-09-12 22:42:36 +02:00
</description>
</method>
2022-06-12 01:15:44 +02:00
<method name= "get_aabb" qualifiers= "const" >
<return type= "AABB" />
2020-12-04 15:54:48 +01:00
<description >
2022-06-12 01:15:44 +02:00
Returns the axis-aligned bounding box of the vertex positions.
2020-12-04 15:54:48 +01:00
</description>
</method>
2022-06-12 01:15:44 +02:00
<method name= "get_custom_format" qualifiers= "const" >
<return type= "int" enum= "SurfaceTool.CustomFormat" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "channel_index" type= "int" />
2021-01-04 14:33:44 +01:00
<description >
2022-08-10 04:00:19 +02:00
Returns the format for custom [param channel_index] (currently up to 4). Returns [constant CUSTOM_MAX] if this custom channel is unused.
2021-01-04 14:33:44 +01:00
</description>
</method>
2022-06-12 01:15:44 +02:00
<method name= "get_primitive_type" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "int" enum= "Mesh.PrimitiveType" />
2021-03-25 12:19:51 +01:00
<description >
2022-06-12 01:15:44 +02:00
Returns the type of mesh geometry, such as [constant Mesh.PRIMITIVE_TRIANGLES].
2021-03-25 12:19:51 +01:00
</description>
</method>
2020-12-04 15:54:48 +01:00
<method name= "get_skin_weight_count" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "int" enum= "SurfaceTool.SkinWeightCount" />
2020-12-04 15:54:48 +01:00
<description >
2022-06-12 01:15:44 +02:00
By default, returns [constant SKIN_4_WEIGHTS] to indicate only 4 bone influences per vertex are used.
Returns [constant SKIN_8_WEIGHTS] if up to 8 influences are used.
[b]Note:[/b] This function returns an enum, not the exact number of weights.
2020-12-04 15:54:48 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "index" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2017-09-12 22:42:36 +02:00
<description >
2020-11-06 22:03:25 +01:00
Shrinks the vertex array by creating an index array. This can improve performance by avoiding vertex reuse.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-01-04 14:33:44 +01:00
<method name= "optimize_indices_for_cache" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2021-01-04 14:33:44 +01:00
<description >
2022-06-12 01:15:44 +02:00
Optimizes triangle sorting for performance. Requires that [method get_primitive_type] is [constant Mesh.PRIMITIVE_TRIANGLES].
2021-01-04 14:33:44 +01:00
</description>
</method>
2020-12-04 15:54:48 +01:00
<method name= "set_bones" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "bones" type= "PackedInt32Array" />
2020-12-04 15:54:48 +01:00
<description >
2022-08-10 04:00:19 +02:00
Specifies an array of bones to use for the [i]next[/i] vertex. [param bones] must contain 4 integers.
2020-12-04 15:54:48 +01:00
</description>
</method>
<method name= "set_color" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "color" type= "Color" />
2020-12-04 15:54:48 +01:00
<description >
2020-11-06 22:03:25 +01:00
Specifies a [Color] to use for the [i]next[/i] 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.
2020-12-04 15:54:48 +01:00
[b]Note:[/b] The material must have [member BaseMaterial3D.vertex_color_use_as_albedo] enabled for the vertex color to be visible.
</description>
</method>
<method name= "set_custom" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "channel_index" type= "int" />
<param index= "1" name= "custom_color" type= "Color" />
2020-12-04 15:54:48 +01:00
<description >
2022-08-10 04:00:19 +02:00
Sets the custom value on this vertex for [param channel_index].
[method set_custom_format] must be called first for this [param channel_index]. Formats which are not RGBA will ignore other color channels.
2020-12-04 15:54:48 +01:00
</description>
</method>
<method name= "set_custom_format" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "channel_index" type= "int" />
<param index= "1" name= "format" type= "int" enum= "SurfaceTool.CustomFormat" />
2020-12-04 15:54:48 +01:00
<description >
2022-08-10 04:00:19 +02:00
Sets the color format for this custom [param channel_index]. Use [constant CUSTOM_MAX] to disable.
2022-06-12 01:15:44 +02:00
Must be invoked after [method begin] and should be set before [method commit] or [method commit_to_arrays].
2020-12-04 15:54:48 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "set_material" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "material" type= "Material" />
2017-09-12 22:42:36 +02:00
<description >
Sets [Material] to be used by the [Mesh] you are constructing.
</description>
</method>
2020-12-04 15:54:48 +01:00
<method name= "set_normal" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "normal" type= "Vector3" />
2020-12-04 15:54:48 +01:00
<description >
2020-11-06 22:03:25 +01:00
Specifies a normal to use for the [i]next[/i] 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.
2020-12-04 15:54:48 +01:00
</description>
</method>
<method name= "set_skin_weight_count" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "count" type= "int" enum= "SurfaceTool.SkinWeightCount" />
2020-12-04 15:54:48 +01:00
<description >
2022-06-12 01:15:44 +02:00
Set to [constant SKIN_8_WEIGHTS] to indicate that up to 8 bone influences per vertex may be used.
By default, only 4 bone influences are used ([constant SKIN_4_WEIGHTS])
[b]Note:[/b] This function takes an enum, not the exact number of weights.
2020-12-04 15:54:48 +01:00
</description>
</method>
2021-01-04 14:33:44 +01:00
<method name= "set_smooth_group" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "index" type= "int" />
2021-01-04 14:33:44 +01:00
<description >
2022-10-29 22:37:09 +02:00
Specifies the smooth group to use for the [i]next[/i] vertex. If this is never called, all vertices will have the default smooth group of [code]0[/code] and will be smoothed with adjacent vertices of the same group. To produce a mesh with flat normals, set the smooth group to [code]-1[/code].
2023-05-28 18:10:39 +02:00
[b]Note:[/b] This function actually takes a [code]uint32_t[/code], so C# users should use [code]uint32.MaxValue[/code] instead of [code]-1[/code] to produce a mesh with flat normals.
2021-01-04 14:33:44 +01:00
</description>
</method>
2020-12-04 15:54:48 +01:00
<method name= "set_tangent" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "tangent" type= "Plane" />
2020-12-04 15:54:48 +01:00
<description >
2020-11-06 22:03:25 +01:00
Specifies a tangent to use for the [i]next[/i] 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.
2020-12-04 15:54:48 +01:00
</description>
</method>
<method name= "set_uv" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "uv" type= "Vector2" />
2020-12-04 15:54:48 +01:00
<description >
2020-11-06 22:03:25 +01:00
Specifies a set of UV coordinates to use for the [i]next[/i] 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.
2020-12-04 15:54:48 +01:00
</description>
</method>
<method name= "set_uv2" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "uv2" type= "Vector2" />
2020-12-04 15:54:48 +01:00
<description >
2020-11-06 22:03:25 +01:00
Specifies an optional second set of UV coordinates to use for the [i]next[/i] 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.
2020-12-04 15:54:48 +01:00
</description>
</method>
<method name= "set_weights" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "weights" type= "PackedFloat32Array" />
2020-12-04 15:54:48 +01:00
<description >
2022-08-10 04:00:19 +02:00
Specifies weight values to use for the [i]next[/i] vertex. [param 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.
2020-12-04 15:54:48 +01:00
</description>
</method>
2017-09-12 22:42:36 +02:00
</methods>
<constants >
2020-12-04 15:54:48 +01:00
<constant name= "CUSTOM_RGBA8_UNORM" value= "0" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Limits range of data passed to [method set_custom] to unsigned normalized 0 to 1 stored in 8 bits per channel. See [constant Mesh.ARRAY_CUSTOM_RGBA8_UNORM].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_RGBA8_SNORM" value= "1" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Limits range of data passed to [method set_custom] to signed normalized -1 to 1 stored in 8 bits per channel. See [constant Mesh.ARRAY_CUSTOM_RGBA8_SNORM].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_RG_HALF" value= "2" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Stores data passed to [method set_custom] as half precision floats, and uses only red and green color channels. See [constant Mesh.ARRAY_CUSTOM_RG_HALF].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_RGBA_HALF" value= "3" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Stores data passed to [method set_custom] as half precision floats and uses all color channels. See [constant Mesh.ARRAY_CUSTOM_RGBA_HALF].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_R_FLOAT" value= "4" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Stores data passed to [method set_custom] as full precision floats, and uses only red color channel. See [constant Mesh.ARRAY_CUSTOM_R_FLOAT].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_RG_FLOAT" value= "5" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Stores data passed to [method set_custom] as full precision floats, and uses only red and green color channels. See [constant Mesh.ARRAY_CUSTOM_RG_FLOAT].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_RGB_FLOAT" value= "6" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Stores data passed to [method set_custom] as full precision floats, and uses only red, green and blue color channels. See [constant Mesh.ARRAY_CUSTOM_RGB_FLOAT].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_RGBA_FLOAT" value= "7" enum= "CustomFormat" >
2022-11-01 15:29:38 +01:00
Stores data passed to [method set_custom] as full precision floats, and uses all color channels. See [constant Mesh.ARRAY_CUSTOM_RGBA_FLOAT].
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "CUSTOM_MAX" value= "8" enum= "CustomFormat" >
2022-06-12 01:15:44 +02:00
Used to indicate a disabled custom channel.
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "SKIN_4_WEIGHTS" value= "0" enum= "SkinWeightCount" >
2022-06-12 01:15:44 +02:00
Each individual vertex can be influenced by only 4 bone weights.
2020-12-04 15:54:48 +01:00
</constant>
<constant name= "SKIN_8_WEIGHTS" value= "1" enum= "SkinWeightCount" >
2022-06-12 01:15:44 +02:00
Each individual vertex can be influenced by up to 8 bone weights.
2020-12-04 15:54:48 +01:00
</constant>
2017-09-12 22:42:36 +02:00
</constants>
</class>