Prompt specification
Build or customize the Three.js 3D scene "Testing a Bus Shelter With Different Users" 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: Testing a Bus Shelter With Different Users
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/testing-a-bus-shelter-with-different-users-x3242
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing participatory design informed by different users. Build a shelter prototype with seats, route information, and a ramped approach. Move several mobility proxies through it and record observable blocked paths. Stylized solid forms.
Working Three.js Starter (testing-a-bus-shelter-with-different-users-x3242):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Access Lab — Participatory Shelter Prototype</title>
<style>
:root {
--ink: #18302e;
--muted: #60716e;
--paper: rgba(250, 248, 241, 0.93);
--line: rgba(24, 48, 46, 0.14);
--teal: #167b75;
--orange: #e76f51;
--yellow: #e9b949;
--shadow: 0 18px 50px rgba(35, 54, 51, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5da;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#topbar {
position: absolute;
z-index: 5;
top: 20px;
left: 22px;
right: 22px;
min-height: 74px;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 22px;
padding: 13px 18px 13px 20px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 270px;
}
.brand-mark {
width: 43px;
height: 43px;
display: grid;
place-items: center;
flex: 0 0 auto;
border-radius: 13px;
color: white;
background: var(--ink);
font-size: 23px;
font-weight: 800;
}
.eyebrow {
margin: 0 0 3px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(16px, 1.8vw, 23px);
line-height: 1.05;
letter-spacing: -0.035em;
}
#metrics {
display: flex;
align-items: stretch;
gap: 8px;
pointer-events: auto;
}
.metric {
min-width: 88px;
padding: 8px 12px;
border-left: 1px solid var(--line);
}
.metric-value {
display: block;
font-size: 20px;
font-weight: 800;
letter-spacing: -0.04em;
}
.metric-label {
display: block;
margin-top: 1px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.panel {
position: absolute;
z-index: 4;
top: 112px;
width: 310px;
max-height: calc(100vh - 212px);
overflow: auto;
border-radius: 18px;
padding: 18px;
scrollbar-width: thin;
}
#brief {
left: 22px;
}
#log-panel {
right: 22px;
width: 350px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.panel-heading h2 {
margin: 0;
font-size: 14px;
letter-spacing: -0.015em;
}
.round-tag {
padding: 5px 8px;
border-radius: 999px;
background: #e4efeb;
color: var(--teal);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
}
.intro {
margin: 0 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.requirement {
display: grid;
grid-template-columns: 30px 1fr;
gap: 10px;
align-items: start;
padding: 10px 0;
border-top: 1px solid var(--line);
}
.avatar {
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 10px;
color: white;
font-size: 12px;
font-weight: 800;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}
.requirement strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.requirement span {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.derived {
margin-top: 14px;
padding: 12px;
border-radius: 13px;
background: rgba(22, 123, 117, 0.08);
color: #315b57;
font-size: 11px;
line-height: 1.5;
}
.derived b {
color: var(--teal);
}
.event {
position: relative;
display: grid;
grid-template-columns: 9px 1fr;
gap: 10px;
padding: 10px 0 12px;
border-top: 1px solid var(--line);
}
.event:first-of-type {
border-top: 0;
}
.event-dot {
width: 9px;
height: 9px;
margin-top: 4px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 123, 117, 0.1);
}
.event.blocked .event-dot {
background: var(--orange);
box-shadow: 0 0 0 4px rgba(231, 111, 81, 0.12);
}
.event.clear .event-dot {
background: #3c9a73;
box-shadow: 0 0 0 4px rgba(60, 154, 115, 0.12);
}
.event-title {
margin-bottom: 4px;
font-size: 11px;
font-weight: 800;
line-height: 1.35;
}
.event-detail {
color: var(--muted);
font-size: 10px;
line-height: 1.48;
}
.event-time {
margin-top: 5px;
color: #8a9693;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#bottom-bar {
position: absolute;
z-index: 6;
left: 50%;
bottom: 19px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 12px;
max-width: calc(100vw - 44px);
padding: 10px 12px 10px 15px;
border-radius: 17px;
}
.control-copy {
min-width: 180px;
}
.control-copy strong {
display: block;
font-size: 11px;
}
.control-copy span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
button {
appearance: none;
border: 0;
border-radius: 11px;
padding: 10px 13px;
color: white;
background: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
transition: transform 0.15s ease, opacity 0.15s ease;
}
button:hover {
transform: translateY(-1px);
}
button.secondary {
color: var(--ink);
background: #e8ebe5;
}
.toggle {
display: flex;
align-items: center;
gap: 9px;
padding-left: 12px;
border-left: 1px solid var(--line);
cursor: pointer;
user-select: none;
}
.toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle-track {
position: relative;
width: 38px;
height: 22px;
flex: 0 0 auto;
border-radius: 999px;
background: #bdc6c2;
transition: background 0.2s ease;
}
.toggle-track::after {
content: "";
position: absolute;
width: 16px;
height: 16px;
top: 3px;
left: 3px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-track {
background: var(--teal);
}
.toggle input:checked + .toggle-track::after {
transform: translateX(16px);
}
.toggle-text {
font-size: 10px;
font-weight: 800;
line-height: 1.25;
}
.toggle-text small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
#legend {
position: absolute;
z-index: 3;
left: 22px;
bottom: 22px;
display: flex;
gap: 12px;
padding: 9px 12px;
border-radius: 12px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 18px;
height: 3px;
border-radius: 3px;
background: var(--teal);
}
.legend-swatch.blocked {
background: var(--orange);
}
.legend-swatch.planned {
height: 0;
border-top: 2px dashed #83938f;
background: transparent;
}
@media (max-width: 1050px) {
#brief {
width: 275px;
}
#log-panel {
width: 310px;
}
#metrics .metric:nth-child(1) {
display: none;
}
}
@media (max-width: 820px) {
#topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
min-width: 0;
}
.brand-mark {
width: 36px;
height: 36px;
}
#metrics {
gap: 2px;
}
.metric {
min-width: 60px;
padding: 5px 8px;
}
.metric-value {
font-size: 16px;
}
.metric-label {
font-size: 8px;
}
.panel {
top: auto;
bottom: 82px;
max-height: 33vh;
width: calc(50vw - 15px);
padding: 13px;
}
#brief {
left: 10px;
}
#log-panel {
right: 10px;
}
#bottom-bar {
bottom: 10px;
left: 10px;
right: 10px;
transform: none;
max-width: none;
justify-content: center;
}
.control-copy,
#legend {
display: none;
}
.toggle {
padding-left: 8px;
}
}
@media (max-width: 560px) {
#brief {
display: none;
}
#log-panel {
width: calc(100vw - 20px);
max-height: 26vh;
}
.brand .eyebrow {
display: none;
}
h1 {
font-size: 14px;
}
#metrics .metric:nth-child(3) {
display: none;
}
#bottom-bar {
flex-wrap: wrap;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header id="topbar" class="glass">
<div class="brand">
<div class="brand-mark" aria-hidden="true">A</div>
<div>
<p class="eyebrow">Access Lab / Public Realm</p>
<h1>Neighborhood Shelter 07</h1>
</div>
</div>
<div id="metrics" aria-live="polite">
<div class="metric">
<span id="metric-round" class="metric-value">01</span>
<span class="metric-label">Design round</span>
</div>
<div class="metric">
<span id="metric-moved" class="metric-value">0/4</span>
<span class="metric-label">In motion</span>
</div>
<div class="metric">
<span id="metric-blocked" class="metric-value">0</span>
<span class="metric-label">Blocked</span>
</div>
<div class="metric">
<span id="metric-clear" class="metric-value">0</span>
<span class="metric-label">Clear</span>
</div>
</div>
</header>
<aside id="brief" class="panel glass">
<div class="panel-heading">
<h2>Participatory design brief</h2>
<span id="round-tag" class="round-tag">Round 01 · As built</span>
</div>
<p class="intro">
Four mobility proxies replay routes derived from user research. Observable
conflicts are recorded where a planned path intersects the prototype.
</p>
<div class="requirement">
<div class="avatar" style="background:#3568b9">A</div>
<div>
<strong>Manual wheelchair</strong>
<span>“I need enough space to turn without backing into the cabinet.”</span>
</div>
</div>
<div class="requirement">
<div class="avatar" style="background:#b56a3f">M</div>
<div>
<strong>Walking frame</strong>
<span>“Keep the full ramp width clear; side planters are awkward.”</span>
</div>
</div>
<div class="requirement">
<div class="avatar" style="background:#8b5aa8">J</div>
<div>
<strong>White cane</strong>
<span>“A continuous route needs contrast and objects out of the line.”</span>
</div>
</div>
<div class="requirement">
<div class="avatar" style="background:#397e64">S</div>
<div>
<strong>Pushchair</strong>
<span>“We need a wide landing and room to pass another person.”</span>
</div>
</div>
<div class="derived">
<b>Shared requirements:</b> continuous 2.4 m ramp, visible route
information, 1.5 m turning space, unobstructed seating approaches,
and a lateral transfer option beside the priority bench.
</div>
</aside>
<aside id="log-panel" class="panel glass">
<div class="panel-heading">
<h2>Observable path log</h2>
<span id="session-time" class="round-tag">00:00</span>
</div>
<div id="event-log" aria-live="polite"></div>
</aside>
<div id="legend" class="glass">
<div class="legend-item"><span class="legend-swatch planned"></span>Planned route</div>
<div class="legend-item"><span class="legend-swatch"></span>Traveled route</div>
<div class="legend-item"><span class="legend-swatch blocked"></span>Blocked segment</div>
</div>
<div id="bottom-bar" class="glass">
<div class="control-copy">
<strong>Route study</strong>
<span>Drag to orbit · Shift/right-drag to pan · Scroll to zoom</span>
</div>
<button id="play-button" type="button">Pause</button>
<button id="reset-button" class="secondary" type="button">Replay</button>
<label class="toggle" title="Apply the co-design revisions and replay the study">
<input id="fix-toggle" type="checkbox" />
<span class="toggle-track"></span>
<span class="toggle-text">
Co-design revisions
<small>Clear ramp + relocate cabinet</small>
</span>
</label>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional accessible shelter prototype"
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5da);
scene.fog = new THREE.Fog(0xe9e5da, 28, 58);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xfff8e8, 0x80928b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.2);
sun.position.set(-12, 19, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00035;
scene.add(sun);
const colors = {
ink: 0x18302e,
teal: 0x167b75,
tealDark: 0x285d59,
cream: 0xf4efe2,
concrete: 0xc9c3b4,
paving: 0xd8d3c7,
deck: 0xb6a58a,
yellow: 0xe9b949,
orange: 0xe76f51,
green: 0x397e64,
blue: 0x3568b9,
purple: 0x8b5aa8,
brown: 0xb56a3f,
white: 0xfaf8f2,
dark: 0x263331
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
function box(w, h, d, color, x, y, z, parent = scene, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, color, x, y, z, parent = scene, segments = 12) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(radius, color, x, y, z, parent = scene, detail = 1) {
const geometry =
detail === 1
? new THREE.IcosahedronGeometry(radius, 1)
: new THREE.SphereGeometry(radius, 16, 12);
const mesh = new THREE.Mesh(geometry, material(color));
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, color, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 10),
material(color)
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function groundHeightAt(x) {
if (x < -7 || x > 7) return 0;
if (x < -1) return 0.42 * ((x + 7) / 6);
return 0.42;
}
// ------------------------------------------------------------
// Ground, plaza and distant context
// ------------------------------------------------------------
box(30, 0.42, 21, colors.paving, 0, -0.23, 0, scene, {
roughness: 1
});
box(29, 0.08, 20, 0xe2ddd1, 0, -0.015, 0, scene, {
roughness: 1
});
for (let x = -14; x <= 14; x += 2) {
box(0.018, 0.012, 20, 0xc9c4b8, x, 0.035, 0, scene, {
roughness: 1,
castShadow: false
});
}
for (let z = -10; z <= 10; z += 2) {
box(28, 0.012, 0.018, 0xc9c4b8, 0, 0.036, z, scene, {
roughness: 1,
castShadow: false
});
}
// Grass islands at the edge of the plaza.
const grassMaterial = material(0x91a98c, { roughness: 1 });
box(6, 0.18, 3.4, 0x91a98c, -10.5, 0.04, -7.6, scene, { roughness: 1 });
box(5.5, 0.18, 3.2, 0x91a98c, 10.4, 0.04, -7.5, scene, { roughness: 1 });
box(4.6, 0.18, 2.7, 0x91a98c, 11.1, 0.04, 7.4, scene, { roughness: 1 });
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.14, 0.2, 2.5, 0x80664c, 0, 1.25, 0, group, 9);
sphere(1.05, 0x668d70, 0, 2.8, 0, group, 1);
sphere(0.7, 0x7ca27d, 0.62, 2.55, 0.18, group, 1);
}
makeTree(-10.7, -7.5, 1.05);
makeTree(9.8, -7.4, 0.9);
makeTree(11.2, 7.2, 1.1);
for (const x of [-9, 8.8]) {
cylinder(0.11, 0.14, 0.72, colors.ink, x, 0.36, 4.6, scene, 10);
cylinder(0.14, 0.14, 0.08, colors.yellow, x, 0.74, 4.6, scene, 10);
}
// ------------------------------------------------------------
// Shelter platform, ramp, rails, roof and seating
// ------------------------------------------------------------
box(8.2, 0.42, 6.1, colors.deck, 3, 0.21, 0, scene, {
roughness: 0.95
});
box(8.34, 0.14, 6.24, colors.concrete, 3, 0.04, 0, scene, {
roughness: 1
});
const rampLength = Math.hypot(6, 0.42);
const ramp = box(
rampLength,
0.16,
2.4,
0xcac4b6,
-4,
0.13,
0,
scene,
{ roughness: 1 }
);
ramp.rotation.z = Math.atan2(0.42, 6);
// Tactile warning strip at the top of the ramp.
box(0.24, 0.035, 2.32, colors.yellow, -1.08, 0.438, 0, scene, {
roughness: 0.72
});
for (let z = -1.05; z <= 1.06; z += 0.21) {
box(0.16, 0.025, 0.07, 0xf2ca63, -1.08, 0.463, z, scene, {
roughness: 0.7
});
}
// Ramp handrails.
for (const z of [-1.11, 1.11]) {
cylinderBetween(
[-7, 0.86, z],
[-1, 1.28, z],
0.045,
colors.ink
);
for (let i = 0; i <= 6; i++) {
const t = i / 6;
const x = -7 + t * 6;
const y = 0.42 * t;
cylinderBetween(
[x, y + 0.02, z],
[x, y + 0.84, z],
0.037,
colors.ink
);
}
}
// Short guardrails at the ramp landing.
for (const z of [-1.11, 1.11]) {
cylinderBetween([-1, 1.26, z], [-0.55, 1.26, z], 0.045, colors.ink);
cylinderBetween([-0.55, 0.44, z], [-0.55, 1.26, z], 0.037, colors.ink);
}
// Back wall and structural columns.
box(8.25, 2.85, 0.24, 0xe6dfd1, 3, 1.845, -2.72, scene, {
roughness: 0.95
});
box(8.05, 0.16, 0.08, colors.teal, 3, 2.95, -2.57, scene, {
roughness: 0.85
});
for (const x of [-0.05, 6.35]) {
for (const z of [-2.55, 2.55]) {
cylinder(0.13, 0.16, 3.34, colors.ink, x, 2.09, z, scene, 12);
}
}
// Stylized roof slab and fascia.
const roof = box(9.15, 0.34, 6.75, colors.tealDark, 3, 3.9, 0, scene, {
roughness: 0.8
});
roof.rotation.x = -0.025;
box(9.25, 0.18, 0.2, colors.ink, 3, 3.72, 3.32, scene, {
roughness: 0.85
});
// A lighter roof inset makes the solid mass legible from above.
box(7.85, 0.08, 5.65, 0x2f7770, 3, 4.1, 0, scene, {
roughness: 0.9
});
function makeBench(cx, length, revised = false) {
const group = new THREE.Group();
group.position.set(cx, 0.42, -1.65);
scene.add(group);
for (const x of [-length * 0.36, length * 0.36]) {
box(0.13, 0.48, 0.52, colors.ink, x, 0.24, 0, group);
}
box(length, 0.15, 0.62, colors.brown, 0, 0.49, 0, group);
box(length, 0.64, 0.13, 0xc98555, 0, 0.86, -0.29, group);
// Original seats have end arms. The revised priority seat removes
// the near arm to create a lateral transfer opening.
const armXs = revised ? [-length / 2 + 0.08] : [-length / 2 + 0.08, length / 2 - 0.08];
for (const x of armXs) {
cylinder(0.035, 0.035, 0.52, colors.ink, x, 0.73, 0.05, group, 8);
box(0.08, 0.07, 0.5, colors.ink, x, 0.98, 0, group);
}
return group;
}
const originalPriorityBench = makeBench(2.25, 2.55, false);
const revisedPriorityBench = makeBench(2.25, 2.55, true);
const standardBench = makeBench(5.15, 2.65, false);
revisedPriorityBench.visible = false;
// ------------------------------------------------------------
// Canvas-generated sign graphics; no external assets
// ------------------------------------------------------------
function canvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const shelterTitleTexture = canvasTexture(1024, 180, (ctx, w, h) => {
ctx.fillStyle = "#18302e";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#f7f1e5";
ctx.font = "800 64px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("NEIGHBORHOOD SHELTER 07", w / 2, h / 2 - 3);
ctx.fillStyle = "#e9b949";
ctx.fillRect(w / 2 - 95, h - 23, 190, 5);
});
const titlePlane = new THREE.Mesh(
new THREE.PlaneGeometry(4.4, 0.77),
new THREE.MeshBasicMaterial({ map: shelterTitleTexture })
);
titlePlane.position.set(3, 3.72, 3.43);
scene.add(titlePlane);
const routeMapTexture = canvasTexture(768, 512, (ctx, w, h) => {
ctx.fillStyle = "#f6f0e4";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#18302e";
ctx.fillRect(0, 0, w, 91);
ctx.fillStyle = "#ffffff";
ctx.font = "800 39px system-ui, sans-serif";
ctx.fillText("YOU ARE HERE", 31, 58);
ctx.strokeStyle = "#c9c4b7";
ctx.lineWidth = 13;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.beginPath();
ctx.moveTo(98, 365);
ctx.lineTo(250, 365);
ctx.lineTo(335, 278);
ctx.lineTo(335, 159);
ctx.lineTo(575, 159);
ctx.stroke();
ctx.strokeStyle = "#167b75";
ctx.lineWidth = 10;
ctx.beginPath();
ctx.moveTo(98, 365);
ctx.lineTo(250, 365);
ctx.lineTo(335, 278);
ctx.lineTo(335, 159);
ctx.lineTo(575, 159);
ctx.stroke();
const stops = [
[98, 365, "Bus"],
[250, 365, "Market"],
[335, 278, "Ramp"],
[335, 159, "Clinic"],
[575, 159, "Park"]
];
for (const [x, y, label] of stops) {
ctx.fillStyle = "#ffffff";
ctx.strokeStyle = "#167b75";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.arc(x, y, 15, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
ctx.fillStyle = "#28413e";
ctx.font = "700 21px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText(label, x, y + 38);
}
ctx.fillStyle = "#e76f51";
ctx.beginPath();
ctx.arc(654, 365, 18, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#28413e";
ctx.font = "800 20px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("Shelter", 654, 409);
ctx.fillStyle = "#dcebe6";
ctx.fillRect(26, 433, 716, 53);
ctx.fillStyle = "#315b57";
ctx.font = "700 21px system-ui, sans-serif";
ctx.textAlign = "left";
ctx.fillText("Step-free route • Ramp 1:14 • Seating", 48, 467);
});
const routeSign = new THREE.Group();
routeSign.position.set(0.45, 0, 1.72);
scene.add(routeSign);
cylinder(0.075, 0.09, 2.45, colors.ink, 0, 1.645, 0, routeSign, 10);
box(2.75, 1.82, 0.16, colors.ink, 0, 2.36, 0, routeSign);
const routeMapPlane = new THREE.Mesh(
new THREE.PlaneGeometry(2.58, 1.65),
new THREE.MeshBasicMaterial({ map: routeMapTexture })
);
routeMapPlane.position.set(0, 2.36, 0.086);
routeSign.add(routeMapPlane);
const rampSignTexture = canvasTexture(640, 190, (ctx, w, h) => {
ctx.fillStyle = "#167b75";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#ffffff";
ctx.font = "800 49px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("STEP-FREE ROUTE", w / 2, 65);
ctx.font = "700 33px system-ui, sans-serif";
ctx.fillText("RAMP 1:14 • 2.4 m CLEAR", w / 2, 125);
});
const rampSign = new THREE.Group();
rampSign.position.set(-6.8, 0, -1.65);
scene.add(rampSign);
cylinder(0.06, 0.07, 1.45, colors.ink, 0, 0.725, 0, rampSign, 10);
box(1.8, 0.55, 0.12, colors.ink, 0, 1.48, 0, rampSign);
const rampSignPlane = new THREE.Mesh(
new THREE.PlaneGeometry(1.68, 0.46),
new THREE.MeshBasicMaterial({ map: rampSignTexture })
);
rampSignPlane.position.set(0, 1.48, 0.066);
rampSign.add(rampSignPlane);
function makeLabelSprite(text, background = "#18302e", foreground = "#ffffff") {
const texture = canvasTexture(512, 128, (ctx, w, h) => {
ctx.fillStyle = background;
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = foreground;
ctx.font = "800 35px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2);
});
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({ map: texture, depthTest: true })
);
sprite.scale.set(2.4, 0.6, 1);
return sprite;
}
// ------------------------------------------------------------
// Design obstacles and their revision positions
// ------------------------------------------------------------
const obstacleLayer = new THREE.Group();
scene.add(obstacleLayer);
const planter = new THREE.Group();
obstacleLayer.add(planter);
box(0.95, 0.7, 0.68, colors.tealDark, 0, 0.35, 0, planter);
box(0.76, 0.14, 0.51, 0x547e67, 0, 0.74, 0, planter);
sphere(0.51, 0x5f956d, 0, 1.07, 0, planter, 1);
sphere(0.31, 0x79aa78, 0.27, 1.15, 0.05, planter, 1);
const planterLabel = makeLabelSprite("PLANTER • PINCH", "#e76f51");
planterLabel.position.set(0, 1.68, 0);
planter.add(planterLabel);
const cabinet = new THREE.Group();
obstacleLayer.add(cabinet);
box(0.94, 1.18, 0.72, colors.tealDark, 0, 0.59, 0, cabinet);
box(1.02, 0.1, 0.8, colors.ink, 0, 1.22, 0, cabinet);
box(0.68, 0.4, 0.025, 0x8bc5bb, 0, 0.7, 0.371, cabinet);
box(0.06, 0.24, 0.035, colors.yellow, 0.32, 0.7, 0.39, cabinet);
const cabinetLabel = makeLabelSprite("CABINET • TURN", "#e76f51");
cabinetLabel.position.set(0, 1.78, 0);
cabinet.add(cabinetLabel);
const blockers = [
{
name: "ramp planter",
center: new THREE.Vector2(-4.2, 0.28),
half: new THREE.Vector2(0.48, 0.34),
eventTitle: "Ramp planter intersects walking route",
eventDetail:
"The planter projects into the 2.40 m ramp. The walking-frame and cane proxy envelopes overlap its 0.68 m footprint.",
location: "Ramp approach · x −4.2 m"
},
{
name: "charging cabinet",
center: new THREE.Vector2(2.0, -0.55),
half: new THREE.Vector2(0.49, 0.36),
eventTitle: "Cabinet creates an entrance pinch point",
eventDetail:
"The cabinet interrupts the direct deck approach. Wheelchair and stroller turning envelopes overlap the narrowed lane.",
location: "Shelter deck · x 2.0 m"
}
];
// ------------------------------------------------------------
// Mobility proxy models
// ------------------------------------------------------------
function addPerson(group, shirtColor, scale = 1) {
const person = new THREE.Group();
person.scale.setScalar(scale);
group.add(person);
box(0.42, 0.54, 0.28, shirtColor, 0, 0.98, 0, person);
sphere(0.2, 0xd5a17c, 0, 1.42, 0, person, 1);
cylinder(0.075, 0.09, 0.55, colors.ink, -0.12, 0.42, 0, person, 8);
cylinder(0.075, 0.09, 0.55, colors.ink, 0.12, 0.42, 0, person, 8);
return person;
}
function makeWheelchair(color) {
const group = new THREE.Group();
const wheelGeometry = new THREE.TorusGeometry(0.38, 0.065, 9, 18);
for (const x of [-0.39, 0.39]) {
const wheel = new THREE.Mesh(wheelGeometry, material(colors.dark));
wheel.position.set(x, 0.39, -0.13);
wheel.rotation.y = Math.PI / 2;
wheel.castShadow = true;
group.add(wheel);
}
for (const z of [-0.26, 0.28]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.09, 12),
material(colors.dark)
);
wheel.position.set(0, 0.14, z);
wheel.rotation.z = Math.PI / 2;
group.add(wheel);
}
box(0.63, 0.12, 0.58, color, 0, 0.55, 0.02, group);
box(0.63, 0.62, 0.1, color, 0, 0.86, -0.28, group);
cylinderBetween([-0.28, 0.65, -0.28], [-0.28, 1.08, -0.36], 0.025, colors.ink, group);
cylinderBetween([0.28, 0.65, -0.28], [0.28, 1.08, -0.36], 0.025, colors.ink, group);
cylinderBetween([-0.28, 1.08, -0.36], [0.28, 1.08, -0.36], 0.025, colors.ink, group);
addPerson(group, color, 0.88);
return group;
}
function makeWalker(color) {
const group = new THREE.Group();
for (const x of [-0.29, 0.29]) {
for (const z of [-0.22, 0.24]) {
cylinderBetween([x, 0.08, z], [x, 0.88, z], 0.035, colors.ink, group);
}
}
box(0.62, 0.09, 0.5, color, 0, 0.67, 0, group);
cylinderBetween([-0.29, 0.88, -0.2], [0.29, 0.88, -0.2], 0.04, color, group);
cylinderBetween([-0.29, 0.88, 0.2], [0.29, 0.88, 0.2], 0.04, color, group);
cylinderBetween([-0.29, 0.88, -0.2], [-0.29, 0.88, 0.2], 0.035, color, group);
cylinderBetween([0.29, 0.88, -0.2], [0.29, 0.88, 0.2], 0.035, color, group);
addPerson(group, color, 0.9);
return group;
}
function makeCaneUser(color) {
const group = new THREE.Group();
addPerson(group, color, 0.92);
cylinderBetween([0.38, 0.05, 0.22], [0.38, 1.0, 0.22], 0.022, colors.ink, group);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.075, 0.018, 8, 12, Math.PI),
material(colors.ink)
);
handle.position.set(0.38, 1.0, 0.22);
handle.rotation.z = Math.PI / 2;
group.add(handle);
return group;
}
function makeStroller(color) {
const group = new THREE.Group();
box(0.67, 0.36, 0.8, color, 0, 0.57, -0.05, group);
box(0.72, 0.52, 0.16, color, 0, 0.88, -0.4, group);
box(0.58, 0.08, 0.66, colors.ink, 0, 0.77, -0.02, group);
for (const x of [-0.35, 0.35]) {
for (const z of [-0.34, 0.31]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.09, 12),
material(colors.dark)
);
wheel.position.set(x, 0.14, z);
wheel.rotation.z = Math.PI / 2;
wheel.castShadow = true;
group.add(wheel);
}
}
cylinderBetween([-0.27, 0.55, 0.37], [-0.27, 1.06, 0.48], 0.025, colors.ink, group);
cylinderBetween([0.27, 0.55, 0.37], [0.27, 1.06, 0.48], 0.025, colors.ink, group);
cylinderBetween([-0.27, 1.06, 0.48], [0.27, 1.06, 0.48], 0.03, colors.ink, group);
addPerson(group, color, 0.72);
return group;
}
// ------------------------------------------------------------
// Route geometry and proxy state
// ------------------------------------------------------------
function buildRoute(points, sampleCount = 240) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const dx = points[i + 1].x - points[i].x;
const dz = points[i + 1].z - points[i].z;
const length = Math.hypot(dx, dz);
lengths.push(length);
total += length;
}
const cumulative = [0];
for (const length of lengths) {
cumulative.push(cumulative[cumulative.length - 1] + length);
}
const samples = [];
for (let i = 0; i <= sampleCount; i++) {
samples.push(pointAtDistance({ points, lengths, cumulative, total }, (total * i) / sampleCount));
}
return { points, lengths, cumulative, total, samples, sampleCount };
}
function pointAtDistance(route, distance) {
const d = THREE.MathUtils.clamp(distance, 0, route.total);
for (let i = 0; i < route.lengths.length; i++) {
if (d <= route.cumulative[i + 1] || i === route.lengths.length - 1) {
const local = d - route.cumulative[i];
const t = route.lengths[i] === 0 ? 0 : local / route.lengths[i];
const a = route.points[i];
const b = route.points[i + 1];
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
return {
x,
z,
y: groundHeightAt(x),
heading: Math.atan2(b.x - a.x, b.z - a.z)
};
}
}
}
const agentDefinitions = [
{
id: "ari",
name: "Ari",
detail: "Manual wheelchair",
color: colors.blue,
radius: 0.42,
speed: 1.34,
model: makeWheelchair,
points: [
{ x: -8.8, z: -0.62 },
{ x: -6.7, z: -0.62 },
{ x: -1.0, z: -0.62 },
{ x: 0.2, z: -0.62 },
{ x: 1.0, z: -0.62 },
{ x: 2.5, z: -0.7 },
{ x: 2.8, z: -0.72 }
]
},
{
id: "mei",
name: "Mei",
detail: "Walking frame",
color: colors.brown,
radius: 0.32,
speed: 1.12,
model: makeWalker,
points: [
{ x: -8.6, z: 0.34 },
{ x: -6.6, z: 0.34 },
{ x: -1.0, z: 0.34 },
{ x: 0.0, z: 0.34 },
{ x: 1.0, z: 0.55 },
{ x: 2.4, z: 0.9 },
{ x: 4.7, z: 0.85 },
{ x: 5.15, z: -0.4 }
]
},
{
id: "jo",
name: "Jo",
detail: "White cane",
color: colors.purple,
radius: 0.22,
speed: 1.02,
model: makeCaneUser,
points: [
{ x: -8.2, z: 0.04 },
{ x: -6.4, z: 0.04 },
{ x: -1.0, z: 0.04 },
{ x: 0.2, z: 0.2 },
{ x: 1.4, z: 0.75 },
{ x: 3.2, z: 0.65 },
{ x: 3.45, z: -0.65 }
]
},
{
id: "sam",
name: "Sam",
detail: "Pushchair",
color: colors.green,
radius: 0.45,
speed: 1.18,
model: makeStroller,
points: [
{ x: -8.7, z: -0.72 },
{ x: -6.6, z: -0.72 },
{ x: -1.0, z: -0.72 },
{ x: 0.3, z: -0.72 },
{ x: 1.2, z: -0.72 },
{ x: 2.8, z: -0.72 },
{ x: 4.7, z: -0.72 }
]
}
];
const routeLayer = new THREE.Group();
const markerLayer = new THREE.Group();
scene.add(routeLayer, markerLayer);
const agents = agentDefinitions.map((definition) => {
const route = buildRoute(definition.points);
const group = definition.model(definition.color);
scene.add(group);
const plannedGeometry = new THREE.BufferGeometry().setFromPoints(
route.samples.map((p) => new THREE.Vector3(p.x, p.y + 0.045, p.z))
);
const plannedLine = new THREE.Line(
plannedGeometry,
new THREE.LineDashedMaterial({
color: definition.color,
transparent: true,
opacity: 0.38,
dashSize: 0.2,
gapSize: 0.15,
depthWrite: false
})
);
plannedLine.computeLineDistances();
routeLayer.add(plannedLine);
const traveledGeometry = new THREE.BufferGeometry().setFromPoints(
route.samples.map((p) => new THREE.Vector3(p.x, p.y + 0.055, p.z))
);
const traveledLine = new THREE.Line(
traveledGeometry,
new THREE.LineBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.92
})
);
traveledLine.geometry.setDrawRange(0, 1);
routeLayer.add(traveledLine);
const label = makeLabelSprite(`${definition.name} · ${definition.detail}`, `#${definition.color.toString(16).padStart(6, "0")}`);
label.position.set(0, 1.95, 0);
label.scale.set(2.15, 0.54, 1);
group.add(label);
return {
...definition,
group,
route,
plannedLine,
traveledLine,
label,
distance: 0,
status: "moving",
blocker: null
};
});
// ------------------------------------------------------------
// Observable collision recording
// ------------------------------------------------------------
let fixesApplied = false;
let running = true;
let sessionTime = 0;
let events = [];
const eventLog = document.getElementById("event-log");
const metricRound = document.getElementById("metric-round");
const metricMoved = document.getElementById("metric-moved");
const metricBlocked = document.getElementById("metric-blocked");
const metricClear = document.getElementById("metric-clear");
const sessionTimeElement = document.getElementById("session-time");
const roundTag = document.getElementById("round-tag");
const playButton = document.getElementById("play-button");
const resetButton = document.getElementById("reset-button");
const fixToggle = document.getElementById("fix-toggle");
function formatTime(seconds) {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${String(mins).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
}
function renderEvents() {
eventLog.innerHTML = events
.map(
(event) => `
<div class="event ${event.kind}">
<div class="event-dot"></div>
<div>
<div class="event-title">${event.title}</div>
<div class="event-detail">${event.detail}</div>
<div class="event-time">${event.location} · ${formatTime(event.time)}</div>
</div>
</div>
`
)
.join("");
}
function addEvent(kind, title, detail, location = "Prototype study") {
events.unshift({ kind, title, detail, location, time: sessionTime });
renderEvents();
}
function updateMetrics() {
const moving = agents.filter((a) => a.status === "moving").length;
const blocked = agents.filter((a) => a.status === "blocked").length;
const clear = agents.filter((a) => a.status === "clear").length;
metricRound.textContent = fixesApplied ? "02" : "01";
metricMoved.textContent = `${moving}/4`;
metricBlocked.textContent = String(blocked);
metricClear.textContent = String(clear);
sessionTimeElement.textContent = formatTime(sessionTime);
roundTag.textContent = fixesApplied
? "Round 02 · Revised"
: "Round 01 · As built";
}
function setAgentLabel(agent, suffix, color) {
agent.label.material.map?.dispose();
agent.label.material.dispose();
const texture = canvasTexture(512, 128, (ctx, w, h) => {
ctx.fillStyle = color;
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#ffffff";
ctx.font = "800 33px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(`${agent.name} · ${suffix}`, w / 2, h / 2);
});
agent.label.material = new THREE.SpriteMaterial({ map: texture });
}
function pointIsBlocked(x, z, radius) {
for (const blocker of blockers) {
const closestX = THREE.MathUtils.clamp(
x,
blocker.center.x - blocker.half.x,
blocker.center.x + blocker.half.x
);
const closestZ = THREE.MathUtils.clamp(
z,
blocker.center.y - blocker.half.y,
blocker.center.y + blocker.half.y
);
const distance = Math.hypot(x - closestX, z - closestZ);
if (distance < radius) return blocker;
}
return null;
}
function findCollision(agent, from, to) {
const step = 0.055;
const distance = to - from;
if (distance <= 0) return null;
for (let d = step; d <= distance + step; d += step) {
const sampleDistance = Math.min(to, from + d);
const p = pointAtDistance(agent.route, sampleDistance);
const blocker = pointIsBlocked(p.x, p.z, agent.radius);
if (blocker) {
const safeDistance = Math.max(from, sampleDistance - step * 0.65);
return { blocker, distance: safeDistance, point: pointAtDistance(agent.route, safeDistance) };
}
}
return null;
}
function clearDynamicMarkers() {
while (markerLayer.children.length) {
const child = markerLayer.children.pop();
child.traverse((object) => {
object.geometry?.dispose();
if (Array.isArray(object.material)) {
object.material.forEach((m) => m.dispose());
} else {
object.material?.dispose();
}
});
}
}
function addBlockedMarker(agent, point) {
const marker = new THREE.Group();
marker.position.set(point.x, point.y + 0.07, point.z);
markerLayer.add(marker);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.2, 0.34, 28),
new THREE.MeshBasicMaterial({
color: colors.orange,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.92
})
);
ring.rotation.x = -Math.PI / 2;
marker.add(ring);
const barMaterial = new THREE.MeshBasicMaterial({ color: colors.orange });
const bar1 = new THREE.Mesh(new THREE.BoxGeometry(0.42, 0.035, 0.07), barMaterial);
const bar2 = new THREE.Mesh(new THREE.BoxGeometry(0.42, 0.035, 0.07), barMaterial);
bar1.rotation.y = Math.PI / 4;
bar2.rotation.y = -Math.PI / 4;
marker.add(bar1, bar2);
const previous = pointAtDistance(
agent.route,
Math.max(0, agent.distance - 0.48)
);
const blockedGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(previous.x, previous.y + 0.075, previous.z),
new THREE.Vector3(point.x, point.y + 0.075, point.z)
]);
const blockedLine = new THREE.Line(
blockedGeometry,
new THREE.LineBasicMaterial({ color: colors.orange })
);
markerLayer.add(blockedLine);
}
function positionAgent(agent) {
const p = pointAtDistance(agent.route, agent.distance);
agent.group.position.set(p.x, p.y, p.z);
const targetYaw = p.heading;
let difference = targetYaw - agent.group.rotation.y;
difference = Math.atan2(Math.sin(difference), Math.cos(difference));
agent.group.rotation.y += difference * 0.14;
const drawIndex = Math.min(
agent.route.sampleCount,
Math.floor((agent.distance / agent.route.total) * agent.route.sampleCount)
);
agent.traveledLine.geometry.setDrawRange(0, drawIndex + 1);
}
function placeObstaclesForRound() {
if (fixesApplied) {
planter.position.set(-5.0, 0, 2.35);
cabinet.position.set(0.55, 0.42, 2.35);
blockers[0].center.set(-5.0, 2.35);
blockers[1].center.set(0.55, 2.35);
planterLabel.material.color.setHex(0xffffff);
cabinetLabel.material.color.setHex(0xffffff);
} else {
planter.position.set(-4.2, groundHeightAt(-4.2), 0.28);
cabinet.position.set(2.0, 0.42, -0.55);
blockers[0].center.set(-4.2, 0.28);
blockers[1].center.set(2.0, -0.55);
}
}
function resetSession(systemMessage = true) {
sessionTime = 0;
events = [];
clearDynamicMarkers();
placeObstaclesForRound();
originalPriorityBench.visible = !fixesApplied;
revisedPriorityBench.visible = fixesApplied;
for (const agent of agents) {
agent.distance = 0;
agent.status = "moving";
agent.blocker = null;
agent.group.rotation.y = Math.PI / 2;
positionAgent(agent);
const color = `#${agent.color.toString(16).padStart(6, "0")}`;
setAgentLabel(agent, agent.detail, color);
}
if (systemMessage) {
addEvent(
"clear",
fixesApplied ? "Co-design revision activated" : "As-built route study started",
fixesApplied
? "The ramp planter is relocated, the cabinet is moved outside the approach lane, and the priority bench gains a lateral transfer opening."
: "Four mobility proxies are following user-derived routes through the unrevised prototype.",
fixesApplied ? "Design revision" : "Study start"
);
}
updateMetrics();
}
function blockAgent(agent, collision) {
agent.distance = collision.distance;
agent.status = "blocked";
agent.blocker = collision.blocker;
positionAgent(agent);
addBlockedMarker(agent, collision.point);
setAgentLabel(agent, "BLOCKED", "#e76f51");
addEvent(
"blocked",
`${agent.name} · ${agent.detail}: ${collision.blocker.eventTitle}`,
collision.blocker.eventDetail,
collision.blocker.location
);
updateMetrics();
}
function completeAgent(agent) {
agent.status = "clear";
setAgentLabel(agent, "CLEAR", "#397e64");
addEvent(
"clear",
`${agent.name} · ${agent.detail} reached the seating area`,
fixesApplied
? "The revised route remained clear through the ramp, turning zone, and seating approach."
: "The planned route reached the seating area without another recorded conflict.",
"Shelter seating"
);
updateMetrics();
}
// ------------------------------------------------------------
// Directly implemented camera controls
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.05, 0),
theta: 2.25,
phi: 0.91,
radius: 22
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.cos(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let panning = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (panning) {
const scale = cameraState.radius * 0.0013;
cameraState.target.x -= dx * scale * Math.cos(cameraState.theta);
cameraState.target.z += dx * scale * Math.sin(cameraState.theta);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y + dy * scale,
0.2,
4
);
} else {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.43,
1.38
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
panning = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
panning = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
11,
34
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") cameraState.theta += step;
if (event.key === "ArrowRight") cameraState.theta -= step;
if (event.key === "ArrowUp") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - step, 0.43, 1.38);
}
if (event.key === "ArrowDown") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + step, 0.43, 1.38);
}
if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(11, cameraState.radius - 1);
}
if (event.key === "-") {
cameraState.radius = Math.min(34, cameraState.radius + 1);
}
updateCamera();
});
// ------------------------------------------------------------
// Interface controls
// ------------------------------------------------------------
playButton.addEventListener("click", () => {
running = !running;
playButton.textContent = running ? "Pause" : "Resume";
});
resetButton.addEventListener("click", () => {
running = true;
playButton.textContent = "Pause";
resetSession();
});
fixToggle.addEventListener("change", () => {
fixesApplied = fixToggle.checked;
running = true;
playButton.textContent = "Pause";
resetSession();
});
// ------------------------------------------------------------
// Animation and resize
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
sessionTime += delta;
for (const agent of agents) {
if (agent.status !== "moving") continue;
const proposed = Math.min(
agent.route.total,
agent.distance + agent.speed * delta
);
const collision = findCollision(agent, agent.distance, proposed);
if (collision) {
blockAgent(agent, collision);
} else {
agent.distance = proposed;
positionAgent(agent);
if (agent.distance >= agent.route.total - 0.01) {
agent.distance = agent.route.total;
positionAgent(agent);
completeAgent(agent);
}
}
}
}
updateMetrics();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
resetSession();
animate();
</script>
</body>
</html>
```