Skip to content

Core API

Mesh2D is the central editable mesh object.

Member Purpose
Vertices Ordered List<Vertex2D> storing positions and UVs.
Edges HashSet<Edge2D> rebuilt from triangle faces.
Faces Ordered List<Face2D> of triangle indices.
Texture Optional Texture2D bound to the mesh.
Version Geometry version used by render extraction and managers.

Common editing methods:

var index = mesh.AddVertex(new Vector2(32, 64));
mesh.AddFace(0, 1, 2);
mesh.RemoveFace(0);
mesh.RemoveVertex(index);
mesh.RebuildEdges();

RemoveVertex() reindexes later vertices, removes faces using the deleted vertex, and rebuilds edges.

Use mesh queries for editor tools, picking, and topology inspection:

foreach (var connected in mesh.GetConnectedVertices(vertexIndex))
{
// adjacent vertex indices
}
foreach (var faceIndex in mesh.GetFacesContainingVertex(vertexIndex))
{
// face contains the vertex
}
var hitFace = mesh.FindFaceAt(mousePosition);

FindFaceAt() returns the first triangle containing a point, or -1 when no face is hit. For richer editor picking, use MeshPicking2D from Editor Utilities.

Use Validate() before accepting imported meshes, generated meshes, or user-edited topology:

var result = mesh.Validate();
foreach (var issue in result.Issues)
{
Console.WriteLine(issue);
}

MeshValidator2D.Validate(mesh, options) exposes the same diagnostics as a static helper. Validation reports invalid face indices, repeated vertices inside a face, tiny triangles, duplicate faces, orphan vertices, non-manifold edges, and inconsistent shared-edge winding.

Type Purpose
Vertex2D Stores Index, Position, and UV.
Edge2D Stores an undirected pair of vertex indices.
Face2D Stores triangle indices A, B, and C.

Changing vertex position or UV through Vertex2D notifies the owning mesh and bumps Mesh2D.Version.

Texture2D stores image dimensions and optional source path.

var texture = Texture2D.LoadFromFile("character.png");
var uv = texture.PixelToUV(new Vector2(128, 64));
var pixel = texture.UVToPixel(uv);

The built-in dimension reader supports common image formats such as PNG, JPEG, BMP, and GIF without adding third-party dependencies.

Mesh2DSerializer converts a mesh to and from JSON strings or files:

var json = Mesh2DSerializer.ToJson(mesh);
var loaded = Mesh2DSerializer.FromJson(json);
Mesh2DSerializer.SaveToFile(mesh, "character.mesh.json");
var loadedFile = Mesh2DSerializer.LoadFromFile("character.mesh.json");

Serialized data includes a schema version, vertices, UVs, faces, and the linked texture path when available.