class_mergegroup.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/MergeGroup.xml.
  6. .. _class_MergeGroup:
  7. MergeGroup
  8. ==========
  9. **Inherits:** :ref:`Spatial<class_Spatial>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. MergeGroups allow merging of suitable meshes, which can enhance performance.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **MergeGroup** is a way of grouping nodes into logical blocks that contain meshes that are suitable for joining together, in order to increase rendering efficiency and reduce the number of nodes to simplify the scene.
  15. Only children and descendants will be considered for merging. **MergeGroup** has no effect on parents or siblings.
  16. Meshes must be static (non-moving) in relation to one another to be joined. For instance, a level background is often intended to be static. However, logical blocks that **move** together, such as a ship, or car, are also good candidates for merging.
  17. Within these blocks you will often want to prevent certain nodes or branches from being merged, because they **are** intended to move, or change visibility, in relation to the main block. An example might be a steering wheel on a ship. You can finely control this with :ref:`Spatial.merging_mode<class_Spatial_property_merging_mode>`. Be aware that :ref:`Spatial.merging_mode<class_Spatial_property_merging_mode>` will be inherited from parents and ancestors of the **MergeGroup**.
  18. There are two ways of performing merging:
  19. - At runtime, using :ref:`merge_meshes<class_MergeGroup_method_merge_meshes>` or :ref:`auto_merge<class_MergeGroup_property_auto_merge>`.
  20. - Baking at design time to a separate scene, using the ``bake`` button in the Editor inspector.
  21. Merging at runtime is usually best, because it is non-destructive, and will minimize the binary size of the ``pck`` file. It can however take a small amount of time to merge the meshes (usually during level load), but this will usually be well under a second.
  22. Baking ahead of time allows fastest possible load times, but it is by nature a *destructive* operation - you should keep a copy of the source scene for later editing, because you cannot reconstruct an unmerged scene from a baked scene. It can also bloat the size of the ``pck`` file considerably, as for example storing 10 merged trees will have 10x the geometry of the scene before merging.
  23. On the other hand, baking ahead of time is very useful for previewing what will happen after merging, and diagnosing problems. It is also convenient for some workflows such as constructing a scene out of merged modular units.
  24. .. rst-class:: classref-reftable-group
  25. Properties
  26. ----------
  27. .. table::
  28. :widths: auto
  29. +-------------------------+-------------------------------------------------------------+----------+
  30. | :ref:`bool<class_bool>` | :ref:`auto_merge<class_MergeGroup_property_auto_merge>` | ``true`` |
  31. +-------------------------+-------------------------------------------------------------+----------+
  32. | :ref:`bool<class_bool>` | :ref:`shadow_proxy<class_MergeGroup_property_shadow_proxy>` | ``true`` |
  33. +-------------------------+-------------------------------------------------------------+----------+
  34. .. rst-class:: classref-reftable-group
  35. Methods
  36. -------
  37. .. table::
  38. :widths: auto
  39. +-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_param<class_MergeGroup_method_get_param>` **(** :ref:`Param<enum_MergeGroup_Param>` param **)** |
  41. +-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`get_param_enabled<class_MergeGroup_method_get_param_enabled>` **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param **)** |
  43. +-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`merge_meshes<class_MergeGroup_method_merge_meshes>` **(** **)** |
  45. +-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`set_param<class_MergeGroup_method_set_param>` **(** :ref:`Param<enum_MergeGroup_Param>` param, :ref:`int<class_int>` value **)** |
  47. +-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`set_param_enabled<class_MergeGroup_method_set_param_enabled>` **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param, :ref:`bool<class_bool>` value **)** |
  49. +-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. .. rst-class:: classref-section-separator
  51. ----
  52. .. rst-class:: classref-descriptions-group
  53. Enumerations
  54. ------------
  55. .. _enum_MergeGroup_ParamEnabled:
  56. .. rst-class:: classref-enumeration
  57. enum **ParamEnabled**:
  58. .. _class_MergeGroup_constant_PARAM_ENABLED_AUTO_MERGE:
  59. .. rst-class:: classref-enumeration-constant
  60. :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` **PARAM_ENABLED_AUTO_MERGE** = ``0``
  61. Activates merging automatically when the **MergeGroup** enters the scene (usually during loading).
  62. Alternatively you can switch this off and use :ref:`merge_meshes<class_MergeGroup_method_merge_meshes>` to manually activate merging.
  63. .. _class_MergeGroup_constant_PARAM_ENABLED_SHADOW_PROXY:
  64. .. rst-class:: classref-enumeration-constant
  65. :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` **PARAM_ENABLED_SHADOW_PROXY** = ``1``
  66. If ``true``, a **shadow proxy** will be generated. This is a merged mesh that is a duplicate of the existing opaque geometry, set to cast shadows only. The source meshes will have shadow casting switched off.
  67. This can be more efficient for rendering shadows, because the requirements for merging a **shadow mesh** are far lower than for regular merging. Providing materials are opaque, meshes with different materials can often be merged together for the purposes of shadow casting. This can reduce drawcalls.
  68. \ **Tip:** Try running with and without a **shadow proxy** and measure performance, sometimes it will be faster, sometimes not.
  69. .. _class_MergeGroup_constant_PARAM_ENABLED_CONVERT_CSGS:
  70. .. rst-class:: classref-enumeration-constant
  71. :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` **PARAM_ENABLED_CONVERT_CSGS** = ``2``
  72. If ``true``, ``CSG`` nodes will be converted to :ref:`MeshInstance<class_MeshInstance>`\ s. These :ref:`MeshInstance<class_MeshInstance>`\ s can then be merged if suitable matches are found.
  73. .. _class_MergeGroup_constant_PARAM_ENABLED_CONVERT_GRIDMAPS:
  74. .. rst-class:: classref-enumeration-constant
  75. :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` **PARAM_ENABLED_CONVERT_GRIDMAPS** = ``3``
  76. If ``true``, :ref:`GridMap<class_GridMap>`\ s will be converted to :ref:`MeshInstance<class_MeshInstance>`\ s. These :ref:`MeshInstance<class_MeshInstance>`\ s can then be merged if suitable matches are found.
  77. \ **Note:** :ref:`GridMap<class_GridMap>`\ s are usually rendered as :ref:`MultiMesh<class_MultiMesh>`\ es very efficiently, so converting these will often be counterproductive. Exceptions include when using the ``GLES2`` backend, which can be inefficient at rendering :ref:`MultiMesh<class_MultiMesh>`.
  78. .. _class_MergeGroup_constant_PARAM_ENABLED_COMBINE_SURFACES:
  79. .. rst-class:: classref-enumeration-constant
  80. :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` **PARAM_ENABLED_COMBINE_SURFACES** = ``4``
  81. If ``true``, as a final step, matching :ref:`MeshInstance<class_MeshInstance>`\ s can be joined by combining their surfaces to form an *"uber mesh instance"*.
  82. While this is convenient, it does have the downside that all the constituent meshes will be culled as one unit, which can make culling less efficient in some situations.
  83. .. _class_MergeGroup_constant_PARAM_ENABLED_CLEAN_MESHES:
  84. .. rst-class:: classref-enumeration-constant
  85. :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` **PARAM_ENABLED_CLEAN_MESHES** = ``5``
  86. Cleans and removes degenerate triangles from meshes, which can make them more suitable for later processing, such as generating secondary UVs for lightmapping.
  87. \ **Note:** This step can be slow and should typically only be used when *baking* the **MergeGroup**.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _enum_MergeGroup_Param:
  91. .. rst-class:: classref-enumeration
  92. enum **Param**:
  93. .. _class_MergeGroup_constant_PARAM_GROUP_SIZE:
  94. .. rst-class:: classref-enumeration-constant
  95. :ref:`Param<enum_MergeGroup_Param>` **PARAM_GROUP_SIZE** = ``0``
  96. When set to ``0``, all matching meshes will be merged within the **MergeGroup**.
  97. If set to ``1`` or above, only groups of a maximum of ``group_size`` meshes will be merged together. These groups will be chosen by locality. This enables getting some of the benefits of merging, while still allowing some culling to take place.
  98. \ **Tip:** Use *baking* to preview what the scene will look like after merging.
  99. .. _class_MergeGroup_constant_PARAM_SPLITS_HORIZONTAL:
  100. .. rst-class:: classref-enumeration-constant
  101. :ref:`Param<enum_MergeGroup_Param>` **PARAM_SPLITS_HORIZONTAL** = ``1``
  102. When set to a value above ``1``, mesh geometry will be *split by locality* into a grid of :ref:`MeshInstance<class_MeshInstance>`\ s.
  103. For instance a value of ``2`` will split meshes into a grid of 2x2 (on the ``x`` and ``z`` axes), for greater culling efficiency.
  104. \ **Note:** Greater culling efficiency must be balanced against a greater number of drawcalls.
  105. .. _class_MergeGroup_constant_PARAM_SPLITS_VERTICAL:
  106. .. rst-class:: classref-enumeration-constant
  107. :ref:`Param<enum_MergeGroup_Param>` **PARAM_SPLITS_VERTICAL** = ``2``
  108. This setting acts exactly as :ref:`PARAM_SPLITS_HORIZONTAL<class_MergeGroup_constant_PARAM_SPLITS_HORIZONTAL>`, except it determines the grid split on the vertical axis.
  109. A grid with :ref:`PARAM_SPLITS_HORIZONTAL<class_MergeGroup_constant_PARAM_SPLITS_HORIZONTAL>` ``3``, and :ref:`PARAM_SPLITS_VERTICAL<class_MergeGroup_constant_PARAM_SPLITS_VERTICAL>` ``2`` will produce a grid of 3x2x3 (on the ``x`` and ``y`` and ``z`` axes respectively).
  110. .. _class_MergeGroup_constant_PARAM_MIN_SPLIT_POLY_COUNT:
  111. .. rst-class:: classref-enumeration-constant
  112. :ref:`Param<enum_MergeGroup_Param>` **PARAM_MIN_SPLIT_POLY_COUNT** = ``3``
  113. When using *split by locality* using :ref:`PARAM_SPLITS_HORIZONTAL<class_MergeGroup_constant_PARAM_SPLITS_HORIZONTAL>` and / or :ref:`PARAM_SPLITS_VERTICAL<class_MergeGroup_constant_PARAM_SPLITS_VERTICAL>`, you can specify that the split will only occur for meshes above this specified poly count.
  114. There is often little to gain by splitting meshes with low poly count.
  115. .. rst-class:: classref-section-separator
  116. ----
  117. .. rst-class:: classref-descriptions-group
  118. Property Descriptions
  119. ---------------------
  120. .. _class_MergeGroup_property_auto_merge:
  121. .. rst-class:: classref-property
  122. :ref:`bool<class_bool>` **auto_merge** = ``true``
  123. .. rst-class:: classref-property-setget
  124. - void **set_param_enabled** **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param, :ref:`bool<class_bool>` value **)**
  125. - :ref:`bool<class_bool>` **get_param_enabled** **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param **)**
  126. Activates merging automatically when the **MergeGroup** enters the scene (usually during loading).
  127. Alternatively you can switch this off and use :ref:`merge_meshes<class_MergeGroup_method_merge_meshes>` to manually activate merging.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_MergeGroup_property_shadow_proxy:
  131. .. rst-class:: classref-property
  132. :ref:`bool<class_bool>` **shadow_proxy** = ``true``
  133. .. rst-class:: classref-property-setget
  134. - void **set_param_enabled** **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param, :ref:`bool<class_bool>` value **)**
  135. - :ref:`bool<class_bool>` **get_param_enabled** **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param **)**
  136. If ``true``, a **shadow proxy** will be generated. This is a merged mesh that is a duplicate of the existing opaque geometry, set to cast shadows only. The source meshes will have shadow casting switched off.
  137. This can be more efficient for rendering shadows, because the requirements for merging a **shadow mesh** are far lower than for regular merging. Providing materials are opaque, meshes with different materials can often be merged together for the purposes of shadow casting. This can reduce drawcalls.
  138. \ **Tip:** Try running with and without a **shadow proxy** and measure performance, sometimes it will be faster, sometimes not.
  139. .. rst-class:: classref-section-separator
  140. ----
  141. .. rst-class:: classref-descriptions-group
  142. Method Descriptions
  143. -------------------
  144. .. _class_MergeGroup_method_get_param:
  145. .. rst-class:: classref-method
  146. :ref:`int<class_int>` **get_param** **(** :ref:`Param<enum_MergeGroup_Param>` param **)**
  147. Returns the value of the specified :ref:`Param<enum_MergeGroup_Param>` parameter.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_MergeGroup_method_get_param_enabled:
  151. .. rst-class:: classref-method
  152. :ref:`bool<class_bool>` **get_param_enabled** **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param **)**
  153. Gets the value of the specified :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` parameter.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_MergeGroup_method_merge_meshes:
  157. .. rst-class:: classref-method
  158. void **merge_meshes** **(** **)**
  159. You can choose to either automatically merge when the **MergeGroup** enters the scene (usually during loading) using :ref:`auto_merge<class_MergeGroup_property_auto_merge>`, or you can manually trigger merging by calling this function.
  160. Manually activating merging is especially useful when you are *procedurally generating* your level, and when you want to set advanced parameters prior to merging at runtime.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_MergeGroup_method_set_param:
  164. .. rst-class:: classref-method
  165. void **set_param** **(** :ref:`Param<enum_MergeGroup_Param>` param, :ref:`int<class_int>` value **)**
  166. Sets the value of the specified :ref:`Param<enum_MergeGroup_Param>` parameter.
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_MergeGroup_method_set_param_enabled:
  170. .. rst-class:: classref-method
  171. void **set_param_enabled** **(** :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` param, :ref:`bool<class_bool>` value **)**
  172. Sets the value of the specified :ref:`ParamEnabled<enum_MergeGroup_ParamEnabled>` parameter.
  173. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  174. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  175. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  176. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`