Prompt specification
Build or customize the Three.js 3D scene "Produce restocking along a Vienna market aisle" 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: Produce restocking along a Vienna market aisle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/produce-restocking-along-a-vienna-market-aisle-x2878
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows restocking along a small voxel slice of Vienna's Naschmarkt. Use referenced stall proportions and a narrow shared aisle, but give the stalls original arrangements of fruit, bread, and baskets. A handcart approaches through a clear service route, stops beside one stall, and transfers a few crates onto an accessible shelf. Shoppers occupy a separate part of the aisle, leaving a visible passage around the cart. Keep shelves and stall walls fixed; the cart must follow the available route instead of passing through the displays. The vignette should remain compact enough to read as one restocking action.
Working Three.js Starter (produce-restocking-along-a-vienna-market-aisle-x2878):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Naschmarkt Restocking</title>
<style>
:root {
color-scheme: light;
--ink: #252923;
--muted: #66695f;
--paper: rgba(250, 247, 237, 0.92);
--gold: #d69b3b;
--blue: #668a91;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e3d6;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid rgba(52, 57, 49, 0.14);
box-shadow: 0 10px 30px rgba(49, 45, 34, 0.12);
backdrop-filter: blur(10px);
}
#title {
top: 20px;
left: 20px;
max-width: min(390px, calc(100vw - 40px));
padding: 16px 18px 14px;
border-radius: 15px;
pointer-events: none;
}
#title h1 {
margin: 0;
font-size: clamp(20px, 3vw, 31px);
line-height: 1.02;
letter-spacing: -0.045em;
}
#title p {
margin: 8px 0 12px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.chip {
padding: 5px 8px;
border-radius: 999px;
background: #eee9dc;
color: #55584f;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
}
#legend {
top: 20px;
right: 20px;
width: 190px;
padding: 13px 14px;
border-radius: 14px;
font-size: 11px;
color: #55594f;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin: 7px 0;
}
.swatch {
width: 19px;
height: 8px;
border-radius: 2px;
flex: 0 0 auto;
}
.swatch.service { background: #d9a34a; }
.swatch.shoppers { background: #78969b; }
.swatch.shelf { background: #8b7355; }
#controls {
left: 20px;
bottom: 20px;
width: min(410px, calc(100vw - 40px));
padding: 13px 15px 14px;
border-radius: 15px;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
#status {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
button {
appearance: none;
border: 0;
border-radius: 9px;
padding: 8px 12px;
background: #29312d;
color: #fffdf4;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover { background: #414b44; }
button:active { transform: translateY(1px); }
.progress {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: #ddd8ca;
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #cf9137, #e1b25e);
transition: width 80ms linear;
}
#hint {
margin-top: 8px;
color: #777a70;
font-size: 10px;
}
@media (max-width: 650px) {
#legend { display: none; }
#title { top: 12px; left: 12px; max-width: calc(100vw - 24px); }
#controls { left: 12px; bottom: 12px; width: calc(100vw - 24px); }
#title p { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<section id="title" class="panel">
<h1>Naschmarkt,<br />between deliveries.</h1>
<p>
A compact voxel slice of Vienna: fruit, bread and woven baskets line a
narrow shared aisle while a handcart uses the marked service lane.
</p>
<div class="chips">
<span class="chip">2.8 m shared aisle</span>
<span class="chip">Fixed displays</span>
<span class="chip">Accessible low shelf</span>
</div>
</section>
<aside id="legend" class="panel">
<strong style="font-size:11px;letter-spacing:.08em;text-transform:uppercase">
Aisle key
</strong>
<div class="legend-row"><span class="swatch service"></span> Service route</div>
<div class="legend-row"><span class="swatch shoppers"></span> Shopper lane</div>
<div class="legend-row"><span class="swatch shelf"></span> Crate destination</div>
</aside>
<section id="controls" class="panel">
<div class="status-row">
<span id="status">Preparing route</span>
<button id="replay" type="button">Replay</button>
</div>
<div class="progress"><div id="progress"></div></div>
<div id="hint">Drag to orbit · scroll or pinch to zoom · double-click to reset</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const statusEl = document.getElementById("status");
const progressEl = document.getElementById("progress");
const replayButton = document.getElementById("replay");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e3d6);
scene.fog = new THREE.Fog(0xe8e3d6, 19, 34);
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.12;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const target = new THREE.Vector3(0, 1.05, 0.1);
const spherical = new THREE.Spherical(15.6, 0.9, 0.045);
function updateCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff8df, 0x777b69, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.1);
sun.position.set(-5, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d7df, 0.72);
fill.position.set(7, 6, -6);
scene.add(fill);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
typeof color === "number" || typeof color === "string"
? material(color)
: color
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radius, height, color, x = 0, y = 0, z = 0, sides = 12) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, sides),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function canvasTexture(text, background, foreground, subtitle = "") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(255,255,255,.28)";
ctx.lineWidth = 8;
ctx.strokeRect(12, 12, canvas.width - 24, canvas.height - 24);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 76px system-ui, sans-serif";
ctx.fillText(text, canvas.width / 2, subtitle ? 76 : 96);
if (subtitle) {
ctx.globalAlpha = 0.78;
ctx.font = "700 27px system-ui, sans-serif";
ctx.fillText(subtitle, canvas.width / 2, 137);
ctx.globalAlpha = 1;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function sign(parent, text, subtitle, bg, fg, w, h, x, y, z) {
const texture = canvasTexture(text, bg, fg, subtitle);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({ map: texture, side: THREE.DoubleSide })
);
mesh.position.set(x, y, z);
mesh.rotation.y = -Math.PI / 2;
parent.add(mesh);
return mesh;
}
// Diorama base and lane surfaces.
box(scene, 10.2, 0.36, 13.6, 0xb8ad91, 0, -0.18, 0.6, false);
box(scene, 9.9, 0.07, 13.25, 0xd7d0bd, 0, 0.025, 0.6, false);
box(scene, 10.25, 0.09, 0.18, 0x8e8269, 0, 0.01, 7.43, false);
box(scene, 10.25, 0.09, 0.18, 0x8e8269, 0, 0.01, -6.22, false);
// The two lanes occupy different portions of the same narrow aisle.
box(scene, 1.1, 0.018, 11.9, 0xcbd4d1, -0.94, 0.073, 0.65, false);
box(scene, 0.94, 0.018, 11.9, 0xe6d4a8, 0.35, 0.074, 0.65, false);
for (let z = -4.8; z < 6.2; z += 0.72) {
box(scene, 0.045, 0.022, 0.33, 0xfff4d5, -0.28, 0.09, z, false);
}
function routeArrow(z) {
box(scene, 0.055, 0.022, 0.52, 0xbc7e22, 0.35, 0.096, z, false);
const left = box(scene, 0.055, 0.022, 0.43, 0xbc7e22, 0.22, 0.097, z - 0.2, false);
const right = box(scene, 0.055, 0.022, 0.43, 0xbc7e22, 0.48, 0.097, z - 0.2, false);
left.rotation.y = -0.64;
right.rotation.y = 0.64;
}
routeArrow(5.5);
routeArrow(4.3);
routeArrow(3.1);
function buildShell(parent, width, depth, accent, awningA, awningB) {
box(parent, depth, 0.12, width, 0x9c825e, 0, 0.08, 0);
// Rear boards.
const boardCount = Math.max(4, Math.round(width / 0.55));
const boardWidth = width / boardCount;
for (let i = 0; i < boardCount; i++) {
const z = -width / 2 + boardWidth * (i + 0.5);
box(
parent,
0.12,
2.55,
boardWidth * 0.94,
i % 2 ? 0xb59467 : 0xa9875d,
depth / 2 - 0.07,
1.34,
z
);
}
// Short side walls leave the front open.
box(parent, depth * 0.9, 0.82, 0.11, accent, 0.08, 0.53, width / 2 - 0.05);
box(parent, depth * 0.9, 0.82, 0.11, accent, 0.08, 0.53, -width / 2 + 0.05);
const postXs = [-depth / 2 + 0.06, depth / 2 - 0.06];
const postZs = [-width / 2 + 0.06, width / 2 - 0.06];
for (const x of postXs) {
for (const z of postZs) {
box(parent, 0.14, 2.83, 0.14, 0x5e4934, x, 1.43, z);
}
}
// Stepped voxel awning.
const stripeWidth = 0.42;
const stripeCount = Math.ceil(width / stripeWidth);
for (let i = 0; i < stripeCount; i++) {
const z = -width / 2 + stripeWidth * (i + 0.5);
box(
parent,
0.56,
0.13,
stripeWidth * 0.97,
i % 2 ? awningA : awningB,
-depth / 2 - 0.18,
2.78,
z
);
box(
parent,
0.11,
0.34,
stripeWidth * 0.97,
i % 2 ? awningA : awningB,
-depth / 2 - 0.43,
2.57,
z
);
}
// A shallow rear roof helps frame the stall without hiding the displays.
box(parent, depth * 0.72, 0.1, width, 0x62523e, depth * 0.12, 2.8, 0);
}
function makeCrate(parent, color = 0xa77b48) {
const g = new THREE.Group();
parent.add(g);
box(g, 0.58, 0.045, 0.64, color, 0, 0.023, 0);
for (const x of [-0.27, 0.27]) {
for (const z of [-0.30, 0.30]) {
box(g, 0.045, 0.30, 0.045, color, x, 0.16, z);
}
}
for (const x of [-0.285, 0.285]) {
box(g, 0.035, 0.065, 0.64, color, x, 0.12, 0);
box(g, 0.035, 0.065, 0.64, color, x, 0.235, 0);
}
for (const z of [-0.315, 0.315]) {
box(g, 0.58, 0.065, 0.035, color, 0, 0.12, z);
box(g, 0.58, 0.065, 0.035, color, 0, 0.235, z);
}
return g;
}
function addProduce(parent, x, y, z, type = "apple") {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
const colors = {
apple: [0xc84c3d, 0xe35c43, 0xb83f36],
citrus: [0xe2a12f, 0xf0b842, 0xcd8b26],
plum: [0x66416f, 0x825080, 0x51345d]
};
const palette = colors[type];
const positions = [
[-0.14, 0, -0.13], [0.12, 0, -0.12],
[0, 0, 0.02], [-0.13, 0, 0.15],
[0.13, 0, 0.15], [0, 0.16, 0]
];
positions.forEach((p, i) => {
const fruit = box(g, 0.14, 0.13, 0.14, palette[i % palette.length], p[0], p[1] + 0.08, p[2]);
fruit.rotation.y = (i * 0.7) % Math.PI;
if (type !== "citrus") {
box(g, 0.025, 0.04, 0.025, 0x695035, p[0], p[1] + 0.16, p[2]);
}
});
return g;
}
function fruitTray(parent, x, y, z, type) {
const crate = makeCrate(parent, type === "citrus" ? 0x9f733c : 0x9a7044);
crate.position.set(x, y, z);
addProduce(crate, 0, 0.255, 0, type);
return crate;
}
function loaf(parent, x, y, z, scale = 1, rotation = 0) {
const g = new THREE.Group();
g.position.set(x, y, z);
g.rotation.y = rotation;
g.scale.setScalar(scale);
parent.add(g);
box(g, 0.48, 0.16, 0.24, 0xc98742, 0, 0.08, 0);
box(g, 0.38, 0.10, 0.22, 0xd99b52, 0, 0.19, 0);
box(g, 0.035, 0.018, 0.18, 0xf0c883, -0.09, 0.246, 0);
box(g, 0.035, 0.018, 0.18, 0xf0c883, 0.09, 0.246, 0);
return g;
}
function basket(parent, x, y, z, w = 0.66, d = 0.48, h = 0.36) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
const wicker = 0xb6864f;
box(g, w, 0.045, d, 0x8d673e, 0, 0.025, 0);
for (const yy of [0.10, 0.20, h]) {
box(g, w, 0.045, 0.04, wicker, 0, yy, d / 2 - 0.02);
box(g, w, 0.045, 0.04, wicker, 0, yy, -d / 2 + 0.02);
box(g, 0.04, 0.045, d, wicker, w / 2 - 0.02, yy, 0);
box(g, 0.04, 0.045, d, wicker, -w / 2 + 0.02, yy, 0);
}
for (let i = 0; i < 5; i++) {
const xx = -w / 2 + 0.08 + i * (w - 0.16) / 4;
box(g, 0.025, h, 0.025, wicker, xx, h / 2, d / 2 - 0.02);
box(g, 0.025, h, 0.025, wicker, xx, h / 2, -d / 2 + 0.02);
}
return g;
}
// Left fruit stall: faces the aisle to the right.
const fruitStall = new THREE.Group();
fruitStall.position.set(-2.55, 0, -1.15);
fruitStall.rotation.y = Math.PI;
scene.add(fruitStall);
buildShell(fruitStall, 4.6, 2.3, 0x607d60, 0xd06d4d, 0xf0e2c3);
box(fruitStall, 0.68, 0.22, 4.25, 0xa57b50, -1.12, 0.86, 0);
box(fruitStall, 0.12, 0.78, 4.22, 0x80603f, -0.86, 0.42, 0);
sign(fruitStall, "OBST", "FRUIT · FRESH DAILY", "#315746", "#fff1c9", 2.25, 0.58, -1.21, 2.24, 0);
fruitTray(fruitStall, -1.19, 0.98, -1.45, "apple");
fruitTray(fruitStall, -1.19, 0.98, 0.00, "citrus");
fruitTray(fruitStall, -1.19, 0.98, 1.45, "plum");
box(fruitStall, 0.62, 0.12, 4.05, 0x9a7449, 0.69, 1.40, 0);
box(fruitStall, 0.62, 0.12, 4.05, 0x9a7449, 0.69, 2.04, 0);
fruitTray(fruitStall, 0.67, 1.46, -1.28, "citrus");
fruitTray(fruitStall, 0.67, 1.46, 0.0, "apple");
fruitTray(fruitStall, 0.67, 1.46, 1.28, "plum");
fruitTray(fruitStall, 0.67, 2.10, -0.7, "apple");
fruitTray(fruitStall, 0.67, 2.10, 0.7, "citrus");
// Right bread stall: faces the aisle to the left.
const breadStall = new THREE.Group();
breadStall.position.set(2.55, 0, -2.55);
scene.add(breadStall);
buildShell(breadStall, 3.8, 2.3, 0x9a6849, 0x4e7481, 0xe9dfc7);
box(breadStall, 0.68, 0.22, 3.48, 0x9e744b, -1.12, 0.86, 0);
box(breadStall, 0.12, 0.78, 3.45, 0x78563c, -0.86, 0.42, 0);
sign(breadStall, "BROT", "BAKED THIS MORNING", "#315463", "#fff0ce", 2.05, 0.58, -1.21, 2.24, 0);
box(breadStall, 0.58, 0.12, 3.48, 0x936b43, 0.70, 1.38, 0);
box(breadStall, 0.58, 0.12, 3.48, 0x936b43, 0.70, 2.02, 0);
[-1.15, -0.38, 0.40, 1.15].forEach((z, i) => {
loaf(breadStall, -1.18, 0.98, z, 1.0, i % 2 ? 0.08 : -0.06);
loaf(breadStall, 0.67, 1.44, z, 0.88, i % 2 ? -0.08 : 0.05);
loaf(breadStall, 0.67, 2.08, z, 0.82, i % 2 ? 0.12 : -0.10);
});
// Right basket stall, including the low accessible transfer shelf.
const basketStall = new THREE.Group();
basketStall.position.set(2.55, 0, 1.55);
scene.add(basketStall);
buildShell(basketStall, 4.1, 2.3, 0x887551, 0x8c6e98, 0xe8ddc6);
sign(basketStall, "KÖRB", "WOVEN & READY", "#594267", "#fff0cf", 2.15, 0.58, -1.21, 2.24, 0);
box(basketStall, 0.65, 0.18, 3.72, 0x9b784f, 0.64, 0.89, 0);
box(basketStall, 0.58, 0.12, 3.72, 0x987249, 0.69, 1.44, 0);
box(basketStall, 0.58, 0.12, 3.72, 0x987249, 0.69, 2.04, 0);
basket(basketStall, 0.56, 0.99, -1.35, 0.66, 0.48, 0.38);
basket(basketStall, 0.56, 0.99, -0.67, 0.66, 0.48, 0.38);
basket(basketStall, 0.56, 0.99, 0.02, 0.66, 0.48, 0.38);
basket(basketStall, 0.56, 0.99, 0.72, 0.66, 0.48, 0.38);
basket(basketStall, 0.62, 1.51, -1.18, 0.62, 0.45, 0.35);
basket(basketStall, 0.62, 1.51, -0.42, 0.62, 0.45, 0.35);
basket(basketStall, 0.62, 1.51, 0.34, 0.62, 0.45, 0.35);
basket(basketStall, 0.62, 2.11, -0.85, 0.62, 0.45, 0.35);
basket(basketStall, 0.62, 2.11, 0.02, 0.62, 0.45, 0.35);
// Fixed, reachable shelf. It protrudes into the service side but leaves
// the cart's marked lane unobstructed.
box(basketStall, 0.70, 0.12, 2.82, 0x7e6246, -1.25, 0.58, 0);
box(basketStall, 0.06, 0.43, 2.76, 0x9c7b54, -1.59, 0.42, 0);
sign(basketStall, "LOW SHELF", "", "#6e5844", "#fff5d8", 0.92, 0.22, -1.625, 0.43, 0);
function makePerson(coatColor, skinColor, hatColor = null, apronColor = null) {
const g = new THREE.Group();
scene.add(g);
box(g, 0.16, 0.46, 0.18, 0x3d4542, -0.105, 0.26, 0);
box(g, 0.16, 0.46, 0.18, 0x3d4542, 0.105, 0.26, 0);
box(g, 0.34, 0.19, 0.25, 0x282d2c, -0.105, 0.055, 0.03);
box(g, 0.34, 0.19, 0.25, 0x282d2c, 0.105, 0.055, 0.03);
box(g, 0.44, 0.53, 0.28, coatColor, 0, 0.77, 0);
box(g, 0.28, 0.28, 0.28, skinColor, 0, 1.20, 0);
box(g, 0.08, 0.07, 0.04, skinColor, 0, 1.18, -0.16);
if (hatColor) {
box(g, 0.36, 0.08, 0.34, hatColor, 0, 1.39, 0);
box(g, 0.31, 0.13, 0.29, hatColor, 0, 1.48, 0);
} else {
box(g, 0.32, 0.13, 0.31, 0x5a4433, 0, 1.36, 0.015);
}
if (apronColor) {
box(g, 0.34, 0.39, 0.035, apronColor, 0, 0.74, -0.16);
}
const leftArm = new THREE.Group();
leftArm.position.set(-0.27, 1.00, 0);
g.add(leftArm);
box(leftArm, 0.12, 0.44, 0.13, coatColor, 0, -0.20, 0);
box(leftArm, 0.12, 0.10, 0.13, skinColor, 0, -0.43, 0);
const rightArm = new THREE.Group();
rightArm.position.set(0.27, 1.00, 0);
g.add(rightArm);
box(rightArm, 0.12, 0.44, 0.13, coatColor, 0, -0.20, 0);
box(rightArm, 0.12, 0.10, 0.13, skinColor, 0, -0.43, 0);
return { group: g, leftArm, rightArm };
}
const shopperA = makePerson(0x6f8790, 0xc98d67, 0x405f67);
shopperA.group.position.set(-0.94, 0.04, -2.35);
shopperA.group.rotation.y = Math.PI / 2;
shopperA.leftArm.rotation.x = 0.48;
const shopperB = makePerson(0xb56e54, 0xe0b187, 0x854d3c, 0xeee0bd);
shopperB.group.position.set(-0.93, 0.04, -0.45);
shopperB.group.rotation.y = Math.PI / 2;
shopperB.rightArm.rotation.x = 0.58;
const shopperC = makePerson(0x7e705e, 0x9f694d, 0x54483e);
shopperC.group.position.set(-0.95, 0.04, 1.50);
shopperC.group.rotation.y = -Math.PI / 2;
shopperC.leftArm.rotation.x = 0.40;
const operator = makePerson(0x4f6d5b, 0xd29a72, 0x354a40, 0xc89c51);
operator.group.rotation.y = -Math.PI / 2;
// Handcart.
const cart = new THREE.Group();
scene.add(cart);
box(cart, 0.96, 0.13, 1.55, 0x855f3e, 0, 0.43, 0);
box(cart, 0.74, 0.16, 1.28, 0xa47a4d, 0, 0.55, 0);
for (const x of [-0.43, 0.43]) {
box(cart, 0.09, 0.13, 1.54, 0x6a4b34, x, 0.36, 0);
box(cart, 0.08, 0.08, 1.12, 0x654731, x * 0.9, 0.73, 0.32);
}
for (const z of [-0.52, 0.52]) {
box(cart, 0.93, 0.09, 0.10, 0x654731, 0, 0.35, z);
}
// Handles project toward the operator.
for (const x of [-0.39, 0.39]) {
box(cart, 0.09, 0.09, 1.08, 0x654731, x, 0.67, 0.93);
box(cart, 0.12, 0.12, 0.18, 0x4e3829, x, 0.67, 1.40);
}
const wheels = [];
for (const x of [-0.52, 0.52]) {
for (const z of [-0.51, 0.51]) {
const wheelPivot = new THREE.Group();
wheelPivot.position.set(x, 0.25, z);
cart.add(wheelPivot);
const wheel = cylinder(wheelPivot, 0.245, 0.12, 0x303433);
wheel.rotation.z = Math.PI / 2;
const hub = cylinder(wheelPivot, 0.095, 0.145, 0xa68752);
hub.rotation.z = Math.PI / 2;
box(wheelPivot, 0.16, 0.35, 0.055, 0x8e754e, 0, 0, 0);
box(wheelPivot, 0.16, 0.055, 0.35, 0x8e754e, 0, 0, 0);
wheels.push(wheelPivot);
}
}
// Three removable crates, initially stacked on the cart.
const transferCrates = [];
for (let i = 0; i < 3; i++) {
const crate = makeCrate(scene, 0xb2814d);
addProduce(crate, 0, 0.25, 0, i === 1 ? "citrus" : "apple");
transferCrates.push(crate);
}
const crateTargets = [
new THREE.Vector3(1.22, 0.642, 0.55),
new THREE.Vector3(1.22, 0.642, 1.55),
new THREE.Vector3(1.22, 0.642, 2.55)
];
// Small decorative details outside the active route.
function planter(x, z) {
box(scene, 0.56, 0.42, 0.56, 0x9b6950, x, 0.22, z);
box(scene, 0.48, 0.07, 0.48, 0x4d4833, x, 0.46, z);
box(scene, 0.10, 0.70, 0.10, 0x6f5836, x, 0.78, z);
box(scene, 0.45, 0.34, 0.42, 0x5f8056, x, 1.16, z);
box(scene, 0.34, 0.26, 0.33, 0x759364, x + 0.09, 1.40, z);
}
planter(-4.55, 5.65);
planter(4.55, 5.65);
function lamp(x, z) {
cylinder(scene, 0.055, 2.65, 0x424946, x, 1.32, z);
box(scene, 0.38, 0.12, 0.38, 0x3f4642, x, 2.67, z);
box(scene, 0.29, 0.20, 0.29, 0xf5df9a, x, 2.54, z);
}
lamp(-4.62, -5.35);
lamp(4.62, -5.35);
// Animation timeline.
const APPROACH_END = 6.2;
const TRANSFER_START = 6.8;
const TRANSFER_DURATION = 1.35;
const TRANSFER_STAGGER = 1.55;
const TOTAL_TIME = 12.0;
let elapsed = 0;
let playing = true;
const clamp01 = v => Math.max(0, Math.min(1, v));
const ease = v => {
const x = clamp01(v);
return x * x * (3 - 2 * x);
};
function updateAnimation(t) {
const approach = ease(t / APPROACH_END);
const cartZ = THREE.MathUtils.lerp(5.72, 1.55, approach);
cart.position.set(0.35, 0, cartZ);
const travel = 5.72 - cartZ;
wheels.forEach(wheel => {
wheel.rotation.x = travel / 0.245;
});
// The operator pushes behind the cart and then turns toward the low shelf.
const operatorMove = ease((t - APPROACH_END) / 0.65);
operator.group.position.set(
THREE.MathUtils.lerp(0.35, 0.69, operatorMove),
0.015,
cartZ + 1.08
);
let armPulse = 0;
transferCrates.forEach((crate, i) => {
const start = TRANSFER_START + (2 - i) * TRANSFER_STAGGER;
const end = start + TRANSFER_DURATION;
const stackPosition = new THREE.Vector3(
0.35,
0.50 + i * 0.305,
cartZ
);
if (t < start) {
crate.position.copy(stackPosition);
crate.rotation.set(0, 0, 0);
} else if (t < end) {
const u = ease((t - start) / TRANSFER_DURATION);
const target = crateTargets[i];
crate.position.x = THREE.MathUtils.lerp(stackPosition.x, target.x, u);
crate.position.z = THREE.MathUtils.lerp(stackPosition.z, target.z, u);
crate.position.y =
THREE.MathUtils.lerp(stackPosition.y, target.y, u) +
Math.sin(Math.PI * u) * 0.48;
crate.rotation.y = Math.sin(Math.PI * u) * 0.08;
crate.rotation.z = Math.sin(Math.PI * u) * 0.025;
armPulse = Math.max(armPulse, Math.sin(Math.PI * u));
} else {
crate.position.copy(crateTargets[i]);
crate.rotation.set(0, 0, 0);
}
});
operator.leftArm.rotation.x = 0.12 + armPulse * 1.08;
operator.rightArm.rotation.x = 0.16 + armPulse * 0.72;
// Subtle life in the shopper lane; no shopper enters the service route.
shopperA.group.position.y = 0.04 + Math.sin(t * 1.6) * 0.008;
shopperB.group.position.y = 0.04 + Math.sin(t * 1.3 + 1.2) * 0.007;
shopperC.group.position.y = 0.04 + Math.sin(t * 1.45 + 2.1) * 0.008;
operator.group.position.y = 0.015 + Math.sin(t * 2.0) * 0.004;
const progress = clamp01(t / TOTAL_TIME);
progressEl.style.width = `${progress * 100}%`;
if (t < APPROACH_END) {
statusEl.textContent = "Handcart entering service lane";
} else if (t < TRANSFER_START) {
statusEl.textContent = "Stopped beside basket stall";
} else if (t < TRANSFER_START + TRANSFER_STAGGER * 2 + TRANSFER_DURATION) {
statusEl.textContent = "Transferring crates to low shelf";
} else {
statusEl.textContent = "Restock complete · aisle clear";
}
}
replayButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
replayButton.textContent = "Replay";
});
// Direct camera controls, implemented without external examples or addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", event => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
} else if (pointers.size === 2) {
const points = [...pointers.values()];
pinchDistance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
spherical.theta -= dx * 0.005;
spherical.phi = THREE.MathUtils.clamp(spherical.phi - dy * 0.005, 0.48, 1.27);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
if (pinchDistance > 0) {
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * (pinchDistance / distance),
10.5,
23
);
updateCamera();
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) dragging = false;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius + event.deltaY * 0.008,
10.5,
23
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
spherical.set(15.6, 0.9, 0.045);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
elapsed += dt;
if (elapsed >= TOTAL_TIME) {
elapsed = TOTAL_TIME;
playing = false;
replayButton.textContent = "Play again";
}
}
updateAnimation(elapsed);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```