Prompt specification
Build or customize the Three.js 3D scene "Connected water-table teaching tank" 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: Connected water-table teaching tank
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/connected-water-table-teaching-tank-x1206
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts aquifers and wells. Use a shallow transparent sand-model tank with two observation tubes; a water-level control changes both visible levels consistently under a stated connected equilibrium assumption. Stylized solid forms.
Working Three.js Starter (connected-water-table-teaching-tank-x1206):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Connected Aquifer and Observation Wells</title>
<style>
:root {
color-scheme: light;
--ink: #17323a;
--muted: #557078;
--panel: rgba(255, 255, 255, 0.90);
--line: rgba(23, 50, 58, 0.14);
--teal: #159da5;
--sand: #d9ae68;
--coral: #ef765f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eff1;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.panel {
position: fixed;
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(29, 58, 67, 0.16),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 27px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 9px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.assumption {
margin: 0 0 17px;
padding: 11px 12px;
border-left: 4px solid var(--teal);
border-radius: 0 10px 10px 0;
background: rgba(21, 157, 165, 0.075);
font-size: 12px;
line-height: 1.45;
}
.assumption strong {
display: block;
margin-bottom: 2px;
}
.level-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
margin-bottom: 8px;
font-size: 13px;
font-weight: 700;
}
output {
color: var(--teal);
font-size: 17px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--teal);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.equation {
display: flex;
align-items: center;
justify-content: space-between;
margin: 14px 0;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.64);
font-size: 13px;
font-weight: 750;
}
#equation-value {
color: var(--teal);
font-variant-numeric: tabular-nums;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
margin: 0 0 15px;
color: var(--muted);
font-size: 11px;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 11px;
height: 11px;
flex: 0 0 auto;
border-radius: 3px;
}
.swatch.sand {
background: var(--sand);
}
.swatch.water {
background: #35b9c0;
}
.swatch.level {
background: var(--coral);
}
.swatch.gravel {
background: #9e8261;
}
.controls {
display: flex;
gap: 7px;
}
button {
min-height: 35px;
padding: 7px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.86);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
button:hover {
border-color: rgba(21, 157, 165, 0.45);
background: #fff;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(21, 157, 165, 0.25);
outline-offset: 2px;
}
.hint {
position: fixed;
right: 18px;
bottom: 16px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 9px;
background: rgba(255, 255, 255, 0.75);
color: var(--muted);
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #e8eff1;
color: var(--muted);
font-size: 14px;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 640px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
.intro {
display: none;
}
.assumption {
margin-bottom: 12px;
}
.legend {
margin-bottom: 10px;
}
.hint {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive aquifer and observation well model"></canvas>
<section class="panel" aria-label="Aquifer model controls">
<p class="eyebrow">Hydrogeology Sandbox</p>
<h1>Aquifer + Observation Wells</h1>
<p class="intro">
A shallow transparent sand tank with two connected observation tubes.
Move the water-level control to change the shared hydraulic head.
</p>
<p class="assumption">
<strong>Connected equilibrium assumption</strong>
The homogeneous aquifer is hydraulically connected and has no hydraulic
gradient between the wells. Therefore, h<sub>A</sub> = h<sub>B</sub>, and
the saturated zone, common datum, and both tube levels remain synchronized.
</p>
<div class="level-head">
<label for="level">Common water level</label>
<output id="level-value" for="level">1.15</output>
</div>
<input
id="level"
type="range"
min="0.35"
max="1.78"
step="0.01"
value="1.15"
aria-label="Common aquifer water level"
>
<div class="range-labels">
<span>LOW</span>
<span>HIGH</span>
</div>
<div class="equation">
<span>h<sub>A</sub> = h<sub>B</sub></span>
<span id="equation-value">1.15 model units</span>
</div>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch sand"></i>Porous sand</span>
<span><i class="swatch gravel"></i>Gravel aquifer</span>
<span><i class="swatch water"></i>Saturated water</span>
<span><i class="swatch level"></i>Shared level datum</span>
</div>
<div class="controls">
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button id="reset-view" type="button">Reset view</button>
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
</div>
</section>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Wheel to zoom</div>
<div id="loading">Loading Three.js scene…</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.querySelector("#scene");
const levelInput = document.querySelector("#level");
const levelValue = document.querySelector("#level-value");
const equationValue = document.querySelector("#equation-value");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eff1);
scene.fog = new THREE.Fog(0xe8eff1, 18, 34);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const hemi = new THREE.HemisphereLight(0xffffff, 0x71838a, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff8e9, 3.1);
sun.position.set(6.5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8e9ef, 0.8);
fill.position.set(-7, 5, -6);
scene.add(fill);
const materials = {
base: new THREE.MeshStandardMaterial({
color: 0x6f858d,
roughness: 0.72,
metalness: 0.08,
flatShading: true
}),
baseTop: new THREE.MeshStandardMaterial({
color: 0x9aadb2,
roughness: 0.68,
flatShading: true
}),
gravel: new THREE.MeshStandardMaterial({
color: 0xa88c63,
roughness: 1,
flatShading: true
}),
sand: new THREE.MeshStandardMaterial({
color: 0xdfb875,
roughness: 0.98,
flatShading: true
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0xd9f5f5,
transparent: true,
opacity: 0.13,
roughness: 0.08,
metalness: 0,
transmission: 0,
depthWrite: false,
side: THREE.DoubleSide
}),
tubeGlass: new THREE.MeshPhysicalMaterial({
color: 0xd8f5f4,
transparent: true,
opacity: 0.18,
roughness: 0.06,
metalness: 0,
depthWrite: false,
side: THREE.DoubleSide
}),
tubeWater: new THREE.MeshStandardMaterial({
color: 0x159fa9,
transparent: true,
opacity: 0.78,
roughness: 0.22,
depthWrite: false
}),
saturation: new THREE.MeshBasicMaterial({
color: 0x25b8c4,
transparent: true,
opacity: 0.27,
depthWrite: false,
side: THREE.DoubleSide
}),
surface: new THREE.MeshBasicMaterial({
color: 0x53d4d8,
transparent: true,
opacity: 0.17,
depthWrite: false,
depthTest: false,
side: THREE.DoubleSide
}),
pipe: new THREE.MeshStandardMaterial({
color: 0x50676e,
roughness: 0.52,
metalness: 0.28,
flatShading: true
}),
collar: new THREE.MeshStandardMaterial({
color: 0xe8f1ef,
roughness: 0.48,
metalness: 0.12,
flatShading: true
}),
marker: new THREE.MeshStandardMaterial({
color: 0xef765f,
roughness: 0.5,
emissive: 0x5a1308,
emissiveIntensity: 0.08
}),
datum: new THREE.MeshBasicMaterial({
color: 0x22b6bc,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
})
};
function box(width, height, depth, material, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addEdges(mesh, opacity = 0.34) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x5c7a82,
transparent: true,
opacity
})
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
scene.add(edges);
return edges;
}
// Ground and stylized plinth.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0xe5ecee,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.5;
ground.receiveShadow = true;
scene.add(ground);
box(11.7, 0.24, 5.35, materials.base, 0, -0.18, 0);
box(11.35, 0.08, 5.0, materials.baseTop, 0, -0.035, 0);
const footGeometry = new THREE.BoxGeometry(1.15, 0.18, 0.9);
for (const x of [-4.8, 4.8]) {
for (const z of [-1.9, 1.9]) {
const foot = new THREE.Mesh(footGeometry, materials.base);
foot.position.set(x, -0.39, z);
foot.castShadow = true;
foot.receiveShadow = true;
scene.add(foot);
}
}
// Transparent shallow tank.
const tankHeight = 3.0;
const tankY = tankHeight / 2;
const glassBottom = box(
11.1, 0.07, 4.95,
materials.glass,
0, 0.005, 0,
false
);
glassBottom.renderOrder = 5;
const glassFront = box(
11.1, tankHeight, 0.08,
materials.glass,
0, tankY, 2.45,
false
);
const glassBack = box(
11.1, tankHeight, 0.08,
materials.glass,
0, tankY, -2.45,
false
);
const glassLeft = box(
0.08, tankHeight, 4.9,
materials.glass,
-5.5, tankY, 0,
false
);
const glassRight = box(
0.08, tankHeight, 4.9,
materials.glass,
5.5, tankY, 0,
false
);
for (const wall of [glassFront, glassBack, glassLeft, glassRight]) {
wall.renderOrder = 5;
addEdges(wall, 0.42);
}
// Open tank rim.
for (const z of [-2.45, 2.45]) {
const rim = box(11.14, 0.055, 0.11, materials.glass, 0, 3.01, z, false);
rim.renderOrder = 5;
}
for (const x of [-5.5, 5.5]) {
const rim = box(0.11, 0.055, 4.9, materials.glass, x, 3.01, 0, false);
rim.renderOrder = 5;
}
// Solid aquifer layers.
const gravelLayer = box(
10.7, 0.58, 4.3,
materials.gravel,
0, 0.35, 0
);
const sandLayer = box(
10.7, 1.22, 4.3,
materials.sand,
0, 1.25, 0
);
addEdges(gravelLayer, 0.16);
addEdges(sandLayer, 0.14);
// Deterministic low-poly aggregate texture.
function randomGenerator(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 = randomGenerator(81273);
const pebbleGeometry = new THREE.DodecahedronGeometry(0.105, 0);
const pebbleColors = [0xb89362, 0xe3bd79, 0xc59a5f];
function makePebbleGroup(count, color, place) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
});
const mesh = new THREE.InstancedMesh(pebbleGeometry, material, count);
const dummy = new THREE.Object3D();
for (let i = 0; i < count; i++) {
place(dummy, i, random);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
for (let group = 0; group < 3; group++) {
makePebbleGroup(28, pebbleColors[group], (dummy, i, rand) => {
dummy.position.set(
-5.12 + rand() * 10.24,
0.11 + rand() * 1.66,
2.165
);
dummy.rotation.set(rand() * 2, rand() * 2, rand() * 2);
dummy.scale.set(
0.55 + rand() * 1.15,
0.45 + rand() * 0.9,
0.4 + rand() * 0.65
);
});
makePebbleGroup(16, pebbleColors[group], (dummy, i, rand) => {
dummy.position.set(
5.365,
0.11 + rand() * 1.66,
-2.03 + rand() * 4.06
);
dummy.rotation.set(rand() * 2, rand() * 2, rand() * 2);
dummy.scale.set(
0.45 + rand() * 0.75,
0.45 + rand() * 0.9,
0.55 + rand() * 1.05
);
});
makePebbleGroup(15, pebbleColors[group], (dummy, i, rand) => {
dummy.position.set(
-5.08 + rand() * 10.16,
1.855,
-2.02 + rand() * 4.04
);
dummy.rotation.set(rand() * 2, rand() * 2, rand() * 2);
dummy.scale.set(
0.65 + rand() * 1.25,
0.22 + rand() * 0.28,
0.65 + rand() * 1.25
);
});
}
// Transparent saturated-zone overlays on the visible cut faces.
const saturationFront = box(
10.68, 1, 0.025,
materials.saturation,
0, 0.5, 2.175,
false
);
saturationFront.renderOrder = 2;
const saturationSide = box(
0.025, 1, 4.28,
materials.saturation,
5.375, 0.5, 0,
false
);
saturationSide.renderOrder = 2;
// Conceptual common water-table surface.
const waterSurface = new THREE.Mesh(
new THREE.PlaneGeometry(10.66, 4.25),
materials.surface
);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.position.y = 1.15;
waterSurface.renderOrder = 5;
scene.add(waterSurface);
// Observation tubes and their inlets.
const TUBE_Z = 3.03;
const TUBE_BOTTOM = 0.06;
const TUBE_TOP = 3.66;
const tubeHeight = TUBE_TOP - TUBE_BOTTOM;
const tubeXPositions = [-3.55, 3.55];
const wells = [];
function horizontalCylinder(radius, length, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 16),
material
);
mesh.rotation.x = Math.PI / 2;
mesh.position.set(x, y, z);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
function makeRing(radius, tubeRadius, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tubeRadius, 8, 32),
material
);
mesh.rotation.x = Math.PI / 2;
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
for (const x of tubeXPositions) {
const outer = new THREE.Mesh(
new THREE.CylinderGeometry(
0.285,
0.285,
tubeHeight,
24,
1,
true
),
materials.tubeGlass
);
outer.position.set(x, (TUBE_TOP + TUBE_BOTTOM) / 2, TUBE_Z);
outer.renderOrder = 6;
scene.add(outer);
const water = new THREE.Mesh(
new THREE.CylinderGeometry(0.185, 0.185, 1, 24),
materials.tubeWater
);
water.position.set(x, 0.5, TUBE_Z);
water.renderOrder = 3;
scene.add(water);
const surface = new THREE.Mesh(
new THREE.CircleGeometry(0.185, 24),
new THREE.MeshBasicMaterial({
color: 0x54d8d7,
transparent: true,
opacity: 0.95,
side: THREE.DoubleSide
})
);
surface.rotation.x = -Math.PI / 2;
surface.position.set(x, 1.15, TUBE_Z);
surface.renderOrder = 7;
scene.add(surface);
makeRing(0.29, 0.035, materials.collar, x, TUBE_TOP, TUBE_Z);
makeRing(0.29, 0.035, materials.collar, x, TUBE_BOTTOM, TUBE_Z);
// Low horizontal connector from the aquifer cut face into the tube.
horizontalCylinder(
0.105,
1.02,
materials.pipe,
x,
0.26,
2.58
);
const connectorCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.145, 0.145, 0.11, 16),
materials.collar
);
connectorCollar.rotation.x = Math.PI / 2;
connectorCollar.position.set(x, 0.26, 2.32);
scene.add(connectorCollar);
// Gauge ticks.
for (let y = 0.40; y <= 1.81; y += 0.28) {
const major = Math.abs(y / 0.56 - Math.round(y / 0.56)) < 0.03;
const tick = box(
major ? 0.18 : 0.12,
0.018,
0.025,
materials.pipe,
x + 0.29,
y,
TUBE_Z,
false
);
tick.renderOrder = 7;
}
const marker = makeRing(
0.315,
0.026,
materials.marker,
x,
1.15,
TUBE_Z
);
marker.renderOrder = 8;
wells.push({ x, water, surface, marker });
}
// A single datum visibly connects the equal tube levels.
const commonDatum = box(
7.4,
0.027,
0.035,
materials.datum,
0,
1.15,
TUBE_Z,
false
);
commonDatum.renderOrder = 8;
// Canvas-generated labels keep the scene standalone.
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function makeLabel(text, accent = "#159da5", width = 512, height = 128) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = width;
labelCanvas.height = height;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
roundedRect(ctx, 5, 5, width - 10, height - 10, 24);
ctx.fillStyle = "rgba(255,255,255,0.94)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 6;
ctx.stroke();
ctx.fillStyle = "#17323a";
ctx.font = "750 36px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
const wellLabelA = makeLabel("OBSERVATION WELL A");
wellLabelA.scale.set(3.25, 0.81, 1);
wellLabelA.position.set(-3.55, 4.17, TUBE_Z);
const wellLabelB = makeLabel("OBSERVATION WELL B");
wellLabelB.scale.set(3.25, 0.81, 1);
wellLabelB.position.set(3.55, 4.17, TUBE_Z);
const aquiferLabel = makeLabel("POROUS SAND AQUIFER", "#d29b4f");
aquiferLabel.scale.set(3.45, 0.76, 1);
aquiferLabel.position.set(0, 2.62, 2.48);
const equalityLabel = makeLabel("hA = hB", "#ef765f", 420, 120);
equalityLabel.scale.set(1.75, 0.50, 1);
equalityLabel.position.set(0, 1.48, TUBE_Z + 0.03);
// Update every water representation from exactly the same level value.
function setWaterLevel(value) {
const level = THREE.MathUtils.clamp(value, 0.35, 1.78);
const bottom = TUBE_BOTTOM;
const height = Math.max(0.01, level - bottom);
const middle = (bottom + level) / 2;
saturationFront.scale.y = height;
saturationFront.position.y = middle;
saturationSide.scale.y = height;
saturationSide.position.y = middle;
waterSurface.position.y = level;
for (const well of wells) {
well.water.scale.y = height;
well.water.position.y = middle;
well.surface.position.y = level + 0.004;
well.marker.position.y = level;
}
commonDatum.position.y = level;
equalityLabel.position.y = level + 0.33;
levelValue.textContent = level.toFixed(2);
equationValue.textContent = `${level.toFixed(2)} model units`;
}
levelInput.addEventListener("input", (event) => {
setWaterLevel(Number(event.target.value));
});
setWaterLevel(Number(levelInput.value));
// Camera controls implemented directly without Three.js addons.
const target = new THREE.Vector3(0, 1.35, 0);
const initial = {
azimuth: 0.62,
polar: 1.03,
radius: 13.8
};
let azimuth = initial.azimuth;
let polar = initial.polar;
let radius = initial.radius;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
}
function resetCamera() {
target.set(0, 1.35, 0);
azimuth = initial.azimuth;
polar = initial.polar;
radius = initial.radius;
updateCamera();
}
resetCamera();
let dragging = false;
let lastX = 0;
let lastY = 0;
let dragButton = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
dragButton = event.button;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragButton === 2 || event.shiftKey) {
const panScale = radius * 0.00125;
const rightX = Math.cos(azimuth);
const rightZ = -Math.sin(azimuth);
target.x -= dx * panScale * rightX;
target.z -= dx * panScale * rightZ;
target.y += dy * panScale;
target.x = THREE.MathUtils.clamp(target.x, -3.5, 3.5);
target.y = THREE.MathUtils.clamp(target.y, 0.2, 3.3);
target.z = THREE.MathUtils.clamp(target.z, -2.5, 2.5);
} else {
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(
polar - dy * 0.005,
0.48,
1.42
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
8.5,
21
);
updateCamera();
}, { passive: false });
document.querySelector("#reset-view").addEventListener("click", resetCamera);
document.querySelector("#zoom-in").addEventListener("click", () => {
radius = Math.max(8.5, radius - 1);
updateCamera();
});
document.querySelector("#zoom-out").addEventListener("click", () => {
radius = Math.min(21, radius + 1);
updateCamera();
});
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight, false);
}
addEventListener("resize", resize);
renderer.render(scene, camera);
document.querySelector("#loading").classList.add("hidden");
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```