Prompt specification
Build or customize the Three.js 3D scene "Litter breakdown time sequence" 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: Litter breakdown time sequence
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/litter-breakdown-time-sequence-x0726
Scene Description Prompt:
Animate low-poly litter fragmenting under fungi and detritivore activity at distinct scales, labeling time condensed. Three.js from cdnjs, one HTML file.
Working Three.js Starter (litter-breakdown-time-sequence-x0726):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Litter / Decay — Three.js</title>
<style>
:root {
--ink: #eef5ec;
--muted: #9aa99d;
--mint: #8de3ba;
--amber: #e3a85a;
--panel: rgba(12, 18, 14, .78);
--line: rgba(221, 240, 226, .14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #090d0a;
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;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 24px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--mint);
font-size: 10px;
font-weight: 750;
letter-spacing: .22em;
text-transform: uppercase;
}
.live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 12px var(--mint);
animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe {
50% { opacity: .35; transform: scale(.72); }
}
h1 {
margin: 7px 0 2px;
font-size: clamp(24px, 3.1vw, 46px);
line-height: .96;
font-weight: 760;
letter-spacing: -.055em;
}
.subtitle {
margin-top: 9px;
color: var(--muted);
font-size: 12px;
letter-spacing: .025em;
}
.status {
min-width: 164px;
padding: 11px 13px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(12px);
border-radius: 4px;
}
.status small {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: .18em;
text-transform: uppercase;
}
#stage {
display: block;
margin-top: 5px;
font-size: 11px;
font-weight: 700;
letter-spacing: .1em;
}
#divider {
position: absolute;
top: 0;
bottom: 0;
left: 64%;
width: 1px;
background: linear-gradient(
transparent,
rgba(230, 245, 233, .22) 16%,
rgba(230, 245, 233, .22) 82%,
transparent
);
}
#divider::after {
content: "↗";
position: absolute;
top: 50%;
left: 50%;
display: grid;
width: 28px;
height: 28px;
place-items: center;
transform: translate(-50%, -50%);
color: var(--mint);
border: 1px solid rgba(141, 227, 186, .35);
border-radius: 50%;
background: rgba(9, 15, 11, .85);
font-size: 12px;
}
.view-label {
position: absolute;
top: 126px;
padding: 11px 12px;
border-left: 2px solid var(--mint);
background: linear-gradient(90deg, rgba(9, 14, 10, .74), transparent);
}
#macroLabel { left: 28px; }
#microLabel { left: calc(64% + 20px); }
.view-label .index {
color: var(--mint);
font-size: 9px;
font-weight: 800;
letter-spacing: .18em;
}
.view-label h2 {
margin: 4px 0 3px;
font-size: 15px;
letter-spacing: -.02em;
}
.view-label p {
margin: 0;
color: var(--muted);
font-size: 10px;
}
.scale {
position: absolute;
top: 207px;
color: rgba(238, 245, 236, .68);
font-size: 9px;
letter-spacing: .12em;
text-transform: uppercase;
}
#macroScale { left: 29px; }
#microScale { left: calc(64% + 21px); }
.scale-line {
width: 94px;
height: 5px;
margin-top: 5px;
border-bottom: 1px solid rgba(238, 245, 236, .7);
position: relative;
}
.scale-line::before,
.scale-line::after {
content: "";
position: absolute;
bottom: -2px;
width: 1px;
height: 5px;
background: rgba(238, 245, 236, .7);
}
.scale-line::before { left: 0; }
.scale-line::after { right: 0; }
#microScale .scale-line { width: 56px; }
.callout {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
color: rgba(238, 245, 236, .82);
font-size: 9px;
font-weight: 700;
letter-spacing: .12em;
text-transform: uppercase;
transition: opacity .3s;
}
.callout::before {
content: "";
width: 25px;
height: 1px;
background: currentColor;
opacity: .65;
}
#fungiCallout {
left: 44%;
top: 38%;
color: var(--mint);
}
#detritivoreCallout {
left: 25%;
top: 58%;
color: var(--amber);
}
#hyphaCallout {
left: calc(64% + 20%);
top: 42%;
color: var(--mint);
}
#sporeCallout {
left: calc(64% + 30%);
top: 65%;
color: #c9e9ff;
}
.legend {
position: absolute;
top: 257px;
left: calc(64% + 21px);
display: grid;
gap: 7px;
color: var(--muted);
font-size: 9px;
letter-spacing: .08em;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.legend i {
width: 14px;
height: 2px;
background: var(--mint);
}
.legend span:nth-child(2) i { background: var(--amber); }
.legend span:nth-child(3) i { background: #c9e9ff; }
.help {
position: absolute;
right: 28px;
bottom: 139px;
color: rgba(238, 245, 236, .45);
font-size: 9px;
letter-spacing: .09em;
text-transform: uppercase;
}
.timeline {
position: absolute;
left: 28px;
right: 28px;
bottom: 22px;
min-height: 96px;
padding: 14px 16px 12px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(8, 13, 9, .86);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.timeline-top {
display: flex;
justify-content: space-between;
align-items: center;
gap: 14px;
margin-bottom: 12px;
}
.timeline-title {
display: flex;
align-items: baseline;
gap: 10px;
}
.timeline-title strong {
font-size: 11px;
letter-spacing: .14em;
text-transform: uppercase;
}
.timeline-title span {
color: var(--muted);
font-size: 9px;
letter-spacing: .08em;
}
#dayReadout {
color: var(--mint);
font-variant-numeric: tabular-nums;
font-size: 12px;
font-weight: 750;
letter-spacing: .08em;
}
.controls {
display: flex;
align-items: center;
gap: 10px;
}
.control {
width: 31px;
height: 31px;
padding: 0;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 3px;
color: var(--ink);
background: rgba(255, 255, 255, .035);
cursor: pointer;
font-size: 12px;
}
.control:hover { border-color: rgba(141, 227, 186, .45); }
.range-wrap {
position: relative;
flex: 1;
height: 22px;
display: flex;
align-items: center;
}
#timeline {
--p: 0%;
width: 100%;
height: 3px;
margin: 0;
appearance: none;
outline: none;
border-radius: 5px;
background:
linear-gradient(90deg, var(--mint) var(--p), rgba(255,255,255,.13) var(--p));
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 12px;
height: 12px;
appearance: none;
border: 2px solid #0b120d;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 1px var(--mint), 0 0 14px rgba(141, 227, 186, .5);
}
#timeline::-moz-range-thumb {
width: 10px;
height: 10px;
border: 2px solid #0b120d;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 1px var(--mint);
}
.marks {
position: relative;
height: 24px;
margin: 0 40px 0 41px;
}
.mark {
position: absolute;
top: 0;
transform: translateX(-50%);
color: var(--muted);
font-size: 8px;
letter-spacing: .08em;
white-space: nowrap;
}
.mark::before {
content: "";
position: absolute;
left: 50%;
top: -8px;
width: 1px;
height: 5px;
background: rgba(255,255,255,.24);
}
.mark:first-child { transform: none; }
.mark:first-child::before { left: 0; }
.mark:last-child { transform: translateX(-100%); }
.mark:last-child::before { left: 100%; }
@media (max-width: 760px) {
header { top: 18px; left: 18px; right: 18px; }
.subtitle { display: none; }
.status { min-width: 120px; padding: 9px; }
.view-label { top: 102px; }
#macroLabel { left: 18px; }
#microLabel { left: calc(58% + 13px); }
#macroScale { left: 19px; top: 183px; }
#microScale { left: calc(58% + 14px); top: 183px; }
.callout { display: none; }
.legend { left: calc(58% + 14px); top: 231px; }
.timeline { left: 12px; right: 12px; bottom: 12px; padding: 12px; }
.timeline-title span { display: none; }
.help { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly forest litter decomposition visualization"></canvas>
<div class="hud">
<header>
<div>
<div class="eyebrow"><span class="live-dot"></span> Forest-floor decomposition</div>
<h1>Litter / Decay</h1>
<div class="subtitle">Fungal colonization and detritivore grazing reshape dead material into soil.</div>
</div>
<div class="status">
<small>Current process</small>
<strong id="stage">CUTICLE INTACT</strong>
</div>
</header>
<div id="divider"></div>
<section id="macroLabel" class="view-label">
<span class="index">01 / MACRO</span>
<h2>Forest-floor litter</h2>
<p>Leaf fragments, fungi and surface-active detritivores</p>
</section>
<section id="microLabel" class="view-label">
<span class="index">02 / MICRO</span>
<h2>Fragment interface</h2>
<p>Hyphal tips, spores and microfauna</p>
</section>
<div id="macroScale" class="scale">
Approx. 10 cm
<div class="scale-line"></div>
</div>
<div id="microScale" class="scale">
Approx. 200 μm
<div class="scale-line"></div>
</div>
<div id="fungiCallout" class="callout">Fungal mycelium</div>
<div id="detritivoreCallout" class="callout">Detritivore grazing</div>
<div id="hyphaCallout" class="callout">Hyphal growth front</div>
<div id="sporeCallout" class="callout">Spore release</div>
<div class="legend">
<span><i></i> Fungal structures</span>
<span><i></i> Detritivore activity</span>
<span><i></i> Dispersed spores</span>
</div>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<section class="timeline">
<div class="timeline-top">
<div class="timeline-title">
<strong>Time condensed</strong>
<span>90 ecological days compressed into 24 seconds</span>
</div>
<div id="dayReadout">DAY 00 / 90</div>
<div class="controls">
<button id="play" class="control" title="Play or pause" aria-label="Pause">❚❚</button>
<button id="restart" class="control" title="Restart timeline" aria-label="Restart">↺</button>
<button id="cameraReset" class="control" title="Reset cameras" aria-label="Reset cameras">⌖</button>
</div>
</div>
<div class="range-wrap">
<input id="timeline" type="range" min="0" max="1000" value="0" aria-label="Decomposition timeline">
</div>
<div class="marks">
<span class="mark" style="left:0%">0 DAYS</span>
<span class="mark" style="left:25%">3 DAYS</span>
<span class="mark" style="left:50%">2 WEEKS</span>
<span class="mark" style="left:75%">6 WEEKS</span>
<span class="mark" style="left:100%">3 MONTHS</span>
</div>
</section>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* -------------------------------------------------------------------------- */
/* Utilities */
/* -------------------------------------------------------------------------- */
const canvas = document.querySelector("#scene");
const clamp = (x, a = 0, b = 1) => Math.max(a, Math.min(b, x));
const lerp = (a, b, t) => a + (b - a) * t;
const smoothstep = (a, b, x) => {
const t = clamp((x - a) / (b - a));
return t * t * (3 - 2 * t);
};
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(1847);
const rand = (a, b) => lerp(a, b, random());
/* Timeline checkpoints deliberately use nonuniform ecological intervals. */
const timeMarks = [
{ position: 0, day: 0 },
{ position: .25, day: 3 },
{ position: .50, day: 14 },
{ position: .75, day: 45 },
{ position: 1, day: 90 }
];
function ageToDay(age) {
for (let i = 0; i < timeMarks.length - 1; i++) {
const a = timeMarks[i];
const b = timeMarks[i + 1];
if (age <= b.position) {
return lerp(a.day, b.day, (age - a.position) / (b.position - a.position));
}
}
return 90;
}
function processForDay(day) {
if (day < 2) return "CUTICLE INTACT";
if (day < 7) return "SURFACE COLONIZATION";
if (day < 20) return "HYPHAL BRIDGING";
if (day < 45) return "GRAZING + INOCULATION";
if (day < 75) return "FRAGMENTATION";
return "POROUS HUMUS";
}
/* -------------------------------------------------------------------------- */
/* Renderer and camera views */
/* -------------------------------------------------------------------------- */
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const macroScene = new THREE.Scene();
macroScene.background = new THREE.Color(0x111913);
macroScene.fog = new THREE.FogExp2(0x111913, .052);
const microScene = new THREE.Scene();
microScene.background = new THREE.Color(0x08100c);
microScene.fog = new THREE.Fog(0x08100c, 5, 11);
const macroCamera = new THREE.PerspectiveCamera(42, 1, .1, 60);
const microCamera = new THREE.PerspectiveCamera(39, 1, .05, 30);
const views = {
macro: {
camera: macroCamera,
target: new THREE.Vector3(0, .05, 0),
radius: 10.8,
theta: .40,
phi: 1.03,
defaults: { radius: 10.8, theta: .40, phi: 1.03 }
},
micro: {
camera: microCamera,
target: new THREE.Vector3(0, .12, 0),
radius: 4.5,
theta: .58,
phi: 1.08,
defaults: { radius: 4.5, theta: .58, phi: 1.08 }
}
};
function applyView(name) {
const v = views[name];
const horizontal = Math.sin(v.phi) * v.radius;
v.camera.position.set(
v.target.x + horizontal * Math.sin(v.theta),
v.target.y + Math.cos(v.phi) * v.radius,
v.target.z + horizontal * Math.cos(v.theta)
);
v.camera.lookAt(v.target);
}
Object.values(views).forEach(v => {
v.camera.position.copy(v.target);
});
/* -------------------------------------------------------------------------- */
/* Lighting */
/* -------------------------------------------------------------------------- */
macroScene.add(new THREE.HemisphereLight(0xc7dfcf, 0x2a1d11, 1.8));
const macroSun = new THREE.DirectionalLight(0xffdfaa, 3.1);
macroSun.position.set(-4, 8, 5);
macroSun.castShadow = true;
macroSun.shadow.mapSize.set(1024, 1024);
macroSun.shadow.camera.left = -8;
macroSun.shadow.camera.right = 8;
macroSun.shadow.camera.top = 8;
macroSun.shadow.camera.bottom = -8;
macroSun.shadow.bias = -.0007;
macroScene.add(macroSun);
const macroRim = new THREE.PointLight(0x68d6a2, 8, 12, 2);
macroRim.position.set(4, 3, -3);
macroScene.add(macroRim);
microScene.add(new THREE.HemisphereLight(0x9ddbbd, 0x10100c, 1.3));
const microKey = new THREE.DirectionalLight(0xd8ffe7, 2.7);
microKey.position.set(3, 5, 4);
microScene.add(microKey);
const microFill = new THREE.PointLight(0x56b9ff, 3.5, 8, 2);
microFill.position.set(-3, 1.5, -1);
microScene.add(microFill);
/* -------------------------------------------------------------------------- */
/* Geometry helpers */
/* -------------------------------------------------------------------------- */
function triangleGeometry(points, ridge = .025) {
const positions = [];
for (const [x, z] of points) {
positions.push(x, ridge, z);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.computeVertexNormals();
return geometry;
}
function lineBetween(a, b, material) {
const geometry = new THREE.BufferGeometry().setFromPoints([a, b]);
return new THREE.Line(geometry, material);
}
function makeMite(size, bodyColor, legColor) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: bodyColor,
roughness: .72,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(size, 1),
bodyMaterial
);
body.scale.set(.78, .55, 1.25);
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(size * .56, 0),
bodyMaterial
);
head.position.set(0, .01, -size * 1.05);
group.add(head);
const legMaterial = new THREE.LineBasicMaterial({
color: legColor,
transparent: true,
opacity: .9
});
const legPositions = [];
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
const z = (i - 1) * size * .55;
legPositions.push(
side * size * .45, 0, z,
side * size * 1.65, -size * .08, z + (i - 1) * size * .25
);
}
}
const legs = new THREE.BufferGeometry();
legs.setAttribute("position", new THREE.Float32BufferAttribute(legPositions, 3));
group.add(new THREE.LineSegments(legs, legMaterial));
const antennaGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-size * .25, size * .15, -size * 1.3),
new THREE.Vector3(-size * .55, size * .35, -size * 1.9),
new THREE.Vector3(size * .25, size * .15, -size * 1.3),
new THREE.Vector3(size * .55, size * .35, -size * 1.9)
]);
group.add(new THREE.LineSegments(antennaGeometry, legMaterial));
return group;
}
function makeMushroom() {
const group = new THREE.Group();
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(.055, .075, .38, 6),
new THREE.MeshStandardMaterial({ color: 0xd7c8a0, roughness: .95, flatShading: true })
);
stem.position.y = .19;
stem.castShadow = true;
group.add(stem);
const cap = new THREE.Mesh(
new THREE.IcosahedronGeometry(.22, 1),
new THREE.MeshStandardMaterial({
color: 0xc17a4c,
roughness: .88,
flatShading: true
})
);
cap.scale.set(1, .43, 1);
cap.position.y = .39;
cap.castShadow = true;
group.add(cap);
const gills = new THREE.Mesh(
new THREE.CircleGeometry(.19, 8),
new THREE.MeshStandardMaterial({
color: 0xe7d2a3,
side: THREE.DoubleSide,
roughness: 1
})
);
gills.rotation.x = Math.PI / 2;
gills.position.y = .365;
group.add(gills);
group.scale.setScalar(.001);
return group;
}
/* -------------------------------------------------------------------------- */
/* Macro scene: low-poly soil */
/* -------------------------------------------------------------------------- */
const soilGeometry = new THREE.CylinderGeometry(6.15, 6.55, .58, 14, 2).toNonIndexed();
const soilPositions = soilGeometry.attributes.position;
const soilColors = [];
for (let i = 0; i < soilPositions.count; i++) {
const y = soilPositions.getY(i);
const shade = rand(.72, 1.12);
soilColors.push(
.16 * shade,
.105 * shade,
.061 * shade
);
}
soilGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(soilColors, 3)
);
const soil = new THREE.Mesh(
soilGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
soil.position.y = -.37;
soil.receiveShadow = true;
macroScene.add(soil);
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x2d2116,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 42; i++) {
const angle = rand(0, Math.PI * 2);
const radius = Math.sqrt(random()) * 5.6;
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(rand(.025, .105), 0),
soilMaterial
);
stone.position.set(
Math.cos(angle) * radius,
rand(-.025, .035),
Math.sin(angle) * radius
);
stone.scale.y = rand(.35, .7);
stone.rotation.set(rand(0, 3), rand(0, 3), rand(0, 3));
stone.castShadow = true;
macroScene.add(stone);
}
/* -------------------------------------------------------------------------- */
/* Macro scene: fragmented leaves */
/* -------------------------------------------------------------------------- */
const leafFragments = [];
const leafGroups = [];
function makeLeaf(x, z, scale, rotation, color, seed) {
const group = new THREE.Group();
group.position.set(x, .025, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
const shardDefinitions = [
[[0, 0], [-.95, -.62], [-.72, -1.52]],
[[0, 0], [-.72, -1.52], [-.04, -1.96]],
[[-.72, -1.52], [-.04, -1.98], [0, -2.55]],
[[0, 0], [0, -1.98], [.72, -1.52]],
[[0, 0], [.72, -1.52], [.95, -.62]]
];
const baseColor = new THREE.Color(color);
const fragments = [];
shardDefinitions.forEach((points, index) => {
const material = new THREE.MeshStandardMaterial({
color: baseColor.clone().offsetHSL(rand(-.025, .025), 0, rand(-.08, .07)),
side: THREE.DoubleSide,
roughness: .94,
flatShading: true
});
const mesh = new THREE.Mesh(
triangleGeometry(points, index === 2 ? .012 : .028),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
const center = new THREE.Vector3();
points.forEach(p => center.x += p[0] / points.length);
points.forEach(p => center.z += p[1] / points.length);
center.normalize();
mesh.userData.outward = center;
mesh.userData.baseColor = material.color.clone();
mesh.userData.phase = seed + index * .8;
group.add(mesh);
fragments.push(mesh);
leafFragments.push(mesh);
});
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(.026, .038, .53, 5),
new THREE.MeshStandardMaterial({ color: 0x5c3d24, roughness: 1 })
);
stem.rotation.x = Math.PI / 2;
stem.position.set(0, .015, .24);
stem.castShadow = true;
group.add(stem);
const veinGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, .047, -.02),
new THREE.Vector3(0, .057, -1.1),
new THREE.Vector3(0, .036, -2.52)
]);
const vein = new THREE.Line(
veinGeometry,
new THREE.LineBasicMaterial({ color: 0x5e452b, transparent: true, opacity: .8 })
);
group.add(vein);
group.userData.vein = vein;
leafGroups.push(group);
macroScene.add(group);
return group;
}
const leafSpecs = [
[-2.55, -1.15, .93, .35, 0x9b6330],
[-.45, -2.25, 1.12, -.62, 0xb07938],
[1.75, -1.00, .84, 1.12, 0x85562c],
[2.45, 1.55, .97, -1.15, 0x9d6331],
[-1.55, 1.88, .86, .84, 0xaa7639],
[.15, .72, .76, 2.15, 0x8f5d2d],
[-3.20, 1.15, .66, -.42, 0xb27a3e]
];
leafSpecs.forEach((spec, i) => makeLeaf(...spec, i * 1.71));
/* Crumbs released as the leaf structure loses cohesion. */
const crumbs = [];
for (let i = 0; i < 30; i++) {
const angle = rand(0, Math.PI * 2);
const radius = rand(.7, 4.7);
const crumb = new THREE.Mesh(
new THREE.TetrahedronGeometry(rand(.025, .07), 0),
new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(.08, .42, rand(.18, .32)),
roughness: 1,
flatShading: true
})
);
crumb.position.set(Math.cos(angle) * radius, .01, Math.sin(angle) * radius);
crumb.rotation.set(rand(0, 3), rand(0, 3), rand(0, 3));
crumb.scale.setScalar(.001);
macroScene.add(crumb);
crumbs.push({
mesh: crumb,
base: crumb.position.clone(),
phase: rand(0, Math.PI * 2),
delay: rand(.38, .7)
});
}
/* -------------------------------------------------------------------------- */
/* Macro scene: fungal mycelium and fruiting bodies */
/* -------------------------------------------------------------------------- */
const fungalThreads = [];
function addFungalThread(points, radius, delay, parent = macroScene) {
const curve = new THREE.CatmullRomCurve3(points);
const geometry = new THREE.TubeGeometry(curve, 40, radius, 4, false);
const material = new THREE.MeshStandardMaterial({
color: 0x87dcb4,
emissive: 0x174a31,
emissiveIntensity: .8,
roughness: .72,
transparent: true,
opacity: .92
});
const mesh = new THREE.Mesh(geometry, material);
geometry.setDrawRange(0, 0);
parent.add(mesh);
const tip = new THREE.Mesh(
new THREE.SphereGeometry(radius * 1.8, 6, 4),
new THREE.MeshStandardMaterial({
color: 0xc3ffe2,
emissive: 0x4dba83,
emissiveIntensity: 1.5,
roughness: .5
})
);
tip.scale.setScalar(.001);
parent.add(tip);
fungalThreads.push({ curve, geometry, material, tip, delay });
}
for (let i = 0; i < 9; i++) {
const points = [];
const startAngle = rand(0, Math.PI * 2);
const startRadius = rand(.3, 4.4);
const start = new THREE.Vector3(
Math.cos(startAngle) * startRadius,
rand(.07, .12),
Math.sin(startAngle) * startRadius
);
for (let j = 0; j < 7; j++) {
const angle = startAngle + j * rand(.28, .62);
const radius = startRadius + j * rand(.08, .22);
points.push(new THREE.Vector3(
Math.cos(angle) * radius + rand(-.13, .13),
rand(.055, .11),
Math.sin(angle) * radius + rand(-.13, .13)
));
}
addFungalThread(points, rand(.011, .023), rand(.08, .42));
}
const mushrooms = [];
const mushroomPositions = [
[-2.25, -.35], [-.75, -1.15], [1.10, -.12],
[2.85, .75], [-1.92, 1.15], [.95, 1.65]
];
mushroomPositions.forEach(([x, z], i) => {
const mushroom = makeMushroom();
mushroom.position.set(x, -.015, z);
mushroom.rotation.y = rand(0, Math.PI * 2);
macroScene.add(mushroom);
mushrooms.push({ group: mushroom, delay: .25 + i * .075 });
});
/* -------------------------------------------------------------------------- */
/* Macro scene: detritivores */
/* -------------------------------------------------------------------------- */
const macroMites = [];
for (let i = 0; i < 4; i++) {
const mite = makeMite(.11, i % 2 ? 0xb67c45 : 0x74513a, 0x30251c);
macroScene.add(mite);
macroMites.push({
group: mite,
base: new THREE.Vector3(rand(-2.7, 2.7), .14, rand(-2.7, 2.7)),
range: rand(.4, 1.05),
phase: rand(0, Math.PI * 2),
speed: rand(.45, .85)
});
}
/* A larger segmented surface detritivore. */
const isopod = new THREE.Group();
const isopodMaterial = new THREE.MeshStandardMaterial({
color: 0x675c4b,
roughness: .86,
flatShading: true
});
for (let i = 0; i < 6; i++) {
const segment = new THREE.Mesh(
new THREE.IcosahedronGeometry(.13 - Math.abs(i - 2.5) * .012, 1),
isopodMaterial
);
segment.scale.set(1.12, .45, .72);
segment.position.set(0, 0, (i - 2.5) * .15);
segment.castShadow = true;
isopod.add(segment);
}
const isopodLegs = [];
for (const side of [-1, 1]) {
for (let i = 0; i < 5; i++) {
isopodLegs.push(
side * .1, -.025, (i - 2) * .13,
side * .22, -.08, (i - 2) * .16
);
}
}
const isopodLegGeometry = new THREE.BufferGeometry();
isopodLegGeometry.setAttribute("position", new THREE.Float32BufferAttribute(isopodLegs, 3));
isopod.add(new THREE.LineSegments(
isopodLegGeometry,
new THREE.LineBasicMaterial({ color: 0x29251f })
));
isopod.position.set(.6, .15, .1);
isopod.rotation.y = -.8;
macroScene.add(isopod);
/* -------------------------------------------------------------------------- */
/* Micro scene: enlarged fragment interface */
/* -------------------------------------------------------------------------- */
const surfaceGeometry = new THREE.PlaneGeometry(5.6, 3.5, 9, 6);
surfaceGeometry.rotateX(-Math.PI / 2);
const surfacePositions = surfaceGeometry.attributes.position;
const surfaceColors = [];
for (let i = 0; i < surfacePositions.count; i++) {
const x = surfacePositions.getX(i);
const z = surfacePositions.getZ(i);
surfacePositions.setY(i, Math.sin(x * 2.4) * .025 + rand(-.025, .025));
const color = new THREE.Color().setHSL(
.12 + rand(-.025, .025),
.34,
rand(.13, .23)
);
surfaceColors.push(color.r, color.g, color.b);
}
surfaceGeometry.setAttribute("color", new THREE.Float32BufferAttribute(surfaceColors, 3));
const microSurface = new THREE.Mesh(
surfaceGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: .95,
side: THREE.DoubleSide,
flatShading: true
})
);
microSurface.receiveShadow = true;
microScene.add(microSurface);
const underSurface = new THREE.Mesh(
new THREE.BoxGeometry(5.7, .22, 3.6),
new THREE.MeshStandardMaterial({ color: 0x211a12, roughness: 1, flatShading: true })
);
underSurface.position.y = -.15;
microScene.add(underSurface);
/* Grazing pits become visible as the detritivores enlarge damaged areas. */
const grazePits = [];
for (let i = 0; i < 9; i++) {
const pit = new THREE.Mesh(
new THREE.CircleGeometry(rand(.06, .17), 7),
new THREE.MeshBasicMaterial({
color: 0x090b08,
transparent: true,
opacity: .9,
side: THREE.DoubleSide
})
);
pit.rotation.x = -Math.PI / 2;
pit.position.set(rand(-2.3, 2.3), .055, rand(-1.3, 1.3));
pit.scale.setScalar(.01);
microScene.add(pit);
grazePits.push({ mesh: pit, delay: rand(.2, .7), factor: rand(.7, 1.4) });
}
/* Branching hyphal network. */
const microThreads = [];
for (let i = 0; i < 13; i++) {
const points = [];
const startX = rand(-2.35, 2.35);
const startZ = rand(-1.35, 1.35);
const direction = rand(0, Math.PI * 2);
for (let j = 0; j < 6; j++) {
const distance = j * rand(.24, .43);
points.push(new THREE.Vector3(
startX + Math.cos(direction + Math.sin(j * .8) * .35) * distance,
.10 + rand(-.015, .025),
startZ + Math.sin(direction + Math.sin(j * .8) * .35) * distance
));
}
const curve = new THREE.CatmullRomCurve3(points);
const geometry = new THREE.TubeGeometry(curve, 36, rand(.014, .028), 4, false);
const material = new THREE.MeshStandardMaterial({
color: 0x9af0c7,
emissive: 0x296a4b,
emissiveIntensity: 1.1,
roughness: .58,
transparent: true,
opacity: .95
});
const mesh = new THREE.Mesh(geometry, material);
geometry.setDrawRange(0, 0);
microScene.add(mesh);
const tip = new THREE.Mesh(
new THREE.IcosahedronGeometry(rand(.035, .06), 1),
new THREE.MeshStandardMaterial({
color: 0xd5ffe9,
emissive: 0x6ad49d,
emissiveIntensity: 1.8,
roughness: .35
})
);
tip.scale.setScalar(.001);
microScene.add(tip);
microThreads.push({
curve,
geometry,
tip,
delay: rand(.05, .32)
});
}
/* Microbial spores. */
const sporeCount = 110;
const sporePositions = new Float32Array(sporeCount * 3);
const sporeSeeds = [];
for (let i = 0; i < sporeCount; i++) {
sporeSeeds.push({
x: rand(-2.7, 2.7),
y: rand(.15, 1.8),
z: rand(-1.7, 1.7),
phase: rand(0, Math.PI * 2),
speed: rand(.02, .07)
});
}
const sporeGeometry = new THREE.BufferGeometry();
sporeGeometry.setAttribute("position", new THREE.BufferAttribute(sporePositions, 3));
const spores = new THREE.Points(
sporeGeometry,
new THREE.PointsMaterial({
color: 0xbde9ff,
size: .034,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
microScene.add(spores);
/* Microfauna. */
const microMites = [];
for (let i = 0; i < 3; i++) {
const mite = makeMite(.13, i === 1 ? 0xd0a16b : 0x806448, 0x211c16);
microScene.add(mite);
microMites.push({
group: mite,
base: new THREE.Vector3(rand(-1.8, 1.8), .18, rand(-1.1, 1.1)),
phase: rand(0, Math.PI * 2),
speed: rand(.7, 1.2)
});
}
/* A small nematode-like detritivore. */
const nematodeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-1.8, .16, .6),
new THREE.Vector3(-1.2, .18, .45),
new THREE.Vector3(-.6, .16, .7),
new THREE.Vector3(.1, .17, .55),
new THREE.Vector3(.8, .16, .78)
]);
const nematode = new THREE.Mesh(
new THREE.TubeGeometry(nematodeCurve, 40, .034, 5, false),
new THREE.MeshStandardMaterial({
color: 0xc6b28a,
roughness: .85,
flatShading: true
})
);
microScene.add(nematode);
/* -------------------------------------------------------------------------- */
/* Animation state */
/* -------------------------------------------------------------------------- */
let age = 0;
let playing = true;
const playbackDuration = 24;
const playButton = document.querySelector("#play");
const restartButton = document.querySelector("#restart");
const cameraResetButton = document.querySelector("#cameraReset");
const timeline = document.querySelector("#timeline");
const dayReadout = document.querySelector("#dayReadout");
const stageReadout = document.querySelector("#stage");
const fungiCallout = document.querySelector("#fungiCallout");
const detritivoreCallout = document.querySelector("#detritivoreCallout");
const hyphaCallout = document.querySelector("#hyphaCallout");
const sporeCallout = document.querySelector("#sporeCallout");
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "❚❚" : "▶";
playButton.setAttribute("aria-label", playing ? "Pause" : "Play");
}
playButton.addEventListener("click", () => setPlaying(!playing));
restartButton.addEventListener("click", () => {
age = 0;
setPlaying(true);
});
timeline.addEventListener("input", () => {
age = Number(timeline.value) / 1000;
setPlaying(false);
});
cameraResetButton.addEventListener("click", () => {
Object.entries(views).forEach(([name, view]) => {
view.radius = view.defaults.radius;
view.theta = view.defaults.theta;
view.phi = view.defaults.phi;
applyView(name);
});
});
/* -------------------------------------------------------------------------- */
/* Direct camera controls — no external controls addon */
/* -------------------------------------------------------------------------- */
let activeView = null;
let dragging = false;
let previousX = 0;
let previousY = 0;
function mainWidth() {
return Math.floor(window.innerWidth * (window.innerWidth < 760 ? .58 : .64));
}
function viewAt(clientX) {
return clientX < mainWidth() ? "macro" : "micro";
}
canvas.addEventListener("pointerdown", event => {
activeView = viewAt(event.clientX);
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging || !activeView) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
const view = views[activeView];
view.theta -= dx * .006;
view.phi = clamp(view.phi + dy * .005, .30, 1.43);
applyView(activeView);
});
canvas.addEventListener("pointerup", event => {
dragging = false;
activeView = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
activeView = null;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
const name = viewAt(event.clientX);
const view = views[name];
const minimum = name === "macro" ? 6.2 : 2.2;
const maximum = name === "macro" ? 16 : 7.5;
view.radius = clamp(view.radius * Math.exp(event.deltaY * .001), minimum, maximum);
applyView(name);
}, { passive: false });
canvas.addEventListener("dblclick", event => {
const name = viewAt(event.clientX);
const view = views[name];
view.radius = view.defaults.radius;
view.theta = view.defaults.theta;
view.phi = view.defaults.phi;
applyView(name);
});
/* -------------------------------------------------------------------------- */
/* Resize and split rendering */
/* -------------------------------------------------------------------------- */
let width = window.innerWidth;
let height = window.innerHeight;
function onResize() {
width = window.innerWidth;
height = window.innerHeight;
renderer.setSize(width, height, false);
const split = mainWidth();
macroCamera.aspect = split / height;
microCamera.aspect = (width - split) / height;
macroCamera.updateProjectionMatrix();
microCamera.updateProjectionMatrix();
document.querySelector("#divider").style.left = `${(split / width) * 100}%`;
}
window.addEventListener("resize", onResize);
onResize();
/* -------------------------------------------------------------------------- */
/* Scene updates */
/* -------------------------------------------------------------------------- */
const darkLeafColor = new THREE.Color(0x30271d);
function updateMacro(day) {
const fracture = smoothstep(.18, .82, age);
const decay = smoothstep(.18, 1, age);
leafFragments.forEach(fragment => {
const outward = fragment.userData.outward;
const phase = fragment.userData.phase;
const gap = fracture * (.15 + (phase % .7) * .12);
fragment.position.set(
outward.x * gap,
Math.sin(phase * 2) * fracture * .035 -
smoothstep(.72, 1, age) * .09,
outward.z * gap
);
fragment.rotation.x = Math.sin(phase) * fracture * .09;
fragment.rotation.z = Math.cos(phase) * fracture * .12;
const finalScale = 1 - smoothstep(.87, 1, age) * .24;
fragment.scale.setScalar(finalScale);
fragment.material.color
.copy(fragment.userData.baseColor)
.lerp(darkLeafColor, decay * .83);
});
leafGroups.forEach(group => {
group.userData.vein.material.opacity = .8 - decay * .65;
});
crumbs.forEach(crumb => {
const growth = smoothstep(crumb.delay, crumb.delay + .28, age);
const pulse = .72 + Math.sin(age * 90 + crumb.phase) * .18;
crumb.mesh.scale.setScalar(Math.max(.001, growth * pulse));
crumb.mesh.position.y = crumb.base.y + Math.sin(crumb.phase + age * 18) * .015;
crumb.mesh.rotation.y += .003;
});
fungalThreads.forEach(thread => {
const growth = smoothstep(thread.delay, thread.delay + .54, age);
const count = thread.geometry.index.count;
thread.geometry.setDrawRange(0, Math.floor(count * growth / 3) * 3);
thread.material.opacity = .92 * growth;
const tipPosition = thread.curve.getPoint(growth);
thread.tip.position.copy(tipPosition);
thread.tip.scale.setScalar(Math.max(.001, growth));
});
mushrooms.forEach(mushroom => {
const growth = smoothstep(mushroom.delay, mushroom.delay + .17, age);
mushroom.group.scale.setScalar(Math.max(.001, growth));
});
const activity = smoothstep(.12, .48, age);
macroMites.forEach(mite => {
const t = age * 42 + mite.phase;
mite.group.position.set(
mite.base.x + Math.sin(t * mite.speed) * mite.range,
mite.base.y,
mite.base.z + Math.cos(t * mite.speed * .83) * mite.range
);
mite.group.rotation.y = -t * mite.speed;
mite.group.scale.setScalar(Math.max(.001, activity));
});
const isopodT = age * 35;
isopod.position.set(
.6 + Math.sin(isopodT * .32) * 1.2,
.15,
.1 + Math.cos(isopodT * .32) * .8
);
isopod.rotation.y = -isopodT * .32 + Math.PI / 2;
isopod.scale.setScalar(Math.max(.001, activity));
fungiCallout.style.opacity = smoothstep(3, 12, day) * .95;
detritivoreCallout.style.opacity = smoothstep(10, 30, day) * .95;
}
function updateMicro(day) {
microThreads.forEach(thread => {
const growth = smoothstep(thread.delay, thread.delay + .45, age);
const count = thread.geometry.index.count;
thread.geometry.setDrawRange(0, Math.floor(count * growth / 3) * 3);
thread.tip.position.copy(thread.curve.getPoint(growth));
const pulse = .8 + Math.sin(age * 95 + thread.delay * 30) * .2;
thread.tip.scale.setScalar(Math.max(.001, growth * pulse));
});
grazePits.forEach(pit => {
const growth = smoothstep(pit.delay, pit.delay + .35, age);
pit.mesh.scale.setScalar(Math.max(.001, growth * pit.factor));
});
const sporeActivity = smoothstep(8, 26, day);
spores.material.opacity = sporeActivity * .8;
const sporeArray = sporeGeometry.attributes.position.array;
sporeSeeds.forEach((spore, i) => {
sporeArray[i * 3] = spore.x + Math.sin(age * 15 + spore.phase) * .12;
sporeArray[i * 3 + 1] =
.12 + ((spore.y + age * 90 * spore.speed) % 1.9);
sporeArray[i * 3 + 2] =
spore.z + Math.cos(age * 12 + spore.phase) * .09;
});
sporeGeometry.attributes.position.needsUpdate = true;
microMites.forEach(mite => {
const t = age * 70 + mite.phase;
mite.group.position.set(
mite.base.x + Math.sin(t * mite.speed) * .42,
.18,
mite.base.z + Math.cos(t * mite.speed * .72) * .32
);
mite.group.rotation.y = -t * mite.speed;
});
nematode.position.x = Math.sin(age * 26) * .22;
nematode.rotation.y = Math.sin(age * 15) * .18;
hyphaCallout.style.opacity = smoothstep(3, 14, day) * .95;
sporeCallout.style.opacity = smoothstep(9, 25, day) * .95;
}
function updateHUD(day) {
const roundedDay = Math.round(day);
dayReadout.textContent = `DAY ${String(roundedDay).padStart(2, "0")} / 90`;
stageReadout.textContent = processForDay(day);
timeline.value = Math.round(age * 1000);
timeline.style.setProperty("--p", `${age * 100}%`);
}
/* -------------------------------------------------------------------------- */
/* Main loop */
/* -------------------------------------------------------------------------- */
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, .05);
previousTime = now;
if (playing) {
age = (age + dt / playbackDuration) % 1;
}
const day = ageToDay(age);
updateMacro(day);
updateMicro(day);
updateHUD(day);
const split = mainWidth();
renderer.setScissorTest(true);
renderer.setViewport(0, 0, split, height);
renderer.setScissor(0, 0, split, height);
renderer.render(macroScene, macroCamera);
renderer.setViewport(split, 0, width - split, height);
renderer.setScissor(split, 0, width - split, height);
renderer.render(microScene, microCamera);
renderer.setScissorTest(false);
}
applyView("macro");
applyView("micro");
requestAnimationFrame(animate);
</script>
</body>
</html>
```