Prompt specification
Build or customize the Three.js 3D scene "Forest-floor partnership cutaway" 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: Forest-floor partnership cutaway
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/forest-floor-partnership-cutaway-x0759
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows mycorrhizal resource exchange. Build soil beneath two plants with roots, fungal filaments, litter, and mineral particles; show selected associations clearly without implying that every plant joins one intelligent network. Stylized solid forms.
Working Three.js Starter (forest-floor-partnership-cutaway-x0759):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mycorrhizal Resource Exchange</title>
<style>
:root {
--ink: #283229;
--muted: #657064;
--paper: #f5f0e5;
--root: #c98d59;
--am: #23a89f;
--ecm: #7865c6;
--carbon: #eea13b;
--nutrient: #2d9ddd;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e3d7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#scene canvas:focus-visible {
outline: 3px solid rgba(45, 157, 221, 0.7);
outline-offset: -4px;
}
.wash {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 45%, rgba(74, 61, 45, 0.07)),
linear-gradient(to bottom, rgba(255,255,255,0.1), transparent 28%);
}
.intro {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
width: min(440px, calc(100vw - 420px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #697466;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 430px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3.5vw, 49px);
font-weight: 600;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro p {
max-width: 390px;
margin: 13px 0 0;
color: #566056;
font-size: 14px;
line-height: 1.5;
}
.info-card {
position: fixed;
top: 24px;
right: 24px;
z-index: 6;
width: 338px;
max-height: calc(100vh - 112px);
overflow: auto;
padding: 19px;
border: 1px solid rgba(78, 72, 59, 0.16);
border-radius: 17px;
background: rgba(255, 253, 247, 0.9);
box-shadow: 0 16px 46px rgba(56, 44, 31, 0.14);
backdrop-filter: blur(16px);
}
.info-card h2 {
margin: 0 0 13px;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
line-height: 1.05;
}
.flow-row {
display: flex;
align-items: center;
gap: 11px;
padding: 10px 0;
border-top: 1px solid rgba(78, 72, 59, 0.1);
}
.flow-row b,
.flow-row small {
display: block;
}
.flow-row b {
font-size: 13px;
}
.flow-row small {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.flow-icon {
position: relative;
flex: 0 0 auto;
width: 25px;
height: 25px;
}
.flow-icon::after {
position: absolute;
top: 50%;
right: -13px;
width: 10px;
height: 1px;
background: currentColor;
content: "";
}
.flow-icon::before {
position: absolute;
top: calc(50% - 3px);
right: -13px;
width: 6px;
height: 6px;
border-top: 1px solid currentColor;
border-right: 1px solid currentColor;
content: "";
transform: rotate(45deg);
}
.flow-icon.carbon {
color: var(--carbon);
}
.flow-icon.carbon::before {
width: 13px;
height: 13px;
border: 0;
border-radius: 3px;
background: currentColor;
transform: rotate(45deg);
}
.flow-icon.nutrient {
color: var(--nutrient);
}
.flow-icon.nutrient::before {
width: 13px;
height: 13px;
border: 0;
border-radius: 50%;
background: currentColor;
}
.type-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.type {
padding: 10px;
border: 1px solid rgba(78, 72, 59, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.45);
}
.type-title {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 5px;
font-size: 12px;
}
.type small {
display: block;
color: var(--muted);
font-size: 10.5px;
line-height: 1.35;
}
.swatch {
display: inline-block;
flex: 0 0 auto;
width: 11px;
height: 11px;
border-radius: 50%;
}
.swatch.am {
background: var(--am);
}
.swatch.ecm {
background: var(--ecm);
}
.scope {
margin: 14px 0;
padding: 11px 12px;
border-left: 3px solid #8b8d73;
border-radius: 0 8px 8px 0;
background: rgba(125, 127, 100, 0.09);
color: #555b50;
font-size: 11.5px;
line-height: 1.45;
}
.scope b {
color: #343b32;
}
.toggle {
display: flex;
align-items: center;
gap: 9px;
color: #4d574c;
font-size: 12px;
cursor: pointer;
user-select: none;
}
.toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.track {
position: relative;
width: 34px;
height: 19px;
border-radius: 20px;
background: #c7c8bc;
transition: background 160ms ease;
}
.track::after {
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 4px rgba(0,0,0,0.2);
content: "";
transition: transform 160ms ease;
}
.toggle input:checked + .track {
background: var(--nutrient);
}
.toggle input:checked + .track::after {
transform: translateX(15px);
}
.toggle input:focus-visible + .track {
outline: 2px solid var(--nutrient);
outline-offset: 2px;
}
.legend {
position: fixed;
left: 24px;
bottom: 23px;
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
max-width: min(720px, calc(100vw - 310px));
padding: 10px 13px;
border: 1px solid rgba(78, 72, 59, 0.12);
border-radius: 12px;
background: rgba(255, 253, 247, 0.78);
box-shadow: 0 8px 25px rgba(56, 44, 31, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #4e584d;
font-size: 10.5px;
font-weight: 650;
white-space: nowrap;
}
.key {
display: inline-block;
width: 15px;
height: 8px;
border-radius: 5px;
}
.key.root {
height: 4px;
background: var(--root);
}
.key.am {
background: var(--am);
}
.key.ecm {
background: var(--ecm);
}
.key.mineral {
width: 8px;
height: 8px;
border-radius: 2px;
background: linear-gradient(135deg, #66c1e7 50%, #d9ae58 50%);
transform: rotate(45deg);
}
.key.litter {
width: 13px;
height: 8px;
border-radius: 80% 20% 70% 30%;
background: #a46b3e;
transform: rotate(-18deg);
}
.key.carbon {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--carbon);
transform: rotate(45deg);
}
.key.nutrient {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--nutrient);
}
.controls {
position: fixed;
right: 24px;
bottom: 23px;
z-index: 6;
display: flex;
align-items: center;
gap: 12px;
color: #596257;
font-size: 10.5px;
}
.controls span {
padding: 8px 10px;
border-radius: 9px;
background: rgba(255, 253, 247, 0.72);
}
.reset {
padding: 9px 12px;
border: 1px solid rgba(78, 72, 59, 0.18);
border-radius: 9px;
background: rgba(255, 253, 247, 0.9);
color: #354035;
font-size: 11px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 6px 18px rgba(56, 44, 31, 0.08);
}
.reset:hover {
background: white;
}
.reset:focus-visible {
outline: 2px solid var(--nutrient);
outline-offset: 2px;
}
#tag-layer {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.scene-tag {
position: absolute;
left: 0;
top: 0;
padding: 7px 10px;
border: 1px solid rgba(78, 72, 59, 0.15);
border-radius: 9px;
background: rgba(255, 253, 247, 0.88);
box-shadow: 0 5px 18px rgba(56, 44, 31, 0.1);
opacity: 0;
transition: opacity 180ms ease;
backdrop-filter: blur(8px);
}
.scene-tag.visible {
opacity: 1;
}
.scene-tag strong,
.scene-tag span {
display: block;
white-space: nowrap;
}
.scene-tag strong {
color: #354036;
font-size: 10.5px;
letter-spacing: 0.025em;
}
.scene-tag span {
margin-top: 2px;
color: #70786d;
font-size: 9px;
}
.plant-tag {
transform: translate(-50%, -125%);
}
.plant-tag strong {
font-size: 11px;
}
.root-tag {
transform: translate(-50%, 17px);
}
.root-tag::before {
position: absolute;
top: -18px;
left: 50%;
width: 1px;
height: 18px;
background: currentColor;
content: "";
opacity: 0.5;
}
.root-tag.am {
color: var(--am);
}
.root-tag.ecm {
color: var(--ecm);
}
.root-tag strong,
.root-tag span {
color: #354036;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8e3d7;
color: #5f695d;
font-size: 13px;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 820px) {
.intro {
top: 13px;
left: 14px;
width: calc(100vw - 28px);
}
.intro p {
display: none;
}
h1 {
max-width: 310px;
font-size: 29px;
}
.info-card {
top: auto;
right: 12px;
bottom: 62px;
left: 12px;
width: auto;
max-height: 35vh;
padding: 13px;
}
.info-card h2 {
margin-bottom: 7px;
font-size: 19px;
}
.type-grid,
.scope {
display: none;
}
.flow-row {
padding: 7px 0;
}
.legend {
display: none;
}
.controls {
right: 12px;
bottom: 13px;
}
.controls span {
display: none;
}
.root-tag {
display: none !important;
}
.scene-tag {
padding: 5px 8px;
}
.scene-tag span {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="wash"></div>
<header class="intro">
<div class="eyebrow">Soil biology · interactive cutaway</div>
<h1>Mycorrhizal resource exchange</h1>
<p>
Two selected plant–fungus partnerships, shown as local exchanges beneath
the soil line.
</p>
</header>
<aside class="info-card">
<div class="eyebrow">A two-way partnership</div>
<h2>Resources move locally</h2>
<div class="flow-row carbon">
<span class="flow-icon carbon"></span>
<div>
<b>Plant root → fungus</b>
<small>Photosynthetically produced sugars and lipids</small>
</div>
</div>
<div class="flow-row nutrient">
<span class="flow-icon nutrient"></span>
<div>
<b>Fungus → plant root</b>
<small>Mineral nutrients and water, especially phosphorus</small>
</div>
</div>
<div class="type-grid">
<div class="type">
<div class="type-title">
<span class="swatch am"></span>
<b>Plant A · AM</b>
</div>
<small>Fine hyphae explore small soil pores near one selected root.</small>
</div>
<div class="type">
<div class="type-title">
<span class="swatch ecm"></span>
<b>Plant B · ECM</b>
</div>
<small>A fungal mantle and Hartig-style net surround selected fine roots.</small>
</div>
</div>
<div class="scope">
<b>Scope:</b> Only the colored root sections are shown as associated.
The two local fungal patches deliberately do not connect the plants.
This is not a universal plant network or a plant “intelligence” system.
</div>
<label class="toggle">
<input id="exchange-toggle" type="checkbox" checked>
<span class="track"></span>
<span>Show exchange arrows</span>
</label>
</aside>
<div class="legend" aria-label="Scene legend">
<span class="legend-item"><i class="key root"></i>Roots</span>
<span class="legend-item"><i class="key am"></i>AM filaments</span>
<span class="legend-item"><i class="key ecm"></i>ECM mantle / net</span>
<span class="legend-item"><i class="key mineral"></i>Mineral particles</span>
<span class="legend-item"><i class="key litter"></i>Leaf litter</span>
<span class="legend-item"><i class="key carbon"></i>Plant carbon</span>
<span class="legend-item"><i class="key nutrient"></i>Mineral nutrients</span>
</div>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button class="reset" id="reset-view" type="button">Reset view</button>
</div>
<div id="tag-layer" aria-hidden="true">
<div class="scene-tag plant-tag" id="tag-plant-a">
<strong>Plant A</strong>
<span>photosynthetic carbon source</span>
</div>
<div class="scene-tag plant-tag" id="tag-plant-b">
<strong>Plant B</strong>
<span>photosynthetic carbon source</span>
</div>
<div class="scene-tag root-tag am" id="tag-am">
<strong>Selected local AM partnership</strong>
<span>Fine fungal filaments contact one root branch</span>
</div>
<div class="scene-tag root-tag ecm" id="tag-ecm">
<strong>Selected local ECM partnership</strong>
<span>Fungal mantle and root net on selected fine roots</span>
</div>
</div>
<div id="loading">Loading the soil cutaway…</div>
<p class="sr-only">
A stylized cutaway shows two separate plants, their branching roots,
distinct local fungal partnerships, leaf litter, crystalline mineral
particles, and two-way resource exchange arrows.
</p>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e8e3d7");
scene.fog = new THREE.Fog("#e8e3d7", 32, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional cutaway of mycorrhizal resource exchange"
);
host.appendChild(renderer.domElement);
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const V3 = THREE.Vector3;
const Y_AXIS = new V3(0, 1, 0);
const Z_AXIS = new V3(0, 0, 1);
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...extra
});
}
const materials = {
soilTop: standard("#6e4935"),
soilUpper: standard("#79513a"),
soilMid: standard("#654331"),
soilDeep: standard("#51362b"),
soilSide: standard("#5b3b2d"),
floor: standard("#d7d0c1"),
root: standard("#b77c4d"),
rootSelected: standard("#d6a16b"),
stem: standard("#476d37"),
leafA: standard("#3f7b43", { roughness: 0.78 }),
leafA2: standard("#60964c", { roughness: 0.78 }),
leafB: standard("#347054", { roughness: 0.78 }),
leafB2: standard("#4e8954", { roughness: 0.78 }),
am: standard("#22a99e", {
emissive: "#0d3e39",
emissiveIntensity: 0.16
}),
ecm: standard("#7865c6", {
emissive: "#281f51",
emissiveIntensity: 0.16
}),
twig: standard("#69452f"),
litter1: standard("#a66c3e"),
litter2: standard("#bd8247"),
litter3: standard("#80583a")
};
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(width, height, depth, x, y, z, material, parent = scene) {
const mesh = addMesh(
new THREE.BoxGeometry(width, height, depth),
material,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function cylinderBetween(a, b, radiusA, radiusB, material, parent = scene, segments = 8) {
const direction = b.clone().sub(a);
const length = direction.length();
if (length < 0.001) return null;
const geometry = new THREE.CylinderGeometry(
radiusB,
radiusA,
length,
segments,
1,
false
);
const mesh = addMesh(geometry, material, parent);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
return mesh;
}
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(81472);
// Lighting: broad key, soft hemisphere, and a cool fill.
scene.add(new THREE.HemisphereLight("#fff8e7", "#684635", 2.15));
const keyLight = new THREE.DirectionalLight("#fff2d5", 3.15);
keyLight.position.set(-8, 14, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#b8d6e5", 1.05);
fillLight.position.set(9, 7, 5);
scene.add(fillLight);
// Ground and open-front soil block.
const floor = addMesh(
new THREE.PlaneGeometry(80, 80),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -7.18;
floor.castShadow = false;
box(18, 0.48, 8, 0, -0.24, 0, materials.soilTop);
box(18, 7, 0.52, 0, -3.5, -3.76, materials.soilSide);
box(0.52, 7, 8, -8.76, -3.5, 0, materials.soilSide);
box(0.52, 7, 8, 8.76, -3.5, 0, materials.soilSide);
box(18, 0.42, 8, 0, -6.8, 0, materials.soilDeep);
// Visible strata on the rear cutaway wall.
box(17.5, 2.05, 0.09, 0, -1.02, -3.46, materials.soilUpper);
box(17.5, 2.35, 0.10, 0, -3.22, -3.45, materials.soilMid);
box(17.5, 2.42, 0.11, 0, -5.62, -3.44, materials.soilDeep);
const moundGeometry = new THREE.IcosahedronGeometry(1, 1);
const moundMaterial = standard("#72503a");
function addMound(x, z, sx, sy, sz) {
const mound = addMesh(moundGeometry, moundMaterial);
mound.position.set(x, -0.02, z);
mound.scale.set(sx, sy, sz);
mound.rotation.y = random() * Math.PI;
return mound;
}
addMound(-4.4, 0.1, 1.15, 0.22, 0.78);
addMound(4.4, 0.0, 1.05, 0.24, 0.72);
addMound(-6.5, -1.4, 0.8, 0.13, 0.55);
addMound(2.6, -1.7, 0.68, 0.11, 0.45);
addMound(6.7, 1.2, 0.75, 0.12, 0.5);
// Soil aggregates and faceted mineral particles.
const aggregateGeometry = new THREE.IcosahedronGeometry(0.13, 0);
const aggregateMaterial = standard("#6f4b36");
const aggregateCount = 145;
const aggregates = new THREE.InstancedMesh(
aggregateGeometry,
aggregateMaterial,
aggregateCount
);
aggregates.receiveShadow = true;
const dummy = new THREE.Object3D();
const aggregateColors = ["#76523a", "#674431", "#825a3e"];
for (let i = 0; i < aggregateCount; i++) {
dummy.position.set(
-8.25 + random() * 16.5,
-6.35 + random() * 5.8,
-3.05 + random() * 6.0
);
dummy.rotation.set(random() * 3, random() * 3, random() * 3);
const size = 0.48 + random() * 1.45;
dummy.scale.set(size, size * 0.7, size);
dummy.updateMatrix();
aggregates.setMatrixAt(i, dummy.matrix);
aggregates.setColorAt(
i,
new THREE.Color(aggregateColors[i % aggregateColors.length])
);
}
aggregates.instanceMatrix.needsUpdate = true;
if (aggregates.instanceColor) aggregates.instanceColor.needsUpdate = true;
scene.add(aggregates);
const mineralGeometry = new THREE.OctahedronGeometry(0.095, 0);
const mineralMaterial = standard("#ffffff", { roughness: 0.62 });
const mineralCount = 120;
const minerals = new THREE.InstancedMesh(
mineralGeometry,
mineralMaterial,
mineralCount
);
const mineralColors = ["#69bce0", "#78c9e7", "#e0b45e", "#c7d7d5"];
for (let i = 0; i < mineralCount; i++) {
dummy.position.set(
-8.1 + random() * 16.2,
-6.25 + random() * 5.7,
-3.0 + random() * 5.95
);
dummy.rotation.set(random() * 3, random() * 3, random() * 3);
const size = 0.55 + random() * 1.25;
dummy.scale.set(size, size, size);
dummy.updateMatrix();
minerals.setMatrixAt(i, dummy.matrix);
minerals.setColorAt(
i,
new THREE.Color(mineralColors[i % mineralColors.length])
);
}
minerals.instanceMatrix.needsUpdate = true;
if (minerals.instanceColor) minerals.instanceColor.needsUpdate = true;
scene.add(minerals);
// Leaf litter on the soil surface.
const litterShape = new THREE.Shape();
litterShape.moveTo(0, -0.62);
litterShape.bezierCurveTo(-0.53, -0.22, -0.42, 0.45, 0, 0.72);
litterShape.bezierCurveTo(0.42, 0.45, 0.53, -0.22, 0, -0.62);
const litterGeometry = new THREE.ExtrudeGeometry(litterShape, {
depth: 0.065,
bevelEnabled: true,
bevelSegments: 1,
steps: 1,
bevelSize: 0.025,
bevelThickness: 0.025
});
function addLitterLeaf(x, z, angle, material, scale) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.06, z);
pivot.rotation.y = angle;
pivot.scale.setScalar(scale);
scene.add(pivot);
const leaf = addMesh(litterGeometry, material, pivot);
leaf.rotation.x = -Math.PI / 2;
leaf.position.y = 0.015;
const midrib = addMesh(
new THREE.CylinderGeometry(0.018, 0.012, 1.26, 6),
materials.twig,
pivot
);
midrib.rotation.x = Math.PI / 2;
midrib.position.set(0, 0.13, 0.04);
return pivot;
}
addLitterLeaf(-6.8, 1.3, 0.45, materials.litter1, 0.88);
addLitterLeaf(-2.1, 2.3, -0.8, materials.litter2, 0.68);
addLitterLeaf(2.7, 1.9, 1.0, materials.litter3, 0.82);
addLitterLeaf(6.9, -0.7, 2.1, materials.litter1, 0.76);
addLitterLeaf(-7.7, -1.9, -1.7, materials.litter3, 0.58);
cylinderBetween(
new V3(-6.8, 0.12, -0.6),
new V3(-5.55, 0.12, -0.15),
0.055,
0.032,
materials.twig
);
cylinderBetween(
new V3(5.9, 0.12, 2.3),
new V3(7.3, 0.12, 2.65),
0.06,
0.035,
materials.twig
);
// Root systems remain separate: no plant-to-plant fungal bridge.
const rootGroup = new THREE.Group();
const fungiGroup = new THREE.Group();
scene.add(rootGroup, fungiGroup);
function buildRootNetwork(x, seed, spread) {
const rng = mulberry32(seed);
const group = new THREE.Group();
function grow(start, direction, length, radius, depth) {
const end = start.clone().addScaledVector(direction, length);
end.y = Math.max(end.y, -6.28);
end.x = THREE.MathUtils.clamp(end.x, x - spread, x + spread);
end.z = THREE.MathUtils.clamp(end.z, -2.8, 2.7);
const actualLength = start.distanceTo(end);
if (actualLength < 0.1) return;
cylinderBetween(
start,
end,
radius,
Math.max(radius * 0.68, 0.016),
materials.root,
group
);
if (depth <= 0) return;
const count = depth >= 3 ? 2 : (rng() > 0.48 ? 2 : 1);
for (let i = 0; i < count; i++) {
const origin = start.clone().lerp(end, 0.48 + rng() * 0.38);
const nextDirection = new V3(
(rng() - 0.5) * 1.25,
-0.42 - rng() * 0.4,
(rng() - 0.5) * 0.95
).normalize();
grow(
origin,
nextDirection,
length * (0.59 + rng() * 0.14),
radius * 0.65,
depth - 1
);
}
}
grow(
new V3(x, -0.05, 0.62),
new V3(0.045, -1, 0.025).normalize(),
3.0,
0.14,
4
);
rootGroup.add(group);
}
buildRootNetwork(-4.4, 111, 2.85);
buildRootNetwork(4.4, 222, 2.85);
function makeRootPath(points, parent = rootGroup) {
for (let i = 0; i < points.length - 1; i++) {
const radius = 0.13 - i * 0.019;
cylinderBetween(
points[i],
points[i + 1],
radius,
Math.max(radius - 0.022, 0.035),
materials.rootSelected,
parent
);
}
}
function addHypha(points, material = materials.am, radius = 0.031) {
const curve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.45);
const mesh = addMesh(
new THREE.TubeGeometry(
curve,
Math.max(14, points.length * 8),
radius,
6,
false
),
material,
fungiGroup
);
return { mesh, curve };
}
const contactGeometry = new THREE.SphereGeometry(1, 9, 7);
function addContact(point, material, size = 0.077) {
const contact = addMesh(contactGeometry, material, fungiGroup);
contact.position.copy(point);
contact.scale.setScalar(size);
return contact;
}
// Selected AM-associated root on Plant A.
const amRootPoints = [
new V3(-4.4, -0.08, 1.25),
new V3(-4.67, -1.12, 1.39),
new V3(-4.05, -2.04, 1.53),
new V3(-3.25, -2.74, 1.67),
new V3(-2.55, -3.23, 1.67)
];
makeRootPath(amRootPoints);
const amRootCurve = new THREE.CatmullRomCurve3(
amRootPoints,
false,
"catmullrom",
0.45
);
const amContacts = [0.17, 0.33, 0.49, 0.65, 0.81].map(t =>
amRootCurve.getPoint(t)
);
const amRng = mulberry32(909);
for (const contact of amContacts) {
const middle = contact.clone().add(
new V3(
-0.25 + amRng() * 0.45,
-0.10 + amRng() * 0.20,
(amRng() - 0.5) * 0.62
)
);
const end = middle.clone().add(
new V3(
-0.65 + amRng() * 0.65,
-0.25 - amRng() * 0.34,
(amRng() - 0.5) * 0.82
)
);
addHypha([contact, middle, end], materials.am, 0.033);
const branchMiddle = middle.clone().add(
new V3(
(amRng() - 0.5) * 0.55,
-0.11,
(amRng() - 0.5) * 0.55
)
);
const branchEnd = branchMiddle.clone().add(
new V3(
-0.30 + amRng() * 0.48,
-0.28 - amRng() * 0.22,
(amRng() - 0.5) * 0.70
)
);
addHypha([middle, branchMiddle, branchEnd], materials.am, 0.025);
addContact(contact, materials.am, 0.072);
}
// A few interconnected hyphae make the AM patch visibly local.
for (let i = 0; i < 6; i++) {
const t = 0.1 + i * 0.12;
const p = amRootCurve.getPoint(t).add(
new V3(-0.30, 0.10 + amRng() * 0.18, (amRng() - 0.5) * 0.52)
);
const q = amRootCurve.getPoint(Math.min(0.96, t + 0.15)).add(
new V3(-0.68, 0.02, (amRng() - 0.5) * 0.62)
);
const mid = p.clone().lerp(q, 0.52).add(
new V3(-0.10, -0.18 + amRng() * 0.22, (amRng() - 0.5) * 0.40)
);
addHypha([p, mid, q], materials.am, 0.026);
}
// Selected ECM-associated fine root on Plant B.
const ecmRootPoints = [
new V3(4.4, -0.08, 1.22),
new V3(4.65, -1.06, 1.38),
new V3(4.17, -1.96, 1.53),
new V3(4.88, -2.72, 1.66),
new V3(5.72, -3.25, 1.69)
];
makeRootPath(ecmRootPoints);
const ecmRootCurve = new THREE.CatmullRomCurve3(
ecmRootPoints,
false,
"catmullrom",
0.45
);
// Longitudinal strands suggest the Hartig net around the fine root.
const netOffsets = [
new V3(0.105, 0, 0),
new V3(-0.105, 0, 0),
new V3(0, 0, 0.105),
new V3(0, 0, -0.105)
];
for (const offset of netOffsets) {
const strandPoints = ecmRootPoints.map(p => p.clone().add(offset));
addHypha(strandPoints, materials.ecm, 0.018);
}
// Rungs make the fine root's fungal net more legible.
for (const t of [0.18, 0.34, 0.5, 0.66, 0.8]) {
const point = ecmRootCurve.getPoint(t);
const tangent = ecmRootCurve.getTangent(t).normalize();
const ring = addMesh(
new THREE.TorusGeometry(0.125, 0.018, 6, 18),
materials.ecm,
fungiGroup
);
ring.position.copy(point);
ring.quaternion.setFromUnitVectors(Z_AXIS, tangent);
}
// The distal fungal mantle encloses a selected section of root.
const mantlePoints = ecmRootPoints.slice(2).map(p => p.clone());
const mantleCurve = new THREE.CatmullRomCurve3(
mantlePoints,
false,
"catmullrom",
0.35
);
addMesh(
new THREE.TubeGeometry(mantleCurve, 34, 0.12, 8, false),
materials.ecm,
fungiGroup
);
const ecmRng = mulberry32(1212);
for (const t of [0.5, 0.59, 0.68, 0.77, 0.86, 0.95]) {
const contact = ecmRootCurve.getPoint(t);
const middle = contact.clone().add(
new V3(
0.28 + ecmRng() * 0.36,
-0.12 + ecmRng() * 0.20,
(ecmRng() - 0.5) * 0.60
)
);
const end = middle.clone().add(
new V3(
0.65 + ecmRng() * 0.62,
-0.25 - ecmRng() * 0.35,
(ecmRng() - 0.5) * 0.82
)
);
addHypha([contact, middle, end], materials.ecm, 0.033);
addContact(contact, materials.ecm, 0.075);
const branchMiddle = middle.clone().add(
new V3(
(ecmRng() - 0.5) * 0.50,
-0.13,
(ecmRng() - 0.5) * 0.52
)
);
const branchEnd = branchMiddle.clone().add(
new V3(
0.30 + ecmRng() * 0.50,
-0.25 - ecmRng() * 0.25,
(ecmRng() - 0.5) * 0.70
)
);
addHypha([middle, branchMiddle, branchEnd], materials.ecm, 0.025);
}
// Stylized solid plants with broad, faceted leaves.
const leafGeometry = new THREE.SphereGeometry(1, 12, 8);
function addLeaf(parent, base, direction, length, width, material) {
const leaf = addMesh(leafGeometry, material, parent);
const normalized = direction.clone().normalize();
leaf.scale.set(width, length, 0.15);
leaf.quaternion.setFromUnitVectors(Y_AXIS, normalized);
leaf.position.copy(base).addScaledVector(normalized, length * 0.80);
return leaf;
}
function createPlant(x, height, seed, leafMaterials) {
const rng = mulberry32(seed);
const plant = new THREE.Group();
plant.position.x = x;
scene.add(plant);
const canopy = new THREE.Group();
plant.add(canopy);
const stemCurve = new THREE.CatmullRomCurve3([
new V3(0, 0, 0),
new V3(0.07, height * 0.22, 0),
new V3(-0.10, height * 0.43, 0.015),
new V3(0.09, height * 0.66, -0.015),
new V3(-0.04, height * 0.86, 0),
new V3(0, height, 0)
]);
addMesh(
new THREE.TubeGeometry(stemCurve, 34, 0.105, 8, false),
materials.stem,
canopy
);
const crown = addMesh(contactGeometry, materials.rootSelected, rootGroup);
crown.position.set(x, -0.01, 0.57);
crown.scale.set(0.22, 0.17, 0.20);
for (let i = 0; i < 7; i++) {
const t = 0.25 + i * 0.092;
const base = stemCurve.getPoint(t);
const side = i % 2 === 0 ? 1 : -1;
const branchDirection = new V3(
side * (0.72 + rng() * 0.26),
0.30 + rng() * 0.22,
(rng() - 0.5) * 0.38
).normalize();
const branchEnd = base.clone().addScaledVector(
branchDirection,
0.72 + rng() * 0.28
);
cylinderBetween(
base,
branchEnd,
0.052,
0.024,
materials.stem,
canopy
);
const leafDirection = new V3(
side * (0.72 + rng() * 0.20),
0.46 + rng() * 0.20,
(rng() - 0.5) * 0.46
).normalize();
addLeaf(
canopy,
branchEnd,
leafDirection,
0.70 + rng() * 0.19,
0.28 + rng() * 0.08,
leafMaterials[i % leafMaterials.length]
);
const secondDirection = new V3(
side * 0.9,
0.06 + rng() * 0.18,
(rng() - 0.5) * 0.62
).normalize();
addLeaf(
canopy,
branchEnd.clone().add(new V3(0, 0.04, 0)),
secondDirection,
0.61 + rng() * 0.18,
0.25 + rng() * 0.07,
leafMaterials[(i + 1) % leafMaterials.length]
);
}
const top = stemCurve.getPoint(1);
addLeaf(
canopy,
top,
new V3(-0.55, 0.78, 0.22),
0.73,
0.30,
leafMaterials[0]
);
addLeaf(
canopy,
top,
new V3(0.58, 0.74, 0.12),
0.76,
0.31,
leafMaterials[1]
);
addLeaf(
canopy,
top,
new V3(0.08, 0.92, -0.36),
0.70,
0.29,
leafMaterials[0]
);
return { plant, canopy, height };
}
const plantA = createPlant(
-4.4,
4.85,
33,
[materials.leafA, materials.leafA2]
);
const plantB = createPlant(
4.4,
5.55,
77,
[materials.leafB, materials.leafB2]
);
// Bidirectional exchange arrows remain inside each local fungal patch.
const exchangeGroup = new THREE.Group();
scene.add(exchangeGroup);
const exchangeItems = [];
const nutrientMaterial = new THREE.MeshBasicMaterial({
color: "#2d9ddd",
transparent: true,
opacity: 0.94,
depthWrite: false
});
const carbonMaterial = new THREE.MeshBasicMaterial({
color: "#eea13b",
transparent: true,
opacity: 0.96,
depthWrite: false
});
function createArrow(curve, material, moverGeometry, speed, offset) {
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 36, 0.034, 6, false),
material
);
tube.renderOrder = 4;
exchangeGroup.add(tube);
const end = curve.getPoint(1);
const tangent = curve.getTangent(1).normalize();
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.115, 0.30, 9),
material
);
cone.position.copy(end).addScaledVector(tangent, -0.15);
cone.quaternion.setFromUnitVectors(Y_AXIS, tangent);
cone.renderOrder = 4;
exchangeGroup.add(cone);
const mover = new THREE.Mesh(moverGeometry, material);
mover.renderOrder = 5;
exchangeGroup.add(mover);
exchangeItems.push({
curve,
mover,
speed,
offset
});
}
const nutrientMoverGeometry = new THREE.OctahedronGeometry(0.09, 0);
const carbonMoverGeometry = new THREE.DodecahedronGeometry(0.078, 0);
function addLocalExchange(rootPoint, fungalPoint, labelSide) {
const root = rootPoint.clone();
const fungus = fungalPoint.clone();
const nutrientControl = root.clone().add(fungus).multiplyScalar(0.5).add(
new V3(labelSide * 0.04, 0.43, 0.56)
);
const carbonControl = root.clone().add(fungus).multiplyScalar(0.5).add(
new V3(labelSide * 0.04, -0.31, 0.72)
);
const nutrientCurve = new THREE.QuadraticBezierCurve3(
fungus,
nutrientControl,
root
);
const carbonCurve = new THREE.QuadraticBezierCurve3(
root,
carbonControl,
fungus
);
createArrow(
nutrientCurve,
nutrientMaterial,
nutrientMoverGeometry,
0.17,
0.12
);
createArrow(
carbonCurve,
carbonMaterial,
carbonMoverGeometry,
0.13,
0.62
);
}
const amExchangeRoot = amRootCurve.getPoint(0.57);
const amExchangeFungus = amExchangeRoot.clone().add(
new V3(-1.08, -0.48, 0.64)
);
addHypha(
[
amExchangeRoot,
amExchangeRoot.clone().lerp(amExchangeFungus, 0.52).add(
new V3(-0.08, -0.10, 0.18)
),
amExchangeFungus
],
materials.am,
0.039
);
addContact(amExchangeFungus, materials.am, 0.085);
addLocalExchange(amExchangeRoot, amExchangeFungus, -1);
const ecmExchangeRoot = ecmRootCurve.getPoint(0.55);
const ecmExchangeFungus = ecmExchangeRoot.clone().add(
new V3(1.07, -0.49, 0.63)
);
addHypha(
[
ecmExchangeRoot,
ecmExchangeRoot.clone().lerp(ecmExchangeFungus, 0.52).add(
new V3(0.07, -0.11, 0.17)
),
ecmExchangeFungus
],
materials.ecm,
0.039
);
addContact(ecmExchangeFungus, materials.ecm, 0.085);
addLocalExchange(ecmExchangeRoot, ecmExchangeFungus, 1);
// Direct camera controls, implemented without addons.
const view = {
theta: 0.045,
phi: 1.22,
radius: 22.5,
target: new V3(0, -0.45, 0)
};
let dragging = false;
let lastX = 0;
let lastY = 0;
let userMoved = false;
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
function resetView() {
view.theta = 0.045;
view.phi = 1.22;
view.radius = window.innerWidth / window.innerHeight < 0.8 ? 29 : 22.5;
userMoved = false;
updateCamera();
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
userMoved = true;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
view.theta = THREE.MathUtils.clamp(
view.theta - dx * 0.005,
-1.12,
1.12
);
view.phi = THREE.MathUtils.clamp(
view.phi + dy * 0.004,
0.72,
1.42
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.012,
15,
38
);
userMoved = true;
},
{ passive: false }
);
canvas.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
view.theta -= 0.08;
break;
case "ArrowRight":
view.theta += 0.08;
break;
case "ArrowUp":
view.phi -= 0.05;
break;
case "ArrowDown":
view.phi += 0.05;
break;
case "+":
case "=":
view.radius -= 1;
break;
case "-":
case "_":
view.radius += 1;
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
userMoved = true;
view.theta = THREE.MathUtils.clamp(view.theta, -1.12, 1.12);
view.phi = THREE.MathUtils.clamp(view.phi, 0.72, 1.42);
view.radius = THREE.MathUtils.clamp(view.radius, 15, 38);
}
});
document.getElementById("reset-view").addEventListener("click", resetView);
const exchangeToggle = document.getElementById("exchange-toggle");
exchangeToggle.addEventListener("change", () => {
exchangeGroup.visible = exchangeToggle.checked;
});
// DOM annotations follow their 3D anchors.
const tagElements = {
plantA: document.getElementById("tag-plant-a"),
plantB: document.getElementById("tag-plant-b"),
am: document.getElementById("tag-am"),
ecm: document.getElementById("tag-ecm")
};
const tagAnchors = {
plantA: new V3(-4.4, 5.55, 0),
plantB: new V3(4.4, 6.25, 0),
am: new V3(-3.25, -2.73, 1.72),
ecm: new V3(5.15, -2.72, 1.72)
};
function positionTag(element, worldPosition, offsetX = 0) {
const projected = worldPosition.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -120 &&
x < window.innerWidth + 120 &&
y > -80 &&
y < window.innerHeight + 80;
element.classList.toggle("visible", visible);
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateTags() {
positionTag(tagElements.plantA, tagAnchors.plantA, -12);
positionTag(tagElements.plantB, tagAnchors.plantB, 10);
positionTag(tagElements.am, tagAnchors.am, -22);
positionTag(tagElements.ecm, tagAnchors.ecm, 24);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
if (!userMoved) {
view.radius = aspect < 0.8 ? 29 : 22.5;
}
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (!reducedMotion) {
plantA.canopy.rotation.z = Math.sin(elapsed * 0.72) * 0.009;
plantB.canopy.rotation.z = Math.sin(elapsed * 0.64 + 1.3) * 0.008;
}
for (const item of exchangeItems) {
const phase = reducedMotion
? item.offset
: (elapsed * item.speed + item.offset) % 1;
item.mover.position.copy(item.curve.getPointAt(phase));
item.mover.rotation.y += 0.035;
item.mover.rotation.x += 0.021;
}
updateCamera();
updateTags();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
const loading = document.getElementById("loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 300);
}
}
animate();
</script>
</body>
</html>
```