Prompt specification
Build or customize the Three.js 3D scene "Herd moving toward a seasonal water patch" 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: Herd moving toward a seasonal water patch
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/herd-moving-toward-a-seasonal-water-patch-x3118
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing seasonal resources and herd routes in the Serengeti. Create a compact vignette with a small group of one referenced herbivore species. Animate coordinated movement toward visible water without claiming a precise real migration rule. A 3D cutaway view.
Working Three.js Starter (herd-moving-toward-a-seasonal-water-patch-x3118):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Serengeti: Seasonal Forage & Water</title>
<style>
:root {
color-scheme: dark;
--ink: #f4efe2;
--muted: #b9c1b8;
--panel: rgba(18, 29, 29, 0.88);
--line: rgba(220, 230, 215, 0.16);
--gold: #e7b85c;
--green: #83b982;
--water: #65bfd0;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #10191a;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 38%, rgba(5, 10, 11, 0.34) 100%),
linear-gradient(180deg, rgba(6, 12, 13, 0.12), transparent 22%, transparent 76%, rgba(5, 10, 11, 0.22));
z-index: 2;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
border-radius: 18px;
padding: 20px 21px 18px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--gold);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 340px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3vw, 40px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.season-label {
margin: 0 0 9px;
color: #dce4d9;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.seasons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
button {
color: var(--ink);
font: inherit;
}
.season-button {
min-height: 44px;
padding: 8px 7px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
background: rgba(255, 255, 255, 0.04);
color: #c9d0c7;
cursor: pointer;
font-size: 11px;
line-height: 1.15;
transition: 160ms ease;
}
.season-button:hover,
.season-button:focus-visible {
border-color: rgba(231, 184, 92, 0.7);
background: rgba(231, 184, 92, 0.08);
outline: none;
}
.season-button.active {
border-color: var(--gold);
background: rgba(231, 184, 92, 0.14);
color: #fff1cd;
}
.season-note {
min-height: 42px;
margin: 11px 0 0;
color: #aeb9ae;
font-size: 11px;
line-height: 1.45;
}
#species {
top: 22px;
right: 22px;
width: 286px;
border-radius: 18px;
padding: 17px 18px;
}
.species-heading {
display: flex;
align-items: center;
gap: 12px;
}
.species-mark {
display: grid;
width: 42px;
height: 42px;
flex: 0 0 auto;
place-items: center;
border: 1px solid rgba(231, 184, 92, 0.4);
border-radius: 50%;
color: var(--gold);
font-size: 20px;
}
.species-heading strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
font-weight: 500;
}
.species-heading span {
display: block;
margin-top: 3px;
color: #9eaaa0;
font-size: 11px;
font-style: italic;
}
.species-copy {
margin: 13px 0 0;
color: #b6c0b7;
font-size: 12px;
line-height: 1.52;
}
.disclaimer {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #a7b2aa;
font-size: 10px;
line-height: 1.5;
}
#bottom {
left: 50%;
bottom: 20px;
display: flex;
align-items: center;
gap: 18px;
max-width: calc(100vw - 40px);
padding: 11px 13px;
border-radius: 14px;
transform: translateX(-50%);
}
.legend {
display: flex;
align-items: center;
gap: 15px;
white-space: nowrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #cbd2c9;
font-size: 11px;
}
.swatch {
width: 19px;
height: 4px;
border-radius: 9px;
}
.swatch.route { background: var(--gold); }
.swatch.water { background: var(--water); }
.swatch.forage { background: var(--green); }
.swatch.strata { height: 10px; background: #9b6944; }
.divider {
width: 1px;
height: 26px;
background: var(--line);
}
.hint {
color: #9eaaa0;
font-size: 10px;
white-space: nowrap;
}
#replay {
min-height: 32px;
padding: 6px 12px;
border: 1px solid rgba(231, 184, 92, 0.5);
border-radius: 9px;
background: rgba(231, 184, 92, 0.09);
color: #f2dba7;
cursor: pointer;
font-size: 11px;
white-space: nowrap;
}
#replay:hover,
#replay:focus-visible {
background: rgba(231, 184, 92, 0.18);
outline: none;
}
#compass {
position: fixed;
right: 25px;
bottom: 25px;
z-index: 5;
width: 58px;
height: 58px;
border: 1px solid var(--line);
border-radius: 50%;
background: rgba(18, 29, 29, 0.7);
color: #d9dfd5;
text-align: center;
pointer-events: none;
}
#compass b {
display: block;
padding-top: 5px;
font-size: 10px;
letter-spacing: 0.08em;
}
#compass span {
display: block;
margin-top: 2px;
font-size: 18px;
line-height: 1;
}
@media (max-width: 760px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px;
}
h1 { font-size: 28px; }
.subtitle { margin-bottom: 12px; }
#species { display: none; }
#bottom {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
gap: 10px;
padding: 9px;
}
.legend { gap: 8px; }
.legend-item { font-size: 9px; }
.hint, .divider { display: none; }
#compass { display: none; }
}
</style>
</head>
<body>
<div id="intro" class="panel">
<p class="eyebrow">Field vignette · Serengeti</p>
<h1>Seasonal forage,<br />shared water</h1>
<p class="subtitle">
A compact cutaway of changing grass cover, surface water, and an illustrative
route used by a small blue wildebeest group.
</p>
<div class="season-label">Season lens</div>
<div class="seasons" role="group" aria-label="Choose a seasonal landscape">
<button class="season-button active" data-season="dry">Dry-season<br />grass</button>
<button class="season-button" data-season="short">Short-rain<br />flush</button>
<button class="season-button" data-season="green">Green-season<br />cover</button>
</div>
<p id="season-note" class="season-note">
Sparse, tawny grass and conspicuous open water in this schematic landscape.
</p>
</div>
<aside id="species" class="panel">
<div class="species-heading">
<div class="species-mark">↗</div>
<div>
<strong>Blue wildebeest</strong>
<span>Connochaetes taurinus</span>
</div>
</div>
<p class="species-copy">
This vignette uses one herbivore species. The animals move as a coordinated
group from a seasonal grass patch toward the visible water edge.
</p>
<div class="disclaimer">
<strong>Interpretive model:</strong> rainfall, forage quality, and movement
vary by place and year. The route is not a precise prediction of a fixed
real-world migration rule.
</div>
</aside>
<div id="bottom" class="panel">
<div class="legend" aria-label="Scene legend">
<div class="legend-item"><span class="swatch route"></span>Illustrative route</div>
<div class="legend-item"><span class="swatch water"></span>Surface water</div>
<div class="legend-item"><span class="swatch forage"></span>Forage patch</div>
<div class="legend-item"><span class="swatch strata"></span>Cutaway strata</div>
</div>
<div class="divider"></div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<button id="replay" type="button">Replay approach</button>
</div>
<div id="compass" aria-hidden="true"><b>N</b><span>↑</span></div>
<div class="vignette"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x10191a);
scene.fog = new THREE.Fog(0x10191a, 58, 95);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xcfe3dd, 0x493728, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe4b2, 3.0);
sun.position.set(-17, 29, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.0007;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x78aeb7, 0.8);
rim.position.set(18, 9, -24);
scene.add(rim);
const diorama = new THREE.Group();
scene.add(diorama);
const WIDTH = 36;
const DEPTH = 24;
const HALF_W = WIDTH / 2;
const HALF_D = DEPTH / 2;
const BOTTOM = -5.2;
const POND = { x: -10.2, z: 3.4, rx: 3.15, rz: 2.15 };
// Deterministic randomness keeps the composition stable across reloads.
let randomSeed = 82741;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function clamp(v, a, b) {
return Math.max(a, Math.min(b, v));
}
function smoothstep(a, b, x) {
const t = clamp((x - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function pondDistance(x, z) {
const dx = (x - POND.x) / POND.rx;
const dz = (z - POND.z) / POND.rz;
return Math.sqrt(dx * dx + dz * dz);
}
function rawHeight(x, z) {
return (
0.46 +
Math.sin(x * 0.22) * 0.32 +
Math.cos(z * 0.31) * 0.25 +
Math.sin((x + z) * 0.43) * 0.12 +
Math.cos((x - z) * 0.17) * 0.10
);
}
function terrainHeight(x, z) {
const h = rawHeight(x, z);
const d = pondDistance(x, z);
const basin = 1 - smoothstep(0.52, 1.48, d);
return THREE.MathUtils.lerp(h, -0.17, basin);
}
function groundY(x, z, offset = 0) {
return terrainHeight(x, z) + offset;
}
// -------------------------------------------------------------------------
// Terrain top
// -------------------------------------------------------------------------
const terrainGeometry = new THREE.PlaneGeometry(
WIDTH,
DEPTH,
64,
44
);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPosition = terrainGeometry.attributes.position;
for (let i = 0; i < terrainPosition.count; i++) {
const x = terrainPosition.getX(i);
const z = terrainPosition.getZ(i);
terrainPosition.setY(i, terrainHeight(x, z));
}
terrainGeometry.setAttribute(
"color",
new THREE.BufferAttribute(new Float32Array(terrainPosition.count * 3), 3)
);
terrainGeometry.computeVertexNormals();
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.94,
metalness: 0.0
});
const terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
terrain.receiveShadow = true;
diorama.add(terrain);
// -------------------------------------------------------------------------
// Cutaway walls: bedrock, subsoil, pale stratum, topsoil
// -------------------------------------------------------------------------
function createWall(axis, constant, start, end, segments, lower, upper) {
const positions = [];
const indices = [];
for (let i = 0; i < segments; i++) {
const a0 = THREE.MathUtils.lerp(start, end, i / segments);
const a1 = THREE.MathUtils.lerp(start, end, (i + 1) / segments);
const base = positions.length / 3;
const top0 = typeof upper === "function" ? upper(a0) : upper;
const top1 = typeof upper === "function" ? upper(a1) : upper;
let p0, p1, p2, p3;
if (axis === "front") {
p0 = [a0, lower, constant];
p1 = [a1, lower, constant];
p2 = [a1, top1, constant];
p3 = [a0, top0, constant];
} else {
p0 = [constant, lower, a0];
p1 = [constant, lower, a1];
p2 = [constant, top1, a1];
p3 = [constant, top0, a0];
}
positions.push(...p0, ...p1, ...p2, ...p3);
indices.push(
base, base + 1, base + 2,
base, base + 2, base + 3
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const strata = [
{
bottom: BOTTOM,
top: -3.55,
color: 0x51443c,
roughness: 1
},
{
bottom: -3.55,
top: -1.9,
color: 0x7f5d42,
roughness: 1
},
{
bottom: -1.9,
top: -0.52,
color: 0xa98258,
roughness: 1
},
{
bottom: -0.52,
top: (v) => terrainHeight(v, HALF_D),
color: 0x6b6842,
roughness: 1
}
];
for (const layer of strata) {
const material = new THREE.MeshStandardMaterial({
color: layer.color,
roughness: layer.roughness,
metalness: 0,
side: THREE.DoubleSide
});
const front = new THREE.Mesh(
createWall("front", HALF_D, -HALF_W, HALF_W, 64, layer.bottom, layer.top),
material
);
const right = new THREE.Mesh(
createWall("right", HALF_W, -HALF_D, HALF_D, 44, layer.bottom, layer.top),
material
);
front.receiveShadow = true;
right.receiveShadow = true;
diorama.add(front, right);
}
const bottomSlab = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH, 0.28, DEPTH),
new THREE.MeshStandardMaterial({
color: 0x3b342f,
roughness: 0.9
})
);
bottomSlab.position.y = BOTTOM - 0.14;
bottomSlab.receiveShadow = true;
diorama.add(bottomSlab);
// Schematic blue aquifer visible in the exposed front section.
const aquifer = new THREE.Mesh(
new THREE.PlaneGeometry(21, 0.82),
new THREE.MeshBasicMaterial({
color: 0x4da9bd,
transparent: true,
opacity: 0.38,
depthWrite: false,
side: THREE.DoubleSide
})
);
aquifer.position.set(-3.5, -2.63, HALF_D + 0.025);
diorama.add(aquifer);
const aquiferEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x78d5df,
transparent: true,
opacity: 0.8
});
for (const y of [-3.04, -2.22]) {
const lineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-14, y, HALF_D + 0.045),
new THREE.Vector3(7, y, HALF_D + 0.045)
]);
diorama.add(new THREE.Line(lineGeometry, aquiferEdgeMaterial));
}
// Fine seep lines provide a visual connection to the cut face.
const seepMaterial = new THREE.LineBasicMaterial({
color: 0x75cbd2,
transparent: true,
opacity: 0.30
});
for (let i = 0; i < 15; i++) {
const x = -12.8 + i * 1.35;
const top = groundY(x, HALF_D, 0.03);
const points = [
new THREE.Vector3(x, top, HALF_D + 0.04),
new THREE.Vector3(x + 0.12, top - 0.55, HALF_D + 0.04),
new THREE.Vector3(x - 0.08, -1.8, HALF_D + 0.04),
new THREE.Vector3(x + 0.04, -2.52, HALF_D + 0.04)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
diorama.add(new THREE.Line(geometry, seepMaterial));
}
// -------------------------------------------------------------------------
// Surface water and shoreline
// -------------------------------------------------------------------------
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x3f9eb1,
emissive: 0x0c3640,
emissiveIntensity: 0.25,
roughness: 0.22,
metalness: 0.05,
transparent: true,
opacity: 0.88,
clearcoat: 0.8,
clearcoatRoughness: 0.18,
side: THREE.DoubleSide
});
const pond = new THREE.Mesh(
new THREE.CircleGeometry(1, 72),
waterMaterial
);
pond.rotation.x = -Math.PI / 2;
pond.scale.set(POND.rx * 0.97, POND.rz * 0.97, 1);
pond.position.set(POND.x, -0.075, POND.z);
pond.receiveShadow = true;
diorama.add(pond);
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xb9edf0,
transparent: true,
opacity: 0.22,
side: THREE.DoubleSide,
depthWrite: false
});
const ripples = [];
for (let i = 0; i < 3; i++) {
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.44 + i * 0.19, 0.455 + i * 0.19, 64),
rippleMaterial.clone()
);
ripple.rotation.x = -Math.PI / 2;
ripple.scale.set(POND.rx * 0.92, POND.rz * 0.92, 1);
ripple.position.set(POND.x, -0.065 + i * 0.002, POND.z);
diorama.add(ripple);
ripples.push(ripple);
}
// Shoreline stones.
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x77776b,
roughness: 0.98
});
for (let i = 0; i < 25; i++) {
const angle = (i / 25) * Math.PI * 2 + random() * 0.12;
const radius = 1 + random() * 0.13;
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.15 + random() * 0.16, 0),
stoneMaterial
);
stone.position.set(
POND.x + Math.cos(angle) * POND.rx * radius,
groundY(
POND.x + Math.cos(angle) * POND.rx * radius,
POND.z + Math.sin(angle) * POND.rz * radius,
0.08
),
POND.z + Math.sin(angle) * POND.rz * radius
);
stone.scale.y = 0.7;
stone.rotation.set(random(), random() * Math.PI, random());
stone.castShadow = true;
stone.receiveShadow = true;
diorama.add(stone);
}
// Reeds around the water.
const reedMaterial = new THREE.MeshStandardMaterial({
color: 0x627849,
roughness: 0.9
});
for (let i = 0; i < 34; i++) {
const angle = random() * Math.PI * 2;
const radius = 0.93 + random() * 0.16;
const x = POND.x + Math.cos(angle) * POND.rx * radius;
const z = POND.z + Math.sin(angle) * POND.rz * radius;
const reed = new THREE.Mesh(
new THREE.ConeGeometry(0.025, 0.38 + random() * 0.28, 4),
reedMaterial
);
reed.position.set(x, groundY(x, z, 0.15), z);
reed.rotation.z = (random() - 0.5) * 0.3;
diorama.add(reed);
}
// -------------------------------------------------------------------------
// Vegetation and seasonal forage patches
// -------------------------------------------------------------------------
const resourcePatches = [];
function createForagePatch(x, z, rx, rz, seedPhase) {
const geometry = new THREE.CircleGeometry(1, 40);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const px = position.getX(i);
const py = position.getY(i);
const angle = Math.atan2(py, px);
const wobble =
1 +
Math.sin(angle * 3 + seedPhase) * 0.10 +
Math.sin(angle * 7 - seedPhase) * 0.055;
position.setXY(i, px * wobble, py * wobble);
}
geometry.computeVertexNormals();
const material = new THREE.MeshBasicMaterial({
color: 0x78935a,
transparent: true,
opacity: 0.38,
depthWrite: false,
side: THREE.DoubleSide
});
const patch = new THREE.Mesh(geometry, material);
patch.rotation.x = -Math.PI / 2;
patch.scale.set(rx, rz, 1);
patch.position.set(x, groundY(x, z, 0.026), z);
diorama.add(patch);
resourcePatches.push(patch);
}
createForagePatch(-10.3, 3.4, 4.4, 3.1, 0.4);
createForagePatch(-3.7, -5.3, 4.0, 2.7, 1.3);
createForagePatch(7.4, -6.4, 4.5, 2.8, 2.2);
createForagePatch(10.0, 6.6, 3.3, 2.2, 3.1);
createForagePatch(3.3, -1.8, 2.8, 1.8, 4.0);
// Instanced grass blades.
const grassCount = 260;
const grassGeometry = new THREE.ConeGeometry(0.045, 0.55, 3);
grassGeometry.translate(0, 0.275, 0);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x7f814a,
roughness: 0.95
});
const grass = new THREE.InstancedMesh(
grassGeometry,
grassMaterial,
grassCount
);
grass.castShadow = true;
grass.receiveShadow = true;
const dummy = new THREE.Object3D();
const grassColor = new THREE.Color();
for (let i = 0; i < grassCount; i++) {
let x;
let z;
do {
x = (random() - 0.5) * (WIDTH - 1.3);
z = (random() - 0.5) * (DEPTH - 1.3);
} while (pondDistance(x, z) < 1.05);
const scale = 0.45 + random() * 0.85;
dummy.position.set(x, groundY(x, z, 0.01), z);
dummy.rotation.set(
(random() - 0.5) * 0.12,
random() * Math.PI * 2,
(random() - 0.5) * 0.15
);
dummy.scale.set(scale, scale, scale);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
grassColor.setHSL(
0.15 + random() * 0.04,
0.23 + random() * 0.18,
0.35 + random() * 0.18
);
grass.setColorAt(i, grassColor);
}
grass.instanceMatrix.needsUpdate = true;
if (grass.instanceColor) grass.instanceColor.needsUpdate = true;
diorama.add(grass);
// Acacia-like trees.
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x5d4935,
roughness: 1
});
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.22, 2.6, 7),
trunkMaterial
);
trunk.position.y = 1.3;
trunk.castShadow = true;
tree.add(trunk);
const branchMaterial = new THREE.MeshStandardMaterial({
color: 0x65503a,
roughness: 1
});
for (let i = 0; i < 3; i++) {
const branch = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.09, 1.2, 6),
branchMaterial
);
branch.position.set(
(random() - 0.5) * 0.8,
2.0 + random() * 0.25,
(random() - 0.5) * 0.7
);
branch.rotation.z = (random() - 0.5) * 0.8;
branch.rotation.x = (random() - 0.5) * 0.65;
tree.add(branch);
}
const canopyMaterial = new THREE.MeshStandardMaterial({
color: 0x56633d,
roughness: 1
});
for (let i = 0; i < 4; i++) {
const canopy = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.85 + random() * 0.25, 1),
canopyMaterial
);
canopy.scale.set(1.25, 0.40, 0.86);
canopy.position.set(
(i - 1.5) * 0.55,
2.72 + (i % 2) * 0.14,
(random() - 0.5) * 0.45
);
canopy.castShadow = true;
tree.add(canopy);
}
tree.position.set(x, groundY(x, z), z);
tree.scale.setScalar(scale);
tree.rotation.y = random() * Math.PI;
diorama.add(tree);
}
addTree(-15.2, -7.3, 0.90);
addTree(-13.5, -8.3, 0.67);
addTree(12.7, -8.4, 0.82);
addTree(15.0, 8.2, 0.72);
addTree(-14.0, 8.7, 0.61);
// Scattered stones.
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x77766a,
roughness: 1
});
for (let i = 0; i < 22; i++) {
const x = (random() - 0.5) * 32;
const z = (random() - 0.5) * 20;
if (pondDistance(x, z) < 1.2) continue;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.12 + random() * 0.30, 0),
rockMaterial
);
rock.position.set(x, groundY(x, z, 0.06), z);
rock.scale.y = 0.55 + random() * 0.35;
rock.rotation.set(random(), random() * Math.PI, random());
rock.castShadow = true;
diorama.add(rock);
}
// -------------------------------------------------------------------------
// Illustrative route network
// -------------------------------------------------------------------------
function routePoint(x, z, offset = 0.11) {
return new THREE.Vector3(x, groundY(x, z, offset), z);
}
const mainRoute = new THREE.CatmullRomCurve3([
routePoint(12.0, 7.0),
routePoint(9.2, 5.8),
routePoint(5.7, 3.4),
routePoint(2.1, 0.3),
routePoint(-1.8, -0.8),
routePoint(-5.4, 1.2),
routePoint(-7.7, 3.25)
]);
const secondaryRoute = new THREE.CatmullRomCurve3([
routePoint(11.6, -6.0),
routePoint(8.2, -5.2),
routePoint(4.1, -4.1),
routePoint(0.4, -2.3),
routePoint(-3.8, -0.5),
routePoint(-7.7, 3.25)
]);
const mainRouteMaterial = new THREE.LineDashedMaterial({
color: 0xe7b85c,
dashSize: 0.58,
gapSize: 0.34,
linewidth: 1,
transparent: true,
opacity: 0.95
});
const secondaryRouteMaterial = new THREE.LineDashedMaterial({
color: 0xc8b47c,
dashSize: 0.28,
gapSize: 0.44,
transparent: true,
opacity: 0.34
});
const mainRouteLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(mainRoute.getPoints(180)),
mainRouteMaterial
);
mainRouteLine.computeLineDistances();
const secondaryRouteLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(secondaryRoute.getPoints(150)),
secondaryRouteMaterial
);
secondaryRouteLine.computeLineDistances();
diorama.add(mainRouteLine, secondaryRouteLine);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xf0bd5e,
emissive: 0x6a3d0e,
emissiveIntensity: 0.25,
roughness: 0.75
});
const up = new THREE.Vector3(0, 1, 0);
for (const t of [0.14, 0.31, 0.49, 0.67, 0.84]) {
const point = mainRoute.getPointAt(t);
const tangent = mainRoute.getTangentAt(t).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.16, 0.45, 7),
arrowMaterial
);
arrow.position.copy(point).add(new THREE.Vector3(0, 0.18, 0));
arrow.quaternion.setFromUnitVectors(up, tangent);
arrow.castShadow = true;
diorama.add(arrow);
}
// A soft start ring identifies the initial seasonal grass area.
const startRing = new THREE.Mesh(
new THREE.RingGeometry(1.25, 1.31, 48),
new THREE.MeshBasicMaterial({
color: 0xe7b85c,
transparent: true,
opacity: 0.5,
side: THREE.DoubleSide
})
);
startRing.rotation.x = -Math.PI / 2;
startRing.position.set(12.0, groundY(12, 7, 0.04), 7.0);
diorama.add(startRing);
// -------------------------------------------------------------------------
// Scene labels rendered as camera-facing sprites
// -------------------------------------------------------------------------
function makeLabel(text, color = "#f1ead8", background = "rgba(18,29,29,.82)") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 12, 632, 104, 22);
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,.18)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "600 29px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 320, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(5.8, 1.16, 1);
return sprite;
}
const waterLabel = makeLabel("VISIBLE WATER", "#bdeef1");
waterLabel.position.set(POND.x, 1.65, POND.z);
waterLabel.scale.set(4.3, 0.86, 1);
diorama.add(waterLabel);
const grassLabel = makeLabel("SEASONAL GRASS", "#e8d69e");
grassLabel.position.set(-3.8, 1.35, -5.2);
grassLabel.scale.set(4.7, 0.94, 1);
diorama.add(grassLabel);
const routeLabel = makeLabel("ILLUSTRATIVE PATH", "#f1c976");
routeLabel.position.set(4.1, 1.35, 1.0);
routeLabel.scale.set(4.9, 0.98, 1);
diorama.add(routeLabel);
const aquiferLabel = makeLabel("WATER-BEARING STRATUM · SCHEMATIC", "#9edce1");
aquiferLabel.position.set(2.0, -2.55, HALF_D + 0.45);
aquiferLabel.scale.set(7.4, 1.48, 1);
diorama.add(aquiferLabel);
// -------------------------------------------------------------------------
// Blue wildebeest: six stylized individuals, all facing local +Z
// -------------------------------------------------------------------------
const hideMaterial = new THREE.MeshStandardMaterial({
color: 0x51565a,
roughness: 0.92
});
const hideLightMaterial = new THREE.MeshStandardMaterial({
color: 0x73736f,
roughness: 0.95
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x252827,
roughness: 0.9
});
const hornMaterial = new THREE.MeshStandardMaterial({
color: 0x302c29,
roughness: 0.72
});
function createWildebeest() {
const animal = new THREE.Group();
const legPivots = [];
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 16, 12),
hideMaterial
);
body.scale.set(0.82, 0.78, 1.42);
body.position.y = 1.05;
body.castShadow = true;
body.receiveShadow = true;
animal.add(body);
const shoulder = new THREE.Mesh(
new THREE.SphereGeometry(0.4, 14, 10),
hideLightMaterial
);
shoulder.scale.set(0.82, 1.1, 0.92);
shoulder.position.set(0, 1.14, 0.50);
shoulder.castShadow = true;
animal.add(shoulder);
const rump = new THREE.Mesh(
new THREE.SphereGeometry(0.38, 14, 10),
hideLightMaterial
);
rump.scale.set(0.88, 0.90, 0.82);
rump.position.set(0, 1.08, -0.50);
animal.add(rump);
const neck = new THREE.Mesh(
new THREE.SphereGeometry(0.34, 12, 9),
hideMaterial
);
neck.scale.set(0.80, 1.25, 0.95);
neck.position.set(0, 1.33, 0.70);
neck.castShadow = true;
animal.add(neck);
const mane = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.62, 0.26),
darkMaterial
);
mane.position.set(0, 1.52, 0.64);
mane.rotation.x = -0.40;
animal.add(mane);
const headPivot = new THREE.Group();
headPivot.position.set(0, 1.58, 0.83);
animal.add(headPivot);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.28, 14, 10),
hideMaterial
);
head.scale.set(0.85, 0.82, 1.16);
head.position.set(0, 0.05, 0.12);
head.castShadow = true;
headPivot.add(head);
const muzzle = new THREE.Mesh(
new THREE.SphereGeometry(0.20, 12, 8),
darkMaterial
);
muzzle.scale.set(0.72, 0.60, 1.12);
muzzle.position.set(0, -0.06, 0.40);
headPivot.add(muzzle);
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.026, 8, 6),
darkMaterial
);
eye.position.set(side * 0.215, 0.11, 0.26);
headPivot.add(eye);
const hornCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(side * 0.19, 0.25, 0.03),
new THREE.Vector3(side * 0.28, 0.37, -0.02),
new THREE.Vector3(side * 0.32, 0.44, -0.20),
new THREE.Vector3(side * 0.29, 0.39, -0.34)
]);
const horn = new THREE.Mesh(
new THREE.TubeGeometry(hornCurve, 12, 0.032, 6, false),
hornMaterial
);
horn.castShadow = true;
headPivot.add(horn);
}
const legPositions = [
[-0.29, 0.50],
[0.29, 0.50],
[-0.29, -0.49],
[0.29, -0.49]
];
legPositions.forEach(([x, z], index) => {
const pivot = new THREE.Group();
pivot.position.set(x, 0.68, z);
animal.add(pivot);
const upper = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.075, 0.66, 7),
hideMaterial
);
upper.position.y = -0.33;
upper.castShadow = true;
pivot.add(upper);
const hoof = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.09, 0.13, 7),
darkMaterial
);
hoof.position.y = -0.71;
hoof.castShadow = true;
pivot.add(hoof);
legPivots.push({ pivot, phase: index * 1.55 + (index > 1 ? 0.5 : 0) });
});
const tailPivot = new THREE.Group();
tailPivot.position.set(0, 1.20, -0.86);
animal.add(tailPivot);
const tail = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.045, 0.70, 6),
darkMaterial
);
tail.position.y = -0.30;
tail.rotation.x = -0.45;
tailPivot.add(tail);
const tailTip = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.28, 7),
darkMaterial
);
tailTip.position.set(0, -0.66, 0.12);
tailTip.rotation.x = 1.3;
tailPivot.add(tailTip);
animal.userData.legs = legPivots;
animal.userData.headPivot = headPivot;
animal.userData.tailPivot = tailPivot;
return animal;
}
const herd = [];
const animalCount = 6;
const lateralOffsets = [-0.72, 0.64, -0.28, 0.92, -0.95, 0.12];
for (let i = 0; i < animalCount; i++) {
const animal = createWildebeest();
animal.scale.setScalar(0.62 + random() * 0.08);
animal.rotation.y = Math.PI + random() * 0.14;
animal.userData.index = i;
animal.userData.delay = i * 0.42;
animal.userData.duration = 25.5;
animal.userData.offset = lateralOffsets[i];
animal.userData.phase = random() * Math.PI * 2;
diorama.add(animal);
herd.push(animal);
}
// -------------------------------------------------------------------------
// Seasonal color logic
// -------------------------------------------------------------------------
const seasons = {
dry: {
base: new THREE.Color(0xa78f50),
green: new THREE.Color(0x667449),
patch: new THREE.Color(0x6f7d48),
patchOpacity: 0.24,
grass: new THREE.Color(0x8b814b),
note: "Sparse, tawny grass and conspicuous open water in this schematic landscape."
},
short: {
base: new THREE.Color(0x929052),
green: new THREE.Color(0x577448),
patch: new THREE.Color(0x5f8548),
patchOpacity: 0.45,
grass: new THREE.Color(0x71804a),
note: "Localized green flushes appear around moist ground and within the seasonal grass patch."
},
green: {
base: new THREE.Color(0x718044),
green: new THREE.Color(0x486b43),
patch: new THREE.Color(0x4f7b46),
patchOpacity: 0.62,
grass: new THREE.Color(0x607748),
note: "Broader green cover is shown as a seasonal lens; actual rainfall and grass conditions vary."
}
};
function updateTerrainColors(season) {
const config = seasons[season];
const colors = terrainGeometry.attributes.color;
const base = config.base.clone();
const green = config.green.clone();
const color = new THREE.Color();
for (let i = 0; i < terrainPosition.count; i++) {
const x = terrainPosition.getX(i);
const z = terrainPosition.getZ(i);
const moisture =
(1 - smoothstep(0.65, 3.1, pondDistance(x, z))) * 0.75;
const patchNoise =
(Math.sin(x * 0.31 + z * 0.16) +
Math.cos(z * 0.37 - x * 0.12) +
Math.sin((x + z) * 0.19) * 0.5) / 2.5;
const seasonalGreen = clamp(
moisture + patchNoise * (season === "dry" ? 0.12 : 0.36),
0,
0.88
);
color.copy(base).lerp(green, seasonalGreen);
const grain = 0.94 + random() * 0.10;
color.multiplyScalar(grain);
colors.setXYZ(i, color.r, color.g, color.b);
}
colors.needsUpdate = true;
resourcePatches.forEach((patch, index) => {
patch.material.color.copy(config.patch);
patch.material.opacity =
config.patchOpacity * (index === 0 ? 0.82 : 0.86 + random() * 0.14);
});
grassMaterial.color.copy(config.grass);
arrowMaterial.color.set(season === "green" ? 0xe9c66b : 0xe7b85c);
mainRouteMaterial.color.set(season === "green" ? 0xe9c66b : 0xe7b85c);
}
document.querySelectorAll(".season-button").forEach((button) => {
button.addEventListener("click", () => {
const season = button.dataset.season;
document.querySelectorAll(".season-button").forEach((b) => {
b.classList.toggle("active", b === button);
b.setAttribute("aria-pressed", String(b === button));
});
updateTerrainColors(season);
document.getElementById("season-note").textContent = seasons[season].note;
});
});
updateTerrainColors("dry");
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
const controls = {
yaw: 0.70,
pitch: 0.59,
radius: 48,
target: new THREE.Vector3(0, -0.35, 0),
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const horizontal = controls.radius * Math.cos(controls.pitch);
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.radius,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.yaw = 0.70;
controls.pitch = 0.59;
controls.radius = 48;
controls.target.set(0, -0.35, 0);
updateCamera();
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.yaw -= dx * 0.006;
controls.pitch = clamp(controls.pitch + dy * 0.005, 0.25, 1.18);
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = clamp(controls.radius + event.deltaY * 0.028, 31, 72);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.yaw += 0.08;
if (event.key === "ArrowRight") controls.yaw -= 0.08;
if (event.key === "ArrowUp") controls.pitch = clamp(controls.pitch + 0.06, 0.25, 1.18);
if (event.key === "ArrowDown") controls.pitch = clamp(controls.pitch - 0.06, 0.25, 1.18);
if (event.key === "+" || event.key === "=") controls.radius = clamp(controls.radius - 2, 31, 72);
if (event.key === "-") controls.radius = clamp(controls.radius + 2, 31, 72);
if (event.key === "Escape") resetCamera();
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let approachStart = clock.getElapsedTime();
document.getElementById("replay").addEventListener("click", () => {
approachStart = clock.getElapsedTime();
});
const tempPoint = new THREE.Vector3();
const tempTangent = new THREE.Vector3();
const tempRight = new THREE.Vector3();
const worldUp = new THREE.Vector3(0, 1, 0);
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const sceneTime = elapsed - approachStart;
herd.forEach((animal) => {
const data = animal.userData;
const rawProgress = clamp(
(sceneTime - data.delay) / data.duration,
0,
1
);
// Ease-in/ease-out keeps the group calm and coordinated.
const progress = rawProgress * rawProgress * (3 - 2 * rawProgress);
mainRoute.getPointAt(progress, tempPoint);
mainRoute.getTangentAt(progress, tempTangent).normalize();
tempRight.crossVectors(tempTangent, worldUp).normalize();
tempPoint.addScaledVector(tempRight, data.offset);
tempPoint.y = groundY(tempPoint.x, tempPoint.z, 0.015);
animal.position.copy(tempPoint);
const heading = Math.atan2(tempTangent.x, tempTangent.z);
animal.rotation.y = heading;
const moving = rawProgress > 0 && rawProgress < 0.999;
const stride = moving ? elapsed * 8.2 + data.phase : 0;
data.legs.forEach((leg) => {
leg.pivot.rotation.x = moving
? Math.sin(stride + leg.phase) * 0.48
: 0;
});
const bob = moving
? Math.abs(Math.sin(stride * 0.5)) * 0.055
: Math.sin(elapsed * 1.8 + data.phase) * 0.012;
animal.position.y += bob;
const reachedWater = rawProgress > 0.985;
data.headPivot.rotation.x = reachedWater
? 0.62 + Math.sin(elapsed * 1.7 + data.phase) * 0.08
: moving
? Math.sin(stride * 0.5) * 0.035
: 0.05;
data.tailPivot.rotation.z = Math.sin(elapsed * 3.0 + data.phase) * 0.10;
});
ripples.forEach((ripple, index) => {
const phase = (elapsed * 0.16 + index * 0.23) % 1;
const scale = 0.86 + phase * 0.17;
ripple.scale.set(POND.rx * scale, POND.rz * scale, 1);
ripple.material.opacity = 0.24 * (1 - phase);
});
renderer.render(scene, camera);
}
animate();
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
</script>
</body>
</html>
```