Prompt specification
Build or customize the Three.js 3D scene "Garden soil community cutaway" 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: Garden soil community cutaway
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/garden-soil-community-cutaway-x0675
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows earthworm burrows. Compose layered garden soil with roots, burrows, litter, and moisture patches; visible pathways connect surface material to subsurface spaces while organisms occupy distinct regions. Stylized solid forms.
Working Three.js Starter (garden-soil-community-cutaway-x0675):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Below the Garden — Earthworm Burrows</title>
<style>
:root {
--ink: #28251f;
--paper: #f3eee2;
--muted: #777063;
--orange: #c97855;
--teal: #4f8b83;
--line: rgba(40, 37, 31, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e2d4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 46%, transparent 45%, rgba(61, 46, 31, 0.09) 100%),
linear-gradient(180deg, rgba(255,255,255,0.12), transparent 24%);
z-index: 2;
}
.intro {
position: fixed;
top: 28px;
left: 30px;
width: min(360px, calc(100vw - 60px));
z-index: 5;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #746d60;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 1px;
background: #8a8274;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4.4vw, 61px);
font-weight: 500;
line-height: 0.93;
letter-spacing: -0.045em;
}
.intro p {
width: 315px;
max-width: 100%;
margin: 17px 0 0;
color: #686155;
font-size: 12px;
line-height: 1.65;
}
.legend {
position: fixed;
top: 26px;
right: 26px;
z-index: 5;
width: 225px;
padding: 17px 17px 15px;
border: 1px solid rgba(62, 54, 43, 0.13);
border-radius: 13px;
background: rgba(247, 243, 234, 0.76);
box-shadow: 0 12px 40px rgba(58, 44, 27, 0.08);
backdrop-filter: blur(13px);
-webkit-backdrop-filter: blur(13px);
}
.legend h2 {
margin: 0 0 12px;
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
color: #71695d;
}
.legend-row {
display: grid;
grid-template-columns: 11px 1fr;
align-items: center;
gap: 9px;
margin: 8px 0;
font-size: 11px;
color: #4f4a42;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.legend-note {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #83796b;
font-size: 9px;
line-height: 1.5;
letter-spacing: 0.03em;
}
.scene-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(46, 39, 30, 0.13);
border-radius: 999px;
background: rgba(250, 247, 240, 0.89);
box-shadow: 0 5px 18px rgba(48, 36, 23, 0.09);
backdrop-filter: blur(7px);
-webkit-backdrop-filter: blur(7px);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 160ms ease;
}
.scene-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: rgba(58, 49, 38, 0.44);
}
.scene-label .num {
display: grid;
width: 18px;
height: 18px;
place-items: center;
border-radius: 50%;
background: #3c382f;
color: #fffaf0;
font-size: 8px;
}
.controls {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 6;
display: flex;
align-items: center;
gap: 13px;
transform: translateX(-50%);
color: #736b5f;
font-size: 10px;
letter-spacing: 0.07em;
}
.controls .divider {
width: 1px;
height: 14px;
background: rgba(45, 40, 33, 0.2);
}
button {
border: 1px solid rgba(43, 38, 31, 0.18);
border-radius: 999px;
padding: 7px 11px;
background: rgba(250, 247, 239, 0.72);
color: #4f4940;
font: inherit;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: #fffaf0;
transform: translateY(-1px);
}
.depth-scale {
position: fixed;
left: 14px;
top: 50%;
z-index: 3;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 240px;
padding: 2px 0;
color: rgba(49, 44, 37, 0.52);
font-size: 8px;
letter-spacing: 0.08em;
pointer-events: none;
}
.depth-scale span {
display: flex;
align-items: center;
gap: 5px;
}
.depth-scale span::before {
content: "";
width: 7px;
height: 1px;
background: rgba(49, 44, 37, 0.35);
}
@media (max-width: 760px) {
.intro {
top: 18px;
left: 18px;
}
.intro p { display: none; }
.legend {
top: auto;
right: 15px;
bottom: 68px;
width: 176px;
padding: 12px;
}
.legend-note, .depth-scale { display: none; }
.scene-label { font-size: 8px; }
.controls { bottom: 16px; white-space: nowrap; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway diagram of garden soil, roots, burrows, moisture, and soil organisms"></canvas>
<div class="vignette"></div>
<header class="intro">
<div class="eyebrow">Cutaway study · 01</div>
<h1>Below the<br>garden</h1>
<p>
A living section of garden soil. Roots explore the upper layers while
connected burrows carry surface litter into deeper, moist chambers.
</p>
</header>
<aside class="legend" aria-label="Habitat legend">
<h2>Habitat zones</h2>
<div class="legend-row"><span class="swatch" style="background:#8a5836"></span>Litter & topsoil</div>
<div class="legend-row"><span class="swatch" style="background:#c18a59"></span>Living root network</div>
<div class="legend-row"><span class="swatch" style="background:#4f8b83"></span>Moisture pocket</div>
<div class="legend-row"><span class="swatch" style="background:#25231f"></span>Burrow pathway</div>
<div class="legend-row"><span class="swatch" style="background:#c56e52"></span>Deep-soil earthworm</div>
<div class="legend-note">
Ants and springtails occupy the litter; root-zone nematodes follow roots;
earthworms remain in the deeper burrow network.
</div>
</aside>
<div class="depth-scale" aria-hidden="true">
<span>0 cm</span>
<span>−20</span>
<span>−40</span>
<span>−60</span>
</div>
<div class="controls">
<span>Drag to orbit</span>
<span class="divider"></span>
<span>Scroll to zoom</span>
<span class="divider"></span>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9e2d4");
scene.fog = new THREE.Fog("#e9e2d4", 39, 75);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0, -0.2, 0),
radius: 28,
theta: 0.58,
phi: 1.17
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
scene.add(new THREE.HemisphereLight("#fff5df", "#65513f", 2.25));
const key = new THREE.DirectionalLight("#fff0d5", 3.6);
key.position.set(-10, 18, 15);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -18;
key.shadow.camera.right = 18;
key.shadow.camera.top = 16;
key.shadow.camera.bottom = -16;
key.shadow.camera.near = 1;
key.shadow.camera.far = 55;
key.shadow.normalBias = 0.035;
scene.add(key);
const fill = new THREE.DirectionalLight("#8fb8b1", 1.25);
fill.position.set(13, 5, -10);
scene.add(fill);
const rim = new THREE.DirectionalLight("#ffd5a0", 1.0);
rim.position.set(0, 8, -16);
scene.add(rim);
const W = 18;
const D = 9;
const FRONT = D / 2;
const mat = (color, roughness = 0.9, extra = {}) =>
new THREE.MeshStandardMaterial({ color, roughness, ...extra });
const materials = {
topsoil: mat("#65432d"),
subsoil: mat("#8a5a38"),
loam: mat("#704a35"),
deep: mat("#49362d"),
pebbleA: mat("#9b7d5e"),
pebbleB: mat("#5e5145"),
pebbleC: mat("#b0916b"),
root: mat("#c28b57", 0.95),
rootLight: mat("#d3a46b", 0.95),
tunnelRim: mat("#795139", 1),
tunnelDark: mat("#24231f", 1),
moisture: mat("#4e8b82", 0.5, {
transparent: true,
opacity: 0.48,
depthWrite: false
}),
moistureEdge: mat("#365f5b", 0.8, {
transparent: true,
opacity: 0.22,
depthWrite: false
}),
greenA: mat("#587347"),
greenB: mat("#78905b"),
greenC: mat("#3f623e"),
leafA: mat("#b8793f"),
leafB: mat("#d29a50"),
leafC: mat("#805137"),
leafD: mat("#b6a36b"),
worm: mat("#bf674f", 0.72),
wormDark: mat("#91483a", 0.78),
ant: mat("#7f392a", 0.72),
antDark: mat("#4f2d26", 0.78),
springtail: mat("#a9c9b8", 0.65),
nematode: mat("#e3cf9d", 0.8)
};
// Deterministic randomness keeps the scene composition consistent.
let seed = 42719;
function random() {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
const range = (a, b) => a + (b - a) * random();
const pick = arr => arr[Math.floor(random() * arr.length)];
function surfaceY(x, z) {
return 5.02
+ 0.12 * Math.sin(x * 0.65)
+ 0.075 * Math.sin(x * 1.36 + 1.1) * Math.cos(z * 0.42);
}
function boundary1(x, z) {
return 3.13
+ 0.25 * Math.sin(x * 0.56 + 0.4)
+ 0.11 * Math.sin(x * 1.42 + 2.1);
}
function boundary2(x, z) {
return 0.18
+ 0.3 * Math.sin(x * 0.43 + 1.5)
+ 0.14 * Math.sin(x * 1.12);
}
function boundary3(x, z) {
return -3.08
+ 0.2 * Math.sin(x * 0.62 + 2.4)
+ 0.09 * Math.sin(x * 1.36 + 0.6);
}
function bottomY(x, z) {
return -5.05 + 0.05 * Math.sin(x * 0.72);
}
function makeSoilSlab(topFn, bottomFn, material) {
const nx = 48;
const nz = 14;
const positions = [];
const indices = [];
function addGrid(fn, up) {
const offset = positions.length / 3;
for (let iz = 0; iz <= nz; iz++) {
const z = -D / 2 + D * iz / nz;
for (let ix = 0; ix <= nx; ix++) {
const x = -W / 2 + W * ix / nx;
positions.push(x, fn(x, z), z);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = offset + iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
if (up) {
indices.push(a, c, b, b, c, d);
} else {
indices.push(a, b, c, b, d, c);
}
}
}
}
addGrid(topFn, true);
addGrid(bottomFn, false);
function connectFront(z, frontFacing) {
const offset = positions.length / 3;
for (let ix = 0; ix < nx; ix++) {
const x0 = -W / 2 + W * ix / nx;
const x1 = -W / 2 + W * (ix + 1) / nx;
positions.push(
x0, topFn(x0, z), z,
x1, topFn(x1, z), z,
x0, bottomFn(x0, z), z,
x1, bottomFn(x1, z), z
);
const a = offset + ix * 4;
if (frontFacing) {
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
} else {
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
}
connectFront(FRONT, true);
connectFront(-FRONT, false);
// Left wall.
let offset = positions.length / 3;
for (let iz = 0; iz < nz; iz++) {
const z0 = -FRONT + D * iz / nz;
const z1 = -FRONT + D * (iz + 1) / nz;
const x = -W / 2;
positions.push(
x, topFn(x, z0), z0,
x, topFn(x, z1), z1,
x, bottomFn(x, z0), z0,
x, bottomFn(x, z1), z1
);
const a = offset + iz * 4;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
// Right wall.
offset = positions.length / 3;
for (let iz = 0; iz < nz; iz++) {
const z0 = -FRONT + D * iz / nz;
const z1 = -FRONT + D * (iz + 1) / nz;
const x = W / 2;
positions.push(
x, topFn(x, z0), z0,
x, topFn(x, z1), z1,
x, bottomFn(x, z0), z0,
x, bottomFn(x, z1), z1
);
const a = offset + iz * 4;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
makeSoilSlab(surfaceY, boundary1, materials.topsoil);
makeSoilSlab(boundary1, boundary2, materials.subsoil);
makeSoilSlab(boundary2, boundary3, materials.loam);
makeSoilSlab(boundary3, bottomY, materials.deep);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
mat("#ddd4c4", 1)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5.18;
ground.receiveShadow = true;
scene.add(ground);
// Low-poly mineral and organic inclusions embedded in the cut face.
const pebbleGeometry = new THREE.DodecahedronGeometry(0.12, 0);
const pebbleMaterials = [materials.pebbleA, materials.pebbleB, materials.pebbleC];
for (let i = 0; i < 100; i++) {
const x = range(-8.65, 8.65);
const layer = Math.floor(random() * 4);
let low, high;
if (layer === 0) {
low = boundary1(x, FRONT);
high = surfaceY(x, FRONT);
} else if (layer === 1) {
low = boundary2(x, FRONT);
high = boundary1(x, FRONT);
} else if (layer === 2) {
low = boundary3(x, FRONT);
high = boundary2(x, FRONT);
} else {
low = bottomY(x, FRONT);
high = boundary3(x, FRONT);
}
const stone = new THREE.Mesh(pebbleGeometry, pick(pebbleMaterials));
stone.position.set(x, range(low + 0.12, high - 0.12), FRONT + 0.045);
const size = range(0.55, 1.75);
stone.scale.set(size, size * range(0.55, 1.0), 0.36);
stone.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
stone.castShadow = true;
scene.add(stone);
}
function organicBlob(radius, irregularity = 0.18) {
const vertices = [0, 0, 0];
const count = 22;
for (let i = 0; i < count; i++) {
const angle = i / count * Math.PI * 2;
const r = radius * (1 + Math.sin(angle * 3 + 0.7) * irregularity
+ Math.sin(angle * 5 - 0.4) * irregularity * 0.45);
vertices.push(Math.cos(angle) * r, Math.sin(angle) * r, 0);
}
const indices = [];
for (let i = 0; i < count; i++) {
indices.push(0, i + 1, (i + 1) % count + 1);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function addMoisture(x, y, sx, sy, horizontal = false) {
const edge = new THREE.Mesh(organicBlob(1, 0.2), materials.moistureEdge);
edge.position.set(x, y, FRONT + 0.075);
edge.scale.set(sx * 1.12, sy * 1.12, 1);
if (horizontal) {
edge.rotation.x = -Math.PI / 2;
edge.position.z = 0;
}
scene.add(edge);
const patch = new THREE.Mesh(organicBlob(1, 0.18), materials.moisture);
patch.position.set(x, y, FRONT + 0.095);
patch.scale.set(sx, sy, 1);
if (horizontal) {
patch.rotation.x = -Math.PI / 2;
patch.position.z = 0;
}
scene.add(patch);
}
addMoisture(-6.45, 0.95, 1.35, 0.86);
addMoisture(2.2, 2.3, 0.93, 0.6);
addMoisture(6.35, -3.85, 1.22, 0.72);
addMoisture(-3.25, 4.72, 1.35, 0.72, true);
function cylinderBetween(a, b, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
return mesh;
}
function addTube(points, radius, material, segments = 50, radialSegments = 6) {
const curve = new THREE.CatmullRomCurve3(points);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, radialSegments, false),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return { curve, mesh };
}
// Burrows bend from surface openings into the exposed cross-section.
const burrowDefinitions = [
{
x: 5.05,
points: [
[5.05, surfaceY(5.05, 3.65) + 0.03, 3.65],
[4.88, 4.55, 4.22],
[4.48, 3.65, FRONT + 0.15],
[4.82, 2.65, FRONT + 0.18],
[4.28, 1.65, FRONT + 0.18],
[5.05, 0.72, FRONT + 0.18],
[4.72, -0.3, FRONT + 0.18],
[5.35, -1.25, FRONT + 0.19],
[5.08, -2.12, FRONT + 0.20]
],
radius: 0.19
},
{
x: -1.55,
points: [
[-1.55, surfaceY(-1.55, 3.8) + 0.03, 3.8],
[-1.3, 4.55, 4.28],
[-1.72, 3.65, FRONT + 0.16],
[-1.02, 2.7, FRONT + 0.17],
[-1.32, 1.72, FRONT + 0.17],
[-0.62, 0.72, FRONT + 0.17],
[-0.95, -0.3, FRONT + 0.17],
[-0.45, -1.12, FRONT + 0.18]
],
radius: 0.16
},
{
x: -5.65,
points: [
[-5.65, surfaceY(-5.65, 3.82) + 0.03, 3.82],
[-5.38, 4.5, 4.3],
[-5.86, 3.55, FRONT + 0.15],
[-5.15, 2.72, FRONT + 0.16],
[-5.72, 1.82, FRONT + 0.16],
[-5.18, 0.78, FRONT + 0.16],
[-5.65, -0.12, FRONT + 0.16]
],
radius: 0.145
}
];
for (const def of burrowDefinitions) {
const rimPoints = def.points.map(p => new THREE.Vector3(p[0], p[1], p[2] - 0.07));
const darkPoints = def.points.map(p => new THREE.Vector3(p[0], p[1], p[2] + 0.045));
addTube(rimPoints, def.radius + 0.075, materials.tunnelRim, 70, 7);
addTube(darkPoints, def.radius, materials.tunnelDark, 70, 8);
const opening = new THREE.Mesh(
new THREE.CircleGeometry(def.radius * 1.08, 18),
materials.tunnelDark
);
opening.rotation.x = -Math.PI / 2;
opening.position.set(def.x, surfaceY(def.x, 3.8) + 0.018, 3.8);
scene.add(opening);
const lip = new THREE.Mesh(
new THREE.TorusGeometry(def.radius * 1.08, 0.035, 6, 22),
materials.tunnelRim
);
lip.rotation.x = Math.PI / 2;
lip.position.set(def.x, surfaceY(def.x, 3.8) + 0.025, 3.8);
scene.add(lip);
}
// Enlarged underground chambers at the ends of selected passages.
function addChamber(x, y, sx, sy) {
const cavity = new THREE.Mesh(
new THREE.SphereGeometry(1, 18, 12),
materials.tunnelDark
);
cavity.position.set(x, y, FRONT + 0.13);
cavity.scale.set(sx, sy, 0.11);
scene.add(cavity);
}
addChamber(5.08, -2.12, 0.72, 0.48);
addChamber(-0.45, -1.12, 0.57, 0.4);
addChamber(-5.65, -0.12, 0.5, 0.36);
// Root network exposed in the cut face.
const rootStarts = [-7.25, -4.45, -3.0, -0.15, 2.75, 7.2];
rootStarts.forEach((x, i) => {
const depth = [3.7, 4.45, 3.15, 4.65, 2.9, 3.65][i];
const points = [
new THREE.Vector3(x, surfaceY(x, FRONT) + 0.02, FRONT + 0.11),
new THREE.Vector3(x + range(-0.22, 0.22), 4.35, FRONT + 0.13),
new THREE.Vector3(x + range(-0.5, 0.5), 3.7, FRONT + 0.14),
new THREE.Vector3(x + range(-0.7, 0.7), surfaceY(x, FRONT) - depth + 0.8, FRONT + 0.14),
new THREE.Vector3(x + range(-0.9, 0.9), surfaceY(x, FRONT) - depth, FRONT + 0.15)
];
addTube(points, 0.052 + (i % 2) * 0.014, i % 2 ? materials.root : materials.rootLight, 35, 5);
for (let j = 0; j < 3; j++) {
const p = points[1 + Math.floor(random() * 3)];
const branchEnd = p.clone().add(new THREE.Vector3(
range(-0.9, 0.9),
range(-0.65, -0.1),
range(-0.03, 0.03)
));
addTube(
[p, p.clone().lerp(branchEnd, 0.52).add(new THREE.Vector3(0.08, 0.08, 0)), branchEnd],
0.025,
materials.rootLight,
18,
5
);
}
});
// Roots also travel laterally over the top surface.
for (let i = 0; i < 9; i++) {
const x = range(-8.1, 8.1);
const z = range(-3.8, 3.5);
const points = [
new THREE.Vector3(x, surfaceY(x, z) + 0.035, z),
new THREE.Vector3(x + range(-0.45, 0.45), surfaceY(x, z) + 0.045, z + range(-0.3, 0.3)),
new THREE.Vector3(x + range(-1.1, 1.1), surfaceY(x, z) + 0.04, z + range(-0.9, 0.9))
];
addTube(points, 0.035, materials.rootLight, 22, 5);
}
// Solid leaf litter.
const leafGeometry = new THREE.SphereGeometry(0.22, 9, 6);
const leafMaterials = [materials.leafA, materials.leafB, materials.leafC, materials.leafD];
for (let i = 0; i < 31; i++) {
const x = range(-8.45, 8.45);
const z = range(-4.0, 3.95);
const leaf = new THREE.Mesh(leafGeometry, pick(leafMaterials));
leaf.position.set(x, surfaceY(x, z) + 0.065, z);
leaf.scale.set(range(1.1, 1.9), range(0.12, 0.2), range(0.55, 0.95));
leaf.rotation.set(range(-0.16, 0.16), range(0, Math.PI * 2), range(-0.12, 0.12));
leaf.castShadow = true;
scene.add(leaf);
if (i % 3 === 0) {
const vein = cylinderBetween(
new THREE.Vector3(x - 0.22, leaf.position.y + 0.025, z),
new THREE.Vector3(x + 0.22, leaf.position.y + 0.025, z),
0.012,
materials.leafC,
5
);
vein.rotation.y = leaf.rotation.y;
scene.add(vein);
}
}
// Small woody twigs.
for (let i = 0; i < 6; i++) {
const x = range(-7.7, 7.7);
const z = range(-3.8, 3.7);
const a = new THREE.Vector3(x, surfaceY(x, z) + 0.09, z);
const b = a.clone().add(new THREE.Vector3(range(-1.2, 1.2), 0.02, range(-0.55, 0.55)));
scene.add(cylinderBetween(a, b, range(0.025, 0.045), materials.leafC, 6));
}
// Stylized grass tufts using solid tapered blades.
const bladeGeometry = new THREE.ConeGeometry(0.055, 0.62, 5);
for (let i = 0; i < 18; i++) {
const x = range(-8.5, 8.5);
const z = range(-4.0, 2.9);
const tuft = new THREE.Group();
for (let j = 0; j < 4; j++) {
const height = range(0.38, 0.78);
const blade = new THREE.Mesh(
new THREE.ConeGeometry(range(0.035, 0.06), height, 5),
pick([materials.greenA, materials.greenB, materials.greenC])
);
blade.position.set(range(-0.09, 0.09), height / 2, range(-0.09, 0.09));
blade.rotation.z = range(-0.35, 0.35);
blade.rotation.x = range(-0.25, 0.25);
blade.castShadow = true;
tuft.add(blade);
}
tuft.position.set(x, surfaceY(x, z), z);
scene.add(tuft);
}
// Surface moss patches.
for (let i = 0; i < 8; i++) {
const x = range(-8, 8);
const z = range(-3.8, 3.4);
const moss = new THREE.Mesh(organicBlob(1, 0.22), materials.greenC);
moss.rotation.x = -Math.PI / 2;
moss.position.set(x, surfaceY(x, z) + 0.025, z);
moss.scale.set(range(0.35, 0.75), range(0.25, 0.5), 1);
moss.receiveShadow = true;
scene.add(moss);
}
function makeAnt(scale = 1) {
const group = new THREE.Group();
const abdomen = new THREE.Mesh(new THREE.SphereGeometry(0.13, 10, 7), materials.ant);
abdomen.position.set(0, 0.13, -0.17);
abdomen.scale.set(1, 0.82, 1.25);
group.add(abdomen);
const thorax = new THREE.Mesh(new THREE.SphereGeometry(0.085, 9, 6), materials.antDark);
thorax.position.set(0, 0.12, 0.015);
group.add(thorax);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.1, 10, 7), materials.antDark);
head.position.set(0, 0.12, 0.17);
group.add(head);
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
const start = new THREE.Vector3(side * 0.045, 0.11, 0.09 - i * 0.075);
const end = new THREE.Vector3(side * 0.22, 0.025, 0.16 - i * 0.13);
const leg = cylinderBetween(start, end, 0.011, materials.antDark, 5);
group.add(leg);
}
const antenna = cylinderBetween(
new THREE.Vector3(side * 0.035, 0.16, 0.23),
new THREE.Vector3(side * 0.11, 0.19, 0.35),
0.009,
materials.antDark,
5
);
group.add(antenna);
}
group.scale.setScalar(scale);
group.traverse(o => { if (o.isMesh) o.castShadow = true; });
return group;
}
const ant1 = makeAnt(1);
ant1.position.set(-6.35, surfaceY(-6.35, 2.9) + 0.08, 2.9);
ant1.rotation.y = -0.45;
scene.add(ant1);
const ant2 = makeAnt(0.78);
ant2.position.set(-5.65, surfaceY(-5.65, 3.15) + 0.07, 3.15);
ant2.rotation.y = 1.25;
scene.add(ant2);
function makeSpringtail(scale = 1) {
const group = new THREE.Group();
const body = new THREE.Mesh(new THREE.SphereGeometry(0.085, 9, 6), materials.springtail);
body.scale.set(0.65, 0.45, 1.2);
body.position.y = 0.06;
group.add(body);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.035, 8, 5), materials.springtail);
head.position.set(0, 0.065, 0.085);
group.add(head);
for (const side of [-1, 1]) {
const antenna = cylinderBetween(
new THREE.Vector3(side * 0.018, 0.075, 0.1),
new THREE.Vector3(side * 0.08, 0.11, 0.23),
0.006,
materials.springtail,
5
);
group.add(antenna);
}
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
const leg = cylinderBetween(
new THREE.Vector3(side * 0.035, 0.04, 0.04 - i * 0.035),
new THREE.Vector3(side * 0.09, 0.01, 0.07 - i * 0.06),
0.005,
materials.springtail,
4
);
group.add(leg);
}
}
group.scale.setScalar(scale);
group.traverse(o => { if (o.isMesh) o.castShadow = true; });
return group;
}
[
[-6.05, 2.48, 1.0],
[-5.22, 2.73, 0.75],
[-6.78, 2.36, 0.62]
].forEach(([x, z, s]) => {
const springtail = makeSpringtail(s);
springtail.position.set(x, surfaceY(x, z) + 0.055, z);
springtail.rotation.y = range(-1, 1);
scene.add(springtail);
});
// Segmented earthworms occupy the deeper chambers.
function makeEarthworm(points, scale = 1, material = materials.worm) {
const group = new THREE.Group();
const curve = new THREE.CatmullRomCurve3(points);
const count = 15;
for (let i = 0; i < count; i++) {
const t = i / (count - 1);
const position = curve.getPointAt(t);
const tangent = curve.getTangentAt(t).normalize();
const taper = 0.72 + Math.sin(t * Math.PI) * 0.36;
const segment = new THREE.Mesh(
new THREE.SphereGeometry(0.115 * taper * scale, 10, 7),
i % 4 === 0 ? materials.wormDark : material
);
segment.position.copy(position);
segment.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), tangent);
segment.scale.set(1, 1.38, 0.9);
segment.castShadow = true;
group.add(segment);
}
// A subtle head taper.
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.11 * scale, 10, 7),
material
);
head.position.copy(curve.getPointAt(1));
head.scale.set(0.9, 0.8, 0.9);
group.add(head);
return group;
}
const worm1 = makeEarthworm([
new THREE.Vector3(4.0, -1.92, FRONT + 0.34),
new THREE.Vector3(4.25, -1.72, FRONT + 0.35),
new THREE.Vector3(4.55, -1.83, FRONT + 0.35),
new THREE.Vector3(4.82, -1.58, FRONT + 0.35),
new THREE.Vector3(5.1, -1.72, FRONT + 0.35),
new THREE.Vector3(5.38, -1.52, FRONT + 0.35),
new THREE.Vector3(5.67, -1.65, FRONT + 0.35)
], 1.08);
scene.add(worm1);
const worm2 = makeEarthworm([
new THREE.Vector3(-1.12, -0.92, FRONT + 0.29),
new THREE.Vector3(-0.92, -1.12, FRONT + 0.3),
new THREE.Vector3(-0.67, -1.0, FRONT + 0.3),
new THREE.Vector3(-0.42, -1.18, FRONT + 0.3),
new THREE.Vector3(-0.16, -1.04, FRONT + 0.3)
], 0.68, materials.wormDark);
scene.add(worm2);
// Root-zone nematodes: tiny pale curves close to the upper roots.
const nematodeMaterial = materials.nematode;
const nematodeCurves = [
[[-3.3, 2.95], [-3.02, 2.75], [-2.8, 2.83], [-2.57, 2.58]],
[[-2.9, 1.93], [-2.62, 1.78], [-2.4, 1.89], [-2.17, 1.68]],
[[-4.75, 2.18], [-4.53, 2.02], [-4.3, 2.1], [-4.08, 1.91]]
];
nematodeCurves.forEach(points => {
const vectors = points.map(([x, y]) => new THREE.Vector3(x, y, FRONT + 0.2));
addTube(vectors, 0.026, nematodeMaterial, 28, 5);
});
// HTML labels projected from fixed 3D positions.
const labelData = [
{ text: "Surface litter", num: "01", pos: new THREE.Vector3(-6.1, surfaceY(-6.1, 2.9) + 0.25, 2.9) },
{ text: "Root network", num: "02", pos: new THREE.Vector3(-3.05, 3.35, FRONT + 0.35) },
{ text: "Moisture pocket", num: "03", pos: new THREE.Vector3(6.4, -3.82, FRONT + 0.3) },
{ text: "Deep burrows", num: "04", pos: new THREE.Vector3(4.95, -2.35, FRONT + 0.4) }
];
labelData.forEach(data => {
const element = document.createElement("div");
element.className = "scene-label";
element.innerHTML = `<span class="num">${data.num}</span><span>${data.text}</span>`;
document.body.appendChild(element);
data.element = element;
});
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelData.forEach(data => {
const p = data.pos.clone().project(camera);
const x = (p.x * 0.5 + 0.5) * width;
const y = (-p.y * 0.5 + 0.5) * height;
const visible = p.z > -1 && p.z < 1;
data.element.style.left = `${x}px`;
data.element.style.top = `${y}px`;
data.element.style.opacity = visible ? "1" : "0";
});
}
// Custom pointer orbit controls; no external control modules are used.
let dragging = false;
let lastX = 0;
let lastY = 0;
const activePointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", event => {
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 1) {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
});
canvas.addEventListener("pointermove", event => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
if (pinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (pinchDistance / distance),
18,
42
);
}
pinchDistance = distance;
} else if (dragging) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.55, 1.47);
lastX = event.clientX;
lastY = event.clientY;
}
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
if (activePointers.size === 0) {
dragging = false;
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
18,
42
);
}, { passive: false });
document.querySelector("#reset").addEventListener("click", () => {
controls.target.set(0, -0.2, 0);
controls.radius = 28;
controls.theta = 0.58;
controls.phi = 1.17;
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```