Prompt specification
Build or customize the Three.js 3D scene "Train Station Connection Sequence" 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: Train Station Connection Sequence
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/train-station-connection-sequence-x3427
Scene Description Prompt:
Create a fictional voxel station where visible arrival, transfer, and departure times determine whether connections succeed. One HTML file using Three.js from cdnjs.
Working Three.js Starter (train-station-connection-sequence-x3427):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Nova Junction — Voxel Connection Planner</title>
<style>
:root {
--ink: #eaf7ff;
--muted: #8ba6b8;
--panel: rgba(9, 19, 30, 0.88);
--panel-solid: #0b1825;
--line: rgba(148, 195, 219, 0.17);
--cyan: #58dfd1;
--amber: #ffbd62;
--green: #61e6a5;
--red: #ff737b;
--violet: #b499ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111c;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 14px;
left: 14px;
right: 14px;
height: 64px;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 18px;
padding: 0 17px;
background: rgba(7, 16, 26, 0.9);
border: 1px solid var(--line);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 35px;
height: 35px;
display: grid;
place-items: center;
flex: 0 0 auto;
color: #06151c;
background: var(--cyan);
font: 900 17px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
box-shadow: 4px 4px 0 rgba(88, 223, 209, 0.2);
}
.brand-name {
font: 850 15px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
white-space: nowrap;
}
.brand-sub {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
}
.station-summary {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
color: #b8cbd7;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.station-summary strong {
color: var(--green);
}
.summary-dot {
width: 4px;
height: 4px;
background: #577082;
}
.clock-tools {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 9px;
min-width: 0;
}
.clock {
display: flex;
align-items: center;
gap: 9px;
padding-right: 3px;
font: 800 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
white-space: nowrap;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 14px var(--green);
}
.tool-group {
display: flex;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
}
.tool {
height: 30px;
padding: 0 10px;
border: 0;
border-right: 1px solid var(--line);
background: transparent;
color: #9eb4c3;
cursor: pointer;
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
}
.tool:last-child {
border-right: 0;
}
.tool:hover,
.tool.active {
color: #06151c;
background: var(--cyan);
}
.panel {
position: fixed;
z-index: 8;
top: 92px;
width: 292px;
max-height: calc(100vh - 326px);
overflow: auto;
padding: 15px;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(15px);
scrollbar-width: thin;
scrollbar-color: #355064 transparent;
}
#arrivals-panel {
left: 14px;
}
#departures-panel {
right: 14px;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.eyebrow {
color: var(--muted);
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.panel h2 {
margin: 6px 0 0;
font: 850 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.panel-count {
padding: 6px 7px;
color: var(--cyan);
border: 1px solid rgba(88, 223, 209, 0.28);
background: rgba(88, 223, 209, 0.06);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.panel-note {
margin: 0 0 12px;
color: #7892a5;
font-size: 10px;
line-height: 1.45;
}
.service-list {
display: grid;
gap: 8px;
}
.service-card {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 48px 1fr;
gap: 10px;
padding: 11px 10px;
overflow: hidden;
text-align: left;
border: 1px solid rgba(144, 185, 207, 0.13);
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition: 140ms ease;
}
.service-card:hover {
border-color: rgba(144, 205, 229, 0.45);
background: rgba(255, 255, 255, 0.05);
transform: translateX(2px);
}
.service-card.selected {
border-color: var(--service-color);
background: color-mix(in srgb, var(--service-color) 9%, transparent);
}
.service-card.selected::after {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
background: var(--service-color);
}
.service-time {
padding-top: 2px;
color: var(--service-color);
font: 900 19px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.06em;
}
.service-name {
font-size: 12px;
font-weight: 800;
line-height: 1.2;
}
.service-meta {
margin-top: 5px;
color: #7893a6;
font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.service-status {
display: inline-block;
margin-top: 8px;
color: #9ab0bf;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.service-status.imminent {
color: var(--amber);
}
.service-status.docked {
color: var(--green);
}
#planner {
position: fixed;
z-index: 9;
bottom: 14px;
left: 50%;
width: min(760px, calc(100vw - 640px));
min-width: 520px;
transform: translateX(-50%);
display: grid;
grid-template-columns: 220px 1fr;
background: rgba(8, 18, 28, 0.94);
border: 1px solid rgba(148, 195, 219, 0.23);
box-shadow: 0 20px 55px rgba(0, 0, 0, 0.4);
backdrop-filter: blur(18px);
}
.planner-result {
padding: 18px;
border-right: 1px solid var(--line);
background: rgba(255, 255, 255, 0.018);
}
.result-badge {
display: inline-block;
margin-bottom: 11px;
padding: 6px 8px;
border: 1px solid currentColor;
font: 900 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.result-badge.success {
color: var(--green);
background: rgba(97, 230, 165, 0.07);
}
.result-badge.fail {
color: var(--red);
background: rgba(255, 115, 123, 0.07);
}
#result-title {
margin: 0;
font: 900 20px/1.08 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.04em;
}
#result-note {
margin: 8px 0 0;
color: #8da6b7;
font-size: 11px;
line-height: 1.4;
}
.planner-main {
min-width: 0;
padding: 16px 18px;
}
.planner-instruction {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.planner-instruction p {
margin: 0;
color: #7894a7;
font-size: 10px;
}
#choice-line {
color: #c9dce7;
font-size: 11px;
font-weight: 800;
text-align: right;
}
.timeline {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
position: relative;
}
.time-node {
position: relative;
min-width: 0;
padding-right: 12px;
}
.time-node:not(:last-child)::after {
content: "→";
position: absolute;
top: 20px;
right: 13px;
color: #476074;
font: 800 15px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.time-label {
color: #7894a7;
font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.time-value {
margin-top: 6px;
color: #f0fbff;
font: 900 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.07em;
}
.time-meta {
margin-top: 5px;
color: #7993a5;
font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.time-node.bad .time-value,
.time-node.bad .time-label {
color: var(--red);
}
.time-node.good .time-value,
.time-node.good .time-label {
color: var(--green);
}
.planner-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-top: 14px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
#route-meta {
color: #7d97a9;
font: 700 9px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.03em;
}
#jump-button {
flex: 0 0 auto;
height: 31px;
padding: 0 11px;
border: 1px solid rgba(88, 223, 209, 0.35);
background: rgba(88, 223, 209, 0.08);
color: var(--cyan);
cursor: pointer;
font: 850 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
#jump-button:hover {
color: #06151c;
background: var(--cyan);
}
.scene-hint {
position: fixed;
z-index: 5;
left: 50%;
bottom: 218px;
transform: translateX(-50%);
padding: 7px 10px;
color: rgba(192, 219, 232, 0.62);
background: rgba(4, 12, 20, 0.54);
border: 1px solid rgba(150, 195, 218, 0.1);
pointer-events: none;
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.11em;
text-transform: uppercase;
white-space: nowrap;
}
@media (max-width: 1100px) {
.panel {
width: 260px;
}
#planner {
left: 14px;
right: 14px;
bottom: 14px;
width: auto;
min-width: 0;
transform: none;
}
.scene-hint {
bottom: 220px;
}
.station-summary {
display: none;
}
.topbar {
grid-template-columns: 1fr 1fr;
}
}
@media (max-width: 700px) {
.topbar {
height: 58px;
padding: 0 10px;
}
.brand-sub,
.clock .live-dot,
#reset-button {
display: none;
}
.brand-mark {
width: 30px;
height: 30px;
}
.brand-name {
font-size: 12px;
}
.clock {
font-size: 14px;
}
.tool {
height: 27px;
padding: 0 8px;
}
.panel {
top: 82px;
width: calc(50% - 21px);
max-height: 34vh;
padding: 10px;
}
#arrivals-panel {
left: 10px;
}
#departures-panel {
right: 10px;
}
.panel h2 {
font-size: 13px;
}
.panel-note,
.service-meta {
display: none;
}
.service-card {
grid-template-columns: 43px 1fr;
gap: 6px;
padding: 9px 7px;
}
.service-time {
font-size: 15px;
}
.service-name {
font-size: 10px;
}
#planner {
left: 8px;
right: 8px;
bottom: 8px;
grid-template-columns: 1fr;
}
.planner-result {
padding: 10px 12px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.result-badge {
margin-bottom: 6px;
}
#result-title {
font-size: 15px;
}
#result-note {
display: none;
}
.planner-main {
padding: 11px 12px;
}
.planner-instruction p {
display: none;
}
.time-value {
font-size: 17px;
}
.planner-footer {
margin-top: 9px;
padding-top: 8px;
}
.scene-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive 3D voxel station"></main>
<header class="topbar">
<div class="brand">
<div class="brand-mark">N</div>
<div>
<div class="brand-name">NOVA JUNCTION</div>
<div class="brand-sub">Voxel transit laboratory · Station 09</div>
</div>
</div>
<div class="station-summary">
<span>8 platforms</span>
<span class="summary-dot"></span>
<strong id="link-count">7/16 connections open</strong>
</div>
<div class="clock-tools">
<div class="clock">
<span class="live-dot"></span>
<span id="clock">08:18:00</span>
</div>
<div class="tool-group" aria-label="Simulation speed">
<button class="tool" id="pause-button" type="button">PAUSE</button>
<button class="tool active" data-speed="1" type="button">1×</button>
<button class="tool" data-speed="4" type="button">4×</button>
</div>
<div class="tool-group">
<button class="tool" id="reset-button" type="button">RESET</button>
</div>
</div>
</header>
<aside class="panel" id="arrivals-panel">
<div class="panel-heading">
<div>
<div class="eyebrow">Platform board</div>
<h2>ARRIVALS</h2>
</div>
<div class="panel-count">04</div>
</div>
<p class="panel-note">Select the train bringing you into the junction.</p>
<div class="service-list" id="arrival-list"></div>
</aside>
<aside class="panel" id="departures-panel">
<div class="panel-heading">
<div>
<div class="eyebrow">Platform board</div>
<h2>DEPARTURES</h2>
</div>
<div class="panel-count">04</div>
</div>
<p class="panel-note">Select the outbound train. Platform distance sets transfer time.</p>
<div class="service-list" id="departure-list"></div>
</aside>
<section id="planner" aria-live="polite">
<div class="planner-result">
<div class="result-badge fail" id="result-badge">MISSED</div>
<h2 id="result-title">Connection missed</h2>
<p id="result-note">The train departs before the transfer is complete.</p>
</div>
<div class="planner-main">
<div class="planner-instruction">
<p>01 Select arrival · 02 Select departure</p>
<div id="choice-line">Alder Local → Meridian Rapid</div>
</div>
<div class="timeline">
<div class="time-node">
<div class="time-label">Arrival</div>
<div class="time-value" id="arrival-value">08:18</div>
<div class="time-meta" id="arrival-meta">Platform 1</div>
</div>
<div class="time-node bad" id="transfer-node">
<div class="time-label">Transfer ready</div>
<div class="time-value" id="transfer-value">08:23</div>
<div class="time-meta" id="transfer-meta">5 min walk</div>
</div>
<div class="time-node bad" id="departure-node">
<div class="time-label">Departure</div>
<div class="time-value" id="departure-value">08:22</div>
<div class="time-meta" id="departure-meta">Platform 5</div>
</div>
</div>
<div class="planner-footer">
<div id="route-meta">P1 → P5 · central concourse</div>
<button id="jump-button" type="button">SEE DEPARTURE →</button>
</div>
</div>
</section>
<div class="scene-hint">Drag to orbit · Scroll to zoom · Click a train or board card</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -----------------------------------------------------------------------
// Application state
// -----------------------------------------------------------------------
const BASE_MINUTES = 8 * 60 + 18;
const CONCOURSE_X = -6.3;
let simElapsed = 0;
let speed = 1;
let paused = false;
let selectedArrival = null;
let selectedDeparture = null;
const platformZ = {
1: 3,
2: 6,
3: 9,
4: 12,
5: -3,
6: -6,
7: -9,
8: -12
};
const arrivals = [
{ id: "A1", name: "Alder Local", time: 18, platform: 1, color: 0x58dfd1, kind: "arrival" },
{ id: "A2", name: "Birch Local", time: 23, platform: 2, color: 0xffbd62, kind: "arrival" },
{ id: "A3", name: "Cobalt Regional", time: 29, platform: 3, color: 0xb499ff, kind: "arrival" },
{ id: "A4", name: "Drift Express", time: 35, platform: 4, color: 0xff7ca8, kind: "arrival" }
];
const departures = [
{ id: "D1", name: "Meridian Rapid", time: 22, platform: 5, color: 0x61e6a5, kind: "departure" },
{ id: "D2", name: "Sunjet", time: 27, platform: 6, color: 0xffbd62, kind: "departure" },
{ id: "D3", name: "Nightjar", time: 33, platform: 7, color: 0xb499ff, kind: "departure" },
{ id: "D4", name: "Aurora", time: 46, platform: 8, color: 0x65bfff, kind: "departure" }
];
const services = [...arrivals, ...departures];
const statusNodes = new Map();
selectedArrival = arrivals[0];
selectedDeparture = departures[0];
// -----------------------------------------------------------------------
// Time and connection helpers
// -----------------------------------------------------------------------
function formatTime(minutes) {
const rounded = Math.round(minutes);
const h = Math.floor(rounded / 60) % 24;
const m = rounded % 60;
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
}
function formatClock() {
const total = BASE_MINUTES + simElapsed;
const whole = Math.floor(total);
const seconds = Math.floor((total - whole) * 60);
return `${formatTime(whole)}:${String(seconds).padStart(2, "0")}`;
}
function absoluteTime(service) {
return BASE_MINUTES + service.time;
}
function transferDuration(arrival, departure) {
const arrivalZ = platformZ[arrival.platform] + 1;
const departureZ = platformZ[departure.platform] + 1;
const stationWalkDistance = 6.4 + Math.abs(arrivalZ - departureZ);
return Math.max(3, Math.ceil(stationWalkDistance / 3));
}
function connectionResult(arrival = selectedArrival, departure = selectedDeparture) {
const arrivalTime = absoluteTime(arrival);
const departureTime = absoluteTime(departure);
const transferTime = transferDuration(arrival, departure);
const readyTime = arrivalTime + transferTime;
const success = readyTime <= departureTime;
const margin = departureTime - readyTime;
return {
arrival,
departure,
arrivalTime,
departureTime,
transferTime,
readyTime,
success,
margin
};
}
// -----------------------------------------------------------------------
// Three.js setup
// -----------------------------------------------------------------------
const host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131f);
scene.fog = new THREE.Fog(0x07131f, 40, 85);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
host.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xa9dcff, 0x17232c, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.2);
sun.position.set(-16, 28, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00025;
scene.add(sun);
const cyanRim = new THREE.DirectionalLight(0x52c8ff, 1.1);
cyanRim.position.set(20, 10, -18);
scene.add(cyanRim);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, emissive = 0) {
const key = `${color}:${emissive}`;
if (materialCache.has(key)) return materialCache.get(key);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.08,
emissive,
emissiveIntensity: emissive ? 0.65 : 0
});
materialCache.set(key, material);
return material;
}
function addBox(parent, width, height, depth, color, x = 0, y = 0, z = 0, options = {}) {
const material = options.material || getMaterial(color, options.emissive || 0);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function hex(color) {
return `#${new THREE.Color(color).getHexString()}`;
}
function makeLabel(text, color = "#dff9ff", background = "#0b1b29", scale = 3) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = color;
ctx.lineWidth = 8;
ctx.strokeRect(7, 7, canvas.width - 14, canvas.height - 14);
ctx.fillStyle = color;
ctx.font = "800 45px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scale, scale * 0.28125, 1);
sprite.renderOrder = 20;
return sprite;
}
// -----------------------------------------------------------------------
// Voxel station
// -----------------------------------------------------------------------
const station = new THREE.Group();
scene.add(station);
// Ground and base.
addBox(station, 52, 1, 42, 0x102333, 0, -0.7, 0);
addBox(station, 49, 0.22, 39, 0x142c3b, 0, -0.12, 0);
// Grid paving.
for (let x = -22; x <= 22; x += 4) {
addBox(station, 0.06, 0.025, 36, 0x294353, x, 0.015, 0, {
castShadow: false
});
}
for (let z = -18; z <= 18; z += 4) {
addBox(station, 46, 0.025, 0.06, 0x294353, 0, 0.015, z, {
castShadow: false
});
}
// Central open-cut concourse.
addBox(station, 5.8, 0.65, 28, 0x38505f, CONCOURSE_X, 0.34, 0);
addBox(station, 0.22, 0.06, 27, 0xf3c75f, CONCOURSE_X + 2.48, 0.69, 0);
// West entrance hall.
addBox(station, 7.2, 4.8, 4.8, 0x29485b, -12.2, 2.4, 0);
addBox(station, 7.8, 0.45, 5.4, 0x172f40, -12.2, 5.02, 0);
addBox(station, 1.0, 6.4, 1.0, 0x1c394b, -15.2, 3.2, 0);
addBox(station, 2.4, 0.35, 2.4, 0x58dfd1, -15.2, 6.55, 0, {
emissive: 0x1a8077
});
for (let z = -1.35; z <= 1.35; z += 0.9) {
addBox(station, 0.08, 1.3, 0.55, 0x8cdcf0, -8.56, 2.7, z, {
emissive: 0x244f61
});
}
const stationLabel = makeLabel("NOVA JUNCTION", "#6ee9de", "#0a1925", 7.5);
stationLabel.position.set(-12.2, 5.9, 0);
station.add(stationLabel);
// Rails, sleepers, platforms, signs.
const sleeperGeometry = new THREE.BoxGeometry(0.3, 0.12, 1.25);
const sleeperMaterial = getMaterial(0x283a45);
for (const platform of Object.keys(platformZ).map(Number)) {
const z = platformZ[platform];
addBox(station, 40, 0.12, 0.11, 0x718996, 0, 0.12, z - 0.43);
addBox(station, 40, 0.12, 0.11, 0x718996, 0, 0.12, z + 0.43);
const sleepers = new THREE.InstancedMesh(
sleeperGeometry,
sleeperMaterial,
31
);
const dummy = new THREE.Object3D();
for (let i = 0; i < 31; i++) {
dummy.position.set(-18.5 + i * 1.225, 0.03, z);
dummy.updateMatrix();
sleepers.setMatrixAt(i, dummy.matrix);
}
sleepers.receiveShadow = true;
station.add(sleepers);
const platformZCenter = z + 1;
addBox(station, 14, 0.62, 1.28, 0x4b626f, 0, 0.31, platformZCenter);
addBox(station, 13.8, 0.07, 0.18, 0xf2c755, 0, 0.65, platformZCenter - 0.48);
const sign = makeLabel(`P${platform}`, hex(services[platform - 1].color), "#091724", 2.1);
sign.position.set(-5.7, 2.25, platformZCenter);
station.add(sign);
addBox(station, 0.14, 2.1, 0.14, 0x203946, -5.7, 1.05, platformZCenter);
addBox(station, 1.7, 0.14, 0.14, 0x203946, -5.7, 2.05, platformZCenter);
// Bench and lamp.
addBox(station, 1.5, 0.18, 0.45, 0x1b3140, 3.8, 0.85, platformZCenter);
addBox(station, 0.18, 0.55, 0.45, 0x1b3140, 3.2, 0.57, platformZCenter);
addBox(station, 0.18, 0.55, 0.45, 0x1b3140, 4.4, 0.57, platformZCenter);
addBox(station, 0.12, 2.2, 0.12, 0x263e4c, 6.1, 1.1, platformZCenter);
addBox(station, 0.4, 0.3, 0.4, 0xa9eaff, 6.1, 2.32, platformZCenter, {
emissive: 0x3b90aa
});
}
// Concourse columns and overhead markers.
for (let z = -12; z <= 12; z += 4) {
addBox(station, 0.34, 4.2, 0.34, 0x284554, CONCOURSE_X - 2.25, 2.1, z);
addBox(station, 0.34, 4.2, 0.34, 0x284554, CONCOURSE_X + 2.25, 2.1, z);
addBox(station, 4.8, 0.22, 0.28, 0x315465, CONCOURSE_X, 4.17, z);
addBox(station, 0.55, 0.18, 0.55, 0x9eeeff, CONCOURSE_X + 1.7, 3.98, z, {
emissive: 0x31748a
});
}
// Peripheral voxel buildings.
const cityColors = [0x183044, 0x1d3a4d, 0x244658, 0x173044];
for (let i = 0; i < 22; i++) {
const side = i % 2 === 0 ? -1 : 1;
const x = -21 + ((i * 7.3) % 42);
const z = side * (19 + ((i * 2.7) % 5));
const height = 1.2 + ((i * 1.37) % 5);
const width = 1.4 + ((i * 0.9) % 2.4);
const depth = 1.4 + ((i * 1.1) % 2.2);
addBox(station, width, height, depth, cityColors[i % cityColors.length], x, height / 2, z);
if (i % 3 === 0) {
addBox(
station,
width * 0.55,
0.5,
depth * 0.5,
0xffd88a,
x,
height + 0.25,
z,
{ emissive: 0x6f4d1d }
);
}
}
// Blocky clouds.
for (const cloud of [
[-18, 15, -25],
[9, 18, -27],
[22, 13, 20]
]) {
addBox(station, 6, 1.1, 2, 0x87a8b8, cloud[0], cloud[1], cloud[2], {
castShadow: false
});
addBox(station, 3, 1.2, 2.3, 0x9ab8c4, cloud[0] - 1, cloud[1] + 0.6, cloud[2], {
castShadow: false
});
}
// -----------------------------------------------------------------------
// Voxel trains
// -----------------------------------------------------------------------
const trainGroups = [];
function makeTrain(service) {
const group = new THREE.Group();
group.userData.service = service;
group.userData.kind = service.kind;
const bodyMaterial = getMaterial(service.color);
const roofMaterial = getMaterial(0x152735);
const windowMaterial = getMaterial(0xb7ecff, 0x3b7790);
const wheelMaterial = getMaterial(0x101a22);
for (let carIndex = -1; carIndex <= 1; carIndex++) {
const car = new THREE.Group();
car.position.x = carIndex * 4.05;
group.add(car);
addBox(car, 3.75, 1.32, 1.42, service.color, 0, 1.12, 0, {
material: bodyMaterial
});
addBox(car, 3.5, 0.25, 1.25, 0x162a38, 0, 1.9, 0, {
material: roofMaterial
});
for (const side of [-1, 1]) {
for (const x of [-1.05, 0, 1.05]) {
addBox(car, 0.72, 0.43, 0.055, 0xb7ecff, x, 1.35, side * 0.735, {
material: windowMaterial
});
}
addBox(car, 0.7, 0.45, 0.36, 0x111c24, -1.18, 0.37, side * 0.62, {
material: wheelMaterial
});
addBox(car, 0.7, 0.45, 0.36, 0x111c24, 1.18, 0.37, side * 0.62, {
material: wheelMaterial
});
}
addBox(car, 0.18, 0.16, 1.02, 0xf8f5dd, 1.88, 1.08, 0, {
emissive: 0x615b35
});
}
const label = makeLabel(
`${service.id} · ${service.name.toUpperCase()}`,
hex(service.color),
"#091724",
5.4
);
label.position.set(0, 3.25, 0);
group.add(label);
group.position.z = platformZ[service.platform];
scene.add(group);
trainGroups.push(group);
return group;
}
services.forEach(makeTrain);
// -----------------------------------------------------------------------
// Transfer route and selection markers
// -----------------------------------------------------------------------
const routeLine = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineDashedMaterial({
color: 0xff737b,
dashSize: 0.48,
gapSize: 0.27,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
routeLine.renderOrder = 15;
scene.add(routeLine);
const transferMarker = new THREE.Mesh(
unitBox,
new THREE.MeshBasicMaterial({ color: 0xff737b, depthTest: false })
);
transferMarker.scale.set(0.65, 0.65, 0.65);
transferMarker.renderOrder = 16;
scene.add(transferMarker);
function makeSelectionFrame(color) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthTest: false
});
addBox(group, 11.2, 0.04, 0.09, color, 0, 0, 0.84, { material });
addBox(group, 11.2, 0.04, 0.09, color, 0, 0, -0.84, { material });
addBox(group, 0.09, 0.04, 1.76, color, -5.6, 0, 0, { material });
addBox(group, 0.09, 0.04, 1.76, color, 5.6, 0, 0, { material });
group.renderOrder = 14;
scene.add(group);
return group;
}
const arrivalFrame = makeSelectionFrame(0x58dfd1);
const departureFrame = makeSelectionFrame(0xffbd62);
function routePoints(result) {
const arrivalZ = platformZ[result.arrival.platform] + 1;
const departureZ = platformZ[result.departure.platform] + 1;
return [
new THREE.Vector3(-3.35, 0.76, arrivalZ),
new THREE.Vector3(CONCOURSE_X, 0.76, arrivalZ),
new THREE.Vector3(CONCOURSE_X, 0.76, departureZ),
new THREE.Vector3(-3.35, 0.76, departureZ)
];
}
function updateTransferRoute() {
const result = connectionResult();
const points = routePoints(result);
const color = result.success ? 0x61e6a5 : 0xff737b;
routeLine.geometry.dispose();
routeLine.geometry = new THREE.BufferGeometry().setFromPoints(points);
routeLine.computeLineDistances();
routeLine.material.color.setHex(color);
transferMarker.material.color.setHex(color);
transferMarker.userData.points = points;
arrivalFrame.position.set(0, 0.76, platformZ[result.arrival.platform] + 1);
departureFrame.position.set(0, 0.76, platformZ[result.departure.platform] + 1);
}
function pointAlongPath(points, t) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let remaining = THREE.MathUtils.clamp(t, 0, 0.9999) * total;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i]) {
const fraction = lengths[i] === 0 ? 0 : remaining / lengths[i];
return new THREE.Vector3().lerpVectors(points[i], points[i + 1], fraction);
}
remaining -= lengths[i];
}
return points[points.length - 1].clone();
}
// -----------------------------------------------------------------------
// Voxel passengers
// -----------------------------------------------------------------------
const people = [];
const passengerColors = [0xffd36b, 0x69d8ff, 0xff7f9e, 0x9d87ff, 0x6de3ad];
for (let i = 0; i < 18; i++) {
const group = new THREE.Group();
const color = passengerColors[i % passengerColors.length];
addBox(group, 0.28, 0.52, 0.24, color, 0, 0.62, 0);
addBox(group, 0.26, 0.25, 0.25, 0xd8b49b, 0, 1.02, 0);
addBox(group, 0.12, 0.22, 0.12, 0x182530, -0.08, 0.22, 0);
addBox(group, 0.12, 0.22, 0.12, 0x182530, 0.08, 0.22, 0);
scene.add(group);
people.push({
group,
offset: i * 2.73,
lane: -1.8 + (i % 4) * 1.05,
direction: i % 2 === 0 ? 1 : -1,
speed: 0.45 + (i % 5) * 0.09
});
}
// -----------------------------------------------------------------------
// Board and planner UI
// -----------------------------------------------------------------------
const arrivalList = document.getElementById("arrival-list");
const departureList = document.getElementById("departure-list");
function serviceCard(service, kind) {
const button = document.createElement("button");
button.type = "button";
button.className = "service-card";
button.dataset.serviceId = service.id;
button.style.setProperty("--service-color", hex(service.color));
button.innerHTML = `
<div class="service-time">${formatTime(absoluteTime(service))}</div>
<div>
<div class="service-name">${service.name}</div>
<div class="service-meta">${service.id} · Platform ${service.platform}</div>
<span class="service-status"></span>
</div>
`;
button.addEventListener("click", () => {
selectService(kind, service);
});
statusNodes.set(service.id, button.querySelector(".service-status"));
return button;
}
arrivals.forEach(service => arrivalList.appendChild(serviceCard(service, "arrival")));
departures.forEach(service => departureList.appendChild(serviceCard(service, "departure")));
function selectService(kind, service) {
if (kind === "arrival") {
selectedArrival = service;
} else {
selectedDeparture = service;
}
renderPlanner();
updateTransferRoute();
}
function countOpenConnections() {
let count = 0;
for (const arrival of arrivals) {
for (const departure of departures) {
if (connectionResult(arrival, departure).success) count++;
}
}
return count;
}
document.getElementById("link-count").textContent =
`${countOpenConnections()}/16 connections open`;
function renderPlanner() {
const result = connectionResult();
document.getElementById("choice-line").textContent =
`${result.arrival.name} → ${result.departure.name}`;
document.getElementById("arrival-value").textContent =
formatTime(result.arrivalTime);
document.getElementById("arrival-meta").textContent =
`Platform ${result.arrival.platform}`;
document.getElementById("transfer-value").textContent =
formatTime(result.readyTime);
document.getElementById("transfer-meta").textContent =
`${result.transferTime} min walk`;
document.getElementById("departure-value").textContent =
formatTime(result.departureTime);
document.getElementById("departure-meta").textContent =
`Platform ${result.departure.platform}`;
document.getElementById("route-meta").textContent =
`P${result.arrival.platform} → P${result.departure.platform} · central concourse`;
const badge = document.getElementById("result-badge");
const title = document.getElementById("result-title");
const note = document.getElementById("result-note");
const transferNode = document.getElementById("transfer-node");
const departureNode = document.getElementById("departure-node");
badge.className = `result-badge ${result.success ? "success" : "fail"}`;
if (result.success) {
badge.textContent = result.margin === 0 ? "EXACT FIT" : "SUCCESS";
title.textContent = "Connection secured";
note.textContent = result.margin === 0
? "The transfer finishes exactly as the departure platform closes."
: `You reach the gate ${result.margin} minute${result.margin === 1 ? "" : "s"} before departure.`;
transferNode.className = "time-node good";
departureNode.className = "time-node good";
} else {
badge.textContent = "MISSED";
title.textContent = "Connection missed";
note.textContent = `The outbound train leaves ${Math.abs(result.margin)} minute${Math.abs(result.margin) === 1 ? "" : "s"} before the transfer is complete.`;
transferNode.className = "time-node bad";
departureNode.className = "time-node bad";
}
document.querySelectorAll(".service-card").forEach(card => {
const service = services.find(item => item.id === card.dataset.serviceId);
card.classList.toggle(
"selected",
service.id === selectedArrival.id || service.id === selectedDeparture.id
);
});
}
function updateScheduleStatuses() {
const now = BASE_MINUTES + simElapsed;
for (const service of services) {
const node = statusNodes.get(service.id);
node.className = "service-status";
if (service.kind === "arrival") {
const event = absoluteTime(service);
if (now < event) {
node.textContent = `Due in ${Math.ceil(event - now)} min`;
if (event - now <= 3) node.classList.add("imminent");
} else if (now <= event + 3) {
node.textContent = "At platform";
node.classList.add("docked");
} else {
node.textContent = `Arrived ${Math.floor(now - event)} min ago`;
}
} else {
const event = absoluteTime(service);
if (now < event - 2) {
node.textContent = `Boarding in ${Math.ceil(event - now)} min`;
} else if (now <= event) {
node.textContent = "Boarding";
node.classList.add("imminent");
} else {
node.textContent = `Departed ${Math.floor(now - event)} min ago`;
}
}
}
}
document.getElementById("jump-button").addEventListener("click", () => {
const result = connectionResult();
simElapsed = Math.max(0, result.departureTime - BASE_MINUTES - 1.5);
});
document.getElementById("pause-button").addEventListener("click", event => {
paused = !paused;
event.currentTarget.textContent = paused ? "RESUME" : "PAUSE";
event.currentTarget.classList.toggle("active", paused);
});
document.getElementById("reset-button").addEventListener("click", () => {
simElapsed = 0;
paused = false;
document.getElementById("pause-button").textContent = "PAUSE";
document.getElementById("pause-button").classList.remove("active");
});
document.querySelectorAll("[data-speed]").forEach(button => {
button.addEventListener("click", () => {
speed = Number(button.dataset.speed);
document.querySelectorAll("[data-speed]").forEach(item => {
item.classList.toggle("active", item === button);
});
});
});
renderPlanner();
updateTransferRoute();
// -----------------------------------------------------------------------
// Custom camera controls — no addons
// -----------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(-1.5, 0.8, 0),
theta: 0.68,
phi: 0.9,
radius: 45
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.68;
orbit.phi = 0.9;
orbit.radius = 45;
updateCamera();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
function pickTrain(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(trainGroups, true);
if (!hits.length) return null;
let object = hits[0].object;
while (object && !object.userData.service) {
object = object.parent;
}
return object?.userData.service || null;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = {
x: event.clientX,
y: event.clientY,
moved: 0
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
pointerDown.moved += Math.abs(dx) + Math.abs(dy);
orbit.theta -= dx * 0.005;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.004, 0.35, 1.35);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
updateCamera();
} else {
const service = pickTrain(event.clientX, event.clientY);
renderer.domElement.style.cursor = service ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerDown && pointerDown.moved < 7) {
const service = pickTrain(event.clientX, event.clientY);
if (service) selectService(service.kind, service);
}
pointerDown = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
24,
72
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") orbit.theta -= 0.08;
if (event.key === "ArrowRight") orbit.theta += 0.08;
if (event.key === "ArrowUp") orbit.phi = Math.max(0.35, orbit.phi - 0.06);
if (event.key === "ArrowDown") orbit.phi = Math.min(1.35, orbit.phi + 0.06);
if (event.key.toLowerCase() === "r") resetCamera();
updateCamera();
});
// -----------------------------------------------------------------------
// Simulation and animation
// -----------------------------------------------------------------------
function updateTrains() {
const now = BASE_MINUTES + simElapsed;
for (const train of trainGroups) {
const service = train.userData.service;
if (service.kind === "arrival") {
const arrival = absoluteTime(service);
const departure = arrival + 3;
if (now < arrival - 4 || now > departure + 4) {
train.visible = false;
continue;
}
train.visible = true;
if (now < arrival) {
train.position.x = THREE.MathUtils.lerp(-17.5, 0, (now - arrival + 4) / 4);
} else if (now <= departure) {
train.position.x = 0;
} else {
train.position.x = THREE.MathUtils.lerp(0, 17.5, (now - departure) / 4);
}
} else {
const departure = absoluteTime(service);
if (now < departure - 4 || now > departure + 5) {
train.visible = false;
continue;
}
train.visible = true;
if (now < departure) {
train.position.x = THREE.MathUtils.lerp(17.5, 0, (now - departure + 4) / 4);
} else {
train.position.x = THREE.MathUtils.lerp(0, -17.5, (now - departure) / 5);
}
}
}
}
function updatePeople() {
for (const person of people) {
const travel = (simElapsed * person.speed + person.offset) % 28;
const z = -14 + travel;
person.group.position.set(
CONCOURSE_X + person.lane * 0.32,
0.68,
z
);
person.group.rotation.y = person.direction > 0 ? 0 : Math.PI;
}
}
function updateTransferMarker() {
const points = transferMarker.userData.points;
if (!points?.length) return;
const result = connectionResult();
const progress = ((simElapsed / result.transferTime) + 0.14) % 1;
const position = pointAlongPath(points, progress);
transferMarker.position.copy(position);
transferMarker.position.y += 0.38;
transferMarker.rotation.y += 0.04;
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = camera.aspect < 1 ? 55 : 40;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.1);
if (!paused) {
simElapsed += dt * speed * 0.5;
}
updateTrains();
updatePeople();
updateTransferMarker();
updateScheduleStatuses();
document.getElementById("clock").textContent = formatClock();
renderer.render(scene, camera);
}
onResize();
updateCamera();
animate();
</script>
</body>
</html>
```