Prompt specification
Build or customize the Three.js 3D scene "Interrupted transport thought 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: Interrupted transport thought experiment
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/interrupted-transport-thought-experiment-x0800
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing plant vascular transport. Create a schematic branching plant with selectable blocked pathways; users compare which leaves remain connected under a graph model, with clear limits on its biological realism. Low-poly.
Working Three.js Starter (interrupted-transport-thought-experiment-x0800):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light">
<title>Plant Vascular Transport — Interactive Graph Model</title>
<style>
:root {
--ink: #21312a;
--muted: #67746d;
--line: #d8e0da;
--panel: #f8faf7;
--stage: #e8efe8;
--green: #347c55;
--green-soft: #e4f2e8;
--red: #c64e47;
--red-soft: #f9e7e4;
--blue: #3187a8;
--blue-soft: #e1f1f6;
--taupe: #9a8d70;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: var(--panel);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 3px solid rgba(49, 135, 168, 0.35);
outline-offset: 2px;
}
.app {
display: grid;
grid-template-columns: 370px minmax(0, 1fr);
width: 100%;
height: 100vh;
}
.panel {
position: relative;
z-index: 5;
overflow-y: auto;
padding: 26px 24px 30px;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(248, 250, 247, 0.98)),
var(--panel);
border-right: 1px solid var(--line);
box-shadow: 8px 0 30px rgba(44, 67, 54, 0.05);
}
.kicker {
margin-bottom: 8px;
color: var(--green);
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 1.72rem;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 12px 0 20px;
color: var(--muted);
font-size: 0.9rem;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 20px;
}
.metric {
padding: 12px 13px;
background: #fff;
border: 1px solid var(--line);
border-radius: 12px;
}
.metric strong {
display: block;
margin-bottom: 3px;
font-size: 1.28rem;
letter-spacing: -0.03em;
}
.metric span {
color: var(--muted);
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
section {
margin-top: 22px;
}
.section-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
}
h2 {
margin: 0;
font-size: 0.98rem;
letter-spacing: -0.01em;
}
.section-meta {
color: var(--muted);
font-size: 0.72rem;
font-weight: 700;
}
.section-note {
margin: 6px 0 12px;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.45;
}
.path-list {
display: grid;
gap: 6px;
}
.path-button {
display: grid;
grid-template-columns: 9px minmax(0, 1fr) auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 9px 10px;
color: var(--ink);
text-align: left;
background: #fff;
border: 1px solid var(--line);
border-radius: 10px;
cursor: pointer;
transition:
border-color 120ms ease,
background 120ms ease,
transform 120ms ease;
}
.path-button:hover {
transform: translateX(2px);
border-color: #aebdb2;
}
.path-button.is-blocked {
color: #8b302c;
background: var(--red-soft);
border-color: #e7bbb6;
}
.path-button.is-unreachable:not(.is-blocked) {
background: #f3f0e8;
border-color: #ded7c8;
}
.path-mark {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 3px rgba(52, 124, 85, 0.11);
}
.is-blocked .path-mark {
background: var(--red);
box-shadow: 0 0 0 3px rgba(198, 78, 71, 0.12);
}
.is-unreachable:not(.is-blocked) .path-mark {
background: var(--taupe);
box-shadow: 0 0 0 3px rgba(154, 141, 112, 0.13);
}
.path-copy {
min-width: 0;
}
.path-copy strong,
.path-copy small {
display: block;
}
.path-copy strong {
overflow: hidden;
font-size: 0.78rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.path-copy small {
overflow: hidden;
margin-top: 2px;
color: var(--muted);
font-size: 0.68rem;
text-overflow: ellipsis;
white-space: nowrap;
}
.is-blocked .path-copy small {
color: #a76560;
}
.path-state {
color: var(--green);
font-size: 0.62rem;
font-weight: 900;
letter-spacing: 0.06em;
}
.is-blocked .path-state {
color: var(--red);
}
.is-unreachable:not(.is-blocked) .path-state {
color: #8c7c5f;
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 11px;
}
.button {
padding: 7px 10px;
color: var(--ink);
font-size: 0.72rem;
font-weight: 750;
background: #fff;
border: 1px solid var(--line);
border-radius: 8px;
cursor: pointer;
}
.button:hover {
background: #f0f5f1;
border-color: #afbeb2;
}
.button.primary {
color: #fff;
background: var(--green);
border-color: var(--green);
}
.button.primary:hover {
background: #286847;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.leaf-chip {
min-width: 40px;
padding: 7px 9px;
color: #6f756f;
font-size: 0.72rem;
font-weight: 800;
background: #eeece5;
border: 1px solid #ddd8ca;
border-radius: 999px;
cursor: pointer;
}
.leaf-chip.connected {
color: #286747;
background: var(--green-soft);
border-color: #bfdbc8;
}
.leaf-chip.lost {
color: #9c3b35;
background: var(--red-soft);
border-color: #ebc2bd;
}
.leaf-chip.gained {
color: #26738f;
background: var(--blue-soft);
border-color: #b9dbe6;
}
.leaf-chip.kept {
color: #286747;
background: var(--green-soft);
border-color: #bfdbc8;
}
.reference-box {
margin-top: 12px;
padding: 11px;
background: #fff;
border: 1px solid var(--line);
border-radius: 10px;
}
.reference-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
color: var(--muted);
font-size: 0.72rem;
}
.reference-title strong {
color: var(--ink);
font-size: 0.75rem;
}
.compare-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 7px;
margin-top: 10px;
}
.compare-group {
min-width: 0;
padding: 9px;
background: #fff;
border: 1px solid var(--line);
border-radius: 10px;
}
.compare-group strong {
display: block;
margin-bottom: 8px;
font-size: 0.7rem;
}
.compare-group.kept strong {
color: var(--green);
}
.compare-group.lost strong {
color: var(--red);
}
.compare-group.gained strong {
color: var(--blue);
}
.empty {
color: #a2aaa4;
font-size: 0.68rem;
}
.limits {
margin-top: 22px;
padding: 14px;
background: #fffaf0;
border: 1px solid #e9ddbd;
border-radius: 12px;
}
.limits h3 {
margin: 0 0 7px;
color: #705827;
font-size: 0.82rem;
}
.limits p,
.limits ul {
margin: 0;
color: #776e58;
font-size: 0.72rem;
line-height: 1.5;
}
.limits ul {
margin-top: 7px;
padding-left: 17px;
}
.limits li + li {
margin-top: 4px;
}
.stage {
position: relative;
min-width: 0;
overflow: hidden;
background: var(--stage);
}
.webgl {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.webgl:active {
cursor: grabbing;
}
.scene-heading {
position: absolute;
z-index: 2;
top: 20px;
left: 22px;
pointer-events: none;
}
.scene-heading span {
display: block;
margin-bottom: 5px;
color: #56715f;
font-size: 0.66rem;
font-weight: 850;
letter-spacing: 0.14em;
}
.scene-heading strong {
display: block;
color: #263d30;
font-size: 1rem;
letter-spacing: -0.02em;
}
.view-controls {
position: absolute;
z-index: 3;
top: 18px;
right: 18px;
display: flex;
gap: 7px;
}
.view-controls button {
padding: 7px 10px;
color: #344b3e;
font-size: 0.7rem;
font-weight: 750;
background: rgba(255, 255, 255, 0.78);
border: 1px solid rgba(134, 156, 141, 0.35);
border-radius: 8px;
box-shadow: 0 4px 14px rgba(47, 69, 56, 0.06);
cursor: pointer;
backdrop-filter: blur(8px);
}
.scene-footer {
position: absolute;
z-index: 3;
right: 18px;
bottom: 17px;
left: 18px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
padding: 9px 12px;
color: #52645a;
font-size: 0.68rem;
font-weight: 700;
background: rgba(255, 255, 255, 0.78);
border: 1px solid rgba(134, 156, 141, 0.28);
border-radius: 9px;
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
}
.swatch.green {
background: var(--green);
}
.swatch.red {
background: var(--red);
}
.swatch.grey {
background: var(--taupe);
}
.swatch.blue {
background: var(--blue);
box-shadow: 0 0 0 3px rgba(49, 135, 168, 0.13);
}
.hint {
max-width: 350px;
padding: 9px 11px;
color: #5c6b62;
font-size: 0.67rem;
line-height: 1.4;
text-align: right;
background: rgba(255, 255, 255, 0.65);
border-radius: 8px;
backdrop-filter: blur(8px);
}
.world-label {
position: absolute;
z-index: 1;
display: flex;
align-items: center;
gap: 5px;
padding: 4px 7px;
color: #31533f;
font-size: 0.65rem;
font-weight: 850;
letter-spacing: 0.03em;
white-space: nowrap;
background: rgba(248, 252, 248, 0.84);
border: 1px solid rgba(85, 125, 99, 0.2);
border-radius: 999px;
box-shadow: 0 3px 10px rgba(49, 74, 59, 0.08);
transform: translate(-50%, -50%);
pointer-events: none;
backdrop-filter: blur(5px);
}
.world-label.disconnected {
color: #827963;
background: rgba(246, 243, 235, 0.86);
border-color: rgba(132, 119, 90, 0.2);
}
.world-label .label-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--green);
}
.world-label.disconnected .label-dot {
background: var(--taupe);
}
.world-label.source {
color: #26738f;
border-color: rgba(49, 135, 168, 0.25);
}
.world-label.source .label-dot {
background: var(--blue);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
}
@media (max-width: 820px) {
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: minmax(430px, 58vh) auto;
height: auto;
min-height: 100vh;
}
.stage {
grid-row: 1;
}
.panel {
grid-row: 2;
overflow: visible;
border-top: 1px solid var(--line);
border-right: 0;
}
.scene-footer {
align-items: flex-start;
flex-direction: column;
}
.hint {
max-width: none;
text-align: left;
}
}
@media (max-width: 480px) {
.panel {
padding: 22px 16px 28px;
}
.view-controls {
top: 65px;
left: 18px;
right: auto;
}
.compare-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<main class="app">
<aside class="panel" aria-label="Transport graph controls">
<div class="kicker">Interactive schematic</div>
<h1>Plant vascular<br>transport</h1>
<p class="intro">
Block individual stem segments and compare which leaves remain reachable
from the source. Click a branch in the 3D view or use the pathway list.
</p>
<div class="metrics" aria-live="polite">
<div class="metric">
<strong id="connectedMetric">7 / 7</strong>
<span>Connected leaves</span>
</div>
<div class="metric">
<strong id="referenceMetric">7 / 7</strong>
<span>Reference leaves</span>
</div>
</div>
<section>
<div class="section-heading">
<h2>Pathways</h2>
<span class="section-meta" id="blockedCount">0 blocked</span>
</div>
<p class="section-note">
A red segment is removed from the graph in both directions.
Open segments outside the source component appear muted.
</p>
<div class="path-list" id="pathList"></div>
<div class="button-row">
<button class="button" id="resetBlocks" type="button">Reset all</button>
<button class="button" id="blockAll" type="button">Block all</button>
</div>
</section>
<section>
<div class="section-heading">
<h2>Leaf status</h2>
<span class="section-meta">Current network</span>
</div>
<p class="section-note">
Connected leaves are green. Select a leaf label to focus the camera.
</p>
<div class="chips" id="leafStatus"></div>
</section>
<section>
<div class="section-heading">
<h2>Compare with reference</h2>
<span class="section-meta" id="referenceCaption">All-open baseline</span>
</div>
<div class="reference-box">
<div class="reference-title">
<span>Reference snapshot</span>
<strong id="referenceSummary">7 of 7 leaves</strong>
</div>
<div class="button-row">
<button class="button primary" id="saveReference" type="button">
Save current
</button>
<button class="button" id="allOpenReference" type="button">
All-open baseline
</button>
</div>
</div>
<div class="compare-grid">
<div class="compare-group kept">
<strong id="keptTitle">Kept</strong>
<div class="chips" id="keptChips"></div>
</div>
<div class="compare-group lost">
<strong id="lostTitle">Lost</strong>
<div class="chips" id="lostChips"></div>
</div>
<div class="compare-group gained">
<strong id="gainedTitle">Gained</strong>
<div class="chips" id="gainedChips"></div>
</div>
</div>
</section>
<div class="limits">
<h3>Biological limits of this model</h3>
<p>
<strong>This is a reachability abstraction, not a fluid or physiological
simulation.</strong> Each drawn segment is one binary, undirected graph
edge. Blue beads indicate a source-to-leaf path, not actual water flow.
</p>
<ul>
<li>No pressure, hydraulic resistance, water volume, or embolism dynamics.</li>
<li>No separate xylem and phloem circuits, source–sink exchange, or sugar transport.</li>
<li>The topology is a tree, so it contains no parallel bypass routes.</li>
<li>Recovery, partial dysfunction, anatomy, and scale are not represented.</li>
<li>The low-poly plant is an illustrative diagram, not a botanically accurate model.</li>
</ul>
</div>
<div class="sr-only" id="liveStatus" aria-live="polite"></div>
</aside>
<section class="stage" id="stage" aria-label="Interactive 3D plant">
<div class="scene-heading">
<span>LOW-POLY NETWORK</span>
<strong>Root-to-leaf reachability</strong>
</div>
<div class="view-controls">
<button id="resetView" type="button">Reset view</button>
</div>
<div class="scene-footer">
<div class="legend" aria-label="Scene legend">
<span class="legend-item">
<span class="swatch green"></span> Connected
</span>
<span class="legend-item">
<span class="swatch red"></span> Blocked
</span>
<span class="legend-item">
<span class="swatch grey"></span> Disconnected
</span>
<span class="legend-item">
<span class="swatch blue"></span> Path tracer
</span>
</div>
<div class="hint">
Click a stem to block or reopen it · drag to orbit · Shift-drag to pan ·
scroll to zoom
</div>
</div>
</section>
</main>
<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 stage = $("stage");
// ------------------------------------------------------------
// Graph model
// ------------------------------------------------------------
const nodes = [
{
id: "source",
label: "SOURCE",
short: "Source",
type: "source",
position: [0, 0.28, 0]
},
{
id: "hub",
label: "HUB",
short: "Main hub",
type: "junction",
position: [0, 2.15, 0]
},
{
id: "left",
label: "LEFT",
short: "Left fork",
type: "junction",
position: [-1.75, 3.15, 0]
},
{
id: "right",
label: "RIGHT",
short: "Right fork",
type: "junction",
position: [1.75, 3.15, 0]
},
{
id: "top",
label: "TOP",
short: "Top fork",
type: "junction",
position: [0, 4.0, 0.12]
},
{
id: "L1",
label: "L1",
short: "Leaf 1",
type: "leaf",
position: [-3.15, 3.95, 0.08]
},
{
id: "L2",
label: "L2",
short: "Leaf 2",
type: "leaf",
position: [-2.35, 4.85, -0.2]
},
{
id: "R1",
label: "R1",
short: "Leaf 3",
type: "leaf",
position: [3.15, 3.95, -0.08]
},
{
id: "R2",
label: "R2",
short: "Leaf 4",
type: "leaf",
position: [2.35, 4.85, 0.2]
},
{
id: "T1",
label: "T1",
short: "Leaf 5",
type: "leaf",
position: [-1.1, 5.15, 0.24]
},
{
id: "T2",
label: "T2",
short: "Leaf 6",
type: "leaf",
position: [0.1, 5.85, -0.03]
},
{
id: "T3",
label: "T3",
short: "Leaf 7",
type: "leaf",
position: [1.2, 5.15, 0.2]
}
];
const edges = [
{
id: "e0",
a: "source",
b: "hub",
short: "Base stem",
route: "Source → main hub",
radius: 0.17
},
{
id: "e1",
a: "hub",
b: "left",
short: "Left main branch",
route: "Main hub → left fork",
radius: 0.12
},
{
id: "e2",
a: "hub",
b: "right",
short: "Right main branch",
route: "Main hub → right fork",
radius: 0.12
},
{
id: "e3",
a: "hub",
b: "top",
short: "Upper main branch",
route: "Main hub → top fork",
radius: 0.115
},
{
id: "e4",
a: "left",
b: "L1",
short: "Lower left leaf",
route: "Left fork → L1",
radius: 0.075
},
{
id: "e5",
a: "left",
b: "L2",
short: "Upper left leaf",
route: "Left fork → L2",
radius: 0.075
},
{
id: "e6",
a: "right",
b: "R1",
short: "Lower right leaf",
route: "Right fork → R1",
radius: 0.075
},
{
id: "e7",
a: "right",
b: "R2",
short: "Upper right leaf",
route: "Right fork → R2",
radius: 0.075
},
{
id: "e8",
a: "top",
b: "T1",
short: "Upper-left leaf",
route: "Top fork → T1",
radius: 0.07
},
{
id: "e9",
a: "top",
b: "T2",
short: "Highest leaf",
route: "Top fork → T2",
radius: 0.07
},
{
id: "e10",
a: "top",
b: "T3",
short: "Upper-right leaf",
route: "Top fork → T3",
radius: 0.07
}
];
const nodeById = new Map(nodes.map((node) => [node.id, node]));
const edgeById = new Map(edges.map((edge) => [edge.id, edge]));
const leafNodes = nodes.filter((node) => node.type === "leaf");
const leafIds = leafNodes.map((node) => node.id);
const adjacency = new Map(nodes.map((node) => [node.id, []]));
for (const edge of edges) {
adjacency.get(edge.a).push({ edge, other: edge.b });
adjacency.get(edge.b).push({ edge, other: edge.a });
}
const blockedEdges = new Set();
let referenceLeaves = new Set(leafIds);
let referenceLabel = "All-open baseline";
let currentConnectedLeaves = new Set(leafIds);
let hoveredEdgeId = null;
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8efe8);
scene.fog = new THREE.Fog(0xe8efe8, 18, 35);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.className = "webgl";
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly plant showing connected and disconnected leaves"
);
stage.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf7fff4, 0x7c7765, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(7, 11, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -3;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cc9d4, 0.8);
fill.position.set(-7, 5, -6);
scene.add(fill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
new THREE.MeshStandardMaterial({
color: 0xd3ddcf,
roughness: 1,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.17;
ground.receiveShadow = true;
scene.add(ground);
const soil = new THREE.Mesh(
new THREE.CylinderGeometry(1.12, 1.28, 0.3, 10),
new THREE.MeshStandardMaterial({
color: 0x897358,
roughness: 1,
flatShading: true
})
);
soil.position.y = -0.015;
soil.receiveShadow = true;
soil.castShadow = true;
scene.add(soil);
const soilTop = new THREE.Mesh(
new THREE.CylinderGeometry(1.08, 1.08, 0.035, 10),
new THREE.MeshStandardMaterial({
color: 0x9d896a,
roughness: 1,
flatShading: true
})
);
soilTop.position.y = 0.145;
soilTop.receiveShadow = true;
scene.add(soilTop);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0xa6afa2,
roughness: 1,
flatShading: true
});
[
[-1.9, -0.02, 0.6, 0.23],
[1.75, -0.035, -0.5, 0.2],
[2.15, -0.045, 0.8, 0.13]
].forEach(([x, y, z, size]) => {
const rock = new THREE.Mesh(
new THREE.IcosahedronGeometry(size, 0),
rockMaterial
);
rock.position.set(x, y, z);
rock.scale.y = 0.65;
rock.rotation.set(0.2, x, 0.15);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
});
const sourceMarker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.22, 1),
new THREE.MeshStandardMaterial({
color: 0x3a95b4,
emissive: 0x164e62,
emissiveIntensity: 0.55,
roughness: 0.45,
flatShading: true
})
);
sourceMarker.position.set(0, 0.32, 0.18);
sourceMarker.castShadow = true;
scene.add(sourceMarker);
const edgeVisuals = new Map();
const edgeHitTargets = [];
const junctionVisuals = new Map();
const leafVisuals = new Map();
const labels = [];
const flowVisuals = new Map();
const routeCache = new Map();
const up = new THREE.Vector3(0, 1, 0);
const zAxis = new THREE.Vector3(0, 0, 1);
function createEdgeVisual(edge) {
const start = nodeById.get(edge.a).position;
const end = nodeById.get(edge.b).position;
const startV = new THREE.Vector3(...start);
const endV = new THREE.Vector3(...end);
const direction = endV.clone().sub(startV);
const length = direction.length();
const midpoint = startV.clone().add(endV).multiplyScalar(0.5);
direction.normalize();
const material = new THREE.MeshStandardMaterial({
color: 0x347c55,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.82,
flatShading: true
});
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(
edge.radius * 0.82,
edge.radius,
length,
6,
1,
false
),
material
);
stem.position.copy(midpoint);
stem.quaternion.setFromUnitVectors(up, direction);
stem.castShadow = true;
stem.receiveShadow = true;
stem.userData.edgeId = edge.id;
scene.add(stem);
// A wider invisible cylinder makes thin branches easier to pick.
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const hit = new THREE.Mesh(
new THREE.CylinderGeometry(
Math.max(edge.radius * 2.2, 0.16),
Math.max(edge.radius * 2.2, 0.16),
length,
6
),
hitMaterial
);
hit.position.copy(midpoint);
hit.quaternion.setFromUnitVectors(up, direction);
hit.userData.edgeId = edge.id;
scene.add(hit);
edgeHitTargets.push(hit);
const marker = new THREE.Group();
const ring = new THREE.Mesh(
new THREE.TorusGeometry(Math.max(edge.radius * 1.5, 0.14), 0.055, 5, 10),
new THREE.MeshStandardMaterial({
color: 0xe36a60,
emissive: 0x6c1612,
emissiveIntensity: 0.4,
roughness: 0.5,
flatShading: true
})
);
ring.quaternion.setFromUnitVectors(zAxis, direction);
marker.add(ring);
const barGeometry = new THREE.BoxGeometry(0.29, 0.055, 0.055);
const barMaterial = new THREE.MeshStandardMaterial({
color: 0xe36a60,
emissive: 0x6c1612,
emissiveIntensity: 0.35,
roughness: 0.55,
flatShading: true
});
const bar1 = new THREE.Mesh(barGeometry, barMaterial);
const bar2 = new THREE.Mesh(barGeometry, barMaterial);
bar1.rotation.z = Math.PI / 4;
bar2.rotation.z = -Math.PI / 4;
marker.add(bar1, bar2);
marker.position.copy(midpoint);
marker.visible = false;
scene.add(marker);
edgeVisuals.set(edge.id, {
stem,
material,
marker
});
}
edges.forEach(createEdgeVisual);
for (const node of nodes.filter((item) => item.type === "junction")) {
const material = new THREE.MeshStandardMaterial({
color: 0x347c55,
roughness: 0.8,
flatShading: true
});
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(node.id === "hub" ? 0.19 : 0.15, 1),
material
);
mesh.position.set(...node.position);
mesh.castShadow = true;
scene.add(mesh);
junctionVisuals.set(node.id, mesh);
}
const leafGeometry = new THREE.BufferGeometry();
leafGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0, 0, 0, // base
0, 0.86, 0, // tip
-0.35, 0.38, 0, // left
0.35, 0.38, 0, // right
0, 0.4, 0.14, // raised ridge
0, 0.4, -0.08 // back ridge
],
3
)
);
leafGeometry.setIndex([
0, 2, 4,
2, 1, 4,
1, 3, 4,
3, 0, 4,
0, 4, 5,
2, 5, 4,
1, 5, 4,
3, 5, 4
]);
leafGeometry.computeVertexNormals();
function parentEdgeFor(nodeId) {
return edges.find(
(edge) => edge.a === nodeId || edge.b === nodeId
);
}
function makeWorldLabel(text, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`;
const dot = document.createElement("span");
dot.className = "label-dot";
const textElement = document.createElement("span");
textElement.textContent = text;
element.append(dot, textElement);
stage.appendChild(element);
return element;
}
leafNodes.forEach((node, index) => {
const parentEdge = parentEdgeFor(node.id);
const parentNode = nodeById.get(
parentEdge.a === node.id ? parentEdge.b : parentEdge.a
);
const direction = new THREE.Vector3(...node.position)
.sub(new THREE.Vector3(...parentNode.position))
.normalize();
const material = new THREE.MeshStandardMaterial({
color: 0x438d59,
emissive: 0x0d2a18,
emissiveIntensity: 0.12,
roughness: 0.8,
flatShading: true,
side: THREE.DoubleSide
});
const leaf = new THREE.Mesh(leafGeometry, material);
leaf.position.set(...node.position);
leaf.quaternion.setFromUnitVectors(up, direction);
leaf.rotateY(index * 1.17);
leaf.scale.setScalar(0.88 + (index % 3) * 0.055);
leaf.castShadow = true;
leaf.receiveShadow = true;
scene.add(leaf);
leafVisuals.set(node.id, {
mesh: leaf,
material,
anchor: new THREE.Vector3(...node.position).addScaledVector(direction, 1.02)
});
const label = makeWorldLabel(node.label);
labels.push({
element: label,
anchor: new THREE.Vector3(...node.position).addScaledVector(direction, 1.02),
nodeId: node.id
});
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.07, 1),
new THREE.MeshBasicMaterial({ color: 0x45b4d0 })
);
const halo = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.14, 1),
new THREE.MeshBasicMaterial({
color: 0x66c4dc,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
const flow = new THREE.Group();
flow.add(core, halo);
flow.visible = false;
scene.add(flow);
flowVisuals.set(node.id, flow);
});
const sourceLabel = makeWorldLabel("SOURCE", "source");
labels.push({
element: sourceLabel,
anchor: new THREE.Vector3(0, 0.78, 0.12),
nodeId: "source"
});
// ------------------------------------------------------------
// Graph analysis
// ------------------------------------------------------------
function analyzeNetwork() {
const connectedNodes = new Set(["source"]);
const parent = new Map();
const connectedEdges = new Set();
const queue = ["source"];
while (queue.length) {
const current = queue.shift();
for (const { edge, other } of adjacency.get(current)) {
if (blockedEdges.has(edge.id) || connectedNodes.has(other)) {
continue;
}
connectedNodes.add(other);
connectedEdges.add(edge.id);
parent.set(other, { node: current, edge: edge.id });
queue.push(other);
}
}
const connectedLeaves = new Set(
leafIds.filter((id) => connectedNodes.has(id))
);
return {
connectedNodes,
connectedEdges,
connectedLeaves,
parent
};
}
function rebuildRouteCache(parent, connectedLeaves) {
routeCache.clear();
for (const leafId of leafIds) {
if (!connectedLeaves.has(leafId)) {
continue;
}
const edgeIds = [];
const nodeIds = [leafId];
let current = leafId;
while (current !== "source") {
const parentInfo = parent.get(current);
if (!parentInfo) {
break;
}
edgeIds.unshift(parentInfo.edge);
current = parentInfo.node;
nodeIds.unshift(current);
}
const points = nodeIds.map(
(id) => new THREE.Vector3(...nodeById.get(id).position)
);
const lengths = [];
let totalLength = 0;
for (let i = 0; i < points.length - 1; i += 1) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
totalLength += length;
}
routeCache.set(leafId, { points, lengths, totalLength });
}
}
function setEdgeAppearance(edge, connectedEdges) {
const visual = edgeVisuals.get(edge.id);
if (blockedEdges.has(edge.id)) {
visual.material.color.setHex(0xc64e47);
visual.material.emissive.setHex(
hoveredEdgeId === edge.id ? 0x8f2823 : 0x4c100d
);
visual.material.emissiveIntensity = hoveredEdgeId === edge.id ? 0.7 : 0.28;
visual.marker.visible = true;
} else if (connectedEdges.has(edge.id)) {
visual.material.color.setHex(0x347c55);
visual.material.emissive.setHex(
hoveredEdgeId === edge.id ? 0x285b3c : 0x000000
);
visual.material.emissiveIntensity = hoveredEdgeId === edge.id ? 0.55 : 0;
visual.marker.visible = false;
} else {
visual.material.color.setHex(0x9a8d70);
visual.material.emissive.setHex(
hoveredEdgeId === edge.id ? 0x665b43 : 0x000000
);
visual.material.emissiveIntensity = hoveredEdgeId === edge.id ? 0.45 : 0;
visual.marker.visible = false;
}
}
function updateModelState() {
const analysis = analyzeNetwork();
currentConnectedLeaves = analysis.connectedLeaves;
for (const edge of edges) {
setEdgeAppearance(edge, analysis.connectedEdges);
}
for (const node of nodes.filter((item) => item.type === "junction")) {
const visual = junctionVisuals.get(node.id);
visual.material.color.setHex(
analysis.connectedNodes.has(node.id) ? 0x347c55 : 0x9a8d70
);
}
for (const leaf of leafNodes) {
const visual = leafVisuals.get(leaf.id);
const connected = currentConnectedLeaves.has(leaf.id);
visual.material.color.setHex(
connected ? 0x438d59 : 0x9d967b
);
visual.material.emissive.setHex(
connected ? 0x0d2a18 : 0x000000
);
visual.material.emissiveIntensity = connected ? 0.12 : 0;
}
rebuildRouteCache(analysis.parent, currentConnectedLeaves);
updateUI();
}
// ------------------------------------------------------------
// UI construction and updates
// ------------------------------------------------------------
const pathButtons = new Map();
for (const edge of edges) {
const button = document.createElement("button");
button.type = "button";
button.className = "path-button";
button.innerHTML = `
<span class="path-mark" aria-hidden="true"></span>
<span class="path-copy">
<strong>${edge.short}</strong>
<small>${edge.route}</small>
</span>
<span class="path-state">OPEN</span>
`;
button.addEventListener("click", () => toggleEdge(edge.id));
$("pathList").appendChild(button);
pathButtons.set(edge.id, button);
}
function renderLeafStatus() {
$("leafStatus").replaceChildren();
for (const leaf of leafNodes) {
const connected = currentConnectedLeaves.has(leaf.id);
const chip = document.createElement("button");
chip.type = "button";
chip.className = `leaf-chip ${connected ? "connected" : ""}`;
chip.textContent = leaf.id;
chip.title = connected
? `${leaf.short}: connected to the source`
: `${leaf.short}: disconnected from the source`;
chip.addEventListener("click", () => focusLeaf(leaf.id));
$("leafStatus").appendChild(chip);
}
}
function renderComparison(containerId, ids, className) {
const container = $(containerId);
container.replaceChildren();
if (ids.length === 0) {
const empty = document.createElement("span");
empty.className = "empty";
empty.textContent = "None";
container.appendChild(empty);
return;
}
for (const id of ids) {
const chip = document.createElement("button");
chip.type = "button";
chip.className = `leaf-chip ${className}`;
chip.textContent = id;
chip.title = `Focus ${nodeById.get(id).short}`;
chip.addEventListener("click", () => focusLeaf(id));
container.appendChild(chip);
}
}
function updateUI() {
$("connectedMetric").textContent =
`${currentConnectedLeaves.size} / ${leafIds.length}`;
$("referenceMetric").textContent =
`${referenceLeaves.size} / ${leafIds.length}`;
$("referenceCaption").textContent = referenceLabel;
$("referenceSummary").textContent =
`${referenceLeaves.size} of ${leafIds.length} leaves`;
$("blockedCount").textContent =
`${blockedEdges.size} blocked`;
for (const edge of edges) {
const button = pathButtons.get(edge.id);
const blocked = blockedEdges.has(edge.id);
button.classList.toggle("is-blocked", blocked);
button.setAttribute("aria-pressed", String(blocked));
button.querySelector(".path-state").textContent =
blocked ? "BLOCKED" : "OPEN";
}
renderLeafStatus();
const kept = [...currentConnectedLeaves].filter((id) =>
referenceLeaves.has(id)
);
const lost = [...referenceLeaves].filter(
(id) => !currentConnectedLeaves.has(id)
);
const gained = [...currentConnectedLeaves].filter(
(id) => !referenceLeaves.has(id)
);
$("keptTitle").textContent = `Kept (${kept.length})`;
$("lostTitle").textContent = `Lost (${lost.length})`;
$("gainedTitle").textContent = `Gained (${gained.length})`;
renderComparison("keptChips", kept, "kept");
renderComparison("lostChips", lost, "lost");
renderComparison("gainedChips", gained, "gained");
$("liveStatus").textContent =
`${currentConnectedLeaves.size} of ${leafIds.length} leaves are connected. ` +
`${blockedEdges.size} pathways are blocked.`;
}
function toggleEdge(edgeId) {
if (blockedEdges.has(edgeId)) {
blockedEdges.delete(edgeId);
} else {
blockedEdges.add(edgeId);
}
updateModelState();
}
$("resetBlocks").addEventListener("click", () => {
blockedEdges.clear();
updateModelState();
});
$("blockAll").addEventListener("click", () => {
edges.forEach((edge) => blockedEdges.add(edge.id));
updateModelState();
});
$("saveReference").addEventListener("click", () => {
referenceLeaves = new Set(currentConnectedLeaves);
referenceLabel = "Saved snapshot";
updateUI();
});
$("allOpenReference").addEventListener("click", () => {
referenceLeaves = new Set(leafIds);
referenceLabel = "All-open baseline";
updateUI();
});
// ------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, and picking
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 3.0, 0),
azimuth: 0.56,
polar: 1.08,
distance: 13.5
};
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.distance * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y +
cameraState.distance * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.distance * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(0, 3.0, 0);
cameraState.azimuth = 0.56;
cameraState.polar = 1.08;
cameraState.distance = 13.5;
updateCamera();
}
function focusLeaf(id) {
const node = nodeById.get(id);
cameraState.target.set(...node.position);
cameraState.distance = Math.min(cameraState.distance, 7.5);
updateCamera();
}
$("resetView").addEventListener("click", resetCamera);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickEdge(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(edgeHitTargets, false);
if (intersections.length) {
return intersections[0].object.userData.edgeId;
}
return null;
}
function setHoveredEdge(edgeId) {
if (hoveredEdgeId === edgeId) {
return;
}
hoveredEdgeId = edgeId;
renderer.domElement.style.cursor = edgeId ? "pointer" : "grab";
const analysis = analyzeNetwork();
for (const edge of edges) {
setEdgeAppearance(edge, analysis.connectedEdges);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) {
return;
}
pointerDown = {
id: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown && pointerDown.id === event.pointerId) {
const dx = event.clientX - pointerDown.lastX;
const dy = event.clientY - pointerDown.lastY;
const totalX = event.clientX - pointerDown.startX;
const totalY = event.clientY - pointerDown.startY;
if (Math.hypot(totalX, totalY) > 4) {
pointerDown.moved = true;
}
if (event.shiftKey) {
const forward = camera.getWorldDirection(new THREE.Vector3());
const right = new THREE.Vector3()
.crossVectors(forward, up)
.normalize();
const cameraUp = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const panScale = cameraState.distance * 0.0014;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(cameraUp, dy * panScale);
} else {
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.34,
1.48
);
}
pointerDown.lastX = event.clientX;
pointerDown.lastY = event.clientY;
setHoveredEdge(null);
updateCamera();
return;
}
setHoveredEdge(pickEdge(event));
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerDown || pointerDown.id !== event.pointerId) {
return;
}
if (!pointerDown.moved) {
const edgeId = pickEdge(event);
if (edgeId) {
toggleEdge(edgeId);
}
}
pointerDown = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
5.2,
23
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------
// Animation and projected labels
// ------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function animateFlowers(elapsed) {
leafNodes.forEach((leaf, index) => {
const flow = flowVisuals.get(leaf.id);
const route = routeCache.get(leaf.id);
if (!route) {
flow.visible = false;
return;
}
flow.visible = true;
const t = (elapsed * 0.00014 + index * 0.137) % 1;
let distance = t * route.totalLength;
let segmentIndex = 0;
while (
segmentIndex < route.lengths.length - 1 &&
distance > route.lengths[segmentIndex]
) {
distance -= route.lengths[segmentIndex];
segmentIndex += 1;
}
const segmentLength =
route.lengths[segmentIndex] || route.totalLength || 1;
const localT = THREE.MathUtils.clamp(
distance / segmentLength,
0,
1
);
const start = route.points[segmentIndex];
const end = route.points[segmentIndex + 1];
flow.position.lerpVectors(start, end, localT);
});
}
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
label.element.style.display = visible ? "flex" : "none";
if (!visible) {
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
if (label.nodeId !== "source") {
label.element.classList.toggle(
"disconnected",
!currentConnectedLeaves.has(label.nodeId)
);
}
}
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
updateCamera();
updateModelState();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
animateFlowers(elapsed);
updateLabels();
const pulse = 1 + Math.sin(elapsed * 2.6) * 0.07;
sourceMarker.scale.setScalar(pulse);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```