Prompt specification
Build or customize the Three.js 3D scene "Community garden irrigation loop" 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: Community garden irrigation loop
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-garden-irrigation-loop-x1059
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a stylized community-garden irrigation loop. Arrange four raised beds around a footpath, with a reservoir at the back and a main hose following the path edge. Each bed receives a separate branch with a clearly visible valve and small outlets. Clicking a valve sends moving water markers only along that branch and into its assigned bed. Closed branches remain still, and the route through each junction should be continuous. Use timber bed walls, varied vegetables, rounded hoses, and a transparent reservoir. Give the camera an elevated view that shows the complete distribution network while retaining the garden's ordinary human scale.
Working Three.js Starter (community-garden-irrigation-loop-x1059):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Community Garden Irrigation Loop</title>
<style>
:root {
color-scheme: light;
--ink: #173d3c;
--muted: #58706c;
--glass: rgba(249, 252, 246, 0.88);
--line: rgba(34, 83, 74, 0.16);
--cyan: #24c8d7;
--green: #43b96b;
--red: #dc625d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8df;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#app,
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.panel,
.controls,
.legend {
position: fixed;
z-index: 20;
background: var(--glass);
border: 1px solid var(--line);
box-shadow: 0 12px 35px rgba(30, 65, 53, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.panel {
top: 18px;
left: 18px;
width: 290px;
padding: 18px 20px 16px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
display: block;
margin-bottom: 5px;
color: #4f8174;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 30px;
font-weight: 500;
letter-spacing: -0.025em;
}
.panel p {
margin: 7px 0 13px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.status {
display: flex;
align-items: center;
gap: 9px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #355e56;
font-size: 12px;
font-weight: 700;
}
.status-light {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 5px rgba(36, 200, 215, 0.13);
}
.controls {
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 13px;
padding: 8px 9px 8px 14px;
border-radius: 999px;
color: var(--muted);
font-size: 11px;
}
.controls button {
appearance: none;
border: 0;
border-radius: 999px;
padding: 9px 13px;
background: #255c53;
color: white;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
.controls button:hover {
transform: translateY(-1px);
background: #1d4c45;
}
.legend {
right: 18px;
bottom: 18px;
display: flex;
gap: 17px;
align-items: center;
padding: 10px 14px;
border-radius: 999px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.02em;
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend i {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
}
.legend .moving {
background: #64efff;
box-shadow: 0 0 8px rgba(64, 225, 255, 0.8);
}
.legend .paused {
background: #78918d;
}
.legend .valve {
background: #df655f;
}
#valveLabels {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.valve-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: 112px;
padding: 7px 10px;
transform: translate(-50%, -115%);
border: 1px solid rgba(37, 77, 67, 0.18);
border-radius: 11px;
background: rgba(252, 254, 249, 0.92);
box-shadow: 0 7px 22px rgba(29, 66, 55, 0.14);
color: var(--ink);
font: inherit;
text-align: left;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
.valve-label:hover {
transform: translate(-50%, -120%);
background: white;
}
.valve-label .dot {
flex: 0 0 auto;
width: 10px;
height: 10px;
border: 2px solid rgba(255, 255, 255, 0.85);
border-radius: 50%;
background: var(--red);
box-shadow: 0 0 0 1px rgba(38, 76, 67, 0.18);
}
.valve-label.open .dot {
background: var(--green);
box-shadow: 0 0 0 1px rgba(38, 76, 67, 0.18),
0 0 9px rgba(67, 185, 107, 0.4);
}
.valve-label strong,
.valve-label small {
display: block;
}
.valve-label strong {
font-size: 10px;
letter-spacing: 0.035em;
}
.valve-label small {
margin-top: 1px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
}
@media (max-width: 700px) {
.panel {
top: 10px;
left: 10px;
width: 220px;
padding: 13px 15px;
}
h1 {
font-size: 24px;
}
.panel p {
display: none;
}
.status {
margin-top: 9px;
padding-top: 9px;
}
.controls {
top: 10px;
right: 10px;
}
.controls span {
display: none;
}
.legend {
right: 10px;
bottom: 10px;
gap: 10px;
}
.legend span:nth-child(2) {
display: none;
}
.valve-label {
min-width: 94px;
padding: 6px 8px;
}
.valve-label strong {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app">
<div id="viewport"></div>
<section class="panel">
<span class="eyebrow">Community Garden</span>
<h1>Irrigation Loop</h1>
<p>
A shared reservoir feeds four independent raised-bed branches.
Click a valve to start or pause its water markers.
</p>
<div class="status">
<span class="status-light"></span>
<span id="flowStatus" aria-live="polite">1 branch flowing</span>
</div>
</section>
<div class="controls">
<span>Drag to orbit · wheel to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
<div class="legend">
<span><i class="moving"></i>Moving water</span>
<span><i class="paused"></i>Paused branch</span>
<span><i class="valve"></i>Click a valve</span>
</div>
<div id="valveLabels"></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, camera, and scene
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("valveLabels");
const flowStatus = document.getElementById("flowStatus");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8df);
scene.fog = new THREE.Fog(0xdce8df, 25, 46);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.04;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf7fcff, 0x71805b, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.0);
sun.position.set(7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc5e9ee, 0.65);
fill.position.set(-8, 6, -8);
scene.add(fill);
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const valvePickMeshes = [];
const branches = [];
// Custom camera controls: no addons or example modules.
const cameraState = {
theta: 0.56,
phi: 0.76,
radius: 17.4,
target: new THREE.Vector3(0, 0.1, -0.4)
};
function updateCamera() {
const aspectBoost = Math.max(1, 0.94 / camera.aspect);
const r = cameraState.radius * aspectBoost;
const horizontal = Math.cos(cameraState.phi);
const target = cameraState.target;
camera.position.set(
target.x + r * Math.sin(cameraState.theta) * horizontal,
target.y + r * Math.sin(cameraState.phi),
target.z + r * Math.cos(cameraState.theta) * horizontal
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
// -------------------------------------------------------------------------
// Materials and procedural textures
// -------------------------------------------------------------------------
function makeWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#b97948";
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < 85; i++) {
const y = Math.random() * canvas.height;
const x = Math.random() * canvas.width;
const length = 15 + Math.random() * 85;
ctx.strokeStyle =
Math.random() > 0.5
? "rgba(86,43,22,0.16)"
: "rgba(255,208,145,0.15)";
ctx.lineWidth = 0.5 + Math.random() * 1.4;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.bezierCurveTo(
x + length * 0.3,
y + Math.random() * 4 - 2,
x + length * 0.7,
y + Math.random() * 4 - 2,
x + length,
y
);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2, 1);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeSoilTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#70503a";
ctx.fillRect(0, 0, 256, 256);
for (let i = 0; i < 1500; i++) {
const x = Math.random() * 256;
const y = Math.random() * 256;
const radius = 0.3 + Math.random() * 1.8;
ctx.fillStyle =
Math.random() > 0.45
? "rgba(35,24,18,0.30)"
: "rgba(185,143,96,0.24)";
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3, 2);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const woodTexture = makeWoodTexture();
const soilTexture = makeSoilTexture();
const materials = {
wood: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xffffff,
roughness: 0.88
}),
woodLight: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xffd4a0,
roughness: 0.9
}),
soil: new THREE.MeshStandardMaterial({
map: soilTexture,
color: 0xffffff,
roughness: 1
}),
grass: new THREE.MeshStandardMaterial({
color: 0x91ad78,
roughness: 0.98
}),
grassDark: new THREE.MeshStandardMaterial({
color: 0x789a67,
roughness: 0.98
}),
path: new THREE.MeshStandardMaterial({
color: 0xd7c29c,
roughness: 0.94
}),
pathEdge: new THREE.MeshStandardMaterial({
color: 0xbca57e,
roughness: 0.95
}),
brass: new THREE.MeshStandardMaterial({
color: 0xd3a84e,
roughness: 0.35,
metalness: 0.68
}),
mainHose: new THREE.MeshStandardMaterial({
color: 0x236c70,
roughness: 0.42,
metalness: 0.03
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x4f8d48,
roughness: 0.86
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x73ad55,
roughness: 0.84
}),
leafDark: new THREE.MeshStandardMaterial({
color: 0x356f43,
roughness: 0.9
}),
tomato: new THREE.MeshStandardMaterial({
color: 0xdb5542,
roughness: 0.48
}),
orange: new THREE.MeshStandardMaterial({
color: 0xe78b38,
roughness: 0.66
}),
carrot: new THREE.MeshStandardMaterial({
color: 0xe67829,
roughness: 0.72
}),
flowerPink: new THREE.MeshStandardMaterial({
color: 0xe997a8,
roughness: 0.7
}),
flowerYellow: new THREE.MeshStandardMaterial({
color: 0xf0c954,
roughness: 0.7
})
};
function addMesh(geometry, material, position, parent = scene) {
const object = new THREE.Mesh(geometry, material);
object.position.set(position[0], position[1], position[2]);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
// -------------------------------------------------------------------------
// Ground, path, fence, and central island
// -------------------------------------------------------------------------
const ground = addMesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0xa8bd91,
roughness: 1
}),
[0, -0.12, 0]
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
addMesh(
new THREE.BoxGeometry(13.4, 0.12, 11.8),
materials.grassDark,
[0, -0.055, -0.55]
);
function roundedRectShape(width, depth, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -depth / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + depth - radius);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - radius,
y + depth
);
shape.lineTo(x + radius, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const pathGeometry = new THREE.ShapeGeometry(
roundedRectShape(4.35, 3.72, 0.58),
24
);
pathGeometry.rotateX(-Math.PI / 2);
addMesh(pathGeometry, materials.path, [0, 0.018, 0]);
const islandGeometry = new THREE.ShapeGeometry(
roundedRectShape(2.62, 1.88, 0.45),
24
);
islandGeometry.rotateX(-Math.PI / 2);
addMesh(islandGeometry, materials.grass, [0, 0.032, 0]);
function addFence() {
const postGeo = new THREE.BoxGeometry(0.13, 0.85, 0.13);
const railGeo = new THREE.BoxGeometry(12.4, 0.1, 0.09);
for (let x = -6; x <= 6; x += 2) {
addMesh(postGeo, materials.woodLight, [x, 0.39, -6.18]);
}
addMesh(railGeo, materials.wood, [0, 0.34, -6.18]);
addMesh(railGeo, materials.wood, [0, 0.62, -6.18]);
const sidePostGeo = new THREE.BoxGeometry(0.13, 0.85, 0.13);
const sideRailGeo = new THREE.BoxGeometry(0.09, 0.1, 10.7);
for (const side of [-1, 1]) {
for (let z = -6; z <= 4; z += 2) {
addMesh(sidePostGeo, materials.woodLight, [side * 6.2, 0.39, z]);
}
addMesh(sideRailGeo, materials.wood, [side * 6.2, 0.48, -0.9]);
}
}
addFence();
function addShrub(x, z, color = 0x4e8448) {
const shrub = new THREE.Group();
shrub.position.set(x, 0.05, z);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.92
});
addMesh(
new THREE.SphereGeometry(0.18, 10, 8),
material,
[0, 0.13, 0],
shrub
);
addMesh(
new THREE.SphereGeometry(0.14, 10, 8),
materials.leafLight,
[0.12, 0.12, 0.05],
shrub
);
addMesh(
new THREE.SphereGeometry(0.13, 10, 8),
materials.leafDark,
[-0.11, 0.11, 0.03],
shrub
);
scene.add(shrub);
}
addShrub(-0.76, -0.48);
addShrub(0.66, -0.48, 0x5a934f);
addShrub(-0.73, 0.46, 0x3f7c4a);
addShrub(0.69, 0.46, 0x669c51);
// A small watering can supplies a human-scale reference.
const can = new THREE.Group();
can.position.set(0.42, 0.06, 0.35);
can.rotation.y = -0.35;
addMesh(
new THREE.CylinderGeometry(0.2, 0.24, 0.32, 16),
new THREE.MeshStandardMaterial({
color: 0x4f8f8c,
roughness: 0.55
}),
[0, 0.16, 0],
can
);
const handle = addMesh(
new THREE.TorusGeometry(0.18, 0.028, 8, 20, Math.PI * 1.55),
materials.mainHose,
[-0.16, 0.18, 0],
can
);
handle.rotation.z = -0.25;
const spout = addMesh(
new THREE.CylinderGeometry(0.045, 0.07, 0.48, 10),
materials.mainHose,
[0.28, 0.22, 0],
can
);
spout.rotation.z = -0.85;
scene.add(can);
// -------------------------------------------------------------------------
// Transparent reservoir and feed hose
// -------------------------------------------------------------------------
const reservoir = new THREE.Group();
reservoir.position.set(0, 0, -5.25);
scene.add(reservoir);
addMesh(
new THREE.BoxGeometry(1.6, 0.13, 1.3),
materials.woodLight,
[0, 0.1, 0],
reservoir
);
for (const x of [-0.54, 0.54]) {
addMesh(
new THREE.BoxGeometry(0.14, 0.55, 0.14),
materials.wood,
[x, 0.39, 0],
reservoir
);
}
const shellMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc3eeee,
transparent: true,
opacity: 0.3,
roughness: 0.12,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const shell = addMesh(
new THREE.CylinderGeometry(0.72, 0.72, 1.5, 32, 1, true),
shellMaterial,
[0, 1.05, 0],
reservoir
);
shell.castShadow = false;
shell.renderOrder = 3;
const water = addMesh(
new THREE.CylinderGeometry(0.665, 0.665, 0.98, 32),
new THREE.MeshPhysicalMaterial({
color: 0x35b9cf,
transparent: true,
opacity: 0.58,
roughness: 0.12,
transmission: 0.15,
depthWrite: false
}),
[0, 0.79, 0],
reservoir
);
water.castShadow = false;
water.renderOrder = 2;
const ringGeometry = new THREE.TorusGeometry(0.72, 0.035, 8, 32);
for (const y of [0.3, 1.8]) {
const ring = addMesh(
ringGeometry,
materials.mainHose,
[0, y, 0],
reservoir
);
ring.rotation.x = Math.PI / 2;
}
addMesh(
new THREE.CylinderGeometry(0.72, 0.72, 0.055, 32),
new THREE.MeshPhysicalMaterial({
color: 0xc3eeee,
transparent: true,
opacity: 0.28,
roughness: 0.15,
depthWrite: false
}),
[0, 1.82, 0],
reservoir
);
const outlet = addMesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.28, 12),
materials.brass,
[0, 0.48, 0.78],
reservoir
);
outlet.rotation.x = Math.PI / 2;
function makePlaqueTexture(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f2e8cf";
ctx.fillRect(0, 0, 512, 128);
ctx.strokeStyle = "#577d70";
ctx.lineWidth = 8;
ctx.strokeRect(5, 5, 502, 118);
ctx.fillStyle = "#315c53";
ctx.font = "700 37px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const plaque = addMesh(
new THREE.PlaneGeometry(1.22, 0.31),
new THREE.MeshBasicMaterial({
map: makePlaqueTexture("WATER RESERVOIR"),
side: THREE.DoubleSide
}),
[0, 0.52, 0.735],
reservoir
);
plaque.castShadow = false;
// -------------------------------------------------------------------------
// Crops
// -------------------------------------------------------------------------
const leafGeometry = new THREE.SphereGeometry(0.16, 10, 8);
const smallLeafGeometry = new THREE.SphereGeometry(0.1, 8, 6);
function addTomato(x, z, parent) {
const plant = new THREE.Group();
plant.position.set(x, 0.42, z);
parent.add(plant);
addMesh(
new THREE.CylinderGeometry(0.025, 0.04, 0.57, 8),
materials.leafDark,
[0, 0.285, 0],
plant
);
const leafPositions = [
[-0.13, 0.32, 0],
[0.13, 0.38, 0.02],
[-0.1, 0.49, 0.03],
[0.11, 0.52, -0.02]
];
leafPositions.forEach((p, i) => {
const leaf = addMesh(
leafGeometry,
i % 2 ? materials.leaf : materials.leafLight,
p,
plant
);
leaf.scale.set(1.3, 0.22, 0.6);
leaf.rotation.z = i % 2 ? 0.28 : -0.28;
leaf.rotation.y = i * 1.4;
});
addMesh(
new THREE.SphereGeometry(0.09, 12, 10),
materials.tomato,
[0.09, 0.26, 0.07],
plant
);
addMesh(
new THREE.SphereGeometry(0.075, 12, 10),
materials.orange,
[-0.09, 0.41, 0.07],
plant
);
}
function addCabbage(x, z, parent) {
const plant = new THREE.Group();
plant.position.set(x, 0.42, z);
parent.add(plant);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = addMesh(
leafGeometry,
i % 2 ? materials.leafLight : materials.leaf,
[
Math.cos(angle) * 0.14,
0.09,
Math.sin(angle) * 0.14
],
plant
);
leaf.scale.set(1.05, 0.42, 0.7);
leaf.rotation.y = angle;
leaf.rotation.z = Math.cos(angle) * 0.28;
}
addMesh(
new THREE.SphereGeometry(0.11, 10, 8),
materials.leafLight,
[0, 0.18, 0],
plant
);
}
function addCarrot(x, z, parent) {
const plant = new THREE.Group();
plant.position.set(x, 0.42, z);
parent.add(plant);
const carrot = addMesh(
new THREE.ConeGeometry(0.095, 0.32, 9),
materials.carrot,
[0, 0.12, 0],
plant
);
carrot.rotation.z = Math.PI;
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const leaf = addMesh(
smallLeafGeometry,
i % 2 ? materials.leaf : materials.leafLight,
[
Math.cos(angle) * 0.05,
0.3,
Math.sin(angle) * 0.05
],
plant
);
leaf.scale.set(0.45, 1.2, 0.35);
leaf.rotation.z = Math.cos(angle) * 0.45;
leaf.rotation.x = Math.sin(angle) * 0.45;
}
}
function addHerb(x, z, parent) {
const plant = new THREE.Group();
plant.position.set(x, 0.42, z);
parent.add(plant);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const stem = addMesh(
new THREE.CylinderGeometry(0.012, 0.018, 0.3, 6),
materials.leafDark,
[Math.cos(angle) * 0.04, 0.15, Math.sin(angle) * 0.04],
plant
);
stem.rotation.z = Math.cos(angle) * 0.25;
stem.rotation.x = Math.sin(angle) * 0.25;
const leaf = addMesh(
smallLeafGeometry,
i % 2 ? materials.leafLight : materials.leaf,
[
Math.cos(angle) * 0.1,
0.25 + (i % 2) * 0.04,
Math.sin(angle) * 0.1
],
plant
);
leaf.scale.set(1.35, 0.45, 0.75);
leaf.rotation.y = angle;
}
}
// -------------------------------------------------------------------------
// Raised beds
// -------------------------------------------------------------------------
const bedConfigs = [
{
id: "ne",
title: "NE / TOMATOES",
shortTitle: "North-east",
crop: "Tomatoes",
sx: 1,
sz: -1,
cx: 3.35,
cz: -2.85,
start: [1.3, -1.72],
valve: [1.58, -1.88],
manifoldStart: [2.05, -2.3],
manifoldEnd: [4.45, -2.3],
taps: [2.55, 3.35, 4.15],
tipZ: -3.05,
open: false
},
{
id: "nw",
title: "NW / CABBAGES",
shortTitle: "North-west",
crop: "Cabbages",
sx: -1,
sz: -1,
cx: -3.35,
cz: -2.85,
start: [-1.3, -1.72],
valve: [-1.58, -1.88],
manifoldStart: [-2.05, -2.3],
manifoldEnd: [-4.45, -2.3],
taps: [-2.55, -3.35, -4.15],
tipZ: -3.05,
open: false
},
{
id: "sw",
title: "SW / CARROTS",
shortTitle: "South-west",
crop: "Root carrots",
sx: -1,
sz: 1,
cx: -3.35,
cz: 2.85,
start: [-1.3, 1.72],
valve: [-1.58, 1.88],
manifoldStart: [-2.05, 2.3],
manifoldEnd: [-4.45, 2.3],
taps: [-2.55, -3.35, -4.15],
tipZ: 3.05,
open: false
},
{
id: "se",
title: "SE / KITCHEN HERBS",
shortTitle: "South-east",
crop: "Kitchen herbs",
sx: 1,
sz: 1,
cx: 3.35,
cz: 2.85,
start: [1.3, 1.72],
valve: [1.58, 1.88],
manifoldStart: [2.05, 2.3],
manifoldEnd: [4.45, 2.3],
taps: [2.55, 3.35, 4.15],
tipZ: 3.05,
open: true
}
];
function createBed(config) {
const group = new THREE.Group();
group.position.set(config.cx, 0, config.cz);
scene.add(group);
const width = 3.1;
const depth = 2.3;
addMesh(
new THREE.BoxGeometry(width, 0.42, 0.15),
materials.wood,
[0, 0.31, -depth / 2 + 0.075],
group
);
addMesh(
new THREE.BoxGeometry(width, 0.42, 0.15),
materials.woodLight,
[0, 0.31, depth / 2 - 0.075],
group
);
addMesh(
new THREE.BoxGeometry(0.15, 0.42, depth - 0.2),
materials.wood,
[-width / 2 + 0.075, 0.31, 0],
group
);
addMesh(
new THREE.BoxGeometry(0.15, 0.42, depth - 0.2),
materials.woodLight,
[width / 2 - 0.075, 0.31, 0],
group
);
const postGeometry = new THREE.BoxGeometry(0.19, 0.68, 0.19);
for (const x of [-width / 2 + 0.09, width / 2 - 0.09]) {
for (const z of [-depth / 2 + 0.09, depth / 2 - 0.09]) {
addMesh(postGeometry, materials.wood, [x, 0.34, z], group);
}
}
addMesh(
new THREE.BoxGeometry(width - 0.25, 0.17, depth - 0.25),
materials.soil,
[0, 0.33, 0],
group
);
const rowZ = config.sz * 0.72;
if (config.id === "ne") {
[-1.05, 0, 1.05].forEach((x) => addTomato(x, rowZ, group));
} else if (config.id === "nw") {
[-1.05, 0, 1.05].forEach((x) => addCabbage(x, rowZ, group));
} else if (config.id === "sw") {
[-1.05, 0, 1.05].forEach((x) => addCarrot(x, rowZ, group));
} else {
[-1.05, 0, 1.05].forEach((x) => addHerb(x, rowZ, group));
}
}
bedConfigs.forEach(createBed);
// -------------------------------------------------------------------------
// Continuous main hose loop along the path edge
// -------------------------------------------------------------------------
const mainHosePoints = [
new THREE.Vector3(0, 0.145, -1.72),
new THREE.Vector3(1.3, 0.145, -1.72),
new THREE.Vector3(1.95, 0.145, -1.15),
new THREE.Vector3(1.95, 0.145, 1.15),
new THREE.Vector3(1.3, 0.145, 1.72),
new THREE.Vector3(0, 0.145, 1.72),
new THREE.Vector3(-1.3, 0.145, 1.72),
new THREE.Vector3(-1.95, 0.145, 1.15),
new THREE.Vector3(-1.95, 0.145, -1.15),
new THREE.Vector3(-1.3, 0.145, -1.72)
];
const mainCurve = new THREE.CatmullRomCurve3(
mainHosePoints,
true,
"centripetal"
);
addMesh(
new THREE.TubeGeometry(mainCurve, 180, 0.083, 10, true),
materials.mainHose,
[0, 0, 0]
);
const feedCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(0, 0.48, -4.46),
new THREE.Vector3(0, 0.3, -4.1),
new THREE.Vector3(0, 0.16, -3.0),
new THREE.Vector3(0, 0.145, -1.72)
],
false,
"centripetal"
);
addMesh(
new THREE.TubeGeometry(feedCurve, 70, 0.083, 10, false),
materials.mainHose,
[0, 0, 0]
);
addMesh(
new THREE.SphereGeometry(0.115, 12, 10),
materials.brass,
[0, 0.145, -1.72]
);
// -------------------------------------------------------------------------
// Branch hoses, valves, outlets, and moving water markers
// -------------------------------------------------------------------------
const markerGeometry = new THREE.SphereGeometry(0.077, 10, 8);
const markerAxis = new THREE.Vector3(0, 0, 1);
function createValve(config, branch) {
const group = new THREE.Group();
group.position.set(config.valve[0], 0.28, config.valve[1]);
scene.add(group);
const body = addMesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.2, 12),
materials.brass,
[0, 0, 0],
group
);
body.rotation.z = Math.PI / 2;
addMesh(
new THREE.CylinderGeometry(0.034, 0.034, 0.22, 8),
materials.brass,
[0, 0.12, 0],
group
);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0xdf655f,
roughness: 0.38,
metalness: 0.12,
emissive: 0x000000
});
const wheel = new THREE.Group();
wheel.position.y = 0.25;
group.add(wheel);
const rim = addMesh(
new THREE.TorusGeometry(0.17, 0.032, 8, 24),
wheelMaterial,
[0, 0, 0],
wheel
);
rim.rotation.x = Math.PI / 2;
addMesh(
new THREE.BoxGeometry(0.28, 0.025, 0.025),
wheelMaterial,
[0, 0, 0],
wheel
);
addMesh(
new THREE.BoxGeometry(0.025, 0.025, 0.28),
wheelMaterial,
[0, 0, 0],
wheel
);
const indicator = addMesh(
new THREE.SphereGeometry(0.046, 10, 8),
new THREE.MeshStandardMaterial({
color: 0xdf655f,
roughness: 0.35,
emissive: 0x5a1110,
emissiveIntensity: 0.25
}),
[0.21, -0.035, 0],
group
);
const pickProxy = new THREE.Mesh(
new THREE.SphereGeometry(0.33, 12, 10),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
})
);
pickProxy.position.y = 0.23;
pickProxy.userData.branchId = config.id;
group.add(pickProxy);
valvePickMeshes.push(pickProxy);
branch.wheel = wheel;
branch.wheelMaterial = wheelMaterial;
branch.indicator = indicator;
}
function createBranch(config) {
const branch = {
config,
open: config.open,
markers: [],
routes: [],
lengths: []
};
const start = new THREE.Vector3(config.start[0], 0.145, config.start[1]);
const valve = new THREE.Vector3(config.valve[0], 0.28, config.valve[1]);
const lift = new THREE.Vector3(
config.sx * 1.72,
0.68,
config.sz * 1.98
);
const manifoldStart = new THREE.Vector3(
config.manifoldStart[0],
0.64,
config.manifoldStart[1]
);
const manifoldEnd = new THREE.Vector3(
config.manifoldEnd[0],
0.64,
config.manifoldEnd[1]
);
const trunk = new THREE.CatmullRomCurve3(
[start, valve, lift, manifoldStart],
false,
"centripetal"
);
const hoseMaterial = new THREE.MeshStandardMaterial({
color: 0x258b96,
roughness: 0.38,
metalness: 0.02,
emissive: 0x000000,
emissiveIntensity: 0
});
branch.hoseMaterial = hoseMaterial;
addMesh(
new THREE.TubeGeometry(trunk, 55, 0.054, 9, false),
hoseMaterial,
[0, 0, 0]
);
const manifold = new THREE.LineCurve3(manifoldStart, manifoldEnd);
addMesh(
new THREE.TubeGeometry(manifold, 1, 0.044, 8, false),
hoseMaterial,
[0, 0, 0]
);
addMesh(
new THREE.SphereGeometry(0.08, 10, 8),
hoseMaterial,
manifoldStart.toArray()
);
// Visible junction at the main loop.
addMesh(
new THREE.SphereGeometry(0.105, 12, 10),
materials.mainHose,
start.toArray()
);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x8ff7ff,
transparent: true,
opacity: config.open ? 0.98 : 0.18,
depthWrite: false
});
branch.markerMaterial = markerMaterial;
config.taps.forEach((tapX, routeIndex) => {
const tap = new THREE.Vector3(tapX, 0.64, config.sz * 2.3);
const outletTip = new THREE.Vector3(tapX, 0.47, config.tipZ);
const outletCurve = new THREE.LineCurve3(tap, outletTip);
addMesh(
new THREE.TubeGeometry(outletCurve, 1, 0.031, 7, false),
hoseMaterial,
[0, 0, 0]
);
const outletNozzle = addMesh(
new THREE.CylinderGeometry(0.062, 0.062, 0.055, 10),
materials.brass,
tap.toArray()
);
outletNozzle.rotation.x = Math.PI / 2;
addMesh(
new THREE.SphereGeometry(0.052, 8, 6),
new THREE.MeshBasicMaterial({ color: 0x5de5ef }),
outletTip.toArray()
);
const route = new THREE.CurvePath();
route.add(trunk);
route.add(new THREE.LineCurve3(manifoldStart, tap));
route.add(new THREE.LineCurve3(tap, outletTip));
const routeLength = route.getLength();
branch.routes.push(route);
branch.lengths.push(routeLength);
for (let markerIndex = 0; markerIndex < 2; markerIndex++) {
const marker = addMesh(
markerGeometry,
markerMaterial,
[0, 0, 0]
);
marker.castShadow = false;
marker.scale.set(0.74, 0.74, 1.85);
branch.markers.push({
mesh: marker,
routeIndex,
progress: config.open
? (routeIndex * 0.29 + markerIndex * 0.43) % 1
: 0
});
}
});
createValve(config, branch);
const label = document.createElement("button");
label.type = "button";
label.className = "valve-label";
label.innerHTML = `
<span class="dot"></span>
<span>
<strong>${config.title}</strong>
<small>${config.open ? "OPEN · FLOWING" : "CLOSED · PAUSED"}</small>
</span>
`;
label.setAttribute(
"aria-label",
`Toggle irrigation valve for ${config.crop}`
);
label.addEventListener("click", (event) => {
event.stopPropagation();
toggleBranch(branch);
});
labelLayer.appendChild(label);
branch.label = label;
branch.labelAnchor = new THREE.Vector3(
config.valve[0],
0.78,
config.valve[1]
);
branches.push(branch);
updateBranchVisual(branch);
}
bedConfigs.forEach(createBranch);
function updateBranchVisual(branch) {
const isOpen = branch.open;
const color = isOpen ? 0x43b96b : 0xdf655f;
branch.wheelMaterial.color.setHex(color);
branch.wheelMaterial.emissive.setHex(isOpen ? 0x0c4f27 : 0x4b1110);
branch.wheelMaterial.emissiveIntensity = isOpen ? 0.28 : 0.08;
branch.wheel.rotation.y = isOpen ? 0 : Math.PI / 4;
branch.indicator.material.color.setHex(color);
branch.indicator.material.emissive.setHex(isOpen ? 0x0d7138 : 0x5a1110);
branch.hoseMaterial.emissive.setHex(isOpen ? 0x07535c : 0x000000);
branch.hoseMaterial.emissiveIntensity = isOpen ? 0.35 : 0;
branch.markerMaterial.opacity = isOpen ? 0.98 : 0.18;
branch.label.classList.toggle("open", isOpen);
branch.label.querySelector("small").textContent = isOpen
? "OPEN · FLOWING"
: "CLOSED · PAUSED";
updateFlowStatus();
}
function updateFlowStatus() {
const count = branches.filter((branch) => branch.open).length;
flowStatus.textContent =
count === 0
? "All branches paused"
: `${count} branch${count === 1 ? "" : "es"} flowing`;
}
function toggleBranch(branch) {
branch.open = !branch.open;
updateBranchVisual(branch);
}
// -------------------------------------------------------------------------
// Animation: only open branches advance. Closed markers remain stationary.
// -------------------------------------------------------------------------
function updateMarkers(delta) {
branches.forEach((branch) => {
branch.markers.forEach((marker) => {
if (branch.open) {
const speed = 0.52;
marker.progress =
(marker.progress +
(delta * speed) / branch.lengths[marker.routeIndex]) %
1;
}
const route = branch.routes[marker.routeIndex];
const position = route.getPointAt(marker.progress);
const tangent = route.getTangentAt(marker.progress).normalize();
marker.mesh.position.copy(position);
marker.mesh.quaternion.setFromUnitVectors(markerAxis, tangent);
});
});
}
const projected = new THREE.Vector3();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
branches.forEach((branch) => {
projected.copy(branch.labelAnchor).project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
branch.label.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
branch.label.style.left = `${x}px`;
branch.label.style.top = `${y}px`;
});
}
// -------------------------------------------------------------------------
// Pointer picking and direct camera controls
// -------------------------------------------------------------------------
let dragging = false;
let pointerMoved = false;
let lastX = 0;
let lastY = 0;
let downX = 0;
let downY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
lastX = downX = event.clientX;
lastY = downY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.hypot(event.clientX - downX, event.clientY - downY) > 5) {
pointerMoved = true;
}
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.42,
1.24
);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
camera.updateMatrixWorld();
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(valvePickMeshes, false);
if (hits.length) {
const branch = branches.find(
(item) => item.config.id === hits[0].object.userData.branchId
);
if (branch) toggleBranch(branch);
}
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerMoved = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
12,
26
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
document.getElementById("resetView").addEventListener("click", () => {
cameraState.theta = 0.56;
cameraState.phi = 0.76;
cameraState.radius = 17.4;
updateCamera();
});
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateFlowStatus();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateMarkers(delta);
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```