Prompt specification
Build or customize the Three.js 3D scene "Neighborhood Heat-Day Support Network" 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: Neighborhood Heat-Day Support Network
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-heat-day-support-network-x3235
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring mutual aid matched to confirmed community needs. Build a fictional block with shade stations, water pickup, and requested check-ins. Show logistical coordination without providing medical advice or exposing personal information. Voxel style.
Working Three.js Starter (neighborhood-heat-day-support-network-x3235):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#dce8df" />
<title>Juniper Commons — Mutual Aid Coordination</title>
<style>
:root {
--ink: #20352f;
--muted: #61746d;
--paper: #f8f4e9;
--paper-2: #fffdf7;
--line: rgba(32, 53, 47, 0.13);
--green: #247b65;
--green-soft: #dceee5;
--amber: #dc8d2b;
--amber-soft: #f9e8cb;
--blue: #347e99;
--blue-soft: #dbeaf1;
--coral: #d7674d;
--shadow: 0 18px 48px rgba(38, 63, 55, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 3px solid rgba(52, 126, 153, 0.38);
outline-offset: 3px;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(240, 247, 240, 0.16), transparent 25%),
radial-gradient(circle at 48% 45%, transparent 42%, rgba(53, 77, 69, 0.08));
}
.header {
position: fixed;
z-index: 20;
top: 20px;
left: 22px;
right: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.brand,
.header-meta {
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
padding: 12px 15px 12px 12px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 18px;
background: rgba(248, 244, 233, 0.9);
box-shadow: 0 12px 32px rgba(45, 69, 61, 0.13);
backdrop-filter: blur(12px);
}
.brand-mark {
display: grid;
grid-template-columns: repeat(3, 8px);
grid-template-rows: repeat(3, 8px);
gap: 3px;
padding: 8px;
border-radius: 12px;
background: var(--ink);
transform: rotate(-2deg);
}
.brand-mark i {
display: block;
background: #f3c86e;
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(8) {
background: #85bca8;
}
.brand-mark i:nth-child(5) {
background: #e78163;
}
.eyebrow {
margin-bottom: 3px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: 19px;
line-height: 1.05;
letter-spacing: -0.025em;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
}
.header-meta {
display: flex;
align-items: center;
gap: 8px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 35px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(248, 244, 233, 0.88);
box-shadow: 0 9px 24px rgba(45, 69, 61, 0.1);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.chip .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(36, 123, 101, 0.12);
}
.chip.simulated {
color: #98651f;
background: rgba(255, 242, 216, 0.92);
}
.panel {
position: fixed;
z-index: 15;
top: 104px;
right: 22px;
width: 350px;
max-height: calc(100vh - 132px);
overflow: auto;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 22px;
background: rgba(248, 244, 233, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
scrollbar-width: thin;
scrollbar-color: rgba(32, 53, 47, 0.22) transparent;
}
.panel-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.panel-head h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.025em;
}
.panel-head p {
margin: 5px 0 0;
max-width: 210px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.small-button,
.primary-button,
.toolbar-button {
border: 0;
border-radius: 11px;
cursor: pointer;
font-weight: 750;
transition:
transform 150ms ease,
background 150ms ease,
opacity 150ms ease;
}
.small-button:hover,
.primary-button:hover:not(:disabled),
.toolbar-button:hover {
transform: translateY(-1px);
}
.small-button {
flex: 0 0 auto;
padding: 9px 11px;
background: var(--ink);
color: white;
font-size: 11px;
}
.small-button:disabled,
.primary-button:disabled {
cursor: not-allowed;
opacity: 0.48;
}
.summary {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 15px 0 12px;
}
.summary-item {
padding: 10px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 253, 247, 0.68);
}
.summary-item strong {
display: block;
font-size: 18px;
line-height: 1;
}
.summary-item span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.request-list {
display: grid;
gap: 8px;
}
.request-card {
width: 100%;
padding: 12px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 253, 247, 0.72);
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.request-card:hover {
transform: translateY(-1px);
border-color: rgba(36, 123, 101, 0.34);
}
.request-card.active {
border-color: rgba(36, 123, 101, 0.48);
background: #fffdf7;
box-shadow: inset 3px 0 0 var(--green);
}
.request-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 7px;
}
.confirmed,
.status {
display: inline-flex;
align-items: center;
gap: 5px;
border-radius: 999px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.035em;
}
.confirmed {
color: var(--green);
}
.status {
padding: 4px 7px;
color: var(--muted);
background: #edf0e9;
}
.status.enroute {
color: #9b6419;
background: var(--amber-soft);
}
.status.arrived {
color: #2d6f89;
background: var(--blue-soft);
}
.status.complete {
color: var(--green);
background: var(--green-soft);
}
.request-card strong {
display: block;
font-size: 13px;
}
.request-location {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.request-resource {
display: flex;
align-items: center;
gap: 7px;
margin-top: 9px;
color: #3c544c;
font-size: 10px;
font-weight: 650;
}
.resource-cube {
width: 8px;
height: 8px;
background: var(--amber);
box-shadow: 3px -3px 0 rgba(220, 141, 43, 0.28);
}
.privacy-note {
display: flex;
align-items: flex-start;
gap: 9px;
margin-top: 13px;
padding: 11px;
border-radius: 13px;
background: #e8efe8;
color: #53675f;
font-size: 10px;
line-height: 1.45;
}
.privacy-note .lock {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 19px;
height: 19px;
border-radius: 6px;
background: #d2e2d7;
color: var(--green);
font-weight: 900;
}
.detail {
position: fixed;
z-index: 14;
left: 22px;
bottom: 68px;
width: 420px;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 22px;
background: rgba(255, 253, 247, 0.95);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.detail-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.detail-type {
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.detail h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.025em;
}
.detail-need {
margin: 7px 0 13px;
color: #52665e;
font-size: 11px;
line-height: 1.5;
}
.detail-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 10px;
}
.detail-cell {
min-height: 62px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: #f7f4eb;
}
.detail-cell span {
display: block;
margin-bottom: 5px;
color: #77877f;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.detail-cell strong {
display: block;
font-size: 11px;
line-height: 1.35;
}
.detail-privacy {
margin: 0 0 11px;
color: #6a7c75;
font-size: 9px;
line-height: 1.45;
}
.primary-button {
width: 100%;
min-height: 41px;
padding: 10px 13px;
background: var(--green);
color: white;
font-size: 11px;
}
#labels {
position: fixed;
z-index: 8;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
max-width: 180px;
padding: 7px 9px 7px 7px;
border: 1px solid rgba(255, 255, 255, 0.86);
border-radius: 12px;
background: rgba(255, 253, 247, 0.92);
box-shadow: 0 8px 22px rgba(40, 65, 57, 0.14);
color: var(--ink);
transform: translate(-50%, -100%);
pointer-events: auto;
cursor: pointer;
transition:
background 150ms ease,
box-shadow 150ms ease;
}
.map-label:hover,
.map-label.active {
background: white;
box-shadow: 0 10px 28px rgba(40, 65, 57, 0.22);
}
.map-label.active {
outline: 2px solid rgba(36, 123, 101, 0.35);
outline-offset: 2px;
}
.label-icon {
display: grid;
place-items: center;
flex: 0 0 auto;
width: 26px;
height: 26px;
border-radius: 8px;
background: var(--green-soft);
color: var(--green);
font-size: 14px;
font-weight: 900;
}
.map-label.water .label-icon {
background: var(--blue-soft);
color: var(--blue);
}
.map-label.checkin .label-icon {
background: var(--amber-soft);
color: #a76819;
}
.label-copy {
min-width: 0;
text-align: left;
}
.label-title {
display: block;
overflow: hidden;
font-size: 10px;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.label-stage {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.toolbar {
position: fixed;
z-index: 16;
left: 50%;
bottom: 18px;
display: flex;
align-items: center;
gap: 7px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 16px;
background: rgba(248, 244, 233, 0.9);
box-shadow: 0 10px 30px rgba(45, 69, 61, 0.12);
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
.toolbar-button {
padding: 8px 10px;
background: #fffdf7;
color: var(--ink);
font-size: 10px;
}
.toolbar-button.active {
background: var(--green-soft);
color: var(--green);
}
.control-hint {
padding: 0 7px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.toast {
position: fixed;
z-index: 40;
top: 88px;
left: 50%;
max-width: min(420px, calc(100vw - 32px));
padding: 11px 15px;
border-radius: 12px;
background: var(--ink);
box-shadow: var(--shadow);
color: white;
font-size: 11px;
opacity: 0;
transform: translate(-50%, -10px);
transition:
opacity 180ms ease,
transform 180ms ease;
pointer-events: none;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #dce8df;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader-block {
width: 46px;
height: 46px;
margin: 0 auto 14px;
border: 8px solid var(--green);
border-right-color: #efbd58;
border-bottom-color: #87bba8;
animation: voxel-spin 1.4s steps(8) infinite;
}
.loading p {
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@keyframes voxel-spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 900px) {
.panel {
width: 315px;
}
.detail {
width: 360px;
}
.control-hint {
display: none;
}
}
@media (max-width: 700px) {
.header {
top: 10px;
left: 10px;
right: 10px;
}
.brand {
padding: 9px 11px 9px 9px;
}
.brand-mark {
grid-template-columns: repeat(3, 6px);
grid-template-rows: repeat(3, 6px);
padding: 6px;
}
.brand h1 {
font-size: 16px;
}
.brand p,
.header-meta .chip:not(.simulated) {
display: none;
}
.panel {
top: 82px;
right: 10px;
width: min(290px, calc(100vw - 20px));
max-height: 43vh;
padding: 13px;
border-radius: 18px;
}
.panel-head p,
.privacy-note {
display: none;
}
.summary {
margin: 10px 0;
}
.request-list {
gap: 6px;
}
.request-card {
padding: 9px;
}
.detail {
left: 10px;
right: 10px;
bottom: 58px;
width: auto;
padding: 13px;
border-radius: 18px;
}
.detail h2 {
font-size: 17px;
}
.detail-need {
margin-bottom: 9px;
}
.detail-grid {
gap: 6px;
}
.detail-cell {
min-height: 53px;
padding: 8px;
}
.toolbar {
bottom: 10px;
}
.map-label {
max-width: 145px;
}
.label-title {
max-width: 100px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive voxel map of Juniper Commons showing matched shade, water pickup, and courtesy check-in requests"
></canvas>
<div class="vignette"></div>
<header class="header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<div class="eyebrow">Fictional community network</div>
<h1>Juniper Commons</h1>
<p>Mutual aid matched to confirmed needs</p>
</div>
</div>
<div class="header-meta">
<span class="chip">
<span class="dot"></span>
Role-level coordination
</span>
<span class="chip simulated">SIMULATED</span>
</div>
</header>
<aside class="panel" aria-label="Confirmed needs and coordination queue">
<div class="panel-head">
<div>
<div class="eyebrow">Operations board</div>
<h2>Confirmed needs</h2>
<p>Public drop points and task-level resources only.</p>
</div>
<button class="small-button" id="startNext">Start next carry</button>
</div>
<div class="summary" aria-live="polite">
<div class="summary-item">
<strong id="confirmedCount">4</strong>
<span>Confirmed</span>
</div>
<div class="summary-item">
<strong id="matchedCount">4</strong>
<span>Matched</span>
</div>
<div class="summary-item">
<strong id="activeCount">0</strong>
<span>In transit</span>
</div>
</div>
<div class="request-list" id="requestList"></div>
<div class="privacy-note">
<span class="lock" aria-hidden="true">✓</span>
<span>
No names, contact details, health information, medical advice,
visit notes, or resident rosters are collected in this fictional workflow.
</span>
</div>
</aside>
<section class="detail" aria-labelledby="detailTitle">
<div class="detail-head">
<span class="detail-type" id="detailType">Confirmed request</span>
<span class="status" id="detailStage">Matched · ready</span>
</div>
<h2 id="detailTitle">Shade station setup</h2>
<p class="detail-need" id="detailNeed"></p>
<div class="detail-grid">
<div class="detail-cell">
<span>Public drop point</span>
<strong id="detailLocation"></strong>
</div>
<div class="detail-cell">
<span>Matched resource</span>
<strong id="detailResource"></strong>
</div>
</div>
<p class="detail-privacy" id="detailPrivacy"></p>
<button class="primary-button" id="dispatchButton">Start coordinated carry</button>
</section>
<div id="labels" aria-label="Map markers"></div>
<nav class="toolbar" aria-label="Scene controls">
<button class="toolbar-button" id="resetView">Reset view</button>
<button class="toolbar-button active" id="toggleRoutes">Routes on</button>
<span class="control-hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom</span>
</nav>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div class="loading" id="loading">
<div>
<div class="loader-block"></div>
<p>Building the block</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const clamp = THREE.MathUtils.clamp;
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const requests = [
{
id: "shade",
type: "Shade access",
title: "Shade station setup",
need: "Provide two open canopy bays and folding seats at the east courtyard.",
location: "East Courtyard",
window: "Today · 16:00–18:00",
resource: "2 canopy kits + 2 folding seats",
privacy:
"Operational task only: public location, setup window, and matched equipment.",
icon: "▦",
className: "shade",
stage: "staged",
focus: new THREE.Vector3(-2, 0, -2.8),
focusSize: 4.3,
path: [
[10, 4.3],
[12.5, 4.3],
[12.5, -2.8],
[-2, -2.8]
],
carryColor: 0x3b9586
},
{
id: "water",
type: "Water pickup",
title: "Sealed water pickup",
need: "Stage sealed drinking-water cases at the market corner for a scheduled pickup.",
location: "Market Corner",
window: "Today · 17:00–19:00",
resource: "24 sealed cases + pallet cart",
privacy:
"Inventory and pickup-window data only. No purchaser or household information.",
icon: "◆",
className: "water",
stage: "staged",
focus: new THREE.Vector3(7, 0, -2.8),
focusSize: 3.8,
path: [
[10, 4.3],
[12.5, 4.3],
[12.5, -2.8],
[7, -2.8]
],
carryColor: 0x3d87a2
},
{
id: "check-west",
type: "Courtesy check-in",
title: "West entrance handoff",
need: "Knock once to confirm a supply handoff. Participation is optional.",
location: "Maple Walk · West",
window: "Today · 18:00",
resource: "1 volunteer + 1 supply tote",
privacy:
"Presence-only handoff confirmation. No wellness questions or visit notes.",
icon: "✓",
className: "checkin",
stage: "staged",
focus: new THREE.Vector3(-8, 0, 3.55),
focusSize: 2.2,
path: [
[10, 4.3],
[10, 3.45],
[-8, 3.45]
],
carryColor: 0xd99235
},
{
id: "check-east",
type: "Courtesy check-in",
title: "East entrance handoff",
need: "Collect a supply tote from the lobby and confirm the handoff.",
location: "Maple Walk · East",
window: "Today · 18:15",
resource: "1 volunteer + 1 supply tote",
privacy:
"Task completion only. No resident identity, reason for request, or follow-up notes.",
icon: "✓",
className: "checkin",
stage: "staged",
focus: new THREE.Vector3(-3, 0, 3.55),
focusSize: 2.2,
path: [
[10, 4.3],
[10, 3.45],
[-3, 3.45]
],
carryColor: 0xd99235
}
];
const requestById = new Map(requests.map((request) => [request.id, request]));
const pickTargets = [];
const waterDrops = [];
const clouds = [];
const labels = [];
let selectedId = "shade";
let activeCarry = null;
let routesVisible = true;
let toastTimer;
// ---------------------------------------------------------------------
// Renderer, camera, and lighting
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas: $("scene"),
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8df);
scene.fog = new THREE.Fog(0xdce8df, 31, 58);
const world = new THREE.Group();
scene.add(world);
const orthoHeight = 20.5;
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, 0);
const desiredTarget = new THREE.Vector3(0, 0, 0);
let azimuth = 0.72;
let elevation = 0.72;
let desiredAzimuth = azimuth;
let desiredElevation = elevation;
let desiredZoom = 0.96;
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x789582, 2.1);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xfff2d5, 3.2);
sunLight.position.set(-10, 19, 13);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -22;
sunLight.shadow.camera.right = 22;
sunLight.shadow.camera.top = 20;
sunLight.shadow.camera.bottom = -20;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 55;
sunLight.shadow.bias = -0.0003;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0x9fc6d3, 0.65);
fillLight.position.set(14, 8, -12);
scene.add(fillLight);
// ---------------------------------------------------------------------
// Voxel construction helpers
// ---------------------------------------------------------------------
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = [
color,
options.roughness ?? 0.84,
options.metalness ?? 0,
options.transparent ? "transparent" : "solid",
options.opacity ?? 1
].join(":");
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(size[0], size[1], size[2]);
const material = options.material || getMaterial(color, options);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addHitBox(parent, position, size, requestId) {
const material = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const mesh = addBox(parent, size, position, 0xffffff, {
material,
castShadow: false,
receiveShadow: false
});
mesh.userData.requestId = requestId;
pickTargets.push(mesh);
return mesh;
}
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addBox(tree, [0.28, 1.8, 0.28], [0, 0.9, 0], 0x76543e);
addBox(tree, [1.55, 0.85, 1.45], [0, 2.0, 0], 0x4f8c66);
addBox(tree, [1.05, 0.7, 1.1], [-0.55, 2.65, 0.05], 0x65a876);
addBox(tree, [0.9, 0.65, 0.95], [0.6, 2.55, 0.08], 0x74b17d);
addBox(tree, [0.72, 0.58, 0.72], [0.05, 3.15, 0], 0x82bd83);
world.add(tree);
}
function addBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
addBox(bench, [1.9, 0.16, 0.58], [0, 0.62, 0], 0xa86e42);
addBox(bench, [1.9, 0.75, 0.13], [0, 1.08, -0.24], 0xa86e42);
addBox(bench, [0.13, 0.62, 0.13], [-0.7, 0.3, 0], 0x5f625d);
addBox(bench, [0.13, 0.62, 0.13], [0.7, 0.3, 0], 0x5f625d);
world.add(bench);
}
function addBuilding({
x,
z,
width,
depth,
height,
color,
roofColor = 0x526761,
windowColor = 0x9cc9c4,
doorColor = 0x465d58,
awningColor = null
}) {
const building = new THREE.Group();
building.position.set(x, 0, z);
addBox(building, [width, height, depth], [0, height / 2, 0], color);
addBox(
building,
[width + 0.24, 0.26, depth + 0.24],
[0, height + 0.08, 0],
roofColor
);
const columns = Math.max(2, Math.floor((width - 1.1) / 1.25));
for (let i = 0; i < columns; i++) {
const wx = -width / 2 + 0.85 + i * ((width - 1.7) / Math.max(1, columns - 1));
if (Math.abs(wx) > 0.65) {
addBox(
building,
[0.68, 0.72, 0.07],
[wx, height * 0.58, depth / 2 + 0.045],
windowColor,
{ roughness: 0.35, metalness: 0.05 }
);
addBox(
building,
[0.76, 0.08, 0.09],
[wx, height * 0.58 - 0.4, depth / 2 + 0.06],
roofColor
);
}
}
addBox(
building,
[0.88, 1.65, 0.09],
[0, 0.83, depth / 2 + 0.06],
doorColor
);
addBox(
building,
[0.62, 0.38, 0.1],
[0, 1.35, depth / 2 + 0.08],
windowColor,
{ roughness: 0.35 }
);
for (const side of [-1, 1]) {
addBox(
building,
[0.08, 0.7, 0.62],
[side * (width / 2 + 0.04), height * 0.58, 0.35],
windowColor,
{ roughness: 0.35 }
);
}
if (awningColor !== null) {
addBox(
building,
[width * 0.68, 0.16, 0.95],
[0, 2.15, depth / 2 + 0.45],
awningColor
);
}
world.add(building);
return building;
}
function addShadeStation() {
const station = new THREE.Group();
station.position.set(-2, 0, -2.8);
addBox(station, [3.9, 0.16, 2.8], [0, 0.08, 0], 0xd8cdb5);
addBox(station, [3.65, 0.1, 2.55], [0, 0.2, 0], 0xb8c8aa);
for (const x of [-1.55, 1.55]) {
for (const z of [-1.05, 1.05]) {
addBox(station, [0.13, 2.3, 0.13], [x, 1.36, z], 0xf0e7d4);
}
}
for (let i = 0; i < 6; i++) {
const color = i % 2 === 0 ? 0x3f9284 : 0xe8dfc8;
addBox(
station,
[0.62, 0.2, 2.75],
[-1.55 + i * 0.62, 2.58, 0],
color
);
}
addBox(station, [1.75, 0.16, 0.5], [0, 0.64, 0.55], 0x9c6943);
addBox(station, [1.75, 0.55, 0.12], [0, 0.98, 0.3], 0x9c6943);
addBox(station, [0.14, 0.48, 0.14], [-0.65, 0.38, 0.55], 0x5c625d);
addBox(station, [0.14, 0.48, 0.14], [0.65, 0.38, 0.55], 0x5c625d);
addBox(station, [0.12, 1.7, 0.12], [-2.08, 0.95, -0.9], 0x5e756c);
addBox(station, [0.72, 0.72, 0.12], [-2.08, 1.8, -0.9], 0x3f9284);
addBox(station, [0.26, 0.26, 0.08], [-2.08, 1.8, -0.81], 0xf5ead3);
addHitBox(station, [0, 1.25, 0], [4.1, 2.8, 3], "shade");
world.add(station);
}
function addWaterStation() {
const station = new THREE.Group();
station.position.set(7, 0, -2.8);
addBox(station, [2.65, 0.16, 1.75], [0, 0.08, 0], 0xd7cdb6);
addBox(station, [1.65, 0.78, 1.05], [-0.2, 0.55, 0], 0x5189a0);
addBox(station, [0.48, 0.34, 0.16], [0.66, 0.65, 0], 0xdde7df);
const crateMaterial = new THREE.MeshStandardMaterial({
color: 0x397f9b,
roughness: 0.7
});
for (let i = 0; i < 3; i++) {
const crate = addBox(
station,
[0.54, 0.42, 0.48],
[-0.85 + i * 0.6, 0.37, 0.62],
0x397f9b
);
crate.material = crateMaterial;
addBox(
station,
[0.32, 0.08, 0.5],
[-0.85 + i * 0.6, 0.62, 0.62],
0x8fc5d6
);
}
addBox(station, [0.12, 1.7, 0.12], [-1.35, 0.92, -0.65], 0x5e756c);
addBox(station, [0.78, 0.78, 0.12], [-1.35, 1.8, -0.65], 0x397f9b);
const drop = new THREE.Group();
drop.position.set(-1.35, 1.8, -0.55);
addBox(drop, [0.22, 0.32, 0.14], [0, 0, 0], 0xe6f4f2);
addBox(drop, [0.14, 0.16, 0.14], [0, 0.23, 0], 0xe6f4f2);
addBox(drop, [0.34, 0.16, 0.14], [0, -0.08, 0], 0xe6f4f2);
station.add(drop);
const animatedDrop = new THREE.Group();
animatedDrop.position.set(1.4, 0.8, 0.3);
addBox(animatedDrop, [0.18, 0.28, 0.18], [0, 0, 0], 0x74bad0);
addBox(animatedDrop, [0.11, 0.14, 0.11], [0, 0.2, 0], 0x9fd2df);
station.add(animatedDrop);
waterDrops.push({ group: animatedDrop, baseY: 0.8, phase: 0.4 });
addHitBox(station, [0, 1.1, 0], [3.4, 2.4, 2.4], "water");
world.add(station);
}
function addCheckInStation(x, requestId) {
const station = new THREE.Group();
station.position.set(x, 0, 3.58);
addBox(station, [1.22, 0.08, 0.72], [0, 0.12, 0.26], 0xc6b89b);
addBox(station, [0.13, 1.75, 0.13], [0.72, 0.94, -0.42], 0x5e756c);
addBox(station, [0.7, 0.7, 0.13], [0.72, 1.82, -0.42], 0xe1a14c);
addBox(station, [0.12, 0.34, 0.08], [0.65, 1.82, -0.33], 0xfff5dc);
addBox(station, [0.12, 0.34, 0.08], [0.81, 1.82, -0.33], 0xfff5dc);
addHitBox(station, [0, 1.0, 0], [1.9, 2.2, 1.5], requestId);
world.add(station);
}
function addNoticeBoard() {
const board = new THREE.Group();
board.position.set(2.25, 0, -2.9);
addBox(board, [0.14, 1.55, 0.14], [-0.95, 0.78, 0], 0x725a43);
addBox(board, [0.14, 1.55, 0.14], [0.95, 0.78, 0], 0x725a43);
addBox(board, [2.35, 1.28, 0.16], [0, 1.55, 0], 0x6a7868);
addBox(board, [2.08, 1.02, 0.05], [0, 1.55, 0.12], 0xe8dfc7);
const noteColors = [0x3f9284, 0xd99235, 0x397f9b, 0xd7674d];
for (let i = 0; i < 4; i++) {
addBox(
board,
[0.32, 0.32, 0.04],
[-0.72 + (i % 2) * 0.74, 1.78 - Math.floor(i / 2) * 0.48, 0.16],
noteColors[i]
);
}
world.add(board);
}
function addCloud(x, y, z, scale = 1) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
addBox(cloud, [2.8, 0.7, 0.9], [0, 0, 0], 0xf4f6ed);
addBox(cloud, [1.2, 0.95, 1.0], [-0.75, 0.45, 0], 0xf4f6ed);
addBox(cloud, [1.35, 1.05, 1.0], [0.35, 0.52, 0], 0xf4f6ed);
addBox(cloud, [1.05, 0.65, 0.9], [1.3, 0.12, 0], 0xf4f6ed);
scene.add(cloud);
clouds.push({ group: cloud, baseX: x, phase: Math.random() * Math.PI * 2 });
}
// ---------------------------------------------------------------------
// Build the fictional block
// ---------------------------------------------------------------------
addBox(world, [28, 0.8, 20], [0, -0.45, 0], 0xb8cf9f);
addBox(world, [27.3, 0.13, 3.15], [0, 0.015, 1], 0x59686b);
addBox(world, [27.4, 0.1, 0.35], [0, 0.05, -0.66], 0xd7d0bc);
addBox(world, [27.4, 0.1, 0.35], [0, 0.05, 2.66], 0xd7d0bc);
for (let x = -12; x <= 12; x += 2.1) {
addBox(world, [0.9, 0.025, 0.1], [x, 0.1, 1], 0xf0e7ce, {
castShadow: false
});
}
for (let i = 0; i < 6; i++) {
addBox(world, [0.48, 0.03, 2.35], [11.95 + i * 0, 0.11, 1], 0xf1e9d3, {
castShadow: false
});
}
// North and south pedestrian paths.
addBox(world, [25.5, 0.1, 1.5], [-0.7, 0.06, -3.85], 0xd7d0bc);
addBox(world, [24.5, 0.1, 1.55], [-0.4, 0.06, 3.45], 0xd7d0bc);
addBox(world, [1.45, 0.1, 16.2], [12.5, 0.06, 0.1], 0xd7d0bc);
addBox(world, [7.4, 0.12, 3.6], [-2.1, 0.06, -2.8], 0xc9d5b4);
addBuilding({
x: -7.8,
z: -6.55,
width: 5.4,
depth: 4.35,
height: 3.2,
color: 0xe0b985,
roofColor: 0x61716b,
windowColor: 0x9fc8bd,
doorColor: 0x4c6961,
awningColor: 0x3f9284
});
addBuilding({
x: 6.25,
z: -6.5,
width: 5.1,
depth: 4.2,
height: 3.65,
color: 0xd9d2b9,
roofColor: 0x586965,
windowColor: 0x8fbec4,
doorColor: 0x4e6671,
awningColor: 0x3d87a2
});
addBuilding({
x: -5.5,
z: 6.25,
width: 8.0,
depth: 4.1,
height: 3.75,
color: 0xc6b3c6,
roofColor: 0x5c6269,
windowColor: 0xa7c8ca,
doorColor: 0x586573
});
addBuilding({
x: 3.2,
z: 7.1,
width: 4.0,
depth: 3.2,
height: 2.6,
color: 0xd8b982,
roofColor: 0x65716a,
windowColor: 0x9ac8c2,
doorColor: 0x55685f
});
addBuilding({
x: 10,
z: 6.75,
width: 4.2,
depth: 4.0,
height: 2.75,
color: 0x9dbab0,
roofColor: 0x536762,
windowColor: 0xc0d2c2,
doorColor: 0x4b625a
});
addShadeStation();
addWaterStation();
addCheckInStation(-8, "check-west");
addCheckInStation(-3, "check-east");
addNoticeBoard();
addBench(-4.15, -3.7);
addBench(-0.2, -3.7);
addBench(8.7, 0.15, Math.PI / 2);
addBench(1.2, 3.45, Math.PI);
[
[-11.4, -7.8, 1.1],
[-11.2, -1.2, 0.9],
[-11.7, 5.6, 1.15],
[-1.8, -8.6, 0.82],
[3.4, -8.8, 1.0],
[7.8, 8.2, 0.85],
[-0.2, 8.1, 0.95],
[5.9, 4.6, 0.82]
].forEach(([x, z, scale]) => addTree(x, z, scale));
// Small planter blocks and utility details.
for (let i = 0; i < 7; i++) {
const x = -10.5 + i * 3.3;
addBox(world, [0.72, 0.4, 0.72], [x, 0.25, 2.18], 0x9b7354);
addBox(world, [0.58, 0.3, 0.58], [x, 0.55, 2.18], 0x619b69);
}
addBox(world, [0.65, 0.95, 0.65], [-11.2, 0.48, -0.4], 0x3d87a2);
addBox(world, [0.32, 0.16, 0.68], [-11.2, 0.8, -0.4], 0xdde7df);
addCloud(-9, 9.8, -12, 1.15);
addCloud(6, 11.5, -15, 0.85);
addCloud(15, 9.2, -8, 0.7);
// Sun rendered as a cluster of pale voxels.
const sun = new THREE.Group();
sun.position.set(11.5, 12.5, -13);
addBox(sun, [1.7, 1.7, 0.55], [0, 0, 0], 0xf2cf77, {
castShadow: false,
receiveShadow: false
});
addBox(sun, [1.15, 1.15, 0.65], [0, 0, 0.08], 0xf7df93, {
castShadow: false,
receiveShadow: false
});
scene.add(sun);
// ---------------------------------------------------------------------
// Routes and selection frame
// ---------------------------------------------------------------------
function createRoute(request) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: 0xd99235,
transparent: true,
opacity: 0.32,
depthWrite: false
});
for (let segment = 0; segment < request.path.length - 1; segment++) {
const [x1, z1] = request.path[segment];
const [x2, z2] = request.path[segment + 1];
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const angle = -Math.atan2(dz, dx);
const count = Math.max(1, Math.floor(length / 0.56));
const dashLength = Math.min(0.32, length / count * 0.55);
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const dash = addBox(
group,
[dashLength, 0.045, 0.14],
[x1 + dx * t, 0.145, z1 + dz * t],
0xffffff,
{
material,
castShadow: false,
receiveShadow: false
}
);
dash.rotation.y = angle;
}
}
const end = request.path[request.path.length - 1];
addBox(group, [0.32, 0.08, 0.32], [end[0], 0.18, end[1]], 0xffffff, {
material,
castShadow: false,
receiveShadow: false
});
request.routeGroup = group;
request.routeMaterial = material;
world.add(group);
}
requests.forEach(createRoute);
const focusMaterial = new THREE.MeshBasicMaterial({
color: 0xeea33c,
transparent: true,
opacity: 0.78,
depthWrite: false
});
const focusFrame = new THREE.Group();
addBox(focusFrame, [1, 0.045, 0.05], [0, 0, -0.5], 0xffffff, {
material: focusMaterial,
castShadow: false,
receiveShadow: false
});
addBox(focusFrame, [1, 0.045, 0.05], [0, 0, 0.5], 0xffffff, {
material: focusMaterial,
castShadow: false,
receiveShadow: false
});
addBox(focusFrame, [0.05, 0.045, 1], [-0.5, 0, 0], 0xffffff, {
material: focusMaterial,
castShadow: false,
receiveShadow: false
});
addBox(focusFrame, [0.05, 0.045, 1], [0.5, 0, 0], 0xffffff, {
material: focusMaterial,
castShadow: false,
receiveShadow: false
});
world.add(focusFrame);
// ---------------------------------------------------------------------
// Generic volunteer courier: role-based, no identifying features
// ---------------------------------------------------------------------
const courier = new THREE.Group();
const courierModel = new THREE.Group();
addBox(courierModel, [0.58, 0.78, 0.38], [0, 1.03, 0], 0x3f9284);
addBox(courierModel, [0.42, 0.42, 0.4], [0, 1.67, 0], 0xd9a77d);
addBox(courierModel, [0.46, 0.18, 0.44], [0, 1.87, 0], 0x4d5e5a);
addBox(courierModel, [0.19, 0.55, 0.22], [-0.16, 0.34, 0], 0x394a48);
addBox(courierModel, [0.19, 0.55, 0.22], [0.16, 0.34, 0], 0x394a48);
addBox(courierModel, [0.16, 0.58, 0.18], [-0.4, 1.03, 0], 0x3f9284);
addBox(courierModel, [0.16, 0.58, 0.18], [0.4, 1.03, 0], 0x3f9284);
addBox(courierModel, [0.48, 0.13, 0.41], [0, 1.08, 0.01], 0xf0c85f);
addBox(courierModel, [0.12, 0.58, 0.4], [0, 1.08, 0.01], 0xf6e2a4);
const carryGroup = new THREE.Group();
const carryMaterial = new THREE.MeshStandardMaterial({
color: 0x3b9586,
roughness: 0.72
});
addBox(carryGroup, [0.72, 0.58, 0.6], [0, 0, 0], 0x3b9586, {
material: carryMaterial
});
addBox(carryGroup, [0.16, 0.61, 0.63], [0, 0, 0], 0xe8d6aa);
carryGroup.position.set(0, 1.03, 0.48);
carryGroup.visible = false;
courierModel.add(carryGroup);
courier.add(courierModel);
courier.position.set(10, 0.14, 4.3);
world.add(courier);
// ---------------------------------------------------------------------
// HTML map labels
// ---------------------------------------------------------------------
function addLabel(request, position) {
const button = document.createElement("button");
button.className = `map-label ${request.className}`;
button.type = "button";
button.setAttribute("aria-label", `Select ${request.title}`);
button.innerHTML = `
<span class="label-icon">${request.icon}</span>
<span class="label-copy">
<span class="label-title">${request.title}</span>
<span class="label-stage"></span>
</span>
`;
button.addEventListener("click", (event) => {
event.stopPropagation();
selectRequest(request.id, true);
});
$("labels").appendChild(button);
labels.push({
element: button,
request,
worldPosition: position
});
}
addLabel(requestById.get("shade"), new THREE.Vector3(-2, 3.35, -2.8));
addLabel(requestById.get("water"), new THREE.Vector3(7, 3.2, -2.8));
addLabel(requestById.get("check-west"), new THREE.Vector3(-8, 2.65, 3.58));
addLabel(requestById.get("check-east"), new THREE.Vector3(-3, 2.65, 3.58));
// ---------------------------------------------------------------------
// UI rendering
// ---------------------------------------------------------------------
function stageLabel(request) {
switch (request.stage) {
case "enroute":
return "En route";
case "arrived":
return "At drop point";
case "complete":
return "Handoff logged";
default:
return "Matched · ready";
}
}
function renderRequestList() {
$("requestList").innerHTML = requests
.map(
(request) => `
<button
class="request-card ${request.id === selectedId ? "active" : ""}"
type="button"
data-request-id="${request.id}"
aria-pressed="${request.id === selectedId}"
>
<span class="request-top">
<span class="confirmed">✓ Confirmed</span>
<span class="status ${request.stage}">${stageLabel(request)}</span>
</span>
<strong>${request.title}</strong>
<span class="request-location">${request.location} · ${request.window}</span>
<span class="request-resource">
<span class="resource-cube"></span>
${request.resource}
</span>
</button>
`
)
.join("");
$("requestList")
.querySelectorAll("[data-request-id]")
.forEach((button) => {
button.addEventListener("click", () => {
selectRequest(button.dataset.requestId, true);
});
});
}
function renderDetail() {
const request = requestById.get(selectedId);
$("detailType").textContent = request.type;
$("detailTitle").textContent = request.title;
$("detailNeed").textContent = request.need;
$("detailLocation").textContent = `${request.location}\n${request.window}`;
$("detailResource").textContent = request.resource;
$("detailPrivacy").textContent = request.privacy;
const status = $("detailStage");
status.textContent = stageLabel(request);
status.className = `status ${request.stage}`;
const button = $("dispatchButton");
button.disabled = false;
if (request.stage === "complete") {
button.textContent = "Handoff logged";
button.disabled = true;
} else if (request.stage === "arrived") {
button.textContent = "Log handoff complete";
} else if (request.stage === "enroute") {
button.textContent = "Carry in progress";
button.disabled = true;
} else if (activeCarry && activeCarry.request.id !== request.id) {
button.textContent = "Another carry is in progress";
button.disabled = true;
} else {
button.textContent = "Start coordinated carry";
}
button.onclick = () => {
if (request.stage === "arrived") {
completeHandoff(request);
} else if (request.stage === "staged") {
startCarry(request);
}
};
}
function renderSummary() {
const activeCount = requests.filter((request) => request.stage === "enroute").length;
$("confirmedCount").textContent = requests.length;
$("matchedCount").textContent = requests.length;
$("activeCount").textContent = activeCount;
$("startNext").disabled =
Boolean(activeCarry) ||
!requests.some((request) => request.stage === "staged");
}
function updateRouteStyles() {
requests.forEach((request) => {
const selected = request.id === selectedId;
let color = 0xd99235;
let opacity = selected ? 0.94 : 0.23;
if (request.stage === "complete") {
color = 0x247b65;
opacity = selected ? 0.98 : 0.3;
} else if (request.stage === "enroute") {
color = 0xee9a2e;
opacity = 0.98;
} else if (request.stage === "arrived") {
color = 0x347e99;
opacity = selected ? 0.98 : 0.32;
}
request.routeMaterial.color.setHex(color);
request.routeMaterial.opacity = opacity;
request.routeGroup.visible = routesVisible;
});
const selected = requestById.get(selectedId);
focusFrame.position.set(selected.focus.x, 0.19, selected.focus.z);
focusFrame.scale.set(selected.focusSize, 1, selected.focusSize);
labels.forEach(({ element, request }) => {
element.classList.toggle("active", request.id === selectedId);
element.querySelector(".label-stage").textContent = stageLabel(request);
});
}
function renderAll() {
renderRequestList();
renderDetail();
renderSummary();
updateRouteStyles();
}
function selectRequest(id, focus = true) {
selectedId = id;
renderAll();
if (focus) {
const request = requestById.get(id);
desiredTarget.set(request.focus.x, 0, request.focus.z);
desiredZoom = 1.3;
}
}
function showToast(message) {
const toast = $("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2800);
}
// ---------------------------------------------------------------------
// Carry workflow
// ---------------------------------------------------------------------
function startCarry(request) {
if (activeCarry) {
showToast("One carry is already in progress.");
return;
}
if (request.stage !== "staged") {
return;
}
request.stage = "enroute";
activeCarry = {
request,
elapsed: 0,
duration: reducedMotion ? 1.2 : 6.2
};
carryGroup.visible = true;
carryMaterial.color.setHex(request.carryColor);
const start = samplePath(request.path, 0);
courier.position.set(start.x, 0.14, start.z);
selectedId = request.id;
renderAll();
showToast(`Coordinated carry started for ${request.title.toLowerCase()}.`);
}
function completeHandoff(request) {
request.stage = "complete";
carryGroup.visible = false;
renderAll();
showToast(`${request.title}: handoff logged. No personal notes added.`);
}
function samplePath(path, normalizedDistance) {
const lengths = [];
let total = 0;
for (let i = 0; i < path.length - 1; i++) {
const dx = path[i + 1][0] - path[i][0];
const dz = path[i + 1][1] - path[i][1];
const length = Math.hypot(dx, dz);
lengths.push(length);
total += length;
}
let remaining = clamp(normalizedDistance, 0, 1) * total;
for (let i = 0; i < lengths.length; i++) {
const length = lengths[i];
if (remaining <= length || i === lengths.length - 1) {
const t = length === 0 ? 0 : clamp(remaining / length, 0, 1);
const [x1, z1] = path[i];
const [x2, z2] = path[i + 1];
const dx = x2 - x1;
const dz = z2 - z1;
const divisor = Math.hypot(dx, dz) || 1;
return {
x: x1 + dx * t,
z: z1 + dz * t,
dirX: dx / divisor,
dirZ: dz / divisor
};
}
remaining -= length;
}
const end = path[path.length - 1];
return { x: end[0], z: end[1], dirX: 1, dirZ: 0 };
}
$("startNext").addEventListener("click", () => {
const next = requests.find((request) => request.stage === "staged");
if (!next) {
showToast("All matched carries are logged.");
return;
}
selectRequest(next.id, true);
startCarry(next);
});
// ---------------------------------------------------------------------
// Camera controls implemented directly
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.left = (-orthoHeight * aspect) / 2;
camera.right = (orthoHeight * aspect) / 2;
camera.top = orthoHeight / 2;
camera.bottom = -orthoHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
}
window.addEventListener("resize", resize);
resize();
function resetView() {
desiredTarget.set(0, 0, 0);
desiredZoom = 0.96;
desiredAzimuth = 0.72;
desiredElevation = 0.72;
}
$("resetView").addEventListener("click", resetView);
$("toggleRoutes").addEventListener("click", () => {
routesVisible = !routesVisible;
$("toggleRoutes").textContent = routesVisible ? "Routes on" : "Routes off";
$("toggleRoutes").classList.toggle("active", routesVisible);
updateRouteStyles();
});
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
const activePointers = new Map();
let interaction = null;
let pointerStart = { x: 0, y: 0 };
let pointerMoved = false;
let pinchStartDistance = 0;
let pinchStartZoom = desiredZoom;
function pointerDistance() {
const points = [...activePointers.values()];
if (points.length < 2) return 0;
return Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
function pickScene(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(pickTargets, false);
if (hits.length) {
const id = hits[0].object.userData.requestId;
if (id) selectRequest(id, true);
}
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 1) {
pointerStart = { x: event.clientX, y: event.clientY };
pointerMoved = false;
interaction =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else if (activePointers.size === 2) {
interaction = "pinch";
pinchStartDistance = pointerDistance();
pinchStartZoom = desiredZoom;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (activePointers.size === 2) {
const distance = pointerDistance();
if (pinchStartDistance > 0) {
desiredZoom = clamp(
pinchStartZoom * (distance / pinchStartDistance),
0.65,
2.8
);
}
return;
}
const totalDistance = Math.hypot(
event.clientX - pointerStart.x,
event.clientY - pointerStart.y
);
if (totalDistance > 4) pointerMoved = true;
if (interaction === "orbit") {
desiredAzimuth -= dx * 0.006;
desiredElevation = clamp(desiredElevation + dy * 0.004, 0.34, 1.25);
} else if (interaction === "pan") {
const scale = (2 * orthoHeight / desiredZoom) / window.innerHeight;
const rightX = Math.cos(desiredAzimuth);
const rightZ = -Math.sin(desiredAzimuth);
const forwardX = -Math.sin(desiredAzimuth);
const forwardZ = -Math.cos(desiredAzimuth);
desiredTarget.x += (-dx * rightX + dy * forwardX) * scale;
desiredTarget.z += (-dx * rightZ + dy * forwardZ) * scale;
desiredTarget.x = clamp(desiredTarget.x, -10, 10);
desiredTarget.z = clamp(desiredTarget.z, -8, 8);
}
});
function releasePointer(event) {
const wasSingle = activePointers.size === 1;
activePointers.delete(event.pointerId);
if (wasSingle && !pointerMoved && event.button === 0 && interaction === "orbit") {
pickScene(event.clientX, event.clientY);
}
if (activePointers.size === 0) {
interaction = null;
} else if (activePointers.size === 1) {
interaction = "orbit";
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredZoom = clamp(
desiredZoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.8
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "t") $("toggleRoutes").click();
const index = Number(event.key) - 1;
if (index >= 0 && index < requests.length) {
selectRequest(requests[index].id, true);
}
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 7);
cameraTarget.lerp(desiredTarget, smoothing);
azimuth += (desiredAzimuth - azimuth) * smoothing;
elevation += (desiredElevation - elevation) * smoothing;
camera.zoom += (desiredZoom - camera.zoom) * smoothing;
camera.updateProjectionMatrix();
const distance = 38;
const horizontal = Math.cos(elevation) * distance;
camera.position.set(
cameraTarget.x + Math.sin(azimuth) * horizontal,
cameraTarget.y + Math.sin(elevation) * distance,
cameraTarget.z + Math.cos(azimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function updateCourier(delta) {
if (activeCarry) {
activeCarry.elapsed += delta;
const progress = clamp(activeCarry.elapsed / activeCarry.duration, 0, 1);
const point = samplePath(activeCarry.request.path, progress);
courier.position.set(point.x, 0.14, point.z);
courier.rotation.y = Math.atan2(point.dirX, point.dirZ);
if (progress >= 1) {
const finished = activeCarry.request;
finished.stage = "arrived";
activeCarry = null;
carryGroup.visible = false;
desiredTarget.set(finished.focus.x, 0, finished.focus.z);
desiredZoom = 1.38;
renderAll();
showToast(`Carry arrived at ${finished.location.toLowerCase()}.`);
}
}
courierModel.position.y = Math.sin(clock.elapsedTime * 10) * 0.025;
}
function updateDecorations() {
const elapsed = clock.elapsedTime;
focusMaterial.opacity = 0.58 + Math.sin(elapsed * 3.2) * 0.18;
waterDrops.forEach(({ group, baseY, phase }) => {
group.position.y = baseY + Math.sin(elapsed * 2.2 + phase) * 0.12;
group.rotation.y = elapsed * 0.7 + phase;
});
clouds.forEach(({ group, baseX, phase }) => {
group.position.x = baseX + Math.sin(elapsed * 0.08 + phase) * 1.3;
});
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach(({ element, worldPosition }) => {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera(delta);
updateCourier(delta);
updateDecorations();
updateLabels();
renderer.render(scene, camera);
}
renderAll();
animate();
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```