Prompt specification
Build or customize the Three.js 3D scene "Compacted versus porous soil exhibit" 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: Compacted versus porous soil exhibit
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compacted-versus-porous-soil-exhibit-x0676
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing earthworm burrows. Create two schematic soil blocks with different pore connectivity and worm-access routes; users compare tracer movement through declared channels while labels distinguish geometry from actual soil-hydrology prediction. Low-poly.
Working Three.js Starter (compacted-versus-porous-soil-exhibit-x0676):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Earthworm Burrows — Declared Connectivity</title>
<style>
:root {
color-scheme: dark;
--bg: #071318;
--panel: rgba(9, 25, 31, 0.88);
--panel-strong: rgba(11, 30, 37, 0.95);
--line: rgba(163, 209, 219, 0.2);
--text: #e8f4f5;
--muted: #9db4b9;
--cyan: #52eaff;
--cyan-dark: #247f96;
--orange: #ff9b62;
--cream: #f0d4ad;
--danger: #ffba75;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
select,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
z-index: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
#annotations {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.annotation {
position: absolute;
transform: translate(-50%, -50%);
white-space: nowrap;
transition: opacity 120ms ease;
}
.block-title {
min-width: 255px;
padding: 10px 13px 11px;
text-align: center;
background: rgba(7, 22, 28, 0.83);
border: 1px solid rgba(108, 218, 237, 0.25);
border-top: 2px solid var(--cyan-dark);
border-radius: 8px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(8px);
}
.block-title .eyebrow {
display: block;
margin-bottom: 3px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
}
.block-title strong {
display: block;
font-size: 14px;
letter-spacing: 0.01em;
}
.block-title small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.callout {
padding: 5px 8px;
color: #d5e4e7;
background: rgba(7, 19, 24, 0.86);
border: 1px solid rgba(171, 204, 211, 0.22);
border-radius: 5px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.24);
}
.callout::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: rgba(190, 215, 220, 0.42);
}
.callout.worm {
color: #ffd1b4;
border-color: rgba(255, 155, 98, 0.35);
}
.callout.gap {
color: #e8eef0;
border-color: rgba(210, 224, 228, 0.42);
letter-spacing: 0.12em;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 12px;
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
#hud {
position: fixed;
z-index: 6;
top: 18px;
left: 20px;
width: min(680px, calc(100vw - 390px));
padding: 17px 19px 16px;
}
.kicker {
margin-bottom: 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.5vw, 34px);
line-height: 1.08;
letter-spacing: -0.035em;
}
#hud p {
max-width: 610px;
margin: 8px 0 13px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
button,
select {
min-height: 34px;
color: var(--text);
background: rgba(20, 48, 57, 0.92);
border: 1px solid rgba(121, 195, 207, 0.24);
border-radius: 7px;
}
button {
padding: 7px 12px;
cursor: pointer;
font-weight: 750;
}
button:hover,
select:hover {
border-color: rgba(82, 234, 255, 0.62);
background: rgba(27, 64, 75, 0.98);
}
button:focus-visible,
select:focus-visible,
input:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
select {
padding: 6px 27px 6px 9px;
}
.toggle {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 34px;
color: #c8d7da;
font-size: 12px;
user-select: none;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: var(--orange);
}
#legend {
position: fixed;
z-index: 6;
top: 18px;
right: 20px;
width: 300px;
padding: 15px 16px;
}
.legend-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.legend-title strong {
font-size: 13px;
}
.geometry-badge {
padding: 4px 7px;
color: var(--cream);
background: rgba(255, 186, 117, 0.09);
border: 1px solid rgba(255, 186, 117, 0.26);
border-radius: 999px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
}
.legend-row {
display: grid;
grid-template-columns: 38px 1fr;
gap: 9px;
align-items: center;
min-height: 31px;
color: #c8d5d8;
font-size: 11px;
line-height: 1.3;
}
.swatch {
position: relative;
display: block;
height: 12px;
}
.swatch.channel::before {
content: "";
position: absolute;
top: 5px;
left: 0;
width: 37px;
height: 4px;
background: var(--cyan-dark);
border-radius: 2px;
box-shadow: 0 0 8px rgba(82, 234, 255, 0.22);
}
.swatch.active::before {
background: var(--cyan);
box-shadow: 0 0 10px rgba(82, 234, 255, 0.55);
}
.swatch.dashed::before {
content: "";
position: absolute;
top: 5px;
left: 0;
width: 37px;
height: 4px;
background: repeating-linear-gradient(
90deg,
var(--orange) 0 8px,
transparent 8px 12px
);
}
.swatch.tracer::before {
content: "";
position: absolute;
top: 1px;
left: 14px;
width: 10px;
height: 10px;
background: var(--cyan);
border: 2px solid #d9fbff;
border-radius: 50%;
box-shadow: 0 0 12px var(--cyan);
}
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#compare {
position: fixed;
z-index: 6;
left: 50%;
bottom: 66px;
display: grid;
grid-template-columns: repeat(2, minmax(280px, 1fr));
gap: 10px;
width: min(780px, calc(100vw - 40px));
transform: translateX(-50%);
}
.compare-card {
padding: 13px 14px 12px;
}
.compare-head {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
}
.compare-head strong {
font-size: 13px;
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
background: var(--cyan);
border-radius: 50%;
box-shadow: 0 0 9px rgba(82, 234, 255, 0.7);
}
.graph-tag {
margin-left: auto;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.compare-card p {
min-height: 34px;
margin: 0 0 8px;
color: #c6d5d8;
font-size: 11px;
line-height: 1.4;
}
.progress {
height: 4px;
overflow: hidden;
background: rgba(136, 179, 188, 0.13);
border-radius: 99px;
}
.progress i {
display: block;
width: 0;
height: 100%;
background: linear-gradient(90deg, #1d7289, var(--cyan));
border-radius: inherit;
box-shadow: 0 0 9px rgba(82, 234, 255, 0.55);
}
.compare-card small {
display: block;
margin-top: 7px;
color: #7f989e;
font-size: 9px;
line-height: 1.35;
}
#disclaimer {
position: fixed;
z-index: 7;
right: 20px;
bottom: 16px;
left: 20px;
padding: 9px 13px;
color: #e7d7c2;
background: rgba(38, 28, 20, 0.91);
border: 1px solid rgba(255, 186, 117, 0.28);
border-radius: 8px;
font-size: 10px;
line-height: 1.4;
text-align: center;
backdrop-filter: blur(10px);
}
#disclaimer strong {
color: #ffd3a8;
letter-spacing: 0.04em;
}
#cameraHint {
position: fixed;
z-index: 4;
right: 22px;
bottom: 108px;
color: rgba(181, 204, 209, 0.66);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: var(--cyan);
background: var(--bg);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 980px) {
#hud {
width: calc(100vw - 40px);
max-width: 680px;
}
#legend {
top: auto;
right: 12px;
bottom: 160px;
width: 270px;
}
#cameraHint {
display: none;
}
}
@media (max-width: 680px) {
#hud {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 14px;
}
#hud p {
display: none;
}
h1 {
font-size: 22px;
}
#legend {
top: 132px;
right: 10px;
bottom: auto;
width: 218px;
padding: 10px 12px;
}
.legend-row {
grid-template-columns: 29px 1fr;
min-height: 25px;
font-size: 9px;
}
.swatch.channel::before,
.swatch.active::before,
.swatch.dashed::before {
width: 28px;
}
.swatch.tracer::before {
left: 9px;
}
.legend-note {
display: none;
}
#compare {
bottom: 77px;
grid-template-columns: 1fr;
gap: 6px;
width: calc(100vw - 20px);
}
.compare-card {
padding: 9px 11px;
}
.compare-card p {
min-height: 0;
margin-bottom: 5px;
}
.compare-card small {
display: none;
}
.block-title {
min-width: 205px;
padding: 7px 9px;
}
.block-title strong {
font-size: 11px;
}
.block-title small,
.callout {
display: none;
}
#disclaimer {
right: 10px;
bottom: 8px;
left: 10px;
padding: 7px 9px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive low-poly comparison of two schematic earthworm burrow networks"></div>
<div id="annotations" aria-hidden="true"></div>
<header id="hud" class="panel">
<div class="kicker">Earthworm burrows / declared connectivity</div>
<h1>Compare the geometry, not a flow prediction</h1>
<p>
Cyan tracers perform a scripted walk along the blue edge networks.
Dashed orange overlays show illustrative worm-access routes.
</p>
<div class="controls">
<button id="playButton" type="button" aria-pressed="true">Pause walk</button>
<button id="resetButton" type="button">Reset tracers</button>
<label class="toggle">
<input id="wormToggle" type="checkbox" checked>
Worm-access overlays
</label>
<label class="toggle" for="speedSelect">
Speed
<select id="speedSelect">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="2">2×</option>
<option value="4">4×</option>
</select>
</label>
</div>
</header>
<aside id="legend" class="panel" aria-label="Visualization legend">
<div class="legend-title">
<strong>Visual grammar</strong>
<span class="geometry-badge">Geometry only</span>
</div>
<div class="legend-row">
<span class="swatch channel"></span>
<span>Declared pore-channel edge</span>
</div>
<div class="legend-row">
<span class="swatch active"></span>
<span>Visited segment of scripted walk</span>
</div>
<div class="legend-row">
<span class="swatch dashed"></span>
<span>Illustrative worm-access route</span>
</div>
<div class="legend-row">
<span class="swatch tracer"></span>
<span>Scripted tracer position</span>
</div>
<div class="legend-note">
Low-poly soil and rock shapes are decorative context. The only
paths available to a tracer are the explicitly connected blue edges.
</div>
</aside>
<section id="compare" aria-label="Declared graph status">
<article class="compare-card panel">
<div class="compare-head">
<span class="status-dot"></span>
<strong>Geometry A</strong>
<span class="graph-tag">continuous chain</span>
</div>
<p id="statusA" aria-live="polite">At surface inlet · scripted walk ready</p>
<div class="progress"><i id="barA"></i></div>
<small>9 declared edge links · one uninterrupted terminal path</small>
</article>
<article class="compare-card panel">
<div class="compare-head">
<span class="status-dot"></span>
<strong>Geometry B</strong>
<span class="graph-tag">interrupted graph</span>
</div>
<p id="statusB" aria-live="polite">At surface inlet · scripted walk ready</p>
<div class="progress"><i id="barB"></i></div>
<small>Upper chain: 2 links · lower cluster: 4 links · no inter-cluster link</small>
</article>
</section>
<div id="cameraHint">Drag to orbit · wheel to zoom · double-click to reset view</div>
<footer id="disclaimer">
<strong>NOT AN ACTUAL SOIL-HYDROLOGY PREDICTION.</strong>
This is a declared-network geometry demonstration. The animation does not
solve water flow, solute transport, Richards’ equation, or real burrow
behavior. The orange routes are illustrative access overlays.
</footer>
<div id="loading">Loading schematic geometry…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const annotations = document.getElementById("annotations");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071318);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is required to display this schematic.";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.16;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Two low-poly cutaway soil blocks with declared burrow channel networks"
);
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -1.38, 0);
const cameraState = {
theta: 0.16,
phi: 1.02,
zoom: 1
};
function updateCamera() {
const radius = 18;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + radius * Math.cos(cameraState.phi),
cameraTarget.z + radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.16;
cameraState.phi = 1.02;
cameraState.zoom = 1;
updateCamera();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve both blocks and their title space at all aspect ratios.
const halfHeight = Math.max(3.8, 5.7 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const hemisphere = new THREE.HemisphereLight(0xc6ecff, 0x4a2d1d, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d8, 2.5);
keyLight.position.set(4.5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4bd8ff, 1.25);
rimLight.position.set(-7, 3, -5);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x0a2024,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -3.33;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x28515a, 0x17373e);
grid.position.y = -3.315;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const baseRockGeometry = new THREE.IcosahedronGeometry(1, 0);
const soilPaletteA = [0x5e402d, 0x725037, 0x4c3527, 0x806044, 0x664733];
const soilPaletteB = [0x57402f, 0x6b4c38, 0x463329, 0x7d5c43, 0x60452f];
const channelBaseColor = new THREE.Color(0x23758a);
const channelBrightColor = new THREE.Color(0x52eaff);
const wormColor = 0xff9b62;
const blocks = [];
const annotationItems = [];
const wormGroups = [];
function seededRandom(seed) {
let value = seed >>> 0;
return function random() {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function cylinderBetween(group, pointA, pointB, radius, material, segments = 6) {
const direction = new THREE.Vector3().subVectors(pointB, pointA);
const length = direction.length();
if (length < 0.0001) {
return null;
}
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
segments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(pointA).add(pointB).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function makeSoilBlock(def) {
const group = new THREE.Group();
group.position.x = def.cx;
scene.add(group);
const width = 3.4;
const height = 3.6;
const depth = 2.2;
const centerY = -1.5;
const backMaterial = new THREE.MeshStandardMaterial({
color: def.id === "A" ? 0x5c3f2d : 0x533d30,
roughness: 1,
metalness: 0,
flatShading: true
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: 0x493326,
roughness: 1,
metalness: 0,
transparent: true,
opacity: 0.84,
side: THREE.DoubleSide,
flatShading: true
});
const topMaterial = new THREE.MeshStandardMaterial({
color: 0x765039,
roughness: 1,
metalness: 0,
flatShading: true
});
const back = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
backMaterial
);
back.position.set(0, centerY, -depth / 2);
back.receiveShadow = true;
group.add(back);
const right = new THREE.Mesh(
new THREE.PlaneGeometry(depth, height),
sideMaterial
);
right.position.set(width / 2, centerY, 0);
right.rotation.y = Math.PI / 2;
right.castShadow = true;
right.receiveShadow = true;
group.add(right);
const left = right.clone();
left.position.x = -width / 2;
left.rotation.y = -Math.PI / 2;
group.add(left);
const bottom = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
sideMaterial
);
bottom.position.set(0, -3.3, 0);
bottom.rotation.x = Math.PI / 2;
bottom.receiveShadow = true;
group.add(bottom);
const top = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
topMaterial
);
top.position.set(0, 0.3, 0);
top.rotation.x = -Math.PI / 2;
top.receiveShadow = true;
group.add(top);
const frame = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(width, height, depth)),
new THREE.LineBasicMaterial({
color: 0xc19c78,
transparent: true,
opacity: 0.58
})
);
frame.position.y = centerY;
group.add(frame);
// Decorative low-poly soil aggregates behind the channel geometry.
const random = seededRandom(def.id === "A" ? 781 : 1293);
const palette = def.id === "A" ? soilPaletteA : soilPaletteB;
const rockMaterials = palette.map((color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 1,
metalness: 0,
flatShading: true
})
);
for (let i = 0; i < 76; i += 1) {
const radius = 0.065 + random() * 0.145;
const rock = new THREE.Mesh(
baseRockGeometry,
rockMaterials[Math.floor(random() * rockMaterials.length)]
);
rock.position.set(
(random() - 0.5) * (width - 0.3),
-3.08 + random() * 3.16,
-0.98 + random() * 0.57
);
rock.scale.set(
radius * (0.8 + random() * 0.8),
radius * (0.65 + random() * 0.75),
radius * (0.7 + random() * 0.6)
);
rock.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
rock.castShadow = true;
rock.receiveShadow = true;
group.add(rock);
}
// Faint strata guides on the open cutaway face.
for (const y of [-0.62, -1.68, -2.72]) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.66, y, 1.07),
new THREE.Vector3(1.66, y, 1.07)
]);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color: 0xd4b188,
transparent: true,
opacity: 0.23,
dashSize: 0.13,
gapSize: 0.09
})
);
line.computeLineDistances();
group.add(line);
}
return group;
}
function makeChannelNetwork(block) {
const routeNodes = new Set(block.def.route);
const routeEdgeKeys = new Set();
for (let i = 0; i < block.def.route.length - 1; i += 1) {
routeEdgeKeys.add(
`${block.def.route[i]}->${block.def.route[i + 1]}`
);
}
const nodeMaterials = new Map();
for (const [id, coordinates] of Object.entries(block.def.nodes)) {
const isRouteNode = routeNodes.has(id);
const material = new THREE.MeshStandardMaterial({
color: isRouteNode ? 0x48d8ec : 0x2a6473,
emissive: isRouteNode ? 0x073641 : 0x041c22,
emissiveIntensity: isRouteNode ? 0.75 : 0.25,
roughness: 0.45,
metalness: 0.03,
transparent: true,
opacity: isRouteNode ? 0.94 : 0.55,
depthWrite: false,
flatShading: true
});
nodeMaterials.set(id, material);
const chamber = new THREE.Mesh(
new THREE.IcosahedronGeometry(isRouteNode ? 0.115 : 0.09, 0),
material
);
chamber.position.set(...coordinates);
chamber.castShadow = true;
chamber.renderOrder = 4;
block.group.add(chamber);
}
for (const [edgeIndex, edgeData] of block.def.edges.entries()) {
const [idA, idB] = edgeData;
const pointA = new THREE.Vector3(...block.def.nodes[idA]);
const pointB = new THREE.Vector3(...block.def.nodes[idB]);
const key = `${idA}->${idB}`;
const isRouteEdge = routeEdgeKeys.has(key);
let routeIndex = -1;
for (let i = 0; i < block.def.route.length - 1; i += 1) {
if (
block.def.route[i] === idA &&
block.def.route[i + 1] === idB
) {
routeIndex = i;
break;
}
}
const material = new THREE.MeshStandardMaterial({
color: channelBaseColor.clone(),
emissive: new THREE.Color(0x062832),
emissiveIntensity: 0.65,
roughness: 0.48,
metalness: 0.02,
transparent: true,
opacity: isRouteEdge ? 0.78 : 0.42,
depthWrite: false,
flatShading: true
});
const tube = cylinderBetween(
block.group,
pointA,
pointB,
isRouteEdge ? 0.062 : 0.052,
material,
6
);
tube.renderOrder = 3;
const arrowMaterial = new THREE.MeshBasicMaterial({
color: isRouteEdge ? 0x57eaff : 0x357b8a,
transparent: true,
opacity: isRouteEdge ? 0.72 : 0.34,
depthWrite: false
});
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.19, 5),
arrowMaterial
);
arrow.position.lerpVectors(pointA, pointB, 0.63);
arrow.quaternion.setFromUnitVectors(
Y_AXIS,
new THREE.Vector3().subVectors(pointB, pointA).normalize()
);
arrow.renderOrder = 5;
block.group.add(arrow);
block.edges.push({
key,
idA,
idB,
tube,
arrow,
material,
arrowMaterial,
isRouteEdge,
routeIndex,
visited: 0,
edgeIndex
});
}
}
function makeDashedRoute(group, points) {
const routeMaterial = new THREE.MeshStandardMaterial({
color: wormColor,
emissive: new THREE.Color(0x4c1607),
emissiveIntensity: 0.45,
roughness: 0.58,
metalness: 0,
flatShading: true
});
const dashLength = 0.17;
const gapLength = 0.085;
for (let segment = 0; segment < points.length - 1; segment += 1) {
const start = points[segment];
const end = points[segment + 1];
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const directionNormalized = direction.clone().normalize();
let cursor = 0;
while (cursor < length - 0.01) {
const dashEnd = Math.min(cursor + dashLength, length);
const dashStartPoint = start
.clone()
.addScaledVector(directionNormalized, cursor);
const dashEndPoint = start
.clone()
.addScaledVector(directionNormalized, dashEnd);
cylinderBetween(
group,
dashStartPoint,
dashEndPoint,
0.047,
routeMaterial,
6
);
cursor += dashLength + gapLength;
}
}
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xffb27d,
emissive: new THREE.Color(0x351006),
emissiveIntensity: 0.35,
roughness: 0.65,
flatShading: true
});
for (const point of points) {
const joint = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.068, 0),
jointMaterial
);
joint.position.copy(point);
group.add(joint);
}
}
function makeSurfaceWorm(group, x, z) {
const wormMaterial = new THREE.MeshStandardMaterial({
color: 0xe8885d,
emissive: new THREE.Color(0x2b0a04),
emissiveIntensity: 0.25,
roughness: 0.82,
flatShading: true
});
const points = [
new THREE.Vector3(x - 0.34, 0.37, z + 0.07),
new THREE.Vector3(x - 0.17, 0.42, z + 0.02),
new THREE.Vector3(x, 0.39, z - 0.02),
new THREE.Vector3(x + 0.17, 0.38, z)
];
for (let i = 0; i < points.length - 1; i += 1) {
cylinderBetween(
group,
points[i],
points[i + 1],
0.045,
wormMaterial,
6
);
}
for (let i = 0; i < points.length; i += 1) {
const segment = new THREE.Mesh(
new THREE.IcosahedronGeometry(i === 3 ? 0.084 : 0.066, 0),
wormMaterial
);
segment.position.copy(points[i]);
segment.castShadow = true;
group.add(segment);
}
}
function makeTracer(block) {
const group = new THREE.Group();
const core = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 10, 7),
new THREE.MeshStandardMaterial({
color: 0xc3fbff,
emissive: 0x22e6ff,
emissiveIntensity: 2.6,
roughness: 0.22,
metalness: 0.05,
flatShading: true
})
);
core.castShadow = true;
group.add(core);
const halo = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 10, 7),
new THREE.MeshBasicMaterial({
color: 0x52eaff,
transparent: true,
opacity: 0.2,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
group.add(halo);
const light = new THREE.PointLight(0x52eaff, 1.25, 1.25);
group.add(light);
block.group.add(group);
return {
group,
core,
halo
};
}
function addAnnotation(html, anchorFunction, className = "callout") {
const element = document.createElement("div");
element.className = `annotation ${className}`;
element.innerHTML = html;
annotations.appendChild(element);
annotationItems.push({
element,
anchorFunction
});
}
function addGapMarker(block, pointA, pointB) {
const midpoint = new THREE.Vector3()
.addVectors(pointA, pointB)
.multiplyScalar(0.5);
const size = 0.13;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
midpoint.x - size,
midpoint.y - size,
midpoint.z
),
new THREE.Vector3(
midpoint.x + size,
midpoint.y + size,
midpoint.z
),
new THREE.Vector3(
midpoint.x - size,
midpoint.y + size,
midpoint.z
),
new THREE.Vector3(
midpoint.x + size,
midpoint.y - size,
midpoint.z
)
]);
const marker = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0xd5e0e3,
transparent: true,
opacity: 0.75
})
);
block.group.add(marker);
}
const blockDefinitions = [
{
id: "A",
cx: -3.45,
route: [
"A0", "A1", "A2", "A3", "A4",
"A5", "A6", "A7", "A8", "A9"
],
nodes: {
A0: [-0.78, 0.30, 0.58],
A1: [-0.78, -0.28, 0.58],
A2: [-0.15, -0.72, 0.58],
A3: [0.55, -1.15, 0.58],
A4: [1.12, -1.85, 0.60],
A5: [0.65, -2.65, 0.62],
A6: [-0.28, -2.88, 0.64],
A7: [-1.02, -2.38, 0.62],
A8: [-1.45, -1.60, 0.60],
A9: [-1.35, -0.92, 0.58],
AB0: [0.98, -0.62, 0.58],
AB1: [0.28, -0.25, 0.58]
},
edges: [
["A0", "A1"],
["A1", "A2"],
["A2", "A3"],
["A3", "A4"],
["A4", "A5"],
["A5", "A6"],
["A6", "A7"],
["A7", "A8"],
["A8", "A9"],
["A3", "AB0"],
["AB0", "AB1"]
],
wormPath: [
[0.95, 0.31, 0.57],
[0.95, -0.30, 0.57],
[0.55, -0.72, 0.57],
[0.55, -1.15, 0.58]
],
wormX: 0.95,
title: `
<span class="eyebrow">GEOMETRY A</span>
<strong>Continuous declared edge chain</strong>
<small>worm overlay joins the chain at mid-depth</small>
`
},
{
id: "B",
cx: 3.45,
route: ["B0", "B1", "B2"],
nodes: {
B0: [-0.78, 0.30, 0.58],
B1: [-0.75, -0.42, 0.58],
B2: [-0.05, -0.95, 0.63],
B3: [0.72, -1.45, 0.63],
B4: [1.15, -2.10, 0.63],
B5: [0.58, -2.78, 0.64],
B6: [-0.28, -2.92, 0.62],
B7: [-0.95, -2.35, 0.61]
},
edges: [
["B0", "B1"],
["B1", "B2"],
["B3", "B4"],
["B4", "B5"],
["B5", "B6"],
["B6", "B7"]
],
wormPath: [
[0.85, 0.31, 0.58],
[0.85, -0.30, 0.58],
[0.35, -0.78, 0.60],
[-0.05, -0.95, 0.63]
],
wormX: 0.85,
title: `
<span class="eyebrow">GEOMETRY B</span>
<strong>Interrupted declared graph</strong>
<small>upper and lower clusters are not edge-linked</small>
`
}
];
for (const definition of blockDefinitions) {
const block = {
id: definition.id,
def: definition,
group: makeSoilBlock(definition),
edges: []
};
makeChannelNetwork(block);
const wormGroup = new THREE.Group();
block.group.add(wormGroup);
wormGroups.push(wormGroup);
makeDashedRoute(
wormGroup,
definition.wormPath.map((point) => new THREE.Vector3(...point))
);
makeSurfaceWorm(wormGroup, definition.wormX, 0.62);
block.tracer = makeTracer(block);
blocks.push(block);
addAnnotation(
definition.title,
() =>
block.group.localToWorld(
new THREE.Vector3(0, 0.68, 0.30)
),
"block-title"
);
const wormAnchor =
definition.id === "A"
? new THREE.Vector3(1.08, -0.42, 0.70)
: new THREE.Vector3(1.00, -0.36, 0.70);
addAnnotation(
"Illustrative worm access",
() => block.group.localToWorld(wormAnchor.clone()),
"callout worm"
);
if (definition.id === "B") {
addGapMarker(
block,
new THREE.Vector3(...definition.nodes.B2),
new THREE.Vector3(...definition.nodes.B3)
);
addAnnotation(
"No declared edge",
() =>
block.group.localToWorld(
new THREE.Vector3(0.34, -1.20, 0.74)
),
"callout gap"
);
}
}
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const wormToggle = document.getElementById("wormToggle");
const speedSelect = document.getElementById("speedSelect");
const statusA = document.getElementById("statusA");
const statusB = document.getElementById("statusB");
const barA = document.getElementById("barA");
const barB = document.getElementById("barB");
const edgeDuration = 1.25;
const state = {
running: true,
time: 0,
speed: 1
};
function setStatus(element, text) {
if (element.textContent !== text) {
element.textContent = text;
}
}
function updatePlayButton() {
playButton.textContent = state.running ? "Pause walk" : "Play walk";
playButton.setAttribute("aria-pressed", String(state.running));
}
function resetWalk() {
state.time = 0;
state.running = true;
updatePlayButton();
}
playButton.addEventListener("click", () => {
state.running = !state.running;
updatePlayButton();
});
resetButton.addEventListener("click", resetWalk);
speedSelect.addEventListener("change", () => {
state.speed = Number(speedSelect.value);
});
wormToggle.addEventListener("change", () => {
for (const group of wormGroups) {
group.visible = wormToggle.checked;
}
});
window.addEventListener("keydown", (event) => {
const activeElement = document.activeElement;
if (
activeElement &&
["INPUT", "SELECT", "BUTTON", "TEXTAREA"].includes(activeElement.tagName)
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
state.running = !state.running;
updatePlayButton();
}
if (event.key.toLowerCase() === "r") {
resetWalk();
}
});
function getRouteState(block) {
const edgeCount = block.def.route.length - 1;
const totalDuration = edgeCount * edgeDuration;
if (state.time <= 0) {
return {
edgeCount,
totalDuration,
complete: false,
edgeIndex: 0,
fraction: 0,
position: new THREE.Vector3(...block.def.nodes[block.def.route[0]])
};
}
if (state.time >= totalDuration) {
return {
edgeCount,
totalDuration,
complete: true,
edgeIndex: edgeCount - 1,
fraction: 1,
position: new THREE.Vector3(
...block.def.nodes[block.def.route[edgeCount]]
)
};
}
const edgeIndex = Math.min(
edgeCount - 1,
Math.floor(state.time / edgeDuration)
);
const fraction =
(state.time - edgeIndex * edgeDuration) / edgeDuration;
const start = new THREE.Vector3(
...block.def.nodes[block.def.route[edgeIndex]]
);
const end = new THREE.Vector3(
...block.def.nodes[block.def.route[edgeIndex + 1]]
);
return {
edgeCount,
totalDuration,
complete: false,
edgeIndex,
fraction,
position: start.lerp(end, fraction)
};
}
function updateBlock(block, animationTime) {
const routeState = getRouteState(block);
block.tracer.group.position.copy(routeState.position);
const pulse = 1 + Math.sin(animationTime * 5.5) * 0.12;
block.tracer.halo.scale.setScalar(pulse);
block.tracer.halo.material.opacity =
0.17 + (Math.sin(animationTime * 4.5) + 1) * 0.055;
for (const edge of block.edges) {
let visited = 0;
if (edge.routeIndex >= 0) {
const edgeStart = edge.routeIndex * edgeDuration;
const edgeEnd = edgeStart + edgeDuration;
if (state.time >= edgeEnd) {
visited = 1;
} else if (state.time > edgeStart) {
visited = (state.time - edgeStart) / edgeDuration;
}
}
edge.visited = visited;
edge.material.color
.copy(channelBaseColor)
.lerp(channelBrightColor, visited);
edge.material.emissiveIntensity =
0.45 + visited * 1.25;
edge.material.opacity = edge.isRouteEdge
? 0.72 + visited * 0.28
: 0.40;
edge.arrowMaterial.opacity = edge.isRouteEdge
? 0.48 + visited * 0.48
: 0.31;
}
const progress = Math.min(
1,
state.time / routeState.totalDuration
);
return { routeState, progress };
}
function updateReadouts() {
const a = updateBlock(blocks[0], state.time);
const b = updateBlock(blocks[1], state.time);
barA.style.width = `${a.progress * 100}%`;
barB.style.width = `${b.progress * 100}%`;
if (state.time <= 0) {
setStatus(
statusA,
"At surface inlet · scripted walk ready"
);
setStatus(
statusB,
"At surface inlet · scripted walk ready"
);
return;
}
if (a.routeState.complete) {
setStatus(
statusA,
"Lower terminal reached · 9 of 9 declared edges"
);
} else {
setStatus(
statusA,
`Walking declared edge ${a.routeState.edgeIndex + 1} of ${a.routeState.edgeCount}`
);
}
if (b.routeState.complete) {
setStatus(
statusB,
"Stopped at upper terminal · no onward declared edge"
);
} else {
setStatus(
statusB,
`Walking declared edge ${b.routeState.edgeIndex + 1} of ${b.routeState.edgeCount}`
);
}
}
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of annotationItems) {
const projected = item.anchorFunction().project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
item.element.style.display = visible ? "block" : "none";
if (!visible) {
continue;
}
item.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
item.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// Direct camera controls: no examples or addons are used.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) {
return;
}
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) {
return;
}
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.55,
1.48
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("lostpointercapture", () => {
dragging = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.75
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.running) {
state.time += delta * state.speed;
}
updateReadouts();
renderer.render(scene, camera);
updateAnnotations();
}
resize();
resetCamera();
updatePlayButton();
updateReadouts();
updateCamera();
loading.remove();
animate();
</script>
</body>
</html>
```