Prompt specification
Build or customize the Three.js 3D scene "Compare routes when a checkpoint opens" 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 routes when a checkpoint opens
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-routes-when-a-checkpoint-opens-x2420
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring the opening of the Berlin Wall in 1989. Let users toggle a simplified crossing in a neighborhood graph. Show changed walking distances and connected areas while separating geometric effects from wider reunification history. Low-poly.
Working Three.js Starter (compare-routes-when-a-checkpoint-opens-x2420):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One Crossing, Two Graphs — Berlin 1989</title>
<style>
:root {
--ink: #142b31;
--muted: #627478;
--paper: #eef0eb;
--panel: #12272d;
--panel-2: #1a343b;
--line: rgba(255, 255, 255, 0.12);
--west: #4f8db3;
--east: #db795a;
--open: #60c49a;
--closed: #e07861;
--gold: #ffd166;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #d9dfdb;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, select { font: inherit; }
#app, #stage, #labels {
position: absolute;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#labels {
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.scrim {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(180deg, rgba(236, 239, 234, 0.56), transparent 28%),
radial-gradient(circle at 42% 48%, transparent 45%, rgba(26, 46, 47, 0.08));
}
.masthead {
position: absolute;
z-index: 10;
top: 28px;
left: 30px;
width: min(570px, calc(100vw - 410px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #496066;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 29px;
height: 2px;
content: "";
background: var(--east);
}
h1 {
max-width: 540px;
margin: 0;
font-size: clamp(34px, 4vw, 60px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.deck {
max-width: 500px;
margin: 15px 0 0;
color: #496066;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: absolute;
z-index: 20;
top: 20px;
right: 20px;
bottom: 20px;
width: 360px;
padding: 21px;
overflow: auto;
color: #edf5f3;
background: rgba(18, 39, 45, 0.96);
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 22px;
box-shadow: 0 22px 70px rgba(20, 43, 49, 0.25);
scrollbar-width: thin;
scrollbar-color: #496267 transparent;
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
color: #9db0b2;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 7px;
}
.live::before {
width: 7px;
height: 7px;
content: "";
border-radius: 50%;
background: var(--open);
box-shadow: 0 0 0 5px rgba(96, 196, 154, 0.1);
}
.panel h2 {
margin: 10px 0 4px;
font-size: 24px;
letter-spacing: -0.035em;
}
.subtle {
margin: 0;
color: #a8b9ba;
font-size: 12px;
line-height: 1.5;
}
.gate-control {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin: 20px 0 16px;
padding: 14px;
background: var(--panel-2);
border: 1px solid var(--line);
border-radius: 15px;
}
.gate-label {
display: flex;
align-items: center;
gap: 10px;
font-size: 13px;
font-weight: 750;
}
.gate-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--closed);
box-shadow: 0 0 0 5px rgba(224, 120, 97, 0.1);
transition: 300ms ease;
}
.open .gate-dot {
background: var(--open);
box-shadow: 0 0 0 5px rgba(96, 196, 154, 0.1);
}
.switch {
position: relative;
flex: 0 0 auto;
width: 50px;
height: 29px;
padding: 0;
cursor: pointer;
background: #3b4d51;
border: 0;
border-radius: 20px;
transition: 250ms ease;
}
.switch::after {
position: absolute;
top: 4px;
left: 4px;
width: 21px;
height: 21px;
content: "";
background: #eef2ee;
border-radius: 50%;
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.22);
transition: 250ms ease;
}
.switch[aria-checked="true"] {
background: #398c70;
}
.switch[aria-checked="true"]::after {
transform: translateX(21px);
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
color: #91a4a6;
font-size: 11px;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
color: #f2a38f;
font-weight: 750;
}
.status::before {
width: 7px;
height: 7px;
content: "";
border-radius: 50%;
background: currentColor;
}
.status.open {
color: var(--open);
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 15px;
}
.metric {
min-height: 98px;
padding: 13px;
background: rgba(255, 255, 255, 0.045);
border: 1px solid var(--line);
border-radius: 13px;
}
.metric.wide { grid-column: 1 / -1; }
.metric-label {
display: block;
margin-bottom: 7px;
color: #9eb0b2;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
font-size: 26px;
font-weight: 760;
letter-spacing: -0.035em;
}
.metric small {
display: block;
margin-top: 4px;
color: #91a5a6;
font-size: 10px;
line-height: 1.35;
}
.field-label {
display: block;
margin: 17px 0 7px;
color: #9eb0b2;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 10px 12px;
color: #eef5f3;
cursor: pointer;
background: #203a40;
border: 1px solid var(--line);
border-radius: 10px;
outline: none;
}
select:focus-visible,
button:focus-visible {
outline: 2px solid var(--gold);
outline-offset: 2px;
}
.component-strip {
display: grid;
grid-template-columns: 1fr 34px 1fr;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 12px;
background: rgba(0, 0, 0, 0.11);
border-radius: 12px;
}
.mini-cluster {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.mini-dot {
width: 9px;
height: 9px;
justify-self: center;
border-radius: 50%;
background: var(--west);
box-shadow: 0 0 0 3px rgba(79, 141, 179, 0.11);
}
.mini-cluster.east .mini-dot {
background: var(--east);
box-shadow: 0 0 0 3px rgba(219, 121, 90, 0.11);
}
.mini-gate {
position: relative;
height: 42px;
}
.mini-gate::before {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 3px;
content: "";
background: #d9dfdb;
transform: translateX(-50%);
transition: 300ms ease;
}
.mini-gate::after {
position: absolute;
top: 50%;
left: 50%;
width: 27px;
height: 3px;
content: "";
background: var(--closed);
border-radius: 4px;
transform: translate(-50%, -50%);
transition: 300ms ease;
}
.component-strip.open .mini-gate::before {
background: var(--open);
}
.component-strip.open .mini-gate::after {
background: var(--open);
box-shadow: 0 0 10px rgba(96, 196, 154, 0.7);
}
.component-caption {
margin-top: 7px;
color: #91a4a6;
font-size: 10px;
text-align: center;
}
.comparison {
margin-top: 17px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
}
.comparison-title {
padding: 10px 12px;
color: #aebfc0;
background: rgba(255, 255, 255, 0.035);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
th, td {
padding: 8px 9px;
text-align: right;
border-top: 1px solid var(--line);
}
th:first-child, td:first-child { text-align: left; }
th { color: #84999b; font-weight: 700; }
td { color: #bcc9c9; }
td.active { color: var(--gold); font-weight: 750; }
td.no-route { color: #ef9a84; }
.interpretation {
display: grid;
gap: 9px;
margin-top: 17px;
}
.note {
padding: 13px;
background: rgba(255, 255, 255, 0.04);
border: 1px solid var(--line);
border-left: 3px solid var(--west);
border-radius: 10px;
}
.note.history { border-left-color: var(--east); }
.note h3 {
margin: 0 0 5px;
font-size: 11px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.note p {
margin: 0;
color: #a9b9ba;
font-size: 10px;
line-height: 1.55;
}
.timeline {
margin-top: 12px;
padding-left: 11px;
border-left: 1px solid #51676b;
}
.timeline div {
position: relative;
margin: 0 0 9px;
color: #a9b9ba;
font-size: 10px;
line-height: 1.4;
}
.timeline div::before {
position: absolute;
top: 4px;
left: -15px;
width: 6px;
height: 6px;
content: "";
background: #8aa2a3;
border-radius: 50%;
}
.timeline time {
display: block;
color: #e4ece9;
font-weight: 750;
}
.panel-footnote {
margin: 14px 0 0;
color: #71888a;
font-size: 9px;
line-height: 1.5;
}
.world-label {
position: absolute;
z-index: 3;
padding: 4px 7px;
color: rgba(20, 43, 49, 0.76);
background: rgba(239, 242, 236, 0.78);
border: 1px solid rgba(20, 43, 49, 0.12);
border-radius: 6px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
}
.node-label {
position: absolute;
z-index: 5;
max-width: 130px;
padding: 4px 7px;
overflow: hidden;
color: #263f44;
cursor: pointer;
background: rgba(245, 246, 240, 0.88);
border: 1px solid rgba(25, 52, 57, 0.15);
border-radius: 6px;
box-shadow: 0 3px 10px rgba(31, 53, 55, 0.08);
font-size: 9px;
font-weight: 720;
line-height: 1.15;
text-overflow: ellipsis;
white-space: nowrap;
pointer-events: auto;
transform: translate(-50%, -50%);
}
.node-label::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 5px;
content: "";
vertical-align: 1px;
background: var(--west);
border-radius: 50%;
}
.node-label.east::before { background: var(--east); }
.node-label.selected {
color: #172d32;
background: #fff1bd;
border-color: #d9b84b;
box-shadow: 0 3px 14px rgba(104, 84, 20, 0.16);
}
.node-label.source::after {
margin-left: 5px;
color: #557075;
content: "START";
font-size: 7px;
letter-spacing: 0.08em;
}
.legend {
position: absolute;
z-index: 10;
bottom: 24px;
left: 30px;
display: flex;
align-items: center;
gap: 17px;
padding: 10px 13px;
color: #52696c;
background: rgba(240, 242, 237, 0.78);
border: 1px solid rgba(20, 43, 49, 0.12);
border-radius: 11px;
backdrop-filter: blur(8px);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--west);
}
.legend i.east { background: var(--east); }
.legend i.route { background: var(--gold); }
.legend i.wall { width: 12px; height: 5px; border-radius: 1px; background: #7f817b; }
.reset {
position: absolute;
z-index: 11;
right: 400px;
bottom: 24px;
padding: 9px 12px;
color: #355157;
cursor: pointer;
background: rgba(240, 242, 237, 0.86);
border: 1px solid rgba(20, 43, 49, 0.15);
border-radius: 9px;
font-size: 10px;
font-weight: 700;
}
@media (max-width: 900px) {
.masthead {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 { font-size: 36px; }
.deck { max-width: 460px; font-size: 12px; }
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
padding: 17px;
border-radius: 18px;
}
.legend, .reset { display: none; }
.node-label { font-size: 8px; }
}
</style>
</head>
<body>
<main id="app">
<div id="stage"></div>
<div class="scrim"></div>
<div id="labels"></div>
<header class="masthead">
<div class="eyebrow">Berlin · 9 November 1989</div>
<h1>One crossing,<br />two graphs.</h1>
<p class="deck">
Open a simplified pedestrian crossing in a schematic neighborhood.
The graph changes before the wider story of the Wall’s fall and
German reunification can be told.
</p>
</header>
<aside class="panel" aria-label="Crossing model controls and interpretation">
<div class="panel-kicker">
<span>Crossing point 01</span>
<span class="live">Live model</span>
</div>
<h2>Bornholmer Straße</h2>
<p class="subtle">
One schematic border point. Not to scale and not a reconstruction of
the full city network.
</p>
<div class="gate-control">
<div class="gate-label">
<span class="gate-dot"></span>
<span>Open the crossing</span>
</div>
<button
id="gateToggle"
class="switch"
type="button"
role="switch"
aria-checked="false"
aria-label="Open the schematic crossing"
></button>
</div>
<div class="status-row">
<span>Bornholmer Straße</span>
<span id="gateStatus" class="status" aria-live="polite">Crossing closed</span>
</div>
<div class="metric-grid">
<div class="metric">
<span class="metric-label">Connected graph areas</span>
<strong id="areaMetric">2</strong>
<small id="areaDetail">After opening: 1 connected area</small>
</div>
<div class="metric">
<span class="metric-label">Reachable districts</span>
<strong id="reachMetric">6 / 12</strong>
<small id="reachDetail">After opening: all 12 districts</small>
</div>
<div class="metric wide">
<span class="metric-label">Illustrative walk from Ku’damm</span>
<strong id="walkMetric">No route</strong>
<small id="walkDetail">After opening: a finite walking route</small>
</div>
</div>
<label class="field-label" for="destination">Walking destination</label>
<select id="destination"></select>
<div id="componentStrip" class="component-strip" aria-hidden="true">
<div class="mini-cluster">
<i class="mini-dot"></i><i class="mini-dot"></i><i class="mini-dot"></i>
<i class="mini-dot"></i><i class="mini-dot"></i><i class="mini-dot"></i>
</div>
<div class="mini-gate"></div>
<div class="mini-cluster east">
<i class="mini-dot"></i><i class="mini-dot"></i><i class="mini-dot"></i>
<i class="mini-dot"></i><i class="mini-dot"></i><i class="mini-dot"></i>
</div>
</div>
<div id="componentCaption" class="component-caption">
2 separated connected components
</div>
<div class="comparison">
<div class="comparison-title">Distance comparison · illustrative km</div>
<table>
<thead>
<tr>
<th>Destination</th>
<th>Closed</th>
<th>Open</th>
</tr>
</thead>
<tbody id="comparisonBody"></tbody>
</table>
</div>
<div class="interpretation">
<section class="note">
<h3>Geometric layer</h3>
<p>
The switch adds one graph edge. It changes reachability and the
shortest-path calculation inside this model. It does not simulate
permits, checkpoints, crowding, or every crossing that existed.
</p>
</section>
<section class="note history">
<h3>Wider historical layer</h3>
<p>
A single gate is not a metaphor for the entire transition. The
border announcement, mass crossings, Wall demolition, and formal
reunification were related but distinct events.
</p>
<div class="timeline">
<div>
<time>9 Nov 1989</time>
An imprecise press briefing helped trigger crowds and opened
border crossings that night.
</div>
<div>
<time>13 Jun 1990</time>
Formal demolition of the Wall begins.
</div>
<div>
<time>3 Oct 1990</time>
German reunification takes effect.
</div>
</div>
</section>
</div>
<p class="panel-footnote">
“Connected area” means a connected component of this stylized pedestrian
graph, not an administrative district. Edge weights and distances are
illustrative rather than geographically exact.
</p>
</aside>
<div class="legend" aria-hidden="true">
<span><i></i> West-side node</span>
<span><i class="east"></i> East-side node</span>
<span><i class="route"></i> Shortest route</span>
<span><i class="wall"></i> Wall</span>
</div>
<button id="resetView" class="reset" type="button">Reset camera</button>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Schematic graph data
// -------------------------------------------------------------------------
const nodes = [
{ id: "kurf", name: "Kurfürstendamm", side: "west", x: -18, z: -6 },
{ id: "moeckern", name: "Möckernbrücke", side: "west", x: -10, z: 1 },
{ id: "sonnenallee",name: "Sonnenallee", side: "west", x: -7, z: -11 },
{ id: "zoo", name: "Zoologischer Garten", side: "west", x: -15, z: 10 },
{ id: "charlotten", name: "Charlottenburg", side: "west", x: -5, z: 11 },
{ id: "invalid", name: "Invalidenstraße", side: "west", x: -3, z: 2 },
{ id: "bornholmer", name: "Bornholmer Straße", side: "east", x: 7, z: 6 },
{ id: "alex", name: "Alexanderplatz", side: "east", x: 11, z: -4 },
{ id: "mitte", name: "Mitte", side: "east", x: 8, z: -9 },
{ id: "prenzlauer", name: "Prenzlauer Berg", side: "east", x: 15, z: 10 },
{ id: "marzahn", name: "Marzahn", side: "east", x: 20, z: -9 },
{ id: "ahrensfelde",name: "Ahrensfelde", side: "east", x: 19, z: 9 }
];
const edges = [
{ a: "kurf", b: "moeckern", w: 3.6 },
{ a: "kurf", b: "sonnenallee",w: 6.2 },
{ a: "moeckern", b: "sonnenallee",w: 5.4 },
{ a: "moeckern", b: "zoo", w: 4.2 },
{ a: "zoo", b: "charlotten", w: 3.8 },
{ a: "charlotten", b: "invalid", w: 3.7 },
{ a: "moeckern", b: "invalid", w: 2.1 },
{ a: "invalid", b: "bornholmer", w: 2.8, crossing: true },
{ a: "bornholmer", b: "prenzlauer", w: 4.1 },
{ a: "bornholmer", b: "ahrensfelde",w: 5.4 },
{ a: "bornholmer", b: "alex", w: 4.8 },
{ a: "bornholmer", b: "mitte", w: 7.1 },
{ a: "alex", b: "mitte", w: 3.3 },
{ a: "alex", b: "prenzlauer", w: 8.0 },
{ a: "alex", b: "marzahn", w: 5.0 },
{ a: "mitte", b: "marzahn", w: 5.7 },
{ a: "prenzlauer", b: "ahrensfelde",w: 4.2 }
];
const nodeById = Object.fromEntries(nodes.map(n => [n.id, n]));
const sourceId = "kurf";
const comparisonTargets = ["alex", "mitte", "prenzlauer", "ahrensfelde"];
const $ = id => document.getElementById(id);
const gateToggle = $("gateToggle");
const gateStatus = $("gateStatus");
const destination = $("destination");
const areaMetric = $("areaMetric");
const areaDetail = $("areaDetail");
const reachMetric = $("reachMetric");
const reachDetail = $("reachDetail");
const walkMetric = $("walkMetric");
const walkDetail = $("walkDetail");
const componentStrip = $("componentStrip");
const componentCaption = $("componentCaption");
let gateOpen = false;
let gateBlend = 0;
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const stage = $("stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce2de);
scene.fog = new THREE.Fog(0xdce2de, 52, 88);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly schematic of Berlin in 1989 with a toggleable crossing"
);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
160
);
const cameraState = {
radius: 47,
phi: 0.82,
theta: 0.64,
target: new THREE.Vector3(1.5, 0, 0)
};
const hemisphere = new THREE.HemisphereLight(0xf7fbf4, 0x778078, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d5, 3.0);
sun.position.set(-19, 31, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -35;
sun.shadow.camera.right = 35;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7d9e5, 0.75);
fill.position.set(22, 12, -19);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and low-poly helpers
// -------------------------------------------------------------------------
const palette = {
west: new THREE.Color(0x4f8db3),
east: new THREE.Color(0xdb795a),
open: new THREE.Color(0x60c49a),
closed: new THREE.Color(0xe07861),
gold: new THREE.Color(0xffd166)
};
const buildingColors = [
0xd8c8b2, 0xc8d2c8, 0xb9c5c2, 0xd7d5c7,
0xcbbcae, 0xbacbd2, 0xd5d9d2, 0xb9a99d
];
const roofColors = [
0x6f7773, 0x805f52, 0x667a82, 0x756f66
];
let randomSeed = 1989;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.02,
...options
});
}
function setShadow(mesh, cast = true, receive = true) {
mesh.castShadow = cast;
mesh.receiveShadow = receive;
return mesh;
}
function makeGroundText(text, color = "#40585c") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = color;
context.font = "800 58px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.letterSpacing = "7px";
context.fillText(text, canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(11, 1.85),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
opacity: 0.55
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = 0.035;
return mesh;
}
// -------------------------------------------------------------------------
// Ground, zones, roads, buildings, trees
// -------------------------------------------------------------------------
const base = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(50, 0.7, 34),
standard(0xd8d4c8)
),
false,
true
);
base.position.y = -0.38;
scene.add(base);
const westZone = new THREE.Mesh(
new THREE.PlaneGeometry(24.5, 33.4),
new THREE.MeshBasicMaterial({
color: 0x93bad0,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
westZone.rotation.x = -Math.PI / 2;
westZone.position.set(-12.25, 0.005, 0);
scene.add(westZone);
const eastZone = new THREE.Mesh(
new THREE.PlaneGeometry(24.5, 33.4),
new THREE.MeshBasicMaterial({
color: 0xe7aa8c,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
eastZone.rotation.x = -Math.PI / 2;
eastZone.position.set(12.25, 0.005, 0);
scene.add(eastZone);
const westText = makeGroundText("WEST BERLIN");
westText.position.set(-12.5, 0.04, -15.15);
scene.add(westText);
const eastText = makeGroundText("EAST BERLIN");
eastText.position.set(12.5, 0.04, -15.15);
scene.add(eastText);
function addRoad(a, b, crossing = false) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const angle = Math.atan2(dz, dx);
const underlay = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.075, 1.32),
standard(crossing ? 0xbebbb3 : 0xc6c5bc)
);
underlay.position.set((a.x + b.x) / 2, 0.05, (a.z + b.z) / 2);
underlay.rotation.y = -angle;
underlay.receiveShadow = true;
scene.add(underlay);
const surface = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.065, crossing ? 1.02 : 1.08),
standard(crossing ? 0xddd8cc : 0xeeeae0)
);
surface.position.set((a.x + b.x) / 2, 0.105, (a.z + b.z) / 2);
surface.rotation.y = -angle;
surface.receiveShadow = true;
scene.add(surface);
}
edges.forEach(edge => addRoad(
nodeById[edge.a],
nodeById[edge.b],
Boolean(edge.crossing)
));
function addBuilding(x, z, width, depth, height, colorIndex) {
const body = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standard(buildingColors[colorIndex % buildingColors.length])
)
);
body.position.set(x, height / 2, z);
body.rotation.y = (random() - 0.5) * 0.22;
scene.add(body);
const roof = setShadow(
new THREE.Mesh(
new THREE.ConeGeometry(0.75, 0.58, 4),
standard(roofColors[colorIndex % roofColors.length])
)
);
roof.scale.set(width * 0.68, 1, depth * 0.68);
roof.rotation.y = Math.PI / 4;
roof.position.set(x, height + 0.29, z);
scene.add(roof);
}
function addTree(x, z, scale = 1) {
if (Math.abs(x) < 1.0) return;
const trunk = setShadow(
new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.12, 0.9 * scale, 5),
standard(0x76614d)
)
);
trunk.position.set(x, 0.45 * scale, z);
scene.add(trunk);
const crown = setShadow(
new THREE.Mesh(
new THREE.ConeGeometry(0.57 * scale, 1.35 * scale, 5),
standard(random() > 0.5 ? 0x627f61 : 0x78916c)
)
);
crown.position.set(x, 1.45 * scale, z);
scene.add(crown);
}
nodes.forEach((node, nodeIndex) => {
const count = nodeIndex % 2 === 0 ? 5 : 4;
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2 + random() * 0.65;
const radius = 1.55 + random() * 1.65;
const x = node.x + Math.cos(angle) * radius;
const z = node.z + Math.sin(angle) * radius;
if (Math.abs(x) < 1.15) continue;
const width = 0.75 + random() * 1.25;
const depth = 0.75 + random() * 1.15;
const height = 1.2 + random() * 2.6;
addBuilding(x, z, width, depth, height, nodeIndex + i);
}
for (let i = 0; i < 2; i++) {
const angle = random() * Math.PI * 2;
const radius = 3.0 + random() * 0.9;
addTree(
node.x + Math.cos(angle) * radius,
node.z + Math.sin(angle) * radius,
0.72 + random() * 0.35
);
}
});
// A small period car near the western approach.
const car = new THREE.Group();
const carBody = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(1.55, 0.38, 0.78),
standard(0xd9d3bd)
)
);
carBody.position.y = 0.36;
car.add(carBody);
const carRoof = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.34, 0.68),
standard(0xc7c0ad)
)
);
carRoof.position.set(-0.12, 0.68, 0);
car.add(carRoof);
[-0.47, 0.47].forEach(x => {
[-0.39, 0.39].forEach(z => {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.16, 0.11, 8),
standard(0x353837)
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.2, z);
car.add(wheel);
});
});
car.position.set(-6.7, 0.02, 1.45);
car.rotation.y = -Math.atan2(1, 7);
scene.add(car);
// -------------------------------------------------------------------------
// Wall, checkpoint, and animated barrier
// -------------------------------------------------------------------------
const wallMaterials = [
standard(0xaaa99e),
standard(0xb8b5a9),
standard(0x9f9e94),
standard(0xc1bdaf)
];
function buildWall(startZ, endZ) {
let z = startZ;
let index = 0;
while (z < endZ - 0.05) {
const length = Math.min(2.25, endZ - z);
const slab = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.76, 2.72, Math.max(0.1, length - 0.08)),
wallMaterials[index % wallMaterials.length]
)
);
slab.position.set(
(random() - 0.5) * 0.07,
1.34,
z + length / 2
);
scene.add(slab);
const cap = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.92, 0.16, Math.max(0.1, length - 0.06)),
standard(0x8f8e85)
)
);
cap.position.set(slab.position.x, 2.76, slab.position.z);
scene.add(cap);
if (index % 3 === 0) {
const rib = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.92, 2.95, 0.14),
standard(0x85847c)
)
);
rib.position.set(0, 1.45, z + 0.1);
scene.add(rib);
}
z += length + 0.06;
index++;
}
}
buildWall(-16.3, 1.0);
buildWall(5.4, 16.3);
function addCheckpoint(x, z, rotation = 0) {
const group = new THREE.Group();
const base = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(1.35, 1.45, 1.25),
standard(0x7d817b)
)
);
base.position.y = 0.725;
group.add(base);
const roof = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(1.58, 0.17, 1.48),
standard(0x555e5d)
)
);
roof.position.y = 1.52;
group.add(roof);
const windowMaterial = standard(0x273e43, {
roughness: 0.35,
metalness: 0.12
});
[-0.38, 0.38].forEach(wx => {
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.33, 0.43, 0.04),
windowMaterial
);
windowMesh.position.set(wx, 0.98, 0.64);
group.add(windowMesh);
});
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
}
addCheckpoint(-1.7, 6.2, -0.25);
addCheckpoint(1.75, 0.15, 0.2);
const crossingStart = nodeById.invalid;
const crossingEnd = nodeById.bornholmer;
const crossingDirection = new THREE.Vector3(
crossingEnd.x - crossingStart.x,
0,
crossingEnd.z - crossingStart.z
);
const crossingLength = crossingDirection.length();
crossingDirection.normalize();
const crossingAngle = Math.atan2(
crossingEnd.z - crossingStart.z,
crossingEnd.x - crossingStart.x
);
const crossingPoint = new THREE.Vector3(0, 0, 3.2);
const barrierYaw = new THREE.Group();
barrierYaw.position.copy(crossingPoint);
barrierYaw.rotation.y = crossingAngle - Math.PI / 2;
scene.add(barrierYaw);
const barrierBase = setShadow(
new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.24, 1.15, 8),
standard(0x4c5555)
)
);
barrierBase.position.set(-2.3, 0.58, 0);
barrierYaw.add(barrierBase);
const barrierHinge = new THREE.Group();
barrierHinge.position.set(-2.3, 1.15, 0);
barrierYaw.add(barrierHinge);
const barrierArm = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(4.6, 0.16, 0.16),
standard(0xe4dfd2)
)
);
barrierArm.position.x = 2.3;
barrierHinge.add(barrierArm);
for (let i = 0; i < 7; i++) {
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.27, 0.175, 0.175),
standard(0xba5549)
);
stripe.position.x = 0.35 + i * 0.63;
barrierHinge.add(stripe);
}
// -------------------------------------------------------------------------
// Graph nodes, projected labels, and graph lines
// -------------------------------------------------------------------------
const nodeMeshes = [];
const nodeRings = [];
const labelsLayer = $("labels");
const nodeLabels = new Map();
nodes.forEach(node => {
const color = node.side === "west" ? palette.west : palette.east;
const marker = setShadow(
new THREE.Mesh(
new THREE.CylinderGeometry(0.57, 0.67, 0.35, 6),
standard(color.getHex(), {
roughness: 0.58,
emissive: color.getHex(),
emissiveIntensity: 0.05
})
)
);
marker.position.set(node.x, 0.38, node.z);
marker.userData.nodeId = node.id;
scene.add(marker);
nodeMeshes.push(marker);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.075, 4, 18),
new THREE.MeshBasicMaterial({
color: color.getHex(),
transparent: true,
opacity: 0.92
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(node.x, 0.22, node.z);
scene.add(ring);
nodeRings.push({ mesh: ring, id: node.id });
const label = document.createElement("button");
label.type = "button";
label.className = `node-label ${node.side}`;
if (node.id === sourceId) label.classList.add("source");
label.textContent = node.name;
label.setAttribute("aria-label", `Choose ${node.name} as walking destination`);
label.addEventListener("click", event => {
event.stopPropagation();
if (node.id === sourceId) return;
destination.value = node.id;
updateUI();
});
labelsLayer.appendChild(label);
nodeLabels.set(node.id, label);
});
let crossingLine;
edges.forEach(edge => {
const a = nodeById[edge.a];
const b = nodeById[edge.b];
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(a.x, 0.27, a.z),
new THREE.Vector3(b.x, 0.27, b.z)
]);
if (edge.crossing) {
crossingLine = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color: palette.closed.getHex(),
dashSize: 0.7,
gapSize: 0.42,
transparent: true,
opacity: 0.95
})
);
crossingLine.computeLineDistances();
crossingLine.renderOrder = 4;
scene.add(crossingLine);
} else {
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x496c70,
transparent: true,
opacity: 0.55
})
);
scene.add(line);
}
});
// -------------------------------------------------------------------------
// Shortest-path graph calculations
// -------------------------------------------------------------------------
function buildAdjacency(open) {
const adjacency = Object.fromEntries(nodes.map(node => [node.id, []]));
edges.forEach(edge => {
if (edge.crossing && !open) return;
adjacency[edge.a].push({ id: edge.b, weight: edge.w });
adjacency[edge.b].push({ id: edge.a, weight: edge.w });
});
return adjacency;
}
function dijkstra(open) {
const adjacency = buildAdjacency(open);
const distance = Object.fromEntries(nodes.map(node => [node.id, Infinity]));
const previous = {};
const visited = new Set();
distance[sourceId] = 0;
while (true) {
let current = null;
let smallest = Infinity;
for (const node of nodes) {
if (!visited.has(node.id) && distance[node.id] < smallest) {
smallest = distance[node.id];
current = node.id;
}
}
if (current === null) break;
visited.add(current);
adjacency[current].forEach(neighbor => {
const nextDistance = distance[current] + neighbor.weight;
if (nextDistance < distance[neighbor.id]) {
distance[neighbor.id] = nextDistance;
previous[neighbor.id] = current;
}
});
}
return {
distance,
previous,
reachable: visited.size
};
}
function countComponents(open) {
const adjacency = buildAdjacency(open);
const visited = new Set();
let components = 0;
for (const node of nodes) {
if (visited.has(node.id)) continue;
components++;
const stack = [node.id];
visited.add(node.id);
while (stack.length) {
const current = stack.pop();
adjacency[current].forEach(neighbor => {
if (!visited.has(neighbor.id)) {
visited.add(neighbor.id);
stack.push(neighbor.id);
}
});
}
}
return components;
}
function reconstructPath(previous, target) {
const path = [];
let current = target;
while (current) {
path.unshift(current);
if (current === sourceId) break;
current = previous[current];
}
return path[0] === sourceId ? path : [];
}
// -------------------------------------------------------------------------
// Route highlight and moving people
// -------------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeMaterial = new THREE.MeshBasicMaterial({
color: palette.gold.getHex()
});
const routePulse = new THREE.Mesh(
new THREE.SphereGeometry(0.24, 8, 6),
new THREE.MeshBasicMaterial({
color: 0xffe59a,
transparent: true,
opacity: 0.95
})
);
routePulse.visible = false;
scene.add(routePulse);
let activeRoutePoints = [];
function clearRoute() {
while (routeGroup.children.length) {
const child = routeGroup.children[0];
routeGroup.remove(child);
if (child.geometry) child.geometry.dispose();
}
activeRoutePoints = [];
routePulse.visible = false;
}
function rebuildRoute(result, target) {
clearRoute();
if (!gateOpen || target === sourceId) return;
const path = reconstructPath(result.previous, target);
if (path.length < 2) return;
for (let i = 0; i < path.length - 1; i++) {
const a = nodeById[path[i]];
const b = nodeById[path[i + 1]];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const segment = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.085, 0.19),
routeMaterial
);
segment.position.set((a.x + b.x) / 2, 0.31, (a.z + b.z) / 2);
segment.rotation.y = -Math.atan2(dz, dx);
segment.renderOrder = 5;
routeGroup.add(segment);
activeRoutePoints.push(
new THREE.Vector3(a.x, 0.65, a.z),
new THREE.Vector3(b.x, 0.65, b.z)
);
}
routePulse.visible = true;
}
const people = [];
const peopleColors = [0x536f82, 0x9d5d4c, 0x7c8565, 0xc6a75f, 0x4e7272];
for (let i = 0; i < 9; i++) {
const person = new THREE.Group();
const body = setShadow(
new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.24, 0.62, 5),
standard(peopleColors[i % peopleColors.length])
)
);
body.position.y = 0.66;
person.add(body);
const head = setShadow(
new THREE.Mesh(
new THREE.SphereGeometry(0.18, 6, 5),
standard(i % 3 === 0 ? 0xc69370 : 0xd8b493)
)
);
head.position.y = 1.12;
person.add(head);
const legs = [];
[-0.1, 0.1].forEach(x => {
const leg = setShadow(
new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.42, 0.14),
standard(0x39484c)
)
);
leg.position.set(x, 0.24, 0);
person.add(leg);
legs.push(leg);
});
const lane = ((i % 3) - 1) * 0.34;
const perpendicular = new THREE.Vector3(
-crossingDirection.z,
0,
crossingDirection.x
);
people.push({
group: person,
legs,
lane,
phase: i / 9,
speed: 0.07 + (i % 4) * 0.008,
reverse: i % 3 === 1
});
scene.add(person);
}
// -------------------------------------------------------------------------
// UI population and model updates
// -------------------------------------------------------------------------
const westGroup = document.createElement("optgroup");
westGroup.label = "West-side districts";
const eastGroup = document.createElement("optgroup");
eastGroup.label = "East-side districts";
nodes.forEach(node => {
if (node.id === sourceId) return;
const option = document.createElement("option");
option.value = node.id;
option.textContent = node.name;
(node.side === "west" ? westGroup : eastGroup).appendChild(option);
});
destination.append(westGroup, eastGroup);
destination.value = "alex";
function formatDistance(value) {
return Number.isFinite(value) ? `${value.toFixed(1)} km` : "No route";
}
comparisonTargets.forEach(id => {
const row = document.createElement("tr");
row.dataset.target = id;
row.innerHTML = `
<td>${nodeById[id].name}</td>
<td class="closed-cell no-route">No route</td>
<td class="open-cell">—</td>
`;
$("comparisonBody").appendChild(row);
});
function updateComparisonTable(closed, open) {
comparisonTargets.forEach(id => {
const row = $("comparisonBody").querySelector(`tr[data-target="${id}"]`);
const closedCell = row.querySelector(".closed-cell");
const openCell = row.querySelector(".open-cell");
closedCell.textContent = formatDistance(closed.distance[id]);
openCell.textContent = formatDistance(open.distance[id]);
closedCell.classList.toggle("active", !gateOpen);
openCell.classList.toggle("active", gateOpen);
closedCell.classList.toggle("no-route", !Number.isFinite(closed.distance[id]));
});
}
function updateUI() {
const closed = dijkstra(false);
const open = dijkstra(true);
const current = gateOpen ? open : closed;
const components = countComponents(gateOpen);
const selected = destination.value;
areaMetric.textContent = String(components);
areaDetail.textContent = gateOpen
? "Before opening: 2 separated areas"
: "After opening: 1 connected area";
reachMetric.textContent = `${current.reachable} / ${nodes.length}`;
reachDetail.textContent = gateOpen
? "Before opening: 6 reachable districts"
: "After opening: all 12 districts";
walkMetric.textContent = formatDistance(current.distance[selected]);
walkDetail.textContent = gateOpen
? `Before opening: ${formatDistance(closed.distance[selected]).toLowerCase()}`
: `After opening: ${formatDistance(open.distance[selected])}`;
gateToggle.setAttribute("aria-checked", String(gateOpen));
gateStatus.textContent = gateOpen ? "Crossing open" : "Crossing closed";
gateStatus.classList.toggle("open", gateOpen);
componentStrip.classList.toggle("open", gateOpen);
componentCaption.textContent = gateOpen
? "1 connected component"
: "2 separated connected components";
crossingLine.material.color.copy(gateOpen ? palette.open : palette.closed);
nodeMeshes.forEach(marker => {
const id = marker.userData.nodeId;
const reachable = current.distance[id] !== Infinity;
marker.material.transparent = true;
marker.material.opacity = reachable ? 1 : 0.48;
marker.material.emissiveIntensity = reachable ? 0.07 : 0.01;
});
nodeRings.forEach(({ mesh, id }) => {
const selectedRing = id === selected;
const sourceRing = id === sourceId;
const reachable = current.distance[id] !== Infinity;
mesh.material.color.copy(
selectedRing
? palette.gold
: sourceRing
? new THREE.Color(0xf3f0df)
: nodeById[id].side === "west"
? palette.west
: palette.east
);
mesh.material.opacity = reachable ? 0.95 : 0.35;
mesh.scale.setScalar(selectedRing ? 1.32 : sourceRing ? 1.18 : 1);
});
nodeLabels.forEach((label, id) => {
label.classList.toggle("selected", id === selected);
label.classList.toggle("source", id === sourceId);
});
updateComparisonTable(closed, open);
rebuildRoute(current, selected);
}
gateToggle.addEventListener("click", () => {
gateOpen = !gateOpen;
updateUI();
});
destination.addEventListener("change", updateUI);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pinch zoom, wheel zoom, node picking
// -------------------------------------------------------------------------
const pointers = new Map();
let dragDistance = 0;
let previousPinchDistance = 0;
function updateCamera() {
const { radius, phi, theta, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragDistance = 0;
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragDistance += Math.hypot(dx, dy);
if (pointers.size === 1) {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.34,
1.32
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * previousPinchDistance / distance,
25,
76
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", event => {
if (dragDistance < 6) pickNode(event);
releasePointer(event);
});
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
25,
76
);
}, { passive: false });
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pickNode(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(nodeMeshes, false);
if (hits.length) {
const id = hits[0].object.userData.nodeId;
if (id !== sourceId) {
destination.value = id;
updateUI();
}
}
}
$("resetView").addEventListener("click", () => {
cameraState.radius = 47;
cameraState.phi = 0.82;
cameraState.theta = 0.64;
cameraState.target.set(1.5, 0, 0);
});
// -------------------------------------------------------------------------
// Projected labels and animation
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
nodes.forEach(node => {
const label = nodeLabels.get(node.id);
projected.set(node.x, 2.0, node.z).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.style.left = `${x}px`;
label.style.top = `${y}px`;
}
});
}
function updateRoutePulse(elapsed) {
if (!routePulse.visible || activeRoutePoints.length < 2) return;
let total = 0;
const lengths = [];
for (let i = 0; i < activeRoutePoints.length - 1; i++) {
const length = activeRoutePoints[i].distanceTo(activeRoutePoints[i + 1]);
lengths.push(length);
total += length;
}
let remaining = (elapsed * 0.12) % 1 * total;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i]) {
routePulse.position.lerpVectors(
activeRoutePoints[i],
activeRoutePoints[i + 1],
remaining / lengths[i]
);
break;
}
remaining -= lengths[i];
}
const pulse = 1 + Math.sin(elapsed * 5) * 0.16;
routePulse.scale.setScalar(pulse);
}
function updatePeople(dt, elapsed) {
const perpendicular = new THREE.Vector3(
-crossingDirection.z,
0,
crossingDirection.x
);
people.forEach(person => {
person.group.visible = gateBlend > 0.035;
const rawProgress = (person.phase + elapsed * person.speed) % 1;
const progress = person.reverse ? 1 - rawProgress : rawProgress;
person.group.position
.copy(crossingStart)
.addScaledVector(crossingDirection, progress * crossingLength)
.addScaledVector(perpendicular, person.lane);
person.group.position.y = 0.05;
person.group.rotation.y = -crossingAngle;
const stride = Math.sin(elapsed * 8 + person.phase * 15) * 0.38;
person.legs[0].rotation.x = stride;
person.legs[1].rotation.x = -stride;
});
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const targetBlend = gateOpen ? 1 : 0;
gateBlend += (targetBlend - gateBlend) * (1 - Math.exp(-dt * 3.4));
const eased = gateBlend * gateBlend * (3 - 2 * gateBlend);
barrierHinge.rotation.z = -Math.PI / 2 * eased;
updateCamera();
updatePeople(dt, elapsed);
updateRoutePulse(elapsed);
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateUI();
updateCamera();
animate();
</script>
</body>
</html>
```