Prompt specification
Build or customize the Three.js 3D scene "Wetland migration pause scene" 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: Wetland migration pause scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wetland-migration-pause-scene-x0659
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: wetland migration pause scene. Compose a wetland with mudflat, reeds, shallow pools, and mixed resting birds; short arrival and departure motions show the place functioning as a temporary stopover.
Working Three.js Starter (wetland-migration-pause-scene-x0659):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Wetland Migration Pause</title>
<style>
:root {
color-scheme: dark;
--ink: #f4f1e8;
--muted: rgba(244, 241, 232, 0.68);
--glass: rgba(24, 39, 41, 0.72);
--line: rgba(255, 255, 255, 0.15);
--accent: #e6bc68;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9c6ca;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 48%, rgba(17, 30, 31, 0.19) 100%),
linear-gradient(180deg, rgba(22, 35, 36, 0.08), transparent 28%, rgba(22, 35, 36, 0.12));
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--glass);
box-shadow: 0 16px 42px rgba(14, 25, 26, 0.16);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
top: 24px;
left: 24px;
width: min(440px, calc(100vw - 48px));
padding: 20px 22px 19px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(27px, 3vw, 42px);
font-weight: 620;
letter-spacing: -0.045em;
line-height: 0.98;
}
header p {
max-width: 370px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
right: 24px;
bottom: 24px;
width: 224px;
padding: 15px 16px;
border-radius: 16px;
}
.legend-title {
margin-bottom: 11px;
color: rgba(255, 255, 255, 0.46);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0;
color: rgba(255, 255, 255, 0.76);
font-size: 11px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.status {
left: 24px;
bottom: 24px;
width: min(350px, calc(100vw - 48px));
padding: 15px 17px 14px;
border-radius: 16px;
}
.status-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
}
.status-label {
display: flex;
align-items: center;
gap: 9px;
color: var(--ink);
font-size: 11px;
font-weight: 760;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(230, 188, 104, 0.12);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 8px rgba(230, 188, 104, 0.03);
}
}
.status-clock {
color: rgba(255, 255, 255, 0.44);
font-variant-numeric: tabular-nums;
font-size: 10px;
letter-spacing: 0.08em;
}
.timeline {
height: 3px;
margin-top: 13px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.11);
}
#timelineFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #b5d8d7, var(--accent));
}
.controls {
right: 24px;
top: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 37px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 11px;
outline: none;
background: rgba(24, 39, 41, 0.72);
color: rgba(255, 255, 255, 0.83);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 720;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
button:hover {
border-color: rgba(255, 255, 255, 0.32);
background: rgba(35, 54, 55, 0.9);
}
#hint {
position: fixed;
z-index: 4;
top: 78px;
right: 25px;
color: rgba(255, 255, 255, 0.57);
font-size: 10px;
letter-spacing: 0.05em;
pointer-events: none;
}
.map-label {
position: fixed;
z-index: 3;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 5px;
background: rgba(27, 44, 45, 0.72);
color: rgba(255, 255, 255, 0.82);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
backdrop-filter: blur(6px);
-webkit-backdrop-filter: blur(6px);
}
.map-label::before {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 15px;
content: "";
background: rgba(255, 255, 255, 0.42);
}
.compass {
position: fixed;
z-index: 4;
right: 31px;
bottom: 171px;
display: grid;
place-items: center;
width: 40px;
height: 40px;
border: 1px solid rgba(255, 255, 255, 0.26);
border-radius: 50%;
color: rgba(255, 255, 255, 0.78);
font-size: 10px;
font-weight: 800;
pointer-events: none;
}
.compass::after {
position: absolute;
top: 3px;
content: "▲";
color: var(--accent);
font-size: 7px;
}
@media (max-width: 720px) {
header {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px 17px;
}
header p {
display: none;
}
.controls {
top: 126px;
right: 14px;
}
#hint,
.legend,
.compass {
display: none;
}
.status {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.map-label {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="vignette"></div>
<header class="panel">
<div class="eyebrow">Seasonal stopover · tidal wetland</div>
<h1>Migration<br />Pause</h1>
<p>
Between long legs of the journey, mixed flocks gather on exposed mud,
shallow pools, and reed margins for a brief communal rest.
</p>
</header>
<div class="controls">
<button id="replay" type="button" title="Restart the migration cycle">Replay</button>
<button id="toggle" type="button">Pause motion</button>
</div>
<div id="hint">Drag to orbit · Scroll to zoom</div>
<aside class="legend panel">
<div class="legend-title">Species at the stopover</div>
<div class="legend-row"><span class="swatch" style="background:#dedccb"></span> Grey heron</div>
<div class="legend-row"><span class="swatch" style="background:#315f59"></span> Dabbling duck</div>
<div class="legend-row"><span class="swatch" style="background:#a38866"></span> Sandpiper</div>
<div class="legend-row"><span class="swatch" style="background:#688467"></span> Reed bed</div>
<div class="legend-row"><span class="swatch" style="background:#75aeb5"></span> Shallow pool</div>
</aside>
<section class="status panel" aria-live="polite">
<div class="status-top">
<div class="status-label">
<span class="status-dot"></span>
<span id="phaseLabel">Arriving · landing on the mudflat</span>
</div>
<span id="phaseClock" class="status-clock">00:00 / 00:32</span>
</div>
<div class="timeline"><div id="timelineFill"></div></div>
</section>
<div class="compass">N</div>
<div id="reedLabel" class="map-label">Reed margin</div>
<div id="poolLabel" class="map-label">Tidal pool</div>
<div id="flockLabel" class="map-label">Resting flock</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, lighting
// ------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaac8cb);
scene.fog = new THREE.Fog(0xaac8cb, 27, 62);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xd9eef0, 0x67513e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe7b4, 3.15);
sun.position.set(-10, 18, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9dcbd1, 0.65);
fill.position.set(12, 7, -10);
scene.add(fill);
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function block(parent, material, sx, sy, sz, x, y, z) {
const mesh = new THREE.Mesh(boxGeometry, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function hash(x, z = 0) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
// ------------------------------------------------------------
// Diorama base and voxel mudflat
// ------------------------------------------------------------
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x5f4938,
roughness: 1
});
const lowerBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x49392f,
roughness: 1
});
block(scene, baseMaterial, 30.7, 0.72, 24.7, 0, -0.59, 0);
block(scene, lowerBaseMaterial, 31.1, 0.18, 25.1, 0, -1.02, 0);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x9bb9b8,
roughness: 1
});
const floor = new THREE.Mesh(new THREE.PlaneGeometry(120, 120), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.13;
floor.receiveShadow = true;
scene.add(floor);
const NX = 30;
const NZ = 24;
const cellMap = new Map();
const landCells = [];
const poolCells = [];
const poolSpecs = [
{ x: -7.2, z: 4.1, rx: 3.8, rz: 2.15 },
{ x: 5.0, z: -4.0, rx: 4.15, rz: 2.35 },
{ x: 8.2, z: 5.0, rx: 2.65, rz: 1.75 },
{ x: -2.0, z: -7.3, rx: 2.65, rz: 1.35 }
];
function keyFor(ix, iz) {
return `${ix},${iz}`;
}
for (let iz = 0; iz < NZ; iz++) {
for (let ix = 0; ix < NX; ix++) {
const x = ix - (NX - 1) / 2;
const z = iz - (NZ - 1) / 2;
let isPool = false;
for (const pool of poolSpecs) {
const q =
((x - pool.x) * (x - pool.x)) / (pool.rx * pool.rx) +
((z - pool.z) * (z - pool.z)) / (pool.rz * pool.rz);
const edgeNoise = (hash(ix + 19, iz + 7) - 0.5) * 0.2;
if (q < 0.91 + edgeNoise) {
isPool = true;
break;
}
}
const height = isPool
? 0.1
: 0.26 + hash(ix + 41, iz + 13) * 0.16;
const centerY = -0.23 + height / 2;
const top = -0.23 + height;
const cell = { ix, iz, x, z, top, pool: isPool };
cellMap.set(keyFor(ix, iz), cell);
if (isPool) poolCells.push(cell);
else landCells.push(cell);
}
}
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
});
const ground = new THREE.InstancedMesh(
boxGeometry,
groundMaterial,
NX * NZ
);
ground.receiveShadow = true;
ground.castShadow = true;
let groundIndex = 0;
const mudDark = new THREE.Color(0x72513c);
const mudLight = new THREE.Color(0x9a7656);
const mudWarm = new THREE.Color(0x866047);
for (const cell of cellMap.values()) {
dummy.position.set(cell.x, -0.23 + (cell.pool ? 0.1 : cell.top + 0.23) / 2, cell.z);
dummy.scale.set(0.985, cell.pool ? 0.1 : cell.top + 0.23, 0.985);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
ground.setMatrixAt(groundIndex, dummy.matrix);
const variation = hash(cell.ix + 2, cell.iz + 19);
const color = mudDark.clone().lerp(mudLight, variation * 0.82);
color.lerp(mudWarm, hash(cell.ix + 8, cell.iz + 4) * 0.23);
ground.setColorAt(groundIndex, color);
groundIndex++;
}
ground.instanceMatrix.needsUpdate = true;
ground.instanceColor.needsUpdate = true;
scene.add(ground);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x72aeb5,
transparent: true,
opacity: 0.72,
roughness: 0.2,
metalness: 0.05,
depthWrite: false
});
const water = new THREE.InstancedMesh(boxGeometry, waterMaterial, poolCells.length);
water.renderOrder = 2;
poolCells.forEach((cell, index) => {
dummy.position.set(cell.x, -0.095, cell.z);
dummy.scale.set(0.98, 0.07, 0.98);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
water.setMatrixAt(index, dummy.matrix);
});
water.instanceMatrix.needsUpdate = true;
scene.add(water);
function surfaceAt(x, z) {
const ix = THREE.MathUtils.clamp(Math.round(x + (NX - 1) / 2), 0, NX - 1);
const iz = THREE.MathUtils.clamp(Math.round(z + (NZ - 1) / 2), 0, NZ - 1);
const cell = cellMap.get(keyFor(ix, iz));
return cell ? (cell.pool ? -0.06 : cell.top) : 0.1;
}
function nearestLand(x, z) {
let best = null;
let bestDistance = Infinity;
for (const cell of landCells) {
const dx = cell.x - x;
const dz = cell.z - z;
const distance = dx * dx + dz * dz;
if (distance < bestDistance) {
bestDistance = distance;
best = cell;
}
}
return best;
}
// Shallow-water glints, all made from thin voxel strips.
const glintMaterial = new THREE.MeshBasicMaterial({
color: 0xd8f1ec,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const glints = [];
for (let i = 0; i < 19; i++) {
const cell = poolCells[Math.floor(hash(i + 4, 3) * poolCells.length)];
const glint = new THREE.Mesh(boxGeometry, glintMaterial);
const length = 0.18 + hash(i, 8) * 0.34;
glint.scale.set(length, 0.012, 0.045);
glint.position.set(cell.x, -0.053, cell.z);
glint.userData.baseX = cell.x;
glint.userData.phase = hash(i, 12) * Math.PI * 2;
glint.userData.baseScale = length;
glint.renderOrder = 3;
scene.add(glint);
glints.push(glint);
}
// Small mud clods and stones.
const pebbleMaterials = [
new THREE.MeshStandardMaterial({ color: 0x70523e, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x947052, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x82786a, roughness: 0.92 })
];
for (let i = 0; i < 48; i++) {
const cell = landCells[Math.floor(hash(i + 17, 31) * landCells.length)];
const size = 0.07 + hash(i, 29) * 0.18;
const pebble = block(
scene,
pebbleMaterials[i % pebbleMaterials.length],
size,
size * (0.45 + hash(i, 2) * 0.6),
size * (0.7 + hash(i, 4)),
cell.x,
cell.top + size * 0.22,
cell.z
);
pebble.rotation.y = hash(i, 6) * Math.PI;
}
// ------------------------------------------------------------
// Reed clusters
// ------------------------------------------------------------
const reedMaterials = {
stem: new THREE.MeshStandardMaterial({ color: 0x58744c, roughness: 0.92 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x71895a, roughness: 0.92 }),
dark: new THREE.MeshStandardMaterial({ color: 0x405f40, roughness: 0.95 }),
head: new THREE.MeshStandardMaterial({ color: 0x765039, roughness: 1 })
};
const reedClusters = [];
const clusterPositions = [
[-11.4, 1.8],
[-9.0, 7.1],
[-4.2, 5.6],
[0.0, 6.0],
[3.0, 7.4],
[8.1, 2.9],
[11.3, -1.7],
[12.1, -6.6],
[6.2, -7.5],
[-0.7, -8.7],
[-8.2, -6.5],
[-12.2, -4.7],
[2.4, -2.4]
];
clusterPositions.forEach(([cx, cz], clusterIndex) => {
const group = new THREE.Group();
scene.add(group);
const count = 7 + Math.floor(hash(clusterIndex, 4) * 7);
for (let i = 0; i < count; i++) {
const ox = (hash(clusterIndex * 31 + i, 9) - 0.5) * 1.65;
const oz = (hash(clusterIndex * 17 + i, 22) - 0.5) * 1.45;
const wx = cx + ox;
const wz = cz + oz;
const base = surfaceAt(wx, wz);
const height = 0.8 + hash(i + clusterIndex * 9, 31) * 1.45;
const stem = block(
group,
i % 4 === 0 ? reedMaterials.dark : reedMaterials.stem,
0.052,
height,
0.052,
ox,
base + height / 2,
oz
);
stem.rotation.z = (hash(i, 3) - 0.5) * 0.07;
const leafHeight = height * (0.3 + hash(i, 6) * 0.18);
const leaf = block(
group,
reedMaterials.leaf,
0.055,
leafHeight,
0.095,
ox + (i % 2 ? 0.11 : -0.11),
base + height * (0.44 + hash(i, 8) * 0.17),
oz
);
leaf.rotation.z = i % 2 ? -0.62 : 0.62;
if (i % 4 === 0) {
block(
group,
reedMaterials.head,
0.11,
0.27,
0.11,
ox,
base + height + 0.09,
oz
);
}
}
reedClusters.push({
group,
phase: hash(clusterIndex, 18) * Math.PI * 2
});
});
// ------------------------------------------------------------
// Voxel birds
// ------------------------------------------------------------
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x151817,
roughness: 0.7
});
const birdMaterials = {
heron: {
body: new THREE.MeshStandardMaterial({ color: 0xd8d9c9, roughness: 0.9 }),
wing: new THREE.MeshStandardMaterial({ color: 0x75868a, roughness: 0.92 }),
neck: new THREE.MeshStandardMaterial({ color: 0xe6e4d7, roughness: 0.92 }),
head: new THREE.MeshStandardMaterial({ color: 0xe5e3d7, roughness: 0.92 }),
beak: new THREE.MeshStandardMaterial({ color: 0xe2a447, roughness: 0.82 }),
legs: new THREE.MeshStandardMaterial({ color: 0x69664e, roughness: 0.88 })
},
duck: {
body: new THREE.MeshStandardMaterial({ color: 0x745d43, roughness: 0.94 }),
wing: new THREE.MeshStandardMaterial({ color: 0x907553, roughness: 0.92 }),
neck: new THREE.MeshStandardMaterial({ color: 0x28534c, roughness: 0.92 }),
head: new THREE.MeshStandardMaterial({ color: 0x315f58, roughness: 0.9 }),
beak: new THREE.MeshStandardMaterial({ color: 0xc59b4a, roughness: 0.8 }),
legs: new THREE.MeshStandardMaterial({ color: 0xa87836, roughness: 0.88 })
},
shore: {
body: new THREE.MeshStandardMaterial({ color: 0xa38868, roughness: 0.94 }),
wing: new THREE.MeshStandardMaterial({ color: 0x78664e, roughness: 0.92 }),
neck: new THREE.MeshStandardMaterial({ color: 0xb89a74, roughness: 0.92 }),
head: new THREE.MeshStandardMaterial({ color: 0xa98e6e, roughness: 0.92 }),
beak: new THREE.MeshStandardMaterial({ color: 0x363d38, roughness: 0.82 }),
legs: new THREE.MeshStandardMaterial({ color: 0xb67b48, roughness: 0.88 })
}
};
function makeBird(type) {
const material = birdMaterials[type];
const group = new THREE.Group();
let bodyW;
let bodyH;
let bodyD;
let bodyY;
let neckH;
let headW;
let beakLen;
if (type === "heron") {
bodyW = 0.52;
bodyH = 0.34;
bodyD = 0.72;
bodyY = 0.68;
neckH = 0.88;
headW = 0.23;
beakLen = 0.56;
} else if (type === "duck") {
bodyW = 0.72;
bodyH = 0.4;
bodyD = 0.96;
bodyY = 0.38;
neckH = 0.18;
headW = 0.38;
beakLen = 0.34;
} else {
bodyW = 0.34;
bodyH = 0.24;
bodyD = 0.48;
bodyY = 0.34;
neckH = 0.27;
headW = 0.2;
beakLen = 0.29;
}
block(group, material.body, bodyW, bodyH, bodyD, 0, bodyY, 0);
block(
group,
material.wing,
bodyW * 0.55,
bodyH * 0.55,
bodyD * 0.45,
0,
bodyY + bodyH * 0.32,
-bodyD * 0.48
);
const headPivot = new THREE.Group();
headPivot.position.set(0, bodyY + bodyH * 0.43, bodyD * 0.34);
group.add(headPivot);
block(
headPivot,
material.neck,
type === "heron" ? 0.13 : type === "duck" ? 0.3 : 0.12,
neckH,
type === "heron" ? 0.13 : type === "duck" ? 0.28 : 0.12,
0,
neckH * 0.47,
0
);
block(
headPivot,
material.head,
headW,
headW * 0.82,
headW,
0,
neckH + headW * 0.12,
0.02
);
block(
headPivot,
material.beak,
type === "heron" ? 0.075 : 0.12,
type === "heron" ? 0.065 : 0.09,
beakLen,
0,
neckH + headW * 0.1,
headW * 0.45 + beakLen * 0.48
);
block(
headPivot,
eyeMaterial,
0.035,
0.05,
0.05,
headW * 0.52,
neckH + headW * 0.18,
0.07
);
block(
headPivot,
eyeMaterial,
0.035,
0.05,
0.05,
-headW * 0.52,
neckH + headW * 0.18,
0.07
);
const leftWingPivot = new THREE.Group();
const rightWingPivot = new THREE.Group();
leftWingPivot.position.set(-bodyW * 0.5, bodyY, -0.02);
rightWingPivot.position.set(bodyW * 0.5, bodyY, -0.02);
group.add(leftWingPivot, rightWingPivot);
block(
leftWingPivot,
material.wing,
0.085,
bodyH * 0.72,
bodyD * 0.78,
-bodyW * 0.23,
0,
0
);
block(
rightWingPivot,
material.wing,
0.085,
bodyH * 0.72,
bodyD * 0.78,
bodyW * 0.23,
0,
0
);
const legs = [];
const legHeight = type === "heron" ? 0.64 : type === "shore" ? 0.29 : 0.16;
for (const side of [-1, 1]) {
const leg = block(
group,
material.legs,
0.038,
legHeight,
0.038,
side * bodyW * 0.22,
legHeight * 0.5,
0.03
);
block(
group,
material.legs,
0.11,
0.028,
0.16,
side * bodyW * 0.22,
0.014,
0.09
);
legs.push(leg);
}
return {
group,
headPivot,
leftWingPivot,
rightWingPivot,
legs
};
}
// ------------------------------------------------------------
// Mixed resting flock
// ------------------------------------------------------------
const staticBirds = [];
const staticSpecs = [
["heron", -3.2, 1.4],
["shore", -2.4, 2.9],
["shore", -0.7, 1.1],
["duck", 2.8, 2.6],
["shore", 3.5, 1.8],
["heron", 6.3, 0.2],
["duck", 9.6, -1.5],
["shore", -5.6, -1.6],
["heron", -9.1, -5.5],
["shore", 3.0, -7.8],
["duck", -4.1, 6.2],
["heron", 11.0, -6.7],
["shore", 7.0, 3.8],
["shore", -10.2, 2.8]
];
staticSpecs.forEach(([type, x, z], index) => {
const bird = makeBird(type);
const cell = nearestLand(x, z);
const scale = type === "heron" ? 1 : type === "duck" ? 0.92 : 0.82;
bird.group.scale.setScalar(scale);
bird.group.position.set(cell.x, cell.top + 0.012, cell.z);
bird.group.rotation.y = hash(index + 2, 9) * Math.PI * 2;
if (index % 3 === 1) bird.legs[1].visible = false;
scene.add(bird.group);
staticBirds.push({
...bird,
baseY: bird.group.position.y,
phase: hash(index, 21) * Math.PI * 2,
peckOffset: hash(index, 7) * 5
});
});
// ------------------------------------------------------------
// Arrival / rest / departure travelers
// ------------------------------------------------------------
const CYCLE = 32;
const ARRIVAL_END = 5.5;
const DEPARTURE_START = 22;
const DEPARTURE_END = 27.5;
const travelerSpecs = [
{ type: "shore", x: -1.0, z: 2.8, offset: 0 },
{ type: "heron", x: 7.2, z: 0.8, offset: 7 },
{ type: "duck", x: -5.0, z: -1.8, offset: 14 },
{ type: "shore", x: 10.2, z: 4.0, offset: 21 }
];
const travelers = travelerSpecs.map((spec, index) => {
const bird = makeBird(spec.type);
const cell = nearestLand(spec.x, spec.z);
const scale = spec.type === "heron" ? 1 : spec.type === "duck" ? 0.92 : 0.82;
const target = new THREE.Vector3(cell.x, cell.top + 0.012, cell.z);
bird.group.scale.setScalar(scale);
bird.group.visible = false;
scene.add(bird.group);
const arrivalStart = target.clone().add(new THREE.Vector3(-12, 6, 7));
const arrivalControl1 = arrivalStart.clone().add(new THREE.Vector3(3, -1, 1));
const arrivalControl2 = target.clone().add(new THREE.Vector3(-4, 1, -2));
const departureControl1 = target.clone().add(new THREE.Vector3(3, 1, -2));
const departureControl2 = target.clone().add(new THREE.Vector3(7, 4, -6));
const departureEnd = target.clone().add(new THREE.Vector3(12, 7, -10));
return {
...bird,
index,
offset: spec.offset,
target,
arrivalStart,
arrivalControl1,
arrivalControl2,
departureControl1,
departureControl2,
departureEnd,
landingHeading: Math.atan2(4, -2)
};
});
function cubicBezier(a, b, c, d, t) {
const u = 1 - t;
return new THREE.Vector3()
.addScaledVector(a, u * u * u)
.addScaledVector(b, 3 * u * u * t)
.addScaledVector(c, 3 * u * t * t)
.addScaledVector(d, t * t * t);
}
function setWings(bird, amount) {
bird.leftWingPivot.rotation.z = amount;
bird.rightWingPivot.rotation.z = -amount;
}
function updateTravelers(time) {
for (const bird of travelers) {
const local = (time + bird.offset) % CYCLE;
if (local >= ARRIVAL_END && local < DEPARTURE_START) {
bird.group.visible = true;
bird.group.position.copy(bird.target);
bird.group.rotation.set(0, bird.landingHeading, 0);
const peck =
Math.pow(Math.max(0, Math.sin(time * 0.63 + bird.index)), 10) * 0.72;
bird.headPivot.rotation.x = peck;
setWings(bird, 0.07);
} else if (local < ARRIVAL_END) {
const t = local / ARRIVAL_END;
const eased = t * t * (3 - 2 * t);
const position = cubicBezier(
bird.arrivalStart,
bird.arrivalControl1,
bird.arrivalControl2,
bird.target,
eased
);
const ahead = cubicBezier(
bird.arrivalStart,
bird.arrivalControl1,
bird.arrivalControl2,
bird.target,
Math.min(1, eased + 0.012)
);
const tangent = ahead.sub(position).normalize();
bird.group.visible = true;
bird.group.position.copy(position);
bird.group.lookAt(position.clone().add(tangent));
bird.group.rotateZ(Math.sin(time * 4 + bird.index) * 0.05);
bird.headPivot.rotation.x = -0.12;
setWings(bird, Math.sin(time * 18 + bird.index) * 0.62);
} else if (local >= DEPARTURE_START && local < DEPARTURE_END) {
const t = (local - DEPARTURE_START) / (DEPARTURE_END - DEPARTURE_START);
const eased = t * t * (3 - 2 * t);
const position = cubicBezier(
bird.target,
bird.departureControl1,
bird.departureControl2,
bird.departureEnd,
eased
);
const ahead = cubicBezier(
bird.target,
bird.departureControl1,
bird.departureControl2,
bird.departureEnd,
Math.min(1, eased + 0.012)
);
const tangent = ahead.sub(position).normalize();
bird.group.visible = true;
bird.group.position.copy(position);
bird.group.lookAt(position.clone().add(tangent));
bird.group.rotateZ(Math.sin(time * 5 + bird.index) * 0.07);
bird.headPivot.rotation.x = -0.08;
setWings(bird, Math.sin(time * 20 + bird.index) * 0.66);
} else {
bird.group.visible = false;
}
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard
// ------------------------------------------------------------
const orbit = {
theta: 0.73,
targetTheta: 0.73,
phi: 1.03,
targetPhi: 1.03,
radius: 27,
targetRadius: 27,
target: new THREE.Vector3(0, 0.25, 0)
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(
orbit.targetPhi - dy * 0.005,
0.38,
1.43
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius * Math.exp(event.deltaY * 0.001),
15,
42
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") orbit.targetTheta -= 0.12;
if (event.key === "ArrowRight") orbit.targetTheta += 0.12;
if (event.key === "ArrowUp") orbit.targetPhi = Math.max(0.38, orbit.targetPhi - 0.08);
if (event.key === "ArrowDown") orbit.targetPhi = Math.min(1.43, orbit.targetPhi + 0.08);
if (event.key.toLowerCase() === "r") {
orbit.targetTheta = 0.73;
orbit.targetPhi = 1.03;
orbit.targetRadius = 27;
}
});
function updateCamera() {
orbit.theta += (orbit.targetTheta - orbit.theta) * 0.12;
orbit.phi += (orbit.targetPhi - orbit.phi) * 0.12;
orbit.radius += (orbit.targetRadius - orbit.radius) * 0.1;
const horizontal = orbit.radius * Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
// ------------------------------------------------------------
// UI and labels
// ------------------------------------------------------------
const phaseLabel = document.getElementById("phaseLabel");
const phaseClock = document.getElementById("phaseClock");
const timelineFill = document.getElementById("timelineFill");
const toggleButton = document.getElementById("toggle");
const replayButton = document.getElementById("replay");
let paused = false;
let simulationTime = 0;
toggleButton.addEventListener("click", () => {
paused = !paused;
toggleButton.textContent = paused ? "Resume motion" : "Pause motion";
});
replayButton.addEventListener("click", () => {
simulationTime = 0;
paused = false;
toggleButton.textContent = "Pause motion";
});
const labels = [
{
element: document.getElementById("reedLabel"),
position: new THREE.Vector3(-9.2, 1.35, 6.0)
},
{
element: document.getElementById("poolLabel"),
position: new THREE.Vector3(5.0, 0.28, -4.0)
},
{
element: document.getElementById("flockLabel"),
position: new THREE.Vector3(0.0, 0.9, 1.8)
}
];
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function updateStatus() {
const local = simulationTime % CYCLE;
const seconds = Math.floor(local);
const progress = (local / CYCLE) * 100;
timelineFill.style.width = `${progress}%`;
phaseClock.textContent = `00:${String(seconds).padStart(2, "0")} / 00:32`;
if (local < ARRIVAL_END) {
phaseLabel.textContent = "Arriving · landing on the mudflat";
} else if (local < DEPARTURE_START) {
phaseLabel.textContent = "Resting · temporary stopover";
} else if (local < DEPARTURE_END) {
phaseLabel.textContent = "Departing · beginning the next leg";
} else {
phaseLabel.textContent = "Pause · regrouping before departure";
}
}
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) simulationTime += delta;
updateCamera();
for (const bird of staticBirds) {
bird.group.position.y =
bird.baseY + Math.sin(simulationTime * 1.35 + bird.phase) * 0.008;
const peck =
Math.pow(
Math.max(
0,
Math.sin(simulationTime * 0.57 + bird.peckOffset)
),
10
) * 0.62;
bird.headPivot.rotation.x = peck;
bird.group.rotation.z =
Math.sin(simulationTime * 0.8 + bird.phase) * 0.012;
}
updateTravelers(simulationTime);
for (const reed of reedClusters) {
reed.group.rotation.z =
Math.sin(simulationTime * 0.72 + reed.phase) * 0.009;
reed.group.rotation.x =
Math.sin(simulationTime * 0.54 + reed.phase * 0.7) * 0.006;
}
for (const glint of glints) {
glint.position.x =
glint.userData.baseX +
Math.sin(simulationTime * 0.42 + glint.userData.phase) * 0.075;
glint.scale.x =
glint.userData.baseScale *
(0.78 + Math.sin(simulationTime * 0.55 + glint.userData.phase) * 0.22);
}
updateStatus();
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
animate();
</script>
</body>
</html>
```