2
0

class_mesh.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/Mesh.xml.
  6. .. _class_Mesh:
  7. Mesh
  8. ====
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`ArrayMesh<class_ArrayMesh>`, :ref:`PrimitiveMesh<class_PrimitiveMesh>`
  11. A :ref:`Resource<class_Resource>` that contains vertex array-based geometry.
  12. Description
  13. -----------
  14. Mesh is a type of :ref:`Resource<class_Resource>` that contains vertex array-based geometry, divided in *surfaces*. Each surface contains a completely separate array and a material used to draw it. Design wise, a mesh with multiple surfaces is preferred to a single surface, because objects created in 3D editing software commonly contain multiple materials.
  15. Tutorials
  16. ---------
  17. - `3D Material Testers Demo <https://godotengine.org/asset-library/asset/123>`__
  18. - `3D Kinematic Character Demo <https://godotengine.org/asset-library/asset/126>`__
  19. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/125>`__
  20. - `Third Person Shooter Demo <https://godotengine.org/asset-library/asset/678>`__
  21. Properties
  22. ----------
  23. +-------------------------------+-------------------------------------------------------------------+---------------------+
  24. | :ref:`Vector2<class_Vector2>` | :ref:`lightmap_size_hint<class_Mesh_property_lightmap_size_hint>` | ``Vector2( 0, 0 )`` |
  25. +-------------------------------+-------------------------------------------------------------------+---------------------+
  26. Methods
  27. -------
  28. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Shape<class_Shape>` | :ref:`create_convex_shape<class_Mesh_method_create_convex_shape>` **(** :ref:`bool<class_bool>` clean=true, :ref:`bool<class_bool>` simplify=false **)** |const| |
  30. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Mesh<class_Mesh>` | :ref:`create_outline<class_Mesh_method_create_outline>` **(** :ref:`float<class_float>` margin **)** |const| |
  32. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Shape<class_Shape>` | :ref:`create_trimesh_shape<class_Mesh_method_create_trimesh_shape>` **(** **)** |const| |
  34. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`TriangleMesh<class_TriangleMesh>` | :ref:`generate_triangle_mesh<class_Mesh_method_generate_triangle_mesh>` **(** **)** |const| |
  36. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`AABB<class_AABB>` | :ref:`get_aabb<class_Mesh_method_get_aabb>` **(** **)** |const| |
  38. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`PoolVector3Array<class_PoolVector3Array>` | :ref:`get_faces<class_Mesh_method_get_faces>` **(** **)** |const| |
  40. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | :ref:`get_surface_count<class_Mesh_method_get_surface_count>` **(** **)** |const| |
  42. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Array<class_Array>` | :ref:`surface_get_arrays<class_Mesh_method_surface_get_arrays>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  44. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Array<class_Array>` | :ref:`surface_get_blend_shape_arrays<class_Mesh_method_surface_get_blend_shape_arrays>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  46. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Material<class_Material>` | :ref:`surface_get_material<class_Mesh_method_surface_get_material>` **(** :ref:`int<class_int>` surf_idx **)** |const| |
  48. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`surface_set_material<class_Mesh_method_surface_set_material>` **(** :ref:`int<class_int>` surf_idx, :ref:`Material<class_Material>` material **)** |
  50. +-------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. Enumerations
  52. ------------
  53. .. _enum_Mesh_PrimitiveType:
  54. .. _class_Mesh_constant_PRIMITIVE_POINTS:
  55. .. _class_Mesh_constant_PRIMITIVE_LINES:
  56. .. _class_Mesh_constant_PRIMITIVE_LINE_STRIP:
  57. .. _class_Mesh_constant_PRIMITIVE_LINE_LOOP:
  58. .. _class_Mesh_constant_PRIMITIVE_TRIANGLES:
  59. .. _class_Mesh_constant_PRIMITIVE_TRIANGLE_STRIP:
  60. .. _class_Mesh_constant_PRIMITIVE_TRIANGLE_FAN:
  61. enum **PrimitiveType**:
  62. - **PRIMITIVE_POINTS** = **0** --- Render array as points (one vertex equals one point).
  63. - **PRIMITIVE_LINES** = **1** --- Render array as lines (every two vertices a line is created).
  64. - **PRIMITIVE_LINE_STRIP** = **2** --- Render array as line strip.
  65. - **PRIMITIVE_LINE_LOOP** = **3** --- Render array as line loop (like line strip, but closed).
  66. - **PRIMITIVE_TRIANGLES** = **4** --- Render array as triangles (every three vertices a triangle is created).
  67. - **PRIMITIVE_TRIANGLE_STRIP** = **5** --- Render array as triangle strips.
  68. - **PRIMITIVE_TRIANGLE_FAN** = **6** --- Render array as triangle fans.
  69. ----
  70. .. _enum_Mesh_BlendShapeMode:
  71. .. _class_Mesh_constant_BLEND_SHAPE_MODE_NORMALIZED:
  72. .. _class_Mesh_constant_BLEND_SHAPE_MODE_RELATIVE:
  73. enum **BlendShapeMode**:
  74. - **BLEND_SHAPE_MODE_NORMALIZED** = **0** --- Blend shapes are normalized.
  75. - **BLEND_SHAPE_MODE_RELATIVE** = **1** --- Blend shapes are relative to base weight.
  76. ----
  77. .. _enum_Mesh_ArrayFormat:
  78. .. _class_Mesh_constant_ARRAY_FORMAT_VERTEX:
  79. .. _class_Mesh_constant_ARRAY_FORMAT_NORMAL:
  80. .. _class_Mesh_constant_ARRAY_FORMAT_TANGENT:
  81. .. _class_Mesh_constant_ARRAY_FORMAT_COLOR:
  82. .. _class_Mesh_constant_ARRAY_FORMAT_TEX_UV:
  83. .. _class_Mesh_constant_ARRAY_FORMAT_TEX_UV2:
  84. .. _class_Mesh_constant_ARRAY_FORMAT_BONES:
  85. .. _class_Mesh_constant_ARRAY_FORMAT_WEIGHTS:
  86. .. _class_Mesh_constant_ARRAY_FORMAT_INDEX:
  87. .. _class_Mesh_constant_ARRAY_COMPRESS_BASE:
  88. .. _class_Mesh_constant_ARRAY_COMPRESS_VERTEX:
  89. .. _class_Mesh_constant_ARRAY_COMPRESS_NORMAL:
  90. .. _class_Mesh_constant_ARRAY_COMPRESS_TANGENT:
  91. .. _class_Mesh_constant_ARRAY_COMPRESS_COLOR:
  92. .. _class_Mesh_constant_ARRAY_COMPRESS_TEX_UV:
  93. .. _class_Mesh_constant_ARRAY_COMPRESS_TEX_UV2:
  94. .. _class_Mesh_constant_ARRAY_COMPRESS_BONES:
  95. .. _class_Mesh_constant_ARRAY_COMPRESS_WEIGHTS:
  96. .. _class_Mesh_constant_ARRAY_COMPRESS_INDEX:
  97. .. _class_Mesh_constant_ARRAY_FLAG_USE_2D_VERTICES:
  98. .. _class_Mesh_constant_ARRAY_FLAG_USE_16_BIT_BONES:
  99. .. _class_Mesh_constant_ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION:
  100. .. _class_Mesh_constant_ARRAY_COMPRESS_DEFAULT:
  101. enum **ArrayFormat**:
  102. - **ARRAY_FORMAT_VERTEX** = **1** --- Mesh array contains vertices. All meshes require a vertex array so this should always be present.
  103. - **ARRAY_FORMAT_NORMAL** = **2** --- Mesh array contains normals.
  104. - **ARRAY_FORMAT_TANGENT** = **4** --- Mesh array contains tangents.
  105. - **ARRAY_FORMAT_COLOR** = **8** --- Mesh array contains colors.
  106. - **ARRAY_FORMAT_TEX_UV** = **16** --- Mesh array contains UVs.
  107. - **ARRAY_FORMAT_TEX_UV2** = **32** --- Mesh array contains second UV.
  108. - **ARRAY_FORMAT_BONES** = **64** --- Mesh array contains bones.
  109. - **ARRAY_FORMAT_WEIGHTS** = **128** --- Mesh array contains bone weights.
  110. - **ARRAY_FORMAT_INDEX** = **256** --- Mesh array uses indices.
  111. - **ARRAY_COMPRESS_BASE** = **9** --- Used internally to calculate other ``ARRAY_COMPRESS_*`` enum values. Do not use.
  112. - **ARRAY_COMPRESS_VERTEX** = **512** --- Flag used to mark a compressed (half float) vertex array.
  113. - **ARRAY_COMPRESS_NORMAL** = **1024** --- Flag used to mark a compressed (half float) normal array.
  114. - **ARRAY_COMPRESS_TANGENT** = **2048** --- Flag used to mark a compressed (half float) tangent array.
  115. - **ARRAY_COMPRESS_COLOR** = **4096** --- Flag used to mark a compressed (half float) color array.
  116. \ **Note:** If this flag is enabled, vertex colors will be stored as 8-bit unsigned integers. This will clamp overbright colors to ``Color(1, 1, 1, 1)`` and reduce colors' precision.
  117. - **ARRAY_COMPRESS_TEX_UV** = **8192** --- Flag used to mark a compressed (half float) UV coordinates array.
  118. - **ARRAY_COMPRESS_TEX_UV2** = **16384** --- Flag used to mark a compressed (half float) UV coordinates array for the second UV coordinates.
  119. - **ARRAY_COMPRESS_BONES** = **32768** --- Flag used to mark a compressed bone array.
  120. - **ARRAY_COMPRESS_WEIGHTS** = **65536** --- Flag used to mark a compressed (half float) weight array.
  121. - **ARRAY_COMPRESS_INDEX** = **131072** --- Flag used to mark a compressed index array.
  122. - **ARRAY_FLAG_USE_2D_VERTICES** = **262144** --- Flag used to mark that the array contains 2D vertices.
  123. - **ARRAY_FLAG_USE_16_BIT_BONES** = **524288** --- Flag used to mark that the array uses 16-bit bones instead of 8-bit.
  124. - **ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION** = **2097152** --- Flag used to mark that the array uses an octahedral representation of normal and tangent vectors rather than cartesian.
  125. - **ARRAY_COMPRESS_DEFAULT** = **2194432** --- Used to set flags :ref:`ARRAY_COMPRESS_VERTEX<class_Mesh_constant_ARRAY_COMPRESS_VERTEX>`, :ref:`ARRAY_COMPRESS_NORMAL<class_Mesh_constant_ARRAY_COMPRESS_NORMAL>`, :ref:`ARRAY_COMPRESS_TANGENT<class_Mesh_constant_ARRAY_COMPRESS_TANGENT>`, :ref:`ARRAY_COMPRESS_COLOR<class_Mesh_constant_ARRAY_COMPRESS_COLOR>`, :ref:`ARRAY_COMPRESS_TEX_UV<class_Mesh_constant_ARRAY_COMPRESS_TEX_UV>`, :ref:`ARRAY_COMPRESS_TEX_UV2<class_Mesh_constant_ARRAY_COMPRESS_TEX_UV2>`, :ref:`ARRAY_COMPRESS_WEIGHTS<class_Mesh_constant_ARRAY_COMPRESS_WEIGHTS>`, and :ref:`ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION<class_Mesh_constant_ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION>` quickly.
  126. \ **Note:** Since this flag enables :ref:`ARRAY_COMPRESS_COLOR<class_Mesh_constant_ARRAY_COMPRESS_COLOR>`, vertex colors will be stored as 8-bit unsigned integers. This will clamp overbright colors to ``Color(1, 1, 1, 1)`` and reduce colors' precision.
  127. ----
  128. .. _enum_Mesh_ArrayType:
  129. .. _class_Mesh_constant_ARRAY_VERTEX:
  130. .. _class_Mesh_constant_ARRAY_NORMAL:
  131. .. _class_Mesh_constant_ARRAY_TANGENT:
  132. .. _class_Mesh_constant_ARRAY_COLOR:
  133. .. _class_Mesh_constant_ARRAY_TEX_UV:
  134. .. _class_Mesh_constant_ARRAY_TEX_UV2:
  135. .. _class_Mesh_constant_ARRAY_BONES:
  136. .. _class_Mesh_constant_ARRAY_WEIGHTS:
  137. .. _class_Mesh_constant_ARRAY_INDEX:
  138. .. _class_Mesh_constant_ARRAY_MAX:
  139. enum **ArrayType**:
  140. - **ARRAY_VERTEX** = **0** --- Array of vertices.
  141. - **ARRAY_NORMAL** = **1** --- Array of normals.
  142. - **ARRAY_TANGENT** = **2** --- Array of tangents as an array of floats, 4 floats per tangent.
  143. - **ARRAY_COLOR** = **3** --- Array of colors.
  144. - **ARRAY_TEX_UV** = **4** --- Array of UV coordinates.
  145. - **ARRAY_TEX_UV2** = **5** --- Array of second set of UV coordinates.
  146. - **ARRAY_BONES** = **6** --- Array of bone data.
  147. - **ARRAY_WEIGHTS** = **7** --- Array of weights.
  148. - **ARRAY_INDEX** = **8** --- Array of indices.
  149. - **ARRAY_MAX** = **9** --- Represents the size of the :ref:`ArrayType<enum_Mesh_ArrayType>` enum.
  150. Property Descriptions
  151. ---------------------
  152. .. _class_Mesh_property_lightmap_size_hint:
  153. - :ref:`Vector2<class_Vector2>` **lightmap_size_hint**
  154. +-----------+-------------------------------+
  155. | *Default* | ``Vector2( 0, 0 )`` |
  156. +-----------+-------------------------------+
  157. | *Setter* | set_lightmap_size_hint(value) |
  158. +-----------+-------------------------------+
  159. | *Getter* | get_lightmap_size_hint() |
  160. +-----------+-------------------------------+
  161. Sets a hint to be used for lightmap resolution in :ref:`BakedLightmap<class_BakedLightmap>`. Overrides :ref:`BakedLightmap.default_texels_per_unit<class_BakedLightmap_property_default_texels_per_unit>`.
  162. Method Descriptions
  163. -------------------
  164. .. _class_Mesh_method_create_convex_shape:
  165. - :ref:`Shape<class_Shape>` **create_convex_shape** **(** :ref:`bool<class_bool>` clean=true, :ref:`bool<class_bool>` simplify=false **)** |const|
  166. Calculate a :ref:`ConvexPolygonShape<class_ConvexPolygonShape>` from the mesh.
  167. 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.
  168. If ``simplify`` is ``true``, the geometry can be further simplified to reduce the amount of vertices. Disabled by default.
  169. ----
  170. .. _class_Mesh_method_create_outline:
  171. - :ref:`Mesh<class_Mesh>` **create_outline** **(** :ref:`float<class_float>` margin **)** |const|
  172. Calculate an outline mesh at a defined offset (margin) from the original mesh.
  173. \ **Note:** This method typically returns the vertices in reverse order (e.g. clockwise to counterclockwise).
  174. ----
  175. .. _class_Mesh_method_create_trimesh_shape:
  176. - :ref:`Shape<class_Shape>` **create_trimesh_shape** **(** **)** |const|
  177. Calculate a :ref:`ConcavePolygonShape<class_ConcavePolygonShape>` from the mesh.
  178. ----
  179. .. _class_Mesh_method_generate_triangle_mesh:
  180. - :ref:`TriangleMesh<class_TriangleMesh>` **generate_triangle_mesh** **(** **)** |const|
  181. Generate a :ref:`TriangleMesh<class_TriangleMesh>` from the mesh.
  182. ----
  183. .. _class_Mesh_method_get_aabb:
  184. - :ref:`AABB<class_AABB>` **get_aabb** **(** **)** |const|
  185. Returns the smallest :ref:`AABB<class_AABB>` enclosing this mesh in local space. Not affected by ``custom_aabb``. See also :ref:`VisualInstance.get_transformed_aabb<class_VisualInstance_method_get_transformed_aabb>`.
  186. \ **Note:** This is only implemented for :ref:`ArrayMesh<class_ArrayMesh>` and :ref:`PrimitiveMesh<class_PrimitiveMesh>`.
  187. ----
  188. .. _class_Mesh_method_get_faces:
  189. - :ref:`PoolVector3Array<class_PoolVector3Array>` **get_faces** **(** **)** |const|
  190. Returns all the vertices that make up the faces of the mesh. Each three vertices represent one triangle.
  191. ----
  192. .. _class_Mesh_method_get_surface_count:
  193. - :ref:`int<class_int>` **get_surface_count** **(** **)** |const|
  194. Returns the amount of surfaces that the ``Mesh`` holds.
  195. ----
  196. .. _class_Mesh_method_surface_get_arrays:
  197. - :ref:`Array<class_Array>` **surface_get_arrays** **(** :ref:`int<class_int>` surf_idx **)** |const|
  198. Returns the arrays for the vertices, normals, uvs, etc. that make up the requested surface (see :ref:`ArrayMesh.add_surface_from_arrays<class_ArrayMesh_method_add_surface_from_arrays>`).
  199. ----
  200. .. _class_Mesh_method_surface_get_blend_shape_arrays:
  201. - :ref:`Array<class_Array>` **surface_get_blend_shape_arrays** **(** :ref:`int<class_int>` surf_idx **)** |const|
  202. Returns the blend shape arrays for the requested surface.
  203. ----
  204. .. _class_Mesh_method_surface_get_material:
  205. - :ref:`Material<class_Material>` **surface_get_material** **(** :ref:`int<class_int>` surf_idx **)** |const|
  206. Returns a :ref:`Material<class_Material>` in a given surface. Surface is rendered using this material.
  207. ----
  208. .. _class_Mesh_method_surface_set_material:
  209. - void **surface_set_material** **(** :ref:`int<class_int>` surf_idx, :ref:`Material<class_Material>` material **)**
  210. Sets a :ref:`Material<class_Material>` for a given surface. Surface will be rendered using this material.
  211. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  212. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  213. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`