class_mesh.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Mesh:
  4. Mesh
  5. ====
  6. **Inherits:** :ref:`Resource<class_resource>` **<** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. A :ref:`Resource<class_resource>` that contains vertex-array based geometry.
  11. Member Functions
  12. ----------------
  13. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | void | :ref:`add_morph_target<class_Mesh_add_morph_target>` **(** :ref:`String<class_string>` name **)** |
  15. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`add_surface<class_Mesh_add_surface>` **(** :ref:`int<class_int>` primitive, :ref:`Array<class_array>` arrays, :ref:`Array<class_array>` morph_arrays=Array(), :ref:`bool<class_bool>` alphasort=false **)** |
  17. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | void | :ref:`center_geometry<class_Mesh_center_geometry>` **(** **)** |
  19. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | void | :ref:`clear_morph_targets<class_Mesh_clear_morph_targets>` **(** **)** |
  21. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`Shape<class_shape>` | :ref:`create_convex_shape<class_Mesh_create_convex_shape>` **(** **)** const |
  23. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Mesh<class_mesh>` | :ref:`create_outline<class_Mesh_create_outline>` **(** :ref:`float<class_float>` margin **)** const |
  25. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Shape<class_shape>` | :ref:`create_trimesh_shape<class_Mesh_create_trimesh_shape>` **(** **)** const |
  27. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | TriangleMesh | :ref:`generate_triangle_mesh<class_Mesh_generate_triangle_mesh>` **(** **)** const |
  29. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`AABB<class_aabb>` | :ref:`get_custom_aabb<class_Mesh_get_custom_aabb>` **(** **)** const |
  31. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Vector3Array<class_vector3array>` | :ref:`get_faces<class_Mesh_get_faces>` **(** **)** const |
  33. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`get_morph_target_count<class_Mesh_get_morph_target_count>` **(** **)** const |
  35. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`get_morph_target_mode<class_Mesh_get_morph_target_mode>` **(** **)** const |
  37. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`String<class_string>` | :ref:`get_morph_target_name<class_Mesh_get_morph_target_name>` **(** :ref:`int<class_int>` index **)** const |
  39. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_surface_count<class_Mesh_get_surface_count>` **(** **)** const |
  41. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`regen_normalmaps<class_Mesh_regen_normalmaps>` **(** **)** |
  43. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`set_custom_aabb<class_Mesh_set_custom_aabb>` **(** :ref:`AABB<class_aabb>` aabb **)** |
  45. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`set_morph_target_mode<class_Mesh_set_morph_target_mode>` **(** :ref:`int<class_int>` mode **)** |
  47. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`surface_get_array_index_len<class_Mesh_surface_get_array_index_len>` **(** :ref:`int<class_int>` surf_idx **)** const |
  49. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`surface_get_array_len<class_Mesh_surface_get_array_len>` **(** :ref:`int<class_int>` surf_idx **)** const |
  51. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`surface_get_format<class_Mesh_surface_get_format>` **(** :ref:`int<class_int>` surf_idx **)** const |
  53. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Material<class_material>` | :ref:`surface_get_material<class_Mesh_surface_get_material>` **(** :ref:`int<class_int>` surf_idx **)** const |
  55. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`String<class_string>` | :ref:`surface_get_name<class_Mesh_surface_get_name>` **(** :ref:`int<class_int>` surf_idx **)** const |
  57. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`int<class_int>` | :ref:`surface_get_primitive_type<class_Mesh_surface_get_primitive_type>` **(** :ref:`int<class_int>` surf_idx **)** const |
  59. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`surface_remove<class_Mesh_surface_remove>` **(** :ref:`int<class_int>` surf_idx **)** |
  61. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`surface_set_material<class_Mesh_surface_set_material>` **(** :ref:`int<class_int>` surf_idx, :ref:`Material<class_material>` material **)** |
  63. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`surface_set_name<class_Mesh_surface_set_name>` **(** :ref:`int<class_int>` surf_idx, :ref:`String<class_string>` name **)** |
  65. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. Numeric Constants
  67. -----------------
  68. - **NO_INDEX_ARRAY** = **-1** --- Default value used for index_array_len when no indices are present.
  69. - **ARRAY_WEIGHTS_SIZE** = **4** --- Amount of weights/bone indices per vertex (always 4).
  70. - **ARRAY_VERTEX** = **0** --- Vertex array (array of :ref:`Vector3<class_vector3>` vertices).
  71. - **ARRAY_NORMAL** = **1** --- Normal array (array of :ref:`Vector3<class_vector3>` normals).
  72. - **ARRAY_TANGENT** = **2** --- Tangent array, array of groups of 4 floats. first 3 floats determine the tangent, and the last the binormal direction as -1 or 1.
  73. - **ARRAY_COLOR** = **3** --- Vertex array (array of :ref:`Color<class_color>` colors).
  74. - **ARRAY_TEX_UV** = **4** --- UV array (array of :ref:`Vector3<class_vector3>` UVs or float array of groups of 2 floats (u,v)).
  75. - **ARRAY_TEX_UV2** = **5** --- Second UV array (array of :ref:`Vector3<class_vector3>` UVs or float array of groups of 2 floats (u,v)).
  76. - **ARRAY_BONES** = **6** --- Array of bone indices, as a float array. Each element in groups of 4 floats.
  77. - **ARRAY_WEIGHTS** = **7** --- Array of bone weights, as a float array. Each element in groups of 4 floats.
  78. - **ARRAY_INDEX** = **8** --- Array of integers, used as indices referencing vertices. No index can be beyond the vertex array size.
  79. - **ARRAY_FORMAT_VERTEX** = **1** --- Array format will include vertices (mandatory).
  80. - **ARRAY_FORMAT_NORMAL** = **2** --- Array format will include normals
  81. - **ARRAY_FORMAT_TANGENT** = **4** --- Array format will include tangents
  82. - **ARRAY_FORMAT_COLOR** = **8** --- Array format will include a color array.
  83. - **ARRAY_FORMAT_TEX_UV** = **16** --- Array format will include UVs.
  84. - **ARRAY_FORMAT_TEX_UV2** = **32** --- Array format will include another set of UVs.
  85. - **ARRAY_FORMAT_BONES** = **64** --- Array format will include bone indices.
  86. - **ARRAY_FORMAT_WEIGHTS** = **128** --- Array format will include bone weights.
  87. - **ARRAY_FORMAT_INDEX** = **256** --- Index array will be used.
  88. - **PRIMITIVE_POINTS** = **0** --- Render array as points (one vertex equals one point).
  89. - **PRIMITIVE_LINES** = **1** --- Render array as lines (every two vertices a line is created).
  90. - **PRIMITIVE_LINE_STRIP** = **2** --- Render array as line strip.
  91. - **PRIMITIVE_LINE_LOOP** = **3** --- Render array as line loop (like line strip, but closed).
  92. - **PRIMITIVE_TRIANGLES** = **4** --- Render array as triangles (every three vertices a triangle is created).
  93. - **PRIMITIVE_TRIANGLE_STRIP** = **5** --- Render array as triangle strips.
  94. - **PRIMITIVE_TRIANGLE_FAN** = **6** --- Render array as triangle fans.
  95. Description
  96. -----------
  97. 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.
  98. Member Function Description
  99. ---------------------------
  100. .. _class_Mesh_add_morph_target:
  101. - void **add_morph_target** **(** :ref:`String<class_string>` name **)**
  102. .. _class_Mesh_add_surface:
  103. - void **add_surface** **(** :ref:`int<class_int>` primitive, :ref:`Array<class_array>` arrays, :ref:`Array<class_array>` morph_arrays=Array(), :ref:`bool<class_bool>` alphasort=false **)**
  104. Create a new surface (:ref:`get_surface_count<class_Mesh_get_surface_count>` that will become surf_idx for this.
  105. Surfaces are created to be rendered using a "primitive", which may be PRIMITIVE_POINTS, PRIMITIVE_LINES, PRIMITIVE_LINE_STRIP, PRIMITIVE_LINE_LOOP, PRIMITIVE_TRIANGLES, PRIMITIVE_TRIANGLE_STRIP, PRIMITIVE_TRIANGLE_FAN. (As a note, when using indices, it is recommended to only use just points, lines or triangles).
  106. The format of a surface determines which arrays it will allocate and hold, so "format" is a combination of ARRAY_FORMAT\_\* mask constants ORed together. ARRAY_FORMAT_VERTEX must be always present. "array_len" determines the amount of vertices in the array (not primitives!). if ARRAY_FORMAT_INDEX is in the format mask, then it means that an index array will be allocated and "index_array_len" must be passed.
  107. .. _class_Mesh_center_geometry:
  108. - void **center_geometry** **(** **)**
  109. .. _class_Mesh_clear_morph_targets:
  110. - void **clear_morph_targets** **(** **)**
  111. .. _class_Mesh_create_convex_shape:
  112. - :ref:`Shape<class_shape>` **create_convex_shape** **(** **)** const
  113. .. _class_Mesh_create_outline:
  114. - :ref:`Mesh<class_mesh>` **create_outline** **(** :ref:`float<class_float>` margin **)** const
  115. .. _class_Mesh_create_trimesh_shape:
  116. - :ref:`Shape<class_shape>` **create_trimesh_shape** **(** **)** const
  117. .. _class_Mesh_generate_triangle_mesh:
  118. - TriangleMesh **generate_triangle_mesh** **(** **)** const
  119. .. _class_Mesh_get_custom_aabb:
  120. - :ref:`AABB<class_aabb>` **get_custom_aabb** **(** **)** const
  121. .. _class_Mesh_get_faces:
  122. - :ref:`Vector3Array<class_vector3array>` **get_faces** **(** **)** const
  123. .. _class_Mesh_get_morph_target_count:
  124. - :ref:`int<class_int>` **get_morph_target_count** **(** **)** const
  125. .. _class_Mesh_get_morph_target_mode:
  126. - :ref:`int<class_int>` **get_morph_target_mode** **(** **)** const
  127. .. _class_Mesh_get_morph_target_name:
  128. - :ref:`String<class_string>` **get_morph_target_name** **(** :ref:`int<class_int>` index **)** const
  129. .. _class_Mesh_get_surface_count:
  130. - :ref:`int<class_int>` **get_surface_count** **(** **)** const
  131. Return the amount of surfaces that the :ref:`Mesh<class_mesh>` holds.
  132. .. _class_Mesh_regen_normalmaps:
  133. - void **regen_normalmaps** **(** **)**
  134. .. _class_Mesh_set_custom_aabb:
  135. - void **set_custom_aabb** **(** :ref:`AABB<class_aabb>` aabb **)**
  136. .. _class_Mesh_set_morph_target_mode:
  137. - void **set_morph_target_mode** **(** :ref:`int<class_int>` mode **)**
  138. .. _class_Mesh_surface_get_array_index_len:
  139. - :ref:`int<class_int>` **surface_get_array_index_len** **(** :ref:`int<class_int>` surf_idx **)** const
  140. Return the length in indices of the index array in the requested surface (see :ref:`add_surface<class_Mesh_add_surface>`).
  141. .. _class_Mesh_surface_get_array_len:
  142. - :ref:`int<class_int>` **surface_get_array_len** **(** :ref:`int<class_int>` surf_idx **)** const
  143. Return the length in vertices of the vertex array in the requested surface (see :ref:`add_surface<class_Mesh_add_surface>`).
  144. .. _class_Mesh_surface_get_format:
  145. - :ref:`int<class_int>` **surface_get_format** **(** :ref:`int<class_int>` surf_idx **)** const
  146. Return the format mask of the requested surface (see :ref:`add_surface<class_Mesh_add_surface>`).
  147. .. _class_Mesh_surface_get_material:
  148. - :ref:`Material<class_material>` **surface_get_material** **(** :ref:`int<class_int>` surf_idx **)** const
  149. Return a :ref:`Material<class_material>` in a given surface. Surface is rendered using this material.
  150. .. _class_Mesh_surface_get_name:
  151. - :ref:`String<class_string>` **surface_get_name** **(** :ref:`int<class_int>` surf_idx **)** const
  152. .. _class_Mesh_surface_get_primitive_type:
  153. - :ref:`int<class_int>` **surface_get_primitive_type** **(** :ref:`int<class_int>` surf_idx **)** const
  154. Return the primitive type of the requested surface (see :ref:`add_surface<class_Mesh_add_surface>`).
  155. .. _class_Mesh_surface_remove:
  156. - void **surface_remove** **(** :ref:`int<class_int>` surf_idx **)**
  157. Remove a surface at position surf_idx, shifting greater surfaces one surf_idx slot down.
  158. .. _class_Mesh_surface_set_material:
  159. - void **surface_set_material** **(** :ref:`int<class_int>` surf_idx, :ref:`Material<class_material>` material **)**
  160. Set a :ref:`Material<class_material>` for a given surface. Surface will be rendered using this material.
  161. .. _class_Mesh_surface_set_name:
  162. - void **surface_set_name** **(** :ref:`int<class_int>` surf_idx, :ref:`String<class_string>` name **)**