Prompt specification
Build or customize the Three.js 3D scene "Moss rehydration time-lapse" 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: Moss rehydration time-lapse
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/moss-rehydration-time-lapse-x0754
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: moss rehydration time-lapse. Animate droplets reaching a dry moss cushion followed by gradual leaf expansion; keep individual stems anchored and make the time compression explicit on the display.
Working Three.js Starter (moss-rehydration-time-lapse-x0754):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Moss Rehydration — Voxel Time-Lapse</title>
<style>
:root {
--ink: #23382b;
--muted: #6d7a6c;
--paper: rgba(248, 249, 239, 0.88);
--line: rgba(35, 56, 43, 0.14);
--green: #477e3e;
--blue: #4aaec7;
--orange: #b8793e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e6e9dd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow:
0 14px 38px rgba(38, 53, 42, 0.08),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
position: absolute;
top: 24px;
left: 24px;
width: min(420px, calc(100vw - 48px));
padding: 19px 21px 17px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(71, 126, 62, 0.12);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 39px);
font-weight: 780;
letter-spacing: -0.055em;
line-height: 0.95;
}
.subtitle {
max-width: 340px;
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.compression {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-top: 15px;
}
.compression strong {
padding: 7px 10px;
border-radius: 8px;
background: var(--ink);
color: #f5f7e9;
font-size: 11px;
letter-spacing: 0.04em;
}
.compression span {
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.time-panel {
position: absolute;
top: 24px;
right: 24px;
width: 286px;
padding: 17px 18px;
border-radius: 18px;
}
.time-top {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
}
.time-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.time-scale {
color: var(--blue);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
}
.clock {
margin-top: 8px;
font-variant-numeric: tabular-nums;
font-size: 31px;
font-weight: 760;
letter-spacing: -0.055em;
}
.clock small {
margin-left: 5px;
color: var(--muted);
font-size: 12px;
font-weight: 650;
letter-spacing: 0;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 15px;
}
.metric {
padding: 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.34);
}
.metric span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 18px;
font-variant-numeric: tabular-nums;
letter-spacing: -0.04em;
}
.timeline-panel {
position: absolute;
left: 50%;
bottom: 24px;
width: min(760px, calc(100vw - 48px));
padding: 15px 18px 14px;
border-radius: 17px;
transform: translateX(-50%);
}
.timeline-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 14px;
margin-bottom: 10px;
}
#phaseName {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-head small {
color: var(--muted);
font-size: 10px;
font-weight: 650;
text-align: right;
}
.track {
position: relative;
height: 6px;
overflow: hidden;
border-radius: 20px;
background: rgba(35, 56, 43, 0.11);
}
.track-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: linear-gradient(90deg, var(--orange), #75964d 45%, var(--green));
box-shadow: 0 0 14px rgba(71, 126, 62, 0.25);
}
.phase-list {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 5px;
margin-top: 9px;
color: #8b9488;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.phase-list span {
transition: color 180ms ease;
}
.phase-list span.active {
color: var(--ink);
}
.controls {
position: absolute;
right: 24px;
bottom: 155px;
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 11px;
background: rgba(248, 249, 239, 0.9);
box-shadow: 0 8px 24px rgba(38, 53, 42, 0.09);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
backdrop-filter: blur(12px);
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
background: #fffef5;
transform: translateY(-2px);
}
button:active {
transform: translateY(0);
}
.hint {
position: absolute;
left: 24px;
bottom: 29px;
max-width: 190px;
color: rgba(35, 56, 43, 0.64);
font-size: 10px;
font-weight: 650;
line-height: 1.5;
}
.legend-dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 5px;
border-radius: 50%;
background: var(--green);
}
@media (max-width: 820px) {
.title-panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
.subtitle {
display: none;
}
.compression {
margin-top: 12px;
}
.time-panel {
top: 142px;
right: 14px;
width: 218px;
padding: 13px 14px;
}
.clock {
font-size: 25px;
}
.metrics {
margin-top: 10px;
}
.metric {
padding: 7px;
}
.metric strong {
font-size: 15px;
}
.timeline-panel {
bottom: 14px;
width: calc(100vw - 28px);
padding: 12px 14px;
}
.timeline-head small {
display: none;
}
.phase-list {
font-size: 7px;
}
.controls {
right: 14px;
bottom: 132px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="overlay">
<section class="panel title-panel">
<div class="eyebrow">Voxel field study · specimen 07</div>
<h1>Moss<br>Rehydration</h1>
<p class="subtitle">
Precipitation reaches a dormant cushion. Moisture spreads through the
substrate while every rooted stem expands its leaf blades in place.
</p>
<div class="compression">
<strong>18 h → 42 s</strong>
<span>≈ 25.7 simulated minutes per second</span>
</div>
</section>
<section class="panel time-panel">
<div class="time-top">
<span class="time-label">Simulated time</span>
<span class="time-scale">26 min / sec</span>
</div>
<div class="clock">
<span id="clock">06:00</span><small>/ 18 h study</small>
</div>
<div class="metrics">
<div class="metric">
<span>Relative humidity</span>
<strong id="humidity">28%</strong>
</div>
<div class="metric">
<span>Leaf turgor</span>
<strong id="turgor">12%</strong>
</div>
</div>
</section>
<div class="controls">
<button id="toggle" type="button" aria-label="Pause time-lapse">Pause</button>
<button id="restart" type="button">Restart</button>
<button id="resetCamera" type="button">Reset view</button>
</div>
<section class="panel timeline-panel">
<div class="timeline-head">
<span id="phaseName">01 / Dormant cushion</span>
<small>18 simulated hours compressed into 42 real seconds</small>
</div>
<div class="track">
<div class="track-fill" id="trackFill"></div>
</div>
<div class="phase-list" id="phaseList">
<span class="active">Dormant</span>
<span>Precipitation</span>
<span>Absorption</span>
<span>Expansion</span>
<span>Hydrated</span>
</div>
</section>
<div class="hint">
<span class="legend-dot"></span>
Drag to orbit · scroll to zoom<br />
Root anchors remain fixed throughout
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DURATION = 42;
const TAU = Math.PI * 2;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe6e9dd);
scene.fog = new THREE.Fog(0xe6e9dd, 15, 30);
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;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-7, 7, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.45, 0);
let yaw = 0.72;
let pitch = 0.57;
let zoom = 1;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight =
aspect < 0.8 ? 7.0 : aspect < 1.2 ? 5.65 : 4.35;
camera.left = -halfHeight * aspect / zoom;
camera.right = halfHeight * aspect / zoom;
camera.top = halfHeight / zoom;
camera.bottom = -halfHeight / zoom;
const radius = 12;
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);
camera.updateProjectionMatrix();
}
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
}
window.addEventListener("resize", resize);
updateCamera();
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
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 = THREE.MathUtils.clamp(pitch + dy * 0.0045, 0.22, 1.25);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.7,
1.8
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") yaw += 0.08;
if (event.key === "ArrowRight") yaw -= 0.08;
if (event.key === "ArrowUp") pitch = Math.min(1.25, pitch + 0.05);
if (event.key === "ArrowDown") pitch = Math.max(0.22, pitch - 0.05);
if (event.key === "+" || event.key === "=") zoom = Math.min(1.8, zoom * 1.08);
if (event.key === "-") zoom = Math.max(0.7, zoom / 1.08);
updateCamera();
});
const hemisphere = new THREE.HemisphereLight(0xf6f7e8, 0x65735b, 2.3);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5d5, 3.1);
sun.position.set(-5.5, 9, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9d5, 1.1);
fill.position.set(6, 4, -5);
scene.add(fill);
let seed = 73191;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function smoothstep(min, max, value) {
const x = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return x * x * (3 - 2 * x);
}
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xdfe3d5,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.2;
floor.receiveShadow = true;
scene.add(floor);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0xbec4b2,
roughness: 0.92
});
const stoneTopMaterial = new THREE.MeshStandardMaterial({
color: 0xd2d5c6,
roughness: 0.9
});
function addBox(size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
addBox(
new THREE.Vector3(7.9, 0.34, 4.85),
new THREE.Vector3(0, 0.02, 0),
stoneMaterial
);
addBox(
new THREE.Vector3(7.55, 0.09, 4.5),
new THREE.Vector3(0, 0.225, 0),
stoneTopMaterial
);
const rimHeight = 0.56;
const rimY = 0.48;
addBox(
new THREE.Vector3(7.5, rimHeight, 0.22),
new THREE.Vector3(0, rimY, -2.14),
stoneTopMaterial
);
addBox(
new THREE.Vector3(7.5, rimHeight, 0.22),
new THREE.Vector3(0, rimY, 2.14),
stoneTopMaterial
);
addBox(
new THREE.Vector3(0.22, rimHeight, 4.08),
new THREE.Vector3(-3.64, rimY, 0),
stoneTopMaterial
);
addBox(
new THREE.Vector3(0.22, rimHeight, 4.08),
new THREE.Vector3(3.64, rimY, 0),
stoneTopMaterial
);
const insetMaterial = new THREE.MeshStandardMaterial({
color: 0x76795d,
roughness: 1
});
addBox(
new THREE.Vector3(7.1, 0.12, 4.02),
new THREE.Vector3(0, 0.31, 0),
insetMaterial
);
const mossGeometry = new THREE.BoxGeometry(1, 1, 1);
const mossMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
metalness: 0
});
const dryPalette = [
new THREE.Color(0x8a7945),
new THREE.Color(0x776a3b),
new THREE.Color(0x9a8650),
new THREE.Color(0x685f38),
new THREE.Color(0x8e8250)
];
const wetPalette = [
new THREE.Color(0x497b3b),
new THREE.Color(0x365f35),
new THREE.Color(0x638b42),
new THREE.Color(0x285638),
new THREE.Color(0x729447)
];
const columns = [];
const mossInstances = [];
const baseY = 0.49;
const voxelHeight = 0.19;
const gridX = 30;
const gridZ = 18;
const stepX = 0.215;
const stepZ = 0.215;
for (let ix = 0; ix < gridX; ix++) {
for (let iz = 0; iz < gridZ; iz++) {
const x = (ix - (gridX - 1) / 2) * stepX;
const z = (iz - (gridZ - 1) / 2) * stepZ;
const edge = (x / 3.25) ** 2 + (z / 2.03) ** 2;
if (edge > 1.03 + (random() - 0.5) * 0.16) continue;
const mound = 1 - Math.min(1, edge);
const surfaceTarget =
0.98 + mound * 0.31 + random() * 0.11;
const layers = Math.max(
2,
Math.round((surfaceTarget - baseY) / voxelHeight)
);
const surfaceY = baseY + layers * voxelHeight;
columns.push({
x,
z,
surfaceY,
palette: Math.floor(random() * dryPalette.length)
});
for (let layer = 0; layer < layers; layer++) {
mossInstances.push({
x: x + (random() - 0.5) * 0.018,
y: baseY + (layer + 0.5) * voxelHeight,
z: z + (random() - 0.5) * 0.018,
palette: Math.floor(random() * dryPalette.length),
variation: 0.88 + random() * 0.2
});
}
}
}
const moss = new THREE.InstancedMesh(
mossGeometry,
mossMaterial,
mossInstances.length
);
moss.castShadow = true;
moss.receiveShadow = true;
const dummy = new THREE.Object3D();
const mossBaseColors = [];
const mossWetColors = [];
mossInstances.forEach((instance, index) => {
dummy.position.set(instance.x, instance.y, instance.z);
dummy.rotation.set(
(random() - 0.5) * 0.04,
(random() - 0.5) * 0.06,
(random() - 0.5) * 0.04
);
dummy.scale.set(
0.205 * instance.variation,
voxelHeight * 0.94,
0.205 * instance.variation
);
dummy.updateMatrix();
moss.setMatrixAt(index, dummy.matrix);
const base = dryPalette[instance.palette].clone();
base.multiplyScalar(instance.variation);
const wet = wetPalette[instance.palette].clone();
wet.multiplyScalar(instance.variation);
mossBaseColors.push(base);
mossWetColors.push(wet);
moss.setColorAt(index, base);
});
moss.instanceMatrix.needsUpdate = true;
moss.instanceColor.needsUpdate = true;
scene.add(moss);
function surfaceAt(x, z) {
let best = Infinity;
let result = 1.15;
for (const column of columns) {
const distance =
(column.x - x) ** 2 + (column.z - z) ** 2;
if (distance < best) {
best = distance;
result = column.surfaceY;
}
}
return result;
}
const impacts = [
[-2.55, 1.08, 0.145, 0.070],
[-1.82, 0.48, 0.165, 0.075],
[-1.02, 1.18, 0.183, 0.066],
[-0.18, 0.28, 0.198, 0.078],
[ 0.68, 1.08, 0.214, 0.069],
[ 1.53, 0.32, 0.230, 0.075],
[ 2.37, 0.88, 0.247, 0.065],
[-2.22, -0.62, 0.270, 0.077],
[-1.28, -1.08, 0.288, 0.070],
[-0.13, -0.54, 0.305, 0.075],
[ 1.08, -1.05, 0.322, 0.068],
[ 2.10, -0.43, 0.340, 0.078]
].map(([x, z, release, fall], index) => ({
x,
z,
release,
fall,
hit: release + fall,
index,
startX: x + (random() - 0.5) * 0.48,
startZ: z + (random() - 0.5) * 0.44,
startY: 5.15 + random() * 0.35,
size: 0.82 + random() * 0.35,
surfaceY: surfaceAt(x, z)
}));
function moistureAt(x, z, time) {
let moisture = 0;
for (const impact of impacts) {
if (time < impact.hit) continue;
const age = (time - impact.hit) * DURATION;
const distance = Math.hypot(x - impact.x, z - impact.z);
const core = Math.exp(
-(distance * distance) / (0.36 + age * 0.035)
);
const spreadRadius = 0.46 + age * 0.57;
const spread =
Math.max(0, 1 - distance / spreadRadius) * 0.88;
moisture = Math.max(moisture, core, spread);
}
return THREE.MathUtils.clamp(moisture, 0, 1);
}
const leafGeometry = new THREE.BoxGeometry(1, 1, 1);
leafGeometry.translate(0.5, 0, 0);
const unitGeometry = new THREE.BoxGeometry(1, 1, 1);
const dryStemColor = new THREE.Color(0x695c35);
const wetStemColor = new THREE.Color(0x315e35);
const dryLeafColor = new THREE.Color(0x777844);
const wetLeafColor = new THREE.Color(0x4f873d);
const selectedColumns = columns.slice();
for (let i = selectedColumns.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[selectedColumns[i], selectedColumns[j]] = [
selectedColumns[j],
selectedColumns[i]
];
}
const stems = [];
const rootSpacing = 0.225;
for (const column of selectedColumns) {
if (stems.length >= 68) break;
const tooClose = stems.some(
(stem) =>
Math.hypot(stem.x - column.x, stem.z - column.z) <
rootSpacing
);
if (tooClose) continue;
const stemMaterial = new THREE.MeshStandardMaterial({
color: dryStemColor,
roughness: 0.94
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: dryLeafColor,
roughness: 0.88
});
const root = new THREE.Group();
root.position.set(column.x, column.surfaceY, column.z);
scene.add(root);
const height = 0.34 + random() * 0.38;
const stem = new THREE.Mesh(unitGeometry, stemMaterial);
stem.scale.set(0.052, height, 0.052);
stem.position.y = height / 2;
stem.castShadow = true;
root.add(stem);
const rootFoot = new THREE.Mesh(unitGeometry, stemMaterial);
rootFoot.scale.set(0.105, 0.055, 0.105);
rootFoot.position.y = 0.01;
rootFoot.castShadow = true;
root.add(rootFoot);
const leafCluster = new THREE.Group();
leafCluster.position.y = height;
root.add(leafCluster);
const leaves = [];
const leafCount = 3;
for (let leafIndex = 0; leafIndex < leafCount; leafIndex++) {
const pivot = new THREE.Group();
pivot.rotation.y =
random() * TAU + (leafIndex / leafCount) * TAU;
leafCluster.add(pivot);
const leaf = new THREE.Mesh(leafGeometry, leafMaterial);
leaf.rotation.z = -0.08 - random() * 0.09;
leaf.castShadow = true;
leaf.receiveShadow = true;
pivot.add(leaf);
leaves.push({
pivot,
leaf,
length: 0.38 + random() * 0.38,
width: 0.22 + random() * 0.17,
phase: random() * TAU
});
}
const bud = new THREE.Mesh(unitGeometry, leafMaterial);
bud.position.y = 0.02;
bud.castShadow = true;
leafCluster.add(bud);
stems.push({
root,
leafCluster,
leaves,
bud,
stemMaterial,
leafMaterial,
x: column.x,
z: column.z,
phase: random() * TAU
});
}
const dropletGeometry = new THREE.BoxGeometry(0.12, 0.2, 0.12);
const dropletMaterial = new THREE.MeshStandardMaterial({
color: 0x62c7df,
roughness: 0.18,
metalness: 0.04,
transparent: true,
opacity: 0.93
});
const droplets = new THREE.InstancedMesh(
dropletGeometry,
dropletMaterial,
impacts.length
);
droplets.castShadow = true;
droplets.frustumCulled = false;
scene.add(droplets);
const ripples = impacts.map((impact) => {
const group = new THREE.Group();
group.position.set(impact.x, impact.surfaceY + 0.035, impact.z);
const material = new THREE.MeshStandardMaterial({
color: 0x73d0df,
roughness: 0.2,
transparent: true,
opacity: 0,
depthWrite: false
});
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * TAU;
const cube = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 0.035, 0.07),
material
);
cube.position.set(
Math.cos(angle) * 0.14,
0,
Math.sin(angle) * 0.14
);
cube.rotation.y = angle;
group.add(cube);
}
group.visible = false;
scene.add(group);
return { group, material };
});
const clockElement = document.getElementById("clock");
const humidityElement = document.getElementById("humidity");
const turgorElement = document.getElementById("turgor");
const phaseNameElement = document.getElementById("phaseName");
const trackFillElement = document.getElementById("trackFill");
const phaseElements = [
...document.getElementById("phaseList").children
];
const phaseLabels = [
"01 / Dormant cushion",
"02 / Precipitation reaches moss",
"03 / Moisture absorbed",
"04 / Leaf blades expanding",
"05 / Fully rehydrated"
];
function formatClock(minutes) {
const normalized = ((minutes % 1440) + 1440) % 1440;
const hours = Math.floor(normalized / 60);
const mins = Math.floor(normalized % 60);
return `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
}
let elapsed = 0;
let playing = true;
let phaseIndex = -1;
const toggleButton = document.getElementById("toggle");
const restartButton = document.getElementById("restart");
const resetCameraButton = document.getElementById("resetCamera");
toggleButton.addEventListener("click", () => {
playing = !playing;
toggleButton.textContent = playing ? "Pause" : "Play";
});
restartButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
toggleButton.textContent = "Pause";
});
resetCameraButton.addEventListener("click", () => {
yaw = 0.72;
pitch = 0.57;
zoom = 1;
updateCamera();
});
function updateUI(time) {
const simulatedMinutes = 6 * 60 + time * 18 * 60;
clockElement.textContent = formatClock(simulatedMinutes);
const humidity = Math.round(
28 + 66 * smoothstep(0.12, 0.94, time)
);
const turgor = Math.round(
12 + 84 * smoothstep(0.24, 0.93, time)
);
humidityElement.textContent = `${humidity}%`;
turgorElement.textContent = `${turgor}%`;
trackFillElement.style.width = `${(time * 100).toFixed(2)}%`;
const nextPhase =
time < 0.14 ? 0 :
time < 0.43 ? 1 :
time < 0.66 ? 2 :
time < 0.93 ? 3 : 4;
if (nextPhase !== phaseIndex) {
phaseIndex = nextPhase;
phaseNameElement.textContent = phaseLabels[phaseIndex];
phaseElements.forEach((element, index) => {
element.classList.toggle("active", index === phaseIndex);
});
}
}
const mossColor = new THREE.Color();
function updateScene(time, realTime) {
// Dry substrate gradually darkens and shifts toward chlorophyll green.
mossInstances.forEach((instance, index) => {
const moisture = moistureAt(instance.x, instance.z, time);
mossColor
.copy(mossBaseColors[index])
.lerp(mossWetColors[index], moisture * 0.94);
moss.setColorAt(index, mossColor);
});
moss.instanceColor.needsUpdate = true;
// Stem roots never move; only leaf geometry unfolds around fixed pivots.
stems.forEach((stem) => {
const moisture = moistureAt(stem.x, stem.z, time);
const expansion = smoothstep(0.08, 0.86, moisture);
stem.stemMaterial.color
.copy(dryStemColor)
.lerp(wetStemColor, smoothstep(0.05, 0.8, moisture));
stem.leafMaterial.color
.copy(dryLeafColor)
.lerp(wetLeafColor, smoothstep(0.08, 0.88, moisture));
stem.leaves.forEach((leafData) => {
const individualGrowth =
smoothstep(
0.08,
0.92,
moisture + Math.sin(realTime * 0.55 + leafData.phase) * 0.025
);
const growth = Math.max(0.001, individualGrowth);
leafData.leaf.scale.set(
leafData.length * growth,
0.075 * growth,
leafData.width * growth
);
const sway =
Math.sin(realTime * 0.8 + leafData.phase) *
0.035 *
expansion;
leafData.pivot.rotation.x = sway;
});
const budScale = 0.035 + 0.085 * expansion;
stem.bud.scale.set(budScale, budScale * 1.4, budScale);
});
// Falling voxel droplets, accelerating toward the cushion.
impacts.forEach((impact, index) => {
const local = time - impact.release;
let visible = local >= 0 && local <= impact.fall;
if (visible) {
const u = local / impact.fall;
const fall = Math.pow(u, 1.55);
const x = THREE.MathUtils.lerp(
impact.startX,
impact.x,
u
);
const z = THREE.MathUtils.lerp(
impact.startZ,
impact.z,
u
);
const y = THREE.MathUtils.lerp(
impact.startY,
impact.surfaceY + 0.11,
fall
);
dummy.position.set(x, y, z);
dummy.rotation.set(
0,
realTime * 1.6 + impact.index,
Math.sin(realTime * 2 + impact.index) * 0.12
);
dummy.scale.set(
impact.size * (0.75 + u * 0.3),
impact.size * (1.1 + u * 0.65),
impact.size * (0.75 + u * 0.3)
);
} else {
dummy.position.set(0, -20, 0);
dummy.scale.setScalar(0.0001);
}
dummy.updateMatrix();
droplets.setMatrixAt(index, dummy.matrix);
});
droplets.instanceMatrix.needsUpdate = true;
// Small expanding voxel splash rings mark absorption points.
ripples.forEach((ripple, index) => {
const impact = impacts[index];
const age = (time - impact.hit) * DURATION;
const active = age >= 0 && age < 1.15;
ripple.group.visible = active;
if (active) {
const u = age / 1.15;
ripple.group.scale.setScalar(1 + u * 4.4);
ripple.material.opacity = (1 - u) * 0.72;
}
});
}
const clock = new THREE.Clock();
let realTime = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
realTime += delta;
if (playing) {
elapsed = (elapsed + delta) % DURATION;
}
const time = elapsed / DURATION;
updateUI(time);
updateScene(time, realTime);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```