Prompt specification
Build or customize the Three.js 3D scene "Two Platforms and a Transfer Stair" 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: Two Platforms and a Transfer Stair
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-platforms-and-a-transfer-stair-x2149
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing transit interchanges between platforms. Model two platforms connected by a stair and accessible alternate path. Show walking distances separately from the distance between the train tracks. Stylized solid forms.
Working Three.js Starter (two-platforms-and-a-transfer-stair-x2149):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Transit Platform Interchange</title>
<style>
:root {
--ink: #25313a;
--muted: #69747c;
--paper: rgba(250, 249, 245, 0.94);
--line: rgba(37, 49, 58, 0.13);
--orange: #ef783e;
--teal: #169c89;
--purple: #7658d8;
--yellow: #efbf48;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eceae3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
max-width: 440px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.brand p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.metrics {
position: fixed;
z-index: 10;
top: 22px;
right: 22px;
width: 328px;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 55px rgba(43, 53, 59, 0.13);
backdrop-filter: blur(14px);
}
.metrics-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.metrics-head strong {
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scale-badge {
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.metric-card {
position: relative;
margin-top: 8px;
padding: 13px 13px 12px 16px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.64);
}
.metric-card::before {
position: absolute;
inset: 0 auto 0 0;
width: 5px;
content: "";
background: var(--accent);
}
.metric-card.stair {
--accent: var(--orange);
}
.metric-card.accessible {
--accent: var(--teal);
}
.metric-card.track {
--accent: var(--purple);
}
.metric-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
}
.metric-title {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.metric-value {
flex: 0 0 auto;
color: var(--accent);
font-size: 24px;
font-weight: 850;
letter-spacing: -0.05em;
}
.metric-value small {
margin-left: 3px;
font-size: 12px;
letter-spacing: 0;
}
.metric-sub {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.note {
margin: 12px 2px 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.legend {
position: fixed;
z-index: 10;
bottom: 22px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 9px 17px;
max-width: min(620px, calc(100vw - 390px));
padding: 12px 15px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(43, 53, 59, 0.1);
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
white-space: nowrap;
}
.swatch {
width: 25px;
height: 5px;
border-radius: 999px;
background: var(--swatch);
}
.controls {
position: fixed;
z-index: 10;
right: 22px;
bottom: 22px;
display: flex;
gap: 8px;
}
button {
appearance: none;
padding: 10px 13px;
border: 1px solid rgba(37, 49, 58, 0.15);
border-radius: 11px;
background: rgba(250, 249, 245, 0.94);
color: var(--ink);
box-shadow: 0 8px 24px rgba(43, 53, 59, 0.1);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover {
transform: translateY(-1px);
}
button[aria-pressed="false"] {
color: #8b9398;
background: rgba(235, 233, 227, 0.94);
}
.help {
position: fixed;
z-index: 9;
left: 24px;
bottom: 88px;
color: #778087;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
top: 0;
left: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
will-change: transform;
}
.label-inner {
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 9px;
background: rgba(250, 249, 245, 0.93);
box-shadow: 0 8px 24px rgba(43, 53, 59, 0.12);
backdrop-filter: blur(8px);
}
.label-title {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.label-value {
margin-top: 2px;
font-size: 11px;
font-weight: 750;
}
.world-label.platform .label-inner {
border-left: 4px solid var(--yellow);
}
.world-label.stair .label-inner {
border-left: 4px solid var(--orange);
}
.world-label.accessible .label-inner {
border-left: 4px solid var(--teal);
}
.world-label.track .label-inner {
border-left: 4px solid var(--purple);
}
.world-label.stair .label-value {
color: #c95727;
}
.world-label.accessible .label-value {
color: #087c6c;
}
.world-label.track .label-value {
color: #6746ca;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #eceae3;
color: var(--muted);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.3s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 15px;
left: 15px;
}
.brand p {
display: none;
}
.metrics {
top: auto;
right: 12px;
bottom: 66px;
width: min(310px, calc(100vw - 24px));
padding: 12px;
}
.metrics-head,
.note {
display: none;
}
.metric-card {
padding: 10px 10px 9px 13px;
}
.metric-value {
font-size: 20px;
}
.legend {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional model of two train platforms"></canvas>
<header class="brand">
<div class="eyebrow">Interchange model</div>
<h1>Platform transfer study</h1>
<p>
Two platforms, a direct stair connection, and a step-free lift route.
Walking distances and rail spacing are shown as separate measurements.
</p>
</header>
<aside class="metrics" aria-label="Interchange measurements">
<div class="metrics-head">
<strong>Distance measures</strong>
<span class="scale-badge">1 unit = 1 metre</span>
</div>
<section class="metric-card stair">
<div class="metric-row">
<span class="metric-title">Stair walking route</span>
<span class="metric-value">21 <small>m</small></span>
</div>
<div class="metric-sub">18 + 18 steps · 4.65 m total rise</div>
</section>
<section class="metric-card accessible">
<div class="metric-row">
<span class="metric-title">Step-free walking route</span>
<span class="metric-value">20 <small>m</small></span>
</div>
<div class="metric-sub">2 lifts · no steps · lift travel excluded</div>
</section>
<section class="metric-card track">
<div class="metric-row">
<span class="metric-title">Train-track centres</span>
<span class="metric-value">8.5 <small>m</small></span>
</div>
<div class="metric-sub">Rail geometry only — this is not a walking route</div>
</section>
<p class="note">
Walking routes are measured between marked interchange points.
The purple dimension is the centre-to-centre spacing of the two tracks.
</p>
</aside>
<div class="legend" aria-label="Model legend">
<div class="legend-item">
<span class="swatch" style="--swatch: var(--orange)"></span>
Stair link · 21 m walking
</div>
<div class="legend-item">
<span class="swatch" style="--swatch: var(--teal)"></span>
Step-free link · 20 m walking
</div>
<div class="legend-item">
<span class="swatch" style="--swatch: var(--purple)"></span>
Track-centre dimension · 8.5 m
</div>
</div>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<nav class="controls" aria-label="View controls">
<button id="resetView" type="button">Reset view</button>
<button id="planView" type="button">Plan view</button>
<button id="toggleRoutes" type="button" aria-pressed="true">Routes on</button>
</nav>
<div id="labels" aria-hidden="true"></div>
<div id="loading">Building interchange model…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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(0xeceae3);
scene.fog = new THREE.Fog(0xeceae3, 58, 105);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 160);
const target = new THREE.Vector3(0, 2.1, 0);
const view = {
theta: 0.72,
phi: 1.02,
zoom: 1,
radius: 52
};
const hemi = new THREE.HemisphereLight(0xffffff, 0x8c918d, 2.35);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3dc, 3.25);
sun.position.set(-17, 30, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc9e5ef, 0.75);
fill.position.set(18, 12, -15);
scene.add(fill);
const materials = {
ground: new THREE.MeshStandardMaterial({ color: 0xe4e1d8, roughness: 1 }),
base: new THREE.MeshStandardMaterial({ color: 0xd8d4ca, roughness: 0.95 }),
platform: new THREE.MeshStandardMaterial({ color: 0xe9e5dc, roughness: 0.93 }),
platformSide: new THREE.MeshStandardMaterial({ color: 0xaaa69d, roughness: 0.95 }),
ballast: new THREE.MeshStandardMaterial({ color: 0xa9a49a, roughness: 1 }),
sleeper: new THREE.MeshStandardMaterial({ color: 0x68645e, roughness: 0.92 }),
rail: new THREE.MeshStandardMaterial({
color: 0x596168,
roughness: 0.42,
metalness: 0.72
}),
dark: new THREE.MeshStandardMaterial({ color: 0x303b43, roughness: 0.72 }),
orange: new THREE.MeshStandardMaterial({ color: 0xef783e, roughness: 0.66 }),
orangeDark: new THREE.MeshStandardMaterial({ color: 0xa94828, roughness: 0.72 }),
teal: new THREE.MeshStandardMaterial({ color: 0x169c89, roughness: 0.6 }),
tealDark: new THREE.MeshStandardMaterial({ color: 0x0d6c62, roughness: 0.72 }),
purple: new THREE.MeshStandardMaterial({ color: 0x7658d8, roughness: 0.58 }),
yellow: new THREE.MeshStandardMaterial({ color: 0xefbf48, roughness: 0.76 }),
train: new THREE.MeshStandardMaterial({ color: 0x397b9c, roughness: 0.58 }),
trainStripe: new THREE.MeshStandardMaterial({ color: 0xf1c358, roughness: 0.7 }),
glass: new THREE.MeshStandardMaterial({
color: 0x8ecbd1,
roughness: 0.18,
metalness: 0.08,
transparent: true,
opacity: 0.38,
depthWrite: false
}),
green: new THREE.MeshStandardMaterial({ color: 0x6d9a71, roughness: 0.95 }),
trunk: new THREE.MeshStandardMaterial({ color: 0x8b745e, roughness: 1 }),
white: new THREE.MeshStandardMaterial({ color: 0xf6f3eb, roughness: 0.86 })
};
function box(width, height, depth, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent = scene, radialSegments = 12) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, 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(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function boxBeamBetween(a, b, width, depth, material, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, depth),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function coneBetween(a, b, radius, material, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.ConeGeometry(radius, length, 12),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and station base.
box(85, 0.35, 75, 0, -0.64, 0, materials.ground);
box(33.5, 0.42, 28.5, 0, -0.38, 0, materials.base);
const grid = new THREE.GridHelper(36, 18, 0xb6b1a7, 0xc7c2b8);
grid.position.y = -0.155;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// Track bed and rails.
box(16.5, 0.2, 25, 0, -0.01, 0, materials.ballast);
const trackCentres = [-4.25, 4.25];
trackCentres.forEach((trackX) => {
box(3.05, 0.1, 24.5, trackX, 0.1, 0, materials.ballast);
for (let z = -11.55; z <= 11.55; z += 0.9) {
box(2.3, 0.13, 0.24, trackX, 0.18, z, materials.sleeper);
}
[-0.72, 0.72].forEach((offset) => {
box(0.115, 0.14, 24.2, trackX + offset, 0.31, 0, materials.rail);
});
});
// Platform slabs.
function buildPlatform(x, side) {
box(5.5, 0.82, 25, x, 1.14, 0, materials.platformSide);
box(5.46, 0.08, 24.92, x, 1.51, 0, materials.platform);
const edgeX = x + side * 2.55;
box(0.22, 0.055, 24.8, edgeX, 1.575, 0, materials.yellow);
for (let z = -11.8; z <= 11.8; z += 0.8) {
box(0.075, 0.018, 0.24, edgeX + side * 0.02, 1.615, z, materials.dark);
}
// Paving joints.
for (let z = -10; z <= 10; z += 4) {
box(5.1, 0.014, 0.035, x, 1.56, z, materials.platformSide);
}
// Partial canopy at the outer edge.
const canopyX = x + side * 1.8;
box(2.8, 0.2, 11.5, canopyX, 4.25, 5.2, materials.white);
[-0.85, 5.2, 11.25].forEach((z) => {
box(0.13, 2.65, 0.13, canopyX, 2.88, z, materials.dark);
});
// Benches.
[ -5.5, 7.4 ].forEach((z) => {
box(0.72, 0.12, 2.15, x - side * 0.65, 2.2, z, materials.dark);
box(0.12, 0.62, 0.12, x - side * 0.65, 1.9, z - 0.75, materials.dark);
box(0.12, 0.62, 0.12, x - side * 0.65, 1.9, z + 0.75, materials.dark);
});
// Platform sign.
box(0.1, 1.3, 2.15, x + side * 1.25, 3.0, -8.8, materials.dark);
box(0.12, 0.65, 1.6, x + side * 1.25, 3.22, -8.8, materials.white);
}
buildPlatform(-11.25, 1);
buildPlatform(11.25, -1);
// Stylized train on the western track.
function buildTrainCar(z) {
const x = -4.25;
box(2.18, 1.82, 6.65, x, 1.64, z, materials.train);
box(2.03, 0.24, 6.38, x, 2.64, z, materials.white);
box(2.22, 0.18, 6.4, x, 1.12, z, materials.trainStripe);
[-1, 1].forEach((side) => {
[-2.15, -0.72, 0.72, 2.15].forEach((offset) => {
box(
0.035,
0.61,
1.03,
x + side * 1.105,
1.98,
z + offset,
materials.glass
);
});
});
[-2.12, 2.12].forEach((offset) => {
[-0.76, 0.76].forEach((wheelX) => {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.29, 0.22, 14),
materials.dark
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x + wheelX, 0.49, z + offset);
wheel.castShadow = true;
scene.add(wheel);
});
});
}
[-6.9, 0, 6.9].forEach(buildTrainCar);
// Stair construction.
function buildStairs(x0, x1, y0, y1, z, routeMaterial) {
const count = 18;
const stepLength = (x1 - x0) / count;
const rise = (y1 - y0) / count;
for (let i = 0; i < count; i++) {
const x = x0 + (i + 0.5) * stepLength;
const top = y0 + (i + 1) * rise;
box(
Math.abs(stepLength) + 0.045,
0.2,
2.28,
x,
top - 0.1,
z,
materials.platform
);
}
[-1.08, 1.08].forEach((side) => {
boxBeamBetween(
[x0, y0 - 0.12, z + side],
[x1, y1 - 0.12, z + side],
0.16,
0.24,
materials.orangeDark
);
cylinderBetween(
[x0, y0 + 1.02, z + side],
[x1, y1 + 1.02, z + side],
0.055,
materials.orangeDark
);
for (let i = 0; i <= 4; i++) {
const t = i / 4;
const x = x0 + (x1 - x0) * t;
const y = y0 + (y1 - y0) * t;
cylinderBetween(
[x, y, z + side],
[x, y + 1.02, z + side],
0.045,
materials.orangeDark
);
}
});
cylinderBetween(
[x0, y0 + 0.16, z],
[x1, y1 + 0.16, z],
0.065,
routeMaterial
);
}
buildStairs(-8.5, -3, 1.55, 6.18, -1.5, materials.orange);
buildStairs(3, 8.5, 6.18, 1.55, -1.5, materials.orange);
// Orange upper transfer bridge.
box(6.7, 0.27, 2.65, 0, 6.045, -1.5, materials.platform);
[-2.82, -0.18].forEach((z) => {
cylinderBetween(
[-3.25, 7.23, z],
[3.25, 7.23, z],
0.055,
materials.orangeDark
);
cylinderBetween(
[-3.25, 6.78, z],
[3.25, 6.78, z],
0.038,
materials.orangeDark
);
for (let x = -3.1; x <= 3.2; x += 1.25) {
cylinderBetween(
[x, 6.18, z],
[x, 7.23, z],
0.04,
materials.orangeDark
);
}
});
// Teal level-access bridge.
box(18.2, 0.27, 2.45, 0, 6.045, 4.5, materials.platform);
[3.27, 5.73].forEach((z) => {
cylinderBetween(
[-9.05, 7.23, z],
[9.05, 7.23, z],
0.055,
materials.tealDark
);
cylinderBetween(
[-9.05, 6.78, z],
[9.05, 6.78, z],
0.038,
materials.tealDark
);
for (let x = -9; x <= 9.1; x += 1.5) {
cylinderBetween(
[x, 6.18, z],
[x, 7.23, z],
0.04,
materials.tealDark
);
}
});
// Lift shafts and cabins.
function buildLift(x, cabinY) {
const baseY = 1.55;
const topY = 6.3;
const shaftHeight = topY - baseY;
[-0.78, 0.78].forEach((dx) => {
[-0.78, 0.78].forEach((dz) => {
box(
0.12,
shaftHeight,
0.12,
x + dx,
baseY + shaftHeight / 2,
4.5 + dz,
materials.tealDark
);
});
});
box(1.8, 0.15, 1.8, x, topY + 0.05, 4.5, materials.tealDark);
box(1.68, shaftHeight - 0.2, 0.08, x, baseY + shaftHeight / 2, 5.28, materials.glass);
box(1.5, 0.12, 1.5, x, cabinY, 4.5, materials.tealDark);
box(1.42, 1.55, 1.42, x, cabinY + 0.78, 4.5, materials.glass);
box(1.58, 0.1, 1.58, x, cabinY + 1.58, 4.5, materials.tealDark);
}
buildLift(-8.65, 2.0);
buildLift(8.65, 5.05);
// Route overlays.
const routeGroup = new THREE.Group();
scene.add(routeGroup);
cylinderBetween(
[-8.82, 1.72, -1.5],
[-3, 6.35, -1.5],
0.075,
materials.orange,
routeGroup
);
cylinderBetween(
[-3, 6.35, -1.5],
[3, 6.35, -1.5],
0.075,
materials.orange,
routeGroup
);
cylinderBetween(
[3, 6.35, -1.5],
[8.82, 1.72, -1.5],
0.075,
materials.orange,
routeGroup
);
cylinderBetween(
[-8.65, 1.73, 4.5],
[-8.65, 6.36, 4.5],
0.075,
materials.teal,
routeGroup
);
cylinderBetween(
[-8.65, 6.36, 4.5],
[8.65, 6.36, 4.5],
0.075,
materials.teal,
routeGroup
);
cylinderBetween(
[8.65, 6.36, 4.5],
[8.65, 1.73, 4.5],
0.075,
materials.teal,
routeGroup
);
// Interchange-point markers.
function transferMarker(x, z, material) {
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.42, 0.42, 0.055, 32),
material
);
marker.position.set(x, 1.62, z);
marker.receiveShadow = true;
scene.add(marker);
}
transferMarker(-8.8, -1.5, materials.orange);
transferMarker(8.8, -1.5, materials.orange);
transferMarker(-8.8, 4.5, materials.teal);
transferMarker(8.8, 4.5, materials.teal);
// Purple track-centre dimension, deliberately separate from route lines.
const dimensionZ = -11.55;
const dimensionY = 0.78;
cylinderBetween(
[-4.25, dimensionY, dimensionZ],
[4.25, dimensionY, dimensionZ],
0.035,
materials.purple
);
[-4.25, 4.25].forEach((x) => {
cylinderBetween(
[x, 0.32, dimensionZ],
[x, 1.04, dimensionZ],
0.025,
materials.purple
);
});
coneBetween(
[-4.0, dimensionY, dimensionZ],
[-4.34, dimensionY, dimensionZ],
0.13,
materials.purple
);
coneBetween(
[4.0, dimensionY, dimensionZ],
[4.34, dimensionY, dimensionZ],
0.13,
materials.purple
);
// People for scale.
const personMaterials = [
new THREE.MeshStandardMaterial({ color: 0x486a91, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0xe0774f, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0x5c8d72, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0x8b6b9c, roughness: 0.9 })
];
function person(x, y, z, index) {
const clothing = personMaterials[index % personMaterials.length];
const skin = new THREE.MeshStandardMaterial({
color: index % 2 ? 0xd8aa82 : 0x9b674b,
roughness: 0.95
});
[-0.1, 0.1].forEach((legX) => {
cylinderBetween(
[x + legX, y + 0.04, z],
[x + legX, y + 0.61, z],
0.065,
materials.dark
);
});
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.2, 0.58, 10),
clothing
);
torso.position.set(x, y + 0.9, z);
torso.castShadow = true;
scene.add(torso);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.145, 12, 10),
skin
);
head.position.set(x, y + 1.35, z);
head.castShadow = true;
scene.add(head);
cylinderBetween(
[x - 0.2, y + 1.08, z],
[x - 0.28, y + 0.67, z],
0.055,
clothing
);
cylinderBetween(
[x + 0.2, y + 1.08, z],
[x + 0.28, y + 0.67, z],
0.055,
clothing
);
}
person(-10.2, 1.55, -3.8, 0);
person(-12.1, 1.55, 1.3, 1);
person(-9.6, 1.55, -7.2, 2);
person(10.1, 1.55, -2.7, 1);
person(12.0, 1.55, 4.5, 3);
person(9.7, 1.55, -7.1, 2);
person(-1.4, 6.18, -1.5, 0);
person(2.7, 6.18, 4.5, 3);
// Small trees around the station base.
function tree(x, z, scale = 1) {
box(2.3, 0.3, 2.3, x, -0.02, z, materials.platformSide);
cylinderBetween(
[x, 0.1, z],
[x, 1.45 * scale, z],
0.13 * scale,
materials.trunk
);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.92 * scale, 2.15 * scale, 7),
materials.green
);
crown.position.set(x, 2.0 * scale, z);
crown.castShadow = true;
scene.add(crown);
}
tree(-15.1, -10.4, 0.9);
tree(15.2, -10.2, 0.85);
tree(-15.2, 10.6, 0.8);
tree(15.1, 10.2, 0.95);
// DOM labels anchored to 3D positions.
const labels = [];
function addLabel(className, title, value, position) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = `
<div class="label-inner">
<div class="label-title">${title}</div>
${value ? `<div class="label-value">${value}</div>` : ""}
</div>
`;
labelLayer.appendChild(element);
labels.push({ element, position: new THREE.Vector3(...position) });
return element;
}
addLabel("platform", "Platform A", "Westbound", [-11.1, 2.2, -8.2]);
addLabel("platform", "Platform B", "Eastbound", [11.1, 2.2, -8.2]);
const stairLabel = addLabel(
"stair",
"Stair connection",
"21 m walking",
[-0.4, 7.85, -1.5]
);
const accessibleLabel = addLabel(
"accessible",
"Step-free connection",
"20 m walking · 2 lifts",
[0.2, 7.8, 4.5]
);
addLabel(
"track",
"Track-centre spacing",
"8.5 m · rail dimension only",
[0, 1.55, -11.55]
);
// Camera controls implemented directly without addon modules.
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
const minimumWidth = 38;
const viewHeight = Math.max(30, minimumWidth / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
}
function updateCamera() {
const spherical = new THREE.Spherical(view.radius, view.phi, view.theta);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetView() {
view.theta = 0.72;
view.phi = 1.02;
view.zoom = 1;
target.set(0, 2.1, 0);
updateProjection();
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi + dy * 0.005, 0.12, 1.43);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(event.deltaY * 0.001),
0.65,
2.25
);
updateProjection();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateProjection();
updateCamera();
});
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") view.theta += step;
if (event.key === "ArrowRight") view.theta -= step;
if (event.key === "ArrowUp") {
view.phi = Math.max(0.12, view.phi - step);
}
if (event.key === "ArrowDown") {
view.phi = Math.min(1.43, view.phi + step);
}
if (event.key === "+" || event.key === "=") {
view.zoom = Math.min(2.25, view.zoom * 1.08);
updateProjection();
}
if (event.key === "-") {
view.zoom = Math.max(0.65, view.zoom / 1.08);
updateProjection();
}
updateCamera();
});
document.querySelector("#resetView").addEventListener("click", resetView);
document.querySelector("#planView").addEventListener("click", () => {
view.theta = 0;
view.phi = 0.12;
view.zoom = 1.02;
updateProjection();
updateCamera();
});
const routeButton = document.querySelector("#toggleRoutes");
routeButton.addEventListener("click", () => {
const visible = !routeGroup.visible;
routeGroup.visible = visible;
stairLabel.style.display = visible ? "" : "none";
accessibleLabel.style.display = visible ? "" : "none";
routeButton.textContent = visible ? "Routes on" : "Routes off";
routeButton.setAttribute("aria-pressed", String(visible));
});
const projected = new THREE.Vector3();
function updateLabels() {
labels.forEach(({ element, position }) => {
projected.copy(position).project(camera);
const inFront = projected.z > -1 && projected.z < 1;
if (!inFront) {
element.style.visibility = "hidden";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.visibility = "visible";
element.style.transform =
`translate(-50%, -50%) translate(${x.toFixed(1)}px, ${y.toFixed(1)}px)`;
});
}
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateProjection();
updateCamera();
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```