Prompt specification
Build or customize the Three.js 3D scene "Schedule market trips across changing water conditions" 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: Schedule market trips across changing water conditions
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/schedule-market-trips-across-changing-water-conditions-x2564
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly river-market route planning scene. Arrange several small landings along a branching river, with a market at one landing and homes or storage sheds at the others. Give each channel a stated schematic depth and a prescribed current direction. Let the user choose a boat route and a water-condition preset, then show which landings remain reachable and the travel time under those assumptions. A route blocked by insufficient modeled depth should stop at the relevant channel. Keep route distance, current effects, and landing access separate, and label the display as a simplified teaching model rather than real navigation guidance.
Working Three.js Starter (schedule-market-trips-across-changing-water-conditions-x2564):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Branchwater — River Route Teaching Model</title>
<style>
:root {
--ink: #edf7f3;
--muted: #a9c0bd;
--panel: rgba(16, 38, 43, 0.94);
--panel-2: rgba(28, 57, 62, 0.82);
--line: rgba(190, 225, 218, 0.16);
--mint: #7de0b1;
--yellow: #ffe179;
--red: #ff8178;
--blue: #79c9df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aecbd0;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
transform: translate(-50%, -100%);
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.28);
border-radius: 9px;
background: rgba(19, 43, 48, 0.87);
box-shadow: 0 5px 18px rgba(8, 24, 29, 0.22);
color: white;
white-space: nowrap;
backdrop-filter: blur(5px);
transition:
border-color 160ms ease,
background 160ms ease,
opacity 160ms ease;
}
.node-label {
min-width: 116px;
text-align: center;
}
.node-label.reachable {
border-color: var(--mint);
background: rgba(19, 58, 48, 0.92);
}
.node-label.blocked {
border-color: var(--red);
background: rgba(72, 31, 31, 0.92);
}
.node-label.idle {
opacity: 0.78;
}
.channel-label {
padding: 5px 8px;
border-color: rgba(255, 225, 121, 0.48);
background: rgba(26, 48, 52, 0.84);
font-size: 11px;
}
.label-title {
display: block;
font-size: 12px;
font-weight: 760;
letter-spacing: 0.01em;
}
.channel-label .label-title {
color: var(--yellow);
font-size: 11px;
}
.label-kind,
.label-sub {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 600;
}
.channel-label .label-sub {
color: #d4e5df;
}
.brand {
position: fixed;
z-index: 5;
top: 18px;
left: 18px;
max-width: min(570px, calc(100vw - 430px));
padding: 13px 16px 12px;
border: 1px solid rgba(255, 255, 255, 0.24);
border-radius: 14px;
background: rgba(15, 39, 44, 0.84);
box-shadow: 0 12px 40px rgba(9, 30, 35, 0.2);
backdrop-filter: blur(9px);
pointer-events: none;
}
.brand h1 {
margin: 0;
font-size: clamp(20px, 2.4vw, 31px);
line-height: 1;
letter-spacing: -0.035em;
}
.brand p {
margin: 7px 0 0;
color: #c5d9d4;
font-size: 12px;
}
.warning {
display: inline-block;
margin-top: 9px;
padding: 5px 8px;
border-radius: 6px;
background: #f5cf68;
color: #29332c;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.065em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
right: 18px;
width: 390px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(8, 24, 29, 0.3);
backdrop-filter: blur(12px);
scrollbar-width: thin;
scrollbar-color: #527278 transparent;
}
.panel h2 {
margin: 0 0 12px;
font-size: 16px;
letter-spacing: -0.015em;
}
.control {
margin-bottom: 13px;
}
.control label,
.control-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 6px;
color: #d9e9e5;
font-size: 12px;
font-weight: 750;
}
select {
width: 100%;
height: 39px;
padding: 0 34px 0 10px;
border: 1px solid rgba(190, 225, 218, 0.24);
border-radius: 9px;
outline: none;
background: #21464c;
color: white;
font-size: 12px;
}
select:focus {
border-color: var(--mint);
box-shadow: 0 0 0 2px rgba(125, 224, 177, 0.15);
}
input[type="range"] {
width: 100%;
accent-color: var(--mint);
}
.control-note {
margin-top: 4px;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.preset-note {
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel-2);
color: #c7dcda;
font-size: 10.5px;
line-height: 1.45;
}
.status {
margin: 13px 0;
padding: 11px 12px;
border: 1px solid;
border-radius: 11px;
font-size: 11.5px;
line-height: 1.45;
}
.status.complete {
border-color: rgba(125, 224, 177, 0.5);
background: rgba(54, 125, 91, 0.22);
}
.status.blocked {
border-color: rgba(255, 129, 120, 0.55);
background: rgba(143, 49, 45, 0.24);
}
.status strong {
display: block;
margin-bottom: 2px;
font-size: 13px;
}
.summary-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-width: 0;
padding: 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(30, 59, 64, 0.72);
}
.metric.access {
grid-column: 1 / -1;
}
.metric-title {
margin-bottom: 6px;
color: var(--muted);
font-size: 9.5px;
font-weight: 850;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.big-value {
display: block;
overflow-wrap: anywhere;
font-size: 22px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.metric-line {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 7px;
color: #c7dcda;
font-size: 10.5px;
}
.metric-line strong {
color: white;
font-weight: 720;
text-align: right;
}
.landing-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
margin-top: 8px;
}
.landing-item {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
padding: 6px 7px;
border-radius: 7px;
background: rgba(10, 29, 33, 0.25);
color: #c8dcda;
font-size: 10px;
}
.landing-item span:last-child {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.dot {
width: 7px;
height: 7px;
flex: 0 0 7px;
border-radius: 50%;
background: #71888a;
}
.dot.good {
background: var(--mint);
box-shadow: 0 0 7px rgba(125, 224, 177, 0.6);
}
.dot.bad {
background: var(--red);
}
details {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
summary {
cursor: pointer;
color: #d8e9e5;
font-size: 12px;
font-weight: 780;
}
.table-wrap {
margin-top: 9px;
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 9.5px;
line-height: 1.35;
}
th,
td {
padding: 7px 5px;
border-bottom: 1px solid rgba(190, 225, 218, 0.1);
text-align: left;
vertical-align: top;
}
th {
color: var(--muted);
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
td {
color: #d1e2df;
}
.pass {
color: var(--mint);
font-weight: 750;
}
.fail {
color: var(--red);
font-weight: 750;
}
.muted {
color: #8fa6a5;
}
.fine-print {
margin: 11px 0 0;
color: #91aaa8;
font-size: 9.5px;
line-height: 1.5;
}
.scene-controls {
position: fixed;
z-index: 6;
bottom: 18px;
left: 18px;
display: flex;
gap: 6px;
}
.scene-controls button {
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 10px;
background: rgba(18, 43, 48, 0.88);
color: white;
cursor: pointer;
box-shadow: 0 7px 20px rgba(8, 24, 29, 0.18);
}
.scene-controls button:hover {
background: rgba(32, 74, 80, 0.96);
}
.camera-hint {
position: fixed;
z-index: 5;
bottom: 20px;
left: 157px;
padding: 8px 10px;
border-radius: 8px;
background: rgba(18, 43, 48, 0.74);
color: #d5e6e2;
font-size: 10px;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
max-width: calc(100vw - 20px);
padding: 10px 12px;
}
.brand h1 {
font-size: 21px;
}
.brand p {
display: none;
}
.warning {
margin-top: 7px;
font-size: 8.5px;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 53vh;
padding: 13px;
}
.scene-controls {
bottom: calc(53vh + 20px);
left: 10px;
}
.camera-hint {
display: none;
}
.summary-grid {
grid-template-columns: 1fr 1fr;
}
.scene-label {
transform: translate(-50%, -100%) scale(0.86);
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly branching river and landing scene"></div>
<div id="labels" aria-hidden="true"></div>
<header class="brand">
<h1>Branchwater</h1>
<p>River-market route planning sandbox</p>
<div class="warning">Simplified teaching model — not real navigation guidance</div>
</header>
<aside class="panel" aria-label="Route planning controls and results">
<h2>Plan a boat route</h2>
<div class="control">
<label for="routeSelect">Route</label>
<select id="routeSelect"></select>
</div>
<div class="control">
<label for="presetSelect">
Water-condition preset
</label>
<select id="presetSelect">
<option value="normal">Normal summer level</option>
<option value="high">High water</option>
<option value="low">Low water</option>
</select>
<div id="presetNote" class="preset-note"></div>
</div>
<div class="control">
<label for="draftRange">
Boat draft
<output id="draftOutput" for="draftRange">0.65 m</output>
</label>
<input id="draftRange" type="range" min="0.35" max="1.30" step="0.05" value="0.65">
<div id="draftNote" class="control-note"></div>
</div>
<div id="statusBox" class="status complete" role="status" aria-live="polite"></div>
<div class="summary-grid">
<section class="metric">
<div class="metric-title">Travel time</div>
<strong id="travelTime" class="big-value">—</strong>
<div id="travelCaption" class="metric-line"></div>
<div class="metric-line">
<span>Full-route time</span>
<strong id="fullRouteTime">—</strong>
</div>
</section>
<section class="metric">
<div class="metric-title">Route distance</div>
<strong id="plannedDistance" class="big-value">—</strong>
<div class="metric-line">
<span>Reachable</span>
<strong id="reachableDistance">—</strong>
</div>
<div class="metric-line">
<span>Remaining</span>
<strong id="remainingDistance">—</strong>
</div>
</section>
<section class="metric">
<div class="metric-title">Current effects</div>
<strong id="currentDelta" class="big-value">—</strong>
<div class="metric-line">
<span>Without current</span>
<strong id="neutralTime">—</strong>
</div>
<div class="metric-line">
<span>Route mix</span>
<strong id="currentMix">—</strong>
</div>
</section>
<section class="metric access">
<div class="metric-title">Landing access</div>
<div id="landingList" class="landing-list"></div>
</section>
</div>
<details open>
<summary>Selected route by channel</summary>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Channel</th>
<th>Modeled depth</th>
<th>Current vs route</th>
<th>Result</th>
</tr>
</thead>
<tbody id="routeTable"></tbody>
</table>
</div>
</details>
<details>
<summary>All channel assumptions</summary>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Channel</th>
<th>Nominal depth</th>
<th>Prescribed current</th>
<th>Speed</th>
</tr>
</thead>
<tbody>
<tr>
<td>North Run</td>
<td>1.80 m</td>
<td>Upper → Market</td>
<td>0.25 m/s</td>
</tr>
<tr>
<td>Reed Channel</td>
<td>1.20 m</td>
<td>Market → Reed</td>
<td>0.40 m/s</td>
</tr>
<tr>
<td>Market Cut</td>
<td>1.00 m</td>
<td>Market → Sheds</td>
<td>0.35 m/s</td>
</tr>
<tr>
<td>South Link</td>
<td>0.90 m</td>
<td>Reed → Sheds</td>
<td>0.30 m/s</td>
</tr>
</tbody>
</table>
</div>
<p class="fine-print">
Nominal depths are schematic values. The selected water preset adds a simple
depth offset to every channel. A boat may enter a channel only when modeled
depth is at least the boat draft plus 0.10 m clearance.
</p>
</details>
<p class="fine-print">
Distances use a schematic scale of 12 m per scene unit. Still-water boat speed
is 1.70 m/s. Travel time includes the signed effect of the prescribed current.
No wind, waves, obstacles, bank effects, or weather forecasts are modeled.
</p>
</aside>
<div class="scene-controls" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="resetCamera" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
<div class="camera-hint">Drag: orbit · Shift-drag: pan · Scroll: zoom</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);
// -------------------------------------------------------------------------
// Model data
// -------------------------------------------------------------------------
const METERS_PER_UNIT = 12;
const BOAT_SPEED = 1.70; // m/s in still water
const REQUIRED_CLEARANCE = 0.10; // m
const presets = {
normal: {
name: "Normal summer level",
depthOffset: 0,
currentFactor: 1,
note:
"Nominal channel depths; current speed ×1.00. Still-water speed remains 1.70 m/s."
},
high: {
name: "High water",
depthOffset: 0.30,
currentFactor: 1.15,
note:
"Modeled depth +0.30 m; current speed ×1.15. Still-water speed remains 1.70 m/s."
},
low: {
name: "Low water",
depthOffset: -0.30,
currentFactor: 0.80,
note:
"Modeled depth −0.30 m; current speed ×0.80. Still-water speed remains 1.70 m/s."
}
};
const nodes = {
upper: {
id: "upper",
name: "Upper Landing",
short: "Upper",
kind: "Boat sheds",
pos: new THREE.Vector3(-7, 0, -5),
dock: new THREE.Vector3(-0.15, 0, 0.48)
},
market: {
id: "market",
name: "Market Landing",
short: "Market",
kind: "Market",
pos: new THREE.Vector3(-1, 0, 0),
dock: new THREE.Vector3(-0.15, 0, -0.65)
},
reed: {
id: "reed",
name: "Reed Homes",
short: "Reed",
kind: "Homes",
pos: new THREE.Vector3(6, 0, -4),
dock: new THREE.Vector3(-0.25, 0, -0.62)
},
shed: {
id: "shed",
name: "Shed Landing",
short: "Sheds",
kind: "Storage",
pos: new THREE.Vector3(6, 0, 5),
dock: new THREE.Vector3(-0.3, 0, 0.68)
}
};
const edges = {
north: {
id: "north",
name: "North Run",
from: "upper",
to: "market",
depth: 1.80,
currentFrom: "upper",
currentTo: "market",
currentSpeed: 0.25,
path: [
new THREE.Vector3(-7, 0, -5),
new THREE.Vector3(-5.45, 0, -4.15),
new THREE.Vector3(-3.65, 0, -2.72),
new THREE.Vector3(-1, 0, 0)
]
},
reed: {
id: "reed",
name: "Reed Channel",
from: "market",
to: "reed",
depth: 1.20,
currentFrom: "market",
currentTo: "reed",
currentSpeed: 0.40,
path: [
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(1.15, 0, -0.65),
new THREE.Vector3(3.4, 0, -2.2),
new THREE.Vector3(6, 0, -4)
]
},
market: {
id: "market",
name: "Market Cut",
from: "market",
to: "shed",
depth: 1.00,
currentFrom: "market",
currentTo: "shed",
currentSpeed: 0.35,
path: [
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(1.35, 0, 1.1),
new THREE.Vector3(3.75, 0, 3.15),
new THREE.Vector3(6, 0, 5)
]
},
south: {
id: "south",
name: "South Link",
from: "reed",
to: "shed",
depth: 0.90,
currentFrom: "reed",
currentTo: "shed",
currentSpeed: 0.30,
path: [
new THREE.Vector3(6, 0, -4),
new THREE.Vector3(7.35, 0, -1.35),
new THREE.Vector3(7.7, 0, 2.7),
new THREE.Vector3(6, 0, 5)
]
}
};
const adjacency = Object.fromEntries(
Object.keys(nodes).map((id) => [id, []])
);
for (const edge of Object.values(edges)) {
adjacency[edge.from].push({ to: edge.to, edgeId: edge.id });
adjacency[edge.to].push({ to: edge.from, edgeId: edge.id });
}
function findSimplePaths(start, goal) {
const results = [];
function walk(current, nodePath, edgePath) {
if (current === goal) {
results.push({
nodes: [...nodePath],
edges: [...edgePath]
});
return;
}
for (const link of adjacency[current]) {
if (nodePath.includes(link.to)) continue;
nodePath.push(link.to);
edgePath.push(link.edgeId);
walk(link.to, nodePath, edgePath);
edgePath.pop();
nodePath.pop();
}
}
walk(start, [start], []);
return results;
}
const routes = [];
const nodeIds = Object.keys(nodes);
for (let i = 0; i < nodeIds.length; i++) {
for (let j = i + 1; j < nodeIds.length; j++) {
const paths = findSimplePaths(nodeIds[i], nodeIds[j]);
paths.forEach((path, pathIndex) => {
routes.push({
id: `${nodeIds[i]}-${nodeIds[j]}-${pathIndex}`,
nodes: path.nodes,
edges: path.edges,
label: path.nodes.map((id) => nodes[id].short).join(" → ")
});
});
}
}
routes.sort((a, b) => {
const aStart = nodeIds.indexOf(a.nodes[0]);
const bStart = nodeIds.indexOf(b.nodes[0]);
if (aStart !== bStart) return aStart - bStart;
const aEnd = nodeIds.indexOf(a.nodes.at(-1));
const bEnd = nodeIds.indexOf(b.nodes.at(-1));
if (aEnd !== bEnd) return aEnd - bEnd;
return a.edges.length - b.edges.length;
});
for (const route of routes) {
const option = document.createElement("option");
option.value = route.id;
option.textContent = route.label;
$("routeSelect").appendChild(option);
}
const defaultRoute = routes.find(
(route) =>
route.nodes.join(",") === "upper,market,reed,shed"
);
if (defaultRoute) $("routeSelect").value = defaultRoute.id;
// -------------------------------------------------------------------------
// Renderer, camera, and direct camera controls
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaecbd0);
scene.fog = new THREE.Fog(0xaecbd0, 25, 48);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"Branchwater river route scene. Drag to orbit, shift-drag to pan, and scroll to zoom."
);
$("scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe8f7f3, 0x6d684c, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc4, 3.0);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
scene.add(sun);
const cameraState = {
theta: 0.72,
phi: 0.86,
radius: 22,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.cos(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.sin(theta)
);
camera.lookAt(target);
}
updateCamera();
function resetCamera() {
cameraState.theta = 0.72;
cameraState.phi = 0.86;
cameraState.radius = 22;
cameraState.target.set(0, 0, 0);
updateCamera();
}
let dragging = false;
let panning = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, new THREE.Vector3(0, 1, 0))
.normalize();
const scale = cameraState.radius * 0.0017;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-6,
6
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-5,
5
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.35,
1.36
);
}
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
panning = false;
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"contextmenu",
(event) => event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
12,
36
);
updateCamera();
},
{ passive: false }
);
$("zoomIn").addEventListener("click", () => {
cameraState.radius = Math.max(12, cameraState.radius - 2);
updateCamera();
});
$("zoomOut").addEventListener("click", () => {
cameraState.radius = Math.min(36, cameraState.radius + 2);
updateCamera();
});
$("resetCamera").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function makeRibbon(path, width, y, material) {
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i < path.length; i++) {
const previous = path[Math.max(0, i - 1)];
const next = path[Math.min(path.length - 1, i + 1)];
const tangent = next.clone().sub(previous).normalize();
const normal = new THREE.Vector3(-tangent.z, 0, tangent.x);
const p = path[i];
const left = p.clone().addScaledVector(normal, width / 2);
const right = p.clone().addScaledVector(normal, -width / 2);
positions.push(left.x, y, left.z, right.x, y, right.z);
uvs.push(0, i / (path.length - 1), 1, i / (path.length - 1));
if (i < path.length - 1) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, a, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
return mesh;
}
function pathLength(path) {
let length = 0;
for (let i = 1; i < path.length; i++) {
length += path[i].distanceTo(path[i - 1]);
}
return length;
}
function pointOnPath(path, t) {
const lengths = [];
let total = 0;
for (let i = 1; i < path.length; i++) {
const length = path[i].distanceTo(path[i - 1]);
lengths.push(length);
total += length;
}
let distance = THREE.MathUtils.clamp(t, 0, 1) * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
const fraction = lengths[i] === 0 ? 0 : distance / lengths[i];
return {
point: path[i].clone().lerp(path[i + 1], fraction),
direction: path[i + 1].clone().sub(path[i]).normalize()
};
}
distance -= lengths[i];
}
return {
point: path.at(-1).clone(),
direction: path.at(-1).clone().sub(path.at(-2)).normalize()
};
}
function distanceToSegment(x, z, a, b) {
const abx = b.x - a.x;
const abz = b.z - a.z;
const apx = x - a.x;
const apz = z - a.z;
const lengthSquared = abx * abx + abz * abz;
const t =
lengthSquared === 0
? 0
: THREE.MathUtils.clamp(
(apx * abx + apz * abz) / lengthSquared,
0,
1
);
const dx = x - (a.x + abx * t);
const dz = z - (a.z + abz * t);
return Math.hypot(dx, dz);
}
// -------------------------------------------------------------------------
// Low-poly terrain, rivers, and scenery
// -------------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xb8b27e,
roughness: 1,
flatShading: true,
vertexColors: true
});
const terrainGeometry = new THREE.PlaneGeometry(25, 20, 16, 12);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPositions = terrainGeometry.attributes.position;
const terrainColors = [];
let seed = 94721;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const colorA = new THREE.Color(0xa9ad78);
const colorB = new THREE.Color(0xc5bb86);
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
terrainPositions.setY(i, -0.22 + random() * 0.13);
const color = colorA.clone().lerp(colorB, random() * 0.8);
terrainColors.push(color.r, color.g, color.b);
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(terrainGeometry, groundMaterial);
terrain.receiveShadow = true;
scene.add(terrain);
const underlay = new THREE.Mesh(
new THREE.BoxGeometry(25.4, 0.55, 20.4),
new THREE.MeshStandardMaterial({
color: 0x766d50,
roughness: 1
})
);
underlay.position.y = -0.55;
underlay.receiveShadow = true;
scene.add(underlay);
const bankMaterial = new THREE.MeshStandardMaterial({
color: 0xc1ad78,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x3f91aa,
roughness: 0.38,
metalness: 0.02,
flatShading: true,
side: THREE.DoubleSide
});
for (const edge of Object.values(edges)) {
scene.add(makeRibbon(edge.path, 1.72, -0.035, bankMaterial));
scene.add(makeRibbon(edge.path, 1.08, 0.035, waterMaterial));
}
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.1, z);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.14, 0.8, 5),
new THREE.MeshStandardMaterial({
color: 0x745438,
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.4;
trunk.castShadow = true;
group.add(trunk);
const foliage = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.25, 6),
new THREE.MeshStandardMaterial({
color: random() > 0.5 ? 0x477a54 : 0x5e8a58,
roughness: 1,
flatShading: true
})
);
foliage.position.y = 1.25;
foliage.castShadow = true;
group.add(foliage);
group.scale.setScalar(scale);
scene.add(group);
}
function nearWaterOrLanding(x, z) {
for (const edge of Object.values(edges)) {
for (let i = 1; i < edge.path.length; i++) {
if (
distanceToSegment(
x,
z,
edge.path[i - 1],
edge.path[i]
) < 1.15
) {
return true;
}
}
}
return Object.values(nodes).some(
(node) => Math.hypot(x - node.pos.x, z - node.pos.z) < 1.45
);
}
let treeCount = 0;
for (let attempt = 0; attempt < 180 && treeCount < 34; attempt++) {
const x = -11.6 + random() * 23.2;
const z = -8.8 + random() * 17.6;
if (nearWaterOrLanding(x, z)) continue;
makeTree(x, z, 0.75 + random() * 0.5);
treeCount++;
}
for (let i = 0; i < 18; i++) {
const x = -11.5 + random() * 23;
const z = -8.5 + random() * 17;
if (nearWaterOrLanding(x, z)) continue;
const rock = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.16 + random() * 0.18, 0),
new THREE.MeshStandardMaterial({
color: 0x8b8d7b,
roughness: 1,
flatShading: true
})
);
rock.position.set(x, -0.12, z);
rock.scale.y = 0.65;
rock.castShadow = true;
scene.add(rock);
}
// -------------------------------------------------------------------------
// Landing buildings and docks
// -------------------------------------------------------------------------
function makeHouse(x, z, wallColor, roofColor, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.13, z);
group.scale.setScalar(scale);
const wall = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 1.0, 1.0),
new THREE.MeshStandardMaterial({
color: wallColor,
roughness: 0.95,
flatShading: true
})
);
wall.position.y = 0.5;
wall.castShadow = true;
wall.receiveShadow = true;
group.add(wall);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(0.84, 0.58, 4),
new THREE.MeshStandardMaterial({
color: roofColor,
roughness: 0.9,
flatShading: true
})
);
roof.position.y = 1.28;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.55, 0.035),
new THREE.MeshStandardMaterial({ color: 0x4d4937 })
);
door.position.set(0, 0.28, 0.52);
group.add(door);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xf1d786,
emissive: 0x5e4d1c,
emissiveIntensity: 0.18
});
const window = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.25, 0.035),
windowMaterial
);
window.position.set(-0.32, 0.66, 0.52);
group.add(window);
scene.add(group);
}
function makeShed(x, z, wallColor, roofColor, scale = 1) {
const group = new THREE.Group();
group.position.set(x, -0.13, z);
group.scale.setScalar(scale);
const wall = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.85, 1.05),
new THREE.MeshStandardMaterial({
color: wallColor,
roughness: 1,
flatShading: true
})
);
wall.position.y = 0.425;
wall.castShadow = true;
group.add(wall);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(1.62, 0.12, 1.18),
new THREE.MeshStandardMaterial({
color: roofColor,
roughness: 1,
flatShading: true
})
);
roof.position.y = 0.91;
roof.rotation.z = -0.08;
roof.castShadow = true;
group.add(roof);
const door = new THREE.Mesh(
new THREE.BoxGeometry(0.55, 0.58, 0.035),
new THREE.MeshStandardMaterial({ color: 0x3e3c31 })
);
door.position.set(0, 0.3, 0.54);
group.add(door);
scene.add(group);
}
function makeMarketStall(x, z, color) {
const group = new THREE.Group();
group.position.set(x, -0.13, z);
const poleMaterial = new THREE.MeshStandardMaterial({
color: 0x6b5036,
roughness: 1
});
for (const px of [-0.52, 0.52]) {
for (const pz of [-0.36, 0.36]) {
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 1.15, 5),
poleMaterial
);
pole.position.set(px, 0.575, pz);
pole.castShadow = true;
group.add(pole);
}
}
const canopy = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.11, 0.93),
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
flatShading: true
})
);
canopy.position.y = 1.18;
canopy.castShadow = true;
group.add(canopy);
for (let i = 0; i < 4; i++) {
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.115, 0.94),
new THREE.MeshStandardMaterial({
color: 0xf3e6c6,
roughness: 1
})
);
stripe.position.set(-0.47 + i * 0.31, 1.19, 0);
group.add(stripe);
}
const table = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.16, 0.66),
new THREE.MeshStandardMaterial({
color: 0x9a7045,
roughness: 1
})
);
table.position.y = 0.66;
table.castShadow = true;
group.add(table);
const produceColors = [0xe9973f, 0x8caf4e, 0xd65442];
for (let i = 0; i < 3; i++) {
const produce = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.13, 0),
new THREE.MeshStandardMaterial({
color: produceColors[i],
roughness: 1,
flatShading: true
})
);
produce.position.set(-0.32 + i * 0.32, 0.83, 0);
group.add(produce);
}
scene.add(group);
}
function makeDock(node) {
const group = new THREE.Group();
group.position.copy(node.pos).add(node.dock);
const plankMaterial = new THREE.MeshStandardMaterial({
color: 0x8b6844,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 5; i++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.12, 0.15),
plankMaterial
);
plank.position.set(0, 0.13, -0.34 + i * 0.17);
plank.castShadow = true;
group.add(plank);
}
const postMaterial = new THREE.MeshStandardMaterial({
color: 0x5b4935,
roughness: 1
});
for (const px of [-0.58, 0.58]) {
for (const pz of [-0.31, 0.31]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.075, 0.72, 5),
postMaterial
);
post.position.set(px, 0.03, pz);
post.castShadow = true;
group.add(post);
}
}
scene.add(group);
}
for (const node of Object.values(nodes)) makeDock(node);
// Upper Landing: storage and repair sheds.
makeShed(-8.45, -4.45, 0x8a7558, 0x53665d, 0.92);
makeShed(-7.85, -6.15, 0x9b8562, 0x58675d, 0.72);
// Market Landing: three stalls and crates.
makeMarketStall(-2.1, -1.55, 0xc85f4a);
makeMarketStall(-0.55, -1.55, 0x477d6c);
makeMarketStall(1.0, -1.55, 0xd29a3f);
const crateMaterial = new THREE.MeshStandardMaterial({
color: 0x9b7144,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 4; i++) {
const crate = new THREE.Mesh(
new THREE.BoxGeometry(0.35, 0.35, 0.35),
crateMaterial
);
crate.position.set(-2.3 + (i % 2) * 0.42, 0.08, -2.25);
crate.rotation.y = i * 0.25;
crate.castShadow = true;
scene.add(crate);
}
// Reed Homes: two homes.
makeHouse(4.55, -5.35, 0xd8b77c, 0x8b493d, 0.9);
makeHouse(6.65, -5.65, 0xc8d0a1, 0x4d6b69, 0.82);
// Shed Landing: storage sheds.
makeShed(4.55, 5.55, 0xa6865f, 0x596760, 0.95);
makeShed(4.05, 6.65, 0x8d7c5f, 0x4b5f5b, 0.72);
// -------------------------------------------------------------------------
// Current arrows and route overlays
// -------------------------------------------------------------------------
function makeHorizontalArrow(edge, t) {
const sample = pointOnPath(edge.path, t);
const currentDirection =
edge.currentFrom === nodes[edge.from].id
? sample.direction
: sample.direction.clone().negate();
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xffed91,
transparent: true,
opacity: 0.96
});
const group = new THREE.Group();
group.position.copy(sample.point);
group.position.y = 0.19;
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.045, 0.52, 5),
arrowMaterial
);
shaft.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
currentDirection
);
shaft.position.copy(currentDirection).multiplyScalar(0.26);
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.33, 5),
arrowMaterial
);
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
currentDirection
);
head.position.copy(currentDirection).multiplyScalar(0.66);
group.add(head);
edge.arrowMaterial = arrowMaterial;
scene.add(group);
}
for (const edge of Object.values(edges)) {
makeHorizontalArrow(edge, 0.34);
makeHorizontalArrow(edge, 0.73);
}
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeBaseMaterial = new THREE.MeshBasicMaterial({
color: 0xe8f5ef,
transparent: true,
opacity: 0.23,
depthWrite: false
});
const routePassMaterial = new THREE.MeshBasicMaterial({
color: 0xffe179,
transparent: true,
opacity: 0.98,
depthWrite: false
});
const routeBlockMaterial = new THREE.MeshBasicMaterial({
color: 0xff5f59,
transparent: true,
opacity: 0.96,
depthWrite: false
});
function clearRouteGroup() {
while (routeGroup.children.length) {
const child = routeGroup.children.pop();
child.geometry?.dispose();
}
}
const stopMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.3, 0.075, 6, 18),
new THREE.MeshBasicMaterial({ color: 0xff625b })
);
stopMarker.rotation.x = Math.PI / 2;
stopMarker.visible = false;
scene.add(stopMarker);
// -------------------------------------------------------------------------
// Boat
// -------------------------------------------------------------------------
const boat = new THREE.Group();
const hull = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.24, 0.82),
new THREE.MeshStandardMaterial({
color: 0xe18b3d,
roughness: 0.7,
flatShading: true
})
);
hull.position.y = 0.1;
hull.castShadow = true;
boat.add(hull);
const bow = new THREE.Mesh(
new THREE.ConeGeometry(0.32, 0.55, 4),
new THREE.MeshStandardMaterial({
color: 0xe18b3d,
roughness: 0.7,
flatShading: true
})
);
bow.rotation.x = -Math.PI / 2;
bow.position.set(0, 0.1, -0.56);
bow.castShadow = true;
boat.add(bow);
const seat = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.1, 0.25),
new THREE.MeshStandardMaterial({
color: 0x6a4a32,
roughness: 1
})
);
seat.position.set(0, 0.27, 0.08);
boat.add(seat);
const personBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.14, 0.42, 6),
new THREE.MeshStandardMaterial({
color: 0x376d73,
roughness: 1,
flatShading: true
})
);
personBody.position.set(0, 0.5, 0.1);
personBody.castShadow = true;
boat.add(personBody);
const personHead = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 0),
new THREE.MeshStandardMaterial({
color: 0xd9aa76,
roughness: 1,
flatShading: true
})
);
personHead.position.set(0, 0.81, 0.1);
boat.add(personHead);
scene.add(boat);
// -------------------------------------------------------------------------
// HTML scene labels
// -------------------------------------------------------------------------
const labelRecords = [];
function createLabel(position, className, html) {
const element = document.createElement("div");
element.className = className;
element.innerHTML = html;
$("labels").appendChild(element);
const record = {
element,
position: position.clone()
};
labelRecords.push(record);
return record;
}
const nodeLabels = {};
for (const node of Object.values(nodes)) {
nodeLabels[node.id] = createLabel(
node.pos.clone().add(new THREE.Vector3(0, 1.6, 0)),
"scene-label node-label idle",
`<span class="label-title">${node.name}</span><span class="label-kind">${node.kind}</span>`
);
}
const channelLabels = {};
for (const edge of Object.values(edges)) {
const sample = pointOnPath(edge.path, 0.54);
channelLabels[edge.id] = createLabel(
sample.point.clone().add(new THREE.Vector3(0, 0.45, 0)),
"scene-label channel-label",
""
);
}
function updateProjectedLabels() {
for (const record of labelRecords) {
const projected = record.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
record.element.style.display = visible ? "block" : "none";
if (!visible) continue;
record.element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
record.element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
// -------------------------------------------------------------------------
// Route calculations and presentation
// -------------------------------------------------------------------------
function formatTime(seconds) {
if (!Number.isFinite(seconds)) return "—";
const rounded = Math.max(0, Math.round(seconds));
if (rounded < 60) return `${rounded} s`;
const minutes = Math.floor(rounded / 60);
const remainder = String(rounded % 60).padStart(2, "0");
return `${minutes}m ${remainder}s`;
}
function signedTime(seconds) {
if (Math.abs(seconds) < 0.5) return "0 s";
return `${seconds < 0 ? "−" : "+"}${Math.abs(Math.round(seconds))} s`;
}
function currentLabel(edge) {
return `${nodes[edge.currentFrom].short} → ${nodes[edge.currentTo].short}`;
}
function routeCurrentDescription(edge, travelFrom, travelTo) {
const favorable =
travelFrom === edge.currentFrom && travelTo === edge.currentTo;
const speed = (
edge.currentSpeed * presets[$("presetSelect").value].currentFactor
).toFixed(2);
return `${currentLabel(edge)} · ${favorable ? "favorable" : "adverse"} ${speed} m/s`;
}
function updateModel() {
const route = routes.find(
(candidate) => candidate.id === $("routeSelect").value
);
const preset = presets[$("presetSelect").value];
const draft = Number($("draftRange").value);
const requiredDepth = draft + REQUIRED_CLEARANCE;
$("draftOutput").textContent = `${draft.toFixed(2)} m`;
$("draftNote").textContent =
`Required modeled depth = ${draft.toFixed(2)} m draft + ` +
`${REQUIRED_CLEARANCE.toFixed(2)} m clearance = ` +
`${requiredDepth.toFixed(2)} m.`;
$("presetNote").textContent = preset.note;
if (preset.id === undefined) {
const colors = {
normal: 0x3f91aa,
high: 0x3f94ad,
low: 0x658d91
};
waterMaterial.color.set(
colors[$("presetSelect").value] ?? 0x3f91aa
);
}
let plannedDistance = 0;
let reachableDistance = 0;
let actualTime = 0;
let neutralTime = 0;
let currentDelta = 0;
let favorableCount = 0;
let adverseCount = 0;
let blocked = null;
const reachable = [route.nodes[0]];
const rowStates = [];
const traversedEdges = [];
route.edges.forEach((edgeId, index) => {
const edge = edges[edgeId];
const distance = pathLength(edge.path) * METERS_PER_UNIT;
const effectiveDepth = edge.depth + preset.depthOffset;
const travelFrom = route.nodes[index];
const travelTo = route.nodes[index + 1];
const favorable =
travelFrom === edge.currentFrom && travelTo === edge.currentTo;
const signedCurrent =
edge.currentSpeed * preset.currentFactor * (favorable ? 1 : -1);
const effectiveSpeed = Math.max(0.25, BOAT_SPEED + signedCurrent);
const channelActualTime = distance / effectiveSpeed;
const channelNeutralTime = distance / BOAT_SPEED;
plannedDistance += distance;
if (blocked) {
rowStates.push({
edge,
effectiveDepth,
status: "not-assessed",
favorable,
distance,
channelActualTime,
channelNeutralTime
});
return;
}
if (effectiveDepth + 1e-9 < requiredDepth) {
blocked = {
edge,
effectiveDepth,
requiredDepth,
atNode: travelFrom
};
rowStates.push({
edge,
effectiveDepth,
status: "blocked",
favorable,
distance,
channelActualTime,
channelNeutralTime
});
return;
}
reachable.push(travelTo);
traversedEdges.push(edge);
reachableDistance += distance;
actualTime += channelActualTime;
neutralTime += channelNeutralTime;
currentDelta += channelActualTime - channelNeutralTime;
if (favorable) favorableCount++;
else adverseCount++;
rowStates.push({
edge,
effectiveDepth,
status: "pass",
favorable,
distance,
channelActualTime,
channelNeutralTime
});
});
const remainingDistance = plannedDistance - reachableDistance;
const complete = !blocked;
// Main results.
$("travelTime").textContent = formatTime(actualTime);
$("travelCaption").innerHTML = complete
? `<span>Complete route</span><strong>${route.label}</strong>`
: `<span>To last reachable landing</span><strong>${
nodes[reachable.at(-1)].name
}</strong>`;
$("fullRouteTime").textContent = complete
? formatTime(actualTime)
: "Unavailable — depth stop";
$("plannedDistance").textContent = `${Math.round(plannedDistance)} m`;
$("reachableDistance").textContent = `${Math.round(
reachableDistance
)} m`;
$("remainingDistance").textContent = `${Math.round(
remainingDistance
)} m`;
$("neutralTime").textContent = formatTime(neutralTime);
$("currentDelta").textContent = signedTime(currentDelta);
$("currentDelta").style.color =
currentDelta < -0.5
? "var(--mint)"
: currentDelta > 0.5
? "var(--red)"
: "var(--ink)";
const mixParts = [];
if (favorableCount) mixParts.push(`${favorableCount} favorable`);
if (adverseCount) mixParts.push(`${adverseCount} adverse`);
$("currentMix").textContent = mixParts.length
? mixParts.join(", ")
: "No traveled channel";
const statusBox = $("statusBox");
statusBox.className = `status ${complete ? "complete" : "blocked"}`;
if (complete) {
statusBox.innerHTML =
`<strong>Route complete</strong>` +
`All ${route.nodes.length} landings on this route are reachable. ` +
`Travel time is ${formatTime(actualTime)} under the selected assumptions.`;
} else {
statusBox.innerHTML =
`<strong>Stopped before ${blocked.edge.name}</strong>` +
`Modeled depth is ${blocked.effectiveDepth.toFixed(
2
)} m, below the required ${blocked.requiredDepth.toFixed(
2
)} m. The boat stops at ${nodes[blocked.atNode].name}. ` +
`Travel time shown is only for the reachable portion.`;
}
// Landing access, deliberately separate from distance and current.
const routeNodeSet = new Set(route.nodes);
const reachableSet = new Set(reachable);
$("landingList").innerHTML = Object.values(nodes)
.map((node) => {
const onRoute = routeNodeSet.has(node.id);
const isReachable = reachableSet.has(node.id);
const stateClass = !onRoute
? ""
: isReachable
? "good"
: "bad";
const stateText = !onRoute
? "Not on route"
: isReachable
? "Reachable"
: "Not reached";
return `
<div class="landing-item">
<span class="dot ${stateClass}"></span>
<span title="${node.name}: ${stateText}">${node.name} · ${stateText}</span>
</div>
`;
})
.join("");
// Selected route table.
$("routeTable").innerHTML = rowStates
.map((row) => {
const depthText =
`${row.effectiveDepth.toFixed(2)} m modeled<br>` +
`<span class="muted">${row.edge.depth.toFixed(
2
)} m nominal / ${requiredDepth.toFixed(2)} m needed</span>`;
const currentText = routeCurrentDescription(
row.edge,
row.status === "not-assessed"
? route.nodes[rowStates.indexOf(row)]
: route.nodes[rowStates.indexOf(row)],
route.nodes[rowStates.indexOf(row) + 1]
);
let outcome = "";
if (row.status === "pass") {
outcome =
`<span class="pass">Pass</span><br>` +
`${formatTime(row.channelActualTime)}`;
} else if (row.status === "blocked") {
outcome =
`<span class="fail">Depth stop</span><br>` +
`${row.effectiveDepth.toFixed(2)} < ` +
`${requiredDepth.toFixed(2)} m`;
} else {
outcome = `<span class="muted">Not assessed<br>after stop</span>`;
}
return `
<tr>
<td><strong>${row.edge.name}</strong></td>
<td>${depthText}</td>
<td>${currentText}</td>
<td>${outcome}</td>
</tr>
`;
})
.join("");
// Update the planned route line, with a red blocked channel.
clearRouteGroup();
for (const edgeId of route.edges) {
const edge = edges[edgeId];
routeGroup.add(
makeRibbon(edge.path, 0.12, 0.105, routeBaseMaterial)
);
}
for (const row of rowStates) {
if (row.status === "pass") {
routeGroup.add(
makeRibbon(row.edge.path, 0.09, 0.13, routePassMaterial)
);
} else if (row.status === "blocked") {
routeGroup.add(
makeRibbon(row.edge.path, 0.10, 0.14, routeBlockMaterial)
);
}
}
// Highlight current arrows belonging to the selected route.
const selectedEdgeIds = new Set(route.edges);
for (const edge of Object.values(edges)) {
edge.arrowMaterial.color.set(
selectedEdgeIds.has(edge.id) ? 0xffd35b : 0xf6f1c3
);
edge.arrowMaterial.opacity = selectedEdgeIds.has(edge.id)
? 1
: 0.55;
}
// Place the boat at the last reachable point.
let boatPosition;
let boatDirection;
if (traversedEdges.length) {
const lastEdge = traversedEdges.at(-1);
boatPosition = lastEdge.path.at(-1).clone();
boatDirection = lastEdge.path
.at(-1)
.clone()
.sub(lastEdge.path.at(-2))
.normalize();
} else {
boatPosition = nodes[route.nodes[0]].pos.clone();
boatDirection = edges[route.edges[0]].path[1]
.clone()
.sub(edges[route.edges[0]].path[0])
.normalize();
}
boat.position.set(boatPosition.x, 0.23, boatPosition.z);
boat.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, -1),
boatDirection
);
stopMarker.visible = !complete;
if (blocked) {
stopMarker.position.copy(nodes[blocked.atNode].pos);
stopMarker.position.y = 0.19;
}
// Update 3D landing label states.
for (const node of Object.values(nodes)) {
const label = nodeLabels[node.id];
label.element.classList.remove("reachable", "blocked", "idle");
if (!routeNodeSet.has(node.id)) {
label.element.classList.add("idle");
} else if (reachableSet.has(node.id)) {
label.element.classList.add("reachable");
} else {
label.element.classList.add("blocked");
}
}
// Update channel depth labels for the selected water preset.
for (const edge of Object.values(edges)) {
const effectiveDepth = edge.depth + preset.depthOffset;
channelLabels[edge.id].element.innerHTML =
`<span class="label-title">${edge.name}</span>` +
`<span class="label-sub">` +
`${effectiveDepth.toFixed(2)} m modeled · ${currentLabel(edge)}` +
`</span>`;
}
}
// -------------------------------------------------------------------------
// Interaction
// -------------------------------------------------------------------------
$("routeSelect").addEventListener("change", updateModel);
$("presetSelect").addEventListener("change", () => {
const colorByPreset = {
normal: 0x3f91aa,
high: 0x3f94ad,
low: 0x658d91
};
waterMaterial.color.set(
colorByPreset[$("presetSelect").value] ?? 0x3f91aa
);
updateModel();
});
$("draftRange").addEventListener("input", updateModel);
updateModel();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
boat.position.y = 0.23 + Math.sin(time * 2.2) * 0.035;
if (stopMarker.visible) {
const pulse = 1 + Math.sin(time * 4.2) * 0.12;
stopMarker.scale.setScalar(pulse);
}
updateProjectedLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```