Prompt specification
Build or customize the Three.js 3D scene "Box follows its room label" 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: Box follows its room label
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/box-follows-its-room-label-x3882
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Animate one labeled box traveling from old shelf to trolley to new room; keep its symbol and contents unchanged through every transfer.
Working Three.js Starter (box-follows-its-room-label-x3882):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transfer Orbit — Three.js</title>
<style>
:root {
color-scheme: light;
--ink: #18312d;
--muted: #64736e;
--paper: rgba(250, 251, 247, 0.92);
--line: rgba(24, 49, 45, 0.14);
--teal: #167d70;
--amber: #e3a72f;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background: #e9eeea;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255,255,255,0.75);
box-shadow: 0 14px 40px rgba(27, 51, 46, 0.12);
backdrop-filter: blur(12px);
}
#title-card {
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--teal);
transform: rotate(45deg);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.manifest {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.manifest div {
min-width: 0;
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,0.55);
}
.manifest small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.manifest strong {
display: block;
overflow: hidden;
font-size: 12px;
text-overflow: ellipsis;
white-space: nowrap;
}
#transfer-card {
left: 22px;
bottom: 22px;
width: min(430px, calc(100vw - 44px));
padding: 15px 17px;
border-radius: 16px;
}
.transfer-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
#status {
font-size: 13px;
font-weight: 800;
letter-spacing: 0.01em;
}
.locked {
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.track {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: #dce4df;
}
#progress {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), #49a693);
transform: scaleX(0);
transform-origin: left center;
}
.controls {
display: flex;
gap: 8px;
margin-top: 12px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 9px;
padding: 8px 11px;
background: rgba(255,255,255,0.8);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 750;
}
button:hover { background: white; }
button:active { transform: translateY(1px); }
#help {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 10;
padding: 9px 12px;
border-radius: 10px;
background: rgba(250,251,247,0.78);
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 650px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle { display: none; }
.manifest { margin-top: 12px; }
#transfer-card {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
#help { display: none; }
}
</style>
</head>
<body>
<div id="title-card" class="panel">
<div class="eyebrow">Continuous transfer study</div>
<h1>Orbit-17</h1>
<p class="subtitle">
A single labeled container moves from the old storage shelf to the trolley,
across the facility, and into the new room.
</p>
<div class="manifest" aria-label="Unchanging box manifest">
<div>
<small>Identity</small>
<strong>ORBIT-17</strong>
</div>
<div>
<small>Symbol</small>
<strong>◆ Teal</strong>
</div>
<div>
<small>Contents</small>
<strong>3 fixed items</strong>
</div>
</div>
</div>
<div id="transfer-card" class="panel">
<div class="transfer-row">
<div id="status">01 · Old shelf</div>
<div class="locked">Manifest locked</div>
</div>
<div class="track"><div id="progress"></div></div>
<div class="controls">
<button id="play" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="camera" type="button">Reset camera</button>
</div>
</div>
<div id="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";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eeea);
scene.fog = new THREE.Fog(0xe9eeea, 19, 38);
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;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 1.0, 0);
let cameraTheta = 0.61;
let cameraPhi = 1.02;
let cameraRadius = 18.2;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
target.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
target.y + cameraRadius * Math.cos(cameraPhi),
target.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf8fbf4, 0x8c9a91, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff6dc, 3.3);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9e5, 1.0);
fill.position.set(8, 6, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xdfe6df, roughness: 0.96, flatShading: true
}),
oldFloor: new THREE.MeshStandardMaterial({
color: 0xd4ddd7, roughness: 0.95, flatShading: true
}),
newFloor: new THREE.MeshStandardMaterial({
color: 0xd9e6df, roughness: 0.95, flatShading: true
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x334743, roughness: 0.62, metalness: 0.42, flatShading: true
}),
shelfMetal: new THREE.MeshStandardMaterial({
color: 0x7d8d87, roughness: 0.58, metalness: 0.5, flatShading: true
}),
shelfDeck: new THREE.MeshStandardMaterial({
color: 0xb9a67d, roughness: 0.86, flatShading: true
}),
trolley: new THREE.MeshStandardMaterial({
color: 0x177b70, roughness: 0.62, flatShading: true
}),
trolleyTop: new THREE.MeshStandardMaterial({
color: 0x6ca79c, roughness: 0.68, flatShading: true
}),
table: new THREE.MeshStandardMaterial({
color: 0xb67d50, roughness: 0.83, flatShading: true
}),
wall: new THREE.MeshStandardMaterial({
color: 0xf0f2ea, roughness: 0.94, flatShading: true
}),
wallAccent: new THREE.MeshStandardMaterial({
color: 0x9eb8aa, roughness: 0.92, flatShading: true
}),
box: new THREE.MeshStandardMaterial({
color: 0xc88c47, roughness: 0.82, flatShading: true
}),
boxDark: new THREE.MeshStandardMaterial({
color: 0xa86b32, roughness: 0.86, flatShading: true
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x1f2b29, roughness: 0.93, flatShading: true
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xe8b643, roughness: 0.7, flatShading: true
}),
coral: new THREE.MeshStandardMaterial({
color: 0xd9674e, roughness: 0.72, flatShading: true
}),
blue: new THREE.MeshStandardMaterial({
color: 0x41869a, roughness: 0.68, flatShading: true
})
};
function addMesh(geometry, material, position, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function boxMesh(w, h, d, material, x, y, z, parent = scene) {
return addMesh(new THREE.BoxGeometry(w, h, d), material,
new THREE.Vector3(x, y, z), parent);
}
function cylinderMesh(radiusTop, radiusBottom, height, segments, material,
x, y, z, parent = scene) {
return addMesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material,
new THREE.Vector3(x, y, z),
parent
);
}
function makeTextTexture(text, subtitle, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = options.width || 512;
canvas.height = options.height || 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (options.background !== false) {
ctx.fillStyle = options.background || "#f7f1dc";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = options.border || "#153d38";
ctx.lineWidth = 14;
ctx.strokeRect(9, 9, canvas.width - 18, canvas.height - 18);
}
ctx.fillStyle = options.color || "#153d38";
ctx.textBaseline = "middle";
ctx.font = `900 ${options.fontSize || 70}px system-ui, sans-serif`;
ctx.fillText(text, 32, options.textY || 98);
if (subtitle) {
ctx.font = `700 ${options.subtitleSize || 27}px system-ui, sans-serif`;
ctx.fillStyle = options.subtitleColor || "#46625c";
ctx.fillText(subtitle, 34, options.subtitleY || 165);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function addFlatText(texture, w, h, x, y, z, parent = scene, rotationX = 0) {
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.position.set(x, y, z);
mesh.rotation.x = rotationX;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x27443f, opacity = 0.4) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 24),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
edges.scale.copy(mesh.scale);
mesh.parent.add(edges);
return edges;
}
// -------------------------------------------------------------------------
// Floor, rooms, and signage
// -------------------------------------------------------------------------
const floor = addMesh(
new THREE.BoxGeometry(19, 0.22, 11),
materials.floor,
new THREE.Vector3(0, -0.13, 0)
);
floor.receiveShadow = true;
boxMesh(7.6, 0.035, 9.8, materials.oldFloor, -5.45, 0.005, 0);
boxMesh(7.6, 0.035, 9.8, materials.newFloor, 5.45, 0.005, 0);
// Back wall sections suggest two separate rooms.
boxMesh(7.3, 4.1, 0.18, materials.wall, -5.5, 2.03, -3.35);
boxMesh(7.3, 4.1, 0.18, materials.wall, 5.5, 2.03, -3.35);
boxMesh(0.22, 4.1, 0.22, materials.wallAccent, 1.78, 2.03, -3.25);
boxMesh(0.22, 4.1, 0.22, materials.wallAccent, 9.28, 2.03, -3.25);
boxMesh(7.5, 0.22, 0.22, materials.wallAccent, 5.53, 4.03, -3.25);
const oldSign = makeTextTexture("OLD STORE", "SOURCE SHELF", {
width: 512,
height: 180,
fontSize: 58,
subtitleSize: 24,
background: "#dce7df",
border: "#6f8d80"
});
addFlatText(oldSign, 2.7, 0.95, -5.5, 3.48, -3.235);
const newSign = makeTextTexture("NEW ROOM", "DESTINATION", {
width: 512,
height: 180,
fontSize: 58,
subtitleSize: 24,
background: "#d5e6df",
border: "#407c70"
});
addFlatText(newSign, 2.7, 0.95, 5.5, 3.48, -3.235);
const oldFloorSign = makeTextTexture("01 OLD", "", {
width: 512,
height: 150,
fontSize: 68,
background: "#d4ddd7",
border: "#d4ddd7"
});
addFlatText(oldFloorSign, 2.7, 0.8, -5.2, 0.04, 2.45, scene, -Math.PI / 2);
const newFloorSign = makeTextTexture("03 NEW", "", {
width: 512,
height: 150,
fontSize: 68,
background: "#d9e6df",
border: "#d9e6df"
});
addFlatText(newFloorSign, 2.7, 0.8, 5.2, 0.04, 2.45, scene, -Math.PI / 2);
// -------------------------------------------------------------------------
// Old storage shelf
// -------------------------------------------------------------------------
const shelf = new THREE.Group();
shelf.position.set(-5.2, 0, -1.0);
scene.add(shelf);
const shelfWidth = 3.8;
const shelfDepth = 1.55;
for (const x of [-shelfWidth / 2, shelfWidth / 2]) {
for (const z of [-shelfDepth / 2, shelfDepth / 2]) {
boxMesh(0.12, 3.45, 0.12, materials.shelfMetal, x, 1.72, z, shelf);
}
}
for (const y of [0.25, 1.56, 2.87]) {
const deck = boxMesh(shelfWidth, 0.18, shelfDepth,
materials.shelfDeck, 0, y, 0, shelf);
addEdges(deck, 0x725d39, 0.24);
boxMesh(shelfWidth, 0.1, 0.1, materials.shelfMetal,
0, y - 0.11, shelfDepth / 2 + 0.015, shelf);
}
// Diagonal rear braces.
const braceMaterial = materials.shelfMetal;
const braceA = boxMesh(0.08, 3.4, 0.08, braceMaterial,
-0.35, 1.72, -shelfDepth / 2 - 0.02, shelf);
braceA.rotation.z = -0.68;
const braceB = boxMesh(0.08, 3.4, 0.08, braceMaterial,
0.35, 1.72, -shelfDepth / 2 - 0.02, shelf);
braceB.rotation.z = 0.68;
// -------------------------------------------------------------------------
// Trolley
// -------------------------------------------------------------------------
const trolley = new THREE.Group();
trolley.position.set(-1.6, 0, 0.1);
scene.add(trolley);
const trolleyDeck = boxMesh(2.15, 0.16, 1.55,
materials.trolleyTop, 0, 0.77, 0, trolley);
addEdges(trolleyDeck, 0x194c46, 0.45);
boxMesh(2.22, 0.11, 1.62, materials.trolley,
0, 0.665, 0, trolley);
for (const x of [-0.92, 0.92]) {
for (const z of [-0.58, 0.58]) {
boxMesh(0.1, 0.64, 0.1, materials.trolley,
x, 0.34, z, trolley);
const wheel = cylinderMesh(
0.17, 0.17, 0.12, 12,
materials.rubber,
x, 0.16, z, trolley
);
wheel.rotation.z = Math.PI / 2;
}
}
// Handle.
for (const x of [-0.92, 0.92]) {
boxMesh(0.1, 1.22, 0.1, materials.trolley,
x, 1.36, -0.67, trolley);
}
boxMesh(1.95, 0.1, 0.1, materials.trolley,
0, 1.94, -0.67, trolley);
// -------------------------------------------------------------------------
// Destination table
// -------------------------------------------------------------------------
const table = new THREE.Group();
table.position.set(5.2, 0, -0.65);
scene.add(table);
const tableTop = boxMesh(2.35, 0.16, 1.65,
materials.table, 0, 1.27, 0, table);
addEdges(tableTop, 0x704a2f, 0.28);
for (const x of [-0.9, 0.9]) {
for (const z of [-0.58, 0.58]) {
boxMesh(0.13, 1.2, 0.13, materials.darkMetal,
x, 0.59, z, table);
}
}
boxMesh(1.95, 0.1, 0.1, materials.darkMetal, 0, 0.33, -0.58, table);
// -------------------------------------------------------------------------
// Floor route and waypoints
// -------------------------------------------------------------------------
const routePoints = [
new THREE.Vector3(-5.2, 0.04, -0.55),
new THREE.Vector3(-1.6, 0.04, 0.1),
new THREE.Vector3(4.6, 0.04, 0.1),
new THREE.Vector3(5.2, 0.04, -0.65)
];
const routeGeometry = new THREE.BufferGeometry().setFromPoints(routePoints);
const route = new THREE.Line(
routeGeometry,
new THREE.LineDashedMaterial({
color: 0x368b7d,
dashSize: 0.2,
gapSize: 0.13,
transparent: true,
opacity: 0.68
})
);
route.computeLineDistances();
scene.add(route);
const waypointMaterial = new THREE.MeshStandardMaterial({
color: 0xf0f4eb,
roughness: 0.8,
flatShading: true
});
for (const point of routePoints) {
const marker = cylinderMesh(
0.22, 0.22, 0.035, 16,
waypointMaterial,
point.x, 0.045, point.z
);
marker.castShadow = false;
}
// -------------------------------------------------------------------------
// The single moving box: one group containing fixed label and fixed contents
// -------------------------------------------------------------------------
const movingBox = new THREE.Group();
movingBox.name = "ORBIT-17";
scene.add(movingBox);
const boxW = 1.36;
const boxD = 1.06;
const boxH = 1.22;
const bottom = boxMesh(boxW, 0.18, boxD,
materials.boxDark, 0, 0.09, 0, movingBox);
addEdges(bottom, 0x74451f, 0.46);
// Four walls form one open-top container.
const front = boxMesh(boxW, 0.91, 0.12,
materials.box, 0, 0.64, boxD / 2, movingBox);
addEdges(front, 0x74451f, 0.46);
const back = boxMesh(boxW, 0.91, 0.12,
materials.box, 0, 0.64, -boxD / 2, movingBox);
addEdges(back, 0x74451f, 0.46);
const left = boxMesh(0.12, 0.91, boxD,
materials.box, -boxW / 2, 0.64, 0, movingBox);
addEdges(left, 0x74451f, 0.46);
const right = boxMesh(0.12, 0.91, boxD,
materials.box, boxW / 2, 0.64, 0, movingBox);
addEdges(right, 0x74451f, 0.46);
// Reinforced corners.
for (const x of [-boxW / 2, boxW / 2]) {
for (const z of [-boxD / 2, boxD / 2]) {
boxMesh(0.1, 1.02, 0.1, materials.boxDark,
x, 0.61, z, movingBox);
}
}
// A single static label texture is reused on every side.
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 320;
const labelContext = labelCanvas.getContext("2d");
labelContext.fillStyle = "#f7f1dc";
labelContext.fillRect(0, 0, 640, 320);
labelContext.strokeStyle = "#153d38";
labelContext.lineWidth = 18;
labelContext.strokeRect(12, 12, 616, 296);
labelContext.fillStyle = "#153d38";
labelContext.textBaseline = "middle";
labelContext.font = "900 78px system-ui, sans-serif";
labelContext.fillText("ORBIT-17", 36, 102);
labelContext.fillStyle = "#46625c";
labelContext.font = "800 29px system-ui, sans-serif";
labelContext.fillText("PARTS / 03 · KEEP SEALED", 38, 171);
// The same teal diamond symbol on every label.
labelContext.save();
labelContext.translate(530, 145);
labelContext.rotate(Math.PI / 4);
labelContext.fillStyle = "#167d70";
labelContext.fillRect(-58, -58, 116, 116);
labelContext.restore();
labelContext.fillStyle = "#f7f1dc";
labelContext.beginPath();
labelContext.arc(530, 145, 18, 0, Math.PI * 2);
labelContext.fill();
labelContext.fillStyle = "#153d38";
labelContext.font = "900 25px system-ui, sans-serif";
labelContext.fillText("◆", 501, 250);
const labelTexture = new THREE.CanvasTexture(labelCanvas);
labelTexture.colorSpace = THREE.SRGBColorSpace;
labelTexture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const labelMaterial = new THREE.MeshStandardMaterial({
map: labelTexture,
roughness: 0.82,
metalness: 0,
side: THREE.DoubleSide
});
function addBoxLabel(width, height, x, y, z, rotationY) {
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
labelMaterial
);
label.position.set(x, y, z);
label.rotation.y = rotationY;
movingBox.add(label);
return label;
}
addBoxLabel(1.12, 0.56, 0, 0.67, boxD / 2 + 0.066, 0);
addBoxLabel(0.90, 0.56, boxW / 2 + 0.066, 0.67, 0, Math.PI / 2);
addBoxLabel(1.12, 0.56, 0, 0.67, -boxD / 2 - 0.066, Math.PI);
addBoxLabel(0.90, 0.56, -boxW / 2 - 0.066, 0.67, 0, -Math.PI / 2);
// Fixed contents. These are never swapped, replaced, hidden, or animated.
const contents = new THREE.Group();
contents.name = "Fixed contents: cylinder, cube, icosahedron";
movingBox.add(contents);
const contentCylinder = cylinderMesh(
0.16, 0.19, 0.38, 8,
materials.blue,
-0.31, 0.45, -0.03, contents
);
contentCylinder.rotation.y = 0.2;
const contentCube = boxMesh(
0.31, 0.31, 0.31,
materials.coral,
0.23, 0.43, 0.06, contents
);
contentCube.rotation.set(0.12, 0.32, -0.08);
const contentGem = addMesh(
new THREE.IcosahedronGeometry(0.23, 0),
materials.yellow,
new THREE.Vector3(0.02, 0.47, 0.28),
contents
);
contentGem.rotation.set(0.1, 0.45, 0.08);
// Small fixed content pips on the front edge.
for (let i = 0; i < 3; i++) {
const pip = cylinderMesh(
0.035, 0.035, 0.015, 12,
[materials.blue, materials.coral, materials.yellow][i],
-0.16 + i * 0.16, 0.195, boxD / 2 + 0.075, movingBox
);
pip.rotation.x = Math.PI / 2;
}
// -------------------------------------------------------------------------
// Animation timeline
// -------------------------------------------------------------------------
const startPosition = new THREE.Vector3(-5.2, 1.66, -0.55);
const trolleyPosition = new THREE.Vector3(-1.6, 0.86, 0.1);
const destinationPosition = new THREE.Vector3(5.2, 1.36, -0.65);
const times = {
start: 0,
liftFromShelf: 1.2,
shelfLiftDone: 1.8,
trolleyArrive: 3.2,
trolleySettle: 3.7,
trolleyArriveRoom: 5.2,
roomLiftDone: 5.9,
destinationArrive: 7.1,
destinationSettle: 7.7,
end: 8.5
};
let elapsed = 0;
let playing = true;
let previousTime = performance.now();
const statusElement = document.getElementById("status");
const progressElement = document.getElementById("progress");
const playButton = document.getElementById("play");
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function smooth(value) {
const x = clamp01(value);
return x * x * (3 - 2 * x);
}
function phaseProgress(time, start, end) {
return smooth((time - start) / (end - start));
}
function interpolatePosition(target, a, b, amount) {
target.lerpVectors(a, b, amount);
return target;
}
function updateTransfer(time) {
const boxPosition = new THREE.Vector3();
let trolleyX = -1.6;
if (time < times.liftFromShelf) {
boxPosition.copy(startPosition);
statusElement.textContent = "01 · Old shelf";
} else if (time < times.shelfLiftDone) {
const p = phaseProgress(time, times.liftFromShelf, times.shelfLiftDone);
boxPosition.copy(startPosition);
boxPosition.y = THREE.MathUtils.lerp(startPosition.y, 2.55, p);
statusElement.textContent = "02 · Lifting from old shelf";
} else if (time < times.trolleyArrive) {
const p = phaseProgress(time, times.shelfLiftDone, times.trolleyArrive);
interpolatePosition(
boxPosition,
new THREE.Vector3(startPosition.x, 2.55, startPosition.z),
trolleyPosition,
p
);
boxPosition.y += Math.sin(p * Math.PI) * 0.38;
statusElement.textContent = "02 · Transfer to trolley";
} else if (time < times.trolleySettle) {
const p = phaseProgress(time, times.trolleyArrive, times.trolleySettle);
boxPosition.set(trolleyPosition.x, 2.55, trolleyPosition.z);
boxPosition.y = THREE.MathUtils.lerp(2.55, trolleyPosition.y, p);
statusElement.textContent = "02 · Settling onto trolley";
} else if (time < times.trolleyArriveRoom) {
const p = phaseProgress(time, times.trolleySettle, times.trolleyArriveRoom);
trolleyX = THREE.MathUtils.lerp(-1.6, 4.6, p);
boxPosition.set(trolleyX, trolleyPosition.y, trolleyPosition.z);
statusElement.textContent = "03 · Traveling on trolley";
} else if (time < times.roomLiftDone) {
const p = phaseProgress(time, times.trolleyArriveRoom, times.roomLiftDone);
trolleyX = 4.6;
boxPosition.set(4.6, trolleyPosition.y, trolleyPosition.z);
boxPosition.y = THREE.MathUtils.lerp(trolleyPosition.y, 2.35, p);
statusElement.textContent = "04 · Lifting in new room";
} else if (time < times.destinationArrive) {
const p = phaseProgress(time, times.roomLiftDone, times.destinationArrive);
interpolatePosition(
boxPosition,
new THREE.Vector3(4.6, 2.35, 0.1),
destinationPosition,
p
);
boxPosition.y += Math.sin(p * Math.PI) * 0.32;
statusElement.textContent = "04 · Moving to destination";
} else if (time < times.destinationSettle) {
const p = phaseProgress(time, times.destinationArrive, times.destinationSettle);
boxPosition.set(destinationPosition.x, 2.35, destinationPosition.z);
boxPosition.y = THREE.MathUtils.lerp(2.35, destinationPosition.y, p);
statusElement.textContent = "04 · Placing on destination table";
} else {
boxPosition.copy(destinationPosition);
statusElement.textContent = "05 · Destination reached";
}
movingBox.position.copy(boxPosition);
trolley.position.x = trolleyX;
// A very small settling tilt only; identity and contents never change.
const arrivalPulse = time < times.trolleySettle
? Math.sin(clamp01((time - times.trolleyArrive) /
(times.trolleySettle - times.trolleyArrive)) * Math.PI) * 0.018
: 0;
movingBox.rotation.z = arrivalPulse;
movingBox.rotation.y = 0.04;
progressElement.style.transform = `scaleX(${clamp01(time / times.end)})`;
}
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
document.getElementById("replay").addEventListener("click", () => {
elapsed = 0;
playing = true;
playButton.textContent = "Pause";
});
document.getElementById("camera").addEventListener("click", () => {
cameraTheta = 0.61;
cameraPhi = 1.02;
cameraRadius = 18.2;
updateCamera();
});
// -------------------------------------------------------------------------
// Custom camera controls: drag to orbit and wheel to zoom
// -------------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.005, 0.38, 1.43);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
9,
28
);
updateCamera();
}, { passive: false });
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
elapsed = Math.min(elapsed + delta, times.end);
if (elapsed >= times.end) {
playing = false;
playButton.textContent = "Replay";
}
}
updateTransfer(elapsed);
renderer.render(scene, camera);
}
updateTransfer(0);
requestAnimationFrame(animate);
</script>
</body>
</html>
```