2
0

MeshDataTool.xml 11 KB

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