Prompt specification
Build or customize the Three.js 3D scene "Trace work and household routes to the waterfront" 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: Trace work and household routes to the waterfront
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/trace-work-and-household-routes-to-the-waterfront-x2884
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Jamestown's waterfront streets in Accra. Let users compare two fictional daily routes through the schematic neighborhood. Show shared spaces and obstacles without inferring residents' socioeconomic circumstances from the built environment. Voxel style.
Working Three.js Starter (trace-work-and-household-routes-to-the-waterfront-x2884):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Jamestown Routes — Accra</title>
<style>
:root {
--ink: #183236;
--muted: #617276;
--paper: #f5f1e8;
--panel: #fffdf8;
--line: #d9ddd5;
--route-a: #ef654c;
--route-b: #008f91;
--shared: #7a68a8;
--obstacle: #e29b31;
--shadow: 0 12px 36px rgba(24, 50, 54, 0.12);
}
* {
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 {
position: relative;
width: 100%;
height: 100%;
}
#viewport {
position: absolute;
inset: 0 390px 0 0;
overflow: hidden;
background: #d9e5e0;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
z-index: 3;
min-width: max-content;
padding: 5px 8px;
border: 1px solid rgba(24, 50, 54, 0.14);
border-radius: 4px;
background: rgba(255, 253, 248, 0.92);
box-shadow: 0 4px 12px rgba(24, 50, 54, 0.12);
color: var(--ink);
font-size: 11px;
font-weight: 750;
line-height: 1.15;
letter-spacing: 0.015em;
white-space: nowrap;
transform: translate(-50%, -100%);
pointer-events: none;
}
.map-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
border-right: 1px solid rgba(24, 50, 54, 0.14);
border-bottom: 1px solid rgba(24, 50, 54, 0.14);
background: rgba(255, 253, 248, 0.92);
transform: translateX(-50%) rotate(45deg);
}
.map-label.space {
border-color: rgba(122, 104, 168, 0.45);
color: #594a82;
}
.map-label.space::after {
background: #f0ecf8;
border-color: rgba(122, 104, 168, 0.45);
}
.map-label.obstacle {
padding: 4px 6px;
border-color: rgba(191, 123, 24, 0.45);
background: rgba(255, 247, 225, 0.95);
color: #84540d;
font-size: 10px;
}
.map-label.obstacle::after {
background: #fff7e1;
border-color: rgba(191, 123, 24, 0.45);
}
.map-label.landmark {
background: rgba(24, 50, 54, 0.88);
border-color: transparent;
color: white;
}
.map-label.landmark::after {
background: rgba(24, 50, 54, 0.88);
border-color: transparent;
}
.topbar {
position: absolute;
z-index: 10;
top: 20px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
max-width: 470px;
padding: 15px 17px 14px;
border: 1px solid rgba(255, 255, 255, 0.66);
border-radius: 8px;
background: rgba(255, 253, 248, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
pointer-events: auto;
}
.eyebrow {
margin-bottom: 7px;
color: #66777a;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.2vw, 31px);
line-height: 1.05;
letter-spacing: -0.045em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.view-tools {
display: flex;
gap: 7px;
pointer-events: auto;
}
.icon-button {
display: grid;
width: 38px;
height: 38px;
padding: 0;
place-items: center;
border: 1px solid rgba(24, 50, 54, 0.14);
border-radius: 6px;
background: rgba(255, 253, 248, 0.93);
box-shadow: 0 6px 18px rgba(24, 50, 54, 0.1);
cursor: pointer;
font-size: 18px;
font-weight: 800;
}
.icon-button:hover {
background: white;
transform: translateY(-1px);
}
.icon-button.wide {
width: auto;
padding: 0 12px;
font-size: 11px;
letter-spacing: 0.02em;
}
#panel {
position: absolute;
z-index: 20;
top: 0;
right: 0;
width: 390px;
height: 100%;
overflow-y: auto;
padding: 25px 22px 30px;
border-left: 1px solid #d8dcd4;
background: var(--panel);
box-shadow: -10px 0 30px rgba(24, 50, 54, 0.06);
scrollbar-width: thin;
scrollbar-color: #b9c4bf transparent;
}
.panel-kicker {
margin: 0 0 8px;
color: #6d7a7b;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.04em;
}
.intro {
margin: 10px 0 19px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.route-card {
position: relative;
margin-bottom: 10px;
padding: 13px 12px 12px;
border: 1px solid var(--line);
border-radius: 7px;
background: white;
transition: opacity 160ms ease, border-color 160ms ease;
}
.route-card[data-hidden="true"] {
opacity: 0.48;
}
.route-card-head {
display: flex;
align-items: flex-start;
gap: 10px;
}
.route-swatch {
flex: 0 0 auto;
width: 11px;
height: 38px;
border-radius: 2px;
background: var(--route-a);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.route-b .route-swatch {
background: var(--route-b);
}
.route-copy {
min-width: 0;
flex: 1;
}
.route-name-row {
display: flex;
align-items: center;
gap: 7px;
}
.route-letter {
display: grid;
width: 19px;
height: 19px;
place-items: center;
border-radius: 3px;
background: var(--route-a);
color: white;
font-size: 10px;
font-weight: 900;
}
.route-b .route-letter {
background: var(--route-b);
}
.route-name {
margin: 0;
font-size: 14px;
font-weight: 820;
letter-spacing: -0.015em;
}
.route-sub {
margin: 5px 0 0 26px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.route-toggle {
position: relative;
flex: 0 0 auto;
width: 34px;
height: 19px;
margin-top: 2px;
}
.route-toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle-track {
position: absolute;
inset: 0;
border-radius: 10px;
background: #c6ceca;
cursor: pointer;
transition: background 150ms ease;
}
.toggle-track::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
transition: transform 150ms ease;
}
.route-toggle input:checked + .toggle-track {
background: var(--route-a);
}
.route-b .route-toggle input:checked + .toggle-track {
background: var(--route-b);
}
.route-toggle input:checked + .toggle-track::after {
transform: translateX(15px);
}
.route-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid #eceee9;
}
.route-mini {
color: #536366;
font-size: 10px;
font-weight: 700;
}
.focus-button {
padding: 4px 7px;
border: 1px solid #d7ddd7;
border-radius: 4px;
background: #f8f8f4;
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.focus-button:hover {
background: #eef1eb;
}
.section {
margin-top: 22px;
padding-top: 18px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 12px;
font-size: 12px;
font-weight: 850;
letter-spacing: -0.01em;
}
.section-title small {
color: #899493;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-row {
display: grid;
grid-template-columns: 1fr 53px 53px;
align-items: center;
gap: 8px;
margin-bottom: 12px;
}
.metric-label {
color: #58686a;
font-size: 10px;
font-weight: 700;
}
.metric-value {
text-align: right;
font-size: 11px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.metric-value.a {
color: #c94c38;
}
.metric-value.b {
color: #007b7e;
}
.meter-row {
display: grid;
grid-template-columns: 1fr 53px 53px;
gap: 8px;
margin: -7px 0 12px;
}
.meter {
grid-column: 1;
height: 5px;
overflow: hidden;
border-radius: 3px;
background: #e7eae5;
}
.meter span {
display: block;
height: 100%;
border-radius: 3px;
background: var(--route-a);
}
.meter.b {
grid-column: 2 / 4;
margin-top: 3px;
}
.meter.b span {
background: var(--route-b);
}
.insight {
margin-top: 14px;
padding: 11px 12px;
border-left: 3px solid var(--shared);
border-radius: 0 5px 5px 0;
background: #f1eef7;
color: #554b6e;
font-size: 10px;
line-height: 1.55;
}
.place-list,
.obstacle-list {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.place-chip,
.obstacle-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 7px;
border: 1px solid #ddd9e9;
border-radius: 4px;
background: #f7f4fb;
color: #5c507d;
font-size: 9px;
font-weight: 750;
cursor: pointer;
}
.place-chip:hover,
.obstacle-chip:hover {
background: white;
}
.route-tag {
display: inline-grid;
min-width: 15px;
height: 15px;
padding: 0 3px;
place-items: center;
border-radius: 3px;
background: var(--route-a);
color: white;
font-size: 8px;
font-weight: 900;
}
.route-tag.b {
background: var(--route-b);
}
.obstacle-chip {
border-color: #eadcbf;
background: #fff8e9;
color: #79541e;
}
.layer-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.layer-option {
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border: 1px solid #e0e3dd;
border-radius: 5px;
background: #fafaf6;
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.layer-option input {
accent-color: var(--ink);
}
.preview-button {
width: 100%;
margin-top: 12px;
padding: 10px 12px;
border: 0;
border-radius: 5px;
background: var(--ink);
color: white;
cursor: pointer;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.preview-button:hover {
background: #294b4f;
}
.disclaimer {
margin: 18px 0 0;
padding: 11px;
border: 1px solid #e1e2dc;
border-radius: 5px;
background: #f8f7f1;
color: #657174;
font-size: 9px;
line-height: 1.55;
}
.map-key {
position: absolute;
z-index: 8;
left: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 13px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 6px;
background: rgba(255, 253, 248, 0.91);
box-shadow: 0 7px 22px rgba(24, 50, 54, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
}
.key-item {
display: flex;
align-items: center;
gap: 6px;
color: #566568;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.key-line {
width: 19px;
height: 4px;
border-radius: 2px;
background: var(--route-a);
}
.key-line.b {
background: var(--route-b);
}
.key-square {
width: 10px;
height: 10px;
border-radius: 2px;
background: rgba(122, 104, 168, 0.35);
border: 1px solid var(--shared);
}
.key-obstacle {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--obstacle);
}
.help {
position: absolute;
z-index: 7;
right: 18px;
bottom: 18px;
padding: 7px 9px;
border-radius: 4px;
background: rgba(24, 50, 54, 0.78);
color: rgba(255, 255, 255, 0.9);
font-size: 9px;
pointer-events: none;
}
#loading {
position: absolute;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #d9e5e0;
color: #52686b;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.loading-cube {
width: 26px;
height: 26px;
margin: 0 auto 14px;
background: var(--route-b);
animation: loading 1s steps(4) infinite;
}
@keyframes loading {
0% { transform: rotate(0deg) scale(1); }
50% { transform: rotate(90deg) scale(0.72); }
100% { transform: rotate(180deg) scale(1); }
}
@media (max-width: 850px) {
#viewport {
inset: 0 0 280px 0;
}
#panel {
top: auto;
bottom: 0;
width: 100%;
height: 280px;
padding: 18px 20px 26px;
border-top: 1px solid #d8dcd4;
border-left: 0;
box-shadow: 0 -10px 30px rgba(24, 50, 54, 0.08);
}
.panel h2 {
font-size: 21px;
}
.intro {
margin-bottom: 12px;
}
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand {
max-width: 62%;
padding: 11px 12px;
}
.brand .subtitle {
display: none;
}
.view-tools {
flex-wrap: wrap;
justify-content: flex-end;
}
.icon-button.wide {
display: none;
}
.map-key {
left: 12px;
bottom: 12px;
gap: 9px;
padding: 7px 8px;
}
.key-item {
font-size: 8px;
}
.help {
display: none;
}
}
@media (max-width: 520px) {
#viewport {
inset-bottom: 300px;
}
#panel {
height: 300px;
}
.brand {
max-width: 70%;
}
h1 {
font-size: 20px;
}
.eyebrow {
font-size: 8px;
}
.map-key .key-item:nth-child(3),
.map-key .key-item:nth-child(4) {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<section id="viewport" aria-label="Interactive schematic 3D map of Jamestown waterfront streets">
<canvas id="scene" tabindex="0" aria-label="Drag to orbit, scroll to zoom, shift-drag to pan"></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Accra / Jamestown</div>
<h1>Two ways through the waterfront</h1>
<p class="subtitle">
A fictional, schematic comparison of two daily routes through Jamestown's waterfront streets.
</p>
</div>
<div class="view-tools" aria-label="Map view controls">
<button id="zoomOut" class="icon-button" title="Zoom out" aria-label="Zoom out">−</button>
<button id="zoomIn" class="icon-button" title="Zoom in" aria-label="Zoom in">+</button>
<button id="resetView" class="icon-button wide" title="Reset camera">Reset view</button>
</div>
</header>
<div class="map-key" aria-label="Map legend">
<div class="key-item"><span class="key-line"></span>Route A</div>
<div class="key-item"><span class="key-line b"></span>Route B</div>
<div class="key-item"><span class="key-square"></span>Shared space</div>
<div class="key-item"><span class="key-obstacle"></span>Obstacle</div>
</div>
<div class="help">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
<div id="loading"><div><div class="loading-cube"></div>Building Jamestown</div></div>
</section>
<aside id="panel" aria-label="Route comparison panel">
<p class="panel-kicker">Schematic route study</p>
<h2>Compare the daily loops</h2>
<p class="intro">
Toggle either route, focus its extent, and compare distance, overlap, shared spaces,
and illustrative obstacles.
</p>
<article id="cardA" class="route-card">
<div class="route-card-head">
<div class="route-swatch" aria-hidden="true"></div>
<div class="route-copy">
<div class="route-name-row">
<span class="route-letter">A</span>
<h3 class="route-name">Waterfront circuit</h3>
</div>
<p class="route-sub">
Harbour Gate → Market Court → East Steps → Harbour Gate
</p>
</div>
<label class="route-toggle" title="Show Route A">
<input id="routeA" type="checkbox" checked />
<span class="toggle-track"></span>
</label>
</div>
<div class="route-footer">
<span class="route-mini">0.85 km · 4 stops · 3 obstacle points</span>
<button class="focus-button" data-focus-route="A">Focus</button>
</div>
</article>
<article id="cardB" class="route-card route-b">
<div class="route-card-head">
<div class="route-swatch" aria-hidden="true"></div>
<div class="route-copy">
<div class="route-name-row">
<span class="route-letter">B</span>
<h3 class="route-name">Market & north-lane loop</h3>
</div>
<p class="route-sub">
Harbour Gate → Clock Court → North Wharf → Market Court → Gate
</p>
</div>
<label class="route-toggle" title="Show Route B">
<input id="routeB" type="checkbox" checked />
<span class="toggle-track"></span>
</label>
</div>
<div class="route-footer">
<span class="route-mini">1.69 km · 7 stops · 5 obstacle points</span>
<button class="focus-button" data-focus-route="B">Focus</button>
</div>
</article>
<section class="section">
<h3 class="section-title">Route comparison <small>Fictional model</small></h3>
<div class="metric-row">
<div class="metric-label">Distance</div>
<div class="metric-value a">0.85 km</div>
<div class="metric-value b">1.69 km</div>
</div>
<div class="meter-row">
<div class="meter"><span style="width: 50.3%"></span></div>
<div class="meter b"><span style="width: 100%"></span></div>
</div>
<div class="metric-row">
<div class="metric-label">Shared route</div>
<div class="metric-value a">0.59 km</div>
<div class="metric-value b">0.59 km</div>
</div>
<div class="metric-row">
<div class="metric-label">Shared spaces used</div>
<div class="metric-value a">3</div>
<div class="metric-value b">3</div>
</div>
<div class="metric-row">
<div class="metric-label">Stops</div>
<div class="metric-value a">4</div>
<div class="metric-value b">7</div>
</div>
<div class="metric-row">
<div class="metric-label">Obstacle points</div>
<div class="metric-value a">3</div>
<div class="metric-value b">5</div>
</div>
<div class="insight">
Route A is about 0.84 km shorter in this schematic. Both routes share the harbour
gate, market court, promenade, and roughly 0.59 km of street or court.
</div>
</section>
<section class="section">
<h3 class="section-title">Shared places <small>Click to focus</small></h3>
<div id="placeList" class="place-list"></div>
</section>
<section class="section">
<h3 class="section-title">Obstacle points <small>Illustrative only</small></h3>
<div id="obstacleList" class="obstacle-list"></div>
</section>
<section class="section">
<h3 class="section-title">Map layers</h3>
<div class="layer-list">
<label class="layer-option">
<input id="showSpaces" type="checkbox" checked />
Shared spaces
</label>
<label class="layer-option">
<input id="showObstacles" type="checkbox" checked />
Obstacles
</label>
<label class="layer-option">
<input id="showLabels" type="checkbox" checked />
Labels
</label>
<label class="layer-option">
<input id="showRoutes" type="checkbox" checked />
Both routes
</label>
</div>
<button id="previewRoutes" class="preview-button">▶ Animate both routes</button>
</section>
<p class="disclaimer">
This is an illustrative model, not a surveyed map or a description of any real person's
circumstances. Building color, height, and form indicate visual variety only; no resident
characteristics or socioeconomic circumstances are inferred.
</p>
</aside>
</main>
<script type="module">
let THREE;
try {
THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
} catch (error) {
document.querySelector("#loading").innerHTML =
"<div>Unable to load Three.js.<br>Check your internet connection and reload.</div>";
throw error;
}
const viewport = document.querySelector("#viewport");
const canvas = document.querySelector("#scene");
const labelsContainer = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e5e0);
scene.fog = new THREE.Fog(0xd9e5e0, 105, 190);
const camera = new THREE.OrthographicCamera(-30, 30, 23, -23, 0.1, 250);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const ambient = new THREE.HemisphereLight(0xf9fff7, 0x758a7e, 2.15);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff1d5, 3.25);
sun.position.set(-30, 55, 35);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 140;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xb9dce1, 0.8);
fillLight.position.set(35, 18, -30);
scene.add(fillLight);
const materials = {
land: new THREE.MeshStandardMaterial({ color: 0xc4b79d, roughness: 1 }),
landSide: new THREE.MeshStandardMaterial({ color: 0xa7957b, roughness: 1 }),
water: new THREE.MeshStandardMaterial({
color: 0x4c9eaa,
roughness: 0.72,
metalness: 0.05
}),
wave: new THREE.MeshStandardMaterial({
color: 0x8fd0d1,
transparent: true,
opacity: 0.38,
roughness: 0.8
}),
sidewalk: new THREE.MeshStandardMaterial({ color: 0xd8d2c3, roughness: 1 }),
promenade: new THREE.MeshStandardMaterial({ color: 0xddd6c6, roughness: 1 }),
road: new THREE.MeshStandardMaterial({ color: 0x536064, roughness: 0.95 }),
marking: new THREE.MeshStandardMaterial({ color: 0xe5dfc9, roughness: 1 }),
seawall: new THREE.MeshStandardMaterial({ color: 0x9c998d, roughness: 1 }),
dock: new THREE.MeshStandardMaterial({ color: 0x7a6956, roughness: 1 }),
roof: new THREE.MeshStandardMaterial({ color: 0x5c6869, roughness: 0.9 }),
glass: new THREE.MeshStandardMaterial({
color: 0x315561,
roughness: 0.42,
metalness: 0.12
}),
trunk: new THREE.MeshStandardMaterial({ color: 0x745b43, roughness: 1 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x5d8a67, roughness: 1 }),
leafLight: new THREE.MeshStandardMaterial({ color: 0x79a26f, roughness: 1 }),
shared: new THREE.MeshStandardMaterial({
color: 0x806cac,
transparent: true,
opacity: 0.33,
depthWrite: false,
roughness: 0.9
}),
sharedBorder: new THREE.MeshStandardMaterial({
color: 0x806cac,
transparent: true,
opacity: 0.72,
roughness: 0.9
}),
obstacleFootprint: new THREE.MeshStandardMaterial({
color: 0xe29b31,
transparent: true,
opacity: 0.3,
depthWrite: false
}),
obstacle: new THREE.MeshStandardMaterial({ color: 0xe39a2c, roughness: 0.78 }),
obstacleDark: new THREE.MeshStandardMaterial({ color: 0x4a4840, roughness: 0.9 }),
cream: new THREE.MeshStandardMaterial({ color: 0xeee6d3, roughness: 1 })
};
const buildingPalette = [
0xd7c5a6,
0xc7a58c,
0xb8c1b0,
0xc9b9c2,
0xb9c9c4,
0xd0b18a,
0xaeb9c1
];
const roofPalette = [
0x66716f,
0x6f625d,
0x5e7476,
0x776e66
];
function box(w, h, d, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = h > 0.25;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Base terrain and harbour water.
const landBase = box(68, 2, 32, 0, -1, -2, materials.landSide);
landBase.castShadow = false;
box(68, 0.08, 32, 0, 0.02, -2, materials.land);
box(130, 0.45, 130, 0, -0.36, 45, materials.water);
const waveMeshes = [];
for (let i = 0; i < 42; i++) {
const wave = box(
2.2 + (i % 4) * 0.55,
0.045,
0.18,
-47 + ((i * 13.7) % 94),
-0.08,
16 + ((i * 7.3) % 48),
materials.wave
);
wave.castShadow = false;
waveMeshes.push({ mesh: wave, phase: i * 0.71 });
}
// Street grid.
const verticalStreets = [-25, -9, 7, 23];
const horizontalStreets = [-10, 0];
for (const x of verticalStreets) {
box(4.25, 0.12, 29, x, 0.08, -2.5, materials.sidewalk);
box(2.85, 0.15, 29, x, 0.16, -2.5, materials.road);
}
for (const z of horizontalStreets) {
box(64, 0.12, 4.25, 0, 0.08, z, materials.sidewalk);
box(64, 0.15, 2.85, 0, 0.16, z, materials.road);
}
// The waterfront promenade is treated as a broad shared paved edge.
box(64, 0.13, 4.4, 0, 0.09, 10, materials.promenade);
box(64, 0.04, 0.15, 0, 0.18, 11.55, materials.sharedBorder);
// Centre road dashes.
for (const x of verticalStreets) {
for (let z = -15; z <= 8; z += 4) {
if (horizontalStreets.some(hz => Math.abs(hz - z) < 3)) continue;
box(0.12, 0.025, 1.4, x, 0.255, z, materials.marking);
}
}
for (const z of horizontalStreets) {
for (let x = -29; x <= 29; x += 5) {
if (verticalStreets.some(vx => Math.abs(vx - x) < 3)) continue;
box(1.4, 0.025, 0.12, x, 0.255, z, materials.marking);
}
}
// Crosswalk at the market court.
for (let i = 0; i < 5; i++) {
box(0.55, 0.025, 2.2, -4.5 + i * 1.2, 0.26, -1.55, materials.marking);
}
// Sea wall, dock, bollards and a few voxel boats.
for (let x = -32; x < 32; x += 4) {
box(3.85, 1.0, 0.75, x, 0.35, 14.05, materials.seawall);
}
box(5.2, 0.48, 8.2, 23, 0.25, 18.1, materials.dock);
for (let z = 15; z <= 21; z += 1.2) {
box(5.4, 0.08, 0.12, 23, 0.52, z, materials.dock);
}
for (const x of [-30, -20, -10, 0, 10, 18, 28]) {
box(0.45, 0.9, 0.45, x, 0.65, 12.9, materials.obstacleDark);
box(0.58, 0.15, 0.58, x, 1.14, 12.9, materials.cream);
}
function addBoat(x, z, hullColor, cabinColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(5.4, 0.65, 2.2, 0, 0.25, 0,
new THREE.MeshStandardMaterial({ color: hullColor, roughness: 0.85 }), group);
box(3.6, 0.22, 1.9, 0, 0.67, 0,
new THREE.MeshStandardMaterial({ color: cabinColor, roughness: 0.85 }), group);
box(1.8, 1.2, 1.45, -0.5, 1.28, 0,
new THREE.MeshStandardMaterial({ color: cabinColor, roughness: 0.85 }), group);
box(1.4, 0.55, 0.07, -0.5, 1.48, 0.75, materials.glass, group);
box(0.16, 3.0, 0.16, 1.4, 2.05, 0, materials.cream, group);
}
addBoat(16.5, 24.5, 0xc95e49, 0xe4d9c1);
addBoat(-11, 27, 0x4f8084, 0xd9cfb8);
addBoat(31, 32, 0xd49b43, 0xe9dfc9);
function addBuilding(x, z, w, d, h, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const wallMaterial = new THREE.MeshStandardMaterial({
color: buildingPalette[index % buildingPalette.length],
roughness: 0.93
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: roofPalette[index % roofPalette.length],
roughness: 0.9
});
box(w, h, d, 0, h / 2, 0, wallMaterial, group);
box(w + 0.45, 0.32, d + 0.45, 0, h + 0.12, 0, roofMaterial, group);
if (index % 3 !== 1) {
box(
w * 0.22,
0.7,
d * 0.2,
-w * 0.22,
h + 0.55,
0,
roofMaterial,
group
);
}
const floors = Math.max(1, Math.floor(h / 2.1));
const columns = Math.max(2, Math.floor(w / 2.2));
for (let floor = 0; floor < floors; floor++) {
const y = 1.15 + floor * 1.65;
if (y + 0.4 > h) continue;
for (let column = 0; column < columns; column++) {
const wx = -w / 2 + (column + 0.5) * (w / columns);
box(
0.62,
0.72,
0.075,
wx,
y,
d / 2 + 0.045,
materials.glass,
group
);
}
}
box(0.9, 1.4, 0.12, 0, 0.72, d / 2 + 0.08, materials.roof, group);
}
const buildings = [
[-17, -14, 9.5, 4.8, 4.4],
[-1, -14, 9, 5.2, 5.6],
[15, -14, 9.5, 4.8, 4.3],
[28, -14, 4.5, 4.4, 3.7],
[-17, -5, 8.5, 4.2, 3.7],
[15, -5, 9.2, 4.4, 4.8],
[-17, 5, 8.8, 4.8, 4.2],
[15, 5, 9.5, 4.8, 4.7],
[-29, 5, 3.3, 5.3, 3.8]
];
buildings.forEach((building, index) => addBuilding(...building, index));
function addTree(x, z, scale = 1) {
box(
0.35 * scale,
1.6 * scale,
0.35 * scale,
x,
0.8 * scale,
z,
materials.trunk
);
box(
1.55 * scale,
1.15 * scale,
1.55 * scale,
x,
1.75 * scale,
z,
materials.leaf
);
box(
1.15 * scale,
0.9 * scale,
1.15 * scale,
x + 0.12 * scale,
2.55 * scale,
z - 0.1 * scale,
materials.leafLight
);
}
[
[-30, -15, 0.85],
[-10, -15, 0.9],
[9, -15, 0.85],
[24, -15, 0.8],
[-30, 7, 0.9],
[-12, 7, 0.85],
[11, 7, 0.85],
[29, -5, 0.8],
[-12, -12, 0.75],
[3, -12, 0.72]
].forEach((tree) => addTree(...tree));
// Market court paving.
box(12.5, 0.16, 5.2, -0.5, 0.18, 2.4, materials.sidewalk);
// Small market stalls along the northern edge of the court.
function addStall(x, z, accent) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const canopyMaterial = new THREE.MeshStandardMaterial({
color: accent,
roughness: 0.95
});
box(0.15, 1.8, 0.15, -1.1, 0.9, -0.7, materials.dock, group);
box(0.15, 1.8, 0.15, 1.1, 0.9, -0.7, materials.dock, group);
box(0.15, 1.8, 0.15, -1.1, 0.9, 0.7, materials.dock, group);
box(0.15, 1.8, 0.15, 1.1, 0.9, 0.7, materials.dock, group);
box(2.5, 0.28, 1.7, 0, 1.75, 0, canopyMaterial, group);
box(2.1, 0.65, 1.05, 0, 0.63, 0, materials.cream, group);
}
addStall(-4.6, 5.2, 0xc7644c);
addStall(-0.5, 5.2, 0xd7a340);
addStall(3.6, 5.2, 0x4f9290);
// Schematic clock tower near Clock Court.
const clockTower = new THREE.Group();
clockTower.position.set(-12.5, 0, -10.7);
scene.add(clockTower);
box(2.5, 6.8, 2.5, 0, 3.4, 0, materials.cream, clockTower);
box(2.8, 0.32, 2.8, 0, 6.95, 0, materials.roof, clockTower);
box(1.45, 1.45, 0.12, 0, 5.4, 1.3, materials.glass, clockTower);
box(0.08, 0.72, 0.08, 0, 5.55, 1.39, materials.cream, clockTower);
box(0.5, 0.08, 0.08, 0.12, 5.38, 1.4, materials.cream, clockTower);
// Lighthouse at the eastern harbour edge.
const lighthouse = new THREE.Group();
lighthouse.position.set(27.2, 0, 5.8);
scene.add(lighthouse);
box(3.1, 1.0, 3.1, 0, 0.5, 0, materials.cream, lighthouse);
box(2.35, 4.6, 2.35, 0, 3.2, 0, materials.cream, lighthouse);
box(2.55, 0.7, 2.55, 0, 5.75, 0, materials.obstacle, lighthouse);
box(1.55, 1.25, 1.55, 0, 6.7, 0, materials.glass, lighthouse);
box(1.9, 0.32, 1.9, 0, 7.48, 0, materials.roof, lighthouse);
// Shared spaces.
const sharedGroup = new THREE.Group();
const obstacleGroup = new THREE.Group();
scene.add(sharedGroup, obstacleGroup);
const spaces = [
{
name: "Harbour Gate",
x: -25,
z: 10,
w: 4.8,
d: 4.8,
routes: ["A", "B"],
labelHeight: 3
},
{
name: "Market Court",
x: -0.5,
z: 2.3,
w: 12.5,
d: 5.2,
routes: ["A", "B"],
labelHeight: 3.7
},
{
name: "Clock Court",
x: -9,
z: -10,
w: 4.4,
d: 4.4,
routes: ["B"],
labelHeight: 3.3
},
{
name: "Harbour Promenade",
x: 0,
z: 10,
w: 62,
d: 3.7,
routes: ["A", "B"],
labelHeight: 3.1
}
];
function addSharedSpace(space) {
box(
space.w,
0.055,
space.d,
space.x,
0.245,
space.z,
materials.shared,
sharedGroup
);
const border = materials.sharedBorder;
box(space.w, 0.07, 0.12, space.x, 0.29, space.z - space.d / 2, border, sharedGroup);
box(space.w, 0.07, 0.12, space.x, 0.29, space.z + space.d / 2, border, sharedGroup);
box(0.12, 0.07, space.d, space.x - space.w / 2, 0.29, space.z, border, sharedGroup);
box(0.12, 0.07, space.d, space.x + space.w / 2, 0.29, space.z, border, sharedGroup);
}
spaces.forEach(addSharedSpace);
// Obstacles are visual and illustrative, not live conditions.
const obstacles = [
{
name: "Step repair",
x: -9,
z: 0,
type: "steps",
routes: ["A", "B"]
},
{
name: "Market awning",
x: 2.8,
z: 2,
type: "awning",
routes: ["A", "B"]
},
{
name: "Bollard pinch",
x: 7,
z: 10,
type: "bollards",
routes: ["A", "B"]
},
{
name: "Loading bay",
x: -25,
z: -5,
type: "loading",
routes: ["B"]
},
{
name: "Works barrier",
x: 23,
z: -10,
type: "works",
routes: ["B"]
}
];
function addBarrier(parent, y = 1.05) {
box(2.5, 0.34, 0.22, 0, y, 0, materials.obstacle, parent);
box(0.16, 1.25, 0.18, -0.95, y - 0.55, 0, materials.obstacleDark, parent);
box(0.16, 1.25, 0.18, 0.95, y - 0.55, 0, materials.obstacleDark, parent);
box(0.42, 0.42, 0.44, -0.62, y, 0.13, materials.cream, parent);
box(0.42, 0.42, 0.44, 0.62, y, 0.13, materials.cream, parent);
}
function addObstacle(obstacle) {
const group = new THREE.Group();
group.position.set(obstacle.x, 0, obstacle.z);
obstacleGroup.add(group);
box(3.1, 0.055, 2.6, 0, 0.31, 0, materials.obstacleFootprint, group);
switch (obstacle.type) {
case "steps":
box(2.3, 0.22, 0.8, 0, 0.39, -0.5, materials.cream, group);
box(2.3, 0.35, 0.8, 0, 0.48, 0, materials.cream, group);
box(2.3, 0.5, 0.8, 0, 0.52, 0.5, materials.cream, group);
addBarrier(group, 1.15);
break;
case "awning":
box(2.6, 0.18, 1.8, 0, 1.65, 0, materials.obstacle, group);
box(0.14, 1.5, 0.14, -1, 0.9, -0.6, materials.obstacleDark, group);
box(0.14, 1.5, 0.14, 1, 0.9, -0.6, materials.obstacleDark, group);
box(0.14, 1.5, 0.14, -1, 0.9, 0.6, materials.obstacleDark, group);
box(0.14, 1.5, 0.14, 1, 0.9, 0.6, materials.obstacleDark, group);
break;
case "bollards":
for (const x of [-0.9, -0.3, 0.3, 0.9]) {
box(0.27, 1.1, 0.27, x, 0.82, 0, materials.obstacleDark, group);
box(0.37, 0.16, 0.37, x, 1.43, 0, materials.obstacle, group);
}
break;
case "loading":
box(1.8, 0.85, 1.25, 0, 0.78, 0, materials.obstacle, group);
box(1.45, 0.55, 0.06, 0, 0.95, 0.66, materials.cream, group);
box(0.45, 0.4, 0.45, -1.1, 0.58, 0.8, materials.obstacleDark, group);
box(0.45, 0.4, 0.45, 1.1, 0.58, 0.8, materials.obstacleDark, group);
break;
case "works":
addBarrier(group, 1.1);
box(0.65, 0.65, 0.65, -1.3, 0.67, 0.7, materials.obstacle, group);
box(0.65, 0.65, 0.65, 1.3, 0.67, 0.7, materials.obstacle, group);
break;
}
}
obstacles.forEach(addObstacle);
// Route geometry.
const routeA = [
[-25, 10],
[-25, 0],
[-9, 0],
[-6, 2],
[4, 2],
[7, 0],
[7, 10],
[-25, 10]
];
const routeB = [
[-25, 10],
[-25, -10],
[-9, -10],
[-9, 0],
[-6, 2],
[4, 2],
[7, 0],
[7, -10],
[23, -10],
[23, 0],
[7, 0],
[7, 10],
[-25, 10]
];
const routeMaterials = {
A: new THREE.MeshStandardMaterial({
color: 0xef654c,
emissive: 0x7a160b,
emissiveIntensity: 0.22,
roughness: 0.65
}),
B: new THREE.MeshStandardMaterial({
color: 0x008f91,
emissive: 0x004849,
emissiveIntensity: 0.25,
roughness: 0.65
})
};
const routeGroups = {
A: new THREE.Group(),
B: new THREE.Group()
};
scene.add(routeGroups.A, routeGroups.B);
function addRouteRibbon(points, offset, material, group) {
for (let i = 0; i < points.length - 1; i++) {
const [x1, z1] = points[i];
const [x2, z2] = points[i + 1];
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const nx = -dz / length;
const nz = dx / length;
const ribbon = box(
length,
0.18,
0.58,
(x1 + x2) / 2 + nx * offset,
0.39,
(z1 + z2) / 2 + nz * offset,
material,
group
);
ribbon.rotation.y = -Math.atan2(dz, dx);
ribbon.castShadow = false;
}
for (const [x, z] of points) {
const node = box(0.68, 0.19, 0.68, x, 0.4, z, material, group);
node.castShadow = false;
}
}
addRouteRibbon(routeA, 0.38, routeMaterials.A, routeGroups.A);
addRouteRibbon(routeB, -0.38, routeMaterials.B, routeGroups.B);
function addStopMarker(group, x, z, material, height = 1.25) {
box(0.14, height, 0.14, x, height / 2 + 0.32, z, material, group);
box(0.75, 0.75, 0.75, x, height + 0.42, z, material, group);
box(0.28, 0.28, 0.28, x, height + 0.93, z, materials.cream, group);
}
[
[-25, 10],
[-9, 0],
[0, 2],
[7, 10]
].forEach(([x, z]) => addStopMarker(routeGroups.A, x, z, routeMaterials.A));
[
[-25, 10],
[-9, -10],
[-1, 2],
[7, -10],
[23, -10],
[7, 0],
[7, 10]
].forEach(([x, z]) => addStopMarker(routeGroups.B, x, z, routeMaterials.B));
// Moving route markers.
const movingMarkers = {};
function createMovingMarker(color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.5
});
box(0.85, 0.85, 0.85, 0, 0.9, 0, material, group);
box(0.34, 0.34, 0.34, 0, 1.48, 0, materials.cream, group);
scene.add(group);
return group;
}
movingMarkers.A = createMovingMarker(0xef654c);
movingMarkers.B = createMovingMarker(0x008f91);
function pathLength(points) {
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
total += Math.hypot(
points[i + 1][0] - points[i][0],
points[i + 1][1] - points[i][1]
);
}
return total;
}
function samplePath(points, progress) {
const total = pathLength(points);
let remaining = THREE.MathUtils.clamp(progress, 0, 1) * total;
for (let i = 0; i < points.length - 1; i++) {
const [x1, z1] = points[i];
const [x2, z2] = points[i + 1];
const length = Math.hypot(x2 - x1, z2 - z1);
if (remaining <= length || i === points.length - 2) {
const t = length === 0 ? 0 : remaining / length;
return new THREE.Vector3(
THREE.MathUtils.lerp(x1, x2, t),
0,
THREE.MathUtils.lerp(z1, z2, t)
);
}
remaining -= length;
}
return new THREE.Vector3(points[0][0], 0, points[0][1]);
}
// HTML labels projected from 3D positions.
const labels = [];
function addLabel(text, position, kind = "landmark", onClick = null) {
const element = document.createElement("div");
element.className = `map-label ${kind}`;
element.textContent = text;
labelsContainer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(...position),
kind,
onClick
});
return element;
}
spaces.forEach((space) => {
addLabel(
space.name,
[space.x, space.labelHeight, space.z],
"space",
() => focusAt(space.x, space.z, 1.8)
);
});
obstacles.forEach((obstacle) => {
addLabel(
`${obstacle.name} · ${obstacle.routes.join("+")}`,
[obstacle.x, 2.4, obstacle.z],
"obstacle",
() => focusAt(obstacle.x, obstacle.z, 2)
);
});
addLabel("Lighthouse", [27.2, 9.2, 5.8], "landmark", () => focusAt(27.2, 5.8, 1.8));
// Populate place and obstacle lists.
const placeList = document.querySelector("#placeList");
spaces.forEach((space) => {
const button = document.createElement("button");
button.className = "place-chip";
button.innerHTML = `
<span>${space.name}</span>
${space.routes.map(route => `<span class="route-tag ${route === "B" ? "b" : ""}">${route}</span>`).join("")}
`;
button.addEventListener("click", () => focusAt(space.x, space.z, 1.8));
placeList.appendChild(button);
});
const obstacleList = document.querySelector("#obstacleList");
obstacles.forEach((obstacle) => {
const button = document.createElement("button");
button.className = "obstacle-chip";
button.innerHTML = `
<span>${obstacle.name}</span>
${obstacle.routes.map(route => `<span class="route-tag ${route === "B" ? "b" : ""}">${route}</span>`).join("")}
`;
button.addEventListener("click", () => focusAt(obstacle.x, obstacle.z, 2));
obstacleList.appendChild(button);
});
// Custom orbit / zoom / pan camera controls, implemented without addons.
const cameraState = {
target: new THREE.Vector3(-2, 0, -1),
yaw: 0.38,
elevation: 0.88,
zoom: 1
};
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const distance = 110;
const horizontal = Math.cos(cameraState.elevation) * distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.elevation) * distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const scale = 0.045 / cameraState.zoom;
cameraState.target.x -= dx * scale;
cameraState.target.z -= dy * scale;
} else {
cameraState.yaw -= dx * 0.005;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.004,
0.38,
1.38
);
}
updateCamera();
});
function stopDragging(event) {
dragging = false;
panning = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.6
);
updateCamera();
},
{ passive: false }
);
function resetView() {
cameraState.target.set(-2, 0, -1);
cameraState.yaw = 0.38;
cameraState.elevation = 0.88;
cameraState.zoom = 1;
updateCamera();
}
function focusAt(x, z, zoom = 1.6) {
cameraState.target.set(x, 0, z);
cameraState.zoom = zoom;
updateCamera();
}
function focusRoute(route) {
const points = route === "A" ? routeA : routeB;
const xs = points.map(point => point[0]);
const zs = points.map(point => point[1]);
const minX = Math.min(...xs);
const maxX = Math.max(...xs);
const minZ = Math.min(...zs);
const maxZ = Math.max(...zs);
cameraState.target.set((minX + maxX) / 2, 0, (minZ + maxZ) / 2);
cameraState.zoom = 1.35;
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetView);
document.querySelector("#zoomIn").addEventListener("click", () => {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom * 1.15, 0.62, 2.6);
updateCamera();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom / 1.15, 0.62, 2.6);
updateCamera();
});
document.querySelectorAll("[data-focus-route]").forEach((button) => {
button.addEventListener("click", () => focusRoute(button.dataset.focusRoute));
});
// Route and layer toggles.
const routeVisibility = { A: true, B: true };
function setRouteVisibility(route, visible) {
routeVisibility[route] = visible;
routeGroups[route].visible = visible;
movingMarkers[route].visible = visible;
document.querySelector(`#card${route}`).dataset.hidden = String(!visible);
}
document.querySelector("#routeA").addEventListener("change", (event) => {
setRouteVisibility("A", event.target.checked);
});
document.querySelector("#routeB").addEventListener("change", (event) => {
setRouteVisibility("B", event.target.checked);
});
document.querySelector("#showSpaces").addEventListener("change", (event) => {
sharedGroup.visible = event.target.checked;
});
document.querySelector("#showObstacles").addEventListener("change", (event) => {
obstacleGroup.visible = event.target.checked;
});
document.querySelector("#showRoutes").addEventListener("change", (event) => {
setRouteVisibility("A", event.target.checked);
setRouteVisibility("B", event.target.checked);
document.querySelector("#routeA").checked = event.target.checked;
document.querySelector("#routeB").checked = event.target.checked;
});
const previewButton = document.querySelector("#previewRoutes");
let animationRunning = false;
let animationStart = 0;
previewButton.addEventListener("click", () => {
animationRunning = !animationRunning;
animationStart = performance.now();
previewButton.textContent = animationRunning
? "Ⅱ Pause route animation"
: "▶ Animate both routes";
});
// Responsive camera frustum.
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
const aspect = width / height;
const frustumHeight = 47;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
// Project labels after each camera update.
const projected = new THREE.Vector3();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const labelsEnabled = document.querySelector("#showLabels").checked;
const spacesEnabled = document.querySelector("#showSpaces").checked;
const obstaclesEnabled = document.querySelector("#showObstacles").checked;
for (const label of labels) {
let visible = labelsEnabled;
if (label.kind === "space") visible = visible && spacesEnabled;
if (label.kind === "obstacle") visible = visible && obstaclesEnabled;
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
visible =
visible &&
projected.z > -1 &&
projected.z < 1 &&
x > -100 &&
x < width + 100 &&
y > -50 &&
y < height + 50;
label.element.style.display = visible ? "block" : "none";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function animate(now) {
requestAnimationFrame(animate);
for (const wave of waveMeshes) {
wave.mesh.position.y = -0.08 + Math.sin(now * 0.0012 + wave.phase) * 0.035;
}
if (animationRunning) {
const elapsed = now - animationStart;
const progressA = (elapsed % 15000) / 15000;
const progressB = ((elapsed + 4500) % 18000) / 18000;
const pointA = samplePath(routeA, progressA);
const pointB = samplePath(routeB, progressB);
movingMarkers.A.position.set(pointA.x, 0.15 + Math.sin(now * 0.006) * 0.08, pointA.z);
movingMarkers.B.position.set(pointB.x, 0.15 + Math.sin(now * 0.006 + 1.4) * 0.08, pointB.z);
} else {
movingMarkers.A.position.set(routeA[0][0], 0.75, routeA[0][1]);
movingMarkers.B.position.set(routeB[0][0], 0.75, routeB[0][1]);
}
renderer.render(scene, camera);
updateLabels();
}
updateCamera();
movingMarkers.A.position.set(routeA[0][0], 0.75, routeA[0][1]);
movingMarkers.B.position.set(routeB[0][0], 0.75, routeB[0][1]);
renderer.render(scene, camera);
document.querySelector("#loading").style.display = "none";
requestAnimationFrame(animate);
</script>
</body>
</html>
```