Skip to content

Getting Started

Vergeo2D.Mesh targets net8.0, netstandard2.1, and netstandard2.0.

Target Use when
net8.0 You are building a modern .NET 8+ app or tool.
netstandard2.1 You need to consume the mesh core from .NET Core 3.x, .NET 5+, or another runtime that supports .NET Standard 2.1.
netstandard2.0 You need compatibility with older hosts, including .NET Framework 4.7.2+ consumers through the .NET Standard asset.

The netstandard2.0 target includes small compatibility fallbacks and package references for APIs that older runtimes do not provide.

Terminal window
dotnet add package Vergeo2D.Mesh

Then import the core namespace:

using System.Numerics;
using Vergeo2D.Mesh;

Mesh2D stores vertex positions, UV coordinates, triangle faces, and a generated edge set.

var mesh = new Mesh2D();
var v0 = mesh.AddVertex(new Vector2(0, 0));
var v1 = mesh.AddVertex(new Vector2(256, 0));
var v2 = mesh.AddVertex(new Vector2(256, 128));
var v3 = mesh.AddVertex(new Vector2(0, 128));
mesh.AddFace(v0, v1, v2);
mesh.AddFace(v0, v2, v3);

Faces are triangles. Each call to AddFace() also adds the corresponding undirected Edge2D values to mesh.Edges.

Texture2D stores image dimensions and converts pixel positions into UV coordinates.

var texture = Texture2D.LoadFromFile("character.png");
mesh.SetTexture(texture);
mesh.GenerateUVsFromPositions(flipY: false);

Use flipY: true when your renderer expects the Y axis inverted in UV space.

For the common sprite case, create a ready-to-use rectangular mesh from a texture:

var texture = Texture2D.LoadFromFile("character.png");
var quad = MeshPrimitives2D.CreateTexturedQuad(texture);

The quad is a two-triangle mesh sized to the texture dimensions with UVs generated from vertex positions.

mesh.RemoveFace(0);
mesh.RemoveVertex(v3);
var clone = mesh.Clone();
var validation = mesh.Validate();
var json = Mesh2DSerializer.ToJson(mesh);
var loaded = Mesh2DSerializer.FromJson(json);
Mesh2DSerializer.SaveToFile(mesh, "character.mesh.json");

Mesh2D.Version is incremented when geometry changes. Render and management systems use this to avoid re-extracting unchanged meshes.