Prompt specification
Build or customize the Three.js 3D scene "Find a hill-to-river route through historic gateways" 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: Find a hill-to-river route through historic gateways
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/find-a-hill-to-river-route-through-historic-gateways-x2860
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Malá Strana's lanes and bridge approach in Prague. Let users choose a route from an upper lane to a river viewpoint. Display descent and distance separately, highlighting how gateway positions constrain the path. Voxel style.
Working Three.js Starter (find-a-hill-to-river-route-through-historic-gateways-x2860):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Malá Strana — Gateway Walk</title>
<style>
:root {
--ink: #243331;
--muted: #6d7873;
--paper: rgba(249, 247, 240, 0.94);
--line: rgba(36, 51, 49, 0.14);
--accent: #e65e3f;
--accent-soft: #f9dfd6;
--teal: #39877f;
--violet: #7868a8;
--shadow: 0 18px 50px rgba(37, 52, 48, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe8e5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport,
#sceneLabels {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#sceneLabels {
pointer-events: none;
overflow: hidden;
z-index: 2;
}
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#routePanel {
top: 18px;
left: 18px;
width: 370px;
max-height: calc(100vh - 36px);
padding: 20px;
overflow: auto;
border-radius: 8px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 29px;
line-height: 1.03;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.route-list {
display: grid;
gap: 9px;
}
.route-card {
position: relative;
width: 100%;
padding: 13px 13px 12px 15px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(255, 255, 255, 0.48);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
transform 150ms ease,
border-color 150ms ease,
background 150ms ease,
box-shadow 150ms ease;
}
.route-card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 4px;
border-radius: 5px 0 0 5px;
background: var(--route-color);
content: "";
opacity: 0.38;
}
.route-card:hover {
transform: translateX(2px);
border-color: rgba(36, 51, 49, 0.28);
}
.route-card.active {
border-color: var(--route-color);
background: #fffdf8;
box-shadow: 0 7px 22px rgba(39, 53, 49, 0.09);
}
.route-card.active::before {
opacity: 1;
}
.route-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.route-name {
font-size: 15px;
font-weight: 760;
letter-spacing: -0.015em;
}
.route-kind {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
.route-description {
margin: 6px 0 10px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.route-metrics {
display: flex;
gap: 7px;
}
.route-metric {
padding: 5px 7px;
border-radius: 3px;
background: #eeeee8;
color: #52605b;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.02em;
}
.route-metric.down {
background: var(--accent-soft);
color: #9b422f;
}
.constraint-note {
margin-top: 16px;
padding: 13px;
border: 1px solid #e4c9bb;
border-radius: 5px;
background: #fff4ec;
}
.constraint-note strong {
display: block;
margin-bottom: 5px;
color: #8b452f;
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.constraint-note p {
margin: 0;
color: #705c53;
font-size: 11px;
line-height: 1.55;
}
.schematic {
margin-top: 11px;
color: #89918d;
font-size: 9px;
line-height: 1.4;
}
#mapPanel {
top: 18px;
right: 18px;
width: 280px;
padding: 16px;
border-radius: 8px;
}
.panel-label {
margin: 0 0 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.gate-sequence {
display: grid;
gap: 7px;
margin-bottom: 14px;
}
.gate-row {
display: grid;
grid-template-columns: 23px 1fr;
align-items: center;
gap: 8px;
color: #58635f;
font-size: 11px;
}
.gate-number {
display: grid;
width: 21px;
height: 21px;
place-items: center;
border: 1px solid #d59a7f;
border-radius: 3px;
background: #fff0e7;
color: #9d5037;
font-size: 9px;
font-weight: 800;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 12px 0;
padding: 10px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
color: #56615d;
font-size: 11px;
}
.toggle-row input {
width: 16px;
height: 16px;
accent-color: var(--accent);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.small-button {
min-height: 34px;
border: 1px solid var(--line);
border-radius: 4px;
background: #fffdf8;
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.small-button:hover {
border-color: var(--accent);
color: var(--accent);
}
.controls-hint {
margin-top: 11px;
color: #87908c;
font-size: 9px;
line-height: 1.55;
}
#metrics {
right: 18px;
bottom: 18px;
display: grid;
grid-template-columns: 1fr 1fr;
width: 340px;
overflow: hidden;
border-radius: 8px;
}
.metric {
min-height: 87px;
padding: 14px 16px;
border-right: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.metric:nth-child(2n) {
border-right: 0;
}
.metric:nth-child(n + 3) {
border-bottom: 0;
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
font-size: 25px;
font-weight: 800;
letter-spacing: -0.05em;
}
.metric-value small {
margin-left: 2px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0;
}
.world-label {
position: absolute;
z-index: 3;
padding: 4px 7px;
border: 1px solid rgba(48, 64, 60, 0.14);
border-radius: 3px;
background: rgba(252, 250, 244, 0.88);
box-shadow: 0 4px 12px rgba(32, 49, 44, 0.09);
color: #3f4d48;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.015em;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 100ms linear;
}
.world-label.gate-label {
display: flex;
align-items: center;
gap: 5px;
border-color: rgba(198, 103, 70, 0.28);
background: rgba(255, 246, 238, 0.94);
color: #844936;
}
.world-label.gate-label b {
display: grid;
width: 16px;
height: 16px;
place-items: center;
border-radius: 2px;
background: #df7652;
color: white;
font-size: 8px;
}
.world-label.water-label {
border-color: rgba(255, 255, 255, 0.3);
background: rgba(52, 128, 141, 0.72);
color: white;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.world-label.minor {
opacity: 0.78;
font-size: 8px;
}
#toast {
position: fixed;
z-index: 10;
top: 20px;
left: 50%;
max-width: 430px;
padding: 11px 15px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 5px;
background: rgba(39, 52, 48, 0.93);
box-shadow: var(--shadow);
color: white;
font-size: 11px;
line-height: 1.45;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -12px);
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
#sceneHint {
position: fixed;
z-index: 4;
bottom: 20px;
left: 20px;
color: rgba(41, 57, 53, 0.66);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
@media (max-width: 980px) {
#routePanel {
width: 340px;
}
#mapPanel {
width: 245px;
}
#metrics {
width: 300px;
}
}
@media (max-width: 720px) {
#routePanel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 14px;
}
h1 {
font-size: 22px;
}
.subtitle {
margin: 7px 0 11px;
font-size: 11px;
}
.route-list {
display: flex;
overflow-x: auto;
padding-bottom: 3px;
}
.route-card {
min-width: 250px;
}
.constraint-note,
.schematic {
display: none;
}
#mapPanel {
top: 10px;
right: 10px;
width: 145px;
padding: 10px;
}
#mapPanel .gate-sequence,
#mapPanel .controls-hint {
display: none;
}
#mapPanel .panel-label {
margin-bottom: 7px;
font-size: 8px;
}
.toggle-row {
margin: 7px 0;
padding: 7px 0;
font-size: 9px;
}
.small-button {
min-height: 30px;
font-size: 9px;
}
#metrics {
top: 10px;
right: 165px;
bottom: auto;
left: 10px;
width: auto;
}
.metric {
min-height: 61px;
padding: 9px 10px;
}
.metric-label {
margin-bottom: 2px;
font-size: 7px;
}
.metric-value {
font-size: 18px;
}
#sceneHint {
display: none;
}
.world-label.minor {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="sceneLabels"></div>
<section id="routePanel" class="panel">
<p class="eyebrow">Prague · Voxel Route Study</p>
<h1>Gateway Walk</h1>
<p class="subtitle">
Malá Strana’s upper lanes to the Charles Bridge approach.
Choose a route through the same four fixed gateways.
</p>
<div id="routeList" class="route-list"></div>
<div class="constraint-note">
<strong>Why the path bends</strong>
<p id="routeExplanation"></p>
</div>
<div class="schematic">
Schematic voxel map. Distances and cumulative descent are route estimates,
not surveyed navigation data.
</div>
</section>
<aside id="mapPanel" class="panel">
<p class="panel-label">Fixed gateway sequence</p>
<div class="gate-sequence">
<div class="gate-row"><span class="gate-number">1</span>Castle Gate</div>
<div class="gate-row"><span class="gate-number">2</span>Lennon Passage</div>
<div class="gate-row"><span class="gate-number">3</span>St. Nicholas Gate</div>
<div class="gate-row"><span class="gate-number">4</span>Bridgehead Gate</div>
</div>
<label class="toggle-row">
Gate constraint halos
<input id="constraintToggle" type="checkbox" checked />
</label>
<div class="button-row">
<button id="focusRoute" class="small-button">Focus route</button>
<button id="resetView" class="small-button">Reset view</button>
</div>
<div class="controls-hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom.<br />
Touch: drag to orbit, pinch to zoom. Click a gateway for its constraint.
</div>
</aside>
<section id="metrics" class="panel">
<div class="metric">
<span class="metric-label">Cumulative descent</span>
<span class="metric-value"><span id="descentValue">16</span><small>m</small></span>
</div>
<div class="metric">
<span class="metric-label">Route distance</span>
<span class="metric-value"><span id="distanceValue">190</span><small>m</small></span>
</div>
<div class="metric">
<span class="metric-label">Fixed gateways</span>
<span class="metric-value">4</span>
</div>
<div class="metric">
<span class="metric-label">Stair flights</span>
<span class="metric-value"><span id="flightsValue">4</span></span>
</div>
</section>
<div id="toast"></div>
<div id="sceneHint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Route data: x/z are schematic map coordinates, elevation is in metres.
// -------------------------------------------------------------------------
const P = {
start: { x: -20, z: -33, elevation: 18 },
castle: { x: -16, z: -27, elevation: 16 },
lennon: { x: -9, z: -14, elevation: 12 },
nicholas: { x: 0, z: -2, elevation: 8 },
bridgehead: { x: 7, z: 12, elevation: 4 },
viewpoint: { x: 9, z: 19, elevation: 2 },
kampaA: { x: -11, z: -7, elevation: 9 },
kampaB: { x: -2, z: -10, elevation: 7 },
kampaC: { x: 4, z: -5, elevation: 5 },
courtA: { x: -10, z: -6, elevation: 10 },
courtB: { x: -5, z: -4, elevation: 11 }
};
const routes = [
{
id: "castle-cut",
name: "Castle Cut",
kind: "Steepest · 4 flights",
description: "Short stepped link from the castle wall to the bridgehead.",
color: "#e65e3f",
flights: 4,
points: [
P.start, P.castle, P.lennon, P.nicholas, P.bridgehead, P.viewpoint
],
explanation:
"The Castle Gate fixes the first descent. The stepped lane is shortest, but Lennon Passage and St. Nicholas Gate prevent a direct line to the river."
},
{
id: "kampa-loop",
name: "Kampa Garden Loop",
kind: "Longest · 19 m drop",
description: "Descends through the garden lanes, then climbs to the gate.",
color: "#39877f",
flights: 5,
points: [
P.start, P.castle, P.lennon, P.kampaA, P.kampaB,
P.kampaC, P.nicholas, P.bridgehead, P.viewpoint
],
explanation:
"The route slips through Lennon Passage into the lower gardens, then climbs 3 m back to St. Nicholas Gate. More distance, but the fixed openings shape a broad S-curve."
},
{
id: "nicholas-terrace",
name: "Nicholas Terrace",
kind: "Balanced · gentle kink",
description: "A courtyard switchback with only a minor rise.",
color: "#7868a8",
flights: 3,
points: [
P.start, P.castle, P.lennon, P.courtA,
P.courtB, P.nicholas, P.bridgehead, P.viewpoint
],
explanation:
"This switchback threads through the Nicholas courtyard. The gateway order remains unchanged, so the route trades a little distance for a gentler approach."
}
];
const gates = [
{
number: 1,
name: "Castle Gate",
point: P.castle,
constraint: "Only one usable opening pierces the castle wall; the route cannot bypass it."
},
{
number: 2,
name: "Lennon Passage",
point: P.lennon,
constraint: "The passage pinches between the garden wall and the descending terraces."
},
{
number: 3,
name: "St. Nicholas Gate",
point: P.nicholas,
constraint: "Courtyard walls force the path to turn toward the river before the final descent."
},
{
number: 4,
name: "Bridgehead Gate",
point: P.bridgehead,
constraint: "This last arch fixes the alignment onto the Charles Bridge approach."
}
];
const MAP_SCALE = 3.25;
const Y_SCALE = 0.62;
function routeMetrics(route) {
let distance = 0;
let descent = 0;
for (let i = 1; i < route.points.length; i++) {
const a = route.points[i - 1];
const b = route.points[i];
distance += Math.hypot((b.x - a.x) * MAP_SCALE, (b.z - a.z) * MAP_SCALE);
descent += Math.max(0, a.elevation - b.elevation);
}
return {
distance: Math.round(distance),
descent: Math.round(descent)
};
}
routes.forEach(route => {
Object.assign(route, routeMetrics(route));
});
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe8e5);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute("aria-label", "Interactive voxel map of Malá Strana");
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-40, 40, 40, -40, 0.1, 300);
const defaultTarget = new THREE.Vector3(0, 4, -3);
const target = defaultTarget.clone();
let yaw = 0.72;
let pitch = 0.72;
let cameraTween = null;
const hemisphere = new THREE.HemisphereLight(0xf6fbff, 0xa5a08a, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d7, 3.1);
sun.position.set(-32, 58, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 58;
sun.shadow.camera.bottom = -58;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 140;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e6ee, 0.85);
fill.position.set(35, 22, -35);
scene.add(fill);
// Shared materials
const materials = {
plinth: new THREE.MeshStandardMaterial({ color: 0xb9b4a4, roughness: 1 }),
bank: new THREE.MeshStandardMaterial({ color: 0xd8d1b9, roughness: 1 }),
upper: new THREE.MeshStandardMaterial({ color: 0xd6ccb4, roughness: 1 }),
middle: new THREE.MeshStandardMaterial({ color: 0xe0d6bd, roughness: 1 }),
lower: new THREE.MeshStandardMaterial({ color: 0xe8deca, roughness: 1 }),
water: new THREE.MeshStandardMaterial({
color: 0x4f9ca5,
roughness: 0.48,
metalness: 0.04,
transparent: true,
opacity: 0.9
}),
road: new THREE.MeshStandardMaterial({
color: 0xf4ead4,
roughness: 1,
side: THREE.DoubleSide
}),
stair: new THREE.MeshStandardMaterial({ color: 0xf7f0df, roughness: 1 }),
stone: new THREE.MeshStandardMaterial({ color: 0xc8bda3, roughness: 1 }),
stoneLight: new THREE.MeshStandardMaterial({ color: 0xe0d4b8, roughness: 1 }),
gateAccent: new THREE.MeshStandardMaterial({ color: 0xda704d, roughness: 0.85 }),
window: new THREE.MeshStandardMaterial({
color: 0xffdf8c,
emissive: 0xe5a93f,
emissiveIntensity: 0.28,
roughness: 0.8
}),
leaf: new THREE.MeshStandardMaterial({ color: 0x668d62, roughness: 1 }),
leafLight: new THREE.MeshStandardMaterial({ color: 0x88a673, roughness: 1 }),
trunk: new THREE.MeshStandardMaterial({ color: 0x8e6d4b, roughness: 1 }),
dark: new THREE.MeshStandardMaterial({ color: 0x46554d, roughness: 1 })
};
function addBox(parent, width, height, depth, material, x, y, z, shadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function point3(point) {
return new THREE.Vector3(point.x, point.elevation * Y_SCALE, point.z);
}
// -------------------------------------------------------------------------
// Voxel terrain, river and retaining edges
// -------------------------------------------------------------------------
addBox(scene, 80, 3, 76, materials.plinth, 8, -3.1, -4);
addBox(scene, 39, 2, 72, materials.bank, -10.5, -0.7, -4);
addBox(scene, 13, 2, 72, materials.bank, 41.5, -0.7, -4);
addBox(scene, 26, 0.8, 72, materials.water, 22.5, -0.55, -4, false);
addBox(scene, 30, 9.3, 17, materials.upper, -15, 4.85, -26.5);
addBox(scene, 39, 4.2, 14, materials.middle, -10.5, 2.1, -5);
addBox(scene, 29, 1.8, 22, materials.lower, -4, 0.05, 17);
// Quay blocks along the left bank.
for (let z = -34; z <= 27; z += 3) {
addBox(scene, 1.2, 1.7, 2.5, materials.stone, 8.6, 0.65, z);
}
// Stone retaining walls, broken where the lanes pass through.
for (let x = -29; x <= -14; x += 2) {
addBox(scene, 1.8, 1.4, 0.65, materials.stone, x, 9.2, -17.8);
}
for (let x = -6; x <= 8; x += 2) {
addBox(scene, 1.8, 1.4, 0.65, materials.stone, x, 4.7, 2.2);
}
// Water glints.
const waterGlints = [];
const glintMaterial = new THREE.MeshStandardMaterial({
color: 0xa8d8d8,
roughness: 0.7,
transparent: true,
opacity: 0.55
});
let seed = 73;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 38; i++) {
const x = 11.5 + random() * 21;
const z = -35 + random() * 68;
const width = 0.8 + random() * 2.8;
const mesh = addBox(
scene, width, 0.035, 0.16, glintMaterial,
x, -0.09, z, false
);
waterGlints.push({ mesh, x, phase: random() * Math.PI * 2 });
}
// -------------------------------------------------------------------------
// Ribbon paths and stairs
// -------------------------------------------------------------------------
function makeRibbon(a, b, width, material) {
const A = point3(a);
const B = point3(b);
const dx = B.x - A.x;
const dz = B.z - A.z;
const length = Math.hypot(dx, dz) || 1;
const px = (-dz / length) * width * 0.5;
const pz = (dx / length) * width * 0.5;
const yA = A.y + 0.035;
const yB = B.y + 0.035;
const vertices = new Float32Array([
A.x + px, yA, A.z + pz,
A.x - px, yA, A.z - pz,
B.x - px, yB, B.z - pz,
B.x + px, yB, B.z + pz
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const roadSegments = new Set();
routes.forEach(route => {
for (let i = 1; i < route.points.length; i++) {
const a = route.points[i - 1];
const b = route.points[i];
const key = [
a.x, a.z, b.x, b.z
].sort((x, y) => x - y).join("|");
if (!roadSegments.has(key)) {
roadSegments.add(key);
makeRibbon(a, b, 1.8, materials.road);
}
}
});
function addStairFlight(a, b, count) {
const A = point3(a);
const B = point3(b);
const dx = B.x - A.x;
const dz = B.z - A.z;
const length = Math.hypot(dx, dz);
const angle = Math.atan2(dx, dz);
const depth = length / count * 1.05;
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const step = addBox(
scene,
1.72,
0.18,
depth,
materials.stair,
THREE.MathUtils.lerp(A.x, B.x, t),
THREE.MathUtils.lerp(A.y, B.y, t) + 0.07,
THREE.MathUtils.lerp(A.z, B.z, t)
);
step.rotation.y = angle;
}
}
addStairFlight(P.castle, P.lennon, 25);
addStairFlight(P.lennon, P.nicholas, 24);
addStairFlight(P.nicholas, P.bridgehead, 22);
// -------------------------------------------------------------------------
// Buildings, church, castle and Lennon Wall
// -------------------------------------------------------------------------
const wallColors = [
0xdca98d, 0xe5c092, 0xc9d0ad, 0xc6b5c5,
0xe0d7bb, 0xc7a58e, 0xb8c7bc, 0xd6b48e
];
const roofColors = [
0x765a50, 0x6d7774, 0x8b5d4d, 0x5d716a
];
function addBuilding(x, z, width, depth, height, baseY, wallColor, roofColor) {
const wall = new THREE.MeshStandardMaterial({ color: wallColor, roughness: 1 });
const roof = new THREE.MeshStandardMaterial({ color: roofColor, roughness: 1 });
addBox(scene, width, height, depth, wall, x, baseY + height / 2, z);
// Stepped voxel roof.
addBox(
scene, width + 0.35, 0.55, depth + 0.35, roof,
x, baseY + height + 0.25, z
);
addBox(
scene, width * 0.72, 0.45, depth * 0.72, roof,
x, baseY + height + 0.72, z
);
const floors = Math.max(1, Math.floor(height / 1.8));
const columns = Math.max(1, Math.floor(width / 1.8));
for (let floor = 0; floor < floors; floor++) {
const wy = baseY + 1.05 + floor * 1.75;
for (let col = 0; col < columns; col++) {
const wx = x - width * 0.34 + col * (width * 0.68 / Math.max(1, columns - 1));
addBox(scene, 0.42, 0.58, 0.08, materials.window, wx, wy, z + depth / 2 + 0.045, false);
}
}
}
const upperBuildings = [
[-26, -33, 6, 6, 7],
[-26, -23, 5, 6, 6],
[-12, -33, 5, 5, 5],
[-8, -25, 6, 5, 5],
[-25, -14, 6, 6, 6]
];
const middleBuildings = [
[-24, -8, 6, 7, 6],
[-17, -4, 6, 6, 6],
[-9, 2, 5, 5, 5]
];
const lowerBuildings = [
[-7, 16, 7, 6, 6],
[-7, 25, 6, 6, 5],
[1, 22, 6, 6, 5]
];
const rightBuildings = [
[39, -29, 6, 7, 6],
[43, -16, 7, 7, 7],
[39, -3, 6, 8, 6],
[42, 8, 7, 7, 7],
[39, 25, 6, 6, 6]
];
[...upperBuildings, ...middleBuildings, ...lowerBuildings, ...rightBuildings]
.forEach((building, index) => {
const [x, z, width, depth, height] = building;
const baseY = z < -14 ? 9.5 : z < 5 ? 4.2 : z < 30 ? 0.95 : 0.3;
addBuilding(
x, z, width, depth, height, baseY,
wallColors[index % wallColors.length],
roofColors[index % roofColors.length]
);
});
// Prague Castle / St. Vitus schematic massing.
addBuilding(-25, -29, 7, 8, 8, 9.5, 0xb8b4a8, 0x6e7470);
addBuilding(-20, -35, 6, 5, 6, 9.5, 0xd0c9b5, 0x765b51);
for (const x of [-28, -22]) {
addBox(scene, 2.3, 8, 2.3, materials.stoneLight, x, 13.5, -34);
addBox(scene, 2.7, 1, 2.7, materials.stoneLight, x, 18, -34);
addBox(scene, 1.5, 2.1, 1.5, materials.dark, x, 19.5, -34);
}
// St. Nicholas Church: block body, tower and stepped green dome.
addBuilding(-3, 2, 5.5, 7, 5.8, 4.2, 0xe4d6bd, 0x6b7f69);
addBox(scene, 3.1, 8, 3.1, materials.stoneLight, -3, 8.2, 0.4);
addBox(scene, 3.5, 0.6, 3.5, materials.stoneLight, -3, 12.5, 0.4);
addBox(scene, 2.8, 1.1, 2.8, materials.leaf, -3, 13.35, 0.4);
addBox(scene, 2, 1, 2, materials.leafLight, -3, 14.35, 0.4);
addBox(scene, 1.2, 1.4, 1.2, materials.leaf, -3, 15.55, 0.4);
// Lennon Wall, split around its passage.
for (let x = -15; x <= -11; x += 1.25) {
addBox(scene, 1.1, 1.8, 0.55, materials.stoneLight, x, 7.6, -13.8);
}
for (let x = -7; x <= -3; x += 1.25) {
addBox(scene, 1.1, 1.8, 0.55, materials.stoneLight, x, 7.6, -13.8);
}
function addTree(x, z, baseY, size = 1) {
addBox(scene, 0.45 * size, 2 * size, 0.45 * size, materials.trunk,
x, baseY + size, z);
addBox(scene, 2.2 * size, 1.6 * size, 2.2 * size, materials.leaf,
x, baseY + 2.6 * size, z);
addBox(scene, 1.55 * size, 1.2 * size, 1.55 * size, materials.leafLight,
x, baseY + 3.6 * size, z);
}
[
[-7, -9, 4.3], [-5, -12, 4.3], [2, -9, 1], [5, -12, 1],
[-12, 5, 1], [-15, 2, 4.3], [-28, -17, 9.5], [-19, -18, 9.5],
[-20, 11, 1], [-14, 15, 1], [39, -12, 0.3], [40, 2, 0.3]
].forEach(([x, z, y], i) => addTree(x, z, y, 0.8 + (i % 3) * 0.12));
// -------------------------------------------------------------------------
// Charles Bridge and river viewpoint
// -------------------------------------------------------------------------
addBox(scene, 25.5, 0.65, 3.2, materials.stoneLight, 22.75, 0.85, 18);
for (let x = 12; x < 35; x += 3.2) {
addBox(scene, 0.65, 1.1, 3.2, materials.stone, x, -0.15, 18);
}
for (const z of [16.32, 19.68]) {
for (let x = 10.5; x < 35.5; x += 1.25) {
addBox(scene, 1.05, 0.55, 0.42, materials.stoneLight, x, 1.45, z);
}
}
// New bridge tower with an opening along the bridge axis.
addBox(scene, 2.8, 5.3, 1.05, materials.stoneLight, 11.3, 3.25, 16.7);
addBox(scene, 2.8, 5.3, 1.05, materials.stoneLight, 11.3, 3.25, 19.3);
addBox(scene, 2.8, 1.3, 3.7, materials.stoneLight, 11.3, 6.15, 18);
addBox(scene, 3.4, 0.6, 4.2, materials.gateAccent, 11.3, 7.05, 18);
// Old Town tower.
addBox(scene, 3.8, 7.5, 4.2, materials.stoneLight, 35.1, 4.35, 18);
addBox(scene, 4.3, 0.7, 4.8, materials.gateAccent, 35.1, 8.45, 18);
addBox(scene, 2.5, 1.6, 2.5, materials.dark, 35.1, 9.55, 18);
// Small voxel statues on the parapets.
for (let x = 13.3; x < 34.5; x += 2.65) {
for (const z of [16.32, 19.68]) {
addBox(scene, 0.36, 0.5, 0.36, materials.stone, x, 1.98, z);
addBox(scene, 0.45, 0.75, 0.38, materials.stoneLight, x, 2.56, z);
addBox(scene, 0.32, 0.32, 0.32, materials.stoneLight, x, 3.08, z);
}
}
// Viewing platform on the Malá Strana bridgehead.
addBox(scene, 3.6, 0.55, 4.2, materials.stoneLight, 8.1, 0.72, 19);
addBox(scene, 0.35, 1.1, 4.2, materials.stone, 6.35, 1.5, 19);
addBox(scene, 3.5, 0.35, 0.35, materials.stone, 8, 2.05, 21);
// -------------------------------------------------------------------------
// Gateways: voxel arches and fixed-position halos
// -------------------------------------------------------------------------
const gateHitMeshes = [];
const constraintGroup = new THREE.Group();
scene.add(constraintGroup);
function createGate(gate, direction) {
const group = new THREE.Group();
const position = point3(gate.point);
group.position.copy(position);
group.rotation.y = Math.atan2(direction.x, direction.z);
scene.add(group);
// Stepped block arch.
addBox(group, 0.65, 2.0, 0.65, materials.stoneLight, -1.15, 1, 0);
addBox(group, 0.65, 2.0, 0.65, materials.stoneLight, 1.15, 1, 0);
addBox(group, 0.7, 0.65, 0.7, materials.stoneLight, -0.9, 2.0, 0);
addBox(group, 0.7, 0.65, 0.7, materials.stoneLight, 0.9, 2.0, 0);
addBox(group, 0.7, 0.65, 0.7, materials.stoneLight, -0.48, 2.48, 0);
addBox(group, 0.7, 0.65, 0.7, materials.stoneLight, 0.48, 2.48, 0);
addBox(group, 1.65, 0.48, 0.78, materials.stoneLight, 0, 2.9, 0);
// Small orange marker.
addBox(group, 0.16, 2.8, 0.16, materials.gateAccent, 1.65, 1.4, 0);
addBox(group, 0.7, 0.55, 0.16, materials.gateAccent, 1.4, 2.65, 0);
// Constraint footprint: a square halo fixed to the opening.
const haloMaterial = new THREE.MeshBasicMaterial({
color: 0xe77954,
transparent: true,
opacity: 0.42,
depthWrite: false
});
const halo = new THREE.Group();
halo.position.y = 0.035;
addBox(halo, 4.2, 0.025, 0.11, haloMaterial, 0, 0, 2.05, false);
addBox(halo, 4.2, 0.025, 0.11, haloMaterial, 0, 0, -2.05, false);
addBox(halo, 0.11, 0.025, 4.2, haloMaterial, 2.05, 0, 0, false);
addBox(halo, 0.11, 0.025, 4.2, haloMaterial, -2.05, 0, 0, false);
group.add(halo);
constraintGroup.add(group);
// Invisible click target.
const hit = new THREE.Mesh(
new THREE.BoxGeometry(3.5, 3.8, 3.5),
new THREE.MeshBasicMaterial({ transparent: true, opacity: 0, depthWrite: false })
);
hit.position.y = 1.4;
hit.userData.gate = gate;
group.add(hit);
gateHitMeshes.push(hit);
return group;
}
const canonicalDirections = [
new THREE.Vector3(7, 0, 13),
new THREE.Vector3(9, 0, 12),
new THREE.Vector3(7, 0, 14),
new THREE.Vector3(2, 0, 7)
];
gates.forEach((gate, index) => createGate(gate, canonicalDirections[index]));
// -------------------------------------------------------------------------
// Active route ribbons and animated voxel markers
// -------------------------------------------------------------------------
const routeVisuals = [];
function sampleRoute(route) {
const samples = [];
for (let i = 1; i < route.points.length; i++) {
const a = point3(route.points[i - 1]);
const b = point3(route.points[i]);
const length = a.distanceTo(b);
const steps = Math.max(1, Math.ceil(length / 0.62));
for (let step = 0; step < steps; step++) {
const t = step / steps;
samples.push(
new THREE.Vector3(
THREE.MathUtils.lerp(a.x, b.x, t),
THREE.MathUtils.lerp(a.y, b.y, t) + 0.25,
THREE.MathUtils.lerp(a.z, b.z, t)
)
);
}
}
const end = point3(route.points[route.points.length - 1]);
samples.push(end.add(new THREE.Vector3(0, 0.25, 0)));
return samples;
}
routes.forEach(route => {
const ribbonMaterial = new THREE.MeshStandardMaterial({
color: route.color,
emissive: route.color,
emissiveIntensity: 0.12,
transparent: true,
opacity: 0.24,
roughness: 1,
side: THREE.DoubleSide
});
for (let i = 1; i < route.points.length; i++) {
makeRibbon(route.points[i - 1], route.points[i], 2.55, ribbonMaterial);
}
const samples = sampleRoute(route);
const markerMaterial = new THREE.MeshStandardMaterial({
color: route.color,
emissive: route.color,
emissiveIntensity: 0.42,
roughness: 0.65
});
const markers = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.34, 0.34, 0.34),
markerMaterial,
samples.length
);
markers.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
markers.frustumCulled = false;
markers.userData.samples = samples;
markers.visible = false;
scene.add(markers);
routeVisuals.push(markers);
});
const markerDummy = new THREE.Object3D();
function updateRouteMarkers(time) {
routeVisuals.forEach(markers => {
if (!markers.visible) return;
markers.userData.samples.forEach((position, index) => {
markerDummy.position.copy(position);
markerDummy.position.y += Math.sin(time * 3.1 - index * 0.18) * 0.075;
const pulse = 1 + Math.sin(time * 2.4 - index * 0.24) * 0.1;
markerDummy.scale.setScalar(pulse);
markerDummy.updateMatrix();
markers.setMatrixAt(index, markerDummy.matrix);
});
markers.instanceMatrix.needsUpdate = true;
});
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelLayer = document.getElementById("sceneLabels");
const labels = [];
function addLabel(html, position, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
labelLayer.appendChild(element);
labels.push({ element, position: position.clone() });
return element;
}
addLabel("Upper lane", new THREE.Vector3(-20, 12, -33), "minor");
addLabel("Prague Castle", new THREE.Vector3(-25, 20, -31), "minor");
addLabel("Mostecká Lane", new THREE.Vector3(-6, 8.4, -8), "minor");
addLabel("Kampa Garden", new THREE.Vector3(-2, 7, -10), "minor");
addLabel("St. Nicholas", new THREE.Vector3(-3, 16.4, 2), "minor");
addLabel("Charles Bridge", new THREE.Vector3(23, 5.2, 18));
addLabel("Vltava River", new THREE.Vector3(24, 0.8, -9), "water-label");
addLabel("River viewpoint", new THREE.Vector3(8, 4.4, 19));
gates.forEach(gate => {
const p = point3(gate.point);
p.y += 4;
addLabel(`<b>${gate.number}</b>${gate.name}`, p, "gate-label");
});
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach(label => {
const projected = label.position.clone().project(camera);
const onScreen =
projected.z > -1 && projected.z < 1 &&
projected.x > -1.15 && projected.x < 1.15 &&
projected.y > -1.15 && projected.y < 1.15;
label.element.style.opacity = onScreen ? "1" : "0";
if (!onScreen) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// -------------------------------------------------------------------------
// Interface and route selection
// -------------------------------------------------------------------------
const routeList = document.getElementById("routeList");
const routeExplanation = document.getElementById("routeExplanation");
const descentValue = document.getElementById("descentValue");
const distanceValue = document.getElementById("distanceValue");
const flightsValue = document.getElementById("flightsValue");
const toast = document.getElementById("toast");
let selectedRouteIndex = 0;
let toastTimer = null;
routes.forEach((route, index) => {
const button = document.createElement("button");
button.className = "route-card";
button.style.setProperty("--route-color", route.color);
button.setAttribute("aria-pressed", index === selectedRouteIndex ? "true" : "false");
button.innerHTML = `
<div class="route-top">
<span class="route-name">${route.name}</span>
<span class="route-kind">${route.kind}</span>
</div>
<div class="route-description">${route.description}</div>
<div class="route-metrics">
<span class="route-metric down">↓ ${route.descent} m descent</span>
<span class="route-metric">↔ ${route.distance} m distance</span>
</div>
`;
button.addEventListener("click", () => selectRoute(index));
routeList.appendChild(button);
});
function selectRoute(index) {
selectedRouteIndex = index;
const route = routes[index];
[...routeList.children].forEach((card, i) => {
card.classList.toggle("active", i === index);
card.setAttribute("aria-pressed", i === index ? "true" : "false");
});
routeVisuals.forEach((visual, i) => {
visual.visible = i === index;
});
document.documentElement.style.setProperty("--accent", route.color);
document.documentElement.style.setProperty("--accent-soft", `${route.color}22`);
descentValue.textContent = route.descent;
distanceValue.textContent = route.distance;
flightsValue.textContent = route.flights;
routeExplanation.textContent = route.explanation;
}
selectRoute(0);
document.getElementById("constraintToggle").addEventListener("change", event => {
constraintGroup.visible = event.target.checked;
});
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 3800);
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom and touch gestures
// -------------------------------------------------------------------------
function updateCamera() {
const radius = 100;
const offset = new THREE.Vector3(
radius * Math.cos(pitch) * Math.sin(yaw),
radius * Math.sin(pitch),
radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.position.copy(target).add(offset);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(34, 38 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const pointers = new Map();
let pointerTravel = 0;
let previousPinchDistance = null;
let previousPinchMiddle = null;
function panScreen(dx, dy) {
const frustumHeight = (camera.top - camera.bottom) / camera.zoom;
const scale = frustumHeight / window.innerHeight;
const right = new THREE.Vector3();
camera.getWorldDirection(right);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(-right.z, 0, right.x);
target.addScaledVector(right, -dx * scale);
target.addScaledVector(forward, -dy * scale);
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
pointerTravel = 0;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
previousPinchMiddle = {
x: (a.x + b.x) / 2,
y: (a.y + b.y) / 2
};
}
});
renderer.domElement.addEventListener("pointermove", event => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
cameraTween = null;
if (pointers.size === 1) {
if (event.shiftKey || pointer.button === 2) {
panScreen(dx, dy);
} else {
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.28, 1.28);
}
} else if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
const middle = {
x: (a.x + b.x) / 2,
y: (a.y + b.y) / 2
};
if (previousPinchDistance) {
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (distance / previousPinchDistance),
0.65,
2.8
);
camera.updateProjectionMatrix();
}
if (previousPinchMiddle) {
panScreen(
middle.x - previousPinchMiddle.x,
middle.y - previousPinchMiddle.y
);
}
previousPinchDistance = distance;
previousPinchMiddle = middle;
}
});
renderer.domElement.addEventListener("pointerup", event => {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = null;
previousPinchMiddle = null;
}
if (pointerTravel < 5) {
const gate = pickGate(event);
if (gate) {
showToast(`Gateway ${gate.number} · ${gate.name} — ${gate.constraint}`);
}
}
});
renderer.domElement.addEventListener("pointercancel", event => {
pointers.delete(event.pointerId);
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraTween = null;
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.8
);
camera.updateProjectionMatrix();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") yaw += 0.08;
if (event.key === "ArrowRight") yaw -= 0.08;
if (event.key === "ArrowUp") pitch = Math.min(1.28, pitch + 0.06);
if (event.key === "ArrowDown") pitch = Math.max(0.28, pitch - 0.06);
if (event.key === "+" || event.key === "=") camera.zoom *= 1.08;
if (event.key === "-") camera.zoom *= 0.92;
camera.updateProjectionMatrix();
});
// Gateway picking.
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function pickGate(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(gateHitMeshes, false);
return hits.length ? hits[0].object.userData.gate : null;
}
// Focus and reset controls.
document.getElementById("focusRoute").addEventListener("click", () => {
const route = routes[selectedRouteIndex];
const center = new THREE.Vector3();
route.points.forEach(point => center.add(point3(point)));
center.multiplyScalar(1 / route.points.length);
cameraTween = {
fromTarget: target.clone(),
toTarget: center,
fromZoom: camera.zoom,
toZoom: 1.45,
elapsed: 0
};
});
document.getElementById("resetView").addEventListener("click", () => {
yaw = 0.72;
pitch = 0.72;
cameraTween = {
fromTarget: target.clone(),
toTarget: defaultTarget.clone(),
fromZoom: camera.zoom,
toZoom: 1,
elapsed: 0
};
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const delta = clock.getDelta();
if (cameraTween) {
cameraTween.elapsed += delta;
const t = Math.min(1, cameraTween.elapsed / 0.65);
const eased = 1 - Math.pow(1 - t, 3);
target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
eased
);
camera.zoom = THREE.MathUtils.lerp(
cameraTween.fromZoom,
cameraTween.toZoom,
eased
);
camera.updateProjectionMatrix();
if (t >= 1) cameraTween = null;
}
waterGlints.forEach(glint => {
glint.mesh.position.x = glint.x + Math.sin(elapsed * 0.35 + glint.phase) * 0.55;
});
updateCamera();
updateRouteMarkers(elapsed);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```