Prompt specification
Build or customize the Three.js 3D scene "Fast Route With a Slow Transfer" 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: Fast Route With a Slow Transfer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fast-route-with-a-slow-transfer-x2104
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: fast route with a slow transfer. Compare two delivery itineraries with different travel and transfer durations. Compute total arrival times from explicit schedules and reveal when a seemingly faster mode loses overall.
Working Three.js Starter (fast-route-with-a-slow-transfer-x2104):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Last Mile Lab — Fast Is Not the Finish Line</title>
<style>
:root {
--ink: #07161d;
--panel: rgba(8, 24, 32, 0.92);
--panel-soft: rgba(10, 31, 40, 0.78);
--line: rgba(206, 240, 242, 0.15);
--text: #edf8f7;
--muted: #9bb5b8;
--cyan: #40e0d6;
--cyan-dark: #153f43;
--amber: #ffb35f;
--amber-dark: #493526;
--green: #9ee66c;
--shadow: 0 20px 50px rgba(0, 12, 18, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--text);
background: #a8cfd1;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select,
input {
color-scheme: dark;
}
button {
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#world-labels {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 7px;
color: #17323a;
background: rgba(244, 252, 250, 0.9);
box-shadow: 0 5px 18px rgba(24, 51, 56, 0.16);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
will-change: left, top;
}
.world-label::after {
position: absolute;
bottom: -8px;
left: 50%;
width: 1px;
height: 8px;
content: "";
background: rgba(23, 50, 58, 0.5);
}
.world-label i {
width: 7px;
height: 7px;
border-radius: 2px;
background: #1d5960;
}
.header {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 20px 24px 30px;
pointer-events: none;
background: linear-gradient(
180deg,
rgba(5, 19, 26, 0.91),
rgba(5, 19, 26, 0.55) 66%,
transparent
);
}
.brand {
display: flex;
align-items: center;
gap: 14px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
}
.brand-mark span {
position: absolute;
width: 16px;
height: 16px;
border-radius: 3px;
background: var(--cyan);
box-shadow: 0 0 20px rgba(64, 224, 214, 0.2);
}
.brand-mark span:nth-child(1) {
top: 2px;
left: 11px;
}
.brand-mark span:nth-child(2) {
top: 18px;
left: 2px;
background: #d8f4ef;
}
.brand-mark span:nth-child(3) {
top: 18px;
left: 20px;
background: var(--amber);
}
.eyebrow {
margin: 0 0 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.4vw, 36px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1;
}
.header-note {
max-width: 330px;
color: #b8cccf;
font-size: 12px;
line-height: 1.5;
text-align: right;
}
.panel {
position: fixed;
z-index: 8;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.routes-panel {
top: 100px;
left: 24px;
width: 362px;
max-height: calc(100vh - 218px);
overflow: auto;
padding: 18px;
scrollbar-width: thin;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
}
.panel-title h2,
.verdict h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.025em;
}
.formula-pill {
padding: 5px 8px;
border: 1px solid rgba(158, 230, 108, 0.25);
border-radius: 999px;
color: var(--green);
background: rgba(158, 230, 108, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.intro {
margin: 0 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.route-card {
position: relative;
overflow: hidden;
margin-top: 10px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.025);
transition: border-color 180ms ease, background 180ms ease;
}
.route-card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
content: "";
background: var(--route-color);
}
.route-card.is-active {
border-color: color-mix(in srgb, var(--route-color) 54%, transparent);
background: color-mix(in srgb, var(--route-color) 7%, transparent);
}
.route-card.is-done {
border-color: rgba(158, 230, 108, 0.42);
}
.route-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.route-id {
display: flex;
align-items: center;
gap: 8px;
color: var(--route-color);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.route-id::before {
width: 8px;
height: 8px;
border-radius: 2px;
content: "";
background: var(--route-color);
box-shadow: 0 0 12px color-mix(in srgb, var(--route-color) 55%, transparent);
}
.route-card h3 {
margin: 6px 0 3px;
font-size: 18px;
letter-spacing: -0.025em;
}
.route-subtitle {
margin: 0;
color: var(--muted);
font-size: 11px;
}
.arrival {
min-width: 75px;
text-align: right;
}
.arrival span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.arrival strong {
display: block;
color: var(--text);
font-size: 23px;
letter-spacing: -0.04em;
}
.schedule-grid {
display: grid;
grid-template-columns: 1.15fr 0.9fr 0.9fr;
gap: 7px;
margin-top: 14px;
}
.field label {
display: block;
margin: 0 0 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.field input {
width: 100%;
height: 34px;
padding: 0 8px;
border: 1px solid rgba(213, 239, 239, 0.17);
border-radius: 7px;
outline: none;
color: var(--text);
background: rgba(2, 14, 20, 0.65);
font-size: 12px;
font-weight: 700;
}
.field input:focus {
border-color: var(--route-color);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--route-color) 13%, transparent);
}
.route-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.route-summary strong {
color: var(--text);
font-size: 11px;
}
.route-status {
display: inline-flex;
align-items: center;
gap: 6px;
min-height: 20px;
color: var(--muted);
font-weight: 700;
}
.route-status::before {
width: 6px;
height: 6px;
border-radius: 50%;
content: "";
background: currentColor;
}
.route-card.is-active .route-status {
color: var(--route-color);
}
.route-card.is-done .route-status {
color: var(--green);
}
.note {
margin: 13px 2px 0;
color: #829da1;
font-size: 10px;
line-height: 1.5;
}
.verdict {
top: 100px;
right: 24px;
width: 310px;
padding: 18px;
}
.verdict .eyebrow {
color: var(--amber);
}
.verdict h2 {
margin-top: 8px;
font-size: 21px;
line-height: 1.13;
}
.verdict-copy {
min-height: 63px;
margin: 10px 0 16px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.verdict.revealed {
border-color: rgba(158, 230, 108, 0.36);
box-shadow:
var(--shadow),
0 0 35px rgba(158, 230, 108, 0.08);
}
.verdict.revealed .eyebrow {
color: var(--green);
}
.verdict.revealed h2 {
color: var(--green);
}
.comparison {
padding-top: 13px;
border-top: 1px solid var(--line);
}
.comparison-title {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.bar-row {
margin: 11px 0;
}
.bar-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
font-size: 10px;
}
.bar-label span {
color: var(--muted);
}
.bar-track {
position: relative;
height: 8px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.bar-fill {
position: absolute;
top: 0;
bottom: 0;
border-radius: 999px;
background: var(--bar-color);
opacity: 0.75;
transition: opacity 180ms ease;
}
.bar-row.winner .bar-fill {
opacity: 1;
box-shadow: 0 0 14px color-mix(in srgb, var(--bar-color) 35%, transparent);
}
.insight {
margin-top: 15px;
padding: 10px 11px;
border-left: 2px solid var(--amber);
color: #c9d8d9;
background: rgba(255, 179, 95, 0.06);
font-size: 10px;
line-height: 1.5;
}
.timeline-panel {
right: 24px;
bottom: 22px;
left: 24px;
display: grid;
grid-template-columns: auto auto auto minmax(160px, 1fr) auto;
align-items: center;
gap: 12px;
padding: 12px 14px;
}
.control-button {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 38px;
height: 38px;
padding: 0 12px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 9px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
font-size: 12px;
font-weight: 800;
transition: transform 140ms ease, background 140ms ease;
}
.control-button:hover {
background: rgba(255, 255, 255, 0.11);
transform: translateY(-1px);
}
.control-button.primary {
min-width: 96px;
border-color: rgba(64, 224, 214, 0.4);
color: #062227;
background: var(--cyan);
}
.control-button.primary:hover {
background: #76eee7;
}
.time-readout {
min-width: 57px;
font-variant-numeric: tabular-nums;
font-size: 15px;
font-weight: 850;
letter-spacing: -0.03em;
}
.scrubber-wrap {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
90deg,
var(--cyan) 0 var(--played, 0%),
rgba(255, 255, 255, 0.13) var(--played, 0%) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #0c242c;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #0c242c;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan);
}
.speed-control {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
select {
height: 34px;
padding: 0 27px 0 9px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
outline: none;
background: #102a33;
font-size: 11px;
font-weight: 750;
}
.timeline-meta {
grid-column: 3 / 5;
display: flex;
justify-content: space-between;
margin-top: -5px;
color: #789397;
font-size: 9px;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: #d8f2ef;
background: #102b34;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.header-note {
display: none;
}
.routes-panel {
width: 335px;
}
.verdict {
width: 280px;
}
.timeline-panel {
grid-template-columns: auto auto auto 1fr;
}
.speed-control {
display: none;
}
.timeline-meta {
grid-column: 2 / 5;
}
}
@media (max-width: 680px) {
.header {
padding: 16px 14px 25px;
}
h1 {
font-size: 23px;
}
.brand-mark {
transform: scale(0.82);
}
.routes-panel {
top: 82px;
left: 10px;
width: calc(100% - 20px);
max-height: 41vh;
padding: 13px;
}
.route-card {
padding: 11px;
}
.schedule-grid {
gap: 5px;
}
.verdict {
top: auto;
right: 10px;
bottom: 108px;
width: 235px;
max-height: 35vh;
overflow: auto;
padding: 13px;
}
.verdict h2 {
font-size: 17px;
}
.verdict-copy {
min-height: 0;
margin-bottom: 10px;
}
.insight,
.comparison-title {
display: none;
}
.timeline-panel {
right: 10px;
bottom: 10px;
left: 10px;
grid-template-columns: auto auto 1fr;
gap: 8px;
padding: 9px;
}
.control-button {
height: 34px;
padding: 0 9px;
}
.control-button.primary {
min-width: 80px;
}
#skip {
display: none;
}
.time-readout {
font-size: 12px;
}
.timeline-meta {
display: none;
}
.world-label {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel delivery comparison"></div>
<div id="world-labels" aria-hidden="true">
<div class="world-label" id="label-origin"><i></i>Dispatch</div>
<div class="world-label" id="label-air"><i></i>Sky terminal</div>
<div class="world-label" id="label-relay"><i></i>Road relay</div>
<div class="world-label" id="label-customer"><i></i>Customer</div>
</div>
<header class="header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div>
<p class="eyebrow">Last Mile Lab / Schedule 02</p>
<h1>Fast is not the finish line.</h1>
</div>
</div>
<div class="header-note">
Two delivery itineraries. One deliberately fast leg, one very slow transfer.
Follow the clock to see which package actually arrives first.
</div>
</header>
<aside class="panel routes-panel" aria-label="Delivery schedules">
<div class="panel-title">
<h2>Explicit schedules</h2>
<span class="formula-pill">Arrival = departure + travel + transfer</span>
</div>
<p class="intro">
Edit any duration or departure time. Totals and the replay are calculated
from the complete itinerary, not from the travel leg alone.
</p>
<section class="route-card" id="route-a" style="--route-color: var(--cyan)">
<div class="route-head">
<div>
<div class="route-id">Route A · Swift air</div>
<h3>Skyline sprint</h3>
<p class="route-subtitle">Fast flight, painfully slow ground transfer</p>
</div>
<div class="arrival">
<span>Arrival</span>
<strong id="a-arrival">10:30</strong>
</div>
</div>
<div class="schedule-grid">
<div class="field">
<label for="a-depart">Departure</label>
<input id="a-depart" type="time" value="08:00" step="60">
</div>
<div class="field">
<label for="a-travel">Travel, min</label>
<input id="a-travel" type="number" value="45" min="0" max="600" step="5">
</div>
<div class="field">
<label for="a-transfer">Transfer, min</label>
<input id="a-transfer" type="number" value="105" min="0" max="600" step="5">
</div>
</div>
<div class="route-summary">
<span>Total journey <strong id="a-total">2h 30m</strong></span>
<span class="route-status" id="a-status">Waiting</span>
</div>
</section>
<section class="route-card" id="route-b" style="--route-color: var(--amber)">
<div class="route-head">
<div>
<div class="route-id">Route B · Road relay</div>
<h3>Direct rhythm</h3>
<p class="route-subtitle">Slower road leg, quick final handoff</p>
</div>
<div class="arrival">
<span>Arrival</span>
<strong id="b-arrival">10:10</strong>
</div>
</div>
<div class="schedule-grid">
<div class="field">
<label for="b-depart">Departure</label>
<input id="b-depart" type="time" value="08:15" step="60">
</div>
<div class="field">
<label for="b-travel">Travel, min</label>
<input id="b-travel" type="number" value="95" min="0" max="600" step="5">
</div>
<div class="field">
<label for="b-transfer">Transfer, min</label>
<input id="b-transfer" type="number" value="20" min="0" max="600" step="5">
</div>
</div>
<div class="route-summary">
<span>Total journey <strong id="b-total">1h 55m</strong></span>
<span class="route-status" id="b-status">Waiting</span>
</div>
</section>
<p class="note">
Route A’s first leg is faster. Route B’s complete schedule is shorter.
The replay begins at 08:00 and runs until both deliveries are complete.
</p>
</aside>
<aside class="panel verdict" id="verdict" aria-live="polite">
<p class="eyebrow">Schedule verdict</p>
<h2 id="verdict-title">Waiting for the clock</h2>
<p class="verdict-copy" id="verdict-copy">
The arrival totals above are already computed. Replay both routes to
reveal which itinerary wins end to end.
</p>
<div class="comparison">
<div class="comparison-title">
<span>Wall-clock arrival</span>
<span>Departure → customer</span>
</div>
<div class="bar-row" id="bar-a" style="--bar-color: var(--cyan)">
<div class="bar-label">
<strong>Route A</strong>
<span id="bar-a-text">08:00 → 10:30</span>
</div>
<div class="bar-track"><div class="bar-fill" id="bar-a-fill"></div></div>
</div>
<div class="bar-row" id="bar-b" style="--bar-color: var(--amber)">
<div class="bar-label">
<strong>Route B</strong>
<span id="bar-b-text">08:15 → 10:10</span>
</div>
<div class="bar-track"><div class="bar-fill" id="bar-b-fill"></div></div>
</div>
</div>
<div class="insight">
First-leg speed is not the same as end-to-end speed. Handoffs count.
</div>
</aside>
<section class="panel timeline-panel" aria-label="Schedule replay controls">
<button class="control-button primary" id="play" type="button">▶ Play</button>
<button class="control-button" id="reset" type="button" title="Reset replay">↺</button>
<button class="control-button" id="skip" type="button" title="Jump to the final result">Result</button>
<div class="time-readout" id="clock">08:00</div>
<div class="scrubber-wrap">
<input id="timeline" type="range" min="475" max="650" value="480" step="0.1"
aria-label="Simulation time">
<div class="speed-control">
<label for="speed">Speed</label>
<select id="speed">
<option value="1">1 min/s</option>
<option value="4">4 min/s</option>
<option value="6" selected>6 min/s</option>
<option value="12">12 min/s</option>
<option value="30">30 min/s</option>
</select>
</div>
</div>
<div class="timeline-meta">
<span>Drag the scene to orbit · scroll to zoom</span>
<span id="timeline-end">Ends 10:42</span>
</div>
</section>
<div id="loading">Building the voxel network…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// UI and schedule calculations
// ---------------------------------------------------------------------
const ui = {
aDepart: document.querySelector("#a-depart"),
aTravel: document.querySelector("#a-travel"),
aTransfer: document.querySelector("#a-transfer"),
bDepart: document.querySelector("#b-depart"),
bTravel: document.querySelector("#b-travel"),
bTransfer: document.querySelector("#b-transfer"),
aArrival: document.querySelector("#a-arrival"),
bArrival: document.querySelector("#b-arrival"),
aTotal: document.querySelector("#a-total"),
bTotal: document.querySelector("#b-total"),
aStatus: document.querySelector("#a-status"),
bStatus: document.querySelector("#b-status"),
routeA: document.querySelector("#route-a"),
routeB: document.querySelector("#route-b"),
verdict: document.querySelector("#verdict"),
verdictTitle: document.querySelector("#verdict-title"),
verdictCopy: document.querySelector("#verdict-copy"),
barA: document.querySelector("#bar-a"),
barB: document.querySelector("#bar-b"),
barAFill: document.querySelector("#bar-a-fill"),
barBFill: document.querySelector("#bar-b-fill"),
barAText: document.querySelector("#bar-a-text"),
barBText: document.querySelector("#bar-b-text"),
play: document.querySelector("#play"),
reset: document.querySelector("#reset"),
skip: document.querySelector("#skip"),
timeline: document.querySelector("#timeline"),
clock: document.querySelector("#clock"),
timelineEnd: document.querySelector("#timeline-end"),
speed: document.querySelector("#speed"),
loading: document.querySelector("#loading")
};
const state = {
playing: !matchMedia("(prefers-reduced-motion: reduce)").matches,
current: 480,
speed: 6,
timelineStart: 475,
timelineEnd: 650,
maxArrival: 630,
revealed: false
};
function parseTime(value) {
const match = /^(\d{1,2}):(\d{2})$/.exec(value);
if (!match) return 0;
return Number(match[1]) * 60 + Number(match[2]);
}
function formatTime(minutes) {
const normalized = ((Math.round(minutes) % 1440) + 1440) % 1440;
const h = Math.floor(normalized / 60);
const m = normalized % 60;
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
}
function formatDuration(minutes) {
const h = Math.floor(minutes / 60);
const m = minutes % 60;
if (!h) return `${m}m`;
if (!m) return `${h}h`;
return `${h}h ${m}m`;
}
function positiveNumber(input) {
const value = Number(input.value);
return Number.isFinite(value) ? Math.max(0, value) : 0;
}
function readSchedules() {
const a = {
name: "Skyline sprint",
shortName: "Route A",
depart: parseTime(ui.aDepart.value),
travel: positiveNumber(ui.aTravel),
transfer: positiveNumber(ui.aTransfer)
};
const b = {
name: "Direct rhythm",
shortName: "Route B",
depart: parseTime(ui.bDepart.value),
travel: positiveNumber(ui.bTravel),
transfer: positiveNumber(ui.bTransfer)
};
a.total = a.travel + a.transfer;
b.total = b.travel + b.transfer;
a.arrival = a.depart + a.total;
b.arrival = b.depart + b.total;
return { a, b };
}
let schedules;
function updateScheduleUI() {
schedules = readSchedules();
ui.aArrival.textContent = formatTime(schedules.a.arrival);
ui.bArrival.textContent = formatTime(schedules.b.arrival);
ui.aTotal.textContent = formatDuration(schedules.a.total);
ui.bTotal.textContent = formatDuration(schedules.b.total);
state.timelineStart = Math.max(
0,
Math.min(schedules.a.depart, schedules.b.depart, 480) - 5
);
state.maxArrival = Math.max(schedules.a.arrival, schedules.b.arrival);
state.timelineEnd = state.maxArrival + 12;
state.current = THREE.MathUtils.clamp(
state.current,
state.timelineStart,
state.timelineEnd
);
ui.timeline.min = state.timelineStart;
ui.timeline.max = state.timelineEnd;
ui.timeline.value = state.current;
ui.timelineEnd.textContent = `Ends ${formatTime(state.timelineEnd)}`;
const span = Math.max(1, state.timelineEnd - state.timelineStart);
ui.barAFill.style.left =
`${((schedules.a.depart - state.timelineStart) / span) * 100}%`;
ui.barAFill.style.width =
`${((schedules.a.arrival - schedules.a.depart) / span) * 100}%`;
ui.barBFill.style.left =
`${((schedules.b.depart - state.timelineStart) / span) * 100}%`;
ui.barBFill.style.width =
`${((schedules.b.arrival - schedules.b.depart) / span) * 100}%`;
ui.barAText.textContent =
`${formatTime(schedules.a.depart)} → ${formatTime(schedules.a.arrival)}`;
ui.barBText.textContent =
`${formatTime(schedules.b.depart)} → ${formatTime(schedules.b.arrival)}`;
state.revealed = state.current >= state.maxArrival;
updateVerdict(state.revealed);
updateTimelineUI();
}
function updateVerdict(revealed) {
ui.verdict.classList.toggle("revealed", revealed);
ui.barA.classList.remove("winner");
ui.barB.classList.remove("winner");
const aWins = schedules.a.arrival < schedules.b.arrival;
const equal = schedules.a.arrival === schedules.b.arrival;
const winner = aWins ? schedules.a : schedules.b;
const loser = aWins ? schedules.b : schedules.a;
const gap = Math.abs(schedules.a.arrival - schedules.b.arrival);
if (!revealed) {
ui.verdictTitle.textContent = "Waiting for the clock";
ui.verdictCopy.textContent =
"The arrival totals above are already computed. Replay both routes to reveal which itinerary wins end to end.";
return;
}
if (equal) {
ui.verdictTitle.textContent = "Dead heat";
ui.verdictCopy.textContent =
"Both complete itineraries produce the same wall-clock arrival time.";
ui.barA.classList.add("winner");
ui.barB.classList.add("winner");
return;
}
ui.verdictTitle.textContent =
`${winner.shortName} wins by ${gap} minute${gap === 1 ? "" : "s"}`;
(aWins ? ui.barA : ui.barB).classList.add("winner");
if (!aWins) {
const travelDifference = schedules.b.travel - schedules.a.travel;
const transferDifference = schedules.a.transfer - schedules.b.transfer;
const durationDifference = schedules.a.total - schedules.b.total;
const departureLead = schedules.b.depart - schedules.a.depart;
ui.verdictCopy.textContent =
`${schedules.a.name} has the ${schedules.a.travel}m leg, ` +
`${Math.abs(travelDifference)}m quicker than the ${schedules.b.travel}m road leg. ` +
`But its ${schedules.a.transfer}m transfer is ${Math.abs(transferDifference)}m longer ` +
`than the ${schedules.b.transfer}m relay. The ${durationDifference}m journey penalty—` +
`despite starting ${departureLead}m earlier—leaves it ${gap}m late.`;
} else {
ui.verdictCopy.textContent =
`${winner.name} arrives ${gap}m earlier. Its complete ` +
`${winner.total}m itinerary beats the other route’s ${loser.total}m ` +
`schedule. End-to-end time, rather than the first leg alone, determines the winner.`;
}
}
function stageFor(route, now) {
if (now < route.depart) {
return { type: "wait", progress: 0 };
}
if (now < route.depart + route.travel) {
return {
type: "travel",
progress: (now - route.depart) / Math.max(1, route.travel)
};
}
if (now < route.arrival) {
return {
type: "transfer",
progress:
(now - route.depart - route.travel) /
Math.max(1, route.transfer)
};
}
return { type: "arrived", progress: 1 };
}
function updateRouteStatus(card, statusElement, route, now) {
const stage = stageFor(route, now);
card.classList.toggle("is-active", stage.type === "travel" || stage.type === "transfer");
card.classList.toggle("is-done", stage.type === "arrived");
if (stage.type === "wait") {
statusElement.textContent = `Waiting · dep ${formatTime(route.depart)}`;
} else if (stage.type === "travel") {
statusElement.textContent = `Travel leg · ${route.travel}m`;
} else if (stage.type === "transfer") {
statusElement.textContent = `Transfer · ${route.transfer}m`;
} else {
statusElement.textContent = `Delivered · ${formatTime(route.arrival)}`;
}
}
function updateTimelineUI() {
ui.clock.textContent = formatTime(state.current);
ui.timeline.value = state.current;
const progress =
((state.current - state.timelineStart) /
Math.max(1, state.timelineEnd - state.timelineStart)) *
100;
ui.timeline.style.setProperty("--played", `${progress}%`);
ui.play.textContent = state.playing
? "❚❚ Pause"
: state.current >= state.timelineEnd
? "▶ Replay"
: "▶ Play";
updateRouteStatus(ui.routeA, ui.aStatus, schedules.a, state.current);
updateRouteStatus(ui.routeB, ui.bStatus, schedules.b, state.current);
const shouldReveal = state.current >= state.maxArrival;
if (shouldReveal !== state.revealed) {
state.revealed = shouldReveal;
updateVerdict(state.revealed);
}
}
[
ui.aDepart, ui.aTravel, ui.aTransfer,
ui.bDepart, ui.bTravel, ui.bTransfer
].forEach((input) => {
input.addEventListener("change", updateScheduleUI);
});
ui.play.addEventListener("click", () => {
if (state.current >= state.timelineEnd - 0.01) {
state.current = state.timelineStart;
state.revealed = false;
}
state.playing = !state.playing;
updateTimelineUI();
});
ui.reset.addEventListener("click", () => {
state.current = state.timelineStart;
state.playing = false;
state.revealed = false;
updateVerdict(false);
updateTimelineUI();
});
ui.skip.addEventListener("click", () => {
state.current = state.timelineEnd;
state.playing = false;
updateTimelineUI();
});
ui.timeline.addEventListener("input", () => {
state.playing = false;
state.current = Number(ui.timeline.value);
updateTimelineUI();
});
ui.speed.addEventListener("change", () => {
state.speed = Number(ui.speed.value);
});
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const host = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaed3d5);
scene.fog = new THREE.Fog(0xaed3d5, 32, 58);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const cameraControl = {
radius: 28,
theta: 0.64,
phi: 0.83,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const sinPhi = Math.sin(cameraControl.phi);
camera.position.set(
cameraControl.target.x +
cameraControl.radius * sinPhi * Math.sin(cameraControl.theta),
cameraControl.target.y +
cameraControl.radius * Math.cos(cameraControl.phi),
cameraControl.target.z +
cameraControl.radius * sinPhi * Math.cos(cameraControl.theta)
);
camera.lookAt(cameraControl.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xe9ffff, 0x31505a, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.2);
sun.position.set(-10, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x74dbdc, 0.75);
rim.position.set(13, 8, -14);
scene.add(rim);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
...extra
});
const mats = {
base: material(0x173b43),
road: material(0x304c52),
roadEdge: material(0x688083),
cream: material(0xe5e5d2),
white: material(0xf4f8ed),
dark: material(0x172a31),
glass: material(0x68a9ad, { roughness: 0.3, metalness: 0.1 }),
cyan: material(0x39d9d0),
cyanLight: material(0x9df4e9),
amber: material(0xffad55),
amberLight: material(0xffd09b),
green: material(0x91d967),
wood: material(0x8d6447),
leaf: material(0x3b8064),
leafLight: material(0x64a86d),
window: material(0xbce9e2, { emissive: 0x143b3d, emissiveIntensity: 0.45 })
};
function box(parent, width, height, depth, x, y, z, mat, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Island and tiled voxel ground.
box(scene, 26.5, 0.6, 20.5, 0, -0.47, 0, mats.base);
const tileGeometry = new THREE.BoxGeometry(0.94, 0.14, 0.94);
const tileCount = 25 * 19;
const tiles = new THREE.InstancedMesh(
tileGeometry,
material(0xffffff),
tileCount
);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let z = -9; z <= 9; z++) {
for (let x = -12; x <= 12; x++) {
dummy.position.set(x, -0.14, z);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const variation = Math.sin(x * 12.71 + z * 7.13) * 0.5 + 0.5;
tileColor.setHSL(
0.43 + variation * 0.025,
0.17 + variation * 0.07,
0.57 + variation * 0.075
);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
scene.add(tiles);
// Road helpers.
function roadSegment(x1, z1, x2, z2, width = 1.35) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const road = box(
scene,
width,
0.09,
length,
(x1 + x2) / 2,
-0.015,
(z1 + z2) / 2,
mats.road,
false
);
road.rotation.y = Math.atan2(dx, dz);
return road;
}
function dashes(x1, z1, x2, z2, color) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const count = Math.max(2, Math.floor(length / 0.72));
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
box(
scene,
0.17,
0.06,
0.17,
x1 + dx * t,
0.075,
z1 + dz * t,
color,
false
);
}
}
const roadPairs = [
[-8, 0, -8, 4.5],
[-8, 4.5, -1, 4.5],
[-1, 4.5, 3, 4.5],
[3, 4.5, 7, 2],
[7, 2, 8, 0],
[-1, -4.5, 3, -4.5],
[3, -4.5, 7, -2],
[7, -2, 8, 0]
];
roadPairs.forEach((p) => roadSegment(...p));
function dashedRoad(pairs, color) {
for (let i = 0; i < pairs.length - 1; i++) {
const p = pairs[i];
const q = pairs[i + 1];
dashes(p[0], p[1], q[0], q[1], color);
}
}
dashedRoad(
[[-1, -4.5], [3, -4.5], [7, -2], [8, 0]],
mats.cyan
);
dashedRoad(
[[-8, 0], [-8, 4.5], [-1, 4.5]],
mats.amber
);
dashedRoad(
[[-1, 4.5], [3, 4.5], [7, 2], [8, 0]],
mats.amberLight
);
// Buildings.
function makeBuilding(x, z, width, depth, height, bodyColor, roofColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(
group,
width,
height,
depth,
0,
height / 2,
0,
material(bodyColor)
);
box(
group,
width + 0.18,
0.22,
depth + 0.18,
0,
height + 0.11,
0,
material(roofColor)
);
const rows = Math.max(1, Math.floor(height / 0.75));
const cols = Math.max(1, Math.floor(width / 0.65));
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
box(
group,
0.24,
0.3,
0.035,
(col - (cols - 1) / 2) * 0.58,
0.55 + row * 0.68,
depth / 2 + 0.025,
mats.window,
false
);
}
}
return group;
}
makeBuilding(-9.3, -7, 2.6, 1.8, 1.8, 0x496b70, 0x29474e);
makeBuilding(-5.3, -7.1, 2.1, 1.7, 2.6, 0x876f63, 0x46565a);
makeBuilding(-0.5, -7.1, 2.3, 1.7, 1.35, 0x5c7978, 0x304b50);
makeBuilding(4.1, -7.2, 2.6, 1.7, 2.1, 0x536c73, 0x2a4249);
makeBuilding(8.3, -7, 2.4, 1.9, 3.15, 0x817369, 0x41545a);
makeBuilding(-9.6, 7.1, 2.2, 1.6, 1.5, 0x517176, 0x29494f);
makeBuilding(-5.7, 7.1, 2.8, 1.6, 2.2, 0x7a7167, 0x3f5154);
makeBuilding(2.2, 7.2, 2.2, 1.6, 1.25, 0x58777a, 0x29484e);
makeBuilding(6.0, 7.1, 2.6, 1.7, 2.8, 0x667477, 0x34474d);
makeBuilding(10.1, 6.8, 1.7, 1.8, 1.55, 0x857263, 0x3d5154);
// Origin dispatch platform.
box(scene, 2.5, 0.2, 2.4, -8, 0.05, 0, mats.cream);
box(scene, 2.1, 0.9, 1.8, -9.7, 0.48, -1.5, mats.cream);
box(scene, 2.3, 0.18, 2.0, -9.7, 1.02, -1.5, mats.dark);
box(scene, 0.75, 0.7, 0.75, -7.2, 0.42, 0.65, mats.wood);
box(scene, 0.65, 0.65, 0.65, -7.1, 1.08, 0.65, mats.amber);
// Air terminal.
box(scene, 3.3, 1.15, 2.0, -1, 0.58, -6.0, mats.cream);
box(scene, 3.6, 0.25, 2.25, -1, 1.28, -6.0, mats.cyan);
box(scene, 1.0, 0.22, 2.0, -1, 0.08, -4.5, mats.cyanLight);
for (let i = 0; i < 4; i++) {
box(scene, 0.12, 0.7, 0.12, -2.25 + i * 0.83, 0.48, -4.92, mats.dark);
}
// Road relay.
box(scene, 3.2, 0.8, 1.9, -1, 0.43, 6.0, mats.cream);
box(scene, 3.5, 0.22, 2.15, -1, 0.94, 6.0, mats.amber);
box(scene, 1.0, 0.15, 1.8, -1, 0.04, 4.5, mats.amberLight);
// Customer tower.
box(scene, 2.2, 2.8, 2.1, 9.3, 1.42, 1.6, mats.cream);
box(scene, 2.5, 0.25, 2.4, 9.3, 2.94, 1.6, mats.dark);
box(scene, 0.55, 3.6, 0.55, 8.0, 1.8, 0, mats.green);
const targetTop = box(scene, 1.45, 0.22, 0.22, 8.0, 3.5, 0, mats.green);
const targetSide = box(scene, 0.22, 0.22, 1.45, 8.0, 3.5, 0, mats.green);
const beacon = box(
scene,
0.22,
1.8,
0.22,
8.0,
4.3,
0,
material(0xb8f48a, {
emissive: 0x72c751,
emissiveIntensity: 0.6
})
);
// Trees.
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, 0.22, 0.9, 0.22, 0, 0.45, 0, mats.wood);
box(group, 1.0, 0.75, 1.0, 0, 1.15, 0, mats.leaf);
box(group, 0.72, 0.65, 0.72, 0, 1.78, 0, mats.leafLight);
}
[
[-11, -3.7, 0.9],
[-10.8, 2.8, 0.8],
[-5.2, -5.1, 0.7],
[1.4, -5.6, 0.75],
[6.0, -5.5, 0.8],
[10.7, -3.8, 0.85],
[10.9, 4.8, 0.8],
[-4.2, 6.2, 0.7],
[4.8, 6.1, 0.7]
].forEach((p) => makeTree(...p));
// Voxel clouds.
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, 1.8, 0.45, 0.75, 0, 0, 0, mats.white, false);
box(group, 1.05, 0.7, 0.75, -0.55, 0.22, 0, mats.white, false);
box(group, 1.35, 0.85, 0.75, 0.4, 0.28, 0, mats.white, false);
}
makeCloud(-10, 8.5, -9, 1.1);
makeCloud(3, 9.2, -10, 0.85);
makeCloud(11, 7.8, -8, 1.0);
// ---------------------------------------------------------------------
// Vehicles
// ---------------------------------------------------------------------
function makeVan(color, cargoColor) {
const group = new THREE.Group();
const bodyMat = material(color);
const cargoMat = material(cargoColor);
box(group, 0.9, 0.68, 1.35, 0, 0.52, -0.18, bodyMat);
box(group, 0.86, 0.68, 0.62, 0, 0.51, 0.67, bodyMat);
box(group, 0.69, 0.32, 0.045, 0, 0.68, 1.0, mats.glass);
box(group, 0.52, 0.42, 0.55, 0, 0.82, 0.62, cargoMat);
const wheelMat = mats.dark;
box(group, 0.13, 0.34, 0.34, -0.49, 0.22, 0.48, wheelMat);
box(group, 0.13, 0.34, 0.34, 0.49, 0.22, 0.48, wheelMat);
box(group, 0.13, 0.34, 0.34, -0.49, 0.22, -0.52, wheelMat);
box(group, 0.13, 0.34, 0.34, 0.49, 0.22, -0.52, wheelMat);
box(group, 0.58, 0.18, 0.04, 0, 0.36, 1.02, mats.white, false);
return group;
}
function makeDrone() {
const group = new THREE.Group();
const body = material(0x42ded4);
const cargo = material(0xe2f7ec);
box(group, 0.78, 0.35, 0.92, 0, 0, 0, body);
box(group, 0.48, 0.42, 0.56, 0, -0.32, 0, cargo);
box(group, 1.72, 0.08, 0.13, 0, 0.05, 0, body);
box(group, 0.13, 0.08, 1.35, 0, 0.05, 0, body);
const rotors = [];
const rotorMat = material(0x24464c, { roughness: 0.5 });
for (const x of [-0.69, 0.69]) {
for (const z of [-0.48, 0.48]) {
box(group, 0.12, 0.14, 0.12, x, 0.02, z, body);
const rotor = box(group, 0.55, 0.045, 0.11, x, 0.13, z, rotorMat);
rotors.push(rotor);
}
}
group.userData.rotors = rotors;
return group;
}
const droneA = makeDrone();
const transferA = makeVan(0x3ddbd1, 0xd9fff2);
const roadB = makeVan(0xffad58, 0xffd8a7);
const relayB = makeVan(0xe99a45, 0xffe0b2);
scene.add(droneA, transferA, roadB, relayB);
// ---------------------------------------------------------------------
// Paths and replay animation
// ---------------------------------------------------------------------
const point = (x, z) => new THREE.Vector3(x, 0, z);
const origin = point(-8, 0);
const airTerminal = point(-1, -4.5);
const roadRelay = point(-1, 4.5);
const customer = point(8, 0);
const airPath = [origin, airTerminal];
const transferPathA = [
airTerminal,
point(3, -4.5),
point(7, -2),
customer
];
const travelPathB = [
origin,
point(-8, 4.5),
roadRelay
];
const transferPathB = [
roadRelay,
point(3, 4.5),
point(7, 2),
customer
];
function samplePath(path, progress) {
const lengths = [];
let total = 0;
for (let i = 0; i < path.length - 1; i++) {
const length = path[i].distanceTo(path[i + 1]);
lengths.push(length);
total += length;
}
let remaining = THREE.MathUtils.clamp(progress, 0, 1) * total;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i] || i === lengths.length - 1) {
const t = lengths[i] === 0 ? 0 : remaining / lengths[i];
const position = path[i].clone().lerp(path[i + 1], t);
const tangent = path[i + 1].clone().sub(path[i]).normalize();
return { position, tangent };
}
remaining -= lengths[i];
}
return {
position: path[path.length - 1].clone(),
tangent: new THREE.Vector3(0, 0, 1)
};
}
function placeOnPath(object, path, progress) {
const sample = samplePath(path, progress);
object.position.copy(sample.position);
object.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
}
function updateVehicles(now) {
const aStage = stageFor(schedules.a, now);
const bStage = stageFor(schedules.b, now);
if (aStage.type === "travel") {
droneA.visible = true;
transferA.visible = false;
const p = aStage.progress;
droneA.position.copy(origin).lerp(airTerminal, p);
droneA.position.y = 2.45 + Math.sin(Math.PI * p) * 2.45;
droneA.rotation.y = -0.18;
} else if (aStage.type === "transfer") {
droneA.visible = false;
transferA.visible = true;
placeOnPath(transferA, transferPathA, aStage.progress);
} else if (aStage.type === "arrived") {
droneA.visible = false;
transferA.visible = true;
transferA.position.copy(customer);
transferA.rotation.y = Math.PI * 0.18;
} else {
droneA.visible = false;
transferA.visible = false;
}
if (bStage.type === "travel") {
roadB.visible = true;
relayB.visible = false;
placeOnPath(roadB, travelPathB, bStage.progress);
} else if (bStage.type === "transfer") {
roadB.visible = false;
relayB.visible = true;
placeOnPath(relayB, transferPathB, bStage.progress);
} else if (bStage.type === "arrived") {
roadB.visible = false;
relayB.visible = true;
relayB.position.copy(customer);
relayB.rotation.y = Math.PI * 0.18;
} else {
roadB.visible = false;
relayB.visible = false;
}
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit and zoom, no addons
// ---------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraControl.theta -= dx * 0.006;
cameraControl.phi = THREE.MathUtils.clamp(
cameraControl.phi + dy * 0.005,
0.42,
1.28
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraControl.radius = THREE.MathUtils.clamp(
cameraControl.radius + event.deltaY * 0.018,
15,
43
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.tabIndex = 0;
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraControl.theta -= 0.12;
if (event.key === "ArrowRight") cameraControl.theta += 0.12;
if (event.key === "ArrowUp") cameraControl.phi = Math.max(0.42, cameraControl.phi - 0.08);
if (event.key === "ArrowDown") cameraControl.phi = Math.min(1.28, cameraControl.phi + 0.08);
if (event.key === "+" || event.key === "=") cameraControl.radius = Math.max(15, cameraControl.radius - 2);
if (event.key === "-") cameraControl.radius = Math.min(43, cameraControl.radius + 2);
updateCamera();
});
// Project HTML labels into the 3D scene.
const labels = [
{ element: document.querySelector("#label-origin"), position: new THREE.Vector3(-8, 1.7, 0) },
{ element: document.querySelector("#label-air"), position: new THREE.Vector3(-1, 2.0, -4.5) },
{ element: document.querySelector("#label-relay"), position: new THREE.Vector3(-1, 1.7, 4.5) },
{ element: document.querySelector("#label-customer"), position: new THREE.Vector3(8, 3.0, 0) }
];
function updateLabels() {
labels.forEach((label) => {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "flex" : "none";
if (!visible) return;
label.element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
});
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Main loop
// ---------------------------------------------------------------------
updateScheduleUI();
updateCamera();
const clock = new THREE.Clock();
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.playing) {
state.current += delta * state.speed;
if (state.current >= state.timelineEnd) {
state.current = state.timelineEnd;
state.playing = false;
}
}
updateVehicles(state.current);
droneA.userData.rotors.forEach((rotor) => {
rotor.rotation.y += delta * 24;
});
const delivered = state.current >= schedules.b.arrival;
const pulse = delivered
? 1 + Math.sin(performance.now() * 0.006) * 0.08
: 1;
beacon.scale.y = pulse;
beacon.material.emissiveIntensity = delivered ? 1.15 : 0.55;
targetTop.material.emissiveIntensity = delivered ? 0.35 : 0;
targetSide.material.emissiveIntensity = delivered ? 0.35 : 0;
uiAccumulator += delta;
if (uiAccumulator > 0.08) {
uiAccumulator = 0;
updateTimelineUI();
}
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
ui.loading.classList.add("hidden");
setTimeout(() => ui.loading.remove(), 350);
});
</script>
</body>
</html>
```