class_arraymesh.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the ArrayMesh.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_ArrayMesh:
  6. ArrayMesh
  7. =========
  8. **Inherits:** :ref:`Mesh<class_Mesh>` **<** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. :ref:`Mesh<class_Mesh>` type that provides utility for constructing a surface from arrays.
  10. Description
  11. -----------
  12. The ``ArrayMesh`` is used to construct a :ref:`Mesh<class_Mesh>` by specifying the attributes as arrays.
  13. The most basic example is the creation of a single triangle:
  14. ::
  15. var vertices = PoolVector3Array()
  16. vertices.push_back(Vector3(0, 1, 0))
  17. vertices.push_back(Vector3(1, 0, 0))
  18. vertices.push_back(Vector3(0, 0, 1))
  19. # Initialize the ArrayMesh.
  20. var arr_mesh = ArrayMesh.new()
  21. var arrays = []
  22. arrays.resize(ArrayMesh.ARRAY_MAX)
  23. arrays[ArrayMesh.ARRAY_VERTEX] = vertices
  24. # Create the Mesh.
  25. arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
  26. var m = MeshInstance.new()
  27. m.mesh = arr_mesh
  28. The :ref:`MeshInstance<class_MeshInstance>` is ready to be added to the :ref:`SceneTree<class_SceneTree>` to be shown.
  29. See also :ref:`ImmediateGeometry<class_ImmediateGeometry>`, :ref:`MeshDataTool<class_MeshDataTool>` and :ref:`SurfaceTool<class_SurfaceTool>` for procedural geometry generation.
  30. **Note:** Godot uses clockwise `winding order <https://learnopengl.com/Advanced-OpenGL/Face-culling>`__ for front faces of triangle primitive modes.
  31. Tutorials
  32. ---------
  33. - :doc:`../tutorials/3d/procedural_geometry/arraymesh`
  34. Properties
  35. ----------
  36. +-------------------------------------------------+--------------------------------------------------------------------+------------------------------+
  37. | :ref:`BlendShapeMode<enum_Mesh_BlendShapeMode>` | :ref:`blend_shape_mode<class_ArrayMesh_property_blend_shape_mode>` | ``1`` |
  38. +-------------------------------------------------+--------------------------------------------------------------------+------------------------------+
  39. | :ref:`AABB<class_AABB>` | :ref:`custom_aabb<class_ArrayMesh_property_custom_aabb>` | ``AABB( 0, 0, 0, 0, 0, 0 )`` |
  40. +-------------------------------------------------+--------------------------------------------------------------------+------------------------------+
  41. Methods
  42. -------
  43. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`add_blend_shape<class_ArrayMesh_method_add_blend_shape>` **(** :ref:`String<class_String>` name **)** |
  45. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>` **(** :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` primitive, :ref:`Array<class_Array>` arrays, :ref:`Array<class_Array>` blend_shapes=[ ], :ref:`int<class_int>` compress_flags=2194432 **)** |
  47. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`clear_blend_shapes<class_ArrayMesh_method_clear_blend_shapes>` **(** **)** |
  49. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`clear_surfaces<class_ArrayMesh_method_clear_surfaces>` **(** **)** |
  51. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`get_blend_shape_count<class_ArrayMesh_method_get_blend_shape_count>` **(** **)** |const| |
  53. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`String<class_String>` | :ref:`get_blend_shape_name<class_ArrayMesh_method_get_blend_shape_name>` **(** :ref:`int<class_int>` index **)** |const| |
  55. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`lightmap_unwrap<class_ArrayMesh_method_lightmap_unwrap>` **(** :ref:`Transform<class_Transform>` transform, :ref:`float<class_float>` texel_size **)** |
  57. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`regen_normalmaps<class_ArrayMesh_method_regen_normalmaps>` **(** **)** |
  59. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`set_blend_shape_name<class_ArrayMesh_method_set_blend_shape_name>` **(** :ref:`int<class_int>` index, :ref:`String<class_String>` name **)** |
  61. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`int<class_int>` | :ref:`surface_find_by_name<class_ArrayMesh_method_surface_find_by_name>` **(** :ref:`String<class_String>` name **)** |const| |
  63. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`int<class_int>` | :ref:`surface_get_array_index_len<class_ArrayMesh_method_surface_get_array_index_len>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  65. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`int<class_int>` | :ref:`surface_get_array_len<class_ArrayMesh_method_surface_get_array_len>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  67. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`surface_get_format<class_ArrayMesh_method_surface_get_format>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  69. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`String<class_String>` | :ref:`surface_get_name<class_ArrayMesh_method_surface_get_name>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  71. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` | :ref:`surface_get_primitive_type<class_ArrayMesh_method_surface_get_primitive_type>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  73. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`surface_remove<class_ArrayMesh_method_surface_remove>` **(** :ref:`int<class_int>` surf_idx **)** |
  75. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`surface_set_name<class_ArrayMesh_method_surface_set_name>` **(** :ref:`int<class_int>` surf_idx, :ref:`String<class_String>` name **)** |
  77. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`surface_update_region<class_ArrayMesh_method_surface_update_region>` **(** :ref:`int<class_int>` surf_idx, :ref:`int<class_int>` offset, :ref:`PoolByteArray<class_PoolByteArray>` data **)** |
  79. +-----------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. Enumerations
  81. ------------
  82. .. _enum_ArrayMesh_ArrayType:
  83. .. _class_ArrayMesh_constant_ARRAY_VERTEX:
  84. .. _class_ArrayMesh_constant_ARRAY_NORMAL:
  85. .. _class_ArrayMesh_constant_ARRAY_TANGENT:
  86. .. _class_ArrayMesh_constant_ARRAY_COLOR:
  87. .. _class_ArrayMesh_constant_ARRAY_TEX_UV:
  88. .. _class_ArrayMesh_constant_ARRAY_TEX_UV2:
  89. .. _class_ArrayMesh_constant_ARRAY_BONES:
  90. .. _class_ArrayMesh_constant_ARRAY_WEIGHTS:
  91. .. _class_ArrayMesh_constant_ARRAY_INDEX:
  92. .. _class_ArrayMesh_constant_ARRAY_MAX:
  93. enum **ArrayType**:
  94. - **ARRAY_VERTEX** = **0** --- :ref:`PoolVector3Array<class_PoolVector3Array>`, :ref:`PoolVector2Array<class_PoolVector2Array>`, or :ref:`Array<class_Array>` of vertex positions.
  95. - **ARRAY_NORMAL** = **1** --- :ref:`PoolVector3Array<class_PoolVector3Array>` of vertex normals.
  96. - **ARRAY_TANGENT** = **2** --- :ref:`PoolRealArray<class_PoolRealArray>` of vertex tangents. Each element in groups of 4 floats, first 3 floats determine the tangent, and the last the binormal direction as -1 or 1.
  97. - **ARRAY_COLOR** = **3** --- :ref:`PoolColorArray<class_PoolColorArray>` of vertex colors.
  98. - **ARRAY_TEX_UV** = **4** --- :ref:`PoolVector2Array<class_PoolVector2Array>` for UV coordinates.
  99. - **ARRAY_TEX_UV2** = **5** --- :ref:`PoolVector2Array<class_PoolVector2Array>` for second UV coordinates.
  100. - **ARRAY_BONES** = **6** --- :ref:`PoolRealArray<class_PoolRealArray>` or :ref:`PoolIntArray<class_PoolIntArray>` of bone indices. Each element in groups of 4 floats.
  101. - **ARRAY_WEIGHTS** = **7** --- :ref:`PoolRealArray<class_PoolRealArray>` of bone weights. Each element in groups of 4 floats.
  102. - **ARRAY_INDEX** = **8** --- :ref:`PoolIntArray<class_PoolIntArray>` of integers used as indices referencing vertices, colors, normals, tangents, and textures. All of those arrays must have the same number of elements as the vertex array. No index can be beyond the vertex array size. When this index array is present, it puts the function into "index mode," where the index selects the \*i\*'th vertex, normal, tangent, color, UV, etc. This means if you want to have different normals or colors along an edge, you have to duplicate the vertices.
  103. For triangles, the index array is interpreted as triples, referring to the vertices of each triangle. For lines, the index array is in pairs indicating the start and end of each line.
  104. - **ARRAY_MAX** = **9** --- Represents the size of the :ref:`ArrayType<enum_ArrayMesh_ArrayType>` enum.
  105. ----
  106. .. _enum_ArrayMesh_ArrayFormat:
  107. .. _class_ArrayMesh_constant_ARRAY_FORMAT_VERTEX:
  108. .. _class_ArrayMesh_constant_ARRAY_FORMAT_NORMAL:
  109. .. _class_ArrayMesh_constant_ARRAY_FORMAT_TANGENT:
  110. .. _class_ArrayMesh_constant_ARRAY_FORMAT_COLOR:
  111. .. _class_ArrayMesh_constant_ARRAY_FORMAT_TEX_UV:
  112. .. _class_ArrayMesh_constant_ARRAY_FORMAT_TEX_UV2:
  113. .. _class_ArrayMesh_constant_ARRAY_FORMAT_BONES:
  114. .. _class_ArrayMesh_constant_ARRAY_FORMAT_WEIGHTS:
  115. .. _class_ArrayMesh_constant_ARRAY_FORMAT_INDEX:
  116. enum **ArrayFormat**:
  117. - **ARRAY_FORMAT_VERTEX** = **1** --- Array format will include vertices (mandatory).
  118. - **ARRAY_FORMAT_NORMAL** = **2** --- Array format will include normals.
  119. - **ARRAY_FORMAT_TANGENT** = **4** --- Array format will include tangents.
  120. - **ARRAY_FORMAT_COLOR** = **8** --- Array format will include a color array.
  121. - **ARRAY_FORMAT_TEX_UV** = **16** --- Array format will include UVs.
  122. - **ARRAY_FORMAT_TEX_UV2** = **32** --- Array format will include another set of UVs.
  123. - **ARRAY_FORMAT_BONES** = **64** --- Array format will include bone indices.
  124. - **ARRAY_FORMAT_WEIGHTS** = **128** --- Array format will include bone weights.
  125. - **ARRAY_FORMAT_INDEX** = **256** --- Index array will be used.
  126. Constants
  127. ---------
  128. .. _class_ArrayMesh_constant_NO_INDEX_ARRAY:
  129. .. _class_ArrayMesh_constant_ARRAY_WEIGHTS_SIZE:
  130. - **NO_INDEX_ARRAY** = **-1** --- Default value used for index_array_len when no indices are present.
  131. - **ARRAY_WEIGHTS_SIZE** = **4** --- Amount of weights/bone indices per vertex (always 4).
  132. Property Descriptions
  133. ---------------------
  134. .. _class_ArrayMesh_property_blend_shape_mode:
  135. - :ref:`BlendShapeMode<enum_Mesh_BlendShapeMode>` **blend_shape_mode**
  136. +-----------+-----------------------------+
  137. | *Default* | ``1`` |
  138. +-----------+-----------------------------+
  139. | *Setter* | set_blend_shape_mode(value) |
  140. +-----------+-----------------------------+
  141. | *Getter* | get_blend_shape_mode() |
  142. +-----------+-----------------------------+
  143. Sets the blend shape mode to one of :ref:`BlendShapeMode<enum_Mesh_BlendShapeMode>`.
  144. ----
  145. .. _class_ArrayMesh_property_custom_aabb:
  146. - :ref:`AABB<class_AABB>` **custom_aabb**
  147. +-----------+------------------------------+
  148. | *Default* | ``AABB( 0, 0, 0, 0, 0, 0 )`` |
  149. +-----------+------------------------------+
  150. | *Setter* | set_custom_aabb(value) |
  151. +-----------+------------------------------+
  152. | *Getter* | get_custom_aabb() |
  153. +-----------+------------------------------+
  154. Overrides the :ref:`AABB<class_AABB>` with one defined by user for use with frustum culling. Especially useful to avoid unexpected culling when using a shader to offset vertices.
  155. Method Descriptions
  156. -------------------
  157. .. _class_ArrayMesh_method_add_blend_shape:
  158. - void **add_blend_shape** **(** :ref:`String<class_String>` name **)**
  159. Adds name for a blend shape that will be added with :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`. Must be called before surface is added.
  160. ----
  161. .. _class_ArrayMesh_method_add_surface_from_arrays:
  162. - void **add_surface_from_arrays** **(** :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` primitive, :ref:`Array<class_Array>` arrays, :ref:`Array<class_Array>` blend_shapes=[ ], :ref:`int<class_int>` compress_flags=2194432 **)**
  163. Creates a new surface.
  164. Surfaces are created to be rendered using a ``primitive``, which may be any of the types defined in :ref:`PrimitiveType<enum_Mesh_PrimitiveType>`. (As a note, when using indices, it is recommended to only use points, lines, or triangles.) :ref:`Mesh.get_surface_count<class_Mesh_method_get_surface_count>` will become the ``surf_idx`` for this new surface.
  165. The ``arrays`` argument is an array of arrays. See :ref:`ArrayType<enum_ArrayMesh_ArrayType>` for the values used in this array. For example, ``arrays[0]`` is the array of vertices. That first vertex sub-array is always required; the others are optional. Adding an index array puts this function into "index mode" where the vertex and other arrays become the sources of data and the index array defines the vertex order. All sub-arrays must have the same length as the vertex array or be empty, except for :ref:`ARRAY_INDEX<class_ArrayMesh_constant_ARRAY_INDEX>` if it is used.
  166. ----
  167. .. _class_ArrayMesh_method_clear_blend_shapes:
  168. - void **clear_blend_shapes** **(** **)**
  169. Removes all blend shapes from this ``ArrayMesh``.
  170. ----
  171. .. _class_ArrayMesh_method_clear_surfaces:
  172. - void **clear_surfaces** **(** **)**
  173. Removes all surfaces from this ``ArrayMesh``.
  174. ----
  175. .. _class_ArrayMesh_method_get_blend_shape_count:
  176. - :ref:`int<class_int>` **get_blend_shape_count** **(** **)** |const|
  177. Returns the number of blend shapes that the ``ArrayMesh`` holds.
  178. ----
  179. .. _class_ArrayMesh_method_get_blend_shape_name:
  180. - :ref:`String<class_String>` **get_blend_shape_name** **(** :ref:`int<class_int>` index **)** |const|
  181. Returns the name of the blend shape at this index.
  182. ----
  183. .. _class_ArrayMesh_method_lightmap_unwrap:
  184. - :ref:`Error<enum_@GlobalScope_Error>` **lightmap_unwrap** **(** :ref:`Transform<class_Transform>` transform, :ref:`float<class_float>` texel_size **)**
  185. Will perform a UV unwrap on the ``ArrayMesh`` to prepare the mesh for lightmapping.
  186. ----
  187. .. _class_ArrayMesh_method_regen_normalmaps:
  188. - void **regen_normalmaps** **(** **)**
  189. Will regenerate normal maps for the ``ArrayMesh``.
  190. ----
  191. .. _class_ArrayMesh_method_set_blend_shape_name:
  192. - void **set_blend_shape_name** **(** :ref:`int<class_int>` index, :ref:`String<class_String>` name **)**
  193. ----
  194. .. _class_ArrayMesh_method_surface_find_by_name:
  195. - :ref:`int<class_int>` **surface_find_by_name** **(** :ref:`String<class_String>` name **)** |const|
  196. Returns the index of the first surface with this name held within this ``ArrayMesh``. If none are found, -1 is returned.
  197. ----
  198. .. _class_ArrayMesh_method_surface_get_array_index_len:
  199. - :ref:`int<class_int>` **surface_get_array_index_len** **(** :ref:`int<class_int>` surf_idx **)** |const|
  200. Returns the length in indices of the index array in the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).
  201. ----
  202. .. _class_ArrayMesh_method_surface_get_array_len:
  203. - :ref:`int<class_int>` **surface_get_array_len** **(** :ref:`int<class_int>` surf_idx **)** |const|
  204. Returns the length in vertices of the vertex array in the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).
  205. ----
  206. .. _class_ArrayMesh_method_surface_get_format:
  207. - :ref:`int<class_int>` **surface_get_format** **(** :ref:`int<class_int>` surf_idx **)** |const|
  208. Returns the format mask of the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).
  209. ----
  210. .. _class_ArrayMesh_method_surface_get_name:
  211. - :ref:`String<class_String>` **surface_get_name** **(** :ref:`int<class_int>` surf_idx **)** |const|
  212. Gets the name assigned to this surface.
  213. ----
  214. .. _class_ArrayMesh_method_surface_get_primitive_type:
  215. - :ref:`PrimitiveType<enum_Mesh_PrimitiveType>` **surface_get_primitive_type** **(** :ref:`int<class_int>` surf_idx **)** |const|
  216. Returns the primitive type of the requested surface (see :ref:`add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).
  217. ----
  218. .. _class_ArrayMesh_method_surface_remove:
  219. - void **surface_remove** **(** :ref:`int<class_int>` surf_idx **)**
  220. Removes a surface at position ``surf_idx``, shifting greater surfaces one ``surf_idx`` slot down.
  221. ----
  222. .. _class_ArrayMesh_method_surface_set_name:
  223. - void **surface_set_name** **(** :ref:`int<class_int>` surf_idx, :ref:`String<class_String>` name **)**
  224. Sets a name for a given surface.
  225. ----
  226. .. _class_ArrayMesh_method_surface_update_region:
  227. - void **surface_update_region** **(** :ref:`int<class_int>` surf_idx, :ref:`int<class_int>` offset, :ref:`PoolByteArray<class_PoolByteArray>` data **)**
  228. Updates a specified region of mesh arrays on the GPU.
  229. **Warning:** Only use if you know what you are doing. You can easily cause crashes by calling this function with improper arguments.
  230. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  231. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  232. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`