Prompt specification
Build or customize the Three.js 3D scene "Correct nesting order 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: Correct nesting order sequence
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/correct-nesting-order-sequence-x0358
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing nesting dolls. Animate shells enclosing smaller figures from inside outward; a wrong-size attempt stops at the opening and highlights the dimensional mismatch before the sequence resumes. Low-poly.
Working Three.js Starter (correct-nesting-order-sequence-x0358):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Nesting Dolls</title>
<style>
:root {
color-scheme: dark;
--ink: #eef4ff;
--muted: #9aabc3;
--panel: rgba(12, 20, 35, 0.72);
--border: rgba(180, 204, 255, 0.16);
--accent: #ffc857;
--danger: #ff5b55;
--cyan: #58e0d1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0d1524;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
touch-action: none;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.title-block {
position: absolute;
top: clamp(18px, 3vw, 34px);
left: clamp(18px, 3vw, 38px);
max-width: 430px;
}
.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, 3.5vw, 48px);
font-weight: 800;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.mismatch-card {
position: absolute;
top: clamp(18px, 3vw, 34px);
right: clamp(18px, 3vw, 38px);
width: min(350px, calc(100vw - 36px));
padding: 15px 17px;
border: 1px solid rgba(255, 91, 85, 0.52);
border-left: 4px solid var(--danger);
border-radius: 12px;
background:
linear-gradient(135deg, rgba(78, 18, 28, 0.94), rgba(20, 25, 38, 0.92));
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
opacity: 0;
transform: translateY(-12px);
transition:
opacity 180ms ease,
transform 180ms ease;
}
.mismatch-card.show {
opacity: 1;
transform: translateY(0);
}
.mismatch-title {
display: flex;
align-items: center;
gap: 8px;
color: #ffaaa6;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.mismatch-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--danger);
box-shadow: 0 0 16px var(--danger);
animation: warning-pulse 700ms ease-in-out infinite alternate;
}
.mismatch-values {
margin-top: 9px;
font-variant-numeric: tabular-nums;
font-size: 17px;
font-weight: 750;
}
.mismatch-values strong {
color: var(--danger);
}
.mismatch-note {
margin-top: 5px;
color: #c3c9d4;
font-size: 12px;
line-height: 1.45;
}
@keyframes warning-pulse {
to {
opacity: 0.35;
transform: scale(0.75);
}
}
.bottom-panel {
position: absolute;
right: clamp(18px, 3vw, 38px);
bottom: clamp(18px, 3vw, 32px);
left: clamp(18px, 3vw, 38px);
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
}
.sequence {
width: min(510px, 100%);
padding: 14px 16px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 14px 38px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
}
.sequence-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
#step-label {
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#time-label {
flex: 0 0 auto;
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.track {
height: 4px;
margin-top: 11px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #ef6a5b, #ffc857, #58e0d1, #7566d8);
box-shadow: 0 0 12px rgba(255, 200, 87, 0.35);
}
.controls {
display: flex;
flex: 0 0 auto;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 40px;
padding: 0 14px;
border: 1px solid var(--border);
border-radius: 10px;
color: var(--ink);
background: rgba(15, 25, 42, 0.85);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(255, 200, 87, 0.55);
background: rgba(29, 42, 64, 0.92);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.interaction-hint {
position: absolute;
right: clamp(18px, 3vw, 38px);
bottom: 102px;
color: rgba(210, 223, 242, 0.58);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.subtitle {
display: none;
}
.mismatch-card {
top: auto;
right: 18px;
bottom: 154px;
}
.bottom-panel {
align-items: stretch;
flex-direction: column;
gap: 10px;
}
.controls {
justify-content: flex-end;
}
.interaction-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="title-block">
<p class="eyebrow">Low-poly assembly study</p>
<h1>Nested,<br>from within.</h1>
<p class="subtitle">
Faceted shells close from the smallest figure outward. One shell tests
the fit, catches a dimensional mismatch, and returns before assembly resumes.
</p>
</section>
<aside id="mismatch-card" class="mismatch-card" aria-live="polite">
<div class="mismatch-title">
<span class="mismatch-dot"></span>
Dimensional mismatch
</div>
<div class="mismatch-values">
Opening <strong>Ø 0.81</strong> / Required <strong>Ø 1.61</strong>
</div>
<div class="mismatch-note">
The opening cannot clear the lower body. The shell is rejected and the
correctly sized outer shell continues the sequence.
</div>
</aside>
<div class="interaction-hint">Drag to orbit · Scroll to zoom · Double-click to reset view</div>
<footer class="bottom-panel">
<section class="sequence">
<div class="sequence-row">
<span id="step-label">01 / Seed figure</span>
<span id="time-label">0.0 / 15.6 s</span>
</div>
<div class="track"><div id="progress"></div></div>
</section>
<div class="controls">
<button id="restart" type="button">Restart</button>
<button id="pause" type="button">Pause</button>
<button id="speed" type="button">1×</button>
</div>
</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d1524);
scene.fog = new THREE.Fog(0x0d1524, 18, 34);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.querySelector("#scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc8ddff, 0x263448, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe6c7, 4.2);
keyLight.position.set(6, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x779dff, 2.1);
rimLight.position.set(-7, 6, -6);
scene.add(rimLight);
const warmPoint = new THREE.PointLight(0xff9b62, 14, 15, 2);
warmPoint.position.set(-3, 3.5, 4);
scene.add(warmPoint);
// -------------------------------------------------------------------------
// Low-poly stage
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.CircleGeometry(27, 48),
new THREE.MeshStandardMaterial({
color: 0x101b2b,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(2.75, 2.95, 0.24, 12),
new THREE.MeshStandardMaterial({
color: 0x293750,
roughness: 0.78,
metalness: 0.08,
flatShading: true
})
);
pedestal.position.y = 0.10;
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const pedestalEdge = new THREE.Mesh(
new THREE.TorusGeometry(2.75, 0.035, 4, 12),
new THREE.MeshStandardMaterial({
color: 0xffc857,
emissive: 0x6f3d00,
emissiveIntensity: 0.35,
roughness: 0.55
})
);
pedestalEdge.rotation.x = Math.PI / 2;
pedestalEdge.position.y = 0.225;
scene.add(pedestalEdge);
// -------------------------------------------------------------------------
// Shared geometry and materials
// -------------------------------------------------------------------------
const shellProfile = [
new THREE.Vector2(0.52, 0.00),
new THREE.Vector2(0.72, 0.12),
new THREE.Vector2(0.92, 0.65),
new THREE.Vector2(0.90, 1.05),
new THREE.Vector2(0.70, 1.42),
new THREE.Vector2(0.40, 1.58),
new THREE.Vector2(0.34, 1.66)
];
const shellGeometry = new THREE.LatheGeometry(shellProfile, 12);
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x161821,
roughness: 0.75,
flatShading: true
});
const cheekMaterial = new THREE.MeshBasicMaterial({
color: 0xf08b91,
transparent: true,
opacity: 0.82,
side: THREE.DoubleSide
});
function addFace(parent, size = 1) {
const eyeGeometry = new THREE.IcosahedronGeometry(0.045, 0);
const cheekGeometry = new THREE.CircleGeometry(0.072, 8);
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(eyeGeometry, eyeMaterial);
eye.position.set(side * 0.13 * size, 0.025 * size, 0.365 * size);
eye.scale.z = 0.45;
eye.castShadow = true;
parent.add(eye);
const cheek = new THREE.Mesh(cheekGeometry, cheekMaterial);
cheek.position.set(side * 0.225 * size, -0.085 * size, 0.335 * size);
cheek.scale.set(1, 0.65, 1);
parent.add(cheek);
}
const mouth = new THREE.Mesh(
new THREE.TorusGeometry(0.072, 0.013, 3, 10, Math.PI),
eyeMaterial
);
mouth.position.set(0, -0.125 * size, 0.365 * size);
mouth.rotation.z = Math.PI;
parent.add(mouth);
}
function makeShell(color, accentColor, scale, park, parkYaw) {
const group = new THREE.Group();
group.scale.setScalar(scale);
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.03,
flatShading: true,
side: THREE.DoubleSide
});
const innerMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(color).lerp(new THREE.Color(0x241a2d), 0.36),
roughness: 0.9,
flatShading: true,
side: THREE.BackSide
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.62,
metalness: 0.02,
flatShading: true
});
const body = new THREE.Mesh(shellGeometry, bodyMaterial);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const inner = new THREE.Mesh(shellGeometry, innerMaterial);
inner.scale.set(0.93, 0.985, 0.93);
inner.receiveShadow = true;
group.add(inner);
const rimMaterial = new THREE.MeshStandardMaterial({
color: accentColor,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.52,
metalness: 0.05,
flatShading: true
});
const bottomRim = new THREE.Mesh(
new THREE.TorusGeometry(0.505, 0.048, 4, 12),
rimMaterial
);
bottomRim.rotation.x = Math.PI / 2;
bottomRim.position.y = 0.012;
bottomRim.castShadow = true;
group.add(bottomRim);
const scarf = new THREE.Mesh(
new THREE.TorusGeometry(0.365, 0.07, 4, 12),
accentMaterial
);
scarf.rotation.x = Math.PI / 2;
scarf.position.y = 1.67;
scarf.castShadow = true;
group.add(scarf);
const apron = new THREE.Mesh(
new THREE.CircleGeometry(0.27, 6),
accentMaterial
);
apron.scale.set(1, 1.45, 1);
apron.position.set(0, 0.73, 0.875);
group.add(apron);
const apronInset = new THREE.Mesh(
new THREE.CircleGeometry(0.105, 6),
new THREE.MeshStandardMaterial({
color: 0xf6e6c8,
roughness: 0.8,
flatShading: true
})
);
apronInset.scale.set(1, 1.25, 1);
apronInset.position.set(0, 0.73, 0.892);
group.add(apronInset);
const waistBand = new THREE.Mesh(
new THREE.TorusGeometry(0.895, 0.023, 4, 12),
accentMaterial
);
waistBand.rotation.x = Math.PI / 2;
waistBand.position.y = 0.48;
group.add(waistBand);
const headPivot = new THREE.Group();
headPivot.position.y = 1.9;
group.add(headPivot);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.4, 0),
bodyMaterial
);
head.castShadow = true;
head.receiveShadow = true;
headPivot.add(head);
addFace(headPivot, 1);
group.position.copy(park);
group.rotation.y = parkYaw;
scene.add(group);
return {
group,
headPivot,
bodyMaterial,
rimMaterial,
park: park.clone(),
parkYaw,
targetYaw: 0.34,
scale
};
}
function makeCoreFigure() {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xf2d6a0,
roughness: 0.76,
flatShading: true
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0xc94f45,
roughness: 0.7,
flatShading: true
});
const coreProfile = [
new THREE.Vector2(0.02, 0.00),
new THREE.Vector2(0.30, 0.08),
new THREE.Vector2(0.46, 0.48),
new THREE.Vector2(0.43, 0.92),
new THREE.Vector2(0.29, 1.30),
new THREE.Vector2(0.18, 1.46),
new THREE.Vector2(0.02, 1.50)
];
const body = new THREE.Mesh(
new THREE.LatheGeometry(coreProfile, 10),
bodyMaterial
);
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.36, 0),
bodyMaterial
);
head.position.y = 1.75;
head.castShadow = true;
group.add(head);
const scarf = new THREE.Mesh(
new THREE.TorusGeometry(0.21, 0.05, 4, 10),
accentMaterial
);
scarf.rotation.x = Math.PI / 2;
scarf.position.y = 1.43;
group.add(scarf);
const apron = new THREE.Mesh(
new THREE.CircleGeometry(0.19, 6),
accentMaterial
);
apron.scale.set(1, 1.4, 1);
apron.position.set(0, 0.64, 0.415);
group.add(apron);
addFace(group, 0.9);
group.children.at(-1).position.y = 1.75;
group.children.at(-2).position.y = 1.75;
group.children.at(-3).position.y = 1.75;
group.scale.setScalar(0.82);
scene.add(group);
return group;
}
const core = makeCoreFigure();
const smallShell = makeShell(
0xef6a5b,
0xffd166,
1.0,
new THREE.Vector3(-2.65, 0.24, 0.8),
-0.45
);
const mediumShell = makeShell(
0x2a9d8f,
0xf6bd60,
1.55,
new THREE.Vector3(0.15, 0.24, -3.55),
-0.18
);
const wrongShell = makeShell(
0xf4a261,
0xe76f51,
0.78,
new THREE.Vector3(2.55, 0.24, 0.75),
0.55
);
const largeShell = makeShell(
0x7566d8,
0xf2a7c8,
2.4,
new THREE.Vector3(-4.65, 0.24, -2.25),
-0.62
);
// -------------------------------------------------------------------------
// Dimension annotation for the failed fit
// -------------------------------------------------------------------------
const OPENING_RADIUS = 0.52 * wrongShell.scale;
const REQUIRED_RADIUS = 0.52 * mediumShell.scale;
function makeTextSprite(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(10, 17, 29, 0.92)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = color;
context.lineWidth = 5;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
context.fillStyle = color;
context.font = "800 43px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.55, 0.64, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeDimension(color, radius, y, z) {
const group = new THREE.Group();
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
});
const points = [
new THREE.Vector3(-radius, y, z),
new THREE.Vector3(radius, y, z)
];
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
material
);
line.renderOrder = 20;
group.add(line);
const coneGeometry = new THREE.ConeGeometry(0.085, 0.22, 4);
const coneMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
});
const right = new THREE.Mesh(coneGeometry, coneMaterial);
right.position.set(radius - 0.11, y, z);
right.rotation.z = -Math.PI / 2;
right.renderOrder = 20;
group.add(right);
const left = new THREE.Mesh(coneGeometry, coneMaterial);
left.position.set(-radius + 0.11, y, z);
left.rotation.z = Math.PI / 2;
left.renderOrder = 20;
group.add(left);
return group;
}
const guide = new THREE.Group();
guide.visible = false;
scene.add(guide);
const openingRing = new THREE.Mesh(
new THREE.TorusGeometry(OPENING_RADIUS, 0.026, 4, 24),
new THREE.MeshBasicMaterial({
color: 0xff5148,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
openingRing.rotation.x = Math.PI / 2;
openingRing.renderOrder = 20;
guide.add(openingRing);
const requiredRing = new THREE.Mesh(
new THREE.TorusGeometry(REQUIRED_RADIUS, 0.022, 4, 32),
new THREE.MeshBasicMaterial({
color: 0x58e0d1,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
requiredRing.rotation.x = Math.PI / 2;
requiredRing.renderOrder = 20;
guide.add(requiredRing);
const openingDimension = makeDimension(
0xff5148,
OPENING_RADIUS,
0.76,
1.05
);
guide.add(openingDimension);
const requiredDimension = makeDimension(
0x58e0d1,
REQUIRED_RADIUS,
0.29,
1.05
);
guide.add(requiredDimension);
const openingLabel = makeTextSprite("OPENING Ø 0.81", "#ff7770");
openingLabel.position.set(0, 1.55, 1.08);
guide.add(openingLabel);
const requiredLabel = makeTextSprite("REQUIRED Ø 1.61", "#58e0d1");
requiredLabel.position.set(0, 0.55, 1.08);
guide.add(requiredLabel);
const guideMaterials = [];
guide.traverse((object) => {
if (object.material) {
guideMaterials.push(object.material);
}
});
// -------------------------------------------------------------------------
// Timeline and animation helpers
// -------------------------------------------------------------------------
const DURATION = 15.6;
const INSTALLED_Y = 0.24;
const WRONG_STOP_Y = 0.76;
const clamp01 = (value) => THREE.MathUtils.clamp(value, 0, 1);
const lerp = THREE.MathUtils.lerp;
const easeInOut = (value) => {
const x = clamp01(value);
return x * x * (3 - 2 * x);
};
const easeOut = (value) => 1 - Math.pow(1 - clamp01(value), 3);
function cubicBezier(a, b, c, d, t) {
const s = 1 - t;
return new THREE.Vector3()
.addScaledVector(a, s * s * s)
.addScaledVector(b, 3 * s * s * t)
.addScaledVector(c, 3 * s * t * t)
.addScaledVector(d, t * t * t);
}
function setShellPose(shell, position, capOpen, yaw) {
shell.group.position.copy(position);
shell.group.rotation.y = yaw;
shell.headPivot.position.y = 1.9 + capOpen * 0.16;
shell.headPivot.rotation.x = -capOpen * 0.34;
}
function approachPose(shell, startTime, endTime, stageY, time) {
const progress = easeInOut((time - startTime) / (endTime - startTime));
const p0 = shell.park;
const p1 = shell.park.clone().add(new THREE.Vector3(0, 2.6, 0));
const p2 = new THREE.Vector3(0, stageY + 2.2, 0);
const p3 = new THREE.Vector3(0, stageY, 0);
const position = cubicBezier(p0, p1, p2, p3, progress);
const yaw = lerp(shell.parkYaw, shell.targetYaw, progress);
const capOpen = lerp(1, 0.3, progress);
setShellPose(shell, position, capOpen, yaw);
}
function updateCore(time) {
const progress = easeOut(time / 1.15);
core.scale.setScalar(0.82 * lerp(0.62, 1, progress));
core.position.y = lerp(-0.52, INSTALLED_Y, progress);
core.rotation.y = lerp(-0.85, 0.34, progress);
}
function updateCorrectShell(shell, time, timings, stageY) {
const [approachStart, approachEnd, descendStart, descendEnd, sealEnd] = timings;
if (time < approachStart) {
setShellPose(shell, shell.park, 1, shell.parkYaw);
return;
}
if (time < approachEnd) {
approachPose(shell, approachStart, approachEnd, stageY, time);
return;
}
if (time < descendEnd) {
const progress = easeInOut(
(time - descendStart) / (descendEnd - descendStart)
);
const position = new THREE.Vector3(
0,
lerp(stageY, INSTALLED_Y, progress),
0
);
setShellPose(shell, position, 0.3, shell.targetYaw);
return;
}
if (time < sealEnd) {
const progress = easeInOut(
(time - descendEnd) / (sealEnd - descendEnd)
);
setShellPose(
shell,
new THREE.Vector3(0, INSTALLED_Y, 0),
lerp(0.3, 0, progress),
shell.targetYaw
);
return;
}
setShellPose(
shell,
new THREE.Vector3(0, INSTALLED_Y, 0),
0,
shell.targetYaw
);
}
function updateWrongShell(time) {
wrongShell.bodyMaterial.emissive.set(0x000000);
wrongShell.bodyMaterial.emissiveIntensity = 0;
wrongShell.rimMaterial.emissive.set(0x000000);
wrongShell.rimMaterial.emissiveIntensity = 0;
if (time < 6.6) {
setShellPose(wrongShell, wrongShell.park, 1, wrongShell.parkYaw);
return;
}
if (time < 7.45) {
approachPose(wrongShell, 6.6, 7.45, 4.2, time);
return;
}
if (time < 8.55) {
const progress = easeInOut((time - 7.45) / (8.55 - 7.45));
setShellPose(
wrongShell,
new THREE.Vector3(0, lerp(4.2, WRONG_STOP_Y, progress), 0),
lerp(0.3, 0.14, progress),
wrongShell.targetYaw
);
return;
}
if (time < 10.15) {
const flash =
0.5 + 0.5 * Math.sin((time - 8.55) * 15);
wrongShell.bodyMaterial.emissive.set(0xff2b21);
wrongShell.bodyMaterial.emissiveIntensity = flash * 1.15;
wrongShell.rimMaterial.emissive.set(0xff2b21);
wrongShell.rimMaterial.emissiveIntensity = flash * 2.2;
const position = new THREE.Vector3(
Math.sin(time * 38) * 0.035,
WRONG_STOP_Y,
Math.cos(time * 31) * 0.025
);
setShellPose(wrongShell, position, 0.14, wrongShell.targetYaw);
return;
}
if (time < 11.1) {
const progress = easeInOut((time - 10.15) / (11.1 - 10.15));
const p0 = new THREE.Vector3(0, WRONG_STOP_Y, 0);
const p1 = new THREE.Vector3(0, WRONG_STOP_Y + 2.2, 0);
const p2 = wrongShell.park.clone().add(new THREE.Vector3(0, 1.7, 0));
const p3 = wrongShell.park;
const position = cubicBezier(p0, p1, p2, p3, progress);
setShellPose(
wrongShell,
position,
lerp(0.14, 1, progress),
lerp(wrongShell.targetYaw, wrongShell.parkYaw, progress)
);
return;
}
setShellPose(wrongShell, wrongShell.park, 1, wrongShell.parkYaw);
}
function updateGuide(time) {
const visible = time >= 8.43 && time <= 10.35;
guide.visible = visible;
const fadeIn = clamp01((time - 8.43) / 0.18);
const fadeOut = clamp01((10.35 - time) / 0.18);
const opacity = Math.min(fadeIn, fadeOut);
for (const material of guideMaterials) {
material.opacity = opacity * 0.95;
}
if (!visible) {
return;
}
const pulse = 0.5 + 0.5 * Math.sin(time * 11);
openingRing.position.set(
wrongShell.group.position.x,
wrongShell.group.position.y + 0.025,
0
);
openingRing.scale.setScalar(1 + pulse * 0.07);
requiredRing.position.set(0, 0.255, 0);
requiredRing.scale.setScalar(1 + pulse * 0.035);
openingDimension.position.x = wrongShell.group.position.x;
openingLabel.position.x = wrongShell.group.position.x;
}
const progressElement = document.querySelector("#progress");
const timeElement = document.querySelector("#time-label");
const stepElement = document.querySelector("#step-label");
const mismatchElement = document.querySelector("#mismatch-card");
let lastStatus = "";
function updateStatus(time) {
let label = "";
if (time < 1.2) {
label = "01 / Seed figure";
} else if (time < 3.8) {
label = "02 / First shell closes";
} else if (time < 6.6) {
label = "03 / Middle shell closes";
} else if (time < 8.55) {
label = "04 / Testing shell fit";
} else if (time < 10.15) {
label = "04 / Dimensional mismatch";
} else if (time < 11.2) {
label = "04 / Rejected shell returned";
} else if (time < 14.65) {
label = "05 / Correct outer shell";
} else {
label = "06 / Nested complete";
}
if (label !== lastStatus) {
stepElement.textContent = label;
lastStatus = label;
}
progressElement.style.width = `${clamp01(time / DURATION) * 100}%`;
timeElement.textContent = `${time.toFixed(1)} / ${DURATION.toFixed(1)} s`;
mismatchElement.classList.toggle(
"show",
time >= 8.55 && time <= 10.2
);
}
function evaluateTimeline(time) {
updateCore(time);
updateCorrectShell(
smallShell,
time,
[1.2, 2.2, 2.2, 3.25, 3.65],
2.35
);
updateCorrectShell(
mediumShell,
time,
[3.8, 4.8, 4.8, 6.0, 6.4],
2.9
);
updateWrongShell(time);
updateCorrectShell(
largeShell,
time,
[11.2, 12.25, 12.25, 14.2, 14.65],
4.15
);
updateGuide(time);
updateStatus(time);
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, and reset
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 2.45, 0);
let cameraRadius = 14.5;
let cameraTheta = 0.46;
let cameraPhi = 1.22;
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);
}
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;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + deltaY * 0.005,
0.72,
1.48
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
8.5,
21
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraRadius = 14.5;
cameraTheta = 0.46;
cameraPhi = 1.22;
updateCamera();
});
// -------------------------------------------------------------------------
// UI and render loop
// -------------------------------------------------------------------------
let timelineTime = 0;
let paused = false;
let playbackSpeed = 1;
const speedOptions = [0.75, 1, 1.5];
const pauseButton = document.querySelector("#pause");
const speedButton = document.querySelector("#speed");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
document.querySelector("#restart").addEventListener("click", () => {
timelineTime = 0;
paused = false;
pauseButton.textContent = "Pause";
evaluateTimeline(0);
});
speedButton.addEventListener("click", () => {
const currentIndex = speedOptions.indexOf(playbackSpeed);
playbackSpeed = speedOptions[(currentIndex + 1) % speedOptions.length];
speedButton.textContent = `${playbackSpeed}×`;
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
});
updateCamera();
evaluateTimeline(0);
let previousFrame = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousFrame) / 1000, 0.05);
previousFrame = now;
if (!paused && timelineTime < DURATION) {
timelineTime = Math.min(
DURATION,
timelineTime + delta * playbackSpeed
);
}
evaluateTimeline(timelineTime);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```