Prompt specification
Build or customize the Three.js 3D scene "Community Water Exhibit Cutaway" 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: Community Water Exhibit Cutaway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-water-exhibit-cutaway-x3995
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring separate water supply and drainage networks. Build a fictional water-system museum model showing potable supply, wastewater collection, and stormwater separately. Keep arrows consistent with pipe connectivity and label omitted treatment complexity. Voxel style.
Working Three.js Starter (community-water-exhibit-cutaway-x3995):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Water Systems Museum</title>
<style>
:root {
--ink: #17242d;
--muted: #65747d;
--panel: rgba(250, 252, 252, 0.92);
--supply: #2678d8;
--waste: #a96532;
--storm: #18a39c;
--border: rgba(23, 36, 45, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7ecef;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
min-width: 92px;
padding: 7px 9px 7px 10px;
transform: translate(-50%, -100%);
border-left: 4px solid var(--label-color, #7b8991);
border-radius: 3px 7px 7px 3px;
background: rgba(251, 253, 253, 0.91);
box-shadow: 0 4px 13px rgba(25, 39, 48, 0.12);
color: #20303a;
white-space: nowrap;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.055em;
line-height: 1.25;
}
.world-label small {
display: block;
margin-top: 3px;
color: #687781;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.02em;
text-transform: none;
}
.world-label.zone-label {
background: rgba(32, 45, 53, 0.84);
color: white;
box-shadow: none;
}
.world-label.zone-label small {
color: rgba(255, 255, 255, 0.72);
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 10px 30px rgba(27, 42, 51, 0.1);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.intro {
position: absolute;
top: 18px;
left: 18px;
width: 300px;
padding: 17px;
}
.eyebrow {
margin-bottom: 7px;
color: #718089;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 22px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.legend {
display: grid;
gap: 7px;
padding-top: 12px;
border-top: 1px solid var(--border);
}
.legend-row {
display: grid;
grid-template-columns: 17px 12px 1fr;
align-items: center;
gap: 7px;
min-height: 22px;
}
.legend-row input {
width: 13px;
height: 13px;
margin: 0;
accent-color: var(--row-color);
cursor: pointer;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--row-color);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.network-name {
padding: 2px 0;
border: 0;
background: transparent;
color: #2d3d47;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
text-align: left;
}
.network-name:hover {
color: var(--row-color);
}
.legend-row.selected .network-name {
color: var(--row-color);
}
.tools {
position: absolute;
top: 18px;
right: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
max-width: 320px;
}
.tool {
pointer-events: auto;
padding: 8px 10px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(250, 252, 252, 0.9);
box-shadow: 0 4px 15px rgba(25, 39, 48, 0.08);
color: #41515b;
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 750;
}
.tool:hover {
background: white;
color: #111d24;
}
.info {
position: absolute;
right: 18px;
bottom: 18px;
width: 292px;
padding: 15px 16px;
}
.info-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
font-size: 14px;
font-weight: 850;
}
.info-dot {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--info-color);
}
.info p {
margin: 0;
color: #596a74;
font-size: 11px;
line-height: 1.5;
}
.info .route {
margin: 10px 0 8px;
color: #2f414b;
font-size: 10px;
font-weight: 750;
line-height: 1.45;
}
.note {
position: absolute;
bottom: 18px;
left: 18px;
max-width: 300px;
padding: 10px 12px;
border-radius: 8px;
background: rgba(34, 47, 55, 0.9);
color: #f3f6f7;
box-shadow: 0 6px 18px rgba(25, 39, 48, 0.13);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.055em;
line-height: 1.45;
text-transform: uppercase;
}
.controls-hint {
position: absolute;
left: 50%;
bottom: 20px;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 20px;
background: rgba(250, 252, 252, 0.76);
color: #65747d;
font-size: 9px;
font-weight: 650;
white-space: nowrap;
}
@media (max-width: 760px) {
.intro {
top: 10px;
left: 10px;
width: 245px;
padding: 13px;
}
h1 {
font-size: 18px;
}
.subtitle {
margin-bottom: 10px;
}
.tools {
top: 10px;
right: 10px;
max-width: 145px;
}
.info {
right: 10px;
bottom: 45px;
width: 245px;
}
.note {
left: 10px;
bottom: 10px;
max-width: 230px;
}
.controls-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels"></div>
<div id="ui">
<section class="panel intro">
<div class="eyebrow">Fictional civic infrastructure exhibit</div>
<h1>The Water Systems Museum</h1>
<p class="subtitle">
A voxel district model showing potable supply, sanitary wastewater,
and stormwater as three independent networks.
</p>
<div class="legend">
<div class="legend-row selected" data-network="supply" style="--row-color: var(--supply)">
<input type="checkbox" checked aria-label="Show potable supply network">
<span class="swatch"></span>
<button class="network-name">Potable supply</button>
</div>
<div class="legend-row" data-network="waste" style="--row-color: var(--waste)">
<input type="checkbox" checked aria-label="Show wastewater collection network">
<span class="swatch"></span>
<button class="network-name">Wastewater collection</button>
</div>
<div class="legend-row" data-network="storm" style="--row-color: var(--storm)">
<input type="checkbox" checked aria-label="Show stormwater collection network">
<span class="swatch"></span>
<button class="network-name">Stormwater collection</button>
</div>
</div>
</section>
<div class="tools">
<button class="tool" id="reset-view">Reset view</button>
<button class="tool" id="zoom-in">Zoom +</button>
<button class="tool" id="zoom-out">Zoom −</button>
<button class="tool" id="toggle-labels">Labels on</button>
<button class="tool" id="toggle-arrows">Arrows on</button>
</div>
<section class="panel info" id="info-panel">
<div class="info-title">
<span class="info-dot"></span>
<span id="info-title">Potable supply</span>
</div>
<p id="info-description"></p>
<div class="route" id="info-route"></div>
<p>Click a colored pipe or legend item to inspect a network.</p>
</section>
<div class="note">
Schematic model — treatment process complexity omitted
</div>
<div class="controls-hint">
Drag: orbit · Wheel: zoom · Right/Shift-drag: pan · Click: select
</div>
</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 and camera
// ---------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ecef);
scene.fog = new THREE.Fog(0xe7ecef, 43, 72);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf5fbff, 0x7e877c, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff6df, 3.1);
sun.position.set(-12, 22, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e8ff, 0.75);
fill.position.set(14, 9, -15);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(w, h, d, x, y, z, material, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function material(color, roughness = 0.8, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const groundMaterial = material(0xd9ddd7);
const plinthMaterial = material(0xaeb8b7);
const roadMaterial = material(0x7d8789);
const markingMaterial = material(0xeef1e8);
const concreteMaterial = material(0xb9c1be);
const darkMaterial = material(0x3c4a50);
const roofMaterial = material(0x5c6b70);
const trunkMaterial = material(0x7f6651);
const leafMaterial = material(0x4c8469);
const leafLightMaterial = material(0x73a27d);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xffdf8b,
emissive: 0xa96f15,
emissiveIntensity: 0.22,
roughness: 0.45
});
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x3b9fd1,
roughness: 0.35,
metalness: 0.05
});
const colors = {
supply: 0x2678d8,
waste: 0xa96532,
storm: 0x18a39c
};
const networks = {};
for (const key of Object.keys(colors)) {
const group = new THREE.Group();
const arrowRoot = new THREE.Group();
group.add(arrowRoot);
scene.add(group);
const pipeMaterial = new THREE.MeshStandardMaterial({
color: colors[key],
emissive: colors[key],
emissiveIntensity: 0.12,
roughness: 0.48,
metalness: 0.08
});
const arrowMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(colors[key]).lerp(new THREE.Color(0xffffff), 0.34),
emissive: colors[key],
emissiveIntensity: 0.22,
roughness: 0.42
});
networks[key] = {
group,
arrowRoot,
pipeMaterial,
arrowMaterial,
color: colors[key]
};
}
// ---------------------------------------------------------------------
// Voxel arrows and pipe construction
// ---------------------------------------------------------------------
function addVoxelArrow(position, direction, parent, material, scale = 1) {
const arrow = new THREE.Group();
parent.add(arrow);
const forward = direction.clone().normalize();
const reference = Math.abs(forward.y) > 0.9
? new THREE.Vector3(0, 0, 1)
: new THREE.Vector3(0, 1, 0);
const side = new THREE.Vector3()
.crossVectors(reference, forward)
.normalize();
const up = new THREE.Vector3()
.crossVectors(forward, side)
.normalize();
const basis = new THREE.Matrix4().makeBasis(side, up, forward);
arrow.quaternion.setFromRotationMatrix(basis);
arrow.position.copy(position);
arrow.scale.setScalar(scale);
// Local +Z is the flow direction.
box(0.12, 0.12, 0.48, 0, 0, -0.10, material, arrow, false);
box(0.30, 0.12, 0.12, 0, 0, 0.16, material, arrow, false);
box(0.20, 0.12, 0.12, 0, 0, 0.25, material, arrow, false);
box(0.10, 0.12, 0.12, 0, 0, 0.33, material, arrow, false);
return arrow;
}
function pipeSegment(a, b, thickness, material, parent) {
const dx = b.x - a.x;
const dy = b.y - a.y;
const dz = b.z - a.z;
const length = Math.hypot(dx, dy, dz);
if (length < 0.0001) return;
const midpoint = a.clone().add(b).multiplyScalar(0.5);
if (Math.abs(dx) > 0.0001) {
box(
Math.abs(dx) + thickness,
thickness,
thickness,
midpoint.x,
midpoint.y,
midpoint.z,
material,
parent
);
} else if (Math.abs(dz) > 0.0001) {
box(
thickness,
thickness,
Math.abs(dz) + thickness,
midpoint.x,
midpoint.y,
midpoint.z,
material,
parent
);
} else {
box(
thickness,
Math.abs(dy) + thickness,
thickness,
midpoint.x,
midpoint.y,
midpoint.z,
material,
parent
);
}
}
function pipePath(points, networkKey, thickness = 0.25) {
const network = networks[networkKey];
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const direction = b.clone().sub(a);
const length = direction.length();
pipeSegment(a, b, thickness, network.pipeMaterial, network.group);
const arrowCount = Math.max(1, Math.floor(length / 2.5));
for (let n = 0; n < arrowCount; n++) {
const t = (n + 1) / (arrowCount + 1);
const position = a.clone().lerp(b, t);
const arrowScale = Math.min(0.9, Math.max(0.55, length / 2.2));
addVoxelArrow(
position,
direction,
network.arrowRoot,
network.arrowMaterial,
arrowScale
);
}
}
// Square voxel joints make every route visibly connected.
for (const point of points) {
box(
thickness * 1.18,
thickness * 1.18,
thickness * 1.18,
point.x,
point.y,
point.z,
network.pipeMaterial,
network.group
);
}
}
// ---------------------------------------------------------------------
// Museum plinth and district
// ---------------------------------------------------------------------
box(28, 0.7, 18, 0, -0.42, 0, plinthMaterial);
box(27.6, 0.12, 17.6, 0, -0.04, 0, groundMaterial);
// Subtle exhibit-zone surfaces.
const supplyPadMaterial = new THREE.MeshStandardMaterial({
color: colors.supply,
transparent: true,
opacity: 0.055,
roughness: 1
});
const wastePadMaterial = new THREE.MeshStandardMaterial({
color: colors.waste,
transparent: true,
opacity: 0.055,
roughness: 1
});
const stormPadMaterial = new THREE.MeshStandardMaterial({
color: colors.storm,
transparent: true,
opacity: 0.055,
roughness: 1
});
box(10.5, 0.025, 6.3, -7.0, 0.035, -3.7, supplyPadMaterial, scene, false);
box(13.2, 0.025, 3.6, 4.1, 0.037, 4.2, wastePadMaterial, scene, false);
box(14.4, 0.025, 4.2, 5.5, 0.038, -1.1, stormPadMaterial, scene, false);
function addRoad(x, z, width, depth) {
box(width, 0.055, depth, x, 0.055, z, roadMaterial, scene, false);
const alongX = width >= depth;
const count = Math.floor((alongX ? width : depth) / 1.25);
for (let i = 0; i < count; i++) {
const offset = (i - (count - 1) / 2) * 1.25;
if (alongX) {
box(0.48, 0.018, 0.07, x + offset, 0.095, z, markingMaterial, scene, false);
} else {
box(0.07, 0.018, 0.48, x, 0.095, z + offset, markingMaterial, scene, false);
}
}
}
addRoad(2.2, 0.2, 10.2, 1.35);
addRoad(-5.1, 2.25, 1.2, 4.2);
function addBuilding(x, z, width, depth, height, wallColor, roofColor = 0x596970) {
const wallMaterial = material(wallColor);
const roofMaterialLocal = material(roofColor);
box(width, height, depth, x, height / 2, z, wallMaterial);
box(width + 0.18, 0.18, depth + 0.18, x, height + 0.08, z, roofMaterialLocal);
// Front windows.
const columns = Math.max(1, Math.floor(width / 0.72));
const rows = Math.max(1, Math.floor(height / 0.78));
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const wx = x + (col - (columns - 1) / 2) * 0.68;
const wy = 0.55 + row * 0.65;
if (wy < height - 0.15) {
box(
0.25,
0.27,
0.055,
wx,
wy,
z + depth / 2 + 0.035,
windowMaterial,
scene,
false
);
}
}
}
// Right-side windows.
const sideRows = Math.max(1, Math.floor(depth / 0.9));
for (let row = 0; row < sideRows; row++) {
for (let col = 0; col < rows; col++) {
const wz = z + (row - (sideRows - 1) / 2) * 0.78;
const wy = 0.58 + col * 0.65;
if (wy < height - 0.15) {
box(
0.055,
0.25,
0.28,
x + width / 2 + 0.035,
wy,
wz,
windowMaterial,
scene,
false
);
}
}
}
// Small rooftop service block.
box(
width * 0.23,
0.25,
depth * 0.25,
x + width * 0.18,
height + 0.29,
z - depth * 0.12,
roofMaterialLocal
);
}
function addTree(x, z, scale = 1) {
box(0.18 * scale, 0.8 * scale, 0.18 * scale,
x, 0.4 * scale, z, trunkMaterial);
box(0.9 * scale, 0.65 * scale, 0.9 * scale,
x, 1.0 * scale, z, leafMaterial);
box(0.62 * scale, 0.45 * scale, 0.62 * scale,
x + 0.12 * scale, 1.48 * scale, z - 0.05 * scale,
leafLightMaterial);
}
function addLamp(x, z) {
box(0.09, 1.15, 0.09, x, 0.58, z, darkMaterial);
box(0.28, 0.14, 0.28, x, 1.18, z, windowMaterial);
}
// North-side houses and civic hall.
addBuilding(-0.5, -3.4, 1.8, 1.7, 1.55, 0xd7c8a4, 0x7c6c5f);
addBuilding(2.2, -3.4, 1.8, 1.7, 1.8, 0xbdcfd0, 0x64777c);
addBuilding(5.0, -3.4, 1.8, 1.7, 1.45, 0xd3c2b0, 0x77675d);
addBuilding(-3.5, 1.0, 3.0, 2.2, 2.35, 0xc5d4d9, 0x536970);
// Front-side sanitary district.
addBuilding(-1.5, 3.25, 2.3, 2.35, 3.0, 0xd6c5b6, 0x7a6458);
addBuilding(3.0, 3.05, 2.8, 2.15, 1.75, 0xc9b98e, 0x6e735c);
addBuilding(6.0, 3.15, 2.4, 2.1, 2.55, 0xb8c9c6, 0x617273);
addTree(-8.8, 5.8, 1.2);
addTree(-6.6, 6.6, 0.95);
addTree(-10.7, 6.4, 1.05);
addTree(-0.2, 6.5, 0.95);
addTree(4.7, 6.6, 1.1);
addTree(8.0, 6.8, 0.9);
addTree(-11.5, 1.3, 1.1);
addTree(-9.8, 0.1, 0.9);
addTree(8.3, -0.7, 0.85);
addLamp(-2.1, 0.2);
addLamp(2.0, 0.2);
addLamp(6.0, 0.2);
// ---------------------------------------------------------------------
// Source, water works and elevated storage
// ---------------------------------------------------------------------
// Stepped source terrain.
box(3.8, 0.55, 2.6, -11.2, 0.30, -5.8, material(0x8c9a8d));
box(2.8, 0.65, 2.0, -11.1, 0.78, -6.2, material(0x78877d));
box(1.9, 0.65, 1.5, -10.8, 1.32, -6.45, material(0x68786f));
// Square spring pool.
box(2.3, 0.18, 1.65, -11.1, 0.13, -4.65, concreteMaterial);
box(1.9, 0.09, 1.28, -11.1, 0.25, -4.65, waterMaterial, scene, false);
// Water works building.
addBuilding(-7.7, -4.8, 3.0, 2.1, 1.55, 0xbad0d8, 0x64777c);
// Two square treatment tanks; process complexity is intentionally omitted.
box(0.95, 0.72, 0.95, -8.3, 0.36, -3.35, concreteMaterial);
box(0.78, 0.10, 0.78, -8.3, 0.77, -3.35, waterMaterial, scene, false);
box(0.95, 0.72, 0.95, -7.05, 0.36, -3.35, concreteMaterial);
box(0.78, 0.10, 0.78, -7.05, 0.77, -3.35, waterMaterial, scene, false);
// Elevated storage tower.
const towerX = -3.5;
const towerZ = -4.8;
for (const dx of [-0.48, 0.48]) {
for (const dz of [-0.48, 0.48]) {
box(0.16, 2.25, 0.16, towerX + dx, 1.13, towerZ + dz, darkMaterial);
}
}
box(1.45, 1.15, 1.45, towerX, 2.82, towerZ, material(0x4d92c8));
box(1.62, 0.17, 1.62, towerX, 3.47, towerZ, roofMaterial);
box(1.20, 0.12, 1.20, towerX, 2.22, towerZ, darkMaterial);
// ---------------------------------------------------------------------
// Wastewater plant and stormwater basin
// ---------------------------------------------------------------------
// Wastewater plant at the downstream end of the collection trunk.
addBuilding(10.55, 4.8, 3.0, 2.25, 1.8, 0xb7a995, 0x705f54);
box(1.05, 0.8, 1.05, 10.2, 0.4, 2.95, concreteMaterial);
box(0.86, 0.10, 0.86, 10.2, 0.85, 2.95, waterMaterial, scene, false);
box(1.05, 0.8, 1.05, 11.4, 0.4, 2.95, concreteMaterial);
box(0.86, 0.10, 0.86, 11.4, 0.85, 2.95, waterMaterial, scene, false);
// Stormwater detention/outfall basin.
const basinX = 10.5;
const basinZ = -5.2;
box(3.1, 0.18, 2.8, basinX, 0.10, basinZ, concreteMaterial);
box(0.22, 0.55, 2.9, basinX - 1.48, 0.34, basinZ, concreteMaterial);
box(0.22, 0.55, 2.9, basinX + 1.48, 0.34, basinZ, concreteMaterial);
box(3.1, 0.55, 0.22, basinX, 0.34, basinZ - 1.38, concreteMaterial);
box(3.1, 0.55, 0.22, basinX, 0.34, basinZ + 1.38, concreteMaterial);
const animatedWater = [];
for (let ix = 0; ix < 6; ix++) {
for (let iz = 0; iz < 4; iz++) {
const waterBlock = box(
0.40,
0.07,
0.52,
basinX - 1.05 + ix * 0.42,
0.23,
basinZ - 0.78 + iz * 0.52,
waterMaterial,
scene,
false
);
animatedWater.push(waterBlock);
}
}
// Small receiving channel at the outfall edge.
box(1.8, 0.08, 1.4, 13.2, 0.13, -5.2, waterMaterial, scene, false);
// ---------------------------------------------------------------------
// Network 1: Potable supply
// Source -> water works -> elevated storage -> district branches.
// ---------------------------------------------------------------------
pipePath([
new THREE.Vector3(-11.15, 0.78, -4.65),
new THREE.Vector3(-9.2, 0.78, -4.65)
], "supply", 0.28);
pipePath([
new THREE.Vector3(-6.2, 0.78, -4.65),
new THREE.Vector3(-4.2, 0.78, -4.65)
], "supply", 0.28);
pipePath([
new THREE.Vector3(-2.85, 0.78, -4.65),
new THREE.Vector3(-2.85, 0.78, -1.8)
], "supply", 0.28);
pipePath([
new THREE.Vector3(-2.85, 0.78, -1.8),
new THREE.Vector3(6.15, 0.78, -1.8)
], "supply", 0.28);
// Civic hall branch.
pipePath([
new THREE.Vector3(-3.5, 0.78, -1.8),
new THREE.Vector3(-3.5, 0.78, -0.2)
], "supply", 0.23);
// North house branches.
for (const houseX of [-0.5, 2.2, 5.0]) {
pipePath([
new THREE.Vector3(houseX, 0.78, -1.8),
new THREE.Vector3(houseX, 0.78, -2.5)
], "supply", 0.22);
}
// ---------------------------------------------------------------------
// Network 2: Wastewater collection
// Building drains -> lower sewer trunk -> wastewater plant.
// ---------------------------------------------------------------------
pipePath([
new THREE.Vector3(-1.5, 0.75, 4.38),
new THREE.Vector3(-1.5, 0.28, 4.38),
new THREE.Vector3(-1.5, 0.28, 4.8)
], "waste", 0.23);
pipePath([
new THREE.Vector3(3.0, 0.55, 4.12),
new THREE.Vector3(3.0, 0.28, 4.12),
new THREE.Vector3(3.0, 0.28, 4.8)
], "waste", 0.23);
pipePath([
new THREE.Vector3(6.0, 0.75, 4.2),
new THREE.Vector3(6.0, 0.28, 4.2),
new THREE.Vector3(6.0, 0.28, 4.8)
], "waste", 0.23);
pipePath([
new THREE.Vector3(-1.5, 0.28, 4.8),
new THREE.Vector3(9.05, 0.28, 4.8)
], "waste", 0.27);
// ---------------------------------------------------------------------
// Network 3: Stormwater collection
// Roof/road runoff -> storm drains -> basin -> outfall.
// ---------------------------------------------------------------------
// Main storm drain, kept below and separate from the potable main.
pipePath([
new THREE.Vector3(-1.1, 0.22, -0.8),
new THREE.Vector3(8.8, 0.22, -0.8)
], "storm", 0.24);
// Basin inlet.
pipePath([
new THREE.Vector3(8.8, 0.22, -0.8),
new THREE.Vector3(8.8, 0.22, -5.2),
new THREE.Vector3(9.1, 0.22, -5.2)
], "storm", 0.24);
// Basin outlet and receiving channel.
pipePath([
new THREE.Vector3(11.9, 0.22, -5.2),
new THREE.Vector3(13.45, 0.22, -5.2)
], "storm", 0.24);
// Roof downspouts from the north houses.
for (const houseX of [-0.5, 2.2, 5.0]) {
const spoutX = houseX - 0.62;
pipePath([
new THREE.Vector3(spoutX, 1.45, -2.42),
new THREE.Vector3(spoutX, 0.22, -2.42),
new THREE.Vector3(spoutX, 0.22, -0.8)
], "storm", 0.19);
}
// Road inlets feeding the storm drain.
for (const inletX of [0.2, 3.3, 6.4]) {
pipePath([
new THREE.Vector3(inletX, 0.14, 0.2),
new THREE.Vector3(inletX, 0.22, -0.8)
], "storm", 0.19);
// Square storm grate.
box(0.48, 0.07, 0.48, inletX, 0.13, 0.2, darkMaterial, scene, false);
for (let i = 0; i < 3; i++) {
box(0.34, 0.025, 0.045, inletX, 0.18, 0.07 + i * 0.13,
concreteMaterial, scene, false);
}
}
// ---------------------------------------------------------------------
// Labels
// ---------------------------------------------------------------------
const labels = [];
function addLabel(title, subtitle, position, network = null, zone = false) {
const element = document.createElement("div");
element.className = "world-label" + (zone ? " zone-label" : "");
element.innerHTML = `${title}${subtitle ? `<small>${subtitle}</small>` : ""}`;
const cssColor = network
? "#" + new THREE.Color(colors[network]).getHexString()
: "#708089";
element.style.setProperty("--label-color", cssColor);
labelsLayer.appendChild(element);
labels.push({
element,
position: position.clone(),
network
});
}
addLabel(
"SOURCE & INTAKE",
"Potable source",
new THREE.Vector3(-11.1, 1.65, -4.7)
);
addLabel(
"WATER WORKS",
"Treatment complexity omitted",
new THREE.Vector3(-7.7, 2.45, -4.8),
"supply"
);
addLabel(
"ELEVATED STORAGE",
"Distribution pressure",
new THREE.Vector3(-3.5, 3.85, -4.8),
"supply"
);
addLabel(
"POTABLE SUPPLY",
"Source → storage → buildings",
new THREE.Vector3(-1.4, 1.25, -5.85),
"supply",
true
);
addLabel(
"CIVIC HALL",
"Potable service",
new THREE.Vector3(-3.5, 3.0, 1.0),
"supply"
);
addLabel(
"WASTEWATER PLANT",
"Collection endpoint · treatment complexity omitted",
new THREE.Vector3(10.55, 2.7, 4.8),
"waste"
);
addLabel(
"WASTEWATER COLLECTION",
"Building drains → collection trunk",
new THREE.Vector3(2.3, 0.85, 6.25),
"waste",
true
);
addLabel(
"STORMWATER BASIN",
"Outfall · treatment complexity omitted",
new THREE.Vector3(10.5, 1.25, -5.2),
"storm"
);
addLabel(
"STORMWATER COLLECTION",
"Roof and road runoff → outfall",
new THREE.Vector3(5.1, 0.85, -1.45),
"storm",
true
);
// ---------------------------------------------------------------------
// Selection and legend behavior
// ---------------------------------------------------------------------
const infoPanel = document.querySelector("#info-panel");
const infoTitle = document.querySelector("#info-title");
const infoDescription = document.querySelector("#info-description");
const infoRoute = document.querySelector("#info-route");
const networkInfo = {
supply: {
title: "Potable supply",
description:
"Treated potable water moves from the source through the water works and elevated storage before entering the district distribution branches.",
route: "Source → water works → elevated storage → civic hall and houses"
},
waste: {
title: "Wastewater collection",
description:
"Sanitary drains from the front district descend to a lower collection trunk. The brown network remains independent of potable and storm pipes.",
route: "Building drains → lower sewer trunk → wastewater plant"
},
storm: {
title: "Stormwater collection",
description:
"Roof downspouts and road inlets convey runoff through a dedicated storm drain to the basin and outfall. It never joins the sanitary sewer.",
route: "Roofs and road → storm drains → detention basin → outfall"
}
};
let selectedNetwork = "supply";
function selectNetwork(key) {
if (!networkInfo[key]) return;
selectedNetwork = key;
for (const row of document.querySelectorAll(".legend-row")) {
row.classList.toggle("selected", row.dataset.network === key);
}
const info = networkInfo[key];
infoTitle.textContent = info.title;
infoDescription.textContent = info.description;
infoRoute.textContent = info.route;
infoPanel.style.setProperty(
"--info-color",
"#" + new THREE.Color(colors[key]).getHexString()
);
}
for (const row of document.querySelectorAll(".legend-row")) {
const key = row.dataset.network;
row.querySelector("input").addEventListener("change", (event) => {
networks[key].group.visible = event.target.checked;
if (!event.target.checked && selectedNetwork === key) {
const visible = Object.keys(networks).find(
(networkKey) => networks[networkKey].group.visible
);
if (visible) selectNetwork(visible);
}
});
row.querySelector(".network-name").addEventListener("click", () => {
selectNetwork(key);
});
}
selectNetwork("supply");
// ---------------------------------------------------------------------
// Custom orbit, pan and zoom controls — no addon imports
// ---------------------------------------------------------------------
const orbit = {
theta: 0.72,
phi: 0.88,
radius: 31,
target: new THREE.Vector3(0, 0.55, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.cos(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.sin(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
updateCamera();
let dragging = false;
let dragButton = 0;
let pointerX = 0;
let pointerY = 0;
let pointerTravel = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragButton = event.button;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
if (dragButton === 2 || event.shiftKey) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1);
up.y = 0;
if (up.lengthSq() < 0.0001) up.set(0, 0, -1);
up.normalize();
const scale = orbit.radius * 0.0015;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(up, dy * scale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.006,
0.34,
1.36
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (pointerTravel < 5) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const visibleGroups = Object.values(networks)
.filter((network) => network.group.visible)
.map((network) => network.group);
const hits = raycaster.intersectObjects(visibleGroups, true);
if (hits.length) {
let object = hits[0].object;
let key = null;
while (object) {
if (object.userData.network) {
key = object.userData.network;
break;
}
object = object.parent;
}
if (key) selectNetwork(key);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
16,
48
);
updateCamera();
},
{ passive: false }
);
// Assign click metadata to every network object.
for (const [key, network] of Object.entries(networks)) {
network.group.traverse((object) => {
object.userData.network = key;
});
}
// ---------------------------------------------------------------------
// Interface buttons
// ---------------------------------------------------------------------
const labelsButton = document.querySelector("#toggle-labels");
const arrowsButton = document.querySelector("#toggle-arrows");
let labelsVisible = true;
let arrowsVisible = true;
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsButton.textContent = labelsVisible ? "Labels on" : "Labels off";
});
arrowsButton.addEventListener("click", () => {
arrowsVisible = !arrowsVisible;
for (const network of Object.values(networks)) {
network.arrowRoot.visible = arrowsVisible;
}
arrowsButton.textContent = arrowsVisible ? "Arrows on" : "Arrows off";
});
document.querySelector("#reset-view").addEventListener("click", () => {
orbit.theta = 0.72;
orbit.phi = 0.88;
orbit.radius = 31;
orbit.target.set(0, 0.55, 0);
updateCamera();
});
document.querySelector("#zoom-in").addEventListener("click", () => {
orbit.radius = Math.max(16, orbit.radius * 0.88);
updateCamera();
});
document.querySelector("#zoom-out").addEventListener("click", () => {
orbit.radius = Math.min(48, orbit.radius * 1.12);
updateCamera();
});
// ---------------------------------------------------------------------
// Responsive rendering and animation
// ---------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
function updateLabels() {
const width = innerWidth;
const height = innerHeight;
for (const label of labels) {
if (!labelsVisible) {
label.element.style.display = "none";
continue;
}
if (label.network && !networks[label.network].group.visible) {
label.element.style.display = "none";
continue;
}
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (visible) {
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
}
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
for (const [key, network] of Object.entries(networks)) {
const selected = selectedNetwork === key;
const pulse = Math.sin(elapsed * 2.2 + key.length) * 0.06;
network.pipeMaterial.emissiveIntensity =
(selected ? 0.34 : 0.10) + pulse;
network.arrowMaterial.emissiveIntensity =
(selected ? 0.62 : 0.24) + pulse * 1.5;
}
for (let i = 0; i < animatedWater.length; i++) {
animatedWater[i].position.y =
0.23 + Math.sin(elapsed * 1.35 + i * 0.42) * 0.018;
}
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```