Prompt specification
Build or customize the Three.js 3D scene "Follow a clue to the toy" 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: Follow a clue to the toy
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/follow-a-clue-to-the-toy-x3874
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Animate a child checking a shelf, noticing a matching wheel beneath a chair, and finding the toy; each clue appears before the action it motivates.
Working Three.js Starter (follow-a-clue-to-the-toy-x3874):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Little Red Wheel</title>
<style>
:root {
--ink: #24363d;
--cream: #fff8e8;
--yellow: #f6c85f;
--teal: #5aa7a0;
--red: #d85b4b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bed8d8;
color: var(--ink);
font-family: ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 45%, rgba(35, 55, 62, 0.12) 100%),
linear-gradient(to bottom, rgba(255, 255, 255, 0.08), transparent 35%);
z-index: 2;
}
.title-card {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
pointer-events: none;
max-width: min(430px, calc(100vw - 52px));
}
.title-card .kicker {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
padding: 7px 11px;
border-radius: 999px;
background: rgba(255, 248, 232, 0.88);
box-shadow: 0 8px 28px rgba(31, 54, 61, 0.12);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.title-card .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--red);
box-shadow: 0 0 0 4px rgba(216, 91, 75, 0.15);
}
h1 {
margin: 0;
color: #fffdf5;
font-size: clamp(31px, 4.5vw, 60px);
line-height: 0.95;
letter-spacing: -0.055em;
text-shadow: 0 4px 24px rgba(31, 54, 61, 0.2);
}
.subtitle {
margin-top: 10px;
max-width: 390px;
color: rgba(255, 255, 255, 0.9);
font-size: 13px;
line-height: 1.45;
text-shadow: 0 2px 12px rgba(31, 54, 61, 0.25);
}
.camera-hint {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 999px;
background: rgba(37, 58, 65, 0.55);
color: white;
backdrop-filter: blur(12px);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.03em;
pointer-events: none;
}
.story-panel {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 5;
width: min(780px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 16px 18px 14px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 22px;
background: rgba(255, 248, 232, 0.9);
box-shadow: 0 18px 60px rgba(30, 53, 59, 0.22);
backdrop-filter: blur(16px);
}
.story-copy {
display: flex;
align-items: flex-start;
gap: 13px;
min-height: 48px;
}
.chapter-number {
display: grid;
flex: 0 0 38px;
width: 38px;
height: 38px;
place-items: center;
border-radius: 12px;
background: var(--yellow);
color: #33454a;
font-size: 12px;
font-weight: 900;
box-shadow: inset 0 -2px 0 rgba(88, 70, 27, 0.12);
}
#chapterLabel {
margin-bottom: 3px;
color: #b04d40;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#caption {
font-size: clamp(14px, 2vw, 17px);
font-weight: 750;
line-height: 1.35;
}
.timeline-wrap {
margin-top: 12px;
}
#seek {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(to right, var(--red) 0%, var(--red) var(--progress, 0%),
rgba(57, 78, 83, 0.16) var(--progress, 0%), rgba(57, 78, 83, 0.16) 100%);
cursor: pointer;
}
#seek::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid var(--cream);
border-radius: 50%;
appearance: none;
background: var(--red);
box-shadow: 0 2px 8px rgba(31, 54, 61, 0.28);
}
#seek::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--cream);
border-radius: 50%;
background: var(--red);
box-shadow: 0 2px 8px rgba(31, 54, 61, 0.28);
}
.controls-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
}
.chapters,
.buttons {
display: flex;
align-items: center;
gap: 7px;
}
button {
border: 0;
color: var(--ink);
font: inherit;
cursor: pointer;
}
.chapter-button {
padding: 7px 9px;
border-radius: 9px;
background: transparent;
color: rgba(36, 54, 61, 0.58);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: 160ms ease;
}
.chapter-button:hover,
.chapter-button.active {
background: rgba(216, 91, 75, 0.12);
color: #a54236;
}
.control-button {
min-width: 40px;
height: 36px;
padding: 0 12px;
border-radius: 11px;
background: rgba(54, 76, 81, 0.09);
font-size: 12px;
font-weight: 800;
transition: transform 150ms ease, background 150ms ease;
}
.control-button:hover {
transform: translateY(-1px);
background: rgba(54, 76, 81, 0.15);
}
.control-button.primary {
background: var(--ink);
color: white;
}
@media (max-width: 650px) {
.title-card {
top: 18px;
left: 18px;
}
.subtitle,
.camera-hint {
display: none;
}
.story-panel {
bottom: 14px;
padding: 13px;
border-radius: 18px;
}
.chapters {
display: none;
}
.controls-row {
justify-content: flex-end;
}
}
</style>
</head>
<body>
<div class="vignette"></div>
<header class="title-card">
<div class="kicker">
<span class="dot"></span>
A tiny mystery
</div>
<h1>The Little<br />Red Wheel</h1>
<p class="subtitle">
Every clue appears first. Follow the child from the shelf to the chair,
then discover what the matching wheel unlocks.
</p>
</header>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<section class="story-panel" aria-live="polite">
<div class="story-copy">
<div id="chapterNumber" class="chapter-number">01</div>
<div>
<div id="chapterLabel">Clue 1 · The shelf</div>
<div id="caption">A little sign says: CHECK THE SHELF.</div>
</div>
</div>
<div class="timeline-wrap">
<input
id="seek"
type="range"
min="0"
max="19"
step="0.01"
value="0"
aria-label="Animation timeline"
/>
</div>
<div class="controls-row">
<div class="chapters">
<button class="chapter-button active" data-time="0">Shelf</button>
<button class="chapter-button" data-time="5.3">Wheel</button>
<button class="chapter-button" data-time="10">Match</button>
<button class="chapter-button" data-time="14.2">Toy</button>
</div>
<div class="buttons">
<button id="play" class="control-button primary">Pause</button>
<button id="replay" class="control-button">Replay</button>
<button id="resetCamera" class="control-button">Camera</button>
</div>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbed8d8);
scene.fog = new THREE.Fog(0xbed8d8, 12, 27);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly child following clues to find a hidden toy"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const duration = 19;
let time = 0;
let playing = true;
const hemi = new THREE.HemisphereLight(0xe9f8ff, 0x9c795b, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedc5, 3.1);
sun.position.set(5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ed8df, 0.75);
fill.position.set(-6, 5, 1);
scene.add(fill);
const color = {
wall: 0xe8ddc8,
wallSide: 0xd5c6ae,
floor: 0xb88d68,
floorEdge: 0x8e654d,
wood: 0xb87848,
woodLight: 0xd69a61,
woodDark: 0x754a37,
teal: 0x4e9b95,
tealDark: 0x34736f,
yellow: 0xf5c85d,
red: 0xd75a49,
cream: 0xfff1cf,
navy: 0x345463,
green: 0x6e9c68,
greenDark: 0x47794d,
skin: 0xd99b72,
hair: 0x4b3028,
black: 0x24343a
};
function material(c, extra = {}) {
return new THREE.MeshStandardMaterial({
color: c,
roughness: 0.82,
metalness: 0,
flatShading: true,
...extra
});
}
function mesh(parent, geometry, mat, position = [0, 0, 0], rotation = [0, 0, 0]) {
const object = new THREE.Mesh(geometry, mat);
object.position.set(...position);
object.rotation.set(...rotation);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(parent, size, mat, position = [0, 0, 0], rotation = [0, 0, 0]) {
return mesh(
parent,
new THREE.BoxGeometry(...size),
mat,
position,
rotation
);
}
function cylinder(parent, radii, height, segments, mat, position = [0, 0, 0], rotation = [0, 0, 0]) {
return mesh(
parent,
new THREE.CylinderGeometry(radii[0], radii[1], height, segments),
mat,
position,
rotation
);
}
function sphere(parent, radius, mat, position = [0, 0, 0], scale = [1, 1, 1]) {
const object = mesh(
parent,
new THREE.SphereGeometry(radius, 8, 6),
mat,
position
);
object.scale.set(...scale);
return object;
}
// -------------------------------------------------------------------------
// Room
// -------------------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
box(room, [14, 0.18, 13], material(color.floor), [0, -0.11, 0]);
box(room, [14, 7.5, 0.25], material(color.wall), [0, 3.65, -4.2]);
box(room, [0.25, 7.5, 11], material(color.wallSide), [-6.2, 3.65, -0.2]);
// Low baseboards.
box(room, [13.7, 0.22, 0.12], material(0xf0e6d4), [0, 0.1, -4.04]);
box(room, [0.12, 0.22, 10.7], material(0xf0e6d4), [-6.04, 0.1, -0.2]);
// Rug.
const rug = cylinder(room, [3.25, 3.25], 0.055, 40, material(0xe9d6b2), [0.2, 0.015, 0.55]);
rug.scale.set(1.15, 1, 0.73);
const rugInner = cylinder(room, [2.48, 2.48], 0.018, 40, material(0x91b6ad), [0.2, 0.052, 0.55]);
rugInner.scale.set(1.15, 1, 0.73);
// Window.
const windowGroup = new THREE.Group();
windowGroup.position.set(1.55, 3.2, -4.02);
room.add(windowGroup);
box(windowGroup, [3.0, 2.25, 0.12], material(0x9bcdd4), [0, 0, 0]);
box(windowGroup, [3.25, 0.14, 0.2], material(0xfff1d4), [0, 1.17, 0.08]);
box(windowGroup, [3.25, 0.14, 0.2], material(0xfff1d4), [0, -1.17, 0.08]);
box(windowGroup, [0.14, 2.48, 0.2], material(0xfff1d4), [-1.57, 0, 0.08]);
box(windowGroup, [0.14, 2.48, 0.2], material(0xfff1d4), [1.57, 0, 0.08]);
box(windowGroup, [0.11, 2.36, 0.18], material(0xfff1d4), [0, 0, 0.1]);
box(windowGroup, [3.1, 0.11, 0.18], material(0xfff1d4), [0, 0, 0.1]);
const sunDisc = mesh(
windowGroup,
new THREE.CircleGeometry(0.37, 16),
new THREE.MeshBasicMaterial({ color: 0xffd66f }),
[0.75, 0.52, 0.09]
);
sunDisc.castShadow = false;
// Plant.
const plant = new THREE.Group();
plant.position.set(4.65, 0, -3.25);
room.add(plant);
cylinder(plant, [0.42, 0.3], 0.65, 8, material(0xb96c4e), [0, 0.34, 0]);
cylinder(plant, [0.35, 0.35], 0.06, 8, material(0x704636), [0, 0.68, 0]);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = mesh(
plant,
new THREE.SphereGeometry(0.38, 6, 4),
material(i % 2 ? color.green : color.greenDark),
[Math.cos(angle) * 0.24, 1.0 + (i % 2) * 0.14, Math.sin(angle) * 0.24],
[0.2, angle, -0.35]
);
leaf.scale.set(0.45, 1.1, 0.24);
}
// -------------------------------------------------------------------------
// Shelf and hidden compartment
// -------------------------------------------------------------------------
const shelf = new THREE.Group();
shelf.position.set(-2.7, 0, -3.5);
room.add(shelf);
const shelfWood = material(color.wood);
const shelfLight = material(color.woodLight);
const shelfDark = material(color.woodDark);
box(shelf, [3.8, 3.05, 0.14], shelfDark, [0, 1.68, -0.38]);
box(shelf, [0.18, 3.15, 0.86], shelfWood, [-1.91, 1.65, 0]);
box(shelf, [0.18, 3.15, 0.86], shelfWood, [1.91, 1.65, 0]);
[0.18, 1.2, 2.2, 3.22].forEach((y) => {
box(shelf, [3.95, 0.15, 0.9], shelfLight, [0, y, 0]);
});
// Books and storage on the right side.
const bookColors = [0xd45e4c, 0x4f8e91, 0xe7b44c, 0x6c7c9c, 0x78965f];
for (let i = 0; i < 7; i++) {
const h = 0.42 + (i % 3) * 0.08;
box(
shelf,
[0.16, h, 0.48],
material(bookColors[i % bookColors.length]),
[0.58 + i * 0.19, 1.28 + h / 2, 0.02],
[0, 0, (i % 2 ? 1 : -1) * 0.025]
);
}
box(shelf, [1.1, 0.62, 0.66], material(0xd5aa68), [1.15, 1.57, 0]);
box(shelf, [0.83, 0.06, 0.69], material(0xe4bf7d), [1.15, 1.91, 0]);
box(shelf, [0.28, 0.12, 0.05], material(0x896044), [1.15, 1.65, 0.35]);
// Little house on top.
const house = new THREE.Group();
house.position.set(-1.12, 3.3, 0.04);
shelf.add(house);
box(house, [0.7, 0.55, 0.6], material(0xe9c783), [0, 0.28, 0]);
const roof = mesh(
house,
new THREE.ConeGeometry(0.58, 0.48, 4),
material(0xb75d4b),
[0, 0.78, 0],
[0, Math.PI / 4, 0]
);
roof.scale.z = 0.9;
box(house, [0.18, 0.3, 0.03], material(0x5e7776), [0, 0.18, 0.31]);
// Hinged panel inside the shelf.
const panelHinge = new THREE.Group();
panelHinge.position.set(-1.65, 1.7, 0.47);
shelf.add(panelHinge);
box(panelHinge, [1.4, 0.82, 0.09], material(0xe3b879), [0.7, 0, 0]);
box(panelHinge, [1.48, 0.08, 0.12], shelfDark, [0.7, 0.38, 0.01]);
box(panelHinge, [1.48, 0.08, 0.12], shelfDark, [0.7, -0.38, 0.01]);
const hub = mesh(
panelHinge,
new THREE.TorusGeometry(0.17, 0.052, 6, 12),
material(0x85694f),
[0.96, 0, 0.075]
);
const hubGlowMaterial = new THREE.MeshBasicMaterial({
color: 0xffd66f,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const hubGlow = mesh(
panelHinge,
new THREE.TorusGeometry(0.28, 0.022, 6, 24),
hubGlowMaterial,
[0.96, 0, 0.085]
);
hubGlow.castShadow = false;
// Sign texture helper.
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeSignTexture(title, subtitle, background = "#fff1cf", foreground = "#33474d") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 12, 12, 744, 196, 34);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = "rgba(53, 70, 75, 0.25)";
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = "900 58px system-ui";
ctx.fillText(title, 384, 78);
ctx.font = "700 28px system-ui";
ctx.fillText(subtitle, 384, 142);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
const shelfSignMaterial = new THREE.MeshBasicMaterial({
map: makeSignTexture("CHECK THE SHELF", "a tiny clue is waiting"),
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const shelfSign = mesh(
shelf,
new THREE.PlaneGeometry(2.15, 0.62),
shelfSignMaterial,
[-1.0, 2.66, 0.49]
);
shelfSign.castShadow = false;
// -------------------------------------------------------------------------
// Chair
// -------------------------------------------------------------------------
const chair = new THREE.Group();
chair.position.set(2.55, 0, -0.45);
room.add(chair);
const chairMat = material(0x4f9692);
const chairLegMat = material(0x775044);
box(chair, [1.18, 0.18, 1.08], chairMat, [0, 1.02, 0]);
box(chair, [1.18, 1.12, 0.15], chairMat, [0, 1.65, -0.49], [-0.08, 0, 0]);
[
[-0.46, 0.48, -0.39],
[0.46, 0.48, -0.39],
[-0.46, 0.48, 0.39],
[0.46, 0.48, 0.39]
].forEach(([x, y, z]) => {
const leg = cylinder(chair, [0.07, 0.09], 0.95, 7, chairLegMat, [x, y, z]);
leg.rotation.z = x < 0 ? -0.05 : 0.05;
});
box(chair, [1.22, 0.13, 0.16], chairLegMat, [0, 0.61, -0.43]);
box(chair, [1.22, 0.13, 0.16], chairLegMat, [0, 0.61, 0.43]);
// -------------------------------------------------------------------------
// Matching wheel clue
// -------------------------------------------------------------------------
const wheelRestPosition = new THREE.Vector3(2.14, 0.45, -0.1);
const freeWheel = new THREE.Group();
freeWheel.position.copy(wheelRestPosition);
room.add(freeWheel);
const wheelRed = material(color.red);
const wheelHubMat = material(0xe5aa58);
const freeTorus = mesh(
freeWheel,
new THREE.TorusGeometry(0.21, 0.06, 7, 14),
wheelRed
);
for (let i = 0; i < 4; i++) {
const spoke = box(
freeWheel,
[0.34, 0.045, 0.045],
wheelHubMat,
[0, 0, 0],
[0, 0, (i * Math.PI) / 4]
);
spoke.castShadow = true;
}
cylinder(
freeWheel,
[0.075, 0.075],
0.09,
8,
wheelHubMat,
[0, 0, 0],
[Math.PI / 2, 0, 0]
);
const wheelHaloMaterial = new THREE.MeshBasicMaterial({
color: 0xffd36d,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const wheelHalo = mesh(
freeWheel,
new THREE.TorusGeometry(0.33, 0.022, 6, 28),
wheelHaloMaterial,
[0, 0, 0]
);
wheelHalo.castShadow = false;
const matchTexture = makeSignTexture("RED WHEEL", "does it match?", "#f7d66f", "#713d38");
const matchMaterial = new THREE.SpriteMaterial({
map: matchTexture,
transparent: true,
opacity: 0,
depthWrite: false
});
const matchLabel = new THREE.Sprite(matchMaterial);
matchLabel.position.set(2.14, 1.34, 0.03);
matchLabel.scale.set(1.6, 0.46, 1);
room.add(matchLabel);
// The version that becomes part of the shelf lock.
const attachedWheel = new THREE.Group();
attachedWheel.position.set(0.96, 0, 0.13);
attachedWheel.visible = false;
panelHinge.add(attachedWheel);
mesh(
attachedWheel,
new THREE.TorusGeometry(0.185, 0.055, 7, 14),
wheelRed
);
for (let i = 0; i < 4; i++) {
box(
attachedWheel,
[0.3, 0.04, 0.04],
wheelHubMat,
[0, 0, 0],
[0, 0, (i * Math.PI) / 4]
);
}
cylinder(
attachedWheel,
[0.07, 0.07],
0.08,
8,
wheelHubMat,
[0, 0, 0],
[Math.PI / 2, 0, 0]
);
// -------------------------------------------------------------------------
// Hidden toy robot
// -------------------------------------------------------------------------
const robot = new THREE.Group();
const robotBasePosition = new THREE.Vector3(-3.42, 1.27, -3.25);
robot.position.copy(robotBasePosition);
robot.visible = false;
room.add(robot);
const robotYellow = material(0xf0bd48);
const robotTeal = material(0x4c9896);
const robotRed = material(0xd45c4d);
const robotDark = material(0x344b52);
box(robot, [0.43, 0.47, 0.3], robotYellow, [0, 0.32, 0]);
box(robot, [0.25, 0.17, 0.025], robotTeal, [0, 0.32, 0.166]);
sphere(robot, 0.245, robotYellow, [0, 0.69, 0]);
sphere(robot, 0.034, robotDark, [-0.085, 0.71, 0.222]);
sphere(robot, 0.034, robotDark, [0.085, 0.71, 0.222]);
box(robot, [0.11, 0.025, 0.025], robotRed, [0, 0.61, 0.23]);
cylinder(robot, [0.022, 0.022], 0.18, 6, robotDark, [0, 0.96, 0]);
sphere(robot, 0.065, robotRed, [0, 1.06, 0]);
const robotArmL = box(robot, [0.12, 0.34, 0.13], robotTeal, [-0.29, 0.34, 0], [0, 0, -0.16]);
const robotArmR = box(robot, [0.12, 0.34, 0.13], robotTeal, [0.29, 0.34, 0], [0, 0, 0.16]);
const robotLegL = box(robot, [0.15, 0.22, 0.16], robotDark, [-0.12, 0.09, 0]);
const robotLegR = box(robot, [0.15, 0.22, 0.16], robotDark, [0.12, 0.09, 0]);
robotArmL.castShadow = true;
robotArmR.castShadow = true;
robotLegL.castShadow = true;
robotLegR.castShadow = true;
// -------------------------------------------------------------------------
// Low-poly child
// -------------------------------------------------------------------------
const child = new THREE.Group();
room.add(child);
const skinMat = material(color.skin);
const shirtMat = material(0xe49b45);
const pantsMat = material(color.navy);
const shoeMat = material(0xb95148);
const hairMat = material(color.hair);
const body = new THREE.Group();
body.position.y = 0.78;
child.add(body);
cylinder(body, [0.31, 0.35, 0.66, 7], 0.64, 7, shirtMat, [0, 0.32, 0]);
cylinder(body, [0.31, 0.31, 0.1, 7], 0.1, 7, material(0x6d9b8f), [0, 0.05, 0]);
const head = new THREE.Group();
head.position.set(0, 0.9, 0);
body.add(head);
sphere(head, 0.3, skinMat, [0, 0, 0], [1, 1.04, 0.96]);
const hairCap = mesh(
head,
new THREE.SphereGeometry(0.315, 8, 5, 0, Math.PI * 2, 0, Math.PI * 0.54),
hairMat,
[0, 0.065, 0],
[0.08, 0, 0]
);
hairCap.scale.set(1.03, 0.76, 1.02);
const hairTuft = mesh(
head,
new THREE.ConeGeometry(0.13, 0.28, 5),
hairMat,
[0.09, 0.32, -0.03],
[-0.2, 0, 0.25]
);
sphere(head, 0.034, material(0x25383e), [-0.092, 0.015, 0.276], [1, 1.15, 0.55]);
sphere(head, 0.034, material(0x25383e), [0.092, 0.015, 0.276], [1, 1.15, 0.55]);
sphere(head, 0.055, skinMat, [0, -0.035, 0.31], [1, 0.75, 0.95]);
box(head, [0.13, 0.025, 0.025], material(0x9e514a), [0, -0.115, 0.288]);
const armL = new THREE.Group();
armL.position.set(-0.38, 0.58, 0);
body.add(armL);
cylinder(armL, [0.09, 0.105], 0.48, 6, shirtMat, [0, -0.24, 0]);
const handL = sphere(armL, 0.105, skinMat, [0, -0.53, 0]);
const armR = new THREE.Group();
armR.position.set(0.38, 0.58, 0);
body.add(armR);
cylinder(armR, [0.09, 0.105], 0.48, 6, shirtMat, [0, -0.24, 0]);
const handR = sphere(armR, 0.105, skinMat, [0, -0.53, 0]);
const legL = new THREE.Group();
legL.position.set(-0.16, 0.7, 0);
child.add(legL);
cylinder(legL, [0.105, 0.12], 0.52, 6, pantsMat, [0, -0.27, 0]);
box(legL, [0.22, 0.14, 0.36], shoeMat, [0, -0.58, 0.07]);
const legR = new THREE.Group();
legR.position.set(0.16, 0.7, 0);
child.add(legR);
cylinder(legR, [0.105, 0.12], 0.52, 6, pantsMat, [0, -0.27, 0]);
box(legR, [0.22, 0.14, 0.36], shoeMat, [0, -0.58, 0.07]);
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const clamp01 = (v) => Math.min(1, Math.max(0, v));
const lerp = (a, b, t) => a + (b - a) * t;
const smooth = (a, b, value) => {
const x = clamp01((value - a) / (b - a));
return x * x * (3 - 2 * x);
};
function angleLerp(a, b, t) {
let difference = ((b - a + Math.PI) % (Math.PI * 2)) - Math.PI;
if (difference < -Math.PI) difference += Math.PI * 2;
return a + difference * t;
}
const startPosition = new THREE.Vector3(0.35, 0, 1.85);
const shelfPosition = new THREE.Vector3(-3.4, 0, -2.2);
const chairPosition = new THREE.Vector3(1.55, 0, 0.58);
function childPosition(t, target) {
if (t < 2.15) {
target.copy(startPosition);
} else if (t < 4.25) {
target.lerpVectors(startPosition, shelfPosition, smooth(2.15, 4.25, t));
} else if (t < 6.35) {
target.copy(shelfPosition);
} else if (t < 9.55) {
target.lerpVectors(shelfPosition, chairPosition, smooth(6.35, 9.55, t));
} else if (t < 10.8) {
target.copy(chairPosition);
} else if (t < 13.3) {
target.lerpVectors(chairPosition, shelfPosition, smooth(10.8, 13.3, t));
} else {
target.copy(shelfPosition);
}
}
function childAngle(t) {
if (t < 1.85) return 0.2;
if (t < 3.15) return angleLerp(0.2, Math.PI, smooth(1.85, 3.15, t));
if (t < 5.65) return Math.PI;
if (t < 6.45) return angleLerp(Math.PI, 1.15, smooth(5.65, 6.45, t));
if (t < 7.75) return 1.15;
if (t < 8.35) return angleLerp(1.15, 2.43, smooth(7.75, 8.35, t));
if (t < 9.8) return 2.43;
if (t < 10.55) return angleLerp(2.43, -1.96, smooth(9.8, 10.55, t));
if (t < 12.35) return -1.96;
return angleLerp(-1.96, Math.PI, smooth(12.35, 13.15, t));
}
const temporaryPosition = new THREE.Vector3();
const handPosition = new THREE.Vector3();
const hubWorldPosition = new THREE.Vector3();
const robotHoldPosition = new THREE.Vector3();
function updateCharacter(t) {
childPosition(t, temporaryPosition);
child.position.copy(temporaryPosition);
child.rotation.y = childAngle(t);
const walking =
smooth(2.15, 2.45, t) * (1 - smooth(3.9, 4.25, t)) +
smooth(6.35, 6.65, t) * (1 - smooth(9.15, 9.55, t)) +
smooth(10.8, 11.1, t) * (1 - smooth(12.95, 13.3, t));
const gait = Math.sin(t * 10.2) * walking;
child.position.y += Math.abs(gait) * 0.035;
const crouch =
smooth(8.05, 8.45, t) * (1 - smooth(9.45, 10.0, t));
body.position.y = 0.78 - crouch * 0.32;
body.rotation.x = crouch * 0.12;
legL.rotation.x = gait * 0.5 + crouch * 0.45;
legR.rotation.x = -gait * 0.5 + crouch * 0.45;
armL.rotation.set(gait * 0.42, 0, -0.07);
armR.rotation.set(-gait * 0.42, 0, 0.07);
// Check the shelf.
const shelfCheck = smooth(3.45, 4.0, t) * (1 - smooth(5.35, 5.8, t));
armR.rotation.x = lerp(armR.rotation.x, -0.9, shelfCheck);
head.rotation.x = lerp(head.rotation.x, 0.18, shelfCheck);
head.rotation.y = lerp(head.rotation.y, 0.12, shelfCheck);
// Notice the wheel over a shoulder.
const glance = smooth(5.45, 5.9, t) * (1 - smooth(6.45, 6.85, t));
head.rotation.y = lerp(head.rotation.y, -1.05, glance);
head.rotation.x = lerp(head.rotation.x, 0.02, glance);
// Crouch and pick up the wheel.
const pickWheel = smooth(8.05, 8.45, t) * (1 - smooth(9.45, 9.95, t));
armR.rotation.x = lerp(armR.rotation.x, -0.25, pickWheel);
head.rotation.x = lerp(head.rotation.x, 0.38, pickWheel);
// Carry the wheel with less arm swing.
const carrying = smooth(9.4, 9.8, t) * (1 - smooth(13.15, 13.55, t));
armR.rotation.x = lerp(armR.rotation.x, -0.72, carrying * 0.75);
// Fit the wheel into the shelf lock.
const attach = smooth(13.25, 13.7, t) * (1 - smooth(14.0, 14.35, t));
armR.rotation.x = lerp(armR.rotation.x, -1.48, attach);
head.rotation.x = lerp(head.rotation.x, 0.08, attach);
// Reach for and lift the toy.
const reachToy = smooth(15.1, 15.55, t) * (1 - smooth(16.2, 16.65, t));
armL.rotation.x = lerp(armL.rotation.x, -1.45, reachToy);
armR.rotation.x = lerp(armR.rotation.x, -1.55, reachToy);
const liftToy = smooth(16.15, 16.65, t);
armL.rotation.x = lerp(armL.rotation.x, -1.95, liftToy);
armR.rotation.x = lerp(armR.rotation.x, -2.25, liftToy);
armL.rotation.z = lerp(armL.rotation.z, -0.25, liftToy);
armR.rotation.z = lerp(armR.rotation.z, 0.22, liftToy);
head.rotation.x = lerp(head.rotation.x, -0.08, liftToy);
child.updateMatrixWorld(true);
handR.getWorldPosition(handPosition);
}
function updateClues(t) {
const signIn = smooth(0.35, 1.05, t);
shelfSignMaterial.opacity = signIn * 0.94;
const signPop = 0.86 + Math.sin(smooth(0.35, 1.8, t) * Math.PI) * 0.14;
shelfSign.scale.setScalar(Math.max(0.001, signIn * signPop));
const wheelIn = smooth(5.25, 5.9, t);
freeWheel.visible = t >= 5.25 && t < 14.01;
freeWheel.scale.setScalar(Math.max(0.001, wheelIn));
const wheelGlow = smooth(5.25, 5.85, t) * (1 - smooth(9.35, 9.85, t));
wheelHaloMaterial.opacity = wheelGlow * (0.48 + Math.sin(t * 5) * 0.14);
wheelHalo.scale.setScalar(1 + Math.sin(t * 4.2) * 0.07);
const matchIn = smooth(5.35, 5.95, t);
const matchOut = 1 - smooth(8.95, 9.65, t);
matchMaterial.opacity = matchIn * matchOut * 0.95;
matchLabel.scale.set(
1.6 * Math.max(0.001, matchIn),
0.46 * Math.max(0.001, matchIn),
1
);
matchLabel.position.y = 1.34 + Math.sin(t * 3.2) * 0.055;
const hubClue = smooth(9.75, 10.15, t) * (1 - smooth(13.75, 14.05, t));
hubGlowMaterial.opacity = hubClue * (0.55 + Math.sin(t * 6.5) * 0.2);
hubGlow.scale.setScalar(1 + Math.sin(t * 6.5) * 0.1);
attachedWheel.visible = t >= 14;
attachedWheel.scale.setScalar(smooth(13.95, 14.15, t));
}
function updateWheelAndToy(t) {
updateCharacter(t);
// World position of the empty lock.
panelHinge.updateMatrixWorld(true);
hubWorldPosition.set(0.96, 0, 0.14);
panelHinge.localToWorld(hubWorldPosition);
if (t < 8.35) {
freeWheel.position.copy(wheelRestPosition);
} else if (t < 9.35) {
freeWheel.position.lerpVectors(
wheelRestPosition,
handPosition,
smooth(8.35, 9.35, t)
);
} else if (t < 13.45) {
freeWheel.position.copy(handPosition);
freeWheel.position.y -= 0.03;
} else {
freeWheel.position.lerpVectors(
handPosition,
hubWorldPosition,
smooth(13.45, 14, t)
);
}
freeWheel.rotation.z = Math.sin(t * 4) * 0.05;
freeWheel.rotation.y = smooth(8.35, 9.35, t) * 0.15;
// Panel opens only after the wheel has been fitted.
const opening = smooth(14.05, 15.0, t);
panelHinge.rotation.y = opening * 1.28;
// Toy appears after the lock is opened.
const reveal = smooth(14.2, 15.05, t);
robot.visible = t >= 14.2;
robotHoldPosition.set(
child.position.x,
1.53 + child.position.y,
child.position.z - 0.54
);
if (t < 15.3) {
robot.position.set(
robotBasePosition.x,
robotBasePosition.y + reveal * 0.04,
lerp(robotBasePosition.z, -2.83, reveal)
);
robot.scale.setScalar(Math.max(0.001, reveal * 0.9));
} else {
const pick = smooth(15.3, 16.35, t);
robot.position.lerpVectors(
new THREE.Vector3(robotBasePosition.x, robotBasePosition.y, -2.83),
robotHoldPosition,
pick
);
robot.scale.setScalar(lerp(0.9, 0.84, pick));
}
robot.rotation.y = 0;
robot.rotation.z = lerp(0, -0.05, smooth(16.0, 16.6, t));
}
// -------------------------------------------------------------------------
// Custom orbit camera: no addons or OrbitControls
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-0.15, 1.25, -0.85),
theta: 0.55,
phi: 1.02,
radius: 12.1,
dragging: false,
pointerX: 0,
pointerY: 0
};
function resetCamera() {
cameraState.theta = 0.55;
cameraState.phi = 1.02;
cameraState.radius = window.innerWidth < 700 ? 14.2 : 12.1;
cameraState.target.set(-0.15, 1.25, -0.85);
}
function updateCamera() {
const mobileOffset = window.innerWidth < 700 ? 1.8 : 0;
const radius = cameraState.radius + mobileOffset;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + radius * Math.cos(cameraState.phi),
cameraState.target.z + radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.pointerX;
const dy = event.clientY - cameraState.pointerY;
cameraState.pointerX = event.clientX;
cameraState.pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.55,
1.38
);
});
function stopDragging() {
cameraState.dragging = false;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
7.4,
16.5
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
const playButton = document.getElementById("play");
const replayButton = document.getElementById("replay");
const resetCameraButton = document.getElementById("resetCamera");
const seek = document.getElementById("seek");
const caption = document.getElementById("caption");
const chapterLabel = document.getElementById("chapterLabel");
const chapterNumber = document.getElementById("chapterNumber");
const chapterButtons = [...document.querySelectorAll(".chapter-button")];
const chapters = [
{
start: 0,
number: "01",
label: "Clue 1 · The shelf",
text: "A little sign says: CHECK THE SHELF."
},
{
start: 2.2,
number: "02",
label: "The shelf",
text: "The clue appears first, and the child goes to check the shelf."
},
{
start: 5.3,
number: "03",
label: "Clue 2 · The wheel",
text: "A matching red wheel appears beneath the chair."
},
{
start: 6.5,
number: "04",
label: "The wheel",
text: "The child notices the new clue and picks up the wheel."
},
{
start: 9.8,
number: "05",
label: "Clue 3 · The match",
text: "The empty wheel-lock on the shelf starts to glow."
},
{
start: 10.8,
number: "06",
label: "The match",
text: "Now the child carries the matching wheel back to the shelf."
},
{
start: 14.0,
number: "07",
label: "The hidden compartment",
text: "The wheel fits. The hidden compartment opens!"
},
{
start: 15.2,
number: "08",
label: "The toy",
text: "The toy is found — and the little mystery is solved."
}
];
function currentChapter(t) {
let selected = chapters[0];
for (const chapter of chapters) {
if (t >= chapter.start) selected = chapter;
}
return selected;
}
function updateInterface() {
const selected = currentChapter(time);
caption.textContent = selected.text;
chapterLabel.textContent = selected.label;
chapterNumber.textContent = selected.number;
const chapterIndex =
time < 5.3 ? 0 : time < 9.8 ? 1 : time < 14.0 ? 2 : 3;
chapterButtons.forEach((button, index) => {
button.classList.toggle("active", index === chapterIndex);
});
seek.value = time.toFixed(2);
seek.style.setProperty("--progress", `${(time / duration) * 100}%`);
playButton.textContent = playing ? "Pause" : time >= duration ? "Replay" : "Play";
}
function togglePlay() {
if (time >= duration) {
time = 0;
playing = true;
} else {
playing = !playing;
}
updateInterface();
}
playButton.addEventListener("click", togglePlay);
replayButton.addEventListener("click", () => {
time = 0;
playing = true;
updateInterface();
});
resetCameraButton.addEventListener("click", resetCamera);
seek.addEventListener("input", () => {
time = Number(seek.value);
updateInterface();
});
chapterButtons.forEach((button) => {
button.addEventListener("click", () => {
time = Number(button.dataset.time);
playing = true;
updateInterface();
});
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target.tagName !== "INPUT") {
event.preventDefault();
togglePlay();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetCamera();
updateCamera();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
time = Math.min(duration, time + delta);
if (time >= duration) {
playing = false;
}
}
updateWheelAndToy(time);
updateClues(time);
updateCamera();
updateInterface();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```