class_meshinstance.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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/MeshInstance.xml.
  6. .. _class_MeshInstance:
  7. MeshInstance
  8. ============
  9. **Inherits:** :ref:`GeometryInstance<class_GeometryInstance>` **<** :ref:`VisualInstance<class_VisualInstance>` **<** :ref:`CullInstance<class_CullInstance>` **<** :ref:`Spatial<class_Spatial>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`SoftBody<class_SoftBody>`
  11. Node that instances meshes into a scenario.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. MeshInstance is a node that takes a :ref:`Mesh<class_Mesh>` resource and adds it to the current scenario by creating an instance of it. This is the class most often used to get 3D geometry rendered and can be used to instance a single :ref:`Mesh<class_Mesh>` in many places. This allows reusing geometry, which can save on resources. When a :ref:`Mesh<class_Mesh>` has to be instanced more than thousands of times at close proximity, consider using a :ref:`MultiMesh<class_MultiMesh>` in a :ref:`MultiMeshInstance<class_MultiMeshInstance>` instead.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - `3D Material Testers Demo <https://godotengine.org/asset-library/asset/123>`__
  20. - `3D Kinematic Character Demo <https://godotengine.org/asset-library/asset/126>`__
  21. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/125>`__
  22. - `Third Person Shooter Demo <https://godotengine.org/asset-library/asset/678>`__
  23. .. rst-class:: classref-reftable-group
  24. Properties
  25. ----------
  26. .. table::
  27. :widths: auto
  28. +---------------------------------+-------------------------------------------------------------------------------------------------------------+--------------------+
  29. | :ref:`Mesh<class_Mesh>` | :ref:`mesh<class_MeshInstance_property_mesh>` | |
  30. +---------------------------------+-------------------------------------------------------------------------------------------------------------+--------------------+
  31. | :ref:`NodePath<class_NodePath>` | :ref:`skeleton<class_MeshInstance_property_skeleton>` | ``NodePath("..")`` |
  32. +---------------------------------+-------------------------------------------------------------------------------------------------------------+--------------------+
  33. | :ref:`Skin<class_Skin>` | :ref:`skin<class_MeshInstance_property_skin>` | |
  34. +---------------------------------+-------------------------------------------------------------------------------------------------------------+--------------------+
  35. | :ref:`bool<class_bool>` | :ref:`software_skinning_transform_normals<class_MeshInstance_property_software_skinning_transform_normals>` | ``true`` |
  36. +---------------------------------+-------------------------------------------------------------------------------------------------------------+--------------------+
  37. .. rst-class:: classref-reftable-group
  38. Methods
  39. -------
  40. .. table::
  41. :widths: auto
  42. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`create_convex_collision<class_MeshInstance_method_create_convex_collision>` **(** :ref:`bool<class_bool>` clean=true, :ref:`bool<class_bool>` simplify=false **)** |
  44. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`create_debug_tangents<class_MeshInstance_method_create_debug_tangents>` **(** **)** |
  46. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`create_multiple_convex_collisions<class_MeshInstance_method_create_multiple_convex_collisions>` **(** **)** |
  48. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`create_trimesh_collision<class_MeshInstance_method_create_trimesh_collision>` **(** **)** |
  50. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Material<class_Material>` | :ref:`get_active_material<class_MeshInstance_method_get_active_material>` **(** :ref:`int<class_int>` surface **)** |const| |
  52. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Material<class_Material>` | :ref:`get_surface_material<class_MeshInstance_method_get_surface_material>` **(** :ref:`int<class_int>` surface **)** |const| |
  54. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`int<class_int>` | :ref:`get_surface_material_count<class_MeshInstance_method_get_surface_material_count>` **(** **)** |const| |
  56. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`is_mergeable_with<class_MeshInstance_method_is_mergeable_with>` **(** :ref:`Node<class_Node>` other_mesh_instance, :ref:`bool<class_bool>` shadows_only=false **)** |const| |
  58. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`merge_meshes<class_MeshInstance_method_merge_meshes>` **(** :ref:`Array<class_Array>` mesh_instances, :ref:`bool<class_bool>` use_global_space=false, :ref:`bool<class_bool>` check_compatibility=true, :ref:`bool<class_bool>` shadows_only=false **)** |
  60. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_surface_material<class_MeshInstance_method_set_surface_material>` **(** :ref:`int<class_int>` surface, :ref:`Material<class_Material>` material **)** |
  62. +---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. .. rst-class:: classref-section-separator
  64. ----
  65. .. rst-class:: classref-descriptions-group
  66. Property Descriptions
  67. ---------------------
  68. .. _class_MeshInstance_property_mesh:
  69. .. rst-class:: classref-property
  70. :ref:`Mesh<class_Mesh>` **mesh**
  71. .. rst-class:: classref-property-setget
  72. - void **set_mesh** **(** :ref:`Mesh<class_Mesh>` value **)**
  73. - :ref:`Mesh<class_Mesh>` **get_mesh** **(** **)**
  74. The :ref:`Mesh<class_Mesh>` resource for the instance.
  75. .. rst-class:: classref-item-separator
  76. ----
  77. .. _class_MeshInstance_property_skeleton:
  78. .. rst-class:: classref-property
  79. :ref:`NodePath<class_NodePath>` **skeleton** = ``NodePath("..")``
  80. .. rst-class:: classref-property-setget
  81. - void **set_skeleton_path** **(** :ref:`NodePath<class_NodePath>` value **)**
  82. - :ref:`NodePath<class_NodePath>` **get_skeleton_path** **(** **)**
  83. :ref:`NodePath<class_NodePath>` to the :ref:`Skeleton<class_Skeleton>` associated with the instance.
  84. .. rst-class:: classref-item-separator
  85. ----
  86. .. _class_MeshInstance_property_skin:
  87. .. rst-class:: classref-property
  88. :ref:`Skin<class_Skin>` **skin**
  89. .. rst-class:: classref-property-setget
  90. - void **set_skin** **(** :ref:`Skin<class_Skin>` value **)**
  91. - :ref:`Skin<class_Skin>` **get_skin** **(** **)**
  92. Sets the skin to be used by this instance.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_MeshInstance_property_software_skinning_transform_normals:
  96. .. rst-class:: classref-property
  97. :ref:`bool<class_bool>` **software_skinning_transform_normals** = ``true``
  98. .. rst-class:: classref-property-setget
  99. - void **set_software_skinning_transform_normals** **(** :ref:`bool<class_bool>` value **)**
  100. - :ref:`bool<class_bool>` **is_software_skinning_transform_normals_enabled** **(** **)**
  101. If ``true``, normals are transformed when software skinning is used. Set to ``false`` when normals are not needed for better performance.
  102. See :ref:`ProjectSettings.rendering/quality/skinning/software_skinning_fallback<class_ProjectSettings_property_rendering/quality/skinning/software_skinning_fallback>` for details about how software skinning is enabled.
  103. .. rst-class:: classref-section-separator
  104. ----
  105. .. rst-class:: classref-descriptions-group
  106. Method Descriptions
  107. -------------------
  108. .. _class_MeshInstance_method_create_convex_collision:
  109. .. rst-class:: classref-method
  110. void **create_convex_collision** **(** :ref:`bool<class_bool>` clean=true, :ref:`bool<class_bool>` simplify=false **)**
  111. This helper creates a :ref:`StaticBody<class_StaticBody>` child node with a :ref:`ConvexPolygonShape<class_ConvexPolygonShape>` collision shape calculated from the mesh geometry. It's mainly used for testing.
  112. If ``clean`` is ``true`` (default), duplicate and interior vertices are removed automatically. You can set it to ``false`` to make the process faster if not needed.
  113. If ``simplify`` is ``true``, the geometry can be further simplified to reduce the amount of vertices. Disabled by default.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_MeshInstance_method_create_debug_tangents:
  117. .. rst-class:: classref-method
  118. void **create_debug_tangents** **(** **)**
  119. This helper creates a **MeshInstance** child node with gizmos at every vertex calculated from the mesh geometry. It's mainly used for testing.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_MeshInstance_method_create_multiple_convex_collisions:
  123. .. rst-class:: classref-method
  124. void **create_multiple_convex_collisions** **(** **)**
  125. This helper creates a :ref:`StaticBody<class_StaticBody>` child node with multiple :ref:`ConvexPolygonShape<class_ConvexPolygonShape>` collision shapes calculated from the mesh geometry via convex decomposition. It's mainly used for testing.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_MeshInstance_method_create_trimesh_collision:
  129. .. rst-class:: classref-method
  130. void **create_trimesh_collision** **(** **)**
  131. This helper creates a :ref:`StaticBody<class_StaticBody>` child node with a :ref:`ConcavePolygonShape<class_ConcavePolygonShape>` collision shape calculated from the mesh geometry. It's mainly used for testing.
  132. .. rst-class:: classref-item-separator
  133. ----
  134. .. _class_MeshInstance_method_get_active_material:
  135. .. rst-class:: classref-method
  136. :ref:`Material<class_Material>` **get_active_material** **(** :ref:`int<class_int>` surface **)** |const|
  137. Returns the :ref:`Material<class_Material>` that will be used by the :ref:`Mesh<class_Mesh>` when drawing. This can return the :ref:`GeometryInstance.material_override<class_GeometryInstance_property_material_override>`, the surface override :ref:`Material<class_Material>` defined in this **MeshInstance**, or the surface :ref:`Material<class_Material>` defined in the :ref:`Mesh<class_Mesh>`. For example, if :ref:`GeometryInstance.material_override<class_GeometryInstance_property_material_override>` is used, all surfaces will return the override material.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_MeshInstance_method_get_surface_material:
  141. .. rst-class:: classref-method
  142. :ref:`Material<class_Material>` **get_surface_material** **(** :ref:`int<class_int>` surface **)** |const|
  143. Returns the override :ref:`Material<class_Material>` for a surface of the :ref:`Mesh<class_Mesh>` resource.
  144. \ **Note:** This function only returns *override* materials associated with this **MeshInstance**. Consider using :ref:`get_active_material<class_MeshInstance_method_get_active_material>` or :ref:`Mesh.surface_get_material<class_Mesh_method_surface_get_material>` to get materials associated with the :ref:`Mesh<class_Mesh>` resource.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_MeshInstance_method_get_surface_material_count:
  148. .. rst-class:: classref-method
  149. :ref:`int<class_int>` **get_surface_material_count** **(** **)** |const|
  150. Returns the number of surface override materials.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_MeshInstance_method_is_mergeable_with:
  154. .. rst-class:: classref-method
  155. :ref:`bool<class_bool>` **is_mergeable_with** **(** :ref:`Node<class_Node>` other_mesh_instance, :ref:`bool<class_bool>` shadows_only=false **)** |const|
  156. Returns ``true`` if this **MeshInstance** can be merged with the specified ``other_mesh_instance``, using the :ref:`merge_meshes<class_MeshInstance_method_merge_meshes>` function.
  157. In order to be mergeable, properties of the **MeshInstance** must match, and each surface must match, in terms of material, attributes and vertex format.
  158. .. rst-class:: classref-item-separator
  159. ----
  160. .. _class_MeshInstance_method_merge_meshes:
  161. .. rst-class:: classref-method
  162. :ref:`bool<class_bool>` **merge_meshes** **(** :ref:`Array<class_Array>` mesh_instances, :ref:`bool<class_bool>` use_global_space=false, :ref:`bool<class_bool>` check_compatibility=true, :ref:`bool<class_bool>` shadows_only=false **)**
  163. This function can merge together the data from several source **MeshInstance**\ s into a single destination **MeshInstance** (the MeshInstance the function is called from). This is primarily useful for improving performance by reducing the number of drawcalls and :ref:`Node<class_Node>`\ s.
  164. Merging should only be attempted for simple meshes that do not contain animation.
  165. The final vertices can either be returned in global space, or in local space relative to the destination **MeshInstance** global transform (the destination Node must be inside the :ref:`SceneTree<class_SceneTree>` for local space to work).
  166. The function will make a final check for compatibility between the **MeshInstance**\ s by default, this should always be used unless you have previously checked for compatibility using :ref:`is_mergeable_with<class_MeshInstance_method_is_mergeable_with>`. If the compatibility check is omitted and the meshes are merged, you may see rendering errors.
  167. \ **Note:** The requirements for similarity between meshes are quite stringent. They can be checked using the :ref:`is_mergeable_with<class_MeshInstance_method_is_mergeable_with>` function prior to calling :ref:`merge_meshes<class_MeshInstance_method_merge_meshes>`.
  168. Also note that any initial data in the destination **MeshInstance** data will be discarded.
  169. .. rst-class:: classref-item-separator
  170. ----
  171. .. _class_MeshInstance_method_set_surface_material:
  172. .. rst-class:: classref-method
  173. void **set_surface_material** **(** :ref:`int<class_int>` surface, :ref:`Material<class_Material>` material **)**
  174. Sets the override :ref:`Material<class_Material>` for the specified surface of the :ref:`Mesh<class_Mesh>` resource. This material is associated with this **MeshInstance** rather than with the :ref:`Mesh<class_Mesh>` resource.
  175. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  176. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  177. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  178. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`