import { type HalfSpace } from './math'; /** * The garment-side topology the fit's displacement field lives on, and the smoothing that keeps that field * shaped like cloth rather than like a set of independent spikes. Pure: positions in, arrays out. * * ── WHY WELD FIRST ───────────────────────────────────────────────────────────────────────────────────────── * A glTF garment stores one vertex per (position, normal, uv) combination, so every UV seam and hard edge * is two or more coincident vertices — and some exports (Female NEO Arcane Heir Gloves' LOD0) are fully * non-indexed, every triangle carrying its own three vertices. Displacing coincident vertices by different * amounts tears the surface open along every seam. So the fit computes ONE displacement per welded position * group and writes that same displacement to every member. Welding also gives the smoothing a connected * graph, and makes hems detectable: a seam looks like a boundary edge until it is welded. */ export interface WeldResult { /** vertex index (in the concatenated vertex list) -> group id */ groupOf: Int32Array; groupCount: number; /** representative rest position per group (3 per group) */ groupPos: Float64Array; } /** Groups vertices whose rest positions coincide to within `quantum` metres (default 1µm — far below any * modelled feature, far above float32 round-off on character-scale coordinates). */ export declare function weldByPosition(positions: Float64Array, quantum?: number): WeldResult; export interface GroupGraph { /** CSR adjacency: neighbours of g are `neighbors[offsets[g] .. offsets[g+1])`. */ offsets: Int32Array; neighbors: Int32Array; /** Edge weight per adjacency entry: 1 / rest edge length (closer neighbours pull harder). */ weights: Float64Array; /** Group lies on an open (manifold-boundary) edge — a hem, cuff, collar or opening. */ boundary: Uint8Array; /** Group lies on or next to a boundary (its 1-ring touches one). */ nearBoundary: Uint8Array; meanEdgeLength: number; } /** Builds the welded edge graph from triangles given as group ids (3 per triangle). An edge used by exactly * one triangle is a boundary edge; non-manifold edges (3+ triangles) are treated as interior. */ export declare function buildGroupGraph(triangleGroups: Int32Array, groupPos: Float64Array, groupCount: number): GroupGraph; /** * How many smoothing sweeps give a falloff of roughly `radiusMeters` on a mesh with this edge length. * Explicit Laplacian diffusion spreads a spike over ~√k edge rings after k sweeps, so k ≈ (radius / edge)². * Deriving k from a physical radius (instead of a fixed sweep count) keeps the falloff the same size in * centimetres on a dense LOD0 and a coarse LOD2 — a fixed count would make LOD2's bumps 3-4× wider. */ export declare function sweepsForRadius(radiusMeters: number, meanEdgeLength: number, min?: number, max?: number): number; /** * THE SMOOTHING — an obstacle-constrained membrane, not plain smoothing. * * Input: `offsets` (3 per group), the raw per-group displacement each vertex needs on its own, and the * half-space requirements that produced it. Each sweep does two things: * * 1. Jacobi Laplacian step: x ← (1-α)·x + α·(Σ wᵢⱼ xⱼ / Σ wᵢⱼ). Spikes spread to their neighbours and * shrink; unconstrained vertices next to a pushed one start moving with it. * 2. Obstacle projection: every group that carries requirements is projected back onto them, so no * smoothing sweep can ever leave a vertex short of the clearance it was asked for. * * The fixed point is the smoothest field that still satisfies every requirement — a "tent" draped over the * required pushes instead of a bed of nails. That is what keeps silhouettes intact: a lone chord that has to * move 4mm pulls its neighbourhood out in a smooth bump that fades over `radius`, instead of creating a * 4mm dimple-in-reverse that reads as a lump in motion, and a whole region that needs clearance moves as a * sheet. Hem-specific behaviour (so a cuff or waistband is not flared outward) is applied by the caller as a * lower magnitude cap on boundary groups — see `capMagnitudes` and the stage's `hemMaxPushMm`. */ export declare function smoothWithObstacles(offsets: Float64Array, requirements: ReadonlyArray, graph: GroupGraph, sweeps: number, alpha?: number): void; /** Scales every group's TOTAL displacement (`base` + `offsets`) down to at most `caps[g]` metres, writing the * capped increment back into `offsets`. Returns how many groups were capped. */ export declare function capMagnitudes(offsets: Float64Array, base: Float64Array, caps: Float64Array): number; /** * Shortest along-surface distance (metres, over welded edges) from every group to the nearest boundary * group — Dijkstra from all boundary groups at once. Infinity for a closed mesh / an island with no hem. * Drives the hem band: a group's push cap ramps from `hemMaxPush` on the hem itself to the full `maxPush` * `hemBand` metres in, so a cuff keeps its edge without a visible step one ring inside it. */ export declare function distanceToBoundary(graph: GroupGraph): Float64Array; /** Per-group push cap: `hemMax` on the hem, ramping linearly to `max` over `band` metres of surface. */ export declare function hemBandCaps(distToHem: Float64Array, max: number, hemMax: number, band: number): Float64Array;