MeshDataTool provides access to individual vertices in a godot.Mesh. It allows users to read and edit vertex data of meshes. It also creates an array of faces and edges.
To use MeshDataTool, load a mesh with godot.MeshDataTool.createFromSurface. When you are finished editing the data commit the data to a mesh with godot.MeshDataTool.commitToSurface.
Below is an example of how MeshDataTool may be used.
var mesh = ArrayMesh.new()
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, CubeMesh.new().get_mesh_arrays())
var mdt = MeshDataTool.new()
mdt.create_from_surface(mesh, 0)
for i in range(mdt.get_vertex_count()):
var vertex = mdt.get_vertex(i)
# In this example we extend the mesh by one unit, which results in separated faces as it is flat shaded.
vertex += mdt.get_vertex_normal(i)
# Save your change.
mdt.set_vertex(i, vertex)
mesh.surface_remove(0)
mdt.commit_to_surface(mesh)
var mi = MeshInstance.new()
mi.mesh = mesh
add_child(mi)
See also godot.ArrayMesh, godot.ImmediateGeometry and godot.SurfaceTool for procedural geometry generation.
Note: Godot uses clockwise [https://learnopengl.com/Advanced-OpenGL/Face-culling](winding order) for front faces of triangle primitive modes.
Constructor
Methods
createFromSurface(mesh:ArrayMesh, surface:Int):Error
Uses specified surface of given godot.Mesh to populate data for MeshDataTool.
Requires godot.Mesh with primitive type godot.Mesh_PrimitiveType.triangles.
getEdgeVertex(idx:Int, vertex:Int):Int
Returns index of specified vertex connected to given edge.
Vertex argument can only be 0 or 1 because edges are comprised of two vertices.
getFaceEdge(idx:Int, edge:Int):Int
Returns specified edge associated with given face.
Edge argument must be either 0, 1, or 2 because a face only has three edges.
getFaceVertex(idx:Int, vertex:Int):Int
Returns the specified vertex of the given face.
Vertex argument must be either 0, 1, or 2 because faces contain three vertices.
getFormat():Int
Returns the godot.Mesh's format. Format is an integer made up of godot.Mesh format flags combined together. For example, a mesh containing both vertices and normals would return a format of 3 because godot.ArrayMesh_ArrayFormat.vertex is 1 and godot.ArrayMesh_ArrayFormat.normal is 2.
See godot.ArrayMesh_ArrayFormat for a list of format flags.