Prompt specification
Build or customize the Three.js 3D scene "Small grocery morning replenishment" 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: Small grocery morning replenishment
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-grocery-morning-replenishment-x0535
Scene Description Prompt:
Stylized grocery workers replenish grouped shelves while shoppers keep a clear path to checkout. Make one HTML file using Three.js from cdnjs.
Working Three.js Starter (small-grocery-morning-replenishment-x0535):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Grove & Go — Grocery Store</title>
<style>
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e4;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 5;
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 20px 22px;
border: 1px solid rgba(255, 255, 255, .7);
border-radius: 22px;
background: rgba(255, 255, 255, .82);
box-shadow: 0 18px 50px rgba(28, 64, 55, .14);
backdrop-filter: blur(16px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #287265;
font-size: 11px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #ef765f;
box-shadow: 0 0 0 5px rgba(239, 118, 95, .13);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% { box-shadow: 0 0 0 8px rgba(239, 118, 95, 0); }
}
h1 {
margin: 0;
color: #173f38;
font-size: clamp(24px, 3vw, 34px);
line-height: 1.04;
letter-spacing: -.045em;
}
.subtitle {
margin: 10px 0 16px;
color: #5d7771;
font-size: 13px;
line-height: 1.5;
}
.stats {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.stat {
padding: 7px 10px;
border-radius: 999px;
background: #edf5ef;
color: #35655b;
font-size: 11px;
font-weight: 750;
}
.toolbar {
position: fixed;
z-index: 6;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, .75);
border-radius: 16px;
background: rgba(255, 255, 255, .84);
box-shadow: 0 14px 40px rgba(28, 64, 55, .13);
backdrop-filter: blur(14px);
}
button {
border: 0;
border-radius: 11px;
padding: 10px 14px;
background: #21685d;
color: white;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: transform .15s ease, background .15s ease;
}
button:hover { background: #174f47; }
button:active { transform: translateY(1px); }
.hint {
position: fixed;
z-index: 5;
left: 24px;
bottom: 25px;
padding: 9px 13px;
border-radius: 12px;
background: rgba(28, 64, 55, .78);
color: white;
font-size: 11px;
font-weight: 650;
letter-spacing: .02em;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 720px) {
.hud {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.subtitle { display: none; }
.stats { margin-top: 11px; }
.toolbar { right: 12px; bottom: 12px; }
.hint { display: none; }
}
</style>
</head>
<body>
<div class="hud">
<div class="eyebrow"><span class="live-dot"></span>Grove & Go · Store floor</div>
<h1>Fresh shelves.<br />Smooth checkout.</h1>
<p class="subtitle">
Three stocking crews organize produce, bakery, and pantry shelves while shoppers follow the open center aisle.
</p>
<div class="stats">
<span class="stat">3 CREW</span>
<span class="stat">2 SHOPPERS</span>
<span class="stat">3 DEPARTMENTS</span>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="toolbar">
<button id="pause" type="button">Pause motion</button>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.domElement.id = "scene";
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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 scene = new THREE.Scene();
scene.background = new THREE.Color("#dce9e4");
scene.fog = new THREE.Fog("#dce9e4", 30, 58);
const camera = new THREE.OrthographicCamera(-15, 15, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.25, -0.1);
let cameraTheta = 0.73;
let cameraPhi = 0.88;
let cameraZoom = 1;
scene.add(new THREE.HemisphereLight("#fff9e9", "#78a598", 2.25));
const sun = new THREE.DirectionalLight("#fff1d6", 3.1);
sun.position.set(8, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.035;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9e5df", 1.05);
fill.position.set(-10, 8, -6);
scene.add(fill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const mat = (color, roughness = 0.72, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const M = {
floor: mat("#eee7d8"),
floorLine: mat("#ded8ca"),
wall: mat("#f5efe2"),
wallGreen: mat("#cfe3d8"),
cream: mat("#fff8e9"),
white: mat("#ffffff"),
dark: mat("#214d46"),
teal: mat("#287a6d"),
mint: mat("#b9ddca"),
path: mat("#dcece2"),
green: mat("#68ad62"),
lightGreen: mat("#9acb78"),
red: mat("#e86c58"),
orange: mat("#f2a64c"),
yellow: mat("#f2cb55"),
blue: mat("#5c9fc0"),
navy: mat("#355d73"),
purple: mat("#9a7bb5"),
pink: mat("#e69aa4"),
brown: mat("#8f6042"),
tan: mat("#d69a61"),
darkWood: mat("#6d4937"),
metal: mat("#aeb8b2", 0.34, 0.48),
black: mat("#26312f"),
skin1: mat("#e4a678"),
skin2: mat("#ad6949"),
skin3: mat("#f0bd91"),
hair1: mat("#47322b"),
hair2: mat("#202927"),
hair3: mat("#9a613d")
};
function addBox(parent, w, h, d, x, y, z, material, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, rt, rb, h, x, y, z, material, segments = 16) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, radius, x, y, z, material, segments = 16) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, Math.max(10, segments / 2)),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addLabel(text, width, height, options = {}) {
const {
bg = "#216b60",
fg = "#ffffff",
sub = "",
transparent = false
} = options;
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = Math.max(128, Math.min(320, Math.round(1024 * height / width)));
const ctx = canvas.getContext("2d");
if (bg && !transparent) {
ctx.fillStyle = bg;
ctx.beginPath();
ctx.roundRect(0, 0, canvas.width, canvas.height, 30);
ctx.fill();
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = fg;
ctx.font = `800 ${sub ? 67 : 82}px Arial, sans-serif`;
ctx.fillText(text, canvas.width / 2, sub ? canvas.height * 0.41 : canvas.height * 0.52);
if (sub) {
ctx.globalAlpha = 0.78;
ctx.font = "700 27px Arial, sans-serif";
ctx.fillText(sub, canvas.width / 2, canvas.height * 0.72);
ctx.globalAlpha = 1;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide,
toneMapped: false
})
);
return mesh;
}
function addArrow(x, z, color = "#318374") {
const shape = new THREE.Shape();
shape.moveTo(-0.26, -0.11);
shape.lineTo(0.04, -0.11);
shape.lineTo(0.04, -0.24);
shape.lineTo(0.31, 0);
shape.lineTo(0.04, 0.24);
shape.lineTo(0.04, 0.11);
shape.lineTo(-0.26, 0.11);
shape.closePath();
const arrow = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
new THREE.MeshBasicMaterial({ color, side: THREE.DoubleSide })
);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(x, 0.037, z);
scene.add(arrow);
}
// ------------------------------------------------------------
// Store shell and floor
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
mat("#bfd4cb")
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.29;
ground.receiveShadow = true;
scene.add(ground);
addBox(scene, 18, 0.25, 13, 0, -0.14, 0, M.floor);
addBox(scene, 18, 4.75, 0.18, 0, 2.28, -6.42, M.wall);
addBox(scene, 0.18, 4.75, 13, -8.92, 2.28, 0, M.wall);
addBox(scene, 17.85, 1.15, 0.08, 0, 0.58, -6.29, M.wallGreen);
addBox(scene, 0.08, 1.15, 12.85, -8.79, 0.58, 0, M.wallGreen);
addBox(scene, 17.85, 0.16, 0.12, 0, 0.13, -6.29, M.cream);
addBox(scene, 0.12, 0.16, 12.85, -8.79, 0.13, 0, M.cream);
for (let x = -8; x <= 8; x += 2) {
addBox(scene, 0.012, 0.006, 12.7, x, -0.008, 0, M.floorLine, false);
}
for (let z = -6; z <= 6; z += 2) {
addBox(scene, 17.7, 0.006, 0.012, 0, -0.007, z, M.floorLine, false);
}
// Unobstructed central checkout route.
addBox(scene, 15.25, 0.045, 2.8, -0.55, 0.005, 1.15, M.path);
[-6.8, -3.9, -1.0, 1.9, 4.55].forEach(x => addArrow(x, 1.15));
const routeLabel = addLabel("TO CHECKOUT", 3.2, 0.48, {
fg: "#5d8b7d",
transparent: true
});
routeLabel.rotation.x = -Math.PI / 2;
routeLabel.position.set(0.4, 0.038, 1.75);
scene.add(routeLabel);
// Left-wall windows.
[-4.25, -0.9, 2.45].forEach((z, i) => {
addBox(scene, 0.07, 1.85, 2.5, -8.78, 2.75, z, M.blue, false);
addBox(scene, 0.11, 0.12, 2.7, -8.71, 3.72, z, M.cream);
addBox(scene, 0.11, 2.02, 0.12, -8.71, 2.75, z, M.cream);
addBox(scene, 0.11, 0.12, 2.7, -8.71, 1.79, z, M.cream);
addBox(scene, 0.1, 1.8, 0.07, -8.69, 2.75, z, M.cream);
addBox(scene, 1.25, 0.16, 0.55, -8.42, 1.45, z + (i % 2 ? 0.6 : -0.6), M.teal);
});
// Brand and wall clock.
const brand = addLabel("GROVE & GO", 5.5, 1.05, {
bg: "#1e6257",
fg: "#fff9e8",
sub: "NEIGHBORHOOD MARKET"
});
brand.position.set(-0.55, 4.0, -6.305);
scene.add(brand);
const wallClock = addCylinder(scene, 0.4, 0.4, 0.09, 7.75, 3.78, -6.28, M.cream, 32);
wallClock.rotation.x = Math.PI / 2;
const clockHub = addCylinder(scene, 0.055, 0.055, 0.02, 7.75, 3.78, -6.225, M.dark, 16);
clockHub.rotation.x = Math.PI / 2;
addBox(scene, 0.045, 0.24, 0.025, 7.75, 3.87, -6.205, M.dark, false);
const minute = addBox(scene, 0.035, 0.3, 0.025, 7.87, 3.83, -6.2, M.dark, false);
minute.rotation.z = -0.42;
// ------------------------------------------------------------
// Department shelves
// ------------------------------------------------------------
const departmentColors = {
produce: M.green,
bakery: M.orange,
pantry: M.blue
};
function addShelfProducts(group, type, level, shelfY) {
const count = level === 3 ? 4 : 6;
const colors = [M.red, M.orange, M.yellow, M.green, M.pink, M.purple];
for (let i = 0; i < count; i++) {
const x = -1.24 + i * (2.48 / Math.max(1, count - 1));
const color = colors[(i + level * 2) % colors.length];
if (type === "produce") {
addBox(group, 0.35, 0.14, 0.61, x, shelfY + 0.12, 0.02, M.tan);
addSphere(group, 0.13, x - 0.07, shelfY + 0.26, 0.13, color);
addSphere(group, 0.13, x + 0.08, shelfY + 0.26, -0.06, color);
} else if (type === "bakery") {
addBox(group, 0.35, 0.25, 0.48, x, shelfY + 0.17, 0.01, M.tan);
const loaf = addSphere(group, 0.18, x, shelfY + 0.34, 0.02, M.tan);
loaf.scale.set(1.25, 0.64, 0.72);
addBox(group, 0.09, 0.015, 0.19, x - 0.06, shelfY + 0.45, 0.02, M.cream, false);
addBox(group, 0.09, 0.015, 0.19, x + 0.06, shelfY + 0.45, 0.02, M.cream, false);
} else {
addCylinder(group, 0.135, 0.135, 0.38, x, shelfY + 0.24, 0.02, color, 16);
addCylinder(group, 0.14, 0.14, 0.12, x, shelfY + 0.24, 0.02, M.cream, 16);
addCylinder(group, 0.137, 0.137, 0.025, x, shelfY + 0.445, 0.02, M.metal, 16);
}
}
}
function makeShelf(x, type, title, accent, floorColor) {
const group = new THREE.Group();
group.position.set(x, 0, -4.75);
scene.add(group);
addBox(scene, 3.62, 0.018, 1.72, x, -0.001, -4.7, floorColor, false);
addBox(group, 3.25, 0.2, 1.2, 0, 0.12, 0, accent);
addBox(group, 3.08, 3.22, 0.11, 0, 1.72, -0.57, M.cream);
addBox(group, 0.12, 3.3, 1.12, -1.58, 1.75, 0, accent);
addBox(group, 0.12, 3.3, 1.12, 1.58, 1.75, 0, accent);
const levels = [0.34, 1.16, 1.98, 2.8];
levels.forEach((y, level) => {
addBox(group, 3.08, 0.1, 1.1, 0, y, 0, M.cream);
addBox(group, 3.08, 0.12, 0.07, 0, y - 0.02, 0.56, accent);
addShelfProducts(group, type, level, y);
for (let i = 0; i < 6; i++) {
addBox(
group,
0.19,
0.075,
0.02,
-1.22 + i * 0.49,
y - 0.015,
0.605,
M.white,
false
);
}
});
addBox(group, 2.95, 0.62, 0.12, 0, 3.52, 0.38, accent);
addBox(group, 0.045, 0.34, 0.045, -1.1, 3.2, 0.38, M.metal);
addBox(group, 0.045, 0.34, 0.045, 1.1, 3.2, 0.38, M.metal);
const label = addLabel(title, 2.72, 0.48, {
bg: "#ffffff",
fg: type === "produce" ? "#397e3c" : type === "bakery" ? "#9b5c2e" : "#356d88",
sub: type === "produce" ? "PICKED TODAY" : type === "bakery" ? "BAKED DAILY" : "EVERYDAY ESSENTIALS"
});
label.position.set(0, 3.52, 0.449);
group.add(label);
return group;
}
makeShelf(-5.25, "produce", "FRESH PRODUCE", M.green, mat("#dbe9cc"));
makeShelf(-1.15, "bakery", "BAKERY", M.orange, mat("#f2dfc4"));
makeShelf(2.95, "pantry", "PANTRY", M.blue, mat("#d4e4eb"));
// ------------------------------------------------------------
// Stylized people
// ------------------------------------------------------------
function makePerson({
shirt,
apron = null,
skin = M.skin1,
hair = M.hair1,
cap = false,
longHair = false
}) {
const root = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CapsuleGeometry(0.31, 0.52, 6, 12),
shirt
);
body.position.y = 1.25;
body.castShadow = true;
body.receiveShadow = true;
root.add(body);
const neck = addCylinder(root, 0.11, 0.12, 0.17, 0, 1.79, 0, skin, 12);
const head = addSphere(root, 0.29, 0, 1.98, 0, skin, 20);
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(0.305, 18, 10, 0, Math.PI * 2, 0, Math.PI * 0.55),
hair
);
hairCap.position.y = 2.01;
hairCap.castShadow = true;
root.add(hairCap);
addSphere(root, 0.035, -0.085, 2.0, 0.272, M.black, 10);
addSphere(root, 0.035, 0.085, 2.0, 0.272, M.black, 10);
addSphere(root, 0.055, 0, 1.94, 0.296, skin, 10);
if (longHair) {
const pony = addSphere(root, 0.17, 0, 1.91, -0.22, hair, 14);
pony.scale.set(0.8, 1.25, 0.7);
}
if (cap) {
addCylinder(root, 0.3, 0.31, 0.1, 0, 2.22, 0, M.cream, 20);
addBox(root, 0.48, 0.035, 0.3, 0, 2.2, 0.2, M.cream);
}
if (apron) {
addBox(root, 0.52, 0.72, 0.075, 0, 1.18, 0.287, apron);
addBox(root, 0.38, 0.08, 0.085, 0, 1.5, 0.29, apron);
}
const legs = [];
const shoes = [];
[-1, 1].forEach(side => {
const pivot = new THREE.Group();
pivot.position.set(side * 0.16, 0.76, 0);
root.add(pivot);
addCylinder(pivot, 0.105, 0.12, 0.62, 0, -0.31, 0, M.navy, 12);
const shoe = addBox(pivot, 0.24, 0.14, 0.37, 0, -0.67, 0.075, M.dark);
legs.push(pivot);
shoes.push(shoe);
});
const arms = [];
[-1, 1].forEach(side => {
const pivot = new THREE.Group();
pivot.position.set(side * 0.4, 1.58, 0);
root.add(pivot);
addCylinder(pivot, 0.09, 0.1, 0.54, 0, -0.27, 0, shirt, 12);
addSphere(pivot, 0.105, 0, -0.58, 0, skin, 12);
arms.push(pivot);
});
return { root, head, hairCap, legs, shoes, arms };
}
function makeWorker(x, color, apron, skin, hair, type) {
const person = makePerson({
shirt: color,
apron,
skin,
hair,
cap: true
});
person.root.position.set(x, 0, -3.02);
person.root.rotation.y = Math.PI;
scene.add(person.root);
const packageGroup = new THREE.Group();
if (type === "produce") {
addBox(packageGroup, 0.38, 0.15, 0.38, 0, -0.11, 0, M.tan);
addSphere(packageGroup, 0.13, -0.09, 0.08, 0.02, M.red);
addSphere(packageGroup, 0.13, 0.09, 0.08, -0.02, M.green);
} else if (type === "bakery") {
const bread = addSphere(packageGroup, 0.22, 0, 0, 0, M.tan);
bread.scale.set(1.25, 0.65, 0.75);
} else {
addCylinder(packageGroup, 0.16, 0.16, 0.42, 0, 0, 0, M.blue, 16);
addCylinder(packageGroup, 0.165, 0.165, 0.11, 0, 0.03, 0, M.cream, 16);
}
person.root.add(packageGroup);
// Small replenishment crate beside each worker.
const crate = new THREE.Group();
crate.position.set(x + 0.82, 0, -2.82);
scene.add(crate);
addBox(crate, 0.68, 0.32, 0.56, 0, 0.17, 0, M.tan);
addBox(crate, 0.54, 0.03, 0.43, 0, 0.35, 0, M.brown);
addSphere(crate, 0.14, -0.16, 0.39, 0.03, M.yellow);
addSphere(crate, 0.14, 0.16, 0.39, -0.04, M.red);
return {
...person,
packageGroup,
phase: Math.random(),
type
};
}
const workers = [
makeWorker(-5.25, M.teal, M.mint, M.skin2, M.hair1, "produce"),
makeWorker(-1.15, M.red, M.cream, M.skin1, M.hair3, "bakery"),
makeWorker(2.95, M.blue, M.cream, M.skin3, M.hair2, "pantry")
];
function addBasket(parent) {
const basket = new THREE.Group();
basket.position.set(0.48, 0.92, 0.36);
parent.add(basket);
addBox(basket, 0.43, 0.32, 0.32, 0, 0, 0, M.teal);
addBox(basket, 0.31, 0.035, 0.23, 0, 0.18, 0, M.green);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.025, 8, 20, Math.PI),
M.dark
);
handle.position.set(0, 0.16, 0);
handle.castShadow = true;
basket.add(handle);
return basket;
}
function addCart(parent) {
const cart = new THREE.Group();
cart.position.set(0, 0, 1.05);
parent.add(cart);
addBox(cart, 0.86, 0.08, 0.95, 0, 0.63, 0, M.metal);
addBox(cart, 0.86, 0.08, 0.95, 0, 1.2, 0, M.teal);
addBox(cart, 0.07, 0.58, 0.95, -0.42, 0.92, 0, M.teal);
addBox(cart, 0.07, 0.58, 0.95, 0.42, 0.92, 0, M.teal);
addBox(cart, 0.86, 0.58, 0.07, 0, 0.92, -0.45, M.teal);
[-0.28, 0, 0.28].forEach(x => {
addBox(cart, 0.035, 0.58, 0.035, x, 0.92, 0.46, M.metal);
});
addBox(cart, 0.82, 0.035, 0.05, 0, 1.28, 0.5, M.metal);
addBox(cart, 0.32, 0.24, 0.3, -0.18, 0.8, 0.05, M.yellow);
addBox(cart, 0.3, 0.22, 0.28, 0.2, 0.78, -0.05, M.red);
addSphere(cart, 0.14, 0.15, 0.85, 0.16, M.green);
[-0.48, 0.48].forEach(x => {
[-0.34, 0.34].forEach(z => {
const wheel = addCylinder(cart, 0.1, 0.1, 0.08, x, 0.1, z, M.black, 14);
wheel.rotation.z = Math.PI / 2;
});
});
addBox(cart, 0.045, 0.55, 0.045, -0.43, 0.9, 0.53, M.metal);
addBox(cart, 0.045, 0.55, 0.045, 0.43, 0.9, 0.53, M.metal);
return cart;
}
const shopperA = makePerson({
shirt: M.purple,
skin: M.skin1,
hair: M.hair1,
longHair: true
});
shopperA.root.position.z = 0.15;
addCart(shopperA.root);
scene.add(shopperA.root);
const shopperB = makePerson({
shirt: M.yellow,
skin: M.skin3,
hair: M.hair2
});
shopperB.root.position.z = 2.15;
addBasket(shopperB.root);
scene.add(shopperB.root);
// ------------------------------------------------------------
// Checkout, basket stack, exit, and decorations
// ------------------------------------------------------------
const checkout = new THREE.Group();
checkout.position.set(6.35, 0, 1.15);
scene.add(checkout);
addBox(checkout, 2.7, 0.92, 1.25, 0, 0.46, 0, M.teal);
addBox(checkout, 2.78, 0.12, 1.32, 0, 0.98, 0, M.cream);
addBox(checkout, 2.5, 0.08, 0.9, -0.12, 1.06, 0, M.black);
addBox(checkout, 2.55, 0.035, 0.035, -0.12, 1.12, 0.46, M.metal);
addBox(checkout, 2.55, 0.035, 0.035, -0.12, 1.12, -0.46, M.metal);
addBox(checkout, 0.18, 0.15, 1.15, -1.38, 1.08, 0, M.yellow);
addCylinder(checkout, 0.07, 0.07, 0.62, 0.87, 1.35, -0.18, M.metal, 12);
const monitor = addBox(checkout, 0.62, 0.42, 0.08, 0.87, 1.66, -0.18, M.dark);
monitor.rotation.x = -0.18;
addBox(checkout, 0.48, 0.29, 0.02, 0.87, 1.66, -0.13, M.mint);
addBox(checkout, 0.26, 0.08, 0.26, 0.32, 1.16, 0.16, M.red);
addBox(checkout, 0.75, 0.04, 0.75, 1.04, 1.08, 0, M.tan);
addBox(checkout, 0.3, 0.27, 0.22, 1.05, 1.25, 0, M.cream);
addBox(checkout, 0.34, 0.3, 0.24, 0.78, 1.26, -0.12, M.orange);
addBox(checkout, 0.07, 2.0, 0.07, 0.78, 2.0, -0.22, M.metal);
addBox(checkout, 2.1, 0.64, 0.13, 0.78, 3.05, -0.22, M.teal);
const checkoutLabel = addLabel("CHECKOUT", 1.92, 0.47, {
bg: "#ffffff",
fg: "#216b60",
sub: "PAY · BAG · GO"
});
checkoutLabel.position.set(0.78, 3.05, -0.145);
checkout.add(checkoutLabel);
// Nested basket stack.
for (let i = 0; i < 4; i++) {
addBox(scene, 0.84, 0.2, 0.68, 7.55, 0.12 + i * 0.2, 4.25, i % 2 ? M.teal : M.dark);
addBox(scene, 0.63, 0.025, 0.46, 7.55, 0.235 + i * 0.2, 4.25, M.mint);
}
addBox(scene, 2.25, 0.05, 1.08, 7.25, 0.015, 5.55, M.dark);
const exit = addLabel("EXIT", 1.45, 0.58, {
fg: "#ffffff",
transparent: true
});
exit.rotation.x = -Math.PI / 2;
exit.position.set(7.25, 0.043, 5.55);
scene.add(exit);
// Potted plant.
const plant = new THREE.Group();
plant.position.set(-8.0, 0, 4.8);
scene.add(plant);
addCylinder(plant, 0.38, 0.28, 0.62, 0, 0.31, 0, M.orange, 18);
addCylinder(plant, 0.34, 0.34, 0.05, 0, 0.63, 0, M.brown, 18);
const leafMat = mat("#3c9367");
[
[-0.22, 1.1, 0.05], [0.2, 1.25, -0.04], [0, 1.48, 0.03],
[-0.38, 0.9, -0.08], [0.35, 0.92, 0.1]
].forEach(p => {
const leaf = addSphere(plant, 0.28, p[0], p[1], p[2], leafMat, 12);
leaf.scale.set(0.55, 1.5, 0.42);
leaf.rotation.z = p[0] * 1.8;
});
// Small promotional display beside the checkout.
const promo = new THREE.Group();
promo.position.set(4.85, 0, -4.6);
scene.add(promo);
addBox(promo, 1.1, 1.25, 0.75, 0, 0.63, 0, M.pink);
addBox(promo, 1.22, 0.08, 0.84, 0, 1.3, 0, M.cream);
const promoLabel = addLabel("WEEKLY", 0.88, 0.34, {
bg: "#ffffff",
fg: "#c04f55"
});
promoLabel.position.set(0, 0.82, 0.386);
promo.add(promoLabel);
addBox(promo, 0.27, 0.35, 0.27, -0.25, 1.5, 0, M.red);
addBox(promo, 0.27, 0.35, 0.27, 0.22, 1.5, 0, M.blue);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const packageStart = new THREE.Vector3(0.38, 1.0, 0.22);
const packageEnd = new THREE.Vector3(0.38, 2.55, 0.98);
function animateWorker(worker, time) {
const phase = (time * 0.19 + worker.phase) % 1;
const visible = phase < 0.73;
worker.packageGroup.visible = visible;
if (phase < 0.61) {
const u = THREE.MathUtils.smoothstep(phase / 0.61, 0, 1);
worker.packageGroup.position.lerpVectors(packageStart, packageEnd, u);
worker.packageGroup.rotation.z = Math.sin(u * Math.PI) * 0.08;
worker.arms[1].rotation.x = -0.2 - u * 0.92;
worker.arms[0].rotation.x = -0.18;
} else if (phase < 0.73) {
worker.packageGroup.position.copy(packageEnd);
worker.arms[1].rotation.x = -1.12;
worker.arms[0].rotation.x = -0.2;
} else {
worker.arms[1].rotation.x = -0.18;
worker.arms[0].rotation.x = -0.15;
}
worker.root.rotation.y = Math.PI + Math.sin(time * 0.55 + worker.phase * 9) * 0.045;
worker.head.rotation.y = Math.sin(time * 0.7 + worker.phase * 8) * 0.1;
worker.legs[0].rotation.x = Math.sin(time * 1.2 + worker.phase * 5) * 0.025;
worker.legs[1].rotation.x = -worker.legs[0].rotation.x;
}
function animateShopper(person, phase, time, offset, cart = false) {
person.root.visible = phase > 0.025 && phase < 0.975;
person.root.position.x = -7.35 + 12.7 * phase;
person.root.rotation.y = Math.PI / 2;
const gait = Math.sin(time * 6.4 + offset);
person.legs[0].rotation.x = gait * 0.48;
person.legs[1].rotation.x = -gait * 0.48;
person.arms[0].rotation.x = -gait * 0.36;
if (cart) {
person.arms[0].rotation.x = -0.92;
person.arms[1].rotation.x = -0.92;
} else {
person.arms[1].rotation.x = -0.64;
}
person.head.rotation.z = Math.sin(time * 1.4 + offset) * 0.025;
}
let simulationTime = 0;
let paused = false;
const clock = new THREE.Clock();
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
});
// ------------------------------------------------------------
// Direct camera controls — no external controls module
// ------------------------------------------------------------
function updateCamera() {
const radius = 26;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z + radius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
cameraTheta = 0.73;
cameraPhi = 0.88;
cameraZoom = 1;
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetCamera);
const pointers = new Map();
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function pinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
previousX = event.clientX;
previousY = event.clientY;
previousPinchDistance = pinchDistance();
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const oldX = pointers.get(event.pointerId).x;
const oldY = pointers.get(event.pointerId).y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
cameraTheta -= (event.clientX - oldX) * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - (event.clientY - oldY) * 0.005,
0.43,
1.28
);
updateCamera();
} else if (pointers.size === 2) {
const distance = pinchDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * (distance / previousPinchDistance),
0.68,
1.8
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pinchDistance();
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.8
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = Math.max(15.6, 25.2 / aspect);
camera.left = -frustumHeight * aspect / 2;
camera.right = frustumHeight * aspect / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) simulationTime += delta;
workers.forEach(worker => animateWorker(worker, simulationTime));
const shopperPhaseA = (simulationTime * 0.029 + 0.08) % 1;
const shopperPhaseB = (simulationTime * 0.022 + 0.52) % 1;
animateShopper(shopperA, shopperPhaseA, simulationTime, 0.4, true);
animateShopper(shopperB, shopperPhaseB, simulationTime, 2.1, false);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```