Prompt specification
Build or customize the Three.js 3D scene "City survey booth diorama" 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: City survey booth diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/city-survey-booth-diorama-x1831
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Compose a fictional square, distant neighborhoods, and a survey booth with visitor paths; illustrate who becomes reachable and who remains unobserved under the stated sampling rule.
Working Three.js Starter (city-survey-booth-diorama-x1831):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Aster Ward — Lantern Square Survey</title>
<style>
:root {
--ink: #17333a;
--muted: #60777b;
--paper: rgba(248, 246, 235, 0.94);
--line: rgba(23, 51, 58, 0.16);
--teal: #277f82;
--green: #238b65;
--amber: #d88932;
--violet: #826b9b;
--shadow: 0 12px 36px rgba(35, 62, 64, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbdcd6;
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;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
.brand {
top: 18px;
left: 18px;
width: 330px;
padding: 18px 20px 17px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 27px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.rule {
top: 18px;
right: 18px;
width: 365px;
padding: 17px 18px 16px;
}
.rule h2,
.roster h2 {
margin: 0 0 8px;
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.rule strong {
display: block;
margin-bottom: 7px;
font-size: 16px;
line-height: 1.3;
}
.rule p {
margin: 0;
color: var(--muted);
font-size: 11.5px;
line-height: 1.48;
}
.rule .note {
margin-top: 9px;
padding-top: 9px;
border-top: 1px solid var(--line);
font-style: italic;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
margin-top: 13px;
font-size: 10.5px;
color: var(--muted);
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--teal);
}
.swatch.green { background: var(--green); }
.swatch.amber { background: var(--amber); }
.swatch.violet { background: var(--violet); }
.stats {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 14px;
}
.stat {
min-width: 0;
padding: 8px 7px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,0.46);
}
.stat b {
display: block;
font-size: 19px;
line-height: 1;
font-variant-numeric: tabular-nums;
}
.stat small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 8px;
line-height: 1.25;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.roster {
left: 18px;
bottom: 82px;
width: 330px;
padding: 16px 18px;
}
.roster-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
}
.roster-head span {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.chips {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 10px;
}
.chip {
min-width: 0;
padding: 7px 5px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255,255,255,0.55);
transition: background 180ms, border-color 180ms, transform 180ms;
}
.chip b {
display: block;
font-size: 12px;
}
.chip small {
display: block;
overflow: hidden;
margin-top: 3px;
color: var(--muted);
font-size: 7.5px;
line-height: 1.15;
white-space: nowrap;
text-overflow: ellipsis;
}
.chip.sampled {
border-color: rgba(35,139,101,.55);
background: rgba(35,139,101,.14);
transform: translateY(-2px);
}
.chip.sampled small { color: var(--green); }
.chip.unsampled {
border-color: rgba(216,137,50,.48);
background: rgba(216,137,50,.12);
}
.chip.unsampled small { color: #a66728; }
.chip.no-access {
border-color: rgba(130,107,155,.42);
background: rgba(130,107,155,.12);
}
.chip.no-access small { color: var(--violet); }
.arrival-pips {
display: flex;
gap: 5px;
margin-top: 11px;
}
.pip {
position: relative;
height: 5px;
flex: 1;
overflow: hidden;
border-radius: 999px;
background: rgba(23,51,58,.10);
}
.pip.seen { background: var(--amber); }
.pip.sample { background: var(--green); }
.controls {
position: absolute;
left: 50%;
bottom: 18px;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: var(--shadow);
transform: translateX(-50%);
pointer-events: auto;
}
button {
min-height: 34px;
padding: 0 13px;
border: 0;
border-radius: 9px;
background: rgba(23,51,58,.07);
color: var(--ink);
font: 700 11px/1 ui-sans-serif, system-ui, sans-serif;
cursor: pointer;
transition: background 150ms, transform 150ms;
}
button:hover {
background: rgba(39,127,130,.16);
transform: translateY(-1px);
}
button:active { transform: translateY(0); }
button.primary { background: var(--teal); color: white; }
button.primary:hover { background: #206d70; }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #cbdcd6;
color: var(--ink);
font-size: 13px;
font-weight: 700;
letter-spacing: .08em;
text-transform: uppercase;
transition: opacity 350ms;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 900px) {
.brand { width: 285px; }
.rule { width: 320px; }
.roster { width: 285px; }
.stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 13px 15px;
}
h1 { font-size: 21px; }
.brand p { display: none; }
.rule {
top: 94px;
left: 10px;
right: 10px;
width: auto;
padding: 12px 14px;
}
.rule p, .rule .note { display: none; }
.rule strong { font-size: 13px; }
.legend { margin-top: 9px; font-size: 9px; }
.roster {
left: 10px;
bottom: 73px;
width: 250px;
padding: 12px;
}
.roster h2 { margin-bottom: 5px; }
.chips { grid-template-columns: repeat(4, 1fr); gap: 4px; }
.chip { padding: 5px 3px; }
.chip small { font-size: 6.5px; }
.controls {
bottom: 10px;
width: calc(100% - 20px);
justify-content: center;
}
button { padding: 0 9px; font-size: 9px; }
}
</style>
</head>
<body>
<div id="loading">Composing Lantern Square…</div>
<div id="hud">
<section class="panel brand">
<p class="eyebrow">Aster Ward · Field Study 04</p>
<h1>Lantern Square</h1>
<p>A fictional square where physical access and statistical observation are shown separately.</p>
</section>
<section class="panel rule">
<h2>Stated sampling rule</h2>
<strong>Sample every third arrival at the survey booth.</strong>
<p>
Eligibility requires reaching the booth’s front counter. Arrivals
<b>#3</b> and <b>#6</b> are sampled in this six-arrival cycle.
Other eligible arrivals remain reachable but unobserved.
</p>
<p class="note">Reachable does not mean observed. Violet routes never reach the booth.</p>
<div class="legend">
<span><i class="swatch"></i> booth-bound route</span>
<span><i class="swatch green"></i> sampled</span>
<span><i class="swatch amber"></i> reachable, unobserved</span>
<span><i class="swatch violet"></i> no booth access</span>
</div>
<div class="stats" aria-live="polite">
<div class="stat"><b id="arrival-count">0/6</b><small>Arrivals</small></div>
<div class="stat"><b id="sample-count">0</b><small>Sampled</small></div>
<div class="stat"><b id="missed-count">0</b><small>Unobserved</small></div>
<div class="stat"><b id="no-access-count">2</b><small>No access</small></div>
</div>
</section>
<section class="panel roster">
<div class="roster-head">
<h2>Visitor register</h2>
<span>Arrival order A—F</span>
</div>
<div class="chips">
<div class="chip" id="chip-A"><b>A</b><small>en route</small></div>
<div class="chip" id="chip-B"><b>B</b><small>en route</small></div>
<div class="chip" id="chip-C"><b>C</b><small>en route</small></div>
<div class="chip" id="chip-D"><b>D</b><small>en route</small></div>
<div class="chip" id="chip-E"><b>E</b><small>en route</small></div>
<div class="chip" id="chip-F"><b>F</b><small>en route</small></div>
<div class="chip no-access" id="chip-N1"><b>N1</b><small>no access</small></div>
<div class="chip no-access" id="chip-N2"><b>N2</b><small>no access</small></div>
</div>
<div class="arrival-pips" aria-hidden="true">
<i class="pip"></i><i class="pip"></i><i class="pip"></i>
<i class="pip"></i><i class="pip"></i><i class="pip"></i>
</div>
</section>
<nav class="controls" aria-label="Scene controls">
<button id="pause" class="primary">Pause</button>
<button id="replay">Replay cycle</button>
<button id="labels">Labels on</button>
<button id="reset-view">Reset view</button>
</nav>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbdcd6);
scene.fog = new THREE.Fog(0xcbdcd6, 58, 115);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-30, 30, 20, -20, 0.1, 180);
const cameraTarget = new THREE.Vector3(0, 1.2, 0);
let azimuth = -0.67;
let elevation = 0.72;
let cameraZoom = 1.03;
const hemi = new THREE.HemisphereLight(0xf6f4df, 0x78928a, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.2);
sun.position.set(-24, 38, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 42;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 95;
sun.shadow.bias = -0.0004;
scene.add(sun);
const worldLabels = new THREE.Group();
scene.add(worldLabels);
const materialCache = new Map();
function mat(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({ color, roughness: 0.92, metalness: 0 })
);
}
return materialCache.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat(color));
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function label(text, color = "#17333a", background = "rgba(248,246,235,.92)", width = 4) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
roundedRect(ctx, 8, 8, 496, 112, 20);
ctx.fill();
ctx.strokeStyle = "rgba(23,51,58,.18)";
ctx.lineWidth = 4;
roundedRect(ctx, 8, 8, 496, 112, 20);
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "800 37px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 30;
return sprite;
}
function addLabel(text, x, y, z, options = {}) {
const sprite = label(
text,
options.color || "#17333a",
options.background || "rgba(248,246,235,.92)",
options.width || 4
);
sprite.position.set(x, y, z);
worldLabels.add(sprite);
return sprite;
}
// Ground and street grid.
box(scene, 72, 1, 72, 0xaec3a8, 0, -0.66, 0, false);
box(scene, 68, 0.13, 5.3, 0x7f9491, 0, -0.07, 20, false);
box(scene, 68, 0.13, 5.3, 0x7f9491, 0, -0.07, -20, false);
box(scene, 5.3, 0.13, 68, 0x7f9491, 20, -0.07, 0, false);
box(scene, 5.3, 0.13, 68, 0x7f9491, -20, -0.07, 0, false);
box(scene, 34, 0.20, 34, 0xd8d0b9, 0, -0.03, 0, false);
// Instanced plaza tiles.
const tileCount = 30 * 30;
const tileGeo = new THREE.BoxGeometry(0.97, 0.12, 0.97);
const tileMat = new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 1 });
const tiles = new THREE.InstancedMesh(tileGeo, tileMat, tileCount);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const tilePalette = [0xe7dec7, 0xe3dac3, 0xeadfc8, 0xdcd7c2, 0xeee3ca];
let ti = 0;
for (let z = 0; z < 30; z++) {
for (let x = 0; x < 30; x++) {
dummy.position.set(x - 14.5, 0.12, z - 14.5);
dummy.updateMatrix();
tiles.setMatrixAt(ti, dummy.matrix);
const edge = x === 0 || z === 0 || x === 29 || z === 29;
const color = new THREE.Color(edge ? 0xd1c9b4 : tilePalette[(x * 3 + z * 5) % 5]);
tiles.setColorAt(ti, color);
ti++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// Voxel landscaping.
function tree(x, z, scale = 1) {
box(scene, 0.48 * scale, 2.1 * scale, 0.48 * scale, 0x705d47, x, 1.0 * scale, z);
box(scene, 2.3 * scale, 1.35 * scale, 2.3 * scale, 0x507f68, x, 2.15 * scale, z);
box(scene, 1.55 * scale, 1.05 * scale, 1.55 * scale, 0x6d9c74, x, 2.95 * scale, z);
box(scene, 0.85 * scale, 0.8 * scale, 0.85 * scale, 0x83ad7b, x, 3.65 * scale, z);
}
function planter(x, z) {
box(scene, 3.2, 0.45, 3.2, 0x8f7960, x, 0.3, z);
box(scene, 2.7, 0.16, 2.7, 0x536f58, x, 0.58, z);
tree(x, z, 0.82);
}
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(group, 2.8, 0.25, 0.7, 0x8a654c, 0, 0.8, 0);
box(group, 2.8, 0.7, 0.2, 0x9c7455, 0, 1.2, 0.34);
box(group, 0.22, 0.75, 0.55, 0x4c5c59, -1, 0.42, 0);
box(group, 0.22, 0.75, 0.55, 0x4c5c59, 1, 0.42, 0);
}
planter(-14, -14);
planter(14, -14);
planter(-14, 14);
planter(14, 14);
planter(-13, 2);
tree(-5, -13, 0.72);
tree(5, -13, 0.72);
tree(-8, 15, 0.7);
tree(0, 15, 0.7);
bench(-9, -7, Math.PI / 2);
bench(9, -7, -Math.PI / 2);
bench(-7, 3, 0);
bench(6, 3, 0);
bench(-16, 5, Math.PI / 2);
// Central civic hall.
const hall = new THREE.Group();
hall.position.set(0, 0, -5.2);
scene.add(hall);
box(hall, 10.5, 0.45, 5.6, 0xb4a98e, 0, 0.32, 0);
box(hall, 8.5, 3.5, 4.3, 0xe8dcc0, 0, 2.2, 0);
box(hall, 9.2, 0.35, 4.9, 0xc56d4f, 0, 4.12, 0);
box(hall, 5.8, 0.45, 3.1, 0xd27b58, 0, 4.48, 0);
box(hall, 2.1, 2.15, 0.22, 0x527477, 0, 1.55, -2.22);
box(hall, 0.25, 2.3, 0.34, 0xf3dfaa, -2.7, 2.2, -2.23);
box(hall, 0.25, 2.3, 0.34, 0xf3dfaa, 2.7, 2.2, -2.23);
addLabel("TOWN HALL", 0, 6.1, -5.2, { width: 5.4 });
// Stepped voxel fountain.
box(scene, 4.2, 0.4, 4.2, 0xb7a991, 0, 0.38, 0);
box(scene, 3.35, 0.35, 3.35, 0x6fa9aa, 0, 0.72, 0);
box(scene, 1.1, 1.35, 1.1, 0xc2b89e, 0, 1.45, 0);
box(scene, 2.0, 0.28, 2.0, 0x78b6b6, 0, 2.17, 0);
box(scene, 0.62, 0.85, 0.62, 0x7dbbb9, 0, 2.68, 0);
// Survey booth and front-counter approach.
const booth = new THREE.Group();
booth.position.set(10, 0, 9);
scene.add(booth);
box(booth, 4.2, 0.35, 3.6, 0x9b917b, 0, 0.25, 0);
box(booth, 3.5, 2.55, 0.28, 0xf0dfb7, 1.45, 1.65, 0);
box(booth, 0.28, 2.55, 3.0, 0xe6d4ae, 0, 1.65, -1.35);
box(booth, 0.28, 2.55, 3.0, 0xe6d4ae, 0, 1.65, 1.35);
box(booth, 0.68, 0.55, 2.65, 0x277f82, -1.35, 1.22, 0);
box(booth, 3.9, 0.4, 3.8, 0xd66f48, 0, 3.02, 0);
box(booth, 2.8, 0.24, 2.8, 0xe58c5e, 0, 3.32, 0);
box(booth, 0.22, 2.6, 0.22, 0x375e60, -1.45, 1.65, -1.35);
box(booth, 0.22, 2.6, 0.22, 0x375e60, -1.45, 1.65, 1.35);
box(booth, 0.45, 0.42, 0.45, 0x234d52, -1.45, 2.25, 0);
box(booth, 0.2, 0.2, 0.2, 0x8ff0c1, -1.7, 2.25, 0);
for (let x = 7; x <= 9; x++) {
for (let z = 8; z <= 10; z++) {
box(scene, 0.92, 0.08, 0.92, 0xb9d6b3, x, 0.225, z, false);
}
}
addLabel("SURVEY", 10, 4.5, 9, {
color: "#17333a",
background: "rgba(239,190,112,.96)",
width: 4.1
});
addLabel("FRONT COUNTER", 8.2, 3.5, 9, {
color: "#277f82",
width: 3.5
});
// Distant voxel neighborhoods.
function building(x, z, w, d, h, color, roofColor) {
box(scene, w, h, d, color, x, h / 2, z);
box(scene, w + 0.25, 0.28, d + 0.25, roofColor, x, h + 0.14, z);
if (w > 5 && h > 5) {
box(scene, w * 0.46, 0.8, d * 0.46, roofColor, x, h + 0.65, z);
}
const frontZ = z > 0 ? z - d / 2 - 0.08 : z + d / 2 + 0.08;
const windowRows = Math.max(1, Math.floor(h / 3));
for (let row = 0; row < windowRows; row++) {
for (let col = -1; col <= 1; col++) {
if ((row + col + 8) % 3 === 0) continue;
box(
scene,
0.58,
0.72,
0.12,
0xf0dfa9,
x + col * Math.min(1.65, w * 0.28),
1.55 + row * 2.25,
frontZ,
false
);
}
}
}
const neighborhoodData = [
[-27,-27,7,6,7,0xc8836e,0x805d60],
[-18,-27,6,6,10,0xd3aa72,0x866b62],
[-28,-18,6,7,5,0x789da0,0x596f78],
[-19,-18,7,6,8,0x8fa5ae,0x65747e],
[18,-27,7,6,8,0x78969b,0x5a6e75],
[27,-26,7,7,11,0xc28b76,0x775b61],
[18,-18,7,6,5,0xd1b47e,0x8b765e],
[27,-17,6,6,8,0x8198ae,0x596b84],
[-27,27,7,6,9,0x7e9b9b,0x5b7174],
[-18,27,7,6,6,0xc7947c,0x805f62],
[-28,18,6,7,12,0xaab19a,0x6d7665],
[18,27,7,6,10,0x7899a8,0x576d82],
[27,27,7,7,7,0xd19b72,0x84655d],
[27,7,6,7,9,0xb08d7c,0x745d61],
[27,-4,6,6,6,0x87a4a4,0x5d7778]
];
neighborhoodData.forEach((b) => building(...b));
addLabel("PINE ROW", -23, 13.8, -27, { width: 4.2 });
addLabel("EAST MARKET", 24, 14.5, -27, { width: 4.8 });
addLabel("CANAL ROW", -23, 14, 27, { width: 4.4 });
addLabel("RAIL END", 24, 13.6, 27, { width: 4.2 });
addLabel("LANTERN SQUARE", 0, 0.55, 17.8, {
color: "#536f70",
background: "rgba(230,220,192,.75)",
width: 6.2
});
// Street lamps.
function lamp(x, z) {
box(scene, 0.18, 4.4, 0.18, 0x425c5d, x, 2.2, z);
box(scene, 0.8, 0.22, 0.8, 0x425c5d, x, 4.42, z);
box(scene, 0.55, 0.36, 0.55, 0xf4dda0, x, 4.18, z, false);
}
[[-16,-10],[16,-10],[-16,10],[16,15],[-4,18],[4,-18]].forEach((p) => lamp(...p));
// Visitor routes.
const BOOTH_APPROACH = new THREE.Vector2(8, 9);
const boothVisitors = [
{
id: "A",
arrivalTime: 4.5,
shirt: 0x4b8ea8,
prefix: [[-20,12],[-12,12],[-12,7],[7,7],[7,9],[8,9]],
exit: [[8,9],[8,14],[-20,14]],
gate: "WEST GATE"
},
{
id: "B",
arrivalTime: 7.7,
shirt: 0x5f82ae,
prefix: [[4,-20],[4,-12],[4,7],[7,7],[7,9],[8,9]],
exit: [[8,9],[8,15],[14,15],[14,-21]],
gate: "SOUTH GATE"
},
{
id: "C",
arrivalTime: 10.9,
shirt: 0x3f8991,
prefix: [[-2,20],[-2,12],[-2,7],[7,7],[7,9],[8,9]],
exit: [[8,9],[8,18],[-6,18]],
gate: "NORTH GATE"
},
{
id: "D",
arrivalTime: 14.1,
shirt: 0x6f91b2,
prefix: [[20,12],[12,12],[12,9],[8,9]],
exit: [[8,9],[15,9],[15,16],[21,16]],
gate: "EAST GATE"
},
{
id: "E",
arrivalTime: 17.3,
shirt: 0x487d8f,
prefix: [[-18,-14],[-10,-14],[-10,7],[7,7],[7,9],[8,9]],
exit: [[8,9],[3,9],[3,-16],[-18,-16]],
gate: "OLD RAIL"
},
{
id: "F",
arrivalTime: 20.5,
shirt: 0x4e9a9b,
prefix: [[12,-18],[12,-10],[7,-10],[7,7],[7,9],[8,9]],
exit: [[8,9],[12,9],[12,12],[20,12]],
gate: "MARKET WALK"
}
];
const noAccessVisitors = [
{
id: "N1",
shirt: 0x826b9b,
path: [[-24,16],[-24,-16],[-18,-16],[-18,16]],
offset: 0,
speed: 2.5
},
{
id: "N2",
shirt: 0x927ba8,
path: [[-6,24],[18,24],[18,18],[-6,18]],
offset: 17,
speed: 2.25
}
];
function polylineLength(points) {
let length = 0;
for (let i = 1; i < points.length; i++) {
length += Math.hypot(points[i][0] - points[i - 1][0], points[i][1] - points[i - 1][1]);
}
return length;
}
function pointAtDistance(points, distance) {
if (distance <= 0) return new THREE.Vector2(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) {
const a = points[i - 1];
const b = points[i];
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
if (distance <= length) {
const t = length === 0 ? 0 : distance / length;
return new THREE.Vector2(
THREE.MathUtils.lerp(a[0], b[0], t),
THREE.MathUtils.lerp(a[1], b[1], t)
);
}
distance -= length;
}
const last = points[points.length - 1];
return new THREE.Vector2(last[0], last[1]);
}
const routePixelGeo = new THREE.BoxGeometry(0.29, 0.09, 0.29);
function voxelRoute(points, color, layer = 0, closed = false) {
const positions = [];
const count = closed ? points.length : points.length - 1;
for (let i = 0; i < count; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
const ux = (b[0] - a[0]) / length;
const uz = (b[1] - a[1]) / length;
const steps = Math.max(1, Math.ceil(length / 0.83));
for (let j = 0; j < steps; j++) {
const d = (j + 0.5) / steps * length;
positions.push([a[0] + ux * d, a[1] + uz * d]);
}
}
const routeMat = new THREE.MeshStandardMaterial({
color,
roughness: 1,
transparent: true,
opacity: 0.72
});
const mesh = new THREE.InstancedMesh(routePixelGeo, routeMat, positions.length);
const obj = new THREE.Object3D();
positions.forEach((p, index) => {
obj.position.set(p[0], 0.255 + layer * 0.002, p[1]);
obj.updateMatrix();
mesh.setMatrixAt(index, obj.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
boothVisitors.forEach((visitor, index) => {
visitor.path = visitor.prefix.concat(visitor.exit.slice(1));
visitor.boothDistance = polylineLength(visitor.prefix);
visitor.totalDistance = polylineLength(visitor.path);
visitor.startTime = visitor.arrivalTime - visitor.boothDistance / 3.6;
visitor.finishTime =
visitor.arrivalTime +
0.9 +
(visitor.totalDistance - visitor.boothDistance) / 3.6;
voxelRoute(
visitor.path,
[0x4e91ad, 0x5a84ac, 0x3f8790, 0x7397b5, 0x477b8c, 0x4d969d][index],
index
);
const gate = addLabel(visitor.gate, visitor.path[0][0], 0.9, visitor.path[0][1], {
color: "#477986",
width: 3.1
});
gate.material.opacity = 0.78;
});
noAccessVisitors.forEach((visitor, index) => {
visitor.totalDistance = polylineLength(visitor.path);
voxelRoute(visitor.path, 0x826b9b, 10 + index, true);
});
// Voxel people, sample halos, and scanner beams.
const sampleGreen = 0x2e9b70;
const missedAmber = 0xd88932;
function makePerson(id, shirtColor) {
const group = new THREE.Group();
scene.add(group);
const shadow = box(group, 0.82, 0.035, 0.62, 0x4f6661, 0, 0.035, 0, false);
shadow.material = new THREE.MeshBasicMaterial({
color: 0x49615c,
transparent: true,
opacity: 0.18,
depthWrite: false
});
const leftLeg = box(group, 0.23, 0.5, 0.28, 0x344c55, -0.16, 0.38, 0);
const rightLeg = box(group, 0.23, 0.5, 0.28, 0x344c55, 0.16, 0.38, 0);
const shirtMat = new THREE.MeshStandardMaterial({ color: shirtColor, roughness: 0.92 });
const torso = new THREE.Mesh(new THREE.BoxGeometry(0.58, 0.62, 0.38), shirtMat);
torso.position.y = 0.93;
torso.castShadow = true;
group.add(torso);
const skin = id === "N1" || id === "N2" ? 0xa87e67 : 0xd5a27f;
box(group, 0.4, 0.4, 0.4, skin, 0, 1.45, 0);
box(group, 0.45, 0.13, 0.44, id === "N1" || id === "N2" ? 0x5c506b : 0x35565d, 0, 1.67, 0);
box(group, 0.18, 0.55, 0.2, shirtColor, -0.39, 0.92, 0);
box(group, 0.18, 0.55, 0.2, shirtColor, 0.39, 0.92, 0);
const idTag = label(id, "#17333a", "rgba(248,246,235,.94)", 1.25);
idTag.position.y = 2.15;
group.add(idTag);
const halo = new THREE.Group();
for (let i = 0; i < 12; i++) {
const angle = i / 12 * Math.PI * 2;
const pixel = box(
halo,
0.23,
0.12,
0.23,
sampleGreen,
Math.cos(angle) * 0.86,
0.1,
Math.sin(angle) * 0.86,
false
);
pixel.material = new THREE.MeshBasicMaterial({ color: sampleGreen });
}
halo.visible = false;
group.add(halo);
const sampledTag = label("SAMPLED", "#ffffff", "rgba(35,139,101,.97)", 2.0);
sampledTag.position.y = 2.78;
sampledTag.visible = false;
group.add(sampledTag);
const beamGeo = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(8.3, 2.25, 9),
new THREE.Vector3(8, 1.4, 9)
]);
const beam = new THREE.Line(
beamGeo,
new THREE.LineBasicMaterial({
color: sampleGreen,
transparent: true,
opacity: 0.72,
depthTest: false
})
);
beam.visible = false;
beam.frustumCulled = false;
beam.renderOrder = 12;
scene.add(beam);
return {
group,
shirtMat,
halo,
sampledTag,
beam,
baseColor: shirtColor,
sampled: false,
arrived: false
};
}
boothVisitors.forEach((v) => {
Object.assign(v, makePerson(v.id, v.shirt));
});
noAccessVisitors.forEach((v) => {
Object.assign(v, makePerson(v.id, v.shirt));
const noAccessTag = label("NO BOOTH", "#69527f", "rgba(232,222,238,.93)", 2.1);
noAccessTag.position.y = 2.72;
v.group.add(noAccessTag);
});
// Camera controls implemented without addons.
function updateCamera() {
const halfHeight = Math.max(19, 34 / camera.aspect);
camera.left = -halfHeight * camera.aspect;
camera.right = halfHeight * camera.aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
const radius = 75;
camera.position.set(
cameraTarget.x + Math.sin(azimuth) * Math.cos(elevation) * radius,
cameraTarget.y + Math.sin(elevation) * radius,
cameraTarget.z + Math.cos(azimuth) * Math.cos(elevation) * radius
);
camera.lookAt(cameraTarget);
}
function resize() {
renderer.setSize(innerWidth, innerHeight);
camera.aspect = innerWidth / innerHeight;
updateCamera();
}
addEventListener("resize", resize);
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
if (pointers.size === 1) {
azimuth -= (event.clientX - previous.x) * 0.006;
elevation = THREE.MathUtils.clamp(
elevation + (event.clientY - previous.y) * 0.005,
0.38,
1.28
);
updateCamera();
} else if (pointers.size === 2) {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
cameraZoom = THREE.MathUtils.clamp(cameraZoom * distance / pinchDistance, 0.65, 2.4);
updateCamera();
}
pinchDistance = distance;
return;
}
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.4
);
updateCamera();
},
{ passive: false }
);
// Sampling state.
const CYCLE_LENGTH = 34;
const BOOTH_PAUSE = 0.9;
let simulationTime = 0;
let currentCycle = -1;
let localTime = 0;
let arrivalCount = 0;
let sampleCount = 0;
let paused = false;
const pips = [...document.querySelectorAll(".pip")];
function resetVisitor(v) {
v.sampled = false;
v.arrived = false;
v.shirtMat.color.setHex(v.baseColor);
v.halo.visible = false;
v.sampledTag.visible = false;
v.beam.visible = false;
}
function updateRegister() {
boothVisitors.forEach((v) => {
const chip = $(`#chip-${v.id}`);
chip.classList.remove("sampled", "unsampled");
const text = chip.querySelector("small");
if (v.sampled) {
chip.classList.add("sampled");
text.textContent = "sampled";
} else if (v.arrived) {
chip.classList.add("unsampled");
text.textContent = "not sampled";
} else {
text.textContent = "en route";
}
});
$("#arrival-count").textContent = `${arrivalCount}/6`;
$("#sample-count").textContent = sampleCount;
$("#missed-count").textContent = arrivalCount - sampleCount;
$("#no-access-count").textContent = "2";
pips.forEach((pip, index) => {
pip.classList.toggle("seen", index < arrivalCount);
pip.classList.toggle("sample", index < sampleCount && (index + 1) % 3 === 0);
});
}
function resetRun() {
arrivalCount = 0;
sampleCount = 0;
boothVisitors.forEach(resetVisitor);
updateRegister();
}
function processArrivals(t) {
for (const visitor of boothVisitors) {
if (!visitor.arrived && t >= visitor.arrivalTime) {
visitor.arrived = true;
arrivalCount++;
visitor.sampled = arrivalCount % 3 === 0;
if (visitor.sampled) {
sampleCount++;
visitor.shirtMat.color.setHex(sampleGreen);
visitor.halo.visible = true;
visitor.sampledTag.visible = true;
visitor.beam.visible = true;
} else {
visitor.shirtMat.color.setHex(missedAmber);
}
updateRegister();
}
}
}
const beamStart = new THREE.Vector3(8.3, 2.25, 9);
const beamEnd = new THREE.Vector3();
function updateVisitor(v, t) {
if (t < v.startTime) {
v.group.visible = false;
return;
}
v.group.visible = true;
let distance;
if (t < v.arrivalTime) {
distance = (t - v.startTime) * 3.6;
} else if (t < v.arrivalTime + BOOTH_PAUSE) {
distance = v.boothDistance;
} else {
distance = v.boothDistance + (t - v.arrivalTime - BOOTH_PAUSE) * 3.6;
}
if (distance >= v.totalDistance) {
v.group.visible = false;
return;
}
const position = pointAtDistance(v.path, distance);
const ahead = pointAtDistance(v.path, Math.min(distance + 0.3, v.totalDistance));
v.group.position.set(position.x, 0.22, position.y);
v.group.rotation.y = Math.atan2(ahead.x - position.x, ahead.y - position.y);
const moving = t < v.arrivalTime || t > v.arrivalTime + BOOTH_PAUSE;
v.group.position.y += moving ? Math.abs(Math.sin((t - v.startTime) * 9)) * 0.045 : 0;
if (v.sampled) {
v.halo.rotation.y = t * 0.9;
v.beam.visible = true;
beamEnd.set(v.group.position.x, 1.45, v.group.position.z);
const attribute = v.beam.geometry.attributes.position;
attribute.setXYZ(0, beamStart.x, beamStart.y, beamStart.z);
attribute.setXYZ(1, beamEnd.x, beamEnd.y, beamEnd.z);
attribute.needsUpdate = true;
}
}
function updateOutsideVisitor(v, t) {
const distance = (t * v.speed + v.offset) % v.totalDistance;
const position = pointAtDistance(v.path, distance);
const ahead = pointAtDistance(v.path, (distance + 0.3) % v.totalDistance);
v.group.position.set(position.x, 0.22, position.y);
v.group.rotation.y = Math.atan2(ahead.x - position.x, ahead.y - position.y);
v.group.position.y += Math.abs(Math.sin(t * 8 + v.offset)) * 0.035;
}
// UI controls.
$("#pause").addEventListener("click", () => {
paused = !paused;
$("#pause").textContent = paused ? "Resume" : "Pause";
$("#pause").classList.toggle("primary", !paused);
});
$("#replay").addEventListener("click", () => {
simulationTime = 0;
currentCycle = -1;
localTime = 0;
resetRun();
});
$("#labels").addEventListener("click", () => {
worldLabels.visible = !worldLabels.visible;
$("#labels").textContent = worldLabels.visible ? "Labels on" : "Labels off";
});
$("#reset-view").addEventListener("click", () => {
azimuth = -0.67;
elevation = 0.72;
cameraZoom = 1.03;
updateCamera();
});
addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
$("#pause").click();
}
if (event.key.toLowerCase() === "r") $("#replay").click();
if (event.key === "ArrowLeft") {
azimuth -= 0.12;
updateCamera();
}
if (event.key === "ArrowRight") {
azimuth += 0.12;
updateCamera();
}
});
resize();
resetRun();
let lastTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) simulationTime += delta;
const cycle = Math.floor(simulationTime / CYCLE_LENGTH);
localTime = simulationTime - cycle * CYCLE_LENGTH;
if (cycle !== currentCycle) {
currentCycle = cycle;
resetRun();
}
processArrivals(localTime);
boothVisitors.forEach((visitor) => updateVisitor(visitor, localTime));
noAccessVisitors.forEach((visitor) => updateOutsideVisitor(visitor, localTime));
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
$("#loading").classList.add("hidden");
</script>
</body>
</html>
```