FERRETGame engine over Babylon.js
Ferret

@ferret/destruction

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 · source in packages/destruction/src

Classes

Assembly class

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): LinkStatejoin 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

packages/destruction/src/assembly.ts:22

DebrisWorld class

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'>): DebrisPlanplan a break against the world's budget and add its pieces; returns the plan
trim(incoming = 0): voidmake 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): voidadvance every piece by dt; speed(piece) is the body's speed now. Gone pieces are removed.
merge(group: number): Clutter | nullmerge 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[]

packages/destruction/src/debris.ts:162

DestructionService class

class DestructionService
readonly book: StyleBook
readonly scopes: StyleScopes
readonly things: Map<string, Destructible>
debris: DebrisWorldthe pieces of every break: the world's cap, bodies, sleepers, clutter, fading (debris.ts)
viewer: Vec3 | nullwhere the viewer is, for the level of detail by distance (null: every thing is near, unless its own lod says otherwise)
groundY: numberthe lowest height a fallen piece rests at (the cheap fall of pieces that are not bodies)
styleGravity: numbergravity 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) | nullthe 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): voida failure model by name: for styles that replace a model (override) and for parts that name theirs
listen(fn: (name: string, payload: any) => void): () => voidevery 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(): voida 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): voidwhere the thing is (the capability keeps this current from the body); a vehicle is placed through its own pose
releasePieces(n: number): voidthe 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): DebrisLevelthe 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): Destructiblea 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): Destructiblea 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): stringthe 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): ResolvedStylethe 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 | nulla 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 }): HitResultthe 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): HitResulta 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): Vec3the world position of a part's centre: where its pieces' offsets are measured from
settle(p: DebrisPiece, at: Vec3): voida 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 | nullwhere a piece is by the cheap fall, world (a body's own position is the host's)
advance(dt: number, bodySpeedOf?: (p: DebrisPiece) => number): voidadvance 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): numberthe share of the thing's mass that has come off or broken, 0..1
inspect(id: string): unknown
save(): unknowneverything a break changed, as plain JSON (dents as number lists): damage records, dent lattices, broken links, parts that are off
load(data: any): voidrestore 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

packages/destruction/src/service.ts:94

GroundPlane class

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

packages/destruction/src/vehicle.ts:55

StyleBook class

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): FailureModelthe 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): Outcomethe whole step for a hit on a part: resolve nothing, only run the style's model with the style's context

packages/destruction/src/style.ts:77

StyleScopes class

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): ResolvedStylethe 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

packages/destruction/src/style.ts:102

TreeBreaker class

class TreeBreaker
last: { contacts: { branch: number; depth: number; lever: number; k: number; fBreak: number }[]; drive: number; broke: number; held: boolean } | nullthe 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 | nullRegister 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): TreeStepOne 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()

packages/destruction/src/view-trees.ts:64

Vehicle class

class Vehicle
readonly assembly: Assembly
readonly chassis: string
readonly wheels: WheelState[]
readonly zones: Record<string, CrushZone[]>
readonly model: FailureModel | undefined
readonly friction: number
pos: Vec3world position of the centre of mass, m
rot: Quat
vel: Vec3world velocity of the centre of mass, m/s
angVel: Vec3world angular velocity, rad/s
mass: number
com: Vec3centre of mass in the car frame, m
inertia: Vec3inertia about the centre of mass along the car axes, kg m^2
controls: Controls
sleeping: boolean
autoSleep: booleanfalse: never falls asleep (for tests of the dynamics)
readonly bodies: DetachedBody[]everything the car has lost, once each
ledger: Ledgerthe sum of the ledgers of all the hits it has taken
readonly events: DestructionEvent[]
readonly driveTorque: number
readonly brakeTorque: number
constructor(spec: VehicleSpec)
recompute(): voidmass, centre of mass and inertia of the parts still attached
boxCenter(id: string): Vec3the centre of a part's box in the car frame, m
refreshHull(): voidthe 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()): voidput the car frame's origin at origin with orientation rot, at rest (the centre of mass is placed from it)
toWorld(p: Vec3): Vec3world position of a point of the car frame
toLocal(p: Vec3): Vec3car frame position of a world point
velocityAt(p: Vec3): Vec3the velocity of the body at a world point, m/s
tilt(): numberthe 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): voidgive 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): voida 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): voidan impulse at once, N s at a world point
invInertia(t: Vec3): Vec3the world-frame inverse inertia applied to a torque or angular impulse: the angular velocity it gives, rad/s
step(dt: number, ground: RayCaster): voidthe 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): stringthe part of the car frame point p (the smallest part's box that holds it; the chassis if none does)
strike(s: StrikeInput): StrikeResultA 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.

packages/destruction/src/vehicle.ts:148

Functions

addDent function

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.

packages/destruction/src/crush.ts:217

addLedgers function

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

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

packages/destruction/src/energy.ts:81

analyseBark function

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).

packages/destruction/src/branches.ts:78

applyCrush function

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.

packages/destruction/src/crush.ts:294

assignLeaves function

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).

packages/destruction/src/branches.ts:216

balanced function

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

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

packages/destruction/src/energy.ts:76

barForce function

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)

packages/destruction/src/wood.ts:112

barGeometry function

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

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

packages/destruction/src/wood.ts:93

barMoment function

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

packages/destruction/src/wood.ts:118

branchBreakForce function

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

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

packages/destruction/src/branches.ts:49

branchMass function

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

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

packages/destruction/src/branches.ts:51

branchPose function

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.

packages/destruction/src/branches.ts:351

branchStiffness function

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

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

packages/destruction/src/branches.ts:47

breakSeed function

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

packages/destruction/src/rng.ts:32

buildCar function

function buildCar(spec: CarSpec): CarBlock

packages/destruction/src/autoparts.ts:143

carModel function

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)

packages/destruction/src/autoparts.ts:269

carVehicle function

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

packages/destruction/src/autoparts.ts:282

centreBreakForce function

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

packages/destruction/src/wood.ts:123

closeCrush function

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

packages/destruction/src/crush.ts:334

collideCars function

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.

packages/destruction/src/vehicle.ts:464

contactStiffness function

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)

packages/destruction/src/energy.ts:34

crackAreaFor function

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

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

packages/destruction/src/fracture.ts:23

crackEnergy function

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

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

packages/destruction/src/fracture.ts:21

crushAlignment function

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

packages/destruction/src/crush.ts:281

crushBalanced function

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

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

packages/destruction/src/energy.ts:76

crushCapacity function

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

packages/destruction/src/crush.ts:171

crushDepthOf function

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

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

packages/destruction/src/crush.ts:276

crushEnergy function

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)

packages/destruction/src/crush.ts:132

crushForce function

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)

packages/destruction/src/crush.ts:119

debrisLevel function

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

packages/destruction/src/debris.ts:53

decelerationAlong function

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)

packages/destruction/src/crush.ts:186

defaultCurve function

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

packages/destruction/src/crush.ts:74

defaultZoneFor function

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.

packages/destruction/src/crush.ts:343

dentDepthOf function

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

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

packages/destruction/src/crush.ts:278

dentMagnitude function

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

packages/destruction/src/crush.ts:266

depthForEnergy function

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)

packages/destruction/src/crush.ts:149

destruction function

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

packages/destruction/src/capability.ts:37

dicePane function

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.

packages/destruction/src/fracture.ts:184

dustShare function

function dustShare(part: PartState): number

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

packages/destruction/src/stone.ts:51

explainHit function

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)

packages/destruction/src/style.ts:126

fillMaterial function

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)

packages/destruction/src/material.ts:43

flingPieces function

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).

packages/destruction/src/fracture.ts:608

glassFailureEnergy function

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.

packages/destruction/src/glass.ts:86

glassKind function

function glassKind(part: PartState): GlassKind

packages/destruction/src/glass.ts:54

glassModel function

function glassModel: FailureModel

packages/destruction/src/glass.ts:95

grainSplit function

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.

packages/destruction/src/fracture.ts:235

grainSplitArea function

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

packages/destruction/src/fracture.ts:230

grainSplitByEnergy function

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

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

packages/destruction/src/fracture.ts:258

gridBlock function

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 chunks with box vertices.

packages/destruction/src/fracture.ts:275

groundOf function

function groundOf(list: RayCaster[]): RayCaster

several grounds as one: the nearest hit wins

packages/destruction/src/vehicle.ts:68

hash32 function

function hash32: (x: number) => number

packages/destruction/src/rng.ts:5

hashRand function

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

packages/destruction/src/rng.ts:30

hitEnergy function

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)

packages/destruction/src/energy.ts:17

holdModel function

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)

packages/destruction/src/style.ts:56

hullContact function

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

packages/destruction/src/vehicle.ts:428

knotFactor function

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

packages/destruction/src/wood.ts:77

linkHolds function

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

packages/destruction/src/assembly.ts:10

linkMotion function

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.

packages/destruction/src/motion.ts:30

loudness function

function loudness: (energy: number) => number

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

packages/destruction/src/debris.ts:65

makeCrushModel function

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

packages/destruction/src/crush.ts:352

makeCrushZone function

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

packages/destruction/src/crush.ts:97

makeDentLattice function

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)

packages/destruction/src/crush.ts:206

makeHit function

function makeHit(i: HitInput): Hit

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

packages/destruction/src/energy.ts:49

makePart function

function makePart(i: PartInput): PartState

packages/destruction/src/part.ts:19

newLedger function

function newLedger: (input: number) => Ledger

packages/destruction/src/energy.ts:59

newStream function

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

packages/destruction/src/rng.ts:14

pieceKinetic function

function pieceKinetic(pieces: PieceSpec[]): number

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

packages/destruction/src/fracture.ts:595

pieceMass function

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

the sum of the pieces' masses, kg

packages/destruction/src/fracture.ts:604

planDebris function

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

packages/destruction/src/debris.ts:98

plateStress function

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

packages/destruction/src/glass.ts:65

qAxisAngle function

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

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

packages/destruction/src/vehicle.ts:41

qConj function

function qConj: (q: Quat) => Quat

packages/destruction/src/vehicle.ts:33

qIdentity function

function qIdentity: () => Quat

packages/destruction/src/vehicle.ts:26

qMul function

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

packages/destruction/src/vehicle.ts:27

qRot function

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

rotate a vector by a unit quaternion

packages/destruction/src/vehicle.ts:35

radialPane function

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.

packages/destruction/src/fracture.ts:154

reducedMass function

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

packages/destruction/src/energy.ts:9

regionOf function

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

packages/destruction/src/autoparts.ts:97

resolveContacts function

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)

packages/destruction/src/branches.ts:284

resolveStyle function

function resolveStyle(spec: StyleSpec): ResolvedStyle

packages/destruction/src/style.ts:34

rnd function

function rnd(s: Stream): number

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

packages/destruction/src/rng.ts:16

rnorm function

function rnorm(s: Stream): number

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

packages/destruction/src/rng.ts:25

rrange function

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

packages/destruction/src/rng.ts:23

sampleDent function

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

packages/destruction/src/crush.ts:255

scaleOf function

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

the mean scale of a matrix

packages/destruction/src/branches.ts:241

scatterDebris function

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.

packages/destruction/src/debris.ts:135

secondMoment function

function secondMoment: (d: number) => number

packages/destruction/src/branches.ts:45

sectionModulus function

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)

packages/destruction/src/material.ts:58

seedState function

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

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

packages/destruction/src/rng.ts:11

setGlassKind function

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

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

packages/destruction/src/glass.ts:59

settle function

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)

packages/destruction/src/energy.ts:70

shrinkHull function

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.

packages/destruction/src/crush.ts:373

spend function

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.

packages/destruction/src/energy.ts:63

spent function

function spent: (l: Ledger) => number

what has been spent so far, J

packages/destruction/src/energy.ts:61

splitEnergy function

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].

packages/destruction/src/energy.ts:24

springFor function

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

packages/destruction/src/branches.ts:307

startFall function

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

packages/destruction/src/branches.ts:322

stepFall function

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

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

packages/destruction/src/branches.ts:327

stepPiece function

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.

packages/destruction/src/debris.ts:143

stepSpring function

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

packages/destruction/src/branches.ts:312

stoneCapacity function

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)

packages/destruction/src/stone.ts:48

stoneModel function

function stoneModel: FailureModel

packages/destruction/src/stone.ts:57

substance function

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

packages/destruction/src/material.ts:36

subtree function

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

every branch on b (b itself included)

packages/destruction/src/branches.ts:387

treeContacts function

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.

packages/destruction/src/branches.ts:247

voronoiBlock function

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.

packages/destruction/src/fracture.ts:528

voronoiCrackArea function

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

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

packages/destruction/src/fracture.ts:516

voronoiVolumeSum function

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)

packages/destruction/src/fracture.ts:521

wakePiece function

function wakePiece(p: DebrisPiece): boolean

wake a sleeping piece (a hit on it); a merged piece is part of the clutter and does not wake

packages/destruction/src/debris.ts:156

woodKnots function

function woodKnots(seed: number, length: number, density: number): Knot[]

the knots of a plank of length L (m) by its seed: positions along it and radii, about density per metre. The same seed gives the same knots.

packages/destruction/src/wood.ts:68

woodModel function

function woodModel: FailureModel

packages/destruction/src/wood.ts:127

xform function

function xform: (m: ArrayLike<number>, p: Vec3) => Vec3

column-major 4x4 (Babylon's m): a model point to the world

packages/destruction/src/branches.ts:239

Interfaces

AssemblyPart interface

interface AssemblyPart
part: PartState
at: Vec3
attached: boolean

packages/destruction/src/assembly.ts:20

BarGeometry interface

interface BarGeometry
axis: number
loadAxis: number
widthAxis: number
length: numberm
depth: number
width: number
Z: numberm^3
I: numberm^4

packages/destruction/src/wood.ts:86

BarSupports interface

interface BarSupports
s0: number
s1: number

packages/destruction/src/wood.ts:105

BodyBox interface

interface BodyBox

a body as an upright box: its centre, half sizes (x across, y up, z along) and its yaw about y (world)

centre: Vec3
half: Vec3
yaw: number

packages/destruction/src/branches.ts:234

BodyLike interface

interface BodyLike

the part of a physics Body this capability reads

kind: string
mass: number
removed: boolean
position: Vec3
orientation: [number, number, number, number]
velocity?: Vec3

packages/destruction/src/capability.ts:10

Branch interface

interface Branch
id: number
parent: number
order: number
nodes: number[]the rings of the branch, from its base (on its parent) to its tip
length: number
diameter: numberdiameter at the base (m): the median of the rings in the first third, the junction ring left out

packages/destruction/src/branches.ts:27

BranchSpring interface

interface BranchSpring

a bent branch swinging back: x is the deflection at the lever (m, along dir), v its speed

x: number
v: number
dir: Vec3
omega: number
zeta: number

packages/destruction/src/branches.ts:306

BreakNoise interface

interface BreakNoise
part: string
point: Vec3
seed: number
loudness: number0..1
dust: number0..1
energy: numberJ
level: DebrisLevel
made: numberpieces made, and the mass of those not made, kg
dropped: number

packages/destruction/src/debris.ts:56

BreakRecord interface

interface BreakRecord

what travels to another machine for a break: enough to compute the same outcome (section 8)

id: string
part: string
style: string
seed: number
hit: Hit

packages/destruction/src/service.ts:69

Capability interface

interface Capability

the shape of a physics Capability (@ferret/physics) as this one provides it

readonly name: string
readonly phase: 'strength'
readonly order: number
readonly needsBodies: boolean
readonly cost: string
readonly defaults: Record<string, unknown>
enable(host: HostLike): void
disable(): void
step(dt: number, host: HostLike, contacts: readonly ContactLike[]): void

packages/destruction/src/capability.ts:19

CarBlock interface

interface CarBlock
name: string
mass: number
assembly: Assembly
chassis: string
layout: CarLayout
regions: Region[]
panes: GlassPane[]
zones: Record<string, CrushZone[]>
wheels: WheelSpec[]
centers: Record<string, Vec3>the centre of the chassis box (its mass centre is lower)
parts: PartState[]

packages/destruction/src/autoparts.ts:78

CarLayout interface

interface CarLayout
bodyMin: Vec3
bodyMax: Vec3
frontAxle: numberx of the front and the rear axle, m
rearAxle: number
radius: number
track: number
leftSign: numberthe z of the left side (the sign of the front-left wheel's z)
frontEnd: number
rearEnd: number
bumperTop: number
cowlX: number
cabinRearX: number
hoodHalf: number

packages/destruction/src/autoparts.ts:71

CarSpec interface

interface CarSpec
name: string
mass?: numberkg, the whole car; when missing it is the curb weight in CAR_MASS for the name (an unknown name without a mass throws)
nodes: NodeInfo[]

packages/destruction/src/autoparts.ts:63

Clutter interface

interface Clutter
group: number
count: number
mass: number
lo: Vec3
hi: Vec3

packages/destruction/src/debris.ts:82

CommandHost interface

interface CommandHost
register(name: string, description: string, fn: (args: any) => unknown | Promise<unknown>): void

packages/destruction/src/service.ts:33

Contact interface

interface Contact
normal: Vec3
depth: number
point: Vec3

packages/destruction/src/vehicle.ts:426

ContactInput interface

interface ContactInput

a contact as the capability gives it: world point, the normal from the other body toward this thing, closing speed, the other's mass (Infinity for the ground)

point: Vec3
normal: Vec3
speed: number
slide?: number
impulse?: number
otherMass: number
restitution: number
area?: number
step: number
rigidOther?: booleanthe other side is a wall, the ground, a fixed or kinematic body: infinite mass and stiffness (all of the hit's energy is this thing's), and the blow is spread over the whole face that meets it

packages/destruction/src/service.ts:74

ContactLike interface

interface ContactLike

the part of a physics ContactEvent it reads: normal points from b toward a

a: BodyLike
b: BodyLike
point: Vec3
normal: Vec3
impulse: number
speed: number
slide: number
restitution: number

packages/destruction/src/capability.ts:12

ContactOutcome interface

interface ContactOutcome
push: Vec3the body's correction (m, world): where it may not go
force: Vec3the force the branches put on the body (N, world)
held: booleanwhether the body is held (it could not push through): its speed into hold (unit) is to be taken away
hold: Vec3
bends: { contact: TreeContact; deflection: number }[]per contact: how far the branch is bent at its lever (m, along the contact's normal)
broke: TreeContact[]the contacts whose branch broke

packages/destruction/src/branches.ts:270

Controls interface

interface Controls
throttle: number
brake: number
steer: number

packages/destruction/src/vehicle.ts:125

CrushZone interface

interface CrushZone
id: string
axis: Vec3unit vector: the direction the zone crumples in, into the part
center: Vec3centre of the zone in the part's frame, m (where a dent is centred by default is the hit point; this is for hulls and views)
width: numberextent of the zone's face across the axis, m
height: number
dMax: numbermaximum depth, m: the zone is bottomed out here
area: numbereffective section area, m^2 (the plateau force is yield strength times this)
plateau: numberthe plateau force, N
curve: CurvePoint[]force-depth points from (0, 0) to (dMax, F); piecewise linear, x increasing
hardStiffness: numberN/m: stiffness past dMax, where the zone is a block
dentRadius: numberthe dent's default radius on the lattice, m

packages/destruction/src/crush.ts:41

CrushZoneInput interface

interface CrushZoneInput
id: string
axis: Vec3
center?: Vec3
width: number
height: number
dMax: numbermaximum depth, m (ignored when a custom curve is given: the curve's last depth is dMax)
thickness: numbersheet thickness, m; 0 means a solid section (all of width x height carries)
yieldStrength: numberPa; read from the part's material
loadShare?: numberoverride of CRUSH_LOAD_SHARE
curve?: CurvePoint[]a custom curve, from (0, 0) (added if missing) with depth increasing
dentRadius?: number

packages/destruction/src/crush.ts:54

CurvePoint interface

interface CurvePoint
x: number
f: number

packages/destruction/src/crush.ts:39

DebrisLod interface

interface DebrisLod
near: number
middle: number

packages/destruction/src/debris.ts:30

DebrisPiece interface

interface DebrisPiece
id: number
group: number
spec: PieceSpec
mode: DebrisMode
age: numberseconds since the break
still: numberseconds below DEBRIS_SLEEP_SPEED
asleep: numberseconds asleep
sleeping: boolean
merged: booleanjoined into its group's clutter: no longer a body
scale: number1..0 while fading
life: numberseconds, Infinity for a piece that stays
bodyUntil: numberseconds a body (Infinity: stays a body)
gone: boolean

packages/destruction/src/debris.ts:67

DebrisPlan interface

interface DebrisPlan
level: DebrisLevel
pieces: DebrisPiece[]
noise: BreakNoise

packages/destruction/src/debris.ts:81

Deceleration interface

interface Deceleration
depth: numberthe deepest the zone was pushed, m (beyond dMax only by the elastic give of the block)
time: numbertime to the deepest point, s
peak: numberthe largest deceleration, m/s^2
mean: numberthe mean deceleration to the stop, v0^2 / (2 depth), m/s^2
bottomed: booleanthe zone reached dMax and the body was stopped by the block

packages/destruction/src/crush.ts:176

DecelerationOptions interface

interface DecelerationOptions
from?: number
strengthScale?: number
dt?: number

packages/destruction/src/crush.ts:183

Destructible interface

interface Destructible

a thing that can break

id: string
entity: numberthe number the seeds are made from (a hash of the id unless given)
assembly: Assembly
zones: Record<string, CrushZone[]>crush zones of each part id
models: Record<string, string>model names to use for a part id instead of the kind's default
vehicle?: Vehicle
frame: { position: Vec3; rotation: Quat }where the thing is in the world; the part frame is this one (a vehicle uses its own pose)
lod: Lod
ledger: Ledgerthe sum of the ledgers of all the hits taken
explained: stringthe last explain text
last: Record<string, Outcome>the last outcome, by part
off: string[]parts that have come off, once each
lastStage: stringthe stage of the last hit
seen: booleanthe viewer can see it (debris levels)

packages/destruction/src/service.ts:51

DestructionCapability interface

interface DestructionCapability extends Capability
bind(id: string, body: Body): voidthe thing id of the service rides on this body: its pose is kept current and its contacts are the thing's hits
unbind(id: string): void
isBound(id: string): booleanthe thing rides a body of this capability (its vehicle is not to be stepped again by a view)
reset(): voidforget every binding and start the step count again (a new scene: the seeds of its hits come from the step number, so the same scene gives the same breaks)

packages/destruction/src/capability.ts:25

DestructionEvent interface

interface DestructionEvent
kind: DestructionEventKind
part: string
point: Vec3
energy: number
seed: number
detail?: string

packages/destruction/src/types.ts:81

DetachedBody interface

interface DetachedBody
id: string
mass: number
size: Vec3
position: Vec3
velocity: Vec3
angular: Vec3
rotation: Quat

packages/destruction/src/vehicle.ts:139

DiceOptions interface

interface DiceOptions extends Omit<PaneOptions, 'budget' | 'point'>
cell: numberthe natural cell edge, m (tempered glass: a few thicknesses)

packages/destruction/src/fracture.ts:180

FallingBranch interface

interface FallingBranch

a broken branch falling: its pivot's place and speed (world), its turn (axis-angle rate) and attitude (quaternion x, y, z, w)

p: Vec3
v: Vec3
q: [number, number, number, number]
w: Vec3
terminal: number
radius: number
resting: boolean
t: number

packages/destruction/src/branches.ts:321

FractureResult interface

interface FractureResult
pieces: PieceSpec[]
crackArea: numberthe crack area made, m^2
fractureEnergy: numbercrackArea * fractureEnergy, J
count: numberpieces made

packages/destruction/src/fracture.ts:25

GlassPane interface

interface GlassPane
id: string
kind: GlassKind
thickness: number
size: Vec3
parent: string

packages/destruction/src/autoparts.ts:70

GrainSplitOptions interface

interface GrainSplitOptions
size: Vec3the box that splits, full size, m
center?: Vec3its centre in the part frame (default 0)
grainAxis: numberaxis index (0 x, 1 y, 2 z) the grain runs along
splitAxis: numberaxis index the slabs are stacked along (the cut planes are normal to it; they contain the grain)
fractureEnergy: numberJ/m^2
mass: numberkg: the slabs' masses sum to this
seed: number

packages/destruction/src/fracture.ts:220

GridBlockOptions interface

interface GridBlockOptions
size: Vec3
center?: Vec3
mass: numberkg: the cells' masses sum to this
budget: numberJ available for new crack surface
fractureEnergy: numberJ/m^2
seed: number
maxPieces?: numbermost cells (default 12)
countScale?: numbera style's multiplier on the count (default 1)

packages/destruction/src/fracture.ts:264

Hit interface

interface Hit

one contact turned into the numbers a failure model needs (energy.ts makeHit)

point: Vec3world
normal: Vec3from the other body toward this part
speed: numberclosing speed along the normal, m/s
slide: numbersliding speed along the surface, m/s
impulse: numberthe normal impulse over the step, N*s
energy: numberthe energy available for damage to THIS part, J (the share its softness takes, energy.ts splitEnergy)
total: numberthe whole hit's energy before it was split between the two sides, J
massA: number
massB: number
area: numberthe contact area on this part, m^2
step: numberthe fixed step the hit happened in
seed: numberthe seed of this break (rng.ts breakSeed)

packages/destruction/src/types.ts:51

HitInput interface

interface HitInput
point: Vec3
normal: Vec3
speed: numberclosing speed along the normal, m/s
slide?: number
impulse?: number
massA: number
massB: number
restitution: numberthe restitution the contact was solved with
stiffThis?: numberstiffness of this part's side and of the other side, N/m (contactStiffness); equal if missing
stiffOther?: number
area: number
step: number
entity: numberthe entity (or body) number, for the seed
energyScale?: numbera style's multiplier on the energy (1: physical)

packages/destruction/src/energy.ts:36

HitResult interface

interface HitResult
record: BreakRecord
outcome: Outcome
detached: string[]
load: number
pieces: PieceSpec[]
dropped: number
plan: DebrisPlan | null
events: DestructionEvent[]
explain: string

packages/destruction/src/service.ts:71

HostLike interface

interface HostLike

the part of the physics host it uses

world: { events: { emit(name: string, payload: unknown): void }; commands: { register(name: string, description: string, fn: (args: any) => unknown): void } }
config(name: string): { get<T>(key: string, ctx: object): T }

packages/destruction/src/capability.ts:14

Hull interface

interface Hull

the bounds of a hull after dents, and where its centre has moved to (part frame)

size: Vec3
offset: Vec3

packages/destruction/src/crush.ts:367

Knot interface

interface Knot
pos: number
radius: number

packages/destruction/src/wood.ts:66

Ledger interface

interface Ledger

where the energy of a hit went, J. input = crush + fracture + kinetic + heat + sound + residual, within 1e-9 of the input (energy.ts balanced)

input: number
crush: number
fracture: number
kinetic: number
heat: number
sound: number
residual: number

packages/destruction/src/types.ts:66

LinkState interface

interface LinkState
id: string
to: string | nullthe part this link joins to, or null for the world
kind: 'weld' | 'bolt' | 'hinge' | 'nail' | 'glue' | 'clip'
holds: numberthe force it holds, N (tensile x area x count)
load: numberthe force it has taken over the last step, N
broken: boolean

packages/destruction/src/types.ts:27

MaterialProps interface

interface MaterialProps

the numbers of a substance a failure model reads (SI); material.ts fills the missing ones from the kind's typical substance

density: numberkg/m^3
youngModulus: numberPa
yieldStrength: numberPa: where it deforms for good (ductile)
tensileStrength: numberPa: where it tears or ruptures along its strong direction (brittle: modulus of rupture; fibrous: along the grain)
crossStrength: numberPa: across the grain (fibrous); equals tensileStrength for the rest
fractureEnergy: numberJ/m^2: the energy of a new crack surface (brittle, fibrous, crumbly)
restitution: number0 sticks, 1 perfectly elastic
kineticShare: numberthe share of a hit's energy that fragments carry away as motion (0..1)

packages/destruction/src/types.ts:16

MotionBridgeLike interface

interface MotionBridgeLike

the part of MotionBridge (@ferret/motion) this link uses

define(name: string, sig: { args: string[]; min?: number; rest?: string; returns?: string }, fn: (ctx: unknown, ...args: any[]) => unknown): unknown
readonly rt: { deliver(name: string, payload?: unknown): void }

packages/destruction/src/motion.ts:19

NodeInfo interface

interface NodeInfo

what the loader gives for a node of the model: its bounds in the car frame, and for a wheel its hub; area is the mesh's surface area (both faces of a thin shell counted, as a mesh has it)

name: string
min: Vec3
max: Vec3
origin?: Vec3
area?: number

packages/destruction/src/autoparts.ts:59

Outcome interface

interface Outcome

what a model returns for one hit on one part

ledger: Ledger
damage: Record<string, number>the part's damage after the hit (the whole record, not a delta)
pieces: PieceSpec[]
stage: stringthe stage reached: 'none' | 'dent' | 'star' | 'shards' | 'split' | 'crumble' ... (a model names its own)
broken: booleanthe part is gone (replaced by its pieces)
events: DestructionEvent[]

packages/destruction/src/types.ts:84

PaneOptions interface

interface PaneOptions
width: numberpane size in its plane, m
height: number
thickness: numberm
mass: numberkg: the pieces' masses sum to this
point: [number, number]impact point in the pane's plane, part frame, m
budget: numberJ available for new crack surface
fractureEnergy: numberJ/m^2
seed: number
maxPieces?: numbermost pieces (default 128)
countScale?: numbera style's multiplier on how rich the pattern may be (default 1; the cost may then pass the budget)
spread?: number0..1: how irregular the pattern is (0: the physical amount)

packages/destruction/src/fracture.ts:98

PartInput interface

interface PartInput
id: string
substance?: stringa substance name (glass-tempered), or a kind with material numbers
kind?: MaterialKind
material?: Partial<MaterialProps>
size: Vec3full size of the bounds, m
thickness?: numberthickness of a sheet or pane, m (0: solid)
mass?: numberkg; the density times the bounds' volume (times fill) when missing
fill?: numberthe share of the bounds' volume that is material (a car door is mostly air); 1 for a solid part
grain?: Vec3

packages/destruction/src/part.ts:6

PartState interface

interface PartState
id: string
kind: MaterialKind
material: MaterialProps
mass: numberkg
size: Vec3full size of the part's bounds, m (x, y, z in the part's own frame)
thickness: numberthickness of a sheet or pane, m (0: solid)
grain?: Vec3the grain direction in the part's frame (fibrous); a unit vector
damage: Record<string, number>named damage numbers a model keeps between hits: dent depth, crack stage, accumulated energy...
dents?: Float32Arraythe dent lattice (crush): control point offsets, x y z per point, in the part's frame, m
links: LinkState[]
broken: boolean

packages/destruction/src/types.ts:36

PieceSpec interface

interface PieceSpec

a piece that a break makes: a body, an instance or a particle by the level and the budget (debris)

shape: PieceShape
vertices?: Float32Arraya convex piece's vertices in the part's frame (hull, shard, splinter, chunk); absent for a box and dust
size: Vec3full size of the piece's bounds, m
offset: Vec3where its centre was in the part's frame, m
mass: numberkg
velocity: Vec3m/s, the part's own velocity at that point plus the share of the energy that flung it (not included: the part's velocity, the host adds it)
angular: Vec3rad/s

packages/destruction/src/types.ts:70

PlanOptions interface

interface PlanOptions
level: DebrisLevel
live: numberlive pieces and bodies in the world now
liveBodies: number
maxPieces: number
maxBodies: number
energy: numberJ, the hit's energy
point: Vec3
part: string
seed: number
group?: numbera heap the pieces belong to (a window's pieces, a wall's)
ctx: StyleContext
firstId?: numberthe first piece id (the world numbers them)

packages/destruction/src/debris.ts:84

PlateLoad interface

interface PlateLoad
force: number
stress: number
stiffness: number

packages/destruction/src/glass.ts:63

RayCaster interface

interface RayCaster

the one thing the vehicle asks of the world: a ray cast (the kernel's rayCast sits behind it in the engine); dir is a unit vector

cast(origin: Vec3, dir: Vec3, maxDistance: number): RayHit | null

packages/destruction/src/vehicle.ts:52

RayHit interface

interface RayHit
distance: numberdistance along the ray to the surface, m
normal: Vec3unit surface normal, pointing away from the ground
grip: numbera scale on the tyre's friction coefficient (1: the tyre's own; ice is under 1)
velocity?: Vec3velocity of the surface at the hit (a moving platform), m/s; zero if missing

packages/destruction/src/vehicle.ts:45

Region interface

interface Region
id: string
min: Vec3
max: Vec3

packages/destruction/src/autoparts.ts:69

ResolvedStyle interface

interface ResolvedStyle

a resolved style: the context the models read, the view's staging and the replacements

ctx: StyleContext
spec: StyleSpec
override: Record<string, string>
squash: boolean

packages/destruction/src/style.ts:25

ServiceOptions interface

interface ServiceOptions
maxPieces?: number
maxBodies?: number
nodesOf?: (asset: string) => NodeInfo[] | undefinedthe node list of a library model by asset name, for destruction.autoparts {asset} when the command gives no nodes

packages/destruction/src/service.ts:89

SkelNode interface

interface SkelNode

a ring of the bark: its centre and radius (model frame), its branch and how far it is along that branch from the branch's base (m)

p: Vec3
r: number
branch: number
s: number
parent: number
n: number

packages/destruction/src/branches.ts:26

Stream interface

interface Stream
rs: number

packages/destruction/src/rng.ts:13

StrikeInput interface

interface StrikeInput
point: Vec3world
normal: Vec3
speed: numberclosing speed along the normal, m/s
otherMass: number
restitution: number
area?: number
step: number
entity: number
style?: StyleContext

packages/destruction/src/vehicle.ts:140

StrikeResult interface

interface StrikeResult
part: string
ledger: Ledger
stage: string
detached: string[]
events: DestructionEvent[]
load: number

packages/destruction/src/vehicle.ts:146

StyleContext interface

interface StyleContext

the numbers of the style in force for this hit (style.ts resolves them; physical is all ones and conserve true)

name: string
energyScale: numberhits count this many times
strengthScale: numberwhat a part holds is multiplied by this
depthScale: numberdents are this much deeper
recover: number0..1: the share of a dent that springs back (rubber)
piecesScale: numbermore or fewer pieces
sizeSpread: number0..1: how varied the piece sizes are (0: the physical distribution)
burstScale: numberfragments fly this much faster
debrisBounce: numberdebris: restitution, seconds alive, gravity scale
debrisLife: number
debrisGravity: number
conserve: booleanfalse: the ledger may be broken (a style that says so, shown by explain)

packages/destruction/src/types.ts:94

StyleSpec interface

interface StyleSpec

the shape of a style as data (every field optional; a missing one is the physical value)

name: string
energy?: { scale?: number; conserve?: boolean }
strength?: { scale?: number }
crush?: { depthScale?: number; recover?: number; squash?: boolean }
fracture?: { piecesScale?: number; sizeSpread?: number; burstScale?: number }
debris?: { bounce?: number; life?: number; gravityScale?: number }
reaction?: { hitStop?: number; timeScale?: [number, number]; shake?: number }staging for the view (hit stop, slow motion, shake); the physics does not read it
override?: Record<string, string>a failure model replaced by name: key is a kind (brittle, fibrous, ductile, crumbly, rigid) or a part id, value is a registered model name

packages/destruction/src/style.ts:11

StyleZone interface

interface StyleZone
id: string
min: Vec3
max: Vec3
style: string

packages/destruction/src/style.ts:101

ThingBlock interface

interface ThingBlock

the destruction block of a manifest or a command (destruction.define-thing): parts, links, crush zones and glass panes of one thing

id: string
entity?: number
root: string
lod?: Lod
style?: string
parts: (Omit<PartInput, 'id'> & { id: string; at?: Vec3; glass?: GlassKind; model?: string })[]
links?: { part: string; to: string | null; kind: LinkState['kind']; holds?: number; tensile?: number; area?: number; count?: number }[]
zones?: Record<string, (Omit<CrushZoneInput, 'yieldStrength'> & { yieldStrength?: number })[]>by part id; the yield strength is the part's material's unless given

packages/destruction/src/service.ts:78

TreeBreakerOptions interface

interface TreeBreakerOptions
ground: (x: number, z: number) => numberthe ground's height (m) at x, z (the broken branches land on it)
maxLive?: numberat most this many trees live as meshes of their own (default 48)
maxFallen?: numberat most this many branches falling or lying (default 40)
lie?: numberseconds a fallen branch lies before it goes (default 40)

packages/destruction/src/view-trees.ts:52

TreeContact interface

interface TreeContact

one branch of one tree in contact: where (world), how deep the body is in it, along which outward normal (world, unit, from the body), its stiffness and breaking force there

branch: number
node: number
point: Vec3
depth: number
normal: Vec3
lever: number
k: number
fBreak: number

packages/destruction/src/branches.ts:236

TreeKind interface

interface TreeKind
id: string
skeleton: TreeSkeleton
parts: Part[]
leafy: Set<number>

packages/destruction/src/view-trees.ts:42

TreeMesh interface

interface TreeMesh
positions: ArrayLike<number>
indices: ArrayLike<number>

packages/destruction/src/branches.ts:24

TreeSkeleton interface

interface TreeSkeleton
nodes: SkelNode[]
branches: Branch[]
vertexBranch: Uint16Array
height: number
foot: Vec3

packages/destruction/src/branches.ts:35

TreeStep interface

interface TreeStep
held: boolean
hold: Vec3
push: Vec3
broke: number
touching: number

packages/destruction/src/view-trees.ts:62

VehicleSpec interface

interface VehicleSpec
assembly: Assembly
chassis: stringthe part that carries the rest (its box is the body's hull)
wheels: WheelSpec[]
zones?: Record<string, CrushZone[]>the crush zones of each part (autoparts), for the shrunk collider
model?: FailureModelthe failure model that turns a hit into damage of a part (crushModel of autoparts)
driveTorque?: numberN m at each driven wheel at full throttle; default: a quarter of g x mass x radius over the driven wheels
brakeTorque?: numberN m at each wheel at full brake; default: friction limit of the static load
friction?: numbera ground friction coefficient for the tyres
centers?: Record<string, Vec3>the centre of a part's BOX in the car frame where it is not the part's centre of mass (the chassis: its mass centre is low, its box is the whole body); default: the part's own place

packages/destruction/src/vehicle.ts:127

VoronoiOptions interface

interface VoronoiOptions
size: Vec3the block, full size, m
center?: Vec3its centre in the part frame (default 0)
mass: numberkg: the cells' masses sum to this
point: Vec3the impact point, part frame: cells are denser near it
budget: numberJ available for new crack surface
fractureEnergy: numberJ/m^2
seed: number
maxPieces?: numbermost cells (default 48)
countScale?: numbera style's multiplier on the count (default 1)

packages/destruction/src/fracture.ts:468

WheelSpec interface

interface WheelSpec
id: stringthe wheel's part id in the assembly
mount: Vec3x and z of the hub in the car frame, m (the height of the suspension top is worked out from the static load: y here is ignored); the ray starts at the top of the suspension and points down the body's -y axis
radius: number
width: number
steer: boolean
drive: boolean

packages/destruction/src/vehicle.ts:111

WheelState interface

interface WheelState
spec: WheelSpec
mount: Vec3top of the suspension in the car frame: x and z of the spec, and the height at which the spring stands at its static length with the hub on the ground
attached: booleanfalse once the wheel has come off: no ray, no force
spin: numberrad/s
k: numberN/m
c: number
onGround: boolean
load: number
length: number

packages/destruction/src/vehicle.ts:117

Types

DebrisLevel type

type DebrisLevel = 'near' | 'middle' | 'far' | 'unseen'

packages/destruction/src/debris.ts:27

DebrisMode type

type DebrisMode = 'body' | 'instance' | 'particle'

packages/destruction/src/debris.ts:28

DestructionEventKind type

type DestructionEventKind = 'damage' | 'dent' | 'crack' | 'break' | 'detach' | 'link-break' | 'shatter' | 'splinter' | 'crumble' | 'settle'

packages/destruction/src/types.ts:80

FailureModel type

type FailureModel = (hit: Hit, part: PartState, ctx: StyleContext) => Outcome

a failure model: a pure function of the hit, the part and the style; the seed is hit.seed. A style may replace a model by name (style.ts).

packages/destruction/src/types.ts:111

GlassKind type

type GlassKind = keyof typeof GLASS_KIND

packages/destruction/src/glass.ts:36

Lod type

type Lod = 'near' | 'middle' | 'far' | 'unseen'

packages/destruction/src/service.ts:36

MaterialKind type

type MaterialKind = 'brittle' | 'fibrous' | 'ductile' | 'crumbly' | 'rigid'

how a material fails: brittle (glass, ceramic, stone, ice), fibrous (wood), ductile (sheet metal, plastic), crumbly (brick, plaster, concrete), rigid (never fails)

packages/destruction/src/types.ts:12

PieceShape type

type PieceShape = 'box' | 'hull' | 'shard' | 'splinter' | 'chunk' | 'dust'

packages/destruction/src/types.ts:68

Quat type

type Quat = [number, number, number, number]

packages/destruction/src/types.ts:9

Vec3 type

type Vec3 = [number, number, number]

packages/destruction/src/types.ts:8

Constants

ACCESSORY_FILL const

const ACCESSORY_FILL: 0.02

the share of the volume of a small fitted accessory's bounds that is material (a light bar, a speaker)

packages/destruction/src/autoparts.ts:30

ADHESIVE_TENSILE const

const ADHESIVE_TENSILE: 5000000

packages/destruction/src/autoparts.ts:46

AREA_M10 const

const AREA_M10: 0.000058

packages/destruction/src/autoparts.ts:48

AREA_M12 const

const AREA_M12: 0.0000843

packages/destruction/src/autoparts.ts:48

AREA_M6 const

const AREA_M6: 0.0000201

stress areas of ISO metric bolts, m^2

packages/destruction/src/autoparts.ts:48

AREA_M8 const

const AREA_M8: 0.0000366

packages/destruction/src/autoparts.ts:48

BARE_TERMINAL const

const BARE_TERMINAL: 14

packages/destruction/src/branches.ts:41

BASE_LIFE const

const BASE_LIFE: 8

base life of a small piece, seconds, times ctx.debrisLife (tuning constant)

packages/destruction/src/debris.ts:45

BEAD_WIDTH const

const BEAD_WIDTH: 0.01

the width of the adhesive bead and of the window seal's grip, m

packages/destruction/src/autoparts.ts:54

BIG_BREAK const

const BIG_BREAK: 2000

a far break makes dust only from this energy, J (tuning constant)

packages/destruction/src/debris.ts:51

BODY_SECONDS const

const BODY_SECONDS: 1

seconds a middle-distance piece stays a body before it becomes an instance

packages/destruction/src/debris.ts:33

BOLT_TENSILE const

const BOLT_TENSILE: 800000000

handbook strengths of the fixings, Pa: grade 8.8 bolt, spot-weld nugget (as the sheet's tensile strength is used), polyurethane windscreen adhesive, window channel seal

packages/destruction/src/autoparts.ts:46

BUMP_STOP_FACTOR const

const BUMP_STOP_FACTOR: 20

the bump stop is this many times stiffer than the spring

packages/destruction/src/vehicle.ts:81

BUMPER_DEPTH_FRACTION const

const BUMPER_DEPTH_FRACTION: 0.25

where the bumper starts, as a share of the overhang beyond the axle; its height as a share of the body's height

packages/destruction/src/autoparts.ts:40

BUMPER_HEIGHT_FRACTION const

const BUMPER_HEIGHT_FRACTION: 0.4

packages/destruction/src/autoparts.ts:40

BUMPER_LOAD_SHARE const

const BUMPER_LOAD_SHARE: 0.05

packages/destruction/src/autoparts.ts:34

BUMPER_THICKNESS const

const BUMPER_THICKNESS: 0.002

thickness of a bumper's steel reinforcement beam and cover, m

packages/destruction/src/autoparts.ts:24

CAR_CONTACT_AREA const

const CAR_CONTACT_AREA: 0.1

a hit that was not given an area gets this one on the car, m^2

packages/destruction/src/vehicle.ts:105

CAR_MASS const

const CAR_MASS: Record<string, number>

curb weights of the real models, kg: the 1987 police-package sedan (about 4000 lb) and the 1987 convertible (about 3300 lb); chosen by the lead with the owner's consent (2026-11-12)

packages/destruction/src/autoparts.ts:61

CHASSIS const

const CHASSIS: "Chassis"

packages/destruction/src/autoparts.ts:56

CHASSIS_SECTION const

const CHASSIS_SECTION: 0.0015

effective section thickness of the chassis frame that carries a crush zone, m (rails and fold lines: a modelling constant; the plateau force is yield x this x the load share)

packages/destruction/src/autoparts.ts:26

CHIP_ZONE_DEPTHS const

const CHIP_ZONE_DEPTHS: 0.5

the length of the chip zone at the break plane, in section depths (tuning constant)

packages/destruction/src/wood.ts:56

CHIPS_MAX const

const CHIPS_MAX: 12

packages/destruction/src/wood.ts:58

COM_FRONT_BIAS const

const COM_FRONT_BIAS: 0.1

the centre of mass of the chassis (the structure with the engine and drivetrain): ahead of the middle of the wheelbase by this share of it, at this share of the body's top height

packages/destruction/src/autoparts.ts:42

COM_HEIGHT_RATIO const

const COM_HEIGHT_RATIO: 0.4

packages/destruction/src/autoparts.ts:42

COMPRESSION_RATIO const

const COMPRESSION_RATIO: 0.5

compressive strength along the grain over the modulus of rupture (clear wood, about one half; tuning constant)

packages/destruction/src/wood.ts:48

CRUSH_BOTTOM_FORCE_RATIO const

const CRUSH_BOTTOM_FORCE_RATIO: 6

the force at dMax is this many times the plateau force (the bottomed-out branch is stiff)

packages/destruction/src/crush.ts:24

CRUSH_BOTTOM_FRACTION const

const CRUSH_BOTTOM_FRACTION: 0.85

the plateau ends (the zone starts to bottom out) at this fraction of dMax

packages/destruction/src/crush.ts:22

CRUSH_DT const

const CRUSH_DT: number

the fixed step of decelerationAlong, s

packages/destruction/src/crush.ts:34

CRUSH_HARD_FACTOR const

const CRUSH_HARD_FACTOR: 50

past dMax the zone is a solid block: its stiffness is this many times the slope of the bottoming-out branch

packages/destruction/src/crush.ts:26

CRUSH_LOAD_SHARE const

const CRUSH_LOAD_SHARE: 0.25

share of the section's perimeter that lies in the load path (rails and fold lines rather than skin) when the effective area is built from a sheet thickness: a modelling constant, not a measured one

packages/destruction/src/crush.ts:18

CRUSH_ONSET_FRACTION const

const CRUSH_ONSET_FRACTION: 0.03

the stiff first branch of the default curve ends (the plateau starts) at this fraction of dMax

packages/destruction/src/crush.ts:20

crushModel const

const crushModel: FailureModel

the ductile failure model with no zones given: a default zone along the hit's normal (defaultZoneFor)

packages/destruction/src/crush.ts:363

DEBRIS_BOUNCE const

const DEBRIS_BOUNCE: 0.3

packages/destruction/src/service.ts:45

DEBRIS_GRAVITY const

const DEBRIS_GRAVITY: 9.81

the cheap fall of pieces that are not bodies (and of bodies when the host gives no speeds): gravity, m/s^2

packages/destruction/src/service.ts:43

DEBRIS_GROUND_FRICTION const

const DEBRIS_GROUND_FRICTION: 0.6

the share of its speed along the ground that a piece keeps when it lands, and of its vertical speed that it bounces with (before the style's debrisBounce)

packages/destruction/src/service.ts:45

DEBRIS_LOD const

const DEBRIS_LOD: DebrisLod

packages/destruction/src/debris.ts:31

DEBRIS_SLEEP_SPEED const

const DEBRIS_SLEEP_SPEED: 0.05

m/s below which a piece counts as still

packages/destruction/src/debris.ts:35

DEBRIS_SLEEP_TIME const

const DEBRIS_SLEEP_TIME: 0.5

seconds a piece must stay still to sleep

packages/destruction/src/debris.ts:37

DEFAULT_MAX_BODIES const

const DEFAULT_MAX_BODIES: 50

bodies alive at once among the pieces (the tier table's maxShardBodies): a tuning constant, a quarter of the piece cap

packages/destruction/src/service.ts:41

DEFAULT_MAX_PIECES const

const DEFAULT_MAX_PIECES: 200

pieces alive at once over the world (the tier table's maxPieces, as the strength capability's default)

packages/destruction/src/service.ts:39

DENT_DIMS const

const DENT_DIMS: [number, number, number]

the default dent lattice, points along x, y, z of the part (about 5 x 3 x 3 per panel)

packages/destruction/src/crush.ts:36

DENT_MIN_RADIUS_SPACINGS const

const DENT_MIN_RADIUS_SPACINGS: 1.5

a lattice dent never gets a radius below this many grid spacings, so that it always lands on control points

packages/destruction/src/crush.ts:28

DESTRUCTION_EVENTS const

const DESTRUCTION_EVENTS: readonly string[]

the events of the service delivered to programs: the destruction: names the service announces

packages/destruction/src/motion.ts:27

DICE_THICKNESSES const

const DICE_THICKNESSES: 3

a tempered pane dices into cells of this many thicknesses (tuning constant)

packages/destruction/src/glass.ts:50

DUST_BUDGET_SHARE const

const DUST_BUDGET_SHARE: 0.4

the share of the crack budget dust may take (tuning constant)

packages/destruction/src/stone.ts:39

DUST_GRAIN const

const DUST_GRAIN: 0.0002

the size of a dust grain, m (tuning constant)

packages/destruction/src/stone.ts:37

DUST_PUFFS const

const DUST_PUFFS: 6

how many dust puffs the dust of one break is merged into at most

packages/destruction/src/stone.ts:41

END_GRAIN_COS const

const END_GRAIN_COS: 0.7

|n . axis| from which a hit is an end-grain hit

packages/destruction/src/wood.ts:42

FADE_TIME const

const FADE_TIME: 1.5

seconds a fading piece takes to shrink to nothing

packages/destruction/src/debris.ts:47

FENDER_LOAD_SHARE const

const FENDER_LOAD_SHARE: 0.07

packages/destruction/src/autoparts.ts:34

FILL_BUMPER const

const FILL_BUMPER: 2

packages/destruction/src/autoparts.ts:28

FILL_DOOR const

const FILL_DOOR: 4

packages/destruction/src/autoparts.ts:28

FILL_FENDER const

const FILL_FENDER: 1

packages/destruction/src/autoparts.ts:28

FILL_HOOD const

const FILL_HOOD: 2

each panel's mass is density x thickness x face area x fill: the fill stands for inner panels, stiffeners and fittings (a hood or door is far more than its skin)

packages/destruction/src/autoparts.ts:28

FILL_SOFT_TOP const

const FILL_SOFT_TOP: 5

packages/destruction/src/autoparts.ts:28

FILL_TRUNK const

const FILL_TRUNK: 2

packages/destruction/src/autoparts.ts:28

FRAME_LOAD_SHARE const

const FRAME_LOAD_SHARE: 0.12

The share of a zone's section (thickness x perimeter of its face) that carries load when it crumples along the car's length, per load path of a frontal or rear impact (modelling constants). The paths act in PARALLEL, so their plateau forces add: for the crown-victoria they are about 285 kN (frame), 125 kN (bumper beam), 70 kN (hood) and 40 kN each (fenders), 560 kN together; at 15 m/s (54 km/h) a 1.8 t car then stops in about 0.4 m, which is what barrier tests of cars of this class show (0.4 to 0.5 m of crush at 56 km/h). The side, roof and door zones keep the general share. These four numbers are a CALIBRATION (tuning constants chosen for that stop depth), not measured values.

packages/destruction/src/autoparts.ts:34

FRONT_CRUSH_FRACTION const

const FRONT_CRUSH_FRACTION: 0.7

crush depths as shares of what lies there: front and rear of the overhang past the axle; the sides of the half width; the roof of the body's height

packages/destruction/src/autoparts.ts:44

GLASS_FRACTURE_SHARE const

const GLASS_FRACTURE_SHARE: 0.6

the share of a hit's energy that may go into the crack surface of a break (tuning constant)

packages/destruction/src/glass.ts:48

GLASS_KIND const

const GLASS_KIND: { readonly annealed: 0; readonly tempered: 1; readonly laminated: 2; }

packages/destruction/src/glass.ts:35

GLASS_MAX_PIECES const

const GLASS_MAX_PIECES: 128

packages/destruction/src/glass.ts:51

GLASS_POISSON const

const GLASS_POISSON: 0.22

Poisson's ratio of glass

packages/destruction/src/glass.ts:38

GRAVITY const

const GRAVITY: 9.81

packages/destruction/src/vehicle.ts:73

GREEN_WOOD const

const GREEN_WOOD: { modulus: number; rupture: number; density: number; }

packages/destruction/src/branches.ts:37

HOOD_LOAD_SHARE const

const HOOD_LOAD_SHARE: 0.08

packages/destruction/src/autoparts.ts:34

HULL_FRICTION const

const HULL_FRICTION: 0.6

friction of the body's metal on the ground

packages/destruction/src/vehicle.ts:95

HULL_MIN_DEPTH const

const HULL_MIN_DEPTH: 0.05

the collider hull is not rebuilt for dents shallower than this, m (a rebuild per scratch would be a waste)

packages/destruction/src/crush.ts:30

HULL_MIN_FRACTION const

const HULL_MIN_FRACTION: 0.2

a hull never shrinks below this share of its size along an axis

packages/destruction/src/crush.ts:32

HULL_PROBE const

const HULL_PROBE: 0.3

the ray of a hull corner starts this high above the corner, m

packages/destruction/src/vehicle.ts:97

HULL_SAG const

const HULL_SAG: 0.02

the hull touches the ground like a hard pad: static sag of a corner under a quarter of the weight, m

packages/destruction/src/vehicle.ts:93

KIND_DEFAULT const

const KIND_DEFAULT: Record<MaterialKind, string>

the substance a kind stands for when nothing more is said

packages/destruction/src/material.ts:30

KNOT_DENSITY const

const KNOT_DENSITY: 1

knots per metre of a plank, when the part does not say (tuning constant: timber has about one a metre)

packages/destruction/src/wood.ts:44

KNOT_LOSS const

const KNOT_LOSS: 1.5

how much a knot weakens the section at its centre: loss = KNOT_LOSS x knot diameter / depth, at most 0.7 (tuning constant)

packages/destruction/src/wood.ts:46

LAMINATE_THROUGH const

const LAMINATE_THROUGH: 3

a laminated pane breaks through at this multiple of its failure stress (tuning constant: the film carries the pane; 3 means 9 x the energy)

packages/destruction/src/glass.ts:42

LAMINATED_GLASS_THICKNESS const

const LAMINATED_GLASS_THICKNESS: 0.0055

packages/destruction/src/autoparts.ts:38

LEAF_DAMPING const

const LEAF_DAMPING: 0.18

the damping ratio of a branch in leaf swinging back (tuning constant: a branch rings a few times)

packages/destruction/src/branches.ts:39

LEAFY_TERMINAL const

const LEAFY_TERMINAL: 4

m/s: the terminal speed of a falling branch in leaf and of a bare one (tuning constants: a leafy bough drifts, a stick drops)

packages/destruction/src/branches.ts:41

LODS const

const LODS: readonly Lod[]

packages/destruction/src/service.ts:37

LOUD_ENERGY const

const LOUD_ENERGY: 10000

the hit energy that is a loudness of 1, J (tuning constant: a heavy crash)

packages/destruction/src/debris.ts:49

MATERIAL_KINDS const

const MATERIAL_KINDS: readonly MaterialKind[]

packages/destruction/src/types.ts:13

MAX_BRANCHES const

const MAX_BRANCHES: 1024

the most branches a tree is analysed into (the branch index is a vertex attribute and a row of a texture)

packages/destruction/src/branches.ts:43

MAX_STEER const

const MAX_STEER: 0.5

steering lock, rad

packages/destruction/src/vehicle.ts:91

MERGE_DELAY const

const MERGE_DELAY: 1

seconds a sleeper waits before it may merge into the clutter of its group

packages/destruction/src/debris.ts:39

MERGE_MIN const

const MERGE_MIN: 3

the least sleepers in a group for a clutter to be made

packages/destruction/src/debris.ts:41

MIN_LOAD_FRACTION const

const MIN_LOAD_FRACTION: 0.02

the least distance of a load from a support, as a share of the span (the beam formula is not meant for a load at the support; tuning constant)

packages/destruction/src/wood.ts:52

MORTAR_SLIP const

const MORTAR_SLIP: 0.005

how far a mortar joint slips before it lets go, m (tuning constant; the work of tearing it is holds x this)

packages/destruction/src/stone.ts:43

NAIL_DEPTH const

const NAIL_DEPTH: 0.03

how deep a nail sits, m (tuning constant)

packages/destruction/src/wood.ts:62

PANEL_THICKNESS const

const PANEL_THICKNESS: 0.0008

thickness of body sheet, m (typical automotive outer panel)

packages/destruction/src/autoparts.ts:22

PHYSICAL const

const PHYSICAL: StyleContext

packages/destruction/src/types.ts:106

POROUS_DENSITY const

const POROUS_DENSITY: 2000

bulk density above which a crumbly material is taken as solid (no dust by default), kg/m^3 (tuning constant: the guess of porosity)

packages/destruction/src/stone.ts:35

PRESETS const

const PRESETS: Record<string, StyleSpec>

the shipped presets (plan section 4)

packages/destruction/src/style.ts:62

RESTING_SPEED const

const RESTING_SPEED: 0.3

closing speed under which two cars in contact are resting and do each other no damage, m/s (the plan's impact threshold)

packages/destruction/src/vehicle.ts:103

RIGID_STRENGTH const

const RIGID_STRENGTH: 1000000000000000

a part of kind rigid holds against anything: its strengths are this (Pa)

packages/destruction/src/material.ts:34

ROOF_CRUSH_FRACTION const

const ROOF_CRUSH_FRACTION: 0.12

packages/destruction/src/autoparts.ts:44

ROTATION_SHARE const

const ROTATION_SHARE: 0.1

the share of the pieces' kinetic energy that is rotation (the rest is translation)

packages/destruction/src/fracture.ts:591

SEAL_TENSILE const

const SEAL_TENSILE: 1000000

packages/destruction/src/autoparts.ts:46

SIDE_CRUSH_FRACTION const

const SIDE_CRUSH_FRACTION: 0.3

packages/destruction/src/autoparts.ts:44

SIDE_GLASS_THICKNESS const

const SIDE_GLASS_THICKNESS: 0.004

thickness of glass, m: side panes (tempered) and windscreen (laminated), typical

packages/destruction/src/autoparts.ts:38

SLIP_REFERENCE_SPEED const

const SLIP_REFERENCE_SPEED: 2

the speed below which slip is measured against this one (a stopped car has no slip ratio), m/s

packages/destruction/src/vehicle.ts:85

SLIP_SATURATION const

const SLIP_SATURATION: 0.15

slip at which a tyre reaches its friction limit (longitudinal ratio and lateral slope)

packages/destruction/src/vehicle.ts:83

SMALL_MASS const

const SMALL_MASS: 0.05

a piece is small below this mass, kg, and fades; larger ones stay (tuning constant)

packages/destruction/src/debris.ts:43

SPLINTER_LENGTH_DEPTHS const

const SPLINTER_LENGTH_DEPTHS: 2.5

the length of a long splinter, in section depths (tuning constant)

packages/destruction/src/wood.ts:54

SPLINTER_SHARE const

const SPLINTER_SHARE: 0.5

the share of the energy left after the break plane that the splinter cuts may take (tuning constant; the chips get the rest)

packages/destruction/src/wood.ts:60

SPLINTERS_MAX const

const SPLINTERS_MAX: 6

packages/destruction/src/wood.ts:57

SPOT_WELD_DIAMETER const

const SPOT_WELD_DIAMETER: 0.006

the diameter of a spot weld nugget, m

packages/destruction/src/autoparts.ts:52

STAR_FRACTION const

const STAR_FRACTION: 0.7

the stress ratio from which a hit leaves a star (tuning constant: cracks start before the pane gives way)

packages/destruction/src/glass.ts:40

STAR_SHARE const

const STAR_SHARE: 0.3

the share of a hit's energy a star's cracks may take (tuning constant)

packages/destruction/src/glass.ts:46

STAR_WEAKEN const

const STAR_WEAKEN: 0.3

how much a full star weakens the pane for the next hit (tuning constant)

packages/destruction/src/glass.ts:44

STONE_FRACTURE_SHARE const

const STONE_FRACTURE_SHARE: 0.7

the share of a hit's energy that may go into crack surface (tuning constant)

packages/destruction/src/stone.ts:33

STONE_MAX_PIECES const

const STONE_MAX_PIECES: 32

the most cells of one break (tuning constant: the cell build costs about n^1.4, 32 cells take under 2 ms, 48 about 3 ms; stone.maxPieces raises it for one part)

packages/destruction/src/stone.ts:31

STRIKER_DIAMETER const

const STRIKER_DIAMETER: 0.008

a door latch's striker pin, m (diameter)

packages/destruction/src/autoparts.ts:50

STYLE_PRESET_NAMES const

const STYLE_PRESET_NAMES: string[]

the shipped style names, for a game's menu

packages/destruction/src/service.ts:485

SUBSTANCES const

const SUBSTANCES: Record<string, { kind: MaterialKind; props: MaterialProps; }>

substance -> its kind and numbers. Strengths in Pa, fracture energy in J/m^2.

packages/destruction/src/material.ts:11

SUSPENSION_DAMPING const

const SUSPENSION_DAMPING: 0.4

suspension damping as a share of critical

packages/destruction/src/vehicle.ts:77

SUSPENSION_FREQUENCY const

const SUSPENSION_FREQUENCY: 1.2

suspension natural frequency on the sprung weight, Hz (passenger car range)

packages/destruction/src/vehicle.ts:75

SUSPENSION_TRAVEL const

const SUSPENSION_TRAVEL: 0.35

total spring travel from full droop to the bump stop, m

packages/destruction/src/vehicle.ts:79

TEMPERED_MAX_PIECES const

const TEMPERED_MAX_PIECES: 400

packages/destruction/src/glass.ts:52

TYRE_FRICTION const

const TYRE_FRICTION: 1

tyre friction coefficient on a normal surface (dry asphalt, handbook range 0.8 to 1)

packages/destruction/src/vehicle.ts:87

VEHICLE_SLEEP_ANGULAR const

const VEHICLE_SLEEP_ANGULAR: 0.03

packages/destruction/src/vehicle.ts:100

VEHICLE_SLEEP_LINEAR const

const VEHICLE_SLEEP_LINEAR: 0.03

a car sleeps when it has moved no faster than these (m/s, rad/s) for VEHICLE_SLEEP_TIME seconds

packages/destruction/src/vehicle.ts:99

VEHICLE_SLEEP_TIME const

const VEHICLE_SLEEP_TIME: 0.6

packages/destruction/src/vehicle.ts:101

WHEEL_EFFECTIVE_DENSITY const

const WHEEL_EFFECTIVE_DENSITY: 280

effective density of a wheel with its tyre over the cylinder it fills, kg/m^3 (a tyre is mostly air)

packages/destruction/src/autoparts.ts:36

WHEEL_INERTIA const

const WHEEL_INERTIA: 1.5

spin inertia of a wheel with its tyre and brake, kg m^2

packages/destruction/src/vehicle.ts:89

WHEEL_ROLL_AXIS const

const WHEEL_ROLL_AXIS: Vec3

the right-handed rotation axis, in the car frame, of a wheel that rolls forward (+x) on the ground (+y up): up x forward, along -z. A wheel turned by spin x dt radians about it moves its top toward the front.

packages/destruction/src/vehicle.ts:110

WOOD_FRACTURE_SHARE const

const WOOD_FRACTURE_SHARE: 0.6

the share of a hit's energy that may go into crack surface (tuning constant)

packages/destruction/src/wood.ts:50