class_multimesh.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the MultiMesh.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_MultiMesh:
  5. MultiMesh
  6. =========
  7. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Provides high performance mesh instancing.
  12. Properties
  13. ----------
  14. +----------------------------------------------------------+--------------------------------------------------------------------------------+
  15. | :ref:`ColorFormat<enum_MultiMesh_ColorFormat>` | :ref:`color_format<class_MultiMesh_property_color_format>` |
  16. +----------------------------------------------------------+--------------------------------------------------------------------------------+
  17. | :ref:`CustomDataFormat<enum_MultiMesh_CustomDataFormat>` | :ref:`custom_data_format<class_MultiMesh_property_custom_data_format>` |
  18. +----------------------------------------------------------+--------------------------------------------------------------------------------+
  19. | :ref:`int<class_int>` | :ref:`instance_count<class_MultiMesh_property_instance_count>` |
  20. +----------------------------------------------------------+--------------------------------------------------------------------------------+
  21. | :ref:`Mesh<class_Mesh>` | :ref:`mesh<class_MultiMesh_property_mesh>` |
  22. +----------------------------------------------------------+--------------------------------------------------------------------------------+
  23. | :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` | :ref:`transform_format<class_MultiMesh_property_transform_format>` |
  24. +----------------------------------------------------------+--------------------------------------------------------------------------------+
  25. | :ref:`int<class_int>` | :ref:`visible_instance_count<class_MultiMesh_property_visible_instance_count>` |
  26. +----------------------------------------------------------+--------------------------------------------------------------------------------+
  27. Methods
  28. -------
  29. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`AABB<class_AABB>` | :ref:`get_aabb<class_MultiMesh_method_get_aabb>` **(** **)** const |
  31. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Color<class_Color>` | :ref:`get_instance_color<class_MultiMesh_method_get_instance_color>` **(** :ref:`int<class_int>` instance **)** const |
  33. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Color<class_Color>` | :ref:`get_instance_custom_data<class_MultiMesh_method_get_instance_custom_data>` **(** :ref:`int<class_int>` instance **)** const |
  35. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Transform<class_Transform>` | :ref:`get_instance_transform<class_MultiMesh_method_get_instance_transform>` **(** :ref:`int<class_int>` instance **)** const |
  37. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_instance_transform_2d<class_MultiMesh_method_get_instance_transform_2d>` **(** :ref:`int<class_int>` instance **)** const |
  39. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`set_as_bulk_array<class_MultiMesh_method_set_as_bulk_array>` **(** :ref:`PoolRealArray<class_PoolRealArray>` array **)** |
  41. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`set_instance_color<class_MultiMesh_method_set_instance_color>` **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` color **)** |
  43. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`set_instance_custom_data<class_MultiMesh_method_set_instance_custom_data>` **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` custom_data **)** |
  45. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`set_instance_transform<class_MultiMesh_method_set_instance_transform>` **(** :ref:`int<class_int>` instance, :ref:`Transform<class_Transform>` transform **)** |
  47. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`set_instance_transform_2d<class_MultiMesh_method_set_instance_transform_2d>` **(** :ref:`int<class_int>` instance, :ref:`Transform2D<class_Transform2D>` transform **)** |
  49. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. Enumerations
  51. ------------
  52. .. _enum_MultiMesh_TransformFormat:
  53. .. _class_MultiMesh_constant_TRANSFORM_2D:
  54. .. _class_MultiMesh_constant_TRANSFORM_3D:
  55. enum **TransformFormat**:
  56. - **TRANSFORM_2D** = **0** --- Use this when using 2D transforms.
  57. - **TRANSFORM_3D** = **1** --- Use this when using 3D transforms.
  58. .. _enum_MultiMesh_ColorFormat:
  59. .. _class_MultiMesh_constant_COLOR_NONE:
  60. .. _class_MultiMesh_constant_COLOR_8BIT:
  61. .. _class_MultiMesh_constant_COLOR_FLOAT:
  62. enum **ColorFormat**:
  63. - **COLOR_NONE** = **0** --- Use when you are not using per-instance :ref:`Color<class_Color>`\ s.
  64. - **COLOR_8BIT** = **1** --- Compress :ref:`Color<class_Color>` data into 8 bits when passing to shader. This uses less memory and can be faster, but the :ref:`Color<class_Color>` loses precision.
  65. - **COLOR_FLOAT** = **2** --- The :ref:`Color<class_Color>` passed into :ref:`set_instance_color<class_MultiMesh_method_set_instance_color>` will use 4 floats. Use this for highest precision :ref:`Color<class_Color>`.
  66. .. _enum_MultiMesh_CustomDataFormat:
  67. .. _class_MultiMesh_constant_CUSTOM_DATA_NONE:
  68. .. _class_MultiMesh_constant_CUSTOM_DATA_8BIT:
  69. .. _class_MultiMesh_constant_CUSTOM_DATA_FLOAT:
  70. enum **CustomDataFormat**:
  71. - **CUSTOM_DATA_NONE** = **0** --- Use when you are not using per-instance custom data.
  72. - **CUSTOM_DATA_8BIT** = **1** --- Compress custom_data into 8 bits when passing to shader. This uses less memory and can be faster, but loses precision.
  73. - **CUSTOM_DATA_FLOAT** = **2** --- The :ref:`Color<class_Color>` passed into :ref:`set_instance_custom_data<class_MultiMesh_method_set_instance_custom_data>` will use 4 floats. Use this for highest precision.
  74. Description
  75. -----------
  76. MultiMesh provides low level mesh instancing. Drawing thousands of :ref:`MeshInstance<class_MeshInstance>` nodes can be slow because each object is submitted to the GPU to be drawn individually.
  77. MultiMesh is much faster because it can draw thousands of instances with a single draw call, resulting in less API overhead.
  78. As a drawback, if the instances are too far away of each other, performance may be reduced as every single instance will always rendered (they are spatially indexed as one, for the whole object).
  79. Since instances may have any behavior, the AABB used for visibility must be provided by the user.
  80. Tutorials
  81. ---------
  82. - :doc:`../tutorials/3d/vertex_animation/animating_thousands_of_fish`
  83. Property Descriptions
  84. ---------------------
  85. .. _class_MultiMesh_property_color_format:
  86. - :ref:`ColorFormat<enum_MultiMesh_ColorFormat>` **color_format**
  87. +----------+-------------------------+
  88. | *Setter* | set_color_format(value) |
  89. +----------+-------------------------+
  90. | *Getter* | get_color_format() |
  91. +----------+-------------------------+
  92. Format of colors in color array that gets passed to shader.
  93. .. _class_MultiMesh_property_custom_data_format:
  94. - :ref:`CustomDataFormat<enum_MultiMesh_CustomDataFormat>` **custom_data_format**
  95. +----------+-------------------------------+
  96. | *Setter* | set_custom_data_format(value) |
  97. +----------+-------------------------------+
  98. | *Getter* | get_custom_data_format() |
  99. +----------+-------------------------------+
  100. Format of custom data in custom data array that gets passed to shader.
  101. .. _class_MultiMesh_property_instance_count:
  102. - :ref:`int<class_int>` **instance_count**
  103. +----------+---------------------------+
  104. | *Setter* | set_instance_count(value) |
  105. +----------+---------------------------+
  106. | *Getter* | get_instance_count() |
  107. +----------+---------------------------+
  108. Number of instances that will get drawn. This clears and (re)sizes the buffers. By default all instances are drawn but you can limit this with :ref:`visible_instance_count<class_MultiMesh_property_visible_instance_count>`.
  109. .. _class_MultiMesh_property_mesh:
  110. - :ref:`Mesh<class_Mesh>` **mesh**
  111. +----------+-----------------+
  112. | *Setter* | set_mesh(value) |
  113. +----------+-----------------+
  114. | *Getter* | get_mesh() |
  115. +----------+-----------------+
  116. Mesh to be drawn.
  117. .. _class_MultiMesh_property_transform_format:
  118. - :ref:`TransformFormat<enum_MultiMesh_TransformFormat>` **transform_format**
  119. +----------+-----------------------------+
  120. | *Setter* | set_transform_format(value) |
  121. +----------+-----------------------------+
  122. | *Getter* | get_transform_format() |
  123. +----------+-----------------------------+
  124. Format of transform used to transform mesh, either 2D or 3D.
  125. .. _class_MultiMesh_property_visible_instance_count:
  126. - :ref:`int<class_int>` **visible_instance_count**
  127. +----------+-----------------------------------+
  128. | *Setter* | set_visible_instance_count(value) |
  129. +----------+-----------------------------------+
  130. | *Getter* | get_visible_instance_count() |
  131. +----------+-----------------------------------+
  132. Limits the number of instances drawn, -1 draws all instances. Changing this does not change the sizes of the buffers.
  133. Method Descriptions
  134. -------------------
  135. .. _class_MultiMesh_method_get_aabb:
  136. - :ref:`AABB<class_AABB>` **get_aabb** **(** **)** const
  137. Return the visibility AABB.
  138. .. _class_MultiMesh_method_get_instance_color:
  139. - :ref:`Color<class_Color>` **get_instance_color** **(** :ref:`int<class_int>` instance **)** const
  140. Get the color of a specific instance.
  141. .. _class_MultiMesh_method_get_instance_custom_data:
  142. - :ref:`Color<class_Color>` **get_instance_custom_data** **(** :ref:`int<class_int>` instance **)** const
  143. Return the custom data that has been set for a specific instance.
  144. .. _class_MultiMesh_method_get_instance_transform:
  145. - :ref:`Transform<class_Transform>` **get_instance_transform** **(** :ref:`int<class_int>` instance **)** const
  146. Return the :ref:`Transform<class_Transform>` of a specific instance.
  147. .. _class_MultiMesh_method_get_instance_transform_2d:
  148. - :ref:`Transform2D<class_Transform2D>` **get_instance_transform_2d** **(** :ref:`int<class_int>` instance **)** const
  149. Return the :ref:`Transform2D<class_Transform2D>` of a specific instance.
  150. .. _class_MultiMesh_method_set_as_bulk_array:
  151. - void **set_as_bulk_array** **(** :ref:`PoolRealArray<class_PoolRealArray>` array **)**
  152. Set all data related to the instances in one go. This is especially useful when loading the data from disk or preparing the data from GDNative.
  153. All data is packed in one large float array. An array may look like this: Transform for instance 1, color data for instance 1, custom data for instance 1, transform for instance 2, color data for instance 2, etc...
  154. :ref:`Transform<class_Transform>` is stored as 12 floats, :ref:`Transform2D<class_Transform2D>` is stored as 8 floats, COLOR_8BIT / CUSTOM_DATA_8BIT is stored as 1 float (4 bytes as is) and COLOR_FLOAT / CUSTOM_DATA_FLOAT is stored as 4 floats.
  155. .. _class_MultiMesh_method_set_instance_color:
  156. - void **set_instance_color** **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` color **)**
  157. Set the color of a specific instance.
  158. For the color to take effect, ensure that :ref:`color_format<class_MultiMesh_property_color_format>` is non-``null`` on the ``MultiMesh`` and :ref:`SpatialMaterial.vertex_color_use_as_albedo<class_SpatialMaterial_property_vertex_color_use_as_albedo>` is ``true`` on the material.
  159. .. _class_MultiMesh_method_set_instance_custom_data:
  160. - void **set_instance_custom_data** **(** :ref:`int<class_int>` instance, :ref:`Color<class_Color>` custom_data **)**
  161. Set custom data for a specific instance. Although :ref:`Color<class_Color>` is used, it is just a container for 4 numbers.
  162. .. _class_MultiMesh_method_set_instance_transform:
  163. - void **set_instance_transform** **(** :ref:`int<class_int>` instance, :ref:`Transform<class_Transform>` transform **)**
  164. Set the :ref:`Transform<class_Transform>` for a specific instance.
  165. .. _class_MultiMesh_method_set_instance_transform_2d:
  166. - void **set_instance_transform_2d** **(** :ref:`int<class_int>` instance, :ref:`Transform2D<class_Transform2D>` transform **)**
  167. Set the :ref:`Transform2D<class_Transform2D>` for a specific instance.