Prompt specification
Build or customize the Three.js 3D scene "Shaded stone wall microhabitat" 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: Shaded stone wall microhabitat
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shaded-stone-wall-microhabitat-x0755
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: shaded stone wall microhabitat. Compose a stone wall with crevices, moss patches, trickling water, and dry exposed faces; moisture distribution explains the placement of different small habitat patches.
Working Three.js Starter (shaded-stone-wall-microhabitat-x0755):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stone Wall Microhabitat</title>
<style>
:root {
color-scheme: dark;
--ink: #eef3e9;
--muted: #aebcaf;
--glass: rgba(16, 27, 23, 0.72);
--line: rgba(218, 236, 220, 0.14);
--moss: #789342;
--wet: #68b9bd;
--lichen: #c7c49c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101915;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.interface {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-block {
position: absolute;
top: clamp(24px, 4vw, 54px);
left: clamp(22px, 4vw, 58px);
max-width: min(520px, calc(100vw - 44px));
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #bdd3c2;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 29px;
height: 1px;
content: "";
background: #91aa92;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(35px, 5.3vw, 70px);
font-weight: 400;
line-height: 0.96;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 420px;
margin: 17px 0 0;
color: var(--muted);
font-size: clamp(12px, 1.4vw, 15px);
line-height: 1.6;
}
.panel {
position: absolute;
right: clamp(18px, 3vw, 40px);
bottom: clamp(18px, 3vw, 36px);
width: min(292px, calc(100vw - 36px));
padding: 17px 18px 16px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--glass);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: auto;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 13px;
}
.panel-title {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
button {
border: 1px solid rgba(222, 239, 225, 0.2);
border-radius: 999px;
padding: 7px 10px;
background: rgba(223, 238, 226, 0.06);
color: #dce9dd;
font: inherit;
font-size: 10px;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(222, 239, 225, 0.42);
background: rgba(223, 238, 226, 0.13);
}
button:active {
transform: scale(0.97);
}
button[aria-pressed="true"] {
border-color: rgba(104, 185, 189, 0.7);
background: rgba(104, 185, 189, 0.19);
color: #d9ffff;
}
.legend {
display: grid;
gap: 10px;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr;
align-items: start;
gap: 10px;
color: #c8d4c9;
font-size: 11px;
line-height: 1.4;
}
.swatch {
width: 9px;
height: 9px;
margin-top: 3px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.035);
}
.swatch.wet {
background: var(--wet);
box-shadow: 0 0 12px rgba(104, 185, 189, 0.45);
}
.swatch.moss {
background: var(--moss);
}
.swatch.lichen {
background: var(--lichen);
}
.swatch.stone {
background: #85877a;
}
.legend-row strong {
display: block;
margin-bottom: 1px;
color: #edf3eb;
font-size: 11px;
font-weight: 650;
}
.panel-note {
margin: 14px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #91a196;
font-size: 10px;
line-height: 1.5;
}
.instructions {
position: absolute;
bottom: clamp(21px, 3vw, 38px);
left: clamp(22px, 4vw, 58px);
display: flex;
align-items: center;
gap: 10px;
color: rgba(215, 227, 214, 0.65);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.instructions span {
width: 4px;
height: 4px;
border-radius: 50%;
background: rgba(215, 227, 214, 0.4);
}
@media (max-width: 700px) {
.title-block {
top: 22px;
}
.subtitle {
max-width: 290px;
font-size: 12px;
}
.panel {
right: 14px;
bottom: 14px;
width: 236px;
padding: 14px;
}
.legend {
gap: 7px;
}
.legend-row,
.legend-row strong {
font-size: 10px;
}
.panel-note,
.instructions {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<main class="interface">
<section class="title-block">
<div class="eyebrow">Microhabitat study · 03</div>
<h1>A small ecology<br>in stone.</h1>
<p class="subtitle">
A shaded wall divided by exposure and water: moss gathers around the
seep, lichen occupies the dry face, and every living patch follows
the moisture map.
</p>
</section>
<aside class="panel">
<div class="panel-heading">
<div class="panel-title">Moisture map</div>
<button id="moistureToggle" aria-pressed="false">Overlay</button>
</div>
<div class="legend">
<div class="legend-row">
<i class="swatch wet"></i>
<div><strong>Active seep</strong>Persistent water and shaded stone</div>
</div>
<div class="legend-row">
<i class="swatch moss"></i>
<div><strong>Moss colonies</strong>Damp crevices and lower ledges</div>
</div>
<div class="legend-row">
<i class="swatch lichen"></i>
<div><strong>Crustose lichen</strong>Dry, exposed upper faces</div>
</div>
<div class="legend-row">
<i class="swatch stone"></i>
<div><strong>Bare stone</strong>Low moisture and little nutrient</div>
</div>
</div>
<p class="panel-note">
Toggle the overlay to reveal the hidden moisture gradient that
determines where each community can establish.
</p>
</aside>
<div class="instructions">
Drag to orbit <span></span> Scroll to inspect <span></span> Double-click to reset
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, scene, and camera
// ---------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x111a16);
scene.fog = new THREE.FogExp2(0x111a16, 0.047);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
60
);
const target = new THREE.Vector3(0, 2.55, 0);
const desired = {
radius: 9.5,
theta: 0.62,
phi: 1.27
};
const current = {
radius: desired.radius,
theta: desired.theta,
phi: desired.phi
};
function updateCamera(immediate = false) {
if (immediate) {
current.radius = desired.radius;
current.theta = desired.theta;
current.phi = desired.phi;
}
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
}
updateCamera(true);
// ---------------------------------------------------------------------
// Deterministic randomness and utilities
// ---------------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6d2b79f5;
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 = mulberry32(723451);
const randomRange = (a, b) => a + (b - a) * random();
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(a, b, value) {
const t = clamp((value - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function cylinderBetween(a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius * 0.88,
length,
radialSegments,
1
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Lighting: cool shade, a warmer grazing light, and a seep accent
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb8d8ca, 0x2b241b, 1.55));
const sun = new THREE.DirectionalLight(0xffdfaa, 3.25);
sun.position.set(-4.5, 8.5, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -2;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.0008;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const seepLight = new THREE.PointLight(0x70c8cc, 7.5, 5.5, 2);
seepLight.position.set(1.45, 3.4, 1.15);
scene.add(seepLight);
const warmBounce = new THREE.PointLight(0xd7a76d, 3.5, 8, 2);
warmBounce.position.set(-3.2, 1.2, 3.5);
scene.add(warmBounce);
// ---------------------------------------------------------------------
// Backdrop, soil, and the wall
// ---------------------------------------------------------------------
const backdropMaterial = new THREE.MeshStandardMaterial({
color: 0x26342c,
roughness: 1
});
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(24, 16),
backdropMaterial
);
backdrop.position.set(0, 4, -1.55);
backdrop.receiveShadow = true;
scene.add(backdrop);
const backingMaterial = new THREE.MeshStandardMaterial({
color: 0x303a32,
roughness: 1
});
const backing = new THREE.Mesh(
new THREE.BoxGeometry(10.2, 6.4, 0.65),
backingMaterial
);
backing.position.set(0, 2.65, -0.82);
backing.castShadow = true;
backing.receiveShadow = true;
scene.add(backing);
const groundGeometry = new THREE.PlaneGeometry(15, 10, 18, 12);
groundGeometry.rotateX(-Math.PI / 2);
const groundPositions = groundGeometry.attributes.position;
for (let i = 0; i < groundPositions.count; i++) {
const x = groundPositions.getX(i);
const z = groundPositions.getZ(i);
groundPositions.setY(
i,
Math.sin(x * 1.7) * 0.025 +
Math.cos(z * 2.1) * 0.02 +
randomRange(-0.018, 0.018)
);
}
groundGeometry.computeVertexNormals();
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x3a3023,
roughness: 1
});
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.position.y = -0.05;
ground.receiveShadow = true;
scene.add(ground);
const dryColor = new THREE.Color(0x99907b);
const dampColor = new THREE.Color(0x59665b);
const wetColor = new THREE.Color(0x344941);
const overlayColor = new THREE.Color(0x39aeba);
function moistureAt(x, y) {
const seepBand =
Math.exp(-Math.pow((x - 1.45) / 1.12, 2)) *
(0.48 + 0.52 * (1 - clamp(y / 5.8, 0, 1)));
const lowerPocket =
0.36 *
Math.exp(-Math.pow(y / 1.15, 2)) *
(0.58 + 0.42 * Math.exp(-Math.pow((x + 1.8) / 2.7, 2)));
const shadedBase = 0.13 * (1 - clamp(y / 5.8, 0, 1));
return clamp(seepBand + lowerPocket + shadedBase, 0, 1);
}
function makeStoneGeometry(width, height, depth, seed) {
const geometry = new THREE.BoxGeometry(
width,
height,
depth,
3,
3,
2
);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const edgeWear =
Math.sin(y * 2.8 + seed) * 0.018 +
Math.sin(z * 6.1 + seed * 0.7) * 0.009;
positions.setXYZ(
i,
x + Math.sin(y * 3.7 + seed * 0.5) * 0.018 + edgeWear,
y + Math.sin(x * 4.2 + seed * 0.9) * 0.017,
z + Math.sin(x * 2.6 + y * 3.1 + seed) * 0.035
);
}
geometry.computeVertexNormals();
return geometry;
}
const stoneRecords = [];
const rowHeights = [0.92, 1.03, 0.88, 1.12, 0.98, 1.02];
let bottom = 0.06;
let row = 0;
while (bottom < 5.6) {
const height = rowHeights[row % rowHeights.length];
let left = -4.78;
let column = 0;
while (left < 4.68) {
let width = randomRange(1.02, 1.72);
if (left + width > 4.75) {
width = 4.75 - left;
}
if (width > 0.35) {
const depth = randomRange(0.78, 0.98);
const x = left + width * 0.5;
const y = bottom + height * 0.5;
const moisture = moistureAt(x, y);
const baseColor = dryColor
.clone()
.lerp(dampColor, smoothstep(0.12, 0.64, moisture))
.lerp(wetColor, smoothstep(0.58, 0.95, moisture));
const variation = randomRange(-0.055, 0.055);
baseColor.offsetHSL(variation * 0.35, variation * 0.25, variation);
const material = new THREE.MeshStandardMaterial({
color: baseColor,
roughness: lerp(0.98, 0.73, moisture),
metalness: 0
});
const geometry = makeStoneGeometry(
width - 0.075,
height - 0.07,
depth,
randomRange(0, 30)
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(
x,
y,
randomRange(-0.22, -0.11)
);
const rotationZ = randomRange(-0.026, 0.026);
const rotationY = randomRange(-0.025, 0.025);
mesh.rotation.set(0, rotationY, rotationZ);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const quaternion = mesh.quaternion.clone();
stoneRecords.push({
mesh,
material,
baseColor: baseColor.clone(),
moisture,
width,
height,
depth,
position: mesh.position.clone(),
quaternion
});
}
left += width + randomRange(0.055, 0.105);
column++;
}
bottom += height + randomRange(0.045, 0.085);
row++;
}
// ---------------------------------------------------------------------
// Moss: concentrated by damp crevices and the lower wall
// ---------------------------------------------------------------------
const mossTransforms = [];
const mossColors = [];
const mossPalette = [
new THREE.Color(0x4e672b),
new THREE.Color(0x668038),
new THREE.Color(0x7b913e),
new THREE.Color(0x3f592b)
];
const localMossQuaternion = new THREE.Quaternion();
const localPosition = new THREE.Vector3();
for (const stone of stoneRecords) {
if (
stone.moisture < 0.255 ||
random() > 0.82 + stone.moisture * 0.15
) {
continue;
}
const patchCount = Math.round(lerp(12, 28, stone.moisture));
const patchX = randomRange(
-stone.width * 0.22,
stone.width * 0.22
);
const patchY = randomRange(
-stone.height * 0.2,
stone.height * 0.2
);
const patchWidth = randomRange(0.2, 0.42);
const patchHeight = randomRange(0.12, 0.25);
for (let i = 0; i < patchCount; i++) {
const angle = randomRange(0, Math.PI * 2);
const radius = Math.sqrt(random());
localPosition.set(
patchX + Math.cos(angle) * patchWidth * radius,
patchY + Math.sin(angle) * patchHeight * radius,
stone.depth * 0.5 + randomRange(0.025, 0.075)
);
const worldPosition = localPosition
.clone()
.applyQuaternion(stone.quaternion)
.add(stone.position);
localMossQuaternion.setFromEuler(
new THREE.Euler(
randomRange(-0.5, 0.5),
randomRange(-0.4, 0.4),
randomRange(0, Math.PI * 2)
)
);
const worldQuaternion = stone.quaternion
.clone()
.multiply(localMossQuaternion);
const scale = new THREE.Vector3(
randomRange(0.09, 0.21) * (0.7 + radius * 0.4),
randomRange(0.065, 0.14),
randomRange(0.035, 0.075)
);
mossTransforms.push({
position: worldPosition,
quaternion: worldQuaternion,
scale
});
const color = mossPalette[
Math.floor(random() * mossPalette.length)
].clone();
color.offsetHSL(
randomRange(-0.025, 0.025),
randomRange(-0.04, 0.05),
randomRange(-0.035, 0.035)
);
mossColors.push(color);
}
}
const mossMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
flatShading: true
});
const mossGeometry = new THREE.IcosahedronGeometry(1, 1);
const moss = new THREE.InstancedMesh(
mossGeometry,
mossMaterial,
mossTransforms.length
);
const instanceDummy = new THREE.Object3D();
mossTransforms.forEach((transform, index) => {
instanceDummy.position.copy(transform.position);
instanceDummy.quaternion.copy(transform.quaternion);
instanceDummy.scale.copy(transform.scale);
instanceDummy.updateMatrix();
moss.setMatrixAt(index, instanceDummy.matrix);
moss.setColorAt(index, mossColors[index]);
});
moss.instanceMatrix.needsUpdate = true;
moss.instanceColor.needsUpdate = true;
moss.castShadow = true;
moss.receiveShadow = true;
scene.add(moss);
// ---------------------------------------------------------------------
// Lichen: pale crusts restricted to exposed, dry stone
// ---------------------------------------------------------------------
const lichenGeometry = new THREE.CircleGeometry(1, 13);
const lichenPositions = lichenGeometry.attributes.position;
for (let i = 0; i < lichenPositions.count; i++) {
const x = lichenPositions.getX(i);
const y = lichenPositions.getY(i);
const angle = Math.atan2(y, x);
const radius = 0.82 + Math.sin(angle * 5.0 + 1.2) * 0.13;
lichenPositions.setXY(i, x * radius, y * radius);
}
lichenGeometry.computeVertexNormals();
const lichenTransforms = [];
const lichenColors = [];
const lichenPalette = [
new THREE.Color(0xb7b791),
new THREE.Color(0xced0aa),
new THREE.Color(0x929d77),
new THREE.Color(0xd3c7a0)
];
for (const stone of stoneRecords) {
if (stone.moisture > 0.36) {
continue;
}
const count = Math.floor(randomRange(3, 9));
for (let i = 0; i < count; i++) {
const local = new THREE.Vector3(
randomRange(-stone.width * 0.42, stone.width * 0.42),
randomRange(-stone.height * 0.4, stone.height * 0.4),
stone.depth * 0.5 + randomRange(0.036, 0.052)
);
const position = local
.clone()
.applyQuaternion(stone.quaternion)
.add(stone.position);
const rotation = new THREE.Quaternion().setFromAxisAngle(
new THREE.Vector3(0, 0, 1),
randomRange(0, Math.PI * 2)
);
const quaternion = stone.quaternion.clone().multiply(rotation);
const size = randomRange(0.045, 0.135);
lichenTransforms.push({
position,
quaternion,
scale: new THREE.Vector3(size, size * randomRange(0.65, 1.2), 1)
});
lichenColors.push(
lichenPalette[Math.floor(random() * lichenPalette.length)].clone()
);
}
}
const lichenMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
side: THREE.DoubleSide
});
const lichen = new THREE.InstancedMesh(
lichenGeometry,
lichenMaterial,
lichenTransforms.length
);
lichenTransforms.forEach((transform, index) => {
instanceDummy.position.copy(transform.position);
instanceDummy.quaternion.copy(transform.quaternion);
instanceDummy.scale.copy(transform.scale);
instanceDummy.updateMatrix();
lichen.setMatrixAt(index, instanceDummy.matrix);
lichen.setColorAt(index, lichenColors[index]);
});
lichen.instanceMatrix.needsUpdate = true;
lichen.instanceColor.needsUpdate = true;
lichen.receiveShadow = true;
scene.add(lichen);
// ---------------------------------------------------------------------
// Trickling water and damp stone trail
// ---------------------------------------------------------------------
const seepCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.38, 5.12, 0.37),
new THREE.Vector3(1.44, 4.78, 0.39),
new THREE.Vector3(1.34, 4.43, 0.38),
new THREE.Vector3(1.52, 4.08, 0.40),
new THREE.Vector3(1.43, 3.72, 0.39),
new THREE.Vector3(1.57, 3.36, 0.41),
new THREE.Vector3(1.44, 3.02, 0.40),
new THREE.Vector3(1.55, 2.64, 0.42),
new THREE.Vector3(1.42, 2.26, 0.41),
new THREE.Vector3(1.50, 1.86, 0.43),
new THREE.Vector3(1.40, 1.43, 0.44),
new THREE.Vector3(1.48, 0.98, 0.46),
new THREE.Vector3(1.39, 0.52, 0.49),
new THREE.Vector3(1.44, 0.12, 0.54)
]);
function createWetRibbon(curve, width) {
const vertices = [];
const indices = [];
const samples = 80;
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
const side = new THREE.Vector3(
-tangent.y,
tangent.x,
0
).normalize();
const halfWidth = width * (0.6 + Math.sin(t * 20) * 0.12);
vertices.push(
point.x - side.x * halfWidth,
point.y - side.y * halfWidth,
point.z - 0.012,
point.x + side.x * halfWidth,
point.y + side.y * halfWidth,
point.z - 0.012
);
if (i < samples) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: 0x173d37,
transparent: true,
opacity: 0.33,
roughness: 0.72,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
}
createWetRibbon(seepCurve, 0.15);
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x83d1d4,
roughness: 0.12,
metalness: 0,
transmission: 0.35,
transparent: true,
opacity: 0.86,
thickness: 0.08,
emissive: 0x123d42,
emissiveIntensity: 0.18
});
const mainStream = new THREE.Mesh(
new THREE.TubeGeometry(seepCurve, 100, 0.022, 7, false),
waterMaterial
);
mainStream.castShadow = true;
scene.add(mainStream);
const hairlineCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.58, 4.54, 0.37),
new THREE.Vector3(1.68, 4.26, 0.39),
new THREE.Vector3(1.61, 3.97, 0.40),
new THREE.Vector3(1.72, 3.64, 0.41),
new THREE.Vector3(1.64, 3.27, 0.42)
]);
const hairline = new THREE.Mesh(
new THREE.TubeGeometry(hairlineCurve, 35, 0.009, 5, false),
waterMaterial
);
scene.add(hairline);
const springMaterial = new THREE.MeshStandardMaterial({
color: 0x101a16,
roughness: 1
});
const spring = new THREE.Mesh(
new THREE.SphereGeometry(1, 16, 10),
springMaterial
);
spring.position.set(1.38, 5.12, 0.34);
spring.scale.set(0.19, 0.075, 0.045);
scene.add(spring);
const dropletGeometry = new THREE.SphereGeometry(1, 8, 6);
const dropletMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc1f5f3,
roughness: 0.05,
transmission: 0.25,
transparent: true,
opacity: 0.9,
emissive: 0x17484b,
emissiveIntensity: 0.25
});
const dropletCount = 18;
const droplets = new THREE.InstancedMesh(
dropletGeometry,
dropletMaterial,
dropletCount
);
droplets.frustumCulled = false;
droplets.castShadow = true;
scene.add(droplets);
// ---------------------------------------------------------------------
// Pool, ripples, pebbles, and leaf litter
// ---------------------------------------------------------------------
const puddleGeometry = new THREE.CircleGeometry(1, 40);
const puddlePositions = puddleGeometry.attributes.position;
for (let i = 0; i < puddlePositions.count; i++) {
const x = puddlePositions.getX(i);
const y = puddlePositions.getY(i);
const angle = Math.atan2(y, x);
const radius = 0.88 + Math.sin(angle * 4.0) * 0.07 +
Math.sin(angle * 9.0 + 0.8) * 0.035;
puddlePositions.setXY(i, x * radius, y * radius);
}
puddleGeometry.computeVertexNormals();
const puddleMaterial = new THREE.MeshPhysicalMaterial({
color: 0x365b58,
roughness: 0.12,
metalness: 0.05,
transparent: true,
opacity: 0.82,
clearcoat: 1,
clearcoatRoughness: 0.08
});
const puddle = new THREE.Mesh(puddleGeometry, puddleMaterial);
puddle.rotation.x = -Math.PI / 2;
puddle.position.set(1.43, 0.012, 0.61);
puddle.scale.set(0.95, 0.53, 1);
puddle.receiveShadow = true;
scene.add(puddle);
const ripples = [];
for (let i = 0; i < 3; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0x9bdcda,
transparent: true,
opacity: 0.3,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.15, 0.009, 5, 40),
material
);
ring.rotation.x = Math.PI / 2;
ring.position.set(1.43, 0.035, 0.62);
scene.add(ring);
ripples.push(ring);
}
const pebbleGeometry = new THREE.IcosahedronGeometry(1, 1);
const pebbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
flatShading: true
});
const pebbleCount = 58;
const pebbles = new THREE.InstancedMesh(
pebbleGeometry,
pebbleMaterial,
pebbleCount
);
for (let i = 0; i < pebbleCount; i++) {
const angle = randomRange(0, Math.PI * 2);
const distance = randomRange(0.35, 5.3);
instanceDummy.position.set(
Math.cos(angle) * distance,
randomRange(0.025, 0.075),
randomRange(0.25, 1.75)
);
instanceDummy.rotation.set(
randomRange(0, Math.PI),
randomRange(0, Math.PI),
randomRange(0, Math.PI)
);
const size = randomRange(0.035, 0.15);
instanceDummy.scale.set(
size * randomRange(0.8, 1.6),
size * randomRange(0.45, 0.8),
size
);
instanceDummy.updateMatrix();
pebbles.setMatrixAt(i, instanceDummy.matrix);
const color = new THREE.Color(0x7c7b6d).lerp(
new THREE.Color(0x444d46),
random()
);
pebbles.setColorAt(i, color);
}
pebbles.instanceMatrix.needsUpdate = true;
pebbles.instanceColor.needsUpdate = true;
pebbles.castShadow = true;
pebbles.receiveShadow = true;
scene.add(pebbles);
const leafGeometry = new THREE.CircleGeometry(1, 8);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
side: THREE.DoubleSide
});
const leafCount = 34;
const leaves = new THREE.InstancedMesh(
leafGeometry,
leafMaterial,
leafCount
);
for (let i = 0; i < leafCount; i++) {
instanceDummy.position.set(
randomRange(-4.7, 4.6),
randomRange(0.025, 0.045),
randomRange(0.25, 1.9)
);
instanceDummy.rotation.set(
-Math.PI / 2 + randomRange(-0.12, 0.12),
randomRange(-0.2, 0.2),
randomRange(0, Math.PI * 2)
);
instanceDummy.scale.set(
randomRange(0.07, 0.16),
randomRange(0.035, 0.08),
1
);
instanceDummy.updateMatrix();
leaves.setMatrixAt(i, instanceDummy.matrix);
const color = new THREE.Color(0x8d512d).lerp(
new THREE.Color(0xb38a45),
random()
);
leaves.setColorAt(i, color);
}
leaves.instanceMatrix.needsUpdate = true;
leaves.instanceColor.needsUpdate = true;
leaves.receiveShadow = true;
scene.add(leaves);
// ---------------------------------------------------------------------
// Small fern in the sheltered damp pocket
// ---------------------------------------------------------------------
const fern = new THREE.Group();
fern.position.set(2.65, 0.02, 0.82);
fern.rotation.y = -0.45;
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x496532,
roughness: 0.92
});
const fernLeafMaterial = new THREE.MeshStandardMaterial({
color: 0x66833b,
roughness: 0.86,
flatShading: true
});
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2 + randomRange(-0.2, 0.2);
const reach = randomRange(0.25, 0.52);
const height = randomRange(0.42, 0.78);
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(
Math.cos(angle) * reach * 0.25,
height * 0.45,
Math.sin(angle) * reach * 0.25
),
new THREE.Vector3(
Math.cos(angle) * reach,
height,
Math.sin(angle) * reach
)
]);
const stem = new THREE.Mesh(
new THREE.TubeGeometry(curve, 12, 0.009, 5, false),
stemMaterial
);
stem.castShadow = true;
fern.add(stem);
for (let j = 1; j <= 4; j++) {
const t = j / 5;
const point = curve.getPointAt(t);
const leaf = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
fernLeafMaterial
);
leaf.position.copy(point);
leaf.scale.set(0.105, 0.018, 0.042);
leaf.rotation.set(
randomRange(-0.2, 0.2),
-angle + randomRange(-0.3, 0.3),
randomRange(-0.35, 0.35)
);
leaf.castShadow = true;
fern.add(leaf);
}
}
scene.add(fern);
// A sparse dry grass tuft for contrast
const dryGrassMaterial = new THREE.MeshStandardMaterial({
color: 0x8c8151,
roughness: 1
});
for (let i = 0; i < 11; i++) {
const angle = randomRange(0, Math.PI * 2);
const height = randomRange(0.18, 0.38);
const grass = new THREE.Mesh(
new THREE.ConeGeometry(0.012, height, 4),
dryGrassMaterial
);
grass.position.set(
-3.2 + Math.cos(angle) * randomRange(0, 0.25),
height * 0.5,
0.85 + Math.sin(angle) * randomRange(0, 0.2)
);
grass.rotation.z = randomRange(-0.5, 0.5);
grass.rotation.x = randomRange(-0.35, 0.35);
grass.castShadow = true;
scene.add(grass);
}
// ---------------------------------------------------------------------
// Overhanging branch and suspended dust
// ---------------------------------------------------------------------
const branchMaterial = new THREE.MeshStandardMaterial({
color: 0x29251d,
roughness: 1
});
cylinderBetween(
new THREE.Vector3(-5.0, 5.85, 0.85),
new THREE.Vector3(4.8, 6.25, -0.05),
0.085,
branchMaterial,
7
);
cylinderBetween(
new THREE.Vector3(-0.8, 6.05, 0.43),
new THREE.Vector3(0.15, 7.1, 0.05),
0.043,
branchMaterial,
6
);
cylinderBetween(
new THREE.Vector3(2.8, 6.16, 0.25),
new THREE.Vector3(3.7, 7.0, 0.0),
0.035,
branchMaterial,
6
);
const dustCount = 150;
const dustPositions = new Float32Array(dustCount * 3);
const dustSpeeds = new Float32Array(dustCount);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = randomRange(-5.5, 5.5);
dustPositions[i * 3 + 1] = randomRange(0.35, 6.2);
dustPositions[i * 3 + 2] = randomRange(0.0, 3.6);
dustSpeeds[i] = randomRange(0.02, 0.09);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dustMaterial = new THREE.PointsMaterial({
color: 0xe8dfbd,
size: 0.026,
transparent: true,
opacity: 0.34,
depthWrite: false,
sizeAttenuation: true
});
const dust = new THREE.Points(dustGeometry, dustMaterial);
scene.add(dust);
// ---------------------------------------------------------------------
// Moisture overlay
// ---------------------------------------------------------------------
const moistureToggle = document.querySelector("#moistureToggle");
let moistureOverlay = false;
moistureToggle.addEventListener("click", () => {
moistureOverlay = !moistureOverlay;
moistureToggle.setAttribute("aria-pressed", String(moistureOverlay));
for (const stone of stoneRecords) {
stone.material.color.copy(stone.baseColor);
if (moistureOverlay) {
stone.material.color.lerp(
overlayColor,
0.12 + stone.moisture * 0.55
);
stone.material.emissive.set(0x082d31);
stone.material.emissiveIntensity = stone.moisture * 0.16;
} else {
stone.material.emissive.set(0x000000);
stone.material.emissiveIntensity = 0;
}
}
});
// ---------------------------------------------------------------------
// Direct camera controls — no addons
// ---------------------------------------------------------------------
let dragging = false;
let lastX = 0;
let lastY = 0;
let pointerId = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) {
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
desired.theta -= dx * 0.005;
desired.phi = clamp(
desired.phi - dy * 0.0045,
0.64,
1.48
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) {
return;
}
dragging = false;
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
5.6,
14.5
);
},
{ passive: false }
);
function resetCamera() {
desired.radius = 9.5;
desired.theta = 0.62;
desired.phi = 1.27;
}
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const dropletPoint = new THREE.Vector3();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.04);
current.theta = lerp(current.theta, desired.theta, 0.075);
current.phi = lerp(current.phi, desired.phi, 0.075);
current.radius = lerp(current.radius, desired.radius, 0.085);
updateCamera();
for (let i = 0; i < dropletCount; i++) {
const t = (i / dropletCount + elapsed * 0.095) % 1;
seepCurve.getPointAt(t, dropletPoint);
const size = 0.018 + Math.sin(i * 7.3) * 0.004;
const stretch = 1.5 + Math.sin(i * 2.8 + elapsed) * 0.35;
instanceDummy.position.copy(dropletPoint);
instanceDummy.quaternion.identity();
instanceDummy.scale.set(size, size * stretch, size);
instanceDummy.updateMatrix();
droplets.setMatrixAt(i, instanceDummy.matrix);
}
droplets.instanceMatrix.needsUpdate = true;
ripples.forEach((ring, index) => {
const phase = (elapsed * 0.42 + index / ripples.length) % 1;
const scale = 0.45 + phase * 3.8;
ring.scale.setScalar(scale);
ring.material.opacity = (1 - phase) * 0.26;
});
const dustAttribute = dustGeometry.attributes.position;
for (let i = 0; i < dustCount; i++) {
let y = dustAttribute.getY(i) + dustSpeeds[i] * delta;
if (y > 6.4) {
y = 0.3;
}
dustAttribute.setY(i, y);
dustAttribute.setX(
i,
dustAttribute.getX(i) + Math.sin(elapsed * 0.25 + i) * delta * 0.006
);
}
dustAttribute.needsUpdate = true;
seepLight.intensity =
7.5 + Math.sin(elapsed * 1.8) * 0.35;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```