Prompt specification
Build or customize the Three.js 3D scene "Community garden soil restoration scene" 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: Community garden soil restoration scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-garden-soil-restoration-scene-x1187
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts soil horizons. Build adjacent compacted and mulched garden beds, root cutaways, and a rain barrel; show water pathways and root space as schematic comparisons. Voxel style.
Working Three.js Starter (community-garden-soil-restoration-scene-x1187):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dce5df" />
<title>Soil Horizons — Voxel Field Study</title>
<style>
:root {
--ink: #25302c;
--muted: #65716b;
--paper: rgba(249, 247, 239, 0.93);
--line: rgba(37, 48, 44, 0.16);
--water: #31b8d3;
--root: #e3c67c;
--compact: #b87945;
--mulch: #426b45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
box-shadow:
0 16px 50px rgba(39, 53, 46, 0.12),
inset 0 0 0 1px rgba(37, 48, 44, 0.06);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 22px;
left: 22px;
width: 350px;
padding: 20px 22px 18px;
border-radius: 4px 18px 18px 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 11px;
color: #53635c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 19px;
height: 3px;
content: "";
background: #77977d;
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 40px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.intro-copy {
max-width: 300px;
margin: 12px 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.control {
min-height: 31px;
padding: 7px 10px;
border: 1px solid rgba(37, 48, 44, 0.16);
border-radius: 999px;
background: rgba(255, 255, 255, 0.38);
color: #4b5953;
cursor: pointer;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.control:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.8);
}
.control.active {
border-color: #536f61;
background: #536f61;
color: #fffdf5;
}
#legend {
top: 22px;
right: 22px;
width: 225px;
padding: 16px 17px;
border-radius: 16px 4px 16px 16px;
}
.section-title {
margin: 0 0 12px;
color: #65716b;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 13px 1fr;
align-items: center;
gap: 9px;
margin-top: 8px;
color: #4f5d57;
font-size: 10px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.horizon-strip {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 3px;
margin: 8px 0 12px;
}
.horizon-strip span {
height: 8px;
border-radius: 2px;
}
#compare {
bottom: 22px;
left: 50%;
display: grid;
grid-template-columns: 1fr 1fr;
width: min(650px, calc(100vw - 44px));
overflow: hidden;
border-radius: 16px 16px 5px 16px;
transform: translateX(-50%);
}
.comparison-card {
padding: 14px 17px 15px;
}
.comparison-card + .comparison-card {
border-left: 1px solid var(--line);
}
.card-heading {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.card-heading::before {
width: 8px;
height: 8px;
content: "";
border-radius: 2px;
background: var(--compact);
}
.comparison-card:last-child .card-heading::before {
background: var(--mulch);
}
.metrics {
display: flex;
gap: 18px;
}
.metric strong {
display: block;
font-size: 15px;
letter-spacing: -0.03em;
}
.metric span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#hint {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 8;
padding: 9px 12px;
border-radius: 8px;
background: rgba(249, 247, 239, 0.78);
color: #65716b;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
pointer-events: none;
}
#label-layer {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(37, 48, 44, 0.12);
border-radius: 5px;
background: rgba(250, 248, 240, 0.9);
box-shadow: 0 6px 18px rgba(31, 47, 39, 0.09);
color: #35433d;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
}
.scene-label::before {
width: 6px;
height: 6px;
flex: 0 0 auto;
content: "";
border-radius: 1px;
background: #7f8f87;
}
.scene-label.bed-label {
padding: 8px 10px;
font-size: 9px;
}
.scene-label.water-label::before {
background: var(--water);
}
.scene-label.root-label::before {
background: var(--root);
}
.scene-label.horizon-label {
padding: 4px 6px;
font-size: 7px;
}
.scene-label.horizon-label::before {
display: none;
}
.scene-label.horizon-label.o::before {
display: block;
width: 7px;
height: 7px;
background: #4d3827;
}
.scene-label.horizon-label.a::before {
display: block;
width: 7px;
height: 7px;
background: #69462e;
}
.scene-label.horizon-label.b::before {
display: block;
width: 7px;
height: 7px;
background: #c58b54;
}
.scene-label.horizon-label.c::before {
display: block;
width: 7px;
height: 7px;
background: #a6784e;
}
.scene-label.organic::before {
background: #b67b43;
}
@media (max-width: 860px) {
#intro {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 16px 17px;
}
.intro-copy {
margin-bottom: 12px;
}
#legend {
display: none;
}
#compare {
bottom: 12px;
width: calc(100vw - 24px);
}
#hint {
display: none;
}
}
@media (max-width: 560px) {
h1 {
font-size: 27px;
}
.intro-copy {
display: none;
}
.eyebrow {
margin-bottom: 9px;
}
.comparison-card {
padding: 11px 12px;
}
.metrics {
gap: 10px;
}
.metric strong {
font-size: 12px;
}
.metric span {
font-size: 6px;
}
.card-heading {
font-size: 8px;
}
.scene-label.minor {
display: none !important;
}
}
@media (prefers-reduced-motion: reduce) {
.control {
transition: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="label-layer"></div>
<section id="intro" class="panel" aria-label="Scene introduction">
<div class="eyebrow">Field study / soil horizons 01</div>
<h1>Soil, water<br />& root space.</h1>
<p class="intro-copy">
A voxel cutaway comparing a compacted bed with a mulch-covered bed.
Water movement and root architecture are shown schematically.
</p>
<div class="controls">
<button class="control active" data-layer="water" aria-pressed="true">
Water pathways
</button>
<button class="control active" data-layer="roots" aria-pressed="true">
Root space
</button>
<button class="control" id="reset-view">Reset view</button>
</div>
</section>
<aside id="legend" class="panel" aria-label="Legend">
<h2 class="section-title">Horizon key</h2>
<div class="horizon-strip" aria-hidden="true">
<span style="background:#4d3827"></span>
<span style="background:#69462e"></span>
<span style="background:#c58b54"></span>
<span style="background:#a6784e"></span>
</div>
<div class="legend-row">
<i class="swatch" style="background:#4d3827"></i>
<span>O — organic mulch</span>
</div>
<div class="legend-row">
<i class="swatch" style="background:#69462e"></i>
<span>A — topsoil</span>
</div>
<div class="legend-row">
<i class="swatch" style="background:#c58b54"></i>
<span>B — subsoil</span>
</div>
<div class="legend-row">
<i class="swatch" style="background:#a6784e"></i>
<span>C — parent material</span>
</div>
<div class="legend-row">
<i class="swatch" style="background:#31b8d3"></i>
<span>Water movement</span>
</div>
<div class="legend-row">
<i class="swatch" style="background:#e3c67c"></i>
<span>Root pathways</span>
</div>
</aside>
<section id="compare" class="panel" aria-label="Soil comparison">
<article class="comparison-card">
<div class="card-heading">Compacted bed</div>
<div class="metrics">
<div class="metric">
<strong>18%</strong>
<span>Pore space</span>
</div>
<div class="metric">
<strong>35 cm</strong>
<span>Root depth</span>
</div>
<div class="metric">
<strong>High</strong>
<span>Runoff</span>
</div>
</div>
</article>
<article class="comparison-card">
<div class="card-heading">Mulched bed</div>
<div class="metrics">
<div class="metric">
<strong>42%</strong>
<span>Pore space</span>
</div>
<div class="metric">
<strong>90 cm</strong>
<span>Root depth</span>
</div>
<div class="metric">
<strong>Deep</strong>
<span>Infiltration</span>
</div>
</div>
</article>
</section>
<div id="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const container = document.querySelector("#scene");
const labelLayer = document.querySelector("#label-layer");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5df);
scene.fog = new THREE.Fog(0xdce5df, 19, 36);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 80);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("aria-label", "Interactive voxel soil-horizon scene");
scene.add(new THREE.HemisphereLight(0xf7f2df, 0x73816f, 2.25));
const sun = new THREE.DirectionalLight(0xfff3d4, 3.25);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 36;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa7d8e5, 1.2);
fill.position.set(9, 6, -8);
scene.add(fill);
// ------------------------------------------------------------
// Shared voxel geometry and material helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function addBox(parent, x, y, z, w, h, d, material, options = {}) {
const mesh = new THREE.Mesh(
unitBox,
material && material.isMaterial ? material : getMaterial(material)
);
mesh.position.set(x, y, z);
mesh.scale.set(w, h, d);
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(82173);
const rootsGroup = new THREE.Group();
const waterGroup = new THREE.Group();
scene.add(rootsGroup, waterGroup);
const plantGroups = [];
const labels = [];
const flows = [];
const rainDrops = [];
// ------------------------------------------------------------
// Ground and diorama base
// ------------------------------------------------------------
const ground = new THREE.Group();
scene.add(ground);
addBox(ground, 0, -0.48, 0, 16.3, 0.86, 10.3, 0x8b9c89);
addBox(ground, 0, -0.08, 0, 16.0, 0.12, 10.0, 0x9ba895);
const tileColors = [0xa9b5a1, 0xa2af9b, 0xb0baa7, 0x9eac97];
for (let x = 0; x < 8; x++) {
for (let z = 0; z < 5; z++) {
addBox(
ground,
-7 + x * 2,
0.015,
-4 + z * 2,
1.93,
0.055,
1.93,
tileColors[(x + z * 2) % tileColors.length],
{ castShadow: false }
);
}
}
// Small blocky grass tufts around the perimeter.
const grassColors = [0x68885d, 0x779767, 0x526f50];
for (let i = 0; i < 46; i++) {
const edge = i % 4;
let x;
let z;
if (edge === 0) {
x = -7.5 + random() * 15;
z = -4.5 + random() * 0.65;
} else if (edge === 1) {
x = -7.5 + random() * 15;
z = 3.85 + random() * 0.65;
} else if (edge === 2) {
x = -7.6 + random() * 0.65;
z = -4.2 + random() * 8.4;
} else {
x = 7 + random() * 0.65;
z = -4.2 + random() * 8.4;
}
const h = 0.13 + random() * 0.24;
addBox(
ground,
x,
0.1 + h / 2,
z,
0.07,
h,
0.08,
grassColors[i % grassColors.length]
);
}
// ------------------------------------------------------------
// Garden beds with exposed horizons
// ------------------------------------------------------------
function makeBed({ x, compacted, seed }) {
const bed = new THREE.Group();
bed.position.x = x;
scene.add(bed);
const width = 5.4;
const depth = 4.4;
const front = depth / 2;
const horizonColors = compacted
? {
c: 0xa6784e,
b: 0xc18a55,
a: 0x69462e,
o: 0x80664b
}
: {
c: 0xb58a5b,
b: 0xd09a61,
a: 0x3e2e25,
o: 0x30251d
};
// C, B, and A horizons.
addBox(bed, 0, 0.50, 0, width, 0.84, depth, horizonColors.c);
addBox(bed, 0, 1.25, 0, width, 0.68, depth, horizonColors.b);
addBox(bed, 0, 2.04, 0, width, 0.84, depth, horizonColors.a);
// Thin horizon separation lines on the exposed face.
addBox(bed, 0, 0.925, front + 0.008, width, 0.035, 0.035, 0x6d5038);
addBox(bed, 0, 1.605, front + 0.008, width, 0.035, 0.035, 0x60462f);
// Open-front wooden bed frame.
const wood = compacted ? 0x765139 : 0x674b35;
const woodLight = compacted ? 0x8b6549 : 0x7c5d42;
for (const side of [-1, 1]) {
addBox(bed, side * (width / 2 + 0.035), 1.28, 0, 0.16, 2.5, depth, wood);
addBox(bed, side * (width / 2 + 0.035), 0.35, 0, 0.21, 0.13, depth, woodLight);
addBox(bed, side * (width / 2 + 0.035), 1.28, 0, 0.21, 0.13, depth, woodLight);
addBox(bed, side * (width / 2 + 0.035), 2.36, 0, 0.21, 0.13, depth, woodLight);
}
addBox(bed, 0, 1.28, -depth / 2 - 0.04, width, 0.15, 0.16, wood);
addBox(bed, 0, 0.35, -depth / 2 - 0.04, width, 0.13, 0.21, woodLight);
addBox(bed, 0, 2.36, -depth / 2 - 0.04, width, 0.13, 0.21, woodLight);
// Aggregate texture on the exposed cutaway.
const aggregateColors = compacted
? [0x7a5638, 0x865f3f, 0x956a46, 0x6f5036]
: [0x563c2d, 0x644635, 0x49352a, 0x75523b];
const rand = seededRandom(seed);
if (compacted) {
// Densely packed, regular aggregates.
for (let ix = 0; ix < 21; ix++) {
for (let iy = 0; iy < 9; iy++) {
const size = 0.18 + rand() * 0.055;
addBox(
bed,
-width / 2 + 0.2 + ix * 0.25,
0.18 + iy * 0.245,
front + 0.032,
size,
size * 0.78,
0.055,
aggregateColors[(ix + iy * 2) % aggregateColors.length],
{ castShadow: false }
);
}
}
} else {
// Irregular aggregates leave visibly larger pore spaces.
for (let i = 0; i < 150; i++) {
const size = 0.15 + rand() * 0.17;
addBox(
bed,
-width / 2 + 0.12 + rand() * (width - 0.24),
0.15 + rand() * 2.15,
front + 0.035,
size,
size * 0.72,
0.055,
aggregateColors[Math.floor(rand() * aggregateColors.length)],
{ castShadow: false }
);
}
}
// Pore cavities.
const poreCount = compacted ? 30 : 72;
const poreColor = compacted ? 0x4b392b : 0x1f1b18;
for (let i = 0; i < poreCount; i++) {
const size = compacted
? 0.055 + rand() * 0.06
: 0.11 + rand() * 0.19;
addBox(
bed,
-width / 2 + 0.16 + rand() * (width - 0.32),
0.18 + rand() * 2.13,
front + 0.072,
size,
size * 0.82,
0.04,
poreColor,
{ castShadow: false }
);
}
if (!compacted) {
// The organic horizon.
addBox(bed, 0, 2.51, 0, width, 0.12, depth, horizonColors.o);
// Blocky mulch chips.
const mulchColors = [0x9e6034, 0xb6763e, 0x74462d, 0xc18a4b, 0x875431];
for (let i = 0; i < 105; i++) {
const chipW = 0.13 + rand() * 0.33;
const chipD = 0.1 + rand() * 0.26;
const chipH = 0.045 + rand() * 0.07;
addBox(
bed,
-width / 2 + 0.1 + rand() * (width - 0.2),
2.59 + chipH / 2,
-depth / 2 + 0.1 + rand() * (depth - 0.2),
chipW,
chipH,
chipD,
mulchColors[Math.floor(rand() * mulchColors.length)]
);
}
// Compost flecks embedded in the topsoil.
for (let i = 0; i < 34; i++) {
addBox(
bed,
-width / 2 + rand() * width,
1.67 + rand() * 0.68,
front + 0.085,
0.05 + rand() * 0.08,
0.04 + rand() * 0.07,
0.04,
rand() > 0.5 ? 0xb07a3e : 0x72502d,
{ castShadow: false }
);
}
} else {
// A thin, crusted surface and visible shrinkage cracks.
addBox(bed, 0, 2.485, 0, width, 0.055, depth, 0x806149);
for (let i = 0; i < 9; i++) {
const crackX = -2.15 + i * 0.49;
addBox(
bed,
crackX,
2.518,
-0.1 + (i % 3) * 0.5,
0.35 + random() * 0.3,
0.018,
0.035,
0x3b2d24,
{ castShadow: false }
);
}
}
return bed;
}
const compactedBed = makeBed({
x: -3.3,
compacted: true,
seed: 1123
});
const mulchedBed = makeBed({
x: 3.0,
compacted: false,
seed: 8712
});
// ------------------------------------------------------------
// Voxel plants
// ------------------------------------------------------------
function makePlant(x, z, healthy) {
const plant = new THREE.Group();
plant.position.set(x, 2.54, z);
scene.add(plant);
const stemColor = healthy ? 0x567343 : 0x81704b;
const leafColors = healthy
? [0x5f8a4a, 0x759951, 0x466f42]
: [0x9a8b50, 0x817443, 0xa3945b];
const height = healthy ? 1.45 : 0.78;
const segments = Math.round(height / 0.16);
for (let i = 0; i < segments; i++) {
addBox(
plant,
0,
0.08 + i * 0.16,
0,
0.105,
0.17,
0.105,
stemColor
);
}
const leafCount = healthy ? 14 : 5;
for (let i = 0; i < leafCount; i++) {
const angle = i * 2.399;
const radius = healthy ? 0.23 + (i % 3) * 0.06 : 0.18;
const y = healthy ? 0.38 + i * 0.075 : 0.29 + i * 0.09;
addBox(
plant,
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius,
healthy ? 0.34 : 0.26,
0.105,
healthy ? 0.19 : 0.15,
leafColors[i % leafColors.length],
{ rotation: [0, angle, 0] }
);
}
if (healthy) {
addBox(plant, 0.23, 0.82, 0.12, 0.18, 0.18, 0.18, 0xcc6742);
addBox(plant, -0.2, 1.05, -0.12, 0.17, 0.17, 0.17, 0xd47c46);
} else {
addBox(plant, 0.18, 0.55, 0, 0.18, 0.07, 0.16, 0xb19a59);
}
plantGroups.push({ group: plant, phase: random() * 6 });
return plant;
}
makePlant(-3.3, -0.25, false);
makePlant(3.0, -0.15, true);
// ------------------------------------------------------------
// Root systems on the exposed cutaway
// ------------------------------------------------------------
function addVoxelTrail(parent, points, thickness, material, spacing = 0.08) {
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const dx = b[0] - a[0];
const dy = b[1] - a[1];
const length = Math.hypot(dx, dy);
const steps = Math.max(1, Math.ceil(length / spacing));
for (let j = 0; j < steps; j++) {
const t = j / steps;
addBox(
parent,
a[0] + dx * t,
a[1] + dy * t,
a[2] + dz(a, b, t),
thickness,
thickness,
thickness,
material,
{ castShadow: false }
);
}
}
}
function dz(a, b, t) {
return a[2] + (b[2] - a[2]) * t;
}
const compactRootMat = new THREE.MeshStandardMaterial({
color: 0xd4b56b,
roughness: 1,
flatShading: true
});
const mulchRootMat = new THREE.MeshStandardMaterial({
color: 0xf1dda0,
roughness: 1,
flatShading: true
});
// Compacted roots are short, pinched, and concentrated near the surface.
const compactRoots = [
[[-3.3, 2.48, 2.34], [-3.27, 2.27, 2.34], [-3.08, 2.23, 2.34], [-3.16, 2.08, 2.34], [-3.02, 1.92, 2.34], [-3.09, 1.72, 2.34]],
[[-3.22, 2.26, 2.35], [-3.52, 2.19, 2.35], [-3.75, 2.10, 2.35]],
[[-3.08, 2.20, 2.35], [-2.83, 2.15, 2.35], [-2.62, 2.03, 2.35]],
[[-3.12, 2.00, 2.35], [-3.38, 1.91, 2.35], [-3.48, 1.77, 2.35]],
[[-3.06, 1.88, 2.35], [-2.84, 1.80, 2.35], [-2.76, 1.67, 2.35]]
];
compactRoots.forEach((path) => {
addVoxelTrail(rootsGroup, path, 0.085, compactRootMat, 0.075);
});
// Mulched roots are deeper, wider, and strongly branched.
const mulchRoots = [
[[3.0, 2.48, 2.36], [2.96, 2.25, 2.36], [3.16, 2.05, 2.36], [2.90, 1.83, 2.36], [3.18, 1.60, 2.36], [2.87, 1.39, 2.36], [3.13, 1.12, 2.36], [2.92, 0.82, 2.36], [3.15, 0.52, 2.36], [2.93, 0.25, 2.36]],
[[3.04, 2.18, 2.37], [2.61, 2.11, 2.37], [2.18, 2.04, 2.37], [1.70, 1.91, 2.37], [1.38, 1.76, 2.37]],
[[3.12, 1.95, 2.37], [3.56, 1.84, 2.37], [4.04, 1.68, 2.37], [4.50, 1.48, 2.37], [4.92, 1.25, 2.37]],
[[3.13, 1.61, 2.37], [3.62, 1.52, 2.37], [4.02, 1.31, 2.37], [4.42, 1.08, 2.37]],
[[2.93, 1.30, 2.37], [2.49, 1.18, 2.37], [2.05, 0.98, 2.37], [1.57, 0.76, 2.37]],
[[3.10, 0.95, 2.37], [3.66, 0.82, 2.37], [4.13, 0.66, 2.37], [4.56, 0.46, 2.37]],
[[2.98, 0.64, 2.37], [2.45, 0.52, 2.37], [2.02, 0.38, 2.37]],
[[3.06, 2.32, 2.37], [3.48, 2.24, 2.37], [3.83, 2.12, 2.37]],
[[2.93, 1.87, 2.37], [2.39, 1.76, 2.37], [1.94, 1.61, 2.37]]
];
mulchRoots.forEach((path) => {
addVoxelTrail(rootsGroup, path, 0.095, mulchRootMat, 0.07);
});
// Fine root hairs.
for (let i = 0; i < 48; i++) {
const mulched = i > 19;
const x = mulched
? 1.55 + random() * 3.4
: -3.8 + random() * 1.3;
const y = mulched
? 0.55 + random() * 1.8
: 1.72 + random() * 0.62;
addBox(
rootsGroup,
x,
y,
2.37,
mulched ? 0.035 : 0.028,
mulched ? 0.12 : 0.08,
0.035,
mulched ? mulchRootMat : compactRootMat,
{ castShadow: false }
);
}
// ------------------------------------------------------------
// Rain barrel
// ------------------------------------------------------------
const barrel = new THREE.Group();
barrel.position.set(6.55, 0, -2.65);
scene.add(barrel);
const barrelMat = 0x316f73;
const barrelDark = 0x214e52;
const barrelLight = 0x4a8584;
// Stand.
addBox(barrel, -0.55, 0.32, -0.55, 0.18, 0.65, 0.18, 0x5f5446);
addBox(barrel, 0.55, 0.32, -0.55, 0.18, 0.65, 0.18, 0x5f5446);
addBox(barrel, -0.55, 0.32, 0.55, 0.18, 0.65, 0.18, 0x5f5446);
addBox(barrel, 0.55, 0.32, 0.55, 0.18, 0.65, 0.18, 0x5f5446);
addBox(barrel, 0, 0.63, 0, 1.55, 0.15, 1.55, 0x6e5e4b);
// Voxel tank.
addBox(barrel, 0, 1.83, 0, 1.52, 2.25, 1.52, barrelMat);
addBox(barrel, 0, 0.84, 0, 1.68, 0.16, 1.68, barrelDark);
addBox(barrel, 0, 1.66, 0, 1.62, 0.12, 1.62, barrelLight);
addBox(barrel, 0, 2.78, 0, 1.68, 0.16, 1.68, barrelDark);
addBox(barrel, 0, 2.9, 0, 1.42, 0.12, 1.42, 0x244a4d);
// Top opening.
addBox(barrel, 0, 3.0, 0, 0.72, 0.08, 0.72, 0x182f32);
addBox(barrel, -0.37, 3.04, -0.37, 0.12, 0.1, 0.12, barrelLight);
addBox(barrel, 0.37, 3.04, -0.37, 0.12, 0.1, 0.12, barrelLight);
addBox(barrel, -0.37, 3.04, 0.37, 0.12, 0.1, 0.12, barrelLight);
addBox(barrel, 0.37, 3.04, 0.37, 0.12, 0.1, 0.12, barrelLight);
// Level gauge.
addBox(barrel, 0.15, 1.75, 0.79, 0.28, 1.15, 0.05, 0x183d40);
const levelWater = addBox(
barrel,
0.15,
1.47,
0.825,
0.18,
0.65,
0.035,
new THREE.MeshStandardMaterial({
color: 0x35bfd8,
emissive: 0x0c5263,
emissiveIntensity: 0.35,
roughness: 0.55,
flatShading: true
})
);
// Spigot.
addBox(barrel, 0, 1.03, 0.92, 0.19, 0.19, 0.38, 0xa27b3e);
addBox(barrel, 0, 1.03, 1.16, 0.26, 0.26, 0.13, 0xc39b52);
addBox(barrel, 0, 1.25, 1.16, 0.42, 0.08, 0.09, 0xc39b52);
// Rain entering the barrel.
for (let i = 0; i < 14; i++) {
const drop = addBox(
waterGroup,
6.55 + (random() - 0.5) * 0.72,
3.35 + random() * 1.55,
-2.65 + (random() - 0.5) * 0.72,
0.055,
0.14 + random() * 0.09,
0.055,
0x49c4db,
{ castShadow: false }
);
rainDrops.push({
mesh: drop,
speed: 1.4 + random() * 1.3,
floor: 3.03 + random() * 0.12
});
}
// ------------------------------------------------------------
// Water route helpers and schematic infiltration
// ------------------------------------------------------------
function addAxisPipe(parent, points, thickness, material) {
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const dx = Math.abs(b[0] - a[0]);
const dy = Math.abs(b[1] - a[1]);
const dz = Math.abs(b[2] - a[2]);
let w = thickness;
let h = thickness;
let d = thickness;
if (dx > 0.001 && dy < 0.001 && dz < 0.001) {
w = dx + thickness;
} else if (dy > 0.001 && dx < 0.001 && dz < 0.001) {
h = dy + thickness;
} else if (dz > 0.001 && dx < 0.001 && dy < 0.001) {
d = dz + thickness;
} else {
// Fallback for any non-axis segment.
const length = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
const mesh = addBox(
parent,
(a[0] + b[0]) / 2,
(a[1] + b[1]) / 2,
(a[2] + b[2]) / 2,
thickness,
thickness,
length,
material
);
mesh.lookAt(b[0], b[1], b[2]);
continue;
}
addBox(
parent,
(a[0] + b[0]) / 2,
(a[1] + b[1]) / 2,
(a[2] + b[2]) / 2,
w,
h,
d,
material
);
}
}
function addFlow(route, count, speed, size, color, category = "water") {
const parent = category === "water" ? waterGroup : rootsGroup;
const flowMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.45,
roughness: 0.45,
flatShading: true
});
const pulses = [];
for (let i = 0; i < count; i++) {
const mesh = addBox(
parent,
route[0][0],
route[0][1],
route[0][2],
size,
size,
size,
flowMaterial,
{ castShadow: false }
);
pulses.push(mesh);
}
flows.push({ route, pulses, speed, phase: random() });
}
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0x315e60,
roughness: 0.68,
flatShading: true
});
// Barrel outlet, perimeter hose, and two drip branches.
const mainPipeRoute = [
[6.55, 1.03, -1.42],
[7.55, 1.03, -1.42],
[7.55, 0.17, -1.42],
[7.55, 0.17, 2.82],
[-6.25, 0.17, 2.82]
];
addAxisPipe(waterGroup, mainPipeRoute, 0.105, pipeMaterial);
addFlow(mainPipeRoute, 5, 0.11, 0.14, 0x50d5e8);
const leftPipeRoute = [
[-3.3, 0.17, 2.82],
[-3.3, 0.17, 2.02],
[-3.3, 2.69, 2.02],
[-3.3, 2.69, -0.25],
[-3.3, 2.60, -0.25]
];
const rightPipeRoute = [
[3.0, 0.17, 2.82],
[3.0, 0.17, 2.02],
[3.0, 2.69, 2.02],
[3.0, 2.69, -0.15],
[3.0, 2.60, -0.15]
];
addAxisPipe(waterGroup, leftPipeRoute, 0.095, pipeMaterial);
addAxisPipe(waterGroup, rightPipeRoute, 0.095, pipeMaterial);
addFlow(leftPipeRoute, 3, 0.15, 0.13, 0x52d9e9);
addFlow(rightPipeRoute, 3, 0.15, 0.13, 0x52d9e9);
// Emitters on the soil surface.
addBox(waterGroup, -3.3, 2.62, -0.25, 0.24, 0.13, 0.24, 0x54b9c2);
addBox(waterGroup, 3.0, 2.62, -0.15, 0.24, 0.13, 0.24, 0x54b9c2);
// Static pale-blue path showing the direction of infiltration.
const paleWater = new THREE.MeshStandardMaterial({
color: 0x3bbdd0,
emissive: 0x124e58,
emissiveIntensity: 0.22,
transparent: true,
opacity: 0.7,
roughness: 0.7,
flatShading: true
});
const compactInfiltration = [
[-2.0, 2.55, 2.36],
[-1.45, 2.55, 2.36],
[-1.45, 2.39, 2.36],
[-1.93, 2.39, 2.36],
[-2.36, 2.27, 2.36],
[-2.70, 2.17, 2.36]
];
const deepInfiltration = [
[4.55, 2.64, 2.39],
[4.55, 2.28, 2.39],
[4.18, 2.28, 2.39],
[4.18, 1.92, 2.39],
[3.83, 1.92, 2.39],
[3.83, 1.48, 2.39],
[4.12, 1.48, 2.39],
[4.12, 1.04, 2.39],
[3.75, 1.04, 2.39],
[3.75, 0.55, 2.39]
];
addVoxelTrail(waterGroup, compactInfiltration, 0.105, paleWater, 0.13);
addVoxelTrail(waterGroup, deepInfiltration, 0.115, paleWater, 0.13);
addFlow(compactInfiltration, 4, 0.13, 0.14, 0x83e9f1);
addFlow(deepInfiltration, 5, 0.17, 0.15, 0x83e9f1);
// Shallow surface runoff on the compacted bed.
const runoffRoute = [
[-3.15, 2.54, 0.65],
[-2.55, 2.54, 0.65],
[-2.05, 2.54, 0.78],
[-1.50, 2.54, 0.95],
[-0.80, 2.54, 1.05],
[-0.55, 2.48, 1.25]
];
addVoxelTrail(waterGroup, runoffRoute, 0.09, paleWater, 0.14);
addFlow(runoffRoute, 3, 0.16, 0.13, 0x8cecf3);
// A few cube-shaped droplets/puddle voxels.
addBox(waterGroup, -1.7, 2.535, 0.55, 0.55, 0.035, 0.3, 0x75cdd6);
addBox(waterGroup, -1.0, 2.535, 0.9, 0.35, 0.035, 0.24, 0x75cdd6);
// ------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------
function addLabel(text, className, position, category = "always") {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(...position),
category
});
}
addLabel("Compacted bed", "bed-label", [-3.3, 3.42, 0]);
addLabel("Mulched bed", "bed-label", [3.0, 3.58, 0]);
addLabel("Rain barrel / 120 L", "bed-label water-label", [6.55, 3.67, -2.65], "water");
addLabel("Shallow + lateral", "water-label minor", [-2.25, 2.12, 2.42], "water");
addLabel("Deep infiltration", "water-label minor", [4.6, 1.32, 2.45], "water");
addLabel("Pinned root zone", "root-label minor", [-4.45, 1.62, 2.43], "roots");
addLabel("Broad root network", "root-label minor", [4.65, 0.82, 2.43], "roots");
addLabel("O", "horizon-label o", [5.78, 2.57, 2.25]);
addLabel("A", "horizon-label a", [5.78, 2.03, 2.25]);
addLabel("B", "horizon-label b", [5.78, 1.25, 2.25]);
addLabel("C", "horizon-label c", [5.78, 0.50, 2.25]);
// ------------------------------------------------------------
// Custom camera controls — no addons
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
let azimuth = 0.64;
let polar = 1.04;
let distance = 17.2;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + distance * sinPolar * Math.sin(azimuth),
cameraTarget.y + distance * Math.cos(polar),
cameraTarget.z + distance * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
azimuth = 0.64;
polar = 1.04;
distance = innerWidth < 600 ? 19.2 : 17.2;
updateCamera();
}
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;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar + dy * 0.005, 0.48, 1.38);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
distance = THREE.MathUtils.clamp(
distance + event.deltaY * 0.012,
10.5,
25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelector("#reset-view").addEventListener("click", resetCamera);
// Layer toggles.
document.querySelectorAll("[data-layer]").forEach((button) => {
button.addEventListener("click", () => {
const layer = button.dataset.layer;
const active = button.classList.toggle("active");
button.setAttribute("aria-pressed", String(active));
if (layer === "water") {
waterGroup.visible = active;
} else if (layer === "roots") {
rootsGroup.visible = active;
}
});
});
// ------------------------------------------------------------
// Resize and responsive camera
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.fov = innerWidth < 600 ? 47 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
updateCamera();
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
function sampleRoute(route, t, target) {
let total = 0;
const lengths = [];
for (let i = 0; i < route.length - 1; i++) {
const a = route[i];
const b = route[i + 1];
const length = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
lengths.push(length);
total += length;
}
let remaining = THREE.MathUtils.clamp(t, 0, 0.999999) * total;
for (let i = 0; i < lengths.length; i++) {
if (remaining <= lengths[i] || i === lengths.length - 1) {
const local = lengths[i] === 0 ? 0 : remaining / lengths[i];
const a = route[i];
const b = route[i + 1];
target.set(
THREE.MathUtils.lerp(a[0], b[0], local),
THREE.MathUtils.lerp(a[1], b[1], local),
THREE.MathUtils.lerp(a[2], b[2], local)
);
return target;
}
remaining -= lengths[i];
}
return target;
}
const flowPosition = new THREE.Vector3();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
// Water pulse movement.
for (const flow of flows) {
flow.pulses.forEach((pulse, index) => {
const t = reducedMotion
? (index + 0.5) / flow.pulses.length
: (elapsed * flow.speed + flow.phase + index / flow.pulses.length) % 1;
sampleRoute(flow.route, t, flowPosition);
pulse.position.copy(flowPosition);
});
}
// Voxel rain.
for (const drop of rainDrops) {
if (!reducedMotion) {
drop.mesh.position.y -= drop.speed * delta;
drop.mesh.rotation.y += delta * 2;
}
if (drop.mesh.position.y < drop.floor) {
drop.mesh.position.y = 4.5 + random() * 1.1;
drop.mesh.position.x = 6.55 + (random() - 0.5) * 0.72;
drop.mesh.position.z = -2.65 + (random() - 0.5) * 0.72;
}
}
// Very subtle plant movement.
if (!reducedMotion) {
for (const plant of plantGroups) {
plant.group.rotation.z = Math.sin(elapsed * 1.15 + plant.phase) * 0.018;
plant.group.rotation.x = Math.cos(elapsed * 0.8 + plant.phase) * 0.009;
}
}
// Water level indicator.
if (!reducedMotion) {
levelWater.scale.y = 0.65 + Math.sin(elapsed * 1.7) * 0.035;
levelWater.position.y = 1.47 + Math.sin(elapsed * 1.7) * 0.018;
}
// Project labels into screen space.
for (const label of labels) {
const visible =
(label.category === "always" ||
(label.category === "water" && waterGroup.visible) ||
(label.category === "roots" && rootsGroup.visible));
if (!visible) {
label.element.style.display = "none";
continue;
}
const projected = label.position.clone().project(camera);
const onScreen = projected.z > -1 && projected.z < 1;
if (!onScreen) {
label.element.style.display = "none";
continue;
}
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.display = "";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
renderer.render(scene, camera);
}
resetCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```