Prompt specification
Build or customize the Three.js 3D scene "Plan a supply journey across seasons" 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: Plan a supply journey across seasons
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/plan-a-supply-journey-across-seasons-x1348
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Let users choose between seasonal routes with explicit closure rules. Animate supplies along the valid path and compare added distance without pretending to predict actual weather.
Working Three.js Starter (plan-a-supply-journey-across-seasons-x1348):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seasonal Supply Routes</title>
<style>
:root {
--season: #e6b84d;
--ink: #f5f4e9;
--muted: #b8c0b9;
--panel: rgba(23, 34, 31, 0.92);
--panel-border: rgba(255, 255, 255, 0.12);
--cyan: #2bd8c5;
--amber: #f4b942;
--red: #f06b61;
--green: #80c98b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aac3bb;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body[data-season="spring"] { --season: #83b96f; }
body[data-season="summer"] { --season: #e6b84d; }
body[data-season="autumn"] { --season: #db8751; }
body[data-season="winter"] { --season: #79aeca; }
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 0;
left: 0;
right: 0;
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 14px 20px;
pointer-events: none;
background: linear-gradient(
to bottom,
rgba(13, 24, 22, 0.78),
rgba(13, 24, 22, 0)
);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
text-shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 11px;
background: rgba(24, 38, 33, 0.72);
color: var(--season);
font-weight: 900;
font-size: 18px;
transition: color 180ms ease;
}
.brand strong {
display: block;
font-size: 14px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.brand small {
display: block;
margin-top: 3px;
color: #d4dbd4;
font-size: 11px;
letter-spacing: 0.06em;
}
.scenario-badge {
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 999px;
background: rgba(21, 33, 29, 0.72);
color: #eef2ea;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.scenario-badge span {
margin-left: 8px;
color: #f4d77e;
}
.panel {
position: fixed;
z-index: 4;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.controls {
top: 88px;
left: 18px;
width: 318px;
padding: 18px;
max-height: calc(100vh - 245px);
overflow-y: auto;
}
.rules {
top: 88px;
right: 18px;
width: 342px;
padding: 17px;
max-height: calc(100vh - 245px);
overflow-y: auto;
}
.eyebrow {
margin-bottom: 7px;
color: var(--season);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1,
h2,
p {
margin: 0;
}
h1 {
font-size: 22px;
line-height: 1.12;
letter-spacing: -0.025em;
}
h2 {
font-size: 16px;
letter-spacing: -0.01em;
}
.intro {
margin-top: 8px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.divider {
height: 1px;
margin: 15px 0;
background: rgba(255, 255, 255, 0.1);
}
.label {
display: block;
margin-bottom: 7px;
color: #d9dfd8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.season-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
}
.season-button {
min-width: 0;
padding: 9px 4px 8px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: #c9d0c9;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
.season-button:hover {
transform: translateY(-1px);
border-color: rgba(255, 255, 255, 0.28);
}
.season-button.active {
border-color: var(--season);
background: color-mix(in srgb, var(--season) 18%, transparent);
color: #fff;
}
.season-button span,
.season-button small {
display: block;
}
.season-button span {
font-size: 11px;
font-weight: 800;
}
.season-button small {
margin-top: 3px;
color: #aeb8b0;
font-size: 8px;
letter-spacing: 0.08em;
}
.season-description {
min-height: 34px;
margin-top: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.field-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
select {
width: 100%;
padding: 10px 28px 10px 10px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 9px;
outline: none;
appearance: none;
background:
linear-gradient(45deg, transparent 50%, #9eaaa0 50%) calc(100% - 13px) 16px / 5px 5px no-repeat,
linear-gradient(135deg, #9eaaa0 50%, transparent 50%) calc(100% - 8px) 16px / 5px 5px no-repeat,
rgba(255, 255, 255, 0.055);
color: #fff;
font: inherit;
font-size: 11px;
cursor: pointer;
}
select:focus {
border-color: var(--season);
}
option {
background: #23302c;
}
.route-summary {
margin-top: 14px;
padding: 12px;
border: 1px solid rgba(43, 216, 197, 0.24);
border-radius: 12px;
background: rgba(43, 216, 197, 0.07);
}
.route-summary-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 7px;
}
.route-summary strong {
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.network-status {
color: #c4ccc5;
font-size: 9px;
text-align: right;
}
.network-status.closed {
color: #ffaaa2;
}
#routePath {
color: #f5f5eb;
font-size: 12px;
line-height: 1.5;
}
#routeMeta {
margin-top: 5px;
color: #9eaaa2;
font-size: 10px;
}
.check-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
color: #cbd2cb;
font-size: 11px;
cursor: pointer;
}
.check-row input {
width: 15px;
height: 15px;
accent-color: var(--amber);
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 13px;
}
button.action {
padding: 10px 8px;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 9px;
background: rgba(255, 255, 255, 0.065);
color: #fff;
font: inherit;
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
button.action:hover {
background: rgba(255, 255, 255, 0.12);
}
button.action.primary {
border-color: rgba(43, 216, 197, 0.4);
background: rgba(43, 216, 197, 0.16);
color: #bafaf1;
}
.speed-row {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 9px;
margin-top: 12px;
color: #aeb8b0;
font-size: 10px;
}
input[type="range"] {
width: 100%;
accent-color: var(--season);
}
.rule-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.rule-count {
flex: 0 0 auto;
padding: 6px 8px;
border-radius: 8px;
background: rgba(240, 107, 97, 0.13);
color: #ffaaa2;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.rule-note {
margin: 10px 0 12px;
padding: 10px;
border-left: 3px solid var(--season);
border-radius: 0 8px 8px 0;
background: rgba(255, 255, 255, 0.055);
color: #c9d1ca;
font-size: 10px;
line-height: 1.5;
}
.rule-list {
display: grid;
gap: 7px;
}
.rule-row {
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
}
.rule-row.closed {
border-color: rgba(240, 107, 97, 0.25);
background: rgba(240, 107, 97, 0.065);
}
.rule-main {
display: flex;
align-items: center;
gap: 7px;
}
.rule-main strong {
flex: 1;
font-size: 11px;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 3px rgba(128, 201, 139, 0.1);
}
.closed .status-dot {
background: var(--red);
box-shadow: 0 0 0 3px rgba(240, 107, 97, 0.1);
}
.rule-status {
color: #aeb8b0;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
}
.closed .rule-status {
color: #ffaaa2;
}
.rule-row p {
margin-top: 5px;
padding-left: 14px;
color: #aeb8b0;
font-size: 9px;
line-height: 1.45;
}
details {
margin-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
padding-top: 11px;
}
summary {
color: #c8d0c9;
font-size: 10px;
font-weight: 750;
cursor: pointer;
}
.matrix {
margin-top: 10px;
display: grid;
gap: 5px;
}
.matrix-row {
display: grid;
grid-template-columns: minmax(88px, 1fr) repeat(4, 36px);
align-items: center;
gap: 4px;
}
.matrix-row.header {
color: #8f9c93;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.06em;
text-align: center;
}
.matrix-row.header span:first-child {
text-align: left;
}
.matrix-name {
overflow: hidden;
color: #b9c3bb;
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.matrix-chip {
padding: 4px 0;
border-radius: 5px;
background: rgba(128, 201, 139, 0.12);
color: #a8d9ad;
font-size: 8px;
font-weight: 900;
text-align: center;
}
.matrix-chip.closed {
background: rgba(240, 107, 97, 0.13);
color: #ffaaa2;
}
.metrics {
position: fixed;
z-index: 4;
left: 50%;
bottom: 18px;
width: min(680px, calc(100vw - 36px));
display: grid;
grid-template-columns: repeat(3, 1fr);
overflow: hidden;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: rgba(21, 32, 29, 0.91);
box-shadow: 0 15px 45px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(15px);
transform: translateX(-50%);
}
.metric {
min-width: 0;
padding: 13px 17px 12px;
border-right: 1px solid rgba(255, 255, 255, 0.1);
}
.metric:last-child {
border-right: 0;
}
.metric-label {
color: #9eaaa2;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.metric-value {
margin-top: 3px;
overflow: hidden;
color: #fff;
font-size: 21px;
font-weight: 800;
letter-spacing: -0.035em;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric-value.cyan { color: var(--cyan); }
.metric-value.amber { color: var(--amber); }
.metric-value.red { color: #ff9188; }
.metric-sub {
margin-top: 2px;
overflow: hidden;
color: #89968d;
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.legend {
position: fixed;
z-index: 3;
left: 354px;
bottom: 24px;
display: flex;
gap: 13px;
padding: 7px 10px;
border-radius: 9px;
background: rgba(22, 34, 30, 0.72);
color: #d2d9d2;
font-size: 9px;
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.swatch {
width: 17px;
height: 4px;
border-radius: 3px;
background: var(--cyan);
}
.swatch.baseline { background: var(--amber); }
.swatch.closed { background: var(--red); }
.camera-hint {
position: fixed;
z-index: 3;
right: 376px;
bottom: 25px;
color: rgba(242, 246, 240, 0.84);
font-size: 9px;
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #1b2b27;
color: #dfe9e2;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1050px) {
.legend {
display: none;
}
.camera-hint {
right: 374px;
}
}
@media (max-width: 760px) {
.topbar {
height: 62px;
padding: 10px 12px;
}
.brand small,
.scenario-badge span {
display: none;
}
.scenario-badge {
font-size: 8px;
}
.controls {
top: 70px;
left: 10px;
width: min(300px, calc(100vw - 20px));
max-height: 47vh;
padding: 14px;
}
.rules {
top: auto;
right: 10px;
bottom: 108px;
width: min(300px, calc(100vw - 20px));
max-height: 36vh;
padding: 13px;
}
.metrics {
bottom: 10px;
width: calc(100vw - 20px);
}
.metric {
padding: 10px;
}
.metric-value {
font-size: 17px;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body data-season="summer">
<div id="stage"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark">SR</div>
<div>
<strong>Seasonal Supply Routes</strong>
<small>Low-poly logistics planning sandbox</small>
</div>
</div>
<div class="scenario-badge">
Fixed seasonal scenario <span>• No weather data</span>
</div>
</header>
<aside class="panel controls">
<div class="eyebrow">Route control</div>
<h1>Choose a seasonal network</h1>
<p class="intro">
Closed corridors are removed before the route is calculated.
Supplies follow the remaining valid path.
</p>
<div class="divider"></div>
<div class="label">Seasonal scenario</div>
<div class="season-grid">
<button class="season-button" data-season="spring" type="button">
<span>Spring</span><small>MAR–MAY</small>
</button>
<button class="season-button active" data-season="summer" type="button">
<span>Summer</span><small>JUN–AUG</small>
</button>
<button class="season-button" data-season="autumn" type="button">
<span>Autumn</span><small>SEP–NOV</small>
</button>
<button class="season-button" data-season="winter" type="button">
<span>Winter</span><small>DEC–FEB</small>
</button>
</div>
<p id="seasonDescription" class="season-description"></p>
<div class="divider"></div>
<div class="label">Origin and destination</div>
<div class="field-grid">
<select id="origin" aria-label="Origin">
<option value="A">Trailhead</option>
<option value="B">Fork</option>
<option value="C">North Lookout</option>
<option value="D">Summit</option>
<option value="E">East Ridge</option>
<option value="F">Alpine Camp</option>
</select>
<select id="destination" aria-label="Destination">
<option value="A">Trailhead</option>
<option value="B">Fork</option>
<option value="C">North Lookout</option>
<option value="D">Summit</option>
<option value="E">East Ridge</option>
<option value="F" selected>Alpine Camp</option>
</select>
</div>
<div class="route-summary">
<div class="route-summary-top">
<strong id="routeTitle">Valid supply route</strong>
<span id="networkStatus" class="network-status"></span>
</div>
<div id="routePath"></div>
<div id="routeMeta"></div>
</div>
<label class="check-row">
<input id="compareBaseline" type="checkbox" checked>
Show all-season shortest-path reference
</label>
<div class="actions">
<button id="playButton" class="action primary" type="button">Pause supplies</button>
<button id="restartButton" class="action" type="button">Restart supplies</button>
</div>
<div class="speed-row">
<span>Speed</span>
<input id="speed" type="range" min="0.5" max="2.5" step="0.1" value="1">
<span id="speedValue">1.0×</span>
</div>
</aside>
<aside class="panel rules">
<div class="rule-header">
<div>
<div class="eyebrow">Explicit rulebook</div>
<h2 id="ruleTitle">Summer closures</h2>
</div>
<div id="ruleCount" class="rule-count"></div>
</div>
<p class="rule-note">
These are deterministic seasonal presets with fixed date windows.
The scene does not use live road reports, observations, forecasts,
or weather prediction.
</p>
<div id="ruleList" class="rule-list"></div>
<details>
<summary>View complete seasonal rule matrix</summary>
<div id="ruleMatrix" class="matrix"></div>
</details>
</aside>
<section class="metrics">
<div class="metric">
<div class="metric-label">Valid seasonal route</div>
<div id="validDistance" class="metric-value cyan">—</div>
<div class="metric-sub">Uses current closure rules</div>
</div>
<div class="metric">
<div class="metric-label">All-season reference</div>
<div id="baselineDistance" class="metric-value amber">—</div>
<div class="metric-sub">Shortest path ignoring closures</div>
</div>
<div class="metric">
<div class="metric-label">Added distance</div>
<div id="addedDistance" class="metric-value">—</div>
<div id="addedSub" class="metric-sub">Compared with reference</div>
</div>
</section>
<div class="legend">
<div class="legend-item"><span class="swatch"></span> Valid route</div>
<div class="legend-item"><span class="swatch baseline"></span> Reference</div>
<div class="legend-item"><span class="swatch closed"></span> Closed</div>
</div>
<div class="camera-hint">Drag: orbit · Shift/right-drag: pan · Scroll/pinch: zoom</div>
<div id="loading">Building low-poly terrain…</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xaec7bf);
scene.fog = new THREE.Fog(0xaec7bf, 78, 175);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
350
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
$("stage").appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe6f3ed, 0x526046, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefcf, 3.2);
sun.position.set(-38, 65, 32);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -72;
sun.shadow.camera.right = 72;
sun.shadow.camera.top = 62;
sun.shadow.camera.bottom = -62;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 170;
sun.shadow.bias = -0.00025;
scene.add(sun);
const seasonInfo = {
spring: {
label: "Spring",
window: "Mar 1 – May 31",
description: "Thaw and repair window: washout inspection and bridge work remove two central corridors."
},
summer: {
label: "Summer",
window: "Jun 1 – Aug 31",
description: "Longest open network: no seasonal corridor closures are defined in this preset."
},
autumn: {
label: "Autumn",
window: "Sep 1 – Nov 30",
description: "Maintenance shoulder: the east road and high pass are removed for scheduled work."
},
winter: {
label: "Winter",
window: "Dec 1 – Feb 28",
description: "Conservative winter network: fixed snow, ice, and avalanche protocols remove four corridors."
}
};
const seasonalRules = {
spring: {
AE: "Closed by scheduled washout inspection rule, Mar 1–May 31.",
BE: "Closed by bridge-deck repair rule, Mar 1–May 31."
},
summer: {},
autumn: {
AE: "Closed by annual road-maintenance rule, Sep 1–Nov 30.",
CD: "Closed by rockfall-maintenance rule, Sep 1–Nov 30."
},
winter: {
AE: "Closed by the fixed seasonal snow/ice protocol, Dec 1–Feb 28.",
BC: "Closed by the fixed seasonal snow/ice protocol, Dec 1–Feb 28.",
BE: "Closed by the fixed seasonal snow/ice protocol, Dec 1–Feb 28.",
CD: "Closed by the fixed seasonal avalanche protocol, Dec 1–Feb 28."
}
};
let currentSeason = "summer";
let currentRoute = null;
let baselineRoute = null;
let currentPathData = null;
let animationDistance = 0;
let animationSpeed = 1;
let isPlaying = true;
function terrainHeight(x, z) {
const summit =
10.5 * Math.exp(-((x + 30) ** 2 / 620 + (z + 22) ** 2 / 430));
const eastPeak =
7.5 * Math.exp(-((x - 31) ** 2 / 650 + (z + 28) ** 2 / 430));
const northHill =
3.4 * Math.exp(-((x + 24) ** 2 / 400 + (z - 1) ** 2 / 320));
const westernHill =
2.2 * Math.exp(-((x + 46) ** 2 / 520 + (z + 4) ** 2 / 600));
const rolling =
0.85 * Math.sin(x * 0.105) * Math.cos(z * 0.09) +
0.35 * Math.sin((x + z) * 0.16);
return summit + eastPeak + northHill + westernHill + rolling;
}
const N = {
A: { name: "Trailhead", x: 0, z: 28 },
B: { name: "Fork", x: 0, z: 8 },
C: { name: "North Lookout", x: -24, z: 0 },
D: { name: "Summit", x: -30, z: -22 },
E: { name: "East Ridge", x: 25, z: -4 },
F: { name: "Alpine Camp", x: 35, z: -28 }
};
for (const node of Object.values(N)) {
node.position = new THREE.Vector3(
node.x,
terrainHeight(node.x, node.z),
node.z
);
}
const edges = [
{ id: "AB", a: "A", b: "B", name: "Gate Trail" },
{ id: "AC", a: "A", b: "C", name: "North Access" },
{ id: "AE", a: "A", b: "E", name: "East Gate Road" },
{ id: "BC", a: "B", b: "C", name: "North Spur" },
{ id: "BE", a: "B", b: "E", name: "Creek Bridge" },
{ id: "CD", a: "C", b: "D", name: "High Pass" },
{ id: "DE", a: "D", b: "E", name: "Ridge Traverse" },
{ id: "DF", a: "D", b: "F", name: "Summit Direct" },
{ id: "EF", a: "E", b: "F", name: "Camp Road" },
{ id: "BF", a: "B", b: "F", name: "Service Track" },
{ id: "CF", a: "C", b: "F", name: "Lookout Traverse" }
];
for (const edge of edges) {
edge.length = Math.hypot(
N[edge.a].position.x - N[edge.b].position.x,
N[edge.a].position.z - N[edge.b].position.z
);
edge.closed = {};
for (const season of Object.keys(seasonalRules)) {
edge.closed[season] = seasonalRules[season][edge.id] || null;
}
}
function createTerrain() {
const nx = 28;
const nz = 22;
const width = 112;
const depth = 90;
const positions = [];
const colors = [];
const indices = [];
const low = new THREE.Color(0x657a55);
const mid = new THREE.Color(0x879167);
const high = new THREE.Color(0xaaa083);
const peak = new THREE.Color(0xc8bda3);
for (let i = 0; i <= nx; i++) {
const x = -width / 2 + (i / nx) * width;
for (let j = 0; j <= nz; j++) {
const z = -depth / 2 + (j / nz) * depth;
const y = terrainHeight(x, z);
positions.push(x, y, z);
const color = new THREE.Color();
if (y < 2.5) {
color.copy(low).lerp(mid, Math.max(0, y / 2.5));
} else if (y < 6.5) {
color.copy(mid).lerp(high, (y - 2.5) / 4);
} else {
color.copy(high).lerp(peak, Math.min(1, (y - 6.5) / 5.5));
}
color.multiplyScalar(0.92 + ((i * 17 + j * 13) % 11) / 80);
colors.push(color.r, color.g, color.b);
}
}
for (let i = 0; i < nx; i++) {
for (let j = 0; j < nz; j++) {
const a = i * (nz + 1) + j;
const b = a + 1;
const c = a + nz + 1;
const d = c + 1;
indices.push(a, b, c, b, d, c);
}
}
let geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setIndex(indices);
geometry = geometry.toNonIndexed();
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 1
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
}
createTerrain();
function sampleLine(a, b, segments = 18) {
const points = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
points.push(new THREE.Vector3(x, terrainHeight(x, z), z));
}
return points;
}
function makeRibbon(points, width, material, heightOffset = 0.3) {
const positions = [];
const indices = [];
for (let i = 0; i < points.length; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(points.length - 1, i + 1)];
const dx = next.x - previous.x;
const dz = next.z - previous.z;
const length = Math.hypot(dx, dz) || 1;
const px = -dz / length;
const pz = dx / length;
for (const side of [-1, 1]) {
const x = points[i].x + px * width * 0.5 * side;
const z = points[i].z + pz * width * 0.5 * side;
const y = terrainHeight(x, z) + heightOffset;
positions.push(x, y, z);
}
}
for (let i = 0; i < points.length - 1; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, c, b, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
return mesh;
}
function addBox(parent, size, position, color, rotationY = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
new THREE.MeshStandardMaterial({ color, roughness: 0.9, flatShading: true })
);
mesh.position.copy(position);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const roadVisuals = new Map();
for (const edge of edges) {
const roadMaterial = new THREE.MeshStandardMaterial({
color: 0x927b5d,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
const points = sampleLine(
N[edge.a].position,
N[edge.b].position,
22
);
const road = makeRibbon(points, 2.15, roadMaterial, 0.3);
scene.add(road);
const closureGroup = new THREE.Group();
const angle = -Math.atan2(
N[edge.b].position.z - N[edge.a].position.z,
N[edge.b].position.x - N[edge.a].position.x
);
const dashLength = Math.max(0.65, edge.length / 18);
for (let i = 0; i < 12; i++) {
const t = (i + 0.5) / 12;
const x = THREE.MathUtils.lerp(
N[edge.a].position.x,
N[edge.b].position.x,
t
);
const z = THREE.MathUtils.lerp(
N[edge.a].position.z,
N[edge.b].position.z,
t
);
const dash = new THREE.Mesh(
new THREE.BoxGeometry(dashLength, 0.16, 0.48),
new THREE.MeshBasicMaterial({ color: 0xf06b61 })
);
dash.position.set(x, terrainHeight(x, z) + 0.64, z);
dash.rotation.y = angle;
closureGroup.add(dash);
}
const barrier = new THREE.Group();
const midpoint = new THREE.Vector3().addVectors(
N[edge.a].position,
N[edge.b].position
).multiplyScalar(0.5);
barrier.position.set(
midpoint.x,
terrainHeight(midpoint.x, midpoint.z) + 0.45,
midpoint.z
);
barrier.rotation.y = angle;
addBox(
barrier,
new THREE.Vector3(0.2, 1.8, 0.2),
new THREE.Vector3(0, 0.9, -1.15),
0x4a4035
);
addBox(
barrier,
new THREE.Vector3(0.2, 1.8, 0.2),
new THREE.Vector3(0, 0.9, 1.15),
0x4a4035
);
addBox(
barrier,
new THREE.Vector3(0.22, 0.35, 2.65),
new THREE.Vector3(0, 1.35, 0),
0xf06b61
);
closureGroup.add(barrier);
closureGroup.visible = false;
scene.add(closureGroup);
roadVisuals.set(edge.id, {
road,
roadMaterial,
closureGroup,
barrier
});
}
function createWater() {
const riverCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-56, 0, -4),
new THREE.Vector3(-40, 0, 1),
new THREE.Vector3(-23, 0, 8),
new THREE.Vector3(-7, 0, 9),
new THREE.Vector3(5, 0, 5),
new THREE.Vector3(15, 0, 1),
new THREE.Vector3(27, 0, -5),
new THREE.Vector3(42, 0, -13),
new THREE.Vector3(56, 0, -20)
]);
const river = makeRibbon(
riverCurve.getPoints(90),
2.4,
new THREE.MeshStandardMaterial({
color: 0x4d93a0,
roughness: 0.34,
metalness: 0.05,
side: THREE.DoubleSide
}),
0.12
);
scene.add(river);
const lakeX = -20;
const lakeZ = 13;
const lakeY = terrainHeight(lakeX, lakeZ) + 0.18;
const shore = new THREE.Mesh(
new THREE.CircleGeometry(1, 20),
new THREE.MeshStandardMaterial({
color: 0xb5a879,
roughness: 1
})
);
shore.rotation.x = -Math.PI / 2;
shore.scale.set(10.2, 6.2, 1);
shore.position.set(lakeX, lakeY - 0.06, lakeZ);
scene.add(shore);
const lake = new THREE.Mesh(
new THREE.CircleGeometry(1, 20),
new THREE.MeshStandardMaterial({
color: 0x5a9eaa,
roughness: 0.3,
metalness: 0.05
})
);
lake.rotation.x = -Math.PI / 2;
lake.scale.set(8.8, 4.9, 1);
lake.position.set(lakeX, lakeY, lakeZ);
scene.add(lake);
}
createWater();
function seededRandom(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(94821);
function distanceToSegment(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const denominator = dx * dx + dz * dz;
const t = denominator
? THREE.MathUtils.clamp(
((px - ax) * dx + (pz - az) * dz) / denominator,
0,
1
)
: 0;
const x = ax + t * dx;
const z = az + t * dz;
return Math.hypot(px - x, pz - z);
}
function createForest() {
const treePositions = [];
for (let attempt = 0; attempt < 850 && treePositions.length < 105; attempt++) {
const x = random() * 102 - 51;
const z = random() * 84 - 42;
if (Object.values(N).some((node) => Math.hypot(x - node.x, z - node.z) < 5.5)) {
continue;
}
const closeToRoad = edges.some((edge) =>
distanceToSegment(
x,
z,
N[edge.a].x,
N[edge.a].z,
N[edge.b].x,
N[edge.b].z
) < 3.1
);
if (closeToRoad) continue;
treePositions.push({
x,
z,
scale: 0.65 + random() * 0.8,
rotation: random() * Math.PI * 2
});
}
const count = treePositions.length;
const trunkGeometry = new THREE.CylinderGeometry(0.2, 0.28, 1.7, 5);
const foliageGeometry = new THREE.ConeGeometry(1.25, 3.9, 6);
const trunks = new THREE.InstancedMesh(
trunkGeometry,
new THREE.MeshStandardMaterial({
color: 0x6a503a,
roughness: 1,
flatShading: true
}),
count
);
const foliage = new THREE.InstancedMesh(
foliageGeometry,
new THREE.MeshStandardMaterial({
color: 0x355d43,
roughness: 1,
flatShading: true
}),
count
);
const dummy = new THREE.Object3D();
treePositions.forEach((tree, index) => {
const y = terrainHeight(tree.x, tree.z);
dummy.position.set(tree.x, y + 0.75 * tree.scale, tree.z);
dummy.rotation.set(0, tree.rotation, 0);
dummy.scale.set(tree.scale, tree.scale, tree.scale);
dummy.updateMatrix();
trunks.setMatrixAt(index, dummy.matrix);
dummy.position.set(tree.x, y + 2.35 * tree.scale, tree.z);
dummy.scale.set(tree.scale, tree.scale, tree.scale);
dummy.updateMatrix();
foliage.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color().setHSL(
0.29 + random() * 0.055,
0.28 + random() * 0.12,
0.20 + random() * 0.09
);
foliage.setColorAt(index, color);
});
trunks.castShadow = true;
trunks.receiveShadow = true;
foliage.castShadow = true;
foliage.receiveShadow = true;
trunks.instanceMatrix.needsUpdate = true;
foliage.instanceMatrix.needsUpdate = true;
if (foliage.instanceColor) foliage.instanceColor.needsUpdate = true;
scene.add(trunks, foliage);
const rockCount = 34;
const rocks = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(0.8, 0),
new THREE.MeshStandardMaterial({
color: 0x777b70,
roughness: 1,
flatShading: true
}),
rockCount
);
for (let i = 0; i < rockCount; i++) {
const x = random() * 100 - 50;
const z = random() * 82 - 41;
const scale = 0.35 + random() * 0.95;
dummy.position.set(x, terrainHeight(x, z) + 0.35 * scale, z);
dummy.rotation.set(random(), random() * Math.PI, random());
dummy.scale.set(scale, scale * 0.75, scale);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
}
rocks.castShadow = true;
rocks.receiveShadow = true;
rocks.instanceMatrix.needsUpdate = true;
scene.add(rocks);
}
createForest();
function makeLabel(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(24, 38, 34, 0.88)";
context.beginPath();
if (context.roundRect) {
context.roundRect(8, 12, 496, 98, 20);
} else {
context.rect(8, 12, 496, 98);
}
context.fill();
context.strokeStyle = "rgba(255,255,255,0.25)";
context.lineWidth = 4;
context.stroke();
context.fillStyle = "#f4f5ec";
context.font = "700 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text.toUpperCase(), 256, 61);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(12.5, 3.1, 1);
sprite.renderOrder = 20;
return sprite;
}
function createNodeStructure(id) {
const node = N[id];
const group = new THREE.Group();
group.position.copy(node.position);
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(2.2, 2.5, 0.32, 8),
new THREE.MeshStandardMaterial({
color: 0xb8aa82,
roughness: 1,
flatShading: true
})
);
pad.position.y = 0.05;
pad.receiveShadow = true;
group.add(pad);
if (id === "A") {
addBox(
group,
new THREE.Vector3(0.28, 3.4, 0.28),
new THREE.Vector3(-1.7, 1.7, 0),
0x604832
);
addBox(
group,
new THREE.Vector3(0.28, 3.4, 0.28),
new THREE.Vector3(1.7, 1.7, 0),
0x604832
);
addBox(
group,
new THREE.Vector3(3.7, 0.45, 0.35),
new THREE.Vector3(0, 3.15, 0),
0xc29753
);
} else if (id === "B") {
addBox(
group,
new THREE.Vector3(0.3, 3.3, 0.3),
new THREE.Vector3(0, 1.65, 0),
0x604832
);
addBox(
group,
new THREE.Vector3(2.4, 0.45, 0.25),
new THREE.Vector3(0.65, 2.65, 0),
0xc29753
);
addBox(
group,
new THREE.Vector3(1.8, 0.38, 0.25),
new THREE.Vector3(0.35, 1.85, 0),
0xd8c89d
);
} else if (id === "C") {
addBox(
group,
new THREE.Vector3(2.4, 1.6, 2.2),
new THREE.Vector3(0, 3.2, 0),
0xb77d4e
);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.1, 1.25, 4),
new THREE.MeshStandardMaterial({
color: 0x604a3b,
roughness: 1,
flatShading: true
})
);
roof.position.y = 4.55;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
for (const x of [-0.85, 0.85]) {
for (const z of [-0.75, 0.75]) {
addBox(
group,
new THREE.Vector3(0.22, 2.5, 0.22),
new THREE.Vector3(x, 1.25, z),
0x654a35
);
}
}
} else if (id === "D") {
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x777970,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 4; i++) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.85 - i * 0.1, 0),
rockMaterial
);
rock.position.y = 0.65 + i * 0.8;
rock.scale.set(1, 0.7, 1);
rock.castShadow = true;
group.add(rock);
}
} else {
addBox(
group,
new THREE.Vector3(2.8, 1.7, 2.4),
new THREE.Vector3(0, 1.05, 0),
0xa76d42
);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.5, 1.45, 4),
new THREE.MeshStandardMaterial({
color: 0x59493d,
roughness: 1,
flatShading: true
})
);
roof.position.y = 2.55;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
if (id === "F") {
const tent = new THREE.Mesh(
new THREE.ConeGeometry(1.5, 2.2, 4),
new THREE.MeshStandardMaterial({
color: 0xd27a43,
roughness: 1,
flatShading: true
})
);
tent.position.set(2.2, 1.2, 0.6);
tent.rotation.y = Math.PI / 4;
tent.castShadow = true;
group.add(tent);
}
}
const label = makeLabel(node.name);
label.position.set(0, id === "C" ? 7 : 5.7, 0);
group.add(label);
scene.add(group);
}
for (const id of Object.keys(N)) createNodeStructure(id);
const activeRouteGroup = new THREE.Group();
const baselineRouteGroup = new THREE.Group();
scene.add(activeRouteGroup, baselineRouteGroup);
function clearDynamicGroup(group) {
for (const child of [...group.children]) {
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) object.material.dispose();
});
group.remove(child);
}
}
function drawRoute(group, route, color, width, opacity, order) {
clearDynamicGroup(group);
if (!route) return;
for (const edge of route.edges) {
const points = sampleLine(
N[edge.a].position,
N[edge.b].position,
24
);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
});
const ribbon = makeRibbon(points, width, material, 0.54);
ribbon.renderOrder = order;
group.add(ribbon);
}
}
function shortestPath(start, end, season = null) {
const distances = {};
const previous = {};
const visited = new Set();
for (const id of Object.keys(N)) {
distances[id] = Infinity;
previous[id] = null;
}
distances[start] = 0;
while (true) {
let current = null;
let smallest = Infinity;
for (const id of Object.keys(N)) {
if (!visited.has(id) && distances[id] < smallest) {
smallest = distances[id];
current = id;
}
}
if (current === null || current === end) break;
visited.add(current);
for (const edge of edges) {
if (season !== null && edge.closed[season]) continue;
let neighbor = null;
if (edge.a === current) neighbor = edge.b;
if (edge.b === current) neighbor = edge.a;
if (!neighbor || visited.has(neighbor)) continue;
const candidate = distances[current] + edge.length;
if (candidate < distances[neighbor]) {
distances[neighbor] = candidate;
previous[neighbor] = { node: current, edge };
}
}
}
if (!Number.isFinite(distances[end])) {
return { nodes: [], edges: [], distance: Infinity };
}
const nodes = [];
const routeEdges = [];
let cursor = end;
while (cursor !== start) {
const record = previous[cursor];
if (!record) break;
nodes.unshift(cursor);
routeEdges.unshift(record.edge);
cursor = record.node;
}
nodes.unshift(start);
return {
nodes,
edges: routeEdges,
distance: distances[end]
};
}
function preparePathData(route) {
if (!route || !route.nodes.length) return null;
const points = route.nodes.map((id) => N[id].position);
const cumulative = [0];
for (let i = 1; i < points.length; i++) {
cumulative.push(
cumulative[i - 1] +
Math.hypot(
points[i].x - points[i - 1].x,
points[i].z - points[i - 1].z
)
);
}
return {
points,
cumulative,
total: cumulative[cumulative.length - 1]
};
}
function makeSupplyCart(color) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 0.65, 1.65),
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
flatShading: true
})
);
body.position.y = 0.75;
body.castShadow = true;
group.add(body);
const cargo = new THREE.Mesh(
new THREE.BoxGeometry(0.95, 0.75, 1.15),
new THREE.MeshStandardMaterial({
color: 0xf1dd9b,
roughness: 0.85,
flatShading: true
})
);
cargo.position.set(0, 1.43, -0.05);
cargo.castShadow = true;
group.add(cargo);
const strap = new THREE.Mesh(
new THREE.BoxGeometry(1.02, 0.1, 0.18),
new THREE.MeshStandardMaterial({ color: 0x34433e })
);
strap.position.set(0, 1.48, -0.05);
group.add(strap);
const wheelGeometry = new THREE.CylinderGeometry(0.3, 0.3, 0.22, 8);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x252c29,
roughness: 0.95,
flatShading: true
});
for (const x of [-0.62, 0.62]) {
for (const z of [-0.53, 0.53]) {
const wheel = new THREE.Mesh(wheelGeometry, wheelMaterial);
wheel.position.set(x, 0.36, z);
wheel.rotation.z = Math.PI / 2;
wheel.castShadow = true;
group.add(wheel);
}
}
scene.add(group);
return group;
}
const supplyCarts = [
makeSupplyCart(0x2bd8c5),
makeSupplyCart(0xe98643),
makeSupplyCart(0xf0cf62)
];
function samplePath(data, distance) {
if (!data || data.total <= 0) return null;
const d = THREE.MathUtils.clamp(distance, 0, data.total);
let segmentIndex = 1;
while (
segmentIndex < data.cumulative.length - 1 &&
data.cumulative[segmentIndex] < d
) {
segmentIndex++;
}
const start = data.points[segmentIndex - 1];
const end = data.points[segmentIndex];
const segmentStart = data.cumulative[segmentIndex - 1];
const segmentLength = data.cumulative[segmentIndex] - segmentStart;
const t = segmentLength
? (d - segmentStart) / segmentLength
: 0;
const x = THREE.MathUtils.lerp(start.x, end.x, t);
const z = THREE.MathUtils.lerp(start.z, end.z, t);
const direction = new THREE.Vector3(
end.x - start.x,
0,
end.z - start.z
).normalize();
return {
position: new THREE.Vector3(x, terrainHeight(x, z) + 0.12, z),
direction,
angle: Math.atan2(direction.x, direction.z)
};
}
function updateSupplyCarts() {
if (!currentPathData || !currentPathData.total) {
supplyCarts.forEach((cart) => (cart.visible = false));
return;
}
const cycleLength = currentPathData.total + 8;
const leadDistance = animationDistance % cycleLength;
supplyCarts.forEach((cart, index) => {
const distance = leadDistance - index * 3.2;
if (distance < 0 || distance > currentPathData.total) {
cart.visible = false;
return;
}
const sample = samplePath(currentPathData, distance);
if (!sample) {
cart.visible = false;
return;
}
cart.visible = true;
cart.position.copy(sample.position);
const difference = Math.atan2(
Math.sin(sample.angle - cart.rotation.y),
Math.cos(sample.angle - cart.rotation.y)
);
cart.rotation.y += difference * 0.18;
});
}
function applyClosureVisuals() {
for (const edge of edges) {
const visual = roadVisuals.get(edge.id);
const closed = Boolean(edge.closed[currentSeason]);
visual.closureGroup.visible = closed;
visual.roadMaterial.color.setHex(closed ? 0xa17662 : 0x927b5d);
}
}
function renderRulePanel() {
const rules = seasonalRules[currentSeason];
const closedCount = Object.keys(rules).length;
$("ruleTitle").textContent = `${seasonInfo[currentSeason].label} closures`;
$("ruleCount").textContent = `${closedCount} closed`;
const sortedEdges = [...edges].sort((a, b) => {
const aClosed = Boolean(a.closed[currentSeason]);
const bClosed = Boolean(b.closed[currentSeason]);
return Number(bClosed) - Number(aClosed);
});
$("ruleList").innerHTML = sortedEdges
.map((edge) => {
const reason = edge.closed[currentSeason];
const closed = Boolean(reason);
return `
<div class="rule-row ${closed ? "closed" : ""}">
<div class="rule-main">
<span class="status-dot"></span>
<strong>${edge.name}</strong>
<span class="rule-status">${closed ? "CLOSED" : "OPEN"}</span>
</div>
<p>${
closed
? reason
: "No closure rule is defined for this seasonal preset."
}</p>
</div>
`;
})
.join("");
$("ruleMatrix").innerHTML = `
<div class="matrix-row header">
<span>Corridor</span>
<span>SPR</span>
<span>SUM</span>
<span>AUT</span>
<span>WIN</span>
</div>
${edges
.map(
(edge) => `
<div class="matrix-row">
<span class="matrix-name">${edge.name}</span>
${["spring", "summer", "autumn", "winter"]
.map(
(season) => `
<span
class="matrix-chip ${edge.closed[season] ? "closed" : ""}"
title="${edge.closed[season] || "Open in this preset"}"
>${edge.closed[season] ? "C" : "O"}</span>
`
)
.join("")}
</div>
`
)
.join("")}
`;
}
function updateRouteUI() {
const hasRoute = currentRoute && Number.isFinite(currentRoute.distance);
const hasBaseline = baselineRoute && Number.isFinite(baselineRoute.distance);
const added = hasRoute && hasBaseline
? currentRoute.distance - baselineRoute.distance
: 0;
const closedCount = Object.keys(seasonalRules[currentSeason]).length;
$("seasonDescription").textContent = seasonInfo[currentSeason].description;
$("seasonDescription").title = seasonInfo[currentSeason].window;
$("networkStatus").textContent = `${closedCount} closure rule${
closedCount === 1 ? "" : "s"
} active`;
$("networkStatus").classList.toggle("closed", closedCount > 0);
if (hasRoute) {
$("routeTitle").textContent = "Valid supply route";
$("routePath").textContent = currentRoute.nodes
.map((id) => N[id].name)
.join(" → ");
$("routeMeta").textContent = `${currentRoute.edges.length} corridors · ${currentRoute.distance.toFixed(1)} km`;
$("validDistance").textContent = `${currentRoute.distance.toFixed(1)} km`;
} else {
$("routeTitle").textContent = "No valid route";
$("routePath").textContent = "The selected closure rules disconnect these endpoints.";
$("routeMeta").textContent = "Choose another destination or seasonal scenario.";
$("validDistance").textContent = "No path";
$("validDistance").className = "metric-value red";
}
if (hasBaseline) {
$("baselineDistance").textContent = `${baselineRoute.distance.toFixed(1)} km`;
} else {
$("baselineDistance").textContent = "—";
}
if (!hasRoute) {
$("addedDistance").textContent = "—";
$("addedSub").textContent = "No valid seasonal path";
} else if (added < 0.05) {
$("addedDistance").textContent = "0.0 km";
$("addedDistance").className = "metric-value";
$("addedSub").textContent = "Same as all-season reference";
} else {
$("addedDistance").textContent = `+${added.toFixed(1)} km`;
$("addedDistance").className = "metric-value red";
$("addedSub").textContent = "Detour vs. all-season reference";
}
baselineRouteGroup.visible = $("compareBaseline").checked;
applyClosureVisuals();
renderRulePanel();
}
function recomputeRoutes() {
const origin = $("origin").value;
const destination = $("destination").value;
currentRoute = shortestPath(origin, destination, currentSeason);
baselineRoute = shortestPath(origin, destination, null);
currentPathData = preparePathData(currentRoute);
animationDistance = 0;
drawRoute(
activeRouteGroup,
currentRoute,
0x2bd8c5,
1.45,
0.96,
4
);
drawRoute(
baselineRouteGroup,
baselineRoute,
0xf4b942,
0.62,
0.92,
3
);
updateRouteUI();
}
document.querySelectorAll(".season-button").forEach((button) => {
button.addEventListener("click", () => {
currentSeason = button.dataset.season;
document.body.dataset.season = currentSeason;
document.querySelectorAll(".season-button").forEach((other) => {
const active = other === button;
other.classList.toggle("active", active);
other.setAttribute("aria-pressed", String(active));
});
recomputeRoutes();
});
});
function handleEndpointChange() {
if ($("origin").value === $("destination").value) {
$("destination").value = $("origin").value === "A" ? "F" : "A";
}
recomputeRoutes();
}
$("origin").addEventListener("change", handleEndpointChange);
$("destination").addEventListener("change", handleEndpointChange);
$("compareBaseline").addEventListener("change", () => {
baselineRouteGroup.visible = $("compareBaseline").checked;
});
$("playButton").addEventListener("click", () => {
isPlaying = !isPlaying;
$("playButton").textContent = isPlaying ? "Pause supplies" : "Play supplies";
});
$("restartButton").addEventListener("click", () => {
animationDistance = 0;
if (!isPlaying) {
isPlaying = true;
$("playButton").textContent = "Pause supplies";
}
});
$("speed").addEventListener("input", (event) => {
animationSpeed = Number(event.target.value);
$("speedValue").textContent = `${animationSpeed.toFixed(1)}×`;
});
// Direct camera controls: orbit, pan, wheel zoom, and two-finger pinch.
const cameraState = {
azimuth: 0.66,
polar: 1.02,
radius: 108,
target: new THREE.Vector3(0, 3.2, -1)
};
const pointers = new Map();
let lastPinchDistance = 0;
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
mode: event.button === 2 || event.shiftKey ? "pan" : "orbit"
});
if (pointers.size === 2) {
const [first, second] = [...pointers.values()];
lastPinchDistance = Math.hypot(
first.x - second.x,
first.y - second.y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) return;
if (pointers.size === 2) {
const [first, second] = [...pointers.values()];
const distance = Math.hypot(
first.x - second.x,
first.y - second.y
);
if (lastPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (lastPinchDistance / distance),
42,
165
);
}
lastPinchDistance = distance;
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.mode === "pan") {
const factor = cameraState.radius / innerHeight * 1.25;
const right = new THREE.Vector3(
Math.cos(cameraState.azimuth),
0,
-Math.sin(cameraState.azimuth)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.azimuth),
0,
-Math.cos(cameraState.azimuth)
);
cameraState.target.addScaledVector(right, -dx * factor);
cameraState.target.addScaledVector(forward, -dy * factor);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-36,
36
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-32,
32
);
} else {
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.34,
1.36
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
42,
165
);
},
{ passive: false }
);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
recomputeRoutes();
updateCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (isPlaying && currentPathData) {
animationDistance += delta * 7.2 * animationSpeed;
}
updateSupplyCarts();
updateCamera();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```