Prompt specification
Build or customize the Three.js 3D scene "Constant-head supply feeding a timing bowl" 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: Constant-head supply feeding a timing bowl
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/constant-head-supply-feeding-a-timing-bowl-x2554
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring water clocks and flow-based timekeeping. Create a historically informed timing arrangement with supply reservoir and receiving bowl. Animate a simplified steady inflow and align the visible scale with the stated model. Low-poly.
Working Three.js Starter (constant-head-supply-feeding-a-timing-bowl-x2554):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Constant-Flow Clepsydra</title>
<style>
:root {
--ink: #302820;
--muted: #756b5c;
--paper: rgba(244, 237, 218, 0.91);
--line: rgba(79, 61, 36, 0.23);
--gold: #b98531;
--blue: #247f89;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8cbb4;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid var(--line);
border-radius: 5px;
box-shadow: 0 12px 35px rgba(55, 42, 25, 0.16);
backdrop-filter: blur(8px);
}
.brand {
position: absolute;
top: 24px;
left: 28px;
max-width: 520px;
text-shadow: 0 1px rgba(255,255,255,.45);
}
.eyebrow {
margin-bottom: 7px;
color: var(--blue);
font: 700 11px/1.2 Arial, sans-serif;
letter-spacing: .22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 46px);
font-weight: 500;
letter-spacing: .035em;
line-height: 1;
}
.subtitle {
margin-top: 9px;
max-width: 460px;
color: #554c40;
font: 14px/1.45 Arial, sans-serif;
}
#model-card {
position: absolute;
left: 28px;
bottom: 27px;
width: 330px;
padding: 17px 18px 16px;
}
#model-card h2,
#controls h2 {
margin: 0 0 11px;
font-size: 12px;
font-family: Arial, sans-serif;
letter-spacing: .18em;
text-transform: uppercase;
}
.equation {
padding: 10px 11px;
border-left: 3px solid var(--gold);
background: rgba(185, 133, 49, .08);
font: 15px/1.5 "Courier New", monospace;
}
.constants {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 12px 0;
font: 12px/1.35 Arial, sans-serif;
}
.constant {
padding: 8px;
border: 1px solid var(--line);
border-radius: 3px;
}
.constant span {
display: block;
color: var(--muted);
font-size: 10px;
letter-spacing: .08em;
text-transform: uppercase;
}
.readouts {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
}
.readout {
flex: 1;
padding-top: 9px;
border-top: 1px solid var(--line);
}
.readout small {
display: block;
color: var(--muted);
font: 10px Arial, sans-serif;
letter-spacing: .1em;
text-transform: uppercase;
}
.readout strong {
display: block;
margin-top: 3px;
font: 600 18px Arial, sans-serif;
}
.meter {
height: 4px;
margin-top: 12px;
overflow: hidden;
background: rgba(57, 45, 30, .12);
border-radius: 10px;
}
#meter-fill {
width: 0;
height: 100%;
background: var(--blue);
}
.note {
margin: 11px 0 0;
color: var(--muted);
font: 11px/1.45 Arial, sans-serif;
}
#controls {
position: absolute;
right: 28px;
bottom: 27px;
width: 292px;
padding: 16px 17px;
}
.button-row {
display: flex;
gap: 8px;
margin-bottom: 12px;
}
button, select {
min-height: 34px;
border: 1px solid rgba(74, 57, 35, .27);
border-radius: 3px;
background: rgba(255, 252, 241, .76);
color: var(--ink);
font: 600 11px Arial, sans-serif;
cursor: pointer;
}
button {
flex: 1;
padding: 0 10px;
}
button:hover, select:hover {
background: #fffaf0;
border-color: var(--gold);
}
button.primary {
background: var(--blue);
border-color: var(--blue);
color: white;
}
button.primary:hover {
background: #1c6972;
}
.range-label {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: var(--muted);
font: 10px Arial, sans-serif;
letter-spacing: .08em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
margin: 0 0 13px;
accent-color: var(--blue);
cursor: pointer;
}
.select-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
color: var(--muted);
font: 11px Arial, sans-serif;
}
select {
padding: 0 8px;
}
.hint {
position: absolute;
right: 29px;
top: 25px;
padding: 8px 11px;
border-radius: 3px;
background: rgba(244, 237, 218, .72);
color: #665d50;
font: 11px Arial, sans-serif;
letter-spacing: .03em;
}
#error {
position: fixed;
inset: 0;
display: none;
place-items: center;
padding: 30px;
background: #e6dcc7;
text-align: center;
font: 16px/1.5 Arial, sans-serif;
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 17px;
right: 17px;
}
.subtitle { display: none; }
.hint { display: none; }
#model-card {
left: 12px;
bottom: 12px;
width: min(310px, calc(100vw - 24px));
padding: 13px;
}
#controls {
top: 92px;
right: 12px;
bottom: auto;
width: 178px;
padding: 12px;
}
#controls h2 { display: none; }
.button-row { flex-wrap: wrap; }
.button-row button { min-width: 76px; }
.constants { gap: 5px; }
.constant { padding: 6px; }
.note { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="brand">
<div class="eyebrow">Flow-based timekeeping</div>
<h1>The Constant-Flow Clepsydra</h1>
<div class="subtitle">
An interpretive reconstruction of an inflow water clock: a constant-head
reservoir feeds a calibrated receiving bowl.
</div>
</header>
<section id="model-card" class="panel">
<h2>Visible scale model</h2>
<div class="equation">h(t) = Q·t / A</div>
<div class="constants">
<div class="constant">
<span>Flow rate</span>
Q = 1.0 L/min
</div>
<div class="constant">
<span>Bowl area</span>
A = π(0.30 m)²
</div>
</div>
<div class="readouts">
<div class="readout">
<small>Elapsed model time</small>
<strong id="sim-time">0.0 min</strong>
</div>
<div class="readout">
<small>Water rise</small>
<strong id="water-level">0.0 cm</strong>
</div>
</div>
<div class="meter"><div id="meter-fill"></div></div>
<p class="note">
The ruler beside the bowl is generated from the same equation:
60 minutes corresponds to 21.22 cm. Head loss, turbulence, and clock
calibration error are intentionally omitted.
</p>
</section>
<section id="controls" class="panel">
<h2>Controls</h2>
<div class="button-row">
<button id="play" class="primary" type="button">Pause</button>
<button id="reset" type="button">Reset</button>
<button id="view" type="button">Reset View</button>
</div>
<div class="range-label">
<span>Model timeline</span>
<span>0–60 min</span>
</div>
<input id="scrub" type="range" min="0" max="60" step="0.1" value="0">
<div class="select-row">
<label for="rate">Playback rate</label>
<select id="rate">
<option value="0.25">0.25 min/s</option>
<option value="1" selected>1 min/s</option>
<option value="2">2 min/s</option>
</select>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
</div>
<div id="error">
This scene requires WebGL. Try opening it in a current desktop or mobile browser.
</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 MODEL = {
Q: 0.001, // m³ per model minute
radius: 0.30, // receiving-bowl inner radius, m
area: Math.PI * 0.30 * 0.30,
floorY: 0.29,
duration: 60
};
MODEL.slope = MODEL.Q / MODEL.area;
MODEL.maxRise = MODEL.slope * MODEL.duration;
Object.freeze(MODEL);
let modelTime = 0;
let playing = true;
let playbackRate = 1;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8cbb4);
scene.fog = new THREE.Fog(0xd8cbb4, 7, 15);
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
document.getElementById('error').style.display = 'grid';
throw error;
}
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.08;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43, window.innerWidth / window.innerHeight, 0.05, 40
);
const cameraState = {
theta: 0.59,
phi: 1.13,
radius: 4.35,
target: new THREE.Vector3(-0.05, 0.97, 0)
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * s * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff2d5, 0x756653, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedc5, 3.2);
sun.position.set(3.7, 6.2, 4.1);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -4;
sun.shadow.camera.right = 4;
sun.shadow.camera.top = 4;
sun.shadow.camera.bottom = -4;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 15;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8dbbc0, 0.75);
fill.position.set(-4, 2.5, 1);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const mat = {
ground: material(0xcbbb9f),
wall: material(0xc6b89e),
platform: material(0xa89779),
platformEdge: material(0x88775e),
stone: material(0xc3ad86),
stoneDark: material(0x9f8867),
stoneLight: material(0xd5c19b),
bronze: material(0x8c5d27, { metalness: 0.62, roughness: 0.43 }),
bronzeLight: material(0xc18a37, { metalness: 0.55, roughness: 0.4 }),
dark: material(0x3f3428),
teal: material(0x287b7b, { metalness: 0.15, roughness: 0.5 }),
water: material(0x3ca8b0, {
transparent: true,
opacity: 0.57,
depthWrite: false,
roughness: 0.22,
metalness: 0.05
}),
waterSurface: material(0x65c5c8, {
transparent: true,
opacity: 0.72,
depthWrite: false,
roughness: 0.16,
metalness: 0.05
}),
stream: material(0x74d2d2, {
transparent: true,
opacity: 0.78,
depthWrite: false,
roughness: 0.18
})
};
function mesh(geometry, m, position, parent = scene) {
const object = new THREE.Mesh(geometry, m);
if (position) object.position.set(...position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, m, x, y, z, parent = scene) {
return mesh(new THREE.BoxGeometry(w, h, d), m, [x, y, z], parent);
}
function makeLabel(text, options = {}) {
const {
width = 0.14,
height = 0.065,
color = '#352d24',
background = 'rgba(244,237,218,0.90)',
border = 'rgba(87,67,39,0.35)',
font = '600 44px Georgia'
} = options;
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 192;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = background;
ctx.strokeStyle = border;
ctx.lineWidth = 5;
const radius = 18;
ctx.beginPath();
ctx.roundRect(5, 5, canvas.width - 10, canvas.height - 10, radius);
ctx.fill();
ctx.stroke();
ctx.fillStyle = color;
ctx.font = font;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, height, 1);
return sprite;
}
// Courtyard and low, stepped display plinth.
const ground = mesh(
new THREE.PlaneGeometry(30, 30),
mat.ground,
[0, -0.01, 0]
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
box(7.5, 3.2, 0.18, mat.wall, 0, 1.55, -2.35);
for (const x of [-2.6, 0, 2.6]) {
box(0.42, 2.55, 0.25, mat.stoneDark, x, 1.23, -2.17);
box(0.75, 0.22, 0.55, mat.stoneLight, x, 2.52, -2.08);
}
box(3.05, 0.14, 1.72, mat.platformEdge, 0, 0.07, 0);
box(2.83, 0.08, 1.52, mat.platform, 0, 0.16, 0);
// Four faceted supports for the elevated supply cistern.
for (const x of [-1.03, -0.27]) {
for (const z of [-0.25, 0.25]) {
mesh(
new THREE.CylinderGeometry(0.075, 0.105, 0.68, 8),
mat.stoneDark,
[x, 0.50, z]
);
box(0.22, 0.08, 0.22, mat.stone, x, 0.84, z);
}
}
// Open-top sandstone reservoir.
const tankX = -0.65;
box(1.12, 0.10, 0.78, mat.stoneDark, tankX, 0.86, 0);
box(1.10, 0.72, 0.10, mat.stone, tankX, 1.22, 0.34);
box(1.10, 0.72, 0.10, mat.stone, tankX, 1.22, -0.34);
box(0.10, 0.72, 0.60, mat.stone, -1.15, 1.22, 0);
box(0.10, 0.72, 0.60, mat.stone, -0.15, 1.22, 0);
// Projecting upper lip.
box(1.20, 0.08, 0.13, mat.stoneLight, tankX, 1.60, 0.34);
box(1.20, 0.08, 0.13, mat.stoneLight, tankX, 1.60, -0.34);
box(0.13, 0.08, 0.80, mat.stoneLight, -1.16, 1.60, 0);
box(0.13, 0.08, 0.80, mat.stoneLight, -0.14, 1.60, 0);
// Constant-head reservoir water surface.
const cisternWater = mesh(
new THREE.PlaneGeometry(0.97, 0.57),
mat.waterSurface,
[tankX, 1.43, 0]
);
cisternWater.rotation.x = -Math.PI / 2;
cisternWater.castShadow = false;
// Decorative band and simple ancient-inspired motifs.
box(0.92, 0.075, 0.025, mat.bronze, tankX, 1.02, 0.398);
for (let i = 0; i < 7; i++) {
const ornament = mesh(
new THREE.OctahedronGeometry(0.027, 0),
mat.bronzeLight,
[-1.00 + i * 0.117, 1.02, 0.418]
);
ornament.rotation.z = Math.PI / 4;
ornament.scale.y = 1.25;
}
const cisternLabel = makeLabel('CONSTANT-HEAD CISTERN', {
width: 0.57,
height: 0.095,
font: '600 34px Georgia'
});
cisternLabel.position.set(tankX, 1.29, 0.414);
scene.add(cisternLabel);
// Bronze outlet and curved spout.
const spoutCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.04, 1.18, 0.05),
new THREE.Vector3(0.08, 1.17, 0.05),
new THREE.Vector3(0.19, 1.01, 0.05),
new THREE.Vector3(0.29, 0.89, 0.05),
new THREE.Vector3(0.34, 0.83, 0.05)
]);
mesh(
new THREE.TubeGeometry(spoutCurve, 18, 0.039, 6, false),
mat.bronze
);
mesh(
new THREE.CylinderGeometry(0.052, 0.043, 0.10, 8),
mat.bronzeLight,
[0.34, 0.795, 0.05]
);
// Receiving bowl pedestal and bowl.
mesh(
new THREE.CylinderGeometry(0.43, 0.49, 0.13, 12),
mat.stoneDark,
[0.50, 0.235, 0]
);
mesh(
new THREE.CylinderGeometry(0.39, 0.43, 0.06, 12),
mat.stoneLight,
[0.50, 0.305, 0]
);
const bowl = mesh(
new THREE.CylinderGeometry(0.36, 0.31, 0.28, 12, 1, true),
material(0xb69668, { side: THREE.DoubleSide }),
[0.50, 0.41, 0]
);
const bowlFloor = mesh(
new THREE.CylinderGeometry(0.305, 0.305, 0.04, 12),
mat.stoneDark,
[0.50, 0.27, 0]
);
const rim = mesh(
new THREE.TorusGeometry(0.35, 0.024, 4, 12),
mat.bronzeLight,
[0.50, 0.55, 0]
);
rim.rotation.x = Math.PI / 2;
const lowerBand = mesh(
new THREE.TorusGeometry(0.337, 0.012, 4, 12),
mat.teal,
[0.50, 0.355, 0]
);
lowerBand.rotation.x = Math.PI / 2;
// Water body in the cylindrical receiver.
const waterBody = mesh(
new THREE.CylinderGeometry(0.294, 0.294, 1, 16),
mat.water,
[0.50, MODEL.floorY, 0]
);
waterBody.scale.y = 0.0001;
waterBody.castShadow = false;
waterBody.renderOrder = 2;
const waterSurface = mesh(
new THREE.CircleGeometry(0.294, 16),
mat.waterSurface,
[0.50, MODEL.floorY + 0.001, 0]
);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.castShadow = false;
waterSurface.renderOrder = 3;
// Visible calibrated minute scale. Every tick uses MODEL.slope.
const scaleCenterY = MODEL.floorY + MODEL.maxRise / 2;
box(
0.35,
MODEL.maxRise + 0.09,
0.025,
mat.dark,
0.84,
scaleCenterY,
0.365
);
box(
0.37,
0.025,
0.035,
mat.bronze,
0.84,
MODEL.floorY - 0.045,
0.365
);
const tickGeometry = new THREE.BoxGeometry(1, 0.004, 0.007);
for (let minute = 0; minute <= MODEL.duration; minute++) {
const y = MODEL.floorY + MODEL.slope * minute;
const isMajor = minute % 10 === 0;
const isMedium = minute % 5 === 0;
const length = isMajor ? 0.125 : isMedium ? 0.090 : 0.052;
const tick = mesh(
tickGeometry,
isMajor ? mat.bronzeLight : mat.stoneLight,
[0.86 - length / 2, y, 0.386]
);
tick.scale.x = length;
tick.castShadow = false;
if (isMajor) {
const label = makeLabel(String(minute), {
width: 0.095,
height: 0.045,
background: 'rgba(63,52,40,0.92)',
color: '#f1dfb8',
border: 'rgba(225,184,104,0.65)',
font: '600 50px Georgia'
});
label.position.set(0.965, y, 0.405);
scene.add(label);
}
}
const minutesLabel = makeLabel('MINUTES', {
width: 0.18,
height: 0.052,
font: '600 36px Georgia'
});
minutesLabel.position.set(0.84, MODEL.floorY + MODEL.maxRise + 0.064, 0.40);
scene.add(minutesLabel);
// Current-level pointer.
const pointerShape = new THREE.Shape();
pointerShape.moveTo(0, 0);
pointerShape.lineTo(-0.060, 0.027);
pointerShape.lineTo(-0.060, -0.027);
pointerShape.closePath();
const pointer = mesh(
new THREE.ShapeGeometry(pointerShape),
mat.bronzeLight,
[0.665, MODEL.floorY, 0.402]
);
pointer.castShadow = false;
// Falling stream from the nozzle to the moving water surface.
const streamStart = new THREE.Vector3(0.34, 0.745, 0.05);
const streamEnd = new THREE.Vector3(0.34, MODEL.floorY, 0.05);
const stream = mesh(
new THREE.CylinderGeometry(0.012, 0.016, 1, 6),
mat.stream
);
stream.castShadow = false;
stream.renderOrder = 4;
const droplets = [];
for (let i = 0; i < 7; i++) {
const drop = mesh(
new THREE.IcosahedronGeometry(0.014, 0),
mat.stream
);
drop.castShadow = false;
droplets.push(drop);
}
// Expanding surface rings.
const ripples = [];
for (let i = 0; i < 4; i++) {
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xc0ffff,
transparent: true,
opacity: 0.4,
side: THREE.DoubleSide,
depthWrite: false
});
const ring = mesh(
new THREE.RingGeometry(0.022, 0.027, 16),
ringMaterial
);
ring.rotation.x = -Math.PI / 2;
ring.castShadow = false;
ring.renderOrder = 5;
ripples.push(ring);
}
const modelPlate = makeLabel('INFLOW CLOCK • V = Q·t', {
width: 0.61,
height: 0.105,
font: '600 34px Georgia'
});
modelPlate.position.set(-0.55, 0.235, 0.79);
scene.add(modelPlate);
// UI references.
const playButton = document.getElementById('play');
const resetButton = document.getElementById('reset');
const viewButton = document.getElementById('view');
const scrub = document.getElementById('scrub');
const rateSelect = document.getElementById('rate');
const simTimeElement = document.getElementById('sim-time');
const waterLevelElement = document.getElementById('water-level');
const meterFill = document.getElementById('meter-fill');
function setPlaying(value) {
if (value && modelTime >= MODEL.duration) modelTime = 0;
playing = value;
playButton.textContent = playing ? 'Pause' : 'Play';
}
playButton.addEventListener('click', () => setPlaying(!playing));
resetButton.addEventListener('click', () => {
modelTime = 0;
setPlaying(true);
});
viewButton.addEventListener('click', () => {
cameraState.theta = 0.59;
cameraState.phi = 1.13;
cameraState.radius = 4.35;
cameraState.target.set(-0.05, 0.97, 0);
updateCamera();
});
scrub.addEventListener('input', () => {
modelTime = Number(scrub.value);
setPlaying(false);
});
rateSelect.addEventListener('change', () => {
playbackRate = Number(rateSelect.value);
});
// Direct orbit controls; no external examples or addons are imported.
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener('pointerdown', event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener('pointermove', event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.55,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
2.05,
7.4
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener('dblclick', () => {
cameraState.theta = 0.59;
cameraState.phi = 1.13;
cameraState.radius = 4.35;
updateCamera();
});
const clock = new THREE.Clock();
function updateScene(elapsed) {
const rise = MODEL.slope * modelTime;
const waterY = MODEL.floorY + rise;
waterBody.scale.y = Math.max(rise, 0.0001);
waterBody.position.y = MODEL.floorY + rise / 2;
waterBody.visible = rise > 0.0005;
waterSurface.position.y = waterY + 0.0015;
waterSurface.visible = rise > 0.0005;
waterSurface.material.opacity = 0.69 + Math.sin(elapsed * 2.1) * 0.035;
pointer.position.y = waterY;
streamEnd.y = waterY + 0.001;
const streamLength = Math.max(streamStart.y - streamEnd.y, 0.02);
stream.position.copy(streamStart).add(streamEnd).multiplyScalar(0.5);
stream.scale.y = streamLength;
droplets.forEach((drop, i) => {
const phase = (elapsed * 1.9 + i / droplets.length) % 1;
drop.position.set(
0.34 + Math.sin(elapsed * 9 + i * 2.4) * 0.009,
streamStart.y - phase * streamLength,
0.05 + Math.cos(elapsed * 8 + i) * 0.006
);
});
ripples.forEach((ring, i) => {
const phase = (elapsed * 0.65 + i / ripples.length) % 1;
ring.position.set(
0.34 + Math.sin(i * 2.3) * 0.035,
waterY + 0.003,
0.05 + Math.cos(i * 2.1) * 0.035
);
const size = 0.65 + phase * 5.2;
ring.scale.set(size, size, size);
ring.material.opacity = (1 - phase) * 0.42;
});
simTimeElement.textContent = `${modelTime.toFixed(1)} min`;
waterLevelElement.textContent = `${(rise * 100).toFixed(1)} cm`;
meterFill.style.width = `${(modelTime / MODEL.duration) * 100}%`;
scrub.value = modelTime.toFixed(1);
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (playing) {
modelTime = Math.min(MODEL.duration, modelTime + dt * playbackRate);
if (modelTime >= MODEL.duration) setPlaying(false);
}
updateScene(elapsed);
renderer.render(scene, camera);
}
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
</script>
</body>
</html>
```