Prompt specification
Build or customize the Three.js 3D scene "Carved channel joining a shallow pool" 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: Carved channel joining a shallow pool
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/carved-channel-joining-a-shallow-pool-x2321
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Andalusi water gardens and irrigation channels. Build a small stone water channel entering a rectangular pool. Keep the inlet slightly higher than the water surface and show a clearly connected outlet. Stylized solid forms.
Working Three.js Starter (carved-channel-joining-a-shallow-pool-x2321):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Andalusi Water Garden</title>
<style>
:root {
color-scheme: light;
font-family: Georgia, "Times New Roman", serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9dcc2;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 28px;
z-index: 2;
max-width: 360px;
padding: 15px 18px 13px;
color: #173e48;
background: rgba(255, 249, 233, 0.88);
border: 1px solid rgba(23, 62, 72, 0.2);
border-left: 5px solid #277d8c;
box-shadow: 0 8px 28px rgba(69, 48, 24, 0.14);
pointer-events: none;
backdrop-filter: blur(8px);
}
.title-card h1 {
margin: 0;
font-size: clamp(20px, 2.4vw, 31px);
font-weight: 500;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.title-card p {
margin: 6px 0 0;
color: #52686b;
font-family: system-ui, sans-serif;
font-size: 12px;
line-height: 1.45;
letter-spacing: 0.04em;
}
.controls-hint {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 2;
padding: 8px 12px;
color: rgba(38, 57, 55, 0.8);
background: rgba(255, 249, 233, 0.72);
border: 1px solid rgba(56, 77, 71, 0.15);
border-radius: 2px;
font-family: system-ui, sans-serif;
font-size: 11px;
letter-spacing: 0.03em;
pointer-events: none;
}
@media (max-width: 600px) {
.title-card {
top: 14px;
left: 14px;
right: 14px;
}
.controls-hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div class="title-card">
<h1>Jardines de Al-Ándalus</h1>
<p>A stylized water garden of stone runs, raised irrigation channels, tiled pools, and shaded arcades.</p>
</div>
<div class="controls-hint">Drag to orbit · Scroll / pinch to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.05;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9dcc2);
scene.fog = new THREE.Fog(0xe9dcc2, 25, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.0,
flatShading: true,
...options
});
const M = {
sand: material(0xd6bf91),
paleStone: material(0xe5d6b6),
warmStone: material(0xc4a978),
darkStone: material(0x9f8260),
stucco: material(0xf0e2c2),
terracotta: material(0xb85f3d),
soil: material(0x6e4b31),
trunk: material(0x73503a),
cypress: material(0x28584a),
cypressLight: material(0x3d7257),
leaf: material(0x4f7b48),
leafLight: material(0x74924e),
orange: material(0xe58a35),
cobalt: material(0x245d78),
turquoise: material(0x58a4a6),
tileLight: material(0x91c6bb),
tileDark: material(0x4f8e91),
water: material(0x39a6b3, {
roughness: 0.2,
metalness: 0.08,
transparent: true,
opacity: 0.84,
depthWrite: false
}),
waterfall: material(0x63d0d3, {
roughness: 0.15,
transparent: true,
opacity: 0.72,
depthWrite: false,
side: THREE.DoubleSide
}),
foam: material(0xd9f4e9, {
roughness: 0.4,
transparent: true,
opacity: 0.82
})
};
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff5dd, 0x80694f, 2.0));
const sun = new THREE.DirectionalLight(0xffeed0, 3.2);
sun.position.set(-8, 14, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.0004;
scene.add(sun);
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function box(width, height, depth, x, y, z, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinder(radiusTop, radiusBottom, height, x, y, z, mat, segments = 12) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Creates a rectangular beam between two points.
function beamBetween(a, b, width, height, mat) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, length),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function shiftedBeam(a, b, width, height, offsetY, mat) {
const aa = [a[0], a[1] + offsetY, a[2]];
const bb = [b[0], b[1] + offsetY, b[2]];
return beamBetween(aa, bb, width, height, mat);
}
// ------------------------------------------------------------
// Courtyard paving
// ------------------------------------------------------------
const pavingGeometry = new THREE.BoxGeometry(1.04, 0.055, 1.04);
const pavingMaterial = material(0xffffff, { roughness: 0.94 });
const paving = new THREE.InstancedMesh(
pavingGeometry,
pavingMaterial,
22 * 18
);
const dummy = new THREE.Object3D();
const pavingColor = new THREE.Color();
let pavingIndex = 0;
for (let row = 0; row < 18; row++) {
for (let col = 0; col < 22; col++) {
const x = (col - 10.5) * 1.1;
const z = (row - 8.5) * 1.1;
dummy.position.set(x, 0.028, z);
dummy.updateMatrix();
paving.setMatrixAt(pavingIndex, dummy.matrix);
const variation = 0.5 + 0.5 * Math.sin(col * 12.73 + row * 7.17);
pavingColor.setHSL(
0.105 + variation * 0.018,
0.30,
0.69 + variation * 0.065
);
paving.setColorAt(pavingIndex, pavingColor);
pavingIndex++;
}
}
paving.receiveShadow = true;
scene.add(paving);
// A broad foundation under the paving.
box(26, 0.22, 22, 0, -0.12, 0, M.sand, false);
// ------------------------------------------------------------
// Andalusi arcade
// ------------------------------------------------------------
function addArchPanel(x, z, width = 3.15, height = 3.25) {
const shape = new THREE.Shape();
shape.moveTo(-width / 2, 0);
shape.lineTo(width / 2, 0);
shape.lineTo(width / 2, height);
shape.lineTo(-width / 2, height);
shape.closePath();
const radius = width * 0.29;
const spring = height * 0.48;
const crown = height * 0.81;
const opening = new THREE.Path();
opening.moveTo(-radius, 0.025);
opening.lineTo(-radius, spring);
opening.bezierCurveTo(
-radius,
spring + 0.35,
-radius * 0.88,
crown - 0.12,
0,
crown
);
opening.bezierCurveTo(
radius * 0.88,
crown - 0.12,
radius,
spring + 0.35,
radius,
spring
);
opening.lineTo(radius, 0.025);
opening.closePath();
shape.holes.push(opening);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.38,
bevelEnabled: false,
curveSegments: 14
});
const arch = new THREE.Mesh(geometry, M.stucco);
arch.position.set(x, 0.03, z);
arch.castShadow = true;
arch.receiveShadow = true;
scene.add(arch);
}
[-7.4, -3.7, 0, 3.7, 7.4].forEach((x) => {
addArchPanel(x, -8.75);
});
// Columns between the arch panels.
[-9, -5.55, -1.85, 1.85, 5.55, 9].forEach((x) => {
cylinder(0.19, 0.23, 2.65, x, 1.34, -8.5, M.paleStone, 10);
box(0.48, 0.18, 0.48, x, 0.12, -8.5, M.warmStone);
box(0.47, 0.15, 0.47, x, 2.63, -8.5, M.paleStone);
});
// Decorative mosaic frieze.
const mosaicColors = [M.cobalt, M.terracotta, M.paleStone, M.turquoise];
for (let i = 0; i < 42; i++) {
box(
0.31,
0.22,
0.07,
-9.9 + i * 0.49,
2.91,
-8.33,
mosaicColors[i % mosaicColors.length]
);
}
box(21, 0.22, 0.48, 0, 3.22, -8.5, M.warmStone);
box(21, 0.12, 0.62, 0, 3.39, -8.5, M.paleStone);
// Low side garden walls.
box(0.35, 0.9, 18, -10.7, 0.43, 0.5, M.warmStone);
box(0.35, 0.9, 18, 10.7, 0.43, 0.5, M.warmStone);
// ------------------------------------------------------------
// Main rectangular pool
// ------------------------------------------------------------
const POOL_WATER_Y = 0.78;
const INLET_WATER_Y = 1.07;
// Foundation and recessed tiled floor.
box(8.15, 0.25, 5.25, 0, 0.27, 0, M.darkStone);
const poolTileGeometry = new THREE.BoxGeometry(0.56, 0.065, 0.56);
const poolTiles = new THREE.InstancedMesh(
poolTileGeometry,
material(0xffffff, { roughness: 0.66 }),
12 * 7
);
let tileIndex = 0;
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 12; col++) {
dummy.position.set(
(col - 5.5) * 0.6,
0.405,
(row - 3) * 0.6
);
dummy.updateMatrix();
poolTiles.setMatrixAt(tileIndex, dummy.matrix);
const dark = (row + col) % 4 === 0;
poolTiles.setColorAt(
tileIndex,
new THREE.Color(dark ? 0x4f8e91 : 0x91c6bb)
);
tileIndex++;
}
}
poolTiles.receiveShadow = true;
scene.add(poolTiles);
// Pool water surface.
box(7.34, 0.08, 4.42, 0, POOL_WATER_Y - 0.04, 0, M.water, false);
// Long pool walls.
box(0.40, 1.12, 5.24, -3.88, 0.66, 0, M.paleStone);
box(0.40, 1.12, 5.24, 3.88, 0.66, 0, M.paleStone);
box(0.50, 0.12, 5.38, -3.88, 1.25, 0, M.warmStone);
box(0.50, 0.12, 5.38, 3.88, 1.25, 0, M.warmStone);
// End walls, split to leave true openings for inlet and outlet.
const openingHalfWidth = 0.78;
const endPieceLength = 3.70 - openingHalfWidth;
const endPieceCenter = openingHalfWidth + endPieceLength / 2;
[-2.42, 2.42].forEach((z) => {
[-endPieceCenter, endPieceCenter].forEach((x) => {
box(endPieceLength, 1.12, 0.40, x, 0.66, z, M.paleStone);
box(endPieceLength, 0.12, 0.50, x, 1.25, z, M.warmStone);
});
});
// ------------------------------------------------------------
// Raised inlet channel
// The inlet water surface is intentionally higher than the pool.
// ------------------------------------------------------------
const inletStartZ = -7.22;
const inletEndZ = -2.43;
const inletLength = inletEndZ - inletStartZ;
const inletCenterZ = (inletStartZ + inletEndZ) / 2;
// Stone bed.
box(
1.45,
0.18,
inletLength,
0,
0.91,
inletCenterZ,
M.warmStone
);
// Visible blue water.
box(
1.07,
0.08,
inletLength + 0.08,
0,
INLET_WATER_Y - 0.04,
inletCenterZ,
M.water,
false
);
// Raised channel side walls.
[-0.69, 0.69].forEach((x) => {
box(
0.18,
0.34,
inletLength,
x,
1.10,
inletCenterZ,
M.paleStone
);
});
// Supports under the elevated channel.
[-6.55, -5.15, -3.75].forEach((z) => {
box(0.78, 0.83, 0.48, 0, 0.42, z, M.warmStone);
box(0.92, 0.12, 0.58, 0, 0.84, z, M.paleStone);
});
// Small raised source cistern at the rear.
box(1.55, 0.82, 1.15, 0, 0.42, -7.52, M.warmStone);
box(2.18, 0.16, 1.70, 0, 0.86, -7.52, M.paleStone);
box(1.78, 0.08, 1.30, 0, INLET_WATER_Y - 0.04, -7.52, M.water, false);
box(0.18, 0.36, 1.68, -1.0, 1.06, -7.52, M.paleStone);
box(0.18, 0.36, 1.68, 1.0, 1.06, -7.52, M.paleStone);
box(2.05, 0.36, 0.18, 0, 1.06, -8.27, M.paleStone);
// Waterfall from the raised channel into the pool.
const waterfall = box(
1.05,
0.34,
0.075,
0,
0.91,
-2.31,
M.waterfall,
false
);
// Foam at the impact point.
const foam = new THREE.Mesh(
new THREE.SphereGeometry(0.42, 16, 8),
M.foam
);
foam.scale.set(1.6, 0.16, 0.58);
foam.position.set(0, 0.81, -2.10);
scene.add(foam);
// ------------------------------------------------------------
// Branch irrigation channels
// ------------------------------------------------------------
const branchA = [0, INLET_WATER_Y, -5.72];
const branchB = [6.0, INLET_WATER_Y, -5.72];
shiftedBeam(branchA, branchB, 0.66, 0.15, -0.14, M.warmStone);
shiftedBeam(branchA, branchB, 0.48, 0.08, 0, M.water);
shiftedBeam(branchA, branchB, 0.14, 0.28, 0.15, M.paleStone);
// Move the horizontal branch rails to either side.
beamBetween(
[0, INLET_WATER_Y + 0.15, -5.96],
[6, INLET_WATER_Y + 0.15, -5.96],
0.14,
0.28,
M.paleStone
);
beamBetween(
[0, INLET_WATER_Y + 0.15, -5.48],
[6, INLET_WATER_Y + 0.15, -5.48],
0.14,
0.28,
M.paleStone
);
const sideBranchA = [6.0, INLET_WATER_Y, -5.72];
const sideBranchB = [6.0, INLET_WATER_Y, 3.35];
shiftedBeam(sideBranchA, sideBranchB, 0.66, 0.15, -0.14, M.warmStone);
shiftedBeam(sideBranchA, sideBranchB, 0.48, 0.08, 0, M.water);
beamBetween(
[5.72, INLET_WATER_Y + 0.15, -5.72],
[5.72, INLET_WATER_Y + 0.15, 3.35],
0.14,
0.28,
M.paleStone
);
beamBetween(
[6.28, INLET_WATER_Y + 0.15, -5.72],
[6.28, INLET_WATER_Y + 0.15, 3.35],
0.14,
0.28,
M.paleStone
);
[-4.7, -2.2, 0.3, 2.5].forEach((z) => {
box(0.52, 0.83, 0.48, 6, 0.42, z, M.warmStone);
box(0.68, 0.12, 0.58, 6, 0.84, z, M.paleStone);
});
// Small square irrigation basin at the end of the side branch.
box(1.42, 0.16, 1.42, 6, 0.84, 3.72, M.paleStone);
box(1.05, 0.08, 1.05, 6, INLET_WATER_Y - 0.04, 3.72, M.water, false);
box(0.16, 0.34, 1.42, 5.34, 1.06, 3.72, M.warmStone);
box(0.16, 0.34, 1.42, 6.66, 1.06, 3.72, M.warmStone);
box(1.42, 0.34, 0.16, 6, 1.06, 3.08, M.warmStone);
box(1.42, 0.34, 0.16, 6, 1.06, 4.36, M.warmStone);
// ------------------------------------------------------------
// Clearly connected outlet from the main pool
// ------------------------------------------------------------
const outletStart = [0, POOL_WATER_Y, 2.16];
const outletEnd = [0, 0.50, 5.66];
shiftedBeam(
outletStart,
outletEnd,
1.32,
0.16,
-0.14,
M.warmStone
);
shiftedBeam(
outletStart,
outletEnd,
1.05,
0.08,
0,
M.water
);
shiftedBeam(
outletStart,
outletEnd,
0.17,
0.30,
0.15,
M.paleStone
);
// Separate the outlet rails because the channel runs in Z.
beamBetween(
[-0.61, POOL_WATER_Y + 0.15, 2.16],
[-0.61, 0.50 + 0.15, 5.66],
0.17,
0.30,
M.paleStone
);
beamBetween(
[0.61, POOL_WATER_Y + 0.15, 2.16],
[0.61, 0.50 + 0.15, 5.66],
0.17,
0.30,
M.paleStone
);
// Octagonal receiving basin.
cylinder(1.25, 1.34, 0.46, 0, 0.21, 6.05, M.warmStone, 8);
cylinder(1.03, 1.03, 0.065, 0, 0.465, 6.05, M.water, 8);
const basinRim = new THREE.Mesh(
new THREE.TorusGeometry(1.08, 0.12, 8, 8),
M.paleStone
);
basinRim.rotation.x = Math.PI / 2;
basinRim.position.set(0, 0.44, 6.05);
basinRim.castShadow = true;
scene.add(basinRim);
// ------------------------------------------------------------
// Garden beds and plants
// ------------------------------------------------------------
function cypress(x, z, scale = 1) {
cylinder(0.13, 0.18, 1.8 * scale, x, 0.9 * scale, z, M.trunk, 8);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.75 * scale, 3.1 * scale, 9),
M.cypress
);
lower.position.set(x, 2.15 * scale, z);
lower.castShadow = true;
scene.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.49 * scale, 2.3 * scale, 9),
M.cypressLight
);
upper.position.set(x, 3.45 * scale, z);
upper.castShadow = true;
scene.add(upper);
}
function orangeTree(x, z, scale = 1) {
cylinder(0.13 * scale, 0.18 * scale, 1.65 * scale, x, 0.82 * scale, z, M.trunk, 8);
const clusters = [
[-0.42, 1.85, 0.05, 0.62],
[0.38, 1.88, 0.08, 0.66],
[0.02, 2.32, 0, 0.72],
[-0.12, 1.67, -0.18, 0.53],
[0.22, 1.67, 0.22, 0.50]
];
clusters.forEach((c, index) => {
const leaf = new THREE.Mesh(
new THREE.IcosahedronGeometry(c[3] * scale, 1),
index % 2 === 0 ? M.leaf : M.leafLight
);
leaf.position.set(
x + c[0] * scale,
c[1] * scale,
z + c[2] * scale
);
leaf.scale.y = 0.88;
leaf.castShadow = true;
scene.add(leaf);
});
for (let i = 0; i < 6; i++) {
const fruit = new THREE.Mesh(
new THREE.SphereGeometry(0.095 * scale, 8, 6),
M.orange
);
const angle = i * 1.65;
fruit.position.set(
x + Math.cos(angle) * 0.63 * scale,
(1.72 + (i % 3) * 0.31) * scale,
z + Math.sin(angle) * 0.58 * scale
);
fruit.castShadow = true;
scene.add(fruit);
}
}
function planter(x, z, width, depth, plantColor = M.leaf) {
box(width, 0.28, depth, x, 0.14, z, M.terracotta);
box(width - 0.16, 0.10, depth - 0.16, x, 0.30, z, M.soil);
const count = Math.max(2, Math.floor(width * 2));
for (let i = 0; i < count; i++) {
const shrub = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.30 + (i % 2) * 0.06, 1),
plantColor
);
shrub.position.set(
x - width * 0.36 + (i / Math.max(1, count - 1)) * width * 0.72,
0.56,
z + (i % 2 ? 0.12 : -0.12)
);
shrub.scale.y = 0.85;
shrub.castShadow = true;
scene.add(shrub);
}
}
planter(-6.7, 1.2, 2.0, 3.1, M.cypress);
planter(8.25, 0.2, 1.65, 3.6, M.leaf);
planter(-2.8, 5.25, 2.4, 1.0, M.leafLight);
cypress(-8.2, -3.2, 1.05);
cypress(8.1, -6.6, 1.0);
cypress(-8.0, 5.3, 0.85);
orangeTree(8.35, -1.2, 1.05);
orangeTree(-7.8, 4.6, 0.9);
// Terracotta pots.
function pot(x, z, scale = 1) {
cylinder(
0.38 * scale,
0.28 * scale,
0.60 * scale,
x,
0.30 * scale,
z,
M.terracotta,
10
);
cylinder(
0.41 * scale,
0.41 * scale,
0.10 * scale,
x,
0.60 * scale,
z,
M.paleStone,
10
);
const shrub = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.43 * scale, 1),
M.leaf
);
shrub.position.set(x, 0.93 * scale, z);
shrub.scale.y = 1.25;
shrub.castShadow = true;
scene.add(shrub);
}
pot(-4.9, -4.2, 0.85);
pot(4.8, -6.6, 0.78);
pot(-3.6, 5.35, 0.72);
pot(8.2, 4.65, 0.82);
// ------------------------------------------------------------
// Animated water details
// ------------------------------------------------------------
const ripples = [];
function addRipple(x, y, z, color = 0xbdebe1, delay = 0) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.42, 0.48, 48),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, y, z);
scene.add(ring);
ripples.push({ mesh: ring, delay });
}
addRipple(0, POOL_WATER_Y + 0.015, -2.08, 0xd9f4e9, 0);
addRipple(0.18, POOL_WATER_Y + 0.018, -2.02, 0xd9f4e9, 1.2);
addRipple(0, 0.51, 6.05, 0xd9f4e9, 0.5);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
waterfall.scale.x = 1 + Math.sin(elapsed * 5.5) * 0.025;
waterfall.material.opacity = 0.68 + Math.sin(elapsed * 4.2) * 0.07;
foam.scale.x = 1.6 + Math.sin(elapsed * 4.8) * 0.12;
foam.scale.z = 0.58 + Math.cos(elapsed * 5.1) * 0.05;
ripples.forEach((ripple) => {
const phase = (elapsed + ripple.delay) % 2.8;
const t = phase / 2.8;
ripple.mesh.scale.setScalar(0.5 + t * 3.4);
ripple.mesh.material.opacity = Math.sin(t * Math.PI) * 0.55;
});
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
// ------------------------------------------------------------
// Direct camera controls: orbit and zoom
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.65, 0.15),
radius: 17.5,
theta: 0.69,
phi: 0.93,
minRadius: 10,
maxRadius: 27,
minPhi: 0.32,
maxPhi: 1.34,
dragging: false,
pointerX: 0,
pointerY: 0,
update() {
const sinPhi = Math.sin(this.phi);
camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * Math.cos(this.phi),
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
camera.lookAt(this.target);
},
reset() {
this.target.set(0, 0.65, 0.15);
this.radius = 17.5;
this.theta = 0.69;
this.phi = 0.93;
}
};
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
controls.minPhi,
controls.maxPhi
);
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("dblclick", () => controls.reset());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
controls.minRadius,
controls.maxRadius
);
},
{ passive: false }
);
// Pinch zoom for touch devices.
const activePointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius + (pinchDistance - distance) * 0.025,
controls.minRadius,
controls.maxRadius
);
}
pinchDistance = distance;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
controls.update();
animate();
</script>
</body>
</html>
```