MeshDataTool.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="MeshDataTool" inherits="Reference" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. Helper tool to access and edit [Mesh] data.
  5. </brief_description>
  6. <description>
  7. MeshDataTool provides access to individual vertices in a [Mesh]. It allows users to read and edit vertex data of meshes. It also creates an array of faces and edges.
  8. To use MeshDataTool, load a mesh with [method create_from_surface]. When you are finished editing the data commit the data to a mesh with [method commit_to_surface].
  9. Below is an example of how MeshDataTool may be used.
  10. [codeblock]
  11. var mesh = ArrayMesh.new()
  12. mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, CubeMesh.new().get_mesh_arrays())
  13. var mdt = MeshDataTool.new()
  14. mdt.create_from_surface(mesh, 0)
  15. for i in range(mdt.get_vertex_count()):
  16. var vertex = mdt.get_vertex(i)
  17. # In this example we extend the mesh by one unit, which results in separated faces as it is flat shaded.
  18. vertex += mdt.get_vertex_normal(i)
  19. # Save your change.
  20. mdt.set_vertex(i, vertex)
  21. mesh.surface_remove(0)
  22. mdt.commit_to_surface(mesh)
  23. var mi = MeshInstance.new()
  24. mi.mesh = mesh
  25. add_child(mi)
  26. [/codeblock]
  27. See also [ArrayMesh], [ImmediateGeometry] and [SurfaceTool] for procedural geometry generation.
  28. [b]Note:[/b] Godot uses clockwise [url=https://learnopengl.com/Advanced-OpenGL/Face-culling]winding order[/url] for front faces of triangle primitive modes.
  29. </description>
  30. <tutorials>
  31. </tutorials>
  32. <methods>
  33. <method name="clear">
  34. <return type="void" />
  35. <description>
  36. Clears all data currently in MeshDataTool.
  37. </description>
  38. </method>
  39. <method name="commit_to_surface">
  40. <return type="int" enum="Error" />
  41. <argument index="0" name="mesh" type="ArrayMesh" />
  42. <description>
  43. Adds a new surface to specified [Mesh] with edited data.
  44. </description>
  45. </method>
  46. <method name="create_from_surface">
  47. <return type="int" enum="Error" />
  48. <argument index="0" name="mesh" type="ArrayMesh" />
  49. <argument index="1" name="surface" type="int" />
  50. <description>
  51. Uses specified surface of given [Mesh] to populate data for MeshDataTool.
  52. Requires [Mesh] with primitive type [constant Mesh.PRIMITIVE_TRIANGLES].
  53. </description>
  54. </method>
  55. <method name="get_edge_count" qualifiers="const">
  56. <return type="int" />
  57. <description>
  58. Returns the number of edges in this [Mesh].
  59. </description>
  60. </method>
  61. <method name="get_edge_faces" qualifiers="const">
  62. <return type="PoolIntArray" />
  63. <argument index="0" name="idx" type="int" />
  64. <description>
  65. Returns array of faces that touch given edge.
  66. </description>
  67. </method>
  68. <method name="get_edge_meta" qualifiers="const">
  69. <return type="Variant" />
  70. <argument index="0" name="idx" type="int" />
  71. <description>
  72. Returns meta information assigned to given edge.
  73. </description>
  74. </method>
  75. <method name="get_edge_vertex" qualifiers="const">
  76. <return type="int" />
  77. <argument index="0" name="idx" type="int" />
  78. <argument index="1" name="vertex" type="int" />
  79. <description>
  80. Returns index of specified vertex connected to given edge.
  81. Vertex argument can only be 0 or 1 because edges are comprised of two vertices.
  82. </description>
  83. </method>
  84. <method name="get_face_count" qualifiers="const">
  85. <return type="int" />
  86. <description>
  87. Returns the number of faces in this [Mesh].
  88. </description>
  89. </method>
  90. <method name="get_face_edge" qualifiers="const">
  91. <return type="int" />
  92. <argument index="0" name="idx" type="int" />
  93. <argument index="1" name="edge" type="int" />
  94. <description>
  95. Returns specified edge associated with given face.
  96. Edge argument must be either 0, 1, or 2 because a face only has three edges.
  97. </description>
  98. </method>
  99. <method name="get_face_meta" qualifiers="const">
  100. <return type="Variant" />
  101. <argument index="0" name="idx" type="int" />
  102. <description>
  103. Returns the metadata associated with the given face.
  104. </description>
  105. </method>
  106. <method name="get_face_normal" qualifiers="const">
  107. <return type="Vector3" />
  108. <argument index="0" name="idx" type="int" />
  109. <description>
  110. Calculates and returns the face normal of the given face.
  111. </description>
  112. </method>
  113. <method name="get_face_vertex" qualifiers="const">
  114. <return type="int" />
  115. <argument index="0" name="idx" type="int" />
  116. <argument index="1" name="vertex" type="int" />
  117. <description>
  118. Returns the specified vertex of the given face.
  119. Vertex argument must be either 0, 1, or 2 because faces contain three vertices.
  120. </description>
  121. </method>
  122. <method name="get_format" qualifiers="const">
  123. <return type="int" />
  124. <description>
  125. Returns the [Mesh]'s format. Format is an integer made up of [Mesh] format flags combined together. For example, a mesh containing both vertices and normals would return a format of [code]3[/code] because [constant ArrayMesh.ARRAY_FORMAT_VERTEX] is [code]1[/code] and [constant ArrayMesh.ARRAY_FORMAT_NORMAL] is [code]2[/code].
  126. See [enum ArrayMesh.ArrayFormat] for a list of format flags.
  127. </description>
  128. </method>
  129. <method name="get_material" qualifiers="const">
  130. <return type="Material" />
  131. <description>
  132. Returns the material assigned to the [Mesh].
  133. </description>
  134. </method>
  135. <method name="get_vertex" qualifiers="const">
  136. <return type="Vector3" />
  137. <argument index="0" name="idx" type="int" />
  138. <description>
  139. Returns the vertex at given index.
  140. </description>
  141. </method>
  142. <method name="get_vertex_bones" qualifiers="const">
  143. <return type="PoolIntArray" />
  144. <argument index="0" name="idx" type="int" />
  145. <description>
  146. Returns the bones of the given vertex.
  147. </description>
  148. </method>
  149. <method name="get_vertex_color" qualifiers="const">
  150. <return type="Color" />
  151. <argument index="0" name="idx" type="int" />
  152. <description>
  153. Returns the color of the given vertex.
  154. </description>
  155. </method>
  156. <method name="get_vertex_count" qualifiers="const">
  157. <return type="int" />
  158. <description>
  159. Returns the total number of vertices in [Mesh].
  160. </description>
  161. </method>
  162. <method name="get_vertex_edges" qualifiers="const">
  163. <return type="PoolIntArray" />
  164. <argument index="0" name="idx" type="int" />
  165. <description>
  166. Returns an array of edges that share the given vertex.
  167. </description>
  168. </method>
  169. <method name="get_vertex_faces" qualifiers="const">
  170. <return type="PoolIntArray" />
  171. <argument index="0" name="idx" type="int" />
  172. <description>
  173. Returns an array of faces that share the given vertex.
  174. </description>
  175. </method>
  176. <method name="get_vertex_meta" qualifiers="const">
  177. <return type="Variant" />
  178. <argument index="0" name="idx" type="int" />
  179. <description>
  180. Returns the metadata associated with the given vertex.
  181. </description>
  182. </method>
  183. <method name="get_vertex_normal" qualifiers="const">
  184. <return type="Vector3" />
  185. <argument index="0" name="idx" type="int" />
  186. <description>
  187. Returns the normal of the given vertex.
  188. </description>
  189. </method>
  190. <method name="get_vertex_tangent" qualifiers="const">
  191. <return type="Plane" />
  192. <argument index="0" name="idx" type="int" />
  193. <description>
  194. Returns the tangent of the given vertex.
  195. </description>
  196. </method>
  197. <method name="get_vertex_uv" qualifiers="const">
  198. <return type="Vector2" />
  199. <argument index="0" name="idx" type="int" />
  200. <description>
  201. Returns the UV of the given vertex.
  202. </description>
  203. </method>
  204. <method name="get_vertex_uv2" qualifiers="const">
  205. <return type="Vector2" />
  206. <argument index="0" name="idx" type="int" />
  207. <description>
  208. Returns the UV2 of the given vertex.
  209. </description>
  210. </method>
  211. <method name="get_vertex_weights" qualifiers="const">
  212. <return type="PoolRealArray" />
  213. <argument index="0" name="idx" type="int" />
  214. <description>
  215. Returns bone weights of the given vertex.
  216. </description>
  217. </method>
  218. <method name="set_edge_meta">
  219. <return type="void" />
  220. <argument index="0" name="idx" type="int" />
  221. <argument index="1" name="meta" type="Variant" />
  222. <description>
  223. Sets the metadata of the given edge.
  224. </description>
  225. </method>
  226. <method name="set_face_meta">
  227. <return type="void" />
  228. <argument index="0" name="idx" type="int" />
  229. <argument index="1" name="meta" type="Variant" />
  230. <description>
  231. Sets the metadata of the given face.
  232. </description>
  233. </method>
  234. <method name="set_material">
  235. <return type="void" />
  236. <argument index="0" name="material" type="Material" />
  237. <description>
  238. Sets the material to be used by newly-constructed [Mesh].
  239. </description>
  240. </method>
  241. <method name="set_vertex">
  242. <return type="void" />
  243. <argument index="0" name="idx" type="int" />
  244. <argument index="1" name="vertex" type="Vector3" />
  245. <description>
  246. Sets the position of the given vertex.
  247. </description>
  248. </method>
  249. <method name="set_vertex_bones">
  250. <return type="void" />
  251. <argument index="0" name="idx" type="int" />
  252. <argument index="1" name="bones" type="PoolIntArray" />
  253. <description>
  254. Sets the bones of the given vertex.
  255. </description>
  256. </method>
  257. <method name="set_vertex_color">
  258. <return type="void" />
  259. <argument index="0" name="idx" type="int" />
  260. <argument index="1" name="color" type="Color" />
  261. <description>
  262. Sets the color of the given vertex.
  263. </description>
  264. </method>
  265. <method name="set_vertex_meta">
  266. <return type="void" />
  267. <argument index="0" name="idx" type="int" />
  268. <argument index="1" name="meta" type="Variant" />
  269. <description>
  270. Sets the metadata associated with the given vertex.
  271. </description>
  272. </method>
  273. <method name="set_vertex_normal">
  274. <return type="void" />
  275. <argument index="0" name="idx" type="int" />
  276. <argument index="1" name="normal" type="Vector3" />
  277. <description>
  278. Sets the normal of the given vertex.
  279. </description>
  280. </method>
  281. <method name="set_vertex_tangent">
  282. <return type="void" />
  283. <argument index="0" name="idx" type="int" />
  284. <argument index="1" name="tangent" type="Plane" />
  285. <description>
  286. Sets the tangent of the given vertex.
  287. </description>
  288. </method>
  289. <method name="set_vertex_uv">
  290. <return type="void" />
  291. <argument index="0" name="idx" type="int" />
  292. <argument index="1" name="uv" type="Vector2" />
  293. <description>
  294. Sets the UV of the given vertex.
  295. </description>
  296. </method>
  297. <method name="set_vertex_uv2">
  298. <return type="void" />
  299. <argument index="0" name="idx" type="int" />
  300. <argument index="1" name="uv2" type="Vector2" />
  301. <description>
  302. Sets the UV2 of the given vertex.
  303. </description>
  304. </method>
  305. <method name="set_vertex_weights">
  306. <return type="void" />
  307. <argument index="0" name="idx" type="int" />
  308. <argument index="1" name="weights" type="PoolRealArray" />
  309. <description>
  310. Sets the bone weights of the given vertex.
  311. </description>
  312. </method>
  313. </methods>
  314. <constants>
  315. </constants>
  316. </class>