Prompt specification
Build or customize the Three.js 3D scene "Shop footfall and sales data scene" 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: Shop footfall and sales data scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shop-footfall-and-sales-data-scene-x1787
Scene Description Prompt:
A voxel fictional shop with synthetic footfall and sales observations, showing a trend explicitly as association rather than causation. Three.js from cdnjs, one HTML file.
Working Three.js Starter (shop-footfall-and-sales-data-scene-x1787):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Maple & Mint — Synthetic Shop Observations</title>
<style>
:root {
--ink: #18342f;
--muted: #667772;
--paper: rgba(255, 255, 252, 0.88);
--line: rgba(24, 52, 47, 0.12);
--footfall: #18a999;
--sales: #ee9b42;
--shadow: 0 18px 45px rgba(32, 58, 51, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eee9;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene-canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene-canvas:active {
cursor: grabbing;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
header {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
gap: 13px;
align-items: center;
}
.brand-mark {
position: relative;
width: 46px;
height: 46px;
flex: 0 0 46px;
border-radius: 13px;
background: var(--ink);
box-shadow: var(--shadow);
}
.brand-mark::before,
.brand-mark::after,
.brand-mark span {
content: "";
position: absolute;
width: 12px;
height: 12px;
}
.brand-mark::before {
left: 10px;
top: 10px;
background: #d8f07d;
box-shadow: 16px 0 0 #eaa85d;
}
.brand-mark::after {
left: 10px;
top: 26px;
background: #73cbbb;
box-shadow: 16px 0 0 #f7f1df;
}
h1 {
margin: 0;
font-size: clamp(21px, 2vw, 29px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin-top: 6px;
color: var(--muted);
font-size: 12px;
font-weight: 650;
letter-spacing: 0.01em;
}
.badges {
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: flex-end;
pointer-events: auto;
}
.badge {
padding: 9px 12px;
border-radius: 999px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.badge.synthetic {
background: var(--ink);
color: #fff;
}
.badge.association {
border: 1px solid #d9913c;
background: #fff2dc;
color: #8b4e14;
}
.panel {
position: fixed;
z-index: 4;
border-radius: 19px;
}
.metric-card {
top: 94px;
left: 24px;
width: 305px;
padding: 17px;
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.week-chip {
padding: 5px 8px;
border-radius: 999px;
background: #edf1eb;
color: var(--ink);
letter-spacing: 0.04em;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.metric {
min-width: 0;
padding: 12px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.63);
}
.metric-label {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
white-space: nowrap;
}
.dot {
width: 8px;
height: 8px;
flex: 0 0 8px;
border-radius: 2px;
}
.dot.footfall {
background: var(--footfall);
}
.dot.sales {
background: var(--sales);
}
.metric strong {
display: block;
margin-top: 8px;
font-size: 31px;
line-height: 1;
letter-spacing: -0.055em;
}
.metric small {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
.meter {
height: 5px;
margin-top: 10px;
overflow: hidden;
border-radius: 999px;
background: #e7ebe5;
}
.meter > div {
width: 0;
height: 100%;
border-radius: inherit;
transition: width 350ms ease;
}
#footfallBar {
background: var(--footfall);
}
#salesBar {
background: var(--sales);
}
.pair-note {
margin: 12px 2px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.chart-card {
top: 94px;
right: 24px;
width: 390px;
padding: 17px;
}
.chart-card h2,
.method-card h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.025em;
}
.chart-subtitle {
margin: 5px 0 7px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#trendChart {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
#trendChart .data-point {
cursor: pointer;
outline: none;
}
#trendChart .data-point:focus {
stroke: var(--ink);
stroke-width: 4;
}
.legend {
display: flex;
align-items: center;
gap: 16px;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 18px;
height: 3px;
border-radius: 2px;
}
.method-card {
bottom: 24px;
left: 24px;
width: 385px;
padding: 17px 18px;
}
.method-title {
display: flex;
align-items: center;
gap: 8px;
}
.method-title::before {
content: "!";
display: grid;
place-items: center;
width: 21px;
height: 21px;
border-radius: 7px;
background: #fff0d7;
color: #9a571b;
font-size: 12px;
font-weight: 900;
}
.method-card p {
margin: 9px 0 0;
color: #52635f;
font-size: 11px;
line-height: 1.55;
}
.method-card strong {
color: var(--ink);
}
.correlation {
display: inline-flex;
margin-top: 11px;
padding: 6px 8px;
border-radius: 8px;
background: #edf2ec;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
font-weight: 800;
}
details {
margin-top: 12px;
border-top: 1px solid var(--line);
padding-top: 10px;
}
summary {
cursor: pointer;
color: var(--muted);
font-size: 10px;
font-weight: 800;
}
table {
width: 100%;
margin-top: 9px;
border-collapse: collapse;
font-size: 9px;
}
th,
td {
padding: 5px;
border-bottom: 1px solid var(--line);
text-align: right;
}
th:first-child,
td:first-child {
text-align: left;
}
th {
color: var(--muted);
}
tbody tr {
cursor: pointer;
}
tbody tr:hover,
tbody tr.selected {
background: #edf3ec;
}
.timeline {
bottom: 24px;
left: 50%;
display: flex;
align-items: center;
gap: 13px;
width: min(560px, calc(100vw - 48px));
padding: 12px 14px;
transform: translateX(-50%);
}
.play-button,
.camera-button {
display: grid;
place-items: center;
height: 34px;
border: 1px solid var(--line);
border-radius: 10px;
background: #fff;
cursor: pointer;
font-weight: 850;
transition:
transform 150ms ease,
background 150ms ease;
}
.play-button {
width: 70px;
flex: 0 0 70px;
color: #fff;
border-color: var(--ink);
background: var(--ink);
font-size: 11px;
}
.play-button:hover,
.camera-button:hover {
transform: translateY(-1px);
}
.timeline-body {
min-width: 0;
flex: 1;
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
accent-color: var(--ink);
cursor: pointer;
}
.camera-controls {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 6px;
padding: 7px;
border-radius: 13px;
}
.camera-button {
width: 32px;
height: 31px;
font-size: 15px;
}
.camera-button.reset {
width: auto;
padding: 0 10px;
font-size: 9px;
letter-spacing: 0.04em;
}
.camera-help {
margin-right: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
#tooltip {
position: fixed;
z-index: 20;
max-width: 220px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 11px;
background: rgba(22, 46, 41, 0.94);
color: #fff;
box-shadow: 0 10px 30px rgba(20, 40, 35, 0.22);
font-size: 10px;
line-height: 1.5;
pointer-events: none;
}
#tooltip[hidden] {
display: none;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1080px) {
.method-card {
display: none;
}
.chart-card {
width: 350px;
}
.metric-card {
width: 280px;
}
.camera-help {
display: none;
}
}
@media (max-width: 760px) {
header {
top: 13px;
left: 13px;
right: 13px;
}
.brand-mark {
width: 39px;
height: 39px;
flex-basis: 39px;
border-radius: 11px;
}
.brand-mark::before {
left: 8px;
top: 8px;
}
.brand-mark::after {
left: 8px;
top: 22px;
}
h1 {
font-size: 19px;
}
.subtitle {
max-width: 210px;
font-size: 9px;
}
.badges {
max-width: 125px;
}
.badge {
padding: 7px 8px;
font-size: 8px;
}
.badge.synthetic {
display: none;
}
.metric-card {
top: 72px;
left: 12px;
right: 12px;
width: auto;
padding: 12px;
border-radius: 15px;
}
.metric strong {
font-size: 25px;
}
.chart-card {
display: none;
}
.timeline {
bottom: 12px;
width: calc(100vw - 24px);
}
.camera-controls {
right: 12px;
bottom: 78px;
}
}
@media (max-height: 690px) and (min-width: 761px) {
.method-card {
display: none;
}
.chart-card {
transform: scale(0.88);
transform-origin: top right;
}
}
</style>
</head>
<body>
<canvas
id="scene-canvas"
tabindex="0"
aria-label="Interactive voxel shop. Drag to orbit, scroll to zoom, and use the observation timeline."
></canvas>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"><span></span></div>
<div>
<h1>Maple & Mint</h1>
<div class="subtitle">A fictional shop observed over 12 synthetic weeks</div>
</div>
</div>
<div class="badges">
<div class="badge synthetic">Synthetic data</div>
<div class="badge association">Association ≠ causation</div>
</div>
</header>
<section class="panel metric-card glass" aria-live="polite">
<div class="eyebrow">
<span>Selected observation</span>
<span class="week-chip" id="weekChip">W12</span>
</div>
<div class="metrics">
<div class="metric">
<div class="metric-label">
<span class="dot footfall"></span>
Footfall index
</div>
<strong id="footfallValue">—</strong>
<small>visits · index, 100 = baseline</small>
<div class="meter"><div id="footfallBar"></div></div>
</div>
<div class="metric">
<div class="metric-label">
<span class="dot sales"></span>
Sales index
</div>
<strong id="salesValue">—</strong>
<small>transactions · index, 100 = baseline</small>
<div class="meter"><div id="salesBar"></div></div>
</div>
</div>
<p class="pair-note">
Both values describe the same selected week. They are observational
aggregates, not an intervention or causal estimate.
</p>
</section>
<section class="panel chart-card glass">
<div class="eyebrow">
<span>Weekly observation</span>
<span>Same index scale</span>
</div>
<h2>Observed co-movement</h2>
<div class="chart-subtitle">
Higher-footfall weeks generally coincide with higher-sales weeks.
The lines show association only.
</div>
<svg
id="trendChart"
viewBox="0 0 356 190"
role="img"
aria-label="Line chart comparing synthetic weekly footfall and sales indices"
></svg>
<div class="legend">
<span class="legend-item">
<span class="legend-line" style="background: var(--footfall)"></span>
Footfall
</span>
<span class="legend-item">
<span class="legend-line" style="background: var(--sales)"></span>
Sales
</span>
</div>
<details>
<summary>View synthetic observations</summary>
<table>
<thead>
<tr>
<th>Week</th>
<th>Footfall</th>
<th>Sales</th>
</tr>
</thead>
<tbody id="dataTable"></tbody>
</table>
</details>
</section>
<section class="panel method-card glass">
<div class="method-title">
<h2>Association, not a causal claim</h2>
</div>
<p>
In these fictional records, weeks with higher footfall generally also had
higher observed sales. This chart shows <strong>co-occurrence</strong>.
It does not show that footfall caused sales. Promotions, stock levels,
weather, and other factors were not measured, and reverse or shared
causes remain possible.
</p>
<div class="correlation" id="correlation">Pearson r = —</div>
</section>
<section class="panel timeline glass" aria-label="Observation timeline">
<button class="play-button" id="playButton" type="button">Play</button>
<div class="timeline-body">
<div class="timeline-labels">
<span>Synthetic week</span>
<span id="timelineWeek">W12</span>
</div>
<input
id="weekSlider"
type="range"
min="0"
max="11"
step="1"
value="11"
aria-label="Select synthetic observation week"
/>
</div>
</section>
<section class="panel camera-controls glass" aria-label="Camera controls">
<span class="camera-help">Drag · scroll</span>
<button class="camera-button" id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button class="camera-button" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="camera-button reset" id="resetCamera" type="button">Reset view</button>
</section>
<div id="tooltip" hidden></div>
<div id="liveRegion" class="sr-only" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// Hand-authored synthetic weekly aggregates. These are not real shop data.
const observations = [
{ week: "W01", footfall: 72, sales: 68 },
{ week: "W02", footfall: 78, sales: 72 },
{ week: "W03", footfall: 75, sales: 77 },
{ week: "W04", footfall: 91, sales: 84 },
{ week: "W05", footfall: 86, sales: 88 },
{ week: "W06", footfall: 103, sales: 95 },
{ week: "W07", footfall: 98, sales: 101 },
{ week: "W08", footfall: 112, sales: 106 },
{ week: "W09", footfall: 107, sales: 112 },
{ week: "W10", footfall: 121, sales: 116 },
{ week: "W11", footfall: 116, sales: 122 },
{ week: "W12", footfall: 128, sales: 126 }
];
const state = {
weekIndex: observations.length - 1,
customerCount: 0,
playing: false,
playTimer: null
};
const $ = (selector) => document.querySelector(selector);
const canvas = $("#scene-canvas");
function pearson(xs, ys) {
const meanX = xs.reduce((a, b) => a + b, 0) / xs.length;
const meanY = ys.reduce((a, b) => a + b, 0) / ys.length;
let numerator = 0;
let dx2 = 0;
let dy2 = 0;
for (let i = 0; i < xs.length; i++) {
const dx = xs[i] - meanX;
const dy = ys[i] - meanY;
numerator += dx * dy;
dx2 += dx * dx;
dy2 += dy * dy;
}
return numerator / Math.sqrt(dx2 * dy2);
}
const r = pearson(
observations.map((d) => d.footfall),
observations.map((d) => d.sales)
);
$("#correlation").textContent = `Pearson r = ${r.toFixed(2)} · descriptive only`;
// ---------------------------------------------------------------------
// THREE.JS SCENE
// ---------------------------------------------------------------------
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(0xe8eee9);
scene.fog = new THREE.Fog(0xe8eee9, 30, 58);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const ambient = new THREE.HemisphereLight(0xf5fbff, 0x88938a, 2.3);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff3d8, 3.3);
sun.position.set(9, 17, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfe7e4, 1.1);
fill.position.set(-12, 8, -6);
scene.add(fill);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function voxel(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
options.material || material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
const shop = new THREE.Group();
scene.add(shop);
// Diorama base and tiled floor.
voxel(shop, 50, 0.3, 50, 0, -0.43, 0, 0xdfe6df, {
castShadow: false
});
voxel(shop, 16.8, 0.62, 12.8, 0, 0, 0, 0xbac9bf);
voxel(shop, 16, 0.12, 12, 0, 0.36, 0, 0xf1eadb);
const tileColors = [0xf4eddd, 0xe9e5d8, 0xeee8da, 0xf7f0e1];
for (let x = 0; x < 16; x++) {
for (let z = 0; z < 12; z++) {
voxel(
shop,
0.975,
0.035,
0.975,
-7.5 + x,
0.435,
-5.5 + z,
tileColors[(x * 3 + z * 5) % tileColors.length],
{ castShadow: false }
);
}
}
// Back and left walls.
voxel(shop, 16.4, 6, 0.38, 0, 3.35, -6.08, 0xf1e9d7);
voxel(shop, 0.38, 6, 12.3, -8.08, 3.35, 0, 0xe8e3d5);
// Decorative wall blocks.
for (let i = 0; i < 9; i++) {
voxel(
shop,
0.72,
0.72,
0.12,
-6.8 + i * 1.7,
5.25,
-5.82,
i % 3 === 0 ? 0xd8e6cf : 0xe4d9c5,
{ castShadow: false }
);
}
// Shop sign as a procedural texture.
function makeLabel(text, foreground = "#173a34", background = "#fffaf0") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 96;
const context = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.userData.labelCanvas = labelCanvas;
sprite.userData.labelContext = context;
sprite.userData.labelTexture = texture;
sprite.userData.foreground = foreground;
sprite.userData.background = background;
sprite.renderOrder = 8;
setLabel(sprite, text);
return sprite;
}
function setLabel(sprite, text) {
const context = sprite.userData.labelContext;
const labelCanvas = sprite.userData.labelCanvas;
context.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
context.fillStyle = sprite.userData.background;
context.fillRect(0, 0, labelCanvas.width, labelCanvas.height);
context.fillStyle = sprite.userData.foreground;
context.font = "700 31px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, labelCanvas.width / 2, labelCanvas.height / 2 + 1);
sprite.userData.labelTexture.needsUpdate = true;
}
const sign = makeLabel("MAPLE & MINT");
sign.position.set(0, 5.35, -5.68);
sign.scale.set(4.6, 0.86, 1);
shop.add(sign);
// Shelves and colorful voxel products.
const productColors = [
0xdc765d,
0xe9b653,
0x75bdaa,
0x87a8c9,
0xb68ab6,
0x96b960,
0xe7d8aa
];
function createShelf(x, z, rotation, width) {
const group = new THREE.Group();
group.position.set(x, 0.48, z);
group.rotation.y = rotation;
shop.add(group);
voxel(group, width, 2.85, 0.16, 0, 1.43, -0.48, 0xb98e67);
voxel(group, 0.16, 2.95, 0.92, -width / 2, 1.48, 0, 0xb07b56);
voxel(group, 0.16, 2.95, 0.92, width / 2, 1.48, 0, 0xb07b56);
const levels = [0.5, 1.38, 2.26];
for (const level of levels) {
voxel(group, width, 0.14, 0.94, 0, level, 0, 0xc89a6d);
const count = Math.max(4, Math.floor(width / 0.58));
for (let i = 0; i < count; i++) {
const productWidth = 0.32 + ((i + level * 2) % 3) * 0.045;
const productHeight = 0.38 + ((i * 7 + Math.round(level * 10)) % 4) * 0.08;
const color = productColors[
(i + Math.round(level * 5) + Math.round(x)) % productColors.length
];
voxel(
group,
productWidth,
productHeight,
0.48,
-width / 2 + 0.35 + i * ((width - 0.7) / Math.max(1, count - 1)),
level + 0.08 + productHeight / 2,
0.05,
color
);
}
}
}
createShelf(-4.8, -5.13, 0, 3.8);
createShelf(-0.45, -5.13, 0, 4.1);
createShelf(4.4, -5.13, 0, 4.1);
createShelf(-7.23, -1.55, Math.PI / 2, 4.4);
// Checkout counter.
const counter = new THREE.Group();
counter.position.set(4.0, 0.48, 1.65);
shop.add(counter);
voxel(counter, 4.15, 1.18, 1.55, 0, 0.59, 0, 0x8db6a7);
voxel(counter, 4.35, 0.18, 1.75, 0, 1.27, 0, 0xf0dfbf);
voxel(counter, 1.0, 0.22, 0.7, -0.35, 1.47, -0.18, 0x294943);
voxel(counter, 0.68, 0.54, 0.12, -0.35, 1.78, -0.18, 0x172d2a);
voxel(counter, 0.48, 0.32, 0.1, -0.35, 1.78, -0.1, 0x77cbbb);
voxel(counter, 0.48, 0.15, 0.45, 0.72, 1.44, 0.1, 0xeaa85d);
// Queue markers.
for (let i = 0; i < 4; i++) {
voxel(
shop,
0.46,
0.025,
0.46,
2.55,
0.47,
3.95 - i * 0.75,
i % 2 ? 0xe8b76c : 0xd7d1bf,
{ castShadow: false }
);
}
// Entrance arch and sensor pad.
voxel(shop, 0.36, 3.6, 0.42, -6.05, 2.25, 5.4, 0x476c62);
voxel(shop, 0.36, 3.6, 0.42, -3.05, 2.25, 5.4, 0x476c62);
voxel(shop, 3.35, 0.4, 0.48, -4.55, 3.92, 5.4, 0x476c62);
voxel(shop, 2.25, 0.035, 1.05, -4.55, 0.48, 4.95, 0x5dc4b5, {
castShadow: false
});
// Small block planters.
function createPlanter(x, z) {
voxel(shop, 0.72, 0.62, 0.72, x, 0.82, z, 0xc9825f);
voxel(shop, 0.18, 1.1, 0.18, x, 1.55, z, 0x496d48);
voxel(shop, 0.72, 0.58, 0.62, x, 1.94, z, 0x76a85c);
voxel(shop, 0.58, 0.52, 0.58, x + 0.12, 2.43, z, 0x8fbe69);
}
createPlanter(-7.0, 4.8);
createPlanter(6.9, -4.8);
// ---------------------------------------------------------------------
// OBSERVATION LAYERS
// ---------------------------------------------------------------------
const pulses = [];
const pulseGeometry = new THREE.BoxGeometry(0.34, 0.5, 0.34);
for (let i = 0; i < 10; i++) {
const pulseMaterial = new THREE.MeshStandardMaterial({
color: 0x28b6a5,
emissive: 0x0c594f,
emissiveIntensity: 0.28,
roughness: 0.5,
transparent: true,
opacity: 0.9
});
const pulse = new THREE.Mesh(pulseGeometry, pulseMaterial);
const column = i % 5;
const row = Math.floor(i / 5);
pulse.position.set(
-5.42 + column * 0.43,
0.73,
4.7 + row * 0.48
);
pulse.castShadow = true;
pulse.userData.phase = i * 0.7;
shop.add(pulse);
pulses.push(pulse);
}
const receipts = [];
const receiptGeometry = new THREE.BoxGeometry(0.3, 0.12, 0.42);
for (let i = 0; i < 10; i++) {
const receipt = new THREE.Mesh(
receiptGeometry,
new THREE.MeshStandardMaterial({
color: i % 3 === 0 ? 0xe89a46 : 0xf3d68d,
emissive: 0x7a4317,
emissiveIntensity: 0.13,
roughness: 0.72
})
);
receipt.position.set(2.8 + (i % 5) * 0.37, 1.48, 1.43 + Math.floor(i / 5) * 0.32);
receipt.rotation.y = (i % 2 ? 1 : -1) * 0.12;
receipt.castShadow = true;
receipt.userData.phase = i * 0.55;
shop.add(receipt);
receipts.push(receipt);
}
const footfallLabel = makeLabel("FOOTFALL", "#ffffff", "#118f82");
footfallLabel.position.set(-4.55, 4.72, 5.2);
footfallLabel.scale.set(2.5, 0.47, 1);
shop.add(footfallLabel);
const salesLabel = makeLabel("SALES", "#5d3510", "#efa64e");
salesLabel.position.set(4.15, 3.1, 1.65);
salesLabel.scale.set(1.75, 0.42, 1);
shop.add(salesLabel);
// ---------------------------------------------------------------------
// VOXEL CUSTOMERS
// ---------------------------------------------------------------------
const customerColors = [
0xd96f5f,
0x4d8f9b,
0xe1aa52,
0x8874aa,
0x6aa77f,
0xd987ad
];
const basePoints = [
[-4.55, 0, 5.75],
[-4.55, 0, 3.85],
[-4.55, 0, 0.7],
[-2.7, 0, -1.6],
[0.2, 0, -2.15],
[2.9, 0, -1.05],
[5.4, 0, -0.15],
[5.35, 0, 1.8],
[3.2, 0, 3.05],
[0.1, 0, 2.75],
[-2.25, 0, 3.55],
[-4.55, 0, 3.85]
];
const curves = [-0.42, 0, 0.42].map((offset) =>
new THREE.CatmullRomCurve3(
basePoints.map(([x, y, z]) => new THREE.Vector3(x + offset, y, z)),
true,
"catmullrom",
0.35
)
);
function createCustomer(index) {
const group = new THREE.Group();
const shirt = customerColors[index % customerColors.length];
voxel(group, 0.48, 0.62, 0.32, 0, 0.93, 0, shirt);
voxel(group, 0.4, 0.4, 0.38, 0, 1.43, 0, 0xe5b991);
voxel(group, 0.43, 0.16, 0.41, 0, 1.66, -0.015, 0x4b3c35);
voxel(group, 0.15, 0.54, 0.18, -0.14, 0.38, 0, 0x354a52);
voxel(group, 0.15, 0.54, 0.18, 0.14, 0.38, 0, 0x354a52);
voxel(group, 0.14, 0.54, 0.16, -0.32, 0.92, 0, shirt);
voxel(group, 0.14, 0.54, 0.16, 0.32, 0.92, 0, shirt);
if (index % 3 === 0) {
voxel(group, 0.34, 0.25, 0.24, 0.38, 0.62, 0.18, 0xe3a04e);
}
group.userData = {
curve: curves[index % curves.length],
offset: (index * 0.137) % 1,
speed: 0.022 + (index % 5) * 0.002,
scale: 0.88 + (index % 4) * 0.055
};
group.scale.setScalar(group.userData.scale);
shop.add(group);
return group;
}
const customers = Array.from({ length: 28 }, (_, index) => createCustomer(index));
// ---------------------------------------------------------------------
// CUSTOM CAMERA CONTROLS — NO ADDONS
// ---------------------------------------------------------------------
const controls = {
yaw: 0.72,
pitch: 0.59,
distance: 25,
target: new THREE.Vector3(0, 1.15, 0),
dragging: false,
pointerX: 0,
pointerY: 0
};
function applyCamera() {
const horizontal = controls.distance * Math.cos(controls.pitch);
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.yaw = 0.72;
controls.pitch = 0.59;
controls.distance = 25;
controls.target.set(0, 1.15, 0);
applyCamera();
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.yaw -= dx * 0.0055;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.3,
1.12
);
applyCamera();
});
function endDrag(event) {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
16,
35
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
if (event.key === "ArrowLeft") controls.yaw -= 0.09;
else if (event.key === "ArrowRight") controls.yaw += 0.09;
else if (event.key === "ArrowUp") controls.pitch += 0.06;
else if (event.key === "ArrowDown") controls.pitch -= 0.06;
else if (event.key === "+" || event.key === "=") {
controls.distance = Math.max(16, controls.distance - 1);
} else if (event.key === "-") {
controls.distance = Math.min(35, controls.distance + 1);
} else {
handled = false;
}
if (handled) {
event.preventDefault();
controls.pitch = THREE.MathUtils.clamp(controls.pitch, 0.3, 1.12);
applyCamera();
}
});
$("#zoomIn").addEventListener("click", () => {
controls.distance = Math.max(16, controls.distance - 1.5);
applyCamera();
});
$("#zoomOut").addEventListener("click", () => {
controls.distance = Math.min(35, controls.distance + 1.5);
applyCamera();
});
$("#resetCamera").addEventListener("click", resetCamera);
applyCamera();
// ---------------------------------------------------------------------
// CHART AND UI
// ---------------------------------------------------------------------
const chart = $("#trendChart");
const tooltip = $("#tooltip");
function chartPoint(value, index, maximum = 140) {
const left = 38;
const top = 14;
const width = 302;
const height = 132;
return {
x:
left +
(index / (observations.length - 1)) * width,
y: top + height - (value / maximum) * height
};
}
function linePath(key) {
return observations
.map((d, index) => {
const p = chartPoint(d[key], index);
return `${index === 0 ? "M" : "L"}${p.x.toFixed(2)},${p.y.toFixed(2)}`;
})
.join(" ");
}
function showTooltip(html, x, y) {
tooltip.innerHTML = html;
tooltip.hidden = false;
const rect = tooltip.getBoundingClientRect();
const left = Math.min(window.innerWidth - rect.width - 8, Math.max(8, x + 12));
const top = Math.min(window.innerHeight - rect.height - 8, Math.max(8, y - rect.height - 10));
tooltip.style.left = `${left}px`;
tooltip.style.top = `${top}px`;
}
function hideTooltip() {
tooltip.hidden = true;
}
function drawChart() {
const selected = observations[state.weekIndex];
const selectedX = chartPoint(selected.footfall, state.weekIndex).x;
const grid = [50, 100, 130]
.map((tick) => {
const y = chartPoint(tick, 0).y;
const isBaseline = tick === 100;
return `
<line
x1="38" x2="340" y1="${y}" y2="${y}"
stroke="${isBaseline ? "#81918a" : "#dce2db"}"
stroke-width="${isBaseline ? 1.2 : 1}"
stroke-dasharray="${isBaseline ? "4 4" : "0"}"
/>
<text
x="31" y="${y + 3}"
text-anchor="end"
fill="#83918d"
font-size="8"
font-family="system-ui, sans-serif"
>${tick}</text>
`;
})
.join("");
const xLabels = observations
.map((d, index) => {
if (index % 2 !== 0 && index !== observations.length - 1) return "";
const p = chartPoint(d.footfall, index);
return `
<text
x="${p.x}" y="165"
text-anchor="middle"
fill="#83918d"
font-size="8"
font-family="system-ui, sans-serif"
>${d.week}</text>
`;
})
.join("");
const pointMarkup = (key, color) =>
observations
.map((d, index) => {
const p = chartPoint(d[key], index);
const selectedClass = index === state.weekIndex;
return `
<circle
class="data-point"
data-key="${key}"
data-index="${index}"
cx="${p.x}" cy="${p.y}"
r="${selectedClass ? 5.4 : 3.4}"
fill="${selectedClass ? color : "#fffaf0"}"
stroke="${color}"
stroke-width="${selectedClass ? 3 : 2}"
tabindex="0"
role="button"
aria-label="${d.week}, ${key} index ${d[key]}"
/>
`;
})
.join("");
chart.innerHTML = `
<rect
x="${selectedX - 8}" y="10" width="16" height="140"
rx="5" fill="#e7ede5"
/>
${grid}
<path
d="${linePath("footfall")}"
fill="none"
stroke="#18a999"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="${linePath("sales")}"
fill="none"
stroke="#ee9b42"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
${pointMarkup("footfall", "#18a999")}
${pointMarkup("sales", "#ee9b42")}
${xLabels}
`;
chart.querySelectorAll(".data-point").forEach((point) => {
const index = Number(point.dataset.index);
const d = observations[index];
const reveal = (event) => {
const rect = point.getBoundingClientRect();
const x = event.clientX || rect.left + rect.width / 2;
const y = event.clientY || rect.top;
showTooltip(
`<strong>${d.week}</strong><br>
Footfall index: <strong>${d.footfall}</strong><br>
Sales index: <strong>${d.sales}</strong><br>
<span style="opacity:.72">Synthetic co-observed values</span>`,
x,
y
);
};
point.addEventListener("pointerenter", reveal);
point.addEventListener("pointermove", reveal);
point.addEventListener("pointerleave", hideTooltip);
point.addEventListener("focus", reveal);
point.addEventListener("blur", hideTooltip);
point.addEventListener("click", () => setWeek(index));
point.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
setWeek(index);
}
});
});
}
$("#dataTable").innerHTML = observations
.map(
(d, index) => `
<tr data-index="${index}">
<td>${d.week}</td>
<td>${d.footfall}</td>
<td>${d.sales}</td>
</tr>
`
)
.join("");
$("#dataTable").querySelectorAll("tr").forEach((row) => {
row.addEventListener("click", () => setWeek(Number(row.dataset.index)));
});
function setWeek(index) {
state.weekIndex = THREE.MathUtils.clamp(index, 0, observations.length - 1);
const d = observations[state.weekIndex];
$("#weekChip").textContent = d.week;
$("#timelineWeek").textContent = d.week;
$("#weekSlider").value = String(state.weekIndex);
$("#footfallValue").textContent = d.footfall;
$("#salesValue").textContent = d.sales;
$("#footfallBar").style.width = `${Math.min(100, (d.footfall / 140) * 100)}%`;
$("#salesBar").style.width = `${Math.min(100, (d.sales / 140) * 100)}%`;
$("#liveRegion").textContent =
`${d.week}: footfall index ${d.footfall}, sales index ${d.sales}. ` +
`These synthetic observations show co-movement and do not establish causation.`;
state.customerCount = Math.round(
5 + ((d.footfall - 60) / 70) * 23
);
state.customerCount = THREE.MathUtils.clamp(
state.customerCount,
5,
customers.length
);
const visibleReceipts = Math.round((d.sales - 50) / 8);
receipts.forEach((receipt, receiptIndex) => {
receipt.visible = receiptIndex < visibleReceipts;
});
setLabel(footfallLabel, `FOOTFALL · ${d.footfall}`);
setLabel(salesLabel, `SALES · ${d.sales}`);
drawChart();
$("#dataTable").querySelectorAll("tr").forEach((row) => {
row.classList.toggle(
"selected",
Number(row.dataset.index) === state.weekIndex
);
});
}
$("#weekSlider").addEventListener("input", (event) => {
setWeek(Number(event.target.value));
});
function stopPlayback() {
state.playing = false;
clearInterval(state.playTimer);
state.playTimer = null;
$("#playButton").textContent = "Play";
}
$("#playButton").addEventListener("click", () => {
if (state.playing) {
stopPlayback();
return;
}
state.playing = true;
$("#playButton").textContent = "Pause";
state.playTimer = setInterval(() => {
setWeek((state.weekIndex + 1) % observations.length);
}, 850);
});
// ---------------------------------------------------------------------
// RENDER LOOP
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
for (let i = 0; i < customers.length; i++) {
const customer = customers[i];
customer.visible = i < state.customerCount;
if (!customer.visible) continue;
const { curve, offset, speed } = customer.userData;
const t = (time * speed + offset) % 1;
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
customer.position.set(point.x, 0.5, point.z);
customer.rotation.y = Math.atan2(tangent.x, tangent.z);
}
const current = observations[state.weekIndex];
const pulseHeight = 0.55 + ((current.footfall - 55) / 75) * 2.65;
pulses.forEach((pulse, index) => {
const wave = 0.88 + Math.sin(time * 2.4 - index * 0.55) * 0.12;
const height = pulseHeight * wave;
pulse.scale.y = height;
pulse.position.y = 0.71 + (0.5 * height) / 2;
pulse.rotation.y = time * 0.18 + index;
});
receipts.forEach((receipt, index) => {
if (!receipt.visible) return;
receipt.position.y =
1.48 + Math.sin(time * 1.8 + receipt.userData.phase) * 0.045;
receipt.rotation.z = Math.sin(time * 1.4 + index) * 0.035;
});
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
setWeek(state.weekIndex);
animate();
</script>
</body>
</html>
```