Prompt specification
Build or customize the Three.js 3D scene "Flamingo bill filtering 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: Flamingo bill filtering section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/flamingo-bill-filtering-section-x0681
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: flamingo bill filtering section. Show a stylized curved flamingo bill beside an enlarged schematic filter structure; distinguish water flow, retained food particles, and expelled particles through separate labeled paths. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (flamingo-bill-filtering-section-x0681):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Flamingo Bill Filter</title>
<style>
:root {
--ink: #eaf8ff;
--muted: #91a9b6;
--panel: rgba(7, 18, 27, 0.82);
--border: rgba(151, 211, 232, 0.18);
--water: #29d9ff;
--retained: #ffb13b;
--expelled: #ff4fa3;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 32%, #183442 0%, #0b1b25 45%, #050c12 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-card {
position: absolute;
top: 22px;
left: 24px;
width: min(430px, calc(100vw - 48px));
padding: 17px 19px 16px;
border: 1px solid var(--border);
border-radius: 16px;
background: linear-gradient(135deg, rgba(13, 34, 45, 0.92), rgba(6, 17, 25, 0.78));
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: #ff9aab;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 3px;
border-radius: 4px;
background: #ff718a;
box-shadow: 0 0 14px rgba(255, 113, 138, 0.6);
}
h1 {
margin: 8px 0 4px;
font-size: clamp(22px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
position: absolute;
top: 22px;
right: 24px;
width: 255px;
padding: 13px 14px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
}
.legend-title {
margin-bottom: 9px;
color: #7893a1;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr;
gap: 9px;
align-items: start;
margin: 8px 0;
font-size: 11px;
line-height: 1.35;
}
.swatch {
width: 9px;
height: 9px;
margin-top: 3px;
border-radius: 2px;
box-shadow: 0 0 12px currentColor;
}
.legend-row strong {
display: block;
color: #eaf8ff;
font-size: 10px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend-row span {
color: #8fa7b4;
}
.controls {
position: absolute;
left: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(151, 211, 232, 0.24);
border-radius: 10px;
padding: 9px 12px;
background: rgba(7, 19, 28, 0.84);
color: #dff7ff;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(22, 48, 62, 0.92);
border-color: rgba(151, 211, 232, 0.48);
transform: translateY(-1px);
}
.hint {
position: absolute;
right: 24px;
bottom: 24px;
color: rgba(205, 231, 241, 0.58);
font-size: 10px;
letter-spacing: 0.05em;
text-align: right;
}
.status {
position: absolute;
left: 24px;
bottom: 76px;
display: flex;
align-items: center;
gap: 7px;
color: rgba(205, 231, 241, 0.62);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #66ffc1;
box-shadow: 0 0 10px #66ffc1;
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% { opacity: 0.45; transform: scale(0.75); }
}
@media (max-width: 760px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
h1 { font-size: 23px; }
.subtitle { font-size: 10px; }
.legend {
top: auto;
right: 12px;
bottom: 63px;
width: 205px;
padding: 10px 11px;
}
.legend-title { display: none; }
.legend-row { margin: 6px 0; }
.legend-row span { display: none; }
.controls {
left: 12px;
bottom: 12px;
}
.hint { display: none; }
.status { left: 12px; bottom: 58px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Voxel anatomy / feeding</div>
<h1>Flamingo Bill Filter</h1>
<p class="subtitle">
A stylized curved mandible paired with an enlarged lamellar filter.
Follow the three color-coded particle routes.
</p>
</section>
<aside class="legend">
<div class="legend-title">Particle pathways</div>
<div class="legend-row">
<i class="swatch" style="color:var(--water);background:var(--water)"></i>
<div><strong>Water flow</strong><span>Passes between the lamellae.</span></div>
</div>
<div class="legend-row">
<i class="swatch" style="color:var(--retained);background:var(--retained)"></i>
<div><strong>Retained food</strong><span>Larger material is held upstream.</span></div>
</div>
<div class="legend-row">
<i class="swatch" style="color:var(--expelled);background:var(--expelled)"></i>
<div><strong>Expelled particles</strong><span>Fine material passes through.</span></div>
</div>
</aside>
<div class="status"><span class="status-dot"></span><span id="statusText">Flow simulation active</span></div>
<div class="controls">
<button id="resetButton" type="button">Reset view</button>
<button id="pauseButton" type="button">Pause flow</button>
</div>
<div class="hint">Drag to orbit · Wheel to zoom · Shift-drag to pan</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.getElementById("scene");
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07131c, 0.022);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
mount.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const ambient = new THREE.HemisphereLight(0xc9efff, 0x1d2732, 2.15);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff2e7, 3.4);
keyLight.position.set(4, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4bcfff, 1.4);
rimLight.position.set(-8, 5, -7);
scene.add(rimLight);
const pinkLight = new THREE.PointLight(0xff6e91, 8, 12, 2);
pinkLight.position.set(-4, 4, 3);
scene.add(pinkLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
class VoxelBatch {
constructor() {
this.groups = new Map();
}
box(x, y, z, sx, sy, sz, color) {
if (!this.groups.has(color)) this.groups.set(color, []);
dummy.position.set(x, y, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(sx, sy, sz);
dummy.updateMatrix();
this.groups.get(color).push(dummy.matrix.clone());
}
build() {
for (const [color, matrices] of this.groups) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02
});
const mesh = new THREE.InstancedMesh(unitBox, material, matrices.length);
matrices.forEach((matrix, index) => mesh.setMatrixAt(index, matrix));
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
}
}
// Ground: a voxel-tiled laboratory plinth.
const ground = new VoxelBatch();
for (let x = -12; x <= 12; x++) {
for (let z = -8; z <= 8; z++) {
if (Math.abs(x + 1) < 2 && Math.abs(z) < 2) continue;
const alternate = (x + z) % 2 === 0;
ground.box(
x * 0.72,
-0.18,
z * 0.72,
0.67,
0.20,
0.67,
alternate ? 0x102631 : 0x0d202a
);
}
}
ground.build();
// Shared materials for the enlarged filter and collection pocket.
const filterBatch = new VoxelBatch();
const lamellaColor = 0xff7b78;
const lamellaDark = 0xd95667;
const frameColor = 0xb8d7dc;
const pocketColor = 0xe89944;
// Enlarged lamellar wall. Vertical voxel columns form parallel gaps.
const barPositions = [-1.4, -1.0, -0.6, -0.2, 0.2, 0.6, 1.0, 1.4];
for (const z of barPositions) {
for (let y = 0.96; y <= 3.76; y += 0.19) {
filterBatch.box(
2.0,
y,
z,
0.19,
0.185,
0.19,
Math.round(y * 10) % 2 === 0 ? lamellaColor : lamellaDark
);
}
}
// Top and bottom rails.
for (let z = -1.6; z <= 1.6; z += 0.19) {
filterBatch.box(2.0, 3.86, z, 0.24, 0.18, 0.185, lamellaColor);
filterBatch.box(2.0, 0.78, z, 0.24, 0.18, 0.185, lamellaDark);
}
// Pale corner frame indicates the magnified region.
for (const z of [-1.78, 1.78]) {
for (let y = 0.66; y <= 4.12; y += 0.19) {
filterBatch.box(2.12, y, z, 0.075, 0.15, 0.075, frameColor);
}
}
for (const y of [0.66, 4.12]) {
for (let z = -1.78; z <= 1.78; z += 0.19) {
filterBatch.box(2.12, y, z, 0.075, 0.075, 0.15, frameColor);
}
}
// Upstream food-retention pocket.
for (let z = -1.05; z <= -0.15; z += 0.18) {
filterBatch.box(1.48, 0.43, z, 0.66, 0.18, 0.175, pocketColor);
}
for (let x = 1.18; x <= 1.78; x += 0.18) {
filterBatch.box(x, 0.63, -1.04, 0.175, 0.35, 0.16, pocketColor);
filterBatch.box(x, 0.63, -0.16, 0.175, 0.35, 0.16, pocketColor);
}
// Small downstream collection marker for expelled fine particles.
for (let z = 0.08; z <= 0.72; z += 0.18) {
filterBatch.box(4.63, 0.28, z, 0.50, 0.15, 0.175, 0xb74d83);
}
filterBatch.build();
// Stylized voxel flamingo head and curved, downturned bill.
const anatomy = new VoxelBatch();
const headPink = 0xff8e9f;
const headLight = 0xffa3aa;
const billTop = 0xf46f87;
const billBottom = 0xffa0a8;
const billTip = 0xd95170;
// Partial head and neck.
anatomy.box(-5.34, 3.63, 0, 0.92, 0.76, 0.88, headPink);
anatomy.box(-5.12, 4.01, 0.02, 0.68, 0.38, 0.72, headLight);
anatomy.box(-5.72, 3.59, 0, 0.42, 0.58, 0.67, headPink);
anatomy.box(-6.05, 3.57, 0, 0.40, 0.46, 0.57, headPink);
// Eye: blocky white surround and black pupil.
anatomy.box(-5.23, 3.91, 0.48, 0.25, 0.25, 0.13, 0xf6f3dd);
anatomy.box(-5.23, 3.91, 0.56, 0.11, 0.12, 0.08, 0x18212a);
const billCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-4.86, 3.43, 0),
new THREE.Vector3(-4.08, 3.43, 0),
new THREE.Vector3(-3.30, 3.23, 0),
new THREE.Vector3(-2.62, 2.83, 0),
new THREE.Vector3(-2.18, 2.18, 0),
new THREE.Vector3(-2.18, 1.54, 0),
new THREE.Vector3(-2.47, 1.12, 0)
],
false,
"catmullrom",
0.35
);
const billSamples = 42;
for (let i = 0; i < billSamples; i++) {
const t = i / (billSamples - 1);
const p = billCurve.getPointAt(t);
const width = 1.38 * (1 - t) + 0.28;
const columns = Math.max(1, Math.round(width / 0.185));
for (let j = 0; j < columns; j++) {
const z = (j - (columns - 1) / 2) * 0.185;
const upperColor = t > 0.84 ? billTip : billTop;
anatomy.box(
p.x,
p.y + 0.015,
z,
0.185,
0.19,
0.185,
upperColor
);
if (t < 0.88) {
anatomy.box(
p.x,
p.y - 0.245,
z,
0.185,
0.18,
0.185,
t > 0.67 ? billTip : billBottom
);
}
}
}
// Tiny dark nostril voxel.
anatomy.box(-4.42, 3.58, 0.24, 0.17, 0.07, 0.15, 0x8e405a);
anatomy.build();
// Canvas-generated 3D labels.
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeLabel(title, subtitle, colorHex, position, width = 3.25) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(0,0,0,0.45)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 8;
roundedRect(ctx, 8, 8, 752, 176, 25);
ctx.fillStyle = "rgba(6, 17, 26, 0.90)";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.strokeStyle = colorHex;
ctx.lineWidth = 4;
roundedRect(ctx, 8, 8, 752, 176, 25);
ctx.stroke();
ctx.fillStyle = colorHex;
roundedRect(ctx, 27, 28, 8, 136, 4);
ctx.fill();
ctx.fillStyle = "#f1fbff";
ctx.font = "800 42px Arial, sans-serif";
ctx.textBaseline = "top";
ctx.fillText(title, 57, 38);
ctx.fillStyle = "#9eb6c2";
ctx.font = "500 27px Arial, sans-serif";
ctx.fillText(subtitle, 58, 101);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
makeLabel(
"CURVED FLAMINGO BILL",
"stylized voxel anatomy",
"#ff8fa1",
new THREE.Vector3(-3.63, 4.75, 0),
3.7
);
makeLabel(
"ENLARGED FILTER",
"parallel lamellae + open channels",
"#b8d7dc",
new THREE.Vector3(2.0, 4.78, 0),
4.0
);
// Three distinct, independently animated paths.
class ParticlePath {
constructor(points, color, particleCount, particleSize, speed) {
this.curve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.28);
this.color = color;
this.particleCount = particleCount;
this.particleSize = particleSize;
this.speed = speed;
const dotGeometry = new THREE.BoxGeometry(1, 1, 1);
const dotMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.42,
depthWrite: false
});
const dotCount = 64;
this.dots = new THREE.InstancedMesh(dotGeometry, dotMaterial, dotCount);
this.dots.frustumCulled = false;
for (let i = 0; i < dotCount; i++) {
const point = this.curve.getPointAt(i / (dotCount - 1));
dummy.position.copy(point);
dummy.rotation.set(0, 0, 0);
dummy.scale.setScalar(0.055);
dummy.updateMatrix();
this.dots.setMatrixAt(i, dummy.matrix);
}
this.dots.instanceMatrix.needsUpdate = true;
scene.add(this.dots);
const particleGeometry = new THREE.BoxGeometry(1, 1, 1);
const particleMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.85,
roughness: 0.28,
metalness: 0.02
});
this.particles = new THREE.InstancedMesh(
particleGeometry,
particleMaterial,
particleCount
);
this.particles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
this.particles.castShadow = true;
this.particles.frustumCulled = false;
scene.add(this.particles);
this.buildArrowHead();
}
buildArrowHead() {
const endpoint = this.curve.getPointAt(1);
const tangent = this.curve.getTangentAt(1).normalize();
const right = new THREE.Vector3().crossVectors(tangent, new THREE.Vector3(0, 1, 0)).normalize();
const back = tangent.clone().multiplyScalar(-0.16);
const positions = [
endpoint.clone(),
endpoint.clone().add(back).addScaledVector(right, 0.09),
endpoint.clone().add(back).addScaledVector(right, -0.09)
];
const material = new THREE.MeshBasicMaterial({ color: this.color });
for (const position of positions) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.copy(position);
mesh.scale.setScalar(0.105);
scene.add(mesh);
}
}
update(time) {
for (let i = 0; i < this.particleCount; i++) {
const phase = (time * this.speed + i / this.particleCount) % 1;
const point = this.curve.getPointAt(phase);
const pulse = 1 + Math.sin(time * 5 + i * 1.7) * 0.10;
dummy.position.copy(point);
dummy.rotation.set(0, time * 0.8 + i, 0);
dummy.scale.setScalar(this.particleSize * pulse);
dummy.updateMatrix();
this.particles.setMatrixAt(i, dummy.matrix);
}
this.particles.instanceMatrix.needsUpdate = true;
}
}
const waterPath = new ParticlePath(
[
new THREE.Vector3(-0.10, 3.16, 0.00),
new THREE.Vector3(0.78, 3.16, 0.00),
new THREE.Vector3(1.65, 3.16, 0.00),
new THREE.Vector3(2.34, 3.16, 0.00),
new THREE.Vector3(3.42, 3.12, 0.00),
new THREE.Vector3(4.42, 2.90, 0.00),
new THREE.Vector3(5.02, 2.55, 0.00)
],
0x29d9ff,
20,
0.085,
0.22
);
const retainedPath = new ParticlePath(
[
new THREE.Vector3(-0.08, 2.15, -0.60),
new THREE.Vector3(0.72, 2.15, -0.60),
new THREE.Vector3(1.47, 2.15, -0.60),
new THREE.Vector3(1.82, 1.96, -0.60),
new THREE.Vector3(1.83, 1.10, -0.60),
new THREE.Vector3(1.70, 0.69, -0.60),
new THREE.Vector3(1.46, 0.60, -0.60)
],
0xffb13b,
8,
0.135,
0.17
);
const expelledPath = new ParticlePath(
[
new THREE.Vector3(-0.08, 2.55, 0.40),
new THREE.Vector3(0.82, 2.55, 0.40),
new THREE.Vector3(1.62, 2.55, 0.40),
new THREE.Vector3(2.42, 2.53, 0.40),
new THREE.Vector3(3.30, 2.38, 0.40),
new THREE.Vector3(4.02, 1.82, 0.40),
new THREE.Vector3(4.48, 0.82, 0.40),
new THREE.Vector3(4.62, 0.40, 0.40)
],
0xff4fa3,
13,
0.065,
0.205
);
makeLabel(
"WATER FLOW",
"passes between lamellae",
"#29d9ff",
new THREE.Vector3(3.47, 3.73, 0.04),
3.25
);
makeLabel(
"RETAINED FOOD",
"held in upstream pocket",
"#ffb13b",
new THREE.Vector3(0.18, 1.05, -0.88),
3.35
);
makeLabel(
"EXPELLED PARTICLES",
"fine material passes through",
"#ff4fa3",
new THREE.Vector3(4.40, 1.28, 0.86),
3.55
);
// Minimal camera controller implemented directly, without addons.
const controls = {
target: new THREE.Vector3(-0.15, 2.15, 0),
theta: 0.52,
phi: 1.12,
radius: 12.7,
dragging: false,
panning: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const portraitScale = camera.aspect < 0.9 ? 1.62 : camera.aspect < 1.25 ? 1.25 : 1;
const radius = controls.radius * portraitScale;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + radius * sinPhi * Math.sin(controls.theta),
controls.target.y + radius * Math.cos(controls.phi),
controls.target.z + radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.set(-0.15, 2.15, 0);
controls.theta = 0.52;
controls.phi = 1.12;
controls.radius = 12.7;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.panning = event.button === 2 || event.shiftKey;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (controls.panning) {
const direction = camera.getWorldDirection(new THREE.Vector3());
const right = new THREE.Vector3()
.crossVectors(camera.up, direction)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, direction)
.normalize();
const panScale = controls.radius * 0.0013;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(up, dy * panScale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -7, 7);
controls.target.y = THREE.MathUtils.clamp(controls.target.y, 0, 6);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -5, 5);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.48, 1.48);
}
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
controls.panning = 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("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
7.0,
18.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
let paused = false;
const pauseButton = document.getElementById("pauseButton");
const statusText = document.getElementById("statusText");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume flow" : "Pause flow";
statusText.textContent = paused ? "Flow simulation paused" : "Flow simulation active";
});
document.getElementById("resetButton").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(7, controls.radius - 0.7);
updateCamera();
}
if (event.key === "-" || event.key === "_") {
controls.radius = Math.min(18.5, controls.radius + 0.7);
updateCamera();
}
if (event.key.toLowerCase() === "r") resetCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
}
window.addEventListener("resize", resize);
updateCamera();
const clock = new THREE.Clock();
let elapsed = 0;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta;
waterPath.update(elapsed);
retainedPath.update(elapsed);
expelledPath.update(elapsed);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```