# Timeline and Keyframes

Tracks of keyframes on any property, smooth curves, spring follow-through and loop modes.

`timeline.tracks` animate properties over `duration` seconds. Each track targets one node (or `"$camera"`) and one property, with keyframes sorted by `t`.

```json title="apps/docs/examples/timeline.json"
{
  "camera": { "position": [0, 1, 7], "target": [0, 0.6, 0], "fov": 40 },
  "lighting": { "rig": "studio_soft" },
  "environment": {
    "background": {
      "radial_gradient": { "inner": "#1b2233", "outer": "#07090f" }
    }
  },
  "materials": { "floor": { "preset": "matte_clay", "color": "#2a2f3a" } },
  "nodes": {
    "floor": {
      "mesh": {
        "geometry": { "plane": { "size": [30, 30] } },
        "material": "floor"
      },
      "transform": { "rotation": [-90, 0, 0] }
    },
    "ball": {
      "transform": { "position": [-2, 0.5, 0] },
      "mesh": {
        "geometry": { "sphere": { "radius": 0.5 } },
        "material": "preset:glossy_plastic"
      }
    }
  },
  "timeline": {
    "duration": 3,
    "loop": "ping_pong",
    "tracks": {
      "move": {
        "target": "ball",
        "property": "position",
        "keyframes": [
          { "t": 0, "value": [-2, 0.5, 0], "easing": "ease_in_out_cubic" },
          { "t": 3, "value": [2, 0.5, 0] }
        ]
      },
      "tint": {
        "target": "ball",
        "property": "color",
        "keyframes": [
          { "t": 0, "value": "#3d85c6" },
          { "t": 3, "value": "#e07a5f" }
        ]
      },
      "bob": {
        "target": "ball",
        "property": "scale",
        "curve": "smooth",
        "keyframes": [
          { "t": 0, "value": [1, 1, 1] },
          { "t": 1.5, "value": [1.3, 0.8, 1.3] },
          { "t": 3, "value": [1, 1, 1] }
        ]
      }
    }
  }
}
```

![Render of timeline](/renders/timeline.gif)

## Properties

`position`, `rotation`, `scale`, `opacity`, `color`, `emissive_intensity`, `morph` (blends a shape through its morph outlines; authoring builds), `trim_start` and `trim_end` (the drawn part of a shape's stroke, 0 to 1; authoring builds), `bend` (degrees: curls a skinned limb, shared over the bones after the target; see [Bending limbs](/docs/features/svg#bending-limbs); authoring builds), `ik_mix` (0 to 1: how much a node's [IK](/docs/features/rigging) wins over the keyed pose; authoring builds), and on the camera `look_at` and `fov`. Values are a number, `[x, y, z]` or a hex colour, matching the property.

## Easing Between Keys

Each keyframe's `easing` shapes the timing to the next key. See [Easing and Springs](/docs/features/easing).

## Smooth Curves

`"curve": "smooth"` draws one flowing curve through every key, with no stop or corner at each one. It eases in at the first key and out at the last, and loops seamlessly when the first and last values match. Keys' easings are ignored. Use it for swaying, floating and hand-drawn paths: a few keys, no per-key easing.

## Spring Follow-Through

`"spring": {"stiffness": 120, "damping": 8}` on a track makes the value chase the keyed curve like a mass on a spring, so it overshoots and settles after each change. Lower `damping` wobbles more; `2 * sqrt(stiffness * mass)` is critical damping. Pair it with `{"steps": 1}` or quick keys for a snappy pop that settles.

## Loops

`loop` is `loop` (default, restarts from 0), `once` (holds the last frame) or `ping_pong`. For a seamless loop, end every track where it starts; rotations may end a full turn later. The validator flags loop seams.

## Clips

`clips` are named timelines that [state machines](/docs/features/state-machines) play. They have the same shape as `timeline`.

## Beat Sync

Give `timeline.beats` a beat grid and tracks can follow the music. The grid is a tempo (`bpm`, with `offset` in seconds to the first beat), or exact `times` in seconds from a beat tracker. `per_bar` says how many beats make a bar (default 4).

- `"in_beats": true` on a track makes each keyframe `t` a beat number instead of seconds: `t: 8` is two bars in at 4/4.
- `pulse` on a track replaces its keyframes with a kick on the beat: the value rises from `from` to `to` over `attack` seconds (default 0.03), then falls back over `decay` (default 0.3). `every: 4` pulses once a bar, and `start` is the first beat that pulses.

```json
"timeline": {
  "duration": 8,
  "beats": { "bpm": 120, "offset": 0.25 },
  "tracks": {
    "kick": { "target": "logo", "property": "scale",
      "pulse": { "from": [1, 1, 1], "to": [1.15, 1.15, 1.15], "every": 1 } },
    "drop": { "target": "title", "property": "opacity", "in_beats": true,
      "keyframes": [{ "t": 0, "value": 0 }, { "t": 4, "value": 1 }] }
  }
}
```

Clips use the main timeline's grid. Beats resolve to plain keyframes when the scene loads, so playback and exports see ordinary tracks. A beat-timed track with no usable grid is a `missing_beats` error.

## Audio

`audio` (at the top of the scene) places sounds on the timeline. Each clip has a `src`: a WAV file relative to the scene, or a generated sound, `silence`, `tone(440)` (a sine at that frequency) or `clicks` (a metronome on `timeline.beats`, accented on each bar). `start` is when it begins, `offset` skips into the source, and `duration` cuts it short (by default a WAV plays to its end and a generated sound to the end of the timeline). `volume` is a gain (1 is the source's level), and `fade_in` and `fade_out` are in seconds. With `"in_beats": true`, `start` and `duration` count beats of `timeline.beats`, so a sting can land on bar 3 at any tempo.

```json
"audio": [
  { "src": "music/bed.wav", "volume": 0.6, "fade_out": 1.5 },
  { "src": "sfx/whoosh.wav", "start": 8, "in_beats": true },
  { "src": "clicks", "volume": 0.3 }
]
```

MP4 exports mix the clips to 48 kHz stereo and mux them in as AAC with `ffmpeg` when it's on PATH. Without `ffmpeg` the mix is written beside the video as a WAV, and the CLI warns. The browser player plays WAV clips timed in seconds in step with playback, once the page has had a user gesture. Generated sounds are export-only. Audio needs authoring builds, and a clip that's neither a `.wav` path nor a known generated sound is an `invalid_audio` error.

## Wiggle

`wiggle` adds seeded noise on top of a track's keys: a hand-held drift, a nervous shake, a flickering torch. `amount` is the largest offset (a number or `[x, y, z]`), `frequency` how many wobbles a second, and `fps` how many new values a second. `hold: true` jumps between values instead of gliding (12 fps on twos reads as hand-drawn boil; fast and held is flicker). `from` and `to` limit it to a window. A track with no keys wiggles around its rest value (0, or 1 for `scale` and `opacity`).

```jsonc
"torch": {"target": "flame", "property": "opacity",
  "wiggle": {"amount": 0.25, "frequency": 9, "fps": 12, "hold": true, "seed": 3}}
```

It is baked into plain keyframes when the scene is expanded, so it plays the same everywhere.

## API Reference

### Timeline

A timeline of keyframed property tracks.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `autoplay` | `boolean` | `true` | Start playing immediately (main timeline) / when the state is entered (clips). |
| `beats` | `Beats` | — | The music's beat grid, for tracks with `in_beats` or `pulse`. |
| `duration` | `number (≥ 0)` | `5` | Length in seconds. |
| `loop` | `LoopMode` | `"loop"` | What happens after `duration`. |
| `tracks` | `map of Track` | `{}` | Tracks keyed by id (patch-friendly: `/timeline/tracks/<id>`). |
### Track

Animates one property of one target over time.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `curve` | `Curve` | — | How the value travels between keys. `linear` (default) goes from key to key, each key's `easing` shaping the timing. `smooth` draws one flowing curve through every key with no corners or stops in between (it eases in at the first key and out at the last; when the first and last values match it loops seamlessly). Keys' easings are ignored. |
| `in_beats` | `boolean` | — | Keyframe `t` counts beats of `timeline.beats` instead of seconds. |
| `keyframes` | `Keyframe[]` | `[]` | Keyframes sorted by `t`. |
| `property` (required) | `Property` | — | The property to animate. |
| `pulse` | `Pulse` | — | Kick to a value on the beat and fall back, instead of keyframes. |
| `spring` | `Spring` | — | Follow-through: the value chases the keyed curve like a mass on a spring, so it overshoots and settles after each change. Lower `damping` for more wobble (critical damping is 2 * sqrt(stiffness * mass)). The spring starts at rest on the first key. |
| `target` (required) | `string` | — | Node id, or `"$camera"`. |
| `wiggle` | `Wiggle` | — | Procedural motion: seeded noise added to the keyed value (hand-held wobble, flicker, boil). Baked into keyframes on expansion. |
### Keyframe

A keyframe: a value at time `t` (seconds).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `easing` | `Easing` | `"ease_in_out_cubic"` | Curve used from this keyframe to the next one. |
| `t` (required) | `number (≥ 0)` | — | Time in seconds. |
| `value` (required) | `AnimValue` | — | The value at `t`: a number, `[x, y, z]` or a hex colour. |
### Beats

The beat grid music-synced tracks snap to: a steady tempo, or the beat times of a real track (e.g. from a beat tracker).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `bpm` | `number (1 to 400)` | — | Tempo in beats per minute (ignored when `times` is given). |
| `offset` | `number` | — | Seconds to the first beat (the downbeat), with `bpm`. |
| `per_bar` | `integer (1 to 16)` | — | Beats in a bar, so `every: 4` lands on each bar. |
| `times` | `number[]` | — | Exact beat times in seconds, ascending. Beats past the last one keep its spacing. |
### Pulse

A value that kicks to `to` on beats and falls back to `from`.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `attack` | `number (≥ 0)` | — | Seconds to rise into the beat (0 snaps on it). |
| `decay` | `number (≥ 0)` | — | Seconds to fall back to `from` after the beat. |
| `every` | `integer (≥ 1)` | — | Pulse on every this many beats (4 with `per_bar: 4` is once a bar). |
| `from` (required) | `AnimValue` | — | The resting value. |
| `start` | `number` | — | First beat that pulses. |
| `to` (required) | `AnimValue` | — | The value on the beat. |
### AudioClip

One sound placed on the timeline.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `duration` | `number (≥ 0)` | — | How long it plays, in seconds (beats with `in_beats`). Defaults to the rest of the source, or the rest of the timeline for generated sounds. |
| `fade_in` | `number (≥ 0)` | — | Seconds to fade up from silence. |
| `fade_out` | `number (≥ 0)` | — | Seconds to fade out at the end. |
| `in_beats` | `boolean` | — | `start` and `duration` count beats of `timeline.beats`. |
| `offset` | `number (≥ 0)` | — | Seconds into the source to begin playing from. |
| `src` (required) | `string` | — | A WAV file (relative to the scene file), or a generated sound: `silence`, `tone(440)` (a sine at that many Hz) or `clicks` (a metronome on `timeline.beats`, accented on each bar). |
| `start` | `number (≥ 0)` | — | When the clip starts, in seconds (beats with `in_beats`). |
| `volume` | `number (0 to 4)` | — | Gain, 1 is the source's own level. |
### Property

Animatable properties.

| Value | Description |
| --- | --- |
| `"position"` | `[x,y,z]` (nodes and camera). |
| `"rotation"` | `[x,y,z]` Euler degrees. |
| `"scale"` | `[x,y,z]`. |
| `"opacity"` | Number 0..1. |
| `"color"` | Hex color; overrides the node's material color. |
| `"emissive_intensity"` | Number. |
| `"look_at"` | `[x,y,z]` camera look-at point (camera only). |
| `"fov"` | Number, degrees (camera only). |
| `"morph"` | Number: blend a shape through its `morph` outlines (0 is the shape's own points, 1 the first morph, 1.5 halfway to the second, ...). Authoring builds. |
| `"trim_start"` | Number 0..1: where a shape's stroke starts, as a fraction of its length (overrides `trim[0]`). Authoring builds. |
| `"trim_end"` | Number 0..1: where a shape's stroke ends, as a fraction of its length (overrides `trim[1]`); animate 0 to 1 to draw a stroke on. Authoring builds. |
| `"bend"` | Number, degrees: curl a skinned limb. On a bone in a mesh's `skin.bones` (or an `svg` part with `joints`), every bone after it in the chain turns by an equal share, so the limb curves smoothly at its joints (positive bends counter-clockwise). Becomes rotation tracks on those bones when the scene expands. Authoring builds. |
| `"ik_mix"` | Number 0..1: how much a node's `ik` wins over its keyed pose (overrides `ik.mix`): 0 is keyed (FK) motion, 1 the full solve. Authoring builds. |
### AnimValue

A keyframe value: number, `[x,y,z]` or hex color.

Type: `number | [x, y, z] | Color`
### Curve

Interpolation between keyframes.

| Value | Description |
| --- | --- |
| `"linear"` |  |
| `"smooth"` |  |
### LoopMode

| Value | Description |
| --- | --- |
| `"once"` | Play once and hold the last frame. |
| `"loop"` | Restart from 0 (seamless loops for X/GIF). |
| `"ping_pong"` | Play forward then backward. |
### Wiggle

Noise added to a track's value.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `amount` (required) | `AnimValue` | — | Largest offset: a number (every component) or `[x, y, z]`. |
| `fps` | `number (1 to 120)` | `24` | New values per second (24 = every frame, 12 = on twos). |
| `frequency` | `number (0 to 60)` | `2` | Wobbles per second. |
| `from` | `number` | — | Wiggle only from this time (seconds). |
| `hold` | `boolean` | — | Hold each value until the next one (flicker, boil) instead of gliding between them. |
| `seed` | `integer` | `0` | Noise seed: tracks with different seeds wiggle differently. |
| `to` | `number` | — | Wiggle only until this time (seconds). |
