Prompt specification
Build or customize the Three.js 3D scene "Monsoon farming landscape teaching scene" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Monsoon farming landscape teaching scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/monsoon-farming-landscape-teaching-scene-x1227
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing monsoon circulation. Compose a coast, inland hills, reservoirs, and rice-field terraces; toggle schematic wet and dry states while separating water storage geometry from climate predictions. Voxel style.
Working Three.js Starter (monsoon-farming-landscape-teaching-scene-x1227):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Monsoon Circulation — Voxel Field Study</title>
<style>
:root {
--ink: #17343b;
--muted: #5f7378;
--panel: rgba(246, 250, 247, 0.90);
--panel-solid: #f6faf7;
--line: rgba(23, 52, 59, 0.14);
--wet: #168c9d;
--wet-soft: #d8f1ef;
--dry: #bb743c;
--dry-soft: #f6e7d7;
--storage: #b78335;
--storage-soft: #f4ead5;
--shadow: 0 16px 45px rgba(25, 55, 60, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9dddd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.72);
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(15px) saturate(115%);
-webkit-backdrop-filter: blur(15px) saturate(115%);
}
.masthead {
top: 22px;
left: 22px;
width: min(440px, calc(100vw - 44px));
padding: 19px 21px 18px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--wet);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3.2vw, 43px);
font-weight: 820;
line-height: 0.96;
letter-spacing: -0.055em;
text-transform: uppercase;
}
h1 span {
display: block;
margin-top: 6px;
color: var(--wet);
font-size: 0.57em;
letter-spacing: -0.025em;
}
.masthead p {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.climate-panel {
top: 22px;
right: 22px;
width: min(355px, calc(100vw - 44px));
padding: 17px;
border-radius: 18px;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-bottom: 14px;
}
.panel-heading h2 {
margin: 2px 0 0;
font-size: 17px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.badge {
flex: 0 0 auto;
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(255, 255, 255, 0.58);
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.toggle {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px;
padding: 4px;
border-radius: 12px;
background: #e5ece8;
}
.toggle button {
min-height: 39px;
padding: 9px 10px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
transition:
background 180ms ease,
color 180ms ease,
box-shadow 180ms ease,
transform 180ms ease;
}
.toggle button:hover {
color: var(--ink);
}
.toggle button:active {
transform: translateY(1px);
}
.toggle button.active {
background: var(--panel-solid);
color: var(--wet);
box-shadow: 0 3px 10px rgba(34, 63, 67, 0.10);
}
.toggle button[data-state="dry"].active {
color: var(--dry);
}
.climate-state {
display: flex;
align-items: center;
gap: 10px;
margin: 14px 0 10px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.47);
}
.state-dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--wet);
box-shadow: 0 0 0 5px var(--wet-soft);
transition: 180ms ease;
}
.state-dot.dry {
background: var(--dry);
box-shadow: 0 0 0 5px var(--dry-soft);
}
.climate-state small {
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
}
.climate-state strong {
display: block;
font-size: 13px;
}
.climate-summary {
min-height: 48px;
margin: 0 0 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.signals {
display: flex;
flex-wrap: wrap;
gap: 6px;
min-height: 27px;
}
.signal {
padding: 5px 7px;
border-radius: 6px;
background: var(--wet-soft);
color: #176b78;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.09em;
}
.signal.dry {
background: var(--dry-soft);
color: #8a552e;
}
.coupling-note {
display: flex;
gap: 8px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.coupling-note::before {
content: "";
width: 7px;
height: 7px;
flex: 0 0 auto;
margin-top: 2px;
border-radius: 2px;
background: var(--storage);
}
.storage-panel {
right: 22px;
bottom: 22px;
width: min(355px, calc(100vw - 44px));
padding: 17px;
border-radius: 18px;
}
.storage-panel .badge {
background: var(--storage-soft);
color: #7b581f;
border-color: rgba(183, 131, 53, 0.20);
}
.storage-list {
display: grid;
gap: 8px;
}
.storage-row {
display: grid;
grid-template-columns: 35px 1fr auto;
align-items: center;
gap: 10px;
padding: 9px;
border: 1px solid rgba(183, 131, 53, 0.15);
border-radius: 10px;
background: rgba(255, 255, 255, 0.48);
}
.structure-icon {
position: relative;
width: 35px;
height: 28px;
border-radius: 6px;
background: #d8c69f;
}
.structure-icon::after {
content: "";
position: absolute;
inset: 7px 5px 6px;
border-radius: 2px;
background: #4ba7b0;
box-shadow:
6px -3px 0 -1px #8fd1cf,
13px 2px 0 -2px #8fd1cf;
}
.structure-icon.terrace::after {
inset: auto 4px 5px;
height: 5px;
box-shadow:
0 -6px 0 0 #61a98c,
0 -12px 0 0 #77b89d;
}
.storage-row strong {
display: block;
font-size: 11px;
}
.storage-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
line-height: 1.35;
}
.unchanged {
padding: 4px 5px;
border-radius: 5px;
background: var(--storage-soft);
color: #7b581f;
font-size: 7px;
font-weight: 850;
letter-spacing: 0.08em;
}
.storage-footnote {
margin: 11px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.legend {
left: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 14px;
max-width: min(540px, calc(100vw - 44px));
padding: 12px 15px;
border-radius: 14px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.03em;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
display: inline-block;
width: 15px;
height: 8px;
border-radius: 2px;
background: #45b5bd;
}
.swatch.rain {
width: 3px;
height: 15px;
background: #378ea5;
}
.swatch.flow {
width: 12px;
height: 12px;
border-radius: 2px;
background: #63d0c5;
transform: rotate(-20deg);
}
.swatch.storage {
background: #d7ad68;
}
.controls-hint {
position: fixed;
z-index: 8;
left: 24px;
bottom: 78px;
display: flex;
align-items: center;
gap: 8px;
color: rgba(23, 52, 59, 0.72);
font-size: 9px;
font-weight: 700;
pointer-events: none;
}
.controls-hint button {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 6px;
background: rgba(246, 250, 247, 0.8);
color: var(--ink);
cursor: pointer;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: max-content;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-left: 3px solid #3a8f99;
border-radius: 6px;
background: rgba(244, 249, 247, 0.82);
box-shadow: 0 5px 18px rgba(20, 45, 48, 0.11);
color: #27464c;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translate(-50%, -50%);
white-space: nowrap;
transition: opacity 120ms ease;
}
.scene-label small {
display: block;
margin-top: 2px;
color: #718287;
font-size: 6px;
font-weight: 750;
letter-spacing: 0.05em;
}
.scene-label.storage {
border-left-color: var(--storage);
}
.scene-label.climate {
border-left-color: var(--wet);
}
@media (max-width: 760px) {
.masthead {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
.masthead p {
display: none;
}
.climate-panel {
top: 125px;
right: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.storage-panel {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.storage-footnote,
.coupling-note {
display: none;
}
.legend {
display: none;
}
.controls-hint {
left: 14px;
bottom: 184px;
}
.scene-label {
font-size: 7px;
}
}
@media (max-height: 650px) {
.masthead p,
.storage-footnote,
.coupling-note,
.legend {
display: none;
}
.climate-panel {
top: 12px;
}
.storage-panel {
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels" aria-hidden="true">
<div id="label-ocean" class="scene-label">
Indian Ocean
<small>moisture source</small>
</div>
<div id="label-coast" class="scene-label">
Coastal plain
<small>low elevation</small>
</div>
<div id="label-hills" class="scene-label">
Inland hills
<small>orographic lift</small>
</div>
<div id="label-reservoir" class="scene-label storage">
Reservoir geometry
<small>fixed storage layer</small>
</div>
<div id="label-terraces" class="scene-label storage">
Rice-field terraces
<small>fixed storage layer</small>
</div>
<div id="label-flow" class="scene-label climate">
Moist onshore flow
<small>climate schematic</small>
</div>
</div>
<header class="panel masthead">
<div class="eyebrow">Voxel hydroclimate field study · 01</div>
<h1>Monsoon <span>circulation</span></h1>
<p>
A schematic cross-section of coastal moisture transport, uplift over inland
hills, rainfall, reservoirs, and terraced rice storage.
</p>
</header>
<aside class="panel climate-panel">
<div class="panel-heading">
<div>
<div class="eyebrow">Climate prediction layer</div>
<h2>Schematic monsoon state</h2>
</div>
<span class="badge">Not calibrated</span>
</div>
<div class="toggle" role="group" aria-label="Monsoon climate state">
<button id="wet-button" data-state="wet" class="active" aria-pressed="true">
WET STATE
</button>
<button id="dry-button" data-state="dry" aria-pressed="false">
DRY STATE
</button>
</div>
<div class="climate-state">
<span id="state-dot" class="state-dot"></span>
<div>
<small>Active circulation</small>
<strong id="climate-name">Wet · onshore monsoon</strong>
</div>
</div>
<p id="climate-summary" class="climate-summary">
Moist air advances inland, rises over the hills, and returns aloft.
</p>
<div id="signals" class="signals">
<span class="signal">ONSHORE</span>
<span class="signal">UPLIFT</span>
<span class="signal">OROGRAPHIC RAIN</span>
</div>
<div class="coupling-note">
This toggle changes only the atmospheric schematic. It does not alter
reservoir or terrace geometry.
</div>
</aside>
<aside class="panel storage-panel">
<div class="panel-heading">
<div>
<div class="eyebrow">Hydrology geometry layer</div>
<h2>Water storage structures</h2>
</div>
<span class="badge">Fixed geometry</span>
</div>
<div class="storage-list">
<div class="storage-row">
<div class="structure-icon"></div>
<div>
<strong>Reservoir basin + spillway</strong>
<small>Discrete surface-storage geometry</small>
</div>
<span class="unchanged">UNCHANGED</span>
</div>
<div class="storage-row">
<div class="structure-icon terrace"></div>
<div>
<strong>Terrace paddies + bunds</strong>
<small>Stepped distributed-storage geometry</small>
</div>
<span class="unchanged">UNCHANGED</span>
</div>
</div>
<p class="storage-footnote">
Storage forms are represented independently from the climate scenario.
Toggle the weather state to inspect that separation.
</p>
</aside>
<div class="legend panel">
<span class="legend-item"><i class="swatch flow"></i>Airflow</span>
<span class="legend-item"><i class="swatch rain"></i>Rain</span>
<span class="legend-item"><i class="swatch storage"></i>Storage geometry</span>
<span class="legend-item"><i class="swatch"></i>Water</span>
</div>
<div class="controls-hint">
Drag to orbit · scroll to zoom · Space toggles climate
<button id="reset-view" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of monsoon circulation"
);
renderer.domElement.tabIndex = 0;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9dddd);
scene.fog = new THREE.Fog(0xc9dddd, 38, 78);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraTarget = new THREE.Vector3(3, 3.1, 0);
const cameraState = {
theta: 0.72,
phi: 1.03,
radius: 38,
targetTheta: 0.72,
targetPhi: 1.03,
targetRadius: 38
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xe8fbff, 0x485443, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d4, 3.0);
sun.position.set(-10, 26, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x9bd9e5, 0.65);
fillLight.position.set(20, 9, -18);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(
parent,
sizeX,
sizeY,
sizeZ,
x,
y,
z,
material,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sizeX, sizeY, sizeZ);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// Separate groups make the conceptual layers explicit.
const terrainGroup = new THREE.Group();
const environmentGroup = new THREE.Group();
const storageGroup = new THREE.Group();
const climateGroup = new THREE.Group();
const wetClimateGroup = new THREE.Group();
const dryClimateGroup = new THREE.Group();
terrainGroup.name = "Terrain and coast";
environmentGroup.name = "Environmental context";
storageGroup.name = "Fixed water storage geometry";
climateGroup.name = "Climate prediction schematic";
wetClimateGroup.name = "Wet climate schematic";
dryClimateGroup.name = "Dry climate schematic";
scene.add(terrainGroup, environmentGroup, storageGroup, climateGroup);
climateGroup.add(wetClimateGroup, dryClimateGroup);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
ocean: standardMaterial(0x287f94, { roughness: 0.48 }),
wave: standardMaterial(0x76c2c7, { roughness: 0.45 }),
sand: standardMaterial(0xc7b67d),
lowland: standardMaterial(0x719966),
midland: standardMaterial(0x63845a),
highland: standardMaterial(0x75815c),
peak: standardMaterial(0x8a8b69),
earth: standardMaterial(0x886144),
darkEarth: standardMaterial(0x654a38),
reservoir: standardMaterial(0x48aeb8, { roughness: 0.38 }),
reservoirLight: standardMaterial(0x83d0ce, { roughness: 0.4 }),
terraceWater: standardMaterial(0x72ad91, { roughness: 0.55 }),
rice: standardMaterial(0x39764a),
riceLight: standardMaterial(0x5b9656),
concrete: standardMaterial(0xa9aaa2),
trunk: standardMaterial(0x70503a),
leaves: standardMaterial(0x3e7451),
leavesLight: standardMaterial(0x5e8b54),
wall: standardMaterial(0xe3c99b),
roof: standardMaterial(0xa75e48),
window: standardMaterial(0x315963)
};
// -------------------------------------------------------------------------
// Ocean and voxel coast
// -------------------------------------------------------------------------
addBox(
terrainGroup,
35,
0.5,
25,
-19.5,
-0.34,
-0.5,
materials.ocean,
false,
true
);
let seed = 81723;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const oceanWaves = [];
for (let i = 0; i < 52; i++) {
const x = -31 + random() * 26;
const z = -11.5 + random() * 23;
if (x > -5.2) continue;
const wave = addBox(
terrainGroup,
0.45 + random() * 0.9,
0.06,
0.18 + random() * 0.22,
x,
0.0,
z,
materials.wave,
false,
false
);
wave.rotation.y = random() > 0.5 ? 0.18 : -0.18;
oceanWaves.push({
mesh: wave,
baseY: 0,
phase: random() * Math.PI * 2,
speed: 0.6 + random() * 0.7
});
}
const heightMap = new Map();
function coastAt(z) {
return (
-2.65 +
Math.sin(z * 0.54) * 0.58 +
Math.sin(z * 1.31 + 0.4) * 0.22
);
}
function insideEllipse(x, z, cx, cz, rx, rz) {
const nx = (x - cx) / rx;
const nz = (z - cz) / rz;
return nx * nx + nz * nz <= 1;
}
// The terrain is built from stacked, quantized voxel columns.
for (let x = -3; x <= 17; x++) {
for (let z = -9; z <= 8; z++) {
const cx = x + 0.5;
const cz = z + 0.5;
const coast = coastAt(cz);
if (cx < coast) continue;
const inlandDistance = cx - coast;
const peakA = Math.max(
0,
3.2 - Math.hypot(cx - 12.4, (cz + 4.4) * 0.72) * 0.52
);
const peakB = Math.max(
0,
2.7 - Math.hypot(cx - 15.3, (cz - 2.2) * 0.78) * 0.58
);
let height =
0.5 +
Math.floor(
Math.max(0, inlandDistance - 1) * 0.27 + peakA + peakB
);
height = Math.min(height, 5.5);
height = Math.round(height * 2) / 2;
// Flat structural zones are separate from the climate layer.
if (
cx >= 6.3 &&
cx <= 13.5 &&
cz >= 1.0 &&
cz <= 8.8
) {
height = 0.5;
}
if (
insideEllipse(cx, cz, 5.8, -3.5, 3.7, 2.4) ||
insideEllipse(cx, cz, 14.0, -6.2, 2.7, 1.8)
) {
height = 0.15;
}
heightMap.set(`${x},${z}`, height);
let terrainMaterial = materials.lowland;
if (inlandDistance < 1.15) {
terrainMaterial = materials.sand;
} else if (height >= 4) {
terrainMaterial = materials.peak;
} else if (height >= 2) {
terrainMaterial = materials.midland;
}
const columnHeight = height + 1;
addBox(
terrainGroup,
0.96,
columnHeight,
0.96,
cx,
(height - 1) / 2,
cz,
terrainMaterial,
true,
true
);
}
}
function groundHeight(x, z) {
return (
heightMap.get(`${Math.floor(x)},${Math.floor(z)}`) ?? 0.5
);
}
// -------------------------------------------------------------------------
// Fixed storage geometry: reservoir basins
// -------------------------------------------------------------------------
function createReservoir(cx, cz, rx, rz, large = false) {
const minX = Math.floor(cx - rx - 1);
const maxX = Math.ceil(cx + rx + 1);
const minZ = Math.floor(cz - rz - 1);
const maxZ = Math.ceil(cz + rz + 1);
for (let x = minX; x <= maxX; x++) {
for (let z = minZ; z <= maxZ; z++) {
const px = x + 0.5;
const pz = z + 0.5;
const nx = (px - cx) / rx;
const nz = (pz - cz) / rz;
const distance = nx * nx + nz * nz;
if (distance > 1.05) continue;
addBox(
storageGroup,
0.96,
0.16,
0.96,
px,
0.24,
pz,
materials.darkEarth,
false,
true
);
if (distance <= 0.96) {
addBox(
storageGroup,
0.91,
0.10,
0.91,
px,
0.43,
pz,
materials.reservoir,
false,
true
);
}
}
}
// Block-like perimeter bunds.
const count = large ? 26 : 20;
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
const px = cx + Math.cos(angle) * (rx + 0.22);
const pz = cz + Math.sin(angle) * (rz + 0.22);
addBox(
storageGroup,
0.62,
0.28,
0.38,
px,
0.48,
pz,
materials.earth,
true,
true
);
}
// Dam and stepped spillway remain static in both climate states.
const damX = cx + rx + 0.55;
addBox(
storageGroup,
0.55,
0.72,
rz * 2.25,
damX,
0.62,
cz,
materials.concrete,
true,
true
);
for (let i = 0; i < 3; i++) {
addBox(
storageGroup,
0.75,
0.18,
0.65,
damX + 0.50 + i * 0.46,
0.42 - i * 0.10,
cz + (i - 1) * 0.22,
materials.concrete,
true,
true
);
}
// Sparse reflected-water voxels.
for (let i = 0; i < (large ? 8 : 5); i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * 0.72;
addBox(
storageGroup,
0.22,
0.025,
0.10,
cx + Math.cos(angle) * rx * radius,
0.495,
cz + Math.sin(angle) * rz * radius,
materials.reservoirLight,
false,
false
);
}
}
createReservoir(5.8, -3.5, 3.15, 1.85, true);
createReservoir(14.0, -6.2, 2.05, 1.25, false);
// -------------------------------------------------------------------------
// Fixed storage geometry: rice-field terraces
// -------------------------------------------------------------------------
for (let level = 0; level < 5; level++) {
const z = 7.65 - level * 1.2;
const y = 1.05 + level * 0.53;
const supportHeight = Math.max(0.1, y - 0.46);
// Retaining mass from the common ground to each terrace level.
addBox(
storageGroup,
7.1,
supportHeight,
1.12,
9.8,
0.46 + supportHeight / 2,
z,
materials.earth,
true,
true
);
// Narrow bund walls.
addBox(
storageGroup,
7.25,
0.19,
0.14,
9.8,
y + 0.02,
z - 0.56,
materials.darkEarth,
true,
true
);
addBox(
storageGroup,
7.25,
0.19,
0.14,
9.8,
y + 0.02,
z + 0.56,
materials.darkEarth,
true,
true
);
// Shallow paddy water.
addBox(
storageGroup,
6.94,
0.07,
0.96,
9.8,
y + 0.08,
z,
materials.terraceWater,
false,
true
);
// Voxel rice rows.
for (let crop = 0; crop < 12; crop++) {
const x = 6.7 + crop * 0.56;
const cropMaterial =
crop % 3 === 0 ? materials.riceLight : materials.rice;
addBox(
storageGroup,
0.28,
0.22,
0.60,
x,
y + 0.22,
z,
cropMaterial,
true,
false
);
}
}
// -------------------------------------------------------------------------
// Environmental context: trees, palms, and a small coastal settlement
// -------------------------------------------------------------------------
function addTree(x, z, scale = 1) {
const ground = groundHeight(x, z);
addBox(
environmentGroup,
0.18 * scale,
0.80 * scale,
0.18 * scale,
x,
ground + 0.40 * scale,
z,
materials.trunk,
true,
false
);
addBox(
environmentGroup,
0.78 * scale,
0.72 * scale,
0.78 * scale,
x,
ground + 1.04 * scale,
z,
materials.leaves,
true,
false
);
addBox(
environmentGroup,
0.50 * scale,
0.40 * scale,
0.50 * scale,
x + 0.12 * scale,
ground + 1.48 * scale,
z - 0.08 * scale,
materials.leavesLight,
true,
false
);
}
[
[13.5, -8.0, 0.9],
[15.3, -7.0, 1.0],
[14.0, -3.8, 0.85],
[16.0, -1.0, 1.0],
[15.6, 1.2, 0.9],
[16.5, 2.4, 1.0],
[3.6, 7.7, 0.75],
[4.2, -7.1, 0.8]
].forEach(([x, z, scale]) => addTree(x, z, scale));
function addPalm(x, z) {
const ground = groundHeight(x, z);
addBox(
environmentGroup,
0.17,
1.55,
0.17,
x,
ground + 0.77,
z,
materials.trunk,
true,
false
);
addBox(
environmentGroup,
0.95,
0.16,
0.24,
x,
ground + 1.53,
z,
materials.leavesLight,
true,
false
);
addBox(
environmentGroup,
0.24,
0.16,
0.95,
x,
ground + 1.53,
z,
materials.leaves,
true,
false
);
}
[
[-1.2, -6.4],
[-0.5, 1.8],
[-0.8, 7.3]
].forEach(([x, z]) => addPalm(x, z));
function addHouse(x, z, width = 1.15) {
const ground = groundHeight(x, z);
addBox(
environmentGroup,
width,
0.75,
0.9,
x,
ground + 0.375,
z,
materials.wall,
true,
true
);
addBox(
environmentGroup,
width + 0.12,
0.22,
1.02,
x,
ground + 0.86,
z,
materials.roof,
true,
true
);
addBox(
environmentGroup,
0.23,
0.28,
0.025,
x,
ground + 0.42,
z + 0.461,
materials.window,
false,
false
);
}
addHouse(0.5, 4.5, 1.2);
addHouse(1.9, 4.2, 1.0);
addHouse(0.7, 6.0, 1.1);
addHouse(2.2, 6.4, 0.95);
// -------------------------------------------------------------------------
// Climate schematic: clouds
// -------------------------------------------------------------------------
const cloudEntries = [];
function createCloud(parent, x, y, z, scale, material) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const pieces = [
[-0.95, 0.00, 0.05, 1.35, 0.65, 0.90],
[0.00, 0.16, 0.00, 1.55, 0.90, 1.10],
[0.95, 0.02, 0.08, 1.25, 0.62, 0.90],
[-0.35, -0.20, 0.16, 1.70, 0.55, 0.92],
[0.43, -0.18, -0.10, 1.45, 0.55, 0.78],
[-0.65, 0.32, -0.08, 0.75, 0.65, 0.70],
[0.64, 0.38, 0.02, 0.80, 0.70, 0.72]
];
for (const [px, py, pz, sx, sy, sz] of pieces) {
addBox(
group,
sx * scale,
sy * scale,
sz * scale,
px * scale,
py * scale,
pz * scale,
material,
false,
false
);
}
cloudEntries.push({
group,
baseY: y,
phase: random() * Math.PI * 2
});
}
const wetCloudMaterial = standardMaterial(0x657b86);
const dryCloudMaterial = standardMaterial(0xc7b18d);
createCloud(wetClimateGroup, 0.0, 11.4, -3.8, 1.25, wetCloudMaterial);
createCloud(wetClimateGroup, 4.2, 12.0, -0.3, 1.40, wetCloudMaterial);
createCloud(wetClimateGroup, 8.2, 12.6, 2.4, 1.50, wetCloudMaterial);
createCloud(wetClimateGroup, 12.0, 13.0, -2.1, 1.25, wetCloudMaterial);
createCloud(dryClimateGroup, 3.0, 12.4, 2.7, 0.82, dryCloudMaterial);
createCloud(dryClimateGroup, 9.7, 13.2, -4.4, 0.72, dryCloudMaterial);
// -------------------------------------------------------------------------
// Climate schematic: moving voxel airflow
// -------------------------------------------------------------------------
const flows = [];
const flowDummy = new THREE.Object3D();
const yAxis = new THREE.Vector3(0, 1, 0);
function createFlow(parent, points, color, count = 18, size = 0.16, speed = 0.065) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.45
);
const material = standardMaterial(color, {
emissive: color,
emissiveIntensity: 0.28,
roughness: 0.55
});
const mesh = new THREE.InstancedMesh(unitBox, material, count);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
parent.add(mesh);
flows.push({ mesh, curve, count, size, speed });
}
// Wet circulation: onshore low-level flow, ascent, and upper return.
createFlow(
wetClimateGroup,
[
[-14, 4.0, 6.8],
[-8.0, 3.7, 5.5],
[-2.0, 3.5, 3.0],
[3.0, 3.8, 0.4],
[6.6, 4.2, -2.2]
],
0x61d4cc,
23,
0.18,
0.060
);
createFlow(
wetClimateGroup,
[
[6.6, 4.2, -2.2],
[7.0, 7.0, -1.8],
[8.6, 10.0, -1.0],
[11.0, 12.2, 0.2]
],
0x87e1c3,
18,
0.18,
0.070
);
createFlow(
wetClimateGroup,
[
[11.0, 12.2, 0.2],
[5.0, 13.2, 1.6],
[-3.0, 12.8, 3.8],
[-11.0, 11.4, 6.2]
],
0x85c7e5,
20,
0.16,
0.052
);
// Dry circulation: continental outflow and descending air.
createFlow(
dryClimateGroup,
[
[13.0, 4.0, 1.8],
[7.0, 4.0, 3.5],
[0.0, 3.8, 5.5],
[-8.0, 3.3, 7.4],
[-14.0, 3.0, 8.5]
],
0xd39a5d,
23,
0.15,
0.055
);
createFlow(
dryClimateGroup,
[
[6.2, 12.5, 2.0],
[5.3, 9.5, 2.7],
[4.4, 6.5, 3.3],
[3.3, 4.2, 3.8]
],
0xe0b37a,
17,
0.14,
0.062
);
createFlow(
dryClimateGroup,
[
[-9.0, 12.0, 5.5],
[-2.0, 12.5, 4.2],
[3.4, 12.6, 2.7],
[6.2, 12.5, 2.0]
],
0xc79562,
18,
0.13,
0.048
);
function updateFlows(elapsed) {
for (const flow of flows) {
for (let i = 0; i < flow.count; i++) {
const t = (elapsed * flow.speed + i / flow.count) % 1;
const position = flow.curve.getPointAt(t);
const tangent = flow.curve.getTangentAt(t).normalize();
const fade = 0.72 + Math.sin(t * Math.PI) * 0.38;
flowDummy.position.copy(position);
flowDummy.quaternion.setFromUnitVectors(yAxis, tangent);
flowDummy.scale.set(
flow.size * fade,
flow.size * 2.7 * fade,
flow.size * fade
);
flowDummy.updateMatrix();
flow.mesh.setMatrixAt(i, flowDummy.matrix);
}
flow.mesh.instanceMatrix.needsUpdate = true;
}
}
// -------------------------------------------------------------------------
// Climate schematic: wet-state rain
// -------------------------------------------------------------------------
const rainCount = 100;
const rainGeometry = new THREE.BoxGeometry(0.035, 0.66, 0.035);
const rainMaterial = standardMaterial(0x3d9bb2, {
transparent: true,
opacity: 0.72,
depthWrite: false
});
const rain = new THREE.InstancedMesh(
rainGeometry,
rainMaterial,
rainCount
);
rain.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
rain.frustumCulled = false;
wetClimateGroup.add(rain);
const rainDrops = [];
for (let i = 0; i < rainCount; i++) {
rainDrops.push({
x: 0.0 + random() * 15.0,
y: 1.2 + random() * 11.5,
z: -7.0 + random() * 14.5,
speed: 5.2 + random() * 3.0
});
}
const rainDummy = new THREE.Object3D();
function updateRain(delta) {
for (let i = 0; i < rainCount; i++) {
const drop = rainDrops[i];
drop.y -= drop.speed * delta;
if (drop.y < 0.7) {
drop.y = 11.5 + random() * 2.5;
drop.x = 0.0 + random() * 15.0;
drop.z = -7.0 + random() * 14.5;
}
rainDummy.position.set(drop.x, drop.y, drop.z);
rainDummy.rotation.set(0, 0, -0.11);
rainDummy.scale.set(1, 1, 1);
rainDummy.updateMatrix();
rain.setMatrixAt(i, rainDummy.matrix);
}
rain.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// HTML labels projected from 3D anchors
// -------------------------------------------------------------------------
const labelDefinitions = [
{
element: document.querySelector("#label-ocean"),
position: new THREE.Vector3(-12.5, 0.5, 6.5)
},
{
element: document.querySelector("#label-coast"),
position: new THREE.Vector3(-0.8, 1.5, 5.7)
},
{
element: document.querySelector("#label-hills"),
position: new THREE.Vector3(12.4, 5.9, -2.8)
},
{
element: document.querySelector("#label-reservoir"),
position: new THREE.Vector3(5.8, 1.2, -3.5)
},
{
element: document.querySelector("#label-terraces"),
position: new THREE.Vector3(9.8, 3.8, 6.2)
}
];
const flowLabel = document.querySelector("#label-flow");
let currentClimate = "wet";
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of labelDefinitions) {
const projected = definition.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
definition.element.style.visibility = visible ? "visible" : "hidden";
definition.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
definition.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
const flowPosition =
currentClimate === "wet"
? new THREE.Vector3(-5.0, 4.7, 4.3)
: new THREE.Vector3(-2.5, 4.6, 5.7);
const projected = flowPosition.project(camera);
flowLabel.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
flowLabel.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
flowLabel.style.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
}
// -------------------------------------------------------------------------
// Climate toggle — does not touch storageGroup
// -------------------------------------------------------------------------
const wetButton = document.querySelector("#wet-button");
const dryButton = document.querySelector("#dry-button");
const stateDot = document.querySelector("#state-dot");
const climateName = document.querySelector("#climate-name");
const climateSummary = document.querySelector("#climate-summary");
const signals = document.querySelector("#signals");
function setClimate(state) {
currentClimate = state;
const isWet = state === "wet";
wetClimateGroup.visible = isWet;
dryClimateGroup.visible = !isWet;
wetButton.classList.toggle("active", isWet);
dryButton.classList.toggle("active", !isWet);
wetButton.setAttribute("aria-pressed", String(isWet));
dryButton.setAttribute("aria-pressed", String(!isWet));
stateDot.classList.toggle("dry", !isWet);
if (isWet) {
climateName.textContent = "Wet · onshore monsoon";
climateSummary.textContent =
"Moist air advances inland, rises over the hills, and returns aloft.";
signals.innerHTML = `
<span class="signal">ONSHORE</span>
<span class="signal">UPLIFT</span>
<span class="signal">OROGRAPHIC RAIN</span>
`;
flowLabel.innerHTML = `
Moist onshore flow
<small>climate schematic</small>
`;
} else {
climateName.textContent = "Dry · continental outflow";
climateSummary.textContent =
"Dry continental air moves toward the coast, with descending motion and no orographic rainfall.";
signals.innerHTML = `
<span class="signal dry">OFFSHORE</span>
<span class="signal dry">DESCENDING</span>
<span class="signal dry">NO OROGRAPHIC RAIN</span>
`;
flowLabel.innerHTML = `
Dry continental outflow
<small>climate schematic</small>
`;
}
}
wetButton.addEventListener("click", () => setClimate("wet"));
dryButton.addEventListener("click", () => setClimate("dry"));
// -------------------------------------------------------------------------
// Direct camera controls, implemented without addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.targetTheta -= deltaX * 0.005;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi + deltaY * 0.004,
0.48,
1.36
);
});
function stopDragging(event) {
dragging = false;
if (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.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius + event.deltaY * 0.018,
23,
57
);
},
{ passive: false }
);
function resetView() {
cameraState.targetTheta = 0.72;
cameraState.targetPhi = 1.03;
cameraState.targetRadius = 38;
}
document.querySelector("#reset-view").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
setClimate(currentClimate === "wet" ? "dry" : "wet");
}
if (event.code === "KeyR") {
resetView();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.targetTheta,
Math.min(1, delta * 8)
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.targetPhi,
Math.min(1, delta * 8)
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.targetRadius,
Math.min(1, delta * 7)
);
updateCamera();
for (const wave of oceanWaves) {
wave.mesh.position.y =
wave.baseY + Math.sin(elapsed * wave.speed + wave.phase) * 0.035;
}
for (const cloud of cloudEntries) {
cloud.group.position.y =
cloud.baseY + Math.sin(elapsed * 0.32 + cloud.phase) * 0.16;
}
updateFlows(elapsed);
if (currentClimate === "wet") {
updateRain(delta);
}
updateLabels();
renderer.render(scene, camera);
}
setClimate("wet");
animate();
</script>
</body>
</html>
```