explode
An exploded view of a model: its parts move apart as the section scrolls.
Live preview needs WebGPU or WebGL 2. 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.
This example failed to draw.
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. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add explode<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" width="900" height="600" /></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.camera', 'model')import { start } from '@dioramajs/diorama'import model from '@dioramajs/model/model'
const app = start()app.attach('.camera', model())Page transitions
Nothing of its own: the model leaves by dithering, with its parts where they are. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
moderebuildsdata-dio-mode | 'radial' | 'axis' | 'extras' | 'radial' |
|
byrebuildsdata-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. |
piecesrebuildsdata-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). |
axisrebuildsdata-dio-axis | [number, number, number]-1 to 1 | [0, 1, 0] | Direction of the axis mode, in model coordinates: x y z. |
spreaddata-dio-spread | number0 to 3 | 1 | How far the parts move: 1 as the mode lays them out, 0 keeps them in place. |
startdata-dio-start | number0 to 1 | 0 | Progress at which the parts start to move. |
enddata-dio-end | number0 to 1 | 1 | Progress at which they are fully apart. |
positiondata-dio-position | number0 to 1 | 0 | How far apart with by="manual": 0 assembled, 1 exploded. |
cascadedata-dio-cascade | number0 to 0.9 | 0.3 | Share of the run by which the parts start one after another, outer ones first. |
twistdata-dio-twist | number-360 to 360° | 0 | Turns around the vertical while it opens; 0 does not turn. |
easedata-dio-ease | number0 to 1 s | 0.15 | Time the parts take to catch up with the scroll; 0 follows it exactly. |
containdata-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. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
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. How a frame is decided.
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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { explode: { reducedMotion: 'off' } } })Cost and quality
- Download
- 2.4 KB min+gzip 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.
- Frames
- Idle at rest
It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.
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.
<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" /> </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.
<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" /></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.
<div data-dio="model explode" data-dio-src="/models/headphones.glb" data-dio-pieces="Left cup, Right cup, Headband"> <img src="/models/headphones.png" /></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.
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 on a parent of the model element: a label on a node follows its part as it moves.