Prompt specification
Build or customize the Three.js 3D scene "Resource Dispatch Under Uncertain Reports" 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: Resource Dispatch Under Uncertain Reports
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/resource-dispatch-under-uncertain-reports-x3228
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a low-poly fictional emergency-coordination board. Place a depot, several neighborhood blocks, and three team vehicles on a compact road network. Requests arrive as timestamped cards linked to locations; some have confirmed details and others remain uncertain. Let the user assign the limited teams and compare a plan based on all reports with one based on confirmed reports. Keep the true synthetic event state separate from the information available to the dispatcher. Show travel time and unresolved requests without inventing real emergency procedures. Use calm, non-graphic symbols and a bounded toy scenario that can be replayed from the same starting conditions.
Working Three.js Starter (resource-dispatch-under-uncertain-reports-x3228):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Neighborhood Coordination Board</title>
<style>
:root {
color-scheme: dark;
--bg: #111a22;
--panel: #18232d;
--panel-2: #1e2b36;
--panel-3: #253541;
--line: #344552;
--text: #edf3f6;
--muted: #9fb0bc;
--teal: #38b8ad;
--amber: #f0b44d;
--coral: #e87961;
--violet: #9b8be8;
--blue: #79a9d4;
--radius: 14px;
--shadow: 0 12px 35px rgba(0, 0, 0, .28);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
}
button, select { font: inherit; }
button {
border: 1px solid var(--line);
background: var(--panel-3);
color: var(--text);
border-radius: 9px;
padding: 8px 11px;
cursor: pointer;
transition: background .16s, border-color .16s, transform .16s;
}
button:hover:not(:disabled) {
background: #314553;
border-color: #587080;
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled {
cursor: not-allowed;
opacity: .42;
}
button.primary {
background: var(--teal);
color: #102329;
border-color: var(--teal);
font-weight: 750;
}
button.primary:hover:not(:disabled) { background: #56c8be; }
button.ghost {
background: transparent;
}
select {
width: 100%;
border: 1px solid var(--line);
background: #121d26;
color: var(--text);
border-radius: 8px;
padding: 7px 8px;
outline: none;
}
select:focus { border-color: var(--teal); }
.app {
height: 100%;
display: grid;
grid-template-rows: 72px minmax(0, 1fr) 78px;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 0 20px;
border-bottom: 1px solid var(--line);
background: #15212a;
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border-radius: 12px;
background: linear-gradient(145deg, #277f7d, #1d5962);
border: 1px solid #4ca9a7;
box-shadow: inset 0 0 0 4px rgba(255,255,255,.06);
font-weight: 900;
letter-spacing: -.04em;
}
h1, h2, h3, p { margin: 0; }
h1 {
font-size: 17px;
line-height: 1.2;
letter-spacing: .01em;
}
.brand p {
margin-top: 3px;
color: var(--muted);
font-size: 12px;
}
.header-actions {
display: flex;
align-items: center;
gap: 9px;
flex-shrink: 0;
}
.pill {
display: inline-flex;
align-items: center;
gap: 6px;
border: 1px solid var(--line);
background: rgba(255,255,255,.035);
border-radius: 999px;
padding: 6px 9px;
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
.pill::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 9px rgba(56,184,173,.7);
}
main {
min-height: 0;
display: grid;
grid-template-columns: 310px minmax(360px, 1fr) 330px;
}
aside {
min-height: 0;
overflow: auto;
background: var(--panel);
scrollbar-width: thin;
scrollbar-color: #455867 transparent;
}
.left-panel {
border-right: 1px solid var(--line);
}
.right-panel {
border-left: 1px solid var(--line);
}
.panel-section {
padding: 16px;
border-bottom: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.section-heading h2 {
font-size: 13px;
letter-spacing: .055em;
text-transform: uppercase;
}
.section-heading .count {
color: var(--muted);
font-size: 11px;
background: #111b24;
border: 1px solid var(--line);
padding: 3px 7px;
border-radius: 999px;
}
.hint {
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#reportList {
display: grid;
gap: 10px;
}
.report-card {
position: relative;
border: 1px solid var(--line);
border-left: 3px solid var(--amber);
border-radius: 11px;
background: var(--panel-2);
padding: 11px;
cursor: pointer;
transition: border-color .16s, background .16s;
}
.report-card.confirmed { border-left-color: var(--teal); }
.report-card.selected {
background: #263744;
border-color: var(--blue);
box-shadow: 0 0 0 1px rgba(121,169,212,.25);
}
.report-card.pending {
opacity: .46;
cursor: default;
border-left-style: dashed;
}
.report-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 8px;
}
.report-id {
color: var(--muted);
font-size: 10px;
letter-spacing: .08em;
font-weight: 750;
}
.timestamp {
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.report-card h3 {
margin-top: 4px;
font-size: 14px;
line-height: 1.25;
}
.need {
margin-top: 4px;
color: #c8d3da;
font-size: 12px;
}
.location {
margin-top: 9px;
color: var(--blue);
font-size: 11px;
line-height: 1.35;
}
.report-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 10px;
}
.status {
font-size: 10px;
line-height: 1.25;
}
.status.confirmed { color: var(--teal); }
.status.uncertain { color: var(--amber); }
.locate {
padding: 4px 7px;
font-size: 10px;
background: transparent;
}
.assign-row {
margin-top: 10px;
}
.assign-row label {
display: block;
color: var(--muted);
font-size: 10px;
margin-bottom: 4px;
text-transform: uppercase;
letter-spacing: .06em;
}
.excluded-note {
border: 1px dashed #78643d;
color: #e7c789;
background: rgba(240,180,77,.055);
padding: 10px;
border-radius: 10px;
font-size: 11px;
line-height: 1.45;
margin-bottom: 10px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #d9e3e7;
}
#canvasHost {
position: absolute;
inset: 0;
}
#canvasHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.stage-top {
position: absolute;
top: 13px;
left: 13px;
right: 13px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
pointer-events: none;
}
.scene-badge {
color: #20323c;
background: rgba(249,252,252,.9);
border: 1px solid rgba(39,63,76,.16);
border-radius: 10px;
padding: 9px 11px;
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
}
.scene-badge strong {
display: block;
font-size: 12px;
}
.scene-badge span {
display: block;
margin-top: 2px;
color: #526874;
font-size: 10px;
}
.hud {
display: flex;
gap: 7px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: 390px;
}
.hud-item {
min-width: 82px;
padding: 8px 10px;
color: #20323c;
background: rgba(249,252,252,.9);
border: 1px solid rgba(39,63,76,.16);
border-radius: 10px;
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
}
.hud-item span {
display: block;
font-size: 9px;
text-transform: uppercase;
letter-spacing: .07em;
color: #60737d;
}
.hud-item b {
display: block;
margin-top: 2px;
font-size: 15px;
font-variant-numeric: tabular-nums;
}
.legend {
position: absolute;
left: 13px;
bottom: 13px;
display: flex;
flex-wrap: wrap;
gap: 9px;
max-width: calc(100% - 160px);
padding: 8px 10px;
color: #304650;
background: rgba(249,252,252,.88);
border: 1px solid rgba(39,63,76,.15);
border-radius: 10px;
box-shadow: var(--shadow);
font-size: 10px;
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--teal);
}
.legend-dot.uncertain {
border-radius: 2px;
background: var(--amber);
}
.legend-dot.truth {
background: var(--violet);
transform: rotate(45deg);
border-radius: 1px;
}
.camera-tools {
position: absolute;
right: 13px;
bottom: 13px;
display: grid;
grid-template-columns: repeat(3, 32px);
gap: 4px;
}
.camera-tools button {
padding: 0;
height: 32px;
color: #20323c;
background: rgba(249,252,252,.9);
border-color: rgba(39,63,76,.2);
box-shadow: var(--shadow);
}
#toast {
position: absolute;
left: 50%;
bottom: 65px;
transform: translateX(-50%) translateY(8px);
max-width: min(480px, 85%);
padding: 9px 12px;
color: #eaf2f5;
background: rgba(22,35,44,.92);
border: 1px solid #455967;
border-radius: 10px;
font-size: 12px;
opacity: 0;
pointer-events: none;
transition: opacity .2s, transform .2s;
box-shadow: var(--shadow);
}
#toast.show {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 4px;
background: #111c24;
border: 1px solid var(--line);
border-radius: 11px;
}
.mode-switch button {
border: 0;
background: transparent;
color: var(--muted);
padding: 8px 5px;
font-size: 11px;
}
.mode-switch button.active {
color: #102329;
background: var(--teal);
font-weight: 750;
}
.mode-note {
min-height: 34px;
margin: 9px 0 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.team-list {
display: grid;
gap: 8px;
}
.team-card {
display: grid;
grid-template-columns: 33px minmax(0, 1fr) auto;
align-items: center;
gap: 9px;
border: 1px solid var(--line);
background: var(--panel-2);
border-radius: 11px;
padding: 10px;
}
.team-badge {
width: 31px;
height: 31px;
display: grid;
place-items: center;
border-radius: 9px;
color: #102329;
font-weight: 900;
}
.team-name {
font-size: 12px;
font-weight: 750;
}
.team-detail {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.team-action {
padding: 6px 8px;
font-size: 10px;
}
.plan-actions {
display: flex;
gap: 7px;
margin-top: 11px;
}
.plan-actions button { flex: 1; font-size: 11px; }
.comparison {
display: grid;
gap: 8px;
}
.compare-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 5px 9px;
align-items: center;
border: 1px solid var(--line);
background: var(--panel-2);
border-radius: 10px;
padding: 10px;
}
.compare-row.current { border-color: #537889; }
.compare-title {
font-size: 12px;
font-weight: 750;
}
.compare-travel {
font-size: 15px;
font-weight: 850;
font-variant-numeric: tabular-nums;
text-align: right;
}
.compare-sub {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.compare-insight {
color: #cbd6dc;
background: #111c24;
border: 1px solid var(--line);
border-radius: 9px;
padding: 9px;
font-size: 11px;
line-height: 1.45;
}
.truth-toggle {
width: 100%;
font-size: 11px;
}
.truth-readout {
margin-top: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.truth-row {
padding: 8px 0;
border-top: 1px solid #31414d;
}
.truth-row b { color: #d9d0ff; }
footer {
display: grid;
grid-template-columns: 300px minmax(0, 1fr) 310px;
align-items: center;
gap: 16px;
border-top: 1px solid var(--line);
background: #15212a;
padding: 10px 15px;
z-index: 5;
}
.playback {
display: flex;
align-items: center;
gap: 7px;
}
.playback button {
padding: 7px 10px;
font-size: 11px;
}
.clock {
margin-left: 3px;
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.timeline-wrap { min-width: 0; }
.timeline-labels {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
margin-bottom: 5px;
}
.timeline-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: #0d161d;
border: 1px solid #30414e;
}
#timelineFill {
width: 0;
height: 100%;
background: linear-gradient(90deg, #2e918e, var(--teal));
transition: width .3s;
}
.footer-note {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
text-align: right;
}
@media (max-width: 1120px) {
main { grid-template-columns: 280px minmax(320px, 1fr) 300px; }
footer { grid-template-columns: 270px minmax(0, 1fr) 270px; }
.hud { max-width: 260px; }
.hud-item { min-width: 72px; }
}
@media (max-width: 860px) {
html, body { overflow: auto; }
.app {
height: auto;
min-height: 100%;
grid-template-rows: auto auto auto;
}
header {
min-height: 72px;
flex-wrap: wrap;
padding: 12px;
}
.header-actions .pill { display: none; }
main {
display: grid;
grid-template-columns: 1fr 1fr;
}
#stage {
grid-column: 1 / -1;
grid-row: 1;
height: 58vh;
min-height: 440px;
}
.left-panel { grid-column: 1; }
.right-panel { grid-column: 2; }
aside { max-height: 650px; }
footer {
grid-template-columns: 1fr;
gap: 9px;
}
.footer-note { text-align: left; }
}
@media (max-width: 580px) {
main { display: block; }
#stage { height: 58vh; min-height: 390px; }
aside { max-height: none; }
.stage-top { flex-direction: column; }
.hud { justify-content: flex-start; max-width: 100%; }
.legend { max-width: calc(100% - 26px); bottom: 55px; }
.camera-tools { left: 13px; right: auto; }
header .brand p { display: none; }
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark">EC</div>
<div>
<h1>Neighborhood Coordination Board</h1>
<p>Fictional training scene · 5 requests · 3 teams · compact road model</p>
</div>
</div>
<div class="header-actions">
<span class="pill">Deterministic toy scenario</span>
<button id="replayBtn" class="primary">Replay same starting state</button>
</div>
</header>
<main>
<aside class="left-panel">
<section class="panel-section">
<div class="section-heading">
<h2>Incoming requests</h2>
<span id="requestCount" class="count">0 received</span>
</div>
<p class="hint">
Select a card, then assign one team. Uncertain cards show the dispatcher’s
reported access point, not the hidden synthetic truth.
</p>
</section>
<section class="panel-section">
<div id="modeExcludedNote" class="excluded-note" hidden></div>
<div id="reportList"></div>
</section>
</aside>
<section id="stage" aria-label="Interactive 3D neighborhood coordination board">
<div id="canvasHost"></div>
<div class="stage-top">
<div class="scene-badge">
<strong id="sceneMode">Plan: All reports</strong>
<span>Drag to orbit · right-drag to pan · wheel to zoom</span>
</div>
<div class="hud">
<div class="hud-item">
<span>Received</span>
<b id="hudArrivals">0 / 5</b>
</div>
<div class="hud-item">
<span>Unresolved</span>
<b id="hudUnresolved">0</b>
</div>
<div class="hud-item">
<span>Total travel</span>
<b id="hudTravel">0.0 min</b>
</div>
</div>
</div>
<div class="legend">
<span class="legend-item"><i class="legend-dot"></i> Confirmed access</span>
<span class="legend-item"><i class="legend-dot uncertain"></i> Uncertain estimate</span>
<span class="legend-item"><i class="legend-dot truth"></i> Hidden truth after debrief</span>
<span>Routes show depot → reported point → depot</span>
</div>
<div class="camera-tools" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in">+</button>
<button id="zoomOut" title="Zoom out">−</button>
<button id="cameraReset" title="Reset camera">⌂</button>
</div>
<div id="toast" role="status" aria-live="polite"></div>
</section>
<aside class="right-panel">
<section class="panel-section">
<div class="section-heading">
<h2>Planning view</h2>
<span class="count">separate plans</span>
</div>
<div class="mode-switch" role="group" aria-label="Plan information set">
<button id="modeAll" class="active">All reports</button>
<button id="modeConfirmed">Confirmed only</button>
</div>
<p id="modeNote" class="mode-note"></p>
<div class="section-heading">
<h2>Available teams</h2>
<span class="count">one request each</span>
</div>
<div id="teamList" class="team-list"></div>
<div class="plan-actions">
<button id="fillBtn">Fill nearest available</button>
<button id="clearBtn" class="ghost">Clear this plan</button>
</div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Plan comparison</h2>
<span class="count">toy travel model</span>
</div>
<div id="comparison" class="comparison"></div>
</section>
<section class="panel-section">
<div class="section-heading">
<h2>Hidden-truth debrief</h2>
<span class="count">separate layer</span>
</div>
<button id="truthBtn" class="truth-toggle ghost">Reveal toy truth</button>
<div id="truthReadout" class="truth-readout"></div>
<p class="hint" style="margin-top:10px">
Revealing truth never changes assignments or modeled travel. It only
exposes a separate synthetic evaluation layer.
</p>
</section>
</aside>
</main>
<footer>
<div class="playback">
<button id="playBtn" class="primary">Pause</button>
<button id="nextBtn">Next arrival</button>
<span id="clockText" class="clock">08:00</span>
</div>
<div class="timeline-wrap">
<div class="timeline-labels">
<span>Scenario start</span>
<span id="timelineEnd">08:08 toy time</span>
</div>
<div class="timeline-track"><div id="timelineFill"></div></div>
</div>
<div class="footer-note">
Illustrative distances and assignments only. No real emergency procedures,
priorities, or dispatch rules are represented.
</div>
</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/*
* The true synthetic event state is deliberately stored separately.
* Planner and assignment code receive only DISPATCHER_REPORTS.
* TRUE_EVENT_STATE is read exclusively by the optional debrief layer.
*/
const TRUE_EVENT_STATE = Object.freeze({
"REQ-01": {
accessNode: "m1",
offset: [0, 0],
actualAccess: "Willow Avenue · central access"
},
"REQ-02": {
accessNode: "s2",
offset: [1.4, -0.8],
actualAccess: "South Lane · lower access"
},
"REQ-03": {
accessNode: "s1",
offset: [0, 0],
actualAccess: "Market Square · west entrance"
},
"REQ-04": {
accessNode: "m3",
offset: [-1.2, 0.7],
actualAccess: "East Walk · upper access"
},
"REQ-05": {
accessNode: "n2",
offset: [0, 0],
actualAccess: "Riverside · north entrance"
}
});
const DISPATCHER_REPORTS = Object.freeze([
{
id: "REQ-01",
arrival: "08:00",
title: "Willow care point",
need: "General welfare check",
locationConfirmed: true,
detailState: "Access and category confirmed",
visibleLocation: {
node: "m1",
label: "Willow Avenue · W2 access",
x: -10,
z: 0
}
},
{
id: "REQ-02",
arrival: "08:02",
title: "Canal stairway",
need: "Access check",
locationConfirmed: false,
detailState: "Access point unverified",
visibleLocation: {
node: "m2",
label: "Canal Steps · E2 estimate",
x: 10,
z: 0
}
},
{
id: "REQ-03",
arrival: "08:04",
title: "Market shelter",
need: "Community support check-in",
locationConfirmed: true,
detailState: "Access and category confirmed",
visibleLocation: {
node: "s1",
label: "Market Square · S2 access",
x: -10,
z: -24
}
},
{
id: "REQ-04",
arrival: "08:06",
title: "Library court",
need: "Supply check-in",
locationConfirmed: false,
detailState: "Reported access may be one block off",
visibleLocation: {
node: "s3",
label: "Library Court · E4 estimate",
x: 30,
z: -24
}
},
{
id: "REQ-05",
arrival: "08:08",
title: "Riverside garden gate",
need: "Route and access check",
locationConfirmed: true,
detailState: "Access and category confirmed",
visibleLocation: {
node: "n2",
label: "Riverside · N3 access",
x: 10,
z: 24
}
}
]);
const TEAMS = Object.freeze([
{ id: "A", name: "Team A", color: 0x38b8ad, css: "#38b8ad" },
{ id: "B", name: "Team B", color: 0xe87961, css: "#e87961" },
{ id: "C", name: "Team C", color: 0x9b8be8, css: "#9b8be8" }
]);
const NODES = Object.freeze({
n0: { x: -30, z: 24, label: "Hill End" },
n1: { x: -10, z: 24, label: "Depot Gate" },
n2: { x: 10, z: 24, label: "Riverside" },
n3: { x: 30, z: 24, label: "North East" },
m0: { x: -30, z: 0, label: "West Lane" },
m1: { x: -10, z: 0, label: "Willow Avenue" },
m2: { x: 10, z: 0, label: "Canal Steps" },
m3: { x: 30, z: 0, label: "East Walk" },
s0: { x: -30, z: -24, label: "Garden Row" },
s1: { x: -10, z: -24, label: "Market Square" },
s2: { x: 10, z: -24, label: "South Lane" },
s3: { x: 30, z: -24, label: "Library Court" }
});
const DEPOT_NODE = "n1";
const METERS_PER_WORLD_UNIT = 3;
const TOY_SPEED_METERS_PER_MINUTE = 90;
const state = {
arrived: new Set(),
assignments: { all: {}, confirmed: {} },
mode: "all",
selectedRequest: null,
playing: false,
truthVisible: false
};
let arrivalTimer = null;
let toastTimer = null;
const $ = id => document.getElementById(id);
const reportById = Object.fromEntries(DISPATCHER_REPORTS.map(r => [r.id, r]));
const teamById = Object.fromEntries(TEAMS.map(t => [t.id, t]));
// ---------- Road graph and toy travel model ----------
const graph = Object.fromEntries(Object.keys(NODES).map(id => [id, []]));
function connect(a, b) {
const na = NODES[a];
const nb = NODES[b];
const distance = Math.hypot(nb.x - na.x, nb.z - na.z);
graph[a].push({ node: b, distance });
graph[b].push({ node: a, distance });
}
for (const row of ["n", "m", "s"]) {
connect(`${row}0`, `${row}1`);
connect(`${row}1`, `${row}2`);
connect(`${row}2`, `${row}3`);
}
for (const col of ["0", "1", "2", "3"]) {
connect(`n${col}`, `m${col}`);
connect(`m${col}`, `s${col}`);
}
function shortestPath(start, end) {
const distances = Object.fromEntries(Object.keys(NODES).map(id => [id, Infinity]));
const previous = {};
const unvisited = new Set(Object.keys(NODES));
distances[start] = 0;
while (unvisited.size) {
let current = null;
let currentDistance = Infinity;
for (const id of unvisited) {
if (distances[id] < currentDistance) {
current = id;
currentDistance = distances[id];
}
}
if (current === null || currentDistance === Infinity) break;
if (current === end) break;
unvisited.delete(current);
for (const edge of graph[current]) {
if (!unvisited.has(edge.node)) continue;
const nextDistance = currentDistance + edge.distance;
if (nextDistance < distances[edge.node]) {
distances[edge.node] = nextDistance;
previous[edge.node] = current;
}
}
}
const path = [];
let cursor = end;
while (cursor) {
path.unshift(cursor);
if (cursor === start) break;
cursor = previous[cursor];
}
return { distance: distances[end], path };
}
function roundTripMinutes(report) {
const { distance } = shortestPath(DEPOT_NODE, report.visibleLocation.node);
const meters = distance * 2 * METERS_PER_WORLD_UNIT;
return meters / TOY_SPEED_METERS_PER_MINUTE;
}
function arrivedReports(mode = state.mode) {
return DISPATCHER_REPORTS.filter(r =>
state.arrived.has(r.id) &&
(mode === "all" || r.locationConfirmed)
);
}
function teamOccupant(mode, teamId) {
return Object.entries(state.assignments[mode])
.find(([, assignedTeam]) => assignedTeam === teamId)?.[0] || null;
}
function planMetrics(mode) {
const pool = arrivedReports(mode);
const assignments = state.assignments[mode];
let travel = 0;
let assigned = 0;
for (const report of pool) {
if (assignments[report.id]) {
assigned++;
travel += roundTripMinutes(report);
}
}
return {
pool: pool.length,
assigned,
unresolved: pool.length - assigned,
travel,
excluded: mode === "confirmed"
? DISPATCHER_REPORTS.filter(r =>
state.arrived.has(r.id) && !r.locationConfirmed
).length
: 0
};
}
// ---------- Three.js scene ----------
const host = $("canvasHost");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e3e7);
scene.fog = new THREE.Fog(0xd9e3e7, 115, 190);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 350);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional neighborhood board. Drag to orbit, right-drag to pan, and use the wheel to zoom."
);
host.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xeaf7ff, 0x637066, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(-34, 70, 35);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -70;
sun.shadow.camera.right = 70;
sun.shadow.camera.top = 60;
sun.shadow.camera.bottom = -60;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 160;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc7df, 1.1);
fill.position.set(40, 25, -45);
scene.add(fill);
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const markerMap = new Map();
const truthMarkerMap = new Map();
const truthLineMap = new Map();
const vehicleMap = new Map();
const cameraTarget = new THREE.Vector3(0, 0, 0);
let cameraRadius = 99;
let cameraTheta = 0.77;
let cameraPhi = 0.76;
function applyCamera() {
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(cameraPhi) * Math.cos(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * Math.sin(cameraPhi) * Math.sin(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTarget.set(0, 0, 0);
cameraRadius = 99;
cameraTheta = 0.77;
cameraPhi = 0.76;
applyCamera();
}
function focusOn(x, z) {
cameraTarget.set(x, 0, z);
cameraRadius = Math.min(cameraRadius, 61);
applyCamera();
}
function makeLabel(text, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = options.width || 320;
canvas.height = options.height || 74;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = options.background || "rgba(28,44,54,.90)";
ctx.strokeStyle = options.border || "rgba(255,255,255,.22)";
ctx.lineWidth = 2;
const x = 3;
const y = 3;
const w = canvas.width - 6;
const h = canvas.height - 6;
const r = 15;
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = options.color || "#f4f8fa";
ctx.font = `${options.weight || 700} ${options.fontSize || 27}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
const width = options.worldWidth || 8;
sprite.scale.set(width, width * canvas.height / canvas.width, 1);
return sprite;
}
function addRoadSegment(a, b) {
const na = NODES[a];
const nb = NODES[b];
const dx = nb.x - na.x;
const dz = nb.z - na.z;
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const midpoint = new THREE.Vector3((na.x + nb.x) / 2, 0, (na.z + nb.z) / 2);
const sidewalk = new THREE.Mesh(
new THREE.BoxGeometry(length + 0.8, 0.18, 3.5),
new THREE.MeshStandardMaterial({ color: 0xcbd3d1, roughness: 1 })
);
sidewalk.position.set(midpoint.x, -0.01, midpoint.z);
sidewalk.rotation.y = angle;
sidewalk.receiveShadow = true;
scene.add(sidewalk);
const road = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.12, 2.55),
new THREE.MeshStandardMaterial({ color: 0x53636d, roughness: 0.95 })
);
road.position.set(midpoint.x, 0.12, midpoint.z);
road.rotation.y = angle;
road.receiveShadow = true;
scene.add(road);
const dashMaterial = new THREE.MeshBasicMaterial({ color: 0xd8e0dc });
for (let d = 2.2; d < length - 1.5; d += 4.2) {
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.95, 0.025, 0.13),
dashMaterial
);
const t = d / length;
dash.position.set(
na.x + dx * t,
0.195,
na.z + dz * t
);
dash.rotation.y = angle;
scene.add(dash);
}
}
function seededRandom(seed) {
return function() {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
function createBuilding(x, z, width, depth, height, color, roofColor) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
new THREE.MeshStandardMaterial({ color, roughness: 0.88 })
);
body.position.y = height / 2 + 0.08;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(Math.max(width, depth) * 0.72, 1.35, 4),
new THREE.MeshStandardMaterial({ color: roofColor, roughness: 0.9 })
);
roof.position.y = height + 0.72;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
const windowMaterial = new THREE.MeshBasicMaterial({ color: 0xd9eef1 });
for (const side of [-1, 1]) {
const window = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.55, 0.42, 0.04),
windowMaterial
);
window.position.set(0, height * 0.58, side * (depth / 2 + 0.025));
group.add(window);
}
group.position.set(x, 0, z);
scene.add(group);
}
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.23, 1.4, 6),
new THREE.MeshStandardMaterial({ color: 0x80634d, roughness: 1 })
);
trunk.position.y = 0.7;
trunk.castShadow = true;
group.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.9, 2.2, 7),
new THREE.MeshStandardMaterial({ color: 0x6e9b7d, roughness: 1 })
);
crown.position.y = 2.15;
crown.castShadow = true;
group.add(crown);
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
}
function createNeighborhoods() {
const random = seededRandom(240519);
const bodyColors = [0xd6c8b7, 0xc3d2d2, 0xd9c6ba, 0xb9c7b5, 0xd8d1bd];
const roofColors = [0x8e7468, 0x687b82, 0x94756f, 0x6f8175, 0x897766];
const cells = [
{ x: -20, z: 12 },
{ x: 0, z: 12 },
{ x: 20, z: 12 },
{ x: -20, z: -12 },
{ x: 0, z: -12 },
{ x: 20, z: -12 }
];
cells.forEach((cell, cellIndex) => {
const offsets = [
[-4.4, -4.2],
[4.2, -4.0],
[-4.2, 4.1],
[4.3, 4.0]
];
offsets.forEach(([ox, oz], i) => {
const width = 3.2 + random() * 1.6;
const depth = 3.1 + random() * 1.7;
const height = 2.4 + random() * 2.8;
const colorIndex = Math.floor(random() * bodyColors.length);
createBuilding(
cell.x + ox,
cell.z + oz,
width,
depth,
height,
bodyColors[colorIndex],
roofColors[colorIndex]
);
if ((cellIndex + i) % 2 === 0) {
createTree(cell.x + ox * 0.62, cell.z + oz * 0.62, 0.7);
}
});
});
createTree(-39, 29, 0.9);
createTree(39, 29, 0.85);
createTree(-39, -30, 0.8);
createTree(39, -31, 0.9);
createTree(-1, -32, 0.75);
}
function createDepot() {
const group = new THREE.Group();
const platform = new THREE.Mesh(
new THREE.BoxGeometry(12, 0.32, 8),
new THREE.MeshStandardMaterial({ color: 0x9db4b4, roughness: 0.95 })
);
platform.position.set(-10, 0.02, 30);
platform.receiveShadow = true;
scene.add(platform);
const building = new THREE.Mesh(
new THREE.BoxGeometry(7.2, 3.4, 4.8),
new THREE.MeshStandardMaterial({ color: 0x4f8f8b, roughness: 0.82 })
);
building.position.set(-10, 1.85, 31);
building.castShadow = true;
scene.add(building);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(5.0, 1.8, 4),
new THREE.MeshStandardMaterial({ color: 0x335d62, roughness: 0.9 })
);
roof.position.set(-10, 4.25, 31);
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
scene.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(2.1, 1.8, 0.12),
new THREE.MeshStandardMaterial({ color: 0x213b43, roughness: 0.8 })
);
door.position.set(-10, 1.0, 28.55);
scene.add(door);
const label = makeLabel("DEPOT", {
worldWidth: 7.4,
background: "rgba(39,87,87,.93)",
border: "rgba(116,207,199,.65)",
color: "#e8fffb"
});
label.position.set(-10, 6.4, 31);
scene.add(label);
}
function createVehicle(team, index) {
const group = new THREE.Group();
const color = team.color;
const body = new THREE.Mesh(
new THREE.BoxGeometry(2.4, 1.35, 4.1),
new THREE.MeshStandardMaterial({ color, roughness: 0.72 })
);
body.position.y = 1.05;
body.castShadow = true;
group.add(body);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(2.05, 0.42, 2.5),
new THREE.MeshStandardMaterial({ color: 0xe3ecef, roughness: 0.68 })
);
roof.position.set(0, 1.93, -0.2);
roof.castShadow = true;
group.add(roof);
const windshield = new THREE.Mesh(
new THREE.BoxGeometry(1.85, 0.55, 0.08),
new THREE.MeshStandardMaterial({
color: 0x476672,
roughness: 0.35,
metalness: 0.08
})
);
windshield.position.set(0, 1.72, -1.25);
group.add(windshield);
const beaconMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.48,
roughness: 0.42
});
const beacon = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.38, 0.38, 10),
beaconMaterial
);
beacon.position.set(0, 2.34, -0.2);
group.add(beacon);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x25323a,
roughness: 0.95
});
for (const x of [-1.24, 1.24]) {
for (const z of [-1.25, 1.25]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.46, 0.28, 10),
wheelMaterial
);
wheel.position.set(x, 0.55, z);
wheel.rotation.z = Math.PI / 2;
wheel.castShadow = true;
group.add(wheel);
}
}
const label = makeLabel(`TEAM ${team.id}`, {
width: 210,
height: 64,
worldWidth: 5.3,
fontSize: 26,
background: "rgba(26,39,48,.92)",
border: team.css
});
label.position.set(0, 3.6, 0);
group.add(label);
group.position.set(-13.5 + index * 3.5, 0, 26.6);
group.rotation.y = Math.PI;
scene.add(group);
vehicleMap.set(team.id, { group, beaconMaterial });
}
function createRequestMarker(report) {
const group = new THREE.Group();
const confirmed = report.locationConfirmed;
const color = confirmed ? 0x38b8ad : 0xf0b44d;
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.25, 1.25, 0.34, 16),
new THREE.MeshStandardMaterial({ color: 0xf2f6f5, roughness: 0.85 })
);
base.position.y = 0.34;
base.castShadow = true;
group.add(base);
const icon = new THREE.Mesh(
confirmed
? new THREE.CylinderGeometry(0.62, 0.62, 0.48, 16)
: new THREE.OctahedronGeometry(0.78),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.17,
roughness: 0.55
})
);
icon.position.y = 1.05;
icon.castShadow = true;
group.add(icon);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.07, 2.2, 8),
new THREE.MeshStandardMaterial({ color })
);
stem.position.y = 1.3;
group.add(stem);
const uncertainty = new THREE.Group();
const disk = new THREE.Mesh(
new THREE.CircleGeometry(4.3, 40),
new THREE.MeshBasicMaterial({
color: 0xf0b44d,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
disk.rotation.x = -Math.PI / 2;
disk.position.y = 0.23;
uncertainty.add(disk);
const boundaryPoints = [];
for (let i = 0; i < 48; i++) {
const angle = i / 48 * Math.PI * 2;
boundaryPoints.push(new THREE.Vector3(
Math.cos(angle) * 4.3,
0.255,
Math.sin(angle) * 4.3
));
}
const boundary = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(boundaryPoints),
new THREE.LineDashedMaterial({
color: 0xf0b44d,
dashSize: 0.65,
gapSize: 0.45,
transparent: true,
opacity: 0.9
})
);
boundary.computeLineDistances();
uncertainty.add(boundary);
uncertainty.visible = !confirmed;
group.add(uncertainty);
const assignmentRing = new THREE.Mesh(
new THREE.TorusGeometry(1.75, 0.15, 6, 28),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
assignmentRing.rotation.x = Math.PI / 2;
assignmentRing.position.y = 0.57;
assignmentRing.visible = false;
group.add(assignmentRing);
const label = makeLabel(report.id, {
width: 240,
height: 64,
worldWidth: 6.6,
fontSize: 27,
background: confirmed ? "rgba(28,94,88,.94)" : "rgba(117,78,31,.94)",
border: confirmed ? "rgba(116,207,199,.7)" : "rgba(240,180,77,.8)"
});
label.position.set(0, 4.25, 0);
group.add(label);
group.position.set(report.visibleLocation.x, 0, report.visibleLocation.z);
group.visible = false;
scene.add(group);
markerMap.set(report.id, {
group,
icon,
uncertainty,
assignmentRing,
label
});
}
function createTruthMarker(report) {
if (report.locationConfirmed) return;
const truth = TRUE_EVENT_STATE[report.id];
const node = NODES[truth.accessNode];
const x = node.x + truth.offset[0];
const z = node.z + truth.offset[1];
const group = new THREE.Group();
const diamond = new THREE.Mesh(
new THREE.OctahedronGeometry(1.05),
new THREE.MeshStandardMaterial({
color: 0x9b8be8,
emissive: 0x6553b3,
emissiveIntensity: 0.3,
roughness: 0.5
})
);
diamond.position.y = 1.25;
diamond.castShadow = true;
group.add(diamond);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.07, 2.4, 8),
new THREE.MeshBasicMaterial({ color: 0x9b8be8 })
);
stem.position.y = 1.3;
group.add(stem);
const label = makeLabel(`TRUE · ${truth.accessNode.toUpperCase()}`, {
width: 280,
height: 64,
worldWidth: 7.5,
fontSize: 25,
background: "rgba(76,59,137,.95)",
border: "rgba(183,168,255,.8)",
color: "#f2efff"
});
label.position.set(0, 4.1, 0);
group.add(label);
group.position.set(x, 0, z);
group.visible = false;
scene.add(group);
truthMarkerMap.set(report.id, group);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(report.visibleLocation.x, 0.36, report.visibleLocation.z),
new THREE.Vector3(x, 0.36, z)
]),
new THREE.LineDashedMaterial({
color: 0x9b8be8,
dashSize: 0.9,
gapSize: 0.65,
transparent: true,
opacity: 0.9
})
);
line.computeLineDistances();
line.visible = false;
scene.add(line);
truthLineMap.set(report.id, line);
}
function initScene() {
const board = new THREE.Mesh(
new THREE.BoxGeometry(92, 1.4, 72),
new THREE.MeshStandardMaterial({ color: 0xcdd8d3, roughness: 0.96 })
);
board.position.y = -0.82;
board.receiveShadow = true;
board.castShadow = true;
scene.add(board);
const edge = new THREE.Mesh(
new THREE.BoxGeometry(92.6, 0.55, 72.6),
new THREE.MeshStandardMaterial({ color: 0x8fa4a7, roughness: 0.8 })
);
edge.position.y = -1.45;
edge.castShadow = true;
scene.add(edge);
for (const [a, b] of Object.entries(graph)) {
for (const edgeInfo of graph[a]) {
if (a < edgeInfo.node) addRoadSegment(a, edgeInfo.node);
}
}
createNeighborhoods();
createDepot();
TEAMS.forEach(createVehicle);
for (const report of DISPATCHER_REPORTS) {
createRequestMarker(report);
createTruthMarker(report);
}
resetCamera();
}
function clearRoutes() {
while (routeGroup.children.length) {
const child = routeGroup.children.pop();
child.geometry?.dispose();
child.material?.dispose();
}
}
function syncSceneState() {
for (const report of DISPATCHER_REPORTS) {
const marker = markerMap.get(report.id);
marker.group.visible = state.arrived.has(report.id);
const teamId = state.assignments[state.mode][report.id];
marker.assignmentRing.visible = Boolean(teamId);
if (teamId) {
marker.assignmentRing.material.color.setHex(teamById[teamId].color);
}
const truthMarker = truthMarkerMap.get(report.id);
const truthLine = truthLineMap.get(report.id);
if (truthMarker) {
truthMarker.visible = state.truthVisible && state.arrived.has(report.id);
truthLine.visible = truthMarker.visible;
}
}
for (const team of TEAMS) {
const vehicle = vehicleMap.get(team.id);
vehicle.beaconMaterial.color.setHex(team.color);
vehicle.beaconMaterial.emissive.setHex(team.color);
}
clearRoutes();
for (const [requestId, teamId] of Object.entries(state.assignments[state.mode])) {
const report = reportById[requestId];
if (!report || !state.arrived.has(requestId)) continue;
const { path } = shortestPath(DEPOT_NODE, report.visibleLocation.node);
const points = path.map(id => {
const node = NODES[id];
return new THREE.Vector3(node.x, 0.36, node.z);
});
if (points.length < 2) continue;
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: teamById[teamId].color,
transparent: true,
opacity: 0.9
})
);
routeGroup.add(line);
const destination = points[points.length - 1].clone();
destination.y = 0.39;
const endpoint = new THREE.Mesh(
new THREE.RingGeometry(0.85, 1.15, 18),
new THREE.MeshBasicMaterial({
color: teamById[teamId].color,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9
})
);
endpoint.rotation.x = -Math.PI / 2;
endpoint.position.copy(destination);
routeGroup.add(endpoint);
}
}
// ---------- Interface rendering ----------
function showToast(message) {
const toast = $("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2400);
}
function renderReports() {
const list = $("reportList");
const visibleReports = DISPATCHER_REPORTS.filter(report =>
state.mode === "all" || report.locationConfirmed
);
$("requestCount").textContent = `${state.arrived.size} received`;
const excluded = $("modeExcludedNote");
const uncertainCount = DISPATCHER_REPORTS.filter(r =>
state.arrived.has(r.id) && !r.locationConfirmed
).length;
if (state.mode === "confirmed" && uncertainCount) {
excluded.hidden = false;
excluded.textContent =
`${uncertainCount} uncertain report${uncertainCount === 1 ? " is" : "s are"} ` +
`outside this view. Exclusion does not resolve them.`;
} else {
excluded.hidden = true;
}
list.innerHTML = "";
for (const report of visibleReports) {
const arrived = state.arrived.has(report.id);
const assignedTeam = state.assignments[state.mode][report.id];
const card = document.createElement("article");
card.className = "report-card";
card.classList.add(report.locationConfirmed ? "confirmed" : "uncertain");
if (!arrived) card.classList.add("pending");
if (state.selectedRequest === report.id) card.classList.add("selected");
const teamOptions = TEAMS.map(team => {
const occupant = teamOccupant(state.mode, team.id);
const disabled = occupant && occupant !== report.id;
return `<option value="${team.id}" ${assignedTeam === team.id ? "selected" : ""} ${disabled ? "disabled" : ""}>
${team.name}${disabled ? " — occupied" : ""}
</option>`;
}).join("");
card.innerHTML = `
<div class="report-top">
<span class="report-id">${report.id}</span>
<span class="timestamp">${report.arrival}</span>
</div>
<h3>${report.title}</h3>
<div class="need">${report.need}</div>
<div class="location">◎ ${report.visibleLocation.label}</div>
<div class="report-meta">
<span class="status ${report.locationConfirmed ? "confirmed" : "uncertain"}">
${report.locationConfirmed ? "●" : "◇"} ${arrived ? report.detailState : "Pending arrival"}
</span>
${arrived ? `<button class="locate" type="button">Locate</button>` : ""}
</div>
${arrived ? `
<div class="assign-row">
<label for="assign-${report.id}">Assigned team</label>
<select id="assign-${report.id}" aria-label="Assign ${report.id}">
<option value="" ${!assignedTeam ? "selected" : ""}>Unassigned</option>
${teamOptions}
</select>
</div>
` : ""}
`;
if (arrived) {
card.addEventListener("click", event => {
if (event.target.closest("select, button")) return;
state.selectedRequest = report.id;
renderAll();
});
card.querySelector(".locate").addEventListener("click", event => {
event.stopPropagation();
state.selectedRequest = report.id;
focusOn(report.visibleLocation.x, report.visibleLocation.z);
renderAll();
showToast(`${report.id}: ${report.visibleLocation.label}`);
});
card.querySelector("select").addEventListener("change", event => {
event.stopPropagation();
assignRequest(report.id, event.target.value || null);
});
}
list.appendChild(card);
}
}
function renderTeams() {
const list = $("teamList");
list.innerHTML = "";
for (const team of TEAMS) {
const requestId = teamOccupant(state.mode, team.id);
const report = requestId ? reportById[requestId] : null;
const assignedToSelected = state.selectedRequest &&
state.assignments[state.mode][state.selectedRequest] === team.id;
const row = document.createElement("div");
row.className = "team-card";
row.innerHTML = `
<div class="team-badge" style="background:${team.css}">${team.id}</div>
<div>
<div class="team-name">${team.name}</div>
<div class="team-detail">
${report
? `${report.id} · ${report.visibleLocation.label}<br>${roundTripMinutes(report).toFixed(1)} min round trip`
: "Available · no request assigned"}
</div>
</div>
<button class="team-action" type="button" ${!state.selectedRequest ? "disabled" : ""}>
${assignedToSelected ? "Assigned" : "Take selected"}
</button>
`;
row.querySelector("button").addEventListener("click", () => {
assignRequest(state.selectedRequest, team.id);
});
list.appendChild(row);
}
}
function renderComparison() {
const all = planMetrics("all");
const confirmed = planMetrics("confirmed");
const difference = all.travel - confirmed.travel;
let insight;
if (!all.excluded) {
insight = "No uncertain arrivals have arrived yet.";
} else {
const verb = difference >= 0 ? "saves" : "adds";
insight =
`Confirmed-only ${verb} ${Math.abs(difference).toFixed(1)} modeled minutes, ` +
`but excludes ${all.excluded} uncertain arrival${all.excluded === 1 ? "" : "s"}. ` +
`Those requests are not resolved.`;
}
$("comparison").innerHTML = `
<div class="compare-row ${state.mode === "all" ? "current" : ""}">
<div>
<div class="compare-title">All reports</div>
<div class="compare-sub">
${all.assigned}/${all.pool} assigned · ${all.unresolved} unresolved
</div>
</div>
<div class="compare-travel">${all.travel.toFixed(1)} min</div>
</div>
<div class="compare-row ${state.mode === "confirmed" ? "current" : ""}">
<div>
<div class="compare-title">Confirmed reports only</div>
<div class="compare-sub">
${confirmed.assigned}/${confirmed.pool} assigned · ${confirmed.unresolved} unresolved in pool
</div>
</div>
<div class="compare-travel">${confirmed.travel.toFixed(1)} min</div>
</div>
<div class="compare-insight">${insight}</div>
`;
}
function renderHud() {
const metrics = planMetrics(state.mode);
$("hudArrivals").textContent = `${state.arrived.size} / ${DISPATCHER_REPORTS.length}`;
$("hudUnresolved").textContent = String(metrics.unresolved);
$("hudTravel").textContent = `${metrics.travel.toFixed(1)} min`;
$("sceneMode").textContent = state.mode === "all"
? "Plan: All reports"
: "Plan: Confirmed reports only";
}
function renderTimeline() {
const arrived = DISPATCHER_REPORTS.filter(r => state.arrived.has(r.id));
const last = arrived[arrived.length - 1];
$("clockText").textContent = last ? last.arrival : "08:00";
$("timelineFill").style.width =
`${state.arrived.size / DISPATCHER_REPORTS.length * 100}%`;
}
function renderTruth() {
$("truthBtn").textContent = state.truthVisible
? "Hide toy truth"
: "Reveal toy truth";
if (!state.truthVisible) {
$("truthReadout").innerHTML =
"The hidden layer contains the actual synthetic access points for uncertain reports.";
return;
}
const uncertainArrived = DISPATCHER_REPORTS.filter(r =>
state.arrived.has(r.id) && !r.locationConfirmed
);
const currentAssignments = Object.entries(state.assignments[state.mode]);
const misses = currentAssignments.filter(([requestId]) => {
const report = reportById[requestId];
if (!report || report.locationConfirmed) return false;
return report.visibleLocation.node !== TRUE_EVENT_STATE[requestId].accessNode;
});
const rows = uncertainArrived.length
? uncertainArrived.map(report => {
const truth = TRUE_EVENT_STATE[report.id];
return `<div class="truth-row">
<b>${report.id}</b> — dispatcher saw
${report.visibleLocation.label}.<br>
Actual synthetic access: ${truth.actualAccess}.
</div>`;
}).join("")
: `<div class="truth-row">No uncertain reports have arrived yet.</div>`;
$("truthReadout").innerHTML = `
${rows}
<div class="truth-row">
<b>Current ${state.mode === "all" ? "all-report" : "confirmed-only"} plan:</b>
${misses.length
? `${misses.length} assigned route${misses.length === 1 ? "" : "s"} land on a different access node in the toy truth.`
: "No currently assigned route lands on a different access node."}
Modeled travel remains based only on dispatcher-visible estimates.
</div>
`;
}
function renderMode() {
$("modeAll").classList.toggle("active", state.mode === "all");
$("modeConfirmed").classList.toggle("active", state.mode === "confirmed");
if (state.mode === "all") {
$("modeNote").textContent =
"All received reports are eligible, including uncertain access estimates.";
} else {
$("modeNote").textContent =
"Only reports with confirmed details are eligible. Uncertain arrivals are excluded, not solved.";
}
}
function renderAll() {
renderMode();
renderReports();
renderTeams();
renderComparison();
renderHud();
renderTimeline();
renderTruth();
syncSceneState();
}
// ---------- Assignment behavior ----------
function assignRequest(requestId, teamId) {
if (!requestId) return;
const report = reportById[requestId];
const pool = arrivedReports();
if (!pool.some(r => r.id === requestId)) return;
if (teamId) {
const occupant = teamOccupant(state.mode, teamId);
if (occupant && occupant !== requestId) {
showToast(`${teamById[teamId].name} is already assigned to ${occupant}.`);
return;
}
}
state.selectedRequest = requestId;
if (teamId) {
state.assignments[state.mode][requestId] = teamId;
} else {
delete state.assignments[state.mode][requestId];
}
renderAll();
}
function fillCurrentPlan() {
const pool = arrivedReports();
const freeTeams = TEAMS.filter(team => !teamOccupant(state.mode, team.id));
const unassigned = pool.filter(report =>
!state.assignments[state.mode][report.id]
);
unassigned.sort((a, b) =>
roundTripMinutes(a) - roundTripMinutes(b)
);
let count = 0;
for (const report of unassigned) {
const team = freeTeams.shift();
if (!team) break;
state.assignments[state.mode][report.id] = team.id;
count++;
}
renderAll();
showToast(count
? `Assigned ${count} request${count === 1 ? "" : "s"} to the nearest available teams.`
: "No unassigned requests or available teams.");
}
function clearCurrentPlan() {
state.assignments[state.mode] = {};
renderAll();
showToast(`${state.mode === "all" ? "All-report" : "Confirmed-only"} plan cleared.`);
}
// ---------- Deterministic replay and arrival timing ----------
function stopPlayback() {
state.playing = false;
clearInterval(arrivalTimer);
arrivalTimer = null;
$("playBtn").textContent = "Resume";
}
function advanceArrival() {
const next = DISPATCHER_REPORTS.find(r => !state.arrived.has(r.id));
if (!next) {
stopPlayback();
return;
}
state.arrived.add(next.id);
renderAll();
showToast(`${next.id} received at ${next.arrival}: ${next.title}`);
if (state.arrived.size === DISPATCHER_REPORTS.length) {
stopPlayback();
}
}
function startPlayback() {
if (state.arrived.size === DISPATCHER_REPORTS.length) {
showToast("All reports have arrived. Replay to restore the same starting state.");
return;
}
state.playing = true;
$("playBtn").textContent = "Pause";
clearInterval(arrivalTimer);
arrivalTimer = setInterval(advanceArrival, 1050);
}
function resetScenario(autoPlay = false) {
stopPlayback();
state.arrived = new Set();
state.assignments = { all: {}, confirmed: {} };
state.mode = "all";
state.selectedRequest = null;
state.truthVisible = false;
resetCamera();
renderAll();
if (autoPlay) {
setTimeout(startPlayback, 300);
}
}
// ---------- Direct camera controls (no addons) ----------
let dragging = false;
let dragButton = 0;
let previousPointer = { x: 0, y: 0 };
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragButton = event.button;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
if (dragButton === 2 || event.shiftKey) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 1);
const scale = cameraRadius * 0.0014;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(up, dy * scale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -42, 42);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -36, 36);
} else {
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.006, 0.28, 1.28);
}
applyCamera();
});
function endPointerDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointerDrag);
renderer.domElement.addEventListener("pointercancel", endPointerDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
42,
145
);
applyCamera();
}, { passive: false });
$("zoomIn").addEventListener("click", () => {
cameraRadius = Math.max(42, cameraRadius * 0.86);
applyCamera();
});
$("zoomOut").addEventListener("click", () => {
cameraRadius = Math.min(145, cameraRadius * 1.16);
applyCamera();
});
$("cameraReset").addEventListener("click", resetCamera);
// ---------- UI events ----------
$("modeAll").addEventListener("click", () => {
state.mode = "all";
if (!arrivedReports("all").some(r => r.id === state.selectedRequest)) {
state.selectedRequest = null;
}
renderAll();
});
$("modeConfirmed").addEventListener("click", () => {
state.mode = "confirmed";
if (!arrivedReports("confirmed").some(r => r.id === state.selectedRequest)) {
state.selectedRequest = null;
}
renderAll();
});
$("fillBtn").addEventListener("click", fillCurrentPlan);
$("clearBtn").addEventListener("click", clearCurrentPlan);
$("truthBtn").addEventListener("click", () => {
state.truthVisible = !state.truthVisible;
renderAll();
});
$("replayBtn").addEventListener("click", () => resetScenario(true));
$("playBtn").addEventListener("click", () => {
if (state.playing) stopPlayback();
else startPlayback();
});
$("nextBtn").addEventListener("click", () => {
stopPlayback();
advanceArrival();
});
// ---------- Resize and animation ----------
function resize() {
const width = Math.max(1, host.clientWidth);
const height = Math.max(1, host.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(host);
function animate(time) {
const pulse = 1 + Math.sin(time * 0.004) * 0.07;
for (const [id, marker] of markerMap) {
if (state.selectedRequest === id) {
marker.icon.scale.setScalar(pulse);
} else {
marker.icon.scale.setScalar(1);
}
}
for (const marker of truthMarkerMap.values()) {
marker.rotation.y = time * 0.0007;
}
renderer.render(scene, camera);
}
initScene();
resize();
resetScenario(true);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```