Prompt specification
Build or customize the Three.js 3D scene "Sink Drain and Toilet Supply Schematic" 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: Sink Drain and Toilet Supply Schematic
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/sink-drain-and-toilet-supply-schematic-x3994
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring separate water supply and drainage networks. Create an educational household water-flow diagram with clearly labeled sources, treatment placeholders, and use points. State that real reuse design requires verified local standards and treatment requirements. Voxel style.
Working Three.js Starter (sink-drain-and-toilet-supply-schematic-x3994):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Household Water Flow — Voxel Diagram</title>
<style>
:root {
--ink: #18312d;
--muted: #5d716c;
--paper: rgba(250, 252, 247, 0.92);
--line: rgba(24, 49, 45, 0.13);
--supply: #1687d4;
--drain: #e2673f;
--shadow: 0 14px 40px rgba(34, 55, 48, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8efe9;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
z-index: 4;
}
.label {
--accent: var(--supply);
position: absolute;
min-width: 128px;
max-width: 210px;
padding: 8px 10px 9px;
border: 1px solid rgba(24, 49, 45, 0.13);
border-left: 4px solid var(--accent);
border-radius: 9px;
background: rgba(255, 255, 252, 0.95);
box-shadow: 0 6px 18px rgba(29, 54, 48, 0.12);
transform: translate(-50%, -100%);
transition:
opacity 180ms ease,
filter 180ms ease;
will-change: left, top;
}
.label::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 10px;
height: 10px;
border-right: 1px solid rgba(24, 49, 45, 0.13);
border-bottom: 1px solid rgba(24, 49, 45, 0.13);
background: rgba(255, 255, 252, 0.95);
transform: translateX(-50%) rotate(45deg);
}
.label.drain {
--accent: var(--drain);
}
.label.neutral {
--accent: #6b7d77;
}
.label .kicker {
display: block;
margin-bottom: 2px;
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
line-height: 1.2;
text-transform: uppercase;
}
.label strong {
display: block;
font-size: 12px;
line-height: 1.22;
}
.label .detail {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.25;
}
.label.muted {
opacity: 0.13;
filter: grayscale(0.7);
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.intro {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 18px 19px 16px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #58706a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 1;
}
.intro p {
margin: 9px 0 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
padding-top: 11px;
border-top: 1px solid var(--line);
font-size: 11px;
font-weight: 650;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 17px;
height: 5px;
border-radius: 2px;
background: var(--supply);
}
.legend .drain-key {
background: var(--drain);
}
.controls {
top: 18px;
right: 18px;
display: flex;
gap: 7px;
padding: 7px;
pointer-events: auto;
}
.controls button {
min-height: 34px;
padding: 7px 10px;
border: 1px solid rgba(24, 49, 45, 0.13);
border-radius: 9px;
background: rgba(255, 255, 252, 0.84);
color: #4e625c;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
background 140ms ease,
color 140ms ease,
transform 140ms ease;
}
.controls button:hover {
transform: translateY(-1px);
background: white;
}
.controls button.active {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.design-note {
bottom: 18px;
left: 18px;
width: min(380px, calc(100vw - 36px));
padding: 14px 16px;
border-left: 4px solid #dca83e;
pointer-events: none;
}
.design-note strong {
display: block;
margin-bottom: 4px;
font-size: 12px;
letter-spacing: 0.01em;
}
.design-note p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.help {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 9;
padding: 8px 11px;
border-radius: 9px;
background: rgba(24, 49, 45, 0.78);
color: rgba(255, 255, 255, 0.9);
font-size: 10px;
font-weight: 650;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e8efe9;
color: var(--ink);
font-size: 13px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
padding: 14px 15px;
}
.intro p,
.legend {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: calc(100vw - 24px);
}
.help,
.design-note {
display: none;
}
.label {
min-width: 92px;
max-width: 145px;
padding: 6px 8px 7px;
}
.label strong {
font-size: 10px;
}
.label .detail {
display: none;
}
}
</style>
</head>
<body>
<main
id="scene"
aria-label="Interactive 3D voxel diagram of separate household potable-water supply and sanitary drainage networks"
></main>
<div id="labels" aria-hidden="true"></div>
<section class="panel intro">
<div class="eyebrow">Interactive cutaway · Concept diagram</div>
<h1>Household water flow</h1>
<p>
Blue follows treated water toward household use points.
Orange follows wastewater away from the home. The two networks remain separate.
</p>
<div class="legend" aria-label="Network legend">
<span><i></i> Potable supply</span>
<span><i class="drain-key"></i> Sanitary drainage</span>
</div>
</section>
<nav class="panel controls" aria-label="Diagram controls">
<button class="active" data-network="all">Both</button>
<button data-network="supply">Supply</button>
<button data-network="drainage">Drainage</button>
<button id="pause">Pause flow</button>
<button id="reset">Reset view</button>
</nav>
<aside class="panel design-note">
<strong>Reuse design note</strong>
<p>
Real reuse design requires verified local standards and treatment requirements.
Treatment plants shown here are placeholders, not engineered process diagrams.
</p>
</aside>
<div class="help">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
<div id="loading">Building voxel water network…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is required to display this diagram.";
throw error;
}
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;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8efe9);
scene.fog = new THREE.Fog(0xe8efe9, 24, 54);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf8fff8, 0x7e9388, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.4);
sun.position.set(-8, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dcff, 1.15);
fill.position.set(10, 6, -8);
scene.add(fill);
const palette = {
ground: new THREE.MeshStandardMaterial({
color: 0xb9c9b7,
roughness: 0.96
}),
base: new THREE.MeshStandardMaterial({
color: 0x7c9187,
roughness: 0.92
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf3eee2,
roughness: 0.84
}),
warm: new THREE.MeshStandardMaterial({
color: 0xd8bc91,
roughness: 0.8
}),
white: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72
}),
dark: new THREE.MeshStandardMaterial({
color: 0x273b3a,
roughness: 0.7
}),
metal: new THREE.MeshStandardMaterial({
color: 0x91a19d,
roughness: 0.42,
metalness: 0.38
}),
green: new THREE.MeshStandardMaterial({
color: 0x5f9472,
roughness: 0.95
}),
greenLight: new THREE.MeshStandardMaterial({
color: 0x8bb88e,
roughness: 0.95
}),
water: new THREE.MeshStandardMaterial({
color: 0x3ca9e3,
roughness: 0.28,
metalness: 0.12
}),
waterDark: new THREE.MeshStandardMaterial({
color: 0x187fbe,
roughness: 0.38,
metalness: 0.12
}),
glass: new THREE.MeshStandardMaterial({
color: 0xa9e1ee,
roughness: 0.16,
metalness: 0.08,
transparent: true,
opacity: 0.35,
depthWrite: false
})
};
const networks = {
supply: {
name: "supply",
pipeMaterial: new THREE.MeshStandardMaterial({
color: 0x1687d4,
roughness: 0.38,
metalness: 0.18
}),
flowMaterial: new THREE.MeshStandardMaterial({
color: 0x8ddcff,
emissive: 0x1687d4,
emissiveIntensity: 0.85,
roughness: 0.25
}),
labels: [],
flows: []
},
drainage: {
name: "drainage",
pipeMaterial: new THREE.MeshStandardMaterial({
color: 0xe2673f,
roughness: 0.52,
metalness: 0.08
}),
flowMaterial: new THREE.MeshStandardMaterial({
color: 0xffb08e,
emissive: 0xd6532e,
emissiveIntensity: 0.7,
roughness: 0.35
}),
labels: [],
flows: []
}
};
function box(parent, size, position, material, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addLabel({
category,
title,
detail = "",
position,
network = null,
neutral = false
}) {
const element = document.createElement("div");
element.className = "label";
if (neutral) element.classList.add("neutral");
else if (network) element.classList.add(network);
const kicker = document.createElement("span");
kicker.className = "kicker";
kicker.textContent = category;
const strong = document.createElement("strong");
strong.textContent = title;
element.append(kicker, strong);
if (detail) {
const detailElement = document.createElement("span");
detailElement.className = "detail";
detailElement.textContent = detail;
element.append(detailElement);
}
labelLayer.appendChild(element);
const label = {
element,
anchor: position.clone(),
network
};
if (network) networks[network].labels.push(label);
else scene.userData.neutralLabels.push(label);
return label;
}
scene.userData.neutralLabels = [];
function createPipe(points, network, thickness = 0.14) {
const group = new THREE.Group();
const path = points.map((point) => new THREE.Vector3(...point));
for (let i = 0; i < path.length - 1; i++) {
const start = path[i];
const end = path[i + 1];
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
if (length < 0.001) continue;
const segment = new THREE.Mesh(
new THREE.BoxGeometry(thickness, length, thickness),
network.pipeMaterial
);
segment.position.copy(start).add(end).multiplyScalar(0.5);
segment.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
segment.castShadow = true;
segment.receiveShadow = true;
group.add(segment);
}
path.forEach((point) => {
const joint = new THREE.Mesh(
new THREE.BoxGeometry(
thickness * 1.34,
thickness * 1.34,
thickness * 1.34
),
network.pipeMaterial
);
joint.position.copy(point);
joint.castShadow = true;
group.add(joint);
});
scene.add(group);
return path;
}
function pathLengths(path) {
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;
}
return { lengths, total };
}
function samplePath(path, t) {
const { lengths, total } = pathLengths(path);
let distance = THREE.MathUtils.clamp(t, 0, 0.999999) * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i]) {
const localT = lengths[i] === 0 ? 0 : distance / lengths[i];
return new THREE.Vector3().lerpVectors(path[i], path[i + 1], localT);
}
distance -= lengths[i];
}
return path[path.length - 1].clone();
}
function addFlow(path, network, count = 4, size = 0.22, speed = 0.12) {
const meshes = [];
for (let i = 0; i < count; i++) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
network.flowMaterial
);
marker.castShadow = true;
scene.add(marker);
meshes.push(marker);
}
network.flows.push({
path,
meshes,
speed
});
}
// ---------------------------------------------------------------------
// Ground and site
// ---------------------------------------------------------------------
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xe8efe9,
roughness: 1
})
);
backdrop.rotation.x = -Math.PI / 2;
backdrop.position.y = -0.62;
backdrop.receiveShadow = true;
scene.add(backdrop);
box(scene, [20.4, 0.6, 10.6], [0, -0.3, 0], palette.base);
box(scene, [20, 0.12, 10.2], [0, 0.02, 0], palette.ground);
const grid = new THREE.GridHelper(20, 40, 0x759387, 0x9fb3a7);
grid.position.y = 0.085;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
// Small voxel landscaping.
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.scale.setScalar(scale);
box(group, [0.22, 1.25, 0.22], [0, 0.62, 0], palette.warm);
box(group, [0.95, 0.75, 0.95], [0, 1.45, 0], palette.green);
box(group, [0.65, 0.55, 0.65], [0.18, 2.0, 0.08], palette.greenLight);
box(group, [0.58, 0.52, 0.58], [-0.18, 1.95, -0.1], palette.green);
scene.add(group);
}
addTree(-8.8, 3.4, 0.9);
addTree(8.6, 3.5, 1.05);
addTree(5.7, -4.1, 0.75);
// ---------------------------------------------------------------------
// Source: city reservoir / public water source
// ---------------------------------------------------------------------
const reservoir = new THREE.Group();
reservoir.position.set(-7.25, 0.08, -1.45);
box(reservoir, [3.25, 0.22, 2.45], [0, 0.11, 0], palette.cream);
box(reservoir, [0.92, 1.25, 1.72], [-1.0, 0.85, 0], palette.water);
box(reservoir, [0.92, 1.5, 1.72], [0, 0.97, 0], palette.waterDark);
box(reservoir, [0.92, 1.25, 1.72], [1.0, 0.85, 0], palette.water);
box(reservoir, [3.1, 0.14, 0.22], [0, 1.62, 0.76], palette.white);
box(reservoir, [0.25, 0.5, 0.25], [1.18, 1.85, 0.76], palette.metal);
scene.add(reservoir);
addLabel({
category: "Source",
title: "City reservoir / public main",
detail: "Illustrative potable-water source",
position: new THREE.Vector3(-7.25, 2.35, -1.45),
network: "supply"
});
// ---------------------------------------------------------------------
// Water treatment placeholder
// ---------------------------------------------------------------------
const waterPlant = new THREE.Group();
waterPlant.position.set(-3.95, 0.08, -1.45);
box(waterPlant, [2.85, 0.22, 2.5], [0, 0.11, 0], palette.cream);
box(waterPlant, [0.65, 1.25, 1.45], [-0.78, 0.85, -0.15], palette.white);
box(waterPlant, [0.65, 1.45, 1.45], [0, 0.94, -0.15], palette.metal);
box(waterPlant, [0.65, 1.25, 1.45], [0.78, 0.85, -0.15], palette.white);
box(waterPlant, [0.8, 0.7, 0.8], [0, 1.95, -0.15], palette.waterDark);
box(waterPlant, [0.24, 0.25, 0.24], [0, 2.38, -0.15], palette.metal);
// Simple block sign.
box(waterPlant, [1.1, 0.36, 0.08], [0, 1.48, 0.82], palette.waterDark);
box(waterPlant, [0.65, 0.07, 0.03], [-0.12, 1.48, 0.87], palette.white);
box(waterPlant, [0.65, 0.07, 0.03], [-0.12, 1.33, 0.87], palette.white);
scene.add(waterPlant);
addLabel({
category: "Treatment placeholder",
title: "Water treatment plant",
detail: "Actual process depends on source and local rules",
position: new THREE.Vector3(-3.95, 2.55, -1.45),
network: "supply"
});
// ---------------------------------------------------------------------
// Cutaway voxel home
// ---------------------------------------------------------------------
const house = new THREE.Group();
house.position.set(1.3, 0.08, 0);
// Floor and partial walls create a readable cutaway.
box(house, [5.55, 0.18, 3.75], [0, 0.13, 0], palette.warm);
box(house, [5.55, 3.0, 0.18], [0, 1.72, -1.82], palette.cream);
box(house, [0.18, 2.35, 1.9], [-2.69, 1.35, -0.78], palette.cream);
box(house, [0.18, 2.35, 1.9], [-2.69, 1.35, 0.82], palette.cream);
box(house, [0.18, 1.0, 1.82], [2.69, 0.68, 0.82], palette.cream);
// Exposed roof frame.
box(house, [5.75, 0.16, 0.18], [0, 3.28, -1.82], palette.warm);
box(house, [0.18, 0.16, 3.75], [-2.77, 3.28, 0], palette.warm);
box(house, [0.18, 0.16, 3.75], [2.77, 3.28, 0], palette.warm);
box(house, [5.65, 0.16, 0.18], [0, 3.28, 1.82], palette.warm);
// Kitchen counter and sink.
box(house, [1.85, 0.82, 0.74], [-0.88, 0.64, -0.92], palette.warm);
box(house, [1.98, 0.12, 0.84], [-0.88, 1.11, -0.92], palette.white);
box(house, [0.66, 0.07, 0.43], [-0.88, 1.20, -0.92], palette.dark);
box(house, [0.12, 0.37, 0.12], [-1.08, 1.37, -1.15], networks.supply.pipeMaterial);
box(house, [0.42, 0.11, 0.11], [-0.88, 1.52, -1.15], networks.supply.pipeMaterial);
box(house, [0.11, 0.19, 0.11], [-0.69, 1.45, -1.15], networks.supply.pipeMaterial);
// Shower.
box(house, [1.35, 0.13, 1.28], [2.1, 0.31, -1.05], palette.white);
box(house, [0.09, 1.8, 0.09], [1.47, 1.35, -1.62], palette.metal);
box(house, [0.09, 0.09, 0.62], [1.47, 2.24, -1.32], palette.metal);
box(house, [0.42, 0.1, 0.34], [1.47, 2.2, -1.08], palette.metal);
box(house, [1.28, 1.75, 0.05], [2.13, 1.42, -1.53], palette.glass);
// Toilet.
box(house, [0.7, 0.72, 0.54], [1.76, 0.61, 0.72], palette.white);
box(house, [0.82, 0.22, 0.68], [1.76, 1.04, 0.72], palette.white);
box(house, [0.65, 0.06, 0.48], [1.76, 1.18, 0.72], palette.cream);
box(house, [0.82, 0.8, 0.2], [1.76, 0.75, 0.39], palette.white);
scene.add(house);
// Service meter at the edge of the cutaway.
box(scene, [0.42, 0.42, 0.32], [-1.35, 0.72, -1.35], palette.white);
box(scene, [0.22, 0.22, 0.08], [-1.35, 0.72, -1.17], networks.supply.pipeMaterial);
addLabel({
category: "Service connection",
title: "Meter / household supply",
detail: "Potable water enters the home",
position: new THREE.Vector3(-1.35, 1.4, -1.35),
network: "supply"
});
addLabel({
category: "Use point",
title: "Kitchen sink",
detail: "Potable water for food preparation",
position: new THREE.Vector3(-0.48, 1.85, -0.92),
network: "supply"
});
addLabel({
category: "Use point",
title: "Shower",
detail: "Potable water for personal hygiene",
position: new THREE.Vector3(3.38, 2.65, -1.05),
network: "supply"
});
addLabel({
category: "Use point",
title: "Toilet",
detail: "Potable water for flushing",
position: new THREE.Vector3(3.05, 1.65, 0.72),
network: "supply"
});
// ---------------------------------------------------------------------
// Supply network
// ---------------------------------------------------------------------
const supplyMain = createPipe(
[
[-5.55, 0.72, -1.45],
[-2.35, 0.72, -1.45],
[-1.52, 0.72, -1.45],
[-1.52, 0.72, -1.2],
[-1.12, 0.72, -1.2],
[3.45, 0.72, -1.2]
],
networks.supply,
0.15
);
const supplySink = createPipe(
[
[-0.48, 0.72, -1.2],
[-0.48, 0.72, -0.72],
[-0.48, 1.2, -0.72]
],
networks.supply,
0.12
);
const supplyShower = createPipe(
[
[3.45, 0.72, -1.2],
[3.45, 0.72, -1.05],
[3.45, 2.1, -1.05]
],
networks.supply,
0.12
);
const supplyToilet = createPipe(
[
[3.45, 0.72, -1.2],
[3.05, 0.72, 0.72],
[3.05, 0.96, 0.72]
],
networks.supply,
0.12
);
addFlow(supplyMain, networks.supply, 6, 0.23, 0.105);
addFlow(supplySink, networks.supply, 2, 0.19, 0.16);
addFlow(supplyShower, networks.supply, 2, 0.19, 0.17);
addFlow(supplyToilet, networks.supply, 2, 0.19, 0.17);
// ---------------------------------------------------------------------
// Drainage network
// ---------------------------------------------------------------------
const drainSink = createPipe(
[
[-0.48, 0.95, -0.72],
[-0.48, 0.43, -0.72],
[0.35, 0.43, -0.72],
[0.35, 0.43, 0.72]
],
networks.drainage,
0.16
);
const drainShower = createPipe(
[
[3.38, 0.32, -1.05],
[3.38, 0.43, -0.8],
[3.38, 0.43, 0.72]
],
networks.drainage,
0.16
);
const drainToilet = createPipe(
[
[3.05, 0.72, 0.72],
[3.05, 0.43, 0.72]
],
networks.drainage,
0.16
);
const drainMain = createPipe(
[
[0.35, 0.43, 0.72],
[3.05, 0.43, 0.72],
[4.35, 0.43, 0.72],
[5.25, 0.43, 0.72],
[5.25, 0.43, -0.25],
[6.15, 0.43, -0.25]
],
networks.drainage,
0.18
);
addFlow(drainSink, networks.drainage, 3, 0.24, 0.12);
addFlow(drainShower, networks.drainage, 3, 0.24, 0.13);
addFlow(drainToilet, networks.drainage, 1, 0.23, 0.18);
addFlow(drainMain, networks.drainage, 5, 0.26, 0.105);
// ---------------------------------------------------------------------
// Wastewater treatment placeholder
// ---------------------------------------------------------------------
const wastewaterPlant = new THREE.Group();
wastewaterPlant.position.set(7.55, 0.08, -0.25);
box(wastewaterPlant, [2.8, 0.22, 2.5], [0, 0.11, 0], palette.cream);
box(wastewaterPlant, [0.82, 1.18, 1.62], [-0.78, 0.81, 0], palette.white);
box(wastewaterPlant, [0.82, 1.38, 1.62], [0, 0.91, 0], palette.metal);
box(wastewaterPlant, [0.82, 1.18, 1.62], [0.78, 0.81, 0], palette.white);
box(wastewaterPlant, [0.72, 0.28, 0.72], [0, 1.78, 0], networks.drainage.pipeMaterial);
box(wastewaterPlant, [0.18, 0.48, 0.18], [0, 2.15, 0], palette.metal);
box(wastewaterPlant, [1.05, 0.35, 0.08], [0, 1.4, 0.87], networks.drainage.pipeMaterial);
scene.add(wastewaterPlant);
addLabel({
category: "Treatment placeholder",
title: "Wastewater treatment",
detail: "Sanitary wastewater leaves the home for treatment",
position: new THREE.Vector3(7.55, 2.55, -0.25),
network: "drainage"
});
addLabel({
category: "Drainage collector",
title: "Sanitary drain",
detail: "Wastewater is kept separate from the supply",
position: new THREE.Vector3(5.15, 1.0, 0.72),
network: "drainage"
});
// Neutral explanatory marker.
addLabel({
category: "Diagram boundary",
title: "Stormwater is not connected here",
detail: "Runoff and sanitary wastewater require their own design",
position: new THREE.Vector3(7.35, 0.35, 3.05),
neutral: true
});
// A disconnected storm drain reinforces the sanitary/supply separation.
const stormDrain = new THREE.Group();
stormDrain.position.set(7.35, 0.12, 3.05);
box(stormDrain, [1.2, 0.18, 0.85], [0, 0.02, 0], palette.dark);
for (let i = 0; i < 5; i++) {
box(
stormDrain,
[0.12, 0.05, 0.72],
[-0.42 + i * 0.21, 0.13, 0],
palette.metal
);
}
scene.add(stormDrain);
// ---------------------------------------------------------------------
// Camera controls implemented without Three.js add-ons
// ---------------------------------------------------------------------
const orbit = {
radius: 18.2,
phi: 1.02,
theta: 0.68,
target: new THREE.Vector3(0.25, 0.75, -0.05)
};
const defaultOrbit = {
radius: 18.2,
phi: 1.02,
theta: 0.68,
target: new THREE.Vector3(0.25, 0.75, -0.05)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const pointers = new Map();
let lastPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: previous.button
});
if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0 && distance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (lastPinchDistance / distance),
9,
29
);
}
lastPinchDistance = distance;
return;
}
if (previous.button === 2 || event.shiftKey) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(
forward,
new THREE.Vector3(0, 1, 0)
);
orbit.target.addScaledVector(right, -dx * 0.014);
orbit.target.addScaledVector(forward, dy * 0.014);
orbit.target.y = THREE.MathUtils.clamp(
orbit.target.y + dy * 0.006,
-1,
5
);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.35,
1.38
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
9,
29
);
},
{ passive: false }
);
document.querySelector("#reset").addEventListener("click", () => {
orbit.radius = defaultOrbit.radius;
orbit.phi = defaultOrbit.phi;
orbit.theta = defaultOrbit.theta;
orbit.target.copy(defaultOrbit.target);
updateCamera();
});
// ---------------------------------------------------------------------
// Network highlighting
// ---------------------------------------------------------------------
let activeNetwork = "all";
function setNetworkMaterialState(network, active) {
for (const material of [network.pipeMaterial, network.flowMaterial]) {
material.transparent = !active;
material.opacity = active ? 1 : 0.12;
material.depthWrite = active;
material.needsUpdate = true;
}
}
function updateNetworkHighlight() {
const supplyActive =
activeNetwork === "all" || activeNetwork === "supply";
const drainageActive =
activeNetwork === "all" || activeNetwork === "drainage";
setNetworkMaterialState(networks.supply, supplyActive);
setNetworkMaterialState(networks.drainage, drainageActive);
networks.supply.labels.forEach((label) => {
label.element.classList.toggle("muted", !supplyActive);
});
networks.drainage.labels.forEach((label) => {
label.element.classList.toggle("muted", !drainageActive);
});
}
document.querySelectorAll("[data-network]").forEach((button) => {
button.addEventListener("click", () => {
activeNetwork = button.dataset.network;
document.querySelectorAll("[data-network]").forEach((otherButton) => {
otherButton.classList.toggle(
"active",
otherButton.dataset.network === activeNetwork
);
});
updateNetworkHighlight();
});
});
let paused = false;
const pauseButton = document.querySelector("#pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume flow" : "Pause flow";
pauseButton.classList.toggle("active", paused);
});
// ---------------------------------------------------------------------
// Projection of DOM labels
// ---------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
const allLabels = [
...networks.supply.labels,
...networks.drainage.labels,
...scene.userData.neutralLabels
];
allLabels.forEach((label) => {
projected.copy(label.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
label.element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// ---------------------------------------------------------------------
// Animation and resize
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) elapsed += delta;
Object.values(networks).forEach((network) => {
network.flows.forEach((flow) => {
flow.meshes.forEach((marker, index) => {
const t =
(elapsed * flow.speed + index / flow.meshes.length) %
1;
marker.position.copy(samplePath(flow.path, t));
const pulse = 1 + Math.sin(elapsed * 5 + index) * 0.06;
marker.scale.setScalar(pulse);
});
});
});
updateCamera();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.render(scene, camera);
loading.classList.add("hidden");
animate();
</script>
</body>
</html>
```