Prompt specification
Build or customize the Three.js 3D scene "Schoolyard runoff planning table" 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: Schoolyard runoff planning table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/schoolyard-runoff-planning-table-x1236
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing rainfall collection. Create a small schoolyard with replaceable paving and planted strips; a rainfall slider changes qualitative runoff, with clearly labeled schematic flow paths and resettable storage levels. Voxel style.
Working Three.js Starter (schoolyard-runoff-planning-table-x1236):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Rainfall Collection Schoolyard</title>
<style>
:root {
--ink: #17333a;
--panel: rgba(250, 249, 239, 0.96);
--line: #b8c8c5;
--blue: #167ea4;
--cyan: #32c5ed;
--green: #418a55;
--yellow: #efc75e;
--muted: #60777b;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcecef;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.topbar {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
min-height: 68px;
padding: 12px 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
pointer-events: none;
background: linear-gradient(rgba(220, 236, 239, 0.96), rgba(220, 236, 239, 0));
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-icon {
width: 38px;
height: 38px;
display: grid;
place-items: center;
background: var(--ink);
color: #f8f5e8;
font-size: 24px;
box-shadow: 4px 4px 0 rgba(23, 51, 58, 0.15);
}
h1 {
margin: 0;
font-size: clamp(16px, 2vw, 23px);
line-height: 1.05;
letter-spacing: -0.02em;
}
.subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 12px;
}
.model-badge {
padding: 7px 10px;
border: 1px solid rgba(23, 51, 58, 0.2);
background: rgba(250, 249, 239, 0.78);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 20;
top: 82px;
left: 16px;
width: 310px;
max-height: calc(100vh - 100px);
overflow-y: auto;
padding: 15px;
background: var(--panel);
border: 1px solid rgba(23, 51, 58, 0.16);
box-shadow: 7px 7px 0 rgba(23, 51, 58, 0.12);
backdrop-filter: blur(8px);
scrollbar-width: thin;
}
.section {
padding: 0 0 14px;
margin-bottom: 14px;
border-bottom: 1px solid var(--line);
}
.section:last-child {
padding-bottom: 0;
margin-bottom: 0;
border-bottom: 0;
}
.section-head,
.row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
h2 {
margin: 0;
font-size: 13px;
text-transform: uppercase;
letter-spacing: 0.075em;
}
.hint {
color: var(--muted);
font-size: 11px;
}
output {
color: var(--blue);
font-size: 13px;
font-weight: 800;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 24px;
margin: 10px 0 0;
accent-color: var(--blue);
cursor: pointer;
}
.scale {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
}
.option-grid {
display: grid;
gap: 6px;
margin-top: 10px;
}
.option {
display: grid;
grid-template-columns: 22px 1fr auto;
align-items: center;
gap: 8px;
width: 100%;
padding: 8px;
color: var(--ink);
text-align: left;
background: #fffdf5;
border: 1px solid var(--line);
border-radius: 0;
cursor: pointer;
}
.option:hover,
.option.active {
border-color: var(--blue);
box-shadow: inset 3px 0 0 var(--blue);
}
.option strong {
display: block;
font-size: 12px;
}
.option small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.option .tag {
color: var(--muted);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
}
.swatch {
width: 20px;
height: 20px;
border: 1px solid rgba(23, 51, 58, 0.22);
box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.08);
}
.swatch.asphalt { background: #53616a; }
.swatch.concrete { background: #aeb9b7; }
.swatch.permeable { background: #c8af7e; }
.swatch.grass { background: #74a94e; }
.swatch.shrubs { background: #39794b; }
.swatch.trees { background: #285d43; }
.mix {
margin-top: 8px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 11px;
}
.readout {
min-height: 56px;
padding: 9px;
background: #edf2ec;
border-left: 4px solid #92a5a2;
}
.readout span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.readout strong {
display: block;
margin-top: 4px;
font-size: 16px;
}
.readout[data-level="low"] { border-left-color: #7ea58a; }
.readout[data-level="medium"] { border-left-color: var(--yellow); }
.readout[data-level="high"] { border-left-color: #df7d62; }
.storage-track {
height: 15px;
margin-top: 10px;
overflow: hidden;
background: #dbe5e2;
border: 1px solid #a9bcb9;
}
#storageBar {
width: 0;
height: 100%;
background: repeating-linear-gradient(
90deg,
#2aaed6 0,
#2aaed6 12px,
#58c7e7 12px,
#58c7e7 16px
);
transition: width 0.15s linear;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 10px;
}
.button {
padding: 9px 8px;
color: var(--ink);
background: #fffdf5;
border: 1px solid var(--line);
cursor: pointer;
font-size: 11px;
font-weight: 800;
}
.button.primary {
color: white;
background: var(--ink);
border-color: var(--ink);
}
.button:hover { filter: brightness(0.96); }
.check {
display: flex;
align-items: center;
gap: 8px;
margin-top: 10px;
font-size: 12px;
}
.check input { accent-color: var(--ink); }
#labels {
position: fixed;
z-index: 5;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 7px;
min-width: 112px;
padding: 6px 8px;
color: var(--ink);
background: rgba(255, 253, 245, 0.93);
border: 1px solid rgba(23, 51, 58, 0.2);
box-shadow: 3px 3px 0 rgba(23, 51, 58, 0.12);
white-space: nowrap;
will-change: transform;
}
.scene-label b {
display: block;
font-size: 9px;
letter-spacing: 0.075em;
}
.scene-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.label-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(50, 197, 237, 0.17);
}
.label-dot.green {
background: var(--green);
box-shadow: 0 0 0 3px rgba(65, 138, 85, 0.17);
}
.label-dot.dark {
background: #356b7b;
box-shadow: 0 0 0 3px rgba(53, 107, 123, 0.17);
}
.legend {
position: fixed;
z-index: 10;
right: 16px;
bottom: 16px;
padding: 11px 13px;
background: rgba(250, 249, 239, 0.92);
border: 1px solid rgba(23, 51, 58, 0.16);
box-shadow: 5px 5px 0 rgba(23, 51, 58, 0.10);
font-size: 10px;
}
.legend-title {
margin-bottom: 7px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 7px;
margin-top: 5px;
}
.legend-mark {
width: 17px;
height: 5px;
background: var(--cyan);
}
.legend-mark.green { background: var(--green); }
.legend-mark.dashed {
height: 0;
background: transparent;
border-top: 3px dotted var(--cyan);
}
.instructions {
position: fixed;
z-index: 10;
left: 50%;
bottom: 16px;
transform: translateX(-50%);
padding: 7px 10px;
color: var(--ink);
background: rgba(250, 249, 239, 0.78);
border: 1px solid rgba(23, 51, 58, 0.13);
font-size: 10px;
font-weight: 700;
white-space: nowrap;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #dcecef;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.topbar {
min-height: 58px;
padding: 9px 12px;
}
.brand-icon { width: 32px; height: 32px; }
.subtitle, .model-badge { display: none; }
.panel {
top: auto;
bottom: 10px;
left: 10px;
width: calc(100% - 20px);
max-height: 43vh;
padding: 12px;
}
.legend, .instructions { display: none; }
.scene-label {
min-width: 95px;
padding: 5px 6px;
}
.scene-label small { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel schoolyard rainfall collection model"></canvas>
<div id="labels" aria-hidden="true">
<div class="scene-label" data-anchor="rain">
<span class="label-dot"></span>
<span><b>RAINFALL ↓</b><small>Vertical water input</small></span>
</div>
<div class="scene-label" data-anchor="roof">
<span class="label-dot"></span>
<span><b>ROOF RUNOFF →</b><small>Roof to gutter</small></span>
</div>
<div class="scene-label" data-anchor="paving">
<span class="label-dot"></span>
<span><b>PAVING RUNOFF →</b><small>Surface flow path</small></span>
</div>
<div class="scene-label" data-anchor="infiltration">
<span class="label-dot green"></span>
<span><b>INFILTRATION ↓</b><small>Into planted soil</small></span>
</div>
<div class="scene-label" data-anchor="drain">
<span class="label-dot"></span>
<span><b>COLLECTION DRAIN</b><small>Runoff collection point</small></span>
</div>
<div class="scene-label" data-anchor="storage">
<span class="label-dot dark"></span>
<span><b>STORAGE TANK</b><small>Resettable water level</small></span>
</div>
</div>
<header class="topbar">
<div class="brand">
<div class="brand-icon">▥</div>
<div>
<h1>Rainfall Collection Schoolyard</h1>
<div class="subtitle">Replace surfaces, compare pathways, and observe qualitative storage</div>
</div>
</div>
<div class="model-badge">Qualitative voxel model</div>
</header>
<aside class="panel">
<section class="section">
<div class="row">
<h2>Rainfall</h2>
<output id="rainValue">58% · Steady</output>
</div>
<input id="rainfall" type="range" min="0" max="100" value="58" aria-label="Rainfall intensity" />
<div class="scale">
<span>Dry</span><span>Light</span><span>Steady</span><span>Heavy</span>
</div>
<div class="readouts">
<div class="readout" id="runoffBox">
<span>Runoff tendency</span>
<strong id="runoffStatus">Moderate</strong>
</div>
<div class="readout" id="infiltrationBox">
<span>Infiltration</span>
<strong id="infiltrationStatus">Moderate</strong>
</div>
</div>
</section>
<section class="section">
<div class="section-head">
<h2>Replace paving</h2>
<span class="hint">Click any tile</span>
</div>
<div class="option-grid" id="pavingOptions">
<button class="option" data-paving="asphalt" type="button">
<span class="swatch asphalt"></span>
<span><strong>Asphalt</strong><small>Low infiltration</small></span>
<span class="tag">High runoff</span>
</button>
<button class="option" data-paving="concrete" type="button">
<span class="swatch concrete"></span>
<span><strong>Concrete</strong><small>Some absorption</small></span>
<span class="tag">Medium</span>
</button>
<button class="option" data-paving="permeable" type="button">
<span class="swatch permeable"></span>
<span><strong>Permeable pavers</strong><small>Water enters joints</small></span>
<span class="tag">Low runoff</span>
</button>
</div>
<div class="mix" id="pavingMix"></div>
</section>
<section class="section">
<div class="section-head">
<h2>Replace planted strips</h2>
<span class="hint">Click any strip</span>
</div>
<div class="option-grid" id="plantOptions">
<button class="option" data-plant="grass" type="button">
<span class="swatch grass"></span>
<span><strong>Grass</strong><small>Simple ground cover</small></span>
<span class="tag">Low uptake</span>
</button>
<button class="option" data-plant="shrubs" type="button">
<span class="swatch shrubs"></span>
<span><strong>Shrubs</strong><small>Dense low planting</small></span>
<span class="tag">Medium</span>
</button>
<button class="option" data-plant="trees" type="button">
<span class="swatch trees"></span>
<span><strong>Trees + shrubs</strong><small>Deep-rooted planting</small></span>
<span class="tag">High uptake</span>
</button>
</div>
<div class="mix" id="plantMix"></div>
</section>
<section class="section">
<div class="section-head">
<h2>Collected storage</h2>
<strong id="storageStatus">0%</strong>
</div>
<div class="storage-track"><div id="storageBar"></div></div>
<div class="hint" style="margin-top:6px">
The tank fills while runoff reaches the drain. Values are illustrative, not calibrated.
</div>
<div class="button-row">
<button id="resetStorage" class="button primary" type="button">Reset tank</button>
<button id="resetYard" class="button" type="button">Reset yard</button>
</div>
<label class="check">
<input id="toggleLabels" type="checkbox" checked />
Show schematic labels
</label>
<div class="button-row">
<button id="resetCamera" class="button" type="button">Reset camera</button>
</div>
</section>
</aside>
<div class="legend">
<div class="legend-title">Schematic flow key</div>
<div class="legend-row"><span class="legend-mark"></span> Runoff / collected water</div>
<div class="legend-row"><span class="legend-mark green"></span> Infiltration</div>
<div class="legend-row"><span class="legend-mark dashed"></span> Direction of flow</div>
</div>
<div class="instructions">Drag to orbit · Wheel to zoom · Click paving or planting to replace</div>
<div id="loading">Building voxel schoolyard…</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcecef);
scene.fog = new THREE.Fog(0xdcecef, 28, 58);
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
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.05;
const world = new THREE.Group();
scene.add(world);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.2, 0.45, 0);
const cameraState = {
azimuth: 0.68,
elevation: 0.72,
distance: 27,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xeafaff, 0x71816a, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d1, 3.0);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
ground: material(0x9dbca5),
base: material(0x607b69),
baseEdge: material(0x4c6356),
foundation: material(0xc5c6b8),
school: material(0xf0dfb8),
roof: material(0x526772),
trim: material(0xf7f1df),
window: material(0x4d9bb4, { roughness: 0.3 }),
door: material(0xbf674f),
soil: material(0x705840),
border: material(0x8b765a),
grass: material(0x73a94d),
shrub: material(0x3d7d49),
tree: material(0x285f45),
trunk: material(0x79583d),
yellow: material(0xefc75e),
grate: material(0x374a4d),
frame: material(0x2f5159),
bench: material(0x9a6744)
};
const pavingMaterials = {
asphalt: material(0x53616a),
concrete: material(0xaeb9b7),
permeable: material(0xc8af7e)
};
const pavingProperties = {
asphalt: { runoff: 1.0, infiltration: 0.04 },
concrete: { runoff: 0.78, infiltration: 0.11 },
permeable: { runoff: 0.48, infiltration: 0.30 }
};
const plantProperties = {
grass: 0.46,
shrubs: 0.73,
trees: 1.0
};
const pavingOrder = ["asphalt", "concrete", "permeable"];
const plantOrder = ["grass", "shrubs", "trees"];
function makeBox(parent, w, h, d, mat, x = 0, y = 0, z = 0, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
// Diorama base and surrounding ground.
makeBox(scene, 70, 0.2, 70, materials.ground, 0, -0.78, 0, false, true);
makeBox(world, 17.8, 0.65, 12.2, materials.base, 0, -0.36, 0);
makeBox(world, 17.9, 0.13, 12.3, materials.baseEdge, 0, -0.69, 0);
// Modular paved courtyard.
makeBox(world, 10.15, 0.14, 6.15, materials.foundation, -0.48, 0.03, 0.53);
const pavingTiles = [];
const pavingState = [];
const pickingTargets = [];
const cols = 8;
const rows = 5;
const stepX = 1.21;
const stepZ = 1.18;
const startX = -5.40;
const startZ = -2.40;
function defaultPaving(index) {
if (index % 9 === 0) return "permeable";
if (index % 5 === 0) return "concrete";
return "asphalt";
}
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const index = row * cols + col;
const type = defaultPaving(index);
const x = startX + col * stepX + 0.575;
const z = startZ + row * stepZ + 0.545;
const tile = makeBox(
world,
1.15,
0.12,
1.12,
pavingMaterials[type],
x,
0.15,
z
);
tile.userData = { kind: "paving", index };
pavingTiles.push(tile);
pavingState.push(type);
pickingTargets.push(tile);
}
}
// Simple voxel school building at the rear.
const school = new THREE.Group();
school.position.set(0.2, 0, -5.0);
world.add(school);
makeBox(school, 8.2, 2.8, 1.4, materials.school, 0, 1.4, 0);
makeBox(school, 8.55, 0.25, 1.7, materials.roof, 0, 2.91, 0);
makeBox(school, 8.35, 0.18, 0.10, materials.trim, 0, 0.36, 0.75);
makeBox(school, 8.35, 0.16, 0.10, materials.trim, 0, 2.60, 0.75);
for (let i = 0; i < 6; i++) {
makeBox(
school,
0.76,
0.72,
0.08,
materials.window,
-3.05 + i * 1.22,
1.70,
0.74
);
makeBox(
school,
0.84,
0.08,
0.12,
materials.trim,
-3.05 + i * 1.22,
1.29,
0.77
);
}
makeBox(school, 0.88, 1.72, 0.10, materials.door, 1.70, 0.86, 0.76);
makeBox(school, 0.12, 0.12, 0.14, materials.window, 1.45, 0.91, 0.83);
// Gutter and downspout at the right end of the roof.
makeBox(world, 8.15, 0.13, 0.13, materials.grate, 0.2, 2.76, -4.12);
makeBox(world, 0.14, 2.46, 0.14, materials.grate, 3.7, 1.42, -4.08);
// Court markings.
const courtY = 0.225;
makeBox(world, 4.7, 0.025, 0.065, materials.yellow, -1.65, courtY, -0.75);
makeBox(world, 4.7, 0.025, 0.065, materials.yellow, -1.65, courtY, 2.40);
makeBox(world, 0.065, 0.025, 3.15, materials.yellow, -4.0, courtY, 0.825);
makeBox(world, 0.065, 0.025, 3.15, materials.yellow, 0.70, courtY, 0.825);
// Bench.
makeBox(world, 1.7, 0.13, 0.42, materials.bench, -3.45, 0.48, 4.0);
makeBox(world, 1.7, 0.45, 0.10, materials.bench, -3.45, 0.73, 4.18);
makeBox(world, 0.13, 0.45, 0.36, materials.grate, -4.10, 0.23, 4.0);
makeBox(world, 0.13, 0.45, 0.36, materials.grate, -2.80, 0.23, 4.0);
// Planted strips, divided into replaceable segments.
const plantSegments = [];
const plantState = [];
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6D2B79F5;
let t = value;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function addPlantSegment(x, z, width, depth, index) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
const base = makeBox(group, width, 0.16, depth, materials.soil, 0, 0.08, 0);
base.userData = { kind: "plant", index };
pickingTargets.push(base);
makeBox(group, width, 0.16, 0.08, materials.border, 0, 0.15, -depth / 2);
makeBox(group, width, 0.16, 0.08, materials.border, 0, 0.15, depth / 2);
makeBox(group, 0.08, 0.16, depth, materials.border, -width / 2, 0.15, 0);
makeBox(group, 0.08, 0.16, depth, materials.border, width / 2, 0.15, 0);
const type = index % 5 === 0 ? "trees" : index % 2 === 0 ? "shrubs" : "grass";
const vegetation = new THREE.Group();
group.add(vegetation);
const segment = { group, base, vegetation, type, x, z, width, depth, index };
plantSegments.push(segment);
plantState.push(type);
buildVegetation(segment);
}
for (let i = 0; i < 7; i++) {
addPlantSegment(-6.28, -2.30 + i * 0.96, 1.30, 0.86, i);
}
for (let i = 0; i < 7; i++) {
addPlantSegment(-4.48 + i * 1.43, -3.62, 1.31, 1.02, i + 7);
}
function buildVegetation(segment) {
while (segment.vegetation.children.length) {
segment.vegetation.remove(segment.vegetation.children[0]);
}
const random = seededRandom(segment.index * 97 + plantOrder.indexOf(segment.type) * 811);
if (segment.type === "grass") {
for (let i = 0; i < 15; i++) {
const height = 0.18 + random() * 0.23;
makeBox(
segment.vegetation,
0.07,
height,
0.07,
materials.grass,
(random() - 0.5) * segment.width * 0.78,
0.19 + height / 2,
(random() - 0.5) * segment.depth * 0.72,
true,
false
);
}
} else if (segment.type === "shrubs") {
for (let cluster = 0; cluster < 4; cluster++) {
const cx = (random() - 0.5) * segment.width * 0.66;
const cz = (random() - 0.5) * segment.depth * 0.58;
const size = 0.30 + random() * 0.18;
makeBox(segment.vegetation, size, size * 0.85, size, materials.shrub, cx, 0.28 + size * 0.4, cz);
makeBox(
segment.vegetation,
size * 0.72,
size * 0.70,
size * 0.72,
materials.grass,
cx + size * 0.20,
0.38 + size * 0.65,
cz - size * 0.12
);
}
} else {
const treeX = (random() - 0.5) * segment.width * 0.32;
const treeZ = (random() - 0.5) * segment.depth * 0.22;
makeBox(segment.vegetation, 0.18, 0.82, 0.18, materials.trunk, treeX, 0.58, treeZ);
makeBox(segment.vegetation, 0.72, 0.60, 0.72, materials.tree, treeX, 1.18, treeZ);
makeBox(segment.vegetation, 0.52, 0.42, 0.52, materials.shrub, treeX + 0.30, 0.93, treeZ + 0.20);
makeBox(segment.vegetation, 0.42, 0.34, 0.42, materials.grass, treeX - 0.32, 0.78, treeZ + 0.18);
}
}
// Collection drain.
makeBox(world, 0.92, 0.11, 0.92, materials.grate, 4.65, 0.26, 2.70);
for (let i = 0; i < 5; i++) {
makeBox(world, 0.70, 0.045, 0.065, materials.frame, 4.65, 0.335, 2.42 + i * 0.14, false, false);
}
// Voxel storage tank.
const tank = new THREE.Group();
tank.position.set(6.18, 0, 1.66);
world.add(tank);
makeBox(tank, 2.30, 0.18, 2.30, materials.frame, 0, 0.10, 0);
const glassMaterial = material(0x5ac5df, {
transparent: true,
opacity: 0.20,
roughness: 0.25,
depthWrite: false
});
for (const x of [-1.02, 1.02]) {
for (const z of [-1.02, 1.02]) {
makeBox(tank, 0.12, 2.08, 0.12, materials.frame, x, 1.20, z);
}
}
makeBox(tank, 2.10, 0.10, 0.10, materials.frame, 0, 2.22, -1.02);
makeBox(tank, 2.10, 0.10, 0.10, materials.frame, 0, 2.22, 1.02);
makeBox(tank, 0.10, 0.10, 2.10, materials.frame, -1.02, 2.22, 0);
makeBox(tank, 0.10, 0.10, 2.10, materials.frame, 1.02, 2.22, 0);
makeBox(tank, 1.96, 1.95, 0.035, glassMaterial, 0, 1.18, -1.02, false, false);
makeBox(tank, 1.96, 1.95, 0.025, glassMaterial, 0, 1.18, 1.02, false, false);
makeBox(tank, 0.025, 1.95, 1.96, glassMaterial, -1.02, 1.18, 0, false, false);
makeBox(tank, 0.025, 1.95, 1.96, glassMaterial, 1.02, 1.18, 0, false, false);
const waterMaterial = material(0x249fc8, {
transparent: true,
opacity: 0.82,
roughness: 0.25,
depthWrite: false
});
const waterFill = makeBox(tank, 1.76, 0.03, 1.76, waterMaterial, 0, 0.27, 0, false, false);
// Flow paths are made from small cubes so they retain the voxel style.
const flowRoot = new THREE.Group();
world.add(flowRoot);
const flowPaths = [];
function addChevron(path, t) {
const point = pointOnPath(path, t);
const ahead = pointOnPath(path, Math.min(1, t + 0.015));
const behind = pointOnPath(path, Math.max(0, t - 0.015));
const direction = ahead.clone().sub(behind).normalize();
const arrow = new THREE.Group();
flowRoot.add(arrow);
makeBox(arrow, 0.09, 0.05, 0.38, path.material, 0, 0, -0.09, false, false);
const wingA = makeBox(arrow, 0.08, 0.05, 0.34, path.material, 0.11, 0, 0.12, false, false);
const wingB = makeBox(arrow, 0.08, 0.05, 0.34, path.material, -0.11, 0, 0.12, false, false);
wingA.rotation.y = -Math.PI / 4;
wingB.rotation.y = Math.PI / 4;
arrow.position.copy(point);
arrow.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), direction);
}
function createFlowPath(name, coordinates, color, pulseCount = 5) {
const points = coordinates.map((p) => new THREE.Vector3(...p));
const path = {
name,
points,
segments: [],
total: 0,
material: new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.4,
depthWrite: false
}),
pulseMaterial: new THREE.MeshBasicMaterial({
color: 0xb9f3ff,
transparent: true,
opacity: 0.9,
depthWrite: false
}),
pulses: []
};
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
path.segments.push({ start: points[i], end: points[i + 1], length });
path.total += length;
const count = Math.max(1, Math.ceil(length / 0.34));
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const position = points[i].clone().lerp(points[i + 1], t);
const marker = new THREE.Mesh(unitBox, path.material);
marker.scale.set(0.115, 0.035, 0.115);
marker.position.copy(position);
flowRoot.add(marker);
}
}
for (let i = 0; i < pulseCount; i++) {
const pulse = new THREE.Mesh(unitBox, path.pulseMaterial);
pulse.scale.set(0.17, 0.10, 0.17);
flowRoot.add(pulse);
path.pulses.push({ mesh: pulse, offset: i / pulseCount });
}
addChevron(path, 0.28);
addChevron(path, 0.66);
flowPaths.push(path);
return path;
}
function pointOnPath(path, normalized) {
let distance = THREE.MathUtils.clamp(normalized, 0, 1) * path.total;
for (const segment of path.segments) {
if (distance <= segment.length) {
return segment.start.clone().lerp(
segment.end,
segment.length === 0 ? 0 : distance / segment.length
);
}
distance -= segment.length;
}
return path.points[path.points.length - 1].clone();
}
const roofPath = createFlowPath("roof", [
[3.70, 2.78, -4.08],
[3.70, 0.30, -3.78],
[3.70, 0.28, -2.40],
[4.00, 0.28, -0.70],
[4.65, 0.28, 1.25],
[4.65, 0.34, 2.70]
], 0x2dbbe5, 6);
const pavingPath = createFlowPath("paving", [
[-4.30, 0.28, -1.40],
[-2.60, 0.28, -0.65],
[-0.40, 0.28, -0.05],
[1.60, 0.28, 0.55],
[3.45, 0.28, 1.55],
[4.65, 0.34, 2.70]
], 0x2dbbe5, 6);
const collectionPath = createFlowPath("collection", [
[4.65, 0.36, 2.70],
[5.20, 0.36, 2.70],
[6.15, 0.36, 2.70],
[6.15, 0.80, 2.64],
[6.15, 1.35, 2.64]
], 0x2dbbe5, 4);
const infiltrationPaths = [
createFlowPath("infiltration-left", [
[-5.15, 0.29, 1.80],
[-5.72, 0.29, 1.80],
[-6.28, 0.29, 1.80],
[-6.28, -0.22, 1.80]
], 0x4daa63, 4),
createFlowPath("infiltration-back", [
[-1.00, 0.29, -2.75],
[-1.00, 0.29, -3.62],
[-1.00, -0.22, -3.62]
], 0x4daa63, 4),
createFlowPath("infiltration-left-2", [
[-5.30, 0.29, -0.80],
[-5.80, 0.29, -0.80],
[-6.28, 0.29, -0.80],
[-6.28, -0.22, -0.80]
], 0x4daa63, 4)
];
// Rain is rendered as a field of small falling voxels.
const rainMaterial = new THREE.MeshBasicMaterial({
color: 0x4cbce8,
transparent: true,
opacity: 0.62,
depthWrite: false
});
const rain = new THREE.InstancedMesh(unitBox, rainMaterial, 110);
rain.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
rain.frustumCulled = false;
world.add(rain);
const rainSeeds = Array.from({ length: 110 }, (_, i) => ({
x: -7.4 + ((i * 1.731) % 14.8),
z: -5.8 + ((i * 0.913) % 11.6),
phase: (i * 0.618033) % 1,
speed: 5.2 + ((i * 0.37) % 3.2)
}));
// Model state.
const rainfallInput = document.querySelector("#rainfall");
const rainValue = document.querySelector("#rainValue");
const runoffStatus = document.querySelector("#runoffStatus");
const runoffBox = document.querySelector("#runoffBox");
const infiltrationStatus = document.querySelector("#infiltrationStatus");
const infiltrationBox = document.querySelector("#infiltrationBox");
const storageStatus = document.querySelector("#storageStatus");
const storageBar = document.querySelector("#storageBar");
const pavingMix = document.querySelector("#pavingMix");
const plantMix = document.querySelector("#plantMix");
let storageLevel = 0;
let displayedStorage = 0;
let runoffIntensity = 0;
let infiltrationIntensity = 0;
let labelsEnabled = true;
function average(values) {
return values.reduce((sum, value) => sum + value, 0) / values.length;
}
function qualitativeLevel(value) {
if (value < 0.30) return { word: "Low", level: "low" };
if (value < 0.62) return { word: "Moderate", level: "medium" };
return { word: "High", level: "high" };
}
function updateMixLabels() {
const pavingCounts = { asphalt: 0, concrete: 0, permeable: 0 };
pavingState.forEach((type) => pavingCounts[type]++);
pavingMix.textContent =
`Current mix: ${pavingCounts.asphalt} asphalt · ${pavingCounts.concrete} concrete · ` +
`${pavingCounts.permeable} permeable`;
const plantCounts = { grass: 0, shrubs: 0, trees: 0 };
plantState.forEach((type) => plantCounts[type]++);
plantMix.textContent =
`Current mix: ${plantCounts.grass} grass · ${plantCounts.shrubs} shrub · ` +
`${plantCounts.trees} tree segments`;
document.querySelectorAll("[data-paving]").forEach((button) => {
button.classList.toggle(
"active",
pavingState.every((type) => type === button.dataset.paving)
);
});
document.querySelectorAll("[data-plant]").forEach((button) => {
button.classList.toggle(
"active",
plantState.every((type) => type === button.dataset.plant)
);
});
}
function refreshHydrology() {
const rainAmount = Number(rainfallInput.value) / 100;
const rainWord =
rainAmount === 0 ? "Dry" :
rainAmount < 0.25 ? "Light" :
rainAmount < 0.66 ? "Steady" : "Heavy";
rainValue.textContent = `${Math.round(rainAmount * 100)}% · ${rainWord}`;
const meanRunoff = average(pavingState.map((type) => pavingProperties[type].runoff));
const meanPavingInfiltration = average(
pavingState.map((type) => pavingProperties[type].infiltration)
);
const meanPlantUptake = average(plantState.map((type) => plantProperties[type]));
runoffIntensity = rainAmount * (0.22 + 0.78 * meanRunoff);
infiltrationIntensity = rainAmount * (0.30 * meanPavingInfiltration + 0.70 * meanPlantUptake);
const runoffLabel = qualitativeLevel(runoffIntensity);
const infiltrationLabel = qualitativeLevel(infiltrationIntensity);
runoffStatus.textContent = runoffLabel.word;
runoffBox.dataset.level = runoffLabel.level;
infiltrationStatus.textContent = infiltrationLabel.word;
infiltrationBox.dataset.level = infiltrationLabel.level;
updateMixLabels();
}
function setAllPaving(type) {
pavingTiles.forEach((tile, index) => {
pavingState[index] = type;
tile.material = pavingMaterials[type];
});
refreshHydrology();
}
function setAllPlants(type) {
plantSegments.forEach((segment, index) => {
plantState[index] = type;
segment.type = type;
buildVegetation(segment);
});
refreshHydrology();
}
document.querySelectorAll("[data-paving]").forEach((button) => {
button.addEventListener("click", () => setAllPaving(button.dataset.paving));
});
document.querySelectorAll("[data-plant]").forEach((button) => {
button.addEventListener("click", () => setAllPlants(button.dataset.plant));
});
rainfallInput.addEventListener("input", refreshHydrology);
document.querySelector("#resetStorage").addEventListener("click", () => {
storageLevel = 0;
displayedStorage = 0;
storageStatus.textContent = "0%";
storageBar.style.width = "0%";
waterFill.scale.y = 0.03;
waterFill.position.y = 0.27;
});
document.querySelector("#resetYard").addEventListener("click", () => {
rainfallInput.value = 58;
pavingTiles.forEach((tile, index) => {
const type = defaultPaving(index);
pavingState[index] = type;
tile.material = pavingMaterials[type];
});
plantSegments.forEach((segment, index) => {
const type = index % 5 === 0 ? "trees" : index % 2 === 0 ? "shrubs" : "grass";
plantState[index] = type;
segment.type = type;
buildVegetation(segment);
});
storageLevel = 0;
displayedStorage = 0;
refreshHydrology();
});
document.querySelector("#toggleLabels").addEventListener("change", (event) => {
labelsEnabled = event.target.checked;
if (!labelsEnabled) {
document.querySelectorAll(".scene-label").forEach((label) => {
label.style.display = "none";
});
}
});
// Camera controls are implemented without addons.
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const horizontalView = 15.2;
const verticalView = aspect < 1 ? horizontalView / aspect : 14.6;
camera.left = -horizontalView / 2;
camera.right = horizontalView / 2;
camera.top = verticalView / 2;
camera.bottom = -verticalView / 2;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
const { azimuth, elevation, distance } = cameraState;
camera.position.set(
cameraTarget.x + distance * Math.cos(elevation) * Math.sin(azimuth),
cameraTarget.y + distance * Math.sin(elevation),
cameraTarget.z + distance * Math.cos(elevation) * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.azimuth = 0.68;
cameraState.elevation = 0.72;
cameraState.zoom = 1;
updateCamera();
}
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerStart = null;
function pickAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickingTargets, false)[0];
if (!hit) return;
const data = hit.object.userData;
if (data.kind === "paving") {
const current = pavingState[data.index];
const next = pavingOrder[(pavingOrder.indexOf(current) + 1) % pavingOrder.length];
pavingState[data.index] = next;
hit.object.material = pavingMaterials[next];
} else if (data.kind === "plant") {
const segment = plantSegments[data.index];
const current = segment.type;
const next = plantOrder[(plantOrder.indexOf(current) + 1) % plantOrder.length];
segment.type = next;
plantState[data.index] = next;
buildVegetation(segment);
}
refreshHydrology();
}
canvas.addEventListener("pointerdown", (event) => {
pointerStart = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerStart) return;
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.004,
0.34,
1.22
);
pointerStart = { x: event.clientX, y: event.clientY };
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (!pointerStart) return;
const movement = Math.hypot(
event.clientX - pointerStart.x,
event.clientY - pointerStart.y
);
if (movement < 5) pickAt(event.clientX, event.clientY);
pointerStart = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerStart = null;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.75
);
updateCamera();
}, { passive: false });
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// Projected HTML labels stay attached to their schematic features.
const labelAnchors = {
rain: {
position: new THREE.Vector3(-1.7, 6.1, -1.3),
offset: [0, -15]
},
roof: {
position: new THREE.Vector3(3.65, 2.65, -3.95),
offset: [28, -18]
},
paving: {
position: new THREE.Vector3(-0.8, 0.55, -0.1),
offset: [0, 5]
},
infiltration: {
position: new THREE.Vector3(-6.15, 1.15, 0.1),
offset: [-18, 0]
},
drain: {
position: new THREE.Vector3(4.65, 0.6, 2.7),
offset: [22, 12]
},
storage: {
position: new THREE.Vector3(6.15, 2.45, 1.66),
offset: [35, -5]
}
};
const projectedLabels = Array.from(document.querySelectorAll(".scene-label")).map((element) => ({
element,
...labelAnchors[element.dataset.anchor]
}));
function updateLabels() {
if (!labelsEnabled) return;
const width = window.innerWidth;
const height = window.innerHeight;
projectedLabels.forEach((label) => {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
label.element.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
label.element.style.display = "flex";
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
});
}
const clock = new THREE.Clock();
let elapsed = 0;
function updateRain(rainAmount) {
const visibleCount = Math.round(rainAmount * rainSeeds.length);
rain.count = visibleCount;
rainMaterial.opacity = 0.30 + rainAmount * 0.42;
for (let i = 0; i < visibleCount; i++) {
const seed = rainSeeds[i];
const fall = (elapsed * seed.speed + seed.phase * 7.4) % 7.4;
dummy.position.set(seed.x, 7.0 - fall, seed.z);
dummy.scale.set(0.045, 0.28 + rainAmount * 0.12, 0.045);
dummy.updateMatrix();
rain.setMatrixAt(i, dummy.matrix);
}
rain.instanceMatrix.needsUpdate = true;
}
function updateFlows() {
const rates = {
roof: runoffIntensity,
paving: runoffIntensity,
collection: runoffIntensity * 0.88,
"infiltration-left": infiltrationIntensity,
"infiltration-back": infiltrationIntensity,
"infiltration-left-2": infiltrationIntensity
};
flowPaths.forEach((path) => {
const rate = THREE.MathUtils.clamp(rates[path.name] ?? 0, 0, 1);
path.material.opacity = 0.17 + rate * 0.48;
path.pulseMaterial.opacity = 0.55 + rate * 0.40;
const visiblePulses = Math.ceil(rate * path.pulses.length);
const speed = 0.025 + rate * 0.09;
path.pulses.forEach((pulse, index) => {
pulse.mesh.visible = index < visiblePulses;
if (!pulse.mesh.visible) return;
const t = (elapsed * speed + pulse.offset) % 1;
pulse.mesh.position.copy(pointOnPath(path, t));
pulse.mesh.position.y += 0.035;
const scale = 0.13 + rate * 0.07;
pulse.mesh.scale.set(scale, 0.09, scale);
});
});
}
function updateStorage(delta) {
const rainAmount = Number(rainfallInput.value) / 100;
const meanRunoff = average(pavingState.map((type) => pavingProperties[type].runoff));
// Deliberately qualitative: values are not engineering measurements.
const collectionRate =
rainAmount * (0.009 + 0.026 * (0.35 + 0.65 * meanRunoff));
storageLevel = Math.min(1, storageLevel + collectionRate * delta);
displayedStorage += (storageLevel - displayedStorage) * Math.min(1, delta * 8);
const waterHeight = Math.max(0.025, displayedStorage * 1.78);
waterFill.scale.y = waterHeight;
waterFill.position.y = 0.24 + waterHeight / 2;
const percent = Math.round(displayedStorage * 100);
storageStatus.textContent = `${percent}%`;
storageBar.style.width = `${percent}%`;
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
const rainAmount = Number(rainfallInput.value) / 100;
updateRain(rainAmount);
updateFlows();
updateStorage(delta);
updateLabels();
renderer.render(scene, camera);
}
renderer.setSize(window.innerWidth, window.innerHeight);
resetCamera();
refreshHydrology();
loading.remove();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```