Prompt specification
Build or customize the Three.js 3D scene "Transit Map Symbol Workshop" 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: Transit Map Symbol Workshop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/transit-map-symbol-workshop-x3419
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build a fictional transit map using station, transfer, and access symbols with redundant labels. Let users change a legend and update all associated markers consistently.
Working Three.js Starter (transit-map-symbol-workshop-x3419):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="dark">
<title>Nightgrid Voxel Transit</title>
<style>
:root {
--bg: #071116;
--panel: rgba(9, 22, 29, 0.91);
--panel-strong: rgba(12, 29, 37, 0.97);
--line: rgba(153, 218, 228, 0.18);
--text: #eaf8fa;
--muted: #8da8ae;
--accent: #66e3ff;
--shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 28% 22%, rgba(27, 82, 91, 0.22), transparent 38%),
radial-gradient(circle at 75% 78%, rgba(60, 33, 91, 0.16), transparent 42%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button {
color: var(--text);
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.brand {
position: absolute;
z-index: 10;
top: 22px;
left: 24px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #8edce8;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border: 2px solid var(--accent);
content: "";
box-shadow: 3px -3px 0 rgba(102, 227, 255, 0.22);
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 39px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
margin-top: 9px;
color: var(--muted);
font: 500 11px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.route-key {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.route-chip {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 26px;
padding: 5px 9px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(8, 20, 27, 0.72);
color: #bad0d4;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.06em;
}
.route-chip i {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--route);
box-shadow: 0 0 10px color-mix(in srgb, var(--route), transparent 45%);
}
.header-actions {
position: absolute;
z-index: 30;
top: 22px;
right: 24px;
display: flex;
gap: 8px;
}
.tool-button {
min-height: 36px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(9, 24, 31, 0.84);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
cursor: pointer;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.tool-button:hover {
border-color: rgba(102, 227, 255, 0.5);
background: rgba(19, 45, 55, 0.95);
transform: translateY(-1px);
}
.legend-panel {
position: absolute;
z-index: 20;
top: 72px;
right: 24px;
width: 320px;
max-height: calc(100vh - 96px);
overflow: auto;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(102, 227, 255, 0.3) transparent;
}
.legend-panel.closed {
display: none;
}
.panel-head {
padding: 17px 17px 14px;
border-bottom: 1px solid var(--line);
}
.panel-kicker {
color: var(--accent);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.panel-head h2 {
margin: 7px 0 5px;
font-size: 17px;
letter-spacing: -0.025em;
}
.panel-head p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
#legendRows {
padding: 7px 13px;
}
.legend-row {
padding: 12px 4px;
border-bottom: 1px solid rgba(153, 218, 228, 0.1);
}
.legend-row:last-child {
border-bottom: 0;
}
.legend-row-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.legend-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 12px;
font-weight: 750;
}
.marker-preview {
--marker-color: #66e3ff;
position: relative;
display: inline-block;
width: 16px;
height: 16px;
flex: 0 0 16px;
background: var(--marker-color);
box-shadow: 0 0 12px color-mix(in srgb, var(--marker-color), transparent 55%);
}
.marker-preview.shape-square {
border-radius: 2px;
}
.marker-preview.shape-diamond {
width: 13px;
height: 13px;
margin: 1px;
transform: rotate(45deg);
}
.marker-preview.shape-circle {
border-radius: 50%;
}
.marker-preview.shape-cross {
clip-path: polygon(
35% 0, 65% 0, 65% 35%, 100% 35%, 100% 65%,
65% 65%, 65% 100%, 35% 100%, 35% 65%, 0 65%, 0 35%, 35% 35%
);
}
.marker-preview.shape-hex {
clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}
.marker-preview.shape-tower {
clip-path: polygon(
20% 100%, 20% 72%, 5% 72%, 5% 43%, 20% 43%, 20% 15%,
80% 15%, 80% 43%, 95% 43%, 95% 72%, 80% 72%, 80% 100%
);
}
.legend-count {
color: #78939a;
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-controls {
display: grid;
grid-template-columns: 37px 1fr 74px;
gap: 8px;
}
.legend-controls input[type="color"] {
width: 37px;
height: 34px;
padding: 2px;
border: 1px solid var(--line);
border-radius: 7px;
background: #101f25;
cursor: pointer;
}
.legend-controls input[type="color"]::-webkit-color-swatch-wrapper {
padding: 0;
}
.legend-controls input[type="color"]::-webkit-color-swatch {
border: 0;
border-radius: 4px;
}
.legend-controls select,
.legend-controls input[type="text"] {
width: 100%;
min-width: 0;
height: 34px;
padding: 0 8px;
border: 1px solid var(--line);
border-radius: 7px;
outline: 0;
background: #101f25;
color: var(--text);
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.legend-controls select:focus,
.legend-controls input[type="text"]:focus {
border-color: rgba(102, 227, 255, 0.65);
box-shadow: 0 0 0 2px rgba(102, 227, 255, 0.08);
}
.legend-footer {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
padding: 12px 13px 15px;
border-top: 1px solid var(--line);
}
.legend-footer button {
min-height: 34px;
border: 1px solid var(--line);
border-radius: 8px;
background: #102129;
cursor: pointer;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-footer button:hover {
border-color: rgba(102, 227, 255, 0.45);
background: #17313a;
}
.inspector {
position: absolute;
z-index: 15;
bottom: 24px;
left: 24px;
width: 285px;
min-height: 112px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel-strong);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
pointer-events: none;
}
.inspector-kicker {
color: #789da4;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.inspector h3 {
margin: 8px 0 5px;
font-size: 16px;
letter-spacing: -0.02em;
}
.inspector p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.inspector-meta {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 10px;
}
.meta-pill {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 5px;
color: #b9cdd1;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.help {
position: absolute;
z-index: 12;
bottom: 23px;
left: 50%;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(7, 19, 25, 0.74);
color: #78949b;
font: 600 9px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.06em;
pointer-events: none;
transform: translateX(-50%);
white-space: nowrap;
}
#hoverTip {
position: fixed;
z-index: 50;
display: none;
max-width: 240px;
padding: 7px 9px;
border: 1px solid rgba(102, 227, 255, 0.3);
border-radius: 6px;
background: rgba(5, 15, 20, 0.94);
color: #dff7fa;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.35);
font: 650 10px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
pointer-events: none;
}
#toast {
position: absolute;
z-index: 60;
top: 22px;
left: 50%;
max-width: min(420px, calc(100vw - 30px));
padding: 10px 14px;
border: 1px solid rgba(102, 227, 255, 0.35);
border-radius: 8px;
background: rgba(9, 29, 37, 0.96);
color: #dff8fb;
box-shadow: var(--shadow);
font: 650 10px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.03em;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -10px);
transition: opacity 180ms, transform 180ms;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
}
.subtitle,
.route-key {
display: none;
}
.header-actions {
top: 14px;
right: 14px;
}
.tool-button {
padding: 8px 9px;
}
#resetView {
display: none;
}
.legend-panel {
top: auto;
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
max-height: 48vh;
}
.inspector,
.help {
display: none;
}
#toast {
top: 66px;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive three-dimensional fictional transit map"></div>
<header class="brand">
<div class="eyebrow">Nightgrid authority / network 07</div>
<h1>Nightgrid Transit</h1>
<div class="subtitle">A voxel interchange atlas · 3 services · 16 map symbols</div>
<div class="route-key" aria-label="Route key">
<span class="route-chip" style="--route:#ffc857"><i></i>A · ORBIT</span>
<span class="route-chip" style="--route:#ff609a"><i></i>B · HARBOR</span>
<span class="route-chip" style="--route:#79efa8"><i></i>C · GRID</span>
</div>
</header>
<div class="header-actions">
<button class="tool-button" id="labelsToggle" type="button">Labels on</button>
<button class="tool-button" id="resetView" type="button">Reset view</button>
<button class="tool-button" id="legendToggle" type="button" aria-expanded="true">Legend</button>
</div>
<aside class="legend-panel" id="legendPanel" aria-label="Editable marker legend">
<div class="panel-head">
<div class="panel-kicker">Marker legend / live editor</div>
<h2>Change the network symbols</h2>
<p>Color, shape, and text are redundant encodings. Editing a legend row immediately updates every matching map marker and label.</p>
</div>
<div id="legendRows"></div>
<div class="legend-footer">
<button id="resetLegend" type="button">Reset legend</button>
<button id="randomLegend" type="button">Randomize</button>
</div>
</aside>
<section class="inspector" id="inspector" aria-live="polite">
<div class="inspector-kicker">Marker inspector</div>
<h3>Select a map marker</h3>
<p>Click any voxel symbol to inspect its category and route connections.</p>
</section>
<div class="help">Drag: orbit · Right-drag: pan · Wheel: zoom · Click: inspect</div>
<div id="hoverTip"></div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const legendPanel = document.querySelector("#legendPanel");
const legendRows = document.querySelector("#legendRows");
const inspector = document.querySelector("#inspector");
const hoverTip = document.querySelector("#hoverTip");
const toast = document.querySelector("#toast");
const typeLabels = {
station: "Station",
transfer: "Transfer",
access: "Access"
};
const defaults = {
station: { color: "#66e3ff", shape: "square", code: "STN" },
transfer: { color: "#ffc857", shape: "hex", code: "XFER" },
access: { color: "#79efa8", shape: "cross", code: "ACC" }
};
const legend = {
station: { ...defaults.station },
transfer: { ...defaults.transfer },
access: { ...defaults.access }
};
const shapeOptions = [
["square", "Square"],
["diamond", "Diamond"],
["circle", "Circle"],
["cross", "Cross"],
["hex", "Hexagon"],
["tower", "Tower"]
];
const routes = [
{
id: "A",
name: "ORBIT",
color: "#ffc857",
points: [[-8, 2], [-4, 2], [-4, -2], [0, -2], [0, 5]]
},
{
id: "B",
name: "HARBOR",
color: "#ff609a",
points: [[-8, -3], [0, -3], [0, 4], [4, 4], [4, 0], [8, 0]]
},
{
id: "C",
name: "GRID",
color: "#79efa8",
points: [[-4, -4], [4, -4], [4, 2], [0, 2], [0, -2], [-4, -2]]
}
];
const markerData = [
{ name: "Quay West", type: "station", x: -8, y: 2, lines: ["A"] },
{ name: "Marina Gate", type: "station", x: -8, y: -3, lines: ["B"] },
{ name: "Signal House", type: "station", x: 0, y: -3, lines: ["B"] },
{ name: "Beacon Works", type: "station", x: 4, y: 4, lines: ["B"] },
{ name: "East Terminal", type: "station", x: 8, y: 0, lines: ["B"] },
{ name: "Orchard Halt", type: "station", x: -4, y: -4, lines: ["C"] },
{ name: "Dock Nine", type: "station", x: 4, y: -4, lines: ["C"] },
{ name: "Summit", type: "station", x: 0, y: 5, lines: ["A"] },
{ name: "Civic Cross", type: "transfer", x: 0, y: -2, lines: ["A", "B", "C"] },
{ name: "North Exchange", type: "transfer", x: 0, y: 2, lines: ["B", "C"] },
{ name: "Foundry Junction", type: "transfer", x: 4, y: 2, lines: ["B", "C"] },
{ name: "Old Mint", type: "transfer", x: -4, y: -2, lines: ["A", "C"] },
{
name: "Quay Lift",
type: "access",
x: -7,
y: 1,
lines: ["A"],
anchor: [-8, 2]
},
{
name: "Signal Ramp",
type: "access",
x: 1,
y: -4,
lines: ["B"],
anchor: [0, -3]
},
{
name: "East Bike Vault",
type: "access",
x: 7,
y: 1,
lines: ["B"],
anchor: [8, 0]
},
{
name: "Summit Night Exit",
type: "access",
x: 1,
y: 4,
lines: ["A"],
anchor: [0, 5]
}
];
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x071116, 31, 52);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setClearColor(0x071116, 0);
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",
"Nightgrid Transit. Drag to orbit, right-drag to pan, and use the wheel to zoom."
);
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-12, 12, 7, -7, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, 0);
const cameraSpherical = {
radius: 28,
theta: -0.11,
phi: 0.18,
zoom: 1
};
scene.add(new THREE.HemisphereLight(0xb9f6ff, 0x102028, 1.75));
const keyLight = new THREE.DirectionalLight(0xe8fbff, 2.7);
keyLight.position.set(-7, 10, 16);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xff6caa, 1.25);
rimLight.position.set(10, -8, 9);
scene.add(rimLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const markerMaterials = {};
for (const type of Object.keys(legend)) {
markerMaterials[type] = new THREE.MeshStandardMaterial({
color: legend[type].color,
emissive: legend[type].color,
emissiveIntensity: 0.43,
roughness: 0.34,
metalness: 0.12
});
}
const markerBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x10252d,
emissive: 0x071116,
emissiveIntensity: 0.5,
roughness: 0.72,
metalness: 0.18
});
function addBox(parent, sx, sy, sz, x, y, z, material, rotation = 0) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.rotation.z = rotation;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function drawGlyph(ctx, cx, cy, shape, color, scale = 1) {
ctx.save();
ctx.translate(cx, cy);
ctx.scale(scale, scale);
ctx.fillStyle = color;
if (shape === "square") {
ctx.fillRect(-8, -8, 16, 16);
} else if (shape === "diamond") {
ctx.rotate(Math.PI / 4);
ctx.fillRect(-6.5, -6.5, 13, 13);
} else if (shape === "circle") {
ctx.beginPath();
ctx.arc(0, 0, 8, 0, Math.PI * 2);
ctx.fill();
} else if (shape === "cross") {
ctx.fillRect(-3, -9, 6, 18);
ctx.fillRect(-9, -3, 18, 6);
} else if (shape === "hex") {
ctx.beginPath();
ctx.moveTo(-4, -8);
ctx.lineTo(4, -8);
ctx.lineTo(8, 0);
ctx.lineTo(4, 8);
ctx.lineTo(-4, 8);
ctx.lineTo(-8, 0);
ctx.closePath();
ctx.fill();
} else if (shape === "tower") {
ctx.fillRect(-5, -8, 10, 5);
ctx.fillRect(-7, -2, 14, 5);
ctx.fillRect(-9, 4, 18, 5);
}
ctx.restore();
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
// Map board and voxel surroundings.
const mapGroup = new THREE.Group();
scene.add(mapGroup);
const boardMaterial = new THREE.MeshStandardMaterial({
color: 0x0b2027,
roughness: 0.92,
metalness: 0.03
});
const board = addBox(
mapGroup,
22,
14,
0.5,
0,
0,
-0.55,
boardMaterial
);
board.castShadow = false;
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0x21434c,
emissive: 0x102b33,
emissiveIntensity: 0.55,
roughness: 0.6
});
addBox(mapGroup, 22.4, 0.15, 0.18, 0, 7.02, -0.24, edgeMaterial);
addBox(mapGroup, 22.4, 0.15, 0.18, 0, -7.02, -0.24, edgeMaterial);
addBox(mapGroup, 0.15, 14.2, 0.18, -11.02, 0, -0.24, edgeMaterial);
addBox(mapGroup, 0.15, 14.2, 0.18, 11.02, 0, -0.24, edgeMaterial);
const gridPositions = [];
for (let x = -10; x <= 10; x += 1) {
gridPositions.push(x, -6.8, -0.285, x, 6.8, -0.285);
}
for (let y = -6; y <= 6; y += 1) {
gridPositions.push(-10.8, y, -0.285, 10.8, y, -0.285);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x83c5cf,
transparent: true,
opacity: 0.075
})
);
mapGroup.add(grid);
function expandRoute(points) {
const cells = [];
const seen = new Set();
for (let i = 0; i < points.length - 1; i++) {
let [x, y] = points[i];
const [endX, endY] = points[i + 1];
const dx = Math.sign(endX - x);
const dy = Math.sign(endY - y);
while (x !== endX || y !== endY) {
if (x !== endX) x += dx;
else if (y !== endY) y += dy;
const key = `${x},${y}`;
if (!seen.has(key)) {
seen.add(key);
cells.push([x, y]);
}
}
}
return cells;
}
const routeCells = new Set();
const routeMaterials = [];
routes.forEach((route, routeIndex) => {
const cells = expandRoute(route.points);
const material = new THREE.MeshStandardMaterial({
color: route.color,
emissive: route.color,
emissiveIntensity: 0.2,
roughness: 0.48,
metalness: 0.05
});
routeMaterials.push(material);
cells.forEach(([x, y]) => {
routeCells.add(`${x},${y}`);
addBox(
mapGroup,
0.54,
0.54,
0.13,
x,
y,
0.015 + routeIndex * 0.032,
material
);
});
});
// A quiet voxel skyline behind the network.
const buildingMaterials = [
new THREE.MeshStandardMaterial({
color: 0x17313a,
roughness: 0.9,
metalness: 0.03
}),
new THREE.MeshStandardMaterial({
color: 0x1b3740,
roughness: 0.85,
metalness: 0.04
}),
new THREE.MeshStandardMaterial({
color: 0x20343e,
roughness: 0.9,
metalness: 0.02
})
];
let seed = 7319;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
for (let x = -9; x <= 9; x += 2) {
for (let y = -5; y <= 5; y += 2) {
if (routeCells.has(`${x},${y}`) || random() < 0.42) continue;
const width = 0.62 + random() * 0.72;
const height = 0.48 + random() * 0.72;
const depth = 0.08 + random() * 0.18;
addBox(
mapGroup,
width,
height,
depth,
x + (random() - 0.5) * 0.3,
y + (random() - 0.5) * 0.3,
-0.21 + depth / 2,
buildingMaterials[Math.floor(random() * buildingMaterials.length)]
);
}
}
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x123f52,
emissive: 0x082b3c,
emissiveIntensity: 0.42,
roughness: 0.36,
metalness: 0.12
});
for (let x = -10.4; x < 10.6; x += 0.72) {
addBox(
mapGroup,
0.68,
0.62 + Math.sin(x * 1.7) * 0.08,
0.07,
x,
-6.1 + Math.sin(x * 0.55) * 0.12,
-0.22,
waterMaterial
);
}
const accessWalkMaterial = new THREE.MeshStandardMaterial({
color: 0x75959c,
emissive: 0x263d42,
emissiveIntensity: 0.35,
roughness: 0.75
});
markerData
.filter(marker => marker.type === "access")
.forEach(marker => {
const [ax, ay] = marker.anchor;
for (let i = 1; i <= 6; i++) {
const t = i / 7;
addBox(
mapGroup,
0.14,
0.14,
0.1,
THREE.MathUtils.lerp(ax, marker.x, t),
THREE.MathUtils.lerp(ay, marker.y, t),
0.08,
accessWalkMaterial
);
}
});
function makeRouteSprite(route, position) {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 72;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 2, 2, 316, 68, 12);
ctx.fillStyle = "rgba(6, 18, 24, 0.92)";
ctx.fill();
ctx.strokeStyle = route.color;
ctx.lineWidth = 3;
ctx.stroke();
roundedRect(ctx, 11, 11, 50, 50, 8);
ctx.fillStyle = route.color;
ctx.fill();
ctx.fillStyle = "#061116";
ctx.font = "900 27px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(route.id, 36, 36);
ctx.textAlign = "left";
ctx.fillStyle = "#dceff2";
ctx.font = "800 18px ui-monospace, monospace";
ctx.fillText(route.name, 75, 36);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: canvasTexture(canvas),
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.copy(position);
sprite.scale.set(2.7, 0.61, 1);
sprite.renderOrder = 10;
mapGroup.add(sprite);
}
makeRouteSprite(routes[0], new THREE.Vector3(-9.2, 3.15, 0.8));
makeRouteSprite(routes[1], new THREE.Vector3(-9.25, -3.8, 0.8));
makeRouteSprite(routes[2], new THREE.Vector3(-3.4, -5.35, 0.8));
// Marker construction.
const markerRoot = new THREE.Group();
scene.add(markerRoot);
const markers = [];
function makeLabelTexture(marker) {
const state = legend[marker.type];
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 120;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 3, 3, 506, 114, 18);
ctx.fillStyle = "rgba(5, 17, 23, 0.94)";
ctx.fill();
ctx.strokeStyle = state.color;
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = state.color;
ctx.fillRect(12, 14, 5, 92);
drawGlyph(ctx, 48, 60, state.shape, state.color, 1.22);
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = "#efffff";
let nameSize = 26;
if (marker.name.length > 16) nameSize = 22;
if (marker.name.length > 21) nameSize = 19;
ctx.font = `800 ${nameSize}px system-ui, sans-serif`;
ctx.fillText(marker.name, 76, 43);
ctx.fillStyle = state.color;
ctx.font = "800 16px ui-monospace, monospace";
ctx.fillText(`${state.code} / ${typeLabels[marker.type].toUpperCase()}`, 76, 79);
return canvasTexture(canvas);
}
function rebuildMarkerVisual(marker) {
const visual = marker.visual;
while (visual.children.length) visual.remove(visual.children[0]);
const state = legend[marker.type];
const material = markerMaterials[marker.type];
const scale = marker.type === "transfer" ? 1.08 : 1;
addBox(
visual,
1.04,
1.04,
0.13,
0,
0,
0.2,
material
);
addBox(
visual,
0.83,
0.83,
0.18,
0,
0,
0.32,
markerBaseMaterial
);
const shape = state.shape;
if (shape === "square") {
addBox(visual, 0.56, 0.56, 0.26, 0, 0, 0.53, material);
} else if (shape === "diamond") {
addBox(
visual,
0.47,
0.47,
0.26,
0,
0,
0.53,
material,
Math.PI / 4
);
} else if (shape === "circle") {
addBox(visual, 0.28, 0.28, 0.25, 0, 0, 0.53, material);
addBox(visual, 0.25, 0.25, 0.25, 0.28, 0, 0.53, material);
addBox(visual, 0.25, 0.25, 0.25, -0.28, 0, 0.53, material);
addBox(visual, 0.25, 0.25, 0.25, 0, 0.28, 0.53, material);
addBox(visual, 0.25, 0.25, 0.25, 0, -0.28, 0.53, material);
} else if (shape === "cross") {
addBox(visual, 0.66, 0.22, 0.26, 0, 0, 0.53, material);
addBox(visual, 0.22, 0.66, 0.26, 0, 0, 0.53, material);
} else if (shape === "hex") {
const radius = 0.27;
for (let i = 0; i < 6; i++) {
const angle = (Math.PI / 3) * i;
addBox(
visual,
0.23,
0.23,
0.26,
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0.53,
material
);
}
addBox(visual, 0.18, 0.18, 0.27, 0, 0, 0.53, material);
} else if (shape === "tower") {
addBox(visual, 0.42, 0.2, 0.25, 0, 0.27, 0.51, material);
addBox(visual, 0.54, 0.2, 0.25, 0, 0.02, 0.53, material);
addBox(visual, 0.66, 0.2, 0.25, 0, -0.23, 0.55, material);
}
marker.baseScale = scale;
visual.scale.setScalar(scale);
}
function updateMarkerLabel(marker) {
const oldMap = marker.label.material.map;
if (oldMap) oldMap.dispose();
marker.label.material.map = makeLabelTexture(marker);
marker.label.material.needsUpdate = true;
}
function createMarker(data) {
const group = new THREE.Group();
group.position.set(data.x, data.y, 0);
const visual = new THREE.Group();
group.add(visual);
const label = new THREE.Sprite(
new THREE.SpriteMaterial({
map: null,
transparent: true,
depthTest: false,
depthWrite: false
})
);
const labelY =
data.type === "transfer" ? 1.52 :
data.type === "access" ? 1.06 : 1.18;
label.position.set(0, labelY, 1.55);
label.scale.set(3.85, 0.9, 1);
label.renderOrder = 20;
group.add(label);
const marker = {
...data,
group,
visual,
label,
baseScale: 1
};
group.userData.marker = marker;
markerRoot.add(group);
markers.push(marker);
rebuildMarkerVisual(marker);
updateMarkerLabel(marker);
return marker;
}
markerData.forEach(createMarker);
// Editable legend UI.
function markerCount(type) {
return markers.filter(marker => marker.type === type).length;
}
function updateLegendPreview(row, type) {
const state = legend[type];
const preview = row.querySelector(".marker-preview");
preview.className = `marker-preview shape-${state.shape}`;
preview.style.setProperty("--marker-color", state.color);
row.querySelector(".legend-count").textContent =
`${markerCount(type)} marker${markerCount(type) === 1 ? "" : "s"}`;
}
function applyLegendType(type, changedField = null) {
const state = legend[type];
const material = markerMaterials[type];
material.color.set(state.color);
material.emissive.set(state.color);
markers
.filter(marker => marker.type === type)
.forEach(marker => {
if (changedField === "shape" || !marker.visual.children.length) {
rebuildMarkerVisual(marker);
}
updateMarkerLabel(marker);
});
const row = legendRows.querySelector(`[data-type="${type}"]`);
if (row) updateLegendPreview(row, type);
}
function buildLegendRows() {
legendRows.innerHTML = Object.keys(typeLabels)
.map(type => `
<div class="legend-row" data-type="${type}">
<div class="legend-row-head">
<div class="legend-name">
<span class="marker-preview shape-${legend[type].shape}"
style="--marker-color:${legend[type].color}"></span>
<span>${typeLabels[type]}</span>
</div>
<span class="legend-count"></span>
</div>
<div class="legend-controls">
<input type="color"
data-field="color"
value="${legend[type].color}"
aria-label="${typeLabels[type]} marker color">
<select data-field="shape" aria-label="${typeLabels[type]} marker shape">
${shapeOptions.map(([value, label]) => `
<option value="${value}" ${legend[type].shape === value ? "selected" : ""}>
${label}
</option>
`).join("")}
</select>
<input type="text"
data-field="code"
value="${legend[type].code}"
maxlength="6"
spellcheck="false"
aria-label="${typeLabels[type]} marker label code">
</div>
</div>
`)
.join("");
legendRows.querySelectorAll(".legend-row").forEach(row => {
const type = row.dataset.type;
updateLegendPreview(row, type);
row.querySelectorAll("[data-field]").forEach(input => {
input.addEventListener("input", () => {
const field = input.dataset.field;
if (field === "color") {
legend[type].color = input.value;
} else if (field === "shape") {
legend[type].shape = input.value;
} else if (field === "code") {
const cleaned = input.value
.toUpperCase()
.replace(/[^A-Z0-9&+\- ]/g, "")
.slice(0, 6);
if (cleaned !== input.value) input.value = cleaned;
legend[type].code = cleaned || "—";
}
applyLegendType(type, field);
});
input.addEventListener("change", () => {
showToast(
`${typeLabels[type]} legend updated — ${markerCount(type)} markers changed.`
);
});
});
});
}
buildLegendRows();
let toastTimer;
function showToast(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("visible");
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2400);
}
document.querySelector("#resetLegend").addEventListener("click", () => {
Object.keys(defaults).forEach(type => {
legend[type] = { ...defaults[type] };
applyLegendType(type, "shape");
});
buildLegendRows();
showToast("Legend restored to the authority defaults.");
});
document.querySelector("#randomLegend").addEventListener("click", () => {
const colors = [
"#66e3ff", "#ffc857", "#ff609a", "#79efa8",
"#a991ff", "#ff8063", "#74f1df", "#f4e07d"
];
const shapes = shapeOptions.map(option => option[0]);
Object.keys(legend).forEach((type, index) => {
const colorIndex = Math.floor(Math.random() * colors.length);
legend[type].color = colors[colorIndex];
legend[type].shape = shapes[(index + colorIndex) % shapes.length];
legend[type].code = ["STOP", "HUB", "LINK"][index];
applyLegendType(type, "shape");
});
buildLegendRows();
showToast("New marker encodings applied across the entire network.");
});
// Selection and inspection.
let selectedMarker = null;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function findMarker(object) {
let current = object;
while (current) {
if (current.userData.marker) return current.userData.marker;
current = current.parent;
}
return null;
}
function pickMarker(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(markerRoot.children, true);
for (const hit of hits) {
const marker = findMarker(hit.object);
if (marker && marker.group.visible) return marker;
}
return null;
}
function escapeHTML(value) {
return String(value).replace(/[&<>'"]/g, character => ({
"&": "&",
"<": "<",
">": ">",
"'": "'",
"\"": """
})[character]);
}
function updateInspector(marker) {
if (!marker) {
inspector.innerHTML = `
<div class="inspector-kicker">Marker inspector</div>
<h3>Select a map marker</h3>
<p>Click any voxel symbol to inspect its category and route connections.</p>
`;
return;
}
const state = legend[marker.type];
const description =
marker.type === "station" ? "Local boarding island and passenger platform." :
marker.type === "transfer" ? "Interchange connecting multiple rail services." :
"Mobility access point, ramp, lift, or bicycle connection.";
inspector.innerHTML = `
<div class="inspector-kicker">${escapeHTML(typeLabels[marker.type])} marker</div>
<h3>${escapeHTML(marker.name)}</h3>
<p>${description}</p>
<div class="inspector-meta">
<span class="meta-pill">${escapeHTML(state.code)}</span>
<span class="meta-pill">${escapeHTML(state.shape)}</span>
<span class="meta-pill">${escapeHTML(marker.lines.join(" · "))}</span>
</div>
`;
}
function selectMarker(marker) {
selectedMarker = marker;
updateInspector(marker);
}
// Custom orthographic camera controls.
function updateCamera() {
const { radius, theta, phi } = cameraSpherical;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * sinPhi * Math.cos(theta),
cameraTarget.z + radius * Math.cos(phi)
);
camera.zoom = cameraSpherical.zoom;
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function panPixels(dx, dy) {
const rect = renderer.domElement.getBoundingClientRect();
const worldPerPixel =
(camera.top - camera.bottom) /
(camera.zoom * rect.height);
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 1);
cameraTarget.addScaledVector(right, -dx * worldPerPixel);
cameraTarget.addScaledVector(up, dy * worldPerPixel);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -9, 9);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, -6, 6);
updateCamera();
}
function resetView() {
cameraTarget.set(0, 0, 0);
cameraSpherical.theta = -0.11;
cameraSpherical.phi = 0.18;
cameraSpherical.zoom = 1;
updateCamera();
}
document.querySelector("#resetView").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
const pointers = new Map();
let pinchStartDistance = 0;
let pinchStartZoom = 1;
let pinchLastMiddle = null;
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);
}
function pointerMiddle() {
const values = [...pointers.values()];
if (values.length < 2) return { x: 0, y: 0 };
return {
x: (values[0].x + values[1].x) / 2,
y: (values[0].y + values[1].y) / 2
};
}
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button,
moved: false
});
if (pointers.size === 2) {
pinchStartDistance = pointerDistance();
pinchStartZoom = cameraSpherical.zoom;
pinchLastMiddle = pointerMiddle();
}
});
renderer.domElement.addEventListener("pointermove", event => {
const pointerState = pointers.get(event.pointerId);
if (!pointerState) {
const hovered = pickMarker(event.clientX, event.clientY);
renderer.domElement.style.cursor = hovered ? "pointer" : "grab";
if (hovered) {
const state = legend[hovered.type];
hoverTip.textContent = `${hovered.name} · ${state.code}`;
hoverTip.style.display = "block";
hoverTip.style.left =
`${Math.min(event.clientX + 14, window.innerWidth - 245)}px`;
hoverTip.style.top =
`${Math.min(event.clientY + 14, window.innerHeight - 50)}px`;
} else {
hoverTip.style.display = "none";
}
return;
}
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 0) pointerState.moved = true;
if (pointers.size === 1) {
if (pointerState.button === 0 || event.pointerType !== "mouse") {
cameraSpherical.theta -= dx * 0.006;
cameraSpherical.phi = THREE.MathUtils.clamp(
cameraSpherical.phi + dy * 0.005,
0.07,
1.18
);
updateCamera();
} else {
panPixels(dx, dy);
}
} else if (pointers.size === 2) {
const distance = pointerDistance();
const middle = pointerMiddle();
if (pinchStartDistance > 0) {
cameraSpherical.zoom = THREE.MathUtils.clamp(
pinchStartZoom * distance / pinchStartDistance,
0.58,
3.2
);
}
if (pinchLastMiddle) {
panPixels(
middle.x - pinchLastMiddle.x,
middle.y - pinchLastMiddle.y
);
}
pinchLastMiddle = middle;
updateCamera();
}
renderer.domElement.style.cursor = "grabbing";
hoverTip.style.display = "none";
});
function finishPointer(event, cancelled = false) {
const pointerState = pointers.get(event.pointerId);
if (
pointerState &&
!cancelled &&
!pointerState.moved &&
pointerState.button === 0 &&
event.pointerType === "mouse"
) {
const marker = pickMarker(event.clientX, event.clientY);
if (marker) selectMarker(marker);
}
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchStartDistance = 0;
pinchLastMiddle = null;
}
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", event => finishPointer(event));
renderer.domElement.addEventListener("pointercancel", event => finishPointer(event, true));
renderer.domElement.addEventListener("pointerleave", () => {
hoverTip.style.display = "none";
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraSpherical.zoom = THREE.MathUtils.clamp(
cameraSpherical.zoom * Math.exp(-event.deltaY * 0.0011),
0.58,
3.2
);
updateCamera();
}, { passive: false });
let labelsVisible = true;
document.querySelector("#labelsToggle").addEventListener("click", event => {
labelsVisible = !labelsVisible;
markers.forEach(marker => {
marker.label.visible = labelsVisible;
});
event.currentTarget.textContent = labelsVisible ? "Labels on" : "Labels off";
showToast(labelsVisible ? "Marker labels shown." : "Marker labels hidden.");
});
const legendToggle = document.querySelector("#legendToggle");
legendToggle.addEventListener("click", () => {
const closed = legendPanel.classList.toggle("closed");
legendToggle.setAttribute("aria-expanded", String(!closed));
});
if (window.innerWidth <= 760) {
legendPanel.classList.add("closed");
legendToggle.setAttribute("aria-expanded", "false");
}
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement ||
event.target instanceof HTMLSelectElement) return;
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "l") {
document.querySelector("#labelsToggle").click();
}
});
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const aspect = width / Math.max(height, 1);
const viewHeight = Math.max(14.5, 24 / aspect);
renderer.setSize(width, height, false);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
markers.forEach(marker => {
const pulse = marker === selectedMarker
? 1 + Math.sin(time * 4.2) * 0.045
: 1;
marker.visual.scale.setScalar(marker.baseScale * pulse);
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```