Prompt specification
Build or customize the Three.js 3D scene "Roof gutter and tank connection" 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: Roof gutter and tank connection
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/roof-gutter-and-tank-connection-x1097
Scene Description Prompt:
A voxel shed roof, gutter, downpipe, covered rainwater tank, and overflow form one continuous route. Three.js from cdnjs, one HTML file.
Working Three.js Starter (roof-gutter-and-tank-connection-x1097):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Continuous Rainwater Route</title>
<style>
:root {
--ink: #173a3b;
--muted: #607879;
--panel: rgba(250, 253, 250, 0.91);
--line: rgba(23, 58, 59, 0.13);
--aqua: #22b9cf;
--aqua-dark: #087f92;
--orange: #ef9d45;
--shadow: 0 18px 50px rgba(20, 55, 55, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7efec;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 22px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: var(--aqua-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--aqua);
box-shadow: 0 0 0 5px rgba(34, 185, 207, 0.12);
content: "";
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 38px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.intro {
margin: 12px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.route-list {
display: grid;
gap: 8px;
margin: 0;
padding: 0;
list-style: none;
}
.route-list li {
display: flex;
align-items: center;
gap: 10px;
color: #385758;
font-size: 12px;
font-weight: 650;
}
.step {
display: grid;
width: 24px;
height: 24px;
flex: 0 0 auto;
place-items: center;
border: 1px solid rgba(34, 185, 207, 0.24);
border-radius: 8px;
background: rgba(34, 185, 207, 0.08);
color: var(--aqua-dark);
font-size: 10px;
font-weight: 800;
}
.status {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 17px;
padding: 11px 12px;
border-radius: 12px;
background: rgba(23, 58, 59, 0.055);
color: #4b6667;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.status strong {
color: var(--aqua-dark);
}
.status-dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 6px;
border-radius: 50%;
background: var(--aqua);
box-shadow: 0 0 0 4px rgba(34, 185, 207, 0.12);
animation: pulse 1.7s ease-in-out infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 7px rgba(34, 185, 207, 0.03);
}
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: min(570px, calc(100vw - 44px));
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 17px;
background: rgba(250, 253, 250, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
user-select: none;
}
button {
min-height: 36px;
padding: 0 13px;
border: 0;
border-radius: 10px;
background: rgba(23, 58, 59, 0.075);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(34, 185, 207, 0.13);
transform: translateY(-1px);
}
button[aria-pressed="true"] {
background: var(--ink);
color: white;
}
.speed {
display: flex;
min-width: 164px;
align-items: center;
gap: 10px;
padding: 0 10px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
}
input[type="range"] {
width: 95px;
accent-color: var(--aqua-dark);
cursor: pointer;
}
.hint {
position: fixed;
right: 24px;
top: 24px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 10px;
background: rgba(250, 253, 250, 0.72);
color: rgba(23, 58, 59, 0.63);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
pointer-events: none;
backdrop-filter: blur(12px);
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
background: rgba(250, 253, 250, 0.88);
box-shadow: 0 8px 24px rgba(20, 55, 55, 0.13);
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.025em;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(12px);
}
.label::before {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--aqua);
content: "";
}
.label.overflow::before {
background: var(--orange);
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
border-radius: 17px;
}
.intro,
.route-list,
.hint {
display: none;
}
h1 {
max-width: 220px;
font-size: 26px;
}
.status {
margin-top: 12px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
max-width: none;
}
button {
padding: 0 10px;
}
.speed {
min-width: 140px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels"></div>
<aside class="panel">
<div class="eyebrow">Rainwater system / interactive model</div>
<h1>One continuous route.</h1>
<p class="intro">
Rain lands on the voxel roof, enters the gutter, travels through the
downpipe, fills the covered tank, and exits through the overflow.
</p>
<ol class="route-list">
<li><span class="step">01</span> Stepped voxel shed roof</li>
<li><span class="step">02</span> Open collection gutter</li>
<li><span class="step">03</span> Connected downpipe</li>
<li><span class="step">04</span> Covered storage tank</li>
<li><span class="step">05</span> Active overflow outlet</li>
</ol>
<div class="status">
<span><span class="status-dot"></span>Tank 82% full</span>
<strong>Overflow active</strong>
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
<nav class="controls" aria-label="Scene controls">
<button id="rainButton" aria-pressed="true">Rain on</button>
<button id="flowButton" aria-pressed="true">Flow on</button>
<button id="cutawayButton" aria-pressed="false">Cutaway</button>
<button id="labelsButton" aria-pressed="true">Labels</button>
<button id="resetButton">Reset view</button>
<label class="speed">
Flow
<input id="speed" type="range" min="0.25" max="2.5" step="0.05" value="1">
</label>
</nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------------
// Renderer, scene and camera
// ------------------------------------------------------------------
const container = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7efec);
scene.fog = new THREE.Fog(0xe7efec, 18, 36);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
container.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf5fbff, 0x6d8068, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff6df, 3.2);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaedce3, 0.8);
fill.position.set(8, 5, -7);
scene.add(fill);
// ------------------------------------------------------------------
// Materials and helpers
// ------------------------------------------------------------------
const palette = {
grass: 0x91ad82,
grassDark: 0x6f8e69,
soil: 0xa9a38d,
paving: 0xbfc5bb,
pavingDark: 0xaab2a7,
wood: 0x9b6a46,
woodLight: 0xb98559,
woodDark: 0x744b35,
roof: [0xa85839, 0xb96743, 0xc7774e, 0x934c34],
zinc: 0x9baead,
zincDark: 0x536b6d,
tank: 0x247e86,
tankDark: 0x155862,
water: 0x21c4df,
orange: 0xef9d45,
glass: 0x9dd9e1
};
const mat = (color, roughness = 0.75, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const materials = {
grass: mat(palette.grass),
grassDark: mat(palette.grassDark),
soil: mat(palette.soil),
paving: mat(palette.paving),
pavingDark: mat(palette.pavingDark),
wood: mat(palette.wood),
woodLight: mat(palette.woodLight),
woodDark: mat(palette.woodDark),
zinc: mat(palette.zinc, 0.42, 0.55),
zincDark: mat(palette.zincDark, 0.55, 0.45),
orange: mat(palette.orange, 0.48, 0.15),
dark: mat(0x263e3f),
stone: mat(0x9d9f91),
stoneLight: mat(0xc0c0ae)
};
function box(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
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 cylinder(
radius,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 12,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 127;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
// ------------------------------------------------------------------
// Ground and paving
// ------------------------------------------------------------------
box(30, 0.22, 24, materials.grass, 0, -0.16, 0);
box(29.6, 0.06, 23.6, materials.grassDark, 0, -0.03, 0);
// Shed foundation.
box(5.85, 0.25, 4.9, materials.pavingDark, -3.0, 0.08, 0);
// Tank pad and front step.
box(3.0, 0.22, 2.65, materials.pavingDark, 2.0, 0.07, 1.15);
box(1.25, 0.12, 0.65, materials.paving, -3.7, 0.10, 2.72);
// A small paved path to the overflow drain.
for (let i = 0; i < 5; i++) {
box(
0.72,
0.055,
0.64,
i % 2 ? materials.paving : materials.pavingDark,
4.58,
0.025,
-0.72 + i * 0.53
);
}
// ------------------------------------------------------------------
// Voxel shed
// ------------------------------------------------------------------
const shed = new THREE.Group();
scene.add(shed);
const shedCenterX = -3.0;
// Main walls.
box(5.35, 3.05, 0.18, materials.wood, shedCenterX, 1.725, 2.22, shed);
box(5.35, 3.82, 0.18, materials.wood, shedCenterX, 2.11, -2.22, shed);
box(0.18, 3.05, 4.45, materials.wood, -5.68, 1.725, 0, shed);
// Stepped side wall follows the shed-roof pitch.
for (let i = 0; i < 11; i++) {
const z = -2.45 + i * 0.49;
const roofY = 4.28 - i * 0.08;
const wallTop = roofY - 0.17;
const wallHeight = wallTop - 0.2;
box(
0.18,
wallHeight,
0.49,
i % 2 ? materials.wood : materials.woodLight,
-5.68,
0.2 + wallHeight / 2,
z,
shed
);
}
// Front vertical plank seams.
for (let i = 0; i < 15; i++) {
box(
0.026,
2.94,
0.026,
materials.woodDark,
-5.58 + i * 0.375,
1.73,
2.325,
shed
);
}
// Door and frame.
box(1.25, 2.34, 0.13, materials.woodDark, -3.65, 1.37, 2.36, shed);
box(0.96, 2.12, 0.08, materials.woodLight, -3.65, 1.33, 2.45, shed);
box(0.95, 0.035, 0.03, materials.woodDark, -3.65, 1.65, 2.50, shed);
box(0.035, 0.95, 0.03, materials.woodDark, -3.65, 1.33, 2.50, shed);
box(0.08, 0.08, 0.08, materials.zinc, -3.27, 1.28, 2.52, shed);
// Window.
box(1.38, 0.96, 0.11, materials.woodDark, -1.45, 2.06, 2.36, shed);
const glass = new THREE.MeshStandardMaterial({
color: palette.glass,
emissive: 0x2a6570,
emissiveIntensity: 0.15,
roughness: 0.25,
metalness: 0.08
});
box(1.12, 0.72, 0.06, glass, -1.45, 2.06, 2.44, shed);
box(0.04, 0.74, 0.035, materials.woodDark, -1.45, 2.06, 2.49, shed);
box(1.14, 0.04, 0.035, materials.woodDark, -1.45, 2.06, 2.49, shed);
// Cross-braced details on the right wall.
const braceA = box(0.06, 2.75, 0.07, materials.woodDark, -5.56, 1.65, 0.35, shed);
braceA.rotation.x = -0.58;
const braceB = box(0.06, 2.75, 0.07, materials.woodDark, -5.56, 1.65, -0.35, shed);
braceB.rotation.x = 0.58;
// Stepped voxel roof tiles.
const roofMaterials = palette.roof.map(color => mat(color, 0.84));
const tileWidth = 0.56;
const tileDepth = 0.49;
const tileHeight = 0.18;
for (let row = 0; row < 11; row++) {
const z = -2.60 + row * 0.52;
const y = 4.36 - row * 0.09;
for (let col = 0; col < 10; col++) {
const x = -5.51 + col * 0.58;
const material = roofMaterials[(row * 3 + col) % roofMaterials.length];
const tile = box(
tileWidth,
tileHeight,
tileDepth,
material,
x,
y,
z,
shed
);
tile.rotation.x = -0.035;
}
}
// Dark fascia under the low eave.
box(5.86, 0.16, 0.14, materials.woodDark, -3.0, 3.28, 2.72, shed);
// ------------------------------------------------------------------
// Gutter, downpipe and continuous water path
// ------------------------------------------------------------------
const gutterY = 3.23;
const gutterZ = 2.72;
box(5.8, 0.08, 0.24, materials.zink, -3.08, gutterY, gutterZ);
box(5.8, 0.22, 0.055, materials.zinc, -3.08, gutterY + 0.11, gutterZ - 0.13);
box(5.8, 0.22, 0.055, materials.zinc, -3.08, gutterY + 0.11, gutterZ + 0.13);
// End caps.
box(0.07, 0.25, 0.28, materials.zincDark, -5.96, gutterY + 0.10, gutterZ);
box(0.07, 0.25, 0.28, materials.zincDark, -0.20, gutterY + 0.10, gutterZ);
// Gutter supports.
for (const x of [-5.25, -3.85, -2.45, -1.05]) {
box(0.07, 0.23, 0.34, materials.zincDark, x, gutterY - 0.12, gutterZ);
}
const waterMaterial = new THREE.MeshStandardMaterial({
color: palette.water,
emissive: 0x087a91,
emissiveIntensity: 0.85,
roughness: 0.18,
metalness: 0.05,
transparent: true,
opacity: 0.9
});
// Shallow water in the gutter.
box(5.62, 0.035, 0.12, waterMaterial, -3.08, gutterY + 0.065, gutterZ);
const gutterCurve = new THREE.LineCurve3(
new THREE.Vector3(-5.82, gutterY + 0.09, gutterZ),
new THREE.Vector3(-0.42, gutterY + 0.09, gutterZ)
);
const pipeCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-0.42, gutterY + 0.09, gutterZ),
new THREE.Vector3(-0.42, 3.02, gutterZ),
new THREE.Vector3(-0.42, 2.55, gutterZ),
new THREE.Vector3(-0.36, 2.31, 2.70),
new THREE.Vector3(-0.10, 2.20, 2.70),
new THREE.Vector3(0.40, 2.18, 2.66),
new THREE.Vector3(0.68, 2.11, 2.38),
new THREE.Vector3(0.72, 2.04, 1.82),
new THREE.Vector3(0.72, 1.94, 1.55)
],
false,
"catmullrom",
0.12
);
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0xb8c7c3,
roughness: 0.32,
metalness: 0.62,
transparent: true,
opacity: 0.66,
depthWrite: false,
side: THREE.DoubleSide
});
const pipe = new THREE.Mesh(
new THREE.TubeGeometry(pipeCurve, 100, 0.125, 8, false),
pipeMaterial
);
pipe.castShadow = true;
pipe.renderOrder = 2;
scene.add(pipe);
// Luminous inner water core makes the route readable through the pipe.
const routeCoreMaterial = new THREE.MeshBasicMaterial({
color: palette.water,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const pipeCore = new THREE.Mesh(
new THREE.TubeGeometry(pipeCurve, 100, 0.047, 6, false),
routeCoreMaterial
);
pipeCore.renderOrder = 3;
scene.add(pipeCore);
// Pipe brackets.
box(0.30, 0.055, 0.08, materials.zincDark, -0.42, 2.72, 2.72);
box(0.055, 0.28, 0.08, materials.zincDark, -0.53, 2.72, 2.72);
box(0.30, 0.055, 0.08, materials.zincDark, -0.42, 2.35, 2.72);
// ------------------------------------------------------------------
// Covered tank
// ------------------------------------------------------------------
const tankMaterial = new THREE.MeshStandardMaterial({
color: palette.tank,
roughness: 0.48,
metalness: 0.12,
transparent: true,
opacity: 0.93
});
const tankWaterMaterial = new THREE.MeshStandardMaterial({
color: 0x24c4dc,
emissive: 0x087b91,
emissiveIntensity: 0.48,
roughness: 0.25,
transparent: true,
opacity: 0.82
});
box(2.72, 0.16, 2.38, materials.tankDark, 2.0, 0.20, 1.15);
box(2.40, 1.76, 2.06, tankMaterial, 2.0, 1.15, 1.15);
// Internal water volume, revealed in cutaway mode.
box(2.18, 1.30, 1.84, tankWaterMaterial, 2.0, 0.91, 1.15);
// Cover.
box(2.57, 0.18, 2.23, materials.tankDark, 2.0, 2.12, 1.15);
box(2.22, 0.05, 1.88, mat(0x2b9299, 0.55, 0.12), 2.0, 2.23, 1.15);
// Structural ribs.
for (const x of [1.08, 2.0, 2.92]) {
box(0.09, 1.58, 0.08, materials.tankDark, x, 1.13, 2.22);
}
box(2.30, 0.09, 0.08, materials.tankDark, 2.0, 0.40, 2.22);
box(2.30, 0.09, 0.08, materials.tankDark, 2.0, 1.85, 2.22);
// Inlet collar around the downpipe.
box(0.42, 0.12, 0.42, materials.zincDark, 0.72, 2.25, 1.55);
box(0.16, 0.14, 0.46, materials.zinc, 0.72, 2.27, 1.55);
box(0.16, 0.14, 0.46, materials.zinc, 0.72, 2.27, 1.55);
// Tank level gauge.
box(0.25, 1.30, 0.09, materials.dark, 2.58, 1.15, 2.24);
box(0.13, 0.98, 0.11, waterMaterial, 2.58, 1.12, 2.30);
for (let i = 0; i < 6; i++) {
box(
i % 2 ? 0.09 : 0.13,
0.025,
0.025,
materials.stoneLight,
2.59,
0.63 + i * 0.20,
2.37
);
}
// ------------------------------------------------------------------
// Overflow pipe and drain
// ------------------------------------------------------------------
const overflowCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(3.05, 1.70, 1.10),
new THREE.Vector3(3.45, 1.70, 1.10),
new THREE.Vector3(3.76, 1.57, 1.10),
new THREE.Vector3(3.82, 0.86, 1.10),
new THREE.Vector3(3.98, 0.57, 1.10),
new THREE.Vector3(4.45, 0.42, 1.10)
],
false,
"catmullrom",
0.08
);
const overflowPipe = new THREE.Mesh(
new THREE.TubeGeometry(overflowCurve, 70, 0.115, 8, false),
pipeMaterial
);
overflowPipe.castShadow = true;
overflowPipe.renderOrder = 2;
scene.add(overflowPipe);
const overflowCore = new THREE.Mesh(
new THREE.TubeGeometry(overflowCurve, 70, 0.043, 6, false),
routeCoreMaterial
);
overflowCore.renderOrder = 3;
scene.add(overflowCore);
// Warning flange where the overflow leaves the tank.
box(0.12, 0.40, 0.40, materials.orange, 3.23, 1.70, 1.10);
box(0.08, 0.10, 0.42, materials.orange, 3.79, 1.13, 1.10);
// Stone catch basin and dark grate.
box(1.48, 0.16, 1.34, materials.stone, 4.65, 0.12, 1.10);
box(1.10, 0.10, 0.96, materials.dark, 4.65, 0.20, 1.10);
for (let i = 0; i < 6; i++) {
box(
0.055,
0.055,
0.88,
materials.zincDark,
4.20 + i * 0.18,
0.29,
1.10
);
}
// A shallow puddle beneath the overflow.
const puddleMaterial = new THREE.MeshStandardMaterial({
color: 0x43bfd1,
roughness: 0.18,
metalness: 0.05,
transparent: true,
opacity: 0.62
});
box(1.18, 0.025, 0.95, puddleMaterial, 4.65, 0.265, 1.10);
// ------------------------------------------------------------------
// Small voxel landscape details
// ------------------------------------------------------------------
// Low block wall in the background.
for (let i = 0; i < 12; i++) {
box(
0.82,
0.64,
0.30,
i % 2 ? materials.stone : materials.stoneLight,
-6.0 + i * 0.84,
0.32,
-5.1
);
}
// Voxel trees behind the shed.
function tree(x, z, scale = 1) {
const trunk = new THREE.Group();
trunk.position.set(x, 0, z);
trunk.scale.setScalar(scale);
scene.add(trunk);
box(0.28, 1.7, 0.28, materials.woodDark, 0, 0.85, 0, trunk);
box(1.05, 0.75, 0.95, materials.grassDark, 0, 1.62, 0, trunk);
box(0.75, 0.66, 0.72, mat(0x789d70), 0.08, 2.16, 0.03, trunk);
box(0.52, 0.48, 0.54, mat(0x86aa78), -0.12, 2.55, 0.04, trunk);
}
tree(-7.0, -3.5, 1.05);
tree(-1.6, -4.3, 0.86);
tree(6.7, -3.9, 1.0);
// Voxel grass tufts.
for (let i = 0; i < 32; i++) {
const x = -8 + random() * 16;
const z = -4.7 + random() * 10.5;
if (x > -6.1 && x < 3.7 && z > -2.6 && z < 3.1) continue;
const tuft = new THREE.Group();
tuft.position.set(x, 0, z);
scene.add(tuft);
for (let j = 0; j < 3; j++) {
const blade = box(
0.055,
0.24 + random() * 0.17,
0.055,
j % 2 ? materials.grass : materials.grassDark,
(j - 1) * 0.09,
0.15,
0,
tuft
);
blade.rotation.z = (j - 1) * 0.22;
}
}
// ------------------------------------------------------------------
// Animated water particles
// ------------------------------------------------------------------
const flowGroup = new THREE.Group();
scene.add(flowGroup);
const particleMaterial = new THREE.MeshStandardMaterial({
color: 0x7ceeff,
emissive: 0x16aeca,
emissiveIntensity: 1.45,
roughness: 0.16,
metalness: 0.05
});
const particleGeometry = new THREE.SphereGeometry(0.065, 8, 6);
function createFlow(curve, count) {
const particles = [];
for (let i = 0; i < count; i++) {
const particle = new THREE.Mesh(particleGeometry, particleMaterial);
particle.renderOrder = 4;
flowGroup.add(particle);
particles.push(particle);
}
return { curve, particles };
}
const flows = [
createFlow(gutterCurve, 18),
createFlow(pipeCurve, 28),
createFlow(overflowCurve, 18)
];
let flowOffset = 0;
let flowEnabled = true;
let flowSpeed = 1;
function updateFlow(dt) {
if (!flowEnabled) return;
flowOffset = (flowOffset + dt * flowSpeed * 0.075) % 1;
flows.forEach(({ curve, particles }, flowIndex) => {
particles.forEach((particle, i) => {
const u = (flowOffset + i / particles.length) % 1;
particle.position.copy(curve.getPointAt(u));
// Slight pulsation makes the moving water easy to see.
const scale = 0.78 + Math.sin((u + flowIndex) * Math.PI * 8) * 0.16;
particle.scale.setScalar(scale);
});
});
}
// ------------------------------------------------------------------
// Rain
// ------------------------------------------------------------------
const rainCount = 260;
const rainPositions = new Float32Array(rainCount * 6);
const rainDrops = [];
for (let i = 0; i < rainCount; i++) {
const x = -9 + random() * 18;
const y = 2 + random() * 11;
const z = -5.5 + random() * 13;
rainDrops.push({ x, y, z, speed: 6 + random() * 5 });
const p = i * 6;
rainPositions[p] = x;
rainPositions[p + 1] = y;
rainPositions[p + 2] = z;
rainPositions[p + 3] = x + 0.035;
rainPositions[p + 4] = y - 0.48;
rainPositions[p + 5] = z;
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rainMaterial = new THREE.LineBasicMaterial({
color: 0x76cddd,
transparent: true,
opacity: 0.38,
depthWrite: false
});
const rain = new THREE.LineSegments(rainGeometry, rainMaterial);
rain.frustumCulled = false;
scene.add(rain);
let rainEnabled = true;
function updateRain(dt) {
if (!rainEnabled) return;
const positions = rainGeometry.attributes.position.array;
rainDrops.forEach((drop, i) => {
drop.y -= drop.speed * dt;
if (drop.y < 0.05) {
drop.y = 9 + random() * 5;
}
const p = i * 6;
positions[p] = drop.x;
positions[p + 1] = drop.y;
positions[p + 2] = drop.z;
positions[p + 3] = drop.x + 0.035;
positions[p + 4] = drop.y - 0.48;
positions[p + 5] = drop.z;
});
rainGeometry.attributes.position.needsUpdate = true;
}
// ------------------------------------------------------------------
// Projected labels
// ------------------------------------------------------------------
const labelDefinitions = [
{
text: "Voxel shed roof",
position: new THREE.Vector3(-3.1, 4.62, -0.15),
offset: new THREE.Vector2(0, -13)
},
{
text: "Collection gutter",
position: new THREE.Vector3(-3.25, 3.57, 2.76),
offset: new THREE.Vector2(0, 13)
},
{
text: "Downpipe",
position: new THREE.Vector3(-0.42, 2.63, 2.73),
offset: new THREE.Vector2(-34, 0)
},
{
text: "Covered tank",
position: new THREE.Vector3(2.05, 2.40, 1.15),
offset: new THREE.Vector2(0, -10)
},
{
text: "Overflow",
position: new THREE.Vector3(3.85, 1.82, 1.10),
offset: new THREE.Vector2(40, -8),
overflow: true
}
];
const labelLayer = document.querySelector("#labels");
let labelsEnabled = true;
labelDefinitions.forEach(definition => {
const element = document.createElement("div");
element.className = `label${definition.overflow ? " overflow" : ""}`;
element.textContent = definition.text;
labelLayer.appendChild(element);
definition.element = element;
});
const projected = new THREE.Vector3();
function updateLabels() {
if (!labelsEnabled) return;
labelDefinitions.forEach(definition => {
projected.copy(definition.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
definition.element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth + definition.offset.x;
const y = (-projected.y * 0.5 + 0.5) * innerHeight + definition.offset.y;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
});
}
// ------------------------------------------------------------------
// Custom camera controls — no external controls addon
// ------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(-0.45, 1.55, 0.55),
yaw: 0.72,
pitch: 0.48,
distance: 14.4,
minDistance: 7,
maxDistance: 24,
dragging: false,
panning: false,
previousX: 0,
previousY: 0
};
const initialControls = {
target: controls.target.clone(),
yaw: controls.yaw,
pitch: controls.pitch,
distance: controls.distance
};
function updateCamera() {
const horizontalDistance = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontalDistance,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontalDistance
);
camera.lookAt(controls.target);
}
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
controls.dragging = true;
controls.panning = event.button === 2 || event.shiftKey;
controls.previousX = event.clientX;
controls.previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!controls.dragging) return;
const dx = event.clientX - controls.previousX;
const dy = event.clientY - controls.previousY;
controls.previousX = event.clientX;
controls.previousY = event.clientY;
if (controls.panning) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const panScale = controls.distance * 0.0015;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(up, dy * panScale);
} else {
controls.yaw -= dx * 0.005;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.12,
1.15
);
}
updateCamera();
});
function endPointer(event) {
controls.dragging = false;
controls.panning = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance + event.deltaY * 0.012,
controls.minDistance,
controls.maxDistance
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------------
// UI controls
// ------------------------------------------------------------------
const rainButton = document.querySelector("#rainButton");
const flowButton = document.querySelector("#flowButton");
const cutawayButton = document.querySelector("#cutawayButton");
const labelsButton = document.querySelector("#labelsButton");
const resetButton = document.querySelector("#resetButton");
const speedInput = document.querySelector("#speed");
rainButton.addEventListener("click", () => {
rainEnabled = !rainEnabled;
rain.visible = rainEnabled;
rainButton.textContent = rainEnabled ? "Rain on" : "Rain off";
rainButton.setAttribute("aria-pressed", String(rainEnabled));
});
flowButton.addEventListener("click", () => {
flowEnabled = !flowEnabled;
flowGroup.visible = flowEnabled;
flowButton.textContent = flowEnabled ? "Flow on" : "Flow off";
flowButton.setAttribute("aria-pressed", String(flowEnabled));
});
let cutawayEnabled = false;
cutawayButton.addEventListener("click", () => {
cutawayEnabled = !cutawayEnabled;
tankMaterial.opacity = cutawayEnabled ? 0.27 : 0.93;
tankMaterial.depthWrite = !cutawayEnabled;
tankWaterMaterial.opacity = cutawayEnabled ? 0.78 : 0.82;
cutawayButton.setAttribute("aria-pressed", String(cutawayEnabled));
});
labelsButton.addEventListener("click", () => {
labelsEnabled = !labelsEnabled;
labelLayer.style.display = labelsEnabled ? "block" : "none";
labelsButton.setAttribute("aria-pressed", String(labelsEnabled));
});
speedInput.addEventListener("input", event => {
flowSpeed = Number(event.target.value);
});
resetButton.addEventListener("click", () => {
controls.target.copy(initialControls.target);
controls.yaw = initialControls.yaw;
controls.pitch = initialControls.pitch;
controls.distance = initialControls.distance;
updateCamera();
});
// ------------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateRain(dt);
updateFlow(dt);
updateLabels();
// Gentle water-surface pulse.
waterMaterial.emissiveIntensity = 0.76 + Math.sin(elapsed * 2.2) * 0.12;
puddleMaterial.opacity = 0.57 + Math.sin(elapsed * 2.0) * 0.06;
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
```