Prompt specification
Build or customize the Three.js 3D scene "Choose a route to the Olinda viewpoint" 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: Choose a route to the Olinda viewpoint
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/choose-a-route-to-the-olinda-viewpoint-x2680
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Alto da Sé in Olinda. Let users compare two schematic approaches to the hilltop square. Display length and elevation gain separately and keep the same final viewing position for both routes. Voxel style.
Working Three.js Starter (choose-a-route-to-the-olinda-viewpoint-x2680):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Alto da Sé — Olinda Route Comparison</title>
<style>
:root {
--ink: #183b3b;
--muted: #667976;
--paper: #f4f0e6;
--line: rgba(24, 59, 59, 0.14);
--route-a: #087f8c;
--route-b: #df6b48;
--arrival: #dba72d;
--panel-shadow: 0 12px 32px rgba(28, 55, 53, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
}
header {
min-height: 78px;
padding: 13px 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
border-bottom: 1px solid var(--line);
background: rgba(244, 240, 230, 0.96);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
}
.brand-mark span {
position: absolute;
display: block;
border: 1px solid rgba(24, 59, 59, 0.2);
background: #dfebdc;
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2);
}
.brand-mark span:nth-child(1) {
left: 3px;
top: 14px;
width: 15px;
height: 15px;
background: #b8cda8;
}
.brand-mark span:nth-child(2) {
left: 12px;
top: 8px;
width: 15px;
height: 15px;
background: #e4d8b6;
}
.brand-mark span:nth-child(3) {
left: 20px;
top: 2px;
width: 15px;
height: 15px;
background: #f1e8cf;
}
.eyebrow {
margin: 0 0 2px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(20px, 2.1vw, 30px);
font-weight: 600;
line-height: 1;
letter-spacing: -0.025em;
}
.brand-subtitle {
margin-left: 8px;
color: var(--muted);
font-size: 12px;
font-weight: 500;
}
.toolbar {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
flex-wrap: wrap;
}
.toolbar button {
min-height: 38px;
padding: 8px 13px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: rgba(255, 255, 255, 0.54);
cursor: pointer;
font-size: 12px;
font-weight: 700;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
.toolbar button:hover {
transform: translateY(-1px);
border-color: rgba(24, 59, 59, 0.32);
background: rgba(255, 255, 255, 0.86);
}
.toolbar button:focus-visible {
outline: 3px solid rgba(8, 127, 140, 0.25);
outline-offset: 2px;
}
.toolbar .primary {
color: #f8f4e9;
border-color: var(--ink);
background: var(--ink);
}
.toolbar .primary:hover {
background: #245453;
}
.toolbar .active {
color: #f8f4e9;
border-color: var(--ink);
background: var(--ink);
}
.same-end {
display: flex;
align-items: center;
gap: 7px;
margin-right: 4px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
white-space: nowrap;
}
.same-end::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--arrival);
box-shadow: 0 0 0 4px rgba(219, 167, 45, 0.14);
}
#stage {
position: relative;
min-height: 0;
display: grid;
grid-template-columns: 1fr 1fr;
overflow: hidden;
background: #dce8e2;
}
#viewport {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#viewport.dragging {
cursor: grabbing;
}
.panel {
position: relative;
z-index: 2;
min-width: 0;
min-height: 0;
pointer-events: none;
}
#panel-b {
border-left: 1px solid rgba(24, 59, 59, 0.16);
}
.route-heading {
position: absolute;
top: 18px;
left: 18px;
max-width: min(390px, calc(100% - 36px));
padding: 12px 14px;
border: 1px solid rgba(24, 59, 59, 0.11);
border-radius: 13px;
background: rgba(248, 245, 235, 0.88);
box-shadow: 0 8px 24px rgba(27, 57, 54, 0.08);
backdrop-filter: blur(9px);
}
.route-kicker {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.route-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--route-a);
}
#panel-b .route-dot {
background: var(--route-b);
}
.route-heading h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(18px, 2vw, 27px);
font-weight: 600;
line-height: 1.05;
letter-spacing: -0.02em;
}
.route-description {
margin-top: 5px;
color: var(--muted);
font-size: 11px;
}
.arrival-badge {
position: absolute;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border: 1px solid rgba(24, 59, 59, 0.11);
border-radius: 999px;
color: var(--muted);
background: rgba(248, 245, 235, 0.86);
box-shadow: 0 6px 18px rgba(27, 57, 54, 0.07);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.arrival-badge::before {
content: "";
width: 7px;
height: 7px;
border: 2px solid var(--arrival);
border-radius: 2px;
}
.stats-card {
position: absolute;
left: 18px;
bottom: 18px;
width: min(370px, calc(100% - 36px));
padding: 13px 14px 10px;
border: 1px solid rgba(24, 59, 59, 0.12);
border-radius: 14px;
background: rgba(248, 245, 235, 0.92);
box-shadow: var(--panel-shadow);
backdrop-filter: blur(10px);
}
.metric-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.metric {
min-width: 0;
}
.metric + .metric {
padding-left: 12px;
border-left: 1px solid var(--line);
}
.metric-label {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(21px, 2.2vw, 31px);
font-weight: 600;
line-height: 1;
letter-spacing: -0.035em;
}
#panel-a .metric-value {
color: var(--route-a);
}
#panel-b .metric-value {
color: var(--route-b);
}
.profile {
display: block;
width: 100%;
height: 44px;
margin-top: 8px;
overflow: visible;
}
.profile-caption {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 8px;
font-weight: 650;
letter-spacing: 0.05em;
text-transform: uppercase;
}
footer {
min-height: 36px;
padding: 8px 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
border-top: 1px solid var(--line);
color: var(--muted);
background: var(--paper);
font-size: 10px;
font-weight: 600;
}
footer strong {
color: var(--ink);
}
#loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--ink);
background: #e4e9df;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 850px) {
header {
min-height: 70px;
padding: 10px 12px;
}
.brand-subtitle,
.same-end {
display: none;
}
.toolbar button {
padding: 7px 10px;
font-size: 10px;
}
#stage {
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr;
}
#panel-b {
border-top: 1px solid rgba(24, 59, 59, 0.16);
border-left: 0;
}
.route-heading {
top: 10px;
left: 10px;
max-width: calc(100% - 20px);
padding: 9px 11px;
}
.arrival-badge {
top: 10px;
right: 10px;
max-width: 124px;
font-size: 8px;
}
.stats-card {
left: 10px;
bottom: 10px;
width: calc(100% - 20px);
padding: 9px 11px;
}
.profile {
display: none;
}
footer {
padding: 7px 12px;
}
.footer-hint {
display: none;
}
}
@media (max-width: 520px) {
.brand-mark {
display: none;
}
.toolbar {
gap: 4px;
}
.toolbar button {
min-height: 34px;
padding: 6px 8px;
}
.view-top {
display: none;
}
.route-description {
display: none;
}
.route-heading h2 {
font-size: 19px;
}
.arrival-badge {
max-width: 112px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span>
<span></span>
<span></span>
</div>
<div>
<p class="eyebrow">Olinda · Pernambuco · Brasil</p>
<h1>
Alto da Sé
<span class="brand-subtitle">Voxel route comparison</span>
</h1>
</div>
</div>
<div class="toolbar">
<div class="same-end">Shared arrival point</div>
<button id="play" class="primary" type="button" aria-pressed="false">
▶ Play both
</button>
<button id="overview" class="active" type="button">
Overview
</button>
<button id="arrival" type="button">
Arrival view
</button>
<button id="top" class="view-top" type="button">
Top
</button>
</div>
</header>
<main id="stage">
<canvas id="viewport" aria-label="Interactive voxel route comparison"></canvas>
<section class="panel" id="panel-a" aria-label="Route A comparison">
<div class="route-heading">
<div class="route-kicker">
<span class="route-dot"></span>
Approach A
</div>
<h2>Ladeira do Carmo</h2>
<div class="route-description">Direct, stair-focused approach</div>
</div>
<div class="arrival-badge">Same square</div>
<div class="stats-card">
<div class="metric-row">
<div class="metric">
<span class="metric-label">Route length</span>
<strong class="metric-value" id="length-a">—</strong>
</div>
<div class="metric">
<span class="metric-label">Elevation gain</span>
<strong class="metric-value" id="gain-a">—</strong>
</div>
</div>
<svg
class="profile"
id="profile-a"
viewBox="0 0 180 40"
preserveAspectRatio="none"
role="img"
aria-label="Elevation profile for route A"
></svg>
<div class="profile-caption">
<span id="progress-a">Ready</span>
<span>Elevation profile</span>
</div>
</div>
</section>
<section class="panel" id="panel-b" aria-label="Route B comparison">
<div class="route-heading">
<div class="route-kicker">
<span class="route-dot"></span>
Approach B
</div>
<h2>Contorno das Casas</h2>
<div class="route-description">Longer, gentler perimeter approach</div>
</div>
<div class="arrival-badge">Same square</div>
<div class="stats-card">
<div class="metric-row">
<div class="metric">
<span class="metric-label">Route length</span>
<strong class="metric-value" id="length-b">—</strong>
</div>
<div class="metric">
<span class="metric-label">Elevation gain</span>
<strong class="metric-value" id="gain-b">—</strong>
</div>
</div>
<svg
class="profile"
id="profile-b"
viewBox="0 0 180 40"
preserveAspectRatio="none"
role="img"
aria-label="Elevation profile for route B"
></svg>
<div class="profile-caption">
<span id="progress-b">Ready</span>
<span>Elevation profile</span>
</div>
</div>
</section>
<div id="loading">Building the voxel model…</div>
</main>
<footer>
<span><strong>Controls:</strong> drag to orbit · scroll to zoom</span>
<span class="footer-hint">Matched walking pace · synchronized cameras</span>
<span>Conceptual estimates — not for navigation</span>
</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const canvas = document.getElementById("viewport");
const panels = [
document.getElementById("panel-a"),
document.getElementById("panel-b")
];
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = false;
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 300);
const overviewView = {
target: new THREE.Vector3(0, 4, 3),
azimuth: 0.62,
polar: 0.84,
zoom: 0.96
};
const arrivalView = {
target: new THREE.Vector3(0, 6, -7),
azimuth: 0.18,
polar: 1.01,
zoom: 1.72
};
const topView = {
target: new THREE.Vector3(0, 0, 3),
azimuth: 0,
polar: 0.075,
zoom: 1.02
};
const currentView = {
target: overviewView.target.clone(),
azimuth: overviewView.azimuth,
polar: overviewView.polar,
zoom: overviewView.zoom
};
const desiredView = {
target: overviewView.target.clone(),
azimuth: overviewView.azimuth,
polar: overviewView.polar,
zoom: overviewView.zoom
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function addBox(
scene,
x,
y,
z,
width,
height,
depth,
color,
options = {}
) {
const mesh = new THREE.Mesh(
unitBox,
getMaterial(color, options.material || {})
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
scene.add(mesh);
return mesh;
}
function terrainHeight(x, z) {
let height = THREE.MathUtils.clamp(
Math.floor((25 - z) / 6),
0,
6
);
// A small raised eastern terrace gives route B a gentler start.
if (x > 18 && z > 15) {
height += 1;
}
// Flat hilltop square.
if (Math.abs(x) < 8 && z > -9 && z < -4) {
height = 6;
}
// Cathedral terrace.
if (Math.abs(x) < 8 && z <= -9) {
height = 6;
}
return Math.min(height, 6);
}
const routeDefinitions = [
{
key: "A",
color: 0x087f8c,
css: "#087f8c",
controls: [
new THREE.Vector3(-13, 0.38, 28),
new THREE.Vector3(-14, 0.38, 23),
new THREE.Vector3(-13, 1.38, 18),
new THREE.Vector3(-11, 2.38, 13),
new THREE.Vector3(-8, 3.38, 8),
new THREE.Vector3(-5, 4.38, 3),
new THREE.Vector3(-2, 5.38, -2),
new THREE.Vector3(0, 6.38, -7)
]
},
{
key: "B",
color: 0xdf6b48,
css: "#df6b48",
controls: [
new THREE.Vector3(25, 1.38, 31),
new THREE.Vector3(28, 1.38, 26),
new THREE.Vector3(27, 1.38, 20),
new THREE.Vector3(23, 2.38, 14),
new THREE.Vector3(18, 2.38, 9),
new THREE.Vector3(12, 3.38, 5),
new THREE.Vector3(8, 4.38, 1),
new THREE.Vector3(4, 5.38, -3),
new THREE.Vector3(1, 6.38, -5),
new THREE.Vector3(0, 6.38, -7)
]
}
];
// Model units are intentionally schematic:
// one horizontal unit represents approximately 8 m,
// and one vertical unit approximately 4 m.
const HORIZONTAL_METERS = 8;
const VERTICAL_METERS = 4;
function measureRoute(samples) {
let length = 0;
let elevationGain = 0;
for (let i = 1; i < samples.length; i++) {
const a = samples[i - 1];
const b = samples[i];
const dx = (b.x - a.x) * HORIZONTAL_METERS;
const dy = (b.y - a.y) * VERTICAL_METERS;
const dz = (b.z - a.z) * HORIZONTAL_METERS;
length += Math.sqrt(dx * dx + dy * dy + dz * dz);
elevationGain += Math.max(0, dy);
}
return {
length: Math.round(length / 10) * 10,
elevationGain: Math.round(elevationGain)
};
}
const routeData = routeDefinitions.map((definition) => {
const curve = new THREE.CatmullRomCurve3(
definition.controls,
false,
"catmullrom",
0.22
);
const samples = curve.getPoints(420);
return {
...definition,
curve,
samples,
metrics: measureRoute(samples)
};
});
function makeProfile(samples, color) {
const width = 180;
const height = 40;
const bottom = 36;
const ys = samples.map((point) => point.y);
const minY = Math.min(...ys);
const maxY = Math.max(...ys);
const range = Math.max(0.001, maxY - minY);
const points = samples.map((point, index) => {
const x = 4 + (index / (samples.length - 1)) * (width - 8);
const y = bottom - ((point.y - minY) / range) * 27;
return `${x.toFixed(2)},${y.toFixed(2)}`;
});
const line = points.join(" ");
const area = `M 4,${bottom} L ${points.join(" L ")} L 172,${bottom} Z`;
return `
<rect x="0" y="0" width="180" height="40" fill="transparent"/>
<line x1="4" y1="35.5" x2="176" y2="35.5"
stroke="rgba(24,59,59,.14)" stroke-width="1"/>
<path d="${area}" fill="${color}" opacity=".12"/>
<polyline points="${line}" fill="none" stroke="${color}"
stroke-width="2.2" stroke-linecap="round"
stroke-linejoin="round"/>
<circle cx="176" cy="${points[points.length - 1].split(",")[1]}"
r="2.5" fill="#dba72d"/>
`;
}
document.getElementById("length-a").textContent =
`${routeData[0].metrics.length} m`;
document.getElementById("gain-a").textContent =
`+${routeData[0].metrics.elevationGain} m`;
document.getElementById("length-b").textContent =
`${routeData[1].metrics.length} m`;
document.getElementById("gain-b").textContent =
`+${routeData[1].metrics.elevationGain} m`;
document.getElementById("profile-a").innerHTML =
makeProfile(routeData[0].samples, routeData[0].css);
document.getElementById("profile-b").innerHTML =
makeProfile(routeData[1].samples, routeData[1].css);
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
function isNearRoute(x, z, radius = 3.2) {
for (const route of routeData) {
for (const point of route.samples) {
const dx = point.x - x;
const dz = point.z - z;
if (dx * dx + dz * dz < radius * radius) {
return true;
}
}
}
return false;
}
function createTerrain(scene) {
const cellSize = 2;
const cells = [];
for (let x = -27; x <= 27; x += cellSize) {
for (let z = -23; z <= 33; z += cellSize) {
cells.push({ x, z, height: terrainHeight(x, z) });
}
}
const geometry = new THREE.BoxGeometry(cellSize, 1, cellSize);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
vertexColors: true
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
cells.length
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
const palette = [
0xa9c7a5,
0xb4c89d,
0xc3cd9d,
0xd1d09d,
0xddd2a7,
0xe5d4ad,
0xeddfbc
];
let index = 0;
for (const cell of cells) {
const height = cell.height;
dummy.position.set(cell.x, (height - 1) / 2, cell.z);
dummy.scale.set(1, height + 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
color.setHex(palette[height]);
color.offsetHSL(
0,
0,
(((cell.x * 13 + cell.z * 7) % 9) - 4) * 0.006
);
mesh.setColorAt(index, color);
index++;
}
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.castShadow = false;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
scene.add(mesh);
}
function addBuilding(scene, x, z, width, depth, height, wallColor) {
const ground = terrainHeight(x, z);
addBox(
scene,
x,
ground + height / 2,
z,
width,
height,
depth,
wallColor
);
const roofColor = new THREE.Color(wallColor)
.multiplyScalar(0.72)
.offsetHSL(0.02, 0.08, -0.02)
.getHex();
addBox(
scene,
x,
ground + height + 0.18,
z,
width + 0.35,
0.38,
depth + 0.35,
roofColor
);
addBox(
scene,
x,
ground + height + 0.58,
z,
width * 0.68,
0.43,
depth * 0.68,
roofColor
);
}
function addTree(scene, x, z, scale = 1) {
const ground = terrainHeight(x, z);
addBox(
scene,
x,
ground + 0.85 * scale,
z,
0.55 * scale,
1.7 * scale,
0.55 * scale,
0x80664d
);
addBox(
scene,
x,
ground + 2.1 * scale,
z,
2.5 * scale,
2.2 * scale,
2.5 * scale,
0x6f9b70
);
addBox(
scene,
x + 0.2 * scale,
ground + 3.15 * scale,
z - 0.15 * scale,
1.65 * scale,
1.35 * scale,
1.65 * scale,
0x83aa78
);
}
function addCathedral(scene) {
const ivory = 0xf0e4c6;
const ivoryLight = 0xfaefd6;
const stone = 0xd8c9aa;
const roof = 0x668b91;
const dark = 0x355457;
// Platform and three voxel steps.
addBox(scene, 0, 6.18, -15, 12.6, 0.42, 12.4, stone);
addBox(scene, 0, 6.38, -10.6, 8.7, 0.22, 1.3, ivoryLight);
addBox(scene, 0, 6.53, -10.0, 7.8, 0.20, 1.0, ivoryLight);
addBox(scene, 0, 6.68, -9.45, 6.9, 0.18, 0.7, ivoryLight);
// Main nave.
addBox(scene, 0, 9.05, -16, 7.2, 5.1, 7.6, ivory);
addBox(scene, 0, 11.75, -16, 7.8, 0.55, 8.2, roof);
addBox(scene, 0, 12.2, -16, 5.7, 0.4, 6.3, roof);
// Front facade.
addBox(scene, 0, 9.1, -12.0, 6.8, 5.4, 1.4, ivoryLight);
addBox(scene, 0, 11.95, -12.0, 7.5, 0.5, 1.8, roof);
// Stepped pediment.
addBox(scene, 0, 12.55, -12.0, 4.6, 0.45, 1.6, ivoryLight);
addBox(scene, 0, 13.0, -12.0, 2.7, 0.45, 1.4, ivoryLight);
// Twin towers.
for (const x of [-4.35, 4.35]) {
addBox(scene, x, 9.65, -12.25, 2.55, 7.15, 3.0, ivory);
addBox(scene, x, 13.35, -12.25, 2.85, 0.45, 3.25, stone);
addBox(scene, x, 13.85, -12.25, 2.25, 0.55, 2.65, roof);
addBox(
scene,
x,
10.8,
-10.72,
0.7,
2.15,
0.16,
dark,
{ castShadow: false }
);
}
// Central doorway and windows.
addBox(scene, 0, 7.75, -11.25, 1.55, 2.7, 0.18, dark);
addBox(scene, 0, 10.55, -11.22, 0.72, 1.45, 0.17, dark);
addBox(scene, -2.25, 10.15, -11.22, 0.62, 1.35, 0.17, dark);
addBox(scene, 2.25, 10.15, -11.22, 0.62, 1.35, 0.17, dark);
// Small cross.
addBox(scene, 0, 13.55, -12, 0.22, 1.35, 0.22, dark);
addBox(scene, 0, 13.85, -12, 0.9, 0.22, 0.22, dark);
// Voxel fountain on the square.
addBox(scene, 5.4, 6.55, -4.3, 2.8, 0.75, 2.8, stone);
addBox(scene, 5.4, 6.98, -4.3, 1.8, 0.22, 1.8, 0x72aeb5);
addBox(scene, 5.4, 7.65, -4.3, 0.45, 1.2, 0.45, ivoryLight);
addBox(scene, 5.4, 8.25, -4.3, 1.25, 0.25, 1.25, stone);
}
function addSquare(scene) {
const tileColors = [0xe4d9bd, 0xddd1b4, 0xeadfc4];
for (let row = 0; row < 4; row++) {
for (let column = 0; column < 8; column++) {
addBox(
scene,
-6.3 + column * 1.8,
6.19,
-8.1 + row * 1.75,
1.68,
0.18,
1.63,
tileColors[(row + column) % tileColors.length],
{ castShadow: false }
);
}
}
}
function addTown(scene) {
const random = seededRandom(90210);
const wallPalette = [
0xd99068,
0xe3ad79,
0xe8c88f,
0xc8896e,
0xd8b48b,
0xa9c3b0,
0xc6a9bc,
0xe5d8b8
];
let buildingCount = 0;
for (let attempt = 0; attempt < 220 && buildingCount < 34; attempt++) {
const x = Math.round((random() * 46 - 23) * 2) / 2;
const z = Math.round((random() * 48 - 19) * 2) / 2;
if (z > -10 && z < -1 && Math.abs(x) < 10) {
continue;
}
if (z < -9 && Math.abs(x) < 9) {
continue;
}
if (isNearRoute(x, z, 3.6)) {
continue;
}
const width = 2.4 + random() * 2.4;
const depth = 2.4 + random() * 2.8;
const height = 2.6 + random() * 3.4;
const color = wallPalette[Math.floor(random() * wallPalette.length)];
addBuilding(scene, x, z, width, depth, height, color);
buildingCount++;
}
let treeCount = 0;
for (let attempt = 0; attempt < 130 && treeCount < 20; attempt++) {
const x = Math.round((random() * 50 - 25) * 2) / 2;
const z = Math.round((random() * 54 - 21) * 2) / 2;
if (z > -11 && z < 1 && Math.abs(x) < 10) {
continue;
}
if (isNearRoute(x, z, 3.2)) {
continue;
}
addTree(scene, x, z, 0.8 + random() * 0.35);
treeCount++;
}
// A few strong edge landmarks.
addBuilding(scene, -18, 5, 4.2, 4.7, 4.3, 0xe2af7a);
addBuilding(scene, 16, 14, 4.1, 4.3, 4.6, 0xc8896e);
addBuilding(scene, -17, -10, 3.8, 4.2, 4.0, 0xa9c3b0);
addBuilding(scene, 17, -10, 4.5, 4.0, 4.2, 0xe8c88f);
}
function createRouteMesh(scene, route) {
const count = Math.max(40, Math.ceil(route.curve.getLength() / 0.58));
const geometry = new THREE.BoxGeometry(0.72, 0.25, 1.05);
const material = new THREE.MeshStandardMaterial({
color: route.color,
roughness: 0.72,
emissive: route.color,
emissiveIntensity: 0.15
});
const mesh = new THREE.InstancedMesh(geometry, material, count);
const dummy = new THREE.Object3D();
const forward = new THREE.Vector3(0, 0, 1);
for (let index = 0; index < count; index++) {
const progress = index / (count - 1);
const point = route.curve.getPointAt(progress);
const tangent = route.curve.getTangentAt(progress).normalize();
dummy.position.copy(point);
dummy.position.y += 0.1;
dummy.quaternion.setFromUnitVectors(forward, tangent);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
scene.add(mesh);
return mesh;
}
function createFrame(scene, point, color) {
const y = point.y + 0.08;
addBox(scene, point.x, y, point.z - 1.25, 2.8, 0.22, 0.28, color);
addBox(scene, point.x, y, point.z + 1.25, 2.8, 0.22, 0.28, color);
addBox(scene, point.x - 1.25, y, point.z, 0.28, 0.22, 2.25, color);
addBox(scene, point.x + 1.25, y, point.z, 0.28, 0.22, 2.25, color);
}
function createWalker(scene, route) {
const group = new THREE.Group();
const body = new THREE.Mesh(
unitBox,
getMaterial(route.color)
);
body.scale.set(0.85, 1.15, 0.85);
body.position.y = 0.72;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
unitBox,
getMaterial(0xf7f0de)
);
head.scale.set(0.68, 0.68, 0.68);
head.position.y = 1.58;
head.castShadow = true;
group.add(head);
const shadow = new THREE.Mesh(
unitBox,
getMaterial(0x314847, {
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
shadow.scale.set(1.1, 0.06, 1.1);
shadow.position.y = 0.03;
group.add(shadow);
scene.add(group);
return group;
}
function buildScene(route) {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e2);
scene.fog = new THREE.Fog(0xdce8e2, 105, 170);
const hemisphere = new THREE.HemisphereLight(
0xf8f4df,
0x7f9c8c,
2.3
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc9, 3.1);
sun.position.set(-28, 58, 38);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -45;
sun.shadow.camera.right = 45;
sun.shadow.camera.top = 45;
sun.shadow.camera.bottom = -45;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 130;
sun.shadow.normalBias = 0.035;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dce0, 0.7);
fill.position.set(30, 22, -30);
scene.add(fill);
// Atlantic-colored plane surrounding the raised city model.
const ocean = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.MeshStandardMaterial({
color: 0x9fc7c7,
roughness: 0.95
})
);
ocean.rotation.x = -Math.PI / 2;
ocean.position.y = -2.05;
ocean.receiveShadow = true;
scene.add(ocean);
addBox(
scene,
0,
-1.62,
5,
56,
0.82,
58,
0xb5a487,
{ castShadow: false }
);
createTerrain(scene);
addTown(scene);
addSquare(scene);
addCathedral(scene);
createRouteMesh(scene, route);
const startPoint = route.curve.getPointAt(0);
const endPoint = route.curve.getPointAt(1);
createFrame(scene, startPoint, route.color);
createFrame(scene, endPoint, 0xdba72d);
const marker = createWalker(scene, route);
marker.position.copy(startPoint);
return { scene, marker, route };
}
const routeScenes = routeData.map(buildScene);
function setView(view, instant = false) {
desiredView.target.copy(view.target);
desiredView.azimuth = view.azimuth;
desiredView.polar = view.polar;
desiredView.zoom = view.zoom;
if (instant) {
currentView.target.copy(view.target);
currentView.azimuth = view.azimuth;
currentView.polar = view.polar;
currentView.zoom = view.zoom;
}
document
.querySelectorAll(".toolbar .active")
.forEach((button) => button.classList.remove("active"));
const buttonMap = {
overview: document.getElementById("overview"),
arrival: document.getElementById("arrival"),
top: document.getElementById("top")
};
buttonMap[view === overviewView ? "overview" :
view === arrivalView ? "arrival" : "top"].classList.add("active");
}
document.getElementById("overview").addEventListener("click", () => {
setView(overviewView);
});
document.getElementById("arrival").addEventListener("click", () => {
setView(arrivalView);
});
document.getElementById("top").addEventListener("click", () => {
setView(topView);
});
// Direct camera controls: no examples/addons are used.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) {
return;
}
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
currentView.azimuth -= deltaX * 0.006;
desiredView.azimuth = currentView.azimuth;
currentView.polar = THREE.MathUtils.clamp(
currentView.polar + deltaY * 0.005,
0.075,
1.38
);
desiredView.polar = currentView.polar;
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * 0.0012);
currentView.zoom = THREE.MathUtils.clamp(
currentView.zoom * factor,
0.58,
2.65
);
desiredView.zoom = currentView.zoom;
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
setView(overviewView);
});
const playButton = document.getElementById("play");
const progressLabels = [
document.getElementById("progress-a"),
document.getElementById("progress-b")
];
const BASE_DURATION = 8.5;
const durations = routeData.map((route, index) => {
if (index === 0) {
return BASE_DURATION;
}
return (
BASE_DURATION *
route.metrics.length /
routeData[0].metrics.length
);
});
let animationRunning = false;
let animationComplete = false;
let elapsed = 0;
let previousTime = performance.now();
playButton.addEventListener("click", () => {
if (animationComplete) {
elapsed = 0;
animationComplete = false;
}
animationRunning = !animationRunning;
playButton.setAttribute("aria-pressed", String(animationRunning));
playButton.textContent = animationRunning
? "Ⅱ Pause comparison"
: "▶ Resume comparison";
});
function updateRouteAnimation(deltaTime) {
if (animationRunning) {
elapsed += deltaTime;
const maximumDuration = Math.max(...durations);
if (elapsed >= maximumDuration) {
elapsed = maximumDuration;
animationRunning = false;
animationComplete = true;
playButton.textContent = "↻ Replay routes";
playButton.setAttribute("aria-pressed", "false");
// Both routes finish at exactly the same camera and square.
setView(arrivalView);
}
}
routeScenes.forEach((routeScene, index) => {
const progress = THREE.MathUtils.clamp(
elapsed / durations[index],
0,
1
);
const point = routeScene.route.curve.getPointAt(progress);
const tangent = routeScene.route.curve.getTangentAt(progress);
routeScene.marker.position.copy(point);
routeScene.marker.rotation.y = Math.atan2(
tangent.x,
tangent.z
);
const pulse = 1 + Math.sin(performance.now() * 0.007) * 0.055;
routeScene.marker.scale.setScalar(pulse);
const percent = Math.round(progress * 100);
progressLabels[index].textContent = animationComplete
? "Arrived · shared square"
: `${percent}% along route`;
});
}
function resizeRenderer() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
}
new ResizeObserver(resizeRenderer).observe(stage);
resizeRenderer();
function updateCamera(deltaTime) {
const smoothing = 1 - Math.exp(-deltaTime * 7);
currentView.target.lerp(desiredView.target, smoothing);
currentView.azimuth = THREE.MathUtils.lerp(
currentView.azimuth,
desiredView.azimuth,
smoothing
);
currentView.polar = THREE.MathUtils.lerp(
currentView.polar,
desiredView.polar,
smoothing
);
currentView.zoom = THREE.MathUtils.lerp(
currentView.zoom,
desiredView.zoom,
smoothing
);
const radius = 90;
const sinPolar = Math.sin(currentView.polar);
camera.position.set(
currentView.target.x +
radius * sinPolar * Math.sin(currentView.azimuth),
currentView.target.y + radius * Math.cos(currentView.polar),
currentView.target.z +
radius * sinPolar * Math.cos(currentView.azimuth)
);
camera.lookAt(currentView.target);
camera.updateMatrixWorld();
}
function render() {
const stageRect = stage.getBoundingClientRect();
for (const routeScene of routeScenes) {
const panel = panels[routeScenes.indexOf(routeScene)];
const panelRect = panel.getBoundingClientRect();
const x = panelRect.left - stageRect.left;
const y = stageRect.bottom - panelRect.bottom;
const width = panelRect.width;
const height = panelRect.height;
renderer.setViewport(x, y, width, height);
renderer.setScissor(x, y, width, height);
renderer.setScissorTest(true);
renderer.setClearColor(routeScene.scene.background, 1);
renderer.clear(true, true, true);
const aspect = width / Math.max(height, 1);
const frustumHeight = 70 / currentView.zoom;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.render(routeScene.scene, camera);
}
}
function animate(now) {
const deltaTime = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
updateCamera(deltaTime);
updateRouteAnimation(deltaTime);
render();
requestAnimationFrame(animate);
}
updateRouteAnimation(0);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```