# Instancing

Draw any number of copies of a mesh in a single draw call.

Many copies of one mesh should be one node with `mesh.instances`, not many nodes. It's one draw call however many copies there are.

```json title="apps/docs/examples/instancing.json"
{
  "camera": { "position": [0, 7, 12], "target": [0, 0, 0], "fov": 40 },
  "lighting": { "rig": "golden_hour" },
  "environment": {
    "background": {
      "radial_gradient": { "inner": "#1b2233", "outer": "#07090f" }
    }
  },
  "nodes": {
    "cubes": {
      "mesh": {
        "geometry": {
          "rounded_box": { "size": [0.8, 0.8, 0.8], "radius": 0.12 }
        },
        "material": "preset:ceramic",
        "instances": {
          "grid": { "count": [12, 1, 8], "spacing": [1.1, 1, 1.1] }
        }
      }
    },
    "ring": {
      "transform": { "position": [0, 1.5, 0] },
      "mesh": {
        "geometry": { "sphere": { "radius": 0.25 } },
        "material": "preset:chrome",
        "instances": { "ring": { "count": 24, "radius": 5 } }
      }
    }
  }
}
```

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

## Layouts

- `list`: explicit positions, rotations and scales.
- `grid`: `count` copies along x, y and z, `spacing` apart.
- `array`: a row of copies. Copy `k` sits at `start + k * step` and turns `k * rotate`. Lane dashes, fence posts, windows.
- `ring`: copies on a circle, optionally facing the centre.
- `scatter`: seeded random copies in a radius.
- `path`: copies riding a path, like traffic and crowds. See [Paths](/docs/features/paths#crowds-and-traffic).
- `on_terrain`: copies scattered on a terrain. See [Scatter](/docs/features/scatter).

Every copy shares the node's material. Per-copy `colors` are available on the `path` and `on_terrain` layouts.

## API Reference

### Instances

Copies of a mesh, drawn with a single instanced draw call.

- `{"list": Instance[]}`: Explicit per-instance transforms (relative to the node).

- `{"grid": { … }}`: Regular 3D grid centered on the node.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `count` (required) | `integer[]` | — | Copies along x, y, z. |
| `spacing` | `[x, y, z]` | `[1,1,1]` | Distance between copies along x, y, z. |

- `{"array": { … }}`: A straight row of copies: copy `k` sits at `start + k * step` and is rotated by `k * rotate` (degrees). Lane dashes, fence posts, windows.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `count` (required) | `integer` | — | Number of copies. |
| `rotate` | `[x, y, z]` | `[0,0,0]` | Rotation added per copy, in degrees: copy `k` turns `k * rotate`. |
| `start` | `[x, y, z]` | `[0,0,0]` | Position of the first copy. |
| `step` | `[x, y, z]` | `[1,0,0]` | Offset between consecutive copies. |

- `{"path": PathInstances}`: Copies riding a path (crowds, traffic); placed every frame.

- `{"ring": { … }}`: Copies evenly spaced on a circle in the XZ plane.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `count` (required) | `integer` | — | Number of copies. |
| `face_center` | `boolean` | `true` | Rotate each copy to face the center. |
| `radius` | `number` | `2` | Circle radius. |

- `{"on_terrain": TerrainScatter}`: Seeded placement on a `terrain` mesh node: rocks, pebbles, brush. Make this node a child of the terrain node (or give it the same transform) so copies sit on the ground.

- `{"scatter": { … }}`: Seeded random placement inside a sphere.

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `count` (required) | `integer` | — | Number of copies. |
| `radius` | `number` | `2` | Radius of the area copies are scattered in. |
| `random_rotation` | `boolean` | `true` | Random rotation per copy. |
| `scale_jitter` | `number` | `0` | Random scale variation 0..1. |
| `seed` | `integer` | — | Overrides the scene seed. |
### Instance

One instance's transform (and optional tint).

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| `color` | `Color` | — | Per-instance color multiplier. |
| `position` | `[x, y, z]` | `[0,0,0]` | Offset from the node. |
| `rotation` | `[x, y, z]` | `[0,0,0]` | Euler degrees. |
| `scale` | `[x, y, z]` | `[1,1,1]` | Scale of this copy. |
