Prompt specification
Build or customize the Three.js 3D scene "Compare ferry and road access to one district" 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: Compare ferry and road access to one district
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-ferry-and-road-access-to-one-district-x2932
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing two ways to reach a destination in a voxel waterfront district. Include a ferry landing, a road arrival point, several blocks of shops, and the final destination inside the district rather than directly on the shore. Let users choose ferry or road travel using explicitly stated schematic travel times. Animate the full sequence, including any transfer and the final walking segment, and display total elapsed time only after the traveler reaches the destination. Keep the district geometry unchanged between comparisons so the route choice, transfer time, and walking distance explain the result.
Working Three.js Starter (compare-ferry-and-road-access-to-one-district-x2932):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Harbor District — Two Ways to the Same Destination</title>
<style>
:root {
--bg: #08151f;
--panel: rgba(9, 24, 35, 0.92);
--panel-2: rgba(15, 37, 51, 0.92);
--line: rgba(183, 220, 231, 0.16);
--text: #eef8f8;
--muted: #9db6bd;
--ferry: #47e0c1;
--road: #ffb35c;
--destination: #ff7272;
--shadow: 0 18px 55px rgba(0, 0, 0, 0.36);
}
* {
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 {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
}
.brand {
max-width: 590px;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: #c8e5e7;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--ferry);
box-shadow: 0 0 16px rgba(71, 224, 193, 0.75);
}
h1 {
margin: 8px 0 7px;
font-size: clamp(26px, 3.1vw, 47px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 780;
}
.subtitle {
margin: 0;
max-width: 560px;
color: #bdd0d4;
font-size: 14px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: 430px;
}
.legend-item,
.camera-help {
border: 1px solid var(--line);
background: rgba(7, 21, 31, 0.76);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
border-radius: 10px;
color: #c8dade;
font-size: 11px;
padding: 8px 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 18px;
height: 3px;
border-radius: 3px;
background: currentColor;
}
.swatch.ferry {
color: var(--ferry);
}
.swatch.road {
color: var(--road);
}
.swatch.destination {
color: var(--destination);
}
.bottom {
position: absolute;
left: 50%;
bottom: 18px;
width: min(1120px, calc(100% - 28px));
transform: translateX(-50%);
pointer-events: auto;
}
.route-panel {
border: 1px solid rgba(183, 220, 231, 0.2);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
overflow: hidden;
}
.panel-heading {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
padding: 14px 17px 10px;
border-bottom: 1px solid var(--line);
}
.panel-heading strong {
font-size: 13px;
letter-spacing: 0.01em;
}
.fixed-note {
color: var(--muted);
font-size: 11px;
text-align: right;
}
.route-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
padding: 10px;
}
.route-button {
position: relative;
min-height: 118px;
padding: 14px 15px 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(18, 42, 55, 0.7);
color: var(--text);
text-align: left;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.route-button:hover {
transform: translateY(-2px);
background: rgba(24, 52, 67, 0.92);
}
.route-button:focus-visible {
outline: 2px solid white;
outline-offset: 3px;
}
.route-button.ferry.active {
border-color: rgba(71, 224, 193, 0.8);
box-shadow: inset 0 0 0 1px rgba(71, 224, 193, 0.18);
}
.route-button.road.active {
border-color: rgba(255, 179, 92, 0.8);
box-shadow: inset 0 0 0 1px rgba(255, 179, 92, 0.18);
}
.route-button.completed::after {
content: "✓";
position: absolute;
top: 11px;
right: 12px;
width: 24px;
height: 24px;
display: grid;
place-items: center;
border-radius: 50%;
background: rgba(255, 255, 255, 0.11);
color: white;
font-size: 13px;
}
.route-title {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
font-size: 17px;
font-weight: 800;
letter-spacing: -0.02em;
}
.route-icon {
width: 28px;
height: 28px;
display: grid;
place-items: center;
border-radius: 8px;
font-size: 16px;
}
.ferry .route-icon {
color: var(--ferry);
background: rgba(71, 224, 193, 0.12);
}
.road .route-icon {
color: var(--road);
background: rgba(255, 179, 92, 0.12);
}
.times {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.time-chip {
display: inline-flex;
align-items: center;
min-height: 25px;
padding: 4px 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 7px;
background: rgba(255, 255, 255, 0.045);
color: #d4e1e3;
font-size: 10px;
white-space: nowrap;
}
.arrival {
display: none;
margin-top: 9px;
color: white;
font-size: 11px;
font-weight: 800;
}
.arrival.visible {
display: block;
}
.status-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 14px;
align-items: center;
min-height: 76px;
padding: 12px 16px 14px;
border-top: 1px solid var(--line);
background: rgba(4, 15, 23, 0.28);
}
.status-main {
min-width: 0;
}
.status-kicker {
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.status-title {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 14px;
font-weight: 760;
}
.progress-track {
position: relative;
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
}
.progress-fill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #4de3c4, #b5fff1);
transition: width 80ms linear;
}
.road-run .progress-fill {
background: linear-gradient(90deg, #f6a84f, #ffe0aa);
}
.status-side {
display: flex;
align-items: center;
gap: 7px;
}
.control {
min-height: 34px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
color: #dce8e9;
font-size: 10px;
font-weight: 700;
cursor: pointer;
white-space: nowrap;
}
.control:hover {
background: rgba(255, 255, 255, 0.11);
}
.control:disabled {
opacity: 0.38;
cursor: default;
}
.control.active {
border-color: rgba(255, 255, 255, 0.45);
background: rgba(255, 255, 255, 0.13);
color: white;
}
.completion {
display: none;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-top: 10px;
padding: 12px 14px;
border: 1px solid rgba(255, 114, 114, 0.34);
border-radius: 12px;
background: linear-gradient(90deg, rgba(92, 28, 35, 0.62), rgba(30, 42, 52, 0.78));
}
.completion.visible {
display: flex;
}
.completion-copy strong {
display: block;
margin-bottom: 2px;
font-size: 13px;
}
.completion-copy span {
color: #c7d4d7;
font-size: 11px;
}
.total-time {
flex: 0 0 auto;
text-align: right;
}
.total-time small {
display: block;
color: #b8c8cc;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.total-time strong {
color: white;
font-size: 24px;
letter-spacing: -0.04em;
}
.comparison {
display: none;
margin-top: 10px;
padding: 13px 15px;
border: 1px solid rgba(71, 224, 193, 0.24);
border-radius: 12px;
background: rgba(9, 27, 37, 0.9);
box-shadow: var(--shadow);
}
.comparison.visible {
display: block;
}
.comparison-title {
margin-bottom: 6px;
font-size: 12px;
font-weight: 850;
}
.comparison-text {
color: #bdcdd1;
font-size: 11px;
line-height: 1.55;
}
.comparison-text b {
color: white;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #08151f;
color: #c8dcdf;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.subtitle {
max-width: 390px;
font-size: 12px;
}
.legend,
.camera-help {
display: none;
}
.bottom {
bottom: 10px;
width: calc(100% - 18px);
}
.panel-heading {
padding: 11px 12px 8px;
}
.fixed-note {
max-width: 170px;
font-size: 9px;
}
.route-grid {
grid-template-columns: 1fr;
gap: 7px;
padding: 7px;
}
.route-button {
min-height: 0;
padding: 10px 12px;
}
.route-title {
margin-bottom: 6px;
font-size: 14px;
}
.route-icon {
width: 23px;
height: 23px;
font-size: 13px;
}
.time-chip {
min-height: 22px;
padding: 3px 6px;
font-size: 9px;
}
.status-row {
grid-template-columns: 1fr;
gap: 9px;
padding: 10px 12px 12px;
}
.status-side {
overflow-x: auto;
}
.completion {
align-items: flex-start;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="topbar">
<div class="brand">
<div class="eyebrow">Harbor District / Route Study</div>
<h1>Two ways to the same place.</h1>
<p class="subtitle">
A fixed voxel waterfront district. Choose the ferry or the road,
then watch every crossing, transfer, and final walk. Times are schematic.
</p>
</div>
<div>
<div class="legend">
<div class="legend-item"><span class="swatch ferry"></span> Ferry route</div>
<div class="legend-item"><span class="swatch road"></span> Road route</div>
<div class="legend-item"><span class="swatch destination"></span> Destination</div>
</div>
<div class="camera-help" style="margin-top:8px;text-align:right">
Drag to orbit · Wheel to zoom · Shift-drag to pan
</div>
</div>
</header>
<div class="bottom">
<section class="route-panel" aria-label="Travel route controls">
<div class="panel-heading">
<strong>Choose an arrival route</strong>
<div class="fixed-note">
District geometry stays fixed. Only the traveler and route highlight change.
</div>
</div>
<div class="route-grid">
<button class="route-button ferry" id="ferryButton" type="button">
<div class="route-title">
<span class="route-icon">⛴</span>
<span>Take the ferry</span>
</div>
<div class="times">
<span class="time-chip">8 min crossing</span>
<span class="time-chip">3 min transfer</span>
<span class="time-chip">5 min walk · ~420 m</span>
</div>
<div class="arrival"></div>
</button>
<button class="route-button road" id="roadButton" type="button">
<div class="route-title">
<span class="route-icon">▰</span>
<span>Arrive by road</span>
</div>
<div class="times">
<span class="time-chip">10 min road approach</span>
<span class="time-chip">2 min park + transfer</span>
<span class="time-chip">7 min walk · ~590 m</span>
</div>
<div class="arrival"></div>
</button>
</div>
<div class="status-row" id="statusRow">
<div class="status-main">
<div class="status-kicker" id="statusKicker">Ready to travel</div>
<div class="status-title" id="statusTitle" aria-live="polite">
Select a route to begin the full arrival sequence.
</div>
<div class="progress-track">
<div class="progress-fill" id="progressFill"></div>
</div>
</div>
<div class="status-side">
<button class="control" id="pauseButton" type="button" disabled>Pause</button>
<button class="control" id="replayButton" type="button" disabled>Replay</button>
<button class="control active" id="overviewButton" type="button">Overview</button>
<button class="control" id="followButton" type="button">Follow traveler</button>
</div>
</div>
</section>
<div class="completion" id="completion">
<div class="completion-copy">
<strong>Destination reached</strong>
<span id="completionCopy">The traveler has arrived inside the district.</span>
</div>
<div class="total-time">
<small>Total elapsed</small>
<strong id="totalTime">—</strong>
</div>
</div>
<div class="comparison" id="comparison">
<div class="comparison-title">Arrival-to-arrival comparison</div>
<div class="comparison-text" id="comparisonText"></div>
</div>
</div>
</div>
<div class="loading" id="loading">Building harbor district…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1d2a);
scene.fog = new THREE.Fog(0x0b1d2a, 95, 185);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
300
);
const hemisphere = new THREE.HemisphereLight(0xbfe8ff, 0x26312c, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.0);
sun.position.set(35, 58, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -85;
sun.shadow.camera.right = 85;
sun.shadow.camera.top = 70;
sun.shadow.camera.bottom = -70;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x6fc8ff, 0.7);
fill.position.set(-30, 20, -20);
scene.add(fill);
const overviewTarget = new THREE.Vector3(7, 0, -10);
const cameraTarget = overviewTarget.clone();
const cameraState = {
radius: 94,
theta: 0.77,
phi: 0.86,
follow: false,
dragging: false,
lastX: 0,
lastY: 0,
pointers: new Map(),
pinchDistance: 0
};
function updateCamera(immediate = false) {
const desiredTarget = cameraState.follow
? traveler.position.clone().add(new THREE.Vector3(0, 0.4, 0))
: overviewTarget;
const alpha = immediate ? 1 : 0.075;
cameraTarget.lerp(desiredTarget, alpha);
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
const desiredPosition = new THREE.Vector3().setFromSpherical(spherical).add(cameraTarget);
if (immediate) {
camera.position.copy(desiredPosition);
} else {
camera.position.lerp(desiredPosition, 0.09);
}
camera.lookAt(cameraTarget);
}
// Direct camera controls: orbit, zoom, pan, and touch pinch.
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
cameraState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (cameraState.pointers.size === 1) {
cameraState.dragging = true;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
} else if (cameraState.pointers.size === 2) {
const [a, b] = [...cameraState.pointers.values()];
cameraState.pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!cameraState.pointers.has(event.pointerId)) return;
cameraState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (cameraState.pointers.size === 2) {
const [a, b] = [...cameraState.pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (cameraState.pinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (cameraState.pinchDistance / Math.max(distance, 1)),
24,
145
);
}
cameraState.pinchDistance = distance;
return;
}
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.lastX;
const dy = event.clientY - cameraState.lastY;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
if (event.shiftKey) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const panScale = cameraState.radius * 0.0014;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(forward, -dy * panScale);
} else {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.42,
1.38
);
}
});
function releasePointer(event) {
cameraState.pointers.delete(event.pointerId);
cameraState.dragging = cameraState.pointers.size > 0;
if (cameraState.pointers.size < 2) cameraState.pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
24,
145
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Modeling helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, roughness = 0.82, metalness = 0.0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({ color, roughness, metalness })
);
}
return materialCache.get(key);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
typeof color === "number" || typeof color === "string"
? material(color, options.roughness ?? 0.82, options.metalness ?? 0)
: color
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.rotationY) mesh.rotation.y = options.rotationY;
parent.add(mesh);
return mesh;
}
function makeLabel(title, subtitle, accent = "#ffffff", scale = 1) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 180;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(7, 23, 33, 0.92)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = accent;
ctx.lineWidth = 6;
ctx.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
ctx.fillStyle = accent;
ctx.fillRect(25, 25, 12, 130);
ctx.fillStyle = "#f5ffff";
ctx.font = "800 47px system-ui, sans-serif";
ctx.fillText(title, 58, 77);
ctx.fillStyle = "#b9cdd2";
ctx.font = "600 29px system-ui, sans-serif";
ctx.fillText(subtitle, 58, 128);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(12 * scale, 3.375 * scale, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeShopSign(text, background, foreground = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(255,255,255,0.22)";
ctx.lineWidth = 8;
ctx.strokeRect(4, 4, canvas.width - 8, canvas.height - 8);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 50px system-ui, sans-serif";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function createLine(points, color, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const mat = dashed
? new THREE.LineDashedMaterial({
color,
dashSize: 1.25,
gapSize: 0.8,
transparent: true,
opacity: 0.9,
depthTest: true
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthTest: true
});
const line = new THREE.Line(geometry, mat);
if (dashed) line.computeLineDistances();
scene.add(line);
return line;
}
function polylineData(points) {
const lengths = [0];
let total = 0;
for (let i = 1; i < points.length; i++) {
total += points[i].distanceTo(points[i - 1]);
lengths.push(total);
}
return { points, lengths, total };
}
function samplePolyline(data, t) {
const target = THREE.MathUtils.clamp(t, 0, 1) * data.total;
let index = 1;
while (
index < data.lengths.length - 1 &&
data.lengths[index] < target
) {
index++;
}
const start = data.points[index - 1];
const end = data.points[index];
const segmentLength = data.lengths[index] - data.lengths[index - 1];
const localT = segmentLength
? (target - data.lengths[index - 1]) / segmentLength
: 0;
const position = new THREE.Vector3().lerpVectors(start, end, localT);
const tangent = new THREE.Vector3().subVectors(end, start).normalize();
return { position, tangent };
}
function smooth(t) {
return t * t * (3 - 2 * t);
}
// -------------------------------------------------------------------------
// Static waterfront district
// -------------------------------------------------------------------------
const district = new THREE.Group();
scene.add(district);
// Water and land base.
const water = new THREE.Mesh(
new THREE.PlaneGeometry(190, 145),
new THREE.MeshStandardMaterial({
color: 0x167f9e,
roughness: 0.28,
metalness: 0.08
})
);
water.rotation.x = -Math.PI / 2;
water.position.set(5, -0.34, 43);
water.receiveShadow = true;
scene.add(water);
box(district, 60, 1.2, 38, 3, -0.6, -14, 0xb8b3a1);
box(district, 60, 1.7, 1.3, 3, -0.48, 5, 0x6d746f);
box(district, 59.5, 0.18, 37.5, 3, 0.03, -14, 0x9eaa9e);
// Quay edge blocks.
for (let x = -26; x <= 31; x += 4) {
box(district, 3.75, 0.48, 0.55, x, 0.25, 5.1, 0xd1cbb6);
}
// Road and sidewalk grid.
const sidewalk = 0xc8c5b7;
const asphalt = 0x46555c;
function roadSegment(width, depth, x, z, horizontal = true) {
box(district, width, 0.11, depth, x, 0.13, z, sidewalk, { castShadow: false });
box(district, width - 0.6, 0.13, depth - 0.6, x, 0.16, z, asphalt, { castShadow: false });
}
roadSegment(55, 4.8, 3.5, -7);
roadSegment(55, 4.8, 3.5, -18);
roadSegment(12, 3.5, 21, -21);
roadSegment(30, 8.5, 45, 1, false);
roadSegment(3.8, 30, -12, -14, false);
roadSegment(3.8, 30, 4, -14, false);
roadSegment(3.8, 30, 15, -14, false);
roadSegment(4.2, 29, 26, -13.5, false);
// Lane markings.
for (let x = -22; x < 29; x += 5) {
box(district, 2.0, 0.05, 0.18, x, 0.245, -7, 0xe9d79c, { castShadow: false });
box(district, 2.0, 0.05, 0.18, x, 0.245, -18, 0xe9d79c, { castShadow: false });
}
for (let x = 34; x < 60; x += 5) {
box(district, 2.2, 0.05, 0.18, x, 0.245, 1, 0xffd58a, { castShadow: false });
}
// Ferry landing and dock.
const dock = new THREE.Group();
scene.add(dock);
for (let x = -16; x <= -8; x += 2) {
box(dock, 1.8, 0.45, 6.4, x, 0.02, 7.5, 0x8b6744);
}
box(dock, 9.6, 0.3, 1.0, -12, 0.28, 10.7, 0x9b754d);
box(dock, 0.45, 3.2, 0.45, -16.3, 1.6, 10.3, 0x4d4b43);
box(dock, 0.45, 3.2, 0.45, -7.7, 1.6, 10.3, 0x4d4b43);
box(dock, 9.2, 0.45, 0.55, -12, 3.1, 10.3, 0x4d4b43);
box(dock, 4.8, 0.18, 0.8, -12, 3.45, 10.3, 0x47e0c1);
const landingLabel = makeLabel("FERRY LANDING", "Transfer point · 3 min", "#47e0c1", 0.8);
landingLabel.position.set(-12, 7, 8.5);
scene.add(landingLabel);
const landingPad = new THREE.Mesh(
new THREE.CylinderGeometry(1.45, 1.45, 0.1, 24),
new THREE.MeshBasicMaterial({
color: 0x47e0c1,
transparent: true,
opacity: 0.5
})
);
landingPad.position.set(-12, 0.38, 5);
scene.add(landingPad);
// Road arrival parking bay.
const arrivalLabel = makeLabel("ROAD ARRIVAL", "Park + transfer · 2 min", "#ffb35c", 0.8);
arrivalLabel.position.set(42, 7, 1);
scene.add(arrivalLabel);
const roadPad = new THREE.Mesh(
new THREE.CylinderGeometry(1.45, 1.45, 0.1, 24),
new THREE.MeshBasicMaterial({
color: 0xffb35c,
transparent: true,
opacity: 0.55
})
);
roadPad.position.set(41, 0.32, 1);
scene.add(roadPad);
box(district, 0.4, 5.0, 0.4, 38, 2.5, -4.8, 0x43525a);
box(district, 3.4, 1.5, 0.35, 38, 4.65, -4.8, 0xffb35c);
box(district, 2.7, 0.8, 0.38, 38, 4.65, -4.58, 0x26363d);
// Shop blocks.
const shopColors = [
0xe96b64,
0xe8a64b,
0x5db6a7,
0x6d8ed8,
0xba78b1,
0x74b768,
0xd77d91,
0x58a6b9
];
const shopNames = [
"TIDE GOODS",
"BAY CAFE",
"COBALT",
"PIER PIE",
"DOCK & CO",
"NORD",
"MARKET",
"LAMP"
];
function makeBuilding(x, z, width, depth, height, color, name, index) {
const group = new THREE.Group();
district.add(group);
box(group, width, height, depth, x, height / 2 + 0.25, z, color);
box(group, width + 0.35, 0.35, depth + 0.35, x, height + 0.45, z, 0x33444d);
box(group, width * 0.32, 0.85, depth * 0.28, x - width * 0.18, height + 0.95, z, 0x71838a);
box(group, width * 0.16, 0.55, depth * 0.18, x + width * 0.22, height + 0.75, z, 0x4c5b62);
// Front windows and doorway.
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xb7e9f0,
emissive: 0x3d6975,
emissiveIntensity: 0.45,
roughness: 0.4
});
box(
group,
0.85,
0.9,
0.08,
x - width * 0.28,
2.1,
z + depth / 2 + 0.045,
windowMaterial
);
box(
group,
0.85,
0.9,
0.08,
x + width * 0.28,
2.1,
z + depth / 2 + 0.045,
windowMaterial
);
box(group, 1.1, 1.9, 0.12, x, 1.2, z + depth / 2 + 0.06, 0x273b43);
// Awning.
for (let i = 0; i < 6; i++) {
box(
group,
width / 6,
0.23,
0.75,
x - width / 2 + width / 12 + i * (width / 6),
2.95,
z + depth / 2 + 0.3,
i % 2 === 0 ? 0xf7e8c7 : shopColors[(index + i) % shopColors.length],
{ castShadow: false }
);
}
const signTexture = makeShopSign(
name,
`#${new THREE.Color(color).getHexString()}`
);
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(width * 0.78, 1.25),
new THREE.MeshBasicMaterial({ map: signTexture })
);
sign.position.set(x, height * 0.67, z + depth / 2 + 0.08);
group.add(sign);
}
const buildings = [
[-17, -2, 6.2, 6.2, 5.2],
[-3, -2, 6.2, 6.2, 6.8],
[-17, -12, 6.2, 6.2, 6.1],
[-3, -12, 6.2, 6.2, 4.7],
[10, -12, 6.2, 6.2, 7.4],
[-17, -26, 6.2, 6.2, 4.9],
[-3, -26, 6.2, 6.2, 6.5]
];
buildings.forEach((b, i) => {
makeBuilding(b[0], b[1], b[2], b[3], b[4], shopColors[i % shopColors.length], shopNames[i], i);
});
// Destination building, visibly inland rather than on the waterfront.
const destination = new THREE.Group();
district.add(destination);
box(destination, 6.8, 7.5, 6.8, 9, 4, -26, 0xe66363);
box(destination, 7.4, 0.45, 7.4, 9, 8, -26, 0x354750);
box(destination, 2.0, 2.4, 2.0, 9, 9.25, -26, 0xf7d78e);
box(destination, 0.25, 4.0, 0.25, 9, 12.1, -26, 0x4a5a60);
box(destination, 2.8, 1.3, 0.16, 9, 13.25, -26, 0xff7272);
box(destination, 1.35, 2.4, 0.15, 9, 1.45, -22.55, 0x253945);
box(destination, 4.8, 0.16, 1.0, 9, 2.8, -22.3, 0xffd7a3);
const destinationRing = new THREE.Mesh(
new THREE.TorusGeometry(2.45, 0.12, 8, 48),
new THREE.MeshBasicMaterial({
color: 0xff7272,
transparent: true,
opacity: 0.88
})
);
destinationRing.rotation.x = Math.PI / 2;
destinationRing.position.set(9, 0.31, -26);
scene.add(destinationRing);
const destinationBeam = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 1.2, 13, 18, 1, true),
new THREE.MeshBasicMaterial({
color: 0xff7272,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide,
depthWrite: false
})
);
destinationBeam.position.set(9, 6.5, -26);
scene.add(destinationBeam);
const destinationLabel = makeLabel(
"DESTINATION",
"Inside the district · same for both",
"#ff7272",
0.92
);
destinationLabel.position.set(9, 12, -26);
scene.add(destinationLabel);
// Voxel trees and street furniture.
function voxelTree(x, z, scale = 1) {
box(district, 0.45 * scale, 2.3 * scale, 0.45 * scale, x, 1.15 * scale, z, 0x75523d);
box(district, 2.25 * scale, 1.7 * scale, 2.25 * scale, x, 2.65 * scale, z, 0x4f8f64);
box(district, 1.55 * scale, 1.25 * scale, 1.55 * scale, x + 0.2, 3.75 * scale, z, 0x69aa70);
}
[
[-23, 2], [-6, 2], [19, -3], [21, -15],
[-21, -21], [-6, -21], [18, -29], [-22, -30]
].forEach(([x, z], i) => voxelTree(x, z, 0.8 + (i % 3) * 0.08));
for (const x of [-19, -1, 12]) {
for (const z of [-7, -18]) {
box(district, 0.18, 3.8, 0.18, x, 2.1, z, 0x425159);
box(district, 0.8, 0.2, 0.8, x, 4.05, z, 0xffdf9c, { castShadow: false });
}
}
// -------------------------------------------------------------------------
// Vehicles and traveler
// -------------------------------------------------------------------------
const boat = new THREE.Group();
scene.add(boat);
box(boat, 3.9, 0.85, 6.2, 0, 0.05, 0, 0xf0f1e8);
box(boat, 3.4, 0.65, 3.4, 0, 0.78, -0.3, 0x2a92a7);
box(boat, 3.7, 0.25, 3.9, 0, 1.25, -0.3, 0xf5f3df);
box(boat, 2.6, 0.75, 0.12, 0, 1.0, 1.44, 0x8de3ef, { castShadow: false });
box(boat, 0.55, 1.3, 0.55, 0, 1.9, -0.3, 0xffb35c);
box(boat, 0.15, 2.1, 0.15, 0, 2.65, -0.3, 0x46565b);
box(boat, 1.1, 0.55, 0.18, 0.55, 3.65, -0.3, 0x47e0c1);
const wake = new THREE.Group();
box(wake, 4.8, 0.04, 2.0, 0, -0.18, 4.0, 0xb9edf0, {
transparent: true,
opacity: 0.22,
castShadow: false
});
boat.add(wake);
const car = new THREE.Group();
scene.add(car);
box(car, 4.8, 1.05, 2.35, 0, 0.85, 0, 0xffad4d);
box(car, 2.6, 0.9, 2.05, -0.2, 1.75, 0, 0xf7e3bd);
box(car, 2.2, 0.55, 0.08, -0.2, 1.75, 1.06, 0x85c9d5, { castShadow: false });
box(car, 0.12, 0.55, 1.75, -0.2, 1.75, 0, 0x85c9d5, { castShadow: false });
box(car, 0.7, 0.32, 0.08, 2.43, 0.9, 0.72, 0xfff1ba, { castShadow: false });
box(car, 0.7, 0.32, 0.08, 2.43, 0.9, -0.72, 0xfff1ba, { castShadow: false });
box(car, 0.1, 0.28, 1.85, 2.45, 0.85, 0, 0x41515a);
const traveler = new THREE.Group();
scene.add(traveler);
const travelerShadow = new THREE.Mesh(
new THREE.CylinderGeometry(0.5, 0.5, 0.08, 16),
new THREE.MeshBasicMaterial({
color: 0x0a1720,
transparent: true,
opacity: 0.3,
depthWrite: false
})
);
travelerShadow.position.y = 0.08;
traveler.add(travelerShadow);
box(traveler, 0.64, 0.88, 0.42, 0, 1.0, 0, 0xff6f91);
box(traveler, 0.45, 0.45, 0.43, 0, 1.68, 0, 0xf2c6a3);
box(traveler, 0.5, 0.18, 0.48, 0, 1.92, 0, 0x273b45);
box(traveler, 0.22, 0.62, 0.25, -0.18, 0.35, 0, 0x243d51);
box(traveler, 0.22, 0.62, 0.25, 0.18, 0.35, 0, 0x243d51);
box(traveler, 0.18, 0.62, 0.22, -0.42, 1.02, 0, 0xf2c6a3);
box(traveler, 0.18, 0.62, 0.22, 0.42, 1.02, 0, 0xf2c6a3);
const travelerBeacon = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 2.8, 10),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.45,
depthWrite: false
})
);
travelerBeacon.position.y = 2.0;
traveler.add(travelerBeacon);
// -------------------------------------------------------------------------
// Route geometry and path definitions
// -------------------------------------------------------------------------
const FERRY_COLOR = 0x47e0c1;
const ROAD_COLOR = 0xffb35c;
const DESTINATION_POINT = new THREE.Vector3(9, 0.34, -22.82);
const ferryBoatPath = polylineData([
new THREE.Vector3(-38, 0, 25),
new THREE.Vector3(-27, 0, 19),
new THREE.Vector3(-18, 0, 14),
new THREE.Vector3(-12, 0, 11)
]);
const ferryWalkPath = polylineData([
new THREE.Vector3(-12, 0.34, 5),
new THREE.Vector3(-12, 0.34, -7),
new THREE.Vector3(4, 0.34, -7),
new THREE.Vector3(4, 0.34, -18),
new THREE.Vector3(9, 0.34, -18),
DESTINATION_POINT.clone()
]);
const roadDrivePath = polylineData([
new THREE.Vector3(58, 0.3, 1),
new THREE.Vector3(42, 0.3, 1)
]);
const roadWalkPath = polylineData([
new THREE.Vector3(41, 0.34, 1),
new THREE.Vector3(26, 0.34, 1),
new THREE.Vector3(26, 0.34, -21),
new THREE.Vector3(15, 0.34, -21),
new THREE.Vector3(15, 0.34, -18),
new THREE.Vector3(9, 0.34, -18),
DESTINATION_POINT.clone()
]);
const ferryTransitLine = createLine(
ferryBoatPath.points.map(p => new THREE.Vector3(p.x, -0.19, p.z)),
FERRY_COLOR,
false
);
const ferryWalkLine = createLine(ferryWalkPath.points, FERRY_COLOR, true);
const roadTransitLine = createLine(roadDrivePath.points, ROAD_COLOR, false);
const roadWalkLine = createLine(roadWalkPath.points, ROAD_COLOR, true);
const routeVisuals = {
ferry: [ferryTransitLine.material, ferryWalkLine.material],
road: [roadTransitLine.material, roadWalkLine.material]
};
function setRouteHighlight(route) {
Object.entries(routeVisuals).forEach(([key, materials]) => {
materials.forEach((mat) => {
mat.opacity = key === route ? 0.98 : 0.17;
});
});
}
// -------------------------------------------------------------------------
// Route definitions and simulation state
// -------------------------------------------------------------------------
const MINUTE_PER_SECOND = 0.7;
const routes = {
ferry: {
name: "Ferry",
stages: [
{ label: "Ferry crossing", detail: "Schematic crossing time: 8 min" },
{ label: "Disembark and transfer", detail: "Schematic transfer time: 3 min" },
{ label: "Walk through the district", detail: "Schematic walking time: 5 min" }
],
minutes: [8, 3, 5]
},
road: {
name: "Road",
stages: [
{ label: "Road approach", detail: "Schematic road time: 10 min" },
{ label: "Park and transfer", detail: "Schematic transfer time: 2 min" },
{ label: "Walk through the district", detail: "Schematic walking time: 7 min" }
],
minutes: [10, 2, 7]
}
};
const simulation = {
route: null,
stage: 0,
stageT: 0,
active: false,
paused: false
};
const completed = {
ferry: null,
road: null
};
const ferryButton = document.getElementById("ferryButton");
const roadButton = document.getElementById("roadButton");
const statusRow = document.getElementById("statusRow");
const statusKicker = document.getElementById("statusKicker");
const statusTitle = document.getElementById("statusTitle");
const progressFill = document.getElementById("progressFill");
const pauseButton = document.getElementById("pauseButton");
const replayButton = document.getElementById("replayButton");
const overviewButton = document.getElementById("overviewButton");
const followButton = document.getElementById("followButton");
const completion = document.getElementById("completion");
const completionCopy = document.getElementById("completionCopy");
const totalTime = document.getElementById("totalTime");
const comparison = document.getElementById("comparison");
const comparisonText = document.getElementById("comparisonText");
function updateStatusForStage() {
const route = routes[simulation.route];
if (!route) return;
const stage = route.stages[simulation.stage];
statusKicker.textContent = `${route.name} route · Stage ${simulation.stage + 1} of 3`;
statusTitle.textContent = `${stage.label} — ${stage.detail}`;
progressFill.style.width = `${simulation.stageT * 100}%`;
}
function beginStage(index) {
simulation.stage = index;
simulation.stageT = 0;
if (simulation.route === "ferry") {
if (index === 0) {
boat.position.copy(ferryBoatPath.points[0]);
boat.rotation.y = Math.atan2(13, -6);
traveler.scale.setScalar(0.82);
traveler.position.copy(boat.position).add(new THREE.Vector3(0, 1.0, 0.4));
} else if (index === 1) {
traveler.scale.setScalar(1);
traveler.position.copy(boat.position).add(new THREE.Vector3(0, 0.95, 0.5));
} else if (index === 2) {
traveler.scale.setScalar(1);
traveler.position.copy(ferryWalkPath.points[0]);
}
}
if (simulation.route === "road") {
if (index === 0) {
car.position.copy(roadDrivePath.points[0]);
car.rotation.y = 0;
traveler.scale.setScalar(0.68);
traveler.position.copy(car.position).add(new THREE.Vector3(0, 1.35, 0));
} else if (index === 1) {
traveler.scale.setScalar(1);
traveler.position.set(42, 1.35, 1);
} else if (index === 2) {
traveler.scale.setScalar(1);
traveler.position.copy(roadWalkPath.points[0]);
}
}
updateStatusForStage();
}
function updateFerryStage() {
const t = simulation.stageT;
if (simulation.stage === 0) {
const sample = samplePolyline(ferryBoatPath, smooth(t));
boat.position.copy(sample.position);
boat.position.y = Math.sin(performance.now() * 0.003) * 0.08;
boat.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
traveler.position.copy(boat.position).add(new THREE.Vector3(0, 1.0, 0.4));
} else if (simulation.stage === 1) {
const start = new THREE.Vector3(-12, 0.95, 11.5);
const end = new THREE.Vector3(-12, 0.34, 5);
const movement = smooth(THREE.MathUtils.clamp(t / 0.62, 0, 1));
traveler.position.lerpVectors(start, end, movement);
traveler.rotation.y = Math.PI;
travelerBeacon.material.opacity = 0.35 + Math.sin(t * Math.PI * 7) * 0.18;
} else if (simulation.stage === 2) {
const sample = samplePolyline(ferryWalkPath, t);
traveler.position.copy(sample.position);
traveler.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
travelerBeacon.material.opacity = 0.38;
}
}
function updateRoadStage() {
const t = simulation.stageT;
if (simulation.stage === 0) {
const sample = samplePolyline(roadDrivePath, smooth(t));
car.position.copy(sample.position);
car.rotation.y = Math.atan2(-sample.tangent.z, sample.tangent.x);
traveler.position.copy(car.position).add(new THREE.Vector3(0, 1.35, 0));
} else if (simulation.stage === 1) {
const start = new THREE.Vector3(42, 1.35, 1);
const end = new THREE.Vector3(41, 0.34, 1);
const movement = smooth(THREE.MathUtils.clamp(t / 0.62, 0, 1));
traveler.position.lerpVectors(start, end, movement);
traveler.rotation.y = Math.PI / 2;
travelerBeacon.material.opacity = 0.35 + Math.sin(t * Math.PI * 7) * 0.18;
} else if (simulation.stage === 2) {
const sample = samplePolyline(roadWalkPath, t);
traveler.position.copy(sample.position);
traveler.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
travelerBeacon.material.opacity = 0.38;
}
}
function completeRoute() {
simulation.active = false;
simulation.paused = false;
const route = routes[simulation.route];
const total = route.minutes.reduce((sum, value) => sum + value, 0);
completed[simulation.route] = total;
statusKicker.textContent = `${route.name} route · Arrived`;
statusTitle.textContent = "The traveler has reached the shared destination.";
progressFill.style.width = "100%";
pauseButton.disabled = true;
pauseButton.textContent = "Pause";
replayButton.disabled = false;
completion.classList.add("visible");
completionCopy.textContent =
simulation.route === "ferry"
? "Ferry arrival: 8 min crossing, 3 min transfer, then a 5 min / ~420 m walk."
: "Road arrival: 10 min approach, 2 min transfer, then a 7 min / ~590 m walk.";
totalTime.textContent = `${total} min`;
const button = simulation.route === "ferry" ? ferryButton : roadButton;
const arrival = button.querySelector(".arrival");
arrival.textContent = `Arrived · ${total} min total elapsed`;
arrival.classList.add("visible");
updateComparison();
}
function startRoute(routeKey) {
simulation.route = routeKey;
simulation.stage = 0;
simulation.stageT = 0;
simulation.active = true;
simulation.paused = false;
ferryButton.classList.toggle("active", routeKey === "ferry");
roadButton.classList.toggle("active", routeKey === "road");
statusRow.classList.toggle("road-run", routeKey === "road");
boat.visible = routeKey === "ferry";
car.visible = routeKey === "road";
setRouteHighlight(routeKey);
pauseButton.disabled = false;
pauseButton.textContent = "Pause";
replayButton.disabled = false;
completion.classList.remove("visible");
beginStage(0);
}
function updateComparison() {
if (completed.ferry === null || completed.road === null) {
comparison.classList.remove("visible");
return;
}
const faster =
completed.ferry < completed.road
? "Ferry"
: completed.road < completed.ferry
? "Road"
: "Neither";
const difference = Math.abs(completed.ferry - completed.road);
comparison.classList.add("visible");
comparisonText.innerHTML =
`<b>Ferry: ${completed.ferry} min.</b> ` +
`<b>Road: ${completed.road} min.</b> ` +
`${faster} arrives ${difference} min faster. ` +
`The ferry crossing is 2 min shorter than the road approach, but its transfer is 1 min longer; ` +
`its 5 min / ~420 m final walk is 2 min shorter than the road's 7 min / ~590 m walk.`;
}
ferryButton.addEventListener("click", () => startRoute("ferry"));
roadButton.addEventListener("click", () => startRoute("road"));
replayButton.addEventListener("click", () => {
if (simulation.route) startRoute(simulation.route);
});
pauseButton.addEventListener("click", () => {
if (!simulation.active) return;
simulation.paused = !simulation.paused;
pauseButton.textContent = simulation.paused ? "Resume" : "Pause";
statusKicker.textContent = simulation.paused
? `${routes[simulation.route].name} route · Paused`
: statusKicker.textContent;
});
overviewButton.addEventListener("click", () => {
cameraState.follow = false;
cameraState.radius = 94;
cameraState.theta = 0.77;
cameraState.phi = 0.86;
overviewButton.classList.add("active");
followButton.classList.remove("active");
});
followButton.addEventListener("click", () => {
cameraState.follow = true;
cameraState.radius = 43;
cameraState.phi = 0.88;
followButton.classList.add("active");
overviewButton.classList.remove("active");
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && simulation.active) {
event.preventDefault();
pauseButton.click();
}
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (simulation.active && !simulation.paused) {
const route = routes[simulation.route];
const duration = route.minutes[simulation.stage] * MINUTE_PER_SECOND;
simulation.stageT += delta / duration;
if (simulation.route === "ferry") updateFerryStage();
else updateRoadStage();
progressFill.style.width = `${Math.min(simulation.stageT, 1) * 100}%`;
if (simulation.stageT >= 1) {
simulation.stageT = 1;
if (simulation.stage < route.stages.length - 1) {
beginStage(simulation.stage + 1);
} else {
completeRoute();
}
}
}
// Gentle destination pulse.
const pulse = 1 + Math.sin(elapsed * 2.5) * 0.06;
destinationRing.scale.set(pulse, pulse, pulse);
destinationBeam.material.opacity = 0.13 + Math.sin(elapsed * 2.5) * 0.035;
landingPad.material.opacity = 0.4 + Math.sin(elapsed * 3) * 0.12;
roadPad.material.opacity = 0.42 + Math.sin(elapsed * 3 + 1) * 0.12;
updateCamera();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera(true);
setRouteHighlight(null);
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => document.getElementById("loading").remove(), 350);
});
</script>
</body>
</html>
```