Prompt specification
Build or customize the Three.js 3D scene "Find a route through a layered hillside block" 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 route through a layered hillside block
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/find-a-route-through-a-layered-hillside-block-x2740
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Guanajuato's hillside lanes. Let users select a destination across the schematic district. Show stairs, surface streets, and lower passages as separate graph connections with explicit movement restrictions. Low-poly.
Working Three.js Starter (find-a-route-through-a-layered-hillside-block-x2740):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Guanajuato — Hillside Lanes</title>
<style>
:root {
--ink: #f6f0df;
--muted: #b9c2bc;
--panel: rgba(20, 30, 32, 0.91);
--panel-soft: rgba(31, 43, 44, 0.86);
--line: rgba(255, 255, 255, 0.13);
--surface: #f1c36e;
--stairs: #ef8b60;
--lower: #9b9cf7;
--route: #ffe266;
--green: #8fe0b4;
--danger: #ff9b87;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9d7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 16px 48px rgba(15, 24, 27, 0.25);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.brand {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: 320px;
padding: 17px 18px 16px;
border-radius: 18px;
pointer-events: none;
}
.brand-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.brand-kicker,
.eyebrow {
color: var(--route);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand h1 {
margin: 8px 0 5px;
font-size: 27px;
line-height: 1;
letter-spacing: -0.04em;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.schematic-badge {
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid rgba(255, 226, 102, 0.35);
border-radius: 999px;
color: var(--route);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
position: fixed;
z-index: 10;
left: 18px;
bottom: 18px;
width: 320px;
padding: 13px 15px;
border-radius: 15px;
pointer-events: none;
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 34px 1fr;
gap: 9px;
align-items: center;
margin-top: 8px;
font-size: 11px;
}
.legend-line {
height: 5px;
border-radius: 99px;
box-shadow: 0 0 12px currentColor;
}
.legend-line.surface {
color: var(--surface);
background: var(--surface);
}
.legend-line.stairs {
color: var(--stairs);
background: var(--stairs);
}
.legend-line.lower {
color: var(--lower);
background: var(--lower);
}
.legend-row small {
display: block;
margin-top: 1px;
color: var(--muted);
font-size: 9px;
}
.planner {
position: fixed;
z-index: 12;
top: 18px;
right: 18px;
width: 374px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 20px;
border-radius: 20px;
scrollbar-width: thin;
scrollbar-color: rgba(255,255,255,.2) transparent;
}
.planner h2 {
margin: 7px 0 5px;
font-size: 23px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.planner .intro {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.field {
margin-top: 13px;
}
.field-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
select,
input[type="time"] {
width: 100%;
min-height: 40px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 10px;
outline: none;
background: rgba(255, 255, 255, 0.07);
color: var(--ink);
font-size: 12px;
}
select:focus,
input[type="time"]:focus {
border-color: rgba(255, 226, 102, 0.65);
}
.mode-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
padding: 4px;
border-radius: 12px;
background: rgba(0, 0, 0, 0.18);
}
.mode-tabs button {
min-height: 34px;
padding: 6px 4px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.mode-tabs button.active {
background: var(--route);
color: #20251f;
}
.options {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.check {
display: flex;
align-items: center;
gap: 8px;
min-height: 37px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--muted);
cursor: pointer;
font-size: 10px;
line-height: 1.2;
}
.check input {
width: 14px;
height: 14px;
accent-color: var(--route);
}
.time-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
align-items: end;
margin-top: 12px;
}
.time-note {
align-self: center;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.primary {
width: 100%;
min-height: 43px;
margin-top: 14px;
border: 0;
border-radius: 11px;
background: var(--route);
color: #20251f;
cursor: pointer;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.02em;
transition: transform .16s, filter .16s;
}
.primary:hover {
filter: brightness(1.07);
transform: translateY(-1px);
}
.route-panel {
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.route-meta {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-top: 7px;
}
.route-meta strong {
font-size: 19px;
letter-spacing: -0.03em;
}
.route-meta span {
color: var(--muted);
font-size: 10px;
text-align: right;
}
.route-warning {
margin-top: 8px;
color: var(--route);
font-size: 10px;
line-height: 1.4;
}
.route-steps {
display: grid;
gap: 7px;
max-height: 210px;
margin-top: 12px;
overflow: auto;
scrollbar-width: thin;
}
.route-step {
display: grid;
grid-template-columns: 28px 1fr;
gap: 9px;
padding: 9px;
border: 1px solid rgba(255,255,255,.09);
border-radius: 10px;
background: rgba(255,255,255,.035);
}
.step-badge {
display: grid;
place-items: center;
width: 26px;
height: 26px;
border-radius: 8px;
color: #17201f;
font-size: 10px;
font-weight: 900;
}
.step-badge.surface { background: var(--surface); }
.step-badge.stairs { background: var(--stairs); }
.step-badge.lower { background: var(--lower); }
.route-step b {
display: block;
font-size: 11px;
line-height: 1.25;
}
.route-step small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.empty-route {
padding: 12px;
border: 1px solid rgba(255, 155, 135, .25);
border-radius: 11px;
background: rgba(255, 155, 135, .07);
color: #ffd0c7;
font-size: 11px;
line-height: 1.45;
}
.planner-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 15px;
}
.planner-footer small {
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.text-button {
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,.05);
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.text-button:hover {
border-color: rgba(255,255,255,.28);
background: rgba(255,255,255,.09);
}
.network-drawer {
position: fixed;
z-index: 20;
top: 18px;
right: 18px;
bottom: 18px;
width: 410px;
overflow: hidden;
border-radius: 20px;
transform: translateX(calc(100% + 30px));
transition: transform .28s ease;
}
.network-drawer.open {
transform: translateX(0);
}
.drawer-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
padding: 20px;
border-bottom: 1px solid var(--line);
}
.drawer-head h2 {
margin: 6px 0 5px;
font-size: 22px;
letter-spacing: -0.03em;
}
.drawer-head p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.icon-button {
display: grid;
place-items: center;
width: 32px;
height: 32px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,.05);
cursor: pointer;
font-size: 18px;
}
.network-scroll {
height: calc(100% - 112px);
overflow: auto;
padding: 14px 16px 22px;
scrollbar-width: thin;
}
.rules-box {
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.04);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.rules-box b {
color: var(--ink);
}
.network-group {
margin-top: 17px;
}
.network-group-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.network-group-title::before {
content: "";
width: 18px;
height: 4px;
border-radius: 99px;
background: currentColor;
}
.network-group.surface .network-group-title { color: var(--surface); }
.network-group.stairs .network-group-title { color: var(--stairs); }
.network-group.lower .network-group-title { color: var(--lower); }
.network-row {
width: 100%;
margin-top: 6px;
padding: 10px;
border: 1px solid rgba(255,255,255,.08);
border-radius: 10px;
background: rgba(255,255,255,.035);
color: var(--ink);
cursor: pointer;
text-align: left;
}
.network-row:hover,
.network-row.active {
border-color: rgba(255,255,255,.28);
background: rgba(255,255,255,.08);
}
.network-row b {
display: block;
font-size: 11px;
line-height: 1.35;
}
.network-row small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.inspector {
position: fixed;
z-index: 16;
left: 18px;
bottom: 182px;
width: 320px;
padding: 15px;
border-radius: 15px;
opacity: 0;
pointer-events: none;
transform: translateY(8px);
transition: opacity .2s, transform .2s;
}
.inspector.open {
opacity: 1;
pointer-events: auto;
transform: translateY(0);
}
.inspector-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.inspector h3 {
margin: 5px 0 4px;
font-size: 17px;
}
.inspector p {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.inspector .rule-tag {
display: inline-flex;
padding: 5px 7px;
border-radius: 999px;
color: #17201f;
font-size: 9px;
font-weight: 900;
}
.camera-controls {
position: fixed;
z-index: 10;
right: 410px;
top: 18px;
display: grid;
gap: 6px;
padding: 6px;
border-radius: 13px;
}
.camera-controls button {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border: 0;
border-radius: 9px;
background: rgba(255,255,255,.07);
cursor: pointer;
font-size: 15px;
}
.camera-controls button:hover {
background: rgba(255,255,255,.15);
}
.help {
position: fixed;
z-index: 8;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
padding: 8px 12px;
border-radius: 999px;
color: rgba(255,255,255,.82);
font-size: 10px;
pointer-events: none;
white-space: nowrap;
}
.toast {
position: fixed;
z-index: 40;
left: 50%;
top: 24px;
padding: 10px 14px;
border-radius: 999px;
background: #1c292a;
border: 1px solid rgba(255,255,255,.16);
box-shadow: 0 8px 30px rgba(0,0,0,.25);
font-size: 11px;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -8px);
transition: opacity .2s, transform .2s;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 900px) {
.brand {
width: 280px;
}
.planner {
width: 340px;
}
.camera-controls {
right: 374px;
}
}
@media (max-width: 680px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 13px 14px;
}
.brand h1 {
font-size: 22px;
}
.brand p {
font-size: 10px;
}
.planner {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 16px;
border-radius: 17px;
}
.planner h2,
.planner .intro {
display: none;
}
.legend {
top: 105px;
bottom: auto;
left: 10px;
width: 185px;
padding: 10px;
}
.legend-row {
grid-template-columns: 27px 1fr;
font-size: 9px;
}
.legend-row small {
display: none;
}
.camera-controls {
top: 105px;
right: 10px;
}
.help,
.inspector {
display: none;
}
.network-drawer {
top: 10px;
right: 10px;
bottom: 10px;
width: calc(100% - 20px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly map of Guanajuato hillside lanes"></canvas>
<header class="brand glass">
<div class="brand-top">
<div>
<div class="brand-kicker">Guanajuato / Graph Atlas 01</div>
<h1>Hillside Lanes</h1>
</div>
<div class="schematic-badge">Schematic</div>
</div>
<p>
Follow streets, climb stairways, or cut through lower passages.
Every connection carries its own access rules.
</p>
</header>
<section class="planner glass" aria-label="Route planner">
<div class="eyebrow">Destination planner</div>
<h2>Choose a lane, not a shortcut.</h2>
<p class="intro">
Select a destination across the upper and lower districts.
The route respects the selected movement mode and passage hours.
</p>
<div class="field">
<label class="field-label" for="startSelect">Start point</label>
<select id="startSelect"></select>
</div>
<div class="field">
<label class="field-label" for="destinationSelect">Destination</label>
<select id="destinationSelect"></select>
</div>
<div class="field">
<div class="field-label">Movement mode</div>
<div class="mode-tabs" role="group" aria-label="Movement mode">
<button class="active" data-mode="walking">On foot</button>
<button data-mode="stepfree">Step-free</button>
<button data-mode="bicycle">Bicycle</button>
</div>
</div>
<div class="options">
<label class="check">
<input id="avoidLower" type="checkbox" />
Avoid lower passages
</label>
<label class="check">
<input id="accessibleStairs" type="checkbox" />
Mark stair climbs
</label>
</div>
<div class="time-row">
<div>
<label class="field-label" for="networkTime">Schematic clock</label>
<input id="networkTime" type="time" value="10:30" />
</div>
<div class="time-note">
Lower passages are public<br />
from 06:00 to 23:00.
</div>
</div>
<button id="routeButton" class="primary">Find permitted route</button>
<div class="route-panel" aria-live="polite">
<div class="field-label">Permitted route</div>
<div id="routeMeta" class="route-meta"></div>
<div id="routeWarning" class="route-warning"></div>
<div id="routeSteps" class="route-steps"></div>
</div>
<div class="planner-footer">
<small>
Schematic geography only.<br />
Not suitable for real-world navigation.
</small>
<button id="networkToggle" class="text-button">View all connections</button>
</div>
</section>
<aside id="networkDrawer" class="network-drawer glass" aria-label="Connection rules">
<div class="drawer-head">
<div>
<div class="eyebrow">Connection graph</div>
<h2>Every lane has rules.</h2>
<p>Select a connection to inspect its movement restrictions.</p>
</div>
<button id="networkClose" class="icon-button" aria-label="Close connection list">×</button>
</div>
<div class="network-scroll">
<div class="rules-box">
<b>Surface streets:</b> public, two-way, step-free; walking and bicycles allowed.<br />
<b>Stairs:</b> pedestrians only; not step-free and not suitable for bicycles.<br />
<b>Lower passages:</b> pedestrians only, not step-free, low headroom,
and open only from <b>06:00–23:00</b>.
</div>
<div id="networkList"></div>
</div>
</aside>
<aside id="inspector" class="inspector glass" aria-live="polite">
<div class="inspector-head">
<div>
<div class="eyebrow">Connection inspector</div>
<h3 id="inspectorTitle"></h3>
</div>
<button id="inspectorClose" class="icon-button" aria-label="Close inspector">×</button>
</div>
<span id="inspectorTag" class="rule-tag"></span>
<p id="inspectorRules"></p>
</aside>
<div class="legend glass">
<div class="legend-title">Connection layers</div>
<div class="legend-row">
<span class="legend-line surface"></span>
<span>Surface street<small>Walking · bicycles · step-free</small></span>
</div>
<div class="legend-row">
<span class="legend-line stairs"></span>
<span>Stair connection<small>Walking only · not step-free</small></span>
</div>
<div class="legend-row">
<span class="legend-line lower"></span>
<span>Lower passage<small>06:00–23:00 · walking only</small></span>
</div>
</div>
<div class="camera-controls glass" aria-label="Camera controls">
<button id="zoomIn" aria-label="Zoom in">+</button>
<button id="zoomOut" aria-label="Zoom out">−</button>
<button id="homeView" aria-label="Reset camera">⌂</button>
</div>
<div class="help glass">
Drag to orbit · wheel to zoom · shift/right-drag to pan · click a marker
</div>
<div id="toast" class="toast"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const startSelect = document.getElementById("startSelect");
const destinationSelect = document.getElementById("destinationSelect");
const routeButton = document.getElementById("routeButton");
const avoidLower = document.getElementById("avoidLower");
const accessibleStairs = document.getElementById("accessibleStairs");
const networkTime = document.getElementById("networkTime");
const routeMeta = document.getElementById("routeMeta");
const routeWarning = document.getElementById("routeWarning");
const routeSteps = document.getElementById("routeSteps");
const networkDrawer = document.getElementById("networkDrawer");
const networkList = document.getElementById("networkList");
const inspector = document.getElementById("inspector");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd9d7);
scene.fog = new THREE.Fog(0xcbd9d7, 78, 155);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
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.05;
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
250
);
const hemisphere = new THREE.HemisphereLight(0xf7f1dc, 0x53696b, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2b0, 3.25);
sun.position.set(-38, 64, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -65;
sun.shadow.camera.right = 65;
sun.shadow.camera.top = 65;
sun.shadow.camera.bottom = -65;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xaac9ff, 0.75);
rim.position.set(35, 25, -45);
scene.add(rim);
const world = new THREE.Group();
scene.add(world);
const palette = {
surface: 0xe8bf70,
surfaceEdge: 0xa98b54,
stairs: 0xeb8059,
lower: 0x9393f5,
route: 0xffe266,
stone: 0x9d9380,
ground: 0xaeb78d,
terrace: 0xc3b18b
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0.0,
flatShading: options.flatShading ?? true,
...options
});
}
function box(width, height, depth, material, x, y, z, parent = world) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = world, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
let randomSeed = 91427;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
// The city is intentionally diagrammatic: the node coordinates describe
// relative levels and districts rather than surveyed street geometry.
const nodes = {
u1: { name: "Basílica de Guanajuato", level: "upper", p: [-26, 17.0, -19] },
u2: { name: "Callejón de los Cules", level: "upper", p: [-9, 15.8, -21] },
u3: { name: "Mercado Hidalgo", level: "upper", p: [8, 14.4, -18] },
u4: { name: "Museo de las Momias", level: "upper", p: [25, 12.8, -14] },
u5: { name: "Teatro Juárez", level: "upper", p: [40, 10.8, -7] },
u6: { name: "Universidad de Guanajuato", level: "upper", p: [-30, 14.0, 0] },
u7: { name: "Posada de San Miguel", level: "upper", p: [-12, 12.5, -3] },
u8: { name: "Plaza de la Bandera", level: "upper", p: [5, 10.7, 0] },
u9: { name: "Callejón del Carbón", level: "upper", p: [22, 9.2, 1] },
u10: { name: "Mirador de San Miguel", level: "upper", p: [38, 7.5, 6] },
u11: { name: "Paseo del unexplorado", level: "upper", p: [-40, 12.8, 15] },
m1: { name: "Escalinata de la Basílica", level: "middle", p: [-23, 9.0, -10] },
m2: { name: "Patio del Cielo", level: "middle", p: [-9, 7.0, -8] },
m3: { name: "Callejón Héroes", level: "middle", p: [8, 6.0, -8] },
m4: { name: "Túnel de la Alhóndiga", level: "middle", p: [25, 4.8, -7] },
m5: { name: "Entrada al Túnel", level: "middle", p: [38, 5.0, 1] },
l1: { name: "Abajo de la Basílica", level: "lower", p: [-24, 2.5, 12] },
l2: { name: "Barrio del Túnel", level: "lower", p: [-9, 2.8, 13] },
l3: { name: "Mercado Bajo", level: "lower", p: [6, 3.1, 14] },
l4: { name: "Mirador de la Alhóndiga", level: "lower", p: [22, 3.5, 14] },
l5: { name: "Salida Este del Túnel", level: "lower", p: [37, 4.1, 8] }
};
const edges = [];
let edgeCounter = 0;
function addEdge(from, to, type, rules, options = {}) {
const edge = {
id: `edge-${++edgeCounter}`,
from,
to,
type,
rules,
oneWay: Boolean(options.oneWay),
note: options.note || ""
};
edges.push(edge);
return edge;
}
// Surface street graph.
addEdge("u1", "u2", "surface", "Public lane · two-way · step-free · walking and bicycles allowed");
addEdge("u2", "u3", "surface", "Public lane · two-way · step-free · walking and bicycles allowed");
addEdge("u3", "u4", "surface", "Public cobbled street · two-way · step-free · bicycles allowed");
addEdge("u4", "u5", "surface", "Public street · two-way · step-free · bicycles allowed");
addEdge("u1", "u6", "surface", "Public street · two-way · step-free · walking and bicycles allowed");
addEdge("u6", "u7", "surface", "Public street · two-way · step-free · walking and bicycles allowed");
addEdge("u7", "u8", "surface", "Public lane · two-way · step-free · walking and bicycles allowed");
addEdge("u8", "u9", "surface", "Public lane · two-way · step-free · walking and bicycles allowed");
addEdge("u9", "u10", "surface", "Public hillside street · two-way · step-free · bicycles allowed");
addEdge("u2", "u7", "surface", "Public cross-street · two-way · step-free · walking and bicycles allowed");
addEdge("u3", "u8", "surface", "Public cross-street · two-way · step-free · walking and bicycles allowed");
addEdge("u4", "u9", "surface", "Public cross-street · two-way · step-free · walking and bicycles allowed");
addEdge("u1", "m1", "surface", "Public stepped approach · two-way · step-free along the street connection");
addEdge("u7", "m2", "surface", "Public street · two-way · step-free · walking and bicycles allowed");
addEdge("u3", "m3", "surface", "Public street · two-way · step-free · walking and bicycles allowed");
addEdge("u5", "m4", "surface", "Public street · two-way · step-free · walking and bicycles allowed");
addEdge("u10", "m5", "surface", "Public street · two-way · step-free · walking and bicycles allowed");
addEdge("u11", "u6", "surface", "Public street · two-way · step-free · walking and bicycles allowed");
// Stair graph. These are not equivalent to streets.
addEdge("m1", "l1", "stairs", "Pedestrians only · steep stepped descent · no bicycles · not step-free");
addEdge("m2", "l2", "stairs", "Pedestrians only · stepped descent · no bicycles · not step-free");
addEdge("m3", "l3", "stairs", "Pedestrians only · stepped descent · no bicycles · not step-free");
addEdge("m4", "l4", "stairs", "Pedestrians only · stepped descent · no bicycles · not step-free");
addEdge("m5", "l5", "stairs", "Pedestrians only · stepped descent · no bicycles · not step-free");
// Lower passage graph. Kept separate from both surface streets and stairs.
addEdge(
"l1", "l2", "lower",
"Public lower passage · walking only · no bicycles · not step-free · low headroom · open 06:00–23:00",
{ note: "Uneven floor" }
);
addEdge(
"l2", "l3", "lower",
"Public lower passage · walking only · no bicycles · not step-free · uneven floor · open 06:00–23:00"
);
addEdge(
"l3", "l4", "lower",
"Public lower passage · walking only · no bicycles · not step-free · low headroom · open 06:00–23:00"
);
addEdge(
"l4", "l5", "lower",
"Service passage · walking only · no bicycles · not step-free · one-way eastbound · open 06:00–23:00",
{ oneWay: true, note: "Signed one-way passage" }
);
const nodePositions = {};
for (const [id, node] of Object.entries(nodes)) {
nodePositions[id] = new THREE.Vector3(...node.p);
}
// Broad terraced base and muted hillside forms.
const groundMaterial = standard(palette.ground);
const terraceMaterial = standard(palette.terrace);
const wallMaterial = standard(0x9f947b);
box(106, 2.2, 72, groundMaterial, 0, -5.1, -1);
box(94, 12, 18, terraceMaterial, 0, 5, -26);
box(96, 8, 17, terraceMaterial, 0, 0, -8);
box(101, 3, 25, terraceMaterial, 0, -1.5, 13);
for (let i = 0; i < 6; i++) {
const mountain = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
standard(i % 2 ? 0x9daf9d : 0x91a69d, { roughness: 1 })
);
mountain.position.set(-74 + i * 30, 4 + random() * 6, -48 - random() * 9);
mountain.scale.set(18 + random() * 12, 15 + random() * 9, 16 + random() * 10);
mountain.rotation.set(random(), random(), random());
mountain.receiveShadow = true;
world.add(mountain);
}
const laneMaterial = standard(palette.surface);
const laneSideMaterial = standard(palette.surfaceEdge);
const stairMaterial = standard(palette.stairs);
const lowerMaterial = new THREE.MeshBasicMaterial({
color: palette.lower,
transparent: true,
opacity: 0.9
});
const archMaterial = standard(0x8f8877);
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const edgeRender = new Map();
const pickableEdges = [];
function createSurfaceEdge(edge) {
const a = nodePositions[edge.from];
const b = nodePositions[edge.to];
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const xAxis = direction.clone().normalize();
const yAxis = new THREE.Vector3(0, 1, 0);
yAxis.addScaledVector(xAxis, -yAxis.dot(xAxis)).normalize();
const zAxis = new THREE.Vector3().crossVectors(xAxis, yAxis).normalize();
const basis = new THREE.Matrix4().makeBasis(xAxis, yAxis, zAxis);
const lane = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.25, 2.45),
laneMaterial
);
lane.quaternion.setFromRotationMatrix(basis);
lane.position.copy(a).add(b).multiplyScalar(0.5);
lane.castShadow = true;
lane.receiveShadow = true;
world.add(lane);
// A darker underside makes the elevated street read as a lane rather
// than a flat decorative line.
const under = new THREE.Mesh(
new THREE.BoxGeometry(length * 0.985, 0.2, 2.8),
laneSideMaterial
);
under.quaternion.copy(lane.quaternion);
under.position.copy(lane.position);
under.position.y -= 0.18;
under.receiveShadow = true;
world.add(under);
const hit = cylinderBetween(a, b, 0.9, hitMaterial, world, 5);
hit.userData.edgeId = edge.id;
pickableEdges.push(hit);
}
function createStairEdge(edge) {
const a = nodePositions[edge.from];
const b = nodePositions[edge.to];
const dx = b.x - a.x;
const dz = b.z - a.z;
const horizontalLength = Math.hypot(dx, dz);
const verticalDrop = a.y - b.y;
const count = Math.max(7, Math.round(Math.abs(verticalDrop) * 2.3));
const angle = Math.atan2(dx, dz);
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const step = new THREE.Mesh(
new THREE.BoxGeometry(2.15, 0.38, horizontalLength / count + 0.15),
stairMaterial
);
step.position.set(
THREE.MathUtils.lerp(a.x, b.x, t),
THREE.MathUtils.lerp(a.y, b.y, t) - 0.18,
THREE.MathUtils.lerp(a.z, b.z, t)
);
step.rotation.y = angle;
step.castShadow = true;
step.receiveShadow = true;
world.add(step);
}
const sideOffset = new THREE.Vector3(Math.cos(angle), 0, -Math.sin(angle))
.multiplyScalar(1.05);
cylinderBetween(
a.clone().add(sideOffset).add(new THREE.Vector3(0, 0.8, 0)),
b.clone().add(sideOffset).add(new THREE.Vector3(0, 0.8, 0)),
0.07,
standard(0x695f55)
);
const hit = cylinderBetween(a, b, 0.85, hitMaterial, world, 5);
hit.userData.edgeId = edge.id;
pickableEdges.push(hit);
}
function createLowerEdge(edge) {
const a = nodePositions[edge.from];
const b = nodePositions[edge.to];
const dashCount = 8;
for (let i = 0; i < dashCount; i++) {
const t0 = i / dashCount;
const t1 = t0 + 0.69 / dashCount;
const p0 = a.clone().lerp(b, t0);
const p1 = a.clone().lerp(b, t1);
cylinderBetween(p0, p1, 0.18, lowerMaterial, world, 6);
}
// Small masonry portals emphasize that this is a lower passage.
for (const t of [0.18, 0.82]) {
const p = a.clone().lerp(b, t);
const horizontal = new THREE.Vector3(b.x - a.x, 0, b.z - a.z).normalize();
const side = new THREE.Vector3(-horizontal.z, 0, horizontal.x);
const left = p.clone().addScaledVector(side, 1.1);
const right = p.clone().addScaledVector(side, -1.1);
box(0.35, 1.8, 0.45, archMaterial, left.x, p.y + 0.9, left.z);
box(0.35, 1.8, 0.45, archMaterial, right.x, p.y + 0.9, right.z);
const top = box(
2.45, 0.35, 0.55, archMaterial,
p.x, p.y + 1.85, p.z
);
top.rotation.y = Math.atan2(horizontal.x, horizontal.z);
}
const hit = cylinderBetween(a, b, 0.8, hitMaterial, world, 5);
hit.userData.edgeId = edge.id;
pickableEdges.push(hit);
}
for (const edge of edges) {
if (edge.type === "surface") createSurfaceEdge(edge);
if (edge.type === "stairs") createStairEdge(edge);
if (edge.type === "lower") createLowerEdge(edge);
}
// Low-poly building vocabulary.
const buildingColors = [
0xd87f64, 0xe2a967, 0xe6c46f, 0x9eb9a4,
0x779da2, 0xb88b75, 0xd6a0a0, 0xb9b079
];
const windowMaterial = standard(0xf7d58d, {
emissive: 0x6e4b1f,
emissiveIntensity: 0.35,
roughness: 0.5
});
const roofMaterial = standard(0x9e4f3e);
const foundationMaterial = standard(0x9b8d76);
function makeBuilding(x, baseY, z, width, depth, height, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
const foundationHeight = Math.max(0.6, baseY + 1.2);
box(
width * 0.9, foundationHeight, depth * 0.9,
foundationMaterial, x, baseY - foundationHeight / 2, z
);
const body = box(
width, height, depth, standard(color),
x, baseY + height / 2, z
);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(Math.max(width, depth) * 0.73, 1.45, 4),
roofMaterial
);
roof.position.set(x, baseY + height + 0.72, z);
roof.rotation.y = Math.PI / 4;
roof.scale.z = depth / width;
roof.castShadow = true;
world.add(roof);
const windowCount = Math.max(1, Math.floor(width / 1.8));
for (let i = 0; i < windowCount; i++) {
const wx = x - width * 0.32 + (i * width * 0.64) / Math.max(1, windowCount - 1);
box(
0.42, 0.62, 0.07, windowMaterial,
wx, baseY + height * 0.58, z + depth / 2 + 0.045
);
box(
0.42, 0.62, 0.07, windowMaterial,
wx, baseY + height * 0.58, z - depth / 2 - 0.045
);
}
return body;
}
// Buildings are offset from the street graph to keep the schematic
// connections legible.
edges.filter(edge => edge.type === "surface").forEach((edge, index) => {
const a = nodePositions[edge.from];
const b = nodePositions[edge.to];
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const direction = new THREE.Vector3(b.x - a.x, 0, b.z - a.z).normalize();
const side = new THREE.Vector3(-direction.z, 0, direction.x);
const sign = index % 2 === 0 ? 1 : -1;
const offset = midpoint.clone().addScaledVector(side, sign * (4.4 + random()));
makeBuilding(
offset.x,
midpoint.y - 0.05,
offset.z,
3.2 + random() * 2.2,
3.0 + random() * 2.0,
2.8 + random() * 3.5,
buildingColors[index % buildingColors.length]
);
});
// A few landmark blocks at the upper edge.
makeBuilding(-35, 14.8, -29, 6.2, 4.4, 5.6, 0xd7a269);
makeBuilding(-28, 15.4, -31, 4.2, 4.8, 4.4, 0xc77868);
makeBuilding(0, 14.2, -28, 5.7, 4.5, 5.2, 0xe1bd6c);
makeBuilding(12, 13.7, -29, 5.0, 4.1, 4.7, 0x91aaa1);
makeBuilding(31, 12.0, -25, 5.8, 4.6, 4.5, 0xcc866e);
makeBuilding(-43, 12.2, 20, 5.0, 4.2, 4.8, 0xd9b86d);
makeBuilding(-34, 13.1, 23, 4.7, 4.0, 5.6, 0x8ba6a3);
// Sparse polygonal trees.
const foliageMaterials = [
standard(0x668b70),
standard(0x78946e),
standard(0x879a68)
];
const trunkMaterial = standard(0x665343);
function makeTree(x, y, z, size = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.16 * size, 0.23 * size, 2.1 * size, 5),
trunkMaterial
);
trunk.position.set(x, y + 1.05 * size, z);
trunk.castShadow = true;
world.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.25 * size, 0),
foliageMaterials[Math.floor(random() * foliageMaterials.length)]
);
crown.position.set(x, y + 2.5 * size, z);
crown.scale.y = 1.2;
crown.rotation.set(random(), random(), random());
crown.castShadow = true;
world.add(crown);
}
[
[-43, 12.6, -16], [-37, 13.5, -8], [-44, 12.8, 5],
[44, 10.0, -18], [45, 8.8, -4], [43, 7.1, 10],
[-35, 1.5, 21], [-17, 2.4, 22], [5, 2.7, 24],
[29, 3.1, 22], [45, 3.4, 17]
].forEach((p, i) => makeTree(p[0], p[1], p[2], 0.8 + (i % 3) * 0.16));
// Node discs and hit targets.
const nodeGroups = new Map();
const pickableNodes = [];
const nodeColors = {
upper: 0xf4d273,
middle: 0xef9769,
lower: 0x9f9cff
};
const labelNodeIds = new Set([
"u1", "u3", "u5", "u7", "u9", "u10",
"m1", "m4", "m5", "l1", "l2", "l3", "l4", "l5"
]);
function makeLabel(text, position) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 96;
const ctx = labelCanvas.getContext("2d");
roundedRect(ctx, 6, 8, 500, 80, 20);
ctx.fillStyle = "rgba(24, 34, 35, 0.90)";
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,0.16)";
ctx.lineWidth = 2;
ctx.stroke();
let fontSize = 28;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
while (ctx.measureText(text).width > 458 && fontSize > 17) {
fontSize--;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f6f0df";
ctx.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.position.y += 2.7;
sprite.scale.set(8.8, 1.65, 1);
sprite.renderOrder = 20;
world.add(sprite);
return sprite;
}
for (const [id, node] of Object.entries(nodes)) {
const group = new THREE.Group();
group.position.copy(nodePositions[id]);
world.add(group);
const disc = new THREE.Mesh(
new THREE.CylinderGeometry(0.78, 0.9, 0.25, 12),
standard(nodeColors[node.level])
);
disc.position.y = 0.08;
disc.castShadow = true;
group.add(disc);
const hit = new THREE.Mesh(
new THREE.SphereGeometry(1.35, 10, 8),
hitMaterial
);
hit.position.y = 0.4;
hit.userData.nodeId = id;
group.add(hit);
pickableNodes.push(hit);
if (labelNodeIds.has(id)) {
makeLabel(node.name, nodePositions[id]);
}
nodeGroups.set(id, group);
}
// Start and destination markers.
const startMarker = new THREE.Mesh(
new THREE.TorusGeometry(1.15, 0.13, 6, 28),
new THREE.MeshBasicMaterial({ color: 0x8fe0b4 })
);
startMarker.rotation.x = Math.PI / 2;
scene.add(startMarker);
const destinationMarker = new THREE.Group();
const destinationRing = new THREE.Mesh(
new THREE.TorusGeometry(1.3, 0.15, 6, 32),
new THREE.MeshBasicMaterial({ color: 0xffe266 })
);
destinationRing.rotation.x = Math.PI / 2;
destinationMarker.add(destinationRing);
const destinationDiamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.55, 0),
new THREE.MeshBasicMaterial({ color: 0xffe266 })
);
destinationDiamond.position.y = 2.15;
destinationMarker.add(destinationDiamond);
const destinationBeam = new THREE.Mesh(
new THREE.CylinderGeometry(0.08, 0.22, 6, 7),
new THREE.MeshBasicMaterial({
color: 0xffe266,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
destinationBeam.position.y = 2.1;
destinationMarker.add(destinationBeam);
scene.add(destinationMarker);
// Route visual.
let routeGroup = new THREE.Group();
scene.add(routeGroup);
let routeParticles = [];
let routeSegments = [];
let routeTotalLength = 0;
const routeMaterial = new THREE.MeshBasicMaterial({ color: palette.route });
const routeCoreMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
function clearRouteVisual() {
scene.remove(routeGroup);
routeGroup = new THREE.Group();
scene.add(routeGroup);
routeParticles = [];
routeSegments = [];
routeTotalLength = 0;
}
function drawRoute(routeEdges) {
clearRouteVisual();
const points = [nodePositions[routeEdges[0].from].clone()];
let cumulative = 0;
for (const edgeInfo of routeEdges) {
const a = nodePositions[edgeInfo.from].clone();
const b = nodePositions[edgeInfo.to].clone();
a.y += 0.36;
b.y += 0.36;
cylinderBetween(a, b, 0.19, routeMaterial, routeGroup, 7);
const direction = b.clone().sub(a).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.42, 1.05, 5),
routeCoreMaterial
);
arrow.position.copy(a).lerp(b, 0.64);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
routeGroup.add(arrow);
const length = a.distanceTo(b);
routeSegments.push({ a, b, length, start: cumulative });
cumulative += length;
points.push(b);
}
routeTotalLength = cumulative;
for (let i = 0; i < 5; i++) {
const particle = new THREE.Mesh(
new THREE.SphereGeometry(0.25, 8, 6),
routeCoreMaterial
);
routeGroup.add(particle);
routeParticles.push(particle);
}
}
// Direct camera controls: orbit, wheel zoom, and shift/right-drag pan.
const controls = {
theta: 0.72,
phi: 0.86,
distance: 88,
target: new THREE.Vector3(0, 7, -1),
goalTheta: 0.72,
goalPhi: 0.86,
goalDistance: 88,
goalTarget: new THREE.Vector3(0, 7, -1)
};
function updateCamera() {
controls.theta += (controls.goalTheta - controls.theta) * 0.1;
controls.phi += (controls.goalPhi - controls.phi) * 0.1;
controls.distance += (controls.goalDistance - controls.distance) * 0.1;
controls.target.lerp(controls.goalTarget, 0.1);
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.distance * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.distance * Math.cos(controls.phi),
controls.target.z + controls.distance * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.goalTheta = 0.72;
controls.goalPhi = 0.86;
controls.goalDistance = 88;
controls.goalTarget.set(0, 7, -1);
}
function focusEdge(edge) {
const midpoint = nodePositions[edge.from].clone()
.add(nodePositions[edge.to])
.multiplyScalar(0.5);
controls.goalTarget.copy(midpoint);
controls.goalDistance = 48;
}
// Populate selects.
const sortedNodes = Object.entries(nodes).sort((a, b) => {
const order = { upper: 0, middle: 1, lower: 2 };
return order[a[1].level] - order[b[1].level] || a[1].name.localeCompare(b[1].name);
});
for (const [id, node] of sortedNodes) {
for (const select of [startSelect, destinationSelect]) {
const option = document.createElement("option");
option.value = id;
option.textContent = node.name;
select.appendChild(option);
}
}
startSelect.value = "u1";
destinationSelect.value = "l4";
let mode = "walking";
function lowerPassagesOpen() {
const value = networkTime.value || "10:30";
const [hour, minute] = value.split(":").map(Number);
const decimal = hour + minute / 60;
return decimal >= 6 && decimal < 23;
}
function edgeAllowed(edge) {
if (mode === "bicycle" || mode === "stepfree") {
return edge.type === "surface";
}
if (edge.type === "surface") return true;
if (edge.type === "stairs") return true;
if (edge.type === "lower") {
return !avoidLower.checked && lowerPassagesOpen();
}
return false;
}
function dijkstra(start, destination) {
const adjacency = new Map();
for (const id of Object.keys(nodes)) adjacency.set(id, []);
for (const edge of edges) {
if (!edgeAllowed(edge)) continue;
const length = nodePositions[edge.from].distanceTo(nodePositions[edge.to]);
adjacency.get(edge.from).push({
to: edge.to,
edge,
length
});
if (!edge.oneWay) {
adjacency.get(edge.to).push({
to: edge.from,
edge,
length
});
}
}
const distances = new Map();
const previous = new Map();
const unvisited = new Set(Object.keys(nodes));
for (const id of unvisited) distances.set(id, Infinity);
distances.set(start, 0);
while (unvisited.size) {
let current = null;
let best = Infinity;
for (const id of unvisited) {
const distance = distances.get(id);
if (distance < best) {
best = distance;
current = id;
}
}
if (current === null || best === Infinity) break;
if (current === destination) break;
unvisited.delete(current);
for (const neighbor of adjacency.get(current)) {
if (!unvisited.has(neighbor.to)) continue;
const candidate = best + neighbor.length;
if (candidate < distances.get(neighbor.to)) {
distances.set(neighbor.to, candidate);
previous.set(neighbor.to, {
from: current,
edge: neighbor.edge
});
}
}
}
if (!previous.has(destination) && start !== destination) return null;
const route = [];
let current = destination;
while (current !== start) {
const item = previous.get(current);
if (!item) return null;
route.unshift({
from: item.from,
to: current,
edge: item.edge
});
current = item.from;
}
return route;
}
function routeTypeLabel(type) {
if (type === "surface") return "Surface street";
if (type === "stairs") return "Stair connection";
return "Lower passage";
}
function routeTypeBadge(type) {
if (type === "surface") return "ST";
if (type === "stairs") return "▲";
return "LP";
}
function explainNoRoute() {
if (mode === "stepfree") {
return "No step-free route. Step-free mode excludes stair connections and lower passages; lower-layer destinations have no grade-separated connection in this schematic.";
}
if (mode === "bicycle") {
return "No bicycle route. Bicycle mode permits surface streets only; this destination requires stairs or a lower passage.";
}
if (!lowerPassagesOpen()) {
return "No permitted route at the selected clock time. All lower passages are closed outside their 06:00–23:00 public hours.";
}
if (avoidLower.checked) {
return "No permitted route with lower passages avoided. The remaining stair and surface connections do not reach this destination.";
}
return "No permitted route. The selected restrictions disconnect the destination from the start point.";
}
function updateMarkers() {
const start = nodePositions[startSelect.value];
const destination = nodePositions[destinationSelect.value];
startMarker.position.copy(start);
startMarker.position.y += 0.28;
destinationMarker.position.copy(destination);
destinationMarker.position.y += 0.28;
}
function updateRoute() {
const start = startSelect.value;
const destination = destinationSelect.value;
updateMarkers();
if (start === destination) {
routeMeta.innerHTML = "<strong>Already there</strong><span>Choose the same point</span>";
routeWarning.textContent = "Move the start or destination marker to preview another connection.";
routeSteps.innerHTML = "";
clearRouteVisual();
return;
}
const route = dijkstra(start, destination);
if (!route) {
routeMeta.innerHTML = "<strong>No permitted route</strong><span>Restrictions applied</span>";
routeWarning.textContent = "";
routeSteps.innerHTML = `<div class="empty-route">${explainNoRoute()}</div>`;
clearRouteVisual();
return;
}
let meters = 0;
let minutes = 0;
let stairCount = 0;
let lowerCount = 0;
for (const item of route) {
const length = nodePositions[item.from].distanceTo(nodePositions[item.to]);
const distance = length * 5.8;
meters += distance;
let speed = 74;
if (item.edge.type === "stairs") {
speed = 36;
stairCount++;
}
if (item.edge.type === "lower") {
speed = 48;
lowerCount++;
}
minutes += distance / speed;
}
const roundedMinutes = Math.max(1, Math.round(minutes));
routeMeta.innerHTML = `
<strong>≈ ${roundedMinutes} min · ${Math.round(meters)} m</strong>
<span>${route.length} permitted connection${route.length === 1 ? "" : "s"}</span>
`;
const warnings = [];
if (stairCount) {
warnings.push(`${stairCount} stair connection${stairCount === 1 ? "" : "s"} require${stairCount === 1 ? "s" : ""} climbing and are not step-free`);
}
if (lowerCount) {
warnings.push(`${lowerCount} lower passage${lowerCount === 1 ? "" : "s"} ${lowerPassagesOpen() ? "are open at the selected clock time" : "are excluded by the selected hours"}`);
}
if (mode === "bicycle") {
warnings.push("Bicycle route uses surface streets only");
}
routeWarning.textContent = warnings.join(" · ");
routeSteps.innerHTML = route.map(item => {
const edge = item.edge;
const fromName = nodes[item.from].name;
const toName = nodes[item.to].name;
return `
<div class="route-step">
<span class="step-badge ${edge.type}">${routeTypeBadge(edge.type)}</span>
<div>
<b>${fromName} → ${toName}</b>
<small>${routeTypeLabel(edge.type)} · ${edge.rules}</small>
</div>
</div>
`;
}).join("");
drawRoute(route);
}
// Build the explicit connection list.
const typeNames = {
surface: "Surface streets",
stairs: "Stair connections",
lower: "Lower passages"
};
for (const type of ["surface", "stairs", "lower"]) {
const section = document.createElement("section");
section.className = `network-group ${type}`;
const title = document.createElement("div");
title.className = "network-group-title";
title.textContent = typeNames[type];
section.appendChild(title);
for (const edge of edges.filter(item => item.type === type)) {
const button = document.createElement("button");
button.className = "network-row";
button.dataset.edgeId = edge.id;
const direction = edge.oneWay
? `${nodes[edge.from].name} → ${nodes[edge.to].name}`
: `${nodes[edge.from].name} ↔ ${nodes[edge.to].name}`;
button.innerHTML = `
<b>${direction}</b>
<small>${edge.rules}</small>
`;
button.addEventListener("click", () => inspectEdge(edge.id));
section.appendChild(button);
}
networkList.appendChild(section);
}
let selectedEdgeId = null;
let edgeHighlight = null;
function inspectEdge(edgeId) {
const edge = edges.find(item => item.id === edgeId);
if (!edge) return;
selectedEdgeId = edgeId;
if (edgeHighlight) scene.remove(edgeHighlight);
edgeHighlight = new THREE.Group();
scene.add(edgeHighlight);
const a = nodePositions[edge.from].clone().add(new THREE.Vector3(0, 0.55, 0));
const b = nodePositions[edge.to].clone().add(new THREE.Vector3(0, 0.55, 0));
cylinderBetween(
a, b, 0.22,
new THREE.MeshBasicMaterial({ color: 0xffffff }),
edgeHighlight, 8
);
document.querySelectorAll(".network-row").forEach(row => {
row.classList.toggle("active", row.dataset.edgeId === edgeId);
});
const tag = document.getElementById("inspectorTag");
tag.textContent = routeTypeLabel(edge.type);
tag.style.background =
edge.type === "surface" ? "var(--surface)" :
edge.type === "stairs" ? "var(--stairs)" :
"var(--lower)";
document.getElementById("inspectorTitle").textContent =
edge.oneWay ? "One-way connection" : "Two-way connection";
document.getElementById("inspectorRules").textContent = edge.rules;
inspector.classList.add("open");
focusEdge(edge);
}
document.getElementById("inspectorClose").addEventListener("click", () => {
inspector.classList.remove("open");
if (edgeHighlight) {
scene.remove(edgeHighlight);
edgeHighlight = null;
}
document.querySelectorAll(".network-row.active").forEach(row => {
row.classList.remove("active");
});
selectedEdgeId = null;
});
document.getElementById("networkToggle").addEventListener("click", () => {
networkDrawer.classList.add("open");
});
document.getElementById("networkClose").addEventListener("click", () => {
networkDrawer.classList.remove("open");
});
// Planner events.
routeButton.addEventListener("click", () => {
updateRoute();
const toast = document.getElementById("toast");
toast.textContent = "Route updated using the selected access rules";
toast.classList.add("show");
clearTimeout(toast.timer);
toast.timer = setTimeout(() => toast.classList.remove("show"), 1800);
});
startSelect.addEventListener("change", updateRoute);
destinationSelect.addEventListener("change", updateRoute);
avoidLower.addEventListener("change", updateRoute);
networkTime.addEventListener("change", updateRoute);
document.querySelectorAll(".mode-tabs button").forEach(button => {
button.addEventListener("click", () => {
mode = button.dataset.mode;
document.querySelectorAll(".mode-tabs button").forEach(item => {
item.classList.toggle("active", item === button);
});
updateRoute();
});
});
// Camera buttons.
document.getElementById("zoomIn").addEventListener("click", () => {
controls.goalDistance = Math.max(34, controls.goalDistance - 9);
});
document.getElementById("zoomOut").addEventListener("click", () => {
controls.goalDistance = Math.min(135, controls.goalDistance + 9);
});
document.getElementById("homeView").addEventListener("click", resetCamera);
// Pointer interaction.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const activePointers = new Map();
let lastPointer = null;
let dragDistance = 0;
let pinchDistance = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
lastPointer = { x: event.clientX, y: event.clientY };
dragDistance = 0;
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", event => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size >= 2) {
const points = [...activePointers.values()];
const nextDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
controls.goalDistance = THREE.MathUtils.clamp(
controls.goalDistance * (pinchDistance / Math.max(1, nextDistance)),
34,
135
);
}
pinchDistance = nextDistance;
return;
}
if (!lastPointer) return;
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
dragDistance += Math.abs(dx) + Math.abs(dy);
const panning = event.shiftKey || (event.buttons & 2) !== 0;
if (panning) {
const scale = controls.distance * 0.0016;
const right = new THREE.Vector3(
Math.cos(controls.theta),
0,
-Math.sin(controls.theta)
);
const forward = new THREE.Vector3(
-Math.sin(controls.theta),
0,
-Math.cos(controls.theta)
);
controls.goalTarget.addScaledVector(right, -dx * scale);
controls.goalTarget.addScaledVector(forward, -dy * scale);
} else {
controls.goalTheta -= dx * 0.006;
controls.goalPhi = THREE.MathUtils.clamp(
controls.goalPhi - dy * 0.005,
0.32,
1.27
);
}
});
function pickAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const nodeHits = raycaster.intersectObjects(pickableNodes, false);
if (nodeHits.length) {
const id = nodeHits[0].object.userData.nodeId;
destinationSelect.value = id;
updateRoute();
const toast = document.getElementById("toast");
toast.textContent = `Destination: ${nodes[id].name}`;
toast.classList.add("show");
clearTimeout(toast.timer);
toast.timer = setTimeout(() => toast.classList.remove("show"), 1700);
return;
}
const edgeHits = raycaster.intersectObjects(pickableEdges, false);
if (edgeHits.length) {
inspectEdge(edgeHits[0].object.userData.edgeId);
}
}
canvas.addEventListener("pointerup", event => {
const wasSinglePointer = activePointers.size === 1;
activePointers.delete(event.pointerId);
if (wasSinglePointer && dragDistance < 7) {
pickAt(event.clientX, event.clientY);
}
if (activePointers.size === 0) lastPointer = null;
if (activePointers.size < 2) pinchDistance = 0;
});
canvas.addEventListener("pointercancel", event => {
activePointers.delete(event.pointerId);
lastPointer = null;
pinchDistance = 0;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
controls.goalDistance = THREE.MathUtils.clamp(
controls.goalDistance * factor,
34,
135
);
}, { passive: false });
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// Initial state.
updateRoute();
updateCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
destinationRing.scale.setScalar(1 + Math.sin(elapsed * 3.2) * 0.07);
destinationDiamond.rotation.y = elapsed * 1.1;
destinationDiamond.rotation.x = elapsed * 0.55;
destinationDiamond.position.y = 2.15 + Math.sin(elapsed * 2.5) * 0.22;
if (routeSegments.length && routeTotalLength > 0) {
routeParticles.forEach((particle, index) => {
const t = (elapsed * 0.07 + index / routeParticles.length) % 1;
const targetDistance = t * routeTotalLength;
let segment = routeSegments[routeSegments.length - 1];
for (const candidate of routeSegments) {
if (targetDistance <= candidate.start + candidate.length) {
segment = candidate;
break;
}
}
const localT = THREE.MathUtils.clamp(
(targetDistance - segment.start) / Math.max(0.001, segment.length),
0,
1
);
particle.position.copy(segment.a).lerp(segment.b, localT);
});
}
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```