Prompt specification
Build or customize the Three.js 3D scene "Porous aquifer and well section" 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: Porous aquifer and well section
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/porous-aquifer-and-well-section-x1205
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: porous aquifer and well section. Build a transparent ground block with a water table, porous layer, impermeable base, and screened well; distinguish groundwater in pores from an unrealistic underground lake. Return one self-contained HTML file.
Working Three.js Starter (porous-aquifer-and-well-section-x1205):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Porous Aquifer and Well Section</title>
<style>
:root {
--ink: #203238;
--muted: #607176;
--paper: rgba(248, 250, 246, 0.86);
--line: rgba(32, 50, 56, 0.16);
--blue: #168fd1;
--sand: #b58a55;
--slate: #52646a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ece7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.atmosphere {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 35%, rgba(74, 91, 89, 0.07) 100%),
linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 30%);
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 4;
}
.card {
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.72);
background: var(--paper);
box-shadow: 0 18px 45px rgba(42, 58, 58, 0.13);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-card {
position: absolute;
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #4e777d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 18px;
height: 2px;
content: "";
background: var(--blue);
}
h1 {
margin: 0;
font-size: clamp(24px, 2.6vw, 34px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1.04;
}
.title-card p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend-card {
position: absolute;
top: 22px;
right: 22px;
width: 238px;
padding: 15px 16px 14px;
border-radius: 15px;
}
.legend-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0;
color: #42565c;
font-size: 12px;
}
.swatch {
flex: 0 0 auto;
width: 20px;
height: 11px;
border: 1px solid rgba(32, 50, 56, 0.12);
border-radius: 3px;
}
.swatch.grain {
background: var(--sand);
}
.swatch.pore {
background: var(--blue);
box-shadow: inset 5px 0 rgba(255, 255, 255, 0.3);
}
.swatch.table {
height: 0;
border: 0;
border-top: 2px dashed #159db8;
border-radius: 0;
}
.swatch.base {
background: var(--slate);
}
.swatch.screen {
background: repeating-linear-gradient(
90deg,
#75898e 0,
#75898e 2px,
transparent 2px,
transparent 5px
);
}
.controls {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 8px 0;
color: #42565c;
font-size: 12px;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
margin: 0;
accent-color: var(--blue);
cursor: pointer;
}
.reset-button {
width: 100%;
margin-top: 8px;
padding: 9px 12px;
border: 1px solid rgba(32, 50, 56, 0.14);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
.reset-button:hover {
background: white;
transform: translateY(-1px);
}
#annotationLayer {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
#leaderSvg {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
}
.annotation {
position: absolute;
width: 190px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 10px;
background: rgba(248, 250, 246, 0.82);
box-shadow: 0 8px 22px rgba(42, 58, 58, 0.09);
backdrop-filter: blur(9px);
-webkit-backdrop-filter: blur(9px);
}
.annotation strong {
display: block;
color: #294047;
font-size: 11px;
line-height: 1.25;
}
.annotation small {
display: block;
margin-top: 3px;
color: #6b7b7f;
font-size: 9px;
line-height: 1.35;
}
.a-vadose {
top: 29%;
left: 22px;
}
.a-water {
top: 44%;
left: 22px;
}
.a-screen {
top: 39%;
right: 22px;
}
.a-pore {
top: 54%;
right: 22px;
}
.a-base {
top: 74%;
right: 22px;
}
.a-head {
top: 10%;
left: 43%;
}
.note-card {
position: absolute;
bottom: 22px;
left: 22px;
display: flex;
gap: 12px;
max-width: 480px;
padding: 13px 15px;
border-radius: 13px;
}
.note-icon {
display: grid;
flex: 0 0 29px;
width: 29px;
height: 29px;
place-items: center;
border-radius: 50%;
background: rgba(22, 143, 209, 0.12);
color: #0b79b4;
font-size: 15px;
font-weight: 900;
}
.note-card strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.note-card p {
margin: 0;
color: #5a6d72;
font-size: 11px;
line-height: 1.45;
}
.camera-help {
position: absolute;
right: 22px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 999px;
background: rgba(248, 250, 246, 0.7);
color: #637579;
font-size: 10px;
letter-spacing: 0.035em;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
@media (max-width: 900px) {
.annotation {
display: none;
}
}
@media (max-width: 760px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.title-card p {
display: none;
}
.legend-card {
top: auto;
right: 14px;
bottom: 14px;
width: 205px;
padding: 12px 14px;
}
.legend-title {
margin-bottom: 8px;
}
.legend-row {
margin: 6px 0;
}
.note-card,
.camera-help {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="atmosphere"></div>
<div id="annotationLayer">
<svg id="leaderSvg" aria-hidden="true"></svg>
<div class="annotation a-vadose" data-side="left">
<strong>Unsaturated soil</strong>
<small>Recharge moves downward through open pores.</small>
</div>
<div class="annotation a-water" data-side="left">
<strong>Water-table elevation</strong>
<small>A reference surface, not a body of water.</small>
</div>
<div class="annotation a-screen" data-side="right">
<strong>Screened well interval</strong>
<small>Open slots admit groundwater from the aquifer.</small>
</div>
<div class="annotation a-pore" data-side="right">
<strong>Groundwater in pore spaces</strong>
<small>Discrete blue pockets occupy spaces between grains.</small>
</div>
<div class="annotation a-base" data-side="right">
<strong>Impermeable base</strong>
<small>Low-permeability material limits downward flow.</small>
</div>
<div class="annotation a-head" data-side="right">
<strong>Pump and wellhead</strong>
<small>Water is drawn from the screened interval.</small>
</div>
</div>
<div class="hud">
<header class="title-card card">
<div class="eyebrow">Hydrogeologic cutaway</div>
<h1>Porous aquifer<br>& screened well</h1>
<p>
A low-poly section showing saturated pore space, the water-table
elevation, an infiltration zone, and an impermeable foundation.
</p>
</header>
<section class="legend-card card" aria-label="Scene legend">
<div class="legend-title">
<span>Legend</span>
<span>Cutaway</span>
</div>
<div class="legend-row">
<span class="swatch grain"></span>
<span>Aquifer grains / solid matrix</span>
</div>
<div class="legend-row">
<span class="swatch pore"></span>
<span>Groundwater in pores</span>
</div>
<div class="legend-row">
<span class="swatch table"></span>
<span>Water-table elevation</span>
</div>
<div class="legend-row">
<span class="swatch screen"></span>
<span>Well screen</span>
</div>
<div class="legend-row">
<span class="swatch base"></span>
<span>Impermeable base</span>
</div>
<div class="controls">
<label class="toggle">
<span>Aquifer matrix</span>
<input id="grainToggle" type="checkbox" checked>
</label>
<label class="toggle">
<span>Pore water</span>
<input id="poreToggle" type="checkbox" checked>
</label>
<label class="toggle">
<span>Transparent block shell</span>
<input id="shellToggle" type="checkbox" checked>
</label>
<button class="reset-button" id="resetView" type="button">
Reset camera
</button>
</div>
</section>
<aside class="note-card card">
<div class="note-icon">i</div>
<div>
<strong>Porosity, not an underground lake</strong>
<p>
Blue is shown as separate saturated pore bodies between solid grains.
The dashed horizontal line only marks the elevation of the water table.
</p>
</div>
</aside>
<div class="camera-help">
Drag to orbit · Scroll to zoom · Double-click to reset
</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 mount = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional porous aquifer and well section"
);
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ece7);
scene.fog = new THREE.Fog(0xe8ece7, 56, 105);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
150
);
const WIDTH = 20;
const DEPTH = 16;
const TOP = 3;
const WATER_TABLE = -0.8;
const BASE_TOP = -5.3;
const BASE_BOTTOM = -7;
const cameraTarget = new THREE.Vector3(0, -1.25, 0);
const initialView = {
theta: 0.68,
phi: 1.16,
radius: 31
};
const currentView = { ...initialView };
const desiredView = { ...initialView };
function applyCamera() {
const sinPhi = Math.sin(currentView.phi);
const cosPhi = Math.cos(currentView.phi);
camera.position.set(
cameraTarget.x +
currentView.radius * sinPhi * Math.sin(currentView.theta),
cameraTarget.y + currentView.radius * cosPhi,
cameraTarget.z +
currentView.radius * sinPhi * Math.cos(currentView.theta)
);
camera.lookAt(cameraTarget);
}
applyCamera();
// Lighting.
scene.add(
new THREE.HemisphereLight(0xf9fff7, 0x66766e, 2.25)
);
const sun = new THREE.DirectionalLight(0xfff4da, 3.25);
sun.position.set(12, 22, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dded, 1.25);
fill.position.set(-15, 10, -12);
scene.add(fill);
// Ground plane and soft contact shadow.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(140, 140),
new THREE.MeshStandardMaterial({
color: 0xe4e8e2,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = BASE_BOTTOM - 0.06;
floor.receiveShadow = true;
scene.add(floor);
function mulberry32(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(14937);
function makeEdges(mesh, color = 0x4a5b5d, opacity = 0.35) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 20),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
edges.scale.copy(mesh.scale);
edges.renderOrder = 8;
return edges;
}
// Impermeable foundation.
const base = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH, BASE_TOP - BASE_BOTTOM, DEPTH),
new THREE.MeshStandardMaterial({
color: 0x52646a,
roughness: 0.94,
metalness: 0.02,
flatShading: true
})
);
base.position.y = (BASE_TOP + BASE_BOTTOM) * 0.5;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
scene.add(makeEdges(base, 0x2f4248, 0.44));
const baseTop = new THREE.Mesh(
new THREE.PlaneGeometry(WIDTH - 0.04, DEPTH - 0.04),
new THREE.MeshStandardMaterial({
color: 0x64777b,
roughness: 1,
side: THREE.DoubleSide
})
);
baseTop.rotation.x = -Math.PI / 2;
baseTop.position.y = BASE_TOP + 0.012;
baseTop.receiveShadow = true;
scene.add(baseTop);
// Transparent exterior block and subtle layer volumes.
const shellMeshes = [];
const outerShell = new THREE.Mesh(
new THREE.BoxGeometry(WIDTH, TOP - BASE_BOTTOM, DEPTH),
new THREE.MeshPhysicalMaterial({
color: 0xb28b56,
transparent: true,
opacity: 0.065,
roughness: 0.86,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
outerShell.position.y = (TOP + BASE_BOTTOM) * 0.5;
outerShell.renderOrder = 7;
scene.add(outerShell);
shellMeshes.push(outerShell);
const outerEdges = makeEdges(outerShell, 0x6d684f, 0.34);
scene.add(outerEdges);
shellMeshes.push(outerEdges);
const unsaturatedVolume = new THREE.Mesh(
new THREE.BoxGeometry(
WIDTH - 0.08,
TOP - WATER_TABLE,
DEPTH - 0.08
),
new THREE.MeshBasicMaterial({
color: 0xd1a565,
transparent: true,
opacity: 0.045,
side: THREE.DoubleSide,
depthWrite: false
})
);
unsaturatedVolume.position.y = (TOP + WATER_TABLE) * 0.5;
unsaturatedVolume.renderOrder = 6;
scene.add(unsaturatedVolume);
shellMeshes.push(unsaturatedVolume);
const aquiferVolume = new THREE.Mesh(
new THREE.BoxGeometry(
WIDTH - 0.08,
WATER_TABLE - BASE_TOP,
DEPTH - 0.08
),
new THREE.MeshBasicMaterial({
color: 0xb88845,
transparent: true,
opacity: 0.03,
side: THREE.DoubleSide,
depthWrite: false
})
);
aquiferVolume.position.y = (WATER_TABLE + BASE_TOP) * 0.5;
aquiferVolume.renderOrder = 6;
scene.add(aquiferVolume);
shellMeshes.push(aquiferVolume);
// Low-poly ground surface.
function createTerrain() {
const nx = 12;
const nz = 10;
const positions = [];
const colors = [];
const indices = [];
const heights = [];
for (let iz = 0; iz <= nz; iz++) {
heights[iz] = [];
for (let ix = 0; ix <= nx; ix++) {
const x = -WIDTH / 2 + (ix / nx) * WIDTH;
const z = -DEPTH / 2 + (iz / nz) * DEPTH;
const height =
TOP +
Math.sin(x * 0.38) * 0.085 +
Math.cos(z * 0.47) * 0.07 +
(random() - 0.5) * 0.035;
heights[iz][ix] = height;
}
}
for (let iz = 0; iz <= nz; iz++) {
for (let ix = 0; ix <= nx; ix++) {
const x = -WIDTH / 2 + (ix / nx) * WIDTH;
const z = -DEPTH / 2 + (iz / nz) * DEPTH;
positions.push(x, heights[iz][ix], z);
const tint = 0.04 * Math.sin(x * 0.5 + z * 0.25);
const color = new THREE.Color(0x879064);
color.offsetHSL(0, 0, tint);
colors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
if ((ix + iz) % 2 === 0) {
indices.push(a, c, b, b, c, d);
} else {
indices.push(a, c, d, a, d, b);
}
}
}
const indexed = new THREE.BufferGeometry();
indexed.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
indexed.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
indexed.setIndex(indices);
const geometry = indexed.toNonIndexed();
geometry.computeVertexNormals();
indexed.dispose();
const terrain = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
terrain.castShadow = true;
terrain.receiveShadow = true;
return terrain;
}
scene.add(createTerrain());
const grainMeshes = [];
// Unsaturated-zone grains: no blue pore water is placed here.
const unsatGrains = new THREE.InstancedMesh(
new THREE.IcosahedronGeometry(0.31, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
flatShading: true
}),
120
);
const dummy = new THREE.Object3D();
for (let i = 0; i < 120; i++) {
dummy.position.set(
-9.5 + random() * 19,
WATER_TABLE + 0.18 + random() * (TOP - WATER_TABLE - 0.38),
-7.5 + random() * 15
);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
const scale = 0.55 + random() * 0.65;
dummy.scale.set(scale, scale * (0.75 + random() * 0.3), scale);
dummy.updateMatrix();
unsatGrains.setMatrixAt(i, dummy.matrix);
unsatGrains.setColorAt(
i,
new THREE.Color().setHSL(
0.095 + random() * 0.025,
0.34,
0.47 + random() * 0.13
)
);
}
unsatGrains.instanceMatrix.needsUpdate = true;
unsatGrains.instanceColor.needsUpdate = true;
unsatGrains.castShadow = true;
unsatGrains.receiveShadow = true;
scene.add(unsatGrains);
grainMeshes.push(unsatGrains);
// Saturated aquifer grains. Their positions are retained so the blue
// pore-water bodies can be placed in actual inter-grain spaces.
const wellX = 0.6;
const wellZ = 0.6;
const grainData = [];
const aquiferGrains = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(0.48, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
flatShading: true
}),
185
);
let grainIndex = 0;
while (grainIndex < 185) {
const x = -9.45 + random() * 18.9;
const y = BASE_TOP + 0.22 + random() * (WATER_TABLE - BASE_TOP - 0.48);
const z = -7.45 + random() * 14.9;
if (Math.hypot(x - wellX, z - wellZ) < 1.12) {
continue;
}
const scale = 0.58 + random() * 0.72;
const radius = 0.48 * scale;
dummy.position.set(x, y, z);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
dummy.scale.set(
scale,
scale * (0.82 + random() * 0.28),
scale
);
dummy.updateMatrix();
aquiferGrains.setMatrixAt(grainIndex, dummy.matrix);
aquiferGrains.setColorAt(
grainIndex,
new THREE.Color().setHSL(
0.085 + random() * 0.035,
0.32 + random() * 0.16,
0.38 + random() * 0.18
)
);
grainData.push({ x, y, z, radius });
grainIndex++;
}
aquiferGrains.instanceMatrix.needsUpdate = true;
aquiferGrains.instanceColor.needsUpdate = true;
aquiferGrains.castShadow = true;
aquiferGrains.receiveShadow = true;
scene.add(aquiferGrains);
grainMeshes.push(aquiferGrains);
// Groundwater is deliberately represented by many separate blue bodies,
// not one contiguous blue volume.
const poreCandidates = [];
const maxPores = 125;
let attempts = 0;
while (poreCandidates.length < maxPores && attempts < 30000) {
attempts++;
const x = -9.3 + random() * 18.6;
const y = BASE_TOP + 0.2 + random() * (WATER_TABLE - BASE_TOP - 0.4);
const z = -7.35 + random() * 14.7;
const scale = 0.62 + random() * 0.58;
const poreRadius = 0.3 * scale;
if (Math.hypot(x - wellX, z - wellZ) < 0.59) {
continue;
}
let overlapsGrain = false;
for (const grain of grainData) {
const dx = x - grain.x;
const dy = y - grain.y;
const dz = z - grain.z;
const minimumDistance = grain.radius + poreRadius * 0.42;
if (
dx * dx + dy * dy + dz * dz <
minimumDistance * minimumDistance
) {
overlapsGrain = true;
break;
}
}
if (overlapsGrain) {
continue;
}
poreCandidates.push({ x, y, z, scale });
}
const poreMaterial = new THREE.MeshStandardMaterial({
color: 0x168fd1,
emissive: 0x075a82,
emissiveIntensity: 0.17,
roughness: 0.25,
metalness: 0.02,
transparent: true,
opacity: 0.9,
depthWrite: false,
flatShading: true
});
const poreWater = new THREE.InstancedMesh(
new THREE.IcosahedronGeometry(0.3, 0),
poreMaterial,
poreCandidates.length
);
poreCandidates.forEach((pore, i) => {
dummy.position.set(pore.x, pore.y, pore.z);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
dummy.scale.set(
pore.scale,
pore.scale * (0.72 + random() * 0.25),
pore.scale
);
dummy.updateMatrix();
poreWater.setMatrixAt(i, dummy.matrix);
poreWater.setColorAt(
i,
new THREE.Color().setHSL(
0.535 + random() * 0.035,
0.78,
0.47 + random() * 0.12
)
);
});
poreWater.instanceMatrix.needsUpdate = true;
poreWater.instanceColor.needsUpdate = true;
poreWater.renderOrder = 2;
scene.add(poreWater);
// Dashed water-table elevation. There is deliberately no filled blue plane.
const waterTablePoints = [
new THREE.Vector3(-WIDTH / 2, WATER_TABLE, -DEPTH / 2),
new THREE.Vector3(WIDTH / 2, WATER_TABLE, -DEPTH / 2),
new THREE.Vector3(WIDTH / 2, WATER_TABLE, DEPTH / 2),
new THREE.Vector3(-WIDTH / 2, WATER_TABLE, DEPTH / 2)
];
const waterTableLine = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(waterTablePoints),
new THREE.LineDashedMaterial({
color: 0x159db8,
dashSize: 0.42,
gapSize: 0.27,
transparent: true,
opacity: 0.82
})
);
waterTableLine.computeLineDistances();
waterTableLine.renderOrder = 5;
scene.add(waterTableLine);
const frontWaterTable = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-WIDTH / 2, WATER_TABLE, DEPTH / 2 + 0.03),
new THREE.Vector3(WIDTH / 2, WATER_TABLE, DEPTH / 2 + 0.03)
]),
new THREE.LineDashedMaterial({
color: 0x0b9fbe,
dashSize: 0.5,
gapSize: 0.3,
transparent: true,
opacity: 0.95
})
);
frontWaterTable.computeLineDistances();
frontWaterTable.renderOrder = 6;
scene.add(frontWaterTable);
// Recharge arrows in the unsaturated zone.
const rechargeGroup = new THREE.Group();
const rechargeLineMaterial = new THREE.LineDashedMaterial({
color: 0x3e8795,
dashSize: 0.24,
gapSize: 0.2,
transparent: true,
opacity: 0.55
});
for (const x of [-6.6, -3.4, 3.1, 6.4]) {
const z = 5.25;
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 2.55, z),
new THREE.Vector3(x, 0.13, z)
]),
rechargeLineMaterial
);
line.computeLineDistances();
rechargeGroup.add(line);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.28, 5),
new THREE.MeshBasicMaterial({
color: 0x3e8795,
transparent: true,
opacity: 0.62
})
);
arrow.position.set(x, 0.09, z);
arrow.rotation.z = Math.PI;
rechargeGroup.add(arrow);
}
scene.add(rechargeGroup);
// Well assembly.
const well = new THREE.Group();
well.position.set(wellX, 0, wellZ);
scene.add(well);
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0x829398,
roughness: 0.4,
metalness: 0.38,
transparent: true,
opacity: 0.86,
depthWrite: false,
flatShading: true
});
const screenMaterial = new THREE.MeshStandardMaterial({
color: 0x516970,
roughness: 0.48,
metalness: 0.32,
transparent: true,
opacity: 0.16,
depthWrite: false,
side: THREE.DoubleSide
});
const casingBottom = WATER_TABLE;
const casingTop = 4.05;
const casingHeight = casingTop - casingBottom;
const casing = new THREE.Mesh(
new THREE.CylinderGeometry(
0.45,
0.45,
casingHeight,
12,
1,
true
),
metalMaterial
);
casing.position.y = (casingTop + casingBottom) * 0.5;
casing.renderOrder = 4;
well.add(casing);
const screenBottom = -5.05;
const screenTop = -1.0;
const screenHeight = screenTop - screenBottom;
const screenCenter = (screenTop + screenBottom) * 0.5;
const screenEnvelope = new THREE.Mesh(
new THREE.CylinderGeometry(
0.46,
0.46,
screenHeight,
12,
1,
true
),
screenMaterial
);
screenEnvelope.position.y = screenCenter;
screenEnvelope.renderOrder = 3;
well.add(screenEnvelope);
const ribMaterial = new THREE.MeshStandardMaterial({
color: 0x71858a,
roughness: 0.42,
metalness: 0.38,
flatShading: true
});
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const rib = new THREE.Mesh(
new THREE.CylinderGeometry(0.036, 0.036, screenHeight, 5),
ribMaterial
);
rib.position.set(
Math.cos(angle) * 0.44,
screenCenter,
Math.sin(angle) * 0.44
);
rib.castShadow = true;
well.add(rib);
}
for (let y = screenBottom + 0.12; y <= screenTop; y += 0.34) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.032, 4, 12),
ribMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = y;
ring.castShadow = true;
well.add(ring);
}
const wellWaterHeight = WATER_TABLE - screenBottom;
const wellWater = new THREE.Mesh(
new THREE.CylinderGeometry(
0.265,
0.265,
wellWaterHeight,
10
),
new THREE.MeshStandardMaterial({
color: 0x169bd2,
emissive: 0x075f86,
emissiveIntensity: 0.2,
transparent: true,
opacity: 0.62,
depthWrite: false,
flatShading: true
})
);
wellWater.position.y = (WATER_TABLE + screenBottom) * 0.5;
wellWater.renderOrder = 3;
well.add(wellWater);
const sump = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.46, 0.45, 10),
metalMaterial
);
sump.position.y = screenBottom - 0.16;
well.add(sump);
// Gravel filter pack around the screen.
const gravelCount = 82;
const gravel = new THREE.InstancedMesh(
new THREE.IcosahedronGeometry(0.17, 0),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
flatShading: true
}),
gravelCount
);
for (let i = 0; i < gravelCount; i++) {
const angle = random() * Math.PI * 2;
const radius = 0.72 + random() * 0.28;
const scale = 0.72 + random() * 0.65;
dummy.position.set(
Math.cos(angle) * radius,
screenBottom + 0.12 + random() * (screenHeight - 0.24),
Math.sin(angle) * radius
);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
dummy.scale.set(scale, scale * 0.8, scale);
dummy.updateMatrix();
gravel.setMatrixAt(i, dummy.matrix);
gravel.setColorAt(
i,
new THREE.Color().setHSL(
0.1 + random() * 0.05,
0.08,
0.39 + random() * 0.25
)
);
}
gravel.instanceMatrix.needsUpdate = true;
gravel.instanceColor.needsUpdate = true;
gravel.castShadow = true;
well.add(gravel);
// Pump and wellhead.
const pumpMaterial = new THREE.MeshStandardMaterial({
color: 0x36545c,
roughness: 0.45,
metalness: 0.42,
emissive: 0x9f241b,
emissiveIntensity: 0.32,
flatShading: true
});
const wellheadBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.63, 0.63, 0.24, 10),
pumpMaterial
);
wellheadBase.position.y = 4.13;
wellheadBase.castShadow = true;
well.add(wellheadBase);
const pumpBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.47, 0.57, 0.72, 10),
pumpMaterial
);
pumpBody.position.y = 4.61;
pumpBody.castShadow = true;
well.add(pumpBody);
const pumpCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.4, 0.47, 0.22, 10),
pumpMaterial
);
pumpCap.position.y = 5.06;
pumpCap.castShadow = true;
well.add(pumpCap);
const valveStem = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.07, 0.34, 8),
ribMaterial
);
valveStem.position.y = 5.3;
well.add(valveStem);
const valveMaterial = new THREE.MeshStandardMaterial({
color: 0xc94b3f,
roughness: 0.52,
metalness: 0.15,
emissive: 0x7b160f,
emissiveIntensity: 0.2,
flatShading: true
});
const valveWheel = new THREE.Mesh(
new THREE.TorusGeometry(0.35, 0.045, 6, 12),
valveMaterial
);
valveWheel.rotation.x = Math.PI / 2;
valveWheel.position.y = 5.49;
well.add(valveWheel);
const spokeA = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.64, 5),
valveMaterial
);
spokeA.rotation.z = Math.PI / 2;
spokeA.position.y = 5.49;
well.add(spokeA);
const spokeB = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.64, 5),
valveMaterial
);
spokeB.rotation.x = Math.PI / 2;
spokeB.position.y = 5.49;
well.add(spokeB);
// Small arrows indicate local flow toward the screened interval.
const flowArrows = [];
const flowArrowMaterial = new THREE.MeshBasicMaterial({
color: 0x168fd1,
transparent: true,
opacity: 0.72
});
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2 + 0.18;
const radius = 1.72;
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.34, 5),
flowArrowMaterial
);
arrow.position.set(
Math.cos(angle) * radius,
-4.65 + (i % 4) * 0.83,
Math.sin(angle) * radius
);
const direction = new THREE.Vector3(
-Math.cos(angle),
0,
-Math.sin(angle)
).normalize();
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
arrow.userData.phase = i * 0.65;
flowArrows.push(arrow);
well.add(arrow);
}
// Annotation leaders.
const annotationDefinitions = [
{
element: document.querySelector(".a-vadose"),
anchor: new THREE.Vector3(-5.8, 1.15, 8.08)
},
{
element: document.querySelector(".a-water"),
anchor: new THREE.Vector3(-7.5, WATER_TABLE, 8.12)
},
{
element: document.querySelector(".a-screen"),
anchor: new THREE.Vector3(1.08, -3.25, 1.12)
},
{
element: document.querySelector(".a-pore"),
anchor: new THREE.Vector3(6.75, -3.35, 8.1)
},
{
element: document.querySelector(".a-base"),
anchor: new THREE.Vector3(7.25, -6.2, 8.1)
},
{
element: document.querySelector(".a-head"),
anchor: new THREE.Vector3(0.65, 5.42, 0.65)
}
];
const leaderSvg = document.querySelector("#leaderSvg");
const svgNamespace = "http://www.w3.org/2000/svg";
annotationDefinitions.forEach((definition) => {
const line = document.createElementNS(svgNamespace, "line");
line.setAttribute("stroke", "#55757c");
line.setAttribute("stroke-width", "1");
line.setAttribute("stroke-opacity", "0.62");
line.setAttribute("stroke-dasharray", "3 3");
const dot = document.createElementNS(svgNamespace, "circle");
dot.setAttribute("r", "3.2");
dot.setAttribute("fill", "#168fd1");
dot.setAttribute("stroke", "#f7faf5");
dot.setAttribute("stroke-width", "1.5");
leaderSvg.appendChild(line);
leaderSvg.appendChild(dot);
definition.line = line;
definition.dot = dot;
});
function updateAnnotations() {
annotationDefinitions.forEach((definition) => {
const element = definition.element;
const display = getComputedStyle(element).display;
if (display === "none") {
definition.line.style.display = "none";
definition.dot.style.display = "none";
return;
}
const projected = definition.anchor.clone().project(camera);
const screenX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const screenY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const rect = element.getBoundingClientRect();
const side = element.dataset.side;
const startX = side === "left" ? rect.right : rect.left;
const startY = rect.top + rect.height * 0.5;
definition.line.style.display = "";
definition.dot.style.display = "";
definition.line.setAttribute("x1", startX.toFixed(1));
definition.line.setAttribute("y1", startY.toFixed(1));
definition.line.setAttribute("x2", screenX.toFixed(1));
definition.line.setAttribute("y2", screenY.toFixed(1));
definition.dot.setAttribute("cx", screenX.toFixed(1));
definition.dot.setAttribute("cy", screenY.toFixed(1));
});
}
// UI switches.
document.querySelector("#grainToggle").addEventListener("change", (event) => {
grainMeshes.forEach((mesh) => {
mesh.visible = event.target.checked;
});
});
document.querySelector("#poreToggle").addEventListener("change", (event) => {
poreWater.visible = event.target.checked;
});
document.querySelector("#shellToggle").addEventListener("change", (event) => {
shellMeshes.forEach((mesh) => {
mesh.visible = event.target.checked;
});
});
function resetCamera() {
desiredView.theta = initialView.theta;
desiredView.phi = initialView.phi;
desiredView.radius = initialView.radius;
}
document.querySelector("#resetView").addEventListener("click", resetCamera);
// Custom camera controls: pointer orbit, pinch zoom, wheel zoom.
const pointers = new Map();
let lastPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) {
return;
}
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) {
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 (lastPinchDistance > 0) {
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * (lastPinchDistance / distance),
19,
48
);
}
lastPinchDistance = distance;
return;
}
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
desiredView.theta -= deltaX * 0.006;
desiredView.phi = THREE.MathUtils.clamp(
desiredView.phi - deltaY * 0.005,
0.48,
1.47
);
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
lastPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * Math.exp(event.deltaY * 0.001),
19,
48
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
leaderSvg.setAttribute("viewBox", `0 0 ${width} ${height}`);
});
leaderSvg.setAttribute(
"viewBox",
`0 0 ${window.innerWidth} ${window.innerHeight}`
);
// Render loop.
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const damping = 1 - Math.pow(0.001, 1 / 60);
currentView.theta +=
(desiredView.theta - currentView.theta) * damping;
currentView.phi +=
(desiredView.phi - currentView.phi) * damping;
currentView.radius +=
(desiredView.radius - currentView.radius) * damping;
applyCamera();
poreMaterial.emissiveIntensity =
0.15 + Math.sin(elapsed * 1.15) * 0.035;
pumpMaterial.emissiveIntensity =
0.25 + Math.sin(elapsed * 2.8) * 0.16;
flowArrows.forEach((arrow) => {
const pulse = 0.86 + Math.sin(elapsed * 2.1 + arrow.userData.phase) * 0.14;
arrow.scale.setScalar(pulse);
});
renderer.render(scene, camera);
updateAnnotations();
}
animate();
</script>
</body>
</html>
```