Prompt specification
Build or customize the Three.js 3D scene "Shallow lagoon feeding group" 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: Shallow lagoon feeding group
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shallow-lagoon-feeding-group-x0683
Scene Description Prompt:
Create stylized wading birds feeding along a shallow lagoon, with water depths matching their stance. Three.js from cdnjs, one HTML file.
Working Three.js Starter (shallow-lagoon-feeding-group-x0683):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Depth-Aware Lagoon Waders</title>
<style>
:root {
color-scheme: light;
--ink: #173e43;
--muted: #4e7070;
--paper: rgba(250, 247, 232, 0.84);
--line: rgba(23, 62, 67, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d7d3;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 20px 21px 18px;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 18px;
box-shadow:
0 18px 50px rgba(23, 62, 67, 0.12),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px) saturate(115%);
-webkit-backdrop-filter: blur(14px) saturate(115%);
pointer-events: none;
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #597b77;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 1px;
content: "";
background: #70938c;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 40px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.description {
margin: 12px 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #426663;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(23, 62, 67, 0.06);
}
.dot.heron {
background: #60777b;
}
.dot.egret {
background: #f2edd8;
border: 1px solid #bdb99f;
}
.dot.little {
background: #d6a447;
}
.hint {
position: fixed;
z-index: 10;
right: 20px;
bottom: 20px;
padding: 10px 13px;
color: rgba(23, 62, 67, 0.82);
background: rgba(248, 245, 228, 0.7);
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 999px;
box-shadow: 0 8px 24px rgba(23, 62, 67, 0.08);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.035em;
pointer-events: none;
user-select: none;
}
button {
position: fixed;
z-index: 11;
right: 20px;
top: 20px;
padding: 10px 14px;
color: var(--ink);
background: rgba(249, 246, 231, 0.78);
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 999px;
box-shadow: 0 8px 24px rgba(23, 62, 67, 0.09);
backdrop-filter: blur(10px);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
background: rgba(255, 252, 239, 0.96);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #c7dfd9;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
.description {
margin-bottom: 12px;
}
button {
top: auto;
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive scene of wading birds in a shallow lagoon"></canvas>
<section class="panel">
<div class="eyebrow">Lagoon Field Study · 07</div>
<h1>Low-Tide<br />Waders</h1>
<p class="description">
Each bird is placed on the lagoon bed according to its leg length and
stance, so the waterline naturally rises or falls around its legs.
</p>
<div class="legend">
<span><i class="dot heron"></i>Heron · deeper water</span>
<span><i class="dot egret"></i>Egret · shallow water</span>
<span><i class="dot little"></i>Little egret · margin</span>
</div>
</section>
<button id="reset" type="button">Reset view</button>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div id="loading">Preparing the lagoon…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const resetButton = document.querySelector("#reset");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0xb9d6d0, 0.0125);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
160
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const clock = new THREE.Clock();
const WORLD_W = 48;
const WORLD_D = 34;
const MAX_DEPTH = 3;
let seed = 71839;
function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
const range = (a, b) => a + (b - a) * random();
/*
* Signed bathymetry:
* positive values are underwater depth;
* negative values are dry bank elevation.
*/
function bathymetry(x, z) {
const r = Math.hypot(x / 14.5, z / 8.35);
let depth;
if (r <= 1) {
depth = 1.34 * (1 - Math.pow(r, 1.62));
} else {
depth =
-0.64 -
0.24 * THREE.MathUtils.smoothstep(r, 1, 1.38);
}
const meanderingChannel =
0.39 *
Math.exp(-Math.pow((z - 1.55 * Math.sin(x * 0.31)) / 1.62, 2)) *
Math.exp(-Math.pow(x / 15.2, 4));
const sandbar =
0.43 *
Math.exp(-(Math.pow(x - 5.1, 2) / 4.2 + Math.pow(z - 0.8, 2) / 5.4));
const smallIsland =
0.82 *
Math.exp(-(Math.pow(x + 5.2, 2) / 4.8 + Math.pow(z - 3.05, 2) / 2.3));
depth += meanderingChannel - sandbar - smallIsland;
return THREE.MathUtils.clamp(depth, -1.05, 1.85);
}
// ---------------------------------------------------------------------
// Lighting and sky
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe8fbff, 0xa57e54, 1.8);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffedc4, 3.1);
sunLight.position.set(-9, 15, 8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -23;
sunLight.shadow.camera.right = 23;
sunLight.shadow.camera.top = 18;
sunLight.shadow.camera.bottom = -18;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 45;
sunLight.shadow.bias = -0.00035;
scene.add(sunLight);
const sky = new THREE.Mesh(
new THREE.SphereGeometry(75, 32, 18),
new THREE.ShaderMaterial({
side: THREE.BackSide,
depthWrite: false,
vertexShader: `
varying vec3 vDirection;
void main() {
vDirection = normalize(position);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
varying vec3 vDirection;
void main() {
float h = clamp(vDirection.y * 0.5 + 0.5, 0.0, 1.0);
vec3 horizon = vec3(0.94, 0.86, 0.68);
vec3 zenith = vec3(0.39, 0.68, 0.73);
vec3 color = mix(horizon, zenith, smoothstep(0.30, 0.88, h));
float warmth = pow(1.0 - abs(vDirection.y), 6.0);
color += vec3(0.05, 0.025, 0.0) * warmth;
gl_FragColor = vec4(color, 1.0);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`
})
);
sky.renderOrder = -20;
scene.add(sky);
const sunDisc = new THREE.Mesh(
new THREE.SphereGeometry(1.65, 20, 14),
new THREE.MeshBasicMaterial({ color: 0xffe4a0, fog: false })
);
sunDisc.position.set(-22, 16, -30);
scene.add(sunDisc);
const cloudMaterial = new THREE.MeshBasicMaterial({
color: 0xfff5dc,
fog: false
});
const clouds = [];
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
const pieces = [
[-1.2, 0, 0, 1.0],
[-0.45, 0.18, 0, 1.15],
[0.35, 0.12, 0, 0.95],
[1.05, -0.02, 0, 0.72]
];
for (const [px, py, pz, s] of pieces) {
const puff = new THREE.Mesh(
new THREE.SphereGeometry(1, 12, 8),
cloudMaterial
);
puff.position.set(px, py, pz);
puff.scale.set(1.25 * s, 0.48 * s, 0.66 * s);
group.add(puff);
}
group.userData.speed = range(0.025, 0.06);
group.userData.startX = x;
clouds.push(group);
scene.add(group);
}
makeCloud(-18, 13.5, -26, 2.2);
makeCloud(18, 16, -35, 2.8);
makeCloud(-4, 19, -42, 3.5);
// ---------------------------------------------------------------------
// Lagoon bed and surrounding terrain
// ---------------------------------------------------------------------
const terrainGeometry = new THREE.PlaneGeometry(
WORLD_W,
WORLD_D,
128,
90
);
terrainGeometry.rotateX(-Math.PI / 2);
const terrainPositions = terrainGeometry.attributes.position;
const terrainColors = new Float32Array(terrainPositions.count * 3);
const drySand = new THREE.Color(0xd6c08d);
const paleSand = new THREE.Color(0xc9c493);
const wetSand = new THREE.Color(0x8eb6a1);
const deepBed = new THREE.Color(0x3f8580);
const color = new THREE.Color();
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
const depth = bathymetry(x, z);
terrainPositions.setY(i, -depth);
if (depth > 0) {
const t = THREE.MathUtils.clamp(depth / 1.4, 0, 1);
color.copy(paleSand).lerp(wetSand, Math.min(1, t * 2.1));
color.lerp(deepBed, Math.max(0, t * 1.3 - 0.18));
const variation = Math.sin(x * 1.73 + z * 0.91) * 0.025;
color.offsetHSL(0, 0, variation);
} else {
color.copy(drySand);
color.offsetHSL(
Math.sin(x * 0.27 + z * 0.17) * 0.012,
0,
Math.sin(x * 0.63 - z * 0.42) * 0.045
);
}
terrainColors[i * 3] = color.r;
terrainColors[i * 3 + 1] = color.g;
terrainColors[i * 3 + 2] = color.b;
}
terrainGeometry.setAttribute(
"color",
new THREE.BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.94,
metalness: 0,
flatShading: true
})
);
terrain.receiveShadow = true;
scene.add(terrain);
// A surrounding dry plain with an elliptical opening for the lagoon.
const outerShape = new THREE.Shape();
outerShape.moveTo(-70, -70);
outerShape.lineTo(70, -70);
outerShape.lineTo(70, 70);
outerShape.lineTo(-70, 70);
outerShape.closePath();
const lagoonHole = new THREE.Path();
lagoonHole.absellipse(0, 0, 15.2, 8.9, 0, Math.PI * 2, true);
outerShape.holes.push(lagoonHole);
const outerGeometry = new THREE.ShapeGeometry(outerShape);
outerGeometry.rotateX(-Math.PI / 2);
const outerPlain = new THREE.Mesh(
outerGeometry,
new THREE.MeshStandardMaterial({
color: 0xd5bd88,
roughness: 1,
flatShading: true
})
);
outerPlain.position.y = 0.59;
outerPlain.receiveShadow = true;
scene.add(outerPlain);
// ---------------------------------------------------------------------
// Depth texture and animated water
// ---------------------------------------------------------------------
const textureWidth = 256;
const textureHeight = 160;
const depthData = new Uint8Array(textureWidth * textureHeight * 4);
for (let y = 0; y < textureHeight; y++) {
const z = -WORLD_D / 2 + (y / (textureHeight - 1)) * WORLD_D;
for (let x = 0; x < textureWidth; x++) {
const wx = -WORLD_W / 2 + (x / (textureWidth - 1)) * WORLD_W;
const depth = Math.max(0, bathymetry(wx, z));
const i = (y * textureWidth + x) * 4;
const encoded = Math.round(
THREE.MathUtils.clamp(depth / MAX_DEPTH, 0, 1) * 255
);
depthData[i] = encoded;
depthData[i + 1] = encoded;
depthData[i + 2] = encoded;
depthData[i + 3] = 255;
}
}
const depthTexture = new THREE.DataTexture(
depthData,
textureWidth,
textureHeight,
THREE.RGBAFormat
);
depthTexture.minFilter = THREE.LinearFilter;
depthTexture.magFilter = THREE.LinearFilter;
depthTexture.generateMipmaps = false;
depthTexture.needsUpdate = true;
const waterUniforms = {
uTime: { value: 0 },
uDepthMap: { value: depthTexture },
uWorldSize: { value: new THREE.Vector2(WORLD_W, WORLD_D) },
uMaxDepth: { value: MAX_DEPTH }
};
const waterGeometry = new THREE.PlaneGeometry(
WORLD_W,
WORLD_D,
120,
84
);
waterGeometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(
waterGeometry,
new THREE.ShaderMaterial({
uniforms: waterUniforms,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
vertexShader: `
uniform float uTime;
varying vec3 vWorldPosition;
varying float vWave;
void main() {
vec3 p = position;
float waveA = sin(p.x * 0.48 + uTime * 0.75) * 0.014;
float waveB = sin(p.z * 0.81 - uTime * 0.52) * 0.010;
float waveC = sin((p.x + p.z) * 1.23 + uTime * 1.05) * 0.005;
p.y += waveA + waveB + waveC;
vWave = waveA + waveB + waveC;
vec4 world = modelMatrix * vec4(p, 1.0);
vWorldPosition = world.xyz;
gl_Position = projectionMatrix * viewMatrix * world;
}
`,
fragmentShader: `
uniform float uTime;
uniform sampler2D uDepthMap;
uniform vec2 uWorldSize;
uniform float uMaxDepth;
varying vec3 vWorldPosition;
varying float vWave;
void main() {
vec2 uv = vec2(
vWorldPosition.x / uWorldSize.x + 0.5,
vWorldPosition.z / uWorldSize.y + 0.5
);
float depth = texture2D(uDepthMap, uv).r * uMaxDepth;
if (depth < 0.008) discard;
float deep = smoothstep(0.04, 1.30, depth);
float shore = 1.0 - smoothstep(0.018, 0.10, depth);
vec3 shallowColor = vec3(0.49, 0.79, 0.72);
vec3 deepColor = vec3(0.055, 0.36, 0.43);
vec3 color = mix(shallowColor, deepColor, deep);
float ripples =
sin(vWorldPosition.x * 2.4 + uTime * 0.85) *
sin(vWorldPosition.z * 2.8 - uTime * 0.63);
float glints = pow(max(0.0, ripples), 8.0) * 0.09;
color += glints;
vec3 normal = normalize(vec3(
cos(vWorldPosition.x * 0.48 + uTime * 0.75) * 0.018,
1.0,
cos(vWorldPosition.z * 0.81 - uTime * 0.52) * 0.015
));
vec3 viewDir = normalize(cameraPosition - vWorldPosition);
float fresnel = pow(1.0 - max(dot(normal, viewDir), 0.0), 3.0);
color = mix(color, vec3(0.78, 0.91, 0.86), fresnel * 0.24);
float reflectionZone =
1.0 - smoothstep(
0.0,
1.0,
length((vWorldPosition.xz - vec2(-6.0, -8.0)) / vec2(9.0, 5.0))
);
float brokenGlint =
pow(
max(0.0, sin(vWorldPosition.x * 3.2 + uTime) *
cos(vWorldPosition.z * 4.1 - uTime * 0.7)),
18.0
);
color += vec3(1.0, 0.82, 0.48) *
reflectionZone * brokenGlint * 0.32;
color = mix(color, vec3(0.94, 0.92, 0.72), shore * 0.58);
float alpha = mix(0.40, 0.72, deep);
alpha += shore * 0.13;
alpha += fresnel * 0.08;
gl_FragColor = vec4(color, alpha);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`
})
);
water.position.y = 0.005;
water.renderOrder = 2;
scene.add(water);
// ---------------------------------------------------------------------
// Shared geometry and material helpers
// ---------------------------------------------------------------------
const unitSphere = new THREE.SphereGeometry(1, 12, 8);
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 7);
const billGeometry = new THREE.ConeGeometry(0.13, 0.82, 6);
const tailGeometry = new THREE.ConeGeometry(0.27, 0.72, 5);
const leafGeometry = new THREE.ConeGeometry(0.085, 0.72, 3);
const rockGeometry = new THREE.IcosahedronGeometry(1, 0);
const UP = new THREE.Vector3(0, 1, 0);
function cylinderBetween(parent, a, b, radius, material, shadow = true) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(unitCylinder, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(UP, direction.normalize());
mesh.scale.set(radius, length, radius);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function ellipsoid(parent, position, scale, material, shadow = true) {
const mesh = new THREE.Mesh(unitSphere, material);
mesh.position.copy(position);
mesh.scale.copy(scale);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function standard(colorValue, options = {}) {
return new THREE.MeshStandardMaterial({
color: colorValue,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const species = {
heron: {
leg: 1.82,
neck: 1.16,
neckRadius: 0.118,
bodyScale: new THREE.Vector3(0.49, 0.37, 0.74),
bodyMaterial: standard(0x687d80),
wingMaterial: standard(0x465b60),
neckMaterial: standard(0xd4d8ce),
legMaterial: standard(0x39484a),
footMaterial: standard(0x39484a),
billMaterial: standard(0xd6a63d),
crestMaterial: standard(0x263b3e),
eyeMaterial: standard(0x111d1e),
targetDepth: 0.47,
depthRange: [0.30, 0.63]
},
egret: {
leg: 1.34,
neck: 1.03,
neckRadius: 0.104,
bodyScale: new THREE.Vector3(0.43, 0.33, 0.68),
bodyMaterial: standard(0xf4f0dc),
wingMaterial: standard(0xe4dfc8),
neckMaterial: standard(0xf7f3df),
legMaterial: standard(0x3f4c49),
footMaterial: standard(0x3f4c49),
billMaterial: standard(0xe4aa3c),
crestMaterial: standard(0x334747),
eyeMaterial: standard(0x101919),
targetDepth: 0.21,
depthRange: [0.105, 0.34]
},
little: {
leg: 0.94,
neck: 0.78,
neckRadius: 0.088,
bodyScale: new THREE.Vector3(0.37, 0.29, 0.59),
bodyMaterial: standard(0xf8f2d9),
wingMaterial: standard(0xebe3c8),
neckMaterial: standard(0xfaf4dc),
legMaterial: standard(0x414b45),
footMaterial: standard(0xd2a345),
billMaterial: standard(0xe4ae3b),
crestMaterial: standard(0x3b4946),
eyeMaterial: standard(0x101919),
targetDepth: 0.075,
depthRange: [0.025, 0.14]
}
};
// ---------------------------------------------------------------------
// Stylized bird construction
// ---------------------------------------------------------------------
const birds = [];
function makeBird(type, x, z, depth, yaw, index) {
const sp = species[type];
const root = new THREE.Group();
root.position.set(x, -depth, z);
root.rotation.y = yaw;
scene.add(root);
const bodyGroup = new THREE.Group();
bodyGroup.position.y = sp.leg;
root.add(bodyGroup);
ellipsoid(
bodyGroup,
new THREE.Vector3(0, 0, 0),
sp.bodyScale,
sp.bodyMaterial
);
// Folded wings.
for (const side of [-1, 1]) {
ellipsoid(
bodyGroup,
new THREE.Vector3(side * 0.41, 0.035, -0.02),
new THREE.Vector3(0.115, 0.285, 0.60),
sp.wingMaterial
);
}
// A dark shoulder mark on the gray herons.
if (type === "heron") {
for (const side of [-1, 1]) {
ellipsoid(
bodyGroup,
new THREE.Vector3(side * 0.455, 0.12, -0.14),
new THREE.Vector3(0.075, 0.16, 0.31),
sp.crestMaterial
);
}
}
const tail = new THREE.Mesh(tailGeometry, sp.wingMaterial);
tail.position.set(0, 0.025, -0.79);
tail.rotation.x = -Math.PI / 2;
tail.castShadow = true;
bodyGroup.add(tail);
// One planted leg and one folded, slightly raised leg.
const plantedSide = index % 2 === 0 ? 1 : -1;
const plantedFoot = new THREE.Vector3(
plantedSide * 0.14,
0.035,
0.01
);
const plantedHip = new THREE.Vector3(
plantedSide * 0.14,
sp.leg - 0.09,
-0.02
);
cylinderBetween(
root,
plantedFoot,
plantedHip,
0.032,
sp.legMaterial
);
const liftedSide = -plantedSide;
const liftedHip = new THREE.Vector3(
liftedSide * 0.14,
sp.leg - 0.09,
-0.01
);
const liftedKnee = new THREE.Vector3(
liftedSide * 0.22,
sp.leg * 0.51,
-0.24
);
const liftedFoot = new THREE.Vector3(
liftedSide * 0.18,
0.20,
-0.43
);
cylinderBetween(
root,
liftedHip,
liftedKnee,
0.031,
sp.legMaterial
);
cylinderBetween(
root,
liftedKnee,
liftedFoot,
0.027,
sp.legMaterial
);
// Long toes follow the actual submerged foot position.
for (const dx of [-0.115, 0, 0.115]) {
cylinderBetween(
root,
plantedFoot,
new THREE.Vector3(
plantedFoot.x + dx,
0.025,
plantedFoot.z + 0.38
),
0.015,
sp.footMaterial
);
}
cylinderBetween(
root,
plantedFoot,
new THREE.Vector3(
plantedFoot.x,
0.025,
plantedFoot.z - 0.19
),
0.014,
sp.footMaterial
);
// The feeding posture is constructed to reach the water surface.
const feeding = index % 3 !== 1;
const neckPivot = new THREE.Group();
neckPivot.position.set(0, 0.12, 0.46);
bodyGroup.add(neckPivot);
let endY;
let endZ;
if (feeding) {
endY = -(sp.leg - depth - 0.16);
endZ = 0.91;
} else {
endY = sp.neck;
endZ = 0.18;
}
const neckPoints = feeding
? [
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 0.30, -0.07),
new THREE.Vector3(0, Math.max(0.08, endY * 0.36), 0.43),
new THREE.Vector3(0, endY, endZ)
]
: [
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 0.35, -0.11),
new THREE.Vector3(0, sp.neck * 0.74, -0.04),
new THREE.Vector3(0, endY, endZ)
];
const neckCurve = new THREE.CatmullRomCurve3(neckPoints);
const neckMesh = new THREE.Mesh(
new THREE.TubeGeometry(
neckCurve,
18,
sp.neckRadius,
7,
false
),
sp.neckMaterial
);
neckMesh.castShadow = true;
neckMesh.receiveShadow = true;
neckPivot.add(neckMesh);
const head = new THREE.Group();
head.position.copy(neckPoints[neckPoints.length - 1]);
neckPivot.add(head);
ellipsoid(
head,
new THREE.Vector3(0, 0, 0.03),
new THREE.Vector3(0.205, 0.19, 0.285),
sp.neckMaterial
);
const bill = new THREE.Mesh(billGeometry, sp.billMaterial);
bill.position.set(0, -0.015, 0.43);
bill.rotation.x = 2.15;
bill.castShadow = true;
head.add(bill);
for (const side of [-1, 1]) {
ellipsoid(
head,
new THREE.Vector3(side * 0.17, 0.055, 0.095),
new THREE.Vector3(0.028, 0.028, 0.028),
sp.eyeMaterial,
false
);
}
// Fine crest plumes.
const plumeCount = type === "heron" ? 1 : 2;
for (let i = 0; i < plumeCount; i++) {
const offset = (i - (plumeCount - 1) / 2) * 0.07;
cylinderBetween(
head,
new THREE.Vector3(offset, 0.13, -0.04),
new THREE.Vector3(offset * 1.8, 0.34 - Math.abs(offset), -0.50),
0.012,
sp.crestMaterial
);
}
root.userData = {
baseY: -depth,
phase: random() * Math.PI * 2,
bodyGroup,
neckPivot,
head,
feeding,
baseDip: feeding ? 0.07 : -0.015
};
// Surface ripple around the planted foot.
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xe9f0d6,
transparent: true,
opacity: 0.25,
depthWrite: false,
side: THREE.DoubleSide
});
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.15, 0.185, 40),
rippleMaterial
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(x, 0.025, z);
ripple.renderOrder = 3;
scene.add(ripple);
root.userData.ripple = ripple;
birds.push(root);
}
function findBirdSpot(sp, occupied) {
let best = null;
let bestScore = Infinity;
for (let attempt = 0; attempt < 9000; attempt++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random());
const x = Math.cos(angle) * radius * 13.5;
const z = Math.sin(angle) * radius * 7.8;
const depth = bathymetry(x, z);
if (
depth < sp.depthRange[0] ||
depth > sp.depthRange[1]
) {
continue;
}
let nearest = Infinity;
for (const other of occupied) {
nearest = Math.min(
nearest,
Math.hypot(x - other.x, z - other.z)
);
}
if (nearest < 1.25) continue;
const score =
Math.abs(depth - sp.targetDepth) +
random() * 0.08 +
Math.max(0, 2.1 - nearest) * 0.06;
if (score < bestScore) {
bestScore = score;
best = { x, z, depth };
}
}
if (!best) {
// Relaxed fallback for very crowded procedural placement.
for (let attempt = 0; attempt < 12000; attempt++) {
const x = range(-13, 13);
const z = range(-7.5, 7.5);
const depth = bathymetry(x, z);
const score = Math.abs(depth - sp.targetDepth);
if (depth > 0.015 && score < bestScore) {
bestScore = score;
best = { x, z, depth };
}
}
}
return best;
}
const population = [
"heron",
"egret",
"heron",
"little",
"egret",
"heron",
"little",
"egret",
"little",
"egret"
];
const occupied = [];
population.forEach((type, index) => {
const sp = species[type];
const spot = findBirdSpot(sp, occupied);
if (!spot) return;
occupied.push(spot);
makeBird(
type,
spot.x,
spot.z,
spot.depth,
random() * Math.PI * 2,
index
);
});
// ---------------------------------------------------------------------
// Reeds, rocks, and low dunes
// ---------------------------------------------------------------------
const reedMaterial = standard(0x58784f);
const reedLightMaterial = standard(0x77935d);
const reedDarkMaterial = standard(0x405e43);
const cattailMaterial = standard(0x775039);
const rockMaterial = standard(0x8a8c78);
const rockLightMaterial = standard(0xa5a087);
const reedGroups = [];
function makeReedCluster(x, z, baseY) {
const cluster = new THREE.Group();
cluster.position.set(x, baseY, z);
const count = 3 + Math.floor(random() * 4);
for (let i = 0; i < count; i++) {
const height = range(0.65, 1.55);
const leanX = range(-0.12, 0.12);
const leanZ = range(-0.12, 0.12);
const px = range(-0.24, 0.24);
const pz = range(-0.24, 0.24);
const base = new THREE.Vector3(px, 0, pz);
const top = new THREE.Vector3(
px + leanX,
height,
pz + leanZ
);
cylinderBetween(
cluster,
base,
top,
range(0.012, 0.019),
random() > 0.5 ? reedMaterial : reedLightMaterial
);
for (let leafIndex = 0; leafIndex < 2; leafIndex++) {
const leaf = new THREE.Mesh(
leafGeometry,
leafIndex ? reedDarkMaterial : reedLightMaterial
);
leaf.position.set(
px + leanX * 0.3,
height * (0.35 + leafIndex * 0.25),
pz + leanZ * 0.3
);
leaf.rotation.z = (leafIndex ? -1 : 1) * range(0.65, 1.15);
leaf.rotation.x = range(-0.2, 0.2);
leaf.scale.y = range(0.75, 1.2);
leaf.castShadow = true;
cluster.add(leaf);
}
if (random() > 0.52) {
const cattail = new THREE.Mesh(
unitCylinder,
cattailMaterial
);
cattail.position.copy(top);
cattail.position.y += 0.09;
cattail.scale.set(0.047, 0.24, 0.047);
cattail.castShadow = true;
cluster.add(cattail);
}
}
cluster.userData.phase = random() * Math.PI * 2;
reedGroups.push(cluster);
scene.add(cluster);
}
let reedCount = 0;
for (let attempt = 0; attempt < 3000 && reedCount < 25; attempt++) {
const x = range(-15.2, 15.2);
const z = range(-8.8, 8.8);
const depth = bathymetry(x, z);
if (depth < -0.22 || depth > 0.115) continue;
if (occupied.some((p) => Math.hypot(x - p.x, z - p.z) < 1.0)) {
continue;
}
makeReedCluster(x, z, -depth);
reedCount++;
}
for (let i = 0; i < 24; i++) {
const x = range(-18, 18);
const z = range(-11, 11);
const depth = bathymetry(x, z);
if (depth > -0.08 || depth < -0.58) continue;
const rock = new THREE.Mesh(
rockGeometry,
random() > 0.5 ? rockMaterial : rockLightMaterial
);
const size = range(0.18, 0.58);
rock.scale.set(size * range(0.8, 1.5), size, size * range(0.8, 1.4));
rock.position.set(x, -depth + size * 0.28, z);
rock.rotation.set(random(), random() * Math.PI, random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
const duneMaterial = standard(0xcbb27e);
for (const [x, z, sx, sy, sz] of [
[-22, -5, 6, 1.4, 3],
[21, 4, 7, 1.1, 4],
[-18, 12, 5, 0.9, 3],
[12, -14, 5.5, 1.2, 3.3]
]) {
const dune = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
duneMaterial
);
dune.position.set(x, 0.58, z);
dune.scale.set(sx, sy, sz);
dune.receiveShadow = true;
scene.add(dune);
}
// ---------------------------------------------------------------------
// Custom orbit, pan, zoom, touch, and reset controls
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.35, 0),
radius: 20.5,
theta: 0.72,
phi: 0.74
};
const initialControls = {
target: controls.target.clone(),
radius: controls.radius,
theta: controls.theta,
phi: controls.phi
};
const pointers = new Map();
let interactionMode = "orbit";
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
let pinchCenterX = 0;
let pinchCenterY = 0;
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function panCamera(dx, dy) {
const forward = new THREE.Vector3()
.subVectors(controls.target, camera.position);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, UP)
.normalize();
const scale = controls.radius * 0.00135;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, dy * scale);
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-18,
18
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-12,
12
);
}
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
function pointerCenter() {
const points = [...pointers.values()];
if (!points.length) return { x: 0, y: 0 };
return {
x: points.reduce((sum, p) => sum + p.x, 0) / points.length,
y: points.reduce((sum, p) => sum + p.y, 0) / points.length
};
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
canvas.classList.add("dragging");
if (pointers.size === 1) {
interactionMode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
interactionMode = "pinch";
pinchDistance = pointerDistance();
const center = pointerCenter();
pinchCenterX = center.x;
pinchCenterY = center.y;
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (interactionMode === "pan") {
panCamera(dx, dy);
} else {
controls.theta -= dx * 0.0052;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0045,
0.23,
1.43
);
}
} else if (pointers.size === 2) {
const distance = pointerDistance();
const center = pointerCenter();
if (pinchDistance > 0 && distance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (pinchDistance / distance),
7,
34
);
}
panCamera(center.x - pinchCenterX, center.y - pinchCenterY);
pinchDistance = distance;
pinchCenterX = center.x;
pinchCenterY = center.y;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
canvas.classList.remove("dragging");
interactionMode = "orbit";
pinchDistance = 0;
} else if (pointers.size === 1) {
interactionMode = "orbit";
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
7,
34
);
},
{ passive: false }
);
resetButton.addEventListener("click", () => {
controls.target.copy(initialControls.target);
controls.radius = initialControls.radius;
controls.theta = initialControls.theta;
controls.phi = initialControls.phi;
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
function animate() {
const time = clock.getElapsedTime();
waterUniforms.uTime.value = time;
for (const bird of birds) {
const data = bird.userData;
const phase = data.phase;
const bob = Math.sin(time * 0.86 + phase) * 0.012;
bird.position.y = data.baseY + bob;
data.bodyGroup.rotation.z = Math.sin(time * 0.72 + phase) * 0.012;
data.bodyGroup.rotation.x = Math.sin(time * 0.43 + phase) * 0.006;
const peck = data.feeding
? 0.035 + (Math.sin(time * 0.82 + phase) * 0.5 + 0.5) * 0.095
: Math.sin(time * 0.61 + phase) * 0.025;
data.neckPivot.rotation.x = data.baseDip + peck;
data.head.rotation.y = Math.sin(time * 0.54 + phase) * 0.045;
const ripple = data.ripple;
const ripplePhase = (time * 0.32 + phase * 0.12) % 1;
const scale = 0.75 + ripplePhase * 1.55;
ripple.scale.setScalar(scale);
ripple.material.opacity = (1 - ripplePhase) * 0.23;
}
for (const reed of reedGroups) {
reed.rotation.z = Math.sin(time * 0.75 + reed.userData.phase) * 0.035;
reed.rotation.x = Math.cos(time * 0.58 + reed.userData.phase) * 0.018;
}
for (const cloud of clouds) {
cloud.position.x =
cloud.userData.startX +
Math.sin(time * cloud.userData.speed) * 2.8;
}
updateCamera();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
updateCamera();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
});
</script>
</body>
</html>
```