Prompt specification
Build or customize the Three.js 3D scene "Rain routes across terraces" 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: Rain routes across terraces
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rain-routes-across-terraces-x1110
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows terrace farming. Animate symbolic runoff over the smooth slope and through stepped plots; highlight changed travel paths while labeling infiltration and erosion behavior as qualitative simplifications. Voxel style.
Working Three.js Starter (rain-routes-across-terraces-x1110):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Terrace Farming — Symbolic Runoff</title>
<style>
:root {
--ink: #26352f;
--muted: #68746c;
--paper: rgba(250, 248, 240, 0.88);
--line: rgba(38, 53, 47, 0.14);
--water: #27bfd0;
--changed: #e89a35;
--green: #708c59;
--orange: #d86e3e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ebe8dc;
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%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 42%, rgba(53, 58, 48, 0.08) 100%),
linear-gradient(180deg, rgba(255,255,255,0.12), transparent 30%);
z-index: 2;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow:
0 14px 40px rgba(53, 58, 48, 0.11),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.hero {
position: fixed;
z-index: 5;
top: 24px;
left: 24px;
width: min(420px, calc(100vw - 48px));
padding: 20px 22px 18px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 2px;
background: var(--changed);
}
h1 {
margin: 0;
max-width: 360px;
font-size: clamp(28px, 3.2vw, 46px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 790;
}
.hero p {
margin: 12px 0 0;
max-width: 365px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.actions {
position: fixed;
z-index: 8;
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border-radius: 14px;
}
.status {
display: flex;
align-items: center;
gap: 7px;
margin: 0 8px 0 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
white-space: nowrap;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 5px rgba(39, 191, 208, 0.12);
animation: pulse 1.7s ease-in-out infinite;
}
.status.paused .status-dot {
background: var(--changed);
box-shadow: 0 0 0 5px rgba(232, 154, 53, 0.13);
animation: none;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 9px rgba(39, 191, 208, 0);
}
}
.control-button {
min-height: 35px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,0.72);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 760;
transition: background 150ms ease, transform 150ms ease;
}
.control-button:hover {
background: #fff;
transform: translateY(-1px);
}
.control-button.active {
background: var(--ink);
color: #fff;
border-color: var(--ink);
}
.compare {
position: fixed;
z-index: 5;
right: 24px;
bottom: 82px;
width: 285px;
padding: 17px;
border-radius: 16px;
pointer-events: none;
}
.compare-title {
margin-bottom: 13px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.compare-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
align-items: start;
padding: 11px 0;
border-top: 1px solid var(--line);
}
.compare-row:first-of-type {
border-top: 0;
}
.compare-row strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.compare-row small {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.route-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 7px;
border-radius: 999px;
background: rgba(38, 53, 47, 0.07);
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.route-chip::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--water);
}
.route-chip.gold::before {
background: var(--changed);
}
.metric {
margin-top: 10px;
padding: 10px 11px;
border-radius: 10px;
background: rgba(232, 154, 53, 0.10);
color: #7b572b;
font-size: 10px;
line-height: 1.4;
}
.legend {
position: fixed;
z-index: 5;
left: 24px;
bottom: 82px;
width: 270px;
padding: 15px 17px;
border-radius: 15px;
pointer-events: none;
}
.legend-title {
margin-bottom: 11px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
color: var(--muted);
font-size: 10px;
}
.symbol {
position: relative;
flex: 0 0 auto;
width: 25px;
height: 12px;
}
.symbol.water::before,
.symbol.changed::before,
.symbol.reference::before {
content: "";
position: absolute;
left: 0;
right: 0;
top: 5px;
height: 3px;
border-radius: 3px;
background: var(--water);
}
.symbol.changed::before {
height: 4px;
background: var(--changed);
}
.symbol.reference::before {
height: 0;
border-top: 2px dashed rgba(38,53,47,0.48);
background: transparent;
}
.symbol.infiltration::before {
content: "↓";
position: absolute;
inset: -7px 0 0;
color: var(--water);
font-size: 21px;
font-weight: 800;
}
.symbol.erosion::before {
content: "";
position: absolute;
width: 7px;
height: 7px;
top: 2px;
left: 3px;
background: var(--orange);
box-shadow: 8px 2px 0 #e9aa60, 16px -1px 0 #be5d38;
transform: rotate(12deg);
}
.disclaimer {
position: fixed;
z-index: 6;
left: 50%;
bottom: 20px;
width: min(820px, calc(100vw - 48px));
transform: translateX(-50%);
padding: 11px 16px;
border-radius: 12px;
color: var(--muted);
text-align: center;
font-size: 10px;
line-height: 1.45;
pointer-events: none;
}
.disclaimer strong {
color: var(--ink);
letter-spacing: 0.07em;
}
.world-label {
position: fixed;
z-index: 4;
min-width: 125px;
padding: 9px 11px;
border: 1px solid rgba(255,255,255,0.82);
border-radius: 10px;
background: rgba(252, 250, 243, 0.90);
box-shadow: 0 8px 22px rgba(49, 55, 45, 0.13);
pointer-events: none;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 120ms linear;
}
.world-label::before {
content: "";
position: absolute;
left: 50%;
bottom: -11px;
width: 1px;
height: 10px;
background: rgba(38, 53, 47, 0.33);
}
.world-label .label-kicker {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.world-label strong {
display: block;
font-size: 10px;
line-height: 1.25;
}
.world-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
}
.world-label.plot-tag {
min-width: 0;
padding: 7px 9px;
border-radius: 7px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label.plot-tag::before {
display: none;
}
.tag-dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 5px;
border-radius: 2px;
background: var(--water);
vertical-align: 1px;
}
.tag-dot.gold {
background: var(--changed);
}
.loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #ebe8dc;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.hero {
top: 14px;
left: 14px;
width: min(355px, calc(100vw - 28px));
padding: 16px 17px;
}
.hero p {
display: none;
}
.actions {
top: auto;
right: 14px;
bottom: 66px;
}
.status {
display: none;
}
.compare {
right: 14px;
bottom: 122px;
width: 235px;
}
.legend {
display: none;
}
.disclaimer {
bottom: 12px;
width: calc(100vw - 28px);
}
}
@media (max-width: 560px) {
.compare {
display: none;
}
.actions {
bottom: 66px;
}
.control-button {
padding: 0 9px;
}
h1 {
font-size: 31px;
}
.world-label:not(.plot-tag) {
transform: translate(-50%, -50%) scale(0.9);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="hero panel">
<div class="eyebrow">Landscape systems / study 01</div>
<h1>Terrace farming<br />changes the runoff.</h1>
<p>
A symbolic, voxel landscape follows the same water pulse down a continuous
grade and through stepped agricultural plots. Drag to orbit; scroll to zoom.
</p>
</header>
<nav class="actions panel" aria-label="Animation controls">
<div class="status" id="status">
<span class="status-dot"></span>
<span id="statusText">FLOW ACTIVE</span>
</div>
<button class="control-button" id="pauseButton" type="button">Pause flow</button>
<button class="control-button" id="replayButton" type="button">Replay</button>
<button class="control-button active" id="referenceButton" type="button"
aria-pressed="true">Reference path</button>
<button class="control-button" id="viewButton" type="button">Reset view</button>
</nav>
<aside class="compare panel">
<div class="compare-title">Changed travel paths</div>
<div class="compare-row">
<div>
<strong>A · Continuous grade</strong>
<small>Water follows a short, concentrated fall line.</small>
</div>
<span class="route-chip">direct</span>
</div>
<div class="compare-row">
<div>
<strong>B · Stepped plots</strong>
<small>Each terrace interrupts and redirects the pulse.</small>
</div>
<span class="route-chip gold">stepped</span>
</div>
<div class="metric" id="metric">
Illustrative stepped route: calculating length…
</div>
</aside>
<aside class="legend panel">
<div class="legend-title">Symbol key</div>
<div class="legend-item"><span class="symbol water"></span>Runoff / water pulse</div>
<div class="legend-item"><span class="symbol changed"></span>Changed terraced path</div>
<div class="legend-item"><span class="symbol reference"></span>Former direct fall line</div>
<div class="legend-item"><span class="symbol infiltration"></span>Infiltration cue</div>
<div class="legend-item"><span class="symbol erosion"></span>Erosion focus cue</div>
</aside>
<div class="disclaimer panel">
<strong>QUALITATIVE MODEL</strong> — infiltration, detention, and erosion are
symbolic simplifications. No calibrated rainfall, soil, or hydrologic calculations are used.
</div>
<div class="world-label plot-tag" id="plotSmooth">
<span class="tag-dot"></span>A · Smooth grade
</div>
<div class="world-label plot-tag" id="plotTerrace">
<span class="tag-dot gold"></span>B · Stepped plots
</div>
<div class="world-label" id="runoffLabel">
<span class="label-kicker">Runoff pulse</span>
<strong>Surface water</strong>
<small>cyan voxel markers</small>
</div>
<div class="world-label" id="infiltrationLabel">
<span class="label-kicker">Infiltration</span>
<strong>More contact opportunity</strong>
<small>qualitative simplification</small>
</div>
<div class="world-label" id="erosionLabel">
<span class="label-kicker">Erosion focus</span>
<strong>Uninterrupted descent</strong>
<small>qualitative simplification</small>
</div>
<div class="world-label" id="pathLabel">
<span class="label-kicker">Changed travel path</span>
<strong>Direct fall line → stepped route</strong>
<small>highlighted in amber</small>
</div>
<div class="loading" id="loading">Building voxel landscape</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneContainer = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xebe8dc);
scene.fog = new THREE.Fog(0xebe8dc, 38, 72);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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;
sceneContainer.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit controls: no addons are imported.
const orbit = {
target: new THREE.Vector3(0, 1.4, 0),
radius: 33,
theta: 0.56,
phi: 0.84,
dragging: false,
lastX: 0,
lastY: 0
};
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.updateMatrixWorld();
}
function resetCamera() {
orbit.radius = 33;
orbit.theta = 0.56;
orbit.phi = 0.84;
updateCamera();
}
updateCamera();
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
orbit.theta -= dx * 0.005;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.004, 0.34, 1.24);
updateCamera();
});
function stopDragging(event) {
orbit.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("dblclick", resetCamera);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
22,
55
);
updateCamera();
},
{ passive: false }
);
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x65725f, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-9, 20, 13);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -22;
keyLight.shadow.camera.right = 22;
keyLight.shadow.camera.top = 22;
keyLight.shadow.camera.bottom = -22;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 55;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xffd2a0, 1.05);
fillLight.position.set(16, 9, -10);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function makeMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.94,
metalness: 0,
flatShading: true,
...extra
});
}
function addBox(parent, position, scale, color, extra = {}) {
const material = makeMaterial(color, extra);
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeInstancedBoxes(items, material = null) {
const mat = material || makeMaterial(0xffffff, { vertexColors: true });
const mesh = new THREE.InstancedMesh(unitBox, mat, items.length);
items.forEach((item, index) => {
dummy.position.set(...item.position);
dummy.rotation.set(...(item.rotation || [0, 0, 0]));
dummy.scale.set(...item.scale);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(item.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Floor and raised model base.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
makeMaterial(0xe8e5d9)
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.62;
floor.receiveShadow = true;
scene.add(floor);
addBox(scene, [0, -1.19, 0], [25.4, 0.82, 19.2], 0xd4cbb7);
addBox(scene, [0, -0.75, 0], [24.8, 0.12, 18.6], 0xe5ddca);
// The smooth plot is a continuous inclined slab over voxel soil supports.
const slopeY = (z) => 2.775 - 0.29125 * z;
const smoothColumns = [-9.7, -7.75, -5.8, -3.85, -1.9];
const slopeAngle = Math.asin(0.29125);
const slopeSupports = [];
smoothColumns.forEach((x, column) => {
const soilColor = [0x9c6d4b, 0xa87850, 0xb17b51, 0xa16d49, 0xaa7550][column];
const grassColor = [0x819361, 0x8a9b66, 0x789057, 0x8b9b65, 0x7c925d][column];
const body = addBox(
scene,
[
x,
2.775 - 0.275 * Math.cos(slopeAngle),
0
],
[1.88, 0.55, 16.5],
soilColor
);
body.rotation.x = slopeAngle;
const cap = addBox(
scene,
[
x,
2.775 - 0.06 * Math.cos(slopeAngle),
0
],
[1.89, 0.12, 16.5],
grassColor
);
cap.rotation.x = slopeAngle;
for (let row = 0; row < 10; row++) {
const z = -7.65 + row * 1.7;
slopeSupports.push({
position: [x, (slopeY(z) - 0.26 - 0.8) / 2, z],
scale: [1.88, slopeY(z) + 0.26, 1.64],
color: row % 2 ? 0xa16f49 : 0xaa7650
});
}
});
makeInstancedBoxes(slopeSupports);
// Four stepped agricultural terraces.
const terraces = [
{ z0: -8.0, z1: -3.6, y: 5.1 },
{ z0: -3.6, z1: 1.3, y: 3.2 },
{ z0: 1.3, z1: 6.2, y: 1.3 },
{ z0: 6.2, z1: 8.0, y: 0.45 }
];
function terraceLevelAt(z) {
if (z < -3.6) return 5.1;
if (z < 1.3) return 3.2;
if (z < 6.2) return 1.3;
return 0.45;
}
const terraceBodies = [];
const terraceCaps = [];
const terraceX = [2.2, 3.9, 5.6, 7.3, 9.0];
for (let row = 0; row < 10; row++) {
const z = -7.65 + row * 1.7;
const level = terraceLevelAt(z);
terraceX.forEach((x, column) => {
terraceBodies.push({
position: [x, (level - 0.8) / 2, z],
scale: [1.68, level + 0.8, 1.63],
color: (row + column) % 3 === 0 ? 0xa66d47 : 0xb2764d
});
terraceCaps.push({
position: [x, level + 0.055, z],
scale: [1.69, 0.11, 1.64],
color: (row + column) % 4 === 0 ? 0xc18a58 : 0xb97d4f
});
});
}
makeInstancedBoxes(terraceBodies);
makeInstancedBoxes(terraceCaps);
// Stone retaining faces emphasize the abrupt terrace breaks.
const wallMaterial = makeMaterial(0xc7ae82);
function retainingWall(z, upper, lower) {
const height = upper - lower;
const face = new THREE.Mesh(unitBox, wallMaterial);
face.position.set(6.1, lower + height / 2, z + 0.08);
face.scale.set(9.65, height, 0.18);
face.castShadow = true;
face.receiveShadow = true;
scene.add(face);
addBox(
scene,
[6.1, upper + 0.08, z],
[9.7, 0.16, 0.30],
0xd0ba8d
);
}
retainingWall(-3.6, 5.1, 3.2);
retainingWall(1.3, 3.2, 1.3);
retainingWall(6.2, 1.3, 0.45);
// Crop rows on the terraced side.
const cropHeads = [];
const cropStems = [];
terraces.forEach((terrace, bandIndex) => {
for (let x = 1.65; x <= 10.45; x += 0.68) {
if (Math.abs(x - 6.05) < 0.92) continue;
for (let z = terrace.z0 + 0.55; z < terrace.z1 - 0.38; z += 0.78) {
if (bandIndex === 3) continue;
const jitter = Math.sin(x * 8.7 + z * 4.3) * 0.08;
const px = x + jitter;
const pz = z + Math.cos(x * 4.1) * 0.06;
cropStems.push({
position: [px, terrace.y + 0.31, pz],
scale: [0.09, 0.36, 0.09],
color: 0x587348
});
cropHeads.push({
position: [px, terrace.y + 0.51, pz],
scale: [0.31, 0.25, 0.31],
color: (Math.floor(x + z) % 3 === 0) ? 0xb7a24f : 0x729054
});
}
}
});
makeInstancedBoxes(cropStems);
makeInstancedBoxes(cropHeads);
// Sparse voxel grass on the untreated smooth slope.
const grass = [];
smoothColumns.forEach((x, column) => {
for (let z = -7.4; z < 7.8; z += 0.82) {
if (Math.abs(x + 5.8) < 0.9) continue;
const gx = x + Math.sin(z * 3.1 + column) * 0.48;
grass.push({
position: [gx, slopeY(z) + 0.21, z],
scale: [0.20, 0.18, 0.20],
color: (column + Math.floor(z)) % 2 ? 0x728b55 : 0x9ba66d
});
}
});
makeInstancedBoxes(grass);
// Symbolic paths.
const smoothPoints = [];
for (let i = 0; i <= 20; i++) {
const z = -7.85 + (15.7 * i) / 20;
smoothPoints.push(
new THREE.Vector3(-5.8 + Math.sin(i * 0.5) * 0.08, slopeY(z) + 0.22, z)
);
}
const terracePoints = [
new THREE.Vector3(5.8, 5.32, -7.85),
new THREE.Vector3(6.15, 5.32, -6.5),
new THREE.Vector3(6.48, 5.32, -4.25),
new THREE.Vector3(6.35, 5.30, -3.74),
new THREE.Vector3(6.13, 4.72, -3.46),
new THREE.Vector3(6.03, 3.52, -3.24),
new THREE.Vector3(5.73, 3.42, -2.45),
new THREE.Vector3(5.53, 3.42, -0.55),
new THREE.Vector3(5.62, 3.40, 0.84),
new THREE.Vector3(5.87, 2.85, 1.18),
new THREE.Vector3(6.00, 2.18, 1.44),
new THREE.Vector3(6.15, 1.52, 1.67),
new THREE.Vector3(6.38, 1.52, 2.45),
new THREE.Vector3(6.58, 1.52, 4.55),
new THREE.Vector3(6.48, 1.50, 5.62),
new THREE.Vector3(6.32, 1.13, 6.03),
new THREE.Vector3(6.08, 0.70, 6.36),
new THREE.Vector3(5.88, 0.67, 7.18),
new THREE.Vector3(5.58, 0.67, 7.82)
];
const smoothCurve = new THREE.CatmullRomCurve3(
smoothPoints,
false,
"centripetal"
);
const terraceCurve = new THREE.CatmullRomCurve3(
terracePoints,
false,
"centripetal"
);
function addRoute(curve, color, radius, opacity = 1) {
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 220, radius, 7, false),
new THREE.MeshBasicMaterial({
color,
transparent: opacity < 1,
opacity,
toneMapped: false
})
);
scene.add(tube);
return tube;
}
addRoute(smoothCurve, 0x21bfd0, 0.055, 0.95);
const changedGlow = addRoute(terraceCurve, 0xe89a35, 0.16, 0.13);
const changedRoute = addRoute(terraceCurve, 0xf0a83c, 0.072, 1);
changedGlow.renderOrder = 1;
changedRoute.renderOrder = 2;
// Dashed former fall line projected over the terraced side.
const referencePoints = [];
for (let i = 0; i <= 32; i++) {
const z = -7.85 + (15.7 * i) / 32;
referencePoints.push(
new THREE.Vector3(5.8 + Math.sin(i * 0.36) * 0.12, slopeY(z) + 0.24, z)
);
}
const referenceGeometry = new THREE.BufferGeometry().setFromPoints(referencePoints);
const referenceLine = new THREE.Line(
referenceGeometry,
new THREE.LineDashedMaterial({
color: 0x49574e,
dashSize: 0.34,
gapSize: 0.23,
transparent: true,
opacity: 0.55,
toneMapped: false
})
);
referenceLine.computeLineDistances();
scene.add(referenceLine);
const smoothLength = smoothCurve.getLength();
const terraceLength = terraceCurve.getLength();
const lengthChange = Math.round(((terraceLength - smoothLength) / smoothLength) * 100);
document.getElementById("metric").textContent =
`Illustrative stepped route: about ${lengthChange}% longer in this schematic. ` +
`Geometry cue only—not a hydrologic prediction.`;
// Animated symbolic runoff cubes.
function createWater(curve, count, speed, color) {
const mesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({ color, toneMapped: false }),
count
);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
scene.add(mesh);
const offsets = Array.from({ length: count }, (_, i) => i / count);
return { mesh, curve, count, speed, offsets };
}
const smoothWater = createWater(smoothCurve, 74, 0.070, 0x42dce5);
const terraceWater = createWater(terraceCurve, 96, 0.045, 0x73f0ed);
const forward = new THREE.Vector3(0, 0, 1);
function updateWater(water, time) {
for (let i = 0; i < water.count; i++) {
const t = (time * water.speed + water.offsets[i]) % 1;
const position = water.curve.getPointAt(t);
const tangent = water.curve.getTangentAt(t).normalize();
dummy.position.copy(position);
dummy.quaternion.setFromUnitVectors(forward, tangent);
const variation = 0.82 + Math.sin(i * 3.71) * 0.12;
dummy.scale.set(0.115 * variation, 0.115 * variation, 0.31 * variation);
dummy.updateMatrix();
water.mesh.setMatrixAt(i, dummy.matrix);
}
water.mesh.instanceMatrix.needsUpdate = true;
}
// Schematic infiltration markers sink into the terrace soil.
const infiltrationAnchors = [
new THREE.Vector3(8.35, 3.2, -0.45),
new THREE.Vector3(9.25, 3.2, 0.35),
new THREE.Vector3(8.55, 1.3, 4.05),
new THREE.Vector3(9.45, 1.3, 5.0),
new THREE.Vector3(3.05, 5.1, -6.55),
new THREE.Vector3(3.85, 5.1, -5.65)
];
const infiltrationMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({
color: 0x238ec6,
transparent: true,
opacity: 0.82,
toneMapped: false
}),
42
);
infiltrationMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
infiltrationMesh.frustumCulled = false;
scene.add(infiltrationMesh);
function updateInfiltration(time) {
for (let i = 0; i < 42; i++) {
const anchor = infiltrationAnchors[i % infiltrationAnchors.length];
const phase = (time * 0.34 + i * 0.173) % 1;
const scale = phase < 0.82 ? 0.115 * (1 - phase * 0.68) : 0;
dummy.position.set(
anchor.x + Math.sin(i * 2.13) * 0.17,
anchor.y + 0.68 - phase * 1.02,
anchor.z + Math.cos(i * 1.72) * 0.17
);
dummy.rotation.set(0, i * 0.31, 0);
dummy.scale.setScalar(scale);
dummy.updateMatrix();
infiltrationMesh.setMatrixAt(i, dummy.matrix);
}
infiltrationMesh.instanceMatrix.needsUpdate = true;
}
// Orange erosion chips move down the uninterrupted grade.
const erosionMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({
color: 0xe0703e,
toneMapped: false
}),
30
);
erosionMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
erosionMesh.frustumCulled = false;
scene.add(erosionMesh);
function updateErosion(time) {
for (let i = 0; i < 30; i++) {
const t = (time * 0.085 + i / 30) % 1;
const z = -7.5 + t * 15;
const x = -5.8 + Math.sin(i * 5.37) * 0.52;
const pulse = 0.5 + 0.5 * Math.sin(time * 3 + i);
dummy.position.set(x, slopeY(z) + 0.19, z);
dummy.rotation.set(i * 0.2, i * 0.37, i * 0.16);
dummy.scale.setScalar(0.075 + pulse * 0.045);
dummy.updateMatrix();
erosionMesh.setMatrixAt(i, dummy.matrix);
}
erosionMesh.instanceMatrix.needsUpdate = true;
}
// Projected labels.
const labelDefinitions = [
{
id: "plotSmooth",
position: new THREE.Vector3(-7.2, 5.65, -5.8),
offset: [-20, -12]
},
{
id: "plotTerrace",
position: new THREE.Vector3(7.1, 5.72, -5.8),
offset: [16, -12]
},
{
id: "runoffLabel",
position: new THREE.Vector3(5.8, 4.0, -3.25),
offset: [63, -2]
},
{
id: "infiltrationLabel",
position: new THREE.Vector3(9.05, 3.95, -0.15),
offset: [47, -18]
},
{
id: "erosionLabel",
position: new THREE.Vector3(-5.8, 1.35, 2.65),
offset: [-66, -8]
},
{
id: "pathLabel",
position: new THREE.Vector3(6.45, 1.95, 4.25),
offset: [74, 16]
}
];
const projected = new THREE.Vector3();
function updateLabels() {
labelDefinitions.forEach((definition) => {
const element = document.getElementById(definition.id);
projected.copy(definition.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + definition.offset[0];
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + definition.offset[1];
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = "1";
});
}
// UI controls.
let paused = false;
let simulationTime = 0;
const pauseButton = document.getElementById("pauseButton");
const replayButton = document.getElementById("replayButton");
const referenceButton = document.getElementById("referenceButton");
const viewButton = document.getElementById("viewButton");
const status = document.getElementById("status");
const statusText = document.getElementById("statusText");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume flow" : "Pause flow";
status.classList.toggle("paused", paused);
statusText.textContent = paused ? "FLOW PAUSED" : "FLOW ACTIVE";
});
replayButton.addEventListener("click", () => {
simulationTime = 0;
});
referenceButton.addEventListener("click", () => {
const visible = !referenceLine.visible;
referenceLine.visible = visible;
referenceButton.classList.toggle("active", visible);
referenceButton.setAttribute("aria-pressed", String(visible));
});
viewButton.addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Main loop.
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) simulationTime += delta;
updateWater(smoothWater, simulationTime);
updateWater(terraceWater, simulationTime);
updateInfiltration(simulationTime);
updateErosion(simulationTime);
updateLabels();
renderer.render(scene, camera);
}
updateWater(smoothWater, 0);
updateWater(terraceWater, 0);
updateInfiltration(0);
updateErosion(0);
updateLabels();
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```