# explode

An exploded view of a model: its parts move apart as the section scrolls.

Works on the `model` of the same element. As the visitor scrolls through a sticky section, the parts of the product move apart one after another, the outer ones first, and come back together on the way up, so a page can show what is inside headphones, a watch, a speaker or a chair. The model shrinks a little as it opens so the exploded view stays in its box, and can turn as it opens. Drag, swatches and the rest pose of `model` keep working.

Module `model`, category 3D and product. Import `@dioramajs/model/explode`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/model/src/explode.ts)

A rangefinder camera that comes apart as you scroll: the lens fans out forward, the dials lift off the top and the eyepiece comes off the back.

```html title="index.html"
<div class="camera" data-dio="model explode" data-dio-src="/media/camera/camera.glb" data-dio-mode="extras" data-dio-yaw="-28" data-dio-pitch="12" data-dio-scale="0.8" data-dio-spread="0.75" data-dio-twist="-32.4" data-dio-cascade="0.25" role="img" aria-label="A rangefinder camera that comes apart as you scroll: the lens slides off forward with its rings and glass elements fanned out, the dials lift off the top plate, and the eyepiece and the film reminder come off the back." style="touch-action: pan-y">
  <img src="/media/camera/camera.webp" alt="" width="900" height="600" />
</div>
```

## Usage

Put it on: an element with the `model` effect: `data-dio="model explode"`, inside a tall `data-dio-section` with a sticky stage.

`start()` registers `explode`, so the attribute alone puts it on an element.

```html
<section data-dio-section="" style="height: 300vh"><div style="position: sticky; top: 0; height: 100vh"><div class="viewer" data-dio="model explode" data-dio-src="/models/speaker.glb" data-dio-mode="axis"><img src="/models/speaker.avif" alt="Speaker" /></div></div></section>
```

In page transitions: Nothing of its own: the model leaves by dithering, with its parts where they are.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `mode` (rebuilds) | `data-dio-mode` | `'radial' \| 'axis' \| 'extras'` | `'radial'` | radial moves each part away from the center by its own distance; axis stacks the parts in even levels along `axis`, like a watch or a speaker taken apart; extras takes the offsets the modeler wrote as glTF node extras `"explode": [x, y, z]`, in model units. |
| `by` (rebuilds) | `data-dio-by` | `'pin' \| 'progress' \| 'manual'` | `'pin'` | What drives it: pin of the sticky section, viewport progress, or `position` alone for a button or a tween. |
| `pieces` (rebuilds) | `data-dio-pieces` | `string` | `''` | Node names of the parts to move, comma separated; empty takes the children of the model root (or every node with extras in extras mode). |
| `axis` (rebuilds) | `data-dio-axis` | `[number, number, number]` -1 to 1 | `[0, 1, 0]` | Direction of the axis mode, in model coordinates: x y z. |
| `spread` | `data-dio-spread` | `number` 0 to 3 | `1` | How far the parts move: 1 as the mode lays them out, 0 keeps them in place. |
| `start` | `data-dio-start` | `number` 0 to 1 | `0` | Progress at which the parts start to move. |
| `end` | `data-dio-end` | `number` 0 to 1 | `1` | Progress at which they are fully apart. |
| `position` | `data-dio-position` | `number` 0 to 1 | `0` | How far apart with `by="manual"`: 0 assembled, 1 exploded. |
| `cascade` | `data-dio-cascade` | `number` 0 to 0.9 | `0.3` | Share of the run by which the parts start one after another, outer ones first. |
| `twist` | `data-dio-twist` | `number` -360 to 360° | `0` | Turns around the vertical while it opens; 0 does not turn. |
| `ease` | `data-dio-ease` | `number` 0 to 1 s | `0.15` | Time the parts take to catch up with the scroll; 0 follows it exactly. |
| `contain` | `data-dio-contain` | `boolean` | `true` | Keeps every part inside the box at every step: the model shrinks and recenters as it opens, measured in its rest pose and in perspective. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `mode`: `radial`, `axis`, `extras`
  - `radial` moves each part away from the center by its own distance.
  - `axis` stacks the parts in even levels along `axis`, like a watch or a speaker taken apart.
  - `extras` takes the offsets the modeler wrote as glTF node extras `"explode": [x, y, z]`, in model units.
- `by`: `pin`, `progress`, `manual`

## Inputs and frames

Draws only while something on it moves, then stops. Only on scroll, and while the parts catch up with it for `ease` seconds; none at rest. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. The exploded view stands still, parts apart and without the turn, wherever the page is scrolled. With `by="manual"` the parts jump to `position` without easing.

Runs on every device. Scroll drives it, so touch works as on desktop.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { explode: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 2.4 KB the first time a page uses it. GPU: None of its own: the model draws as it does without it. Memory: A few vectors per part.

See [the quality plugin](/docs/effects/quality).

## Recipes

### Offsets from the model file

The most exact exploded view is the one the modeler lays out. Give each part node an `explode` entry in its glTF extras, an offset in the units of the file, and use `mode="extras"`. In Blender, a custom property named `explode` on the object with the value `[0, 0.17, 0]` exports as exactly that when “Include > Custom Properties” is on. Parts inside another part with extras move with it, then by their own offset.

```html
<section data-dio-section style="height: 300vh">
  <div style="position: sticky; top: 0; height: 100vh">
    <div class="viewer" data-dio="model explode" data-dio-src="/models/speaker.glb" data-dio-mode="extras"><img src="/models/speaker.png" alt="Desk speaker" /></div>
  </div>
</section>
```

### A stack along one axis

Watches, speakers, phones and burgers come apart in layers. `mode="axis"` sorts the parts by their position along `axis` and spreads the layers evenly over one model size, the middle one staying put. Parts at the same height share a layer.

```html
<div class="viewer" data-dio="model explode" data-dio-src="/models/watch.glb" data-dio-mode="axis" data-dio-axis="0 0 1" data-dio-twist="54"><img src="/models/watch.png" alt="Watch" /></div>
```

### Pick the parts

Without `pieces` the effect moves the children of the model root, below any chain of single wrapper nodes an exporter adds. Name nodes to move only some of them, or to go deeper in the hierarchy. A name that is not in the file logs the names it has in development.

```html
<div data-dio="model explode" data-dio-src="/models/headphones.glb" data-dio-pieces="Left cup, Right cup, Headband"><img src="/models/headphones.png" alt="Headphones" /></div>
```

### Open it with a button

`by="manual"` leaves the scroll alone and follows `position`, so a button, a tab or a GSAP timeline can take the product apart.

```ts
const speaker = app.effects.get(document.querySelector('.viewer'), 'explode')
toggle.addEventListener('click', () => {
  speaker.params.position = speaker.params.position ? 0 : 1
})
```

## Notes

`explode` works on the `model` of the same element, so the file, the poster, the rest pose, drag, swatches and colors are all `model`’s. It moves the nodes of that model and never loads anything of its own; take it off the element and the parts go back.

`radial` moves each part away from the center by its own distance. A one-piece shell whose center is the center of the model, like a sleeve around a speaker, stays where it is and hides what is inside: split it into halves in the file, or use `axis` or `extras` as this camera does.

`contain` keeps the exploded model inside its box at every step: it scales the model down as it opens, measured in the rest pose and in perspective, and keeps the center of its exploded bounds in the middle. Turn it off when the stage has room around the model and the parts may fly out over the page.

Under reduced motion the camera stands taken apart, still, wherever the page is scrolled: what is inside is the content, and scroll no longer moves it.

Label the parts with [hotspots](/docs/effects/hotspots) on a parent of the model element: a label on a node follows its part as it moves.

## Related

- [book](/docs/effects/book.md): A cover image made a 3D book that turns to show its spine and opens on hover.
- [box](/docs/effects/box.md): A product box built from pictures of its faces: turn it, tilt it, open its lid.
- [coin](/docs/effects/coin.md): A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.
- [device](/docs/effects/device.md): A screenshot or a video shown in a 3D phone, tablet, laptop or browser window.
- [hotspots](/docs/effects/hotspots.md): Feature callouts pinned to points of a model, real buttons that follow it as it turns.
- [label](/docs/effects/label.md): A flat label wrapped around a can, a bottle or a jar that turns to show all of it.
- [model](/docs/effects/model.md): A glTF model fitted into the element, lit, turnable and recolored from markup.
- [panorama](/docs/effects/panorama.md): A 360° photo in a box that turns by drag, keys and gyroscope, with hotspots.
- [How a layer follows scroll](/docs/concepts/scroll.md)
- [3D models](/docs/guides/models.md)
