# @ferret/micromotion: API (continued)

### MicroOut

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

```ts
interface MicroOut
```

- `posture: PostureName`
- `sit: number` — 0 standing .. 1 seated, through the change
- `gestures: GestureOut[]`
- `props: Record<string, number>` — each prop in the profile: 0 at rest .. 1 in use
- `gaze: { eyes: GazeAim; head: GazeAim; chest: GazeAim; bodyYaw: number; target: string | null; blink: number; glancing: boolean }`
- `moving: boolean`
- `speed: number`
- `arousal: number`

### MicroPerson

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

```ts
interface MicroPerson
```

- `state: PersonState`
- `lod: MicroLod`
- `held: number`
- `seen: number`

### MicroPoseOptions

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

```ts
interface MicroPoseOptions
```

- `lod?: LodLevel`
- `time: number` — the sim clock for the life layers' time, s
- `seed: number`
- `seatHeight?: number` — the seat's height, m (default 0.47)
- `clips?: ClipBank` — clips for gestures: a gesture with a clip here is played by the clip (a masked layer), the rest by the module's curves

### MicroPoseReport

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

```ts
interface MicroPoseReport
```

- `face: FaceWeights`
- `handError: { l: number; r: number }` — how far each hand ended from the target it was given, m (0 when it had none)
- `footError: { l: number; r: number }` — how far each foot ended from where it stood, m (a seated person's feet go to the floor in front, so it is measured from that target)
- `maxTurn: number` — the largest turn any joint was given, degrees

### MicroProfile

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

```ts
interface MicroProfile
```

- `name: string`
- `role: string`
- `temperament: Temperament`
- `handedness: 'left' | 'right'`
- `repertoire: Record<string, number>` — activity name -> weight (> 0); every name is in ACTIVITIES
- `props: Record<string, PropSpec>`
- `anchors: Anchors`
- `interests: Record<string, number>` — target tag -> how much it raises salience for this person (0..3)
- `reactions: Partial<Record<StimulusKind, Partial<Record<ReactionName, number>>>>` — stimulus kind -> reaction -> weight; a kind that is missing does not move the person (a glance only)
- `gaze: GazeParams`
- `maxStill: number` — the longest time, s, in which nothing but the life layers moves the person
- `seated?: boolean` — starts seated
- `habits?: HabitSettings` — the settings of his habits: how often he swings a leg, turns his head, shifts his weight, blinks (the rest come from the temperament)
- `mode?: AiMode` — the AI mode he starts in (default 'auto')

### MicroSessionOptions

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

```ts
interface MicroSessionOptions
```

- `thresholds?: LodThresholds`
- `budget?: LodBudget`
- `occluded?: MicroWorld['occluded']`

### MicroWorld

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

```ts
interface MicroWorld
```

- `targets: readonly GazeTarget[]` — what there is to look at
- `take?: 'idle' | 'running'` — a scene is running (the one in charge shouts, the one with a camera follows the action)
- `occluded?: (from: Vec3, to: Vec3) => boolean` — the line is blocked (smoke, a wall)

### MotionBridgeLike

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

```ts
interface MotionBridgeLike
```

the part of `MotionBridge` (@ferret/motion) this link uses

- `define(name: string, sig: { args: string[]; min?: number; rest?: string; returns?: string }, fn: (ctx: unknown, ...args: any[]) => unknown): unknown`
- `lasting(name: string, sig: { args: string[]; min?: number; rest?: string; returns?: string }, fn: (ctx: unknown, ...args: any[]) => { done(): boolean; result?: unknown }): unknown`
- `run(program: string | unknown, params?: Record<string, unknown>): unknown`
- `readonly rt: { deliver(name: string, payload?: unknown): void }`

### MotionClip

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

```ts
interface MotionClip
```

- `id: string`
- `duration: number` — seconds
- `fps: number`
- `frames: number`
- `bones: string[]` — the bones the clip drives, and their local rotations per frame: frames * bones.length * 4
- `rot: Float32Array`
- `plays: string[]` — the gestures it can play (ids of GESTURES or reactions), e.g. `point`, `megaphone-shout`, `cheer`
- `dominant?: 'l' | 'r'` — the clip is made for a left-dominant (the module's frame) or a right-dominant person; the other is got by mirroring
- `amplitude?: number` — the clip's own look: how large and how quick it is as made (1 = as made)

### NewPersonOptions

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

```ts
interface NewPersonOptions
```

- `pos?: Vec3`
- `facing?: number`
- `external?: boolean`

### Observer

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

```ts
interface Observer
```

- `pos: Vec3`
- `facing: Vec3` — the direction the head faces, a unit vector in the world
- `fov?: number` — half the field of view of the eyes, radians (default 100 degrees)

### Perceived

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

```ts
interface Perceived
```

- `arrive: number` — the sim time when it reaches him: the sound's delay for the distance, the light at once
- `strength: number`
- `dir: Vec3 | null` — a unit vector from him to the source (null for a stimulus with no place)
- `by: 'sight' | 'hearing' | 'told'`

### PersonState

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

```ts
interface PersonState
```

- `id: string`
- `profile: MicroProfile`
- `seed: number`
- `rs: number`
- `t: number` — sim clock, s
- `posture: PostureName`
- `trans: { to: PostureName; t: number; total: number } | null`
- `pos: Vec3`
- `facing: number` — yaw in the world, radians, 0 = +z, positive toward +x
- `external: boolean` — the game moves the person (a NavAgent); the sim then does not integrate walks
- `activity: ActiveActivity | null`
- `reaction: ActiveReaction | null`
- `beats: ActiveBeat[]`
- `nextAt: number`
- `cool: Record<string, number>`
- `recent: string[]`
- `fatigue: number`
- `arousal: number`
- `pending: Pending[]`
- `line: { line: Line; t: number; plan: BeatEvent[]; next: number } | null`
- `gaze: { frame: GazeFrame; target: string | null; since: number; tick: number; glanceUntil: number; glanceTo: GazeAim; nextGlance: number; glances: number; event: { dir: Vec3; until: number } | null; idle: GazeAim; lastWant: GazeAim; }`
- `blink: BlinkState`
- `still: number` — time since anything but the life layers moved him, s
- `propBlend: Record<string, number>`
- `speed: number`
- `longestDwell: number` — the longest the gaze has stayed on one target without a glance, s (a diagnostic)
- `log: LogEntry[]`
- `logN: number` — how many log entries there have been in all (the log keeps the last ones)
- `ai: AiState` — his own AI: mode, habits, orders (see ai.ts), and the habits under way
- `habits: ActiveHabit[]`
- `releasing: { kind: GestureOut['kind']; g: Gesture; u: number; t: number; amp: number; age: number }[]` — gestures taken away before their end (a reaction cuts the activity, a stronger reaction the weaker one, an ordered habit the one of its group): each goes on being drawn where it was cut, its amplitude going to nothing over RELEASE seconds, so a body part never jumps back to rest in one frame
- `out: MicroOut`

### PoseLike

*interface* · `packages/micromotion/src/pose.ts:20`

```ts
interface PoseLike
```

- `q: Float32Array`
- `pelvis: [number, number, number]`

### PoseOfOptions

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

```ts
interface PoseOfOptions
```

- `lod: LodLevel`
- `time: number`
- `seed: number`
- `seatHeight?: number`
- `baked?: BakedPerson`

### PropSpec

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

```ts
interface PropSpec
```

- `hand: 'd' | 'o' | 'both'` — the hand that holds it (the dominant one by default)
- `socket: string` — the socket (a bone name) it hangs on when not in hand
- `rest: [number, number, number][]` — hand targets from the shoulder, left-dominant frame, metres at the reference arm length (see gestures.ts), at rest and in use; [d, o] hands
- `use: [number, number, number][]`

### ReactionDef

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

```ts
interface ReactionDef
```

- `id: ReactionName`
- `gesture: string | null` — the gesture it plays (null: no gesture of its own, the posture or the gaze does it)
- `arousal: number` — how much it adds to arousal at strength 1
- `look: boolean` — the gaze goes to the source of the stimulus
- `stand?: boolean` — the person gets to his feet
- `delay: [number, number]` — the first motion comes this soon after the stimulus is perceived: [min, max] seconds (the plan's 150-300 ms)

### RigLike

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

```ts
interface RigLike
```

- `n: number`
- `names: string[]`
- `index: Map<string, number>`
- `parent: Int16Array`
- `restQ: Float32Array`
- `restWorldQ: Float32Array`
- `tLocal: Float32Array`
- `restWorld: Float32Array`
- `legScale: number`

### SampledFoot

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

```ts
interface SampledFoot
```

- `side: 'd' | 'o'`
- `pos: [number, number, number]`

### SampledHand

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

```ts
interface SampledHand
```

- `side: 'd' | 'o'`
- `pos: [number, number, number] | null`
- `w: number`

### SampledRot

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

```ts
interface SampledRot
```

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

### Stimulus

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

```ts
interface Stimulus
```

- `kind: StimulusKind`
- `at: Vec3 | null` — where it happened; null: the whole set hears it (a scene starting, a shout by the one in charge)
- `size: number` — its size at the source, 0..1.4 (a blast's follows its TNT equivalent, an impact's its impulse)
- `t0: number` — the sim clock when it happened, s
- `sound: boolean` — can it be heard / seen
- `sight: boolean`
- `note?: string` — what it is, for the log

### Stream

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

```ts
interface Stream
```

- `rs: number`

### Sway

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

```ts
interface Sway
```

- `roll: number`
- `yaw: number`
- `shiftX: number`
- `shiftZ: number`

### Temperament

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

```ts
interface Temperament
```

- `energy: number` — how often and how wide the motions are
- `nervousness: number` — fidget rate, short attention span, tremor
- `expansiveness: number` — the size of gestures, how far from the body
- `dominance: number` — an upright stance, pointing at others
- `focus: number` — how long attention stays on one thing
- `mood: number` — 0 gloomy .. 1 cheerful: the face at rest and the reactions

## Types

### AiMode

*type* · `packages/micromotion/src/profile.ts:11`

```ts
type AiMode = 'auto' | 'habits' | 'off'
```

### Axis

*type* · `packages/micromotion/src/gestures.ts:8`

```ts
type Axis = 'pitch' | 'yaw' | 'roll'
```

### FaceWeights

*type* · `packages/micromotion/src/life.ts:7`

```ts
type FaceWeights = Record<string, number>
```

### FrameAxis

*type* · `packages/micromotion/src/frame.ts:12`

```ts
type FrameAxis = 0 | 1 | 2
```

### HabitName

*type* · `packages/micromotion/src/profile.ts:9`

```ts
type HabitName = 'leg-swing' | 'foot-tap' | 'head-turn' | 'weight-shift' | 'blink'
```

### HabitSettings

*type* · `packages/micromotion/src/profile.ts:14`

```ts
type HabitSettings = Partial<Record<HabitName, { perMin?: number; rate?: number; amp?: number; enabled?: boolean }>>
```

the settings of the habits of a person (see ai.ts): `perMin` fixes the rate, `rate` and `amp` are factors, `enabled` false switches it off

### HandKey

*type* · `packages/micromotion/src/gestures.ts:11`

```ts
type HandKey = [number, number, number, number] | [number, 'rest']
```

### LodLevel

*type* · `packages/micromotion/src/lod.ts:5`

```ts
type LodLevel = 'near' | 'middle' | 'far'
```

the levels the pose layer knows

### MicroListener

*type* · `packages/micromotion/src/service.ts:21`

```ts
type MicroListener = (name: string, id: string) => void
```

what the session announces: `micro:activity`, `micro:reaction`, `micro:posture`, `micro:habit`, `micro:walk`, `micro:arrived`, `micro:refused`, `micro:removed`; the argument is the person's id

### MicroLod

*type* · `packages/micromotion/src/lod.ts:6`

```ts
type MicroLod = LodLevel | 'crowd' | 'off'
```

### PostureName

*type* · `packages/micromotion/src/activities.ts:7`

```ts
type PostureName = 'stand' | 'sit'
```

### Quat

*type* · `packages/micromotion/src/math.ts:4`

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

### ReactionName

*type* · `packages/micromotion/src/activities.ts:51`

```ts
type ReactionName = 'flinch' | 'startle' | 'duck' | 'turn-look' | 'stand-up' | 'cheer' | 'applaud' | 'despair' | 'anger'
```

### StimulusKind

*type* · `packages/micromotion/src/profile.ts:6`

```ts
type StimulusKind = 'blast' | 'impact' | 'break' | 'fire' | 'fire-out' | 'shot' | 'speech' | 'take-start' | 'take-cut' | 'scene-good' | 'scene-bad' | 'custom'
```

### Vec3

*type* · `packages/micromotion/src/math.ts:3`

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

## Constants

### ACTIVITIES

*const* · `packages/micromotion/src/activities.ts:22`

```ts
const ACTIVITIES: Record<string, ActivityDef>
```

### AI_MODES

*const* · `packages/micromotion/src/profile.ts:12`

```ts
const AI_MODES: AiMode[]
```

### BAKE_BONES

*const* · `packages/micromotion/src/bake.ts:18`

```ts
const BAKE_BONES: string[]
```

the bones a loop records: those the pose layer turns (the fingers and the face are near-level only)

### BEAT_PEAK

*const* · `packages/micromotion/src/gestures.ts:217`

```ts
const BEAT_PEAK: 0.4
```

the progress u at which a beat gesture's stroke lands (a speech stress is aligned to it)

### BLINK_CLOSE

*const* · `packages/micromotion/src/life.ts:19`

```ts
const BLINK_CLOSE: 0.06
```

### BLINK_OPEN

*const* · `packages/micromotion/src/life.ts:19`

```ts
const BLINK_OPEN: 0.14
```

### BODY_TURN_AFTER

*const* · `packages/micromotion/src/gaze.ts:76`

```ts
const BODY_TURN_AFTER: 0.9
```

the time, s, the target must be out of reach of head and chest before the body turns

### BONE_LIMITS

*const* · `packages/micromotion/src/gestures.ts:220`

```ts
const BONE_LIMITS: Record<string, number>
```

the comfort limits of a rotation channel's bone, degrees (a gesture's value is clamped to them)

### DEFAULT_BUDGET

*const* · `packages/micromotion/src/lod.ts:16`

```ts
const DEFAULT_BUDGET: LodBudget
```

### DEFAULT_THRESHOLDS

*const* · `packages/micromotion/src/lod.ts:11`

```ts
const DEFAULT_THRESHOLDS: LodThresholds
```

### EMPTY_WORLD

*const* · `packages/micromotion/src/sim.ts:25`

```ts
const EMPTY_WORLD: MicroWorld
```

### GAZE_LIMITS

*const* · `packages/micromotion/src/gaze.ts:63`

```ts
const GAZE_LIMITS: { eyes: { yaw: number; up: number; down: number; }; head: { yaw: number; up: number; down: number; }; chest: { yaw: number; }; headComfort: number; }
```

the limits of each stage, radians

### GAZE_SPEED

*const* · `packages/micromotion/src/gaze.ts:71`

```ts
const GAZE_SPEED: { eyes: number; head: number; chest: number; body: number; headMax: number; chestMax: number; bodyMax: number; }
```

how fast each stage follows, 1/s (the eyes jump in about a tenth of a second) and the most it turns, rad/s

### GAZE_SPRING

*const* · `packages/micromotion/src/gaze.ts:74`

```ts
const GAZE_SPRING: { head: number; chest: number; }
```

the head and the chest are heavy: they speed up into a turn and slow down out of it (a critically damped follow of this natural frequency, rad/s), never starting
at full speed in one frame as a first-order follow would; the eyes, light, jump (a saccade)

### GESTURES

*const* · `packages/micromotion/src/gestures.ts:48`

```ts
const GESTURES: Record<string, Gesture>
```

### HABIT_NAMES

*const* · `packages/micromotion/src/profile.ts:10`

```ts
const HABIT_NAMES: HabitName[]
```

### HABITS

*const* · `packages/micromotion/src/ai.ts:28`

```ts
const HABITS: Record<HabitName, HabitDef>
```

### HEARING_THRESHOLD

*const* · `packages/micromotion/src/stimulus.ts:31`

```ts
const HEARING_THRESHOLD: 0.04
```

### MIN_BEAT_GAP

*const* · `packages/micromotion/src/speech.ts:24`

```ts
const MIN_BEAT_GAP: 0.45
```

the least time between two stresses that get a gesture, s (a hand cannot chop faster and look natural)

### MIN_STRENGTH

*const* · `packages/micromotion/src/stimulus.ts:87`

```ts
const MIN_STRENGTH: Record<ReactionName, number>
```

the least strength at which a reaction is possible (a ducking man needs a loud thing)

### POSE_EVERY

*const* · `packages/micromotion/src/lod.ts:50`

```ts
const POSE_EVERY: Record<MicroLod, number>
```

How often a level is posed, in frames (the sim is not affected): the far ones every few frames, the off ones never.

### PROFILE_NAMES

*const* · `packages/micromotion/src/profiles.ts:97`

```ts
const PROFILE_NAMES: string[]
```

### PROFILES

*const* · `packages/micromotion/src/profiles.ts:16`

```ts
const PROFILES: Record<string, MicroProfile>
```

### QI

*const* · `packages/micromotion/src/math.ts:6`

```ts
const QI: Quat
```

### REACTIONS

*const* · `packages/micromotion/src/activities.ts:65`

```ts
const REACTIONS: Record<ReactionName, ReactionDef>
```

### RELEASE

*const* · `packages/micromotion/src/sim.ts:95`

```ts
const RELEASE: 0.3
```

how long a cut gesture takes to let go, s

### restPose

*const* · `packages/micromotion/src/pose.ts:287`

```ts
const restPose: (rig: RigLike) => PoseLike
```

a fresh rest pose of a rig (a pose to build on when there is no clip)

### SALIENCE

*const* · `packages/micromotion/src/gaze.ts:22`

```ts
const SALIENCE: { tag: number; speed: number; loud: number; speaking: number; near: number; noise: number; dwellPenalty: number; event: number; }
```

the weight of each source of salience

### SPEED_OF_SOUND

*const* · `packages/micromotion/src/stimulus.ts:10`

```ts
const SPEED_OF_SOUND: 343
```

### STIMULUS_EVENTS

*const* · `packages/micromotion/src/stimulus.ts:136`

```ts
const STIMULUS_EVENTS: readonly ["explosion:blast", "physics:impact", "physics:break", "combustion:out", "vfx:ignite", "vfx:out", "take:start", "take:cut", "scene:good", "scene:bad", "micro:stimulus"]
```

the bus events a service listens to

### STIMULUS_KINDS

*const* · `packages/micromotion/src/profile.ts:7`

```ts
const STIMULUS_KINDS: StimulusKind[]
```

