Prompt specification
Build or customize the Three.js 3D scene "Three stations on a bent track" 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: Three stations on a bent track
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/three-stations-on-a-bent-track-x1353
Scene Description Prompt:
Three voxel stations on a curved track correspond to a straight schematic map with identical connection order. One HTML file using Three.js from cdnjs.
Working Three.js Starter (three-stations-on-a-bent-track-x1353):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#071114" />
<title>Curve / Line — Voxel Transit Study</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5ef;
--muted: #8fa49e;
--panel: rgba(8, 19, 22, 0.82);
--line: rgba(207, 235, 222, 0.16);
--accent: #ffbf69;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071114;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
[tabindex] {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.hud button,
.hud [role="button"] {
pointer-events: auto;
}
.eyebrow {
margin: 0 0 9px;
color: #a9bdb5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand {
top: 26px;
left: 28px;
max-width: 390px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6);
}
.brand h1 {
margin: 0;
font-size: clamp(27px, 4vw, 48px);
font-weight: 620;
letter-spacing: -0.055em;
line-height: 0.95;
}
.brand h1 span {
color: var(--accent);
}
.brand p:last-child {
max-width: 330px;
margin: 13px 0 0;
color: #a9bbb5;
font-size: 12px;
line-height: 1.55;
}
.glass {
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(18px) saturate(120%);
-webkit-backdrop-filter: blur(18px) saturate(120%);
}
.map-panel {
top: 24px;
right: 24px;
width: min(390px, calc(100vw - 48px));
padding: 17px 18px 15px;
border-radius: 18px;
}
.map-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.map-header h2 {
margin: 0;
font-size: 15px;
font-weight: 650;
letter-spacing: -0.02em;
}
.map-header .eyebrow {
margin-bottom: 5px;
}
.run-button,
.focus-button,
.overview-button {
border: 1px solid rgba(226, 245, 235, 0.18);
border-radius: 9px;
background: rgba(225, 245, 235, 0.07);
padding: 7px 10px;
color: #dce9e2;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.run-button:hover,
.focus-button:hover,
.overview-button:hover {
border-color: rgba(226, 245, 235, 0.4);
background: rgba(225, 245, 235, 0.14);
transform: translateY(-1px);
}
.map-svg {
display: block;
width: 100%;
height: auto;
margin-top: 8px;
overflow: visible;
}
.map-svg .base-route {
stroke: rgba(214, 235, 224, 0.17);
stroke-width: 3;
stroke-linecap: round;
}
.map-svg .progress-route {
stroke: #d9f5e7;
stroke-width: 3;
stroke-linecap: round;
transition: stroke 180ms ease;
}
.map-svg .map-node {
cursor: pointer;
outline: none;
}
.map-svg .node-halo {
fill: rgba(255, 255, 255, 0.03);
stroke: transparent;
stroke-width: 1.5;
transition:
fill 180ms ease,
stroke 180ms ease,
r 180ms ease;
}
.map-svg .node-dot {
fill: #102126;
stroke: var(--node);
stroke-width: 3;
transition:
fill 180ms ease,
stroke-width 180ms ease;
}
.map-svg .map-node.active .node-halo,
.map-svg .map-node:focus .node-halo {
fill: color-mix(in srgb, var(--node) 12%, transparent);
stroke: color-mix(in srgb, var(--node) 55%, transparent);
}
.map-svg .map-node.active .node-dot {
fill: var(--node);
stroke: #f6fff9;
}
.map-svg .node-code {
fill: #eef7f1;
font: 800 13px ui-monospace, SFMono-Regular, Menlo, monospace;
text-anchor: middle;
pointer-events: none;
}
.map-svg .node-name {
fill: #8fa59d;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-anchor: middle;
pointer-events: none;
}
.map-svg .train-dot {
fill: #f1fff7;
stroke: #071114;
stroke-width: 3;
filter: drop-shadow(0 0 5px rgba(220, 255, 238, 0.8));
}
.map-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.order-lock {
color: #d9eee3;
}
.detail-panel {
bottom: 24px;
left: 24px;
width: min(330px, calc(100vw - 48px));
padding: 16px 17px;
border-radius: 17px;
}
.detail-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.detail-code {
color: var(--accent);
font: 800 12px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
}
.trip-state {
display: flex;
align-items: center;
gap: 7px;
color: #9db1aa;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.trip-state::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 9px var(--accent);
content: "";
}
.detail-panel h2 {
margin: 10px 0 2px;
font-size: 25px;
font-weight: 650;
letter-spacing: -0.045em;
}
.detail-panel p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.journey {
height: 3px;
margin: 15px 0 12px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
.journey > div {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
.detail-actions {
display: flex;
gap: 8px;
}
.controls {
right: 25px;
bottom: 25px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(7, 17, 20, 0.66);
color: #91a69e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.mouse-icon {
position: relative;
width: 13px;
height: 19px;
border: 1px solid #a6b9b1;
border-radius: 8px;
}
.mouse-icon::before {
position: absolute;
top: 4px;
left: 5px;
width: 2px;
height: 4px;
border-radius: 2px;
background: #c8d9d1;
content: "";
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px 7px 7px;
border: 1px solid rgba(224, 242, 232, 0.2);
border-radius: 9px;
background: rgba(6, 16, 19, 0.82);
color: #eaf5ee;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
font-size: 9px;
font-weight: 780;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -100%);
transition:
border-color 160ms ease,
background 160ms ease,
opacity 160ms ease;
}
.world-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 15px;
background: linear-gradient(var(--station-color), transparent);
content: "";
}
.world-label .label-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--station-color);
box-shadow: 0 0 9px var(--station-color);
}
.world-label:hover,
.world-label.active {
border-color: var(--station-color);
background: rgba(11, 24, 27, 0.95);
}
.world-label.hidden {
opacity: 0;
pointer-events: none;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #071114;
color: #9bb0a7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
body.ready .loading {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 17px;
left: 17px;
}
.brand p:last-child {
display: none;
}
.map-panel {
top: auto;
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 12px 14px 11px;
}
.map-svg {
max-height: 118px;
}
.detail-panel {
top: 83px;
bottom: auto;
left: 12px;
width: 238px;
padding: 12px 13px;
}
.detail-panel h2 {
font-size: 20px;
}
.controls {
display: none;
}
.map-footer span:first-child {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D voxel railway scene"></div>
<header class="hud brand">
<p class="eyebrow">Voxel transit study · 03</p>
<h1>Curve <span>/</span> Line</h1>
<p>A physical S-curve and its deliberately straightened transit diagram. The sequence stays unchanged.</p>
</header>
<section class="hud map-panel glass" aria-label="Straight-line station schematic">
<div class="map-header">
<div>
<p class="eyebrow">Live schematic</p>
<h2>Straight-line abstraction</h2>
</div>
<button class="run-button" id="runLine" type="button">Play A–C</button>
</div>
<svg class="map-svg" viewBox="0 0 420 160" role="img" aria-label="Stations in order: A, B, C">
<defs>
<linearGradient id="routeGradient" x1="0" x2="1">
<stop offset="0" stop-color="#ffbf69" />
<stop offset="0.5" stop-color="#65e6d2" />
<stop offset="1" stop-color="#ff7d72" />
</linearGradient>
</defs>
<line class="base-route" x1="65" y1="78" x2="355" y2="78" />
<line
id="routeProgress"
class="progress-route"
x1="65"
y1="78"
x2="65"
y2="78"
stroke="url(#routeGradient)"
/>
<g class="map-node" data-index="0" style="--node:#ffbf69" transform="translate(65 78)" tabindex="0" role="button" aria-label="Station A, Ember">
<circle class="node-halo" r="22" />
<circle class="node-dot" r="12" />
<text class="node-code" y="4">A</text>
<text class="node-name" y="43">EMBER</text>
</g>
<g class="map-node" data-index="1" style="--node:#65e6d2" transform="translate(210 78)" tabindex="0" role="button" aria-label="Station B, Halo">
<circle class="node-halo" r="22" />
<circle class="node-dot" r="12" />
<text class="node-code" y="4">B</text>
<text class="node-name" y="43">HALO</text>
</g>
<g class="map-node" data-index="2" style="--node:#ff7d72" transform="translate(355 78)" tabindex="0" role="button" aria-label="Station C, Quarry">
<circle class="node-halo" r="22" />
<circle class="node-dot" r="12" />
<text class="node-code" y="4">C</text>
<text class="node-name" y="43">QUARRY</text>
</g>
<circle id="trainDot" class="train-dot" cx="65" cy="78" r="5" />
</svg>
<div class="map-footer">
<span>01 → 02 → 03</span>
<span class="order-lock">Order locked ✓</span>
</div>
</section>
<section class="hud detail-panel glass" aria-live="polite">
<div class="detail-top">
<span class="detail-code" id="detailCode">PLATFORM 01</span>
<span class="trip-state" id="tripState">At platform</span>
</div>
<h2 id="detailName">Ember</h2>
<p id="detailMeta">Origin block · amber district</p>
<div class="journey"><div id="journeyFill"></div></div>
<div class="detail-actions">
<button class="focus-button" id="focusStation" type="button">Focus</button>
<button class="overview-button" id="overview" type="button">Overview</button>
</div>
</section>
<div class="hud controls" aria-hidden="true">
<span class="mouse-icon"></span>
<span>Drag to orbit · scroll to zoom</span>
</div>
<div id="labels">
<button class="world-label" data-index="0" style="--station-color:#ffbf69" type="button">
<span class="label-dot"></span><span>01 · Ember</span>
</button>
<button class="world-label" data-index="1" style="--station-color:#65e6d2" type="button">
<span class="label-dot"></span><span>02 · Halo</span>
</button>
<button class="world-label" data-index="2" style="--station-color:#ff7d72" type="button">
<span class="label-dot"></span><span>03 · Quarry</span>
</button>
</div>
<div class="loading">Building the line…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const labels = [...document.querySelectorAll(".world-label")];
const mapNodes = [...document.querySelectorAll(".map-node")];
const routeProgress = document.querySelector("#routeProgress");
const trainDot = document.querySelector("#trainDot");
const detailCode = document.querySelector("#detailCode");
const detailName = document.querySelector("#detailName");
const detailMeta = document.querySelector("#detailMeta");
const tripState = document.querySelector("#tripState");
const journeyFill = document.querySelector("#journeyFill");
const stations = [
{
code: "01",
letter: "A",
name: "Ember",
meta: "Origin block · amber district",
color: 0xffbf69,
css: "#ffbf69"
},
{
code: "02",
letter: "B",
name: "Halo",
meta: "Central exchange · mint district",
color: 0x65e6d2,
css: "#65e6d2"
},
{
code: "03",
letter: "C",
name: "Quarry",
meta: "Terminal block · coral district",
color: 0xff7d72,
css: "#ff7d72"
}
];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071114);
scene.fog = new THREE.FogExp2(0x071114, 0.023);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xcce6dd, 0x172327, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xe9fff4, 3.1);
sun.position.set(-9, 18, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x5fb9b1, 1.25);
rimLight.position.set(12, 8, -14);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0x0a171a,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(80, 40, 0x264043, 0x14282b);
grid.position.y = -0.105;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const routeCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-13, 0, -2.8),
new THREE.Vector3(-9.2, 0, 1.6),
new THREE.Vector3(-4.6, 0, 3.9),
new THREE.Vector3(0, 0, 2.4),
new THREE.Vector3(4.7, 0, -1.8),
new THREE.Vector3(9.2, 0, -3.2),
new THREE.Vector3(13, 0, 0.7)
],
false,
"catmullrom",
0.48
);
const stationTs = [0.13, 0.5, 0.87];
const stationPoints = stationTs.map((t) => routeCurve.getPointAt(t));
const stationTangents = stationTs.map((t) => routeCurve.getTangentAt(t).normalize());
const stationAngles = stationTangents.map((tangent) => -Math.atan2(tangent.z, tangent.x));
function sideAt(t) {
const tangent = routeCurve.getTangentAt(t).normalize();
return new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
}
function makeRibbon(width, height, color) {
const segments = 180;
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = routeCurve.getPointAt(t);
const side = sideAt(t);
const left = point.clone().addScaledVector(side, width * 0.5);
const right = point.clone().addScaledVector(side, -width * 0.5);
left.y = height;
right.y = height;
positions.push(left.x, left.y, left.z, right.x, right.y, right.z);
uvs.push(0, t * 12, 1, t * 12);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color,
roughness: 0.93,
metalness: 0.02
})
);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
makeRibbon(3.45, 0.025, 0x34474a);
makeRibbon(2.85, 0.055, 0x566462);
function makeOffsetRail(offset) {
const points = [];
for (let i = 0; i <= 120; i++) {
const t = i / 120;
const point = routeCurve.getPointAt(t);
const side = sideAt(t);
point.addScaledVector(side, offset);
point.y = 0.23;
points.push(point);
}
const railCurve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.4);
const rail = new THREE.Mesh(
new THREE.TubeGeometry(railCurve, 220, 0.075, 7, false),
new THREE.MeshStandardMaterial({
color: 0xa7b9b3,
roughness: 0.28,
metalness: 0.78
})
);
rail.castShadow = true;
rail.receiveShadow = true;
scene.add(rail);
}
makeOffsetRail(0.78);
makeOffsetRail(-0.78);
const sleeperGeometry = new THREE.BoxGeometry(0.22, 0.13, 2.85);
const sleeperMaterial = new THREE.MeshStandardMaterial({
color: 0x263638,
roughness: 0.86,
metalness: 0.12
});
const sleepers = new THREE.InstancedMesh(sleeperGeometry, sleeperMaterial, 112);
sleepers.castShadow = true;
sleepers.receiveShadow = true;
const sleeperMatrix = new THREE.Matrix4();
const sleeperQuaternion = new THREE.Quaternion();
const sleeperScale = new THREE.Vector3(1, 1, 1);
const upAxis = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < 112; i++) {
const t = i / 111;
const point = routeCurve.getPointAt(t);
const tangent = routeCurve.getTangentAt(t).normalize();
const angle = -Math.atan2(tangent.z, tangent.x);
sleeperQuaternion.setFromAxisAngle(upAxis, angle);
sleeperMatrix.compose(
new THREE.Vector3(point.x, 0.105, point.z),
sleeperQuaternion,
sleeperScale
);
sleepers.setMatrixAt(i, sleeperMatrix);
}
sleepers.instanceMatrix.needsUpdate = true;
scene.add(sleepers);
function makeSignTexture(code, color) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const context = canvas.getContext("2d");
context.fillStyle = "#071114";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = `#${color.toString(16).padStart(6, "0")}`;
context.lineWidth = 5;
context.strokeRect(5, 5, canvas.width - 10, canvas.height - 10);
context.fillStyle = `#${color.toString(16).padStart(6, "0")}`;
context.font = "800 50px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(code, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
const pickables = [];
const stationRings = [];
const labelAnchors = [];
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createStation(station, index) {
const group = new THREE.Group();
const point = stationPoints[index];
const angle = stationAngles[index];
group.position.copy(point);
group.rotation.y = angle;
const accent = new THREE.MeshStandardMaterial({
color: station.color,
emissive: station.color,
emissiveIntensity: 0.18,
roughness: 0.48,
metalness: 0.16
});
const dark = new THREE.MeshStandardMaterial({
color: 0x203337,
roughness: 0.75,
metalness: 0.08
});
const pale = new THREE.MeshStandardMaterial({
color: 0x9eb4ad,
roughness: 0.66,
metalness: 0.1
});
const glass = new THREE.MeshStandardMaterial({
color: 0x29494c,
emissive: 0x17383a,
emissiveIntensity: 0.35,
roughness: 0.24,
metalness: 0.35
});
addBox(group, [5.4, 0.46, 2.25], [0, 0.31, 2.38], pale);
addBox(group, [5.15, 0.08, 2.02], [0, 0.57, 2.38], dark);
addBox(group, [2.45, 1.65, 1.5], [-0.52, 1.43, 2.68], dark);
addBox(group, [2.75, 0.18, 1.78], [-0.52, 2.34, 2.68], accent);
addBox(group, [0.7, 1.2, 1.6], [1.03, 1.18, 2.6], pale);
addBox(group, [0.83, 0.16, 1.72], [1.03, 1.86, 2.6], accent);
addBox(group, [0.22, 1.15, 0.22], [-1.62, 1.13, 1.54], pale);
addBox(group, [0.22, 1.15, 0.22], [1.5, 1.13, 1.54], pale);
addBox(group, [3.85, 0.16, 1.26], [-0.05, 1.83, 1.48], accent);
addBox(group, [1.15, 0.65, 0.06], [-0.5, 1.34, 1.9], glass);
addBox(group, [0.05, 0.66, 0.54], [-1.76, 1.35, 2.67], glass);
addBox(group, [0.05, 0.66, 0.54], [0.72, 1.35, 2.67], glass);
addBox(group, [0.16, 0.62, 0.16], [-1.25, 2.78, 2.67], pale);
addBox(group, [0.16, 0.16, 0.16], [-1.25, 3.12, 2.67], accent);
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(1.05, 0.4),
new THREE.MeshBasicMaterial({
map: makeSignTexture(station.code, station.color),
side: THREE.DoubleSide,
toneMapped: false
})
);
sign.position.set(1.02, 2.14, 1.78);
sign.rotation.y = Math.PI;
group.add(sign);
const ring = new THREE.Mesh(
new THREE.RingGeometry(2.08, 2.14, 64),
new THREE.MeshBasicMaterial({
color: station.color,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(0, 0.635, 2.35);
group.add(ring);
stationRings.push(ring);
const pickMesh = new THREE.Mesh(
new THREE.BoxGeometry(6.4, 4.2, 5.8),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
pickMesh.position.set(0, 1.7, 1.8);
pickMesh.userData.stationIndex = index;
group.add(pickMesh);
pickables.push(pickMesh);
scene.add(group);
const localAnchor = new THREE.Vector3(0, 3.75, 2.6);
localAnchor.applyAxisAngle(upAxis, angle).add(point);
labelAnchors.push(localAnchor);
}
stations.forEach(createStation);
// Deterministic low-poly scenery.
let randomSeed = 93217;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const treeTrunkMaterial = new THREE.MeshStandardMaterial({
color: 0x31413b,
roughness: 1
});
const treeLeafMaterials = [
new THREE.MeshStandardMaterial({ color: 0x244a42, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x2e5a4d, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x355f50, roughness: 1 })
];
function nearTrack(x, z, minimum = 3.1) {
for (let i = 0; i <= 80; i++) {
const p = routeCurve.getPointAt(i / 80);
const dx = p.x - x;
const dz = p.z - z;
if (dx * dx + dz * dz < minimum * minimum) return true;
}
return false;
}
function nearStation(x, z, minimum = 4.6) {
return stationPoints.some((p) => {
const dx = p.x - x;
const dz = p.z - z;
return dx * dx + dz * dz < minimum * minimum;
});
}
let treesMade = 0;
for (let attempt = 0; attempt < 250 && treesMade < 31; attempt++) {
const x = random() * 35 - 17.5;
const z = random() * 18 - 9;
if (nearTrack(x, z) || nearStation(x, z)) continue;
const tree = new THREE.Group();
tree.position.set(x, 0, z);
const scale = 0.65 + random() * 0.55;
addBox(tree, [0.24, 0.72, 0.24], [0, 0.36, 0], treeTrunkMaterial);
addBox(tree, [0.9, 0.72, 0.9], [0, 0.98, 0], treeLeafMaterials[treesMade % 3]);
addBox(tree, [0.62, 0.62, 0.62], [0.08, 1.58, -0.05], treeLeafMaterials[(treesMade + 1) % 3]);
addBox(tree, [0.36, 0.36, 0.36], [-0.1, 2.03, 0.04], treeLeafMaterials[(treesMade + 2) % 3]);
tree.scale.setScalar(scale);
scene.add(tree);
treesMade++;
}
const buildingMaterials = [
new THREE.MeshStandardMaterial({ color: 0x17282c, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: 0x1c3032, roughness: 0.88 }),
new THREE.MeshStandardMaterial({ color: 0x233437, roughness: 0.92 })
];
for (let i = 0; i < 15; i++) {
const x = random() * 31 - 15.5;
const z = (i % 2 === 0 ? 1 : -1) * (8 + random() * 5);
const width = 0.9 + random() * 1.5;
const depth = 0.9 + random() * 1.3;
const height = 0.7 + random() * 2.4;
const building = addBox(
scene,
[width, height, depth],
[x, height * 0.5 - 0.1, z],
buildingMaterials[i % buildingMaterials.length]
);
const roof = addBox(
scene,
[width * 0.65, 0.12, depth * 0.65],
[x, height - 0.04, z],
buildingMaterials[(i + 1) % buildingMaterials.length]
);
building.castShadow = true;
roof.castShadow = true;
}
// Train.
const trainBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xdcebe4,
roughness: 0.34,
metalness: 0.22
});
const trainAccentMaterial = new THREE.MeshStandardMaterial({
color: 0x4cd8c1,
emissive: 0x1a6f64,
emissiveIntensity: 0.28,
roughness: 0.35,
metalness: 0.18
});
const trainWindowMaterial = new THREE.MeshStandardMaterial({
color: 0x173f46,
emissive: 0x1e6971,
emissiveIntensity: 0.45,
roughness: 0.2,
metalness: 0.38
});
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x111a1c,
roughness: 0.5,
metalness: 0.6
});
const headlightMaterial = new THREE.MeshBasicMaterial({
color: 0xfff1b2,
toneMapped: false
});
function createTrainCar(index) {
const car = new THREE.Group();
addBox(car, [1.82, 0.62, 0.94], [0, 0.73, 0], trainBodyMaterial);
addBox(car, [1.88, 0.16, 0.98], [0, 1.09, 0], trainAccentMaterial);
addBox(car, [1.58, 0.1, 0.82], [0, 1.2, 0], trainBodyMaterial);
for (const side of [-1, 1]) {
for (const x of [-0.52, 0, 0.52]) {
addBox(
car,
[0.38, 0.28, 0.035],
[x, 0.88, side * 0.485],
trainWindowMaterial,
false
);
}
}
addBox(car, [0.045, 0.31, 0.61], [0.93, 0.88, 0], trainWindowMaterial, false);
for (const x of [-0.57, 0.57]) {
for (const side of [-1, 1]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.18, 0.1, 12),
wheelMaterial
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.36, side * 0.49);
wheel.castShadow = true;
car.add(wheel);
}
}
if (index === 0) {
for (const side of [-1, 1]) {
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 10, 8),
headlightMaterial
);
lamp.position.set(0.96, 0.66, side * 0.24);
car.add(lamp);
}
}
scene.add(car);
return car;
}
const trainCars = [createTrainCar(0), createTrainCar(1), createTrainCar(2)];
// Custom camera controls, implemented without external addons.
const cameraState = {
theta: 0.68,
phi: 1.02,
radius: 28,
target: new THREE.Vector3(0, 0.5, 0)
};
const desiredCamera = {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
};
let dragging = false;
let dragMoved = false;
let previousPointer = { x: 0, y: 0 };
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function getStationIntersection(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(pickables, false)[0] || null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
desiredCamera.theta -= dx * 0.0055;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.0045,
0.48,
1.42
);
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
} else {
renderer.domElement.style.cursor = getStationIntersection(event)
? "pointer"
: "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.releasePointerCapture(event.pointerId);
if (!dragMoved) {
const hit = getStationIntersection(event);
if (hit) dispatchTo(hit.object.userData.stationIndex);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
12,
46
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") desiredCamera.theta -= 0.12;
if (event.key === "ArrowRight") desiredCamera.theta += 0.12;
if (event.key === "ArrowUp") {
desiredCamera.phi = THREE.MathUtils.clamp(desiredCamera.phi - 0.08, 0.48, 1.42);
}
if (event.key === "ArrowDown") {
desiredCamera.phi = THREE.MathUtils.clamp(desiredCamera.phi + 0.08, 0.48, 1.42);
}
});
let selectedStation = 0;
let currentT = stationTs[0];
let trainDirection = 1;
let trip = null;
let routeQueue = [];
function setSelected(index) {
selectedStation = index;
const station = stations[index];
document.documentElement.style.setProperty("--accent", station.css);
detailCode.textContent = `PLATFORM ${station.code}`;
detailName.textContent = station.name;
detailMeta.textContent = station.meta;
mapNodes.forEach((node, nodeIndex) => {
node.classList.toggle("active", nodeIndex === index);
});
labels.forEach((label, labelIndex) => {
label.classList.toggle("active", labelIndex === index);
});
}
function startTrip(index) {
const end = stationTs[index];
const delta = end - currentT;
setSelected(index);
if (Math.abs(delta) < 0.0001) {
trip = null;
tripState.textContent = "At platform";
completeQueuedTrip();
return;
}
trainDirection = Math.sign(delta);
trip = {
start: currentT,
end,
startedAt: performance.now(),
duration: 900 + Math.abs(delta) * 5300
};
tripState.textContent = `To ${stations[index].letter}`;
}
function dispatchTo(index) {
routeQueue = [];
startTrip(index);
}
function completeQueuedTrip() {
if (!routeQueue.length) return;
const next = routeQueue.shift();
window.setTimeout(() => startTrip(next), 420);
}
function activateMapNode(node) {
dispatchTo(Number(node.dataset.index));
}
mapNodes.forEach((node) => {
node.addEventListener("click", () => activateMapNode(node));
node.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
activateMapNode(node);
}
});
});
labels.forEach((label) => {
label.addEventListener("click", () => dispatchTo(Number(label.dataset.index)));
});
document.querySelector("#runLine").addEventListener("click", () => {
routeQueue = [0, 1, 2];
startTrip(0);
});
document.querySelector("#focusStation").addEventListener("click", () => {
desiredCamera.target.copy(stationPoints[selectedStation]);
desiredCamera.target.y = 1.1;
desiredCamera.radius = 14;
});
document.querySelector("#overview").addEventListener("click", () => {
desiredCamera.target.set(0, 0.5, 0);
desiredCamera.radius = 28;
desiredCamera.phi = 1.02;
});
function mapXFromT(t) {
const min = stationTs[0];
const max = stationTs[stationTs.length - 1];
const fraction = THREE.MathUtils.clamp((t - min) / (max - min), 0, 1);
return 65 + fraction * 290;
}
function updateWorldLabels() {
labels.forEach((label, index) => {
const projected = labelAnchors[index].clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.classList.toggle("hidden", !visible);
if (visible) {
label.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
label.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
});
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
setSelected(0);
const clock = new THREE.Clock();
let elapsed = 0;
function animate(now) {
requestAnimationFrame(animate);
elapsed = clock.getElapsedTime();
if (trip) {
const progress = THREE.MathUtils.clamp(
(now - trip.startedAt) / trip.duration,
0,
1
);
currentT = THREE.MathUtils.lerp(
trip.start,
trip.end,
easeInOutCubic(progress)
);
if (progress >= 1) {
currentT = trip.end;
trip = null;
tripState.textContent = "At platform";
completeQueuedTrip();
}
}
const smoothedTheta = THREE.MathUtils.lerp(
cameraState.theta,
desiredCamera.theta,
0.095
);
const smoothedPhi = THREE.MathUtils.lerp(
cameraState.phi,
desiredCamera.phi,
0.095
);
const smoothedRadius = THREE.MathUtils.lerp(
cameraState.radius,
desiredCamera.radius,
0.095
);
cameraState.theta = smoothedTheta;
cameraState.phi = smoothedPhi;
cameraState.radius = smoothedRadius;
cameraState.target.lerp(desiredCamera.target, 0.08);
const sinPhi = Math.sin(smoothedPhi);
camera.position.set(
cameraState.target.x + smoothedRadius * sinPhi * Math.sin(smoothedTheta),
cameraState.target.y + smoothedRadius * Math.cos(smoothedPhi),
cameraState.target.z + smoothedRadius * sinPhi * Math.cos(smoothedTheta)
);
camera.lookAt(cameraState.target);
trainCars.forEach((car, index) => {
const carT = THREE.MathUtils.clamp(
currentT - trainDirection * index * 0.032,
0.001,
0.999
);
const point = routeCurve.getPointAt(carT);
const tangent = routeCurve.getTangentAt(carT).normalize();
car.position.copy(point);
car.rotation.y =
-Math.atan2(tangent.z, tangent.x) +
(trainDirection < 0 ? Math.PI : 0);
});
stationRings.forEach((ring, index) => {
const active = index === selectedStation;
const pulse = active ? 1 + Math.sin(elapsed * 3.1) * 0.035 : 1;
ring.scale.setScalar(pulse);
ring.material.opacity = active ? 0.68 : 0.13;
});
const mapX = mapXFromT(currentT);
trainDot.setAttribute("cx", mapX);
routeProgress.setAttribute("x2", mapX);
const routeFraction = THREE.MathUtils.clamp(
(currentT - stationTs[0]) /
(stationTs[stationTs.length - 1] - stationTs[0]),
0,
1
);
journeyFill.style.width = `${routeFraction * 100}%`;
updateWorldLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
document.body.classList.add("ready");
</script>
</body>
</html>
```