Prompt specification
Build or customize the Three.js 3D scene "Disaster Relief Information Simulation" 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: Disaster Relief Information Simulation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/disaster-relief-information-simulation-x3268
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing shared information about tasks and supplies. Model a fictional relief depot with delayed needs reports and finite supplies. Compare routing under stale and updated information, clearly separating report quality from actual demand. Voxel style.
Working Three.js Starter (disaster-relief-information-simulation-x3268):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>West Quay Relief Depot — Stale vs. Updated Reports</title>
<style>
:root {
--ink: #263238;
--muted: #6c777b;
--paper: #f7f5ef;
--panel: rgba(250, 249, 244, 0.94);
--line: #d8d6cd;
--teal: #087f78;
--teal-soft: #d7eeea;
--purple: #7655a5;
--purple-soft: #ebe5f5;
--orange: #e76f51;
--amber: #e9a23b;
--blue: #3182c8;
--green: #4d9564;
--shadow: 0 6px 22px rgba(43, 52, 54, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: flex;
flex-direction: column;
height: 100vh;
min-height: 0;
}
header {
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
min-height: 70px;
padding: 12px 22px;
border-bottom: 1px solid #cbc9c0;
background: #f6f4ed;
box-shadow: 0 2px 12px rgba(43, 52, 54, 0.05);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
}
.brand-mark span {
position: absolute;
display: block;
width: 19px;
height: 19px;
box-shadow: 3px 3px 0 rgba(38, 50, 56, 0.13);
}
.brand-mark span:nth-child(1) {
left: 0;
top: 0;
background: var(--teal);
}
.brand-mark span:nth-child(2) {
right: 0;
top: 0;
background: #55b6ae;
}
.brand-mark span:nth-child(3) {
left: 0;
bottom: 0;
background: #f0b24b;
}
.brand-mark span:nth-child(4) {
right: 0;
bottom: 0;
background: #ece7d9;
}
.brand-title {
margin: 0;
font-size: 17px;
font-weight: 800;
letter-spacing: 0.01em;
}
.brand-subtitle {
margin-top: 3px;
color: var(--muted);
font-size: 12px;
}
.header-status {
display: flex;
align-items: center;
gap: 9px;
color: #526065;
font-size: 12px;
font-weight: 650;
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(77, 149, 100, 0.14);
}
main {
display: flex;
flex: 1;
min-height: 0;
}
#stage {
position: relative;
flex: 1;
min-width: 0;
overflow: hidden;
background: #e9e6dc;
}
#canvasWrap,
#labelLayer {
position: absolute;
inset: 0;
}
#canvasWrap canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#labelLayer {
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.scene-heading {
position: absolute;
z-index: 8;
top: 22px;
left: 24px;
max-width: 440px;
pointer-events: none;
}
.eyebrow {
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scene-heading h1 {
margin: 7px 0 7px;
font-size: clamp(23px, 2.2vw, 34px);
line-height: 1.02;
letter-spacing: -0.035em;
}
.scene-heading p {
max-width: 410px;
margin: 0;
color: #59666b;
font-size: 12px;
line-height: 1.45;
}
.legend {
position: absolute;
z-index: 8;
top: 22px;
right: 22px;
width: 220px;
padding: 12px 13px;
border: 1px solid rgba(118, 115, 104, 0.28);
border-radius: 4px;
background: rgba(248, 246, 239, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin: 7px 0;
color: #526065;
font-size: 11px;
}
.legend-swatch {
width: 22px;
height: 4px;
flex: 0 0 auto;
background: var(--teal);
}
.legend-swatch.stale {
background: var(--purple);
}
.legend-cube {
width: 9px;
height: 9px;
margin-left: 3px;
background: var(--orange);
}
.legend-cube.quality {
background: var(--blue);
}
.legend-cube.truth {
background: var(--green);
}
.legend-note {
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid var(--line);
color: #7a8385;
font-size: 9px;
line-height: 1.4;
}
.site-label {
position: absolute;
z-index: 7;
min-width: 64px;
padding: 6px 7px;
transform: translate(-50%, -100%);
border: 1px solid rgba(40, 50, 53, 0.22);
border-radius: 3px;
background: rgba(250, 248, 241, 0.94);
box-shadow: 0 3px 8px rgba(38, 50, 56, 0.14);
color: var(--ink);
text-align: left;
cursor: pointer;
pointer-events: auto;
}
.site-label::after {
position: absolute;
bottom: -5px;
left: 50%;
width: 7px;
height: 7px;
transform: translateX(-50%) rotate(45deg);
border-right: 1px solid rgba(40, 50, 53, 0.22);
border-bottom: 1px solid rgba(40, 50, 53, 0.22);
background: #faf8f1;
content: "";
}
.site-label.selected {
border-color: var(--teal);
box-shadow: 0 0 0 2px rgba(8, 127, 120, 0.18);
}
.site-label.missing {
opacity: 0.65;
}
.site-label strong {
display: block;
font-size: 10px;
letter-spacing: 0.06em;
}
.site-label small {
display: block;
margin-top: 2px;
color: #667276;
font-size: 8px;
}
.timeline {
position: absolute;
z-index: 9;
right: 22px;
bottom: 20px;
left: 22px;
display: grid;
grid-template-columns: auto minmax(160px, 1fr) auto auto;
align-items: center;
gap: 15px;
min-height: 72px;
padding: 12px 15px;
border: 1px solid rgba(118, 115, 104, 0.3);
border-radius: 4px;
background: rgba(249, 247, 240, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.clock-block {
min-width: 94px;
}
.clock-time {
margin-top: 4px;
font-size: 22px;
font-weight: 850;
letter-spacing: -0.03em;
}
.slider-wrap {
display: flex;
align-items: center;
gap: 10px;
}
input[type="range"] {
width: 100%;
accent-color: var(--teal);
cursor: pointer;
}
.range-label {
color: #667276;
font-size: 9px;
white-space: nowrap;
}
.advance-button,
.small-button,
.truth-button {
border: 1px solid #c9c8c0;
border-radius: 3px;
background: #fffefa;
box-shadow: 0 2px 0 #c9c8c0;
cursor: pointer;
font-size: 11px;
font-weight: 750;
}
.advance-button {
min-height: 37px;
padding: 0 13px;
}
.advance-button:active,
.small-button:active,
.truth-button:active {
transform: translateY(1px);
box-shadow: 0 1px 0 #c9c8c0;
}
.map-tools {
position: absolute;
z-index: 9;
right: 22px;
bottom: 108px;
display: flex;
gap: 6px;
}
.small-button {
width: 36px;
height: 34px;
font-size: 16px;
}
.selected-card {
position: absolute;
z-index: 9;
bottom: 109px;
left: 24px;
width: min(350px, calc(100% - 88px));
padding: 13px;
border: 1px solid rgba(118, 115, 104, 0.28);
border-radius: 4px;
background: rgba(249, 247, 240, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
.selected-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
padding-bottom: 9px;
border-bottom: 1px solid var(--line);
}
.selected-header h3 {
margin: 3px 0 0;
font-size: 14px;
}
.site-code {
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
}
.selected-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 10px;
}
.signal-box {
min-width: 0;
padding: 9px;
border: 1px solid #d8dedf;
background: rgba(229, 242, 244, 0.68);
}
.signal-box.audit {
border-color: #d5dfd6;
background: rgba(231, 241, 231, 0.72);
}
.signal-label {
margin-bottom: 5px;
color: #607075;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.signal-value {
font-size: 11px;
font-weight: 750;
line-height: 1.35;
}
.signal-meta {
margin-top: 5px;
color: #6a7678;
font-size: 9px;
line-height: 1.4;
}
.selected-note {
margin-top: 8px;
color: #788184;
font-size: 9px;
line-height: 1.35;
}
#sidebar {
z-index: 12;
width: 410px;
flex: 0 0 410px;
overflow-y: auto;
border-left: 1px solid #cbc9c0;
background: #f7f5ef;
scrollbar-color: #b8b7af transparent;
scrollbar-width: thin;
}
.sidebar-section {
padding: 17px 18px;
border-bottom: 1px solid #d8d6ce;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.section-heading .meta {
color: var(--muted);
font-size: 10px;
}
.scenario-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.scenario-card {
position: relative;
min-width: 0;
padding: 11px;
border: 1px solid #d3d1c8;
border-top: 4px solid var(--purple);
border-radius: 3px;
background: #fffefa;
text-align: left;
cursor: pointer;
transition:
transform 120ms ease,
box-shadow 120ms ease;
}
.scenario-card.updated {
border-top-color: var(--teal);
}
.scenario-card.active {
box-shadow: 0 0 0 2px rgba(8, 127, 120, 0.13);
transform: translateY(-1px);
}
.scenario-card.stale.active {
box-shadow: 0 0 0 2px rgba(118, 85, 165, 0.15);
}
.scenario-name {
display: flex;
align-items: center;
justify-content: space-between;
gap: 5px;
font-size: 12px;
font-weight: 850;
}
.scenario-time {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.coverage-number {
margin-top: 12px;
font-size: 26px;
font-weight: 900;
letter-spacing: -0.05em;
}
.coverage-number span {
margin-left: 3px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0;
}
.coverage-track {
height: 5px;
margin-top: 6px;
overflow: hidden;
background: #e7e5de;
}
.coverage-fill {
height: 100%;
background: var(--purple);
transition: width 240ms ease;
}
.updated .coverage-fill {
background: var(--teal);
}
.scenario-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
margin-top: 9px;
color: #667276;
font-size: 9px;
}
.scenario-stats b {
display: block;
margin-top: 2px;
color: var(--ink);
font-size: 11px;
}
.comparison-note {
margin-top: 11px;
padding: 9px 10px;
border-left: 3px solid var(--teal);
background: #e8f1ee;
color: #405455;
font-size: 10px;
line-height: 1.45;
}
.stock-grid {
display: grid;
gap: 10px;
}
.stock-row {
display: grid;
grid-template-columns: 92px 1fr auto;
align-items: center;
gap: 9px;
font-size: 10px;
}
.stock-name {
font-weight: 700;
}
.stock-track {
height: 8px;
overflow: hidden;
background: #dfddd4;
}
.stock-fill {
height: 100%;
background: var(--teal);
}
.stock-fill.water {
background: var(--blue);
}
.stock-fill.med {
background: var(--orange);
}
.stock-value {
min-width: 38px;
font-weight: 800;
text-align: right;
}
.micro-note {
margin-top: 10px;
color: #788184;
font-size: 9px;
line-height: 1.45;
}
.quality-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 10px;
padding: 8px 9px;
border: 1px solid #d6e0e7;
background: #edf4f7;
color: #4d616a;
font-size: 10px;
line-height: 1.35;
}
.quality-summary strong {
color: var(--blue);
font-size: 15px;
}
.report-feed {
display: grid;
gap: 6px;
}
.feed-item {
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: center;
gap: 8px;
padding: 6px 0;
border-bottom: 1px dashed #d7d5cc;
font-size: 9px;
}
.feed-dot {
width: 7px;
height: 7px;
background: var(--blue);
}
.feed-item span:nth-child(2) {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.feed-item time {
color: var(--muted);
}
.truth-button {
padding: 6px 9px;
font-size: 9px;
}
.truth-button.active {
border-color: var(--green);
background: #e4f0e6;
color: #356b48;
box-shadow: 0 2px 0 #b8cdbd;
}
.ledger-head,
.ledger-row {
display: grid;
grid-template-columns: 1.05fr 1.05fr 0.9fr;
gap: 8px;
align-items: center;
}
.ledger-head {
padding: 0 0 7px;
color: #7c8587;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.ledger-row {
width: 100%;
padding: 9px 0;
border: 0;
border-top: 1px solid #dfddd5;
background: transparent;
text-align: left;
cursor: pointer;
}
.ledger-row:hover,
.ledger-row.selected {
background: rgba(8, 127, 120, 0.035);
}
.ledger-site strong {
display: block;
font-size: 10px;
}
.ledger-site small {
display: block;
margin-top: 2px;
color: #7b8587;
font-size: 8px;
}
.reported {
font-size: 9px;
line-height: 1.4;
}
.quality-badge {
display: inline-block;
margin-top: 4px;
padding: 2px 4px;
border-radius: 2px;
background: #e3edf4;
color: #2f6fae;
font-size: 8px;
font-weight: 800;
}
.audit-value {
color: #477455;
font-size: 9px;
font-weight: 750;
line-height: 1.4;
}
.audit-value.locked {
color: #9a9e9c;
font-weight: 600;
}
.audit-key {
display: block;
margin-top: 4px;
color: #77827d;
font-size: 7px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.sidebar-footer {
padding: 14px 18px 20px;
color: #7b8384;
font-size: 9px;
line-height: 1.5;
}
#loading {
position: absolute;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #e9e6dc;
color: #526065;
font-size: 12px;
font-weight: 750;
}
#loading.hidden {
display: none;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100vh;
}
header {
position: sticky;
top: 0;
}
main {
flex-direction: column;
}
#stage {
height: 62vh;
min-height: 510px;
flex: none;
}
#sidebar {
width: 100%;
flex: none;
overflow: visible;
border-top: 1px solid #cbc9c0;
border-left: 0;
}
.header-status {
display: none;
}
}
@media (max-width: 650px) {
header {
padding: 10px 14px;
}
.brand-title {
font-size: 14px;
}
.brand-subtitle {
font-size: 10px;
}
#stage {
min-height: 600px;
}
.scene-heading {
top: 16px;
left: 15px;
max-width: calc(100% - 30px);
}
.scene-heading p {
max-width: 280px;
}
.legend {
top: 115px;
right: 14px;
width: 180px;
}
.timeline {
right: 12px;
bottom: 12px;
left: 12px;
grid-template-columns: auto 1fr auto;
gap: 9px;
}
.timeline .range-label {
display: none;
}
.selected-card {
bottom: 102px;
left: 12px;
width: calc(100% - 75px);
}
.map-tools {
right: 12px;
bottom: 102px;
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<div class="brand-title">West Quay Relief Depot</div>
<div class="brand-subtitle">Shared routing picture · fictional operational sandbox</div>
</div>
</div>
<div class="header-status">
<span class="status-dot"></span>
<span id="headerStock">414 units available · 3 vehicles</span>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive relief depot map">
<div id="canvasWrap"></div>
<div id="labelLayer"></div>
<div class="scene-heading">
<div class="eyebrow">Flood response / West Quay</div>
<h1>What changed when the reports arrived?</h1>
<p>
The same finite stock and vehicles are planned twice: once from the
07:00 snapshot, once from the latest reports received by the clock.
</p>
</div>
<div class="legend">
<div class="legend-title">Map key</div>
<div class="legend-row">
<span class="legend-swatch"></span>
Updated routing plan
</div>
<div class="legend-row">
<span class="legend-swatch stale"></span>
Stale routing plan
</div>
<div class="legend-row">
<span class="legend-cube"></span>
Reported urgency
</div>
<div class="legend-row">
<span class="legend-cube quality"></span>
Report quality
</div>
<div class="legend-row">
<span class="legend-cube truth"></span>
Audited actual need
</div>
<div class="legend-note">
Blue quality blocks and green audit blocks are separate signals.
Only the report set enters the router.
</div>
</div>
<div id="selectedCard" class="selected-card"></div>
<div class="map-tools">
<button id="zoomIn" class="small-button" title="Zoom in">+</button>
<button id="zoomOut" class="small-button" title="Zoom out">−</button>
<button id="resetCamera" class="small-button" title="Reset camera">⌂</button>
</div>
<div class="timeline">
<div class="clock-block">
<div class="eyebrow">Sim clock</div>
<div id="clockTime" class="clock-time">14:00</div>
</div>
<div class="slider-wrap">
<span class="range-label">07:00</span>
<input
id="timeSlider"
type="range"
min="7"
max="20"
step="1"
value="14"
aria-label="Simulation time"
/>
<span class="range-label">20:00</span>
</div>
<div>
<div class="eyebrow">Fixed comparison</div>
<div style="margin-top: 4px; font-size: 10px">Stale = 07:00</div>
</div>
<button id="advanceTime" class="advance-button">Advance 2h</button>
</div>
<div id="loading">Building the voxel depot…</div>
</section>
<aside id="sidebar">
<section class="sidebar-section">
<div class="section-heading">
<h2>Compare routing plans</h2>
<span class="meta">Alternatives, not combined loads</span>
</div>
<div id="scenarioCards" class="scenario-tabs"></div>
<div id="comparisonNote" class="comparison-note"></div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Finite depot stock</h2>
<span class="meta">Before dispatch</span>
</div>
<div id="stockGrid" class="stock-grid"></div>
<div class="micro-note">
Each route starts from this same stock ledger. Three vehicles can carry
72 units each. Selecting a plan does not consume stock.
</div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Incoming reports</h2>
<span id="reportCount" class="meta"></span>
</div>
<div id="qualitySummary" class="quality-summary"></div>
<div id="reportFeed" class="report-feed"></div>
</section>
<section class="sidebar-section">
<div class="section-heading">
<h2>Site signal ledger</h2>
<button id="truthToggle" class="truth-button active">Audit visible</button>
</div>
<div class="ledger-head">
<span>Site / age</span>
<span>Planner sees</span>
<span>Audit truth</span>
</div>
<div id="ledger"></div>
</section>
<div class="sidebar-footer">
<strong>Method note:</strong> route quality is computed from report urgency,
report confidence, freshness, distance, vehicle capacity, and depot stock.
Audited needs appear only in the post-plan comparison. They are not read by
the routing function.
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scenario data
// -------------------------------------------------------------------------
const INITIAL_STOCK = {
shelter: 152,
water: 220,
medical: 42
};
const VEHICLE_COUNT = 3;
const VEHICLE_CAPACITY = 72;
const STALE_HOUR = 7;
const CATEGORY_LABELS = {
shelter: "Shelter kits",
water: "Water cases",
medical: "Med packs"
};
const sites = [
{
id: "RIV",
name: "Riverside Homes",
x: -37,
z: 22,
type: "homes",
population: 186,
actual: { shelter: 34, water: 46, medical: 8 }
},
{
id: "HIL",
name: "Hilltop School",
x: 14,
z: 30,
type: "school",
population: 122,
actual: { shelter: 28, water: 38, medical: 5 }
},
{
id: "CED",
name: "Cedar Clinic",
x: -41,
z: -18,
type: "clinic",
population: 74,
actual: { shelter: 12, water: 30, medical: 18 }
},
{
id: "NOR",
name: "North Market",
x: 39,
z: -24,
type: "market",
population: 214,
actual: { shelter: 18, water: 54, medical: 4 }
},
{
id: "MIL",
name: "Old Mill Shelter",
x: -9,
z: 39,
type: "mill",
population: 98,
actual: { shelter: 24, water: 24, medical: 6 }
},
{
id: "EAS",
name: "East Bridge Camp",
x: 43,
z: 10,
type: "camp",
population: 163,
actual: { shelter: 38, water: 31, medical: 10 }
},
{
id: "PIN",
name: "Pine Gardens",
x: -18,
z: -39,
type: "homes",
population: 145,
actual: { shelter: 40, water: 44, medical: 8 }
},
{
id: "SOU",
name: "South Wharf",
x: 31,
z: -40,
type: "market",
population: 127,
actual: { shelter: 14, water: 40, medical: 6 }
}
];
// The stale 07:00 report snapshot. PIN has no report yet.
const staleReports = {
RIV: {
received: 7,
quality: 74,
urgency: "critical",
need: { shelter: 18, water: 39, medical: 0 }
},
HIL: {
received: 7,
quality: 81,
urgency: "standard",
need: { shelter: 31, water: 18, medical: 0 }
},
CED: {
received: 7,
quality: 88,
urgency: "critical",
need: { shelter: 8, water: 14, medical: 8 }
},
NOR: {
received: 7,
quality: 63,
urgency: "standard",
need: { shelter: 13, water: 46, medical: 0 }
},
MIL: {
received: 7,
quality: 72,
urgency: "standard",
need: { shelter: 25, water: 20, medical: 1 }
},
EAS: {
received: 7,
quality: 68,
urgency: "high",
need: { shelter: 28, water: 19, medical: 4 }
},
PIN: null,
SOU: {
received: 7,
quality: 66,
urgency: "standard",
need: { shelter: 9, water: 36, medical: 0 }
}
};
// Later arrivals. Their content and confidence are independent of actual demand.
const reportEvents = [
{
site: "CED",
received: 11,
quality: 96,
urgency: "critical",
need: { shelter: 11, water: 29, medical: 19 }
},
{
site: "EAS",
received: 12,
quality: 91,
urgency: "high",
need: { shelter: 38, water: 31, medical: 10 }
},
{
site: "RIV",
received: 13,
quality: 94,
urgency: "critical",
need: { shelter: 35, water: 49, medical: 8 }
},
{
site: "PIN",
received: 13,
quality: 86,
urgency: "standard",
need: { shelter: 42, water: 45, medical: 8 }
},
{
site: "NOR",
received: 14,
quality: 70,
urgency: "standard",
need: { shelter: 18, water: 56, medical: 4 }
},
{
site: "HIL",
received: 16,
quality: 89,
urgency: "standard",
need: { shelter: 27, water: 39, medical: 5 }
},
{
site: "SOU",
received: 17,
quality: 74,
urgency: "standard",
need: { shelter: 14, water: 42, medical: 6 }
},
{
site: "MIL",
received: 18,
quality: 80,
urgency: "standard",
need: { shelter: 23, water: 26, medical: 6 }
}
];
const state = {
currentHour: 14,
activeScenario: "updated",
selectedSite: "RIV",
truthVisible: true
};
const $ = (id) => document.getElementById(id);
const formatHour = (hour) => `${String(hour).padStart(2, "0")}:00`;
const sumNeeds = (need) =>
need.shelter + need.water + need.medical;
const formatNeed = (need) =>
`${need.shelter}S · ${need.water}W · ${need.medical}M`;
function getUpdatedReports(hour) {
const result = {};
for (const site of sites) {
const arrivals = reportEvents
.filter((report) => report.site === site.id && report.received <= hour)
.sort((a, b) => b.received - a.received);
result[site.id] = arrivals.length
? { ...arrivals[0], need: { ...arrivals[0].need } }
: staleReports[site.id]
? {
...staleReports[site.id],
need: { ...staleReports[site.id].need }
}
: null;
}
return result;
}
// -------------------------------------------------------------------------
// Router
//
// IMPORTANT: buildPlan receives reports only. It never receives or reads
// the site's audited actual demand.
// -------------------------------------------------------------------------
const urgencyWeights = {
critical: 10,
high: 6.2,
standard: 2.8
};
function distanceToDepot(site) {
return Math.hypot(site.x - 2, site.z);
}
function nearestNeighborOrder(selectedIds) {
const remaining = [...selectedIds];
const ordered = [];
let current = { x: 2, z: 0 };
while (remaining.length) {
let bestIndex = 0;
let bestDistance = Infinity;
remaining.forEach((id, index) => {
const site = sites.find((item) => item.id === id);
const distance = Math.hypot(site.x - current.x, site.z - current.z);
if (distance < bestDistance) {
bestDistance = distance;
bestIndex = index;
}
});
const [nextId] = remaining.splice(bestIndex, 1);
const next = sites.find((item) => item.id === nextId);
ordered.push(nextId);
current = next;
}
return ordered;
}
function buildPlan(reportSet) {
const stock = { ...INITIAL_STOCK };
const allocationBySite = {};
const vehicles = [];
const usedSites = new Set();
for (const site of sites) {
allocationBySite[site.id] = {
shelter: 0,
water: 0,
medical: 0
};
}
for (let vehicleIndex = 0; vehicleIndex < VEHICLE_COUNT; vehicleIndex++) {
let remainingCapacity = VEHICLE_CAPACITY;
const selected = [];
while (remainingCapacity >= 4) {
let best = null;
for (const site of sites) {
if (usedSites.has(site.id)) continue;
const report = reportSet[site.id];
if (!report) continue;
const desired = {
shelter: Math.min(report.need.shelter, stock.shelter),
water: Math.min(report.need.water, stock.water),
medical: Math.min(report.need.medical, stock.medical)
};
const desiredTotal = sumNeeds(desired);
if (desiredTotal <= 0) continue;
// Keep individual stops usable so a large report cannot consume
// an entire vehicle before another site is considered.
const scale = Math.min(
1,
remainingCapacity / desiredTotal,
48 / desiredTotal
);
const allocation = {
shelter: Math.floor(desired.shelter * scale),
water: Math.floor(desired.water * scale),
medical: Math.floor(desired.medical * scale)
};
const allocationTotal = sumNeeds(allocation);
if (allocationTotal < 4) continue;
const age = Math.max(0, state.currentHour - report.received);
const freshness = Math.max(0.32, 1 - age / 19);
const confidenceFactor = 0.65 + (report.quality / 100) * 0.35;
const distanceFactor = 1 / (1 + distanceToDepot(site) / 58);
const score =
urgencyWeights[report.urgency] *
freshness *
confidenceFactor *
(1 + allocationTotal * 0.055) *
distanceFactor;
if (!best || score > best.score) {
best = { site, report, allocation, allocationTotal, score };
}
}
if (!best) break;
stock.shelter -= best.allocation.shelter;
stock.water -= best.allocation.water;
stock.medical -= best.allocation.medical;
allocationBySite[best.site.id].shelter += best.allocation.shelter;
allocationBySite[best.site.id].water += best.allocation.water;
allocationBySite[best.site.id].medical += best.allocation.medical;
usedSites.add(best.site.id);
selected.push(best.site.id);
remainingCapacity -= best.allocationTotal;
}
vehicles.push({
index: vehicleIndex,
routes: nearestNeighborOrder(selected)
});
}
let loaded = 0;
let served = 0;
let actualCovered = 0;
let actualTotal = 0;
let reportCovered = 0;
let reportTotal = 0;
let criticalReached = 0;
let criticalTotal = 0;
let overstocked = 0;
for (const site of sites) {
const allocation = allocationBySite[site.id];
const report = reportSet[site.id];
const allocationTotal = sumNeeds(allocation);
loaded += allocationTotal;
if (allocationTotal > 0) served++;
actualTotal += sumNeeds(site.actual);
for (const category of ["shelter", "water", "medical"]) {
actualCovered += Math.min(allocation[category], site.actual[category]);
overstocked += Math.max(0, allocation[category] - site.actual[category]);
if (report) {
reportTotal += report.need[category];
reportCovered += Math.min(allocation[category], report.need[category]);
}
}
if (report?.urgency === "critical") {
criticalTotal++;
if (allocationTotal > 0) criticalReached++;
}
}
return {
vehicles,
allocationBySite,
loaded,
served,
actualCoverage: actualTotal ? (actualCovered / actualTotal) * 100 : 0,
actualCovered,
reportCoverage: reportTotal ? (reportCovered / reportTotal) * 100 : 0,
criticalReached,
criticalTotal,
overstocked
};
}
let reports = {
stale: { ...staleReports },
updated: getUpdatedReports(state.currentHour)
};
let plans = {
stale: buildPlan(reports.stale),
updated: buildPlan(reports.updated)
};
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const stage = $("stage");
const canvasWrap = $("canvasWrap");
const labelLayer = $("labelLayer");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9e6dc");
scene.fog = new THREE.Fog("#e9e6dc", 145, 255);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 500);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
canvasWrap.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#fff9e9", "#7d8f86", 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff3d6", 3.1);
sun.position.set(-55, 95, 40);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -80;
sun.shadow.camera.right = 80;
sun.shadow.camera.top = 70;
sun.shadow.camera.bottom = -70;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 220;
sun.shadow.bias = -0.00025;
scene.add(sun);
const world = new THREE.Group();
scene.add(world);
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const siteVisuals = {};
const siteMeshes = [];
const siteLabels = {};
const routeMaterials = [];
let routeMeshes = {};
const palette = {
ground: "#d6d2c4",
road: "#a6a79e",
roadEdge: "#bbb9af",
depot: "#d7d0b9",
depotRoof: "#617c78",
homes: "#d7c3a1",
homesRoof: "#a75d4c",
school: "#c9d0b7",
schoolRoof: "#58706e",
clinic: "#e8e4d8",
clinicRoof: "#c45d4c",
market: "#d5b96d",
marketRoof: "#5d8790",
mill: "#b8a987",
camp: "#d5c49a",
water: "#7ea5a8",
updated: "#087f78",
stale: "#7655a5",
orange: "#e76f51",
amber: "#e9a23b",
blue: "#3182c8",
green: "#4d9564",
neutral: "#879195"
};
function box(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = world
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addGround() {
box(112, 1.4, 92, palette.ground, 0, -0.8, 0);
const grid = new THREE.GridHelper(108, 18, "#b9b8ae", "#c7c5ba");
grid.position.y = 0.01;
grid.scale.z = 0.84;
grid.material.transparent = true;
grid.material.opacity = 0.38;
world.add(grid);
// River edge.
box(9, 0.18, 91, palette.water, -52, 0.03, 0);
box(1.1, 0.65, 91, "#b2b5a9", -47, 0.22, 0);
// Main road grid.
const roads = [
[94, 4.8, 0, 27],
[94, 4.8, 0, -28],
[4.8, 65, -28, -1],
[4.8, 65, 28, -1]
];
roads.forEach(([width, depth, x, z]) => {
box(width + 0.8, 0.16, depth + 0.8, palette.roadEdge, x, 0.08, z);
box(width, 0.18, depth, palette.road, x, 0.17, z);
});
// Small connectors.
box(27, 3.5, 3.5, palette.road, -35, 0.16, 13);
box(24, 3.5, 3.5, palette.road, 34, 0.16, 17);
box(3.5, 3.5, 29, palette.road, 10, 0.16, 34);
box(3.5, 3.5, 25, palette.road, 40, 0.16, -33);
}
function makeTree(x, z, scale = 1) {
box(0.8 * scale, 3.2 * scale, 0.8 * scale, "#7d6650", x, 1.6 * scale, z);
box(
4.2 * scale,
3.7 * scale,
4.2 * scale,
"#708d6c",
x,
4.2 * scale,
z
);
box(
3.2 * scale,
2.8 * scale,
3.2 * scale,
"#7f9d73",
x,
6.2 * scale,
z
);
}
function addScenery() {
const trees = [
[-43, 37, 0.9], [-30, 42, 0.8], [3, 40, 0.85],
[24, 41, 0.75], [47, 34, 0.8], [-45, -35, 0.9],
[-30, -43, 0.72], [44, -41, 0.85], [49, -14, 0.65],
[-14, -42, 0.75], [7, -43, 0.8], [19, -17, 0.55]
];
trees.forEach(([x, z, scale]) => makeTree(x, z, scale));
// Low voxel embankments.
for (let i = 0; i < 8; i++) {
box(3.2, 0.8, 2.3, "#b8b39f", -42 + i * 5.2, 0.35, 44);
}
}
function addDepot() {
const depot = new THREE.Group();
depot.position.set(2, 0, 0);
world.add(depot);
box(21, 0.55, 14, "#c1bca9", 0, 0.25, 0, depot);
box(16, 6.5, 10, palette.depot, -1, 3.5, 0, depot);
box(17, 0.75, 11, palette.depotRoof, -1, 7.05, 0, depot);
box(5, 4.2, 8.5, "#e3ded0", 9, 2.1, 0, depot);
box(5.6, 0.55, 9.1, "#7a6e59", 9, 4.45, 0, depot);
// Loading doors.
[-5, -1, 3].forEach((x) => {
box(2.8, 3.5, 0.18, "#536866", x, 1.9, 5.08, depot);
});
// Red cross sign.
box(1.1, 3.5, 0.28, palette.orange, 9, 2.6, 4.35, depot);
box(3.5, 1.1, 0.28, palette.orange, 9, 2.6, 4.36, depot);
// Supply stacks.
const crateColors = ["#2d7e79", "#397da8", "#c65d49"];
for (let i = 0; i < 12; i++) {
const row = Math.floor(i / 4);
const col = i % 4;
box(
1.6,
1.2,
1.6,
crateColors[col % 3],
-5 + col * 1.9,
1 + row * 1.25,
-7
);
}
// Flag pole and block flag.
box(0.22, 6, 0.22, "#555f5f", -11, 3, 1, depot);
box(2.6, 1.5, 0.18, "#d4a336", -9.8, 5.6, 1, depot);
}
function addBuildingToSite(group, site) {
const type = site.type;
if (type === "homes") {
for (let i = 0; i < 3; i++) {
const x = -4 + i * 4;
box(3.2, 3.1, 4.3, palette.homes, x, 1.65, 0, group);
box(3.6, 0.65, 4.7, palette.homesRoof, x, 3.5, 0, group);
box(0.8, 1.1, 0.16, "#506d73", x - 0.7, 2, 2.18, group);
}
} else if (type === "school") {
box(9.5, 4.1, 5.2, palette.school, 0, 2.15, 0, group);
box(10.2, 0.65, 5.8, palette.schoolRoof, 0, 4.5, 0, group);
box(2.4, 5.7, 2.4, "#d8d4c4", 3.6, 2.95, 0, group);
box(1, 1.5, 0.16, "#486b73", 3.6, 3.2, 1.3, group);
} else if (type === "clinic") {
box(8.5, 4.6, 6.8, palette.clinic, 0, 2.4, 0, group);
box(9.2, 0.7, 7.4, palette.clinicRoof, 0, 5.05, 0, group);
box(0.8, 2.7, 0.18, palette.orange, 0, 2.8, 3.45, group);
box(2.7, 0.8, 0.18, palette.orange, 0, 2.8, 3.46, group);
} else if (type === "market") {
box(8.5, 2.8, 6.2, "#d7c18a", 0, 1.5, 0, group);
box(9.3, 0.6, 7, palette.marketRoof, 0, 3.2, 0, group);
[-2.5, 0.5, 3].forEach((x, index) => {
box(1.7, 1.3, 1.7, ["#c76a50", "#4f8f89", "#d3a63d"][index], x, 0.75, 4);
});
} else if (type === "mill") {
box(7.8, 5.3, 6.2, palette.mill, 0, 2.75, 0, group);
box(8.7, 0.75, 7, "#796c59", 0, 5.7, 0, group);
box(1.6, 3.4, 1.6, "#8b7f69", 2.4, 7.5, -1.2, group);
box(4.4, 0.8, 0.5, "#635d54", 0, 3.1, 3.3, group);
} else {
for (let i = 0; i < 4; i++) {
const x = -3 + (i % 2) * 6;
const z = -1.8 + Math.floor(i / 2) * 3.7;
box(3.5, 2.3, 3.1, palette.camp, x, 1.25, z, group);
box(3.9, 0.55, 3.5, "#788f6e", x, 2.65, z, group);
box(1.2, 1.3, 0.16, "#4f6d70", x, 1.4, z + 1.62, group);
}
}
}
function addSite(site) {
const group = new THREE.Group();
group.position.set(site.x, 0, site.z);
world.add(group);
box(10.5, 0.25, 9.5, "#c8c4b7", 0, 0.1, 0, group);
addBuildingToSite(group, site);
const marker = new THREE.Group();
marker.position.set(4.6, 0, 3.8);
group.add(marker);
box(0.45, 3.8, 0.45, "#536063", 0, 2, 0, marker);
const capMaterial = new THREE.MeshStandardMaterial({
color: palette.orange,
roughness: 0.8
});
const cap = new THREE.Mesh(new THREE.BoxGeometry(1.3, 0.75, 1.3), capMaterial);
cap.position.y = 4.25;
cap.castShadow = true;
marker.add(cap);
const qualityBlocks = [];
for (let i = 0; i < 4; i++) {
const block = box(
0.75,
0.75,
0.75,
palette.blue,
0.9 + (i % 2) * 0.85,
0.45 + Math.floor(i / 2) * 0.8,
0,
marker
);
qualityBlocks.push(block);
}
const truthGroup = new THREE.Group();
group.add(truthGroup);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
box(
0.85,
0.18,
0.85,
palette.green,
Math.cos(angle) * 6.2,
0.3,
Math.sin(angle) * 6.2,
truthGroup
);
}
const label = document.createElement("button");
label.className = "site-label";
label.type = "button";
label.innerHTML = `<strong>${site.id}</strong><small></small>`;
label.addEventListener("click", () => selectSite(site.id));
labelLayer.appendChild(label);
siteVisuals[site.id] = {
group,
cap,
capMaterial,
qualityBlocks,
truthGroup,
label
};
group.traverse((object) => {
if (object.isMesh) {
object.userData.siteId = site.id;
siteMeshes.push(object);
}
});
}
addGround();
addScenery();
addDepot();
sites.forEach(addSite);
function routeColor(scenario) {
return scenario === "updated" ? palette.updated : palette.stale;
}
function clearRouteMeshes() {
routeGroup.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
routeGroup.clear();
routeMaterials.length = 0;
}
function addRouteSegment(start, end, material) {
const from = new THREE.Vector3(start.x, 0.42, start.z);
const to = new THREE.Vector3(end.x, 0.42, end.z);
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(0.22, 0.22, length, 8);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(from).add(to).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
routeGroup.add(mesh);
}
function buildRouteMeshes() {
clearRouteMeshes();
routeMeshes = {};
for (const scenario of ["stale", "updated"]) {
const material = new THREE.MeshStandardMaterial({
color: routeColor(scenario),
transparent: true,
opacity: scenario === state.activeScenario ? 0.96 : 0.2,
roughness: 0.6
});
routeMaterials.push({ scenario, material });
for (const vehicle of plans[scenario].vehicles) {
let previous = { x: 2, z: 0 };
for (const siteId of vehicle.routes) {
const site = sites.find((item) => item.id === siteId);
addRouteSegment(previous, site, material);
previous = site;
}
if (vehicle.routes.length) {
addRouteSegment(previous, { x: 2, z: 0 }, material);
}
}
}
}
// Voxel trucks.
const truckGroup = new THREE.Group();
scene.add(truckGroup);
const trucks = [];
function makeTruck(color) {
const truck = new THREE.Group();
box(2.2, 1.1, 3.4, "#f1ead9", 0, 1.1, 0, truck);
box(2.25, 1.3, 1.45, color, 0, 1.2, 1.05, truck);
box(1.7, 0.65, 0.12, "#526d75", 0, 1.55, 1.82, truck);
box(1.55, 1.55, 1.65, "#d4cbb4", 0, 2.25, -0.65, truck);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: "#384244",
roughness: 0.95
});
[-1.15, 1.15].forEach((x) => {
[-0.95, 1.05].forEach((z) => {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.48, 0.48, 0.34, 10),
wheelMaterial
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, 0.52, z);
wheel.castShadow = true;
truck.add(wheel);
});
});
truckGroup.add(truck);
return truck;
}
for (let i = 0; i < VEHICLE_COUNT; i++) {
trucks.push(makeTruck(i === 0 ? "#f0b24b" : "#5b898b"));
}
function pathForVehicle(vehicle) {
const path = [{ x: 2, z: 0 }];
for (const id of vehicle.routes) {
const site = sites.find((item) => item.id === id);
path.push({ x: site.x, z: site.z });
}
if (path.length > 1) path.push({ x: 2, z: 0 });
return path;
}
function pointOnPath(path, progress) {
if (path.length < 2) return { x: 2, z: 0, angle: 0 };
const segments = [];
let totalLength = 0;
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
const length = Math.hypot(b.x - a.x, b.z - a.z);
segments.push({ a, b, length });
totalLength += length;
}
let remaining = progress * totalLength;
for (const segment of segments) {
if (remaining <= segment.length || segment === segments.at(-1)) {
const t = segment.length ? Math.min(1, remaining / segment.length) : 0;
return {
x: THREE.MathUtils.lerp(segment.a.x, segment.b.x, t),
z: THREE.MathUtils.lerp(segment.a.z, segment.b.z, t),
angle: Math.atan2(segment.b.x - segment.a.x, segment.b.z - segment.a.z)
};
}
remaining -= segment.length;
}
return { x: 2, z: 0, angle: 0 };
}
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
function urgencyLabel(urgency) {
if (urgency === "critical") return "Critical";
if (urgency === "high") return "High";
return "Standard";
}
function urgencyColor(urgency) {
if (urgency === "critical") return palette.orange;
if (urgency === "high") return palette.amber;
return palette.neutral;
}
function getActiveReports() {
return reports[state.activeScenario];
}
function renderScenarioCards() {
const staleAge = Math.max(0, state.currentHour - STALE_HOUR);
$("scenarioCards").innerHTML = `
<button
class="scenario-card stale ${state.activeScenario === "stale" ? "active" : ""}"
data-scenario="stale"
aria-pressed="${state.activeScenario === "stale"}"
>
<div class="scenario-name">
Stale snapshot
<span>${staleAge}h old</span>
</div>
<div class="scenario-time">Fixed at ${formatHour(STALE_HOUR)}</div>
<div class="coverage-number">
${plans.stale.actualCoverage.toFixed(0)}<span>% audited need met</span>
</div>
<div class="coverage-track">
<div class="coverage-fill" style="width:${plans.stale.actualCoverage}%"></div>
</div>
<div class="scenario-stats">
<span>Sites reached<b>${plans.stale.served}/8</b></span>
<span>Units loaded<b>${plans.stale.loaded}</b></span>
<span>Critical reached<b>${plans.stale.criticalReached}/${plans.stale.criticalTotal}</b></span>
<span>Reported coverage<b>${plans.stale.reportCoverage.toFixed(0)}%</b></span>
</div>
</button>
<button
class="scenario-card updated ${state.activeScenario === "updated" ? "active" : ""}"
data-scenario="updated"
aria-pressed="${state.activeScenario === "updated"}"
>
<div class="scenario-name">
Latest received
<span>≤ ${formatHour(state.currentHour)}</span>
</div>
<div class="scenario-time">All reports received by the clock</div>
<div class="coverage-number">
${plans.updated.actualCoverage.toFixed(0)}<span>% audited need met</span>
</div>
<div class="coverage-track">
<div class="coverage-fill" style="width:${plans.updated.actualCoverage}%"></div>
</div>
<div class="scenario-stats">
<span>Sites reached<b>${plans.updated.served}/8</b></span>
<span>Units loaded<b>${plans.updated.loaded}</b></span>
<span>Critical reached<b>${plans.updated.criticalReached}/${plans.updated.criticalTotal}</b></span>
<span>Reported coverage<b>${plans.updated.reportCoverage.toFixed(0)}%</b></span>
</div>
</button>
`;
document.querySelectorAll(".scenario-card").forEach((button) => {
button.addEventListener("click", () => {
state.activeScenario = button.dataset.scenario;
updateMapVisuals();
renderScenarioCards();
renderSelectedSite();
updateRouteVisibility();
});
});
const delta = plans.updated.actualCovered - plans.stale.actualCovered;
let message;
if (delta > 0) {
message = `Latest reports improve audited need coverage by ${delta} units over the stale snapshot.`;
} else if (delta < 0) {
message = `Latest reports score ${Math.abs(delta)} fewer audited units here; newer is not automatically better.`;
} else {
message = "Both plans cover the same quantity of audited need at this clock time.";
}
$("comparisonNote").innerHTML = `
<strong>Comparison result:</strong> ${message}
Audited need is used only for this score, never by the router.
`;
}
function renderStock() {
const total = Object.values(INITIAL_STOCK).reduce((sum, value) => sum + value, 0);
$("headerStock").textContent = `${total} units available · ${VEHICLE_COUNT} vehicles`;
$("stockGrid").innerHTML = `
<div class="stock-row">
<span class="stock-name">Shelter kits</span>
<div class="stock-track"><div class="stock-fill" style="width:100%"></div></div>
<span class="stock-value">${INITIAL_STOCK.shelter}</span>
</div>
<div class="stock-row">
<span class="stock-name">Water cases</span>
<div class="stock-track"><div class="stock-fill water" style="width:100%"></div></div>
<span class="stock-value">${INITIAL_STOCK.water}</span>
</div>
<div class="stock-row">
<span class="stock-name">Med packs</span>
<div class="stock-track"><div class="stock-fill med" style="width:100%"></div></div>
<span class="stock-value">${INITIAL_STOCK.medical}</span>
</div>
`;
}
function renderFeed() {
const arrivals = reportEvents
.filter((report) => report.received <= state.currentHour)
.sort((a, b) => b.received - a.received)
.slice(0, 4);
const reportSet = getActiveReports();
const receivedReports = Object.values(reportSet).filter(Boolean);
const averageQuality = receivedReports.length
? receivedReports.reduce((sum, report) => sum + report.quality, 0) /
receivedReports.length
: 0;
$("reportCount").textContent = `${receivedReports.length}/8 sites reported`;
$("qualitySummary").innerHTML = `
<span>
Mean confidence of the planner's current report set.
This measures report quality—not actual need.
</span>
<strong>${averageQuality.toFixed(0)}%</strong>
`;
$("reportFeed").innerHTML = arrivals.length
? arrivals
.map((report) => {
const site = sites.find((item) => item.id === report.site);
return `
<div class="feed-item">
<span class="feed-dot"></span>
<span>${site.name} · ${report.quality}% confidence</span>
<time>${formatHour(report.received)}</time>
</div>
`;
})
.join("")
: `<div class="feed-item"><span class="feed-dot"></span><span>No later reports yet</span><time>07:00</time></div>`;
}
function renderLedger() {
const reportSet = getActiveReports();
$("ledger").innerHTML = sites
.map((site) => {
const report = reportSet[site.id];
const age = report ? Math.max(0, state.currentHour - report.received) : null;
return `
<button
class="ledger-row ${state.selectedSite === site.id ? "selected" : ""}"
data-site="${site.id}"
>
<span class="ledger-site">
<strong>${site.id} · ${site.name}</strong>
<small>${report ? `${age}h old · ${urgencyLabel(report.urgency)}` : "No report received"}</small>
</span>
<span class="reported">
${
report
? `${formatNeed(report.need)}
<span class="quality-badge">${report.quality}% quality</span>`
: `<span style="color:#929997">Awaiting report</span>`
}
</span>
<span class="audit-value ${state.truthVisible ? "" : "locked"}">
${
state.truthVisible
? `${formatNeed(site.actual)}`
: "Hidden"
}
<span class="audit-key">not planner input</span>
</span>
</button>
`;
})
.join("");
document.querySelectorAll(".ledger-row").forEach((row) => {
row.addEventListener("click", () => selectSite(row.dataset.site));
});
}
function renderSelectedSite() {
const site = sites.find((item) => item.id === state.selectedSite);
const report = getActiveReports()[site.id];
$("selectedCard").innerHTML = `
<div class="selected-header">
<div>
<div class="site-code">${site.id} / SELECTED SITE</div>
<h3>${site.name}</h3>
</div>
<div style="text-align:right;color:#707b7d;font-size:9px">
${site.population} residents<br />
audit only
</div>
</div>
<div class="selected-grid">
<div class="signal-box">
<div class="signal-label">Planner sees</div>
<div class="signal-value">
${
report
? `${formatNeed(report.need)}`
: "No report received"
}
</div>
<div class="signal-meta">
${
report
? `${urgencyLabel(report.urgency)} urgency · ${report.quality}% quality<br />
Received ${formatHour(report.received)}`
: "No routing signal available"
}
</div>
</div>
<div class="signal-box audit">
<div class="signal-label">Audit truth</div>
<div class="signal-value">${formatNeed(site.actual)}</div>
<div class="signal-meta">
Independently observed need.<br />
Excluded from route construction.
</div>
</div>
</div>
<div class="selected-note">
Report quality describes confidence in the incoming signal. It does not
redefine the site's actual need.
</div>
`;
}
function updateMapVisuals() {
const reportSet = getActiveReports();
for (const site of sites) {
const visual = siteVisuals[site.id];
const report = reportSet[site.id];
visual.capMaterial.color.set(report ? urgencyColor(report.urgency) : "#a7acab");
visual.qualityBlocks.forEach((block, index) => {
block.visible = Boolean(report && index < Math.ceil(report.quality / 25));
});
visual.truthGroup.visible = state.truthVisible;
visual.label.classList.toggle("selected", state.selectedSite === site.id);
visual.label.classList.toggle("missing", !report);
const age = report ? Math.max(0, state.currentHour - report.received) : null;
visual.label.innerHTML = `
<strong>${site.id}</strong>
<small>${report ? `${age}h · ${report.quality}% quality` : "No report"}</small>
`;
}
}
function updateRouteVisibility() {
for (const item of routeMaterials) {
item.material.opacity = item.scenario === state.activeScenario ? 0.96 : 0.2;
item.material.depthWrite = item.scenario === state.activeScenario;
}
}
function renderAll() {
$("clockTime").textContent = formatHour(state.currentHour);
$("timeSlider").value = state.currentHour;
$("truthToggle").classList.toggle("active", state.truthVisible);
$("truthToggle").textContent = state.truthVisible ? "Audit visible" : "Show audit";
renderScenarioCards();
renderStock();
renderFeed();
renderLedger();
renderSelectedSite();
updateMapVisuals();
}
function recompute() {
reports.updated = getUpdatedReports(state.currentHour);
plans.stale = buildPlan(reports.stale);
plans.updated = buildPlan(reports.updated);
buildRouteMeshes();
updateRouteVisibility();
renderAll();
}
function selectSite(id) {
state.selectedSite = id;
renderLedger();
renderSelectedSite();
updateMapVisuals();
}
$("timeSlider").addEventListener("input", (event) => {
state.currentHour = Number(event.target.value);
recompute();
});
$("advanceTime").addEventListener("click", () => {
state.currentHour = Math.min(20, state.currentHour + 2);
recompute();
});
$("truthToggle").addEventListener("click", () => {
state.truthVisible = !state.truthVisible;
renderLedger();
renderSelectedSite();
updateMapVisuals();
});
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
radius: 126,
theta: 0.68,
phi: 0.84
};
function updateCamera() {
const { radius, theta, phi, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.target.set(0, 0, 0);
cameraState.radius = 126;
cameraState.theta = 0.68;
cameraState.phi = 0.84;
updateCamera();
}
$("zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(52, cameraState.radius - 10);
updateCamera();
});
$("zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(190, cameraState.radius + 10);
updateCamera();
});
$("resetCamera").addEventListener("click", resetCamera);
const pointer = {
dragging: false,
lastX: 0,
lastY: 0,
startX: 0,
startY: 0,
panning: false
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.dragging = true;
pointer.panning = event.button === 2 || event.shiftKey;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.dragging) return;
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
if (pointer.panning) {
const right = new THREE.Vector3();
camera.getWorldDirection(right);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(-right.z, 0, right.x);
const scale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.35,
1.34
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointer.dragging = false;
renderer.domElement.releasePointerCapture(event.pointerId);
const moved = Math.hypot(
event.clientX - pointer.startX,
event.clientY - pointer.startY
);
if (moved < 5 && !pointer.panning) {
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const hits = raycaster.intersectObjects(siteMeshes, false);
if (hits.length) selectSite(hits[0].object.userData.siteId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.dragging = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.075,
52,
190
);
updateCamera();
},
{ passive: false }
);
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Animation and projected HTML labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const width = stage.clientWidth;
const height = stage.clientHeight;
const activePlan = plans[state.activeScenario];
for (const site of sites) {
projected.set(site.x, 9.5, site.z);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
const label = siteVisuals[site.id].label;
label.style.display = visible ? "block" : "none";
if (visible) {
label.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
trucks.forEach((truck, index) => {
const vehicle = activePlan.vehicles[index];
const path = pathForVehicle(vehicle);
if (path.length < 2) {
truck.visible = false;
return;
}
truck.visible = true;
const progress = (elapsed * 0.022 + index * 0.29) % 1;
const point = pointOnPath(path, progress);
truck.position.set(point.x, 0.42, point.z);
truck.rotation.y = point.angle;
});
renderer.render(scene, camera);
}
recompute();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```