import type { Document, Node, Primitive, Skin } from '@gltf-transform/core'; /** * LIMB BRIDGE REPAIR — cut the skin that an auto-rigged character grew between an arm and a leg, close the * holes, and make each side follow its own bone. * * ── WHY ──────────────────────────────────────────────────────────────────────────────────────────────────── * Meshy (Dreamer) generates characters in an A-pose with the hands resting against the thighs. Where the hand * and the thigh touch, its mesher merges the two surfaces: a strip of triangles runs from the inside of the * forearm/hand to the outside of the thigh, and its auto-rigger then spreads thigh weight onto the hand (and * hand weight onto the thigh) across the contact. In the walk the arm swings forward while the leg swings back, * so the strip is torn into a sheet from the wrist to the knee. Dreamer item 4400fe58 (job 8f604f4d, * 2026-10-03): 342 arm<->leg triangles on a 52 896-triangle mesh, 4.5% of the skinned surface stretched over 3x * in the walk — the visual-QA gate's `avatar.skin_intact` failed it, and the critic saw "a long smeared sheet * running from the arm down to the rear leg". Five other recent Meshy rigs carry 0-126 such triangles. * * ── DETECT (from skin weights, conservatively) ───────────────────────────────────────────────────────────── * A vertex belongs to a limb when that limb's joints (upperarm/lowerarm/hand/fingers, or thigh/calf/foot/ball, * per side) own at least `limbDominance` (0.5) of its weight. A BRIDGE triangle has one corner owned by an arm * and another owned by a leg. Only the arm<->leg pair is ever cut: no joint of a humanoid connects them, so no * real surface may join them. Legitimate contacts live on other pairs and are never touched — a skirt spans the * two legs, a hoodie pocket holding a hand is arm<->torso, a cape and a long sleeve are torso<->arm, a tail is * pelvis. Bridge triangles are grouped into clusters (shared welded vertices). A cluster is REFUSED, and its * geometry left as it is, when it is larger than `maxClusterTris`, when cutting it would detach any piece of * the mesh, or when the holes it leaves cannot be traced as closed loops. * * ── REPAIR ───────────────────────────────────────────────────────────────────────────────────────────────── * 1. Delete the accepted clusters' triangles. * 2. A vertex shared by an arm-side fan and a leg-side fan (a bow-tie left by the cut) is split, the copy nudged * 0.1 mm into its own fan so later position welds (LOD simplify) cannot fuse it again. * 3. Each new boundary loop is closed from its own vertices (no new vertices) by greedy ear clipping that always * takes the shortest diagonal — a long slit along the forearm is zipped shut, a round hole is capped. * 4. Within `cleanseRadiusM` (surface distance) of the cut, every vertex sides with the nearer cut edge and loses * the OTHER limb's weight; a vertex left with no weight takes the average of its cleansed neighbours. * * ── GATE ─────────────────────────────────────────────────────────────────────────────────────────────────── * The surface is posed into two opposite walk strides (legs ±`strideDeg`, arms counter-swinging) and the share * of triangle area with an edge stretched over 3x is measured — the same quantity as visual QA's skin_intact. * The repair is kept only when that share falls in the sum of both strides and rises in neither; otherwise the * primitive is left byte-for-byte untouched and the report says why. Mode `report` measures and reports what it * WOULD change without writing anything. * * Under `restPose` (the arm re-bind's preview, for an arm the hand-to-thigh guard would hold back) both strides are * taken from the re-bound pose: in the low source pose the hand rests on the thigh and the bridge barely stretches, so * the cut never looked worth it and the guard then kept the arm in the body (Tripo fox girl 18 deg; Meshy b1884bb1, * 8f604f4d failing bind_pose). There the final gate takes the sum of both strides only. */ export type LimbBridgeMode = 'repair' | 'report' | 'off'; export interface LimbBridgeOptions { /** 'repair' (default) cuts and closes; 'report' only measures; 'off' skips the stage. */ mode?: LimbBridgeMode; /** A vertex belongs to a limb when that limb owns at least this share of its weight (default 0.5). */ limbDominance?: number; /** Surface distance from the cut within which cross-limb weight is removed, metres (default 0.06). */ cleanseRadiusM?: number; /** Larger bridge clusters are refused as deliberate geometry (default 1500 triangles). */ maxClusterTris?: number; /** Gate pose: leg swing in degrees each way (default 35); arms counter-swing at 0.85x. */ strideDeg?: number; /** Side contact vertices by which bone their surface faces away from (default true); false = weights only. */ facing?: boolean; /** Base-colour luminance (0-255) sampler for a primitive's TEXCOORD_0, so a cap takes a representative texel. */ sampleLuma?: (prim: Primitive) => ((u: number, v: number) => number) | null; /** * The rest the character will walk from when it differs from the file's: per skin, a world-space transform per joint * (null = unchanged) that a later stage bakes in — the arm re-bind (`previewArmRebind`, armBind.ts). The gate's two * strides are then taken from that pose and compared with the file's rest, so a hand fused to the thigh is judged * where the re-bind pulls it away from the leg, not in the low source pose where the bridge does not stretch. */ restPose?: (skin: Skin) => Array | null; } export type Limb = 'arm_l' | 'arm_r' | 'leg_l' | 'leg_r'; /** helix-humanoid@1 joint -> limb, or null for torso/head/clavicle/root joints. */ export declare function limbOfJoint(name: string): Limb | null; export interface LimbBridgeCluster { arm: Limb; leg: Limb; triangles: number; /** Rest-space bounds of the cluster, metres. */ min: [number, number, number]; max: [number, number, number]; /** null = accepted; otherwise why it was left alone. */ refused: string | null; } export interface LimbBridgeUnitReport { mesh: string; triangles: number; bridgeTriangles: number; clusters: LimbBridgeCluster[]; /** What the repair did (or would do, in report mode). */ removedTriangles: number; fillTriangles: number; holesClosed: number; bowtiesSplit: number; verticesReweighted: number; /** Pieces only a bridge held on, re-assigned to the limb they hang from ("150 tris -> arm_r"). */ reassignedPieces: string[]; /** Share (%) of triangle area stretched over 3x in the two gate strides. */ stretchBefore: [number, number]; stretchAfter: [number, number] | null; outcome: 'repaired' | 'would-repair' | 'clean' | 'refused' | 'no-improvement'; reason?: string; /** Repair passes kept (a cut can expose a new bridge next to it; each pass re-detects). */ passes: number; } export interface LimbBridgeReport { mode: LimbBridgeMode; units: LimbBridgeUnitReport[]; /** Totals over units that were (or, in report mode, would be) changed. */ removedTriangles: number; fillTriangles: number; verticesReweighted: number; } /** Percent of triangle area with any edge stretched over 3x between `rest` and `posed`. */ export declare function stretchedAreaPercent(rest: ArrayLike, posed: ArrayLike, tris: ArrayLike): number; /** Bind-pose bone segments per limb (index into LIMBS), from the skin's inverse bind matrices. */ export type LimbSegments = Array>; export declare function limbSegments(node: Node): LimbSegments | null; /** * Detect and (by default) repair arm<->leg bridge geometry on every skinned triangle primitive of `document`. * Joint names must already be helix-humanoid@1 (run after retarget/conform). */ export declare function repairLimbBridges(document: Document, options?: LimbBridgeOptions): LimbBridgeReport; /** Decodes every base-colour texture once (sharp) and returns a luminance sampler factory for `sampleLuma`. */ export declare function baseColorLumaSamplers(document: Document): Promise<(prim: Primitive) => ((u: number, v: number) => number) | null>; /** One log line per unit that had anything to say. */ export declare function describeLimbBridgeReport(report: LimbBridgeReport): string[]; /** * Whether the re-bind may take `sides` all the way: the repair judged their bridge under the full re-bind (`restPose`) * and what it left there — cut where cutting helped, uncut where the cut stretched more — stretches at most * BRIDGE_TOLERABLE_PCT of the surface in either stride. Then the hand-to-thigh guard does not hold the arm in the body: * measured, the held-back arm was the worse outcome (Meshy 8f604f4d imported from its raw rig: guarded arms at 13.5 / * 15.5 deg, forearms inside the hoodie, 30 % of them in the Marketplace walk; let through after the cut left 1.9 / 1.7 %, * arms at 42 deg, 1.9 %, every walk assert passing; 75a413cd: 0.3 / 0.4 % uncut, its cut drew shards through the * hoodie). A bridge the repair refused outright or never saw (`clean`) leaves the guard in charge. */ export declare function bridgeVerdict(report: LimbBridgeReport, sides: ReadonlyArray<'l' | 'r'>): Array<'l' | 'r'>;