FERRETGame engine over Babylon.js
Ferret

@ferret/animation

Animation graphs: state machines, blend spaces, layers, notifies, retargeting and a stand-in puppet.

138 exports · source in packages/animation/src

Classes

Animator class

class Animator extends Component<AnimatorParams>

Plays an animation graph on an entity. Parameters come from the entity's motion source (or from game code through graph.set / graph.trigger), the pose is applied once per rendered frame (the world hands over dt scaled by the entity's time dilation). Notifies are emitted on the world's event bus as anim:notify { entity, name, clip }.

graph: AnimGraph
backend: GroupBackend
rootDelta: RootDeltaroot motion of the last frame, in the entity's own space (zero without rootMotion)
poseGate: (() => boolean) | nullAsked once per rendered frame: false skips applying the pose to the skeleton this frame (the graph still runs, so states, notifies, montages and the clock are exactly as without a gate; the root motion of the skipped frames comes with the next applied one). @ferret/perspective sets it so a far object poses its bones less often. Null (the default) poses every frame.
onAttach()
onFixedUpdate()
onUpdate(dt: number)
playMontage(def: MontageDef)Play a one-shot clip over the base animation (a gesture, an attack, a pick-up).
onDetach()

packages/animation/src/animator.ts:33

AnimGraph class

class AnimGraph

Runtime of one graph on one character.

readonly values: Record<string, number>
notifyThreshold: numbera clip whose weight in the output is at least this fires its notifies
constructor(readonly def: GraphDef, readonly clips: ClipLibrary, readonly events: GraphEvents = {})
get state(): string
get phase(): numberhow far the current state is through its cycle, 0..1 (for what follows the gait: a hop's arc, footsteps)
get activeMontages(): readonly Montage[]
set(param: string, value: number | boolean)
get(param: string): number
trigger(name: string)
playMontage(def: MontageDef): Montage
stopMontage(m: Montage)
update(dt: number): PoseAdvance by dt seconds (already multiplied by the entity's time dilation).

packages/animation/src/graph.ts:265

ClipEditError class

class ClipEditError extends Error

packages/animation/src/clip.ts:250

ClipEditor class

class ClipEditor
readonly rest: Rest
constructor(clip: ClipJson, private readonly o: ClipEditorOptions)
static create(o: ClipEditorOptions & { skeleton: string; name: string; duration?: number; base?: string; loop?: boolean; fps?: number }): ClipEditorA new clip: empty (the rest pose), or a copy of a library clip.
get json(): ClipJson
get canUndo()
get canRedo()
history(): string[]
undo(): boolean
redo(): boolean
setKey(a: { bone: string; time: number; rotation?: Quat; euler?: Vec3; position?: Vec3; interp?: Interp; absolute?: boolean }): voidSet a key of a bone at a time (replaces the key there). rotation (quaternion) or euler (degrees) is the change from rest; with absolute it is the bone's own rotation (the change is worked out from the rest pose). position is the offset from the rest position (root and pelvis only).
removeKey(a: { bone: string; time: number; channel?: 'rotation' | 'position' | 'scale' }): numberRemove the key of a bone at a time (channel limits it to rotation, position or scale). Returns how many were removed.
copyKey(a: { from: number; to: number; bone?: string }): numberCopy the keys at a time to another time: of one bone, or of every bone that has one (a pose). The values are what the clip is at from (held keys, or sampled between).
mirror(a: { time?: number } = {}): numberMirror left and right (partners are found by the _l / _r ending of the bone name; bones on the middle line are mirrored in place). With time, only the pose at that time is mirrored (the keys there); without, the whole clip.
ik(a: { chain: [string, string, string]; target: Vec3 | { bone: string; offset?: Vec3 }; pole?: Vec3 | { bone: string; offset?: Vec3 }; time: number; endRotation?: Quat; weight?: number; interp?: Interp }): { error: number; stretched: boolean }Set keys by solving a limb to a target at a time: chain is [root bone, middle bone, end bone] (shoulder, elbow, hand), target a point in the skeleton frame or a point on another bone ({bone, offset}, the offset in that bone's frame: a grip on the sword is an offset of the right hand), pole the same for the point the elbow or knee bends toward. The chain's three bones get rotation keys at time; the end bone keeps its rotation in the world unless endRotation (a rotation in the skeleton frame) is given. Returns how far the end is from the target afterwards (a limb too short stretches).
hold(a: { time: number; side?: 'r' | 'l'; grip: Grip; position: Vec3; direction: Vec3; roll?: number | 'auto'; both?: boolean; poleMain?: Vec3; poleOff?: Vec3; wrapToward?: Vec3; edge?: Vec3; edgeWeight?: number; interp?: Interp }): ReturnType<typeof holdWeapon>Put a weapon in the hands at a time (see holdWeapon): the grip's middle at position, the blade along direction, both hands if the grip has a spacing. The arms, the hands' turn and the fingers get rotation keys at time; returns the solve's errors.
holdRun(holds: Parameters<ClipEditor['hold']>[0][], o: { loop?: boolean; step?: number } = {}): ReturnType<typeof holdWeapon>[]Hold a weapon at many times at once (frames of a move, in any order): the turns of the hands about the blade left as 'auto' (or absent) are chosen for the whole run together (holdRolls: wrists least bent, hands moving least between the times; loop joins the last to the first), then each is set as hold does. The poses the run is solved on are the clip's at those times before the hands are set. One undo step per time. Returns one result per hold, in the order given.
setNotify(a: { name: string; time: number }): void
removeNotify(a: { name: string; time?: number }): number
retime(a: { scale?: number; curve?: [number, number][] }): voidChange the length: scale multiplies every time, or curve maps old times to new ones with straight lines between the pairs (first pair 0 -> 0 added if missing).
setInfo(a: { duration?: number; loop?: boolean; fps?: number; name?: string }): void
validate(): { ok: boolean; issues: ClipIssue[]; skipped: string[] }Checks of the clip: what a hand-made clip gets wrong. Errors are what cannot play; warnings are joints bent past their limit (limits), sudden jumps between keys (pops), a loop whose end does not meet its start, and tracks for bones the skeleton lacks. Foot sliding and ground penetration need the bodies' bones in space and are not checked here (skipped).

packages/animation/src/clip.ts:274

GroupBackend class

class GroupBackend

Applies a pose request to Babylon animation groups without Babylon's own animation clock: every targeted animation is sampled at the requested time (Animation.evaluate), the samples of one property are blended by weight (vectors and floats linearly, rotations by normalised lerp) and written to the target. A masked item (a montage on the upper body) counts only for targets under its bones, and takes its weight from the base clips there. Targets the pose does not mention keep their value, and a property whose weights sum to less than 1 keeps the rest of its current value. The groups are plain containers of animations: never started, so they cost nothing between frames.

constructor(readonly groups: Record<string, BABYLON.AnimationGroup>, readonly rootMotion?: RootMotionOptions)
apply(pose: Pose, rootOnly = false): RootDeltaApply a pose; returns the root motion the clips made this call (all zero without rootMotion). With rootOnly nothing is written to the skeleton: only the root motion is measured (and each clip's clock noted), so an object that does not pose its bones still moves exactly as one that does.
dispose()

packages/animation/src/backend.ts:67

IkRig class

class IkRig

IK for one body. Add parts (limb, lookAt, footPlacement), then attach() to run it after each frame's animation (or call update(dt) yourself). Parts run in the order: feet, look-at, limbs (so a hand that follows a sword held by an animated hand sees the body as placed).

readonly frame: Node
readonly rest: Rest
readonly state: { pelvisDrop: number; footOffsets: number[]; limbError: Record<string, number> }what the last update did, for tests and the inspector
constructor(readonly scene: BABYLON.Scene, readonly bones: Record<string, Node>, o: IkRigOptions = {})
limb(spec: LimbSpec): this
lookAt(spec: LookAtSpec): this
footPlacement(spec: FootPlacementSpec): this
attach(): thisrun after the scene's animations every frame
dispose()
frameT(n: Node): { p: Vec3; q: Quat }frame position and rotation of a node, from the local values of it and its parents up to the frame
axisOf(bone: string, worldDir: BABYLON.Vector3): Vec3a world direction as an axis of a bone's own frame, with the skeleton as it is now (for lookAt.forward: build the rig with the body at rest, facing worldDir)
update(dt: number): void

packages/animation/src/ik-babylon.ts:88

Legged class

class Legged extends Component<LeggedParams>

Ground, slope, lean, rock, hop and head for a legged body (see the file's comment). Add it to an entity that has an Animator playing a leggedGraph; the entity's node stays where the nav mesh keeps it. Exposes state for tests and the inspector.

schema: { readonly model: { readonly type: "object"; readonly required: true; }; readonly pivot: { readonly type: "object"; readonly required: true; }; readonly legs: { readonly type: "object"; readonly required: true; }; readonly pelvis: { readonly type: "string"; readonly required: true; }; readonly gaits: { readonly type: "array"; readonly required: true; }; readonly groundAt: { readonly type: "function"; readonly required: true; }; readonly head: { readonly type: "object"; }; readonly sway: { readonly type: "number"; readonly min: 0; }; readonly lean: { readonly type: "number"; readonly min: 0; }; readonly maxLean: { readonly type: "number"; readonly min: 0; }; readonly range: { readonly type: "number"; readonly min: 1; }; readonly smooth: { readonly type: "number"; readonly min: 0.1; }; readonly headForward: { readonly type: "array"; }; readonly climb: { readonly type: "boolean"; }; }
readonly state: { pitch: number; roll: number; lift: number; bank: number; rock: number; near: boolean; footWeight: number; gait: string; wheelbase: number; track: number; }what the last frame did
onAttach()
onUpdate(dt: number)
onDetach()

packages/animation/src/legged.ts:115

Montage class

class Montage
time: number
weight: number
stopping: boolean
finished: boolean
constructor(readonly def: MontageDef, readonly id: number)

packages/animation/src/graph.ts:118

Functions

airState function

function airState: (g: string | GaitSpec) => string

packages/animation/src/gait.ts:59

alignFrames function

function alignFrames(la: Vec3, lb: Vec3, wa: Vec3, wb: Vec3): Quat

The rotation that turns the orthonormal frame made of (la, lb) onto the one made of (wa, wb): la onto wa exactly, lb as near to wb as it can be.

packages/animation/src/hold.ts:31

analyseAnimal function

function analyseAnimal(scene: BABYLON.Scene, model: Node, o: AnalyseOptions): AnimalPlan

Make the plan of an animal from its skeleton and clips. The model must be at rest (no clip played) and may be turned by plan.yaw afterwards; the measures are valid for the turned body.

packages/animation/src/anatomy.ts:221

analyseFoot function

function analyseFoot(track: FootTrack, duration: number, band = 0.2): FootGait

Stance of one foot: the samples within band (default a fifth of the foot's own height range) of its lowest point are on the ground; over the longest run of them the foot moves back along the body at the speed the ground goes by under it. duration is the clip's length, seconds.

packages/animation/src/gait.ts:163

applyClipPose function

function applyClipPose(bones: Record<string, Node>, rest: Rest, pose: Record<string, { q?: Quat; p?: Vec3; s?: Vec3 }>): void

Put the pose of a clip at a time on a body's nodes (rest where the clip has no key): for scrubbing in a panel, without an animation group.

packages/animation/src/clip-babylon.ts:145

bindClips function

function bindClips(scene: BABYLON.Scene, bodyRoot: BABYLON.TransformNode, source: Record<string, BABYLON.AnimationGroup>, map: Record<string, string>, o: BindClipsOptions = {}): BoundClips

Puts the clips of a skeleton on a body made of parts: source is the animation groups of a loaded clips file (by their names in the file), map says which of them each name of the animation graph is ({ idle: 'Idle', walk: 'Walk_Fwd' }), bodyRoot is the loaded character. Every bound clip is a copy of the source targeting the body's bones by name, so one clips file serves any number of bodies. A character made by tools/ue-export/characters.mjs has the bone names of its clips; a body with other names passes a bone map in retarget.

packages/animation/src/character.ts:26

bonesOf function

function bonesOf(root: Node, bones?: Iterable<string>): Record<string, Node>

The bones of a model by name: the transform nodes below a root (a body made by the library has them named <model>/<bone>).

packages/animation/src/clip-babylon.ts:12

boneTracks function

function boneTracks(scene: BABYLON.Scene, groups: Record<string, BABYLON.AnimationGroup>, model: Node, frame: Node, boneNames: string[], clip: string, duration: number, samples = 48): BABYLON.Vector3[][]

The places of some bones over one pass of a clip, in the frame of frame (the body's own: up is y), samples equal steps of the cycle. The skeleton is returned to the pose it had before.

packages/animation/src/legged.ts:44

buildPuppet function

function buildPuppet(scene: BABYLON.Scene, opts: PuppetOptions = {}): Puppet

packages/animation/src/puppet.ts:49

chain2Pose function

function chain2Pose(c: Chain2): Chain2Pose

packages/animation/src/ik.ts:40

classifyClips function

function classifyClips(names: string[]): ClipRoles

Sort a skeleton's clips by what their names say: the ones it rests in, the ones it feeds in, the ones it moves in. Names carry the species and a _anim tail, which is ignored.

packages/animation/src/anatomy.ts:22

clipFromJson function

function clipFromJson(scene: BABYLON.Scene, clip: ClipJson, bones: Record<string, Node>, rest: Rest, o: { name?: string } = {}): BuiltClip

Make an AnimationGroup of a clip for a body: one animation per bone that has keys, targeting that bone's node. bones are the body's nodes by bone name and rest its rest pose (restOf). Bones the body lacks are listed in missing and skipped. The group has the clip's name (or name) and is not started.

packages/animation/src/clip-babylon.ts:71

clipInfo function

function clipInfo(group: BABYLON.AnimationGroup, opts: { loop?: boolean; notifies?: Notify[] } = {}): ClipInfo

The length and frame rate of an AnimationGroup, as a graph clip.

packages/animation/src/backend.ts:5

clipLibrary function

function clipLibrary(groups: Record<string, BABYLON.AnimationGroup>, extra: Record<string, { loop?: boolean; notifies?: Notify[] }> = {}): ClipLibrary

packages/animation/src/backend.ts:9

clipToJson function

function clipToJson(group: BABYLON.AnimationGroup, rest: Rest, o: { name?: string; skeleton: string; loop?: boolean; fps?: number; positionBones?: (b: string) => boolean; scales?: boolean }): { clip: ClipJson; skipped: string[] }

The clip file of any AnimationGroup of a body, with the skeleton's rest (the library's clips are such groups): every animation of a bone's rotation and position becomes keys at the animation's own frames, as the change from rest (linear between keys, as Babylon plays them). Tracks of other properties and of nodes that are not bones are left out and named in skipped. With scales, a scaling track that leaves the rest scale is taken too, as factors on it (a track with a zero in it is a broken export and is left out, as retargetGroup leaves it).

packages/animation/src/clip-babylon.ts:108

findAnatomy function

function findAnatomy(model: Node, frame: Node): Anatomy | null

Find a body's legs. A limb is a run of bones that hangs off the body at a joint where the skeleton branches into more than one part of real size, goes down to the ground, and has a partner on the other side (a tail, a neck and a head are alone). The leg chain is the two longest consecutive segments of the limb (thigh and shin), the sole is its lowest bone. Reads the nodes as they stand: call it before any clip has played.

packages/animation/src/anatomy.ts:76

findHead function

function findHead(model: Node, frame: Node, anatomy: Anatomy, yaw: number): Anatomy['head']

The head chain for a body facing +z: the foremost bone that is not in a limb, climbed to the first bone with some size to it, and the two bones above.

packages/animation/src/anatomy.ts:148

gaitAt function

function gaitAt(spec: Pick<LeggedGraphSpec, 'gaits' | 'startAt' | 'stopAt' | 'hysteresis'>, speed: number, current = -1): number

The gait a speed asks for, with the same hysteresis as the graph (current = the gait now; none = rest). Index into spec.gaits, or -1 for rest.

packages/animation/src/gait.ts:112

gaitState function

function gaitState: (g: string | GaitSpec) => string

packages/animation/src/gait.ts:58

holdCost function

function holdCost(a: HoldArgs, r: HoldResult, near = false): number

How awkward a hold leaves the arms: the wrists' bend counts in full, the turn of the forearm they carry much less, the elbows and shoulders less; a hand off its place or a joint past its range costs much more. With near, also how far the hands moved from where a.pose has them.

packages/animation/src/hold.ts:122

holdRolls function

function holdRolls(holds: HoldArgs[], o: { step?: number; smooth?: number; loop?: boolean } = {}): number[]

The turns of the hands about the blade for a whole run of holds (one per frame of a clip, in time order): the run that is least awkward over all its frames and whose hands move least between frames (each frame tries every turn in step degrees, the best path through them is found at once, then each is refined by a degree). loop: the last frame joins the first. Returns one turn per hold, degrees, to pass as roll.

packages/animation/src/hold.ts:142

holdWeapon function

function holdWeapon(a: HoldArgs): HoldResult

Put a weapon in the hands: the grip's middle at position, the blade along direction, the main hand's frame turned so the weapon sits as its socket places it, the second hand mirrored on the grip spacing toward the pommel, the arms solved to them (two-bone IK on the pose, elbows toward the poles), and the fingers closed round the grip. The thumb is left as it is (it rests on the grip in the library's hands).

packages/animation/src/hold.ts:107

hopLift function

function hopLift(h: HopSpec, phase: number): number

The height of a hop at a cycle fraction, 0..1 of height: a parabola between lift-off and touch-down (the window may wrap past the end of the cycle).

packages/animation/src/gait.ts:194

hopPitch function

function hopPitch(h: HopSpec, phase: number): number

How far the nose is tipped at a cycle fraction, degrees, + up: leaving the ground it is up, at the top level, landing down.

packages/animation/src/gait.ts:202

hopWindowOf function

function hopWindowOf(legs: Partial<Record<LegRole, FootGait>>, min = 0.25): [number, number] | null

The window of a hop in a clip's cycle, from the stances of its feet: the body is off the ground from the hind feet's push-off to the front feet's touch-down (a rabbit bounds so: its hind legs drive, its fore legs take the landing). Cycle fractions [lift-off, touch-down]; null when the clip has no such pair of feet. A window shorter than min of the cycle is stretched about its middle so the hop is seen.

packages/animation/src/gait.ts:215

leggedGraph function

function leggedGraph(spec: LeggedGraphSpec): GraphDef

The animation graph of a walker. Parameters it reads: speed (m/s, fed by the Animator from the motion source) and turnRate (rad/s, when it has a turn). States: rest (random player), gait:<name> per gait, turn. Gait changes keep the phase, so the feet stay in step across them.

packages/animation/src/gait.ts:65

legShifts function

function legShifts(native: Partial<Record<LegRole, number>>, pattern: Partial<Record<LegRole, number>>): Partial<Record<LegRole, number>>

The phases that put a clip's legs in a gait's footfall pattern. native is the cycle fraction at which each leg of the clip touches down (touchDown); pattern the fractions the gait wants (trot: diagonals together: fl 0, hr 0, fr 0.5, hl 0.5). A leg's shift is the wanted fraction less its own, so every leg runs the clip's own swing and stance, only at another time.

packages/animation/src/gait.ts:127

locomotionGraph function

function locomotionGraph(opts: { walkSpeed?: number; runSpeed?: number; points?: { at: number; clip: string }[]; crouch?: boolean; swim?: { at: number; clip: string }[]; swim2d?: { x: number; y: number; clip: string }[] } = {})

A ready-made locomotion graph for a puppet (or any character with the same clip names): a blend of idle and gaits by speed, jump, fall, and with crouch a crouch state (the clips crouch and crouchWalk) entered while the crouching parameter is true. swim (blend1d points on the speed, e.g. Swim_Idle and Swim_Fwd) adds a swim state entered while the swimming parameter is true (CharacterMovement in a dense medium) and left when it is false. swim2d (blend2d points on swimX = m/s to the right and swimY = m/s forward, e.g. Swim_Idle at 0,0, Swim_Fwd 0,3, Swim_Bwd 0,-3, Swim_Left -3,0, Swim_Right 3,0) replaces the speed blend of the swim state; the Animator feeds both from the motion source. points replaces the idle/walk/run blend: [{ at: 0, clip: 'idle' }, { at: 2, clip: 'walk' }, { at: 3.5, clip: 'jog' }, { at: 6, clip: 'sprint' }].

packages/animation/src/puppet.ts:166

measureClip function

function measureClip(scene: BABYLON.Scene, groups: Record<string, BABYLON.AnimationGroup>, model: Node, frame: Node, legs: LegMap, clip: string, duration: number, o: { samples?: number; forward?: Vec3 } = {}): ClipFeet

Plays a clip through its cycle on the skeleton and watches the feet: the body's own frame is frame (up is y, forward is z unless forward says otherwise). Without forward it is taken from the legs (the way the fore feet are from the hind feet). The skeleton is left as it was.

packages/animation/src/legged.ts:63

mirrorName function

function mirrorName(name: string): string | null

upperarm_l -> upperarm_r and back (case kept: Wing_01_L -> Wing_01_R); null for a bone on the middle line

packages/animation/src/clip.ts:224

mirrorPosition function

function mirrorPosition(p: Vec3, from: BoneRest, to: BoneRest): Vec3

packages/animation/src/clip.ts:243

mirrorRotation function

function mirrorRotation(q: Quat, from: BoneRest, to: BoneRest): Quat

The mirror of a rotation change of a bone as the change of its partner, for a skeleton that is symmetric about the plane x = 0 in its own frame: the change is taken into the skeleton frame with the bone's rest rotation, reflected (the axis of a rotation keeps its component along the plane's normal and flips the others), and taken into the partner's frame. A bone on the middle line is its own partner.

packages/animation/src/clip.ts:236

motionClips function

function motionClips(m: Motion): string[]

packages/animation/src/graph.ts:164

poseFk function

function poseFk(rest: Rest, pose: Record<string, { q?: Quat; p?: Vec3 }>, bone: string): { p: Vec3; q: Quat }

The frame position and rotation of a bone in a pose of the clip (the change from rest per bone, as samplePose gives), the skeleton frame being the top bone's parent.

packages/animation/src/clip.ts:160

qAngle function

function qAngle(q: Quat): number

the angle of a rotation in degrees, 0 to 180

packages/animation/src/clip.ts:74

qDistance function

function qDistance: (a: Quat, b: Quat) => number

angle between two rotations in degrees

packages/animation/src/clip.ts:76

qFromEuler function

function qFromEuler(deg: Vec3): Quat

Euler angles in degrees, rotating about x, then y, then z of the parent frame's axes taken in the XYZ order of three.js (q = qx qy qz).

packages/animation/src/clip.ts:99

qIdentity function

function qIdentity: () => Quat

packages/animation/src/clip.ts:61

qInv function

function qInv: (q: Quat) => Quat

packages/animation/src/clip.ts:70

qMul function

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

packages/animation/src/clip.ts:62

qNorm function

function qNorm(q: Quat): Quat

packages/animation/src/clip.ts:71

qRotate function

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

packages/animation/src/clip.ts:72

qSlerp function

function qSlerp(a: Quat, b: Quat, t: number): Quat

packages/animation/src/clip.ts:90

qToEuler function

function qToEuler(q: Quat): Vec3

packages/animation/src/clip.ts:104

restOf function

function restOf(bones: Record<string, Node>): Rest

The rest pose of a skeleton as the editor wants it: local position and rotation of every bone, and the rest rotations in the skeleton's frame (every parent multiplied in; the loader's mirror above the skeleton is not part of it). Read from the nodes as they are: call it before any clip has played, or with the skeleton returned to rest.

packages/animation/src/clip-babylon.ts:26

retargetGroup function

function retargetGroup(scene: BABYLON.Scene, source: BABYLON.AnimationGroup, targetRoot: BABYLON.TransformNode, opts: RetargetOptions = {}): RetargetResult

Copy an animation group from one skeleton onto another with different bone names, proportions and rest pose. Targets are found by name below targetRoot. Rotations keep their change from the rest pose (target = targetRest inverse(sourceRest) source); positions are scaled.

packages/animation/src/retarget.ts:31

samplePose function

function samplePose(clip: ClipJson, t: number): Record<string, { q?: Quat; p?: Vec3; s?: Vec3 }>

A pose of the clip at a time: per bone the change from rest. Bones without keys are not in it.

packages/animation/src/clip.ts:147

samplePosition function

function samplePosition(keys: PosKey[], t: number): Vec3

packages/animation/src/clip.ts:130

sampleRotation function

function sampleRotation(keys: RotKey[], t: number): Quat

The rotation key track at a time (held before the first and after the last key).

packages/animation/src/clip.ts:124

sampleScale function

function sampleScale(keys: ScaleKey[], t: number): Vec3

packages/animation/src/clip.ts:138

solveLookAt function

function solveLookAt(bones: LookBone[], forward: Vec3, toward: Vec3, o: { maxAngle?: number; weight?: number } = {}): Quat[]

Turn a chain of bones (root-ward first, the head last) so the axis forward of the last bone (in its own frame) points along toward, within maxAngle degrees of where it points now. Every bone takes its share of the turn; the last one takes what is left so the whole comes out exact. Parents' rotations are taken from parentQ of the first bone and the bones above each other.

packages/animation/src/ik.ts:108

solveTwoBone function

function solveTwoBone(c: Chain2, target: Vec3, o: TwoBoneOptions = {}): TwoBoneResult

Solve a two-bone chain so its end is at target (law of cosines), bending toward pole. The bone lengths are kept.

packages/animation/src/ik.ts:62

strideSpeed function

function strideSpeed(feet: FootTrack[], duration: number): number

The ground speed of a gait from the stances of its feet (the median of the feet that stand: one slow foot does not set it).

packages/animation/src/gait.ts:187

swing function

function swing(a: Vec3, b: Vec3): Quat

The shortest rotation taking direction a to direction b (any lengths).

packages/animation/src/ik.ts:16

swingTwist function

function swingTwist(q: Quat, axis: Vec3): { swing: number; twist: number; twistQ: Quat }

Split a rotation into a turn about axis (twist, signed degrees) and the rest (swing, degrees): q = swing * twist.

packages/animation/src/clip.ts:78

twistAxis function

function twistAxis(rest: Rest, bone: string): Vec3

The axis a bone twists about, in its own frame: the line from its parent's joint to its own (its rest offset seen from itself).

packages/animation/src/clip.ts:89

validateClipJson function

function validateClipJson(clip: unknown): ClipIssue[]

The problems of a clip file (JSON path and message). Empty when it can be played.

packages/animation/src/clip.ts:180

validateGraphDef function

function validateGraphDef(def: unknown): { path: string; message: string }[]

Check a graph definition without any clips: the initial state exists, transitions join existing states, every condition names a declared parameter of the right kind, motions have clips and sensible numbers. Returns the problems with their paths (relative to the graph); an empty list means new AnimGraph will accept it as long as the clips exist.

packages/animation/src/graph.ts:177

Interfaces

AnalyseOptions interface

interface AnalyseOptions
clips: Record<string, number>the clips by name, with their lengths in seconds
groups: Record<string, BABYLON.AnimationGroup>the groups to play
frame: Nodethe frame the body's measures are taken in

packages/animation/src/anatomy.ts:208

Anatomy interface

interface Anatomy
limbs: Limb[]
pelvis: stringthe bone all the legs hang from together: the body is lowered by it
head?: { bones: { bone: string; share: number }[] }neck and head, rootward first
rest: Record<string, [number, number, number]>bone positions at rest, in the body's frame (before any turn of the model)
height: numberoverall height of the skeleton at rest and the height of the hip over the sole, metres
legHeight: number

packages/animation/src/anatomy.ts:58

AnimalPlan interface

interface AnimalPlan
kind: 'walker' | 'swimmer' | 'glider' | 'flier' | 'crawler'what its body is: walks on legs, or swims, glides, flies, crawls without feet to measure
legs: LegMap
pelvis: string
head?: Anatomy['head']
gaits: GaitSpec[]
air: GaitSpec[]
graph: GraphDef
paces: { speed: number; weight?: number; minDistance?: number }[]the paces of a trip, m/s, as Roam chooses among them
turnFirst: numberradians of heading error that stop it before it sets off, and how fast it turns, rad/s
turnRate: number
sway: numberdegrees the body rocks as it walks
yaw: numberthe turn of the model about the vertical that puts the way it goes along +z, radians; apply it to the model's node
per: Record<string, number>ground speed of each gait's clip, m/s
size: { length: number; width: number; legHeight: number; sprawl: number }the body's length, width and leg height, metres, and how far its legs sprawl (track over leg height)
climb: booleanthe body climbs with its path (it swims or flies)
notes: string[]
feet: Record<string, ClipFeet>what the feet of each move clip did, when it has feet

packages/animation/src/anatomy.ts:173

AnimatorParams interface

interface AnimatorParams
graph: GraphDef
groups: Record<string, BABYLON.AnimationGroup>one AnimationGroup per clip name used by the graph
notifies?: Record<string, Notify[]>notifies per clip, and clips that do not loop (default: all loop)
loops?: Record<string, boolean>
fromMovement?: booleanFeed speed, verticalSpeed, grounded, crouching from the entity's motion source (a component with motionState(): CharacterMovement, NavAgent) and the jump trigger from character:jump (default true)
rootMotion?: RootMotionOptions & { apply?: 'node' | 'none' }Take the movement the clips author on a bone off the skeleton (see RootMotionOptions). Each frame it is reported as Animator.rootDelta and the anim:rootmotion event { entity, x, y, z, yaw } in the entity's own space. apply: 'node' also moves and turns the entity's node by it (for entities nothing else drives: a prop, a cutscene actor); the default 'none' leaves that to the game, e.g. to feed a character controller.

packages/animation/src/animator.ts:11

BindClipsOptions interface

interface BindClipsOptions
retarget?: RetargetOptionsretargetGroup options (the bones are matched by name; restRotation re-bases the rotations when the two rest poses differ)
oneShot?: string[]clip names (the keys of map) that do not loop (default: all loop)

packages/animation/src/character.ts:4

BoneRest interface

interface BoneRest

What the editor must know about one bone of the skeleton: its rest pose (local), and the rest rotations in the skeleton frame for mirroring.

p: Vec3
q: Quat
s?: Vec3the local rest scale (absent: 1, 1, 1)
wq?: Quatthe bone's rest rotation in the skeleton's frame (all parents multiplied in); needed to mirror left to right
pwq?: Quatthe same for its parent (identity at the root)
parent?: stringthe parent bone's name (absent at the top of the skeleton); needed to work in space (ik)

packages/animation/src/clip.ts:44

BoundClips interface

interface BoundClips
groups: Record<string, BABYLON.AnimationGroup>one AnimationGroup per graph clip name, targeting this body's bones: what Animator takes as groups
loops: Record<string, boolean>
missingClips: string[]graph clip names whose source clip does not exist, and the source bones without a bone on the body (per clip, once)
missingBones: string[]

packages/animation/src/character.ts:11

BuiltClip interface

interface BuiltClip
group: BABYLON.AnimationGroup
info: ClipInfo
missing: string[]

packages/animation/src/clip-babylon.ts:65

Chain2 interface

interface Chain2

A two-bone chain a -> b -> c: the local rotations and positions of the three bones, and the rotation of a's parent in the frame the target is given in.

pa: Quatworld (frame) rotation of the parent of a, and the frame position of a
posA: Vec3
qa: Quat
pb: Vec3local position of b in a, and of c in b
pc: Vec3
qb: Quat
qc: Quat

packages/animation/src/ik.ts:29

Chain2Pose interface

interface Chain2Pose
A: Vec3
B: Vec3
C: Vec3
wa: Quat
wb: Quat
wc: Quat

packages/animation/src/ik.ts:38

ClipBone interface

interface ClipBone
rotation?: RotKey[]
position?: PosKey[]
scale?: ScaleKey[]

packages/animation/src/clip.ts:21

ClipEditorOptions interface

interface ClipEditorOptions
rest: Rest
positionBones?: (bone: string) => booleanwhich bones may carry position keys (default: the root and the pelvis)
library?: (name: string) => ClipJson | undefineda clip of the library by name, for base (its keys are copied)
limits?: [RegExp, number][]largest change from rest, in degrees, per bone matcher; the first match counts (default: a table for a human)
twistLimits?: [RegExp, number][]bones whose turn about their own length is checked apart (degrees): for these limits holds the bend (the swing) and this the twist; the default: the hands, which turn with the forearm (from a T-pose, palm down, a forearm turns some 170 degrees, a wrist bends no more than 90)

packages/animation/src/clip.ts:252

ClipFeet interface

interface ClipFeet
speed: numberground speed at which the clip does not slide, m/s (0 for a clip whose feet never stand)
legs: Record<string, FootGait>per leg: when it touches down and leaves, how long it stands, the stride it makes
duration: number

packages/animation/src/legged.ts:26

ClipInfo interface

interface ClipInfo
duration: number
loop?: boolean
notifies?: Notify[]

packages/animation/src/graph.ts:8

ClipIssue interface

interface ClipIssue
level: 'error' | 'warning'
path: string
message: string

packages/animation/src/clip.ts:58

ClipJson interface

interface ClipJson
format: 1
name: string
skeleton: stringskeleton id of the library (gw-68, viking-73, dragon-62)
duration: numberseconds
loop?: boolean
fps?: numberframe rate the clip is played and sampled at when it becomes an animation group (default 30)
base?: stringthe library clip this one was made from (its keys were copied in; informational)
additive?: booleanan additive clip (UE's additive animations): its keys are the change itself (rotation from identity, position from zero), to be put on top of another pose, not relative to rest
bones: Record<string, ClipBone>
notifies?: ClipNotify[]

packages/animation/src/clip.ts:24

ClipNotify interface

interface ClipNotify
name: string
time: number

packages/animation/src/clip.ts:22

ClipRoles interface

interface ClipRoles
idle: string[]
graze: string[]
moves: MoveClip[]

packages/animation/src/anatomy.ts:17

FootGait interface

interface FootGait
speed: numberthe ground speed that makes the stance still (m/s); 0 when the foot never stands
touch: numbercycle fraction at which the foot touches down and leaves the ground
lift: number
duty: numberfraction of the cycle the foot is on the ground
stride: numberdistance the foot travels back along the body while it stands, metres

packages/animation/src/gait.ts:147

FootPlacementSpec interface

interface FootPlacementSpec
feet: FootSpec[]
pelvis?: stringthe bone that carries the body and is lowered when a foot finds the ground lower (default pelvis)
isGround?: (mesh: BABYLON.AbstractMesh) => booleanwhich meshes are ground (rays are cast at them)
groundAt?: (world: BABYLON.Vector3) => { y: number; normal?: BABYLON.Vector3 } | nullor: the ground's height (and, if known, its normal) under a world point, from the game's own query (a nav mesh, a height field); no ray is cast then. Null: no ground there.
probeUp?: numberhow far above the foot the probe starts and how far below it ends, in metres (default 0.6 and 1.0)
probeDown?: number
smooth?: numberhow quickly the offsets follow the ground, 1/s (default 14)
maxDrop?: numberthe largest the body is lowered, in metres (default 0.45)
tilt?: numbertilt the foot to the ground normal, up to this many degrees (default 25; 0 leaves it)
weight?: Live<number>

packages/animation/src/ik-babylon.ts:58

FootSpec interface

interface FootSpec
chain: [string, string, string][thigh, calf, foot]
sole?: stringthe bone that stands on the ground when the chain's end is not the sole (a hoof's ball below the chain's last bone): the ground is probed under it, so it, not the chain's end, lands

packages/animation/src/ik-babylon.ts:52

FootTrack interface

interface FootTrack

one foot over one cycle: samples at equal steps of the cycle, x forward along the body, y up, metres, in the frame of the body (the ground's frame)

x: number[]
y: number[]

packages/animation/src/gait.ts:145

GaitSpec interface

interface GaitSpec
name: string
clip: string
per: numberthe ground speed, m/s, at which the clip as authored does not slide (strideSpeed, measureGait)
from: numberthe body speed from which this gait is used, m/s (the first gait is used from startAt)
legs?: { mask: string[]; phase: number }[]legs in other phases than the clip has them: bone names under each leg and the shift in cycles
minRate?: numberthe playback rate may be bent this far (defaults 0.5 and 2)
maxRate?: number
hop?: HopSpec

packages/animation/src/gait.ts:21

GraphDef interface

interface GraphDef
params?: Record<string, 'float' | 'bool' | 'trigger'>
states: Record<string, StateDef>
initial: string
transitions?: TransitionDef[]
seed?: numberseed of the random players, so a run can be repeated (default: not seeded)

packages/animation/src/graph.ts:79

GraphEvents interface

interface GraphEvents
notify?(name: string, clip: string): void
stateEnter?(state: string): void
stateExit?(state: string): void
montageEnd?(handle: Montage): void

packages/animation/src/graph.ts:111

Grip interface

interface Grip

A grip of a weapon in the frame of the bone that holds it (the socket's bone): point is the middle of the grip, axis runs along it toward the blade.

point: Vec3
axis: Vec3
radius: numberradius of the grip, metres
spacing?: numberdistance from the hand on the grip to the second hand, toward the pommel (metres; 0 or absent: one hand)
edge?: Vec3for a blade: the way its edge faces, across axis (a two-edged blade cuts along it either way)

packages/animation/src/hold.ts:19

HoldArgs interface

interface HoldArgs
rest: Rest
pose: Posethe 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: Vec3where the middle of the grip (the main hand) goes, in the skeleton frame
direction: Vec3where 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?: booleanhold with both hands (needs grip.spacing; default: when the grip has a spacing)
poleMain?: Vec3points 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?: booleankeep the elbows hinges (default true): the forearm bends about one axis only and the hand carries the forearm's turn
wrapToward?: Vec3a direction in the skeleton frame the fingers wrap toward before roll (default: to the left of the holder, -x for a right hand)
edge?: Vec3for 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

packages/animation/src/hold.ts:50

HoldResult interface

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: numberthe turn of the hands about the blade used, degrees (the one chosen with roll: 'auto')
edgeOff?: numberwith edge: how far the blade's edge (either one) is from leading, degrees

packages/animation/src/hold.ts:81

HopSpec interface

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?: numberhow far the nose is tipped at lift-off and touch-down, degrees (up when leaving, down when landing; default 18)

packages/animation/src/gait.ts:14

IkRigOptions interface

interface IkRigOptions
frame?: Nodethe node that holds the skeleton: the parent of the root bone (default found by name)
rest?: Restthe rest pose of the bodies skeleton (default: read from the nodes now, so build the rig before any clip has played)

packages/animation/src/ik-babylon.ts:77

LegBones interface

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: stringthe bone whose height says where the foot is: the sole's end (ball, toe, hoof)

packages/animation/src/legged.ts:17

LeggedGraphSpec interface

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?: numberspeed (m/s) above which it moves and below which it stops (defaults 0.12 and 0.05)
stopAt?: number
hysteresis?: numberthe speed a faster gait has to fall below, under its from, before the slower one returns (m/s, default 0.25)
restFade?: numbercross-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.

packages/animation/src/gait.ts:36

LeggedParams interface

interface LeggedParams
model: Nodethe model root (what the IK treats as the frame of the skeleton)
pivot: Nodea node under the entity that holds the model: it is tipped, raised and pitched, the entity stays on the ground
legs: LegMap
pelvis: stringthe 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 | nullthe 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?: numberdegrees the body rocks side to side as it walks, at the speed of its walk (default 1.2)
lean?: numberhow 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?: numberthe camera distance beyond which the feet and tilt are not worked out (default 45 m); the clips still play
smooth?: numberhow the body follows the ground, 1/s (default 10)
headForward?: Vec3the 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?: booleanthe body pitches with its climb (a flier, a swimmer): nose up as it rises, down as it sinks

packages/animation/src/legged.ts:79

Limb interface

interface Limb
top: stringthe 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

packages/animation/src/anatomy.ts:48

LimbSpec interface

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 | nullwhere the end goes, in the world; null: the limb is left as animated this frame
pole?: () => BABYLON.Vector3 | nullthe 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?: numberseconds to fade the weight in and out (default 0.1)
maxStretch?: numberhow 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.

packages/animation/src/ik-babylon.ts:22

LookAtSpec interface

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: Vec3the 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 | nullwhat to look at, in the world; null: look as animated
maxAngle?: numberhow far the head may leave where the animation looks, degrees (default 70)
weight?: Live<number>
smooth?: numberhow quickly the look follows, 1/s (default 8)

packages/animation/src/ik-babylon.ts:38

LookBone interface

interface LookBone
parentQ: Quatworld (frame) rotation of this bone's parent
q: Quatlocal rotation
share: numbershare of the turn this bone takes, 0 to 1 (shares are normalised)

packages/animation/src/ik.ts:95

MontageDef interface

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.

packages/animation/src/graph.ts:88

MotionSource interface

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 }

packages/animation/src/animator.ts:7

MoveClip interface

interface MoveClip
clip: string
kind: MoveKind
fast: boolean
slow: boolean

packages/animation/src/anatomy.ts:16

Notify interface

interface Notify
time: number
name: string

packages/animation/src/graph.ts:6

Pose interface

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

packages/animation/src/graph.ts:106

PoseItem interface

interface PoseItem
clip: string
time: number
weight: number
mask?: string[]
additive?: { reference: number }

packages/animation/src/graph.ts:105

PosKey interface

interface PosKey
t: number
p: Vec3
i?: Interp

packages/animation/src/clip.ts:18

Puppet interface

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>

packages/animation/src/puppet.ts:19

PuppetOptions interface

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?: numberoverall size factor (1 = 1.8 m tall)
armRest?: numberangle of the arms from straight down at rest, radians (a T-pose or A-pose authoring difference)
prefix?: stringbone name prefix, to tell two puppets in one scene apart
color?: [number, number, number]

packages/animation/src/puppet.ts:9

RandomEntry interface

interface RandomEntry
clip: string
weight?: numberchance 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?: numberseconds to cross-fade from the previous entry (default 0.2)

packages/animation/src/graph.ts:30

RetargetOptions interface

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?: stringremoved from the front of the source names (and addPrefix put on the target names) before the lookup
addPrefix?: string
positionScale?: numberposition 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?: booleanrotation tracks are re-based from the source rest rotation to the target one (different T-/A-poses)
name?: string

packages/animation/src/retarget.ts:2

RetargetResult interface

interface RetargetResult
group: BABYLON.AnimationGroup
missing: string[]source bones that have an animation but no target bone

packages/animation/src/retarget.ts:20

RootDelta interface

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

packages/animation/src/backend.ts:57

RootMotionOptions interface

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: stringname 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?: booleanalso take the bone's turn about the vertical axis (default true)

packages/animation/src/backend.ts:47

RotKey interface

interface RotKey
t: number
q: Quat
i?: Interp

packages/animation/src/clip.ts:17

ScaleKey interface

interface ScaleKey

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

t: number
s: Vec3
i?: Interp

packages/animation/src/clip.ts:20

StateDef interface

interface StateDef
motion: Motion
speed?: numberplayback rate (1 = as authored)
loop?: booleanoverride 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.

packages/animation/src/graph.ts:53

TransitionDef interface

interface TransitionDef
from: string | '*'
to: string
when?: Condition[]all must hold
duration?: numbercross-fade seconds
interruptible?: booleanmay start while the state is still fading in (default true)
syncPhase?: booleanthe 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

packages/animation/src/graph.ts:66

TwoBoneOptions interface

interface TwoBoneOptions
pole?: Vec3a point the knee or elbow bends toward (default: the way it bends now)
weight?: number0 to 1: how much of the solved pose is used (default 1)
endRotation?: Quata world (frame) rotation for the end bone (the hand turned onto a grip, the foot onto the ground); default: it keeps its world rotation

packages/animation/src/ik.ts:45

TwoBoneResult interface

interface TwoBoneResult
qa: Quat
qb: Quat
qc: Quat
stretched: booleanthe chain was too short to reach: it is stretched straight toward the target
error: numberdistance of the end bone from the target after the solve

packages/animation/src/ik.ts:53

Types

ClipLibrary type

type ClipLibrary = Record<string, ClipInfo>

packages/animation/src/graph.ts:14

Condition type

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 }

packages/animation/src/graph.ts:42

Interp type

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

packages/animation/src/clip.ts:14

LegMap type

type LegMap = Record<string, LegBones>

packages/animation/src/legged.ts:24

LegRole type

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

packages/animation/src/gait.ts:11

Motion type

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 }[] } }

packages/animation/src/graph.ts:17

MoveKind type

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

packages/animation/src/anatomy.ts:15

QuadRole type

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

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

packages/animation/src/gait.ts:9

Quat type

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

packages/animation/src/clip.ts:13

Rest type

type Rest = Record<string, BoneRest>

packages/animation/src/clip.ts:56

Vec3 type

type Vec3 = [number, number, number]

packages/animation/src/clip.ts:12

Constants

DEFAULT_LIMITS const

const DEFAULT_LIMITS: [RegExp, number][]

packages/animation/src/clip.ts:265

DEFAULT_TWIST_LIMITS const

const DEFAULT_TWIST_LIMITS: [RegExp, number][]

packages/animation/src/clip.ts:269

FOOTFALLS const

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

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

packages/animation/src/gait.ts:135

INTERPS const

const INTERPS: readonly Interp[]

packages/animation/src/clip.ts:15