Prompt specification
Build or customize the Three.js 3D scene "Library Roof Garden Section" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Library Roof Garden Section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/library-roof-garden-section-x3939
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: library roof garden section. Build an original library roof garden with paths, planting zones, and drainage outlets. Show access and schematic water movement without providing structural-load certification. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (library-roof-garden-section-x3939):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Library Roof Garden</title>
<style>
:root {
color-scheme: light;
--ink: #20302d;
--muted: #65736f;
--panel: rgba(250, 252, 248, 0.92);
--line: rgba(32, 48, 45, 0.14);
--green: #347b58;
--cyan: #168da6;
--teal: #176b78;
--gold: #d99a27;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce4df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app, #viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.panel {
position: fixed;
z-index: 5;
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(28, 45, 40, 0.16);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--green);
box-shadow: 13px 0 0 #7fbd8a;
}
h1 {
margin: 0;
max-width: 280px;
font-size: clamp(25px, 3vw, 34px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.intro {
margin: 11px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 16px;
}
button {
min-height: 38px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease, border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(32, 48, 45, 0.3);
}
button.active {
color: white;
border-color: transparent;
background: var(--green);
}
button#reset {
color: var(--ink);
background: #eef2ed;
}
.legend {
display: grid;
gap: 8px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #52615d;
font-size: 11px;
}
.swatch {
width: 17px;
height: 7px;
border-radius: 2px;
background: var(--cyan);
}
.swatch.under { background: var(--teal); }
.swatch.access { background: var(--gold); }
.swatch.planting { background: #6ca46d; }
.stamp {
position: fixed;
z-index: 4;
top: 24px;
right: 24px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
background: rgba(250, 252, 248, 0.84);
box-shadow: 0 8px 30px rgba(28, 45, 40, 0.1);
color: #52615d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.hint {
position: fixed;
z-index: 4;
left: 24px;
bottom: 86px;
padding: 8px 11px;
border-radius: 9px;
background: rgba(31, 48, 44, 0.76);
color: white;
font-size: 11px;
pointer-events: none;
}
.disclaimer {
position: fixed;
z-index: 5;
left: 50%;
bottom: 18px;
width: min(760px, calc(100vw - 32px));
padding: 12px 16px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 12px;
background: rgba(250, 252, 248, 0.91);
box-shadow: 0 10px 38px rgba(28, 45, 40, 0.12);
color: #596762;
font-size: 11px;
line-height: 1.45;
text-align: center;
backdrop-filter: blur(14px);
}
.disclaimer strong {
color: #30423d;
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 15px;
}
.intro, .legend {
display: none;
}
.controls {
margin: 14px 0 0;
}
.stamp {
display: none;
}
.hint {
left: 12px;
bottom: 95px;
}
}
</style>
</head>
<body>
<div id="app">
<div id="viewport"></div>
<section class="panel" aria-label="Scene controls and legend">
<div class="eyebrow">Voxel Section · Concept 04</div>
<h1>Library Roof Garden</h1>
<p class="intro">
An original cutaway exploring planted roof zones, pedestrian access,
and schematic water movement above a library reading room.
</p>
<div class="controls">
<button id="waterToggle" class="active" aria-pressed="true">Water routes</button>
<button id="rainToggle" class="active" aria-pressed="true">Rainfall</button>
<button id="labelsToggle" class="active" aria-pressed="true">Labels</button>
<button id="reset">Reset view</button>
</div>
<div class="legend" aria-label="Diagram legend">
<div class="legend-row"><span class="swatch"></span>Schematic overland water path</div>
<div class="legend-row"><span class="swatch under"></span>Exposed under-deck drainage route</div>
<div class="legend-row"><span class="swatch access"></span>Access route and wayfinding</div>
<div class="legend-row"><span class="swatch planting"></span>Planting and habitat zones</div>
</div>
</section>
<div class="stamp">Schematic model · not load certified</div>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div class="disclaimer">
<strong>Concept visualization only.</strong>
Access and water-flow graphics are schematic. This model does not provide
structural-load, drainage-capacity, waterproofing, accessibility/code-compliance,
or engineering certification.
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce4df");
scene.fog = new THREE.Fog("#dce4df", 48, 95);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel cutaway of a library roof garden with planting, access stairs, and schematic drainage routes"
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 14, -14, 0.1, 200);
const cameraState = {
target: new THREE.Vector3(-0.4, -0.55, 0),
theta: 0.62,
phi: 1.03,
radius: 38,
zoom: 1
};
const hemi = new THREE.HemisphereLight("#f7fff5", "#64716e", 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff6df", 3.1);
sun.position.set(-15, 24, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 23;
sun.shadow.camera.bottom = -23;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b8dce5", 1.25);
fill.position.set(18, 10, -14);
scene.add(fill);
const model = new THREE.Group();
const waterTop = new THREE.Group();
const waterUnder = new THREE.Group();
const rainGroup = new THREE.Group();
const labelGroup = new THREE.Group();
scene.add(model, waterTop, waterUnder, rainGroup, labelGroup);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function materialFor(color, options = {}) {
const key = `${color}|${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
}));
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const material = color && color.isMaterial ? color : materialFor(color, options);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) mesh.rotation.set(...options.rotation);
parent.add(mesh);
return mesh;
}
let randomSeed = 938421;
function random() {
randomSeed |= 0;
randomSeed = randomSeed + 0x6D2B79F5 | 0;
let t = Math.imul(randomSeed ^ randomSeed >>> 15, 1 | randomSeed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
}
// Studio ground.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
materialFor("#d6dfda", { roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5.08;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Cutaway library structure
// -------------------------------------------------------------------------
const slabSegments = [
[-12, -10.5, -9, 9],
[-7.5, 12, -9, 9],
[-10.5, -7.5, -9, 3]
];
const layerDefinitions = [
{ h: 0.08, y: 0.00, color: "#aeb8af" },
{ h: 0.10, y: -0.09, color: "#315e63" },
{ h: 0.18, y: -0.23, color: "#d7c7a2" },
{ h: 0.70, y: -0.67, color: "#7d8989" }
];
for (const [x1, x2, z1, z2] of slabSegments) {
const width = x2 - x1;
const depth = z2 - z1;
const cx = (x1 + x2) / 2;
const cz = (z1 + z2) / 2;
for (const layer of layerDefinitions) {
box(model, [width, layer.h, depth], [cx, layer.y, cz], layer.color);
}
}
// Lower library floor, rear wall, and columns.
box(model, [23.5, 0.30, 17.4], [0, -4.76, 0], "#495b59");
box(model, [23.5, 3.72, 0.28], [0, -2.85, -8.62], "#75817b");
box(model, [0.28, 3.72, 17.4], [-11.66, -2.85, 0], "#66756f");
for (const x of [-7.0, 0.5, 8.1]) {
box(model, [0.42, 3.65, 0.42], [x, -2.86, -7.75], "#b8b7a7");
box(model, [0.72, 0.18, 0.72], [x, -4.47, -7.75], "#7c8983");
}
// Warm reading-room floor inset.
box(model, [10.2, 0.035, 5.7], [2.1, -4.59, 1.2], "#9b8166");
box(model, [7.8, 0.04, 4.3], [2.1, -4.56, 1.1], "#b29a7c");
// Bookcases facing the cutaway.
const bookColors = ["#bf684f", "#547d76", "#d2a856", "#486b82", "#8c6f91", "#70905c"];
function makeBookcase(x, z, width = 3.4) {
const baseY = -4.55;
const h = 2.55;
box(model, [width, h, 0.18], [x, baseY + h / 2, z], "#40514e");
box(model, [width + 0.18, 0.12, 0.62], [x, baseY + h, z + 0.08], "#66756e");
for (let row = 0; row < 3; row++) {
const shelfY = baseY + 0.20 + row * 0.78;
box(model, [width - 0.12, 0.08, 0.56], [x, shelfY, z + 0.08], "#8a9185");
const count = Math.floor((width - 0.3) / 0.24);
for (let i = 0; i < count; i++) {
const bw = 0.11 + random() * 0.08;
const bh = 0.38 + random() * 0.22;
const bx = x - width / 2 + 0.2 + i * 0.24;
box(
model,
[bw, bh, 0.34],
[bx, shelfY + 0.05 + bh / 2, z + 0.20],
bookColors[Math.floor(random() * bookColors.length)]
);
}
}
}
makeBookcase(-0.8, 7.65, 4.0);
makeBookcase(4.3, 7.65, 4.0);
makeBookcase(9.1, 7.30, 3.2);
// Reading tables and chairs.
for (const [x, z] of [[-0.2, 2.2], [4.4, 2.0]]) {
box(model, [3.1, 0.13, 1.35], [x, -3.83, z], "#c49b6e");
box(model, [0.16, 0.95, 0.16], [x - 1.1, -4.31, z], "#4a5c57");
box(model, [0.16, 0.95, 0.16], [x + 1.1, -4.31, z], "#4a5c57");
for (const dx of [-1.0, 1.0]) {
box(model, [0.7, 0.10, 0.7], [x + dx, -4.31, z + 1.05], "#70877a");
box(model, [0.7, 0.75, 0.10], [x + dx, -3.96, z + 1.38], "#70877a");
}
}
// Access stair descending into the reading room through an actual slab opening.
const stairX = -9.0;
const stairStepCount = 13;
for (let i = 0; i < stairStepCount; i++) {
const top = -i * 0.34;
const z = 3.22 + i * 0.39;
box(model, [2.48, 0.14, 0.43], [stairX, top - 0.07, z], "#c6b89e");
box(model, [2.42, 0.035, 0.07], [stairX, top + 0.012, z + 0.18], "#e2c566");
}
const stairAngle = Math.atan(0.34 / 0.39);
for (const x of [-10.18, -7.82]) {
const stringer = box(
model,
[0.16, 0.22, 5.7],
[x, -2.17, 5.62],
"#7e6e55"
);
stringer.rotation.x = stairAngle;
const rail = box(
model,
[0.09, 0.09, 5.95],
[x, -1.69, 5.62],
"#526b61"
);
rail.rotation.x = stairAngle;
for (let i = 0; i <= 12; i += 3) {
const top = -i * 0.34;
const z = 3.22 + i * 0.39;
box(model, [0.08, 0.92, 0.08], [x, top + 0.46, z], "#526b61");
}
}
box(model, [2.65, 0.16, 1.05], [stairX, -4.50, 8.18], "#b9aa91");
// -------------------------------------------------------------------------
// Roof paving and parapets
// -------------------------------------------------------------------------
const paverColors = ["#d8ccb8", "#cfc1aa", "#e1d7c6", "#c8bda9"];
function tilePathX(start, end, z, width = 1.65) {
for (let x = start; x <= end; x += 1.02) {
box(
model,
[0.94, 0.10, width],
[x, 0.09, z],
paverColors[Math.floor(random() * paverColors.length)]
);
}
}
function tilePathZ(zStart, zEnd, x, width = 1.55) {
for (let z = zStart; z <= zEnd; z += 1.02) {
box(
model,
[width, 0.10, 0.94],
[x, 0.09, z],
paverColors[Math.floor(random() * paverColors.length)]
);
}
}
tilePathX(-7.4, 10.5, 0, 1.75);
tilePathX(-6.8, 9.5, -6.55, 1.45);
tilePathX(-6.8, 9.5, 6.25, 1.45);
tilePathZ(-5.9, 5.7, -8.25, 1.35);
tilePathZ(-5.6, 1.8, -9.0, 1.65);
// Parapets, with a gap at the roof drain.
box(model, [23.6, 0.60, 0.26], [0, 0.34, -8.88], "#a9afa6");
box(model, [0.26, 0.60, 8.6], [-11.88, 0.34, -4.55], "#a9afa6");
box(model, [0.26, 0.60, 4.7], [-11.88, 0.34, 6.25], "#a9afa6");
box(model, [0.26, 0.60, 13.9], [11.88, 0.34, -2.45], "#a9afa6");
box(model, [0.26, 0.60, 2.7], [11.88, 0.34, 7.55], "#a9afa6");
box(model, [23.6, 0.08, 0.34], [0, 0.67, -8.88], "#d5d3c5");
box(model, [0.34, 0.08, 8.6], [-11.88, 0.67, -4.55], "#d5d3c5");
box(model, [0.34, 0.08, 4.7], [-11.88, 0.67, 6.25], "#d5d3c5");
// -------------------------------------------------------------------------
// Planting zones
// -------------------------------------------------------------------------
function makeBed(cx, cz, width, depth, style = "shrub") {
const curb = "#b7b8aa";
const soil = "#5b4937";
box(model, [width, 0.22, depth], [cx, 0.15, cz], soil);
box(model, [width + 0.22, 0.42, 0.22], [cx, 0.22, cz - depth / 2], curb);
box(model, [width + 0.22, 0.42, 0.22], [cx, 0.22, cz + depth / 2], curb);
box(model, [0.22, 0.42, depth], [cx - width / 2, 0.22, cz], curb);
box(model, [0.22, 0.42, depth], [cx + width / 2, 0.22, cz], curb);
const plantCount = style === "flowers" ? 30 : 24;
const leafColors = ["#4e8756", "#66985e", "#3f7952", "#7daa67", "#568f60"];
for (let i = 0; i < plantCount; i++) {
const x = cx + (random() - 0.5) * (width - 0.8);
const z = cz + (random() - 0.5) * (depth - 0.8);
if (style === "flowers") {
const h = 0.34 + random() * 0.30;
box(model, [0.055, h, 0.055], [x, 0.28 + h / 2, z], "#5f8b51");
const petal = ["#e8c75b", "#d98268", "#d9d1bd", "#b985a5"][Math.floor(random() * 4)];
box(model, [0.28, 0.13, 0.28], [x, 0.31 + h, z], petal);
box(model, [0.13, 0.28, 0.13], [x, 0.31 + h, z], petal);
} else if (style === "grass") {
for (let k = 0; k < 3; k++) {
const h = 0.45 + random() * 0.45;
box(
model,
[0.07, h, 0.07],
[x + (k - 1) * 0.10, 0.28 + h / 2, z],
k % 2 ? "#6e9a58" : "#87a963"
);
}
} else {
const s = 0.38 + random() * 0.30;
box(model, [0.08, 0.34, 0.08], [x, 0.45, z], "#6d6845");
box(
model,
[s, s * 0.85, s],
[x, 0.65 + s * 0.25, z],
leafColors[Math.floor(random() * leafColors.length)]
);
if (random() > 0.35) {
box(
model,
[s * 0.72, s * 0.62, s * 0.72],
[x + s * 0.22, 0.89 + s * 0.25, z - s * 0.18],
leafColors[Math.floor(random() * leafColors.length)]
);
}
}
}
}
makeBed(-3.65, -4.15, 7.55, 4.10, "shrub");
makeBed(3.65, 4.15, 7.55, 4.10, "flowers");
makeBed(7.80, -4.60, 4.15, 2.65, "grass");
makeBed(-9.35, -4.50, 2.25, 2.65, "flowers");
function makeTree(x, z, scale = 1) {
box(model, [0.34 * scale, 1.65 * scale, 0.34 * scale], [x, 1.08, z], "#806347");
box(model, [1.16 * scale, 0.95 * scale, 1.04 * scale], [x, 2.15 * scale, z], "#3f7750");
box(model, [0.94 * scale, 0.78 * scale, 0.92 * scale], [x - 0.44 * scale, 2.53 * scale, z + 0.12], "#5b9258");
box(model, [0.90 * scale, 0.80 * scale, 0.84 * scale], [x + 0.48 * scale, 2.45 * scale, z - 0.16], "#4e8653");
box(model, [0.78 * scale, 0.68 * scale, 0.74 * scale], [x + 0.08 * scale, 2.93 * scale, z - 0.05], "#76a360");
}
makeTree(-5.45, -4.35, 0.92);
makeTree(5.55, 4.25, 0.88);
function makeBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
model.add(group);
for (const y of [0.48, 0.67]) {
box(group, [2.45, 0.12, 0.20], [0, y, 0], "#a9794e");
box(group, [2.45, 0.18, 0.10], [0, y + 0.42, -0.28], "#a9794e");
}
box(group, [0.16, 0.56, 0.62], [-0.92, 0.28, 0], "#51665e");
box(group, [0.16, 0.56, 0.62], [0.92, 0.28, 0], "#51665e");
}
makeBench(1.30, -5.45);
makeBench(8.85, 2.75, Math.PI / 2);
// Compact library skylight / reading lantern.
box(model, [3.7, 0.72, 1.45], [-1.7, 0.40, -7.72], "#65837f", {
transparent: true,
opacity: 0.62,
roughness: 0.28
});
box(model, [3.95, 0.13, 0.14], [-1.7, 0.79, -7.04], "#405b58");
box(model, [3.95, 0.13, 0.14], [-1.7, 0.79, -8.40], "#405b58");
box(model, [0.14, 0.13, 1.48], [-3.56, 0.79, -7.72], "#405b58");
box(model, [0.14, 0.13, 1.48], [0.16, 0.79, -7.72], "#405b58");
// -------------------------------------------------------------------------
// Schematic access route
// -------------------------------------------------------------------------
const accessGold = materialFor("#e7b342", {
emissive: "#7a4f08",
emissiveIntensity: 0.18
});
for (let x = -8.9; x <= 9.7; x += 0.72) {
box(model, [0.36, 0.025, 0.07], [x, 0.158, 0], accessGold, { castShadow: false });
}
for (let z = 0.45; z <= 2.7; z += 0.72) {
box(model, [0.07, 0.025, 0.36], [-9.0, 0.158, z], accessGold, { castShadow: false });
}
// Wayfinding posts.
for (const [x, z] of [[-7.15, 0.95], [-7.15, -0.95], [8.85, 0.95], [8.85, -0.95]]) {
box(model, [0.13, 0.95, 0.13], [x, 0.54, z], "#52695f");
box(model, [0.19, 0.15, 0.19], [x, 1.05, z], "#e7b342");
}
// -------------------------------------------------------------------------
// Roof drainage channels and outlet
// -------------------------------------------------------------------------
const channelBorder = "#566d6d";
const channelBlue = materialFor("#27a9bd", {
emissive: "#07566a",
emissiveIntensity: 0.55,
roughness: 0.45
});
function roofChannel(size, position) {
box(waterTop, [size[0] + 0.15, 0.075, size[2] + 0.15], [position[0], 0.115, position[2]], channelBorder);
box(waterTop, size, [position[0], 0.155, position[2]], channelBlue);
}
roofChannel([17.3, 0.045, 0.18], [1.65, 0, -1.68]);
roofChannel([17.3, 0.045, 0.18], [1.65, 0, 1.68]);
roofChannel([0.18, 0.045, 8.1], [10.55, 0, 0]);
// Outlet grate at the east edge.
box(model, [0.82, 0.11, 1.24], [11.23, 0.13, 5.80], "#3e5353");
box(model, [0.62, 0.05, 1.03], [11.23, 0.20, 5.80], channelBlue);
for (let i = 0; i < 6; i++) {
box(model, [0.08, 0.055, 1.00], [10.96 + i * 0.11, 0.25, 5.80], "#34494a");
}
// -------------------------------------------------------------------------
// Exposed schematic under-deck drainage
// -------------------------------------------------------------------------
const pipeMaterial = materialFor("#1f8290", {
emissive: "#064854",
emissiveIntensity: 0.38,
roughness: 0.52
});
const pipeJoint = "#315c62";
box(waterUnder, [16.1, 0.22, 0.22], [3.0, -1.46, 9.14], pipeMaterial);
box(waterUnder, [0.22, 3.55, 0.22], [11.0, -3.20, 9.14], pipeMaterial);
box(waterUnder, [0.22, 1.35, 0.22], [-5.0, -0.78, 9.14], pipeMaterial);
box(waterUnder, [0.22, 1.35, 0.22], [5.0, -0.78, 9.14], pipeMaterial);
for (const p of [[-5, -1.46], [5, -1.46], [11, -1.46], [11, -4.86]]) {
box(waterUnder, [0.39, 0.39, 0.39], p, pipeJoint);
}
// Square inspection chambers shown on the cut face.
box(waterUnder, [0.70, 0.70, 0.18], [-5.0, -1.46, 9.10], "#28494e");
box(waterUnder, [0.70, 0.70, 0.18], [5.0, -1.46, 9.10], "#28494e");
// -------------------------------------------------------------------------
// Arrow symbols and animated flow pulses
// -------------------------------------------------------------------------
function makeTopArrow(x, z, dx, dz) {
const group = new THREE.Group();
group.position.set(x, 0.27, z);
group.rotation.y = -Math.atan2(dz, dx);
waterTop.add(group);
box(group, [0.54, 0.055, 0.11], [-0.12, 0, 0], channelBlue, { castShadow: false });
box(group, [0.43, 0.055, 0.10], [0.17, 0, 0.12], channelBlue, {
castShadow: false,
rotation: [0, -Math.PI / 4, 0]
});
box(group, [0.43, 0.055, 0.10], [0.17, 0, -0.12], channelBlue, {
castShadow: false,
rotation: [0, Math.PI / 4, 0]
});
}
makeTopArrow(-5.0, -2.80, 0, 1);
makeTopArrow(-1.2, -1.68, 1, 0);
makeTopArrow(4.7, -1.68, 1, 0);
makeTopArrow(10.55, -0.35, 0, 1);
makeTopArrow(10.55, 4.0, 0, 1);
makeTopArrow(10.95, 5.80, 1, 0);
makeTopArrow(5.0, 2.85, 0, -1);
makeTopArrow(8.1, 1.68, 1, 0);
makeTopArrow(7.80, -3.15, 0, 1);
const pulseMaterial = materialFor("#8ce9ed", {
emissive: "#2cc5d5",
emissiveIntensity: 1.25,
roughness: 0.3
});
const routes = [
[
new THREE.Vector3(-5.0, 0.31, -4.1),
new THREE.Vector3(-5.0, 0.31, -1.68),
new THREE.Vector3(10.55, 0.31, -1.68),
new THREE.Vector3(10.55, 0.31, 5.80),
new THREE.Vector3(11.25, 0.31, 5.80)
],
[
new THREE.Vector3(5.0, 0.31, 4.2),
new THREE.Vector3(5.0, 0.31, 1.68),
new THREE.Vector3(10.55, 0.31, 1.68)
],
[
new THREE.Vector3(7.80, 0.31, -4.6),
new THREE.Vector3(7.80, 0.31, -1.68)
]
];
const underRoutes = [
[
new THREE.Vector3(-5.0, -0.20, 9.29),
new THREE.Vector3(-5.0, -1.46, 9.29),
new THREE.Vector3(11.0, -1.46, 9.29),
new THREE.Vector3(11.0, -4.95, 9.29)
],
[
new THREE.Vector3(5.0, -0.20, 9.29),
new THREE.Vector3(5.0, -1.46, 9.29),
new THREE.Vector3(11.0, -1.46, 9.29)
]
];
function preparePath(points) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
return { points, lengths, total };
}
function samplePath(path, t) {
let distance = ((t % 1) + 1) % 1 * path.total;
for (let i = 0; i < path.lengths.length; i++) {
if (distance <= path.lengths[i]) {
const u = distance / path.lengths[i];
return path.points[i].clone().lerp(path.points[i + 1], u);
}
distance -= path.lengths[i];
}
return path.points[path.points.length - 1].clone();
}
const topPulses = [];
routes.forEach((route, routeIndex) => {
const path = preparePath(route);
for (let i = 0; i < 3; i++) {
const mesh = new THREE.Mesh(unitBox, pulseMaterial);
mesh.scale.set(0.15, 0.15, 0.15);
waterTop.add(mesh);
topPulses.push({ mesh, path, offset: i / 3 + routeIndex * 0.11 });
}
});
const underPulses = [];
underRoutes.forEach((route, routeIndex) => {
const path = preparePath(route);
for (let i = 0; i < 3; i++) {
const mesh = new THREE.Mesh(unitBox, pulseMaterial);
mesh.scale.set(0.16, 0.16, 0.16);
waterUnder.add(mesh);
underPulses.push({ mesh, path, offset: i / 3 + routeIndex * 0.14 });
}
});
// -------------------------------------------------------------------------
// Schematic rainfall
// -------------------------------------------------------------------------
const rainMaterial = materialFor("#68bed3", {
emissive: "#2f8ca8",
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.62,
roughness: 0.35,
castShadow: false
});
const rainDrops = [];
for (let i = 0; i < 64; i++) {
const inBedA = i < 34;
const x = inBedA
? -7.1 + random() * 7.0
: -0.1 + random() * 7.2;
const z = inBedA
? -5.9 + random() * 3.5
: 2.5 + random() * 3.2;
const mesh = new THREE.Mesh(unitBox, rainMaterial);
mesh.scale.set(0.035, 0.42 + random() * 0.22, 0.035);
mesh.position.set(x, 5.8, z);
rainGroup.add(mesh);
rainDrops.push({
mesh,
phase: random() * 5.3,
speed: 2.6 + random() * 1.8
});
}
// -------------------------------------------------------------------------
// Canvas labels
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function makeLabel(text, position, accent = "#347b58", maxWidth = 5.7) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 150;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 6, 6, 628, 138, 24);
ctx.fillStyle = "rgba(250,252,248,0.94)";
ctx.fill();
ctx.strokeStyle = "rgba(32,48,45,0.18)";
ctx.lineWidth = 4;
ctx.stroke();
roundedRect(ctx, 22, 24, 10, 102, 5);
ctx.fillStyle = accent;
ctx.fill();
ctx.fillStyle = "#253733";
ctx.font = "800 39px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 337, 76, 545);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
const width = Math.min(maxWidth, Math.max(3.4, text.length * 0.155 + 1.2));
sprite.scale.set(width, width * 150 / 640, 1);
sprite.position.set(position[0], position[1], position[2]);
sprite.renderOrder = 20;
labelGroup.add(sprite);
return sprite;
}
makeLabel("RAIN GARDEN", [-3.7, 2.85, -4.3], "#347b58", 5.2);
makeLabel("POLLINATOR BED", [7.7, 1.65, -4.65], "#6b9b59", 5.5);
makeLabel("FLOWER ZONE", [3.8, 2.55, 4.2], "#9a7251", 4.8);
makeLabel("ROOF ACCESS", [-9.0, 1.75, 3.05], "#d99a27", 4.6);
makeLabel("ACCESS ROUTE · SCHEMATIC", [0.6, 1.05, 0], "#d99a27", 6.5);
makeLabel("DRAIN OUTLET", [10.65, 1.55, 5.8], "#168da6", 4.8);
makeLabel("UNDER-DECK FLOW", [2.5, -2.45, 9.55], "#176b78", 6.0);
makeLabel("READING ROOM", [2.1, -2.55, 7.8], "#63736b", 5.4);
makeLabel("LIBRARY SKYLIGHT", [-1.7, 1.45, -7.7], "#5b7d80", 5.6);
// -------------------------------------------------------------------------
// Camera controls implemented directly
// -------------------------------------------------------------------------
function updateCamera() {
const { target, theta, phi, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(15.3, 29.5 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = panning ? "grabbing" : "move";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = forward.clone().cross(new THREE.Vector3(0, 1, 0)).normalize();
const scale = 0.022 / cameraState.zoom;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
} else {
cameraState.theta -= dx * 0.0055;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - dy * 0.0045, 0.38, 1.34);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
renderer.domElement.style.cursor = "grab";
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.15
);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") cameraState.theta -= 0.08;
else if (event.key === "ArrowRight") cameraState.theta += 0.08;
else if (event.key === "ArrowUp") cameraState.phi = Math.max(0.38, cameraState.phi - 0.06);
else if (event.key === "ArrowDown") cameraState.phi = Math.min(1.34, cameraState.phi + 0.06);
else if (event.key === "+" || event.key === "=") cameraState.zoom = Math.min(2.15, cameraState.zoom * 1.08);
else if (event.key === "-") cameraState.zoom = Math.max(0.62, cameraState.zoom / 1.08);
else return;
event.preventDefault();
updateCamera();
});
// -------------------------------------------------------------------------
// UI toggles
// -------------------------------------------------------------------------
function bindToggle(id, group) {
const button = document.getElementById(id);
button.addEventListener("click", () => {
const visible = !group.visible;
group.visible = visible;
button.classList.toggle("active", visible);
button.setAttribute("aria-pressed", String(visible));
});
}
bindToggle("waterToggle", waterTop);
bindToggle("labelsToggle", labelGroup);
// Rain has its own button, and does not alter the channel visibility.
const rainButton = document.getElementById("rainToggle");
rainButton.addEventListener("click", () => {
rainGroup.visible = !rainGroup.visible;
rainButton.classList.toggle("active", rainGroup.visible);
rainButton.setAttribute("aria-pressed", String(rainGroup.visible));
});
document.getElementById("reset").addEventListener("click", () => {
cameraState.target.set(-0.4, -0.55, 0);
cameraState.theta = 0.62;
cameraState.phi = 1.03;
cameraState.radius = 38;
cameraState.zoom = 1;
updateCamera();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
if (rainGroup.visible) {
for (const drop of rainDrops) {
drop.mesh.position.y = 5.8 - ((drop.phase + time * drop.speed) % 5.3);
}
}
if (waterTop.visible) {
for (const pulse of topPulses) {
pulse.mesh.position.copy(samplePath(pulse.path, time * 0.075 + pulse.offset));
const pulseScale = 0.13 + Math.sin(time * 5 + pulse.offset * 10) * 0.025;
pulse.mesh.scale.setScalar(pulseScale);
}
}
if (waterUnder.visible) {
for (const pulse of underPulses) {
pulse.mesh.position.copy(samplePath(pulse.path, time * 0.09 + pulse.offset));
const pulseScale = 0.14 + Math.sin(time * 5 + pulse.offset * 9) * 0.025;
pulse.mesh.scale.setScalar(pulseScale);
}
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```