Prompt specification
Build or customize the Three.js 3D scene "Meander bank profile block" 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: Meander bank profile block
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/meander-bank-profile-block-x1173
Scene Description Prompt:
A low-poly riverbend cutaway contrasts its steep outer bank and gentle inner sediment bar. One HTML file using Three.js from cdnjs.
Working Three.js Starter (meander-bank-profile-block-x1173):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Riverbend Cutaway</title>
<style>
:root {
--ink: #26342f;
--muted: #66736b;
--paper: rgba(248, 245, 236, 0.92);
--line: rgba(48, 62, 54, 0.2);
--water: #55a9b6;
--sand: #d6ad65;
--erosion: #a76042;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: absolute;
z-index: 4;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 30px rgba(50, 45, 35, 0.1);
backdrop-filter: blur(10px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 18px;
height: 2px;
background: var(--erosion);
content: "";
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3.2vw, 39px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
bottom: 22px;
left: 22px;
padding: 13px 15px;
border-radius: 4px;
}
.legend-title {
margin-bottom: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 6px;
font-size: 11px;
font-weight: 650;
}
.swatch {
width: 19px;
height: 7px;
border-radius: 1px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.water {
background: var(--water);
}
.swatch.sand {
background: var(--sand);
}
.swatch.erosion {
background: var(--erosion);
}
.controls {
right: 22px;
bottom: 22px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 4px;
}
button {
border: 1px solid var(--line);
border-radius: 2px;
padding: 8px 11px;
background: rgba(255, 255, 255, 0.54);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition:
background 150ms ease,
color 150ms ease;
}
button:hover,
button.active {
background: var(--ink);
color: #fffdf5;
}
.hint {
position: absolute;
z-index: 3;
right: 23px;
bottom: 73px;
color: rgba(38, 52, 47, 0.65);
font-size: 10px;
letter-spacing: 0.025em;
pointer-events: none;
}
#leaders {
position: absolute;
z-index: 5;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders polyline {
fill: none;
stroke: rgba(44, 57, 50, 0.66);
stroke-width: 1.2;
stroke-linejoin: round;
}
#leaders circle {
fill: #fffaf0;
stroke: rgba(44, 57, 50, 0.78);
stroke-width: 1.5;
}
#annotations {
position: absolute;
z-index: 6;
inset: 0;
pointer-events: none;
transition: opacity 160ms ease;
}
#annotations.hidden {
opacity: 0;
}
.callout {
position: absolute;
width: 196px;
padding: 11px 12px 10px;
border: 1px solid rgba(48, 62, 54, 0.22);
border-left: 4px solid var(--erosion);
border-radius: 3px;
background: rgba(250, 247, 237, 0.95);
box-shadow: 0 10px 25px rgba(50, 45, 35, 0.14);
transform: translateZ(0);
}
.callout.deposition {
border-left-color: var(--sand);
}
.callout h2 {
margin: 0 0 5px;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.callout p {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.scale-note {
position: absolute;
z-index: 3;
top: 25px;
right: 25px;
color: rgba(38, 52, 47, 0.55);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.title-panel .subtitle {
display: none;
}
.legend {
bottom: 12px;
left: 12px;
padding: 10px 12px;
}
.legend-title {
display: none;
}
.legend-row {
font-size: 9px;
}
.controls {
right: 12px;
bottom: 12px;
}
button {
padding: 8px;
font-size: 8px;
}
.hint,
.scale-note {
display: none;
}
.callout {
width: 155px;
padding: 9px 10px;
}
.callout h2 {
font-size: 9px;
}
.callout p {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<svg id="leaders" aria-hidden="true">
<polyline id="outer-leader"></polyline>
<polyline id="inner-leader"></polyline>
<circle id="outer-dot" r="4"></circle>
<circle id="inner-dot" r="4"></circle>
</svg>
<div id="annotations">
<div id="outer-callout" class="callout">
<h2>Steep outer bank</h2>
<p>Fast water undercuts the exposed bank, maintaining a steep erosion face.</p>
</div>
<div id="inner-callout" class="callout deposition">
<h2>Gentle inner bar</h2>
<p>Slower water deposits sand and silt, building a low, gently sloping bar.</p>
</div>
</div>
<header class="panel title-panel">
<div class="eyebrow">Fluvial landform study</div>
<h1>Riverbend cutaway</h1>
<p class="subtitle">
Erosion on the outer bend contrasts with sediment deposition on the inner bend.
</p>
</header>
<div class="panel legend">
<div class="legend-title">Material key</div>
<div class="legend-row">
<span class="swatch water"></span>
Active channel
</div>
<div class="legend-row">
<span class="swatch sand"></span>
Deposited sediment
</div>
<div class="legend-row">
<span class="swatch erosion"></span>
Eroded bank
</div>
</div>
<div class="hint">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
<div class="scale-note">Schematic · Not to scale</div>
<div class="panel controls">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-labels" class="active" type="button">Labels</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const host = document.getElementById("scene");
const scene = new THREE.Scene();
const backgroundColor = 0xe8e1d4;
scene.background = new THREE.Color(backgroundColor);
scene.fog = new THREE.Fog(backgroundColor, 29, 53);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.02;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraState = {
target: new THREE.Vector3(0, -0.45, 0),
radius: 25,
theta: 0.73,
phi: 1.02,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xfff4dc, 0x596970, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d0, 3.1);
sun.position.set(-9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7d5dc, 0.8);
fill.position.set(10, 7, -10);
scene.add(fill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xe8e1d4,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -3.24;
ground.receiveShadow = true;
scene.add(ground);
const model = new THREE.Group();
scene.add(model);
// -------------------------------------------------------------------------
// River geometry helpers
// -------------------------------------------------------------------------
const WIDTH = 16;
const DEPTH = 13;
const NX = 40;
const NZ = 34;
const BEND_Z = -2.45;
const WATER_LEVEL = 0.16;
function riverCenter(z) {
return 2.25 * Math.sin((z + 0.1) * 0.52);
}
function riverDerivative(z) {
return 2.25 * 0.52 * Math.cos((z + 0.1) * 0.52);
}
function riverSpread(z) {
return Math.sqrt(1 + Math.pow(riverDerivative(z), 2));
}
function signedRiverDistance(x, z) {
return (x - riverCenter(z)) / riverSpread(z);
}
function bendWeight(z) {
const normalized = Math.abs(z - BEND_Z) / 3.35;
return Math.exp(-Math.pow(normalized, 4));
}
function rawTerrainHeight(x, z) {
const d = signedRiverDistance(x, z);
const bend = bendWeight(z);
const outerHalfWidth = 1.48;
const innerEdge = 1.06;
let h;
if (d < -outerHalfWidth) {
const outerDistance = -d - outerHalfWidth;
const steepness = THREE.MathUtils.lerp(0.78, 0.22, bend);
h =
-0.84 +
2.08 *
(1 - Math.exp(-outerDistance / steepness));
} else if (d <= innerEdge) {
const ratio = (d + outerHalfWidth) / (outerHalfWidth + innerEdge);
h =
-0.84 +
0.08 * ratio +
0.018 * Math.sin(z * 1.7 + x * 0.9);
} else {
const innerDistance = d - innerEdge;
const barWidth = THREE.MathUtils.lerp(1.55, 2.15, bend);
h =
-0.76 +
1.85 *
(1 - Math.exp(-innerDistance / barWidth));
const barMound =
0.42 *
bend *
Math.exp(-Math.pow((d - 1.8) / 0.65, 2));
h += barMound;
}
if (d > 3.1) {
h +=
0.035 * Math.sin(x * 1.3 + z * 0.75) +
0.018 * Math.cos(x * 0.7 - z * 1.45);
}
return Math.round(h * 24) / 24;
}
function terrainHeight(x, z) {
return rawTerrainHeight(x, z);
}
function pointAtRiverOffset(offset, z) {
const x = riverCenter(z) + offset * riverSpread(z);
return new THREE.Vector3(x, terrainHeight(x, z), z);
}
let randomSeed = 91237;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function terrainColor(x, z, height) {
const d = signedRiverDistance(x, z);
const bend = bendWeight(z);
let hex;
if (height < -0.12) {
hex = d > 0 ? 0x9b8058 : 0x626558;
} else if (d > 1.3 && d < 3.6 && bend > 0.16) {
hex = 0xd4aa63;
} else if (d < -1.4 && bend > 0.18) {
hex = 0x8d6045;
} else if (height > 0.92) {
hex = 0x78955c;
} else {
hex = 0x9a9368;
}
const color = new THREE.Color(hex);
color.multiplyScalar(0.92 + random() * 0.14);
return color;
}
function pushTriangle(array, colors, a, b, c, color) {
array.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
function terrainPoint(x, z) {
return new THREE.Vector3(x, terrainHeight(x, z), z);
}
// -------------------------------------------------------------------------
// Faceted terrain surface
// -------------------------------------------------------------------------
function buildTerrain() {
const positions = [];
const colors = [];
const dx = WIDTH / NX;
const dz = DEPTH / NZ;
for (let ix = 0; ix < NX; ix++) {
for (let iz = 0; iz < NZ; iz++) {
const x0 = -WIDTH / 2 + ix * dx;
const x1 = x0 + dx;
const z0 = -DEPTH / 2 + iz * dz;
const z1 = z0 + dz;
const p00 = terrainPoint(x0, z0);
const p10 = terrainPoint(x1, z0);
const p01 = terrainPoint(x0, z1);
const p11 = terrainPoint(x1, z1);
const cx = (x0 + x1) * 0.5;
const cz = (z0 + z1) * 0.5;
const cy = (p00.y + p10.y + p01.y + p11.y) * 0.25;
const color = terrainColor(cx, cz, cy);
if ((ix + iz) % 2 === 0) {
pushTriangle(positions, colors, p00, p01, p11, color);
pushTriangle(positions, colors, p00, p11, p10, color);
} else {
pushTriangle(positions, colors, p00, p01, p10, color);
pushTriangle(positions, colors, p10, p01, p11, color);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
model.add(mesh);
}
buildTerrain();
// -------------------------------------------------------------------------
// Cutaway walls and geological strata
// -------------------------------------------------------------------------
function boundaryPoints() {
const points = [];
const dx = WIDTH / NX;
const dz = DEPTH / NZ;
for (let i = 0; i <= NX; i++) {
const x = -WIDTH / 2 + i * dx;
points.push(terrainPoint(x, DEPTH / 2));
}
for (let j = 1; j <= NZ; j++) {
const z = DEPTH / 2 - j * dz;
points.push(terrainPoint(WIDTH / 2, z));
}
for (let i = NX - 1; i >= 0; i--) {
const x = -WIDTH / 2 + i * dx;
points.push(terrainPoint(x, -DEPTH / 2));
}
for (let j = NZ - 1; j >= 1; j--) {
const z = -DEPTH / 2 + j * dz;
points.push(terrainPoint(-WIDTH / 2, z));
}
return points;
}
function strataColor(y, segment) {
let hex;
if (y < -1.95) {
hex = 0x59676c;
} else if (y < -1.05) {
hex = 0x827769;
} else if (y < -0.48) {
hex = 0xb17d52;
} else if (y < 0.17) {
hex = 0xd0a466;
} else {
hex = 0x926849;
}
const color = new THREE.Color(hex);
color.multiplyScalar(0.94 + ((segment * 0.173) % 1) * 0.1);
return color;
}
function buildWalls() {
const positions = [];
const colors = [];
const points = boundaryPoints();
const baseY = -3.05;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const levels = [baseY];
const fixedLevels = [-2.25, -1.35, -0.55, 0.15];
for (const level of fixedLevels) {
if (level > baseY && level < Math.min(a.y, b.y)) {
levels.push(level);
}
}
levels.push(a.y, b.y);
levels.sort((p, q) => p - q);
const uniqueLevels = levels.filter(
(level, index) =>
index === 0 || Math.abs(level - levels[index - 1]) > 0.001
);
for (let j = 0; j < uniqueLevels.length - 1; j++) {
const lower = uniqueLevels[j];
const upper = uniqueLevels[j + 1];
const middle = (lower + upper) * 0.5;
const color = strataColor(middle, i);
const a0 = new THREE.Vector3(a.x, lower, a.z);
const b0 = new THREE.Vector3(b.x, lower, b.z);
const b1 = new THREE.Vector3(b.x, upper, b.z);
const a1 = new THREE.Vector3(a.x, upper, a.z);
pushTriangle(positions, colors, a0, b0, b1, color);
pushTriangle(positions, colors, a0, b1, a1, color);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
});
const walls = new THREE.Mesh(geometry, material);
walls.castShadow = true;
walls.receiveShadow = true;
model.add(walls);
const outlinePoints = points.map(
(point) => new THREE.Vector3(point.x, point.y + 0.018, point.z)
);
outlinePoints.push(outlinePoints[0].clone());
const outline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(outlinePoints),
new THREE.LineBasicMaterial({
color: 0x514a3f,
transparent: true,
opacity: 0.55
})
);
model.add(outline);
}
buildWalls();
const baseSlab = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH + 0.08, 0.16, DEPTH + 0.08),
new THREE.MeshStandardMaterial({
color: 0x555b58,
roughness: 1
})
);
baseSlab.position.y = -3.13;
baseSlab.castShadow = true;
baseSlab.receiveShadow = true;
model.add(baseSlab);
// -------------------------------------------------------------------------
// Water surface, cross-section faces, and current marks
// -------------------------------------------------------------------------
function buildWaterSurface() {
const positions = [];
const rows = 70;
const leftOffset = -1.48;
const rightOffset = 1.08;
function waterPoint(offset, z) {
return new THREE.Vector3(
riverCenter(z) + offset * riverSpread(z),
WATER_LEVEL,
z
);
}
for (let i = 0; i < rows; i++) {
const z0 = -DEPTH / 2 + (i / rows) * DEPTH;
const z1 = -DEPTH / 2 + ((i + 1) / rows) * DEPTH;
const l0 = waterPoint(leftOffset, z0);
const r0 = waterPoint(rightOffset, z0);
const l1 = waterPoint(leftOffset, z1);
const r1 = waterPoint(rightOffset, z1);
positions.push(
l0.x, l0.y, l0.z,
l1.x, l1.y, l1.z,
r0.x, r0.y, r0.z,
r0.x, r0.y, r0.z,
l1.x, l1.y, l1.z,
r1.x, r1.y, r1.z
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: 0x4aa2b2,
transparent: true,
opacity: 0.72,
roughness: 0.25,
metalness: 0.04,
depthWrite: false,
side: THREE.DoubleSide
});
const water = new THREE.Mesh(geometry, material);
water.receiveShadow = true;
water.renderOrder = 2;
model.add(water);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xb7e4e5,
transparent: true,
opacity: 0.62
});
for (const offset of [leftOffset, rightOffset]) {
const edgePoints = [];
for (let i = 0; i <= 80; i++) {
const z = -DEPTH / 2 + (i / 80) * DEPTH;
edgePoints.push(
new THREE.Vector3(
riverCenter(z) + offset * riverSpread(z),
WATER_LEVEL + 0.012,
z
)
);
}
model.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(edgePoints),
edgeMaterial
)
);
}
const capMaterial = new THREE.MeshStandardMaterial({
color: 0x2c8197,
transparent: true,
opacity: 0.72,
roughness: 0.4,
side: THREE.DoubleSide
});
for (const z of [-DEPTH / 2, DEPTH / 2]) {
const xl = riverCenter(z) + leftOffset * riverSpread(z);
const xr = riverCenter(z) + rightOffset * riverSpread(z);
const bottom = -0.94;
const capGeometry = new THREE.BufferGeometry();
capGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
z > 0
? [
xl, bottom, z,
xr, bottom, z,
xr, WATER_LEVEL, z,
xl, bottom, z,
xr, WATER_LEVEL, z,
xl, WATER_LEVEL, z
]
: [
xl, bottom, z,
xr, WATER_LEVEL, z,
xr, bottom, z,
xl, bottom, z,
xl, WATER_LEVEL, z,
xr, WATER_LEVEL, z
],
3
)
);
capGeometry.computeVertexNormals();
const cap = new THREE.Mesh(capGeometry, capMaterial);
cap.renderOrder = 3;
model.add(cap);
}
}
buildWaterSurface();
const currentMaterial = new THREE.LineDashedMaterial({
color: 0xd9f6ef,
transparent: true,
opacity: 0.48,
dashSize: 0.38,
gapSize: 0.28,
depthWrite: false
});
for (const offset of [-0.93, -0.28, 0.42]) {
const points = [];
for (let i = 0; i <= 100; i++) {
const z = -DEPTH / 2 + (i / 100) * DEPTH;
points.push(
new THREE.Vector3(
riverCenter(z) + offset * riverSpread(z),
WATER_LEVEL + 0.025,
z
)
);
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
currentMaterial
);
line.computeLineDistances();
line.renderOrder = 4;
model.add(line);
}
// -------------------------------------------------------------------------
// Low-poly flow arrows
// -------------------------------------------------------------------------
const arrowGeometry = new THREE.ConeGeometry(0.12, 0.4, 3);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xe2f4ed,
roughness: 0.55,
emissive: 0x1e4142,
emissiveIntensity: 0.12
});
const flowArrows = [];
for (let i = 0; i < 6; i++) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.castShadow = true;
arrow.renderOrder = 5;
model.add(arrow);
flowArrows.push(arrow);
}
const upAxis = new THREE.Vector3(0, 1, 0);
const flowDirection = new THREE.Vector3();
function updateFlowArrows(elapsed) {
flowArrows.forEach((arrow, index) => {
const progress = (elapsed * 0.055 + index / flowArrows.length) % 1;
const z = THREE.MathUtils.lerp(-5.8, 5.8, progress);
const x = riverCenter(z);
arrow.position.set(x, WATER_LEVEL + 0.1, z);
flowDirection
.set(riverDerivative(z), 0, 1)
.normalize();
arrow.quaternion.setFromUnitVectors(upAxis, flowDirection);
});
}
// -------------------------------------------------------------------------
// Rocks and sediment details
// -------------------------------------------------------------------------
const rockGeometry = new THREE.DodecahedronGeometry(0.16, 0);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x68594a,
roughness: 1,
flatShading: true
});
const rockCount = 20;
const rocks = new THREE.InstancedMesh(
rockGeometry,
rockMaterial,
rockCount
);
rocks.castShadow = true;
rocks.receiveShadow = true;
const dummy = new THREE.Object3D();
for (let i = 0; i < rockCount; i++) {
const z = BEND_Z + (random() - 0.5) * 3.25;
const offset = -1.73 - random() * 0.48;
const point = pointAtRiverOffset(offset, z);
dummy.position.set(
point.x,
point.y + 0.045,
point.z
);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
const scale = 0.65 + random() * 0.95;
dummy.scale.setScalar(scale);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
}
rocks.instanceMatrix.needsUpdate = true;
model.add(rocks);
const pebbleGeometry = new THREE.DodecahedronGeometry(0.075, 0);
const pebbleMaterial = new THREE.MeshStandardMaterial({
color: 0xe0bd78,
roughness: 1,
flatShading: true
});
const pebbleCount = 28;
const pebbles = new THREE.InstancedMesh(
pebbleGeometry,
pebbleMaterial,
pebbleCount
);
pebbles.castShadow = true;
for (let i = 0; i < pebbleCount; i++) {
const z = BEND_Z + (random() - 0.5) * 3.6;
const offset = 1.55 + random() * 0.75;
const point = pointAtRiverOffset(offset, z);
dummy.position.set(
point.x,
Math.max(point.y, WATER_LEVEL) + 0.035,
point.z
);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
dummy.scale.setScalar(0.7 + random() * 0.7);
dummy.updateMatrix();
pebbles.setMatrixAt(i, dummy.matrix);
}
pebbles.instanceMatrix.needsUpdate = true;
model.add(pebbles);
function buildSurfaceContour(offset, zStart, zEnd, color, opacity) {
const points = [];
for (let i = 0; i <= 80; i++) {
const z = THREE.MathUtils.lerp(zStart, zEnd, i / 80);
const point = pointAtRiverOffset(offset, z);
point.y += 0.018;
points.push(point);
}
return new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
}
model.add(
buildSurfaceContour(
-1.76,
BEND_Z - 1.9,
BEND_Z + 1.9,
0x563d32,
0.62
)
);
model.add(
buildSurfaceContour(
1.67,
BEND_Z - 1.8,
BEND_Z + 1.8,
0xf2d494,
0.76
)
);
// -------------------------------------------------------------------------
// Annotation anchors and scene markers
// -------------------------------------------------------------------------
const outerAnchor = pointAtRiverOffset(-1.72, BEND_Z);
const innerAnchor = pointAtRiverOffset(1.95, BEND_Z);
function createMarker(anchor, color) {
const markerMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.18,
roughness: 0.45
});
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.012, 0.43, 5),
markerMaterial
);
stem.position.set(
anchor.x,
anchor.y + 0.215,
anchor.z
);
model.add(stem);
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 8, 6),
markerMaterial
);
cap.position.set(
anchor.x,
anchor.y + 0.47,
anchor.z
);
model.add(cap);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.022, 5, 18),
markerMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(
anchor.x,
anchor.y + 0.025,
anchor.z
);
model.add(ring);
}
createMarker(outerAnchor, 0xb65f3d);
createMarker(innerAnchor, 0xd8a849);
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
let viewportWidth = 1;
let viewportHeight = 1;
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position
.setFromSpherical(spherical)
.add(cameraState.target);
camera.zoom = cameraState.zoom;
camera.lookAt(cameraState.target);
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
viewportWidth = Math.max(host.clientWidth, 1);
viewportHeight = Math.max(host.clientHeight, 1);
const aspect = viewportWidth / viewportHeight;
const halfHeight = Math.max(8.5, 9.25 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
renderer.setSize(viewportWidth, viewportHeight);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0)
.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1)
.normalize();
const worldPerPixel =
(camera.top - camera.bottom) /
camera.zoom /
viewportHeight;
cameraState.target.addScaledVector(
right,
-dx * worldPerPixel
);
cameraState.target.addScaledVector(
up,
dy * worldPerPixel
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.34,
1.43
);
}
updateCamera();
});
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();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
document.getElementById("reset-view").addEventListener("click", () => {
cameraState.target.set(0, -0.45, 0);
cameraState.theta = 0.73;
cameraState.phi = 1.02;
cameraState.zoom = 1;
updateCamera();
});
const annotations = document.getElementById("annotations");
const leaders = document.getElementById("leaders");
const labelButton = document.getElementById("toggle-labels");
let labelsVisible = true;
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
annotations.classList.toggle("hidden", !labelsVisible);
leaders.style.display = labelsVisible ? "block" : "none";
labelButton.classList.toggle("active", labelsVisible);
});
// -------------------------------------------------------------------------
// Screen-space callout positioning
// -------------------------------------------------------------------------
const annotationDefinitions = [
{
element: document.getElementById("outer-callout"),
line: document.getElementById("outer-leader"),
dot: document.getElementById("outer-dot"),
anchor: outerAnchor,
desktopOffset: [-220, -102],
mobileOffset: [-146, -94],
side: "left"
},
{
element: document.getElementById("inner-callout"),
line: document.getElementById("inner-leader"),
dot: document.getElementById("inner-dot"),
anchor: innerAnchor,
desktopOffset: [76, 58],
mobileOffset: [22, 76],
side: "right"
}
];
function updateAnnotations() {
if (!labelsVisible) return;
for (const definition of annotationDefinitions) {
const projected = definition.anchor.clone().project(camera);
const screenX = (projected.x * 0.5 + 0.5) * viewportWidth;
const screenY = (-projected.y * 0.5 + 0.5) * viewportHeight;
const element = definition.element;
const width = element.offsetWidth || 190;
const height = element.offsetHeight || 70;
const offset =
viewportWidth < 700
? definition.mobileOffset
: definition.desktopOffset;
let left = screenX + offset[0];
let top = screenY + offset[1];
left = THREE.MathUtils.clamp(
left,
12,
viewportWidth - width - 12
);
top = THREE.MathUtils.clamp(
top,
78,
viewportHeight - height - 82
);
element.style.left = `${left}px`;
element.style.top = `${top}px`;
const endpointX =
definition.side === "left"
? left + width
: left;
const endpointY = top + height * 0.5;
const middleX = screenX + (endpointX - screenX) * 0.43;
const middleY = screenY + (endpointY - screenY) * 0.68;
definition.line.setAttribute(
"points",
`${screenX},${screenY} ${middleX},${middleY} ${endpointX},${endpointY}`
);
definition.dot.setAttribute("cx", screenX);
definition.dot.setAttribute("cy", screenY);
}
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
updateFlowArrows(elapsed);
updateAnnotations();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```