# @ferret/clothing: API

333 exports. Generated from the source (`packages/clothing/src`), so it matches the code.

## Classes

### ClothingService

*class* · `packages/clothing/src/service.ts:54`

```ts
class ClothingService implements Service
```

- `readonly name: "clothing"`
- `readonly dressed: Map<string, { meshes: Mesh[]; garments: DressedGarment[]; body: Mesh; indices: Uint32Array<ArrayBufferLike>; }>` — dressed entities: their garments' meshes and what they hid
- `init(world: World): void`
- `dress(a: DressRequest): { garments: { name: string; vertices: number; triangles: number }[]; hidden: number }`
- `undress(id: string): boolean`
- `dispose(): void`

### ClothMotion

*class* · `packages/clothing/src/motion.ts:130`

```ts
class ClothMotion
```

- `readonly positions: Float32Array` — vertices of the garment and the cloth positions of the last step (bind positions before the first one)
- `readonly indices: Uint32Array`
- `readonly skin: ClothSkin`
- `readonly drive: Float32Array` — per vertex: 1 follows the skin rigidly, 0 is free, between is the band
- `freeVertices: number` — number of vertices simulated (not rigid), of links, and the substeps the last frame used
- `linkCount: number`
- `lastSubsteps: number`
- `bodySurface: Surface | null` — the posed body's surface of the last step (what the cloth collided with)
- `readonly sim: ClothSim`
- `fade: number` — how much of the simulated cloth is shown: 0 only the skinned one, 1 only the simulated (a change of detail blends over fadeTime)
- `frame: number` — frames simulated since the last reset
- `constructor(garment: Pick<DressedGarment, 'positions' | 'indices'> & { garment?: { support?: unknown; cloth?: { density?: number; stretch?: number; bend?: number; thickness?: number; damping?: number; friction?: number } } }, body: ClothingBody, o: MotionOptions = {})`
- `substeps(): number` — the substeps a frame takes: the most the budget allows, 2 at least, and half at the reduced detail
- `setBudget(b: number | undefined): void`
- `setDetail(level: 0 | 1 | 2): void` — 0 the skinned garment only, 1 simulated with fewer substeps, 2 simulated (a rise from 0 starts the cloth from the skinned pose)
- `get detail(): number`
- `cost(): number` — work one frame costs now: links x substeps, 0 when only skinned
- `reset(): void` — back to the start: the cloth is the skinned garment at the next pose, at rest
- `asCollider(): MotionCollider` — the cloth of the last step as a collider for the garment over it
- `step(mats: ArrayLike<number>, dt = FIXED): Float32Array` — one frame of `dt` (the fixed step) with the body in the pose `mats`; the cloth is in `positions`
- `maxStretchNow(): number` — the longest edge of the simulated cloth now as a ratio of its length at rest (edges between two rigid vertices are the skin's, not the cloth's)
- `freeIndices(): Uint32Array` — the vertices that are not rigid (their bind-pose positions change when the cloth moves)
- `skinnedPositions(mats: ArrayLike<number>, out = this.skinnedAll): Float32Array` — the garment's vertices skinned only, in the pose of the last step (bind-pose positions of the rigid part, and of the rest by its weights)
- `positionsAtRest(): Float32Array`

### ClothMotionService

*class* · `packages/clothing/src/motion.ts:360`

```ts
class ClothMotionService implements Service
```

Cloth in motion in the world: the garments `ClothingService` has dressed, moved each fixed step by the animated skeleton. A vertex budget
and distances set the detail: the nearest garments are simulated until the budget of free vertices is spent, farther ones are only
skinned (what the dressing already gives them) and cost nothing. Everything is a command (`clothing.motion.*`).

- `readonly name: "clothing-motion"`
- `readonly moving: Map<string, Moving>`
- `budget: number` — free vertices that may be simulated at once, simulated within `near` metres of the camera (full) and `far` (half the substeps); beyond it skinned only
- `near: number`
- `far: number`
- `viewer: () => [number, number, number]` — the point distances are measured from (a camera); the world's origin until set
- `enabled: boolean`
- `init(world: World): void`
- `start(a: MotionRequest): { garments: { name: string; freeVertices: number; links: number }[] }`
- `stop(entity: string): boolean`
- `assign(): void` — which garments are simulated at what detail by distance and the vertex budget (nearest first)
- `fixedUpdate(dt: number): void` — Called before the components' fixed update, at the fixed rate.
- `stats(): { garment: string; entity: string; freeVertices: number; detail: number; substeps: number; stretch: number; distance: number }[]`
- `dispose(): void`

### ClothSim

*class* · `packages/clothing/src/sim.ts:16`

```ts
class ClothSim
```

The cloth solver: extended position-based dynamics with small steps (one iteration per substep,
many substeps), distance links with compliance (stretch, bending, seams, tacks), gravity, damping, and the collision of collide.ts: every substep the
cloth is tested against the surfaces (vertex-triangle, triangle-vertex, edge-edge, continuous, the side kept from the start of the substep,
friction) and, when `enableSelfCollision` is called, against itself. Deterministic.

Kept for the old drape (drape.ts, until step 6 of the plan removes it): `colliders`/`collidersT`/`torsoV`/`bodyOnly`/`bodyOnlyV` (they only choose,
per particle, which of the surfaces it sees), `findContacts`/`skipReset` (now no-ops: contacts are found per substep), `contact2`/`hasContact2` (second
planes set from outside, solved as before), `maxSpeed` (an optional limit, default none; the collision does not need it), `resolveInside`, `holdI`, `pin`.

- `readonly n: number`
- `readonly x: Float64Array`
- `readonly p: Float64Array`
- `readonly v: Float64Array`
- `readonly w: Float64Array`
- `li: number[]` — links: i, j, rest, compliance; rest may be changed (seams closing)
- `lj: number[]`
- `rest: number[]`
- `comp: number[]`
- `lambda: number[]`
- `pinI: number[]` — pins: particle i pulled to a fixed point (a waistband held up by braces, a cap on the head); compliance per pin
- `pinX: number[]`
- `pinC: number[]`
- `pinOn: number`
- `holdI: number[]` — height holds: particle i kept at height y (an edge that must not slide down while the seams close round it)
- `holdY: number[]`
- `pin(i: number, at: ArrayLike<number>, compliance: number): void`
- `seamLinks: number[]` — the links of the seams (indices) and how many extra iterations they get per substep
- `seamIters: number`
- `readonly world: CollisionWorld` — the collision world: surfaces added with `world.addStatic(surface, thickness, id)` are seen by every particle (see also `colliders`)
- `self: SelfCollider | null` — self collision of the cloth (null: off), see `enableSelfCollision`
- `colliders: Surface[]` — the surfaces (the first is the body: solid, closed, wound outward; the others are layers dressed before). They are registered in `world` at the next step.
- `collidersT: Surface[] | null` — colliders of the particles flagged in `torsoV` (when set)
- `torsoV: Uint8Array | null`
- `bodyOnly: boolean` — while `bodyOnly` is set the particles flagged in `bodyOnlyV` see only the first collider (the body)
- `bodyOnlyV: Uint8Array | null`
- `thickness: number` — distance the cloth keeps from the `colliders` (m)
- `friction: number` — friction of the cloth on the `colliders`
- `damping: number`
- `gravity: number`
- `maxSpeed: number` — optional speed limit, m/s. The collision is continuous and does not need it; the old drape uses it to hold the cloth still while it is sewn.
- `contactPasses: number` — rounds of contact projection per substep
- `collideRounds: number` — rounds of (find contacts, project them) per substep: a later round finds what the earlier ones moved into
- `contact2: Float64Array` — second contact planes (a panel lying over another panel of the same garment): point, normal, per particle; set from outside each frame (old drape)
- `hasContact2: Uint8Array`
- `lastContacts: number` — contacts found in the last substep
- `constructor(positions: ArrayLike<number>, masses: ArrayLike<number>)`
- `link(i: number, j: number, rest: number, compliance: number): number`
- `drag: { normal: number; tangent: number } | null` — air drag on the cloth's triangles (set by `applyFabric`; needs `setTriangles`): normal and tangent coefficients, and the air's velocity
- `wind: [number, number, number]`
- `airDensity: number`
- `applyFabric(p: FabricPhysics): void` — Take the fabric's measured values: thickness (the distance kept from surfaces and from itself), friction on the skin (the first collider, the body) and on cloth (the other colliders and itself), and the air drag. Mass per area and the link compliances belong to whoever builds the links.
- `skinFriction: number | null` — friction on the first collider (the body) when it differs from `friction` (set by `applyFabric`)
- `setTriangles(idx: ArrayLike<number>): void` — the cloth's triangles: they give the edges for the edge-edge tests and the triangles for the tests of the surfaces' vertices (without them only the cloth's vertices are tested)
- `enableSelfCollision(idx: ArrayLike<number>, glue: ArrayLike<readonly [number, number]> = [], thickness = 0.002, friction = 0.3): SelfCollider` — switch the cloth's collision with itself on; `glue`: pairs of particles that are one point (the two sides of a seam)
- `findContacts(_reach?: number): void` — old API of the drape: contacts are found per substep now, nothing is searched per frame
- `skipReset(): void`
- `step(dt: number, sub: number): void` — one frame of `dt` seconds in `sub` substeps
- `resolveInside(reach: number, maxMove = Infinity): number` — old API of the drape: push every particle out of the colliders along the nearest normal (after the run). A post pass; the new dressing does not use it.

### CollisionWorld

*class* · `packages/clothing/src/collide.ts:261`

```ts
class CollisionWorld
```

The surfaces cloth collides with. `addStatic(surface, thickness, id)`; an animated body is moved between frames by writing the surface's `pos`
(or `moveStatic`): `beginFrame()` finds it out, and during the frame the surface goes linearly from where it was to the new place.
Per substep `update(positionsPrev, positionsNext, invMass) -> ContactSet` of the contacts to be solved on the predicted positions.
At most 32 static surfaces (a particle's view of them is a 32-bit mask): the body and the layers of one outfit are far fewer.
`setTriangles` gives the cloth's triangles (the edges for the edge tests and the triangles for the tests of the surface's vertices).

- `readonly statics: Static[]`
- `friction: number`
- `skin: number` — extra distance round the motion of an item that its candidate list covers (m): a list is rebuilt when the item leaves it
- `rescue: number` — how deep inside a solid surface a vertex is still pushed out (m)
- `readonly contacts: ContactSet`
- `readonly stats: { vertexTri: number; triVertex: number; edgeEdge: number; contacts: number; updates: number; }` — machine-independent work counters since the last `resetStats()`: narrow-phase pair tests (cloth vertex/surface triangle, surface vertex/cloth triangle, cloth edge/surface edge), contacts produced, update calls
- `resetStats(): void`
- `commit(p: Float64Array): void` — call at the end of each substep with the final positions: the particles that were tested move their anchors to where they are
- `addStatic(surface: Surface, thickness: number, id: string, opts: StaticOptions = {}): number`
- `removeStatic(id: string): void`
- `getStatic(id: string): { surface: Surface; thickness: number; friction: number; k: number } | undefined`
- `moveStatic(id: string, positions: ArrayLike<number>): void` — move a static surface to new positions (takes effect with the next `beginFrame`)
- `moveStaticSkinned(id: string, rest: ArrayLike<number>, joints: ArrayLike<number>, weights: ArrayLike<number>, matrices: ArrayLike<number>): void` — Move a static surface by skeleton matrices (linear blend skinning), for an animated body: `rest` are the vertex positions in the bind pose (3 per vertex), `joints`/`weights` 4 per vertex, `matrices` 16 numbers per joint, column-major, each already multiplied by the joint's inverse bind matrix (the matrix that takes a bind-pose point to its place now). Takes effect with the next `beginFrame`.
- `setTriangles(idx: ArrayLike<number>): void` — the cloth's triangles (3 indices each): the edges and the triangles the surfaces' vertices are tested against
- `get triangles(): Uint32Array` — the cloth's triangles as given to `setTriangles`
- `get triangleCount(): number`
- `beginFrame(): void` — call once per frame before its substeps: finds the surfaces that moved since the last frame and prepares their boxes and bins
- `endFrame(): void` — call once per frame after its substeps
- `vertexContacts(x: Float64Array, p: Float64Array, w: Float64Array, a: number, b: number, tau0: number, tau1: number, mask: Uint32Array | null, out: ContactSet): void` — Pure range search (for parallel workers): the contacts of cloth vertices [a, b) with the surfaces' triangles on the motion x -> p of one substep (typed arrays in, `out` appended; the surfaces and `setTriangles` data are only read; the only state written is the per-vertex candidate list of the vertices in the range, so disjoint ranges on separate CollisionWorld copies, or on one for ranges that do not overlap, never interfere). `mask`: per particle bit mask of the statics it sees (null: all). One contact per vertex and surface: the most violated.
- `update(x: Float64Array, p: Float64Array, w: Float64Array, opts: UpdateOptions = {}): ContactSet` — Contacts for one substep: particle i goes from x[i] (start) to p[i] (predicted). Particles with w[i] = 0 are fixed. Appended to `out` after it is cleared.

### ContactSet

*class* · `packages/clothing/src/collide.ts:24`

```ts
class ContactSet
```

a list of contact constraints: C = dir . (sum om[k] p[m[k]]) - off, kept >= 0

- `n: number`
- `m: Int32Array<ArrayBuffer>`
- `om: Float64Array<ArrayBuffer>`
- `dir: Float64Array<ArrayBuffer>`
- `off: Float64Array<ArrayBuffer>`
- `mu: Float64Array<ArrayBuffer>`
- `sv: Float64Array<ArrayBuffer>`
- `clear(): void`
- `addFrom(o: ContactSet, i: number): void` — append contact i of another set
- `appendFrom(o: ContactSet): void`
- `keepFrom(o: ContactSet, skip: Uint8Array): void` — append the contacts of another set none of whose particles is flagged in `skip`
- `add(m0: number, m1: number, m2: number, m3: number, o0: number, o1: number, o2: number, o3: number, dx: number, dy: number, dz: number, off: number, mu: number, sx = 0, sy = 0, sz = 0): void` — a constraint over up to 4 particles (-1 ends the list); `sv` is the motion of the surface point during the substep (friction is taken relative to it)
- `set(i: number, m0: number, m1: number, m2: number, m3: number, o0: number, o1: number, o2: number, o3: number, dx: number, dy: number, dz: number, off: number, mu: number, sx = 0, sy = 0, sz = 0): void` — overwrite contact i (used to keep the most violated of several contacts of one vertex with one surface)
- `solve(p: Float64Array, x: Float64Array, w: Float64Array, passes = 2): number` — Project the contacts on the predicted positions `p` (particle k has inverse mass w[k]; x are the positions at the start of the substep, for friction): `passes` rounds; in the first the tangential motion of a violated contact is cut by mu * depth. Returns the contacts violated in the first round.

### DescribeError

*class* · `packages/clothing/src/describe.ts:33`

```ts
class DescribeError extends Error
```

- `issues: DescribeIssue[]`
- `constructor(issues: DescribeIssue[])`

### FolderBackend

*class* · `packages/clothing/src/cache.ts:344`

```ts
class FolderBackend implements StoreBackend
```

- `readonly readOnly: false`
- `constructor(private io: FolderIO)`
- `get(n: string)`
- `put(n: string, b: Uint8Array)`
- `async has(n: string)`
- `async list()`
- `delete(n: string)`

### MemoryBackend

*class* · `packages/clothing/src/cache.ts:327`

```ts
class MemoryBackend implements StoreBackend
```

- `readonly readOnly: false`
- `readonly files: Map<string, Uint8Array<ArrayBufferLike>>`
- `async get(n: string)`
- `async put(n: string, b: Uint8Array)`
- `async has(n: string)`
- `async list()`
- `async delete(n: string)`

### Narrow

*class* · `packages/clothing/src/collide.ts:89`

```ts
class Narrow
```

The narrow phase tests, on the motion of one substep. Inputs are set in the arrays (T: triangle, E and F: two edges; index 0 at the start of the
substep, 1 at its end); results are `dir` (the direction away from the other surface, unit), `w` (barycentric weights on the triangle),
`q` (the point of the other surface at the end), `s` and `t` (the parameters on the edges).

- `readonly T0: Float64Array<ArrayBuffer>`
- `readonly T1: Float64Array<ArrayBuffer>`
- `readonly E0: Float64Array<ArrayBuffer>`
- `readonly E1: Float64Array<ArrayBuffer>`
- `readonly F0: Float64Array<ArrayBuffer>`
- `readonly F1: Float64Array<ArrayBuffer>`
- `readonly dir: Float64Array<ArrayBuffer>`
- `readonly w: Float64Array<ArrayBuffer>`
- `readonly q: Float64Array<ArrayBuffer>`
- `s: number`
- `t: number`
- `vertexTri(x0x: number, x0y: number, x0z: number, x1x: number, x1y: number, x1z: number, th: number, solid: boolean, surf: Surface | null, ia: number, ib: number, ic: number, reach: number): boolean` — a point (x0 -> x1) against the triangle T0 -> T1. th: thickness; solid: the triangle belongs to a closed surface wound outward (whatever is inside is pushed out, up to `reach` deep); `surf` and ia, ib, ic: the surface and the triangle's vertices (its smooth normals decide the side at an edge or a corner; null: the face normal). true when the point must be held (a crossing, or nearer than `th`).
- `edgeEdge(th: number): boolean` — edge E (E0 -> E1: both end points at the start and at the end) against edge F. Handles the crossing of two edges and the closeness of their inner points (an end point against an edge is a vertex-triangle case). s, t: parameters on E and F at the end; dir: from F to E; q: the point of F.

### OutfitStore

*class* · `packages/clothing/src/cache.ts:377`

```ts
class OutfitStore
```

- `constructor(readonly backend: StoreBackend)`
- `async has(key: string): Promise<boolean>`
- `async getBytes(key: string): Promise<Uint8Array | undefined>`
- `async get(key: string): Promise<OutfitRecord | undefined>`
- `async put(key: string, rec: OutfitRecord): Promise<void>`
- `async list(): Promise<string[]>` — keys, sorted
- `async drop(key: string): Promise<void>`
- `async addAnim(key: string, a: CachedAnim): Promise<void>` — add the baked animation of one garment and clip to a stored record
- `async assign(characterId: string, outfitId: string, key: string, fit: Record<string, unknown> = {}): Promise<void>`
- `async unassign(characterId: string, outfitId: string): Promise<void>`
- `async forCharacter(characterId: string, outfitId: string): Promise<MapEntry | undefined>`
- `async loadFor(characterId: string, outfitId: string): Promise<(MapEntry & { record: OutfitRecord }) | undefined>` — the entry and its record
- `async assignments(): Promise<{ characterId: string; outfitId: string; key: string; fit: Record<string, unknown> }[]>` — every assignment, sorted
- `async dangling(): Promise<{ characterId: string; outfitId: string; key: string }[]>` — assignments whose record is not stored
- `once<T>(key: string, make: () => Promise<T>): Promise<T>`

### PackageBackend

*class* · `packages/clothing/src/cache.ts:357`

```ts
class PackageBackend implements StoreBackend
```

a store packed into a Ferret package under `prefix` (default `outfits/`), read only: what the game opens at run time

- `readonly readOnly: true`
- `constructor(private pkg: PackageFiles, private prefix = 'outfits/')`
- `async get(n: string)`
- `async put(): Promise<void>`
- `async has(n: string)`
- `async list()`
- `async delete(): Promise<void>`

### SelfCollider

*class* · `packages/clothing/src/collide.ts:525`

```ts
class SelfCollider
```

a cloth's collision with itself

- `thickness: number` — the cloth keeps this far from itself
- `friction: number`
- `skin: number` — Verlet skin (m)
- `readonly n: number`
- `builds: number` — how many times the pair lists were rebuilt (tests and the speed report read it)
- `constructor(n: number, idx: ArrayLike<number>, glue: ArrayLike<readonly [number, number]> = [])`
- `near(a: number, b: number): boolean` — are a and b in the same patch of the cloth (left out of each other's tests)?
- `update(x: Float64Array, p: Float64Array, w: Float64Array, out: ContactSet): void` — the contacts of the cloth with itself for one substep (appended to `out`)

### Sha256Stream

*class* · `packages/clothing/src/cache.ts:42`

```ts
class Sha256Stream
```

an incremental SHA-256 (synchronous, so the key is made the same in Node, a browser and a worker)

- `update(data: Uint8Array): this`
- `hex(): string`

### Surface

*class* · `packages/clothing/src/body.ts:91`

```ts
class Surface
```

A triangle surface to collide with: closest point on its triangles to a point, with the side (outside along the interpolated vertex
normal). Triangles are binned in a grid; a query looks at the cells within `reach`.

- `readonly normals: Float32Array`
- `pos: Float32Array` — the positions the queries use (may be moved: a body shrunk for the start of a drape, then grown back)
- `constructor(readonly base: Float32Array, readonly idx: Uint32Array, cell = 0.03)`
- `core: Float32Array | null` — points every vertex shrinks toward (its bones' axes), see `shrinkTargets`
- `shrinkTo(k: number): void` — scale the surface toward its core: 1 = as it is, 0.4 = limbs at 40 % of their thickness round the bones (no surface turns inside out)
- `inflate(d: number): void` — move every vertex `d` metres along its normal from the base (negative: inward)
- `closest(x: number, y: number, z: number, reach: number, out: SurfaceHit): boolean` — closest point within `reach`: { d: signed distance (+ outside), p, n (outward), t (triangle), w (barycentric) } or null
- `triBox(): Float32Array` — per-triangle boxes x0,y0,z0,x1,y1,z1 (of `pos`; after `refit(from)` of `from` and `pos` together, so they hold for the whole move)
- `refit(from?: ArrayLike<number>): void` — The surface has moved (`pos` changed; or the first call): recompute the normals, the triangle boxes and the grid. With `from` (where it was) the boxes and bins cover `from` and `pos` together, so a query finds every triangle at every instant of the move.
- `updateNormals(): void` — vertex normals of `pos`, in place
- `collectBox(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number, out: number[]): void` — push into `out` the triangles whose box overlaps the box x0..x1 (after `refit`; in a fixed order)
- `rim(h: SurfaceHit): boolean` — Is the closest point of `h` on a free edge of the surface (the rim of a waist or a hem; seams that share positions are not free)? A cloth vertex whose nearest point is a rim has gone past the end of the surface: the rim's plane must not hold it (it would lift the cloth over a waist).

## Functions

### add

*function* · `packages/clothing/src/body.ts:28`

```ts
function add: (a: V3, b: V3) => V3
```

### animToBaked

*function* · `packages/clothing/src/bake.ts:166`

```ts
function animToBaked(a: CachedAnim): BakedCloth
```

the baked cloth of an animation slot (`getAnim`); throws when the slot holds another kind

### armGirth

*function* · `packages/clothing/src/parts/util.ts:34`

```ts
function armGirth(m: Measurements, U: UpperFrame, s: number): number
```

the arm's girth at the distance s along it from the shoulder joint (upper arm, elbow, wrist)

### armholeDrop

*function* · `packages/clothing/src/blocks/ease.ts:46`

```ts
function armholeDrop(kind: HoldKind, thickness: number, sleeveless: boolean): number
```

the depth of the armhole below the sleeve root, beyond the body's armpit, metres: a hung garment's armhole is cut lower (it hangs off the shoulder and the arm lifts it), a sleeveless one is cut away, and every layer under needs the room of its sleeve

### armPath

*function* · `packages/clothing/src/blocks/common.ts:42`

```ts
function armPath(U: UpperFrame, sx: 1 | -1, back = 0.03): V3[]
```

the arm's own path: from `back` metres above the shoulder joint (along the upper arm) through the elbow to the wrist

### bakeClip

*function* · `packages/clothing/src/bake.ts:88`

```ts
function bakeClip(garment: Pick<DressedGarment, 'positions' | 'indices'> & { name?: string; garment?: unknown }, body: ClothingBody, clip: PoseSource, o: BakeOptions = {}): BakedCloth
```

Bake `garment` over `clip`: the cloth is simulated at 60 Hz with the pose stepping through the clip, after warm-up cycles (so the first
frame is the cloth in its steady state of the motion), and every 60/fps-th step is stored. For a loop the start is blended into the
continuation of the end, so the last frame is followed by the first without a jump.

### bakedToAnim

*function* · `packages/clothing/src/bake.ts:162`

```ts
function bakedToAnim(b: BakedCloth): CachedAnim
```

a baked cloth as the outfit record's animation slot (`setAnim`; the slot is keyed by clip and garment name, as the block names them)

### bakeFabricTile

*function* · `packages/clothing/src/fabric.ts:219`

```ts
function bakeFabricTile(f: FabricSpec, size = 1, pxPerMeter = 2048): { width: number; height: number; albedo: Uint8Array; normal: Uint8Array; orm: Uint8Array }
```

a flat tile of a fabric `size` metres square at `pxPerMeter`, baked as a garment panel is (for looking at a fabric on its own)

### bakeGarment

*function* · `packages/clothing/src/fabric.ts:231`

```ts
function bakeGarment(d: DressedGarment, o: TextureBakeOptions): BakedGarment
```

bake a dressed garment's textures: albedo, normal, ORM, with the seams, hems and buttonholes

### ballJoint

*function* · `packages/clothing/src/body.ts:66`

```ts
function ballJoint(body: ClothingBody, side: 1 | -1): V3
```

the ball of the foot; a rig without one gets a point 14 cm in front of the ankle, 4 cm above the floor (the lowest vertex)

### beanie

*function* · `packages/clothing/src/blocks/hats.ts:70`

```ts
function beanie(body: ClothingBody, m: Measurements, s: BeanieStyle = {}): Garment
```

### belt

*function* · `packages/clothing/src/blocks/accessories.ts:163`

```ts
function belt(body: ClothingBody, m: Measurements, s: BeltStyle = {}): Garment
```

A belt or sash: a stiff band closed into a ring at the waist over what is worn there, held at the waist, with a buckle at the centre front.

### blockSpec

*function* · `packages/clothing/src/catalog.ts:332`

```ts
function blockSpec(name: string): BlockSpec | undefined
```

the block's spec, or undefined

### bodyFit

*function* · `packages/clothing/src/fit.ts:41`

```ts
function bodyFit(body: ClothingBody, m: Measurements): BodyFit
```

### bodyFromMesh

*function* · `packages/clothing/src/babylon.ts:11`

```ts
function bodyFromMesh(mesh: BABYLON.Mesh): ClothingBody
```

The engine side of clothes: a skinned Babylon mesh as a clothing body (its bind pose, its skin, its skeleton's bone
names and rest positions), and a dressed garment as a Babylon mesh skinned to the same skeleton, with its baked textures.

### bodyGirth

*function* · `packages/clothing/src/parts/ctx.ts:85`

```ts
function bodyGirth(m: Measurements, y: number): number
```

the body's girth at a world height (chest above the chest line, then the waist, the seat, held below)

### bodyKey

*function* · `packages/clothing/src/cache.ts:125`

```ts
function bodyKey(body: ClothingBody): string
```

the key of the body alone (a character's identity for the cache; its mesh, skin, joints and rig hints)

### bodyRig

*function* · `packages/clothing/src/body.ts:45`

```ts
function bodyRig(body: ClothingBody): RigMap
```

the roles of the body's joints (resolved once per body)

### bodyZ

*function* · `packages/clothing/src/parts/ctx.ts:92`

```ts
function bodyZ(m: Measurements, y: number): number
```

z of the body's centre at a world height

### boots

*function* · `packages/clothing/src/footwear.ts:23`

```ts
function boots(body: ClothingBody, s: BootStyle = {}): Boots
```

### breeches

*function* · `packages/clothing/src/blocks/breeches.ts:24`

```ts
function breeches(body: ClothingBody, m: Measurements, s: BreechesStyle = {}): Garment
```

### brimmedHat

*function* · `packages/clothing/src/blocks/hats.ts:37`

```ts
function brimmedHat(body: ClothingBody, m: Measurements, s: BrimmedHatStyle = {}): Garment
```

### brodyHelmet

*function* · `packages/clothing/src/blocks/accessories.ts:100`

```ts
function brodyHelmet(body: ClothingBody, m: Measurements, s: BrodyHelmetStyle = {}): Garment
```

The Brodie steel helmet: a dome of six gores (the developable pattern of a sphere, each gore a lens) and a down-sloping brim of six sectors
(a cone frustum), pressed steel, so every piece has the bending stiffness of steel; the optional chin strap hangs from the brim on each side and
is joined under the chin. It sits on the head by the dome's rim.

### buildUpper

*function* · `packages/clothing/src/parts/style.ts:84`

```ts
function buildUpper(body: ClothingBody, m: Measurements, st: UpperStyle = {}, d: UpperDefaults): Garment
```

the defaults of a garment with the style over them -> the garment

### button

*function* · `packages/clothing/src/trims.ts:35`

```ts
function button(at: { p: V3; n: V3; v: number }, o: { name?: string; size?: number; style?: 'horn' | 'brass'; material?: string } = {}): TrimMesh
```

a button on the cloth: a rim, a dished face, four holes (horn) or a domed face (brass, with the anchor in its normal map)

### buttonFace

*function* · `packages/clothing/src/trims.ts:102`

```ts
function buttonFace(style: 'horn' | 'brass', size = 256): { albedo: Uint8Array; normal: Uint8Array; orm: Uint8Array }
```

a button's face texture (RGBA, `size` square): brass with a fouled anchor raised in its height, or horn with four holes; height in A

### cap

*function* · `packages/clothing/src/blocks/headwear.ts:22`

```ts
function cap(body: ClothingBody, m: Measurements, s: CapStyle = {}): Garment
```

### capCrown

*function* · `packages/clothing/src/parts/sleeves.ts:113`

```ts
function capCrown(lF: number, lB: number, wt: number, Lcut: number, setting: number): { Lu: number; h: number; xa: number; cf: V2[]; cb: V2[] }
```

The crown of a set-in sleeve of width `wt` (the sleeve's flat top, round the upper arm) whose seam length is the front armhole `lF` and the back
armhole `lB` each plus `setting` (the fraction): the crown's height `h` and the slide `xa` of its apex toward the longer half are solved, the
cap lies on the sleeve from the height `Lu = Lcut - h` up. Returns the two cap edges (front from the sleeve's front corner, back to its back corner).

### catalogInfo

*function* · `packages/clothing/src/catalog.ts:335`

```ts
function catalogInfo(): Record<string, { implemented: boolean; description: string; defaultFabric: string; options: Record<string, { type: string; values?: string[]; min?: number; max?: number; unit?: string; description: string }> }>
```

a plain-data copy of the registry (no functions) for commands and docs

### clipPoseSource

*function* · `packages/clothing/src/bake.ts:60`

```ts
function clipPoseSource(body: ClothingBody, clip: ClipJson, rest: Rest): PoseSource
```

the skinning matrices of a clip of the animation package on `body` (its joints named as the clip's bones; `rest` is the skeleton's rest pose in the body's frame)

### cloak

*function* · `packages/clothing/src/blocks/cloak.ts:30`

```ts
function cloak(body: ClothingBody, m: Measurements, s: CloakStyle = {}): Garment
```

### closestOnTri

*function* · `packages/clothing/src/body.ts:227`

```ts
function closestOnTri(px: number, py: number, pz: number, ax: number, ay: number, az: number, bx: number, by: number, bz: number, cx: number, cy: number, cz: number, out: Float64Array): void
```

closest point of triangle abc to p (Ericson), with its barycentric weights: out = [x, y, z, wa, wb, wc]

### coat

*function* · `packages/clothing/src/blocks/coat.ts:13`

```ts
function coat(body: ClothingBody, m: Measurements, s: CoatStyle = {}): Garment
```

### composeUpper

*function* · `packages/clothing/src/parts/compose.ts:47`

```ts
function composeUpper(body: ClothingBody, m: Measurements, s: UpperSpec): Garment
```

### convexHull

*function* · `packages/clothing/src/body.ts:292`

```ts
function convexHull(p: [number, number][]): [number, number][]
```

### cross

*function* · `packages/clothing/src/body.ts:31`

```ts
function cross: (a: V3, b: V3) => V3
```

### curve

*function* · `packages/clothing/src/pattern.ts:205`

```ts
function curve(ctrl: V2[], n = 8): V2[]
```

a smooth curve through control points (Catmull-Rom), `n` points per span

### dartLegs

*function* · `packages/clothing/src/fit.ts:96`

```ts
function dartLegs(d: Dart, dir: V2): [V2, V2]
```

the two legs' base points of a dart whose base lies on an edge running along `dir` (unit, 2D)

### darts

*function* · `packages/clothing/src/fit.ts:118`

```ts
function darts(m: Measurements, style: DartStyle = 'fitted', o: { fit?: BodyFit; region?: 'bodice' | 'skirt'; easeBust?: number; easeWaist?: number; easeHip?: number } = {}): DartPlan
```

The darts a bodice takes from its bust to its waist (`region: 'bodice'`, default) or a skirt from its hip to its waist (`'skirt'`; the
darts are then shorter and there is no bust dart). About half of the shaping goes into darts, the rest into the side seams; `style`
scales it: fitted all, semi 0.55, shift 0.2, none nothing. The eases are the finished garment's (see `ease`).

### decodeOutfit

*function* · `packages/clothing/src/cache.ts:276`

```ts
function decodeOutfit(bytes: Uint8Array): OutfitRecord
```

### delaunay

*function* · `packages/clothing/src/pattern.ts:290`

```ts
function delaunay(p: V2[]): [number, number, number][]
```

Bowyer-Watson Delaunay triangulation of a point set

### describe

*function* · `packages/clothing/src/describe.ts:358`

```ts
function describe(input: string | Record<string, unknown> | unknown[], opts: DescribeOptions = {}): Description
```

Describe garments in words or in the structured form.
- text: "blue denim shorts", "a long single-breasted wool overcoat with notched lapels and flap pockets", "красное шёлковое платье с короткими рукавами"
- JSON (a string starting with `{` or `[`, or the object): `{garments: [{block, style?, fabric?, color?}], fabrics?: {key: FabricSpec | {fabric, color?}}}`
Throws `DescribeError` (its `issues` name the fields) when the text names no garment or the JSON is not valid.

### dot

*function* · `packages/clothing/src/body.ts:30`

```ts
function dot: (a: V3, b: V3) => number
```

### draftClosure

*function* · `packages/clothing/src/parts/closures.ts:32`

```ts
function draftClosure(ctx: UpperCtx, spec: ClosureSpec): ClosureDraft
```

### draftCollar

*function* · `packages/clothing/src/parts/collars.ts:54`

```ts
function draftCollar(ctx: UpperCtx, spec: CollarSpec): NeckDraft
```

### draftHood

*function* · `packages/clothing/src/parts/hood.ts:33`

```ts
function draftHood(ctx: UpperCtx, spec: HoodSpec, ring: NeckRing, nd: number): Piece
```

### draftPockets

*function* · `packages/clothing/src/parts/pockets.ts:23`

```ts
function draftPockets(ctx: UpperCtx, specs: PocketSpec[]): Piece
```

### draftSleeve

*function* · `packages/clothing/src/parts/sleeves.ts:49`

```ts
function draftSleeve(ctx: UpperCtx, spec: SleeveSpec): SleeveDraft
```

### drape

*function* · `packages/clothing/src/drape.ts:79`

```ts
function drape(body: ClothingBody, garments: Garment[], o: DrapeOptions = {}): DressedGarment[]
```

dress the garments in order of their layer, each settling over the body and those before it

### dress

*function* · `packages/clothing/src/blocks/dress.ts:35`

```ts
function dress(body: ClothingBody, m: Measurements, s: DressStyle = {}): Garment
```

### dressCached

*function* · `packages/clothing/src/cache.ts:457`

```ts
async function dressCached(body: ClothingBody, garments: Garment[], options: { fabrics?: Record<string, unknown> } & Record<string, unknown>, store: OutfitStore, dress: Dresser): Promise<{ key: string; record: OutfitRecord; hit: boolean }>
```

The outfit of these garments on this body: from the store when its key is there, else dressed by `dress` and put. `options` holds the
fabrics (`options.fabrics`, if any) and everything else the dressing reads; all of it is in the key. A read-only store that misses throws.

### dressGarment

*function* · `packages/clothing/src/dress.ts:129`

```ts
function dressGarment(sewn: SewnGarment, body: ClothingBody, layersBelow: LayerBelow[] = [], o: DressOptions = {}): DressedCloth
```

Put a sewn garment on the body over `layersBelow` (the layers dressed before it, lower first) and let it settle. Deterministic.
The garment must have been sewn with the same body's measurements (its pattern already has the ease for the layers under it).

### ease

*function* · `packages/clothing/src/fit.ts:87`

```ts
function ease(fitting: Fitting, fit?: Pick<BodyFit, 'childness'>): { bust: number; waist: number; hip: number }
```

Ease in metres of girth over the body at the bust, the waist and the hip for a fitting; a child's figure is straighter, and a child
grows, so it gets a little more room.

### emptyOutfit

*function* · `packages/clothing/src/cache.ts:204`

```ts
function emptyOutfit(key: string, meta: Record<string, unknown> = {}): OutfitRecord
```

### encodeOutfit

*function* · `packages/clothing/src/cache.ts:252`

```ts
function encodeOutfit(rec: OutfitRecord): Uint8Array
```

### fabricAt

*function* · `packages/clothing/src/fabric.ts:66`

```ts
function fabricAt(f: FabricSpec, x: number, y: number, px: number, panel = '', py = y): { h: number; shade: number; rough: number; mix?: number }
```

The relief of a fabric at a flat point: height (metres) and a colour factor (thread shade), filtered for the pixel size `px` (metres):
structure finer than two pixels fades to its mean so the bake does not alias.

### fabricFor

*function* · `packages/clothing/src/fabrics.ts:110`

```ts
function fabricFor(name: string, color?: number | RGB | string): { name: string; spec: FabricSpec; cloth: ClothProps }
```

the fabric `name` (or a word that names it) with an optional colour (sRGB hex number, linear RGB triple, or a colour word); copies, never the catalogue's own objects

### findColor

*function* · `packages/clothing/src/fabrics.ts:101`

```ts
function findColor(word: string): number | undefined
```

a colour word to its hex: an exact word, or a Russian stem the word starts with (the longest stem wins)

### findFabric

*function* · `packages/clothing/src/fabrics.ts:94`

```ts
function findFabric(name: string): CatalogFabric | undefined
```

a fabric by exact name, or by one of its words

### foldShade

*function* · `packages/clothing/src/fabric.ts:335`

```ts
function foldShade(pos: ArrayLike<number>, nrm: ArrayLike<number>, idx: ArrayLike<number>, strength = 1): Float32Array
```

per vertex darkening in the folds (concave places, from the mesh's own curvature): a colour multiplier 0..1

### garmentMesh

*function* · `packages/clothing/src/babylon.ts:30`

```ts
function garmentMesh(scene: BABYLON.Scene, d: DressedGarment, baked: BakedGarment, skin: ClothSkin, skeleton: BABYLON.Skeleton | null, fabric?: FabricSpec): BABYLON.Mesh
```

a dressed garment as a mesh skinned to `skeleton` (bone indices as in the body), its atlas as textures, wool sheen when the fabric has it

### garmentRecord

*function* · `packages/clothing/src/cache.ts:209`

```ts
function garmentRecord(d: DressedGarment, o: { skin: ClothSkin; uv: ArrayLike<number>; texture?: CachedTexture; material?: Record<string, unknown> }): CachedGarment
```

a record garment from a dressed one, its skin and its baked atlas (`uv` as `bakeGarment` gives it)

### getAnim

*function* · `packages/clothing/src/cache.ts:236`

```ts
function getAnim(rec: OutfitRecord, clip: string, garment: string): CachedAnim | undefined
```

### girthAt

*function* · `packages/clothing/src/body.ts:270`

```ts
function girthAt(body: ClothingBody, y: number, band = 0.01, keep: (x: number, z: number) => boolean = () => true): { girth: number; cx: number; cz: number; depth: number; width: number }
```

convex girth of the cross-section of the body at height y (only vertices within `band` of y, kept by `keep`)

### gloves

*function* · `packages/clothing/src/blocks/gloves.ts:95`

```ts
function gloves(body: ClothingBody, s: GloveStyle = {}): Gloves
```

### handDigits

*function* · `packages/clothing/src/blocks/gloves.ts:34`

```ts
function handDigits(body: ClothingBody, side: 1 | -1): { hand: V3; digits: Digit[]; axis: V3; palmLen: number }
```

the digits of the hand on `side` (1: left): from the skeleton's tree under the hand joint

### hashCanonical

*function* · `packages/clothing/src/cache.ts:96`

```ts
function hashCanonical(h: Sha256Stream, v: unknown, path = '$'): void
```

The canonical form of a value, fed to the hash: object keys sorted (their order does not matter), `undefined` fields left out, numbers by
their shortest round-trip text (-0 is 0), typed arrays by their bytes (little endian) with their kind, Maps by sorted keys. A function or
a non-finite-safe unknown thing throws: it has no stable form.

### hashOf

*function* · `packages/clothing/src/cache.ts:122`

```ts
function hashOf(v: unknown): string
```

the hash of a value in its canonical form, hex

### hasJoint

*function* · `packages/clothing/src/body.ts:40`

```ts
function hasJoint(body: ClothingBody, name: string): boolean
```

### hasRole

*function* · `packages/clothing/src/body.ts:50`

```ts
function hasRole(body: ClothingBody, role: BoneRole): boolean
```

### hemAt

*function* · `packages/clothing/src/parts/style.ts:58`

```ts
function hemAt(body: ClothingBody, m: Measurements, length: UpperHemName | number): number
```

the world height of a named hem, or `length` metres below the shoulder point

### hemHeight

*function* · `packages/clothing/src/blocks/skirt.ts:43`

```ts
function hemHeight(m: Measurements, name: HemName): number
```

the hem height above the floor for a named length

### hemLine

*function* · `packages/clothing/src/parts/hems.ts:48`

```ts
function hemLine(x0: number, x1: number, rise: number, w: number): V2[]
```

a plain hem line across a half panel from x0 to x1, curved up at the ends by `rise`

### hex

*function* · `packages/clothing/src/fabrics.ts:23`

```ts
function hex(h: number): RGB
```

sRGB hex to linear RGB

### hiddenBody

*function* · `packages/clothing/src/transfer.ts:54`

```ts
function hiddenBody(body: ClothingBody, garments: Pick<DressedGarment, 'positions' | 'indices'>[], o: { reach?: number; inset?: number; tris?: [number, number] } = {}): Uint8Array
```

Body triangles hidden under the garments: a triangle is hidden when each of its corners has cloth over it (a garment surface within
`reach` outward) and that cloth is at least `inset` metres in from the garment's open edges (cuffs, hems, the neckline stay open to see).

### hoodie

*function* · `packages/clothing/src/blocks/hoodie.ts:12`

```ts
function hoodie(body: ClothingBody, m: Measurements, s: HoodieStyle = {}): Garment
```

### interlining

*function* · `packages/clothing/src/blocks/ease.ts:81`

```ts
function interlining: (what: "collar stand" | "collar fall" | "lapel" | "waistband" | "cuff" | "brim" | "band" | "flap" | "facing" | "crown" | "shell" | "belt") => number
```

### isKnit

*function* · `packages/clothing/src/blocks/ease.ts:27`

```ts
function isKnit: (c?: ClothProps | undefined) => boolean
```

a cloth that stretches (a knit) rather than a woven one

### jacket

*function* · `packages/clothing/src/blocks/jacket.ts:37`

```ts
function jacket(body: ClothingBody, m: Measurements, s: JacketStyle = {}): Garment
```

### jersey

*function* · `packages/clothing/src/blocks/jersey.ts:30`

```ts
function jersey(body: ClothingBody, m: Measurements, s: JerseyStyle = {}): Garment
```

### joint

*function* · `packages/clothing/src/body.ts:35`

```ts
function joint(body: ClothingBody, name: string): V3
```

### layerGirth

*function* · `packages/clothing/src/blocks/ease.ts:24`

```ts
function layerGirth: (t: number) => number
```

the girth a thickness `t` of layers under a garment adds to it, metres

### legBlock

*function* · `packages/clothing/src/blocks/shorts.ts:41`

```ts
function legBlock(body: ClothingBody, m: Measurements, s: LegBlockStyle): Garment
```

