Prompt specification
Build or customize the Three.js 3D scene "Follow three routes through a river crossing" 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: Follow three routes through a river crossing
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/follow-three-routes-through-a-river-crossing-x2732
Scene Description Prompt:
Trace low-poly boat, pedestrian, and car routes through one Chicago River crossing, showing separate networks and transfer points. Three.js from cdnjs, one HTML file.
Working Three.js Starter (follow-three-routes-through-a-river-crossing-x2732):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chicago River Crossing — Three Networks</title>
<style>
:root {
--bg: #08111d;
--panel: rgba(10, 20, 34, 0.82);
--panel-border: rgba(255, 255, 255, 0.11);
--text: #f4f7fb;
--muted: #9baac0;
--boat: #34d8ff;
--pedestrian: #ff746d;
--car: #ffc44d;
--green: #69e5ad;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
color: inherit;
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.glass {
position: fixed;
z-index: 5;
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px) saturate(125%);
-webkit-backdrop-filter: blur(18px) saturate(125%);
}
.title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 20px 17px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 14px var(--green);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
font-weight: 760;
line-height: 1.03;
letter-spacing: -0.045em;
}
.title-card p {
margin: 10px 0 15px;
max-width: 340px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.control-button {
min-height: 34px;
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition: background 160ms ease, border-color 160ms ease;
}
.control-button:hover {
border-color: rgba(255, 255, 255, 0.25);
background: rgba(255, 255, 255, 0.1);
}
.crossing-card {
top: 22px;
right: 22px;
width: 315px;
padding: 18px;
border-radius: 18px;
}
.crossing-card h2 {
margin: 0 0 5px;
font-size: 20px;
letter-spacing: -0.025em;
}
.crossing-card > p {
margin: 0 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.transfer-list {
display: grid;
gap: 8px;
}
.transfer-row {
display: grid;
grid-template-columns: 27px 1fr;
gap: 10px;
align-items: center;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
}
.transfer-node {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
color: #fff;
font-size: 10px;
font-weight: 850;
}
.transfer-copy strong {
display: block;
margin-bottom: 2px;
font-size: 11px;
}
.transfer-copy span {
color: var(--muted);
font-size: 10px;
}
.schematic-note {
margin-top: 12px !important;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #718198 !important;
font-size: 9px !important;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.route-dock {
bottom: 22px;
left: 50%;
display: flex;
width: min(760px, calc(100vw - 44px));
transform: translateX(-50%);
padding: 8px;
gap: 8px;
border-radius: 18px;
}
.route-card {
position: relative;
display: grid;
flex: 1 1 0;
grid-template-columns: 38px 1fr auto;
gap: 10px;
align-items: center;
min-width: 0;
padding: 11px 12px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 12px;
background: rgba(255, 255, 255, 0.045);
text-align: left;
cursor: pointer;
transition: opacity 160ms ease, background 160ms ease, border-color 160ms ease;
}
.route-card::before {
position: absolute;
inset: 0 auto 0 0;
width: 3px;
content: "";
background: var(--route-color);
opacity: 0;
transition: opacity 160ms ease;
}
.route-card.active {
border-color: color-mix(in srgb, var(--route-color) 38%, transparent);
background: color-mix(in srgb, var(--route-color) 9%, rgba(255, 255, 255, 0.035));
}
.route-card.active::before {
opacity: 1;
}
.route-card:not(.active) {
opacity: 0.48;
}
.route-icon {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border: 1px solid color-mix(in srgb, var(--route-color) 50%, transparent);
border-radius: 11px;
color: var(--route-color);
background: color-mix(in srgb, var(--route-color) 9%, transparent);
font-size: 19px;
}
.route-copy {
min-width: 0;
}
.route-copy strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.route-copy span {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
}
.route-state {
color: var(--route-color);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.map-hint {
position: fixed;
z-index: 4;
bottom: 128px;
left: 50%;
transform: translateX(-50%);
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
background: rgba(8, 17, 29, 0.68);
color: #8797ad;
font-size: 9px;
letter-spacing: 0.035em;
pointer-events: none;
white-space: nowrap;
}
#compass {
position: fixed;
z-index: 4;
right: 26px;
bottom: 28px;
display: grid;
width: 43px;
height: 43px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 50%;
background: rgba(8, 17, 29, 0.72);
pointer-events: none;
}
#north-needle {
position: relative;
width: 10px;
height: 28px;
transition: transform 80ms linear;
}
#north-needle::before {
position: absolute;
top: 0;
left: 2px;
border-right: 3px solid transparent;
border-bottom: 13px solid #fff;
border-left: 3px solid transparent;
content: "";
}
#north-needle::after {
position: absolute;
bottom: 0;
left: 4px;
width: 2px;
height: 13px;
background: #65758a;
content: "";
}
.map-label {
position: absolute;
z-index: 3;
transform: translate(-50%, -100%);
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 6px;
background: rgba(6, 14, 25, 0.78);
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
color: #dce6f2;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
line-height: 1.2;
text-align: center;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
.map-label small {
display: block;
margin-top: 3px;
color: #8292a7;
font-size: 7px;
font-weight: 650;
letter-spacing: 0.06em;
}
.map-label.transfer {
border-color: rgba(255, 255, 255, 0.28);
color: #fff;
}
.map-label.bridge {
border-color: rgba(105, 229, 173, 0.36);
color: #bff7dc;
}
.map-label.river {
border-color: rgba(52, 216, 255, 0.34);
color: #a7ecff;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #08111d;
color: #dce6f2;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 850px) {
.crossing-card {
display: none;
}
.title-card {
width: min(350px, calc(100vw - 32px));
top: 16px;
left: 16px;
}
.route-dock {
bottom: 12px;
width: calc(100vw - 24px);
gap: 5px;
padding: 6px;
}
.route-card {
grid-template-columns: 30px 1fr;
gap: 7px;
padding: 8px;
}
.route-icon {
width: 30px;
height: 30px;
border-radius: 8px;
font-size: 15px;
}
.route-state {
display: none;
}
.route-copy strong {
font-size: 10px;
}
.route-copy span {
font-size: 8px;
}
.map-hint {
bottom: 103px;
font-size: 8px;
}
#compass {
right: 14px;
bottom: 112px;
width: 36px;
height: 36px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels"></div>
<header class="glass title-card">
<div class="eyebrow"><span class="live-dot"></span> Chicago mobility atlas</div>
<h1>One river crossing.<br />Three connected networks.</h1>
<p>
Trace a boat, pedestrian, and car path through the Wells Street crossing.
Color-coded traces reveal separate routes and shared transfer points.
</p>
<div class="button-row">
<button class="control-button" id="play-button" type="button">Pause motion</button>
<button class="control-button" id="reset-button" type="button">Reset view</button>
<button class="control-button" id="top-button" type="button">Top view</button>
</div>
</header>
<aside class="glass crossing-card">
<div class="eyebrow">Crossing focus</div>
<h2>Wells Street Bridge</h2>
<p>
The river trace passes below the bridge while street-level pedestrian
and car routes cross the same central span.
</p>
<div class="transfer-list">
<div class="transfer-row">
<span class="transfer-node">A</span>
<div class="transfer-copy">
<strong>West Quay</strong>
<span>Boat dock ↔ pedestrian riverwalk</span>
</div>
</div>
<div class="transfer-row">
<span class="transfer-node">B</span>
<div class="transfer-copy">
<strong>East Quay</strong>
<span>Boat dock ↔ pedestrian ↔ car network</span>
</div>
</div>
<div class="transfer-row">
<span class="transfer-node">C</span>
<div class="transfer-copy">
<strong>Street Hub</strong>
<span>Pedestrian crossing ↔ street route</span>
</div>
</div>
</div>
<p class="schematic-note">Schematic geometry · relative positions only</p>
</aside>
<div class="map-hint">
Drag to orbit · Shift-drag to pan · Scroll to zoom · Click a route to toggle
</div>
<nav class="glass route-dock" aria-label="Route visibility">
<button
class="route-card active"
type="button"
data-layer="boat"
style="--route-color: var(--boat)"
aria-pressed="true"
>
<span class="route-icon">◒</span>
<span class="route-copy">
<strong>Boat network</strong>
<span>North Branch → South Branch</span>
</span>
<span class="route-state">Visible</span>
</button>
<button
class="route-card active"
type="button"
data-layer="pedestrian"
style="--route-color: var(--pedestrian)"
aria-pressed="true"
>
<span class="route-icon">♙</span>
<span class="route-copy">
<strong>Pedestrian network</strong>
<span>West bank → bridge → Riverwalk</span>
</span>
<span class="route-state">Visible</span>
</button>
<button
class="route-card active"
type="button"
data-layer="car"
style="--route-color: var(--car)"
aria-pressed="true"
>
<span class="route-icon">▰</span>
<span class="route-copy">
<strong>Car network</strong>
<span>West Loop → bridge → Riverfront</span>
</span>
<span class="route-state">Visible</span>
</button>
</nav>
<div id="compass" aria-hidden="true"><div id="north-needle"></div></div>
<div id="loading">Building Chicago River model…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Application state
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const labelsContainer = document.getElementById("labels");
const loading = document.getElementById("loading");
const playButton = document.getElementById("play-button");
const resetButton = document.getElementById("reset-button");
const topButton = document.getElementById("top-button");
const northNeedle = document.getElementById("north-needle");
const COLORS = {
boat: 0x34d8ff,
pedestrian: 0xff746d,
car: 0xffc44d,
transfer: 0xe9f4ff,
ground: 0x101b28,
road: 0x202d3b,
bank: 0x334353,
building: [
0x293b4e,
0x314658,
0x3a5062,
0x263849,
0x405568,
0x2c4052
]
};
let running = true;
let elapsed = 0;
let lastFrame = performance.now();
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111d);
scene.fog = new THREE.Fog(0x08111d, 245, 440);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
700
);
// Custom camera controls: orbit, pan and zoom implemented locally.
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
desiredTarget: new THREE.Vector3(0, 0, 0),
azimuth: 0.78,
desiredAzimuth: 0.78,
polar: 0.73,
desiredPolar: 0.73,
radius: 255,
desiredRadius: 255
};
const clock = new THREE.Clock();
const routeLayers = {};
const transferMarkers = [];
const labels = [];
const agents = [];
const movingDots = [];
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xb9d8ff, 0x17202a, 1.9);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe7c7, 3.2);
sun.position.set(-80, 145, 85);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -175;
sun.shadow.camera.right = 175;
sun.shadow.camera.top = 175;
sun.shadow.camera.bottom = -175;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 350;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x6dbbff, 1.1);
fill.position.set(100, 75, -100);
scene.add(fill);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function V(x, y, z) {
return new THREE.Vector3(x, y, z);
}
function curveFrom(points) {
return new THREE.CatmullRomCurve3(
points,
false,
"centripetal",
0.35
);
}
function ribbonGeometry(curve, width, segments = 100) {
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
const normal = new THREE.Vector3(
-tangent.z,
0,
tangent.x
).normalize();
const left = point.clone().addScaledVector(normal, width * 0.5);
const right = point.clone().addScaledVector(normal, -width * 0.5);
positions.push(left.x, left.y, left.z);
positions.push(right.x, right.y, right.z);
uvs.push(0, t, 1, t);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1);
indices.push(a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createStrip(points, width, material, segments = 100) {
const curve = curveFrom(points);
const mesh = new THREE.Mesh(
ribbonGeometry(curve, width, segments),
material
);
mesh.receiveShadow = true;
return mesh;
}
function offsetCurve(baseCurve, offset) {
const points = [];
for (let i = 0; i <= 50; i++) {
const point = baseCurve.getPointAt(i / 50);
const tangent = baseCurve.getTangentAt(i / 50);
const normal = new THREE.Vector3(
-tangent.z,
0,
tangent.x
).normalize();
point.addScaledVector(normal, offset);
points.push(point);
}
return curveFrom(points);
}
function centerXAtZ(curve, z) {
let closest = curve.getPointAt(0);
let distance = Infinity;
for (let i = 0; i <= 300; i++) {
const point = curve.getPointAt(i / 300);
const d = Math.abs(point.z - z);
if (d < distance) {
distance = d;
closest = point;
}
}
return closest.x;
}
function distanceToRiver(curve, x, z) {
let minimum = Infinity;
for (let i = 0; i <= 140; i++) {
const point = curve.getPointAt(i / 140);
const dx = point.x - x;
const dz = point.z - z;
minimum = Math.min(minimum, dx * dx + dz * dz);
}
return Math.sqrt(minimum);
}
// Deterministic pseudo-random values keep the city layout stable.
let randomSeed = 73921;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function randomRange(min, max) {
return min + (max - min) * random();
}
// -------------------------------------------------------------------------
// Map geometry
// -------------------------------------------------------------------------
const riverControlPoints = [
V(-8, 0.11, -132),
V(-10, 0.11, -102),
V(-15, 0.11, -72),
V(-17, 0.11, -43),
V(-10, 0.11, -21),
V(-5, 0.11, -5),
V(7, 0.11, 18),
V(5, 0.11, 48),
V(16, 0.11, 78),
V(31, 0.11, 132)
];
const riverCurve = curveFrom(riverControlPoints);
const CROSS_Z = -12;
const CROSS_X = centerXAtZ(riverCurve, CROSS_Z);
const CAR_Z = CROSS_Z + 4;
const PED_Z = CROSS_Z - 4;
function buildGround() {
const groundMaterial = new THREE.MeshStandardMaterial({
color: COLORS.ground,
roughness: 0.94,
metalness: 0.03
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(320, 320),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.18;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(320, 32, 0x7aa4c7, 0x49657d);
grid.position.y = -0.105;
grid.material.transparent = true;
grid.material.opacity = 0.085;
scene.add(grid);
const bankMaterial = new THREE.MeshStandardMaterial({
color: COLORS.bank,
roughness: 0.93,
metalness: 0.04
});
const bankUnderlay = createStrip(
riverControlPoints.map((point) => V(point.x, 0.015, point.z)),
43,
bankMaterial,
140
);
scene.add(bankUnderlay);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x087f9a,
emissive: 0x034c61,
emissiveIntensity: 0.36,
roughness: 0.22,
metalness: 0.22
});
const water = createStrip(
riverControlPoints.map((point) => V(point.x, 0.11, point.z)),
33,
waterMaterial,
160
);
scene.add(water);
// Low waterfront walls emphasize the separate river corridor.
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x5b6c79,
roughness: 0.9,
flatShading: true
});
for (const side of [-1, 1]) {
const wallPoints = [];
for (let i = 0; i <= 60; i++) {
const point = riverCurve.getPointAt(i / 60);
const tangent = riverCurve.getTangentAt(i / 60);
const normal = new THREE.Vector3(
-tangent.z,
0,
tangent.x
).normalize();
point.addScaledVector(normal, side * 16.7);
point.y = 0.38;
wallPoints.push(point);
}
scene.add(createStrip(wallPoints, 1.15, wallMaterial, 120));
}
// Sparse angular water highlights.
const waveMaterial = new THREE.LineBasicMaterial({
color: 0x7ee9ff,
transparent: true,
opacity: 0.2
});
for (let i = 0; i < 28; i++) {
const t = randomRange(0.04, 0.96);
const point = riverCurve.getPointAt(t);
const tangent = riverCurve.getTangentAt(t);
const normal = new THREE.Vector3(
-tangent.z,
0,
tangent.x
).normalize();
const offset = randomRange(-11, 11);
const center = point.clone().addScaledVector(normal, offset);
const length = randomRange(2.5, 7);
const geometry = new THREE.BufferGeometry().setFromPoints([
center.clone().addScaledVector(tangent, -length * 0.5),
center.clone().addScaledVector(tangent, length * 0.5)
]);
const wave = new THREE.Line(geometry, waveMaterial);
wave.position.y = 0.18;
scene.add(wave);
}
}
function buildRoadsAndBridge() {
const roadMaterial = new THREE.MeshStandardMaterial({
color: COLORS.road,
roughness: 0.97,
metalness: 0.02
});
const laneMaterial = new THREE.LineBasicMaterial({
color: 0x74899a,
transparent: true,
opacity: 0.25
});
// Riverside roads follow the local river geometry.
for (const offset of [-29, 29]) {
const roadCurve = offsetCurve(riverCurve, offset);
const roadPoints = roadCurve.getPoints(80).map(
(point) => V(point.x, 0.075, point.z)
);
scene.add(createStrip(roadPoints, 7, roadMaterial, 120));
}
// Chicago-like cross streets terminate at the riverbank.
const crossStreetZ = [-92, -61, 30, 66, 98];
for (const z of crossStreetZ) {
const centerX = centerXAtZ(riverCurve, z);
const west = createStrip(
[V(-132, 0.08, z), V(centerX - 24, 0.08, z)],
8,
roadMaterial,
32
);
const east = createStrip(
[V(centerX + 24, 0.08, z), V(132, 0.08, z)],
8,
roadMaterial,
32
);
scene.add(west, east);
for (const start of [-132, centerX - 24]) {
const end = start === -132 ? centerX - 24 : 132;
const laneGeometry = new THREE.BufferGeometry().setFromPoints([
V(start, 0.13, z),
V(end, 0.13, z)
]);
scene.add(new THREE.Line(laneGeometry, laneMaterial));
}
}
// Long north-south streets on the landward sides.
for (const x of [-108, -78, -52, 58, 88, 116]) {
scene.add(
createStrip(
[V(x, 0.08, -137), V(x, 0.08, 137)],
7.5,
roadMaterial,
70
)
);
}
// Bridge deck.
const bridgeMaterial = new THREE.MeshStandardMaterial({
color: 0x3c4c5c,
roughness: 0.82,
metalness: 0.12,
flatShading: true
});
const bridge = new THREE.Mesh(
new THREE.BoxGeometry(80, 0.72, 19),
bridgeMaterial
);
bridge.position.set(CROSS_X, 1.55, CROSS_Z);
bridge.castShadow = true;
bridge.receiveShadow = true;
scene.add(bridge);
// Ramps blend the bridge into the street network.
const crossingRoadPoints = [
V(-138, 0.085, CAR_Z),
V(CROSS_X - 49, 0.085, CAR_Z),
V(CROSS_X - 34, 1.96, CAR_Z),
V(CROSS_X + 34, 1.96, CAR_Z),
V(CROSS_X + 49, 0.085, CAR_Z),
V(138, 0.085, CAR_Z)
];
scene.add(createStrip(crossingRoadPoints, 11, roadMaterial, 110));
// Lightweight bridge rails.
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x8ba0ae,
roughness: 0.62,
metalness: 0.25
});
for (const z of [CROSS_Z - 9.3, CROSS_Z + 9.3]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(80, 0.28, 0.28),
railMaterial
);
rail.position.set(CROSS_X, 2.18, z);
rail.castShadow = true;
scene.add(rail);
}
// Bridge piers leave the central boat navigation corridor open.
for (const offset of [-20, 20]) {
const pier = new THREE.Mesh(
new THREE.BoxGeometry(3.8, 1.35, 5.2),
new THREE.MeshStandardMaterial({
color: 0x536372,
roughness: 0.92,
flatShading: true
})
);
pier.position.set(CROSS_X + offset, 0.63, CROSS_Z);
pier.castShadow = true;
scene.add(pier);
}
// Bascule-like blocks at both ends.
for (const offset of [-35, 35]) {
const counterweight = new THREE.Mesh(
new THREE.BoxGeometry(8.5, 1.45, 13),
new THREE.MeshStandardMaterial({
color: 0x526271,
roughness: 0.86,
flatShading: true
})
);
counterweight.position.set(CROSS_X + offset, 1.45, CROSS_Z);
counterweight.castShadow = true;
scene.add(counterweight);
}
}
function buildBuildings() {
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x182634,
roughness: 0.9,
flatShading: true
});
const buildingGeometry = new THREE.BoxGeometry(1, 1, 1);
const crossStreetZ = [-92, -61, 30, 66, 98];
for (let x = -119; x <= 119; x += 24) {
for (let z = -115; z <= 115; z += 24) {
const jx = x + randomRange(-4, 4);
const jz = z + randomRange(-4, 4);
if (distanceToRiver(riverCurve, jx, jz) < 36) continue;
if (Math.abs(jz - CROSS_Z) < 18) continue;
if (crossStreetZ.some((streetZ) => Math.abs(jz - streetZ) < 8)) {
continue;
}
if (
Math.abs(jx + 108) < 8 ||
Math.abs(jx + 78) < 8 ||
Math.abs(jx + 52) < 8 ||
Math.abs(jx - 58) < 8 ||
Math.abs(jx - 88) < 8 ||
Math.abs(jx - 116) < 8
) {
continue;
}
const width = randomRange(8, 15);
const depth = randomRange(8, 16);
const height = randomRange(5, 21);
const material = new THREE.MeshStandardMaterial({
color: COLORS.building[
Math.floor(random() * COLORS.building.length)
],
roughness: 0.86,
metalness: 0.06,
flatShading: true
});
const building = new THREE.Mesh(
buildingGeometry,
material
);
building.scale.set(width, height, depth);
building.position.set(jx, height * 0.5, jz);
building.rotation.y = randomRange(-0.035, 0.035);
building.castShadow = true;
building.receiveShadow = true;
scene.add(building);
if (random() > 0.62) {
const roof = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.52, 0.7, depth * 0.48),
roofMaterial
);
roof.position.set(
jx + randomRange(-1.5, 1.5),
height + 0.35,
jz + randomRange(-1.5, 1.5)
);
roof.rotation.y = building.rotation.y;
roof.castShadow = true;
scene.add(roof);
}
}
}
// Low-poly street trees.
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x594a3b,
roughness: 1,
flatShading: true
});
const crownMaterial = new THREE.MeshStandardMaterial({
color: 0x2f6959,
roughness: 0.95,
flatShading: true
});
for (let i = 0; i < 34; i++) {
const t = randomRange(0.08, 0.92);
const point = riverCurve.getPointAt(t);
const tangent = riverCurve.getTangentAt(t);
const normal = new THREE.Vector3(
-tangent.z,
0,
tangent.x
).normalize();
const side = i % 2 === 0 ? -1 : 1;
const tree = new THREE.Group();
tree.position.copy(point).addScaledVector(normal, side * 20.2);
tree.position.y = 0;
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.38, 2.6, 5),
trunkMaterial
);
trunk.position.y = 1.3;
trunk.castShadow = true;
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(2.15, 0),
crownMaterial
);
crown.position.y = 3.25;
crown.scale.set(0.86, 1.12, 0.86);
crown.castShadow = true;
tree.add(trunk, crown);
scene.add(tree);
}
}
// -------------------------------------------------------------------------
// Moving-object factories
// -------------------------------------------------------------------------
function createBoat() {
const group = new THREE.Group();
const hullMaterial = new THREE.MeshStandardMaterial({
color: 0xf3f1e6,
roughness: 0.6,
metalness: 0.08,
flatShading: true
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: COLORS.boat,
emissive: 0x0a6173,
emissiveIntensity: 0.4,
roughness: 0.48,
flatShading: true
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x17303d,
roughness: 0.4,
metalness: 0.22,
flatShading: true
});
const hull = new THREE.Mesh(
new THREE.BoxGeometry(4.1, 1.05, 7),
hullMaterial
);
hull.position.y = 0.18;
hull.castShadow = true;
const bow = new THREE.Mesh(
new THREE.ConeGeometry(2.25, 4, 4),
hullMaterial
);
bow.rotation.x = Math.PI / 2;
bow.position.set(0, 0.18, 5.1);
bow.scale.z = 0.48;
bow.castShadow = true;
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(4.18, 0.27, 7.05),
accentMaterial
);
stripe.position.y = 0.55;
const cabin = new THREE.Mesh(
new THREE.BoxGeometry(2.9, 1.5, 3.2),
hullMaterial
);
cabin.position.set(0, 1.42, -0.5);
cabin.castShadow = true;
const windows = new THREE.Mesh(
new THREE.BoxGeometry(2.95, 0.6, 2.45),
darkMaterial
);
windows.position.set(0, 1.65, -0.25);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(3.25, 0.23, 3.5),
accentMaterial
);
roof.position.set(0, 2.24, -0.5);
roof.castShadow = true;
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.08, 0.08, 2.3, 5),
darkMaterial
);
mast.position.set(0, 3.2, -1.2);
group.add(hull, bow, stripe, cabin, windows, roof, mast);
group.scale.setScalar(1.18);
return group;
}
function createPedestrian() {
const group = new THREE.Group();
const coat = new THREE.MeshStandardMaterial({
color: COLORS.pedestrian,
roughness: 0.85,
flatShading: true
});
const dark = new THREE.MeshStandardMaterial({
color: 0x25303c,
roughness: 0.9,
flatShading: true
});
const skin = new THREE.MeshStandardMaterial({
color: 0xd7a77e,
roughness: 0.95,
flatShading: true
});
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.5, 1.15, 5),
coat
);
torso.position.y = 1.35;
torso.castShadow = true;
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.43, 1),
skin
);
head.position.y = 2.25;
head.castShadow = true;
for (const x of [-0.22, 0.22]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.82, 0.2),
dark
);
leg.position.set(x, 0.42, 0);
leg.castShadow = true;
group.add(leg);
}
const arm = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.85, 0.18),
coat
);
arm.position.set(-0.56, 1.36, 0);
arm.rotation.z = -0.12;
arm.castShadow = true;
group.add(torso, head, arm);
return group;
}
function createCar() {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: COLORS.car,
roughness: 0.48,
metalness: 0.18,
flatShading: true
});
const cabinMaterial = new THREE.MeshStandardMaterial({
color: 0x263d4c,
roughness: 0.32,
metalness: 0.25,
flatShading: true
});
const tireMaterial = new THREE.MeshStandardMaterial({
color: 0x10161d,
roughness: 0.95
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(2.3, 0.72, 4.5),
bodyMaterial
);
body.position.y = 0.72;
body.castShadow = true;
const cabin = new THREE.Mesh(
new THREE.BoxGeometry(1.82, 0.78, 2.25),
cabinMaterial
);
cabin.position.set(0, 1.42, -0.25);
cabin.castShadow = true;
const roof = new THREE.Mesh(
new THREE.BoxGeometry(1.9, 0.14, 1.75),
bodyMaterial
);
roof.position.set(0, 1.84, -0.38);
for (const x of [-1.16, 1.16]) {
for (const z of [-1.42, 1.42]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.43, 0.28, 8),
tireMaterial
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.45, z);
wheel.castShadow = true;
group.add(wheel);
}
}
group.add(body, cabin, roof);
return group;
}
// -------------------------------------------------------------------------
// Route construction
// -------------------------------------------------------------------------
function createRouteLayer(name, points, color, speed, agentType, agentCount) {
const layer = new THREE.Group();
layer.name = `${name}-layer`;
routeLayers[name] = layer;
scene.add(layer);
const curve = curveFrom(points);
const underlay = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, 1.18, 6, false),
new THREE.MeshBasicMaterial({
color: 0x07111d,
transparent: true,
opacity: 0.6,
depthWrite: false
})
);
layer.add(underlay);
const traceMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.78,
roughness: 0.35,
metalness: 0.04
});
const trace = new THREE.Mesh(
new THREE.TubeGeometry(curve, 180, 0.52, 7, false),
traceMaterial
);
trace.castShadow = true;
layer.add(trace);
// Moving light packets reinforce route direction.
for (let i = 0; i < 7; i++) {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.68, 8, 6),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.76
})
);
layer.add(dot);
movingDots.push({
mesh: dot,
curve,
phase: i / 7,
speed: speed * 1.35,
layer: name
});
}
// Route endpoint rings.
for (const t of [0, 1]) {
const point = curve.getPointAt(t);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(2.1, 0.25, 6, 18),
new THREE.MeshBasicMaterial({ color })
);
ring.rotation.x = Math.PI / 2;
ring.position.copy(point);
ring.position.y += 0.12;
layer.add(ring);
}
for (let i = 0; i < agentCount; i++) {
let model;
if (agentType === "boat") {
model = createBoat();
} else if (agentType === "pedestrian") {
model = createPedestrian();
} else {
model = createCar();
}
layer.add(model);
agents.push({
mesh: model,
curve,
type: agentType,
phase: i / agentCount,
speed,
lateral: agentType === "pedestrian" ? (i % 2 ? 0.7 : -0.7) : 0
});
}
return curve;
}
function buildRoutes() {
const boatCurve = createRouteLayer(
"boat",
[
V(-8, 0.57, -132),
V(-10, 0.57, -102),
V(-15, 0.57, -72),
V(-17, 0.57, -43),
V(-10, 0.57, -21),
V(CROSS_X, 0.57, CROSS_Z),
V(7, 0.57, 18),
V(5, 0.57, 48),
V(16, 0.57, 78),
V(31, 0.57, 132)
],
COLORS.boat,
0.018,
"boat",
1
);
const pedestrianCurve = createRouteLayer(
"pedestrian",
[
V(-116, 0.44, -68),
V(-83, 0.44, -68),
V(-58, 0.44, -57),
V(-43, 0.44, -35),
V(CROSS_X - 26, 2.16, PED_Z),
V(CROSS_X - 15, 2.16, PED_Z),
V(CROSS_X + 15, 2.16, PED_Z),
V(CROSS_X + 25, 2.16, PED_Z),
V(CROSS_X + 38, 0.44, -29),
V(CROSS_X + 44, 0.44, PED_Z),
V(CROSS_X + 48, 0.44, 23),
V(CROSS_X + 65, 0.44, 47),
V(CROSS_X + 85, 0.44, 62)
],
COLORS.pedestrian,
0.028,
"pedestrian",
8
);
const carCurve = createRouteLayer(
"car",
[
V(-136, 0.48, 44),
V(-103, 0.48, 44),
V(-75, 0.48, 39),
V(-54, 0.48, 22),
V(CROSS_X - 39, 0.48, 3),
V(CROSS_X - 33, 2.03, CAR_Z),
V(CROSS_X - 16, 2.03, CAR_Z),
V(CROSS_X + 17, 2.03, CAR_Z),
V(CROSS_X + 33, 2.03, CAR_Z),
V(CROSS_X + 44, 0.48, -8),
V(CROSS_X + 55, 0.48, -19),
V(CROSS_X + 80, 0.48, -23),
V(136, 0.48, -23)
],
COLORS.car,
0.034,
"car",
6
);
return { boatCurve, pedestrianCurve, carCurve };
}
// -------------------------------------------------------------------------
// Transfer points
// -------------------------------------------------------------------------
function addConnector(points) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color: 0xd9ecff,
dashSize: 1.25,
gapSize: 0.8,
transparent: true,
opacity: 0.62
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
scene.add(line);
}
function createTransferMarker(id, position) {
const group = new THREE.Group();
group.position.copy(position);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.2, 2.4, 6),
new THREE.MeshStandardMaterial({
color: 0xcfe8f7,
emissive: 0x416b82,
emissiveIntensity: 0.35,
roughness: 0.5
})
);
stem.position.y = 1.2;
const diamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.92, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0x78b7d6,
emissiveIntensity: 0.5,
roughness: 0.35,
flatShading: true
})
);
diamond.position.y = 2.65;
diamond.castShadow = true;
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.65, 0.16, 6, 24),
new THREE.MeshBasicMaterial({
color: COLORS.transfer,
transparent: true,
opacity: 0.75
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.18;
group.add(stem, diamond, ring);
scene.add(group);
transferMarkers.push({
group,
diamond,
ring,
phase: transferMarkers.length * 0.8
});
}
function buildTransfers() {
const A = V(CROSS_X - 20, 0.22, PED_Z);
const B = V(CROSS_X + 20, 0.22, PED_Z);
const C = V(CROSS_X + 44, 0.22, CAR_Z);
createTransferMarker("A", A);
createTransferMarker("B", B);
createTransferMarker("C", C);
addConnector([
V(CROSS_X - 16, 0.45, CROSS_Z),
V(CROSS_X - 19, 0.65, PED_Z),
A.clone().add(V(0, 0.5, 0))
]);
addConnector([
V(CROSS_X + 16, 0.45, CROSS_Z),
V(CROSS_X + 19, 0.65, PED_Z),
B.clone().add(V(0, 0.5, 0))
]);
addConnector([
V(CROSS_X + 25, 2.18, PED_Z),
V(CROSS_X + 35, 1.4, PED_Z),
C.clone().add(V(0, 0.5, 0))
]);
addConnector([
V(CROSS_X + 30, 2.05, CAR_Z),
V(CROSS_X + 39, 1.1, CAR_Z),
C.clone().add(V(0, 0.5, 0))
]);
}
// -------------------------------------------------------------------------
// HTML labels projected from world-space anchors
// -------------------------------------------------------------------------
function addLabel(title, subtitle, anchor, className = "") {
const element = document.createElement("div");
element.className = `map-label ${className}`.trim();
element.innerHTML = `${title}${subtitle ? `<small>${subtitle}</small>` : ""}`;
labelsContainer.appendChild(element);
labels.push({ element, anchor });
}
function buildLabels() {
addLabel(
"Wells Street Bridge",
"Central crossing",
V(CROSS_X, 5.1, CROSS_Z),
"bridge"
);
addLabel(
"Chicago River",
"North + South branches",
V(-13, 1.1, 37),
"river"
);
addLabel(
"West Quay",
"Transfer A",
V(CROSS_X - 20, 3.1, PED_Z),
"transfer"
);
addLabel(
"East Quay",
"Transfer B",
V(CROSS_X + 20, 3.1, PED_Z),
"transfer"
);
addLabel(
"Street Hub",
"Transfer C",
V(CROSS_X + 44, 3.1, CAR_Z),
"transfer"
);
addLabel(
"North Branch",
"Boat corridor",
V(-13, 1, -101),
"river"
);
addLabel(
"South Branch",
"Boat corridor",
V(17, 1, 88),
"river"
);
}
// -------------------------------------------------------------------------
// Custom camera interaction
// -------------------------------------------------------------------------
const pointers = new Map();
let pinchDistance = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
const state = cameraState;
const smoothing = 0.12;
state.azimuth += (state.desiredAzimuth - state.azimuth) * smoothing;
state.polar += (state.desiredPolar - state.polar) * smoothing;
state.radius += (state.desiredRadius - state.radius) * smoothing;
state.target.lerp(state.desiredTarget, smoothing);
const sinPolar = Math.sin(state.polar);
const cosPolar = Math.cos(state.polar);
camera.position.set(
state.target.x + state.radius * sinPolar * Math.sin(state.azimuth),
state.target.y + state.radius * cosPolar,
state.target.z + state.radius * sinPolar * Math.cos(state.azimuth)
);
camera.lookAt(state.target);
}
function panCamera(deltaX, deltaY) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const scale = cameraState.radius * 0.00155;
cameraState.desiredTarget.addScaledVector(
right,
-deltaX * scale
);
cameraState.desiredTarget.addScaledVector(
forward,
deltaY * scale
);
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY,
shift: event.shiftKey,
button: event.button
});
if (pointers.size === 2) {
pinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
if (previous.shift || previous.button === 2) {
panCamera(dx, dy);
} else {
cameraState.desiredAzimuth -= dx * 0.0055;
cameraState.desiredPolar = clamp(
cameraState.desiredPolar + dy * 0.0047,
0.18,
1.38
);
}
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
cameraState.desiredRadius = clamp(
cameraState.desiredRadius * (pinchDistance / distance),
90,
390
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"contextmenu",
(event) => event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
90,
390
);
},
{ passive: false }
);
function resetView() {
cameraState.desiredAzimuth = 0.78;
cameraState.desiredPolar = 0.73;
cameraState.desiredRadius = 255;
cameraState.desiredTarget.set(0, 0, 0);
}
function topView() {
cameraState.desiredAzimuth = 0;
cameraState.desiredPolar = 0.19;
cameraState.desiredRadius = 235;
cameraState.desiredTarget.set(0, 0, 0);
}
resetButton.addEventListener("click", resetView);
topButton.addEventListener("click", topView);
// -------------------------------------------------------------------------
// UI and animation
// -------------------------------------------------------------------------
playButton.addEventListener("click", () => {
running = !running;
playButton.textContent = running ? "Pause motion" : "Play motion";
});
document.querySelectorAll(".route-card").forEach((button) => {
button.addEventListener("click", () => {
const layerName = button.dataset.layer;
const layer = routeLayers[layerName];
const active = !layer.visible;
layer.visible = active;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
const state = button.querySelector(".route-state");
state.textContent = active ? "Visible" : "Hidden";
});
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "t") topView();
});
function updateRouteAnimation() {
for (const agent of agents) {
if (!routeLayers[agent.type === "boat" ? "boat" :
agent.type === "pedestrian" ? "pedestrian" : "car"].visible) {
continue;
}
const t = (agent.phase + elapsed * agent.speed) % 1;
const point = agent.curve.getPointAt(t);
const tangent = agent.curve.getTangentAt(t);
const side = new THREE.Vector3(
-tangent.z,
0,
tangent.x
).normalize();
point.addScaledVector(side, agent.lateral);
agent.mesh.position.copy(point);
agent.mesh.rotation.y = Math.atan2(tangent.x, tangent.z);
if (agent.type === "boat") {
agent.mesh.position.y += Math.sin(elapsed * 2.8) * 0.11;
agent.mesh.rotation.z = Math.sin(elapsed * 2.1) * 0.018;
agent.mesh.rotation.x = Math.cos(elapsed * 1.7) * 0.012;
} else if (agent.type === "pedestrian") {
agent.mesh.position.y -= 0.39;
agent.mesh.rotation.z = Math.sin(elapsed * 8 + agent.phase * 10) * 0.035;
agent.mesh.position.y += Math.abs(Math.sin(elapsed * 8 + agent.phase * 10)) * 0.05;
} else {
agent.mesh.position.y -= 0.42;
}
}
for (const dot of movingDots) {
if (!routeLayers[dot.layer].visible) continue;
const t = (dot.phase + elapsed * dot.speed) % 1;
dot.mesh.position.copy(dot.curve.getPointAt(t));
dot.mesh.scale.setScalar(0.78 + Math.sin(elapsed * 5 + dot.phase * 8) * 0.12);
}
}
function updateTransferAnimation() {
for (const marker of transferMarkers) {
const pulse = (elapsed * 0.8 + marker.phase) % 1;
marker.ring.scale.setScalar(1 + pulse * 1.25);
marker.ring.material.opacity = 0.7 * (1 - pulse);
marker.diamond.rotation.y = elapsed * 1.1;
marker.diamond.position.y = 2.65 + Math.sin(elapsed * 2.2 + marker.phase) * 0.15;
}
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const projected = label.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.1 &&
projected.y < 1.1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastFrame) / 1000, 0.05);
lastFrame = now;
if (running) {
elapsed += delta;
}
updateCamera();
updateRouteAnimation();
updateTransferAnimation();
updateLabels();
northNeedle.style.transform =
`rotate(${-cameraState.azimuth * 180 / Math.PI}deg)`;
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
// Build the scene.
buildGround();
buildRoadsAndBridge();
buildBuildings();
buildRoutes();
buildTransfers();
buildLabels();
updateCamera();
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
requestAnimationFrame(animate);
</script>
</body>
</html>
```