import { Document, type Primitive } from '@gltf-transform/core'; /** * The FACE of a single-mesh character import: the triangles a viewer reads as the face (eyes, brows, nose, mouth, * bangs, cheeks) and that a uniform decimate + area-proportional atlas destroy first. Meshy-class imports are one * welded mesh whose face is ~1-2% of the surface area, so a 31k -> 10k uniform decimate turns it into a handful of * large facets and an area-proportional unwrap gives it ~1% of the atlas (helix-creator-cli #290). * * Classification is rig-driven and geometric, never name-driven on the mesh: * - skin weight into the HEAD subtree ('head' and its descendants; falls back to the neck subtree when the rig has * no 'head') averaged over the triangle's corners is above `minHeadWeight` — the skull, not the neck or the long * hair the auto-rig weights to the clavicles; * - the triangle faces forward: its geometric normal's component along `forward` (+Z, the canonical facing every * conformed character has — see restFrameGuard) is above `minFacing`, which drops the back of the head (hair * mass, the cheapest place to lose density) and keeps the face, temples and fringe; * - it sits above the chin line: no lower than `chinDrop` of the head's height (head joint -> top of the head-weighted * surface) below the head joint. Auto-rigs (Meshy) weight the whole neck and the hood collar to 'head', so weight * alone would spend the face budget on a hoodie collar. */ export interface FaceRegionOptions { /** Mean per-corner weight into the head subtree above which a triangle is head (default 0.5). */ minHeadWeight?: number; /** Minimum dot(faceNormal, forward) for a head triangle to count as FACE (default 0.25, ~75 degrees off-axis). */ minFacing?: number; /** Facing axis in mesh space (default +Z, the conformed canonical facing). */ forward?: readonly [number, number, number]; /** How far below the head joint the face may reach, as a fraction of the head's height (default 0.15). */ chinDrop?: number; } /** * Per-TRIANGLE face mask over `prim`'s current index buffer (1 = face), or null when the primitive is not a skinned * indexed triangle list or its rig has no head joint. Pure read; never mutates the document. */ export declare function faceTriangleMask(document: Document, prim: Primitive, options?: FaceRegionOptions): Uint8Array | null; export interface FaceSplit { /** The original primitive, now holding only the non-face triangles. */ body: Primitive; /** The face triangles, as a sibling primitive in the same mesh sharing the body's accessors and material. */ face: Primitive; /** Triangle-area fraction (mesh space) the face holds of body + face. */ faceAreaShare: number; } /** * Moves each skinned primitive's face triangles into a sibling primitive (same mesh, same material, SHARED attribute * accessors — only the index buffer splits), so an unwrap can scale the face's charts independently: xatlas never * builds a chart across primitives. `rejoinFaceSplits` folds them back after the bake. Returns one entry per split. */ export declare function splitFaceForUnwrap(document: Document, options?: FaceRegionOptions): FaceSplit[]; /** Folds each face primitive back into its body primitive (one draw call again), in place in the same mesh. */ export declare function rejoinFaceSplits(document: Document, splits: readonly FaceSplit[]): void; /** * Linear scale for the face's charts in the unwrap so the face gets `boost` x the body's texel density, reduced * so the face never takes more than `maxShare` of the packed atlas area. With face area fraction f and linear scale * s, the face's atlas share is f s^2 / (f s^2 + 1 - f). */ export declare function faceChartScale(faceAreaShare: number, boost: number, maxShare: number): number;