Prompt specification
Build or customize the Three.js 3D scene "Rain garden beside a bus stop" 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: Rain garden beside a bus stop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rain-garden-beside-a-bus-stop-x1263
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring urban stormwater drainage. Compose a sidewalk, accessible boarding area, curb opening, planted basin, and overflow outlet; route water around the pedestrian area into the basin. Voxel style.
Working Three.js Starter (rain-garden-beside-a-bus-stop-x1263):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Stormwater Drainage Scene</title>
<style>
:root {
color-scheme: light;
--ink: #17343a;
--muted: #526b70;
--panel: rgba(248, 251, 247, 0.88);
--line: rgba(23, 52, 58, 0.14);
--cyan: #19a9bd;
--green: #719d68;
--yellow: #eab94e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8ccc5;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(27, 54, 58, 0.16);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 18px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #477078;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(25, 169, 189, 0.14);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.subtitle {
margin: 12px 0 0;
max-width: 34ch;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
left: 22px;
bottom: 22px;
padding: 14px 16px;
display: grid;
gap: 9px;
font-size: 12px;
font-weight: 650;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
white-space: nowrap;
}
.swatch {
width: 15px;
height: 15px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.flow {
background: #22b5ca;
}
.swatch.basin {
background: #789d6a;
}
.swatch.tactile {
background: #f0c34f;
}
.swatch.outlet {
background: #47646a;
}
.controls {
right: 22px;
bottom: 22px;
padding: 8px;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 0;
border-radius: 11px;
padding: 10px 13px;
background: #e9efeb;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
background: #dce7e1;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(25, 169, 189, 0.35);
outline-offset: 2px;
}
.hint {
position: fixed;
z-index: 9;
top: 22px;
right: 22px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.38);
border-radius: 999px;
background: rgba(23, 52, 58, 0.76);
color: #f4faf7;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(10px);
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.subtitle {
max-width: 45ch;
}
.hint {
display: none;
}
.legend {
left: 12px;
bottom: 12px;
padding: 10px 12px;
gap: 6px;
}
.controls {
right: 12px;
bottom: 12px;
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="panel title-card">
<div class="eyebrow">Urban water systems</div>
<h1>Stormwater<br />Drainage</h1>
<p class="subtitle">
Runoff travels through a curb opening, skirts the accessible boarding area,
and settles in a planted basin before reaching the overflow outlet.
</p>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="panel legend" aria-label="Scene legend">
<div class="legend-row"><span class="swatch flow"></span>Active water route</div>
<div class="legend-row"><span class="swatch basin"></span>Planted treatment basin</div>
<div class="legend-row"><span class="swatch tactile"></span>Accessible tactile paving</div>
<div class="legend-row"><span class="swatch outlet"></span>Overflow structure</div>
</div>
<div class="panel controls">
<button id="pauseButton" type="button">Pause water</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8ccc5);
scene.fog = new THREE.Fog(0xb8ccc5, 38, 72);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-15, 15, 9, -9, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, -1.2);
let cameraTheta = 0.62;
let cameraPhi = 0.91;
let cameraZoom = 1;
function updateCamera() {
const spherical = new THREE.Spherical(30, cameraPhi, cameraTheta);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const halfWidth = 15;
const halfHeight = halfWidth / aspect;
camera.left = -halfWidth;
camera.right = halfWidth;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
scene.add(new THREE.HemisphereLight(0xf5fbff, 0x687760, 2.15));
const sun = new THREE.DirectionalLight(0xfff6de, 3.1);
sun.position.set(-9, 18, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xa8dbe0, 1.05);
rim.position.set(12, 7, -12);
scene.add(rim);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options,
});
const mats = {
base: material(0x75857c),
baseEdge: material(0x607269),
grass: material(0x91b681),
grassDark: material(0x739c68),
grassLight: material(0xa7c78e),
asphalt: material(0x45545a),
asphaltEdge: material(0x34464b),
gutter: material(0x304b52),
concrete: material(0xd8dbd2),
concreteLight: material(0xebe9df),
concreteDark: material(0xaeb7ae),
curb: material(0xc3c8be),
soil: material(0x695747),
soilLight: material(0x806651),
water: material(0x26b5c9, {
roughness: 0.25,
metalness: 0.05,
transparent: true,
opacity: 0.83,
emissive: 0x075766,
emissiveIntensity: 0.34,
}),
waterLight: material(0x7be1e6, {
roughness: 0.22,
transparent: true,
opacity: 0.9,
emissive: 0x1b7580,
emissiveIntensity: 0.3,
}),
yellow: material(0xefc44b),
white: material(0xf3f1e8),
dark: material(0x263b40),
teal: material(0x2e7378),
tealDark: material(0x24585d),
glass: material(0x91cbd0, {
roughness: 0.25,
transparent: true,
opacity: 0.38,
depthWrite: false,
}),
bark: material(0x79583d),
leaf: material(0x648d58),
leafLight: material(0x7fa568),
leafDark: material(0x52764d),
coral: material(0xd87361),
coralDark: material(0xa85247),
skin: material(0xc99874),
shirtBlue: material(0x4e7e91),
shirtGold: material(0xd8aa45),
trunk: material(0x60493b),
rain: material(0x88d4dd, {
transparent: true,
opacity: 0.44,
depthWrite: false,
}),
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addBox(
width,
height,
depth,
mat,
x,
y,
z,
options = {},
) {
const mesh = new THREE.Mesh(
unitBox,
typeof mat === "string" ? mats[mat] : mat,
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.rotation.set(
options.rx || 0,
options.ry || 0,
options.rz || 0,
);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
if (options.parent) {
options.parent.add(mesh);
} else {
scene.add(mesh);
}
return mesh;
}
let randomSeed = 92471;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// Diorama base and ground planes.
addBox(27, 1.1, 22, "baseEdge", 0, -0.73, -1.5);
addBox(26.7, 0.22, 21.7, "grass", 0, -0.08, -1.5);
addBox(24, 0.18, 8, "asphalt", 0, 0.02, 4);
addBox(24.2, 0.26, 2.05, "concreteDark", 0, 0.16, -1.02);
// Road edge, lane markings, and a voxel crosswalk.
addBox(24.2, 0.18, 0.22, "asphaltEdge", 0, 0.02, 0.08);
for (let x = -10.5; x <= 10.5; x += 2.7) {
addBox(1.35, 0.025, 0.12, "white", x, 0.125, 4.1, {
cast: false,
});
}
for (let z = 0.75; z < 8; z += 0.72) {
addBox(3.4, 0.025, 0.38, "white", -8.8, 0.125, z, {
cast: false,
});
}
// Sidewalk paving, with gaps for the curb inlet and boarding ramp.
for (let x = -11; x < 11; x += 2) {
for (let z = -1.78; z < -0.08; z += 0.42) {
const overlapsInlet = x > -2.25 && x < -0.15;
const overlapsBoarding = x > 0.15 && x < 4.1;
if (overlapsInlet || overlapsBoarding) continue;
const shade = random() > 0.55 ? "concreteLight" : "concrete";
addBox(1.94, 0.035, 0.38, shade, x, 0.315, z, {
cast: false,
});
}
}
// Boarding forecourt.
for (let x = 0.2; x < 4.1; x += 1.3) {
for (let z = -3.75; z < -2; z += 0.58) {
addBox(1.23, 0.035, 0.52, "concreteLight", x, 0.15, z, {
cast: false,
});
}
}
// Curb, interrupted at the drainage opening.
addBox(10.4, 0.38, 0.28, "curb", -6.8, 0.2, -0.08);
addBox(12.8, 0.38, 0.28, "curb", 5.6, 0.2, -0.08);
// Gutter channel and the first segment of the water route.
addBox(11.9, 0.045, 0.58, "gutter", 4.75, 0.13, 0.5);
addBox(11.9, 0.025, 0.38, "water", 4.75, 0.165, 0.5, {
cast: false,
});
// Stone-lined swale passing west of the boarding area.
addBox(0.78, 0.06, 4.25, "gutter", -1.2, 0.13, -2.15);
addBox(0.78, 0.025, 4.25, "water", -1.2, 0.17, -2.15, {
cast: false,
});
addBox(0.12, 0.23, 4.35, "concreteDark", -1.64, 0.19, -2.15);
addBox(0.12, 0.23, 4.35, "concreteDark", -0.76, 0.19, -2.15);
// Swale continues behind the boarding area toward the basin.
addBox(7.65, 0.06, 0.78, "gutter", 2.62, 0.13, -4.35);
addBox(7.65, 0.025, 0.78, "water", 2.62, 0.17, -4.35, {
cast: false,
});
addBox(7.75, 0.23, 0.12, "concreteDark", 2.62, 0.19, -4.79);
addBox(7.75, 0.23, 0.12, "concreteDark", 2.62, 0.19, -3.91);
// Inlet branch into the planted basin.
addBox(0.78, 0.06, 1.2, "gutter", 6.4, 0.13, -4.95);
addBox(0.78, 0.025, 1.2, "water", 6.4, 0.17, -4.95, {
cast: false,
});
// Curb inlet lip and grate.
addBox(0.92, 0.11, 0.34, "concreteDark", -1.2, 0.18, -0.14);
for (let x = -1.57; x <= -0.83; x += 0.14) {
addBox(0.055, 0.06, 0.32, "dark", x, 0.24, -0.14, {
cast: false,
});
}
// Accessible boarding pad.
addBox(3.45, 0.1, 1.35, "concreteLight", 2, 0.38, -1.1);
addBox(2.65, 0.14, 1.35, "concreteLight", 2, 0.225, -0.18, {
rx: 0.19,
});
// Tactile warning surface at the bottom of the ramp.
for (let x = 0.78; x <= 3.22; x += 0.22) {
for (let z = 0.38; z <= 0.62; z += 0.12) {
addBox(0.12, 0.055, 0.075, "yellow", x, 0.145, z, {
cast: false,
});
}
}
// Ramp side rails.
for (const x of [0.62, 3.38]) {
addBox(0.08, 0.08, 1.45, "tealDark", x, 0.72, -0.18, {
rx: 0.19,
});
for (const z of [-0.65, 0.28]) {
addBox(0.08, 0.72, 0.08, "tealDark", x, 0.49, z);
}
}
// Bus shelter.
const shelter = new THREE.Group();
shelter.position.set(2.55, 0, -2.75);
scene.add(shelter);
addBox(3.45, 0.18, 1.5, "tealDark", 0, 2.35, 0, {
parent: shelter,
});
addBox(3.12, 0.1, 1.18, "teal", 0, 2.23, 0, {
parent: shelter,
});
for (const x of [-1.55, 1.55]) {
for (const z of [-0.62, 0.62]) {
addBox(0.1, 2.08, 0.1, "tealDark", x, 1.17, z, {
parent: shelter,
});
}
}
addBox(3.02, 1.5, 0.055, "glass", 0, 1.25, -0.61, {
parent: shelter,
cast: false,
});
addBox(0.055, 1.5, 1.12, "glass", -1.55, 1.25, 0, {
parent: shelter,
cast: false,
});
addBox(0.055, 1.5, 1.12, "glass", 1.55, 1.25, 0, {
parent: shelter,
cast: false,
});
addBox(2.35, 0.16, 0.48, "tealDark", 0, 0.65, -0.25, {
parent: shelter,
});
addBox(0.12, 0.46, 0.36, "tealDark", -0.88, 0.39, -0.25, {
parent: shelter,
});
addBox(0.12, 0.46, 0.36, "tealDark", 0.88, 0.39, -0.25, {
parent: shelter,
});
// Bus stop sign.
addBox(0.09, 2.2, 0.09, "dark", 0.15, 1.42, -1.35);
addBox(0.72, 0.72, 0.12, "teal", 0.15, 2.34, -1.35);
addBox(0.22, 0.22, 0.14, "white", 0.15, 2.34, -1.28);
addBox(0.36, 0.08, 0.14, "white", 0.15, 2.34, -1.28);
// Planted treatment basin.
addBox(5.8, 0.08, 4.4, "soil", 7.8, 0.13, -7.25);
// Basin retaining edges, with an inlet gap and overflow opening.
addBox(5.8, 0.29, 0.2, "concreteDark", 7.8, 0.22, -9.45);
addBox(1.0, 0.29, 0.2, "concreteDark", 5.4, 0.22, -5.05);
addBox(3.8, 0.29, 0.2, "concreteDark", 8.8, 0.22, -5.05);
addBox(0.2, 0.29, 1.75, "concreteDark", 4.9, 0.22, -8.575);
addBox(0.2, 0.29, 1.75, "concreteDark", 10.7, 0.22, -8.575);
addBox(0.2, 0.29, 0.75, "concreteDark", 10.7, 0.22, -7.075);
// Shallow pooled water in the basin.
addBox(3.25, 0.035, 1.55, "water", 7.4, 0.205, -6.55, {
cast: false,
});
addBox(1.65, 0.035, 0.85, "waterLight", 9.55, 0.207, -7.35, {
cast: false,
});
// Overflow outlet: square voxel headwall and rectangular culvert.
addBox(0.3, 0.3, 1.55, "concrete", 10.72, 0.91, -7.2);
addBox(0.3, 0.3, 1.55, "concrete", 10.72, 0.05, -7.2);
addBox(0.3, 0.6, 0.3, "concrete", 10.72, 0.48, -7.825);
addBox(0.3, 0.6, 0.3, "concrete", 10.72, 0.48, -6.575);
addBox(1.15, 0.18, 1.05, "concreteDark", 11.42, 0.84, -7.2);
addBox(1.15, 0.18, 1.05, "concreteDark", 11.42, 0.12, -7.2);
addBox(1.15, 0.72, 0.16, "concreteDark", 11.42, 0.48, -7.64);
addBox(1.15, 0.72, 0.16, "concreteDark", 11.42, 0.48, -6.76);
addBox(0.08, 0.62, 0.76, "dark", 11.93, 0.48, -7.2);
// Small receiving channel beyond the overflow pipe.
addBox(1.45, 0.08, 0.86, "gutter", 12.48, 0.12, -7.2);
addBox(1.45, 0.025, 0.54, "water", 12.48, 0.175, -7.2, {
cast: false,
});
function addReedCluster(x, z, count = 6) {
for (let i = 0; i < count; i++) {
const offsetX = (random() - 0.5) * 0.65;
const offsetZ = (random() - 0.5) * 0.65;
const height = 0.45 + random() * 0.8;
addBox(
0.055,
height,
0.055,
random() > 0.45 ? "leafLight" : "leafDark",
x + offsetX,
0.2 + height / 2,
z + offsetZ,
{
rz: (random() - 0.5) * 0.28,
rx: (random() - 0.5) * 0.18,
},
);
}
}
[
[5.55, -8.85],
[6.25, -8.6],
[8.85, -8.8],
[9.55, -8.35],
[9.95, -6.0],
[5.35, -6.2],
[8.6, -5.65],
].forEach(([x, z]) => addReedCluster(x, z, 7));
// Low planted berms and voxel shrubs.
const shrubData = [
[5.35, -8.95, "leafDark"],
[8.95, -8.95, "leaf"],
[9.95, -6.05, "leafLight"],
[5.45, -6.25, "leaf"],
[6.05, -9.0, "leafLight"],
[9.45, -8.6, "leafDark"],
];
for (const [x, z, mat] of shrubData) {
addBox(0.58, 0.46, 0.58, mat, x, 0.4, z);
addBox(0.4, 0.35, 0.43, mat, x + 0.08, 0.75, z - 0.04);
}
function addTree(x, z, scale = 1) {
addBox(0.32 * scale, 1.65 * scale, 0.32 * scale, "trunk", x, 0.9, z);
addBox(1.55 * scale, 0.9 * scale, 1.45 * scale, "leafDark", x, 2.1, z);
addBox(1.1 * scale, 0.8 * scale, 1.05 * scale, "leaf", x - 0.12, 2.72, z);
addBox(0.75 * scale, 0.58 * scale, 0.75 * scale, "leafLight", x + 0.2, 3.18, z - 0.08);
}
addTree(-8.5, -5.35, 1.05);
addTree(-4.6, -8.75, 0.9);
addTree(11.2, -10.25, 0.82);
addTree(-9.6, -2.95, 0.72);
// Voxel car on the street.
const car = new THREE.Group();
car.position.set(6.6, 0, 4.75);
scene.add(car);
addBox(2.65, 0.58, 1.18, "coral", 0, 0.62, 0, {
parent: car,
});
addBox(1.42, 0.55, 1.04, "coralDark", -0.12, 1.1, 0, {
parent: car,
});
addBox(1.18, 0.34, 1.065, "dark", -0.12, 1.13, 0, {
parent: car,
});
addBox(1.48, 0.12, 1.1, "coral", -0.12, 1.41, 0, {
parent: car,
});
for (const x of [-0.86, 0.86]) {
for (const z of [-0.63, 0.63]) {
addBox(0.48, 0.48, 0.2, "dark", x, 0.37, z, {
parent: car,
});
}
}
addBox(0.08, 0.18, 0.32, "white", 1.36, 0.68, 0.38, {
parent: car,
});
addBox(0.08, 0.18, 0.32, "white", 1.36, 0.68, -0.38, {
parent: car,
});
function addPerson(x, y, z, shirtMat, facing = 0) {
const person = new THREE.Group();
person.position.set(x, y, z);
person.rotation.y = facing;
scene.add(person);
addBox(0.17, 0.62, 0.2, "dark", -0.12, 0.31, 0, {
parent: person,
});
addBox(0.17, 0.62, 0.2, "dark", 0.12, 0.31, 0, {
parent: person,
});
addBox(0.48, 0.62, 0.28, shirtMat, 0, 0.92, 0, {
parent: person,
});
addBox(0.15, 0.55, 0.17, shirtMat, -0.3, 0.94, 0, {
parent: person,
});
addBox(0.15, 0.55, 0.17, shirtMat, 0.3, 0.94, 0, {
parent: person,
});
addBox(0.32, 0.34, 0.32, "skin", 0, 1.43, 0, {
parent: person,
});
addBox(0.34, 0.11, 0.34, "trunk", 0, 1.61, 0, {
parent: person,
});
}
addPerson(-5.4, 0.34, -1.15, "shirtBlue", -0.4);
addPerson(3.65, 0.43, -1.12, "shirtGold", Math.PI);
// Simple wayfinding markers assembled entirely from boxes.
function addBollard(x, z) {
addBox(0.16, 0.72, 0.16, "tealDark", x, 0.69, z);
addBox(0.18, 0.09, 0.18, "white", x, 0.98, z);
}
[
[-0.1, -1.65],
[4.25, -1.65],
[-0.1, -3.45],
[4.25, -3.45],
].forEach(([x, z]) => addBollard(x, z));
// Streetlight.
addBox(0.13, 3.8, 0.13, "dark", -6.8, 2.2, -1.55);
addBox(1.15, 0.13, 0.13, "dark", -6.25, 4.02, -1.55);
addBox(0.5, 0.14, 0.32, "white", -5.78, 3.92, -1.55);
// World-space labels.
function makeLabel(text, accent = "#1ca9bc") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 112;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(22, 48, 53, 0.92)";
ctx.beginPath();
if (ctx.roundRect) {
ctx.roundRect(4, 4, 632, 104, 22);
} else {
ctx.rect(4, 4, 632, 104);
}
ctx.fill();
ctx.fillStyle = accent;
ctx.fillRect(23, 24, 12, 64);
ctx.fillStyle = "#f4faf7";
ctx.font = "800 31px system-ui, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(text, 56, 57);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
}),
);
sprite.scale.set(4.15, 0.73, 1);
sprite.renderOrder = 20;
return sprite;
}
const labels = [
{ text: "ACCESSIBLE BOARDING", pos: [2.65, 3.25, -2.6], color: "#e9b948" },
{ text: "CURB INLET", pos: [-1.2, 1.02, -0.15], color: "#24b5ca" },
{ text: "PLANTED BASIN", pos: [7.55, 1.55, -8.65], color: "#7ca56d" },
{ text: "OVERFLOW OUTLET", pos: [11.25, 1.48, -7.25], color: "#7fa8ad" },
];
for (const item of labels) {
const sprite = makeLabel(item.text, item.color);
sprite.position.set(...item.pos);
scene.add(sprite);
}
// Route used by the animated water blocks.
const routePoints = [
new THREE.Vector3(10.7, 0.205, 0.5),
new THREE.Vector3(-1.2, 0.205, 0.5),
new THREE.Vector3(-1.2, 0.21, -4.35),
new THREE.Vector3(6.4, 0.21, -4.35),
new THREE.Vector3(6.4, 0.235, -5.45),
];
const routeSegments = [];
let routeLength = 0;
for (let i = 0; i < routePoints.length - 1; i++) {
const start = routePoints[i];
const end = routePoints[i + 1];
const length = start.distanceTo(end);
routeSegments.push({ start, end, length, offset: routeLength });
routeLength += length;
}
function sampleRoute(distance) {
const d = ((distance % routeLength) + routeLength) % routeLength;
for (const segment of routeSegments) {
if (d <= segment.offset + segment.length) {
const t = (d - segment.offset) / segment.length;
return new THREE.Vector3().lerpVectors(
segment.start,
segment.end,
t,
);
}
}
return routePoints[routePoints.length - 1].clone();
}
// Moving voxels make the drainage path easy to follow.
const flowCount = 46;
const flowMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.16, 0.075, 0.16),
mats.waterLight,
flowCount,
);
flowMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
flowMesh.frustumCulled = false;
scene.add(flowMesh);
const dummy = new THREE.Object3D();
// Sparse stylized rain.
const rainCount = 42;
const rainMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.035, 0.42, 0.035),
mats.rain,
rainCount,
);
rainMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
rainMesh.frustumCulled = false;
scene.add(rainMesh);
const rainData = Array.from({ length: rainCount }, () => ({
x: -12 + random() * 24,
z: -9 + random() * 17,
phase: random() * 10,
speed: 5.5 + random() * 3.5,
}));
// Overflow droplets leaving the culvert.
const overflowDrops = [];
for (let i = 0; i < 9; i++) {
const drop = addBox(
0.13,
0.11,
0.13,
"waterLight",
11.9 + i * 0.11,
0.32,
-7.2,
{ cast: false },
);
overflowDrops.push(drop);
}
let paused = false;
let elapsed = 0;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta;
for (let i = 0; i < flowCount; i++) {
const distance = elapsed * 2.2 + (i * routeLength) / flowCount;
const position = sampleRoute(distance);
const pulse = 1 + Math.sin(elapsed * 5 + i) * 0.12;
dummy.position.copy(position);
dummy.scale.set(pulse, 1, pulse);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
flowMesh.setMatrixAt(i, dummy.matrix);
}
flowMesh.instanceMatrix.needsUpdate = true;
for (let i = 0; i < rainCount; i++) {
const data = rainData[i];
const y = 0.35 + ((data.phase + elapsed * data.speed) % 11.5);
dummy.position.set(data.x, y, data.z);
dummy.scale.set(1, 0.75 + (y / 12) * 0.5, 1);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
rainMesh.setMatrixAt(i, dummy.matrix);
}
rainMesh.instanceMatrix.needsUpdate = true;
overflowDrops.forEach((drop, i) => {
const t = (elapsed * 1.45 + i / overflowDrops.length) % 1;
drop.position.x = 11.9 + t * 1.25;
drop.position.y = 0.3 - t * 0.13 + Math.sin(i * 2.1) * 0.025;
const scale = 0.75 + Math.sin(t * Math.PI) * 0.5;
drop.scale.set(scale, scale, scale);
});
renderer.render(scene, camera);
}
animate();
// Direct camera controls, implemented without external addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + dy * 0.005,
0.42,
1.38,
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.9,
);
updateCamera();
},
{ passive: false },
);
document.getElementById("pauseButton").addEventListener("click", (event) => {
paused = !paused;
event.currentTarget.textContent = paused ? "Resume water" : "Pause water";
});
document.getElementById("resetButton").addEventListener("click", () => {
cameraTheta = 0.62;
cameraPhi = 0.91;
cameraZoom = 1;
updateCamera();
});
</script>
</body>
</html>
```