# @ferret/destruction: API

things that break by physics or by a style of their own: crush zones, glass, wood, stone, links, cars, debris, energy ledger, replication by seed.

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

## Classes

### Assembly

*class* · `packages/destruction/src/assembly.ts:22`

```ts
class Assembly
```

- `readonly parts: Map<string, AssemblyPart>`
- `constructor(readonly root: string)`
- `add(part: PartState, at: Vec3): void`
- `get(id: string): AssemblyPart`
- `join(a: string, to: string | null, kind: LinkState['kind'], holds: number): LinkState` — join `a` to `b` (or to the world with null): a link is kept on `a`, and `b` is reached through it
- `connected(): Set<string>` — the ids reachable from the root by unbroken links in either direction (the root's own links to the world count)
- `balance(): { mass: number; com: Vec3 }` — the mass and the centre of mass of the parts still attached (kg, assembly frame)
- `load(partId: string, force: number, point: Vec3, seed: number, ctx: StyleContext = PHYSICAL): { events: DestructionEvent[]; detached: string[] }` — A force N on a part is shared by its links in proportion to their holding force; a link that carries more than it holds (x `ctx.strengthScale`) breaks. Parts left without a path to the root detach. Returns the events (`link-break`, `detach`) and the ids of the parts that came off.
- `release(partId: string, point: Vec3, seed: number): { events: DestructionEvent[]; detached: string[] }` — force a part off at once (its links all fail): a glass pane that shattered leaves its frame, a wheel knocked off

### DebrisWorld

*class* · `packages/destruction/src/debris.ts:162`

```ts
class DebrisWorld
```

- `pieces: DebrisPiece[]`
- `clutter: Clutter[]`
- `events: BreakNoise[]` — one noise event per break, newest last (the host drains it)
- `constructor(public maxPieces: number, public maxBodies: number)`
- `get live(): number`
- `get bodies(): number`
- `add(pieces: PieceSpec[], o: Omit<PlanOptions, 'live' | 'liveBodies' | 'maxPieces' | 'maxBodies' | 'firstId'>): DebrisPlan` — plan a break against the world's budget and add its pieces; returns the plan
- `trim(incoming = 0): void` — make room for `incoming` pieces: drop the gone, the merged and the oldest sleepers, then the smallest oldest pieces, until the cap holds
- `step(dt: number, speed: (p: DebrisPiece) => number): void` — advance every piece by dt; `speed(piece)` is the body's speed now. Gone pieces are removed.
- `merge(group: number): Clutter | null` — merge the long-sleeping pieces of a group into its static clutter (one collider box and batched meshes); the pieces stay in the world as merged and no longer count as bodies
- `drainEvents(): BreakNoise[]`

### DestructionService

*class* · `packages/destruction/src/service.ts:94`

```ts
class DestructionService
```

- `readonly book: StyleBook`
- `readonly scopes: StyleScopes`
- `readonly things: Map<string, Destructible>`
- `debris: DebrisWorld` — the pieces of every break: the world's cap, bodies, sleepers, clutter, fading (debris.ts)
- `viewer: Vec3 | null` — where the viewer is, for the level of detail by distance (null: every thing is near, unless its own `lod` says otherwise)
- `groundY: number` — the lowest height a fallen piece rests at (the cheap fall of pieces that are not bodies)
- `styleGravity: number` — gravity and bounce the cheap fall uses (the style of the last break sets them; physical is 1 and 1)
- `styleBounce: number`
- `readonly bound: Set<string>` — the things that ride a kernel body (the capability binds them): the view does not step their vehicles again
- `bodySpeed: ((p: DebrisPiece) => number) | null` — the speed of the kernel body of a piece in `body` mode, when the host makes bodies for pieces (the view sets it); without it the cheap fall serves every piece
- `get alivePieces(): number`
- `get maxPieces(): number`
- `set maxPieces(n: number)`
- `readonly counts: { hits: number; breaks: number; dropped: number; }`
- `constructor(o: ServiceOptions = {})`
- `registerModel(name: string, model: FailureModel): void` — a failure model by name: for styles that replace a model (`override`) and for parts that name theirs
- `listen(fn: (name: string, payload: any) => void): () => void` — every announcement goes to `fn(name, payload)`; returns the function that stops it
- `add(t: { id: string; assembly: Assembly; entity?: number; zones?: Record<string, CrushZone[]>; models?: Record<string, string>; vehicle?: Vehicle; lod?: Lod }): Destructible`
- `thing(id: string): Destructible`
- `remove(id: string): boolean`
- `reset(): void` — a clean world for the next scene: no things, no pieces, no falls, the counts at zero. The styles, their scopes and the registered models stay (a scene change is not a style change); the piece cap is the one it was made with, or the present one.
- `setLod(id: string, lod: Lod): void`
- `setFrame(id: string, position: Vec3, rotation: Quat): void` — where the thing is (the capability keeps this current from the body); a vehicle is placed through its own pose
- `releasePieces(n: number): void` — the host removed `n` pieces (the oldest go first): the debris world forgets them, so the cap is the world's
- `levelOf(d: Destructible, point: Vec3): DebrisLevel` — the level of detail a break gets: the worse of the thing's own `lod` and the one its distance from the viewer (and `seen`) gives
- `defineThing(b: ThingBlock): Destructible` — a thing from a block of a manifest (parts, links, crush zones, glass panes)
- `defineCar(id: string, name: string, mass: number | undefined, nodes: NodeInfo[], entity?: number): Destructible` — a library car from the node names and bounds of its model (`autoparts`): the parts, links, crush zones, glass panes and the wheeled vehicle
- `partAt(d: Destructible, local: Vec3): string` — the part (by id) that a point of the thing's frame lies in: a vehicle knows its own boxes, others use the part's place and size
- `styleAt(d: Destructible, point: Vec3, event?: string): ResolvedStyle` — the style that rules a hit on a thing at a world point: the narrowest scope (event, entity, zone, level, world)
- `contact(id: string, c: ContactInput, eventStyle?: string): HitResult | null` — a contact on a thing: the part at the point takes it under the style in force. Below the impact threshold nothing happens (no wear from resting stacks).
- `breakAt(id: string, a: { part?: string; point: Vec3; normal?: Vec3; energy: number; seed?: number; style?: string; speed?: number; area?: number; step?: number }): HitResult` — the break a command asks for: `energy` J at a world point on a part (the part at the point when none is named), normal from the other body toward the thing (default: along the part's thinnest axis, into the part from its +side: a blow on the face of a sheet, a plank or a pane)
- `replay(rec: BreakRecord): HitResult` — a remote copy of a break: the owner's record, applied to this instance's own copy of the thing; the same outcome comes out (the models are pure in the hit, the part and the style)
- `originOf(d: Destructible, partId: string): Vec3` — the world position of a part's centre: where its pieces' offsets are measured from
- `settle(p: DebrisPiece, at: Vec3): void` — a piece that was a body comes to rest where its body was: the instance stays there (the cheap fall takes it from this place, at rest)
- `pieceAt(p: DebrisPiece): Vec3 | null` — where a piece is by the cheap fall, world (a body's own position is the host's)
- `advance(dt: number, bodySpeedOf?: (p: DebrisPiece) => number): void` — advance the debris by dt: pieces that are not bodies (and bodies the host has not made: `bodySpeed` returns -1 for them) fall by the cheap sim, then sleeping, merging into clutter, fading and removal by debris.ts; the noise events go out
- `lost(id: string): number` — the share of the thing's mass that has come off or broken, 0..1
- `inspect(id: string): unknown`
- `save(): unknown` — everything a break changed, as plain JSON (dents as number lists): damage records, dent lattices, broken links, parts that are off
- `load(data: any): void` — restore a save over the same things (defined the same way); a thing the save does not know is left as it is
- `registerCommands(host: CommandHost): void`

### GroundPlane

*class* · `packages/destruction/src/vehicle.ts:55`

```ts
class GroundPlane implements RayCaster
```

a plane as ground (optionally only within an x range, so that a ramp can be laid on a floor); the nearest of several is `groundOf([...])`

- `readonly normal: Vec3`
- `constructor(readonly point: Vec3 = [0, 0, 0], normal: Vec3 = [0, 1, 0], readonly grip = 1, readonly xRange?: [number, number])`
- `cast(o: Vec3, d: Vec3, maxDistance: number): RayHit | null`

### StyleBook

*class* · `packages/destruction/src/style.ts:77`

```ts
class StyleBook
```

the registry of failure models by name and of styles by name; the module's own models are registered by the capability (D11), a game adds its own

- `constructor()`
- `registerModel(name: string, model: FailureModel): void`
- `hasModel(name: string): boolean`
- `defineStyle(spec: StyleSpec): ResolvedStyle`
- `style(name: string): ResolvedStyle`
- `styleNames(): string[]`
- `modelFor(style: ResolvedStyle, part: PartState, base: FailureModel): FailureModel` — the model to run for this part: the style's replacement by part id, then by kind, else the physical `base` model
- `run(style: ResolvedStyle, hit: Hit, part: PartState, base: FailureModel): Outcome` — the whole step for a hit on a part: resolve nothing, only run the style's model with the style's context

### StyleScopes

*class* · `packages/destruction/src/style.ts:102`

```ts
class StyleScopes
```

- `world: string`
- `level: string | null`
- `constructor(readonly book: StyleBook)`
- `setWorld(name: string): void`
- `setLevel(name: string | null): void`
- `setZone(z: StyleZone): void`
- `removeZone(id: string): void`
- `setEntity(entity: number, name: string | null): void`
- `resolve(entity: number, point: Vec3, event?: string): ResolvedStyle` — the style that rules a hit on `entity` at `point`: event, then entity, then the last zone set that holds the point, then level, then world
- `name(entity: number, point: Vec3, event?: string): string`

### TreeBreaker

*class* · `packages/destruction/src/view-trees.ts:64`

```ts
class TreeBreaker
```

- `last: { contacts: { branch: number; depth: number; lever: number; k: number; fBreak: number }[]; drive: number; broke: number; held: boolean } | null` — the last step's contacts and verdict, for the tools that look inside
- `constructor(readonly scene: BABYLON.Scene, readonly o: TreeBreakerOptions)`
- `addKind(id: string, bark: BABYLON.Mesh, others: { mesh: BABYLON.Mesh; leafy: boolean }[]): TreeKind | null` — Register a tree kind. `bark` is the mesh whose skeleton is taken (the trunk and branches), `others` the rest of the tree drawn from the same instances (leaves, knots), each marked leafy or not. All of them must be thin-instanced with the same matrices (one entry per tree).
- `update(dt: number, box: BodyBox, v: Vec3, drive: number): TreeStep` — One step. `box` is the body, `v` its velocity (m/s), `drive` the force it can push with (N). Returns what the trees did to it: push (a correction of its place), hold (a direction its speed into is to be taken away) and how many branches broke this step.
- `stats()`
- `dispose()`

### Vehicle

*class* · `packages/destruction/src/vehicle.ts:148`

```ts
class Vehicle
```

- `readonly assembly: Assembly`
- `readonly chassis: string`
- `readonly wheels: WheelState[]`
- `readonly zones: Record<string, CrushZone[]>`
- `readonly model: FailureModel | undefined`
- `readonly friction: number`
- `pos: Vec3` — world position of the centre of mass, m
- `rot: Quat`
- `vel: Vec3` — world velocity of the centre of mass, m/s
- `angVel: Vec3` — world angular velocity, rad/s
- `mass: number`
- `com: Vec3` — centre of mass in the car frame, m
- `inertia: Vec3` — inertia about the centre of mass along the car axes, kg m^2
- `controls: Controls`
- `sleeping: boolean`
- `autoSleep: boolean` — false: never falls asleep (for tests of the dynamics)
- `readonly bodies: DetachedBody[]` — everything the car has lost, once each
- `ledger: Ledger` — the sum of the ledgers of all the hits it has taken
- `readonly events: DestructionEvent[]`
- `readonly driveTorque: number`
- `readonly brakeTorque: number`
- `constructor(spec: VehicleSpec)`
- `recompute(): void` — mass, centre of mass and inertia of the parts still attached
- `boxCenter(id: string): Vec3` — the centre of a part's box in the car frame, m
- `refreshHull(): void` — the collider hull: the chassis box, shrunk by the crush depths
- `hull(): { size: Vec3; center: Vec3 }` — the size and centre (car frame) of the collider hull now
- `place(origin: Vec3, rot: Quat = qIdentity()): void` — put the car frame's origin at `origin` with orientation `rot`, at rest (the centre of mass is placed from it)
- `toWorld(p: Vec3): Vec3` — world position of a point of the car frame
- `toLocal(p: Vec3): Vec3` — car frame position of a world point
- `velocityAt(p: Vec3): Vec3` — the velocity of the body at a world point, m/s
- `tilt(): number` — the angle between the car's up axis and the world's up, rad (over a quarter turn the car is on its side, near pi on its roof)
- `launch(v: Vec3): void` — give the car a velocity with its wheels already rolling at it (a car that was driving, not one dropped with locked wheels)
- `wake(): void`
- `pushForce(f: Vec3, at: Vec3 = this.pos): void` — a force for the next step only, N at a world point (a push, a wind, a test's side force)
- `applyImpulse(j: Vec3, at: Vec3 = this.pos): void` — an impulse at once, N s at a world point
- `invInertia(t: Vec3): Vec3` — the world-frame inverse inertia applied to a torque or angular impulse: the angular velocity it gives, rad/s
- `step(dt: number, ground: RayCaster): void` — the steady wheel and body forces for one step of `dt` seconds on a ground
- `detach(ids: string[]): DetachedBody[]` — the ids that have just detached (assembly.load or release gave them): each becomes a body of its own carrying the car's motion at its place, once; the car's mass, centre of mass and inertia are recomputed and the wheels among them lose their rays
- `partAt(p: Vec3): string` — the part of the car frame point `p` (the smallest part's box that holds it; the chassis if none does)
- `strike(s: StrikeInput): StrikeResult` — A contact turned into damage: the part at the point takes the hit by the car's failure model (a crush zone, a pane, whatever the model is), what it cannot absorb goes on to its links as a force (residual energy over `LINK_GIVE`, E = F x), links that take more than they hold break, parts left unjoined come off as bodies. Only the struck car is touched: each car in a pile-up takes the damage of its own contacts.

## Functions

### addDent

*function* · `packages/destruction/src/crush.ts:217`

```ts
function addDent(lattice: Float32Array, size: Vec3, point: Vec3, direction: Vec3, depth: number, radius: number, dims: [number, number, number] = DENT_DIMS, across = 1): void
```

Displace the control points by a dent: at `point` (part frame) along unit `direction` by `depth`, with a smooth falloff of `radius` (a compact (1 - t^2)^2 bump, zero past the radius).
The weights are scaled so that the lattice's displacement AT the point (`sampleDent`) is exactly `depth` along the direction. Additive: a second dent adds to the first. The radius is raised to at least
`DENT_MIN_RADIUS_SPACINGS` grid spacings so the dent always lands on control points. `across` (default 1: a round dent) widens the falloff in the plane across the direction by that factor: the face of a wall that meets a car.

### addLedgers

*function* · `packages/destruction/src/energy.ts:81`

```ts
function addLedgers: (a: Ledger, b: Ledger) => Ledger
```

the ledger of two hits added (a car's several parts, one event)

### analyseBark

*function* · `packages/destruction/src/branches.ts:78`

```ts
function analyseBark(mesh: TreeMesh, o: { use?: (v: number) => boolean; slice?: number } = {}): TreeSkeleton
```

The branches of a bark mesh. `use` picks the bark's vertices when the mesh holds leaves too (a triangle is bark when all three are). `slice` is the thickness of a slice of g (default height / 70).

### applyCrush

*function* · `packages/destruction/src/crush.ts:294`

```ts
function applyCrush(hit: Hit, part: PartState, zone: CrushZone, ctx: StyleContext): Outcome
```

One hit on one crush zone of a ductile part. The share of the hit's energy along the zone's axis (the alignment squared) goes into the `crush` column up to what the zone can still absorb from where
it stands (until bottomed out); the permanent dent is written into the returned damage record and into `part.dents` (made if missing, the ONE side effect: the Outcome has no field for the lattice,
the lattice grows in place and is additive). Everything the zone cannot take (the part of the energy off the axis, and what is beyond the bottomed-out limit) stays in the ledger's `residual`
for the assembly to pass on as load to the links and the next part. The ledger balances. `ctx.strengthScale` scales the curve, `ctx.depthScale` the visible dent, `ctx.recover` removes that share of the
dent after the hit; `ctx.energyScale` is already in `hit.energy`.

### assignLeaves

*function* · `packages/destruction/src/branches.ts:216`

```ts
function assignLeaves(sk: TreeSkeleton, mesh: TreeMesh, use?: (v: number) => boolean): Uint16Array
```

the branch of every vertex of a leaf mesh: each card (a connected piece) goes with the ring nearest its centre. `use` picks the leaf vertices of a mesh that holds bark too (the others get 0).

### balanced

*function* · `packages/destruction/src/energy.ts:76`

```ts
function balanced(l: Ledger, tol = 1e-9): boolean
```

the ledger closes within `tol` (relative to the input, at least 1e-12 absolute)

### barForce

*function* · `packages/destruction/src/wood.ts:112`

```ts
function barForce(energy: number, youngModulus: number, I: number, span: number, x: number): number
```

the force a hit of `energy` J makes on a bar of this section at x from the first support, on a span Ls: E = F^2 / 2k with k = 3 Y I Ls / (x^2 (Ls - x)^2)

### barGeometry

*function* · `packages/destruction/src/wood.ts:93`

```ts
function barGeometry(part: PartState, normal: Vec3): BarGeometry
```

the bar's axis and section for a hit (see the header)

### barMoment

*function* · `packages/destruction/src/wood.ts:118`

```ts
function barMoment(F: number, span: number, x: number, u: number): number
```

the bending moment at u from the first support under a point load F at x, N m

### branchBreakForce

*function* · `packages/destruction/src/branches.ts:49`

```ts
function branchBreakForce: (d: number, L: number, sigma?: number) => number
```

N: the sideways force at lever L that breaks a branch of base diameter d

### branchMass

*function* · `packages/destruction/src/branches.ts:51`

```ts
function branchMass: (d: number, L: number, rho?: number) => number
```

kg: the wood of a branch (a cone of base diameter d and length L)

### branchPose

*function* · `packages/destruction/src/branches.ts:351`

```ts
function branchPose(sk: TreeSkeleton, bend: (b: number) => { x: number; dir: Vec3; lever: number } | null, gone: (b: number) => boolean, out = new Float32Array(sk.branches.length * 12)): Float32Array
```

The 3x4 matrices (rows, model frame) of every branch: a bent branch turns about its base by deflection / lever, toward its bend's direction (model frame); a branch on it turns with it; a gone
branch is folded into its base point (it draws nothing). Returns 12 floats a branch.

### branchStiffness

*function* · `packages/destruction/src/branches.ts:47`

```ts
function branchStiffness: (d: number, L: number, E?: number) => number
```

N/m: the stiffness of a cantilever of base diameter d pushed at lever L

### breakSeed

*function* · `packages/destruction/src/rng.ts:32`

```ts
function breakSeed: (entity: number, step: number, p: readonly [number, number, number]) => number
```

the seed of one break: a pure function of the entity, the step of the hit and the point (millimetres), so a remote copy of the break gets the same one

### buildCar

*function* · `packages/destruction/src/autoparts.ts:143`

```ts
function buildCar(spec: CarSpec): CarBlock
```

### carModel

*function* · `packages/destruction/src/autoparts.ts:269`

```ts
function carModel(block: CarBlock, others: Partial<Record<MaterialKind, FailureModel>> = {}): FailureModel
```

a failure model for the parts of a car: ductile parts crush along their zones, glass takes the model given for brittle parts, and a part of the kind `rigid` takes nothing (all its energy stays as residual)

### carVehicle

*function* · `packages/destruction/src/autoparts.ts:282`

```ts
function carVehicle(block: CarBlock, others: Partial<Record<MaterialKind, FailureModel>> = {}, extra: Partial<VehicleSpec> = {}): Vehicle
```

the wheeled assembly of a car block: its failure model (ductile by crush, the rest by `others`), its crush zones and the chassis' box centre

### centreBreakForce

*function* · `packages/destruction/src/wood.ts:123`

```ts
function centreBreakForce: (sigma: number, Z: number, span: number) => number
```

the force at which a clear bar on two supports a span apart breaks under a load at its centre: F = 4 sigma Z / L

### closeCrush

*function* · `packages/destruction/src/crush.ts:334`

```ts
function closeCrush(o: Outcome): Outcome
```

close an outcome whose residual has nowhere further to go (the last part of the chain): the rest becomes heat and sound, and the ledger still balances

### collideCars

*function* · `packages/destruction/src/vehicle.ts:464`

```ts
function collideCars(a: Vehicle, b: Vehicle, step: number, entityA: number, entityB: number, restitution = 0.1): { speed: number; a?: StrikeResult; b?: StrikeResult } | null
```

Two cars meet: an inelastic-with-restitution impulse at the contact (momentum is conserved, both bodies turn as they should), the overlap pushed apart in proportion to the inverse masses, and, if
they were closing faster than `RESTING_SPEED`, each car takes the hit of its own side (`strike`) with the energy `1/2 mu v^2 (1 - e^2)` shared by the two. Returns the closing speed, or null if apart.

### contactStiffness

*function* · `packages/destruction/src/energy.ts:34`

```ts
function contactStiffness: (youngModulus: number, area: number, length: number) => number
```

the stiffness of a part at a contact, N/m: its Young's modulus over its size along the hit, times the contact area (a short, wide, stiff part is stiff)

### crackAreaFor

*function* · `packages/destruction/src/fracture.ts:23`

```ts
function crackAreaFor: (energy: number, fractureEnergy: number) => number
```

the crack area that the given energy can make, m^2

### crackEnergy

*function* · `packages/destruction/src/fracture.ts:21`

```ts
function crackEnergy: (area: number, fractureEnergy: number) => number
```

the energy that a crack of the given area costs, J (surface-energy law)

### crushAlignment

*function* · `packages/destruction/src/crush.ts:281`

```ts
function crushAlignment(hit: Hit, zone: CrushZone): number
```

how squarely the hit lands on the zone: the cosine of the angle between the hit's normal and the zone's axis, 0 when it comes from behind

### crushBalanced

*function* · `packages/destruction/src/energy.ts:76`

```ts
function balanced(l: Ledger, tol = 1e-9): boolean
```

the ledger closes within `tol` (relative to the input, at least 1e-12 absolute)

### crushCapacity

*function* · `packages/destruction/src/crush.ts:171`

```ts
function crushCapacity(zone: CrushZone, x0 = 0, strengthScale = 1): number
```

the energy the zone can still absorb from depth x0 up to being bottomed out, J

### crushDepthOf

*function* · `packages/destruction/src/crush.ts:276`

```ts
function crushDepthOf: (part: PartState, zone: CrushZone) => number
```

the physical depth a zone stands at in a part's damage record, m

### crushEnergy

*function* · `packages/destruction/src/crush.ts:132`

```ts
function crushEnergy(zone: CrushZone, x: number, strengthScale = 1): number
```

the work done compressing the zone to depth x, J: the integral of F from 0 to x (exact for the piecewise-linear curve and the block past dMax)

### crushForce

*function* · `packages/destruction/src/crush.ts:119`

```ts
function crushForce(zone: CrushZone, x: number, strengthScale = 1): number
```

the resisting force at depth x, N (`strengthScale` multiplies the curve; past dMax the zone is a stiff block; x below 0 gives 0)

### debrisLevel

*function* · `packages/destruction/src/debris.ts:53`

```ts
function debrisLevel: (distance: number, seen: boolean, lod?: DebrisLod) => DebrisLevel
```

### decelerationAlong

*function* · `packages/destruction/src/crush.ts:186`

```ts
function decelerationAlong(zone: CrushZone, mass: number, v0: number, opt: DecelerationOptions = {}): Deceleration
```

a body of `mass` kg hits a rigid wall at `v0` m/s through the zone: semi-implicit steps of a fixed dt (`CRUSH_DT`, 1/1000 s) until it stops (the speed reaches 0)

### defaultCurve

*function* · `packages/destruction/src/crush.ts:74`

```ts
function defaultCurve(dMax: number, plateau: number): CurvePoint[]
```

the default curve: stiff onset to the plateau at `plateau`, the plateau, then a stiff bottoming-out branch to `CRUSH_BOTTOM_FORCE_RATIO` times the plateau at `dMax`

### defaultZoneFor

*function* · `packages/destruction/src/crush.ts:343`

```ts
function defaultZoneFor(part: PartState, normal: Vec3): CrushZone
```

A default crush zone for a part and a hit: it crumples along the hit's normal, through half of the part's size along that normal, over the face across it, from the material's yield strength and the
part's sheet thickness. Used where the assembly gave the part no zones of its own.

### dentDepthOf

*function* · `packages/destruction/src/crush.ts:278`

```ts
function dentDepthOf: (part: PartState, zone: CrushZone) => number
```

the visible dent depth of a zone in a part's damage record, m

### dentMagnitude

*function* · `packages/destruction/src/crush.ts:266`

```ts
function dentMagnitude(lattice: Float32Array): number
```

the total of the lattice's displacements, a single number that grows with every dent (m): the sum of the lengths of the control point offsets

### depthForEnergy

*function* · `packages/destruction/src/crush.ts:149`

```ts
function depthForEnergy(zone: CrushZone, energy: number, strengthScale = 1): number
```

the depth at which the zone has absorbed energy E, m: the inverse of `crushEnergy` (past the capacity it goes on into the block branch)

### destruction

*function* · `packages/destruction/src/capability.ts:37`

```ts
function destruction(service: DestructionService): DestructionCapability
```

the force of a hit is reported as `amount` (J) in `physics:damage`; `health` is the share of the thing's mass still on

### dicePane

*function* · `packages/destruction/src/fracture.ts:184`

```ts
function dicePane(o: DiceOptions): FractureResult
```

a jittered grid of small blunt cells over the whole pane (tempered glass dices all at once). The cell edge grows if the count would pass `maxPieces`. Mass is shared by area.

### dustShare

*function* · `packages/destruction/src/stone.ts:51`

```ts
function dustShare(part: PartState): number
```

the share of the volume that may turn to dust (see the header)

### explainHit

*function* · `packages/destruction/src/style.ts:126`

```ts
function explainHit(style: ResolvedStyle, hit: Hit, outcome: Outcome): string
```

`destruction.explain`: which style ruled, the energy in and where every part of it went (or why nothing broke)

### fillMaterial

*function* · `packages/destruction/src/material.ts:43`

```ts
function fillMaterial(given: Partial<MaterialProps> | undefined, kind: MaterialKind): MaterialProps
```

the numbers of a material with what is missing taken from the kind's typical substance (a rigid part gets an unreachable strength)

### flingPieces

*function* · `packages/destruction/src/fracture.ts:608`

```ts
function flingPieces(pieces: PieceSpec[], point: Vec3, normal: Vec3, kinetic: number, seed: number): number
```

Set the velocities of the pieces (the part's own motion not included) so that their kinetic energy is exactly `kinetic` J: each flies away from the impact point and along the hit's push (`normal`),
with a seeded scatter. Returns the energy given, which equals `kinetic` (0 with no pieces).

### glassFailureEnergy

*function* · `packages/destruction/src/glass.ts:86`

```ts
function glassFailureEnergy(part: PartState, point: Vec3, area: number, ctx: StyleContext): number
```

the hit energy at which the stress reaches the failure stress (ratio 1), J; the same hit position and contact area. A pure function: monotone in strength and in the thickness.

### glassKind

*function* · `packages/destruction/src/glass.ts:54`

```ts
function glassKind(part: PartState): GlassKind
```

### glassModel

*function* · `packages/destruction/src/glass.ts:95`

```ts
function glassModel: FailureModel
```

### grainSplit

*function* · `packages/destruction/src/fracture.ts:235`

```ts
function grainSplit(o: GrainSplitOptions, n: number): FractureResult
```

split a box along its grain into `n` long slabs (n = 1: one piece, no crack). Slab widths vary by seed.

### grainSplitArea

*function* · `packages/destruction/src/fracture.ts:230`

```ts
function grainSplitArea(o: GrainSplitOptions, n: number): number
```

the crack area of splitting the box into `n` slabs along the grain: (n - 1) planes, each as long as the box along the grain and as wide as it is in the third direction

### grainSplitByEnergy

*function* · `packages/destruction/src/fracture.ts:258`

```ts
function grainSplitByEnergy(o: GrainSplitOptions, budget: number, max: number): FractureResult
```

the most slabs (at most `max`) that the budget pays for, then the split

### gridBlock

*function* · `packages/destruction/src/fracture.ts:275`

```ts
function gridBlock(o: GridBlockOptions): FractureResult
```

a cheap pattern for small blocks (the chips of a snapped plank): the block cut by jittered planes into a grid of at most 3 x 3 x 3 cells, more cells along the longer sides. The richest grid
(by cell count) whose planes cost no more than the budget; one cell when the budget pays for no cut. Mass is shared by volume; pieces are `chunk`s with box vertices.

### groundOf

*function* · `packages/destruction/src/vehicle.ts:68`

```ts
function groundOf(list: RayCaster[]): RayCaster
```

several grounds as one: the nearest hit wins

### hash32

*function* · `packages/destruction/src/rng.ts:5`

```ts
function hash32: (x: number) => number
```

### hashRand

*function* · `packages/destruction/src/rng.ts:30`

```ts
function hashRand: (seed: number, a: number, b?: number) => number
```

a number in [0, 1) that is a pure function of (seed, a, b): for things that must not depend on how many numbers were drawn before

### hitEnergy

*function* · `packages/destruction/src/energy.ts:17`

```ts
function hitEnergy(speed: number, massA: number, massB: number, restitution: number): number
```

the energy of a hit available for damage, J: `1/2 mu v_n^2 (1 - e^2)` (the rest goes into the bounce, `e` the restitution)

### holdModel

*function* · `packages/destruction/src/style.ts:56`

```ts
function holdModel: FailureModel
```

the model that breaks nothing: the hit's energy goes to heat and sound, the part is untouched (`rigid-world`, and a part that must hold)

### hullContact

*function* · `packages/destruction/src/vehicle.ts:428`

```ts
function hullContact(a: Vehicle, b: Vehicle): Contact | null
```

separating axis test of two cars' hull boxes: the normal points from `a` to `b`; null if they do not overlap

### knotFactor

*function* · `packages/destruction/src/wood.ts:77`

```ts
function knotFactor(knots: Knot[], x: number, depth: number): number
```

the strength of the section at x (0..1 of the clear wood's): each knot digs a smooth dip, deeper the bigger it is against the depth

### linkHolds

*function* · `packages/destruction/src/assembly.ts:10`

```ts
function linkHolds: (tensile: number, area: number, count?: number) => number
```

a link's holding force, N: the strength of the fixing times the section of one times how many there are

### linkMotion

*function* · `packages/destruction/src/motion.ts:30`

```ts
function linkMotion(service: DestructionService, bridge: MotionBridgeLike): () => void
```

Registers the words on a bridge and forwards the service's events to the runtime. Returns the function that stops the forwarding. Call it once per bridge, before the programs that use the words are loaded.

### loudness

*function* · `packages/destruction/src/debris.ts:65`

```ts
function loudness: (energy: number) => number
```

the loudness of a break by its energy, 0..1 (log scale, monotone)

### makeCrushModel

*function* · `packages/destruction/src/crush.ts:352`

```ts
function makeCrushModel(zones: (part: PartState) => CrushZone[]): FailureModel
```

the failure model of ductile parts with the zones of the part given: the zone best aligned with the hit takes it

### makeCrushZone

*function* · `packages/destruction/src/crush.ts:97`

```ts
function makeCrushZone(i: CrushZoneInput): CrushZone
```

a crush zone; the effective area is `thickness x perimeter x load share` (or the whole face for a solid section), the plateau is `yieldStrength x area`

### makeDentLattice

*function* · `packages/destruction/src/crush.ts:206`

```ts
function makeDentLattice(nx = DENT_DIMS[0], ny = DENT_DIMS[1], nz = DENT_DIMS[2]): Float32Array
```

a lattice of nx x ny x nz control points of a free-form cage over the part's bounds; x y z offsets per point, all zero at first (the point order is x fastest, then y, then z)

### makeHit

*function* · `packages/destruction/src/energy.ts:49`

```ts
function makeHit(i: HitInput): Hit
```

a contact turned into the numbers a failure model reads. A resting contact (speed 0) has no energy.

### makeLink

*function* · `packages/destruction/src/assembly.ts:15`

```ts
function makeLink(id: string, to: string | null, kind: LinkState['kind'], holds: number): LinkState
```

### makePart

*function* · `packages/destruction/src/part.ts:19`

```ts
function makePart(i: PartInput): PartState
```

### newLedger

*function* · `packages/destruction/src/energy.ts:59`

```ts
function newLedger: (input: number) => Ledger
```

### newStream

*function* · `packages/destruction/src/rng.ts:14`

```ts
function newStream: (seed: number, salt?: number) => Stream
```

### pieceKinetic

*function* · `packages/destruction/src/fracture.ts:595`

```ts
function pieceKinetic(pieces: PieceSpec[]): number
```

the kinetic energy of the pieces as they stand (translation and rotation about their centres), J

### pieceMass

*function* · `packages/destruction/src/fracture.ts:604`

```ts
function pieceMass: (pieces: PieceSpec[]) => number
```

the sum of the pieces' masses, kg

### planDebris

*function* · `packages/destruction/src/debris.ts:98`

```ts
function planDebris(pieces: PieceSpec[], o: PlanOptions): DebrisPlan
```

decide what a break's pieces become: bodies, instances, particles or nothing, by level and budget, and make the one noise event

### plateStress

*function* · `packages/destruction/src/glass.ts:65`

```ts
function plateStress(energy: number, w: number, h: number, t: number, youngModulus: number, x: number, y: number, area: number): PlateLoad
```

the force and the peak bending stress of a hit of `energy` J at (x, y) from the pane's centre on a pane of w x h x t (m) with Young's modulus Y, over a contact of `area` m^2

### qAxisAngle

*function* · `packages/destruction/src/vehicle.ts:41`

```ts
function qAxisAngle(axis: Vec3, angle: number): Quat
```

the quaternion of a rotation of `angle` radians about a unit axis

### qConj

*function* · `packages/destruction/src/vehicle.ts:33`

```ts
function qConj: (q: Quat) => Quat
```

### qIdentity

*function* · `packages/destruction/src/vehicle.ts:26`

```ts
function qIdentity: () => Quat
```

### qMul

*function* · `packages/destruction/src/vehicle.ts:27`

```ts
function qMul(a: Quat, b: Quat): Quat
```

### qRot

*function* · `packages/destruction/src/vehicle.ts:35`

```ts
function qRot(q: Quat, v: Vec3): Vec3
```

rotate a vector by a unit quaternion

### radialPane

*function* · `packages/destruction/src/fracture.ts:154`

```ts
function radialPane(o: PaneOptions): FractureResult
```

the pieces of a pane cracked radially and in rings from the impact point: the richest pattern whose crack surface costs no more than the budget (at least four wedges). Mass is shared by area.

### reducedMass

*function* · `packages/destruction/src/energy.ts:9`

```ts
function reducedMass(a: number, b: number): number
```

the reduced mass of two bodies, kg; a body of infinite mass (the ground, a wall) gives the other one's

### regionOf

*function* · `packages/destruction/src/autoparts.ts:97`

```ts
function regionOf(l: CarLayout, p: Vec3): string
```

which region of the car a point of the `Body` mesh belongs to (car frame): the names are the part ids, `Chassis` for the rest

### resolveContacts

*function* · `packages/destruction/src/branches.ts:284`

```ts
function resolveContacts(cs: TreeContact[], drive: number): ContactOutcome
```

what the branches do against a body that can push with at most `drive` newtons (see THE LAW)

### resolveStyle

*function* · `packages/destruction/src/style.ts:34`

```ts
function resolveStyle(spec: StyleSpec): ResolvedStyle
```

### rnd

*function* · `packages/destruction/src/rng.ts:16`

```ts
function rnd(s: Stream): number
```

the next number in [0, 1) of a stream (mulberry32)

### rnorm

*function* · `packages/destruction/src/rng.ts:25`

```ts
function rnorm(s: Stream): number
```

a standard normal number (Box-Muller; two draws)

### rrange

*function* · `packages/destruction/src/rng.ts:23`

```ts
function rrange: (s: Stream, lo: number, hi: number) => number
```

### sampleDent

*function* · `packages/destruction/src/crush.ts:255`

```ts
function sampleDent(lattice: Float32Array, size: Vec3, point: Vec3, dims: [number, number, number] = DENT_DIMS): Vec3
```

the lattice's displacement at a point of the part's frame (trilinear over the control points), m

### scaleOf

*function* · `packages/destruction/src/branches.ts:241`

```ts
function scaleOf: (m: ArrayLike<number>) => number
```

the mean scale of a matrix

### scatterDebris

*function* · `packages/destruction/src/debris.ts:135`

```ts
function scatterDebris(pieces: PieceSpec[], point: Vec3, normal: Vec3, energy: number, kineticShare: number, ctx: StyleContext, seed: number): number
```

give the pieces velocities so that their kinetic energy is at most `kineticShare` of the hit (times the style's burst^2); returns the kinetic energy given, J. Uses `flingPieces`.

### secondMoment

*function* · `packages/destruction/src/branches.ts:45`

```ts
function secondMoment: (d: number) => number
```

### sectionModulus

*function* · `packages/destruction/src/material.ts:58`

```ts
function sectionModulus: (w: number, h: number) => number
```

section modulus of a rectangular section of width w and depth h about the axis the load bends it over, m^3 (Z = w h^2 / 6)

### seedState

*function* · `packages/destruction/src/rng.ts:11`

```ts
function seedState: (seed: number, salt?: number) => number
```

the state of a stream from a seed (never 0)

### setGlassKind

*function* · `packages/destruction/src/glass.ts:59`

```ts
function setGlassKind(part: PartState, kind: GlassKind): void
```

set the kind on a part (writes `glass.kind`)

### settle

*function* · `packages/destruction/src/energy.ts:70`

```ts
function settle(l: Ledger, soundShare = 0.02): Ledger
```

whatever is left after the named columns goes to heat and sound (the rest of an inelastic hit), so the ledger closes: `soundShare` is the part that is sound (small)

### shrinkHull

*function* · `packages/destruction/src/crush.ts:373`

```ts
function shrinkHull(size: Vec3, zones: CrushZone[], damage: Record<string, number>): Hull
```

The reduced bounds to use as the collider after deep dents: every zone's face has moved in along its axis by its physical depth, so the size shrinks along each
axis by `depth x |axis component|` and the centre moves by half of that toward the part. A depth under `HULL_MIN_DEPTH` changes nothing; a size never goes below `HULL_MIN_FRACTION` of the original.

### spend

*function* · `packages/destruction/src/energy.ts:63`

```ts
function spend(l: Ledger, column: 'crush' | 'fracture' | 'kinetic' | 'heat' | 'sound', joules: number, conserve = true): number
```

spend energy into a column; the residual is what is left (never below 0 unless the style does not conserve). Returns the amount actually spent.

### spent

*function* · `packages/destruction/src/energy.ts:61`

```ts
function spent: (l: Ledger) => number
```

what has been spent so far, J

### splitEnergy

*function* · `packages/destruction/src/energy.ts:24`

```ts
function splitEnergy(total: number, stiffA: number, stiffB: number): [number, number]
```

how the energy divides between two sides in contact: by their compliance (two springs in series carry energy in inverse proportion to their stiffness); the softer takes more. Returns [for A, for B].

### springFor

*function* · `packages/destruction/src/branches.ts:307`

```ts
function springFor(k: number, d: number, L: number, leafy: boolean): BranchSpring
```

### startFall

*function* · `packages/destruction/src/branches.ts:322`

```ts
function startFall(p: Vec3, v: Vec3, leafy: boolean, radius: number, seed: number): FallingBranch
```

### stepFall

*function* · `packages/destruction/src/branches.ts:327`

```ts
function stepFall(f: FallingBranch, dt: number, ground: (x: number, z: number) => number, gravity = 9.81): void
```

one step; `ground(x, z)` the height there

### stepPiece

*function* · `packages/destruction/src/debris.ts:143`

```ts
function stepPiece(p: DebrisPiece, dt: number, speed: number): boolean
```

advance one piece by dt seconds, given its speed now (the host reads it from the body, or the cheap sim makes it). A sleeper stays asleep. Returns true while the piece is live.

### stepSpring

*function* · `packages/destruction/src/branches.ts:312`

```ts
function stepSpring(s: BranchSpring, dt: number, target: number | null): boolean
```

one step: held at `target` while the body presses it, free otherwise; returns whether it still moves

### stoneCapacity

*function* · `packages/destruction/src/stone.ts:48`

```ts
function stoneCapacity: (sigma: number, volume: number, youngModulus: number) => number
```

the energy at which a solid of this size fails by stress, J: sigma^2 V / (2 Y)

### stoneModel

*function* · `packages/destruction/src/stone.ts:57`

```ts
function stoneModel: FailureModel
```

### substance

*function* · `packages/destruction/src/material.ts:36`

```ts
function substance(name: string): { kind: MaterialKind; props: MaterialProps }
```

### subtree

*function* · `packages/destruction/src/branches.ts:387`

```ts
function subtree(sk: TreeSkeleton, b: number): Set<number>
```

every branch on `b` (b itself included)

### treeContacts

*function* · `packages/destruction/src/branches.ts:247`

```ts
function treeContacts(sk: TreeSkeleton, matrix: ArrayLike<number>, box: BodyBox, gone: (b: number) => boolean, wood = GREEN_WOOD): TreeContact[]
```

The branches of one tree (its skeleton placed by `matrix`) that the body is in: for each branch its deepest ring, the depth to clear it along the box's nearest face, and the beam numbers at that
lever. `gone(branch)` is true for a broken branch (and those on it). `wood` gives E and sigma.

### voronoiBlock

*function* · `packages/destruction/src/fracture.ts:528`

```ts
function voronoiBlock(o: VoronoiOptions): FractureResult
```

Voronoi cells of a block: the most cells (at most `maxPieces`) whose internal faces cost no more than the budget; n = 1 (the block whole) when the budget pays for no split. Mass is shared by volume.

### voronoiCrackArea

*function* · `packages/destruction/src/fracture.ts:516`

```ts
function voronoiCrackArea(o: VoronoiOptions, n: number): number
```

the crack area of splitting the block into `n` Voronoi cells (0 for n = 1), m^2

### voronoiVolumeSum

*function* · `packages/destruction/src/fracture.ts:521`

```ts
function voronoiVolumeSum(o: VoronoiOptions, n: number): number
```

the sum of the volumes of the `n` cells, m^3: it equals the block's volume when the cells tile it (a check of the cutting)

