Prompt specification
Build or customize the Three.js 3D scene "Missing-stopover network experiment" 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: Missing-stopover network experiment
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/missing-stopover-network-experiment-x0660
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring bird migration stopovers. Create a schematic migration network where users remove one resource node; compare remaining reachable paths using a toy travel budget without claiming actual species migration predictions. Low-poly.
Working Three.js Starter (missing-stopover-network-experiment-x0660):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Stopover Atlas — Schematic Migration Network</title>
<style>
:root {
--ink: #233638;
--muted: #64706d;
--paper: #f5f0e4;
--panel: rgba(250, 247, 238, 0.94);
--line: rgba(35, 54, 56, 0.14);
--teal: #177f78;
--orange: #d76c3e;
--red: #b64c45;
--wetland: #4ca6a1;
--grass: #91a95c;
--fruit: #b46f55;
--water: #5e8fc4;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #dfe7e3;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 20px;
left: 24px;
right: 374px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.brand {
max-width: 430px;
padding: 14px 16px 13px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 16px;
background: rgba(248, 244, 233, 0.83);
box-shadow: 0 12px 35px rgba(38, 52, 49, 0.08);
backdrop-filter: blur(12px);
}
.eyebrow {
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 2px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 40px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 13px;
}
.disclaimer {
max-width: 340px;
padding: 11px 13px;
border: 1px solid rgba(182, 76, 69, 0.19);
border-radius: 13px;
background: rgba(255, 247, 235, 0.88);
color: #735a4f;
font-size: 11px;
line-height: 1.45;
backdrop-filter: blur(12px);
}
.disclaimer strong {
display: block;
margin-bottom: 2px;
color: var(--red);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
right: 18px;
bottom: 18px;
width: 338px;
overflow: auto;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(38, 52, 49, 0.16);
backdrop-filter: blur(18px);
scrollbar-width: thin;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 16px;
}
.panel h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
letter-spacing: -0.02em;
}
.state-pill {
padding: 5px 8px;
border-radius: 999px;
background: rgba(23, 127, 120, 0.1);
color: var(--teal);
font-size: 10px;
font-weight: 750;
white-space: nowrap;
}
.state-pill.removed {
background: rgba(182, 76, 69, 0.1);
color: var(--red);
}
.section {
padding: 15px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type {
border-top: 0;
padding-top: 0;
}
.section-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.section-title h3 {
margin: 0;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.helper {
margin: 8px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.budget-value {
color: var(--teal);
font-size: 12px;
font-weight: 800;
}
input[type="range"] {
width: 100%;
accent-color: var(--teal);
cursor: pointer;
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: #89918e;
font-size: 10px;
}
.compare-grid {
display: grid;
gap: 9px;
}
.route-card {
min-height: 112px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.42);
}
.route-card.after {
border-color: rgba(215, 108, 62, 0.24);
}
.route-card-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 8px;
}
.route-card-title strong {
font-size: 11px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.route-card.baseline .route-card-title strong {
color: var(--teal);
}
.route-card.after .route-card-title strong {
color: var(--orange);
}
.badge {
padding: 3px 6px;
border-radius: 999px;
background: rgba(23, 127, 120, 0.1);
color: var(--teal);
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.badge.over {
background: rgba(182, 76, 69, 0.1);
color: var(--red);
}
.route-cost {
display: flex;
align-items: baseline;
gap: 5px;
margin-bottom: 5px;
}
.route-cost b {
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 500;
line-height: 1;
}
.route-cost span {
color: var(--muted);
font-size: 10px;
}
.route-path {
color: #4c5957;
font-size: 11px;
line-height: 1.55;
}
.route-meta {
margin-top: 8px;
color: #78817e;
font-size: 10px;
line-height: 1.4;
}
.empty-route {
display: grid;
min-height: 88px;
place-items: center;
padding: 10px;
border: 1px dashed rgba(35, 54, 56, 0.16);
border-radius: 10px;
color: #818986;
font-size: 11px;
text-align: center;
}
.delta-strip {
margin-top: 9px;
padding: 10px 11px;
border-radius: 10px;
background: #e8eee8;
color: #52605c;
font-size: 11px;
line-height: 1.45;
}
.delta-strip b {
color: var(--ink);
}
label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
select {
width: 100%;
padding: 10px 11px;
border: 1px solid rgba(35, 54, 56, 0.18);
border-radius: 10px;
outline: none;
background: rgba(255, 255, 255, 0.68);
color: var(--ink);
font-size: 12px;
}
select:focus,
button:focus-visible,
input:focus-visible {
outline: 2px solid rgba(23, 127, 120, 0.45);
outline-offset: 2px;
}
.selected-meta {
margin: 10px 0;
padding: 11px;
border-radius: 10px;
background: rgba(35, 54, 56, 0.055);
color: #586360;
font-size: 11px;
line-height: 1.55;
}
.selected-meta b {
color: var(--ink);
}
.connection-list {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 8px;
}
.connection {
padding: 4px 6px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.64);
color: #5e6966;
font-size: 9px;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
padding: 10px 11px;
border: 1px solid transparent;
border-radius: 10px;
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition:
transform 120ms ease,
opacity 120ms ease,
background 120ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
}
button:disabled {
cursor: not-allowed;
opacity: 0.42;
}
.primary {
background: var(--teal);
color: white;
}
.secondary {
border-color: rgba(35, 54, 56, 0.15);
background: rgba(255, 255, 255, 0.48);
color: var(--ink);
}
.full {
width: 100%;
margin-top: 8px;
}
.legend {
position: fixed;
z-index: 5;
left: 24px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 11px 15px;
max-width: min(670px, calc(100vw - 390px));
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.46);
border-radius: 13px;
background: rgba(248, 244, 233, 0.84);
box-shadow: 0 10px 28px rgba(38, 52, 49, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #596562;
font-size: 10px;
white-space: nowrap;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.65);
}
.line-key {
width: 18px;
height: 3px;
border-radius: 2px;
background: var(--dot);
}
.instructions {
position: fixed;
z-index: 4;
right: 374px;
bottom: 24px;
padding: 7px 10px;
border-radius: 999px;
background: rgba(248, 244, 233, 0.72);
color: #687370;
font-size: 10px;
pointer-events: none;
}
@media (max-width: 900px) {
.topbar {
right: 20px;
}
.disclaimer {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 48vh;
border-radius: 17px;
}
.legend {
right: 10px;
bottom: calc(48vh + 20px);
max-width: calc(100vw - 20px);
}
.instructions {
display: none;
}
.brand {
padding: 10px 12px;
}
.brand p {
display: none;
}
}
@media (max-width: 520px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
}
h1 {
font-size: 26px;
}
.eyebrow {
font-size: 8px;
}
.legend {
gap: 8px 10px;
}
.legend-item {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive low-poly migration stopover network"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Field study / interactive schematic</div>
<h1>Stopover Atlas</h1>
<p>A schematic network of migration resources and travel trade-offs.</p>
</div>
<div class="disclaimer">
<strong>Toy model only</strong>
Resource categories and edge costs are illustrative. This scene does not
represent actual routes or make species migration predictions.
</div>
</header>
<aside class="panel" aria-label="Network controls and route comparison">
<div class="panel-heading">
<h2>Network lab</h2>
<span id="statePill" class="state-pill">All stopovers active</span>
</div>
<section class="section">
<div class="section-title">
<h3>Toy travel budget</h3>
<span id="budgetValue" class="budget-value">58 toy units</span>
</div>
<input
id="budget"
type="range"
min="45"
max="85"
step="1"
value="58"
aria-label="Toy travel budget"
/>
<div class="range-scale">
<span>45</span>
<span>85</span>
</div>
<p class="helper">
Edge costs are invented “toy units,” not distance, time, or an empirical
measure of bird movement.
</p>
</section>
<section class="section">
<div class="section-title">
<h3>Compare paths</h3>
<span class="helper" style="margin: 0">shortest route</span>
</div>
<div class="compare-grid">
<div id="baselineCard" class="route-card baseline"></div>
<div id="afterCard" class="route-card after"></div>
</div>
<div id="comparisonDelta" class="delta-strip" aria-live="polite"></div>
</section>
<section class="section">
<div class="section-title">
<h3>Resource node</h3>
<span class="helper" style="margin: 0">select in scene or menu</span>
</div>
<label for="nodeSelect">Stopover to inspect</label>
<select id="nodeSelect"></select>
<div id="selectedMeta" class="selected-meta"></div>
<div class="button-row">
<button id="removeButton" class="primary" type="button">
Remove this stopover
</button>
<button id="restoreButton" class="secondary" type="button" disabled>
Restore network
</button>
</div>
<button id="resetScenario" class="secondary full" type="button">
Reset scenario
</button>
<button id="resetView" class="secondary full" type="button">
Reset camera
</button>
</section>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="dot" style="--dot:#4ca6a1"></span>Wetland</div>
<div class="legend-item"><span class="dot" style="--dot:#91a95c"></span>Grass / grain</div>
<div class="legend-item"><span class="dot" style="--dot:#b46f55"></span>Fruit / scrub</div>
<div class="legend-item"><span class="dot" style="--dot:#5e8fc4"></span>Freshwater</div>
<div class="legend-item"><span class="line-key" style="--dot:#177f78"></span>Baseline path</div>
<div class="legend-item"><span class="line-key" style="--dot:#d76c3e"></span>Remaining path</div>
</div>
<div class="instructions">
Drag to orbit · Shift-drag to pan · Scroll to zoom · Click a node
</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 viewport = $("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe7e3);
scene.fog = new THREE.Fog(0xdfe7e3, 22, 43);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const palette = {
baseline: 0x177f78,
after: 0xd76c3e,
removed: 0xb64c45,
edge: 0x71817b,
wetland: 0x4ca6a1,
grass: 0x91a95c,
fruit: 0xb46f55,
water: 0x5e8fc4,
anchor: 0x2e4848
};
let budget = 58;
let removedId = null;
let selectedId = "n2";
const nodeDefinitions = [
{
id: "n0",
name: "North staging",
short: "North staging",
type: "anchor",
role: "Fixed origin",
x: -8.6,
z: -5.5
},
{
id: "n1",
name: "Reedbed wetland",
short: "Reedbeds",
type: "wetland",
role: "Sheltering wetland resource",
x: -6.8,
z: -1.7
},
{
id: "n2",
name: "Grain margin",
short: "Grain margin",
type: "grass",
role: "Seed and open-grassland resource",
x: -3.5,
z: -5.0
},
{
id: "n3",
name: "River delta",
short: "River delta",
type: "wetland",
role: "Shallow-water and reed resource",
x: -0.6,
z: -1.0
},
{
id: "n4",
name: "Bramble belt",
short: "Bramble belt",
type: "fruit",
role: "Fruit and scrub resource",
x: -1.7,
z: 4.1
},
{
id: "n5",
name: "Freshwater fen",
short: "Freshwater fen",
type: "water",
role: "Freshwater-edge resource",
x: 3.2,
z: 1.6
},
{
id: "n6",
name: "Tidal saltmarsh",
short: "Saltmarsh",
type: "wetland",
role: "Intertidal feeding resource",
x: 5.8,
z: -4.6
},
{
id: "n7",
name: "Mountain pass",
short: "Mountain pass",
type: "fruit",
role: "Sheltered scrub and fruit resource",
x: 7.0,
z: 4.6
},
{
id: "n8",
name: "Wintering flats",
short: "Winter flats",
type: "anchor",
role: "Fixed destination",
x: 9.2,
z: -0.1
}
];
const nodeById = new Map(nodeDefinitions.map((node) => [node.id, node]));
const edgeDefinitions = [
["n0", "n1", 13],
["n0", "n2", 11],
["n1", "n2", 10],
["n1", "n3", 17],
["n2", "n3", 13],
["n2", "n4", 15],
["n3", "n5", 11],
["n3", "n6", 15],
["n4", "n5", 14],
["n4", "n7", 17],
["n5", "n7", 12],
["n5", "n8", 19],
["n6", "n8", 17],
["n7", "n8", 14]
];
const edges = [];
const edgeLookup = new Map();
const adjacency = new Map(nodeDefinitions.map((node) => [node.id, []]));
const edgeKey = (a, b) => [a, b].sort().join("--");
// ---------------------------------------------------------------------
// Lighting and low-poly terrain
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff8e8, 0x64766d, 2.15));
const sun = new THREE.DirectionalLight(0xfff1cf, 3.0);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.0007;
scene.add(sun);
const hills = [
{ x: -7.5, z: 5.8, r: 2.6, a: 0.72 },
{ x: 8.4, z: 6.3, r: 3.2, a: 0.92 },
{ x: 1.8, z: -6.2, r: 2.1, a: 0.43 }
];
function terrainHeight(x, z) {
let h =
0.13 +
Math.sin(x * 0.58) * 0.11 +
Math.cos(z * 0.73) * 0.1 +
Math.sin((x + z) * 0.31) * 0.08;
for (const hill of hills) {
const dx = x - hill.x;
const dz = z - hill.z;
h += hill.a * Math.exp(-(dx * dx + dz * dz) / (hill.r * hill.r));
}
return h;
}
const water = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x9fb9b7,
roughness: 0.96,
metalness: 0
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.86;
water.receiveShadow = true;
scene.add(water);
const base = new THREE.Mesh(
new THREE.BoxGeometry(23.6, 0.72, 16.6),
new THREE.MeshStandardMaterial({
color: 0xa99f83,
roughness: 1,
flatShading: true
})
);
base.position.y = -0.5;
base.receiveShadow = true;
scene.add(base);
const terrainGeometry = new THREE.PlaneGeometry(23, 16, 18, 14);
const terrainPositions = terrainGeometry.attributes.position;
const terrainColors = [];
const lowColor = new THREE.Color(0xd7cfab);
const highColor = new THREE.Color(0x91a67e);
const tempColor = new THREE.Color();
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const localY = terrainPositions.getY(i);
const worldZ = -localY;
const h = terrainHeight(x, worldZ);
terrainPositions.setZ(i, h);
const t = THREE.MathUtils.clamp((h + 0.08) / 1.15, 0, 1);
tempColor.copy(lowColor).lerp(highColor, t);
tempColor.offsetHSL(0, 0, (Math.sin(i * 17.73) * 0.018));
terrainColors.push(tempColor.r, tempColor.g, tempColor.b);
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
terrainGeometry.rotateX(-Math.PI / 2);
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
terrain.receiveShadow = true;
terrain.castShadow = true;
scene.add(terrain);
const rim = new THREE.LineSegments(
new THREE.EdgesGeometry(base.geometry),
new THREE.LineBasicMaterial({
color: 0x766f60,
transparent: true,
opacity: 0.5
})
);
rim.position.copy(base.position);
scene.add(rim);
// ---------------------------------------------------------------------
// Nodes and labels
// ---------------------------------------------------------------------
const nodeGroup = new THREE.Group();
scene.add(nodeGroup);
const hitTargets = [];
const nodeVisuals = new Map();
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function createLabel(text, isAnchor) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = isAnchor
? "rgba(35, 54, 56, 0.93)"
: "rgba(250, 247, 238, 0.91)";
roundedRect(ctx, 5, 8, 502, 78, 18);
ctx.fill();
ctx.strokeStyle = isAnchor
? "rgba(255,255,255,0.22)"
: "rgba(35,54,56,0.16)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = isAnchor ? "#fffaf0" : "#2c4141";
ctx.font = "700 29px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 48);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.55, 0.48, 1);
sprite.renderOrder = 8;
return sprite;
}
function materialFor(color) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
flatShading: true
});
}
function createNode(node) {
const group = new THREE.Group();
group.position.set(node.x, terrainHeight(node.x, node.z) + 0.06, node.z);
node.pos = group.position.clone();
const isAnchor = node.type === "anchor";
const color = palette[node.type];
const baseMaterial = materialFor(isAnchor ? 0xd8d1b9 : 0xb8ad8f);
const baseMesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.5, 0.55, 0.09, 8),
baseMaterial
);
baseMesh.position.y = 0.035;
baseMesh.castShadow = true;
baseMesh.receiveShadow = true;
group.add(baseMesh);
const visualMeshes = [baseMesh];
function addMesh(geometry, meshColor, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, materialFor(meshColor));
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.baseColor = meshColor;
group.add(mesh);
visualMeshes.push(mesh);
return mesh;
}
if (node.type === "wetland") {
addMesh(new THREE.CylinderGeometry(0.32, 0.42, 0.28, 6), color, [0, 0.25, 0]);
addMesh(new THREE.ConeGeometry(0.055, 0.48, 4), 0x6c7e48, [-0.15, 0.48, 0.03]);
addMesh(new THREE.ConeGeometry(0.055, 0.42, 4), 0x7f8f53, [0.1, 0.45, 0.08]);
addMesh(new THREE.ConeGeometry(0.05, 0.36, 4), 0x657a45, [0.18, 0.4, -0.09]);
} else if (node.type === "grass") {
addMesh(new THREE.ConeGeometry(0.36, 0.58, 5), color, [0, 0.38, 0]);
addMesh(new THREE.CylinderGeometry(0.22, 0.28, 0.12, 7), 0xc1b56a, [0, 0.32, 0]);
} else if (node.type === "fruit") {
addMesh(new THREE.DodecahedronGeometry(0.38, 0), color, [0, 0.42, 0]);
addMesh(new THREE.IcosahedronGeometry(0.11, 0), 0xd38b57, [0.18, 0.5, 0.1]);
addMesh(new THREE.IcosahedronGeometry(0.1, 0), 0xc77a4e, [-0.16, 0.48, -0.08]);
} else if (node.type === "water") {
addMesh(new THREE.OctahedronGeometry(0.42, 0), color, [0, 0.43, 0]);
addMesh(new THREE.CylinderGeometry(0.23, 0.31, 0.12, 7), 0xa9c9d3, [0, 0.25, 0]);
} else {
addMesh(new THREE.OctahedronGeometry(0.46, 0), color, [0, 0.48, 0]);
addMesh(
new THREE.TorusGeometry(0.43, 0.055, 5, 16),
0x78908b,
[0, 0.47, 0]
).rotation.x = Math.PI / 2;
}
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.66, 0.035, 5, 28),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.9
})
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.position.y = 0.12;
selectionRing.visible = false;
group.add(selectionRing);
const label = createLabel(node.short, isAnchor);
label.position.set(0, 1.15, 0);
group.add(label);
const hit = new THREE.Mesh(
new THREE.SphereGeometry(0.72, 8, 6),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
})
);
hit.position.y = 0.35;
hit.userData.nodeId = node.id;
group.add(hit);
hitTargets.push(hit);
nodeGroup.add(group);
nodeVisuals.set(node.id, {
group,
visualMeshes,
selectionRing,
label,
originalScale: group.scale.clone()
});
}
nodeDefinitions.forEach(createNode);
// ---------------------------------------------------------------------
// Network edges
// ---------------------------------------------------------------------
const edgeGroup = new THREE.Group();
scene.add(edgeGroup);
function makeEdgeCurve(a, b, yOffset = 0) {
const start = nodeById.get(a).pos.clone();
const end = nodeById.get(b).pos.clone();
start.y += 0.27 + yOffset;
end.y += 0.27 + yOffset;
const distance = Math.hypot(end.x - start.x, end.z - start.z);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
midpoint.y += 0.22 + Math.min(1.0, distance * 0.055) + yOffset;
return new THREE.QuadraticBezierCurve3(start, midpoint, end);
}
for (const [a, b, cost] of edgeDefinitions) {
const curve = makeEdgeCurve(a, b);
const geometry = new THREE.TubeGeometry(curve, 28, 0.034, 5, false);
const material = new THREE.MeshBasicMaterial({
color: palette.edge,
transparent: true,
opacity: 0.43
});
const mesh = new THREE.Mesh(geometry, material);
edgeGroup.add(mesh);
const edge = { a, b, cost, curve, mesh };
edges.push(edge);
edgeLookup.set(edgeKey(a, b), edge);
adjacency.get(a).push({ to: b, cost });
adjacency.get(b).push({ to: a, cost });
}
// ---------------------------------------------------------------------
// Small low-poly scenery
// ---------------------------------------------------------------------
const sceneryGroup = new THREE.Group();
scene.add(sceneryGroup);
let randomSeed = 1937;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function tooCloseToNetwork(x, z) {
return nodeDefinitions.some(
(node) => Math.hypot(node.x - x, node.z - z) < 1.15
);
}
for (let i = 0; i < 48; i++) {
const x = -11 + random() * 22;
const z = -7.2 + random() * 14.4;
if (tooCloseToNetwork(x, z)) continue;
if (Math.abs(x) < 7 && Math.abs(z) < 5 && random() < 0.64) continue;
const tree = new THREE.Group();
tree.position.set(x, terrainHeight(x, z), z);
tree.rotation.y = random() * Math.PI;
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.055, 0.35, 5),
materialFor(0x776049)
);
trunk.position.y = 0.17;
tree.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.25 + random() * 0.12, 0.65 + random() * 0.35, 5),
materialFor(random() > 0.5 ? 0x718863 : 0x89976c)
);
crown.position.y = 0.67;
crown.castShadow = true;
tree.add(crown);
tree.scale.setScalar(0.65 + random() * 0.5);
sceneryGroup.add(tree);
}
for (let i = 0; i < 25; i++) {
const x = -11 + random() * 22;
const z = -7.2 + random() * 14.4;
if (tooCloseToNetwork(x, z)) continue;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.12 + random() * 0.18, 0),
materialFor(0xa39d89)
);
rock.position.set(x, terrainHeight(x, z) + 0.08, z);
rock.scale.y = 0.55 + random() * 0.35;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
sceneryGroup.add(rock);
}
// ---------------------------------------------------------------------
// Graph calculations
// ---------------------------------------------------------------------
function enumeratePaths(blockedNodeId) {
const results = [];
const origin = "n0";
const destination = "n8";
function walk(current, visited, pathNodes, pathEdges, cost) {
if (current === destination) {
results.push({
nodes: [...pathNodes],
edges: [...pathEdges],
cost
});
return;
}
for (const connection of adjacency.get(current)) {
if (blockedNodeId && connection.to === blockedNodeId) continue;
if (visited.has(connection.to)) continue;
visited.add(connection.to);
pathNodes.push(connection.to);
pathEdges.push(edgeKey(current, connection.to));
walk(
connection.to,
visited,
pathNodes,
pathEdges,
cost + connection.cost
);
pathEdges.pop();
pathNodes.pop();
visited.delete(connection.to);
}
}
walk(origin, new Set([origin]), [origin], [], 0);
return results.sort(
(a, b) => a.cost - b.cost || a.nodes.length - b.nodes.length
);
}
function pathEdgesFor(path, yOffset = 0) {
return path.edges.map((key) => {
const edge = edgeLookup.get(key);
return makeEdgeCurve(edge.a, edge.b, yOffset);
});
}
function routeSampler(path, yOffset = 0) {
const segments = pathEdgesFor(path, yOffset).map((curve) => ({
curve,
length: curve.getLength()
}));
const total = segments.reduce((sum, segment) => sum + segment.length, 0);
return {
total,
at(distance) {
let remaining = ((distance % total) + total) % total;
for (const segment of segments) {
if (remaining <= segment.length || segment === segments.at(-1)) {
const u = THREE.MathUtils.clamp(
remaining / segment.length,
0,
1
);
return {
point: segment.curve.getPointAt(u),
tangent: segment.curve.getTangentAt(u)
};
}
remaining -= segment.length;
}
}
};
}
// ---------------------------------------------------------------------
// Route rendering and animated birds
// ---------------------------------------------------------------------
const baselineRouteGroup = new THREE.Group();
const afterRouteGroup = new THREE.Group();
const removedEdgeGroup = new THREE.Group();
const baselineFlockGroup = new THREE.Group();
const afterFlockGroup = new THREE.Group();
scene.add(
baselineRouteGroup,
afterRouteGroup,
removedEdgeGroup,
baselineFlockGroup,
afterFlockGroup
);
function clearGroup(group) {
const geometries = new Set();
const materials = new Set();
group.traverse((object) => {
if (object.geometry) geometries.add(object.geometry);
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => materials.add(material));
} else {
materials.add(object.material);
}
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
group.clear();
}
function addSolidPath(group, path, color, radius, yOffset) {
for (const curve of pathEdgesFor(path, yOffset)) {
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 30, radius, 6, false),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95
})
);
group.add(mesh);
}
}
function addDashedPath(group, path, color, yOffset) {
for (const curve of pathEdgesFor(path, yOffset)) {
const points = curve.getPoints(48);
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
dashSize: 0.28,
gapSize: 0.18,
transparent: true,
opacity: 0.95
})
);
line.computeLineDistances();
group.add(line);
}
}
function addRemovedEdges() {
clearGroup(removedEdgeGroup);
if (!removedId) return;
for (const edge of edges) {
if (edge.a !== removedId && edge.b !== removedId) continue;
const curve = makeEdgeCurve(edge.a, edge.b, 0.015);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(48)),
new THREE.LineDashedMaterial({
color: palette.removed,
dashSize: 0.18,
gapSize: 0.14,
transparent: true,
opacity: 0.65
})
);
line.computeLineDistances();
removedEdgeGroup.add(line);
}
}
function createBird(color) {
const bird = new THREE.Group();
const body = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.31, 4),
new THREE.MeshBasicMaterial({ color })
);
body.rotation.x = Math.PI / 2;
bird.add(body);
const rightGeometry = new THREE.BufferGeometry();
rightGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.04, 0, 0.04,
0.43, 0, -0.06,
0.11, 0, 0.15
],
3
)
);
rightGeometry.computeVertexNormals();
const leftGeometry = new THREE.BufferGeometry();
leftGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-0.04, 0, 0.04,
-0.43, 0, -0.06,
-0.11, 0, 0.15
],
3
)
);
leftGeometry.computeVertexNormals();
const wingMaterial = new THREE.MeshBasicMaterial({
color,
side: THREE.DoubleSide
});
const rightWing = new THREE.Mesh(rightGeometry, wingMaterial);
const leftWing = new THREE.Mesh(leftGeometry, wingMaterial);
bird.add(rightWing, leftWing);
bird.userData.rightWing = rightWing;
bird.userData.leftWing = leftWing;
return bird;
}
function createFlock(group, path, color, count, yOffset) {
clearGroup(group);
if (!path) return;
const sampler = routeSampler(path, yOffset);
const birds = [];
for (let i = 0; i < count; i++) {
const bird = createBird(color);
group.add(bird);
birds.push(bird);
}
group.userData.sampler = sampler;
group.userData.birds = birds;
group.userData.count = count;
}
function updateFlock(group, elapsed, speed) {
const sampler = group.userData.sampler;
const birds = group.userData.birds;
if (!sampler || !birds?.length) return;
birds.forEach((bird, index) => {
const phase = index / birds.length;
const distance =
((elapsed * speed + phase * sampler.total) % sampler.total);
const sample = sampler.at(distance);
bird.position.copy(sample.point);
bird.position.y += 0.18 + Math.sin(elapsed * 4 + index) * 0.025;
bird.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
bird.rotation.x = -sample.tangent.y * 0.45;
const flap = Math.sin(elapsed * 10 + index * 1.8) * 0.48;
bird.userData.rightWing.rotation.z = -flap;
bird.userData.leftWing.rotation.z = flap;
});
}
// ---------------------------------------------------------------------
// UI state
// ---------------------------------------------------------------------
function pathText(path) {
return path.nodes.map((id) => nodeById.get(id).short).join(" → ");
}
function renderRouteCard(paths, isAfter) {
if (!paths.length) {
return `
<div class="route-card-title">
<strong>${isAfter ? "After removal" : "Baseline"}</strong>
</div>
<div class="empty-route">No route remains to the wintering flats.</div>
`;
}
const shortest = paths[0];
const reachable = paths.filter((path) => path.cost <= budget);
const within = shortest.cost <= budget;
const alternative = reachable[1];
const badge = within
? '<span class="badge">Within budget</span>'
: `<span class="badge over">Over by ${shortest.cost - budget}</span>`;
const resourceStops = Math.max(0, shortest.nodes.length - 2);
return `
<div class="route-card-title">
<strong>${isAfter ? "After removal" : "Baseline"}</strong>
${badge}
</div>
<div class="route-cost">
<b>${shortest.cost}</b>
<span>toy units</span>
</div>
<div class="route-path">${pathText(shortest)}</div>
<div class="route-meta">
${resourceStops} resource stop${resourceStops === 1 ? "" : "s"} ·
${reachable.length} route combination${reachable.length === 1 ? "" : "s"} within budget
${
alternative
? `<br>Next in-budget route: ${alternative.cost} units`
: ""
}
</div>
`;
}
function updateSelectedPanel() {
const node = nodeById.get(selectedId);
if (!node) return;
const connections = adjacency.get(node.id);
const connectionMarkup = connections
.map((connection) => {
const other = nodeById.get(connection.to);
return `<span class="connection">${other.short} · ${connection.cost}</span>`;
})
.join("");
const isRemoved = removedId === node.id;
const isAnchor = node.type === "anchor";
$("selectedMeta").innerHTML = `
<b>${node.name}</b><br>
${node.role}${isRemoved ? " · <b>Removed from network</b>" : ""}
<div class="connection-list">${connectionMarkup}</div>
`;
const removeButton = $("removeButton");
removeButton.disabled = isAnchor || Boolean(removedId);
removeButton.textContent = isRemoved
? "Stopover removed"
: isAnchor
? "Anchor cannot be removed"
: "Remove this stopover";
$("restoreButton").disabled = !removedId;
}
function updateNodeVisuals() {
for (const node of nodeDefinitions) {
const visuals = nodeVisuals.get(node.id);
const isRemoved = node.id === removedId;
const isSelected = node.id === selectedId;
visuals.selectionRing.visible = isSelected;
visuals.selectionRing.material.color.set(
isRemoved ? palette.removed : 0xffffff
);
visuals.label.material.opacity = isRemoved ? 0.5 : 1;
visuals.label.scale.set(isSelected ? 2.82 : 2.55, isSelected ? 0.53 : 0.48, 1);
visuals.group.scale.copy(visuals.originalScale);
visuals.group.scale.multiplyScalar(isRemoved ? 0.72 : 1);
for (const mesh of visuals.visualMeshes) {
const baseColor = mesh.userData.baseColor;
mesh.material.color.setHex(isRemoved ? 0x968d80 : baseColor);
mesh.material.opacity = isRemoved ? 0.3 : 1;
mesh.material.transparent = isRemoved;
mesh.material.depthWrite = !isRemoved;
}
}
}
function updateScenario() {
const baselinePaths = enumeratePaths(null);
const afterPaths = removedId ? enumeratePaths(removedId) : [];
const baselineReachable = baselinePaths.filter((path) => path.cost <= budget);
const afterReachable = afterPaths.filter((path) => path.cost <= budget);
$("baselineCard").innerHTML = renderRouteCard(baselinePaths, false);
$("afterCard").innerHTML = removedId
? renderRouteCard(afterPaths, true)
: `
<div class="route-card-title">
<strong>After removal</strong>
</div>
<div class="empty-route">
Remove one resource stopover to calculate the remaining network.
</div>
`;
if (!removedId) {
$("comparisonDelta").innerHTML = `
<b>${baselineReachable.length} baseline route combinations</b> fit the
current ${budget}-unit toy budget. Select and remove a resource node
to compare what remains.
`;
} else if (!afterPaths.length) {
$("comparisonDelta").innerHTML = `
<b>Destination disconnected.</b> Removing
${nodeById.get(removedId).name} leaves no route to the wintering flats.
`;
} else {
const baselineShortest = baselinePaths[0];
const afterShortest = afterPaths[0];
const costDelta = afterShortest.cost - baselineShortest.cost;
const stopDelta =
afterShortest.nodes.length - baselineShortest.nodes.length;
const costText =
costDelta === 0
? "The shortest remaining route has the same toy cost."
: `The shortest remaining route costs ${costDelta > 0 ? "+" : ""}${costDelta} toy units.`;
const stopText =
stopDelta === 0
? ""
: ` It uses ${Math.abs(stopDelta)} ${stopDelta > 0 ? "more" : "fewer"} stop${Math.abs(stopDelta) === 1 ? "" : "s"}.`;
$("comparisonDelta").innerHTML = `
<b>${costText}</b>${stopText}
${afterReachable.length} of ${afterPaths.length} remaining route
combinations fit the ${budget}-unit budget.
`;
}
$("statePill").textContent = removedId ? "1 node removed" : "All stopovers active";
$("statePill").classList.toggle("removed", Boolean(removedId));
clearGroup(baselineRouteGroup);
clearGroup(afterRouteGroup);
const baselineShortest = baselinePaths[0];
if (baselineShortest.cost <= budget) {
addSolidPath(
baselineRouteGroup,
baselineShortest,
palette.baseline,
0.072,
0.015
);
} else {
addDashedPath(
baselineRouteGroup,
baselineShortest,
palette.baseline,
0.045
);
}
if (removedId && afterPaths.length) {
const afterShortest = afterPaths[0];
if (afterShortest.cost <= budget) {
addSolidPath(
afterRouteGroup,
afterShortest,
palette.after,
0.082,
0.075
);
} else {
addDashedPath(
afterRouteGroup,
afterShortest,
palette.after,
0.055
);
}
}
addRemovedEdges();
createFlock(
baselineFlockGroup,
baselineShortest,
palette.baseline,
7,
0.16
);
createFlock(
afterFlockGroup,
removedId && afterReachable.length ? afterReachable[0] : null,
palette.after,
7,
0.24
);
updateNodeVisuals();
updateSelectedPanel();
}
function selectNode(id) {
if (!nodeById.has(id)) return;
selectedId = id;
$("nodeSelect").value = id;
updateNodeVisuals();
updateSelectedPanel();
}
for (const node of nodeDefinitions) {
const option = document.createElement("option");
option.value = node.id;
option.textContent =
node.type === "anchor"
? `${node.name} — fixed anchor`
: `${node.name} — resource`;
$("nodeSelect").appendChild(option);
}
$("nodeSelect").value = selectedId;
$("nodeSelect").addEventListener("change", (event) => {
selectNode(event.target.value);
});
$("budget").addEventListener("input", (event) => {
budget = Number(event.target.value);
$("budgetValue").textContent = `${budget} toy units`;
updateScenario();
});
$("removeButton").addEventListener("click", () => {
const node = nodeById.get(selectedId);
if (!node || node.type === "anchor" || removedId) return;
removedId = selectedId;
updateScenario();
});
$("restoreButton").addEventListener("click", () => {
removedId = null;
updateScenario();
});
$("resetScenario").addEventListener("click", () => {
removedId = null;
budget = 58;
$("budget").value = budget;
$("budgetValue").textContent = `${budget} toy units`;
updateScenario();
});
// ---------------------------------------------------------------------
// Custom camera controls: orbit, pan and zoom
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0.1, 0.35, 0),
radius: 21.5,
yaw: 0.42,
phi: 0.76
};
const defaultCamera = {
radius: cameraState.radius,
yaw: cameraState.yaw,
phi: cameraState.phi,
target: cameraState.target.clone()
};
function resetCamera() {
cameraState.radius = defaultCamera.radius;
cameraState.yaw = defaultCamera.yaw;
cameraState.phi = defaultCamera.phi;
cameraState.target.copy(defaultCamera.target);
}
$("resetView").addEventListener("click", resetCamera);
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
const pointerState = {
down: false,
dragging: false,
button: 0,
startX: 0,
startY: 0,
previousX: 0,
previousY: 0
};
function pickNode(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const intersections = raycaster.intersectObjects(hitTargets, false);
return intersections.length ? intersections[0].object.userData.nodeId : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerState.down = true;
pointerState.dragging = false;
pointerState.button = event.button;
pointerState.startX = event.clientX;
pointerState.startY = event.clientY;
pointerState.previousX = event.clientX;
pointerState.previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState.down) {
renderer.domElement.style.cursor = pickNode(event) ? "pointer" : "grab";
return;
}
const dx = event.clientX - pointerState.previousX;
const dy = event.clientY - pointerState.previousY;
const totalDistance = Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
);
if (totalDistance > 5) pointerState.dragging = true;
const wantsPan =
pointerState.button === 2 || event.shiftKey || pointerState.button === 1;
if (wantsPan) {
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.yaw),
0,
-Math.cos(cameraState.yaw)
);
cameraState.target.addScaledVector(right, -dx * cameraState.radius * 0.0012);
cameraState.target.addScaledVector(forward, -dy * cameraState.radius * 0.0012);
} else {
cameraState.yaw -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.004,
0.28,
1.34
);
}
pointerState.previousX = event.clientX;
pointerState.previousY = event.clientY;
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
pointerState.down &&
!pointerState.dragging &&
Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
) < 6;
pointerState.down = false;
if (wasClick && event.button === 0) {
const id = pickNode(event);
if (id) selectNode(id);
}
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
pointerState.dragging = false;
});
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),
9,
31
);
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
updateFlock(baselineFlockGroup, elapsed, 0.75);
updateFlock(afterFlockGroup, elapsed + 0.35, 0.72);
renderer.render(scene, camera);
}
// Node positions must be available before edge curves are constructed.
for (const node of nodeDefinitions) {
node.pos = new THREE.Vector3(
node.x,
terrainHeight(node.x, node.z) + 0.06,
node.z
);
}
updateScenario();
updateCamera();
animate();
</script>
</body>
</html>
```