Prompt specification
Build or customize the Three.js 3D scene "Zero-waste shop circulation" 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: Zero-waste shop circulation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/zero-waste-shop-circulation-x0060
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing reusable grocery bags. Create a compact refill shop with bags, jars, scales, and dispensers; a visitor weighs containers, fills them, and packs purchases through a continuous visible route. Voxel style.
Working Three.js Starter (zero-waste-shop-circulation-x0060):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dfe9df" />
<title>The Carry Shop — Voxel Refill Store</title>
<style>
:root {
--ink: #19342f;
--muted: #5d746e;
--paper: #fffdf5;
--mint: #18a889;
--mint-dark: #087461;
--coral: #ef765f;
--gold: #e5b84b;
--blue: #70a8c7;
--line: #c8d9d1;
--shadow: 5px 5px 0 rgba(25, 52, 47, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe9df;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", "Courier New", monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
button {
border: 2px solid var(--ink);
border-radius: 0;
background: var(--paper);
color: var(--ink);
padding: 9px 12px;
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
cursor: pointer;
box-shadow: 3px 3px 0 rgba(25, 52, 47, 0.18);
}
button:hover {
background: #e8fff6;
transform: translateY(-1px);
}
button:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 rgba(25, 52, 47, 0.18);
}
.panel {
background: rgba(255, 253, 245, 0.94);
border: 2px solid var(--ink);
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
}
#brand {
position: fixed;
top: 22px;
left: 22px;
z-index: 5;
width: min(360px, calc(100vw - 44px));
padding: 16px 18px 15px;
pointer-events: none;
}
.eyebrow {
display: inline-block;
margin-bottom: 9px;
padding: 5px 7px;
background: var(--ink);
color: var(--paper);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 36px);
line-height: 0.98;
letter-spacing: -0.07em;
text-transform: uppercase;
}
#brand p {
margin: 10px 0 0;
max-width: 300px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
#controls {
position: fixed;
z-index: 6;
top: 22px;
right: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: min(390px, calc(100vw - 44px));
}
#controls button {
min-width: 44px;
}
#controls .primary {
min-width: 92px;
background: var(--mint);
color: white;
border-color: var(--mint-dark);
}
#step-card {
position: fixed;
z-index: 5;
left: 22px;
bottom: 112px;
width: min(310px, calc(100vw - 44px));
padding: 15px 16px;
pointer-events: none;
}
#step-number {
display: inline-grid;
place-items: center;
width: 31px;
height: 31px;
margin-bottom: 10px;
background: var(--coral);
color: white;
border: 2px solid var(--ink);
font-size: 13px;
font-weight: 900;
}
#step-title {
margin: 0 0 6px;
font-size: 16px;
line-height: 1.15;
text-transform: uppercase;
}
#step-detail {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#timeline {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
width: min(900px, calc(100vw - 44px));
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 6px;
padding: 10px;
}
.step {
position: relative;
min-width: 0;
padding: 10px 7px 9px;
border: 2px solid transparent;
background: #edf2e9;
color: #72847f;
text-align: left;
box-shadow: none;
}
.step::after {
content: "";
position: absolute;
top: 50%;
right: -7px;
z-index: 2;
width: 8px;
height: 2px;
background: #b9cac2;
}
.step:last-child::after {
display: none;
}
.step .num {
display: block;
margin-bottom: 6px;
color: #83958f;
font-size: 9px;
font-weight: 900;
}
.step .name {
display: block;
overflow: hidden;
color: inherit;
font-size: 10px;
font-weight: 800;
line-height: 1.15;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.step.done {
background: #d9f3e9;
color: var(--mint-dark);
}
.step.done .num {
color: var(--mint-dark);
}
.step.active {
border-color: var(--ink);
background: var(--mint);
color: white;
box-shadow: 3px 3px 0 rgba(25, 52, 47, 0.2);
}
.step.active .num {
color: white;
}
#help {
position: fixed;
z-index: 4;
right: 22px;
bottom: 112px;
padding: 8px 10px;
background: rgba(255, 253, 245, 0.8);
border: 1px solid rgba(25, 52, 47, 0.25);
color: var(--muted);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dfe9df;
color: var(--ink);
font-size: 12px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#loading.hidden {
display: none;
}
@media (max-width: 760px) {
#brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 12px 14px;
}
#brand p {
display: none;
}
#controls {
top: 105px;
right: 12px;
max-width: calc(100vw - 24px);
}
#controls button {
padding: 8px 9px;
font-size: 10px;
}
#step-card {
left: 12px;
bottom: 100px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
#step-number {
float: left;
margin: 0 10px 0 0;
}
#step-title {
margin-top: 2px;
font-size: 13px;
}
#step-detail {
clear: both;
padding-top: 7px;
}
#timeline {
left: 12px;
bottom: 12px;
transform: none;
width: calc(100vw - 24px);
gap: 3px;
padding: 6px;
}
.step {
min-height: 54px;
padding: 7px 4px;
}
.step .num {
margin-bottom: 3px;
font-size: 8px;
}
.step .name {
font-size: 8px;
}
#help {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Opening the refill shop…</div>
<section id="brand" class="panel">
<span class="eyebrow">Zero-waste / neighborhood refill</span>
<h1>The Carry Shop</h1>
<p>A compact voxel market for reusable totes, refill dispensers, glass jars, scales, and packed groceries.</p>
</section>
<nav id="controls" aria-label="Scene controls">
<button id="pause" class="primary">❚❚ Pause</button>
<button id="speed">Speed 1×</button>
<button id="reset">Reset</button>
<button id="iso" title="Isometric camera">Iso</button>
<button id="top" title="Top-down camera">Top</button>
</nav>
<section id="step-card" class="panel" aria-live="polite">
<span id="step-number">01</span>
<h2 id="step-title">Choose a reusable tote</h2>
<p id="step-detail">The shopper begins at the bag rack. Every station is connected by the green floor route.</p>
</section>
<div id="help">DRAG TO ORBIT · SCROLL TO ZOOM · SPACE TO PAUSE</div>
<nav id="timeline" class="panel" aria-label="Shopping route"></nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe9df);
scene.fog = new THREE.Fog(0xdfe9df, 30, 56);
const camera = new THREE.OrthographicCamera(-12, 12, 9, -9, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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 ambient = new THREE.HemisphereLight(0xfff8df, 0x6d8f83, 2.1);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.25);
sun.position.set(8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0007;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x9ad9ef, 0.65);
fillLight.position.set(-8, 7, -4);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, options = {}) {
const key = color + JSON.stringify(options);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function block(w, h, d, color, x, y, z, parent = scene, options = {}) {
const mesh = new THREE.Mesh(unitBox, material(color, options));
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(x = 0, y = 0, z = 0, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
return group;
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function makeLabel(text, accent = "#18a889", width = 2.5, height = 0.62) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(25,52,47,0.94)";
ctx.fillRect(0, 0, 512, 128);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 15, 128);
ctx.fillStyle = "#fffdf5";
ctx.font = "800 43px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 263, 67, 460);
const texture = canvasTexture(canvas);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function makeDisplay() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 112;
const ctx = canvas.getContext("2d");
const texture = canvasTexture(canvas);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.05, 0.46, 1);
sprite.renderOrder = 21;
scene.add(sprite);
function update(value, color = "#a8f0c4") {
ctx.fillStyle = "#142824";
ctx.fillRect(0, 0, 256, 112);
ctx.strokeStyle = "#61736e";
ctx.lineWidth = 8;
ctx.strokeRect(4, 4, 248, 104);
ctx.fillStyle = color;
ctx.font = "800 49px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(value, 128, 59, 226);
texture.needsUpdate = true;
}
update("0.00 kg");
return { sprite, update };
}
function makeTote(color = 0x25b89a, small = false) {
const tote = new THREE.Group();
const s = small ? 0.72 : 1;
const w = 0.62 * s;
const h = 0.57 * s;
const d = 0.34 * s;
const t = 0.055 * s;
block(w, t, d, color, 0, -h / 2 + t / 2, 0, tote);
block(w, h * 0.76, t, color, 0, -h * 0.12, d / 2, tote);
block(w, h * 0.76, t, color, 0, -h * 0.12, -d / 2, tote);
block(t, h * 0.76, d, color, -w / 2 + t / 2, -h * 0.12, 0, tote);
block(t, h * 0.76, d, color, w / 2 - t / 2, -h * 0.12, 0, tote);
const handleColor = new THREE.Color(color).multiplyScalar(0.74).getHex();
block(t, 0.34 * s, t, handleColor, -w * 0.3, h * 0.47, 0, tote);
block(t, 0.34 * s, t, handleColor, w * 0.3, h * 0.47, 0, tote);
block(w * 0.64, t, t, handleColor, 0, h * 0.64, 0, tote);
const goods = groupAt(0, -h * 0.34, 0, tote);
const apple = block(0.15 * s, 0.15 * s, 0.15 * s, 0xef765f,
-0.13 * s, 0.07 * s, 0.01 * s, goods);
const loaf = block(0.22 * s, 0.16 * s, 0.16 * s, 0xe5b84b,
0.08 * s, 0.08 * s, -0.02 * s, goods);
const greens = block(0.14 * s, 0.19 * s, 0.14 * s, 0x65b76b,
0.05 * s, 0.15 * s, 0.09 * s, goods);
goods.visible = false;
return { group: tote, goods, apple, loaf, greens };
}
function makeJar() {
const jar = new THREE.Group();
const glass = material(0xb9e8e5, {
transparent: true,
opacity: 0.38,
roughness: 0.12,
depthWrite: false
});
const body = new THREE.Mesh(unitBox, glass);
body.scale.set(0.43, 0.56, 0.43);
body.position.y = 0;
body.castShadow = true;
jar.add(body);
const inner = block(0.34, 0.08, 0.34, 0xd9a85c, 0, -0.23, 0, jar);
const lid = block(0.49, 0.09, 0.49, 0x315f59, 0, 0.32, 0, jar);
lid.visible = false;
return { group: jar, inner, lid, glassBody: body };
}
// Room shell and tiled floor.
block(17.5, 0.72, 12.5, 0xc9b895, 0, -0.4, 0);
block(17.3, 0.18, 12.3, 0x8fa99e, 0, -0.03, 0);
const tileColors = [0xf4eddb, 0xeaf0df, 0xf8f2e4];
for (let x = 0; x < 17; x++) {
for (let z = 0; z < 12; z++) {
const color = tileColors[(x + z * 2) % tileColors.length];
block(0.97, 0.08, 0.97, color, -8 + x, 0.035, -5.5 + z).castShadow = false;
}
}
// Back and left walls, leaving the front and right open.
block(17.4, 3.9, 0.38, 0xeadfca, 0, 1.95, -6.08);
block(0.38, 3.9, 12.2, 0xd8e5d6, -8.52, 1.95, 0);
block(17.5, 0.22, 0.55, 0x9fc9b7, 0, 3.93, -6.08);
block(0.55, 0.22, 12.2, 0x9fc9b7, -8.52, 3.93, 0);
block(17.1, 0.72, 0.08, 0xaecdbd, 0, 0.48, -5.86);
block(0.08, 0.72, 12.0, 0xaecdbd, -8.3, 0.48, 0);
// Back-wall sign.
block(6.4, 1.45, 0.18, 0x244c43, 0, 3.0, -5.79);
const shopSign = makeLabel("CARRY / REFILL + REUSE", "#f0c75e", 5.9, 1.13);
shopSign.position.set(0, 3.03, -5.64);
// Decorative voxel windows.
for (const x of [-6.0, 5.9]) {
block(2.35, 1.75, 0.15, 0x315f59, x, 2.45, -5.79);
block(2.08, 1.48, 0.08, 0x8dc8d7, x, 2.45, -5.69);
block(0.09, 1.5, 0.1, 0xd7eee5, x, 2.45, -5.62);
block(2.1, 0.09, 0.1, 0xd7eee5, x, 2.45, -5.62);
}
// Reusable tote rack.
const toteRack = groupAt(-7.05, 0, 3.45);
block(1.9, 0.16, 0.92, 0x315f59, 0, 0.12, 0, toteRack);
block(0.15, 2.35, 0.15, 0x315f59, -0.82, 1.22, 0, toteRack);
block(0.15, 2.35, 0.15, 0x315f59, 0.82, 1.22, 0, toteRack);
block(1.8, 0.16, 0.16, 0x315f59, 0, 2.34, 0, toteRack);
const rackTotes = [
makeTote(0xef765f, true),
makeTote(0xe5b84b, true),
makeTote(0x4cb9a5, true)
];
rackTotes.forEach((tote, index) => {
tote.group.position.set(-0.58 + index * 0.58, 1.56, 0.08);
tote.group.rotation.y = index === 1 ? 0.08 : -0.04;
toteRack.add(tote.group);
});
const toteLabel = makeLabel("1 / REUSABLE TOTES", "#ef765f", 2.65, 0.58);
toteLabel.position.set(-7.0, 2.85, 3.45);
// Scale station.
const scaleStation = groupAt(-5.75, 0, 0.35);
block(2.2, 0.18, 1.45, 0xe0b96c, 0, 1.0, 0, scaleStation);
for (const x of [-0.88, 0.88]) {
for (const z of [-0.52, 0.52]) {
block(0.15, 0.92, 0.15, 0x557a6e, x, 0.47, z, scaleStation);
}
}
block(1.32, 0.16, 1.02, 0x244c43, 0, 1.19, 0, scaleStation);
block(1.12, 0.1, 0.84, 0xa9b7ae, 0, 1.32, 0, scaleStation);
block(0.1, 0.73, 0.1, 0x244c43, 0.63, 1.57, -0.26, scaleStation);
const scaleDisplay = makeDisplay();
scaleDisplay.sprite.position.set(-5.12, 1.93, 0.09);
scaleDisplay.update("0.00 kg");
const scaleJar = makeJar();
scaleJar.group.position.set(-5.78, 1.65, 0.35);
scaleJar.inner.visible = false;
scaleStation.add(scaleJar.group);
const scaleLabel = makeLabel("2 / WEIGH", "#70a8c7", 2.0, 0.56);
scaleLabel.position.set(-5.65, 2.55, 0.35);
// Refill dispensers.
const dispenserXs = [-2.25, 0, 2.25];
const dispenserNames = ["GRAIN", "OATS", "SOAP"];
const dispenserColors = [0xe5b84b, 0xd9a85c, 0x73b9a4];
dispenserXs.forEach((x, index) => {
const unit = groupAt(x, 0, -5.13);
block(1.65, 0.22, 1.28, 0x315f59, 0, 0.16, 0, unit);
block(1.45, 1.25, 1.05, 0xf1e7d2, 0, 0.9, 0, unit);
block(1.42, 0.85, 1.04, dispenserColors[index], 0, 2.05, 0, unit);
block(1.2, 0.68, 0.08, 0x85cfc9, 0, 1.02, 0.55, unit,
{ transparent: true, opacity: 0.34, depthWrite: false });
block(1.07, 0.56, 0.12, dispenserColors[index], 0, 0.98, 0.57, unit);
block(0.28, 0.42, 0.6, 0x315f59, 0, 1.62, 0.48, unit);
block(0.14, 0.15, 0.72, 0x244c43, 0, 1.42, 0.7, unit);
block(0.58, 0.11, 0.13, 0x244c43, 0, 1.28, 0.66, unit);
block(0.22, 0.14, 0.22, 0xef765f, 0.46, 1.13, 0.6, unit);
const label = makeLabel(dispenserNames[index], "#e5b84b", 1.45, 0.42);
label.position.set(x, 2.7, -5.1);
});
const fillLabel = makeLabel("3 / REFILL", "#e5b84b", 2.2, 0.58);
fillLabel.position.set(0, 3.3, -5.1);
// Jar and lid shelf.
const shelf = groupAt(4.25, 0, -4.86);
block(3.4, 0.18, 1.18, 0xe0b96c, 0, 1.0, 0, shelf);
for (const x of [-1.48, 1.48]) {
block(0.15, 0.92, 0.9, 0x557a6e, x, 0.47, 0, shelf);
}
block(3.2, 0.13, 0.13, 0x315f59, 0, 1.7, -0.45, shelf);
block(0.13, 0.78, 0.13, 0x315f59, -1.48, 1.37, -0.45, shelf);
block(0.13, 0.78, 0.13, 0x315f59, 1.48, 1.37, -0.45, shelf);
const shelfJars = [];
[-1.0, -0.35, 0.35, 1.0].forEach((x, i) => {
const jar = makeJar();
jar.group.scale.setScalar(i % 2 ? 0.8 : 0.95);
jar.group.position.set(x, 1.43, 0);
jar.inner.visible = false;
shelf.add(jar.group);
shelfJars.push(jar);
});
[-1.15, -0.55, 0.45, 1.1].forEach((x) => {
block(0.5, 0.09, 0.5, 0x315f59, x, 2.02, -0.4, shelf);
});
const sealLabel = makeLabel("4 / JAR + LID", "#8b73b6", 2.35, 0.56);
sealLabel.position.set(4.25, 2.63, -4.86);
// Packing bench.
const packBench = groupAt(5.6, 0, 1.75);
block(3.25, 0.2, 1.9, 0xe0b96c, 0, 1.0, 0, packBench);
for (const x of [-1.35, 1.35]) {
for (const z of [-0.7, 0.7]) {
block(0.16, 0.9, 0.16, 0x557a6e, x, 0.46, z, packBench);
}
}
block(0.82, 0.42, 0.62, 0xef765f, -0.88, 1.31, -0.2, packBench);
block(0.62, 0.28, 0.55, 0x8fcf83, -0.86, 1.67, -0.18, packBench);
const benchJar = makeJar();
benchJar.group.scale.setScalar(0.9);
benchJar.group.position.set(0.03, 1.52, -0.2);
benchJar.inner.visible = false;
packBench.add(benchJar.group);
block(0.45, 0.45, 0.45, 0x315f59, 1.05, 1.33, 0.36, packBench);
const packLabel = makeLabel("5 / PACK", "#ef765f", 1.9, 0.56);
packLabel.position.set(5.7, 2.5, 1.75);
// Checkout counter.
const checkout = groupAt(0.7, 0, 3.65);
block(3.7, 1.15, 1.35, 0x5e9785, 0, 0.57, 0, checkout);
block(3.95, 0.18, 1.55, 0x315f59, 0, 1.22, 0, checkout);
block(0.58, 0.5, 0.46, 0x244c43, 0.9, 1.55, -0.1, checkout);
block(0.43, 0.3, 0.12, 0xa8f0c4, 0.9, 1.61, 0.16, checkout);
block(0.1, 1.45, 0.1, 0x315f59, -0.9, 1.9, -0.25, checkout);
block(0.4, 0.3, 0.22, 0xef765f, -0.9, 2.63, -0.25, checkout);
const checkoutLabel = makeLabel("6 / CHECKOUT", "#70a8c7", 2.45, 0.56);
checkoutLabel.position.set(0.7, 2.95, 3.65);
// Decorative back-left shelf and canisters.
block(3.6, 0.18, 0.85, 0x315f59, -5.55, 1.35, -5.48);
block(3.6, 0.18, 0.85, 0x315f59, -5.55, 2.35, -5.48);
[-6.85, -6.15, -5.45, -4.75].forEach((x, i) => {
block(0.43, 0.62, 0.45, [0xe5b84b, 0xef765f, 0x79b89f, 0x8ab9d1][i],
x, 1.75, -5.4);
});
[-6.8, -6.15, -5.5].forEach((x, i) => {
block(0.48, 0.55, 0.48, [0xd9a85c, 0x79b89f, 0xe5b84b][i],
x, 2.72, -5.4);
});
// Voxel plant by the entrance.
const plant = groupAt(7.05, 0, 4.65);
block(0.7, 0.72, 0.7, 0xd47c5f, 0, 0.36, 0, plant);
block(0.12, 1.15, 0.12, 0x4d8060, 0, 1.25, 0, plant);
block(0.55, 0.35, 0.5, 0x67a85e, -0.22, 1.48, 0, plant);
block(0.48, 0.42, 0.45, 0x79b86c, 0.25, 1.75, 0, plant);
block(0.38, 0.35, 0.4, 0x4f9361, 0.02, 2.08, 0, plant);
// A continuous closed shopping route.
const routePoints = [
[-7.05, 0.105, 3.45],
[-6.35, 0.105, 2.25],
[-4.90, 0.105, 0.50],
[-4.90, 0.105, -1.85],
[-2.35, 0.105, -3.55],
[0.00, 0.105, -3.90],
[2.75, 0.105, -3.30],
[4.80, 0.105, -1.20],
[4.65, 0.105, 1.70],
[4.35, 0.105, 3.20],
[2.00, 0.105, 4.35],
[0.00, 0.105, 4.80],
[-3.45, 0.105, 4.80],
[-6.25, 0.105, 4.72]
].map((p) => new THREE.Vector3(...p));
const routeCurve = new THREE.CatmullRomCurve3(
routePoints,
true,
"catmullrom",
0.18
);
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeSegments = 150;
const zAxis = new THREE.Vector3(0, 0, 1);
for (let i = 0; i < routeSegments; i++) {
const a = routeCurve.getPointAt(i / routeSegments);
const b = routeCurve.getPointAt((i + 1) / routeSegments);
const direction = b.clone().sub(a);
const length = direction.length();
const segment = block(
0.17,
0.045,
length + 0.055,
0x18a889,
(a.x + b.x) / 2,
0.105,
(a.z + b.z) / 2,
routeGroup
);
segment.quaternion.setFromUnitVectors(zAxis, direction.normalize());
segment.castShadow = false;
}
// Directional chevrons reinforce the visible route.
for (let i = 0; i < 15; i++) {
const u = i / 15;
const p = routeCurve.getPointAt(u);
const tangent = routeCurve.getTangentAt(u);
const arrow = groupAt(p.x, 0.145, p.z, routeGroup);
arrow.rotation.y = Math.atan2(tangent.x, tangent.z);
const shaft = block(0.13, 0.035, 0.45, 0xf7e276, 0, 0, -0.05, arrow);
shaft.castShadow = false;
const left = block(0.11, 0.035, 0.31, 0xf7e276, -0.085, 0, 0.13, arrow);
left.rotation.y = 0.5;
left.castShadow = false;
const right = block(0.11, 0.035, 0.31, 0xf7e276, 0.085, 0, 0.13, arrow);
right.rotation.y = -0.5;
right.castShadow = false;
}
function nearestU(x, z) {
let bestU = 0;
let bestDistance = Infinity;
for (let i = 0; i < 3000; i++) {
const u = i / 3000;
const p = routeCurve.getPointAt(u);
const d = (p.x - x) ** 2 + (p.z - z) ** 2;
if (d < bestDistance) {
bestDistance = d;
bestU = u;
}
}
return bestU;
}
const events = [
{
index: 0,
short: "Tote",
title: "Choose a reusable tote",
detail: "The shopper picks a sturdy reusable grocery bag instead of a single-use carrier.",
kind: "tote",
duration: 1.5,
u: nearestU(-7.05, 3.45)
},
{
index: 1,
short: "Weigh",
title: "Weigh the empty container",
detail: "The glass jar is checked at the scale before it is filled.",
kind: "weigh",
duration: 2.5,
u: nearestU(-4.90, 0.50)
},
{
index: 2,
short: "Fill",
title: "Fill at the dispenser",
detail: "A measured portion of loose grains drops directly into the jar.",
kind: "fill",
duration: 3.2,
u: nearestU(0.00, -3.90)
},
{
index: 3,
short: "Seal",
title: "Choose a reusable lid",
detail: "A sturdy square lid is selected from the jar and fitting shelf.",
kind: "seal",
duration: 2.1,
u: nearestU(2.75, -3.30)
},
{
index: 4,
short: "Pack",
title: "Pack the purchases",
detail: "Refilled goods are arranged inside the reusable tote for the trip home.",
kind: "pack",
duration: 3.0,
u: nearestU(4.65, 1.70)
},
{
index: 5,
short: "Checkout",
title: "Scan and go",
detail: "The packed tote is checked, and the shopper begins the return trip.",
kind: "checkout",
duration: 2.0,
u: nearestU(2.00, 4.35)
}
];
// Voxel shopper.
const visitor = groupAt(0, 0.08, 0);
const bodyPivot = groupAt(0, 0, 0, visitor);
const leftLeg = groupAt(-0.2, 0.77, 0, bodyPivot);
const rightLeg = groupAt(0.2, 0.77, 0, bodyPivot);
for (const leg of [leftLeg, rightLeg]) {
block(0.25, 0.6, 0.28, 0x315f59, 0, -0.3, 0, leg);
block(0.28, 0.16, 0.42, 0x203b37, 0, -0.66, 0.07, leg);
}
block(0.76, 0.76, 0.46, 0xef765f, 0, 1.08, 0, bodyPivot);
block(0.8, 0.13, 0.5, 0x315f59, 0, 1.39, 0, bodyPivot);
block(0.5, 0.48, 0.48, 0xe6b18b, 0, 1.68, 0, bodyPivot);
block(0.53, 0.17, 0.51, 0x3b332e, 0, 1.94, 0, bodyPivot);
block(0.08, 0.08, 0.08, 0x203b37, -0.12, 1.7, 0.251, bodyPivot);
block(0.08, 0.08, 0.08, 0x203b37, 0.12, 1.7, 0.251, bodyPivot);
const leftArm = groupAt(-0.5, 1.34, 0, bodyPivot);
const rightArm = groupAt(0.5, 1.34, 0, bodyPivot);
for (const arm of [leftArm, rightArm]) {
block(0.2, 0.57, 0.24, 0xef765f, 0, -0.27, 0, arm);
block(0.2, 0.18, 0.22, 0xe6b18b, 0, -0.62, 0, arm);
}
const shopperTote = makeTote(0x18a889, true);
shopperTote.group.position.set(0.5, 0.35, 0.18);
shopperTote.group.visible = false;
bodyPivot.add(shopperTote.group);
const heldJar = makeJar();
heldJar.group.position.set(0, 0.98, 0.49);
heldJar.group.visible = false;
bodyPivot.add(heldJar.group);
// Grain particles used during the refill action.
const fillParticles = [];
for (let i = 0; i < 18; i++) {
const particle = block(
0.065,
0.065,
0.065,
i % 3 === 0 ? 0xf1cc70 : 0xd9a85c,
0,
1.75,
-4.42,
scene
);
particle.visible = false;
fillParticles.push(particle);
}
// Simulation state.
let routeProgress = 0;
let eventIndex = 0;
let currentAction = null;
let actionElapsed = 0;
let wrapPending = false;
let paused = false;
let speed = 1;
let walkingPhase = 0;
let toteTaken = false;
let jarTaken = false;
let jarFilled = 0;
let lidAdded = false;
let goodsPacked = 0;
let lastScaleText = "0.00 kg";
const timeline = document.getElementById("timeline");
const stepNodes = events.map((event) => {
const button = document.createElement("button");
button.className = "step";
button.innerHTML =
`<span class="num">${String(event.index + 1).padStart(2, "0")}</span>` +
`<span class="name">${event.short}</span>`;
button.addEventListener("click", () => jumpToEvent(event.index));
timeline.appendChild(button);
return button;
});
const stepNumber = document.getElementById("step-number");
const stepTitle = document.getElementById("step-title");
const stepDetail = document.getElementById("step-detail");
const pauseButton = document.getElementById("pause");
const speedButton = document.getElementById("speed");
function updateUI() {
const shown = currentAction || events[eventIndex];
if (!shown) return;
stepNumber.textContent = String(shown.index + 1).padStart(2, "0");
stepTitle.textContent = shown.title;
stepDetail.textContent = shown.detail;
stepNodes.forEach((node, index) => {
node.classList.toggle("active", shown.index === index);
node.classList.toggle("done", index < eventIndex);
});
}
function resetSimulation() {
routeProgress = 0;
eventIndex = 0;
currentAction = null;
actionElapsed = 0;
wrapPending = false;
toteTaken = false;
jarTaken = false;
jarFilled = 0;
lidAdded = false;
goodsPacked = 0;
shopperTote.group.visible = false;
shopperTote.goods.visible = false;
heldJar.group.visible = false;
heldJar.inner.visible = false;
heldJar.lid.visible = false;
scaleDisplay.update("0.00 kg");
fillParticles.forEach((particle) => (particle.visible = false));
updateUI();
}
function jumpToEvent(index) {
resetSimulation();
routeProgress = events[index].u;
currentAction = events[index];
actionElapsed = 0;
eventIndex = (index + 1) % events.length;
wrapPending = index === events.length - 1;
updateUI();
}
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "▶ Play" : "❚❚ Pause";
});
speedButton.addEventListener("click", () => {
speed = speed === 1 ? 1.5 : speed === 1.5 ? 2 : 1;
speedButton.textContent = `Speed ${speed}×`;
});
document.getElementById("reset").addEventListener("click", resetSimulation);
// Direct, custom camera controls — no external controls module.
let azimuth = 0.72;
let elevation = 0.68;
let cameraZoom = 1;
const cameraTarget = new THREE.Vector3(0, 0.7, 0);
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const radius = 30;
camera.position.set(
cameraTarget.x + radius * Math.sin(azimuth) * Math.cos(elevation),
cameraTarget.y + radius * Math.sin(elevation),
cameraTarget.z + radius * Math.cos(azimuth) * Math.cos(elevation)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
azimuth -= dx * 0.006;
elevation = THREE.MathUtils.clamp(elevation + dy * 0.0045, 0.34, 1.48);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * (event.deltaY > 0 ? 0.92 : 1.08),
0.68,
1.72
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
azimuth = 0.72;
elevation = 0.68;
cameraZoom = 1;
updateCamera();
});
document.getElementById("iso").addEventListener("click", () => {
azimuth = 0.72;
elevation = 0.68;
cameraZoom = 1;
updateCamera();
});
document.getElementById("top").addEventListener("click", () => {
azimuth = 0;
elevation = 1.48;
cameraZoom = 1;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") resetSimulation();
if (event.key.toLowerCase() === "t") document.getElementById("top").click();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(8.5, 10.7 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateUI();
function updateActionVisuals() {
const kind = currentAction?.kind;
const progress = currentAction
? THREE.MathUtils.clamp(actionElapsed / currentAction.duration, 0, 1)
: 0;
shopperTote.group.visible = toteTaken || kind === "tote";
heldJar.group.visible = jarTaken && !(kind === "pack" && progress > 0.12);
if (kind === "weigh") {
const reading = progress < 0.55 ? "0.00 kg" : "0.42 kg";
scaleDisplay.update(reading);
if (reading !== lastScaleText) {
lastScaleText = reading;
}
} else if (kind === "fill") {
scaleDisplay.update("0.42 kg");
} else {
scaleDisplay.update(lastScaleText);
}
if (kind === "fill") {
jarFilled = Math.max(jarFilled, 0.14 + progress * 0.72);
}
const fillHeight = Math.max(0.04, jarFilled * 0.45);
heldJar.inner.visible = jarFilled > 0.01;
heldJar.inner.scale.y = fillHeight / 0.08;
heldJar.inner.position.y = -0.23 + fillHeight / 2;
if (kind === "seal") {
heldJar.lid.visible = progress > 0.38;
if (progress > 0.38) lidAdded = true;
} else {
heldJar.lid.visible = lidAdded;
}
if (kind === "pack") {
goodsPacked = Math.max(goodsPacked, progress);
shopperTote.goods.visible = goodsPacked > 0.1;
shopperTote.apple.visible = goodsPacked > 0.18;
shopperTote.loaf.visible = goodsPacked > 0.42;
shopperTote.greens.visible = goodsPacked > 0.67;
} else if (goodsPacked > 0) {
shopperTote.goods.visible = true;
shopperTote.apple.visible = true;
shopperTote.loaf.visible = true;
shopperTote.greens.visible = true;
}
const particlesVisible = kind === "fill";
fillParticles.forEach((particle, index) => {
particle.visible = particlesVisible;
if (!particlesVisible) return;
const phase = (actionElapsed * 1.65 + index * 0.137) % 1;
particle.position.set(
Math.sin(index * 2.17) * 0.075,
1.72 - phase * 0.46,
-4.42 + Math.cos(index * 1.73) * 0.055
);
particle.rotation.x += 0.04;
particle.rotation.y += 0.03;
});
}
function updateVisitor(dt, elapsed) {
const position = routeCurve.getPointAt(routeProgress);
const tangent = routeCurve.getTangentAt(routeProgress);
let targetRotation = Math.atan2(tangent.x, tangent.z);
if (currentAction) {
const facings = {
tote: Math.atan2(0, 1),
weigh: Math.atan2(-0.85, -0.15),
fill: Math.PI,
seal: Math.atan2(1.45, -1.55),
pack: Math.atan2(1.05, 0.05),
checkout: Math.atan2(-1.3, -0.65)
};
targetRotation = facings[currentAction.kind];
}
let angleDifference = targetRotation - visitor.rotation.y;
angleDifference = Math.atan2(Math.sin(angleDifference), Math.cos(angleDifference));
visitor.rotation.y += angleDifference * Math.min(1, dt * 10);
const walking = !currentAction && !paused;
if (walking) walkingPhase += dt * 9 * speed;
const swing = walking ? Math.sin(walkingPhase) * 0.48 : 0;
leftLeg.rotation.x = swing;
rightLeg.rotation.x = -swing;
leftArm.rotation.x = -swing * 0.75;
rightArm.rotation.x = swing * 0.75;
let bodyBob = walking ? Math.abs(Math.sin(walkingPhase)) * 0.035 : 0;
let bodyLean = 0;
if (currentAction?.kind === "weigh") {
rightArm.rotation.x = -0.75;
leftArm.rotation.x = -0.2;
bodyLean = -0.05;
} else if (currentAction?.kind === "fill") {
leftArm.rotation.x = -0.9;
rightArm.rotation.x = -0.9;
bodyLean = -0.03;
} else if (currentAction?.kind === "seal") {
rightArm.rotation.x = -1.05;
bodyLean = 0.02;
} else if (currentAction?.kind === "pack") {
leftArm.rotation.x = -1.2;
rightArm.rotation.x = -1.2;
bodyLean = 0.17;
bodyBob = -0.05;
} else if (currentAction?.kind === "checkout") {
rightArm.rotation.x = -0.65;
bodyLean = -0.05;
}
bodyPivot.position.y = bodyBob;
bodyPivot.rotation.x = bodyLean;
visitor.position.set(position.x, 0.08, position.z);
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const simDt = paused ? 0 : dt * speed;
if (simDt > 0) {
if (currentAction) {
actionElapsed += simDt;
if (actionElapsed >= currentAction.duration) {
if (currentAction.kind === "tote") toteTaken = true;
if (currentAction.kind === "weigh") {
jarTaken = true;
lastScaleText = "0.42 kg";
}
if (currentAction.kind === "fill") jarFilled = 0.86;
if (currentAction.kind === "seal") lidAdded = true;
if (currentAction.kind === "pack") goodsPacked = 1;
currentAction = null;
actionElapsed = 0;
if (wrapPending) {
routeProgress = 0;
wrapPending = false;
}
}
} else {
const nextEvent = events[eventIndex];
const travelSpeed = 0.027;
if (routeProgress < nextEvent.u - 0.0001) {
routeProgress = Math.min(
nextEvent.u,
routeProgress + travelSpeed * simDt
);
} else {
currentAction = nextEvent;
actionElapsed = 0;
eventIndex = (eventIndex + 1) % events.length;
if (eventIndex === 0) wrapPending = true;
}
}
}
updateActionVisuals();
updateVisitor(dt, elapsed);
updateUI();
renderer.render(scene, camera);
}
animate();
document.getElementById("loading").classList.add("hidden");
</script>
</body>
</html>
```