@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.
Read the guide: how to use it →
Classes
Assembly class
class Assemblyreadonly 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 |
packages/destruction/src/assembly.ts:22
DebrisWorld class
class DebrisWorldpieces: 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[] |
packages/destruction/src/debris.ts:162
DestructionService class
class DestructionServicereadonly 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 |
packages/destruction/src/service.ts:94
GroundPlane class
class GroundPlane implements RayCastera 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 StyleBookthe 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 |
packages/destruction/src/style.ts:77
StyleScopes class
class StyleScopesworld: 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 |
packages/destruction/src/style.ts:102
TreeBreaker class
class TreeBreakerlast: { 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() |
packages/destruction/src/view-trees.ts:64
Vehicle class
class Vehiclereadonly 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. |
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): voidDisplace 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) => Ledgerthe 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 } = {}): TreeSkeletonThe 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): OutcomeOne 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): Uint16Arraythe 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): booleanthe 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): numberthe 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): BarGeometrythe 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): numberthe 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) => numberN: 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) => numberkg: 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)): Float32ArrayThe 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) => numberN/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]) => numberthe 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): CarBlockpackages/destruction/src/autoparts.ts:143
carModel function
function carModel(block: CarBlock, others: Partial<Record<MaterialKind, FailureModel>> = {}): FailureModela 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> = {}): Vehiclethe 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) => numberthe 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): Outcomeclose 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 } | nullTwo 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) => numberthe 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) => numberthe crack area that the given energy can make, m^2
packages/destruction/src/fracture.ts:23
crackEnergy function
function crackEnergy: (area: number, fractureEnergy: number) => numberthe 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): numberhow 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): booleanthe 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): numberthe 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) => numberthe 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): numberthe 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): numberthe 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) => DebrisLevelpackages/destruction/src/debris.ts:53
decelerationAlong function
function decelerationAlong(zone: CrushZone, mass: number, v0: number, opt: DecelerationOptions = {}): Decelerationa 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): CrushZoneA 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) => numberthe 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): numberthe 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): numberthe 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): DestructionCapabilitythe 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): FractureResulta 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
explainHit function
function explainHit(style: ResolvedStyle, hit: Hit, outcome: Outcome): stringdestruction.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): MaterialPropsthe 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): numberSet 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): numberthe 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): GlassKindpackages/destruction/src/glass.ts:54
glassModel function
function glassModel: FailureModelpackages/destruction/src/glass.ts:95
grainSplit function
function grainSplit(o: GrainSplitOptions, n: number): FractureResultsplit 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): numberthe 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): FractureResultthe 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): FractureResulta 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[]): RayCasterseveral grounds as one: the nearest hit wins
packages/destruction/src/vehicle.ts:68
hash32 function
function hash32: (x: number) => numberpackages/destruction/src/rng.ts:5
hashRand function
function hashRand: (seed: number, a: number, b?: number) => numbera 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): numberthe 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: FailureModelthe 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 | nullseparating 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): numberthe 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) => numbera 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): () => voidRegisters 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) => numberthe 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[]): FailureModelthe 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): CrushZonea 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]): Float32Arraya 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): Hita contact turned into the numbers a failure model reads. A resting contact (speed 0) has no energy.
packages/destruction/src/energy.ts:49
makeLink function
function makeLink(id: string, to: string | null, kind: LinkState['kind'], holds: number): LinkStatepackages/destruction/src/assembly.ts:15
makePart function
function makePart(i: PartInput): PartStatepackages/destruction/src/part.ts:19
newLedger function
function newLedger: (input: number) => Ledgerpackages/destruction/src/energy.ts:59
newStream function
function newStream: (seed: number, salt?: number) => Streampackages/destruction/src/rng.ts:14
pieceKinetic function
function pieceKinetic(pieces: PieceSpec[]): numberthe 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[]) => numberthe sum of the pieces' masses, kg
packages/destruction/src/fracture.ts:604
planDebris function
function planDebris(pieces: PieceSpec[], o: PlanOptions): DebrisPlandecide 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): PlateLoadthe 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): Quatthe quaternion of a rotation of angle radians about a unit axis
packages/destruction/src/vehicle.ts:41
qConj function
function qConj: (q: Quat) => Quatpackages/destruction/src/vehicle.ts:33
qIdentity function
function qIdentity: () => Quatpackages/destruction/src/vehicle.ts:26
qMul function
function qMul(a: Quat, b: Quat): Quatpackages/destruction/src/vehicle.ts:27
qRot function
function qRot(q: Quat, v: Vec3): Vec3rotate a vector by a unit quaternion
packages/destruction/src/vehicle.ts:35
radialPane function
function radialPane(o: PaneOptions): FractureResultthe 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): numberthe 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): stringwhich 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): ContactOutcomewhat 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): ResolvedStylepackages/destruction/src/style.ts:34
rnd function
function rnd(s: Stream): numberthe next number in [0, 1) of a stream (mulberry32)
packages/destruction/src/rng.ts:16
rnorm function
function rnorm(s: Stream): numbera standard normal number (Box-Muller; two draws)
packages/destruction/src/rng.ts:25
rrange function
function rrange: (s: Stream, lo: number, hi: number) => numberpackages/destruction/src/rng.ts:23
sampleDent function
function sampleDent(lattice: Float32Array, size: Vec3, point: Vec3, dims: [number, number, number] = DENT_DIMS): Vec3the 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>) => numberthe 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): numbergive 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) => numberpackages/destruction/src/branches.ts:45
sectionModulus function
function sectionModulus: (w: number, h: number) => numbersection 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) => numberthe state of a stream from a seed (never 0)
packages/destruction/src/rng.ts:11
setGlassKind function
function setGlassKind(part: PartState, kind: GlassKind): voidset the kind on a part (writes glass.kind)
packages/destruction/src/glass.ts:59
settle function
function settle(l: Ledger, soundShare = 0.02): Ledgerwhatever 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>): HullThe 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): numberspend 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) => numberwhat 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): BranchSpringpackages/destruction/src/branches.ts:307
startFall function
function startFall(p: Vec3, v: Vec3, leafy: boolean, radius: number, seed: number): FallingBranchpackages/destruction/src/branches.ts:322
stepFall function
function stepFall(f: FallingBranch, dt: number, ground: (x: number, z: number) => number, gravity = 9.81): voidone step; ground(x, z) the height there
packages/destruction/src/branches.ts:327
stepPiece function
function stepPiece(p: DebrisPiece, dt: number, speed: number): booleanadvance 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): booleanone 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) => numberthe 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: FailureModelpackages/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): FractureResultVoronoi 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): numberthe 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): numberthe 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): booleanwake 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: FailureModelpackages/destruction/src/wood.ts:127
xform function
function xform: (m: ArrayLike<number>, p: Vec3) => Vec3column-major 4x4 (Babylon's m): a model point to the world
packages/destruction/src/branches.ts:239
Interfaces
AssemblyPart interface
interface AssemblyPartpackages/destruction/src/assembly.ts:20
BarGeometry interface
interface BarGeometryaxis: number | |
loadAxis: number | |
widthAxis: number | |
length: number | m |
depth: number | |
width: number | |
Z: number | m^3 |
I: number | m^4 |
packages/destruction/src/wood.ts:86
BarSupports interface
interface BarSupportss0: number | |
s1: number |
packages/destruction/src/wood.ts:105
BodyBox interface
interface BodyBoxa body as an upright box: its centre, half sizes (x across, y up, z along) and its yaw about y (world)
packages/destruction/src/branches.ts:234
BodyLike interface
interface BodyLikethe 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 Branchid: number | |
parent: number | |
order: number | |
nodes: number[] | the rings of the branch, from its base (on its parent) to its tip |
length: number | |
diameter: number | diameter 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 BranchSpringa 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 BreakNoisepart: string | |
point: Vec3 | |
seed: number | |
loudness: number | 0..1 |
dust: number | 0..1 |
energy: number | J |
level: DebrisLevel | |
made: number | pieces made, and the mass of those not made, kg |
dropped: number |
packages/destruction/src/debris.ts:56
BreakRecord interface
interface BreakRecordwhat 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 Capabilitythe 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 CarBlockname: 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 CarLayoutbodyMin: Vec3 | |
bodyMax: Vec3 | |
frontAxle: number | x of the front and the rear axle, m |
rearAxle: number | |
radius: number | |
track: number | |
leftSign: number | the 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 CarSpecname: string | |
mass?: number | kg, 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 Clutterpackages/destruction/src/debris.ts:82
CommandHost interface
interface CommandHostregister(name: string, description: string, fn: (args: any) => unknown | Promise<unknown>): void |
packages/destruction/src/service.ts:33
Contact interface
interface Contactpackages/destruction/src/vehicle.ts:426
ContactInput interface
interface ContactInputa 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?: boolean | the 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 ContactLikethe 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 ContactOutcomepush: Vec3 | the body's correction (m, world): where it may not go |
force: Vec3 | the force the branches put on the body (N, world) |
held: boolean | whether 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 Controlsthrottle: number | |
brake: number | |
steer: number |
packages/destruction/src/vehicle.ts:125
CrushZone interface
interface CrushZoneid: string | |
axis: Vec3 | unit vector: the direction the zone crumples in, into the part |
center: Vec3 | centre 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: number | extent of the zone's face across the axis, m |
height: number | |
dMax: number | maximum depth, m: the zone is bottomed out here |
area: number | effective section area, m^2 (the plateau force is yield strength times this) |
plateau: number | the plateau force, N |
curve: CurvePoint[] | force-depth points from (0, 0) to (dMax, F); piecewise linear, x increasing |
hardStiffness: number | N/m: stiffness past dMax, where the zone is a block |
dentRadius: number | the dent's default radius on the lattice, m |
packages/destruction/src/crush.ts:41
CrushZoneInput interface
interface CrushZoneInputid: string | |
axis: Vec3 | |
center?: Vec3 | |
width: number | |
height: number | |
dMax: number | maximum depth, m (ignored when a custom curve is given: the curve's last depth is dMax) |
thickness: number | sheet thickness, m; 0 means a solid section (all of width x height carries) |
yieldStrength: number | Pa; read from the part's material |
loadShare?: number | override 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 CurvePointx: number | |
f: number |
packages/destruction/src/crush.ts:39
DebrisLod interface
interface DebrisLodnear: number | |
middle: number |
packages/destruction/src/debris.ts:30
DebrisPiece interface
interface DebrisPieceid: number | |
group: number | |
spec: PieceSpec | |
mode: DebrisMode | |
age: number | seconds since the break |
still: number | seconds below DEBRIS_SLEEP_SPEED |
asleep: number | seconds asleep |
sleeping: boolean | |
merged: boolean | joined into its group's clutter: no longer a body |
scale: number | 1..0 while fading |
life: number | seconds, Infinity for a piece that stays |
bodyUntil: number | seconds a body (Infinity: stays a body) |
gone: boolean |
packages/destruction/src/debris.ts:67
DebrisPlan interface
interface DebrisPlanlevel: DebrisLevel | |
pieces: DebrisPiece[] | |
noise: BreakNoise |
packages/destruction/src/debris.ts:81
Deceleration interface
interface Decelerationdepth: number | the deepest the zone was pushed, m (beyond dMax only by the elastic give of the block) |
time: number | time to the deepest point, s |
peak: number | the largest deceleration, m/s^2 |
mean: number | the mean deceleration to the stop, v0^2 / (2 depth), m/s^2 |
bottomed: boolean | the zone reached dMax and the body was stopped by the block |
packages/destruction/src/crush.ts:176
DecelerationOptions interface
interface DecelerationOptionsfrom?: number | |
strengthScale?: number | |
dt?: number |
packages/destruction/src/crush.ts:183
Destructible interface
interface Destructiblea thing that can break
id: string | |
entity: number | the 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: Ledger | the sum of the ledgers of all the hits taken |
explained: string | the last explain text |
last: Record<string, Outcome> | the last outcome, by part |
off: string[] | parts that have come off, once each |
lastStage: string | the stage of the last hit |
seen: boolean | the viewer can see it (debris levels) |
packages/destruction/src/service.ts:51
DestructionCapability interface
interface DestructionCapability extends Capabilitybind(id: string, body: Body): void | the 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): boolean | the thing rides a body of this capability (its vehicle is not to be stepped again by a view) |
reset(): void | forget 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 DestructionEventkind: DestructionEventKind | |
part: string | |
point: Vec3 | |
energy: number | |
seed: number | |
detail?: string |
packages/destruction/src/types.ts:81
DetachedBody interface
interface DetachedBodypackages/destruction/src/vehicle.ts:139
DiceOptions interface
interface DiceOptions extends Omit<PaneOptions, 'budget' | 'point'>cell: number | the natural cell edge, m (tempered glass: a few thicknesses) |
packages/destruction/src/fracture.ts:180
FallingBranch interface
interface FallingBrancha 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 FractureResultpieces: PieceSpec[] | |
crackArea: number | the crack area made, m^2 |
fractureEnergy: number | crackArea * fractureEnergy, J |
count: number | pieces made |
packages/destruction/src/fracture.ts:25
GlassPane interface
interface GlassPanepackages/destruction/src/autoparts.ts:70
GrainSplitOptions interface
interface GrainSplitOptionssize: Vec3 | the box that splits, full size, m |
center?: Vec3 | its centre in the part frame (default 0) |
grainAxis: number | axis index (0 x, 1 y, 2 z) the grain runs along |
splitAxis: number | axis index the slabs are stacked along (the cut planes are normal to it; they contain the grain) |
fractureEnergy: number | J/m^2 |
mass: number | kg: the slabs' masses sum to this |
seed: number |
packages/destruction/src/fracture.ts:220
GridBlockOptions interface
interface GridBlockOptionssize: Vec3 | |
center?: Vec3 | |
mass: number | kg: the cells' masses sum to this |
budget: number | J available for new crack surface |
fractureEnergy: number | J/m^2 |
seed: number | |
maxPieces?: number | most cells (default 12) |
countScale?: number | a style's multiplier on the count (default 1) |
packages/destruction/src/fracture.ts:264
Hit interface
interface Hitone contact turned into the numbers a failure model needs (energy.ts makeHit)
point: Vec3 | world |
normal: Vec3 | from the other body toward this part |
speed: number | closing speed along the normal, m/s |
slide: number | sliding speed along the surface, m/s |
impulse: number | the normal impulse over the step, N*s |
energy: number | the energy available for damage to THIS part, J (the share its softness takes, energy.ts splitEnergy) |
total: number | the whole hit's energy before it was split between the two sides, J |
massA: number | |
massB: number | |
area: number | the contact area on this part, m^2 |
step: number | the fixed step the hit happened in |
seed: number | the seed of this break (rng.ts breakSeed) |
packages/destruction/src/types.ts:51
HitInput interface
interface HitInputpoint: Vec3 | |
normal: Vec3 | |
speed: number | closing speed along the normal, m/s |
slide?: number | |
impulse?: number | |
massA: number | |
massB: number | |
restitution: number | the restitution the contact was solved with |
stiffThis?: number | stiffness of this part's side and of the other side, N/m (contactStiffness); equal if missing |
stiffOther?: number | |
area: number | |
step: number | |
entity: number | the entity (or body) number, for the seed |
energyScale?: number | a style's multiplier on the energy (1: physical) |
packages/destruction/src/energy.ts:36
HitResult interface
interface HitResultrecord: 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 HostLikethe 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 Hullthe bounds of a hull after dents, and where its centre has moved to (part frame)
packages/destruction/src/crush.ts:367
Knot interface
interface Knotpos: number | |
radius: number |
packages/destruction/src/wood.ts:66
Ledger interface
interface Ledgerwhere 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 LinkStateid: string | |
to: string | null | the part this link joins to, or null for the world |
kind: 'weld' | 'bolt' | 'hinge' | 'nail' | 'glue' | 'clip' | |
holds: number | the force it holds, N (tensile x area x count) |
load: number | the force it has taken over the last step, N |
broken: boolean |
packages/destruction/src/types.ts:27
MaterialProps interface
interface MaterialPropsthe numbers of a substance a failure model reads (SI); material.ts fills the missing ones from the kind's typical substance
density: number | kg/m^3 |
youngModulus: number | Pa |
yieldStrength: number | Pa: where it deforms for good (ductile) |
tensileStrength: number | Pa: where it tears or ruptures along its strong direction (brittle: modulus of rupture; fibrous: along the grain) |
crossStrength: number | Pa: across the grain (fibrous); equals tensileStrength for the rest |
fractureEnergy: number | J/m^2: the energy of a new crack surface (brittle, fibrous, crumbly) |
restitution: number | 0 sticks, 1 perfectly elastic |
kineticShare: number | the share of a hit's energy that fragments carry away as motion (0..1) |
packages/destruction/src/types.ts:16
MotionBridgeLike interface
interface MotionBridgeLikethe 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 NodeInfowhat 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)
packages/destruction/src/autoparts.ts:59
Outcome interface
interface Outcomewhat 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: string | the stage reached: 'none' | 'dent' | 'star' | 'shards' | 'split' | 'crumble' ... (a model names its own) |
broken: boolean | the part is gone (replaced by its pieces) |
events: DestructionEvent[] |
packages/destruction/src/types.ts:84
PaneOptions interface
interface PaneOptionswidth: number | pane size in its plane, m |
height: number | |
thickness: number | m |
mass: number | kg: the pieces' masses sum to this |
point: [number, number] | impact point in the pane's plane, part frame, m |
budget: number | J available for new crack surface |
fractureEnergy: number | J/m^2 |
seed: number | |
maxPieces?: number | most pieces (default 128) |
countScale?: number | a style's multiplier on how rich the pattern may be (default 1; the cost may then pass the budget) |
spread?: number | 0..1: how irregular the pattern is (0: the physical amount) |
packages/destruction/src/fracture.ts:98
PartInput interface
interface PartInputid: string | |
substance?: string | a substance name (glass-tempered), or a kind with material numbers |
kind?: MaterialKind | |
material?: Partial<MaterialProps> | |
size: Vec3 | full size of the bounds, m |
thickness?: number | thickness of a sheet or pane, m (0: solid) |
mass?: number | kg; the density times the bounds' volume (times fill) when missing |
fill?: number | the 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 PartStateid: string | |
kind: MaterialKind | |
material: MaterialProps | |
mass: number | kg |
size: Vec3 | full size of the part's bounds, m (x, y, z in the part's own frame) |
thickness: number | thickness of a sheet or pane, m (0: solid) |
grain?: Vec3 | the 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?: Float32Array | the 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 PieceSpeca piece that a break makes: a body, an instance or a particle by the level and the budget (debris)
shape: PieceShape | |
vertices?: Float32Array | a convex piece's vertices in the part's frame (hull, shard, splinter, chunk); absent for a box and dust |
size: Vec3 | full size of the piece's bounds, m |
offset: Vec3 | where its centre was in the part's frame, m |
mass: number | kg |
velocity: Vec3 | m/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: Vec3 | rad/s |
packages/destruction/src/types.ts:70
PlanOptions interface
interface PlanOptionslevel: DebrisLevel | |
live: number | live pieces and bodies in the world now |
liveBodies: number | |
maxPieces: number | |
maxBodies: number | |
energy: number | J, the hit's energy |
point: Vec3 | |
part: string | |
seed: number | |
group?: number | a heap the pieces belong to (a window's pieces, a wall's) |
ctx: StyleContext | |
firstId?: number | the first piece id (the world numbers them) |
packages/destruction/src/debris.ts:84
PlateLoad interface
interface PlateLoadforce: number | |
stress: number | |
stiffness: number |
packages/destruction/src/glass.ts:63
RayCaster interface
interface RayCasterthe 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
packages/destruction/src/vehicle.ts:52
RayHit interface
interface RayHitdistance: number | distance along the ray to the surface, m |
normal: Vec3 | unit surface normal, pointing away from the ground |
grip: number | a scale on the tyre's friction coefficient (1: the tyre's own; ice is under 1) |
velocity?: Vec3 | velocity of the surface at the hit (a moving platform), m/s; zero if missing |
packages/destruction/src/vehicle.ts:45
Region interface
interface Regionpackages/destruction/src/autoparts.ts:69
ResolvedStyle interface
interface ResolvedStylea 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 ServiceOptionsmaxPieces?: number | |
maxBodies?: number | |
nodesOf?: (asset: string) => NodeInfo[] | undefined | the 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 SkelNodea 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 Streamrs: number |
packages/destruction/src/rng.ts:13
StrikeInput interface
interface StrikeInputpoint: Vec3 | world |
normal: Vec3 | |
speed: number | closing 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 StrikeResultpart: string | |
ledger: Ledger | |
stage: string | |
detached: string[] | |
events: DestructionEvent[] | |
load: number |
packages/destruction/src/vehicle.ts:146
StyleContext interface
interface StyleContextthe numbers of the style in force for this hit (style.ts resolves them; physical is all ones and conserve true)
name: string | |
energyScale: number | hits count this many times |
strengthScale: number | what a part holds is multiplied by this |
depthScale: number | dents are this much deeper |
recover: number | 0..1: the share of a dent that springs back (rubber) |
piecesScale: number | more or fewer pieces |
sizeSpread: number | 0..1: how varied the piece sizes are (0: the physical distribution) |
burstScale: number | fragments fly this much faster |
debrisBounce: number | debris: restitution, seconds alive, gravity scale |
debrisLife: number | |
debrisGravity: number | |
conserve: boolean | false: the ledger may be broken (a style that says so, shown by explain) |
packages/destruction/src/types.ts:94
StyleSpec interface
interface StyleSpecthe 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 StyleZonepackages/destruction/src/style.ts:101
ThingBlock interface
interface ThingBlockthe 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 TreeBreakerOptionsground: (x: number, z: number) => number | the ground's height (m) at x, z (the broken branches land on it) |
maxLive?: number | at most this many trees live as meshes of their own (default 48) |
maxFallen?: number | at most this many branches falling or lying (default 40) |
lie?: number | seconds a fallen branch lies before it goes (default 40) |
packages/destruction/src/view-trees.ts:52
TreeContact interface
interface TreeContactone 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
packages/destruction/src/branches.ts:236
TreeKind interface
interface TreeKindid: string | |
skeleton: TreeSkeleton | |
parts: Part[] | |
leafy: Set<number> |
packages/destruction/src/view-trees.ts:42
TreeMesh interface
interface TreeMeshpositions: ArrayLike<number> | |
indices: ArrayLike<number> |
packages/destruction/src/branches.ts:24
TreeSkeleton interface
interface TreeSkeletonpackages/destruction/src/branches.ts:35
TreeStep interface
interface TreeSteppackages/destruction/src/view-trees.ts:62
VehicleSpec interface
interface VehicleSpecassembly: Assembly | |
chassis: string | the 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?: FailureModel | the failure model that turns a hit into damage of a part (crushModel of autoparts) |
driveTorque?: number | N m at each driven wheel at full throttle; default: a quarter of g x mass x radius over the driven wheels |
brakeTorque?: number | N m at each wheel at full brake; default: friction limit of the static load |
friction?: number | a 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 VoronoiOptionssize: Vec3 | the block, full size, m |
center?: Vec3 | its centre in the part frame (default 0) |
mass: number | kg: the cells' masses sum to this |
point: Vec3 | the impact point, part frame: cells are denser near it |
budget: number | J available for new crack surface |
fractureEnergy: number | J/m^2 |
seed: number | |
maxPieces?: number | most cells (default 48) |
countScale?: number | a style's multiplier on the count (default 1) |
packages/destruction/src/fracture.ts:468
WheelSpec interface
interface WheelSpecid: string | the wheel's part id in the assembly |
mount: Vec3 | x 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 WheelStatespec: WheelSpec | |
mount: Vec3 | top 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: boolean | false once the wheel has come off: no ray, no force |
spin: number | rad/s |
k: number | N/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) => Outcomea 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_KINDpackages/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.02the 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: 5000000packages/destruction/src/autoparts.ts:46
AREA_M10 const
const AREA_M10: 0.000058packages/destruction/src/autoparts.ts:48
AREA_M12 const
const AREA_M12: 0.0000843packages/destruction/src/autoparts.ts:48
AREA_M6 const
const AREA_M6: 0.0000201stress areas of ISO metric bolts, m^2
packages/destruction/src/autoparts.ts:48
AREA_M8 const
const AREA_M8: 0.0000366packages/destruction/src/autoparts.ts:48
BARE_TERMINAL const
const BARE_TERMINAL: 14packages/destruction/src/branches.ts:41
BASE_LIFE const
const BASE_LIFE: 8base life of a small piece, seconds, times ctx.debrisLife (tuning constant)
packages/destruction/src/debris.ts:45
BEAD_WIDTH const
const BEAD_WIDTH: 0.01the 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: 2000a far break makes dust only from this energy, J (tuning constant)
packages/destruction/src/debris.ts:51
BODY_SECONDS const
const BODY_SECONDS: 1seconds a middle-distance piece stays a body before it becomes an instance
packages/destruction/src/debris.ts:33
BOLT_TENSILE const
const BOLT_TENSILE: 800000000handbook 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: 20the 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.25where 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.4packages/destruction/src/autoparts.ts:40
BUMPER_LOAD_SHARE const
const BUMPER_LOAD_SHARE: 0.05packages/destruction/src/autoparts.ts:34
BUMPER_THICKNESS const
const BUMPER_THICKNESS: 0.002thickness 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.1a 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.0015effective 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.5the 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: 12packages/destruction/src/wood.ts:58
COM_FRONT_BIAS const
const COM_FRONT_BIAS: 0.1the 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.4packages/destruction/src/autoparts.ts:42
COMPRESSION_RATIO const
const COMPRESSION_RATIO: 0.5compressive 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: 6the 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.85the 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: numberthe fixed step of decelerationAlong, s
packages/destruction/src/crush.ts:34
CRUSH_HARD_FACTOR const
const CRUSH_HARD_FACTOR: 50past 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.25share 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.03the 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: FailureModelthe 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.3packages/destruction/src/service.ts:45
DEBRIS_GRAVITY const
const DEBRIS_GRAVITY: 9.81the 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.6the 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: DebrisLodpackages/destruction/src/debris.ts:31
DEBRIS_SLEEP_SPEED const
const DEBRIS_SLEEP_SPEED: 0.05m/s below which a piece counts as still
packages/destruction/src/debris.ts:35
DEBRIS_SLEEP_TIME const
const DEBRIS_SLEEP_TIME: 0.5seconds a piece must stay still to sleep
packages/destruction/src/debris.ts:37
DEFAULT_MAX_BODIES const
const DEFAULT_MAX_BODIES: 50bodies 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: 200pieces 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.5a 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: 3a 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.4the share of the crack budget dust may take (tuning constant)
packages/destruction/src/stone.ts:39
DUST_GRAIN const
const DUST_GRAIN: 0.0002the size of a dust grain, m (tuning constant)
packages/destruction/src/stone.ts:37
DUST_PUFFS const
const DUST_PUFFS: 6how 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.5seconds a fading piece takes to shrink to nothing
packages/destruction/src/debris.ts:47
FENDER_LOAD_SHARE const
const FENDER_LOAD_SHARE: 0.07packages/destruction/src/autoparts.ts:34
FILL_BUMPER const
const FILL_BUMPER: 2packages/destruction/src/autoparts.ts:28
FILL_DOOR const
const FILL_DOOR: 4packages/destruction/src/autoparts.ts:28
FILL_FENDER const
const FILL_FENDER: 1packages/destruction/src/autoparts.ts:28
FILL_HOOD const
const FILL_HOOD: 2each 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: 5packages/destruction/src/autoparts.ts:28
FILL_TRUNK const
const FILL_TRUNK: 2packages/destruction/src/autoparts.ts:28
FRAME_LOAD_SHARE const
const FRAME_LOAD_SHARE: 0.12The 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.7crush 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.6the 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: 128packages/destruction/src/glass.ts:51
GLASS_POISSON const
const GLASS_POISSON: 0.22Poisson's ratio of glass
packages/destruction/src/glass.ts:38
GRAVITY const
const GRAVITY: 9.81packages/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.08packages/destruction/src/autoparts.ts:34
HULL_FRICTION const
const HULL_FRICTION: 0.6friction of the body's metal on the ground
packages/destruction/src/vehicle.ts:95
HULL_MIN_DEPTH const
const HULL_MIN_DEPTH: 0.05the 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.2a 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.3the 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.02the 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: 1knots 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.5how 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: 3a 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.0055packages/destruction/src/autoparts.ts:38
LEAF_DAMPING const
const LEAF_DAMPING: 0.18the 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: 4m/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
LINK_GIVE const
const LINK_GIVE: 0.02the elastic give of the links of a part that has taken a hit, m: the residual energy of a hit over this length is the force on its links (E = F x)
packages/destruction/src/vehicle.ts:107
LODS const
const LODS: readonly Lod[]packages/destruction/src/service.ts:37
LOUD_ENERGY const
const LOUD_ENERGY: 10000the 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: 1024the 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.5steering lock, rad
packages/destruction/src/vehicle.ts:91
MERGE_DELAY const
const MERGE_DELAY: 1seconds 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: 3the 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.02the 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.005how 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.03how deep a nail sits, m (tuning constant)
packages/destruction/src/wood.ts:62
PANEL_THICKNESS const
const PANEL_THICKNESS: 0.0008thickness of body sheet, m (typical automotive outer panel)
packages/destruction/src/autoparts.ts:22
PHYSICAL const
const PHYSICAL: StyleContextpackages/destruction/src/types.ts:106
POROUS_DENSITY const
const POROUS_DENSITY: 2000bulk 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.3closing 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: 1000000000000000a 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.12packages/destruction/src/autoparts.ts:44
ROTATION_SHARE const
const ROTATION_SHARE: 0.1the 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: 1000000packages/destruction/src/autoparts.ts:46
SIDE_CRUSH_FRACTION const
const SIDE_CRUSH_FRACTION: 0.3packages/destruction/src/autoparts.ts:44
SIDE_GLASS_THICKNESS const
const SIDE_GLASS_THICKNESS: 0.004thickness of glass, m: side panes (tempered) and windscreen (laminated), typical
packages/destruction/src/autoparts.ts:38
SLIP_REFERENCE_SPEED const
const SLIP_REFERENCE_SPEED: 2the 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.15slip 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.05a 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.5the length of a long splinter, in section depths (tuning constant)
packages/destruction/src/wood.ts:54
SPLINTER_SHARE const
const SPLINTER_SHARE: 0.5the 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: 6packages/destruction/src/wood.ts:57
SPOT_WELD_DIAMETER const
const SPOT_WELD_DIAMETER: 0.006the diameter of a spot weld nugget, m
packages/destruction/src/autoparts.ts:52
STAR_FRACTION const
const STAR_FRACTION: 0.7the 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.3the 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.3how 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.7the 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: 32the 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.008a 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.4suspension damping as a share of critical
packages/destruction/src/vehicle.ts:77
SUSPENSION_FREQUENCY const
const SUSPENSION_FREQUENCY: 1.2suspension natural frequency on the sprung weight, Hz (passenger car range)
packages/destruction/src/vehicle.ts:75
SUSPENSION_TRAVEL const
const SUSPENSION_TRAVEL: 0.35total spring travel from full droop to the bump stop, m
packages/destruction/src/vehicle.ts:79
TEMPERED_MAX_PIECES const
const TEMPERED_MAX_PIECES: 400packages/destruction/src/glass.ts:52
TYRE_FRICTION const
const TYRE_FRICTION: 1tyre 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.03packages/destruction/src/vehicle.ts:100
VEHICLE_SLEEP_LINEAR const
const VEHICLE_SLEEP_LINEAR: 0.03a 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.6packages/destruction/src/vehicle.ts:101
WHEEL_EFFECTIVE_DENSITY const
const WHEEL_EFFECTIVE_DENSITY: 280effective 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.5spin 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: Vec3the 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.6the share of a hit's energy that may go into crack surface (tuning constant)
packages/destruction/src/wood.ts:50