class_multimesh.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 MultiMesh.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_MultiMesh:
  6. MultiMesh
  7. =========
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. Provides high-performance mesh instancing.
  10. Description
  11. -----------
  12. MultiMesh provides low-level mesh instancing. Drawing thousands of :ref:`MeshInstance3D<class_MeshInstance3D>` nodes can be slow, since each object is submitted to the GPU then drawn individually.
  13. MultiMesh is much faster as it can draw thousands of instances with a single draw call, resulting in less API overhead.
  14. As a drawback, if the instances are too far away from each other, performance may be reduced as every single instance will always render (they are spatially indexed as one, for the whole object).
  15. Since instances may have any behavior, the AABB used for visibility must be provided by the user.
  16. Tutorials
  17. ---------
  18. - :doc:`Animating thousands of fish with MultiMeshInstance <../tutorials/performance/vertex_animation/animating_thousands_of_fish>`
  19. - :doc:`Optimization using MultiMeshes <../tutorials/performance/using_multimesh>`
  20. Properties
  21. ----------
  22. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  23. | :ref:`PackedFloat32Array<class_PackedFloat32Array>` | :ref:`buffer<class_MultiMesh_property_buffer>` | ``PackedFloat32Array()`` |
  24. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  25. | :ref:`PackedColorArray<class_PackedColorArray>` | :ref:`color_array<class_MultiMesh_property_color_array>` | |
  26. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  27. | :ref:`PackedColorArray<class_PackedColorArray>` | :ref:`custom_data_array<class_MultiMesh_property_custom_data_array>` | |
  28. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  29. | :ref:`int<class_int>` | :ref:`instance_count<class_MultiMesh_property_instance_count>` | ``0`` |
  30. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  31. | :ref:`Mesh<class_Mesh>` | :ref:`mesh<class_MultiMesh_property_mesh>` | |
  32. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  33. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`transform_2d_array<class_MultiMesh_property_transform_2d_array>` | |
  34. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  35. | :ref:`PackedVector3Array<class_PackedVector3Array>` | :ref:`transform_array<class_MultiMesh_property_transform_array>` | |
  36. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  37. | :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` | :ref:`transform_format<class_MultiMesh_property_transform_format>` | ``0`` |
  38. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`use_colors<class_MultiMesh_property_use_colors>` | ``false`` |
  40. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`use_custom_data<class_MultiMesh_property_use_custom_data>` | ``false`` |
  42. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  43. | :ref:`int<class_int>` | :ref:`visible_instance_count<class_MultiMesh_property_visible_instance_count>` | ``-1`` |
  44. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  45. Methods
  46. -------
  47. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`AABB<class_AABB>` | :ref:`get_aabb<class_MultiMesh_method_get_aabb>` **(** **)** |const| |
  49. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Color<class_Color>` | :ref:`get_instance_color<class_MultiMesh_method_get_instance_color>` **(** :ref:`int<class_int>` instance **)** |const| |
  51. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Color<class_Color>` | :ref:`get_instance_custom_data<class_MultiMesh_method_get_instance_custom_data>` **(** :ref:`int<class_int>` instance **)** |const| |
  53. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Transform3D<class_Transform3D>` | :ref:`get_instance_transform<class_MultiMesh_method_get_instance_transform>` **(** :ref:`int<class_int>` instance **)** |const| |
  55. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_instance_transform_2d<class_MultiMesh_method_get_instance_transform_2d>` **(** :ref:`int<class_int>` instance **)** |const| |
  57. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`set_instance_color<class_MultiMesh_method_set_instance_color>` **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` color **)** |
  59. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`set_instance_custom_data<class_MultiMesh_method_set_instance_custom_data>` **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` custom_data **)** |
  61. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`set_instance_transform<class_MultiMesh_method_set_instance_transform>` **(** :ref:`int<class_int>` instance, :ref:`Transform3D<class_Transform3D>` transform **)** |
  63. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`set_instance_transform_2d<class_MultiMesh_method_set_instance_transform_2d>` **(** :ref:`int<class_int>` instance, :ref:`Transform2D<class_Transform2D>` transform **)** |
  65. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. Enumerations
  67. ------------
  68. .. _enum_MultiMesh_TransformFormat:
  69. .. _class_MultiMesh_constant_TRANSFORM_2D:
  70. .. _class_MultiMesh_constant_TRANSFORM_3D:
  71. enum **TransformFormat**:
  72. - **TRANSFORM_2D** = **0** --- Use this when using 2D transforms.
  73. - **TRANSFORM_3D** = **1** --- Use this when using 3D transforms.
  74. Property Descriptions
  75. ---------------------
  76. .. _class_MultiMesh_property_buffer:
  77. - :ref:`PackedFloat32Array<class_PackedFloat32Array>` **buffer**
  78. +-----------+--------------------------+
  79. | *Default* | ``PackedFloat32Array()`` |
  80. +-----------+--------------------------+
  81. | *Setter* | set_buffer(value) |
  82. +-----------+--------------------------+
  83. | *Getter* | get_buffer() |
  84. +-----------+--------------------------+
  85. ----
  86. .. _class_MultiMesh_property_color_array:
  87. - :ref:`PackedColorArray<class_PackedColorArray>` **color_array**
  88. ----
  89. .. _class_MultiMesh_property_custom_data_array:
  90. - :ref:`PackedColorArray<class_PackedColorArray>` **custom_data_array**
  91. ----
  92. .. _class_MultiMesh_property_instance_count:
  93. - :ref:`int<class_int>` **instance_count**
  94. +-----------+---------------------------+
  95. | *Default* | ``0`` |
  96. +-----------+---------------------------+
  97. | *Setter* | set_instance_count(value) |
  98. +-----------+---------------------------+
  99. | *Getter* | get_instance_count() |
  100. +-----------+---------------------------+
  101. Number of instances that will get drawn. This clears and (re)sizes the buffers. Setting data format or flags afterwards will have no effect.
  102. By default, all instances are drawn but you can limit this with :ref:`visible_instance_count<class_MultiMesh_property_visible_instance_count>`.
  103. ----
  104. .. _class_MultiMesh_property_mesh:
  105. - :ref:`Mesh<class_Mesh>` **mesh**
  106. +----------+-----------------+
  107. | *Setter* | set_mesh(value) |
  108. +----------+-----------------+
  109. | *Getter* | get_mesh() |
  110. +----------+-----------------+
  111. Mesh to be drawn.
  112. ----
  113. .. _class_MultiMesh_property_transform_2d_array:
  114. - :ref:`PackedVector2Array<class_PackedVector2Array>` **transform_2d_array**
  115. ----
  116. .. _class_MultiMesh_property_transform_array:
  117. - :ref:`PackedVector3Array<class_PackedVector3Array>` **transform_array**
  118. ----
  119. .. _class_MultiMesh_property_transform_format:
  120. - :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` **transform_format**
  121. +-----------+-----------------------------+
  122. | *Default* | ``0`` |
  123. +-----------+-----------------------------+
  124. | *Setter* | set_transform_format(value) |
  125. +-----------+-----------------------------+
  126. | *Getter* | get_transform_format() |
  127. +-----------+-----------------------------+
  128. Format of transform used to transform mesh, either 2D or 3D.
  129. ----
  130. .. _class_MultiMesh_property_use_colors:
  131. - :ref:`bool<class_bool>` **use_colors**
  132. +-----------+-----------------------+
  133. | *Default* | ``false`` |
  134. +-----------+-----------------------+
  135. | *Setter* | set_use_colors(value) |
  136. +-----------+-----------------------+
  137. | *Getter* | is_using_colors() |
  138. +-----------+-----------------------+
  139. If ``true``, the ``MultiMesh`` will use color data (see :ref:`color_array<class_MultiMesh_property_color_array>`).
  140. ----
  141. .. _class_MultiMesh_property_use_custom_data:
  142. - :ref:`bool<class_bool>` **use_custom_data**
  143. +-----------+----------------------------+
  144. | *Default* | ``false`` |
  145. +-----------+----------------------------+
  146. | *Setter* | set_use_custom_data(value) |
  147. +-----------+----------------------------+
  148. | *Getter* | is_using_custom_data() |
  149. +-----------+----------------------------+
  150. If ``true``, the ``MultiMesh`` will use custom data (see :ref:`custom_data_array<class_MultiMesh_property_custom_data_array>`).
  151. ----
  152. .. _class_MultiMesh_property_visible_instance_count:
  153. - :ref:`int<class_int>` **visible_instance_count**
  154. +-----------+-----------------------------------+
  155. | *Default* | ``-1`` |
  156. +-----------+-----------------------------------+
  157. | *Setter* | set_visible_instance_count(value) |
  158. +-----------+-----------------------------------+
  159. | *Getter* | get_visible_instance_count() |
  160. +-----------+-----------------------------------+
  161. Limits the number of instances drawn, -1 draws all instances. Changing this does not change the sizes of the buffers.
  162. Method Descriptions
  163. -------------------
  164. .. _class_MultiMesh_method_get_aabb:
  165. - :ref:`AABB<class_AABB>` **get_aabb** **(** **)** |const|
  166. Returns the visibility axis-aligned bounding box in local space. See also :ref:`VisualInstance3D.get_transformed_aabb<class_VisualInstance3D_method_get_transformed_aabb>`.
  167. ----
  168. .. _class_MultiMesh_method_get_instance_color:
  169. - :ref:`Color<class_Color>` **get_instance_color** **(** :ref:`int<class_int>` instance **)** |const|
  170. Gets a specific instance's color.
  171. ----
  172. .. _class_MultiMesh_method_get_instance_custom_data:
  173. - :ref:`Color<class_Color>` **get_instance_custom_data** **(** :ref:`int<class_int>` instance **)** |const|
  174. Returns the custom data that has been set for a specific instance.
  175. ----
  176. .. _class_MultiMesh_method_get_instance_transform:
  177. - :ref:`Transform3D<class_Transform3D>` **get_instance_transform** **(** :ref:`int<class_int>` instance **)** |const|
  178. Returns the :ref:`Transform3D<class_Transform3D>` of a specific instance.
  179. ----
  180. .. _class_MultiMesh_method_get_instance_transform_2d:
  181. - :ref:`Transform2D<class_Transform2D>` **get_instance_transform_2d** **(** :ref:`int<class_int>` instance **)** |const|
  182. Returns the :ref:`Transform2D<class_Transform2D>` of a specific instance.
  183. ----
  184. .. _class_MultiMesh_method_set_instance_color:
  185. - void **set_instance_color** **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` color **)**
  186. Sets the color of a specific instance by *multiplying* the mesh's existing vertex colors.
  187. For the color to take effect, ensure that :ref:`use_colors<class_MultiMesh_property_use_colors>` is ``true`` on the ``MultiMesh`` and :ref:`BaseMaterial3D.vertex_color_use_as_albedo<class_BaseMaterial3D_property_vertex_color_use_as_albedo>` is ``true`` on the material.
  188. ----
  189. .. _class_MultiMesh_method_set_instance_custom_data:
  190. - void **set_instance_custom_data** **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` custom_data **)**
  191. Sets custom data for a specific instance. Although :ref:`Color<class_Color>` is used, it is just a container for 4 floating point numbers.
  192. For the custom data to be used, ensure that :ref:`use_custom_data<class_MultiMesh_property_use_custom_data>` is ``true``.
  193. ----
  194. .. _class_MultiMesh_method_set_instance_transform:
  195. - void **set_instance_transform** **(** :ref:`int<class_int>` instance, :ref:`Transform3D<class_Transform3D>` transform **)**
  196. Sets the :ref:`Transform3D<class_Transform3D>` for a specific instance.
  197. ----
  198. .. _class_MultiMesh_method_set_instance_transform_2d:
  199. - void **set_instance_transform_2d** **(** :ref:`int<class_int>` instance, :ref:`Transform2D<class_Transform2D>` transform **)**
  200. Sets the :ref:`Transform2D<class_Transform2D>` for a specific instance.
  201. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  202. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  203. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  204. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  205. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  206. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`