Prompt specification
Build or customize the Three.js 3D scene "Chrysalis-to-adult emergence sequence" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Chrysalis-to-adult emergence sequence
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/chrysalis-to-adult-emergence-sequence-x0662
Scene Description Prompt:
Show a stylized butterfly emerging from a stationary chrysalis and unfolding its wings gradually; preserve attachment positions and identify the animation as a condensed stage illustration. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (chrysalis-to-adult-emergence-sequence-x0662):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Metamorphosis</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5ff;
--muted: #a9bad0;
--panel: rgba(10, 18, 36, 0.78);
--line: rgba(174, 205, 255, 0.2);
--accent: #70e5ff;
--warm: #ff8b6a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #091321;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-block {
position: absolute;
top: 28px;
left: 30px;
max-width: min(460px, calc(100vw - 60px));
}
.eyebrow {
margin: 0 0 8px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 46px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid rgba(112, 229, 255, 0.42);
border-radius: 999px;
background: rgba(16, 34, 58, 0.66);
color: #c9f7ff;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
content: "";
}
.controls-note {
position: absolute;
top: 30px;
right: 30px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
.stage-card {
position: absolute;
bottom: 24px;
left: 50%;
width: min(680px, calc(100vw - 32px));
padding: 17px 18px 15px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(15px);
pointer-events: auto;
}
.stage-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
.stage-index {
margin-bottom: 5px;
color: var(--warm);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.stage-title {
margin: 0;
font-size: clamp(16px, 2vw, 22px);
letter-spacing: -0.025em;
}
.stage-note {
min-height: 18px;
margin: 6px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.4;
}
button {
flex: 0 0 auto;
padding: 9px 13px;
border: 1px solid rgba(112, 229, 255, 0.35);
border-radius: 9px;
background: rgba(112, 229, 255, 0.08);
color: #d9f9ff;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(112, 229, 255, 0.18);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.timeline {
position: relative;
height: 4px;
margin-top: 16px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.1);
}
.timeline-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--warm), #ffcf70, var(--accent));
box-shadow: 0 0 15px rgba(112, 229, 255, 0.4);
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: #71859e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.caption {
margin-top: 11px;
color: #8195ae;
font-size: 10px;
letter-spacing: 0.05em;
text-align: center;
}
@media (max-width: 620px) {
.title-block {
top: 20px;
left: 20px;
}
.controls-note {
display: none;
}
.stage-card {
bottom: 14px;
padding: 14px;
}
.stage-note {
font-size: 11px;
}
.timeline-labels span:nth-child(even) {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<header class="title-block">
<p class="eyebrow">A miniature life cycle</p>
<h1>Voxel<br />Metamorphosis</h1>
<div class="badge">Condensed stage illustration</div>
</header>
<div class="controls-note">
Drag to orbit<br />
Scroll to zoom
</div>
<section class="stage-card" aria-live="polite">
<div class="stage-row">
<div>
<div class="stage-index" id="stageIndex">Stage 01 / 05</div>
<h2 class="stage-title" id="stageTitle">Dormant chrysalis</h2>
<p class="stage-note" id="stageNote">
The chrysalis remains fixed to its anchor.
</p>
</div>
<button id="replay" type="button">Replay</button>
</div>
<div class="timeline" aria-hidden="true">
<div class="timeline-fill" id="timelineFill"></div>
</div>
<div class="timeline-labels" aria-hidden="true">
<span>Dormant</span>
<span>Emergence</span>
<span>Unfolding</span>
<span>Display</span>
</div>
<div class="caption">
Time compressed for clarity · Wings rotate around fixed thorax pivots
</div>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091321);
scene.fog = new THREE.FogExp2(0x091321, 0.045);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance",
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Voxel butterfly emerging from a chrysalis and unfolding its wings"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb8ddff, 0x182038, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d8, 4.2);
keyLight.position.set(4, 7, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x54dfff, 20, 12, 2);
cyanLight.position.set(-3.5, 2.6, 4);
scene.add(cyanLight);
const coralLight = new THREE.PointLight(0xff705d, 16, 10, 2);
coralLight.position.set(3.5, 0.4, 3);
scene.add(coralLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addVoxel(
parent,
position,
size,
color,
rotation = new THREE.Euler()
) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02,
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(...position);
mesh.scale.set(...size);
mesh.rotation.copy(rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createInstancedVoxels(cells, blockSize, options = {}) {
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0.02,
});
const mesh = new THREE.InstancedMesh(
unitBox,
material,
cells.length
);
const dummy = new THREE.Object3D();
cells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
if (cell.scale) {
dummy.scale.set(...cell.scale);
} else {
dummy.scale.setScalar(blockSize);
}
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(cell.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
return mesh;
}
// ------------------------------------------------------------
// Diorama base, branch, and atmospheric cubes
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x0c1728,
roughness: 1,
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.92;
ground.receiveShadow = true;
scene.add(ground);
const branch = new THREE.Group();
scene.add(branch);
const barkColors = [0x563d39, 0x694a43, 0x3e2c31];
for (let x = -6; x <= 6; x++) {
addVoxel(
branch,
[x * 0.22, 3.28 + Math.sin(x * 0.7) * 0.035, -0.2],
[0.225, 0.19, 0.2],
barkColors[Math.abs(x) % barkColors.length]
);
}
for (let y = 0; y < 8; y++) {
addVoxel(
branch,
[
-0.62 + Math.sin(y * 0.55) * 0.06,
-0.73 + y * 0.5,
-0.25
],
[0.29, 0.5, 0.28],
barkColors[y % barkColors.length]
);
}
// Small block-built leaves around the twig.
const leafGroups = [
[-1.02, 3.38, -0.16, -0.45],
[1.03, 3.4, -0.14, 0.45],
[-1.2, 3.5, -0.13, -0.7],
[1.19, 3.52, -0.12, 0.72],
];
leafGroups.forEach(([x, y, z, angle], index) => {
const leaf = new THREE.Group();
leaf.position.set(x, y, z);
leaf.rotation.z = angle;
branch.add(leaf);
for (let i = 0; i < 4; i++) {
addVoxel(
leaf,
[i * 0.13, Math.sin(i * 0.8) * 0.045, 0],
[0.145, 0.09, 0.13],
index % 2 === 0 ? 0x2d8062 : 0x3ca777
);
}
});
// Small voxel plants near the bottom.
for (const [x, z, height] of [
[-2.0, -0.3, 0.35],
[-1.75, -0.45, 0.25],
[2.05, -0.45, 0.3],
[1.8, -0.3, 0.22],
]) {
for (let i = 0; i < height * 10; i++) {
addVoxel(
scene,
[
x + Math.sin(i * 0.9) * 0.06,
-0.82 + i * 0.1,
z
],
[0.11, 0.11, 0.11],
i % 2 === 0 ? 0x214f53 : 0x2d6c65
);
}
}
// Subtle background motes.
const motes = [];
const moteGeometry = new THREE.BoxGeometry(0.045, 0.045, 0.045);
const moteMaterial = new THREE.MeshBasicMaterial({
color: 0x7eeaff,
transparent: true,
opacity: 0.55,
});
for (let i = 0; i < 22; i++) {
const mote = new THREE.Mesh(moteGeometry, moteMaterial);
mote.position.set(
(Math.random() - 0.5) * 8,
Math.random() * 4.6 - 0.4,
-1.8 - Math.random() * 4
);
mote.userData.phase = Math.random() * Math.PI * 2;
mote.userData.speed = 0.15 + Math.random() * 0.3;
scene.add(mote);
motes.push(mote);
}
// ------------------------------------------------------------
// Stationary chrysalis
// The anchor and overall position never move. Only the two
// casing halves separate slightly around a fixed seam.
// ------------------------------------------------------------
const chrysalis = new THREE.Group();
chrysalis.position.set(0, 2.18, 0);
scene.add(chrysalis);
const shellLeft = new THREE.Group();
const shellRight = new THREE.Group();
chrysalis.add(shellLeft, shellRight);
const leftCells = [];
const rightCells = [];
const shellColors = [
0x4f8b68,
0x68a878,
0x85b985,
0xb3b46f,
0xd0bc69
];
for (let yi = 0; yi <= 9; yi++) {
const t = yi / 9;
const y = -0.02 + yi * 0.105;
const rx = 0.105 + Math.sin(Math.PI * t) * 0.14;
const rz = 0.085 + Math.sin(Math.PI * t) * 0.12;
for (let xi = -2; xi <= 2; xi++) {
if (xi === 0) continue;
for (let zi = -1; zi <= 1; zi++) {
const x = xi * 0.105;
const z = zi * 0.105;
if ((x * x) / (rx * rx) + (z * z) / (rz * rz) > 1) {
continue;
}
const color = shellColors[(yi + Math.abs(xi) + (zi + 1)) % shellColors.length];
const cell = { x, y, z, color };
if (xi < 0) leftCells.push(cell);
else rightCells.push(cell);
}
}
}
shellLeft.add(createInstancedVoxels(leftCells, 0.097));
shellRight.add(createInstancedVoxels(rightCells, 0.097));
// Silk attachment cubes between the branch and chrysalis.
for (let i = 0; i < 4; i++) {
addVoxel(
chrysalis,
[0, 1.06 + i * 0.045, 0],
[0.038, 0.05, 0.038],
0xe5dfc8
);
}
// ------------------------------------------------------------
// Butterfly
// ------------------------------------------------------------
const butterfly = new THREE.Group();
butterfly.position.set(0, 2.76, 0);
scene.add(butterfly);
const body = new THREE.Group();
butterfly.add(body);
const bodyDark = 0x211a3d;
const bodyBlue = 0x30285b;
const bodyWarm = 0xff8b55;
addVoxel(body, [0, 0.23, 0.015], [0.2, 0.2, 0.19], bodyWarm);
addVoxel(body, [0, 0.035, 0], [0.245, 0.25, 0.23], bodyBlue);
addVoxel(body, [0, -0.19, -0.005], [0.17, 0.2, 0.17], bodyDark);
addVoxel(body, [0, -0.35, -0.01], [0.145, 0.17, 0.15], bodyBlue);
addVoxel(body, [0, -0.48, -0.015], [0.105, 0.14, 0.12], bodyDark);
// Bright eyes.
addVoxel(body, [-0.072, 0.255, 0.125], [0.05, 0.06, 0.035], 0xeefaff);
addVoxel(body, [0.072, 0.255, 0.125], [0.05, 0.06, 0.035], 0xeefaff);
// Legs, built from small cubes.
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
addVoxel(
body,
[side * 0.13, 0.035 - i * 0.1, 0.04],
[0.035, 0.12, 0.035],
bodyDark,
new THREE.Euler(0, 0, side * (0.28 + i * 0.12))
);
}
}
const antennae = new THREE.Group();
body.add(antennae);
for (const side of [-1, 1]) {
for (let i = 0; i < 6; i++) {
addVoxel(
antennae,
[
side * (0.035 + i * 0.022),
0.37 + i * 0.048,
0.015
],
[0.026, 0.052, 0.026],
0x251b3e
);
}
}
// Voxel wing generation.
function makeUpperWingCells() {
const cells = [];
const palette = {
coral: 0xff6679,
pink: 0xff8c72,
orange: 0xffa25d,
violet: 0x29214f,
blue: 0x397ca0,
cream: 0xffe2b0,
cyan: 0x66d7dc
};
for (let ix = 0; ix <= 12; ix++) {
for (let iy = 0; iy <= 8; iy++) {
const x = 0.045 + ix * 0.095;
const y = iy * 0.095;
const u = x / 1.28;
const v = y / 0.86;
const ellipse =
((u - 0.39) / 0.64) ** 2 +
((v - 0.43) / 0.72) ** 2;
if (ellipse > 1 || y < -0.01) continue;
let color = (ix + iy) % 3 === 0 ? palette.pink : palette.coral;
// Dark outer border.
if (u > 0.78 || v > 0.79) {
color = palette.violet;
}
// Blue diagonal band.
if (ix + iy > 12 && ix + iy < 17) {
color = palette.blue;
}
// Cream and cyan markings.
const creamSpot = (ix - 9) ** 2 + (iy - 5) ** 2 < 4.5;
const cyanSpot = (ix - 5) ** 2 + (iy - 6) ** 2 < 3.5;
if (creamSpot) color = palette.cream;
if (cyanSpot) color = palette.cyan;
cells.push({ x, y, z: 0, color });
}
}
return cells;
}
function makeLowerWingCells() {
const cells = [];
const palette = {
coral: 0xff6679,
orange: 0xff9b59,
violet: 0x29214f,
blue: 0x397ca0,
cream: 0xffe2b0,
cyan: 0x66d7dc
};
for (let ix = 0; ix <= 10; ix++) {
for (let iy = 0; iy <= 7; iy++) {
const x = 0.04 + ix * 0.09;
const y = -iy * 0.09;
const u = x / 1.02;
const v = -y / 0.72;
const ellipse =
((u - 0.42) / 0.61) ** 2 +
((v - 0.48) / 0.57) ** 2;
if (ellipse > 1 || y > 0.01) continue;
let color = palette.coral;
if (v > 0.73 || u > 0.76) color = palette.violet;
if (ix > 5 && iy < 3) color = palette.orange;
if ((ix - 7) ** 2 + (iy - 3) ** 2 < 3.5) color = palette.cyan;
if ((ix - 4) ** 2 + (iy - 5) ** 2 < 2.8) color = palette.cream;
cells.push({ x, y, z: 0.005, color });
}
}
return cells;
}
const upperCells = makeUpperWingCells();
const lowerCells = makeLowerWingCells();
function createWingPivot(cells, mirrored, position) {
// The pivot is the permanent attachment point at the thorax.
// Geometry is local to it, so opening never separates the wing.
const pivot = new THREE.Group();
pivot.position.set(...position);
const mirroredCells = cells.map((cell) => ({
...cell,
x: mirrored ? -cell.x : cell.x,
}));
const wing = createInstancedVoxels(mirroredCells, 0.083);
wing.castShadow = true;
wing.receiveShadow = true;
pivot.add(wing);
butterfly.add(pivot);
return pivot;
}
const rightUpper = createWingPivot(upperCells, false, [0.12, 0.12, -0.04]);
const leftUpper = createWingPivot(upperCells, true, [-0.12, 0.12, -0.04]);
const rightLower = createWingPivot(lowerCells, false, [0.11, -0.17, -0.035]);
const leftLower = createWingPivot(lowerCells, true, [-0.11, -0.17, -0.035]);
// ------------------------------------------------------------
// Direct camera controls: orbit with drag and zoom with wheel
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.65, 0);
let cameraTheta = 0;
let cameraPhi = 1.34;
let cameraRadius = 7.1;
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + deltaY * 0.005,
0.86,
1.72
);
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.004,
4.8,
10.5
);
},
{ passive: false }
);
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
// ------------------------------------------------------------
// Condensed stage animation
// ------------------------------------------------------------
const duration = 8.4;
const replayButton = document.getElementById("replay");
const timelineFill = document.getElementById("timelineFill");
const stageIndex = document.getElementById("stageIndex");
const stageTitle = document.getElementById("stageTitle");
const stageNote = document.getElementById("stageNote");
let animationStart = performance.now();
let previousStage = "";
function clamp01(value) {
return Math.min(1, Math.max(0, value));
}
function smoothRange(value, start, end) {
const x = clamp01((value - start) / (end - start));
return x * x * (3 - 2 * x);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function setStage(index, title, note) {
const key = `${index}-${title}`;
if (key === previousStage) return;
previousStage = key;
stageIndex.textContent = `Stage ${index} / 05`;
stageTitle.textContent = title;
stageNote.textContent = note;
}
replayButton.addEventListener("click", () => {
animationStart = performance.now();
previousStage = "";
});
function animate(now) {
requestAnimationFrame(animate);
const elapsed = Math.min((now - animationStart) / 1000, duration);
// The chrysalis is anchored in place throughout the sequence.
const casingOpen = smoothRange(elapsed, 1.15, 2.15);
shellLeft.position.x = -0.025 - casingOpen * 0.105;
shellRight.position.x = 0.025 + casingOpen * 0.105;
// The butterfly body clears the casing.
const emergence = smoothRange(elapsed, 1.3, 3.15);
butterfly.position.y = lerp(2.76, 1.43, emergence);
// Compact wings expand around their original thorax pivots.
const wingScale = lerp(0.46, 1, emergence);
rightUpper.scale.setScalar(wingScale);
leftUpper.scale.setScalar(wingScale);
rightLower.scale.setScalar(wingScale);
leftLower.scale.setScalar(wingScale);
butterfly.visible = elapsed > 1.12;
// Lower wings unfold first, then the larger upper wings.
const lowerOpen = smoothRange(elapsed, 2.55, 4.15);
const upperOpen = smoothRange(elapsed, 3.25, 5.35);
rightLower.rotation.z = lerp(1.34, -0.08, lowerOpen);
leftLower.rotation.z = lerp(-1.34, 0.08, lowerOpen);
rightUpper.rotation.z = lerp(-1.43, 0.1, upperOpen);
leftUpper.rotation.z = lerp(1.43, -0.1, upperOpen);
// Antennae become visible as the butterfly settles.
const antennaReveal = smoothRange(elapsed, 3.55, 5.35);
antennae.scale.setScalar(lerp(0.08, 1, antennaReveal));
antennae.position.y = lerp(0.08, 0, antennaReveal);
// A restrained final pose adds life without moving any hinge.
const display = smoothRange(elapsed, 5.25, 6.4);
const flutter = Math.sin((elapsed - 5.25) * 2.2);
rightUpper.rotation.y = flutter * 0.08 * display;
leftUpper.rotation.y = -flutter * 0.08 * display;
rightUpper.rotation.z += flutter * 0.035 * display;
leftUpper.rotation.z -= flutter * 0.035 * display;
rightLower.rotation.y = -flutter * 0.045 * display;
leftLower.rotation.y = flutter * 0.045 * display;
butterfly.position.y += Math.sin((elapsed - 5.25) * 2) * 0.018 * display;
// Atmospheric cubes drift independently.
motes.forEach((mote) => {
const phase = mote.userData.phase;
const speed = mote.userData.speed;
mote.position.y += Math.sin(now * 0.00045 * speed + phase) * 0.00035;
mote.rotation.x += 0.002 * speed;
mote.rotation.y += 0.003 * speed;
});
if (elapsed < 1.15) {
setStage(
1,
"Dormant chrysalis",
"The chrysalis remains fixed to its anchor."
);
} else if (elapsed < 2.55) {
setStage(
2,
"Emergence",
"The body clears the split casing while all wing hinges remain attached."
);
} else if (elapsed < 3.55) {
setStage(
3,
"Lower wings unfold",
"The smaller wings rotate around their original thorax pivots."
);
} else if (elapsed < 5.35) {
setStage(
4,
"Upper wings unfold",
"The larger wings open from the same fixed attachment positions."
);
} else {
setStage(
5,
"Full display",
"The butterfly holds its open-wing pose in the finished stage illustration."
);
}
timelineFill.style.width = `${(elapsed / duration) * 100}%`;
updateCamera();
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
});
requestAnimationFrame(animate);
</script>
</body>
</html>
```