# Paths and Signals

Curves for nodes to follow, traffic that queues at lights, crowds, and cycling signals.

`paths` holds curves. Nodes `follow` them, and path instances ride them. `signals` are cycling states, like traffic lights, that stop followers and show or hide nodes.

```json title="apps/docs/examples/paths.json"
{
  "camera": { "position": [0, 22, 20], "target": [0, 0, 0], "fov": 40 },
  "lighting": { "rig": "golden_hour" },
  "environment": { "background": { "solid": "#20262e" } },
  "materials": {
    "road": { "color": "#2b2f36" },
    "car": { "preset": "glossy_plastic" },
    "red": { "preset": "neon", "color": "#ff2a2a" },
    "green": { "preset": "neon", "color": "#2aff6a" }
  },
  "paths": {
    "loop": {
      "polyline": {
        "points": [[-10, 0, -6], [10, 0, -6], [10, 0, 6], [-10, 0, 6]],
        "closed": true,
        "corner_radius": 3
      }
    },
    "walk": {
      "bezier": { "points": [[-12, 0, 9], [-4, 0, 12], [4, 0, 6], [12, 0, 9]] }
    }
  },
  "signals": {
    "light": {
      "phases": [
        { "state": "go", "duration": 3 },
        { "state": "caution", "duration": 1 },
        { "state": "stop", "duration": 3 }
      ]
    }
  },
  "nodes": {
    "road": {
      "mesh": {
        "geometry": { "plane": { "size": [30, 24] } },
        "material": "road"
      },
      "transform": { "rotation": [-90, 0, 0] }
    },
    "cars": {
      "transform": { "position": [0, 0.4, 0] },
      "mesh": {
        "geometry": { "box": { "size": [1.6, 0.8, 3] } },
        "material": "car",
        "instances": {
          "path": {
            "path": "loop",
            "count": 6,
            "speed": 6,
            "stops": [{ "at": 10, "signal": "light" }],
            "colors": ["#f2c230", "#d23a33", "#3d85c6"]
          }
        }
      }
    },
    "walkers": {
      "transform": { "position": [0, 0.5, 0] },
      "mesh": {
        "geometry": { "capsule": { "radius": 0.2, "length": 0.6 } },
        "material": "preset:matte_clay",
        "instances": {
          "path": { "path": "walk", "count": 10, "speed": 1.4, "spread": 0.8 }
        }
      }
    },
    "red": {
      "transform": { "position": [10, 2, -8] },
      "mesh": {
        "geometry": { "sphere": { "radius": 0.35 } },
        "material": "red"
      },
      "show_when": { "signal": "light", "states": ["stop", "caution"] }
    },
    "green": {
      "transform": { "position": [10, 1.2, -8] },
      "mesh": {
        "geometry": { "sphere": { "radius": 0.35 } },
        "material": "green"
      },
      "show_when": { "signal": "light", "states": ["go"] }
    }
  },
  "timeline": { "duration": 7, "loop": "loop" }
}
```

![Render of paths](/renders/paths.jpg)

## Paths

- `polyline`: `points`, `closed`, and `corner_radius` to round each corner.
- `bezier`: `[p0, c0, c1, p1, ...]` control points.

## Follow

`follow` on a node moves it along a path.

- `speed` in units per second, or `duration` with an `easing`.
- `offset` or `phase` to start part-way along. `start` waits before moving.
- `lateral` shifts sideways, for lanes (+ is right).
- `orient` faces along the path. Nodes face -z.
- `end`: `wrap` around a closed path, or `hold` at the end.
- `stops`, `brake` and `gap`: stop lines that wait for a signal, how long braking takes, and queue spacing. Followers on the same path queue behind each other at red lights.

## Crowds and Traffic

`"instances": {"path": {...}}` puts `count` copies on one path in a single draw call, with `speed`, `speed_jitter`, `spread`, `lateral`, per-copy `colors` and the same `stops`.

## Signals

A signal cycles through `go`, `caution` and `stop` phases, each with a `duration`, starting `offset` seconds in. `show_when: {"signal": "light", "states": ["stop"]}` shows a node only in those states, like a red lamp.

## API Reference

### Path

A path shape. Written as `{"polyline": {...}}` or `{"bezier": {...}}`.

- `{"polyline": { … }}`: Straight segments through `points`; `corner_radius` rounds corners so followers turn smoothly.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `closed` | `boolean` | `false` | Join the last point back to the first. |
| `corner_radius` | `number` | `0` | Round each corner with an arc of this radius. |
| `points` (required) | `[x, y, z][]` | — | The points, `[x, y, z]` each. |

- `{"bezier": { … }}`: Cubic Bézier chain: `[p0, c0, c1, p1, c2, c3, p2, ...]` (3k+1 points; 3k when `closed`, the last segment returning to `p0`).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `closed` | `boolean` | `false` | Join the last point back to the first. |
| `points` (required) | `[x, y, z][]` | — | Control points, `[x, y, z]` each. |
### Follow

Ride a path. The node sits at the path point, shifted `lateral` to the right of travel, plus its own position; with `orient` it turns to face along the path (models face -Z, like the camera).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `brake` | `number` | `1` | Seconds to brake to a stop and to pull away again. |
| `duration` | `number` | — | Travel the whole path in this many seconds with `easing`, instead of at a speed (stops are ignored then). |
| `easing` | `Easing` | `"linear"` | Timing curve for travel in duration mode. |
| `end` | `PathEnd` | `"wrap"` | What happens at the end of the path: stop, loop or ping-pong. |
| `gap` | `number` | `6` | Queue spacing behind followers already waiting at the same stop. |
| `lateral` | `number` | `0` | Sideways shift, positive = right of the travel direction (lanes). |
| `offset` | `number` | `0` | Starting distance along the path. |
| `orient` | `boolean` | `true` | Face along the path. |
| `path` (required) | `string` | — | Id of an entry in `paths`. |
| `phase` | `number` | `0` | Starting point as a fraction of the path length (added to `offset`). |
| `speed` | `number` | `1` | World units per second (ignored when `duration` is set). |
| `start` | `number` | `0` | Seconds before moving (the follower waits at its start point). |
| `stops` | `Stop[]` | — | Stop lines (speed mode only). |
### PathEnd

What a follower does at the end of an open path.

| Value | Description |
| --- | --- |
| `"wrap"` | Start over from the beginning (closed paths always wrap). |
| `"hold"` | Stay at the end. |
### Stop

A stop line on a path, honored while its signal is not `go`.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `at` (required) | `number` | — | Distance along the path (world units). |
| `signal` (required) | `string` | — | Id of an entry in `signals`. |
### PathInstances

Copies spread along a path, each riding it (crowds, traffic). Copy `k` starts `k * spacing` behind the first (default: evenly around the path).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `brake` | `number` | `1` | Seconds to brake to a stop and to pull away again. |
| `colors` | `Color[]` | — | Per-copy colors, cycled. |
| `count` (required) | `integer` | — | Number of copies. |
| `gap` | `number` | `6` | Queue spacing behind copies already waiting at the same stop. |
| `lateral` | `number` | `0` | Sideways shift of every copy. |
| `offset` | `number` | `0` | Starting distance along the path of the first copy. |
| `orient` | `boolean` | `true` | Face along the path. |
| `path` (required) | `string` | — | Id of the path in `paths`. |
| `spacing` | `number` | — | Distance between consecutive copies (default: path length / count). |
| `speed` | `number` | `1` | Speed in units per second. |
| `speed_jitter` | `number` | `0` | Random speed variation as a fraction (0.2 = +-20%), seeded per copy. |
| `spread` | `number` | `0` | Random sideways spread (+-), seeded per copy. |
| `stops` | `Stop[]` | — | Stop lines where copies wait for a signal. |
### Signal

A cycling signal such as a traffic light. Followers stop for it at `follow.stops`; nodes can show or hide with it (`show_when`).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `offset` | `number` | `0` | Seconds into the cycle at t = 0 (use to offset crossing directions). |
| `phases` (required) | `SignalPhase[]` | — | The cycle, repeated forever. |
### SignalPhase

One step of a signal cycle.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `duration` (required) | `number` | — | Seconds. |
| `state` (required) | `SignalState` | — | The signal's state during this step. |
### SignalState

What a signal currently shows.

| Value | Description |
| --- | --- |
| `"go"` | Followers pass. |
| `"caution"` | Followers that have not started braking stop (amber). |
| `"stop"` | Followers stop at the line. |
### ShowWhen

Show a node only while a signal is in one of `states` (traffic light lamps).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `signal` (required) | `string` | — | Id of the signal in `signals`. |
| `states` (required) | `SignalState[]` | — | Signal states in which the node is visible. |
