Prompt specification
Build or customize the Three.js 3D scene "Same Corridor Different Species Assumptions" 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: Same Corridor Different Species Assumptions
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/same-corridor-different-species-assumptions-x3944
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: the same corridor different species assumptions. Create a habitat network experiment applying two different source-informed movement constraints. Show that a corridor suitable under one profile may not connect the other.
Working Three.js Starter (same-corridor-different-species-assumptions-x3944):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Habitat Network — One Corridor, Two Movement Worlds</title>
<style>
:root {
--accent: #55d6be;
--accent-rgb: 85, 214, 190;
--ink: #eaf4ef;
--muted: #9aacaa;
--panel: rgba(12, 27, 31, 0.91);
--line: rgba(196, 225, 216, 0.14);
--good: #78d6a0;
--bad: #ee7b72;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #17262c;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.ui > * { pointer-events: auto; }
.intro {
position: absolute;
top: 26px;
left: 28px;
width: min(440px, calc(100vw - 430px));
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #bfd0cc;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 27px;
height: 2px;
background: var(--accent);
box-shadow: 0 0 14px rgba(var(--accent-rgb), 0.8);
}
h1 {
margin: 0;
max-width: 430px;
font-size: clamp(30px, 3.2vw, 52px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 820;
}
.intro p {
max-width: 420px;
margin: 15px 0 0;
color: #c0d0cc;
font-size: 13px;
line-height: 1.55;
}
.mismatch-pill {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 16px;
padding: 8px 11px;
border: 1px solid rgba(238, 123, 114, 0.42);
border-radius: 999px;
background: rgba(72, 27, 28, 0.55);
color: #ffc0b9;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.mismatch-pill::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #ff8177;
box-shadow: 0 0 12px #ff8177;
}
.panel {
position: absolute;
top: 18px;
right: 18px;
width: 370px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.33);
backdrop-filter: blur(20px) saturate(125%);
scrollbar-width: thin;
scrollbar-color: #415b5b transparent;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #c8d6d2;
}
.tiny-tag {
padding: 5px 7px;
border-radius: 7px;
background: rgba(var(--accent-rgb), 0.1);
color: var(--accent);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.profile-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 14px;
}
.profile-tab {
position: relative;
min-height: 66px;
padding: 11px 10px 10px 32px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.profile-tab:hover {
border-color: rgba(var(--accent-rgb), 0.5);
background: rgba(var(--accent-rgb), 0.05);
}
.profile-tab.active {
border-color: rgba(var(--accent-rgb), 0.72);
background: rgba(var(--accent-rgb), 0.1);
box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), 0.08);
}
.profile-tab::before {
content: "";
position: absolute;
left: 12px;
top: 14px;
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 10px var(--dot);
}
.profile-tab strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
}
.profile-tab span {
color: var(--muted);
font-size: 10px;
line-height: 1.25;
}
.profile-intro {
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.025);
}
.profile-title-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
}
.profile-title-row strong {
font-size: 15px;
}
.profile-title-row span {
color: var(--accent);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.source-note {
margin: 9px 0 0;
color: #afc0bd;
font-size: 11px;
line-height: 1.5;
}
.source-note b { color: #e4eeeb; }
.controls {
margin-top: 14px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
}
.section-label {
margin: 0 0 11px;
color: #91a6a3;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.slider-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 8px 12px;
margin-top: 10px;
}
.slider-row label {
color: #c8d5d2;
font-size: 11px;
}
.slider-row output {
min-width: 56px;
padding: 3px 6px;
border-radius: 6px;
background: rgba(var(--accent-rgb), 0.09);
color: var(--accent);
font-size: 10px;
font-weight: 800;
text-align: right;
}
input[type="range"] {
grid-column: 1 / -1;
width: 100%;
height: 4px;
margin: 2px 0 5px;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(
90deg,
rgba(var(--accent-rgb), 0.9) 0 var(--fill, 50%),
#304448 var(--fill, 50%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 3px solid #173035;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #173035;
border-radius: 50%;
background: var(--accent);
}
.diagnostic {
margin-top: 14px;
padding: 14px;
border: 1px solid rgba(var(--accent-rgb), 0.25);
border-radius: 13px;
background: rgba(var(--accent-rgb), 0.065);
}
.diagnostic.bad {
border-color: rgba(238, 123, 114, 0.4);
background: rgba(238, 123, 114, 0.07);
}
.status-line {
display: flex;
align-items: center;
gap: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.diagnostic.bad .status-line { color: var(--bad); }
.status-line::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.diagnostic h3 {
margin: 8px 0 5px;
font-size: 16px;
letter-spacing: -0.02em;
}
.diagnostic p {
margin: 0;
color: #aebfbc;
font-size: 11px;
line-height: 1.5;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 10px;
}
.stat {
padding: 9px 7px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.02);
text-align: center;
}
.stat strong {
display: block;
margin-bottom: 3px;
color: #eef7f3;
font-size: 15px;
}
.stat span {
color: #829794;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.edge-list {
margin-top: 14px;
}
.edge-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
padding: 10px 0;
border-top: 1px solid var(--line);
}
.edge-row:first-child { border-top: 0; }
.edge-name {
margin-bottom: 3px;
font-size: 11px;
font-weight: 800;
}
.edge-metrics {
color: #879c99;
font-size: 9px;
line-height: 1.45;
}
.edge-reason {
margin-top: 3px;
color: #dba29d;
font-size: 9px;
line-height: 1.4;
}
.edge-chip {
align-self: start;
padding: 4px 6px;
border-radius: 6px;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.edge-chip.pass {
background: rgba(120, 214, 160, 0.11);
color: var(--good);
}
.edge-chip.fail {
background: rgba(238, 123, 114, 0.11);
color: var(--bad);
}
.comparison {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.compare-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 12px;
width: 100%;
margin-top: 7px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: transparent;
text-align: left;
cursor: pointer;
}
.compare-row:hover {
border-color: rgba(255, 255, 255, 0.28);
}
.compare-row strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
}
.compare-row span {
color: #829794;
font-size: 9px;
}
.compare-result {
font-size: 9px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.compare-result.connected { color: var(--good); }
.compare-result.disconnected { color: var(--bad); }
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.action {
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: 150ms ease;
}
.action:hover {
background: rgba(var(--accent-rgb), 0.08);
border-color: rgba(var(--accent-rgb), 0.45);
}
.action.primary {
border-color: rgba(var(--accent-rgb), 0.5);
background: rgba(var(--accent-rgb), 0.12);
color: var(--accent);
}
.footnote {
margin: 12px 2px 0;
color: #708582;
font-size: 8px;
line-height: 1.5;
}
.scene-badge {
position: absolute;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
max-width: calc(100vw - 460px);
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(9, 23, 27, 0.76);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.24);
color: #c7d7d3;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
backdrop-filter: blur(12px);
}
.scene-badge::before {
content: "";
flex: 0 0 auto;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
.controls-hint {
position: absolute;
left: 28px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
color: #a6b9b5;
font-size: 10px;
}
.mouse-icon {
position: relative;
width: 17px;
height: 25px;
border: 1px solid #9eb2ae;
border-radius: 9px;
}
.mouse-icon::before {
content: "";
position: absolute;
top: 4px;
left: 7px;
width: 2px;
height: 6px;
border-radius: 2px;
background: #b8cbc6;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #17262c;
color: #c9d8d4;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#loading::before {
content: "";
position: absolute;
width: 38px;
height: 38px;
border: 2px solid rgba(255, 255, 255, 0.13);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 950px) {
.intro {
width: min(370px, calc(100vw - 390px));
}
h1 { font-size: 36px; }
.intro p { font-size: 12px; }
.panel { width: 350px; }
.scene-badge { display: none; }
}
@media (max-width: 700px) {
.intro {
top: 16px;
left: 16px;
width: calc(100vw - 32px);
}
.intro h1 {
max-width: 300px;
font-size: 31px;
}
.intro p, .mismatch-pill { display: none; }
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 49vh;
padding: 14px;
border-radius: 16px;
}
.controls-hint { display: none; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="ui">
<header class="intro">
<div class="eyebrow">Habitat network / experiment 04</div>
<h1>One corridor.<br>Two movement worlds.</h1>
<p>
The habitat patches and links never change. Only the source-informed
movement rules do. Select a species profile to test whether the same
corridor still connects the source to the target.
</p>
<div class="mismatch-pill" id="mismatchPill">
Profile mismatch · connectivity changes
</div>
</header>
<aside class="panel">
<div class="panel-heading">
<h2>Movement profile</h2>
<span class="tiny-tag">Editable assumptions</span>
</div>
<div class="profile-tabs">
<button class="profile-tab" data-profile="heat" style="--dot:#f6b94b">
<strong>Heat-runner</strong>
<span>Open-country disperser</span>
</button>
<button class="profile-tab active" data-profile="moisture" style="--dot:#55d6be">
<strong>Creek salamander</strong>
<span>Moisture-bound connector</span>
</button>
</div>
<section class="profile-intro">
<div class="profile-title-row">
<strong id="profileName">Creek salamander</strong>
<span id="profileTag">Moisture-bound</span>
</div>
<p class="source-note" id="sourceNote"></p>
</section>
<section class="controls">
<p class="section-label">Source-informed constraints</p>
<div class="slider-row">
<label for="rangeStep">Maximum crossing gap</label>
<output id="outStep">4.0 m</output>
<input id="rangeStep" type="range" min="2.5" max="7" step="0.1" value="4">
</div>
<div class="slider-row">
<label for="rangeMoisture">Minimum moisture</label>
<output id="outMoisture">55%</output>
<input id="rangeMoisture" type="range" min="0" max="1" step="0.01" value="0.55">
</div>
<div class="slider-row">
<label for="rangeCover">Minimum canopy cover</label>
<output id="outCover">50%</output>
<input id="rangeCover" type="range" min="0" max="1" step="0.01" value="0.5">
</div>
</section>
<section class="diagnostic" id="diagnostic">
<div class="status-line" id="diagnosticStatus">Network disconnected</div>
<h3 id="diagnosticTitle">No source-to-refuge path</h3>
<p id="diagnosticText"></p>
<div class="stats">
<div class="stat">
<strong id="statReach">2 / 4</strong>
<span>Reachable patches</span>
</div>
<div class="stat">
<strong id="statEdges">1 / 3</strong>
<span>Usable links</span>
</div>
<div class="stat">
<strong id="statBottleneck">Dry cut</strong>
<span>Bottleneck</span>
</div>
</div>
</section>
<section class="edge-list">
<p class="section-label">Physical corridor assessment</p>
<div id="edgeList"></div>
</section>
<section class="comparison">
<p class="section-label">Profile comparison</p>
<button class="compare-row" data-profile="heat">
<div>
<strong>Heat-runner</strong>
<span>Broad gaps · low cover tolerated</span>
</div>
<span class="compare-result connected" id="compareHeat">Connected</span>
</button>
<button class="compare-row" data-profile="moisture">
<div>
<strong>Creek salamander</strong>
<span>Short steps · wet canopy required</span>
</div>
<span class="compare-result disconnected" id="compareMoisture">Disconnected</span>
</button>
</section>
<div class="actions">
<button class="action primary" id="replayButton">Replay movement</button>
<button class="action" id="restoreButton">Restore assumptions</button>
<button class="action" id="cameraButton">Reset camera</button>
<button class="action" id="compareButton">Compare outcomes</button>
</div>
<p class="footnote">
Illustrative, editable parameters rather than field estimates. The
physical corridor geometry is identical in both trials.
</p>
</aside>
<div class="scene-badge" id="sceneBadge">
Creek salamander selected · movement trial running
</div>
<div class="controls-hint">
<span class="mouse-icon"></span>
<span>Drag to orbit · wheel to zoom · double-click to reset</span>
</div>
</div>
<div id="loading">Building habitat network</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Scene and renderer
// ---------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17262c);
scene.fog = new THREE.Fog(0x17262c, 25, 53);
const camera = new THREE.PerspectiveCamera(
43,
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.13;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9dce2, 0x334431, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6bd, 3.2);
sun.position.set(-8, 16, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
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 = 40;
sun.shadow.bias = -0.0008;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x6ccfc8, 1.05);
rim.position.set(11, 8, -12);
scene.add(rim);
// ---------------------------------------------------------------------
// Data: one physical corridor, two interpretive profiles
// ---------------------------------------------------------------------
const profiles = {
heat: {
name: "Heat-runner",
tag: "Open-country",
color: 0xf6b94b,
css: "#f6b94b",
rgb: "246, 185, 75",
maxStep: 6.5,
minMoisture: 0.15,
minCover: 0.10,
note:
"Illustrative departures from the mosaic-edge source favor short, open links and tolerate dry gaps.",
evidence: "12 outbound fixes · 72% used dry, open links"
},
moisture: {
name: "Creek salamander",
tag: "Moisture-bound",
color: 0x55d6be,
css: "#55d6be",
rgb: "85, 214, 190",
maxStep: 4.0,
minMoisture: 0.55,
minCover: 0.50,
note:
"Illustrative departures from the same source favor short steps under cover and moist substrate.",
evidence: "9 emergence points · 81% departed beneath canopy"
}
};
const nodes = [
{
id: "source",
name: "Mosaic edge",
title: "SOURCE 01",
position: new THREE.Vector3(-7.6, 0, 1.6),
radius: 2.05,
color: 0x81965a,
side: 0x536642,
subtitle: "Mixed cover · 64% moisture"
},
{
id: "bench",
name: "Wooded bench",
title: "WOODED BENCH",
position: new THREE.Vector3(-4.6, 0, 1.2),
radius: 1.55,
color: 0x4d7752,
side: 0x304f39,
subtitle: "Canopy refuge"
},
{
id: "terrace",
name: "Dry terrace",
title: "DRY TERRACE",
position: new THREE.Vector3(1.5, 0, -0.7),
radius: 1.85,
color: 0xa49b68,
side: 0x736e4b,
subtitle: "Exposed · 24% moisture"
},
{
id: "refuge",
name: "Riparian refuge",
title: "TARGET 04",
position: new THREE.Vector3(5.3, 0, -1.4),
radius: 2.1,
color: 0x438a78,
side: 0x2b6257,
subtitle: "Cool, connected habitat"
}
];
const nodeById = Object.fromEntries(nodes.map((node) => [node.id, node]));
const edges = [
{
id: "canopy-hop",
name: "Canopy hop",
from: "source",
to: "bench",
moisture: 0.78,
cover: 0.84
},
{
id: "dry-cut",
name: "Dry cut",
from: "bench",
to: "terrace",
moisture: 0.24,
cover: 0.18
},
{
id: "shaded-rill",
name: "Shaded rill",
from: "terrace",
to: "refuge",
moisture: 0.74,
cover: 0.67
}
];
edges.forEach((edge) => {
edge.length = nodeById[edge.from].position.distanceTo(
nodeById[edge.to].position
);
});
const adjacency = Object.fromEntries(nodes.map((node) => [node.id, []]));
edges.forEach((edge, index) => {
adjacency[edge.from].push({ to: edge.to, edge, index });
adjacency[edge.to].push({ to: edge.from, edge, index });
});
let selectedProfileId = "moisture";
let currentResult = null;
let edgeVisuals = new Map();
// ---------------------------------------------------------------------
// Low-poly world construction
// ---------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
function rngFactory(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6D2B79F5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const worldRandom = rngFactory(81273);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(13.0, 13.45, 0.72, 12),
standardMaterial(0x314649)
);
platform.position.y = -0.56;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const grid = new THREE.GridHelper(26, 26, 0x567171, 0x354d4e);
grid.position.y = -0.188;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
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 makeTextSprite(title, subtitle, accent = "#55d6be", scale = 3.2) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 180;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 640, 180);
roundedRect(ctx, 8, 8, 624, 164, 24);
ctx.fillStyle = "rgba(9, 24, 28, 0.86)";
ctx.fill();
ctx.strokeStyle = "rgba(210, 235, 226, 0.22)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(44, 49, 10, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#eff8f4";
ctx.font = "800 36px system-ui, sans-serif";
ctx.fillText(title, 68, 60);
ctx.fillStyle = "#a9bfba";
ctx.font = "500 25px system-ui, sans-serif";
ctx.fillText(subtitle, 32, 118);
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(scale, scale * 0.28125, 1);
sprite.renderOrder = 20;
return sprite;
}
function addTree(x, z, scale, foliageColor) {
const group = new THREE.Group();
group.position.set(x, 0.27, z);
group.rotation.y = worldRandom() * Math.PI * 2;
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.09 * scale, 0.13 * scale, 0.85 * scale, 5),
standardMaterial(0x6b513b)
);
trunk.position.y = 0.43 * scale;
trunk.castShadow = true;
group.add(trunk);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.55 * scale, 1.25 * scale, 6),
standardMaterial(foliageColor)
);
lower.position.y = 1.18 * scale;
lower.castShadow = true;
group.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.39 * scale, 0.92 * scale, 6),
standardMaterial(new THREE.Color(foliageColor).multiplyScalar(1.09))
);
upper.position.y = 1.7 * scale;
upper.castShadow = true;
group.add(upper);
scene.add(group);
}
function addRock(x, z, scale, color = 0x78807a) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
standardMaterial(color)
);
rock.position.set(x, 0.29 + scale * 0.28, z);
rock.scale.set(1, 0.7, 1.1);
rock.rotation.set(worldRandom(), worldRandom(), worldRandom());
rock.castShadow = true;
scene.add(rock);
}
function addPatch(node) {
const patch = new THREE.Mesh(
new THREE.CylinderGeometry(
node.radius,
node.radius * 1.06,
0.5,
8
),
[
standardMaterial(node.side),
standardMaterial(node.color),
standardMaterial(node.side)
]
);
patch.position.set(node.position.x, 0.02, node.position.z);
patch.rotation.y = 0.15;
patch.receiveShadow = true;
patch.castShadow = true;
scene.add(patch);
const ring = new THREE.Mesh(
new THREE.RingGeometry(node.radius * 0.62, node.radius * 0.65, 32),
new THREE.MeshBasicMaterial({
color: node.id === "source" ? 0xe4d278 :
node.id === "refuge" ? 0x69e3ca : 0xaec3a0,
transparent: true,
opacity: 0.42,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(node.position.x, 0.279, node.position.z);
scene.add(ring);
const label = makeTextSprite(
node.title,
node.subtitle,
node.id === "source" ? "#f6d978" :
node.id === "refuge" ? "#65e2c7" : "#c4d4ce",
node.id === "source" || node.id === "refuge" ? 3.35 : 3.05
);
label.position.set(node.position.x, 2.55, node.position.z);
scene.add(label);
const treeCount =
node.id === "bench" ? 9 :
node.id === "source" ? 7 :
node.id === "terrace" ? 3 : 5;
const foliage =
node.id === "terrace" ? 0x7c8552 :
node.id === "refuge" ? 0x39755e :
node.id === "bench" ? 0x315f46 : 0x5f7e45;
for (let i = 0; i < treeCount; i++) {
const angle = worldRandom() * Math.PI * 2;
const radius = node.radius * (0.55 + worldRandom() * 0.43);
addTree(
node.position.x + Math.cos(angle) * radius,
node.position.z + Math.sin(angle) * radius,
0.62 + worldRandom() * 0.46,
foliage
);
}
for (let i = 0; i < 5; i++) {
const angle = worldRandom() * Math.PI * 2;
const radius = node.radius * (0.42 + worldRandom() * 0.5);
addRock(
node.position.x + Math.cos(angle) * radius,
node.position.z + Math.sin(angle) * radius,
0.10 + worldRandom() * 0.10,
node.id === "terrace" ? 0x9a8b67 : 0x6d7973
);
}
if (node.id === "refuge") {
const pond = new THREE.Mesh(
new THREE.CircleGeometry(0.8, 9),
standardMaterial(0x4da9ba, {
roughness: 0.24,
metalness: 0.08,
transparent: true,
opacity: 0.92
})
);
pond.rotation.x = -Math.PI / 2;
pond.position.set(node.position.x + 0.1, 0.286, node.position.z + 0.05);
scene.add(pond);
for (let i = 0; i < 12; i++) {
const angle = worldRandom() * Math.PI * 2;
const radius = 0.9 + worldRandom() * 0.32;
const reed = new THREE.Mesh(
new THREE.CylinderGeometry(
0.018,
0.025,
0.35 + worldRandom() * 0.28,
5
),
standardMaterial(0x8a9f55)
);
reed.position.set(
node.position.x + 0.1 + Math.cos(angle) * radius,
0.46,
node.position.z + 0.05 + Math.sin(angle) * radius
);
reed.rotation.z = (worldRandom() - 0.5) * 0.24;
scene.add(reed);
}
}
if (node.id === "terrace") {
for (let i = 0; i < 7; i++) {
const angle = worldRandom() * Math.PI * 2;
const radius = 0.55 + worldRandom() * 0.9;
const shrub = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17 + worldRandom() * 0.09, 0),
standardMaterial(0x899253)
);
shrub.position.set(
node.position.x + Math.cos(angle) * radius,
0.39,
node.position.z + Math.sin(angle) * radius
);
shrub.scale.y = 0.65;
scene.add(shrub);
}
}
}
nodes.forEach(addPatch);
function addBarrier(edge, midpoint, angle) {
const group = new THREE.Group();
group.position.set(midpoint.x, 0.18, midpoint.z);
group.rotation.y = angle;
const material = standardMaterial(0xe76f67, {
emissive: 0x5d1717,
emissiveIntensity: 0.35
});
for (const z of [-0.52, 0.52]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.065, 0.95, 5),
material
);
post.position.set(0, 0.47, z);
post.castShadow = true;
group.add(post);
}
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.11, 1.05),
material
);
bar.position.y = 0.73;
group.add(bar);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.16, 0),
material
);
marker.position.y = 1.08;
group.add(marker);
scene.add(group);
return group;
}
function addCorridorEdge(edge) {
const from = nodeById[edge.from].position;
const to = nodeById[edge.to].position;
const dx = to.x - from.x;
const dz = to.z - from.z;
const midpoint = from.clone().add(to).multiplyScalar(0.5);
const angle = -Math.atan2(dz, dx);
const perpendicular = new THREE.Vector3(-dz, 0, dx).normalize();
const base = new THREE.Mesh(
new THREE.BoxGeometry(edge.length, 0.16, 1.03),
standardMaterial(0xb8aa7f)
);
base.position.set(midpoint.x, 0.075, midpoint.z);
base.rotation.y = angle;
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
const statusMaterial = standardMaterial(0x6b8d72, {
emissive: 0x1d3327,
emissiveIntensity: 0.2
});
const statusRibbon = new THREE.Mesh(
new THREE.BoxGeometry(edge.length * 0.94, 0.035, 0.15),
statusMaterial
);
statusRibbon.position.set(midpoint.x, 0.173, midpoint.z);
statusRibbon.rotation.y = angle;
scene.add(statusRibbon);
const pips = [];
for (const t of [0.23, 0.5, 0.77]) {
const pip = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.09, 0),
new THREE.MeshBasicMaterial({ color: 0x6b8d72 })
);
pip.position.copy(from).lerp(to, t);
pip.position.y = 0.24;
scene.add(pip);
pips.push(pip);
}
const stoneCount = Math.max(3, Math.round(edge.length * 1.15));
for (let i = 0; i < stoneCount; i++) {
const t = (i + 0.4) / stoneCount;
const side = (i % 2 === 0 ? 1 : -1) * (0.32 + worldRandom() * 0.08);
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.07 + worldRandom() * 0.055, 0),
standardMaterial(edge.id === "dry-cut" ? 0x9d8e66 : 0x78827a)
);
stone.position.copy(from).lerp(to, t).addScaledVector(perpendicular, side);
stone.position.y = 0.20;
stone.scale.y = 0.7;
stone.rotation.y = worldRandom() * Math.PI;
stone.castShadow = true;
scene.add(stone);
}
const barrier = addBarrier(edge, midpoint, angle);
const label = makeTextSprite(
edge.name.toUpperCase(),
`${edge.length.toFixed(1)} m gap · ${Math.round(edge.moisture * 100)}% wet`,
"#d8c790",
2.85
);
label.position.set(
midpoint.x + perpendicular.x * 0.62,
0.77,
midpoint.z + perpendicular.z * 0.62
);
scene.add(label);
edgeVisuals.set(edge.id, {
base,
statusMaterial,
statusRibbon,
pips,
barrier,
midpoint
});
}
edges.forEach(addCorridorEdge);
// Perimeter stones make the floating habitat platform read as a diorama.
for (let i = 0; i < 27; i++) {
const angle = worldRandom() * Math.PI * 2;
const radius = 11.1 + worldRandom() * 1.15;
addRock(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0.18 + worldRandom() * 0.25,
0x425858
);
}
const pollenGeometry = new THREE.BufferGeometry();
const pollenPositions = [];
for (let i = 0; i < 95; i++) {
pollenPositions.push(
(worldRandom() - 0.5) * 24,
0.6 + worldRandom() * 3.2,
(worldRandom() - 0.5) * 17
);
}
pollenGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(pollenPositions, 3)
);
const pollen = new THREE.Points(
pollenGeometry,
new THREE.PointsMaterial({
color: 0xdce8bd,
size: 0.055,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
scene.add(pollen);
// ---------------------------------------------------------------------
// Network logic
// ---------------------------------------------------------------------
function evaluateEdge(edge, profile) {
const reasons = [];
if (edge.length > profile.maxStep) {
reasons.push(
`${edge.length.toFixed(1)} m gap > ${profile.maxStep.toFixed(1)} m`
);
}
if (edge.moisture < profile.minMoisture) {
reasons.push(
`${Math.round(edge.moisture * 100)}% moisture < ${Math.round(profile.minMoisture * 100)}%`
);
}
if (edge.cover < profile.minCover) {
reasons.push(
`${Math.round(edge.cover * 100)}% cover < ${Math.round(profile.minCover * 100)}%`
);
}
return { pass: reasons.length === 0, reasons };
}
function computeReachability(profile) {
const assessments = new Map(
edges.map((edge) => [edge.id, evaluateEdge(edge, profile)])
);
const parent = new Map([["source", null]]);
const parentEdge = new Map();
const queue = ["source"];
while (queue.length) {
const current = queue.shift();
for (const connection of adjacency[current]) {
if (!assessments.get(connection.edge.id).pass) continue;
if (parent.has(connection.to)) continue;
parent.set(connection.to, current);
parentEdge.set(connection.to, connection.edge);
queue.push(connection.to);
}
}
const pathNodes = [];
const pathEdges = [];
if (parent.has("refuge")) {
let cursor = "refuge";
while (cursor) {
pathNodes.unshift(cursor);
const edge = parentEdge.get(cursor);
if (!edge) break;
pathEdges.unshift(edge);
cursor = parent.get(cursor);
}
}
const usableCount = [...assessments.values()]
.filter((assessment) => assessment.pass).length;
// This network is intentionally linear. The reachable prefix shows where
// an animal stops when the first incompatible link is encountered.
const prefixNodes = ["source"];
const prefixEdges = [];
let cursor = "source";
for (const edge of edges) {
if (edge.from !== cursor) break;
if (!assessments.get(edge.id).pass) break;
prefixEdges.push(edge);
prefixNodes.push(edge.to);
cursor = edge.to;
}
const failedEdge = edges.find(
(edge) => !assessments.get(edge.id).pass && edge.from === cursor
) || null;
return {
assessments,
connected: parent.has("refuge"),
reachable: parent.size,
usableCount,
pathNodes,
pathEdges,
prefixNodes,
prefixEdges,
failedEdge
};
}
// ---------------------------------------------------------------------
// Route overlays and moving organism
// ---------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
function clearGroup(group) {
while (group.children.length) {
const child = group.children[0];
group.remove(child);
if (child.geometry) child.geometry.dispose();
if (child.material) {
const materials = Array.isArray(child.material)
? child.material
: [child.material];
materials.forEach((material) => {
if (material.map) material.map.dispose();
material.dispose();
});
}
}
}
function addRouteTube(edge, color) {
const from = nodeById[edge.from].position.clone();
const to = nodeById[edge.to].position.clone();
from.y = 0.43;
to.y = 0.43;
const curve = new THREE.LineCurve3(from, to);
const geometry = new THREE.TubeGeometry(curve, 1, 0.052, 5, false);
const material = new THREE.MeshBasicMaterial({ color });
const tube = new THREE.Mesh(geometry, material);
routeGroup.add(tube);
}
function addFailedRoute(edge) {
const from = nodeById[edge.from].position.clone();
const to = nodeById[edge.to].position.clone();
from.y = 0.44;
to.y = 0.44;
const geometry = new THREE.BufferGeometry().setFromPoints([from, to]);
const material = new THREE.LineDashedMaterial({
color: 0xee7168,
dashSize: 0.24,
gapSize: 0.14,
transparent: true,
opacity: 0.95
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
routeGroup.add(line);
}
const agent = new THREE.Group();
const agentBodyMaterial = standardMaterial(profiles.moisture.color, {
emissive: profiles.moisture.color,
emissiveIntensity: 0.34,
roughness: 0.48
});
const agentBody = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.27, 0),
agentBodyMaterial
);
agentBody.castShadow = true;
agent.add(agentBody);
const agentCap = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.28, 5),
standardMaterial(0xf0f4dc)
);
agentCap.position.y = 0.25;
agentCap.rotation.z = -0.25;
agent.add(agentCap);
const agentRing = new THREE.Mesh(
new THREE.RingGeometry(0.32, 0.38, 24),
new THREE.MeshBasicMaterial({
color: profiles.moisture.color,
transparent: true,
opacity: 0.7,
side: THREE.DoubleSide
})
);
agentRing.rotation.x = -Math.PI / 2;
agentRing.position.y = -0.27;
agent.add(agentRing);
const agentLight = new THREE.PointLight(profiles.moisture.color, 0.8, 3.2);
agent.add(agentLight);
scene.add(agent);
let agentLabel = null;
let animationProgress = 0;
let animationElapsed = 0;
let animationDuration = 4;
let animationRouteEdges = [];
let animationRouteNodes = [];
function updateAgentLabel(profile) {
if (agentLabel) {
agent.remove(agentLabel);
agentLabel.material.map.dispose();
agentLabel.material.dispose();
}
agentLabel = makeTextSprite(
profile.name.toUpperCase(),
"Movement proxy",
profile.css,
2.3
);
agentLabel.position.set(0, 1.05, 0);
agent.add(agentLabel);
}
function resetAgent(result) {
const profile = profiles[selectedProfileId];
animationProgress = 0;
animationElapsed = 0;
animationRouteEdges = result.connected
? result.pathEdges
: result.prefixEdges;
animationRouteNodes = ["source"];
animationRouteEdges.forEach((edge) => {
animationRouteNodes.push(edge.to);
});
const totalLength = animationRouteEdges.reduce(
(sum, edge) => sum + edge.length,
0
);
animationDuration = result.connected
? Math.max(5.0, totalLength / 2.7)
: Math.max(3.2, totalLength / 1.1);
agentBodyMaterial.color.setHex(profile.color);
agentBodyMaterial.emissive.setHex(profile.color);
agentLight.color.setHex(profile.color);
agentRing.material.color.setHex(profile.color);
agentLabel.material.opacity = 1;
agent.position.copy(nodeById.source.position);
agent.position.y = 0.66;
agent.scale.setScalar(1);
}
function positionAgentAlongRoute(progress) {
const edgesToWalk = animationRouteEdges;
if (!edgesToWalk.length) {
agent.position.copy(nodeById.source.position);
agent.position.y = 0.66;
return;
}
const total = edgesToWalk.reduce((sum, edge) => sum + edge.length, 0);
let distance = progress * total;
for (const edge of edgesToWalk) {
if (distance <= edge.length) {
const t = distance / edge.length;
const from = nodeById[edge.from].position;
const to = nodeById[edge.to].position;
agent.position.copy(from).lerp(to, t);
agent.position.y = 0.66 + Math.sin(progress * Math.PI * 8) * 0.025;
return;
}
distance -= edge.length;
}
const last = nodeById[edgesToWalk[edgesToWalk.length - 1].to].position;
agent.position.set(last.x, 0.66, last.z);
}
// ---------------------------------------------------------------------
// UI
// ---------------------------------------------------------------------
const elements = {
profileTabs: [...document.querySelectorAll(".profile-tab")],
compareRows: [...document.querySelectorAll(".compare-row")],
profileName: document.getElementById("profileName"),
profileTag: document.getElementById("profileTag"),
sourceNote: document.getElementById("sourceNote"),
rangeStep: document.getElementById("rangeStep"),
rangeMoisture: document.getElementById("rangeMoisture"),
rangeCover: document.getElementById("rangeCover"),
outStep: document.getElementById("outStep"),
outMoisture: document.getElementById("outMoisture"),
outCover: document.getElementById("outCover"),
diagnostic: document.getElementById("diagnostic"),
diagnosticStatus: document.getElementById("diagnosticStatus"),
diagnosticTitle: document.getElementById("diagnosticTitle"),
diagnosticText: document.getElementById("diagnosticText"),
statReach: document.getElementById("statReach"),
statEdges: document.getElementById("statEdges"),
statBottleneck: document.getElementById("statBottleneck"),
edgeList: document.getElementById("edgeList"),
compareHeat: document.getElementById("compareHeat"),
compareMoisture: document.getElementById("compareMoisture"),
mismatchPill: document.getElementById("mismatchPill"),
sceneBadge: document.getElementById("sceneBadge")
};
function updateRangeFill(input) {
const percentage =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--fill", `${percentage}%`);
}
function setRangeValues(profile) {
elements.rangeStep.value = profile.maxStep;
elements.rangeMoisture.value = profile.minMoisture;
elements.rangeCover.value = profile.minCover;
[elements.rangeStep, elements.rangeMoisture, elements.rangeCover]
.forEach(updateRangeFill);
}
function updateComparison() {
const heatResult = computeReachability(profiles.heat);
const moistureResult = computeReachability(profiles.moisture);
[
[elements.compareHeat, heatResult],
[elements.compareMoisture, moistureResult]
].forEach(([element, result]) => {
element.textContent = result.connected ? "Connected" : "Disconnected";
element.className =
"compare-result " + (result.connected ? "connected" : "disconnected");
});
const mismatch = heatResult.connected !== moistureResult.connected;
elements.mismatchPill.textContent = mismatch
? "Profile mismatch · connectivity changes"
: "Profiles agree · connectivity outcome matches";
elements.mismatchPill.style.borderColor = mismatch
? "rgba(238, 123, 114, 0.42)"
: "rgba(120, 214, 160, 0.42)";
elements.mismatchPill.style.background = mismatch
? "rgba(72, 27, 28, 0.55)"
: "rgba(25, 67, 47, 0.55)";
elements.mismatchPill.style.color = mismatch
? "#ffc0b9"
: "#b9ebc9";
}
function updateEdgeList(result) {
elements.edgeList.innerHTML = edges.map((edge) => {
const assessment = result.assessments.get(edge.id);
const reason = assessment.reasons.join(" · ");
return `
<div class="edge-row">
<div>
<div class="edge-name">${edge.name}</div>
<div class="edge-metrics">
${edge.length.toFixed(1)} m · ${Math.round(edge.moisture * 100)}% moisture
· ${Math.round(edge.cover * 100)}% cover
</div>
${
assessment.pass
? ""
: `<div class="edge-reason">${reason}</div>`
}
</div>
<span class="edge-chip ${assessment.pass ? "pass" : "fail"}">
${assessment.pass ? "Usable" : "Blocked"}
</span>
</div>
`;
}).join("");
}
function updateWorldAssessment(result, profile) {
const profileColor = new THREE.Color(profile.color);
const mutedPass = profileColor.clone().lerp(new THREE.Color(0x9cad82), 0.36);
const failColor = new THREE.Color(0xb95e58);
edges.forEach((edge) => {
const visual = edgeVisuals.get(edge.id);
const assessment = result.assessments.get(edge.id);
const color = assessment.pass ? mutedPass : failColor;
visual.statusMaterial.color.copy(color);
visual.statusMaterial.emissive.copy(color);
visual.statusMaterial.emissiveIntensity = assessment.pass ? 0.16 : 0.25;
visual.pips.forEach((pip) => pip.material.color.copy(color));
visual.barrier.visible = !assessment.pass;
});
}
function updateRouteOverlay(result, profile) {
clearGroup(routeGroup);
const routeEdges = result.connected
? result.pathEdges
: result.prefixEdges;
routeEdges.forEach((edge) => addRouteTube(edge, profile.color));
if (!result.connected && result.failedEdge) {
addFailedRoute(result.failedEdge);
}
}
function updateExperiment() {
const profile = profiles[selectedProfileId];
const result = computeReachability(profile);
currentResult = result;
document.documentElement.style.setProperty("--accent", profile.css);
document.documentElement.style.setProperty("--accent-rgb", profile.rgb);
elements.profileTabs.forEach((button) => {
const active = button.dataset.profile === selectedProfileId;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
elements.profileName.textContent = profile.name;
elements.profileTag.textContent = profile.tag;
elements.sourceNote.innerHTML =
`Source calibration: <b>64% moisture · 62% cover</b>. ${profile.note} ` +
`<b>${profile.evidence}.</b>`;
elements.outStep.textContent = `${profile.maxStep.toFixed(1)} m`;
elements.outMoisture.textContent = `${Math.round(profile.minMoisture * 100)}%`;
elements.outCover.textContent = `${Math.round(profile.minCover * 100)}%`;
elements.diagnostic.classList.toggle("bad", !result.connected);
elements.diagnosticStatus.textContent = result.connected
? "Network connected"
: "Network disconnected";
if (result.connected) {
elements.diagnosticTitle.textContent = "A viable source-to-refuge path exists";
elements.diagnosticText.textContent =
`${profile.name} can use all three links. The long dry cut remains physically present, but it satisfies this profile’s assumptions.`;
} else {
elements.diagnosticTitle.textContent = "No source-to-refuge path";
elements.diagnosticText.textContent =
`${profile.name} reaches the wooded bench, then the dry cut fails the movement rules. The target remains unreachable.`;
}
elements.statReach.textContent = `${result.reachable} / ${nodes.length}`;
elements.statEdges.textContent = `${result.usableCount} / ${edges.length}`;
elements.statBottleneck.textContent = result.failedEdge
? result.failedEdge.name
: "None";
elements.sceneBadge.textContent = result.connected
? `${profile.name} selected · continuous route to target`
: `${profile.name} selected · movement stops at the bottleneck`;
updateEdgeList(result);
updateComparison();
updateWorldAssessment(result, profile);
updateRouteOverlay(result, profile);
updateAgentLabel(profile);
resetAgent(result);
}
function selectProfile(profileId) {
selectedProfileId = profileId;
setRangeValues(profiles[profileId]);
updateExperiment();
}
elements.profileTabs.forEach((button) => {
button.addEventListener("click", () => selectProfile(button.dataset.profile));
});
elements.compareRows.forEach((button) => {
button.addEventListener("click", () => selectProfile(button.dataset.profile));
});
elements.rangeStep.addEventListener("input", (event) => {
profiles[selectedProfileId].maxStep = Number(event.target.value);
updateRangeFill(event.target);
updateExperiment();
});
elements.rangeMoisture.addEventListener("input", (event) => {
profiles[selectedProfileId].minMoisture = Number(event.target.value);
updateRangeFill(event.target);
updateExperiment();
});
elements.rangeCover.addEventListener("input", (event) => {
profiles[selectedProfileId].minCover = Number(event.target.value);
updateRangeFill(event.target);
updateExperiment();
});
document.getElementById("replayButton").addEventListener("click", () => {
resetAgent(currentResult);
});
document.getElementById("restoreButton").addEventListener("click", () => {
profiles.heat.maxStep = 6.5;
profiles.heat.minMoisture = 0.15;
profiles.heat.minCover = 0.10;
profiles.moisture.maxStep = 4.0;
profiles.moisture.minMoisture = 0.55;
profiles.moisture.minCover = 0.50;
setRangeValues(profiles[selectedProfileId]);
updateExperiment();
});
document.getElementById("compareButton").addEventListener("click", () => {
const otherId = selectedProfileId === "heat" ? "moisture" : "heat";
selectProfile(otherId);
});
// ---------------------------------------------------------------------
// Direct camera controls — no addons
// ---------------------------------------------------------------------
const cameraState = {
theta: 0.67,
phi: 0.91,
radius: 22.5,
target: new THREE.Vector3(-0.8, 0.2, 0),
dragging: false,
lastX: 0,
lastY: 0
};
function resetCamera() {
cameraState.theta = 0.67;
cameraState.phi = 0.91;
cameraState.radius = 22.5;
cameraState.target.set(-0.8, 0.2, 0);
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.lastX;
const dy = event.clientY - cameraState.lastY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.43,
1.36
);
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
});
function stopDragging(event) {
cameraState.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
12,
34
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("cameraButton").addEventListener("click", resetCamera);
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
animationElapsed += dt;
animationProgress = Math.min(
1,
animationElapsed / animationDuration
);
positionAgentAlongRoute(animationProgress);
agentBody.rotation.y += dt * 1.8;
agentBody.rotation.z = Math.sin(time * 4.2) * 0.08;
agentCap.rotation.y -= dt * 2.1;
if (currentResult && !currentResult.connected &&
animationProgress >= 1) {
const pulse = 1 + Math.sin(time * 7) * 0.13;
agent.scale.setScalar(pulse);
agentRing.material.color.setHex(0xee7168);
} else {
agent.scale.lerp(new THREE.Vector3(1, 1, 1), 0.14);
}
pollen.rotation.y = Math.sin(time * 0.08) * 0.035;
pollen.position.y = Math.sin(time * 0.35) * 0.08;
updateCamera();
renderer.render(scene, camera);
}
setRangeValues(profiles[selectedProfileId]);
updateExperiment();
updateCamera();
animate();
document.getElementById("loading").remove();
</script>
</body>
</html>
```