class_multimesh.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/MultiMesh.xml.
  6. .. _class_MultiMesh:
  7. MultiMesh
  8. =========
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Provides high-performance drawing of a mesh multiple times using GPU instancing.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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.
  15. MultiMesh is much faster as it can draw thousands of instances with a single draw call, resulting in less API overhead.
  16. 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).
  17. Since instances may have any behavior, the AABB used for visibility must be provided by the user.
  18. \ **Note:** A MultiMesh is a single object, therefore the same maximum lights per object restriction applies. This means, that once the maximum lights are consumed by one or more instances, the rest of the MultiMesh instances will **not** receive any lighting.
  19. \ **Note:** Blend Shapes will be ignored if used in a MultiMesh.
  20. .. rst-class:: classref-introduction-group
  21. Tutorials
  22. ---------
  23. - :doc:`Using MultiMeshInstance <../tutorials/3d/using_multi_mesh_instance>`
  24. - :doc:`Optimization using MultiMeshes <../tutorials/performance/using_multimesh>`
  25. - :doc:`Animating thousands of fish with MultiMeshInstance <../tutorials/performance/vertex_animation/animating_thousands_of_fish>`
  26. .. rst-class:: classref-reftable-group
  27. Properties
  28. ----------
  29. .. table::
  30. :widths: auto
  31. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  32. | :ref:`PackedFloat32Array<class_PackedFloat32Array>` | :ref:`buffer<class_MultiMesh_property_buffer>` | ``PackedFloat32Array()`` |
  33. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  34. | :ref:`PackedColorArray<class_PackedColorArray>` | :ref:`color_array<class_MultiMesh_property_color_array>` | |
  35. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  36. | :ref:`PackedColorArray<class_PackedColorArray>` | :ref:`custom_data_array<class_MultiMesh_property_custom_data_array>` | |
  37. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  38. | :ref:`int<class_int>` | :ref:`instance_count<class_MultiMesh_property_instance_count>` | ``0`` |
  39. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  40. | :ref:`Mesh<class_Mesh>` | :ref:`mesh<class_MultiMesh_property_mesh>` | |
  41. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  42. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`transform_2d_array<class_MultiMesh_property_transform_2d_array>` | |
  43. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  44. | :ref:`PackedVector3Array<class_PackedVector3Array>` | :ref:`transform_array<class_MultiMesh_property_transform_array>` | |
  45. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  46. | :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` | :ref:`transform_format<class_MultiMesh_property_transform_format>` | ``0`` |
  47. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`use_colors<class_MultiMesh_property_use_colors>` | ``false`` |
  49. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  50. | :ref:`bool<class_bool>` | :ref:`use_custom_data<class_MultiMesh_property_use_custom_data>` | ``false`` |
  51. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  52. | :ref:`int<class_int>` | :ref:`visible_instance_count<class_MultiMesh_property_visible_instance_count>` | ``-1`` |
  53. +--------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------+
  54. .. rst-class:: classref-reftable-group
  55. Methods
  56. -------
  57. .. table::
  58. :widths: auto
  59. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`AABB<class_AABB>` | :ref:`get_aabb<class_MultiMesh_method_get_aabb>` **(** **)** |const| |
  61. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Color<class_Color>` | :ref:`get_instance_color<class_MultiMesh_method_get_instance_color>` **(** :ref:`int<class_int>` instance **)** |const| |
  63. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`Color<class_Color>` | :ref:`get_instance_custom_data<class_MultiMesh_method_get_instance_custom_data>` **(** :ref:`int<class_int>` instance **)** |const| |
  65. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Transform3D<class_Transform3D>` | :ref:`get_instance_transform<class_MultiMesh_method_get_instance_transform>` **(** :ref:`int<class_int>` instance **)** |const| |
  67. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_instance_transform_2d<class_MultiMesh_method_get_instance_transform_2d>` **(** :ref:`int<class_int>` instance **)** |const| |
  69. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`set_instance_color<class_MultiMesh_method_set_instance_color>` **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` color **)** |
  71. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set_instance_custom_data<class_MultiMesh_method_set_instance_custom_data>` **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` custom_data **)** |
  73. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`set_instance_transform<class_MultiMesh_method_set_instance_transform>` **(** :ref:`int<class_int>` instance, :ref:`Transform3D<class_Transform3D>` transform **)** |
  75. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`set_instance_transform_2d<class_MultiMesh_method_set_instance_transform_2d>` **(** :ref:`int<class_int>` instance, :ref:`Transform2D<class_Transform2D>` transform **)** |
  77. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. .. rst-class:: classref-section-separator
  79. ----
  80. .. rst-class:: classref-descriptions-group
  81. Enumerations
  82. ------------
  83. .. _enum_MultiMesh_TransformFormat:
  84. .. rst-class:: classref-enumeration
  85. enum **TransformFormat**:
  86. .. _class_MultiMesh_constant_TRANSFORM_2D:
  87. .. rst-class:: classref-enumeration-constant
  88. :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` **TRANSFORM_2D** = ``0``
  89. Use this when using 2D transforms.
  90. .. _class_MultiMesh_constant_TRANSFORM_3D:
  91. .. rst-class:: classref-enumeration-constant
  92. :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` **TRANSFORM_3D** = ``1``
  93. Use this when using 3D transforms.
  94. .. rst-class:: classref-section-separator
  95. ----
  96. .. rst-class:: classref-descriptions-group
  97. Property Descriptions
  98. ---------------------
  99. .. _class_MultiMesh_property_buffer:
  100. .. rst-class:: classref-property
  101. :ref:`PackedFloat32Array<class_PackedFloat32Array>` **buffer** = ``PackedFloat32Array()``
  102. .. rst-class:: classref-property-setget
  103. - void **set_buffer** **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` value **)**
  104. - :ref:`PackedFloat32Array<class_PackedFloat32Array>` **get_buffer** **(** **)**
  105. .. container:: contribute
  106. There is currently no description for this property. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_MultiMesh_property_color_array:
  110. .. rst-class:: classref-property
  111. :ref:`PackedColorArray<class_PackedColorArray>` **color_array**
  112. See :ref:`set_instance_color<class_MultiMesh_method_set_instance_color>`.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_MultiMesh_property_custom_data_array:
  116. .. rst-class:: classref-property
  117. :ref:`PackedColorArray<class_PackedColorArray>` **custom_data_array**
  118. See :ref:`set_instance_custom_data<class_MultiMesh_method_set_instance_custom_data>`.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_MultiMesh_property_instance_count:
  122. .. rst-class:: classref-property
  123. :ref:`int<class_int>` **instance_count** = ``0``
  124. .. rst-class:: classref-property-setget
  125. - void **set_instance_count** **(** :ref:`int<class_int>` value **)**
  126. - :ref:`int<class_int>` **get_instance_count** **(** **)**
  127. Number of instances that will get drawn. This clears and (re)sizes the buffers. Setting data format or flags afterwards will have no effect.
  128. By default, all instances are drawn but you can limit this with :ref:`visible_instance_count<class_MultiMesh_property_visible_instance_count>`.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_MultiMesh_property_mesh:
  132. .. rst-class:: classref-property
  133. :ref:`Mesh<class_Mesh>` **mesh**
  134. .. rst-class:: classref-property-setget
  135. - void **set_mesh** **(** :ref:`Mesh<class_Mesh>` value **)**
  136. - :ref:`Mesh<class_Mesh>` **get_mesh** **(** **)**
  137. :ref:`Mesh<class_Mesh>` resource to be instanced.
  138. The looks of the individual instances can be modified using :ref:`set_instance_color<class_MultiMesh_method_set_instance_color>` and :ref:`set_instance_custom_data<class_MultiMesh_method_set_instance_custom_data>`.
  139. .. rst-class:: classref-item-separator
  140. ----
  141. .. _class_MultiMesh_property_transform_2d_array:
  142. .. rst-class:: classref-property
  143. :ref:`PackedVector2Array<class_PackedVector2Array>` **transform_2d_array**
  144. See :ref:`set_instance_transform_2d<class_MultiMesh_method_set_instance_transform_2d>`.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_MultiMesh_property_transform_array:
  148. .. rst-class:: classref-property
  149. :ref:`PackedVector3Array<class_PackedVector3Array>` **transform_array**
  150. See :ref:`set_instance_transform<class_MultiMesh_method_set_instance_transform>`.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_MultiMesh_property_transform_format:
  154. .. rst-class:: classref-property
  155. :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` **transform_format** = ``0``
  156. .. rst-class:: classref-property-setget
  157. - void **set_transform_format** **(** :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` value **)**
  158. - :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` **get_transform_format** **(** **)**
  159. Format of transform used to transform mesh, either 2D or 3D.
  160. .. rst-class:: classref-item-separator
  161. ----
  162. .. _class_MultiMesh_property_use_colors:
  163. .. rst-class:: classref-property
  164. :ref:`bool<class_bool>` **use_colors** = ``false``
  165. .. rst-class:: classref-property-setget
  166. - void **set_use_colors** **(** :ref:`bool<class_bool>` value **)**
  167. - :ref:`bool<class_bool>` **is_using_colors** **(** **)**
  168. If ``true``, the **MultiMesh** will use color data (see :ref:`set_instance_color<class_MultiMesh_method_set_instance_color>`). Can only be set when :ref:`instance_count<class_MultiMesh_property_instance_count>` is ``0`` or less. This means that you need to call this method before setting the instance count, or temporarily reset it to ``0``.
  169. .. rst-class:: classref-item-separator
  170. ----
  171. .. _class_MultiMesh_property_use_custom_data:
  172. .. rst-class:: classref-property
  173. :ref:`bool<class_bool>` **use_custom_data** = ``false``
  174. .. rst-class:: classref-property-setget
  175. - void **set_use_custom_data** **(** :ref:`bool<class_bool>` value **)**
  176. - :ref:`bool<class_bool>` **is_using_custom_data** **(** **)**
  177. If ``true``, the **MultiMesh** will use custom data (see :ref:`set_instance_custom_data<class_MultiMesh_method_set_instance_custom_data>`). Can only be set when :ref:`instance_count<class_MultiMesh_property_instance_count>` is ``0`` or less. This means that you need to call this method before setting the instance count, or temporarily reset it to ``0``.
  178. .. rst-class:: classref-item-separator
  179. ----
  180. .. _class_MultiMesh_property_visible_instance_count:
  181. .. rst-class:: classref-property
  182. :ref:`int<class_int>` **visible_instance_count** = ``-1``
  183. .. rst-class:: classref-property-setget
  184. - void **set_visible_instance_count** **(** :ref:`int<class_int>` value **)**
  185. - :ref:`int<class_int>` **get_visible_instance_count** **(** **)**
  186. Limits the number of instances drawn, -1 draws all instances. Changing this does not change the sizes of the buffers.
  187. .. rst-class:: classref-section-separator
  188. ----
  189. .. rst-class:: classref-descriptions-group
  190. Method Descriptions
  191. -------------------
  192. .. _class_MultiMesh_method_get_aabb:
  193. .. rst-class:: classref-method
  194. :ref:`AABB<class_AABB>` **get_aabb** **(** **)** |const|
  195. Returns the visibility axis-aligned bounding box in local space.
  196. .. rst-class:: classref-item-separator
  197. ----
  198. .. _class_MultiMesh_method_get_instance_color:
  199. .. rst-class:: classref-method
  200. :ref:`Color<class_Color>` **get_instance_color** **(** :ref:`int<class_int>` instance **)** |const|
  201. Gets a specific instance's color multiplier.
  202. .. rst-class:: classref-item-separator
  203. ----
  204. .. _class_MultiMesh_method_get_instance_custom_data:
  205. .. rst-class:: classref-method
  206. :ref:`Color<class_Color>` **get_instance_custom_data** **(** :ref:`int<class_int>` instance **)** |const|
  207. Returns the custom data that has been set for a specific instance.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. _class_MultiMesh_method_get_instance_transform:
  211. .. rst-class:: classref-method
  212. :ref:`Transform3D<class_Transform3D>` **get_instance_transform** **(** :ref:`int<class_int>` instance **)** |const|
  213. Returns the :ref:`Transform3D<class_Transform3D>` of a specific instance.
  214. .. rst-class:: classref-item-separator
  215. ----
  216. .. _class_MultiMesh_method_get_instance_transform_2d:
  217. .. rst-class:: classref-method
  218. :ref:`Transform2D<class_Transform2D>` **get_instance_transform_2d** **(** :ref:`int<class_int>` instance **)** |const|
  219. Returns the :ref:`Transform2D<class_Transform2D>` of a specific instance.
  220. .. rst-class:: classref-item-separator
  221. ----
  222. .. _class_MultiMesh_method_set_instance_color:
  223. .. rst-class:: classref-method
  224. void **set_instance_color** **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` color **)**
  225. Sets the color of a specific instance by *multiplying* the mesh's existing vertex colors. This allows for different color tinting per instance.
  226. 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. If you intend to set an absolute color instead of tinting, make sure the material's albedo color is set to pure white (``Color(1, 1, 1)``).
  227. .. rst-class:: classref-item-separator
  228. ----
  229. .. _class_MultiMesh_method_set_instance_custom_data:
  230. .. rst-class:: classref-method
  231. void **set_instance_custom_data** **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` custom_data **)**
  232. Sets custom data for a specific instance. Although :ref:`Color<class_Color>` is used, it is just a container for 4 floating point numbers.
  233. For the custom data to be used, ensure that :ref:`use_custom_data<class_MultiMesh_property_use_custom_data>` is ``true``.
  234. This custom instance data has to be manually accessed in your custom shader using ``INSTANCE_CUSTOM``.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_MultiMesh_method_set_instance_transform:
  238. .. rst-class:: classref-method
  239. void **set_instance_transform** **(** :ref:`int<class_int>` instance, :ref:`Transform3D<class_Transform3D>` transform **)**
  240. Sets the :ref:`Transform3D<class_Transform3D>` for a specific instance.
  241. .. rst-class:: classref-item-separator
  242. ----
  243. .. _class_MultiMesh_method_set_instance_transform_2d:
  244. .. rst-class:: classref-method
  245. void **set_instance_transform_2d** **(** :ref:`int<class_int>` instance, :ref:`Transform2D<class_Transform2D>` transform **)**
  246. Sets the :ref:`Transform2D<class_Transform2D>` for a specific instance.
  247. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  248. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  249. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  250. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  251. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  252. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  253. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`