Prompt specification
Build or customize the Three.js 3D scene "Stormwater neighborhood planning game" 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: Stormwater neighborhood planning game
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stormwater-neighborhood-planning-game-x1264
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: stormwater neighborhood planning game. Let users add a rain garden or permeable strip to a compact block; show schematic runoff routes and relative storage with resettable rainfall and no engineering capacity claims. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (stormwater-neighborhood-planning-game-x1264):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cloudblock — Stormwater Sketch Game</title>
<style>
:root {
--ink: #183338;
--muted: #61777a;
--paper: rgba(250, 252, 249, 0.94);
--line: rgba(24, 51, 56, 0.13);
--blue: #238eae;
--teal: #238f79;
--teal-light: #dff3e9;
--coral: #e88368;
--shadow: 0 16px 45px rgba(38, 67, 68, 0.16);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
color: var(--ink);
background: #dfe9e4;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene canvas:active { cursor: grabbing; }
#scene canvas.build-mode { cursor: crosshair; }
.brand {
position: fixed;
z-index: 5;
top: 18px;
left: 20px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: none;
}
.brand-mark {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border-radius: 13px;
color: white;
background: var(--ink);
box-shadow: 0 8px 20px rgba(24, 51, 56, .18);
}
.brand-mark svg { width: 25px; height: 25px; }
.brand h1 {
margin: 0;
font-size: 20px;
letter-spacing: -.035em;
line-height: 1;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: .08em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 4;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, .75);
border-radius: 20px;
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.control-panel {
top: 80px;
left: 20px;
width: 306px;
max-height: calc(100vh - 104px);
overflow: auto;
padding: 17px;
scrollbar-width: thin;
}
.stats-panel {
top: 20px;
right: 20px;
width: 282px;
padding: 17px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--teal);
font-size: 10px;
font-weight: 900;
letter-spacing: .14em;
text-transform: uppercase;
}
h2, h3 { margin: 0; }
h2 {
font-size: 18px;
letter-spacing: -.025em;
}
h3 {
font-size: 13px;
letter-spacing: -.01em;
}
.intro {
margin: 8px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.section {
padding-top: 15px;
margin-top: 15px;
border-top: 1px solid var(--line);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.step {
display: inline-grid;
place-items: center;
width: 20px;
height: 20px;
margin-right: 7px;
border-radius: 7px;
background: var(--ink);
color: white;
font-size: 10px;
font-weight: 900;
}
.tools {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.tool {
min-height: 94px;
padding: 11px;
text-align: left;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255,255,255,.75);
transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.tool:hover {
transform: translateY(-2px);
border-color: rgba(35, 143, 121, .45);
}
.tool.active {
border-color: var(--teal);
background: var(--teal-light);
box-shadow: inset 0 0 0 1px var(--teal);
}
.tool-icon {
display: grid;
place-items: center;
width: 36px;
height: 30px;
margin-bottom: 8px;
border-radius: 9px;
background: #e7eee9;
color: var(--teal);
}
.tool-icon svg {
width: 26px;
height: 23px;
}
.tool strong {
display: block;
font-size: 12px;
line-height: 1.2;
}
.tool small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.mode-note {
min-height: 31px;
margin-top: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.weather-readout {
display: flex;
align-items: center;
justify-content: space-between;
margin: 2px 0 8px;
font-size: 11px;
}
.weather-readout output {
color: var(--blue);
font-weight: 900;
letter-spacing: .05em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 7px 0 13px;
appearance: none;
border-radius: 99px;
background: linear-gradient(90deg, var(--blue), #87cbd1);
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
appearance: none;
border: 3px solid white;
border-radius: 50%;
background: var(--blue);
box-shadow: 0 2px 8px rgba(24, 51, 56, .22);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid white;
border-radius: 50%;
background: var(--blue);
box-shadow: 0 2px 8px rgba(24, 51, 56, .22);
}
.button-row {
display: flex;
gap: 8px;
}
.primary, .secondary, .danger {
min-height: 38px;
border-radius: 11px;
font-size: 11px;
font-weight: 850;
transition: transform .15s ease, background .15s ease, opacity .15s ease;
}
.primary:hover, .secondary:hover, .danger:hover { transform: translateY(-1px); }
.primary {
flex: 1;
border: 0;
color: white;
background: var(--ink);
}
.primary.running {
background: var(--blue);
}
.secondary {
padding: 0 13px;
border: 1px solid var(--line);
background: white;
}
.danger {
width: 100%;
border: 1px solid rgba(207, 91, 71, .25);
color: #a84e3e;
background: rgba(232, 131, 104, .08);
}
.danger:disabled, .primary:disabled {
cursor: default;
opacity: .42;
transform: none;
}
.hint-list {
margin: 0;
padding: 0;
list-style: none;
color: var(--muted);
font-size: 11px;
line-height: 1.65;
}
.hint-list li {
position: relative;
padding-left: 17px;
}
.hint-list li::before {
content: "";
position: absolute;
left: 1px;
top: 7px;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--teal);
}
.summary-count {
margin-top: 5px;
color: var(--muted);
font-size: 11px;
}
.storage-meter {
height: 9px;
margin: 13px 0 8px;
overflow: hidden;
border-radius: 99px;
background: #e7ece8;
}
.storage-meter > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #62b8a0, var(--teal));
transition: width .3s ease;
}
.storage-label {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.plan-list {
display: grid;
gap: 8px;
max-height: 190px;
overflow: auto;
margin-top: 13px;
padding-right: 2px;
}
.empty-plan {
padding: 13px;
border: 1px dashed rgba(24, 51, 56, .18);
border-radius: 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
text-align: center;
}
.plan-row {
display: grid;
grid-template-columns: 12px 1fr auto 24px;
align-items: center;
gap: 8px;
padding: 9px;
border-radius: 11px;
background: rgba(230, 239, 234, .68);
}
.swatch {
width: 10px;
height: 10px;
border-radius: 4px;
background: var(--teal);
}
.swatch.strip { background: #c99d59; }
.plan-row strong {
display: block;
font-size: 10px;
}
.plan-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.mini-bars {
display: flex;
gap: 2px;
}
.mini-bars i {
display: block;
width: 4px;
height: 12px;
border-radius: 2px;
background: #d3ddd8;
}
.mini-bars i.on { background: var(--teal); }
.remove-button {
width: 24px;
height: 24px;
padding: 0;
border: 0;
border-radius: 8px;
color: var(--muted);
background: rgba(255,255,255,.7);
font-size: 16px;
line-height: 1;
}
.remove-button:hover {
color: #a84e3e;
background: white;
}
.disclaimer {
margin: 13px 0 0;
padding: 10px;
border-radius: 11px;
color: #6c7774;
background: #f0f2ed;
font-size: 9px;
line-height: 1.5;
}
.legend {
position: fixed;
z-index: 3;
left: 50%;
bottom: 18px;
display: flex;
align-items: center;
gap: 15px;
padding: 9px 13px;
transform: translateX(-50%);
border: 1px solid rgba(255,255,255,.65);
border-radius: 14px;
color: var(--muted);
background: rgba(250, 252, 249, .86);
box-shadow: 0 8px 28px rgba(38, 67, 68, .1);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 750;
white-space: nowrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-line {
width: 18px;
height: 3px;
border-radius: 2px;
background: var(--blue);
}
.legend-line.managed { background: var(--teal); }
.legend-shape {
width: 11px;
height: 11px;
border-radius: 50%;
background: #58a77e;
}
.legend-shape.strip {
width: 15px;
border-radius: 3px;
background: #c99d59;
}
.tooltip {
position: fixed;
z-index: 8;
display: none;
max-width: 190px;
padding: 8px 10px;
pointer-events: none;
border-radius: 9px;
color: white;
background: rgba(24, 51, 56, .93);
box-shadow: 0 8px 22px rgba(24,51,56,.18);
font-size: 10px;
line-height: 1.4;
}
.toast {
position: fixed;
z-index: 9;
left: 50%;
top: 24px;
max-width: min(440px, calc(100vw - 32px));
padding: 10px 14px;
transform: translate(-50%, -18px);
opacity: 0;
pointer-events: none;
border-radius: 11px;
color: white;
background: rgba(24, 51, 56, .94);
box-shadow: 0 10px 30px rgba(24,51,56,.18);
font-size: 11px;
font-weight: 700;
transition: opacity .2s ease, transform .2s ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 900px) {
.control-panel {
width: 276px;
}
.stats-panel {
width: 250px;
}
.legend { gap: 9px; }
}
@media (max-width: 680px) {
.brand {
top: 10px;
left: 10px;
}
.brand-mark {
width: 36px;
height: 36px;
}
.brand h1 { font-size: 16px; }
.brand p { display: none; }
.control-panel {
top: 56px;
left: 10px;
width: min(250px, calc(100vw - 20px));
max-height: 43vh;
padding: 13px;
}
.stats-panel {
top: auto;
right: 10px;
bottom: 10px;
width: min(250px, calc(100vw - 20px));
max-height: 34vh;
overflow: auto;
padding: 13px;
}
.legend {
display: none;
}
.intro { display: none; }
.tool { min-height: 80px; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly stormwater neighborhood"></div>
<header class="brand">
<div class="brand-mark" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M6.5 15.5h10.8a3.2 3.2 0 0 0 .35-6.38A5.4 5.4 0 0 0 7.1 7.7 4 4 0 0 0 6.5 15.5Z"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8 18.5 6.8 21M13 18.5l-1.2 2.5M18 18.5l-1.2 2.5"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
</svg>
</div>
<div>
<h1>Cloudblock</h1>
<p>Neighborhood runoff sketch</p>
</div>
</header>
<section class="panel control-panel" aria-label="Planning controls">
<p class="eyebrow">Plan a compact block</p>
<h2>Shape the runoff story</h2>
<p class="intro">
Add green infrastructure, sketch a storm, and compare how the neighborhood route changes.
</p>
<div class="section-heading">
<h3><span class="step">1</span>Choose a treatment</h3>
</div>
<div class="tools">
<button class="tool" id="gardenTool" type="button" aria-pressed="false">
<span class="tool-icon" aria-hidden="true">
<svg viewBox="0 0 32 26" fill="none">
<path d="M3 20c5-7 9-7 13-2s9 4 13-1" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/>
<path d="M9 19c0-6 3-10 7-14 0 6 1 10-2 14M20 18c-1-6 1-10 5-14 1 6 1 10-1 14"
stroke="currentColor" stroke-width="2.4" stroke-linejoin="round"/>
</svg>
</span>
<strong>Rain garden</strong>
<small>More relative visual storage</small>
</button>
<button class="tool" id="stripTool" type="button" aria-pressed="false">
<span class="tool-icon" aria-hidden="true">
<svg viewBox="0 0 32 26" fill="none">
<path d="M8 3h16v20H8z" fill="#d8c49d" stroke="currentColor" stroke-width="1.8"/>
<path d="M8 9h16M8 15h16M13 3v20M19 3v20" stroke="currentColor" stroke-width="1.2"/>
<path d="M22 7h7M25 4l4 3-4 3" stroke="#238eae" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
<strong>Permeable strip</strong>
<small>Less relative visual storage</small>
</button>
</div>
<p class="mode-note" id="modeNote">
Pick a treatment, then select a highlighted neighborhood lot.
</p>
<div class="section">
<div class="section-heading">
<h3><span class="step">2</span>Sketch the rainfall</h3>
</div>
<div class="weather-readout">
<span>Relative storm strength</span>
<output id="rainLabel">Steady</output>
</div>
<input id="rainSlider" type="range" min="10" max="100" value="55"
aria-label="Relative storm strength" />
<div class="button-row">
<button class="primary" id="rainToggle" type="button">Start rain</button>
<button class="secondary" id="resetRain" type="button">Reset rain</button>
</div>
</div>
<div class="section">
<h3>Controls</h3>
<ul class="hint-list">
<li>Click a highlighted lot to place a treatment.</li>
<li>Drag to orbit; scroll to zoom.</li>
<li>Shift-drag to pan around the block.</li>
<li>Reset rain without removing your plan.</li>
</ul>
</div>
</section>
<aside class="panel stats-panel" aria-label="Plan snapshot">
<p class="eyebrow">Plan snapshot</p>
<h2>Relative storage</h2>
<p class="summary-count" id="planCount">0 of 6 lots treated</p>
<div class="storage-meter" aria-hidden="true"><span id="storageFill"></span></div>
<div class="storage-label">
<span id="storageLabel">Empty plan</span>
<span>visual comparison</span>
</div>
<div class="plan-list" id="planList">
<div class="empty-plan">
Your block is untreated.<br>Add a rain garden or permeable strip to compare relative storage.
</div>
</div>
<button class="danger" id="clearPlan" type="button" disabled>Clear all treatments</button>
<p class="disclaimer">
Schematic gameplay only. Relative storage is a visual comparison—not a volume, sizing,
performance, rainfall-depth, or engineering-capacity estimate.
</p>
</aside>
<div class="legend" aria-label="Scene legend">
<span class="legend-item"><i class="legend-line"></i> Roof runoff</span>
<span class="legend-item"><i class="legend-line managed"></i> Managed route</span>
<span class="legend-item"><i class="legend-shape"></i> Rain garden</span>
<span class="legend-item"><i class="legend-shape strip"></i> Permeable strip</span>
</div>
<div class="tooltip" id="tooltip"></div>
<div class="toast" id="toast" role="status" aria-live="polite"></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 tooltip = document.getElementById("tooltip");
const toast = document.getElementById("toast");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe9e4);
scene.fog = new THREE.Fog(0xdfe9e4, 55, 95);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 160);
const orbit = {
target: new THREE.Vector3(0, 0.6, 0),
radius: 49,
theta: 0.72,
phi: 0.87,
zoom: 1
};
const up = new THREE.Vector3(0, 1, 0);
const spherical = new THREE.Spherical();
function updateCamera() {
spherical.set(orbit.radius, orbit.phi, orbit.theta);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(orbit.target).add(offset);
camera.lookAt(orbit.target);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(31, 43 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemi = new THREE.HemisphereLight(0xf8fff9, 0x7d9486, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3dc, 3.2);
sun.position.set(-18, 28, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.0005;
scene.add(sun);
const world = new THREE.Group();
scene.add(world);
const materials = {
ground: new THREE.MeshStandardMaterial({ color: 0xc8d8c8, roughness: 1 }),
road: new THREE.MeshStandardMaterial({ color: 0x596568, roughness: 0.92 }),
curb: new THREE.MeshStandardMaterial({ color: 0xd8ded8, roughness: 0.95 }),
lane: new THREE.MeshStandardMaterial({ color: 0xf0d78f, roughness: 0.9 }),
white: new THREE.MeshStandardMaterial({ color: 0xf4f4e9, roughness: 0.9 }),
drain: new THREE.MeshStandardMaterial({ color: 0x273c40, roughness: 0.65 }),
trunk: new THREE.MeshStandardMaterial({ color: 0x785f48, roughness: 1 }),
leafA: new THREE.MeshStandardMaterial({ color: 0x477f62, roughness: 1, flatShading: true }),
leafB: new THREE.MeshStandardMaterial({ color: 0x6a9b69, roughness: 1, flatShading: true }),
leafC: new THREE.MeshStandardMaterial({ color: 0x3d7868, roughness: 1, flatShading: true })
};
function box(parent, w, h, d, material, x, y, z, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, rt, rb, h, segments, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
cylinder(group, 0.16, 0.22, 1.35, 6, materials.trunk, 0, 0.67, 0);
const crown = new THREE.Mesh(
new THREE.DodecahedronGeometry(1.05, 0),
[materials.leafA, materials.leafB, materials.leafC][Math.floor(Math.random() * 3)]
);
crown.position.y = 2.05;
crown.scale.set(1, 1.15, 0.95);
crown.castShadow = true;
crown.receiveShadow = true;
group.add(crown);
world.add(group);
}
function makeLabel(text, background = "#183338", foreground = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 80;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.beginPath();
if (ctx.roundRect) ctx.roundRect(4, 4, 248, 72, 28);
else ctx.rect(4, 4, 248, 72);
ctx.fill();
ctx.fillStyle = foreground;
ctx.font = "800 30px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 128, 42);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.25, 0.7, 1);
sprite.renderOrder = 20;
return sprite;
}
// Ground and compact street grid.
box(world, 42, 0.5, 30, materials.ground, 0, -0.32, 0, false);
box(world, 42.5, 0.13, 4.6, materials.road, 0, 0.055, 0, false);
box(world, 4.6, 0.13, 30, materials.road, -7, 0.06, 0, false);
box(world, 4.6, 0.13, 30, materials.road, 7, 0.06, 0, false);
// Curb edges.
box(world, 42, 0.18, 0.22, materials.curb, 0, 0.13, -2.38, false);
box(world, 42, 0.18, 0.22, materials.curb, 0, 0.13, 2.38, false);
box(world, 0.22, 0.18, 30, materials.curb, -9.38, 0.13, 0, false);
box(world, 0.22, 0.18, 30, materials.curb, -4.62, 0.13, 0, false);
box(world, 0.22, 0.18, 30, materials.curb, 4.62, 0.13, 0, false);
box(world, 0.22, 0.18, 30, materials.curb, 9.38, 0.13, 0, false);
// Center lane dashes.
for (let x = -19; x <= 19; x += 3) {
if (Math.abs(Math.abs(x) - 7) < 3.5) continue;
box(world, 1.05, 0.025, 0.09, materials.lane, x, 0.14, 0, false);
}
for (let z = -13; z <= 13; z += 3) {
if (Math.abs(z) < 3.5) continue;
box(world, 0.09, 0.025, 1.05, materials.lane, -7, 0.145, z, false);
box(world, 0.09, 0.025, 1.05, materials.lane, 7, 0.145, z, false);
}
// Crosswalks.
for (const x of [-7, 7]) {
for (let i = 0; i < 5; i++) {
box(world, 0.42, 0.025, 1.45, materials.white, x - 1.55 + i * 0.78, 0.145, -3.05, false);
box(world, 0.42, 0.025, 1.45, materials.white, x - 1.55 + i * 0.78, 0.145, 3.05, false);
}
}
const parcels = [];
const lotPickers = [];
const roofColors = [0xc97962, 0xd4a94f, 0x648a91, 0x8b7d9c, 0x6f9272, 0xb57665];
const lotDefinitions = [
{ id: "A1", x: -14, z: -7 },
{ id: "A2", x: 0, z: -7 },
{ id: "A3", x: 14, z: -7 },
{ id: "B1", x: -14, z: 7 },
{ id: "B2", x: 0, z: 7 },
{ id: "B3", x: 14, z: 7 }
];
function makeHouse(parcel, index) {
const group = new THREE.Group();
group.position.set(parcel.x, 0, parcel.z);
const wallColor = [0xe6d8bf, 0xd9c8ac, 0xc6d8cf, 0xd8c5b7, 0xd8dfc6, 0xcdd8d4][index];
const wallMat = new THREE.MeshStandardMaterial({ color: wallColor, roughness: 0.93 });
const roofMat = new THREE.MeshStandardMaterial({
color: roofColors[index],
roughness: 0.9,
flatShading: true
});
const windowMat = new THREE.MeshStandardMaterial({
color: 0x315462,
roughness: 0.36,
metalness: 0.08
});
const doorMat = new THREE.MeshStandardMaterial({ color: 0x5f766f, roughness: 0.8 });
box(group, 2.65, 2.25, 2.55, wallMat, 0, 1.18, -1.25);
const roof = new THREE.Mesh(new THREE.ConeGeometry(2.15, 1.15, 4), roofMat);
roof.position.set(0, 2.83, -1.25);
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
box(group, 0.55, 1.25, 0.55, roofMat, -0.62, 3.35, -1.5);
box(group, 0.54, 0.62, 0.06, windowMat, -0.65, 1.45, 0.04);
box(group, 0.54, 0.62, 0.06, windowMat, 0.65, 1.45, 0.04);
box(group, 0.58, 1.25, 0.07, doorMat, 0, 0.74, 0.045);
box(group, 0.06, 0.62, 0.58, windowMat, 1.34, 1.43, -1.25);
box(group, 1.25, 0.12, 0.72, materials.curb, 0, 0.12, 0.55, false);
world.add(group);
}
function makeDrain(x, z) {
box(world, 1.15, 0.13, 0.65, materials.drain, x, 0.18, z, false);
for (let i = 0; i < 4; i++) {
box(world, 0.12, 0.035, 0.49, materials.curb, x - 0.36 + i * 0.24, 0.27, z, false);
}
}
lotDefinitions.forEach((definition, index) => {
const parcel = {
...definition,
intervention: null,
interventionGroup: null,
water: null,
baseColor: index % 2 ? 0xb9cfb9 : 0xc4d6c1
};
const tileMat = new THREE.MeshStandardMaterial({
color: parcel.baseColor,
roughness: 1,
transparent: true,
opacity: 0.82,
depthWrite: false
});
const tile = new THREE.Mesh(new THREE.PlaneGeometry(6.15, 6.15), tileMat);
tile.rotation.x = -Math.PI / 2;
tile.position.set(parcel.x, 0.125, parcel.z);
tile.receiveShadow = true;
tile.userData.parcelId = parcel.id;
world.add(tile);
lotPickers.push(tile);
parcel.tile = tile;
const borderPoints = [
new THREE.Vector3(parcel.x - 3.05, 0.19, parcel.z - 3.05),
new THREE.Vector3(parcel.x + 3.05, 0.19, parcel.z - 3.05),
new THREE.Vector3(parcel.x + 3.05, 0.19, parcel.z + 3.05),
new THREE.Vector3(parcel.x - 3.05, 0.19, parcel.z + 3.05)
];
const border = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(borderPoints),
new THREE.LineBasicMaterial({ color: 0x738b7d, transparent: true, opacity: 0.48 })
);
world.add(border);
makeHouse(parcel, index);
makeDrain(parcel.x, parcel.z < 0 ? -2.6 : 2.6);
const idLabel = makeLabel(definition.id, "#f4f7f1", "#38595a");
idLabel.scale.set(0.95, 0.3, 1);
idLabel.position.set(parcel.x - 2.35, 0.48, parcel.z + 2.65);
world.add(idLabel);
parcels.push(parcel);
});
// Perimeter planting and neighborhood furniture.
[
[-19.2, -11.5, 1.05], [-18.8, -4.8, 0.85], [-19.1, 4.2, 1.1], [-18.7, 11.5, .9],
[-3.3, -12.5, .82], [3.4, -12.4, .95], [-3.5, 12.4, .9], [3.3, 12.5, .82],
[11.2, -12.4, .88], [18.9, -11.4, 1.1], [11.4, 12.2, .95], [18.8, 11.2, 1.05],
[19.2, -4.2, .82], [19.1, 4.2, .85]
].forEach(args => makeTree(...args));
const benchMat = new THREE.MeshStandardMaterial({ color: 0x936f4c, roughness: 0.9 });
box(world, 1.6, 0.13, 0.48, benchMat, -10.1, .55, -7, false);
box(world, 0.14, .45, .38, materials.drain, -10.7, .28, -7, false);
box(world, 0.14, .45, .38, materials.drain, -9.5, .28, -7, false);
// A small schematic outlet at the downstream edge.
const outlet = new THREE.Group();
outlet.position.set(19.1, 0, 0);
const pipe = new THREE.Mesh(
new THREE.CylinderGeometry(.58, .58, 1.25, 10),
new THREE.MeshStandardMaterial({ color: 0x3d5659, roughness: .7 })
);
pipe.rotation.z = Math.PI / 2;
pipe.position.y = .5;
pipe.castShadow = true;
outlet.add(pipe);
const outletWater = new THREE.Mesh(
new THREE.CircleGeometry(.43, 18),
new THREE.MeshStandardMaterial({ color: 0x52a9bd, roughness: .35 })
);
outletWater.rotation.y = Math.PI / 2;
outletWater.position.set(.66, .5, 0);
outlet.add(outletWater);
world.add(outlet);
const outletLabel = makeLabel("OUT", "#e9f2ed", "#2d6264");
outletLabel.scale.set(1.1, .36, 1);
outletLabel.position.set(18.7, 1.55, -.75);
world.add(outletLabel);
// Low-poly cloud.
const cloud = new THREE.Group();
cloud.position.set(-10, 10.5, -7.5);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf4f6ef,
roughness: 1,
flatShading: true
});
[
[-1.45, 0, 0, 1.25], [-.35, .35, .1, 1.55], [.85, .12, 0, 1.3],
[1.75, -.15, .1, .95], [.15, -.25, .25, 1.15]
].forEach(([x, y, z, s]) => {
const puff = new THREE.Mesh(new THREE.DodecahedronGeometry(s, 1), cloudMaterial);
puff.position.set(x, y, z);
puff.castShadow = true;
cloud.add(puff);
});
world.add(cloud);
// Rain particles.
const rainCount = 360;
const rainPositions = new Float32Array(rainCount * 3);
for (let i = 0; i < rainCount; i++) {
rainPositions[i * 3] = (Math.random() - .5) * 43;
rainPositions[i * 3 + 1] = Math.random() * 18;
rainPositions[i * 3 + 2] = (Math.random() - .5) * 29;
}
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute("position", new THREE.BufferAttribute(rainPositions, 3));
const rainMaterial = new THREE.PointsMaterial({
color: 0x4b9fb8,
size: .13,
transparent: true,
opacity: .72,
depthWrite: false
});
const rainPoints = new THREE.Points(rainGeometry, rainMaterial);
rainPoints.visible = false;
world.add(rainPoints);
const state = {
tool: null,
hoverParcel: null,
rain: {
running: false,
intensity: 55,
elapsed: 0
}
};
const routeGroup = new THREE.Group();
world.add(routeGroup);
const routes = [];
function interventionPosition(parcel) {
if (parcel.intervention === "garden") {
return new THREE.Vector3(parcel.x + .25, .31, parcel.z + 1.95);
}
if (parcel.intervention === "strip") {
return new THREE.Vector3(parcel.x + 2, .31, parcel.z + 1.1);
}
return null;
}
function disposeObject(object) {
object.traverse(child => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const list = Array.isArray(child.material) ? child.material : [child.material];
list.forEach(material => material.dispose());
}
});
}
function createGarden(parcel) {
const group = new THREE.Group();
const gx = parcel.x + .25;
const gz = parcel.z + 1.95;
const soil = new THREE.Mesh(
new THREE.CylinderGeometry(1.36, 1.52, .2, 12),
new THREE.MeshStandardMaterial({ color: 0x79604b, roughness: 1, flatShading: true })
);
soil.position.set(gx, .2, gz);
soil.scale.set(1.16, 1, .77);
soil.castShadow = true;
soil.receiveShadow = true;
group.add(soil);
const stoneMat = new THREE.MeshStandardMaterial({
color: 0xa6aaa0,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 10; i++) {
const angle = i / 10 * Math.PI * 2;
const stone = new THREE.Mesh(new THREE.DodecahedronGeometry(.18, 0), stoneMat);
stone.position.set(
gx + Math.cos(angle) * 1.5,
.28,
gz + Math.sin(angle) * 1.13
);
stone.rotation.set(Math.random(), Math.random(), Math.random());
stone.castShadow = true;
group.add(stone);
}
const plantMat = new THREE.MeshStandardMaterial({
color: 0x39775b,
roughness: 1,
flatShading: true
});
const plantMat2 = new THREE.MeshStandardMaterial({
color: 0x76a65f,
roughness: 1,
flatShading: true
});
[
[-.7, .25], [0, -.15], [.68, .3], [-.15, .55], [.35, -.55]
].forEach(([dx, dz], i) => {
const plant = new THREE.Mesh(
new THREE.ConeGeometry(.22, .75, 5),
i % 2 ? plantMat : plantMat2
);
plant.position.set(gx + dx, .68, gz + dz);
plant.castShadow = true;
group.add(plant);
});
const water = new THREE.Mesh(
new THREE.CircleGeometry(1.12, 24),
new THREE.MeshStandardMaterial({
color: 0x53a8b7,
transparent: true,
opacity: 0,
roughness: .28,
depthWrite: false
})
);
water.rotation.x = -Math.PI / 2;
water.position.set(gx, .325, gz);
water.scale.set(.55, .4, 1);
water.visible = false;
group.add(water);
world.add(group);
parcel.water = { mesh: water, kind: "garden" };
return group;
}
function createStrip(parcel) {
const group = new THREE.Group();
const sx = parcel.x + 2;
const sz = parcel.z + 1.1;
const base = new THREE.Mesh(
new THREE.BoxGeometry(.92, .14, 4),
new THREE.MeshStandardMaterial({ color: 0xc4a56f, roughness: 1 })
);
base.position.set(sx, .21, sz);
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const paverMat = new THREE.MeshStandardMaterial({
color: 0xd7bd88,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 8; i++) {
const paver = new THREE.Mesh(new THREE.BoxGeometry(.76, .045, .4), paverMat);
paver.position.set(sx, .31, sz - 1.7 + i * .49);
paver.rotation.y = (i % 2 ? 1 : -1) * .035;
paver.castShadow = true;
group.add(paver);
}
const water = new THREE.Mesh(
new THREE.BoxGeometry(.52, .025, 3.45),
new THREE.MeshStandardMaterial({
color: 0x5ba9b7,
transparent: true,
opacity: 0,
roughness: .28,
depthWrite: false
})
);
water.position.set(sx, .35, sz);
water.visible = false;
group.add(water);
world.add(group);
parcel.water = { mesh: water, kind: "strip" };
return group;
}
function removeIntervention(parcel) {
if (!parcel.interventionGroup) return;
world.remove(parcel.interventionGroup);
disposeObject(parcel.interventionGroup);
parcel.interventionGroup = null;
parcel.intervention = null;
parcel.water = null;
}
function setIntervention(parcel, type) {
removeIntervention(parcel);
parcel.intervention = type;
parcel.interventionGroup = type === "garden"
? createGarden(parcel)
: createStrip(parcel);
rebuildRoutes();
updateUI();
}
function buildRoute(parcel, index) {
const points = [];
const source = new THREE.Vector3(parcel.x + 1.15, 3.03, parcel.z - 1.25);
const ground = new THREE.Vector3(parcel.x + 1.15, .3, parcel.z - 1.25);
const drainZ = parcel.z < 0 ? -2.6 : 2.6;
points.push(source, ground);
const treatment = interventionPosition(parcel);
if (treatment) points.push(treatment);
points.push(
new THREE.Vector3(parcel.x, .3, drainZ),
new THREE.Vector3(parcel.x, .3, 0),
new THREE.Vector3(19.6, .3, 0)
);
const path = new THREE.CurvePath();
for (let i = 0; i < points.length - 1; i++) {
path.add(new THREE.LineCurve3(points[i], points[i + 1]));
}
const color = parcel.intervention ? 0x238f79 : 0x2997b3;
const material = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: .3,
dashSize: .5,
gapSize: .24,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
material
);
line.computeLineDistances();
line.renderOrder = 8;
routeGroup.add(line);
const markerMaterial = new THREE.MeshStandardMaterial({
color,
roughness: .45,
depthTest: false
});
const markerGeometry = new THREE.ConeGeometry(.2, .58, 5);
const markers = [];
for (let i = 0; i < 2; i++) {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.renderOrder = 9;
marker.visible = false;
routeGroup.add(marker);
markers.push(marker);
}
routes.push({
parcel,
path,
line,
markers,
offset: index * .137
});
}
function rebuildRoutes() {
routes.forEach(route => {
routeGroup.remove(route.line);
disposeObject(route.line);
route.markers.forEach(marker => {
routeGroup.remove(marker);
disposeObject(marker);
});
});
routes.length = 0;
parcels.forEach((parcel, index) => buildRoute(parcel, index));
}
rebuildRoutes();
function storageMeta(type) {
if (type === "garden") return { bars: 4, label: "More relative storage" };
return { bars: 2, label: "Some relative storage" };
}
function updateUI() {
const treated = parcels.filter(parcel => parcel.intervention);
document.getElementById("planCount").textContent =
`${treated.length} of ${parcels.length} lots treated`;
const total = treated.reduce((sum, parcel) => sum + storageMeta(parcel.intervention).bars, 0);
const max = parcels.length * 4;
const fill = Math.min(100, total / max * 100);
document.getElementById("storageFill").style.width = `${fill}%`;
document.getElementById("storageLabel").textContent = total === 0
? "Empty plan"
: total >= 12
? "High relative storage"
: total >= 6
? "Moderate relative storage"
: "Low relative storage";
const list = document.getElementById("planList");
if (!treated.length) {
list.innerHTML = `
<div class="empty-plan">
Your block is untreated.<br>
Add a rain garden or permeable strip to compare relative storage.
</div>`;
} else {
list.innerHTML = treated.map(parcel => {
const meta = storageMeta(parcel.intervention);
const bars = Array.from({ length: 4 }, (_, i) =>
`<i class="${i < meta.bars ? "on" : ""}"></i>`).join("");
const name = parcel.intervention === "garden" ? "Rain garden" : "Permeable strip";
return `
<div class="plan-row">
<span class="swatch ${parcel.intervention === "strip" ? "strip" : ""}"></span>
<span>
<strong>${name}</strong>
<small>${parcel.id} · ${meta.label}</small>
</span>
<span class="mini-bars" aria-label="${meta.label}">${bars}</span>
<button class="remove-button" type="button" data-remove="${parcel.id}"
aria-label="Remove treatment from ${parcel.id}">×</button>
</div>`;
}).join("");
}
document.getElementById("clearPlan").disabled = treated.length === 0;
updateParcelHighlights();
}
function updateParcelHighlights() {
parcels.forEach(parcel => {
const hovered = state.hoverParcel === parcel.id;
parcel.tile.material.color.set(
state.tool ? (hovered ? 0x5fc5a7 : 0x69bca5) : parcel.baseColor
);
parcel.tile.material.opacity = state.tool
? (hovered ? .38 : .18)
: .82;
});
}
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2600);
}
function setTool(tool) {
state.tool = state.tool === tool ? null : tool;
const gardenActive = state.tool === "garden";
const stripActive = state.tool === "strip";
document.getElementById("gardenTool").classList.toggle("active", gardenActive);
document.getElementById("stripTool").classList.toggle("active", stripActive);
document.getElementById("gardenTool").setAttribute("aria-pressed", String(gardenActive));
document.getElementById("stripTool").setAttribute("aria-pressed", String(stripActive));
renderer.domElement.classList.toggle("build-mode", Boolean(state.tool));
document.getElementById("modeNote").textContent = state.tool
? `Choose a highlighted lot to add a ${state.tool === "garden" ? "rain garden" : "permeable strip"}.`
: "Pick a treatment, then select a highlighted neighborhood lot.";
updateParcelHighlights();
}
document.getElementById("gardenTool").addEventListener("click", () => setTool("garden"));
document.getElementById("stripTool").addEventListener("click", () => setTool("strip"));
function stormWord(value) {
if (value < 35) return "Light";
if (value < 72) return "Steady";
return "Strong";
}
const rainSlider = document.getElementById("rainSlider");
const rainLabel = document.getElementById("rainLabel");
const rainToggle = document.getElementById("rainToggle");
rainSlider.addEventListener("input", () => {
state.rain.intensity = Number(rainSlider.value);
const word = stormWord(state.rain.intensity);
rainLabel.textContent = word;
rainSlider.setAttribute("aria-valuetext", `${word} relative strength`);
});
function updateRainButton() {
rainToggle.textContent = state.rain.running ? "Stop rain" : "Start rain";
rainToggle.classList.toggle("running", state.rain.running);
}
rainToggle.addEventListener("click", () => {
state.rain.running = !state.rain.running;
updateRainButton();
showToast(state.rain.running ? "Sketch rain started." : "Rain paused.");
});
document.getElementById("resetRain").addEventListener("click", () => {
state.rain.running = false;
state.rain.elapsed = 0;
updateRainButton();
showToast("Rain reset. Your treatment plan was kept.");
});
document.getElementById("planList").addEventListener("click", event => {
const button = event.target.closest("[data-remove]");
if (!button) return;
const parcel = parcels.find(item => item.id === button.dataset.remove);
if (!parcel) return;
removeIntervention(parcel);
rebuildRoutes();
updateUI();
showToast(`Treatment removed from lot ${parcel.id}.`);
});
document.getElementById("clearPlan").addEventListener("click", () => {
parcels.forEach(removeIntervention);
rebuildRoutes();
updateUI();
showToast("All treatments cleared.");
});
// Pointer interaction and direct camera controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const drag = {
active: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
pan: false
};
function pointerToNdc(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function parcelAt(event) {
pointerToNdc(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(lotPickers, false);
if (!hits.length) return null;
return parcels.find(parcel => parcel.id === hits[0].object.userData.parcelId) || null;
}
function updateHover(event) {
if (drag.active) return;
const parcel = parcelAt(event);
state.hoverParcel = parcel?.id || null;
updateParcelHighlights();
if (!parcel) {
tooltip.style.display = "none";
return;
}
const treatment = parcel.intervention
? parcel.intervention === "garden"
? "Rain garden"
: "Permeable strip"
: "Untreated lot";
tooltip.textContent = `${parcel.id} · ${treatment}`;
tooltip.style.display = "block";
tooltip.style.left = `${Math.min(event.clientX + 13, window.innerWidth - 200)}px`;
tooltip.style.top = `${Math.min(event.clientY + 14, window.innerHeight - 55)}px`;
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0 && event.button !== 2) return;
drag.active = true;
drag.moved = false;
drag.pan = event.button === 2 || event.shiftKey;
drag.startX = drag.lastX = event.clientX;
drag.startY = drag.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!drag.active) {
updateHover(event);
return;
}
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
const totalDistance = Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY);
if (totalDistance > 5) drag.moved = true;
if (drag.pan) {
const forward = camera.getWorldDirection(new THREE.Vector3());
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, up).normalize();
const panUp = new THREE.Vector3().crossVectors(right, forward).normalize();
const panScale = .025 / orbit.zoom;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(panUp, dy * panScale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -10, 10);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -8, 8);
} else {
orbit.theta -= dx * .006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * .005, .43, 1.22);
}
drag.lastX = event.clientX;
drag.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
if (!drag.active) return;
const wasClick = !drag.moved && event.button === 0;
drag.active = false;
renderer.domElement.releasePointerCapture(event.pointerId);
if (wasClick) {
const parcel = parcelAt(event);
if (parcel && state.tool) {
const previous = parcel.intervention;
setIntervention(parcel, state.tool);
const name = state.tool === "garden" ? "Rain garden" : "Permeable strip";
showToast(previous
? `${name} replaced the treatment on lot ${parcel.id}.`
: `${name} added to lot ${parcel.id}.`);
} else if (parcel?.intervention) {
const meta = storageMeta(parcel.intervention);
showToast(`${parcel.id}: ${meta.label.toLowerCase()}.`);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
drag.active = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!drag.active) tooltip.style.display = "none";
});
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * .001),
.68,
2.25
);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "Escape") {
state.tool = null;
document.getElementById("gardenTool").classList.remove("active");
document.getElementById("stripTool").classList.remove("active");
renderer.domElement.classList.remove("build-mode");
document.getElementById("modeNote").textContent =
"Pick a treatment, then select a highlighted neighborhood lot.";
updateParcelHighlights();
}
});
const dryRoad = new THREE.Color(0x596568);
const wetRoad = new THREE.Color(0x46595d);
const dryCloud = new THREE.Color(0xf4f6ef);
const wetCloud = new THREE.Color(0xafbbb6);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), .05);
const rain = state.rain;
if (rain.running) {
rain.elapsed += delta;
const positions = rainGeometry.attributes.position.array;
const fallSpeed = 7 + rain.intensity * .075;
for (let i = 0; i < rainCount; i++) {
positions[i * 3 + 1] -= fallSpeed * delta;
positions[i * 3] += delta * .45;
if (positions[i * 3 + 1] < .1) {
positions[i * 3 + 1] = 17 + Math.random() * 2;
positions[i * 3] = (Math.random() - .5) * 43;
positions[i * 3 + 2] = (Math.random() - .5) * 29;
}
}
rainGeometry.attributes.position.needsUpdate = true;
}
rainPoints.visible = rain.running;
rainMaterial.opacity = .38 + rain.intensity / 100 * .42;
const wetLevel = rain.running ? rain.intensity / 100 : 0;
materials.road.color.copy(dryRoad).lerp(wetRoad, wetLevel * .62);
cloudMaterial.color.copy(dryCloud).lerp(wetCloud, wetLevel * .7);
cloud.position.x = -10 + Math.sin(rain.elapsed * .12) * 1.4;
parcels.forEach(parcel => {
if (!parcel.water) return;
const { mesh, kind } = parcel.water;
const level = rain.running ? rain.intensity / 100 : 0;
mesh.visible = level > .04;
mesh.material.opacity = level * .62;
if (kind === "garden") {
mesh.scale.set(.45 + level * .62, .3 + level * .55, 1);
}
});
routes.forEach((route, routeIndex) => {
const active = rain.running;
route.line.material.opacity = active ? .88 : .3;
const attenuation = route.parcel.intervention ? .66 : 1;
const markerScale = (.72 + rain.intensity / 100 * .48) * attenuation;
route.markers.forEach((marker, markerIndex) => {
marker.visible = active;
if (!active) return;
const t = (rain.elapsed * (.105 + rain.intensity * .00035) + route.offset + markerIndex * .5) % 1;
const point = route.path.getPoint(t);
const tangent = route.path.getTangent(t).normalize();
marker.position.copy(point);
marker.quaternion.setFromUnitVectors(up, tangent);
marker.scale.setScalar(markerScale);
});
});
renderer.render(scene, camera);
}
updateUI();
animate();
</script>
</body>
</html>
```