Prompt specification
Build or customize the Three.js 3D scene "Inclusive sidewalk inspection game" 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: Inclusive sidewalk inspection game
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inclusive-sidewalk-inspection-game-x0448
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring cane-detectable obstacles. Create a short street with movable signs and café furniture; users identify discontinuities and relocate obstacles while a route overlay checks clear passage through the whole block. Low-poly.
Working Three.js Starter (inclusive-sidewalk-inspection-game-x0448):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cane Route Lab</title>
<style>
:root {
--ink: #18313a;
--muted: #647981;
--paper: #f7fbf9;
--panel: rgba(250, 253, 251, 0.94);
--line: rgba(31, 68, 76, 0.14);
--teal: #087f78;
--teal-bright: #13b8a6;
--cyan: #34c6ef;
--amber: #e59a20;
--red: #d95656;
--green: #168b62;
--shadow: 0 18px 55px rgba(27, 55, 62, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 15px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 16px;
background: rgba(250, 253, 251, 0.84);
box-shadow: 0 8px 30px rgba(27, 55, 62, 0.1);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 12px;
color: white;
background: linear-gradient(145deg, #0b9187, #075f64);
font-weight: 900;
letter-spacing: -0.08em;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1.1;
letter-spacing: -0.02em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
}
.top-status {
display: flex;
align-items: center;
gap: 9px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 999px;
background: rgba(250, 253, 251, 0.87);
box-shadow: 0 8px 30px rgba(27, 55, 62, 0.1);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 4px rgba(229, 154, 32, 0.15);
}
.top-status.good .status-dot {
background: var(--green);
box-shadow: 0 0 0 4px rgba(22, 139, 98, 0.14);
}
.top-status.bad .status-dot {
background: var(--red);
box-shadow: 0 0 0 4px rgba(217, 86, 86, 0.14);
}
#topStatusText {
font-size: 12px;
font-weight: 750;
letter-spacing: 0.02em;
}
.panel {
position: fixed;
z-index: 12;
top: 18px;
right: 20px;
bottom: 18px;
width: 352px;
overflow: auto;
overscroll-behavior: contain;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.panel::-webkit-scrollbar {
width: 8px;
}
.panel::-webkit-scrollbar-thumb {
border: 2px solid transparent;
border-radius: 99px;
background: rgba(35, 77, 84, 0.18);
background-clip: padding-box;
}
.section {
padding: 18px;
border-bottom: 1px solid var(--line);
}
.section:last-child {
border-bottom: 0;
}
.eyebrow {
margin: 0 0 7px;
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.route-card {
position: relative;
overflow: hidden;
padding: 15px;
border: 1px solid rgba(217, 86, 86, 0.19);
border-radius: 16px;
background: rgba(217, 86, 86, 0.07);
}
.route-card.good {
border-color: rgba(22, 139, 98, 0.21);
background: rgba(22, 139, 98, 0.07);
}
.route-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.route-heading strong {
font-size: 17px;
letter-spacing: -0.02em;
}
.route-badge {
padding: 5px 8px;
border-radius: 99px;
color: var(--red);
background: rgba(217, 86, 86, 0.13);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.route-badge.good {
color: var(--green);
background: rgba(22, 139, 98, 0.13);
}
#routeMeta {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.metric {
padding: 10px;
border-radius: 11px;
background: rgba(255, 255, 255, 0.72);
border: 1px solid rgba(31, 68, 76, 0.08);
}
.metric span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 13px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.section-title h2 {
margin: 0;
font-size: 14px;
letter-spacing: -0.01em;
}
.small-count {
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.progress {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: rgba(31, 68, 76, 0.09);
}
#auditProgress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), var(--cyan));
transition: width 240ms ease;
}
.audit-counts {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.object-list {
display: grid;
gap: 8px;
}
.object-card {
width: 100%;
display: grid;
grid-template-columns: 31px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 13px;
color: var(--ink);
background: rgba(255, 255, 255, 0.67);
cursor: pointer;
text-align: left;
transition:
transform 140ms ease,
border-color 140ms ease,
background 140ms ease;
}
.object-card:hover {
transform: translateY(-1px);
border-color: rgba(8, 127, 120, 0.28);
background: white;
}
.object-card.selected {
border-color: rgba(8, 127, 120, 0.5);
background: rgba(19, 184, 166, 0.09);
box-shadow: inset 3px 0 0 var(--teal-bright);
}
.object-icon {
width: 31px;
height: 31px;
display: grid;
place-items: center;
border-radius: 9px;
color: var(--teal);
background: rgba(8, 127, 120, 0.09);
font-size: 15px;
font-weight: 900;
}
.object-name {
min-width: 0;
}
.object-name strong {
display: block;
overflow: hidden;
font-size: 12px;
text-overflow: ellipsis;
white-space: nowrap;
}
.object-name small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.object-badge {
padding: 4px 6px;
border-radius: 99px;
color: var(--muted);
background: rgba(31, 68, 76, 0.07);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.object-badge.issue {
color: #a85e09;
background: rgba(229, 154, 32, 0.15);
}
.object-badge.flagged {
color: #a04444;
background: rgba(217, 86, 86, 0.13);
}
.object-badge.clear {
color: var(--green);
background: rgba(22, 139, 98, 0.12);
}
.inspector-empty {
padding: 15px;
border: 1px dashed rgba(31, 68, 76, 0.21);
border-radius: 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
text-align: center;
}
.inspector-title {
margin: 0;
font-size: 18px;
letter-spacing: -0.025em;
}
.inspector-copy {
margin: 9px 0 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.cue-chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-bottom: 11px;
}
.cue-chip {
padding: 6px 8px;
border-radius: 99px;
color: var(--green);
background: rgba(22, 139, 98, 0.1);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.cue-chip.missing {
color: #a85e09;
background: rgba(229, 154, 32, 0.13);
}
.cue-chip.lane {
color: #a04444;
background: rgba(217, 86, 86, 0.11);
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.button {
min-height: 38px;
padding: 9px 12px;
border: 1px solid transparent;
border-radius: 10px;
color: white;
background: var(--teal);
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition:
transform 140ms ease,
background 140ms ease,
opacity 140ms ease;
}
.button:hover:not(:disabled) {
transform: translateY(-1px);
background: #066e69;
}
.button.secondary {
color: var(--ink);
border-color: var(--line);
background: rgba(255, 255, 255, 0.78);
}
.button.secondary:hover:not(:disabled) {
background: white;
}
.button.warning {
color: #744106;
background: #f3b64f;
}
.button.warning:hover:not(:disabled) {
background: #eaa52f;
}
.button:disabled {
cursor: default;
opacity: 0.5;
}
.position-readout {
margin-top: 10px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
}
.legend {
display: grid;
gap: 8px;
color: var(--muted);
font-size: 10px;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.legend-swatch {
width: 23px;
height: 6px;
border-radius: 99px;
background: var(--teal-bright);
}
.legend-swatch.amber {
background: var(--amber);
}
.legend-swatch.cyan {
background: var(--cyan);
}
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.view-tools {
position: fixed;
z-index: 9;
left: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
}
.tool-group {
display: flex;
gap: 4px;
padding: 5px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 13px;
background: rgba(250, 253, 251, 0.88);
box-shadow: 0 8px 30px rgba(27, 55, 62, 0.1);
backdrop-filter: blur(12px);
}
.tool-button {
width: 34px;
height: 34px;
border: 0;
border-radius: 9px;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 16px;
font-weight: 800;
}
.tool-button:hover {
background: rgba(8, 127, 120, 0.1);
}
.hint {
max-width: 390px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 13px;
color: var(--muted);
background: rgba(250, 253, 251, 0.86);
box-shadow: 0 8px 30px rgba(27, 55, 62, 0.1);
backdrop-filter: blur(12px);
font-size: 11px;
line-height: 1.45;
pointer-events: none;
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
bottom: 24px;
max-width: min(480px, calc(100vw - 30px));
padding: 11px 15px;
border-radius: 12px;
color: white;
background: rgba(24, 49, 58, 0.94);
box-shadow: 0 12px 35px rgba(24, 49, 58, 0.24);
font-size: 12px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.success {
position: fixed;
z-index: 40;
inset: 0;
display: grid;
place-items: center;
padding: 24px;
background: rgba(22, 48, 54, 0.34);
backdrop-filter: blur(8px);
}
.success.hidden {
display: none;
}
.success-card {
width: min(410px, 100%);
padding: 28px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 24px;
background: rgba(250, 253, 251, 0.97);
box-shadow: 0 30px 80px rgba(24, 49, 58, 0.27);
text-align: center;
}
.success-icon {
width: 64px;
height: 64px;
display: grid;
place-items: center;
margin: 0 auto 15px;
border-radius: 20px;
color: white;
background: linear-gradient(145deg, #13b88e, #087f78);
font-size: 30px;
font-weight: 900;
}
.success-card h2 {
margin: 0;
font-size: 25px;
letter-spacing: -0.04em;
}
.success-card p {
margin: 10px 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
@media (max-width: 820px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
padding: 9px 11px;
}
.brand p {
display: none;
}
.top-status {
padding: 10px;
}
.panel {
top: auto;
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 47vh;
border-radius: 18px;
}
.view-tools {
left: 10px;
bottom: calc(47vh + 20px);
}
.hint {
display: none;
}
}
@media (max-width: 480px) {
.brand-mark {
width: 32px;
height: 32px;
}
.brand h1 {
font-size: 14px;
}
#topStatusText {
font-size: 10px;
}
.section {
padding: 14px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly street accessibility scene"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark">CR</div>
<div>
<h1>Cane Route Lab</h1>
<p>Audit detectable cues. Restore a continuous route.</p>
</div>
</div>
<div class="top-status" id="topStatus">
<span class="status-dot"></span>
<span id="topStatusText">CHECKING PASSAGE</span>
</div>
</header>
<aside class="panel" aria-label="Route audit panel">
<section class="section">
<p class="eyebrow">Live route check</p>
<div class="route-card" id="routeCard">
<div class="route-heading">
<strong id="routeTitle">Calculating route</strong>
<span class="route-badge" id="routeBadge">CHECKING</span>
</div>
<p id="routeMeta">
Testing the sidewalk for a continuous 1.10 m passage.
</p>
<div class="metrics">
<div class="metric">
<span>Required width</span>
<strong>1.10 m</strong>
</div>
<div class="metric">
<span>Block direction</span>
<strong>West → east</strong>
</div>
</div>
</div>
</section>
<section class="section">
<div class="section-title">
<h2>Audit progress</h2>
<span class="small-count" id="auditPercent">0%</span>
</div>
<div class="progress"><div id="auditProgress"></div></div>
<div class="audit-counts">
<span id="reviewedCount">Reviewed 0 / 5</span>
<span id="flaggedCount">Flagged 0 / 3</span>
<span id="relocatedCount">Relocated 0 / 3</span>
</div>
</section>
<section class="section">
<div class="section-title">
<h2>Street objects</h2>
<span class="small-count">Select to inspect</span>
</div>
<div class="object-list" id="objectList"></div>
</section>
<section class="section" id="inspector">
<p class="eyebrow">Object inspector</p>
<div class="inspector-empty" id="inspectorEmpty">
Select a sign, table, chair, planter, or pole.
<br />
Drag objects to relocate them and watch the route update.
</div>
<div id="inspectorContent" hidden>
<h2 class="inspector-title" id="inspectorTitle"></h2>
<div class="cue-chips" id="cueChips"></div>
<p class="inspector-copy" id="inspectorCopy"></p>
<div class="button-row">
<button class="button warning" id="flagButton">Flag discontinuity</button>
<button class="button secondary" id="bayButton">Move to clear bay</button>
</div>
<div class="position-readout" id="positionReadout"></div>
</div>
</section>
<section class="section">
<p class="eyebrow">Visual key</p>
<div class="legend">
<div class="legend-row">
<span class="legend-swatch cyan"></span>
<span>Blue corridor: minimum continuous route</span>
</div>
<div class="legend-row">
<span class="legend-swatch"></span>
<span>Teal lower band: cane-detectable cue</span>
</div>
<div class="legend-row">
<span class="legend-swatch amber"></span>
<span>Amber outline: selected object</span>
</div>
</div>
</section>
<section class="section">
<div class="panel-actions">
<button class="button secondary" id="checkButton">Run route check</button>
<button class="button secondary" id="resetButton">Reset layout</button>
</div>
</section>
</aside>
<div class="view-tools">
<div class="tool-group">
<button class="tool-button" id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button class="tool-button" id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button class="tool-button" id="homeView" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
<div class="hint">
<strong>Controls:</strong> click to inspect · drag objects to move ·
drag pavement to orbit · right-drag to pan · scroll to zoom
</div>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<div class="success hidden" id="successOverlay">
<div class="success-card">
<div class="success-icon">✓</div>
<h2>Block verified</h2>
<p>
All objects have been audited, each discontinuity has been flagged and
relocated, and the blue route now passes continuously through the block.
</p>
<button class="button" id="successClose">Review the route</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e7);
scene.fog = new THREE.Fog(0xdce8e7, 58, 105);
const camera = new THREE.OrthographicCamera(-25, 25, 16, -16, 0.1, 180);
const rig = {
azimuth: 0.58,
polar: 0.88,
zoom: 1,
radius: 48,
target: new THREE.Vector3(0, 0.35, 0)
};
function updateCamera() {
const s = Math.sin(rig.polar);
camera.position.set(
rig.target.x + rig.radius * s * Math.sin(rig.azimuth),
rig.target.y + rig.radius * Math.cos(rig.polar),
rig.target.z + rig.radius * s * Math.cos(rig.azimuth)
);
camera.lookAt(rig.target);
camera.zoom = rig.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
const hemisphere = new THREE.HemisphereLight(0xeaf8f4, 0x81938d, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(-17, 30, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -31;
sun.shadow.camera.right = 31;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const materialCache = new Map();
function getMaterial(color, options = {}) {
if (color?.isMaterial) return color;
const key = `${String(color)}:${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
getMaterial(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
topRadius,
bottomRadius,
height,
position,
color,
segments = 10,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
getMaterial(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addTextPlane(text, width, height, background, foreground) {
const textCanvas = document.createElement("canvas");
textCanvas.width = 1024;
textCanvas.height = 256;
const ctx = textCanvas.getContext("2d");
ctx.clearRect(0, 0, textCanvas.width, textCanvas.height);
ctx.fillStyle = background;
ctx.fillRect(0, 0, textCanvas.width, textCanvas.height);
ctx.fillStyle = foreground;
ctx.font = "800 76px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 512, 132, 950);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
})
);
}
function addTextSprite(text, color = "#ffffff", background = "#18313a") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 4, 504, 120, 30);
ctx.fill();
ctx.fillStyle = color;
ctx.font = "800 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66, 460);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.6, 0.9, 1);
sprite.renderOrder = 20;
return sprite;
}
// ------------------------------------------------------------
// Street environment
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
getMaterial(0xb9c9bf)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.24;
ground.receiveShadow = true;
scene.add(ground);
addBox(scene, [56, 0.18, 10.4], [0, -0.08, 9.6], 0x536267);
addBox(scene, [56, 0.1, 8.7], [0, -0.11, 0.05], 0x91a19c);
// Sidewalk slabs and their subtle seams.
for (let i = 0; i < 46; i++) {
const x = -22.5 + i;
addBox(
scene,
[0.97, 0.27, 8.55],
[x, 0.015, 0.05],
i % 2 === 0 ? 0xd7d5c6 : 0xd3d1c2
);
}
// Curb blocks.
for (let i = 0; i < 23; i++) {
addBox(
scene,
[1.92, 0.32, 0.34],
[-22 + i * 2, 0.12, 4.35],
i % 2 === 0 ? 0xe6e1d1 : 0xded9c9
);
}
// Road markings.
for (let x = -24; x <= 24; x += 4) {
addBox(
scene,
[1.7, 0.025, 0.12],
[x, 0.035, 9.65],
0xf1e9ca,
{ castShadow: false }
);
}
// Building shells.
function addBuilding(x, width, height, color, name, accent) {
const group = new THREE.Group();
group.position.set(x, 0.16, -8.1);
scene.add(group);
addBox(
group,
[width, height, 5.5],
[0, height / 2, 0],
color
);
addBox(
group,
[width + 0.25, 0.28, 5.85],
[0, height + 0.12, 0],
0x6d7974
);
const windowCount = Math.max(2, Math.floor(width / 3));
const windowWidth = Math.min(2.1, width / windowCount - 0.8);
for (let i = 0; i < windowCount; i++) {
const wx = -width / 2 + 1.5 + i * ((width - 3) / (windowCount - 1));
addBox(
group,
[windowWidth, 1.55, 0.08],
[wx, height * 0.55, 2.79],
0x315c63,
{ roughness: 0.35 }
);
addBox(
group,
[0.07, 1.56, 0.1],
[wx, height * 0.55, 2.84],
0xe7e1c8
);
}
addBox(
group,
[1.55, 2.35, 0.12],
[0, 1.18, 2.82],
0x35575a
);
if (name) {
const sign = addTextPlane(name, Math.min(width - 1.2, 7), 1.15, accent, "#fffaf0");
sign.position.set(0, height - 1.05, 2.84);
group.add(sign);
}
}
addBuilding(-15, 11.5, 7.2, 0xd4b6a2, "BOOKS", "#315c63");
addBuilding(7, 18, 6.8, 0xe6d4aa, "CAFÉ LUNE", "#b95d45");
addBuilding(23, 12.5, 8.2, 0xafc4ba, "CORNER SHOP", "#456b64");
// Café awning.
const awning = new THREE.Group();
awning.position.set(7, 3.9, -4.88);
scene.add(awning);
for (let i = 0; i < 12; i++) {
const stripe = addBox(
awning,
[1.42, 0.13, 1.4],
[-7.85 + i * 1.42, 0, 0],
i % 2 === 0 ? 0xb95d45 : 0xf3dfbc
);
stripe.rotation.x = -0.13;
}
// Café tables represented by small decorative cups and plants.
for (const x of [-14, -8, 12, 17]) {
addCylinder(scene, 0.18, 0.18, 0.22, [x, 0.3, -3.65], 0xc36d4b, 8);
const plant = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.36, 0),
getMaterial(0x4d8b68)
);
plant.position.set(x, 0.67, -3.65);
plant.castShadow = true;
scene.add(plant);
}
// Low-poly vehicles.
function addCar(x, z, color, rotation = 0) {
const car = new THREE.Group();
car.position.set(x, 0.05, z);
car.rotation.y = rotation;
scene.add(car);
addBox(car, [3.2, 0.7, 1.45], [0, 0.6, 0], color);
addBox(car, [1.65, 0.66, 1.26], [-0.15, 1.18, 0], 0xc9ded8);
addBox(car, [1.48, 0.5, 1.29], [-0.15, 1.2, 0], 0x365c63);
for (const wx of [-1, 1]) {
for (const wz of [-0.73, 0.73]) {
const wheel = addCylinder(
car,
0.32,
0.32,
0.22,
[wx, 0.34, wz],
0x26383a,
10
);
wheel.rotation.x = Math.PI / 2;
}
}
}
addCar(-13, 8.1, 0xc86d55);
addCar(14, 11.15, 0x5e8b93, Math.PI);
// Trees.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.16, z);
tree.scale.setScalar(scale);
scene.add(tree);
addCylinder(tree, 0.15, 0.22, 2.4, [0, 1.2, 0], 0x876a4d, 7);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.05, 0),
getMaterial(0x56886b)
);
crown.position.y = 2.75;
crown.scale.set(1, 1.13, 0.9);
crown.castShadow = true;
tree.add(crown);
const crown2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72, 0),
getMaterial(0x75a17a)
);
crown2.position.set(0.42, 3.15, 0.1);
crown2.castShadow = true;
tree.add(crown2);
}
addTree(-20.5, -3.55, 0.9);
addTree(18.2, -3.55, 1.05);
addTree(21.4, 3.55, 0.78);
// Street lamps.
function addLamp(x, z) {
const lamp = new THREE.Group();
lamp.position.set(x, 0.16, z);
scene.add(lamp);
addCylinder(lamp, 0.055, 0.085, 3.4, [0, 1.7, 0], 0x3f5556, 8);
addBox(lamp, [0.65, 0.1, 0.25], [0.25, 3.4, 0], 0x3f5556);
addBox(lamp, [0.35, 0.12, 0.22], [0.48, 3.31, 0], 0xf6dfa0);
const pool = new THREE.Mesh(
new THREE.CircleGeometry(0.72, 24),
new THREE.MeshBasicMaterial({
color: 0xf5d890,
transparent: true,
opacity: 0.08,
depthWrite: false
})
);
pool.rotation.x = -Math.PI / 2;
pool.position.set(0.48, 0.025, 0);
lamp.add(pool);
}
addLamp(-20, 3.55);
addLamp(-4, 3.55);
addLamp(20, 3.55);
// Marked furnishing bays outside the walking corridor.
const bayTargets = {
table: new THREE.Vector3(-4.2, 0.16, -3.62),
sign: new THREE.Vector3(0, 0.16, -3.62),
chair: new THREE.Vector3(4.2, 0.16, -3.62),
planter: new THREE.Vector3(-10, 0.16, -3.62),
pole: new THREE.Vector3(12, 0.16, -3.62)
};
for (const target of Object.values(bayTargets)) {
const bay = new THREE.Mesh(
new THREE.PlaneGeometry(2.6, 1.12),
new THREE.MeshBasicMaterial({
color: 0x11ad9c,
transparent: true,
opacity: 0.11,
depthWrite: false
})
);
bay.rotation.x = -Math.PI / 2;
bay.position.set(target.x, 0.165, target.z + 0.05);
scene.add(bay);
const border = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.PlaneGeometry(2.6, 1.12)),
new THREE.LineBasicMaterial({
color: 0x148f83,
transparent: true,
opacity: 0.5
})
);
border.rotation.x = -Math.PI / 2;
border.position.copy(bay.position);
border.position.y += 0.005;
scene.add(border);
}
const bayLabel = addTextSprite("CLEAR FURNITURE BAYS", "#d9fff8", "#087f78");
bayLabel.position.set(0, 0.65, -3.8);
bayLabel.scale.set(5.4, 1.05, 1);
scene.add(bayLabel);
// Entry and exit labels.
const entryLabel = addTextSprite("ENTRY", "#ffffff", "#087f78");
entryLabel.position.set(-20.5, 1.1, 0.45);
entryLabel.scale.set(2.6, 0.65, 1);
scene.add(entryLabel);
const exitLabel = addTextSprite("EXIT", "#ffffff", "#18313a");
exitLabel.position.set(20.5, 1.1, 0.45);
exitLabel.scale.set(2.6, 0.65, 1);
scene.add(exitLabel);
// ------------------------------------------------------------
// Interactive obstacles
// ------------------------------------------------------------
const obstacles = [];
const pickables = [];
function addCueBand(group, radius = 0.36, square = false) {
if (square) {
addBox(
group,
[radius * 2, 0.17, radius * 2],
[0, 0.13, 0],
0x0ba99b,
{ roughness: 0.55 }
);
addBox(
group,
[radius * 2.05, 0.05, radius * 2.05],
[0, 0.23, 0],
0xf3e7c6,
{ roughness: 0.55 }
);
} else {
addCylinder(
group,
radius,
radius,
0.17,
[0, 0.13, 0],
0x0ba99b,
12,
{ roughness: 0.55 }
);
addCylinder(
group,
radius + 0.018,
radius + 0.018,
0.045,
[0, 0.235, 0],
0xf3e7c6,
12,
{ roughness: 0.55 }
);
}
}
function registerObstacle(config) {
const group = new THREE.Group();
group.position.set(config.x, 0.16, config.z);
group.userData.obstacleId = config.id;
scene.add(group);
const obstacle = {
...config,
group,
flagged: false,
audited: false
};
group.traverse((child) => {
if (child.isMesh) child.userData.obstacleId = config.id;
});
obstacles.push(obstacle);
pickables.push(group);
return obstacle;
}
// A-frame café sign: open frame, no continuous detectable lower face.
{
const group = new THREE.Group();
addBox(group, [0.09, 1.28, 0.09], [-0.42, 0.64, 0], 0x5d493d);
addBox(group, [0.09, 1.28, 0.09], [0.42, 0.64, 0], 0x5d493d);
addBox(group, [0.94, 1.08, 0.12], [0, 0.64, 0], 0xb85f46);
for (let i = 0; i < 3; i++) {
const stripe = addBox(
group,
[0.72, 0.08, 0.025],
[0, 0.35 + i * 0.25, 0.075],
0xf4dfb7
);
stripe.rotation.z = -0.45;
}
addBox(group, [0.5, 0.16, 0.025], [0, 0.84, 0.08], 0xfff2d3);
group.rotation.y = -0.18;
registerObstacle({
id: "sign",
name: "A-frame café sign",
short: "A",
icon: "▱",
type: "Movable sign",
x: 0.8,
z: -1.3,
radius: 0.65,
detectable: false,
issue: true,
description:
"The open A-frame has gaps between slats. A cane can pass between them without contacting a continuous detectable surface.",
model: group
});
}
// Café table: detectable pedestal, but the projecting top intrudes.
{
const group = new THREE.Group();
addCylinder(group, 0.7, 0.7, 0.13, [0, 0.82, 0], 0xc88d56, 12);
addCylinder(group, 0.095, 0.12, 0.73, [0, 0.41, 0], 0x496568, 10);
addCylinder(group, 0.42, 0.42, 0.07, [0, 0.05, 0], 0x496568, 12);
addCueBand(group, 0.34);
addCylinder(group, 0.11, 0.09, 0.18, [0.2, 0.97, 0.05], 0xf7f0da, 8);
addCylinder(group, 0.12, 0.12, 0.015, [0.2, 1.07, 0.05], 0x6f3f31, 8);
registerObstacle({
id: "table",
name: "Café table",
short: "T",
icon: "T",
type: "Café furniture",
x: 0,
z: 1.05,
radius: 1.2,
detectable: true,
issue: true,
description:
"The pedestal has a detectable lower band, but the projecting tabletop leaves less than the required continuous clear width.",
model: group
});
}
// Isolated chair with thin, low-contrast legs.
{
const group = new THREE.Group();
addBox(group, [0.64, 0.1, 0.58], [0, 0.48, 0], 0x507d78);
addBox(group, [0.64, 0.53, 0.08], [0, 0.76, -0.25], 0x507d78);
for (const x of [-0.25, 0.25]) {
for (const z of [-0.21, 0.21]) {
addBox(
group,
[0.055, 0.48, 0.055],
[x, 0.24, z],
0x6c7770
);
}
}
group.rotation.y = 0.2;
registerObstacle({
id: "chair",
name: "Loose café chair",
short: "C",
icon: "C",
type: "Café furniture",
x: 6.4,
z: 0.1,
radius: 0.65,
detectable: false,
issue: true,
description:
"The isolated legs and low-contrast seat do not create a continuous cane-detectable face, so the chair may be missed below knee height.",
model: group
});
}
// Detectable planter.
{
const group = new THREE.Group();
addBox(group, [1.15, 0.66, 1.15], [0, 0.33, 0], 0xaf7657);
addCueBand(group, 0.61, true);
const foliage = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72, 0),
getMaterial(0x5b8e67)
);
foliage.position.y = 1.02;
foliage.scale.set(1.05, 0.95, 1);
foliage.castShadow = true;
group.add(foliage);
const foliage2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.46, 0),
getMaterial(0x79a873)
);
foliage2.position.set(0.32, 1.35, 0.06);
foliage2.castShadow = true;
group.add(foliage2);
registerObstacle({
id: "planter",
name: "Street planter",
short: "P",
icon: "P",
type: "Fixed street object",
x: -10,
z: 1.25,
radius: 0.7,
detectable: true,
issue: false,
description:
"The planter has a continuous face and a contrasting lower band. It is detectable, and the route can bend around it.",
model: group
});
}
// Detectable sign pole.
{
const group = new THREE.Group();
addCylinder(group, 0.24, 0.28, 0.1, [0, 0.05, 0], 0x53686a, 10);
addCylinder(group, 0.065, 0.08, 2.5, [0, 1.25, 0], 0x53686a, 8);
addCueBand(group, 0.22);
addBox(group, [0.78, 0.58, 0.09], [0, 2.05, 0], 0x227c77);
addBox(group, [0.62, 0.07, 0.025], [0, 2.08, 0.055], 0xf5e9c8);
registerObstacle({
id: "pole",
name: "Wayfinding pole",
short: "W",
icon: "W",
type: "Street sign",
x: 13,
z: 2.25,
radius: 0.25,
detectable: true,
issue: false,
description:
"The projecting base and contrasting lower band make the pole cane-detectable. The route has sufficient room to pass below it.",
model: group
});
}
// ------------------------------------------------------------
// Selection helpers
// ------------------------------------------------------------
const selectionBox = new THREE.BoxHelper(
obstacles[0].group,
new THREE.Color(0xe59a20)
);
selectionBox.visible = false;
selectionBox.material.depthTest = false;
selectionBox.material.transparent = true;
selectionBox.material.opacity = 0.92;
selectionBox.renderOrder = 15;
scene.add(selectionBox);
const selectionRing = new THREE.Mesh(
new THREE.RingGeometry(0.8, 0.9, 48),
new THREE.MeshBasicMaterial({
color: 0xe59a20,
transparent: true,
opacity: 0.85,
depthTest: false,
depthWrite: false,
side: THREE.DoubleSide
})
);
selectionRing.rotation.x = -Math.PI / 2;
selectionRing.visible = false;
selectionRing.renderOrder = 15;
scene.add(selectionRing);
let selectedObstacle = null;
function updateSelectionHelpers() {
if (!selectedObstacle) {
selectionBox.visible = false;
selectionRing.visible = false;
return;
}
selectionBox.setFromObject(selectedObstacle.group);
selectionBox.visible = true;
selectionRing.position.set(
selectedObstacle.group.position.x,
0.185,
selectedObstacle.group.position.z
);
selectionRing.scale.setScalar(
Math.max(1, selectedObstacle.radius / 0.75)
);
selectionRing.visible = true;
}
// ------------------------------------------------------------
// Grid-based A* route checker
// ------------------------------------------------------------
const ROUTE = {
minX: -21.5,
maxX: 21.5,
minZ: -2,
maxZ: 3,
step: 0.3,
clearance: 0.55
};
const gridWidth = Math.round(
(ROUTE.maxX - ROUTE.minX) / ROUTE.step
) + 1;
const gridHeight = Math.round(
(ROUTE.maxZ - ROUTE.minZ) / ROUTE.step
) + 1;
const cellCount = gridWidth * gridHeight;
const blockedCells = new Uint8Array(cellCount);
function cellX(index) {
return ROUTE.minX + (index % gridWidth) * ROUTE.step;
}
function cellZ(index) {
return (
ROUTE.minZ +
Math.floor(index / gridWidth) * ROUTE.step
);
}
function cellIndex(ix, iz) {
return iz * gridWidth + ix;
}
function cellIsBlocked(ix, iz) {
if (ix < 0 || iz < 0 || ix >= gridWidth || iz >= gridHeight) {
return true;
}
const x = ROUTE.minX + ix * ROUTE.step;
const z = ROUTE.minZ + iz * ROUTE.step;
// Keep the route center inside the pedestrian corridor with clearance.
if (
x < ROUTE.minX + ROUTE.clearance ||
x > ROUTE.maxX - ROUTE.clearance ||
z < ROUTE.minZ + ROUTE.clearance ||
z > ROUTE.maxZ - ROUTE.clearance
) {
return true;
}
for (const obstacle of obstacles) {
const dx = x - obstacle.group.position.x;
const dz = z - obstacle.group.position.z;
const required = obstacle.radius + ROUTE.clearance;
if (dx * dx + dz * dz < required * required) {
return true;
}
}
return false;
}
class MinHeap {
constructor() {
this.items = [];
}
push(item) {
this.items.push(item);
let i = this.items.length - 1;
while (i > 0) {
const parent = Math.floor((i - 1) / 2);
if (this.items[parent].f <= item.f) break;
this.items[i] = this.items[parent];
i = parent;
}
this.items[i] = item;
}
pop() {
if (this.items.length === 0) return null;
const root = this.items[0];
const tail = this.items.pop();
if (this.items.length > 0) {
this.items[0] = tail;
let i = 0;
while (true) {
const left = i * 2 + 1;
const right = left + 1;
let smallest = i;
if (
left < this.items.length &&
this.items[left].f < this.items[smallest].f
) {
smallest = left;
}
if (
right < this.items.length &&
this.items[right].f < this.items[smallest].f
) {
smallest = right;
}
if (smallest === i) break;
[this.items[i], this.items[smallest]] = [
this.items[smallest],
this.items[i]
];
i = smallest;
}
}
return root;
}
get length() {
return this.items.length;
}
}
function nearestCell(x, z) {
const ix = Math.max(
0,
Math.min(
gridWidth - 1,
Math.round((x - ROUTE.minX) / ROUTE.step)
)
);
const iz = Math.max(
0,
Math.min(
gridHeight - 1,
Math.round((z - ROUTE.minZ) / ROUTE.step)
)
);
return cellIndex(ix, iz);
}
function findRoute() {
const start = nearestCell(-20.5, 0.4);
const goal = nearestCell(20.5, 0.4);
if (blockedCells[start] || blockedCells[goal]) {
return {
path: null,
blocker: obstacles.find(
(o) =>
Math.hypot(
o.group.position.x + 20.5,
o.group.position.z - 0.4
) <
o.radius + ROUTE.clearance
)
};
}
const gScore = new Float64Array(cellCount);
gScore.fill(Infinity);
const cameFrom = new Int32Array(cellCount);
cameFrom.fill(-1);
const closed = new Uint8Array(cellCount);
const heap = new MinHeap();
const goalX = cellX(goal);
const goalZ = cellZ(goal);
const heuristic = (index) =>
Math.abs(cellX(index) - goalX) +
Math.abs(cellZ(index) - goalZ);
gScore[start] = 0;
heap.push({ index: start, g: 0, f: heuristic(start) });
const directions = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1],
[1, 1],
[1, -1],
[-1, 1],
[-1, -1]
];
while (heap.length) {
const current = heap.pop();
if (current.g !== gScore[current.index]) continue;
if (closed[current.index]) continue;
closed[current.index] = 1;
if (current.index === goal) {
const path = [];
let cursor = goal;
while (cursor !== -1) {
path.push(
new THREE.Vector3(cellX(cursor), 0.205, cellZ(cursor))
);
cursor = cameFrom[cursor];
}
path.reverse();
return { path, blocker: null };
}
const ix = current.index % gridWidth;
const iz = Math.floor(current.index / gridWidth);
for (const [dx, dz] of directions) {
const nx = ix + dx;
const nz = iz + dz;
if (
nx < 0 ||
nz < 0 ||
nx >= gridWidth ||
nz >= gridHeight
) {
continue;
}
const neighbor = cellIndex(nx, nz);
if (blockedCells[neighbor] || closed[neighbor]) continue;
// Do not cut diagonally through blocked orthogonal cells.
if (
dx !== 0 &&
dz !== 0 &&
(blockedCells[cellIndex(nx, iz)] ||
blockedCells[cellIndex(ix, nz)])
) {
continue;
}
const movement = dx !== 0 && dz !== 0 ? Math.SQRT2 : 1;
const tentative = current.g + movement;
if (tentative < gScore[neighbor]) {
gScore[neighbor] = tentative;
cameFrom[neighbor] = current.index;
heap.push({
index: neighbor,
g: tentative,
f: tentative + heuristic(neighbor)
});
}
}
}
// Find the reachable cell closest to the exit to place a blockage marker.
let nearest = start;
let nearestDistance = Infinity;
for (let i = 0; i < cellCount; i++) {
if (!closed[i]) continue;
const distance =
Math.abs(cellX(i) - goalX) + Math.abs(cellZ(i) - goalZ);
if (distance < nearestDistance) {
nearestDistance = distance;
nearest = i;
}
}
let blocker = null;
let blockerDistance = Infinity;
for (const obstacle of obstacles) {
const dx = cellX(nearest) - obstacle.group.position.x;
const dz = cellZ(nearest) - obstacle.group.position.z;
const distance = Math.hypot(dx, dz);
const relevance = obstacle.radius + ROUTE.clearance + ROUTE.step * 1.5;
if (distance < relevance && distance < blockerDistance) {
blocker = obstacle;
blockerDistance = distance;
}
}
return { path: null, blocker };
}
function simplifyPath(path) {
if (!path || path.length < 3) return path ?? [];
const simplified = [path[0]];
for (let i = 1; i < path.length - 1; i++) {
const previous = simplified[simplified.length - 1];
const current = path[i];
const next = path[i + 1];
const directionA = new THREE.Vector2(
current.x - previous.x,
current.z - previous.z
);
const directionB = new THREE.Vector2(
next.x - current.x,
next.z - current.z
);
if (directionA.cross(directionB) ** 2 > 0.00001) {
simplified.push(current);
}
}
simplified.push(path[path.length - 1]);
return simplified;
}
const routeGroup = new THREE.Group();
scene.add(routeGroup);
function clearRouteGroup() {
while (routeGroup.children.length) {
const child = routeGroup.children.pop();
child.traverse((item) => {
item.geometry?.dispose();
if (Array.isArray(item.material)) {
item.material.forEach((material) => material.dispose());
} else {
item.material?.dispose();
}
});
}
}
function addRouteSegment(a, b, width, height, color, opacity = 1) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
if (length < 0.001) return null;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, length + 0.025),
new THREE.MeshBasicMaterial({
color,
transparent: opacity < 1,
opacity,
depthWrite: false
})
);
mesh.position.set(
(a.x + b.x) / 2,
0.19,
(a.z + b.z) / 2
);
mesh.rotation.y = Math.atan2(dx, dz);
mesh.renderOrder = 4;
routeGroup.add(mesh);
return mesh;
}
function addRouteDisc(position, color, radius = 0.33) {
const disc = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 0.035, 24),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
})
);
disc.position.set(position.x, 0.205, position.z);
disc.renderOrder = 5;
routeGroup.add(disc);
}
function renderRoute(route) {
clearRouteGroup();
if (route.path) {
const path = simplifyPath(route.path);
for (let i = 0; i < path.length - 1; i++) {
addRouteSegment(
path[i],
path[i + 1],
1.1,
0.018,
0x34c6ef,
0.18
);
addRouteSegment(
path[i],
path[i + 1],
0.075,
0.035,
0x0799c6,
0.98
);
}
addRouteDisc(path[0], 0x087f78, 0.38);
addRouteDisc(path[path.length - 1], 0x168b62, 0.38);
} else {
const start = new THREE.Vector3(-20.5, 0.22, 0.4);
const blockerPosition = route.blocker
? new THREE.Vector3(
route.blocker.group.position.x,
0.22,
route.blocker.group.position.z
)
: new THREE.Vector3(0, 0.22, 0);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
start,
blockerPosition
]),
new THREE.LineDashedMaterial({
color: 0xd95656,
dashSize: 0.55,
gapSize: 0.28,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
line.computeLineDistances();
line.renderOrder = 7;
routeGroup.add(line);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(
Math.max(0.8, route.blocker?.radius ?? 0.9),
0.065,
8,
40
),
new THREE.MeshBasicMaterial({
color: 0xd95656,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.copy(blockerPosition);
ring.position.y = 0.23;
ring.renderOrder = 8;
routeGroup.add(ring);
const crossA = addBox(
routeGroup,
[0.8, 0.05, 0.1],
[
blockerPosition.x,
0.245,
blockerPosition.z
],
0xd95656,
{ castShadow: false, receiveShadow: false }
);
const crossB = addBox(
routeGroup,
[0.1, 0.05, 0.8],
[
blockerPosition.x,
0.25,
blockerPosition.z
],
0xd95656,
{ castShadow: false, receiveShadow: false }
);
crossA.rotation.y = Math.PI / 4;
crossB.rotation.y = Math.PI / 4;
const marker = addTextSprite("ROUTE BLOCKED", "#ffffff", "#c34d4d");
marker.position.set(
blockerPosition.x,
1.65,
blockerPosition.z
);
marker.scale.set(3.3, 0.82, 1);
routeGroup.add(marker);
}
}
let currentRoute = null;
function routeLength(path) {
let length = 0;
for (let i = 0; i < path.length - 1; i++) {
length += path[i].distanceTo(path[i + 1]);
}
return length;
}
function updateRoute() {
for (let i = 0; i < cellCount; i++) blockedCells[i] = cellIsBlocked(i % gridWidth, Math.floor(i / gridWidth)) ? 1 : 0;
currentRoute = findRoute();
renderRoute(currentRoute);
const isClear = Boolean(currentRoute.path);
const routeCard = document.getElementById("routeCard");
const routeBadge = document.getElementById("routeBadge");
const routeTitle = document.getElementById("routeTitle");
const routeMeta = document.getElementById("routeMeta");
const topStatus = document.getElementById("topStatus");
const topStatusText = document.getElementById("topStatusText");
routeCard.classList.toggle("good", isClear);
routeBadge.classList.toggle("good", isClear);
topStatus.classList.toggle("good", isClear);
topStatus.classList.toggle("bad", !isClear);
routeBadge.textContent = isClear ? "PASSABLE" : "BLOCKED";
routeTitle.textContent = isClear
? "Continuous passage found"
: "Passage is blocked";
topStatusText.textContent = isClear
? "ROUTE PASSABLE"
: "ROUTE BLOCKED";
routeMeta.textContent = isClear
? `${routeLength(currentRoute.path).toFixed(1)} m continuous route found within the required 1.10 m clear width.`
: "No continuous route was found within the required 1.10 m clear width.";
updateAuditProgress();
checkCompletion();
}
let routeFrame = 0;
function scheduleRouteUpdate() {
if (routeFrame) return;
routeFrame = requestAnimationFrame(() => {
routeFrame = 0;
updateRoute();
});
}
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
const objectList = document.getElementById("objectList");
const inspectorEmpty = document.getElementById("inspectorEmpty");
const inspectorContent = document.getElementById("inspectorContent");
function isRelocated(obstacle) {
return obstacle.group.position.z < -2.72;
}
function buildObjectList() {
objectList.innerHTML = "";
for (const obstacle of obstacles) {
const button = document.createElement("button");
button.className = "object-card";
button.dataset.id = obstacle.id;
button.classList.toggle(
"selected",
selectedObstacle?.id === obstacle.id
);
let badge = "REVIEW";
let badgeClass = "";
if (obstacle.audited) {
if (obstacle.issue) {
badge = obstacle.flagged ? "FLAGGED" : "ISSUE";
badgeClass = obstacle.flagged ? "flagged" : "issue";
} else {
badge = "CLEAR";
badgeClass = "clear";
}
}
const location = isRelocated(obstacle)
? "Clear furnishing strip"
: obstacle.type;
button.innerHTML = `
<span class="object-icon">${obstacle.icon}</span>
<span class="object-name">
<strong>${obstacle.name}</strong>
<small>${location}</small>
</span>
<span class="object-badge ${badgeClass}">${badge}</span>
`;
objectList.appendChild(button);
}
}
function updateInspector() {
if (!selectedObstacle) {
inspectorEmpty.hidden = false;
inspectorContent.hidden = true;
return;
}
const obstacle = selectedObstacle;
inspectorEmpty.hidden = true;
inspectorContent.hidden = false;
document.getElementById("inspectorTitle").textContent =
obstacle.name;
const cueChip = obstacle.detectable
? `<span class="cue-chip">Cane cue: present</span>`
: `<span class="cue-chip missing">Cane cue: missing</span>`;
const laneChip = isRelocated(obstacle)
? `<span class="cue-chip">Outside walking lane</span>`
: `<span class="cue-chip lane">Intrudes into route</span>`;
document.getElementById("cueChips").innerHTML =
cueChip + laneChip;
document.getElementById("inspectorCopy").textContent =
obstacle.description;
const flagButton = document.getElementById("flagButton");
flagButton.disabled = !obstacle.issue || obstacle.flagged;
flagButton.textContent = obstacle.flagged
? "Discontinuity flagged ✓"
: obstacle.issue
? "Flag discontinuity"
: "No discontinuity found";
document.getElementById("bayButton").textContent = isRelocated(
obstacle
)
? "Return to furnishing bay"
: "Move to clear bay";
document.getElementById("positionReadout").textContent =
`X ${obstacle.group.position.x.toFixed(2)} m · Z ${obstacle.group.position.z.toFixed(2)} m`;
}
function selectObstacle(obstacle) {
selectedObstacle = obstacle;
if (obstacle) obstacle.audited = true;
buildObjectList();
updateInspector();
updateAuditProgress();
updateSelectionHelpers();
}
function updateAuditProgress() {
const issueObjects = obstacles.filter((obstacle) => obstacle.issue);
const reviewed = obstacles.filter((obstacle) => obstacle.audited).length;
const flagged = issueObjects.filter(
(obstacle) => obstacle.flagged
).length;
const relocated = issueObjects.filter(isRelocated).length;
const totalTasks = obstacles.length + issueObjects.length * 2;
const completedTasks = reviewed + flagged + relocated;
const percent = Math.round((completedTasks / totalTasks) * 100);
document.getElementById("reviewedCount").textContent =
`Reviewed ${reviewed} / ${obstacles.length}`;
document.getElementById("flaggedCount").textContent =
`Flagged ${flagged} / ${issueObjects.length}`;
document.getElementById("relocatedCount").textContent =
`Relocated ${relocated} / ${issueObjects.length}`;
document.getElementById("auditPercent").textContent =
`${percent}%`;
document.getElementById("auditProgress").style.width =
`${percent}%`;
}
function checkCompletion() {
const allReviewed = obstacles.every((obstacle) => obstacle.audited);
const allFlagged = obstacles
.filter((obstacle) => obstacle.issue)
.every((obstacle) => obstacle.flagged);
const allRelocated = obstacles
.filter((obstacle) => obstacle.issue)
.every(isRelocated);
const routeClear = Boolean(currentRoute?.path);
if (
allReviewed &&
allFlagged &&
allRelocated &&
routeClear
) {
document.getElementById("successOverlay").classList.remove("hidden");
}
}
let toastTimer = 0;
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 2600);
}
objectList.addEventListener("click", (event) => {
const card = event.target.closest("[data-id]");
if (!card) return;
const obstacle = obstacles.find(
(item) => item.id === card.dataset.id
);
if (obstacle) selectObstacle(obstacle);
});
document.getElementById("flagButton").addEventListener("click", () => {
if (!selectedObstacle?.issue) return;
selectedObstacle.flagged = true;
buildObjectList();
updateInspector();
updateAuditProgress();
showToast(`${selectedObstacle.name} flagged as a route discontinuity.`);
});
document.getElementById("bayButton").addEventListener("click", () => {
if (!selectedObstacle) return;
const target = bayTargets[selectedObstacle.id];
if (!target) return;
selectedObstacle.group.position.x = target.x;
selectedObstacle.group.position.z = target.z;
selectedObstacle.group.position.y = 0.16;
buildObjectList();
updateInspector();
updateSelectionHelpers();
updateRoute();
showToast(
`${selectedObstacle.name} moved to the clear furnishing bay.`
);
});
document.getElementById("checkButton").addEventListener("click", () => {
updateRoute();
showToast(
currentRoute.path
? "Route check complete: continuous passage found."
: "Route check complete: passage is still blocked."
);
});
const initialPositions = new Map(
obstacles.map((obstacle) => [
obstacle.id,
new THREE.Vector3(
obstacle.group.position.x,
obstacle.group.position.y,
obstacle.group.position.z
)
])
);
document.getElementById("resetButton").addEventListener("click", () => {
for (const obstacle of obstacles) {
const initial = initialPositions.get(obstacle.id);
obstacle.group.position.copy(initial);
obstacle.flagged = false;
obstacle.audited = false;
}
selectedObstacle = null;
document
.getElementById("successOverlay")
.classList.add("hidden");
buildObjectList();
updateInspector();
updateSelectionHelpers();
updateRoute();
showToast("Street layout reset.");
});
document.getElementById("successClose").addEventListener("click", () => {
document
.getElementById("successOverlay")
.classList.add("hidden");
});
// ------------------------------------------------------------
// Pointer interaction and custom camera controls
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(
new THREE.Vector3(0, 1, 0),
-0.16
);
const planePoint = new THREE.Vector3();
let pointerDown = false;
let activeMode = null;
let dragObstacle = null;
let dragOffset = new THREE.Vector2();
let dragMoved = false;
let lastPointer = { x: 0, y: 0 };
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function pickObstacle(event) {
updatePointer(event);
const hits = raycaster.intersectObjects(pickables, true);
for (const hit of hits) {
let object = hit.object;
while (object && !object.userData.obstacleId) {
object = object.parent;
}
if (object?.userData.obstacleId) {
return obstacles.find(
(item) => item.id === object.userData.obstacleId
);
}
}
return null;
}
function pointerToGround(event) {
updatePointer(event);
return raycaster.ray.intersectPlane(dragPlane, planePoint);
}
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerLast = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
const hitObstacle =
event.button === 0 && !event.shiftKey
? pickObstacle(event)
: null;
if (hitObstacle) {
selectObstacle(hitObstacle);
activeMode = "object";
dragObstacle = hitObstacle;
dragMoved = false;
const ground = pointerToGround(event);
if (ground) {
dragOffset.set(
hitObstacle.group.position.x - ground.x,
hitObstacle.group.position.z - ground.z
);
}
canvas.style.cursor = "grabbing";
} else if (event.button === 2 || event.shiftKey) {
activeMode = "pan";
canvas.style.cursor = "grabbing";
} else {
activeMode = "orbit";
canvas.style.cursor = "grabbing";
}
event.preventDefault();
});
let pointerLast = { x: 0, y: 0 };
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) {
const hovered = pickObstacle(event);
canvas.style.cursor = hovered ? "grab" : "default";
return;
}
const dx = event.clientX - pointerLast.x;
const dy = event.clientY - pointerLast.y;
pointerLast = { x: event.clientX, y: event.clientY };
if (activeMode === "object" && dragObstacle) {
const ground = pointerToGround(event);
if (ground) {
let x = ground.x + dragOffset.x;
let z = ground.z + dragOffset.y;
x = THREE.MathUtils.clamp(x, -21.2, 21.2);
z = THREE.MathUtils.clamp(z, -3.95, 3.35);
x = Math.round(x * 20) / 20;
z = Math.round(z * 20) / 20;
if (
Math.abs(x - dragObstacle.group.position.x) > 0.001 ||
Math.abs(z - dragObstacle.group.position.z) > 0.001
) {
dragMoved = true;
}
dragObstacle.group.position.x = x;
dragObstacle.group.position.z = z;
updateSelectionHelpers();
updateInspector();
scheduleRouteUpdate();
}
} else if (activeMode === "orbit") {
rig.azimuth -= dx * 0.006;
rig.polar = THREE.MathUtils.clamp(
rig.polar + dy * 0.0045,
0.43,
1.28
);
updateCamera();
} else if (activeMode === "pan") {
const units = 0.045 / rig.zoom;
const right = new THREE.Vector3(
Math.cos(rig.azimuth),
0,
-Math.sin(rig.azimuth)
);
const forward = new THREE.Vector3(
-Math.sin(rig.azimuth),
0,
-Math.cos(rig.azimuth)
);
rig.target.addScaledVector(right, -dx * units);
rig.target.addScaledVector(forward, -dy * units);
rig.target.x = THREE.MathUtils.clamp(rig.target.x, -10, 10);
rig.target.z = THREE.MathUtils.clamp(rig.target.z, -8, 7);
updateCamera();
}
});
function finishPointer(event) {
if (activeMode === "object" && dragObstacle && dragMoved) {
updateRoute();
buildObjectList();
updateInspector();
showToast(
`${dragObstacle.name} relocated. Route recalculated automatically.`
);
}
pointerDown = false;
activeMode = null;
dragObstacle = null;
dragMoved = false;
canvas.style.cursor = "default";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", finishPointer);
canvas.addEventListener("pointercancel", finishPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
rig.zoom = THREE.MathUtils.clamp(
rig.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.35
);
updateCamera();
},
{ passive: false }
);
document.getElementById("zoomIn").addEventListener("click", () => {
rig.zoom = THREE.MathUtils.clamp(rig.zoom * 1.12, 0.68, 2.35);
updateCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
rig.zoom = THREE.MathUtils.clamp(rig.zoom / 1.12, 0.68, 2.35);
updateCamera();
});
document.getElementById("homeView").addEventListener("click", () => {
rig.azimuth = 0.58;
rig.polar = 0.88;
rig.zoom = 1;
rig.target.set(0, 0.35, 0);
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (!selectedObstacle) return;
const step = event.shiftKey ? 0.5 : 0.2;
let changed = true;
switch (event.key) {
case "ArrowLeft":
selectedObstacle.group.position.x -= step;
break;
case "ArrowRight":
selectedObstacle.group.position.x += step;
break;
case "ArrowUp":
selectedObstacle.group.position.z -= step;
break;
case "ArrowDown":
selectedObstacle.group.position.z += step;
break;
case "Escape":
selectObstacle(null);
changed = false;
break;
default:
changed = false;
}
if (changed) {
event.preventDefault();
selectedObstacle.group.position.x = THREE.MathUtils.clamp(
selectedObstacle.group.position.x,
-21.2,
21.2
);
selectedObstacle.group.position.z = THREE.MathUtils.clamp(
selectedObstacle.group.position.z,
-3.95,
3.35
);
updateSelectionHelpers();
updateInspector();
updateRoute();
buildObjectList();
}
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
const frustumHeight = Math.max(27, 49 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
updateCamera();
}
window.addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
if (selectedObstacle) {
selectionBox.update();
selectionRing.material.opacity =
0.72 + Math.sin(performance.now() * 0.004) * 0.14;
}
renderer.render(scene, camera);
}
buildObjectList();
updateInspector();
updateAuditProgress();
resize();
updateRoute();
animate();
</script>
</body>
</html>
```