Prompt specification
Build or customize the Three.js 3D scene "Museum opening route" 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: Museum opening route
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/museum-opening-route-x0044
Scene Description Prompt:
Museum opening route. Create a miniature museum with a key cabinet and four galleries; animate the caretaker opening doors in sequence while the cabinet records which keys are absent. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (museum-opening-route-x0044):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Miniature Museum — Opening Route</title>
<style>
:root {
--ink: #17232c;
--muted: #667681;
--paper: rgba(251, 249, 242, 0.93);
--line: rgba(23, 35, 44, 0.13);
--shadow: 0 16px 42px rgba(24, 37, 45, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e4e8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
z-index: 0;
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.68);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 20px;
left: 20px;
width: min(340px, calc(100vw - 40px));
padding: 20px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 8px;
color: #8c5c30;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
line-height: 1.02;
letter-spacing: -0.045em;
}
#intro p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
#phase {
margin-top: 16px;
padding: 11px 12px;
border-radius: 10px;
background: #20313c;
color: #fff9e8;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.06em;
line-height: 1.4;
}
#ledger {
top: 20px;
right: 20px;
width: 286px;
padding: 17px;
border-radius: 18px;
}
.ledger-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.ledger-title strong {
font-size: 13px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #4ea77a;
box-shadow: 0 0 0 5px rgba(78, 167, 122, 0.13);
}
.key-row {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 9px;
min-height: 32px;
border-top: 1px solid var(--line);
font-size: 12px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.key-row strong {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
letter-spacing: 0.08em;
}
.key-row strong.present {
color: #4d8b68;
}
.key-row strong.absent {
color: #b55f51;
}
#ledger-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#controls {
left: 50%;
bottom: 20px;
width: min(650px, calc(100vw - 40px));
padding: 14px;
transform: translateX(-50%);
border-radius: 16px;
}
.control-row {
display: flex;
align-items: center;
gap: 9px;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(23, 35, 44, 0.15);
border-radius: 9px;
background: #fff;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #f1eee5;
}
button.primary {
border-color: #20313c;
background: #20313c;
color: #fff;
}
button.primary:hover {
background: #314653;
}
#timeline {
width: 100%;
margin: 13px 0 0;
accent-color: #bd7b3f;
cursor: pointer;
}
.time-row {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
}
#camera-help {
position: fixed;
right: 20px;
bottom: 22px;
z-index: 8;
color: rgba(23, 35, 44, 0.62);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 820px) {
#intro {
top: 12px;
left: 12px;
width: 280px;
padding: 15px;
}
#intro p {
display: none;
}
#ledger {
top: 12px;
right: 12px;
width: 235px;
padding: 13px;
}
#ledger-note {
display: none;
}
#controls {
bottom: 12px;
width: calc(100vw - 24px);
}
#camera-help {
display: none;
}
}
@media (max-width: 560px) {
#ledger {
top: auto;
right: 12px;
bottom: 136px;
width: 210px;
}
#intro {
width: calc(100vw - 24px);
}
#phase {
margin-top: 10px;
}
button {
padding: 0 10px;
}
}
</style>
</head>
<body>
<section id="intro" class="panel">
<p class="eyebrow">Curator Operations / 04</p>
<h1>Miniature Museum</h1>
<p>
Follow the caretaker through the opening route. Each gallery door is
unlocked in sequence while the key cabinet records the missing key.
</p>
<div id="phase">CABINET · Preparing the opening route</div>
</section>
<aside id="ledger" class="panel">
<div class="ledger-title">
<strong>Cabinet ledger</strong>
<span class="live-dot"></span>
</div>
<div class="key-row">
<span class="swatch" style="background:#d69b3d"></span>
<span>Gallery I · Antiquity</span>
<strong id="keyState0">PRESENT</strong>
</div>
<div class="key-row">
<span class="swatch" style="background:#d96b5f"></span>
<span>Gallery II · Chroma</span>
<strong id="keyState1">PRESENT</strong>
</div>
<div class="key-row">
<span class="swatch" style="background:#3da39a"></span>
<span>Gallery III · Nature</span>
<strong id="keyState2">PRESENT</strong>
</div>
<div class="key-row">
<span class="swatch" style="background:#8067c7"></span>
<span>Gallery IV · Futures</span>
<strong id="keyState3">PRESENT</strong>
</div>
<p id="ledger-note">
The physical status board on the cabinet mirrors this ledger.
</p>
</aside>
<section id="controls" class="panel">
<div class="control-row">
<button id="playPause" class="primary">Pause route</button>
<button id="replay">Replay</button>
<button id="speed">Speed 1×</button>
<input id="timeline" type="range" min="0" max="26.4" step="0.01" value="0" />
</div>
<div class="time-row">
<span id="elapsed">00:00</span>
<span id="routeLabel">OPENING ROUTE</span>
<span>00:26</span>
</div>
</section>
<div id="camera-help">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e4e8);
scene.fog = new THREE.Fog(0xd9e4e8, 62, 105);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive miniature museum");
document.body.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemisphere = new THREE.HemisphereLight(0xf5fbff, 0x9b8064, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d7, 3.25);
sun.position.set(-16, 30, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9ef, 0.8);
fill.position.set(25, 12, -18);
scene.add(fill);
const materialCache = new Map();
const geometryCache = new Map();
function standardMaterial(color, options = {}) {
const key = String(color) + JSON.stringify(options);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
})
);
}
return materialCache.get(key);
}
function boxGeometry(w, h, d) {
const key = `${w},${h},${d}`;
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(w, h, d));
}
return geometryCache.get(key);
}
function box(parent, w, h, d, x, y, z, color, options = {}) {
const material =
color && color.isMaterial
? color
: standardMaterial(color, options);
const mesh = new THREE.Mesh(boxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, width = 5, height = 0.8, background = "#263844") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#fff8e8";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
let fontSize = 58;
ctx.font = `700 ${fontSize}px monospace`;
while (ctx.measureText(text).width > 930 && fontSize > 20) {
fontSize -= 2;
ctx.font = `700 ${fontSize}px monospace`;
}
ctx.fillText(text, 512, 84);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
transparent: true
});
return new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
}
function voxelKey(color) {
const group = new THREE.Group();
const keyMat = standardMaterial(color, {
roughness: 0.48,
metalness: 0.18,
emissive: color,
emissiveIntensity: 0.08
});
// Square ring.
box(group, 0.34, 0.075, 0.09, 0, 0.15, 0, keyMat);
box(group, 0.34, 0.075, 0.09, 0, -0.075, 0, keyMat);
box(group, 0.075, 0.225, 0.09, -0.1325, 0.0375, 0, keyMat);
box(group, 0.075, 0.225, 0.09, 0.1325, 0.0375, 0, keyMat);
// Stem and teeth.
box(group, 0.075, 0.34, 0.09, 0, -0.28, 0, keyMat);
box(group, 0.15, 0.065, 0.09, 0.052, -0.38, 0, keyMat);
box(group, 0.13, 0.065, 0.09, 0.045, -0.49, 0, keyMat);
return group;
}
// -------------------------------------------------------------------------
// Architecture
// -------------------------------------------------------------------------
const museum = new THREE.Group();
scene.add(museum);
const FLOOR_Y = 0.38;
const FRONT_Z = 0.9;
const ROOM_Z = -3.3;
box(museum, 39, 1.05, 22, 0, -0.58, 0.2, 0x526b78);
box(museum, 38.5, 0.2, 21.5, 0, -0.05, 0.2, 0x8196a0);
box(museum, 35.4, 0.3, 18.2, 0, 0.15, 0.2, 0xe9e4d8);
// Corridor and floor title.
box(museum, 34, 0.09, 7.2, 0, 0.34, 5, 0xf2eee2);
const floorTitle = makeLabel("MINI MUSEUM / OPENING ROUTE", 8.4, 0.72, "#334b58");
floorTitle.rotation.x = -Math.PI / 2;
floorTitle.position.set(1.1, 0.402, 8.55);
museum.add(floorTitle);
const galleryData = [
{
id: "I",
x: -12.6,
name: "ANTIQUITY",
full: "Gallery I · Antiquity",
color: 0xd69b3d,
floor: 0xe9dcc2
},
{
id: "II",
x: -4.2,
name: "CHROMA",
full: "Gallery II · Chroma",
color: 0xd96b5f,
floor: 0xf0d8d2
},
{
id: "III",
x: 4.2,
name: "NATURE",
full: "Gallery III · Nature",
color: 0x3da39a,
floor: 0xd4e6df
},
{
id: "IV",
x: 12.6,
name: "FUTURES",
full: "Gallery IV · Futures",
color: 0x8067c7,
floor: 0xded9ee
}
];
const doors = [];
for (const gallery of galleryData) {
const { x } = gallery;
// Floor.
box(museum, 7.4, 0.08, 8.4, x, 0.36, ROOM_Z, gallery.floor);
// Back and cutaway side walls.
box(museum, 7.4, 4.2, 0.28, x, 2.43, -7.5, 0xf6f2e8);
box(museum, 0.24, 2.35, 8.4, x - 3.7, 1.5, ROOM_Z, 0xdedbd2);
box(museum, 0.24, 2.35, 8.4, x + 3.7, 1.5, ROOM_Z, 0xdedbd2);
// Front wall with a central doorway.
const sideWidth = 2.43;
const sideOffset = 2.47;
box(museum, sideWidth, 3.2, 0.28, x - sideOffset, 1.93, FRONT_Z, 0xf0ede5);
box(museum, sideWidth, 3.2, 0.28, x + sideOffset, 1.93, FRONT_Z, 0xf0ede5);
box(museum, 2.55, 0.48, 0.28, x, 3.25, FRONT_Z, 0xf0ede5);
// Accent plinth strip.
box(museum, 7.3, 0.24, 0.36, x, 0.55, FRONT_Z + 0.04, gallery.color);
// Door frame.
box(museum, 0.16, 2.72, 0.38, x - 1.32, 1.73, FRONT_Z, gallery.color);
box(museum, 0.16, 2.72, 0.38, x + 1.32, 1.73, FRONT_Z, gallery.color);
box(museum, 2.8, 0.16, 0.38, x, 3.02, FRONT_Z, gallery.color);
// Door pivot at the left hinge.
const doorWidth = 2.48;
const doorHeight = 2.62;
const pivot = new THREE.Group();
pivot.position.set(x - doorWidth / 2, FLOOR_Y, FRONT_Z);
museum.add(pivot);
const doorMat = standardMaterial(0x344a56, { roughness: 0.68 });
box(pivot, doorWidth, doorHeight, 0.22, doorWidth / 2, doorHeight / 2, 0, doorMat);
box(
pivot,
doorWidth - 0.32,
0.18,
0.27,
doorWidth / 2,
doorHeight - 0.35,
0,
gallery.color
);
box(
pivot,
0.18,
0.56,
0.32,
doorWidth - 0.23,
1.25,
0,
standardMaterial(0xf4d58a, { metalness: 0.35, roughness: 0.4 })
);
// The key left in the gallery lock after use.
const doorKey = voxelKey(gallery.color);
doorKey.scale.setScalar(0.34);
doorKey.position.set(doorWidth - 0.24, 1.25, 0.2);
doorKey.visible = false;
pivot.add(doorKey);
// Door status light.
const lampMat = new THREE.MeshStandardMaterial({
color: 0x59666c,
emissive: 0x000000,
roughness: 0.5
});
box(museum, 0.4, 0.18, 0.18, x, 3.33, FRONT_Z + 0.24, lampMat);
const plaque = makeLabel(`GALLERY ${gallery.id} / ${gallery.name}`, 5.7, 0.82);
plaque.position.set(x, 3.46, -7.34);
museum.add(plaque);
doors.push({
pivot,
lampMat,
doorKey,
open: 0
});
}
// -------------------------------------------------------------------------
// Gallery exhibits — all built from visible blocks
// -------------------------------------------------------------------------
// Gallery I: stepped pedestal and block statue.
{
const x = -12.6;
box(museum, 3.2, 0.45, 2.9, x, 0.65, -3.55, 0xb8b4aa);
box(museum, 2.55, 0.38, 2.3, x, 1.05, -3.55, 0xcec8ba);
box(museum, 1.25, 1.1, 0.9, x, 1.76, -3.55, 0x817d76);
box(museum, 0.68, 0.68, 0.68, x, 2.63, -3.55, 0xd3c09f);
box(museum, 1.7, 0.28, 0.5, x, 1.93, -3.55, 0x817d76);
box(museum, 0.35, 1.15, 0.45, x - 1.25, 1.88, -3.5, 0xa69f90);
box(museum, 0.35, 1.15, 0.45, x + 1.25, 1.88, -3.5, 0xa69f90);
box(museum, 0.58, 0.25, 0.1, x, 2.62, -3.18, 0x3e4649);
}
// Gallery II: colored blocks.
{
const x = -4.2;
const colors = [0xe46f62, 0xe7b94f, 0x4ca9a2, 0x6b72bb];
for (let i = 0; i < 4; i++) {
const px = x - 1.35 + i * 0.9;
box(museum, 0.72, 0.45, 0.72, px, 0.65, -3.55, 0xf0ede4);
box(museum, 0.48, 0.75 + (i % 2) * 0.45, 0.48, px, 1.24 + (i % 2) * 0.22, -3.55, colors[i]);
box(museum, 0.72, 0.18, 0.72, px, 1.78 + (i % 2) * 0.45, -3.55, colors[(i + 1) % 4]);
}
box(museum, 5.2, 0.16, 0.3, x, 0.58, -5.25, 0x5f6870);
}
// Gallery III: voxel tree and rocks.
{
const x = 4.2;
box(museum, 4.1, 0.22, 3.1, x, 0.53, -3.65, 0xb8c8a8);
box(museum, 0.55, 1.7, 0.55, x - 0.25, 1.48, -3.7, 0x87674d);
box(museum, 1.65, 0.78, 1.25, x - 0.25, 2.32, -3.7, 0x4c9270);
box(museum, 1.05, 0.7, 0.95, x + 0.75, 2.0, -3.55, 0x63a681);
box(museum, 0.72, 0.58, 0.68, x - 1.35, 0.92, -3.15, 0x9eaaa3);
box(museum, 0.9, 0.36, 0.68, x + 1.25, 0.82, -4.25, 0x879991);
box(museum, 0.42, 0.8, 0.4, x + 0.15, 0.94, -2.45, 0x5f8f72);
}
// Gallery IV: futuristic stacked forms.
{
const x = 12.6;
box(museum, 3.4, 0.35, 2.7, x, 0.6, -3.55, 0xd6d0e5);
box(museum, 1.7, 0.45, 1.2, x, 0.98, -3.55, 0x715fa8);
box(museum, 1.15, 0.85, 0.85, x, 1.62, -3.55, 0x8d79cb);
box(museum, 0.65, 0.65, 0.65, x, 2.35, -3.55, 0x65c5cf, {
emissive: 0x327e88,
emissiveIntensity: 0.35
});
box(museum, 2.55, 0.16, 0.16, x, 2.45, -3.55, 0x4d5871);
box(museum, 0.16, 0.16, 1.8, x - 1.18, 2.45, -3.55, 0x4d5871);
box(museum, 0.16, 0.16, 1.8, x + 1.18, 2.45, -3.55, 0x4d5871);
}
// -------------------------------------------------------------------------
// Key cabinet with physical absence display
// -------------------------------------------------------------------------
const cabinet = new THREE.Group();
cabinet.position.set(-14.6, FLOOR_Y, 6.5);
museum.add(cabinet);
const cabinetDark = standardMaterial(0x344650);
const cabinetInside = standardMaterial(0x26343b);
box(cabinet, 4.05, 0.18, 1.25, 0, 0.12, 0, cabinetDark);
box(cabinet, 4.05, 0.18, 1.25, 0, 3.03, 0, cabinetDark);
box(cabinet, 0.18, 2.9, 1.25, -1.93, 1.57, 0, cabinetDark);
box(cabinet, 0.18, 2.9, 1.25, 1.93, 1.57, 0, cabinetDark);
box(cabinet, 4.05, 2.9, 0.16, 0, 1.57, -0.58, cabinetInside);
const cabinetLabel = makeLabel("KEY CABINET / ABSENCE LOG", 3.75, 0.58, "#223640");
cabinetLabel.position.set(0, 3.32, 0.69);
cabinet.add(cabinetLabel);
const cabinetKeys = [];
const cabinetLeds = [];
const keyPositions = [
[-1.38, 2.28],
[-0.62, 2.28],
[-1.38, 1.38],
[-0.62, 1.38]
];
for (let i = 0; i < 4; i++) {
const [x, y] = keyPositions[i];
box(cabinet, 0.16, 0.16, 0.18, x, y + 0.19, 0.32, 0x819099);
const key = voxelKey(galleryData[i].color);
key.position.set(x, y, 0.38);
cabinet.add(key);
cabinetKeys.push(key);
const ledMat = new THREE.MeshStandardMaterial({
color: galleryData[i].color,
emissive: galleryData[i].color,
emissiveIntensity: 0.62,
roughness: 0.42
});
const ledX = 1.12 + (i % 2) * 0.45;
const ledY = 1.95 - Math.floor(i / 2) * 0.65;
box(cabinet, 0.31, 0.31, 0.12, ledX, ledY, 0.4, ledMat);
cabinetLeds.push(ledMat);
}
// Small ledger board behind the indicator lights.
box(cabinet, 1.25, 1.75, 0.1, 1.35, 1.62, 0.25, 0x17262d);
// -------------------------------------------------------------------------
// Caretaker
// -------------------------------------------------------------------------
const caretaker = new THREE.Group();
caretaker.position.set(-14.6, FLOOR_Y, 8.15);
museum.add(caretaker);
const uniform = standardMaterial(0x2c6c79);
const uniformDark = standardMaterial(0x214c59);
const skin = standardMaterial(0xe5b68c);
const trousers = standardMaterial(0x33424a);
const shoes = standardMaterial(0x1d252a);
box(caretaker, 0.72, 0.78, 0.42, 0, 1.08, 0, uniform);
box(caretaker, 0.76, 0.15, 0.46, 0, 0.76, 0, uniformDark);
box(caretaker, 0.62, 0.62, 0.58, 0, 1.78, 0, skin);
box(caretaker, 0.69, 0.16, 0.64, 0, 2.08, 0.01, uniformDark);
box(caretaker, 0.53, 0.11, 0.32, 0, 2.08, 0.28, uniformDark);
// Eyes and nose establish the forward direction.
box(caretaker, 0.08, 0.09, 0.04, -0.15, 1.83, 0.30, 0x263139);
box(caretaker, 0.08, 0.09, 0.04, 0.15, 1.83, 0.30, 0x263139);
box(caretaker, 0.13, 0.13, 0.13, 0, 1.69, 0.34, skin);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.2, 0.58, 0);
rightLeg.position.set(0.2, 0.58, 0);
caretaker.add(leftLeg, rightLeg);
box(leftLeg, 0.23, 0.44, 0.24, 0, -0.22, 0, trousers);
box(rightLeg, 0.23, 0.44, 0.24, 0, -0.22, 0, trousers);
box(leftLeg, 0.27, 0.12, 0.38, 0, -0.48, 0.06, shoes);
box(rightLeg, 0.27, 0.12, 0.38, 0, -0.48, 0.06, shoes);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.47, 1.39, 0);
rightArm.position.set(0.47, 1.39, 0);
caretaker.add(leftArm, rightArm);
box(leftArm, 0.19, 0.45, 0.2, 0, -0.22, 0, uniform);
box(rightArm, 0.19, 0.45, 0.2, 0, -0.22, 0, uniform);
box(leftArm, 0.2, 0.18, 0.2, 0, -0.5, 0, skin);
box(rightArm, 0.2, 0.18, 0.2, 0, -0.5, 0, skin);
// Carried keys are shown while the caretaker crosses to each door.
const carriedKeys = [];
for (let i = 0; i < 4; i++) {
const key = voxelKey(galleryData[i].color);
key.scale.setScalar(0.42);
key.position.set(0.54, 1.05, 0.35);
key.visible = false;
caretaker.add(key);
carriedKeys.push(key);
}
// -------------------------------------------------------------------------
// Route markers
// -------------------------------------------------------------------------
const cabinetStop = new THREE.Vector3(-14.6, FLOOR_Y, 8.15);
galleryData.forEach((gallery, i) => {
const doorStop = new THREE.Vector3(gallery.x, FLOOR_Y, 2.55);
for (let s = 0; s < 10; s++) {
const t = s / 10;
const marker = new THREE.Vector3().lerpVectors(cabinetStop, doorStop, t);
marker.y = FLOOR_Y + 0.025;
const markerMat = standardMaterial(gallery.color, {
transparent: true,
opacity: 0.42,
roughness: 1
});
box(
museum,
0.13,
0.035,
0.32,
marker.x,
marker.y,
marker.z,
markerMat
);
}
box(
museum,
0.55,
0.04,
0.55,
gallery.x,
FLOOR_Y + 0.02,
2.55,
standardMaterial(gallery.color, { transparent: true, opacity: 0.62 })
);
});
// -------------------------------------------------------------------------
// Timeline and animation
// -------------------------------------------------------------------------
const CYCLE = 6.6;
const TOTAL = CYCLE * 4;
let routeTime = 0;
let running = true;
let speed = 1;
const playPause = document.getElementById("playPause");
const replay = document.getElementById("replay");
const speedButton = document.getElementById("speed");
const timeline = document.getElementById("timeline");
const phaseElement = document.getElementById("phase");
const elapsedElement = document.getElementById("elapsed");
const keyStateElements = galleryData.map(
(_, i) => document.getElementById(`keyState${i}`)
);
function clamp01(v) {
return Math.max(0, Math.min(1, v));
}
function smoothstep(v) {
const x = clamp01(v);
return x * x * (3 - 2 * x);
}
function angleLerp(a, b, amount) {
const difference = Math.atan2(Math.sin(b - a), Math.cos(b - a));
return a + difference * amount;
}
function formatTime(seconds) {
const whole = Math.floor(seconds);
const minutes = Math.floor(whole / 60);
const remainder = whole % 60;
return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
}
function setText(element, value) {
if (element.textContent !== value) {
element.textContent = value;
}
}
function updateRoute(time) {
timeline.value = String(time);
elapsedElement.textContent = formatTime(time);
let phase = "OPENING ROUTE · COMPLETE";
if (time < TOTAL) {
const cycleIndex = Math.min(3, Math.floor(time / CYCLE));
const localTime = time - cycleIndex * CYCLE;
const gallery = galleryData[cycleIndex];
if (localTime < 0.4) {
phase = `CABINET · Taking the ${gallery.id} key`;
} else if (localTime < 2.6) {
phase = `TRANSIT · Walking to Gallery ${gallery.id}`;
} else if (localTime < 4.2) {
phase = `GALLERY ${gallery.id} · Opening the door`;
} else {
phase = `RETURN · Heading back to the key cabinet`;
}
}
setText(phaseElement, phase);
// Doors and their status lamps.
galleryData.forEach((gallery, i) => {
const base = i * CYCLE;
const openStart = base + 2.8;
const openEnd = base + 4.2;
const progress = smoothstep((time - openStart) / (openEnd - openStart));
doors[i].open = progress;
doors[i].pivot.rotation.y = progress * Math.PI * 0.47;
const lamp = doors[i].lampMat;
if (time >= openEnd) {
lamp.color.setHex(gallery.color);
lamp.emissive.setHex(gallery.color);
lamp.emissiveIntensity = 0.72;
} else if (time >= openStart) {
lamp.color.setHex(gallery.color);
lamp.emissive.setHex(gallery.color);
lamp.emissiveIntensity = 0.25 + progress * 0.45;
} else {
lamp.color.setHex(0x59666c);
lamp.emissive.setHex(0x000000);
lamp.emissiveIntensity = 0;
}
doors[i].doorKey.visible = time >= openStart;
// Cabinet key removal.
const removal = clamp01((time - (base + 0.05)) / 0.25);
cabinetKeys[i].scale.setScalar(1 - removal);
cabinetKeys[i].visible = removal < 0.999;
const absent = time >= base + 0.3;
const led = cabinetLeds[i];
if (absent) {
led.color.setHex(0x26343b);
led.emissive.setHex(0x000000);
led.emissiveIntensity = 0;
} else {
led.color.setHex(gallery.color);
led.emissive.setHex(gallery.color);
led.emissiveIntensity = 0.62;
}
const state = keyStateElements[i];
state.textContent = absent ? "ABSENT" : "PRESENT";
state.className = absent ? "absent" : "present";
});
// Caretaker route.
let position = cabinetStop.clone();
let desiredHeading = Math.PI;
let walking = false;
let walkClock = 0;
let unlocking = false;
if (time < TOTAL) {
const cycleIndex = Math.min(3, Math.floor(time / CYCLE));
const localTime = time - cycleIndex * CYCLE;
const gallery = galleryData[cycleIndex];
const doorStop = new THREE.Vector3(gallery.x, FLOOR_Y, 2.55);
if (localTime < 0.4) {
position.copy(cabinetStop);
desiredHeading = Math.PI;
} else if (localTime < 2.6) {
const u = (localTime - 0.4) / 2.2;
position.lerpVectors(cabinetStop, doorStop, u);
desiredHeading = Math.atan2(
doorStop.x - cabinetStop.x,
doorStop.z - cabinetStop.z
);
walking = true;
walkClock = (localTime - 0.4) * 8;
} else if (localTime < 4.2) {
position.copy(doorStop);
desiredHeading = Math.PI;
unlocking = true;
} else if (localTime < CYCLE) {
const u = (localTime - 4.4) / 2.2;
position.lerpVectors(doorStop, cabinetStop, u);
desiredHeading = Math.atan2(
cabinetStop.x - doorStop.x,
cabinetStop.z - doorStop.z
);
walking = true;
walkClock = (localTime - 4.4) * 8;
}
// Carried key visibility.
carriedKeys.forEach((key, i) => {
const base = i * CYCLE;
key.visible = time >= base + 0.3 && time < base + 2.8;
});
} else {
position.copy(cabinetStop);
desiredHeading = Math.PI;
carriedKeys.forEach((key) => (key.visible = false));
}
caretaker.position.x = position.x;
caretaker.position.z = position.z;
caretaker.position.y =
FLOOR_Y + (walking ? Math.abs(Math.sin(walkClock)) * 0.045 : 0);
caretaker.rotation.y = angleLerp(
caretaker.rotation.y,
desiredHeading,
0.16
);
const legSwing = walking ? Math.sin(walkClock) * 0.55 : 0;
leftLeg.rotation.x = legSwing;
rightLeg.rotation.x = -legSwing;
leftArm.rotation.x = walking ? -legSwing * 0.7 : 0;
rightArm.rotation.x = unlocking ? -1.18 : walking ? legSwing * 0.7 : 0;
}
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
playPause.addEventListener("click", () => {
if (routeTime >= TOTAL) {
routeTime = 0;
running = true;
} else {
running = !running;
}
updatePlayButton();
});
function updatePlayButton() {
playPause.textContent =
routeTime >= TOTAL ? "Play again" : running ? "Pause route" : "Resume route";
}
replay.addEventListener("click", () => {
routeTime = 0;
running = true;
updatePlayButton();
});
speedButton.addEventListener("click", () => {
speed = speed === 1 ? 2 : 1;
speedButton.textContent = `Speed ${speed}×`;
});
timeline.addEventListener("input", () => {
routeTime = Number(timeline.value);
running = false;
updatePlayButton();
});
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.05, -0.25);
const view = {
theta: 0.72,
phi: 0.82,
radius: 48
};
const desiredView = { ...view };
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 dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredView.theta -= dx * 0.006;
desiredView.phi = Math.max(
0.42,
Math.min(1.28, desiredView.phi + dy * 0.005)
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
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();
desiredView.radius = Math.max(
30,
Math.min(70, desiredView.radius * Math.exp(event.deltaY * 0.001))
);
},
{ passive: false }
);
function updateCamera() {
view.theta = angleLerp(view.theta, desiredView.theta, 0.12);
view.phi = angleLerp(view.phi, desiredView.phi, 0.12);
view.radius = angleLerp(view.radius, desiredView.radius, 0.12);
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + view.radius * sinPhi * Math.sin(view.theta),
cameraTarget.y + view.radius * Math.cos(view.phi),
cameraTarget.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(cameraTarget);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
updateRoute(0);
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
routeTime = Math.min(TOTAL, routeTime + delta * speed);
if (routeTime >= TOTAL) {
running = false;
updatePlayButton();
}
}
updateRoute(routeTime);
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```