Prompt specification
Build or customize the Three.js 3D scene "Compare wagon transport before and after rail access" 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: Compare wagon transport before and after rail access
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-wagon-transport-before-and-after-rail-access-x2476
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring the Stockton and Darlington Railway's 1825 opening. Let users move equal illustrative loads by road wagon and early rail under stated assumptions. Display capacity and time without presenting the values as measured opening-day performance. Voxel style.
Working Three.js Starter (compare-wagon-transport-before-and-after-rail-access-x2476):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stockton & Darlington, 1825 — Equal Load Comparison</title>
<style>
:root {
--ink: #173333;
--muted: #60706a;
--paper: #f6f0df;
--paper-2: #fffaf0;
--line: rgba(23, 51, 51, 0.15);
--green: #287269;
--green-2: #d9ebe1;
--amber: #d68c36;
--amber-2: #f6e5c8;
--red: #b95643;
--shadow: 0 16px 45px rgba(27, 48, 43, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bad6ca;
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;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.masthead {
position: fixed;
z-index: 10;
top: 20px;
left: 24px;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
}
.date-block {
display: grid;
place-items: center;
width: 58px;
height: 58px;
flex: 0 0 auto;
border: 2px solid var(--ink);
border-radius: 15px;
background: var(--paper);
box-shadow: 5px 5px 0 rgba(23, 51, 51, 0.16);
}
.date-block span {
font-family: Georgia, serif;
font-size: 21px;
font-weight: 700;
line-height: 1;
}
.date-block small {
margin-top: 3px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
}
.masthead h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(20px, 2.1vw, 31px);
font-weight: 700;
line-height: 1.02;
text-shadow: 0 1px rgba(255, 255, 255, 0.45);
}
.masthead p {
margin: 5px 0 0;
color: #35534d;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.035em;
}
.model-badge {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 7px;
padding: 4px 8px;
border: 1px solid rgba(23, 51, 51, 0.18);
border-radius: 999px;
background: rgba(246, 240, 223, 0.88);
color: var(--red);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.model-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--red);
}
.panel {
position: fixed;
z-index: 20;
top: 108px;
bottom: 98px;
left: 24px;
width: 340px;
overflow: auto;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 20px;
background: rgba(246, 240, 223, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
scrollbar-width: thin;
scrollbar-color: rgba(23, 51, 51, 0.3) transparent;
}
.eyebrow {
margin: 0 0 7px;
color: var(--green);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2,
.results h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
line-height: 1.12;
}
.intro {
margin: 9px 0 18px;
color: var(--muted);
font-size: 12.5px;
line-height: 1.5;
}
.section-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin: 17px 0 9px;
}
.section-label strong {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.section-label output {
color: var(--green);
font-family: Georgia, serif;
font-size: 24px;
font-weight: 700;
}
.load-control {
padding: 13px 14px 10px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.48);
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 5px 0 3px;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--green) 0%,
var(--green) 30.4%,
#c8cec5 30.4%,
#c8cec5 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 3px solid var(--paper-2);
border-radius: 50%;
appearance: none;
background: var(--green);
box-shadow: 0 2px 7px rgba(23, 51, 51, 0.28);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 15px;
height: 15px;
border: 3px solid var(--paper-2);
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 7px rgba(23, 51, 51, 0.28);
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 5px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.42);
}
.segmented button {
padding: 8px 4px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--muted);
font-size: 11px;
font-weight: 800;
cursor: pointer;
}
.segmented button.active {
background: var(--ink);
color: var(--paper-2);
box-shadow: 0 2px 5px rgba(23, 51, 51, 0.16);
}
.actions {
display: grid;
grid-template-columns: 1fr 42px;
gap: 8px;
margin-top: 13px;
}
.primary {
min-height: 42px;
border: 0;
border-radius: 11px;
background: var(--green);
color: white;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.02em;
cursor: pointer;
box-shadow: 0 4px 0 #1d5b54;
}
.primary:hover {
background: #22675f;
}
.primary:active {
transform: translateY(2px);
box-shadow: 0 2px 0 #1d5b54;
}
.reset {
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.5);
font-size: 20px;
cursor: pointer;
}
.assumption-box {
margin-top: 18px;
padding: 13px 14px;
border: 1px solid rgba(185, 86, 67, 0.22);
border-radius: 13px;
background: rgba(246, 229, 200, 0.55);
}
.assumption-box summary {
color: var(--red);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
.assumption-box ul {
margin: 11px 0 0;
padding-left: 17px;
color: #5b5549;
font-size: 10.5px;
line-height: 1.47;
}
.assumption-box li + li {
margin-top: 5px;
}
.history-note {
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.history-note p {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.5;
}
.history-note strong {
color: var(--ink);
}
.results {
position: fixed;
z-index: 20;
top: 108px;
right: 24px;
width: 342px;
}
.results-heading {
margin-bottom: 11px;
padding: 14px 16px;
border: 1px solid rgba(255, 255, 255, 0.66);
border-radius: 14px;
background: rgba(246, 240, 223, 0.9);
box-shadow: 0 8px 25px rgba(27, 48, 43, 0.1);
backdrop-filter: blur(10px);
}
.results-heading .eyebrow {
margin-bottom: 4px;
}
.results-heading h2 {
font-size: 20px;
}
.results-heading p {
margin: 7px 0 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.result-card {
position: relative;
overflow: hidden;
margin-bottom: 10px;
padding: 15px 16px 14px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 16px;
background: rgba(246, 240, 223, 0.95);
box-shadow: var(--shadow);
transition: opacity 180ms ease, transform 180ms ease;
}
.result-card::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 5px;
background: var(--amber);
}
.result-card.rail::before {
background: var(--green);
}
.result-card.inactive {
opacity: 0.46;
transform: scale(0.985);
}
.result-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.result-title h3 {
margin: 0;
font-family: Georgia, serif;
font-size: 18px;
}
.vehicle-icon {
display: grid;
place-items: center;
width: 31px;
height: 31px;
border-radius: 9px;
background: var(--amber-2);
font-size: 17px;
}
.rail .vehicle-icon {
background: var(--green-2);
}
.capacity {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.result-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 13px;
}
.stat {
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.42);
}
.stat span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.stat strong {
display: block;
margin-top: 3px;
font-family: Georgia, serif;
font-size: 23px;
line-height: 1;
}
.stat strong small {
margin-left: 3px;
font-family: ui-sans-serif, system-ui, sans-serif;
font-size: 10px;
font-weight: 700;
}
.last-load {
margin-top: 9px;
color: var(--muted);
font-size: 9.5px;
}
.comparison {
padding: 12px 14px;
border: 1px solid rgba(40, 114, 105, 0.2);
border-radius: 13px;
background: rgba(217, 235, 225, 0.92);
box-shadow: 0 7px 20px rgba(27, 48, 43, 0.09);
color: #315650;
font-size: 10.5px;
line-height: 1.48;
}
.comparison strong {
color: var(--ink);
}
.disclaimer {
margin-top: 8px;
padding: 0 5px;
color: #596a64;
font-size: 9px;
font-weight: 750;
line-height: 1.4;
}
.replay {
position: fixed;
z-index: 20;
right: 24px;
bottom: 20px;
left: 388px;
display: grid;
grid-template-columns: minmax(180px, 0.7fr) 1.3fr;
gap: 15px;
align-items: center;
min-height: 58px;
padding: 10px 15px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 14px;
background: rgba(246, 240, 223, 0.92);
box-shadow: 0 9px 30px rgba(27, 48, 43, 0.13);
backdrop-filter: blur(10px);
}
.replay-title {
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.replay-status {
margin-top: 3px;
overflow: hidden;
color: var(--muted);
font-size: 9.5px;
text-overflow: ellipsis;
white-space: nowrap;
}
.progress-row {
display: grid;
grid-template-columns: 43px 1fr 35px;
gap: 7px;
align-items: center;
margin: 4px 0;
font-size: 8.5px;
font-weight: 850;
text-transform: uppercase;
}
.progress-track {
overflow: hidden;
height: 6px;
border-radius: 999px;
background: rgba(23, 51, 51, 0.12);
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--amber);
}
.progress-fill.rail {
background: var(--green);
}
.place-label {
position: fixed;
z-index: 5;
pointer-events: none;
padding: 5px 8px;
border: 1px solid rgba(23, 51, 51, 0.22);
border-radius: 7px;
background: rgba(246, 240, 223, 0.86);
color: var(--ink);
font-family: Georgia, serif;
font-size: 12px;
font-weight: 700;
box-shadow: 0 4px 12px rgba(23, 51, 51, 0.13);
transform: translate(-50%, -50%);
white-space: nowrap;
}
.place-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: rgba(23, 51, 51, 0.35);
}
.view-hint {
position: fixed;
z-index: 6;
right: 24px;
bottom: 91px;
padding: 5px 8px;
border-radius: 6px;
background: rgba(23, 51, 51, 0.65);
color: white;
font-size: 8.5px;
font-weight: 750;
letter-spacing: 0.03em;
pointer-events: none;
}
@media (max-width: 1050px) {
.panel {
width: 310px;
}
.results {
width: 310px;
}
.replay {
left: 354px;
}
}
@media (max-width: 760px) {
.masthead {
top: 12px;
left: 12px;
}
.date-block {
width: 48px;
height: 48px;
border-radius: 12px;
}
.date-block span {
font-size: 18px;
}
.masthead h1 {
max-width: 260px;
font-size: 19px;
}
.masthead p {
display: none;
}
.model-badge {
margin-top: 4px;
font-size: 7px;
}
.panel {
top: 78px;
right: 12px;
bottom: auto;
left: 12px;
width: auto;
max-height: 35vh;
padding: 14px;
border-radius: 15px;
}
.panel h2 {
font-size: 18px;
}
.intro {
margin-bottom: 12px;
}
.results {
top: auto;
right: 12px;
bottom: 78px;
left: 12px;
width: auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.results-heading,
.comparison,
.disclaimer {
grid-column: 1 / -1;
}
.results-heading {
padding: 10px 12px;
}
.results-heading h2 {
font-size: 16px;
}
.results-heading p {
display: none;
}
.result-card {
margin: 0;
padding: 11px;
}
.result-title h3 {
font-size: 15px;
}
.vehicle-icon {
width: 25px;
height: 25px;
font-size: 14px;
}
.result-stats {
gap: 5px;
margin-top: 9px;
}
.stat {
padding: 7px;
}
.stat strong {
font-size: 18px;
}
.last-load {
display: none;
}
.comparison {
padding: 8px 10px;
font-size: 9px;
}
.disclaimer {
display: none;
}
.replay {
right: 12px;
bottom: 10px;
left: 12px;
grid-template-columns: 1fr;
gap: 4px;
min-height: 60px;
padding: 8px 11px;
}
.replay-title,
.replay-status {
display: none;
}
.view-hint {
display: none;
}
.place-label {
font-size: 10px;
}
}
@media (max-width: 420px) {
.results {
grid-template-columns: 1fr 1fr;
}
.result-title h3 {
font-size: 13px;
}
.capacity {
font-size: 8px;
}
.stat span {
font-size: 7px;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive voxel scene comparing a road wagon and an early railway wagon"></div>
<header class="masthead">
<div class="date-block" aria-hidden="true">
<span>1825</span>
<small>OPENED</small>
</div>
<div>
<h1>Stockton & Darlington Railway</h1>
<p>An equal-load transport comparison</p>
<span class="model-badge">Illustrative model · not recorded performance</span>
</div>
</header>
<aside class="panel" aria-label="Comparison controls and assumptions">
<p class="eyebrow">27 September 1825</p>
<h2>How would the same load move?</h2>
<p class="intro">
Move one selected payload over a generalized route, using either a period-style
road wagon or an early railway consist.
</p>
<div class="section-label">
<strong>Payload for each option</strong>
<output id="payload-output" for="payload">8 t</output>
</div>
<div class="load-control">
<input
id="payload"
type="range"
min="1"
max="24"
step="1"
value="8"
aria-label="Illustrative payload in tonnes"
>
<div class="range-ends">
<span>1 tonne</span>
<span>24 tonnes</span>
</div>
</div>
<div class="section-label">
<strong>Visible option</strong>
</div>
<div class="segmented" role="group" aria-label="Visible transport option">
<button type="button" data-mode="road">Road</button>
<button type="button" data-mode="rail">Early rail</button>
<button type="button" data-mode="both" class="active">Both</button>
</div>
<div class="actions">
<button id="run" type="button" class="primary">Run equal-load comparison</button>
<button id="reset" type="button" class="reset" aria-label="Reset replay" title="Reset replay">↺</button>
</div>
<details class="assumption-box" open>
<summary>Stated model assumptions</summary>
<ul>
<li>Generalized illustrative route: <strong>40 km one way</strong>, not a surveyed historical distance.</li>
<li>Road wagon capacity: <strong>1.5 t</strong>. Early rail wagon capacity: <strong>8.0 t</strong>.</li>
<li>Effective travel speeds: <strong>6 km/h by road</strong> and <strong>18 km/h by rail</strong>, including ordinary route stops.</li>
<li>Loading and unloading allowances: road <strong>0.60 + 0.35 h</strong>; rail <strong>0.25 + 0.15 h</strong> per trip.</li>
<li>One vehicle makes sequential trips and returns empty between trips, except after the final delivery.</li>
<li>No crew shifts, breakdowns, weather, congestion, or other delays are modeled.</li>
</ul>
</details>
<div class="history-note">
<p>
<strong>Historical context:</strong> the Stockton & Darlington Railway opened on
27 September 1825. Its Stockton–Darlington passenger service is often credited as
the first public railway passenger service. The landscape and vehicles here are
generalized voxel interpretations inspired by the period, not a reconstruction.
</p>
</div>
</aside>
<section class="results" aria-label="Illustrative comparison results" aria-live="polite">
<div class="results-heading">
<p class="eyebrow">Equal payload · equal route</p>
<h2>Illustrative results</h2>
<p>
Capacity and timing below are hypothetical teaching assumptions. They are not
measurements of opening-day performance.
</p>
</div>
<article id="road-card" class="result-card road">
<div class="result-title">
<div>
<h3>Road wagon</h3>
<div class="capacity">Illustrative capacity: 1.5 t per vehicle</div>
</div>
<div class="vehicle-icon" aria-hidden="true">▰</div>
</div>
<div class="result-stats">
<div class="stat">
<span>Trips</span>
<strong id="road-trips">6</strong>
</div>
<div class="stat">
<span>Model time</span>
<strong id="road-time">79.0<small>h</small></strong>
</div>
</div>
<div class="last-load" id="road-last">Final trip carries 0.5 t</div>
</article>
<article id="rail-card" class="result-card rail">
<div class="result-title">
<div>
<h3>Early rail wagon</h3>
<div class="capacity">Illustrative capacity: 8.0 t per vehicle</div>
</div>
<div class="vehicle-icon" aria-hidden="true">▥</div>
</div>
<div class="result-stats">
<div class="stat">
<span>Trips</span>
<strong id="rail-trips">1</strong>
</div>
<div class="stat">
<span>Model time</span>
<strong id="rail-time">2.6<small>h</small></strong>
</div>
</div>
<div class="last-load" id="rail-last">Final trip carries 8.0 t</div>
</article>
<div class="comparison" id="comparison">
<strong>Under these assumptions:</strong> the rail option takes fewer modelled hours.
</div>
<div class="disclaimer">
Historical opening date and railway significance are contextual. All capacities,
distances, speeds, handling times and totals in this interface are assumptions.
</div>
</section>
<div class="replay" aria-label="Replay progress">
<div>
<div class="replay-title">Equal-load replay</div>
<div class="replay-status" id="replay-status">Ready to compare</div>
</div>
<div>
<div class="progress-row">
<span>Road</span>
<div class="progress-track"><div id="road-progress" class="progress-fill"></div></div>
<span id="road-percent">0%</span>
</div>
<div class="progress-row">
<span>Rail</span>
<div class="progress-track"><div id="rail-progress" class="progress-fill rail"></div></div>
<span id="rail-percent">0%</span>
</div>
</div>
</div>
<div class="view-hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET VIEW</div>
<div id="stockton-label" class="place-label">Stockton</div>
<div id="darlington-label" class="place-label">Darlington</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model constants. These are deliberately explicit hypothetical assumptions.
// -------------------------------------------------------------------------
const MODEL = {
distanceKm: 40,
road: {
capacityT: 1.5,
speedKmh: 6,
loadHours: 0.60,
unloadHours: 0.35
},
rail: {
capacityT: 8,
speedKmh: 18,
loadHours: 0.25,
unloadHours: 0.15
}
};
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d8ce);
scene.fog = new THREE.Fog(0xb9d8ce, 70, 135);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
220
);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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.12;
viewport.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Voxel landscape with a road wagon and an early railway wagon"
);
// -------------------------------------------------------------------------
// Lighting and materials
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf8f1d8, 0x55776d, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1ce, 3.2);
sun.position.set(-24, 42, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -52;
sun.shadow.camera.right = 52;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 110;
sun.shadow.bias = -0.0004;
scene.add(sun);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
const MAT = {
grass: material(0x789a65),
grassDark: material(0x557b59),
grassLight: material(0x94ad73),
soil: material(0x6f6650),
gravel: material(0x777b70),
sleeper: material(0x594b39),
rail: material(0x646b69, { metalness: 0.48, roughness: 0.38 }),
road: material(0xb99a70),
roadEdge: material(0x8c7959),
wood: material(0x80583a),
woodLight: material(0xb57e48),
darkWood: material(0x4e392d),
cream: material(0xe8d7ae),
brick: material(0xa65d45),
roof: material(0x4f5a55),
iron: material(0x263b3a),
green: material(0x285e56),
greenLight: material(0x3f7566),
brass: material(0xc89b3d, { metalness: 0.35, roughness: 0.4 }),
crate: material(0xd58d38),
crateBand: material(0xf1c36d),
horse: material(0x8b5238),
horseDark: material(0x653d30),
window: material(0x87b3b0, { metalness: 0.12, roughness: 0.42 }),
tree: material(0x3f6b4d),
treeLight: material(0x577e52),
trunk: material(0x654936),
cloud: material(0xf2eee0, { transparent: true, opacity: 0.8 })
};
function box(width, height, depth, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Voxel landscape
// -------------------------------------------------------------------------
box(92, 1.2, 38, MAT.grass, 0, -0.8, 0);
box(92, 0.8, 5, MAT.grassDark, 0, -0.25, 15.5);
// Low stepped hills behind the route.
[
[-31, 13, 15, 4, 9],
[-18, 15, 13, 3, 8],
[1, 16, 18, 4, 10],
[22, 14, 15, 3, 9],
[36, 13, 13, 4, 8]
].forEach(([x, z, w, h, d]) => {
box(w, h, d, MAT.grassDark, x, h / 2 - 0.3, z);
box(w * 0.72, 1.6, d * 0.72, MAT.grassLight, x, h + 0.45, z);
});
// Rail formation.
box(64, 0.24, 3.7, MAT.gravel, 0, 0.02, 2);
for (let x = -31.3; x <= 31.3; x += 1.45) {
box(0.38, 0.18, 3.25, MAT.sleeper, x, 0.22, 2);
}
box(64, 0.2, 0.15, MAT.rail, 0, 0.4, 1.27);
box(64, 0.2, 0.15, MAT.rail, 0, 0.4, 2.73);
// Road formation.
box(64, 0.13, 4.2, MAT.roadEdge, 0, -0.02, -4.8);
box(64, 0.1, 3.65, MAT.road, 0, 0.06, -4.8);
// Small milestones.
for (let x = -24; x <= 24; x += 12) {
box(0.28, 1.15, 0.28, MAT.cream, x, 0.58, -6.9);
box(0.34, 0.22, 0.34, MAT.red, x, 1.08, -6.9);
}
let seed = 1825;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
box(0.42, 2.4, 0.42, MAT.trunk, 0, 1.2, 0, group);
box(2.4, 1.8, 2.4, MAT.tree, 0, 3.05, 0, group);
box(1.85, 1.4, 1.85, MAT.treeLight, 0, 4.15, 0, group);
box(1.25, 1.05, 1.25, MAT.tree, 0, 5, 0, group);
scene.add(group);
}
[
[-40, -12], [-36, 10], [-30, 12], [-24, -13], [-18, 11],
[-13, -14], [-7, 12], [3, -13], [9, 12], [16, -13],
[22, 11], [29, 12], [36, -12], [40, 9], [-43, 5], [43, 5]
].forEach(([x, z]) => makeTree(x, z, 0.7 + random() * 0.45));
function makeHouse(x, z, width = 5, depth = 4, height = 3.2, wallMat = MAT.cream) {
const group = new THREE.Group();
group.position.set(x, 0, z);
box(width, height, depth, wallMat, 0, height / 2, 0, group);
// Stepped voxel roof.
box(width + 0.45, 0.55, depth + 0.45, MAT.roof, 0, height + 0.25, 0, group);
box(width * 0.78, 0.55, depth * 0.78, MAT.roof, 0, height + 0.78, 0, group);
box(width * 0.52, 0.48, depth * 0.52, MAT.roof, 0, height + 1.27, 0, group);
box(0.75, 1.4, 0.12, MAT.darkWood, 0, 0.7, depth / 2 + 0.07, group);
box(0.72, 0.68, 0.12, MAT.window, -width * 0.28, height * 0.62, depth / 2 + 0.08, group);
box(0.72, 0.68, 0.12, MAT.window, width * 0.28, height * 0.62, depth / 2 + 0.08, group);
box(0.65, 1.45, 0.65, MAT.brick, width * 0.28, height + 1.2, -depth * 0.22, group);
scene.add(group);
}
makeHouse(-34, -11.5, 6, 4.5, 3.4, MAT.cream);
makeHouse(-27, -12.5, 4.5, 4, 2.8, MAT.brick);
makeHouse(34, -11.5, 6, 4.5, 3.4, MAT.cream);
makeHouse(27, -12.5, 4.5, 4, 2.8, MAT.brick);
makeHouse(-15, 10, 4, 3, 2.5, MAT.cream);
makeHouse(13, 10.5, 4.5, 3.5, 2.8, MAT.brick);
// Warehouses beside the terminal areas.
function makeWarehouse(x, z, brickMat) {
const group = new THREE.Group();
group.position.set(x, 0, z);
box(6.5, 3.4, 4.4, brickMat, 0, 1.7, 0, group);
box(7, 0.55, 4.9, MAT.roof, 0, 3.65, 0, group);
box(2.3, 2.2, 0.14, MAT.darkWood, 0, 1.1, 2.27, group);
for (let i = -1; i <= 1; i++) {
box(0.7, 0.65, 0.12, MAT.window, i * 1.85, 2.25, 2.25, group);
}
scene.add(group);
}
makeWarehouse(-31.5, 7.2, MAT.brick);
makeWarehouse(31.5, 7.2, MAT.brick);
// Voxel clouds.
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
box(4, 1.1, 1.5, MAT.cloud, 0, 0, 0, group);
box(2, 1.8, 1.7, MAT.cloud, -1.1, 0.7, 0, group);
box(2.4, 2.1, 1.7, MAT.cloud, 0.7, 0.85, 0, group);
box(1.6, 1.4, 1.5, MAT.cloud, 2.1, 0.2, 0, group);
scene.add(group);
}
makeCloud(-23, 17, -17, 1.2);
makeCloud(16, 19, -19, 1.45);
makeCloud(38, 15, -13, 0.9);
// -------------------------------------------------------------------------
// Cargo helpers
// -------------------------------------------------------------------------
function makeCargoSlot(parent, x, y, z, capacity = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const crate = box(0.58, 0.58, 0.58, MAT.crate, 0, 0, 0, group);
box(0.61, 0.08, 0.61, MAT.crateBand, 0, 0, 0, group);
crate.userData.capacity = capacity;
crate.userData.baseY = y;
crate.userData.homeY = y;
crate.userData.group = group;
return crate;
}
function setCargo(slots, amount) {
let remaining = Math.max(0, amount);
slots.forEach((slot) => {
const group = slot.userData.group;
const capacity = slot.userData.capacity;
const visible = remaining > 0.0001;
group.visible = visible;
if (visible) {
const factor = Math.min(1, remaining / capacity);
const baseScaleY = slot.scale.y;
group.scale.y = Math.max(0.06, factor) * baseScaleY;
group.position.y = slot.userData.baseY - 0.29 * (1 - factor);
remaining -= Math.min(remaining, capacity);
}
});
}
// -------------------------------------------------------------------------
// Early rail consist: a Locomotion-inspired block silhouette and a wagon.
// -------------------------------------------------------------------------
const railVehicle = new THREE.Group();
railVehicle.position.set(-29, 0, 2);
scene.add(railVehicle);
// Locomotive.
box(4.5, 0.34, 2.05, MAT.iron, 1.65, 0.72, 0, railVehicle);
box(3.25, 1.55, 1.75, MAT.green, 1.55, 1.55, 0, railVehicle);
box(1.35, 2.1, 1.38, MAT.greenLight, 1.95, 2.25, 0, railVehicle);
box(1.05, 0.48, 1.06, MAT.brass, 1.95, 3.5, 0, railVehicle);
box(0.46, 1.05, 0.46, MAT.iron, 1.95, 4.1, 0, railVehicle);
box(0.62, 0.2, 0.62, MAT.iron, 1.95, 4.66, 0, railVehicle);
box(1.55, 1.65, 1.85, MAT.wood, -0.25, 1.62, 0, railVehicle);
box(1.72, 0.18, 1.98, MAT.roof, -0.25, 2.54, 0, railVehicle);
box(0.72, 0.7, 0.12, MAT.window, -0.25, 1.82, 0.98, railVehicle);
box(0.12, 0.7, 0.72, MAT.window, 0.57, 1.82, 0, railVehicle);
box(0.45, 0.55, 1.35, MAT.brass, 0.35, 0.82, 0, railVehicle);
// Voxel wheels and connecting rod.
[-1.2, 0.2, 1.55, 2.9].forEach((x) => {
box(0.72, 0.72, 0.25, MAT.iron, x, 0.45, -0.94, railVehicle);
box(0.72, 0.72, 0.25, MAT.iron, x, 0.45, 0.94, railVehicle);
box(0.24, 0.24, 2.0, MAT.iron, x, 0.45, 0, railVehicle);
});
box(3.5, 0.16, 0.12, MAT.brass, 1.25, 0.49, 1.08, railVehicle);
// Buffer beam and voxel steps.
box(0.22, 0.4, 2.25, MAT.wood, 3.85, 0.72, 0, railVehicle);
box(0.45, 0.22, 2.45, MAT.iron, 3.98, 0.52, 0, railVehicle);
box(0.42, 0.2, 2.4, MAT.iron, 4.12, 0.34, 0, railVehicle);
// Railway wagon.
const railWagon = new THREE.Group();
railWagon.position.set(-2.45, 0, 0);
railVehicle.add(railWagon);
box(3.7, 0.28, 2.1, MAT.woodLight, 0, 0.95, 0, railWagon);
box(0.2, 0.65, 2.15, MAT.darkWood, -1.75, 1.25, 0, railWagon);
box(0.2, 0.65, 2.15, MAT.darkWood, 1.75, 1.25, 0, railWagon);
box(3.4, 0.35, 0.12, MAT.darkWood, 0, 1.2, -1.0, railWagon);
box(3.4, 0.35, 0.12, MAT.darkWood, 0, 1.2, 1.0, railWagon);
[-1.25, 1.25].forEach((x) => {
box(0.56, 0.56, 0.22, MAT.iron, x, 0.47, -0.96, railWagon);
box(0.56, 0.56, 0.22, MAT.iron, x, 0.47, 0.96, railWagon);
});
const railCargoSlots = [];
for (let col = 0; col < 4; col++) {
for (const z of [-0.48, 0.48]) {
railCargoSlots.push(
makeCargoSlot(
railVehicle,
-3.72 + col * 0.68,
1.4,
z,
1
)
);
}
}
// -------------------------------------------------------------------------
// Road wagon and blocky horse.
// -------------------------------------------------------------------------
const roadVehicle = new THREE.Group();
roadVehicle.position.set(-29, 0, -4.8);
scene.add(roadVehicle);
const roadWagon = new THREE.Group();
roadWagon.position.set(-1.45, 0, 0);
roadVehicle.add(roadWagon);
box(2.7, 0.25, 1.85, MAT.woodLight, 0, 0.88, 0, roadWagon);
box(2.55, 0.55, 0.16, MAT.wood, 0, 1.2, -0.87, roadWagon);
box(2.55, 0.55, 0.16, MAT.wood, 0, 1.2, 0.87, roadWagon);
box(0.16, 0.55, 1.7, MAT.wood, -1.22, 1.2, 0, roadWagon);
box(0.16, 0.55, 1.7, MAT.wood, 1.22, 1.2, 0, roadWagon);
[-0.83, 0.83].forEach((x) => {
box(0.72, 0.72, 0.22, MAT.darkWood, x, 0.47, -0.92, roadWagon);
box(0.72, 0.72, 0.22, MAT.darkWood, x, 0.47, 0.92, roadWagon);
box(0.22, 0.22, 1.95, MAT.darkWood, x, 0.47, 0, roadWagon);
});
box(0.14, 0.14, 2.3, MAT.wood, 0.8, 0.55, 0, roadWagon);
const roadCargoSlots = [
makeCargoSlot(roadVehicle, -2.05, 1.34, -0.42, 1),
makeCargoSlot(roadVehicle, -0.95, 1.34, 0.42, 0.5)
];
// Horse.
const horse = new THREE.Group();
horse.position.set(2.0, 0, 0);
roadVehicle.add(horse);
box(1.75, 0.72, 0.68, MAT.horse, 0, 1.5, 0, horse);
box(0.65, 1.15, 0.58, MAT.horse, 0.7, 1.75, 0, horse);
box(0.78, 0.5, 0.5, MAT.horse, 1.12, 2.25, 0, horse);
box(0.32, 0.58, 0.52, MAT.horseDark, 0.95, 2.65, 0, horse);
box(0.24, 0.28, 0.15, MAT.iron, 1.48, 2.3, 0, horse);
box(0.25, 0.85, 0.18, MAT.horseDark, -0.85, 1.55, 0, horse);
const horseLegs = [];
[
[0.55, -0.24], [0.55, 0.24], [-0.55, -0.24], [-0.55, 0.24]
].forEach(([x, z]) => {
const leg = box(0.22, 0.95, 0.22, MAT.horseDark, x, 0.78, z, horse);
horseLegs.push(leg);
});
// Shafts linking horse and wagon.
box(1.8, 0.12, 0.12, MAT.wood, 0.6, 0.87, -0.55, roadVehicle);
box(1.8, 0.12, 0.12, MAT.wood, 0.6, 0.87, 0.55, roadVehicle);
// -------------------------------------------------------------------------
// Destination cargo piles
// -------------------------------------------------------------------------
function makePile(baseX, baseZ) {
const slots = [];
for (let i = 0; i < 24; i++) {
const layer = Math.floor(i / 8);
const column = i % 8;
slots.push(
makeCargoSlot(
scene,
baseX + (column - 3.5) * 0.58,
0.35 + layer * 0.59,
baseZ,
1
)
);
}
setCargo(slots, 0);
return slots;
}
const roadPile = makePile(31.5, -7.25);
const railPile = makePile(31.5, 4.55);
// -------------------------------------------------------------------------
// Steam puffs
// -------------------------------------------------------------------------
const smokePuffs = [];
for (let i = 0; i < 12; i++) {
const puff = box(
0.45,
0.45,
0.45,
new THREE.MeshStandardMaterial({
color: 0xf2eee0,
transparent: true,
opacity: 0.5,
roughness: 1
}),
0,
0,
0,
scene
);
puff.castShadow = false;
smokePuffs.push(puff);
}
// -------------------------------------------------------------------------
// Manual camera controls: orbit and zoom only; no external controls addon.
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.63,
phi: 0.91,
radius: window.innerWidth < 760 ? 91 : 73,
target: new THREE.Vector3(0, 1.5, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.cos(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.sin(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.theta = 0.63;
cameraState.phi = 0.91;
cameraState.radius = window.innerWidth < 760 ? 91 : 73;
cameraState.target.set(0, 1.5, 0);
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.004,
0.35,
1.28
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.055,
43,
108
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
updateCamera();
// -------------------------------------------------------------------------
// Model calculations and replay state
// -------------------------------------------------------------------------
const payloadInput = document.getElementById("payload");
const payloadOutput = document.getElementById("payload-output");
const runButton = document.getElementById("run");
const resetButton = document.getElementById("reset");
const modeButtons = [...document.querySelectorAll("[data-mode]")];
let selectedMode = "both";
let payload = Number(payloadInput.value);
let playing = false;
let started = false;
let completed = false;
let realTime = 0;
const modeProgress = { road: 0, rail: 0 };
const timelines = { road: null, rail: null };
const modeStatus = { road: "Ready", rail: "Ready" };
function tripCount(mode, load) {
return Math.ceil(load / MODEL[mode].capacityT);
}
function totalTime(mode, load) {
const config = MODEL[mode];
const travel = MODEL.distanceKm / config.speedKmh;
const trips = tripCount(mode, load);
return (
trips * (config.loadHours + travel + config.unloadHours) +
Math.max(0, trips - 1) * travel
);
}
function buildTimeline(mode, load) {
const config = MODEL[mode];
const travel = MODEL.distanceKm / config.speedKmh;
const trips = tripCount(mode, load);
const segments = [];
let delivered = 0;
for (let i = 0; i < trips; i++) {
const amount = Math.min(
config.capacityT,
load - i * config.capacityT
);
segments.push({
type: "load",
duration: config.loadHours,
amount,
trip: i + 1,
deliveredBefore: delivered
});
segments.push({
type: "outbound",
duration: travel,
amount,
trip: i + 1,
deliveredBefore: delivered
});
segments.push({
type: "unload",
duration: config.unloadHours,
amount,
trip: i + 1,
deliveredBefore: delivered
});
delivered += amount;
if (i < trips - 1) {
segments.push({
type: "return",
duration: travel,
amount: 0,
trip: i + 1,
deliveredBefore: delivered
});
}
}
return {
segments,
total: segments.reduce((sum, segment) => sum + segment.duration, 0)
};
}
function formatDuration(hours) {
const minutes = Math.round(hours * 60);
const days = Math.floor(minutes / 1440);
const hoursLeft = Math.floor((minutes % 1440) / 60);
const mins = minutes % 60;
if (days > 0) return `${days}d ${hoursLeft}h`;
if (hoursLeft > 0) return `${hoursLeft}h ${mins}m`;
return `${mins}m`;
}
function setStat(element, value, unit) {
element.innerHTML = `${value}<small>${unit}</small>`;
}
function updateMetrics() {
const roadTrips = tripCount("road", payload);
const railTrips = tripCount("rail", payload);
const roadHours = totalTime("road", payload);
const railHours = totalTime("rail", payload);
setStat(document.getElementById("road-trips"), roadTrips, "");
setStat(document.getElementById("rail-trips"), railTrips, "");
setStat(document.getElementById("road-time"), roadHours.toFixed(1), "h");
setStat(document.getElementById("rail-time"), railHours.toFixed(1), "h");
const roadLast = Math.max(
0,
payload - (roadTrips - 1) * MODEL.road.capacityT
);
const railLast = Math.max(
0,
payload - (railTrips - 1) * MODEL.rail.capacityT
);
document.getElementById("road-last").textContent =
`Final trip carries ${roadLast.toFixed(1)} t`;
document.getElementById("rail-last").textContent =
`Final trip carries ${railLast.toFixed(1)} t`;
const tonneKm = payload * MODEL.distanceKm;
const difference = roadHours - railHours;
const percent = roadHours > 0
? Math.round((difference / roadHours) * 100)
: 0;
document.getElementById("comparison").innerHTML =
`<strong>${payload} t over ${MODEL.distanceKm} km</strong> means ` +
`${tonneKm} t·km for each option. Under these assumptions, the rail model ` +
`uses ${formatDuration(difference)} less time (${percent}% less). ` +
`This is a model comparison, not an opening-day result.`;
}
function updateRangeFill() {
const min = Number(payloadInput.min);
const max = Number(payloadInput.max);
const percentage = ((payload - min) / (max - min)) * 100;
payloadInput.style.background =
`linear-gradient(to right, var(--green) 0%, var(--green) ${percentage}%, ` +
`#c8cec5 ${percentage}%, #c8cec5 100%)`;
}
function resetReplay() {
playing = false;
started = false;
completed = false;
modeProgress.road = 0;
modeProgress.rail = 0;
modeStatus.road = "Ready";
modeStatus.rail = "Ready";
runButton.textContent = "Run equal-load comparison";
applyModeState("road", 0);
applyModeState("rail", 0);
updateProgressUI();
}
function togglePlayback() {
if (!started || completed) {
if (selectedMode === "road" || selectedMode === "both") {
modeProgress.road = 0;
}
if (selectedMode === "rail" || selectedMode === "both") {
modeProgress.rail = 0;
}
started = true;
completed = false;
playing = true;
} else {
playing = !playing;
}
runButton.textContent = playing
? "Pause replay"
: completed
? "Replay comparison"
: "Resume replay";
}
function applyModeState(mode, progress) {
const timeline = timelines[mode];
if (!timeline) return;
const t = Math.max(0, Math.min(1, progress)) * timeline.total;
let segment = timeline.segments[timeline.segments.length - 1];
let localTime = segment.duration;
let segmentStart = 0;
for (let i = 0; i < timeline.segments.length; i++) {
const candidate = timeline.segments[i];
const end = segmentStart + candidate.duration;
if (t <= end + 0.000001) {
segment = candidate;
localTime = Math.max(0, t - segmentStart);
break;
}
segmentStart = end;
}
const fraction = segment.duration > 0
? Math.min(1, localTime / segment.duration)
: 1;
let vehicleAmount = 0;
let delivered = segment.deliveredBefore;
if (segment.type === "load") {
vehicleAmount = segment.amount * fraction;
modeStatus[mode] = `Loading trip ${segment.trip}`;
} else if (segment.type === "outbound") {
vehicleAmount = segment.amount;
modeStatus[mode] = `Loaded run · trip ${segment.trip}`;
} else if (segment.type === "unload") {
vehicleAmount = segment.amount * (1 - fraction);
delivered = segment.deliveredBefore + segment.amount * fraction;
modeStatus[mode] = `Unloading trip ${segment.trip}`;
} else {
modeStatus[mode] = `Empty return after trip ${segment.trip}`;
}
if (progress >= 0.999999) {
delivered = payload;
vehicleAmount = 0;
modeStatus[mode] = "Payload delivered";
}
const vehicle = mode === "road" ? roadVehicle : railVehicle;
const cargoSlots = mode === "road" ? roadCargoSlots : railCargoSlots;
const pile = mode === "road" ? roadPile : railPile;
setCargo(cargoSlots, vehicleAmount);
setCargo(pile, delivered);
if (segment.type === "outbound") {
vehicle.position.x = THREE.MathUtils.lerp(-29, 27, fraction);
vehicle.rotation.y = 0;
} else if (segment.type === "return") {
vehicle.position.x = THREE.MathUtils.lerp(27, -29, fraction);
vehicle.rotation.y = Math.PI;
} else if (segment.type === "unload") {
vehicle.position.x = 27;
vehicle.rotation.y = 0;
} else {
vehicle.position.x = -29;
vehicle.rotation.y = 0;
}
if (mode === "road") {
horseLegs.forEach((leg, index) => {
leg.rotation.z =
segment.type === "outbound" || segment.type === "return"
? Math.sin(realTime * 8 + index * 1.7) * 0.22
: 0;
});
}
}
function updateProgressUI() {
const roadPercent = Math.round(modeProgress.road * 100);
const railPercent = Math.round(modeProgress.rail * 100);
document.getElementById("road-progress").style.width = `${roadPercent}%`;
document.getElementById("rail-progress").style.width = `${railPercent}%`;
document.getElementById("road-percent").textContent = `${roadPercent}%`;
document.getElementById("rail-percent").textContent = `${railPercent}%`;
const status = document.getElementById("replay-status");
if (selectedMode === "both") {
status.textContent = `Road: ${modeStatus.road} · Rail: ${modeStatus.rail}`;
} else if (selectedMode === "road") {
status.textContent = `Road: ${modeStatus.road}`;
} else {
status.textContent = `Rail: ${modeStatus.rail}`;
}
status.title = "Replay is normalized for comparison and is not to time scale.";
}
function updateVisibility() {
roadVehicle.visible = selectedMode === "road" || selectedMode === "both";
railVehicle.visible = selectedMode === "rail" || selectedMode === "both";
document
.getElementById("road-card")
.classList.toggle("inactive", selectedMode === "rail");
document
.getElementById("rail-card")
.classList.toggle("inactive", selectedMode === "road");
modeButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.mode === selectedMode);
});
updateProgressUI();
}
payloadInput.addEventListener("input", () => {
payload = Number(payloadInput.value);
payloadOutput.textContent = `${payload} t`;
timelines.road = buildTimeline("road", payload);
timelines.rail = buildTimeline("rail", payload);
updateRangeFill();
updateMetrics();
resetReplay();
});
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
selectedMode = button.dataset.mode;
updateVisibility();
});
});
runButton.addEventListener("click", togglePlayback);
resetButton.addEventListener("click", resetReplay);
timelines.road = buildTimeline("road", payload);
timelines.rail = buildTimeline("rail", payload);
payloadOutput.textContent = `${payload} t`;
updateRangeFill();
updateMetrics();
updateVisibility();
resetReplay();
// -------------------------------------------------------------------------
// Projected place labels
// -------------------------------------------------------------------------
const stocktonLabel = document.getElementById("stockton-label");
const darlingtonLabel = document.getElementById("darlington-label");
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
realTime += delta;
if (playing) {
// The replay normalizes each option's sequence to the same visual
// duration; it is explicitly not a time-scale simulation.
const increment = delta / 24;
if (selectedMode === "road" || selectedMode === "both") {
modeProgress.road = Math.min(1, modeProgress.road + increment);
}
if (selectedMode === "rail" || selectedMode === "both") {
modeProgress.rail = Math.min(1, modeProgress.rail + increment);
}
const selectedProgress =
selectedMode === "road"
? modeProgress.road
: selectedMode === "rail"
? modeProgress.rail
: Math.max(modeProgress.road, modeProgress.rail);
if (selectedProgress >= 1) {
playing = false;
completed = true;
runButton.textContent = "Replay comparison";
}
}
applyModeState("road", modeProgress.road);
applyModeState("rail", modeProgress.rail);
updateProgressUI();
// Voxel steam trail.
smokePuffs.forEach((puff, index) => {
const phase = (realTime * 0.13 + index / smokePuffs.length) % 1;
puff.position.set(
railVehicle.position.x + 2.0 + phase * 3.2,
5.0 + phase * 7.5,
2 + Math.sin(index * 1.9) * 0.18
);
const size = 0.35 + phase * 0.85;
puff.scale.setScalar(size);
puff.material.opacity = (1 - phase) * 0.55;
});
positionLabel(stocktonLabel, new THREE.Vector3(-33, 2.5, -8.2));
positionLabel(darlingtonLabel, new THREE.Vector3(33, 2.5, -8.2));
renderer.render(scene, camera);
});
</script>
</body>
</html>
```