Table of Contents

Class MeshDataTool

Namespace
Godot
Assembly
GodotSharp.dll

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.

To use MeshDataTool, load a mesh with CreateFromSurface(ArrayMesh, int). When you are finished editing the data commit the data to a mesh with CommitToSurface(ArrayMesh, ulong).

Below is an example of how MeshDataTool may be used.

var mesh = new ArrayMesh();
  mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, new BoxMesh().GetMeshArrays());
  var mdt = new MeshDataTool();
  mdt.CreateFromSurface(mesh, 0);
  for (var i = 0; i < mdt.GetVertexCount(); i++)
  {
      Vector3 vertex = mdt.GetVertex(i);
      // In this example we extend the mesh by one unit, which results in separated faces as it is flat shaded.
      vertex += mdt.GetVertexNormal(i);
      // Save your change.
      mdt.SetVertex(i, vertex);
  }
  mesh.ClearSurfaces();
  mdt.CommitToSurface(mesh);
  var mi = new MeshInstance();
  mi.Mesh = mesh;
  AddChild(mi);

See also ArrayMesh, ImmediateMesh and SurfaceTool for procedural geometry generation.

Note: Godot uses clockwise winding order for front faces of triangle primitive modes.

public class MeshDataTool : RefCounted, IDisposable
Inheritance
MeshDataTool
Implements
Inherited Members

Constructors

MeshDataTool()

public MeshDataTool()

Methods

Clear()

Clears all data currently in MeshDataTool.

public void Clear()

CommitToSurface(ArrayMesh, ulong)

Adds a new surface to specified Mesh with edited data.

public Error CommitToSurface(ArrayMesh mesh, ulong compressionFlags = 0)

Parameters

mesh ArrayMesh
compressionFlags ulong

Returns

Error

CreateFromSurface(ArrayMesh, int)

Uses specified surface of given Mesh to populate data for MeshDataTool.

Requires Mesh with primitive type Triangles.

public Error CreateFromSurface(ArrayMesh mesh, int surface)

Parameters

mesh ArrayMesh
surface int

Returns

Error

GetEdgeCount()

Returns the number of edges in this Mesh.

public int GetEdgeCount()

Returns

int

GetEdgeFaces(int)

Returns array of faces that touch given edge.

public int[] GetEdgeFaces(int idx)

Parameters

idx int

Returns

int[]

GetEdgeMeta(int)

Returns meta information assigned to given edge.

public Variant GetEdgeMeta(int idx)

Parameters

idx int

Returns

Variant

GetEdgeVertex(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.

public int GetEdgeVertex(int idx, int vertex)

Parameters

idx int
vertex int

Returns

int

GetFaceCount()

Returns the number of faces in this Mesh.

public int GetFaceCount()

Returns

int

GetFaceEdge(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.

public int GetFaceEdge(int idx, int edge)

Parameters

idx int
edge int

Returns

int

GetFaceMeta(int)

Returns the metadata associated with the given face.

public Variant GetFaceMeta(int idx)

Parameters

idx int

Returns

Variant

GetFaceNormal(int)

Calculates and returns the face normal of the given face.

public Vector3 GetFaceNormal(int idx)

Parameters

idx int

Returns

Vector3

GetFaceVertex(int, int)

Returns the specified vertex index of the given face.

Vertex argument must be either 0, 1, or 2 because faces contain three vertices.

Example:

int index = meshDataTool.GetFaceVertex(0, 1); // Gets the index of the second vertex of the first face.
  Vector3 position = meshDataTool.GetVertex(index);
  Vector3 normal = meshDataTool.GetVertexNormal(index);
public int GetFaceVertex(int idx, int vertex)

Parameters

idx int
vertex int

Returns

int

GetFormat()

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 3 because FormatVertex is 1 and FormatNormal is 2.

See Mesh.ArrayFormat for a list of format flags.

public ulong GetFormat()

Returns

ulong

GetMaterial()

Returns the material assigned to the Mesh.

public Material GetMaterial()

Returns

Material

GetVertex(int)

Returns the position of the given vertex.

public Vector3 GetVertex(int idx)

Parameters

idx int

Returns

Vector3

GetVertexBones(int)

Returns the bones of the given vertex.

public int[] GetVertexBones(int idx)

Parameters

idx int

Returns

int[]

GetVertexColor(int)

Returns the color of the given vertex.

public Color GetVertexColor(int idx)

Parameters

idx int

Returns

Color

GetVertexCount()

Returns the total number of vertices in Mesh.

public int GetVertexCount()

Returns

int

GetVertexEdges(int)

Returns an array of edges that share the given vertex.

public int[] GetVertexEdges(int idx)

Parameters

idx int

Returns

int[]

GetVertexFaces(int)

Returns an array of faces that share the given vertex.

public int[] GetVertexFaces(int idx)

Parameters

idx int

Returns

int[]

GetVertexMeta(int)

Returns the metadata associated with the given vertex.

public Variant GetVertexMeta(int idx)

Parameters

idx int

Returns

Variant

GetVertexNormal(int)

Returns the normal of the given vertex.

public Vector3 GetVertexNormal(int idx)

Parameters

idx int

Returns

Vector3

GetVertexTangent(int)

Returns the tangent of the given vertex.

public Plane GetVertexTangent(int idx)

Parameters

idx int

Returns

Plane

GetVertexUV(int)

Returns the UV of the given vertex.

public Vector2 GetVertexUV(int idx)

Parameters

idx int

Returns

Vector2

GetVertexUV2(int)

Returns the UV2 of the given vertex.

public Vector2 GetVertexUV2(int idx)

Parameters

idx int

Returns

Vector2

GetVertexWeights(int)

Returns bone weights of the given vertex.

public float[] GetVertexWeights(int idx)

Parameters

idx int

Returns

float[]

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

SetEdgeMeta(int, Variant)

Sets the metadata of the given edge.

public void SetEdgeMeta(int idx, Variant meta)

Parameters

idx int
meta Variant

SetFaceMeta(int, Variant)

Sets the metadata of the given face.

public void SetFaceMeta(int idx, Variant meta)

Parameters

idx int
meta Variant

SetMaterial(Material)

Sets the material to be used by newly-constructed Mesh.

public void SetMaterial(Material material)

Parameters

material Material

SetVertex(int, Vector3)

Sets the position of the given vertex.

public void SetVertex(int idx, Vector3 vertex)

Parameters

idx int
vertex Vector3

SetVertexBones(int, int[])

Sets the bones of the given vertex.

public void SetVertexBones(int idx, int[] bones)

Parameters

idx int
bones int[]

SetVertexColor(int, Color)

Sets the color of the given vertex.

public void SetVertexColor(int idx, Color color)

Parameters

idx int
color Color

SetVertexMeta(int, Variant)

Sets the metadata associated with the given vertex.

public void SetVertexMeta(int idx, Variant meta)

Parameters

idx int
meta Variant

SetVertexNormal(int, Vector3)

Sets the normal of the given vertex.

public void SetVertexNormal(int idx, Vector3 normal)

Parameters

idx int
normal Vector3

SetVertexTangent(int, Plane)

Sets the tangent of the given vertex.

public void SetVertexTangent(int idx, Plane tangent)

Parameters

idx int
tangent Plane

SetVertexUV(int, Vector2)

Sets the UV of the given vertex.

public void SetVertexUV(int idx, Vector2 uV)

Parameters

idx int
uV Vector2

SetVertexUV2(int, Vector2)

Sets the UV2 of the given vertex.

public void SetVertexUV2(int idx, Vector2 uV2)

Parameters

idx int
uV2 Vector2

SetVertexWeights(int, float[])

Sets the bone weights of the given vertex.

public void SetVertexWeights(int idx, float[] weights)

Parameters

idx int
weights float[]