Prompt specification
Build or customize the Three.js 3D scene "Terrace wall with a drainage outlet" 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: Terrace wall with a drainage outlet
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/terrace-wall-with-a-drainage-outlet-x2214
Scene Description Prompt:
Make a cutaway Three.js scene in a self-contained HTML file using cdnjs: terrace wall with a drainage outlet. Model a small planted terrace above a wall with an outlet pipe. Animate illustrative water moving through a drainage layer to the exposed outlet below.
Working Three.js Starter (terrace-wall-with-a-drainage-outlet-x2214):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cutaway Terrace Drainage</title>
<style>
:root {
--ink: #18313a;
--muted: #567078;
--panel: rgba(248, 252, 250, 0.88);
--line: rgba(24, 49, 58, 0.14);
--water: #00bfe8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 30%, #f7fbf7 0%, #dce9e5 50%, #c8d8d4 100%);
color: var(--ink);
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:active {
cursor: grabbing;
}
.panel {
position: absolute;
z-index: 10;
pointer-events: none;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 12px 35px rgba(33, 60, 67, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 19px 20px 17px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #497078;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 5px rgba(0, 191, 232, 0.13);
content: "";
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 1.02;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 14px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(24, 49, 58, 0.16);
border-radius: 9px;
padding: 8px 11px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
#legend {
right: 24px;
bottom: 24px;
min-width: 205px;
padding: 14px 16px;
border-radius: 14px;
}
.legend-title {
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
}
.swatch {
width: 20px;
height: 4px;
border-radius: 10px;
background: var(--water);
box-shadow: 0 0 8px rgba(0, 191, 232, 0.65);
}
.swatch.gravel {
background: #b69a6f;
box-shadow: none;
}
.swatch.root {
background: #805033;
box-shadow: none;
}
#hint {
position: absolute;
z-index: 10;
left: 24px;
bottom: 24px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(248, 252, 250, 0.74);
color: #567078;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
pointer-events: none;
backdrop-filter: blur(10px);
}
.label {
position: absolute;
z-index: 8;
top: 0;
left: 0;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 7px;
background: rgba(20, 44, 52, 0.82);
box-shadow: 0 5px 18px rgba(15, 39, 48, 0.16);
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.095em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
will-change: transform;
}
.label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 18px;
background: rgba(20, 44, 52, 0.55);
content: "";
}
.label.water {
background: rgba(0, 139, 181, 0.88);
}
@media (max-width: 700px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
#legend {
right: 12px;
bottom: 12px;
min-width: 170px;
}
#hint {
display: none;
}
.label {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway of a planted terrace drainage system"></canvas>
<section id="intro" class="panel">
<div class="eyebrow">Live drainage study</div>
<h1>Terrace Wall<br />Cutaway</h1>
<p class="subtitle">
Rain infiltrates the planted soil, collects in the gravel layer,
and travels through the perforated pipe to the exposed outlet.
</p>
<div class="controls">
<button id="pause" type="button">Pause flow</button>
<button id="reset" type="button">Reset view</button>
</div>
</section>
<section id="legend" class="panel">
<div class="legend-title">Flow key</div>
<div class="legend-row"><span class="swatch"></span>Moving water</div>
<div class="legend-row"><span class="swatch gravel"></span>Drainage aggregate</div>
<div class="legend-row"><span class="swatch root"></span>Root zone</div>
</section>
<div id="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="label-terrace" class="label">Planted terrace</div>
<div id="label-drainage" class="label">Drainage layer</div>
<div id="label-collector" class="label water">Collector pipe</div>
<div id="label-wall" class="label">Cutaway wall</div>
<div id="label-outlet" class="label water">Exposed outlet</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 renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xdbe8e4, 19, 35);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------
// Camera controls, implemented without Three.js add-ons.
// ------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 1.9, -0.75),
radius: 14.4,
theta: 0.55,
phi: 1.16,
dragging: false,
lastX: 0,
lastY: 0
};
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.target.set(0, 1.9, -0.75);
orbit.radius = 14.4;
orbit.theta = 0.55;
orbit.phi = 1.16;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.62, 1.43);
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
updateCamera();
});
function endDrag(event) {
orbit.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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.009,
9.5,
22
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#reset").addEventListener("click", resetCamera);
updateCamera();
// ------------------------------------------------------------
// Lighting.
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf4fffb, 0x68756c, 2.0));
const sun = new THREE.DirectionalLight(0xfff5dd, 3.1);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 32;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x9bdfff, 1.0);
rim.position.set(8, 5, -7);
scene.add(rim);
// ------------------------------------------------------------
// Utilities and procedural textures.
// ------------------------------------------------------------
let seed = 34712;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function makeNoiseTexture(base, fleckA, fleckB, count, size = 256) {
const c = document.createElement("canvas");
c.width = c.height = size;
const ctx = c.getContext("2d");
ctx.fillStyle = base;
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < count; i++) {
const x = random() * size;
const y = random() * size;
const r = 0.4 + random() * 2.1;
ctx.globalAlpha = 0.12 + random() * 0.28;
ctx.fillStyle = random() > 0.5 ? fleckA : fleckB;
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2);
ctx.fill();
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3, 2);
return texture;
}
function box(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(start, end, radius, material, parent = scene, segments = 10) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
const soilTexture = makeNoiseTexture(
"#805437",
"#b78a61",
"#4e321f",
1500
);
const gravelTexture = makeNoiseTexture(
"#b7a27f",
"#e0d0ae",
"#79694e",
2200
);
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x9b704b,
map: soilTexture,
roughness: 1
});
const mulchMaterial = new THREE.MeshStandardMaterial({
color: 0x4e3927,
map: soilTexture,
roughness: 1
});
const gravelMaterial = new THREE.MeshStandardMaterial({
color: 0xc3ad88,
map: gravelTexture,
roughness: 0.95
});
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x73847f,
roughness: 0.88
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xc98d57,
roughness: 0.7
});
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0x355d68,
roughness: 0.36,
metalness: 0.18,
transparent: true,
opacity: 0.5,
depthWrite: false,
side: THREE.DoubleSide
});
const pipeRimMaterial = new THREE.MeshStandardMaterial({
color: 0x29464f,
roughness: 0.35,
metalness: 0.38
});
const rootMaterial = new THREE.MeshStandardMaterial({
color: 0x74472d,
roughness: 1
});
const leafMaterials = [
new THREE.MeshStandardMaterial({ color: 0x3f7750, roughness: 0.88 }),
new THREE.MeshStandardMaterial({ color: 0x5f9460, roughness: 0.88 }),
new THREE.MeshStandardMaterial({ color: 0x2f654b, roughness: 0.88 })
];
// ------------------------------------------------------------
// Ground and diorama base.
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xd7e2dd,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
scene.add(ground);
box(
9.8,
0.22,
4.65,
new THREE.MeshStandardMaterial({
color: 0x9cafaa,
roughness: 0.92
}),
0,
-0.25,
-1.45
);
box(9.25, 0.22, 0.72, stoneMaterial, 0, -0.04, -0.13);
box(9.55, 0.08, 0.9, cutMaterial, 0, -0.13, -0.13);
// ------------------------------------------------------------
// Masonry retaining wall with a large physical cutaway opening.
// ------------------------------------------------------------
const wall = new THREE.Group();
scene.add(wall);
const brickColors = [0x8d9993, 0x9aa49e, 0x7f8c87, 0xa2aaa4, 0x8f9b96];
const brickMaterials = brickColors.map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.94
})
);
const brickWidth = 1.02;
const brickHeight = 0.53;
const brickDepth = 0.88;
const rowStep = 0.58;
for (let row = 0; row < 5; row++) {
const y = 0.29 + row * rowStep;
const offset = row % 2 === 0 ? 0 : -brickWidth * 0.5;
for (let x = -4.35 + offset; x < 4.4; x += brickWidth) {
const center = x + brickWidth * 0.5;
// The center and upper section is removed to expose the pipe.
if (row >= 3 && Math.abs(center) < 3.05) continue;
const material = brickMaterials[Math.floor(random() * brickMaterials.length)];
box(brickWidth - 0.035, brickHeight - 0.035, brickDepth, material, center, y, -0.12, wall);
}
}
// Warm section edges make the cutaway explicit.
box(0.055, 1.35, 0.9, cutMaterial, -3.035, 2.38, -0.12, wall);
box(0.055, 1.35, 0.9, cutMaterial, 3.035, 2.38, -0.12, wall);
box(6.1, 0.045, 0.9, cutMaterial, 0, 1.79, -0.12, wall);
// ------------------------------------------------------------
// Soil section, drainage aggregate and geotextile.
// ------------------------------------------------------------
const soilWidth = 8.55;
const soilDepth = 3.12;
const soilZ = -2.08;
const soilSide = new THREE.MeshStandardMaterial({
color: 0x8f6545,
map: soilTexture,
roughness: 1
});
const soilFront = new THREE.MeshStandardMaterial({
color: 0x936744,
map: soilTexture,
roughness: 1
});
const soilBox = new THREE.Mesh(
new THREE.BoxGeometry(soilWidth, 1.55, soilDepth),
[
soilSide,
soilSide,
mulchMaterial,
soilSide,
soilFront,
soilSide
]
);
soilBox.position.set(0, 3.62, soilZ);
soilBox.castShadow = true;
soilBox.receiveShadow = true;
scene.add(soilBox);
const gravelBox = new THREE.Mesh(
new THREE.BoxGeometry(soilWidth, 0.63, soilDepth),
gravelMaterial
);
gravelBox.position.set(0, 2.53, soilZ);
gravelBox.castShadow = true;
gravelBox.receiveShadow = true;
scene.add(gravelBox);
box(
soilWidth,
0.035,
soilDepth,
new THREE.MeshStandardMaterial({
color: 0x56625b,
roughness: 1
}),
0,
2.86,
soilZ
);
// A narrow capstone marks the planted terrace edge.
box(
8.82,
0.16,
0.46,
new THREE.MeshStandardMaterial({
color: 0xb8b8a8,
roughness: 0.9
}),
0,
4.43,
-0.43
);
// Exposed aggregate at the section face.
const stoneGeometry = new THREE.DodecahedronGeometry(0.105, 0);
const aggregate = new THREE.InstancedMesh(
stoneGeometry,
new THREE.MeshStandardMaterial({
color: 0xcab794,
roughness: 1
}),
115
);
const dummy = new THREE.Object3D();
const aggregateColor = new THREE.Color();
for (let i = 0; i < 115; i++) {
dummy.position.set(
-4.0 + random() * 8.0,
2.28 + random() * 0.5,
-0.48 + random() * 0.055
);
dummy.rotation.set(random() * 3, random() * 3, random() * 3);
dummy.scale.set(
0.6 + random() * 0.9,
0.45 + random() * 0.75,
0.55 + random() * 0.65
);
dummy.updateMatrix();
aggregate.setMatrixAt(i, dummy.matrix);
aggregateColor.setHSL(
0.095 + random() * 0.035,
0.18 + random() * 0.12,
0.49 + random() * 0.17
);
aggregate.setColorAt(i, aggregateColor);
}
aggregate.castShadow = true;
aggregate.receiveShadow = true;
scene.add(aggregate);
// ------------------------------------------------------------
// Roots visible on the cut face.
// ------------------------------------------------------------
function makeRoot(points, radius = 0.018) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
const root = new THREE.Mesh(
new THREE.TubeGeometry(curve, 24, radius, 6, false),
rootMaterial
);
root.castShadow = true;
scene.add(root);
return root;
}
const rootGroups = [
{ x: -2.55, branches: 4 },
{ x: -0.65, branches: 5 },
{ x: 1.45, branches: 4 },
{ x: 3.0, branches: 3 }
];
for (const group of rootGroups) {
const x = group.x;
makeRoot([
[x, 4.32, -0.37],
[x + 0.04, 4.0, -0.36],
[x - 0.08, 3.65, -0.35],
[x + 0.03, 3.22, -0.34],
[x - 0.05, 2.89, -0.33]
], 0.025);
for (let b = 0; b < group.branches; b++) {
const spread = (b - (group.branches - 1) * 0.5) * 0.24;
const endY = 3.0 + random() * 0.65;
makeRoot([
[x + spread * 0.2, 3.7 + random() * 0.25, -0.36],
[x + spread * 0.55, endY + 0.18, -0.35],
[x + spread, endY, -0.34]
], 0.014);
}
}
// ------------------------------------------------------------
// Planted terrace.
// ------------------------------------------------------------
const flowerColors = [0xe58c70, 0xf0c75e, 0xd7a1d2];
function makeLeaf(x, y, z, angle, scale, material) {
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(1, 12, 7),
material
);
leaf.position.set(x, y, z);
leaf.scale.set(0.11 * scale, 0.34 * scale, 0.065 * scale);
leaf.rotation.z = angle;
leaf.rotation.x = 0.35;
leaf.castShadow = true;
scene.add(leaf);
}
function makeShrub(x, z, size = 1) {
const stemMaterial = leafMaterials[2];
cylinderBetween(
new THREE.Vector3(x, 4.39, z),
new THREE.Vector3(x + 0.04, 4.39 + 0.85 * size, z),
0.025 * size,
stemMaterial
);
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2 + random() * 0.25;
const radius = 0.2 * size;
const y = 4.55 * size + (i % 3) * 0.11 * size;
makeLeaf(
x + Math.cos(angle) * radius,
y,
z + Math.sin(angle) * radius,
Math.cos(angle) * 0.72,
size,
leafMaterials[i % leafMaterials.length]
);
}
}
function makeGrass(x, z, size = 1) {
for (let i = 0; i < 7; i++) {
const height = (0.42 + random() * 0.48) * size;
const blade = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.032, height, 5),
leafMaterials[i % 3]
);
blade.position.set(
x + (random() - 0.5) * 0.2,
4.39 + height * 0.5,
z + (random() - 0.5) * 0.18
);
blade.rotation.z = (random() - 0.5) * 0.42;
blade.rotation.x = (random() - 0.5) * 0.3;
blade.castShadow = true;
scene.add(blade);
}
}
function makeFlower(x, z, size = 1, colorIndex = 0) {
const height = 0.85 * size;
const stem = cylinderBetween(
new THREE.Vector3(x, 4.39, z),
new THREE.Vector3(x, 4.39 + height, z),
0.018,
leafMaterials[2]
);
stem.castShadow = true;
const petalMaterial = new THREE.MeshStandardMaterial({
color: flowerColors[colorIndex],
roughness: 0.72
});
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petal = new THREE.Mesh(
new THREE.SphereGeometry(1, 10, 6),
petalMaterial
);
petal.position.set(
x + Math.cos(angle) * 0.115 * size,
4.39 + height,
z + Math.sin(angle) * 0.115 * size
);
petal.scale.set(0.075 * size, 0.035 * size, 0.14 * size);
petal.rotation.y = -angle;
petal.castShadow = true;
scene.add(petal);
}
const center = new THREE.Mesh(
new THREE.SphereGeometry(0.065 * size, 12, 8),
new THREE.MeshStandardMaterial({ color: 0xf1bb3d, roughness: 0.65 })
);
center.position.set(x, 4.4 + height, z);
scene.add(center);
}
makeGrass(-3.15, -1.25, 1.2);
makeShrub(-2.35, -1.45, 1.12);
makeFlower(-1.55, -1.2, 1.0, 0);
makeGrass(-0.85, -2.25, 1.0);
makeShrub(-0.35, -1.4, 0.92);
makeFlower(0.35, -1.75, 0.9, 1);
makeGrass(1.0, -2.3, 1.2);
makeShrub(1.55, -1.3, 1.05);
makeFlower(2.15, -1.75, 1.05, 2);
makeGrass(2.8, -2.2, 1.0);
makeShrub(3.25, -1.45, 0.85);
// ------------------------------------------------------------
// Drainage pipe: horizontal collector, central elbow and outlet.
// ------------------------------------------------------------
const collectorLength = 7.55;
const collector = new THREE.Mesh(
new THREE.CylinderGeometry(0.175, 0.175, collectorLength, 28, 1, true),
pipeMaterial
);
collector.rotation.z = Math.PI / 2;
collector.position.set(0, 2.62, -0.18);
collector.renderOrder = 2;
scene.add(collector);
const collectorWater = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.052, collectorLength - 0.15, 12),
new THREE.MeshBasicMaterial({
color: 0x00c9ed,
transparent: true,
opacity: 0.28,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
collectorWater.rotation.z = Math.PI / 2;
collectorWater.position.set(0, 2.62, -0.18);
collectorWater.renderOrder = 3;
scene.add(collectorWater);
const outletCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 2.62, -0.18),
new THREE.Vector3(0, 2.61, 0.02),
new THREE.Vector3(0, 2.53, 0.25),
new THREE.Vector3(0, 2.29, 0.34),
new THREE.Vector3(0, 0.78, 0.34),
new THREE.Vector3(0, 0.56, 0.43)
]);
const outletPipe = new THREE.Mesh(
new THREE.TubeGeometry(outletCurve, 70, 0.175, 14, false),
pipeMaterial
);
outletPipe.renderOrder = 2;
scene.add(outletPipe);
const outletWaterCore = new THREE.Mesh(
new THREE.TubeGeometry(outletCurve, 70, 0.052, 8, false),
new THREE.MeshBasicMaterial({
color: 0x00d8f4,
transparent: true,
opacity: 0.42,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
outletWaterCore.renderOrder = 3;
scene.add(outletWaterCore);
const tee = new THREE.Mesh(
new THREE.SphereGeometry(0.205, 18, 12),
pipeRimMaterial
);
tee.position.set(0, 2.62, -0.18);
scene.add(tee);
function addPipeRing(x, y, z, axis) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.027, 8, 24),
pipeRimMaterial
);
ring.position.set(x, y, z);
if (axis === "x") ring.rotation.y = Math.PI / 2;
if (axis === "y") ring.rotation.x = Math.PI / 2;
ring.castShadow = true;
scene.add(ring);
}
addPipeRing(-2.85, 2.62, -0.18, "x");
addPipeRing(2.85, 2.62, -0.18, "x");
addPipeRing(0, 1.18, 0.34, "y");
addPipeRing(0, 0.66, 0.405, "y");
// Small dark perforations on the front of the collector.
const perforationMaterial = new THREE.MeshBasicMaterial({ color: 0x203a42 });
for (let x = -3.2; x <= 3.2; x += 0.72) {
const hole = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.055, 10),
perforationMaterial
);
hole.rotation.x = Math.PI / 2;
hole.position.set(x, 2.62, -0.006);
scene.add(hole);
}
// ------------------------------------------------------------
// Catch basin below the exposed outlet.
// ------------------------------------------------------------
const basin = new THREE.Mesh(
new THREE.CylinderGeometry(1.05, 1.16, 0.16, 48),
new THREE.MeshStandardMaterial({
color: 0x60736f,
roughness: 0.78
})
);
basin.position.set(0, -0.06, 0.43);
basin.castShadow = true;
basin.receiveShadow = true;
scene.add(basin);
const basinWater = new THREE.Mesh(
new THREE.CircleGeometry(0.88, 48),
new THREE.MeshBasicMaterial({
color: 0x08a9cb,
transparent: true,
opacity: 0.62,
depthWrite: false
})
);
basinWater.rotation.x = -Math.PI / 2;
basinWater.position.set(0, 0.026, 0.43);
scene.add(basinWater);
const ripples = [];
for (let i = 0; i < 3; i++) {
const ripple = new THREE.Mesh(
new THREE.TorusGeometry(0.25, 0.012, 6, 40),
new THREE.MeshBasicMaterial({
color: 0x82efff,
transparent: true,
opacity: 0.55,
depthWrite: false
})
);
ripple.rotation.x = Math.PI / 2;
ripple.position.set(0, 0.038, 0.43);
scene.add(ripple);
ripples.push(ripple);
}
// ------------------------------------------------------------
// Animated water.
// ------------------------------------------------------------
const waterMaterial = new THREE.MeshBasicMaterial({
color: 0x00d9f4,
transparent: true,
opacity: 0.88,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const waterGeometry = new THREE.SphereGeometry(0.055, 8, 6);
// Infiltration droplets shown along the exposed soil section.
const infiltrationDrops = [];
for (let i = 0; i < 34; i++) {
const mesh = new THREE.Mesh(waterGeometry, waterMaterial.clone());
const baseX = -3.75 + random() * 7.5;
const baseZ = -0.38 + random() * 0.035;
const offset = random();
mesh.material.opacity = 0.75;
scene.add(mesh);
infiltrationDrops.push({
mesh,
baseX,
baseZ,
offset,
speed: 0.085 + random() * 0.04
});
}
// Pipe flow beads.
const pipeDrops = [];
for (let i = 0; i < 28; i++) {
const mesh = new THREE.Mesh(waterGeometry, waterMaterial.clone());
mesh.scale.setScalar(0.78 + random() * 0.55);
scene.add(mesh);
pipeDrops.push({
mesh,
startX: -3.35 + random() * 6.7,
offset: random(),
speed: 0.12 + random() * 0.055
});
}
// Animated arrows through the drainage aggregate.
const arrows = [];
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x38e7ff,
transparent: true,
opacity: 0.78,
depthWrite: false
});
for (let i = 0; i < 13; i++) {
const group = new THREE.Group();
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.026, 0.02),
arrowMaterial
);
shaft.position.x = -0.04;
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.14, 8),
arrowMaterial
);
head.rotation.z = -Math.PI / 2;
head.position.x = 0.17;
group.add(shaft, head);
group.position.set(0, 2.37 + (i % 3) * 0.08, -0.355);
scene.add(group);
const start = i % 2 === 0
? -3.35 + random() * 1.4
: 1.1 + random() * 2.3;
group.rotation.y = start > 0 ? Math.PI : 0;
arrows.push({
group,
start,
offset: random(),
speed: 0.12 + random() * 0.06
});
}
// Rain above the planting.
const rainDrops = [];
const rainGeometry = new THREE.CylinderGeometry(0.012, 0.012, 0.17, 6);
for (let i = 0; i < 20; i++) {
const mesh = new THREE.Mesh(
rainGeometry,
new THREE.MeshBasicMaterial({
color: 0x55dff4,
transparent: true,
opacity: 0.45,
depthWrite: false
})
);
scene.add(mesh);
rainDrops.push({
mesh,
x: -3.6 + random() * 7.2,
z: -2.7 + random() * 2.0,
offset: random(),
speed: 0.35 + random() * 0.22
});
}
// Falling drops and small splashes from the outlet.
const fallingDrops = [];
for (let i = 0; i < 15; i++) {
const mesh = new THREE.Mesh(waterGeometry, waterMaterial.clone());
mesh.scale.set(0.72, 1.45, 0.72);
scene.add(mesh);
fallingDrops.push({
mesh,
offset: random(),
speed: 0.72 + random() * 0.36,
jitter: random() * Math.PI * 2
});
}
// ------------------------------------------------------------
// Screen-space labels anchored to the 3D scene.
// ------------------------------------------------------------
const labels = [
{
element: document.querySelector("#label-terrace"),
anchor: new THREE.Vector3(-2.55, 4.95, -1.45),
offset: new THREE.Vector2(-55, -15)
},
{
element: document.querySelector("#label-drainage"),
anchor: new THREE.Vector3(-3.55, 2.48, -0.45),
offset: new THREE.Vector2(-82, 22)
},
{
element: document.querySelector("#label-collector"),
anchor: new THREE.Vector3(-1.6, 2.62, -0.18),
offset: new THREE.Vector2(-36, -44)
},
{
element: document.querySelector("#label-wall"),
anchor: new THREE.Vector3(3.85, 1.15, 0.34),
offset: new THREE.Vector2(72, 18)
},
{
element: document.querySelector("#label-outlet"),
anchor: new THREE.Vector3(0.05, 0.62, 0.44),
offset: new THREE.Vector2(92, 12)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2;
label.element.style.display = visible ? "block" : "none";
const x = (projected.x * 0.5 + 0.5) * width + label.offset.x;
const y = (-projected.y * 0.5 + 0.5) * height + label.offset.y;
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
}
// ------------------------------------------------------------
// Animation loop.
// ------------------------------------------------------------
let paused = false;
let flowTime = 0;
const pauseButton = document.querySelector("#pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume flow" : "Pause flow";
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) flowTime += dt;
const t = flowTime;
// Infiltration through the root zone and into the aggregate.
for (const drop of infiltrationDrops) {
const p = (t * drop.speed + drop.offset) % 1;
let x;
let y;
let z;
if (p < 0.72) {
const q = p / 0.72;
x = drop.baseX + Math.sin(q * 8 + drop.offset * 10) * 0.035;
y = 4.28 - q * 1.39;
z = drop.baseZ;
} else {
const q = (p - 0.72) / 0.28;
x = THREE.MathUtils.lerp(drop.baseX, 0, q);
y = THREE.MathUtils.lerp(2.89, 2.62, q);
z = THREE.MathUtils.lerp(drop.baseZ, -0.18, q);
}
drop.mesh.position.set(x, y, z);
drop.mesh.material.opacity =
Math.sin(Math.PI * Math.min(1, Math.max(0, p))) * 0.8;
drop.mesh.scale.setScalar(0.75 + Math.sin(p * Math.PI) * 0.35);
}
// Beads travel through the collector and around the elbow.
for (const drop of pipeDrops) {
const p = (t * drop.speed + drop.offset) % 1;
let position;
if (p < 0.54) {
const q = p / 0.54;
position = new THREE.Vector3(
THREE.MathUtils.lerp(drop.startX, 0, q),
2.62,
-0.18
);
} else {
const q = (p - 0.54) / 0.46;
position = outletCurve.getPoint(q);
}
drop.mesh.position.copy(position);
drop.mesh.material.opacity = 0.82;
}
// Aggregate arrows move toward the collector.
for (const arrow of arrows) {
const p = (t * arrow.speed + arrow.offset) % 1;
arrow.group.position.x = arrow.start * (1 - p);
arrow.group.scale.setScalar(0.8 + Math.sin(p * Math.PI) * 0.25);
arrow.group.visible = p < 0.92;
}
// Rain.
for (const drop of rainDrops) {
const p = (t * drop.speed + drop.offset) % 1;
drop.mesh.position.set(
drop.x,
6.35 - p * 2.0,
drop.z
);
drop.mesh.material.opacity = Math.sin(p * Math.PI) * 0.45;
}
// Falling outlet water.
for (const drop of fallingDrops) {
const p = (t * drop.speed + drop.offset) % 1;
const spread = Math.sin(p * Math.PI) * 0.1;
drop.mesh.position.set(
Math.sin(drop.jitter + p * 8) * spread,
THREE.MathUtils.lerp(0.54, 0.035, p),
0.43 + Math.cos(drop.jitter + p * 7) * spread * 0.45
);
drop.mesh.material.opacity = (1 - p) * 0.78;
}
// Expanding ripples in the catch basin.
ripples.forEach((ripple, index) => {
const p = (t * 0.65 + index / ripples.length) % 1;
const scale = 0.55 + p * 2.0;
ripple.scale.setScalar(scale);
ripple.material.opacity = (1 - p) * 0.5;
});
updateLabels();
renderer.render(scene, camera);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```