Prompt specification
Build or customize the Three.js 3D scene "Dryland planter microhabitats" 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: Dryland planter microhabitats
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/dryland-planter-microhabitats-x0795
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts succulent water storage. Compose rocks, sandy soil, succulents, and small shaded crevices; a rain pulse follows visible drainage paths while separate plant indicators represent illustrative stored-water changes. Stylized solid forms.
Working Three.js Starter (dryland-planter-microhabitats-x0795):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Succulent Water Storage</title>
<style>
:root {
--ink: #273d3c;
--muted: #667773;
--paper: #eee7d8;
--glass: rgba(246, 241, 228, 0.82);
--line: rgba(39, 61, 60, 0.16);
--water: #4f9fa8;
--water-light: #a9ded7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e0d0;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.plant-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(39, 61, 60, 0.18);
border-radius: 999px;
background: rgba(246, 241, 228, 0.9);
box-shadow: 0 6px 18px rgba(47, 57, 51, 0.09);
color: var(--ink);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
white-space: nowrap;
transform: translate(-50%, -115%);
transition: opacity 160ms ease;
}
.plant-label .swatch {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 3px rgba(79, 159, 168, 0.13);
}
.plant-label .value {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.hud {
position: fixed;
pointer-events: none;
z-index: 3;
}
.brand {
top: 28px;
left: 30px;
max-width: 390px;
}
.eyebrow {
margin-bottom: 9px;
color: #71817b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 52px);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 330px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.pulse-card {
top: 28px;
right: 28px;
width: 252px;
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--glass);
box-shadow: 0 16px 40px rgba(61, 65, 55, 0.09);
backdrop-filter: blur(12px);
}
.pulse-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.pulse-title {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.pulse-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 5px rgba(79, 159, 168, 0.12);
}
.phase {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
#phase-name {
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
letter-spacing: -0.02em;
}
#phase-number {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
.progress-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(39, 61, 60, 0.11);
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #397d85, #8bc9c4);
}
.metric-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
color: var(--muted);
font-size: 11px;
}
.metric-row strong {
color: var(--ink);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.legend {
left: 30px;
bottom: 28px;
display: flex;
flex-wrap: wrap;
gap: 15px;
max-width: 500px;
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(246, 241, 228, 0.76);
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #5f716c;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
}
.legend-mark {
width: 12px;
height: 7px;
border-radius: 2px;
}
.legend-mark.soil {
background: #d4b486;
}
.legend-mark.plant {
background: #729379;
}
.legend-mark.water {
background: #4f9fa8;
}
.legend-mark.gauge {
background: #344b49;
}
.hint {
right: 30px;
bottom: 30px;
color: rgba(39, 61, 60, 0.62);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
max-width: 230px;
}
.subtitle {
display: none;
}
.pulse-card {
top: 16px;
right: 16px;
width: 190px;
padding: 13px;
}
.eyebrow {
font-size: 8px;
}
#phase-name {
font-size: 16px;
}
.metric-row {
font-size: 9px;
}
.legend {
left: 16px;
bottom: 16px;
gap: 9px;
max-width: 280px;
padding: 10px;
}
.legend-item {
font-size: 8px;
}
.hint {
display: none;
}
.plant-label {
gap: 4px;
padding: 4px 7px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="labels"></div>
<section class="hud brand">
<div class="eyebrow">Pluvial field study · cycle 04</div>
<h1>Quiet<br>Reservoirs</h1>
<p class="subtitle">
A stylized study of succulents receiving brief rain pulses,
channeling runoff through sandy soil, and storing the remainder.
</p>
</section>
<section class="hud pulse-card">
<div class="pulse-head">
<div class="pulse-title">Live water cycle</div>
<div class="pulse-dot"></div>
</div>
<div class="phase">
<div id="phase-name">Rain arriving</div>
<div id="phase-number">01 / 03</div>
</div>
<div class="progress-track">
<div id="progress"></div>
</div>
<div class="metric-row">
<span>Illustrative stored water</span>
<strong id="storage-total">52%</strong>
</div>
<div class="metric-row">
<span>Drainage activity</span>
<strong id="drainage-state">Calm</strong>
</div>
</section>
<section class="hud legend">
<div class="legend-item">
<span class="legend-mark soil"></span>Sandy soil
</div>
<div class="legend-item">
<span class="legend-mark plant"></span>Succulent tissue
</div>
<div class="legend-item">
<span class="legend-mark water"></span>Runoff path
</div>
<div class="legend-item">
<span class="legend-mark gauge"></span>Storage indicator
</div>
</section>
<div class="hud hint">Drag to orbit · scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e0d0);
scene.fog = new THREE.Fog(0xe9e0d0, 17, 31);
const camera = new THREE.PerspectiveCamera(
35,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional succulent water storage diorama"
);
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8e9, 0x817363, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3d8, 3.3);
sun.position.set(-5.5, 10, 7.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 = 1;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9dbbc0, 0.55);
fill.position.set(7, 5, -5);
scene.add(fill);
const clock = new THREE.Clock();
const world = new THREE.Group();
scene.add(world);
// ------------------------------------------------------------
// Deterministic helpers
// ------------------------------------------------------------
let seed = 18347;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function smooth(a, b, x) {
const t = THREE.MathUtils.clamp((x - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function terrainHeight(x, z) {
const q = Math.sqrt(
(x * x) / (4.75 * 4.75) +
(z * z) / (3.45 * 3.45)
);
const centralMound =
0.34 * Math.exp(-q * q * 1.3) +
0.19 * Math.exp(
-((x + 1.1) ** 2 + (z + 0.8) ** 2) / 1.45
) +
0.09 * Math.exp(
-((x - 1.35) ** 2 + (z - 0.9) ** 2) / 1.8
);
const ripple =
0.028 *
Math.sin(x * 2.1 + z * 1.3) *
Math.sin(z * 2.4 - x * 0.7);
return (
centralMound * (1 - smooth(0.68, 1, q)) +
ripple * (1 - smooth(0.75, 1, q)) -
0.05 * smooth(0.85, 1, q)
);
}
function flatMaterial(color, roughness = 0.88) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true
});
}
// ------------------------------------------------------------
// Sand island and lower strata
// ------------------------------------------------------------
const base = new THREE.Mesh(
new THREE.CylinderGeometry(4.88, 4.67, 0.72, 56),
flatMaterial(0xb68c68)
);
base.scale.z = 0.73;
base.position.y = -0.41;
base.castShadow = true;
base.receiveShadow = true;
world.add(base);
const lowerBand = new THREE.Mesh(
new THREE.CylinderGeometry(4.69, 4.48, 0.18, 56),
flatMaterial(0x9c7458)
);
lowerBand.scale.z = 0.73;
lowerBand.position.y = -0.79;
lowerBand.castShadow = true;
world.add(lowerBand);
function createTerrain() {
const rings = 18;
const segments = 72;
const positions = [];
const colors = [];
const indices = [];
const lightSand = new THREE.Color(0xe6d0a6);
const midSand = new THREE.Color(0xd3b183);
const darkSand = new THREE.Color(0xba936b);
const color = new THREE.Color();
positions.push(0, terrainHeight(0, 0), 0);
color.copy(midSand);
colors.push(color.r, color.g, color.b);
for (let ring = 1; ring <= rings; ring++) {
const radius = ring / rings;
for (let segment = 0; segment < segments; segment++) {
const angle = (segment / segments) * Math.PI * 2;
const x = Math.cos(angle) * 4.75 * radius;
const z = Math.sin(angle) * 3.45 * radius;
const y = terrainHeight(x, z);
positions.push(x, y, z);
const variation =
0.45 +
0.24 * Math.sin(x * 1.8 + z * 0.7) +
random() * 0.16;
color.copy(midSand).lerp(lightSand, variation);
if (y < 0.04) {
color.lerp(darkSand, 0.2);
}
colors.push(color.r, color.g, color.b);
}
}
const indexAt = (ring, segment) =>
1 + (ring - 1) * segments + (segment % segments);
for (let segment = 0; segment < segments; segment++) {
indices.push(
0,
indexAt(1, segment + 1),
indexAt(1, segment)
);
}
for (let ring = 1; ring < rings; ring++) {
for (let segment = 0; segment < segments; segment++) {
const innerCurrent = indexAt(ring, segment);
const innerNext = indexAt(ring, segment + 1);
const outerCurrent = indexAt(ring + 1, segment);
const outerNext = indexAt(ring + 1, segment + 1);
indices.push(
innerCurrent,
outerNext,
outerCurrent,
innerCurrent,
innerNext,
outerNext
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
world.add(mesh);
}
createTerrain();
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
flatMaterial(0xd9cfbd, 1)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.9;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Rocks and shaded crevices
// ------------------------------------------------------------
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const rockMaterials = [
flatMaterial(0x8d8c7d),
flatMaterial(0x9b927e),
flatMaterial(0x7d8177),
flatMaterial(0xaaa087)
];
const rockSpecs = [
[-2.95, 1.75, 0.88, 0.57, 0.68],
[-3.35, 1.12, 0.65, 0.46, 0.55],
[-1.70, 2.12, 0.54, 0.38, 0.47],
[2.80, 1.85, 0.91, 0.59, 0.68],
[3.27, 1.34, 0.63, 0.44, 0.54],
[1.80, 2.30, 0.49, 0.34, 0.43],
[-3.20, -1.18, 0.66, 0.42, 0.52],
[-2.80, -1.62, 0.40, 0.28, 0.35],
[3.18, -0.93, 0.72, 0.47, 0.56],
[2.80, -1.42, 0.39, 0.27, 0.33],
[-3.48, 0.23, 0.38, 0.27, 0.35],
[3.52, 0.27, 0.35, 0.25, 0.32],
[-1.55, -2.42, 0.36, 0.24, 0.31],
[1.48, -2.48, 0.41, 0.28, 0.34]
];
rockSpecs.forEach((spec, index) => {
const [x, z, sx, sy, sz] = spec;
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[index % rockMaterials.length]
);
rock.position.set(
x,
terrainHeight(x, z) + sy * 0.56,
z
);
rock.scale.set(sx, sy, sz);
rock.rotation.set(
random() * 0.4,
random() * Math.PI,
random() * 0.22
);
rock.castShadow = true;
rock.receiveShadow = true;
world.add(rock);
});
const creviceGeometry = new THREE.SphereGeometry(1, 16, 8);
const creviceMaterial = flatMaterial(0x493f3b, 1);
const crevices = [
[-3.02, 1.33, 0.54, 0.035, 0.18],
[2.96, 1.38, 0.50, 0.035, 0.19],
[-2.94, -1.33, 0.43, 0.030, 0.14],
[2.95, -1.18, 0.46, 0.030, 0.15],
[-1.48, 2.00, 0.34, 0.025, 0.12],
[1.62, 2.16, 0.35, 0.025, 0.12]
];
crevices.forEach(([x, z, sx, sy, sz]) => {
const crevice = new THREE.Mesh(
creviceGeometry,
creviceMaterial
);
crevice.position.set(x, terrainHeight(x, z) + 0.015, z);
crevice.scale.set(sx, sy, sz);
world.add(crevice);
});
// Small scattered mineral grains.
const pebbleGeometry = new THREE.IcosahedronGeometry(0.07, 0);
const pebbleMaterial = flatMaterial(0xb99f7a);
const pebbles = new THREE.InstancedMesh(
pebbleGeometry,
pebbleMaterial,
110
);
const dummy = new THREE.Object3D();
for (let i = 0; i < 110; i++) {
const x = (random() - 0.5) * 8.4;
const z = (random() - 0.5) * 5.9;
const scale = 0.45 + random() * 1.15;
dummy.position.set(x, terrainHeight(x, z) + 0.025, z);
dummy.rotation.set(random(), random() * Math.PI, random());
dummy.scale.set(scale, scale * 0.45, scale * 0.8);
dummy.updateMatrix();
pebbles.setMatrixAt(i, dummy.matrix);
}
pebbles.castShadow = true;
pebbles.receiveShadow = true;
world.add(pebbles);
// ------------------------------------------------------------
// Faceted solid leaf geometry
// ------------------------------------------------------------
function createLeafGeometry() {
const sections = [
{ y: 0.00, width: 0.025, depth: 0.018 },
{ y: 0.18, width: 0.260, depth: 0.105 },
{ y: 0.63, width: 0.215, depth: 0.080 },
{ y: 1.00, width: 0.002, depth: 0.002 }
];
const positions = [];
const indices = [];
sections.forEach((section) => {
const { y, width, depth } = section;
positions.push(
-width, y, -depth,
width, y, -depth,
width, y, depth,
-width, y, depth
);
});
for (let section = 0; section < sections.length - 1; section++) {
for (let side = 0; side < 4; side++) {
const a = section * 4 + side;
const b = section * 4 + (side + 1) % 4;
const c = (section + 1) * 4 + side;
const d = (section + 1) * 4 + (side + 1) % 4;
indices.push(a, d, b, a, c, d);
}
}
const bottomCenter = positions.length / 3;
positions.push(0, 0, 0);
for (let side = 0; side < 4; side++) {
indices.push(bottomCenter, side, (side + 1) % 4);
}
const topCenter = positions.length / 3;
positions.push(0, 1, 0);
const topOffset = (sections.length - 1) * 4;
for (let side = 0; side < 4; side++) {
indices.push(
topCenter,
topOffset + (side + 1) % 4,
topOffset + side
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const leafGeometry = createLeafGeometry();
function leafMaterial(color, lightnessOffset = 0) {
const adjusted = new THREE.Color(color).offsetHSL(
0,
0,
lightnessOffset
);
return new THREE.MeshStandardMaterial({
color: adjusted,
roughness: 0.7,
metalness: 0,
flatShading: true
});
}
const up = new THREE.Vector3(0, 1, 0);
const basisMatrix = new THREE.Matrix4();
const leafDirection = new THREE.Vector3();
const leafTangent = new THREE.Vector3();
const leafNormal = new THREE.Vector3();
function addLeaf(group, angle, tilt, length, size, material) {
leafDirection.set(
Math.cos(angle) * Math.sin(tilt),
Math.cos(tilt),
Math.sin(angle) * Math.sin(tilt)
).normalize();
leafTangent.set(
-Math.sin(angle),
0,
Math.cos(angle)
);
leafTangent.addScaledVector(
leafDirection,
-leafTangent.dot(leafDirection)
).normalize();
leafNormal.crossVectors(leafTangent, leafDirection).normalize();
basisMatrix.makeBasis(
leafTangent,
leafDirection,
leafNormal
);
const leaf = new THREE.Mesh(leafGeometry, material);
leaf.quaternion.setFromRotationMatrix(basisMatrix);
leaf.scale.set(size * 1.15, size * length, size * 1.15);
leaf.position.y = 0.035;
leaf.castShadow = true;
leaf.receiveShadow = true;
group.add(leaf);
}
function createRosette(x, z, size, baseColor, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, terrainHeight(x, z) + 0.025, z);
group.rotation.y = rotation;
const outer = leafMaterial(baseColor, 0.035);
const middle = leafMaterial(baseColor, 0.09);
const inner = leafMaterial(baseColor, 0.16);
const outerCount = 11;
const middleCount = 8;
const innerCount = 5;
for (let i = 0; i < outerCount; i++) {
addLeaf(
group,
rotation + (i / outerCount) * Math.PI * 2,
1.12,
0.98,
size,
outer
);
}
for (let i = 0; i < middleCount; i++) {
addLeaf(
group,
rotation + 0.28 + (i / middleCount) * Math.PI * 2,
0.77,
0.72,
size * 0.95,
middle
);
}
for (let i = 0; i < innerCount; i++) {
addLeaf(
group,
rotation + 0.58 + (i / innerCount) * Math.PI * 2,
0.42,
0.46,
size * 0.85,
inner
);
}
const center = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17 * size, 1),
leafMaterial(baseColor, 0.2)
);
center.position.y = 0.16 * size;
center.scale.y = 0.7;
center.castShadow = true;
group.add(center);
world.add(group);
return group;
}
// ------------------------------------------------------------
// Drainage paths
// ------------------------------------------------------------
const pathDefinitions = [
[
[-2.65, 1.70],
[-2.10, 1.20],
[-1.55, 0.80],
[-1.25, 0.15],
[-0.90, -0.65],
[-0.45, -1.65],
[-0.15, -2.82]
],
[
[2.55, 1.65],
[2.10, 1.05],
[1.60, 0.55],
[1.25, -0.15],
[1.45, -0.95],
[1.90, -1.80],
[2.20, -2.62]
],
[
[-0.35, 2.15],
[-0.25, 1.55],
[0.05, 0.95],
[0.25, 0.25],
[0.20, -0.65],
[-0.15, -1.65]
]
];
const drainagePaths = [];
const grooveMaterial = flatMaterial(0x8c7057, 1);
pathDefinitions.forEach((definition, pathIndex) => {
const points = definition.map(([x, z]) =>
new THREE.Vector3(x, terrainHeight(x, z) + 0.035, z)
);
const curve = new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.42
);
const groove = new THREE.Mesh(
new THREE.TubeGeometry(curve, 96, 0.065, 6, false),
grooveMaterial
);
groove.receiveShadow = true;
world.add(groove);
const channelMaterial = new THREE.MeshStandardMaterial({
color: pathIndex === 2 ? 0x4d929a : 0x579fa6,
emissive: 0x2b7b82,
emissiveIntensity: 0.12,
roughness: 0.52,
metalness: 0,
flatShading: true
});
const channel = new THREE.Mesh(
new THREE.TubeGeometry(curve, 96, 0.027, 6, false),
channelMaterial
);
world.add(channel);
const beads = [];
const beadGeometry = new THREE.IcosahedronGeometry(0.075, 1);
const beadMaterial = new THREE.MeshStandardMaterial({
color: 0xc2f2e9,
emissive: 0x66c8c4,
emissiveIntensity: 0.65,
roughness: 0.35,
flatShading: true
});
for (let i = 0; i < 6; i++) {
const bead = new THREE.Mesh(beadGeometry, beadMaterial);
bead.visible = false;
bead.castShadow = true;
world.add(bead);
beads.push(bead);
}
drainagePaths.push({
curve,
channelMaterial,
beads
});
});
const poolMaterial = new THREE.MeshStandardMaterial({
color: 0x6eafb3,
emissive: 0x387f84,
emissiveIntensity: 0.12,
roughness: 0.42,
flatShading: true
});
const pools = [];
[
[-0.15, -2.82],
[2.20, -2.62]
].forEach(([x, z]) => {
const pool = new THREE.Mesh(
new THREE.CircleGeometry(0.23, 20),
poolMaterial
);
pool.rotation.x = -Math.PI / 2;
pool.scale.set(1.45, 0.72, 1);
pool.position.set(x, terrainHeight(x, z) + 0.038, z);
world.add(pool);
pools.push(pool);
});
// ------------------------------------------------------------
// Succulents and separate storage indicators
// ------------------------------------------------------------
const plantSpecs = [
{
name: "A / SAGE",
x: -2.25,
z: -0.15,
size: 1.08,
color: 0x789878,
gaugeX: -1.24,
gaugeZ: -0.50,
baseStorage: 0.48,
gain: 0.35,
delay: 0.10
},
{
name: "B / ECHO",
x: -0.58,
z: -1.86,
size: 1.25,
color: 0x5e8a73,
gaugeX: 0.34,
gaugeZ: -2.23,
baseStorage: 0.61,
gain: 0.25,
delay: 0.30
},
{
name: "C / MOSS",
x: 1.18,
z: -0.46,
size: 0.94,
color: 0x88a66f,
gaugeX: 2.22,
gaugeZ: -0.38,
baseStorage: 0.41,
gain: 0.38,
delay: 0.50
},
{
name: "D / FERN",
x: 2.45,
z: 1.03,
size: 0.86,
color: 0x708f80,
gaugeX: 3.30,
gaugeZ: 0.52,
baseStorage: 0.56,
gain: 0.28,
delay: 0.65
},
{
name: "E / LIME",
x: 0.03,
z: 1.20,
size: 0.72,
color: 0x98a56a,
gaugeX: 0.85,
gaugeZ: 1.72,
baseStorage: 0.46,
gain: 0.32,
delay: 0.80
}
];
const gaugeFrameMaterial = flatMaterial(0x314a48, 0.82);
const gaugeTickMaterial = flatMaterial(0xe9dfc8, 0.9);
const gaugeStemMaterial = flatMaterial(0x8b8d79, 0.9);
const gaugeFillMaterial = new THREE.MeshStandardMaterial({
color: 0x5fb2b8,
emissive: 0x347e84,
emissiveIntensity: 0.22,
roughness: 0.5,
flatShading: true
});
const gauges = [];
const labelContainer = document.getElementById("labels");
plantSpecs.forEach((spec, index) => {
createRosette(
spec.x,
spec.z,
spec.size,
spec.color,
random() * Math.PI
);
const gauge = new THREE.Group();
gauge.position.set(
spec.gaugeX,
terrainHeight(spec.gaugeX, spec.gaugeZ) + 0.015,
spec.gaugeZ
);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.045, 0.23, 8),
gaugeStemMaterial
);
stem.position.y = 0.115;
stem.castShadow = true;
gauge.add(stem);
const back = new THREE.Mesh(
new THREE.BoxGeometry(0.205, 0.72, 0.075),
gaugeFrameMaterial
);
back.position.y = 0.53;
back.castShadow = true;
gauge.add(back);
for (let tick = 0; tick < 5; tick++) {
const tickMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.225, 0.016, 0.085),
gaugeTickMaterial
);
tickMesh.position.set(0, 0.235 + tick * 0.125, 0.01);
gauge.add(tickMesh);
}
const fill = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 1, 0.055),
gaugeFillMaterial.clone()
);
fill.position.set(0, 0.35, 0.052);
gauge.add(fill);
const marker = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.055, 1),
flatMaterial(0xc5eee6, 0.45)
);
marker.position.set(0, 0.45, 0.088);
gauge.add(marker);
world.add(gauge);
const label = document.createElement("div");
label.className = "plant-label";
label.innerHTML = `
<span class="swatch"></span>
<span>${spec.name}</span>
<span class="value">50%</span>
`;
labelContainer.appendChild(label);
gauges.push({
group: gauge,
fill,
marker,
label,
value: label.querySelector(".value"),
spec,
storage: spec.baseStorage,
index
});
});
// ------------------------------------------------------------
// Rain pulse particles
// ------------------------------------------------------------
const rainGroup = new THREE.Group();
world.add(rainGroup);
const rainGeometry = new THREE.IcosahedronGeometry(0.035, 0);
const rainMaterial = new THREE.MeshStandardMaterial({
color: 0x78b9c0,
emissive: 0x467f88,
emissiveIntensity: 0.35,
roughness: 0.35,
flatShading: true
});
const rainDrops = [];
for (let i = 0; i < 52; i++) {
const drop = new THREE.Mesh(rainGeometry, rainMaterial);
const x = (random() - 0.5) * 8.1;
const z = (random() - 0.5) * 5.5;
drop.userData = {
x,
z,
offset: random(),
speed: 0.8 + random() * 0.45
};
drop.scale.y = 2.7;
drop.visible = false;
rainGroup.add(drop);
rainDrops.push(drop);
}
// ------------------------------------------------------------
// Direct orbit controls — no addons
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 0.32, 0);
let yaw = 0.68;
let pitch = 0.55;
let radius = innerWidth < 760 ? 19 : 15.5;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(
pitch + dy * 0.004,
0.30,
1.04
);
pointerX = event.clientX;
pointerY = event.clientY;
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
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();
radius = THREE.MathUtils.clamp(
radius + event.deltaY * 0.012,
10.5,
23
);
},
{ passive: false }
);
function updateCamera() {
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
// ------------------------------------------------------------
// Animation and responsive behavior
// ------------------------------------------------------------
const phaseName = document.getElementById("phase-name");
const phaseNumber = document.getElementById("phase-number");
const progressBar = document.getElementById("progress");
const storageTotal = document.getElementById("storage-total");
const drainageState = document.getElementById("drainage-state");
const CYCLE = 12;
const RAIN_END = 2.2;
const FLOW_START = 1.8;
const FLOW_END = 9.0;
const projected = new THREE.Vector3();
const anchor = new THREE.Vector3();
function updateStorage(cycleTime) {
let total = 0;
gauges.forEach((gauge) => {
const { spec } = gauge;
const rise = smooth(
2.2 + spec.delay,
4.8 + spec.delay,
cycleTime
);
const fall = smooth(
7.8 + spec.delay,
11.2 + spec.delay,
cycleTime
);
const wet = Math.max(0, rise * (1 - fall));
const storage = THREE.MathUtils.clamp(
spec.baseStorage + spec.gain * wet,
0,
1
);
gauge.storage = storage;
total += storage;
const fillHeight = storage * 0.58;
gauge.fill.scale.y = storage;
gauge.fill.position.y = 0.20 + fillHeight * 0.5;
gauge.marker.position.y = 0.20 + fillHeight;
const percent = Math.round(storage * 100);
gauge.value.textContent = `${percent}%`;
});
storageTotal.textContent = `${Math.round((total / gauges.length) * 100)}%`;
}
function updateLabels() {
gauges.forEach((gauge) => {
anchor.set(0, 1.04, 0);
gauge.group.localToWorld(anchor);
projected.copy(anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
gauge.label.style.left = `${x}px`;
gauge.label.style.top = `${y}px`;
gauge.label.style.opacity = visible ? "1" : "0";
});
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const cycleTime = elapsed % CYCLE;
const raining = cycleTime < RAIN_END;
const flowing = cycleTime >= FLOW_START && cycleTime < FLOW_END;
updateCamera();
if (raining) {
phaseName.textContent = "Rain arriving";
phaseNumber.textContent = "01 / 03";
drainageState.textContent = "Incoming";
} else if (flowing) {
phaseName.textContent = "Drainage pulse";
phaseNumber.textContent = "02 / 03";
drainageState.textContent = "Active";
} else {
phaseName.textContent = "Stored & slowly released";
phaseNumber.textContent = "03 / 03";
drainageState.textContent = "Receding";
}
progressBar.style.width = `${(cycleTime / CYCLE) * 100}%`;
// Rain falls only during the opening portion of each cycle.
rainDrops.forEach((drop) => {
drop.visible = raining;
if (raining) {
const data = drop.userData;
const progress = (
cycleTime * data.speed + data.offset
) % 1;
const ground = terrainHeight(data.x, data.z);
drop.position.set(
data.x,
ground + 0.08 + (1 - progress) * 4.7,
data.z
);
}
});
// Visible channels brighten and animated water beads travel
// from the high rocks down toward collection pools.
const flowTime = cycleTime - FLOW_START;
drainagePaths.forEach((path, pathIndex) => {
path.channelMaterial.emissiveIntensity = flowing
? 0.38 + 0.14 * Math.sin(elapsed * 5 + pathIndex)
: 0.10;
path.beads.forEach((bead, beadIndex) => {
bead.visible = flowing;
if (flowing) {
const progress = (
flowTime * 0.205 +
beadIndex / path.beads.length +
pathIndex * 0.07
) % 1;
path.curve.getPointAt(progress, bead.position);
bead.position.y += 0.065;
const pulse = 1 + 0.16 * Math.sin(elapsed * 8 + beadIndex);
bead.scale.setScalar(pulse);
}
});
});
pools.forEach((pool, index) => {
const poolPulse = flowing
? 1 + 0.12 * Math.sin(elapsed * 4 + index)
: 1;
pool.scale.set(1.45 * poolPulse, 0.72 * poolPulse, 1);
});
updateStorage(cycleTime);
scene.updateMatrixWorld(true);
updateLabels();
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
if (innerWidth < 760) {
radius = THREE.MathUtils.clamp(radius, 17, 23);
}
});
animate();
</script>
</body>
</html>
```