Prompt specification
Build or customize the Three.js 3D scene "Amazon river bend with floodplain lake connections" 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: Amazon river bend with floodplain lake connections
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/amazon-river-bend-with-floodplain-lake-connections-x3043
Scene Description Prompt:
Amazon river bend with floodplain lake connections. Build a bounded landscape scene with main channel, side lake, floodplain forest, and higher bank. Use referenced regional forms and clearly simplify distances and vegetation density. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (amazon-river-bend-with-floodplain-lake-connections-x3043):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Amazon Floodplain — Low-Poly Landscape Study</title>
<style>
:root {
--ink: #23382e;
--muted: #66776e;
--paper: rgba(248, 246, 236, 0.91);
--line: rgba(35, 56, 46, 0.15);
--water: #4e9298;
--forest: #496c40;
--terra: #8a8e54;
--bank: #a68f63;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce6df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 18px 48px rgba(35, 56, 46, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#info {
top: 22px;
left: 22px;
width: min(355px, calc(100vw - 44px));
padding: 19px 20px 17px;
border-radius: 15px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: #6a7b70;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 34px);
font-weight: 500;
line-height: 1.03;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 12px;
padding-top: 12px;
border-top: 1px solid var(--line);
font-size: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 11px;
height: 11px;
flex: 0 0 auto;
border: 1px solid rgba(0, 0, 0, 0.09);
border-radius: 2px;
}
.notes {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 13px;
}
.note {
padding: 4px 7px;
border: 1px solid rgba(35, 56, 46, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.34);
color: #69776e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.03em;
}
#controls {
right: 22px;
bottom: 22px;
width: 248px;
padding: 13px;
border-radius: 13px;
}
.button-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
button {
min-height: 34px;
border: 1px solid rgba(35, 56, 46, 0.17);
border-radius: 8px;
background: rgba(255, 255, 255, 0.56);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.9);
transform: translateY(-1px);
}
button[aria-pressed="false"] {
color: #8b958f;
background: rgba(255, 255, 255, 0.28);
}
.control-hint {
margin: 10px 2px 1px;
color: #758279;
font-size: 10px;
line-height: 1.45;
}
#scale-note {
position: fixed;
z-index: 9;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(248, 246, 236, 0.75);
color: #647269;
font-size: 10px;
pointer-events: none;
}
.scale-mark {
position: relative;
width: 42px;
height: 7px;
border-right: 1px solid #57685d;
border-bottom: 1px solid #57685d;
border-left: 1px solid #57685d;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: 118px;
padding: 7px 10px 8px;
border: 1px solid rgba(35, 56, 46, 0.17);
border-radius: 8px;
background: rgba(249, 247, 238, 0.91);
box-shadow: 0 8px 22px rgba(35, 56, 46, 0.12);
transform: translate(-50%, -100%);
white-space: nowrap;
}
.scene-label::after {
position: absolute;
bottom: -13px;
left: 50%;
width: 1px;
height: 12px;
background: rgba(35, 56, 46, 0.45);
content: "";
}
.scene-label strong {
display: block;
color: #31493c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.03em;
}
.scene-label span {
display: block;
margin-top: 2px;
color: #7a857e;
font-size: 8px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #dce6df;
color: #53675b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#info {
top: 12px;
left: 12px;
width: min(310px, calc(100vw - 24px));
padding: 14px 15px;
}
.subtitle {
margin-bottom: 10px;
}
.legend {
grid-template-columns: 1fr;
}
.legend-item:nth-child(n + 4) {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
width: 218px;
}
#scale-note {
display: none;
}
.scene-label {
min-width: 92px;
padding: 5px 7px;
}
.scene-label strong {
font-size: 8px;
}
.scene-label span {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="labels"></div>
<section id="info" class="panel">
<p class="eyebrow">Low-poly geomorphology study</p>
<h1>Amazon river bend</h1>
<p class="subtitle">
A broad meandering channel connects to a side floodplain lake,
seasonally flooded forest, and a higher terra firme bank.
</p>
<div class="legend">
<div class="legend-item">
<i class="swatch" style="background:#4e9298"></i>
Main channel and lake
</div>
<div class="legend-item">
<i class="swatch" style="background:#496c40"></i>
Floodplain / igapó forest
</div>
<div class="legend-item">
<i class="swatch" style="background:#8a8e54"></i>
Higher terra firme
</div>
<div class="legend-item">
<i class="swatch" style="background:#a68f63"></i>
Exposed sediment bank
</div>
</div>
<div class="notes">
<span class="note">Distances compressed</span>
<span class="note">Tree spacing enlarged</span>
<span class="note">Schematic — not to scale</span>
</div>
</section>
<section id="controls" class="panel">
<div class="button-row">
<button id="reset" type="button">Perspective</button>
<button id="top" type="button">Plan view</button>
<button id="labels-toggle" type="button" aria-pressed="true">Labels</button>
</div>
<p class="control-hint">
Drag to rotate · Shift/right-drag to pan · Wheel or pinch to zoom<br>
Arrow keys rotate · + / − zoom
</p>
</section>
<div id="scale-note">
<span class="scale-mark"></span>
<span>Indicative landform spacing only<br>No true map scale</span>
</div>
<div id="loading">Building floodplain…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce6df);
scene.fog = new THREE.Fog(0xdce6df, 105, 205);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
300
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xe9f2ec,
0x6b6048,
2.05
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.15);
sun.position.set(-35, 62, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -70;
sun.shadow.camera.right = 70;
sun.shadow.camera.top = 60;
sun.shadow.camera.bottom = -60;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 145;
sun.shadow.bias = -0.0003;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbad6d5, 0.65);
fill.position.set(40, 20, -45);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared geometry and procedural helpers
// -------------------------------------------------------------------------
const clamp = THREE.MathUtils.clamp;
function smoothstep(a, b, x) {
const t = clamp((x - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function distanceToPolyline(points, x, z) {
let minimum = Infinity;
for (let i = 0; i < points.length - 1; i++) {
const ax = points[i].x;
const az = points[i].z;
const bx = points[i + 1].x;
const bz = points[i + 1].z;
const vx = bx - ax;
const vz = bz - az;
const lengthSquared = vx * vx + vz * vz;
const t = lengthSquared > 0
? clamp(((x - ax) * vx + (z - az) * vz) / lengthSquared, 0, 1)
: 0;
const dx = x - (ax + vx * t);
const dz = z - (az + vz * t);
const distance = dx * dx + dz * dz;
if (distance < minimum) minimum = distance;
}
return Math.sqrt(minimum);
}
function makeRibbon(points, width, y, varyWidth = false) {
const positions = [];
const indices = [];
for (let i = 0; i < points.length; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(points.length - 1, i + 1)];
const tangent = new THREE.Vector3().subVectors(next, previous);
tangent.y = 0;
tangent.normalize();
const normal = new THREE.Vector3(-tangent.z, 0, tangent.x);
const localWidth = width *
(varyWidth ? 1 + 0.075 * Math.sin(i * 0.61) : 1);
const left = points[i].clone().addScaledVector(normal, localWidth * 0.5);
const right = points[i].clone().addScaledVector(normal, -localWidth * 0.5);
positions.push(left.x, y, left.z);
positions.push(right.x, y, right.z);
}
for (let i = 0; i < points.length - 1; i++) {
const a = i * 2;
indices.push(a, a + 2, a + 1);
indices.push(a + 1, a + 2, a + 3);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function mulberry32(seed) {
return function random() {
let value = seed += 0x6D2B79F5;
value = Math.imul(value ^ value >>> 15, value | 1);
value ^= value + Math.imul(value ^ value >>> 7, value | 61);
return ((value ^ value >>> 14) >>> 0) / 4294967296;
};
}
const random = mulberry32(94271);
// -------------------------------------------------------------------------
// Amazonian landform vocabulary, simplified for a bounded schematic scene
// - Main meandering channel
// - Connected floodplain lake
// - Igapó / seasonally flooded forest
// - Higher terra firme bank
// -------------------------------------------------------------------------
const LAND = {
halfWidth: 46,
halfDepth: 31,
waterLevel: 0.5,
lakeX: -19,
lakeZ: -16,
lakeRX: 11.5,
lakeRZ: 7.6
};
function mainChannelZ(x) {
return (
7.0 * Math.sin((x + 4) * 0.105) +
2.8 * Math.sin((x - 9) * 0.22)
);
}
const mainPath = [];
for (let i = 0; i <= 140; i++) {
const x = -52 + (104 * i) / 140;
mainPath.push(new THREE.Vector3(x, 0, mainChannelZ(x)));
}
const connectorCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(LAND.lakeX, 0, LAND.lakeZ),
new THREE.Vector3(-17.3, 0, -11.3),
new THREE.Vector3(-14.8, 0, -7.0),
new THREE.Vector3(-10.0, 0, mainChannelZ(-10))
],
false,
"catmullrom",
0.35
);
const connectorPath = connectorCurve.getPoints(42);
function lakeQ(x, z) {
return Math.hypot(
(x - LAND.lakeX) / LAND.lakeRX,
(z - LAND.lakeZ) / LAND.lakeRZ
);
}
function terrainHeight(x, z) {
let height =
0.62 +
0.18 * Math.sin(x * 0.19) +
0.14 * Math.cos(z * 0.27) +
0.16 * Math.sin((x + z) * 0.11);
// Higher, drier bank toward the back and far right.
height += 5.0 * smoothstep(7, 20, z);
height += 1.2 * smoothstep(18, 44, x);
const riverDistance = distanceToPolyline(mainPath, x, z);
const connectorDistance = distanceToPolyline(connectorPath, x, z);
const q = lakeQ(x, z);
// Broad channel with a low bed and gently rising sediment banks.
if (riverDistance < 7.2) {
const bed = -1.55 +
2.03 * smoothstep(2.8, 4.2, riverDistance) +
0.28 * smoothstep(4.2, 7.2, riverDistance);
height = Math.min(height, bed);
}
// Side lake depression.
if (q < 1.16) {
const bed = -1.65 +
2.13 * smoothstep(0.68, 1.0, q) +
0.32 * smoothstep(1.0, 1.16, q);
height = Math.min(height, bed);
}
// Narrow connecting channel between the lake and main river.
if (connectorDistance < 4.2) {
const bed = -1.4 +
1.88 * smoothstep(0.7, 2.05, connectorDistance) +
0.34 * smoothstep(2.05, 4.2, connectorDistance);
height = Math.min(height, bed);
}
return height;
}
function terrainColor(x, z, height) {
const riverDistance = distanceToPolyline(mainPath, x, z);
const connectorDistance = distanceToPolyline(connectorPath, x, z);
const q = lakeQ(x, z);
let color;
if (
riverDistance < 4.65 ||
q < 1.02 ||
connectorDistance < 2.4
) {
color = new THREE.Color(0x998962);
} else if (height > 3.4) {
color = new THREE.Color(0x85894e);
} else if (z > 5 && height > 1.15) {
color = new THREE.Color(0x93875b);
} else {
color = new THREE.Color(0x5e7b42);
}
const variation = 0.93 + 0.09 *
(0.5 + 0.5 * Math.sin(x * 0.71 + z * 0.43));
color.multiplyScalar(variation);
return color;
}
// -------------------------------------------------------------------------
// Low-poly terrain slab
// -------------------------------------------------------------------------
const gridX = 58;
const gridZ = 40;
const terrainGrid = [];
for (let j = 0; j <= gridZ; j++) {
const row = [];
const z = -LAND.halfDepth + (2 * LAND.halfDepth * j) / gridZ;
// Slightly chamfered footprint keeps the study area visibly bounded.
const rowHalfWidth = LAND.halfWidth -
6.0 * Math.pow(Math.abs(z) / LAND.halfDepth, 8);
for (let i = 0; i <= gridX; i++) {
const u = -1 + (2 * i) / gridX;
const x = u * rowHalfWidth;
row.push({
x,
z,
y: terrainHeight(x, z)
});
}
terrainGrid.push(row);
}
const terrainPositions = [];
const terrainColors = [];
function appendTerrainTriangle(a, b, c) {
const cx = (a.x + b.x + c.x) / 3;
const cz = (a.z + b.z + c.z) / 3;
const cy = (a.y + b.y + c.y) / 3;
const color = terrainColor(cx, cz, cy);
terrainPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let k = 0; k < 3; k++) {
terrainColors.push(color.r, color.g, color.b);
}
}
for (let j = 0; j < gridZ; j++) {
for (let i = 0; i < gridX; i++) {
const a = terrainGrid[j][i];
const b = terrainGrid[j][i + 1];
const c = terrainGrid[j + 1][i];
const d = terrainGrid[j + 1][i + 1];
appendTerrainTriangle(a, c, b);
appendTerrainTriangle(b, c, d);
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 1,
metalness: 0
})
);
terrain.receiveShadow = true;
terrain.castShadow = true;
scene.add(terrain);
// Ordered perimeter for the cut-earth sides and base.
const boundary = [];
for (let i = 0; i <= gridX; i++) {
boundary.push(terrainGrid[0][i]);
}
for (let j = 1; j <= gridZ; j++) {
boundary.push(terrainGrid[j][gridX]);
}
for (let i = gridX - 1; i >= 0; i--) {
boundary.push(terrainGrid[gridZ][i]);
}
for (let j = gridZ - 1; j > 0; j--) {
boundary.push(terrainGrid[j][0]);
}
const wallPositions = [];
for (let i = 0; i < boundary.length; i++) {
const a = boundary[i];
const b = boundary[(i + 1) % boundary.length];
wallPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
a.x, -4.1, a.z,
b.x, b.y, b.z,
b.x, -4.1, b.z,
a.x, -4.1, a.z
);
}
const wallGeometry = new THREE.BufferGeometry();
wallGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(wallPositions, 3)
);
wallGeometry.computeVertexNormals();
const wall = new THREE.Mesh(
wallGeometry,
new THREE.MeshStandardMaterial({
color: 0x654c35,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
wall.receiveShadow = true;
wall.castShadow = true;
scene.add(wall);
const bottomPositions = [];
for (let i = 0; i < boundary.length; i++) {
const a = boundary[i];
const b = boundary[(i + 1) % boundary.length];
bottomPositions.push(
0, -4.1, 0,
b.x, -4.1, b.z,
a.x, -4.1, a.z
);
}
const bottomGeometry = new THREE.BufferGeometry();
bottomGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(bottomPositions, 3)
);
bottomGeometry.computeVertexNormals();
const bottom = new THREE.Mesh(
bottomGeometry,
new THREE.MeshStandardMaterial({
color: 0x4d3b2d,
roughness: 1,
side: THREE.DoubleSide
})
);
scene.add(bottom);
// Subtle strata lines on the exposed block edge.
function addStratum(y, scale, color) {
const points = boundary.map(point =>
new THREE.Vector3(point.x * scale, y, point.z * scale)
);
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.LineLoop(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.42
})
);
scene.add(line);
}
addStratum(-1.25, 0.996, 0xb08352);
addStratum(-2.75, 0.992, 0x9b6843);
const stage = new THREE.Mesh(
new THREE.PlaneGeometry(260, 260),
new THREE.MeshStandardMaterial({
color: 0xd7dfd6,
roughness: 1
})
);
stage.rotation.x = -Math.PI / 2;
stage.position.y = -4.13;
stage.receiveShadow = true;
scene.add(stage);
// -------------------------------------------------------------------------
// Water: main channel, irregular side lake, and connecting channel
// -------------------------------------------------------------------------
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x4d9098,
roughness: 0.28,
metalness: 0.06,
transparent: true,
opacity: 0.9,
depthWrite: false,
side: THREE.DoubleSide
});
const mainWater = new THREE.Mesh(
makeRibbon(mainPath, 4.25, LAND.waterLevel, true),
waterMaterial
);
mainWater.renderOrder = 2;
mainWater.receiveShadow = true;
scene.add(mainWater);
const connectorWater = new THREE.Mesh(
makeRibbon(connectorPath, 2.05, LAND.waterLevel + 0.012),
waterMaterial
);
connectorWater.renderOrder = 2;
scene.add(connectorWater);
function createLakeGeometry() {
const positions = [LAND.lakeX, LAND.waterLevel, LAND.lakeZ];
const indices = [];
const segments = 42;
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const irregularity =
1 +
0.035 * Math.sin(angle * 3 + 0.5) +
0.018 * Math.sin(angle * 5 - 0.8);
const x = LAND.lakeX +
Math.cos(angle) * LAND.lakeRX * irregularity;
const z = LAND.lakeZ +
Math.sin(angle) * LAND.lakeRZ * irregularity;
positions.push(x, LAND.waterLevel, z);
}
for (let i = 0; i < segments; i++) {
const current = i + 1;
const next = (i + 1) % segments + 1;
indices.push(0, next, current);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const lakeWater = new THREE.Mesh(
createLakeGeometry(),
waterMaterial
);
lakeWater.renderOrder = 2;
scene.add(lakeWater);
// Pale current streaks emphasize the schematic flow direction.
const currentMaterial = new THREE.MeshBasicMaterial({
color: 0xb7d8d2,
transparent: true,
opacity: 0.34,
depthWrite: false,
side: THREE.DoubleSide
});
for (const offset of [-1.75, 0.35, 1.8]) {
const currentPath = [];
for (let i = 0; i <= 70; i++) {
const x = -39 + (78 * i) / 70;
currentPath.push(
new THREE.Vector3(x, 0, mainChannelZ(x) + offset)
);
}
const streak = new THREE.Mesh(
makeRibbon(currentPath, 0.09, LAND.waterLevel + 0.045),
currentMaterial
);
streak.renderOrder = 3;
scene.add(streak);
}
// -------------------------------------------------------------------------
// Exposed sediment bars and driftwood
// -------------------------------------------------------------------------
function createSandBar(cx, cz, rx, rz) {
const positions = [cx, 0.78, cz];
const indices = [];
const segments = 18;
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const irregularity = 1 + 0.12 * Math.sin(angle * 3 + 0.9);
positions.push(
cx + Math.cos(angle) * rx * irregularity,
0.465,
cz + Math.sin(angle) * rz * irregularity
);
}
for (let i = 0; i < segments; i++) {
const current = i + 1;
const next = (i + 1) % segments + 1;
indices.push(0, next, current);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0xb7a277,
flatShading: true,
roughness: 1,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
createSandBar(-26.5, -10.6, 2.4, 0.82);
createSandBar(4.5, -1.4, 2.0, 0.72);
createSandBar(27.0, -7.2, 2.5, 0.86);
function addLog(x, z, length, angle) {
const y = terrainHeight(x, z);
const geometry = new THREE.CylinderGeometry(
0.16,
0.24,
length,
6,
1,
false
);
const log = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0x66513a,
flatShading: true,
roughness: 1
})
);
log.position.set(x, y + 0.28, z);
log.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(Math.cos(angle), 0, Math.sin(angle))
);
log.castShadow = true;
log.receiveShadow = true;
scene.add(log);
}
addLog(-10.5, -4.2, 3.8, 0.55);
addLog(14.0, -5.7, 4.6, -0.28);
addLog(-31.0, -11.5, 3.3, 0.95);
addLog(29.0, 3.1, 4.0, 0.15);
// -------------------------------------------------------------------------
// Simplified vegetation distribution
// -------------------------------------------------------------------------
const occupiedTreePositions = [];
function farEnoughFromTrees(x, z, spacing) {
return occupiedTreePositions.every(point =>
Math.hypot(point.x - x, point.z - z) >= spacing
);
}
const trees = [];
// Terra firme trees: broader crowns and greater spacing.
for (let attempt = 0; attempt < 700 && trees.length < 29; attempt++) {
const x = -41 + random() * 82;
const z = 12 + random() * 17;
const y = terrainHeight(x, z);
if (y < 2.1 || !farEnoughFromTrees(x, z, 4.0)) continue;
trees.push({
x,
z,
y,
height: 3.7 + random() * 2.2,
radius: 1.65 + random() * 0.85,
type: "terra"
});
occupiedTreePositions.push({ x, z });
}
// Floodplain trees: smaller, irregular clusters.
for (let attempt = 0; attempt < 1800 && trees.length < 64; attempt++) {
const x = -41 + random() * 82;
const z = -28 + random() * 38;
const y = terrainHeight(x, z);
const riverDistance = distanceToPolyline(mainPath, x, z);
const connectorDistance = distanceToPolyline(connectorPath, x, z);
const q = lakeQ(x, z);
if (y < 0.58 || y > 3.1) continue;
if (riverDistance < 7.7 || connectorDistance < 4.8 || q < 1.24) {
continue;
}
if (!farEnoughFromTrees(x, z, 3.25)) continue;
trees.push({
x,
z,
y,
height: 3.4 + random() * 2.8,
radius: 1.25 + random() * 0.85,
type: "floodplain"
});
occupiedTreePositions.push({ x, z });
}
// Emergent trees at the lake margin: taller trunks, smaller elevated crowns.
for (let attempt = 0; attempt < 700 && trees.length < 75; attempt++) {
const angle = random() * Math.PI * 2;
const q = 0.93 + random() * 0.065;
const x = LAND.lakeX + Math.cos(angle) * LAND.lakeRX * q;
const z = LAND.lakeZ + Math.sin(angle) * LAND.lakeRZ * q;
const y = terrainHeight(x, z);
if (y < -0.75 || !farEnoughFromTrees(x, z, 2.4)) continue;
trees.push({
x,
z,
y,
height: 5.0 + random() * 1.8,
radius: 1.05 + random() * 0.45,
type: "emergent"
});
occupiedTreePositions.push({ x, z });
}
const trunkGeometry = new THREE.CylinderGeometry(
0.22,
0.34,
1,
5,
1,
false
);
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x68513a,
roughness: 1,
flatShading: true
});
const trunkInstances = new THREE.InstancedMesh(
trunkGeometry,
trunkMaterial,
trees.length
);
const canopyGeometry = new THREE.IcosahedronGeometry(1, 0);
const canopyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const canopyInstances = new THREE.InstancedMesh(
canopyGeometry,
canopyMaterial,
trees.length
);
const dummy = new THREE.Object3D();
const canopyPalettes = {
terra: [0x53723c, 0x687c42, 0x768449],
floodplain: [0x345c35, 0x42673a, 0x537744],
emergent: [0x3d653c, 0x4b7042, 0x587a47]
};
trees.forEach((tree, index) => {
dummy.position.set(tree.x, tree.y + tree.height * 0.5, tree.z);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.set(1, tree.height, 1);
dummy.updateMatrix();
trunkInstances.setMatrixAt(index, dummy.matrix);
dummy.position.set(
tree.x + (random() - 0.5) * 0.25,
tree.y + tree.height + tree.radius * 0.2,
tree.z + (random() - 0.5) * 0.25
);
dummy.rotation.set(
(random() - 0.5) * 0.15,
random() * Math.PI,
(random() - 0.5) * 0.15
);
dummy.scale.set(
tree.radius,
tree.radius * (tree.type === "emergent" ? 0.62 : 0.78),
tree.radius
);
dummy.updateMatrix();
canopyInstances.setMatrixAt(index, dummy.matrix);
const palette = canopyPalettes[tree.type];
const color = new THREE.Color(
palette[Math.floor(random() * palette.length)]
);
color.multiplyScalar(0.9 + random() * 0.16);
canopyInstances.setColorAt(index, color);
});
trunkInstances.instanceMatrix.needsUpdate = true;
canopyInstances.instanceMatrix.needsUpdate = true;
canopyInstances.instanceColor.needsUpdate = true;
trunkInstances.castShadow = true;
trunkInstances.receiveShadow = true;
canopyInstances.castShadow = true;
canopyInstances.receiveShadow = true;
trunkInstances.computeBoundingSphere();
canopyInstances.computeBoundingSphere();
scene.add(trunkInstances);
scene.add(canopyInstances);
// Low shrubs on the floodplain.
const shrubs = [];
for (let attempt = 0; attempt < 700 && shrubs.length < 30; attempt++) {
const x = -40 + random() * 80;
const z = -27 + random() * 35;
const y = terrainHeight(x, z);
if (y < 0.58) continue;
if (distanceToPolyline(mainPath, x, z) < 7.3) continue;
if (lakeQ(x, z) < 1.2) continue;
shrubs.push({
x,
z,
y,
radius: 0.38 + random() * 0.48
});
}
const shrubInstances = new THREE.InstancedMesh(
new THREE.IcosahedronGeometry(1, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
flatShading: true,
roughness: 1
}),
shrubs.length
);
shrubs.forEach((shrub, index) => {
dummy.position.set(shrub.x, shrub.y + shrub.radius * 0.6, shrub.z);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.scale.set(
shrub.radius,
shrub.radius * 0.72,
shrub.radius
);
dummy.updateMatrix();
shrubInstances.setMatrixAt(index, dummy.matrix);
shrubInstances.setColorAt(
index,
new THREE.Color(
[0x6b7f43, 0x78894a, 0x607844][index % 3]
)
);
});
shrubInstances.instanceMatrix.needsUpdate = true;
shrubInstances.instanceColor.needsUpdate = true;
shrubInstances.castShadow = true;
scene.add(shrubInstances);
// Sparse emergent reeds around the side lake.
const reeds = [];
for (let i = 0; i < 34; i++) {
const angle = random() * Math.PI * 2;
const q = 0.91 + random() * 0.08;
const x = LAND.lakeX + Math.cos(angle) * LAND.lakeRX * q;
const z = LAND.lakeZ + Math.sin(angle) * LAND.lakeRZ * q;
reeds.push({
x,
z,
y: terrainHeight(x, z),
height: 0.55 + random() * 0.65
});
}
const reedInstances = new THREE.InstancedMesh(
new THREE.ConeGeometry(0.12, 1, 4),
new THREE.MeshStandardMaterial({
color: 0x8b9355,
roughness: 1,
flatShading: true
}),
reeds.length
);
reeds.forEach((reed, index) => {
dummy.position.set(reed.x, reed.y + reed.height * 0.5, reed.z);
dummy.rotation.set(
(random() - 0.5) * 0.13,
random() * Math.PI,
(random() - 0.5) * 0.13
);
dummy.scale.set(1, reed.height, 1);
dummy.updateMatrix();
reedInstances.setMatrixAt(index, dummy.matrix);
});
reedInstances.instanceMatrix.needsUpdate = true;
reedInstances.castShadow = true;
scene.add(reedInstances);
// Sparse rocks on the higher bank.
const rocks = [];
for (let attempt = 0; attempt < 500 && rocks.length < 17; attempt++) {
const x = -40 + random() * 80;
const z = 14 + random() * 14;
const y = terrainHeight(x, z);
if (y < 2.2) continue;
rocks.push({
x,
z,
y,
radius: 0.25 + random() * 0.52
});
}
const rockInstances = new THREE.InstancedMesh(
new THREE.IcosahedronGeometry(1, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
}),
rocks.length
);
rocks.forEach((rock, index) => {
dummy.position.set(rock.x, rock.y + rock.radius * 0.35, rock.z);
dummy.rotation.set(random(), random(), random());
dummy.scale.set(
rock.radius * 1.3,
rock.radius * 0.72,
rock.radius
);
dummy.updateMatrix();
rockInstances.setMatrixAt(index, dummy.matrix);
rockInstances.setColorAt(
index,
new THREE.Color(
[0x77796b, 0x8c8978, 0x686d62][index % 3]
)
);
});
rockInstances.instanceMatrix.needsUpdate = true;
rockInstances.instanceColor.needsUpdate = true;
rockInstances.castShadow = true;
rockInstances.receiveShadow = true;
scene.add(rockInstances);
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelLayer = document.getElementById("labels");
const labelsEnabled = { value: true };
const labelDefinitions = [
{
title: "Amazon main channel",
subtitle: "meandering river",
position: new THREE.Vector3(13, 1.1, mainChannelZ(13)),
offset: [18, -18]
},
{
title: "Side floodplain lake",
subtitle: "connected basin",
position: new THREE.Vector3(LAND.lakeX, 1.0, LAND.lakeZ),
offset: [-4, -18]
},
{
title: "Lake connection",
subtitle: "narrow floodplain channel",
position: new THREE.Vector3(-14.8, 1.1, -7),
offset: [-48, -12]
},
{
title: "Igapó forest",
subtitle: "seasonally flooded woodland",
position: new THREE.Vector3(-3.5, 1.4, -17),
offset: [34, -8]
},
{
title: "Terra firme bank",
subtitle: "higher, drier ground",
position: new THREE.Vector3(28, terrainHeight(28, 22) + 1.5, 22),
offset: [10, -12]
}
];
const labels = labelDefinitions.map(definition => {
const element = document.createElement("div");
element.className = "scene-label";
element.innerHTML = `
<strong>${definition.title}</strong>
<span>${definition.subtitle}</span>
`;
labelLayer.appendChild(element);
return { ...definition, element };
});
function updateLabels() {
if (!labelsEnabled.value) return;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x + label.offset[0]}px`;
label.element.style.top = `${y + label.offset[1]}px`;
}
}
// -------------------------------------------------------------------------
// Custom camera controls — no external controls module
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
radius: 84,
theta: 0.72,
phi: 0.83
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function panCamera(dx, dy) {
const forward = new THREE.Vector3()
.subVectors(cameraState.target, camera.position)
.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const screenUp = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = cameraState.radius * 0.00135;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(screenUp, dy * scale);
cameraState.target.x = clamp(cameraState.target.x, -28, 28);
cameraState.target.z = clamp(cameraState.target.z, -24, 24);
cameraState.target.y = 0;
}
const pointers = new Map();
let gesture = null;
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
event.preventDefault();
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
gesture = {
mode: event.button === 2 || event.shiftKey ? "pan" : "orbit",
lastX: event.clientX,
lastY: event.clientY
};
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
gesture = {
mode: "pinch",
distance: Math.hypot(a.x - b.x, a.y - b.y),
centerX: (a.x + b.x) * 0.5,
centerY: (a.y + b.y) * 0.5
};
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2 && gesture?.mode === "pinch") {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
const centerX = (a.x + b.x) * 0.5;
const centerY = (a.y + b.y) * 0.5;
cameraState.radius = clamp(
cameraState.radius * gesture.distance / Math.max(distance, 1),
28,
145
);
panCamera(centerX - gesture.centerX, centerY - gesture.centerY);
gesture.distance = distance;
gesture.centerX = centerX;
gesture.centerY = centerY;
} else if (pointers.size === 1 && gesture) {
const dx = event.clientX - gesture.lastX;
const dy = event.clientY - gesture.lastY;
if (gesture.mode === "orbit") {
cameraState.theta -= dx * 0.005;
cameraState.phi = clamp(cameraState.phi - dy * 0.004, 0.09, 1.43);
} else {
panCamera(dx, dy);
}
gesture.lastX = event.clientX;
gesture.lastY = event.clientY;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const [remaining] = [...pointers.values()];
gesture = {
mode: "orbit",
lastX: remaining.x,
lastY: remaining.y
};
} else if (pointers.size === 0) {
gesture = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
28,
145
);
updateCamera();
},
{ passive: false }
);
addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraState.theta += 0.08;
else if (key === "arrowright") cameraState.theta -= 0.08;
else if (key === "arrowup") {
cameraState.phi = clamp(cameraState.phi - 0.055, 0.09, 1.43);
} else if (key === "arrowdown") {
cameraState.phi = clamp(cameraState.phi + 0.055, 0.09, 1.43);
} else if (key === "+" || key === "=") {
cameraState.radius = clamp(cameraState.radius * 0.92, 28, 145);
} else if (key === "-") {
cameraState.radius = clamp(cameraState.radius * 1.08, 28, 145);
} else {
return;
}
updateCamera();
});
document.getElementById("reset").addEventListener("click", () => {
cameraState.target.set(0, 0, 0);
cameraState.radius = 84;
cameraState.theta = 0.72;
cameraState.phi = 0.83;
updateCamera();
});
document.getElementById("top").addEventListener("click", () => {
cameraState.target.set(0, 0, 0);
cameraState.radius = 88;
cameraState.theta = 0;
cameraState.phi = 0.09;
updateCamera();
});
const labelsButton = document.getElementById("labels-toggle");
labelsButton.addEventListener("click", () => {
labelsEnabled.value = !labelsEnabled.value;
labelsButton.setAttribute(
"aria-pressed",
String(labelsEnabled.value)
);
if (!labelsEnabled.value) {
labels.forEach(label => {
label.element.style.display = "none";
});
}
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = innerWidth;
const height = innerHeight;
camera.aspect = width / height;
camera.fov = width < 700 ? 52 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(width, height);
}
addEventListener("resize", resize);
resize();
updateCamera();
renderer.render(scene, camera);
document.getElementById("loading").classList.add("hidden");
function animate() {
requestAnimationFrame(animate);
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```