Prompt specification
Build or customize the Three.js 3D scene "Estuary density teaching cutaway" 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: Estuary density teaching cutaway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/estuary-density-teaching-cutaway-x1463
Scene Description Prompt:
Build a voxel estuary with a qualitative salinity-layer cutaway, clearly marked schematic. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (estuary-density-teaching-cutaway-x1463):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Estuary — Qualitative Salinity Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #07151c;
--panel: rgba(10, 29, 37, 0.86);
--panel-border: rgba(156, 219, 228, 0.18);
--text: #edf9fa;
--muted: #9bb8bd;
--cyan: #8ddce8;
--green: #a8d36a;
--blue: #73b8ed;
--orange: #efb46d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #15313a 0%, #091920 48%, #061118 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 3;
}
.panel {
position: absolute;
pointer-events: auto;
background:
linear-gradient(135deg, rgba(17, 43, 52, 0.94), rgba(7, 24, 31, 0.88));
border: 1px solid var(--panel-border);
border-radius: 16px;
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 24px;
left: 24px;
width: min(440px, calc(100vw - 48px));
padding: 20px 22px 19px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 18px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(141, 220, 232, 0.55);
}
h1 {
margin: 0;
font-size: clamp(28px, 3vw, 42px);
font-weight: 750;
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 380px;
margin: 12px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.badge-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.badge {
display: inline-flex;
align-items: center;
min-height: 25px;
padding: 5px 9px;
border: 1px solid rgba(239, 180, 109, 0.42);
border-radius: 999px;
background: rgba(239, 180, 109, 0.09);
color: #ffd29a;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.mini-note {
color: #78969c;
font-size: 10px;
}
.orientation {
position: absolute;
top: 27px;
left: 50%;
display: flex;
align-items: center;
gap: 12px;
padding: 8px 13px;
transform: translateX(-50%);
border: 1px solid rgba(156, 219, 228, 0.14);
border-radius: 999px;
background: rgba(7, 23, 29, 0.7);
color: #b7d2d6;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
backdrop-filter: blur(10px);
}
.orientation .axis {
position: relative;
width: 92px;
height: 1px;
background: linear-gradient(90deg, #397fa7, #62b5ad, #9fca6c);
}
.orientation .axis::before,
.orientation .axis::after {
position: absolute;
top: 50%;
content: "";
transform: translateY(-50%);
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
}
.orientation .axis::before {
left: -1px;
border-right: 6px solid #5b91b6;
}
.orientation .axis::after {
right: -1px;
border-left: 6px solid #9fca6c;
}
.legend-panel {
right: 24px;
bottom: 24px;
width: 294px;
padding: 18px;
}
.panel-heading {
margin: 0 0 12px;
color: #dff4f5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.salinity-ramp {
display: grid;
grid-template-columns: repeat(9, 1fr);
height: 13px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 4px;
}
.salinity-ramp span:nth-child(1) { background: #a8d36a; }
.salinity-ramp span:nth-child(2) { background: #8ecb70; }
.salinity-ramp span:nth-child(3) { background: #5fbd82; }
.salinity-ramp span:nth-child(4) { background: #43a99a; }
.salinity-ramp span:nth-child(5) { background: #338fa4; }
.salinity-ramp span:nth-child(6) { background: #3276a5; }
.salinity-ramp span:nth-child(7) { background: #315d98; }
.salinity-ramp span:nth-child(8) { background: #294b83; }
.salinity-ramp span:nth-child(9) { background: #243a70; }
.ramp-labels {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #8ca9ae;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.04em;
}
.layer-key {
display: grid;
gap: 9px;
margin-top: 15px;
}
.layer-row {
display: grid;
grid-template-columns: 24px 1fr;
align-items: start;
gap: 9px;
}
.layer-symbol {
position: relative;
height: 25px;
border-left: 3px solid var(--green);
border-radius: 2px;
background: rgba(168, 211, 106, 0.09);
}
.layer-symbol.deep {
border-color: #397db5;
background: rgba(57, 125, 181, 0.12);
}
.layer-symbol.interface {
height: 0;
margin-top: 12px;
border-top: 2px dashed #d8f4f6;
border-left: 0;
background: none;
}
.layer-row strong {
display: block;
margin-bottom: 2px;
color: #e8f6f7;
font-size: 11px;
font-weight: 700;
}
.layer-row small {
display: block;
color: #8ea9ae;
font-size: 10px;
line-height: 1.35;
}
.legend-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid rgba(153, 211, 220, 0.1);
color: #78969c;
font-size: 9px;
line-height: 1.35;
}
.legend-footer .swatch {
display: inline-block;
width: 20px;
margin-right: 6px;
vertical-align: middle;
border-top: 2px dashed #d8f4f6;
}
.read-panel {
left: 24px;
bottom: 24px;
width: 284px;
padding: 17px 18px;
}
.read-step {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
align-items: start;
margin-top: 11px;
}
.step-number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(141, 220, 232, 0.22);
border-radius: 7px;
background: rgba(141, 220, 232, 0.06);
color: var(--cyan);
font-size: 9px;
font-weight: 800;
}
.read-step strong {
display: block;
margin-bottom: 2px;
font-size: 11px;
}
.read-step p {
margin: 0;
color: #8fa9ae;
font-size: 10px;
line-height: 1.4;
}
.controls {
position: absolute;
right: 24px;
top: 25px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.hint {
padding: 8px 11px;
border: 1px solid rgba(156, 219, 228, 0.13);
border-radius: 999px;
background: rgba(7, 23, 29, 0.68);
color: #8eabb0;
font-size: 9px;
backdrop-filter: blur(10px);
}
#reset {
display: grid;
width: 34px;
height: 34px;
padding: 0;
place-items: center;
border: 1px solid rgba(156, 219, 228, 0.18);
border-radius: 50%;
background: rgba(11, 34, 42, 0.88);
color: #d9f2f4;
cursor: pointer;
font-size: 18px;
transition: background 160ms ease, transform 160ms ease;
}
#reset:hover {
background: rgba(27, 67, 77, 0.95);
transform: rotate(-12deg);
}
.scene-label {
position: absolute;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
min-width: max-content;
padding: 6px 9px;
transform: translate(-50%, -50%);
border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
border-radius: 8px;
background: rgba(6, 20, 26, 0.8);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
color: #ecf9fa;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.scene-label::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
.scene-label small {
color: var(--accent);
font-size: 8px;
}
.scene-label strong {
font-weight: 780;
}
.scene-label .label-main {
display: flex;
flex-direction: column;
gap: 1px;
}
.scene-label .label-main span {
color: #9bb7bc;
font-size: 7px;
letter-spacing: 0.1em;
}
@media (max-width: 980px) {
.orientation,
.hint {
display: none;
}
.title-panel {
width: 360px;
}
.legend-panel {
width: 255px;
}
.read-panel {
width: 245px;
}
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
.subtitle {
margin: 9px 0 11px;
font-size: 11px;
}
.legend-panel {
right: 12px;
bottom: 12px;
width: 210px;
padding: 13px;
}
.read-panel {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
}
.legend-panel + .controls {
bottom: 258px;
}
.scene-label {
padding: 4px 6px;
font-size: 7px;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional voxel estuary cutaway"></main>
<div class="hud">
<header class="panel title-panel">
<div class="eyebrow">Estuary process model</div>
<h1>Voxel Estuary</h1>
<p class="subtitle">
Freshwater meets salt water in a layered mixing zone. The exposed
cross-section shows a fresher surface layer above a saltier wedge.
</p>
<div class="badge-row">
<span class="badge">Schematic · not to scale</span>
<span class="mini-note">Qualitative salinity only</span>
</div>
</header>
<div class="orientation" aria-hidden="true">
<span>Ocean</span>
<span class="axis"></span>
<span>River</span>
</div>
<section class="panel read-panel" aria-label="How to read the cutaway">
<h2 class="panel-heading">Read the cutaway</h2>
<div class="read-step">
<span class="step-number">01</span>
<div>
<strong>Fresher surface layer</strong>
<p>River influence extends farther toward the sea near the top.</p>
</div>
</div>
<div class="read-step">
<span class="step-number">02</span>
<div>
<strong>Mixing interface</strong>
<p>The dotted line marks a conceptual boundary, not a sharp front.</p>
</div>
</div>
<div class="read-step">
<span class="step-number">03</span>
<div>
<strong>Saltier bottom wedge</strong>
<p>Saltwater intrudes landward beneath the fresher river water.</p>
</div>
</div>
</section>
<section class="panel legend-panel" aria-label="Salinity legend">
<h2 class="panel-heading">Relative salinity</h2>
<div class="salinity-ramp" aria-hidden="true">
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
</div>
<div class="ramp-labels">
<span>Fresh</span>
<span>Brackish</span>
<span>Saline</span>
</div>
<div class="layer-key">
<div class="layer-row">
<span class="layer-symbol"></span>
<div>
<strong>Surface: river influence</strong>
<small>Greener voxels represent lower salinity.</small>
</div>
</div>
<div class="layer-row">
<span class="layer-symbol interface"></span>
<div>
<strong>Mixing interface</strong>
<small>Dotted line is schematic and transitional.</small>
</div>
</div>
<div class="layer-row">
<span class="layer-symbol deep"></span>
<div>
<strong>Bottom: marine influence</strong>
<small>Blue voxels represent higher salinity.</small>
</div>
</div>
</div>
<div class="legend-footer">
<span><span class="swatch"></span>Dashed boundary</span>
<span>Vertical scale exaggerated</span>
</div>
</section>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom</div>
<button id="reset" type="button" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
<div
id="label-sea"
class="scene-label"
style="--accent:#73b8ed"
aria-hidden="true"
>
<span class="label-main"><span>Marine end</span><strong>Ocean / salt water</strong></span>
</div>
<div
id="label-river"
class="scene-label"
style="--accent:#a8d36a"
aria-hidden="true"
>
<span class="label-main"><span>Freshwater end</span><strong>River inflow</strong></span>
</div>
<div
id="label-surface"
class="scene-label"
style="--accent:#9ed56d"
aria-hidden="true"
>
<span class="label-main"><span>Upper layer</span><strong>Fresher surface</strong></span>
</div>
<div
id="label-interface"
class="scene-label"
style="--accent:#d9f4f5"
aria-hidden="true"
>
<span class="label-main"><span>Dotted boundary</span><strong>Mixing interface</strong></span>
</div>
<div
id="label-wedge"
class="scene-label"
style="--accent:#5aa8dc"
aria-hidden="true"
>
<span class="label-main"><span>Lower layer</span><strong>Salt wedge</strong></span>
</div>
<div
id="label-cutaway"
class="scene-label"
style="--accent:#e5f8f9"
aria-hidden="true"
>
<span class="label-main"><span>Removed front half</span><strong>Exposed cutaway</strong></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 container = document.getElementById("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.15;
container.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07151c);
scene.fog = new THREE.FogExp2(0x07151c, 0.021);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.45, 0);
const cameraHome = {
radius: 19,
theta: 0.58,
phi: 1.04
};
const cameraState = { ...cameraHome };
function updateCamera() {
const { radius, theta, phi } = cameraState;
const horizontal = radius * Math.sin(phi);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + horizontal * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Lighting
const hemi = new THREE.HemisphereLight(0xc7efff, 0x26352a, 2.0);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff3d6, 3.4);
keyLight.position.set(-6, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x78cbe8, 1.15);
fillLight.position.set(10, 7, -10);
scene.add(fillLight);
const warmRim = new THREE.PointLight(0xd9e995, 18, 24, 2);
warmRim.position.set(8, 5, 3);
scene.add(warmRim);
// Ground and presentation base
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x07151b,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.305;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(44, 44, 0x234550, 0x143039);
grid.position.y = -0.298;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const baseGeometry = new THREE.BoxGeometry(16.35, 0.28, 7.3);
const base = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
color: 0x142a31,
roughness: 0.75,
metalness: 0.08
})
);
base.position.y = -0.14;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const baseEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(baseGeometry),
new THREE.LineBasicMaterial({
color: 0x34535c,
transparent: true,
opacity: 0.55
})
);
baseEdges.position.copy(base.position);
scene.add(baseEdges);
// Estuary voxel dimensions
const NX = 31;
const NY = 7;
const NZ = 13;
const CELL = 0.52;
const VOXEL = 0.48;
const WATER_ROWS = 6;
const xAt = (i) => (i - (NX - 1) / 2) * CELL;
const zAt = (j) => (j - (NZ - 1) / 2) * CELL;
const palette = [
0xa8d36a,
0x8ecb70,
0x5fbd82,
0x43a99a,
0x338fa4,
0x3276a5,
0x315d98,
0x294b83,
0x243a70
];
// Quantized, rising river bed
const bedProfile = [];
const terrainBins = [[], [], []];
for (let i = 0; i < NX; i++) {
const riverNorm = i / (NX - 1);
const idealBed = 0.32 + 0.76 * Math.pow(riverNorm, 1.35);
const centralLevels = Math.max(2, Math.round(idealBed / 0.22));
bedProfile[i] = centralLevels * 0.22 - 0.02;
for (let j = 0; j < NZ; j++) {
const variation = (j % 3) - 1;
const levels = Math.max(2, centralLevels + variation * 0.35);
for (let k = 0; k < levels; k++) {
const bin = Math.abs((i * 5 + j * 3 + k * 2) % 3);
terrainBins[bin].push({
x: xAt(i),
y: k * 0.22 + 0.1,
z: zAt(j)
});
}
}
}
const terrainColors = [0x756a4d, 0x665e47, 0x827458];
const terrainMaterials = terrainColors.map((color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.96,
metalness: 0,
flatShading: true
})
);
const terrainGeometry = new THREE.BoxGeometry(0.48, 0.2, 0.48);
const dummy = new THREE.Object3D();
terrainBins.forEach((instances, index) => {
const mesh = new THREE.InstancedMesh(
terrainGeometry,
terrainMaterials[index],
instances.length
);
instances.forEach((p, i) => {
dummy.position.set(p.x, p.y, p.z);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
});
// Qualitative salinity model:
// - marine influence increases toward the sea
// - saltier water occupies greater depth
// - the resulting boundary slopes toward the river
const waterBins = palette.map(() => []);
const allWaterInstances = [];
const topProfile = [];
for (let i = 0; i < NX; i++) {
const riverNorm = i / (NX - 1);
const seaInfluence = Math.pow(1 - riverNorm, 0.85);
const bedY = bedProfile[i];
const surfaceY = 4.42 - 0.47 * riverNorm;
const rows = 3 + Math.round(3 * (1 - riverNorm));
let highestK = -1;
for (let j = 0; j < rows; j++) {
const z = -0.26 - j * CELL;
for (let k = 0; k < NY; k++) {
const y = bedY + k * CELL + CELL / 2;
if (y + VOXEL / 2 > surfaceY) {
continue;
}
const depth = k / (NY - 1);
const verticalInfluence = 0.58 + 0.42 * depth;
const mixingBulge =
0.045 *
Math.exp(-Math.pow((riverNorm - 0.65) / 0.13, 2)) *
Math.sin(Math.PI * depth);
const salinity = THREE.MathUtils.clamp(
seaInfluence * verticalInfluence + mixingBulge,
0,
0.999
);
const colorIndex = Math.min(
palette.length - 1,
Math.floor(salinity * palette.length)
);
const instance = {
x: xAt(i),
y,
z,
colorIndex
};
waterBins[colorIndex].push(instance);
allWaterInstances.push(instance);
highestK = Math.max(highestK, k);
}
}
topProfile.push(
highestK >= 0
? bedY + (highestK + 1) * CELL
: bedY
);
}
const waterGeometry = new THREE.BoxGeometry(VOXEL, VOXEL, VOXEL);
const waterMaterials = palette.map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.28,
metalness: 0.07,
flatShading: true,
emissive: new THREE.Color(color).multiplyScalar(0.025)
})
);
waterBins.forEach((instances, index) => {
if (!instances.length) return;
const mesh = new THREE.InstancedMesh(
waterGeometry,
waterMaterials[index],
instances.length
);
instances.forEach((p, i) => {
dummy.position.set(p.x, p.y, p.z);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
});
// Fine wire edges emphasize the voxel construction.
const wireMaterial = new THREE.MeshBasicMaterial({
color: 0x061820,
wireframe: true,
transparent: true,
opacity: 0.33,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1
});
const wireMesh = new THREE.InstancedMesh(
waterGeometry,
wireMaterial,
allWaterInstances.length
);
allWaterInstances.forEach((p, i) => {
dummy.position.set(p.x, p.y, p.z);
dummy.updateMatrix();
wireMesh.setMatrixAt(i, dummy.matrix);
});
wireMesh.instanceMatrix.needsUpdate = true;
wireMesh.renderOrder = 2;
scene.add(wireMesh);
// Outline around the exposed vertical cutaway.
const outlinePoints = [];
for (let i = 0; i < NX; i++) {
outlinePoints.push(
new THREE.Vector3(xAt(i), topProfile[i], 0.015)
);
}
for (let i = NX - 1; i >= 0; i--) {
outlinePoints.push(
new THREE.Vector3(xAt(i), bedProfile[i], 0.015)
);
}
outlinePoints.push(outlinePoints[0].clone());
const cutOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(outlinePoints),
new THREE.LineBasicMaterial({
color: 0xbceaf0,
transparent: true,
opacity: 0.48
})
);
scene.add(cutOutline);
// Dashed conceptual mixing interface on the cut face.
const interfacePoints = [];
const interfaceThreshold = 0.38;
for (let i = 0; i < NX; i++) {
const riverNorm = i / (NX - 1);
const seaInfluence = Math.pow(1 - riverNorm, 0.85);
if (
seaInfluence < interfaceThreshold ||
seaInfluence > interfaceThreshold / 0.58
) {
continue;
}
const depth =
(interfaceThreshold / seaInfluence - 0.58) / 0.42;
const k = THREE.MathUtils.clamp(depth, 0, 1) * (NY - 1);
const y = bedProfile[i] + k * CELL + CELL / 2;
interfacePoints.push(new THREE.Vector3(xAt(i), y, 0.045));
}
const interfaceLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(interfacePoints),
new THREE.LineDashedMaterial({
color: 0xe6f8f9,
dashSize: 0.16,
gapSize: 0.11,
transparent: true,
opacity: 0.9
})
);
interfaceLine.computeLineDistances();
interfaceLine.renderOrder = 5;
scene.add(interfaceLine);
// A small pulsing marker identifies the conceptual mixing zone.
const mixMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.022, 8, 48),
new THREE.MeshBasicMaterial({
color: 0xdff7f8,
transparent: true,
opacity: 0.64,
depthTest: false
})
);
mixMarker.position.set(-0.75, 2.45, 0.065);
mixMarker.renderOrder = 7;
scene.add(mixMarker);
// Bracket identifying the exposed cutaway.
const rightBed = bedProfile[NX - 1];
const rightTop = topProfile[NX - 1];
const bracketPoints = [
new THREE.Vector3(7.95, rightBed, 0.05),
new THREE.Vector3(8.22, rightBed, 0.05),
new THREE.Vector3(8.22, rightTop, 0.05),
new THREE.Vector3(7.95, rightTop, 0.05)
];
const cutBracket = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(bracketPoints),
new THREE.LineBasicMaterial({
color: 0xe9f9fa,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
cutBracket.renderOrder = 7;
scene.add(cutBracket);
function makeArrow(origin, direction, length, color, headLength, headWidth) {
const arrow = new THREE.ArrowHelper(
direction,
origin,
length,
color,
headLength,
headWidth
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.9;
arrow.line.material.depthTest = false;
arrow.line.renderOrder = 8;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.94;
arrow.cone.material.depthTest = false;
arrow.cone.renderOrder = 8;
scene.add(arrow);
return arrow;
}
// River flow moves seaward above the water.
const surfaceArrow = makeArrow(
new THREE.Vector3(6.7, 4.72, -1.15),
new THREE.Vector3(-1, 0, 0),
8.1,
0xb6e66f,
0.56,
0.35
);
// Saltwater intrusion moves landward near the bed.
const intrusionArrow = makeArrow(
new THREE.Vector3(-6.3, 1.03, 0.075),
new THREE.Vector3(1, 0, 0),
7.1,
0x9bdcff,
0.55,
0.34
);
// Screen-space labels projected from scene coordinates.
const labelConfigs = [
{
element: document.getElementById("label-sea"),
anchor: new THREE.Vector3(-7.25, 4.95, -0.25),
offset: [-28, -5]
},
{
element: document.getElementById("label-river"),
anchor: new THREE.Vector3(7.15, 4.35, -0.35),
offset: [24, -6]
},
{
element: document.getElementById("label-surface"),
anchor: new THREE.Vector3(3.55, 3.8, -0.25),
offset: [-10, -38]
},
{
element: document.getElementById("label-interface"),
anchor: new THREE.Vector3(-2.65, 2.72, 0.07),
offset: [-28, -30]
},
{
element: document.getElementById("label-wedge"),
anchor: new THREE.Vector3(0.8, 1.28, 0.07),
offset: [30, 25]
},
{
element: document.getElementById("label-cutaway"),
anchor: new THREE.Vector3(8.22, 2.05, 0.05),
offset: [66, 5]
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = container.clientWidth;
const height = container.clientHeight;
for (const label of labelConfigs) {
projected.copy(label.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
label.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// Direct camera controls: no examples or addons are imported.
const pointers = new Map();
let dragging = false;
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
function resetCamera() {
cameraState.radius = cameraHome.radius;
cameraState.theta = cameraHome.theta;
cameraState.phi = cameraHome.phi;
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.classList.add("dragging");
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
10.5,
27
);
updateCamera();
}
pinchDistance = distance;
return;
}
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.34
);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 0) {
dragging = false;
renderer.domElement.classList.remove("dragging");
} else {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
10.5,
27
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
break;
case "ArrowRight":
cameraState.theta -= 0.08;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.48, cameraState.phi - 0.06);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.34, cameraState.phi + 0.06);
break;
case "+":
case "=":
cameraState.radius = Math.max(10.5, cameraState.radius - 0.8);
break;
case "-":
case "_":
cameraState.radius = Math.min(27, cameraState.radius + 0.8);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
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();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
const elapsed = clock.getElapsedTime();
if (!reducedMotion) {
const pulse = 1 + Math.sin(elapsed * 2.2) * 0.09;
mixMarker.scale.setScalar(pulse);
mixMarker.material.opacity = 0.48 + Math.sin(elapsed * 2.2) * 0.16;
surfaceArrow.position.y =
4.72 + Math.sin(elapsed * 1.5) * 0.035;
intrusionArrow.position.y =
1.03 + Math.sin(elapsed * 1.5 + 1.5) * 0.025;
}
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```