# @ferret/animation: API (continued)

### HoldArgs

*interface* · `packages/animation/src/hold.ts:50`

```ts
interface HoldArgs
```

- `rest: Rest`
- `pose: Pose` — the pose the clip has at this time (the other bones; the held hands and fingers are replaced)
- `side: 'r' | 'l'` — the hand that holds the weapon: its bone is `hand_<side>`
- `grip: Grip`
- `position: Vec3` — where the middle of the grip (the main hand) goes, in the skeleton frame
- `direction: Vec3` — where the blade points
- `roll?: number | 'auto'` — turn of the hands about the blade, degrees (0: the fingers wrap toward the holder's left for a right hand); `'auto'`: the turn that bends the wrists and forearms least and moves the hands least from where `pose` has them (searched all round; a clip made frame by frame has the previous frame's hands there, so it stays smooth)
- `both?: boolean` — hold with both hands (needs `grip.spacing`; default: when the grip has a spacing)
- `poleMain?: Vec3` — points the elbows bend toward, in the skeleton frame; default: down and out, a little back
- `poleOff?: Vec3`
- `names?: { upper?: string; lower?: string; hand?: string; twist?: string; finger?: (finger: string, joint: number, side: string) => string }` — names, default `upperarm_<side>`, `lowerarm_<side>`, `hand_<side>`
- `elbows?: 'auto' | 'fixed'` — where the elbows go when no pole is given: `'auto'` (default) round the shoulder-wrist line where the wrists and upper arms turn least; `'fixed'`: down, out to the side and a little back
- `hinge?: boolean` — keep the elbows hinges (default true): the forearm bends about one axis only and the hand carries the forearm's turn
- `wrapToward?: Vec3` — a direction in the skeleton frame the fingers wrap toward before `roll` (default: to the left of the holder, -x for a right hand)
- `edge?: Vec3` — for a blade with `grip.edge`: the way the edge should lead (the way the blade moves; skeleton frame), and how much that counts against the arms' comfort when the turn is chosen (`roll: 'auto'`, `holdRolls`; default 1, 0: not at all). A cut gives the blade's motion with a weight that grows with its speed.
- `edgeWeight?: number`

### HoldResult

*interface* · `packages/animation/src/hold.ts:81`

```ts
interface HoldResult
```

- `rotations: Record<string, Quat>` — keys to set: bone -> rotation change from rest (quaternion)
- `error: { main: number; off?: number }` — how far each hand's solve is from its place (metres), and whether the arm had to stretch
- `stretched: { main: boolean; off?: boolean }`
- `roll: number` — the turn of the hands about the blade used, degrees (the one chosen with `roll: 'auto'`)
- `edgeOff?: number` — with `edge`: how far the blade's edge (either one) is from leading, degrees

### HopSpec

*interface* · `packages/animation/src/gait.ts:14`

```ts
interface HopSpec
```

A hop: the body leaves the ground for a window of the cycle (`window` = [lift-off, touch-down] as fractions of the cycle) and rises `height` metres.

- `height: number`
- `window: [number, number]`
- `pitch?: number` — how far the nose is tipped at lift-off and touch-down, degrees (up when leaving, down when landing; default 18)

### IkRigOptions

*interface* · `packages/animation/src/ik-babylon.ts:77`

```ts
interface IkRigOptions
```

- `frame?: Node` — the node that holds the skeleton: the parent of the `root` bone (default found by name)
- `rest?: Rest` — the rest pose of the bodies skeleton (default: read from the nodes now, so build the rig before any clip has played)

### LegBones

*interface* · `packages/animation/src/legged.ts:17`

```ts
interface LegBones
```

one leg of a body, by bone names

- `chain: [string, string, string]` — hip (thigh) bone, knee, and the bone that ends the solved chain (it keeps its own turn, so the foot below stays as the clip poses it)
- `foot: string` — the bone whose height says where the foot is: the sole's end (ball, toe, hoof)

### LeggedGraphSpec

*interface* · `packages/animation/src/gait.ts:36`

```ts
interface LeggedGraphSpec
```

- `rest: RandomEntry[]` — what the body does standing: one entry or several (rest, graze, look about); the random player cross-fades between them
- `gaits: GaitSpec[]` — slowest first
- `turn?: { clip: string; per: number }` — a clip played at the turning rate when the body turns on the spot: its feet march in place
- `startAt?: number` — speed (m/s) above which it moves and below which it stops (defaults 0.12 and 0.05)
- `stopAt?: number`
- `hysteresis?: number` — the speed a faster gait has to fall below, under its `from`, before the slower one returns (m/s, default 0.25)
- `restFade?: number` — cross-fade seconds: into and out of rest, between gaits (defaults 0.3 and 0.2)
- `gaitFade?: number`
- `air?: GaitSpec[]` — Flight of a body that also walks (a bird): gaits used while the body is `airborne` (the Animator feeds it from the motion source), slowest first. They are entered from any ground state when it leaves the ground and left for rest when it lands.

### LeggedParams

*interface* · `packages/animation/src/legged.ts:79`

```ts
interface LeggedParams
```

- `model: Node` — the model root (what the IK treats as the frame of the skeleton)
- `pivot: Node` — a node under the entity that holds the model: it is tipped, raised and pitched, the entity stays on the ground
- `legs: LegMap`
- `pelvis: string` — the bone that carries the body: lowered when a foot finds the ground lower
- `gaits: GaitSpec[]` — the gaits of the body's graph (for what each does to the body: hops)
- `groundAt: (x: number, z: number, hint: number) => number | null` — the ground's height under a world point (a nav mesh, a height field); null when there is none
- `head?: { bones: { bone: string; share: number }[]; maxAngle?: number }` — the neck and head bones, rootward first, with the share of a turn each takes; the head leads a turn of the body (default: none)
- `sway?: number` — degrees the body rocks side to side as it walks, at the speed of its walk (default 1.2)
- `lean?: number` — how far the body banks into a turn: degrees per (m/s x rad/s) of the turn, and the most (defaults 2.5 and 11)
- `maxLean?: number`
- `range?: number` — the camera distance beyond which the feet and tilt are not worked out (default 45 m); the clips still play
- `smooth?: number` — how the body follows the ground, 1/s (default 10)
- `headForward?: Vec3` — the way the head's own axis points, in the head bone's frame (default: measured from the skeleton at rest, which faces the body's way)
- `climb?: boolean` — the body pitches with its climb (a flier, a swimmer): nose up as it rises, down as it sinks

### Limb

*interface* · `packages/animation/src/anatomy.ts:48`

```ts
interface Limb
```

- `top: string` — the bone the limb hangs from the body by
- `chain: [string, string, string]` — the three bones the foot is placed with, and the bone that stands on the ground (the lowest of the limb)
- `foot: string`
- `at: [number, number, number]` — the sole at rest, in the body's frame

### LimbSpec

*interface* · `packages/animation/src/ik-babylon.ts:22`

```ts
interface LimbSpec
```

- `name: string`
- `chain: [string, string, string]` — [root bone, middle bone, end bone] by name: shoulder, elbow, hand / thigh, calf, foot
- `target: () => BABYLON.Vector3 | null` — where the end goes, in the world; null: the limb is left as animated this frame
- `pole?: () => BABYLON.Vector3 | null` — the point the elbow or knee bends toward, in the world (default: the way the animation bends it)
- `weight?: Live<number>` — 0 to 1 (default 1)
- `fade?: number` — seconds to fade the weight in and out (default 0.1)
- `maxStretch?: number` — how far past the limb's full length the target may be before the limb is let go back to the animation (a fraction of the length; the weight falls to 0 over the next 0.15). Default: never let go, the limb stretches toward the target.

### LookAtSpec

*interface* · `packages/animation/src/ik-babylon.ts:38`

```ts
interface LookAtSpec
```

- `bones: { bone: string; share: number }[]` — root-ward bone first, head last, with the share of the turn each takes (spine 0.2, neck 0.3, head 0.5)
- `forward: Vec3` — the head's axis that looks forward, in the head bone's own frame (the glTF/UE mannequins look along +Z... measure with `forwardOf`)
- `target: () => BABYLON.Vector3 | null` — what to look at, in the world; null: look as animated
- `maxAngle?: number` — how far the head may leave where the animation looks, degrees (default 70)
- `weight?: Live<number>`
- `smooth?: number` — how quickly the look follows, 1/s (default 8)

### LookBone

*interface* · `packages/animation/src/ik.ts:95`

```ts
interface LookBone
```

- `parentQ: Quat` — world (frame) rotation of this bone's parent
- `q: Quat` — local rotation
- `share: number` — share of the turn this bone takes, 0 to 1 (shares are normalised)

### MontageDef

*interface* · `packages/animation/src/graph.ts:88`

```ts
interface MontageDef
```

- `clip: string`
- `blendIn?: number`
- `blendOut?: number`
- `rate?: number`
- `loop?: boolean`
- `mask?: string[]` — only these bones (and everything below them) are animated; the rest keeps the base pose
- `additive?: boolean | { reference?: number }` — Add the clip's change from a reference pose on top of the result instead of replacing it (breathing, leaning, a flinch over any locomotion). `reference` is the time in seconds of the clip's own reference pose (default 0, its first frame). The weight scales the change; an additive montage never takes weight from the base. Combines with `mask` and `loop`.

### MotionSource

*interface* · `packages/animation/src/animator.ts:7`

```ts
interface MotionSource
```

Anything that moves an entity and can say how: CharacterMovement (players, NPCs on the capsule) and NavAgent (crowd).

- `motionState(): { velocity: { x: number; y: number; z: number }; grounded: boolean; crouching?: boolean; swimming?: boolean; /** rad/s the body is turning at, + to the right */ yawRate?: number }`

### MoveClip

*interface* · `packages/animation/src/anatomy.ts:16`

```ts
interface MoveClip
```

- `clip: string`
- `kind: MoveKind`
- `fast: boolean`
- `slow: boolean`

### Notify

*interface* · `packages/animation/src/graph.ts:6`

```ts
interface Notify
```

- `time: number`
- `name: string`

### Pose

*interface* · `packages/animation/src/graph.ts:106`

```ts
interface Pose
```

- `items: PoseItem[]` — the weights of the items without `mask` or `additive` sum to 1; a masked item blends over the base on its bones only; an additive item adds its change from the reference time on top of that

### PoseItem

*interface* · `packages/animation/src/graph.ts:105`

```ts
interface PoseItem
```

- `clip: string`
- `time: number`
- `weight: number`
- `mask?: string[]`
- `additive?: { reference: number }`

### PosKey

*interface* · `packages/animation/src/clip.ts:18`

```ts
interface PosKey
```

- `t: number`
- `p: Vec3`
- `i?: Interp`

### Puppet

*interface* · `packages/animation/src/puppet.ts:19`

```ts
interface Puppet
```

- `root: BABYLON.TransformNode`
- `mesh: BABYLON.Mesh`
- `skeleton: BABYLON.Skeleton`
- `bones: Record<string, BABYLON.TransformNode>`
- `groups: Record<string, BABYLON.AnimationGroup>`
- `notifies: Record<string, Notify[]>` — notifies authored with the clips (footsteps, take-off)
- `loops: Record<string, boolean>`

### PuppetOptions

*interface* · `packages/animation/src/puppet.ts:9`

```ts
interface PuppetOptions
```

A procedural skinned character with a skeleton and a set of clips: the stand-in for a character exported from Unreal
(a GLB with a skeleton and animations) in samples and tests. Bones are TransformNodes linked to a Babylon Skeleton, the way
the glTF loader makes them, and the clips are AnimationGroups that target those nodes.

- `scale?: number` — overall size factor (1 = 1.8 m tall)
- `armRest?: number` — angle of the arms from straight down at rest, radians (a T-pose or A-pose authoring difference)
- `prefix?: string` — bone name prefix, to tell two puppets in one scene apart
- `color?: [number, number, number]`

### RandomEntry

*interface* · `packages/animation/src/graph.ts:30`

```ts
interface RandomEntry
```

- `clip: string`
- `weight?: number` — chance to be picked relative to the others (default 1)
- `loops?: [number, number]` — how many times the clip loops before the next pick: [min, max] (default [1, 1])
- `rate?: [number, number]` — playback rate range: [min, max] (default [1, 1])
- `blendIn?: number` — seconds to cross-fade from the previous entry (default 0.2)

### RetargetOptions

*interface* · `packages/animation/src/retarget.ts:2`

```ts
interface RetargetOptions
```

- `map?: Record<string, string> | ((source: string) => string | null)` — source bone name -> target bone name; a function, a table, or nothing when the names are equal after `stripPrefix`
- `stripPrefix?: string` — removed from the front of the source names (and `addPrefix` put on the target names) before the lookup
- `addPrefix?: string`
- `positionScale?: number` — position tracks are multiplied by this (the target is taller or shorter than the source)
- `positionBones?: string[]` — Unreal's translation retargeting of a skeleton with other bone lengths than the clip's: only these bones (by target name, after the prefix) keep their position track, each scaled by (the target's rest length / the source's rest length); every other bone keeps its own rest position, so the clip cannot stretch the body. Default: all position tracks are copied as they are.
- `restRotation?: boolean` — rotation tracks are re-based from the source rest rotation to the target one (different T-/A-poses)
- `name?: string`

### RetargetResult

*interface* · `packages/animation/src/retarget.ts:20`

```ts
interface RetargetResult
```

- `group: BABYLON.AnimationGroup`
- `missing: string[]` — source bones that have an animation but no target bone

### RootDelta

*interface* · `packages/animation/src/backend.ts:57`

```ts
interface RootDelta
```

What the clips moved the root bone by during one `apply`, in the bone's parent space (the entity's own space for a skeleton under it).

- `x: number`
- `y: number`
- `z: number`
- `yaw: number`

### RootMotionOptions

*interface* · `packages/animation/src/backend.ts:47`

```ts
interface RootMotionOptions
```

Root motion: the movement a clip authors on one bone (usually the root or hips) is taken off the skeleton and handed to the game, so the
character's body moves by what the animation says (a dodge roll, a lunge, a climb) instead of the skeleton sliding away from its entity.

- `bone: string` — name of the bone whose position track (and yaw) carries the motion
- `axes?: ('x' | 'y' | 'z')[]` — position axes taken off the bone and reported (default x and z: the bone keeps its own height bob)
- `yaw?: boolean` — also take the bone's turn about the vertical axis (default true)

### RotKey

*interface* · `packages/animation/src/clip.ts:17`

```ts
interface RotKey
```

- `t: number`
- `q: Quat`
- `i?: Interp`

### ScaleKey

*interface* · `packages/animation/src/clip.ts:20`

```ts
interface ScaleKey
```

a factor on the bone's rest scale, per axis (absolute = rest * key)

- `t: number`
- `s: Vec3`
- `i?: Interp`

### StateDef

*interface* · `packages/animation/src/graph.ts:53`

```ts
interface StateDef
```

- `motion: Motion`
- `speed?: number` — playback rate (1 = as authored)
- `loop?: boolean` — override the loop flag of the clips: a state that plays once and holds the last pose
- `rate?: { param: string; per: number; min?: number; max?: number }` — Play at the rate that makes the clip's feet stand still on the ground: the rate is `param / per` (clamped to `min`..`max`, defaults 0.5 and 2), times `speed`. `per` is the ground speed, in m/s, at which the clip as authored does not slide (see `strideSpeed`); `param` is the body's speed.

### TransitionDef

*interface* · `packages/animation/src/graph.ts:66`

```ts
interface TransitionDef
```

- `from: string | '*'`
- `to: string`
- `when?: Condition[]` — all must hold
- `duration?: number` — cross-fade seconds
- `interruptible?: boolean` — may start while the state is still fading in (default true)
- `syncPhase?: boolean` — the new state starts at the phase the old one is at, not at its beginning: gaits of one body keep their feet in step across the change

### TwoBoneOptions

*interface* · `packages/animation/src/ik.ts:45`

```ts
interface TwoBoneOptions
```

- `pole?: Vec3` — a point the knee or elbow bends toward (default: the way it bends now)
- `weight?: number` — 0 to 1: how much of the solved pose is used (default 1)
- `endRotation?: Quat` — a world (frame) rotation for the end bone (the hand turned onto a grip, the foot onto the ground); default: it keeps its world rotation

### TwoBoneResult

*interface* · `packages/animation/src/ik.ts:53`

```ts
interface TwoBoneResult
```

- `qa: Quat`
- `qb: Quat`
- `qc: Quat`
- `stretched: boolean` — the chain was too short to reach: it is stretched straight toward the target
- `error: number` — distance of the end bone from the target after the solve

## Types

### ClipLibrary

*type* · `packages/animation/src/graph.ts:14`

```ts
type ClipLibrary = Record<string, ClipInfo>
```

### Condition

*type* · `packages/animation/src/graph.ts:42`

```ts
type Condition = | { param: string; op: '>' | '<' | '>=' | '<=' | '==' | '!='; value: number } | { param: string; is: boolean } | { trigger: string } /** the state has played at least this many seconds */ | { stateTime: number } /** a non-looping state has reached its end */ | { finished: true } /** less than this fraction of the state's clip is left to play (Unreal's TimeRemaining (ratio) < value) */ | { remaining: number }
```

### Interp

*type* · `packages/animation/src/clip.ts:14`

```ts
type Interp = 'step' | 'linear' | 'smooth'
```

### LegMap

*type* · `packages/animation/src/legged.ts:24`

```ts
type LegMap = Record<string, LegBones>
```

### LegRole

*type* · `packages/animation/src/gait.ts:11`

```ts
type LegRole = string
```

a leg's role: `fl fr hl hr` for a quadruped, `l r` for a biped, `l0 r0 l1 r1 ...` (front to back) for six, eight or more legs

### Motion

*type* · `packages/animation/src/graph.ts:17`

```ts
type Motion = | { clip: string } | { blend1d: { param: string; points: { at: number; clip: string }[] } } | { blend2d: { x: string; y: string; points: { x: number; y: number; clip: string }[] } } /** plays one entry for a random number of loops, then cross-fades to another (Unreal's Random Player) */ | { random: { entries: RandomEntry[] } } /** * One clip played with different phases on different parts of the body: the first part (no `mask`) is the whole body, each later part is the * bones under its `mask` (a leg) shifted by `phase` cycles. Legs keep their own cycle, so a walk clip becomes a trot when its diagonal legs * are put in step (`gait.ts`). */ | { phased: { clip: string; parts: { mask?: string[]; phase: number }[] } }
```

### MoveKind

*type* · `packages/animation/src/anatomy.ts:15`

```ts
type MoveKind = 'walk' | 'run' | 'swim' | 'fly' | 'glide'
```

### QuadRole

*type* · `packages/animation/src/gait.ts:9`

```ts
type QuadRole = 'fl' | 'fr' | 'hl' | 'hr'
```

the four legs of a quadruped, by the role they have in a gait

### Quat

*type* · `packages/animation/src/clip.ts:13`

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

### Rest

*type* · `packages/animation/src/clip.ts:56`

```ts
type Rest = Record<string, BoneRest>
```

### Vec3

*type* · `packages/animation/src/clip.ts:12`

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

## Constants

### DEFAULT_LIMITS

*const* · `packages/animation/src/clip.ts:265`

```ts
const DEFAULT_LIMITS: [RegExp, number][]
```

### DEFAULT_TWIST_LIMITS

*const* · `packages/animation/src/clip.ts:269`

```ts
const DEFAULT_TWIST_LIMITS: [RegExp, number][]
```

### FOOTFALLS

*const* · `packages/animation/src/gait.ts:135`

```ts
const FOOTFALLS: Record<"walk" | "trot" | "pace" | "canter" | "bound", Record<QuadRole, number>>
```

Footfall patterns, fractions of the cycle at which each leg touches down.

### INTERPS

*const* · `packages/animation/src/clip.ts:15`

```ts
const INTERPS: readonly Interp[]
```

