Prompt specification
Build or customize the Three.js 3D scene "Neighborhood Rain Garden Street Section" 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: Neighborhood Rain Garden Street Section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-rain-garden-street-section-x3983
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows stormwater runoff through streets, drains, and permeable ground. Build an original street cutaway with roofs, gutters, pavement, and a planted depression. Show connected flow paths and label the hydraulic behavior qualitative. Voxel style.
Working Three.js Starter (neighborhood-rain-garden-street-section-x3983):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stormwater Cutaway</title>
<style>
:root {
--ink: #17343a;
--muted: #5d7376;
--panel: rgba(249, 252, 249, 0.91);
--line: rgba(23, 52, 58, 0.14);
--blue: #2789ff;
--cyan: #16b9d1;
--green: #52aa68;
--amber: #e49b36;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8efeb;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.header {
position: absolute;
top: 26px;
left: 28px;
max-width: 480px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #2d6f71;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 4px;
border-radius: 4px;
background: #2f8f8d;
}
h1 {
margin: 0;
font-size: clamp(26px, 3.4vw, 46px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 410px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow:
0 14px 40px rgba(33, 61, 61, 0.10),
inset 0 1px 0 rgba(255, 255, 255, 0.75);
backdrop-filter: blur(12px);
}
.legend {
position: absolute;
top: 26px;
right: 28px;
width: 270px;
padding: 17px 18px 15px;
pointer-events: auto;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel-title span:last-child {
color: #759092;
font-size: 9px;
letter-spacing: 0.08em;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr auto;
gap: 9px;
align-items: center;
margin: 9px 0;
font-size: 12px;
}
.legend-row small {
color: #789092;
font-size: 10px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.035);
}
.intensity {
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.intensity-label {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
accent-color: #2789ff;
cursor: pointer;
}
.behavior {
position: absolute;
right: 28px;
bottom: 27px;
width: 326px;
padding: 18px;
pointer-events: auto;
}
.behavior h2 {
margin: 0 0 13px;
font-size: 15px;
letter-spacing: -0.015em;
}
.behavior ol {
display: grid;
gap: 9px;
margin: 0;
padding: 0;
list-style: none;
counter-reset: steps;
}
.behavior li {
position: relative;
min-height: 19px;
padding-left: 29px;
color: #4f686c;
font-size: 11px;
line-height: 1.45;
counter-increment: steps;
}
.behavior li::before {
content: counter(steps);
position: absolute;
top: 0;
left: 0;
display: grid;
place-items: center;
width: 19px;
height: 19px;
border-radius: 5px;
background: #e7efeb;
color: #2b6667;
font-size: 9px;
font-weight: 850;
}
.behavior li strong {
color: var(--ink);
font-weight: 760;
}
.note {
margin: 14px 0 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #809295;
font-size: 9px;
line-height: 1.45;
}
.toolbar {
position: absolute;
left: 50%;
bottom: 27px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(249, 252, 249, 0.92);
box-shadow: 0 12px 35px rgba(33, 61, 61, 0.12);
backdrop-filter: blur(12px);
transform: translateX(-50%);
pointer-events: auto;
}
.toolbar button {
min-height: 35px;
padding: 0 12px;
border: 0;
border-radius: 8px;
background: transparent;
color: #536d70;
font-size: 11px;
font-weight: 760;
cursor: pointer;
transition:
background 140ms ease,
color 140ms ease,
transform 140ms ease;
}
.toolbar button:hover {
background: #eaf0ec;
color: var(--ink);
}
.toolbar button:active {
transform: translateY(1px);
}
.toolbar button.active {
background: #dcece7;
color: #1f6261;
}
.toolbar .divider {
width: 1px;
margin: 5px 2px;
background: var(--line);
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
z-index: 3;
padding: 6px 9px;
border: 1px solid rgba(25, 54, 59, 0.14);
border-radius: 7px;
background: rgba(250, 253, 250, 0.89);
box-shadow: 0 5px 18px rgba(34, 65, 65, 0.10);
color: #29474b;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.095em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
will-change: transform;
}
.scene-label::before {
content: "";
position: absolute;
top: 50%;
left: -8px;
width: 7px;
height: 2px;
background: currentColor;
opacity: 0.35;
}
.scene-label.blue {
color: #1673d9;
}
.scene-label.cyan {
color: #078fa8;
}
.scene-label.green {
color: #338c50;
}
.scene-label.amber {
color: #b46f16;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8efeb;
color: #376b6b;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.behavior {
display: none;
}
.legend {
top: 22px;
right: 20px;
width: 225px;
}
.header {
top: 22px;
left: 20px;
max-width: calc(100vw - 275px);
}
.toolbar {
bottom: 18px;
}
}
@media (max-width: 650px) {
.header {
max-width: calc(100vw - 40px);
}
.header .subtitle {
max-width: 310px;
}
.legend {
top: 125px;
left: 20px;
right: auto;
width: 205px;
padding: 13px;
}
.legend .legend-row {
margin: 7px 0;
}
.toolbar {
width: calc(100vw - 24px);
justify-content: center;
overflow-x: auto;
}
.toolbar button {
flex: 0 0 auto;
padding: 0 9px;
font-size: 10px;
}
.scene-label {
font-size: 8px;
}
.scene-label.optional {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="ui">
<header class="header">
<div class="eyebrow">Urban watershed / cutaway 01</div>
<h1>Stormwater,<br>below the surface.</h1>
<p class="subtitle">
A voxel street section showing how roof runoff, street drainage,
connected pipes, planted ground, and permeable soil work together.
</p>
</header>
<section class="panel legend" aria-label="Flow legend">
<div class="panel-title">
<span>Flow language</span>
<span>Qualitative</span>
</div>
<div class="legend-row">
<i class="swatch" style="background: var(--cyan)"></i>
<span>Roof runoff</span>
<small>fast</small>
</div>
<div class="legend-row">
<i class="swatch" style="background: var(--blue)"></i>
<span>Street + pipe flow</span>
<small>moving</small>
</div>
<div class="legend-row">
<i class="swatch" style="background: var(--green)"></i>
<span>Infiltration</span>
<small>slow</small>
</div>
<div class="legend-row">
<i class="swatch" style="background: var(--amber)"></i>
<span>High-flow overflow</span>
<small>rare</small>
</div>
<div class="intensity">
<label class="intensity-label" for="rainRange">
<span>Storm intensity</span>
<span id="intensityValue">65%</span>
</label>
<input id="rainRange" type="range" min="0" max="100" value="65">
</div>
</section>
<section class="panel behavior" aria-label="Hydraulic behavior explanation">
<h2>How the street drains</h2>
<ol>
<li><strong>Roofs concentrate rain</strong> into gutters and downspouts.</li>
<li><strong>Street grade</strong> carries runoff along the gutter to inlets.</li>
<li><strong>Connected pipes</strong> move water toward the planted depression.</li>
<li><strong>Plants and filter media</strong> slow, store, and infiltrate the flow.</li>
<li><strong>During excess flow,</strong> an overflow notch bypasses the basin.</li>
</ol>
<p class="note">
Paths and relative rates are illustrative, not a hydraulic model.
Blue pipe routes are shown as a schematic cutaway overlay.
</p>
</section>
<nav class="toolbar" aria-label="Scene controls">
<button id="flowBtn" class="active" aria-pressed="true">Flow paths</button>
<button id="rainBtn" class="active" aria-pressed="true">Rain</button>
<button id="labelsBtn" class="active" aria-pressed="true">Labels</button>
<span class="divider"></span>
<button id="zoomOut" aria-label="Zoom out">−</button>
<button id="resetBtn">Reset view</button>
<button id="zoomIn" aria-label="Zoom in">+</button>
</nav>
<div id="labels" aria-hidden="true"></div>
</div>
<div id="loading">Building watershed…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const labelsLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8efeb);
scene.fog = new THREE.Fog(0xe8efeb, 31, 58);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const view = {
azimuth: 0.62,
polar: 1.01,
zoom: 1,
target: new THREE.Vector3(0, -0.25, 0)
};
let currentViewHeight = 13.5;
function updateCamera() {
const radius = 26;
const sinPolar = Math.sin(view.polar);
camera.position.set(
view.target.x + radius * sinPolar * Math.sin(view.azimuth),
view.target.y + radius * Math.cos(view.polar),
view.target.z + radius * sinPolar * Math.cos(view.azimuth)
);
camera.lookAt(view.target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
currentViewHeight = Math.max(13.5, 22 / aspect);
camera.left = (-currentViewHeight * aspect) / 2;
camera.right = (currentViewHeight * aspect) / 2;
camera.top = currentViewHeight / 2;
camera.bottom = -currentViewHeight / 2;
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemi = new THREE.HemisphereLight(0xf6fffc, 0x74847b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4df, 3.2);
sun.position.set(-8, 15, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bd4e1, 0.7);
fill.position.set(10, 7, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Geometry helpers and materials
// -------------------------------------------------------------------------
const world = new THREE.Group();
const flowGroup = new THREE.Group();
const pipeGroup = new THREE.Group();
scene.add(world, pipeGroup, flowGroup);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const mat = {
subsoil: new THREE.MeshStandardMaterial({
color: 0xb9825f,
roughness: 1,
flatShading: true
}),
aggregate: new THREE.MeshStandardMaterial({
color: 0x9f9b83,
roughness: 1,
flatShading: true
}),
soil: new THREE.MeshStandardMaterial({
color: 0x806f50,
roughness: 1,
flatShading: true
}),
gardenSoil: new THREE.MeshStandardMaterial({
color: 0x65704a,
roughness: 1,
flatShading: true
}),
sand: new THREE.MeshStandardMaterial({
color: 0xd2b77e,
roughness: 1,
flatShading: true
}),
gravel: new THREE.MeshStandardMaterial({
color: 0x8e9589,
roughness: 1,
flatShading: true
}),
asphalt: new THREE.MeshStandardMaterial({
color: 0x424e52,
roughness: 0.95,
flatShading: true
}),
asphalt2: new THREE.MeshStandardMaterial({
color: 0x49575b,
roughness: 0.95,
flatShading: true
}),
curb: new THREE.MeshStandardMaterial({
color: 0xb9beb4,
roughness: 0.9,
flatShading: true
}),
paver: new THREE.MeshStandardMaterial({
color: 0xc8c9bc,
roughness: 0.95,
flatShading: true
}),
houseA: new THREE.MeshStandardMaterial({
color: 0xe6d9bd,
roughness: 0.88,
flatShading: true
}),
houseB: new THREE.MeshStandardMaterial({
color: 0xc8d5ca,
roughness: 0.88,
flatShading: true
}),
roofA: new THREE.MeshStandardMaterial({
color: 0x5c7473,
roughness: 0.88,
flatShading: true
}),
roofB: new THREE.MeshStandardMaterial({
color: 0xa96f54,
roughness: 0.88,
flatShading: true
}),
trim: new THREE.MeshStandardMaterial({
color: 0xf4efe1,
roughness: 0.85,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x273b3e,
roughness: 0.8,
flatShading: true
}),
grate: new THREE.MeshStandardMaterial({
color: 0x1f3033,
roughness: 0.65,
metalness: 0.35,
flatShading: true
}),
window: new THREE.MeshStandardMaterial({
color: 0x81bcca,
emissive: 0x244b56,
emissiveIntensity: 0.35,
roughness: 0.32,
flatShading: true
}),
door: new THREE.MeshStandardMaterial({
color: 0x5c776e,
roughness: 0.85,
flatShading: true
}),
stem: new THREE.MeshStandardMaterial({
color: 0x476b3d,
roughness: 1,
flatShading: true
}),
leaf1: new THREE.MeshStandardMaterial({
color: 0x5b9c56,
roughness: 1,
flatShading: true
}),
leaf2: new THREE.MeshStandardMaterial({
color: 0x78aa55,
roughness: 1,
flatShading: true
}),
leaf3: new THREE.MeshStandardMaterial({
color: 0x3f7e4a,
roughness: 1,
flatShading: true
}),
water: new THREE.MeshStandardMaterial({
color: 0x4eafd2,
transparent: true,
opacity: 0.42,
roughness: 0.18,
metalness: 0.08,
depthWrite: false
}),
paint: new THREE.MeshStandardMaterial({
color: 0xe6c75d,
roughness: 0.95,
flatShading: true
}),
whitePaint: new THREE.MeshStandardMaterial({
color: 0xe8eee7,
roughness: 0.95,
flatShading: true
})
};
function box(w, h, d, x, y, z, material, parent = world) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(radius, height, x, y, z, material, radialSegments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, radialSegments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
world.add(mesh);
return mesh;
}
let seed = 72341;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// -------------------------------------------------------------------------
// Soil mass and visible cutaway strata
// -------------------------------------------------------------------------
box(20, 1.4, 10, 0, -3.3, 0, mat.subsoil);
box(20, 0.8, 10, 0, -2.2, 0, mat.aggregate);
// Land is assembled around a rectangular garden void.
box(20, 1.8, 3, 0, -0.9, -3.5, mat.soil);
box(12.4, 1.8, 7, -3.8, -0.9, 1.5, mat.soil);
box(0.8, 1.8, 7, 9.6, -0.9, 1.5, mat.soil);
box(6.8, 1.8, 0.6, 5.8, -0.9, 4.7, mat.soil);
// Pixel-like inclusions on the exposed front cut.
const inclusionMaterials = [
new THREE.MeshStandardMaterial({ color: 0xc69a72, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x907558, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0xada48e, roughness: 1 })
];
for (let i = 0; i < 52; i++) {
const size = 0.12 + random() * 0.28;
box(
size,
size * 0.65,
0.035,
-9.5 + random() * 19,
-3.8 + random() * 1.85,
5.025,
inclusionMaterials[i % inclusionMaterials.length]
);
}
// Subtle reference grid under the model.
const grid = new THREE.GridHelper(32, 32, 0xc6d3cd, 0xd8e1dc);
grid.position.y = -4.02;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0xe3eae5,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -4.04;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Street, curb, sidewalk, markings
// -------------------------------------------------------------------------
for (let i = 0; i < 8; i++) {
const x = -8.75 + i * 2.5;
const y = 0.16 - i * 0.012;
box(2.5, 0.28, 2.5, x, y, -0.75, i % 2 ? mat.asphalt : mat.asphalt2);
}
// Rear sidewalk and individual voxel pavers.
box(20, 0.2, 0.42, 0, 0.1, -2.22, mat.curb);
for (let i = 0; i < 20; i++) {
box(0.82, 0.07, 0.35, -9.5 + i, 0.245, -2.23, mat.paver);
}
// Near curb, segmented into voxel blocks.
for (let i = 0; i < 20; i++) {
box(0.96, 0.38, 0.22, -9.5 + i, 0.19, 0.57, mat.curb);
}
// Gutter edge.
box(20, 0.055, 0.15, 0, 0.075, 0.36, mat.dark);
// Dashed center line.
for (let i = 0; i < 10; i++) {
box(0.75, 0.035, 0.10, -9 + i * 2, 0.33 - Math.abs(i - 5) * 0.012, -0.79, mat.paint);
}
// Crosswalk-like white blocks.
for (let i = 0; i < 5; i++) {
box(0.25, 0.035, 1.25, -0.9 + i * 0.36, 0.31, -0.55, mat.whitePaint);
}
// -------------------------------------------------------------------------
// Houses, stepped voxel roofs, gutters, downspouts
// -------------------------------------------------------------------------
function buildHouse({
x,
z,
width,
depth,
wallHeight,
wallMaterial,
roofMaterial,
roofLevels,
gutterX
}) {
box(width + 0.35, 0.22, depth + 0.3, x, 0.11, z, mat.curb);
box(width, wallHeight, depth, x, 0.22 + wallHeight / 2, z, wallMaterial);
// Stepped roof silhouette.
for (let i = 0; i < roofLevels; i++) {
const w = width + 0.42 - i * 0.47;
const d = depth + 0.42 - i * 0.38;
box(
w,
0.25,
d,
x,
0.22 + wallHeight + i * 0.25,
z,
roofMaterial
);
}
const front = z + depth / 2 + 0.035;
const roofY = 0.22 + wallHeight + 0.1;
// Windows.
box(0.64, 0.58, 0.07, x - width * 0.28, 1.55, front, mat.window);
box(0.64, 0.58, 0.07, x + width * 0.28, 1.55, front, mat.window);
box(0.58, 0.62, 0.07, x, 1.55, front, mat.window);
// Door and trim.
box(0.56, 1.24, 0.08, x + width * 0.03, 0.86, front + 0.015, mat.door);
box(0.67, 0.08, 0.1, x + width * 0.03, 1.51, front + 0.02, mat.trim);
box(0.06, 0.52, 0.07, x - width * 0.59, 1.5, front, mat.trim);
box(0.06, 0.52, 0.07, x + width * 0.59, 1.5, front, mat.trim);
// Front gutter.
box(width + 0.4, 0.13, 0.16, x, roofY, front - 0.02, mat.dark);
// Downspout: square, voxel-like vertical pipe.
box(0.12, roofY - 0.38, 0.12, gutterX, (roofY + 0.38) / 2, front - 0.03, mat.dark);
box(0.45, 0.11, 0.13, gutterX - 0.12, 0.39, front - 0.03, mat.dark);
// Chimney.
box(0.42, 0.72, 0.42, x + width * 0.25, roofY + 1.02, z - 0.18, mat.trim);
box(0.55, 0.12, 0.55, x + width * 0.25, roofY + 1.42, z - 0.18, mat.dark);
}
buildHouse({
x: -6.4,
z: -3.45,
width: 3,
depth: 2.1,
wallHeight: 2.25,
wallMaterial: mat.houseA,
roofMaterial: mat.roofA,
roofLevels: 5,
gutterX: -4.55
});
buildHouse({
x: -0.55,
z: -3.48,
width: 2.55,
depth: 1.95,
wallHeight: 2.08,
wallMaterial: mat.houseB,
roofMaterial: mat.roofB,
roofLevels: 5,
gutterX: 0.98
});
// -------------------------------------------------------------------------
// Storm inlets
// -------------------------------------------------------------------------
function buildInlet(x) {
box(1.02, 0.22, 0.76, x, 0.22, 0.31, mat.dark);
box(0.91, 0.08, 0.66, x, 0.35, 0.31, mat.grate);
for (let i = 0; i < 7; i++) {
box(
0.055,
0.055,
0.58,
x - 0.34 + i * 0.112,
0.415,
0.31,
mat.grate
);
}
// Small curb opening.
box(0.86, 0.16, 0.06, x, 0.22, 0.675, mat.dark);
}
buildInlet(-2.7);
buildInlet(2.25);
// -------------------------------------------------------------------------
// Planted depression and filter-media section
// -------------------------------------------------------------------------
box(6.8, 0.55, 3.2, 5.8, -1.525, 2.8, mat.gravel);
box(6.8, 0.65, 3.2, 5.8, -0.925, 2.8, mat.sand);
box(6.8, 0.35, 3.2, 5.8, -0.425, 2.8, mat.gardenSoil);
// Depression edges, with a front overflow notch.
box(0.28, 0.28, 3.45, 2.46, 0.08, 2.8, mat.curb);
box(0.28, 0.28, 3.45, 9.14, 0.08, 2.8, mat.curb);
box(6.95, 0.28, 0.28, 5.8, 0.08, 1.16, mat.curb);
box(1.22, 0.25, 0.28, 3.03, 0.08, 4.43, mat.curb);
box(5.05, 0.25, 0.28, 6.68, 0.08, 4.43, mat.curb);
// Shallow retained water.
const basinWater = box(5.92, 0.055, 2.50, 5.8, -0.17, 2.75, mat.water);
basinWater.castShadow = false;
basinWater.renderOrder = 2;
// Gravel inclusions visible in the section.
const pebbleMats = [
new THREE.MeshStandardMaterial({ color: 0xb7b3a2, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x777e77, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x99927e, roughness: 1 })
];
for (let i = 0; i < 24; i++) {
const s = 0.12 + random() * 0.16;
box(
s,
s * 0.65,
0.08,
2.75 + random() * 6.1,
-1.42 + random() * 0.48,
4.43,
pebbleMats[i % pebbleMats.length]
);
}
function plant(x, z, scale = 1, variant = 0) {
const leafMaterials = [mat.leaf1, mat.leaf2, mat.leaf3];
const leafMaterial = leafMaterials[variant % leafMaterials.length];
box(
0.07 * scale,
0.72 * scale,
0.07 * scale,
x,
-0.04 + 0.36 * scale,
z,
mat.stem
);
const leaf = box(
0.46 * scale,
0.24 * scale,
0.42 * scale,
x,
0.28 * scale,
z,
leafMaterial
);
leaf.rotation.y = (variant % 4) * 0.35;
const leaf2 = box(
0.33 * scale,
0.19 * scale,
0.36 * scale,
x + 0.14 * scale,
0.51 * scale,
z - 0.04,
leafMaterial
);
leaf2.rotation.z = 0.16;
}
const plantPositions = [
[3.0, 2.0, 0.9, 0],
[3.25, 3.8, 1.05, 1],
[4.75, 3.72, 0.85, 2],
[6.25, 3.75, 1.1, 0],
[8.35, 3.55, 0.95, 1],
[8.45, 1.95, 1.0, 2],
[5.1, 2.4, 0.72, 1],
[6.85, 2.05, 0.8, 0],
[7.7, 3.9, 0.7, 2]
];
plantPositions.forEach((p) => plant(...p));
// Animated square glints on the water.
const glints = [];
for (let i = 0; i < 6; i++) {
const glint = box(
0.23,
0.018,
0.10,
3.4 + random() * 4.7,
-0.13,
1.7 + random() * 2.2,
mat.whitePaint
);
glint.castShadow = false;
glint.userData.baseX = glint.position.x;
glint.userData.baseZ = glint.position.z;
glint.userData.phase = random() * Math.PI * 2;
glints.push(glint);
}
// -------------------------------------------------------------------------
// Connected flow paths and pipe shells
// -------------------------------------------------------------------------
const flowRecords = [];
const flowParticleGeometry = new THREE.BoxGeometry(0.105, 0.105, 0.105);
const flowArrowGeometry = new THREE.ConeGeometry(0.095, 0.25, 4);
const upAxis = new THREE.Vector3(0, 1, 0);
function addFlow(points, color, options = {}) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
false,
"catmullrom",
0.12
);
const xray = options.xray ?? false;
const opacity = options.opacity ?? 0.82;
const tubeMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthTest: !xray,
depthWrite: false
});
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, options.segments ?? 80, options.radius ?? 0.035, 5, false),
tubeMaterial
);
tube.renderOrder = xray ? 14 : 5;
flowGroup.add(tube);
const arrowMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: Math.min(1, opacity + 0.08),
depthTest: !xray,
depthWrite: false
});
const arrowFractions = options.arrows ?? [0.27, 0.61, 0.84];
arrowFractions.forEach((fraction) => {
const arrow = new THREE.Mesh(flowArrowGeometry, arrowMaterial);
arrow.position.copy(curve.getPointAt(fraction));
arrow.quaternion.setFromUnitVectors(
upAxis,
curve.getTangentAt(fraction).normalize()
);
arrow.renderOrder = xray ? 15 : 6;
flowGroup.add(arrow);
});
const particleMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: !xray,
depthWrite: false
});
const particles = [];
const particleCount = options.particles ?? 4;
for (let i = 0; i < particleCount; i++) {
const particle = new THREE.Mesh(flowParticleGeometry, particleMaterial);
particle.renderOrder = xray ? 16 : 7;
flowGroup.add(particle);
particles.push({
mesh: particle,
offset: i / particleCount,
drift: 0.03 + random() * 0.035
});
}
flowRecords.push({
curve,
particles,
speed: options.speed ?? 0.115
});
return curve;
}
function addPipeShell(curve) {
const material = new THREE.MeshStandardMaterial({
color: 0x355158,
roughness: 0.75,
transparent: true,
opacity: 0.36,
depthTest: false,
depthWrite: false
});
const shell = new THREE.Mesh(
new THREE.TubeGeometry(curve, 90, 0.145, 7, false),
material
);
shell.renderOrder = 11;
pipeGroup.add(shell);
}
// Roof A: roof → gutter → downspout → street inlet.
addFlow(
[
[-6.4, 3.85, -3.35],
[-6.4, 3.35, -2.65],
[-6.15, 2.74, -2.20],
[-5.05, 2.62, -2.20],
[-4.55, 2.55, -2.20],
[-4.55, 0.82, -2.20],
[-3.78, 0.42, -0.20],
[-2.70, 0.39, 0.30]
],
0x16b9d1,
{ speed: 0.14, arrows: [0.25, 0.56, 0.82], particles: 5 }
);
// Roof B.
addFlow(
[
[-0.55, 3.62, -3.40],
[-0.55, 3.13, -2.63],
[-0.22, 2.65, -2.23],
[0.50, 2.58, -2.23],
[0.98, 2.48, -2.23],
[0.98, 0.78, -2.23],
[1.62, 0.39, -0.18],
[2.25, 0.39, 0.30]
],
0x16b9d1,
{ speed: 0.15, arrows: [0.28, 0.63, 0.86], particles: 5 }
);
// Street runoff along the gutter.
addFlow(
[
[-9.35, 0.29, 0.35],
[-7.25, 0.26, 0.35],
[-5.05, 0.23, 0.35],
[-3.55, 0.22, 0.35],
[-2.70, 0.39, 0.30]
],
0x2789ff,
{ speed: 0.10, arrows: [0.24, 0.61, 0.86], particles: 5 }
);
// A second local street catchment.
addFlow(
[
[-1.65, 0.23, 0.35],
[-0.55, 0.24, 0.35],
[0.95, 0.26, 0.35],
[1.85, 0.31, 0.34],
[2.25, 0.39, 0.30]
],
0x2789ff,
{ speed: 0.105, arrows: [0.30, 0.72], particles: 4 }
);
// Connected underground route: inlet 1 → planted depression.
const mainPipeCurve = addFlow(
[
[-2.70, 0.28, 0.30],
[-2.70, -0.40, 0.30],
[-1.85, -0.64, 0.22],
[0.25, -0.72, 0.28],
[2.30, -0.65, 0.55],
[3.25, -0.40, 1.10],
[4.15, -0.12, 1.62],
[4.75, -0.10, 2.00]
],
0x2789ff,
{
xray: true,
opacity: 0.74,
speed: 0.105,
arrows: [0.23, 0.53, 0.81],
particles: 6
}
);
addPipeShell(mainPipeCurve);
// Connected underground route: inlet 2 → planted depression.
const secondPipeCurve = addFlow(
[
[2.25, 0.28, 0.30],
[2.25, -0.42, 0.30],
[2.60, -0.60, 0.62],
[3.05, -0.40, 1.00],
[3.75, -0.13, 1.48],
[4.35, -0.10, 1.85]
],
0x2789ff,
{
xray: true,
opacity: 0.74,
speed: 0.11,
arrows: [0.28, 0.66],
particles: 5
}
);
addPipeShell(secondPipeCurve);
// Infiltration through filter media and subsoil.
[4.65, 6.15, 7.65].forEach((x, index) => {
addFlow(
[
[x, -0.14, 3.55],
[x, -0.46, 3.95],
[x, -1.12, 4.48],
[x, -2.02, 4.66],
[x, -3.12, 4.66]
],
0x52aa68,
{
xray: true,
opacity: 0.76,
speed: 0.055 + index * 0.006,
arrows: [0.32, 0.70],
particles: 4,
radius: 0.027
}
);
});
// Overflow notch for high-flow conditions.
addFlow(
[
[3.85, -0.12, 4.16],
[3.87, -0.04, 4.48],
[3.87, -0.38, 4.78],
[3.87, -1.10, 5.06],
[3.15, -1.32, 5.06]
],
0xe49b36,
{
xray: true,
opacity: 0.9,
speed: 0.09,
arrows: [0.30, 0.72],
particles: 4
}
);
// A small visible junction block at the garden inlet.
box(0.42, 0.22, 0.32, 4.55, -0.10, 1.72, mat.grate);
// -------------------------------------------------------------------------
// Rain: instanced voxel raindrops
// -------------------------------------------------------------------------
const rainGeometry = new THREE.BoxGeometry(0.045, 0.31, 0.045);
const rainMaterial = new THREE.MeshBasicMaterial({
color: 0x6cb9d5,
transparent: true,
opacity: 0.38,
depthWrite: false
});
const maxRaindrops = 135;
const rainMesh = new THREE.InstancedMesh(
rainGeometry,
rainMaterial,
maxRaindrops
);
rainMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
rainMesh.frustumCulled = false;
scene.add(rainMesh);
const rainData = [];
const rainDummy = new THREE.Object3D();
for (let i = 0; i < maxRaindrops; i++) {
rainData.push({
x: -11 + random() * 22,
y: 1 + random() * 9,
z: -5.2 + random() * 10.4,
speed: 4.3 + random() * 4.2
});
}
// -------------------------------------------------------------------------
// Projected HTML labels — no external label renderer required
// -------------------------------------------------------------------------
const labelItems = [];
function addLabel(text, position, dx, dy, className = "", optional = false) {
const element = document.createElement("div");
element.className = `scene-label ${className} ${optional ? "optional" : ""}`;
element.textContent = text;
labelsLayer.appendChild(element);
labelItems.push({
element,
position: new THREE.Vector3(...position),
dx,
dy
});
}
addLabel("Roof runoff", [-6.4, 3.9, -3.3], -45, -24, "cyan");
addLabel("Gutter + downspout", [-4.55, 2.5, -2.2], -8, -42, "cyan", true);
addLabel("Street grade", [-7.25, 0.4, -0.65], -18, -29, "blue", true);
addLabel("Leaf-litter inlet", [-2.7, 0.45, 0.3], -18, 28, "blue");
addLabel("Connected storm pipe", [0.1, -0.72, 0.3], -10, 35, "blue");
addLabel("Planted depression", [6.1, 0.35, 2.8], 45, -31, "green");
addLabel("Filter media", [5.9, -0.95, 4.45], 78, 8, "green", true);
addLabel("Infiltration ↓", [6.15, -2.0, 4.66], 75, 14, "green");
addLabel("High-flow overflow", [3.87, -0.35, 4.8], -55, -2, "amber", true);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelItems.forEach((item) => {
projected.copy(item.position).project(camera);
const visible =
state.labels &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
item.element.style.visibility = visible ? "visible" : "hidden";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width + item.dx;
const y = (-projected.y * 0.5 + 0.5) * height + item.dy;
item.element.style.transform = `translate(-50%, -50%)`;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
});
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset, keyboard
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey || event.button === 2;
previousX = event.clientX;
previousY = event.clientY;
pointerId = event.pointerId;
canvas.setPointerCapture(pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const panScale = currentViewHeight / camera.zoom / height;
view.target.addScaledVector(right, -dx * panScale);
view.target.addScaledVector(camera.up, dy * panScale);
} else {
view.azimuth -= dx * 0.006;
view.polar = THREE.MathUtils.clamp(
view.polar + dy * 0.005,
0.55,
1.36
);
}
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
panning = false;
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.75
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "+" || event.key === "=") {
view.zoom = Math.min(1.75, view.zoom * 1.1);
} else if (event.key === "-") {
view.zoom = Math.max(0.65, view.zoom / 1.1);
} else if (event.key.toLowerCase() === "r") {
resetView();
} else {
return;
}
updateCamera();
});
function resetView() {
view.azimuth = 0.62;
view.polar = 1.01;
view.zoom = 1;
view.target.set(0, -0.25, 0);
updateCamera();
}
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const state = {
flows: true,
rain: true,
labels: true,
intensity: 0.65
};
const flowButton = document.querySelector("#flowBtn");
const rainButton = document.querySelector("#rainBtn");
const labelsButton = document.querySelector("#labelsBtn");
const rainRange = document.querySelector("#rainRange");
const intensityValue = document.querySelector("#intensityValue");
function updateToggle(button, key) {
button.classList.toggle("active", state[key]);
button.setAttribute("aria-pressed", String(state[key]));
}
flowButton.addEventListener("click", () => {
state.flows = !state.flows;
flowGroup.visible = state.flows;
updateToggle(flowButton, "flows");
});
rainButton.addEventListener("click", () => {
state.rain = !state.rain;
rainMesh.visible = state.rain;
updateToggle(rainButton, "rain");
});
labelsButton.addEventListener("click", () => {
state.labels = !state.labels;
updateToggle(labelsButton, "labels");
});
rainRange.addEventListener("input", () => {
state.intensity = Number(rainRange.value) / 100;
intensityValue.textContent = `${rainRange.value}%`;
});
document.querySelector("#zoomIn").addEventListener("click", () => {
view.zoom = Math.min(1.75, view.zoom * 1.12);
updateCamera();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
view.zoom = Math.max(0.65, view.zoom / 1.12);
updateCamera();
});
document.querySelector("#resetBtn").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const intensityFactor = 0.55 + state.intensity * 0.9;
// Flow particles.
flowRecords.forEach((record, flowIndex) => {
record.particles.forEach((particle) => {
const progress =
(elapsed * record.speed * intensityFactor + particle.offset) % 1;
const position = record.curve.getPointAt(progress);
particle.mesh.position.copy(position);
particle.mesh.rotation.set(
elapsed * 1.8 + flowIndex,
elapsed * 1.3,
elapsed * 0.9
);
});
});
// Rain.
if (state.rain) {
const count = Math.floor(maxRaindrops * state.intensity);
for (let i = 0; i < count; i++) {
const drop = rainData[i];
drop.y -= delta * drop.speed;
if (drop.y < 0.25) {
drop.y = 8 + random() * 4;
drop.x = -11 + random() * 22;
drop.z = -5.2 + random() * 10.4;
}
rainDummy.position.set(drop.x, drop.y, drop.z);
rainDummy.rotation.set(0, 0, -0.07);
rainDummy.updateMatrix();
rainMesh.setMatrixAt(i, rainDummy.matrix);
}
rainMesh.count = count;
rainMesh.instanceMatrix.needsUpdate = true;
}
// Water glints.
glints.forEach((glint) => {
const phase = elapsed * 0.65 + glint.userData.phase;
glint.position.x = glint.userData.baseX + Math.sin(phase) * 0.18;
glint.position.z = glint.userData.baseZ + Math.cos(phase * 0.8) * 0.13;
glint.material.opacity = 0.28 + Math.sin(phase * 1.7) * 0.12;
});
basinWater.material.opacity = 0.39 + Math.sin(elapsed * 1.1) * 0.035;
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
animate();
requestAnimationFrame(() => {
loading.classList.add("done");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```