Prompt specification
Build or customize the Three.js 3D scene "Municipal Service Request 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: Municipal Service Request Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/municipal-service-request-diorama-x3231
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts institutional roles, approval steps, and oversight. Build a fictional civic service office with reporting, scheduling, fieldwork, and verification areas. Trace a broken bench request while keeping the procedure explicitly illustrative. Voxel style.
Working Three.js Starter (municipal-service-request-diorama-x3231):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Illustrative Civic Office — Broken Bench Request</title>
<style>
:root {
color-scheme: light;
--ink: #13242d;
--muted: #5f7078;
--paper: rgba(250, 249, 244, 0.94);
--line: rgba(19, 36, 45, 0.15);
--cyan: #31c7c5;
--orange: #ff9f43;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dde6e2;
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;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 12px 40px rgba(31, 49, 55, 0.13);
backdrop-filter: blur(14px);
}
#titleCard {
top: 18px;
left: 18px;
width: min(410px, calc(100vw - 36px));
padding: 17px 19px;
pointer-events: none;
}
.eyebrow {
color: #477078;
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 5px;
font-size: clamp(21px, 2.3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.illustrative-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 11px;
padding: 6px 9px;
border: 1px solid rgba(255, 159, 67, 0.45);
border-radius: 999px;
background: rgba(255, 159, 67, 0.12);
color: #9a5411;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.illustrative-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--orange);
box-shadow: 0 0 0 3px rgba(255, 159, 67, 0.16);
}
#processPanel {
top: 190px;
left: 18px;
width: 306px;
padding: 15px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 11px;
}
.panel-heading strong {
font-size: 12px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.case-id {
color: #567078;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#stageList {
display: grid;
gap: 6px;
}
.stage-button {
display: grid;
grid-template-columns: 30px 1fr;
align-items: center;
gap: 9px;
width: 100%;
padding: 8px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.stage-button:hover {
background: rgba(49, 199, 197, 0.08);
border-color: rgba(49, 199, 197, 0.22);
}
.stage-button.active {
background: white;
border-color: rgba(19, 36, 45, 0.17);
box-shadow: 0 5px 16px rgba(19, 36, 45, 0.08);
}
.stage-number {
display: grid;
place-items: center;
width: 29px;
height: 29px;
border-radius: 7px;
color: #102129;
font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}
.stage-name {
display: block;
font-size: 12px;
font-weight: 800;
}
.stage-role {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
#stageDetail {
margin-top: 12px;
padding: 12px;
border-top: 1px solid var(--line);
}
#stageKicker {
color: #6c7d84;
font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#stageTitle {
margin: 5px 0;
font-size: 15px;
line-height: 1.2;
}
#stageText {
margin: 0;
color: #596d75;
font-size: 11px;
line-height: 1.45;
}
#approvalTag {
display: inline-block;
margin-top: 9px;
padding: 5px 7px;
border-radius: 6px;
background: rgba(49, 199, 197, 0.12);
color: #167c7a;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-transform: uppercase;
}
#viewPanel {
top: 18px;
right: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
width: 292px;
padding: 8px;
}
button {
font: 700 11px/1 ui-sans-serif, system-ui, sans-serif;
}
.tool {
min-height: 34px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.8);
color: var(--ink);
cursor: pointer;
}
.tool:hover { background: white; }
.tool.accent { background: var(--ink); color: white; }
#legend {
right: 18px;
bottom: 63px;
padding: 11px 13px;
color: #526870;
font-size: 10px;
line-height: 1.7;
}
#legend strong {
color: var(--ink);
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: inset 0 -1px 0 rgba(0,0,0,.16);
}
#footer {
position: fixed;
z-index: 10;
right: 18px;
bottom: 16px;
left: 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
pointer-events: none;
color: #526870;
font-size: 10px;
}
#footer strong {
color: #263e48;
font-weight: 800;
}
#hint {
padding: 8px 11px;
border: 1px solid rgba(19, 36, 45, 0.13);
border-radius: 8px;
background: rgba(250, 249, 244, 0.83);
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #dde6e2;
color: var(--ink);
font: 700 13px/1.4 ui-monospace, monospace;
text-align: center;
}
@media (max-width: 760px) {
#titleCard {
width: calc(100vw - 36px);
padding: 13px 15px;
}
#titleCard .subtitle { display: none; }
.illustrative-badge { margin-top: 8px; }
#processPanel {
top: auto;
right: 12px;
bottom: 54px;
left: 12px;
width: auto;
padding: 9px;
}
#stageList {
display: flex;
overflow-x: auto;
padding-bottom: 3px;
}
.stage-button {
flex: 0 0 118px;
grid-template-columns: 25px 1fr;
gap: 6px;
padding: 6px;
}
.stage-number { width: 24px; height: 24px; }
.stage-name { font-size: 10px; }
.stage-role { font-size: 8px; }
#stageDetail { display: none; }
#viewPanel {
top: 132px;
right: 12px;
width: 210px;
}
#legend { display: none; }
#footer { right: 12px; bottom: 12px; left: 12px; }
#hint { display: none; }
#footer .disclaimer { max-width: 80%; line-height: 1.35; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel civic service office"></canvas>
<header id="titleCard" class="panel">
<div class="eyebrow">Civic Works / Request Trace</div>
<h1>Broken bench request</h1>
<p class="subtitle">
A fictional office showing reporting, scheduling, fieldwork, verification,
and oversight as an illustrative approval path.
</p>
<div class="illustrative-badge">Illustrative scenario · not official procedure</div>
</header>
<aside id="processPanel" class="panel" aria-label="Request stages">
<div class="panel-heading">
<strong>Approval trace</strong>
<span class="case-id">BRK-BCH-042</span>
</div>
<div id="stageList"></div>
<div id="stageDetail" aria-live="polite">
<div id="stageKicker">Step 01 · Role</div>
<div id="stageTitle">Report received</div>
<p id="stageText"></p>
<div id="approvalTag"></div>
</div>
</aside>
<nav id="viewPanel" class="panel" aria-label="Scene controls">
<button id="pauseBtn" class="tool accent">Pause trace</button>
<button id="flowBtn" class="tool">Hide flow</button>
<button id="labelsBtn" class="tool">Hide labels</button>
<button id="resetBtn" class="tool">Reset view</button>
<button id="zoomInBtn" class="tool" aria-label="Zoom in">+</button>
<button id="zoomOutBtn" class="tool" aria-label="Zoom out">-</button>
</nav>
<div id="legend" class="panel">
<strong>Scene key</strong>
<div class="legend-row"><span class="swatch" style="background:#31c7c5"></span> Request route</div>
<div class="legend-row"><span class="swatch" style="background:#ff9f43"></span> Moving request ticket</div>
<div class="legend-row"><span class="swatch" style="background:#ff6565"></span> Reported bench defect</div>
<div class="legend-row"><span class="swatch" style="background:#62d394"></span> Verified repair</div>
</div>
<footer id="footer">
<div class="disclaimer">
<strong>Illustrative only.</strong>
Fictional roles and approvals; not official policy, repair guidance, or legal advice.
</div>
<div id="hint">Drag: orbit · Right/Shift-drag: pan · Wheel: zoom · 0: reset</div>
</footer>
<div id="loading">Building the illustrative civic office…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dde6e2");
scene.fog = new THREE.Fog("#dde6e2", 65, 115);
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.OrthographicCamera(-20, 20, 16, -16, 0.1, 180);
const view = {
azimuth: 0.78,
polar: 0.88,
zoom: 1,
target: new THREE.Vector3(0, 0, 0),
desiredTarget: new THREE.Vector3(0, 0, 0)
};
const hemi = new THREE.HemisphereLight("#f9fffc", "#75857b", 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff4dd", 3.2);
sun.position.set(18, 32, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 32;
sun.shadow.camera.bottom = -32;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#bfe8ff", 0.8);
fill.position.set(-20, 12, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Voxel helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function box(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const M = {
foundation: material("#52656a"),
ground: material("#cbd6cf"),
wall: material("#ece7db"),
wallEdge: material("#c8c3b5"),
dark: material("#21343c"),
darker: material("#12252d"),
steel: material("#91a5aa", { roughness: 0.55, metalness: 0.25 }),
wood: material("#a8733f"),
woodLight: material("#c79459"),
red: material("#ef5c5c", {
emissive: "#8c1717",
emissiveIntensity: 0.25
}),
orange: material("#ff9f43", {
emissive: "#b75200",
emissiveIntensity: 0.42
}),
cyan: material("#31c7c5", {
emissive: "#087d7b",
emissiveIntensity: 0.42
}),
green: material("#62d394", {
emissive: "#167445",
emissiveIntensity: 0.38
}),
screen: material("#8be8e1", {
emissive: "#1eaaa7",
emissiveIntensity: 0.75,
roughness: 0.35
}),
paper: material("#f8f3e6"),
glass: material("#8dc8d3", {
roughness: 0.28,
metalness: 0.08,
emissive: "#235968",
emissiveIntensity: 0.14
})
};
// -------------------------------------------------------------------------
// Text sprites made locally with canvas textures
// -------------------------------------------------------------------------
const labelsGroup = new THREE.Group();
scene.add(labelsGroup);
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 createLabelSprite(title, subtitle = "", options = {}) {
const {
width = 5,
background = "#142a33",
foreground = "#f8faf5",
accent = "#31c7c5"
} = options;
const c = document.createElement("canvas");
c.width = 768;
c.height = subtitle ? 164 : 112;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
roundedRect(ctx, 4, 4, c.width - 8, c.height - 8, 18);
ctx.fillStyle = background;
ctx.fill();
ctx.fillStyle = accent;
roundedRect(ctx, 4, 4, 18, c.height - 8, 8);
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = `700 ${subtitle ? 34 : 38}px "Courier New", monospace`;
ctx.fillText(title, c.width / 2 + 8, subtitle ? 57 : c.height / 2);
if (subtitle) {
ctx.fillStyle = "#b7c7ca";
ctx.font = '600 23px "Courier New", monospace';
ctx.fillText(subtitle, c.width / 2 + 8, 113);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: true
}));
sprite.scale.set(width, width * c.height / c.width, 1);
sprite.renderOrder = 4;
return sprite;
}
function addLabel(title, subtitle, position, options = {}) {
const sprite = createLabelSprite(title, subtitle, options);
sprite.position.set(position[0], position[1], position[2]);
labelsGroup.add(sprite);
return sprite;
}
function addNumberSprite(number, color, parent, position) {
const c = document.createElement("canvas");
c.width = 128;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = color;
ctx.fillRect(0, 0, 128, 128);
ctx.strokeStyle = "rgba(255,255,255,.7)";
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, 112, 112);
ctx.fillStyle = "#102129";
ctx.font = "800 68px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 64, 68);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.scale.set(0.78, 0.78, 1);
sprite.position.set(position[0], position[1], position[2]);
sprite.renderOrder = 6;
parent.add(sprite);
return sprite;
}
// -------------------------------------------------------------------------
// Floor, zone tiles, and architecture
// -------------------------------------------------------------------------
box(scene, [120, 0.25, 100], [0, -0.86, 0], M.ground, false);
box(scene, [39, 0.6, 29], [0, -0.38, 0], M.foundation);
function tileField(x0, x1, z0, z1, color) {
const count = ((x1 - x0) / 2) * ((z1 - z0) / 2);
const mesh = new THREE.InstancedMesh(
unitBox,
material(color),
count
);
const dummy = new THREE.Object3D();
let index = 0;
for (let x = x0; x < x1; x += 2) {
for (let z = z0; z < z1; z += 2) {
dummy.position.set(x + 1, 0, z + 1);
dummy.scale.set(1.91, 0.12, 1.91);
dummy.updateMatrix();
mesh.setMatrixAt(index++, dummy.matrix);
}
}
mesh.instanceMatrix.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
tileField(-18, -2, -12, 0, "#e9cf9d"); // Reporting
tileField(0, 16, -12, 0, "#b9d8e7"); // Scheduling
tileField(0, 16, 2, 12, "#bdd9b4"); // Fieldwork
tileField(-18, -2, 2, 12, "#d1c4e5"); // Verification
// Neutral circulation tiles.
tileField(-18, -2, 0, 2, "#d8d8cd");
tileField(-2, 0, -12, 12, "#d8d8cd");
tileField(0, 16, 0, 2, "#d8d8cd");
box(scene, [39, 6.2, 0.55], [0, 3.1, -14.2], M.wall);
box(scene, [0.55, 6.2, 28.4], [-19.5, 3.1, 0], M.wall);
box(scene, [39.4, 0.35, 0.7], [0, 0.18, -14.2], M.wallEdge);
box(scene, [0.7, 0.35, 28.5], [-19.5, 0.18, 0], M.wallEdge);
box(scene, [39.4, 0.35, 0.7], [0, 6.18, -14.2], M.wallEdge);
box(scene, [0.7, 0.35, 28.5], [-19.5, 6.18, 0], M.wallEdge);
// Back-wall windows.
for (const x of [-14, -7, 0, 7, 14]) {
box(scene, [4.2, 2.5, 0.15], [x, 4.25, -13.86], M.glass, false);
box(scene, [0.18, 2.7, 0.24], [x - 2.05, 4.25, -13.72], M.wallEdge);
box(scene, [0.18, 2.7, 0.24], [x + 2.05, 4.25, -13.72], M.wallEdge);
box(scene, [4.25, 0.18, 0.24], [x, 5.55, -13.72], M.wallEdge);
box(scene, [4.25, 0.18, 0.24], [x, 2.95, -13.72], M.wallEdge);
box(scene, [0.14, 2.55, 0.20], [x, 4.25, -13.70], M.wallEdge);
}
// Low partitions preserve the cutaway view.
box(scene, [0.25, 1.15, 10.8], [-1.5, 0.64, -6.8], M.wallEdge);
box(scene, [0.25, 1.15, 9.8], [-1.5, 0.64, 7.0], M.wallEdge);
// Raised oversight dais.
box(scene, [7.2, 0.38, 5.2], [0, 0.22, 0], material("#53656e"));
box(scene, [6.7, 0.12, 4.7], [0, 0.46, 0], material("#708087"));
// -------------------------------------------------------------------------
// Furniture and voxel people
// -------------------------------------------------------------------------
function makeDesk(x, z, accent, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
group.rotation.y = rotation;
scene.add(group);
box(group, [5.2, 0.34, 2.25], [0, 1.65, 0], M.paper);
box(group, [4.5, 0.95, 0.16], [0, 1.0, 0.92], accent);
for (const lx of [-2.1, 2.1]) {
box(group, [0.35, 1.5, 1.75], [lx, 0.83, 0], M.steel);
}
box(group, [1.8, 1.15, 0.18], [0, 2.75, -0.42], M.dark);
box(group, [1.55, 0.88, 0.08], [0, 2.78, -0.29], M.screen);
box(group, [1.2, 0.08, 0.16], [0, 1.95, 0.36], M.dark);
box(group, [0.34, 0.08, 0.10], [-0.9, 2.91, -0.22], M.cyan);
box(group, [0.68, 0.06, 0.10], [-0.73, 2.72, -0.22], M.dark);
box(group, [0.95, 0.05, 0.10], [-0.59, 2.52, -0.22], M.dark);
// Chair.
box(group, [1.25, 0.22, 1.1], [0, 0.95, -1.8], M.dark);
box(group, [1.25, 1.25, 0.18], [0, 1.55, -2.27], M.dark);
box(group, [0.18, 0.9, 0.18], [0, 0.48, -1.8], M.steel);
return group;
}
function makePerson(x, z, shirtColor, skinColor = "#d99b72", prop = false) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
scene.add(group);
const shirt = material(shirtColor);
const skin = material(skinColor);
const trousers = material("#35474e");
const hair = material("#3b302c");
box(group, [0.34, 0.78, 0.38], [-0.25, 0.46, 0], trousers);
box(group, [0.34, 0.78, 0.38], [0.25, 0.46, 0], trousers);
box(group, [0.95, 1.05, 0.56], [0, 1.35, 0], shirt);
box(group, [0.64, 0.64, 0.62], [0, 2.15, 0], skin);
box(group, [0.68, 0.22, 0.66], [0, 2.48, -0.01], hair);
box(group, [0.28, 0.95, 0.34], [-0.64, 1.32, 0], shirt);
box(group, [0.28, 0.95, 0.34], [0.64, 1.32, 0], shirt);
box(group, [0.25, 0.24, 0.28], [-0.64, 0.80, 0], skin);
box(group, [0.25, 0.24, 0.28], [0.64, 0.80, 0], skin);
if (prop) {
box(group, [0.8, 0.10, 0.62], [0.65, 1.23, 0.45], M.paper);
box(group, [0.10, 0.58, 0.10], [0.40, 1.28, 0.45], M.dark);
}
return group;
}
function makeShelf(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
group.rotation.y = rotation;
scene.add(group);
box(group, [4.2, 4.2, 0.45], [0, 2.1, 0], M.dark);
box(group, [4.5, 0.25, 1.15], [0, 0.25, 0.42], M.steel);
box(group, [4.5, 0.25, 1.15], [0, 4.15, 0.42], M.steel);
const colors = ["#d9a861", "#86b6ca", "#9cc49b", "#c29cc2"];
for (let row = 0; row < 3; row++) {
box(group, [4.05, 0.18, 1.08], [0, 0.9 + row * 1.25, 0.38], M.steel);
for (let i = 0; i < 6; i++) {
box(
group,
[0.42, 0.68, 0.70],
[-1.65 + i * 0.66, 1.35 + row * 1.25, 0.40],
material(colors[(i + row) % colors.length])
);
}
}
}
function makeBench(x, z, broken = false, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
group.rotation.y = rotation;
scene.add(group);
const wood = broken ? material("#a66a38") : M.woodLight;
for (const lx of [-1.65, 1.65]) {
box(group, [0.38, 1.35, 1.0], [lx, 0.72, 0], M.steel);
box(group, [0.55, 0.18, 1.6], [lx, 0.16, 0], M.dark);
}
if (broken) {
box(group, [1.65, 0.28, 0.48], [-1.33, 1.42, 0.64], wood);
box(group, [1.65, 0.28, 0.48], [1.33, 1.42, 0.64], wood);
box(group, [1.65, 0.28, 0.48], [0, 1.42, -0.02], wood);
box(group, [0.55, 0.22, 0.42], [0.03, 1.48, 0.64], M.red);
box(group, [0.18, 0.55, 0.18], [0, 2.00, 0.64], M.red);
} else {
for (let i = 0; i < 3; i++) {
box(group, [4.35, 0.28, 0.48], [0, 1.42, -0.64 + i * 0.64], wood);
}
box(group, [0.65, 0.18, 0.65], [0, 1.64, 0], M.green);
}
for (const lx of [-1.65, 1.65]) {
box(group, [0.25, 2.1, 0.25], [lx, 1.05, -0.75], M.steel);
}
box(group, [4.35, 0.28, 0.30], [0, 2.25, -0.77], wood);
box(group, [4.35, 0.28, 0.30], [0, 1.88, -0.77], wood);
return group;
}
function makeCone(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
scene.add(group);
box(group, [0.85, 0.16, 0.85], [0, 0.08, 0], M.orange);
box(group, [0.48, 0.65, 0.48], [0, 0.48, 0], M.orange);
box(group, [0.39, 0.18, 0.39], [0, 0.60, 0], M.paper);
box(group, [0.25, 0.32, 0.25], [0, 0.96, 0], M.orange);
}
function makeCrate(x, z, color = "#9b794e") {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
scene.add(group);
const crateMat = material(color);
box(group, [2.2, 0.25, 1.7], [0, 0.14, 0], crateMat);
box(group, [2.2, 1.45, 0.18], [0, 0.9, 0.78], crateMat);
box(group, [2.2, 1.45, 0.18], [0, 0.9, -0.78], crateMat);
box(group, [0.18, 1.45, 1.7], [1.0, 0.9, 0], crateMat);
box(group, [0.18, 1.45, 1.7], [-1.0, 0.9, 0], crateMat);
}
// Reporting.
makeDesk(-7, -6.4, material("#d79a4f"));
makeShelf(-17.4, -2.7, Math.PI / 2);
makePerson(-7, -8.7, "#e99542", "#bb7959", true);
makePerson(-12.3, -6.4, "#5f8294", "#e0a57c");
// Intake kiosk with a miniature broken-bench pictogram.
const kiosk = new THREE.Group();
kiosk.position.set(-13.1, 0.06, -5.2);
scene.add(kiosk);
box(kiosk, [0.35, 1.35, 0.35], [0, 0.68, 0], M.steel);
box(kiosk, [3.0, 2.35, 0.32], [0, 2.0, 0], M.dark);
box(kiosk, [2.65, 1.95, 0.12], [0, 2.0, 0.22], material("#e9c684"));
box(kiosk, [1.75, 0.25, 0.16], [0, 1.75, 0.34], M.orange);
box(kiosk, [0.22, 0.80, 0.16], [-0.65, 1.38, 0.34], M.wood);
box(kiosk, [0.22, 0.80, 0.16], [0.65, 1.38, 0.34], M.wood);
box(kiosk, [0.30, 0.18, 0.16], [0.15, 1.90, 0.35], M.red);
// Scheduling.
makeDesk(8, -6.4, material("#659eb9"));
makePerson(8, -8.7, "#548eb4", "#d9a27b", true);
const planner = new THREE.Group();
planner.position.set(8, 4.05, -13.48);
scene.add(planner);
box(planner, [9.2, 3.35, 0.25], [0, 0, 0], M.dark);
box(planner, [8.5, 0.08, 0.12], [0, 1.23, 0.17], M.steel);
box(planner, [8.5, 0.08, 0.12], [0, 0.35, 0.17], M.steel);
box(planner, [8.5, 0.08, 0.12], [0, -0.55, 0.17], M.steel);
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 7; col++) {
const color = col === 2 + row ? M.orange : material("#6b8892");
box(
planner,
[0.82, 0.50, 0.12],
[-3.45 + col * 1.15, 0.84 - row * 0.90, 0.22],
color
);
}
}
// Fieldwork.
makeBench(11.7, 10.4, true, -0.08);
makePerson(9.4, 7.6, "#58a979", "#b97858", true);
const workbench = new THREE.Group();
workbench.position.set(5.7, 0.06, 10.4);
scene.add(workbench);
box(workbench, [5.2, 0.38, 2.0], [0, 1.65, 0], M.wood);
for (const x of [-2.1, 2.1]) {
box(workbench, [0.32, 1.5, 1.6], [x, 0.82, 0], M.steel);
}
box(workbench, [1.7, 0.24, 0.48], [-0.9, 1.95, 0], M.green);
box(workbench, [0.30, 0.28, 0.48], [0.5, 1.96, 0], M.red);
box(workbench, [0.16, 0.75, 0.16], [1.3, 2.05, 0], M.steel);
makeCone(14.2, 4.2);
makeCone(12.7, 4.8);
makeCrate(14.4, 8.8);
makeCrate(13.9, 11.1, "#6f9298");
const toolBoard = new THREE.Group();
toolBoard.position.set(13.7, 2.75, 3.0);
scene.add(toolBoard);
box(toolBoard, [5.4, 3.25, 0.25], [0, 0, 0], M.dark);
for (let i = 0; i < 5; i++) {
box(toolBoard, [0.16, 1.25, 0.14], [-1.8 + i * 0.9, 0.1, 0.2], M.steel);
box(toolBoard, [0.55, 0.30, 0.18], [-1.8 + i * 0.9, 0.78, 0.2], M.orange);
}
// Verification.
makeDesk(-7, 7.6, material("#9c80bb"));
makePerson(-7, 5.4, "#936db4", "#e0a57d", true);
makeBench(-14.4, 9.7, false, 0.08);
const scanner = new THREE.Group();
scanner.position.set(-11.3, 0.06, 7.2);
scene.add(scanner);
box(scanner, [0.34, 3.6, 0.34], [-1.7, 1.8, 0], M.steel);
box(scanner, [0.34, 3.6, 0.34], [1.7, 1.8, 0], M.steel);
box(scanner, [3.75, 0.34, 0.34], [0, 3.58, 0], M.steel);
const scanBeam = box(scanner, [3.05, 0.10, 0.10], [0, 1.4, 0], M.green, false);
scanBeam.material.transparent = true;
scanBeam.material.opacity = 0.8;
// Oversight.
makeDesk(0, -0.8, material("#a78a43"));
makePerson(0, -2.8, "#c8a13d", "#c98763", true);
const approvalBoard = new THREE.Group();
approvalBoard.position.set(0, 3.6, -3.25);
scene.add(approvalBoard);
box(approvalBoard, [6.3, 2.7, 0.25], [0, 0, 0], M.dark);
const boardColors = ["#ff9f43", "#4aa8ff", "#61c98c", "#b98cff", "#ffcf5a"];
for (let i = 0; i < 5; i++) {
box(
approvalBoard,
[0.68, 0.68, 0.12],
[-2.25 + i * 1.125, 0.10, 0.18],
material(boardColors[i])
);
box(
approvalBoard,
[0.48, 0.11, 0.10],
[-2.25 + i * 1.125, -0.53, 0.17],
M.steel
);
}
// -------------------------------------------------------------------------
// Area and station labels
// -------------------------------------------------------------------------
addLabel("REPORTING", "citizen intake", [-10, 6.25, -13.25], {
width: 5.3,
accent: "#ff9f43"
});
addLabel("SCHEDULING", "crew coordination", [8, 6.25, -13.25], {
width: 5.3,
accent: "#4aa8ff"
});
addLabel("FIELDWORK", "repair crew bay", [8, 5.4, 1.2], {
width: 5.1,
accent: "#61c98c"
});
addLabel("VERIFICATION", "evidence & check", [-10, 5.4, 1.2], {
width: 5.1,
accent: "#b98cff"
});
addLabel("BENCH #042", "reported defect", [-13.1, 3.8, -5.2], {
width: 4.1,
accent: "#ff6565"
});
addLabel("BROKEN SLAT", "field inspection", [11.7, 3.7, 10.4], {
width: 4.4,
accent: "#ff6565"
});
addLabel("REPAIR VERIFIED", "verification bay", [-14.4, 3.7, 9.7], {
width: 4.8,
accent: "#62d394"
});
addLabel("APPROVAL BOARD", "oversight record", [0, 5.55, -3.25], {
width: 5.1,
accent: "#ffcf5a"
});
addLabel("FICTIONAL SCENARIO", "illustrative · not official", [0, 1.55, 14.25], {
width: 8.6,
accent: "#ff9f43"
});
// -------------------------------------------------------------------------
// Request stages and approval path
// -------------------------------------------------------------------------
const stageData = [
{
short: "Reporting",
title: "Broken-bench report received",
role: "Intake clerk",
text: "The clerk records a public report: bench #042 has a broken seat slat and requires a site inspection.",
approval: "Intake accepted",
color: "#ff9f43"
},
{
short: "Scheduling",
title: "Crew visit and work slot approved",
role: "Scheduling coordinator",
text: "A fictional coordinator assigns a repair crew, reserves a visit window, and approves the inspection task.",
approval: "Visit approved",
color: "#4aa8ff"
},
{
short: "Fieldwork",
title: "Defect inspected and repair recorded",
role: "Field crew",
text: "The crew checks the bench, confirms the damaged slat, and records the illustrated repair action and materials.",
approval: "Field work recorded",
color: "#61c98c"
},
{
short: "Verification",
title: "Repair evidence checked",
role: "Verification inspector",
text: "An inspector compares the completed work with the report and marks the illustrative repair evidence as acceptable.",
approval: "Repair approved",
color: "#b98cff"
},
{
short: "Oversight",
title: "Case reviewed and closure approved",
role: "Oversight lead",
text: "The fictional oversight role reviews the approval record and closes the request. No real authority is represented.",
approval: "Closure approved",
color: "#ffcf5a"
}
];
const pathPoints = [
new THREE.Vector3(-10.0, 0, -3.45),
new THREE.Vector3(8.0, 0, -3.45),
new THREE.Vector3(8.0, 0, 5.0),
new THREE.Vector3(-7.0, 0, 4.75),
new THREE.Vector3(0.0, 0, 2.15)
];
stageData.forEach((stage, i) => {
const p = pathPoints[i];
addLabel(
`${i + 1} · ${stage.short.toUpperCase()}`,
stage.role,
[p.x, 3.55 + (i === 4 ? 0.65 : 0), p.z],
{
width: i === 4 ? 5.6 : 5.0,
accent: stage.color
}
);
});
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const routeGroup = new THREE.Group();
flowGroup.add(routeGroup);
function makeFlowArrow(position, angle) {
const group = new THREE.Group();
group.position.copy(position);
group.rotation.y = angle;
routeGroup.add(group);
box(group, [0.20, 0.10, 0.75], [0, 0, 0], M.cyan, false);
box(group, [0.20, 0.10, 0.63], [-0.22, 0, -0.20], M.cyan, false)
.rotation.y = -0.72;
box(group, [0.20, 0.10, 0.63], [0.22, 0, -0.20], M.cyan, false)
.rotation.y = 0.72;
}
for (let i = 0; i < pathPoints.length - 1; i++) {
const a = pathPoints[i];
const b = pathPoints[i + 1];
const delta = new THREE.Vector3().subVectors(b, a);
const length = delta.length();
const direction = delta.clone().normalize();
const count = Math.max(2, Math.floor(length / 0.58));
for (let j = 0; j < count; j++) {
const p = a.clone().lerp(b, (j + 0.5) / count);
p.y = 0.19;
box(routeGroup, [0.22, 0.10, 0.22], [p.x, p.y, p.z], M.cyan, false);
}
const angle = Math.atan2(direction.x, direction.z);
for (const t of [0.32, 0.72]) {
const p = a.clone().lerp(b, t);
p.y = 0.23;
makeFlowArrow(p, angle);
}
}
// Stage halos and numbered gates.
const stageMarkers = [];
pathPoints.forEach((p, i) => {
const group = new THREE.Group();
flowGroup.add(group);
const ringMaterial = material(stageData[i].color, {
emissive: stageData[i].color,
emissiveIntensity: 0.75,
transparent: true,
opacity: 0.9
});
for (let j = 0; j < 16; j++) {
const angle = j / 16 * Math.PI * 2;
box(
group,
[0.27, 0.13, 0.27],
[
p.x + Math.cos(angle) * 1.28,
0.22,
p.z + Math.sin(angle) * 1.28
],
ringMaterial,
false
);
}
const number = addNumberSprite(i + 1, stageData[i].color, group, [p.x, 1.12, p.z]);
stageMarkers.push({ group, material: ringMaterial, number });
});
// Moving request ticket.
const requestGroup = new THREE.Group();
scene.add(requestGroup);
const requestPayload = new THREE.Group();
requestGroup.add(requestPayload);
box(requestPayload, [0.72, 0.72, 0.72], [0, 0.55, 0], M.orange);
box(requestPayload, [0.48, 0.12, 0.48], [0, 0.96, 0], M.paper);
box(requestPayload, [0.30, 0.08, 0.30], [0, 1.05, 0], M.dark);
const requestBeam = box(
requestPayload,
[0.08, 1.45, 0.08],
[0, 1.55, 0],
material("#ffb15f", {
emissive: "#ff861d",
emissiveIntensity: 1,
transparent: true,
opacity: 0.38
}),
false
);
const requestLabel = createLabelSprite("BRK-BCH-042", "broken bench", {
width: 3.5,
accent: "#ff9f43"
});
requestLabel.position.set(0, 2.30, 0);
requestPayload.add(requestLabel);
// -------------------------------------------------------------------------
// Interface and stage state
// -------------------------------------------------------------------------
const stageList = document.querySelector("#stageList");
const stageButtons = [];
stageData.forEach((stage, i) => {
const button = document.createElement("button");
button.className = "stage-button";
button.innerHTML = `
<span class="stage-number" style="background:${stage.color}">${i + 1}</span>
<span>
<span class="stage-name">${stage.short}</span>
<span class="stage-role">${stage.role}</span>
</span>
`;
button.addEventListener("click", () => {
traceTime = i * SEGMENT_TIME;
playing = false;
setActiveStage(i);
updatePauseButton();
focusStage(i);
});
stageList.appendChild(button);
stageButtons.push(button);
});
const stageKicker = document.querySelector("#stageKicker");
const stageTitle = document.querySelector("#stageTitle");
const stageText = document.querySelector("#stageText");
const approvalTag = document.querySelector("#approvalTag");
const pauseBtn = document.querySelector("#pauseBtn");
const flowBtn = document.querySelector("#flowBtn");
const labelsBtn = document.querySelector("#labelsBtn");
const SEGMENT_TIME = 2.65;
const TRACE_LOOP = SEGMENT_TIME * 4 + 3.2;
let traceTime = 0;
let playing = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let activeStage = -1;
let labelsVisible = true;
let flowVisible = true;
function updatePauseButton() {
pauseBtn.textContent = playing ? "Pause trace" : "Resume trace";
}
function setActiveStage(index) {
if (index === activeStage) return;
activeStage = index;
stageMarkers.forEach((marker, i) => {
const active = i === index;
marker.material.opacity = active ? 0.96 : 0.24;
marker.material.emissiveIntensity = active ? 0.95 : 0.08;
marker.group.scale.setScalar(active ? 1 : 0.91);
marker.number.material.opacity = active ? 1 : 0.48;
});
stageButtons.forEach((button, i) => {
button.classList.toggle("active", i === index);
button.setAttribute("aria-current", i === index ? "step" : "false");
});
const stage = stageData[index];
stageKicker.textContent = `Step ${String(index + 1).padStart(2, "0")} · ${stage.role}`;
stageTitle.textContent = stage.title;
stageText.textContent = stage.text;
approvalTag.textContent = stage.approval;
approvalTag.style.color = stage.color;
approvalTag.style.background = `${stage.color}22`;
}
pauseBtn.addEventListener("click", () => {
playing = !playing;
updatePauseButton();
});
flowBtn.addEventListener("click", () => {
flowVisible = !flowVisible;
flowGroup.visible = flowVisible;
requestGroup.visible = flowVisible;
flowBtn.textContent = flowVisible ? "Hide flow" : "Show flow";
});
labelsBtn.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsGroup.visible = labelsVisible;
requestLabel.visible = labelsVisible;
labelsBtn.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
document.querySelector("#resetBtn").addEventListener("click", resetView);
function setZoom(value) {
view.zoom = THREE.MathUtils.clamp(value, 0.65, 2.35);
}
document.querySelector("#zoomInBtn").addEventListener("click", () => setZoom(view.zoom * 1.15));
document.querySelector("#zoomOutBtn").addEventListener("click", () => setZoom(view.zoom / 1.15));
function resetView() {
view.azimuth = 0.78;
view.polar = 0.88;
view.zoom = 1;
view.desiredTarget.set(0, 0, 0);
}
function focusStage(index) {
const p = pathPoints[index];
view.desiredTarget.set(p.x, 0, p.z);
setZoom(1.35);
}
updatePauseButton();
setActiveStage(0);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, and zoom
// -------------------------------------------------------------------------
let dragging = false;
let dragMode = "orbit";
let pointerId = null;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0 && event.button !== 2) return;
dragging = true;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragMode === "orbit") {
view.azimuth -= dx * 0.006;
view.polar = THREE.MathUtils.clamp(view.polar + dy * 0.005, 0.42, 1.25);
} else {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const worldPerPixel =
(camera.top - camera.bottom) / camera.zoom / canvas.clientHeight;
view.desiredTarget.addScaledVector(right, -dx * worldPerPixel);
view.desiredTarget.addScaledVector(forward, dy * worldPerPixel);
view.desiredTarget.x = THREE.MathUtils.clamp(view.desiredTarget.x, -14, 14);
view.desiredTarget.z = THREE.MathUtils.clamp(view.desiredTarget.z, -12, 12);
}
});
function endDrag(event) {
if (!dragging || event.pointerId !== pointerId) return;
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();
setZoom(view.zoom * Math.exp(-event.deltaY * 0.001));
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLButtonElement) return;
if (event.key === "+" || event.key === "=") {
setZoom(view.zoom * 1.12);
} else if (event.key === "-") {
setZoom(view.zoom / 1.12);
} else if (event.key === "0") {
resetView();
} else if (event.code === "Space") {
event.preventDefault();
playing = !playing;
updatePauseButton();
}
});
function updateCamera(dt) {
const follow = 1 - Math.exp(-dt * 6);
view.target.lerp(view.desiredTarget, follow);
const spherical = new THREE.Spherical(
52,
view.polar,
view.azimuth
);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(view.target).add(offset);
camera.lookAt(view.target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = Math.max(31, 42 / aspect);
camera.left = -frustumHeight * aspect / 2;
camera.right = frustumHeight * aspect / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const requestPosition = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (playing) {
traceTime += dt;
if (traceTime >= TRACE_LOOP) {
traceTime = 0;
activeStage = -1;
}
}
const currentStage = Math.min(4, Math.floor(traceTime / SEGMENT_TIME));
setActiveStage(currentStage);
if (traceTime < SEGMENT_TIME * 4) {
const segment = Math.min(3, Math.floor(traceTime / SEGMENT_TIME));
const local = (traceTime - segment * SEGMENT_TIME) / SEGMENT_TIME;
const eased = local * local * (3 - 2 * local);
requestPosition.lerpVectors(
pathPoints[segment],
pathPoints[segment + 1],
eased
);
} else {
requestPosition.copy(pathPoints[4]);
}
requestGroup.position.set(
requestPosition.x,
0.13,
requestPosition.z
);
requestPayload.position.y = 0.08 + Math.sin(elapsed * 5.2) * 0.10;
requestPayload.rotation.y = elapsed * 0.7;
requestBeam.material.opacity = 0.26 + Math.sin(elapsed * 4.0) * 0.08;
scanBeam.position.y = 0.75 + (Math.sin(elapsed * 2.2) * 0.5 + 0.5) * 2.0;
stageMarkers.forEach((marker, i) => {
if (i === activeStage) {
const pulse = 1 + Math.sin(elapsed * 4.0) * 0.055;
marker.group.scale.setScalar(pulse);
}
});
updateCamera(dt);
renderer.render(scene, camera);
}
animate();
document.querySelector("#loading").style.display = "none";
</script>
</body>
</html>
```