class_mesh.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Mesh.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Mesh:
  6. Mesh
  7. ====
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`ArrayMesh<class_ArrayMesh>`, :ref:`PrimitiveMesh<class_PrimitiveMesh>`
  10. A :ref:`Resource<class_Resource>` that contains vertex array-based geometry.
  11. Description
  12. -----------
  13. 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.
  14. Properties
  15. ----------
  16. +-------------------------------+-------------------------------------------------------------------+---------------------+
  17. | :ref:`Vector2<class_Vector2>` | :ref:`lightmap_size_hint<class_Mesh_property_lightmap_size_hint>` | ``Vector2( 0, 0 )`` |
  18. +-------------------------------+-------------------------------------------------------------------+---------------------+
  19. Methods
  20. -------
  21. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`Shape<class_Shape>` | :ref:`create_convex_shape<class_Mesh_method_create_convex_shape>` **(** **)** const |
  23. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Mesh<class_Mesh>` | :ref:`create_outline<class_Mesh_method_create_outline>` **(** :ref:`float<class_float>` margin **)** const |
  25. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Shape<class_Shape>` | :ref:`create_trimesh_shape<class_Mesh_method_create_trimesh_shape>` **(** **)** const |
  27. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`TriangleMesh<class_TriangleMesh>` | :ref:`generate_triangle_mesh<class_Mesh_method_generate_triangle_mesh>` **(** **)** const |
  29. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`AABB<class_AABB>` | :ref:`get_aabb<class_Mesh_method_get_aabb>` **(** **)** const |
  31. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`PackedVector3Array<class_PackedVector3Array>` | :ref:`get_faces<class_Mesh_method_get_faces>` **(** **)** const |
  33. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`get_surface_count<class_Mesh_method_get_surface_count>` **(** **)** const |
  35. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Array<class_Array>` | :ref:`surface_get_arrays<class_Mesh_method_surface_get_arrays>` **(** :ref:`int<class_int>` surf_idx **)** const |
  37. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :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 |
  39. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Material<class_Material>` | :ref:`surface_get_material<class_Mesh_method_surface_get_material>` **(** :ref:`int<class_int>` surf_idx **)** const |
  41. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`surface_set_material<class_Mesh_method_surface_set_material>` **(** :ref:`int<class_int>` surf_idx, :ref:`Material<class_Material>` material **)** |
  43. +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. Enumerations
  45. ------------
  46. .. _enum_Mesh_PrimitiveType:
  47. .. _class_Mesh_constant_PRIMITIVE_POINTS:
  48. .. _class_Mesh_constant_PRIMITIVE_LINES:
  49. .. _class_Mesh_constant_PRIMITIVE_LINE_STRIP:
  50. .. _class_Mesh_constant_PRIMITIVE_TRIANGLES:
  51. .. _class_Mesh_constant_PRIMITIVE_TRIANGLE_STRIP:
  52. enum **PrimitiveType**:
  53. - **PRIMITIVE_POINTS** = **0** --- Render array as points (one vertex equals one point).
  54. - **PRIMITIVE_LINES** = **1** --- Render array as lines (every two vertices a line is created).
  55. - **PRIMITIVE_LINE_STRIP** = **2** --- Render array as line strip.
  56. - **PRIMITIVE_TRIANGLES** = **3** --- Render array as triangles (every three vertices a triangle is created).
  57. - **PRIMITIVE_TRIANGLE_STRIP** = **4** --- Render array as triangle strips.
  58. ----
  59. .. _enum_Mesh_BlendShapeMode:
  60. .. _class_Mesh_constant_BLEND_SHAPE_MODE_NORMALIZED:
  61. .. _class_Mesh_constant_BLEND_SHAPE_MODE_RELATIVE:
  62. enum **BlendShapeMode**:
  63. - **BLEND_SHAPE_MODE_NORMALIZED** = **0** --- Blend shapes are normalized.
  64. - **BLEND_SHAPE_MODE_RELATIVE** = **1** --- Blend shapes are relative to base weight.
  65. ----
  66. .. _enum_Mesh_ArrayFormat:
  67. .. _class_Mesh_constant_ARRAY_FORMAT_VERTEX:
  68. .. _class_Mesh_constant_ARRAY_FORMAT_NORMAL:
  69. .. _class_Mesh_constant_ARRAY_FORMAT_TANGENT:
  70. .. _class_Mesh_constant_ARRAY_FORMAT_COLOR:
  71. .. _class_Mesh_constant_ARRAY_FORMAT_TEX_UV:
  72. .. _class_Mesh_constant_ARRAY_FORMAT_TEX_UV2:
  73. .. _class_Mesh_constant_ARRAY_FORMAT_BONES:
  74. .. _class_Mesh_constant_ARRAY_FORMAT_WEIGHTS:
  75. .. _class_Mesh_constant_ARRAY_FORMAT_INDEX:
  76. .. _class_Mesh_constant_ARRAY_COMPRESS_NORMAL:
  77. .. _class_Mesh_constant_ARRAY_COMPRESS_TANGENT:
  78. .. _class_Mesh_constant_ARRAY_COMPRESS_COLOR:
  79. .. _class_Mesh_constant_ARRAY_COMPRESS_TEX_UV:
  80. .. _class_Mesh_constant_ARRAY_COMPRESS_TEX_UV2:
  81. .. _class_Mesh_constant_ARRAY_COMPRESS_INDEX:
  82. .. _class_Mesh_constant_ARRAY_FLAG_USE_2D_VERTICES:
  83. .. _class_Mesh_constant_ARRAY_COMPRESS_DEFAULT:
  84. enum **ArrayFormat**:
  85. - **ARRAY_FORMAT_VERTEX** = **1** --- Mesh array contains vertices. All meshes require a vertex array so this should always be present.
  86. - **ARRAY_FORMAT_NORMAL** = **2** --- Mesh array contains normals.
  87. - **ARRAY_FORMAT_TANGENT** = **4** --- Mesh array contains tangents.
  88. - **ARRAY_FORMAT_COLOR** = **8** --- Mesh array contains colors.
  89. - **ARRAY_FORMAT_TEX_UV** = **16** --- Mesh array contains UVs.
  90. - **ARRAY_FORMAT_TEX_UV2** = **32** --- Mesh array contains second UV.
  91. - **ARRAY_FORMAT_BONES** = **64** --- Mesh array contains bones.
  92. - **ARRAY_FORMAT_WEIGHTS** = **128** --- Mesh array contains bone weights.
  93. - **ARRAY_FORMAT_INDEX** = **256** --- Mesh array uses indices.
  94. - **ARRAY_COMPRESS_NORMAL** = **1024** --- Flag used to mark a compressed (half float) normal array.
  95. - **ARRAY_COMPRESS_TANGENT** = **2048** --- Flag used to mark a compressed (half float) tangent array.
  96. - **ARRAY_COMPRESS_COLOR** = **4096** --- Flag used to mark a compressed (half float) color array.
  97. - **ARRAY_COMPRESS_TEX_UV** = **8192** --- Flag used to mark a compressed (half float) UV coordinates array.
  98. - **ARRAY_COMPRESS_TEX_UV2** = **16384** --- Flag used to mark a compressed (half float) UV coordinates array for the second UV coordinates.
  99. - **ARRAY_COMPRESS_INDEX** = **131072** --- Flag used to mark a compressed index array.
  100. - **ARRAY_FLAG_USE_2D_VERTICES** = **262144** --- Flag used to mark that the array contains 2D vertices.
  101. - **ARRAY_COMPRESS_DEFAULT** = **31744** --- Used to set flags :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>` and :ref:`ARRAY_COMPRESS_TEX_UV2<class_Mesh_constant_ARRAY_COMPRESS_TEX_UV2>` quickly.
  102. ----
  103. .. _enum_Mesh_ArrayType:
  104. .. _class_Mesh_constant_ARRAY_VERTEX:
  105. .. _class_Mesh_constant_ARRAY_NORMAL:
  106. .. _class_Mesh_constant_ARRAY_TANGENT:
  107. .. _class_Mesh_constant_ARRAY_COLOR:
  108. .. _class_Mesh_constant_ARRAY_TEX_UV:
  109. .. _class_Mesh_constant_ARRAY_TEX_UV2:
  110. .. _class_Mesh_constant_ARRAY_BONES:
  111. .. _class_Mesh_constant_ARRAY_WEIGHTS:
  112. .. _class_Mesh_constant_ARRAY_INDEX:
  113. .. _class_Mesh_constant_ARRAY_MAX:
  114. enum **ArrayType**:
  115. - **ARRAY_VERTEX** = **0** --- Array of vertices.
  116. - **ARRAY_NORMAL** = **1** --- Array of normals.
  117. - **ARRAY_TANGENT** = **2** --- Array of tangents as an array of floats, 4 floats per tangent.
  118. - **ARRAY_COLOR** = **3** --- Array of colors.
  119. - **ARRAY_TEX_UV** = **4** --- Array of UV coordinates.
  120. - **ARRAY_TEX_UV2** = **5** --- Array of second set of UV coordinates.
  121. - **ARRAY_BONES** = **6** --- Array of bone data.
  122. - **ARRAY_WEIGHTS** = **7** --- Array of weights.
  123. - **ARRAY_INDEX** = **8** --- Array of indices.
  124. - **ARRAY_MAX** = **9** --- Represents the size of the :ref:`ArrayType<enum_Mesh_ArrayType>` enum.
  125. Property Descriptions
  126. ---------------------
  127. .. _class_Mesh_property_lightmap_size_hint:
  128. - :ref:`Vector2<class_Vector2>` **lightmap_size_hint**
  129. +-----------+-------------------------------+
  130. | *Default* | ``Vector2( 0, 0 )`` |
  131. +-----------+-------------------------------+
  132. | *Setter* | set_lightmap_size_hint(value) |
  133. +-----------+-------------------------------+
  134. | *Getter* | get_lightmap_size_hint() |
  135. +-----------+-------------------------------+
  136. Sets a hint to be used for lightmap resolution.
  137. Method Descriptions
  138. -------------------
  139. .. _class_Mesh_method_create_convex_shape:
  140. - :ref:`Shape<class_Shape>` **create_convex_shape** **(** **)** const
  141. Calculate a :ref:`ConvexPolygonShape<class_ConvexPolygonShape>` from the mesh.
  142. ----
  143. .. _class_Mesh_method_create_outline:
  144. - :ref:`Mesh<class_Mesh>` **create_outline** **(** :ref:`float<class_float>` margin **)** const
  145. Calculate an outline mesh at a defined offset (margin) from the original mesh.
  146. **Note:** This method typically returns the vertices in reverse order (e.g. clockwise to counterclockwise).
  147. ----
  148. .. _class_Mesh_method_create_trimesh_shape:
  149. - :ref:`Shape<class_Shape>` **create_trimesh_shape** **(** **)** const
  150. Calculate a :ref:`ConcavePolygonShape<class_ConcavePolygonShape>` from the mesh.
  151. ----
  152. .. _class_Mesh_method_generate_triangle_mesh:
  153. - :ref:`TriangleMesh<class_TriangleMesh>` **generate_triangle_mesh** **(** **)** const
  154. Generate a :ref:`TriangleMesh<class_TriangleMesh>` from the mesh.
  155. ----
  156. .. _class_Mesh_method_get_aabb:
  157. - :ref:`AABB<class_AABB>` **get_aabb** **(** **)** const
  158. Returns the smallest :ref:`AABB<class_AABB>` enclosing this mesh. Not affected by ``custom_aabb``.
  159. **Note:** This is only implemented for :ref:`ArrayMesh<class_ArrayMesh>` and :ref:`PrimitiveMesh<class_PrimitiveMesh>`.
  160. ----
  161. .. _class_Mesh_method_get_faces:
  162. - :ref:`PackedVector3Array<class_PackedVector3Array>` **get_faces** **(** **)** const
  163. Returns all the vertices that make up the faces of the mesh. Each three vertices represent one triangle.
  164. ----
  165. .. _class_Mesh_method_get_surface_count:
  166. - :ref:`int<class_int>` **get_surface_count** **(** **)** const
  167. Returns the amount of surfaces that the ``Mesh`` holds.
  168. ----
  169. .. _class_Mesh_method_surface_get_arrays:
  170. - :ref:`Array<class_Array>` **surface_get_arrays** **(** :ref:`int<class_int>` surf_idx **)** const
  171. 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>`).
  172. ----
  173. .. _class_Mesh_method_surface_get_blend_shape_arrays:
  174. - :ref:`Array<class_Array>` **surface_get_blend_shape_arrays** **(** :ref:`int<class_int>` surf_idx **)** const
  175. Returns the blend shape arrays for the requested surface.
  176. ----
  177. .. _class_Mesh_method_surface_get_material:
  178. - :ref:`Material<class_Material>` **surface_get_material** **(** :ref:`int<class_int>` surf_idx **)** const
  179. Returns a :ref:`Material<class_Material>` in a given surface. Surface is rendered using this material.
  180. ----
  181. .. _class_Mesh_method_surface_set_material:
  182. - void **surface_set_material** **(** :ref:`int<class_int>` surf_idx, :ref:`Material<class_Material>` material **)**
  183. Sets a :ref:`Material<class_Material>` for a given surface. Surface will be rendered using this material.