Prompt specification
Build or customize the Three.js 3D scene "Neighborhood bulk-food shop" 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: Neighborhood bulk-food shop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-bulk-food-shop-x0527
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: neighborhood bulk-food shop. Compose dispensers, jars, scale, checkout, and washing station; visitors bring containers through a continuous weigh-fill-pay route with each selected product remaining clearly identified.
Working Three.js Starter (neighborhood-bulk-food-shop-x0527):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Corner Bulk — Voxel Refill Shop</title>
<style>
:root {
--ink: #173d35;
--muted: #6c7b70;
--cream: #f8f2e8;
--paper: rgba(255, 251, 243, 0.94);
--line: rgba(23, 61, 53, 0.13);
--gold: #e9b84c;
--orange: #d77b45;
--teal: #2d7567;
}
* { box-sizing: border-box; }
html, body, #app {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
background: #efe5d5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: absolute;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
z-index: 3;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
padding: 10px 14px 10px 10px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(255, 251, 243, 0.85);
backdrop-filter: blur(12px);
box-shadow: 0 9px 30px rgba(43, 48, 38, 0.08);
}
.brand-mark {
display: grid;
place-items: center;
width: 37px;
height: 37px;
border-radius: 11px;
color: var(--cream);
background: var(--ink);
font-size: 21px;
font-weight: 900;
letter-spacing: -5px;
padding-right: 5px;
}
.brand strong {
display: block;
font-size: 13px;
letter-spacing: 0.13em;
}
.brand small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
}
.top-actions {
display: flex;
gap: 8px;
pointer-events: auto;
}
.small-button {
border: 1px solid var(--line);
border-radius: 12px;
padding: 11px 13px;
color: var(--ink);
background: rgba(255, 251, 243, 0.88);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
box-shadow: 0 6px 20px rgba(43, 48, 38, 0.06);
}
.small-button:hover {
background: #fffdf8;
transform: translateY(-1px);
}
#hud {
position: absolute;
top: 91px;
left: 20px;
width: 342px;
max-height: calc(100vh - 116px);
overflow: auto;
padding: 19px;
border: 1px solid var(--line);
border-radius: 21px;
background: var(--paper);
backdrop-filter: blur(15px);
box-shadow: 0 18px 45px rgba(43, 48, 38, 0.13);
z-index: 4;
}
.eyebrow {
color: var(--orange);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 7px;
font-size: 28px;
line-height: 1.02;
letter-spacing: -0.055em;
}
.intro {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 9px;
color: var(--ink);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-label span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: none;
}
#productGrid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-bottom: 16px;
}
.product {
display: flex;
align-items: center;
gap: 8px;
min-height: 57px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
background: rgba(255, 255, 255, 0.58);
text-align: left;
cursor: pointer;
transition: 0.16s ease;
}
.product:hover:not(:disabled) {
transform: translateY(-1px);
border-color: rgba(23, 61, 53, 0.32);
background: #fffdf9;
}
.product.active {
border: 2px solid var(--ink);
padding: 7px;
background: #fffdf8;
box-shadow: 0 4px 12px rgba(23, 61, 53, 0.08);
}
.product:disabled {
opacity: 0.58;
cursor: not-allowed;
}
.swatch {
flex: 0 0 auto;
width: 25px;
height: 25px;
border-radius: 7px;
box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.12),
inset 0 3px 0 rgba(255, 255, 255, 0.22);
}
.product strong {
display: block;
font-size: 11px;
line-height: 1.1;
}
.product small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.bag-card {
display: grid;
grid-template-columns: 1fr auto;
gap: 4px 10px;
align-items: center;
padding: 12px 13px;
margin-bottom: 15px;
border-radius: 14px;
background: #e9f0e7;
border: 1px solid rgba(45, 117, 103, 0.16);
}
.bag-card .label {
grid-column: 1 / -1;
color: var(--teal);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#bagName {
font-size: 14px;
font-weight: 850;
}
#bagWeight {
grid-column: 1;
color: var(--muted);
font-size: 10px;
}
#bagPrice {
grid-row: 2 / 4;
grid-column: 2;
color: var(--ink);
font-size: 16px;
font-weight: 900;
}
.steps {
display: grid;
gap: 7px;
margin: 0 0 16px;
padding: 0;
list-style: none;
}
.step {
display: grid;
grid-template-columns: 23px 1fr auto;
align-items: center;
gap: 8px;
padding: 8px 9px;
border-radius: 10px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.step .number {
display: grid;
place-items: center;
width: 22px;
height: 22px;
border-radius: 7px;
color: var(--muted);
background: rgba(23, 61, 53, 0.07);
font-size: 10px;
font-weight: 900;
}
.step.active {
color: var(--ink);
background: rgba(233, 184, 76, 0.17);
}
.step.active .number {
color: var(--cream);
background: var(--ink);
}
.step.done {
color: var(--teal);
}
.step.done .number {
color: white;
background: var(--teal);
}
.step small {
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
#action {
width: 100%;
min-height: 49px;
padding: 12px 14px;
border: 0;
border-radius: 12px;
color: #fff9ed;
background: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.06em;
transition: 0.16s ease;
}
#action:hover:not(:disabled) {
background: #28584c;
transform: translateY(-1px);
box-shadow: 0 7px 15px rgba(23, 61, 53, 0.17);
}
#action:disabled {
cursor: wait;
opacity: 0.65;
}
#hint {
min-height: 31px;
margin: 10px 2px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.scene-note {
position: absolute;
right: 20px;
bottom: 20px;
max-width: 250px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 14px;
color: var(--ink);
background: rgba(255, 251, 243, 0.86);
backdrop-filter: blur(12px);
box-shadow: 0 10px 28px rgba(43, 48, 38, 0.09);
z-index: 3;
pointer-events: none;
}
.scene-note strong {
display: block;
margin-bottom: 4px;
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.scene-note span {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.legend {
display: flex;
align-items: center;
gap: 7px;
margin-top: 8px;
font-size: 10px;
color: var(--muted);
}
.legend-dot {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--gold);
box-shadow: 0 0 0 3px rgba(233, 184, 76, 0.2);
}
@media (max-width: 700px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
padding: 8px 10px 8px 8px;
}
.brand strong { font-size: 10px; }
.brand small { font-size: 7px; }
.top-actions .small-button {
padding: 10px;
font-size: 9px;
}
#hud {
top: auto;
bottom: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 47vh;
padding: 14px;
border-radius: 17px;
}
h1 { font-size: 23px; }
.intro { margin-bottom: 12px; }
.scene-note { display: none; }
#productGrid { grid-template-columns: repeat(3, 1fr); }
.product { min-height: 49px; }
.product small { font-size: 8px; }
}
</style>
</head>
<body>
<div id="app">
<div id="viewport"></div>
<div class="topbar">
<div class="brand">
<div class="brand-mark">▦</div>
<div>
<strong>THE CORNER BULK</strong>
<small>REUSABLE • LOCAL • GOOD</small>
</div>
</div>
<div class="top-actions">
<button id="resetView" class="small-button">RESET VIEW</button>
</div>
</div>
<aside id="hud">
<div class="eyebrow">Neighborhood refill station</div>
<h1>Bring your own<br>and take home good.</h1>
<p class="intro">
Choose a product and follow the golden route:
wash, weigh, fill, then pay. Your container stays labeled all the way.
</p>
<div class="section-label">
Choose your refill
<span>prices per kg</span>
</div>
<div id="productGrid"></div>
<div class="bag-card">
<div class="label">Your labeled container</div>
<div id="bagName">Wheat</div>
<div id="bagWeight">Empty • ready for the wash station</div>
<div id="bagPrice">$2.40</div>
</div>
<ol id="stepList" class="steps">
<li class="step active" data-step="0">
<span class="number">1</span>
<span>Wash container</span>
<small>clean</small>
</li>
<li class="step" data-step="1">
<span class="number">2</span>
<span>Fill & weigh</span>
<small>1 kg</small>
</li>
<li class="step" data-step="2">
<span class="number">3</span>
<span>Pay</span>
<small>take home</small>
</li>
</ol>
<button id="action">1 BRING CONTAINER TO WASH</button>
<p id="hint" aria-live="polite">
Drag the scene to orbit. Scroll or pinch to zoom.
</p>
</aside>
<div class="scene-note">
<strong>One continuous route</strong>
<span>The golden line connects the wash station, selected dispenser, scale, and checkout.</span>
<div class="legend">
<span class="legend-dot"></span>
<span>Follow the route from entrance to exit</span>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scene setup
// ---------------------------------------------------------------------
const viewport = document.querySelector("#viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xefe5d5);
scene.fog = new THREE.Fog(0xefe5d5, 20, 36);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
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;
viewport.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xfff9ea, 0x6e806e, 2.2);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.3);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(1536, 1536);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xcde7df, 1.15);
fillLight.position.set(9, 7, -8);
scene.add(fillLight);
const mats = {
wall: new THREE.MeshStandardMaterial({
color: 0xd8c9b1,
roughness: 0.95
}),
wallLight: new THREE.MeshStandardMaterial({
color: 0xeadbc4,
roughness: 0.95
}),
floor: new THREE.MeshStandardMaterial({
color: 0xc9b99e,
roughness: 0.93
}),
tileA: new THREE.MeshStandardMaterial({
color: 0xd8c9ae,
roughness: 0.92
}),
tileB: new THREE.MeshStandardMaterial({
color: 0xcbb99c,
roughness: 0.92
}),
wood: new THREE.MeshStandardMaterial({
color: 0x9e704b,
roughness: 0.82
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf4ecdc,
roughness: 0.8
}),
teal: new THREE.MeshStandardMaterial({
color: 0x39786c,
roughness: 0.74
}),
deepTeal: new THREE.MeshStandardMaterial({
color: 0x214e46,
roughness: 0.78
}),
coral: new THREE.MeshStandardMaterial({
color: 0xce7954,
roughness: 0.8
}),
dark: new THREE.MeshStandardMaterial({
color: 0x263a35,
roughness: 0.7
}),
metal: new THREE.MeshStandardMaterial({
color: 0xaebbb2,
roughness: 0.34,
metalness: 0.55
}),
gold: new THREE.MeshStandardMaterial({
color: 0xe7b64b,
roughness: 0.55
}),
skin: new THREE.MeshStandardMaterial({
color: 0xd99f78,
roughness: 0.9
}),
hair: new THREE.MeshStandardMaterial({
color: 0x3b2f28,
roughness: 1
}),
glass: new THREE.MeshStandardMaterial({
color: 0xd6e8df,
roughness: 0.12,
metalness: 0.05,
transparent: true,
opacity: 0.32,
depthWrite: false
}),
water: new THREE.MeshStandardMaterial({
color: 0x8ed0d0,
roughness: 0.15,
transparent: true,
opacity: 0.68
})
};
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0,
...extra
});
}
function box(parent, size, position, material, rotation = null) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
if (rotation) mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radius, height, position, material) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, 8),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Canvas-based labels: no external font or image assets.
function makeLabel(lines, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = options.canvasWidth || 768;
canvas.height = options.canvasHeight || 192;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: options.depthTest !== false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const width = options.width || 2.4;
sprite.scale.set(width, width * canvas.height / canvas.width, 1);
sprite.renderOrder = options.renderOrder || 5;
function setLines(nextLines) {
const arr = Array.isArray(nextLines) ? nextLines : [nextLines];
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = options.bg || "#173d35";
ctx.fillRect(0, 0, canvas.width, canvas.height);
if (options.border !== false) {
ctx.strokeStyle = options.borderColor || "rgba(255,255,255,.2)";
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
}
const fontSize = options.fontSize || (arr.length > 1 ? 34 : 46);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = options.fg || "#fff8e9";
ctx.font = `900 ${fontSize}px system-ui, sans-serif`;
const lineHeight = fontSize * 1.18;
const start = canvas.height / 2 - ((arr.length - 1) * lineHeight) / 2;
arr.forEach((line, i) => {
ctx.fillText(String(line), canvas.width / 2, start + i * lineHeight);
});
texture.needsUpdate = true;
}
setLines(lines);
return {
sprite,
texture,
setLines
};
}
function addLabel(parent, lines, position, options = {}) {
const label = makeLabel(lines, options);
label.sprite.position.set(position[0], position[1], position[2]);
parent.add(label.sprite);
return label;
}
// ---------------------------------------------------------------------
// Shop construction
// ---------------------------------------------------------------------
const products = [
{
id: "wheat",
name: "Wheat",
color: 0xd9a441,
css: "#d9a441",
price: 2.40,
x: -4.4,
note: "stone-ground"
},
{
id: "rice",
name: "Rice",
color: 0xe5d8ae,
css: "#e5d8ae",
price: 1.90,
x: -2.2,
note: "long grain"
},
{
id: "beans",
name: "Beans",
color: 0x8c4a3c,
css: "#8c4a3c",
price: 4.50,
x: 0,
note: "pinto beans"
},
{
id: "oats",
name: "Oats",
color: 0xc89455,
css: "#c89455",
price: 2.20,
x: 2.2,
note: "rolled flakes"
},
{
id: "lentils",
name: "Lentils",
color: 0xd77b45,
css: "#d77b45",
price: 3.10,
x: 4.4,
note: "red lentils"
}
];
let selectedProduct = products[0];
// Floor and walls.
box(scene, [14, 0.3, 10], [0, -0.2, 0], mats.floor);
for (let ix = 0; ix < 7; ix++) {
for (let iz = 0; iz < 5; iz++) {
const material = (ix + iz) % 2 ? mats.tileA : mats.tileB;
box(
scene,
[1.94, 0.075, 1.94],
[-6 + ix * 2, 0.015, -4 + iz * 2],
material
);
}
}
box(scene, [14, 5.5, 0.25], [0, 2.7, -5], mats.wall);
box(scene, [0.25, 5.5, 10], [-7, 2.7, 0], mats.wallLight);
box(scene, [14, 0.15, 0.3], [0, 0.26, -4.82], mats.wood);
box(scene, [0.3, 0.15, 10], [-6.82, 0.26, 0], mats.wood);
box(scene, [14, 0.18, 0.35], [0, 5.34, -4.8], mats.deepTeal);
addLabel(
scene,
["THE CORNER BULK", "REUSABLE REFILL MARKET"],
[0, 4.78, -4.77],
{
width: 7.1,
bg: "#214e46",
fg: "#fff5df",
fontSize: 35
}
);
// Counter below dispensers.
box(scene, [12, 0.55, 1.25], [0, 0.37, -4], mats.wood);
box(scene, [12.3, 0.12, 1.36], [0, 0.7, -4], mats.cream);
const dispenserVisuals = new Map();
function buildDispenser(product) {
const group = new THREE.Group();
group.position.set(product.x, 0, -4);
scene.add(group);
box(group, [1.56, 1.02, 1.04], [0, 1.24, 0], mats.cream);
box(group, [1.66, 0.12, 1.1], [0, 0.79, 0], mats.wood);
box(group, [1.38, 1.28, 0.86], [0, 2.25, 0], mats.glass);
box(group, [1.48, 0.12, 0.94], [0, 2.94, 0], mats.cream);
const contents = new THREE.Group();
group.add(contents);
const contentMat = standard(product.color);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
box(
contents,
[0.31, 0.34, 0.62],
[-0.36 + col * 0.36, 1.98 + row * 0.38, 0],
contentMat
);
}
}
box(group, [0.22, 0.42, 0.22], [0, 0.95, 0.62], mats.metal);
box(group, [0.44, 0.13, 0.18], [0, 0.72, 0.67], mats.metal);
box(group, [0.42, 0.12, 0.08], [0, 1.62, 0.56], contentMat);
box(group, [0.16, 0.16, 0.08], [0, 1.25, 0.57], mats.gold);
addLabel(
group,
[product.name.toUpperCase(), `$${product.price.toFixed(2)} / kg`],
[0, 3.34, 0.25],
{
width: 1.57,
bg: product.css,
fg: "#20372f",
fontSize: 30
}
);
const halo = box(
group,
[1.88, 0.055, 1.4],
[0, 0.79, 0],
standard(0xf6c75a, {
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
halo.visible = false;
dispenserVisuals.set(product.id, { group, halo, contents });
}
products.forEach(buildDispenser);
// Right-hand pantry shelf with voxel jars.
const shelf = new THREE.Group();
shelf.position.set(6, 0, -2.1);
scene.add(shelf);
box(shelf, [0.16, 4.1, 0.16], [-0.65, 2.05, -1.25], mats.wood);
box(shelf, [0.16, 4.1, 0.16], [0.65, 2.05, -1.25], mats.wood);
box(shelf, [0.16, 4.1, 0.16], [-0.65, 2.05, 1.25], mats.wood);
box(shelf, [0.16, 4.1, 0.16], [0.65, 2.05, 1.25], mats.wood);
[0.9, 2, 3.1].forEach((height) => {
box(shelf, [1.45, 0.13, 2.7], [0, height, 0], mats.wood);
});
addLabel(
shelf,
["PANTRY JARS"],
[0, 4.45, -0.7],
{
width: 1.7,
bg: "#f4ecdc",
fg: "#214e46",
fontSize: 35
}
);
function makeJar(x, y, z, product, parent = scene) {
const jar = new THREE.Group();
jar.position.set(x, y, z);
parent.add(jar);
box(jar, [0.54, 0.68, 0.54], [0, 0.34, 0], mats.glass);
box(jar, [0.44, 0.48, 0.44], [0, 0.28, 0], standard(product.color));
box(jar, [0.6, 0.12, 0.6], [0, 0.73, 0], mats.wood);
addLabel(
jar,
[product.name.toUpperCase()],
[0, 0.99, 0],
{
width: 0.78,
bg: product.css,
fg: "#20372f",
fontSize: 34
}
);
}
const jarProducts = [
products[1], products[3], products[0],
products[4], products[2], products[1]
];
jarProducts.forEach((product, i) => {
const level = Math.floor(i / 2);
const side = i % 2 === 0 ? -0.3 : 0.3;
const row = i < 4 ? 0 : 1;
makeJar(
6 + side,
[0.97, 2.07][level],
-2.95 + row * 1.55,
product
);
});
// Wash station.
const wash = new THREE.Group();
wash.position.set(-5, 0, 1.25);
scene.add(wash);
box(wash, [2.45, 0.96, 1.35], [0, 0.54, 0], mats.teal);
box(wash, [2.6, 0.15, 1.45], [0, 1.09, 0], mats.cream);
box(wash, [1.38, 0.07, 0.88], [-0.18, 1.19, 0.03], mats.dark);
box(wash, [1.13, 0.025, 0.67], [-0.18, 1.235, 0.03], mats.water);
box(wash, [0.13, 0.56, 0.13], [-0.18, 1.46, -0.48], mats.metal);
box(wash, [0.13, 0.12, 0.66], [-0.18, 1.74, -0.18], mats.metal);
box(wash, [0.13, 0.28, 0.13], [-0.18, 1.62, 0.1], mats.metal);
box(wash, [0.24, 0.43, 0.24], [0.88, 1.37, -0.05], mats.gold);
box(wash, [0.12, 0.09, 0.12], [0.88, 1.62, -0.05], mats.deepTeal);
box(wash, [0.82, 0.035, 0.57], [0.64, 1.19, 0.23], standard(0xb99a6a));
addLabel(
wash,
["WASH + RINSE", "BRING YOUR CONTAINER"],
[0, 2.35, 0.35],
{
width: 2.45,
bg: "#39786c",
fg: "#fff6df",
fontSize: 32
}
);
// Scale / filling station.
const scaleStation = new THREE.Group();
scaleStation.position.set(0, 0, -0.5);
scene.add(scaleStation);
box(scaleStation, [1.65, 0.86, 1.2], [0, 0.48, 0], mats.deepTeal);
box(scaleStation, [1.8, 0.13, 1.28], [0, 0.97, 0], mats.cream);
box(scaleStation, [1.38, 0.08, 0.92], [0, 1.08, 0], mats.metal);
box(scaleStation, [0.1, 0.92, 0.1], [0.95, 1.45, -0.22], mats.dark);
box(scaleStation, [0.82, 0.34, 0.13], [0.95, 1.96, -0.22], mats.dark);
const scaleFill = box(
scaleStation,
[0.78, 0.28, 0.56],
[0, 1.25, 0],
standard(selectedProduct.color)
);
scaleFill.visible = false;
const scaleReadout = addLabel(
scaleStation,
["0.00 KG"],
[0.95, 2.18, -0.18],
{
width: 1.05,
bg: "#183b34",
fg: "#d9f0a4",
fontSize: 37
}
);
addLabel(
scaleStation,
["WEIGH + FILL", "ONE KILOGRAM"],
[-0.1, 2.62, 0.2],
{
width: 2.55,
bg: "#f4ecdc",
fg: "#214e46",
fontSize: 33
}
);
// Checkout station.
const checkout = new THREE.Group();
checkout.position.set(4.6, 0, 1.1);
scene.add(checkout);
box(checkout, [2.85, 1.08, 1.4], [0, 0.58, 0], mats.coral);
box(checkout, [3, 0.15, 1.52], [0, 1.2, 0], mats.cream);
box(checkout, [0.55, 0.26, 0.42], [-0.55, 1.4, -0.08], mats.dark);
box(
checkout,
[0.72, 0.48, 0.12],
[-0.55, 1.76, -0.16],
mats.dark,
[-0.12, 0, 0]
);
box(checkout, [0.48, 0.27, 0.05], [-0.55, 1.76, -0.085], mats.teal);
box(checkout, [0.48, 0.1, 0.36], [-0.55, 1.31, 0.4], mats.deepTeal);
for (let i = 0; i < 6; i++) {
box(
checkout,
[0.08, 0.03, 0.08],
[-0.72 + (i % 3) * 0.16,
1.38,
0.32 + Math.floor(i / 3) * 0.13],
mats.gold
);
}
const checkoutBag = box(
checkout,
[0.62, 0.78, 0.46],
[0.83, 1.66, 0.12],
standard(0xbc8b58)
);
checkoutBag.visible = false;
box(checkout, [0.3, 0.1, 0.08], [0.83, 2.08, 0.12], mats.wood);
addLabel(
checkout,
["PAY + THANK YOU", "REUSABLE REFILL"],
[0, 2.48, 0.3],
{
width: 2.72,
bg: "#ce7954",
fg: "#fff6df",
fontSize: 32
}
);
// Entrance marker.
box(scene, [2.45, 0.04, 1.1], [-2.7, 0.08, 4.15], mats.deepTeal);
addLabel(
scene,
["WELCOME", "BRING A CONTAINER"],
[-2.7, 0.35, 4.72],
{
width: 2.2,
bg: "#214e46",
fg: "#fff6df",
fontSize: 29
}
);
// ---------------------------------------------------------------------
// Route
// ---------------------------------------------------------------------
const entrance = new THREE.Vector3(-2.7, 0, 4.15);
const washApproach = new THREE.Vector3(-5, 0, 2.48);
const scaleApproach = new THREE.Vector3(0, 0, 0.48);
const checkoutApproach = new THREE.Vector3(4.6, 0, 2.02);
const exit = new THREE.Vector3(6.05, 0, 4.15);
const routeLine = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineDashedMaterial({
color: 0xe8b443,
dashSize: 0.26,
gapSize: 0.17,
transparent: true,
opacity: 0.92
})
);
routeLine.position.y = 0.095;
routeLine.renderOrder = 2;
scene.add(routeLine);
function updateRoute() {
const dispenserApproach = new THREE.Vector3(
selectedProduct.x,
0,
-2.35
);
const points = [
entrance,
washApproach,
dispenserApproach,
scaleApproach,
checkoutApproach,
exit
];
routeLine.geometry.dispose();
routeLine.geometry = new THREE.BufferGeometry().setFromPoints(points);
routeLine.computeLineDistances();
dispenserVisuals.forEach((visual, id) => {
visual.halo.visible = id === selectedProduct.id;
});
}
[
entrance,
washApproach,
scaleApproach,
checkoutApproach,
exit
].forEach((point) => {
box(
scene,
[0.3, 0.055, 0.3],
[point.x, 0.09, point.z],
mats.gold
);
});
// ---------------------------------------------------------------------
// Visitors
// ---------------------------------------------------------------------
function makeShopper(x, z, shirtColor, product, scale = 0.86) {
const shopper = new THREE.Group();
shopper.position.set(x, 0, z);
shopper.scale.setScalar(scale);
scene.add(shopper);
box(shopper, [0.52, 0.68, 0.38], [0, 0.98, 0], standard(shirtColor));
box(shopper, [0.44, 0.44, 0.42], [0, 1.56, 0], mats.skin);
box(shopper, [0.48, 0.16, 0.46], [0, 1.81, 0], mats.hair);
box(shopper, [0.18, 0.57, 0.18], [-0.16, 0.29, 0], mats.dark);
box(shopper, [0.18, 0.57, 0.18], [0.16, 0.29, 0], mats.dark);
box(shopper, [0.15, 0.6, 0.17], [-0.37, 0.98, 0], standard(shirtColor));
box(shopper, [0.15, 0.6, 0.17], [0.37, 0.98, 0], standard(shirtColor));
const jar = new THREE.Group();
jar.position.set(0.53, 0.95, 0.06);
shopper.add(jar);
box(jar, [0.38, 0.46, 0.38], [0, 0, 0], mats.glass);
box(jar, [0.3, 0.32, 0.3], [0, -0.03, 0], standard(product.color));
box(jar, [0.42, 0.08, 0.42], [0, 0.27, 0], mats.wood);
addLabel(
jar,
[product.name.toUpperCase()],
[0, 0.63, 0],
{
width: 0.9,
bg: product.css,
fg: "#20372f",
fontSize: 31
}
);
return shopper;
}
makeShopper(-3.05, 2.82, 0xb7684d, products[1]);
makeShopper(3.05, -2.78, 0x567f91, products[2], 0.78);
// Main active visitor.
const visitor = new THREE.Group();
visitor.position.copy(entrance);
scene.add(visitor);
box(visitor, [0.58, 0.75, 0.42], [0, 1.02, 0], mats.teal);
box(visitor, [0.48, 0.48, 0.45], [0, 1.67, 0], mats.skin);
box(visitor, [0.52, 0.17, 0.48], [0, 1.93, 0], mats.hair);
box(visitor, [0.18, 0.58, 0.18], [-0.17, 0.29, 0], mats.dark);
box(visitor, [0.18, 0.58, 0.18], [0.17, 0.29, 0], mats.dark);
box(visitor, [0.15, 0.62, 0.17], [-0.39, 1.01, 0], mats.teal);
box(visitor, [0.15, 0.62, 0.17], [0.39, 1.01, 0], mats.teal);
const container = new THREE.Group();
container.position.set(0.56, 1.08, 0.02);
visitor.add(container);
box(container, [0.5, 0.58, 0.5], [0, 0, 0], mats.glass);
box(container, [0.56, 0.11, 0.56], [0, 0.34, 0], mats.wood);
const containerFillMaterial = standard(selectedProduct.color);
const containerFill = box(
container,
[0.4, 0.43, 0.4],
[0, -0.065, 0],
containerFillMaterial
);
containerFill.visible = false;
const visitorTag = addLabel(
visitor,
["YOU"],
[0, 2.42, 0],
{
width: 0.9,
bg: "#e9b84c",
fg: "#173d35",
fontSize: 40
}
);
const containerTag = addLabel(
container,
[selectedProduct.name.toUpperCase(), "EMPTY • SELECTED"],
[0, 0.82, 0],
{
width: 1.9,
bg: "#173d35",
fg: "#fff5df",
fontSize: 27
}
);
// ---------------------------------------------------------------------
// Camera controls implemented without external addons
// ---------------------------------------------------------------------
const orbit = {
theta: 0.72,
phi: 0.93,
radius: 16.5,
target: new THREE.Vector3(0.25, 1.15, -0.55)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.cos(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.sin(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
let dragging = false;
let previousPointer = { x: 0, y: 0 };
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.48,
1.43
);
previousPointer = { x: event.clientX, y: event.clientY };
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
10.5,
24
);
updateCamera();
}, { passive: false });
document.querySelector("#resetView").addEventListener("click", () => {
orbit.theta = 0.72;
orbit.phi = 0.93;
orbit.radius = 16.5;
orbit.target.set(0.25, 1.15, -0.55);
updateCamera();
});
// ---------------------------------------------------------------------
// Interface and route state
// ---------------------------------------------------------------------
const productGrid = document.querySelector("#productGrid");
const actionButton = document.querySelector("#action");
const hint = document.querySelector("#hint");
const bagName = document.querySelector("#bagName");
const bagWeight = document.querySelector("#bagWeight");
const bagPrice = document.querySelector("#bagPrice");
const stepElements = [...document.querySelectorAll(".step")];
let state = "ready";
let phase = 0;
let fillAmount = 0;
let travelTween = null;
let fillTween = null;
products.forEach((product) => {
const button = document.createElement("button");
button.className = "product";
button.type = "button";
button.dataset.product = product.id;
button.innerHTML = `
<span class="swatch" style="background:${product.css}"></span>
<span>
<strong>${product.name}</strong>
<small>${product.note} · $${product.price.toFixed(2)}</small>
</span>
`;
button.addEventListener("click", () => {
if (state !== "ready" && state !== "washed") return;
selectProduct(product.id);
});
productGrid.appendChild(button);
});
function updateProductButtons() {
document.querySelectorAll(".product").forEach((button) => {
const active = button.dataset.product === selectedProduct.id;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
button.disabled = state !== "ready" && state !== "washed";
});
}
function updateContainerLabel() {
let subline = "EMPTY • SELECTED";
if (state === "washed") subline = "CLEAN • READY";
if (state === "moving" && phase === 1) subline = "CLEAN • ON THE WAY";
if (state === "filling") subline = "FILLING...";
if (state === "filled") subline = "1.00 KG • WEIGHED";
if (state === "paid") subline = "1.00 KG • PAID";
if (state === "moving" && phase === 2) subline = "1.00 KG • TO PAY";
containerTag.setLines([
selectedProduct.name.toUpperCase(),
subline
]);
}
function selectProduct(id) {
selectedProduct = products.find((product) => product.id === id);
containerFillMaterial.color.setHex(selectedProduct.color);
updateProductButtons();
updateContainerLabel();
updateRoute();
hint.textContent =
`${selectedProduct.name} is selected. Its dispenser and your container label are highlighted.`;
}
function setState(nextState, nextPhase = phase) {
state = nextState;
phase = nextPhase;
stepElements.forEach((element, index) => {
element.classList.toggle("active", index === phase && state !== "paid");
element.classList.toggle("done", state === "paid" || index < phase);
});
const moving = state === "moving" || state === "filling";
actionButton.disabled = moving;
updateProductButtons();
updateContainerLabel();
if (state === "ready") {
actionButton.textContent = "1 BRING CONTAINER TO WASH";
hint.textContent = "Bring your reusable container to the wash station.";
} else if (state === "washed") {
actionButton.textContent = `2 FILL WITH ${selectedProduct.name.toUpperCase()}`;
hint.textContent =
`The ${selectedProduct.name.toLowerCase()} dispenser is highlighted. Continue to the scale.`;
} else if (state === "filled") {
actionButton.textContent = "3 PAY & FINISH";
hint.textContent =
`${selectedProduct.name} is labeled and weighed at 1.00 kg. Take it to checkout.`;
} else if (state === "paid") {
actionButton.textContent = "START ANOTHER REFILL";
hint.textContent =
`Payment complete: $${selectedProduct.price.toFixed(2)} for 1 kg of ${selectedProduct.name.toLowerCase()}.`;
} else if (state === "filling") {
actionButton.textContent = "FILLING YOUR CONTAINER...";
hint.textContent =
`The scale is measuring ${selectedProduct.name.toLowerCase()} to one kilogram.`;
} else if (state === "moving") {
actionButton.textContent = "FOLLOWING THE ROUTE...";
hint.textContent = "Your labeled container stays with you at every station.";
}
bagName.textContent = selectedProduct.name;
bagPrice.textContent = `$${selectedProduct.price.toFixed(2)}`;
if (state === "filled" || state === "paid" ||
(state === "moving" && phase === 2)) {
bagWeight.textContent = "1.00 kg • reusable container";
} else if (state === "washed") {
bagWeight.textContent = "Clean • ready for the selected product";
} else if (state === "filling") {
bagWeight.textContent = "Filling and weighing...";
} else {
bagWeight.textContent = "Empty • ready for the wash station";
}
}
// Smooth travel between waypoints.
function travel(points, onComplete) {
const waypoints = points.map((point) => point.clone());
function nextWaypoint() {
if (!waypoints.length) {
if (onComplete) onComplete();
return;
}
const to = waypoints.shift();
const from = visitor.position.clone();
const distance = from.distanceTo(to);
const duration = Math.max(430, distance * 105);
travelTween = {
from,
to,
start: performance.now(),
duration,
onComplete: nextWaypoint
};
visitor.rotation.y = Math.atan2(
to.x - from.x,
to.z - from.z
);
}
nextWaypoint();
}
function beginRoute() {
setState("moving", 0);
travel([washApproach], () => {
setState("washed", 1);
});
}
function beginFill() {
setState("moving", 1);
const dispenserApproach = new THREE.Vector3(
selectedProduct.x,
0,
-2.35
);
travel([dispenserApproach, scaleApproach], () => {
setState("filling", 1);
fillTween = {
start: performance.now(),
duration: 1250,
onComplete: () => {
setState("filled", 1);
}
};
});
}
function beginPayment() {
setState("moving", 2);
travel([checkoutApproach], () => {
checkoutBag.visible = true;
setState("paid", 3);
});
}
function resetRoute() {
visitor.position.copy(entrance);
visitor.rotation.y = 0;
fillAmount = 0;
containerFill.visible = false;
containerFill.scale.y = 0.01;
scaleFill.visible = false;
scaleReadout.setLines(["0.00 KG"]);
checkoutBag.visible = false;
setState("ready", 0);
}
actionButton.addEventListener("click", () => {
if (state === "ready") beginRoute();
else if (state === "washed") beginFill();
else if (state === "filled") beginPayment();
else if (state === "paid") resetRoute();
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
function smoothStep(value) {
return value * value * (3 - 2 * value);
}
function animate(now) {
requestAnimationFrame(animate);
if (travelTween) {
const progress = Math.min(
1,
(now - travelTween.start) / travelTween.duration
);
const eased = smoothStep(progress);
visitor.position.lerpVectors(
travelTween.from,
travelTween.to,
eased
);
if (progress >= 1) {
const callback = travelTween.onComplete;
travelTween = null;
if (callback) callback();
}
}
if (fillTween) {
const progress = Math.min(
1,
(now - fillTween.start) / fillTween.duration
);
fillAmount = smoothStep(progress);
containerFill.visible = fillAmount > 0.01;
containerFill.scale.y = Math.max(0.01, fillAmount);
containerFill.position.y = -0.22 + 0.215 * fillAmount;
scaleFill.visible = true;
scaleFill.scale.y = Math.max(0.01, fillAmount);
scaleFill.position.y = 1.1 + 0.14 * fillAmount;
scaleReadout.setLines([
`${fillAmount.toFixed(2)} KG`,
selectedProduct.name.toUpperCase()
]);
if (progress >= 1) {
const callback = fillTween.onComplete;
fillTween = null;
if (callback) callback();
}
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateProductButtons();
updateRoute();
updateContainerLabel();
setState("ready", 0);
requestAnimationFrame(animate);
</script>
</body>
</html>
```