Prompt specification
Build or customize the Three.js 3D scene "Pantanal channel grassland and woodland mosaic" 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: Pantanal channel grassland and woodland mosaic
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pantanal-channel-grassland-and-woodland-mosaic-x3107
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the Pantanal's seasonal wetland mosaic. Build a bounded landscape with shallow channels, grassland, wooded patches, and higher ground. Use a selected documented seasonal setting rather than presenting one static appearance as universal. Voxel style.
Working Three.js Starter (pantanal-channel-grassland-and-woodland-mosaic-x3107):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Pantanal — Seasonal Wetland Mosaic</title>
<style>
:root {
--ink: #24352f;
--muted: #63716a;
--paper: rgba(248, 247, 239, 0.9);
--line: rgba(50, 73, 63, 0.16);
--accent: #497b70;
--dry: #b59b5d;
--wet: #598e9b;
--shadow: 0 16px 50px rgba(34, 48, 42, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7ece4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
summary {
font: inherit;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.7);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(115%);
-webkit-backdrop-filter: blur(16px) saturate(115%);
}
#intro {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 22px 22px 20px;
border-radius: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--accent);
font-size: 0.69rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
background: currentColor;
content: "";
}
h1 {
margin: 0;
max-width: 340px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(1.85rem, 4vw, 2.65rem);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 11px 0 18px;
color: var(--muted);
font-size: 0.84rem;
line-height: 1.55;
}
.setting-label {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
color: var(--muted);
font-size: 0.65rem;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.setting-label span:last-child {
color: #89948e;
font-weight: 600;
letter-spacing: 0;
text-transform: none;
}
.season-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(38, 59, 50, 0.045);
}
.season-button {
min-height: 40px;
padding: 7px 10px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 0.75rem;
font-weight: 700;
transition:
color 180ms ease,
background 180ms ease,
box-shadow 180ms ease;
}
.season-button:hover {
color: var(--ink);
}
.season-button[aria-pressed="true"] {
background: #fffdf7;
color: var(--ink);
box-shadow: 0 2px 8px rgba(38, 56, 47, 0.1);
}
#season-copy {
min-height: 69px;
margin: 12px 1px 0;
color: #52615a;
font-size: 0.77rem;
line-height: 1.52;
}
#season-copy strong {
color: var(--ink);
}
#legend {
position: absolute;
top: 24px;
right: 24px;
width: 244px;
padding: 17px 18px;
border-radius: 17px;
}
.panel-title {
margin: 0 0 12px;
color: #708078;
font-size: 0.65rem;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 9px 0;
color: #536159;
font-size: 0.72rem;
}
.swatch {
width: 16px;
height: 16px;
flex: 0 0 auto;
border: 1px solid rgba(30, 44, 37, 0.1);
border-radius: 3px;
box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.06);
}
.swatch.water {
background: #659ba6;
}
.swatch.grass {
background: #9cab68;
}
.swatch.wood {
background: #536d48;
}
.swatch.high {
background: #b6a774;
}
.swatch.mud {
background: #887d62;
}
#sources {
position: absolute;
right: 24px;
bottom: 24px;
width: min(360px, calc(100vw - 48px));
padding: 13px 16px;
border-radius: 15px;
}
#sources summary {
color: #4f5f57;
cursor: pointer;
font-size: 0.71rem;
font-weight: 750;
letter-spacing: 0.08em;
list-style: none;
text-transform: uppercase;
}
#sources summary::-webkit-details-marker {
display: none;
}
#sources summary::after {
float: right;
color: #819087;
content: "+";
font-size: 1rem;
line-height: 0.7;
}
#sources[open] summary::after {
content: "−";
}
#sources .source-content {
padding-top: 12px;
color: #5d6b64;
font-size: 0.71rem;
line-height: 1.55;
}
#sources p {
margin: 0 0 9px;
}
#sources a {
color: #3d746a;
text-underline-offset: 2px;
}
#navigation-hint {
position: absolute;
bottom: 26px;
left: 50%;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 999px;
background: rgba(248, 247, 239, 0.74);
box-shadow: 0 8px 25px rgba(39, 55, 47, 0.08);
color: #67746e;
font-size: 0.67rem;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
.mouse-icon {
position: relative;
width: 15px;
height: 21px;
border: 1.5px solid #718079;
border-radius: 8px;
}
.mouse-icon::before {
position: absolute;
top: 3px;
left: 6px;
width: 2px;
height: 5px;
border-radius: 2px;
background: #718079;
content: "";
}
#map-labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.map-label {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 6px;
background: rgba(247, 246, 236, 0.78);
box-shadow: 0 5px 15px rgba(40, 55, 48, 0.08);
color: #4d5e56;
font-size: 0.59rem;
font-weight: 750;
letter-spacing: 0.04em;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
backdrop-filter: blur(5px);
}
.map-label::before {
width: 6px;
height: 6px;
border: 2px solid #f8f6ea;
border-radius: 50%;
background: #4f8274;
box-shadow: 0 0 0 1px rgba(49, 86, 75, 0.35);
content: "";
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #e7ece4;
color: #4b655b;
font-size: 0.72rem;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#intro {
top: 12px;
left: 12px;
width: min(355px, calc(100vw - 24px));
padding: 16px;
border-radius: 16px;
}
h1 {
font-size: 1.75rem;
}
.subtitle {
display: none;
}
#legend {
display: none;
}
#sources {
right: 12px;
bottom: 12px;
width: 48px;
height: 42px;
padding: 0;
overflow: hidden;
border-radius: 50%;
}
#sources summary {
display: grid;
height: 42px;
place-items: center;
font-size: 0;
}
#sources summary::before {
color: #4f685f;
content: "i";
font-family: Georgia, serif;
font-size: 1.15rem;
font-style: italic;
font-weight: 700;
text-transform: none;
}
#sources summary::after {
display: none;
}
#sources[open] {
width: min(340px, calc(100vw - 24px));
height: auto;
padding: 13px 16px;
border-radius: 15px;
}
#sources[open] summary {
display: block;
height: auto;
font-size: 0.68rem;
}
#sources[open] summary::before {
display: none;
}
#navigation-hint {
bottom: 15px;
left: 16px;
transform: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional voxel landscape of the Pantanal wetland. Drag to orbit and use the mouse wheel to zoom."
></canvas>
<div id="hud">
<section id="intro" class="panel">
<div class="eyebrow">Pantanal · Brazil</div>
<h1>Seasonal wetland mosaic</h1>
<p class="subtitle">
A bounded voxel diorama of shallow channels, seasonal grassland,
gallery woodland, and higher ground.
</p>
<div class="setting-label">
<span>Selected seasonal setting</span>
<span>17°–20° S</span>
</div>
<div class="season-switch" role="group" aria-label="Choose a seasonal setting">
<button
id="dry-button"
class="season-button"
type="button"
aria-pressed="true"
>
Late dry season
</button>
<button
id="wet-button"
class="season-button"
type="button"
aria-pressed="false"
>
Flood season
</button>
</div>
<p id="season-copy" aria-live="polite">
<strong>August–September.</strong> A selected late-dry-season setting:
shallow channels are contracted, the floodplain is exposed, and woodland
remains concentrated on slightly higher ground.
</p>
</section>
<aside id="legend" class="panel">
<h2 class="panel-title">Read the landscape</h2>
<div class="legend-row"><i class="swatch water"></i>Shallow channel</div>
<div class="legend-row"><i class="swatch grass"></i>Seasonal grassland</div>
<div class="legend-row"><i class="swatch wood"></i>Wooded patch</div>
<div class="legend-row"><i class="swatch high"></i>Higher ground</div>
<div class="legend-row"><i class="swatch mud"></i>Exposed floodplain</div>
</aside>
<details id="sources" class="panel">
<summary>Sources & method</summary>
<div class="source-content">
<p>
This is an interpretive, non-georeferenced reconstruction. Its two
seasonal states follow the documented contrast between the Pantanal’s
contracted dry-season channels and broad austral flood season.
Flood timing and extent vary by year and location.
</p>
<p>
Regional references:
<a href="https://whc.unesco.org/en/list/321/" target="_blank" rel="noopener">
UNESCO World Heritage Centre
</a>,
<a href="https://earthobservatory.nasa.gov/search?q=Pantanal" target="_blank" rel="noopener">
NASA Earth Observatory
</a>, and
<a href="https://www.worldwildlife.org/places/pantanal" target="_blank" rel="noopener">
WWF Pantanal
</a>.
</p>
<p>
Geometry, vegetation placement, and the seasonal transition are
stylized rather than derived from a single dated satellite image.
</p>
</div>
</details>
<div id="navigation-hint">
<span class="mouse-icon"></span>
<span>Drag to orbit · scroll to zoom · double-click to reset</span>
</div>
<div id="map-labels" aria-hidden="true">
<div id="label-channel" class="map-label">Main channel</div>
<div id="label-wood" class="map-label">Wooded island</div>
<div id="label-high" class="map-label">Higher terrace</div>
</div>
</div>
<div id="loading">Building the wetland mosaic…</div>
</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, and manually implemented orthographic camera controls.
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
const dryBackground = new THREE.Color("#e7ece4");
const wetBackground = new THREE.Color("#dfe8e2");
scene.background = dryBackground.clone();
scene.fog = new THREE.Fog(dryBackground.clone(), 105, 190);
const camera = new THREE.OrthographicCamera(-50, 50, 50, -50, 0.1, 300);
const orbit = {
theta: 0.76,
phi: 0.91,
radius: 115,
target: new THREE.Vector3(0, 0, 0),
zoom: 1
};
const defaultOrbit = { ...orbit };
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the whole bounded diorama, including on narrow screens.
const viewSize = Math.max(61, 108 / aspect);
camera.left = (-viewSize * aspect) / 2;
camera.right = (viewSize * aspect) / 2;
camera.top = viewSize / 2;
camera.bottom = -viewSize / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.004, 0.48, 1.35);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.25
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
orbit.zoom = defaultOrbit.zoom;
updateCamera();
});
canvas.addEventListener("keydown", (event) => {
let handled = true;
if (event.key === "ArrowLeft") orbit.theta += 0.08;
else if (event.key === "ArrowRight") orbit.theta -= 0.08;
else if (event.key === "ArrowUp") orbit.phi = Math.max(0.48, orbit.phi - 0.06);
else if (event.key === "ArrowDown") orbit.phi = Math.min(1.35, orbit.phi + 0.06);
else if (event.key === "+" || event.key === "=") orbit.zoom = Math.min(2.25, orbit.zoom * 1.08);
else if (event.key === "-") orbit.zoom = Math.max(0.65, orbit.zoom / 1.08);
else handled = false;
if (handled) {
event.preventDefault();
updateCamera();
}
});
resize();
updateCamera();
// -------------------------------------------------------------------------
// Lighting.
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight("#f6f1dc", "#566b60", 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff2cb", 2.65);
sun.position.set(-36, 68, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -65;
sun.shadow.camera.right = 65;
sun.shadow.camera.top = 55;
sun.shadow.camera.bottom = -55;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b8d6d5", 0.55);
fill.position.set(45, 25, -38);
scene.add(fill);
// -------------------------------------------------------------------------
// Synthetic but hydrologically organized landscape geometry.
// -------------------------------------------------------------------------
const NX = 60;
const NZ = 44;
const CELL = 1.35;
const WIDTH = NX * CELL;
const DEPTH = NZ * CELL;
const LAND_BOTTOM = -2.05;
const world = new THREE.Group();
scene.add(world);
const groundMaterial = new THREE.MeshStandardMaterial({
color: "#e4e7df",
roughness: 1
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(260, 260),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5.35;
ground.receiveShadow = true;
scene.add(ground);
const lowerPlinth = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH + 1.8, 1.05, DEPTH + 1.8),
new THREE.MeshStandardMaterial({
color: "#515b4d",
roughness: 0.94
})
);
lowerPlinth.position.y = -4.72;
lowerPlinth.castShadow = true;
lowerPlinth.receiveShadow = true;
world.add(lowerPlinth);
const upperPlinth = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH + 1.15, 2.65, DEPTH + 1.15),
new THREE.MeshStandardMaterial({
color: "#77735b",
roughness: 0.96
})
);
upperPlinth.position.y = -3.3;
upperPlinth.castShadow = true;
upperPlinth.receiveShadow = true;
world.add(upperPlinth);
const riverPaths = [
[
[-40, -16],
[-31, -13],
[-23, -7],
[-12, -4],
[-1, 1],
[9, 5],
[18, 10],
[28, 17],
[40, 22]
],
[
[-19, -29],
[-17, -20],
[-13, -11],
[-6, -7],
[3, -3],
[12, 1],
[18, 8]
],
[
[9, 28],
[12, 20],
[11, 13],
[8, 8],
[2, 3]
],
[
[-39, 14],
[-29, 12],
[-20, 8],
[-11, 2],
[-1, 1]
]
];
function random(i, j, salt = 0) {
const n = Math.sin(i * 127.1 + j * 311.7 + salt * 74.7) * 43758.5453;
return n - Math.floor(n);
}
function gaussian(x, z, centerX, centerZ, radiusX, radiusZ) {
const dx = (x - centerX) / radiusX;
const dz = (z - centerZ) / radiusZ;
return Math.exp(-(dx * dx + dz * dz) * 0.5);
}
function distanceToSegment(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const lengthSquared = dx * dx + dz * dz;
const t = lengthSquared === 0
? 0
: THREE.MathUtils.clamp(
((px - ax) * dx + (pz - az) * dz) / lengthSquared,
0,
1
);
const x = ax + t * dx;
const z = az + t * dz;
return Math.hypot(px - x, pz - z);
}
function channelDistance(x, z) {
let minimum = Infinity;
for (const path of riverPaths) {
for (let p = 0; p < path.length - 1; p++) {
const a = path[p];
const b = path[p + 1];
minimum = Math.min(
minimum,
distanceToSegment(x, z, a[0], a[1], b[0], b[1])
);
}
}
return minimum;
}
const cells = [];
const dryWaterCells = [];
const floodWaterCells = [];
for (let iz = 0; iz < NZ; iz++) {
for (let ix = 0; ix < NX; ix++) {
const x = (ix - (NX - 1) / 2) * CELL;
const z = (iz - (NZ - 1) / 2) * CELL;
const distance = channelDistance(x, z);
const channelCore = Math.exp(-Math.pow(distance / 2.25, 2));
const centralLowland = gaussian(x, z, -1, 2, 25, 20);
const terraceA = gaussian(x, z, -20, -10, 10, 8);
const terraceB = gaussian(x, z, 20, -14, 8, 6);
const terraceC = gaussian(x, z, 24, 14, 9, 7);
const woodA = gaussian(x, z, -19, -11, 8.5, 7);
const woodB = gaussian(x, z, 21, -14, 7, 5.5);
const woodC = gaussian(x, z, 24, 14, 8, 6);
const woodMask = Math.max(woodA, woodB, woodC);
const noise = random(ix, iz, 4) - 0.5;
const fineNoise = random(ix, iz, 12) - 0.5;
let elevation =
0.13 +
0.36 * (1 - centralLowland) +
1.65 * terraceA +
1.5 * terraceB +
1.35 * terraceC +
0.48 * woodMask +
noise * 0.22 +
fineNoise * 0.08 -
0.95 * channelCore;
if (distance < 1.48) {
elevation = Math.min(elevation, -0.44 + distance * 0.1);
}
elevation = THREE.MathUtils.clamp(elevation, -0.62, 2.8);
const cell = {
ix,
iz,
x,
z,
elevation,
distance,
woodMask,
highMask: Math.max(terraceA, terraceB, terraceC),
noise,
fineNoise
};
cells.push(cell);
if (distance < 1.44) {
dryWaterCells.push(cell);
}
if (elevation < 0.74 || distance < 3.05) {
floodWaterCells.push(cell);
}
}
}
// Terrain columns: earthy sides.
const columnMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 1,
vertexColors: true
});
const columns = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
columnMaterial,
cells.length
);
columns.castShadow = true;
columns.receiveShadow = true;
// Thin colored caps make the mosaic readable while retaining voxel sides.
const capMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 0.98,
vertexColors: true
});
const caps = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
capMaterial,
cells.length
);
caps.castShadow = true;
caps.receiveShadow = true;
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
const dryGrassPalette = [
new THREE.Color("#9eac69"),
new THREE.Color("#aeb475"),
new THREE.Color("#939f62"),
new THREE.Color("#b2a36d")
];
const wetGrassPalette = [
new THREE.Color("#718c55"),
new THREE.Color("#7d9c5c"),
new THREE.Color("#688653"),
new THREE.Color("#899f63")
];
const woodPalette = [
new THREE.Color("#62774e"),
new THREE.Color("#6c8054"),
new THREE.Color("#58704c"),
new THREE.Color("#73845a")
];
const wetWoodPalette = [
new THREE.Color("#416744"),
new THREE.Color("#4a7049"),
new THREE.Color("#3d6245"),
new THREE.Color("#51764d")
];
const mudPalette = [
new THREE.Color("#8d8263"),
new THREE.Color("#988b68"),
new THREE.Color("#82785f")
];
for (let index = 0; index < cells.length; index++) {
const cell = cells[index];
const columnHeight = cell.elevation - LAND_BOTTOM;
dummy.position.set(cell.x, LAND_BOTTOM + columnHeight / 2, cell.z);
dummy.scale.set(CELL * 0.965, columnHeight, CELL * 0.965);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
columns.setMatrixAt(index, dummy.matrix);
tempColor.setHSL(
0.105 + cell.noise * 0.025,
0.16,
0.285 + cell.fineNoise * 0.025
);
columns.setColorAt(index, tempColor);
dummy.position.set(cell.x, cell.elevation + 0.045, cell.z);
dummy.scale.set(CELL * 0.955, 0.13, CELL * 0.955);
dummy.updateMatrix();
caps.setMatrixAt(index, dummy.matrix);
let dryColor;
let wetColor;
if (cell.distance < 1.55) {
dryColor = mudPalette[Math.floor(random(cell.ix, cell.iz, 21) * mudPalette.length)];
wetColor = new THREE.Color("#657f65");
} else if (cell.woodMask > 0.38) {
const p = Math.floor(random(cell.ix, cell.iz, 33) * woodPalette.length);
dryColor = woodPalette[p];
wetColor = wetWoodPalette[p];
} else if (cell.highMask > 0.42) {
dryColor = new THREE.Color("#b6a773");
wetColor = new THREE.Color("#9c9866");
} else {
const p = Math.floor(random(cell.ix, cell.iz, 44) * dryGrassPalette.length);
dryColor = dryGrassPalette[p];
wetColor = wetGrassPalette[p];
}
cell.dryColor = dryColor;
cell.wetColor = wetColor;
caps.setColorAt(index, dryColor);
}
columns.instanceMatrix.needsUpdate = true;
columns.instanceColor.needsUpdate = true;
caps.instanceMatrix.needsUpdate = true;
caps.instanceColor.needsUpdate = true;
world.add(columns);
world.add(caps);
// -------------------------------------------------------------------------
// Seasonal water surfaces, built as shallow voxel tiles.
// -------------------------------------------------------------------------
const dryWaterMaterial = new THREE.MeshStandardMaterial({
color: "#57929b",
roughness: 0.28,
metalness: 0.06,
transparent: true,
opacity: 0.94,
depthWrite: false
});
const wetWaterMaterial = new THREE.MeshStandardMaterial({
color: "#5f99a5",
roughness: 0.24,
metalness: 0.04,
transparent: true,
opacity: 0,
depthWrite: false
});
const dryWater = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
dryWaterMaterial,
dryWaterCells.length
);
const floodWater = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
wetWaterMaterial,
floodWaterCells.length
);
dryWater.renderOrder = 2;
floodWater.renderOrder = 3;
for (let index = 0; index < dryWaterCells.length; index++) {
const cell = dryWaterCells[index];
dummy.position.set(cell.x, -0.13, cell.z);
dummy.scale.set(CELL * 0.97, 0.14, CELL * 0.97);
dummy.updateMatrix();
dryWater.setMatrixAt(index, dummy.matrix);
}
for (let index = 0; index < floodWaterCells.length; index++) {
const cell = floodWaterCells[index];
dummy.position.set(cell.x, 0.73, cell.z);
dummy.scale.set(CELL * 0.97, 0.14, CELL * 0.97);
dummy.updateMatrix();
floodWater.setMatrixAt(index, dummy.matrix);
}
dryWater.instanceMatrix.needsUpdate = true;
floodWater.instanceMatrix.needsUpdate = true;
dryWater.receiveShadow = true;
floodWater.receiveShadow = true;
world.add(dryWater);
world.add(floodWater);
// -------------------------------------------------------------------------
// Voxel woodland: block trunks, clustered block canopies, and low shrubs.
// -------------------------------------------------------------------------
const treeData = [];
const bushData = [];
for (const cell of cells) {
if (
cell.woodMask > 0.4 &&
cell.elevation > 0.57 &&
cell.distance > 1.85
) {
if (random(cell.ix, cell.iz, 61) < 0.52) {
treeData.push(cell);
} else if (random(cell.ix, cell.iz, 67) < 0.58) {
bushData.push(cell);
}
}
}
const trunkMaterial = new THREE.MeshStandardMaterial({
color: "#66523a",
roughness: 1
});
const trunkMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
trunkMaterial,
treeData.length
);
const foliageMaterial = new THREE.MeshStandardMaterial({
color: "#ffffff",
roughness: 0.94,
vertexColors: true
});
const foliageData = [];
for (const cell of treeData) {
const offsetX = (random(cell.ix, cell.iz, 73) - 0.5) * 0.7;
const offsetZ = (random(cell.ix, cell.iz, 79) - 0.5) * 0.7;
const x = cell.x + offsetX;
const z = cell.z + offsetZ;
const base = cell.elevation + 0.08;
const trunkHeight = 0.65 + random(cell.ix, cell.iz, 81) * 0.35;
trunkMesh.setMatrixAt(
treeData.indexOf(cell),
new THREE.Matrix4().compose(
new THREE.Vector3(x, base + trunkHeight / 2, z),
new THREE.Quaternion(),
new THREE.Vector3(0.19, trunkHeight, 0.19)
)
);
const canopyWidth = 0.9 + random(cell.ix, cell.iz, 87) * 0.48;
const colorIndex = Math.floor(random(cell.ix, cell.iz, 91) * woodPalette.length);
foliageData.push({
x,
y: base + trunkHeight + canopyWidth * 0.34,
z,
sx: canopyWidth,
sy: canopyWidth * 0.86,
sz: canopyWidth,
colorIndex
});
foliageData.push({
x: x + (random(cell.ix, cell.iz, 93) - 0.5) * 0.7,
y: base + trunkHeight + canopyWidth * 0.79,
z: z + (random(cell.ix, cell.iz, 95) - 0.5) * 0.7,
sx: canopyWidth * 0.67,
sy: canopyWidth * 0.59,
sz: canopyWidth * 0.67,
colorIndex
});
foliageData.push({
x: x + (random(cell.ix, cell.iz, 97) - 0.5) * 0.95,
y: base + trunkHeight + canopyWidth * 0.2,
z: z + (random(cell.ix, cell.iz, 101) - 0.5) * 0.95,
sx: canopyWidth * 0.62,
sy: canopyWidth * 0.62,
sz: canopyWidth * 0.62,
colorIndex
});
}
const foliageMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
foliageMaterial,
foliageData.length
);
foliageData.forEach((leaf, index) => {
dummy.position.set(leaf.x, leaf.y, leaf.z);
dummy.scale.set(leaf.sx, leaf.sy, leaf.sz);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
foliageMesh.setMatrixAt(index, dummy.matrix);
tempColor.set("#ffffff").offsetHSL(
0,
0,
(random(index, leaf.x * 2, 109) - 0.5) * 0.12
);
foliageMesh.setColorAt(index, tempColor);
});
trunkMesh.castShadow = true;
trunkMesh.receiveShadow = true;
foliageMesh.castShadow = true;
foliageMesh.receiveShadow = true;
world.add(trunkMesh);
world.add(foliageMesh);
const shrubMaterial = new THREE.MeshStandardMaterial({
color: "#687b4e",
roughness: 1
});
const shrubMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
shrubMaterial,
bushData.length
);
bushData.forEach((cell, index) => {
const size = 0.35 + random(cell.ix, cell.iz, 112) * 0.3;
dummy.position.set(
cell.x + (random(cell.ix, cell.iz, 114) - 0.5) * 0.5,
cell.elevation + size * 0.45,
cell.z + (random(cell.ix, cell.iz, 118) - 0.5) * 0.5
);
dummy.scale.set(size * 1.25, size * 0.72, size);
dummy.updateMatrix();
shrubMesh.setMatrixAt(index, dummy.matrix);
});
shrubMesh.castShadow = true;
world.add(shrubMesh);
// -------------------------------------------------------------------------
// Small voxel grass stems. Their material color changes seasonally.
// -------------------------------------------------------------------------
const grassData = [];
for (const cell of cells) {
if (
cell.distance > 1.55 &&
cell.woodMask < 0.56 &&
cell.elevation > -0.3
) {
const count = cell.distance < 2.4 ? 3 : 2;
for (let k = 0; k < count; k++) {
if (random(cell.ix + k, cell.iz, 123 + k) < 0.66) {
grassData.push({
x: cell.x + (random(cell.ix, cell.iz + k, 131) - 0.5) * 0.9,
z: cell.z + (random(cell.ix, cell.iz + k, 137) - 0.5) * 0.9,
y: cell.elevation + 0.08,
height: 0.18 + random(cell.ix, cell.iz + k, 139) * 0.34,
tone: random(cell.ix, cell.iz + k, 149)
});
}
}
}
}
const grassMaterial = new THREE.MeshStandardMaterial({
color: "#b5a45f",
roughness: 1,
vertexColors: true
});
const grassMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
grassMaterial,
grassData.length
);
for (const mesh of [columns, caps, foliageMesh, grassMesh]) {
const count = mesh.geometry.getAttribute("position").count;
const neutralVertexColors = new Float32Array(count * 3).fill(1);
mesh.geometry.setAttribute("color", new THREE.BufferAttribute(neutralVertexColors, 3));
}
grassData.forEach((blade, index) => {
dummy.position.set(blade.x, blade.y + blade.height / 2, blade.z);
dummy.scale.set(0.075, blade.height, 0.075);
dummy.rotation.set(0, blade.tone * Math.PI, 0);
dummy.updateMatrix();
grassMesh.setMatrixAt(index, dummy.matrix);
tempColor.set("#ffffff").offsetHSL(0, 0, (blade.tone - 0.5) * 0.16);
grassMesh.setColorAt(index, tempColor);
});
grassMesh.castShadow = true;
world.add(grassMesh);
// -------------------------------------------------------------------------
// Seasonal interface.
// -------------------------------------------------------------------------
const dryButton = document.querySelector("#dry-button");
const wetButton = document.querySelector("#wet-button");
const seasonCopy = document.querySelector("#season-copy");
let floodTarget = 0;
let floodAmount = 0;
const dryGrassColor = new THREE.Color("#b5a45f");
const wetGrassColor = new THREE.Color("#789652");
const dryLeafColor = new THREE.Color("#ffffff");
const wetLeafColor = new THREE.Color("#c3d0bc");
const drySunColor = new THREE.Color("#fff1c9");
const wetSunColor = new THREE.Color("#e6eee4");
function selectSeason(season) {
const isWet = season === "wet";
dryButton.setAttribute("aria-pressed", String(!isWet));
wetButton.setAttribute("aria-pressed", String(isWet));
floodTarget = isWet ? 1 : 0;
if (isWet) {
seasonCopy.innerHTML =
"<strong>January–March.</strong> A selected austral flood-season " +
"setting: low parts of the floodplain are inundated, channels broaden, " +
"and wooded patches remain as higher-ground islands.";
} else {
seasonCopy.innerHTML =
"<strong>August–September.</strong> A selected late-dry-season " +
"setting: shallow channels are contracted, the floodplain is exposed, " +
"and woodland remains concentrated on slightly higher ground.";
}
}
dryButton.addEventListener("click", () => selectSeason("dry"));
wetButton.addEventListener("click", () => selectSeason("wet"));
function updateSeasonVisuals(amount) {
dryWaterMaterial.opacity = 0.94 * (1 - amount);
wetWaterMaterial.opacity = 0.9 * amount;
dryWater.visible = amount < 0.998;
floodWater.visible = amount > 0.002;
grassMaterial.color.lerpColors(dryGrassColor, wetGrassColor, amount);
foliageMaterial.color.lerpColors(dryLeafColor, wetLeafColor, amount);
sun.color.lerpColors(drySunColor, wetSunColor, amount);
sun.intensity = THREE.MathUtils.lerp(2.65, 2.05, amount);
hemisphere.intensity = THREE.MathUtils.lerp(2.05, 2.25, amount);
scene.background.lerpColors(dryBackground, wetBackground, amount);
scene.fog.color.copy(scene.background);
for (let index = 0; index < cells.length; index++) {
const cell = cells[index];
tempColor.lerpColors(cell.dryColor, cell.wetColor, amount);
caps.setColorAt(index, tempColor);
}
caps.instanceColor.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Projected map labels.
// -------------------------------------------------------------------------
const labelDefinitions = [
{
element: document.querySelector("#label-channel"),
point: new THREE.Vector3(-4, 0.5, 1)
},
{
element: document.querySelector("#label-wood"),
point: new THREE.Vector3(21, 3.7, -14)
},
{
element: document.querySelector("#label-high"),
point: new THREE.Vector3(-20, 3.4, -10)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelDefinitions) {
projected.copy(label.point).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > 35 &&
x < width - 35 &&
y > 20 &&
y < height - 30;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = visible ? "1" : "0";
}
}
// -------------------------------------------------------------------------
// Render loop.
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.exp(-delta * 3.6);
if (Math.abs(floodAmount - floodTarget) > 0.0001) {
floodAmount = THREE.MathUtils.lerp(floodAmount, floodTarget, easing);
updateSeasonVisuals(floodAmount);
}
updateLabels();
renderer.render(scene, camera);
}
updateSeasonVisuals(0);
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```