Prompt specification
Build or customize the Three.js 3D scene "Pitched roof tile with gutter edge" 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: Pitched roof tile with gutter edge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pitched-roof-tile-with-gutter-edge-x2217
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Model a small pitched roof patch ending at a gutter. Show overlapping tiles and the downhill direction that prevents rain from pooling on the visible surface.
Working Three.js Starter (pitched-roof-tile-with-gutter-edge-x2217):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Roof — Shingle Overlap and Drainage</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7e7;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
top: 20px;
left: 20px;
width: min(350px, calc(100vw - 40px));
padding: 17px 18px;
color: #eef8f7;
background: rgba(18, 34, 37, 0.88);
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 14px;
box-shadow: 0 12px 32px rgba(12, 27, 29, 0.2);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #70dcf3;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0 0 9px;
font-size: clamp(19px, 2.2vw, 25px);
line-height: 1.15;
}
.panel p {
margin: 0;
color: #c5d8d8;
font-size: 13px;
line-height: 1.5;
}
.legend {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
color: #dff7fb;
font-size: 12px;
font-weight: 700;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 3px;
background: #55d9f5;
box-shadow: 0 0 12px rgba(85, 217, 245, 0.75);
}
.hint {
position: fixed;
z-index: 5;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 8px 12px;
color: #244044;
background: rgba(245, 252, 251, 0.82);
border: 1px solid rgba(32, 64, 68, 0.15);
border-radius: 999px;
font-size: 12px;
font-weight: 700;
white-space: nowrap;
pointer-events: none;
}
#reset {
position: fixed;
z-index: 6;
top: 20px;
right: 20px;
padding: 9px 13px;
color: #eef8f7;
background: rgba(18, 34, 37, 0.86);
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
}
#reset:hover {
background: rgba(30, 56, 60, 0.95);
}
.world-label {
position: fixed;
z-index: 4;
top: 0;
left: 0;
padding: 5px 8px;
color: #17363b;
background: rgba(245, 253, 252, 0.9);
border: 1px solid rgba(22, 61, 67, 0.16);
border-radius: 6px;
box-shadow: 0 4px 12px rgba(24, 48, 51, 0.1);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.world-label.flow {
color: #087b98;
border-color: rgba(29, 174, 207, 0.35);
background: rgba(225, 250, 255, 0.94);
}
@media (max-width: 600px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
.panel p {
font-size: 12px;
}
#reset {
top: auto;
right: 12px;
bottom: 56px;
}
.hint {
bottom: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel roof with overlapping shingles and drainage arrows"></canvas>
<section class="panel">
<div class="eyebrow">Voxel Roof Detail</div>
<h1>Lapped shingles shed toward the gutter</h1>
<p>
Each course overlaps the course below it. The visible shingle faces
fall about 12° toward the eave, so runoff steps over the laps instead
of forming a level pool.
</p>
<div class="legend">
<span class="swatch"></span>
Animated downhill water path
</div>
</section>
<button id="reset" type="button">Reset view</button>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const resetButton = document.querySelector("#reset");
// -------------------------------------------------------------------------
// Renderer, scene, lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7e7);
scene.fog = new THREE.Fog(0xdce7e7, 23, 42);
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(
0xe9fbff,
0x66706b,
2.05
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d4, 3.15);
sun.position.set(-5.5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ad8ed, 0.7);
fill.position.set(7, 5, -6);
scene.add(fill);
// -------------------------------------------------------------------------
// Small custom orbit camera; no addons or control imports
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, 1.55, -0.05);
let azimuth = 0.62;
let polar = 0.84;
let zoom = 1.08;
let dragging = false;
let lastX = 0;
let lastY = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
const radius = 18;
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
resizeCamera();
}
function resizeCamera() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Fit the full model even on narrow portrait displays.
const viewHeight = Math.max(8.4, 10.8 / aspect) / zoom;
camera.left = -viewHeight * aspect * 0.5;
camera.right = viewHeight * aspect * 0.5;
camera.top = viewHeight * 0.5;
camera.bottom = -viewHeight * 0.5;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
function resetView() {
azimuth = 0.62;
polar = 0.84;
zoom = 1.08;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
azimuth -= dx * 0.007;
polar = clamp(polar - dy * 0.006, 0.40, 1.38);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
zoom = clamp(zoom * Math.exp(-event.deltaY * 0.001), 0.65, 1.85);
resizeCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
window.addEventListener("resize", resizeCamera);
updateCamera();
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.85,
metalness: 0.02,
flatShading: true,
...options
});
}
const groundMaterial = standardMaterial(0xd7e2df, { roughness: 1 });
const plinthMaterial = standardMaterial(0x8e9d99, { roughness: 1 });
const woodMaterial = standardMaterial(0x75533c);
const darkWoodMaterial = standardMaterial(0x503b2d);
const gutterMaterial = standardMaterial(0x3c5155, {
metalness: 0.28,
roughness: 0.58
});
const gutterEdgeMaterial = standardMaterial(0x526b70, {
metalness: 0.22,
roughness: 0.55
});
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x52dcf8,
emissive: 0x087e9a,
emissiveIntensity: 0.62,
roughness: 0.3,
metalness: 0.05
});
const tileColors = [
0xc75a3c,
0xd56c46,
0xb94e35,
0xe17a50,
0xbf5639
];
const tileMaterials = tileColors.map((color) =>
standardMaterial(color, { roughness: 0.92 })
);
const lipMaterials = tileColors.map((color) =>
standardMaterial(new THREE.Color(color).multiplyScalar(0.78), {
roughness: 0.96
})
);
function addBox(width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Display ground
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI * 0.5;
ground.position.y = -0.22;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x6f898a, 0x9cadab);
grid.position.y = -0.205;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
addBox(10.1, 0.18, 6.6, plinthMaterial, 0, -0.10, 0.25);
// -------------------------------------------------------------------------
// Roof dimensions
//
// +Z is downhill toward the eave and gutter.
// Every shingle is rotated around X so its visible top falls toward +Z.
// -------------------------------------------------------------------------
const ROOF_WIDTH = 8.4;
const COLUMN_COUNT = 10;
const ROW_COUNT = 7;
const CELL_WIDTH = ROOF_WIDTH / COLUMN_COUNT;
const EAVE_Z = 2.55;
const EAVE_TOP_Y = 2.45;
const SLOPE = 0.22;
const PITCH_ANGLE = Math.atan(SLOPE);
const TILE_DEPTH = 0.88;
const COURSE_STEP = 0.62;
const TILE_THICKNESS = 0.18;
const COURSE_LAYER_STEP = 0.095;
function courseEndZ(row) {
return EAVE_Z - row * COURSE_STEP;
}
function courseTopY(row, z) {
return EAVE_TOP_Y
- SLOPE * (z - EAVE_Z)
+ row * COURSE_LAYER_STEP;
}
const roofStartZ = courseEndZ(ROW_COUNT - 1) - TILE_DEPTH;
const roofCenterZ = (roofStartZ + EAVE_Z) * 0.5;
const roofLength = EAVE_Z - roofStartZ;
// -------------------------------------------------------------------------
// Wooden stepped deck and exposed rafters
// -------------------------------------------------------------------------
const deckGeometry = new THREE.BoxGeometry(
ROOF_WIDTH + 0.12,
0.13,
TILE_DEPTH
);
for (let row = 0; row < ROW_COUNT; row++) {
const endZ = courseEndZ(row);
const centerZ = endZ - TILE_DEPTH * 0.5;
const tileTopY = courseTopY(row, centerZ);
const tileBottomY =
tileTopY - TILE_THICKNESS / Math.cos(PITCH_ANGLE);
const deckTopY = tileBottomY - 0.012;
const deckCenterY =
deckTopY - 0.13 / (2 * Math.cos(PITCH_ANGLE));
const deck = new THREE.Mesh(deckGeometry, woodMaterial);
deck.position.set(0, deckCenterY, centerZ);
deck.rotation.x = PITCH_ANGLE;
deck.castShadow = true;
deck.receiveShadow = true;
scene.add(deck);
}
const rafterGeometry = new THREE.BoxGeometry(
0.18,
0.18,
roofLength + 0.12
);
for (const x of [-3.6, -1.8, 0, 1.8, 3.6]) {
const referenceTop =
EAVE_TOP_Y - SLOPE * (roofCenterZ - EAVE_Z);
const rafterTop = referenceTop - 0.31;
const rafterY =
rafterTop - 0.18 / (2 * Math.cos(PITCH_ANGLE));
const rafter = new THREE.Mesh(rafterGeometry, darkWoodMaterial);
rafter.position.set(x, rafterY, roofCenterZ);
rafter.rotation.x = PITCH_ANGLE;
rafter.castShadow = true;
rafter.receiveShadow = true;
scene.add(rafter);
}
// Four simple posts keep the roof patch grounded without hiding its profile.
for (const x of [-3.8, 3.8]) {
for (const z of [-1.25, 1.38]) {
const roofReferenceY =
EAVE_TOP_Y - SLOPE * (z - EAVE_Z);
const topY = roofReferenceY - 0.38;
const height = topY;
const centerY = height * 0.5;
addBox(
0.22,
height,
0.22,
darkWoodMaterial,
x,
centerY,
z
);
}
}
// -------------------------------------------------------------------------
// Overlapping voxel shingles
// -------------------------------------------------------------------------
for (let row = 0; row < ROW_COUNT; row++) {
const endZ = courseEndZ(row);
const centerZ = endZ - TILE_DEPTH * 0.5;
const topY = courseTopY(row, centerZ);
const centerY =
topY - TILE_THICKNESS / (2 * Math.cos(PITCH_ANGLE));
// Alternate rows are staggered by half a tile.
const stagger = (row % 2) * CELL_WIDTH * 0.5;
for (let column = -1; column <= COLUMN_COUNT; column++) {
const rawCenterX =
-ROOF_WIDTH * 0.5 + (column + 0.5) * CELL_WIDTH + stagger;
const left = Math.max(
rawCenterX - CELL_WIDTH * 0.5,
-ROOF_WIDTH * 0.5
);
const right = Math.min(
rawCenterX + CELL_WIDTH * 0.5,
ROOF_WIDTH * 0.5
);
const width = right - left - 0.035;
if (width <= 0.06) continue;
const x = (left + right) * 0.5;
const materialIndex =
(row * 3 + column * 2 + Math.abs(column)) % tileMaterials.length;
const tile = new THREE.Mesh(
new THREE.BoxGeometry(width, TILE_THICKNESS, TILE_DEPTH),
tileMaterials[materialIndex]
);
tile.position.set(x, centerY, centerZ);
tile.rotation.x = PITCH_ANGLE;
tile.castShadow = true;
tile.receiveShadow = true;
// Darker raised lip marks the exposed, downhill edge of every tile.
const lip = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.055, 0.105),
lipMaterials[materialIndex]
);
lip.position.set(
0,
TILE_THICKNESS * 0.5 + 0.012,
TILE_DEPTH * 0.5 - 0.055
);
lip.castShadow = true;
lip.receiveShadow = true;
tile.add(lip);
scene.add(tile);
}
}
// -------------------------------------------------------------------------
// Eave fascia
// -------------------------------------------------------------------------
addBox(
ROOF_WIDTH + 0.22,
0.28,
0.16,
woodMaterial,
0,
EAVE_TOP_Y - 0.28,
EAVE_Z + 0.035
);
// -------------------------------------------------------------------------
// Open U-shaped gutter
// -------------------------------------------------------------------------
const GUTTER_Z = EAVE_Z + 0.23;
const GUTTER_WIDTH = ROOF_WIDTH + 0.72;
const GUTTER_BOTTOM_Y = 1.84;
const GUTTER_WATER_Y = 1.935;
addBox(
GUTTER_WIDTH,
0.12,
0.72,
gutterMaterial,
0,
GUTTER_BOTTOM_Y,
GUTTER_Z
);
// Rear wall, directly beneath the roof edge.
addBox(
GUTTER_WIDTH,
0.42,
0.11,
gutterEdgeMaterial,
0,
GUTTER_BOTTOM_Y + 0.21,
EAVE_Z - 0.11
);
// Front wall is slightly lower so the channel remains visible.
addBox(
GUTTER_WIDTH,
0.30,
0.11,
gutterEdgeMaterial,
0,
GUTTER_BOTTOM_Y + 0.15,
GUTTER_Z + 0.305
);
// End caps.
for (const side of [-1, 1]) {
addBox(
0.12,
0.43,
0.72,
gutterEdgeMaterial,
side * (GUTTER_WIDTH * 0.5),
GUTTER_BOTTOM_Y + 0.215,
GUTTER_Z
);
}
// A shallow blue water surface inside the gutter.
const gutterWater = addBox(
GUTTER_WIDTH - 0.16,
0.025,
0.47,
waterMaterial,
0,
GUTTER_WATER_Y,
GUTTER_Z
);
gutterWater.castShadow = false;
// Square downspout at the right end.
addBox(
0.30,
1.86,
0.30,
gutterMaterial,
GUTTER_WIDTH * 0.5 - 0.02,
0.92,
GUTTER_Z
);
addBox(
0.30,
0.22,
0.42,
gutterEdgeMaterial,
GUTTER_WIDTH * 0.5 - 0.02,
GUTTER_BOTTOM_Y - 0.02,
GUTTER_Z
);
// Small visible water accent on the downspout.
addBox(
0.055,
1.28,
0.018,
waterMaterial,
GUTTER_WIDTH * 0.5 - 0.02,
0.91,
GUTTER_Z + 0.158
);
// -------------------------------------------------------------------------
// Blocky downhill chevrons
// -------------------------------------------------------------------------
const FLOW_X = -0.42;
const ARROW_X = 0.42;
const flowArrows = [];
function makeFlowArrow() {
const group = new THREE.Group();
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.045, 0.34),
waterMaterial
);
shaft.position.set(0, 0.035, -0.08);
shaft.castShadow = true;
group.add(shaft);
const wingGeometry = new THREE.BoxGeometry(
0.075,
0.045,
0.27
);
const leftWing = new THREE.Mesh(wingGeometry, waterMaterial);
leftWing.position.set(-0.075, 0.035, 0.10);
leftWing.rotation.y = 0.60;
leftWing.castShadow = true;
group.add(leftWing);
const rightWing = new THREE.Mesh(wingGeometry, waterMaterial);
rightWing.position.set(0.075, 0.035, 0.10);
rightWing.rotation.y = -0.60;
rightWing.castShadow = true;
group.add(rightWing);
return group;
}
for (const row of [5, 3, 1]) {
const z = courseEndZ(row) - 0.31;
const y = courseTopY(row, z) + 0.055;
const arrow = makeFlowArrow();
arrow.position.set(ARROW_X, y, z);
arrow.rotation.x = PITCH_ANGLE;
scene.add(arrow);
flowArrows.push(arrow);
}
// -------------------------------------------------------------------------
// Water route
//
// The route follows the pitched course tops, drops vertically at each
// lap, then enters the gutter and travels toward the downspout.
// -------------------------------------------------------------------------
const route = [];
const topRow = ROW_COUNT - 1;
let currentZ = courseEndZ(topRow) - TILE_DEPTH;
route.push(
new THREE.Vector3(
FLOW_X,
courseTopY(topRow, currentZ) + 0.075,
currentZ
)
);
for (let row = topRow; row >= 0; row--) {
const endZ = courseEndZ(row);
route.push(
new THREE.Vector3(
FLOW_X,
courseTopY(row, endZ) + 0.075,
endZ
)
);
if (row > 0) {
route.push(
new THREE.Vector3(
FLOW_X,
courseTopY(row - 1, endZ) + 0.075,
endZ
)
);
}
}
route.push(
new THREE.Vector3(
FLOW_X,
EAVE_TOP_Y - 0.12,
EAVE_Z + 0.13
)
);
route.push(
new THREE.Vector3(
FLOW_X,
GUTTER_WATER_Y + 0.055,
GUTTER_Z
)
);
route.push(
new THREE.Vector3(
GUTTER_WIDTH * 0.5 - 0.02,
GUTTER_WATER_Y + 0.055,
GUTTER_Z
)
);
const cumulativeLengths = [0];
for (let i = 1; i < route.length; i++) {
cumulativeLengths.push(
cumulativeLengths[i - 1] +
route[i].distanceTo(route[i - 1])
);
}
const routeLength = cumulativeLengths[cumulativeLengths.length - 1];
function pointAlongRoute(distance, targetVector) {
const d = clamp(distance, 0, routeLength);
for (let i = 1; i < cumulativeLengths.length; i++) {
if (d <= cumulativeLengths[i]) {
const segmentLength =
cumulativeLengths[i] - cumulativeLengths[i - 1];
const t = segmentLength === 0
? 0
: (d - cumulativeLengths[i - 1]) / segmentLength;
targetVector.lerpVectors(route[i - 1], route[i], t);
return targetVector;
}
}
targetVector.copy(route[route.length - 1]);
return targetVector;
}
// Small voxel water beads make the downhill route visible.
const dropGeometry = new THREE.BoxGeometry(0.075, 0.11, 0.075);
const drops = [];
for (let i = 0; i < 20; i++) {
const drop = new THREE.Mesh(dropGeometry, waterMaterial);
drop.castShadow = true;
scene.add(drop);
drops.push(drop);
}
// -------------------------------------------------------------------------
// World-space labels projected manually to screen coordinates
// -------------------------------------------------------------------------
const labelDefinitions = [
{
text: "UPHILL",
position: new THREE.Vector3(-4.55, 3.72, -2.0),
className: ""
},
{
text: "DOWNHILL ↓",
position: new THREE.Vector3(4.60, 2.78, 1.12),
className: "flow"
},
{
text: "GUTTER",
position: new THREE.Vector3(4.85, 1.88, 3.02),
className: "flow"
}
];
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `world-label ${definition.className}`;
element.textContent = definition.text;
document.body.appendChild(element);
definition.element = element;
}
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of labelDefinitions) {
projected.copy(definition.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
definition.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
definition.element.style.visibility =
projected.z < -1 || projected.z > 1 ? "hidden" : "visible";
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const waterPosition = new THREE.Vector3();
function animate() {
const elapsed = clock.getElapsedTime();
for (let i = 0; i < drops.length; i++) {
const progress = (elapsed * 0.072 + i / drops.length) % 1;
pointAlongRoute(
progress * routeLength,
waterPosition
);
drops[i].position.copy(waterPosition);
drops[i].rotation.y = elapsed * 0.8 + i;
}
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.035;
for (const arrow of flowArrows) {
arrow.scale.setScalar(pulse);
}
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```