Prompt specification
Build or customize the Three.js 3D scene "Greenhouse misting comparison" 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: Greenhouse misting comparison
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/greenhouse-misting-comparison-x0068
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a low-poly greenhouse watering comparison. Arrange three identical plant benches under a simple greenhouse frame. One station uses a hand spray bottle, another has a drip tube, and the third receives a watering-can stream. Controls activate each method separately. Show fine droplets landing across a broad patch for the spray, localized wet spots under drip outlets, and a continuous poured path from the can. Use matching soil trays so the patterns can be compared, keeping the model qualitative rather than assigning real agronomic efficiency values. Frame the benches from above and slightly to the side, with tools resting visibly at their stations.
Working Three.js Starter (greenhouse-misting-comparison-x0068):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Greenhouse Watering Comparison</title>
<style>
:root {
--ink: #18332c;
--muted: #60736d;
--panel: rgba(250, 253, 249, 0.91);
--line: rgba(29, 67, 56, 0.14);
--spray: #ee725f;
--drip: #2688c7;
--can: #d99a2b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
width: min(350px, calc(100vw - 44px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(37, 62, 53, 0.11);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #668078;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.1vw, 28px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.controls-wrap {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 20;
width: min(780px, calc(100vw - 32px));
transform: translateX(-50%);
pointer-events: none;
}
.controls {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
gap: 8px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(249, 252, 248, 0.94);
box-shadow: 0 18px 50px rgba(31, 58, 48, 0.16);
backdrop-filter: blur(14px);
pointer-events: auto;
}
button {
appearance: none;
border: 0;
font: inherit;
color: inherit;
cursor: pointer;
}
.method {
position: relative;
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
min-height: 58px;
padding: 8px 12px;
border: 1px solid transparent;
border-radius: 12px;
background: transparent;
text-align: left;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.method:hover {
background: rgba(35, 76, 64, 0.06);
transform: translateY(-1px);
}
.method.active {
background: color-mix(in srgb, var(--accent) 12%, white);
border-color: color-mix(in srgb, var(--accent) 42%, transparent);
}
.method[data-method="spray"] {
--accent: var(--spray);
}
.method[data-method="drip"] {
--accent: var(--drip);
}
.method[data-method="can"] {
--accent: var(--can);
}
.icon {
display: grid;
flex: 0 0 auto;
width: 34px;
height: 34px;
place-items: center;
border-radius: 10px;
color: var(--accent);
background: color-mix(in srgb, var(--accent) 14%, white);
}
.icon svg {
width: 21px;
height: 21px;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
}
.method-text {
min-width: 0;
}
.method strong,
.method small {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.method strong {
font-size: 12px;
letter-spacing: -0.01em;
}
.method small {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.key {
position: absolute;
top: 5px;
right: 7px;
color: #91a19c;
font-size: 9px;
font-weight: 700;
}
#reset {
align-self: stretch;
min-width: 58px;
padding: 0 13px;
border-radius: 12px;
background: #edf2ee;
color: #536a62;
font-size: 11px;
font-weight: 750;
}
#reset:hover {
background: #e2ebe5;
}
.caption {
display: flex;
justify-content: space-between;
gap: 14px;
margin-top: 8px;
padding: 0 5px;
color: #4e655d;
font-size: 10px;
line-height: 1.35;
text-shadow: 0 1px 3px rgba(255, 255, 255, 0.8);
pointer-events: none;
}
.caption strong {
color: #294c40;
}
#labels {
position: fixed;
inset: 0;
z-index: 8;
pointer-events: none;
}
.station-label {
position: absolute;
min-width: 108px;
padding: 7px 10px 6px;
border: 1px solid rgba(36, 67, 57, 0.15);
border-top: 3px solid var(--accent);
border-radius: 9px;
background: rgba(252, 254, 251, 0.9);
box-shadow: 0 7px 20px rgba(34, 60, 51, 0.1);
transform: translate(-50%, -100%);
text-align: center;
backdrop-filter: blur(7px);
}
.station-label strong,
.station-label small {
display: block;
white-space: nowrap;
}
.station-label strong {
color: #26463b;
font-size: 11px;
}
.station-label small {
margin-top: 1px;
color: #6b7d77;
font-size: 9px;
}
#status {
position: fixed;
top: 24px;
right: 24px;
z-index: 10;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(249, 252, 248, 0.87);
color: #4d685f;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
pointer-events: none;
backdrop-filter: blur(10px);
}
@media (max-width: 720px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.intro p {
display: none;
}
#status {
display: none;
}
.controls-wrap {
bottom: 12px;
width: calc(100vw - 24px);
}
.controls {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.method {
justify-content: center;
min-height: 52px;
padding: 7px 5px;
}
.method .method-text,
.key {
display: none;
}
#reset {
grid-column: 1 / -1;
min-height: 32px;
}
.caption {
display: block;
text-align: center;
}
.caption span:last-child {
display: none;
}
.station-label {
min-width: 90px;
padding: 5px 7px;
}
.station-label small {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="intro">
<div class="eyebrow">Greenhouse study</div>
<h1>Watering methods,<br />side by side.</h1>
<p>
Activate each station to compare where water lands. The trays, plants,
and benches are matched so the visible wetting patterns can be compared.
</p>
</section>
<div id="status" aria-live="polite">Choose a watering method</div>
<div id="labels">
<div class="station-label" style="--accent: var(--spray)">
<strong>Hand spray</strong>
<small>Fine, dispersed droplets</small>
</div>
<div class="station-label" style="--accent: var(--drip)">
<strong>Drip tube</strong>
<small>Localized outlet spots</small>
</div>
<div class="station-label" style="--accent: var(--can)">
<strong>Watering can</strong>
<small>Continuous poured stream</small>
</div>
</div>
<div class="controls-wrap">
<div class="controls" aria-label="Watering method controls">
<button
class="method"
data-method="spray"
aria-pressed="false"
title="Toggle hand spray"
>
<span class="key">1</span>
<span class="icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M8 8h7v12H8z" />
<path d="M9 8V5h4v3M15 11h4v3h-4M19 7v11" />
<path d="m20 4-.5 1.5L18 6l1.5.5L20 8l.5-1.5L22 6l-1.5-.5z" />
</svg>
</span>
<span class="method-text">
<strong>Hand spray</strong>
<small>Broad droplet patch</small>
</span>
</button>
<button
class="method"
data-method="drip"
aria-pressed="false"
title="Toggle drip tube"
>
<span class="key">2</span>
<span class="icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M5 5v5h8V5M9 10v3c0 2 2 2 2 4" />
<path d="M13 15c0 2-2 2-2 4M17 15c0 2-2 2-2 4" />
<path d="M4 3h10v3H4z" />
</svg>
</span>
<span class="method-text">
<strong>Drip tube</strong>
<small>Separate wet spots</small>
</span>
</button>
<button
class="method"
data-method="can"
aria-pressed="false"
title="Toggle watering can"
>
<span class="key">3</span>
<span class="icon">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M5 8h10v10H5zM7 8V5h6v3" />
<path d="m15 11 4-4 2 2-4 5M19 5l1-2" />
<path d="M17 7c2 0 3 2 3 4" />
</svg>
</span>
<span class="method-text">
<strong>Watering can</strong>
<small>Continuous stream</small>
</span>
</button>
<button id="reset" title="Clear all wet marks and stop">Reset</button>
</div>
<div class="caption">
<span><strong>Dark soil marks are wet areas.</strong> Patterns are illustrative, not efficiency measurements.</span>
<span>Drag to orbit · scroll to zoom</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.08;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e4);
scene.fog = new THREE.Fog(0xdce9e4, 25, 46);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 0.47,
phi: 1.02,
radius: window.innerWidth < 720 ? 31 : 19.5,
target: new THREE.Vector3(0, 1.55, 0),
dragging: false,
previousX: 0,
previousY: 0
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
// Small, self-contained orbit implementation; no controls addon.
renderer.domElement.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.previousX = event.clientX;
cameraState.previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.previousX;
const dy = event.clientY - cameraState.previousY;
cameraState.previousX = event.clientX;
cameraState.previousY = event.clientY;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.004,
0.57,
1.36
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
cameraState.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
cameraState.dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
12,
36
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------
// Lighting and shared materials
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf8fff9, 0x52695f, 2.0));
const sun = new THREE.DirectionalLight(0xfff8e8, 3.2);
sun.position.set(-8, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcde9f3, 1.0);
fill.position.set(10, 7, -8);
scene.add(fill);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xcbd6ce,
roughness: 0.96
}),
aisle: new THREE.MeshStandardMaterial({
color: 0xe1e2d8,
roughness: 0.94
}),
frame: new THREE.MeshStandardMaterial({
color: 0x789087,
roughness: 0.62,
metalness: 0.18
}),
benchTop: new THREE.MeshStandardMaterial({
color: 0xa8794d,
roughness: 0.86
}),
benchLeg: new THREE.MeshStandardMaterial({
color: 0x4e635b,
roughness: 0.72,
metalness: 0.12
}),
tray: new THREE.MeshStandardMaterial({
color: 0x8c6543,
roughness: 0.88
}),
stem: new THREE.MeshStandardMaterial({
color: 0x397743,
roughness: 0.88
}),
leafA: new THREE.MeshStandardMaterial({
color: 0x4e9b51,
roughness: 0.9,
flatShading: true
}),
leafB: new THREE.MeshStandardMaterial({
color: 0x75b85e,
roughness: 0.9,
flatShading: true
}),
water: new THREE.MeshStandardMaterial({
color: 0x72d5ed,
roughness: 0.2,
metalness: 0.05,
transparent: true,
opacity: 0.78,
depthWrite: false
}),
brightWater: new THREE.MeshStandardMaterial({
color: 0xd4f8ff,
roughness: 0.2,
transparent: true,
opacity: 0.72,
depthWrite: false
}),
tube: new THREE.MeshStandardMaterial({
color: 0x263f3b,
roughness: 0.55
}),
spray: new THREE.MeshStandardMaterial({
color: 0xee725f,
roughness: 0.46
}),
sprayDark: new THREE.MeshStandardMaterial({
color: 0x87463f,
roughness: 0.48
}),
drip: new THREE.MeshStandardMaterial({
color: 0x2688c7,
roughness: 0.4
}),
can: new THREE.MeshStandardMaterial({
color: 0xd99a2b,
roughness: 0.46,
metalness: 0.08
}),
canDark: new THREE.MeshStandardMaterial({
color: 0x88651e,
roughness: 0.55
})
};
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd8f1ec,
transparent: true,
opacity: 0.075,
roughness: 0.15,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
// ------------------------------------------------------------
// Helpers
// ------------------------------------------------------------
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
radialSegments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, width, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, width),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function tubeFromPoints(points, radius, material, segments = 40) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 7, false),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function quadGeometry(a, b, c, d) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[...a, ...b, ...c, ...a, ...c, ...d],
3
)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(
[0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1],
2
)
);
geometry.computeVertexNormals();
return geometry;
}
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6d2b79f5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function randomNormal() {
let u = 0;
let v = 0;
while (u === 0) u = Math.random();
while (v === 0) v = Math.random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
// ------------------------------------------------------------
// Greenhouse floor and frame
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(31, 16),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
addBox(
scene,
[21.5, 0.045, 1.55],
[0, 0.012, 2.65],
materials.aisle,
false
);
const postXs = [-9.7, 9.7];
const postZs = [-3.7, 3.7];
for (const x of postXs) {
for (const z of postZs) {
addBox(
scene,
[0.16, 4.55, 0.16],
[x, 2.275, z],
materials.frame
);
addBox(
scene,
[0.38, 0.12, 0.38],
[x, 0.06, z],
materials.frame
);
}
}
for (const z of postZs) {
beamBetween([-9.7, 4.5, z], [9.7, 4.5, z], 0.14, materials.frame);
}
beamBetween([-9.7, 6.25, 0], [9.7, 6.25, 0], 0.14, materials.frame);
for (const x of [-9.7, -4.85, 0, 4.85, 9.7]) {
beamBetween([x, 4.5, -3.7], [x, 6.25, 0], 0.12, materials.frame);
beamBetween([x, 4.5, 3.7], [x, 6.25, 0], 0.12, materials.frame);
}
const backGlass = new THREE.Mesh(
new THREE.PlaneGeometry(19.4, 4.35),
glassMaterial
);
backGlass.position.set(0, 2.25, -3.69);
scene.add(backGlass);
const roofBack = new THREE.Mesh(
quadGeometry(
[-9.7, 4.52, -3.7],
[9.7, 4.52, -3.7],
[9.7, 6.27, 0],
[-9.7, 6.27, 0]
),
glassMaterial
);
scene.add(roofBack);
const roofFront = new THREE.Mesh(
quadGeometry(
[-9.7, 6.27, 0],
[9.7, 6.27, 0],
[9.7, 4.52, 3.7],
[-9.7, 4.52, 3.7]
),
glassMaterial
);
scene.add(roofFront);
// ------------------------------------------------------------
// Shared soil texture and wet-mark canvases
// ------------------------------------------------------------
const TRAY_WIDTH = 3.72;
const TRAY_DEPTH = 2.32;
const SOIL_Y = 1.405;
const TEXTURE_SIZE = 512;
function makeSoilCanvas() {
const canvas = document.createElement("canvas");
canvas.width = TEXTURE_SIZE;
canvas.height = TEXTURE_SIZE;
const ctx = canvas.getContext("2d");
const random = seededRandom(82519);
ctx.fillStyle = "#67442e";
ctx.fillRect(0, 0, TEXTURE_SIZE, TEXTURE_SIZE);
const colors = [
"#795338",
"#5d3d29",
"#835b3e",
"#6f4930",
"#8b6244",
"#593a28"
];
for (let i = 0; i < 650; i++) {
const x = random() * TEXTURE_SIZE;
const y = random() * TEXTURE_SIZE;
const radius = 3 + random() * 15;
ctx.fillStyle = colors[Math.floor(random() * colors.length)];
ctx.globalAlpha = 0.25 + random() * 0.45;
ctx.beginPath();
ctx.moveTo(x, y - radius);
ctx.lineTo(x + radius, y + radius);
ctx.lineTo(x - radius, y + radius * 0.65);
ctx.closePath();
ctx.fill();
}
ctx.globalAlpha = 1;
for (let i = 0; i < 150; i++) {
const x = random() * TEXTURE_SIZE;
const y = random() * TEXTURE_SIZE;
const radius = 0.5 + random() * 1.6;
ctx.fillStyle = random() > 0.5 ? "#a37b58" : "#3e2c21";
ctx.globalAlpha = 0.4;
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
ctx.fill();
}
return canvas;
}
const soilCanvas = makeSoilCanvas();
const soilTexture = new THREE.CanvasTexture(soilCanvas);
soilTexture.colorSpace = THREE.SRGBColorSpace;
soilTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const soilMaterial = new THREE.MeshStandardMaterial({
map: soilTexture,
roughness: 1,
metalness: 0
});
function createWetLayer() {
const canvas = document.createElement("canvas");
canvas.width = TEXTURE_SIZE;
canvas.height = TEXTURE_SIZE;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, TEXTURE_SIZE, TEXTURE_SIZE);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -2
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(TRAY_WIDTH - 0.24, TRAY_DEPTH - 0.24),
material
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = SOIL_Y + 0.006;
mesh.renderOrder = 2;
return { canvas, ctx, texture, mesh };
}
function paintWetEllipse(
station,
localX,
localZ,
radiusX,
radiusZ,
angle = 0,
alpha = 0.3
) {
const { ctx, texture } = station.wet;
const scaleX = TEXTURE_SIZE / TRAY_WIDTH;
const scaleY = TEXTURE_SIZE / TRAY_DEPTH;
const px = (localX / TRAY_WIDTH + 0.5) * TEXTURE_SIZE;
const py = (localZ / TRAY_DEPTH + 0.5) * TEXTURE_SIZE;
ctx.save();
ctx.translate(px, py);
ctx.rotate(angle);
ctx.scale(radiusX * scaleX, radiusZ * scaleY);
const gradient = ctx.createRadialGradient(0, 0, 0, 0, 0, 1);
gradient.addColorStop(0, `rgba(10, 35, 33, ${alpha})`);
gradient.addColorStop(0.55, `rgba(15, 43, 38, ${alpha * 0.72})`);
gradient.addColorStop(1, "rgba(20, 48, 42, 0)");
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.ellipse(0, 0, 1, 1, 0, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
texture.needsUpdate = true;
}
// ------------------------------------------------------------
// Plants
// ------------------------------------------------------------
function addPlant(parent, x, z, scale = 1) {
const plant = new THREE.Group();
plant.position.set(x, SOIL_Y, z);
plant.scale.setScalar(scale);
const stem = addCylinder(
plant,
0.028,
0.038,
0.42,
[0, 0.21, 0],
materials.stem,
7
);
const leafGeometry = new THREE.SphereGeometry(1, 7, 5);
const leaves = [
[-0.13, 0.32, 0.02, -0.55],
[0.13, 0.37, 0.01, 0.55],
[-0.11, 0.45, -0.03, -0.8],
[0.1, 0.49, 0.04, 0.8],
[0, 0.56, 0, 0]
];
leaves.forEach((leaf, index) => {
const mesh = new THREE.Mesh(
leafGeometry,
index % 2 === 0 ? materials.leafA : materials.leafB
);
mesh.position.set(leaf[0], leaf[1], leaf[2]);
mesh.scale.set(0.23, 0.055, 0.11);
mesh.rotation.z = leaf[3];
mesh.rotation.y = index * 1.3;
mesh.castShadow = true;
plant.add(mesh);
});
parent.add(plant);
return stem;
}
// ------------------------------------------------------------
// Three identical benches and trays
// ------------------------------------------------------------
const stationXs = [-6, 0, 6];
const stations = [];
function createStation(x, index) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
addBox(
group,
[4.4, 0.18, 3.0],
[0, 1.19, 0],
materials.benchTop
);
for (const legX of [-1.85, 1.85]) {
for (const legZ of [-1.16, 1.16]) {
addBox(
group,
[0.16, 1.1, 0.16],
[legX, 0.57, legZ],
materials.benchLeg
);
}
}
addBox(
group,
[3.9, 0.045, 0.14],
[0, 0.65, 1.16],
materials.benchLeg
);
addBox(
group,
[3.9, 0.045, 0.14],
[0, 0.65, -1.16],
materials.benchLeg
);
addBox(
group,
[TRAY_WIDTH, 0.12, TRAY_DEPTH],
[0, 1.32, 0],
materials.tray
);
addBox(
group,
[TRAY_WIDTH, 0.16, 0.1],
[0, 1.43, TRAY_DEPTH / 2],
materials.tray
);
addBox(
group,
[TRAY_WIDTH, 0.16, 0.1],
[0, 1.43, -TRAY_DEPTH / 2],
materials.tray
);
addBox(
group,
[0.1, 0.16, TRAY_DEPTH],
[TRAY_WIDTH / 2, 1.43, 0],
materials.tray
);
addBox(
group,
[0.1, 0.16, TRAY_DEPTH],
[-TRAY_WIDTH / 2, 1.43, 0],
materials.tray
);
const soil = new THREE.Mesh(
new THREE.PlaneGeometry(TRAY_WIDTH - 0.24, TRAY_DEPTH - 0.24),
soilMaterial
);
soil.rotation.x = -Math.PI / 2;
soil.position.y = SOIL_Y;
soil.receiveShadow = true;
group.add(soil);
const wet = createWetLayer();
group.add(wet.mesh);
addPlant(group, -0.86, -0.72, 0.95);
addPlant(group, 0.86, -0.72, 0.95);
const accentColors = [0xee725f, 0x2688c7, 0xd99a2b];
addBox(
group,
[0.88, 0.19, 0.035],
[0, 1.03, 1.525],
new THREE.MeshStandardMaterial({
color: accentColors[index],
roughness: 0.5
})
);
const station = {
x,
group,
wet,
labelAnchor: new THREE.Vector3(x, 3.55, -1.25)
};
stations.push(station);
return station;
}
stationXs.forEach((x, index) => createStation(x, index));
// ------------------------------------------------------------
// Station 1: hand spray bottle
// ------------------------------------------------------------
const sprayStation = stations[0];
const sprayBottle = new THREE.Group();
sprayBottle.position.set(-7.55, 1.29, 0.86);
scene.add(sprayBottle);
addCylinder(
sprayBottle,
0.21,
0.24,
0.53,
[0, 0.265, 0],
materials.spray,
10
);
const bottleShoulder = new THREE.Mesh(
new THREE.SphereGeometry(0.21, 10, 6),
materials.spray
);
bottleShoulder.scale.set(1, 0.55, 1);
bottleShoulder.position.y = 0.54;
bottleShoulder.castShadow = true;
sprayBottle.add(bottleShoulder);
addCylinder(
sprayBottle,
0.075,
0.09,
0.15,
[0, 0.69, 0],
materials.sprayDark,
10
);
const sprayNozzle = addCylinder(
sprayBottle,
0.055,
0.07,
0.31,
[-0.22, 0.73, 0],
materials.sprayDark,
10
);
sprayNozzle.rotation.z = Math.PI / 2;
const sprayTrigger = addBox(
sprayBottle,
[0.13, 0.2, 0.09],
[-0.08, 0.57, 0],
materials.sprayDark
);
sprayTrigger.rotation.z = -0.3;
const spraySource = new THREE.Vector3(-7.19, 2.04, 0.86);
// ------------------------------------------------------------
// Station 2: reservoir, tube, and three outlets
// ------------------------------------------------------------
const dripStation = stations[1];
const dripReservoir = new THREE.Group();
dripReservoir.position.set(1.68, 1.29, 0.95);
scene.add(dripReservoir);
addCylinder(
dripReservoir,
0.2,
0.23,
0.48,
[0, 0.25, 0],
materials.drip,
10
);
addCylinder(
dripReservoir,
0.085,
0.085,
0.1,
[0, 0.54, 0],
materials.benchLeg,
8
);
const mainTube = tubeFromPoints(
[
[1.68, 1.65, 0.95],
[1.72, 1.61, 0.35],
[1.72, 1.61, -0.83],
[0.9, 1.61, -0.83],
[-1.12, 1.61, -0.83]
],
0.025,
materials.tube,
54
);
scene.add(mainTube);
const dripOutletOffsets = [-1.1, 0, 1.1];
const dripOutlets = [];
for (const offset of dripOutletOffsets) {
const branch = tubeFromPoints(
[
[offset, 1.61, -0.83],
[offset, 1.62, -0.53],
[offset, 1.73, -0.22]
],
0.022,
materials.tube,
18
);
scene.add(branch);
const outlet = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.035, 0.11, 8),
materials.drip
);
outlet.position.set(offset, 1.73, -0.22);
outlet.castShadow = true;
scene.add(outlet);
dripOutlets.push(
new THREE.Vector3(dripStation.x + offset, 1.67, -0.22)
);
}
// ------------------------------------------------------------
// Station 3: watering can
// ------------------------------------------------------------
const canStation = stations[2];
const wateringCan = new THREE.Group();
wateringCan.position.set(7.65, 1.29, 0.82);
scene.add(wateringCan);
addCylinder(
wateringCan,
0.36,
0.43,
0.68,
[0, 0.37, 0],
materials.can,
12
);
const canTop = new THREE.Mesh(
new THREE.CircleGeometry(0.32, 12),
materials.canDark
);
canTop.rotation.x = -Math.PI / 2;
canTop.position.y = 0.711;
wateringCan.add(canTop);
const canRim = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.035, 6, 16),
materials.canDark
);
canRim.rotation.x = Math.PI / 2;
canRim.position.y = 0.72;
canRim.castShadow = true;
wateringCan.add(canRim);
const canHandle = new THREE.Mesh(
new THREE.TorusGeometry(0.3, 0.045, 7, 18, Math.PI * 1.45),
materials.canDark
);
canHandle.position.set(0.12, 0.43, 0.37);
canHandle.rotation.z = -0.55;
canHandle.castShadow = true;
wateringCan.add(canHandle);
const canSpout = tubeFromPoints(
[
[-0.32, 0.27, 0],
[-0.53, 0.46, -0.02],
[-0.77, 0.75, -0.1],
[-1.0, 0.92, -0.14]
],
0.066,
materials.can,
26
);
wateringCan.add(canSpout);
const rose = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 10, 6),
materials.canDark
);
rose.position.set(-1.0, 0.92, -0.14);
rose.scale.set(1, 0.65, 1);
rose.castShadow = true;
wateringCan.add(rose);
const pourSource = new THREE.Vector3(6.65, 2.21, 0.68);
const pourTarget = new THREE.Vector3(5.68, SOIL_Y + 0.025, 0.57);
const pourCurve = new THREE.QuadraticBezierCurve3(
pourSource,
new THREE.Vector3(6.43, 2.55, 0.64),
pourTarget
);
const streamGroup = new THREE.Group();
streamGroup.visible = false;
scene.add(streamGroup);
const stream = new THREE.Mesh(
new THREE.TubeGeometry(pourCurve, 48, 0.036, 7, false),
materials.water
);
streamGroup.add(stream);
const streamHighlight = new THREE.Mesh(
new THREE.TubeGeometry(pourCurve, 48, 0.011, 5, false),
materials.brightWater
);
streamHighlight.position.x -= 0.012;
streamHighlight.position.z -= 0.012;
streamGroup.add(streamHighlight);
// ------------------------------------------------------------
// Water animation systems
// ------------------------------------------------------------
const dummy = new THREE.Object3D();
const SPRAY_COUNT = 110;
const sprayDrops = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.024, 5, 4),
materials.brightWater,
SPRAY_COUNT
);
sprayDrops.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
sprayDrops.frustumCulled = false;
sprayDrops.visible = false;
scene.add(sprayDrops);
const sprayParticles = [];
function randomSprayTarget() {
return {
localX: THREE.MathUtils.clamp(0.08 + randomNormal() * 0.85, -1.42, 1.45),
localZ: THREE.MathUtils.clamp(0.27 + randomNormal() * 0.48, -0.68, 0.82),
duration: 0.82 + Math.random() * 0.48,
elapsed: 0,
arc: 0.45 + Math.random() * 0.42,
size: 0.72 + Math.random() * 0.65
};
}
for (let i = 0; i < SPRAY_COUNT; i++) {
const particle = randomSprayTarget();
particle.elapsed = Math.random() * particle.duration;
sprayParticles.push(particle);
}
const DRIP_COUNT = 24;
const dripDrops = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.034, 6, 4),
materials.brightWater,
DRIP_COUNT
);
dripDrops.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
dripDrops.frustumCulled = false;
dripDrops.visible = false;
scene.add(dripDrops);
const POUR_COUNT = 38;
const pourDrops = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.028, 5, 4),
materials.brightWater,
POUR_COUNT
);
pourDrops.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
pourDrops.frustumCulled = false;
pourDrops.visible = false;
scene.add(pourDrops);
function createSplashRing(position, color = 0x8be5f5) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.055, 0.078, 16),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.copy(position);
ring.renderOrder = 3;
scene.add(ring);
return ring;
}
const dripRings = dripOutlets.map((outlet) =>
createSplashRing(
new THREE.Vector3(outlet.x, SOIL_Y + 0.014, outlet.z)
)
);
const pourRing = createSplashRing(
new THREE.Vector3(pourTarget.x, SOIL_Y + 0.014, pourTarget.z)
);
let activeMethod = null;
let dripElapsed = 0;
let pourElapsed = 0;
let pourPaintTimer = 0;
// ------------------------------------------------------------
// UI and method activation
// ------------------------------------------------------------
const methodButtons = [...document.querySelectorAll(".method")];
const status = document.getElementById("status");
const resetButton = document.getElementById("reset");
function setActiveMethod(method) {
activeMethod = method;
sprayDrops.visible = method === "spray";
dripDrops.visible = method === "drip";
pourDrops.visible = method === "can";
streamGroup.visible = method === "can";
methodButtons.forEach((button) => {
const selected = button.dataset.method === method;
button.classList.toggle("active", selected);
button.setAttribute("aria-pressed", String(selected));
});
if (method === "spray") {
sprayParticles.forEach((particle) => {
Object.assign(particle, randomSprayTarget());
particle.elapsed = Math.random() * particle.duration;
});
}
if (method === "drip") {
dripElapsed = 0;
dripOutletOffsets.forEach((offset) => {
paintWetEllipse(
dripStation,
offset,
-0.22,
0.17,
0.15,
0,
0.18
);
});
}
if (method === "can") {
pourElapsed = 0;
pourPaintTimer = 0;
const dx = pourSource.x - pourTarget.x;
const dz = pourSource.z - pourTarget.z;
const angle = Math.atan2(
dz * (TEXTURE_SIZE / TRAY_DEPTH),
dx * (TEXTURE_SIZE / TRAY_WIDTH)
);
paintWetEllipse(
canStation,
-0.08,
0.55,
0.5,
0.12,
angle,
0.22
);
}
if (method === null) {
status.textContent = "Choose a watering method";
} else {
const names = {
spray: "Hand spray",
drip: "Drip tube",
can: "Watering can"
};
status.textContent = `Running: ${names[method]}`;
}
}
methodButtons.forEach((button) => {
button.addEventListener("click", () => {
const method = button.dataset.method;
setActiveMethod(method === activeMethod ? null : method);
});
});
resetButton.addEventListener("click", () => {
setActiveMethod(null);
stations.forEach((station) => {
station.wet.ctx.clearRect(
0,
0,
TEXTURE_SIZE,
TEXTURE_SIZE
);
station.wet.texture.needsUpdate = true;
});
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") {
setActiveMethod(activeMethod === "spray" ? null : "spray");
} else if (event.key === "2") {
setActiveMethod(activeMethod === "drip" ? null : "drip");
} else if (event.key === "3") {
setActiveMethod(activeMethod === "can" ? null : "can");
}
});
// ------------------------------------------------------------
// Station labels
// ------------------------------------------------------------
const labelElements = [
...document.querySelectorAll(".station-label")
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
stations.forEach((station, index) => {
projected.copy(station.labelAnchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -100 &&
x < width + 100;
labelElements[index].style.display = visible ? "block" : "none";
labelElements[index].style.left = `${x}px`;
labelElements[index].style.top = `${y}px`;
});
}
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (activeMethod === "spray") {
sprayParticles.forEach((particle, index) => {
particle.elapsed += delta;
if (particle.elapsed >= particle.duration) {
paintWetEllipse(
sprayStation,
particle.localX,
particle.localZ,
0.18 + Math.random() * 0.11,
0.14 + Math.random() * 0.09,
0,
0.2
);
Object.assign(particle, randomSprayTarget());
}
const progress = particle.elapsed / particle.duration;
const targetX = sprayStation.x + particle.localX;
const targetZ = particle.localZ;
dummy.position.set(
THREE.MathUtils.lerp(spraySource.x, targetX, progress),
THREE.MathUtils.lerp(spraySource.y, SOIL_Y, progress) +
particle.arc * 4 * progress * (1 - progress),
THREE.MathUtils.lerp(spraySource.z, targetZ, progress)
);
dummy.scale.set(
particle.size,
particle.size * 1.55,
particle.size
);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
sprayDrops.setMatrixAt(index, dummy.matrix);
});
sprayDrops.instanceMatrix.needsUpdate = true;
}
if (activeMethod === "drip") {
dripElapsed += delta;
for (let index = 0; index < DRIP_COUNT; index++) {
const outletIndex = index % dripOutletOffsets.length;
const outlet = dripOutlets[outletIndex];
const offset = (index / DRIP_COUNT) * 0.999;
const phase = (dripElapsed * 0.78 + offset) % 1;
dummy.position.set(
outlet.x,
THREE.MathUtils.lerp(outlet.y, SOIL_Y + 0.02, phase),
outlet.z
);
dummy.scale.set(0.64, 1.65, 0.64);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
dripDrops.setMatrixAt(index, dummy.matrix);
}
dripDrops.instanceMatrix.needsUpdate = true;
dripRings.forEach((ring, index) => {
const phase = (dripElapsed * 1.05 + index * 0.31) % 1;
ring.scale.setScalar(0.8 + phase * 2.8);
ring.material.opacity = (1 - phase) * 0.48;
});
}
if (activeMethod === "can") {
pourElapsed += delta;
pourPaintTimer += delta;
for (let index = 0; index < POUR_COUNT; index++) {
const phase = (pourElapsed * 0.58 + index / POUR_COUNT) % 1;
const point = pourCurve.getPointAt(phase);
dummy.position.copy(point);
dummy.position.x += Math.sin(index * 3.1) * 0.013;
dummy.position.z += Math.cos(index * 2.3) * 0.013;
dummy.scale.set(0.7, 1.45, 0.7);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
pourDrops.setMatrixAt(index, dummy.matrix);
}
pourDrops.instanceMatrix.needsUpdate = true;
const ringPhase = (pourElapsed * 1.15) % 1;
pourRing.scale.setScalar(0.8 + ringPhase * 3.5);
pourRing.material.opacity = (1 - ringPhase) * 0.52;
if (pourPaintTimer > 0.085) {
pourPaintTimer = 0;
const localTargetX = pourTarget.x - canStation.x;
const localTargetZ = pourTarget.z;
const dx = pourSource.x - pourTarget.x;
const dz = pourSource.z - pourTarget.z;
const angle = Math.atan2(
dz * (TEXTURE_SIZE / TRAY_DEPTH),
dx * (TEXTURE_SIZE / TRAY_WIDTH)
);
paintWetEllipse(
canStation,
localTargetX + 0.08,
localTargetZ,
0.42,
0.105,
angle,
0.11
);
}
}
// Gentle movement in the suspended watering-can stream.
streamHighlight.material.opacity =
0.58 + Math.sin(elapsed * 9) * 0.12;
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
</script>
</body>
</html>
```