Prompt specification
Build or customize the Three.js 3D scene "Cooperative Cargo Loading Puzzle" 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: Cooperative Cargo Loading Puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cooperative-cargo-loading-puzzle-x3168
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts negotiated terms for shared resources and exchanges. Build two carriers with different spare capacities and delivery deadlines. Players negotiate a transfer plan, then verify each route and deadline under the explicitly displayed rules. Voxel style.
Working Three.js Starter (cooperative-cargo-loading-puzzle-x3168):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Cargo — Voxel Negotiation</title>
<style>
:root {
--ink: #172825;
--muted: #65746f;
--paper: #f3efe2;
--paper-2: #e9e4d4;
--line: #cfc8b6;
--amber: #f3b83f;
--teal: #31b8aa;
--red: #df5c56;
--green: #4c9a68;
--panel-width: 390px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.topbar {
height: 66px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 22px;
color: #f7f1df;
background: #172825;
border-bottom: 4px solid var(--amber);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
position: relative;
flex: 0 0 auto;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
width: 20px;
height: 20px;
}
.brand-mark::before {
left: 0;
top: 6px;
background: var(--amber);
box-shadow: 10px -10px 0 var(--teal);
}
.brand-mark::after {
right: 0;
bottom: 0;
background: #f7f1df;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1.1;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.brand p {
margin: 4px 0 0;
color: #afbbb4;
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.top-meta {
display: flex;
gap: 9px;
align-items: center;
}
.top-chip {
padding: 7px 10px;
border: 1px solid #43534d;
border-radius: 3px;
color: #d9dfd8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.shell {
display: grid;
grid-template-columns: var(--panel-width) minmax(0, 1fr);
height: calc(100dvh - 66px);
}
.panel {
overflow-y: auto;
padding: 20px;
background:
linear-gradient(90deg, rgb(255 255 255 / 0.2), transparent 70%),
var(--paper);
border-right: 2px solid #bbb5a5;
scrollbar-width: thin;
scrollbar-color: #aaa48f transparent;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.mission {
padding: 15px;
background: #fffaf0;
border: 2px solid var(--ink);
box-shadow: 4px 4px 0 rgb(23 40 37 / 0.12);
margin-bottom: 19px;
}
.mission h2 {
margin: 0;
font-size: 20px;
line-height: 1.15;
}
.mission p {
margin: 9px 0 13px;
color: #53605c;
font-size: 13px;
line-height: 1.5;
}
.mission-facts {
display: grid;
grid-template-columns: repeat(3, 1fr);
border-top: 1px solid var(--line);
padding-top: 11px;
gap: 7px;
}
.mission-fact strong {
display: block;
font-size: 15px;
}
.mission-fact span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-heading {
display: flex;
align-items: end;
justify-content: space-between;
margin: 18px 2px 10px;
}
.section-heading h2,
.section-heading h3 {
margin: 0;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-heading small {
color: var(--muted);
font-size: 10px;
}
.carrier-card {
--carrier: var(--amber);
background: #faf6ea;
border: 1px solid var(--line);
border-left: 5px solid var(--carrier);
padding: 14px;
margin-bottom: 12px;
transition: border-color 160ms, background 160ms;
}
.carrier-card.over-capacity {
background: #fff0eb;
border-color: var(--red);
}
.carrier-header {
display: flex;
justify-content: space-between;
gap: 12px;
align-items: flex-start;
}
.carrier-name {
display: flex;
align-items: center;
gap: 9px;
}
.carrier-code {
width: 30px;
height: 30px;
display: grid;
place-items: center;
color: #172825;
background: var(--carrier);
font-size: 12px;
font-weight: 950;
box-shadow: 2px 2px 0 rgb(23 40 37 / 0.18);
}
.carrier-name strong {
display: block;
font-size: 14px;
}
.carrier-name small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.deadline {
text-align: right;
}
.deadline span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.deadline strong {
font-size: 13px;
}
.load-row {
display: grid;
grid-template-columns: 1fr 62px;
gap: 12px;
align-items: center;
margin-top: 13px;
}
.load-row label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
accent-color: var(--carrier);
cursor: pointer;
}
input[type="number"] {
width: 100%;
height: 35px;
padding: 4px 5px;
color: var(--ink);
background: #fff;
border: 1px solid #aaa48f;
border-radius: 0;
text-align: center;
font-weight: 900;
}
input:focus-visible,
button:focus-visible,
.route-choice:has(input:focus-visible) {
outline: 3px solid rgb(49 184 170 / 0.4);
outline-offset: 2px;
}
.capacity-line {
height: 6px;
margin-top: 8px;
background: #ddd7c8;
overflow: hidden;
}
.capacity-line span {
display: block;
height: 100%;
width: 0;
background: var(--carrier);
transition: width 160ms;
}
.over-capacity .capacity-line span {
background: var(--red);
}
.capacity-copy {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.route-label {
display: block;
margin: 13px 0 6px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.route-choice {
--carrier: var(--amber);
display: grid;
grid-template-columns: 15px 1fr auto;
align-items: center;
gap: 8px;
margin-top: 6px;
padding: 9px;
border: 1px solid #d5cebd;
background: #fffdf7;
cursor: pointer;
transition: 120ms;
}
.route-choice:hover {
border-color: var(--carrier);
}
.route-choice.selected {
border-color: var(--carrier);
background: color-mix(in srgb, var(--carrier) 12%, white);
box-shadow: inset 3px 0 0 var(--carrier);
}
.route-choice input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.route-radio {
width: 11px;
height: 11px;
border: 2px solid #8d948d;
border-radius: 50%;
position: relative;
}
.selected .route-radio {
border-color: var(--carrier);
}
.selected .route-radio::after {
content: "";
position: absolute;
inset: 2px;
background: var(--carrier);
border-radius: 50%;
}
.route-copy strong,
.route-copy small {
display: block;
}
.route-copy strong {
font-size: 11px;
}
.route-copy small {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.route-time {
font-size: 9px;
font-weight: 900;
letter-spacing: 0.04em;
text-align: right;
}
.route-time::before {
display: block;
content: "OPEN";
margin-bottom: 2px;
color: var(--green);
font-size: 8px;
}
.route-time.closed {
color: var(--red);
}
.route-time.closed::before {
content: "CLOSED";
color: var(--red);
}
.proposal-summary {
display: flex;
align-items: center;
justify-content: space-between;
padding: 11px 12px;
margin: 4px 0 10px;
border: 1px solid var(--line);
background: #e8e2d3;
font-size: 11px;
}
.proposal-summary strong {
font-size: 13px;
}
.proposal-summary.bad {
border-color: var(--red);
color: #9c342f;
background: #ffebe7;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.action {
min-height: 42px;
padding: 10px;
border: 2px solid var(--ink);
border-radius: 0;
background: #fffdf7;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: transform 120ms, box-shadow 120ms, opacity 120ms;
}
.action:hover:not(:disabled) {
transform: translate(-1px, -1px);
box-shadow: 3px 3px 0 var(--ink);
}
.action.primary {
color: #172825;
background: var(--amber);
}
.action.verify {
color: #fff;
background: var(--ink);
}
.action:disabled {
cursor: not-allowed;
opacity: 0.38;
}
.action.full {
grid-column: 1 / -1;
}
.rules {
margin-top: 20px;
padding: 14px;
border: 1px solid var(--line);
background: #eae5d7;
}
.rules h3 {
margin: 0 0 10px;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.rule {
display: grid;
grid-template-columns: 27px 1fr;
gap: 8px;
padding: 7px 0;
border-top: 1px solid #d0c9b8;
color: #485550;
font-size: 10px;
line-height: 1.4;
}
.rule:first-of-type {
border-top: 0;
}
.rule b {
color: var(--ink);
font-size: 9px;
}
.results {
margin-top: 16px;
padding: 14px;
border: 2px solid var(--ink);
background: #fffdf7;
}
.results[hidden] {
display: none;
}
.result-head {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
}
.result-head strong {
display: block;
font-size: 14px;
}
.result-head small {
display: block;
color: var(--muted);
font-size: 9px;
margin-top: 2px;
}
.result-icon {
width: 30px;
height: 30px;
display: grid;
place-items: center;
color: white;
background: var(--red);
font-weight: 950;
}
.results.pass .result-icon {
background: var(--green);
}
.result-row {
display: grid;
grid-template-columns: 25px 1fr auto;
gap: 7px;
align-items: start;
padding: 8px 0;
border-top: 1px solid var(--line);
font-size: 10px;
}
.result-code {
color: var(--muted);
font-size: 9px;
font-weight: 900;
}
.result-row strong,
.result-row small {
display: block;
}
.result-row small {
margin-top: 2px;
color: var(--muted);
line-height: 1.35;
}
.check {
width: 18px;
height: 18px;
display: grid;
place-items: center;
color: white;
background: var(--red);
font-size: 10px;
font-weight: 900;
}
.check.pass {
background: var(--green);
}
.stage {
position: relative;
min-width: 0;
overflow: hidden;
background: #c8dfd9;
isolation: isolate;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
z-index: 4;
top: 18px;
left: 20px;
right: 20px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
pointer-events: none;
}
.scene-title {
color: var(--ink);
text-shadow: 0 1px 0 rgb(255 255 255 / 0.55);
}
.scene-title p {
margin: 0 0 3px;
color: #435c55;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scene-title h2 {
margin: 0;
font-size: clamp(18px, 2.2vw, 28px);
letter-spacing: -0.03em;
}
.scene-title small {
display: block;
margin-top: 4px;
color: #526861;
font-size: 10px;
font-weight: 700;
}
.stage-status {
min-width: 125px;
padding: 9px 12px;
border: 2px solid var(--ink);
color: var(--ink);
background: var(--amber);
box-shadow: 4px 4px 0 rgb(23 40 37 / 0.18);
font-size: 9px;
font-weight: 950;
letter-spacing: 0.11em;
text-align: center;
text-transform: uppercase;
}
.stage-status.pass {
color: white;
background: var(--green);
}
.stage-status.fail {
color: white;
background: var(--red);
}
.stage-legend {
position: absolute;
z-index: 4;
left: 20px;
bottom: 18px;
display: flex;
gap: 14px;
align-items: center;
padding: 9px 11px;
border: 1px solid rgb(23 40 37 / 0.3);
background: rgb(255 253 247 / 0.84);
backdrop-filter: blur(6px);
font-size: 9px;
font-weight: 850;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-swatch {
width: 15px;
height: 7px;
background: var(--amber);
}
.legend-swatch.teal {
background: var(--teal);
}
.legend-swatch.gray {
background: #83948f;
}
.stage-help {
position: absolute;
z-index: 4;
right: 20px;
bottom: 18px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: none;
}
.stage-help span {
padding: 8px 10px;
color: #435650;
background: rgb(255 253 247 / 0.78);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
}
#resetView {
padding: 8px 10px;
border: 1px solid rgb(23 40 37 / 0.35);
background: rgb(255 253 247 / 0.9);
font-size: 9px;
font-weight: 900;
cursor: pointer;
pointer-events: auto;
}
#labels {
position: absolute;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 5px 8px;
border: 1px solid rgb(23 40 37 / 0.4);
color: var(--ink);
background: rgb(255 253 247 / 0.9);
box-shadow: 2px 2px 0 rgb(23 40 37 / 0.13);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
will-change: transform;
}
.world-label.carrier {
color: white;
border-color: transparent;
}
.world-label.carrier.a {
background: #c98a12;
}
.world-label.carrier.b {
background: #218d83;
}
.world-label.depot {
color: white;
background: var(--ink);
border-color: var(--ink);
}
.loading {
position: absolute;
z-index: 8;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #c8dfd9;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 1020px) {
:root {
--panel-width: 350px;
}
.panel {
padding: 16px;
}
.stage-help span {
display: none;
}
}
@media (max-width: 760px) {
body {
overflow: auto;
}
.topbar {
height: 60px;
padding: 0 14px;
}
.brand p,
.top-chip:last-child {
display: none;
}
.shell {
display: flex;
flex-direction: column;
height: auto;
}
.stage {
order: 1;
height: 56dvh;
min-height: 420px;
}
.panel {
order: 2;
overflow: visible;
border-right: 0;
}
.stage-top {
top: 13px;
left: 13px;
right: 13px;
}
.scene-title h2 {
font-size: 18px;
}
.stage-legend {
left: 12px;
bottom: 12px;
}
.stage-help {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Common Cargo</h1>
<p>Shared-resource exchange desk</p>
</div>
</div>
<div class="top-meta">
<div class="top-chip">Departure 12:30</div>
<div class="top-chip">Voxel logistics / 02</div>
</div>
</header>
<main class="shell">
<aside class="panel">
<section class="mission">
<p class="eyebrow">Negotiation brief / 24 relief units</p>
<h2>Supply the Common Depot</h2>
<p>
Two carriers have offered spare capacity. Set each contribution and
select a road before proposing the exchange. Mixed food and water
crates are accepted.
</p>
<div class="mission-facts">
<div class="mission-fact">
<strong>24</strong>
<span>Crates needed</span>
</div>
<div class="mission-fact">
<strong>12:30</strong>
<span>Joint departure</span>
</div>
<div class="mission-fact">
<strong>1</strong>
<span>Shared depot</span>
</div>
</div>
</section>
<div class="section-heading">
<h2>Carrier terms</h2>
<small>Adjust loads and routes</small>
</div>
<div id="carrierCards"></div>
<div id="proposalSummary" class="proposal-summary">
<span>Proposed delivery</span>
<strong id="summaryTotal">24 / 24</strong>
</div>
<div class="actions">
<button id="proposeBtn" class="action primary">Propose transfer</button>
<button id="verifyBtn" class="action verify" disabled>Verify plan</button>
<button id="reviseBtn" class="action full" hidden>Revise negotiated terms</button>
</div>
<section class="rules" aria-labelledby="rulesTitle">
<h3 id="rulesTitle">Explicit verification rules</h3>
<div class="rule"><b>R1</b><span>Combined contributions must equal exactly 24 crates.</span></div>
<div class="rule"><b>R2</b><span>Aster may carry no more than its 18 spare crate slots.</span></div>
<div class="rule"><b>R3</b><span>Kestrel may carry no more than its 32 spare crate slots.</span></div>
<div class="rule"><b>R4</b><span>Both carriers must contribute at least one crate.</span></div>
<div class="rule"><b>R5</b><span>Aster’s selected route must be marked OPEN.</span></div>
<div class="rule"><b>R6</b><span>Kestrel’s selected route must be marked OPEN.</span></div>
<div class="rule"><b>R7</b><span>Aster must arrive no later than 14:00.</span></div>
<div class="rule"><b>R8</b><span>Kestrel must arrive no later than 14:30.</span></div>
</section>
<section id="results" class="results" aria-live="polite" hidden></section>
</aside>
<section class="stage" aria-label="Interactive voxel logistics scene">
<div id="viewport"></div>
<div id="loading" class="loading">Building the common yard…</div>
<div id="labels"></div>
<div class="stage-top">
<div class="scene-title">
<p>Exchange district / Sector 04</p>
<h2>The Common Yard</h2>
<small>Two origins. One shared destination.</small>
</div>
<div id="stageStatus" class="stage-status">Draft terms</div>
</div>
<div class="stage-legend">
<div class="legend-item"><span class="legend-swatch"></span>Aster route</div>
<div class="legend-item"><span class="legend-swatch teal"></span>Kestrel route</div>
<div class="legend-item"><span class="legend-swatch gray"></span>Unselected</div>
</div>
<div class="stage-help">
<span>Drag to orbit · wheel to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
</section>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DEPARTURE = 12 * 60 + 30;
const carriers = {
A: {
key: "A",
name: "Aster",
cargo: "Mixed relief crates",
color: "#f3b83f",
capacity: 18,
deadlineMinutes: 14 * 60,
deadline: "14:00",
routes: [
{
id: "relay",
name: "Relay Cut",
note: "Level road via West Relay",
duration: 65,
open: true,
path: [
[-6, -1.45],
[-3, -1.45],
[-0.35, -1.45]
]
},
{
id: "ridge",
name: "Ridge Climb",
note: "Long climb over North Ridge",
duration: 115,
open: true,
path: [
[-6, -1.45],
[-4.6, 2.35],
[-1.4, 2.35],
[-0.35, -1.45]
]
}
]
},
B: {
key: "B",
name: "Kestrel",
cargo: "Mixed relief crates",
color: "#31b8aa",
capacity: 32,
deadlineMinutes: 14 * 60 + 30,
deadline: "14:30",
routes: [
{
id: "pump",
name: "Pump Lane",
note: "Direct road via East Pump",
duration: 75,
open: true,
path: [
[6, -1.45],
[3, -1.45],
[0.35, -1.45]
]
},
{
id: "switchback",
name: "Old Switchback",
note: "Washout reported at north bend",
duration: 125,
open: false,
path: [
[6, -1.45],
[5, 2.35],
[2.4, 2.35],
[0.35, -1.45]
]
}
]
}
};
const state = {
loads: { A: 12, B: 12 },
routes: { A: "relay", B: "pump" },
proposed: false,
verified: false,
verification: null,
dispatchStart: 0
};
const $ = (id) => document.getElementById(id);
const clamp = THREE.MathUtils.clamp;
function routeFor(key) {
return carriers[key].routes.find((route) => route.id === state.routes[key]);
}
function formatTime(minutes) {
const h = Math.floor(minutes / 60);
const m = minutes % 60;
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
}
function arrivalTime(route) {
return DEPARTURE + route.duration;
}
function buildCarrierCards() {
$("carrierCards").innerHTML = Object.values(carriers)
.map((carrier) => {
const selected = state.routes[carrier.key];
const routes = carrier.routes.map((route) => `
<label class="route-choice ${route.id === selected ? "selected" : ""}"
style="--carrier:${carrier.color}">
<input type="radio" name="route-${carrier.key}" value="${route.id}"
${route.id === selected ? "checked" : ""}>
<span class="route-radio"></span>
<span class="route-copy">
<strong>${route.name}</strong>
<small>${route.note}</small>
</span>
<span class="route-time ${route.open ? "" : "closed"}">
${route.duration} min
</span>
</label>
`).join("");
return `
<article id="card-${carrier.key}" class="carrier-card"
style="--carrier:${carrier.color}">
<div class="carrier-header">
<div class="carrier-name">
<div class="carrier-code">${carrier.key}</div>
<div>
<strong>${carrier.name}</strong>
<small>${carrier.cargo}</small>
</div>
</div>
<div class="deadline">
<span>Deadline</span>
<strong>${carrier.deadline}</strong>
</div>
</div>
<div class="load-row">
<div>
<label for="range-${carrier.key}">Contribution</label>
<input id="range-${carrier.key}" type="range" min="0" max="36"
value="${state.loads[carrier.key]}">
</div>
<input id="number-${carrier.key}" type="number" min="0" max="36"
value="${state.loads[carrier.key]}" aria-label="${carrier.name} contribution">
</div>
<div class="capacity-line"><span id="capacity-${carrier.key}"></span></div>
<div class="capacity-copy">
<span id="capacityText-${carrier.key}"></span>
<span>Spare capacity: ${carrier.capacity}</span>
</div>
<span class="route-label">Select route</span>
${routes}
</article>
`;
})
.join("");
}
function updateUI() {
for (const carrier of Object.values(carriers)) {
const key = carrier.key;
const load = state.loads[key];
const card = $(`card-${key}`);
$(`range-${key}`).value = load;
$(`number-${key}`).value = load;
$(`capacity-${key}`).style.width =
`${Math.min(100, (load / carrier.capacity) * 100)}%`;
$(`capacityText-${key}`).textContent = `${load} crates assigned`;
card.classList.toggle("over-capacity", load > carrier.capacity);
document.querySelectorAll(`input[name="route-${key}"]`).forEach((input) => {
input.checked = input.value === state.routes[key];
input.closest(".route-choice").classList.toggle(
"selected",
input.checked
);
});
}
const total = state.loads.A + state.loads.B;
$("summaryTotal").textContent = `${total} / 24`;
$("proposalSummary").classList.toggle("bad", total !== 24);
$("proposeBtn").disabled = state.proposed;
$("proposeBtn").textContent = state.proposed
? "Terms proposed"
: "Propose transfer";
$("verifyBtn").disabled = !state.proposed;
$("reviseBtn").hidden = !state.proposed;
const status = $("stageStatus");
status.className = "stage-status";
if (state.verified) {
const passed = state.verification.every((check) => check.pass);
status.textContent = passed ? "Exchange verified" : "Revision needed";
status.classList.add(passed ? "pass" : "fail");
} else if (state.proposed) {
status.textContent = "Terms live";
} else {
status.textContent = "Draft terms";
}
updateRouteVisuals();
updateTruckCargo();
updateBeacon();
}
function lockInputs(locked) {
document.querySelectorAll("#carrierCards input").forEach((input) => {
input.disabled = locked;
});
}
function clearResults() {
state.verified = false;
state.verification = null;
$("results").hidden = true;
$("results").innerHTML = "";
}
function bindUI() {
for (const carrier of Object.values(carriers)) {
const key = carrier.key;
const range = $(`range-${key}`);
const number = $(`number-${key}`);
range.addEventListener("input", () => {
if (state.proposed) return;
state.loads[key] = clamp(Number(range.value), 0, 36);
clearResults();
updateUI();
});
number.addEventListener("input", () => {
if (state.proposed) return;
const value = Number(number.value);
state.loads[key] = clamp(Number.isFinite(value) ? value : 0, 0, 36);
clearResults();
updateUI();
});
document.querySelectorAll(`input[name="route-${key}"]`).forEach((input) => {
input.addEventListener("change", () => {
if (state.proposed) return;
state.routes[key] = input.value;
clearResults();
updateUI();
});
});
}
$("proposeBtn").addEventListener("click", () => {
if (state.proposed) return;
clearResults();
state.proposed = true;
state.dispatchStart = performance.now();
lockInputs(true);
updateUI();
});
$("verifyBtn").addEventListener("click", () => {
if (!state.proposed) return;
const a = carriers.A;
const b = carriers.B;
const routeA = routeFor("A");
const routeB = routeFor("B");
const total = state.loads.A + state.loads.B;
const checks = [
{
code: "R1",
title: "Demand covered exactly",
detail: `${total} contributed; 24 required.`,
pass: total === 24
},
{
code: "R2",
title: "Aster capacity respected",
detail: `${state.loads.A} assigned; ${a.capacity} spare slots available.`,
pass: state.loads.A <= a.capacity
},
{
code: "R3",
title: "Kestrel capacity respected",
detail: `${state.loads.B} assigned; ${b.capacity} spare slots available.`,
pass: state.loads.B <= b.capacity
},
{
code: "R4",
title: "Both carriers contribute",
detail: `Aster ${state.loads.A}, Kestrel ${state.loads.B}; each must carry at least 1.`,
pass: state.loads.A > 0 && state.loads.B > 0
},
{
code: "R5",
title: "Aster route is open",
detail: `${routeA.name} — ${routeA.open ? "OPEN" : "CLOSED"}.`,
pass: routeA.open
},
{
code: "R6",
title: "Kestrel route is open",
detail: `${routeB.name} — ${routeB.open ? "OPEN" : "CLOSED"}.`,
pass: routeB.open
},
{
code: "R7",
title: "Aster meets its deadline",
detail: `ETA ${formatTime(arrivalTime(routeA))}; deadline ${a.deadline}.`,
pass: arrivalTime(routeA) <= a.deadlineMinutes
},
{
code: "R8",
title: "Kestrel meets its deadline",
detail: `ETA ${formatTime(arrivalTime(routeB))}; deadline ${b.deadline}.`,
pass: arrivalTime(routeB) <= b.deadlineMinutes
}
];
state.verification = checks;
state.verified = checks.every((check) => check.pass);
renderResults(checks);
updateUI();
});
$("reviseBtn").addEventListener("click", () => {
state.proposed = false;
state.dispatchStart = 0;
clearResults();
lockInputs(false);
resetTrucks();
updateUI();
});
$("resetView").addEventListener("click", resetCamera);
}
function renderResults(checks) {
const passed = checks.every((check) => check.pass);
const result = $("results");
result.hidden = false;
result.classList.toggle("pass", passed);
result.innerHTML = `
<div class="result-head">
<div class="result-icon">${passed ? "✓" : "!"}</div>
<div>
<strong>${passed ? "Transfer verified" : "Terms require revision"}</strong>
<small>${
passed
? "All capacities, routes, and deadlines pass."
: "Review the failed rule and propose again."
}</small>
</div>
</div>
${checks.map((check) => `
<div class="result-row">
<span class="result-code">${check.code}</span>
<div>
<strong>${check.title}</strong>
<small>${check.detail}</small>
</div>
<span class="check ${check.pass ? "pass" : ""}">
${check.pass ? "✓" : "×"}
</span>
</div>
`).join("")}
`;
}
// ---------- Three.js scene ----------
const viewport = $("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#c8dfd9");
scene.fog = new THREE.Fog("#c8dfd9", 25, 48);
const renderer = new THREE.WebGLRenderer({
antialias: false,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const cameraState = {
theta: 0.68,
phi: 0.78,
zoom: 1,
target: new THREE.Vector3(0, 0, -0.25)
};
const hemisphere = new THREE.HemisphereLight("#fff5d6", "#5b776f", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff1c9", 3.1);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b8e2df", 1.1);
fill.position.set(10, 7, -9);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...options
});
const palette = {
dirt: material("#9b7652"),
dirtDark: material("#75543d"),
grass: material("#83ad72"),
grassLight: material("#a4c785"),
path: material("#c7b899"),
stone: material("#8c9186"),
stoneDark: material("#606b65"),
roof: material("#3f5f59"),
wall: material("#e4d8ba"),
window: material("#83c9c3", {
emissive: "#315e5a",
emissiveIntensity: 0.3
}),
wood: material("#79523c"),
leaf: material("#4e8d5d"),
leafLight: material("#71a866"),
fruit: material("#e99b45"),
water: material("#58b9bd", {
roughness: 0.38,
metalness: 0.08
}),
cream: material("#f0dfb4"),
dark: material("#243632"),
red: material("#d95c52"),
white: material("#fff8e8")
};
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addVoxelTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
group.scale.setScalar(scale);
addBox(group, [0.28, 1.1, 0.28], [0, 0.55, 0], palette.wood);
addBox(group, [1.2, 0.8, 1.2], [0, 1.45, 0], palette.leaf);
addBox(group, [0.8, 0.7, 0.8], [0.25, 2.0, 0], palette.leafLight);
addBox(group, [0.55, 0.55, 0.55], [-0.25, 2.15, 0.18], palette.leaf);
scene.add(group);
}
function addBuilding(x, z, width, depth, height, wallMat, roofMat) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
addBox(group, [width, height, depth], [0, height / 2, 0], wallMat);
addBox(group, [width + 0.2, 0.22, depth + 0.2], [0, height + 0.08, 0], roofMat);
addBox(group, [width * 0.7, 0.2, depth * 0.7], [0, height + 0.28, 0], roofMat);
const front = depth / 2 + 0.025;
addBox(group, [0.48, height * 0.65, 0.06], [0, height * 0.33, front], palette.dark);
addBox(
group,
[0.34, 0.34, 0.07],
[-width * 0.28, height * 0.63, front],
palette.window,
false
);
addBox(
group,
[0.34, 0.34, 0.07],
[width * 0.28, height * 0.63, front],
palette.window,
false
);
scene.add(group);
return group;
}
function addHill(x, z, color = palette.stoneDark) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
addBox(group, [3.2, 0.65, 2.3], [0, 0.32, 0], color);
addBox(group, [2.2, 0.8, 1.7], [-0.15, 0.9, 0], color);
addBox(group, [1.25, 0.8, 1.2], [-0.2, 1.55, 0], palette.stone);
scene.add(group);
}
// Island and shared yard.
addBox(scene, [18, 1.05, 10], [0, -0.67, 0], palette.dirt);
addBox(scene, [18.2, 0.24, 10.2], [0, -0.02, 0], palette.grass);
addBox(scene, [18.3, 0.28, 10.3], [0, -1.15, 0], palette.dirtDark);
// Water channel along the north edge.
addBox(scene, [17.4, 0.08, 0.95], [0, 0.09, 4.28], palette.water, false);
for (let i = 0; i < 18; i++) {
addBox(
scene,
[0.45, 0.07, 0.12],
[-8.2 + i * 0.95, 0.17, 4.15 + Math.sin(i) * 0.1],
palette.white,
false
);
}
// Common depot and exchange pad.
addBuilding(0, -3.1, 3.4, 1.65, 1.65, palette.wall, palette.roof);
addBox(scene, [2.9, 0.13, 0.95], [0, 0.13, -1.45], palette.path);
for (let i = 0; i < 7; i++) {
addBox(
scene,
[0.32, 0.035, 0.7],
[-0.96 + i * 0.32, 0.21, -1.45],
i % 2 ? palette.amber : palette.teal,
false
);
}
// Depot sign tower.
addBox(scene, [0.18, 2.8, 0.18], [-1.28, 1.4, -2.1], palette.dark);
addBox(scene, [1.4, 0.55, 0.18], [-0.68, 2.65, -2.1], palette.dark);
addBox(scene, [1.1, 0.12, 0.2], [-0.68, 2.65, -2.22], palette.amber, false);
// West quarry.
addBuilding(-6, -3.15, 2.2, 1.45, 1.05, palette.stone, palette.stoneDark);
addBox(scene, [1.0, 0.8, 1.0], [-7.1, 0.45, -2.0], palette.stoneDark);
addBox(scene, [0.75, 0.65, 0.75], [-7.05, 1.05, -2.0], palette.stone);
addBox(scene, [0.16, 2.1, 0.16], [-5.3, 1.05, -3.0], palette.wood);
addBox(scene, [1.9, 0.16, 0.16], [-5.9, 1.95, -3.0], palette.wood);
addBox(scene, [0.14, 1.0, 0.14], [-6.55, 1.45, -3.0], palette.dark);
// East orchard.
addBuilding(6, -3.05, 2.1, 1.5, 1.05, palette.cream, palette.roof);
addVoxelTree(4.8, -3.5, 0.82);
addVoxelTree(7.25, -3.5, 0.92);
addVoxelTree(6.0, -4.0, 0.72);
// Relay and pump.
addBuilding(-3, -3.0, 1.25, 1.05, 0.9, palette.stone, palette.roof);
addBox(scene, [0.9, 0.55, 0.75], [3, 0.28, -3.0], palette.stoneDark);
addBox(scene, [0.75, 0.3, 0.65], [3, 0.7, -3.0], palette.water);
// Northern hills and vegetation.
addHill(-4.4, 3.75);
addHill(4.4, 3.75, material("#68776a"));
addVoxelTree(-7.3, 3.3, 0.75);
addVoxelTree(7.5, 3.25, 0.85);
addVoxelTree(-2.6, 3.9, 0.65);
addVoxelTree(2.4, 4.0, 0.65);
// Small voxel crates around the depot.
for (let i = 0; i < 6; i++) {
const crate = new THREE.Group();
crate.position.set(
-1.65 + (i % 3) * 0.38,
0.05,
-0.45 + Math.floor(i / 3) * 0.42
);
addBox(crate, [0.32, 0.32, 0.32], [0, 0.16, 0], palette.cream);
addBox(crate, [0.34, 0.06, 0.34], [0, 0.18, 0], palette.wood, false);
scene.add(crate);
}
// Route meshes made from small voxel blocks.
const routeMeshes = new Map();
for (const carrier of Object.values(carriers)) {
for (const route of carrier.routes) {
const positions = [];
for (let segment = 0; segment < route.path.length - 1; segment++) {
const a = route.path[segment];
const b = route.path[segment + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const steps = Math.max(1, Math.ceil(length / 0.28));
for (let i = 0; i < steps; i++) {
const t = i / steps;
positions.push([a[0] + dx * t, a[1] + dz * t]);
}
}
positions.push(route.path[route.path.length - 1]);
const geometry = new THREE.BoxGeometry(0.17, 0.08, 0.17);
const routeMaterial = new THREE.MeshBasicMaterial({
color: "#82948f",
transparent: true,
opacity: 0.28,
toneMapped: false
});
const mesh = new THREE.InstancedMesh(
geometry,
routeMaterial,
positions.length
);
const dummy = new THREE.Object3D();
positions.forEach((position, index) => {
dummy.position.set(position[0], 0.14, position[1]);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.frustumCulled = false;
scene.add(mesh);
routeMeshes.set(`${carrier.key}-${route.id}`, mesh);
}
}
// Closed-road barrier on Kestrel's switchback.
const barrier = new THREE.Group();
barrier.position.set(5.28, 0.12, 1.45);
barrier.rotation.y = -0.24;
addBox(barrier, [0.18, 1.1, 0.18], [-0.55, 0.55, 0], palette.dark);
addBox(barrier, [0.18, 1.1, 0.18], [0.55, 0.55, 0], palette.dark);
addBox(barrier, [1.45, 0.25, 0.16], [0, 0.75, 0], palette.white);
for (let i = 0; i < 4; i++) {
addBox(
barrier,
[0.22, 0.27, 0.18],
[-0.48 + i * 0.32, 0.75, 0],
palette.red,
false
);
}
scene.add(barrier);
function updateRouteVisuals() {
for (const carrier of Object.values(carriers)) {
for (const route of carrier.routes) {
const mesh = routeMeshes.get(`${carrier.key}-${route.id}`);
const selected = state.routes[carrier.key] === route.id;
mesh.material.color.set(selected ? carrier.color : "#81938e");
mesh.material.opacity = selected ? 1 : 0.28;
}
}
}
// ---------- Voxel carriers ----------
function createCarrier(color) {
const group = new THREE.Group();
const bodyMaterial = material(color);
const darkBody = material(new THREE.Color(color).multiplyScalar(0.68));
const wheelMaterial = material("#24312f");
const glassMaterial = material("#9bd5d1", {
emissive: "#315e5a",
emissiveIntensity: 0.25
});
addBox(group, [0.82, 0.38, 1.45], [0, 0.42, 0], darkBody);
addBox(group, [0.78, 0.58, 0.48], [0, 0.76, 0.47], bodyMaterial);
addBox(group, [0.68, 0.24, 0.05], [0, 0.87, 0.725], glassMaterial, false);
addBox(group, [0.86, 0.14, 0.52], [0, 0.55, -0.52], bodyMaterial);
addBox(group, [0.88, 0.12, 0.15], [0, 0.35, 0.72], palette.cream);
const wheelPositions = [
[-0.45, 0.22, 0.43],
[0.45, 0.22, 0.43],
[-0.45, 0.22, -0.42],
[0.45, 0.22, -0.42]
];
for (const position of wheelPositions) {
addBox(group, [0.18, 0.32, 0.32], position, wheelMaterial);
}
const cargoGroup = new THREE.Group();
group.add(cargoGroup);
const crateSlots = [];
for (let layer = 0; layer < 3; layer++) {
for (let z = 0; z < 2; z++) {
for (let x = 0; x < 2; x++) {
crateSlots.push([
(x - 0.5) * 0.31,
0.72 + layer * 0.27,
-0.18 - z * 0.34
]);
}
}
}
const cargoMeshes = crateSlots.map((position, index) => {
const crateMaterial = index % 3 === 0 ? palette.cream : bodyMaterial;
const crate = addBox(
cargoGroup,
[0.28, 0.25, 0.28],
position,
crateMaterial
);
crate.visible = false;
return crate;
});
group.userData.cargoMeshes = cargoMeshes;
scene.add(group);
return group;
}
const trucks = {
A: createCarrier(carriers.A.color),
B: createCarrier(carriers.B.color)
};
function updateTruckCargo() {
for (const carrier of Object.values(carriers)) {
const truck = trucks[carrier.key];
const visible = Math.min(12, state.loads[carrier.key]);
truck.userData.cargoMeshes.forEach((mesh, index) => {
mesh.visible = index < visible;
});
}
}
function sampleRoute(path, progress) {
const lengths = [];
let total = 0;
for (let i = 0; i < path.length - 1; i++) {
const dx = path[i + 1][0] - path[i][0];
const dz = path[i + 1][1] - path[i][1];
const length = Math.hypot(dx, dz);
lengths.push(length);
total += length;
}
let remaining = 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 a = path[i];
const b = path[i + 1];
const x = THREE.MathUtils.lerp(a[0], b[0], t);
const z = THREE.MathUtils.lerp(a[1], b[1], t);
const angle = Math.atan2(b[0] - a[0], b[1] - a[1]);
return { x, z, angle };
}
remaining -= lengths[i];
}
return { x: path[0][0], z: path[0][1], angle: 0 };
}
function resetTrucks() {
for (const carrier of Object.values(carriers)) {
const route = routeFor(carrier.key);
const start = sampleRoute(route.path, 0);
trucks[carrier.key].position.set(start.x, 0.13, start.z);
trucks[carrier.key].rotation.y = start.angle;
}
}
function animateTrucks(now) {
if (!state.proposed) return;
const elapsed = now - state.dispatchStart;
const progress = clamp(elapsed / 6200, 0, 1);
for (const carrier of Object.values(carriers)) {
const route = routeFor(carrier.key);
const truck = trucks[carrier.key];
if (!route.open) {
const start = sampleRoute(route.path, 0);
truck.position.set(start.x, 0.13, start.z);
truck.rotation.y = start.angle;
continue;
}
const point = sampleRoute(route.path, progress);
truck.position.set(point.x, 0.13, point.z);
truck.rotation.y = point.angle;
}
}
resetTrucks();
// Depot verification beacon.
const beaconMaterial = material("#f3b83f", {
emissive: "#8e6312",
emissiveIntensity: 0.7
});
addBox(scene, [0.55, 1.0, 0.55], [1.22, 0.5, -3.0], palette.dark);
addBox(scene, [0.42, 0.42, 0.42], [1.22, 1.2, -3.0], beaconMaterial, false);
function updateBeacon() {
if (state.verified) {
const passed = state.verification.every((check) => check.pass);
beaconMaterial.color.set(passed ? "#68d58b" : "#ef675f");
beaconMaterial.emissive.set(passed ? "#287a45" : "#8c2521");
beaconMaterial.emissiveIntensity = 1.2;
} else if (state.proposed) {
beaconMaterial.color.set("#f3b83f");
beaconMaterial.emissive.set("#8e6312");
beaconMaterial.emissiveIntensity = 0.8;
} else {
beaconMaterial.color.set("#aeb8ae");
beaconMaterial.emissive.set("#4c5550");
beaconMaterial.emissiveIntensity = 0.2;
}
}
// ---------- World-space labels ----------
const labelLayer = $("labels");
const labels = [];
function createLabel(text, className, anchor) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({ element, anchor });
}
createLabel("West Quarry", "", new THREE.Vector3(-6, 1.75, -3.15));
createLabel("East Orchard", "", new THREE.Vector3(6, 1.75, -3.05));
createLabel("West Relay", "", new THREE.Vector3(-3, 1.45, -3));
createLabel("East Pump", "", new THREE.Vector3(3, 1.25, -3));
createLabel("Common Depot", "depot", new THREE.Vector3(0, 2.55, -3.1));
createLabel("Aster", "carrier a", () =>
trucks.A.position.clone().add(new THREE.Vector3(0, 1.55, 0))
);
createLabel("Kestrel", "carrier b", () =>
trucks.B.position.clone().add(new THREE.Vector3(0, 1.55, 0))
);
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labels) {
const position = typeof label.anchor === "function"
? label.anchor()
: label.anchor;
const projected = position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -100%)`;
}
}
// ---------- Direct camera controls (no addons) ----------
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const x = cameraState.target.x + 18 * sinPhi * Math.sin(cameraState.theta);
const y = cameraState.target.y + 18 * Math.cos(cameraState.phi);
const z = cameraState.target.z + 18 * sinPhi * Math.cos(cameraState.theta);
camera.position.set(x, y, z);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.68;
cameraState.phi = 0.78;
cameraState.zoom = 1;
updateCamera();
}
let dragging = false;
let previousPointer = { x: 0, y: 0 };
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi + dy * 0.005, 0.45, 1.25);
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
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.zoom = clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.9
);
updateCamera();
},
{ passive: false }
);
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const aspect = width / Math.max(1, height);
const viewHeight = Math.max(11, 19 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
// ---------- Initialize and render ----------
buildCarrierCards();
bindUI();
updateUI();
updateCamera();
resize();
$("loading").style.display = "none";
renderer.setAnimationLoop((now) => {
animateTrucks(now);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```