Prompt specification
Build or customize the Three.js 3D scene "Planter drainage outlet test" 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: Planter drainage outlet test
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/planter-drainage-outlet-test-x1118
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring urban rooftop farming. Apply a symbolic rain pulse to a planter and show excess water exiting through a visible outlet; keep the roof below separate from the contained growing medium. Voxel style.
Working Three.js Starter (planter-drainage-outlet-test-x1118):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Rooftop Farm — Rain Pulse</title>
<style>
:root {
color-scheme: dark;
--ink: #10242d;
--panel: rgba(13, 35, 44, 0.86);
--line: rgba(190, 235, 244, 0.18);
--text: #edfaff;
--muted: #a6c1ca;
--cyan: #38d6f2;
--green: #7bd66d;
--soil: #8e6044;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a8c7d0;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.panel {
position: fixed;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 19px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 16px;
box-shadow: 0 18px 60px rgba(15, 37, 45, 0.24);
backdrop-filter: blur(14px);
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--cyan);
box-shadow: 0 0 14px var(--cyan);
}
h1 {
margin: 0;
font-size: clamp(23px, 4vw, 31px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro {
margin: 12px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
button {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
width: 100%;
padding: 12px 14px;
border: 1px solid rgba(105, 231, 255, 0.46);
border-radius: 10px;
color: #09252e;
background: linear-gradient(135deg, #72e8ff, #35c7e5);
box-shadow: 0 8px 24px rgba(26, 185, 220, 0.2);
font: inherit;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: transform 150ms ease, filter 150ms ease;
}
button:hover { transform: translateY(-1px); filter: brightness(1.06); }
button:active { transform: translateY(1px); }
.pulse-icon {
position: relative;
width: 14px;
height: 14px;
border: 2px solid currentColor;
border-radius: 50%;
}
.pulse-icon::after {
content: "";
position: absolute;
inset: 3px;
border-radius: 50%;
background: currentColor;
}
.meters {
display: grid;
gap: 11px;
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.meter-row {
display: grid;
grid-template-columns: 78px 1fr 34px;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--cyan);
box-shadow: 0 0 10px rgba(56, 214, 242, 0.6);
transition: width 100ms linear;
}
.fill.drain { background: #6fe4ff; }
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 15px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
background: var(--soil);
}
.swatch.water { background: var(--cyan); }
.swatch.growth { background: var(--green); }
.toggle {
display: flex;
align-items: center;
gap: 7px;
margin-top: 14px;
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.toggle input { accent-color: var(--cyan); }
.status {
position: fixed;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
color: #eaffff;
background: rgba(13, 35, 44, 0.8);
border: 1px solid var(--line);
border-radius: 999px;
box-shadow: 0 8px 28px rgba(15, 37, 45, 0.16);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--green);
box-shadow: 0 0 12px currentColor;
}
.hint {
position: fixed;
right: 22px;
bottom: 22px;
padding: 9px 12px;
color: rgba(16, 36, 45, 0.75);
background: rgba(235, 249, 252, 0.64);
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 9px;
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 680px) {
.panel { top: 12px; left: 12px; width: calc(100vw - 24px); padding: 15px; }
.intro { margin: 9px 0 12px; }
.legend, .toggle { display: none; }
.status { left: 12px; bottom: 12px; }
.hint { right: 12px; bottom: 12px; }
.hint span { display: none; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel rooftop farming scene"></div>
<section class="panel">
<div class="eyebrow">Urban Water Lab / Block 07</div>
<h1>Rooftop<br />Rain Pulse</h1>
<p class="intro">
A symbolic irrigation event darkens the contained growing medium.
Excess water then exits the planter through a visible side outlet.
</p>
<button id="rainButton" type="button">
<span class="pulse-icon" aria-hidden="true"></span>
Trigger rain pulse
</button>
<div class="meters" aria-hidden="true">
<div class="meter-row">
<span>Rain</span>
<div class="track"><div class="fill" id="rainFill"></div></div>
<span id="rainValue">0%</span>
</div>
<div class="meter-row">
<span>Drain</span>
<div class="track"><div class="fill drain" id="drainFill"></div></div>
<span id="drainValue">0%</span>
</div>
</div>
<div class="legend">
<span><i class="swatch"></i> Growing medium</span>
<span><i class="swatch water"></i> Reclaimed water</span>
<span><i class="swatch growth"></i> Crops</span>
</div>
<label class="toggle">
<input id="labelToggle" type="checkbox" checked />
Show structural callouts
</label>
</section>
<div class="status" role="status" aria-live="polite">
<i class="status-dot" id="statusDot"></i>
<span id="statusText">System ready</span>
</div>
<div class="hint">Drag to orbit <span>· Scroll to zoom</span></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const rainButton = document.getElementById("rainButton");
const labelToggle = document.getElementById("labelToggle");
const rainFill = document.getElementById("rainFill");
const drainFill = document.getElementById("drainFill");
const rainValue = document.getElementById("rainValue");
const drainValue = document.getElementById("drainValue");
const statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaac8d1);
scene.fog = new THREE.Fog(0xaac8d1, 22, 58);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.65, -0.45);
let cameraTheta = 0.72;
let cameraPhi = 0.77;
const hemisphere = new THREE.HemisphereLight(0xd9f4ff, 0x526057, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d4, 3.1);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x8ddfff, 0.65);
rimLight.position.set(10, 6, -12);
scene.add(rimLight);
const materials = {
city: new THREE.MeshStandardMaterial({ color: 0x60747c, roughness: 0.94 }),
cityLight: new THREE.MeshStandardMaterial({ color: 0x7d9095, roughness: 0.95 }),
cityDark: new THREE.MeshStandardMaterial({ color: 0x43565f, roughness: 0.96 }),
facade: new THREE.MeshStandardMaterial({ color: 0x60747c, roughness: 0.92 }),
roof: new THREE.MeshStandardMaterial({ color: 0x849196, roughness: 0.9 }),
roofDark: new THREE.MeshStandardMaterial({ color: 0x606c72, roughness: 0.95 }),
seam: new THREE.MeshStandardMaterial({ color: 0x566269, roughness: 1 }),
parapet: new THREE.MeshStandardMaterial({ color: 0xa5b0b3, roughness: 0.9 }),
wood: new THREE.MeshStandardMaterial({ color: 0x9a6540, roughness: 0.88 }),
woodLight: new THREE.MeshStandardMaterial({ color: 0xb8784e, roughness: 0.86 }),
woodDark: new THREE.MeshStandardMaterial({ color: 0x71442e, roughness: 0.95 }),
soil: new THREE.MeshStandardMaterial({ color: 0x4d3023, roughness: 1 }),
soilClump: new THREE.MeshStandardMaterial({ color: 0x60402e, roughness: 1 }),
stem: new THREE.MeshStandardMaterial({ color: 0x397d3d, roughness: 0.9 }),
leafA: new THREE.MeshStandardMaterial({ color: 0x67bd52, roughness: 0.9 }),
leafB: new THREE.MeshStandardMaterial({ color: 0x8ed45e, roughness: 0.86 }),
leafC: new THREE.MeshStandardMaterial({ color: 0x3f9548, roughness: 0.92 }),
produce: new THREE.MeshStandardMaterial({ color: 0xf3a33b, roughness: 0.8 }),
metal: new THREE.MeshStandardMaterial({ color: 0x31464e, roughness: 0.55, metalness: 0.35 }),
metalLight: new THREE.MeshStandardMaterial({ color: 0x647982, roughness: 0.52, metalness: 0.28 }),
black: new THREE.MeshStandardMaterial({ color: 0x102329, roughness: 0.8 }),
water: new THREE.MeshStandardMaterial({
color: 0x31cbea,
emissive: 0x07506a,
emissiveIntensity: 0.7,
roughness: 0.22,
metalness: 0.05
}),
rain: new THREE.MeshStandardMaterial({
color: 0x67e6ff,
emissive: 0x1a7790,
emissiveIntensity: 0.85,
transparent: true,
opacity: 0.9,
depthWrite: false,
roughness: 0.2
}),
window: new THREE.MeshStandardMaterial({
color: 0xffd994,
emissive: 0xe5a64f,
emissiveIntensity: 0.55,
roughness: 0.4
})
};
function box(size, position, material, parent = scene) {
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 = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// City plinth.
box([70, 0.35, 70], [0, -3.5, 0], materials.cityDark);
function addCityBuilding(x, z, w, h, d, material) {
const baseY = -3.32;
const y = baseY + h / 2;
box([w, h, d], [x, y, z], material);
box([w + 0.22, 0.2, d + 0.22], [x, baseY + h + 0.1, z], materials.roofDark);
const cols = Math.max(2, Math.floor(w / 1.05));
const rows = Math.max(2, Math.floor(h / 1.05));
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
if ((row + col) % 4 === 0) continue;
const wx = x - w * 0.38 + col * (w * 0.76 / Math.max(1, cols - 1));
const wy = baseY + 0.72 + row * 0.92;
if (wy > baseY + h - 0.45) continue;
box([0.34, 0.48, 0.035], [wx, wy, z + d / 2 + 0.021], materials.window);
}
}
const tankH = 0.8;
box([0.9, tankH, 0.9], [x + w * 0.2, baseY + h + tankH / 2 + 0.2, z - d * 0.2], materials.cityDark);
}
addCityBuilding(-10.8, -7.8, 5.2, 7.0, 5.0, materials.cityDark);
addCityBuilding(8.0, -12.5, 6.2, 9.0, 5.0, materials.city);
addCityBuilding(-13.6, 1.3, 4.4, 4.4, 4.2, materials.cityLight);
addCityBuilding(-4.5, -16.0, 7.0, 5.2, 4.8, materials.cityDark);
addCityBuilding(14.0, -8.0, 5.0, 6.0, 4.8, materials.cityLight);
addCityBuilding(-16.0, -13.0, 4.0, 4.0, 4.0, materials.city);
// Main rooftop building.
box([11, 4.8, 8.4], [0, -0.92, -0.5], materials.facade);
box([11.4, 0.24, 8.8], [0, 1.54, -0.5], materials.roof);
// Roof tile seams emphasize that the deck is a separate structure.
for (let i = -5; i <= 5; i++) {
box([0.025, 0.025, 8.45], [i * 1.0, 1.674, -0.5], materials.seam);
}
for (let i = -4; i <= 4; i++) {
box([10.95, 0.025, 0.025], [0, 1.674, -0.5 + i * 0.95], materials.seam);
}
// Low parapets.
box([11.45, 0.46, 0.24], [0, 1.91, -4.78], materials.parapet);
box([0.24, 0.46, 8.5], [-5.58, 1.91, -0.5], materials.parapet);
box([0.24, 0.46, 8.5], [5.58, 1.91, -0.5], materials.parapet);
box([11.45, 0.24, 0.24], [0, 1.8, 3.78], materials.parapet);
// Building windows.
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 7; col++) {
if ((row + col) % 5 === 0) continue;
box(
[0.62, 0.68, 0.035],
[-4.3 + col * 1.43, -2.15 + row * 1.18, 3.72],
materials.window
);
}
}
// Rooftop utility blocks.
box([1.5, 0.95, 1.2], [3.95, 2.13, -2.65], materials.metalLight);
box([1.15, 0.12, 0.88], [3.95, 2.66, -2.65], materials.metal);
for (let i = 0; i < 5; i++) {
box([0.06, 0.48, 0.06], [3.48 + i * 0.22, 2.93, -2.65], materials.black);
}
box([0.8, 1.3, 0.8], [-4.1, 2.34, -2.85], materials.cityDark);
box([1.05, 0.16, 1.05], [-4.1, 3.05, -2.85], materials.metal);
box([0.08, 1.75, 0.08], [-4.95, 2.48, -3.75], materials.metal);
box([0.7, 0.06, 0.06], [-4.95, 3.31, -3.75], materials.metal);
const planterZ = -0.75;
const deckTop = 1.68;
// Four visible legs create a clear gap between roof deck and planter.
for (const x of [-1.62, 1.62]) {
for (const z of [-1.47, 0.0]) {
box([0.24, 0.46, 0.24], [x, deckTop + 0.23, z], materials.metal);
box([0.48, 0.08, 0.48], [x, deckTop + 0.04, z], materials.metalLight);
}
}
// Planter base and distinct contained soil volume.
box([4.3, 0.18, 2.55], [0, 2.15, planterZ], materials.woodDark);
const soil = box([3.86, 0.66, 2.12], [0, 2.58, planterZ], materials.soil);
const soilTop = 2.91;
// Side and back walls.
box([0.2, 0.9, 2.38], [-2.05, 2.69, planterZ], materials.wood);
box([0.2, 0.9, 2.38], [2.05, 2.69, planterZ], materials.woodLight);
box([4.1, 0.9, 0.2], [0, 2.69, -1.94], materials.woodDark);
// Front wall is assembled from separate voxel boards.
const frontZ = 0.44;
box([4.1, 0.3, 0.18], [0, 2.99, frontZ], materials.woodLight);
box([4.1, 0.3, 0.18], [0, 2.69, frontZ], materials.wood);
// Lower front boards leave a real opening for the drainage outlet.
box([3.2, 0.3, 0.18], [-0.45, 2.39, frontZ], materials.woodLight);
box([0.44, 0.3, 0.18], [1.83, 2.39, frontZ], materials.wood);
// Board seams.
for (const z of [-1.38, -0.35, 0.7]) {
box([0.025, 0.84, 0.025], [-2.16, 2.69, z], materials.woodDark);
box([0.025, 0.84, 0.025], [2.16, 2.69, z], materials.woodDark);
}
for (const x of [-1.45, -0.4, 0.65, 1.7]) {
box([0.025, 0.84, 0.025], [x, 2.69, -2.05], materials.woodDark);
}
// Soil clumps on top.
const clumpPositions = [
[-1.78, -1.45], [-1.05, -1.62], [-0.15, -1.57], [0.88, -1.58],
[1.74, -1.42], [-1.7, -0.05], [-0.8, 0.03], [0.15, 0.03],
[1.05, 0.03], [1.75, -0.03], [-1.15, -0.82], [0.55, -0.82]
];
clumpPositions.forEach(([x, z], i) => {
box(
[0.18 + (i % 3) * 0.045, 0.08, 0.18 + (i % 2) * 0.06],
[x, soilTop + 0.025, z],
materials.soilClump
);
});
// Voxel crops.
const plantPositions = [
[-1.43, -1.33], [-0.43, -1.45], [0.58, -1.35], [1.47, -1.32],
[-1.43, -0.17], [-0.4, -0.13], [0.66, -0.16], [1.46, -0.12]
];
const plantGroups = [];
plantPositions.forEach(([x, z], index) => {
const group = new THREE.Group();
group.position.set(x, soilTop, z);
scene.add(group);
const height = 0.5 + (index % 4) * 0.105;
box([0.12, height, 0.12], [0, height / 2, 0], materials.stem, group);
box([0.42, 0.38, 0.4], [0, height, 0], index % 2 ? materials.leafA : materials.leafB, group);
box([0.33, 0.3, 0.34], [-0.2, height - 0.09, 0.03], materials.leafC, group);
box([0.33, 0.3, 0.34], [0.2, height - 0.04, -0.03], materials.leafA, group);
box([0.26, 0.25, 0.27], [0.03, height + 0.2, 0.02], materials.leafB, group);
if (index === 2 || index === 6) {
box([0.24, 0.24, 0.24], [0.21, height - 0.17, 0.18], materials.produce, group);
}
plantGroups.push({ group, base: group.rotation.z, phase: index * 0.7 });
});
// Square outlet emerging through the lower front board.
const outletX = 1.38;
const outletY = 2.39;
box([0.43, 0.27, 0.04], [outletX, outletY, 0.55], materials.black);
box([0.34, 0.25, 0.73], [outletX, outletY, 0.83], materials.metal);
// Open mouth frame.
box([0.38, 0.045, 0.05], [outletX, outletY + 0.105, 1.215], materials.metalLight);
box([0.38, 0.045, 0.05], [outletX, outletY - 0.105, 1.215], materials.metalLight);
box([0.045, 0.25, 0.05], [outletX - 0.17, outletY, 1.215], materials.metalLight);
box([0.045, 0.25, 0.05], [outletX + 0.17, outletY, 1.215], materials.metalLight);
box([0.25, 0.16, 0.035], [outletX, outletY, 1.215], materials.black);
// Collection tray directly below the outlet.
box([1.7, 0.16, 1.18], [outletX, 1.76, 1.65], materials.metal);
const trayWater = box([1.36, 0.055, 0.84], [outletX, 1.87, 1.65], materials.water);
box([0.06, 0.1, 0.92], [outletX - 0.68, 1.87, 1.65], materials.metalLight);
box([0.06, 0.1, 0.92], [outletX + 0.68, 1.87, 1.65], materials.metalLight);
// Symbolic voxel rain cloud.
const cloudGroup = new THREE.Group();
cloudGroup.position.set(0, 4.95, planterZ);
scene.add(cloudGroup);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xd7f4fa,
emissive: 0x286f80,
emissiveIntensity: 0.25,
transparent: true,
opacity: 0,
depthWrite: false,
roughness: 0.75
});
box([2.25, 0.43, 0.82], [0, 0, 0], cloudMaterial, cloudGroup);
box([0.72, 0.66, 0.86], [-0.78, 0.03, 0], cloudMaterial, cloudGroup);
box([0.82, 0.84, 0.9], [-0.22, 0.22, 0], cloudMaterial, cloudGroup);
box([0.68, 0.61, 0.83], [0.65, 0.1, 0], cloudMaterial, cloudGroup);
box([0.9, 0.52, 0.8], [1.08, -0.01, 0], cloudMaterial, cloudGroup);
cloudGroup.visible = false;
// Square pulse brackets around the growing medium.
const pulseGroup = new THREE.Group();
pulseGroup.position.set(0, 3.22, planterZ);
scene.add(pulseGroup);
const pulseMaterial = new THREE.MeshStandardMaterial({
color: 0x4be4ff,
emissive: 0x1496b3,
emissiveIntensity: 1.0,
transparent: true,
opacity: 0,
depthWrite: false
});
const pulsePoints = [];
for (let i = 0; i < 7; i++) {
const t = -1.75 + i * 0.583;
pulsePoints.push([t, -1.03], [t, 1.03]);
}
for (let i = 0; i < 4; i++) {
const t = -0.69 + i * 0.46;
pulsePoints.push([-1.92, t], [1.92, t]);
}
pulsePoints.forEach(([x, z]) => {
box([0.16, 0.065, 0.16], [x, 0, z], pulseMaterial, pulseGroup);
});
pulseGroup.visible = false;
// Rain cubes.
const rainDrops = [];
const dropCount = 42;
for (let i = 0; i < dropCount; i++) {
const x = -1.78 + ((i * 0.61803398875) % 1) * 3.56;
const z = planterZ - 0.93 + ((i * 0.41421356237) % 1) * 1.86;
const drop = box([0.065, 0.29, 0.065], [x, 5, z], materials.rain);
drop.castShadow = false;
drop.visible = false;
rainDrops.push({ mesh: drop, x, z, offset: i / dropCount });
}
// Splash cubes at the medium surface.
const splashes = [];
for (let i = 0; i < 24; i++) {
const x = -1.7 + ((i * 0.7548776662) % 1) * 3.4;
const z = planterZ - 0.83 + ((i * 0.5698402909) % 1) * 1.66;
const splash = box([0.08, 0.08, 0.08], [x, soilTop, z], materials.rain);
splash.castShadow = false;
splash.visible = false;
splashes.push({ mesh: splash, x, z, offset: i / 24 });
}
// Visible excess-water stream leaving the outlet.
const waterDrops = [];
for (let i = 0; i < 30; i++) {
const drop = box(
[0.075 + (i % 3) * 0.012, 0.13 + (i % 2) * 0.05, 0.075],
[outletX, outletY, 1.25],
materials.water
);
drop.castShadow = false;
drop.visible = false;
waterDrops.push({ mesh: drop, offset: i / 30 });
}
const outletFlow = box(
[0.22, 0.12, 0.035],
[outletX, outletY, 1.24],
materials.water
);
outletFlow.castShadow = false;
outletFlow.visible = false;
// Lightweight canvas-sprite callouts.
function makeLabel(text, color = "#e9fbff", background = "rgba(12,35,44,0.88)") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 512, 96);
ctx.strokeStyle = "rgba(116,224,244,0.55)";
ctx.lineWidth = 4;
ctx.strokeRect(2, 2, 508, 92);
ctx.fillStyle = color;
ctx.font = "800 28px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(2.5, 0.47, 1);
return sprite;
}
const labelGroup = new THREE.Group();
scene.add(labelGroup);
const mediumLabel = makeLabel("CONTAINED MEDIUM");
mediumLabel.position.set(-3.45, 3.25, -0.65);
labelGroup.add(mediumLabel);
const roofLabel = makeLabel("ELEVATED ROOF DECK");
roofLabel.position.set(-3.7, 1.95, 1.05);
roofLabel.scale.set(2.45, 0.46, 1);
labelGroup.add(roofLabel);
const outletLabel = makeLabel("EXCESS OUTLET");
outletLabel.position.set(3.0, 2.82, 1.02);
outletLabel.scale.set(2.0, 0.38, 1);
labelGroup.add(outletLabel);
labelToggle.addEventListener("change", () => {
labelGroup.visible = labelToggle.checked;
});
// Animation state.
const clock = new THREE.Clock();
const drySoil = new THREE.Color(0x4d3023);
const wetSoil = new THREE.Color(0x281b16);
let rainStart = -100;
let drainStart = -100;
let nextAutoPulse = 1.0;
let elapsed = 0;
function triggerRain(time = clock.getElapsedTime()) {
rainStart = time;
drainStart = time + 0.68;
nextAutoPulse = time + 8.5;
}
rainButton.addEventListener("click", () => triggerRain());
function updateCamera() {
const radius = 18;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z + radius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(11.5, 13.2 / 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);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Direct camera controls implemented without Three.js addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi + dy * 0.005, 0.42, 1.32);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.85
);
camera.updateProjectionMatrix();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraTheta = 0.72;
cameraPhi = 0.77;
camera.zoom = 1;
camera.updateProjectionMatrix();
updateCamera();
});
function animate() {
requestAnimationFrame(animate);
elapsed = clock.getElapsedTime();
if (elapsed >= nextAutoPulse) {
triggerRain(elapsed);
}
const rainAge = elapsed - rainStart;
const drainAge = elapsed - drainStart;
const rainActive = rainAge >= 0 && rainAge < 1.85;
const drainActive = drainAge >= 0 && drainAge < 3.85;
const rainEnvelope = rainActive
? Math.min(1, rainAge / 0.16) * Math.min(1, (1.85 - rainAge) / 0.25)
: 0;
// Cloud and pulse symbols.
cloudGroup.visible = rainActive;
cloudMaterial.opacity = 0.76 * rainEnvelope;
cloudGroup.scale.setScalar(1 + Math.sin(rainAge * 10) * 0.055);
cloudGroup.position.y = 4.95 + Math.sin(rainAge * 5) * 0.06;
pulseGroup.visible = rainActive;
pulseMaterial.opacity = 0.88 * rainEnvelope;
pulseGroup.scale.setScalar(1 + Math.sin(rainAge * 8) * 0.09);
// Symbolic rain.
rainDrops.forEach(({ mesh, x, z, offset }) => {
mesh.visible = rainActive;
if (!rainActive) return;
const cycle = (rainAge * 1.7 + offset) % 1;
mesh.position.set(x, 4.72 - cycle * 1.82, z);
mesh.scale.y = 0.8 + cycle * 0.8;
});
splashes.forEach(({ mesh, x, z, offset }) => {
const cycle = (rainAge * 2.45 + offset) % 1;
mesh.visible = rainActive && cycle < 0.2;
if (!mesh.visible) return;
const p = cycle / 0.2;
mesh.position.set(x, soilTop + Math.sin(p * Math.PI) * 0.24, z);
mesh.scale.setScalar(0.65 + p * 0.8);
});
// Soil becomes visibly darker after the rain pulse.
let wetness = 0;
if (rainAge >= 0 && rainAge < 4.6) {
wetness = rainAge < 1.2 ? rainAge / 1.2 : 1 - (rainAge - 1.2) / 3.4;
}
materials.soil.color.copy(drySoil).lerp(wetSoil, THREE.MathUtils.clamp(wetness, 0, 1) * 0.72);
// Excess water leaving the visible outlet.
outletFlow.visible = drainActive;
outletFlow.scale.x = 0.85 + Math.sin(elapsed * 20) * 0.15;
waterDrops.forEach(({ mesh, offset }) => {
mesh.visible = drainActive;
if (!drainActive) return;
const cycle = (drainAge * 1.55 + offset) % 1;
const lateral = ((offset * 17) % 1 - 0.5) * 0.16;
mesh.position.set(
outletX + lateral,
outletY - cycle * 0.63,
1.27 + cycle * 0.32
);
mesh.scale.set(1, 1 + cycle * 0.35, 1);
});
trayWater.scale.y = 1 + (drainActive ? Math.sin(elapsed * 8) * 0.12 : 0);
trayWater.position.y = 1.87 + (drainActive ? Math.sin(elapsed * 8) * 0.012 : 0);
// Plants react subtly to the pulse.
plantGroups.forEach(({ group, base, phase }) => {
group.rotation.z = base + Math.sin(elapsed * 2.2 + phase) * (rainActive ? 0.045 : 0.012);
group.rotation.x = Math.cos(elapsed * 1.8 + phase) * (rainActive ? 0.025 : 0.006);
});
// UI feedback.
const rainPercent = rainActive ? Math.round(rainEnvelope * 100) : 0;
const drainPercent = drainActive ? Math.round(Math.min(1, drainAge / 0.3) * 100) : 0;
rainFill.style.width = `${rainPercent}%`;
drainFill.style.width = `${drainPercent}%`;
rainValue.textContent = `${rainPercent}%`;
drainValue.textContent = `${drainPercent}%`;
if (rainActive) {
statusText.textContent = "Rain pulse active";
statusDot.style.background = "#38d6f2";
statusDot.style.color = "#38d6f2";
} else if (drainActive) {
statusText.textContent = "Excess water draining";
statusDot.style.background = "#38d6f2";
statusDot.style.color = "#38d6f2";
} else {
statusText.textContent = "Medium contained · System ready";
statusDot.style.background = "#7bd66d";
statusDot.style.color = "#7bd66d";
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```