Prompt specification
Build or customize the Three.js 3D scene "Community Supply Strategy Board" 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: Community Supply Strategy Board
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-supply-strategy-board-x3551
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring tradeoffs between route objectives. Create an original delivery game balancing coverage, travel time, and limited supplies. Let players choose explicit priorities and see the resulting tradeoffs on the map. Voxel style.
Working Three.js Starter (community-supply-strategy-board-x3551):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Blockrun — Delivery Priorities</title>
<style>
:root {
--bg: #0d171d;
--panel: #142129;
--panel-2: #1a2a33;
--panel-3: #213640;
--line: #2b414d;
--text: #edf5f3;
--muted: #91a8af;
--teal: #55e0cc;
--teal-dark: #1e796e;
--orange: #ffad5a;
--yellow: #f3d66b;
--blue: #73aee8;
--red: #f27777;
--shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-rows: 66px minmax(0, 1fr) 34px;
width: 100%;
height: 100%;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 20px;
border-bottom: 1px solid var(--line);
background: #111d24;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 260px;
}
.brand-mark {
position: relative;
width: 37px;
height: 37px;
border-radius: 9px;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(85, 224, 204, 0.1);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: #102129;
}
.brand-mark::before {
width: 19px;
height: 7px;
left: 9px;
top: 9px;
box-shadow: 0 12px 0 #102129;
}
.brand-mark::after {
width: 7px;
height: 19px;
left: 15px;
top: 9px;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.shift-info {
display: flex;
align-items: center;
gap: 24px;
color: var(--muted);
font-size: 12px;
}
.shift-info strong {
display: block;
margin-top: 3px;
color: var(--text);
font-size: 13px;
font-weight: 650;
}
.shift-chip {
display: flex;
align-items: center;
gap: 8px;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--teal);
box-shadow: 0 0 12px rgba(85, 224, 204, 0.7);
}
.icon-button,
.ghost-button {
border: 1px solid var(--line);
background: var(--panel-2);
border-radius: 8px;
cursor: pointer;
transition: 160ms ease;
}
.icon-button {
padding: 9px 13px;
color: var(--muted);
font-size: 12px;
font-weight: 700;
}
.icon-button:hover,
.ghost-button:hover {
color: var(--text);
border-color: #4d6d78;
transform: translateY(-1px);
}
.workspace {
display: grid;
grid-template-columns: 300px minmax(0, 1fr) 320px;
min-height: 0;
}
.panel {
min-height: 0;
overflow-y: auto;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #38515c transparent;
}
.left-panel {
padding: 22px 20px;
border-right: 1px solid var(--line);
}
.right-panel {
padding: 20px;
border-left: 1px solid var(--line);
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 20px;
line-height: 1.15;
}
.intro {
margin: 9px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section-label {
margin: 21px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.preset-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.preset-button {
min-height: 55px;
padding: 9px;
text-align: left;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel-2);
cursor: pointer;
transition: 160ms ease;
}
.preset-button:hover {
border-color: #51717b;
}
.preset-button.active {
border-color: var(--teal);
background: rgba(85, 224, 204, 0.09);
box-shadow: inset 0 0 0 1px rgba(85, 224, 204, 0.12);
}
.preset-button strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
}
.preset-button small {
color: var(--muted);
font-size: 9px;
line-height: 1.25;
}
.priority {
margin-top: 15px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: #111d24;
}
.priority-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.priority-heading label {
font-size: 12px;
font-weight: 750;
}
.priority-heading output {
color: var(--text);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.priority-heading output span {
margin-left: 4px;
color: var(--muted);
font-size: 9px;
}
.priority-description {
margin: 5px 0 10px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 4px 0;
appearance: none;
border-radius: 999px;
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid #102028;
border-radius: 4px;
background: var(--range-color, var(--teal));
box-shadow: 0 0 0 1px var(--range-color, var(--teal));
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #102028;
border-radius: 4px;
background: var(--range-color, var(--teal));
box-shadow: 0 0 0 1px var(--range-color, var(--teal));
}
.mix-bar {
display: flex;
height: 8px;
margin-top: 16px;
overflow: hidden;
border-radius: 999px;
background: var(--panel-3);
}
.mix-bar span {
min-width: 0;
transition: width 220ms ease;
}
.mix-bar .coverage {
background: var(--teal);
}
.mix-bar .time {
background: var(--orange);
}
.mix-bar .supply {
background: var(--blue);
}
.priority-readout {
min-height: 64px;
margin-top: 12px;
padding: 11px 12px;
border-left: 3px solid var(--teal);
border-radius: 0 7px 7px 0;
background: var(--panel-2);
color: #bfd0d4;
font-size: 11px;
line-height: 1.5;
}
.primary-button {
width: 100%;
min-height: 43px;
margin-top: 15px;
border: 0;
border-radius: 8px;
background: var(--teal);
color: #10242a;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.03em;
cursor: pointer;
box-shadow: 0 7px 20px rgba(30, 121, 110, 0.2);
transition: 160ms ease;
}
.primary-button:hover:not(:disabled) {
transform: translateY(-1px);
background: #7aebdc;
box-shadow: 0 10px 24px rgba(30, 121, 110, 0.3);
}
.primary-button:disabled {
opacity: 0.42;
cursor: not-allowed;
}
.small-note {
margin-top: 10px;
color: #718b93;
font-size: 10px;
line-height: 1.45;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #17262e;
}
#canvasHost {
position: absolute;
inset: 0;
}
#canvasHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#canvasHost canvas:active {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.map-marker,
.depot-marker {
position: absolute;
transform: translate(-50%, -100%);
pointer-events: auto;
}
.map-marker {
min-width: 104px;
padding: 7px 9px 7px 7px;
border: 1px solid rgba(208, 226, 226, 0.22);
border-radius: 7px;
background: rgba(18, 31, 38, 0.92);
color: var(--text);
text-align: left;
box-shadow: 0 7px 18px rgba(0, 0, 0, 0.28);
cursor: pointer;
transition: opacity 180ms ease, transform 180ms ease, border-color 180ms ease;
backdrop-filter: blur(5px);
}
.map-marker::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 10px;
height: 10px;
transform: translateX(-50%) rotate(45deg);
border-right: 1px solid rgba(208, 226, 226, 0.22);
border-bottom: 1px solid rgba(208, 226, 226, 0.22);
background: #121f26;
}
.map-marker:hover {
transform: translate(-50%, -100%) scale(1.04);
border-color: var(--teal);
}
.map-marker.selected {
border-color: var(--teal);
background: rgba(18, 43, 48, 0.96);
box-shadow: 0 8px 23px rgba(0, 0, 0, 0.35), 0 0 0 2px rgba(85, 224, 204, 0.13);
}
.map-marker.muted {
opacity: 0.48;
}
.marker-main {
display: flex;
align-items: center;
gap: 7px;
}
.marker-icon {
width: 17px;
height: 17px;
flex: 0 0 auto;
border-radius: 3px;
background: var(--pin-color);
box-shadow: inset -4px -4px rgba(0, 0, 0, 0.13);
}
.marker-name {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.03em;
}
.marker-meta {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
}
.marker-order {
display: inline-grid;
place-items: center;
min-width: 16px;
height: 16px;
margin-left: auto;
border-radius: 3px;
background: var(--teal);
color: #10242a;
font-size: 9px;
font-weight: 900;
}
.depot-marker {
padding: 6px 9px;
border: 1px solid rgba(255, 173, 90, 0.5);
border-radius: 5px;
background: rgba(56, 38, 24, 0.9);
color: #ffd7a9;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stage-hud {
position: absolute;
z-index: 4;
pointer-events: none;
}
.stage-hud.top-left {
top: 16px;
left: 17px;
}
.stage-hud.bottom-left {
bottom: 15px;
left: 17px;
}
.map-title {
padding: 8px 10px;
border: 1px solid rgba(208, 226, 226, 0.13);
border-radius: 7px;
background: rgba(13, 23, 29, 0.76);
color: #c0d2d5;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
backdrop-filter: blur(6px);
}
.map-hint {
padding: 7px 10px;
border-radius: 6px;
background: rgba(13, 23, 29, 0.68);
color: #9db2b7;
font-size: 9px;
backdrop-filter: blur(5px);
}
.legend {
display: flex;
gap: 12px;
margin-top: 8px;
padding: 7px 9px;
border-radius: 6px;
background: rgba(13, 23, 29, 0.72);
color: #b4c5c8;
font-size: 9px;
backdrop-filter: blur(5px);
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 2px;
}
#toast {
position: absolute;
z-index: 8;
top: 70px;
left: 50%;
max-width: 80%;
padding: 10px 14px;
transform: translate(-50%, -12px);
border: 1px solid #49636d;
border-radius: 7px;
background: #182932;
color: var(--text);
font-size: 11px;
opacity: 0;
pointer-events: none;
transition: 180ms ease;
box-shadow: var(--shadow);
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.manifest-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.route-badge {
padding: 6px 8px;
border-radius: 5px;
background: var(--panel-3);
color: var(--muted);
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.route-list {
display: flex;
flex-direction: column;
gap: 7px;
margin: 15px 0;
}
.empty-route {
padding: 18px 12px;
border: 1px dashed #38515c;
border-radius: 8px;
color: var(--muted);
text-align: center;
font-size: 11px;
line-height: 1.5;
}
.route-card {
display: grid;
grid-template-columns: 27px minmax(0, 1fr) auto;
align-items: center;
gap: 9px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel-2);
}
.route-number {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border-radius: 5px;
background: var(--stop-color);
color: #112126;
font-size: 11px;
font-weight: 900;
}
.route-card h3 {
margin: 0 0 3px;
font-size: 11px;
}
.route-card p {
margin: 0;
color: var(--muted);
font-size: 9px;
}
.route-actions {
display: flex;
gap: 3px;
}
.mini-button {
display: grid;
place-items: center;
width: 24px;
height: 24px;
padding: 0;
border: 1px solid #36505b;
border-radius: 5px;
background: #17262e;
color: #b9c9cd;
font-size: 11px;
cursor: pointer;
}
.mini-button:hover {
border-color: var(--teal);
color: var(--teal);
}
.mini-button.remove:hover {
border-color: var(--red);
color: var(--red);
}
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 12px;
}
.stat {
min-height: 66px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: #111d24;
}
.stat span {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.stat strong {
font-size: 17px;
font-variant-numeric: tabular-nums;
}
.stat small {
margin-left: 3px;
color: var(--muted);
font-size: 9px;
}
.capacity {
margin-top: 8px;
padding: 9px 10px;
border-radius: 7px;
background: var(--panel-2);
color: var(--muted);
font-size: 10px;
}
.capacity strong {
color: var(--text);
}
.comparison {
display: flex;
flex-direction: column;
gap: 6px;
}
.comparison-row {
position: relative;
overflow: hidden;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: var(--panel-2);
}
.comparison-row.current {
border-color: var(--teal-dark);
background: rgba(85, 224, 204, 0.07);
}
.comparison-row::after {
content: "";
position: absolute;
z-index: 0;
left: 0;
bottom: 0;
width: var(--bar-width, 0%);
height: 2px;
background: var(--bar-color, var(--teal));
opacity: 0.75;
}
.comparison-row > * {
position: relative;
z-index: 1;
}
.comparison-title {
display: flex;
justify-content: space-between;
gap: 8px;
font-size: 10px;
font-weight: 800;
}
.comparison-title span {
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.comparison-row p {
margin: 5px 0 0;
color: var(--muted);
font-size: 9px;
}
.score-panel {
margin-top: 12px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: #111d24;
}
.score-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.score-row span {
color: var(--muted);
font-size: 10px;
}
.score-row strong {
font-size: 22px;
}
.score-track {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: #293e48;
}
.score-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal-dark), var(--teal));
transition: width 250ms ease;
}
.dispatch-button {
margin-top: 12px;
background: var(--orange);
color: #2c2014;
box-shadow: 0 7px 20px rgba(255, 173, 90, 0.14);
}
.dispatch-button:hover:not(:disabled) {
background: #ffc078;
box-shadow: 0 10px 24px rgba(255, 173, 90, 0.22);
}
.statusbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 0 17px;
border-top: 1px solid var(--line);
background: #101b22;
color: #829ba3;
font-size: 10px;
}
.statusbar strong {
color: var(--teal);
}
#modal {
position: fixed;
z-index: 50;
inset: 0;
display: none;
place-items: center;
padding: 20px;
background: rgba(5, 10, 13, 0.76);
backdrop-filter: blur(7px);
}
#modal.show {
display: grid;
}
.modal-card {
width: min(430px, 100%);
overflow: hidden;
border: 1px solid #38525d;
border-radius: 14px;
background: var(--panel);
box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
animation: modal-in 240ms ease both;
}
@keyframes modal-in {
from {
opacity: 0;
transform: translateY(12px) scale(0.97);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
.modal-banner {
padding: 26px;
border-bottom: 1px solid var(--line);
background:
linear-gradient(135deg, rgba(85, 224, 204, 0.12), transparent 65%),
#17262e;
}
.modal-banner h2 {
margin: 6px 0 0;
font-size: 27px;
}
.result-score {
margin-top: 18px;
color: var(--teal);
font-size: 54px;
font-weight: 900;
line-height: 1;
}
.result-score small {
color: var(--muted);
font-size: 14px;
font-weight: 650;
}
.result-body {
padding: 20px 26px 26px;
}
.result-metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 16px;
}
.result-metric {
padding: 10px;
border: 1px solid var(--line);
border-radius: 7px;
background: #111d24;
}
.result-metric span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.result-metric strong {
font-size: 13px;
}
#resultNarrative {
margin: 0 0 18px;
color: #a9bdc3;
font-size: 12px;
line-height: 1.6;
}
.modal-card .primary-button {
margin: 0;
}
@media (max-width: 1120px) {
.workspace {
grid-template-columns: 270px minmax(0, 1fr) 290px;
}
.left-panel,
.right-panel {
padding: 18px 15px;
}
.shift-info {
gap: 13px;
}
}
@media (max-width: 880px) {
html,
body {
height: auto;
overflow: auto;
}
#app {
display: block;
height: auto;
}
.topbar {
position: sticky;
top: 0;
min-height: 66px;
}
.workspace {
display: flex;
flex-direction: column;
}
#stage {
order: -1;
height: 66vh;
min-height: 480px;
}
.panel {
overflow: visible;
}
.left-panel {
border-right: 0;
border-bottom: 1px solid var(--line);
}
.right-panel {
border-left: 0;
border-top: 1px solid var(--line);
}
.shift-info {
display: none;
}
.statusbar {
min-height: 36px;
}
}
@media (max-width: 520px) {
.brand p {
display: none;
}
.brand {
min-width: 0;
}
.icon-button {
padding: 8px 10px;
}
.stage-hud.bottom-left {
display: none;
}
.map-marker {
min-width: 88px;
padding: 6px;
}
.marker-name {
font-size: 9px;
}
.marker-meta {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Blockrun</h1>
<p>Priority delivery lab</p>
</div>
</div>
<div class="shift-info">
<div class="shift-chip">
<span class="status-dot"></span>
<div>
North Quay district
<strong>Shift 04 · Morning run</strong>
</div>
</div>
<div>
Available supplies
<strong>14 crates</strong>
</div>
<div>
Households mapped
<strong>37 homes</strong>
</div>
</div>
<button class="icon-button" id="resetBtn" type="button">Reset shift</button>
</header>
<div class="workspace">
<aside class="panel left-panel">
<div class="eyebrow">01 / Dispatch priorities</div>
<h2>What matters today?</h2>
<p class="intro">
Set the balance before planning. Every priority changes which requests enter
the route and how the score rewards the result.
</p>
<div class="section-label">Quick mixes</div>
<div class="preset-grid" id="presets">
<button class="preset-button active" type="button" data-preset="balanced">
<strong>Balanced</strong>
<small>A dependable mixed shift</small>
</button>
<button class="preset-button" type="button" data-preset="coverage">
<strong>Broad reach</strong>
<small>Maximize households served</small>
</button>
<button class="preset-button" type="button" data-preset="speed">
<strong>Fast relief</strong>
<small>Favor urgent nearby stops</small>
</button>
<button class="preset-button" type="button" data-preset="supply">
<strong>Lean stock</strong>
<small>Protect remaining crates</small>
</button>
</div>
<div class="priority">
<div class="priority-heading">
<label for="coverageRange">Coverage</label>
<output id="coverageValue">45 <span>55%</span></output>
</div>
<div class="priority-description">Favors routes serving more households.</div>
<input
id="coverageRange"
type="range"
min="0"
max="100"
value="45"
style="--range-color: var(--teal)"
/>
</div>
<div class="priority">
<div class="priority-heading">
<label for="timeRange">Travel time</label>
<output id="timeValue">30 <span>30%</span></output>
</div>
<div class="priority-description">Favors urgent requests with shorter detours.</div>
<input
id="timeRange"
type="range"
min="0"
max="100"
value="30"
style="--range-color: var(--orange)"
/>
</div>
<div class="priority">
<div class="priority-heading">
<label for="supplyRange">Supply reserve</label>
<output id="supplyValue">25 <span>25%</span></output>
</div>
<div class="priority-description">Avoids bulky requests and protects spare crates.</div>
<input
id="supplyRange"
type="range"
min="0"
max="100"
value="25"
style="--range-color: var(--blue)"
/>
</div>
<div class="mix-bar" aria-hidden="true">
<span class="coverage" id="mixCoverage"></span>
<span class="time" id="mixTime"></span>
<span class="supply" id="mixSupply"></span>
</div>
<div class="priority-readout" id="priorityReadout">
A balanced route: serve useful demand without creating a long or wasteful shift.
</div>
<button class="primary-button" id="autoPlan" type="button">
Auto-plan with this mix
</button>
<div class="small-note">
Moving a slider re-plans the route. You can then click map pins or use the
manifest arrows to fine-tune it manually.
</div>
</aside>
<main id="stage" aria-label="Interactive voxel district map">
<div id="canvasHost"></div>
<div id="labels"></div>
<div class="stage-hud top-left">
<div class="map-title">North Quay / Isometric district</div>
<div class="legend">
<span><i style="background: var(--teal)"></i> Selected</span>
<span><i style="background: var(--orange)"></i> Depot</span>
<span><i style="background: var(--blue)"></i> Click to edit</span>
</div>
</div>
<div class="stage-hud bottom-left">
<div class="map-hint">Drag to pan · Scroll to zoom · Click pins to edit the route</div>
</div>
<div id="toast" role="status"></div>
</main>
<aside class="panel right-panel">
<div class="manifest-heading">
<div>
<div class="eyebrow">02 / Route manifest</div>
<h2>Delivery route</h2>
</div>
<div class="route-badge" id="routeMeta">0 stops</div>
</div>
<div class="route-list" id="routeList"></div>
<div class="stats-grid">
<div class="stat">
<span>Households</span>
<strong id="statCoverage">0</strong>
<small>/ 37</small>
</div>
<div class="stat">
<span>Route time</span>
<strong id="statTime">0</strong>
<small>min</small>
</div>
<div class="stat">
<span>Cargo used</span>
<strong id="statCargo">0</strong>
<small>/ 14</small>
</div>
<div class="stat">
<span>Est. score</span>
<strong id="statScore">0</strong>
<small>/ 100</small>
</div>
</div>
<div class="capacity" id="capacityText">
<strong>14 crates available.</strong> Every request consumes its stated cargo.
</div>
<div class="section-label">Tradeoff preview</div>
<div class="comparison" id="comparison"></div>
<div class="score-panel">
<div class="score-row">
<span>Weighted route score</span>
<strong id="scoreValue">0</strong>
</div>
<div class="score-track">
<div class="score-fill" id="scoreFill"></div>
</div>
</div>
<button class="primary-button dispatch-button" id="dispatchBtn" type="button" disabled>
Dispatch route
</button>
<div class="small-note">
A 30-minute target receives full time credit. Later routes retain partial credit;
faster routes receive more.
</div>
</aside>
</div>
<footer class="statusbar">
<div id="logText"><strong>Dispatch desk:</strong> Balanced route generated.</div>
<div>Core Three.js · No controls addons · Voxel district</div>
</footer>
</div>
<div id="modal" role="dialog" aria-modal="true" aria-labelledby="resultTitle">
<div class="modal-card">
<div class="modal-banner">
<div class="eyebrow">Shift complete</div>
<h2 id="resultTitle">Route delivered</h2>
<div class="result-score">
<span id="resultScore">0</span><small> / 100</small>
</div>
</div>
<div class="modal-body">
<div class="result-metrics">
<div class="result-metric">
<span>Reached</span>
<strong id="resultCoverage">0 / 37</strong>
</div>
<div class="result-metric">
<span>Travel</span>
<strong id="resultTime">0 min</strong>
</div>
<div class="result-metric">
<span>Spare</span>
<strong id="resultCargo">14 crates</strong>
</div>
</div>
<p id="resultNarrative"></p>
<button class="primary-button" id="resultDone" type="button">
Back to dispatch desk
</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Data
// ------------------------------------------------------------
const $ = (selector) => document.querySelector(selector);
const nodes = [
{ name: "Depot", x: 0, z: 0 },
{ name: "North", x: 0, z: 7 },
{ name: "Market", x: 8, z: 5 },
{ name: "Clinic", x: 10, z: -1 },
{ name: "East Homes", x: 7, z: -7 },
{ name: "School", x: -1, z: -9 },
{ name: "West Grove", x: -9, z: -6 },
{ name: "Workshop", x:-11, z: 1 },
{ name: "North Studio",x: -8, z: 7 }
];
const edges = [
[0, 1, 4], [0, 2, 6], [0, 3, 7], [0, 4, 6],
[0, 5, 5], [0, 6, 6], [0, 7, 7], [0, 8, 5],
[1, 2, 3], [2, 3, 4], [3, 4, 4], [4, 5, 4],
[5, 6, 5], [6, 7, 4], [7, 8, 5], [8, 1, 3]
];
const stops = [
{
id: "market", node: 2, name: "Market", demand: 3, people: 6, urgency: 1.0,
color: "#f0bd58", icon: "M"
},
{
id: "clinic", node: 3, name: "Clinic", demand: 2, people: 4, urgency: 2.4,
color: "#f27777", icon: "+"
},
{
id: "homes", node: 4, name: "East Homes", demand: 4, people: 8, urgency: 1.0,
color: "#73aee8", icon: "H"
},
{
id: "school", node: 5, name: "School", demand: 3, people: 7, urgency: 1.35,
color: "#b18be8", icon: "S"
},
{
id: "grove", node: 6, name: "West Grove", demand: 2, people: 3, urgency: 0.7,
color: "#78c47a", icon: "G"
},
{
id: "workshop", node: 7, name: "Workshop", demand: 4, people: 5, urgency: 1.1,
color: "#e88960", icon: "W"
},
{
id: "studio", node: 8, name: "North Studio", demand: 2, people: 4, urgency: 0.9,
color: "#5ed7cf", icon: "N"
}
];
const TOTAL_CARGO = 14;
const TOTAL_PEOPLE = stops.reduce((sum, stop) => sum + stop.people, 0);
const TARGET_TIME = 30;
const adjacency = nodes.map(() => []);
for (const [a, b, time] of edges) {
adjacency[a].push({ to: b, time });
adjacency[b].push({ to: a, time });
}
const presets = {
balanced: [45, 30, 25],
coverage: [75, 15, 10],
speed: [15, 75, 10],
supply: [15, 15, 70]
};
const priority = {
coverage: 45,
time: 30,
supply: 25
};
let route = [];
let dispatching = false;
let dispatchClock = 0;
let dispatchDuration = 0;
let dispatchSegments = [];
let dispatchTotalDistance = 0;
let toastTimer;
// ------------------------------------------------------------
// Graph and route logic
// ------------------------------------------------------------
function shortestPath(from, to) {
if (from === to) {
return { path: [to], time: 0 };
}
const distance = nodes.map(() => Infinity);
const previous = nodes.map(() => -1);
const visited = nodes.map(() => false);
distance[from] = 0;
for (let iteration = 0; iteration < nodes.length; iteration++) {
let current = -1;
for (let i = 0; i < nodes.length; i++) {
if (!visited[i] && (current === -1 || distance[i] < distance[current])) {
current = i;
}
}
if (current === -1 || distance[current] === Infinity) break;
if (current === to) break;
visited[current] = true;
for (const edge of adjacency[current]) {
const candidate = distance[current] + edge.time;
if (candidate < distance[edge.to]) {
distance[edge.to] = candidate;
previous[edge.to] = current;
}
}
}
const path = [];
let cursor = to;
while (cursor !== -1) {
path.push(cursor);
if (cursor === from) break;
cursor = previous[cursor];
}
path.reverse();
return {
path,
time: distance[to]
};
}
function normalizedPriorities() {
const total = priority.coverage + priority.time + priority.supply;
if (total === 0) {
return { coverage: 1 / 3, time: 1 / 3, supply: 1 / 3 };
}
return {
coverage: priority.coverage / total,
time: priority.time / total,
supply: priority.supply / total
};
}
function planFor(weights) {
let remaining = TOTAL_CARGO;
let current = 0;
const selected = [];
while (selected.length < stops.length) {
let best = null;
for (const stop of stops) {
if (selected.some((item) => item.id === stop.id)) continue;
if (stop.demand > remaining) continue;
const leg = shortestPath(current, stop.node);
const coverageUtility = stop.people / 8;
const timeUtility = stop.urgency * 9 / (leg.time + 3);
const supplyUtility =
(6 / (stop.demand + 1)) * Math.min(1, remaining / 8);
const utility =
weights.coverage * coverageUtility +
weights.time * timeUtility +
weights.supply * supplyUtility;
if (!best || utility > best.utility) {
best = { stop, utility, leg };
}
}
if (!best) break;
selected.push(best.stop);
remaining -= best.stop.demand;
current = best.stop.node;
}
return selected;
}
function routeDetails(selectedRoute = route) {
let current = 0;
let usedCargo = 0;
let people = 0;
let time = 0;
const path = [0];
const legs = [];
for (const stop of selectedRoute) {
const leg = shortestPath(current, stop.node);
time += leg.time;
usedCargo += stop.demand;
people += stop.people;
legs.push(leg.time);
path.push(...leg.path.slice(1));
current = stop.node;
}
const returnLeg = shortestPath(current, 0);
time += returnLeg.time;
path.push(...returnLeg.path.slice(1));
return {
usedCargo,
people,
time,
path,
legs,
remaining: TOTAL_CARGO - usedCargo
};
}
function scoreFor(details) {
const weights = normalizedPriorities();
const coverageScore = details.people / TOTAL_PEOPLE * 100;
const timeScore = details.time <= TARGET_TIME
? 100
: Math.max(0, 100 - (details.time - TARGET_TIME) * 3.2);
const supplyScore = details.remaining / TOTAL_CARGO * 100;
return {
total: Math.round(
weights.coverage * coverageScore +
weights.time * timeScore +
weights.supply * supplyScore
),
coverage: coverageScore,
time: timeScore,
supply: supplyScore
};
}
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17262e);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 150);
const cameraTarget = new THREE.Vector3(0, 0, 0);
const cameraOffset = new THREE.Vector3(26, 31, 26);
let cameraZoom = 1;
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
$("#canvasHost").appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xc8e1e7, 0x415043, 2.25);
scene.add(ambient);
const sunlight = new THREE.DirectionalLight(0xffe3b8, 3.1);
sunlight.position.set(-13, 26, 12);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -27;
sunlight.shadow.camera.right = 27;
sunlight.shadow.camera.top = 27;
sunlight.shadow.camera.bottom = -27;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 70;
sunlight.shadow.bias = -0.0006;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0x7ab7da, 0.65);
fillLight.position.set(18, 10, -16);
scene.add(fillLight);
const materialCache = new Map();
function getMaterial(color, emissive = 0) {
const key = `${color}-${emissive}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.02,
emissive,
emissiveIntensity: emissive ? 0.65 : 0,
flatShading: true
})
);
}
return materialCache.get(key);
}
function addBox(parent, width, height, depth, color, x, y, z, emissive = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
getMaterial(color, emissive)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const city = new THREE.Group();
scene.add(city);
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const confettiGroup = new THREE.Group();
scene.add(confettiGroup);
const BASE_Y = 0.7;
addBox(city, 34, 1.2, 28, 0x60735b, 0, -0.1, 0);
addBox(city, 33.5, 0.18, 27.5, 0x718365, 0, 0.55, 0);
addBox(city, 32, 0.16, 1.8, 0x477b91, 0, 0.68, -12.3);
addBox(city, 32.2, 0.12, 0.22, 0x8ac3d0, 0, 0.79, -11.35);
addBox(city, 32.2, 0.12, 0.22, 0x8ac3d0, 0, 0.79, -13.25);
for (const [a, b] of edges) {
const start = nodes[a];
const end = nodes[b];
const dx = end.x - start.x;
const dz = end.z - start.z;
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const shoulder = addBox(
city, length + 0.2, 0.13, 1.92, 0x90998b,
(start.x + end.x) / 2, 0.64, (start.z + end.z) / 2
);
shoulder.rotation.y = angle;
const road = addBox(
city, length + 0.15, 0.15, 1.48, 0x37484b,
(start.x + end.x) / 2, 0.76, (start.z + end.z) / 2
);
road.rotation.y = angle;
}
function createBuilding({
x, z, width = 2.4, depth = 2.2, height = 2.8,
color = 0xb56d5a, roof = 0x46535b, sign = 0xffd88d
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
city.add(group);
addBox(group, width, height, depth, color, 0, BASE_Y + height / 2, 0);
addBox(
group, width + 0.22, 0.32, depth + 0.22, roof,
0, BASE_Y + height + 0.16, 0
);
addBox(
group, width * 0.34, 0.38, depth * 0.32, 0x68747a,
width * 0.12, BASE_Y + height + 0.48, -depth * 0.12
);
const windowCount = Math.max(1, Math.floor(width / 0.9));
const windowColor = 0x72a1b4;
for (let i = 0; i < windowCount; i++) {
const wx = -width / 2 + (i + 0.5) * (width / windowCount);
addBox(
group, 0.42, 0.48, 0.08, windowColor,
wx, BASE_Y + height * 0.62, depth / 2 + 0.045,
0x244955
);
addBox(
group, 0.42, 0.48, 0.08, windowColor,
width / 2 + 0.045, BASE_Y + height * 0.62, wx,
0x244955
);
}
addBox(
group, 0.68, 1.15, 0.1, 0x26383e,
0, BASE_Y + 0.575, depth / 2 + 0.06
);
addBox(
group, width * 0.34, 0.28, 0.12, sign,
0, BASE_Y + height * 0.86, depth / 2 + 0.09,
0x6a4b20
);
return group;
}
createBuilding({
x: -1.7, z: 1.8, width: 3.1, depth: 2.5, height: 2.6,
color: 0xa7634e, roof: 0x39464d, sign: 0xffbd67
});
createBuilding({
x: 6.2, z: 7.1, width: 3.0, depth: 2.4, height: 2.7,
color: 0xd09a55, roof: 0x5a5148, sign: 0xffd47d
});
createBuilding({
x: 11.5, z: 1.2, width: 2.4, depth: 2.2, height: 3.5,
color: 0xc56d69, roof: 0x714d50, sign: 0xff9890
});
createBuilding({
x: 8.8, z: -8.4, width: 3.1, depth: 2.8, height: 3.2,
color: 0x668bb0, roof: 0x42536b, sign: 0x9bd3ff
});
createBuilding({
x: 1.2, z: -10.4, width: 3.2, depth: 2.3, height: 3.0,
color: 0x9073b2, roof: 0x554b6c, sign: 0xd8baff
});
createBuilding({
x: -10.5, z: -7.6, width: 2.3, depth: 2.1, height: 2.2,
color: 0x6d9a68, roof: 0x4b604a, sign: 0xb7e9a9
});
createBuilding({
x: -12.5, z: 2.6, width: 3.0, depth: 2.6, height: 2.5,
color: 0xbe765c, roof: 0x5d4943, sign: 0xffb18e
});
createBuilding({
x: -9.8, z: 8.6, width: 2.8, depth: 2.2, height: 3.1,
color: 0x4f9f9b, roof: 0x3c6262, sign: 0x86eee2
});
// Small secondary buildings and market canopies.
createBuilding({
x: 9.0, z: 7.8, width: 1.5, depth: 1.5, height: 1.7,
color: 0xbc8a5f, roof: 0x4c5554
});
createBuilding({
x: -0.2, z: 7.6, width: 1.7, depth: 1.6, height: 1.8,
color: 0x728c92, roof: 0x46565b
});
function createTree(x, z, size = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
city.add(group);
addBox(group, 0.24 * size, 1.25 * size, 0.24 * size, 0x73503d,
0, BASE_Y + 0.62 * size, 0);
addBox(group, 1.1 * size, 0.9 * size, 1.1 * size, 0x477b53,
0, BASE_Y + 1.35 * size, 0);
addBox(group, 0.78 * size, 0.65 * size, 0.78 * size, 0x5f985e,
0.23 * size, BASE_Y + 1.78 * size, -0.12 * size);
}
let seed = 48123;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const treeLocations = [
[-15, -9], [-14, -6], [-14, 5], [-14, 9], [-6, 10],
[-4, -11], [4, -11], [13, -9], [14, -5], [14, 5],
[11, 9], [4, 10], [-3, 4], [4, 4], [4, -4], [-4, -4],
[-6, 2], [-6, -2], [6, 2], [6, -2], [1, 10],
[-11, -3], [12, 3], [-2, 10], [2, -11]
];
for (const [x, z] of treeLocations) {
createTree(x, z, 0.75 + random() * 0.42);
}
function createCar(x, z, color, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, BASE_Y, z);
group.rotation.y = rotation;
city.add(group);
addBox(group, 1.35, 0.38, 0.68, color, 0, 0.24, 0);
addBox(group, 0.62, 0.32, 0.58, 0x8db7bd, -0.15, 0.55, 0);
addBox(group, 0.28, 0.22, 0.7, 0x25353b, 0.48, 0.2, 0);
addBox(group, 0.28, 0.22, 0.7, 0x25353b, -0.48, 0.2, 0);
}
createCar(2.1, 1.1, 0xeaa14f, 0.12);
createCar(-2.3, -1.1, 0x73aee8, -0.1);
createCar(6.0, 4.0, 0xb86e5d, 1.48);
createCar(-7.8, -5.0, 0xd4c470, 0.7);
// Depot crates and striped loading bay.
for (let i = 0; i < 8; i++) {
addBox(
city, 0.52, 0.48, 0.52, i % 2 ? 0xb9874e : 0xc99858,
0.7 + (i % 3) * 0.56,
BASE_Y + 0.24 + Math.floor(i / 3) * 0.49,
-1.5 + Math.floor(i / 3) * 0.58
);
}
const van = new THREE.Group();
van.visible = false;
scene.add(van);
addBox(van, 1.55, 0.62, 0.82, 0xffa94d, 0, 0.42, 0);
addBox(van, 0.67, 0.58, 0.76, 0xe98737, 0.48, 0.49, 0);
addBox(van, 0.08, 0.34, 0.62, 0x9bd8dc, 0.82, 0.59, 0);
addBox(van, 1.2, 0.08, 0.84, 0xffe0a6, -0.15, 0.76, 0);
addBox(van, 0.32, 0.28, 0.88, 0x26343a, 0.48, 0.2, 0);
addBox(van, 0.32, 0.28, 0.88, 0x26343a, -0.48, 0.2, 0);
// ------------------------------------------------------------
// DOM markers
// ------------------------------------------------------------
const markerElements = new Map();
for (const stop of stops) {
const button = document.createElement("button");
button.type = "button";
button.className = "map-marker";
button.style.setProperty("--pin-color", stop.color);
button.setAttribute("aria-label", `Add ${stop.name} to route`);
button.innerHTML = `
<div class="marker-main">
<span class="marker-icon"></span>
<span class="marker-name">${stop.name}</span>
<span class="marker-order"></span>
</div>
<div class="marker-meta">
<span>${stop.people} homes</span>
<span>${stop.demand} crates</span>
</div>
`;
button.addEventListener("click", () => toggleStop(stop.id));
$("#labels").appendChild(button);
markerElements.set(stop.id, button);
}
const depotMarker = document.createElement("div");
depotMarker.className = "depot-marker";
depotMarker.textContent = "Relay depot";
$("#labels").appendChild(depotMarker);
const projectionVector = new THREE.Vector3();
function updateMarkerPositions() {
for (const stop of stops) {
const node = nodes[stop.node];
const element = markerElements.get(stop.id);
projectionVector.set(node.x, 5.15, node.z).project(camera);
const x = (projectionVector.x * 0.5 + 0.5) * $("#stage").clientWidth;
const y = (-projectionVector.y * 0.5 + 0.5) * $("#stage").clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.visibility =
projectionVector.x < -1.15 || projectionVector.x > 1.15 ||
projectionVector.y < -1.15 || projectionVector.y > 1.15
? "hidden"
: "visible";
}
projectionVector.set(0, 4.8, 0).project(camera);
depotMarker.style.left =
`${(projectionVector.x * 0.5 + 0.5) * $("#stage").clientWidth}px`;
depotMarker.style.top =
`${(-projectionVector.y * 0.5 + 0.5) * $("#stage").clientHeight}px`;
}
// ------------------------------------------------------------
// Route rendering
// ------------------------------------------------------------
function clearRouteGeometry() {
while (routeGroup.children.length) {
const child = routeGroup.children[0];
routeGroup.remove(child);
if (child.geometry) child.geometry.dispose();
}
}
function drawRoute() {
clearRouteGeometry();
if (!route.length) return;
const details = routeDetails();
const highlighted = new Set();
for (let i = 0; i < details.path.length - 1; i++) {
const fromId = details.path[i];
const toId = details.path[i + 1];
const key = [fromId, toId].sort((a, b) => a - b).join("-");
if (highlighted.has(key)) continue;
highlighted.add(key);
const from = nodes[fromId];
const to = nodes[toId];
const dx = to.x - from.x;
const dz = to.z - from.z;
const length = Math.hypot(dx, dz);
const segment = addBox(
routeGroup,
length,
0.12,
0.38,
0x55e0cc,
(from.x + to.x) / 2,
0.9,
(from.z + to.z) / 2,
0x1b746a
);
segment.rotation.y = -Math.atan2(dz, dx);
segment.castShadow = false;
}
for (const stop of route) {
const node = nodes[stop.node];
addBox(
routeGroup, 0.62, 0.62, 0.62, 0x8ff4e4,
node.x, 1.08, node.z, 0x1d7c70
);
}
}
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
function updatePriorityUI() {
const total = priority.coverage + priority.time + priority.supply;
const normalized = normalizedPriorities();
$("#coverageValue").innerHTML =
`${priority.coverage} <span>${Math.round(normalized.coverage * 100)}%</span>`;
$("#timeValue").innerHTML =
`${priority.time} <span>${Math.round(normalized.time * 100)}%</span>`;
$("#supplyValue").innerHTML =
`${priority.supply} <span>${Math.round(normalized.supply * 100)}%</span>`;
$("#mixCoverage").style.width = `${normalized.coverage * 100}%`;
$("#mixTime").style.width = `${normalized.time * 100}%`;
$("#mixSupply").style.width = `${normalized.supply * 100}%`;
const sliders = [
["#coverageRange", priority.coverage],
["#timeRange", priority.time],
["#supplyRange", priority.supply]
];
for (const [selector, value] of sliders) {
$(selector).style.background =
`linear-gradient(90deg, var(--range-color) ${value}%, #2a414c ${value}%)`;
}
let presetName = null;
for (const [name, values] of Object.entries(presets)) {
if (values[0] === priority.coverage &&
values[1] === priority.time &&
values[2] === priority.supply) {
presetName = name;
break;
}
}
document.querySelectorAll("[data-preset]").forEach((button) => {
button.classList.toggle("active", button.dataset.preset === presetName);
});
const sorted = [
{ name: "coverage", value: normalized.coverage },
{ name: "time", value: normalized.time },
{ name: "supply", value: normalized.supply }
].sort((a, b) => b.value - a.value);
const readout = $("#priorityReadout");
if (total === 0 || sorted[0].value - sorted[1].value < 0.08) {
readout.style.borderLeftColor = "var(--teal)";
readout.textContent =
"A balanced route: serve useful demand without creating a long or wasteful shift.";
} else if (sorted[0].name === "coverage") {
readout.style.borderLeftColor = "var(--teal)";
readout.textContent =
"Coverage is leading. The planner favors larger household groups, even when they consume more cargo.";
} else if (sorted[0].name === "time") {
readout.style.borderLeftColor = "var(--orange)";
readout.textContent =
"Travel time is leading. Urgent, nearby requests should enter the route before distant ones.";
} else {
readout.style.borderLeftColor = "var(--blue)";
readout.textContent =
"Supply reserve is leading. Smaller requests are favored, leaving more crates available in reserve.";
}
}
function updateRouteUI() {
const details = routeDetails();
const score = scoreFor(details);
$("#routeMeta").textContent = `${route.length} stop${route.length === 1 ? "" : "s"}`;
$("#statCoverage").textContent = details.people;
$("#statTime").textContent = details.time;
$("#statCargo").textContent = details.usedCargo;
$("#statScore").textContent = score.total;
$("#scoreValue").textContent = score.total;
$("#scoreFill").style.width = `${score.total}%`;
const capacityState = details.remaining <= 2
? "thin reserve"
: details.remaining <= 5
? "moderate reserve"
: "healthy reserve";
$("#capacityText").innerHTML =
`<strong>${details.remaining} crates spare.</strong> ` +
`${details.usedCargo} crates loaded; ${capacityState}. ` +
`Click a map pin to add or remove it.`;
if (!route.length) {
$("#routeList").innerHTML = `
<div class="empty-route">
No stops selected.<br />Auto-plan a route or click a district pin.
</div>
`;
} else {
let current = 0;
$("#routeList").innerHTML = route.map((stop, index) => {
const leg = shortestPath(current, stop.node);
current = stop.node;
return `
<div class="route-card">
<div class="route-number" style="--stop-color: ${stop.color}">
${index + 1}
</div>
<div>
<h3>${stop.name}</h3>
<p>${stop.people} homes · ${stop.demand} crates · ${leg.time} min leg</p>
</div>
<div class="route-actions">
<button class="mini-button" type="button" data-move="-1"
data-index="${index}" ${index === 0 ? "disabled" : ""}
aria-label="Move ${stop.name} earlier">↑</button>
<button class="mini-button" type="button" data-move="1"
data-index="${index}" ${index === route.length - 1 ? "disabled" : ""}
aria-label="Move ${stop.name} later">↓</button>
<button class="mini-button remove" type="button" data-remove="${stop.id}"
aria-label="Remove ${stop.name}">×</button>
</div>
</div>
`;
}).join("");
}
for (const stop of stops) {
const element = markerElements.get(stop.id);
const selectedIndex = route.findIndex((item) => item.id === stop.id);
const order = element.querySelector(".marker-order");
element.classList.toggle("selected", selectedIndex !== -1);
element.classList.toggle("muted", route.length > 0 && selectedIndex === -1);
order.textContent = selectedIndex === -1 ? "" : selectedIndex + 1;
element.setAttribute(
"aria-label",
selectedIndex === -1
? `Add ${stop.name} to route`
: `Remove ${stop.name} from route`
);
}
$("#dispatchBtn").disabled = !route.length || dispatching;
drawRoute();
updateComparison();
}
function updateComparison() {
const variants = [
{
name: "Reach first",
note: "Coverage-only plan",
weights: { coverage: 1, time: 0, supply: 0 },
color: "#55e0cc",
type: "coverage"
},
{
name: "Time first",
note: "Travel-time-only plan",
weights: { coverage: 0, time: 1, supply: 0 },
color: "#ffad5a",
type: "time"
},
{
name: "Stock first",
note: "Supply-only plan",
weights: { coverage: 0, time: 0, supply: 1 },
color: "#73aee8",
type: "supply"
}
];
const current = routeDetails();
const currentScore = scoreFor(current);
const currentRow = `
<div class="comparison-row current"
style="--bar-width: ${currentScore.total}%; --bar-color: #55e0cc">
<div class="comparison-title">
Your current mix
<span>${currentScore.total} score</span>
</div>
<p>
${current.people} homes · ${current.time} min · ${current.remaining} spare crates
</p>
</div>
`;
const rows = variants.map((variant) => {
const plannedRoute = planFor(variant.weights);
const metrics = routeDetails(plannedRoute);
const coverage = metrics.people / TOTAL_PEOPLE * 100;
let width = coverage;
if (variant.type === "time") {
width = Math.max(0, 100 - metrics.time * 2);
} else if (variant.type === "supply") {
width = metrics.remaining / TOTAL_CARGO * 100;
}
return `
<div class="comparison-row"
style="--bar-width: ${width}%; --bar-color: ${variant.color}">
<div class="comparison-title">
${variant.name}
<span>${variant.note}</span>
</div>
<p>
${metrics.people} homes · ${metrics.time} min · ${metrics.remaining} spare crates
</p>
</div>
`;
}).join("");
$("#comparison").innerHTML = currentRow + rows;
}
function autoPlan(message = "Route generated from the current priority mix.") {
route = planFor(normalizedPriorities());
updatePriorityUI();
updateRouteUI();
$("#logText").innerHTML = `<strong>Dispatch desk:</strong> ${message}`;
}
function toggleStop(id) {
const existingIndex = route.findIndex((stop) => stop.id === id);
const stop = stops.find((item) => item.id === id);
if (existingIndex !== -1) {
route.splice(existingIndex, 1);
$("#logText").innerHTML =
`<strong>Dispatch desk:</strong> ${stop.name} removed from the route.`;
} else {
const used = routeDetails().usedCargo;
if (used + stop.demand > TOTAL_CARGO) {
showToast(
`Not enough crates. ${stop.name} needs ${stop.demand}; only ` +
`${TOTAL_CARGO - used} remain.`
);
return;
}
route.push(stop);
$("#logText").innerHTML =
`<strong>Dispatch desk:</strong> ${stop.name} added at stop ${route.length}.`;
}
updateRouteUI();
}
function moveStop(index, direction) {
const target = index + direction;
if (target < 0 || target >= route.length) return;
const [item] = route.splice(index, 1);
route.splice(target, 0, item);
updateRouteUI();
}
function showToast(message) {
clearTimeout(toastTimer);
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 2800);
}
// ------------------------------------------------------------
// Dispatch animation
// ------------------------------------------------------------
function prepareDispatchSegments(path) {
dispatchSegments = [];
dispatchTotalDistance = 0;
for (let i = 0; i < path.length - 1; i++) {
const from = nodes[path[i]];
const to = nodes[path[i + 1]];
const dx = to.x - from.x;
const dz = to.z - from.z;
const distance = Math.hypot(dx, dz);
dispatchSegments.push({
from,
to,
distance,
startDistance: dispatchTotalDistance
});
dispatchTotalDistance += distance;
}
}
function beginDispatch() {
if (!route.length || dispatching) return;
const details = routeDetails();
dispatching = true;
dispatchClock = 0;
dispatchDuration = Math.max(2.8, Math.min(6, details.time * 0.18));
prepareDispatchSegments(details.path);
van.visible = true;
van.position.set(0, 1.08, 0);
$("#dispatchBtn").disabled = true;
$("#dispatchBtn").textContent = "Delivering…";
$("#logText").innerHTML =
`<strong>Dispatch desk:</strong> Courier dispatched with ${details.usedCargo} crates.`;
}
function updateDispatch(delta) {
if (!dispatching) return;
dispatchClock += delta;
const progress = Math.min(1, dispatchClock / dispatchDuration);
const targetDistance = progress * dispatchTotalDistance;
let segment = dispatchSegments[dispatchSegments.length - 1];
for (const candidate of dispatchSegments) {
if (targetDistance <= candidate.startDistance + candidate.distance) {
segment = candidate;
break;
}
}
const localDistance = Math.max(
0,
Math.min(segment.distance, targetDistance - segment.startDistance)
);
const ratio = segment.distance > 0 ? localDistance / segment.distance : 0;
const x = segment.from.x + (segment.to.x - segment.from.x) * ratio;
const z = segment.from.z + (segment.to.z - segment.from.z) * ratio;
const dx = segment.to.x - segment.from.x;
const dz = segment.to.z - segment.from.z;
van.position.set(x, 1.08 + Math.sin(progress * Math.PI * 24) * 0.025, z);
van.rotation.y = -Math.atan2(dz, dx);
if (progress >= 1) {
completeDispatch();
}
}
function completeDispatch() {
dispatching = false;
const details = routeDetails();
const score = scoreFor(details);
const weights = normalizedPriorities();
$("#dispatchBtn").disabled = false;
$("#dispatchBtn").textContent = "Dispatch again";
$("#resultScore").textContent = score.total;
$("#resultCoverage").textContent = `${details.people} / ${TOTAL_PEOPLE}`;
$("#resultTime").textContent = `${details.time} min`;
$("#resultCargo").textContent = `${details.remaining} crates`;
let title = "Route delivered";
let narrative = "";
if (details.time > TARGET_TIME) {
title = "Delivered, but late";
narrative =
`The route reached ${details.people} households in ${details.time} minutes, ` +
`missing the ${TARGET_TIME}-minute target. Your time-weighted score lost ` +
`${Math.round(score.time === 0 ? 100 : 100 - score.time)} points.`;
} else if (details.remaining <= 2) {
title = "Delivered on a thin margin";
narrative =
`The courier completed the run on time, but only ${details.remaining} crates ` +
`remain in reserve. A supply-led plan may protect more stock.`;
} else if (weights.coverage > 0.5) {
title = "Broad reach achieved";
narrative =
`The route reached ${details.people} households and preserved ${details.remaining} ` +
`crates. Coverage was the main strength of this run.`;
} else if (weights.time > 0.5) {
title = "Fast relief delivered";
narrative =
`The run completed in ${details.time} minutes and reached ${details.people} ` +
`households with ${details.remaining} crates to spare.`;
} else if (weights.supply > 0.5) {
title = "Efficient delivery completed";
narrative =
`The route reached ${details.people} households while keeping ${details.remaining} ` +
`crates available for a later run.`;
} else {
title = "Balanced shift complete";
narrative =
`The route reached ${details.people} households in ${details.time} minutes and ` +
`kept ${details.remaining} crates in reserve.`;
}
$("#resultTitle").textContent = title;
$("#resultNarrative").textContent = narrative;
$("#modal").classList.add("show");
$("#logText").innerHTML =
`<strong>Dispatch desk:</strong> Delivery complete. Weighted score ${score.total}/100.`;
spawnConfetti(details.path[Math.floor(details.path.length / 2)]);
}
const confetti = [];
function spawnConfetti(nodeIndex) {
const node = nodes[nodeIndex] || nodes[0];
const colors = [0x55e0cc, 0xffad5a, 0x73aee8, 0xf3d66b];
for (let i = 0; i < 28; i++) {
const color = colors[i % colors.length];
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.18, 0.18),
getMaterial(color)
);
mesh.position.set(
node.x + (Math.random() - 0.5) * 1.4,
2.2 + Math.random() * 1.4,
node.z + (Math.random() - 0.5) * 1.4
);
confettiGroup.add(mesh);
confetti.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 3.5,
2 + Math.random() * 3,
(Math.random() - 0.5) * 3.5
),
life: 2.4
});
}
}
function updateConfetti(delta) {
for (let i = confetti.length - 1; i >= 0; i--) {
const particle = confetti[i];
particle.life -= delta;
particle.velocity.y -= 6 * delta;
particle.mesh.position.addScaledVector(particle.velocity, delta);
particle.mesh.rotation.x += delta * 4;
particle.mesh.rotation.y += delta * 3;
if (particle.life <= 0) {
confettiGroup.remove(particle.mesh);
particle.mesh.geometry.dispose();
confetti.splice(i, 1);
}
}
}
// ------------------------------------------------------------
// Events
// ------------------------------------------------------------
$("#coverageRange").addEventListener("input", (event) => {
priority.coverage = Number(event.target.value);
autoPlan("Coverage adjusted. Route re-planned.");
});
$("#timeRange").addEventListener("input", (event) => {
priority.time = Number(event.target.value);
autoPlan("Travel-time priority adjusted. Route re-planned.");
});
$("#supplyRange").addEventListener("input", (event) => {
priority.supply = Number(event.target.value);
autoPlan("Supply reserve adjusted. Route re-planned.");
});
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const values = presets[button.dataset.preset];
priority.coverage = values[0];
priority.time = values[1];
priority.supply = values[2];
$("#coverageRange").value = priority.coverage;
$("#timeRange").value = priority.time;
$("#supplyRange").value = priority.supply;
autoPlan(`${button.querySelector("strong").textContent} mix applied.`);
});
});
$("#autoPlan").addEventListener("click", () => {
autoPlan("Priority-aware route generated.");
});
$("#routeList").addEventListener("click", (event) => {
const moveButton = event.target.closest("[data-move]");
const removeButton = event.target.closest("[data-remove]");
if (moveButton) {
moveStop(Number(moveButton.dataset.index), Number(moveButton.dataset.move));
}
if (removeButton) {
toggleStop(removeButton.dataset.remove);
}
});
$("#dispatchBtn").addEventListener("click", beginDispatch);
$("#resultDone").addEventListener("click", () => {
$("#modal").classList.remove("show");
});
$("#resetBtn").addEventListener("click", () => {
route = [];
priority.coverage = 45;
priority.time = 30;
priority.supply = 25;
$("#coverageRange").value = priority.coverage;
$("#timeRange").value = priority.time;
$("#supplyRange").value = priority.supply;
$("#modal").classList.remove("show");
van.visible = false;
autoPlan("Shift reset. Balanced route generated.");
});
// Direct camera controls implemented without Three.js addons.
let pointerDown = false;
let pointerMoved = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
cameraTarget.x -= dx * 0.024;
cameraTarget.z -= dy * 0.024;
pointerX = event.clientX;
pointerY = event.clientY;
});
function endPointer(event) {
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * (event.deltaY > 0 ? 0.92 : 1.08),
0.65,
1.8
);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
function resize() {
const width = $("#canvasHost").clientWidth;
const height = $("#canvasHost").clientHeight;
const aspect = width / Math.max(height, 1);
const view = Math.max(23, 32 / aspect);
renderer.setSize(width, height, false);
camera.left = -view * aspect / 2;
camera.right = view * aspect / 2;
camera.top = view / 2;
camera.bottom = -view / 2;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------
// Start
// ------------------------------------------------------------
resize();
autoPlan("Balanced route generated.");
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
updateDispatch(delta);
updateConfetti(delta);
updateMarkerPositions();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```