Prompt specification
Build or customize the Three.js 3D scene "Civic building route comparison" 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: Civic building route comparison
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/civic-building-route-comparison-x0460
Scene Description Prompt:
Compare low-poly public-building routes to the same destination by distance, slope, and obstacles. Use illustrative accessibility indicators. Three.js from cdnjs, one HTML file.
Working Three.js Starter (civic-building-route-comparison-x0460):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CivicPath — Accessible Route Comparison</title>
<style>
:root {
--paper: #f5f1e8;
--panel: #fbf8f1;
--ink: #20342f;
--muted: #718078;
--line: #ded8cc;
--green: #147d6c;
--green-soft: #dcece6;
--shadow: 0 14px 40px rgba(40, 53, 47, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
-webkit-font-smoothing: antialiased;
}
button {
font: inherit;
}
.topbar {
height: 72px;
padding: 0 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
background: rgba(251, 248, 241, 0.96);
border-bottom: 1px solid var(--line);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
flex: 0 0 auto;
display: grid;
place-items: center;
color: white;
background: var(--green);
border-radius: 12px;
box-shadow: 0 7px 18px rgba(20, 125, 108, 0.23);
}
.brand-mark svg {
width: 24px;
height: 24px;
}
.brand-name {
font-size: 17px;
font-weight: 780;
letter-spacing: -0.02em;
}
.brand-subtitle {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.header-actions {
display: flex;
align-items: center;
gap: 12px;
}
.demo-badge {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
color: #56665f;
background: #efebe2;
border: 1px solid #e1dbd0;
border-radius: 999px;
font-size: 12px;
font-weight: 650;
white-space: nowrap;
}
.demo-badge::before {
content: "";
width: 7px;
height: 7px;
background: #e5a846;
border-radius: 50%;
}
.destination-chip {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
background: white;
border: 1px solid var(--line);
border-radius: 12px;
font-size: 12px;
font-weight: 680;
white-space: nowrap;
}
.destination-chip svg {
width: 18px;
height: 18px;
color: var(--green);
}
.app-shell {
height: calc(100vh - 72px);
display: grid;
grid-template-columns: 370px minmax(0, 1fr);
}
.sidebar {
min-width: 0;
padding: 25px 22px 28px;
overflow-y: auto;
background: var(--panel);
border-right: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #c8c0b2 transparent;
}
.eyebrow {
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 9px;
max-width: 320px;
font-size: 29px;
line-height: 1.08;
letter-spacing: -0.045em;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.destination-card {
margin: 20px 0 23px;
padding: 14px;
display: flex;
align-items: center;
gap: 12px;
background: #f0ece3;
border: 1px solid #e2dcd0;
border-radius: 15px;
}
.destination-icon {
width: 42px;
height: 42px;
flex: 0 0 auto;
display: grid;
place-items: center;
color: #74542f;
background: #e4d4b8;
border-radius: 12px;
}
.destination-icon svg {
width: 23px;
height: 23px;
}
.destination-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.destination-name {
margin-top: 3px;
font-size: 14px;
font-weight: 760;
}
.section-heading {
margin: 0 0 11px;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-heading span:last-child {
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0;
text-transform: none;
}
.route-list {
display: grid;
gap: 10px;
}
.route-card {
--route: #147d6c;
width: 100%;
position: relative;
padding: 15px 15px 13px 18px;
display: block;
overflow: hidden;
color: inherit;
text-align: left;
background: rgba(255, 255, 255, 0.72);
border: 1px solid var(--line);
border-radius: 16px;
cursor: pointer;
transition:
border-color 160ms ease,
box-shadow 160ms ease,
transform 160ms ease,
background 160ms ease;
}
.route-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--route);
opacity: 0.72;
}
.route-card:hover {
transform: translateY(-1px);
border-color: #c9c1b4;
box-shadow: 0 8px 22px rgba(47, 58, 53, 0.08);
}
.route-card:focus-visible {
outline: 3px solid rgba(20, 125, 108, 0.25);
outline-offset: 2px;
}
.route-card.selected {
background: white;
border-color: var(--route);
box-shadow: var(--shadow);
}
.route-card.selected::before {
opacity: 1;
}
.route-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 8px;
}
.route-title-wrap {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
}
.route-swatch {
width: 11px;
height: 11px;
flex: 0 0 auto;
background: var(--route);
border-radius: 50%;
box-shadow: 0 0 0 4px color-mix(in srgb, var(--route) 13%, transparent);
}
.route-name {
font-size: 14px;
font-weight: 790;
letter-spacing: -0.015em;
}
.route-subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
.route-tag {
padding: 4px 7px;
flex: 0 0 auto;
color: var(--route);
background: color-mix(in srgb, var(--route) 9%, white);
border-radius: 7px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.mini-metrics {
margin: 14px 0 12px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.mini-metric {
padding-right: 8px;
border-right: 1px solid #e6e0d6;
}
.mini-metric:last-child {
padding-right: 0;
border-right: 0;
}
.mini-label {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.mini-value {
display: block;
margin-top: 4px;
font-size: 14px;
font-weight: 780;
letter-spacing: -0.02em;
}
.access-row {
padding-top: 10px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
border-top: 1px solid #ebe5dc;
}
.access-copy {
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.access-dots {
display: flex;
gap: 3px;
}
.access-dot {
width: 14px;
height: 5px;
background: #e6e0d6;
border-radius: 999px;
}
.access-dot.filled {
background: var(--route);
}
.comparison {
margin-top: 24px;
}
.comparison-table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
.comparison-table th {
padding: 7px 3px;
color: var(--muted);
text-align: right;
font-weight: 700;
}
.comparison-table th:first-child,
.comparison-table td:first-child {
text-align: left;
}
.comparison-table td {
padding: 9px 3px;
text-align: right;
border-top: 1px solid #e7e1d7;
font-variant-numeric: tabular-nums;
}
.comparison-table .table-route {
font-weight: 760;
white-space: nowrap;
}
.table-dot {
width: 7px;
height: 7px;
margin-right: 5px;
display: inline-block;
border-radius: 50%;
}
.note-card {
margin-top: 18px;
padding: 13px 14px;
display: flex;
align-items: flex-start;
gap: 10px;
color: #59675f;
background: #eef2ec;
border: 1px solid #dce5dc;
border-radius: 13px;
font-size: 10px;
line-height: 1.5;
}
.note-card svg {
width: 17px;
height: 17px;
flex: 0 0 auto;
margin-top: 1px;
color: var(--green);
}
.scene {
min-width: 0;
min-height: 0;
position: relative;
overflow: hidden;
background: #e8e0cf;
}
#canvasHost,
#mapLabels {
position: absolute;
inset: 0;
}
#canvasHost canvas {
width: 100%;
height: 100%;
display: block;
outline: none;
cursor: grab;
touch-action: none;
}
#canvasHost canvas:active {
cursor: grabbing;
}
#mapLabels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
left: 0;
top: 0;
padding: 6px 9px;
color: #33443e;
background: rgba(255, 255, 255, 0.91);
border: 1px solid rgba(207, 201, 188, 0.9);
border-radius: 8px;
box-shadow: 0 5px 15px rgba(43, 54, 49, 0.12);
font-size: 10px;
font-weight: 760;
white-space: nowrap;
will-change: transform;
}
.map-label.destination {
padding: 7px 10px;
color: #654b2d;
background: rgba(255, 248, 232, 0.95);
border-color: rgba(198, 163, 110, 0.65);
}
.map-label.obstacle {
padding: 4px 7px;
color: #7b4d0d;
background: rgba(255, 244, 214, 0.95);
border-color: rgba(213, 155, 53, 0.55);
font-size: 9px;
}
.map-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
background: inherit;
border-right: 1px solid inherit;
border-bottom: 1px solid inherit;
transform: translateX(-50%) rotate(45deg);
}
.map-label.obstacle::after {
display: none;
}
.map-top-left {
position: absolute;
z-index: 4;
top: 22px;
left: 22px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: none;
}
.map-pill {
padding: 9px 12px;
display: flex;
align-items: center;
gap: 8px;
color: #4a5b54;
background: rgba(255, 255, 255, 0.9);
border: 1px solid rgba(210, 204, 191, 0.9);
border-radius: 11px;
box-shadow: 0 7px 20px rgba(54, 61, 57, 0.09);
font-size: 11px;
font-weight: 720;
backdrop-filter: blur(8px);
}
.map-pill svg {
width: 16px;
height: 16px;
color: var(--green);
}
.map-controls {
position: absolute;
z-index: 5;
top: 22px;
right: 22px;
display: flex;
gap: 6px;
}
.control-group {
padding: 4px;
display: flex;
gap: 3px;
background: rgba(255, 255, 255, 0.92);
border: 1px solid rgba(210, 204, 191, 0.9);
border-radius: 11px;
box-shadow: 0 7px 20px rgba(54, 61, 57, 0.09);
backdrop-filter: blur(8px);
}
.control-btn {
height: 32px;
padding: 0 10px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
color: #53635c;
background: transparent;
border: 0;
border-radius: 8px;
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.control-btn:hover {
color: var(--ink);
background: #eeeae1;
}
.control-btn.active {
color: white;
background: var(--green);
}
.control-btn.icon-only {
width: 32px;
padding: 0;
}
.control-btn svg {
width: 15px;
height: 15px;
}
.map-hint {
position: absolute;
z-index: 4;
left: 22px;
bottom: 24px;
padding: 8px 10px;
color: #68746e;
background: rgba(255, 255, 255, 0.78);
border: 1px solid rgba(210, 204, 191, 0.72);
border-radius: 9px;
font-size: 9px;
font-weight: 650;
backdrop-filter: blur(7px);
pointer-events: none;
}
.legend {
position: absolute;
z-index: 4;
left: 22px;
bottom: 63px;
padding: 11px 13px;
display: grid;
gap: 7px;
color: #53625c;
background: rgba(255, 255, 255, 0.88);
border: 1px solid rgba(210, 204, 191, 0.82);
border-radius: 11px;
box-shadow: 0 7px 20px rgba(54, 61, 57, 0.08);
font-size: 9px;
font-weight: 680;
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.legend-line {
width: 22px;
height: 4px;
border-radius: 99px;
}
.legend-note {
padding-top: 5px;
color: #7a847f;
border-top: 1px solid #e7e1d7;
font-size: 8px;
font-weight: 600;
}
.route-detail {
--route: #147d6c;
position: absolute;
z-index: 5;
right: 22px;
bottom: 22px;
width: 335px;
padding: 17px;
color: var(--ink);
background: rgba(255, 255, 255, 0.94);
border: 1px solid rgba(210, 204, 191, 0.92);
border-top: 4px solid var(--route);
border-radius: 14px;
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.detail-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.detail-kicker {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.detail-name {
margin-top: 4px;
font-size: 16px;
font-weight: 800;
letter-spacing: -0.025em;
}
.detail-access {
padding: 5px 8px;
color: var(--route);
background: color-mix(in srgb, var(--route) 10%, white);
border-radius: 8px;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.detail-metrics {
margin: 15px 0 13px;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.detail-metric {
padding: 9px 7px;
background: #f1eee7;
border-radius: 9px;
text-align: center;
}
.detail-metric strong {
display: block;
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.detail-metric span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
text-transform: uppercase;
}
.detail-note {
color: #5d6a64;
font-size: 10px;
line-height: 1.5;
}
.detail-surface {
margin-top: 10px;
padding-top: 10px;
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
border-top: 1px solid #e9e3da;
font-size: 9px;
}
.detail-surface::before {
content: "";
width: 6px;
height: 6px;
background: var(--route);
border-radius: 50%;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
.topbar {
height: 64px;
padding: 0 15px;
}
.destination-chip {
display: none;
}
.app-shell {
height: auto;
min-height: calc(100vh - 64px);
grid-template-columns: 315px minmax(0, 1fr);
}
.sidebar {
padding: 20px 16px;
}
h1 {
font-size: 25px;
}
.scene {
min-height: 700px;
}
.route-detail {
width: 300px;
}
}
@media (max-width: 720px) {
.brand-subtitle,
.demo-badge {
display: none;
}
.app-shell {
display: flex;
flex-direction: column;
}
.sidebar {
overflow: visible;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.scene {
height: 72vh;
min-height: 600px;
}
.map-top-left {
top: 13px;
left: 13px;
}
.map-controls {
top: 13px;
right: 13px;
}
.control-btn .control-text {
display: none;
}
.map-hint {
display: none;
}
.legend {
left: 13px;
bottom: 15px;
}
.route-detail {
right: 13px;
bottom: 13px;
width: min(335px, calc(100% - 26px));
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M5 18V8.5C5 7.7 5.7 7 6.5 7H9.2C9.8 7 10.3 7.5 10.3 8.1V18"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<path d="M10.3 11.3H16.5C17.3 11.3 18 12 18 12.8V18"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<circle cx="5" cy="19" r="1.4" fill="currentColor"/>
<circle cx="18" cy="19" r="1.4" fill="currentColor"/>
</svg>
</div>
<div>
<div class="brand-name">CivicPath</div>
<div class="brand-subtitle">Public access route comparison</div>
</div>
</div>
<div class="header-actions">
<div class="demo-badge">Illustrative dataset</div>
<div class="destination-chip">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M3 21h18M5 21V9l7-5 7 5v12M9 21v-6h6v6M9 10h.01M12 10h.01M15 10h.01"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Riverside Civic Hall
</div>
</div>
</header>
<main class="app-shell">
<aside class="sidebar" aria-label="Route comparison">
<div class="eyebrow">Access planner</div>
<h1>Three ways to the same front door</h1>
<p class="intro">
Compare walking distance, maximum slope, and route barriers between
Riverside Civic Hall and Central Transit Plaza.
</p>
<div class="destination-card">
<div class="destination-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M3 21h18M5 21V9l7-5 7 5v12M9 21v-6h6v6M8 10h2M12 10h2M16 10h.01"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<div>
<div class="destination-label">Destination entrance</div>
<div class="destination-name">Riverside Civic Hall</div>
</div>
</div>
<h2 class="section-heading">
<span>Choose a route</span>
<span>3 alternatives</span>
</h2>
<div class="route-list" id="routeList"></div>
<section class="comparison" aria-labelledby="comparisonTitle">
<h2 class="section-heading" id="comparisonTitle">
<span>At a glance</span>
<span>Illustrative values</span>
</h2>
<table class="comparison-table">
<thead>
<tr>
<th>Route</th>
<th>Distance</th>
<th>Max slope</th>
<th>Barriers</th>
</tr>
</thead>
<tbody id="comparisonBody"></tbody>
</table>
</section>
<div class="note-card">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="1.8"/>
<path d="M12 10.5v5M12 7.5h.01" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
<span>
Accessibility scores and barrier counts are illustrative demo values,
not a substitute for surveyed path data or on-site assessment.
</span>
</div>
</aside>
<section class="scene" aria-label="Interactive 3D route map">
<div id="canvasHost"></div>
<div id="mapLabels" aria-hidden="true"></div>
<div class="map-top-left">
<div class="map-pill">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 6.5 9 4l6 2.5L20 4v13.5L15 20l-6-2.5L4 20V6.5Z"
stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/>
<path d="M9 4v13.5M15 6.5V20" stroke="currentColor" stroke-width="1.7"/>
</svg>
Riverside district · sample map
</div>
</div>
<div class="map-controls" aria-label="Map view controls">
<div class="control-group">
<button class="control-btn active" id="view3d" type="button" aria-pressed="true">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"
stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/>
<path d="m4.5 7.7 7.5 4.2 7.5-4.2M12 12v9"
stroke="currentColor" stroke-width="1.7"/>
</svg>
<span class="control-text">3D</span>
</button>
<button class="control-btn" id="view2d" type="button" aria-pressed="false">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<rect x="4" y="4" width="16" height="16" rx="2"
stroke="currentColor" stroke-width="1.7"/>
<path d="M4 10h16M10 4v16" stroke="currentColor" stroke-width="1.7"/>
</svg>
<span class="control-text">2D</span>
</button>
</div>
<div class="control-group">
<button class="control-btn icon-only" id="overview" type="button" aria-label="Reset map view">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="12" r="3" stroke="currentColor" stroke-width="1.7"/>
</svg>
</button>
<button class="control-btn icon-only" id="toggleLabels" type="button" aria-label="Toggle map labels" aria-pressed="true">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 5h10l6 6-8 8-8-8V5Z"
stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"/>
<circle cx="8.5" cy="9.5" r="1.2" fill="currentColor"/>
</svg>
</button>
</div>
</div>
<div class="legend" id="legend"></div>
<div class="map-hint">
Drag to rotate · Scroll to zoom · Shift-drag to pan · Arrow keys to move
</div>
<article class="route-detail" id="routeDetail" aria-live="polite"></article>
</section>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const routes = [
{
id: "garden",
name: "Garden ramp",
subtitle: "Step-free · continuous paved approach",
tag: "Step-free",
color: "#147d6c",
distance: 840,
averageSlope: 2.8,
maxSlope: 4.6,
obstacles: 0,
access: "High",
score: 96,
dots: 5,
surface: "Smooth concrete",
note:
"The longest option, but it avoids steps and provides curb cuts along the entire approach.",
insight:
"150 m farther than the promenade, while removing both barrier points and reducing maximum grade.",
points: [
[-10, 0.16, 8],
[-9.1, 0.15, 6.8],
[-7.4, 0.14, 5.5],
[-4.4, 0.18, 4.7],
[-1.3, 0.12, 3.9],
[1.8, 0.10, 2.4],
[4.8, 0.08, 0.6],
[7.4, 0.07, -1.2],
[8.7, 0.06, -2.4],
[9, 0.05, -3.25]
],
obstaclesData: []
},
{
id: "promenade",
name: "Civic promenade",
subtitle: "Mostly level · two caution points",
tag: "Caution",
color: "#3976b8",
distance: 690,
averageSlope: 4.2,
maxSlope: 6.8,
obstacles: 2,
access: "Medium",
score: 72,
dots: 3,
surface: "Textured pavers",
note:
"A shorter central route with a narrow gateway and a curb transition before the final approach.",
insight:
"The shortest non-stair route, but the gateway and curb transition require a careful approach.",
points: [
[-10, 0.16, 8],
[-10.2, 0.13, 5.5],
[-8.4, 0.11, 3.1],
[-5.5, 0.14, 1.1],
[-2.6, 0.10, -1.1],
[0.7, 0.08, -2.7],
[3.8, 0.07, -3.8],
[6.8, 0.06, -4.2],
[8.8, 0.05, -3.5],
[9, 0.05, -3.25]
],
obstaclesData: [
{ label: "Narrow gateway", x: -5.5, y: 0.2, z: 1.1 },
{ label: "Curb transition", x: 3.8, y: 0.14, z: -3.8 }
]
},
{
id: "stairs",
name: "Direct steps",
subtitle: "Shortest path · stairs and steep grades",
tag: "Stairs",
color: "#d4643f",
distance: 460,
averageSlope: 10.2,
maxSlope: 17.4,
obstacles: 3,
access: "Low",
score: 28,
dots: 1,
surface: "Stone steps",
note:
"The shortest route follows the historic stair approach and is not suitable for a step-free visit.",
insight:
"380 m shorter than the garden ramp, but stairs and a 17.4% maximum grade exclude step-free travel.",
points: [
[-10, 0.16, 8],
[-7.3, 0.19, 6.2],
[-4.4, 0.46, 4.2],
[-1.8, 0.94, 1.9],
[1.0, 1.36, -0.4],
[4.6, 0.57, -2.6],
[7.8, 0.12, -3.35],
[9, 0.05, -3.25]
],
obstaclesData: [
{ label: "Steep flight", x: -1.8, y: 1.0, z: 1.9 },
{ label: "No landing", x: 1.0, y: 1.45, z: -0.4 },
{ label: "Stone steps", x: 4.6, y: 0.65, z: -2.6 }
]
}
];
const routeList = document.querySelector("#routeList");
const comparisonBody = document.querySelector("#comparisonBody");
const routeDetail = document.querySelector("#routeDetail");
const legend = document.querySelector("#legend");
const labelHost = document.querySelector("#mapLabels");
function metricLabel(value) {
return value === 0 ? "None" : String(value);
}
function renderRouteCards() {
routeList.innerHTML = routes
.map(
(route) => `
<button
class="route-card"
data-route="${route.id}"
style="--route:${route.color}"
type="button"
aria-pressed="false"
>
<span class="route-top">
<span class="route-title-wrap">
<span class="route-swatch" aria-hidden="true"></span>
<span>
<span class="route-name">${route.name}</span>
<span class="route-subtitle">${route.subtitle}</span>
</span>
</span>
<span class="route-tag">${route.tag}</span>
</span>
<span class="mini-metrics">
<span class="mini-metric">
<span class="mini-label">Distance</span>
<span class="mini-value">${route.distance} m</span>
</span>
<span class="mini-metric">
<span class="mini-label">Max slope</span>
<span class="mini-value">${route.maxSlope}%</span>
</span>
<span class="mini-metric">
<span class="mini-label">Barriers</span>
<span class="mini-value">${metricLabel(route.obstacles)}</span>
</span>
</span>
<span class="access-row">
<span class="access-copy">
Illustrative access: ${route.access} · ${route.score}/100
</span>
<span class="access-dots" aria-hidden="true">
${Array.from(
{ length: 5 },
(_, index) =>
`<span class="access-dot ${index < route.dots ? "filled" : ""}"></span>`
).join("")}
</span>
</span>
</button>
`
)
.join("");
comparisonBody.innerHTML = routes
.map(
(route) => `
<tr>
<td class="table-route">
<span class="table-dot" style="background:${route.color}"></span>
${route.name}
</td>
<td>${route.distance} m</td>
<td>${route.maxSlope}%</td>
<td>${route.obstacles}</td>
</tr>
`
)
.join("");
legend.innerHTML = `
${routes
.map(
(route) => `
<div class="legend-item">
<span class="legend-line" style="background:${route.color}"></span>
<span>${route.name}</span>
</div>
`
)
.join("")}
<div class="legend-note">Illustrative map · not surveyed data</div>
`;
}
renderRouteCards();
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const host = document.querySelector("#canvasHost");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e8e0cf");
scene.fog = new THREE.Fog("#e8e0cf", 38, 72);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
host.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly map. Drag to rotate, scroll to zoom, and use arrow keys to move the view."
);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const cameraState = {
target: new THREE.Vector3(0, 0.5, 0),
yaw: 0.72,
pitch: 0.88,
distance: 36
};
function updateCamera() {
const { target, yaw, pitch, distance } = cameraState;
const horizontal = Math.sin(pitch) * distance;
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + Math.cos(pitch) * distance,
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight("#fff8e8", "#879389", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff3d6", 3.1);
sun.position.set(-12, 25, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -26;
sun.shadow.camera.right = 26;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#c9e3df", 0.75);
fill.position.set(18, 12, -18);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(width, height, depth, color, x, y, z, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Ground, paths, river, and plazas.
addBox(40, 0.12, 30, "#ddd4c0", 0, -0.13, 0, {
roughness: 1
});
addBox(39, 0.045, 3.3, "#b9b8ae", 0, -0.035, 11.2);
addBox(3.2, 0.045, 25, "#c2c0b6", -14.5, -0.03, 0);
addBox(40, 0.05, 2.4, "#c3c1b7", 0, -0.03, -12.6);
for (let x = -18; x < 19; x += 2.7) {
addBox(1.2, 0.012, 0.08, "#e7e1cf", x, 0.005, 11.2);
}
addBox(5.3, 0.055, 30, "#8bc2bd", 17.7, -0.025, 0, {
roughness: 0.62
});
addBox(0.45, 0.07, 30, "#c2b99e", 14.95, -0.005, 0);
addBox(4.5, 0.11, 2.8, "#d6cdbb", 16.1, 0.02, -2.0);
const plaza = new THREE.Mesh(
new THREE.CylinderGeometry(3.7, 3.7, 0.09, 32),
material("#d8cdb7")
);
plaza.position.set(-10, 0.015, 8);
plaza.receiveShadow = true;
scene.add(plaza);
const civicPlaza = new THREE.Mesh(
new THREE.CylinderGeometry(3.4, 3.4, 0.08, 24),
material("#e5dac5")
);
civicPlaza.position.set(9, 0.015, -3.5);
civicPlaza.receiveShadow = true;
scene.add(civicPlaza);
const garden = new THREE.Mesh(
new THREE.CircleGeometry(6.4, 24),
material("#a9ba86", { roughness: 1 })
);
garden.rotation.x = -Math.PI / 2;
garden.position.set(-1.5, -0.04, 4.6);
garden.scale.set(1, 1, 0.65);
garden.receiveShadow = true;
scene.add(garden);
function addBuilding({
x,
z,
width,
depth,
height,
color,
roofColor = "#8e7763",
windows = true,
pyramid = false
}) {
const body = addBox(width, height, depth, color, x, height / 2, z);
body.castShadow = true;
if (pyramid) {
const roof = new THREE.Mesh(
new THREE.ConeGeometry(Math.max(width, depth) * 0.66, 1.25, 4),
material(roofColor)
);
roof.position.set(x, height + 0.62, z);
roof.rotation.y = Math.PI / 4;
roof.scale.z = depth / width;
roof.castShadow = true;
scene.add(roof);
} else {
addBox(width + 0.22, 0.22, depth + 0.22, roofColor, x, height + 0.1, z);
}
if (windows) {
const columns = Math.max(2, Math.floor(width / 1.25));
const frontZ = z + depth / 2 + 0.022;
for (let row = 0; row < Math.max(1, Math.floor(height / 1.35)); row++) {
for (let col = 0; col < columns; col++) {
const spacing = width / (columns + 1);
const wx = x - width / 2 + spacing * (col + 1);
const wy = 1.1 + row * 1.25;
if (wy + 0.24 < height) {
addBox(
0.48,
0.48,
0.045,
"#65888a",
wx,
wy,
frontZ,
{ roughness: 0.5 }
);
}
}
}
}
}
addBuilding({
x: 9,
z: -6.3,
width: 6.4,
depth: 4.4,
height: 3.25,
color: "#eadfc7",
roofColor: "#a66f4d",
windows: false,
pyramid: true
});
// Civic Hall entrance and columns.
addBox(1.65, 2.25, 0.16, "#52645f", 9, 1.12, -4.06);
for (const x of [6.65, 7.75, 10.25, 11.35]) {
const column = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.22, 2.55, 8),
material("#f1e8d5")
);
column.position.set(x, 1.27, -3.95);
column.castShadow = true;
scene.add(column);
}
addBox(5.4, 0.28, 0.65, "#eadfc7", 9, 2.7, -4.0);
// Low stairs at the civic entrance.
for (let i = 0; i < 3; i++) {
addBox(
2.5 - i * 0.25,
0.12,
0.42,
"#d4c8b2",
9,
0.06 + i * 0.12,
-3.52 + i * 0.34
);
}
addBuilding({
x: -12.3,
z: 8.0,
width: 4.2,
depth: 3.4,
height: 2.25,
color: "#c5d2cc",
roofColor: "#718984"
});
addBuilding({
x: -7.2,
z: -6.4,
width: 5.2,
depth: 4.2,
height: 3.0,
color: "#d8bda4",
roofColor: "#84665b"
});
addBuilding({
x: 3.4,
z: 7.1,
width: 5.0,
depth: 3.5,
height: 2.55,
color: "#d6c7a7",
roofColor: "#9c8059"
});
addBuilding({
x: 8.0,
z: 7.4,
width: 3.5,
depth: 3.0,
height: 2.1,
color: "#c6d8d3",
roofColor: "#64807e"
});
addBuilding({
x: -6.0,
z: -1.0,
width: 3.5,
depth: 2.7,
height: 2.0,
color: "#e2cda5",
roofColor: "#957452"
});
function addTree(x, z, scale = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.09 * scale, 0.13 * scale, 0.9 * scale, 6),
material("#896c4d")
);
trunk.position.set(x, 0.45 * scale, z);
trunk.castShadow = true;
scene.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.62 * scale, 0),
material("#68895f")
);
crown.position.set(x, 1.28 * scale, z);
crown.scale.y = 1.18;
crown.rotation.y = x * 0.37;
crown.castShadow = true;
scene.add(crown);
}
[
[-11.5, 4.8, 1.1],
[-8.0, 3.4, 0.9],
[-5.0, 7.1, 1.05],
[-1.9, 6.3, 1.1],
[1.0, 5.5, 0.85],
[4.6, 4.0, 0.9],
[7.0, 3.4, 0.85],
[11.5, 2.1, 1.05],
[-1.5, -5.8, 0.9],
[2.0, -6.8, 1.0],
[5.0, -8.3, 0.85],
[12.0, -9.0, 1.15],
[-10.5, -4.7, 0.85],
[-13.0, -1.3, 0.8]
].forEach(([x, z, s]) => addTree(x, z, s));
function addBench(x, z, rotation = 0) {
const group = new THREE.Group();
const seat = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.12, 0.38),
material("#8b684d")
);
seat.position.y = 0.34;
seat.castShadow = true;
group.add(seat);
const back = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.38, 0.1),
material("#8b684d")
);
back.position.set(0, 0.57, -0.15);
back.castShadow = true;
group.add(back);
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
}
addBench(-6.3, 3.0, -0.4);
addBench(-2.6, 5.7, 0.2);
addBench(4.8, 1.6, -0.6);
addBench(10.6, -1.0, 0.6);
function addLamp(x, z) {
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.05, 1.55, 6),
material("#52615c")
);
pole.position.set(x, 0.775, z);
scene.add(pole);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 8, 6),
material("#f7df9e", { emissive: "#b68c38", emissiveIntensity: 0.3 })
);
head.position.set(x, 1.6, z);
scene.add(head);
}
[
[-12.6, 5.2],
[-6.4, 6.8],
[0.4, 2.8],
[7.2, -0.5],
[10.7, -4.7]
].forEach(([x, z]) => addLamp(x, z));
// ---------------------------------------------------------------------
// Route ribbons
// ---------------------------------------------------------------------
function createRibbon(points, width, routeColor, opacity, yOffset = 0) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.24
);
const segments = 120;
const positions = [];
const indices = [];
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPoint(t);
const tangent = curve.getTangent(t).normalize();
const side = new THREE.Vector3().crossVectors(up, tangent).normalize();
const left = point.clone().addScaledVector(side, width / 2);
const right = point.clone().addScaledVector(side, -width / 2);
positions.push(
left.x,
left.y + yOffset,
left.z,
right.x,
right.y + yOffset,
right.z
);
if (i < segments) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
material(routeColor, {
transparent: true,
opacity,
side: THREE.DoubleSide,
depthWrite: false,
roughness: 0.78
})
);
mesh.receiveShadow = true;
scene.add(mesh);
return { mesh, curve };
}
const routeVisuals = new Map();
const obstacleGroups = new Map();
const obstacleLabels = [];
for (const route of routes) {
const underlay = createRibbon(
route.points,
0.78,
route.color,
0.12,
0.015
);
const line = createRibbon(
route.points,
0.18,
route.color,
0.4,
0.035
);
line.mesh.material.emissive = new THREE.Color(route.color);
line.mesh.material.emissiveIntensity = 0.05;
routeVisuals.set(route.id, { underlay, line });
const group = new THREE.Group();
scene.add(group);
for (const obstacle of route.obstaclesData) {
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.27, 0),
material("#e3a13c", {
emissive: "#9a5f09",
emissiveIntensity: 0.16
})
);
marker.position.set(obstacle.x, obstacle.y + 0.48, obstacle.z);
marker.castShadow = true;
group.add(marker);
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.34, 0.45, 20),
new THREE.MeshBasicMaterial({
color: "#dfa23c",
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(obstacle.x, obstacle.y + 0.025, obstacle.z);
group.add(ring);
const label = document.createElement("div");
label.className = "map-label obstacle";
label.textContent = obstacle.label;
labelHost.appendChild(label);
obstacleLabels.push({
element: label,
position: new THREE.Vector3(
obstacle.x,
obstacle.y + 1.03,
obstacle.z
),
routeId: route.id
});
}
obstacleGroups.set(route.id, group);
}
// Visible stair treads on the direct route.
const stairRoute = routes.find((route) => route.id === "stairs");
const stairCurve = routeVisuals.get("stairs").line.curve;
const stairGroup = new THREE.Group();
for (let i = 0; i < 13; i++) {
const t = 0.24 + (i / 12) * 0.31;
const point = stairCurve.getPoint(t);
const tangent = stairCurve.getTangent(t);
const step = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.11, 0.48),
material("#c8b99d")
);
step.position.copy(point);
step.position.y += 0.015;
step.rotation.y = Math.atan2(tangent.x, tangent.z);
step.castShadow = true;
step.receiveShadow = true;
stairGroup.add(step);
}
scene.add(stairGroup);
// Shared start marker.
const startRing = new THREE.Mesh(
new THREE.RingGeometry(0.45, 0.68, 24),
new THREE.MeshBasicMaterial({
color: "#ffffff",
side: THREE.DoubleSide,
transparent: true,
opacity: 0.95
})
);
startRing.rotation.x = -Math.PI / 2;
startRing.position.set(-10, 0.09, 8);
scene.add(startRing);
const startDot = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.18, 0.13, 16),
material("#f9f7ef")
);
startDot.position.set(-10, 0.16, 8);
scene.add(startDot);
// Destination beacon.
const destinationRing = new THREE.Mesh(
new THREE.RingGeometry(0.62, 0.78, 32),
new THREE.MeshBasicMaterial({
color: "#e4a54a",
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9
})
);
destinationRing.rotation.x = -Math.PI / 2;
destinationRing.position.set(9, 0.12, -3.25);
scene.add(destinationRing);
const destinationPin = new THREE.Mesh(
new THREE.ConeGeometry(0.22, 0.58, 8),
material("#d99a3f")
);
destinationPin.position.set(9, 1.55, -3.25);
destinationPin.rotation.z = Math.PI;
destinationPin.castShadow = true;
scene.add(destinationPin);
// Moving route marker and pulse.
const flowMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 12, 8),
material("#ffffff", {
emissive: "#ffffff",
emissiveIntensity: 0.22
})
);
scene.add(flowMarker);
const flowPulse = new THREE.Mesh(
new THREE.RingGeometry(0.24, 0.34, 24),
new THREE.MeshBasicMaterial({
color: "#ffffff",
transparent: true,
opacity: 0.75,
side: THREE.DoubleSide
})
);
flowPulse.rotation.x = -Math.PI / 2;
scene.add(flowPulse);
// ---------------------------------------------------------------------
// Projected HTML map labels
// ---------------------------------------------------------------------
const mapLabels = [];
function createMapLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `map-label ${className}`.trim();
element.textContent = text;
labelHost.appendChild(element);
mapLabels.push({
element,
position: position.clone()
});
}
createMapLabel(
"Riverside Civic Hall",
new THREE.Vector3(9, 5.15, -6.3),
"destination"
);
createMapLabel(
"Central Transit Plaza",
new THREE.Vector3(-10, 1.55, 8)
);
createMapLabel(
"Riverside Library",
new THREE.Vector3(-7.2, 4.25, -6.4)
);
createMapLabel(
"Community Center",
new THREE.Vector3(3.4, 3.8, 7.1)
);
createMapLabel(
"Garden",
new THREE.Vector3(-1.5, 1.0, 5.4)
);
let labelsVisible = true;
function updateLabels() {
const width = host.clientWidth;
const height = host.clientHeight;
const projected = new THREE.Vector3();
for (const label of mapLabels) {
projected.copy(label.position).project(camera);
const visible =
labelsVisible &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -100%)`;
}
}
for (const label of obstacleLabels) {
projected.copy(label.position).project(camera);
const visible =
labelsVisible &&
selectedRouteId === label.routeId &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -100%)`;
}
}
}
// ---------------------------------------------------------------------
// Route selection and UI state
// ---------------------------------------------------------------------
let selectedRouteId = "garden";
function updateDetail(route) {
routeDetail.style.setProperty("--route", route.color);
routeDetail.innerHTML = `
<div class="detail-top">
<div>
<div class="detail-kicker">Selected route</div>
<div class="detail-name">${route.name}</div>
</div>
<div class="detail-access">${route.access} access · ${route.score}/100</div>
</div>
<div class="detail-metrics">
<div class="detail-metric">
<strong>${route.distance} m</strong>
<span>Distance</span>
</div>
<div class="detail-metric">
<strong>${route.maxSlope}%</strong>
<span>Maximum</span>
</div>
<div class="detail-metric">
<strong>${route.obstacles}</strong>
<span>Barriers</span>
</div>
</div>
<div class="detail-note">${route.insight}</div>
<div class="detail-surface">${route.surface} · ${route.note}</div>
`;
}
function selectRoute(routeId) {
selectedRouteId = routeId;
const selected = routes.find((route) => route.id === routeId);
for (const route of routes) {
const isSelected = route.id === routeId;
const visuals = routeVisuals.get(route.id);
visuals.underlay.mesh.material.opacity = isSelected ? 0.34 : 0.09;
visuals.line.mesh.material.opacity = isSelected ? 1 : 0.33;
visuals.line.mesh.material.emissiveIntensity = isSelected ? 0.23 : 0.03;
obstacleGroups.get(route.id).visible = isSelected;
}
stairGroup.visible = routeId === "stairs";
document.querySelectorAll(".route-card").forEach((card) => {
const isSelected = card.dataset.route === routeId;
card.classList.toggle("selected", isSelected);
card.setAttribute("aria-pressed", String(isSelected));
});
updateDetail(selected);
}
document.querySelectorAll(".route-card").forEach((card) => {
card.addEventListener("click", () => selectRoute(card.dataset.route));
});
selectRoute(selectedRouteId);
// ---------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, keyboard, and touch pinch
// ---------------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let gesture = null;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.focus({ preventScroll: true });
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
gesture = {
type: "orbit",
x: event.clientX,
y: event.clientY,
shiftKey: event.shiftKey
};
} else if (pointers.size === 2) {
const values = [...pointers.values()];
gesture = {
type: "pinch",
distance: Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
)
};
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2 && gesture?.type === "pinch") {
const values = [...pointers.values()];
const nextDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (nextDistance > 0 && gesture.distance > 0) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * (gesture.distance / nextDistance),
17,
58
);
}
gesture.distance = nextDistance;
return;
}
if (pointers.size !== 1 || !gesture) return;
const dx = event.clientX - gesture.x;
const dy = event.clientY - gesture.y;
if (gesture.shiftKey || event.shiftKey) {
const panScale = cameraState.distance * 0.00145;
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.yaw),
0,
-Math.cos(cameraState.yaw)
);
cameraState.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(forward, dy * panScale);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.28,
1.49
);
}
gesture.x = event.clientX;
gesture.y = event.clientY;
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const value = [...pointers.values()][0];
gesture = {
type: "orbit",
x: value.x,
y: value.y,
shiftKey: event.shiftKey
};
} else if (pointers.size === 0) {
gesture = null;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
17,
58
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const panScale = cameraState.distance * 0.035;
if (event.key === "ArrowLeft") {
cameraState.target.x -= Math.cos(cameraState.yaw) * panScale;
cameraState.target.z += Math.sin(cameraState.yaw) * panScale;
} else if (event.key === "ArrowRight") {
cameraState.target.x += Math.cos(cameraState.yaw) * panScale;
cameraState.target.z -= Math.sin(cameraState.yaw) * panScale;
} else if (event.key === "ArrowUp") {
cameraState.target.x -= Math.sin(cameraState.yaw) * panScale;
cameraState.target.z -= Math.cos(cameraState.yaw) * panScale;
} else if (event.key === "ArrowDown") {
cameraState.target.x += Math.sin(cameraState.yaw) * panScale;
cameraState.target.z += Math.cos(cameraState.yaw) * panScale;
} else if (event.key === "+" || event.key === "=") {
cameraState.distance = Math.max(17, cameraState.distance - 2);
} else if (event.key === "-" || event.key === "_") {
cameraState.distance = Math.min(58, cameraState.distance + 2);
} else if (event.key.toLowerCase() === "r") {
resetView();
} else if (event.key === "1") {
setView("3d");
} else if (event.key === "2") {
setView("2d");
} else {
return;
}
event.preventDefault();
});
function resetView() {
cameraState.target.set(0, 0.5, 0);
cameraState.yaw = 0.72;
cameraState.pitch = 0.88;
cameraState.distance = 36;
}
function setView(view) {
const is3d = view === "3d";
document.querySelector("#view3d").classList.toggle("active", is3d);
document.querySelector("#view3d").setAttribute("aria-pressed", String(is3d));
document.querySelector("#view2d").classList.toggle("active", !is3d);
document.querySelector("#view2d").setAttribute("aria-pressed", String(!is3d));
if (is3d) {
cameraState.yaw = 0.72;
cameraState.pitch = 0.88;
cameraState.distance = 36;
} else {
cameraState.yaw = 0;
cameraState.pitch = 1.49;
cameraState.distance = 38;
}
cameraState.target.set(0, 0.5, 0);
}
document.querySelector("#view3d").addEventListener("click", () => setView("3d"));
document.querySelector("#view2d").addEventListener("click", () => setView("2d"));
document.querySelector("#overview").addEventListener("click", resetView);
document.querySelector("#toggleLabels").addEventListener("click", (event) => {
labelsVisible = !labelsVisible;
event.currentTarget.setAttribute("aria-pressed", String(labelsVisible));
event.currentTarget.classList.toggle("active", labelsVisible);
});
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function resize() {
const width = host.clientWidth;
const height = host.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(host);
resize();
const clock = new THREE.Clock();
const markerPosition = new THREE.Vector3();
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
const selected = routes.find((route) => route.id === selectedRouteId);
const curve = routeVisuals.get(selectedRouteId).line.curve;
const progress = (elapsed * 0.035) % 1;
markerPosition.copy(curve.getPoint(progress));
flowMarker.position.copy(markerPosition);
flowMarker.position.y += 0.17;
flowPulse.position.copy(markerPosition);
flowPulse.position.y += 0.025;
const pulse = 1 + Math.sin(elapsed * 3.5) * 0.16;
flowPulse.scale.setScalar(pulse);
flowPulse.material.opacity = 0.48 + Math.sin(elapsed * 3.5) * 0.18;
destinationRing.scale.setScalar(1 + Math.sin(elapsed * 2.2) * 0.055);
destinationPin.position.y = 1.55 + Math.sin(elapsed * 2.2) * 0.08;
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```