Prompt specification
Build or customize the Three.js 3D scene "Compare riverfront and bridge-street walking routes" 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 riverfront and bridge-street walking routes
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-riverfront-and-bridge-street-walking-routes-x2832
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Ponte Vecchio in Florence. Let users trace a short route between two bank-side destinations. Show how the limited crossing position changes the path despite the buildings appearing close across water. Voxel style.
Working Three.js Starter (compare-riverfront-and-bridge-street-walking-routes-x2832):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ponte Vecchio — The Long Way Across</title>
<style>
:root {
--ink: #26363a;
--muted: #6e7c7e;
--paper: #fffaf0;
--paper-strong: #fffdf8;
--line: rgba(38, 54, 58, 0.13);
--orange: #ef7047;
--orange-dark: #b8422c;
--teal: #168e88;
--blue: #5b8fa0;
--shadow: 0 20px 55px rgba(41, 60, 60, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe7e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
border: 0;
}
#app,
#viewport,
#labels {
position: absolute;
inset: 0;
}
#viewport {
cursor: grab;
}
#viewport:active {
cursor: grabbing;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
#labels {
pointer-events: none;
overflow: hidden;
z-index: 3;
}
.topbar {
position: absolute;
z-index: 8;
top: 20px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 40px;
height: 40px;
border: 1px solid rgba(38, 54, 58, 0.18);
border-radius: 12px;
background: rgba(255, 250, 240, 0.84);
box-shadow: 0 8px 25px rgba(43, 66, 64, 0.1);
backdrop-filter: blur(10px);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
left: 8px;
right: 8px;
height: 5px;
background: var(--orange);
box-shadow:
0 8px 0 var(--teal),
0 16px 0 #d6a54b;
}
.brand-mark::before {
top: 7px;
}
.brand-mark::after {
top: 7px;
background: var(--teal);
transform: translateX(8px) scaleX(0.45);
}
.brand-copy {
padding: 9px 13px 10px;
border: 1px solid rgba(38, 54, 58, 0.13);
border-radius: 13px;
background: rgba(255, 250, 240, 0.82);
box-shadow: 0 8px 25px rgba(43, 66, 64, 0.09);
backdrop-filter: blur(10px);
}
.eyebrow {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--teal);
}
.brand-copy strong {
display: block;
margin-top: 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
line-height: 1;
font-weight: 600;
letter-spacing: -0.02em;
}
.brand-copy small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 11px;
}
.top-meta {
display: flex;
gap: 8px;
align-items: center;
pointer-events: auto;
}
.pill {
border: 1px solid rgba(38, 54, 58, 0.13);
border-radius: 999px;
padding: 9px 12px;
background: rgba(255, 250, 240, 0.82);
box-shadow: 0 8px 25px rgba(43, 66, 64, 0.08);
backdrop-filter: blur(10px);
color: #566568;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.pill.live {
color: var(--teal);
}
.pill.live::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 142, 136, 0.12);
vertical-align: 1px;
}
.panel {
position: absolute;
z-index: 7;
top: 88px;
right: 20px;
bottom: 20px;
width: 350px;
padding: 22px;
overflow: auto;
border: 1px solid rgba(38, 54, 58, 0.13);
border-radius: 22px;
background: rgba(255, 250, 240, 0.93);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(38, 54, 58, 0.2) transparent;
}
.panel h1 {
margin: 8px 0 10px;
font-family: Georgia, "Times New Roman", serif;
font-size: 31px;
line-height: 1.04;
letter-spacing: -0.035em;
font-weight: 500;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.steps {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 18px 0 13px;
}
.step {
min-height: 72px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.46);
}
.step b {
display: block;
margin-bottom: 4px;
font-size: 11px;
}
.step span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.step-number {
display: inline-grid;
place-items: center;
width: 19px;
height: 19px;
margin-bottom: 7px;
border-radius: 6px;
color: white;
background: var(--teal);
font-size: 10px;
font-weight: 900;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.btn {
min-height: 40px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
.btn:hover:not(:disabled) {
transform: translateY(-1px);
border-color: rgba(22, 142, 136, 0.4);
background: white;
}
.btn:active:not(:disabled) {
transform: translateY(0);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.42;
}
.btn.primary {
width: 100%;
margin-top: 9px;
min-height: 47px;
color: white;
border-color: transparent;
background: var(--orange);
box-shadow: 0 9px 22px rgba(239, 112, 71, 0.26);
}
.btn.primary:hover:not(:disabled) {
border-color: transparent;
background: #f07850;
}
.btn.quiet {
width: 100%;
margin-top: 8px;
background: transparent;
color: var(--muted);
}
.hint {
min-height: 38px;
margin: 11px 0 0;
padding: 9px 11px;
border-left: 3px solid var(--teal);
border-radius: 0 9px 9px 0;
background: rgba(22, 142, 136, 0.07);
color: #526668;
font-size: 10.5px;
line-height: 1.4;
}
.hint.warm {
border-color: var(--orange);
background: rgba(239, 112, 71, 0.08);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 20px 0 10px;
padding-top: 17px;
border-top: 1px solid var(--line);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-title span:last-child {
color: var(--muted);
font-weight: 700;
letter-spacing: 0.03em;
text-transform: none;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.44);
}
.metric.wide {
grid-column: 1 / -1;
display: flex;
align-items: center;
justify-content: space-between;
background: rgba(239, 112, 71, 0.08);
border-color: rgba(239, 112, 71, 0.2);
}
.metric span {
display: block;
color: var(--muted);
font-size: 10px;
}
.metric strong {
display: block;
margin-top: 4px;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 500;
}
.metric.wide strong {
margin: 0;
color: var(--orange-dark);
font-size: 18px;
}
.legend {
display: grid;
gap: 8px;
margin-top: 12px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10.5px;
}
.legend-line {
width: 27px;
height: 3px;
border-radius: 2px;
background: var(--orange);
}
.legend-line.dashed {
height: 0;
border-top: 2px dashed #68868f;
background: transparent;
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 14px;
color: #526668;
font-size: 10.5px;
}
.toggle input {
width: 17px;
height: 17px;
accent-color: var(--teal);
}
.progress {
height: 5px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(38, 54, 58, 0.09);
}
.progress > div {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--orange);
transition: width 80ms linear;
}
.camera-dock {
position: absolute;
z-index: 6;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 5px;
padding: 6px;
border: 1px solid rgba(38, 54, 58, 0.13);
border-radius: 13px;
background: rgba(255, 250, 240, 0.82);
box-shadow: 0 10px 30px rgba(43, 66, 64, 0.11);
backdrop-filter: blur(12px);
}
.camera-dock button {
width: 34px;
height: 32px;
border-radius: 8px;
background: transparent;
color: #536568;
cursor: pointer;
font-size: 14px;
font-weight: 900;
}
.camera-dock button:hover {
background: rgba(38, 54, 58, 0.07);
}
.camera-dock span {
padding: 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid rgba(38, 54, 58, 0.13);
border-radius: 8px;
background: rgba(255, 250, 240, 0.84);
box-shadow: 0 6px 18px rgba(43, 66, 64, 0.1);
color: #435457;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
white-space: nowrap;
backdrop-filter: blur(7px);
}
.world-label.landmark {
padding: 7px 10px;
color: #704b2a;
border-color: rgba(176, 113, 54, 0.22);
background: rgba(255, 242, 211, 0.9);
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
font-weight: 600;
letter-spacing: 0;
text-transform: none;
}
.world-label.bridge {
color: #8a4b27;
border-color: rgba(239, 112, 71, 0.3);
background: rgba(255, 237, 219, 0.92);
}
.world-label.danger {
color: #9c493a;
border-color: rgba(198, 76, 56, 0.28);
background: rgba(255, 238, 230, 0.92);
font-size: 8px;
}
.world-label.minor {
color: #63787a;
background: rgba(242, 247, 242, 0.72);
box-shadow: none;
font-size: 8px;
}
.world-label.pin {
min-width: 26px;
padding: 5px 8px;
color: white;
border: 0;
background: var(--teal);
text-align: center;
}
.world-label.pin.end {
background: var(--orange-dark);
}
#loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #dbe7e2;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#loading::before {
content: "";
width: 26px;
height: 26px;
margin-right: 12px;
border: 4px solid rgba(38, 54, 58, 0.12);
border-top-color: var(--orange);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
#loading {
grid-auto-flow: column;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 760px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand-copy {
padding: 8px 10px;
}
.brand-copy strong {
font-size: 17px;
}
.brand-copy small,
.top-meta .pill:first-child {
display: none;
}
.panel {
top: auto;
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 45vh;
padding: 17px;
border-radius: 18px;
}
.panel h1 {
font-size: 25px;
}
.steps {
margin-top: 12px;
}
.camera-dock {
top: 78px;
bottom: auto;
left: 12px;
}
.camera-dock span {
display: none;
}
.world-label.minor {
display: none !important;
}
}
</style>
</head>
<body>
<div id="app">
<div id="viewport"></div>
<div id="labels" aria-hidden="true">
<div id="labelBridge" class="world-label landmark">Ponte Vecchio</div>
<div id="labelCrossing" class="world-label bridge">Only crossing</div>
<div id="labelArno" class="world-label minor">Arno River</div>
<div id="labelNorth" class="world-label minor">Palazzo bank</div>
<div id="labelSouth" class="world-label minor">Uffizi bank</div>
<div id="labelPalazzo" class="world-label landmark">Palazzo Vecchio</div>
<div id="labelUffizi" class="world-label landmark">Uffizi</div>
<div id="labelNoLanding" class="world-label danger">No landing</div>
<div id="labelA" class="world-label pin">A</div>
<div id="labelB" class="world-label pin end">B</div>
</div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<div class="eyebrow">Florence · Route Study</div>
<strong>Ponte Vecchio</strong>
<small>The long way across the Arno</small>
</div>
</div>
<div class="top-meta">
<div class="pill">Drag to orbit · Scroll to zoom</div>
<div id="modeBadge" class="pill live">Ready</div>
</div>
</header>
<aside class="panel">
<div class="eyebrow">A constrained crossing</div>
<h1>Across looks close.<br>Walk farther.</h1>
<p class="intro">
The buildings seem close across the water, but the river offers no
landing here. Set two quay-side destinations and trace the route that
must use Ponte Vecchio.
</p>
<div class="steps">
<div class="step">
<i class="step-number">1</i>
<b>Place A and B</b>
<span>Click the north quay for A and the south quay for B.</span>
</div>
<div class="step">
<i class="step-number">2</i>
<b>Shape the walk</b>
<span>Optionally add promenade stops, then trace the route.</span>
</div>
</div>
<div class="button-row">
<button id="placeBtn" class="btn" type="button">Move destinations</button>
<button id="stopBtn" class="btn" type="button">+ Add stop</button>
</div>
<p id="routeHint" class="hint" aria-live="polite">
Click either quay to move a destination. The bridge is the only legal
river crossing in this scene.
</p>
<button id="traceBtn" class="btn primary" type="button">
▶ Trace the walkable route
</button>
<button id="resetBtn" class="btn quiet" type="button">
Reset example
</button>
<div class="progress" aria-hidden="true"><div id="traceProgress"></div></div>
<div class="section-title">
<span>Distance comparison</span>
<span>1 scene unit ≈ 10 m</span>
</div>
<div class="metrics">
<div class="metric">
<span>Straight sightline</span>
<strong id="directMetric">—</strong>
</div>
<div class="metric">
<span>Walkable route</span>
<strong id="walkMetric">—</strong>
</div>
<div class="metric wide">
<span>Extra distance caused by the crossing</span>
<strong id="extraMetric">—</strong>
</div>
</div>
<div class="legend">
<div class="legend-row">
<i class="legend-line dashed"></i>
<span>Shortest line across the water</span>
</div>
<div class="legend-row">
<i class="legend-line"></i>
<span>Legal route through Ponte Vecchio</span>
</div>
</div>
<label class="toggle">
<span>Show the impossible straight line</span>
<input id="directToggle" type="checkbox" checked>
</label>
</aside>
<div class="camera-dock" aria-label="Camera controls">
<button id="cameraLeft" type="button" aria-label="Rotate left">↶</button>
<button id="cameraRight" type="button" aria-label="Rotate right">↷</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="cameraReset" type="button" aria-label="Reset camera">⌂</button>
<span>Camera</span>
</div>
<div id="loading">Building Florence</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const viewport = $("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of Ponte Vecchio in Florence"
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe7e2);
scene.fog = new THREE.Fog(0xdbe7e2, 52, 88);
const camera = new THREE.OrthographicCamera(-20, 20, 12, -12, 0.1, 120);
const cameraTarget = new THREE.Vector3(-0.8, 0.9, 0);
const cameraState = {
theta: 0.72,
targetTheta: 0.72,
phi: 0.80,
targetPhi: 0.80,
radius: 38,
zoom: 1,
targetZoom: 1
};
const hemi = new THREE.HemisphereLight(0xfff3dc, 0x6f8580, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd1, 3.15);
sun.position.set(-12, 23, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -23;
sun.shadow.camera.right = 23;
sun.shadow.camera.top = 23;
sun.shadow.camera.bottom = -23;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbadce0, 0.72);
fill.position.set(15, 10, -18);
scene.add(fill);
// ------------------------------------------------------------
// Small material and geometry helpers
// ------------------------------------------------------------
const materialCache = new Map();
function material(color, options = {}) {
if (color && color.isMaterial) return color;
const key = `${color}_${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.0,
...options
})
);
}
return materialCache.get(key);
}
function box(size, position, color, parent = scene, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const bankHitMeshes = [];
const rippleMeshes = [];
// ------------------------------------------------------------
// Diorama base, Arno, quays, and paving
// ------------------------------------------------------------
box([28.2, 1.0, 26.2], [0, -1.0, 0], 0xb9aa8f);
const waterMaterial = material(0x559da3, {
roughness: 0.34,
metalness: 0.06,
transparent: true,
opacity: 0.95
});
box([27.4, 0.34, 8.25], [0, -0.12, 0], 0x397f88);
box([27.4, 0.16, 8.0], [0, 0.05, 0], waterMaterial);
const northBank = box(
[27.4, 1.0, 8.4],
[0, 0.48, 8.2],
0xd4c6a9
);
const southBank = box(
[27.4, 1.0, 8.4],
[0, 0.48, -8.2],
0xd1c1a3
);
bankHitMeshes.push(northBank, southBank);
box([27.5, 0.75, 0.34], [0, 0.31, 4.08], 0xa99678);
box([27.5, 0.75, 0.34], [0, 0.31, -4.08], 0xa99678);
const northWalk = box(
[27.2, 0.22, 1.42],
[0, 1.08, 4.72],
0xeadbbd
);
const southWalk = box(
[27.2, 0.22, 1.42],
[0, 1.08, -4.72],
0xe4d3b3
);
bankHitMeshes.push(northWalk, southWalk);
const pavingColors = [0xe7d5b2, 0xdfccaa, 0xefdfc0, 0xd8c4a2];
for (let side of [-1, 1]) {
for (let i = 0; i < 32; i++) {
const x = -12.7 + i * 0.81;
const z = side * (4.72 + (i % 2 ? 0.28 : -0.28));
box(
[0.68, 0.035, 0.48],
[x, 1.205, z],
pavingColors[i % pavingColors.length]
);
}
}
// Pixel-like river ripples.
for (let i = 0; i < 46; i++) {
const x = -12.4 + ((i * 2.71) % 24.8);
const z = -3.45 + ((i * 1.37) % 6.9);
const ripple = box(
[0.45 + (i % 4) * 0.18, 0.025, 0.07],
[x, 0.155, z],
0xa3d0cf,
scene,
{ transparent: true, opacity: 0.38 }
);
ripple.userData.baseX = x;
rippleMeshes.push(ripple);
}
// ------------------------------------------------------------
// Voxel buildings
// ------------------------------------------------------------
const windowMaterial = material(0x41555a, { roughness: 0.5 });
const shutterMaterial = material(0x6d7e71);
function addBuilding(
x,
z,
width,
depth,
height,
bodyColor,
roofColor = 0xb85f43,
options = {}
) {
const base = 1.02;
const body = box(
[width, height, depth],
[x, base + height / 2, z],
bodyColor
);
const roof = box(
[width + 0.24, 0.20, depth + 0.24],
[x, base + height + 0.10, z],
roofColor
);
if (options.attic) {
box(
[width * 0.62, 0.62, depth * 0.62],
[x, base + height + 0.50, z],
bodyColor
);
box(
[width * 0.66, 0.16, depth * 0.66],
[x, base + height + 0.87, z],
roofColor
);
}
const rows = Math.max(1, Math.floor((height - 0.45) / 0.9));
const cols = Math.max(2, Math.floor(width / 0.68));
const faceZ = z > 0 ? z - depth / 2 - 0.035 : z + depth / 2 + 0.035;
for (let row = 0; row < rows; row++) {
const y = base + 0.60 + row * 0.90;
if (y > base + height - 0.25) continue;
for (let col = 0; col < cols; col++) {
const wx =
x - width / 2 + 0.43 +
col * ((width - 0.86) / Math.max(1, cols - 1));
box([0.27, 0.40, 0.065], [wx, y, faceZ], windowMaterial);
if ((row + col) % 3 !== 0) {
box(
[0.065, 0.40, 0.07],
[wx - 0.18, y, faceZ + (z > 0 ? -0.015 : 0.015)],
shutterMaterial
);
}
}
}
if (options.chimney) {
box(
[0.28, 0.65, 0.30],
[x + width * 0.25, base + height + 0.46, z],
0x8d5b48
);
}
return { body, roof };
}
// North bank: Palazzo Vecchio side.
addBuilding(-9.7, 8.7, 3.0, 3.1, 3.5, 0xd6c29c, 0xa95c46);
addBuilding(-6.4, 9.0, 3.0, 3.2, 4.1, 0xc99068, 0xb65b43, {
attic: true,
chimney: true
});
addBuilding(-3.0, 9.1, 3.3, 3.2, 3.2, 0xe0c79c, 0xb85c43);
addBuilding(0.5, 9.0, 3.0, 3.1, 3.8, 0xc9825f, 0xa94f3d, {
attic: true
});
addBuilding(3.7, 8.9, 3.0, 3.2, 3.1, 0xe4cc9f, 0xb65c43);
addBuilding(5.9, 8.8, 2.5, 3.0, 3.7, 0xcfa16c, 0xa9533d);
// Palazzo Vecchio.
addBuilding(9.1, 8.8, 3.4, 3.2, 4.2, 0xb98964, 0x9b4f3c);
box([1.55, 5.8, 1.85], [9.1, 3.92, 8.6], 0xb67f5b);
box([1.85, 0.22, 2.15], [9.1, 6.92, 8.6], 0x934d3b);
for (let i = 0; i < 5; i++) {
box(
[0.24, 0.40, 0.24],
[8.38 + i * 0.36, 7.22, 8.6],
0x934d3b
);
}
// South bank: Uffizi side.
addBuilding(-10.4, -8.8, 2.8, 3.1, 3.4, 0xc89b74, 0xa95541);
addBuilding(-7.7, -8.6, 2.7, 3.0, 3.0, 0xe0c7a0, 0xb65c43);
// Long Uffizi gallery.
addBuilding(-3.8, -8.7, 7.6, 2.9, 2.7, 0xd5b486, 0xa95643);
box([7.8, 0.18, 3.1], [-3.8, 3.90, -8.7], 0x9c503e);
for (let i = 0; i < 7; i++) {
box(
[0.62, 0.84, 0.09],
[-6.6 + i * 0.92, 2.25, -7.20],
0x5d6b68
);
}
addBuilding(1.0, -8.8, 3.1, 3.2, 3.6, 0xd4b183, 0xb25b42, {
attic: true
});
addBuilding(4.3, -8.8, 3.0, 3.2, 3.0, 0xc47c5e, 0xa64d3d);
addBuilding(7.5, -8.7, 3.2, 3.2, 4.0, 0xe0c69b, 0xb45c43, {
attic: true,
chimney: true
});
addBuilding(10.6, -8.8, 2.5, 3.0, 3.2, 0xc69c70, 0xa95541);
function addTree(x, z, scale = 1) {
box(
[0.22 * scale, 1.15 * scale, 0.22 * scale],
[x, 1.57 * scale, z],
0x806348
);
box(
[0.78 * scale, 0.78 * scale, 0.76 * scale],
[x, 2.23 * scale, z],
0x66855f
);
box(
[0.58 * scale, 0.58 * scale, 0.62 * scale],
[x - 0.22 * scale, 2.72 * scale, z + 0.08],
0x789663
);
box(
[0.46 * scale, 0.46 * scale, 0.48 * scale],
[x + 0.28 * scale, 2.52 * scale, z - 0.10],
0x527653
);
}
[
[-11.6, 5.9], [-8.7, 5.9], [-6.1, 5.9], [-2.0, 5.9],
[3.0, 5.9], [6.6, 5.9], [11.3, 5.9],
[-11.6, -5.9], [-7.0, -5.9], [2.8, -5.9],
[6.5, -5.9], [11.4, -5.9]
].forEach(([x, z], i) => addTree(x, z, 0.8 + (i % 3) * 0.10));
// Small block boats.
function addBoat(x, z, color) {
const boat = new THREE.Group();
boat.position.set(x, 0.2, z);
scene.add(boat);
box([1.7, 0.22, 0.62], [0, 0, 0], color, boat);
box([0.88, 0.42, 0.48], [-0.15, 0.30, 0], 0xe3d6bb, boat);
box([0.48, 0.38, 0.42], [0.55, 0.29, 0], 0x6d8f91, boat);
box([0.08, 0.9, 0.08], [-0.64, 0.55, 0], 0x705d4b, boat);
}
addBoat(7.3, -1.65, 0xa8563f);
addBoat(-8.2, 1.45, 0xd09a58);
// ------------------------------------------------------------
// Ponte Vecchio
// ------------------------------------------------------------
const bridgeGroup = new THREE.Group();
scene.add(bridgeGroup);
// Deck and approaches.
box([3.25, 0.50, 8.5], [0, 1.17, 0], 0xc6a675, bridgeGroup);
box([3.15, 0.16, 0.65], [0, 1.30, 4.28], 0xd2b384, bridgeGroup);
box([3.15, 0.16, 0.65], [0, 1.30, -4.28], 0xd2b384, bridgeGroup);
// Low parapets.
box([0.20, 0.34, 8.2], [-1.53, 1.56, 0], 0xd8b984, bridgeGroup);
box([0.20, 0.34, 8.2], [1.53, 1.56, 0], 0xd8b984, bridgeGroup);
// Stepped stone arch and piers.
for (const side of [-1, 1]) {
for (let i = 0; i <= 18; i++) {
const angle = (i / 18) * Math.PI;
const z = Math.cos(angle) * 3.05;
const y = 0.24 + Math.sin(angle) * 1.02;
box(
[0.34, 0.34, 0.42],
[side * 1.38, y, z],
i % 3 === 0 ? 0xb59463 : 0xc2a16e,
bridgeGroup
);
}
box([0.48, 1.10, 0.65], [side * 1.36, 0.57, 3.15], 0xb59463, bridgeGroup);
box([0.48, 1.10, 0.65], [side * 1.36, 0.57, -3.15], 0xb59463, bridgeGroup);
}
// Shop rows leave a narrow central passage.
const shopColors = [
0xd9a65d, 0xe6c27c, 0xcf8a52, 0xe8bd73,
0xc87d4e, 0xdfb768, 0xd19a58
];
const shopZ = [-3.25, -2.18, -1.10, 0, 1.10, 2.18, 3.25];
shopZ.forEach((z, index) => {
const height = 2.02 + (index % 3) * 0.18;
for (const side of [-1, 1]) {
const x = side * 1.05;
const color = shopColors[(index + (side > 0 ? 2 : 0)) % shopColors.length];
box(
[0.93, height, 0.96],
[x, 1.42 + height / 2, z],
color,
bridgeGroup
);
box(
[1.08, 0.17, 1.10],
[x, 1.42 + height + 0.085, z],
index === 3 && side === 1 ? 0x8b5940 : 0xb96042,
bridgeGroup
);
// Outer windows and central passage windows.
box(
[0.055, 0.42, 0.24],
[x + side * 0.49, 2.22, z],
windowMaterial,
bridgeGroup
);
box(
[0.06, 0.42, 0.24],
[x - side * 0.49, 2.22, z],
windowMaterial,
bridgeGroup
);
if (index % 2 === 0) {
box(
[0.10, 0.62, 0.22],
[x + side * 0.50, 1.79, z + 0.22],
0x7f674b,
bridgeGroup
);
}
}
});
// A brighter jewelry-shop volume near the center.
box([0.94, 2.45, 1.16], [1.05, 2.64, 1.10], 0xe7bd62, bridgeGroup);
box([1.09, 0.18, 1.30], [1.05, 3.95, 1.10], 0x965238, bridgeGroup);
// Small teal crossing beacons.
const beaconMaterial = material(0x9dd9cf, {
emissive: 0x2b8f88,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.72
});
box([0.11, 1.20, 0.11], [-1.72, 2.16, 4.23], beaconMaterial, bridgeGroup);
box([0.11, 1.20, 0.11], [1.72, 2.16, 4.23], beaconMaterial, bridgeGroup);
box([0.11, 1.20, 0.11], [-1.72, 2.16, -4.23], beaconMaterial, bridgeGroup);
box([0.11, 1.20, 0.11], [1.72, 2.16, -4.23], beaconMaterial, bridgeGroup);
// ------------------------------------------------------------
// Route objects
// ------------------------------------------------------------
const routeTilesGroup = new THREE.Group();
const directGroup = new THREE.Group();
scene.add(routeTilesGroup, directGroup);
const routeTileGeometry = new THREE.BoxGeometry(0.12, 0.10, 0.12);
const routeTileMaterial = material(0xef7047, {
emissive: 0xa9311e,
emissiveIntensity: 0.28,
roughness: 0.52
});
const routeLineMaterial = new THREE.LineBasicMaterial({
color: 0xef7047,
transparent: true,
opacity: 0.95
});
const directLineMaterial = new THREE.LineDashedMaterial({
color: 0x557985,
dashSize: 0.32,
gapSize: 0.20,
transparent: true,
opacity: 0.9
});
function makeMarker(color) {
const group = new THREE.Group();
box([0.52, 0.13, 0.52], [0, 0.07, 0], 0x32484c, group);
box([0.10, 0.78, 0.10], [0, 0.48, 0], 0x32484c, group);
box([0.43, 0.43, 0.43], [0, 1.02, 0], color, group);
box([0.25, 0.10, 0.25], [0, 1.27, 0], 0xfff4dc, group);
scene.add(group);
return group;
}
const markerA = makeMarker(0x168e88);
const markerB = makeMarker(0xd85a43);
const walker = new THREE.Group();
box([0.19, 0.38, 0.18], [0, 0.34, 0], 0x263d43, walker);
box([0.20, 0.20, 0.20], [0, 0.64, 0], 0xe3b483, walker);
box([0.07, 0.17, 0.08], [-0.055, 0.09, 0], 0x263d43, walker);
box([0.07, 0.17, 0.08], [0.055, 0.09, 0], 0x263d43, walker);
box([0.10, 0.06, 0.11], [0, 0.36, 0.12], 0xef7047, walker);
walker.visible = false;
scene.add(walker);
const defaultA = new THREE.Vector3(7.8, 1.30, 4.72);
const defaultB = new THREE.Vector3(-4.8, 1.30, -4.72);
let endpointA = defaultA.clone();
let endpointB = defaultB.clone();
let promenadeStops = [];
let routePoints = [];
let routeCumulative = [];
let routeLength = 0;
let routeTiles = [];
let routeLine = null;
let placementMode = "destinations";
let traceAnimating = false;
let traceDistance = 0;
function sideOf(point) {
return point.z >= 0 ? 1 : -1;
}
function bridgeMouth(side) {
return new THREE.Vector3(0, 1.53, side * 4.22);
}
function expandRoute(sequence) {
const expanded = [];
for (let i = 0; i < sequence.length; i++) {
const current = sequence[i].clone();
if (i > 0) {
const previous = sequence[i - 1];
if (sideOf(previous) !== sideOf(current)) {
expanded.push(bridgeMouth(sideOf(previous)));
expanded.push(bridgeMouth(sideOf(current)));
}
}
expanded.push(current);
}
return expanded;
}
function computeCumulative(points) {
const cumulative = [0];
let length = 0;
for (let i = 1; i < points.length; i++) {
length += points[i].distanceTo(points[i - 1]);
cumulative.push(length);
}
return cumulative;
}
function clearRouteVisuals() {
routeTilesGroup.clear();
directGroup.clear();
if (routeLine) {
routeLine.geometry.dispose();
routeLine.parent?.remove(routeLine);
routeLine = null;
}
directGroup.children.forEach((child) => {
child.geometry?.dispose();
});
}
function cancelTrace() {
traceAnimating = false;
traceDistance = 0;
walker.visible = false;
$("traceProgress").style.width = "0%";
$("traceBtn").textContent = "▶ Trace the walkable route";
routeTiles.forEach((tile) => {
tile.visible = true;
});
}
function rebuildRoute() {
cancelTrace();
clearRouteVisuals();
const sequence = [
endpointA.clone(),
...promenadeStops.map((point) => point.clone()),
endpointB.clone()
];
routePoints = expandRoute(sequence);
routeCumulative = computeCumulative(routePoints);
routeLength = routeCumulative.at(-1) || 0;
// Continuous thin line under the voxel tiles.
const routeGeometry = new THREE.BufferGeometry().setFromPoints(routePoints);
routeLine = new THREE.Line(routeGeometry, routeLineMaterial);
routeTilesGroup.add(routeLine);
// Small cube tiles make the route visibly voxel-like.
routeTiles = [];
for (let i = 1; i < routePoints.length; i++) {
const from = routePoints[i - 1];
const to = routePoints[i];
const length = from.distanceTo(to);
const steps = Math.max(1, Math.ceil(length / 0.25));
for (let j = 0; j < steps; j++) {
const t = (j + 0.5) / steps;
const position = from.clone().lerp(to, t);
const mesh = new THREE.Mesh(routeTileGeometry, routeTileMaterial);
mesh.position.copy(position);
mesh.castShadow = false;
mesh.receiveShadow = true;
mesh.userData.distance = routeCumulative[i - 1] + length * t;
routeTilesGroup.add(mesh);
routeTiles.push(mesh);
}
}
// The shortest, but impossible, straight line.
const directStart = endpointA.clone();
const directEnd = endpointB.clone();
directStart.y = 1.43;
directEnd.y = 1.43;
const directGeometry = new THREE.BufferGeometry().setFromPoints([
directStart,
directEnd
]);
const directLine = new THREE.Line(directGeometry, directLineMaterial);
directLine.computeLineDistances();
directGroup.add(directLine);
// Find where the straight line meets the water and mark the missing landing.
const denominator = directEnd.z - directStart.z;
const t = Math.abs(denominator) > 0.0001
? THREE.MathUtils.clamp((0 - directStart.z) / denominator, 0, 1)
: 0.5;
const crossing = directStart.clone().lerp(directEnd, t);
crossing.y = 0.21;
const crossGroup = new THREE.Group();
crossGroup.position.copy(crossing);
crossGroup.rotation.y = Math.PI * 0.25;
box([0.86, 0.055, 0.13], [0, 0, 0], 0xf1dfc0, crossGroup);
box([0.13, 0.055, 0.86], [0, 0, 0], 0xc95c47, crossGroup);
directGroup.add(crossGroup);
markerA.position.set(endpointA.x, 1.19, endpointA.z);
markerB.position.set(endpointB.x, 1.19, endpointB.z);
const directDistance = Math.hypot(
endpointB.x - endpointA.x,
endpointB.z - endpointA.z
);
const extra = Math.max(0, routeLength - directDistance);
const percent = directDistance > 0 ? Math.round((extra / directDistance) * 100) : 0;
$("directMetric").textContent = `${Math.round(directDistance * 10)} m`;
$("walkMetric").textContent = `${Math.round(routeLength * 10)} m`;
$("extraMetric").textContent = `+${Math.round(extra * 10)} m · ${percent}%`;
directGroup.visible = $("directToggle").checked;
}
// ------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------
const labelEntries = [
{ el: $("labelBridge"), position: new THREE.Vector3(0, 4.75, 0.15) },
{ el: $("labelCrossing"), position: new THREE.Vector3(0, 4.18, 4.20) },
{ el: $("labelArno"), position: new THREE.Vector3(-8.7, 0.38, -0.5) },
{ el: $("labelNorth"), position: new THREE.Vector3(-7.8, 1.45, 4.72) },
{ el: $("labelSouth"), position: new THREE.Vector3(7.2, 1.45, -4.72) },
{ el: $("labelPalazzo"), position: new THREE.Vector3(9.1, 7.55, 8.6) },
{ el: $("labelUffizi"), position: new THREE.Vector3(-3.8, 4.30, -8.7) }
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const entry of labelEntries) {
const point = entry.position.clone().project(camera);
const visible = point.z > -1 && point.z < 1;
entry.el.style.display = visible ? "" : "none";
if (visible) {
entry.el.style.left = `${(point.x * 0.5 + 0.5) * width}px`;
entry.el.style.top = `${(-point.y * 0.5 + 0.5) * height}px`;
}
}
const noLandingAnchor = directGroup.children.at(-1);
if (noLandingAnchor) {
const p = noLandingAnchor.position.clone();
p.y = 0.8;
const projected = p.project(camera);
const visible = projected.z > -1 && projected.z < 1;
$("labelNoLanding").style.display = visible ? "" : "none";
$("labelNoLanding").style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
$("labelNoLanding").style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
for (const [id, point] of [
["labelA", markerA.position],
["labelB", markerB.position]
]) {
const p = point.clone();
p.y += 2.18;
const projected = p.project(camera);
const visible = projected.z > -1 && projected.z < 1;
$(id).style.display = visible ? "" : "none";
$(id).style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
$(id).style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// ------------------------------------------------------------
// Custom orthographic camera controls and picking
// ------------------------------------------------------------
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
const viewSize = Math.max(23.5, 34 / aspect);
camera.left = (-viewSize * aspect) / (2 * cameraState.zoom);
camera.right = (viewSize * aspect) / (2 * cameraState.zoom);
camera.top = viewSize / (2 * cameraState.zoom);
camera.bottom = -viewSize / (2 * cameraState.zoom);
camera.updateProjectionMatrix();
}
function updateCamera() {
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.targetTheta,
0.12
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.targetPhi,
0.12
);
cameraState.zoom = THREE.MathUtils.lerp(
cameraState.zoom,
cameraState.targetZoom,
0.12
);
const horizontal = cameraState.radius * Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + horizontal * Math.cos(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z + horizontal * Math.sin(cameraState.theta)
);
camera.lookAt(cameraTarget);
updateProjection();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickBank(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(bankHitMeshes, false);
if (!hits.length) return null;
const hit = hits[0].point;
const side = hit.z >= 0 ? 1 : -1;
return new THREE.Vector3(
THREE.MathUtils.clamp(hit.x, -11.7, 11.7),
1.30,
side * 4.72
);
}
const drag = {
active: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
drag.active = true;
drag.moved = false;
drag.startX = event.clientX;
drag.startY = event.clientY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag.active) return;
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
if (
Math.hypot(
event.clientX - drag.startX,
event.clientY - drag.startY
) > 5
) {
drag.moved = true;
}
if (drag.moved) {
cameraState.targetTheta -= dx * 0.006;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - dy * 0.0045,
0.48,
1.18
);
}
drag.lastX = event.clientX;
drag.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!drag.active) return;
drag.active = false;
if (!drag.moved) {
const point = pickBank(event.clientX, event.clientY);
if (point) {
if (placementMode === "destinations") {
if (sideOf(point) > 0) {
endpointA = point;
$("routeHint").textContent =
"A moved to the north quay. Click the south quay to move B.";
} else {
endpointB = point;
$("routeHint").textContent =
"B moved to the south quay. The direct crossing still has no landing.";
}
$("routeHint").classList.remove("warm");
rebuildRoute();
} else if (placementMode === "stop") {
promenadeStops.push(point);
$("routeHint").textContent =
`Stop ${promenadeStops.length} added. Add another, undo, or trace the route.`;
rebuildRoute();
}
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
drag.active = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = event.deltaY > 0 ? 0.90 : 1.10;
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom * factor,
0.72,
1.75
);
},
{ passive: false }
);
// ------------------------------------------------------------
// UI actions
// ------------------------------------------------------------
$("placeBtn").addEventListener("click", () => {
cancelTrace();
placementMode = "destinations";
$("modeBadge").textContent = "Placing";
$("routeHint").textContent =
"Click the north quay to move A, or the south quay to move B.";
$("routeHint").classList.remove("warm");
});
$("stopBtn").addEventListener("click", () => {
cancelTrace();
placementMode = "stop";
$("modeBadge").textContent = "Adding stop";
$("routeHint").textContent =
"Click either quay to add a stop. Stops are visited in the order added.";
$("routeHint").classList.add("warm");
});
$("resetBtn").addEventListener("click", () => {
endpointA = defaultA.clone();
endpointB = defaultB.clone();
promenadeStops = [];
placementMode = "destinations";
$("modeBadge").textContent = "Ready";
$("routeHint").textContent =
"Click either quay to move a destination. The bridge is the only legal river crossing in this scene.";
$("routeHint").classList.remove("warm");
rebuildRoute();
});
$("directToggle").addEventListener("change", (event) => {
directGroup.visible = event.target.checked;
});
$("traceBtn").addEventListener("click", () => {
if (traceAnimating) {
cancelTrace();
return;
}
placementMode = "none";
$("modeBadge").textContent = "Tracing";
$("routeHint").textContent =
"Tracing the orange route. The straight diagonal cannot become a street without a landing.";
traceDistance = 0;
traceAnimating = true;
walker.visible = true;
walker.position.copy(routePoints[0]);
$("traceBtn").textContent = "■ Stop tracing";
routeTiles.forEach((tile) => {
tile.visible = false;
});
});
$("cameraLeft").addEventListener("click", () => {
cameraState.targetTheta -= 0.25;
});
$("cameraRight").addEventListener("click", () => {
cameraState.targetTheta += 0.25;
});
$("zoomIn").addEventListener("click", () => {
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom * 1.14,
0.72,
1.75
);
});
$("zoomOut").addEventListener("click", () => {
cameraState.targetZoom = THREE.MathUtils.clamp(
cameraState.targetZoom / 1.14,
0.72,
1.75
);
});
$("cameraReset").addEventListener("click", () => {
cameraState.targetTheta = 0.72;
cameraState.targetPhi = 0.80;
cameraState.targetZoom = 1;
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
cancelTrace();
placementMode = "none";
$("modeBadge").textContent = "Ready";
}
});
// ------------------------------------------------------------
// Route animation
// ------------------------------------------------------------
function sampleRoute(distance) {
for (let i = 1; i < routePoints.length; i++) {
if (distance <= routeCumulative[i]) {
const segmentLength = routeCumulative[i] - routeCumulative[i - 1];
const t = segmentLength > 0
? (distance - routeCumulative[i - 1]) / segmentLength
: 0;
const position = routePoints[i - 1].clone().lerp(routePoints[i], t);
const direction = routePoints[i].clone().sub(routePoints[i - 1]);
return { position, direction };
}
}
return {
position: routePoints.at(-1)?.clone() ?? new THREE.Vector3(),
direction: new THREE.Vector3(0, 0, 1)
};
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateProjection();
});
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera();
rippleMeshes.forEach((ripple, index) => {
ripple.position.x =
ripple.userData.baseX + Math.sin(elapsed * 0.35 + index * 0.7) * 0.22;
});
if (traceAnimating) {
traceDistance = Math.min(
routeLength,
traceDistance + delta * 3.25
);
const sample = sampleRoute(traceDistance);
walker.position.copy(sample.position);
if (sample.direction.lengthSq() > 0.0001) {
walker.rotation.y = Math.atan2(
sample.direction.x,
sample.direction.z
);
}
routeTiles.forEach((tile) => {
tile.visible = tile.userData.distance <= traceDistance + 0.01;
});
$("traceProgress").style.width =
`${routeLength ? (traceDistance / routeLength) * 100 : 0}%`;
if (traceDistance >= routeLength - 0.001) {
traceAnimating = false;
walker.visible = false;
$("traceBtn").textContent = "↻ Trace again";
$("modeBadge").textContent = "Complete";
$("routeHint").classList.add("warm");
$("routeHint").textContent =
"Route complete. The bridge forces a longer path even though the buildings look close across the water.";
}
}
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
$("loading").style.display = "none";
}
}
rebuildRoute();
updateCamera();
animate();
</script>
</body>
</html>
```