Skip to content
Shapemetry

Model - Mesh

API reference for src/schema/domains/mesh, src/nodeMethods/mesh, src/nodeMethods/solid/mesh on @huukhanhnguyen/model, reachable from ./compute.

See the Guide for the ModelJSON / evaluate pipeline.

API reference

Signatures are generated from the live package .d.ts - not hand-written.

BakedTriangleMesh

type

The display-tessellation payload: faces → the display triangle mesh, tessellated from the BREP boundary in the wasm kernel, one whole outer shell per entity and the results concatenated.

It IS the canonical TriangleMesh (@huukhanhnguyen/types) — no channel of its own — narrowed so the three channels the display path always fills stop being optional: every consumer reads normals.length / uvs without a guard, and ?? [] there would be a lie about a producer that never omits them. The per-point attr channels (uvs2/colors/skin/morphs) a Shell once carried are gone for good: a brep face has no loop-point index space to hang them on, so anything needing them is a meshEntity, whose own Mesh geometry declares them.

UV follows law 11c: the kernel's own surface UV is the DERIVED frame used whenever uvMatrix is absent (for a planar face it is already plane-frame millimetres, so the tiling law repeat = 1/tile holds); an AUTHORED uvMatrix WINS and is re-projected onto the emitted vertices, or a deliberately placed texture would silently lose its origin and rotation.

type BakedTriangleMesh
// = TriangleMesh & { normals: number[]; uvs: number[]; groups: MeshGroup[]; }

chunkTriangleIndices

function

Chunk a flat triangle index pool into 3-gon faces (GLB intake / migration).

chunkTriangleIndices(indices: number[]): number[][]

computeVertexNormals

function

Area-weighted smooth vertex normals over triangulated faces.

computeVertexNormals(positions: number[], faces: number[][]): number[]

facesToMesh

function

The welded mesh's READS, each opening and releasing its own arena handle.

ponytail: this exists so the consumers outside this module keep their one spelling (facesToMesh(faces).tessellate()) while the live TypeScript class under it is gone — no object owns kernel memory across a call, which is the whole point. A caller that wants to mutate the topology takes facesToMeshHandle and frees it.

facesToMesh(faces: ShellEntity[]): { tessellate(): TriangleMesh; volume(): number; }

facesToTriangleMesh

function

A solid's faces → the welded mesh's TRIANGLE SOUP. The display substrate nodeMethods/entities.ts, solidify.ts, triangulate.ts and unfold.ts all read, and the reason none of them needs a handle: they want positions and indices, not a topology to mutate.

facesToTriangleMesh(faces: ShellEntity[]): TriangleMesh

faceToMesh

const

Planar no-hole faces → one n-gon each (welded shared vertices). Curved or holed faces tessellate to triangle faces (3-gons).

const faceToMesh: ((entities: Entity[]) => Entity[]) & { wholeArray: true

MeshEdgeRecord

type

type MeshEdgeRecord
// = {
    v1: number;
    v2: number;
    /** Bit flags: 1 = crease/sharp. */
    flags: number;
    /** How many faces use this undirected edge. */
    faceCount: number;
}

meshFacesToTriangles

function

Pure: n-gon faces → flat triangle indices. Same input → byte-identical.

meshFacesToTriangles(positions: number[], faces: number[][]): number[]

meshLattice

const

Hollow every mesh into a strut frame from polygon faces (no triangle roundtrip — wireframe follows design edges, not face diagonals).

const meshLattice: ((entities: Entity[], offset: number, boundary?: boolean) => Entity[]) & { wholeArray: true

meshSubdivision

const

Catmull-Clark subdivide every mesh in the stream (mesh→mesh). Channels drop (topology changes); normals rebuild when the input had them.

const meshSubdivision: ((entities: Entity[], iterations?: number) => Entity[]) & { wholeArray: true

meshToFaces

function

A welded half-edge mesh HANDLE → its faces as Face[]. Exactly-planar n-gon faces (box sides, cut faces) map to one region each; non-planar faces split to planar triangles (see emitPlanarOrSplit) so the decompose → re-weld round-trip stays vertex-faithful.

meshToFaces(mesh: number): ShellEntity[]

nurbsToFaces

function

A kernel NURBS surface → one natural-bounds curved scene face when the boundary is honest (kernel ≥ 0.17.0); falls back to one planar triangle face per tessellation triangle only when the natural-bounds path refuses.

nurbsToFaces(nurbs: NurbsSurface): ShellEntity[]

placeMesh

function

GLB bytes → ONE meshEntity. Faces are all 3-gons (no coplanar merge).

placeMesh(url: string, bytes: Uint8Array | ArrayBuffer | null | undefined): Entity[]

tessellateFaces

function

tessellateFaces(faces: ShellEntity[], curveTolerance?: number): BakedTriangleMesh
Last updated: 📖 3 min readEdit on GitHub