Prompt specification
Build or customize the Three.js 3D scene "Weekly market neighborhood block" 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: Weekly market neighborhood block
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/weekly-market-neighborhood-block-x0507
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Build a short market street with produce, books, flowers, and seating; animated shoppers follow different shopping lists while every stall remains reachable from both entrances.
Working Three.js Starter (weekly-market-neighborhood-block-x0507):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Market Lane — Voxel Market</title>
<style>
:root {
--ink: #173b37;
--muted: #64756f;
--paper: rgba(255, 255, 255, 0.9);
--line: rgba(23, 59, 55, 0.12);
--green: #2b8c78;
--orange: #ef765c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7e6df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.brand {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
max-width: 390px;
pointer-events: none;
text-shadow: 0 1px 12px rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #42645d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 4px rgba(239, 118, 92, 0.16);
content: "";
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 850;
letter-spacing: -0.055em;
line-height: 0.98;
}
.brand p {
max-width: 340px;
margin: 10px 0 0;
color: #526a63;
font-size: 13px;
line-height: 1.5;
}
.shopper-panel {
position: fixed;
top: 22px;
right: 22px;
z-index: 6;
width: 306px;
pointer-events: none;
}
.panel-heading {
display: flex;
align-items: end;
justify-content: space-between;
margin: 0 4px 10px;
}
.panel-heading strong {
font-size: 13px;
letter-spacing: 0.02em;
}
.panel-heading span {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.shopper-card {
margin-bottom: 9px;
padding: 13px 14px 12px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(39, 70, 63, 0.1);
backdrop-filter: blur(12px);
}
.shopper-header {
display: flex;
align-items: center;
gap: 10px;
}
.avatar {
display: grid;
width: 31px;
height: 31px;
flex: 0 0 auto;
place-items: center;
border-radius: 10px;
color: white;
font-size: 13px;
font-weight: 850;
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.09);
}
.shopper-name {
min-width: 0;
flex: 1;
}
.shopper-name strong {
display: block;
font-size: 13px;
}
.shopper-name small {
display: block;
margin-top: 1px;
color: var(--muted);
font-size: 10px;
}
.shopper-state {
max-width: 95px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
text-align: right;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.shopping-list {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin: 11px 0 10px;
padding: 0;
list-style: none;
}
.shopping-list li {
padding: 4px 7px;
border: 1px solid var(--line);
border-radius: 7px;
color: #67766f;
background: rgba(255, 255, 255, 0.45);
font-size: 9px;
font-weight: 750;
transition: 0.25s ease;
}
.shopping-list li.collected {
border-color: transparent;
color: #276f61;
background: #dceee7;
text-decoration: line-through;
text-decoration-color: rgba(39, 111, 97, 0.45);
}
.progress {
height: 4px;
overflow: hidden;
border-radius: 4px;
background: rgba(23, 59, 55, 0.08);
}
.progress span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--green);
transition: width 0.35s ease;
}
.network-card {
position: fixed;
bottom: 23px;
left: 24px;
z-index: 6;
max-width: 310px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(39, 70, 63, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
}
.network-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 850;
}
.network-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #36a780;
box-shadow: 0 0 0 4px rgba(54, 167, 128, 0.13);
}
.network-card p {
margin: 6px 0 0 17px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.controls {
position: fixed;
bottom: 24px;
left: 50%;
z-index: 8;
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(39, 70, 63, 0.12);
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
.controls button {
padding: 8px 11px;
border: 0;
border-radius: 9px;
color: var(--ink);
background: #edf2ed;
font: inherit;
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: 0.18s ease;
}
.controls button:hover {
color: white;
background: var(--ink);
}
.controls button[aria-pressed="true"] {
color: white;
background: var(--green);
}
.control-hint {
padding: 0 8px 0 4px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
white-space: nowrap;
}
.toast {
position: fixed;
top: 22px;
left: 50%;
z-index: 10;
padding: 10px 15px;
border-radius: 12px;
color: white;
background: rgba(23, 59, 55, 0.92);
box-shadow: 0 10px 25px rgba(23, 59, 55, 0.2);
font-size: 11px;
font-weight: 750;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -12px);
transition: 0.25s ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: var(--ink);
background: #d7e6df;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 0.4s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.brand {
top: 15px;
left: 15px;
max-width: 260px;
}
.brand p {
display: none;
}
.shopper-panel {
top: auto;
right: 10px;
bottom: 12px;
left: 10px;
display: flex;
width: auto;
gap: 9px;
overflow-x: auto;
padding-bottom: 4px;
}
.panel-heading {
display: none;
}
.shopper-card {
width: 225px;
min-width: 225px;
margin: 0;
}
.network-card {
display: none;
}
.controls {
top: 94px;
bottom: auto;
left: 12px;
transform: none;
}
.control-hint {
display: none;
}
.toast {
top: 151px;
max-width: 90%;
text-align: center;
}
}
@media (max-width: 480px) {
h1 {
font-size: 32px;
}
.eyebrow {
font-size: 9px;
}
.controls button {
padding: 7px 9px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel market street"></canvas>
<header class="brand">
<div class="eyebrow">Open-air voxel market</div>
<h1>Market Lane</h1>
<p>
A tiny shopping street with connected stalls, animated visitors,
fresh produce, books, flowers, and room to sit.
</p>
</header>
<aside class="shopper-panel" aria-label="Shoppers and their lists">
<div class="panel-heading">
<strong>Today’s shoppers</strong>
<span>Live lists</span>
</div>
<div id="shopperCards"></div>
</aside>
<section class="network-card">
<div class="network-title">
<span class="network-dot"></span>
<span id="reachText">Checking the walk map…</span>
</div>
<p id="reachDetail">Every stall is connected to both street entrances.</p>
</section>
<nav class="controls" aria-label="Scene controls">
<button id="resetView" type="button">View all</button>
<button id="toggleRoutes" type="button" aria-pressed="true">Walk map</button>
<span class="control-hint">Drag to orbit · Scroll to zoom · Click a stall</span>
</nav>
<div class="toast" id="toast" role="status"></div>
<div id="loading">Opening the market…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const toast = document.querySelector("#toast");
const shopperCards = document.querySelector("#shopperCards");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7e6df);
scene.fog = new THREE.Fog(0xd7e6df, 48, 92);
const camera = new THREE.OrthographicCamera(-25, 25, 22, -22, 0.1, 150);
const cameraTarget = new THREE.Vector3(0, 0, 0);
const cameraGoal = new THREE.Vector3(0, 0, 0);
let cameraTheta = 0.56;
let cameraPhi = 0.94;
let cameraRadius = 48;
let baseZoom = 1;
let zoomGoal = 1;
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x7d8266, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d6, 3.1);
sun.position.set(-18, 30, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00035;
scene.add(sun);
const geometryCache = new Map();
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0
})
);
}
return materialCache.get(color);
}
function addBox(parent, size, position, color, options = {}) {
const key = size.join(",");
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(...size));
}
const mesh = new THREE.Mesh(
geometryCache.get(key),
options.material || getMaterial(color)
);
mesh.position.set(...position);
if (options.rotation) mesh.rotation.set(...options.rotation);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(text, options = {}) {
const {
background = "#173b37",
foreground = "#ffffff",
worldWidth = 4,
subtext = ""
} = options;
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.shadowColor = "rgba(20,45,40,0.2)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 8;
roundedRect(ctx, 12, 15, 488, 98, 28);
ctx.fillStyle = background;
ctx.fill();
ctx.shadowColor = "transparent";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = `800 ${subtext ? 39 : 48}px system-ui, sans-serif`;
ctx.fillText(text.toUpperCase(), 256, subtext ? 52 : 65);
if (subtext) {
ctx.fillStyle = "rgba(255,255,255,0.72)";
ctx.font = "700 19px system-ui, sans-serif";
ctx.fillText(subtext, 256, 89);
}
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * 0.25, 1);
sprite.renderOrder = 20;
return sprite;
}
// ------------------------------------------------------------
// Street and paving
// ------------------------------------------------------------
addBox(scene, [30, 0.65, 40], [0, -0.42, 0], 0xb8c9a8);
addBox(scene, [29.6, 0.16, 39.6], [0, -0.06, 0], 0xd7d2ae);
// The deliberately wide, uninterrupted central promenade.
addBox(scene, [5.4, 0.12, 36.4], [0, 0.07, 0], 0xead8b3);
const branches = [
{ size: [4.2, 0.12, 2.15], position: [-1.75, 0.08, -7] },
{ size: [4.2, 0.12, 2.15], position: [1.75, 0.08, -1] },
{ size: [4.2, 0.12, 2.15], position: [-1.75, 0.08, 7] },
{ size: [4.8, 0.12, 2.1], position: [2.0, 0.08, -12] },
{ size: [4.8, 0.12, 2.1], position: [-2.0, 0.08, 12] }
];
branches.forEach(({ size, position }) => {
addBox(scene, size, position, 0xead8b3);
});
const tilePositions = [];
for (let row = 0; row < 45; row++) {
for (let col = 0; col < 6; col++) {
tilePositions.push({
x: (col - 2.5) * 0.84,
z: -17.8 + row * 0.81
});
}
}
const tileGeometry = new THREE.BoxGeometry(0.78, 0.075, 0.75);
const tileMaterial = new THREE.MeshStandardMaterial({
roughness: 1,
vertexColors: true
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tilePositions.length
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
tilePositions.forEach((tile, index) => {
dummy.position.set(tile.x, 0.145, tile.z);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
const variation = ((index * 7) % 5) / 5;
tileColor.setHSL(0.105, 0.43, 0.77 + variation * 0.055);
tiles.setColorAt(index, tileColor);
});
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// ------------------------------------------------------------
// Walk graph: both entrances connect to every stall.
// ------------------------------------------------------------
const graphNodes = {
south: { x: 0, z: -17 },
southCross: { x: 0, z: -12 },
southMid: { x: 0, z: -7 },
produce: { x: -3.6, z: -7 },
center: { x: 0, z: 0 },
books: { x: 3.6, z: -1 },
northMid: { x: 0, z: 7 },
flowers: { x: -3.6, z: 7 },
northCross: { x: 0, z: 12 },
north: { x: 0, z: 17 },
southSeats: { x: 4.2, z: -12 },
northSeats: { x: -4.2, z: 12 }
};
const graphEdges = [
["south", "southCross"],
["southCross", "southMid"],
["southMid", "center"],
["center", "northMid"],
["northMid", "northCross"],
["northCross", "north"],
["southMid", "produce"],
["center", "books"],
["northMid", "flowers"],
["southCross", "southSeats"],
["northCross", "northSeats"]
];
const adjacency = Object.fromEntries(
Object.keys(graphNodes).map((key) => [key, []])
);
graphEdges.forEach(([a, b]) => {
adjacency[a].push(b);
adjacency[b].push(a);
});
function reachableFrom(start) {
const seen = new Set([start]);
const queue = [start];
while (queue.length) {
const current = queue.shift();
for (const next of adjacency[current]) {
if (!seen.has(next)) {
seen.add(next);
queue.push(next);
}
}
}
return seen;
}
function shortestPath(start, end) {
const distances = Object.fromEntries(
Object.keys(graphNodes).map((key) => [key, Infinity])
);
const previous = {};
const unvisited = new Set(Object.keys(graphNodes));
distances[start] = 0;
while (unvisited.size) {
let current = null;
for (const node of unvisited) {
if (
current === null ||
distances[node] < distances[current]
) {
current = node;
}
}
if (current === end) break;
unvisited.delete(current);
for (const neighbor of adjacency[current]) {
const nextDistance = distances[current] + 1;
if (nextDistance < distances[neighbor]) {
distances[neighbor] = nextDistance;
previous[neighbor] = current;
}
}
}
const path = [end];
while (path[0] !== start) {
path.unshift(previous[path[0]]);
}
return path;
}
const routeOverlay = new THREE.Group();
const routePositions = [];
graphEdges.forEach(([a, b]) => {
routePositions.push(
graphNodes[a].x,
0.215,
graphNodes[a].z,
graphNodes[b].x,
0.215,
graphNodes[b].z
);
});
const routeGeometry = new THREE.BufferGeometry();
routeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(routePositions, 3)
);
const routeLines = new THREE.LineSegments(
routeGeometry,
new THREE.LineBasicMaterial({
color: 0x288c82,
transparent: true,
opacity: 0.36,
depthWrite: false
})
);
routeLines.renderOrder = 3;
routeOverlay.add(routeLines);
Object.values(graphNodes).forEach((node) => {
const dot = new THREE.Mesh(
new THREE.CircleGeometry(0.14, 16),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.92,
depthWrite: false
})
);
dot.rotation.x = -Math.PI / 2;
dot.position.set(node.x, 0.225, node.z);
routeOverlay.add(dot);
});
scene.add(routeOverlay);
// ------------------------------------------------------------
// Stall construction
// ------------------------------------------------------------
const stallDefinitions = {
produce: {
label: "Produce",
x: -7,
z: -7,
side: -1,
accent: 0xe96a51,
secondary: 0xf5c65d
},
books: {
label: "Books",
x: 7,
z: -1,
side: 1,
accent: 0x397f9e,
secondary: 0x7eb8c8
},
flowers: {
label: "Flowers",
x: -7,
z: 7,
side: -1,
accent: 0x8c6fc2,
secondary: 0xf0a6b6
}
};
const stallGroups = [];
const stalls = {};
function buildStall(id, definition) {
const group = new THREE.Group();
group.position.set(definition.x, 0, definition.z);
group.rotation.y = definition.side === 1 ? Math.PI : 0;
scene.add(group);
// Platform, counter, posts, and striped awning.
addBox(group, [4.25, 0.25, 5.75], [0, 0.15, 0], 0xc5aa7e);
addBox(group, [1.35, 1.25, 4.9], [1.12, 0.82, 0], 0x8f6948);
addBox(group, [1.48, 0.16, 5.05], [1.12, 1.49, 0], 0xc09263);
[-2.42, 2.42].forEach((z) => {
addBox(group, [0.18, 3.25, 0.18], [-1.65, 1.82, z], 0x72543f);
addBox(group, [0.18, 3.25, 0.18], [1.62, 1.82, z], 0x72543f);
});
for (let stripe = 0; stripe < 9; stripe++) {
const color = stripe % 2 === 0
? definition.accent
: definition.secondary;
const z = -2.56 + stripe * 0.64;
addBox(
group,
[3.45, 0.18, 0.64],
[-0.36, 3.48, z],
color
);
addBox(
group,
[0.16, 0.5, 0.64],
[1.38, 3.14, z],
color
);
}
// A small wooden hanging sign board behind the awning.
addBox(group, [0.18, 1.05, 3.5], [-1.69, 2.55, 0], 0x72543f);
if (id === "produce") {
const fruitColors = [0xe95045, 0xf0a735, 0x7fb84e, 0xe8d15a];
[-1.55, 0, 1.55].forEach((z, basketIndex) => {
addBox(group, [1.12, 0.3, 1.02], [0.93, 1.67, z], 0x9a7048);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
addBox(
group,
[0.23, 0.22, 0.23],
[
0.65 + row * 0.48,
1.93,
z - 0.29 + col * 0.29
],
fruitColors[(basketIndex + row + col) % fruitColors.length]
);
}
}
});
}
if (id === "books") {
const bookColors = [
0xd85f54, 0x3b829f, 0xe5b346,
0x6b9d68, 0x8d6cb3, 0xe58a9d
];
[1.0, 1.78, 2.56].forEach((shelfY, shelfIndex) => {
addBox(group, [0.72, 0.12, 4.75], [-1.43, shelfY, 0], 0x79573e);
for (let book = 0; book < 11; book++) {
const height = 0.42 + ((book + shelfIndex) % 3) * 0.08;
addBox(
group,
[0.38, height, 0.24],
[
-1.38,
shelfY + 0.06 + height / 2,
-2.05 + book * 0.41
],
bookColors[(book + shelfIndex) % bookColors.length]
);
}
});
[-1.4, 0, 1.4].forEach((z, stack) => {
for (let book = 0; book < 3; book++) {
addBox(
group,
[0.62, 0.12, 0.82],
[0.82, 1.64 + book * 0.13, z],
bookColors[(stack + book) % bookColors.length],
{ rotation: [0, book * 0.12, 0] }
);
}
});
}
if (id === "flowers") {
const potColors = [0xc97759, 0xe1b45e, 0x829d73];
const petalColors = [0xe96f86, 0xf2c34d, 0xb993d5, 0xf4efe2];
[-1.65, -0.55, 0.55, 1.65].forEach((z, flowerIndex) => {
addBox(
group,
[0.42, 0.38, 0.42],
[0.93, 1.77, z],
potColors[flowerIndex % potColors.length]
);
addBox(
group,
[0.07, 0.58, 0.07],
[0.93, 2.22, z],
0x4f8d59
);
const petal = petalColors[flowerIndex % petalColors.length];
addBox(group, [0.34, 0.18, 0.34], [0.93, 2.55, z], petal);
addBox(group, [0.19, 0.13, 0.19], [0.93, 2.69, z], 0xf2d56d);
});
}
group.traverse((object) => {
if (object.isMesh) object.userData.stallId = id;
});
const sign = makeLabel(definition.label, {
background: `#${new THREE.Color(definition.accent).getHexString()}`,
worldWidth: 4.25
});
sign.position.set(definition.x, 4.35, definition.z);
scene.add(sign);
stallGroups.push(group);
stalls[id] = {
...definition,
group,
access: id,
sign
};
}
Object.entries(stallDefinitions).forEach(([id, definition]) => {
buildStall(id, definition);
});
// ------------------------------------------------------------
// Seating nooks
// ------------------------------------------------------------
function buildSeating(x, z, accent) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addBox(group, [4.6, 0.15, 4.6], [0, 0.1, 0], 0xdccba7);
// Table and stools.
addBox(group, [0.28, 1.05, 0.28], [0, 0.68, 0], 0x795b43);
addBox(group, [1.35, 0.16, 1.35], [0, 1.25, 0], 0xc18d5b);
[
[-1.05, -0.8],
[1.05, -0.8],
[-1.05, 0.8],
[1.05, 0.8]
].forEach(([seatX, seatZ]) => {
addBox(group, [0.58, 0.14, 0.58], [seatX, 0.66, seatZ], 0x5e8b76);
addBox(
group,
[0.58, 0.62, 0.12],
[seatX, 0.96, seatZ + 0.25],
0x5e8b76
);
});
// Voxel parasol.
addBox(group, [0.12, 2.75, 0.12], [0, 1.55, 0], 0x775c43);
addBox(group, [2.65, 0.17, 2.65], [0, 2.9, 0], accent);
addBox(group, [1.85, 0.18, 1.85], [0, 3.05, 0], 0xf2e5c4);
const sign = makeLabel("Rest & Sip", {
background: "#416b5d",
worldWidth: 3.5
});
sign.position.set(x, 3.85, z);
scene.add(sign);
}
buildSeating(5.3, -12, 0xeaa64e);
buildSeating(-5.3, 12, 0x5c9b8c);
// ------------------------------------------------------------
// Entrance arches and street decoration
// ------------------------------------------------------------
function buildEntrance(z, text, subtext) {
[-3.25, 3.25].forEach((x) => {
addBox(scene, [0.28, 3.5, 0.28], [x, 1.86, z], 0x72523d);
addBox(scene, [0.62, 0.2, 0.62], [x, 0.22, z], 0xa37d57);
});
addBox(scene, [6.9, 0.32, 0.38], [0, 3.58, z], 0x72523d);
const sign = makeLabel(text, {
background: "#244d43",
foreground: "#fff8df",
worldWidth: 5.2,
subtext
});
sign.position.set(0, 4.25, z);
scene.add(sign);
}
buildEntrance(-17.5, "South Gate", "Market entrance");
buildEntrance(17.5, "North Gate", "Market entrance");
function buildTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
addBox(group, [0.48, 2.5, 0.48], [0, 1.25, 0], 0x79583f);
addBox(group, [2.35, 1.45, 2.15], [0, 3.0, 0], 0x6e9d63);
addBox(group, [1.65, 1.25, 1.7], [-0.35, 3.8, 0.1], 0x86ad70);
addBox(group, [1.35, 0.95, 1.4], [0.35, 3.35, -0.35], 0x5f8f59);
}
[
[-10.7, -14.8, 1],
[10.7, -14.8, 0.9],
[-10.7, 14.8, 1.05],
[10.7, 14.8, 0.92]
].forEach(([x, z, scale]) => buildTree(x, z, scale));
function buildPlanter(x, z, color) {
addBox(scene, [1.25, 0.55, 1.25], [x, 0.34, z], 0xb7835e);
addBox(scene, [0.85, 0.14, 0.85], [x, 0.64, z], 0x5e7654);
for (let i = 0; i < 5; i++) {
const px = x + (i % 2 ? 0.28 : -0.25);
const pz = z + (i < 3 ? -0.24 : 0.22);
addBox(scene, [0.12, 0.45, 0.12], [px, 0.88, pz], 0x4e8857);
addBox(scene, [0.28, 0.22, 0.28], [px, 1.13, pz], color);
}
}
[
[-3.35, -14.3, 0xe66b5c],
[3.35, -14.3, 0xe3ae49],
[-3.35, -4, 0x8c72bd],
[3.35, 4, 0xe66b5c],
[-3.35, 14.3, 0xe3ae49],
[3.35, 14.3, 0x7ba16b]
].forEach(([x, z, color]) => buildPlanter(x, z, color));
function buildBackgroundBuilding(x, z, width, depth, height, color) {
addBox(scene, [width, height, depth], [x, height / 2, z], color);
addBox(
scene,
[width + 0.25, 0.22, depth + 0.25],
[x, height + 0.11, z],
0xb6aa92
);
const inwardX = x < 0 ? x + width / 2 + 0.03 : x - width / 2 - 0.03;
const windowColor = 0xe8d9ae;
for (let y = 1.25; y < height - 0.4; y += 1.35) {
for (let wz = z - depth / 2 + 0.8; wz < z + depth / 2 - 0.4; wz += 1.2) {
addBox(
scene,
[0.08, 0.62, 0.5],
[inwardX, y, wz],
windowColor,
{ castShadow: false }
);
}
}
}
buildBackgroundBuilding(-14, -7.5, 3.1, 4.5, 5.4, 0xc6a8a1);
buildBackgroundBuilding(-14, 1.5, 3.1, 4.2, 4.2, 0xaeb9a2);
buildBackgroundBuilding(-14, 9, 3.1, 4.3, 6.1, 0xb7a7bd);
buildBackgroundBuilding(14, -8.5, 3.1, 4.5, 4.8, 0xaab8b8);
buildBackgroundBuilding(14, 1, 3.1, 4.5, 5.6, 0xc2b38f);
buildBackgroundBuilding(14, 9, 3.1, 4.2, 4.5, 0xb6a3aa);
// ------------------------------------------------------------
// Shoppers
// ------------------------------------------------------------
const shopperSpecs = [
{
name: "Mara",
color: "#ef6c57",
start: "south",
exit: "north",
speed: 2.0,
list: [
{ name: "Apples", stall: "produce" },
{ name: "Novel", stall: "books" },
{ name: "Tulips", stall: "flowers" }
]
},
{
name: "Theo",
color: "#4f9bc9",
start: "north",
exit: "south",
speed: 1.8,
list: [
{ name: "Notebook", stall: "books" },
{ name: "Pears", stall: "produce" }
]
},
{
name: "Inez",
color: "#8d70c8",
start: "south",
exit: "north",
speed: 2.15,
list: [
{ name: "Roses", stall: "flowers" },
{ name: "Notebook", stall: "books" }
]
},
{
name: "Bo",
color: "#e4a93b",
start: "north",
exit: "south",
speed: 1.7,
list: [
{ name: "Apples", stall: "produce" },
{ name: "Roses", stall: "flowers" }
]
}
];
function buildRoute(spec) {
const route = [{ node: spec.start, action: null }];
let current = spec.start;
spec.list.forEach((item) => {
const path = shortestPath(current, item.stall);
for (let i = 1; i < path.length; i++) {
route.push({
node: path[i],
action: i === path.length - 1 ? item : null
});
}
current = item.stall;
});
const exitPath = shortestPath(current, spec.exit);
for (let i = 1; i < exitPath.length; i++) {
route.push({ node: exitPath[i], action: null });
}
return route;
}
function createShopper(spec, index) {
const root = new THREE.Group();
const model = new THREE.Group();
root.add(model);
scene.add(root);
const ring = new THREE.Mesh(
new THREE.CircleGeometry(0.48, 24),
new THREE.MeshBasicMaterial({
color: spec.color,
transparent: true,
opacity: 0.62,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.17;
root.add(ring);
addBox(model, [0.58, 0.72, 0.38], [0, 0.96, 0], spec.color);
addBox(model, [0.49, 0.49, 0.46], [0, 1.58, 0], 0xe6b88e);
addBox(model, [0.53, 0.16, 0.5], [0, 1.84, -0.015], 0x493d38);
addBox(model, [0.13, 0.08, 0.06], [-0.12, 1.61, 0.245], 0x283733);
addBox(model, [0.13, 0.08, 0.06], [0.12, 1.61, 0.245], 0x283733);
const legs = [];
[-0.16, 0.16].forEach((x) => {
const pivot = new THREE.Group();
pivot.position.set(x, 0.65, 0);
addBox(pivot, [0.2, 0.53, 0.22], [0, -0.25, 0], 0x334b50);
addBox(pivot, [0.23, 0.12, 0.34], [0, -0.53, 0.05], 0x3d3734);
model.add(pivot);
legs.push(pivot);
});
const arms = [];
[-0.4, 0.4].forEach((x) => {
const pivot = new THREE.Group();
pivot.position.set(x, 1.23, 0);
addBox(pivot, [0.16, 0.52, 0.18], [0, -0.23, 0], spec.color);
addBox(pivot, [0.17, 0.16, 0.18], [0, -0.52, 0], 0xe6b88e);
model.add(pivot);
arms.push(pivot);
});
const basket = new THREE.Group();
basket.position.set(0.52, 0.72, 0.03);
addBox(basket, [0.38, 0.28, 0.34], [0, 0, 0], 0xb27c4c);
addBox(basket, [0.08, 0.32, 0.08], [-0.14, 0.23, 0], 0x7d573b);
addBox(basket, [0.08, 0.32, 0.08], [0.14, 0.23, 0], 0x7d573b);
addBox(basket, [0.36, 0.08, 0.08], [0, 0.38, 0], 0x7d573b);
model.add(basket);
const basketContents = spec.list.map((item, itemIndex) => {
const color = item.stall === "produce"
? 0xe85b47
: item.stall === "books"
? 0x4c91ad
: 0xdc7fac;
const contents = addBox(
basket,
[0.16, 0.16, 0.16],
[
-0.1 + (itemIndex % 2) * 0.18,
0.19 + Math.floor(itemIndex / 2) * 0.12,
-0.05 + (itemIndex % 3) * 0.07
],
color
);
contents.visible = false;
return { name: item.name, mesh: contents };
});
const nameLabel = makeLabel(spec.name, {
background: spec.color,
worldWidth: 1.85
});
nameLabel.position.set(0, 2.4, 0);
root.add(nameLabel);
const shopper = {
spec,
root,
model,
ring,
legs,
arms,
basketContents,
route: buildRoute(spec),
currentIndex: 0,
collected: new Set(),
phase: index * 1.7,
wait: 0,
delay: index * 1.8,
done: false,
restart: 0,
currentTarget: null
};
resetShopper(shopper, index * 1.8);
return shopper;
}
function resetShopper(shopper, delay = 0.6) {
shopper.currentIndex = 0;
shopper.collected.clear();
shopper.wait = 0;
shopper.done = false;
shopper.restart = 0;
shopper.delay = delay;
shopper.currentTarget = null;
shopper.root.visible = true;
const start = graphNodes[shopper.spec.start];
shopper.root.position.set(start.x, 0, start.z);
shopper.root.rotation.y =
shopper.spec.exit === "north" ? 0 : Math.PI;
shopper.basketContents.forEach((entry) => {
entry.mesh.visible = false;
});
}
const shoppers = shopperSpecs.map(createShopper);
// ------------------------------------------------------------
// Shopper UI
// ------------------------------------------------------------
shopperSpecs.forEach((spec, index) => {
const card = document.createElement("section");
card.className = "shopper-card";
const itemMarkup = spec.list.map((item) => {
return `<li data-shopper="${index}" data-item="${item.name}">
${item.name}
</li>`;
}).join("");
card.innerHTML = `
<div class="shopper-header">
<div class="avatar" style="background:${spec.color}">
${spec.name[0]}
</div>
<div class="shopper-name">
<strong>${spec.name}</strong>
<small>${spec.list.length} item shopping list</small>
</div>
<div class="shopper-state" id="state-${index}">Arriving</div>
</div>
<ul class="shopping-list">${itemMarkup}</ul>
<div class="progress"><span id="progress-${index}"></span></div>
`;
shopperCards.appendChild(card);
});
function updateShopperUI() {
shoppers.forEach((shopper, index) => {
const state = document.querySelector(`#state-${index}`);
const progress = document.querySelector(`#progress-${index}`);
let label = "Walking";
if (shopper.delay > 0) {
label = "Arriving";
} else if (shopper.done) {
label = "All done";
} else if (shopper.wait > 0) {
const stall = stalls[shopper.currentTarget?.stall];
label = stall ? `At ${stall.label}` : "Shopping";
} else {
const nextAction = shopper.route
.slice(shopper.currentIndex + 1)
.find((point) => point.action);
if (nextAction) {
label = `To ${stalls[nextAction.action.stall].label}`;
}
}
state.textContent = label;
progress.style.width =
`${(shopper.collected.size / shopper.spec.list.length) * 100}%`;
shopper.spec.list.forEach((item) => {
const element = document.querySelector(
`[data-shopper="${index}"][data-item="${item.name}"]`
);
element.classList.toggle(
"collected",
shopper.collected.has(item.name)
);
});
});
}
// ------------------------------------------------------------
// Shopper animation
// ------------------------------------------------------------
function angleLerp(current, target, amount) {
const difference = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + difference * amount;
}
function collectItem(shopper, item) {
shopper.collected.add(item.name);
const basketEntry = shopper.basketContents.find(
(entry) => entry.name === item.name
);
if (basketEntry) basketEntry.mesh.visible = true;
}
function updateShopper(shopper, dt) {
if (shopper.delay > 0) {
shopper.delay -= dt;
shopper.model.position.y = 0;
return;
}
if (shopper.done) {
shopper.restart -= dt;
shopper.model.position.y = 0;
if (shopper.restart <= 0) resetShopper(shopper, 0.7);
return;
}
let moving = false;
if (shopper.wait > 0) {
shopper.wait -= dt;
shopper.phase += dt * 3;
const stall = stalls[shopper.currentTarget?.stall];
if (stall) {
const dx = stall.x - shopper.root.position.x;
const dz = stall.z - shopper.root.position.z;
shopper.root.rotation.y = angleLerp(
shopper.root.rotation.y,
Math.atan2(dx, dz),
1 - Math.exp(-dt * 8)
);
}
} else {
const targetNode = shopper.route[shopper.currentIndex + 1];
if (!targetNode) {
shopper.done = true;
shopper.restart = 3.8;
return;
}
const target = graphNodes[targetNode.node];
const dx = target.x - shopper.root.position.x;
const dz = target.z - shopper.root.position.z;
const distance = Math.hypot(dx, dz);
const movement = shopper.spec.speed * dt;
if (distance <= movement + 0.015) {
shopper.root.position.x = target.x;
shopper.root.position.z = target.z;
shopper.currentIndex++;
const arrived = shopper.route[shopper.currentIndex];
if (arrived?.action) {
shopper.currentTarget = arrived.action;
shopper.wait = 1.35;
collectItem(shopper, arrived.action);
}
if (shopper.currentIndex >= shopper.route.length - 1) {
shopper.done = true;
shopper.restart = 3.8;
}
} else {
moving = true;
shopper.root.position.x += (dx / distance) * movement;
shopper.root.position.z += (dz / distance) * movement;
shopper.root.rotation.y = angleLerp(
shopper.root.rotation.y,
Math.atan2(dx, dz),
1 - Math.exp(-dt * 10)
);
}
}
if (moving) shopper.phase += dt * 9;
const stride = moving ? Math.sin(shopper.phase) * 0.58 : 0;
shopper.legs[0].rotation.x = stride;
shopper.legs[1].rotation.x = -stride;
shopper.arms[0].rotation.x = -stride * 0.72;
shopper.arms[1].rotation.x = stride * 0.72;
shopper.model.position.y = moving
? Math.abs(Math.sin(shopper.phase)) * 0.055
: 0;
const pulse = 1 + Math.sin(shopper.phase * 0.6) * 0.06;
shopper.ring.scale.setScalar(pulse);
}
// ------------------------------------------------------------
// Connectivity validation
// ------------------------------------------------------------
const southReachable = reachableFrom("south");
const northReachable = reachableFrom("north");
const stallAccesses = Object.keys(stalls);
const allConnected = stallAccesses.every(
(id) => southReachable.has(id) && northReachable.has(id)
);
document.querySelector("#reachText").textContent = allConnected
? "All 3 stalls connected"
: "Connection issue";
document.querySelector("#reachDetail").textContent = allConnected
? "Produce, Books and Flowers are each reachable from South and North Gate."
: "One or more stalls are not connected to both entrances.";
// ------------------------------------------------------------
// Direct camera controls — no addons required
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const drag = {
active: false,
moved: false,
lastX: 0,
lastY: 0,
startX: 0,
startY: 0
};
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickStall(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(stallGroups, true);
return hits.length ? hits[0].object.userData.stallId : null;
}
canvas.addEventListener("pointerdown", (event) => {
drag.active = true;
drag.moved = false;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
drag.startX = event.clientX;
drag.startY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (drag.active) {
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + dy * 0.0045,
0.43,
1.25
);
drag.lastX = event.clientX;
drag.lastY = event.clientY;
if (
Math.hypot(
event.clientX - drag.startX,
event.clientY - drag.startY
) > 5
) {
drag.moved = true;
}
} else {
const hit = pickStall(event);
canvas.style.cursor = hit ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
drag.active = false;
if (!drag.moved) {
const stallId = pickStall(event);
if (stallId) selectStall(stallId);
}
});
canvas.addEventListener("pointercancel", () => {
drag.active = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomGoal = THREE.MathUtils.clamp(
zoomGoal * (event.deltaY > 0 ? 0.9 : 1.1),
baseZoom * 0.68,
baseZoom * 2.3
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const selectionBox = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(4.7, 3.95, 6.25)),
new THREE.LineBasicMaterial({
color: 0xffc857,
transparent: true,
opacity: 0.9
})
);
selectionBox.visible = false;
scene.add(selectionBox);
let toastTimer;
function selectStall(id) {
const stall = stalls[id];
selectionBox.visible = true;
selectionBox.position.set(stall.x, 1.95, stall.z);
cameraGoal.set(stall.x * 0.48, 0, stall.z * 0.72);
zoomGoal = baseZoom * 1.22;
toast.textContent =
`${stall.label} · reachable from both entrances`;
clearTimeout(toastTimer);
toast.classList.add("visible");
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 2300);
}
function resetView() {
cameraGoal.set(0, 0, 0);
cameraTheta = 0.56;
cameraPhi = 0.94;
zoomGoal = baseZoom;
selectionBox.visible = false;
}
document.querySelector("#resetView").addEventListener("click", resetView);
const routeButton = document.querySelector("#toggleRoutes");
routeButton.addEventListener("click", () => {
routeOverlay.visible = !routeOverlay.visible;
routeButton.setAttribute(
"aria-pressed",
String(routeOverlay.visible)
);
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = width < 700 ? 23.5 : 21.5;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
const newBaseZoom = aspect < 0.72 ? 0.76 : 1;
const zoomRatio = zoomGoal / baseZoom;
baseZoom = newBaseZoom;
zoomGoal = baseZoom * zoomRatio;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
camera.zoom = baseZoom;
zoomGoal = baseZoom;
camera.updateProjectionMatrix();
// ------------------------------------------------------------
// Main loop
// ------------------------------------------------------------
let lastTime = performance.now();
let lastUIUpdate = 0;
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
shoppers.forEach((shopper) => updateShopper(shopper, dt));
cameraTarget.lerp(
cameraGoal,
1 - Math.exp(-dt * 4.5)
);
camera.zoom = THREE.MathUtils.lerp(
camera.zoom,
zoomGoal,
1 - Math.exp(-dt * 8)
);
camera.updateProjectionMatrix();
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
if (now - lastUIUpdate > 100) {
updateShopperUI();
lastUIUpdate = now;
}
renderer.render(scene, camera);
}
updateShopperUI();
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```