Prompt specification
Build or customize the Three.js 3D scene "Compare access with an escalator temporarily unavailable" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Compare access with an escalator temporarily unavailable
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-access-with-an-escalator-temporarily-unavailab-x2752
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Comuna 13's hillside connections in Medellín. Let users switch to an explicitly hypothetical maintenance condition. Show alternate stair routes and changed vertical effort while preserving all building entrances and neighborhood connections. Voxel style.
Working Three.js Starter (compare-access-with-an-escalator-temporarily-unavailab-x2752):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="An interactive voxel-style conceptual study of hillside connections in Comuna 13, Medellín."
/>
<title>Comuna 13 — Hillside Connections</title>
<style>
:root {
--ink: #172321;
--muted: #63716c;
--paper: #f5f0e5;
--panel: rgba(250, 247, 239, 0.92);
--line: rgba(23, 35, 33, 0.13);
--teal: #147d72;
--teal-soft: #d5ebe5;
--orange: #e86f32;
--orange-soft: #f8e0d1;
--red: #c83d3d;
--blue: #3676a8;
--green: #4c9b61;
--gold: #d6a33d;
--shadow: 0 14px 45px rgba(40, 42, 32, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 34%, #f8f3e7 0, #e8e0ce 52%, #d7cfbd 100%);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(20, 125, 114, 0.42);
outline-offset: 3px;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
touch-action: none;
cursor: grab;
}
#stage canvas.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 20;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.brand,
.top-actions {
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 14px 10px 10px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 17px;
background: rgba(250, 247, 239, 0.84);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.brand-mark {
display: grid;
width: 44px;
height: 44px;
place-items: center;
border-radius: 12px;
background: var(--ink);
color: #fff9ec;
font-size: 17px;
font-weight: 850;
letter-spacing: -0.05em;
}
.brand h1 {
margin: 0;
font-size: 20px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.top-actions {
display: flex;
gap: 8px;
}
.small-button {
min-height: 39px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(250, 247, 239, 0.88);
color: var(--ink);
box-shadow: 0 8px 25px rgba(40, 42, 32, 0.08);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 12px;
font-weight: 750;
}
.small-button:hover {
background: #fffdf8;
transform: translateY(-1px);
}
.small-button[aria-pressed="false"] {
color: var(--muted);
}
.panel {
position: fixed;
z-index: 15;
border: 1px solid rgba(255, 255, 255, 0.66);
border-radius: 19px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
}
#scenario-panel {
top: 92px;
right: 20px;
width: 328px;
max-height: calc(100vh - 116px);
padding: 17px;
overflow: auto;
scrollbar-width: thin;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.badge {
display: inline-flex;
align-items: center;
min-height: 24px;
padding: 0 9px;
border-radius: 999px;
background: var(--teal-soft);
color: var(--teal);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
.badge.hypothetical {
background: var(--orange-soft);
color: #b64d1d;
}
.condition-switch {
display: grid;
grid-template-columns: 0.86fr 1.14fr;
gap: 4px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(32, 45, 41, 0.05);
}
.condition-switch button {
min-height: 40px;
padding: 6px 8px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 11px;
font-weight: 800;
line-height: 1.15;
}
.condition-switch button.active {
background: #fffef9;
color: var(--ink);
box-shadow: 0 4px 12px rgba(31, 42, 38, 0.09);
}
.condition-switch button.hypo.active {
color: #a8461b;
}
.description {
min-height: 56px;
margin: 12px 1px 14px;
color: #53605d;
font-size: 12px;
line-height: 1.5;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 14px 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.route-options {
display: grid;
gap: 6px;
}
.route-option {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
min-height: 45px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.43);
color: var(--ink);
text-align: left;
cursor: pointer;
}
.route-option:hover:not(:disabled) {
background: #fffef9;
border-color: rgba(20, 125, 114, 0.3);
}
.route-option.active {
border-color: rgba(20, 125, 114, 0.48);
background: var(--teal-soft);
}
.route-option.hypo-active {
border-color: rgba(232, 111, 50, 0.52);
background: var(--orange-soft);
}
.route-option:disabled {
cursor: not-allowed;
opacity: 0.46;
}
.route-swatch {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--teal);
}
.route-option[data-route="east"] .route-swatch {
background: var(--orange);
}
.route-option[data-route="west"] .route-swatch {
background: #9e684e;
}
.route-option strong {
display: block;
font-size: 11px;
line-height: 1.2;
}
.route-option small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
.route-option .count {
color: var(--muted);
font-size: 10px;
font-weight: 850;
white-space: nowrap;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.metric {
min-height: 75px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.48);
}
.metric.wide {
grid-column: 1 / -1;
min-height: 68px;
}
.metric-label {
color: var(--muted);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric-value {
margin-top: 5px;
font-size: 21px;
font-weight: 850;
letter-spacing: -0.04em;
}
.metric-value small {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0;
}
.metric-note {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.metric.hypo .metric-value {
color: #bd541f;
}
.delta-note {
margin: 9px 1px 0;
padding: 9px 10px;
border-left: 3px solid var(--orange);
border-radius: 0 8px 8px 0;
background: var(--orange-soft);
color: #754326;
font-size: 10px;
font-weight: 700;
line-height: 1.45;
}
.preservation {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 12px;
}
.preservation-item {
padding: 9px;
border: 1px solid rgba(76, 155, 97, 0.25);
border-radius: 11px;
background: rgba(218, 239, 220, 0.65);
}
.preservation-item strong {
display: block;
color: #327445;
font-size: 14px;
letter-spacing: -0.02em;
}
.preservation-item span {
display: block;
margin-top: 2px;
color: #57745e;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#story-panel {
left: 20px;
bottom: 22px;
width: 315px;
padding: 17px;
}
#story-panel h2 {
margin: 7px 0 8px;
font-size: 20px;
line-height: 1.14;
letter-spacing: -0.035em;
}
#story-panel p {
margin: 0;
color: #596560;
font-size: 11px;
line-height: 1.52;
}
.constraint {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #365e42;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.constraint::before {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(76, 155, 97, 0.13);
content: "";
}
.legend {
position: fixed;
z-index: 12;
right: 20px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px 12px;
max-width: 330px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 12px;
background: rgba(250, 247, 239, 0.82);
box-shadow: 0 8px 28px rgba(40, 42, 32, 0.09);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #596560;
font-size: 9px;
font-weight: 750;
}
.legend-line {
width: 17px;
height: 5px;
border-radius: 2px;
background: var(--teal);
}
.legend-line.orange {
background: var(--orange);
}
.legend-line.green {
background: var(--green);
}
.legend-line.blue {
background: var(--blue);
}
.legend-line.red {
background: var(--red);
}
.help {
position: fixed;
z-index: 10;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 999px;
background: rgba(250, 247, 239, 0.7);
color: #6a756f;
font-size: 9px;
font-weight: 700;
backdrop-filter: blur(8px);
pointer-events: none;
white-space: nowrap;
}
#labels-layer {
position: fixed;
z-index: 8;
inset: 0;
overflow: hidden;
pointer-events: none;
transition: opacity 160ms ease;
}
#labels-layer.hidden {
opacity: 0;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 8px;
background: rgba(250, 247, 239, 0.86);
color: #35423e;
box-shadow: 0 5px 16px rgba(31, 40, 35, 0.09);
font-size: 9px;
font-weight: 800;
line-height: 1;
white-space: nowrap;
backdrop-filter: blur(6px);
}
.scene-label.place {
color: #32413d;
}
.scene-label.entrance {
display: grid;
width: 20px;
height: 20px;
padding: 0;
place-items: center;
border: 2px solid #effaf1;
border-radius: 50%;
background: var(--green);
color: white;
box-shadow: 0 3px 10px rgba(35, 91, 54, 0.25);
font-size: 8px;
}
.scene-label.route {
border-color: rgba(20, 125, 114, 0.2);
background: rgba(226, 245, 239, 0.93);
color: #0f685f;
font-size: 10px;
}
.scene-label.route.hypo {
border-color: rgba(232, 111, 50, 0.3);
background: rgba(255, 237, 225, 0.95);
color: #a9471d;
}
.scene-label.closure {
border-color: rgba(200, 61, 61, 0.3);
background: rgba(255, 235, 232, 0.95);
color: #a52e2e;
font-size: 10px;
}
#tooltip {
position: fixed;
z-index: 30;
display: none;
max-width: 220px;
padding: 7px 9px;
border-radius: 8px;
background: rgba(23, 35, 33, 0.94);
color: white;
box-shadow: 0 8px 25px rgba(20, 25, 23, 0.22);
font-size: 10px;
font-weight: 700;
line-height: 1.35;
pointer-events: none;
}
.disclaimer {
position: fixed;
z-index: 11;
top: 86px;
left: 22px;
max-width: 330px;
color: rgba(54, 65, 61, 0.72);
font-size: 9px;
font-weight: 700;
line-height: 1.4;
pointer-events: none;
}
@media (max-width: 900px) {
.disclaimer {
display: none;
}
#story-panel {
width: 275px;
}
#scenario-panel {
width: 300px;
}
.help {
display: none;
}
}
@media (max-width: 700px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
padding: 8px;
}
.brand-mark {
width: 38px;
height: 38px;
}
.brand h1 {
font-size: 16px;
}
.brand p {
font-size: 8px;
}
.top-actions {
gap: 5px;
}
.small-button {
min-height: 36px;
padding: 0 9px;
font-size: 10px;
}
#scenario-panel {
top: 68px;
right: 10px;
width: min(300px, calc(100vw - 20px));
max-height: 47vh;
padding: 13px;
}
#story-panel {
left: 10px;
bottom: 10px;
width: min(285px, calc(100vw - 20px));
padding: 13px;
}
#story-panel h2 {
font-size: 16px;
}
#story-panel p {
font-size: 10px;
}
.legend {
display: none;
}
.scene-label.place {
font-size: 8px;
}
}
@media (max-height: 690px) and (min-width: 701px) {
#story-panel {
display: none;
}
#scenario-panel {
max-height: calc(100vh - 105px);
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel model of hillside connections in Comuna 13"></main>
<div id="labels-layer" aria-hidden="true"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark">13</div>
<div>
<h1>Comuna 13</h1>
<p>Hillside connections · Medellín</p>
</div>
</div>
<div class="top-actions">
<button class="small-button" id="labels-button" aria-pressed="true">
Labels
</button>
<button class="small-button" id="reset-button">Reset view</button>
</div>
</header>
<p class="disclaimer">
Conceptual voxel diagram, not a surveyed or navigational map.
Access conditions and route dimensions are schematic.
</p>
<aside class="panel" id="scenario-panel" aria-label="Connection scenario controls">
<div class="panel-heading">
<span class="eyebrow">Connection scenario</span>
<span class="badge" id="scenario-badge">Reference</span>
</div>
<div class="condition-switch" role="group" aria-label="Select network condition">
<button id="reference-button" class="active" aria-pressed="true">
Reference<br />network
</button>
<button id="maintenance-button" class="hypo" aria-pressed="false">
Hypothetical<br />maintenance
</button>
</div>
<p class="description" id="scenario-description">
The central stair is open in the reference network. Alternate switchbacks
remain visible as muted context.
</p>
<div class="section-label">
<span>Route comparison</span>
<span>Lower → upper</span>
</div>
<div class="route-options">
<button class="route-option active" data-route="reference" aria-pressed="true">
<span class="route-swatch"></span>
<span>
<strong>Central stair</strong>
<small>Reference alignment</small>
</span>
<span class="count">136 treads</span>
</button>
<button class="route-option" data-route="east" aria-pressed="false" disabled>
<span class="route-swatch"></span>
<span>
<strong>East switchbacks</strong>
<small>Longer, distributed climb</small>
</span>
<span class="count">149 treads</span>
</button>
<button class="route-option" data-route="west" aria-pressed="false" disabled>
<span class="route-swatch"></span>
<span>
<strong>West terraces</strong>
<small>Longest alternate</small>
</span>
<span class="count">162 treads</span>
</button>
</div>
<div class="section-label">
<span>Vertical effort</span>
<span id="route-name">Central stair</span>
</div>
<div class="metrics" aria-live="polite">
<div class="metric wide">
<div class="metric-label">Step effort</div>
<div class="metric-value" id="steps-value">136 <small>treads</small></div>
<div class="metric-note" id="steps-note">Reference effort index: 1.00×</div>
</div>
<div class="metric">
<div class="metric-label">Elevation gain</div>
<div class="metric-value" id="ascent-value">20.0 <small>m</small></div>
<div class="metric-note">Same upper connection</div>
</div>
<div class="metric">
<div class="metric-label">Route length</div>
<div class="metric-value" id="distance-value">40 <small>m</small></div>
<div class="metric-note">Schematic plan length</div>
</div>
<div class="metric wide">
<div class="metric-label">Estimated traversal</div>
<div class="metric-value" id="time-value">4.5 <small>min</small></div>
<div class="metric-note">
Includes a simplified stair-speed penalty; not travel advice.
</div>
</div>
</div>
<p class="delta-note" id="delta-note">
Select the explicitly hypothetical maintenance condition to compare
alternate stair effort.
</p>
<div class="preservation" aria-label="Preserved network elements">
<div class="preservation-item">
<strong>8 / 8</strong>
<span>Entrances retained</span>
</div>
<div class="preservation-item">
<strong>4 / 4</strong>
<span>Neighborhood links retained</span>
</div>
</div>
</aside>
<section class="panel" id="story-panel" aria-label="Design intent">
<span class="eyebrow">Design intent</span>
<h2>A closed stair, not a severed neighborhood.</h2>
<p>
The hypothetical works window removes one central flight—not any building
entrance or neighborhood connection. Alternate stairs redistribute the
same climb over more treads and a longer plan distance.
</p>
<div class="constraint">All access points remain connected</div>
</section>
<div class="legend" aria-label="Map legend">
<div class="legend-item"><span class="legend-line"></span>Reference stair</div>
<div class="legend-item"><span class="legend-line orange"></span>Alternate stair</div>
<div class="legend-item"><span class="legend-line green"></span>Entrance</div>
<div class="legend-item"><span class="legend-line blue"></span>Neighborhood link</div>
<div class="legend-item"><span class="legend-line red"></span>Hypothetical closure</div>
</div>
<div class="help">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div id="tooltip" role="status"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and scene setup
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const labelsLayer = document.querySelector("#labels-layer");
const tooltip = document.querySelector("#tooltip");
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe8e0cf, 105, 175);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Orbitable voxel model of Comuna 13 hillside pedestrian connections"
);
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-40, 40, 26, -26, 0.1, 240);
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x8b9b88, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1ce, 3.4);
sun.position.set(-34, 58, 30);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 52;
sun.shadow.camera.bottom = -52;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 140;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d5df, 0.7);
fill.position.set(42, 24, -35);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d0bc,
roughness: 1
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(220, 220),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.14;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Camera controls — implemented without Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.72,
phi: 0.91,
radius: 78,
zoom: 1,
target: new THREE.Vector3(0, 8.5, 0)
};
let viewSize = window.innerWidth < 700 ? 86 : 52;
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = viewSize / cameraState.zoom / 2;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
viewSize = width < 700 ? 86 : 52;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
let dragState = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
dragState = {
button: event.button,
x: event.clientX,
y: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragState) {
const dx = event.clientX - dragState.x;
const dy = event.clientY - dragState.y;
dragState.x = event.clientX;
dragState.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 1) dragState.moved = true;
if (event.shiftKey || dragState.button === 2) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(
camera.quaternion
);
const scale = viewSize / cameraState.zoom / window.innerHeight;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-24,
24
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
3,
17
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-25,
25
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.004,
0.45,
1.34
);
}
updateCamera();
hideTooltip();
} else {
updateHover(event);
}
});
function stopDragging(event) {
if (!dragState) return;
dragState = null;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("pointerleave", () => {
hideTooltip();
if (!dragState) renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 0.91;
cameraState.radius = 78;
cameraState.zoom = 1;
cameraState.target.set(0, 8.5, 0);
updateCamera();
}
document.querySelector("#reset-button").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.key === "ArrowLeft") cameraState.theta -= 0.09;
if (event.key === "ArrowRight") cameraState.theta += 0.09;
if (event.key === "ArrowUp") cameraState.phi -= 0.06;
if (event.key === "ArrowDown") cameraState.phi += 0.06;
if (event.key === "+" || event.key === "=") cameraState.zoom *= 1.08;
if (event.key === "-") cameraState.zoom /= 1.08;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi, 0.45, 1.34);
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom, 0.62, 2.5);
updateCamera();
});
// -------------------------------------------------------------------------
// Network nodes and edges
// -------------------------------------------------------------------------
const nodes = {
south: new THREE.Vector3(0, 0.2, 22),
plaza: new THREE.Vector3(0, 0.2, 13),
lower: new THREE.Vector3(0, 4.2, 8),
mainTop: new THREE.Vector3(0, 9.2, -2),
upperLanding: new THREE.Vector3(0, 15.2, -10),
upperHub: new THREE.Vector3(0, 20.2, -18),
eastLow: new THREE.Vector3(22, 4.2, 8),
eastMid: new THREE.Vector3(22, 9.2, 2),
eastHigh: new THREE.Vector3(22, 15.2, -10),
westLow: new THREE.Vector3(-25, 4.2, 8),
westMid: new THREE.Vector3(-25, 9.2, 2),
westHigh: new THREE.Vector3(-25, 15.2, -10),
northLink: new THREE.Vector3(0, 20.2, -21),
eastLink: new THREE.Vector3(30, 15.2, -10),
westLink: new THREE.Vector3(-30, 15.2, -10)
};
const edges = [];
const edgeById = new Map();
function addEdge(id, a, b, kind, steps = 0) {
const edge = {
id,
a,
b,
kind,
steps,
distance: nodes[a].distanceTo(nodes[b])
};
edges.push(edge);
edgeById.set(id, edge);
return edge;
}
addEdge("south__plaza", "south", "plaza", "connector");
addEdge("plaza__lower", "plaza", "lower", "stair", 20);
addEdge("lower__mainTop", "lower", "mainTop", "stair", 52);
addEdge("mainTop__upperLanding", "mainTop", "upperLanding", "stair", 38);
addEdge("upperLanding__upperHub", "upperLanding", "upperHub", "stair", 26);
addEdge("plaza__eastLow", "plaza", "eastLow", "alternate", 30);
addEdge("eastLow__eastMid", "eastLow", "eastMid", "alternate", 38);
addEdge("eastMid__eastHigh", "eastMid", "eastHigh", "alternate", 55);
addEdge("eastHigh__upperLanding", "eastHigh", "upperLanding", "alternate");
addEdge("plaza__westLow", "plaza", "westLow", "alternate", 29);
addEdge("westLow__westMid", "westLow", "westMid", "alternate", 43);
addEdge("westMid__westHigh", "westMid", "westHigh", "alternate", 64);
addEdge("westHigh__upperLanding", "westHigh", "upperLanding", "alternate");
addEdge(
"upperLanding__northLink",
"upperLanding",
"northLink",
"connector"
);
addEdge(
"upperLanding__eastLink",
"upperLanding",
"eastLink",
"connector"
);
addEdge(
"upperLanding__westLink",
"upperLanding",
"westLink",
"connector"
);
const buildingSpecs = [
{ x: -10, z: 10, color: 0xd87758, attach: "plaza", number: 1 },
{ x: 10, z: 10, color: 0xe1b958, attach: "plaza", number: 2 },
{ x: -10, z: 4, color: 0x5d94a0, attach: "lower", number: 3 },
{ x: 10, z: 4, color: 0xcf6b53, attach: "lower", number: 4 },
{ x: -10, z: -5, color: 0xe0b95c, attach: "mainTop", number: 5 },
{ x: 10, z: -5, color: 0x628d78, attach: "mainTop", number: 6 },
{ x: -10, z: -13, color: 0xc77358, attach: "upperLanding", number: 7 },
{ x: 10, z: -13, color: 0x5b8ca0, attach: "upperLanding", number: 8 }
];
const entranceEdges = [];
buildingSpecs.forEach((spec) => {
const groundHeight = naturalHeight(spec.x, spec.z);
const entranceNode = `entrance${spec.number}`;
const entrancePosition = new THREE.Vector3(
spec.x,
groundHeight + 0.2,
spec.z + 2.72
);
nodes[entranceNode] = entrancePosition;
const edge = addEdge(
`${spec.attach}__${entranceNode}`,
spec.attach,
entranceNode,
"entrance"
);
entranceEdges.push(edge);
spec.entranceNode = entranceNode;
});
const routeDefinitions = {
reference: {
name: "Central stair",
nodes: [
"south",
"plaza",
"lower",
"mainTop",
"upperLanding",
"upperHub"
],
labelPosition: new THREE.Vector3(0, 9.4, 1.5)
},
east: {
name: "East switchbacks",
nodes: [
"south",
"plaza",
"eastLow",
"eastMid",
"eastHigh",
"upperLanding",
"upperHub"
],
labelPosition: new THREE.Vector3(22, 10.1, 0)
},
west: {
name: "West terraces",
nodes: [
"south",
"plaza",
"westLow",
"westMid",
"westHigh",
"upperLanding",
"upperHub"
],
labelPosition: new THREE.Vector3(-25, 10.1, 0)
}
};
function routeMetrics(routeName) {
const points = routeDefinitions[routeName].nodes;
let steps = 0;
let distance = 0;
let ascent = 0;
for (let i = 0; i < points.length - 1; i++) {
const a = nodes[points[i]];
const b = nodes[points[i + 1]];
const edge = edgeById.get(`${points[i]}__${points[i + 1]}`);
steps += edge.steps;
distance += edge.distance;
ascent += Math.max(0, b.y - a.y);
}
const reference = routeMetrics.reference;
const effort = reference ? steps / reference.steps : 1;
const time = distance / 55 + steps * 0.028;
return { steps, distance, ascent, effort, time };
}
routeMetrics.reference = routeMetrics("reference");
// -------------------------------------------------------------------------
// Terrain
// -------------------------------------------------------------------------
function naturalHeight(x, z) {
if (z > 10) return 0;
if (z > 2) return 4;
if (z > -6) return 9;
if (z > -14) return 15;
return 20;
}
const routeProfiles = [
{
x: 0,
points: [
[13, 0.2],
[8, 4.2],
[-2, 9.2],
[-10, 15.2],
[-18, 20.2]
]
},
{
x: 22,
points: [
[13, 0.2],
[8, 4.2],
[2, 9.2],
[-10, 15.2]
]
},
{
x: -25,
points: [
[13, 0.2],
[8, 4.2],
[2, 9.2],
[-10, 15.2]
]
}
];
function sampleProfile(profile, z) {
const points = profile.points;
if (z >= points[0][0]) return points[0][1];
if (z <= points[points.length - 1][0]) {
return points[points.length - 1][1];
}
for (let i = 0; i < points.length - 1; i++) {
const z0 = points[i][0];
const z1 = points[i + 1][0];
if (z <= z0 && z >= z1) {
const t = (z0 - z) / (z0 - z1);
return THREE.MathUtils.lerp(points[i][1], points[i + 1][1], t);
}
}
return naturalHeight(profile.x, z);
}
function terrainHeight(x, z) {
const natural = naturalHeight(x, z);
let height = natural;
for (const profile of routeProfiles) {
if (Math.abs(x - profile.x) < 4.25) {
height = sampleProfile(profile, z) - 0.48;
break;
}
}
return Math.max(0, height);
}
const terrainGeometry = new THREE.BoxGeometry(3.96, 1, 3.96);
const terrainMaterials = [
new THREE.MeshStandardMaterial({ color: 0x9aab8b, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xa8b596, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x8fa184, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xb2b99a, roughness: 1 })
];
const terrainGroup = new THREE.Group();
terrainGroup.name = "Voxel terrain";
scene.add(terrainGroup);
for (let x = -30; x <= 30; x += 4) {
for (let z = -22; z <= 18; z += 4) {
const h = terrainHeight(x, z);
if (h < 0.02) continue;
const block = new THREE.Mesh(
terrainGeometry,
terrainMaterials[Math.abs(Math.round((x + z) / 4)) % terrainMaterials.length]
);
block.position.set(x, h / 2, z);
block.scale.y = h;
block.castShadow = true;
block.receiveShadow = true;
terrainGroup.add(block);
}
}
// Small context buildings beyond the modeled hillside.
const contextColors = [0xb8a98f, 0xc5b496, 0xa99b86, 0x8f9d91];
for (let i = 0; i < 18; i++) {
const side = i % 2 === 0 ? -1 : 1;
const x = side * (33 + (i % 3) * 2);
const z = -20 + Math.floor(i / 2) * 5;
const h = 3 + (i % 4) * 1.6;
const ground = naturalHeight(x, z);
const block = new THREE.Mesh(
new THREE.BoxGeometry(4.4, h, 4.4),
new THREE.MeshStandardMaterial({
color: contextColors[i % contextColors.length],
roughness: 0.95
})
);
block.position.set(x, ground + h / 2, z);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
}
// -------------------------------------------------------------------------
// Edge rendering
// -------------------------------------------------------------------------
const edgeVisuals = new Map();
function makeEdgeVisual(edge) {
const group = new THREE.Group();
const p0 = nodes[edge.a];
const p1 = nodes[edge.b];
const dx = p1.x - p0.x;
const dz = p1.z - p0.z;
const horizontalDistance = Math.hypot(dx, dz);
const angle = Math.atan2(dx, dz);
const material = new THREE.MeshStandardMaterial({
color: 0x9a9183,
roughness: 0.88,
metalness: 0.02,
emissive: 0x000000,
emissiveIntensity: 0
});
let mesh;
if (edge.kind === "stair" || edge.kind === "alternate") {
const count = edge.steps;
mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
material,
count
);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion().setFromAxisAngle(
new THREE.Vector3(0, 1, 0),
angle
);
const scale = new THREE.Vector3();
const position = new THREE.Vector3();
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const treadDepth = (horizontalDistance / count) * 1.08;
position.set(
THREE.MathUtils.lerp(p0.x, p1.x, t),
THREE.MathUtils.lerp(p0.y, p1.y, t) - 0.13,
THREE.MathUtils.lerp(p0.z, p1.z, t)
);
scale.set(2.65, 0.26, treadDepth);
matrix.compose(position, quaternion, scale);
mesh.setMatrixAt(i, matrix);
}
mesh.instanceMatrix.needsUpdate = true;
} else {
const count = Math.max(3, Math.ceil(horizontalDistance / 1.1));
mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
material,
count
);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion().setFromAxisAngle(
new THREE.Vector3(0, 1, 0),
angle
);
const scale = new THREE.Vector3();
const position = new THREE.Vector3();
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const segmentDepth = (horizontalDistance / count) * 1.08;
position.set(
THREE.MathUtils.lerp(p0.x, p1.x, t),
THREE.MathUtils.lerp(p0.y, p1.y, t) - 0.09,
THREE.MathUtils.lerp(p0.z, p1.z, t)
);
scale.set(2.45, 0.18, segmentDepth);
matrix.compose(position, quaternion, scale);
mesh.setMatrixAt(i, matrix);
}
mesh.instanceMatrix.needsUpdate = true;
}
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
scene.add(group);
const visual = {
group,
mesh,
material,
setColor(color, active = false) {
material.color.set(color);
material.emissive.set(color);
material.emissiveIntensity = active ? 0.12 : 0;
}
};
edgeVisuals.set(edge.id, visual);
return visual;
}
edges.forEach(makeEdgeVisual);
// -------------------------------------------------------------------------
// Buildings and entrance markers
// -------------------------------------------------------------------------
const pickables = [];
const entranceMarkers = [];
const labels = [];
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x5d625a,
roughness: 0.95
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xf4dfae,
roughness: 0.55,
emissive: 0x4d3c1d,
emissiveIntensity: 0.08
});
const darkWindowMaterial = new THREE.MeshStandardMaterial({
color: 0x426b75,
roughness: 0.45,
emissive: 0x183e46,
emissiveIntensity: 0.12
});
const doorMaterial = new THREE.MeshStandardMaterial({
color: 0x25443e,
roughness: 0.8
});
function addLabel(text, position, className = "place", visible = () => true) {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.textContent = text;
labelsLayer.appendChild(element);
labels.push({ element, position, visible });
return element;
}
buildingSpecs.forEach((spec, index) => {
const ground = naturalHeight(spec.x, spec.z);
const width = 5 + (index % 3 === 0 ? 0.8 : 0);
const depth = 5;
const height = 5.2 + ((index * 3) % 5);
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
new THREE.MeshStandardMaterial({
color: spec.color,
roughness: 0.86
})
);
body.position.set(spec.x, ground + height / 2, spec.z);
body.castShadow = true;
body.receiveShadow = true;
scene.add(body);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.45, 0.45, depth + 0.45),
roofMaterial
);
roof.position.set(spec.x, ground + height + 0.225, spec.z);
roof.castShadow = true;
roof.receiveShadow = true;
scene.add(roof);
const tank = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 1.25, 1.25),
new THREE.MeshStandardMaterial({
color: index % 2 ? 0x9f7b56 : 0x6d7c73,
roughness: 0.9
})
);
tank.position.set(spec.x + 0.8, ground + height + 1.1, spec.z - 0.7);
tank.castShadow = true;
scene.add(tank);
const frontZ = spec.z + depth / 2 + 0.04;
for (let floor = 0; floor < Math.floor(height / 2); floor++) {
for (const side of [-1, 1]) {
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.82, 0.95, 0.1),
(floor + index) % 3 === 0 ? darkWindowMaterial : windowMaterial
);
windowMesh.position.set(
spec.x + side * 1.15,
ground + 2.1 + floor * 1.8,
frontZ
);
windowMesh.castShadow = true;
scene.add(windowMesh);
}
}
const door = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 2.1, 0.18),
doorMaterial
);
door.position.set(spec.x, ground + 1.05, spec.z + depth / 2 + 0.13);
door.castShadow = true;
scene.add(door);
const awning = new THREE.Mesh(
new THREE.BoxGeometry(1.8, 0.25, 0.8),
new THREE.MeshStandardMaterial({
color: index % 2 ? 0xf0d38b : 0x9bc3b5,
roughness: 0.9
})
);
awning.position.set(spec.x, ground + 2.35, spec.z + depth / 2 + 0.38);
awning.castShadow = true;
scene.add(awning);
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0x55ad68,
roughness: 0.65,
emissive: 0x2f7d42,
emissiveIntensity: 0.25
});
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.48, 0.48),
markerMaterial
);
marker.position.set(spec.x, ground + 2.95, spec.z + depth / 2 + 0.45);
marker.rotation.set(0.4, Math.PI / 4, 0.4);
marker.castShadow = true;
scene.add(marker);
entranceMarkers.push(marker);
const hitProxy = new THREE.Mesh(
new THREE.BoxGeometry(1.5, 3.1, 1.5),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hitProxy.position.copy(marker.position);
hitProxy.userData.tooltip = `Entrance E${spec.number} · retained in both scenarios`;
scene.add(hitProxy);
pickables.push(hitProxy);
addLabel(
`E${spec.number}`,
marker.position.clone().add(new THREE.Vector3(0, 1.05, 0)),
"entrance"
);
});
// -------------------------------------------------------------------------
// Neighborhood connection portals
// -------------------------------------------------------------------------
const portalMaterial = new THREE.MeshStandardMaterial({
color: 0x3f7fac,
roughness: 0.65,
emissive: 0x24516d,
emissiveIntensity: 0.12
});
function addPortal(nodeId, title, axis) {
const p = nodes[nodeId];
const group = new THREE.Group();
group.position.copy(p);
const across = axis === "z"
? new THREE.Vector3(1, 0, 0)
: new THREE.Vector3(0, 0, 1);
for (const side of [-1, 1]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 3.2, 0.42),
portalMaterial
);
post.position.copy(across).multiplyScalar(side * 2.2);
post.position.y = 1.6;
post.castShadow = true;
group.add(post);
}
const beam = new THREE.Mesh(
new THREE.BoxGeometry(
axis === "z" ? 4.9 : 0.5,
0.48,
axis === "z" ? 0.5 : 4.9
),
portalMaterial
);
beam.position.y = 3.15;
beam.castShadow = true;
group.add(beam);
scene.add(group);
const hitProxy = new THREE.Mesh(
new THREE.BoxGeometry(5.5, 4, 5.5),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hitProxy.position.copy(p).add(new THREE.Vector3(0, 1.7, 0));
hitProxy.userData.tooltip = `${title} · neighborhood connection retained`;
scene.add(hitProxy);
pickables.push(hitProxy);
addLabel(
title,
p.clone().add(new THREE.Vector3(0, 4.25, 0)),
"place"
);
}
addPortal("southLink" in nodes ? "southLink" : "south", "South connection", "z");
addPortal("northLink", "Upper neighborhood", "z");
addPortal("eastLink", "East connector", "x");
addPortal("westLink", "West connector", "x");
addLabel(
"San Javier · lower plaza",
nodes.plaza.clone().add(new THREE.Vector3(0, 1.4, 0)),
"place"
);
addLabel(
"Upper hub",
nodes.upperHub.clone().add(new THREE.Vector3(0, 1.2, 0)),
"place"
);
// -------------------------------------------------------------------------
// Hypothetical closure marker
// -------------------------------------------------------------------------
const closureGroup = new THREE.Group();
const closedEdge = edgeById.get("lower__mainTop");
const closureMid = nodes.lower.clone().lerp(nodes.mainTop, 0.5);
closureGroup.position.copy(closureMid);
const closureMaterial = new THREE.MeshStandardMaterial({
color: 0xc83d3d,
roughness: 0.7,
emissive: 0x7d1717,
emissiveIntensity: 0.14
});
for (const side of [-1, 1]) {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 2.3, 0.28),
closureMaterial
);
post.position.set(side * 1.8, 0.85, 0);
post.castShadow = true;
closureGroup.add(post);
}
const barA = new THREE.Mesh(
new THREE.BoxGeometry(3.6, 0.2, 0.2),
closureMaterial
);
barA.rotation.z = Math.PI / 4;
barA.position.y = 1.15;
const barB = barA.clone();
barB.rotation.z = -Math.PI / 4;
closureGroup.add(barA, barB);
closureGroup.visible = false;
scene.add(closureGroup);
const closureLabel = addLabel(
"CLOSED · hypothetical",
closureMid.clone().add(new THREE.Vector3(0, 2.2, 0)),
"closure",
() => condition === "maintenance"
);
// -------------------------------------------------------------------------
// Animated route markers
// -------------------------------------------------------------------------
const flowMaterial = new THREE.MeshStandardMaterial({
color: 0x20a695,
roughness: 0.35,
emissive: 0x0d6e62,
emissiveIntensity: 0.7
});
const flowMarkers = [];
for (let i = 0; i < 7; i++) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.38, 0.38),
flowMaterial
);
marker.rotation.set(0.2, 0.7, 0.2);
marker.castShadow = true;
scene.add(marker);
flowMarkers.push(marker);
}
const routeLabelPosition = routeDefinitions.reference.labelPosition.clone();
const routeLabel = addLabel(
"Central stair · 136 treads",
routeLabelPosition,
"route"
);
function sampleRoute(routeName, t) {
const route = routeDefinitions[routeName];
const segments = [];
let total = 0;
for (let i = 0; i < route.nodes.length - 1; i++) {
const a = nodes[route.nodes[i]];
const b = nodes[route.nodes[i + 1]];
const length = a.distanceTo(b);
segments.push({ a, b, length });
total += length;
}
let distance = THREE.MathUtils.clamp(t, 0, 0.999999) * total;
for (const segment of segments) {
if (distance <= segment.length) {
const local = distance / segment.length;
return segment.a.clone().lerp(segment.b, local);
}
distance -= segment.length;
}
return nodes[route.nodes[route.nodes.length - 1]].clone();
}
// -------------------------------------------------------------------------
// Scenario state and UI
// -------------------------------------------------------------------------
let condition = "reference";
let selectedAlternate = "east";
let labelsVisible = true;
const colors = {
reference: 0x168579,
alternate: 0xe87532,
inactive: 0xaaa293,
entrance: 0x4c9b61,
connector: 0x397da9,
closed: 0xc83d3d
};
function activeEdgeIds(routeName) {
const route = routeDefinitions[routeName];
const ids = new Set();
for (let i = 0; i < route.nodes.length - 1; i++) {
ids.add(`${route.nodes[i]}__${route.nodes[i + 1]}`);
}
return ids;
}
function updateMetrics(routeName) {
const metrics = routeMetrics(routeName);
const reference = routeMetrics.reference;
const isAlternate = routeName !== "reference";
const stepDifference = metrics.steps - reference.steps;
document.querySelector("#steps-value").innerHTML =
`${metrics.steps} <small>treads</small>`;
document.querySelector("#steps-note").textContent =
`Vertical effort index: ${metrics.effort.toFixed(2)}×` +
(isAlternate ? ` · ${stepDifference > 0 ? "+" : ""}${stepDifference} treads` : "");
document.querySelector("#ascent-value").innerHTML =
`${metrics.ascent.toFixed(1)} <small>m</small>`;
document.querySelector("#distance-value").innerHTML =
`${Math.round(metrics.distance)} <small>m</small>`;
document.querySelector("#time-value").innerHTML =
`${metrics.time.toFixed(1)} <small>min</small>`;
document.querySelector("#route-name").textContent =
routeDefinitions[routeName].name;
const stepMetric = document.querySelector(".metric.wide");
stepMetric.classList.toggle("hypo", isAlternate);
const delta = document.querySelector("#delta-note");
if (isAlternate) {
delta.innerHTML =
`The climb remains ${metrics.ascent.toFixed(1)} m, but it is redistributed across ` +
`<strong>${metrics.steps} treads</strong> and a longer plan distance. ` +
`All entrances and neighborhood links remain connected.`;
} else {
delta.textContent =
"Select the explicitly hypothetical maintenance condition to compare alternate stair effort.";
}
}
function updateNetwork() {
const selectedRoute =
condition === "reference" ? "reference" : selectedAlternate;
const active = activeEdgeIds(selectedRoute);
edges.forEach((edge) => {
const visual = edgeVisuals.get(edge.id);
let color = colors.inactive;
let emphasized = false;
if (edge.kind === "entrance") {
color = colors.entrance;
emphasized = true;
} else if (edge.kind === "connector") {
color = colors.connector;
emphasized = true;
} else if (edge.id === "lower__mainTop") {
if (condition === "maintenance") {
color = colors.closed;
emphasized = true;
} else if (active.has(edge.id)) {
color = colors.reference;
emphasized = true;
}
} else if (active.has(edge.id)) {
color =
condition === "maintenance" ? colors.alternate : colors.reference;
emphasized = true;
} else if (
condition === "reference" &&
activeEdgeIds("reference").has(edge.id)
) {
color = colors.reference;
emphasized = true;
}
visual.setColor(color, emphasized);
});
closureGroup.visible = condition === "maintenance";
const metrics = routeMetrics(selectedRoute);
routeLabel.textContent =
`${routeDefinitions[selectedRoute].name} · ${metrics.steps} treads`;
routeLabel.classList.toggle("hypo", condition === "maintenance");
routeLabelPosition.copy(routeDefinitions[selectedRoute].labelPosition);
flowMaterial.color.set(
condition === "maintenance" ? colors.alternate : colors.reference
);
flowMaterial.emissive.set(
condition === "maintenance" ? 0x9d3c12 : 0x0d6e62
);
updateMetrics(selectedRoute);
const badge = document.querySelector("#scenario-badge");
badge.textContent =
condition === "reference" ? "Reference" : "Hypothetical";
badge.classList.toggle("hypothetical", condition === "maintenance");
document.querySelector("#reference-button").classList.toggle(
"active",
condition === "reference"
);
document.querySelector("#maintenance-button").classList.toggle(
"active",
condition === "maintenance"
);
document.querySelector("#reference-button").setAttribute(
"aria-pressed",
String(condition === "reference")
);
document.querySelector("#maintenance-button").setAttribute(
"aria-pressed",
String(condition === "maintenance")
);
document.querySelector("#scenario-description").textContent =
condition === "reference"
? "The central stair is open in the reference network. Alternate switchbacks remain visible as muted context."
: "A central stair segment is closed for a hypothetical works window. One alternate remains selected; neither alternate removes an entrance or neighborhood connection.";
document.querySelectorAll(".route-option").forEach((button) => {
const route = button.dataset.route;
const isSelected = route === selectedRoute;
button.classList.toggle("active", isSelected);
button.classList.toggle("hypo-active", isSelected && condition === "maintenance");
button.setAttribute("aria-pressed", String(isSelected));
button.disabled =
condition === "reference" ? route !== "reference" : route === "reference";
});
}
document.querySelector("#reference-button").addEventListener("click", () => {
condition = "reference";
updateNetwork();
});
document.querySelector("#maintenance-button").addEventListener("click", () => {
condition = "maintenance";
updateNetwork();
});
document.querySelectorAll(".route-option").forEach((button) => {
button.addEventListener("click", () => {
const route = button.dataset.route;
if (condition === "reference" && route !== "reference") return;
if (condition === "maintenance" && route === "reference") return;
if (route === "east" || route === "west") {
selectedAlternate = route;
}
updateNetwork();
});
});
document.querySelector("#labels-button").addEventListener("click", (event) => {
labelsVisible = !labelsVisible;
labelsLayer.classList.toggle("hidden", !labelsVisible);
event.currentTarget.setAttribute("aria-pressed", String(labelsVisible));
});
// -------------------------------------------------------------------------
// Hover information
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function hideTooltip() {
tooltip.style.display = "none";
}
function updateHover(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
const hit = hits[0].object;
tooltip.textContent = hit.userData.tooltip;
tooltip.style.display = "block";
const x = Math.min(
window.innerWidth - 235,
Math.max(8, event.clientX + 14)
);
const y = Math.min(
window.innerHeight - 55,
Math.max(8, event.clientY + 14)
);
tooltip.style.left = `${x}px`;
tooltip.style.top = `${y}px`;
renderer.domElement.style.cursor = "help";
} else {
hideTooltip();
renderer.domElement.style.cursor = "grab";
}
}
// -------------------------------------------------------------------------
// Label projection and animation loop
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach((label) => {
if (!label.visible()) {
label.element.style.display = "none";
return;
}
projected.copy(label.position).project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
projected.x < -1.2 ||
projected.x > 1.2 ||
projected.y < -1.2 ||
projected.y > 1.2
) {
label.element.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.display = "block";
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
});
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const activeRoute =
condition === "reference" ? "reference" : selectedAlternate;
if (!reducedMotion) {
flowMarkers.forEach((marker, index) => {
const t =
(elapsed * 0.055 + index / flowMarkers.length) % 1;
const position = sampleRoute(activeRoute, t);
marker.position.copy(position).add(new THREE.Vector3(0, 0.38, 0));
marker.rotation.x += 0.012;
marker.rotation.y += 0.018;
});
entranceMarkers.forEach((marker, index) => {
const pulse = 1 + Math.sin(elapsed * 2.2 + index * 0.7) * 0.08;
marker.scale.setScalar(pulse);
marker.rotation.y += 0.005;
});
}
updateCamera();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateNetwork();
resize();
animate();
</script>
</body>
</html>
```