Prompt specification
Build or customize the Three.js 3D scene "Reservoir exchange desktop 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: Reservoir exchange desktop model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reservoir-exchange-desktop-model-x1265
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the water cycle. Build a small basin, cloud disk, mountain, and buried storage chamber with distinct arrows for evaporation, precipitation, runoff, and infiltration; each arrow must reach its named reservoir. Low-poly.
Working Three.js Starter (reservoir-exchange-desktop-model-x1265):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Low-Poly Water Cycle</title>
<style>
:root {
color-scheme: dark;
--evaporation: #43e2c0;
--precipitation: #55aaff;
--runoff: #ff9d4d;
--infiltration: #b681ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b1726;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.heading {
position: fixed;
top: 24px;
left: 26px;
z-index: 10;
max-width: min(480px, calc(100vw - 52px));
pointer-events: none;
color: #f4f8ff;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.55);
}
.heading .eyebrow {
margin-bottom: 8px;
color: #78dbc9;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.heading h1 {
margin: 0;
font-size: clamp(26px, 4vw, 44px);
line-height: 1;
letter-spacing: -0.045em;
}
.heading p {
margin: 10px 0 0;
color: #bdc9d8;
font-size: 13px;
line-height: 1.5;
}
.legend {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 10;
width: min(330px, calc(100vw - 44px));
padding: 15px 16px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 16px;
background: rgba(10, 22, 38, 0.82);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(14px);
}
.legend-title {
margin-bottom: 10px;
color: #8ea0b7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 91px 1fr;
align-items: center;
gap: 8px;
margin: 8px 0;
color: #eef4fc;
font-size: 12px;
}
.legend-row strong {
font-weight: 750;
}
.legend-row span:last-child {
color: #9eafc4;
font-size: 11px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: 0 0 13px currentColor;
}
.swatch.evaporation {
color: var(--evaporation);
background: var(--evaporation);
}
.swatch.precipitation {
color: var(--precipitation);
background: var(--precipitation);
}
.swatch.runoff {
color: var(--runoff);
background: var(--runoff);
}
.swatch.infiltration {
color: var(--infiltration);
background: var(--infiltration);
}
.controls-note {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.09);
color: #8293aa;
font-size: 10px;
}
button {
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 9px;
padding: 7px 10px;
background: rgba(255, 255, 255, 0.07);
color: #e8f1fc;
font: inherit;
font-size: 10px;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.13);
}
.world-label,
.flow-label {
position: fixed;
z-index: 6;
pointer-events: none;
white-space: nowrap;
transform: translate(-50%, -50%);
will-change: left, top;
}
.world-label {
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
background: rgba(7, 17, 30, 0.78);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
color: #f2f7ff;
font-size: 11px;
font-weight: 700;
backdrop-filter: blur(8px);
}
.flow-label {
padding: 4px 7px;
border: 1px solid currentColor;
border-radius: 999px;
background: rgba(7, 17, 30, 0.78);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.24);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.025em;
}
.flow-label.evaporation {
color: var(--evaporation);
}
.flow-label.precipitation {
color: var(--precipitation);
}
.flow-label.runoff {
color: var(--runoff);
}
.flow-label.infiltration {
color: var(--infiltration);
}
@media (max-width: 700px) {
.heading {
top: 17px;
left: 18px;
}
.heading p {
display: none;
}
.legend {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
.legend-row {
grid-template-columns: 10px 86px 1fr;
margin: 6px 0;
}
.controls-note {
margin-top: 9px;
padding-top: 9px;
}
.world-label {
font-size: 9px;
padding: 5px 7px;
}
.flow-label {
font-size: 9px;
}
}
</style>
</head>
<body>
<header class="heading">
<div class="eyebrow">Interactive systems diorama</div>
<h1>Water Cycle</h1>
<p>
A low-poly cross-section of atmosphere, mountain, surface water, and
underground storage.
</p>
</header>
<aside class="legend">
<div class="legend-title">Flow pathways</div>
<div class="legend-row">
<i class="swatch evaporation"></i>
<strong>Evaporation</strong>
<span>Basin lake → Cloud disk</span>
</div>
<div class="legend-row">
<i class="swatch precipitation"></i>
<strong>Precipitation</strong>
<span>Cloud disk → Mountain snowpack</span>
</div>
<div class="legend-row">
<i class="swatch runoff"></i>
<strong>Runoff</strong>
<span>Mountain → Basin lake</span>
</div>
<div class="legend-row">
<i class="swatch infiltration"></i>
<strong>Infiltration</strong>
<span>Basin lake → Buried chamber</span>
</div>
<div class="controls-note">
<span>Drag to orbit · Scroll or pinch to zoom</span>
<button id="resetCamera" type="button">Reset view</button>
</div>
</aside>
<div id="cloudLabel" class="world-label">Cloud disk</div>
<div id="mountainLabel" class="world-label">Mountain snowpack</div>
<div id="basinLabel" class="world-label">Basin lake</div>
<div id="chamberLabel" class="world-label">Buried storage chamber</div>
<div id="evaporationLabel" class="flow-label evaporation">Evaporation</div>
<div id="precipitationLabel" class="flow-label precipitation">Precipitation</div>
<div id="runoffLabel" class="flow-label runoff">Runoff</div>
<div id="infiltrationLabel" class="flow-label infiltration">Infiltration</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1726);
scene.fog = new THREE.Fog(0x0b1726, 25, 48);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly water cycle diagram. Drag to orbit and scroll to zoom."
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc9e8ff, 0x344132, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d6, 3.1);
sun.position.set(7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x5dc7ff, 1.3);
rimLight.position.set(-8, 7, -6);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0x61775a,
roughness: 0.95,
flatShading: true
}),
soil: new THREE.MeshStandardMaterial({
color: 0x9a6848,
roughness: 1,
flatShading: true
}),
soilDark: new THREE.MeshStandardMaterial({
color: 0x6d4938,
roughness: 1,
flatShading: true
}),
stone: new THREE.MeshStandardMaterial({
color: 0x7c807c,
roughness: 0.95,
flatShading: true
}),
stoneDark: new THREE.MeshStandardMaterial({
color: 0x454d50,
roughness: 1,
flatShading: true
}),
mountain: new THREE.MeshStandardMaterial({
color: 0x66766f,
roughness: 0.96,
flatShading: true
}),
mountainLight: new THREE.MeshStandardMaterial({
color: 0x81918a,
roughness: 0.96,
flatShading: true
}),
snow: new THREE.MeshStandardMaterial({
color: 0xe7f3f2,
roughness: 0.85,
flatShading: true
}),
cloud: new THREE.MeshStandardMaterial({
color: 0xe5edf0,
roughness: 0.88,
flatShading: true
}),
cloudShade: new THREE.MeshStandardMaterial({
color: 0xb8cbd4,
roughness: 0.9,
flatShading: true
}),
basin: new THREE.MeshStandardMaterial({
color: 0xc5aa70,
roughness: 0.96,
flatShading: true,
side: THREE.DoubleSide
}),
water: new THREE.MeshStandardMaterial({
color: 0x1e9bd2,
emissive: 0x075878,
emissiveIntensity: 0.52,
roughness: 0.28,
metalness: 0.05,
flatShading: true
}),
chamberWater: new THREE.MeshStandardMaterial({
color: 0x278fd0,
emissive: 0x063e72,
emissiveIntensity: 0.7,
roughness: 0.24,
flatShading: true
})
};
function addMesh(geometry, material, position, castShadow = true) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Landscape cross-section
// -------------------------------------------------------------------------
addMesh(
new THREE.BoxGeometry(11.7, 2.9, 3.35),
materials.soilDark,
new THREE.Vector3(0, -1.68, -1.0)
);
addMesh(
new THREE.BoxGeometry(11.9, 0.42, 5.35),
materials.soil,
new THREE.Vector3(0, -0.24, 0)
);
addMesh(
new THREE.BoxGeometry(11.9, 0.09, 5.35),
materials.ground,
new THREE.Vector3(0, 0.005, 0),
false
);
// Soil strata visible along the cutaway.
[
[-0.95, 0x85563e],
[-1.62, 0xa66d4c],
[-2.32, 0x74503e]
].forEach(([y, color]) => {
const strata = new THREE.Mesh(
new THREE.BoxGeometry(11.65, 0.12, 0.06),
new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
})
);
strata.position.set(0, y, 0.69);
scene.add(strata);
});
// -------------------------------------------------------------------------
// Low-poly mountain and snowpack
// -------------------------------------------------------------------------
const mountain = addMesh(
new THREE.ConeGeometry(2.5, 4.25, 7, 3),
materials.mountain,
new THREE.Vector3(-3.25, 2.125, -0.45)
);
mountain.rotation.y = 0.18;
const secondaryMountain = addMesh(
new THREE.ConeGeometry(1.55, 2.65, 6, 2),
materials.mountainLight,
new THREE.Vector3(-4.35, 1.325, -1.0)
);
secondaryMountain.rotation.y = 0.35;
addMesh(
new THREE.ConeGeometry(0.88, 1.38, 7, 1),
materials.snow,
new THREE.Vector3(-3.25, 3.55, -0.45)
);
addMesh(
new THREE.ConeGeometry(0.53, 0.82, 6, 1),
materials.snow,
new THREE.Vector3(-4.35, 2.44, -1.0)
);
// A small snow shelf provides a precise precipitation destination.
const snowShelf = addMesh(
new THREE.IcosahedronGeometry(0.42, 1),
materials.snow,
new THREE.Vector3(-3.05, 3.31, 0.05)
);
snowShelf.scale.set(1.0, 0.5, 0.32);
// -------------------------------------------------------------------------
// Basin: faceted sloping rim and polygonal lake
// -------------------------------------------------------------------------
function createBasinGeometry(innerRadius, outerRadius, segments) {
const positions = [];
const indices = [];
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const x = Math.cos(angle);
const z = Math.sin(angle);
positions.push(
innerRadius * x, -0.09, innerRadius * z,
outerRadius * x, 0.32, outerRadius * z
);
}
for (let i = 0; i < segments; i++) {
const next = (i + 1) % segments;
const a = i * 2;
const b = i * 2 + 1;
const c = next * 2;
const d = next * 2 + 1;
indices.push(a, b, c, b, d, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const basinCenter = new THREE.Vector3(2.25, 0, 0.1);
const basinRim = addMesh(
createBasinGeometry(1.72, 2.58, 18),
materials.basin,
basinCenter
);
basinRim.receiveShadow = true;
const lake = addMesh(
new THREE.CylinderGeometry(1.66, 1.58, 0.12, 18),
materials.water,
new THREE.Vector3(2.25, 0.035, 0.1),
false
);
// Small faceted rocks around the basin.
const rockGeometry = new THREE.DodecahedronGeometry(0.18, 0);
const rockPositions = [
[0.2, 0.29, 0.85],
[0.75, 0.22, 1.3],
[4.05, 0.24, 0.95],
[3.75, 0.2, -0.8]
];
rockPositions.forEach(([x, y, z], index) => {
const rock = addMesh(
rockGeometry,
index % 2 ? materials.stone : materials.stoneDark,
new THREE.Vector3(x, y, z)
);
rock.scale.set(1.2, 0.7 + index * 0.05, 0.85);
rock.rotation.set(index * 0.4, index * 0.9, index * 0.2);
});
// -------------------------------------------------------------------------
// Cloud disk
// -------------------------------------------------------------------------
const cloud = new THREE.Group();
cloud.position.set(0.55, 6.25, -0.25);
scene.add(cloud);
function addCloudPuff(x, y, z, sx, sy, sz, material) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
material
);
puff.position.set(x, y, z);
puff.scale.set(sx, sy, sz);
puff.castShadow = true;
puff.receiveShadow = true;
cloud.add(puff);
return puff;
}
addCloudPuff(-1.0, -0.05, 0, 1.05, 0.57, 0.72, materials.cloudShade);
addCloudPuff(-0.35, 0.25, 0, 1.18, 0.78, 0.83, materials.cloud);
addCloudPuff(0.55, 0.13, 0, 1.15, 0.68, 0.78, materials.cloud);
addCloudPuff(1.25, -0.09, 0, 0.82, 0.46, 0.61, materials.cloudShade);
const cloudDisk = new THREE.Mesh(
new THREE.CylinderGeometry(1.72, 1.55, 0.22, 12),
materials.cloudShade
);
cloudDisk.position.y = -0.4;
cloudDisk.scale.z = 0.72;
cloudDisk.castShadow = true;
cloud.add(cloudDisk);
// -------------------------------------------------------------------------
// Buried storage chamber, shown as an open-front cutaway
// -------------------------------------------------------------------------
const chamberX = 2.25;
const chamberZ = 1.18;
addMesh(
new THREE.BoxGeometry(4.25, 0.22, 2.05),
materials.stoneDark,
new THREE.Vector3(chamberX, -2.67, chamberZ)
);
addMesh(
new THREE.BoxGeometry(4.25, 1.72, 0.2),
materials.stone,
new THREE.Vector3(chamberX, -1.69, 0.19)
);
addMesh(
new THREE.BoxGeometry(0.22, 1.72, 2.05),
materials.stone,
new THREE.Vector3(chamberX - 2.02, -1.69, chamberZ)
);
addMesh(
new THREE.BoxGeometry(0.22, 1.72, 2.05),
materials.stone,
new THREE.Vector3(chamberX + 2.02, -1.69, chamberZ)
);
addMesh(
new THREE.BoxGeometry(4.4, 0.24, 2.12),
materials.stoneDark,
new THREE.Vector3(chamberX, -0.73, chamberZ)
);
const chamberPool = addMesh(
new THREE.BoxGeometry(3.72, 0.16, 1.67),
materials.chamberWater,
new THREE.Vector3(chamberX, -2.48, chamberZ),
false
);
// A few underground stones establish that the pool is below ground.
[
[0.15, -2.44, 1.75],
[4.45, -2.42, 1.7],
[1.05, -1.12, 0.42],
[3.7, -1.05, 0.4]
].forEach(([x, y, z], index) => {
const rock = addMesh(
new THREE.DodecahedronGeometry(0.15 + (index % 2) * 0.05, 0),
materials.stoneDark,
new THREE.Vector3(x, y, z)
);
rock.scale.set(1.2, 0.75, 1);
rock.rotation.set(index, index * 0.7, index * 0.3);
});
// -------------------------------------------------------------------------
// Flow arrows
//
// Every arrow begins at its source reservoir and its arrowhead tip ends
// at the named destination reservoir.
// -------------------------------------------------------------------------
const arrowSystems = [];
function createFlowArrow({
name,
color,
points,
radius = 0.055,
labelT = 0.5
}) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => p.clone()),
false,
"catmullrom",
0.5
);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 72, radius, 6, false),
material
);
tube.renderOrder = 20;
scene.add(tube);
const end = curve.getPoint(1);
const tangent = curve.getTangent(1).normalize();
const headHeight = 0.42;
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.18, headHeight, 6),
material
);
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
// The cone tip is exactly on the destination reservoir.
head.position.copy(end).addScaledVector(tangent, -headHeight / 2);
head.renderOrder = 21;
scene.add(head);
const particles = [];
const particleGeometry = new THREE.SphereGeometry(0.075, 6, 4);
const particleMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
depthTest: false,
depthWrite: false
});
for (let i = 0; i < 3; i++) {
const particle = new THREE.Mesh(
particleGeometry,
particleMaterial
);
particle.renderOrder = 22;
scene.add(particle);
particles.push(particle);
}
const system = {
name,
color,
curve,
particles,
labelAnchor: curve.getPoint(labelT)
};
arrowSystems.push(system);
return system;
}
// Basin lake → Cloud disk
const evaporation = createFlowArrow({
name: "Evaporation",
color: 0x43e2c0,
points: [
new THREE.Vector3(2.25, 0.18, 0.28),
new THREE.Vector3(2.05, 1.85, 0.56),
new THREE.Vector3(1.36, 4.18, 0.52),
new THREE.Vector3(0.55, 5.72, -0.12)
],
labelT: 0.56
});
// Cloud disk → Mountain snowpack
const precipitation = createFlowArrow({
name: "Precipitation",
color: 0x55aaff,
points: [
new THREE.Vector3(0.38, 5.72, 0.42),
new THREE.Vector3(-0.08, 5.05, 0.76),
new THREE.Vector3(-1.35, 4.18, 0.76),
new THREE.Vector3(-3.05, 3.43, 0.17)
],
labelT: 0.53
});
// Mountain snowpack → Basin lake
const runoff = createFlowArrow({
name: "Runoff",
color: 0xff9d4d,
points: [
new THREE.Vector3(-3.0, 3.26, 0.16),
new THREE.Vector3(-2.25, 2.42, 0.73),
new THREE.Vector3(-1.55, 1.32, 0.86),
new THREE.Vector3(0.35, 0.46, 0.72),
new THREE.Vector3(1.05, 0.17, 0.47)
],
radius: 0.06,
labelT: 0.53
});
// Basin lake → Buried storage chamber
const infiltration = createFlowArrow({
name: "Infiltration",
color: 0xb681ff,
points: [
new THREE.Vector3(3.45, 0.18, 0.44),
new THREE.Vector3(3.74, -0.32, 0.76),
new THREE.Vector3(3.67, -1.25, 1.12),
new THREE.Vector3(3.05, -2.39, 1.2)
],
radius: 0.06,
labelT: 0.51
});
// -------------------------------------------------------------------------
// Labels
// -------------------------------------------------------------------------
const worldLabels = [
{
element: document.getElementById("cloudLabel"),
position: new THREE.Vector3(0.55, 7.24, -0.25)
},
{
element: document.getElementById("mountainLabel"),
position: new THREE.Vector3(-3.42, 4.58, -0.25)
},
{
element: document.getElementById("basinLabel"),
position: new THREE.Vector3(2.28, 0.84, 0.1)
},
{
element: document.getElementById("chamberLabel"),
position: new THREE.Vector3(2.25, -1.12, 2.18)
}
];
const flowLabelElements = {
Evaporation: document.getElementById("evaporationLabel"),
Precipitation: document.getElementById("precipitationLabel"),
Runoff: document.getElementById("runoffLabel"),
Infiltration: document.getElementById("infiltrationLabel")
};
const projected = new THREE.Vector3();
function updateLabel(element, position) {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, keyboard, and touch
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 1.55, 0),
radius: 17.2,
theta: 0.62,
phi: 1.12
};
const defaultOrbit = {
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x +
orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z +
orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function resetCamera() {
orbit.radius = defaultOrbit.radius;
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.005,
0.46,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
10.5,
27
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetCamera").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") orbit.theta -= 0.08;
else if (key === "ArrowRight") orbit.theta += 0.08;
else if (key === "ArrowUp") orbit.phi -= 0.06;
else if (key === "ArrowDown") orbit.phi += 0.06;
else if (key === "+" || key === "=") orbit.radius -= 0.6;
else if (key === "-" || key === "_") orbit.radius += 0.6;
else return;
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.46, 1.43);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 10.5, 27);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Moving bright beads make each directional arrow easy to follow.
arrowSystems.forEach((system, systemIndex) => {
system.particles.forEach((particle, particleIndex) => {
const t =
(elapsed * (0.18 + systemIndex * 0.012) +
particleIndex / system.particles.length) %
1;
particle.position.copy(system.curve.getPointAt(t));
});
});
const waterPulse = 0.48 + Math.sin(elapsed * 1.4) * 0.09;
materials.water.emissiveIntensity = waterPulse;
materials.chamberWater.emissiveIntensity = 0.66 + Math.sin(elapsed * 1.2) * 0.09;
// A very small lake scale pulse keeps the surface alive without moving
// the exact source or destination points of the arrows.
const lakeScale = 1 + Math.sin(elapsed * 1.1) * 0.006;
lake.scale.set(lakeScale, 1, lakeScale);
worldLabels.forEach((label) => {
updateLabel(label.element, label.position);
});
arrowSystems.forEach((system) => {
updateLabel(flowLabelElements[system.name], system.labelAnchor);
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
animate();
</script>
</body>
</html>
```