Skip to content

Mesh

Namespace Nfty.Model in assembly Nfty.Model.

public sealed class Mesh

A triangle mesh: what Riser builds, what the writers serialize, and what the step-6 preview rasterizes. Immutable — every array is copied in and exposed read-only — and every derived value is computed in the constructor, never lazily (mixel's D7), so one mesh may be read from many threads.

Remarks

Vertex rule. A vertex is shared only by the two triangles of its own quad: four vertices and six indices per quad, so Mesh.VertexCount is always twice Mesh.TriangleCount for a risen mesh. Vertices that share a position across quads are NOT merged — their normals and UVs differ per face, and a merge keyed on position alone would be wrong. Whether a merge keyed on (position, normal, uv) is worth its complexity is a size question answered by RisePerfTests' measurement, not assumed.

Coordinates follow glTF: +Y up, +Z toward the viewer. Texture coordinates put (0,0) at the image's top-left, so v grows downward with the image row.

Constructors

Mesh(float[], float[], float[], uint[], int, int)

public Mesh(float[] positions, float[] normals, float[] texCoords, uint[] indices, int textureWidth, int textureHeight);

Builds a mesh, copying every array.

Parameters

  • positions (float[]) - xyz per vertex.
  • normals (float[]) - One xyz unit normal per vertex.
  • texCoords (float[]) - One uv per vertex.
  • indices (uint[]) - Three vertex indices per triangle, counter-clockwise seen from outside.
  • textureWidth (int) - Width of the image the UVs address.
  • textureHeight (int) - Height of the image the UVs address.

Exceptions

  • ArgumentException - The arrays disagree about the vertex count, an index names no vertex, or a position is not finite.

Properties

Indices

public IReadOnlyList<uint> Indices { get; }

Three vertex indices per triangle, counter-clockwise seen from outside.

Max

public Vector3 Max { get; }

The largest x, y and z over every vertex — glTF's POSITION max.

Min

public Vector3 Min { get; }

The smallest x, y and z over every vertex — exactly the values glTF's POSITION accessor must carry as min.

Normals

public IReadOnlyList<float> Normals { get; }

One xyz unit normal per vertex, pointing out of the solid.

Positions

public IReadOnlyList<float> Positions { get; }

xyz per vertex, in world units.

TexCoords

public IReadOnlyList<float> TexCoords { get; }

One uv per vertex; (0,0) is the texture's top-left.

TextureHeight

public int TextureHeight { get; }

Height of the image the UVs address.

TextureWidth

public int TextureWidth { get; }

Width of the image the UVs address; a writer refuses a texture of another size.

TriangleCount

public int TriangleCount { get; }

How many triangles the mesh has.

VertexCount

public int VertexCount { get; }

How many vertices the mesh has.