Prompt specification
Build or customize the Three.js 3D scene "Delta restoration comparison model" 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: Delta restoration comparison model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/delta-restoration-comparison-model-x1132
Scene Description Prompt:
Delta restoration comparison model. Present two adjacent delta tiles with different wetland extents; a tide slider reveals storage areas and navigable channels, using qualitative behavior and matching basin levels. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (delta-restoration-comparison-model-x1132):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Delta Restoration Comparison</title>
<style>
:root {
--ink: #18383b;
--muted: #667a76;
--paper: #f5f2e9;
--line: rgba(24, 56, 59, 0.16);
--teal: #2a8e8b;
--teal-bright: #56c7bb;
--gold: #d6a955;
--green: #718b50;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 38%, #f8f4e9 0%, #e8e3d6 58%, #d8d4c8 100%);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 26px;
left: 30px;
width: min(460px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--teal);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4vw, 50px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.98;
}
.subtitle {
max-width: 420px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.model-tag {
position: fixed;
z-index: 12;
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(24, 56, 59, 0.14);
border-radius: 999px;
background: rgba(248, 246, 238, 0.8);
box-shadow: 0 8px 30px rgba(37, 59, 56, 0.07);
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
pointer-events: none;
}
.model-tag i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal-bright);
box-shadow: 0 0 0 4px rgba(86, 199, 187, 0.16);
}
.tile-label {
position: fixed;
z-index: 8;
min-width: 205px;
padding: 11px 13px 12px;
transform: translate(-50%, -100%);
border: 1px solid rgba(24, 56, 59, 0.13);
border-radius: 13px;
background: rgba(248, 246, 238, 0.9);
box-shadow: 0 12px 30px rgba(37, 59, 56, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
transition: opacity 120ms ease;
}
.tile-label::after {
position: absolute;
bottom: -7px;
left: 50%;
width: 12px;
height: 12px;
content: "";
transform: translateX(-50%) rotate(45deg);
border-right: 1px solid rgba(24, 56, 59, 0.13);
border-bottom: 1px solid rgba(24, 56, 59, 0.13);
background: rgba(248, 246, 238, 0.9);
}
.tile-label .label-row {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 5px;
}
.tile-label .label-row i {
width: 8px;
height: 8px;
border-radius: 50%;
background: #8a9b86;
}
.tile-label.restored .label-row i {
background: var(--teal-bright);
box-shadow: 0 0 0 4px rgba(86, 199, 187, 0.15);
}
.tile-label .label-row span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.tile-label strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
letter-spacing: -0.02em;
}
.tile-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.legend {
position: fixed;
z-index: 9;
left: 30px;
bottom: 210px;
display: grid;
gap: 8px;
padding: 12px 14px;
border: 1px solid rgba(24, 56, 59, 0.11);
border-radius: 13px;
background: rgba(248, 246, 238, 0.78);
box-shadow: 0 10px 30px rgba(37, 59, 56, 0.06);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.legend-row b {
display: inline-block;
width: 17px;
height: 8px;
border-radius: 99px;
background: #62b9b3;
}
.legend-row b.wetland {
background: #718b50;
}
.legend-row b.basin {
height: 9px;
border: 2px solid var(--gold);
background: transparent;
}
.legend-row b.route {
height: 3px;
background: #d9fff2;
box-shadow: 0 0 0 1px rgba(24, 56, 59, 0.2);
}
.control-panel {
position: fixed;
z-index: 15;
left: 50%;
bottom: 24px;
display: grid;
grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.9fr);
width: min(900px, calc(100vw - 48px));
overflow: hidden;
transform: translateX(-50%);
border: 1px solid rgba(24, 56, 59, 0.14);
border-radius: 20px;
background: rgba(249, 247, 240, 0.94);
box-shadow:
0 22px 70px rgba(38, 57, 53, 0.16),
0 3px 10px rgba(38, 57, 53, 0.05);
backdrop-filter: blur(18px);
}
.tide-controls {
padding: 20px 24px 18px;
border-right: 1px solid var(--line);
}
.control-heading {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
}
.control-heading > span:first-child {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#phase {
padding: 4px 7px;
border-radius: 6px;
background: rgba(42, 142, 139, 0.11);
color: var(--teal);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.matched-badge {
margin-left: auto;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.matched-badge::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 50%;
content: "";
background: var(--gold);
vertical-align: 1px;
}
#tide {
--fill: 42%;
width: 100%;
height: 7px;
margin: 4px 0 8px;
border-radius: 99px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--teal) 0%,
var(--teal-bright) var(--fill),
rgba(24, 56, 59, 0.13) var(--fill),
rgba(24, 56, 59, 0.13) 100%
);
cursor: pointer;
}
#tide::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 4px solid var(--paper);
border-radius: 50%;
appearance: none;
background: var(--teal);
box-shadow:
0 0 0 1px rgba(24, 56, 59, 0.16),
0 4px 12px rgba(24, 56, 59, 0.25);
}
#tide::-moz-range-thumb {
width: 13px;
height: 13px;
border: 4px solid var(--paper);
border-radius: 50%;
background: var(--teal);
box-shadow:
0 0 0 1px rgba(24, 56, 59, 0.16),
0 4px 12px rgba(24, 56, 59, 0.25);
}
#tide:focus-visible {
box-shadow: 0 0 0 4px rgba(42, 142, 139, 0.16);
}
.range-labels {
display: flex;
justify-content: space-between;
color: #81908c;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
}
.range-hint {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.state-panel {
display: grid;
grid-template-columns: 1fr auto;
gap: 0 14px;
align-content: center;
padding: 18px 22px;
}
.state-copy {
grid-column: 1 / -1;
}
.state-copy h2 {
margin: 0 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
letter-spacing: -0.02em;
}
.state-copy p {
min-height: 42px;
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.gauge-title {
align-self: end;
margin-bottom: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.gauge-pair {
display: grid;
gap: 7px;
width: 125px;
}
.gauge-label {
display: grid;
grid-template-columns: 47px 1fr;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
}
.gauge-track {
height: 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(24, 56, 59, 0.1);
}
.gauge-track i {
display: block;
width: 42%;
height: 100%;
border-radius: inherit;
background: var(--gold);
transition: width 120ms ease;
}
.help {
position: fixed;
z-index: 8;
right: 30px;
bottom: 27px;
color: rgba(24, 56, 59, 0.58);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #ece7dc;
transition: opacity 450ms ease, visibility 450ms ease;
}
#loading.ready {
visibility: hidden;
opacity: 0;
}
.loading-inner {
display: grid;
justify-items: center;
gap: 13px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.loader {
width: 34px;
height: 34px;
border: 2px solid rgba(42, 142, 139, 0.15);
border-top-color: var(--teal);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 850px) {
.topbar {
top: 20px;
left: 20px;
}
.model-tag {
top: 20px;
right: 20px;
}
.model-tag span {
display: none;
}
.legend {
display: none;
}
.control-panel {
grid-template-columns: 1fr;
bottom: 12px;
width: calc(100vw - 24px);
}
.tide-controls {
padding: 14px 17px 12px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.state-panel {
padding: 12px 17px 13px;
}
.state-copy p {
min-height: 0;
}
.gauge-title,
.gauge-pair {
display: none;
}
.help {
display: none;
}
}
@media (max-width: 600px) {
.topbar {
width: calc(100vw - 40px);
}
h1 {
max-width: 300px;
font-size: 34px;
}
.subtitle {
max-width: 290px;
font-size: 11px;
}
.tile-label {
min-width: 145px;
padding: 8px 10px;
}
.tile-label strong {
font-size: 16px;
}
.tile-label small {
display: none;
}
.state-copy h2 {
font-size: 17px;
}
}
@media (max-height: 700px) {
.subtitle {
display: none;
}
.legend {
display: none;
}
.control-panel {
bottom: 12px;
}
.state-copy p {
min-height: 0;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional comparison of two delta restoration tiles"></canvas>
<header class="topbar">
<div class="eyebrow">Delta restoration study</div>
<h1>Room for the tide</h1>
<p class="subtitle">
Two adjacent tiles compare the same delta with a broader, connected wetland system.
Raise the tide to expose storage basins and navigable channels.
</p>
</header>
<div class="model-tag" title="The model demonstrates qualitative behavior rather than site-specific forecasts.">
<i></i>
<span>Qualitative model · not a forecast</span>
</div>
<div id="labelExisting" class="tile-label">
<div class="label-row"><i></i><span>Existing condition</span></div>
<strong>Narrow & fragmented</strong>
<small>Limited wetland room and pocket storage</small>
</div>
<div id="labelRestored" class="tile-label restored">
<div class="label-row"><i></i><span>Restored condition</span></div>
<strong>Broad & connected</strong>
<small>Expanded wetland and connected storage</small>
</div>
<aside class="legend" aria-label="Scene legend">
<div class="legend-row"><b></b><span>Tidal water</span></div>
<div class="legend-row"><b class="wetland"></b><span>Wetland extent</span></div>
<div class="legend-row"><b class="basin"></b><span>Storage basin</span></div>
<div class="legend-row"><b class="route"></b><span>Navigable channel</span></div>
</aside>
<section class="control-panel" aria-label="Tide controls and qualitative behavior">
<div class="tide-controls">
<div class="control-heading">
<span>Tide</span>
<strong id="phase">Rising tide</strong>
<span class="matched-badge">Matched basin level</span>
</div>
<input
id="tide"
type="range"
min="0"
max="100"
value="42"
step="1"
aria-label="Tide level"
aria-valuetext="Rising tide"
/>
<div class="range-labels">
<span>Low tide</span>
<span>Rising</span>
<span>High tide</span>
</div>
<p class="range-hint">
Raise the slider to reveal basin storage, highlight connected routes, and reconnect wetland flats.
</p>
</div>
<div class="state-panel">
<div class="state-copy">
<h2 id="stateTitle">Connected basins begin to fill</h2>
<p id="stateText">
Water spreads into side channels. The restored tile gains more connected storage before the reference.
</p>
</div>
<div class="gauge-title">Basin level</div>
<div class="gauge-pair" aria-label="Both basin levels are matched">
<div class="gauge-label">
<span>Existing</span>
<div class="gauge-track"><i id="gaugeExisting"></i></div>
</div>
<div class="gauge-label">
<span>Restored</span>
<div class="gauge-track"><i id="gaugeRestored"></i></div>
</div>
</div>
</div>
</section>
<div class="help">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="loading">
<div class="loading-inner">
<div class="loader"></div>
<span>Building the delta tiles</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const tideSlider = document.getElementById("tide");
const phaseElement = document.getElementById("phase");
const stateTitle = document.getElementById("stateTitle");
const stateText = document.getElementById("stateText");
const gaugeExisting = document.getElementById("gaugeExisting");
const gaugeRestored = document.getElementById("gaugeRestored");
const TILE_W = 9.4;
const TILE_D = 7.4;
const TILE_BASE_Y = -0.57;
const GOLD = new THREE.Color("#d6a955");
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(edge0, edge1, value) {
const x = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return x * x * (3 - 2 * x);
}
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.innerHTML =
'<div class="loading-inner">WebGL could not be initialized in this browser.</div>';
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe7e1d5, 26, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff9e8, 0x687566, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 3.1);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bc9c5, 0.65);
fill.position.set(10, 7, -8);
scene.add(fill);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0xd9d3c5,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.16;
ground.receiveShadow = true;
scene.add(ground);
function mainX(z) {
return 0.16 * Math.sin((z + 2.2) * 0.8);
}
const mainPath = [];
for (let z = -3.85; z <= 3.95; z += 0.25) {
mainPath.push([mainX(z), z]);
}
const channelPaths = [
mainPath,
[
[mainX(-1.2), -1.2],
[-0.85, -0.2],
[-1.55, 0.85],
[-2.55, 1.45],
[-3.65, 3.72]
],
[
[mainX(-1.2), -1.2],
[1.05, -0.12],
[2.35, 1.55],
[3.65, 3.78]
],
[
[mainX(0.7), 0.7],
[0.05, 1.85],
[0.55, 3.76]
]
];
const sampledPaths = channelPaths.map((path) => {
const curve = new THREE.CatmullRomCurve3(
path.map(([x, z]) => new THREE.Vector3(x, 0, z)),
false,
"catmullrom",
0.25
);
return curve.getPoints(60);
});
function distanceToChannels(x, z) {
let minimum = Infinity;
for (const points of sampledPaths) {
for (let i = 1; i < points.length; i++) {
const ax = points[i - 1].x;
const az = points[i - 1].z;
const bx = points[i].x;
const bz = points[i].z;
const dx = bx - ax;
const dz = bz - az;
const lengthSquared = dx * dx + dz * dz;
const t = lengthSquared
? clamp(((x - ax) * dx + (z - az) * dz) / lengthSquared, 0, 1)
: 0;
const px = ax + dx * t;
const pz = az + dz * t;
const distance = Math.hypot(x - px, z - pz);
minimum = Math.min(minimum, distance);
}
}
return minimum;
}
const tileDefinitions = [
{
id: "existing",
x: -5.05,
seed: 31,
channelWidth: 0.34,
reedCount: 48,
shrubCount: 22,
wetlands: [
{ x: -1.95, z: 1.15, rx: 1.02, rz: 0.56 },
{ x: 2.3, z: 1.62, rx: 1.32, rz: 0.7 }
],
basins: [
{ x: 2.35, z: 1.55, rx: 0.8, rz: 0.54, bottom: -0.34 }
],
waterColor: 0x78aaa7
},
{
id: "restored",
x: 5.05,
seed: 97,
channelWidth: 0.43,
reedCount: 142,
shrubCount: 64,
wetlands: [
{ x: -2.55, z: 1.45, rx: 1.85, rz: 1.04 },
{ x: 2.45, z: 1.55, rx: 1.94, rz: 1.13 },
{ x: 0.1, z: 2.78, rx: 1.3, rz: 0.56 }
],
basins: [
{
x: 2.35,
z: 1.55,
rx: 1.46,
rz: 0.94,
bottom: -0.34
},
{
x: -2.55,
z: 1.45,
rx: 1.22,
rz: 0.78,
bottom: -0.34
}
],
waterColor: 0x51b9b1
}
];
const state = {
t: 0.42,
level: 0,
cameraDistance: 19.5,
yaw: 0.46,
pitch: 0.7
};
function wetlandMask(x, z, definition) {
let maximum = 0;
for (const patch of definition.wetlands) {
const normalized = Math.hypot(
(x - patch.x) / patch.rx,
(z - patch.z) / patch.rz
);
const mask = 1 - smoothstep(0.08, 1, normalized);
maximum = Math.max(maximum, mask);
}
return maximum;
}
function basinMask(x, z, definition) {
let maximum = 0;
for (const basin of definition.basins) {
const normalized = Math.hypot(
(x - basin.x) / basin.rx,
(z - basin.z) / basin.rz
);
maximum = Math.max(maximum, 1 - smoothstep(0.25, 1, normalized));
}
return maximum;
}
function terrainHeight(x, z, definition) {
let height =
0.58 -
0.047 * (z + TILE_D / 2) +
0.09 * Math.sin(x * 0.82 + z * 0.42) +
0.055 * Math.cos(z * 1.1 - x * 0.34);
const seaBlend = smoothstep(1.7, 3.72, z);
height = lerp(height, -0.25 + 0.025 * Math.sin(x), seaBlend * 0.82);
const wet = wetlandMask(x, z, definition);
const wetlandTarget = -0.025 + 0.035 * Math.sin(x * 1.7 + z);
height = lerp(height, wetlandTarget, wet * 0.8);
const channelDistance = distanceToChannels(x, z);
const channelShape = Math.exp(
-Math.pow(channelDistance / definition.channelWidth, 4)
);
height -= 0.72 * channelShape;
const basin = basinMask(x, z, definition);
if (basin > 0) {
const target = definition.basins.reduce((lowest, item) => {
const normalized = Math.hypot(
(x - item.x) / item.rx,
(z - item.z) / item.rz
);
return normalized < 0.75 ? Math.min(lowest, item.bottom) : lowest;
}, Infinity);
if (Number.isFinite(target)) {
height = lerp(height, target, basin);
}
}
return height;
}
const waterMeshes = [];
const storageLines = [];
const wetlandLines = [];
const channelMaterials = [];
const flowMarkers = [];
const tileGroups = new Map();
function createSkirt(definition) {
const positions = [];
const edgeSamples = 30;
function addEdge(pointA, pointB) {
const topA = terrainHeight(pointA[0], pointA[1], definition);
const topB = terrainHeight(pointB[0], pointB[1], definition);
positions.push(
pointA[0], topA, pointA[1],
pointA[0], TILE_BASE_Y, pointA[1],
pointB[0], topB, pointB[1],
pointB[0], topB, pointB[1],
pointA[0], TILE_BASE_Y, pointA[1],
pointB[0], TILE_BASE_Y, pointB[1]
);
}
for (let i = 0; i < edgeSamples; i++) {
const t0 = i / edgeSamples;
const t1 = (i + 1) / edgeSamples;
const x0 = lerp(-TILE_W / 2, TILE_W / 2, t0);
const x1 = lerp(-TILE_W / 2, TILE_W / 2, t1);
const z0 = lerp(-TILE_D / 2, TILE_D / 2, t0);
const z1 = lerp(-TILE_D / 2, TILE_D / 2, t1);
addEdge([x0, -TILE_D / 2], [x1, -TILE_D / 2]);
addEdge([TILE_W / 2, z0], [TILE_W / 2, z1]);
addEdge([x1, TILE_D / 2], [x0, TILE_D / 2]);
addEdge([-TILE_W / 2, z1], [-TILE_W / 2, z0]);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: 0x82785c,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createTerrain(definition) {
let geometry = new THREE.PlaneGeometry(TILE_W, TILE_D, 30, 24);
geometry.rotateX(-Math.PI / 2);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const z = positions.getZ(i);
positions.setY(i, terrainHeight(x, z, definition));
}
geometry = geometry.toNonIndexed();
const nonIndexedPositions = geometry.attributes.position;
const colors = new Float32Array(nonIndexedPositions.count * 3);
const lowColor = new THREE.Color("#9f936f");
const highColor = new THREE.Color("#c0b28a");
const wetColor = new THREE.Color("#6f874b");
const mudColor = new THREE.Color("#59695c");
for (let i = 0; i < nonIndexedPositions.count; i += 3) {
const x =
(nonIndexedPositions.getX(i) +
nonIndexedPositions.getX(i + 1) +
nonIndexedPositions.getX(i + 2)) /
3;
const y =
(nonIndexedPositions.getY(i) +
nonIndexedPositions.getY(i + 1) +
nonIndexedPositions.getY(i + 2)) /
3;
const z =
(nonIndexedPositions.getZ(i) +
nonIndexedPositions.getZ(i + 1) +
nonIndexedPositions.getZ(i + 2)) /
3;
const color = lowColor.clone().lerp(highColor, clamp((y + 0.05) / 0.95, 0, 1));
const wet = wetlandMask(x, z, definition);
color.lerp(wetColor, wet * 0.86);
const channelDistance = distanceToChannels(x, z);
if (channelDistance < definition.channelWidth * 1.2) {
color.lerp(
mudColor,
1 - smoothstep(definition.channelWidth * 0.45, definition.channelWidth * 1.2, channelDistance)
);
}
const faceIndex = i / 3;
const jitter =
(Math.sin((faceIndex + 1) * 12.9898 + definition.seed * 17.31) * 43758.5453) %
1;
color.offsetHSL(0, 0, (jitter - 0.5) * 0.045);
for (let vertex = 0; vertex < 3; vertex++) {
const offset = (i + vertex) * 3;
colors[offset] = color.r;
colors[offset + 1] = color.g;
colors[offset + 2] = color.b;
}
}
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true
});
const terrain = new THREE.Mesh(geometry, material);
terrain.castShadow = true;
terrain.receiveShadow = true;
return terrain;
}
function createWetlandOutlines(definition) {
for (const patch of definition.wetlands) {
const points = [];
for (let i = 0; i < 56; i++) {
const angle = (i / 56) * Math.PI * 2;
const x = patch.x + Math.cos(angle) * patch.rx;
const z = patch.z + Math.sin(angle) * patch.rz;
points.push(new THREE.Vector3(x, terrainHeight(x, z, definition) + 0.035, z));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: definition.id === "restored" ? 0x8fbf68 : 0x83945f,
transparent: true,
opacity: definition.id === "restored" ? 0.55 : 0.34,
depthTest: false,
depthWrite: false
});
const line = new THREE.LineLoop(geometry, material);
line.renderOrder = 4;
wetlandLines.push(line);
return line;
}
return null;
}
function createStorageOutlines(definition) {
for (const basin of definition.basins) {
const points = [];
for (let i = 0; i < 64; i++) {
const angle = (i / 64) * Math.PI * 2;
points.push(
new THREE.Vector3(
basin.x + Math.cos(angle) * basin.rx,
0,
basin.z + Math.sin(angle) * basin.rz
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: GOLD,
transparent: true,
opacity: 0,
depthTest: false,
depthWrite: false
});
const line = new THREE.LineLoop(geometry, material);
line.renderOrder = 5;
storageLines.push(line);
definition.group.add(line);
}
}
function createChannelLines(definition) {
const curves = [];
for (const path of channelPaths) {
const curve = new THREE.CatmullRomCurve3(
path.map(([x, z]) => new THREE.Vector3(x, 0, z)),
false,
"catmullrom",
0.25
);
curves.push(curve);
const geometry = new THREE.TubeGeometry(
curve,
64,
definition.id === "restored" ? 0.034 : 0.025,
5,
false
);
const material = new THREE.MeshBasicMaterial({
color: 0xd9fff1,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const tube = new THREE.Mesh(geometry, material);
tube.position.y = state.level + 0.025;
tube.renderOrder = 3;
definition.group.add(tube);
channelMaterials.push(material);
}
const markerGeometry = new THREE.ConeGeometry(0.068, 0.22, 3);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xf0fff8,
transparent: true,
opacity: 0.7,
depthWrite: false
});
const markerCount = definition.id === "restored" ? 12 : 8;
for (let i = 0; i < markerCount; i++) {
const curve = curves[i % curves.length];
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.userData.curve = curve;
marker.userData.offset = i / markerCount + definition.seed * 0.003;
marker.renderOrder = 4;
definition.group.add(marker);
flowMarkers.push(marker);
}
}
function createVegetation(definition) {
const random = seededRandom(definition.seed);
const reedGeometry = new THREE.ConeGeometry(0.12, 0.62, 4);
reedGeometry.translate(0, 0.31, 0);
const reedMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const reeds = new THREE.InstancedMesh(
reedGeometry,
reedMaterial,
definition.reedCount
);
const dummy = new THREE.Object3D();
for (let i = 0; i < definition.reedCount; i++) {
let x = 0;
let z = 0;
let valid = false;
for (let attempt = 0; attempt < 100; attempt++) {
const patch =
definition.wetlands[
Math.floor(random() * definition.wetlands.length)
];
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random());
x = patch.x + Math.cos(angle) * patch.rx * radius;
z = patch.z + Math.sin(angle) * patch.rz * radius;
if (
wetlandMask(x, z, definition) > 0.12 &&
distanceToChannels(x, z) > 0.23 &&
basinMask(x, z, definition) < 0.7
) {
valid = true;
break;
}
}
if (!valid) {
x = definition.wetlands[0].x;
z = definition.wetlands[0].z;
}
const height = terrainHeight(x, z, definition);
const scale = 0.68 + random() * 0.72;
dummy.position.set(x, height + 0.005, z);
dummy.rotation.set(
(random() - 0.5) * 0.12,
random() * Math.PI,
(random() - 0.5) * 0.14
);
dummy.scale.set(scale, scale * (0.85 + random() * 0.6), scale);
dummy.updateMatrix();
reeds.setMatrixAt(i, dummy.matrix);
reeds.setColorAt(
i,
new THREE.Color().setHSL(
0.22 + random() * 0.055,
0.27 + random() * 0.14,
0.28 + random() * 0.14
)
);
}
reeds.instanceMatrix.needsUpdate = true;
if (reeds.instanceColor) reeds.instanceColor.needsUpdate = true;
reeds.castShadow = true;
reeds.receiveShadow = true;
definition.group.add(reeds);
const shrubGeometry = new THREE.IcosahedronGeometry(0.22, 0);
const shrubMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const shrubs = new THREE.InstancedMesh(
shrubGeometry,
shrubMaterial,
definition.shrubCount
);
for (let i = 0; i < definition.shrubCount; i++) {
let x = 0;
let z = 0;
let valid = false;
for (let attempt = 0; attempt < 120; attempt++) {
const patch =
definition.wetlands[
Math.floor(random() * definition.wetlands.length)
];
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random());
x = patch.x + Math.cos(angle) * patch.rx * radius;
z = patch.z + Math.sin(angle) * patch.rz * radius;
if (
wetlandMask(x, z, definition) > 0.25 &&
distanceToChannels(x, z) > 0.36
) {
valid = true;
break;
}
}
if (!valid) {
x = definition.wetlands[0].x;
z = definition.wetlands[0].z;
}
const height = terrainHeight(x, z, definition);
const scale = 0.6 + random() * 1.25;
dummy.position.set(x, height + 0.12, z);
dummy.rotation.set(random() * 0.2, random() * Math.PI, random() * 0.2);
dummy.scale.set(scale, scale * (0.65 + random() * 0.4), scale);
dummy.updateMatrix();
shrubs.setMatrixAt(i, dummy.matrix);
shrubs.setColorAt(
i,
new THREE.Color().setHSL(
0.19 + random() * 0.05,
0.22 + random() * 0.1,
0.29 + random() * 0.12
)
);
}
shrubs.instanceMatrix.needsUpdate = true;
if (shrubs.instanceColor) shrubs.instanceColor.needsUpdate = true;
shrubs.castShadow = true;
shrubs.receiveShadow = true;
definition.group.add(shrubs);
}
function createTile(definition) {
const group = new THREE.Group();
group.position.x = definition.x;
definition.group = group;
scene.add(group);
tileGroups.set(definition.id, group);
const base = new THREE.Mesh(
new THREE.BoxGeometry(TILE_W, 0.58, TILE_D),
new THREE.MeshStandardMaterial({
color: 0x30484b,
roughness: 0.92,
metalness: 0.02
})
);
base.position.y = -0.86;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
group.add(createSkirt(definition));
group.add(createTerrain(definition));
const waterGeometry = new THREE.PlaneGeometry(TILE_W - 0.025, TILE_D - 0.025);
waterGeometry.rotateX(-Math.PI / 2);
const waterMaterial = new THREE.MeshStandardMaterial({
color: definition.waterColor,
transparent: true,
opacity: 0.7,
roughness: 0.24,
metalness: 0.02,
depthWrite: false,
side: THREE.DoubleSide
});
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.position.y = state.level;
water.renderOrder = 2;
water.receiveShadow = true;
group.add(water);
waterMeshes.push(water);
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0xd7cdb8,
roughness: 0.9
});
const edgeNorth = new THREE.Mesh(
new THREE.BoxGeometry(TILE_W + 0.04, 0.07, 0.055),
edgeMaterial
);
edgeNorth.position.set(0, -0.535, -TILE_D / 2);
group.add(edgeNorth);
const edgeSouth = edgeNorth.clone();
edgeSouth.position.z = TILE_D / 2;
group.add(edgeSouth);
const edgeWest = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.07, TILE_D + 0.04),
edgeMaterial
);
edgeWest.position.set(-TILE_W / 2, -0.535, 0);
group.add(edgeWest);
const edgeEast = edgeWest.clone();
edgeEast.position.x = TILE_W / 2;
group.add(edgeEast);
for (const patch of definition.wetlands) {
const points = [];
for (let i = 0; i < 56; i++) {
const angle = (i / 56) * Math.PI * 2;
const x = patch.x + Math.cos(angle) * patch.rx;
const z = patch.z + Math.sin(angle) * patch.rz;
points.push(
new THREE.Vector3(x, terrainHeight(x, z, definition) + 0.035, z)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: definition.id === "restored" ? 0x94bd70 : 0x83945f,
transparent: true,
opacity: definition.id === "restored" ? 0.5 : 0.28,
depthTest: false,
depthWrite: false
});
const line = new THREE.LineLoop(geometry, material);
line.renderOrder = 4;
wetlandLines.push(line);
group.add(line);
}
createStorageOutlines(definition);
createChannelLines(definition);
createVegetation(definition);
}
tileDefinitions.forEach(createTile);
const labelElements = [
{
element: document.getElementById("labelExisting"),
anchor: new THREE.Vector3(tileDefinitions[0].x, 1.25, -2.55)
},
{
element: document.getElementById("labelRestored"),
anchor: new THREE.Vector3(tileDefinitions[1].x, 1.25, -2.55)
}
];
function updateTide() {
state.t = Number(tideSlider.value) / 100;
const eased = smoothstep(0, 1, state.t);
state.level = lerp(-0.14, 0.46, eased);
const storageReveal = smoothstep(0.13, 0.46, state.t);
const routeReveal = 0.13 + smoothstep(0.02, 0.55, state.t) * 0.74;
for (const water of waterMeshes) {
water.position.y = state.level;
water.material.opacity = lerp(0.66, 0.79, state.t);
}
for (const line of storageLines) {
line.position.y = state.level + 0.035;
line.material.opacity = storageReveal * 0.95;
}
for (const material of channelMaterials) {
material.opacity = routeReveal;
}
for (const marker of flowMarkers) {
marker.material.opacity = routeReveal * 0.9;
}
tideSlider.style.setProperty("--fill", `${state.t * 100}%`);
const gaugeWidth = `${lerp(18, 100, state.t)}%`;
gaugeExisting.style.width = gaugeWidth;
gaugeRestored.style.width = gaugeWidth;
if (state.t < 0.27) {
phaseElement.textContent = "Low tide";
tideSlider.setAttribute("aria-valuetext", "Low tide");
stateTitle.textContent = "Channels concentrate the flow";
stateText.textContent =
"The main channel remains connected while storage floors are exposed and the wetland flats stay mostly dry.";
} else if (state.t < 0.68) {
phaseElement.textContent = "Rising tide";
tideSlider.setAttribute("aria-valuetext", "Rising tide");
stateTitle.textContent = "Connected basins begin to fill";
stateText.textContent =
"Water spreads into side channels. The restored tile gains more connected storage before the reference.";
} else {
phaseElement.textContent = "High tide";
tideSlider.setAttribute("aria-valuetext", "High tide");
stateTitle.textContent = "Wetlands reconnect to the tide";
stateText.textContent =
"Broader wetland flats flood with the basins, while the existing condition remains more fragmented.";
}
}
tideSlider.addEventListener("input", updateTide);
updateTide();
// Camera controls are implemented locally, without any Three.js addons.
const target = new THREE.Vector3(0, -0.05, 0);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
state.yaw -= deltaX * 0.006;
state.pitch = clamp(state.pitch + deltaY * 0.005, 0.35, 1.14);
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
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();
state.cameraDistance = clamp(
state.cameraDistance * Math.exp(event.deltaY * 0.001),
12,
30
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
state.cameraDistance = 19.5;
state.yaw = 0.46;
state.pitch = 0.7;
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
function updateLabels() {
for (const label of labelElements) {
const projected = label.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const responsiveDistance = Math.max(1, 1.55 / aspect);
const distance = state.cameraDistance * responsiveDistance;
const horizontal = Math.cos(state.pitch) * distance;
camera.position.set(
target.x + Math.sin(state.yaw) * horizontal,
target.y + Math.sin(state.pitch) * distance,
target.z + Math.cos(state.yaw) * horizontal
);
camera.lookAt(target);
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
const up = new THREE.Vector3(0, 1, 0);
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
for (const marker of flowMarkers) {
const curve = marker.userData.curve;
const u = (elapsed * (0.025 + state.t * 0.035) + marker.userData.offset) % 1;
const point = curve.getPointAt(u);
const tangent = curve.getTangentAt(u).normalize();
marker.position.set(point.x, state.level + 0.055, point.z);
marker.quaternion.setFromUnitVectors(up, tangent);
}
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => loading.classList.add("ready"));
</script>
</body>
</html>
```