Prompt specification
Build or customize the Three.js 3D scene "School Rainwater Garden Diorama" 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: School Rainwater Garden Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/school-rainwater-garden-diorama-x3955
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: school rainwater garden diorama. Build an original school courtyard with roof collection, storage, and garden irrigation. Separate the schematic nonpotable system from drinking-water supply and avoid claiming treatment adequacy. Return one self-contained HTML file.
Working Three.js Starter (school-rainwater-garden-diorama-x3955):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel School Courtyard — Rainwater Garden Diorama</title>
<style>
:root {
--ink: #173149;
--muted: #557086;
--paper: rgba(248, 252, 250, 0.94);
--line: rgba(23, 49, 73, 0.15);
--nonpotable: #078bc2;
--potable: #ef7b32;
--garden: #3d9a64;
--shadow: 0 12px 35px rgba(27, 55, 71, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9dfea;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#app, #labels {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
position: absolute;
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--nonpotable);
box-shadow: 15px 0 0 var(--potable);
margin-right: 15px;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1.03;
letter-spacing: -0.04em;
}
#title-card p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 12px;
padding: 6px 9px;
border-radius: 999px;
background: #e5f3ef;
color: #27644c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#legend {
position: absolute;
top: 20px;
right: 20px;
width: 248px;
padding: 15px 16px;
border-radius: 16px;
}
.legend-title {
margin-bottom: 10px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--muted);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 8px 0;
font-size: 12px;
font-weight: 650;
}
.swatch {
flex: 0 0 auto;
width: 23px;
height: 8px;
border-radius: 2px;
background: var(--nonpotable);
}
.swatch.potable { background: var(--potable); }
.swatch.garden { background: var(--garden); }
.swatch.tank {
width: 14px;
height: 14px;
border-radius: 3px;
background: #b8e9f6;
border: 2px solid var(--nonpotable);
}
#detail-card {
position: absolute;
left: 20px;
bottom: 82px;
width: min(390px, calc(100vw - 40px));
padding: 15px 17px 14px;
border-radius: 16px;
}
#detail-kicker {
color: var(--nonpotable);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#detail-title {
margin: 4px 0 6px;
font-size: 17px;
letter-spacing: -0.02em;
}
#detail-copy {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.48;
}
#disclaimer {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #5b6670;
font-size: 10.5px;
line-height: 1.42;
}
#toolbar {
position: absolute;
left: 50%;
bottom: 18px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 15px;
transform: translateX(-50%);
pointer-events: auto;
}
.tool-button {
min-width: 78px;
padding: 9px 12px;
border: 0;
border-radius: 10px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
.tool-button:hover {
background: #e9f1f2;
transform: translateY(-1px);
}
.tool-button.active {
background: var(--ink);
color: white;
}
#labels {
z-index: 5;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
max-width: 210px;
padding: 8px 10px 8px 8px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 11px;
background: rgba(250, 253, 251, 0.93);
box-shadow: 0 7px 18px rgba(25, 48, 65, 0.18);
color: var(--ink);
cursor: pointer;
pointer-events: auto;
transform: translate(-50%, -100%);
text-align: left;
transition: opacity 150ms ease, background 150ms ease, transform 150ms ease;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 2px;
height: 6px;
background: rgba(23, 49, 73, 0.45);
}
.world-label:hover,
.world-label.active {
background: #ffffff;
transform: translate(-50%, calc(-100% - 3px));
}
.label-number {
display: grid;
place-items: center;
flex: 0 0 auto;
width: 25px;
height: 25px;
border-radius: 7px;
background: #d9f0f6;
color: #0579a7;
font-size: 10px;
font-weight: 900;
}
.world-label.potable .label-number {
background: #ffeadf;
color: #c85d1d;
}
.world-label strong {
display: block;
font-size: 10px;
line-height: 1.1;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.world-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #b9dfea;
color: var(--ink);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#loading span {
padding: 14px 18px;
border-radius: 12px;
background: rgba(255,255,255,.72);
box-shadow: var(--shadow);
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
#title-card p { display: none; }
.badge { margin-top: 9px; }
#legend {
top: 126px;
right: 12px;
width: 205px;
padding: 11px 12px;
}
.legend-row { margin: 6px 0; font-size: 10px; }
.legend-title { margin-bottom: 6px; }
#detail-card {
left: 12px;
bottom: 74px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
#detail-copy { display: none; }
#disclaimer { font-size: 9px; margin-top: 7px; padding-top: 7px; }
#toolbar { bottom: 10px; }
.tool-button { min-width: 64px; padding: 8px 9px; font-size: 10px; }
.world-label { max-width: 155px; }
.world-label small { display: none; }
}
</style>
</head>
<body>
<div id="app"></div>
<div id="labels"></div>
<div id="hud">
<section id="title-card" class="panel">
<div class="eyebrow">Cedar Commons School</div>
<h1>Courtyard Water Lab</h1>
<p>
An original voxel diorama tracing roof collection, nonpotable storage,
transfer, and school-garden irrigation.
</p>
<div class="badge">Conceptual schematic · not a treatment design</div>
</section>
<section id="legend" class="panel">
<div class="legend-title">Water-system key</div>
<div class="legend-row"><span class="swatch"></span>Nonpotable collection / irrigation</div>
<div class="legend-row"><span class="swatch potable"></span>Independent potable supply</div>
<div class="legend-row"><span class="swatch garden"></span>Planted rain garden</div>
<div class="legend-row"><span class="swatch tank"></span>Schematic storage vessel</div>
</section>
<section id="detail-card" class="panel">
<div id="detail-kicker">System reading</div>
<h2 id="detail-title">A separated, color-coded water loop</h2>
<p id="detail-copy">
Select a numbered marker to inspect the courtyard system. Blue identifies
the roof-water and nonpotable branch; orange identifies the independent
drinking-water supply.
</p>
<div id="disclaimer">
Concept only: this model does not demonstrate treatment adequacy,
regulatory compliance, hydraulic performance, or suitability for any
potable use. The potable and nonpotable systems are not connected.
</div>
</section>
<nav id="toolbar" class="panel" aria-label="Diorama controls">
<button id="rain-button" class="tool-button active" aria-pressed="true">Rain</button>
<button id="flow-button" class="tool-button active" aria-pressed="true">Flow</button>
<button id="labels-button" class="tool-button active" aria-pressed="true">Labels</button>
<button id="reset-button" class="tool-button">Reset view</button>
</nav>
</div>
<div id="loading"><span>Building the courtyard…</span></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const labelsLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9dfea);
scene.fog = new THREE.Fog(0xb9dfea, 48, 88);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const cameraState = {
target: new THREE.Vector3(-0.4, 2.1, 0),
yaw: 0.64,
pitch: 0.54,
radius: 38
};
const defaultView = {
target: cameraState.target.clone(),
yaw: cameraState.yaw,
pitch: cameraState.pitch,
radius: cameraState.radius
};
function updateCamera() {
const { target, yaw, pitch, radius } = cameraState;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xe9f8ff, 0x758257, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.0);
sun.position.set(-16, 28, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ed8f0, 0.75);
fill.position.set(20, 12, -18);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
});
const M = {
base: material(0x263b49),
baseEdge: material(0x3d5661),
grass: material(0x76aa63),
grassLight: material(0x87b86e),
grassDark: material(0x5f9258),
path: material(0xd6c8a6),
pathDark: material(0xb9a985),
wall: material(0xf0dfbb),
wallShade: material(0xdcc9a5),
roof: material(0x4d6574),
roofLight: material(0x607b86),
navy: material(0x173149),
window: material(0x74c9e5, { roughness: 0.35, metalness: 0.08 }),
windowDark: material(0x2c5970),
door: material(0x247d83),
brick: material(0xb96f52),
blue: material(0x078bc2, { roughness: 0.55 }),
blueLight: material(0x65d1ed),
blueDark: material(0x155f84),
orange: material(0xef7b32, { roughness: 0.58 }),
white: material(0xf5f4e9),
metal: material(0x8b9aa0, { roughness: 0.52, metalness: 0.22 }),
darkMetal: material(0x3d515a),
tankGlass: material(0x72cae4, {
transparent: true,
opacity: 0.38,
depthWrite: false,
roughness: 0.25
}),
tankWater: material(0x24a9d2, {
transparent: true,
opacity: 0.72,
depthWrite: false,
roughness: 0.28
}),
soil: material(0x654636),
soilLight: material(0x76543b),
mulch: material(0x4b382c),
green: material(0x3d9a64),
greenLight: material(0x73b85c),
greenDark: material(0x2d704d),
leaf: material(0x4e9857),
leafLight: material(0x79b85f),
wood: material(0x9a6843),
woodDark: material(0x70492f),
stone: material(0x9ca39d),
stoneLight: material(0xc0c3b7),
water: material(0x4eb7cf, {
transparent: true,
opacity: 0.66,
depthWrite: false,
roughness: 0.22
}),
rain: material(0x8bdcf2, {
transparent: true,
opacity: 0.72,
depthWrite: false
}),
skin: material(0xd99b72),
skin2: material(0x8b5b3f),
hair: material(0x322b2a),
shirt: material(0xe26d4f),
shirt2: material(0x4b8fa3),
pants: material(0x30455b),
backpack: material(0xe0a63b)
};
function box(w, h, d, x, y, z, mat, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(a, b, width, mat, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = box(width, length, width, 0, 0, 0, mat, parent);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeSign(text, sub, width, height, bg = "#173149", fg = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(255,255,255,.10)";
for (let x = 0; x < 1024; x += 64) {
ctx.fillRect(x, 0, 8, 256);
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = fg;
ctx.font = "800 66px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(text, 512, sub ? 103 : 128, 940);
if (sub) {
ctx.fillStyle = "#9edcf0";
ctx.font = "700 28px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(sub, 512, 181, 920);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.castShadow = false;
scene.add(mesh);
return mesh;
}
// Diorama plinth and campus ground.
box(36, 1.25, 24, 0, -0.72, 0, M.base);
box(36.25, 0.22, 24.25, 0, -0.13, 0, M.baseEdge);
box(35.4, 0.18, 23.4, 0, 0.02, 0, M.grass);
// Stepped voxel lawn patches.
box(5.4, 0.08, 5.1, -12.8, 0.13, 5.0, M.grassLight);
box(4.2, 0.08, 3.7, -3.7, 0.13, 8.2, M.grassDark);
box(3.0, 0.08, 2.4, 15.3, 0.13, -7.7, M.grassLight);
// Courtyard paving.
box(5.2, 0.12, 12.2, -6.5, 0.12, 3.0, M.path);
box(11.2, 0.12, 2.5, -7.0, 0.12, -0.5, M.path);
box(2.4, 0.12, 4.5, -2.8, 0.12, 5.6, M.path);
box(18.0, 0.12, 1.6, -8.0, 0.12, -0.2, M.pathDark);
// Paving seams.
for (let z = -2.6; z < 9.3; z += 1.35) {
box(5.0, 0.018, 0.035, -6.5, 0.19, z, M.pathDark);
}
// School building.
box(14, 8, 8, -7, 4, -6, M.wall);
box(14.25, 0.3, 8.25, -7, 0.25, -6, M.wallShade);
box(14.1, 0.25, 8.1, -7, 2.55, -6, M.brick);
box(14.05, 0.16, 8.05, -7, 6.85, -6, M.wallShade);
// Roof and parapets.
box(15.0, 0.46, 9.0, -7, 8.27, -6, M.roof);
box(14.6, 0.12, 8.6, -7, 8.55, -6, M.roofLight);
box(15.0, 0.55, 0.28, -7, 8.75, -10.35, M.wallShade);
box(15.0, 0.55, 0.28, -7, 8.75, -1.65, M.wallShade);
box(0.28, 0.55, 8.7, -14.35, 8.75, -6, M.wallShade);
box(0.28, 0.55, 8.7, 0.35, 8.75, -6, M.wallShade);
// Front windows.
function frontWindow(x, y, w = 1.8, h = 2.0) {
box(w + 0.18, h + 0.18, 0.16, x, y, -1.92, M.navy);
box(w, h, 0.08, x, y, -1.81, M.window);
box(0.07, h, 0.11, x, y, -1.74, M.white);
box(w, 0.07, 0.11, x, y - 0.12, -1.74, M.white);
box(w + 0.28, 0.16, 0.34, x, y - h / 2 - 0.15, -1.78, M.wallShade);
}
frontWindow(-12.0, 4.7);
frontWindow(-9.1, 4.7);
frontWindow(-3.6, 4.7);
frontWindow(-1.5, 4.7);
// Entrance.
box(3.1, 3.4, 0.28, -7, 1.85, -1.88, M.navy);
box(2.75, 3.05, 0.16, -7, 1.85, -1.70, M.door);
box(1.06, 1.05, 0.09, -7.65, 2.45, -1.59, M.window);
box(1.06, 1.05, 0.09, -6.35, 2.45, -1.59, M.window);
box(0.08, 0.42, 0.10, -6.73, 1.55, -1.56, M.white);
box(0.08, 0.42, 0.10, -7.27, 1.55, -1.56, M.white);
box(4.2, 0.22, 1.5, -7, 0.16, -1.35, M.pathDark);
// Side windows.
function sideWindow(z, y) {
box(0.16, 2.15, 2.0, 0.08, y, z, M.navy);
box(0.08, 1.78, 1.65, 0.18, y, z, M.window);
box(0.11, 1.8, 0.07, 0.25, y, z, M.white);
box(0.11, 0.07, 1.68, 0.25, y - 0.1, z, M.white);
}
sideWindow(-8.5, 4.7);
sideWindow(-4.4, 4.7);
const schoolSign = makeSign(
"CEDAR COMMONS",
"ELEMENTARY SCHOOL",
7.4,
1.65,
"#173149",
"#fff8df"
);
schoolSign.position.set(-7, 6.35, -1.71);
// Roof gutter and downpipe, colored as the nonpotable collection route.
box(14.9, 0.18, 0.24, -7, 8.60, -1.39, M.blue);
beam([0.20, 8.60, -1.39], [0.20, 0.68, -1.39], 0.18, M.blue);
beam([0.20, 0.68, -1.39], [1.00, 0.68, -1.39], 0.18, M.blue);
box(0.30, 0.30, 0.30, 0.20, 0.68, -1.39, M.blueDark);
// Storage vessel: intentionally a schematic, nonpotable-only tank.
box(5.1, 0.22, 4.0, 3.0, 0.18, -1.4, M.pathDark);
const tankShell = box(4.0, 3.2, 3.0, 3.0, 1.92, -1.4, M.tankGlass);
tankShell.castShadow = false;
const tankWater = box(3.62, 1.55, 2.62, 3.0, 1.37, -1.4, M.tankWater);
tankWater.castShadow = false;
// Tank frame.
for (const x of [0.93, 5.07]) {
for (const z of [-2.97, 0.17]) {
box(0.13, 3.35, 0.13, x, 1.92, z, M.blueDark);
}
}
box(4.25, 0.16, 3.18, 3.0, 3.58, -1.4, M.blueDark);
box(4.25, 0.16, 3.18, 3.0, 0.29, -1.4, M.blueDark);
box(0.15, 2.2, 0.10, 5.18, 1.85, 0.18, M.white);
box(0.10, 0.44, 0.12, 5.25, 1.54, 0.22, M.orange);
const tankSign = makeSign(
"NONPOTABLE",
"STORAGE ONLY",
3.2,
0.78,
"#155f84",
"#ffffff"
);
tankSign.position.set(3.0, 2.65, 0.17);
// Schematic transfer device, not represented as treatment equipment.
box(1.65, 0.18, 1.25, 5.95, 0.25, -1.4, M.pathDark);
box(0.95, 0.72, 0.78, 5.75, 0.72, -1.4, M.green);
box(0.38, 0.40, 0.90, 6.34, 0.72, -1.4, M.darkMetal);
box(0.60, 0.18, 0.55, 5.65, 1.18, -1.4, M.greenLight);
// Blue nonpotable pipework: tank to pump and irrigation.
beam([5.03, 0.68, -1.4], [5.35, 0.68, -1.4], 0.17, M.blue);
beam([6.45, 0.68, -1.4], [6.80, 0.68, -1.4], 0.17, M.blue);
beam([6.80, 0.68, -1.4], [6.80, 0.68, 0.65], 0.17, M.blue);
beam([6.80, 0.68, 0.65], [7.20, 0.68, 0.65], 0.17, M.blue);
beam([7.20, 0.68, 0.65], [7.20, 0.68, 6.95], 0.14, M.blue);
beam([7.20, 0.68, 3.15], [8.25, 0.68, 3.15], 0.14, M.blue);
beam([7.20, 0.68, 7.85], [10.4, 0.68, 7.85], 0.12, M.blue);
beam([7.20, 0.68, 8.35], [14.7, 0.68, 8.35], 0.12, M.blue);
// Independent orange potable branch and a drinking fountain.
box(8.2, 0.06, 0.50, -13.2, 0.20, -0.55, M.darkMetal);
beam([-17.4, 0.40, -0.55], [-9.10, 0.40, -0.55], 0.16, M.orange);
beam([-9.10, 0.40, -0.55], [-9.10, 1.10, -0.55], 0.16, M.orange);
box(0.85, 0.95, 0.65, -9.1, 0.66, -0.55, M.metal);
box(1.10, 0.18, 0.82, -9.1, 1.23, -0.55, M.white);
box(0.95, 0.16, 0.65, -9.1, 1.35, -0.55, M.white);
box(0.08, 0.32, 0.08, -9.1, 1.47, -0.18, M.orange);
box(0.38, 0.08, 0.10, -9.1, 1.61, -0.22, M.orange);
const potableMarker = makeSign(
"POTABLE",
"MUNICIPAL SUPPLY",
1.55,
0.54,
"#ef7b32",
"#ffffff"
);
potableMarker.position.set(-16.6, 1.55, -0.52);
potableMarker.rotation.y = 0.25;
box(0.12, 1.50, 0.12, -16.6, 0.83, -0.52, M.metal);
// Rain-garden basin, visibly lower than the surrounding lawn blocks.
box(8.5, 0.10, 5.7, 11.0, 0.15, 3.2, M.soil);
box(6.1, 0.07, 3.7, 11.0, 0.23, 3.15, M.water);
// Raised lawn edges around the planted basin.
box(1.1, 0.30, 6.2, 6.55, 0.24, 3.2, M.grassLight);
box(1.1, 0.30, 6.2, 15.45, 0.24, 3.2, M.grassLight);
box(7.8, 0.30, 0.65, 11.0, 0.24, 0.05, M.grassLight);
box(7.8, 0.30, 0.65, 11.0, 0.24, 6.35, M.grassLight);
// Basin stones.
const stonePositions = [
[7.0,0.35,1.0], [7.6,0.34,1.6], [8.3,0.35,1.0], [8.8,0.34,1.7],
[13.0,0.34,1.1], [13.8,0.35,1.7], [14.6,0.34,1.2],
[7.2,0.34,5.3], [8.0,0.35,5.7], [13.4,0.34,5.6], [14.5,0.34,5.1]
];
stonePositions.forEach(([x,y,z], i) => {
const s = box(0.55 + (i % 3) * 0.12, 0.42, 0.48, x, y, z,
i % 2 ? M.stoneLight : M.stone);
s.rotation.y = (i * 0.71) % 1.2;
});
// Rain-garden plants, using voxel stems and leaf clusters.
function reed(x, z, height = 1.25, color = M.greenDark) {
box(0.10, height, 0.10, x, 0.25 + height / 2, z, M.greenDark);
box(0.48, 0.22, 0.22, x, 0.25 + height, z, color);
box(0.24, 0.34, 0.18, x + 0.13, 0.25 + height * 0.72, z, M.greenLight);
}
[
[7.5,1.2],[8.0,1.9],[9.0,1.0],[9.5,1.8],[12.3,1.2],[13.2,1.8],
[14.0,1.1],[7.6,5.1],[8.6,5.5],[12.7,5.2],[13.8,5.4],[14.4,4.7]
].forEach(([x,z], i) => reed(x, z, 0.85 + (i % 4) * 0.18,
i % 2 ? M.green : M.greenDark));
// Raised garden beds.
function raisedBed(cx, cz, w, d) {
box(w, 0.55, 0.18, cx, 0.43, cz - d / 2, M.wood);
box(w, 0.55, 0.18, cx, 0.43, cz + d / 2, M.wood);
box(0.18, 0.55, d, cx - w / 2, 0.43, cz, M.woodDark);
box(0.18, 0.55, d, cx + w / 2, 0.43, cz, M.woodDark);
box(w - 0.3, 0.22, d - 0.3, cx, 0.34, cz, M.mulch);
for (let i = 0; i < 6; i++) {
const px = cx - w / 2 + 0.55 + i * ((w - 1.1) / 5);
box(0.12, 0.55, 0.12, px, 0.72, cz, M.greenDark);
box(0.48, 0.48, 0.48, px, 1.05, cz, i % 2 ? M.greenLight : M.green);
box(0.38, 0.30, 0.38, px + 0.13, 1.36, cz, M.greenLight);
}
}
raisedBed(9.25, 7.85, 4.2, 1.65);
raisedBed(13.45, 7.85, 4.2, 1.65);
// Drip branches visible on the soil.
beam([7.25,0.73,7.45], [10.95,0.73,7.45], 0.055, M.blueLight);
beam([7.25,0.73,8.15], [10.95,0.73,8.15], 0.055, M.blueLight);
beam([11.45,0.73,7.45], [15.15,0.73,7.45], 0.055, M.blueLight);
beam([11.45,0.73,8.15], [15.15,0.73,8.15], 0.055, M.blueLight);
const gardenSign = makeSign(
"RAIN GARDEN",
"PLANTED STORMWATER AREA",
2.5,
0.68,
"#2d704d",
"#ffffff"
);
gardenSign.position.set(14.7, 1.15, 5.85);
box(0.10, 1.15, 0.10, 14.7, 0.63, 5.85, M.woodDark);
// Voxel tree.
function tree(x, z, scale = 1) {
const trunk = box(0.42 * scale, 2.4 * scale, 0.42 * scale,
x, 0.2 + 1.2 * scale, z, M.woodDark);
trunk.rotation.y = 0.08;
const clusters = [
[0,2.9,0,2.1,1.55,1.8],
[-0.85,2.55,0.15,1.6,1.35,1.45],
[0.8,2.6,0.10,1.7,1.45,1.5],
[0.10,2.65,-0.75,1.55,1.25,1.35],
[0.1,3.7,0.05,1.65,1.25,1.55]
];
clusters.forEach(([dx,y,dz,w,h,d], i) => {
box(w * scale, h * scale, d * scale,
x + dx * scale, 0.2 + y * scale, z + dz * scale,
i % 2 ? M.leaf : M.leafLight);
});
}
tree(-13.3, 5.2, 1.08);
tree(15.4, -5.9, 0.95);
tree(-15.1, -9.0, 0.80);
// Shrub clusters.
[
[-10.9,8.7],[-9.8,9.4],[-3.1,8.8],[4.7,-7.2],
[6.1,-8.4],[14.6,-2.0],[2.8,9.4]
].forEach(([x,z], i) => {
box(0.8, 0.65, 0.8, x, 0.43, z, i % 2 ? M.green : M.greenDark);
box(0.55, 0.5, 0.55, x + 0.35, 0.65, z - 0.2, M.greenLight);
});
// Benches and planters.
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(2.5, 0.16, 0.65, 0, 0.70, 0, M.wood, group);
box(2.5, 0.60, 0.14, 0, 1.08, -0.30, M.wood, group);
box(0.16, 0.65, 0.55, -0.95, 0.35, 0, M.darkMetal, group);
box(0.16, 0.65, 0.55, 0.95, 0.35, 0, M.darkMetal, group);
}
bench(-10.4, 2.1, 0);
bench(-2.7, 3.9, Math.PI / 2);
// Flag and small schoolyard details.
box(0.13, 4.2, 0.13, -15.5, 2.15, -1.5, M.metal);
box(1.25, 0.75, 0.10, -14.88, 3.63, -1.5, M.door);
// Trash/recycling bins use neutral colors to avoid water-system confusion.
box(0.8, 1.15, 0.75, -0.9, 0.68, -0.5, M.darkMetal);
box(0.85, 0.13, 0.80, -0.9, 1.29, -0.5, M.white);
// Voxel people.
function person(x, z, shirtMat, skinMat, scale = 1, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.22, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
box(0.23, 0.72, 0.26, -0.17, 0.36, 0, M.pants, group);
box(0.23, 0.72, 0.26, 0.17, 0.36, 0, M.pants, group);
box(0.24, 0.15, 0.42, -0.17, 0.04, 0.06, M.navy, group);
box(0.24, 0.15, 0.42, 0.17, 0.04, 0.06, M.navy, group);
box(0.72, 0.78, 0.40, 0, 1.10, 0, shirtMat, group);
box(0.20, 0.68, 0.22, -0.48, 1.08, 0, shirtMat, group);
box(0.20, 0.68, 0.22, 0.48, 1.08, 0, shirtMat, group);
box(0.52, 0.54, 0.48, 0, 1.82, 0, skinMat, group);
box(0.56, 0.19, 0.52, 0, 2.05, 0.02, M.hair, group);
box(0.60, 0.36, 0.12, 0, 1.88, 0.25, M.hair, group);
}
person(-7.2, 3.1, M.shirt, M.skin, 0.92, 0.35);
person(-5.5, 4.2, M.shirt2, M.skin2, 0.83, -0.35);
person(7.9, 5.7, M.backpack, M.skin, 0.78, 0.8);
// Schematic animated flow paths.
const flowPaths = [];
const flowBeads = [];
function addFlowPath(points, colorMat, count = 7) {
const path = points.map(p => new THREE.Vector3(...p));
const lengths = [];
let total = 0;
for (let i = 0; i < path.length - 1; i++) {
const length = path[i].distanceTo(path[i + 1]);
lengths.push(length);
total += length;
}
const beads = [];
for (let i = 0; i < count; i++) {
const bead = box(0.15, 0.15, 0.15, 0, 0, 0, colorMat);
bead.castShadow = false;
beads.push(bead);
}
flowPaths.push({ path, lengths, total });
flowBeads.push(beads);
}
function sampleFlowPath(pathData, t) {
let distance = ((t % 1) + 1) % 1 * pathData.total;
for (let i = 0; i < pathData.lengths.length; i++) {
if (distance <= pathData.lengths[i]) {
const u = distance / pathData.lengths[i];
return pathData.path[i].clone().lerp(pathData.path[i + 1], u);
}
distance -= pathData.lengths[i];
}
return pathData.path[pathData.path.length - 1].clone();
}
addFlowPath([
[-12.5,8.69,-1.38],
[0.20,8.69,-1.38],
[0.20,0.72,-1.38],
[1.00,0.72,-1.38],
[1.25,1.35,-1.40]
], M.blueLight, 8);
addFlowPath([
[4.95,0.70,-1.40],
[5.75,0.70,-1.40],
[6.80,0.70,-1.40],
[6.80,0.70,0.65],
[7.20,0.70,0.65],
[7.20,0.70,3.15],
[8.25,0.70,3.15]
], M.blueLight, 9);
addFlowPath([
[-17.35,0.43,-0.55],
[-9.10,0.43,-0.55],
[-9.10,1.10,-0.55]
], M.orange, 5);
// Rain as an instanced voxel system.
const rainCount = 150;
const rainGeometry = new THREE.BoxGeometry(0.045, 0.48, 0.045);
const rainMesh = new THREE.InstancedMesh(rainGeometry, M.rain, rainCount);
rainMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
rainMesh.frustumCulled = false;
scene.add(rainMesh);
const raindrops = [];
for (let i = 0; i < rainCount; i++) {
raindrops.push({
x: -17.5 + Math.random() * 35,
y: 1.0 + Math.random() * 18,
z: -10.8 + Math.random() * 21.6,
speed: 6.5 + Math.random() * 5.5
});
}
const rainDummy = new THREE.Object3D();
let rainOn = true;
let flowOn = true;
let labelsVisible = true;
// World-space HTML markers.
const detailData = {
roof: {
kicker: "01 · Collection",
title: "Roof catchment, gutter, and downpipe",
copy:
"Rain is shown falling on the school roof, entering the front gutter, " +
"and moving through a downpipe toward the storage vessel."
},
storage: {
kicker: "02 · Storage",
title: "Nonpotable rainwater storage",
copy:
"The tank is a schematic storage vessel assigned only to the blue " +
"nonpotable branch. No treatment performance is implied."
},
pump: {
kicker: "03 · Transfer",
title: "Schematic transfer to the garden line",
copy:
"A transfer device is shown between storage and irrigation. It is " +
"not represented as a treatment device."
},
garden: {
kicker: "04 · Use",
title: "School-garden irrigation",
copy:
"The blue branch supplies visible drip lines to the raised garden beds " +
"and the planted rain-garden area."
},
potable: {
kicker: "Independent branch",
title: "Drinking-water supply stays separate",
copy:
"The orange municipal branch remains physically separate and serves " +
"the drinking fountain. It is not connected to stored roof water."
}
};
const labelDefinitions = [
{
key: "roof",
number: "01",
title: "Roof collection",
sub: "gutter + downpipe",
position: new THREE.Vector3(-8.5, 10.1, -5.0),
focus: new THREE.Vector3(-7, 4.0, -5.8),
radius: 25
},
{
key: "storage",
number: "02",
title: "Rain storage",
sub: "nonpotable only",
position: new THREE.Vector3(3.0, 4.35, -1.4),
focus: new THREE.Vector3(3.0, 1.6, -1.4),
radius: 19
},
{
key: "pump",
number: "03",
title: "Transfer",
sub: "schematic pump",
position: new THREE.Vector3(5.9, 2.0, -1.35),
focus: new THREE.Vector3(5.8, 0.8, -1.3),
radius: 16
},
{
key: "garden",
number: "04",
title: "Garden irrigation",
sub: "drip branches",
position: new THREE.Vector3(11.2, 2.65, 3.5),
focus: new THREE.Vector3(10.7, 0.8, 4.1),
radius: 22
},
{
key: "potable",
number: "P",
title: "Potable supply",
sub: "independent branch",
position: new THREE.Vector3(-14.3, 1.8, -0.55),
focus: new THREE.Vector3(-12.0, 0.8, -0.5),
radius: 20,
potable: true
}
];
const labels = labelDefinitions.map(def => {
const button = document.createElement("button");
button.className = "world-label" + (def.potable ? " potable" : "");
button.type = "button";
button.innerHTML = `
<span class="label-number">${def.number}</span>
<span><strong>${def.title}</strong><small>${def.sub}</small></span>
`;
button.addEventListener("click", () => focusDefinition(def));
labelsLayer.appendChild(button);
return { def, element: button };
});
const detailKicker = document.getElementById("detail-kicker");
const detailTitle = document.getElementById("detail-title");
const detailCopy = document.getElementById("detail-copy");
function focusDefinition(def) {
const info = detailData[def.key];
detailKicker.textContent = info.kicker;
detailTitle.textContent = info.title;
detailCopy.textContent = info.copy;
labels.forEach(item => {
item.element.classList.toggle("active", item.def.key === def.key);
});
cameraState.target.copy(def.focus);
cameraState.radius = def.radius;
cameraState.yaw = def.key === "roof" ? 0.45 : 0.64;
cameraState.pitch = def.key === "roof" ? 0.48 : 0.53;
}
function updateDetailDefault() {
detailKicker.textContent = "System reading";
detailTitle.textContent = "A separated, color-coded water loop";
detailCopy.textContent =
"Select a numbered marker to inspect the courtyard system. Blue identifies " +
"the roof-water and nonpotable branch; orange identifies the independent " +
"drinking-water supply.";
labels.forEach(item => item.element.classList.remove("active"));
}
// Toolbar.
const rainButton = document.getElementById("rain-button");
const flowButton = document.getElementById("flow-button");
const labelsButton = document.getElementById("labels-button");
const resetButton = document.getElementById("reset-button");
rainButton.addEventListener("click", () => {
rainOn = !rainOn;
rainButton.classList.toggle("active", rainOn);
rainButton.setAttribute("aria-pressed", String(rainOn));
});
flowButton.addEventListener("click", () => {
flowOn = !flowOn;
flowButton.classList.toggle("active", flowOn);
flowButton.setAttribute("aria-pressed", String(flowOn));
});
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsLayer.style.display = labelsVisible ? "block" : "none";
labelsButton.classList.toggle("active", labelsVisible);
labelsButton.setAttribute("aria-pressed", String(labelsVisible));
});
resetButton.addEventListener("click", () => {
cameraState.target.copy(defaultView.target);
cameraState.yaw = defaultView.yaw;
cameraState.pitch = defaultView.pitch;
cameraState.radius = defaultView.radius;
updateDetailDefault();
});
// Direct camera controls implemented without external controls addons.
const canvas = renderer.domElement;
const pointers = new Map();
let dragMode = null;
let lastPointer = { x: 0, y: 0 };
let lastPinchDistance = 0;
let lastPinchCenter = { x: 0, y: 0 };
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
function pointerCenter() {
const values = [...pointers.values()];
if (!values.length) return { x: 0, y: 0 };
if (values.length === 1) return values[0];
return {
x: (values[0].x + values[1].x) / 2,
y: (values[0].y + values[1].y) / 2
};
}
function panCamera(dx, dy) {
const scale = cameraState.radius * 0.0014;
const right = new THREE.Vector3(Math.cos(cameraState.yaw), 0, -Math.sin(cameraState.yaw));
const forward = new THREE.Vector3(Math.sin(cameraState.yaw), 0, Math.cos(cameraState.yaw));
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -13, 13);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -10, 10);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragMode = event.button === 0 ? "orbit" : "pan";
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
dragMode = "pinch";
lastPinchDistance = pointerDistance();
lastPinchCenter = pointerCenter();
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && dragMode) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
if (dragMode === "orbit") {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.18,
1.22
);
} else if (dragMode === "pan") {
panCamera(dx, dy);
}
} else if (pointers.size === 2 && dragMode === "pinch") {
const distance = pointerDistance();
const center = pointerCenter();
if (lastPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (lastPinchDistance / distance),
12,
62
);
}
panCamera(center.x - lastPinchCenter.x, center.y - lastPinchCenter.y);
lastPinchDistance = distance;
lastPinchCenter = center;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (!pointers.size) dragMode = null;
else if (pointers.size === 1) {
dragMode = "orbit";
lastPointer = [...pointers.values()][0];
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
12,
62
);
}, { passive: false });
window.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
let handled = true;
if (key === "arrowleft") cameraState.yaw += 0.08;
else if (key === "arrowright") cameraState.yaw -= 0.08;
else if (key === "arrowup") {
cameraState.pitch = Math.min(1.22, cameraState.pitch + 0.06);
} else if (key === "arrowdown") {
cameraState.pitch = Math.max(0.18, cameraState.pitch - 0.06);
} else if (key === "+" || key === "=") {
cameraState.radius = Math.max(12, cameraState.radius - 2);
} else if (key === "-" || key === "_") {
cameraState.radius = Math.min(62, cameraState.radius + 2);
} else if (key === "w") {
cameraState.target.z -= 0.6;
} else if (key === "s") {
cameraState.target.z += 0.6;
} else if (key === "a") {
cameraState.target.x -= 0.6;
} else if (key === "d") {
cameraState.target.x += 0.6;
} else if (key === "r") {
cameraState.target.copy(defaultView.target);
cameraState.yaw = defaultView.yaw;
cameraState.pitch = defaultView.pitch;
cameraState.radius = defaultView.radius;
} else {
handled = false;
}
if (handled) event.preventDefault();
});
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateCamera();
// Animated flow beads are only symbolic, not a hydraulic simulation.
flowBeads.forEach((beads, pathIndex) => {
const pathData = flowPaths[pathIndex];
beads.forEach((bead, i) => {
bead.visible = flowOn;
const t = time * (pathIndex === 2 ? 0.08 : 0.13) + i / beads.length;
bead.position.copy(sampleFlowPath(pathData, t));
});
});
// Voxel rainfall, with drops restarting above the scene.
rainMesh.visible = rainOn;
if (rainOn) {
raindrops.forEach((drop, i) => {
drop.y -= drop.speed * dt;
const overRoof =
drop.x > -14.6 && drop.x < 0.6 &&
drop.z > -10.6 && drop.z < -1.3;
if (drop.y < 0.2 || (overRoof && drop.y < 8.7)) {
drop.y = 17 + Math.random() * 5;
drop.x = -17.5 + Math.random() * 35;
drop.z = -10.8 + Math.random() * 21.6;
}
rainDummy.position.set(drop.x, drop.y, drop.z);
rainDummy.scale.set(1, 0.85 + (i % 4) * 0.12, 1);
rainDummy.updateMatrix();
rainMesh.setMatrixAt(i, rainDummy.matrix);
});
rainMesh.instanceMatrix.needsUpdate = true;
}
// Project HTML markers into screen space.
if (labelsVisible) {
labels.forEach(({ def, element }) => {
const projected = def.position.clone().project(camera);
const visible =
projected.z > -1 && projected.z < 1 &&
projected.x > -1.15 && projected.x < 1.15 &&
projected.y > -1.1 && projected.y < 1.1;
element.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
});
}
renderer.render(scene, camera);
}
document.getElementById("loading").remove();
animate();
</script>
</body>
</html>
```