Prompt specification
Build or customize the Three.js 3D scene "Storm Cleanup Task Coordination" 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: Storm Cleanup Task Coordination
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/storm-cleanup-task-coordination-x3227
Scene Description Prompt:
Coordinate branch reports, authorized cleanup, and path reopening around a fictional voxel volunteer depot. Create one HTML scene with Three.js from cdnjs.
Working Three.js Starter (storm-cleanup-task-coordination-x3227):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Common Ground — Voxel Volunteer Depot</title>
<style>
:root {
color-scheme: dark;
--bg: #08131b;
--panel: rgba(12, 27, 36, 0.92);
--panel-edge: rgba(160, 211, 218, 0.15);
--text: #eaf5f4;
--muted: #8ca6ad;
--cyan: #64dfca;
--amber: #ffc857;
--coral: #ff786b;
--blue: #72b7ff;
--violet: #c899f2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button {
font: inherit;
}
#scene-wrap,
#scene-wrap canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#scene-wrap canvas {
display: block;
cursor: grab;
touch-action: none;
}
#scene-wrap canvas:active {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
min-width: 118px;
padding: 8px 11px;
border: 1px solid rgba(155, 218, 218, 0.23);
border-radius: 9px;
background: rgba(6, 18, 25, 0.86);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
color: #eafffb;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.05em;
white-space: nowrap;
transform: translate(-50%, -100%);
backdrop-filter: blur(8px);
}
.world-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.07em;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 1px;
height: 7px;
background: rgba(155, 218, 218, 0.4);
}
.world-label.depot-label {
border-color: rgba(100, 223, 202, 0.38);
background: rgba(7, 31, 35, 0.9);
}
.label-dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px currentColor;
}
.topbar {
position: absolute;
z-index: 5;
top: 18px;
left: 20px;
right: 20px;
height: 54px;
display: flex;
align-items: center;
gap: 16px;
padding: 0 14px;
border: 1px solid var(--panel-edge);
border-radius: 14px;
background: rgba(8, 21, 29, 0.88);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
}
.brand {
display: flex;
align-items: center;
min-width: 255px;
gap: 11px;
}
.brand-mark {
position: relative;
width: 28px;
height: 28px;
border: 2px solid var(--cyan);
border-radius: 5px;
transform: rotate(30deg) skew(-7deg);
box-shadow: inset 0 0 0 5px rgba(100, 223, 202, 0.08);
}
.brand-mark::after {
content: "";
position: absolute;
inset: 6px;
border-radius: 2px;
background: var(--cyan);
}
.brand strong {
display: block;
font-size: 12px;
letter-spacing: 0.12em;
}
.brand span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
}
.hud {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
margin-left: auto;
}
.hud-chip {
display: flex;
align-items: center;
gap: 8px;
min-height: 32px;
padding: 0 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.hud-chip b {
color: var(--text);
font-size: 12px;
}
.chip-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 10px rgba(255, 120, 107, 0.6);
}
#reset-view {
height: 32px;
padding: 0 11px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#reset-view:hover {
border-color: rgba(100, 223, 202, 0.45);
background: rgba(100, 223, 202, 0.08);
}
.panel {
position: absolute;
z-index: 4;
border: 1px solid var(--panel-edge);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
.reports-panel {
top: 86px;
bottom: 20px;
left: 20px;
width: 310px;
padding: 18px;
overflow: auto;
}
.inspector-panel {
top: 86px;
right: 20px;
width: 350px;
padding: 20px;
}
.eyebrow {
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.panel-title {
margin: 6px 0 4px;
font-size: 19px;
letter-spacing: -0.02em;
}
.panel-subtitle {
margin: 0 0 16px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.branch-list {
display: grid;
gap: 9px;
}
.branch-card {
position: relative;
width: 100%;
overflow: hidden;
padding: 13px;
border: 1px solid rgba(255, 255, 255, 0.075);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
color: var(--text);
text-align: left;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.branch-card:hover {
transform: translateY(-1px);
border-color: rgba(100, 223, 202, 0.27);
background: rgba(255, 255, 255, 0.045);
}
.branch-card.selected {
border-color: rgba(100, 223, 202, 0.55);
background: rgba(100, 223, 202, 0.08);
box-shadow: inset 3px 0 0 var(--cyan);
}
.card-top,
.card-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.branch-code {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
}
.branch-card h3 {
margin: 6px 0 3px;
font-size: 13px;
}
.branch-issue {
color: #b8c9cc;
font-size: 10px;
line-height: 1.45;
}
.status-pill {
flex: none;
padding: 5px 7px;
border-radius: 999px;
background: rgba(255, 120, 107, 0.1);
color: var(--coral);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-pill[data-state="progress"] {
background: rgba(255, 200, 87, 0.11);
color: var(--amber);
}
.status-pill[data-state="ready"] {
background: rgba(114, 183, 255, 0.12);
color: var(--blue);
}
.status-pill[data-state="open"] {
background: rgba(100, 223, 202, 0.11);
color: var(--cyan);
}
.card-bottom {
margin-top: 11px;
}
.card-time {
color: #6f8b92;
font-size: 9px;
}
.mini-progress {
width: 66px;
height: 3px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.08);
}
.mini-progress i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--amber);
transition: width 140ms linear;
}
.detail-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.detail-top h2 {
margin: 7px 0 0;
font-size: 23px;
letter-spacing: -0.035em;
}
.severity {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.report-box {
margin: 18px 0;
padding: 13px;
border-left: 3px solid var(--coral);
border-radius: 0 9px 9px 0;
background: rgba(255, 255, 255, 0.035);
}
.report-box p {
margin: 0;
color: #c5d4d6;
font-size: 11px;
line-height: 1.65;
}
.report-box small {
display: block;
margin-top: 8px;
color: #78939a;
font-size: 9px;
}
.workflow {
display: grid;
gap: 0;
margin: 19px 0;
padding: 0;
list-style: none;
}
.workflow li {
position: relative;
min-height: 47px;
padding: 0 0 14px 34px;
color: #708990;
font-size: 10px;
line-height: 1.45;
}
.workflow li::before {
content: attr(data-step);
position: absolute;
top: 0;
left: 0;
display: grid;
width: 22px;
height: 22px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 50%;
background: #142832;
color: #708990;
font-size: 9px;
font-weight: 800;
}
.workflow li::after {
content: "";
position: absolute;
top: 23px;
bottom: 3px;
left: 10px;
width: 1px;
background: rgba(255, 255, 255, 0.09);
}
.workflow li:last-child::after {
display: none;
}
.workflow li strong {
display: block;
margin-bottom: 2px;
color: #9eb3b8;
font-size: 10px;
}
.workflow li.active::before {
border-color: var(--amber);
color: var(--amber);
box-shadow: 0 0 16px rgba(255, 200, 87, 0.15);
}
.workflow li.active strong {
color: var(--amber);
}
.workflow li.complete::before {
border-color: var(--cyan);
background: var(--cyan);
color: #09221e;
}
.workflow li.complete strong {
color: var(--cyan);
}
.progress-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 3px 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.progress-track {
height: 7px;
overflow: hidden;
margin-bottom: 16px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.07);
}
.progress-track i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #ffb648, #ffe1a0);
box-shadow: 0 0 15px rgba(255, 200, 87, 0.4);
transition: width 120ms linear;
}
.action-stack {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.action {
min-height: 43px;
padding: 0 12px;
border-radius: 9px;
cursor: pointer;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.045em;
transition:
transform 150ms ease,
opacity 150ms ease,
background 150ms ease;
}
.action:hover:not(:disabled) {
transform: translateY(-1px);
}
.action.primary {
border: 1px solid var(--cyan);
background: var(--cyan);
color: #09221e;
}
.action.secondary {
border: 1px solid rgba(114, 183, 255, 0.45);
background: rgba(114, 183, 255, 0.08);
color: var(--blue);
}
.action:disabled {
cursor: not-allowed;
opacity: 0.32;
}
.authorization-note {
margin: 12px 0 0;
color: #627d84;
font-size: 9px;
line-height: 1.5;
text-align: center;
}
.bottom-hint {
position: absolute;
z-index: 3;
left: 50%;
bottom: 18px;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 8px;
background: rgba(6, 17, 23, 0.7);
color: #69868e;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.04em;
transform: translateX(-50%);
pointer-events: none;
backdrop-filter: blur(8px);
}
.toast {
position: absolute;
z-index: 8;
left: 50%;
top: 85px;
max-width: min(420px, calc(100vw - 40px));
padding: 11px 15px;
border: 1px solid rgba(100, 223, 202, 0.3);
border-radius: 9px;
background: rgba(8, 28, 33, 0.95);
color: #dffbf7;
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.35);
font-size: 11px;
opacity: 0;
transform: translate(-50%, -10px);
transition:
opacity 200ms ease,
transform 200ms ease;
pointer-events: none;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1100px) {
.reports-panel {
width: 270px;
}
.inspector-panel {
width: 320px;
}
.hud-chip:nth-child(2) {
display: none;
}
}
@media (max-width: 760px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
min-width: 0;
}
.brand span,
.hud-chip {
display: none;
}
.reports-panel {
top: 75px;
left: 10px;
bottom: auto;
width: 235px;
max-height: 42vh;
padding: 13px;
}
.inspector-panel {
top: auto;
right: 10px;
bottom: 45px;
width: min(330px, calc(100vw - 20px));
padding: 15px;
}
.bottom-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene-wrap"></div>
<div id="labels"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark"></div>
<div>
<strong>COMMON GROUND</strong>
<span>Volunteer depot network · operations 04</span>
</div>
</div>
<div class="hud">
<div class="hud-chip">
<span class="chip-dot"></span>
Open reports <b id="open-count">3</b>
</div>
<div class="hud-chip">
Active crews <b id="crew-count">0</b>
</div>
<div class="hud-chip">
Paths reopened <b id="reopen-count">0</b>
</div>
<button id="reset-view" type="button">Reset view</button>
</div>
</header>
<aside class="panel reports-panel">
<div class="eyebrow">Field queue</div>
<h2 class="panel-title">Branch reports</h2>
<p class="panel-subtitle">
Select a branch to review its field report and coordinate access.
</p>
<div id="branch-list" class="branch-list"></div>
</aside>
<aside class="panel inspector-panel">
<div class="detail-top">
<div>
<div class="eyebrow" id="detail-code">BR-12</div>
<h2 id="detail-title">Riverbend branch</h2>
<div class="severity" id="detail-severity">Priority report</div>
</div>
<div id="detail-status" class="status-pill">Report received</div>
</div>
<div class="report-box">
<p id="detail-report"></p>
<small id="detail-reporter"></small>
</div>
<ol class="workflow">
<li id="step-report" class="complete" data-step="1">
<strong>Report verified</strong>
Branch condition recorded.
</li>
<li id="step-cleanup" data-step="2">
<strong>Authorize cleanup</strong>
Send a volunteer crew after sign-off.
</li>
<li id="step-reopen" data-step="3">
<strong>Reopen branch path</strong>
Restore access after cleanup is complete.
</li>
</ol>
<div class="progress-heading">
<span>Cleanup completion</span>
<span id="progress-value">0%</span>
</div>
<div class="progress-track"><i id="progress-fill"></i></div>
<div class="action-stack">
<button id="authorize-btn" class="action primary" type="button">
Authorize cleanup
</button>
<button id="reopen-btn" class="action secondary" type="button" disabled>
Reopen path
</button>
</div>
<p class="authorization-note">
Field work starts only after authorization. Paths reopen only after cleanup.
</p>
</aside>
<div class="bottom-hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom · R to reset
</div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const sceneWrap = document.querySelector("#scene-wrap");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08131b);
scene.fog = new THREE.Fog(0x08131b, 47, 82);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
sceneWrap.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(
-25,
25,
18,
-18,
0.1,
160
);
const hemisphere = new THREE.HemisphereLight(0xb9e8ff, 0x19332e, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe9c4, 3.4);
sun.position.set(-16, 30, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.0008;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x6bd8ff, 1.25);
rimLight.position.set(20, 14, -24);
scene.add(rimLight);
// Shared unit cube; all visible architecture is assembled from voxel boxes.
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function solidMaterial(color) {
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0.03
})
);
}
return materialCache.get(key);
}
function glowMaterial(color, intensity = 0.42) {
return new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: intensity,
roughness: 0.55,
metalness: 0.05
});
}
function box(
parent,
x,
y,
z,
width,
height,
depth,
colorOrMaterial,
castShadow = true
) {
const material = colorOrMaterial?.isMaterial
? colorOrMaterial
: solidMaterial(colorOrMaterial);
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 42;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// -------------------------------------------------------------------------
// Depot platform
// -------------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
box(world, 0, -0.72, 0, 34, 1.2, 26, 0x102a31, false);
const tileColors = [
0x244047,
0x29474b,
0x213d43,
0x2c4c4c,
0x294348
];
for (let ix = 0; ix < 16; ix++) {
for (let iz = 0; iz < 12; iz++) {
const x = -15 + ix * 2;
const z = -11 + iz * 2;
const color = tileColors[Math.floor(random() * tileColors.length)];
box(world, x, -0.03, z, 1.92, 0.16, 1.92, color, false);
}
}
// Platform edge and corner blocks.
box(world, 0, 0.02, -12.75, 34, 0.22, 0.35, 0x426267, false);
box(world, 0, 0.02, 12.75, 34, 0.22, 0.35, 0x426267, false);
box(world, -16.75, 0.02, 0, 0.35, 0.22, 26, 0x426267, false);
box(world, 16.75, 0.02, 0, 0.35, 0.22, 26, 0x426267, false);
// Central paved plaza.
box(world, -2, 0.09, -1, 15, 0.14, 11, 0x33494b, false);
box(world, -2, 0.18, 4.2, 15, 0.1, 1.6, 0x42585a, false);
// -------------------------------------------------------------------------
// Main volunteer depot
// -------------------------------------------------------------------------
const depot = new THREE.Group();
world.add(depot);
box(depot, -2, 0.28, -1, 12, 0.38, 8, 0x455b5c);
// Back masonry wall.
for (let i = 0; i < 12; i++) {
const x = -7.5 + i;
const color = i % 3 === 0 ? 0xc4bba1 : 0xd3cbb4;
box(depot, x, 1.65, -4.65, 0.96, 2.65, 0.42, color);
}
// Side wall blocks.
for (let i = 0; i < 7; i++) {
const z = -4 + i;
box(depot, -7.7, 1.45, z, 0.42, 2.35, 0.93, 0xc8bea7);
box(depot, 3.7, 1.45, z, 0.42, 2.35, 0.93, 0xc8bea7);
}
// Front columns and lintels leave an open, readable depot interior.
for (const x of [-7.3, -3.6, 0.1, 3.4]) {
box(depot, x, 1.75, 2.8, 0.48, 3.1, 0.48, 0xd8cfb7);
}
box(depot, -2, 3.38, 2.8, 11.4, 0.45, 0.55, 0x68b7aa);
// Stepped teal roof over the rear half.
box(depot, -2, 3.35, -3.85, 12.2, 0.48, 2.1, 0x388f86);
box(depot, -2, 3.66, -3.85, 11.3, 0.32, 1.55, 0x56b3a5);
box(depot, -2, 3.92, -3.85, 10.4, 0.22, 1.05, 0x77c7b6);
// Side awnings.
box(depot, -7.7, 3.15, -0.3, 1.45, 0.32, 6.5, 0x3d9489);
box(depot, 3.7, 3.15, -0.3, 1.45, 0.32, 6.5, 0x3d9489);
// Illuminated windows.
for (const x of [-5.8, -2.8, 0.2, 2.1]) {
box(depot, x, 1.75, -4.39, 1.55, 1.25, 0.12, glowMaterial(0xffd783, 0.55), false);
box(depot, x, 1.75, -4.29, 0.12, 1.3, 0.13, 0x546665, false);
}
// Interior shelving.
for (const x of [-5.4, -1.4, 1.7]) {
box(depot, x, 1.12, -3.65, 2.8, 0.18, 0.75, 0x775d45);
box(depot, x, 1.9, -3.65, 2.8, 0.18, 0.75, 0x775d45);
box(depot, x, 1.55, -3.65, 2.8, 0.12, 0.75, 0x775d45);
for (let i = 0; i < 4; i++) {
box(depot, x - 0.95 + i * 0.63, 1.46, -3.63, 0.35, 0.45, 0.38, 0x9b7048);
box(depot, x - 0.95 + i * 0.63, 2.23, -3.63, 0.35, 0.4, 0.38, 0x6e9b76);
}
}
// Registration desk and supplies.
box(depot, -1.4, 0.83, 0.65, 3.6, 0.9, 1.25, 0x9c744c);
box(depot, -1.4, 1.33, 0.65, 3.85, 0.18, 1.42, 0xc29a68);
box(depot, -2.1, 1.75, 0.55, 0.75, 0.55, 0.18, glowMaterial(0x72b7ff, 0.45), false);
box(depot, 0.1, 1.62, 0.55, 0.42, 0.3, 0.32, 0xe0d9bd);
// Crates outside.
for (let i = 0; i < 6; i++) {
const x = 3.1 + (i % 2) * 0.85;
const z = 1.2 + Math.floor(i / 2) * 0.82;
box(depot, x, 0.62, z, 0.72, 0.72, 0.72, i % 2 ? 0x9b7048 : 0xb18458);
box(depot, x, 0.65, z + 0.37, 0.58, 0.12, 0.05, 0x6e553f, false);
}
// Depot sign.
box(depot, -2, 2.75, -4.42, 4.2, 0.65, 0.16, 0x1f554f);
for (let i = 0; i < 5; i++) {
box(depot, -3.35 + i * 0.68, 2.76, -4.31, 0.35, 0.22, 0.08, glowMaterial(0xbff4df, 0.55), false);
}
// -------------------------------------------------------------------------
// Branch definitions and shared state
// -------------------------------------------------------------------------
const branchDefinitions = [
{
id: "BR-12",
name: "Riverbend branch",
issue: "Storm debris blocking the lower footbridge.",
reporter: "Lina R. · 14 minutes ago",
severity: "Priority report",
accent: 0x72b7ff,
x: 11,
z: 6,
pathStart: new THREE.Vector2(2.5, 1.6),
pathEnd: new THREE.Vector2(9.8, 5.4),
obstacleAt: new THREE.Vector2(9.6, 5.2),
crewName: "Crew 04",
obstacleType: "wood"
},
{
id: "BR-07",
name: "North pantry branch",
issue: "Empty pallet stacks obstructing pantry access.",
reporter: "Mae T. · 26 minutes ago",
severity: "Routine report",
accent: 0xffc857,
x: 9,
z: -7,
pathStart: new THREE.Vector2(1.5, -2.5),
pathEnd: new THREE.Vector2(8, -6.4),
obstacleAt: new THREE.Vector2(8.3, -6.1),
crewName: "Crew 02",
obstacleType: "pallets"
},
{
id: "BR-09",
name: "Old Mill branch",
issue: "Fallen limbs narrowing the western orchard approach.",
reporter: "Omar K. · 39 minutes ago",
severity: "Scheduled report",
accent: 0xc899f2,
x: -11,
z: 7,
pathStart: new THREE.Vector2(-7.4, 2.5),
pathEnd: new THREE.Vector2(-10.1, 5.9),
obstacleAt: new THREE.Vector2(-10, 5.8),
crewName: "Crew 01",
obstacleType: "branches"
}
];
const branches = branchDefinitions.map((definition) => ({
...definition,
authorized: false,
cleanupComplete: false,
pathOpen: false,
progress: 0
}));
const pickables = [];
// -------------------------------------------------------------------------
// Branch paths, hubs, markers, barriers, and crews
// -------------------------------------------------------------------------
function createPath(branch) {
const start = branch.pathStart;
const end = branch.pathEnd;
const dx = end.x - start.x;
const dz = end.y - start.y;
const length = Math.hypot(dx, dz);
const count = Math.ceil(length / 0.7);
const angle = -Math.atan2(dz, dx);
branch.pathMaterial = new THREE.MeshStandardMaterial({
color: 0xff786b,
emissive: 0xff786b,
emissiveIntensity: 0.22,
roughness: 0.75
});
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const x = start.x + dx * t;
const z = start.y + dz * t;
const segmentLength = length / count;
const base = box(
world,
x,
0.17,
z,
segmentLength * 1.03,
0.13,
1.9,
0x536467,
false
);
base.rotation.y = angle;
const status = box(
world,
x,
0.27,
z,
segmentLength * 0.94,
0.08,
0.58,
branch.pathMaterial,
false
);
status.rotation.y = angle;
}
}
function createTree(x, z, scale = 1, tint = 0x4b8b63) {
const tree = new THREE.Group();
tree.position.set(x, 0.12, z);
tree.scale.setScalar(scale);
world.add(tree);
box(tree, 0, 0.8, 0, 0.35, 1.6, 0.35, 0x75563d);
box(tree, 0, 1.75, 0, 1.75, 0.85, 1.75, tint);
box(tree, 0, 2.35, 0, 1.25, 0.65, 1.25, 0x65a775);
box(tree, -0.45, 2.72, 0.08, 0.85, 0.45, 0.85, 0x76b783);
}
function createBarrier(branch) {
const barrier = new THREE.Group();
barrier.position.set(
branch.pathStart.x + (branch.pathEnd.x - branch.pathStart.x) * 0.73,
0.32,
branch.pathStart.y + (branch.pathEnd.y - branch.pathStart.y) * 0.73
);
barrier.rotation.y =
-Math.atan2(
branch.pathEnd.y - branch.pathStart.y,
branch.pathEnd.x - branch.pathStart.x
);
box(barrier, -0.8, 0.65, 0, 0.18, 1.3, 0.18, 0xe9e3cd);
box(barrier, 0.8, 0.65, 0, 0.18, 1.3, 0.18, 0xe9e3cd);
for (let i = 0; i < 5; i++) {
box(
barrier,
-0.65 + i * 0.32,
0.85,
0,
0.32,
0.28,
0.16,
i % 2 ? 0xf0eee0 : 0xff6b5c
);
}
branch.barrier = barrier;
world.add(barrier);
}
function createCrew(branch) {
const crew = new THREE.Group();
crew.visible = false;
world.add(crew);
// Voxel utility truck.
box(crew, 0.25, 0.65, 0, 1.45, 0.72, 0.85, 0x6fcbb5);
box(crew, 1.08, 0.88, 0, 0.62, 0.72, 0.86, 0xd6e8dc);
box(crew, 1.38, 0.92, 0, 0.08, 0.46, 0.62, glowMaterial(0x8fd8ff, 0.35), false);
box(crew, 0.12, 1.18, 0, 1.15, 0.25, 0.82, 0x4aa896);
for (const x of [-0.25, 0.85]) {
box(crew, x, 0.32, 0.46, 0.38, 0.38, 0.18, 0x172b30);
box(crew, x, 0.32, -0.46, 0.38, 0.38, 0.18, 0x172b30);
}
// Worker with a hard hat.
box(crew, -0.52, 0.78, 0.58, 0.42, 0.72, 0.42, 0xf1aa55);
box(crew, -0.52, 1.22, 0.58, 0.48, 0.18, 0.48, 0xffd15c);
box(crew, -0.52, 0.34, 0.58, 0.48, 0.22, 0.46, 0x283c48);
branch.crew = crew;
}
function createObstacles(branch) {
const group = new THREE.Group();
group.position.set(branch.obstacleAt.x, 0.29, branch.obstacleAt.y);
world.add(group);
branch.debris = [];
if (branch.obstacleType === "wood") {
const pieces = [
[-0.55, 0.22, -0.25, 1.5, 0.38, 0.42, 0x805b3e],
[0.45, 0.3, 0.35, 1.9, 0.4, 0.38, 0x9a7149],
[-0.15, 0.55, 0.08, 0.42, 0.42, 1.65, 0x6d5138],
[0.7, 0.18, -0.55, 1.15, 0.32, 0.42, 0xb08152],
[-0.8, 0.18, 0.65, 0.9, 0.32, 0.52, 0x795d47]
];
for (const p of pieces) {
const mesh = box(group, p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
mesh.rotation.y = random() * 0.8 - 0.4;
branch.debris.push(mesh);
}
box(group, 0.05, 0.1, 0, 2.3, 0.12, 1.45, 0x6b6652, false);
} else if (branch.obstacleType === "pallets") {
for (let i = 0; i < 5; i++) {
const x = -0.65 + (i % 2) * 0.8;
const y = 0.2 + Math.floor(i / 2) * 0.42;
const mesh = box(
group,
x,
y,
i % 2 ? 0.25 : -0.2,
1.1,
0.32,
0.9,
i % 2 ? 0xa77a4d : 0xb58956
);
branch.debris.push(mesh);
}
} else {
const pieces = [
[-0.65, 0.3, -0.2, 1.55, 0.38, 0.38, 0x72503a],
[0.5, 0.25, 0.45, 1.4, 0.36, 0.38, 0x876044],
[0.1, 0.62, 0.1, 0.35, 0.35, 1.4, 0x6c5039],
[-0.7, 0.32, 0.65, 0.7, 0.6, 0.7, 0x527d56]
];
for (const p of pieces) {
const mesh = box(group, p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
mesh.rotation.y = random() * 1.1;
branch.debris.push(mesh);
}
}
}
function createBranchHub(branch) {
const hub = new THREE.Group();
hub.position.set(branch.x, 0.12, branch.z);
world.add(hub);
box(hub, 0, 0.18, 0, 4.5, 0.28, 3.8, 0x43595a);
box(hub, 0, 1.08, -0.35, 2.8, 1.75, 2.15, 0xc8c1a9);
box(hub, 0, 2.03, -0.35, 3.25, 0.35, 2.65, branch.accent);
box(hub, 0, 2.26, -0.35, 2.85, 0.18, 2.2, branch.accent);
box(hub, 0, 1.12, 0.76, 0.85, 1.35, 0.12, 0x48646a);
box(hub, 0.83, 1.42, 0.76, 0.65, 0.62, 0.13, glowMaterial(0xffd883, 0.48), false);
// Small solar array.
for (let i = 0; i < 3; i++) {
const panel = box(
hub,
-1.45,
0.9,
-0.7 + i * 0.55,
0.9,
0.12,
0.43,
0x254f6b
);
panel.rotation.z = -0.22;
}
// Selection ring.
const ringMaterial = new THREE.MeshStandardMaterial({
color: branch.accent,
emissive: branch.accent,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0.2
});
branch.ringMaterial = ringMaterial;
branch.ring = [];
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const marker = box(
hub,
Math.cos(angle) * 2.7,
0.22,
Math.sin(angle) * 2.15,
0.35,
0.18,
0.35,
ringMaterial,
false
);
branch.ring.push(marker);
}
// Raised report beacon.
box(hub, 1.65, 1.45, -1.4, 0.12, 2.6, 0.12, 0x718587);
const beaconMaterial = glowMaterial(branch.accent, 0.75);
branch.beacon = box(hub, 1.65, 2.85, -1.4, 0.62, 0.62, 0.62, beaconMaterial, false);
branch.beacon.userData.branchId = branch.id;
pickables.push(branch.beacon);
// Make the hub itself selectable.
hub.traverse((object) => {
if (object.isMesh) {
object.userData.branchId = branch.id;
pickables.push(object);
}
});
createPath(branch);
createBarrier(branch);
createCrew(branch);
createObstacles(branch);
}
branches.forEach(createBranchHub);
// -------------------------------------------------------------------------
// Landscape details
// -------------------------------------------------------------------------
[
[-14, -8, 1.1], [-12.7, -9.8, 0.8], [-14.8, 2, 0.9],
[-13.5, 9.6, 1.15], [-6.8, 9.3, 0.8], [13.8, -9.1, 1.1],
[14.7, -6.9, 0.8], [14.5, 9.5, 1.05], [7.3, 9.8, 0.75],
[6.1, -10.2, 0.75]
].forEach(([x, z, scale], index) => {
createTree(x, z, scale, index % 2 ? 0x4f8b62 : 0x5e9669);
});
// Small central supply tent, built as stacked voxel layers.
const tent = new THREE.Group();
tent.position.set(-11.2, 0.12, -5.4);
world.add(tent);
box(tent, 0, 0.18, 0, 4.7, 0.28, 3.5, 0x3a5759);
box(tent, 0, 0.55, 0, 3.8, 0.5, 2.8, 0xe2a54e);
box(tent, 0, 0.95, 0, 2.7, 0.5, 2.1, 0xe7b35e);
box(tent, 0, 1.35, 0, 1.55, 0.5, 1.35, 0xf0c574);
box(tent, 0, 1.72, 0, 0.55, 0.35, 0.55, 0xf6d68e);
box(tent, 0, 0.9, 1.6, 1.1, 1.5, 0.12, 0x304b50);
// Benches and lamps around the depot plaza.
for (const [x, z] of [[-9, -1], [4.7, -2.8], [4.7, 2.3]]) {
box(world, x, 0.5, z, 2, 0.22, 0.55, 0x9b714b);
box(world, x, 0.87, z - 0.24, 2, 0.62, 0.14, 0x9b714b);
box(world, x - 0.7, 0.28, z, 0.16, 0.55, 0.38, 0x31484a);
box(world, x + 0.7, 0.28, z, 0.16, 0.55, 0.38, 0x31484a);
}
for (const [x, z] of [[-8.7, 2.3], [4.4, 2.7], [6.3, -4.8]]) {
box(world, x, 1.25, z, 0.14, 2.4, 0.14, 0x4e686b);
box(world, x, 2.48, z, 0.65, 0.22, 0.65, glowMaterial(0xffe6a8, 0.65), false);
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
function createLabel(className, html) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
document.querySelector("#labels").appendChild(element);
return element;
}
const depotLabel = createLabel(
"depot-label",
'<span class="label-dot"></span>COMMON GROUND DEPOT<small>Central supply hub</small>'
);
for (const branch of branches) {
branch.label = createLabel(
"",
`<span class="label-dot" style="color:#${branch.accent
.toString(16)
.padStart(6, "0")}"></span>${branch.name.toUpperCase()}<small>Report received</small>`
);
}
const projected = new THREE.Vector3();
function updateLabel(element, position) {
projected.copy(position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// -------------------------------------------------------------------------
// UI state and branch cards
// -------------------------------------------------------------------------
const branchListElement = document.querySelector("#branch-list");
const branchCardRefs = new Map();
function statusFor(branch) {
if (branch.pathOpen) return "Path reopened";
if (branch.cleanupComplete) return "Cleanup complete";
if (branch.authorized) return "Cleanup in progress";
return "Report received";
}
function statusState(branch) {
if (branch.pathOpen) return "open";
if (branch.cleanupComplete) return "ready";
if (branch.authorized) return "progress";
return "report";
}
for (const branch of branches) {
const card = document.createElement("button");
card.type = "button";
card.className = "branch-card";
card.innerHTML = `
<div class="card-top">
<span class="branch-code">${branch.id}</span>
<span class="status-pill">Report received</span>
</div>
<h3>${branch.name}</h3>
<div class="branch-issue">${branch.issue}</div>
<div class="card-bottom">
<span class="card-time">${branch.reporter.split("·")[0]}</span>
<span class="mini-progress"><i></i></span>
</div>
`;
card.addEventListener("click", () => selectBranch(branch.id));
branchListElement.appendChild(card);
branchCardRefs.set(branch.id, {
card,
status: card.querySelector(".status-pill"),
progress: card.querySelector(".mini-progress i")
});
}
let selectedBranch = branches[0];
const detailCode = document.querySelector("#detail-code");
const detailTitle = document.querySelector("#detail-title");
const detailSeverity = document.querySelector("#detail-severity");
const detailStatus = document.querySelector("#detail-status");
const detailReport = document.querySelector("#detail-report");
const detailReporter = document.querySelector("#detail-reporter");
const stepReport = document.querySelector("#step-report");
const stepCleanup = document.querySelector("#step-cleanup");
const stepReopen = document.querySelector("#step-reopen");
const progressValue = document.querySelector("#progress-value");
const progressFill = document.querySelector("#progress-fill");
const authorizeButton = document.querySelector("#authorize-btn");
const reopenButton = document.querySelector("#reopen-btn");
const openCount = document.querySelector("#open-count");
const crewCount = document.querySelector("#crew-count");
const reopenCount = document.querySelector("#reopen-count");
function selectBranch(id) {
selectedBranch = branches.find((branch) => branch.id === id);
refreshBranchCards();
refreshInspector();
}
function refreshBranchCards() {
for (const branch of branches) {
const refs = branchCardRefs.get(branch.id);
const state = statusState(branch);
refs.card.classList.toggle("selected", branch === selectedBranch);
refs.status.textContent = statusFor(branch);
refs.status.dataset.state = state;
refs.progress.style.width = `${branch.progress}%`;
refs.progress.style.background =
branch.pathOpen ? "#64dfca" : "#ffc857";
branch.label.querySelector("small").textContent = statusFor(branch);
}
openCount.textContent = branches.filter((branch) => !branch.pathOpen).length;
crewCount.textContent = branches.filter(
(branch) => branch.authorized && !branch.pathOpen
).length;
reopenCount.textContent = branches.filter((branch) => branch.pathOpen).length;
}
function refreshInspector() {
const branch = selectedBranch;
const state = statusState(branch);
detailCode.textContent = branch.id;
detailTitle.textContent = branch.name;
detailSeverity.textContent = branch.severity;
detailStatus.textContent = statusFor(branch);
detailStatus.dataset.state = state;
detailReport.textContent = branch.issue;
detailReporter.textContent = `Reported by ${branch.reporter}`;
stepReport.className = "complete";
if (branch.pathOpen) {
stepCleanup.className = "complete";
stepReopen.className = "complete";
} else if (branch.cleanupComplete) {
stepCleanup.className = "complete";
stepReopen.className = "active";
} else if (branch.authorized) {
stepCleanup.className = "active";
stepReopen.className = "";
} else {
stepCleanup.className = "";
stepReopen.className = "";
}
progressValue.textContent = `${Math.round(branch.progress)}%`;
progressFill.style.width = `${branch.progress}%`;
authorizeButton.disabled = branch.authorized;
authorizeButton.textContent = branch.authorized
? branch.cleanupComplete
? "Cleanup complete"
: "Crew dispatched"
: "Authorize cleanup";
reopenButton.disabled =
!branch.authorized || !branch.cleanupComplete || branch.pathOpen;
reopenButton.textContent = branch.pathOpen ? "Path reopened" : "Reopen path";
}
function updatePathVisual(branch) {
let color = 0xff786b;
if (branch.pathOpen) color = 0x64dfca;
else if (branch.authorized) color = 0xffc857;
branch.pathMaterial.color.setHex(color);
branch.pathMaterial.emissive.setHex(color);
branch.pathMaterial.emissiveIntensity = branch.pathOpen ? 0.12 : 0.24;
}
function showToast(message) {
const toast = document.querySelector("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => toast.classList.remove("show"), 2600);
}
authorizeButton.addEventListener("click", () => {
const branch = selectedBranch;
if (branch.authorized) return;
branch.authorized = true;
branch.cleanupComplete = false;
branch.progress = 0;
branch.crew.visible = true;
branch.barrier.visible = true;
updatePathVisual(branch);
refreshBranchCards();
refreshInspector();
showToast(`${branch.crewName} authorized for ${branch.name}. Cleanup underway.`);
});
reopenButton.addEventListener("click", () => {
const branch = selectedBranch;
if (!branch.authorized || !branch.cleanupComplete || branch.pathOpen) return;
branch.pathOpen = true;
branch.crew.visible = false;
branch.barrier.visible = false;
branch.debris.forEach((mesh) => (mesh.visible = false));
updatePathVisual(branch);
refreshBranchCards();
refreshInspector();
showToast(`${branch.name} path reopened and access restored.`);
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard, and raycast selection
// -------------------------------------------------------------------------
const view = {
target: new THREE.Vector3(0, 0.8, 0),
desiredTarget: new THREE.Vector3(0, 0.8, 0),
azimuth: 0.68,
desiredAzimuth: 0.68,
polar: 1.02,
desiredPolar: 1.02,
zoom: 1,
desiredZoom: 1
};
const cameraRadius = 48;
function updateCamera() {
view.azimuth += (view.desiredAzimuth - view.azimuth) * 0.12;
view.polar += (view.desiredPolar - view.polar) * 0.12;
view.zoom += (view.desiredZoom - view.zoom) * 0.12;
view.target.lerp(view.desiredTarget, 0.12);
const horizontal = Math.sin(view.polar) * cameraRadius;
camera.position.set(
view.target.x + Math.sin(view.azimuth) * horizontal,
view.target.y + Math.cos(view.polar) * cameraRadius,
view.target.z + Math.cos(view.azimuth) * horizontal
);
camera.lookAt(view.target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
}
function resetView() {
view.desiredTarget.set(0, 0.8, 0);
view.desiredAzimuth = 0.68;
view.desiredPolar = 1.02;
view.desiredZoom = 1;
}
document.querySelector("#reset-view").addEventListener("click", resetView);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerState = {
down: false,
moved: 0,
button: 0,
lastX: 0,
lastY: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerState.down = true;
pointerState.moved = 0;
pointerState.button = event.button;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState.down) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
pointerState.moved += Math.abs(dx) + Math.abs(dy);
if (pointerState.button === 2 || event.shiftKey) {
const right = new THREE.Vector3(
Math.cos(view.azimuth),
0,
-Math.sin(view.azimuth)
);
const forward = new THREE.Vector3(
-Math.sin(view.azimuth),
0,
-Math.cos(view.azimuth)
);
const scale = 0.025 / view.zoom;
view.desiredTarget.addScaledVector(right, -dx * scale);
view.desiredTarget.addScaledVector(forward, -dy * scale);
view.desiredTarget.x = THREE.MathUtils.clamp(
view.desiredTarget.x,
-13,
13
);
view.desiredTarget.z = THREE.MathUtils.clamp(
view.desiredTarget.z,
-10,
10
);
} else {
view.desiredAzimuth -= dx * 0.006;
view.desiredPolar = THREE.MathUtils.clamp(
view.desiredPolar - dy * 0.005,
0.48,
1.35
);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerState.down = false;
if (
pointerState.button === 0 &&
pointerState.moved < 7
) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length && hits[0].object.userData.branchId) {
selectBranch(hits[0].object.userData.branchId);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.desiredZoom = THREE.MathUtils.clamp(
view.desiredZoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.25
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key === "ArrowLeft") view.desiredAzimuth += 0.09;
if (event.key === "ArrowRight") view.desiredAzimuth -= 0.09;
if (event.key === "ArrowUp") {
view.desiredPolar = Math.max(0.48, view.desiredPolar - 0.06);
}
if (event.key === "ArrowDown") {
view.desiredPolar = Math.min(1.35, view.desiredPolar + 0.06);
}
if (event.key === "+" || event.key === "=") {
view.desiredZoom = Math.min(2.25, view.desiredZoom * 1.08);
}
if (event.key === "-") {
view.desiredZoom = Math.max(0.65, view.desiredZoom / 1.08);
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = 32;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
const depotLabelPosition = new THREE.Vector3(-2, 5.1, -2.4);
const branchLabelPositions = new Map();
for (const branch of branches) {
branchLabelPositions.set(
branch.id,
new THREE.Vector3(branch.x + 0.5, 4.45, branch.z - 0.8)
);
}
const crewStart = new THREE.Vector3();
const crewEnd = new THREE.Vector3();
const crewPosition = new THREE.Vector3();
let previousTime = performance.now();
let uiTimer = 0;
function animate(time) {
requestAnimationFrame(animate);
const delta = Math.min((time - previousTime) / 1000, 0.1);
previousTime = time;
uiTimer += delta;
for (const branch of branches) {
if (branch.authorized && !branch.pathOpen) {
branch.progress = Math.min(100, branch.progress + delta * 11.5);
if (branch.progress >= 100 && !branch.cleanupComplete) {
branch.cleanupComplete = true;
showToast(
`${branch.name} cleanup is complete. The path can now reopen.`
);
}
// Debris disappears progressively as the crew clears the route.
branch.debris.forEach((mesh, index) => {
mesh.visible = branch.progress < 60 + index * 6;
});
// Crew travels from the depot to the obstructed branch.
const travel = Math.min(1, branch.progress / 86);
crewStart.set(branch.pathStart.x, 0.25, branch.pathStart.y);
crewEnd.set(branch.pathEnd.x, 0.25, branch.pathEnd.y);
crewPosition.lerpVectors(crewStart, crewEnd, travel);
branch.crew.position.copy(crewPosition);
branch.crew.rotation.y = -Math.atan2(
branch.pathEnd.y - branch.pathStart.y,
branch.pathEnd.x - branch.pathStart.x
);
}
// Selection highlight and beacon pulse.
const selected = branch === selectedBranch;
branch.ringMaterial.opacity = selected ? 0.85 : 0.15;
branch.ringMaterial.emissiveIntensity = selected ? 0.75 : 0.25;
const pulse = selected
? 1 + Math.sin(time * 0.004) * 0.09
: 1;
branch.beacon.scale.set(0.62 * pulse, 0.62 * pulse, 0.62 * pulse);
}
updateCamera();
updateLabel(depotLabel, depotLabelPosition);
for (const branch of branches) {
updateLabel(branch.label, branchLabelPositions.get(branch.id));
}
if (uiTimer > 0.12) {
refreshBranchCards();
refreshInspector();
uiTimer = 0;
}
renderer.render(scene, camera);
}
refreshBranchCards();
refreshInspector();
requestAnimationFrame(animate);
</script>
</body>
</html>
```