Prompt specification
Build or customize the Three.js 3D scene "Outlet spacing and root zones" 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: Outlet spacing and root zones
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/outlet-spacing-and-root-zones-x1058
Scene Description Prompt:
Move low-poly drip emitters above plants and show root-zone coverage through illustrative wetting circles. Create a single HTML file with Three.js from cdnjs.
Working Three.js Starter (outlet-spacing-and-root-zones-x1058):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Root-Zone Irrigation</title>
<style>
:root {
--ink: #18342f;
--muted: #647872;
--accent: #1699ad;
--accent-dark: #0d7284;
--orange: #f3a844;
--panel: rgba(248, 251, 247, 0.88);
--border: rgba(28, 65, 57, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e6ece6;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: 30px;
left: 32px;
width: min(440px, calc(100vw - 64px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
color: var(--accent-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(22, 153, 173, 0.13);
animation: pulse 2s infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 8px rgba(22, 153, 173, 0);
}
}
h1 {
margin: 0;
font-size: clamp(31px, 4vw, 52px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
}
.subtitle {
max-width: 405px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.stats {
display: flex;
gap: 9px;
margin-top: 20px;
flex-wrap: wrap;
}
.stat {
display: flex;
align-items: center;
gap: 8px;
min-height: 34px;
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(248, 251, 247, 0.68);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.stat strong {
color: var(--ink);
font-size: 13px;
}
.panel {
position: absolute;
top: 28px;
right: 28px;
width: 300px;
padding: 18px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(32, 61, 51, 0.13);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.panel-title {
font-size: 13px;
font-weight: 800;
letter-spacing: 0.02em;
}
.text-button {
padding: 5px 0;
border: 0;
background: none;
color: var(--accent-dark);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
.text-button:hover {
color: var(--ink);
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 12px 0;
border-top: 1px solid var(--border);
}
.toggle-row strong {
display: block;
font-size: 12px;
font-weight: 750;
}
.toggle-row small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 38px;
height: 22px;
}
.switch input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 20px;
background: #cbd5ce;
transition: 180ms ease;
cursor: pointer;
}
.switch span::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 16px;
height: 16px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(20, 40, 35, 0.18);
transition: 180ms ease;
}
.switch input:checked + span {
background: var(--accent);
}
.switch input:checked + span::after {
transform: translateX(16px);
}
.range-block {
padding: 14px 0 11px;
border-top: 1px solid var(--border);
}
.range-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
font-size: 11px;
font-weight: 700;
}
.range-label output {
color: var(--accent-dark);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 5px;
margin: 0;
border-radius: 10px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--fill),
#d4ddd6 var(--fill),
#d4ddd6 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 7px rgba(15, 93, 105, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 7px rgba(15, 93, 105, 0.3);
}
.lift-button {
width: 100%;
margin-top: 4px;
padding: 11px 14px;
border: 0;
border-radius: 11px;
background: var(--ink);
color: white;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease;
}
.lift-button:hover {
transform: translateY(-1px);
background: #244a42;
}
.lift-button:active {
transform: translateY(0);
}
.legend {
display: grid;
gap: 9px;
margin-top: 16px;
padding-top: 15px;
border-top: 1px solid var(--border);
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 10px;
}
.legend-symbol {
width: 15px;
height: 15px;
flex: 0 0 auto;
}
.legend-symbol.circle {
border: 1px solid rgba(22, 153, 173, 0.6);
border-radius: 50%;
background: rgba(22, 153, 173, 0.14);
}
.legend-symbol.drop {
position: relative;
width: 8px;
height: 13px;
margin: 0 4px;
border-radius: 70% 30% 65% 35%;
background: var(--accent);
transform: rotate(40deg);
}
.legend-symbol.emitter {
position: relative;
width: 15px;
height: 11px;
border-radius: 3px;
background: var(--accent);
}
.legend-symbol.emitter::before {
content: "";
position: absolute;
top: -4px;
left: 2px;
width: 11px;
height: 4px;
border-radius: 2px;
background: var(--orange);
}
.hint {
position: absolute;
right: 29px;
bottom: 24px;
padding: 9px 13px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(248, 251, 247, 0.75);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #e6ece6;
color: var(--accent-dark);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
h1 {
max-width: 300px;
font-size: 36px;
}
.subtitle {
max-width: 320px;
font-size: 12px;
}
.stats {
display: none;
}
.panel {
top: auto;
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
max-height: 43vh;
overflow-y: auto;
padding: 15px;
}
.legend {
display: none;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D irrigation visualization"></canvas>
<div class="ui">
<header class="intro">
<div class="eyebrow">
<span class="live-dot"></span>
<span id="layoutStatus">Lifting emitters</span>
</div>
<h1>Root-zone<br />coverage</h1>
<p class="subtitle">
Low-poly drip emitters lift clear of the canopy while translucent
wetting footprints reveal where water reaches each root system.
</p>
<div class="stats">
<div class="stat"><strong>9</strong> emitters</div>
<div class="stat"><strong>3 × 3</strong> planting grid</div>
<div class="stat"><strong id="coverageValue">82%</strong> coverage</div>
</div>
</header>
<section class="panel" aria-label="Irrigation controls">
<div class="panel-head">
<span class="panel-title">Irrigation controls</span>
<button class="text-button" id="resetView" type="button">
Reset view
</button>
</div>
<div class="toggle-row">
<div>
<strong>Root-zone overlay</strong>
<small>Illustrative wetting footprint</small>
</div>
<label class="switch">
<input id="coverageToggle" type="checkbox" checked />
<span></span>
</label>
</div>
<div class="toggle-row">
<div>
<strong>Water flow</strong>
<small>Animated emitter droplets</small>
</div>
<label class="switch">
<input id="flowToggle" type="checkbox" checked />
<span></span>
</label>
</div>
<div class="range-block">
<div class="range-label">
<label for="liftRange">Lift above canopy</label>
<output id="liftValue">1.15 m</output>
</div>
<input id="liftRange" type="range" min="0.55" max="2.1" step="0.05" value="1.15" />
</div>
<div class="range-block">
<div class="range-label">
<label for="coverageRange">Wetting radius</label>
<output id="coverageValueSmall">1.35 m</output>
</div>
<input id="coverageRange" type="range" min="0.75" max="1.9" step="0.05" value="1.35" />
</div>
<button class="lift-button" id="liftAll" type="button">
Lift all emitters above plants
</button>
<div class="legend">
<div class="legend-item">
<span class="legend-symbol circle"></span>
Illustrative root wetting zone
</div>
<div class="legend-item">
<span class="legend-symbol drop"></span>
Water droplet
</div>
<div class="legend-item">
<span class="legend-symbol emitter"></span>
Low-poly drip emitter
</div>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<div class="loading" id="loading">Preparing irrigation field</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe6ece6);
scene.fog = new THREE.Fog(0xe6ece6, 28, 52);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
camera.position.set(13, 11, 15);
const hemi = new THREE.HemisphereLight(0xf6fff8, 0x695749, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4d8, 3.4);
sun.position.set(8, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9e9f0, 0.8);
fill.position.set(-9, 7, -6);
scene.add(fill);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xdfe7df,
roughness: 1,
flatShading: true
});
const floor = new THREE.Mesh(new THREE.PlaneGeometry(80, 80), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.39;
floor.receiveShadow = true;
scene.add(floor);
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x674835,
roughness: 1,
flatShading: true
});
const borderMaterial = new THREE.MeshStandardMaterial({
color: 0x34564c,
roughness: 0.78,
flatShading: true
});
const furrowMaterial = new THREE.MeshStandardMaterial({
color: 0x4f3528,
roughness: 1,
flatShading: true
});
function addBox(size, position, material, castShadow = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
addBox([14.8, 0.34, 10.2], [0, -0.17, 0], soilMaterial);
addBox([0.3, 0.48, 10.8], [-7.5, 0.02, 0], borderMaterial, true);
addBox([0.3, 0.48, 10.8], [7.5, 0.02, 0], borderMaterial, true);
addBox([15.3, 0.48, 0.3], [0, 0.02, -5.1], borderMaterial, true);
addBox([15.3, 0.48, 0.3], [0, 0.02, 5.1], borderMaterial, true);
for (const z of [-1.4, 1.4]) {
addBox([13.8, 0.026, 0.11], [0, 0.016, z], furrowMaterial);
}
let randomSeed = 48291;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const pebbleGeometry = new THREE.DodecahedronGeometry(0.07, 0);
const pebbleMaterials = [
new THREE.MeshStandardMaterial({ color: 0x9a7b5d, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x765946, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0xb29678, roughness: 1, flatShading: true })
];
for (let i = 0; i < 72; i++) {
const pebble = new THREE.Mesh(
pebbleGeometry,
pebbleMaterials[i % pebbleMaterials.length]
);
pebble.position.set(
(random() - 0.5) * 14.1,
0.055,
(random() - 0.5) * 9.5
);
const scale = 0.45 + random() * 0.75;
pebble.scale.setScalar(scale);
pebble.rotation.set(random() * 2, random() * 2, random() * 2);
pebble.castShadow = true;
scene.add(pebble);
}
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x53663b,
roughness: 0.95,
flatShading: true
});
const rootMaterial = new THREE.MeshStandardMaterial({
color: 0x33251e,
roughness: 1,
flatShading: true
});
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x4e8b4f,
roughness: 0.86,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x69a85b,
roughness: 0.86,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x39784c,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x83b965,
roughness: 0.86,
flatShading: true
})
];
const up = new THREE.Vector3(0, 1, 0);
function cylinderBetween(a, b, radius, material, radialSegments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius * 0.72,
radius,
length,
radialSegments
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createPlant(x, z, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const trunkHeight = 1.35 + random() * 0.38;
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.14, trunkHeight, 6),
stemMaterial
);
trunk.position.y = trunkHeight / 2;
trunk.castShadow = true;
trunk.receiveShadow = true;
group.add(trunk);
const leafGeometry = new THREE.IcosahedronGeometry(0.56, 0);
for (let i = 0; i < 8; i++) {
const angle = i * 2.39996 + random() * 0.28;
const level = 0.52 + (i % 3) * 0.13;
const reach = 0.42 + random() * 0.25;
const start = new THREE.Vector3(0, trunkHeight * level, 0);
const end = new THREE.Vector3(
Math.cos(angle) * reach,
trunkHeight * level + 0.27 + random() * 0.24,
Math.sin(angle) * reach
);
group.add(
cylinderBetween(
start,
end,
0.055,
stemMaterial,
5
)
);
const leaf = new THREE.Mesh(
leafGeometry,
leafMaterials[(i + index) % leafMaterials.length]
);
leaf.position.copy(end);
leaf.scale.set(
0.82 + random() * 0.36,
0.22 + random() * 0.08,
0.42 + random() * 0.14
);
leaf.rotation.set(
random() * 0.55,
-angle + random() * 0.35,
(random() - 0.5) * 0.85
);
leaf.castShadow = true;
leaf.receiveShadow = true;
group.add(leaf);
}
const crown = new THREE.Mesh(
leafGeometry,
leafMaterials[(index + 1) % leafMaterials.length]
);
crown.position.y = trunkHeight + 0.26;
crown.scale.set(0.75, 0.32, 0.64);
crown.rotation.y = random() * Math.PI;
crown.castShadow = true;
group.add(crown);
const rootGroup = new THREE.Group();
rootGroup.position.y = 0.047;
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2 + random() * 0.22;
const length = 0.42 + random() * 0.27;
const start = new THREE.Vector3(0, 0, 0);
const middle = new THREE.Vector3(
Math.cos(angle) * length * 0.48,
0,
Math.sin(angle) * length * 0.48
);
const end = new THREE.Vector3(
Math.cos(angle + 0.15) * length,
0,
Math.sin(angle + 0.15) * length
);
rootGroup.add(cylinderBetween(start, middle, 0.025, rootMaterial, 5));
rootGroup.add(cylinderBetween(middle, end, 0.015, rootMaterial, 5));
}
group.add(rootGroup);
scene.add(group);
return {
group,
x,
z,
canopyTop: trunkHeight + 0.55
};
}
const plants = [];
const xPositions = [-4.2, 0, 4.2];
const zPositions = [-2.85, 0, 2.85];
let plantIndex = 0;
for (const z of zPositions) {
for (const x of xPositions) {
plants.push(createPlant(x, z, plantIndex++));
}
}
const emitterBodyMaterial = new THREE.MeshStandardMaterial({
color: 0x168da2,
roughness: 0.48,
metalness: 0.08,
flatShading: true
});
const emitterCapMaterial = new THREE.MeshStandardMaterial({
color: 0xf3a844,
roughness: 0.55,
flatShading: true
});
const emitterDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x1e4e52,
roughness: 0.7,
flatShading: true
});
const nozzleMaterial = new THREE.MeshStandardMaterial({
color: 0xd8eee8,
roughness: 0.42,
flatShading: true
});
const guideMaterial = new THREE.MeshBasicMaterial({
color: 0x54b9c8,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const dropGeometry = new THREE.SphereGeometry(0.047, 6, 4);
const rippleGeometry = new THREE.RingGeometry(0.86, 1, 40);
const coverageVertexShader = `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const coverageFragmentShader = `
precision highp float;
varying vec2 vUv;
uniform vec3 uColor;
uniform float uOpacity;
uniform float uTime;
void main() {
vec2 p = (vUv - 0.5) * 2.0;
float radius = length(p);
float angle = atan(p.y, p.x);
float wobble = 1.0
+ 0.045 * sin(angle * 7.0 + uTime * 0.35)
+ 0.020 * sin(angle * 13.0 - uTime * 0.20);
float boundary = 0.90 * wobble;
if (radius > boundary) discard;
float feather = 1.0 - smoothstep(boundary - 0.12, boundary, radius);
float fill = (1.0 - smoothstep(0.08, 0.87, radius)) * 0.25;
float contour = 1.0 - smoothstep(
0.016,
0.045,
abs(radius - 0.79 * wobble)
);
float alpha = (fill + contour * 0.48) * feather * uOpacity;
gl_FragColor = vec4(uColor, alpha);
}
`;
const outerCoverageMaterial = new THREE.ShaderMaterial({
vertexShader: coverageVertexShader,
fragmentShader: coverageFragmentShader,
uniforms: {
uColor: { value: new THREE.Color(0x25aabd) },
uOpacity: { value: 0.95 },
uTime: { value: 0 }
},
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const innerCoverageMaterial = new THREE.ShaderMaterial({
vertexShader: coverageVertexShader,
fragmentShader: coverageFragmentShader,
uniforms: {
uColor: { value: new THREE.Color(0x44d4cf) },
uOpacity: { value: 0.66 },
uTime: { value: 0 }
},
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const coverageOutlineMaterial = new THREE.MeshBasicMaterial({
color: 0x37b6c5,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
});
const emitters = [];
function createEmitter(plant, index) {
const group = new THREE.Group();
group.position.set(plant.x, plant.canopyTop + 0.48, plant.z);
group.rotation.y = index * 0.39;
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.25, 0.34, 6),
emitterBodyMaterial
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.22, 0.15, 6),
emitterCapMaterial
);
cap.position.y = 0.235;
cap.castShadow = true;
group.add(cap);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.235, 0.032, 4, 10),
emitterDarkMaterial
);
collar.rotation.x = Math.PI / 2;
collar.position.y = 0.035;
collar.castShadow = true;
group.add(collar);
const nozzle = new THREE.Mesh(
new THREE.CylinderGeometry(0.06, 0.085, 0.21, 6),
nozzleMaterial
);
nozzle.position.y = -0.265;
nozzle.castShadow = true;
group.add(nozzle);
const tip = new THREE.Mesh(
new THREE.CylinderGeometry(0.026, 0.05, 0.09, 6),
emitterDarkMaterial
);
tip.position.y = -0.4;
group.add(tip);
scene.add(group);
const guide = new THREE.Mesh(
new THREE.CylinderGeometry(0.009, 0.009, 1, 6),
guideMaterial
);
guide.position.set(plant.x, 1, plant.z);
scene.add(guide);
const coverageGroup = new THREE.Group();
coverageGroup.position.set(plant.x, 0, plant.z);
const outer = new THREE.Mesh(
new THREE.CircleGeometry(1, 64),
outerCoverageMaterial
);
outer.rotation.x = -Math.PI / 2;
outer.position.y = 0.027;
outer.renderOrder = 1;
const inner = new THREE.Mesh(
new THREE.CircleGeometry(1, 64),
innerCoverageMaterial
);
inner.rotation.x = -Math.PI / 2;
inner.position.y = 0.032;
inner.renderOrder = 2;
const outline = new THREE.Mesh(
new THREE.RingGeometry(0.92, 1, 48),
coverageOutlineMaterial
);
outline.rotation.x = -Math.PI / 2;
outline.position.y = 0.038;
outline.renderOrder = 3;
coverageGroup.add(outer, inner, outline);
scene.add(coverageGroup);
const drops = [];
for (let i = 0; i < 3; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0x27c6e8,
transparent: true,
opacity: 0.92,
depthWrite: false
});
const drop = new THREE.Mesh(dropGeometry, material);
drop.scale.set(0.75, 1.8, 0.75);
drop.renderOrder = 4;
scene.add(drop);
drops.push({
mesh: drop,
phase: (i / 3 + index * 0.07) % 1,
offset: i * 2.1
});
}
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0x54d8dc,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const ripple = new THREE.Mesh(rippleGeometry, rippleMaterial);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(plant.x, 0.052, plant.z);
ripple.renderOrder = 4;
scene.add(ripple);
emitters.push({
group,
guide,
plant,
currentY: plant.canopyTop + 0.48,
coverageGroup,
outer,
inner,
outline,
drops,
ripple
});
}
plants.forEach(createEmitter);
// Custom orbit camera controls — no Three.js examples/addons required.
class OrbitController {
constructor(camera, element, target) {
this.camera = camera;
this.element = element;
this.target = target.clone();
this.offset = camera.position.clone().sub(this.target);
this.spherical = new THREE.Spherical().setFromVector3(this.offset);
this.desiredTheta = this.spherical.theta;
this.desiredPhi = this.spherical.phi;
this.desiredZoom = 1;
this.dragging = false;
this.pointerX = 0;
this.pointerY = 0;
this.onPointerDown = this.onPointerDown.bind(this);
this.onPointerMove = this.onPointerMove.bind(this);
this.onPointerUp = this.onPointerUp.bind(this);
this.onWheel = this.onWheel.bind(this);
this.onDoubleClick = this.onDoubleClick.bind(this);
element.addEventListener("pointerdown", this.onPointerDown);
element.addEventListener("pointermove", this.onPointerMove);
element.addEventListener("pointerup", this.onPointerUp);
element.addEventListener("pointercancel", this.onPointerUp);
element.addEventListener("wheel", this.onWheel, { passive: false });
element.addEventListener("dblclick", this.onDoubleClick);
}
onPointerDown(event) {
this.dragging = true;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
this.element.setPointerCapture(event.pointerId);
this.element.classList.add("dragging");
}
onPointerMove(event) {
if (!this.dragging) return;
const dx = event.clientX - this.pointerX;
const dy = event.clientY - this.pointerY;
this.pointerX = event.clientX;
this.pointerY = event.clientY;
this.desiredTheta -= dx * 0.006;
this.desiredPhi = THREE.MathUtils.clamp(
this.desiredPhi - dy * 0.005,
0.46,
1.32
);
}
onPointerUp(event) {
this.dragging = false;
if (this.element.hasPointerCapture(event.pointerId)) {
this.element.releasePointerCapture(event.pointerId);
}
this.element.classList.remove("dragging");
}
onWheel(event) {
event.preventDefault();
this.desiredZoom = THREE.MathUtils.clamp(
this.desiredZoom * Math.exp(event.deltaY * 0.001),
0.65,
1.85
);
}
onDoubleClick() {
this.reset();
}
reset() {
this.desiredTheta = this.spherical.theta;
this.desiredPhi = this.spherical.phi;
this.desiredZoom = 1;
}
update(delta) {
this.spherical.theta = THREE.MathUtils.damp(
this.spherical.theta,
this.desiredTheta,
9,
delta
);
this.spherical.phi = THREE.MathUtils.damp(
this.spherical.phi,
this.desiredPhi,
9,
delta
);
this.camera.zoom = THREE.MathUtils.damp(
this.camera.zoom,
this.desiredZoom,
8,
delta
);
this.camera.position.setFromSpherical(this.spherical).add(this.target);
this.camera.lookAt(this.target);
this.camera.updateProjectionMatrix();
}
}
const controls = new OrbitController(
camera,
canvas,
new THREE.Vector3(0, 0.9, 0)
);
const liftRange = document.querySelector("#liftRange");
const liftValue = document.querySelector("#liftValue");
const coverageRange = document.querySelector("#coverageRange");
const coverageValueSmall = document.querySelector("#coverageValueSmall");
const coverageValue = document.querySelector("#coverageValue");
const coverageToggle = document.querySelector("#coverageToggle");
const flowToggle = document.querySelector("#flowToggle");
const layoutStatus = document.querySelector("#layoutStatus");
let liftSetting = Number(liftRange.value);
let coverageRadius = Number(coverageRange.value);
let currentCoverageRadius = coverageRadius;
let flowActive = flowToggle.checked;
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percent}%`);
}
function updateCoverageReadout() {
const percent = Math.round(
Math.min(98, 39 + coverageRadius * 32)
);
coverageValue.textContent = `${percent}%`;
coverageValueSmall.textContent = `${coverageRadius.toFixed(2)} m`;
}
updateRangeFill(liftRange);
updateRangeFill(coverageRange);
updateCoverageReadout();
liftRange.addEventListener("input", () => {
liftSetting = Number(liftRange.value);
liftValue.textContent = `${liftSetting.toFixed(2)} m`;
updateRangeFill(liftRange);
});
coverageRange.addEventListener("input", () => {
coverageRadius = Number(coverageRange.value);
coverageValueSmall.textContent = `${coverageRadius.toFixed(2)} m`;
updateRangeFill(coverageRange);
updateCoverageReadout();
});
coverageToggle.addEventListener("change", () => {
emitters.forEach((emitter) => {
emitter.coverageGroup.visible = coverageToggle.checked;
});
});
flowToggle.addEventListener("change", () => {
flowActive = flowToggle.checked;
});
document.querySelector("#liftAll").addEventListener("click", () => {
liftRange.value = "1.35";
liftRange.dispatchEvent(new Event("input"));
});
document.querySelector("#resetView").addEventListener("click", () => {
controls.reset();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(11.5, 16.5 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
controls.update(delta);
currentCoverageRadius = THREE.MathUtils.damp(
currentCoverageRadius,
coverageRadius,
7,
delta
);
outerCoverageMaterial.uniforms.uTime.value = elapsed;
innerCoverageMaterial.uniforms.uTime.value = elapsed;
let allLifted = true;
for (const emitter of emitters) {
const targetY =
emitter.plant.canopyTop + liftSetting + 0.4;
emitter.currentY = THREE.MathUtils.damp(
emitter.currentY,
targetY,
4.5,
delta
);
if (Math.abs(emitter.currentY - targetY) > 0.06) {
allLifted = false;
}
emitter.group.position.y = emitter.currentY;
const nozzleY = emitter.currentY - 0.43;
const guideLength = Math.max(0.01, nozzleY - 0.03);
emitter.guide.position.set(
emitter.plant.x,
guideLength / 2 + 0.03,
emitter.plant.z
);
emitter.guide.scale.y = guideLength;
emitter.outer.scale.set(
currentCoverageRadius,
currentCoverageRadius,
1
);
emitter.inner.scale.set(
currentCoverageRadius * 0.48,
currentCoverageRadius * 0.48,
1
);
emitter.outline.scale.set(
currentCoverageRadius,
currentCoverageRadius,
1
);
for (const drop of emitter.drops) {
drop.mesh.visible = flowActive;
if (!flowActive) continue;
const cycle =
(elapsed * (0.52 + currentCoverageRadius * 0.18) +
drop.phase) %
1;
const drift = Math.sin(cycle * 7 + drop.offset) * 0.035;
drop.mesh.position.set(
emitter.plant.x + drift,
THREE.MathUtils.lerp(nozzleY - 0.04, 0.07, cycle),
emitter.plant.z + Math.cos(cycle * 6 + drop.offset) * 0.025
);
drop.mesh.material.opacity =
Math.min(1, cycle * 7) *
(1 - Math.max(0, (cycle - 0.86) / 0.14));
}
const rippleCycle =
(elapsed * 0.62 + emitter.plant.x * 0.013) % 1;
emitter.ripple.visible = flowActive;
if (flowActive) {
const rippleSize =
currentCoverageRadius * (0.12 + rippleCycle * 0.58);
emitter.ripple.scale.set(
rippleSize,
rippleSize,
1
);
emitter.ripple.material.opacity =
(1 - rippleCycle) * 0.36;
}
}
layoutStatus.textContent = allLifted
? "Canopy clear"
: "Lifting emitters";
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("hidden"));
}
}
animate();
</script>
</body>
</html>
```