class_surfacetool.rst 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/SurfaceTool.xml.
  6. .. _class_SurfaceTool:
  7. SurfaceTool
  8. ===========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Helper tool to create geometry.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. The **SurfaceTool** is used to construct a :ref:`Mesh<class_Mesh>` by specifying vertex attributes individually. It can be used to construct a :ref:`Mesh<class_Mesh>` from a script. All properties except indices need to be added before calling :ref:`add_vertex<class_SurfaceTool_method_add_vertex>`. For example, to add vertex colors and UVs:
  15. .. tabs::
  16. .. code-tab:: gdscript
  17. var st = SurfaceTool.new()
  18. st.begin(Mesh.PRIMITIVE_TRIANGLES)
  19. st.set_color(Color(1, 0, 0))
  20. st.set_uv(Vector2(0, 0))
  21. st.add_vertex(Vector3(0, 0, 0))
  22. .. code-tab:: csharp
  23. var st = new SurfaceTool();
  24. st.Begin(Mesh.PrimitiveType.Triangles);
  25. st.SetColor(new Color(1, 0, 0));
  26. st.SetUV(new Vector2(0, 0));
  27. st.AddVertex(new Vector3(0, 0, 0));
  28. The above **SurfaceTool** now contains one vertex of a triangle which has a UV coordinate and a specified :ref:`Color<class_Color>`. If another vertex were added without calling :ref:`set_uv<class_SurfaceTool_method_set_uv>` or :ref:`set_color<class_SurfaceTool_method_set_color>`, then the last values would be used.
  29. Vertex attributes must be passed **before** calling :ref:`add_vertex<class_SurfaceTool_method_add_vertex>`. Failure to do so will result in an error when committing the vertex information to a mesh.
  30. 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.
  31. See also :ref:`ArrayMesh<class_ArrayMesh>`, :ref:`ImmediateMesh<class_ImmediateMesh>` and :ref:`MeshDataTool<class_MeshDataTool>` for procedural geometry generation.
  32. \ **Note:** Godot uses clockwise `winding order <https://learnopengl.com/Advanced-OpenGL/Face-culling>`__ for front faces of triangle primitive modes.
  33. .. rst-class:: classref-introduction-group
  34. Tutorials
  35. ---------
  36. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  37. .. rst-class:: classref-reftable-group
  38. Methods
  39. -------
  40. .. table::
  41. :widths: auto
  42. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`add_index<class_SurfaceTool_method_add_index>` **(** :ref:`int<class_int>` index **)** |
  44. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`add_triangle_fan<class_SurfaceTool_method_add_triangle_fan>` **(** :ref:`PackedVector3Array<class_PackedVector3Array>` vertices, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs=PackedVector2Array(), :ref:`PackedColorArray<class_PackedColorArray>` colors=PackedColorArray(), :ref:`PackedVector2Array<class_PackedVector2Array>` uv2s=PackedVector2Array(), :ref:`PackedVector3Array<class_PackedVector3Array>` normals=PackedVector3Array(), :ref:`Array<class_Array>` tangents=[] **)** |
  46. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`add_vertex<class_SurfaceTool_method_add_vertex>` **(** :ref:`Vector3<class_Vector3>` vertex **)** |
  48. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`append_from<class_SurfaceTool_method_append_from>` **(** :ref:`Mesh<class_Mesh>` existing, :ref:`int<class_int>` surface, :ref:`Transform3D<class_Transform3D>` transform **)** |
  50. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`begin<class_SurfaceTool_method_begin>` **(** :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` primitive **)** |
  52. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`clear<class_SurfaceTool_method_clear>` **(** **)** |
  54. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`ArrayMesh<class_ArrayMesh>` | :ref:`commit<class_SurfaceTool_method_commit>` **(** :ref:`ArrayMesh<class_ArrayMesh>` existing=null, :ref:`int<class_int>` flags=0 **)** |
  56. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Array<class_Array>` | :ref:`commit_to_arrays<class_SurfaceTool_method_commit_to_arrays>` **(** **)** |
  58. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`create_from<class_SurfaceTool_method_create_from>` **(** :ref:`Mesh<class_Mesh>` existing, :ref:`int<class_int>` surface **)** |
  60. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`create_from_blend_shape<class_SurfaceTool_method_create_from_blend_shape>` **(** :ref:`Mesh<class_Mesh>` existing, :ref:`int<class_int>` surface, :ref:`String<class_String>` blend_shape **)** |
  62. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`deindex<class_SurfaceTool_method_deindex>` **(** **)** |
  64. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`generate_lod<class_SurfaceTool_method_generate_lod>` **(** :ref:`float<class_float>` nd_threshold, :ref:`int<class_int>` target_index_count=3 **)** |
  66. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`generate_normals<class_SurfaceTool_method_generate_normals>` **(** :ref:`bool<class_bool>` flip=false **)** |
  68. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`generate_tangents<class_SurfaceTool_method_generate_tangents>` **(** **)** |
  70. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`AABB<class_AABB>` | :ref:`get_aabb<class_SurfaceTool_method_get_aabb>` **(** **)** |const| |
  72. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` | :ref:`get_custom_format<class_SurfaceTool_method_get_custom_format>` **(** :ref:`int<class_int>` channel_index **)** |const| |
  74. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` | :ref:`get_primitive_type<class_SurfaceTool_method_get_primitive_type>` **(** **)** |const| |
  76. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`SkinWeightCount<enum_SurfaceTool_SkinWeightCount>` | :ref:`get_skin_weight_count<class_SurfaceTool_method_get_skin_weight_count>` **(** **)** |const| |
  78. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`index<class_SurfaceTool_method_index>` **(** **)** |
  80. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`optimize_indices_for_cache<class_SurfaceTool_method_optimize_indices_for_cache>` **(** **)** |
  82. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`set_bones<class_SurfaceTool_method_set_bones>` **(** :ref:`PackedInt32Array<class_PackedInt32Array>` bones **)** |
  84. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`set_color<class_SurfaceTool_method_set_color>` **(** :ref:`Color<class_Color>` color **)** |
  86. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`set_custom<class_SurfaceTool_method_set_custom>` **(** :ref:`int<class_int>` channel_index, :ref:`Color<class_Color>` custom_color **)** |
  88. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`set_custom_format<class_SurfaceTool_method_set_custom_format>` **(** :ref:`int<class_int>` channel_index, :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` format **)** |
  90. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`set_material<class_SurfaceTool_method_set_material>` **(** :ref:`Material<class_Material>` material **)** |
  92. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | void | :ref:`set_normal<class_SurfaceTool_method_set_normal>` **(** :ref:`Vector3<class_Vector3>` normal **)** |
  94. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | void | :ref:`set_skin_weight_count<class_SurfaceTool_method_set_skin_weight_count>` **(** :ref:`SkinWeightCount<enum_SurfaceTool_SkinWeightCount>` count **)** |
  96. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | void | :ref:`set_smooth_group<class_SurfaceTool_method_set_smooth_group>` **(** :ref:`int<class_int>` index **)** |
  98. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | void | :ref:`set_tangent<class_SurfaceTool_method_set_tangent>` **(** :ref:`Plane<class_Plane>` tangent **)** |
  100. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | void | :ref:`set_uv<class_SurfaceTool_method_set_uv>` **(** :ref:`Vector2<class_Vector2>` uv **)** |
  102. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | void | :ref:`set_uv2<class_SurfaceTool_method_set_uv2>` **(** :ref:`Vector2<class_Vector2>` uv2 **)** |
  104. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | void | :ref:`set_weights<class_SurfaceTool_method_set_weights>` **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` weights **)** |
  106. +----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. .. rst-class:: classref-section-separator
  108. ----
  109. .. rst-class:: classref-descriptions-group
  110. Enumerations
  111. ------------
  112. .. _enum_SurfaceTool_CustomFormat:
  113. .. rst-class:: classref-enumeration
  114. enum **CustomFormat**:
  115. .. _class_SurfaceTool_constant_CUSTOM_RGBA8_UNORM:
  116. .. rst-class:: classref-enumeration-constant
  117. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_RGBA8_UNORM** = ``0``
  118. Limits range of data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` to unsigned normalized 0 to 1 stored in 8 bits per channel. See :ref:`Mesh.ARRAY_CUSTOM_RGBA8_UNORM<class_Mesh_constant_ARRAY_CUSTOM_RGBA8_UNORM>`.
  119. .. _class_SurfaceTool_constant_CUSTOM_RGBA8_SNORM:
  120. .. rst-class:: classref-enumeration-constant
  121. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_RGBA8_SNORM** = ``1``
  122. Limits range of data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` to signed normalized -1 to 1 stored in 8 bits per channel. See :ref:`Mesh.ARRAY_CUSTOM_RGBA8_SNORM<class_Mesh_constant_ARRAY_CUSTOM_RGBA8_SNORM>`.
  123. .. _class_SurfaceTool_constant_CUSTOM_RG_HALF:
  124. .. rst-class:: classref-enumeration-constant
  125. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_RG_HALF** = ``2``
  126. Stores data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` as half precision floats, and uses only red and green color channels. See :ref:`Mesh.ARRAY_CUSTOM_RG_HALF<class_Mesh_constant_ARRAY_CUSTOM_RG_HALF>`.
  127. .. _class_SurfaceTool_constant_CUSTOM_RGBA_HALF:
  128. .. rst-class:: classref-enumeration-constant
  129. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_RGBA_HALF** = ``3``
  130. Stores data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` as half precision floats and uses all color channels. See :ref:`Mesh.ARRAY_CUSTOM_RGBA_HALF<class_Mesh_constant_ARRAY_CUSTOM_RGBA_HALF>`.
  131. .. _class_SurfaceTool_constant_CUSTOM_R_FLOAT:
  132. .. rst-class:: classref-enumeration-constant
  133. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_R_FLOAT** = ``4``
  134. Stores data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` as full precision floats, and uses only red color channel. See :ref:`Mesh.ARRAY_CUSTOM_R_FLOAT<class_Mesh_constant_ARRAY_CUSTOM_R_FLOAT>`.
  135. .. _class_SurfaceTool_constant_CUSTOM_RG_FLOAT:
  136. .. rst-class:: classref-enumeration-constant
  137. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_RG_FLOAT** = ``5``
  138. Stores data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` as full precision floats, and uses only red and green color channels. See :ref:`Mesh.ARRAY_CUSTOM_RG_FLOAT<class_Mesh_constant_ARRAY_CUSTOM_RG_FLOAT>`.
  139. .. _class_SurfaceTool_constant_CUSTOM_RGB_FLOAT:
  140. .. rst-class:: classref-enumeration-constant
  141. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_RGB_FLOAT** = ``6``
  142. Stores data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` as full precision floats, and uses only red, green and blue color channels. See :ref:`Mesh.ARRAY_CUSTOM_RGB_FLOAT<class_Mesh_constant_ARRAY_CUSTOM_RGB_FLOAT>`.
  143. .. _class_SurfaceTool_constant_CUSTOM_RGBA_FLOAT:
  144. .. rst-class:: classref-enumeration-constant
  145. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_RGBA_FLOAT** = ``7``
  146. Stores data passed to :ref:`set_custom<class_SurfaceTool_method_set_custom>` as full precision floats, and uses all color channels. See :ref:`Mesh.ARRAY_CUSTOM_RGBA_FLOAT<class_Mesh_constant_ARRAY_CUSTOM_RGBA_FLOAT>`.
  147. .. _class_SurfaceTool_constant_CUSTOM_MAX:
  148. .. rst-class:: classref-enumeration-constant
  149. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **CUSTOM_MAX** = ``8``
  150. Used to indicate a disabled custom channel.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _enum_SurfaceTool_SkinWeightCount:
  154. .. rst-class:: classref-enumeration
  155. enum **SkinWeightCount**:
  156. .. _class_SurfaceTool_constant_SKIN_4_WEIGHTS:
  157. .. rst-class:: classref-enumeration-constant
  158. :ref:`SkinWeightCount<enum_SurfaceTool_SkinWeightCount>` **SKIN_4_WEIGHTS** = ``0``
  159. Each individual vertex can be influenced by only 4 bone weights.
  160. .. _class_SurfaceTool_constant_SKIN_8_WEIGHTS:
  161. .. rst-class:: classref-enumeration-constant
  162. :ref:`SkinWeightCount<enum_SurfaceTool_SkinWeightCount>` **SKIN_8_WEIGHTS** = ``1``
  163. Each individual vertex can be influenced by up to 8 bone weights.
  164. .. rst-class:: classref-section-separator
  165. ----
  166. .. rst-class:: classref-descriptions-group
  167. Method Descriptions
  168. -------------------
  169. .. _class_SurfaceTool_method_add_index:
  170. .. rst-class:: classref-method
  171. void **add_index** **(** :ref:`int<class_int>` index **)**
  172. Adds a vertex to index array if you are using indexed vertices. Does not need to be called before adding vertices.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_SurfaceTool_method_add_triangle_fan:
  176. .. rst-class:: classref-method
  177. void **add_triangle_fan** **(** :ref:`PackedVector3Array<class_PackedVector3Array>` vertices, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs=PackedVector2Array(), :ref:`PackedColorArray<class_PackedColorArray>` colors=PackedColorArray(), :ref:`PackedVector2Array<class_PackedVector2Array>` uv2s=PackedVector2Array(), :ref:`PackedVector3Array<class_PackedVector3Array>` normals=PackedVector3Array(), :ref:`Array<class_Array>` tangents=[] **)**
  178. Inserts a triangle fan made of array data into :ref:`Mesh<class_Mesh>` being constructed.
  179. Requires the primitive type be set to :ref:`Mesh.PRIMITIVE_TRIANGLES<class_Mesh_constant_PRIMITIVE_TRIANGLES>`.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_SurfaceTool_method_add_vertex:
  183. .. rst-class:: classref-method
  184. void **add_vertex** **(** :ref:`Vector3<class_Vector3>` vertex **)**
  185. Specifies the position of current vertex. Should be called after specifying other vertex properties (e.g. Color, UV).
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_SurfaceTool_method_append_from:
  189. .. rst-class:: classref-method
  190. void **append_from** **(** :ref:`Mesh<class_Mesh>` existing, :ref:`int<class_int>` surface, :ref:`Transform3D<class_Transform3D>` transform **)**
  191. Append vertices from a given :ref:`Mesh<class_Mesh>` surface onto the current vertex array with specified :ref:`Transform3D<class_Transform3D>`.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_SurfaceTool_method_begin:
  195. .. rst-class:: classref-method
  196. void **begin** **(** :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` primitive **)**
  197. Called before adding any vertices. Takes the primitive type as an argument (e.g. :ref:`Mesh.PRIMITIVE_TRIANGLES<class_Mesh_constant_PRIMITIVE_TRIANGLES>`).
  198. .. rst-class:: classref-item-separator
  199. ----
  200. .. _class_SurfaceTool_method_clear:
  201. .. rst-class:: classref-method
  202. void **clear** **(** **)**
  203. Clear all information passed into the surface tool so far.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_SurfaceTool_method_commit:
  207. .. rst-class:: classref-method
  208. :ref:`ArrayMesh<class_ArrayMesh>` **commit** **(** :ref:`ArrayMesh<class_ArrayMesh>` existing=null, :ref:`int<class_int>` flags=0 **)**
  209. Returns a constructed :ref:`ArrayMesh<class_ArrayMesh>` from current information passed in. If an existing :ref:`ArrayMesh<class_ArrayMesh>` is passed in as an argument, will add an extra surface to the existing :ref:`ArrayMesh<class_ArrayMesh>`.
  210. \ **FIXME:** Document possible values for ``flags``, it changed in 4.0. Likely some combinations of :ref:`ArrayFormat<enum_Mesh_ArrayFormat>`.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_SurfaceTool_method_commit_to_arrays:
  214. .. rst-class:: classref-method
  215. :ref:`Array<class_Array>` **commit_to_arrays** **(** **)**
  216. Commits the data to the same format used by :ref:`ArrayMesh.add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`. This way you can further process the mesh data using the :ref:`ArrayMesh<class_ArrayMesh>` API.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_SurfaceTool_method_create_from:
  220. .. rst-class:: classref-method
  221. void **create_from** **(** :ref:`Mesh<class_Mesh>` existing, :ref:`int<class_int>` surface **)**
  222. Creates a vertex array from an existing :ref:`Mesh<class_Mesh>`.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_SurfaceTool_method_create_from_blend_shape:
  226. .. rst-class:: classref-method
  227. void **create_from_blend_shape** **(** :ref:`Mesh<class_Mesh>` existing, :ref:`int<class_int>` surface, :ref:`String<class_String>` blend_shape **)**
  228. Creates a vertex array from the specified blend shape of an existing :ref:`Mesh<class_Mesh>`. This can be used to extract a specific pose from a blend shape.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_SurfaceTool_method_deindex:
  232. .. rst-class:: classref-method
  233. void **deindex** **(** **)**
  234. Removes the index array by expanding the vertex array.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_SurfaceTool_method_generate_lod:
  238. .. rst-class:: classref-method
  239. :ref:`PackedInt32Array<class_PackedInt32Array>` **generate_lod** **(** :ref:`float<class_float>` nd_threshold, :ref:`int<class_int>` target_index_count=3 **)**
  240. Generates a LOD for a given ``nd_threshold`` in linear units (square root of quadric error metric), using at most ``target_index_count`` indices.
  241. Deprecated. Unused internally and neglects to preserve normals or UVs. Consider using :ref:`ImporterMesh.generate_lods<class_ImporterMesh_method_generate_lods>` instead.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_SurfaceTool_method_generate_normals:
  245. .. rst-class:: classref-method
  246. void **generate_normals** **(** :ref:`bool<class_bool>` flip=false **)**
  247. 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<class_SurfaceTool_method_generate_normals>` should be called *after* generating geometry and *before* committing the mesh using :ref:`commit<class_SurfaceTool_method_commit>` or :ref:`commit_to_arrays<class_SurfaceTool_method_commit_to_arrays>`. For correct display of normal-mapped surfaces, you will also have to generate tangents using :ref:`generate_tangents<class_SurfaceTool_method_generate_tangents>`.
  248. \ **Note:** :ref:`generate_normals<class_SurfaceTool_method_generate_normals>` only works if the primitive type to be set to :ref:`Mesh.PRIMITIVE_TRIANGLES<class_Mesh_constant_PRIMITIVE_TRIANGLES>`.
  249. \ **Note:** :ref:`generate_normals<class_SurfaceTool_method_generate_normals>` takes smooth groups into account. To generate smooth normals, set the smooth group to a value greater than or equal to ``0`` using :ref:`set_smooth_group<class_SurfaceTool_method_set_smooth_group>` or leave the smooth group at the default of ``0``. To generate flat normals, set the smooth group to ``-1`` using :ref:`set_smooth_group<class_SurfaceTool_method_set_smooth_group>` prior to adding vertices.
  250. .. rst-class:: classref-item-separator
  251. ----
  252. .. _class_SurfaceTool_method_generate_tangents:
  253. .. rst-class:: classref-method
  254. void **generate_tangents** **(** **)**
  255. Generates a tangent vector for each vertex. Requires that each vertex have UVs and normals set already (see :ref:`generate_normals<class_SurfaceTool_method_generate_normals>`).
  256. .. rst-class:: classref-item-separator
  257. ----
  258. .. _class_SurfaceTool_method_get_aabb:
  259. .. rst-class:: classref-method
  260. :ref:`AABB<class_AABB>` **get_aabb** **(** **)** |const|
  261. Returns the axis-aligned bounding box of the vertex positions.
  262. .. rst-class:: classref-item-separator
  263. ----
  264. .. _class_SurfaceTool_method_get_custom_format:
  265. .. rst-class:: classref-method
  266. :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` **get_custom_format** **(** :ref:`int<class_int>` channel_index **)** |const|
  267. Returns the format for custom ``channel_index`` (currently up to 4). Returns :ref:`CUSTOM_MAX<class_SurfaceTool_constant_CUSTOM_MAX>` if this custom channel is unused.
  268. .. rst-class:: classref-item-separator
  269. ----
  270. .. _class_SurfaceTool_method_get_primitive_type:
  271. .. rst-class:: classref-method
  272. :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` **get_primitive_type** **(** **)** |const|
  273. Returns the type of mesh geometry, such as :ref:`Mesh.PRIMITIVE_TRIANGLES<class_Mesh_constant_PRIMITIVE_TRIANGLES>`.
  274. .. rst-class:: classref-item-separator
  275. ----
  276. .. _class_SurfaceTool_method_get_skin_weight_count:
  277. .. rst-class:: classref-method
  278. :ref:`SkinWeightCount<enum_SurfaceTool_SkinWeightCount>` **get_skin_weight_count** **(** **)** |const|
  279. By default, returns :ref:`SKIN_4_WEIGHTS<class_SurfaceTool_constant_SKIN_4_WEIGHTS>` to indicate only 4 bone influences per vertex are used.
  280. Returns :ref:`SKIN_8_WEIGHTS<class_SurfaceTool_constant_SKIN_8_WEIGHTS>` if up to 8 influences are used.
  281. \ **Note:** This function returns an enum, not the exact number of weights.
  282. .. rst-class:: classref-item-separator
  283. ----
  284. .. _class_SurfaceTool_method_index:
  285. .. rst-class:: classref-method
  286. void **index** **(** **)**
  287. Shrinks the vertex array by creating an index array. This can improve performance by avoiding vertex reuse.
  288. .. rst-class:: classref-item-separator
  289. ----
  290. .. _class_SurfaceTool_method_optimize_indices_for_cache:
  291. .. rst-class:: classref-method
  292. void **optimize_indices_for_cache** **(** **)**
  293. Optimizes triangle sorting for performance. Requires that :ref:`get_primitive_type<class_SurfaceTool_method_get_primitive_type>` is :ref:`Mesh.PRIMITIVE_TRIANGLES<class_Mesh_constant_PRIMITIVE_TRIANGLES>`.
  294. .. rst-class:: classref-item-separator
  295. ----
  296. .. _class_SurfaceTool_method_set_bones:
  297. .. rst-class:: classref-method
  298. void **set_bones** **(** :ref:`PackedInt32Array<class_PackedInt32Array>` bones **)**
  299. Specifies an array of bones to use for the *next* vertex. ``bones`` must contain 4 integers.
  300. .. rst-class:: classref-item-separator
  301. ----
  302. .. _class_SurfaceTool_method_set_color:
  303. .. rst-class:: classref-method
  304. void **set_color** **(** :ref:`Color<class_Color>` color **)**
  305. Specifies a :ref:`Color<class_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.
  306. \ **Note:** The material must have :ref:`BaseMaterial3D.vertex_color_use_as_albedo<class_BaseMaterial3D_property_vertex_color_use_as_albedo>` enabled for the vertex color to be visible.
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_SurfaceTool_method_set_custom:
  310. .. rst-class:: classref-method
  311. void **set_custom** **(** :ref:`int<class_int>` channel_index, :ref:`Color<class_Color>` custom_color **)**
  312. Sets the custom value on this vertex for ``channel_index``.
  313. \ :ref:`set_custom_format<class_SurfaceTool_method_set_custom_format>` must be called first for this ``channel_index``. Formats which are not RGBA will ignore other color channels.
  314. .. rst-class:: classref-item-separator
  315. ----
  316. .. _class_SurfaceTool_method_set_custom_format:
  317. .. rst-class:: classref-method
  318. void **set_custom_format** **(** :ref:`int<class_int>` channel_index, :ref:`CustomFormat<enum_SurfaceTool_CustomFormat>` format **)**
  319. Sets the color format for this custom ``channel_index``. Use :ref:`CUSTOM_MAX<class_SurfaceTool_constant_CUSTOM_MAX>` to disable.
  320. Must be invoked after :ref:`begin<class_SurfaceTool_method_begin>` and should be set before :ref:`commit<class_SurfaceTool_method_commit>` or :ref:`commit_to_arrays<class_SurfaceTool_method_commit_to_arrays>`.
  321. .. rst-class:: classref-item-separator
  322. ----
  323. .. _class_SurfaceTool_method_set_material:
  324. .. rst-class:: classref-method
  325. void **set_material** **(** :ref:`Material<class_Material>` material **)**
  326. Sets :ref:`Material<class_Material>` to be used by the :ref:`Mesh<class_Mesh>` you are constructing.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_SurfaceTool_method_set_normal:
  330. .. rst-class:: classref-method
  331. void **set_normal** **(** :ref:`Vector3<class_Vector3>` normal **)**
  332. 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.
  333. .. rst-class:: classref-item-separator
  334. ----
  335. .. _class_SurfaceTool_method_set_skin_weight_count:
  336. .. rst-class:: classref-method
  337. void **set_skin_weight_count** **(** :ref:`SkinWeightCount<enum_SurfaceTool_SkinWeightCount>` count **)**
  338. Set to :ref:`SKIN_8_WEIGHTS<class_SurfaceTool_constant_SKIN_8_WEIGHTS>` to indicate that up to 8 bone influences per vertex may be used.
  339. By default, only 4 bone influences are used (:ref:`SKIN_4_WEIGHTS<class_SurfaceTool_constant_SKIN_4_WEIGHTS>`)
  340. \ **Note:** This function takes an enum, not the exact number of weights.
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_SurfaceTool_method_set_smooth_group:
  344. .. rst-class:: classref-method
  345. void **set_smooth_group** **(** :ref:`int<class_int>` index **)**
  346. Specifies the smooth group to use for the *next* vertex. If this is never called, all vertices will have the default smooth group of ``0`` and will be smoothed with adjacent vertices of the same group. To produce a mesh with flat normals, set the smooth group to ``-1``.
  347. \ **Note:** This function actually takes a ``uint32_t``, so C# users should use ``uint32.MaxValue`` instead of ``-1`` to produce a mesh with flat normals.
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_SurfaceTool_method_set_tangent:
  351. .. rst-class:: classref-method
  352. void **set_tangent** **(** :ref:`Plane<class_Plane>` tangent **)**
  353. 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.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_SurfaceTool_method_set_uv:
  357. .. rst-class:: classref-method
  358. void **set_uv** **(** :ref:`Vector2<class_Vector2>` uv **)**
  359. 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.
  360. .. rst-class:: classref-item-separator
  361. ----
  362. .. _class_SurfaceTool_method_set_uv2:
  363. .. rst-class:: classref-method
  364. void **set_uv2** **(** :ref:`Vector2<class_Vector2>` uv2 **)**
  365. 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.
  366. .. rst-class:: classref-item-separator
  367. ----
  368. .. _class_SurfaceTool_method_set_weights:
  369. .. rst-class:: classref-method
  370. void **set_weights** **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` weights **)**
  371. 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.
  372. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  373. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  374. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  375. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  376. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  377. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`