Prompt specification
Build or customize the Three.js 3D scene "Service catchment across a hillside" 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: Service catchment across a hillside
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/service-catchment-across-a-hillside-x1283
Scene Description Prompt:
A voxel hillside neighborhood maps reachable bus-stop areas separately through stairs and wheelchair-compatible routes under explicit constraints. Three.js from cdnjs, one HTML file.
Working Three.js Starter (service-catchment-across-a-hillside-x1283):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hillside Reach — Accessible Bus Stop Map</title>
<style>
:root {
--ink: #19312e;
--muted: #66736f;
--paper: #f4f1e9;
--panel: #fffdf8;
--line: #deddd4;
--teal: #008f7a;
--teal-soft: #d9f0e8;
--orange: #e85f31;
--orange-soft: #fae1d5;
--shadow: 0 18px 50px rgba(25, 49, 46, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
header {
height: 70px;
flex: 0 0 70px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
background: var(--panel);
border-bottom: 1px solid var(--line);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 39px;
height: 39px;
border-radius: 12px;
display: grid;
place-items: center;
background: var(--ink);
color: white;
box-shadow: 0 6px 18px rgba(25, 49, 46, 0.18);
}
.brand-mark svg {
width: 25px;
height: 25px;
}
.brand-title {
font-weight: 790;
letter-spacing: -0.04em;
font-size: 19px;
line-height: 1;
}
.brand-subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.header-right {
display: flex;
align-items: center;
gap: 10px;
}
.model-status {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: #faf9f5;
font-size: 12px;
font-weight: 650;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px var(--teal-soft);
}
.header-button {
border: 1px solid var(--line);
background: white;
border-radius: 10px;
padding: 9px 12px;
cursor: pointer;
font-size: 12px;
font-weight: 720;
}
.header-button:hover {
background: #f4f2eb;
}
main {
min-height: 0;
flex: 1;
display: flex;
}
aside {
width: 370px;
flex: 0 0 370px;
background: var(--panel);
border-right: 1px solid var(--line);
overflow-y: auto;
overscroll-behavior: contain;
z-index: 10;
box-shadow: 8px 0 30px rgba(25, 49, 46, 0.035);
}
.panel-section {
padding: 21px 22px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 6px;
color: var(--muted);
font-size: 10px;
line-height: 1.2;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
h1,
h2,
h3,
p {
margin-top: 0;
}
h1 {
margin-bottom: 9px;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.045em;
}
.intro {
margin-bottom: 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 4px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 12px;
background: #efeee7;
}
.segmented button {
border: 0;
border-radius: 8px;
background: transparent;
padding: 9px 5px;
cursor: pointer;
color: var(--muted);
font-size: 11px;
font-weight: 760;
transition: 160ms ease;
}
.segmented button[aria-pressed="true"] {
color: var(--ink);
background: white;
box-shadow: 0 2px 8px rgba(25, 49, 46, 0.1);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.section-heading h2 {
margin: 0;
font-size: 14px;
letter-spacing: -0.02em;
}
.rule-chip {
padding: 5px 8px;
border-radius: 999px;
background: #efeee7;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.constraint-block {
margin-bottom: 16px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: #fcfbf7;
}
.constraint-block:last-child {
margin-bottom: 0;
}
.constraint-title {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 14px;
font-size: 12px;
font-weight: 790;
}
.route-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--teal);
flex: 0 0 auto;
}
.route-dot.stairs {
background: var(--orange);
}
.control {
margin-top: 12px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 690;
}
.control-label output {
color: var(--ink);
font-size: 11px;
font-weight: 810;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0;
border-radius: 99px;
accent-color: var(--teal);
cursor: pointer;
}
.stairs input[type="range"] {
accent-color: var(--orange);
}
.fixed-rule {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-top: 10px;
margin-top: 11px;
border-top: 1px dashed #d8d5ca;
color: var(--muted);
font-size: 10px;
}
.fixed-rule strong {
color: var(--ink);
font-size: 10px;
}
.presets {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
}
.preset {
border: 1px solid var(--line);
background: white;
border-radius: 999px;
padding: 6px 9px;
cursor: pointer;
color: var(--muted);
font-size: 9px;
font-weight: 760;
}
.preset:hover,
.preset[aria-pressed="true"] {
border-color: var(--ink);
color: var(--ink);
background: #f0efe8;
}
.reach-summary {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 13px;
}
.summary-card {
border: 1px solid var(--line);
border-radius: 12px;
padding: 11px 12px;
background: #fcfbf7;
}
.summary-card .number {
display: block;
margin-bottom: 2px;
font-size: 23px;
line-height: 1;
font-weight: 820;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.summary-card .label {
color: var(--muted);
font-size: 9px;
font-weight: 760;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.summary-card.stairs .number {
color: var(--orange);
}
.summary-card.wheel .number {
color: var(--teal);
}
.selected-card {
margin-bottom: 12px;
padding: 13px;
border-radius: 13px;
background: var(--ink);
color: white;
}
.selected-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.selected-card strong {
display: block;
margin-bottom: 3px;
font-size: 14px;
}
.selected-card small {
color: #b9c7c3;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.selected-code {
color: #9eb2ad;
font-size: 10px;
font-weight: 800;
}
.selected-route {
display: grid;
grid-template-columns: 74px 1fr;
gap: 8px;
padding: 7px 0;
border-top: 1px solid rgba(255, 255, 255, 0.12);
font-size: 10px;
line-height: 1.4;
}
.selected-route span:first-child {
font-weight: 790;
}
.selected-route.stairs span:first-child {
color: #ff9a75;
}
.selected-route.wheel span:first-child {
color: #66d8bc;
}
.selected-route span:last-child {
color: #d6dfdc;
}
.stops {
display: grid;
gap: 7px;
}
.stop-card {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: white;
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.stop-card:hover {
border-color: #b6beb8;
transform: translateY(-1px);
box-shadow: 0 6px 16px rgba(25, 49, 46, 0.07);
}
.stop-card[aria-current="true"] {
border-color: var(--ink);
box-shadow: 0 0 0 1px var(--ink);
}
.stop-name {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
}
.stop-pin {
width: 9px;
height: 9px;
border: 2px solid white;
border-radius: 50%;
background: #8c9691;
box-shadow: 0 0 0 1px #8c9691;
flex: 0 0 auto;
}
.stop-pin.stairs {
background: var(--orange);
box-shadow: 0 0 0 1px var(--orange);
}
.stop-pin.wheel {
background: var(--teal);
box-shadow: 0 0 0 1px var(--teal);
}
.stop-copy {
min-width: 0;
}
.stop-copy strong {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 11px;
}
.stop-copy small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.badges {
display: flex;
flex: 0 0 auto;
gap: 4px;
}
.badge {
min-width: 31px;
padding: 5px 6px;
border-radius: 7px;
text-align: center;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.03em;
}
.badge.ok.stairs {
color: #ae3f1d;
background: var(--orange-soft);
}
.badge.ok.wheel {
color: #006d5e;
background: var(--teal-soft);
}
.badge.no {
color: #7b817e;
background: #eeeee9;
}
.method-note {
padding: 13px 22px 18px;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
.method-note strong {
color: var(--ink);
}
#viewport {
position: relative;
min-width: 0;
flex: 1;
overflow: hidden;
background: #dfe8e3;
}
#canvasHost,
#labels {
position: absolute;
inset: 0;
}
#canvasHost canvas {
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#canvasHost canvas:active {
cursor: grabbing;
}
#labels {
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -100%);
display: flex;
align-items: center;
gap: 6px;
max-width: 150px;
padding: 6px 8px;
border: 1px solid rgba(25, 49, 46, 0.14);
border-radius: 9px;
background: rgba(255, 253, 248, 0.94);
color: var(--ink);
box-shadow: 0 5px 18px rgba(25, 49, 46, 0.16);
font-size: 9px;
font-weight: 780;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
backdrop-filter: blur(7px);
}
.map-label:hover {
border-color: var(--ink);
}
.map-label[aria-current="true"] {
background: var(--ink);
color: white;
}
.map-label .label-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #89928e;
flex: 0 0 auto;
}
.map-label.stairs .label-dot {
background: var(--orange);
}
.map-label.wheel .label-dot {
background: var(--teal);
}
.map-top {
position: absolute;
top: 18px;
left: 18px;
display: flex;
align-items: stretch;
gap: 8px;
z-index: 4;
pointer-events: none;
}
.map-card {
padding: 12px 14px;
border: 1px solid rgba(25, 49, 46, 0.12);
border-radius: 13px;
background: rgba(255, 253, 248, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.map-card small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 790;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.map-card strong {
font-size: 12px;
letter-spacing: -0.015em;
}
.map-tools {
position: absolute;
top: 18px;
right: 18px;
display: flex;
gap: 6px;
z-index: 5;
}
.tool-button {
width: 36px;
height: 36px;
display: grid;
place-items: center;
border: 1px solid rgba(25, 49, 46, 0.15);
border-radius: 11px;
background: rgba(255, 253, 248, 0.94);
box-shadow: 0 6px 20px rgba(25, 49, 46, 0.11);
cursor: pointer;
font-size: 18px;
font-weight: 650;
backdrop-filter: blur(8px);
}
.tool-button:hover {
background: white;
border-color: var(--ink);
}
.tool-button svg {
width: 17px;
height: 17px;
}
.compass {
position: absolute;
top: 66px;
right: 22px;
z-index: 4;
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 50%;
background: rgba(255, 253, 248, 0.8);
color: var(--ink);
font-size: 9px;
font-weight: 850;
box-shadow: 0 4px 14px rgba(25, 49, 46, 0.1);
pointer-events: none;
}
.legend {
position: absolute;
left: 18px;
bottom: 18px;
z-index: 4;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 15px;
padding: 11px 13px;
border: 1px solid rgba(25, 49, 46, 0.12);
border-radius: 12px;
background: rgba(255, 253, 248, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 720;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-line {
width: 24px;
height: 3px;
border-radius: 99px;
background: var(--teal);
}
.legend-line.stairs {
height: 3px;
background: repeating-linear-gradient(
90deg,
var(--orange) 0 7px,
transparent 7px 11px
);
}
.legend-ring {
width: 12px;
height: 12px;
border: 2px solid #89928e;
border-radius: 50%;
}
.origin-chip {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 10px 12px;
border-radius: 12px;
background: rgba(25, 49, 46, 0.91);
color: white;
box-shadow: var(--shadow);
font-size: 9px;
font-weight: 740;
pointer-events: none;
}
.origin-icon {
width: 9px;
height: 9px;
border: 2px solid white;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}
.loading {
position: absolute;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #dfe8e3;
color: var(--ink);
font-size: 12px;
font-weight: 760;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
html,
body {
overflow: auto;
}
.app {
min-height: 100%;
height: auto;
}
header {
padding: 0 14px;
}
.model-status,
.header-button {
display: none;
}
main {
flex-direction: column-reverse;
}
#viewport {
height: 62vh;
min-height: 470px;
flex: none;
}
aside {
width: 100%;
flex: none;
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
.panel-section {
padding: 18px;
}
.map-card.secondary {
display: none;
}
.origin-chip {
display: none;
}
.legend {
gap: 10px;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 32 32" fill="none">
<path d="M7 23V12L14 7H25" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7 23H15L21 17H25" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="7" cy="23" r="3" fill="#66d8bc"/>
<circle cx="25" cy="7" r="3" fill="#ff9a75"/>
<circle cx="25" cy="17" r="3" fill="#66d8bc"/>
</svg>
</div>
<div>
<div class="brand-title">Hillside Reach</div>
<div class="brand-subtitle">Cedar Heights transit access</div>
</div>
</div>
<div class="header-right">
<div class="model-status">
<span class="status-dot"></span>
Constraint model active
</div>
<button class="header-button" id="exportButton" type="button">Export summary</button>
</div>
</header>
<main>
<aside aria-label="Route constraints and reachable stops">
<section class="panel-section">
<p class="eyebrow">Access explorer</p>
<h1>Every route has rules.</h1>
<p class="intro">
Compare bus-stop areas reachable from West Gate through walking stairs
and independently through compliant step-free routes.
</p>
<div class="segmented" role="group" aria-label="Map route layer">
<button type="button" data-mode="both" aria-pressed="true">Both</button>
<button type="button" data-mode="stairs" aria-pressed="false">Stairs</button>
<button type="button" data-mode="wheel" aria-pressed="false">Step-free</button>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Explicit constraints</h2>
<span class="rule-chip">Applied per edge</span>
</div>
<div class="constraint-block stairs">
<div class="constraint-title">
<span class="route-dot stairs"></span>
Stairs / walking route
</div>
<div class="control">
<label class="control-label" for="maxRise">
<span>Maximum total climb</span>
<output id="maxRiseOutput">8.0 m</output>
</label>
<input id="maxRise" type="range" min="4" max="12" step="0.5" value="8" />
</div>
<div class="control">
<label class="control-label" for="maxSteps">
<span>Maximum treads per flight</span>
<output id="maxStepsOutput">28 steps</output>
</label>
<input id="maxSteps" type="range" min="12" max="32" step="2" value="28" />
</div>
<div class="fixed-rule">
<span>Lift dependencies</span>
<strong>None permitted</strong>
</div>
</div>
<div class="constraint-block">
<div class="constraint-title">
<span class="route-dot"></span>
Wheelchair-compatible route
</div>
<div class="control">
<label class="control-label" for="maxSlope">
<span>Maximum route gradient</span>
<output id="maxSlopeOutput">8.0%</output>
</label>
<input id="maxSlope" type="range" min="4" max="12" step="0.5" value="8" />
</div>
<div class="control">
<label class="control-label" for="minWidth">
<span>Minimum clear width</span>
<output id="minWidthOutput">1.20 m</output>
</label>
<input id="minWidth" type="range" min="1" max="1.6" step="0.05" value="1.2" />
</div>
<div class="fixed-rule">
<span>Maximum cross slope</span>
<strong>2.0%</strong>
</div>
<div class="fixed-rule">
<span>Stairs or unverified surfaces</span>
<strong>Excluded</strong>
</div>
</div>
<div class="presets" aria-label="Constraint presets">
<button class="preset" type="button" data-preset="typical" aria-pressed="true">
Typical
</button>
<button class="preset" type="button" data-preset="conservative" aria-pressed="false">
Conservative
</button>
<button class="preset" type="button" data-preset="relaxed" aria-pressed="false">
Relaxed
</button>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Reachable stop areas</h2>
<span class="rule-chip">From West Gate</span>
</div>
<div class="reach-summary" aria-live="polite">
<div class="summary-card stairs">
<span class="number" id="stairsCount">0</span>
<span class="label">Stairs reachable</span>
</div>
<div class="summary-card wheel">
<span class="number" id="wheelCount">0</span>
<span class="label">Step-free reachable</span>
</div>
</div>
<div class="selected-card" id="selectedDetail"></div>
<div class="stops" id="stopsList"></div>
</section>
<div class="method-note">
<strong>Model note:</strong> Routes use the mapped neighborhood graph and
the constraints shown above. A missing route means no mapped connection
satisfies every rule. Elevators and lifts are not present in this scenario.
</div>
</aside>
<section id="viewport" aria-label="Interactive three-dimensional neighborhood map">
<div id="canvasHost"></div>
<div id="labels"></div>
<div class="map-top">
<div class="map-card">
<small>District 04</small>
<strong>Cedar Heights</strong>
</div>
<div class="map-card secondary">
<small>Origin</small>
<strong>West Gate · A01</strong>
</div>
</div>
<div class="map-tools">
<button class="tool-button" id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button class="tool-button" id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button class="tool-button" id="resetView" type="button" aria-label="Reset map view">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 12a8 8 0 1 0 2.34-5.66L4 8.68" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4 4v4.68h4.68" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
<div class="compass" id="compass" aria-hidden="true">N</div>
<div class="legend" aria-label="Map legend">
<div class="legend-item">
<span class="legend-line stairs"></span>
Stairs route
</div>
<div class="legend-item">
<span class="legend-line"></span>
Step-free route
</div>
<div class="legend-item">
<span class="legend-ring"></span>
Outside limits
</div>
</div>
<div class="origin-chip">
<span class="origin-icon"></span>
Start: West Gate
</div>
<div class="loading" id="loading">Building neighborhood model…</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const COLORS = {
ink: 0x19312e,
teal: 0x008f7a,
tealBright: 0x35c6a6,
orange: 0xe85f31,
orangeBright: 0xff9a75,
muted: 0x7b8782,
terrainLow: 0xd9d4c4,
terrainMid: 0xcfc8b7,
terrainHigh: 0xc1baa7,
road: 0x6f7b76,
ramp: 0xa8a99d,
wall: 0xefe9da
};
const viewport = $("#viewport");
const canvasHost = $("#canvasHost");
const labelsLayer = $("#labels");
// ---------------------------------------------------------------------
// Scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe8e3);
scene.fog = new THREE.Fog(0xdfe8e3, 72, 145);
const camera = new THREE.PerspectiveCamera(
42,
1,
0.1,
220
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel map of reachable bus stops in Cedar Heights"
);
renderer.domElement.tabIndex = 0;
canvasHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf7fff9, 0x7c7466, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d7, 3.2);
sun.position.set(-28, 48, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -48;
sun.shadow.camera.right = 48;
sun.shadow.camera.top = 40;
sun.shadow.camera.bottom = -40;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 120;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const staticGroup = new THREE.Group();
const routeGroup = new THREE.Group();
const haloGroup = new THREE.Group();
const markerGroup = new THREE.Group();
scene.add(staticGroup, routeGroup, haloGroup, markerGroup);
const world = new THREE.Group();
scene.add(world);
const nodeMap = new Map();
const edges = [];
const edgeMap = new Map();
const stopSignMaterials = new Map();
const pickables = [];
const labelElements = new Map();
let selectedStop = "market";
let visibleMode = "both";
let allResults = { stairs: new Map(), wheel: new Map() };
const constraints = {
maxRise: 8,
maxSteps: 28,
maxSlope: 8,
minWidth: 1.2
};
function addNode(id, x, y, z, label = "") {
const node = {
id,
label,
position: new THREE.Vector3(x, y, z),
adjacency: []
};
nodeMap.set(id, node);
return node;
}
function addEdge(
id,
a,
b,
kind = "smooth",
options = {}
) {
const nodeA = nodeMap.get(a);
const nodeB = nodeMap.get(b);
const p1 = nodeA.position;
const p2 = nodeB.position;
const delta = new THREE.Vector3().subVectors(p2, p1);
const horizontal = Math.hypot(delta.x, delta.z);
const length = delta.length();
const edge = {
id,
a,
b,
kind,
width: options.width ?? 2.6,
crossSlope: options.crossSlope ?? 0,
steps: options.steps ?? 0,
road: options.road ?? false,
length,
horizontal,
slope: horizontal > 0 ? (Math.abs(delta.y) / horizontal) * 100 : 0
};
edges.push(edge);
edgeMap.set(id, edge);
nodeA.adjacency.push({ edge, other: b });
nodeB.adjacency.push({ edge, other: a });
return edge;
}
// ---------------------------------------------------------------------
// Neighborhood graph
// ---------------------------------------------------------------------
addNode("gate", -24, 0.35, 14, "West Gate");
addNode("hub", -4, 0.35, 14, "Lower Junction");
addNode("market", 16, 0.35, 14, "Market Square");
addNode("stairFoot", 8, 0.35, 8, "Lower stair landing");
addNode("stairTop", 8, 4.35, 2, "Civic landing");
addNode("civic", 18, 4.35, 2, "Civic Hall");
addNode("upperFoot", -12, 4.35, 2, "Upper stair landing");
addNode("upperTop", -12, 8.35, -12, "Ridge landing");
addNode("ridge", 0, 8.35, -12, "Ridge View");
addNode("school", 24, 8.35, -12, "East School");
// Long, switchback ramp: each rising segment is about 6.1%.
addNode("ramp0", -14, 0.35, 18);
addNode("ramp1", -14, 0.35, 6);
addNode("ramp2", 2, 1.35, 6);
addNode("ramp3", 2, 2.35, 18);
addNode("ramp4", -14, 3.35, 18);
addNode("ramp5", -14, 4.35, 6);
addNode("ramp6", 2, 4.35, 6);
addEdge("gate-hub", "gate", "hub", "smooth", {
width: 3.0,
road: true
});
addEdge("hub-market", "hub", "market", "smooth", {
width: 3.0,
road: true
});
addEdge("hub-foot", "hub", "stairFoot", "smooth", {
width: 2.4,
road: true
});
addEdge("lower-stairs", "stairFoot", "stairTop", "stairs", {
width: 2.8,
steps: 24
});
addEdge("stair-civic", "stairTop", "civic", "smooth", {
width: 3.0,
road: true
});
addEdge("civic-upper", "stairTop", "upperFoot", "smooth", {
width: 2.8,
road: true
});
addEdge("upper-stairs", "upperFoot", "upperTop", "stairs", {
width: 2.8,
steps: 24
});
addEdge("ridge-road", "upperTop", "ridge", "smooth", {
width: 2.8,
road: true
});
addEdge("ridge-school", "ridge", "school", "smooth", {
width: 2.8,
road: true
});
addEdge("hub-ramp0", "hub", "ramp0", "smooth", {
width: 2.1
});
addEdge("ramp0-ramp1", "ramp0", "ramp1", "smooth", {
width: 1.6
});
addEdge("ramp1-ramp2", "ramp1", "ramp2", "smooth", {
width: 1.6,
crossSlope: 1
});
addEdge("ramp2-ramp3", "ramp2", "ramp3", "smooth", {
width: 1.6,
crossSlope: 1
});
addEdge("ramp3-ramp4", "ramp3", "ramp4", "smooth", {
width: 1.6,
crossSlope: 1
});
addEdge("ramp4-ramp5", "ramp4", "ramp5", "smooth", {
width: 1.6,
crossSlope: 1
});
addEdge("ramp5-ramp6", "ramp5", "ramp6", "smooth", {
width: 1.6
});
addEdge("ramp6-stairTop", "ramp6", "stairTop", "smooth", {
width: 1.6
});
addEdge("ramp6-civic", "ramp6", "civic", "smooth", {
width: 1.6
});
const stops = [
{
id: "gate",
node: "gate",
name: "West Gate",
code: "A01",
district: "Lower district",
labelOffset: 3.4
},
{
id: "market",
node: "market",
name: "Market Square",
code: "A02",
district: "Lower district",
labelOffset: 4.5
},
{
id: "civic",
node: "civic",
name: "Civic Hall",
code: "B01",
district: "Middle terrace",
labelOffset: 4.7
},
{
id: "ridge",
node: "ridge",
name: "Ridge View",
code: "C01",
district: "Upper terrace",
labelOffset: 4.8
},
{
id: "school",
node: "school",
name: "East School",
code: "C02",
district: "Upper terrace",
labelOffset: 4.8
}
];
// ---------------------------------------------------------------------
// Voxel construction helpers
// ---------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
function box(
width,
height,
depth,
x,
y,
z,
colorOrMaterial,
parent = staticGroup,
cast = true,
receive = true
) {
const mat =
colorOrMaterial instanceof THREE.Material
? colorOrMaterial
: material(colorOrMaterial);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addTerrain() {
const base = box(68, 1.2, 46, 0, -1.6, 0, 0x67736e, staticGroup, false, true);
box(66, 1, 16, 0, -0.5, 14, COLORS.terrainLow);
box(66, 4, 14, 0, 2, -1, COLORS.terrainMid);
box(66, 8, 14, 0, 4, -15, COLORS.terrainHigh);
// Voxel retaining blocks along district changes.
for (let x = -32; x <= 32; x += 4) {
box(3.8, 0.45, 0.55, x, 0.22, 6.05, 0xb5ad9b, staticGroup, false, true);
box(3.8, 0.45, 0.55, x, 4.22, -8.05, 0xaaa28f, staticGroup, false, true);
}
// Small district-edge cubes add scale without obscuring the route graph.
const edgeColors = [0xc8bca4, 0xb8ad98, 0xc1b49c];
for (let i = 0; i < 32; i++) {
const x = -31 + (i % 16) * 4.15;
const z = i < 16 ? -7.2 : -9.1;
const y = i < 16 ? 4.2 : 8.2;
box(
2.2 + (i % 3) * 0.3,
0.65 + (i % 2) * 0.25,
2.1,
x,
y,
z,
edgeColors[i % 3],
staticGroup,
true,
true
);
}
return base;
}
function createRibbon(edge, color, thickness = 0.22, parent = staticGroup) {
const a = nodeMap.get(edge.a).position;
const b = nodeMap.get(edge.b).position;
const dx = b.x - a.x;
const dz = b.z - a.z;
const h = Math.max(0.0001, Math.hypot(dx, dz));
const px = (-dz / h) * edge.width * 0.5;
const pz = (dx / h) * edge.width * 0.5;
const p1L = new THREE.Vector3(a.x + px, a.y, a.z + pz);
const p1R = new THREE.Vector3(a.x - px, a.y, a.z - pz);
const p2L = new THREE.Vector3(b.x + px, b.y, b.z + pz);
const p2R = new THREE.Vector3(b.x - px, b.y, b.z - pz);
const vertices = [];
const indices = [];
function pushBottom(p) {
vertices.push(p.x, p.y - thickness, p.z);
}
function pushTop(p) {
vertices.push(p.x, p.y, p.z);
}
pushTop(p1L);
pushTop(p1R);
pushTop(p2L);
pushTop(p2R);
pushBottom(p1L);
pushBottom(p1R);
pushBottom(p2L);
pushBottom(p2R);
indices.push(
0, 2, 1, 1, 2, 3,
4, 5, 6, 5, 7, 6,
0, 4, 2, 4, 6, 2,
1, 3, 5, 5, 3, 7,
0, 1, 4, 1, 5, 4,
2, 6, 3, 3, 6, 7
);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
material(color, { side: THREE.DoubleSide })
);
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addStairs(edge) {
const a = nodeMap.get(edge.a).position;
const b = nodeMap.get(edge.b).position;
const lower = a.y < b.y ? a : b;
const upper = a.y < b.y ? b : a;
const dx = upper.x - lower.x;
const dz = upper.z - lower.z;
const run = Math.hypot(dx, dz);
const rise = upper.y - lower.y;
const stepDepth = run / edge.steps;
const angle = Math.atan2(-dz, dx);
for (let i = 0; i < edge.steps; i++) {
const t = (i + 0.5) / edge.steps;
const top = lower.y + rise * ((i + 1) / edge.steps);
const bottom = lower.y - 0.28;
const height = Math.max(0.12, top - bottom);
const step = box(
edge.width,
height,
stepDepth + 0.045,
lower.x + dx * t,
bottom + height * 0.5,
lower.z + dz * t,
i % 2 === 0 ? 0xd3cec0 : 0xc8c2b2,
staticGroup,
true,
true
);
step.rotation.y = angle;
}
}
function addInfrastructure() {
for (const edge of edges) {
if (edge.kind === "stairs") {
addStairs(edge);
} else if (edge.road) {
createRibbon(edge, COLORS.road, 0.22);
} else {
createRibbon(edge, COLORS.ramp, 0.24);
}
}
// Ramp edge markers and low curbs make the compliant path legible.
for (const edge of edges) {
if (
edge.kind !== "smooth" ||
edge.road ||
edge.slope < 0.1
) continue;
const a = nodeMap.get(edge.a).position;
const b = nodeMap.get(edge.b).position;
const count = Math.max(3, Math.floor(edge.length / 3.4));
for (let i = 0; i <= count; i++) {
const t = i / count;
const p = a.clone().lerp(b, t);
const side = new THREE.Vector3(
-(b.z - a.z),
0,
b.x - a.x
).normalize();
for (const sign of [-1, 1]) {
const q = p.clone().addScaledVector(side, sign * edge.width * 0.52);
box(
0.16,
0.42,
0.16,
q.x,
q.y + 0.18,
q.z,
0xe9e3d4,
staticGroup,
true,
true
);
}
}
}
}
function addBuilding(x, z, w, d, h, ground, color, roofColor) {
const group = new THREE.Group();
group.position.set(x, ground, z);
staticGroup.add(group);
box(w, h, d, 0, h / 2, 0, color, group, true, true);
box(w + 0.35, 0.48, d + 0.35, 0, h + 0.18, 0, roofColor, group, true, true);
// Stepped upper volume.
if (w > 4.5 && d > 4 && h > 4.5) {
box(
w * 0.42,
1.3,
d * 0.5,
w * 0.16,
h + 0.95,
-d * 0.12,
color,
group,
true,
true
);
}
// Window strips.
const windowMaterial = material(0x526762, {
roughness: 0.36,
metalness: 0.05
});
const count = Math.max(2, Math.floor(w / 1.7));
for (let i = 0; i < count; i++) {
const wx = -w / 2 + 0.8 + i * ((w - 1.6) / Math.max(1, count - 1));
box(
0.58,
0.72,
0.07,
wx,
h * 0.58,
d / 2 + 0.045,
windowMaterial,
group,
false,
false
);
}
}
function addTree(x, z, ground, size = 1) {
const group = new THREE.Group();
group.position.set(x, ground, z);
group.scale.setScalar(size);
staticGroup.add(group);
box(0.42, 1.8, 0.42, 0, 0.9, 0, 0x776a54, group, true, true);
box(2.2, 1.65, 2.2, 0, 2.35, 0, 0x66856d, group, true, true);
box(1.65, 1.45, 1.65, 0.25, 3.15, -0.15, 0x78977b, group, true, true);
box(1.1, 1.05, 1.1, -0.15, 3.85, 0.1, 0x8aa287, group, true, true);
}
function addDetails() {
const lowerBuildings = [
[-27, 9.7, 4.4, 4.8, 4.2, 0xe7d2b8, 0xa7654f],
[-18, 9.8, 5.2, 4.5, 5.4, 0xd9dfcf, 0x72867a],
[-7.5, 9.6, 4.8, 4.6, 4.8, 0xe8dec8, 0xb57556],
[4, 10.2, 4.8, 5.2, 6.3, 0xcfdad9, 0x687f82],
[14.5, 9.6, 5.5, 4.8, 4.7, 0xeadbc4, 0x9c654e],
[25.5, 10.4, 4.4, 4.8, 5.7, 0xd9d1ba, 0x6c806e],
[-23, 19.3, 4.6, 3.4, 3.5, 0xd9e0d0, 0x8e725a],
[-10, 19.4, 5.1, 3.8, 4.1, 0xe5cfb2, 0x8d604d],
[7, 19.6, 4.5, 3.6, 3.7, 0xcbd8d3, 0x607a76],
[22, 19.4, 5.3, 3.7, 4.4, 0xe5d9c1, 0xa16d53]
];
const middleBuildings = [
[-27, -4.3, 5.3, 4.8, 5.1, 0xe3d5bd, 0x8f654e],
[-16.5, -4.5, 4.7, 4.8, 6.4, 0xd5dfd1, 0x6f8475],
[-4.5, -4.7, 5.4, 4.7, 4.4, 0xe8d4b7, 0x9d6249],
[7.5, -4.7, 4.8, 4.6, 5.8, 0xd3ddda, 0x607c7b],
[27, -4.1, 4.7, 4.9, 4.6, 0xe8dcc4, 0x9a765b]
];
const upperBuildings = [
[-27, -18.4, 5.1, 4.7, 5.3, 0xe3d5bd, 0x8d6652],
[-17, -18.6, 4.5, 4.6, 4.2, 0xd4dfd2, 0x668078],
[-5, -18.4, 5.3, 4.8, 6.2, 0xe8d3b6, 0xa1654d],
[8.5, -18.5, 5.1, 4.6, 4.8, 0xccd9d5, 0x607a78],
[19, -18.6, 4.9, 4.7, 5.8, 0xe4d6bd, 0x94705b]
];
for (const b of lowerBuildings) addBuilding(...b, 0);
for (const b of middleBuildings) addBuilding(...b, 4);
for (const b of upperBuildings) addBuilding(...b, 8);
const lowerTrees = [
[-30, 12.2], [-21, 12.1], [-12.5, 11.8], [-1, 12.4],
[9.8, 12.1], [21.3, 12.6], [30, 12.8],
[-29, 16.8], [-18, 16.7], [-6.5, 16.8], [4.8, 16.9], [18.5, 16.6],
[-14, 21.3], [-3, 21.2], [14.5, 21.4], [29, 16.7]
];
const middleTrees = [
[-30, 1], [-20, 4.8], [-10, 4.8], [0, 4.8],
[11, 4.8], [23, 0.8], [29, -5.8]
];
const upperTrees = [
[-30, -14.2], [-20, -14.2], [-9, -14.1], [3, -14.2],
[15, -14.1], [29, -14.1], [-22, -21], [-2, -21], [16, -21]
];
for (const [x, z] of lowerTrees) {
addTree(x, z, 0, 0.75 + ((x + z) % 3) * 0.08);
}
for (const [x, z] of middleTrees) {
addTree(x, z, 4, 0.72 + ((x + z) % 4) * 0.07);
}
for (const [x, z] of upperTrees) {
addTree(x, z, 8, 0.7 + ((x + z) % 3) * 0.08);
}
// Tiny street trees and bollards establish the voxel scale.
for (let i = 0; i < 12; i++) {
const x = -22 + i * 3.7;
box(0.28, 0.72, 0.28, x, 0.36, 11.8, 0x546b62, staticGroup, true, true);
box(0.28, 0.72, 0.28, x, 4.36, 3.35, 0x546b62, staticGroup, true, true);
}
}
function addBusStop(stop) {
const p = nodeMap.get(stop.node).position;
const group = new THREE.Group();
group.position.copy(p);
markerGroup.add(group);
// Shelter.
box(0.22, 2.4, 0.22, -1.25, 1.2, 0.65, 0x344f49, group, true, true);
box(0.22, 2.4, 0.22, 1.25, 1.2, 0.65, 0x344f49, group, true, true);
box(3.1, 0.25, 1.75, 0, 2.48, 0.38, 0x405d55, group, true, true);
box(2.65, 0.18, 0.65, 0, 0.76, 0.42, 0x967b57, group, true, true);
// Dynamic status sign.
const signMaterial = material(COLORS.muted, {
roughness: 0.45
});
const sign = box(
0.9,
0.75,
0.18,
-2.0,
1.85,
0,
signMaterial,
group,
true,
false
);
stopSignMaterials.set(stop.id, sign.material);
// Invisible but raycastable target.
const target = new THREE.Mesh(
new THREE.SphereGeometry(1.25, 12, 8),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
target.position.set(0, 1.4, 0);
target.userData.stopId = stop.id;
group.add(target);
pickables.push(target);
// HTML label.
const label = document.createElement("button");
label.type = "button";
label.className = "map-label";
label.dataset.stop = stop.id;
label.innerHTML = `
<span class="label-dot"></span>
<span>${stop.name}</span>
`;
label.addEventListener("click", () => selectStop(stop.id));
labelsLayer.appendChild(label);
labelElements.set(stop.id, label);
}
addTerrain();
addInfrastructure();
addDetails();
stops.forEach(addBusStop);
// ---------------------------------------------------------------------
// Constraint-aware route calculation
// ---------------------------------------------------------------------
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].distance <= item.distance) break;
this.items[i] = this.items[parent];
i = parent;
}
this.items[i] = item;
}
pop() {
if (!this.items.length) return null;
const root = this.items[0];
const last = this.items.pop();
if (this.items.length) {
let i = 0;
while (true) {
const left = i * 2 + 1;
const right = left + 1;
if (left >= this.items.length) break;
let child = left;
if (
right < this.items.length &&
this.items[right].distance < this.items[left].distance
) {
child = right;
}
if (this.items[child].distance >= last.distance) break;
this.items[i] = this.items[child];
i = child;
}
this.items[i] = last;
}
return root;
}
get size() {
return this.items.length;
}
}
function routeStats(pathEdges, mode) {
const stats = {
distance: 0,
totalRise: 0,
maxSteps: 0,
maxSlope: 0,
minWidth: Infinity,
maxCrossSlope: 0,
usesStairs: false
};
for (const edge of pathEdges) {
const a = nodeMap.get(edge.a).position;
const b = nodeMap.get(edge.b).position;
stats.distance += edge.length;
stats.totalRise += Math.max(0, b.y - a.y);
stats.maxSlope = Math.max(stats.maxSlope, edge.slope);
stats.minWidth = Math.min(stats.minWidth, edge.width);
stats.maxCrossSlope = Math.max(stats.maxCrossSlope, edge.crossSlope);
if (edge.kind === "stairs") {
stats.usesStairs = true;
stats.maxSteps = Math.max(stats.maxSteps, edge.steps);
}
}
if (!Number.isFinite(stats.minWidth)) stats.minWidth = 0;
return stats;
}
function calculateRoutes(mode) {
const queue = new MinHeap();
const visited = new Set();
const results = new Map();
queue.push({
node: "gate",
distance: 0,
rise: 0,
pathNodes: ["gate"],
pathEdges: []
});
while (queue.size) {
const current = queue.pop();
const key = `${current.node}|${current.rise.toFixed(4)}`;
if (visited.has(key)) continue;
visited.add(key);
const node = nodeMap.get(current.node);
for (const connection of node.adjacency) {
const edge = connection.edge;
const other = connection.other;
const otherNode = nodeMap.get(other);
let nextRise = current.rise;
if (mode === "stairs") {
if (edge.kind === "stairs" && edge.steps > constraints.maxSteps) {
continue;
}
nextRise += Math.max(
0,
otherNode.position.y - node.position.y
);
if (nextRise > constraints.maxRise + 0.0001) {
continue;
}
} else {
if (edge.kind !== "smooth") continue;
if (edge.slope > constraints.maxSlope + 0.0001) continue;
if (edge.width + 0.0001 < constraints.minWidth) continue;
if (edge.crossSlope > 2 + 0.0001) continue;
}
const nextDistance = current.distance + edge.length;
const nextKey = `${other}|${nextRise.toFixed(4)}`;
if (visited.has(nextKey)) continue;
queue.push({
node: other,
distance: nextDistance,
rise: nextRise,
pathNodes: [...current.pathNodes, other],
pathEdges: [...current.pathEdges, edge]
});
}
}
for (const stop of stops) {
const match = queue.items.find(
(item) => item.node === stop.node
);
// The heap no longer exposes popped entries, so calculate each stop
// using a dedicated state search.
const dedicated = findRouteTo(mode, stop.node);
if (dedicated) {
results.set(stop.id, {
stopId: stop.id,
nodes: dedicated.pathNodes,
edges: dedicated.pathEdges,
stats: routeStats(dedicated.pathEdges, mode)
});
}
}
return results;
}
function findRouteTo(mode, targetNode) {
const queue = new MinHeap();
const visited = new Set();
queue.push({
node: "gate",
distance: 0,
rise: 0,
pathNodes: ["gate"],
pathEdges: []
});
while (queue.size) {
const current = queue.pop();
const key = `${current.node}|${current.rise.toFixed(4)}`;
if (visited.has(key)) continue;
visited.add(key);
if (current.node === targetNode) return current;
const node = nodeMap.get(current.node);
for (const connection of node.adjacency) {
const edge = connection.edge;
const other = connection.other;
const otherNode = nodeMap.get(other);
let nextRise = current.rise;
if (mode === "stairs") {
if (edge.kind === "stairs" && edge.steps > constraints.maxSteps) {
continue;
}
nextRise += Math.max(
0,
otherNode.position.y - node.position.y
);
if (nextRise > constraints.maxRise + 0.0001) continue;
} else {
if (edge.kind !== "smooth") continue;
if (edge.slope > constraints.maxSlope + 0.0001) continue;
if (edge.width + 0.0001 < constraints.minWidth) continue;
if (edge.crossSlope > 2 + 0.0001) continue;
}
const nextKey = `${other}|${nextRise.toFixed(4)}`;
if (visited.has(nextKey)) continue;
queue.push({
node: other,
distance: current.distance + edge.length,
rise: nextRise,
pathNodes: [...current.pathNodes, other],
pathEdges: [...current.pathEdges, edge]
});
}
}
return null;
}
// ---------------------------------------------------------------------
// Dynamic route visuals
// ---------------------------------------------------------------------
function clearGroup(group) {
const geometries = new Set();
const materials = new Set();
group.traverse((child) => {
if (child.geometry) geometries.add(child.geometry);
if (child.material) {
if (Array.isArray(child.material)) {
child.material.forEach((m) => materials.add(m));
} else {
materials.add(child.material);
}
}
});
geometries.forEach((g) => g.dispose());
materials.forEach((m) => m.dispose());
group.clear();
}
function createRouteSegment(a, b, radius, color, opacity = 1) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
if (length < 0.001) return;
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
new THREE.MeshBasicMaterial({
color,
transparent: opacity < 1,
opacity,
depthWrite: false
})
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.renderOrder = 8;
routeGroup.add(mesh);
}
function renderModeRoutes(mode) {
const result = allResults[mode];
const edgeIds = new Set();
for (const route of result.values()) {
for (const edge of route.edges) edgeIds.add(edge.id);
}
const offset = mode === "stairs" ? 0.18 : 0.34;
const color = mode === "stairs" ? COLORS.orangeBright : COLORS.tealBright;
const radius = mode === "stairs" ? 0.13 : 0.15;
for (const edge of edges) {
if (!edgeIds.has(edge.id)) continue;
const a = nodeMap.get(edge.a).position.clone();
const b = nodeMap.get(edge.b).position.clone();
a.y += offset;
b.y += offset;
if (mode === "stairs" && edge.kind === "stairs") {
const dashCount = 12;
const dashLength = edge.length / dashCount * 0.55;
const direction = new THREE.Vector3().subVectors(b, a);
for (let i = 0; i < dashCount; i++) {
const start = a.clone().lerp(b, i / dashCount);
const end = a
.clone()
.lerp(b, i / dashCount)
.addScaledVector(direction.clone().normalize(), dashLength);
createRouteSegment(start, end, radius, color);
}
} else {
createRouteSegment(a, b, radius, color);
}
}
// Small junction nodes keep the mapped path continuous.
for (const edgeId of edgeIds) {
const edge = edgeMap.get(edgeId);
for (const nodeId of [edge.a, edge.b]) {
const p = nodeMap.get(nodeId).position;
const dot = new THREE.Mesh(
new THREE.SphereGeometry(radius * 1.5, 10, 8),
new THREE.MeshBasicMaterial({
color,
depthWrite: false
})
);
dot.position.set(p.x, p.y + offset, p.z);
dot.renderOrder = 9;
routeGroup.add(dot);
}
}
}
function renderHalos() {
clearGroup(haloGroup);
for (const stop of stops) {
const p = nodeMap.get(stop.node).position;
const stairReachable = allResults.stairs.has(stop.id);
const wheelReachable = allResults.wheel.has(stop.id);
const addRing = (color, start, length, yOffset) => {
const geometry = new THREE.RingGeometry(
1.45,
1.85,
40,
1,
start,
length
);
const ring = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.88,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(p.x, p.y + yOffset, p.z);
ring.renderOrder = 5;
haloGroup.add(ring);
};
if (stairReachable && wheelReachable) {
addRing(COLORS.orange, -Math.PI / 2, Math.PI, 0.04);
addRing(COLORS.teal, Math.PI / 2, Math.PI, 0.07);
} else if (stairReachable) {
addRing(COLORS.orange, 0, Math.PI * 2, 0.05);
} else if (wheelReachable) {
addRing(COLORS.teal, 0, Math.PI * 2, 0.05);
} else {
addRing(COLORS.muted, 0, Math.PI * 2, 0.04);
}
}
}
function updateRouteVisuals() {
clearGroup(routeGroup);
if (visibleMode === "both" || visibleMode === "stairs") {
renderModeRoutes("stairs");
}
if (visibleMode === "both" || visibleMode === "wheel") {
renderModeRoutes("wheel");
}
renderHalos();
for (const stop of stops) {
const stairReachable = allResults.stairs.has(stop.id);
const wheelReachable = allResults.wheel.has(stop.id);
const signMaterial = stopSignMaterials.get(stop.id);
signMaterial.color.setHex(
stairReachable && wheelReachable
? 0x37ad92
: stairReachable
? COLORS.orange
: wheelReachable
? COLORS.teal
: COLORS.muted
);
const label = labelElements.get(stop.id);
label.classList.toggle("stairs", stairReachable);
label.classList.toggle(
"wheel",
wheelReachable && !stairReachable
);
}
}
// ---------------------------------------------------------------------
// Interface
// ---------------------------------------------------------------------
function formatDistance(value) {
return `${Math.round(value)} m`;
}
function describeStairs(route) {
if (!route) {
return `No path meets the ${constraints.maxRise.toFixed(1)} m climb and ${constraints.maxSteps}-step flight limits.`;
}
const s = route.stats;
if (!s.usesStairs) {
return `Level street connection · ${formatDistance(s.distance)}`;
}
return `${formatDistance(s.distance)} · ${s.totalRise.toFixed(1)} m climb · ${s.maxSteps}-step flight`;
}
function describeWheel(route) {
if (!route) {
return `No compliant path at ${constraints.maxSlope.toFixed(1)}% / ${constraints.minWidth.toFixed(2)} m.`;
}
const s = route.stats;
return `${formatDistance(s.distance)} · max ${s.maxSlope.toFixed(1)}% · ${s.minWidth.toFixed(2)} m wide`;
}
function updateSelectedDetail() {
const stop = stops.find((item) => item.id === selectedStop);
const stairsRoute = allResults.stairs.get(stop.id);
const wheelRoute = allResults.wheel.get(stop.id);
$("#selectedDetail").innerHTML = `
<div class="selected-top">
<div>
<strong>${stop.name}</strong>
<small>${stop.district}</small>
</div>
<span class="selected-code">${stop.code}</span>
</div>
<div class="selected-route stairs">
<span>Stairs</span>
<span>${describeStairs(stairsRoute)}</span>
</div>
<div class="selected-route wheel">
<span>Step-free</span>
<span>${describeWheel(wheelRoute)}</span>
</div>
`;
}
function updateStopList() {
const list = $("#stopsList");
list.innerHTML = stops
.map((stop) => {
const stairsReachable = allResults.stairs.has(stop.id);
const wheelReachable = allResults.wheel.has(stop.id);
const stairClass = stairsReachable ? "ok stairs" : "no";
const wheelClass = wheelReachable ? "ok wheel" : "no";
const pinClass = stairsReachable
? "stairs"
: wheelReachable
? "wheel"
: "";
return `
<button
class="stop-card"
type="button"
data-stop="${stop.id}"
aria-current="${stop.id === selectedStop}"
>
<span class="stop-name">
<span class="stop-pin ${pinClass}"></span>
<span class="stop-copy">
<strong>${stop.name}</strong>
<small>${stop.code} · ${stop.district}</small>
</span>
</span>
<span class="badges" aria-label="
Stairs ${stairsReachable ? "reachable" : "blocked"},
step-free ${wheelReachable ? "reachable" : "blocked"}
">
<span class="badge ${stairClass}">STAIR</span>
<span class="badge ${wheelClass}">FREE</span>
</span>
</button>
`;
})
.join("");
$("#stairsCount").textContent = allResults.stairs.size;
$("#wheelCount").textContent = allResults.wheel.size;
updateSelectedDetail();
}
function selectStop(id) {
selectedStop = id;
updateStopList();
$$(".map-label").forEach((label) => {
label.setAttribute(
"aria-current",
label.dataset.stop === selectedStop ? "true" : "false"
);
});
}
function updateConstraintOutputs() {
$("#maxRiseOutput").textContent = `${constraints.maxRise.toFixed(1)} m`;
$("#maxStepsOutput").textContent = `${constraints.maxSteps} steps`;
$("#maxSlopeOutput").textContent = `${constraints.maxSlope.toFixed(1)}%`;
$("#minWidthOutput").textContent = `${constraints.minWidth.toFixed(2)} m`;
}
function recompute() {
updateConstraintOutputs();
allResults = {
stairs: calculateRoutes("stairs"),
wheel: calculateRoutes("wheel")
};
updateRouteVisuals();
updateStopList();
}
$("#stopsList").addEventListener("click", (event) => {
const card = event.target.closest("[data-stop]");
if (card) selectStop(card.dataset.stop);
});
$$("[data-mode]").forEach((button) => {
button.addEventListener("click", () => {
visibleMode = button.dataset.mode;
$$("[data-mode]").forEach((item) => {
item.setAttribute(
"aria-pressed",
item.dataset.mode === visibleMode ? "true" : "false"
);
});
updateRouteVisuals();
});
});
[
["maxRise", "maxRise"],
["maxSteps", "maxSteps"],
["maxSlope", "maxSlope"],
["minWidth", "minWidth"]
].forEach(([id, key]) => {
$(`#${id}`).addEventListener("input", (event) => {
constraints[key] = Number(event.target.value);
$$("[data-preset]").forEach((p) => p.setAttribute("aria-pressed", "false"));
recompute();
});
});
const presets = {
typical: {
maxRise: 8,
maxSteps: 28,
maxSlope: 8,
minWidth: 1.2
},
conservative: {
maxRise: 6,
maxSteps: 20,
maxSlope: 6,
minWidth: 1.4
},
relaxed: {
maxRise: 12,
maxSteps: 32,
maxSlope: 10,
minWidth: 1.0
}
};
$$("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const values = presets[button.dataset.preset];
Object.assign(constraints, values);
for (const key of Object.keys(values)) {
$(`#${key}`).value = values[key];
}
$$("[data-preset]").forEach((item) => {
item.setAttribute(
"aria-pressed",
item === button ? "true" : "false"
);
});
recompute();
});
});
$("#exportButton").addEventListener("click", () => {
const rows = [
["Stop", "Code", "Stairs route", "Step-free route"]
];
for (const stop of stops) {
const stairs = allResults.stairs.get(stop.id);
const wheel = allResults.wheel.get(stop.id);
rows.push([
stop.name,
stop.code,
stairs ? describeStairs(stairs) : "Blocked by constraints",
wheel ? describeWheel(wheel) : "Blocked by constraints"
]);
}
const csv = rows
.map((row) =>
row.map((value) => `"${String(value).replaceAll('"', '""')}"`).join(",")
)
.join("\n");
const blob = new Blob([csv], { type: "text/csv;charset=utf-8" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "hillside-reach-summary.csv";
link.click();
URL.revokeObjectURL(url);
});
// ---------------------------------------------------------------------
// Custom orbit / pan / zoom controls (no external controls addon)
// ---------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 3.1, 0),
desiredTarget: new THREE.Vector3(0, 3.1, 0),
theta: 0.69,
desiredTheta: 0.69,
phi: 0.82,
desiredPhi: 0.82,
radius: 82,
desiredRadius: 82
};
const pointerState = {
active: false,
pointerId: null,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
moved: false,
button: 0
};
function updateCamera() {
orbit.theta += (orbit.desiredTheta - orbit.theta) * 0.12;
orbit.phi += (orbit.desiredPhi - orbit.phi) * 0.12;
orbit.radius += (orbit.desiredRadius - orbit.radius) * 0.12;
orbit.target.lerp(orbit.desiredTarget, 0.12);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
$("#compass").style.transform = `rotate(${-orbit.theta * 180 / Math.PI}deg)`;
}
function panCamera(dx, dy) {
const right = new THREE.Vector3(
Math.cos(orbit.theta),
0,
-Math.sin(orbit.theta)
);
const forward = new THREE.Vector3(
-Math.sin(orbit.theta),
0,
-Math.cos(orbit.theta)
);
const scale = orbit.radius * 0.0013;
orbit.desiredTarget.addScaledVector(right, -dx * scale);
orbit.desiredTarget.addScaledVector(forward, dy * scale);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (pointerState.active) return;
pointerState.active = true;
pointerState.pointerId = event.pointerId;
pointerState.startX = event.clientX;
pointerState.startY = event.clientY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
pointerState.moved = false;
pointerState.button = event.button;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState.active || event.pointerId !== pointerState.pointerId) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
const totalX = event.clientX - pointerState.startX;
const totalY = event.clientY - pointerState.startY;
if (Math.abs(totalX) + Math.abs(totalY) > 4) {
pointerState.moved = true;
}
if (pointerState.button === 2 || event.shiftKey) {
panCamera(dx, dy);
} else {
orbit.desiredTheta -= dx * 0.006;
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi - dy * 0.005,
0.35,
1.35
);
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerState.active) return;
if (!pointerState.moved && pointerState.button === 0) {
const rect = renderer.domElement.getBoundingClientRect();
const mouse = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
selectStop(hits[0].object.userData.stopId);
}
}
pointerState.active = false;
pointerState.pointerId = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.active = false;
pointerState.pointerId = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius + event.deltaY * 0.055,
31,
125
);
},
{ passive: false }
);
function resetView() {
orbit.desiredTarget.set(0, 3.1, 0);
orbit.desiredTheta = 0.69;
orbit.desiredPhi = 0.82;
orbit.desiredRadius = 82;
}
$("#zoomIn").addEventListener("click", () => {
orbit.desiredRadius = Math.max(31, orbit.desiredRadius - 8);
});
$("#zoomOut").addEventListener("click", () => {
orbit.desiredRadius = Math.min(125, orbit.desiredRadius + 8);
});
$("#resetView").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (["INPUT", "TEXTAREA", "SELECT"].includes(tag)) return;
if (event.key === "+" || event.key === "=") {
orbit.desiredRadius = Math.max(31, orbit.desiredRadius - 6);
}
if (event.key === "-" || event.key === "_") {
orbit.desiredRadius = Math.min(125, orbit.desiredRadius + 6);
}
if (event.key.toLowerCase() === "r") resetView();
});
// ---------------------------------------------------------------------
// Resize, labels, and animation
// ---------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
const projected = new THREE.Vector3();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const stop of stops) {
const label = labelElements.get(stop.id);
const p = nodeMap.get(stop.node).position;
projected.set(p.x, p.y + stop.labelOffset, p.z).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
label.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.style.left = `${x}px`;
label.style.top = `${y}px`;
}
}
}
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
recompute();
selectStop("market");
updateCamera();
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```