Prompt specification
Build or customize the Three.js 3D scene "Courtyard roof drainage sequence" 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: Courtyard roof drainage sequence
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-roof-drainage-sequence-x2219
Scene Description Prompt:
Courtyard roof drainage sequence. Create a small courtyard building with roof valleys, gutters, downpipes, and a rain barrel. Trace water through connected elements and keep each outlet physically aligned. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (courtyard-roof-drainage-sequence-x2219):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Courtyard Roof Drainage</title>
<style>
:root {
--ink: #153039;
--muted: #60757b;
--panel: rgba(249, 247, 239, 0.9);
--line: rgba(21, 48, 57, 0.14);
--accent: #159fba;
--accent-dark: #08788f;
--shadow: 0 18px 48px rgba(18, 42, 49, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7e7;
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;
}
#ui {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.panel {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 1.02;
}
.description {
margin: 12px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.sequence {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.sequence span {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.45);
color: #496068;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.sequence i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 3px rgba(21, 159, 186, 0.12);
}
.help {
position: absolute;
right: 24px;
bottom: 24px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 12px;
background: rgba(249, 247, 239, 0.78);
box-shadow: 0 10px 30px rgba(18, 42, 49, 0.1);
color: #587077;
font-size: 11px;
line-height: 1.5;
text-align: right;
backdrop-filter: blur(12px);
}
.controls {
position: absolute;
bottom: 24px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 11px;
background: rgba(249, 247, 239, 0.9);
box-shadow: 0 8px 22px rgba(18, 42, 49, 0.12);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf7;
}
button.primary {
border-color: transparent;
background: var(--ink);
color: white;
}
#labels {
position: fixed;
inset: 0;
z-index: 8;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 10px 6px 6px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 999px;
background: rgba(250, 248, 241, 0.88);
box-shadow: 0 8px 24px rgba(18, 42, 49, 0.14);
color: #3f5960;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
transition:
color 180ms ease,
background 180ms ease,
box-shadow 180ms ease;
}
.world-label b {
display: grid;
width: 21px;
height: 21px;
place-items: center;
border-radius: 50%;
background: #dce8e8;
color: #48656d;
font-size: 10px;
transition:
color 180ms ease,
background 180ms ease;
}
.world-label.active {
background: rgba(9, 120, 143, 0.94);
color: white;
box-shadow: 0 10px 28px rgba(9, 120, 143, 0.28);
}
.world-label.active b {
background: white;
color: var(--accent-dark);
}
@media (max-width: 700px) {
.panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px;
}
.description {
display: none;
}
.sequence {
margin-top: 12px;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
}
.help {
display: none;
}
.world-label {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="labels" aria-hidden="true">
<div class="world-label" data-stage="0"><b>1</b>Roof valley</div>
<div class="world-label" data-stage="1"><b>2</b>Gutter</div>
<div class="world-label" data-stage="2"><b>3</b>Downpipe</div>
<div class="world-label" data-stage="3"><b>4</b>Rain barrel</div>
</div>
<div id="ui">
<section class="panel">
<div class="eyebrow">Water system / low-poly study</div>
<h1>Courtyard Roof Drainage</h1>
<p class="description">
A continuous drainage route follows the intersecting roof valley into
an open gutter, down the aligned downpipe, through the outlet elbow,
and into the rain barrel.
</p>
<div class="sequence">
<span><i></i>Valley</span>
<span><i></i>Gutter</span>
<span><i></i>Downpipe</span>
<span><i></i>Barrel</span>
</div>
</section>
<div class="controls">
<button id="flowButton" class="primary">Pause Flow</button>
<button id="isoButton">Isometric View</button>
<button id="planButton">Plan View</button>
</div>
<div class="help">
Drag to orbit · Shift/right-drag to pan<br>
Scroll or pinch to zoom
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7e7);
scene.fog = new THREE.Fog(0xdce7e7, 30, 62);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: 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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly courtyard building and roof drainage sequence"
);
document.body.prepend(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xeaf8fb, 0x7f8066, 2.15));
const sun = new THREE.DirectionalLight(0xfff3d7, 3.2);
sun.position.set(-12, 20, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9e3ed, 0.8);
fill.position.set(12, 8, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
...options
});
const M = {
ground: material(0x8ea48c),
grass: material(0x9eb296),
wall: material(0xd8cbb2),
wallShade: material(0xc4b59b),
trim: material(0xa7967c),
roof: material(0x355c65, {
roughness: 0.7,
metalness: 0.18,
side: THREE.DoubleSide
}),
roofDark: material(0x294951, {
roughness: 0.66,
metalness: 0.22,
side: THREE.DoubleSide
}),
gutter: material(0x35545c, {
roughness: 0.42,
metalness: 0.62
}),
metal: material(0x536c70, {
roughness: 0.38,
metalness: 0.7
}),
glass: material(0x79a9b3, {
roughness: 0.2,
metalness: 0.28,
emissive: 0x183c43,
emissiveIntensity: 0.18
}),
frame: material(0x4a4035),
wood: material(0x8b6847),
planter: material(0xa88d70),
soil: material(0x4d4034),
leaf: material(0x56795a),
leafLight: material(0x72916b),
trunk: material(0x70513a),
barrel: material(0x426f69, {
roughness: 0.58,
metalness: 0.12,
side: THREE.DoubleSide
}),
water: material(0x25a9c0, {
roughness: 0.18,
metalness: 0.12,
transparent: true,
opacity: 0.88,
emissive: 0x075d72,
emissiveIntensity: 0.48,
side: THREE.DoubleSide
}),
flow: new THREE.MeshBasicMaterial({
color: 0x69e4ff,
transparent: true,
opacity: 0.96
}),
arrow: new THREE.MeshBasicMaterial({
color: 0x0b91ad,
transparent: true,
opacity: 0.82
})
};
function box(w, h, d, x, y, z, mat, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinder(rTop, rBottom, h, x, y, z, mat, segments = 10) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, mat, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function quad(points, mat) {
const geometry = new THREE.BufferGeometry();
const positions = [];
for (const index of [0, 1, 2, 0, 2, 3]) {
const p = points[index];
positions.push(p.x, p.y, p.z);
}
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function triangle(points, mat) {
const geometry = new THREE.BufferGeometry();
const positions = points.flatMap((p) => [p.x, p.y, p.z]);
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addLine(points, color, opacity = 1, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const mat = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.2,
gapSize: 0.12
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const line = new THREE.Line(geometry, mat);
if (dashed) line.computeLineDistances();
scene.add(line);
return line;
}
// -------------------------------------------------------------------------
// Courtyard ground and paving
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
M.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const courtyardBase = box(
10.6,
0.08,
6.4,
0,
-0.015,
1.1,
material(0xbbb7a7),
false
);
const paverGeometry = new THREE.BoxGeometry(0.94, 0.055, 0.94);
const paverMaterial = material(0xffffff, { roughness: 0.95 });
const paverCount = 10 * 6;
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
paverCount
);
const dummy = new THREE.Object3D();
const paverColors = [
new THREE.Color(0xc9c2af),
new THREE.Color(0xb9b4a5),
new THREE.Color(0xd3cbb8),
new THREE.Color(0xc3bca9)
];
let paverIndex = 0;
for (let row = 0; row < 6; row++) {
for (let column = 0; column < 10; column++) {
dummy.position.set(
-4.65 + column,
0.035,
-1.55 + row
);
dummy.rotation.y =
((row + column) % 2) * 0.008 - 0.004;
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
pavers.setColorAt(
paverIndex,
paverColors[(row * 3 + column) % paverColors.length]
);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
pavers.instanceColor.needsUpdate = true;
pavers.receiveShadow = true;
scene.add(pavers);
// -------------------------------------------------------------------------
// U-shaped courtyard building
// -------------------------------------------------------------------------
// Rear wing.
box(18.4, 4.4, 4.5, 0, 2.2, -4.25, M.wall);
box(18.55, 0.16, 4.62, 0, 4.34, -4.25, M.wallShade);
// Side wings. Their inner faces leave a courtyard between x = -5.2 and 5.2.
box(3.8, 4.4, 5.8, 7.3, 2.2, 0.9, M.wall);
box(3.8, 4.4, 5.8, -7.3, 2.2, 0.9, M.wall);
box(3.95, 0.16, 5.95, 7.3, 4.34, 0.9, M.wallShade);
box(3.95, 0.16, 5.95, -7.3, 4.34, 0.9, M.wallShade);
// Front gable end walls.
triangle(
[
new THREE.Vector3(5.4, 4.4, 3.81),
new THREE.Vector3(9.2, 4.4, 3.81),
new THREE.Vector3(7.2, 6.2, 3.81)
],
M.wall
);
triangle(
[
new THREE.Vector3(-9.2, 4.4, 3.81),
new THREE.Vector3(-5.4, 4.4, 3.81),
new THREE.Vector3(-7.2, 6.2, 3.81)
],
M.wall
);
// -------------------------------------------------------------------------
// Roof planes
//
// The right wing's west roof plane intersects the rear roof's south plane
// along the diagonal valley from H = (7.2, 6.2, -4) to
// V = (5.2, 4.4, -2).
// -------------------------------------------------------------------------
const H = new THREE.Vector3(7.2, 6.2, -4.0);
const V = new THREE.Vector3(5.2, 4.4, -2.0);
quad(
[
new THREE.Vector3(-9.2, 4.4, -6.5),
new THREE.Vector3(9.2, 4.4, -6.5),
new THREE.Vector3(9.2, 6.2, -4.0),
new THREE.Vector3(-9.2, 6.2, -4.0)
],
M.roofDark
);
quad(
[
new THREE.Vector3(-9.2, 6.2, -4.0),
new THREE.Vector3(9.2, 6.2, -4.0),
new THREE.Vector3(9.2, 4.4, -2.0),
new THREE.Vector3(-9.2, 4.4, -2.0)
],
M.roof
);
// Right wing roof.
quad(
[
new THREE.Vector3(5.2, 4.4, -4.0),
new THREE.Vector3(7.2, 6.2, -4.0),
new THREE.Vector3(7.2, 6.2, 4.2),
new THREE.Vector3(5.2, 4.4, 4.2)
],
M.roof
);
quad(
[
new THREE.Vector3(7.2, 6.2, -4.0),
new THREE.Vector3(9.2, 4.4, -4.0),
new THREE.Vector3(9.2, 4.4, 4.2),
new THREE.Vector3(7.2, 6.2, 4.2)
],
M.roofDark
);
// Left wing roof.
quad(
[
new THREE.Vector3(-9.2, 4.4, -4.0),
new THREE.Vector3(-7.2, 6.2, -4.0),
new THREE.Vector3(-7.2, 6.2, 4.2),
new THREE.Vector3(-9.2, 4.4, 4.2)
],
M.roofDark
);
quad(
[
new THREE.Vector3(-7.2, 6.2, -4.0),
new THREE.Vector3(-5.2, 4.4, -4.0),
new THREE.Vector3(-5.2, 4.4, 4.2),
new THREE.Vector3(-7.2, 6.2, 4.2)
],
M.roof
);
// Roof fascia and ridge caps.
box(18.4, 0.16, 0.12, 0, 4.36, -2.0, M.trim);
box(18.4, 0.16, 0.12, 0, 4.36, -6.5, M.trim);
box(0.12, 0.16, 8.2, 5.2, 4.36, 0.1, M.trim);
box(0.12, 0.16, 8.2, 9.2, 4.36, 0.1, M.trim);
box(0.12, 0.16, 8.2, -5.2, 4.36, 0.1, M.trim);
box(0.12, 0.16, 8.2, -9.2, 4.36, 0.1, M.trim);
box(18.3, 0.13, 0.18, 0, 6.25, -4, M.roofDark);
box(0.18, 0.13, 8.25, 7.2, 6.25, 0.1, M.roofDark);
box(0.18, 0.13, 8.25, -7.2, 6.25, 0.1, M.roofDark);
// Subtle roof seams.
for (let x = -8.4; x <= 8.4; x += 1.2) {
addLine(
[
new THREE.Vector3(x, 6.225, -4),
new THREE.Vector3(x, 4.425, -2)
],
0x789196,
0.24
);
addLine(
[
new THREE.Vector3(x, 6.225, -4),
new THREE.Vector3(x, 4.425, -6.5)
],
0x789196,
0.2
);
}
for (let z = -3.6; z <= 4.0; z += 1) {
addLine(
[
new THREE.Vector3(5.225, 4.425, z),
new THREE.Vector3(7.175, 6.225, z)
],
0x789196,
0.22
);
addLine(
[
new THREE.Vector3(7.225, 6.225, z),
new THREE.Vector3(9.175, 4.425, z)
],
0x789196,
0.22
);
}
// Dark channel visually identifies the exact roof valley.
const valleyCurve = new THREE.CatmullRomCurve3([
H.clone(),
V.clone()
]);
const valleyChannel = new THREE.Mesh(
new THREE.TubeGeometry(valleyCurve, 16, 0.045, 5, false),
M.roofDark
);
valleyChannel.castShadow = true;
scene.add(valleyChannel);
// -------------------------------------------------------------------------
// Windows, doors, and facade details
// -------------------------------------------------------------------------
function windowOnZ(x, y, z, width = 1.05, height = 1.35) {
box(
width + 0.14,
height + 0.14,
0.1,
x,
y,
z,
M.frame,
false
);
box(width, height, 0.115, x, y, z + 0.018, M.glass, false);
box(0.045, height, 0.13, x, y, z + 0.035, M.frame, false);
box(width, 0.045, 0.13, x, y, z + 0.035, M.frame, false);
}
function windowOnX(x, y, z, width = 1.05, height = 1.35) {
box(
0.1,
height + 0.14,
width + 0.14,
x,
y,
z,
M.frame,
false
);
box(0.115, height, width, x + 0.018, y, z, M.glass, false);
box(
0.13,
height,
0.045,
x + 0.035,
y,
z,
M.frame,
false
);
box(
0.13,
0.045,
width,
x + 0.035,
y,
z,
M.frame,
false
);
}
for (const x of [-3.2, -0.7, 1.8, 3.7]) {
windowOnZ(x, 2.35, -1.94, 1.05, 1.45);
}
windowOnX(5.34, 2.35, -0.7, 1.05, 1.4);
windowOnX(5.34, 2.35, 0.9, 1.05, 1.4);
windowOnX(-5.34, 2.35, -0.7, 1.05, 1.4);
windowOnX(-5.34, 2.35, 0.9, 1.05, 1.4);
// Courtyard-side door on the right wing.
box(0.12, 2.45, 1.08, 5.31, 1.225, 2.45, M.frame, false);
box(0.135, 2.28, 0.91, 5.285, 1.14, 2.45, M.wood, false);
box(0.16, 0.07, 0.07, 5.21, 1.15, 2.72, M.metal, false);
// Low wall caps and door threshold.
box(0.16, 0.12, 5.85, 5.32, 4.29, 0.9, M.trim);
box(0.16, 0.12, 5.85, -5.32, 4.29, 0.9, M.trim);
box(0.38, 0.12, 1.18, 5.25, 0.07, 2.45, M.trim, false);
// -------------------------------------------------------------------------
// Gutter, outlet, downpipe, elbow, and barrel
// -------------------------------------------------------------------------
// Open U-shaped gutter. Its rear end is exactly below the valley outlet.
const gutterX = 5.2;
const gutterStart = -2.0;
const gutterEnd = 4.15;
const gutterLength = gutterEnd - gutterStart;
const gutterCenter = (gutterStart + gutterEnd) / 2;
box(
0.44,
0.08,
gutterLength,
gutterX,
4.075,
gutterCenter,
M.gutter
);
box(
0.07,
0.25,
gutterLength,
gutterX - 0.185,
4.18,
gutterCenter,
M.gutter
);
box(
0.07,
0.25,
gutterLength,
gutterX + 0.185,
4.18,
gutterCenter,
M.gutter
);
// Gutter brackets.
for (const z of [-1.2, 0.8, 2.8]) {
box(0.12, 0.09, 0.12, gutterX, 3.99, z, M.metal);
box(
0.54,
0.055,
0.08,
gutterX,
4.01,
z,
M.metal,
false
);
}
// Small funnel where the valley outlet enters the gutter.
quad(
[
new THREE.Vector3(5.04, 4.43, -2.02),
new THREE.Vector3(5.36, 4.43, -2.02),
new THREE.Vector3(5.35, 4.13, -1.82),
new THREE.Vector3(5.05, 4.13, -1.82)
],
M.gutter
);
// The vertical downpipe is directly below the front end of the gutter.
const pipeX = 5.2;
const pipeZ = 4.0;
cylinderBetween(
new THREE.Vector3(pipeX, 4.08, pipeZ),
new THREE.Vector3(pipeX, 1.72, pipeZ),
0.105,
M.gutter,
9
);
// Gutter outlet shoe and pipe collars.
box(0.36, 0.12, 0.34, pipeX, 4.06, pipeZ, M.gutter);
for (const y of [3.58, 2.48]) {
cylinder(
0.13,
0.13,
0.1,
pipeX,
y,
pipeZ,
M.metal,
9
);
box(
0.25,
0.06,
0.08,
pipeX + 0.12,
y,
pipeZ,
M.metal,
false
);
}
// Horizontal elbow turns toward the barrel.
cylinderBetween(
new THREE.Vector3(pipeX, 1.72, pipeZ),
new THREE.Vector3(3.85, 1.72, pipeZ),
0.105,
M.gutter,
9
);
// Final nozzle enters the open barrel below the rim.
cylinderBetween(
new THREE.Vector3(3.85, 1.72, pipeZ),
new THREE.Vector3(3.85, 1.19, pipeZ),
0.105,
M.gutter,
9
);
const elbowJoint = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 1),
M.gutter
);
elbowJoint.position.set(pipeX, 1.72, pipeZ);
elbowJoint.castShadow = true;
scene.add(elbowJoint);
// Low-poly open rain barrel.
const barrelX = 3.85;
const barrelZ = 4.0;
const barrelBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.73, 0.65, 1.35, 12, 1, true),
M.barrel
);
barrelBody.position.set(barrelX, 0.795, barrelZ);
barrelBody.castShadow = true;
barrelBody.receiveShadow = true;
scene.add(barrelBody);
const barrelBottom = cylinder(
0.65,
0.65,
0.07,
barrelX,
0.135,
barrelZ,
M.barrel,
12
);
barrelBottom.castShadow = false;
for (const y of [0.42, 1.1]) {
const band = new THREE.Mesh(
new THREE.TorusGeometry(0.69, 0.032, 4, 12),
M.metal
);
band.rotation.x = Math.PI / 2;
band.position.set(barrelX, y, barrelZ);
band.castShadow = true;
scene.add(band);
}
const barrelRim = new THREE.Mesh(
new THREE.TorusGeometry(0.71, 0.065, 5, 12),
M.metal
);
barrelRim.rotation.x = Math.PI / 2;
barrelRim.position.set(barrelX, 1.45, barrelZ);
barrelRim.castShadow = true;
scene.add(barrelRim);
const barrelWater = new THREE.Mesh(
new THREE.CircleGeometry(0.625, 16),
M.water
);
barrelWater.rotation.x = -Math.PI / 2;
barrelWater.position.set(barrelX, 1.12, barrelZ);
barrelWater.receiveShadow = true;
scene.add(barrelWater);
// Barrel tap.
cylinderBetween(
new THREE.Vector3(barrelX, 0.58, barrelZ + 0.55),
new THREE.Vector3(barrelX, 0.58, barrelZ + 0.98),
0.055,
M.metal,
8
);
box(
0.055,
0.055,
0.28,
barrelX,
0.58,
barrelZ + 0.84,
M.metal,
false
);
box(
0.3,
0.05,
0.08,
barrelX,
0.72,
barrelZ + 0.78,
M.metal,
false
);
// -------------------------------------------------------------------------
// Courtyard furnishings
// -------------------------------------------------------------------------
function planter(x, z, width = 1.5) {
box(width, 0.42, 0.72, x, 0.23, z, M.planter);
box(width - 0.14, 0.045, 0.58, x, 0.46, z, M.soil, false);
for (let i = 0; i < 3; i++) {
const shrub = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.28 + i * 0.025, 0),
i % 2 ? M.leaf : M.leafLight
);
shrub.position.set(
x + (i - 1) * width * 0.25,
0.7,
z + (i % 2 ? 0.08 : -0.05)
);
shrub.scale.y = 0.85;
shrub.castShadow = true;
scene.add(shrub);
}
}
planter(-3.2, -1.25, 1.7);
planter(1.7, -1.25, 1.55);
// Low-poly courtyard tree.
cylinder(0.15, 0.21, 2.15, -3.35, 1.08, 2.55, M.trunk, 7);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.08, 1),
M.leaf
);
crown.position.set(-3.35, 2.65, 2.55);
crown.scale.set(1, 1.13, 0.94);
crown.castShadow = true;
scene.add(crown);
const crownLight = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.65, 0),
M.leafLight
);
crownLight.position.set(-3.8, 2.92, 2.35);
crownLight.castShadow = true;
scene.add(crownLight);
// Bench.
box(2.0, 0.12, 0.5, 0, 0.75, 3.15, M.wood);
box(2.0, 0.48, 0.1, 0, 1.08, 3.38, M.wood);
box(0.12, 0.72, 0.42, -0.78, 0.36, 3.15, M.metal);
box(0.12, 0.72, 0.42, 0.78, 0.36, 3.15, M.metal);
// -------------------------------------------------------------------------
// Continuous water route
// -------------------------------------------------------------------------
const flowPoints = [
new THREE.Vector3(7.2, 6.29, -4.0),
new THREE.Vector3(5.2, 4.49, -2.0),
new THREE.Vector3(5.2, 4.18, -2.0),
new THREE.Vector3(5.2, 4.16, 3.83),
new THREE.Vector3(5.2, 4.02, 4.0),
new THREE.Vector3(5.2, 1.74, 4.0),
new THREE.Vector3(3.85, 1.70, 4.0),
new THREE.Vector3(3.85, 1.18, 4.0)
];
const segmentLengths = [];
const cumulativeDistances = [0];
let totalFlowLength = 0;
for (let i = 0; i < flowPoints.length - 1; i++) {
const length = flowPoints[i].distanceTo(flowPoints[i + 1]);
segmentLengths.push(length);
totalFlowLength += length;
cumulativeDistances.push(totalFlowLength);
}
function sampleFlow(progress) {
const distance =
THREE.MathUtils.euclideanModulo(progress, 1) * totalFlowLength;
let segment = segmentLengths.length - 1;
for (let i = 0; i < segmentLengths.length; i++) {
if (distance <= cumulativeDistances[i + 1]) {
segment = i;
break;
}
}
const localDistance = distance - cumulativeDistances[segment];
const t = THREE.MathUtils.clamp(
localDistance / segmentLengths[segment],
0,
1
);
const position = new THREE.Vector3().lerpVectors(
flowPoints[segment],
flowPoints[segment + 1],
t
);
const tangent = new THREE.Vector3()
.subVectors(flowPoints[segment + 1], flowPoints[segment])
.normalize();
return { position, tangent, segment };
}
// A fine dashed trace remains visible beneath the moving droplets.
addLine(flowPoints, 0x4bd4e8, 0.58, true);
// Static directional arrows communicate the route.
const arrowGeometry = new THREE.ConeGeometry(0.095, 0.3, 5);
const up = new THREE.Vector3(0, 1, 0);
for (const progress of [0.065, 0.19, 0.33, 0.49, 0.63, 0.77, 0.91]) {
const sample = sampleFlow(progress);
const arrow = new THREE.Mesh(arrowGeometry, M.arrow);
arrow.position.copy(sample.position);
arrow.quaternion.setFromUnitVectors(up, sample.tangent);
scene.add(arrow);
}
// Moving low-poly droplets.
const dropletGeometry = new THREE.ConeGeometry(0.067, 0.23, 5);
const dropletCount = 22;
const droplets = [];
for (let i = 0; i < dropletCount; i++) {
const droplet = new THREE.Mesh(dropletGeometry, M.flow);
droplet.castShadow = false;
scene.add(droplet);
droplets.push(droplet);
}
// Small ripple at the barrel inlet.
const ripple = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.016, 4, 16),
new THREE.MeshBasicMaterial({
color: 0x8af1ff,
transparent: true,
opacity: 0.7
})
);
ripple.rotation.x = Math.PI / 2;
ripple.position.set(barrelX, 1.145, barrelZ);
scene.add(ripple);
// -------------------------------------------------------------------------
// Rain over the roof valley
// -------------------------------------------------------------------------
const rainCount = 42;
const rainData = [];
const rainPositions = new Float32Array(rainCount * 6);
for (let i = 0; i < rainCount; i++) {
rainData.push({
x: 5.35 + Math.random() * 3.55,
y: 6.3 + Math.random() * 3.2,
z: -4.35 + Math.random() * 3.25,
speed: 4.6 + Math.random() * 2.1
});
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rain = new THREE.LineSegments(
rainGeometry,
new THREE.LineBasicMaterial({
color: 0x77bdcf,
transparent: true,
opacity: 0.42
})
);
rain.frustumCulled = false;
scene.add(rain);
function roofHeightAt(x) {
return 6.2 - 0.9 * Math.abs(x - 7.2);
}
function updateRain(delta) {
const positions = rainGeometry.attributes.position.array;
for (let i = 0; i < rainCount; i++) {
const drop = rainData[i];
drop.y -= drop.speed * delta;
drop.x += delta * 0.16;
if (
drop.y < roofHeightAt(drop.x) + 0.08 ||
drop.x > 9.0
) {
drop.x = 5.3 + Math.random() * 3.55;
drop.y = 7.4 + Math.random() * 2.5;
drop.z = -4.35 + Math.random() * 3.25;
}
const offset = i * 6;
positions[offset] = drop.x;
positions[offset + 1] = drop.y;
positions[offset + 2] = drop.z;
positions[offset + 3] = drop.x - 0.025;
positions[offset + 4] = drop.y + 0.34;
positions[offset + 5] = drop.z;
}
rainGeometry.attributes.position.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelData = [
{
element: document.querySelector('[data-stage="0"]'),
position: new THREE.Vector3(6.25, 5.75, -3.05)
},
{
element: document.querySelector('[data-stage="1"]'),
position: new THREE.Vector3(5.45, 4.62, 1.1)
},
{
element: document.querySelector('[data-stage="2"]'),
position: new THREE.Vector3(5.38, 2.78, 4.02)
},
{
element: document.querySelector('[data-stage="3"]'),
position: new THREE.Vector3(3.85, 1.85, 4.05)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelData) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
label.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Camera controls implemented without addons
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, 2.0, -0.6);
const spherical = new THREE.Spherical(22, 1.02, 0.72);
const pointerPositions = new Map();
let activePointer = null;
let previousX = 0;
let previousY = 0;
let panning = false;
let lastPinchDistance = 0;
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.12,
1.45
);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
9,
36
);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function setIsometricView() {
target.set(0, 2.0, -0.6);
spherical.set(22, 1.02, 0.72);
updateCamera();
}
function setPlanView() {
target.set(0, 0.7, -0.65);
spherical.set(24, 0.13, 0.0);
updateCamera();
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerPositions.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
panning =
event.button === 2 ||
event.shiftKey ||
event.ctrlKey;
if (pointerPositions.size === 2) {
const [a, b] = [...pointerPositions.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerPositions.has(event.pointerId)) return;
pointerPositions.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerPositions.size === 2) {
const [a, b] = [...pointerPositions.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
spherical.radius *=
lastPinchDistance / Math.max(distance, 1);
}
lastPinchDistance = distance;
updateCamera();
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const upVector = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = spherical.radius / window.innerHeight;
target
.addScaledVector(right, -dx * panScale)
.addScaledVector(upVector, dy * panScale);
target.x = THREE.MathUtils.clamp(target.x, -8, 8);
target.y = THREE.MathUtils.clamp(target.y, 0.4, 6);
target.z = THREE.MathUtils.clamp(target.z, -6, 6);
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
}
updateCamera();
});
function releasePointer(event) {
pointerPositions.delete(event.pointerId);
if (activePointer === event.pointerId) {
activePointer = null;
panning = false;
}
if (pointerPositions.size < 2) {
lastPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
document.getElementById("isoButton").addEventListener(
"click",
setIsometricView
);
document.getElementById("planButton").addEventListener(
"click",
setPlanView
);
// -------------------------------------------------------------------------
// Flow controls and animation
// -------------------------------------------------------------------------
let flowRunning = true;
let flowTime = 0;
const flowButton = document.getElementById("flowButton");
flowButton.addEventListener("click", () => {
flowRunning = !flowRunning;
flowButton.textContent = flowRunning
? "Pause Flow"
: "Resume Flow";
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (flowRunning) {
flowTime += delta;
}
updateRain(delta);
updateCamera();
const tracer = sampleFlow(flowTime * 0.066);
for (let i = 0; i < dropletCount; i++) {
const progress =
(flowTime * 0.066 + i / dropletCount) % 1;
const sample = sampleFlow(progress);
const droplet = droplets[i];
droplet.position.copy(sample.position);
droplet.quaternion.setFromUnitVectors(up, sample.tangent);
droplet.scale.setScalar(0.86 + (i % 3) * 0.06);
}
// Highlight the label corresponding to the current tracer location.
const activeStage =
tracer.segment <= 1
? 0
: tracer.segment <= 3
? 1
: tracer.segment <= 5
? 2
: 3;
for (const label of labelData) {
const stage = Number(label.element.dataset.stage);
label.element.classList.toggle("active", stage === activeStage);
}
const ripplePhase = (flowTime * 1.35) % 1;
ripple.scale.setScalar(0.75 + ripplePhase * 2.5);
ripple.material.opacity = 0.72 * (1 - ripplePhase);
const waterPulse = 1 + Math.sin(flowTime * 4.2) * 0.018;
barrelWater.scale.setScalar(waterPulse);
updateLabels();
renderer.render(scene, camera);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateCamera();
</script>
</body>
</html>
```