Prompt specification
Build or customize the Three.js 3D scene "District transit graph and street model" 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: District transit graph and street model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/district-transit-graph-and-street-model-x1355
Scene Description Prompt:
District transit graph and street model. Build a small street district under a suspended transit diagram. Selecting a station highlights its real location and neighbors without implying equal travel time between diagram segments. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (district-transit-graph-and-street-model-x1355):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Strata District — Transit Graph</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5fb;
--muted: #9aabba;
--panel: rgba(13, 23, 34, 0.86);
--line: rgba(198, 220, 238, 0.15);
--cyan: #50d7d1;
--amber: #ffbd59;
--violet: #c7a6ff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0a111b;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
#labels {
position: absolute;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.station-label,
.street-label {
position: absolute;
left: 0;
top: 0;
will-change: left, top;
}
.station-label {
--route: var(--cyan);
pointer-events: auto;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 7px;
border: 1px solid rgba(210, 230, 244, 0.22);
border-radius: 8px;
background: rgba(12, 21, 31, 0.83);
color: #dce8f1;
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(10px);
cursor: pointer;
transform: translate(-50%, -50%);
transition:
border-color 160ms ease,
background 160ms ease,
color 160ms ease,
box-shadow 160ms ease,
opacity 160ms ease;
white-space: nowrap;
}
.station-label:hover,
.station-label.is-hovered {
border-color: var(--route);
background: rgba(18, 31, 43, 0.95);
box-shadow: 0 7px 20px rgba(0, 0, 0, 0.3);
}
.station-label.selected {
color: white;
border-color: white;
background: rgba(238, 246, 252, 0.94);
box-shadow:
0 0 0 3px rgba(255, 255, 255, 0.12),
0 8px 22px rgba(0, 0, 0, 0.3);
}
.station-label.neighbor:not(.selected) {
border-color: var(--route);
box-shadow: 0 0 16px color-mix(in srgb, var(--route) 22%, transparent);
}
.station-label .dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--route);
box-shadow: 0 0 9px var(--route);
}
.station-label.selected .dot {
background: var(--route);
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}
.station-label .code {
color: var(--route);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.station-label.selected .code { color: #35404b; }
.station-label .name {
font-size: 11px;
font-weight: 650;
letter-spacing: 0.01em;
}
.street-label {
color: rgba(220, 233, 242, 0.38);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
text-shadow: 0 1px 5px #101822;
transform: translate(-50%, -50%);
white-space: nowrap;
}
.hud {
position: absolute;
z-index: 10;
pointer-events: none;
}
.hud > * { pointer-events: auto; }
.glass {
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
#brand {
top: 22px;
left: 22px;
width: 300px;
padding: 18px 18px 15px;
border-radius: 15px;
}
.eyebrow {
color: #8da1b1;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.brand-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
#brand h1 {
margin: 6px 0 4px;
font-size: 21px;
line-height: 1;
letter-spacing: -0.035em;
}
#brand p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.mini-button {
border: 1px solid rgba(210, 230, 244, 0.18);
border-radius: 7px;
padding: 6px 8px;
background: rgba(255, 255, 255, 0.035);
color: #c7d5df;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
.mini-button:hover {
border-color: rgba(210, 230, 244, 0.38);
background: rgba(255, 255, 255, 0.08);
color: white;
}
.lift-control {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.lift-control label {
color: #9eb0be;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.lift-control output {
min-width: 39px;
color: #d8e7f1;
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
input[type="range"] {
grid-column: 1 / -1;
width: 100%;
height: 3px;
margin: 3px 0 0;
accent-color: var(--cyan);
cursor: pointer;
}
#info {
top: 22px;
right: 22px;
width: 320px;
padding: 18px;
border-radius: 15px;
}
.selected-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
#station-name {
margin: 6px 0 3px;
font-size: 22px;
line-height: 1.05;
letter-spacing: -0.035em;
}
#station-place {
color: var(--muted);
font-size: 11px;
}
#station-code {
display: grid;
place-items: center;
width: 40px;
height: 40px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 11px;
background: rgba(255, 255, 255, 0.07);
color: white;
font-size: 13px;
font-weight: 850;
letter-spacing: 0.05em;
}
.line-badges {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 13px;
}
.line-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 7px;
border: 1px solid color-mix(in srgb, var(--route) 35%, transparent);
border-radius: 999px;
color: #dce8ef;
background: color-mix(in srgb, var(--route) 9%, transparent);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.line-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--route);
box-shadow: 0 0 7px var(--route);
}
.info-section {
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #91a5b5;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title span:last-child {
color: #617788;
font-size: 8px;
letter-spacing: 0.09em;
}
.connection {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.055);
}
.connection:last-child { border-bottom: 0; }
.connection .route-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--route);
box-shadow: 0 0 8px color-mix(in srgb, var(--route) 65%, transparent);
}
.connection .neighbor {
font-size: 11px;
font-weight: 650;
}
.connection .time {
color: #a7b8c5;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.truth-note {
display: flex;
gap: 9px;
margin-top: 14px;
padding: 10px;
border: 1px solid rgba(80, 215, 209, 0.16);
border-radius: 9px;
background: rgba(80, 215, 209, 0.055);
color: #a9bbc6;
font-size: 9px;
line-height: 1.5;
}
.truth-note strong {
display: block;
margin-bottom: 2px;
color: #d8f3f1;
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#legend {
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 18px;
padding: 11px 13px;
border-radius: 11px;
color: #a9bac6;
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.legend-line {
width: 22px;
height: 3px;
border-radius: 3px;
background: var(--route);
box-shadow: 0 0 8px color-mix(in srgb, var(--route) 45%, transparent);
}
.legend-dot {
width: 9px;
height: 9px;
border: 2px solid white;
border-radius: 50%;
background: #334a58;
box-shadow: 0 0 8px rgba(255, 255, 255, 0.25);
}
.legend-note {
padding-left: 14px;
border-left: 1px solid var(--line);
color: #6f8494;
}
#help {
right: 22px;
bottom: 22px;
padding: 8px 11px;
border-radius: 8px;
color: #7f94a3;
font-size: 9px;
letter-spacing: 0.04em;
}
#loading {
position: absolute;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #0a111b;
color: #a7b9c7;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
#brand {
top: 12px;
left: 12px;
width: calc(100% - 24px);
padding: 13px 14px;
}
#brand h1 { font-size: 18px; }
#brand p { display: none; }
.lift-control { margin-top: 10px; padding-top: 9px; }
#info {
top: auto;
right: 12px;
bottom: 12px;
width: min(330px, calc(100% - 24px));
max-height: 47vh;
overflow: auto;
padding: 14px;
}
#station-name { font-size: 19px; }
#legend { display: none; }
#help { top: 125px; right: 12px; bottom: auto; }
.station-label .name { display: none; }
.station-label { padding: 5px 7px; }
.street-label { display: none; }
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive three-dimensional district and suspended transit diagram"></canvas>
<div id="labels" aria-label="Station map labels"></div>
<section id="brand" class="hud glass">
<div class="brand-row">
<div>
<div class="eyebrow">Strata / District 07</div>
<h1>Transit above the block</h1>
<p>A schematic network suspended over its real street locations.</p>
</div>
<button id="reset-view" class="mini-button" type="button">Reset</button>
</div>
<div class="lift-control">
<label for="lift">Diagram elevation</label>
<output id="lift-value" for="lift">13.5 m</output>
<input id="lift" type="range" min="10" max="20" step="0.5" value="13.5">
</div>
</section>
<aside id="info" class="hud glass" aria-live="polite">
<div class="selected-heading">
<div>
<div class="eyebrow">Selected station</div>
<h2 id="station-name">Central Exchange</h2>
<div id="station-place">Market St / 7th St</div>
</div>
<div id="station-code">X1</div>
</div>
<div id="line-badges" class="line-badges"></div>
<div class="info-section">
<div class="section-title">
<span>Direct neighbors</span>
<span>Topology + illustrative time</span>
</div>
<div id="connections"></div>
</div>
<div class="truth-note">
<div>◎</div>
<div>
<strong>Not a distance map</strong>
Diagram spacing does not encode distance or equal travel time.
Segment times shown here vary and are illustrative.
</div>
</div>
</aside>
<section id="legend" class="hud glass">
<div class="legend-item" style="--route:#50d7d1">
<span class="legend-line"></span>
<span>A · Crosstown</span>
</div>
<div class="legend-item" style="--route:#ffbd59">
<span class="legend-line"></span>
<span>B · South Loop</span>
</div>
<div class="legend-item">
<span class="legend-dot"></span>
<span>Actual street location</span>
</div>
<div class="legend-note">Spacing ≠ time</div>
</section>
<div id="help" class="hud glass">
Drag to orbit · Wheel to zoom · Click a station
</div>
<div id="loading">Building district…</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Data: diagram positions are intentionally unrelated to street positions.
// -------------------------------------------------------------------------
const COLORS = {
A: "#50d7d1",
B: "#ffbd59",
interchange: "#c7a6ff"
};
const routes = {
A: { name: "Crosstown", color: COLORS.A },
B: { name: "South Loop", color: COLORS.B }
};
const stations = [
{
id: "foundry", code: "A1", name: "Foundry West",
place: "Dock Ave / 8th St",
lines: ["A"], diagram: [-24, -10], real: [-30, -18]
},
{
id: "civic", code: "A2", name: "Civic Square",
place: "Dock Ave / 5th St",
lines: ["A"], diagram: [-14, -10], real: [-10, -18]
},
{
id: "central", code: "X1", name: "Central Exchange",
place: "Market St / 7th St",
lines: ["A", "B"], diagram: [-2, -2], real: [10, 0]
},
{
id: "east", code: "A3", name: "East Works",
place: "Dock Ave / 11th St",
lines: ["A"], diagram: [11, -10], real: [30, -18]
},
{
id: "harbor", code: "A4", name: "Harbor Gate",
place: "Market St / 11th St",
lines: ["A"], diagram: [24, -2], real: [30, 0]
},
{
id: "museum", code: "B1", name: "Museum",
place: "Canal St / 8th St",
lines: ["B"], diagram: [-23, 8], real: [-30, 18]
},
{
id: "park", code: "B2", name: "North Park",
place: "Canal St / 5th St",
lines: ["B"], diagram: [-12, 8], real: [-10, 18]
},
{
id: "south", code: "B3", name: "South Works",
place: "Canal St / 7th St",
lines: ["B"], diagram: [7, 10], real: [10, 18]
},
{
id: "port", code: "B4", name: "Old Port",
place: "Canal St / 11th St",
lines: ["B"], diagram: [19, 10], real: [30, 18]
}
];
const edges = [
{ a: "foundry", b: "civic", route: "A", minutes: 3 },
{ a: "civic", b: "central", route: "A", minutes: 6 },
{ a: "central", b: "east", route: "A", minutes: 4 },
{ a: "east", b: "harbor", route: "A", minutes: 3 },
{ a: "museum", b: "park", route: "B", minutes: 2 },
{ a: "park", b: "central", route: "B", minutes: 5 },
{ a: "central", b: "south", route: "B", minutes: 4 },
{ a: "south", b: "port", route: "B", minutes: 6 }
];
const stationById = new Map(stations.map(s => [s.id, s]));
// -------------------------------------------------------------------------
// Renderer and scene.
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a111b);
scene.fog = new THREE.Fog(0x0a111b, 85, 145);
const camera = new THREE.PerspectiveCamera(
43, window.innerWidth / window.innerHeight, 0.1, 220
);
const cameraTarget = new THREE.Vector3(0, 6, 0);
const orbit = {
theta: 0.68,
phi: 0.89,
radius: 78,
targetTheta: 0.68,
targetPhi: 0.89,
targetRadius: 78
};
function updateCamera(immediate = false) {
if (immediate) {
orbit.theta = orbit.targetTheta;
orbit.phi = orbit.targetPhi;
orbit.radius = orbit.targetRadius;
}
orbit.theta += (orbit.targetTheta - orbit.theta) * 0.12;
orbit.phi += (orbit.targetPhi - orbit.phi) * 0.12;
orbit.radius += (orbit.targetRadius - orbit.radius) * 0.12;
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera(true);
const hemi = new THREE.HemisphereLight(0xb9d8ff, 0x273126, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe3ba, 3.0);
sun.position.set(22, 45, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -42;
sun.shadow.camera.right = 42;
sun.shadow.camera.top = 38;
sun.shadow.camera.bottom = -38;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x6ca7d9, 1.1);
fill.position.set(-30, 20, -25);
scene.add(fill);
// -------------------------------------------------------------------------
// Small geometry helpers.
// -------------------------------------------------------------------------
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03,
...options
});
}
function box(parent, w, h, d, material, x = 0, y = 0, z = 0, cast = true) {
const mesh = new THREE.Mesh(boxGeometry, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const yAxis = new THREE.Vector3(0, 1, 0);
function cylinderBetween(parent, a, b, radius, material, radialSegments = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 7183;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function randomBetween(a, b) {
return a + (b - a) * random();
}
// -------------------------------------------------------------------------
// District street model.
// -------------------------------------------------------------------------
const district = new THREE.Group();
scene.add(district);
const baseMat = standard(0x101b27);
const groundMat = standard(0x35464a);
const sidewalkMat = standard(0x74818a);
const asphaltMat = standard(0x18232d);
const curbMat = standard(0x8d989f);
const laneMat = standard(0xd8d9c9, { roughness: 0.9 });
const blockMat = standard(0x687279);
box(district, 68, 1.1, 52, baseMat, 0, -0.65, 0, false);
box(district, 66, 0.28, 50, groundMat, 0, -0.05, 0, false);
const roadXs = [-30, -10, 10, 30];
const roadZs = [-18, 0, 18];
// Sidewalks first, then asphalt on top to keep intersections clean.
for (const x of roadXs) {
box(district, 7.2, 0.14, 48, sidewalkMat, x, 0.07, 0, false);
}
for (const z of roadZs) {
box(district, 64, 0.14, 7.2, sidewalkMat, 0, 0.07, z, false);
}
for (const x of roadXs) {
box(district, 5.25, 0.13, 48, asphaltMat, x, 0.15, 0, false);
}
for (const z of roadZs) {
box(district, 64, 0.13, 5.25, asphaltMat, 0, 0.15, z, false);
}
// Lane dashes.
for (const x of roadXs) {
for (let z = -22; z <= 22; z += 4.5) {
box(district, 0.13, 0.025, 1.7, laneMat, x, 0.235, z, false);
}
}
for (const z of roadZs) {
for (let x = -30; x <= 30; x += 4.5) {
box(district, 1.7, 0.025, 0.13, laneMat, x, 0.235, z, false);
}
}
// Crosswalk bars at the central interchange.
for (let i = -1; i <= 1; i++) {
box(district, 4.2, 0.03, 0.55, laneMat, 10 + i * 1.25, 0.245, -3.55, false);
box(district, 4.2, 0.03, 0.55, laneMat, 10 + i * 1.25, 0.245, 3.55, false);
box(district, 0.55, 0.03, 4.2, laneMat, 6.55, 0.245, i * 1.25, false);
box(district, 0.55, 0.03, 4.2, laneMat, 13.45, 0.245, i * 1.25, false);
}
// Building block pads.
const blockCenters = [
[-20, -9], [0, -9], [20, -9],
[-20, 9], [0, 9], [20, 9]
];
for (const [x, z] of blockCenters) {
box(district, 15.4, 0.18, 13.4, blockMat, x, 0.18, z, false);
}
const windowMat = standard(0x182f42, {
roughness: 0.32,
metalness: 0.25,
emissive: 0x0a1720,
emissiveIntensity: 0.18
});
const buildingPalettes = [
0xa88e78, 0x778e9a, 0xb0a58e, 0x6f8790,
0x927b72, 0x839398, 0x9a8d7e, 0x71858c
];
const roofMat = standard(0x39464d);
const doorMat = standard(0x263743);
function addBuilding(x, z, w, d, h, color, options = {}) {
const group = new THREE.Group();
group.position.set(x, 0.27, z);
district.add(group);
const bodyMat = standard(color);
box(group, w, h, d, bodyMat, 0, h / 2, 0);
if (options.flatRoof !== false) {
box(group, w + 0.32, 0.22, d + 0.32, roofMat, 0, h + 0.11, 0);
} else {
const roof = new THREE.Mesh(
new THREE.ConeGeometry(Math.max(w, d) * 0.66, 1.6, 4),
roofMat
);
roof.position.y = h + 0.8;
roof.rotation.y = Math.PI / 4;
roof.scale.z = d / w;
roof.castShadow = true;
group.add(roof);
}
// Dark window bands on the two most visible faces.
const rows = Math.max(1, Math.min(3, Math.floor(h / 2.8)));
const cols = Math.max(1, Math.min(3, Math.floor(w / 1.9)));
for (let row = 0; row < rows; row++) {
const wy = 1.45 + row * 2.25;
if (wy > h - 0.5) continue;
for (let col = 0; col < cols; col++) {
const wx = (col - (cols - 1) / 2) * (w / (cols + 1));
box(group, 0.72, 0.68, 0.055, windowMat, wx, wy, d / 2 + 0.035, false);
}
}
const sideRows = Math.max(1, Math.min(3, Math.floor(h / 3.2)));
for (let row = 0; row < sideRows; row++) {
const wy = 1.45 + row * 2.3;
if (wy > h - 0.5) continue;
box(group, 0.055, 0.68, 0.85, windowMat, w / 2 + 0.035, wy, 0.2, false);
}
box(group, 1.0, 1.45, 0.08, doorMat, 0, 0.72, d / 2 + 0.05, false);
if (h > 8) {
box(group, 1.6, 0.55, 1.1, roofMat, 0.6, h + 0.48, -0.3);
box(group, 0.16, 2.2, 0.16, roofMat, -0.5, h + 1.2, 0.3);
}
return group;
}
addBuilding(-23, -9, 5.3, 7.0, 10.5, 0x8d857e);
addBuilding(-16.5, -9.3, 5.0, 6.2, 5.8, buildingPalettes[1]);
addBuilding(-4.0, -9.2, 6.1, 6.4, 9.1, buildingPalettes[2]);
addBuilding(3.8, -9.0, 5.2, 6.6, 6.2, buildingPalettes[3]);
addBuilding(16.3, -9.1, 7.1, 7.2, 4.7, 0x7b7770);
addBuilding(23.2, -9.0, 5.2, 7.7, 8.0, buildingPalettes[5]);
addBuilding(-23.0, 9.2, 5.6, 6.4, 5.0, buildingPalettes[4]);
addBuilding(-16.2, 9.0, 6.1, 5.8, 7.5, buildingPalettes[7]);
addBuilding(16.3, 9.0, 7.0, 7.0, 5.0, 0x8b8175);
addBuilding(23.1, 9.0, 5.3, 6.7, 7.2, buildingPalettes[1]);
// Central pocket park.
const parkMat = standard(0x426d50);
const pathMat = standard(0xa49d83);
box(district, 14.6, 0.13, 12.7, parkMat, 0, 0.31, 9, false);
box(district, 2.0, 0.08, 12.2, pathMat, 0, 0.40, 9, false);
box(district, 14.0, 0.08, 2.0, pathMat, 0, 0.405, 9, false);
const foliageMats = [
standard(0x416d4d),
standard(0x527b55),
standard(0x365f47)
];
const trunkMat = standard(0x68503d);
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.29, z);
group.scale.setScalar(scale);
district.add(group);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.2, 1.9, 6),
trunkMat
);
trunk.position.y = 0.95;
trunk.castShadow = true;
group.add(trunk);
const foliage = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.25, 0),
foliageMats[Math.floor(random() * foliageMats.length)]
);
foliage.position.y = 2.55;
foliage.scale.y = 1.15;
foliage.castShadow = true;
group.add(foliage);
}
[
[-5.5, 5.4], [-5.6, 12.4], [4.9, 5.4],
[5.2, 12.5], [-2.4, 12.7], [2.2, 5.5]
].forEach(([x, z]) => addTree(x, z, randomBetween(0.82, 1.12)));
// Street trees along the sidewalks.
for (const x of [-20, 0, 20]) {
addTree(x - 7.1, -13.3, 0.78);
addTree(x + 7.1, -5.2, 0.72);
addTree(x - 7.1, 3.4, 0.76);
addTree(x + 7.1, 13.1, 0.7);
}
// Streetlights.
const poleMat = standard(0x34444e, { metalness: 0.45, roughness: 0.4 });
const lampMat = standard(0xffdda1, {
emissive: 0xffb85c,
emissiveIntensity: 1.2,
roughness: 0.4
});
function addStreetlight(x, z, flipX = false) {
const group = new THREE.Group();
group.position.set(x, 0.25, z);
district.add(group);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.09, 4.8, 6),
poleMat
);
pole.position.y = 2.4;
pole.castShadow = true;
group.add(pole);
const arm = box(
group, 0.85, 0.08, 0.08, poleMat,
flipX ? -0.38 : 0.38, 4.7, 0
);
arm.castShadow = true;
box(
group, 0.42, 0.12, 0.26, lampMat,
flipX ? -0.73 : 0.73, 4.58, 0,
false
);
}
for (const x of roadXs) {
for (const z of roadZs) {
addStreetlight(x + 3.35, z + 3.35, true);
}
}
// Benches around the park.
const benchMat = standard(0x77573e);
for (const z of [6.1, 11.9]) {
box(district, 2.5, 0.16, 0.58, benchMat, -3.2, 0.85, z);
box(district, 2.5, 0.7, 0.12, benchMat, -3.2, 1.15, z + 0.25);
box(district, 0.13, 0.65, 0.42, poleMat, -4.2, 0.58, z);
box(district, 0.13, 0.65, 0.42, poleMat, -2.2, 0.58, z);
}
// -------------------------------------------------------------------------
// Low-poly cars.
// -------------------------------------------------------------------------
const cars = [];
const carBodyColors = [0xb85e52, 0xd6c16a, 0x5e8fa6, 0xd7d9d7, 0x4d5963];
function addCar(axis, road, start, speed, direction, color) {
const group = new THREE.Group();
const bodyMat = standard(color, { roughness: 0.5, metalness: 0.18 });
const glassMat = standard(0x223b49, { roughness: 0.25, metalness: 0.35 });
box(group, 1.35, 0.5, 2.55, bodyMat, 0, 0.52, 0);
box(group, 1.05, 0.48, 1.25, glassMat, 0, 0.98, -0.12);
const wheelMat = standard(0x11161a);
for (const x of [-0.68, 0.68]) {
for (const z of [-0.8, 0.8]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.28, 0.18, 8),
wheelMat
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.34, z);
group.add(wheel);
}
}
if (axis === "x") group.rotation.y = Math.PI / 2;
district.add(group);
cars.push({ group, axis, road, start, speed, direction });
}
addCar("z", -30, -21, 4.2, 1, carBodyColors[0]);
addCar("z", -10, 16, 3.6, -1, carBodyColors[1]);
addCar("z", 10, -15, 4.7, 1, carBodyColors[2]);
addCar("z", 30, 8, 3.9, -1, carBodyColors[3]);
addCar("x", -18, -26, 4.0, 1, carBodyColors[4]);
addCar("x", 18, 17, 3.7, -1, carBodyColors[1]);
// -------------------------------------------------------------------------
// Suspended transit diagram.
// -------------------------------------------------------------------------
const diagramGroup = new THREE.Group();
diagramGroup.position.y = 13.5;
scene.add(diagramGroup);
const backplateMat = new THREE.MeshBasicMaterial({
color: 0x0e1d2b,
transparent: true,
opacity: 0.16,
depthWrite: false,
side: THREE.DoubleSide
});
const plate = new THREE.Mesh(
new THREE.PlaneGeometry(55, 28),
backplateMat
);
plate.rotation.x = -Math.PI / 2;
plate.position.y = -0.24;
diagramGroup.add(plate);
const plateOutlinePoints = [
[-27.5, -0.19, -14],
[27.5, -0.19, -14],
[27.5, -0.19, 14],
[-27.5, -0.19, 14]
].map(p => new THREE.Vector3(...p));
const plateOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(plateOutlinePoints),
new THREE.LineBasicMaterial({
color: 0x83a0b6,
transparent: true,
opacity: 0.25
})
);
diagramGroup.add(plateOutline);
// Thin suspension cables imply a ceiling beyond the camera.
const cableMat = new THREE.MeshBasicMaterial({
color: 0x7990a2,
transparent: true,
opacity: 0.28
});
for (const x of [-27.5, 27.5]) {
for (const z of [-14, 14]) {
cylinderBetween(diagramGroup, [x, 0, z], [x, 8, z], 0.025, cableMat, 5);
}
}
const stationVisuals = new Map();
const edgeVisuals = [];
const pickables = [];
const labelElements = new Map();
const labelOffsets = {
foundry: [-4, 14],
civic: [0, -16],
central: [-10, -29],
east: [0, 15],
harbor: [8, -14],
museum: [-5, 13],
park: [0, -16],
south: [0, 15],
port: [8, -15]
};
for (const station of stations) {
const group = new THREE.Group();
group.position.set(station.diagram[0], 0.27, station.diagram[1]);
diagramGroup.add(group);
const accent = station.lines.length > 1
? COLORS.interchange
: COLORS[station.lines[0]];
const coreMaterial = standard(0xf5fbff, {
roughness: 0.3,
metalness: 0.08,
emissive: accent,
emissiveIntensity: 0.04
});
const ringMaterial = standard(accent, {
roughness: 0.34,
metalness: 0.12,
emissive: accent,
emissiveIntensity: 0.45
});
const core = new THREE.Mesh(
new THREE.CylinderGeometry(0.39, 0.39, 0.28, 12),
coreMaterial
);
core.userData.stationId = station.id;
group.add(core);
pickables.push(core);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.61, 0.12, 6, 24),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.12;
ring.userData.stationId = station.id;
group.add(ring);
pickables.push(ring);
if (station.lines.length > 1) {
const secondRing = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.055, 6, 28),
standard(COLORS.A, {
emissive: COLORS.A,
emissiveIntensity: 0.65,
transparent: true,
opacity: 0.9
})
);
secondRing.rotation.x = Math.PI / 2;
secondRing.position.y = 0.11;
group.add(secondRing);
}
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.83, 0.035, 6, 30),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false
})
);
halo.rotation.x = Math.PI / 2;
halo.position.y = 0.2;
group.add(halo);
stationVisuals.set(station.id, {
group, core, coreMaterial, ring, ringMaterial, halo,
baseColor: new THREE.Color(accent)
});
const label = document.createElement("button");
label.type = "button";
label.className = "station-label";
label.style.setProperty("--route", accent);
label.setAttribute("aria-label", `Select ${station.name}`);
label.innerHTML = `
<span class="dot"></span>
<span class="code">${station.code}</span>
<span class="name">${station.name}</span>
`;
label.addEventListener("click", event => {
event.stopPropagation();
selectStation(station.id);
});
document.querySelector("#labels").appendChild(label);
labelElements.set(station.id, label);
}
for (const edge of edges) {
const a = stationById.get(edge.a);
const b = stationById.get(edge.b);
const color = COLORS[edge.route];
const routeMaterial = standard(color, {
emissive: color,
emissiveIntensity: 0.78,
roughness: 0.42,
metalness: 0.06
});
cylinderBetween(
diagramGroup,
[a.diagram[0], 0.13, a.diagram[1]],
[b.diagram[0], 0.13, b.diagram[1]],
0.13,
routeMaterial,
8
);
const glowMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false
});
const glow = cylinderBetween(
diagramGroup,
[a.diagram[0], 0.15, a.diagram[1]],
[b.diagram[0], 0.15, b.diagram[1]],
0.31,
glowMaterial,
8
);
glow.castShadow = false;
edgeVisuals.push({ edge, glow, glowMaterial });
}
// -------------------------------------------------------------------------
// Real street station markers.
// -------------------------------------------------------------------------
const realVisuals = new Map();
for (const station of stations) {
const group = new THREE.Group();
group.position.set(station.real[0], 0.27, station.real[1]);
scene.add(group);
const accent = station.lines.length > 1
? COLORS.interchange
: COLORS[station.lines[0]];
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(0.56, 0.56, 0.12, 12),
standard(0x223541, {
emissive: accent,
emissiveIntensity: 0.08
})
);
pad.userData.stationId = station.id;
group.add(pad);
pickables.push(pad);
const ringMaterial = new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.36,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.74, 0.065, 6, 24),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.08;
group.add(ring);
realVisuals.set(station.id, { group, pad, ring, ringMaterial, accent });
}
// Selected-location beam and ground halo.
const locationBeamGroup = new THREE.Group();
scene.add(locationBeamGroup);
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 5, 6),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
beam.position.y = 2.65;
locationBeamGroup.add(beam);
const locationHalo = new THREE.Mesh(
new THREE.TorusGeometry(1.18, 0.045, 6, 36),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
locationHalo.rotation.x = Math.PI / 2;
locationHalo.position.y = 0.29;
locationBeamGroup.add(locationHalo);
// Dashed tether from schematic node to actual street location.
const tetherMaterial = new THREE.LineDashedMaterial({
color: 0xffffff,
dashSize: 0.65,
gapSize: 0.35,
transparent: true,
opacity: 0.85,
depthWrite: false
});
const tetherGeometry = new THREE.BufferGeometry();
const tether = new THREE.Line(tetherGeometry, tetherMaterial);
scene.add(tether);
// -------------------------------------------------------------------------
// Selection state and UI.
// -------------------------------------------------------------------------
let selectedId = "central";
let hoveredId = null;
function neighborIdsFor(id) {
const result = new Set();
for (const edge of edges) {
if (edge.a === id) result.add(edge.b);
if (edge.b === id) result.add(edge.a);
}
return result;
}
function updateTether() {
const station = stationById.get(selectedId);
diagramGroup.updateMatrixWorld(true);
const diagramPosition = new THREE.Vector3();
stationVisuals.get(selectedId).group.getWorldPosition(diagramPosition);
diagramPosition.y += 0.2;
const realPosition = new THREE.Vector3(
station.real[0], 0.31, station.real[1]
);
tetherGeometry.setFromPoints([diagramPosition, realPosition]);
tether.computeLineDistances();
const accent = station.lines.length > 1
? COLORS.interchange
: COLORS[station.lines[0]];
tetherMaterial.color.set(accent);
locationBeamGroup.position.set(station.real[0], 0, station.real[1]);
locationBeamGroup.traverse(object => {
if (object.material?.color && object !== locationBeamGroup) {
object.material.color.set(accent);
}
});
}
function updatePanel() {
const station = stationById.get(selectedId);
document.querySelector("#station-name").textContent = station.name;
document.querySelector("#station-place").textContent = station.place;
document.querySelector("#station-code").textContent = station.code;
const badges = document.querySelector("#line-badges");
badges.innerHTML = station.lines.map(line => `
<span class="line-badge" style="--route:${COLORS[line]}">
${line} · ${routes[line].name}
</span>
`).join("");
const connections = document.querySelector("#connections");
connections.innerHTML = edges
.filter(edge => edge.a === selectedId || edge.b === selectedId)
.map(edge => {
const otherId = edge.a === selectedId ? edge.b : edge.a;
const other = stationById.get(otherId);
const direction = edge.a === selectedId ? "→" : "←";
return `
<div class="connection" style="--route:${COLORS[edge.route]}">
<span class="route-dot"></span>
<span class="neighbor">${direction} ${other.name}</span>
<span class="time">~${edge.minutes} min</span>
</div>
`;
}).join("");
}
function selectStation(id) {
if (!stationById.has(id)) return;
selectedId = id;
const neighbors = neighborIdsFor(id);
for (const station of stations) {
const visual = stationVisuals.get(station.id);
const label = labelElements.get(station.id);
const real = realVisuals.get(station.id);
const isSelected = station.id === id;
const isNeighbor = neighbors.has(station.id);
visual.coreMaterial.emissiveIntensity = isSelected
? 1.0
: isNeighbor ? 0.42 : 0.04;
visual.ringMaterial.emissiveIntensity = isSelected
? 1.35
: isNeighbor ? 1.0 : 0.45;
visual.ringMaterial.color.set(isSelected ? 0xffffff : visual.baseColor);
visual.halo.material.opacity = isSelected ? 0.68 : 0;
const baseScale = station.lines.length > 1 ? 1.08 : 1;
const targetScale = isSelected ? 1.24 : isNeighbor ? 1.10 : baseScale;
visual.group.scale.setScalar(targetScale);
real.ringMaterial.opacity = isSelected ? 1 : isNeighbor ? 0.75 : 0.28;
real.group.scale.setScalar(isSelected ? 1.28 : isNeighbor ? 1.10 : 1);
label.classList.toggle("selected", isSelected);
label.classList.toggle("neighbor", isNeighbor);
}
for (const { edge, glowMaterial } of edgeVisuals) {
const isDirect =
(edge.a === id && edge.b === id) ||
(edge.a === id && edge.b === id);
const direct =
(edge.a === id && neighbors.has(edge.b)) ||
(edge.b === id && neighbors.has(edge.a));
glowMaterial.opacity = direct ? 0.78 : 0;
}
updatePanel();
updateTether();
}
function setHovered(id) {
if (hoveredId === id) return;
hoveredId = id;
for (const [stationId, label] of labelElements) {
label.classList.toggle("is-hovered", stationId === id);
}
canvas.style.cursor = id ? "pointer" : "grab";
}
// -------------------------------------------------------------------------
// Raycasting and custom camera controls.
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerDown = false;
let pointerX = 0;
let pointerY = 0;
let downX = 0;
let downY = 0;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickStation(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
return hits.length ? hits[0].object.userData.stationId : null;
}
canvas.addEventListener("pointerdown", event => {
pointerDown = true;
dragging = false;
pointerX = event.clientX;
pointerY = event.clientY;
downX = event.clientX;
downY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (Math.hypot(event.clientX - downX, event.clientY - downY) > 4) {
dragging = true;
}
if (dragging) {
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(
orbit.targetPhi + dy * 0.005,
0.34,
1.25
);
}
} else {
setHovered(pickStation(event));
}
});
canvas.addEventListener("pointerup", event => {
if (pointerDown && !dragging) {
const id = pickStation(event);
if (id) selectStation(id);
}
pointerDown = false;
dragging = false;
canvas.style.cursor = hoveredId ? "pointer" : "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointerleave", () => {
if (!pointerDown) setHovered(null);
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius + event.deltaY * 0.045,
42,
112
);
}, { passive: false });
document.querySelector("#reset-view").addEventListener("click", () => {
orbit.targetTheta = 0.68;
orbit.targetPhi = 0.89;
orbit.targetRadius = 78;
});
let liftTarget = 13.5;
document.querySelector("#lift").addEventListener("input", event => {
liftTarget = Number(event.target.value);
document.querySelector("#lift-value").textContent = `${liftTarget.toFixed(1)} m`;
});
// -------------------------------------------------------------------------
// Street labels projected from world space.
// -------------------------------------------------------------------------
const streetLabels = [
{ text: "Dock Avenue", point: new THREE.Vector3(3, 0.3, -18) },
{ text: "Market Street", point: new THREE.Vector3(3, 0.3, 0) },
{ text: "Canal Street", point: new THREE.Vector3(3, 0.3, 18) }
];
for (const item of streetLabels) {
const element = document.createElement("div");
element.className = "street-label";
element.textContent = item.text;
document.querySelector("#labels").appendChild(element);
item.element = element;
}
// -------------------------------------------------------------------------
// Animation and projection.
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
function projectElement(element, point, offsetX = 0, offsetY = 0) {
projected.copy(point).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Smoothly raise or lower the suspended diagram.
diagramGroup.position.y +=
(liftTarget - diagramGroup.position.y) * Math.min(1, delta * 5);
diagramGroup.updateMatrixWorld(true);
updateCamera();
// Cars.
for (const car of cars) {
const position = car.start + car.direction * elapsed * car.speed;
const wrapped = ((position + 25) % 50 + 50) % 50 - 25;
if (car.axis === "z") {
car.group.position.set(car.road, 0.25, wrapped);
} else {
car.group.position.set(wrapped, 0.25, car.road);
}
}
// Selected node pulse.
const selectedVisual = stationVisuals.get(selectedId);
selectedVisual.halo.scale.setScalar(1 + Math.sin(elapsed * 3.2) * 0.10);
selectedVisual.halo.material.opacity = 0.48 + Math.sin(elapsed * 3.2) * 0.16;
locationHalo.scale.setScalar(1 + Math.sin(elapsed * 3.2 + 0.7) * 0.10);
beam.material.opacity = 0.32 + Math.sin(elapsed * 3.2 + 0.4) * 0.12;
updateTether();
// Project station labels.
for (const station of stations) {
stationVisuals.get(station.id).group.getWorldPosition(worldPosition);
worldPosition.y += 0.5;
const offset = labelOffsets[station.id];
projectElement(
labelElements.get(station.id),
worldPosition,
offset[0],
offset[1]
);
}
// Project street names.
for (const item of streetLabels) {
projectElement(item.element, item.point);
}
renderer.render(scene, camera);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
selectStation("central");
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```