| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="MeshDataTool" inherits="RefCounted" 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 | [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.clear_surfaces() |
| 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 < 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.ClearSurfaces(); |
| 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 | <link title="Using the MeshDataTool">$DOCS_URL/tutorials/3d/procedural_geometry/meshdatatool.html</link> |
| 53 | </tutorials> |
| 54 | <methods> |
| 55 | <method name="clear"> |
| 56 | <return type="void" /> |
| 57 | <description> |
| 58 | Clears all data currently in MeshDataTool. |
| 59 | </description> |
| 60 | </method> |
| 61 | <method name="commit_to_surface"> |
| 62 | <return type="int" enum="Error" /> |
| 63 | <param index="0" name="mesh" type="ArrayMesh" /> |
| 64 | <param index="1" name="compression_flags" type="int" default="0" /> |
| 65 | <description> |
| 66 | Adds a new surface to specified [Mesh] with edited data. |
| 67 | </description> |
| 68 | </method> |
| 69 | <method name="create_from_surface"> |
| 70 | <return type="int" enum="Error" /> |
| 71 | <param index="0" name="mesh" type="ArrayMesh" /> |
| 72 | <param index="1" name="surface" type="int" /> |
| 73 | <description> |
| 74 | Uses specified surface of given [Mesh] to populate data for MeshDataTool. |
| 75 | Requires [Mesh] with primitive type [constant Mesh.PRIMITIVE_TRIANGLES]. |
| 76 | </description> |
| 77 | </method> |
| 78 | <method name="get_edge_count" qualifiers="const"> |
| 79 | <return type="int" /> |
| 80 | <description> |
| 81 | Returns the number of edges in this [Mesh]. |
| 82 | </description> |
| 83 | </method> |
| 84 | <method name="get_edge_faces" qualifiers="const"> |
| 85 | <return type="PackedInt32Array" /> |
| 86 | <param index="0" name="idx" type="int" /> |
| 87 | <description> |
| 88 | Returns array of faces that touch given edge. |
| 89 | </description> |
| 90 | </method> |
| 91 | <method name="get_edge_meta" qualifiers="const"> |
| 92 | <return type="Variant" /> |
| 93 | <param index="0" name="idx" type="int" /> |
| 94 | <description> |
| 95 | Returns meta information assigned to given edge. |
| 96 | </description> |
| 97 | </method> |
| 98 | <method name="get_edge_vertex" qualifiers="const"> |
| 99 | <return type="int" /> |
| 100 | <param index="0" name="idx" type="int" /> |
| 101 | <param index="1" name="vertex" type="int" /> |
| 102 | <description> |
| 103 | Returns the index of the specified [param vertex] connected to the edge at index [param idx]. |
| 104 | [param vertex] can only be [code]0[/code] or [code]1[/code], as edges are composed of two vertices. |
| 105 | </description> |
| 106 | </method> |
| 107 | <method name="get_face_count" qualifiers="const"> |
| 108 | <return type="int" /> |
| 109 | <description> |
| 110 | Returns the number of faces in this [Mesh]. |
| 111 | </description> |
| 112 | </method> |
| 113 | <method name="get_face_edge" qualifiers="const"> |
| 114 | <return type="int" /> |
| 115 | <param index="0" name="idx" type="int" /> |
| 116 | <param index="1" name="edge" type="int" /> |
| 117 | <description> |
| 118 | Returns the edge associated with the face at index [param idx]. |
| 119 | [param edge] argument must be either [code]0[/code], [code]1[/code], or [code]2[/code] because a face only has three edges. |
| 120 | </description> |
| 121 | </method> |
| 122 | <method name="get_face_meta" qualifiers="const"> |
| 123 | <return type="Variant" /> |
| 124 | <param index="0" name="idx" type="int" /> |
| 125 | <description> |
| 126 | Returns the metadata associated with the given face. |
| 127 | </description> |
| 128 | </method> |
| 129 | <method name="get_face_normal" qualifiers="const"> |
| 130 | <return type="Vector3" /> |
| 131 | <param index="0" name="idx" type="int" /> |
| 132 | <description> |
| 133 | Calculates and returns the face normal of the given face. |
| 134 | </description> |
| 135 | </method> |
| 136 | <method name="get_face_vertex" qualifiers="const"> |
| 137 | <return type="int" /> |
| 138 | <param index="0" name="idx" type="int" /> |
| 139 | <param index="1" name="vertex" type="int" /> |
| 140 | <description> |
| 141 | Returns the specified vertex index of the given face. |
| 142 | [param vertex] must be either [code]0[/code], [code]1[/code], or [code]2[/code] because faces contain three vertices. |
| 143 | [codeblocks] |
| 144 | [gdscript] |
| 145 | var index = mesh_data_tool.get_face_vertex(0, 1) # Gets the index of the second vertex of the first face. |
| 146 | var position = mesh_data_tool.get_vertex(index) |
| 147 | var normal = mesh_data_tool.get_vertex_normal(index) |
| 148 | [/gdscript] |
| 149 | [csharp] |
| 150 | int index = meshDataTool.GetFaceVertex(0, 1); // Gets the index of the second vertex of the first face. |
| 151 | Vector3 position = meshDataTool.GetVertex(index); |
| 152 | Vector3 normal = meshDataTool.GetVertexNormal(index); |
| 153 | [/csharp] |
| 154 | [/codeblocks] |
| 155 | </description> |
| 156 | </method> |
| 157 | <method name="get_format" qualifiers="const"> |
| 158 | <return type="int" /> |
| 159 | <description> |
| 160 | Returns the [Mesh]'s format as a combination of the [enum Mesh.ArrayFormat] flags. 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]. |
| 161 | </description> |
| 162 | </method> |
| 163 | <method name="get_material" qualifiers="const"> |
| 164 | <return type="Material" /> |
| 165 | <description> |
| 166 | Returns the material assigned to the [Mesh]. |
| 167 | </description> |
| 168 | </method> |
| 169 | <method name="get_vertex" qualifiers="const"> |
| 170 | <return type="Vector3" /> |
| 171 | <param index="0" name="idx" type="int" /> |
| 172 | <description> |
| 173 | Returns the position of the given vertex. |
| 174 | </description> |
| 175 | </method> |
| 176 | <method name="get_vertex_bones" qualifiers="const"> |
| 177 | <return type="PackedInt32Array" /> |
| 178 | <param index="0" name="idx" type="int" /> |
| 179 | <description> |
| 180 | Returns the bones of the given vertex. |
| 181 | </description> |
| 182 | </method> |
| 183 | <method name="get_vertex_color" qualifiers="const"> |
| 184 | <return type="Color" /> |
| 185 | <param index="0" name="idx" type="int" /> |
| 186 | <description> |
| 187 | Returns the color of the given vertex. |
| 188 | </description> |
| 189 | </method> |
| 190 | <method name="get_vertex_count" qualifiers="const"> |
| 191 | <return type="int" /> |
| 192 | <description> |
| 193 | Returns the total number of vertices in [Mesh]. |
| 194 | </description> |
| 195 | </method> |
| 196 | <method name="get_vertex_edges" qualifiers="const"> |
| 197 | <return type="PackedInt32Array" /> |
| 198 | <param index="0" name="idx" type="int" /> |
| 199 | <description> |
| 200 | Returns an array of edges that share the given vertex. |
| 201 | </description> |
| 202 | </method> |
| 203 | <method name="get_vertex_faces" qualifiers="const"> |
| 204 | <return type="PackedInt32Array" /> |
| 205 | <param index="0" name="idx" type="int" /> |
| 206 | <description> |
| 207 | Returns an array of faces that share the given vertex. |
| 208 | </description> |
| 209 | </method> |
| 210 | <method name="get_vertex_meta" qualifiers="const"> |
| 211 | <return type="Variant" /> |
| 212 | <param index="0" name="idx" type="int" /> |
| 213 | <description> |
| 214 | Returns the metadata associated with the given vertex. |
| 215 | </description> |
| 216 | </method> |
| 217 | <method name="get_vertex_normal" qualifiers="const"> |
| 218 | <return type="Vector3" /> |
| 219 | <param index="0" name="idx" type="int" /> |
| 220 | <description> |
| 221 | Returns the normal of the given vertex. |
| 222 | </description> |
| 223 | </method> |
| 224 | <method name="get_vertex_tangent" qualifiers="const"> |
| 225 | <return type="Plane" /> |
| 226 | <param index="0" name="idx" type="int" /> |
| 227 | <description> |
| 228 | Returns the tangent of the given vertex. |
| 229 | </description> |
| 230 | </method> |
| 231 | <method name="get_vertex_uv" qualifiers="const"> |
| 232 | <return type="Vector2" /> |
| 233 | <param index="0" name="idx" type="int" /> |
| 234 | <description> |
| 235 | Returns the UV of the given vertex. |
| 236 | </description> |
| 237 | </method> |
| 238 | <method name="get_vertex_uv2" qualifiers="const"> |
| 239 | <return type="Vector2" /> |
| 240 | <param index="0" name="idx" type="int" /> |
| 241 | <description> |
| 242 | Returns the UV2 of the given vertex. |
| 243 | </description> |
| 244 | </method> |
| 245 | <method name="get_vertex_weights" qualifiers="const"> |
| 246 | <return type="PackedFloat32Array" /> |
| 247 | <param index="0" name="idx" type="int" /> |
| 248 | <description> |
| 249 | Returns bone weights of the given vertex. |
| 250 | </description> |
| 251 | </method> |
| 252 | <method name="set_edge_meta"> |
| 253 | <return type="void" /> |
| 254 | <param index="0" name="idx" type="int" /> |
| 255 | <param index="1" name="meta" type="Variant" /> |
| 256 | <description> |
| 257 | Sets the metadata of the given edge. |
| 258 | </description> |
| 259 | </method> |
| 260 | <method name="set_face_meta"> |
| 261 | <return type="void" /> |
| 262 | <param index="0" name="idx" type="int" /> |
| 263 | <param index="1" name="meta" type="Variant" /> |
| 264 | <description> |
| 265 | Sets the metadata of the given face. |
| 266 | </description> |
| 267 | </method> |
| 268 | <method name="set_material"> |
| 269 | <return type="void" /> |
| 270 | <param index="0" name="material" type="Material" /> |
| 271 | <description> |
| 272 | Sets the material to be used by newly-constructed [Mesh]. |
| 273 | </description> |
| 274 | </method> |
| 275 | <method name="set_vertex"> |
| 276 | <return type="void" /> |
| 277 | <param index="0" name="idx" type="int" /> |
| 278 | <param index="1" name="vertex" type="Vector3" /> |
| 279 | <description> |
| 280 | Sets the position of the given vertex. |
| 281 | </description> |
| 282 | </method> |
| 283 | <method name="set_vertex_bones"> |
| 284 | <return type="void" /> |
| 285 | <param index="0" name="idx" type="int" /> |
| 286 | <param index="1" name="bones" type="PackedInt32Array" /> |
| 287 | <description> |
| 288 | Sets the bones of the given vertex. |
| 289 | </description> |
| 290 | </method> |
| 291 | <method name="set_vertex_color"> |
| 292 | <return type="void" /> |
| 293 | <param index="0" name="idx" type="int" /> |
| 294 | <param index="1" name="color" type="Color" /> |
| 295 | <description> |
| 296 | Sets the color of the given vertex. |
| 297 | </description> |
| 298 | </method> |
| 299 | <method name="set_vertex_meta"> |
| 300 | <return type="void" /> |
| 301 | <param index="0" name="idx" type="int" /> |
| 302 | <param index="1" name="meta" type="Variant" /> |
| 303 | <description> |
| 304 | Sets the metadata associated with the given vertex. |
| 305 | </description> |
| 306 | </method> |
| 307 | <method name="set_vertex_normal"> |
| 308 | <return type="void" /> |
| 309 | <param index="0" name="idx" type="int" /> |
| 310 | <param index="1" name="normal" type="Vector3" /> |
| 311 | <description> |
| 312 | Sets the normal of the given vertex. |
| 313 | </description> |
| 314 | </method> |
| 315 | <method name="set_vertex_tangent"> |
| 316 | <return type="void" /> |
| 317 | <param index="0" name="idx" type="int" /> |
| 318 | <param index="1" name="tangent" type="Plane" /> |
| 319 | <description> |
| 320 | Sets the tangent of the given vertex. |
| 321 | [b]Note:[/b] Even though [param tangent] is a [Plane], it does not directly represent the tangent plane. Its [member Plane.x], [member Plane.y], and [member Plane.z] represent the tangent vector and [member Plane.d] should be either [code]-1[/code] or [code]1[/code]. See also [constant Mesh.ARRAY_TANGENT]. |
| 322 | </description> |
| 323 | </method> |
| 324 | <method name="set_vertex_uv"> |
| 325 | <return type="void" /> |
| 326 | <param index="0" name="idx" type="int" /> |
| 327 | <param index="1" name="uv" type="Vector2" /> |
| 328 | <description> |
| 329 | Sets the UV of the given vertex. |
| 330 | </description> |
| 331 | </method> |
| 332 | <method name="set_vertex_uv2"> |
| 333 | <return type="void" /> |
| 334 | <param index="0" name="idx" type="int" /> |
| 335 | <param index="1" name="uv2" type="Vector2" /> |
| 336 | <description> |
| 337 | Sets the UV2 of the given vertex. |
| 338 | </description> |
| 339 | </method> |
| 340 | <method name="set_vertex_weights"> |
| 341 | <return type="void" /> |
| 342 | <param index="0" name="idx" type="int" /> |
| 343 | <param index="1" name="weights" type="PackedFloat32Array" /> |
| 344 | <description> |
| 345 | Sets the bone weights of the given vertex. |
| 346 | </description> |
| 347 | </method> |
| 348 | </methods> |
| 349 | </class> |