Prompt specification
Build or customize the Three.js 3D scene "Streamside farm buffer strip" 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: Streamside farm buffer strip
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/streamside-farm-buffer-strip-x1063
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts farm soil erosion control. Compose fields, a planted buffer, shallow ditch, and stream; runoff arrows cross the vegetation zone while sediment markers settle in the model's designated capture region. Stylized solid forms.
Working Three.js Starter (streamside-farm-buffer-strip-x1063):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Farm Soil Erosion Control</title>
<style>
:root {
--ink: #26352c;
--muted: #617168;
--paper: rgba(251, 252, 247, 0.92);
--line: rgba(38, 53, 44, 0.14);
--runoff: #4aa9b5;
--plants: #71934e;
--sediment: #bd7040;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ede3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 5;
top: 30px;
left: 34px;
width: min(410px, calc(100vw - 68px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: #56705d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 390px;
font-size: clamp(32px, 4vw, 52px);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro {
max-width: 350px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 18px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(250, 252, 247, 0.7);
color: #526359;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
}
.badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #6f9853;
box-shadow: 0 0 0 4px rgba(111, 152, 83, 0.14);
content: "";
}
.legend {
position: fixed;
z-index: 5;
bottom: 28px;
left: 34px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100vw - 68px);
pointer-events: none;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--paper);
color: #526158;
font-size: 11px;
font-weight: 700;
box-shadow: 0 8px 30px rgba(45, 61, 49, 0.08);
backdrop-filter: blur(12px);
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--color);
}
.controls {
position: fixed;
z-index: 6;
right: 30px;
bottom: 28px;
display: flex;
align-items: center;
gap: 10px;
}
.hint {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--paper);
color: #68766d;
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(12px);
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(38, 53, 44, 0.16);
border-radius: 10px;
background: #31483a;
color: #f6f8f2;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 24px rgba(40, 57, 45, 0.15);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: #263a2e;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(74, 169, 181, 0.35);
outline-offset: 3px;
}
@media (max-width: 700px) {
.hud {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
h1 {
max-width: 280px;
font-size: 34px;
}
.intro {
display: none;
}
.badge {
margin-top: 12px;
}
.legend {
bottom: 68px;
left: 20px;
max-width: calc(100vw - 40px);
}
.legend-item {
padding: 8px 9px;
font-size: 10px;
}
.controls {
right: 20px;
bottom: 18px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<div class="eyebrow">Soil & Water · Interactive Field Model</div>
<h1>Farm soil erosion control</h1>
<p class="intro">
Runoff travels through a planted buffer. Vegetation slows the flow while
sediment settles in the designated forebay before the water reaches the stream.
</p>
<div class="badge">Conservation practice in action</div>
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch" style="--color: #4aa9b5"></span>
Runoff flow
</div>
<div class="legend-item">
<span class="swatch" style="--color: #71934e"></span>
Planted buffer
</div>
<div class="legend-item">
<span class="swatch" style="--color: #bd7040"></span>
Settled sediment
</div>
</div>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom</div>
<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";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ede3);
scene.fog = new THREE.Fog(0xe8ede3, 24, 48);
const camera = new THREE.PerspectiveCamera(
34,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional farm erosion-control model"
);
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf8fff1, 0x6d5a42, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4d8, 3.15);
sun.position.set(-8, 14, 9);
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 = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbad9e2, 0.65);
fill.position.set(10, 5, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
let seed = 92817;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function ditchCenter(z) {
return 2.35 + Math.sin(z * 0.58) * 0.11;
}
function streamCenter(z) {
return 4.63 + Math.sin(z * 0.67 + 0.5) * 0.22;
}
function terrainHeight(x, z) {
let y = 0.08 + (6 - x) * 0.015;
const ditchDistance = (x - ditchCenter(z)) / 0.35;
y -= 0.25 * Math.exp(-ditchDistance * ditchDistance);
const streamDistance = (x - streamCenter(z)) / 0.9;
y -= 0.1 * Math.exp(-streamDistance * streamDistance);
return y;
}
function makeRibbon({
center,
width,
material,
segments = 90,
zMin = -5.65,
zMax = 5.65,
yFunction
}) {
const positions = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const z = lerp(zMin, zMax, i / segments);
const x = center(z);
const left = x - width / 2;
const right = x + width / 2;
const yl = yFunction
? yFunction(left, z)
: terrainHeight(left, z) + 0.018;
const yr = yFunction
? yFunction(right, z)
: terrainHeight(right, z) + 0.018;
positions.push(left, yl, z, right, yr, z);
if (i < segments) {
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(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(text, accent, position, targetHeight = 0.43) {
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
const font = "800 35px system-ui, sans-serif";
ctx.font = font;
const textWidth = ctx.measureText(text).width;
const width = Math.ceil(textWidth + 74);
const height = 76;
canvas.width = width;
canvas.height = height;
ctx.font = font;
ctx.textBaseline = "middle";
ctx.fillStyle = "rgba(252, 253, 248, 0.95)";
roundedRect(ctx, 2, 2, width - 4, height - 4, 18);
ctx.fill();
ctx.strokeStyle = "rgba(38, 53, 44, 0.12)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(30, height / 2, 8, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#304237";
ctx.fillText(text, 50, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(
(width / height) * targetHeight,
targetHeight,
1
);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
// -------------------------------------------------------------------------
// Soil slab and sculpted terrain
// -------------------------------------------------------------------------
const slab = new THREE.Mesh(
new THREE.BoxGeometry(13.8, 0.7, 11.6),
new THREE.MeshStandardMaterial({
color: 0x5e4935,
roughness: 0.96,
metalness: 0
})
);
slab.position.y = -0.57;
slab.receiveShadow = true;
slab.castShadow = true;
scene.add(slab);
const terrainGeometry = new THREE.PlaneGeometry(
13.6,
11.3,
72,
48
);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPosition = terrainGeometry.attributes.position;
const terrainColors = [];
const fieldColor = new THREE.Color(0xa66f42);
const bufferColor = new THREE.Color(0x718d4e);
const bankColor = new THREE.Color(0x849064);
const wetColor = new THREE.Color(0x625b43);
const streamBankColor = new THREE.Color(0x707b58);
const color = new THREE.Color();
for (let i = 0; i < terrainPosition.count; i++) {
const x = terrainPosition.getX(i);
const z = terrainPosition.getZ(i);
terrainPosition.setY(i, terrainHeight(x, z));
if (x < -0.12) {
color.copy(fieldColor);
} else if (x < 1.9) {
color.copy(bufferColor);
} else if (x < 3.35) {
color.copy(bankColor);
} else {
color.copy(streamBankColor);
}
const ditchDistance = Math.abs(x - ditchCenter(z));
const ditchBlend = 1 - THREE.MathUtils.smoothstep(ditchDistance, 0.22, 0.52);
color.lerp(wetColor, ditchBlend * 0.9);
const streamDistance = Math.abs(x - streamCenter(z));
const streamBlend =
1 - THREE.MathUtils.smoothstep(streamDistance, 0.48, 0.95);
color.lerp(streamBankColor, streamBlend * 0.55);
terrainColors.push(color.r, color.g, color.b);
}
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0
})
);
terrain.receiveShadow = true;
scene.add(terrain);
// A simple vertical soil skirt closes the raised terrain around the slab.
const perimeter = [];
const halfW = 6.8;
const halfD = 5.65;
for (let i = 0; i <= 32; i++) {
perimeter.push(new THREE.Vector2(lerp(-halfW, halfW, i / 32), -halfD));
}
for (let i = 1; i <= 28; i++) {
perimeter.push(new THREE.Vector2(halfW, lerp(-halfD, halfD, i / 28)));
}
for (let i = 1; i <= 32; i++) {
perimeter.push(new THREE.Vector2(lerp(halfW, -halfW, i / 32), halfD));
}
for (let i = 1; i <= 28; i++) {
perimeter.push(new THREE.Vector2(-halfW, lerp(halfD, -halfD, i / 28)));
}
const skirtPositions = [];
const skirtIndices = [];
for (let i = 0; i < perimeter.length; i++) {
const p = perimeter[i];
skirtPositions.push(
p.x,
terrainHeight(p.x, p.y),
p.y,
p.x,
-0.22,
p.y
);
}
for (let i = 0; i < perimeter.length; i++) {
const next = (i + 1) % perimeter.length;
const a = i * 2;
const b = next * 2;
skirtIndices.push(a, a + 1, b, b, a + 1, b + 1);
}
const skirtGeometry = new THREE.BufferGeometry();
skirtGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(skirtPositions, 3)
);
skirtGeometry.setIndex(skirtIndices);
skirtGeometry.computeVertexNormals();
const skirt = new THREE.Mesh(
skirtGeometry,
new THREE.MeshStandardMaterial({
color: 0x665039,
roughness: 1,
side: THREE.DoubleSide
})
);
skirt.receiveShadow = true;
scene.add(skirt);
// -------------------------------------------------------------------------
// Water, ditch, field rows, and planted buffer
// -------------------------------------------------------------------------
makeRibbon({
center: ditchCenter,
width: 0.54,
material: new THREE.MeshStandardMaterial({
color: 0x596858,
roughness: 0.66,
metalness: 0.02
})
});
makeRibbon({
center: streamCenter,
width: 1.62,
material: new THREE.MeshStandardMaterial({
color: 0x4f9eae,
roughness: 0.42,
metalness: 0.03
}),
yFunction: () => 0.043
});
// Pale, solid stream strokes suggest the direction of the water.
const streamStrokeGeometry = new THREE.BoxGeometry(0.055, 0.018, 0.5);
const streamStrokeMaterial = new THREE.MeshStandardMaterial({
color: 0xaed8d9,
roughness: 0.5
});
for (let i = 0; i < 11; i++) {
const z = -5 + i * 0.9;
const stroke = new THREE.Mesh(streamStrokeGeometry, streamStrokeMaterial);
stroke.position.set(
streamCenter(z) + (random() - 0.5) * 0.55,
0.061,
z
);
stroke.rotation.y = (random() - 0.5) * 0.35;
scene.add(stroke);
}
// Crop furrows.
const furrowGeometry = new THREE.BoxGeometry(5.45, 0.065, 0.36);
const furrowMaterials = [
new THREE.MeshStandardMaterial({ color: 0x8e5d37, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x9a673d, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x875b38, roughness: 1 })
];
const rowZ = [-4.35, -2.9, -1.45, 0, 1.45, 2.9, 4.35];
rowZ.forEach((z, index) => {
const furrow = new THREE.Mesh(
furrowGeometry,
furrowMaterials[index % furrowMaterials.length]
);
furrow.position.set(-3.05, terrainHeight(-3.05, z) + 0.025, z);
furrow.rotation.z = 0.015;
furrow.receiveShadow = true;
furrow.castShadow = true;
scene.add(furrow);
});
// Crop stalks and low-poly crop heads, instanced for efficiency.
const cropCount = rowZ.length * 9;
const cropStalkGeometry = new THREE.CylinderGeometry(0.027, 0.035, 0.38, 6);
const cropHeadGeometry = new THREE.ConeGeometry(0.16, 0.42, 5);
const cropStalkMaterial = new THREE.MeshStandardMaterial({
color: 0x80633c,
roughness: 1
});
const cropHeadMaterial = new THREE.MeshStandardMaterial({
color: 0x638445,
roughness: 0.95
});
const cropStalks = new THREE.InstancedMesh(
cropStalkGeometry,
cropStalkMaterial,
cropCount
);
const cropHeads = new THREE.InstancedMesh(
cropHeadGeometry,
cropHeadMaterial,
cropCount
);
const dummy = new THREE.Object3D();
let cropIndex = 0;
rowZ.forEach((z) => {
for (let j = 0; j < 9; j++) {
const x = -5.45 + j * 0.61;
const y = terrainHeight(x, z);
dummy.position.set(x, y + 0.2, z);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.set(1, 0.9 + random() * 0.2, 1);
dummy.updateMatrix();
cropStalks.setMatrixAt(cropIndex, dummy.matrix);
dummy.position.set(x, y + 0.46, z);
dummy.rotation.set((random() - 0.5) * 0.08, random() * Math.PI, 0);
dummy.scale.set(0.86 + random() * 0.22, 0.9 + random() * 0.2, 0.86);
dummy.updateMatrix();
cropHeads.setMatrixAt(cropIndex, dummy.matrix);
cropIndex++;
}
});
cropStalks.castShadow = true;
cropHeads.castShadow = true;
cropStalks.receiveShadow = true;
cropHeads.receiveShadow = true;
scene.add(cropStalks, cropHeads);
// Dense, orderly rows of planted buffer vegetation.
const bushGeometry = new THREE.IcosahedronGeometry(0.29, 1);
const bushMaterial = new THREE.MeshStandardMaterial({
color: 0x6e914d,
roughness: 0.95,
vertexColors: false
});
const bushCount = 22;
const bushes = new THREE.InstancedMesh(
bushGeometry,
bushMaterial,
bushCount
);
const bushPalette = [
new THREE.Color(0x678848),
new THREE.Color(0x769a52),
new THREE.Color(0x587b42),
new THREE.Color(0x86a65c)
];
let bushIndex = 0;
for (let row = 0; row < 2; row++) {
const x = row === 0 ? 0.42 : 1.38;
for (let i = 0; i < 11; i++) {
const z = -4.75 + i * 0.94 + (random() - 0.5) * 0.1;
const y = terrainHeight(x, z);
dummy.position.set(x, y + 0.27, z);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.set(
0.86 + random() * 0.28,
1.02 + random() * 0.35,
0.86 + random() * 0.28
);
dummy.updateMatrix();
bushes.setMatrixAt(bushIndex, dummy.matrix);
bushes.setColorAt(
bushIndex,
bushPalette[Math.floor(random() * bushPalette.length)]
);
bushIndex++;
}
}
bushes.castShadow = true;
bushes.receiveShadow = true;
scene.add(bushes);
// -------------------------------------------------------------------------
// Capture forebay
// -------------------------------------------------------------------------
const captureZ = 3.25;
const captureX = ditchCenter(captureZ);
const captureY = terrainHeight(captureX, captureZ);
const captureBed = new THREE.Mesh(
new THREE.CircleGeometry(0.57, 48),
new THREE.MeshStandardMaterial({
color: 0x856342,
roughness: 0.95,
transparent: true,
opacity: 0.88
})
);
captureBed.rotation.x = -Math.PI / 2;
captureBed.position.set(captureX, captureY + 0.028, captureZ);
captureBed.scale.set(1, 1.3, 1);
captureBed.receiveShadow = true;
scene.add(captureBed);
const captureRing = new THREE.Mesh(
new THREE.TorusGeometry(0.59, 0.045, 8, 48),
new THREE.MeshStandardMaterial({
color: 0xe09a4c,
roughness: 0.62,
emissive: 0x7b3d10,
emissiveIntensity: 0.08
})
);
captureRing.rotation.x = Math.PI / 2;
captureRing.position.set(captureX, captureY + 0.075, captureZ);
captureRing.scale.set(1, 1.3, 1);
captureRing.castShadow = true;
scene.add(captureRing);
// A small solid baffle directs sediment into the forebay.
const baffle = new THREE.Mesh(
new THREE.BoxGeometry(0.75, 0.24, 0.09),
new THREE.MeshStandardMaterial({
color: 0x795538,
roughness: 0.9
})
);
baffle.position.set(
ditchCenter(2.58),
terrainHeight(ditchCenter(2.58), 2.58) + 0.1,
2.58
);
baffle.castShadow = true;
scene.add(baffle);
// Existing sediment deposits in the designated capture area.
const depositGeometry = new THREE.IcosahedronGeometry(0.08, 1);
const depositMaterials = [
new THREE.MeshStandardMaterial({ color: 0xb96c3e, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x9d5834, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xc5844e, roughness: 1 })
];
for (let i = 0; i < 24; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * 0.43;
const x = captureX + Math.cos(angle) * radius;
const z = captureZ + Math.sin(angle) * radius * 1.18;
const deposit = new THREE.Mesh(
depositGeometry,
depositMaterials[i % depositMaterials.length]
);
deposit.position.set(x, terrainHeight(x, z) + 0.065, z);
deposit.scale.set(
0.7 + random() * 0.65,
0.55 + random() * 0.4,
0.7 + random() * 0.65
);
deposit.rotation.set(random(), random(), random());
deposit.castShadow = true;
scene.add(deposit);
}
// -------------------------------------------------------------------------
// Animated runoff arrows
// -------------------------------------------------------------------------
const runoffArrows = [];
function createRunoffArrow(z, phaseOffset) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0x46aab5,
emissive: 0x155763,
emissiveIntensity: 0.18,
roughness: 0.34,
metalness: 0.05,
transparent: true,
opacity: 0.86
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.5, 8),
material
);
shaft.rotation.z = -Math.PI / 2;
shaft.position.x = -0.12;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.29, 10),
material
);
head.rotation.z = -Math.PI / 2;
head.position.x = 0.275;
group.add(head);
group.position.set(-0.8, 0.76, z);
group.userData = {
phaseOffset,
material,
z
};
scene.add(group);
runoffArrows.push(group);
}
createRunoffArrow(-2.75, 0.0);
createRunoffArrow(-0.2, 0.33);
createRunoffArrow(1.72, 0.66);
// -------------------------------------------------------------------------
// Moving sediment markers and settling behavior
// -------------------------------------------------------------------------
const sedimentMarkers = [];
const sedimentGeometry = new THREE.IcosahedronGeometry(0.085, 1);
const sedimentPalette = [0xb96a39, 0xc47b43, 0xa95b31, 0xd18b51];
for (let i = 0; i < 22; i++) {
const material = new THREE.MeshStandardMaterial({
color: sedimentPalette[i % sedimentPalette.length],
roughness: 0.96,
transparent: true,
opacity: 1
});
const marker = new THREE.Mesh(sedimentGeometry, material);
marker.castShadow = true;
const startX = -1.05 + random() * 0.28;
const startZ = -2.8 + random() * 4.6;
const targetX = captureX + (random() - 0.5) * 0.55;
const targetZ = captureZ + (random() - 0.5) * 0.62;
sedimentMarkers.push({
mesh: marker,
material,
startX,
startZ,
targetX,
targetZ,
phase: i / sedimentMarkers.length,
stack: random() * 0.045
});
scene.add(marker);
}
// -------------------------------------------------------------------------
// In-world labels
// -------------------------------------------------------------------------
makeLabel(
"PLANTED FIELD",
"#ad7040",
new THREE.Vector3(-3.2, 1.12, -5.12),
0.42
);
makeLabel(
"PLANTED BUFFER",
"#71934e",
new THREE.Vector3(0.78, 1.04, -5.12),
0.42
);
makeLabel(
"SHALLOW DITCH",
"#637765",
new THREE.Vector3(2.38, 0.98, -5.12),
0.42
);
makeLabel(
"STREAM",
"#4f9eae",
new THREE.Vector3(4.8, 0.92, -5.12),
0.42
);
makeLabel(
"SEDIMENT CAPTURE",
"#e09a4c",
new THREE.Vector3(captureX, 0.78, captureZ + 0.82),
0.44
);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, wheel zoom, keyboard, and touch pinch
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, 0.1, 0);
const initialCamera = {
theta: 0.72,
phi: 0.9,
radius: 17.4
};
let theta = initialCamera.theta;
let phi = initialCamera.phi;
let radius = initialCamera.radius;
function applyCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
theta = initialCamera.theta;
phi = initialCamera.phi;
radius = initialCamera.radius;
applyCamera();
}
applyCamera();
const canvas = renderer.domElement;
const pointers = new Map();
let lastPointer = { x: 0, y: 0 };
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const values = [...pointers.values()];
const nextDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0 && nextDistance > 0) {
radius = clamp(radius * (pinchDistance / nextDistance), 10, 27);
applyCamera();
}
pinchDistance = nextDistance;
} else if (pointers.size === 1) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
theta -= dx * 0.005;
phi = clamp(phi - dy * 0.004, 0.35, 1.35);
lastPointer = { x: event.clientX, y: event.clientY };
applyCamera();
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointer = { x: remaining.x, y: remaining.y };
} else {
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = clamp(radius * Math.exp(event.deltaY * 0.001), 10, 27);
applyCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") theta -= 0.08;
if (event.key === "ArrowRight") theta += 0.08;
if (event.key === "ArrowUp") phi = clamp(phi - 0.06, 0.35, 1.35);
if (event.key === "ArrowDown") phi = clamp(phi + 0.06, 0.35, 1.35);
if (event.key === "+" || event.key === "=") radius = clamp(radius - 0.7, 10, 27);
if (event.key === "-") radius = clamp(radius + 0.7, 10, 27);
applyCamera();
});
document.getElementById("reset").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
runoffArrows.forEach((arrow, index) => {
const phase = (time * 0.28 + arrow.userData.phaseOffset) % 1;
arrow.position.x = lerp(-0.95, 2.18, phase);
arrow.position.z = arrow.userData.z;
arrow.position.y = 0.75 + Math.sin(phase * Math.PI * 2) * 0.025;
arrow.userData.material.opacity = 0.28 + Math.sin(phase * Math.PI) * 0.64;
});
sedimentMarkers.forEach((particle) => {
const phase = (time * 0.105 + particle.phase) % 1;
const travel = phase / 0.72;
let x;
let z;
let y;
if (phase < 0.72) {
const eased = travel * travel * (3 - 2 * travel);
x = lerp(particle.startX, particle.targetX, eased);
z = lerp(particle.startZ, particle.targetZ, eased);
z += Math.sin(eased * Math.PI) * 0.12;
y =
terrainHeight(x, z) +
0.12 +
Math.sin(eased * Math.PI) * 0.12;
} else {
x = particle.targetX;
z = particle.targetZ;
y = terrainHeight(x, z) + 0.065 + particle.stack;
}
particle.mesh.position.set(x, y, z);
particle.mesh.rotation.x += 0.012;
particle.mesh.rotation.y += 0.018;
const fadeIn = THREE.MathUtils.smoothstep(phase, 0, 0.06);
const fadeOut = 1 - THREE.MathUtils.smoothstep(phase, 0.95, 1);
particle.material.opacity = Math.min(fadeIn, fadeOut);
});
captureRing.rotation.z = Math.sin(time * 0.55) * 0.018;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```