Prompt specification
Build or customize the Three.js 3D scene "Mutual Aid Route Under a Closed Street" 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: Mutual Aid Route Under a Closed Street
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mutual-aid-route-under-a-closed-street-x3236
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing mutual aid matched to confirmed community needs. Create a delivery network with capacity limits and a blocked connection. Replan requested deliveries while tracking consent status, arrival time, and unmet requests separately. Low-poly.
Working Three.js Starter (mutual-aid-route-under-a-closed-street-x3236):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Ground — Mutual Aid Relay</title>
<style>
:root {
--ink: #20332e;
--muted: #71807b;
--line: #e2e8e3;
--paper: #ffffff;
--canvas: #f3f2ec;
--green: #2d766a;
--green-dark: #1e554d;
--green-soft: #e5f1ed;
--coral: #df684f;
--coral-soft: #fbe9e4;
--amber: #d39a35;
--amber-soft: #fbf1d9;
--blue: #327ca8;
--blue-soft: #e5f1f8;
--shadow: 0 10px 35px rgba(31, 55, 47, 0.08);
}
* {
box-sizing: border-box;
}
html, body {
margin: 0;
min-height: 100%;
background: var(--canvas);
color: var(--ink);
font-family:
Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
sans-serif;
}
button, input {
font: inherit;
}
button {
cursor: pointer;
}
.app {
display: grid;
grid-template-rows: 68px minmax(430px, 1fr) 196px;
min-height: 760px;
height: 100vh;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 22px;
background: rgba(255, 255, 255, 0.94);
border-bottom: 1px solid var(--line);
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
}
.brand-mark {
display: grid;
place-items: center;
width: 36px;
height: 36px;
border-radius: 11px;
background: var(--green-dark);
color: white;
}
.brand-mark svg {
width: 23px;
height: 23px;
}
.brand-name {
font-weight: 800;
letter-spacing: -0.02em;
font-size: 17px;
}
.brand-name span {
color: var(--muted);
font-weight: 500;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
}
.live-pill,
.network-pill {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 31px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: white;
color: var(--muted);
font-size: 12px;
font-weight: 650;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #47a67d;
box-shadow: 0 0 0 4px #e5f5ed;
}
.network-pill strong {
color: var(--ink);
}
.primary,
.secondary,
.danger,
.quiet {
border-radius: 9px;
min-height: 36px;
padding: 0 13px;
border: 1px solid transparent;
font-size: 12px;
font-weight: 750;
transition:
transform 120ms ease,
background 120ms ease,
opacity 120ms ease;
}
.primary {
color: white;
background: var(--green-dark);
}
.primary:hover {
background: var(--green);
transform: translateY(-1px);
}
.secondary {
color: var(--ink);
background: white;
border-color: var(--line);
}
.secondary:hover {
background: #f5f8f6;
}
.danger {
color: var(--coral);
background: var(--coral-soft);
border-color: #f2d3ca;
}
.quiet {
color: var(--muted);
background: transparent;
}
button:disabled {
opacity: 0.42;
cursor: not-allowed;
transform: none !important;
}
.workspace {
display: grid;
grid-template-columns: 300px minmax(440px, 1fr) 330px;
gap: 12px;
min-height: 0;
padding: 12px 16px;
}
.panel {
background: var(--paper);
border: 1px solid var(--line);
border-radius: 15px;
box-shadow: var(--shadow);
min-width: 0;
min-height: 0;
}
.requests-panel,
.operations-panel {
display: flex;
flex-direction: column;
overflow: hidden;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
padding: 17px 17px 12px;
}
.eyebrow {
margin-bottom: 4px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
h1, h2, h3, p {
margin: 0;
}
h2 {
font-size: 16px;
letter-spacing: -0.02em;
}
.count-badge {
display: grid;
place-items: center;
min-width: 25px;
height: 25px;
padding: 0 7px;
border-radius: 8px;
background: #f0f3f1;
color: var(--muted);
font-size: 11px;
font-weight: 800;
}
.search-wrap {
padding: 0 14px 11px;
}
.search-wrap input {
width: 100%;
height: 36px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 9px;
outline: none;
color: var(--ink);
background: #f9faf9;
font-size: 12px;
}
.search-wrap input:focus {
border-color: #91b8ae;
box-shadow: 0 0 0 3px #e7f1ee;
}
.filter-tabs {
display: flex;
gap: 5px;
padding: 0 14px 12px;
overflow-x: auto;
}
.filter-tab {
flex: 0 0 auto;
height: 29px;
padding: 0 9px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.filter-tab.active {
color: var(--green-dark);
background: var(--green-soft);
border-color: #d3e6df;
}
.request-list {
min-height: 0;
overflow-y: auto;
padding: 0 10px 14px;
}
.request-card {
position: relative;
margin-bottom: 8px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: white;
transition:
border-color 120ms ease,
box-shadow 120ms ease,
transform 120ms ease;
}
.request-card:hover {
border-color: #bdd2ca;
transform: translateY(-1px);
}
.request-card.selected {
border-color: #6ea294;
background: #f7fbf9;
box-shadow: inset 3px 0 0 var(--green);
}
.request-top,
.request-bottom,
.card-title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.request-id {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
}
.priority {
padding: 3px 6px;
border-radius: 5px;
color: var(--muted);
background: #f1f3f2;
font-size: 9px;
font-weight: 850;
text-transform: uppercase;
}
.priority.urgent {
color: #b34b37;
background: var(--coral-soft);
}
.card-title-row {
justify-content: flex-start;
margin: 8px 0 9px;
}
.request-title {
font-size: 13px;
font-weight: 780;
line-height: 1.3;
}
.route-line {
display: flex;
align-items: center;
gap: 5px;
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
}
.route-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--green);
}
.route-line .arrow {
color: #a6b2ad;
}
.chip {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 4px 6px;
border-radius: 6px;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.chip.verified {
color: #2b735c;
background: var(--green-soft);
}
.chip.pending {
color: #9a6c17;
background: var(--amber-soft);
}
.chip.declined {
color: #747f7b;
background: #eef1ef;
}
.chip.planned {
color: #2d6f65;
background: var(--green-soft);
}
.chip.transit {
color: #2b7099;
background: var(--blue-soft);
}
.chip.unmet {
color: #b6543f;
background: var(--coral-soft);
}
.eta-small {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.empty-state {
padding: 30px 16px;
text-align: center;
color: var(--muted);
font-size: 12px;
}
.map-panel {
position: relative;
overflow: hidden;
background: #dce5df;
}
#scene,
#mapLabels {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#mapLabels {
pointer-events: none;
z-index: 4;
}
.map-head {
position: absolute;
top: 16px;
left: 16px;
z-index: 7;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 12px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 8px 25px rgba(40, 60, 52, 0.1);
backdrop-filter: blur(10px);
}
.map-head h2 {
margin-bottom: 3px;
}
.map-head p {
color: var(--muted);
font-size: 10px;
}
.map-stats {
position: absolute;
top: 16px;
right: 16px;
z-index: 7;
display: flex;
gap: 7px;
}
.map-stat {
min-width: 72px;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 11px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 8px 25px rgba(40, 60, 52, 0.08);
backdrop-filter: blur(10px);
}
.map-stat strong {
display: block;
margin-bottom: 2px;
font-size: 17px;
}
.map-stat span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.map-label {
position: absolute;
z-index: 5;
min-width: 85px;
padding: 6px 8px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 8px;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 5px 15px rgba(41, 59, 52, 0.12);
text-align: center;
backdrop-filter: blur(6px);
}
.map-label strong,
.map-label span {
display: block;
}
.map-label strong {
font-size: 10px;
}
.map-label span {
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
}
.map-tools {
position: absolute;
right: 15px;
bottom: 15px;
z-index: 8;
display: flex;
gap: 5px;
padding: 5px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 11px;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 8px 25px rgba(40, 60, 52, 0.12);
}
.map-tool {
display: grid;
place-items: center;
width: 31px;
height: 31px;
border: 0;
border-radius: 7px;
color: var(--ink);
background: transparent;
font-size: 17px;
font-weight: 700;
}
.map-tool:hover {
background: #edf2ef;
}
.map-legend {
position: absolute;
left: 15px;
bottom: 15px;
z-index: 7;
display: flex;
gap: 11px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 9px;
background: rgba(255, 255, 255, 0.87);
color: var(--muted);
font-size: 9px;
font-weight: 750;
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.operations-panel {
overflow-y: auto;
}
.operations-inner {
padding-bottom: 14px;
}
.planner {
padding: 0 16px 16px;
border-bottom: 1px solid var(--line);
}
.planner .panel-heading {
padding-left: 0;
padding-right: 0;
}
.planner-card {
padding: 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fbfcfb;
}
.planner-title {
font-size: 14px;
font-weight: 800;
line-height: 1.35;
}
.planner-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin: 8px 0 12px;
}
.planner-route {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
}
.planner-route strong {
color: var(--ink);
}
.route-track {
position: relative;
display: flex;
justify-content: space-between;
margin: 8px 0 11px;
}
.route-track::before {
position: absolute;
top: 5px;
right: 7px;
left: 7px;
height: 2px;
background: #cddbd6;
content: "";
}
.route-stop {
position: relative;
z-index: 1;
max-width: 43%;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.route-stop:last-child {
text-align: right;
}
.route-stop-dot {
width: 11px;
height: 11px;
margin-bottom: 5px;
border: 3px solid white;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 1px #9dbbb1;
}
.route-stop:last-child .route-stop-dot {
margin-left: auto;
}
.planner-facts {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.fact {
padding: 8px;
border-radius: 8px;
background: white;
border: 1px solid #e8ece9;
}
.fact span,
.fact strong {
display: block;
}
.fact span {
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
text-transform: uppercase;
}
.fact strong {
font-size: 11px;
}
.planner-note {
margin-top: 9px;
padding: 9px;
border-radius: 8px;
color: var(--muted);
background: #f0f3f1;
font-size: 10px;
line-height: 1.45;
}
.planner-actions {
display: flex;
gap: 6px;
margin-top: 10px;
}
.planner-actions button {
flex: 1;
padding: 0 8px;
}
.resource-section {
padding: 16px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.section-title h3 {
font-size: 12px;
font-weight: 800;
}
.section-title span {
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
.resource-row {
margin-bottom: 12px;
}
.resource-label {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
font-size: 10px;
}
.resource-label strong {
font-size: 10px;
}
.resource-label span {
color: var(--muted);
font-weight: 700;
}
.capacity-bar {
height: 6px;
overflow: hidden;
border-radius: 99px;
background: #e9eeeb;
}
.capacity-bar i {
display: block;
height: 100%;
border-radius: inherit;
background: var(--green);
}
.capacity-bar i.near {
background: var(--amber);
}
.capacity-bar i.full {
background: var(--coral);
}
.resource-divider {
height: 1px;
margin: 14px 0;
background: var(--line);
}
.courier-row {
display: grid;
grid-template-columns: 28px 1fr auto;
align-items: center;
gap: 9px;
margin-bottom: 10px;
}
.courier-icon {
display: grid;
place-items: center;
width: 28px;
height: 28px;
border-radius: 8px;
color: var(--green-dark);
background: var(--green-soft);
font-size: 13px;
}
.courier-name {
font-size: 10px;
font-weight: 800;
}
.courier-sub {
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.courier-load {
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.connection-card {
margin: 0 16px 16px;
padding: 12px;
border: 1px solid #efd6cf;
border-radius: 11px;
background: #fff9f7;
}
.connection-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 7px;
}
.connection-top strong {
font-size: 11px;
}
.connection-status {
padding: 3px 6px;
border-radius: 5px;
color: #a84c3a;
background: var(--coral-soft);
font-size: 8px;
font-weight: 850;
text-transform: uppercase;
}
.connection-status.open {
color: var(--green-dark);
background: var(--green-soft);
}
.connection-card p {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.connection-card button {
width: 100%;
}
.trackers {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
min-height: 0;
padding: 0 16px 14px;
}
.tracker {
min-width: 0;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 13px;
background: white;
box-shadow: var(--shadow);
}
.tracker-header {
display: flex;
align-items: center;
justify-content: space-between;
height: 46px;
padding: 0 14px;
border-bottom: 1px solid var(--line);
}
.tracker-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 850;
}
.tracker-icon {
display: grid;
place-items: center;
width: 23px;
height: 23px;
border-radius: 7px;
font-size: 11px;
}
.tracker-icon.green {
color: var(--green-dark);
background: var(--green-soft);
}
.tracker-icon.blue {
color: var(--blue);
background: var(--blue-soft);
}
.tracker-icon.coral {
color: var(--coral);
background: var(--coral-soft);
}
.tracker-summary {
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
.tracker-list {
height: calc(100% - 46px);
overflow-y: auto;
padding: 6px 10px 10px;
}
.tracker-row {
display: grid;
grid-template-columns: minmax(80px, 1fr) auto;
align-items: center;
gap: 10px;
min-height: 40px;
padding: 6px;
border-bottom: 1px solid #f0f2f1;
cursor: pointer;
border-radius: 7px;
}
.tracker-row:hover {
background: #f7f9f8;
}
.tracker-row:last-child {
border-bottom: 0;
}
.tracker-main {
min-width: 0;
}
.tracker-main strong {
display: block;
overflow: hidden;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.tracker-main span {
display: block;
overflow: hidden;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
text-overflow: ellipsis;
white-space: nowrap;
}
.tracker-value {
color: var(--ink);
font-size: 10px;
font-weight: 850;
text-align: right;
}
.tracker-value small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 600;
}
.toast {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 100;
max-width: 480px;
padding: 12px 16px;
transform: translate(-50%, 18px);
border-radius: 10px;
color: white;
background: #203b33;
box-shadow: 0 12px 35px rgba(19, 36, 30, 0.25);
opacity: 0;
pointer-events: none;
font-size: 11px;
font-weight: 700;
transition:
opacity 180ms ease,
transform 180ms ease;
}
.toast.show {
transform: translate(-50%, 0);
opacity: 1;
}
@media (max-width: 1180px) {
.workspace {
grid-template-columns: 270px minmax(390px, 1fr) 300px;
}
.map-stats {
top: auto;
right: 15px;
bottom: 59px;
flex-direction: column;
}
.map-stat {
min-width: 95px;
padding: 6px 8px;
}
.map-stat strong {
font-size: 13px;
}
}
@media (max-width: 900px) {
.app {
display: block;
height: auto;
}
.topbar {
position: sticky;
top: 0;
}
.workspace {
grid-template-columns: 1fr;
}
.requests-panel {
max-height: 460px;
}
.map-panel {
height: 560px;
}
.operations-panel {
max-height: none;
}
.trackers {
grid-template-columns: 1fr;
height: 600px;
}
.tracker {
min-height: 190px;
}
.network-pill {
display: none;
}
}
@media (max-width: 560px) {
.brand-name span,
#clock {
display: none;
}
.workspace {
padding: 8px;
}
.map-head {
top: 10px;
left: 10px;
}
.map-stats {
display: none;
}
.map-legend {
display: none;
}
.trackers {
padding: 0 8px 10px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M5 18V9l7-5 7 5v9" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
<path d="M9 18v-6h6v6M3 18h18" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</div>
<div class="brand-name">Common Ground <span>/ Mutual Aid Relay</span></div>
</div>
<div class="top-actions">
<div class="live-pill"><i class="live-dot"></i> Live network</div>
<div class="network-pill" id="networkSummary">4 active deliveries</div>
<span id="clock" style="font-size:11px;color:#71807b;font-weight:700"></span>
<button class="primary" id="replanAllBtn">Replan network</button>
</div>
</header>
<main class="workspace">
<aside class="panel requests-panel">
<div class="panel-heading">
<div>
<div class="eyebrow">Community queue</div>
<h2>Confirmed requests</h2>
</div>
<span class="count-badge" id="requestCount">7</span>
</div>
<div class="search-wrap">
<input id="searchInput" type="search" placeholder="Search need, location, or ID" />
</div>
<div class="filter-tabs" id="filterTabs">
<button class="filter-tab active" data-filter="all">All</button>
<button class="filter-tab" data-filter="ready">Ready</button>
<button class="filter-tab" data-filter="consent">Consent due</button>
<button class="filter-tab" data-filter="unmet">Unmet</button>
</div>
<div class="request-list" id="requestList"></div>
</aside>
<section class="panel map-panel" id="mapPanel">
<div id="scene"></div>
<div id="mapLabels"></div>
<div class="map-head">
<div class="eyebrow">Low-poly service map</div>
<h2>Riverside mutual aid network</h2>
<p>Drag to rotate · scroll to zoom · select a request pin</p>
</div>
<div class="map-stats">
<div class="map-stat">
<strong id="mapActive">4</strong>
<span>ACTIVE ROUTES</span>
</div>
<div class="map-stat">
<strong id="mapUnmet">3</strong>
<span>UNMET REQUESTS</span>
</div>
</div>
<div class="map-legend">
<div class="legend-item"><i class="legend-dot" style="background:#2d766a"></i>Planned</div>
<div class="legend-item"><i class="legend-dot" style="background:#327ca8"></i>In transit</div>
<div class="legend-item"><i class="legend-dot" style="background:#df684f"></i>Unmet</div>
</div>
<div class="map-tools">
<button class="map-tool" id="zoomOutBtn" aria-label="Zoom out">−</button>
<button class="map-tool" id="zoomInBtn" aria-label="Zoom in">+</button>
<button class="map-tool" id="homeBtn" aria-label="Reset camera">⌂</button>
</div>
</section>
<aside class="panel operations-panel">
<div class="operations-inner">
<section class="planner">
<div class="panel-heading">
<div>
<div class="eyebrow">Coordinator view</div>
<h2>Relay planner</h2>
</div>
<span class="count-badge" id="selectedBadge">—</span>
</div>
<div id="plannerBody"></div>
<div class="planner-actions">
<button class="secondary" id="consentAction" hidden>Confirm consent</button>
<button class="secondary" id="releaseSelected">Release</button>
<button class="primary" id="replanSelected">Replan route</button>
</div>
</section>
<section class="resource-section">
<div class="section-title">
<h3>Hub capacity</h3>
<span>USED / MAX</span>
</div>
<div id="hubCapacity"></div>
<div class="resource-divider"></div>
<div class="section-title">
<h3>Courier capacity</h3>
<span>LOAD UNITS</span>
</div>
<div id="courierCapacity"></div>
</section>
<section class="connection-card">
<div class="connection-top">
<strong>Commons ↔ East Pantry</strong>
<span class="connection-status" id="connectionStatus">Blocked</span>
</div>
<p id="connectionDescription">
The eastern connection is unavailable. Pantry requests cannot reach the western network.
</p>
<button class="danger" id="toggleBlockBtn">Simulate blocked connection</button>
</section>
</div>
</aside>
</main>
<section class="trackers">
<div class="tracker">
<div class="tracker-header">
<div class="tracker-title">
<span class="tracker-icon green">✓</span>
Consent watch
</div>
<span class="tracker-summary" id="consentSummary"></span>
</div>
<div class="tracker-list" id="consentTracker"></div>
</div>
<div class="tracker">
<div class="tracker-header">
<div class="tracker-title">
<span class="tracker-icon blue">◷</span>
Arrival tracker
</div>
<span class="tracker-summary" id="arrivalSummary"></span>
</div>
<div class="tracker-list" id="arrivalTracker"></div>
</div>
<div class="tracker">
<div class="tracker-header">
<div class="tracker-title">
<span class="tracker-icon coral">!</span>
Unmet requests
</div>
<span class="tracker-summary" id="unmetSummary"></span>
</div>
<div class="tracker-list" id="unmetTracker"></div>
</div>
</section>
</div>
<div class="toast" id="toast"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const COLORS = {
planned: 0x2d766a,
transit: 0x327ca8,
unmet: 0xdf684f,
pending: 0xd39a35,
selected: 0xf0b84b
};
const locations = {
commons: {
name: "Common Ground",
short: "Commons",
pos: new THREE.Vector3(0, 0, 0),
capacity: 8,
baseUsed: 4
},
clinic: {
name: "Northside Clinic",
short: "Clinic",
pos: new THREE.Vector3(-5.2, 0, 3.3),
capacity: 6,
baseUsed: 3
},
pantry: {
name: "East Pantry",
short: "Pantry",
pos: new THREE.Vector3(5.4, 0, 2.5),
capacity: 4,
baseUsed: 4
},
library: {
name: "River Library",
short: "Library",
pos: new THREE.Vector3(1.5, 0, -4.4),
capacity: 5,
baseUsed: 2
},
shelter: {
name: "South Shelter",
short: "Shelter",
pos: new THREE.Vector3(-4.3, 0, -4.1),
capacity: 6,
baseUsed: 2
}
};
const edges = [
{ a: "commons", b: "clinic", blocked: false },
{ a: "commons", b: "pantry", blocked: true },
{ a: "commons", b: "library", blocked: false },
{ a: "clinic", b: "shelter", blocked: false },
{ a: "shelter", b: "library", blocked: false }
];
const couriers = [
{
id: "bike",
name: "Bike 01",
type: "E-bike",
capacity: 3,
baseLoad: 1,
color: 0x2d766a
},
{
id: "van",
name: "Van 02",
type: "Community van",
capacity: 6,
baseLoad: 3,
color: 0x327ca8
},
{
id: "cargo",
name: "Cargo Trike",
type: "Cargo trike",
capacity: 4,
baseLoad: 1,
color: 0xd39a35
}
];
const requests = [
{
id: "MA-104",
title: "Insulin cold packs",
from: "clinic",
to: "library",
consent: "verified",
status: "planned",
priority: "Urgent",
weight: 1,
due: "Today, 14:30",
notes: "Keep medication below 8°C. Recipient consent is verified.",
courier: null,
route: [],
eta: null,
reason: "",
progress: 0
},
{
id: "MA-108",
title: "Dialysis supply kits",
from: "shelter",
to: "commons",
consent: "verified",
status: "in-transit",
priority: "High",
weight: 2,
due: "Today, 13:45",
notes: "Two units. Call the shelter desk before arrival.",
courier: null,
route: [],
eta: null,
reason: "",
progress: 0.66
},
{
id: "MA-111",
title: "Baby formula",
from: "pantry",
to: "shelter",
consent: "pending",
status: "unmet",
priority: "Standard",
weight: 1,
due: "Today, 16:00",
notes: "Recipient must confirm acceptance before dispatch.",
courier: null,
route: [],
eta: null,
reason: "Consent awaiting verification",
progress: 0
},
{
id: "MA-113",
title: "Reading and literacy kits",
from: "library",
to: "commons",
consent: "verified",
status: "planned",
priority: "Standard",
weight: 1,
due: "Today, 17:00",
notes: "Six boxed kits. Loading available at the library entrance.",
courier: null,
route: [],
eta: null,
reason: "",
progress: 0.18
},
{
id: "MA-117",
title: "Hot meal trays",
from: "pantry",
to: "clinic",
consent: "verified",
status: "unmet",
priority: "Urgent",
weight: 1,
due: "Today, 13:30",
notes: "Four meal trays. Volunteer pickup at the pantry loading door.",
courier: null,
route: [],
eta: null,
reason: "No open route · Commons ↔ East Pantry is blocked",
progress: 0
},
{
id: "MA-120",
title: "Wheelchair ramp kit",
from: "clinic",
to: "shelter",
consent: "verified",
status: "planned",
priority: "High",
weight: 1,
due: "Today, 15:30",
notes: "Two-person lift required. Shelter staff will meet the courier.",
courier: null,
route: [],
eta: null,
reason: "",
progress: 0.14
},
{
id: "MA-122",
title: "Prescription bag refill",
from: "library",
to: "pantry",
consent: "verified",
status: "unmet",
priority: "Standard",
weight: 1,
due: "Today, 18:00",
notes: "Transfer to East Pantry medication shelf.",
courier: null,
route: [],
eta: null,
reason: "East Pantry at capacity (4/4)",
progress: 0
}
];
let selectedId = "MA-104";
let activeFilter = "all";
let searchTerm = "";
let toastTimer;
const byId = id => document.getElementById(id);
const selectedRequest = () => requests.find(r => r.id === selectedId);
function edgeKey(a, b) {
return [a, b].sort().join("--");
}
function getEdge(a, b) {
return edges.find(e =>
(e.a === a && e.b === b) || (e.a === b && e.b === a)
);
}
function findPath(start, end) {
const queue = [[start]];
const visited = new Set([start]);
while (queue.length) {
const path = queue.shift();
const current = path[path.length - 1];
if (current === end) return path;
for (const edge of edges) {
if (edge.blocked) continue;
const next = edge.a === current ? edge.b : edge.b === current ? edge.a : null;
if (!next || visited.has(next)) continue;
visited.add(next);
queue.push([...path, next]);
}
}
return null;
}
function assignedRequests() {
return requests.filter(r => r.assigned);
}
function hubUsed(locationId) {
return locations[locationId].baseUsed +
assignedRequests()
.filter(r => r.to === locationId)
.reduce((sum, r) => sum + r.weight, 0);
}
function courierLoad(courierId) {
const courier = couriers.find(c => c.id === courierId);
return courier.baseLoad +
assignedRequests()
.filter(r => r.courier === courierId)
.reduce((sum, r) => sum + r.weight, 0);
}
function calculateEta(route, request) {
let distance = 0;
for (let i = 0; i < route.length - 1; i++) {
distance += locations[route[i]].pos.distanceTo(locations[route[i + 1]].pos);
}
const urgencyAdjustment = request.priority === "Urgent" ? 0 : 2;
return Math.max(6, Math.round(distance * 1.7 + request.weight * 2 + urgencyAdjustment));
}
function releaseRequest(request, reason = "Awaiting reassignment") {
request.assigned = false;
request.courier = null;
request.route = [];
request.eta = null;
request.status = "unmet";
request.reason = reason;
request.progress = 0;
}
function assignmentFailure(request) {
if (request.consent !== "verified") {
return {
reason: request.consent === "declined"
? "Recipient declined delivery"
: "Consent awaiting verification"
};
}
const route = findPath(request.from, request.to);
if (!route) {
return {
reason: "No open route · Commons ↔ East Pantry is blocked"
};
}
const destination = locations[request.to];
const used = hubUsed(request.to);
if (used + request.weight > destination.capacity) {
return {
reason: `${destination.name} at capacity (${used}/${destination.capacity})`
};
}
const available = couriers.find(c =>
courierLoad(c.id) + request.weight <= c.capacity
);
if (!available) {
return {
reason: "No courier has remaining capacity"
};
}
return null;
}
function assignRequest(request, preferredCourier = null, forcedStatus = "planned") {
const failure = assignmentFailure(request);
if (failure) {
request.assigned = false;
request.courier = null;
request.route = [];
request.eta = null;
request.status = "unmet";
request.reason = failure.reason;
return false;
}
const route = findPath(request.from, request.to);
const preferred = couriers.find(c => c.id === preferredCourier);
const available = preferred &&
courierLoad(preferred.id) + request.weight <= preferred.capacity
? preferred
: couriers
.filter(c => courierLoad(c.id) + request.weight <= c.capacity)
.sort((a, b) => courierLoad(a.id) - courierLoad(b.id))[0];
request.assigned = true;
request.courier = available.id;
request.route = route;
request.eta = calculateEta(route, request);
request.status = forcedStatus;
request.reason = "";
request.progress = 0;
return true;
}
function refreshUnmetReasons() {
for (const request of requests) {
if (request.assigned) continue;
if (request.consent !== "verified") {
request.reason = request.consent === "declined"
? "Recipient declined delivery"
: "Consent awaiting verification";
continue;
}
const failure = assignmentFailure(request);
request.reason = failure
? failure.reason
: "Ready to replan";
}
}
function replanAll() {
for (const request of requests) {
if (request.assigned) releaseRequest(request, "Ready to replan");
}
const priorityOrder = { Urgent: 0, High: 1, Standard: 2 };
const ordered = [...requests].sort(
(a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]
);
for (const request of ordered) {
assignRequest(request);
}
renderAll();
showToast("Network replanned using current consent, route, hub, and courier limits.");
}
function replanSelected() {
const request = selectedRequest();
if (!request) return;
if (request.assigned) releaseRequest(request, "Ready to replan");
const assigned = assignRequest(request);
renderAll();
showToast(
assigned
? `${request.id} replanned with ${locations[request.to].name} in ${request.eta} minutes.`
: `${request.id} remains unmet: ${request.reason}.`
);
}
function toggleConnection() {
const edge = getEdge("commons", "pantry");
edge.blocked = !edge.blocked;
for (const request of requests) {
if (!request.assigned) continue;
const routeContainsEdge = request.route.some((id, index) => {
if (index === 0) return false;
const previous = request.route[index - 1];
return getEdge(previous, id)?.blocked;
});
if (routeContainsEdge) {
releaseRequest(request, "Connection blocked · route invalidated");
}
}
refreshUnmetReasons();
renderAll();
showToast(
edge.blocked
? "Commons ↔ East Pantry blocked. Affected routes must be replanned."
: "Connection restored. Unmet requests are ready to replan."
);
}
// ---------- Three.js scene ----------
const sceneHost = byId("scene");
const labelHost = byId("mapLabels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5df);
scene.fog = new THREE.Fog(0xdce5df, 24, 42);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
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;
sceneHost.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xf5fff8, 0x82978d, 2.1);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xfff4db, 3.2);
sun.position.set(-7, 15, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const world = new THREE.Group();
scene.add(world);
const island = new THREE.Mesh(
new THREE.BoxGeometry(17.5, 0.55, 12.6),
new THREE.MeshStandardMaterial({
color: 0xcbd9ce,
roughness: 0.92,
flatShading: true
})
);
island.position.y = -0.32;
island.receiveShadow = true;
world.add(island);
const islandSide = new THREE.Mesh(
new THREE.BoxGeometry(17.7, 0.22, 12.8),
new THREE.MeshStandardMaterial({
color: 0xaabdb0,
roughness: 1,
flatShading: true
})
);
islandSide.position.y = -0.64;
world.add(islandSide);
const parkMat = new THREE.MeshStandardMaterial({
color: 0xb7cdb7,
roughness: 1,
flatShading: true
});
const park = new THREE.Mesh(new THREE.BoxGeometry(3.2, 0.06, 1.8), parkMat);
park.position.set(4.1, 0.015, -2.9);
park.receiveShadow = true;
world.add(park);
const river = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.065, 12.2),
new THREE.MeshStandardMaterial({
color: 0x8ebbc1,
roughness: 0.55,
metalness: 0.05
})
);
river.position.set(7.25, 0.025, 0);
world.add(river);
const edgeVisuals = new Map();
function createRoad(edge) {
const a = locations[edge.a].pos;
const b = locations[edge.b].pos;
const length = a.distanceTo(b);
const angle = Math.atan2(b.z - a.z, b.x - a.x);
const material = new THREE.MeshStandardMaterial({
color: edge.blocked ? 0xc98374 : 0xe9ece6,
roughness: 0.96,
flatShading: true
});
const road = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.08, 0.36),
material
);
road.position.set((a.x + b.x) / 2, 0.08, (a.z + b.z) / 2);
road.rotation.y = -angle;
road.receiveShadow = true;
world.add(road);
const barriers = new THREE.Group();
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
barriers.position.copy(midpoint);
barriers.position.y = 0.18;
const barrierMat = new THREE.MeshStandardMaterial({
color: 0xdf684f,
roughness: 0.75,
flatShading: true
});
const bar1 = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.17, 0.12),
barrierMat
);
bar1.rotation.y = -angle + Math.PI / 2;
barriers.add(bar1);
const bar2 = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.17, 0.12),
new THREE.MeshStandardMaterial({
color: 0xf4d7b7,
roughness: 0.85,
flatShading: true
})
);
bar2.rotation.y = -angle + Math.PI / 2;
bar2.position.y = 0.01;
barriers.add(bar2);
barriers.visible = edge.blocked;
world.add(barriers);
edgeVisuals.set(edgeKey(edge.a, edge.b), { road, barriers, edge });
}
edges.forEach(createRoad);
function createBuilding(x, z, w, d, h, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const body = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
flatShading: true
})
);
body.position.y = h / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(Math.max(w, d) * 0.73, 0.52, 4),
new THREE.MeshStandardMaterial({
color: 0x7f9890,
roughness: 0.9,
flatShading: true
})
);
roof.position.y = h + 0.23;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
world.add(group);
}
[
[-7.2, -0.8, 1.15, 1.25, 1.25, 0xd8c8ad],
[-7.1, 4.9, 1.0, 1.1, 0.95, 0xb8c9c3],
[-2.6, 5.0, 1.25, 0.95, 1.45, 0xd6b9a8],
[2.7, 4.8, 1.1, 1.2, 1.15, 0xc7d0b4],
[6.8, 4.8, 1.05, 1.05, 1.0, 0xd9d0b7],
[-0.8, -2.2, 1.0, 1.15, 1.0, 0xc4b8ca],
[3.2, -3.7, 1.15, 1.0, 1.3, 0xc6d6cf],
[-7.2, -2.3, 1.1, 1.2, 1.0, 0xd6c7b1],
[-7.1, -5.6, 1.15, 1.0, 1.35, 0xb6c7bc],
[0.1, -6.0, 1.2, 1.0, 0.9, 0xd2bca9],
[4.5, -0.1, 1.0, 1.15, 1.2, 0xb9c9b6]
].forEach(args => createBuilding(...args));
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.08, 0.11, 0.55, 5),
new THREE.MeshStandardMaterial({ color: 0x8f7256, flatShading: true })
);
trunk.position.y = 0.27;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.42, 0.95, 6),
new THREE.MeshStandardMaterial({
color: 0x6f9a76,
roughness: 1,
flatShading: true
})
);
crown.position.y = 0.92;
crown.castShadow = true;
group.add(crown);
world.add(group);
}
[
[-7.8, 2.1, 0.9], [-6.7, 5.6, 0.8], [-3.6, 5.7, 0.85],
[1.5, 5.8, 0.9], [5.4, 5.4, 0.75], [-6.3, -3.4, 0.8],
[-1.7, -5.8, 0.8], [3.2, -5.9, 0.8], [4.7, -2.6, 0.7],
[2.9, -2.8, 0.65], [5.0, -3.0, 0.8]
].forEach(args => createTree(...args));
const hubVisuals = new Map();
const hubLabels = new Map();
function createHub(id, location) {
const group = new THREE.Group();
group.position.copy(location.pos);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x2d766a,
roughness: 0.72,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.64, 0.28, 6),
baseMaterial
);
base.position.y = 0.22;
base.castShadow = true;
group.add(base);
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.44, 0.2, 6),
new THREE.MeshStandardMaterial({
color: 0xf4f1e5,
roughness: 0.8,
flatShading: true
})
);
cap.position.y = 0.44;
cap.castShadow = true;
group.add(cap);
const beacon = new THREE.Mesh(
new THREE.OctahedronGeometry(0.16),
new THREE.MeshStandardMaterial({
color: 0xf0b84b,
roughness: 0.5,
flatShading: true
})
);
beacon.position.y = 0.72;
group.add(beacon);
world.add(group);
hubVisuals.set(id, { group, baseMaterial });
const label = document.createElement("div");
label.className = "map-label";
labelHost.appendChild(label);
hubLabels.set(id, label);
}
Object.entries(locations).forEach(([id, location]) => createHub(id, location));
const markerById = new Map();
const markerMaterials = new Map();
const locationMarkerCounts = new Map();
function createRequestMarker(request) {
const count = locationMarkerCounts.get(request.from) || 0;
locationMarkerCounts.set(request.from, count + 1);
const angle = count * 2.25 + 0.45;
const group = new THREE.Group();
group.position.copy(locations[request.from].pos);
group.position.x += Math.cos(angle) * 0.78;
group.position.z += Math.sin(angle) * 0.78;
group.userData.requestId = request.id;
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.05, 0.5, 6),
new THREE.MeshStandardMaterial({
color: 0xf4f1e5,
roughness: 0.8,
flatShading: true
})
);
stem.position.y = 0.27;
group.add(stem);
const headMaterial = new THREE.MeshStandardMaterial({
color: COLORS.planned,
roughness: 0.6,
flatShading: true
});
const head = new THREE.Mesh(
new THREE.OctahedronGeometry(0.19),
headMaterial
);
head.position.y = 0.64;
head.castShadow = true;
group.add(head);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.28, 0.025, 4, 24),
new THREE.MeshBasicMaterial({
color: COLORS.selected,
transparent: true,
opacity: 0.85
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.04;
group.add(ring);
world.add(group);
markerById.set(request.id, group);
markerMaterials.set(request.id, { headMaterial, ring });
}
requests.forEach(createRequestMarker);
const routeGroup = new THREE.Group();
world.add(routeGroup);
function clearRoute() {
while (routeGroup.children.length) {
const child = routeGroup.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
}
}
function createRouteBeam(fromId, toId, color) {
const from = locations[fromId].pos;
const to = locations[toId].pos;
const length = from.distanceTo(to);
const angle = Math.atan2(to.z - from.z, to.x - from.x);
const beam = new THREE.Mesh(
new THREE.BoxGeometry(length * 0.94, 0.065, 0.16),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92
})
);
beam.position.set((from.x + to.x) / 2, 0.155, (from.z + to.z) / 2);
beam.rotation.y = -angle;
routeGroup.add(beam);
}
const vehicles = new Map();
function createVehicle(request) {
const courier = couriers.find(c => c.id === request.courier);
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.24, 0.54),
new THREE.MeshStandardMaterial({
color: courier?.color || 0x2d766a,
roughness: 0.6,
flatShading: true
})
);
body.position.y = 0.3;
body.castShadow = true;
group.add(body);
const parcel = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.18, 0.27),
new THREE.MeshStandardMaterial({
color: 0xf0d9a7,
roughness: 0.9,
flatShading: true
})
);
parcel.position.set(0, 0.51, -0.06);
parcel.castShadow = true;
group.add(parcel);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x33413d,
roughness: 1,
flatShading: true
});
for (const x of [-0.19, 0.19]) {
for (const z of [-0.17, 0.17]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.055, 8),
wheelMaterial
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.14, z);
group.add(wheel);
}
}
world.add(group);
vehicles.set(request.id, group);
}
function updateVehicles(delta) {
for (const request of requests) {
if (!request.assigned) {
const vehicle = vehicles.get(request.id);
if (vehicle) {
world.remove(vehicle);
vehicle.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
vehicles.delete(request.id);
}
continue;
}
if (!vehicles.has(request.id)) createVehicle(request);
const vehicle = vehicles.get(request.id);
const route = request.route;
if (route.length < 2) continue;
const lengths = [];
let total = 0;
for (let i = 0; i < route.length - 1; i++) {
const length = locations[route[i]].pos.distanceTo(locations[route[i + 1]].pos);
lengths.push(length);
total += length;
}
let distance = request.progress * total;
let segment = 0;
while (
segment < lengths.length - 1 &&
distance > lengths[segment]
) {
distance -= lengths[segment];
segment++;
}
const from = locations[route[segment]].pos;
const to = locations[route[segment + 1]].pos;
const alpha = lengths[segment] ? distance / lengths[segment] : 0;
vehicle.position.set(
THREE.MathUtils.lerp(from.x, to.x, alpha),
0.04,
THREE.MathUtils.lerp(from.z, to.z, alpha)
);
vehicle.rotation.y = -Math.atan2(to.z - from.z, to.x - from.x);
request.progress = Math.min(
0.98,
request.progress + delta * (request.status === "in-transit" ? 0.018 : 0.006)
);
}
}
// ---------- Custom camera controls ----------
let yaw = 0.72;
let pitch = 0.83;
let zoom = 1;
const cameraTarget = new THREE.Vector3(0, 0, 0);
let dragging = false;
let pointerStart = null;
let pointerMoved = false;
function updateCameraProjection() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
const aspect = width / Math.max(height, 1);
const halfHeight = 8.8 / zoom;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
function updateCameraPosition() {
const radius = 28;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * Math.cos(pitch) * radius,
cameraTarget.y + Math.sin(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * Math.cos(pitch) * radius
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
yaw = 0.72;
pitch = 0.83;
zoom = 1;
updateCameraProjection();
}
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerMoved = false;
pointerStart = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging || !pointerStart) return;
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.004, 0.42, 1.25);
pointerStart = { x: event.clientX, y: event.clientY };
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
const pointer = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
Array.from(markerById.values()),
true
);
if (hits.length) {
let object = hits[0].object;
while (object && !object.userData.requestId) object = object.parent;
if (object?.userData.requestId) {
selectedId = object.userData.requestId;
renderAll();
}
}
}
pointerStart = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerStart = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(zoom - event.deltaY * 0.0008, 0.72, 1.65);
updateCameraProjection();
}, { passive: false });
byId("zoomInBtn").onclick = () => {
zoom = Math.min(1.65, zoom + 0.12);
updateCameraProjection();
};
byId("zoomOutBtn").onclick = () => {
zoom = Math.max(0.72, zoom - 0.12);
updateCameraProjection();
};
byId("homeBtn").onclick = resetCamera;
const raycaster = new THREE.Raycaster();
function resize() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
renderer.setSize(width, height, false);
updateCameraProjection();
}
new ResizeObserver(resize).observe(sceneHost);
resize();
updateCameraPosition();
// ---------- Interface rendering ----------
function consentClass(consent) {
return consent === "verified"
? "verified"
: consent === "pending"
? "pending"
: "declined";
}
function consentLabel(consent) {
return consent === "verified"
? "✓ Consent verified"
: consent === "pending"
? "◷ Consent pending"
: "× Consent declined";
}
function statusClass(request) {
if (request.consent === "pending") return "pending";
if (request.assigned) {
return request.status === "in-transit" ? "transit" : "planned";
}
return "unmet";
}
function statusLabel(request) {
if (request.consent === "pending") return "Consent due";
if (request.assigned) {
return request.status === "in-transit" ? "In transit" : "Planned";
}
return "Unmet";
}
function filteredRequests() {
return requests.filter(request => {
const matchesFilter =
activeFilter === "all" ||
(activeFilter === "ready" && request.assigned) ||
(activeFilter === "consent" && request.consent !== "verified") ||
(activeFilter === "unmet" && !request.assigned);
const haystack = [
request.id,
request.title,
locations[request.from].name,
locations[request.to].name
].join(" ").toLowerCase();
return matchesFilter && haystack.includes(searchTerm.toLowerCase());
});
}
function renderRequests() {
const filtered = filteredRequests();
byId("requestCount").textContent = requests.length;
if (!filtered.length) {
byId("requestList").innerHTML =
`<div class="empty-state">No requests match this view.</div>`;
return;
}
byId("requestList").innerHTML = filtered.map(request => `
<article
class="request-card ${request.id === selectedId ? "selected" : ""}"
data-request="${request.id}"
tabindex="0"
>
<div class="request-top">
<span class="request-id">${request.id}</span>
<span class="priority ${request.priority.toLowerCase()}">${request.priority}</span>
</div>
<div class="card-title-row">
<span class="request-title">${request.title}</span>
</div>
<div class="route-line">
<i class="route-dot"></i>
${locations[request.from].short}
<span class="arrow">→</span>
${locations[request.to].short}
</div>
<div class="request-bottom">
<span class="chip ${consentClass(request.consent)}">
${consentLabel(request.consent)}
</span>
<span class="chip ${statusClass(request)}">${statusLabel(request)}</span>
<span class="eta-small">
${request.eta ? `${request.eta} min` : request.reason || "No ETA"}
</span>
</div>
</article>
`).join("");
}
function renderPlanner() {
const request = selectedRequest();
byId("selectedBadge").textContent = request?.id || "—";
if (!request) {
byId("plannerBody").innerHTML =
`<div class="empty-state">Select a request to inspect its route.</div>`;
return;
}
const routeNodes = request.route.length
? request.route.map(id => locations[id].short).join(" → ")
: `${locations[request.from].short} → ${locations[request.to].short}`;
const courier = couriers.find(c => c.id === request.courier);
byId("plannerBody").innerHTML = `
<div class="planner-card">
<div class="planner-title">${request.title}</div>
<div class="planner-meta">
<span class="chip ${consentClass(request.consent)}">
${consentLabel(request.consent)}
</span>
<span class="chip ${statusClass(request)}">${statusLabel(request)}</span>
</div>
<div class="planner-route">
<strong>${locations[request.from].short}</strong>
<span>→</span>
<strong>${locations[request.to].short}</strong>
</div>
<div class="route-track">
<div class="route-stop">
<div class="route-stop-dot"></div>
${locations[request.from].name}
</div>
<div class="route-stop">
<div class="route-stop-dot"></div>
${locations[request.to].name}
</div>
</div>
<div class="planner-facts">
<div class="fact">
<span>Arrival</span>
<strong>${request.eta ? `${request.eta} min` : "Not set"}</strong>
</div>
<div class="fact">
<span>Load</span>
<strong>${request.weight} unit${request.weight === 1 ? "" : "s"}</strong>
</div>
<div class="fact">
<span>Courier</span>
<strong>${courier?.name || "Unassigned"}</strong>
</div>
</div>
<div class="planner-note">
<strong>${routeNodes}</strong><br />
${request.reason || request.notes}
</div>
</div>
`;
byId("consentAction").hidden = request.consent !== "pending";
byId("releaseSelected").disabled = !request.assigned;
byId("replanSelected").disabled = request.consent === "declined";
}
function renderResources() {
byId("hubCapacity").innerHTML = Object.entries(locations).map(([id, location]) => {
const used = hubUsed(id);
const percent = Math.min(100, used / location.capacity * 100);
const level = used >= location.capacity ? "full" : percent >= 80 ? "near" : "";
return `
<div class="resource-row">
<div class="resource-label">
<strong>${location.name}</strong>
<span>${used}/${location.capacity}</span>
</div>
<div class="capacity-bar">
<i class="${level}" style="width:${percent}%"></i>
</div>
</div>
`;
}).join("");
byId("courierCapacity").innerHTML = couriers.map(courier => {
const load = courierLoad(courier.id);
const percent = Math.min(100, load / courier.capacity * 100);
const level = load >= courier.capacity ? "full" : percent >= 80 ? "near" : "";
return `
<div class="courier-row">
<div class="courier-icon">${courier.id === "van" ? "▣" : courier.id === "bike" ? "◉" : "◇"}</div>
<div>
<div class="courier-name">${courier.name}</div>
<div class="capacity-bar" style="margin-top:5px">
<i class="${level}" style="width:${percent}%"></i>
</div>
</div>
<div class="courier-load">${load}/${courier.capacity}</div>
</div>
`;
}).join("");
}
function renderTrackers() {
const verified = requests.filter(r => r.consent === "verified").length;
const pending = requests.filter(r => r.consent === "pending").length;
const declined = requests.filter(r => r.consent === "declined").length;
byId("consentSummary").textContent =
`${verified} verified · ${pending} pending · ${declined} declined`;
byId("consentTracker").innerHTML = requests.map(request => `
<div class="tracker-row" data-select="${request.id}">
<div class="tracker-main">
<strong>${request.id} · ${request.title}</strong>
<span>${locations[request.from].short} → ${locations[request.to].short}</span>
</div>
<span class="chip ${consentClass(request.consent)}">
${request.consent}
</span>
</div>
`).join("");
const arrivals = assignedRequests().sort((a, b) => a.eta - b.eta);
byId("arrivalSummary").textContent = `${arrivals.length} scheduled`;
byId("arrivalTracker").innerHTML = arrivals.length
? arrivals.map(request => `
<div class="tracker-row" data-select="${request.id}">
<div class="tracker-main">
<strong>${request.id} · ${request.title}</strong>
<span>${locations[request.to].name} · ${request.courier || "Unassigned"}</span>
</div>
<div class="tracker-value">
${request.eta} min
<small>${request.status === "in-transit" ? "En route" : "Scheduled"}</small>
</div>
</div>
`).join("")
: `<div class="empty-state">No active arrivals.</div>`;
const unmet = requests.filter(r => !r.assigned);
byId("unmetSummary").textContent = `${unmet.length} need attention`;
byId("unmetTracker").innerHTML = unmet.length
? unmet.map(request => `
<div class="tracker-row" data-select="${request.id}">
<div class="tracker-main">
<strong>${request.id} · ${request.title}</strong>
<span>${request.reason || "Awaiting reassignment"}</span>
</div>
<div class="tracker-value">
${request.priority}
<small>${locations[request.to].short}</small>
</div>
</div>
`).join("")
: `<div class="empty-state">All confirmed requests are covered.</div>`;
}
function updateMapStyles() {
for (const request of requests) {
const styles = markerMaterials.get(request.id);
const color = request.consent === "pending"
? COLORS.pending
: request.assigned
? request.status === "in-transit"
? COLORS.transit
: COLORS.planned
: COLORS.unmet;
styles.headMaterial.color.setHex(color);
styles.ring.visible = request.id === selectedId;
const marker = markerById.get(request.id);
marker.scale.setScalar(request.id === selectedId ? 1.22 : 1);
}
for (const [id, visual] of hubVisuals) {
const location = locations[id];
const used = hubUsed(id);
const color = used >= location.capacity
? 0xdf684f
: used / location.capacity >= 0.8
? 0xd39a35
: 0x2d766a;
visual.baseMaterial.color.setHex(color);
const label = hubLabels.get(id);
label.innerHTML = `
<strong>${location.name}</strong>
<span>${used}/${location.capacity} capacity</span>
`;
}
for (const visual of edgeVisuals.values()) {
visual.road.material.color.setHex(
visual.edge.blocked ? 0xc98374 : 0xe9ece6
);
visual.barriers.visible = visual.edge.blocked;
}
clearRoute();
const request = selectedRequest();
if (request?.assigned && request.route.length > 1) {
for (let i = 0; i < request.route.length - 1; i++) {
createRouteBeam(request.route[i], request.route[i + 1], 0xf0b84b);
}
}
}
function renderSummary() {
const active = assignedRequests().length;
const unmet = requests.filter(r => !r.assigned).length;
const pending = requests.filter(r => r.consent === "pending").length;
byId("networkSummary").innerHTML =
`<strong>${active}</strong> active · <strong>${unmet}</strong> unmet · <strong>${pending}</strong> consent due`;
byId("mapActive").textContent = active;
byId("mapUnmet").textContent = unmet;
}
function renderConnection() {
const blocked = getEdge("commons", "pantry").blocked;
byId("connectionStatus").textContent = blocked ? "Blocked" : "Open";
byId("connectionStatus").classList.toggle("open", !blocked);
byId("toggleBlockBtn").textContent = blocked
? "Restore connection"
: "Simulate blocked connection";
byId("toggleBlockBtn").classList.toggle("danger", blocked);
byId("toggleBlockBtn").classList.toggle("secondary", !blocked);
byId("connectionDescription").textContent = blocked
? "The eastern connection is unavailable. Pantry requests cannot reach the western network."
: "The eastern connection is open again. Replan unmet requests to assign new routes.";
}
function renderAll() {
renderRequests();
renderPlanner();
renderResources();
renderTrackers();
renderSummary();
renderConnection();
updateMapStyles();
}
function selectRequest(id) {
if (!requests.some(r => r.id === id)) return;
selectedId = id;
renderAll();
}
byId("requestList").addEventListener("click", event => {
const card = event.target.closest("[data-request]");
if (card) selectRequest(card.dataset.request);
});
byId("requestList").addEventListener("keydown", event => {
if (event.key !== "Enter") return;
const card = event.target.closest("[data-request]");
if (card) selectRequest(card.dataset.request);
});
byId("filterTabs").addEventListener("click", event => {
const button = event.target.closest("[data-filter]");
if (!button) return;
activeFilter = button.dataset.filter;
document.querySelectorAll(".filter-tab").forEach(tab => {
tab.classList.toggle("active", tab === button);
});
renderRequests();
});
byId("searchInput").addEventListener("input", event => {
searchTerm = event.target.value;
renderRequests();
});
for (const trackerId of ["consentTracker", "arrivalTracker", "unmetTracker"]) {
byId(trackerId).addEventListener("click", event => {
const row = event.target.closest("[data-select]");
if (row) selectRequest(row.dataset.select);
});
}
byId("replanSelected").onclick = replanSelected;
byId("replanAllBtn").onclick = replanAll;
byId("toggleBlockBtn").onclick = toggleConnection;
byId("releaseSelected").onclick = () => {
const request = selectedRequest();
if (!request?.assigned) return;
releaseRequest(request);
renderAll();
showToast(`${request.id} released and added to the unmet queue.`);
};
byId("consentAction").onclick = () => {
const request = selectedRequest();
if (!request) return;
request.consent = "verified";
renderAll();
showToast(`${request.id} consent verified. The request can now be replanned.`);
};
function showToast(message) {
const toast = byId("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 3200);
}
function updateClock() {
byId("clock").textContent = new Date().toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit"
});
}
updateClock();
setInterval(updateClock, 30000);
// Initial assignments: capacity-aware routes with a mix of planned and active deliveries.
assignRequest(requests.find(r => r.id === "MA-104"), "bike", "planned");
assignRequest(requests.find(r => r.id === "MA-108"), "van", "in-transit");
assignRequest(requests.find(r => r.id === "MA-113"), "cargo", "planned");
assignRequest(requests.find(r => r.id === "MA-120"), "van", "planned");
refreshUnmetReasons();
renderAll();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
updateCameraPosition();
updateVehicles(delta);
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
for (const [id, location] of Object.entries(locations)) {
const point = location.pos.clone();
point.y = 1.12;
point.project(camera);
const label = hubLabels.get(id);
const x = (point.x * 0.5 + 0.5) * width;
const y = (-point.y * 0.5 + 0.5) * height;
label.style.left = `${x}px`;
label.style.top = `${y}px`;
label.style.display = point.z < -1 || point.z > 1 ? "none" : "block";
}
const selected = selectedRequest();
if (selected) {
const marker = markerById.get(selected.id);
const pulse = 1.12 + Math.sin(performance.now() * 0.004) * 0.08;
marker.scale.setScalar(pulse);
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```