Prompt specification
Build or customize the Three.js 3D scene "Garden shed watering station" 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: Garden shed watering station
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/garden-shed-watering-station-x1099
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing garden rainwater storage. Compose a shed, tank, vegetable beds, watering cans, and paths; collected water moves from tank to beds while a visible level indicator decreases accordingly. Stylized solid forms.
Working Three.js Starter (garden-shed-watering-station-x1099):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rainward — Garden Water Storage</title>
<style>
:root {
color-scheme: dark;
--ink: #eff9f3;
--muted: #b7cec5;
--panel: rgba(17, 43, 45, 0.88);
--line: rgba(220, 245, 234, 0.16);
--mint: #b9ed9a;
--water: #57d8f5;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcebe6;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.glass {
color: var(--ink);
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 50px rgba(26, 56, 52, 0.18);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
position: fixed;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 20px 22px;
border-radius: 22px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--mint);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 5px rgba(185, 237, 154, 0.13);
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 42px);
line-height: 0.98;
letter-spacing: -0.05em;
}
.intro p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.tank-card {
position: fixed;
top: 22px;
right: 22px;
width: 270px;
padding: 18px;
border-radius: 22px;
pointer-events: none;
}
.tank-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.tank-heading strong {
display: block;
font-size: 12px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#percentage {
display: block;
margin-top: 2px;
font-size: 32px;
line-height: 1;
letter-spacing: -0.05em;
}
.meter {
position: relative;
height: 12px;
margin: 16px 0 13px;
overflow: hidden;
border-radius: 999px;
background: rgba(0, 0, 0, 0.24);
border: 1px solid rgba(255, 255, 255, 0.08);
}
#meter-fill {
position: absolute;
inset: 0 auto 0 0;
width: 78%;
border-radius: inherit;
background: linear-gradient(90deg, #2ca9d5, #69e4ff);
box-shadow: 0 0 16px rgba(87, 216, 245, 0.5);
transition: width 80ms linear;
}
.status {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 12px;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--water);
box-shadow: 0 0 0 4px rgba(87, 216, 245, 0.12);
}
.status-dot.rain {
background: #b9ed9a;
box-shadow: 0 0 0 4px rgba(185, 237, 154, 0.12);
}
.status-dot.paused {
background: #f1c778;
box-shadow: 0 0 0 4px rgba(241, 199, 120, 0.12);
}
.controls {
position: fixed;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 18px;
transform: translateX(-50%);
}
button {
border: 0;
border-radius: 12px;
padding: 11px 15px;
color: #173b36;
background: var(--mint);
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: transform 150ms ease, filter 150ms ease;
}
button:hover {
filter: brightness(1.07);
transform: translateY(-1px);
}
button.secondary {
color: var(--ink);
background: rgba(255, 255, 255, 0.09);
border: 1px solid rgba(255, 255, 255, 0.12);
}
.hint {
position: fixed;
left: 22px;
bottom: 24px;
padding: 10px 13px;
border-radius: 13px;
color: #31564f;
background: rgba(246, 251, 245, 0.82);
font-size: 11px;
font-weight: 700;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #244a44;
background: #dcebe6;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.intro p { display: none; }
.tank-card {
top: auto;
right: 12px;
bottom: 78px;
width: 230px;
padding: 14px;
}
.hint { display: none; }
.controls {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="intro glass">
<div class="eyebrow">Garden water system</div>
<h1>Rainward</h1>
<p>Roof runoff fills the storage tank, while the irrigation line carries water to the vegetable beds.</p>
</header>
<section class="tank-card glass" aria-live="polite">
<div class="tank-heading">
<div>
<strong>Tank level</strong>
<span id="percentage">78%</span>
</div>
<svg width="38" height="38" viewBox="0 0 38 38" aria-hidden="true">
<path d="M19 3C12 12 8 17 8 23a11 11 0 0 0 22 0c0-6-4-11-11-20Z"
fill="none" stroke="#6be2fb" stroke-width="2"/>
<path d="M12 24c2 4 5 6 9 6" fill="none" stroke="#6be2fb"
stroke-width="2" stroke-linecap="round"/>
</svg>
</div>
<div class="meter"><div id="meter-fill"></div></div>
<div class="status">
<span id="status-dot" class="status-dot"></span>
<span id="status-text">Irrigating vegetable beds</span>
</div>
</section>
<div class="controls glass">
<button id="pause-button">Pause cycle</button>
<button id="rain-button" class="secondary">Collect roof runoff</button>
<button id="reset-camera" class="secondary">Reset view</button>
</div>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Shift-drag to pan</div>
<div id="loading">Preparing the garden…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const sceneHost = $("scene");
// ---------- Renderer, scene, and lighting ----------
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("aria-label", "Interactive garden rainwater system");
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcebe6);
scene.fog = new THREE.Fog(0xdcebe6, 24, 45);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xeaf9ff, 0x667650, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4db, 3.2);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x98dff2, 0.65);
fillLight.position.set(8, 6, -8);
scene.add(fillLight);
// ---------- Materials and geometry helpers ----------
const material = (color, roughness = 0.78, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const materials = {
ground: material(0x809b63),
groundEdge: material(0x61784c),
gravel: material(0xc9b995),
stone: material(0xb9aa8d),
shed: material(0x7fa28a),
shedTrim: material(0xe7e4c9),
roof: material(0x425b59),
roofTrim: material(0x304746),
door: material(0x6d4b39),
dark: material(0x263d3b),
window: material(0x8dc8cf, 0.22, 0.08),
wood: material(0xa77745),
woodDark: material(0x815934),
soil: material(0x594537),
tank: material(0x4d8f83, 0.58),
tankBand: material(0x9ac5af),
pipe: material(0x315d65, 0.5),
yellow: material(0xe2b84f),
coral: material(0xc96f58),
blue: material(0x264e68),
leaf: material(0x5f9e4d),
leafLight: material(0x8abd58),
tomato: material(0xd95f43),
carrot: material(0xe7953b),
water: new THREE.MeshStandardMaterial({
color: 0x38b9dc,
roughness: 0.2,
metalness: 0.05,
transparent: true,
opacity: 0.92
}),
droplet: new THREE.MeshBasicMaterial({
color: 0x75e8ff,
transparent: true,
opacity: 0.88
})
};
function addMesh(geometry, mat, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, w, h, d, x, y, z, mat, castShadow = true) {
const mesh = addMesh(new THREE.BoxGeometry(w, h, d), mat, parent);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
return mesh;
}
function addCylinder(parent, rt, rb, h, x, y, z, mat, segments = 20) {
const mesh = addMesh(new THREE.CylinderGeometry(rt, rb, h, segments), mat, parent);
mesh.position.set(x, y, z);
return mesh;
}
function cylinderBetween(parent, start, end, radius, mat, segments = 12) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
mat,
parent
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function addTorus(parent, radius, tube, x, y, z, mat, horizontal = false) {
const mesh = addMesh(new THREE.TorusGeometry(radius, tube, 10, 32), mat, parent);
mesh.position.set(x, y, z);
if (horizontal) mesh.rotation.x = Math.PI / 2;
return mesh;
}
function makeCurve(points) {
return new THREE.CatmullRomCurve3(
points.map(p => new THREE.Vector3(...p)),
false,
"centripetal"
);
}
// ---------- Garden base and paths ----------
const ground = addBox(scene, 16, 0.5, 12, 0, -0.25, 0, materials.ground);
ground.castShadow = false;
addBox(scene, 16.15, 0.22, 12.15, 0, -0.54, 0, materials.groundEdge);
// Main path and path from the shed.
addBox(scene, 1.3, 0.075, 10, 0.48, 0.015, -0.1, materials.gravel, false);
addBox(scene, 7.0, 0.075, 1.18, -2.55, 0.018, -0.55, materials.gravel, false);
const stoneColors = [0xc3b28f, 0xb7a681, 0xd0c09d, 0xaa9b7c];
for (let i = 0; i < 8; i++) {
const stone = addCylinder(
scene,
0.31,
0.33,
0.07,
-5.55 + i * 0.83,
0.07,
-0.55,
material(stoneColors[i % stoneColors.length]),
9
);
stone.rotation.y = i * 0.63;
stone.scale.z = 0.78;
}
// ---------- Shed ----------
const shed = new THREE.Group();
shed.position.set(-4.7, 0, -3.0);
scene.add(shed);
addBox(shed, 4.4, 3.05, 3.7, 0, 1.525, 0, materials.shed);
addBox(shed, 4.65, 0.22, 3.92, 0, 0.12, 0, materials.shedTrim);
// Two solid roof panels forming a pitched roof.
const leftRoof = addBox(shed, 2.58, 0.22, 4.35, -1.12, 3.35, 0, materials.roof);
leftRoof.rotation.z = 0.23;
const rightRoof = addBox(shed, 2.58, 0.22, 4.35, 1.12, 3.35, 0, materials.roof);
rightRoof.rotation.z = -0.23;
addBox(shed, 4.3, 0.15, 0.18, 0, 3.58, 2.1, materials.roofTrim);
addBox(shed, 0.18, 0.15, 4.15, 2.27, 3.03, 0, materials.roofTrim);
// Door and trim.
addBox(shed, 1.35, 2.34, 0.12, -0.92, 1.2, 1.9, materials.shedTrim);
addBox(shed, 1.12, 2.17, 0.13, -0.92, 1.16, 1.98, materials.door);
addBox(shed, 0.08, 2.17, 0.16, -0.92, 1.16, 2.07, materials.woodDark);
addBox(shed, 1.12, 0.08, 0.16, -0.92, 1.16, 2.07, materials.woodDark);
addCylinder(shed, 0.055, 0.055, 0.16, -0.55, 1.18, 2.08, materials.yellow, 12)
.rotation.z = Math.PI / 2;
// Window.
addBox(shed, 1.15, 1.02, 0.14, 1.02, 1.78, 1.91, materials.shedTrim);
addBox(shed, 0.91, 0.78, 0.16, 1.02, 1.78, 2.0, materials.window);
addBox(shed, 0.07, 0.82, 0.19, 1.02, 1.78, 2.08, materials.shedTrim);
addBox(shed, 0.95, 0.07, 0.19, 1.02, 1.78, 2.08, materials.shedTrim);
addBox(shed, 1.45, 0.16, 0.48, 1.02, 1.18, 2.02, materials.woodDark);
// Small sign.
addBox(shed, 1.45, 0.38, 0.14, 0.05, 2.75, 2.02, materials.shedTrim);
addBox(shed, 0.82, 0.09, 0.17, 0.05, 2.78, 2.10, materials.dark);
// Gutter and roof runoff pipe.
cylinderBetween(
scene,
[-6.95, 3.18, -0.86],
[-2.30, 3.18, -0.86],
0.09,
materials.roofTrim,
16
);
const roofRunoffCurve = makeCurve([
[-2.30, 3.18, -0.86],
[-2.32, 3.13, 0.15],
[-2.05, 3.07, 0.85],
[-1.30, 3.00, 1.40]
]);
addMesh(
new THREE.TubeGeometry(roofRunoffCurve, 32, 0.075, 10, false),
materials.pipe
);
// ---------- Rainwater tank ----------
const tankX = -1.30;
const tankZ = 1.45;
const tankHeight = 2.72;
const tankBase = 0.16;
const tankBody = addMesh(
new THREE.CylinderGeometry(1.23, 1.23, tankHeight, 36, 1, true),
materials.tank
);
tankBody.position.set(tankX, tankBase + tankHeight / 2, tankZ);
addTorus(scene, 1.24, 0.09, tankX, tankBase + 0.08, tankZ, materials.tankBand, true);
addTorus(scene, 1.24, 0.08, tankX, tankBase + tankHeight - 0.07, tankZ, materials.tankBand, true);
addCylinder(scene, 1.2, 1.2, 0.12, tankX, tankBase, tankZ, materials.tankBand);
// The blue surface physically drops as the tank empties.
const tankSurface = addCylinder(
scene,
1.05,
1.05,
0.055,
tankX,
tankBase + 0.7,
tankZ,
materials.water,
36
);
// Tank outlet and valve.
cylinderBetween(
scene,
[-0.08, 0.73, tankZ],
[0.24, 0.73, tankZ],
0.11,
materials.pipe
);
addTorus(scene, 0.17, 0.045, 0.27, 0.73, tankZ, materials.coral);
// External vertical gauge.
const gaugeBase = 0.49;
const gaugeHeight = 1.72;
addBox(scene, 0.48, 2.08, 0.13, tankX, 1.46, tankZ + 1.29, materials.dark);
const gaugeFill = addBox(
scene,
0.25,
gaugeHeight,
0.075,
tankX,
gaugeBase + gaugeHeight / 2,
tankZ + 1.39,
materials.water
);
for (let i = 0; i < 6; i++) {
addBox(
scene,
0.10,
0.025,
0.03,
tankX + 0.18,
gaugeBase + 0.15 + i * 0.29,
tankZ + 1.47,
materials.shedTrim,
false
);
}
// ---------- Raised vegetable beds ----------
const bedPositions = [-3.2, 0, 3.2];
const bedX = 3.62;
const bedWidth = 3.65;
const bedDepth = 1.55;
const leafGeometry = new THREE.SphereGeometry(1, 9, 7);
function addPlant(parent, x, z, variant) {
const plant = new THREE.Group();
plant.position.set(x, 0, z);
parent.add(plant);
addCylinder(plant, 0.035, 0.045, 0.42, 0, 0.82, 0, materials.leafLight, 7);
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2 + 0.3;
const leaf = addMesh(leafGeometry, i % 2 ? materials.leaf : materials.leafLight, plant);
leaf.position.set(
Math.cos(angle) * 0.13,
0.78 + (i % 2) * 0.08,
Math.sin(angle) * 0.13
);
leaf.scale.set(0.19, 0.075, 0.27);
leaf.rotation.y = -angle;
}
if (variant === 1) {
const fruit = addMesh(new THREE.SphereGeometry(0.09, 10, 8), materials.tomato, plant);
fruit.position.set(0.11, 0.91, 0.05);
} else if (variant === 2) {
const root = addMesh(new THREE.SphereGeometry(0.085, 9, 7), materials.carrot, plant);
root.position.set(-0.04, 0.67, 0.04);
}
}
bedPositions.forEach((z, bedIndex) => {
const bed = new THREE.Group();
bed.position.set(bedX, 0, z);
scene.add(bed);
addBox(bed, bedWidth, 0.62, 0.16, 0, 0.31, -bedDepth / 2, materials.wood);
addBox(bed, bedWidth, 0.62, 0.16, 0, 0.31, bedDepth / 2, materials.wood);
addBox(bed, 0.16, 0.62, bedDepth, -bedWidth / 2, 0.31, 0, materials.woodDark);
addBox(bed, 0.16, 0.62, bedDepth, bedWidth / 2, 0.31, 0, materials.woodDark);
addBox(bed, bedWidth - 0.22, 0.12, bedDepth - 0.22, 0, 0.56, 0, materials.soil, false);
for (const x of [-1.25, -0.42, 0.42, 1.25]) {
for (const row of [-0.32, 0.32]) {
addPlant(bed, x, row, bedIndex);
}
}
});
// ---------- Irrigation pipes and moving water ----------
const mainHoseCurve = makeCurve([
[0.20, 0.73, tankZ],
[0.63, 0.45, tankZ],
[1.08, 0.25, tankZ]
]);
const manifoldCurve = makeCurve([
[1.08, 0.25, 4.05],
[1.08, 0.25, -3.85]
]);
addMesh(new THREE.TubeGeometry(mainHoseCurve, 24, 0.075, 10, false), materials.pipe);
addMesh(new THREE.TubeGeometry(manifoldCurve, 44, 0.065, 10, false), materials.pipe);
const branchCurves = [];
bedPositions.forEach(z => {
const branch = makeCurve([
[1.08, 0.25, z],
[1.57, 0.28, z],
[1.94, 0.73, z],
[2.42, 1.12, z]
]);
branchCurves.push(branch);
addMesh(new THREE.TubeGeometry(branch, 28, 0.055, 9, false), materials.pipe);
// Small sprinkler head at the end of each branch.
addCylinder(scene, 0.10, 0.13, 0.20, 2.42, 1.13, z, materials.dark, 12);
addTorus(scene, 0.11, 0.025, 2.42, 1.20, z, materials.water, true);
});
function createFlow(curve, count, speed, size = 0.055) {
const group = new THREE.Group();
const geometry = new THREE.SphereGeometry(size, 7, 5);
const offsets = [];
for (let i = 0; i < count; i++) {
const particle = addMesh(geometry, materials.droplet, group);
particle.castShadow = false;
offsets.push(i / count);
}
scene.add(group);
return { group, curve, offsets, speed };
}
const mainFlow = createFlow(mainHoseCurve, 7, 0.23);
const manifoldFlow = createFlow(manifoldCurve, 13, 0.13);
const branchFlows = branchCurves.map(curve => createFlow(curve, 7, 0.24));
const roofFlow = createFlow(roofRunoffCurve, 10, 0.29, 0.045);
function updateFlow(flow, time, active) {
flow.group.visible = active;
if (!active) return;
flow.offsets.forEach((offset, i) => {
const point = flow.curve.getPointAt((time * flow.speed + offset) % 1);
flow.group.children[i].position.copy(point);
});
}
// Water spray above each vegetable bed.
const sprayGroups = [];
bedPositions.forEach(z => {
const spray = new THREE.Group();
const geometry = new THREE.SphereGeometry(0.038, 6, 5);
const seeds = [];
for (let i = 0; i < 20; i++) {
const drop = addMesh(geometry, materials.droplet, spray);
drop.castShadow = false;
seeds.push({
offset: Math.random(),
zOffset: (Math.random() - 0.5) * 0.34,
speed: 0.9 + Math.random() * 0.25
});
}
scene.add(spray);
sprayGroups.push({ group: spray, z, seeds });
});
function updateSprays(time, active) {
sprayGroups.forEach(spray => {
spray.group.visible = active;
if (!active) return;
spray.seeds.forEach((seed, i) => {
const phase = (time * seed.speed + seed.offset) % 1;
const drop = spray.group.children[i];
drop.position.set(
2.43 + phase * 1.12,
1.16 + phase * 0.28 - phase * phase * 0.92,
spray.z + seed.zOffset * (1 - phase * 0.35)
);
drop.scale.y = 1.4;
});
});
}
// ---------- Rain particles ----------
const rainCount = 85;
const rainPositions = new Float32Array(rainCount * 3);
for (let i = 0; i < rainCount; i++) {
rainPositions[i * 3] = -7.1 + Math.random() * 5.3;
rainPositions[i * 3 + 1] = 3.8 + Math.random() * 4.5;
rainPositions[i * 3 + 2] = -5.2 + Math.random() * 4.5;
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute("position", new THREE.BufferAttribute(rainPositions, 3));
const rain = new THREE.Points(
rainGeometry,
new THREE.PointsMaterial({
color: 0x72d9f2,
size: 0.075,
transparent: true,
opacity: 0.68,
depthWrite: false
})
);
rain.frustumCulled = false;
scene.add(rain);
function updateRain(dt) {
rain.visible = mode === "rain";
if (!rain.visible) return;
const positions = rainGeometry.attributes.position.array;
for (let i = 0; i < rainCount; i++) {
positions[i * 3 + 1] -= dt * 5.1;
if (positions[i * 3 + 1] < 3.25) {
positions[i * 3 + 1] = 7.4 + Math.random() * 1.4;
positions[i * 3] = -7.1 + Math.random() * 5.3;
positions[i * 3 + 2] = -5.2 + Math.random() * 4.5;
}
}
rainGeometry.attributes.position.needsUpdate = true;
}
// ---------- Watering cans ----------
function createWateringCan(colorMaterial) {
const can = new THREE.Group();
addCylinder(can, 0.34, 0.42, 0.70, 0, 0.38, 0, colorMaterial, 18);
addTorus(can, 0.34, 0.065, -0.34, 0.52, 0, colorMaterial);
addTorus(can, 0.19, 0.045, 0, 0.75, 0, colorMaterial, true);
cylinderBetween(can, [0.25, 0.40, 0], [0.94, 0.72, 0], 0.085, colorMaterial);
cylinderBetween(can, [0.88, 0.68, 0], [1.02, 0.76, 0], 0.14, colorMaterial, 14);
return can;
}
const canYellow = createWateringCan(materials.yellow);
canYellow.position.set(-3.55, 0.05, 0.15);
canYellow.rotation.y = -0.3;
scene.add(canYellow);
const canCoral = createWateringCan(materials.coral);
canCoral.position.set(5.83, 0.05, 1.35);
canCoral.rotation.y = 0.42;
canCoral.scale.setScalar(0.88);
scene.add(canCoral);
const canSmall = createWateringCan(materials.blue);
canSmall.position.set(-5.85, 0.05, 1.45);
canSmall.rotation.y = 1.1;
canSmall.scale.setScalar(0.82);
scene.add(canSmall);
// ---------- Fence and small garden details ----------
const fenceMat = material(0xd7c7a2);
for (let x = -7.5; x <= 7.5; x += 1.5) {
addBox(scene, 0.13, 1.8, 0.13, x, 0.9, -5.62, fenceMat);
}
addBox(scene, 15.1, 0.12, 0.12, 0, 0.72, -5.62, fenceMat);
addBox(scene, 15.1, 0.12, 0.12, 0, 1.35, -5.62, fenceMat);
// A few grass clusters near the bed edges.
const grassMat = material(0x527f49);
for (let i = 0; i < 18; i++) {
const x = i < 9 ? -6.7 + i * 0.22 : 6.0 + (i - 9) * 0.18;
const z = i < 9 ? 2.0 + (i % 3) * 0.22 : -1.3 + (i % 4) * 0.22;
const blade = addMesh(new THREE.ConeGeometry(0.055, 0.28, 5), grassMat);
blade.position.set(x, 0.13, z);
blade.rotation.z = (Math.random() - 0.5) * 0.3;
}
// ---------- Simulation state ----------
let mode = "irrigating";
let modeElapsed = 0;
let modeStartLevel = 0.78;
let modeEndLevel = 0.16;
let tankLevel = 0.78;
let running = true;
const IRRIGATION_DURATION = 13;
const RAIN_DURATION = 8.5;
function setMode(nextMode) {
mode = nextMode;
modeElapsed = 0;
if (mode === "rain") {
modeStartLevel = tankLevel;
modeEndLevel = Math.min(1, tankLevel + 0.18);
} else {
modeStartLevel = tankLevel;
modeEndLevel = 0.16;
}
}
function updateSimulation(dt) {
if (!running) return;
modeElapsed += dt;
if (mode === "irrigating") {
const progress = Math.min(modeElapsed / IRRIGATION_DURATION, 1);
tankLevel = THREE.MathUtils.lerp(modeStartLevel, modeEndLevel, progress);
if (progress >= 1) {
mode = "rain";
modeElapsed = 0;
modeStartLevel = tankLevel;
modeEndLevel = 0.94;
}
} else {
const progress = Math.min(modeElapsed / RAIN_DURATION, 1);
tankLevel = THREE.MathUtils.lerp(modeStartLevel, modeEndLevel, progress);
if (progress >= 1) {
mode = "irrigating";
modeElapsed = 0;
modeStartLevel = tankLevel;
modeEndLevel = 0.16;
}
}
}
function updateTankDisplay() {
const percentage = Math.round(tankLevel * 100);
$("percentage").textContent = `${percentage}%`;
$("meter-fill").style.width = `${percentage}%`;
gaugeFill.scale.y = Math.max(tankLevel, 0.001);
gaugeFill.position.y = gaugeBase + gaugeHeight * tankLevel / 2;
tankSurface.position.y = tankBase + 0.16 + tankHeight * tankLevel;
tankSurface.scale.set(
0.92 + tankLevel * 0.08,
1,
0.92 + tankLevel * 0.08
);
}
function updateStatus() {
const dot = $("status-dot");
dot.classList.remove("rain", "paused");
if (!running) {
$("status-text").textContent = "Water cycle paused";
dot.classList.add("paused");
} else if (mode === "rain") {
$("status-text").textContent = "Collecting roof runoff";
dot.classList.add("rain");
} else {
$("status-text").textContent = "Irrigating vegetable beds";
}
}
$("pause-button").addEventListener("click", () => {
running = !running;
$("pause-button").textContent = running ? "Pause cycle" : "Resume cycle";
updateStatus();
});
$("rain-button").addEventListener("click", () => {
running = true;
$("pause-button").textContent = "Pause cycle";
setMode("rain");
updateStatus();
});
// ---------- Direct camera controls ----------
const cameraState = {
yaw: 0.61,
pitch: 0.43,
radius: 21,
target: new THREE.Vector3(0, 1.0, 0)
};
function updateCamera() {
const horizontal = Math.cos(cameraState.pitch) * cameraState.radius;
const vertical = Math.sin(cameraState.pitch) * cameraState.radius;
camera.position.set(
cameraState.target.x + horizontal * Math.sin(cameraState.yaw),
cameraState.target.y + vertical,
cameraState.target.z + horizontal * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.yaw = 0.61;
cameraState.pitch = 0.43;
cameraState.radius = 21;
cameraState.target.set(0, 1.0, 0);
updateCamera();
}
$("reset-camera").addEventListener("click", resetCamera);
updateCamera();
const pointers = new Map();
let lastPinchDistance = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", event => {
canvas.focus({ preventScroll: true });
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
if (event.shiftKey) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.setY(0)
.normalize();
const forward = cameraState.target.clone()
.sub(camera.position)
.setY(0)
.normalize();
cameraState.target.addScaledVector(right, -dx * 0.009);
cameraState.target.addScaledVector(forward, dy * 0.007);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch - dy * 0.0045,
0.22,
0.88
);
}
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
cameraState.radius *= lastPinchDistance / distance;
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 11, 30);
}
lastPinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 11, 30);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", event => {
const step = 0.09;
if (event.key === "ArrowLeft") cameraState.yaw += step;
if (event.key === "ArrowRight") cameraState.yaw -= step;
if (event.key === "ArrowUp") cameraState.pitch += 0.04;
if (event.key === "ArrowDown") cameraState.pitch -= 0.04;
if (event.key === "+" || event.key === "=") cameraState.radius -= 0.6;
if (event.key === "-") cameraState.radius += 0.6;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch, 0.22, 0.88);
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 11, 30);
updateCamera();
});
canvas.addEventListener("contextmenu", event => event.preventDefault());
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ---------- Animation loop ----------
const clock = new THREE.Clock();
let lastStatusMode = "";
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateSimulation(dt);
updateTankDisplay();
const statusKey = `${mode}-${running}`;
if (statusKey !== lastStatusMode) {
updateStatus();
lastStatusMode = statusKey;
}
const irrigating = running && mode === "irrigating";
const collecting = running && mode === "rain";
updateFlow(mainFlow, elapsed, irrigating);
updateFlow(manifoldFlow, elapsed, irrigating);
branchFlows.forEach(flow => updateFlow(flow, elapsed, irrigating));
updateFlow(roofFlow, elapsed, collecting);
updateSprays(elapsed, irrigating);
updateRain(dt);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
renderer.render(scene, camera);
$("loading").classList.add("hidden");
setTimeout(() => $("loading").remove(), 500);
</script>
</body>
</html>
```