Prompt specification
Build or customize the Three.js 3D scene "Original Two-Line Metro Interchange" 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: Original Two-Line Metro Interchange
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/original-two-line-metro-interchange-x2151
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build a compact underground station cutaway with clear platform levels, passages, and signs. Move passengers along actual paths and keep route identities consistent.
Working Three.js Starter (original-two-line-metro-interchange-x2151):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Underground Station</title>
<style>
:root {
color-scheme: dark;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071019;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
color: #e9f4f7;
background: rgba(5, 14, 22, 0.84);
border: 1px solid rgba(151, 207, 219, 0.24);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(8px);
}
#title-panel {
top: 18px;
left: 18px;
padding: 14px 17px;
pointer-events: none;
}
#title-panel h1 {
margin: 0 0 5px;
font-size: 16px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#title-panel p {
margin: 0;
color: #9fb7c0;
font-size: 11px;
line-height: 1.55;
}
#controls {
top: 18px;
right: 18px;
display: flex;
gap: 7px;
padding: 8px;
}
button {
border: 1px solid #35505c;
background: #10232e;
color: #dff8ff;
padding: 8px 10px;
font: inherit;
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
border-color: #59d8ec;
background: #173442;
}
button:active {
transform: translateY(1px);
}
#legend {
bottom: 18px;
left: 18px;
min-width: 240px;
padding: 13px 15px;
pointer-events: none;
}
.route-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
color: #c6d8dd;
font-size: 11px;
}
.route-chip {
display: inline-grid;
width: 23px;
height: 23px;
place-items: center;
color: #061017;
font-weight: 900;
border-radius: 2px;
}
.route-a {
background: #22dff1;
box-shadow: 0 0 13px rgba(34, 223, 241, 0.35);
}
.route-b {
background: #ffab3f;
box-shadow: 0 0 13px rgba(255, 171, 63, 0.32);
}
#status {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid rgba(151, 207, 219, 0.16);
color: #819ba5;
font-size: 10px;
line-height: 1.55;
}
#hint {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 10;
padding: 9px 12px;
color: #8ca5ae;
font-size: 10px;
pointer-events: none;
}
@media (max-width: 700px) {
#title-panel {
right: 18px;
}
#title-panel p,
#hint {
display: none;
}
#legend {
right: 18px;
min-width: 0;
}
#controls {
top: auto;
right: 18px;
bottom: 122px;
flex-direction: column;
}
}
</style>
</head>
<body>
<section id="title-panel" class="panel">
<h1>Nova Underground</h1>
<p>Voxel station cutaway · Level 01 / Level 02<br />Live passenger route simulation</p>
</section>
<section id="controls" class="panel">
<button id="pause" type="button">Pause</button>
<button id="paths" type="button">Hide Paths</button>
<button id="reset" type="button">Reset View</button>
</section>
<section id="legend" class="panel">
<div class="route-row">
<span class="route-chip route-a">A</span>
<span>Northbound · lower platform</span>
</div>
<div class="route-row">
<span class="route-chip route-b">B</span>
<span>Concourse link · stair passage</span>
</div>
<div id="status">Loading station…</div>
</section>
<div id="hint" class="panel">Drag to orbit · Wheel to zoom · Space to pause · R to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene and orthographic camera
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.Fog(0x071019, 48, 78);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
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 voxel underground station cutaway"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.75, -0.45);
let cameraTheta = 0.68;
let cameraPhi = 0.82;
let cameraZoom = 1;
const world = new THREE.Group();
scene.add(world);
const routeDecor = new THREE.Group();
world.add(routeDecor);
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = 9.2;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
const radius = 32;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z + radius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9ddff, 0x2b1d12, 2.1));
const sun = new THREE.DirectionalLight(0xfff3dc, 3.0);
sun.position.set(10, 18, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00035;
scene.add(sun);
const cyanLight = new THREE.PointLight(0x22dff1, 18, 9, 2);
cyanLight.position.set(-7.2, 2.1, 0.8);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffa43a, 18, 9, 2);
amberLight.position.set(5.8, 3.8, -3.2);
scene.add(amberLight);
// ------------------------------------------------------------
// Materials and helpers
// ------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.04,
...options
});
const mat = {
earth: material(0x30251c),
earthDark: material(0x211a15),
concrete: material(0x7d8888),
concreteLight: material(0xaab3af),
platform: material(0xc9c8ba),
tile: material(0xd9d6c8),
tileAlt: material(0xc4c4b8),
dark: material(0x20292e),
rail: material(0x717b7e, { metalness: 0.65, roughness: 0.38 }),
sleeper: material(0x4b3c2d),
yellow: material(0xf2c447),
orange: material(0xff9f35),
cyan: material(0x20d9ec),
train: material(0xe7e6dd),
trainDark: material(0x28363b),
window: material(0x4bc9dc, {
emissive: 0x176b78,
emissiveIntensity: 0.75,
roughness: 0.25
}),
light: material(0xffefcc, {
emissive: 0xffd995,
emissiveIntensity: 1.1
}),
red: material(0xe24c47),
bench: material(0x805538),
black: material(0x171d20),
skin: [
material(0xe6b08b),
material(0xb97955),
material(0x8d5c43),
material(0xf1c7a4)
],
pants: material(0x26343e),
hair: material(0x292522)
};
function voxel(parent, size, position, meshMaterial, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
meshMaterial
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(481516);
// ------------------------------------------------------------
// Canvas-based voxel station signs
// ------------------------------------------------------------
function makeSignTexture(lines, accent, width = 512, height = 160) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(7, 18, 25, 0.96)";
context.fillRect(0, 0, width, height);
context.fillStyle = accent;
context.fillRect(0, 0, 14, height);
context.fillRect(14, 0, width - 14, 5);
context.fillRect(14, height - 5, width - 14, 5);
context.strokeStyle = accent;
context.lineWidth = 4;
context.strokeRect(2, 2, width - 4, height - 4);
const slot = height / (lines.length + 0.55);
const fontSize = Math.min(52, slot * 0.66);
lines.forEach((line, index) => {
context.fillStyle = index === 0 ? accent : "#e4f1f3";
context.font = `700 ${fontSize}px ui-monospace, Menlo, Consolas, monospace`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(
line,
width / 2 + 6,
slot * (index + 0.85),
width - 55
);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function addSign(lines, accent, position, worldWidth, worldHeight) {
const texture = makeSignTexture(lines, accent);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(position[0], position[1], position[2]);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 20;
world.add(sprite);
return sprite;
}
function makeBadgeTexture(letter, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "#101a20";
context.fillRect(0, 0, 128, 128);
context.fillStyle = color;
context.fillRect(8, 8, 112, 112);
context.fillStyle = "#071018";
context.font = "900 78px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(letter, 64, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// ------------------------------------------------------------
// Underground structure
// ------------------------------------------------------------
const FLOOR_Y = 0.3;
const UPPER_Y = 3.2;
// Earth and cutaway walls.
voxel(world, [25, 1.0, 14], [0, -1.0, 0], mat.earth);
voxel(world, [24, 5.2, 0.5], [0, 2.1, -6.75], mat.earthDark);
voxel(world, [0.5, 4.8, 13.5], [-11.75, 1.9, 0], mat.concrete);
voxel(world, [0.5, 4.8, 13.5], [11.75, 1.9, 0], mat.concrete);
// Soil strata on the back wall.
voxel(world, [24.2, 0.34, 0.12], [0, 0.05, -6.46], mat.earth);
voxel(world, [24.2, 0.25, 0.12], [0, 0.55, -6.46], material(0x4a3524));
voxel(world, [24.2, 0.28, 0.12], [0, 3.95, -6.46], mat.earth);
// Lower platform slab and tiled surface.
voxel(world, [20, 0.5, 4.8], [0, 0, 0], mat.concreteLight);
for (let i = 0; i < 20; i++) {
voxel(
world,
[0.965, 0.05, 4.55],
[-9.5 + i, 0.275, 0],
i % 2 === 0 ? mat.tile : mat.tileAlt,
false
);
}
// Platform safety edges.
voxel(world, [20, 0.055, 0.13], [0, 0.325, 2.13], mat.yellow, false);
voxel(world, [20, 0.055, 0.13], [0, 0.325, -2.13], mat.yellow, false);
for (let i = 0; i < 40; i++) {
voxel(
world,
[0.19, 0.065, 0.34],
[-9.55 + i * 0.49, 0.333, 1.89],
mat.dark,
false
);
voxel(
world,
[0.19, 0.065, 0.34],
[-9.55 + i * 0.49, 0.333, -1.89],
mat.dark,
false
);
}
// Track bed, sleepers and rails.
voxel(world, [23, 0.25, 1.95], [0, -0.14, 3.55], mat.dark);
voxel(world, [23, 0.08, 1.55], [0, 0.015, 3.55], mat.sleeper, false);
for (let i = 0; i < 28; i++) {
voxel(
world,
[0.16, 0.11, 1.55],
[-10.85 + i * 0.8, 0.08, 3.55],
mat.sleeper,
false
);
}
voxel(world, [23, 0.10, 0.09], [0, 0.16, 3.13], mat.rail);
voxel(world, [23, 0.10, 0.09], [0, 0.16, 3.97], mat.rail);
// Upper concourse and its supporting columns.
voxel(world, [12, 0.5, 2.6], [0, 2.95, -5.4], mat.concreteLight);
voxel(world, [12, 0.07, 2.5], [0, 3.235, -5.4], mat.platform, false);
for (const x of [-5, -0.5, 4.5]) {
voxel(world, [0.48, 3.7, 0.48], [x, 1.35, -5.85], mat.concrete);
voxel(world, [0.75, 0.2, 0.75], [x, -0.35, -5.85], mat.concreteLight);
}
// Upper-level guard rail, leaving the stair landing open.
voxel(world, [10.1, 0.08, 0.08], [-0.95, 4.18, -4.07], mat.rail);
for (let x = -6; x <= 4; x += 2) {
voxel(world, [0.08, 1.0, 0.08], [x, 3.7, -4.07], mat.rail);
}
// Ceiling lights under the concourse.
for (const x of [-4.2, -0.6, 3.0]) {
voxel(world, [1.8, 0.08, 0.22], [x, 2.66, -5.25], mat.light, false);
}
// ------------------------------------------------------------
// Voxel stairway: the physical passage used by Route B
// ------------------------------------------------------------
const stairCount = 9;
const stairDepth = 0.42;
const stairWidth = 2.05;
const stairX = 5.25;
const stairRise = (UPPER_Y - FLOOR_Y) / stairCount;
for (let i = 0; i < stairCount; i++) {
const centerZ = -0.85 - i * stairDepth;
const top = FLOOR_Y + (i + 1) * stairRise;
const bottom = -0.22;
const height = top - bottom;
voxel(
world,
[stairWidth, height, stairDepth],
[stairX, bottom + height / 2, centerZ],
i % 2 === 0 ? mat.concreteLight : mat.concrete
);
voxel(
world,
[0.10, 0.035, stairDepth - 0.05],
[stairX - stairWidth / 2 + 0.12, top + 0.02, centerZ],
mat.orange,
false
);
}
// Landing joins the last step to the upper floor.
voxel(
world,
[2.3, 0.35, 0.48],
[stairX, UPPER_Y - 0.175, -3.95],
mat.concreteLight
);
// ------------------------------------------------------------
// Station furniture
// ------------------------------------------------------------
function makeBench(x, z) {
voxel(world, [1.9, 0.18, 0.58], [x, 0.62, z], mat.bench);
voxel(world, [1.9, 0.65, 0.14], [x, 0.97, z - 0.22], mat.bench);
voxel(world, [0.16, 0.48, 0.42], [x - 0.72, 0.31, z], mat.dark);
voxel(world, [0.16, 0.48, 0.42], [x + 0.72, 0.31, z], mat.dark);
}
makeBench(-6.4, -1.55);
makeBench(-2.2, -1.55);
function makeBin(x, z) {
voxel(world, [0.42, 0.85, 0.42], [x, 0.73, z], mat.dark);
voxel(world, [0.48, 0.12, 0.48], [x, 1.2, z], mat.concreteLight);
voxel(world, [0.25, 0.07, 0.22], [x, 1.28, z], mat.black, false);
}
makeBin(3.85, -1.6);
makeBin(-8.5, -1.55);
// Structural columns on the lower platform.
for (const x of [-9.0, -4.5, 0, 8.5]) {
voxel(world, [0.42, 3.3, 0.42], [x, 1.95, -1.0], mat.concrete);
voxel(world, [0.62, 0.16, 0.62], [x, 0.38, -1.0], mat.concreteLight);
}
// Concourse fare gate aligned with the Route B exit.
voxel(world, [0.34, 1.05, 0.9], [-5.22, 3.73, -5.15], mat.dark);
voxel(world, [0.34, 1.05, 0.9], [-4.38, 3.73, -5.15], mat.dark);
voxel(world, [0.75, 0.08, 0.75], [-4.8, 4.28, -5.15], mat.orange);
voxel(world, [0.08, 0.4, 0.06], [-4.66, 4.02, -5.12], mat.cyan, false);
// ------------------------------------------------------------
// Voxel train on the foreground track
// ------------------------------------------------------------
const train = new THREE.Group();
world.add(train);
for (const carX of [-6.1, 0, 6.1]) {
voxel(train, [5.55, 0.28, 1.3], [carX, 0.42, 3.55], mat.trainDark);
voxel(train, [5.55, 1.15, 1.45], [carX, 1.1, 3.55], mat.train);
voxel(train, [5.35, 0.16, 1.25], [carX, 1.75, 3.55], mat.concreteLight);
for (const side of [-1, 1]) {
const z = 3.55 + side * 0.742;
for (const offset of [-1.75, -0.55, 0.65, 1.85]) {
voxel(
train,
[0.82, 0.48, 0.035],
[carX + offset, 1.25, z],
mat.window,
false
);
}
voxel(
train,
[5.45, 0.11, 0.035],
[carX, 0.78, z],
mat.cyan,
false
);
}
voxel(train, [0.05, 0.85, 1.48], [carX - 2.79, 1.15, 3.55], mat.dark);
voxel(train, [0.05, 0.85, 1.48], [carX + 2.79, 1.15, 3.55], mat.dark);
}
// ------------------------------------------------------------
// Route definitions
// ------------------------------------------------------------
const routeDefinitions = {
A: {
id: "A",
name: "Northbound",
color: 0x22dff1,
css: "#22dff1",
destination: "NORTHBOUND"
},
B: {
id: "B",
name: "Concourse Link",
color: 0xffab3f,
css: "#ffab3f",
destination: "UPPER CONCOURSE"
}
};
const routeAPoints = [
new THREE.Vector3(-9.35, FLOOR_Y + 0.012, 1.15),
new THREE.Vector3(9.35, FLOOR_Y + 0.012, 1.15)
];
const routeBPoints = [
new THREE.Vector3(-7.8, FLOOR_Y + 0.012, 0.25),
new THREE.Vector3(4.1, FLOOR_Y + 0.012, 0.25),
new THREE.Vector3(stairX, FLOOR_Y + 0.012, 0.25),
new THREE.Vector3(stairX, FLOOR_Y + 0.012, -0.45)
];
let previousStepTop = FLOOR_Y;
for (let i = 0; i < stairCount; i++) {
const centerZ = -0.85 - i * stairDepth;
const edgeZ = centerZ + stairDepth / 2;
const top = FLOOR_Y + (i + 1) * stairRise;
// Horizontal approach to the riser, then the vertical riser.
routeBPoints.push(new THREE.Vector3(stairX, previousStepTop, edgeZ));
routeBPoints.push(new THREE.Vector3(stairX, top, edgeZ));
routeBPoints.push(new THREE.Vector3(stairX, top, centerZ));
previousStepTop = top;
}
routeBPoints.push(
new THREE.Vector3(stairX, UPPER_Y + 0.012, -3.95),
new THREE.Vector3(3.6, UPPER_Y + 0.012, -4.75),
new THREE.Vector3(-4.8, UPPER_Y + 0.012, -4.75),
new THREE.Vector3(-4.8, UPPER_Y + 0.012, -5.78)
);
function makePath(points) {
const cumulative = [0];
let total = 0;
for (let i = 1; i < points.length; i++) {
total += points[i].distanceTo(points[i - 1]);
cumulative.push(total);
}
return { points, cumulative, total };
}
const routePaths = {
A: makePath(routeAPoints),
B: makePath(routeBPoints)
};
function samplePath(path, distance) {
const d = THREE.MathUtils.clamp(distance, 0, path.total);
let segment = 1;
while (
segment < path.cumulative.length - 1 &&
path.cumulative[segment] < d
) {
segment++;
}
const startDistance = path.cumulative[segment - 1];
const endDistance = path.cumulative[segment];
const alpha =
endDistance === startDistance
? 0
: (d - startDistance) / (endDistance - startDistance);
const start = path.points[segment - 1];
const end = path.points[segment];
return {
position: new THREE.Vector3().lerpVectors(start, end, alpha),
tangent: new THREE.Vector3().subVectors(end, start).normalize()
};
}
function addPathGuide(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
dashSize: 0.22,
gapSize: 0.12,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
line.computeLineDistances();
routeDecor.add(line);
return line;
}
addPathGuide(routeAPoints, routeDefinitions.A.color);
addPathGuide(routeBPoints, routeDefinitions.B.color);
// Physical route inlays.
for (let x = -9; x <= 9; x += 1.35) {
voxel(
routeDecor,
[0.65, 0.035, 0.075],
[x, FLOOR_Y + 0.025, 1.15],
mat.cyan,
false
);
}
for (let x = -7.3; x <= 3.8; x += 1.25) {
voxel(
routeDecor,
[0.65, 0.035, 0.075],
[x, FLOOR_Y + 0.025, 0.25],
mat.orange,
false
);
}
for (let x = 3.5; x >= -4.4; x -= 1.2) {
voxel(
routeDecor,
[0.65, 0.035, 0.075],
[x, UPPER_Y + 0.025, -4.75],
mat.orange,
false
);
}
// ------------------------------------------------------------
// Passenger models and animation
// ------------------------------------------------------------
const passengers = [];
function createPassenger(routeId, index) {
const route = routeDefinitions[routeId];
const group = new THREE.Group();
const skin = mat.skin[Math.floor(random() * mat.skin.length)];
const routeMaterial = material(route.color, {
emissive: route.color,
emissiveIntensity: 0.08,
roughness: 0.76
});
// The model faces local +X.
voxel(group, [0.34, 0.48, 0.30], [0, 0.69, 0], routeMaterial);
voxel(group, [0.29, 0.29, 0.29], [0, 1.08, 0], skin);
voxel(group, [0.30, 0.10, 0.30], [-0.02, 1.25, 0], mat.hair);
voxel(group, [0.18, 0.40, 0.15], [0.01, 0.27, 0.09], mat.pants);
voxel(group, [0.18, 0.40, 0.15], [0.01, 0.27, -0.09], mat.pants);
voxel(group, [0.27, 0.10, 0.17], [0.06, 0.07, 0.09], mat.black);
voxel(group, [0.27, 0.10, 0.17], [0.06, 0.07, -0.09], mat.black);
voxel(group, [0.15, 0.40, 0.13], [0.01, 0.67, 0.22], routeMaterial);
voxel(group, [0.15, 0.40, 0.13], [0.01, 0.67, -0.22], routeMaterial);
// Backpack and route-colored chest plate.
voxel(group, [0.18, 0.38, 0.25], [-0.25, 0.73, 0], mat.dark);
voxel(group, [0.04, 0.14, 0.22], [0.185, 0.76, 0], mat.black, false);
voxel(group, [0.045, 0.08, 0.08], [0.21, 0.76, 0], routeMaterial, false);
const badge = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeBadgeTexture(route.id, route.css),
transparent: true,
depthTest: false,
depthWrite: false
})
);
badge.position.set(0, 1.45, 0);
badge.scale.set(0.34, 0.34, 1);
badge.renderOrder = 25;
group.add(badge);
group.userData = {
passengerId: `${routeId}-${String(index + 1).padStart(2, "0")}`,
route: route.id,
destination: route.destination,
yaw: 0
};
world.add(group);
const path = routePaths[routeId];
const progress = (index + 0.5) / index;
passengers.push({
group,
routeId,
path,
distance: path.total * progress,
direction: index % 2 === 0 ? 1 : -1,
speed:
routeId === "A"
? 0.72 + random() * 0.38
: 0.63 + random() * 0.31,
wait: 0
});
}
for (let i = 0; i < 10; i++) {
createPassenger("A", i);
}
for (let i = 0; i < 7; i++) {
createPassenger("B", i);
}
function shortestAngleDifference(a, b) {
return Math.atan2(Math.sin(b - a), Math.cos(b - a));
}
function updatePassengers(delta) {
for (const passenger of passengers) {
if (passenger.wait > 0) {
passenger.wait -= delta;
continue;
}
passenger.distance +=
passenger.speed * passenger.direction * delta;
if (passenger.distance >= passenger.path.total) {
passenger.distance = passenger.path.total;
passenger.direction = -1;
passenger.wait = 0.55;
} else if (passenger.distance <= 0) {
passenger.distance = 0;
passenger.direction = 1;
passenger.wait = 0.55;
}
const sample = samplePath(
passenger.path,
passenger.distance
);
passenger.group.position.copy(sample.position);
// Vertical stair risers have no horizontal heading.
if (Math.abs(sample.tangent.x) + Math.abs(sample.tangent.z) > 0.001) {
const targetYaw = Math.atan2(
-sample.tangent.z,
sample.tangent.x
);
passenger.group.userData.yaw +=
shortestAngleDifference(
passenger.group.userData.yaw,
targetYaw
) * Math.min(1, delta * 11);
passenger.group.rotation.y =
passenger.group.userData.yaw;
}
}
}
// ------------------------------------------------------------
// Station signage
// ------------------------------------------------------------
addSign(
["NOVA UNDERGROUND", "CENTRAL / VAULT 07"],
"#22dff1",
[0, 4.75, -6.42],
7.8,
1.75
);
addSign(
["A NORTHBOUND", "PLATFORM 01"],
"#22dff1",
[-7.3, 2.65, -1.4],
4.8,
1.18
);
addSign(
["B UPPER LINK", "STAIR 02"],
"#ffab3f",
[7.25, 2.5, -1.45],
4.3,
1.18
);
addSign(
["PLATFORM 01", "WESTBOUND / NORTHBOUND"],
"#22dff1",
[0.3, 1.45, 2.34],
5.3,
1.12
);
addSign(
["LEVEL 02", "CONCOURSE / TRANSFER"],
"#ffab3f",
[-0.4, 4.8, -5.25],
5.7,
1.25
);
addSign(
["A NORTHBOUND"],
"#22dff1",
[6.0, 1.9, 4.34],
3.1,
0.72
);
// Small physical sign supports.
voxel(world, [0.09, 2.1, 0.09], [-9.15, 1.55, -1.42], mat.dark);
voxel(world, [0.09, 2.1, 0.09], [8.75, 1.55, -1.42], mat.dark);
// ------------------------------------------------------------
// Custom camera controls
// ------------------------------------------------------------
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + deltaY * 0.005,
0.35,
1.32
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.8
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraTheta = 0.68;
cameraPhi = 0.82;
cameraZoom = 1;
updateCamera();
}
// ------------------------------------------------------------
// UI and animation
// ------------------------------------------------------------
let paused = false;
let pathsVisible = true;
const pauseButton = document.getElementById("pause");
const pathsButton = document.getElementById("paths");
const status = document.getElementById("status");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
pathsButton.addEventListener("click", () => {
pathsVisible = !pathsVisible;
routeDecor.visible = pathsVisible;
pathsButton.textContent = pathsVisible
? "Hide Paths"
: "Show Paths";
});
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(
Math.min(window.devicePixelRatio || 1, 1.75)
);
updateCamera();
});
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (!paused) {
updatePassengers(delta);
}
cyanLight.intensity = 17 + Math.sin(elapsed * 2.1) * 1.3;
amberLight.intensity = 17 + Math.sin(elapsed * 2.1 + 2.4) * 1.2;
const countA = passengers.filter((p) => p.routeId === "A").length;
const countB = passengers.filter((p) => p.routeId === "B").length;
status.innerHTML =
`${countA} passengers on Route A · ${countB} on Route B<br />` +
`All route identities remain locked to their assigned paths.`;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```