Prompt specification
Build or customize the Three.js 3D scene "Compare a stair route with a longer street route" 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 a stair route with a longer street route
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-a-stair-route-with-a-longer-street-route-x3032
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring The Rocks and Sydney's harbor edge. Let users navigate between two modeled destinations at different heights. Display route length and elevation change separately, maintaining clear access through the historic passages. Low-poly.
Working Three.js Starter (compare-a-stair-route-with-a-longer-street-route-x3032):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Stones to Water — A Sydney Low-Poly Route</title>
<style>
:root {
--ink: #18343a;
--muted: #61777b;
--paper: rgba(250, 248, 239, 0.94);
--line: rgba(24, 52, 58, 0.14);
--coral: #ef7658;
--blue: #198ea8;
--gold: #f0b653;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #c8dce0;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.wash {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(239, 246, 244, 0.18), transparent 28%),
radial-gradient(circle at 50% 42%, transparent 45%, rgba(20, 45, 50, 0.12));
}
.topbar {
position: fixed;
z-index: 10;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
padding: 9px 13px 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.52);
border-radius: 13px;
background: rgba(250, 248, 239, 0.8);
box-shadow: 0 10px 35px rgba(34, 62, 67, 0.12);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(2, 8px);
grid-template-rows: repeat(2, 8px);
gap: 2px;
transform: rotate(45deg);
}
.brand-mark i {
display: block;
background: var(--coral);
border-radius: 1px;
}
.brand-mark i:nth-child(2) {
background: var(--gold);
}
.brand-mark i:nth-child(3) {
background: var(--blue);
}
.brand-mark i:nth-child(4) {
background: var(--ink);
}
.brand-copy {
line-height: 1.05;
}
.brand-copy strong {
display: block;
font-size: 12px;
letter-spacing: 0.14em;
}
.brand-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.tools {
display: flex;
gap: 8px;
pointer-events: auto;
}
.tool {
min-height: 39px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 11px;
background: rgba(250, 248, 239, 0.85);
box-shadow: 0 8px 26px rgba(34, 62, 67, 0.11);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
transition:
transform 150ms ease,
background 150ms ease;
}
.tool:hover,
.tool:focus-visible {
transform: translateY(-1px);
background: #fffdf6;
outline: none;
}
.tool[aria-pressed="false"] {
color: var(--muted);
}
.destination-panel {
position: fixed;
z-index: 9;
top: 88px;
left: 20px;
width: 310px;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(34, 62, 67, 0.14);
backdrop-filter: blur(16px);
}
.eyebrow {
margin: 0 0 8px;
color: var(--coral);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 38px;
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.intro {
margin: 12px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.destination-list {
display: grid;
gap: 9px;
}
.destination {
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.46);
text-align: left;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.destination:hover,
.destination:focus-visible {
transform: translateY(-1px);
border-color: rgba(24, 52, 58, 0.34);
outline: none;
}
.destination.active {
border-color: rgba(239, 118, 88, 0.55);
background: rgba(255, 255, 255, 0.86);
}
.destination-code {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border-radius: 50%;
color: white;
background: var(--coral);
font-size: 11px;
font-weight: 850;
}
.destination.b .destination-code {
background: var(--blue);
}
.destination strong {
display: block;
font-size: 12px;
}
.destination small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
}
.destination .arrow {
color: var(--muted);
font-size: 16px;
}
.panel-note {
display: flex;
gap: 8px;
align-items: flex-start;
margin: 14px 1px 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.panel-note::before {
content: "";
flex: 0 0 auto;
width: 7px;
height: 7px;
margin-top: 3px;
border-radius: 2px;
background: var(--gold);
transform: rotate(45deg);
}
.route-panel {
position: fixed;
z-index: 10;
right: 20px;
bottom: 18px;
left: 350px;
padding: 15px 17px 14px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 17px;
background: rgba(250, 248, 239, 0.94);
box-shadow: 0 18px 55px rgba(34, 62, 67, 0.16);
backdrop-filter: blur(16px);
}
.route-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-bottom: 11px;
}
.route-heading strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
font-weight: 500;
}
#journeyStatus {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.route-content {
display: grid;
grid-template-columns: minmax(200px, 1fr) minmax(165px, 0.7fr);
gap: 16px;
align-items: center;
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.stat {
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.48);
}
.stat-label {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.stat-value {
display: block;
margin-top: 3px;
font-size: 22px;
font-weight: 780;
letter-spacing: -0.04em;
}
.stat-meta {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.profile {
min-width: 0;
}
.profile-head {
display: flex;
justify-content: space-between;
margin-bottom: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#profileSvg {
display: block;
width: 100%;
height: 57px;
overflow: visible;
}
.route-controls {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1fr auto;
gap: 13px;
align-items: center;
padding-top: 10px;
border-top: 1px solid var(--line);
}
.range-wrap {
position: relative;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
90deg,
var(--coral) 0%,
var(--coral) var(--progress, 0%),
rgba(24, 52, 58, 0.15) var(--progress, 0%),
rgba(24, 52, 58, 0.15) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--coral);
box-shadow: 0 2px 8px rgba(24, 52, 58, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid white;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 2px 8px rgba(24, 52, 58, 0.28);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
}
#walkButton {
min-width: 105px;
min-height: 37px;
padding: 0 14px;
border: 0;
border-radius: 10px;
color: #fffaf0;
background: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 800;
transition:
transform 150ms ease,
background 150ms ease;
}
#walkButton:hover,
#walkButton:focus-visible {
transform: translateY(-1px);
background: #285058;
outline: none;
}
.help {
position: fixed;
z-index: 8;
left: 20px;
bottom: 19px;
padding: 8px 10px;
border-radius: 9px;
color: rgba(24, 52, 58, 0.75);
background: rgba(250, 248, 239, 0.72);
font-size: 9px;
font-weight: 700;
backdrop-filter: blur(10px);
pointer-events: none;
}
#labels {
position: fixed;
z-index: 6;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 999px;
color: var(--ink);
background: rgba(250, 248, 239, 0.87);
box-shadow: 0 6px 18px rgba(24, 52, 58, 0.13);
backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 800;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
}
.map-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 14px;
background: rgba(24, 52, 58, 0.36);
}
.map-label::before {
content: "";
position: absolute;
left: calc(50% - 3px);
top: calc(100% + 12px);
width: 6px;
height: 6px;
border: 2px solid white;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 1px 5px rgba(24, 52, 58, 0.25);
}
.map-label.blue::before {
background: var(--blue);
}
.map-label small {
color: var(--muted);
font-size: 8px;
font-weight: 650;
}
#labels.hidden {
display: none;
}
@media (max-width: 800px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand-copy span,
.help {
display: none;
}
.tool {
padding: 0 10px;
}
.destination-panel {
top: 66px;
left: 10px;
width: 245px;
padding: 15px;
}
h1 {
font-size: 30px;
}
.intro {
margin: 9px 0 12px;
}
.destination {
padding: 8px;
}
.route-panel {
right: 10px;
bottom: 10px;
left: 10px;
}
.route-content {
grid-template-columns: 1fr;
}
.profile {
display: none;
}
}
@media (max-width: 520px) {
.brand {
padding-right: 9px;
}
.brand-copy strong {
font-size: 10px;
}
.tool span {
display: none;
}
.destination-panel {
width: 205px;
}
.destination-panel .intro,
.panel-note {
display: none;
}
.destination small {
max-width: 115px;
}
.route-panel {
padding: 12px;
}
.stat {
padding: 8px;
}
.stat-value {
font-size: 19px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive low-poly model of The Rocks and Sydney Harbour"></main>
<div class="wash"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div class="brand-copy">
<strong>FIELD GUIDE / SYDNEY</strong>
<span>Low-poly harbour walks</span>
</div>
</div>
<div class="tools">
<button class="tool" id="overviewButton" type="button">
<span>⌂ </span> Overview
</button>
<button class="tool" id="labelButton" type="button" aria-pressed="true">
<span>⌖ </span> Labels
</button>
</div>
</header>
<aside class="destination-panel">
<p class="eyebrow">Two stops · one historic walk</p>
<h1>Stones to<br />water</h1>
<p class="intro">
Follow sandstone lanes through The Rocks, then descend toward the
open light of Sydney Harbour.
</p>
<div class="destination-list">
<button class="destination active" data-destination="0" type="button">
<span class="destination-code">A</span>
<span>
<strong>The Rocks</strong>
<small>Historic passages · 21 m above quay</small>
</span>
<span class="arrow">↗</span>
</button>
<button class="destination b" data-destination="1" type="button">
<span class="destination-code">B</span>
<span>
<strong>Harbour Edge</strong>
<small>Circular Quay · open harbour outlook</small>
</span>
<span class="arrow">↘</span>
</button>
</div>
<p class="panel-note">
The route stays inside the pedestrian passages and uses the historic
stair connections between the raised terraces and the quay.
</p>
</aside>
<section class="route-panel" aria-label="Route information and navigation">
<div class="route-heading">
<strong>Heritage passages → Harbour Edge</strong>
<span id="journeyStatus">Ready to explore</span>
</div>
<div class="route-content">
<div class="stats">
<div class="stat">
<span class="stat-label">Route length</span>
<strong class="stat-value" id="distanceValue">—</strong>
<span class="stat-meta" id="distanceMeta">Walking distance</span>
</div>
<div class="stat">
<span class="stat-label">Elevation change</span>
<strong class="stat-value" id="elevationValue">—</strong>
<span class="stat-meta" id="elevationMeta">Net height change</span>
</div>
</div>
<div class="profile" aria-label="Elevation profile">
<div class="profile-head">
<span>Elevation profile</span>
<span>Start → End</span>
</div>
<svg id="profileSvg" viewBox="0 0 260 58" preserveAspectRatio="none">
<defs>
<linearGradient id="profileFill" x1="0" x2="0" y1="0" y2="1">
<stop offset="0%" stop-color="#ef7658" stop-opacity="0.3" />
<stop offset="100%" stop-color="#ef7658" stop-opacity="0.02" />
</linearGradient>
</defs>
<path
id="profileArea"
fill="url(#profileFill)"
stroke="none"
></path>
<path
id="profilePath"
fill="none"
stroke="#ef7658"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
></path>
<circle
id="profileDot"
r="3.5"
fill="#18343a"
stroke="#fffdf6"
stroke-width="2"
></circle>
</svg>
</div>
<div class="route-controls">
<div class="range-wrap">
<input
id="routeSlider"
type="range"
min="0"
max="1000"
value="0"
aria-label="Position along the route"
/>
<div class="range-ends">
<span>A · THE ROCKS</span>
<span>B · HARBOUR EDGE</span>
</div>
</div>
<button id="walkButton" type="button">Walk route</button>
</div>
</div>
</section>
<div class="help">Drag to orbit · Scroll to zoom · ← / → follow route</div>
<div id="labels" aria-hidden="true"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera and basic scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8dce0);
scene.fog = new THREE.Fog(0xc8dce0, 92, 205);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
350
);
camera.position.set(70, 70, 92);
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.querySelector("#scene").appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8f4f3, 0x66766b, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cf, 2.7);
sun.position.set(-42, 74, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(1536, 1536);
sun.shadow.camera.left = -80;
sun.shadow.camera.right = 80;
sun.shadow.camera.top = 80;
sun.shadow.camera.bottom = -80;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 180;
sun.shadow.bias = -0.00025;
scene.add(sun);
const sceneRoot = new THREE.Group();
scene.add(sceneRoot);
const up = new THREE.Vector3(0, 1, 0);
const tempV = new THREE.Vector3();
const tempV2 = new THREE.Vector3();
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.9,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true,
side: options.side ?? THREE.FrontSide
});
}
const material = {
landTop: standard(0xaeb5a2),
landSide: standard(0x767f73),
terraceTop: standard(0xc5b79b),
terraceSide: standard(0x877968),
road: standard(0x777d78),
sandstone: standard(0xc7a77e),
cream: standard(0xe3d7b9),
brick: standard(0x9e6d58),
roof: standard(0x555d5a),
darkRoof: standard(0x424b4c),
white: standard(0xf0ead7),
green: standard(0x49766b),
gold: standard(0xd2a454),
timber: standard(0x80624b),
route: standard(0xf07c4e),
routeGlow: new THREE.MeshBasicMaterial({
color: 0xffb45d,
transparent: true,
opacity: 0.22,
depthWrite: false
})
};
function box(w, h, d, x, y, z, mat, parent = sceneRoot) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, mat, radialSegments = 6, parent = sceneRoot) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makePrism(points, depth, baseY, topMat, sideMat) {
const shape = new THREE.Shape();
points.forEach(([x, z], index) => {
if (index === 0) shape.moveTo(x, -z);
else shape.lineTo(x, -z);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
steps: 1
});
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, [topMat, sideMat]);
mesh.position.y = baseY;
mesh.castShadow = true;
mesh.receiveShadow = true;
sceneRoot.add(mesh);
return mesh;
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(90210);
// ------------------------------------------------------------
// Harbour and land
// ------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(250, 215, 26, 22);
waterGeometry.rotateX(-Math.PI / 2);
const waterPositions = waterGeometry.attributes.position;
const waterColors = [];
const low = new THREE.Color(0x4d9eac);
const high = new THREE.Color(0x74b8c1);
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const z = waterPositions.getZ(i);
waterPositions.setY(
i,
Math.sin(x * 0.17) * 0.09 +
Math.cos(z * 0.12) * 0.07 +
(random() - 0.5) * 0.09
);
const mix = (Math.sin(x * 0.1 + z * 0.06) + 1) * 0.25;
const color = low.clone().lerp(high, mix);
waterColors.push(color.r, color.g, color.b);
}
waterGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
waterGeometry.computeVertexNormals();
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.72,
metalness: 0.05,
flatShading: true,
transparent: true,
opacity: 0.96
})
);
water.position.set(0, -0.08, -45);
water.receiveShadow = true;
sceneRoot.add(water);
makePrism(
[
[-57, 43],
[49, 43],
[52, 22],
[49, -2],
[43, -12],
[31, -14],
[22, -12],
[13, -13],
[3, -11],
[-7, -11],
[-18, -9],
[-31, -9],
[-44, -7],
[-54, 1]
],
2,
0,
material.landTop,
material.landSide
);
makePrism(
[
[-51, 30],
[-45, 15],
[-43, -5],
[-34, -8],
[-23, -6],
[-14, 1],
[-13, 19],
[-25, 30],
[-39, 34]
],
1.8,
2,
material.terraceTop,
material.terraceSide
);
function road(w, d, x, z, angle = 0) {
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(w, d), material.road);
mesh.rotation.x = -Math.PI / 2;
mesh.rotation.z = angle;
mesh.position.set(x, 2.025, z);
mesh.receiveShadow = true;
sceneRoot.add(mesh);
return mesh;
}
road(7, 52, -42, 13);
road(6, 50, -20, 15);
road(6, 50, 1, 15);
road(6, 48, 20, 14);
road(100, 6, -3, 27);
road(100, 5, -3, 12);
road(96, 5, -4, 1);
road(76, 4, -5, 34);
// ------------------------------------------------------------
// Route geometry and measurements
// ------------------------------------------------------------
const METRES_PER_UNIT = 8;
const routePoints = [
new THREE.Vector3(-34, 4.60, 19),
new THREE.Vector3(-30, 4.48, 15),
new THREE.Vector3(-27, 4.18, 11),
new THREE.Vector3(-23, 4.36, 8),
new THREE.Vector3(-20, 4.58, 5),
new THREE.Vector3(-16, 4.18, 2),
new THREE.Vector3(-13, 3.78, -1),
new THREE.Vector3(-9, 3.30, -3),
new THREE.Vector3(-5, 3.00, -1),
new THREE.Vector3(-1, 2.78, 2),
new THREE.Vector3(4, 2.58, 3),
new THREE.Vector3(9, 2.40, 1),
new THREE.Vector3(14, 2.24, -2),
new THREE.Vector3(19, 2.10, -5),
new THREE.Vector3(24, 2.00, -8)
];
const segmentData = [];
let routeHorizontalLength = 0;
let elevationGain = 0;
let elevationLoss = 0;
for (let i = 0; i < routePoints.length - 1; i++) {
const a = routePoints[i];
const b = routePoints[i + 1];
const horizontal = Math.hypot(b.x - a.x, b.z - a.z);
const vertical = b.y - a.y;
segmentData.push({
a,
b,
horizontal,
startDistance: routeHorizontalLength
});
routeHorizontalLength += horizontal;
if (vertical > 0) elevationGain += vertical;
else elevationLoss -= vertical;
}
const routeLengthMetres = routeHorizontalLength * METRES_PER_UNIT;
const elevationGainMetres = elevationGain * METRES_PER_UNIT;
const elevationLossMetres = elevationLoss * METRES_PER_UNIT;
const netElevationMetres =
(routePoints.at(-1).y - routePoints[0].y) * METRES_PER_UNIT;
for (let i = 0; i < routePoints.length - 1; i++) {
const a = routePoints[i];
const b = routePoints[i + 1];
cylinderBetween(a, b, 0.36, material.routeGlow, 6);
cylinderBetween(a, b, 0.13, material.route, 6);
}
function sampleRoute(t) {
const targetDistance = THREE.MathUtils.clamp(t, 0, 1) * routeHorizontalLength;
for (const segment of segmentData) {
const end = segment.startDistance + segment.horizontal;
if (targetDistance <= end || segment === segmentData.at(-1)) {
const alpha =
segment.horizontal === 0
? 0
: (targetDistance - segment.startDistance) / segment.horizontal;
return segment.a.clone().lerp(segment.b, alpha);
}
}
return routePoints[0].clone();
}
function distanceToRoute(x, z) {
let nearest = Infinity;
for (const segment of segmentData) {
const ax = segment.a.x;
const az = segment.a.z;
const bx = segment.b.x;
const bz = segment.b.z;
const dx = bx - ax;
const dz = bz - az;
const lengthSquared = dx * dx + dz * dz;
const t = lengthSquared
? THREE.MathUtils.clamp(
((x - ax) * dx + (z - az) * dz) / lengthSquared,
0,
1
)
: 0;
const px = ax + dx * t;
const pz = az + dz * t;
nearest = Math.min(nearest, Math.hypot(x - px, z - pz));
}
return nearest;
}
function addStairs(a, b, count = 10, width = 2.5) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const horizontalLength = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const stepLength = horizontalLength / count;
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
const y = THREE.MathUtils.lerp(a.y, b.y, t);
const step = box(
stepLength + 0.18,
0.25,
width,
x,
y - 0.13,
z,
i % 3 === 0 ? material.cream : material.terraceTop
);
step.rotation.y = angle;
if (i % 3 === 0 && Math.abs(a.y - b.y) > 0.1) {
const support = box(
0.3,
Math.max(0.2, y - 2.1),
0.3,
x,
2.1 + (y - 2.1) / 2,
z,
material.terraceSide
);
support.rotation.y = angle;
}
}
}
addStairs(routePoints[0], routePoints[1], 7, 2.4);
addStairs(routePoints[4], routePoints[5], 7, 2.6);
addStairs(routePoints[5], routePoints[6], 8, 2.7);
addStairs(routePoints[6], routePoints[7], 10, 2.7);
addStairs(routePoints[7], routePoints[8], 8, 2.7);
// ------------------------------------------------------------
// Buildings and heritage passages
// ------------------------------------------------------------
function addBuilding(
x,
z,
w,
d,
h,
base,
color,
rotation = 0,
roofMaterial = material.roof
) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
sceneRoot.add(group);
const body = box(w, h, d, 0, base + h / 2, 0, color, group);
body.castShadow = true;
const roof = box(
w + 0.28,
0.34,
d + 0.28,
0,
base + h + 0.17,
0,
roofMaterial,
group
);
roof.castShadow = true;
const windowMat = standard(0x40585a, {
roughness: 0.48,
metalness: 0.1
});
const windowCount = Math.max(1, Math.floor(w / 2.5));
for (let i = 0; i < windowCount; i++) {
const wx = -w / 2 + ((i + 0.5) * w) / windowCount;
box(
0.42,
0.72,
0.045,
wx,
base + h * 0.62,
d / 2 + 0.025,
windowMat,
group
);
}
if (random() > 0.55) {
box(
0.42,
1.05,
0.42,
w * 0.25,
base + h + 0.55,
-d * 0.18,
material.brick,
group
);
}
return group;
}
const buildingColors = [
material.sandstone,
material.cream,
material.brick,
standard(0xb78d68),
standard(0xd2c2a0)
];
for (let i = 0; i < 72; i++) {
const x = -52 + random() * 100;
const z = -3 + random() * 42;
if (distanceToRoute(x, z) < 4.4) continue;
if (x > 18 && z < 0) continue;
const w = 2.8 + random() * 4.4;
const d = 2.7 + random() * 4.0;
const h = 3.1 + random() * 6.8;
const base = x < -15 && z > -5 ? 3.8 : 2.04;
addBuilding(
x,
z,
w,
d,
h,
base,
buildingColors[Math.floor(random() * buildingColors.length)],
(random() - 0.5) * 0.18,
random() > 0.72 ? material.darkRoof : material.roof
);
}
// Deliberate street walls frame, but do not block, the route.
addBuilding(-31, 11, 5.2, 7, 5.2, 3.8, material.sandstone, 0.08);
addBuilding(-26, 15, 6.2, 6, 5.8, 3.8, material.cream, -0.08);
addBuilding(-22, 3, 5.7, 7.2, 6.6, 3.8, material.brick, 0.05);
addBuilding(-15, 5, 6.4, 7.3, 5.7, 3.8, material.sandstone, -0.04);
addBuilding(-10, 2, 5.3, 6.2, 6.8, 2.04, material.cream, 0.04);
// Historic gateway spanning the pedestrian passage.
const gatePoint = routePoints[6].clone();
const gateDirection = routePoints[7].clone().sub(routePoints[6]);
gateDirection.y = 0;
gateDirection.normalize();
const perpendicular = new THREE.Vector3(
-gateDirection.z,
0,
gateDirection.x
);
const gateAngle = -Math.atan2(gateDirection.z, gateDirection.x);
for (const side of [-1, 1]) {
const column = box(
0.82,
3.5,
0.9,
gatePoint.x + perpendicular.x * side * 2.05,
gatePoint.y + 1.55,
gatePoint.z + perpendicular.z * side * 2.05,
material.sandstone
);
column.rotation.y = gateAngle;
}
const lintel = box(
0.9,
0.65,
5.0,
gatePoint.x,
gatePoint.y + 3.35,
gatePoint.z,
material.cream
);
lintel.rotation.y = gateAngle;
// Observatory at The Rocks.
const observatory = new THREE.Group();
observatory.position.set(-38, 0, 24);
sceneRoot.add(observatory);
box(5.3, 3.8, 4.4, 0, 5.7, 0, material.white, observatory);
box(5.8, 0.35, 4.9, 0, 7.78, 0, material.cream, observatory);
const dome = new THREE.Mesh(
new THREE.SphereGeometry(2.35, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2),
material.green
);
dome.position.y = 7.95;
dome.castShadow = true;
observatory.add(dome);
const observatorySpire = new THREE.Mesh(
new THREE.ConeGeometry(0.18, 1.3, 5),
material.gold
);
observatorySpire.position.y = 10.7;
observatory.add(observatorySpire);
for (const x of [-1.75, 0, 1.75]) {
box(0.4, 2.6, 0.42, x, 5.7, 2.27, material.white, observatory);
}
// ------------------------------------------------------------
// Harbour edge, piers and Customs House
// ------------------------------------------------------------
const quay = new THREE.Mesh(
new THREE.CylinderGeometry(8.5, 8.5, 0.32, 16),
material.terraceTop
);
quay.position.set(24, 2.12, -5.2);
quay.receiveShadow = true;
sceneRoot.add(quay);
box(14, 0.38, 4.2, 23, 2.13, -10.1, material.cream);
box(3.0, 0.36, 15, 13, 2.08, -15.5, material.timber);
box(2.8, 0.36, 12, 31, 2.08, -14.5, material.timber);
for (let z = -10; z > -21; z -= 2.5) {
box(0.42, 1.5, 0.42, 11.8, 2.9, z, material.timber);
box(0.42, 1.5, 0.42, 14.2, 2.9, z, material.timber);
}
const customs = new THREE.Group();
customs.position.set(35, 0, -3);
sceneRoot.add(customs);
box(7.2, 6.4, 5.5, 0, 5.25, 0, material.white, customs);
box(7.5, 0.4, 5.8, 0, 8.65, 0, material.cream, customs);
box(3.1, 5.4, 3.1, 0, 11.45, 0, material.white, customs);
box(3.5, 0.35, 3.5, 0, 14.3, 0, material.gold, customs);
const customsRoof = new THREE.Mesh(
new THREE.ConeGeometry(2.35, 2.2, 6),
material.green
);
customsRoof.position.y = 15.45;
customsRoof.castShadow = true;
customs.add(customsRoof);
const clockFace = new THREE.Mesh(
new THREE.CircleGeometry(0.72, 12),
standard(0xf5e8c8)
);
clockFace.position.set(0, 12.05, 1.57);
customs.add(clockFace);
// Harbour edge furniture.
for (let x = 9; x <= 38; x += 4) {
const bollard = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.23, 0.8, 6),
material.darkRoof
);
bollard.position.set(x, 2.55, -10.65);
bollard.castShadow = true;
sceneRoot.add(bollard);
}
// ------------------------------------------------------------
// Trees and parks
// ------------------------------------------------------------
const trunkMaterial = standard(0x735f47);
const leafMaterials = [
standard(0x63866a),
standard(0x78936e),
standard(0x4e7561)
];
function addTree(x, z, base = 2.05, scale = 1) {
const group = new THREE.Group();
group.position.set(x, base, z);
sceneRoot.add(group);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.16 * scale, 0.24 * scale, 2.2 * scale, 5),
trunkMaterial
);
trunk.position.y = 1.1 * scale;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.55 * scale, 0),
leafMaterials[Math.floor(random() * leafMaterials.length)]
);
crown.position.y = 2.75 * scale;
crown.scale.set(1, 1.2, 0.92);
crown.castShadow = true;
group.add(crown);
}
for (let i = 0; i < 28; i++) {
const x = -48 + random() * 94;
const z = 7 + random() * 31;
if (distanceToRoute(x, z) < 4.5) continue;
addTree(x, z, x < -15 ? 3.8 : 2.05, 0.75 + random() * 0.55);
}
// ------------------------------------------------------------
// Distant Sydney Harbour landmarks
// ------------------------------------------------------------
// Low-poly Harbour Bridge.
const bridge = new THREE.Group();
bridge.position.set(26, 0, -52);
sceneRoot.add(bridge);
const bridgeMaterial = standard(0x596567);
const bridgeDeck = box(5.0, 0.8, 49, 0, 5.2, 0, bridgeMaterial, bridge);
bridgeDeck.castShadow = true;
for (const z of [-13, 13]) {
box(5.8, 20, 3.3, 0, 10, z, bridgeMaterial, bridge);
box(7.0, 1.0, 4.5, 0, 20.2, z, bridgeMaterial, bridge);
}
for (let i = 0; i <= 18; i++) {
const t = i / 18;
const x = -10 * Math.cos(Math.PI * t);
const y = 5.5 + 17 * Math.sin(Math.PI * t);
const nextT = (i + 1) / 18;
const nextX = -10 * Math.cos(Math.PI * nextT);
const nextY = 5.5 + 17 * Math.sin(Math.PI * nextT);
cylinderBetween(
new THREE.Vector3(x, y, 0),
new THREE.Vector3(nextX, nextY, 0),
0.65,
bridgeMaterial,
4,
bridge
);
if (i % 2 === 0 && i > 0 && i < 18) {
cylinderBetween(
new THREE.Vector3(x, y, 0),
new THREE.Vector3(x, 5.6, 0),
0.13,
bridgeMaterial,
4,
bridge
);
}
}
// Stylized Opera House shells.
const opera = new THREE.Group();
opera.position.set(-25, 0.25, -28);
opera.rotation.y = -0.22;
sceneRoot.add(opera);
const shellMaterial = standard(0xf4edda, {
roughness: 0.7
});
const shellSpecs = [
{ x: -3.0, z: 0.5, s: 1.35, r: -0.2 },
{ x: 0.0, z: 0.0, s: 1.75, r: 0.12 },
{ x: 3.1, z: 0.6, s: 1.30, r: 0.35 },
{ x: -1.4, z: 2.2, s: 1.25, r: -0.1 },
{ x: 1.5, z: 2.4, s: 1.30, r: 0.16 }
];
for (const spec of shellSpecs) {
const shell = new THREE.Mesh(
new THREE.SphereGeometry(
3.4 * spec.s,
7,
4,
0,
Math.PI,
0,
Math.PI * 0.52
),
shellMaterial
);
shell.position.set(spec.x, 0.6, spec.z);
shell.scale.set(0.68, 1.1, 0.72);
shell.rotation.z = spec.r;
shell.rotation.y = spec.r * 0.7;
shell.castShadow = true;
opera.add(shell);
}
box(9, 0.55, 7, 0, 0.35, 1, material.cream, opera);
// Ferry.
const ferry = new THREE.Group();
ferry.position.set(7, 0.2, -25);
ferry.rotation.y = 0.35;
sceneRoot.add(ferry);
const hull = box(7.2, 1.25, 2.5, 0, 0.75, 0, material.white, ferry);
hull.geometry.translate(0, 0, 0);
box(6.6, 0.32, 2.8, 0, 1.5, 0, material.coral, ferry);
box(4.8, 1.7, 2.0, 0, 2.35, 0, material.white, ferry);
box(4.9, 0.24, 2.1, 0, 3.28, 0, material.blue, ferry);
for (const x of [-1.8, 0, 1.8]) {
box(0.85, 0.55, 2.03, x, 2.55, 0, material.blue, ferry);
}
// ------------------------------------------------------------
// Destination markers and walking figure
// ------------------------------------------------------------
function addDestinationMarker(point, color) {
const group = new THREE.Group();
group.position.copy(point);
sceneRoot.add(group);
const markerMaterial = standard(color, {
roughness: 0.48,
metalness: 0.08
});
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.09, 3.2, 6),
markerMaterial
);
pole.position.y = 1.6;
pole.castShadow = true;
group.add(pole);
const diamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.58),
markerMaterial
);
diamond.position.y = 3.45;
diamond.castShadow = true;
group.add(diamond);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.95, 0.11, 5, 18),
markerMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.08;
group.add(ring);
return { group, diamond, ring };
}
const markerA = addDestinationMarker(routePoints[0], 0xef7658);
const markerB = addDestinationMarker(routePoints.at(-1), 0x198ea8);
const walker = new THREE.Group();
sceneRoot.add(walker);
const walkerBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.22, 0.8, 6),
material.coral
);
walkerBody.position.y = 0.55;
walkerBody.castShadow = true;
walker.add(walkerBody);
const walkerHead = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.24, 0),
material.cream
);
walkerHead.position.y = 1.15;
walkerHead.castShadow = true;
walker.add(walkerHead);
const walkerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.07, 5, 16),
material.routeGlow
);
walkerRing.rotation.x = Math.PI / 2;
walkerRing.position.y = 0.06;
walker.add(walkerRing);
// ------------------------------------------------------------
// Screen-space labels
// ------------------------------------------------------------
const labelDefinitions = [
{
text: "The Rocks",
sub: "A",
point: routePoints[0].clone().add(new THREE.Vector3(0, 3.1, 0)),
className: ""
},
{
text: "Historic passages",
sub: "stairs",
point: routePoints[6].clone().add(new THREE.Vector3(0, 2.2, 0)),
className: ""
},
{
text: "Harbour Edge",
sub: "B",
point: routePoints.at(-1).clone().add(new THREE.Vector3(0, 3.1, 0)),
className: "blue"
},
{
text: "Customs House",
sub: "",
point: new THREE.Vector3(35, 15.5, -3),
className: "blue"
},
{
text: "Sydney Harbour Bridge",
sub: "",
point: new THREE.Vector3(26, 23, -52),
className: "blue"
},
{
text: "Sydney Opera House",
sub: "",
point: new THREE.Vector3(-25, 8, -28),
className: "blue"
}
];
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `map-label ${definition.className}`;
element.innerHTML = `${definition.text}${
definition.sub ? ` <small>${definition.sub}</small>` : ""
}`;
document.querySelector("#labels").appendChild(element);
definition.element = element;
}
function updateLabels() {
const cameraDirection = camera.getWorldDirection(tempV2);
for (const definition of labelDefinitions) {
const toLabel = tempV.subVectors(definition.point, camera.position);
const visible =
toLabel.dot(cameraDirection) > 0 &&
definition.point.distanceTo(camera.position) < 155;
const projected = definition.point.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const inside =
x > 25 &&
x < window.innerWidth - 25 &&
y > 70 &&
y < window.innerHeight - 120;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
definition.element.style.opacity = visible && inside ? "1" : "0";
}
}
// ------------------------------------------------------------
// Elevation profile
// ------------------------------------------------------------
const profilePath = document.querySelector("#profilePath");
const profileArea = document.querySelector("#profileArea");
const profileDot = document.querySelector("#profileDot");
const profilePoints = routePoints.map((point, index) => {
const before = index === 0 ? 0 : segmentData[index - 1].startDistance;
const after =
index === segmentData.length
? routeHorizontalLength
: segmentData[index].startDistance + segmentData[index].horizontal;
const x = (after / routeHorizontalLength) * 250 + 5;
const minY = Math.min(...routePoints.map((p) => p.y));
const maxY = Math.max(...routePoints.map((p) => p.y));
const y = 48 - ((point.y - minY) / Math.max(0.001, maxY - minY)) * 37;
return { x, y };
});
const profileD = profilePoints
.map((point, index) => `${index === 0 ? "M" : "L"}${point.x},${point.y}`)
.join(" ");
profilePath.setAttribute("d", profileD);
profileArea.setAttribute(
"d",
`${profileD} L255,55 L5,55 Z`
);
// ------------------------------------------------------------
// Custom camera navigation
// ------------------------------------------------------------
let progress = 0;
let autoWalk = false;
let cameraMode = "overview";
let yaw = 0.58;
let pitch = 0.68;
let cameraDistance = 104;
const cameraTarget = new THREE.Vector3(-2, 2, 9);
const desiredTarget = cameraTarget.clone();
const desiredCamera = camera.position.clone();
const routeSlider = document.querySelector("#routeSlider");
const walkButton = document.querySelector("#walkButton");
const overviewButton = document.querySelector("#overviewButton");
const labelButton = document.querySelector("#labelButton");
const destinationButtons = [
...document.querySelectorAll(".destination")
];
function updateCameraOffset() {
const horizontalDistance = Math.cos(pitch) * cameraDistance;
desiredCamera.set(
desiredTarget.x + Math.sin(yaw) * horizontalDistance,
desiredTarget.y + Math.sin(pitch) * cameraDistance,
desiredTarget.z + Math.cos(yaw) * horizontalDistance
);
}
function setOverview() {
cameraMode = "overview";
autoWalk = false;
yaw = 0.58;
pitch = 0.68;
cameraDistance = 104;
desiredTarget.set(-2, 2, 9);
updateCameraOffset();
updateWalkButton();
}
function setDestination(index) {
cameraMode = "focus";
autoWalk = false;
progress = index === 0 ? 0 : 1;
yaw = index === 0 ? 0.82 : 1.02;
pitch = 0.47;
cameraDistance = 30;
desiredTarget.copy(routePoints[index]);
desiredTarget.y += 1.2;
updateCameraOffset();
updateRouteUI();
updateWalkButton();
}
function setRouteMode() {
cameraMode = "route";
yaw = 0.88;
pitch = 0.48;
cameraDistance = 22;
}
function updateWalkButton() {
if (autoWalk) {
walkButton.textContent = "Pause walk";
} else if (progress >= 0.999) {
walkButton.textContent = "Replay route";
} else {
walkButton.textContent = "Walk route";
}
}
function updateRouteUI() {
const travelled = progress * routeLengthMetres;
const currentPoint = sampleRoute(progress);
const currentChange =
(currentPoint.y - routePoints[0].y) * METRES_PER_UNIT;
const roundedLength = Math.round(routeLengthMetres);
const roundedElevation = Math.round(netElevationMetres);
document.querySelector("#distanceValue").textContent =
`${roundedLength} m`;
document.querySelector("#distanceMeta").textContent =
`${Math.round(travelled)} m travelled`;
document.querySelector("#elevationValue").textContent =
`${roundedElevation > 0 ? "+" : ""}${roundedElevation} m`;
document.querySelector("#elevationMeta").textContent =
`+${Math.round(elevationGainMetres)} m gain · ` +
`−${Math.round(elevationLossMetres)} m loss`;
const currentStatus =
currentChange > 0.5
? `${Math.round(currentChange)} m above start`
: currentChange < -0.5
? `${Math.round(Math.abs(currentChange))} m below start`
: "At the starting level";
document.querySelector("#journeyStatus").textContent =
progress <= 0.001
? "Ready to explore"
: progress >= 0.999
? "Arrived at the harbour"
: `${Math.round(progress * 100)}% · ${currentStatus}`;
routeSlider.value = String(Math.round(progress * 1000));
routeSlider.style.setProperty(
"--progress",
`${Math.round(progress * 100)}%`
);
destinationButtons.forEach((button, index) => {
button.classList.toggle(
"active",
index === 0 ? progress < 0.5 : progress >= 0.5
);
});
const profileIndex = Math.min(
profilePoints.length - 1,
Math.round(progress * (profilePoints.length - 1))
);
const point = profilePoints[profileIndex];
profileDot.setAttribute("cx", point.x);
profileDot.setAttribute("cy", point.y);
}
routeSlider.addEventListener("input", () => {
progress = Number(routeSlider.value) / 1000;
autoWalk = false;
setRouteMode();
updateRouteUI();
updateWalkButton();
});
walkButton.addEventListener("click", () => {
if (autoWalk) {
autoWalk = false;
} else {
if (progress >= 0.999) progress = 0;
autoWalk = true;
setRouteMode();
}
updateWalkButton();
});
overviewButton.addEventListener("click", setOverview);
destinationButtons.forEach((button) => {
button.addEventListener("click", () => {
setDestination(Number(button.dataset.destination));
});
});
labelButton.addEventListener("click", () => {
const labelsVisible = labelButton.getAttribute("aria-pressed") === "true";
labelButton.setAttribute("aria-pressed", String(!labelsVisible));
document.querySelector("#labels").classList.toggle(
"hidden",
labelsVisible
);
});
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.004, 0.16, 1.25);
updateCameraOffset();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch {}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const minimum = cameraMode === "route" ? 11 : 24;
const maximum = cameraMode === "overview" ? 145 : 55;
cameraDistance = THREE.MathUtils.clamp(
cameraDistance * Math.exp(event.deltaY * 0.001),
minimum,
maximum
);
updateCameraOffset();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (
event.key === "ArrowRight" ||
event.key === "ArrowLeft"
) {
event.preventDefault();
autoWalk = false;
setRouteMode();
progress = THREE.MathUtils.clamp(
progress + (event.key === "ArrowRight" ? 0.02 : -0.02),
0,
1
);
updateRouteUI();
updateWalkButton();
}
if (event.key.toLowerCase() === "r") {
setOverview();
}
if (event.key.toLowerCase() === "a") {
setDestination(0);
}
if (event.key.toLowerCase() === "b") {
setDestination(1);
}
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (autoWalk) {
progress = Math.min(1, progress + dt / 24);
if (progress >= 1) {
autoWalk = false;
updateWalkButton();
}
updateRouteUI();
}
if (cameraMode === "route") {
const point = sampleRoute(progress);
desiredTarget.copy(point);
desiredTarget.y += 0.7;
updateCameraOffset();
}
const smoothing = 1 - Math.exp(-dt * 4.8);
camera.position.lerp(desiredCamera, smoothing);
cameraTarget.lerp(desiredTarget, smoothing);
camera.lookAt(cameraTarget);
const point = sampleRoute(progress);
walker.position.copy(point);
walker.position.y += 0.08;
walker.rotation.y = yaw + Math.PI;
walkerRing.scale.setScalar(1 + Math.sin(elapsed * 4) * 0.12);
markerA.diamond.rotation.y = elapsed * 0.8;
markerA.diamond.position.y = 3.45 + Math.sin(elapsed * 2.2) * 0.12;
markerB.diamond.rotation.y = -elapsed * 0.8;
markerB.diamond.position.y = 3.45 + Math.sin(elapsed * 2.2 + 1) * 0.12;
ferry.position.z = -25 + Math.sin(elapsed * 0.13) * 7;
ferry.position.y = 0.2 + Math.sin(elapsed * 0.8) * 0.08;
ferry.rotation.y = 0.35 + Math.sin(elapsed * 0.13) * 0.08;
water.position.y = -0.08 + Math.sin(elapsed * 0.42) * 0.035;
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateRouteUI();
updateWalkButton();
setOverview();
animate();
</script>
</body>
</html>
```