Prompt specification
Build or customize the Three.js 3D scene "Moving box room-label system" 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: Moving box room-label system
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/moving-box-room-label-system-x3881
Scene Description Prompt:
Three stylized moving boxes with visible contents and room symbols matching miniature doorways. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (moving-box-room-label-system-x3881):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Packed Worlds — Three Moving Boxes</title>
<style>
:root {
--ink: #263b36;
--muted: #65756e;
--paper: #fffaf1;
--accent: #de745c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee9df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.title {
position: fixed;
top: 28px;
left: 32px;
z-index: 5;
max-width: 430px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 5vw, 64px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 330px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.room-card {
position: fixed;
left: 28px;
bottom: 28px;
z-index: 6;
width: min(310px, calc(100vw - 56px));
padding: 17px 19px;
border: 1px solid rgba(38, 59, 54, 0.12);
border-radius: 18px;
background: rgba(255, 250, 241, 0.88);
box-shadow: 0 18px 45px rgba(55, 68, 61, 0.12);
backdrop-filter: blur(14px);
pointer-events: none;
}
.room-card .number {
display: block;
margin-bottom: 6px;
color: var(--card-accent, var(--accent));
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.room-card strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
}
.room-card p {
margin: 6px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.controls {
position: fixed;
right: 25px;
bottom: 25px;
z-index: 8;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid rgba(38, 59, 54, 0.12);
border-radius: 999px;
background: rgba(255, 250, 241, 0.9);
box-shadow: 0 15px 40px rgba(55, 68, 61, 0.13);
backdrop-filter: blur(14px);
}
.controls button {
display: grid;
width: 38px;
height: 38px;
padding: 0;
place-items: center;
border: 0;
border-radius: 50%;
background: transparent;
color: var(--ink);
cursor: pointer;
font: 700 20px/1 system-ui, sans-serif;
transition: background 160ms ease, transform 160ms ease;
}
.controls button:hover {
background: rgba(38, 59, 54, 0.09);
transform: translateY(-1px);
}
.controls .reset {
width: auto;
padding: 0 16px;
border-radius: 999px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
}
.hint {
position: fixed;
top: 30px;
right: 30px;
z-index: 5;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #eee9df;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
transition: opacity 600ms ease, visibility 600ms ease;
}
#loading.done {
visibility: hidden;
opacity: 0;
}
@media (max-width: 700px) {
.title {
top: 20px;
left: 20px;
}
.subtitle,
.hint {
display: none;
}
.room-card {
left: 18px;
bottom: 78px;
width: 230px;
}
.controls {
right: 16px;
bottom: 16px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="title">
<div class="eyebrow">A miniature moving story</div>
<h1>Packed<br>Worlds</h1>
<p class="subtitle">
Three open moving boxes, each holding a small room and a doorway
marked with its own symbol.
</p>
</header>
<div class="hint">Drag to orbit · Scroll to zoom · Tap a box</div>
<aside class="room-card" id="roomCard">
<span class="number" id="cardNumber">Three worlds · one collection</span>
<strong id="cardTitle">Choose a moving box</strong>
<p id="cardCopy">
Each front label matches the symbol above its miniature doorway.
</p>
</aside>
<nav class="controls" aria-label="Camera controls">
<button id="zoomOut" aria-label="Zoom out">−</button>
<button id="zoomIn" aria-label="Zoom in">+</button>
<button id="reset" class="reset">Reset view</button>
</nav>
<div id="loading">Packing the little worlds…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const host = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9df);
scene.fog = new THREE.Fog(0xeee9df, 18, 38);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(
0xfff8ec,
0x9cafad,
2.25
);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff4dd, 3.4);
key.position.set(-5, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -10;
key.shadow.camera.right = 10;
key.shadow.camera.top = 9;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 30;
key.shadow.bias = -0.0005;
key.shadow.normalBias = 0.025;
scene.add(key);
const rim = new THREE.DirectionalLight(0xc8e6e4, 1.45);
rim.position.set(6, 5, -6);
scene.add(rim);
const frontFill = new THREE.PointLight(0xffe8cf, 22, 18, 2);
frontFill.position.set(0, 5, 7);
scene.add(frontFill);
// -------------------------------------------------------------------------
// Shared helpers
// -------------------------------------------------------------------------
const cardboardColors = [0xd8ad72, 0xd3a36a, 0xdcb47d];
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x8b6847,
transparent: true,
opacity: 0.42
});
const cardboardMaterials = cardboardColors.map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
})
);
const interiorMaterial = new THREE.MeshStandardMaterial({
color: 0xb98a58,
roughness: 0.94
});
const tapeMaterial = new THREE.MeshStandardMaterial({
color: 0xf0cf99,
roughness: 0.62,
transparent: true,
opacity: 0.66,
depthWrite: false
});
const paperMaterial = new THREE.MeshStandardMaterial({
color: 0xfff7e9,
roughness: 0.94
});
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0,
...options
});
}
function addEdges(mesh, opacity = 0.35) {
const material = edgeMaterial.clone();
material.opacity = opacity;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
material
);
mesh.add(edges);
return mesh;
}
function addBox(parent, size, position, material, edges = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (edges) addEdges(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
segments = 28
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, scale, position, material) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(1, 24, 16),
material
);
mesh.scale.set(scale[0], scale[1], scale[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedPath(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + width - r, y);
context.quadraticCurveTo(x + width, y, x + width, y + r);
context.lineTo(x + width, y + height - r);
context.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
context.lineTo(x + r, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
// All symbols are drawn with the same routine, ensuring the box labels
// and the plaques over the miniature doorways always match.
function drawRoomIcon(context, kind, cx, cy, size, color) {
context.save();
context.translate(cx, cy);
context.scale(size / 100, size / 100);
context.strokeStyle = color;
context.fillStyle = color;
context.lineWidth = 7;
context.lineCap = "round";
context.lineJoin = "round";
if (kind === "bed") {
context.beginPath();
context.moveTo(-38, 24);
context.lineTo(-38, -15);
context.lineTo(-29, -15);
context.lineTo(-29, -4);
context.lineTo(37, -4);
context.lineTo(37, 24);
context.stroke();
roundedPath(context, -30, -25, 25, 19, 6);
context.stroke();
context.beginPath();
context.moveTo(-38, 11);
context.lineTo(37, 11);
context.stroke();
context.beginPath();
context.moveTo(-31, 24);
context.lineTo(-31, 33);
context.moveTo(31, 24);
context.lineTo(31, 33);
context.stroke();
} else if (kind === "leaf") {
context.beginPath();
context.moveTo(-26, 32);
context.bezierCurveTo(-43, 2, -16, -34, 35, -31);
context.bezierCurveTo(38, 9, 13, 35, -26, 32);
context.stroke();
context.beginPath();
context.moveTo(-29, 33);
context.quadraticCurveTo(1, 6, 33, -29);
context.stroke();
context.beginPath();
context.moveTo(-5, 8);
context.lineTo(-5, -12);
context.moveTo(-5, 7);
context.lineTo(16, 2);
context.stroke();
} else if (kind === "bath") {
context.beginPath();
context.moveTo(-39, 0);
context.lineTo(-31, 28);
context.quadraticCurveTo(0, 38, 31, 28);
context.lineTo(39, 0);
context.closePath();
context.stroke();
context.beginPath();
context.moveTo(-36, 0);
context.quadraticCurveTo(0, -12, 36, 0);
context.stroke();
context.beginPath();
context.moveTo(-25, -3);
context.lineTo(-25, -23);
context.quadraticCurveTo(-25, -33, -15, -33);
context.lineTo(-7, -33);
context.stroke();
context.beginPath();
context.moveTo(10, -31);
context.bezierCurveTo(10, -18, 22, -18, 22, -31);
context.bezierCurveTo(22, -40, 10, -40, 10, -31);
context.fill();
}
context.restore();
}
function makeLabelTexture(room) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 384;
const context = canvas.getContext("2d");
roundedPath(context, 12, 12, 1000, 360, 30);
context.fillStyle = "#fff8e9";
context.fill();
context.strokeStyle = room.accentHex;
context.lineWidth = 12;
context.stroke();
context.beginPath();
context.arc(152, 192, 91, 0, Math.PI * 2);
context.fillStyle = room.accentHex;
context.fill();
drawRoomIcon(context, room.symbol, 152, 192, 95, "#fffaf2");
context.fillStyle = room.accentHex;
context.font = "800 25px system-ui, sans-serif";
context.letterSpacing = "4px";
context.fillText(room.kicker, 285, 102);
context.fillStyle = "#263b36";
context.font = "600 67px Georgia, serif";
context.fillText(room.name, 280, 200);
context.fillStyle = "#758078";
context.font = "700 25px system-ui, sans-serif";
context.letterSpacing = "3px";
context.fillText("PACKED MINIATURE ROOM", 285, 262);
context.fillStyle = room.accentHex;
roundedPath(context, 285, 295, 235, 9, 5);
context.fill();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeSymbolTexture(room) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
context.beginPath();
context.arc(128, 128, 112, 0, Math.PI * 2);
context.fillStyle = room.accentHex;
context.fill();
drawRoomIcon(context, room.symbol, 128, 128, 112, "#fffaf2");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// -------------------------------------------------------------------------
// Platform and floor
// -------------------------------------------------------------------------
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(
x + width, y, x + width, y + radius
);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(
x, y + height, x, y + height - radius
);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const platformGeometry = new THREE.ExtrudeGeometry(
roundedRectangleShape(11.2, 5.6, 0.55),
{
depth: 0.22,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.07,
bevelThickness: 0.06,
curveSegments: 16
}
);
const platform = new THREE.Mesh(
platformGeometry,
standard(0xcbd7cc, { roughness: 0.94 })
);
platform.rotation.x = -Math.PI / 2;
platform.position.y = -0.29;
platform.receiveShadow = true;
scene.add(platform);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
standard(0xeee9df, { roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.36;
ground.receiveShadow = true;
scene.add(ground);
// Small decorative floor stripes.
const stripeMaterial = standard(0xb8c8bd, {
roughness: 1,
transparent: true,
opacity: 0.65
});
[-4.2, 4.2].forEach((x) => {
addBox(
scene,
[0.035, 0.012, 4.6],
[x, -0.015, 0],
stripeMaterial,
false
);
});
// -------------------------------------------------------------------------
// Miniature arch geometry and doorways
// -------------------------------------------------------------------------
function archShape(width, height) {
const radius = width / 2;
const shape = new THREE.Shape();
shape.moveTo(-radius, 0);
shape.lineTo(radius, 0);
shape.lineTo(radius, height - radius);
shape.absarc(
0,
height - radius,
radius,
0,
Math.PI,
false
);
shape.lineTo(-radius, 0);
shape.closePath();
return shape;
}
const doorGlowMaterials = [];
function addMiniatureDoor(parent, room, x) {
const door = new THREE.Group();
door.position.set(x, 0.14, -0.7);
parent.add(door);
const frameGeometry = new THREE.ExtrudeGeometry(
archShape(0.76, 1.18),
{
depth: 0.13,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.025,
bevelThickness: 0.018,
curveSegments: 24
}
);
frameGeometry.translate(0, 0, -0.065);
const frame = new THREE.Mesh(
frameGeometry,
standard(room.accent, { roughness: 0.67 })
);
frame.castShadow = true;
frame.receiveShadow = true;
door.add(frame);
const opening = new THREE.Mesh(
new THREE.ShapeGeometry(archShape(0.55, 0.97), 24),
standard(room.dark, { roughness: 0.95 })
);
opening.position.z = 0.072;
door.add(opening);
const glowMaterial = new THREE.MeshBasicMaterial({
color: room.accent,
transparent: true,
opacity: 0.11,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const glow = new THREE.Mesh(
new THREE.ShapeGeometry(archShape(0.52, 0.94), 24),
glowMaterial
);
glow.position.z = 0.077;
door.add(glow);
doorGlowMaterials.push(glowMaterial);
addBox(
door,
[0.65, 0.055, 0.24],
[0, 0.025, 0.08],
standard(room.accent, { roughness: 0.7 }),
false
);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(0.38, 0.38),
new THREE.MeshBasicMaterial({
map: makeSymbolTexture(room),
transparent: true,
toneMapped: false
})
);
plaque.position.set(x, 1.45, -0.56);
parent.add(plaque);
const portalLight = new THREE.PointLight(room.accent, 0.85, 2.2, 2);
portalLight.position.set(x, 0.72, -0.43);
parent.add(portalLight);
}
// -------------------------------------------------------------------------
// Packing details
// -------------------------------------------------------------------------
function addPackingPaper(parent, x, z, scale = 1) {
const paper = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18 * scale, 1),
paperMaterial
);
paper.scale.set(1.2, 0.42, 0.9);
paper.position.set(x, 0.22, z);
paper.rotation.set(0.2, 0.4, 0.1);
paper.castShadow = true;
parent.add(paper);
}
function addCartonShell(root, index, room) {
const width = 2.6;
const height = 1.65;
const depth = 2.2;
const thickness = 0.085;
const cardboard = cardboardMaterials[index];
addBox(
root,
[width, thickness, depth],
[0, thickness / 2, 0],
interiorMaterial
);
addBox(
root,
[width, height, thickness],
[0, height / 2, depth / 2 - thickness / 2],
cardboard
);
addBox(
root,
[width, height, thickness],
[0, height / 2, -depth / 2 + thickness / 2],
cardboard
);
addBox(
root,
[thickness, height, depth - thickness * 2],
[-width / 2 + thickness / 2, height / 2, 0],
cardboard
);
addBox(
root,
[thickness, height, depth - thickness * 2],
[width / 2 - thickness / 2, height / 2, 0],
cardboard
);
// Four folded-open top flaps.
const frontFlap = addBox(
root,
[width, 0.065, 0.72],
[0, height, depth / 2 + 0.3],
cardboard
);
frontFlap.rotation.x = 0.62;
const backFlap = addBox(
root,
[width, 0.065, 0.72],
[0, height, -depth / 2 - 0.3],
cardboard
);
backFlap.rotation.x = -0.62;
const leftFlap = addBox(
root,
[0.72, 0.065, depth - 0.12],
[-width / 2 - 0.3, height, 0],
cardboard
);
leftFlap.rotation.z = 0.62;
const rightFlap = addBox(
root,
[0.72, 0.065, depth - 0.12],
[width / 2 + 0.3, height, 0],
cardboard
);
rightFlap.rotation.z = -0.62;
// Packing tape.
addBox(
root,
[0.18, height + 0.015, 0.018],
[0.83, height / 2, depth / 2 + 0.008],
tapeMaterial,
false
);
const frontTape = addBox(
root,
[0.18, 0.065, 0.63],
[0.83, height + 0.038, depth / 2 + 0.3],
tapeMaterial,
false
);
frontTape.rotation.x = 0.62;
// A dark hand slot on the front.
addBox(
root,
[0.47, 0.12, 0.025],
[0.83, 1.22, depth / 2 + 0.014],
standard(0x6f513b, { roughness: 1 }),
false
);
// The room label.
const label = new THREE.Mesh(
new THREE.PlaneGeometry(1.48, 0.555),
new THREE.MeshBasicMaterial({
map: makeLabelTexture(room),
toneMapped: false
})
);
label.position.set(-0.25, 0.73, depth / 2 + 0.019);
root.add(label);
// A little upward arrow beside the label.
const arrowCanvas = document.createElement("canvas");
arrowCanvas.width = 128;
arrowCanvas.height = 128;
const arrowContext = arrowCanvas.getContext("2d");
arrowContext.strokeStyle = "#75583f";
arrowContext.fillStyle = "#75583f";
arrowContext.lineWidth = 8;
arrowContext.lineCap = "round";
arrowContext.lineJoin = "round";
arrowContext.beginPath();
arrowContext.moveTo(64, 104);
arrowContext.lineTo(64, 25);
arrowContext.moveTo(35, 52);
arrowContext.lineTo(64, 23);
arrowContext.lineTo(93, 52);
arrowContext.stroke();
const arrowTexture = new THREE.CanvasTexture(arrowCanvas);
arrowTexture.colorSpace = THREE.SRGBColorSpace;
const arrow = new THREE.Mesh(
new THREE.PlaneGeometry(0.29, 0.29),
new THREE.MeshBasicMaterial({
map: arrowTexture,
transparent: true,
toneMapped: false
})
);
arrow.position.set(0.83, 0.72, depth / 2 + 0.02);
root.add(arrow);
}
// -------------------------------------------------------------------------
// Bedroom contents
// -------------------------------------------------------------------------
function addBedroom(root, room) {
addMiniatureDoor(root, room, 0.58);
const coral = standard(0xe78670);
const cream = standard(0xfff3da);
const blue = standard(0x7faeb4);
const wood = standard(0x9c6844);
const gold = standard(0xe4b85f);
const rug = new THREE.Mesh(
new THREE.CircleGeometry(0.57, 40),
standard(0x89adb0, { roughness: 1 })
);
rug.rotation.x = -Math.PI / 2;
rug.scale.set(1.15, 0.72, 1);
rug.position.set(-0.62, 0.135, 0.35);
rug.receiveShadow = true;
root.add(rug);
addBox(
root,
[1.06, 0.16, 0.72],
[-0.62, 0.25, 0.35],
coral
);
addBox(
root,
[1.03, 0.18, 0.68],
[-0.62, 0.42, 0.35],
cream
);
addBox(
root,
[0.68, 0.085, 0.69],
[-0.42, 0.535, 0.35],
blue
);
addBox(
root,
[0.35, 0.12, 0.28],
[-0.97, 0.56, 0.39],
cream
);
addBox(
root,
[0.09, 0.67, 0.74],
[-1.16, 0.53, 0.35],
wood
);
[-0.98, -0.28].forEach((x) => {
[-0.01, 0.71].forEach((z) => {
addBox(
root,
[0.07, 0.18, 0.07],
[x, 0.09, z],
wood,
false
);
});
});
// Tiny bedside lamp.
addCylinder(
root,
0.13,
0.15,
0.055,
[0.54, 0.17, 0.56],
gold
);
addCylinder(
root,
0.025,
0.025,
0.37,
[0.54, 0.36, 0.56],
gold,
16
);
const shade = new THREE.Mesh(
new THREE.ConeGeometry(0.22, 0.26, 28, 1, true),
standard(0xf4cf77, { side: THREE.DoubleSide })
);
shade.position.set(0.54, 0.64, 0.56);
shade.castShadow = true;
root.add(shade);
const lampLight = new THREE.PointLight(0xffd281, 1.0, 1.8, 2);
lampLight.position.set(0.54, 0.57, 0.6);
root.add(lampLight);
// Book on the floor.
addBox(
root,
[0.36, 0.055, 0.25],
[0.04, 0.19, 0.73],
standard(0xe9bf66),
false
).rotation.y = -0.18;
addPackingPaper(root, -1.04, -0.63, 0.9);
}
// -------------------------------------------------------------------------
// Greenhouse contents
// -------------------------------------------------------------------------
const swayingLeaves = [];
function addGreenhouse(root, room) {
addMiniatureDoor(root, room, -0.58);
const terracotta = standard(0xc87855);
const soil = standard(0x5f4934);
const stemMaterial = standard(0x52784c);
const leafMaterial = standard(0x719b5b);
const leafLight = standard(0x91b96d);
// Main pot.
addCylinder(
root,
0.25,
0.18,
0.35,
[0.52, 0.30, 0.28],
terracotta
);
addCylinder(
root,
0.225,
0.225,
0.025,
[0.52, 0.485, 0.28],
soil
);
addCylinder(
root,
0.025,
0.035,
0.68,
[0.52, 0.80, 0.28],
stemMaterial,
14
);
const leafData = [
[-0.16, 0.66, 0.02, 0.18, -0.25],
[0.16, 0.72, -0.02, 0.2, 0.25],
[-0.18, 0.89, 0.03, 0.22, -0.35],
[0.17, 0.98, -0.03, 0.19, 0.32],
[-0.12, 1.12, 0.02, 0.17, -0.2],
[0.08, 1.2, 0, 0.15, 0.15]
];
leafData.forEach((data, index) => {
const pivot = new THREE.Group();
pivot.position.set(
0.52 + data[0],
data[1],
0.28 + data[2]
);
root.add(pivot);
const leaf = addSphere(
pivot,
[0.25, 0.065, 0.13],
[0, 0, 0],
index % 2 ? leafMaterial : leafLight
);
leaf.rotation.z = data[3];
leaf.rotation.y = data[4];
swayingLeaves.push({
pivot,
phase: index * 0.7,
amount: 0.045 + (index % 2) * 0.018
});
});
// A stack of small empty pots.
[-0.57, -0.78].forEach((x, index) => {
addCylinder(
root,
0.22,
0.16,
0.28,
[x, 0.27 + index * 0.19, 0.52],
index ? standard(0xd9976e) : terracotta
);
});
// Watering can.
const canMaterial = standard(0x789a9b);
addCylinder(
root,
0.19,
0.2,
0.3,
[0.98, 0.3, 0.63],
canMaterial
);
const spout = addCylinder(
root,
0.045,
0.065,
0.38,
[0.78, 0.4, 0.63],
canMaterial,
14
);
spout.rotation.z = Math.PI / 2.6;
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.027, 10, 30),
canMaterial
);
handle.position.set(1.05, 0.39, 0.63);
handle.rotation.y = Math.PI / 2;
handle.castShadow = true;
root.add(handle);
addPackingPaper(root, 0.92, -0.59, 0.85);
}
// -------------------------------------------------------------------------
// Bathroom contents
// -------------------------------------------------------------------------
function addBathroom(root, room) {
addMiniatureDoor(root, room, 0.58);
const porcelain = standard(0xfff4df);
const aqua = standard(0x8cc5c5, { roughness: 0.42 });
const metal = standard(0xb5c4c1, {
roughness: 0.28,
metalness: 0.65
});
const coral = standard(0xe58a73);
// Miniature tub.
const tub = addCylinder(
root,
0.54,
0.43,
0.34,
[-0.57, 0.31, 0.35],
porcelain,
36
);
tub.scale.z = 0.68;
const water = addCylinder(
root,
0.46,
0.46,
0.025,
[-0.57, 0.49, 0.35],
aqua,
36
);
water.scale.z = 0.68;
addBox(
root,
[0.055, 0.27, 0.055],
[-0.57, 0.12, 0.35],
metal,
false
);
// Curved faucet.
const faucet = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.026, 10, 28, Math.PI),
metal
);
faucet.position.set(-0.57, 0.65, -0.05);
faucet.rotation.set(Math.PI / 2, 0, 0);
faucet.castShadow = true;
root.add(faucet);
addCylinder(
root,
0.025,
0.025,
0.19,
[-0.57, 0.53, -0.05],
metal,
14
);
// Rolled towels.
const towel = addCylinder(
root,
0.17,
0.17,
0.48,
[0.02, 0.36, 0.67],
coral,
28
);
towel.rotation.z = Math.PI / 2;
const towelCore = addCylinder(
root,
0.06,
0.06,
0.495,
[0.02, 0.36, 0.67],
paperMaterial,
20
);
towelCore.rotation.z = Math.PI / 2;
// Bath bottle.
addCylinder(
root,
0.11,
0.13,
0.29,
[-1.05, 0.3, 0.72],
standard(0xe7b85d)
);
addCylinder(
root,
0.05,
0.05,
0.08,
[-1.05, 0.48, 0.72],
standard(0xfff3d9),
16
);
addPackingPaper(root, 0.9, -0.55, 0.95);
}
// -------------------------------------------------------------------------
// Create the three boxes
// -------------------------------------------------------------------------
const rooms = [
{
name: "Bedroom",
symbol: "bed",
kicker: "ROOM 01 · REST",
accent: 0xe78670,
accentHex: "#e78670",
dark: 0x6f4c54,
copy: "A tiny bed, warm lamp, and a warm coral doorway."
},
{
name: "Greenhouse",
symbol: "leaf",
kicker: "ROOM 02 · GROW",
accent: 0x789b65,
accentHex: "#789b65",
dark: 0x3f5941,
copy: "Leafy plants, tiny pots, and a doorway into the green."
},
{
name: "Bathroom",
symbol: "bath",
kicker: "ROOM 03 · RESET",
accent: 0x6eb1b7,
accentHex: "#6eb1b7",
dark: 0x365d67,
copy: "A miniature tub, rolled towel, and a refreshing blue portal."
}
];
const cartonRoots = [];
function createRoom(index, room, x, z, rotation) {
const root = new THREE.Group();
root.position.set(x, 0, z);
root.rotation.y = rotation;
root.userData.room = room;
root.userData.index = index;
root.userData.baseScale = 1;
root.userData.targetScale = 1;
scene.add(root);
addCartonShell(root, index, room);
if (index === 0) addBedroom(root, room);
if (index === 1) addGreenhouse(root, room);
if (index === 2) addBathroom(root, room);
cartonRoots.push(root);
return root;
}
createRoom(0, rooms[0], -3.03, 0.05, -0.025);
createRoom(1, rooms[1], 0, -0.04, 0.018);
createRoom(2, rooms[2], 3.03, 0.06, 0.03);
// -------------------------------------------------------------------------
// Floating dust motes
// -------------------------------------------------------------------------
const dustCount = 90;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 12;
dustPositions[i * 3 + 1] = Math.random() * 4.7 + 0.4;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 7;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xfff7df,
size: 0.028,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const orbit = {
theta: 0.14,
phi: 0.58,
radius: window.innerWidth < 700 ? 22 : 11.7,
targetTheta: 0.14,
targetPhi: 0.58,
targetRadius: window.innerWidth < 700 ? 22 : 11.7
};
const focus = new THREE.Vector3(0, 1.05, 0);
const targetFocus = focus.clone();
const defaultRadius = window.innerWidth < 700 ? 22 : 11.7;
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let downX = 0;
let downY = 0;
let idleTime = 0;
let selectedRoot = null;
let hoveredRoot = null;
function updateCamera(delta) {
orbit.theta +=
(orbit.targetTheta - orbit.theta) *
Math.min(1, delta * 7);
orbit.phi +=
(orbit.targetPhi - orbit.phi) *
Math.min(1, delta * 7);
orbit.radius +=
(orbit.targetRadius - orbit.radius) *
Math.min(1, delta * 6);
focus.lerp(targetFocus, Math.min(1, delta * 6));
const horizontal = Math.cos(orbit.phi) * orbit.radius;
camera.position.set(
focus.x + Math.sin(orbit.theta) * horizontal,
focus.y + Math.sin(orbit.phi) * orbit.radius,
focus.z + Math.cos(orbit.theta) * horizontal
);
camera.lookAt(focus);
}
function resetCamera() {
orbit.targetTheta = 0.14;
orbit.targetPhi = 0.58;
orbit.targetRadius = defaultRadius;
targetFocus.set(0, 1.05, 0);
selectedRoot = null;
cartonRoots.forEach((root) => {
root.userData.targetScale = 1;
});
updateRoomCard(null);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
downX = event.clientX;
downY = event.clientY;
idleTime = 0;
renderer.domElement.setPointerCapture(pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging && event.pointerId === pointerId) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(
orbit.targetPhi + dy * 0.0045,
0.27,
1.08
);
lastX = event.clientX;
lastY = event.clientY;
idleTime = 0;
} else {
updatePointer(event);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const moved = Math.hypot(
event.clientX - downX,
event.clientY - downY
);
dragging = false;
renderer.domElement.releasePointerCapture(pointerId);
pointerId = null;
if (moved < 5) {
selectAt(event.clientX, event.clientY);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerId = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius + event.deltaY * 0.008,
6.5,
29
);
idleTime = 0;
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelector("#zoomIn").addEventListener("click", () => {
orbit.targetRadius = Math.max(6.5, orbit.targetRadius - 1);
idleTime = 0;
});
document.querySelector("#zoomOut").addEventListener("click", () => {
orbit.targetRadius = Math.min(29, orbit.targetRadius + 1);
idleTime = 0;
});
document.querySelector("#reset").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Raycasting and selection
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function roomFromObject(object) {
let current = object;
while (current) {
if (current.userData.room) return current;
current = current.parent;
}
return null;
}
function roomAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(cartonRoots, true);
for (const hit of hits) {
const root = roomFromObject(hit.object);
if (root) return root;
}
return null;
}
function updatePointer(event) {
const root = roomAt(event.clientX, event.clientY);
if (root !== hoveredRoot) {
hoveredRoot = root;
renderer.domElement.style.cursor = root ? "pointer" : "grab";
}
if (!selectedRoot) {
updateRoomCard(hoveredRoot);
}
}
function selectAt(clientX, clientY) {
const root = roomAt(clientX, clientY);
if (!root) {
resetCamera();
return;
}
selectedRoot = root;
targetFocus.set(root.position.x, 1.03, root.position.z);
orbit.targetRadius = window.innerWidth < 700 ? 15.5 : 8.3;
orbit.targetTheta = 0.08;
orbit.targetPhi = 0.52;
cartonRoots.forEach((carton) => {
carton.userData.targetScale =
carton === root ? 1.035 : 0.985;
});
updateRoomCard(root);
}
const card = document.querySelector("#roomCard");
const cardNumber = document.querySelector("#cardNumber");
const cardTitle = document.querySelector("#cardTitle");
const cardCopy = document.querySelector("#cardCopy");
function updateRoomCard(root) {
if (!root) {
card.style.setProperty("--card-accent", "#de745c");
cardNumber.textContent = "Three worlds · one collection";
cardTitle.textContent = "Choose a moving box";
cardCopy.textContent =
"Each front label matches the symbol above its miniature doorway.";
return;
}
const room = root.userData.room;
const number = String(root.userData.index + 1).padStart(2, "0");
card.style.setProperty("--card-accent", room.accentHex);
cardNumber.textContent = `${room.kicker} · BOX ${number}`;
cardTitle.textContent = room.name;
cardCopy.textContent = room.copy;
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (!dragging) idleTime += delta;
// A very slow automatic orbit resumes after interaction.
if (idleTime > 4 && !selectedRoot) {
orbit.targetTheta += delta * 0.022;
}
updateCamera(delta);
cartonRoots.forEach((root) => {
const target = root.userData.targetScale;
const next =
THREE.MathUtils.lerp(root.scale.x, target, 0.08);
root.scale.setScalar(next);
});
swayingLeaves.forEach((leaf) => {
leaf.pivot.rotation.z =
Math.sin(elapsed * 1.5 + leaf.phase) * leaf.amount;
leaf.pivot.rotation.x =
Math.cos(elapsed * 1.1 + leaf.phase) * leaf.amount * 0.65;
});
doorGlowMaterials.forEach((material, index) => {
material.opacity =
0.09 + Math.sin(elapsed * 1.6 + index * 1.7) * 0.025;
});
const positions = dust.geometry.attributes.position.array;
for (let i = 0; i < dustCount; i++) {
positions[i * 3 + 1] += delta * 0.025;
positions[i * 3] += Math.sin(elapsed * 0.25 + i) * delta * 0.004;
if (positions[i * 3 + 1] > 5.2) {
positions[i * 3 + 1] = 0.35;
}
}
dust.geometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// Let the first frame appear before removing the loading screen.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("done");
});
});
</script>
</body>
</html>
```