import type { Document } from '@gltf-transform/core'; import { type SkinModel, type VertexSet, type Weights } from './armBindSkin'; /** * HANGING CLOTH — a skirt, robe, coat tail or cape skinned so it does not tear when the legs part. * * Generated characters (Dreamer: Tripo) come back auto-rigged by proximity to the bones. Cloth that hangs below the * hips and is wider than the legs (a floor-length skirt, a robe, a cape's tail) is given, panel by panel, to whichever * leg it is nearest to in the source pose: the left half of the hem follows the left leg, the right half the right * leg, and a vertex a centimetre from the seam between them is 100 % one leg and its neighbour 100 % the other. At * rest nothing shows. In a stride the legs part half a metre and every edge that crosses the seam is stretched * 10-20x: the hem opens into spikes, the back of the garment into a flat blade behind the legs (2026-10-08, hosted * critic, seven of the day's twelve avatars with long cloth: "the skirt tears into jagged shards", "coat-tail * polygons stretch into spikes below the hem", "a thin flat triangular blade jutting behind the legs"). The gate's own * `avatar.skin_intact` passed most of them because the torn cloth is a small share of the whole surface. * * What fixes it is not where the cloth hangs from but that the weights change SMOOTHLY: the legs part by the same * distance, spread over many edges instead of one. So this stage finds the triangles a walk stride tears (an edge * stretched over `tearRatio` x), takes the cloth around them (surface distance `reachM`), and relaxes that cloth's * weights toward the average of its neighbours until the stride no longer tears it. Nothing else moves: a vertex * outside that reach keeps its weights, and a model whose stride does not tear anything is not touched at all. * * The result is kept only when the stride stretch (share of the surface area with an edge over 3x) falls in the sum * of the two opposite strides and rises in neither. Run per vertex set (per LOD), measured on that LOD's own mesh, * after the other static-weight rules. Only JOINTS_n / WEIGHTS_n change. */ export interface HangingClothOptions { /** An edge stretched past this ratio in a stride marks the cloth around it for relaxing (default 2). */ tearRatio?: number; /** Surface distance around a torn triangle that is relaxed, at 1.70 m (default 0.2 m). */ reachM?: number; /** Relaxation rounds (each `iterationsPerRound` weighted-average sweeps) before giving up (default 30). */ rounds?: number; iterationsPerRound?: number; /** Cloth is only relaxed this far above the pelvis joint, at 1.70 m (default 0.05 m): a skirt, robe or tail hangs below the hips. */ aboveHipM?: number; /** Stride half-angle of the gate, degrees (default 50: a run's, wider than the walk's 35). */ strideDeg?: number; /** * Cloth more than `legMarginM` from every leg axis (a cape's tail, a skirt's flare, a coat tail) is not leg skin: up to * this share of its leg weight is handed to the pelvis, so it hangs from the hips instead of swinging with a leg * (default 0.6; 0 skips). Faded in over `pullFadeM`. */ freeHangShare?: number; legMarginM?: number; pullFadeM?: number; } export interface HangingClothReport { /** Vertices whose weights were relaxed (0 when nothing tore, or the result was not an improvement). */ vertices: number; /** Stride stretch (% of surface area with an edge over 3x), the two strides, before and after. */ before: [number, number]; after: [number, number]; /** Vertices (welded nodes) whose leg weight was partly handed to the pelvis because the cloth hangs free of the legs. */ pulled?: number; /** Why nothing was changed, when so. */ skipped?: string; } /** * Relax the weights of the cloth a stride tears. `w` is changed in place when (and only when) the result is an * improvement; the caller writes it back. */ export declare function relaxHangingCloth(model: SkinModel, set: VertexSet, w: Weights, options?: HangingClothOptions): HangingClothReport; export interface DocumentHangingClothOptions extends HangingClothOptions { /** Write the relaxed weights back (default true). `false` measures only. */ write?: boolean; } export interface DocumentHangingClothReport extends HangingClothReport { /** Vertex sets (one per skinned mesh) the stage looked at. */ sets: number; } /** * `relaxHangingCloth` over every skinned vertex set of one document, writing the result back. The importer relaxes the * full-resolution mesh once, but every LOD is then decimated from it, and a decimated mesh has fewer, longer edges * across the same weight seam: it tears in a stride where its source did not (2026-10-08, hosted critic: published * avatars whose LOD0 still carried 2% stride stretch although the stage had run on the source). So the importer calls * this on each LOD's own mesh as well. * * `vertices` and `pulled` are summed over the sets; `before` / `after` are the biggest set's, as `cleanStaticWeights` * reports them. */ export declare function relaxHangingClothInDocument(document: Document, options?: DocumentHangingClothOptions): DocumentHangingClothReport;