Prompt specification
Build or customize the Three.js 3D scene "Organic Matter Transformation Timeline" 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: Organic Matter Transformation Timeline
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/organic-matter-transformation-timeline-x3926
Scene Description Prompt:
Animate voxel plant litter fragmenting and decomposing, with matter leaving as gases and water instead of entirely becoming soil. Three.js from cdnjs, one HTML file.
Working Three.js Starter (organic-matter-transformation-timeline-x3926):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Litter → Gases + Water</title>
<style>
:root {
color-scheme: dark;
--bg: #0d1515;
--panel: rgba(15, 27, 27, 0.84);
--line: rgba(190, 220, 205, 0.17);
--text: #e7f0e6;
--muted: #a5b8ac;
--leaf: #c8ad49;
--gas: #72d6c2;
--water: #68b9ed;
--soil: #9c6844;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
user-select: none;
}
.title {
position: absolute;
top: 28px;
left: 30px;
max-width: 440px;
text-shadow: 0 2px 15px rgba(0, 0, 0, 0.55);
}
.eyebrow {
color: var(--gas);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 9px 0 8px;
font-size: clamp(28px, 4vw, 53px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 800;
}
.subtitle {
margin: 0;
max-width: 390px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel {
position: absolute;
top: 26px;
right: 26px;
width: 290px;
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.25);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live {
display: flex;
align-items: center;
gap: 6px;
color: var(--gas);
font-size: 9px;
letter-spacing: 0.12em;
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--gas);
box-shadow: 0 0 12px var(--gas);
}
.legend {
display: grid;
gap: 9px;
margin-bottom: 16px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #c7d4ca;
font-size: 11px;
}
.swatch {
width: 11px;
height: 11px;
flex: 0 0 auto;
border-radius: 3px;
}
.swatch.leaf { background: var(--leaf); }
.swatch.gas { background: var(--gas); }
.swatch.water { background: var(--water); }
.swatch.soil { background: var(--soil); }
.balance-title {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.balance-bar {
display: flex;
height: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.balance-bar span {
height: 100%;
transition: width 0.2s linear;
}
#soilBar { background: var(--soil); }
#gasBar { background: var(--gas); }
#waterBar { background: var(--water); }
.balance-numbers {
margin-top: 8px;
color: #dce8df;
font-size: 10px;
line-height: 1.6;
}
.note {
margin: 13px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.controls {
display: flex;
gap: 7px;
margin-top: 14px;
pointer-events: auto;
}
button {
border: 1px solid var(--line);
border-radius: 8px;
padding: 8px 10px;
color: var(--text);
background: rgba(255, 255, 255, 0.06);
font: inherit;
font-size: 10px;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.13);
}
.timeline {
position: absolute;
right: 26px;
bottom: 25px;
left: 26px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 9px;
}
.step {
position: relative;
min-height: 48px;
padding: 10px 13px 12px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(11, 22, 21, 0.62);
color: #84988b;
transition: border-color 0.3s, color 0.3s, background 0.3s;
}
.step.active {
border-color: rgba(114, 214, 194, 0.55);
color: var(--text);
background: rgba(27, 52, 46, 0.76);
}
.step-number {
display: block;
margin-bottom: 3px;
color: var(--gas);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
}
.step-name {
font-size: 11px;
font-weight: 700;
letter-spacing: 0.03em;
}
.progress {
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 2px;
background: rgba(255, 255, 255, 0.08);
}
.progress::after {
content: "";
display: block;
width: var(--progress, 0%);
height: 100%;
background: var(--gas);
box-shadow: 0 0 10px rgba(114, 214, 194, 0.75);
}
.scene-label {
position: absolute;
z-index: 2;
padding: 5px 8px;
border: 1px solid rgba(190, 220, 205, 0.18);
border-radius: 6px;
background: rgba(9, 18, 18, 0.72);
color: #dce9df;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transform: translate(-50%, -50%);
transition: opacity 0.25s;
white-space: nowrap;
}
.scene-label.gas { border-color: rgba(114, 214, 194, 0.42); color: var(--gas); }
.scene-label.water { border-color: rgba(104, 185, 237, 0.42); color: var(--water); }
.scene-label.soil { border-color: rgba(156, 104, 68, 0.62); color: #d69a6d; }
.hint {
position: absolute;
bottom: 100px;
left: 30px;
color: rgba(208, 224, 211, 0.48);
font-size: 10px;
letter-spacing: 0.04em;
}
@media (max-width: 760px) {
.title {
top: 18px;
left: 18px;
max-width: 270px;
}
.subtitle { display: none; }
.panel {
top: 18px;
right: 18px;
width: 215px;
padding: 12px;
}
.legend { gap: 6px; margin-bottom: 11px; }
.legend-row { font-size: 10px; }
.note { display: none; }
.timeline { right: 18px; bottom: 18px; left: 18px; }
.step { min-height: 42px; padding: 8px; }
.step-name { font-size: 9px; }
.hint { display: none; }
.scene-label { font-size: 8px; }
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<div class="title">
<div class="eyebrow">A voxel decomposition study</div>
<h1>Litter → air<br />+ water</h1>
<p class="subtitle">
Plant matter does not simply become soil. Watch the voxel fragments
separate while carbon-rich gases and water droplets leave the litter.
</p>
</div>
<div class="panel">
<div class="panel-title">
<span>Material pathways</span>
<span class="live">simulating</span>
</div>
<div class="legend">
<div class="legend-row"><span class="swatch leaf"></span>Plant litter</div>
<div class="legend-row"><span class="swatch gas"></span>Microbial gases / CO₂</div>
<div class="legend-row"><span class="swatch water"></span>Water / H₂O</div>
<div class="legend-row"><span class="swatch soil"></span>Stable soil residue</div>
</div>
<div class="balance-title">
<span>Pathway balance</span>
<span id="cycleText">cycle 01</span>
</div>
<div class="balance-bar">
<span id="soilBar"></span>
<span id="gasBar"></span>
<span id="waterBar"></span>
</div>
<div class="balance-numbers" id="balanceNumbers">
Soil 0% · Gases 0% · Water 0%
</div>
<p class="note">
The remaining fragments represent stabilized residue. The colored
particles visualize matter leaving the litter as gases and water.
</p>
<div class="controls">
<button id="pauseButton">Pause</button>
<button id="restartButton">Restart</button>
</div>
</div>
<div id="gasLabel" class="scene-label gas">Gases / CO₂</div>
<div id="waterLabel" class="scene-label water">Water / H₂O</div>
<div id="soilLabel" class="scene-label soil">Soil residue</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="timeline">
<div class="step active" data-phase="0">
<span class="step-number">01</span>
<span class="step-name">Fragment the litter</span>
<span class="progress" id="progress0"></span>
</div>
<div class="step" data-phase="1">
<span class="step-number">02</span>
<span class="step-name">Release gases + water</span>
<span class="progress" id="progress1"></span>
</div>
<div class="step" data-phase="2">
<span class="step-number">03</span>
<span class="step-name">Settle stable residue</span>
<span class="progress" id="progress2"></span>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d1515);
scene.fog = new THREE.Fog(0x0d1515, 13, 29);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
app.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xb8d8ce, 0x38271d, 1.55);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xffedc1, 3.1);
sun.position.set(-5, 11, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
scene.add(sun);
const rim = new THREE.PointLight(0x6bd8c2, 12, 16, 2);
rim.position.set(5, 4, -4);
scene.add(rim);
// -------------------------------------------------------------------------
// Ground made from instanced voxel tiles
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 24),
new THREE.MeshStandardMaterial({
color: 0x121c1a,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.1;
ground.receiveShadow = true;
scene.add(ground);
const tileGeometry = new THREE.BoxGeometry(0.72, 0.08, 0.72);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
vertexColors: true
});
const tileColumns = 32;
const tileRows = 24;
const tileCount = tileColumns * tileRows;
const tileMesh = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCount
);
tileMesh.receiveShadow = true;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let z = 0; z < tileRows; z++) {
for (let x = 0; x < tileColumns; x++) {
dummy.position.set(
(x - tileColumns / 2 + 0.5) * 0.72,
-0.055 + Math.random() * 0.015,
(z - tileRows / 2 + 0.5) * 0.72
);
dummy.rotation.y = (Math.random() - 0.5) * 0.03;
dummy.updateMatrix();
tileMesh.setMatrixAt(tileIndex, dummy.matrix);
const brightness = 0.10 + Math.random() * 0.06;
tileColor.setHSL(
0.37 + Math.random() * 0.025,
0.14 + Math.random() * 0.12,
brightness
);
tileMesh.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tileMesh.instanceMatrix.needsUpdate = true;
if (tileMesh.instanceColor) tileMesh.instanceColor.needsUpdate = true;
scene.add(tileMesh);
const soilBed = new THREE.Mesh(
new THREE.CylinderGeometry(2.7, 2.9, 0.055, 36),
new THREE.MeshStandardMaterial({
color: 0x33251e,
roughness: 1
})
);
soilBed.position.y = -0.012;
soilBed.scale.z = 0.62;
soilBed.receiveShadow = true;
scene.add(soilBed);
// -------------------------------------------------------------------------
// Voxel litter
// -------------------------------------------------------------------------
const fragments = [];
const leafPalette = [
0xc5a93f,
0xd0b34b,
0xa19a3c,
0x7f8d3e,
0xb68a35,
0x9e7832
];
const leafGeometry = new THREE.BoxGeometry(0.24, 0.24, 0.24);
function createLeafFragment(x, y, z, color, fate) {
const geometry = new THREE.BoxGeometry(
0.21 + Math.random() * 0.055,
0.2 + Math.random() * 0.055,
0.21 + Math.random() * 0.055
);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
transparent: true,
opacity: 1
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const direction = new THREE.Vector3(
Math.random() - 0.5,
0.2 + Math.random() * 0.8,
Math.random() - 0.5
).normalize();
fragments.push({
mesh,
home: mesh.position.clone(),
direction,
distance: 0.45 + Math.random() * 1.45,
lift: Math.random() * 0.65,
fate,
spin: new THREE.Vector3(
(Math.random() - 0.5) * 5,
(Math.random() - 0.5) * 5,
(Math.random() - 0.5) * 5
),
rotation: new THREE.Vector3(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
),
soilTarget: new THREE.Vector3(
(Math.random() - 0.5) * 4.1,
0.09 + Math.random() * 0.04,
(Math.random() - 0.5) * 2.6
),
startColor: new THREE.Color(color),
soilColor: new THREE.Color(
Math.random() < 0.5 ? 0x5b3826 : 0x75472d
)
});
}
for (let ix = -4; ix <= 4; ix++) {
for (let iz = -2; iz <= 2; iz++) {
const ellipse =
(ix * ix) / (4.65 * 4.65) +
(iz * iz) / (2.7 * 2.7);
if (ellipse > 1 || Math.random() < 0.1) continue;
const stack = Math.random() < 0.28 ? 2 : 1;
for (let level = 0; level < stack; level++) {
const fateRoll = Math.random();
const fate =
fateRoll < 0.55 ? "soil" :
fateRoll < 0.80 ? "gas" : "water";
createLeafFragment(
ix * 0.255 + (Math.random() - 0.5) * 0.045,
0.19 + level * 0.225 + Math.random() * 0.025,
iz * 0.245 + (Math.random() - 0.5) * 0.045,
leafPalette[
Math.floor(Math.random() * leafPalette.length)
],
fate
);
}
}
}
// -------------------------------------------------------------------------
// Small stable soil residue
// -------------------------------------------------------------------------
const crumbs = [];
const crumbMaterial = new THREE.MeshStandardMaterial({
color: 0x583827,
roughness: 1
});
for (let i = 0; i < 85; i++) {
const angle = Math.random() * Math.PI * 2;
const radius = Math.sqrt(Math.random()) * 2.3;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(
0.1 + Math.random() * 0.11,
0.055 + Math.random() * 0.07,
0.1 + Math.random() * 0.11
),
crumbMaterial
);
mesh.position.set(
Math.cos(angle) * radius,
0.045 + Math.random() * 0.025,
Math.sin(angle) * radius * 0.62
);
mesh.rotation.set(
Math.random() * 0.4,
Math.random() * Math.PI,
Math.random() * 0.4
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
crumbs.push({
mesh,
scale: 0.55 + Math.random() * 0.65
});
}
// -------------------------------------------------------------------------
// Water patches that appear as droplets leave the litter
// -------------------------------------------------------------------------
const waterPatches = [];
for (let i = 0; i < 15; i++) {
const angle = Math.random() * Math.PI * 2;
const radius = 0.7 + Math.random() * 2.4;
const material = new THREE.MeshStandardMaterial({
color: 0x4d9bd0,
roughness: 0.18,
metalness: 0.15,
transparent: true,
opacity: 0,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.38, 0.025, 10),
material
);
mesh.position.set(
Math.cos(angle) * radius,
0.018,
Math.sin(angle) * radius * 0.65
);
mesh.scale.set(0, 0, 0);
scene.add(mesh);
waterPatches.push({
mesh,
sx: 0.6 + Math.random() * 1.2,
sz: 0.45 + Math.random() * 0.95
});
}
// -------------------------------------------------------------------------
// Gas and water particles
// -------------------------------------------------------------------------
const gasGeometry = new THREE.IcosahedronGeometry(1, 0);
const waterGeometry = new THREE.SphereGeometry(1, 8, 6);
const particles = [];
function spawnParticle(type) {
if (particles.length >= 150) return;
const sourceFragment =
fragments[Math.floor(Math.random() * fragments.length)];
const origin = sourceFragment.mesh.position.clone();
origin.x += (Math.random() - 0.5) * 0.2;
origin.y += 0.12;
origin.z += (Math.random() - 0.5) * 0.2;
const isGas = type === "gas";
const material = new THREE.MeshBasicMaterial({
color: isGas
? (Math.random() < 0.5 ? 0x65d7bd : 0x9be3b8)
: 0x65b9ef,
transparent: true,
opacity: isGas ? 0.48 : 0.78,
depthWrite: false
});
const mesh = new THREE.Mesh(
isGas ? gasGeometry : waterGeometry,
material
);
const size = isGas
? 0.09 + Math.random() * 0.16
: 0.045 + Math.random() * 0.065;
mesh.position.copy(origin);
mesh.scale.setScalar(size);
scene.add(mesh);
particles.push({
mesh,
type,
age: 0,
life: isGas
? 2.5 + Math.random() * 1.6
: 2.0 + Math.random() * 1.2,
size,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * (isGas ? 0.55 : 0.9),
isGas
? 0.45 + Math.random() * 0.8
: 0.8 + Math.random() * 0.8,
(Math.random() - 0.5) * (isGas ? 0.55 : 0.9)
)
});
}
function clearParticles() {
for (const particle of particles) {
scene.remove(particle.mesh);
particle.mesh.material.dispose();
}
particles.length = 0;
}
// -------------------------------------------------------------------------
// Camera controls, implemented directly without addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.8, 0);
let yaw = 0.64;
let pitch = 0.53;
let radius = 13.2;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
camera.position.set(
cameraTarget.x +
radius * Math.cos(pitch) * Math.sin(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z +
radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
yaw -= dx * 0.006;
pitch = Math.max(
0.18,
Math.min(1.18, pitch + dy * 0.004)
);
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = Math.max(
7.5,
Math.min(20, radius + event.deltaY * 0.012)
);
},
{ passive: false }
);
updateCamera();
// -------------------------------------------------------------------------
// HUD
// -------------------------------------------------------------------------
const soilBar = document.getElementById("soilBar");
const gasBar = document.getElementById("gasBar");
const waterBar = document.getElementById("waterBar");
const balanceNumbers = document.getElementById("balanceNumbers");
const cycleText = document.getElementById("cycleText");
const pauseButton = document.getElementById("pauseButton");
const restartButton = document.getElementById("restartButton");
const steps = [...document.querySelectorAll(".step")];
const progressElements = [
document.getElementById("progress0"),
document.getElementById("progress1"),
document.getElementById("progress2")
];
const gasLabel = document.getElementById("gasLabel");
const waterLabel = document.getElementById("waterLabel");
const soilLabel = document.getElementById("soilLabel");
const gasLabelPosition = new THREE.Vector3(3.6, 4.2, 0.3);
const waterLabelPosition = new THREE.Vector3(-3.6, 1.25, 0.8);
const soilLabelPosition = new THREE.Vector3(0.5, 0.25, 2.6);
function placeLabel(element, position) {
const projected = position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.left =
`${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
element.style.opacity = visible ? "1" : "0";
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const DURATION = 18;
const clamp = (value, min, max) =>
Math.max(min, Math.min(max, value));
function smooth(value, min, max) {
const x = clamp((value - min) / (max - min), 0, 1);
return x * x * (3 - 2 * x);
}
let elapsed = 0;
let previousTime = performance.now();
let paused = false;
let currentCycle = -1;
let spawnAccumulator = 0;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
restartButton.addEventListener("click", () => {
elapsed = 0;
currentCycle = -1;
spawnAccumulator = 0;
clearParticles();
});
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) elapsed += delta;
const cycle = Math.floor(elapsed / DURATION);
const t = (elapsed % DURATION) / DURATION;
if (cycle !== currentCycle) {
currentCycle = cycle;
clearParticles();
spawnAccumulator = 0;
}
const fragmentProgress = smooth(t, 0.08, 0.54);
const decayProgress = smooth(t, 0.42, 0.94);
const soilProgress = smooth(t, 0.44, 0.95);
const gasProgress = smooth(t, 0.44, 0.84);
const waterProgress = smooth(t, 0.52, 0.94);
// Fragment movement and fate separation.
for (const fragment of fragments) {
const mesh = fragment.mesh;
mesh.position.copy(fragment.home);
mesh.position.addScaledVector(
fragment.direction,
fragmentProgress * fragment.distance
);
mesh.position.y +=
Math.sin(fragmentProgress * Math.PI) * fragment.lift;
mesh.rotation.set(
fragment.rotation.x + fragmentProgress * fragment.spin.x,
fragment.rotation.y + fragmentProgress * fragment.spin.y,
fragment.rotation.z + fragmentProgress * fragment.spin.z
);
if (fragment.fate === "soil") {
mesh.position.lerp(fragment.soilTarget, soilProgress);
mesh.position.y += (1 - soilProgress) * 0.08;
const scale = 1 - soilProgress * 0.58;
mesh.scale.setScalar(scale);
mesh.material.opacity = 1;
mesh.material.color.lerpColors(
fragment.startColor,
fragment.soilColor,
soilProgress * 0.9
);
mesh.visible = true;
} else {
const fade = smooth(t, 0.56, 0.89);
mesh.position.y += decayProgress * 1.2;
mesh.position.x += Math.sin(t * 5 + fragment.home.x) * 0.06;
mesh.position.z += Math.cos(t * 4 + fragment.home.z) * 0.06;
mesh.scale.setScalar(1 - fade * 0.72);
mesh.material.opacity = 1 - fade;
mesh.material.color.lerpColors(
fragment.startColor,
fragment.soilColor,
fade * 0.35
);
mesh.visible = mesh.material.opacity > 0.015;
}
}
// Fine soil residue appears progressively.
for (const crumb of crumbs) {
const scale = crumb.scale * soilProgress;
crumb.mesh.scale.set(scale, scale * 0.65, scale);
}
// Surface water accumulates where droplets leave and descend.
for (const patch of waterPatches) {
patch.mesh.scale.set(
patch.sx * waterProgress,
waterProgress,
patch.sz * waterProgress
);
patch.mesh.material.opacity = waterProgress * 0.56;
}
// Spawn escaping matter during the active decomposition interval.
if (t > 0.39 && t < 0.93) {
const rate = 11 + 5 * Math.sin((t - 0.39) / 0.54 * Math.PI);
spawnAccumulator += delta * rate;
while (spawnAccumulator >= 1) {
spawnAccumulator -= 1;
spawnParticle(Math.random() < 0.56 ? "gas" : "water");
}
}
// Update gas and water particles.
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.age += delta;
if (particle.age >= particle.life) {
scene.remove(particle.mesh);
particle.mesh.material.dispose();
particles.splice(i, 1);
continue;
}
if (particle.type === "gas") {
particle.velocity.y += 0.08 * delta;
particle.velocity.x +=
Math.sin(particle.age * 2.4) * 0.025 * delta;
particle.mesh.position.addScaledVector(
particle.velocity,
delta
);
particle.mesh.scale.setScalar(
particle.size * (1 + particle.age * 0.3)
);
particle.mesh.material.opacity =
0.48 * (1 - particle.age / particle.life);
} else {
particle.velocity.y -= 2.6 * delta;
particle.mesh.position.addScaledVector(
particle.velocity,
delta
);
if (particle.mesh.position.y < 0.055) {
particle.mesh.position.y = 0.055;
particle.velocity.set(0, 0, 0);
}
particle.mesh.scale.set(
particle.size * 0.8,
particle.size * 1.35,
particle.size * 0.8
);
particle.mesh.material.opacity =
0.78 * (1 - particle.age / particle.life);
}
}
// Dynamic pathway accounting.
const soilPercent = soilProgress * 55;
const gasPercent = gasProgress * 28;
const waterPercent = waterProgress * 17;
soilBar.style.width = `${soilPercent}%`;
gasBar.style.width = `${gasPercent}%`;
waterBar.style.width = `${waterPercent}%`;
balanceNumbers.textContent =
`Soil ${soilPercent.toFixed(0)}% · ` +
`Gases ${gasPercent.toFixed(0)}% · ` +
`Water ${waterPercent.toFixed(0)}%`;
cycleText.textContent =
`cycle ${String(cycle + 1).padStart(2, "0")}`;
// Timeline phase highlighting.
const phase =
t < 0.22 ? 0 :
t < 0.58 ? 1 : 2;
steps.forEach((step, index) => {
step.classList.toggle("active", index === phase);
});
progressElements[0].style.setProperty(
"--progress",
`${clamp(t / 0.22, 0, 1) * 100}%`
);
progressElements[1].style.setProperty(
"--progress",
`${clamp((t - 0.22) / 0.36, 0, 1) * 100}%`
);
progressElements[2].style.setProperty(
"--progress",
`${clamp((t - 0.58) / 0.42, 0, 1) * 100}%`
);
updateCamera();
placeLabel(gasLabel, gasLabelPosition);
placeLabel(waterLabel, waterLabelPosition);
placeLabel(soilLabel, soilLabelPosition);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```