# @ferret/micromotion: API

Idle people that are never still: a profile and a seed give a person who gestures, looks about, fidgets, walks about his place, speaks with beats and reacts to blasts and impacts; levels of detail, clips as masked layers, micro.* commands.

230 exports. Generated from the source (`packages/micromotion/src`), so it matches the code.

## Classes

### ClipBank

*class* · `packages/micromotion/src/clips.ts:38`

```ts
class ClipBank
```

- `add(c: MotionClip): this`
- `has(gesture: string): boolean`
- `variants(gesture: string): readonly MotionClip[]`
- `size(): number`
- `choose(gesture: string, seed: number, startedAt: number, handedness: 'left' | 'right', style: { amplitude?: number; speed?: number } = {}): ClipPlay | null` — The clip for a gesture as one person plays it this time: the variant, speed and amplitude come from the person's seed and the start of the playback (the same inputs always give the same play), and a person of the other hand gets the mirror of a clip made for the module's frame.

### MicroSession

*class* · `packages/micromotion/src/service.ts:24`

```ts
class MicroSession
```

- `readonly people: Map<string, MicroPerson>`
- `readonly targets: Map<string, GazeTarget>`
- `take: 'idle' | 'running'`
- `t: number`
- `frame: number`
- `readonly thresholds: LodThresholds`
- `readonly budget: LodBudget`
- `occluded?: MicroWorld['occluded']`
- `onRemove?: (id: string) => void` — called when a person is removed (a host that draws him lets go of his body)
- `listen(fn: MicroListener): () => void` — listen to what the people do (the motion language link, a game); returns the function that stops it
- `constructor(o: MicroSessionOptions = {})`
- `spawn(id: string, prof: string | MicroProfile, seed: number, o: { pos?: Vec3; facing?: number; external?: boolean } = {}): PersonState` — a person with a shipped profile (by name) or a profile of his own; the seed makes him: the same seed and profile give the same person
- `remove(id: string): boolean`
- `person(id: string): PersonState`
- `setTarget(t: GazeTarget): void`
- `removeTarget(id: string): boolean`
- `step(dt: number): void` — the sim, in the fixed step: every person, whatever his level
- `stimulate(s: Stimulus): number` — a stimulus for all (or those that perceive it): returns how many perceived it
- `onEvent(name: string, payload: unknown): boolean` — a bus event, mapped by `stimulusOfEvent`; false when it is not one the module listens to
- `attach(bus: BusLike): () => void` — listen to the bus; call the returned function to stop
- `dispose(): void`
- `assign(inputs: { id: string; px: number; visible?: boolean }[]): Map<string, MicroLod>` — the levels of everyone for a camera: `px` is a person's height on the screen (see `screenHeightPx`), `visible` false for those out of view
- `inspect(id: string)` — what an agent needs to see of a person

## Functions

### activityLog

*function* · `packages/micromotion/src/sim.ts:513`

```ts
function activityLog: (P: PersonState) => string[]
```

the names of the activities and reactions in a person's log, in order (the sequence the UE build is compared against)

### aimAt

*function* · `packages/micromotion/src/gaze.ts:139`

```ts
function aimAt(from: Vec3, facing: number, to: Vec3): GazeAim
```

the direction to a world point in the body frame: yaw (positive toward +x, the left), pitch (positive up); `facing` is the body's yaw in the world (0 = +z, positive toward +x)

### applyMicro

*function* · `packages/micromotion/src/pose.ts:184`

```ts
function applyMicro(rig: RigLike, pose: PoseLike, out: MicroOut, profile: MicroProfile, o: MicroPoseOptions): MicroPoseReport
```

The pose of a living person: adds the micro-motion `out` of the sim to `pose` (in place). Returns the face weights and a report.

### assignLods

*function* · `packages/micromotion/src/lod.ts:35`

```ts
function assignLods(people: readonly LodInput[], budget: LodBudget = DEFAULT_BUDGET, t: LodThresholds = DEFAULT_THRESHOLDS): Map<string, MicroLod>
```

The levels of a set of people: by size, then the budget demotes the farthest of the near ones to middle, and of the near-and-middle ones to far (the nearest keep theirs). Stable: ties go by id.

### bakeLoop

*function* · `packages/micromotion/src/bake.ts:59`

```ts
function bakeLoop(rig: RigLike, base: (t: number) => PoseLike, profile: MicroProfile, seed: number, posture: 'stand' | 'sit', o: BakeOptions = {}): BakedLoop
```

Record one loop of a person at rest. `base(t)` is the base pose the live person stands on (an idle clip at time t, a fresh pose each call).

### bakePerson

*function* · `packages/micromotion/src/bake.ts:91`

```ts
function bakePerson(rig: RigLike, base: (t: number) => PoseLike, profile: MicroProfile, seed: number, o: BakeOptions = {}): BakedPerson
```

Record the loops a person can have: standing, and sitting if his anchors have a seat. Done once, when the character is created.

### bakeProfile

*function* · `packages/micromotion/src/bake.ts:45`

```ts
function bakeProfile(p: MicroProfile, posture: 'stand' | 'sit'): MicroProfile
```

the profile as the recording sees him: at his place, nothing that needs a prop in hand or walks, so the loop is the person at rest

### baseRate

*function* · `packages/micromotion/src/ai.ts:85`

```ts
function baseRate(h: HabitName, t: Temperament): number
```

The rate of a habit, times a minute, that the temperament gives: a calm person swings a leg or shifts his weight a couple of times a minute, a nervous one five or more.

### beatPlan

*function* · `packages/micromotion/src/speech.ts:48`

```ts
function beatPlan(line: Line): BeatEvent[]
```

The gestures of a line: a beat on every stress and a nod on every second one, each starting early enough that its stroke lands on the stress.

### blastSize

*function* · `packages/micromotion/src/stimulus.ts:34`

```ts
function blastSize: (tnt: number) => number
```

a blast's size by its TNT equivalent in kg: 0.1 kg is a firecracker's bang near, 10 kg a loud blast, 100 kg and more the top of the scale

### blinkClosure

*function* · `packages/micromotion/src/life.ts:21`

```ts
function blinkClosure(b: BlinkState): number
```

eyelid closure 0..1 now

### blinkInterval

*function* · `packages/micromotion/src/life.ts:26`

```ts
function blinkInterval(s: Stream, nervousness: number, arousal: number): number
```

the seconds to the next blink: 2 to 5.5 s, shorter for a nervous or excited person

### blinkNow

*function* · `packages/micromotion/src/life.ts:45`

```ts
function blinkNow(b: BlinkState): void
```

a blink now, because the gaze made a big shift (not while one is on)

### breathDepth

*function* · `packages/micromotion/src/life.ts:49`

```ts
function breathDepth: (arousal: number) => number
```

### breathRate

*function* · `packages/micromotion/src/life.ts:48`

```ts
function breathRate: (arousal: number) => number
```

breathing: the phase advances by `rate` cycles a second; the rate is 0.22 Hz at rest and up to 0.6 Hz when excited

### breathWave

*function* · `packages/micromotion/src/life.ts:51`

```ts
function breathWave(phase: number): number
```

the chest's displacement for a phase in 0..1: a quicker breath in, a slower out, -1..1

### candidates

*function* · `packages/micromotion/src/sim.ts:179`

```ts
function candidates(P: PersonState, w: MicroWorld, force: boolean): { names: string[]; weights: number[] }
```

the activities that can be chosen now, with their weights

### chooseReaction

*function* · `packages/micromotion/src/stimulus.ts:91`

```ts
function chooseReaction(p: MicroProfile, kind: StimulusKind, strength: number, s: Stream): ReactionName | null
```

The reaction a person has to a stimulus of this kind and strength, drawn from his table with the weights; null when his table has none that the strength allows
(he only glances). The stronger the stimulus, the more the strong reactions count.

### chooseTarget

*function* · `packages/micromotion/src/gaze.ts:29`

```ts
function chooseTarget(p: MicroProfile, seed: number, time: number, from: Vec3, targets: readonly GazeTarget[], held: { id: string | null; since: number }, maxFix: number, boost: Record<string, number> = {}): GazeChoice
```

The most interesting target for a person at `time`. A target's score is the sum of: the profile's interest in each of its tags, its speed, its noise, whether it speaks,
how near it is, and a slow seeded noise per (person, target) that changes every 1.5 s (so equal targets take turns). The target held longer than `maxFix` is penalised, which
is the limit on locking the gaze (the caller also forces a switch past it). A short-lived `event` direction is a target of its own that the caller adds (`id: 'event'`).

### clamp

*function* · `packages/micromotion/src/math.ts:7`

```ts
function clamp: (x: number, lo: number, hi: number) => number
```

### deg

*function* · `packages/micromotion/src/math.ts:44`

```ts
function deg: (d: number) => number
```

### enqueue

*function* · `packages/micromotion/src/ai.ts:206`

```ts
function enqueue(P: AiBody, name: string, dur?: number): void
```

An order: an activity (ACTIVITIES) or a habit by name. Checked now for what cannot change (it exists, its prop and seat are there); whether the posture fits is decided when its turn comes.

### explain

*function* · `packages/micromotion/src/ai.ts:219`

```ts
function explain(P: AiBody, weights: { names: string[]; weights: number[] } | null)
```

Why he does what he does: the mode, each habit (rate, due, what stops it), the orders, and the weights of the activities he may choose (`weights` from `candidates`).

### explainPerson

*function* · `packages/micromotion/src/sim.ts:292`

```ts
function explainPerson(P: PersonState, w: MicroWorld = EMPTY_WORLD)
```

Why he does what he does (see `explain` in ai.ts): includes the chances of his next choice.

### eyePos

*function* · `packages/micromotion/src/sim.ts:129`

```ts
function eyePos: (P: PersonState) => Vec3
```

### faceOf

*function* · `packages/micromotion/src/frame.ts:88`

```ts
function faceOf(out: MicroOut, seed: number, t: number, mood: number): FaceWeights
```

the face: the face at rest, the face of the reaction or shout in progress (ramped in and out), the eyes' gaze and the blink; the largest value of each shape wins

### faceRest

*function* · `packages/micromotion/src/life.ts:69`

```ts
function faceRest(seed: number, t: number, mood: number, arousal: number): FaceWeights
```

the face at rest as ARKit weights: the mood sets a slight smile or frown, the brows and jaw drift, excitement widens the eyes. Blinks and gaze are added by the pose layer.

### fingerCurl

*function* · `packages/micromotion/src/life.ts:64`

```ts
function fingerCurl(seed: number, t: number, finger: number, side: number, nervousness: number): number
```

the curl of one finger 0..1 (the hand's rest: fingers a little curled, each its own way); `finger` 0 index .. 3 pinky, 4 thumb, `side` 0 or 1

### fkInto

*function* · `packages/micromotion/src/pose.ts:86`

```ts
function fkInto(rig: RigLike, pose: PoseLike, pos: Float32Array, wq: Float32Array, order?: Int16Array): { pos: Float32Array; q: Float32Array }
```

forward kinematics into the given buffers (world positions and rotations), no allocation

### frameOf

*function* · `packages/micromotion/src/frame.ts:32`

```ts
function frameOf(out: MicroOut, profile: MicroProfile, o: FrameOptions): MicroFrame
```

### glanceAim

*function* · `packages/micromotion/src/gaze.ts:145`

```ts
function glanceAim(seed: number, n: number, around: GazeAim): GazeAim
```

A seeded glance direction away from the current gaze: a little to the side and down or up, within the eyes' and head's range.

### habitBlock

*function* · `packages/micromotion/src/ai.ts:120`

```ts
function habitBlock(P: AiBody, h: HabitName): string | null
```

Is the habit possible now? (the reason it is not, or null)

### hash32

*function* · `packages/micromotion/src/rng.ts:5`

```ts
function hash32: (x: number) => number
```

### hashRand

*function* · `packages/micromotion/src/rng.ts:24`

```ts
function hashRand: (seed: number, a: number, b?: number) => number
```

a number in [0, 1) that is a pure function of (seed, a, b): for things that must not depend on how many numbers were drawn before

### headDir

*function* · `packages/micromotion/src/sim.ts:131`

```ts
function headDir(P: PersonState): Vec3
```

the world direction the head faces (unit)

### hear

*function* · `packages/micromotion/src/sim.ts:138`

```ts
function hear(P: PersonState, st: Stimulus, occluded?: (a: Vec3, b: Vec3) => boolean): boolean
```

A person hears of a stimulus: what he perceives of it, when, and what he does (a reaction from his table after his reaction time, a glance first). Returns true when he perceives it.

### heardStrength

*function* · `packages/micromotion/src/stimulus.ts:39`

```ts
function heardStrength(s: Stimulus, dist: number): number
```

the strength of a stimulus at a distance as heard (sound)

### impactSize

*function* · `packages/micromotion/src/stimulus.ts:36`

```ts
function impactSize: (impulse: number) => number
```

an impact's size by its impulse in N s: a dropped tool, 5 N s, is small; 2000 N s is a car hitting a wall

### lerp

*function* · `packages/micromotion/src/math.ts:8`

```ts
function lerp: (a: number, b: number, t: number) => number
```

### linkMotion

*function* · `packages/micromotion/src/motion.ts:42`

```ts
function linkMotion(session: MicroSession, bridge: MotionBridgeLike): () => void
```

Registers the words on a bridge and forwards the session's events to the runtime. Returns the function that stops the forwarding (the words stay; they do nothing for a session
that is gone). Call it once per bridge, before the programs that use the words are loaded (the language checks names when it loads).

### lodOfPx

*function* · `packages/micromotion/src/lod.ts:23`

```ts
function lodOfPx(px: number, visible = true, t: LodThresholds = DEFAULT_THRESHOLDS): MicroLod
```

the level by size alone (no budget); `visible` false is `off`

### loopFor

*function* · `packages/micromotion/src/bake.ts:111`

```ts
function loopFor(P: PersonState, baked: BakedPerson | undefined): BakedLoop | null
```

which loop (if any) a person at this moment may be shown by: only a person at rest, standing or seated, with nothing in hand, and not reacting, walking, speaking or changing posture

### loopTime

*function* · `packages/micromotion/src/bake.ts:119`

```ts
function loopTime: (seed: number, t: number, loop: BakedLoop) => number
```

the time in the loop for a person: the sim clock at a phase of his seed, so people of one profile are not in step

### maxFixation

*function* · `packages/micromotion/src/gaze.ts:51`

```ts
function maxFixation(p: MicroProfile): number
```

how long the gaze may stay on one thing, s: the profile's maximum scaled by the person's focus and nervousness

### mirrorClip

*function* · `packages/micromotion/src/clips.ts:113`

```ts
function mirrorClip(rig: RigLike, clip: MotionClip): MotionClip
```

### mirrorIndex

*function* · `packages/micromotion/src/clips.ts:71`

```ts
function mirrorIndex(rig: RigLike): Int16Array
```

### mirrorPose

*function* · `packages/micromotion/src/clips.ts:92`

```ts
function mirrorPose(rig: RigLike, pose: PoseLike): PoseLike
```

The mirror of a pose about the body's middle plane (x to -x): every joint's turn from rest is reflected and given to the joint of the other side. Done on world rotations, so it
does not depend on how the rig's local axes lie; the pelvis' offset is mirrored in x. A pose mirrored twice is the pose.

### missingGestures

*function* · `packages/micromotion/src/activities.ts:78`

```ts
function missingGestures(): string[]
```

every gesture an activity or reaction names exists (checked by the tests and the validator)

### newAi

*function* · `packages/micromotion/src/ai.ts:104`

```ts
function newAi(profile: MicroProfile, seed: number, startT: number): AiState
```

### newBlink

*function* · `packages/micromotion/src/life.ts:17`

```ts
function newBlink: (first: number) => BlinkState
```

### newGazeFrame

*function* · `packages/micromotion/src/gaze.ts:88`

```ts
function newGazeFrame: () => GazeFrame
```

### newPerson

*function* · `packages/micromotion/src/sim.ts:107`

```ts
function newPerson(id: string, profile: MicroProfile, seed: number, o: NewPersonOptions = {}): PersonState
```

### nextBlinkAt

*function* · `packages/micromotion/src/ai.ts:167`

```ts
function nextBlinkAt(P: AiBody, now: number): number | null
```

The next blink at `now`, as the settings want it: the sim calls this when a blink begins; returns the time of the next, or null to leave the life layer's own.

### nextGlanceIn

*function* · `packages/micromotion/src/gaze.ts:56`

```ts
function nextGlanceIn(p: MicroProfile, s: Stream): number
```

the seconds until the next glance away, from the profile's rate and nervousness (seeded)

### noise1

*function* · `packages/micromotion/src/rng.ts:26`

```ts
function noise1(seed: number, channel: number, t: number): number
```

a smooth noise in [-1, 1] of time t for a seed and channel (value noise, 1-D)

### order

*function* · `packages/micromotion/src/sim.ts:287`

```ts
function order(P: PersonState, name: string, o: { dur?: number; now?: boolean } = {}): void
```

Order an activity or a habit by name; it starts as soon as he is free (or at once with `now`, which drops the activity he is in).

### perceive

*function* · `packages/micromotion/src/stimulus.ts:68`

```ts
function perceive(o: Observer, s: Stimulus, occluded?: (from: Vec3, to: Vec3) => boolean): Perceived | null
```

What a person perceives of a stimulus, or null. A stimulus with no place reaches everyone at once ('told'). One with a place is heard when its strength at his ear is
above the threshold (after the sound's delay), seen when it is in his field of view and `occluded` (smoke, a wall) says the line is clear; the earlier of the two counts.

### pickWeighted

*function* · `packages/micromotion/src/rng.ts:32`

```ts
function pickWeighted(weights: readonly number[], r: number): number
```

a weighted pick: the weights of the items, the value of a draw in [0, 1)

### playClip

*function* · `packages/micromotion/src/clips.ts:141`

```ts
function playClip(rig: RigLike, pose: PoseLike, play: ClipPlay, u: number): void
```

Play a clip over a pose as a masked layer: the bones the clip names get the clip's turn since its own first frame (in the bone's own frame, scaled by the amplitude) laid on the
pose's rotation, blended in by the envelope of the gesture (the fade in and out). `u` is the gesture's progress 0..1.

### playLoop

*function* · `packages/micromotion/src/bake.ts:98`

```ts
function playLoop(rig: RigLike, pose: PoseLike, loop: BakedLoop, t: number): void
```

Lay a loop on a pose at time t (wrapping): the recorded rotations of its bones and the pelvis replace the pose's. The loop is a pose of the whole body at rest, so nothing is blended.

### poseFrame

*function* · `packages/micromotion/src/pose.ts:195`

```ts
function poseFrame(rig: RigLike, pose: PoseLike, f: MicroFrame, clips?: (pose: PoseLike) => void): MicroPoseReport
```

Applies a frame to a skeleton: the torso, the seat, the legs, the arms (then the clips, through `clips`), the fingers. The face is the frame's.

### poseLevel

*function* · `packages/micromotion/src/lod.ts:53`

```ts
function poseLevel: (l: MicroLod) => LodLevel | null
```

the pose layer's level for a micro level (a crowd person is posed by the crowd's baked clips until he comes close; off is not posed)

### poseOf

*function* · `packages/micromotion/src/bake.ts:126`

```ts
function poseOf(rig: RigLike, pose: PoseLike, P: PersonState, o: PoseOfOptions): { baked: boolean; report: MicroPoseReport }
```

One call for the frame: the near level is always live; the middle and far play the loop when the person may be shown by one, and are live otherwise. Returns what was done and the
pose report (empty hand and foot errors for a loop).

### poseThisFrame

*function* · `packages/micromotion/src/lod.ts:51`

```ts
function poseThisFrame: (l: MicroLod, frame: number, phase?: number) => boolean
```

### profile

*function* · `packages/micromotion/src/profiles.ts:92`

```ts
function profile(name: string): MicroProfile
```

a copy of a shipped profile, ready to edit

### qangle

*function* · `packages/micromotion/src/math.ts:43`

```ts
function qangle: (q: ArrayLike<number>) => number
```

the rotation angle of a quaternion, radians, 0..pi

### qaxis

*function* · `packages/micromotion/src/math.ts:26`

```ts
function qaxis: (axis: ArrayLike<number>, angle: number) => Quat
```

### qconj

*function* · `packages/micromotion/src/math.ts:24`

```ts
function qconj: (a: ArrayLike<number>) => Quat
```

### qmul

*function* · `packages/micromotion/src/math.ts:18`

```ts
function qmul: (a: ArrayLike<number>, b: ArrayLike<number>) => Quat
```

### qnorm

*function* · `packages/micromotion/src/math.ts:25`

```ts
function qnorm: (a: Quat) => Quat
```

### qrot

*function* · `packages/micromotion/src/math.ts:30`

```ts
function qrot: (q: ArrayLike<number>, v: ArrayLike<number>) => Vec3
```

### qslerp

*function* · `packages/micromotion/src/math.ts:35`

```ts
function qslerp: (a: ArrayLike<number>, b: ArrayLike<number>, t: number) => Quat
```

### rateOf

*function* · `packages/micromotion/src/ai.ts:97`

```ts
function rateOf(P: AiBody, h: HabitName): number
```

The rate now, times a minute: the setting or the temperament's, the factor, and boredom (up to +60% as `still` nears the profile's `maxStill`).

### reactionDelay

*function* · `packages/micromotion/src/stimulus.ts:101`

```ts
function reactionDelay(r: ReactionName, s: Stream): number
```

the time, s, between perceiving and the first motion: 150 to 300 ms, by the reaction

### registerMicroCommands

*function* · `packages/micromotion/src/service.ts:132`

```ts
function registerMicroCommands(host: CommandHost, session: MicroSession = new MicroSession()): MicroSession
```

Registers the `micro.*` commands on a host over a session. Returns the session.

### rnd

*function* · `packages/micromotion/src/rng.ts:15`

```ts
function rnd(s: Stream): number
```

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

### rrange

*function* · `packages/micromotion/src/rng.ts:22`

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

### runRoutine

*function* · `packages/micromotion/src/motion.ts:86`

```ts
function runRoutine(bridge: MotionBridgeLike, id: string, text: string, params: Record<string, unknown> = {}): unknown
```

Runs a person's routine (a program of the motion language, text) with `self` bound to his id. Several people may run the same text: each has his own program.

### saccade

*function* · `packages/micromotion/src/life.ts:83`

```ts
function saccade(seed: number, t: number): { yaw: number; pitch: number }
```

the small jumps of the gaze (micro-saccades), radians

### sampleClipBone

*function* · `packages/micromotion/src/clips.ts:129`

```ts
function sampleClipBone(clip: MotionClip, bone: number, t: number, out: Float32Array, at: number): void
```

the local rotation of a clip's bone at time t (it holds the last frame), slerped between frames

### sampleFeet

*function* · `packages/micromotion/src/gestures.ts:274`

```ts
function sampleFeet(g: Gesture, u: number, amp: number, t: number): SampledFoot[]
```

The foot offsets of a gesture at progress u (metres, x out to the side of the foot); `amp` scales them, `t` is the gesture's clock for the swing.

### sampleHands

*function* · `packages/micromotion/src/gestures.ts:248`

```ts
function sampleHands(g: Gesture, u: number, amp: number, t: number): SampledHand[]
```

The hand targets of a gesture at progress u. `t` is the gesture's clock in seconds (for the wobble).

### sampleKeys

*function* · `packages/micromotion/src/gestures.ts:223`

```ts
function sampleKeys(keys: [number, number][], u: number): number
```

the value of a channel's curve at progress u (smooth between keys), degrees

### sampleRot

*function* · `packages/micromotion/src/gestures.ts:237`

```ts
function sampleRot(g: Gesture, u: number, amp: number, mirror: boolean): SampledRot[]
```

The torso and head rotations of a gesture at progress u, amplitude amp (>= 0), for a dominant side (`mirror` for right-dominant: yaw and roll negate).

### say

*function* · `packages/micromotion/src/sim.ts:296`

```ts
function say(P: PersonState, line: Line)
```

A person is given a line: beats and nods fall on its stresses, and a shouted line raises the loudspeaker prop for its whole length.

### screenHeightPx

*function* · `packages/micromotion/src/lod.ts:19`

```ts
function screenHeightPx: (height: number, distance: number, fov: number, screenPx: number) => number
```

a person's height on the screen in pixels: his height, his distance, the vertical field of view and the screen's height in pixels

### seedState

*function* · `packages/micromotion/src/rng.ts:11`

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

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

### seenStrength

*function* · `packages/micromotion/src/stimulus.ts:44`

```ts
function seenStrength(s: Stimulus, dist: number): number
```

and as seen: lights and movement carry far, and fall with the square of the distance past SIGHT_DIST

### sessionFromManifest

*function* · `packages/micromotion/src/service.ts:221`

```ts
function sessionFromManifest(m: MicroManifest, o: MicroSessionOptions = {}): MicroSession
```

build a session from a manifest block

### setHabit

*function* · `packages/micromotion/src/ai.ts:179`

```ts
function setHabit(P: AiBody, h: HabitName, o: { perMin?: number | null; rate?: number; amp?: number; enabled?: boolean }): HabitSetting
```

### setMode

*function* · `packages/micromotion/src/ai.ts:175`

```ts
function setMode(P: AiBody, mode: AiMode): void
```

### setTemperament

*function* · `packages/micromotion/src/ai.ts:193`

```ts
function setTemperament(P: AiBody, patch: Partial<Temperament>): Temperament
```

Change the temperament while he lives: any of its six numbers, each 0..1. The habits' rates follow at once (they are read from it).

### smooth01

*function* · `packages/micromotion/src/math.ts:9`

```ts
function smooth01: (t: number) => number
```

### startHabit

*function* · `packages/micromotion/src/ai.ts:136`

```ts
function startHabit(P: AiBody, h: HabitName): ActiveHabit | null
```

Begin a habit now (an order, or its time). The size comes from the temperament and the setting; head turns go to a side chosen by the stream.

### startRoutines

*function* · `packages/micromotion/src/motion.ts:91`

```ts
function startRoutines(bridge: MotionBridgeLike, people: { id: string; routine?: string }[]): unknown[]
```

Starts the `routine` of every person of a manifest block that has one. Returns the programs.

### stepBlink

*function* · `packages/micromotion/src/life.ts:30`

```ts
function stepBlink(b: BlinkState, dt: number, now: number, s: Stream, nervousness: number, arousal: number): void
```

advance the blink by dt at sim time `now`

### stepGaze

*function* · `packages/micromotion/src/gaze.ts:106`

```ts
function stepGaze(g: GazeFrame, want: GazeAim, dt: number): { bodyTurn: number }
```

Advance the gaze by dt toward a target direction in the body frame (`want`, relative to where the body faces now). The eyes go first: they take what they can (within their limits)
of the angle left after the head's current turn; the head follows to a share of it; the chest takes what the head cannot comfortably; when the target stays beyond head and chest
for BODY_TURN_AFTER seconds the body turns, which returns `bodyTurn` (rad turned this step) for the caller to rotate the person by; the stages' angles are then relative to the new facing.

### stepHabits

*function* · `packages/micromotion/src/ai.ts:150`

```ts
function stepHabits(P: AiBody, dt: number): HabitName[]
```

One step of the habits. Returns the names begun in this step (the sim notes them). The blink is not here: the life layer plays it and the sim applies `blinkSetting`.

### stepPerson

*function* · `packages/micromotion/src/sim.ts:311`

```ts
function stepPerson(P: PersonState, dt: number, w: MicroWorld = EMPTY_WORLD): void
```

Advance one person by dt seconds (the fixed step).

### stimulusOfEvent

*function* · `packages/micromotion/src/stimulus.ts:112`

```ts
function stimulusOfEvent(e: BusEvent, now: number): Stimulus | null
```

The stimulus of a bus event of the physics and vfx modules (`explosion:blast`, `physics:impact`, `physics:break`, `combustion:out`, `vfx:ignite`, `vfx:out`), or of a game event
(`take:start`, `take:cut`, `scene:good`, `scene:bad`, `micro:stimulus`), at the sim time `now`. Null for any other event.

### stressTimes

*function* · `packages/micromotion/src/speech.ts:28`

```ts
function stressTimes(line: Line): number[]
```

The times of the stresses of a line: from the text (a word of four letters or more, a word ending in ! or ?, a word in capitals; placed at the middle of the word in the
line's time by the characters before it) or the given ones; sorted, and thinned to MIN_BEAT_GAP.

### swayAt

*function* · `packages/micromotion/src/life.ts:58`

```ts
function swayAt(seed: number, t: number, energy: number, nervousness: number, sit: number): Sway
```

the standing person's slow shifts of the pelvis and spine (radians, metres): a sum of slow noises, less when seated; more for an energetic or nervous person

### swing

*function* · `packages/micromotion/src/pose.ts:151`

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

the shortest rotation taking direction a to direction b

### vadd

*function* · `packages/micromotion/src/math.ts:12`

```ts
function vadd: (a: Vec3, b: Vec3) => Vec3
```

### validateMicroManifest

*function* · `packages/micromotion/src/service.ts:204`

```ts
function validateMicroManifest(m: unknown): { path: string; message: string }[]
```

### validateProfile

*function* · `packages/micromotion/src/profile.ts:74`

```ts
function validateProfile(p: unknown): Issue[]
```

### vdot

*function* · `packages/micromotion/src/math.ts:15`

```ts
function vdot: (a: Vec3, b: Vec3) => number
```

### vlen

*function* · `packages/micromotion/src/math.ts:14`

```ts
function vlen: (a: Vec3) => number
```

### vmul

*function* · `packages/micromotion/src/math.ts:13`

```ts
function vmul: (a: Vec3, k: number) => Vec3
```

### vsub

*function* · `packages/micromotion/src/math.ts:11`

```ts
function vsub: (a: Vec3, b: Vec3) => Vec3
```

### vunit

*function* · `packages/micromotion/src/math.ts:16`

```ts
function vunit: (a: Vec3) => Vec3
```

### walkTo

*function* · `packages/micromotion/src/sim.ts:282`

```ts
function walkTo(P: PersonState, pos: Vec3): void
```

Order him to walk to a place on the floor; it becomes his home on arrival (he stands up first if he is seated). A walk about the old home in progress is dropped.

### withHysteresis

*function* · `packages/micromotion/src/lod.ts:55`

```ts
function withHysteresis(prev: MicroLod | undefined, next: MicroLod, held: number, frames = 20): { level: MicroLod; held: number }
```

a change of level takes this many frames of hysteresis so a person on the edge does not flicker

### wrapPi

*function* · `packages/micromotion/src/math.ts:10`

```ts
function wrapPi: (a: number) => number
```

## Interfaces

### ActiveActivity

*interface* · `packages/micromotion/src/sim.ts:27`

```ts
interface ActiveActivity
```

- `def: ActivityDef`
- `gesture: Gesture | null`
- `t: number`
- `dur: number`
- `amp: number`
- `legs: Vec3[]`
- `leg: number`
- `pause: number`
- `rehome?: Vec3` — when the walk ends, this point becomes his home (a walk ordered to a place)

### ActiveBeat

*interface* · `packages/micromotion/src/sim.ts:30`

```ts
interface ActiveBeat
```

- `g: Gesture`
- `kind: 'beat' | 'nod'`
- `t: number`
- `dur: number`
- `amp: number`

### ActiveHabit

*interface* · `packages/micromotion/src/ai.ts:47`

```ts
interface ActiveHabit
```

- `name: HabitName`
- `g: Gesture`
- `t: number`
- `dur: number`
- `amp: number`

### ActiveReaction

*interface* · `packages/micromotion/src/sim.ts:29`

```ts
interface ActiveReaction
```

- `def: ReactionDef`
- `gesture: Gesture | null`
- `t: number`
- `dur: number`
- `amp: number`
- `strength: number`

### ActivityDef

*interface* · `packages/micromotion/src/activities.ts:8`

```ts
interface ActivityDef
```

- `id: string`
- `gesture?: string`
- `special?: 'walk' | 'sit-down' | 'stand-up'`
- `posture: PostureName | 'any'`
- `prop?: string`
- `take?: 'running' | 'idle' | 'any'`
- `cool: number`
- `energy: number`
- `arousal?: number` — what the activity does to arousal (added, 0..1)

### AiBody

*interface* · `packages/micromotion/src/ai.ts:67`

```ts
interface AiBody
```

what the AI needs of a person: the sim's `PersonState` has all of this

- `t: number`
- `posture: PostureName`
- `trans: object | null`
- `reaction: object | null`
- `activity: { gesture: Gesture | null } | null`
- `speed: number`
- `still: number`
- `arousal: number`
- `profile: MicroProfile`
- `ai: AiState`
- `habits: ActiveHabit[]`
- `blink: { next: number; t: number }`

### AiOrder

*interface* · `packages/micromotion/src/ai.ts:48`

```ts
interface AiOrder
```

- `name: string`
- `dur?: number`

### AiState

*interface* · `packages/micromotion/src/ai.ts:49`

```ts
interface AiState
```

- `rs: number`
- `mode: AiMode`
- `habits: Record<HabitName, HabitSetting>`
- `due: Record<HabitName, number>` — the sim time at which each habit is next due
- `queue: AiOrder[]` — orders to carry out as soon as he is free: an activity or a habit
- `goto: Vec3 | null` — a place to walk to, and whether he has arrived (the count of arrivals, for a program that waits)
- `arrivals: number`
- `count: Record<HabitName, number>` — the habits begun, by name (a diagnostic)
- `chair: { home: Vec3; seat: NonNullable<MicroProfile['anchors']['seat']> } | null` — the chair he was given: where it stands and what it is like; it stays there when he walks off, and he can sit again only at it

### Anchors

*interface* · `packages/micromotion/src/profile.ts:31`

```ts
interface Anchors
```

- `home: Vec3` — the home point on the floor [x, y, z], metres, and the way the person faces there (yaw, radians, 0 = +z, positive toward +x)
- `facing: number`
- `seat?: { height: number; back: boolean; armrests: boolean }` — a seat: the seat's height above the floor, metres, and whether it has a back and armrests
- `radius: number` — how far from home the person walks about, metres

### BakedLoop

*interface* · `packages/micromotion/src/bake.ts:21`

```ts
interface BakedLoop
```

- `posture: 'stand' | 'sit'`
- `duration: number` — seconds, and frames per second
- `fps: number`
- `frames: number`
- `bones: string[]` — bone names, and frames * bones * 4 local rotations
- `rot: Float32Array`
- `pelvis: Float32Array` — the pelvis position per frame: frames * 3

### BakedPerson

*interface* · `packages/micromotion/src/bake.ts:30`

```ts
interface BakedPerson
```

- `seed: number`
- `profile: string`
- `stand?: BakedLoop`
- `sit?: BakedLoop`

### BakeOptions

*interface* · `packages/micromotion/src/bake.ts:32`

```ts
interface BakeOptions
```

- `seconds?: number` — seconds in the loop (default 40: long enough that the repeat is not noticed from far)
- `fps?: number` — frames per second recorded (default 15)
- `fade?: number` — seconds of the tail blended into the head to close the loop (default 1.5)
- `lod?: LodLevel` — the level the pose is solved at while recording (default 'middle': arms and legs, no fingers)
- `seatHeight?: number`

### BeatEvent

*interface* · `packages/micromotion/src/speech.ts:16`

```ts
interface BeatEvent
```

- `start: number` — when the gesture starts, s from the start of the line (it may be before 0 for a stress at the very start: clamped to 0)
- `stress: number` — when its stroke lands, s from the start of the line: the stress
- `kind: 'beat' | 'nod'`

### BlinkState

*interface* · `packages/micromotion/src/life.ts:9`

```ts
interface BlinkState
```

- `next: number` — sim time of the next blink, s
- `t: number` — time since this blink began, s; negative: not blinking
- `twice: boolean` — a second blink follows this one

### BusEvent

*interface* · `packages/micromotion/src/stimulus.ts:107`

```ts
interface BusEvent
```

- `name: string`
- `payload: any`

### BusLike

*interface* · `packages/micromotion/src/service.ts:17`

```ts
interface BusLike
```

- `on(name: string, fn: (payload: any) => void): () => void`

### Channel

*interface* · `packages/micromotion/src/gestures.ts:10`

```ts
interface Channel
```

pitch: about +x (positive leans a bone that points up toward +z: the chest forward, the chin down); yaw: about +y (toward the person's left); roll: about +z (toward the right)

- `bone: string`
- `axis: Axis`
- `keys: [number, number][]`

### ClipPlay

*interface* · `packages/micromotion/src/clips.ts:29`

```ts
interface ClipPlay
```

how a clip is played: a variant by the seed, the person's hand, a speed and an amplitude, the style of his profile

- `clip: MotionClip`
- `mirror: boolean`
- `speed: number`
- `amp: number`
- `fade: number` — blend in and out, seconds

### CommandHost

*interface* · `packages/micromotion/src/service.ts:16`

```ts
interface CommandHost
```

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

### FootTrack

*interface* · `packages/micromotion/src/gestures.ts:19`

```ts
interface FootTrack
```

A foot's offset from where the pose has it (a seated person's foot on the floor, a standing person's foot planted): x out to the side of the foot, y up, z forward, metres; keys [u, x, y, z]; `wob` swings it while held.

- `side: 'd' | 'o'`
- `keys: [number, number, number, number][]`
- `wob?: { hz: number; d: [number, number, number]; from: number; to: number }`

### FrameHand

*interface* · `packages/micromotion/src/frame.ts:14`

```ts
interface FrameHand
```

- `side: 'l' | 'r'`
- `pos: Vec3`
- `w: number`
- `ownsProp: boolean`

### FrameOptions

*interface* · `packages/micromotion/src/frame.ts:29`

```ts
interface FrameOptions
```

- `lod?: LodLevel`
- `time: number`
- `seed: number`
- `seatHeight?: number`
- `skip?: (g: GestureOut) => boolean`

### FrameProp

*interface* · `packages/micromotion/src/frame.ts:15`

```ts
interface FrameProp
```

- `side: 'l' | 'r'`
- `at: Vec3`

### FrameRot

*interface* · `packages/micromotion/src/frame.ts:13`

```ts
interface FrameRot
```

- `bone: string`
- `axis: FrameAxis`
- `rad: number`

### GazeAim

*interface* · `packages/micromotion/src/gaze.ts:78`

```ts
interface GazeAim
```

- `yaw: number`
- `pitch: number`

### GazeChoice

*interface* · `packages/micromotion/src/gaze.ts:19`

```ts
interface GazeChoice
```

- `id: string | null`
- `score: number`

### GazeFrame

*interface* · `packages/micromotion/src/gaze.ts:79`

```ts
interface GazeFrame
```

- `eyes: GazeAim`
- `head: GazeAim`
- `chest: GazeAim`
- `bodyYaw: number` — the body's turn so far from where it started, radians (the whole person turns by this much)
- `beyond: number` — the time the target has been beyond what head and chest reach, s
- `headV: GazeAim` — how fast the head and the chest are turning now, rad/s
- `chestV: number`

### GazeParams

*interface* · `packages/micromotion/src/profile.ts:39`

```ts
interface GazeParams
```

- `maxFixation: number` — the longest the gaze stays on one target, s, at focus 1 (a lower focus shortens it)
- `glancesPerMin: number` — glances away per minute

### GazeTarget

*interface* · `packages/micromotion/src/gaze.ts:9`

```ts
interface GazeTarget
```

- `id: string`
- `pos: Vec3`
- `tags: string[]`
- `speed?: number` — its speed, m/s (movement in view draws the eye)
- `loud?: number` — loudness 0..1
- `speaking?: boolean`

### Gesture

*interface* · `packages/micromotion/src/gestures.ts:24`

```ts
interface Gesture
```

- `id: string`
- `dur: [number, number]` — seconds: [min, max]
- `rot: Channel[]`
- `hands: HandTrack[]`
- `prop?: { name: string; mode: 'rest' | 'use' }` — the prop mode this gesture asks for (a loudspeaker or a camera in hand: `use`; none: leave it)
- `shift?: [number, number, number][]` — a pelvis shift (x to the side, z forward, metres) over the gesture, and the root's sway of the weight
- `feet?: FootTrack[]` — offsets of the feet (a leg swung, a foot tapped, the unloaded foot lifted when the weight goes to the other)

### GestureOut

*interface* · `packages/micromotion/src/sim.ts:34`

```ts
interface GestureOut
```

- `kind: 'activity' | 'reaction' | 'beat' | 'nod' | 'habit'`
- `g: Gesture`
- `u: number`
- `t: number`
- `amp: number`

### HabitDef

*interface* · `packages/micromotion/src/ai.ts:19`

```ts
interface HabitDef
```

- `id: HabitName`
- `gesture: string | null` — the gesture it plays (null: the blink, which the life layer plays)
- `posture: PostureName | 'any'` — where it can be done
- `group: 'legs' | 'head' | 'eyes'` — habits of one group do not run together (two things with the legs at once)

### HabitSetting

*interface* · `packages/micromotion/src/ai.ts:37`

```ts
interface HabitSetting
```

the settings of a habit (the profile gives the first ones; `micro.habit` changes them)

- `perMin?: number` — times a minute, overriding the rate the temperament gives (undefined: from the temperament)
- `rate: number` — a factor on the rate, whatever its source
- `amp: number` — a factor on the size of the motion
- `enabled: boolean`

### HandTrack

*interface* · `packages/micromotion/src/gestures.ts:12`

```ts
interface HandTrack
```

- `side: 'd' | 'o'`
- `keys: HandKey[]`
- `wob?: { hz: number; d: [number, number, number]; from: number; to: number }` — a wobble while the hand is held: frequency Hz and the displacement in metres along x, y, z, over the span [from, to] of the gesture's progress

### Issue

*interface* · `packages/micromotion/src/profile.ts:69`

```ts
interface Issue
```

- `path: string`
- `message: string`

### Line

*interface* · `packages/micromotion/src/speech.ts:6`

```ts
interface Line
```

- `text?: string` — the words (optional when `stresses` are given)
- `duration: number` — how long it lasts, s
- `stresses?: number[]` — the times of the stressed moments, s from the start of the line; derived from the text when absent
- `shout?: boolean` — shouted through a loudspeaker prop (raised for the whole line)

### LodBudget

*interface* · `packages/micromotion/src/lod.ts:12`

```ts
interface LodBudget
```

- `near: number` — most people posed at the near level / near and middle together
- `nearMiddle: number`

### LodInput

*interface* · `packages/micromotion/src/lod.ts:32`

```ts
interface LodInput
```

- `id: string`
- `px: number`
- `visible?: boolean`

### LodThresholds

*interface* · `packages/micromotion/src/lod.ts:7`

```ts
interface LodThresholds
```

- `near: number` — the person's height on the screen, pixels, from which each level is used
- `middle: number`
- `far: number`

### LogEntry

*interface* · `packages/micromotion/src/sim.ts:32`

```ts
interface LogEntry
```

- `t: number`
- `kind: 'activity' | 'reaction' | 'posture' | 'stimulus' | 'beat' | 'glance' | 'walk' | 'habit' | 'order'`
- `id: string`

### MicroFrame

*interface* · `packages/micromotion/src/frame.ts:16`

```ts
interface MicroFrame
```

- `lod: LodLevel`
- `sit: number`
- `seatHeight: number`
- `mirror: boolean`
- `sway: { roll: number; yaw: number; shiftX: number; shiftZ: number }`
- `breath: number` — the chest's breath in radians, and the clavicle's, signed for the left
- `breathClavicle: number`
- `head: { yaw: number; pitch: number }`
- `chestYaw: number`
- `rot: FrameRot[]`
- `hands: FrameHand[]`
- `props: FrameProp[]`
- `feet: { l: Vec3; r: Vec3 }` — offsets of the feet from where the pose has them, metres (x out to the side of the foot, y up, z forward)
- `curl: number[]` — the finger curl 0..1 of each finger: side * 4 + finger (index, middle, ring, pinky)
- `face: FaceWeights`

### MicroManifest

*interface* · `packages/micromotion/src/service.ts:203`

```ts
interface MicroManifest
```

- `people?: MicroManifestPerson[]`
- `targets?: (GazeTarget & { id: string })[]`
- `take?: 'idle' | 'running'`

### MicroManifestPerson

*interface* · `packages/micromotion/src/service.ts:202`

```ts
interface MicroManifestPerson
```

`routine`: a program of the motion language run for this person when the level loads (`self` is his id; see motion.ts)

- `id: string`
- `profile: string | MicroProfile`
- `seed?: number`
- `pos?: Vec3`
- `facing?: number`
- `routine?: string`

