# @ferret/physics: API (continued)

### PhysicsKernel

*interface* · `packages/physics/src/kernel.ts:180`

```ts
interface PhysicsKernel
```

- `readonly name: string`
- `readonly caps: KernelCaps`
- `gravity: Vec3`
- `readonly bodies: readonly Body[]`
- `readonly constraints: readonly Constraint[]`
- `step(dt: number): void`
- `addBody(def: BodyDef): Body`
- `removeBody(b: Body): void`
- `addConstraint(def: ConstraintDef): Constraint`
- `removeConstraint(c: Constraint): void`
- `onConstraintBreak(cb: (c: Constraint) => void): () => void` — Called after the step for each constraint whose force passed its limit; the constraint is already removed.
- `applyForce(b: Body, f: Vec3, at?: Vec3): void`
- `applyImpulse(b: Body, j: Vec3, at?: Vec3): void`
- `applyTorque(b: Body, t: Vec3): void`
- `setVelocity(b: Body, v: Vec3): void`
- `setPosition(b: Body, p: Vec3): void`
- `sleep(b: Body): void`
- `wake(b: Body): void`
- `addForceField(fn: (b: Body, h: number) => Vec3 | FieldForce | null): () => void` — A force that depends on where a body is (gravity, drag, buoyancy): evaluated at the position of every sub-step, so a fast or orbiting body gets the force it feels where it is, not where it was at the start of the step. Returns newtons, or null for none.
- `beforeSolve(cb: (c: Contact) => void): () => void` — Called for every contact before it is solved, so a capability can change friction or restitution.
- `onContact(cb: (e: ContactEvent) => void): () => void` — Called after the step with what each contact did.
- `rayCast(origin: Vec3, dir: Vec3, maxDistance: number): KernelRayHit | null`
- `setMassProperties?(b: Body, mass: number, centreOfMass: Vec3, inertia: Vec3): void` — Mass, centre of mass (body space) and principal inertia set from outside (a vessel whose tanks fill); where the kernel can.
- `setSurface?(b: Body, s: { friction: number; kineticFriction: number; restitution: number }): void` — A body's own friction and restitution, over its material's: how a kernel without contact hooks takes a capability's dials.

### PhysicsMaterial

*interface* · `packages/physics/src/materials.ts:6`

```ts
interface PhysicsMaterial
```

Physical materials as data. A value that is not given means "this capability does not apply to it", not a default: a body with
no strength cannot break. The few values a contact cannot do without (friction, restitution) have library defaults, stated here.

- `density?: number`
- `friction?: number`
- `kineticFriction?: number`
- `rollingFriction?: number`
- `pivotFriction?: number`
- `restitution?: number`
- `youngModulus?: number`
- `yieldStrength?: number`
- `tensileStrength?: number`
- `toughness?: number`
- `[property: string]: number | undefined`

### PhysicsOptions

*interface* · `packages/physics/src/physics.ts:52`

```ts
interface PhysicsOptions
```

- `layers?: string[]`

### Piece

*interface* · `packages/physics/src/shapes.ts:122`

```ts
interface Piece
```

- `shape: Shape`
- `position: Vec3`
- `volume: number`

### RayHit

*interface* · `packages/physics/src/physics.ts:25`

```ts
interface RayHit
```

- `point: BABYLON.Vector3`
- `normal: BABYLON.Vector3`
- `distance: number`
- `mesh: BABYLON.AbstractMesh`
- `entity?: Entity`

### RigidBodyParams

*interface* · `packages/physics/src/host.ts:83`

```ts
interface RigidBodyParams
```

- `shape?: 'sphere' | 'box' | 'plane' | 'capsule' | 'cylinder'`
- `radius?: number`
- `height?: number` — capsule and cylinder: the length along y (a capsule's between the centres of its caps)
- `geometry?: Shape` — any shape the kernel has (a hull, a compound, a mesh): wins over `shape`
- `size?: [number, number, number]` — box: full size, like Collider
- `normal?: Vec3`
- `offset?: number`
- `mass?: number` — kg; taken from the material density and the shape when missing
- `material?: string`
- `kind?: BodyKind`
- `linearDamping?: number`
- `angularDamping?: number`
- `gravityScale?: number`
- `velocity?: Vec3`
- `angularVelocity?: Vec3`
- `lockRotation?: boolean`
- `rotate?: boolean` — Turn the node with the body (a rolling ball); off for a body whose node is a model that should stay upright.

### ScopeContext

*interface* · `packages/physics/src/host.ts:40`

```ts
interface ScopeContext
```

Where a value is asked from: an entity, or just a place (a zone covers it).

- `entity?: Entity | string`
- `position?: Vec3`

### ShapeSamples

*interface* · `packages/physics/src/shapes.ts:68`

```ts
interface ShapeSamples
```

- `points: Vec3[]` — cell centres inside the shape, body space
- `cell: Vec3` — the cell's edges along x, y, z, m
- `volume: number` — the volume each point stands for, m³ (the shape's volume over the count, so the sum is exact where the volume is known)

### StepResult

*interface* · `packages/physics/src/walkers.ts:57`

```ts
interface StepResult
```

- `landed: number` — he landed this step, at this speed (m/s); 0 otherwise
- `splash: number` — he went into the water this step, falling at this speed (m/s); 0 otherwise
- `blocked: boolean` — a wall stopped his move

### Support

*interface* · `packages/physics/src/walkers.ts:17`

```ts
interface Support
```

- `name: string`
- `clears?: boolean` — a bridge: where it gives ground, walls of other supports do not stop a man (a gangway through a rail, a ramp over a fender)
- `query(x: number, z: number, feet: number, maxStep: number, reach: number, out: SupportHit): void` — the ground a body can step onto from `feet` (the highest walkable top <= feet + maxStep) and whether something solid blocks him (a top between feet + maxStep and feet + reach)
- `frame?: { toLocal(p: Vec3): Vec3; toWorld(p: Vec3): Vec3 }` — a moving support: world <-> its own frame, so a man on it is carried

### SupportHit

*interface* · `packages/physics/src/walkers.ts:15`

```ts
interface SupportHit
```

- `ground: number | null`
- `wall: boolean`

### TierBudget

*interface* · `packages/physics/src/budget.ts:13`

```ts
interface TierBudget
```

- `stepMs: number` — the share of a frame the whole physics step may take, milliseconds
- `maxPieces: number` — pieces alive at once (the strength capability's `maxPieces`)
- `fluidParticles: number` — particles of all liquids, and of all cloths: for the game to give the capabilities that take such a budget
- `clothParticles: number`
- `flowSources: number` — flow sources the level's field takes (`FlowField.maxSources`) and the cells of flow boxes solved per physics step, all boxes together
- `flowBoxCells: number`

### TriggerEvent

*interface* · `packages/physics/src/physics.ts:24`

```ts
interface TriggerEvent
```

- `trigger: Entity`
- `other: Entity`

### Walker

*interface* · `packages/physics/src/walkers.ts:27`

```ts
interface Walker
```

- `x: number`
- `y: number`
- `z: number`
- `vx: number` — velocity of a body in the air, m/s
- `vy: number`
- `vz: number`
- `support: Support | null` — what he stands on (null in the air) and where on it, in its own frame (when it moves)
- `local: Vec3 | null`
- `air: boolean` — feet off the ground
- `depth: number` — water over his feet, m (0 on dry land): the game decides what a deep one means
- `swim: boolean` — afloat: in water too deep to stand in, he floats with his head out and swims by the move asked of him

### WalkersOptions

*interface* · `packages/physics/src/walkers.ts:42`

```ts
interface WalkersOptions
```

- `gravity?: number`
- `maxStep?: number` — the highest step a man climbs, m (default 0.45)
- `maxDrop?: number` — the drop he walks down without falling, m (default 0.6)
- `reach?: number` — how high above his feet a wall must reach to stop him, m (default 2.2)
- `water?: (x: number, z: number) => number | null` — the water surface at (x, z), m, or null for none (land)
- `sink?: number` — the speed a man sinks at in water, m/s (default 1.2)
- `swimDepth?: number` — water deeper than this over his feet and he cannot stand: he floats (default 1.3 m, the chin)

## Types

### BodyKind

*type* · `packages/physics/src/kernel.ts:19`

```ts
type BodyKind = 'static' | 'dynamic' | 'kinematic'
```

### CombineRule

*type* · `packages/physics/src/materials.ts:20`

```ts
type CombineRule = 'mean' | 'geometric' | 'min' | 'max' | 'multiply'
```

### ConstraintType

*type* · `packages/physics/src/kernel.ts:140`

```ts
type ConstraintType = 'rod' | 'rope' | 'spring' | 'ball' | 'hinge' | 'fixed'
```

A link between two bodies' centres.
 - rod:    a rigid distance (pushes and pulls)
 - rope:   a maximum distance (pulls only; slack when closer)
 - spring: Hooke's law with damping (implicit, so stable at any stiffness)
 - ball:   the two bodies share a point and turn freely about it (a shoulder, a hook)
 - hinge:  they share a point and turn about one axis only, within optional limits (a door, a wheel)
 - fixed:  they are welded in the pose they have (a bracket that can break)
The last three need a kernel with `caps.joints` (rigid bodies).

### Phase

*type* · `packages/physics/src/host.ts:12`

```ts
type Phase = 'field' | 'strength' | 'stretch'
```

The fixed order of the step: fields add forces, the kernel integrates and resolves contacts, strength reads them, stretch integrates soft things.

### Quat

*type* · `packages/physics/src/vec.ts:5`

```ts
type Quat = [number, number, number, number]
```

### Scope

*type* · `packages/physics/src/host.ts:41`

```ts
type Scope = 'world' | 'level' | 'zone' | 'entity'
```

### Shape

*type* · `packages/physics/src/kernel.ts:8`

```ts
type Shape = | { type: 'sphere'; radius: number } | { type: 'box'; half: Vec3 } // static or kinematic only in the light kernel | { type: 'plane'; normal: Vec3; offset: number } // static only: dot(normal, p) = offset // the shapes below need a rigid-body kernel (Havok); the light kernel refuses them | { type: 'capsule'; radius: number; halfHeight: number } // along the body's y, halfHeight to the centre of each cap | { type: 'cylinder'; radius: number; halfHeight: number } // along the body's y | { type: 'convex'; points: Vec3[] } // the hull of the points, in body space | { type: 'mesh'; positions: number[]; indices: number[] } // triangles in body space; static or kinematic only | { type: 'compound'; children: { shape: Shape; position?: Vec3; orientation?: Quat }[] }
```

The part of the dynamics every capability is written against. Havok, the light kernel of this package, or a game's own backend
implements it; a capability asks `caps` what is native and does the rest in a force or contact hook.

### ShapeKind

*type* · `packages/physics/src/physics.ts:5`

```ts
type ShapeKind = 'box' | 'sphere' | 'capsule'
```

### Tier

*type* · `packages/physics/src/budget.ts:12`

```ts
type Tier = 'desktop' | 'mobile' | 'console' | 'low'
```

What a hardware tier can afford, and what to give up when the world step runs over its share of the frame.
The numbers in `TIERS` come from `tools/bench` (2026-11-02), run on the dev machine in Node, Chromium and WebKit: a full step share of 6 ms holds
about 200 resting pieces, or about 170 to 290 liquid particles, or about 230 cloth particles when each takes 40 / 30 / 30 % of it. The console,
mobile and low tiers are scaled down from the same table; they are not measured on those machines: run `tools/bench` there and replace them.
`flowBoxCells` comes from the flow box's measured 0.9 microseconds per cell per step (A13) at 30 % of the step share: 1.8 ms / 0.9 us = 2000 cells
stepped every physics step on the desktop (a box stepped every n-th step may have n times as many).

### Vec3

*type* · `packages/physics/src/vec.ts:4`

```ts
type Vec3 = [number, number, number]
```

Plain-number vectors for the physics code: no allocation-heavy classes, no engine dependency, and the same arithmetic everywhere
so a replay gives the same bits. A vector is [x, y, z]; a quaternion is [x, y, z, w].

## Constants

### DEFAULT_COMBINE

*const* · `packages/physics/src/materials.ts:23`

```ts
const DEFAULT_COMBINE: CombineRules
```

### DEFAULT_CONTACT

*const* · `packages/physics/src/materials.ts:24`

```ts
const DEFAULT_CONTACT: { friction: number; restitution: number; rollingFriction: number; pivotFriction: number; }
```

### DEFAULT_LAYERS

*const* · `packages/physics/src/layers.ts:36`

```ts
const DEFAULT_LAYERS: string[]
```

The layers a game gets unless it defines its own (the common UE object channels).

### EXAMPLE_MATERIALS

*const* · `packages/physics/src/materials.ts:107`

```ts
const EXAMPLE_MATERIALS: Record<string, PhysicsMaterial>
```

A few common materials, as examples and for tests. A game defines its own.

### TIERS

*const* · `packages/physics/src/budget.ts:25`

```ts
const TIERS: Record<Tier, TierBudget>
```

