Prompt specification
Build or customize the Three.js 3D scene "Inspect a blocked covered drain" 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: Inspect a blocked covered drain
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inspect-a-blocked-covered-drain-x2280
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Indus Valley urban drainage. Let users lift selected cover slabs in a reconstructed drainage lane. Trace illustrative water paths, locate one blockage, and show how maintenance restores the connection. Low-poly.
Working Three.js Starter (inspect-a-blocked-covered-drain-x2280):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Indus Valley — The Hidden Drain</title>
<style>
:root {
--bg: #09131d;
--panel: rgba(12, 27, 39, 0.82);
--panel-strong: rgba(13, 31, 45, 0.94);
--line: rgba(161, 210, 226, 0.18);
--text: #edf7f7;
--muted: #9db3bd;
--cyan: #65e7f2;
--cyan-dark: #1e8997;
--amber: #e9b65f;
--red: #ff785f;
--green: #82e3a3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 44%, transparent 28%, rgba(2, 8, 13, 0.18) 75%),
linear-gradient(180deg, rgba(3, 10, 16, 0.48), transparent 28%, transparent 72%, rgba(3, 9, 14, 0.68));
z-index: 2;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
header {
position: fixed;
z-index: 5;
top: 28px;
left: 30px;
pointer-events: none;
max-width: 420px;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 16px var(--cyan);
}
h1 {
margin: 11px 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(42px, 5vw, 72px);
font-weight: 400;
line-height: 0.88;
letter-spacing: -0.045em;
text-shadow: 0 3px 24px rgba(0, 0, 0, 0.45);
}
h1 span {
color: var(--amber);
font-style: italic;
}
header p {
max-width: 370px;
margin: 0;
color: #b9cad0;
font-size: 13px;
line-height: 1.55;
}
#story {
position: fixed;
z-index: 5;
left: 30px;
top: 245px;
width: 310px;
padding: 20px;
border-radius: 17px;
}
.eyebrow {
color: var(--amber);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#story h2 {
margin: 8px 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 400;
}
#story > p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.steps {
display: grid;
gap: 8px;
margin: 17px 0 0;
padding: 0;
list-style: none;
}
.step {
display: grid;
grid-template-columns: 25px 1fr;
align-items: center;
min-height: 31px;
color: #78909c;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.035em;
transition: color 180ms ease;
}
.step-number {
display: grid;
place-items: center;
width: 20px;
height: 20px;
border: 1px solid rgba(145, 180, 193, 0.25);
border-radius: 50%;
font-size: 9px;
}
.step.active {
color: var(--text);
}
.step.active .step-number {
border-color: var(--amber);
color: var(--amber);
box-shadow: 0 0 0 4px rgba(233, 182, 95, 0.07);
}
.step.done {
color: var(--cyan);
}
.step.done .step-number {
border-color: var(--cyan-dark);
background: rgba(101, 231, 242, 0.12);
color: var(--cyan);
}
#status {
position: fixed;
z-index: 5;
top: 28px;
right: 28px;
width: 272px;
padding: 18px;
border-radius: 17px;
}
.status-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.status-heading span:first-child {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status-pill {
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255, 120, 95, 0.28);
border-radius: 999px;
background: rgba(255, 120, 95, 0.08);
color: var(--red);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-pill.clear {
border-color: rgba(130, 227, 163, 0.3);
background: rgba(130, 227, 163, 0.09);
color: var(--green);
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
#conditionTitle {
margin: 0 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 400;
}
#conditionText {
min-height: 54px;
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.meter-label {
display: flex;
justify-content: space-between;
margin-top: 14px;
color: #8fa8b3;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.meter {
height: 5px;
margin-top: 6px;
overflow: hidden;
border-radius: 99px;
background: rgba(126, 167, 181, 0.13);
}
#meterFill {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan-dark), var(--cyan));
box-shadow: 0 0 12px rgba(101, 231, 242, 0.6);
transition: width 500ms ease;
}
.legend {
display: grid;
gap: 7px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #a9bdc5;
font-size: 10px;
}
.swatch {
width: 14px;
height: 4px;
border-radius: 4px;
}
.swatch.water {
background: var(--cyan);
box-shadow: 0 0 8px rgba(101, 231, 242, 0.65);
}
.swatch.cover {
background: var(--amber);
}
.swatch.block {
background: var(--red);
}
#hint {
position: fixed;
z-index: 4;
left: 50%;
bottom: 104px;
transform: translateX(-50%);
padding: 7px 12px;
border-radius: 999px;
background: rgba(5, 14, 21, 0.55);
color: #9eb2ba;
font-size: 10px;
white-space: nowrap;
pointer-events: none;
}
#controls {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 7px;
max-width: calc(100vw - 30px);
padding: 8px;
border-radius: 16px;
}
#controls button {
min-height: 43px;
padding: 0 14px;
border: 1px solid rgba(151, 191, 202, 0.18);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: #d9e7ea;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease,
opacity 140ms ease;
white-space: nowrap;
}
#controls button:hover:not(:disabled) {
transform: translateY(-2px);
border-color: rgba(101, 231, 242, 0.55);
background: rgba(101, 231, 242, 0.1);
}
#controls button:active:not(:disabled) {
transform: translateY(0);
}
#controls button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#controls button.primary {
border-color: rgba(101, 231, 242, 0.45);
background: var(--cyan);
color: #072029;
}
#controls button.primary:hover:not(:disabled) {
background: #8af1f8;
}
#controls button.amber {
border-color: rgba(233, 182, 95, 0.38);
color: #f2c77d;
}
#controls button:disabled {
cursor: not-allowed;
opacity: 0.34;
}
#controls .separator {
width: 1px;
height: 26px;
margin: 0 2px;
background: var(--line);
}
#toast {
position: fixed;
z-index: 10;
left: 50%;
top: 24px;
transform: translate(-50%, -18px);
max-width: min(460px, calc(100vw - 32px));
padding: 10px 15px;
border: 1px solid rgba(101, 231, 242, 0.25);
border-radius: 10px;
background: var(--panel-strong);
color: #dff8fa;
font-size: 11px;
line-height: 1.4;
text-align: center;
opacity: 0;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 920px) {
header {
top: 18px;
left: 18px;
}
header p {
display: none;
}
#story {
display: none;
}
#status {
top: 18px;
right: 18px;
width: 240px;
}
#hint {
bottom: 99px;
}
}
@media (max-width: 650px) {
header {
top: 14px;
left: 14px;
}
h1 {
margin-top: 8px;
font-size: 40px;
}
.brand {
font-size: 9px;
}
#status {
top: 112px;
right: 12px;
width: 206px;
padding: 13px;
}
#conditionText,
.legend {
display: none;
}
#conditionTitle {
font-size: 17px;
}
#controls {
bottom: 10px;
width: calc(100vw - 20px);
flex-wrap: wrap;
justify-content: center;
gap: 5px;
padding: 7px;
}
#controls button {
flex: 1 1 29%;
min-height: 39px;
padding: 0 8px;
font-size: 9px;
}
#controls .separator {
display: none;
}
#hint {
display: none;
}
#toast {
top: 76px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="vignette"></div>
<header>
<div class="brand">
<span class="brand-dot"></span>
Indus Valley · Water Systems
</div>
<h1>Below the<br /><span>city.</span></h1>
<p>
An interpretive reconstruction of a covered urban drainage lane.
Raise the stone covers, trace the flow, and restore a blocked connection.
</p>
</header>
<aside id="story" class="glass">
<div class="eyebrow">Interpretive reconstruction / 04</div>
<h2>A drain beneath the streets</h2>
<p>
Covered drains moved wastewater through settled urban spaces. The cyan route
and moving markers are illustrative, not a measured site plan.
</p>
<ol class="steps" aria-label="Investigation steps">
<li class="step active" id="step0">
<span class="step-number">1</span>
<span>REVEAL THE COVER SLABS</span>
</li>
<li class="step" id="step1">
<span class="step-number">2</span>
<span>TRACE THE WATER PATH</span>
</li>
<li class="step" id="step2">
<span class="step-number">3</span>
<span>LOCATE THE BLOCKAGE</span>
</li>
<li class="step" id="step3">
<span class="step-number">4</span>
<span>RESTORE THE CONNECTION</span>
</li>
</ol>
</aside>
<aside id="status" class="glass">
<div class="status-heading">
<span>Drain condition</span>
<span class="status-pill" id="statusPill">
<span class="status-dot"></span>
<span id="statusPillText">Blocked</span>
</span>
</div>
<h3 id="conditionTitle">Connection interrupted</h3>
<p id="conditionText">
A mixed plug of silt, refuse, and roots is restricting the lane.
</p>
<div class="meter-label">
<span>Downstream connection</span>
<span id="flowPercent">0%</span>
</div>
<div class="meter"><span id="meterFill"></span></div>
<div class="legend">
<div class="legend-item">
<span class="swatch water"></span>
Illustrative water route
</div>
<div class="legend-item">
<span class="swatch cover"></span>
Removable stone cover
</div>
<div class="legend-item">
<span class="swatch block"></span>
Silt and root blockage
</div>
</div>
</aside>
<div id="hint">Drag to orbit · Scroll to zoom · Click a cover slab to lift it</div>
<nav id="controls" class="glass" aria-label="Drainage controls">
<button id="traceBtn">Trace flow</button>
<button id="liftBtn" class="primary">Lift next slab</button>
<button id="locateBtn" class="amber">Locate blockage</button>
<button id="maintenanceBtn" class="primary" disabled>Clear blockage</button>
<div class="separator"></div>
<button id="lowerBtn">Lower covers</button>
<button id="resetBtn" title="Reset reconstruction">Reset</button>
</nav>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// DOM and scene
// ------------------------------------------------------------
const viewport = document.getElementById("viewport");
const toast = document.getElementById("toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09131d);
scene.fog = new THREE.Fog(0x09131d, 19, 39);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xbfe8ff, 0x563829, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0b0, 3.1);
sun.position.set(7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x76c7e8, 1.15);
fill.position.set(-8, 6, -8);
scene.add(fill);
const pickables = [];
const slabs = [];
const flowArrows = [];
const branchArrows = [];
const schematicMarkers = [];
let elapsed = 0;
let flowLimit = 0.60;
let traceBoost = 0;
let traceDone = false;
let located = false;
let isClear = false;
let phase = "blocked";
let maintenanceStart = 0;
let toastTimer = 0;
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(t) {
t = clamp(t, 0, 1);
return t * t * (3 - 2 * t);
}
function notify(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("show");
toastTimer = setTimeout(() => toast.classList.remove("show"), 2900);
}
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...extra
});
}
function addBox(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
extra = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standard(color, extra)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rodBetween(parent, start, end, radius, color) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius * 1.12, length, 5),
standard(color)
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground, plinth, and urban context
// ------------------------------------------------------------
const ground = addBox(
34,
0.32,
31,
0x0c1a22,
0,
-0.62,
0
);
ground.receiveShadow = true;
const grid = new THREE.GridHelper(30, 30, 0x3b5963, 0x233842);
grid.position.y = -0.445;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
addBox(6.1, 0.3, 19.7, 0x17262e, 0, -0.37, 0);
addBox(5.15, 0.18, 18.7, 0x302b29, 0, -0.16, 0);
// Low-poly houses and wall fragments suggest the surrounding city.
const buildingColors = [0xa66f50, 0xb9825d, 0x93654f, 0xc09268];
function addBuilding(x, z, width, depth, height, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addBox(width, height, depth, color, 0, height / 2 - 0.32, 0, group);
const roofColor = new THREE.Color(color).multiplyScalar(0.76);
addBox(
width + 0.22,
0.16,
depth + 0.22,
roofColor.getHex(),
0,
height - 0.26,
0,
group
);
// Small parapet blocks.
addBox(
width + 0.1,
0.22,
0.14,
roofColor.getHex(),
0,
height - 0.08,
depth / 2,
group
);
const facingLane = x < 0 ? width / 2 + 0.015 : -width / 2 - 0.015;
const windowColor = x < 0 ? 0x283c43 : 0x31464d;
for (let i = 0; i < 3; i++) {
addBox(
0.04,
0.42,
0.34,
windowColor,
facingLane,
0.7 + i * 0.7,
(i - 1) * depth * 0.24,
group
);
}
return group;
}
addBuilding(-6.0, -6.4, 2.7, 2.2, 3.7, buildingColors[0]);
addBuilding(-6.2, -2.5, 2.6, 2.8, 4.3, buildingColors[2]);
addBuilding(-6.3, 2.0, 2.8, 2.6, 3.5, buildingColors[1]);
addBuilding(-6.1, 6.0, 2.5, 2.5, 2.8, buildingColors[3]);
// Lower ruins on the camera-facing side avoid blocking the drain.
addBox(2.7, 0.75, 2.0, 0x765443, 6.0, 0.06, -5.5);
addBox(1.8, 0.48, 1.5, 0x684a3e, 6.1, -0.03, -1.7);
addBox(2.4, 0.34, 1.7, 0x60483d, 5.9, -0.08, 2.5);
// ------------------------------------------------------------
// Drain lane and brick walls
// ------------------------------------------------------------
// Slightly recessed central water groove.
addBox(1.72, 0.12, 18.3, 0x66503d, -1.17, -0.035, 0);
addBox(1.72, 0.12, 18.3, 0x66503d, 1.17, -0.035, 0);
addBox(0.62, 0.07, 18.3, 0x292b29, 0, -0.035, 0);
const brickTransforms = [];
for (const side of [-1, 1]) {
for (let row = 0; row < 2; row++) {
const count = row === 0 ? 10 : 9;
const start = row === 0 ? -8.1 : -7.2;
for (let i = 0; i < count; i++) {
brickTransforms.push({
x: side * 2.2,
y: 0.11 + row * 0.32,
z: start + i * 1.8,
tint: 0.83 + Math.random() * 0.2
});
}
}
}
const brickGeometry = new THREE.BoxGeometry(0.38, 0.29, 1.72);
const brickMaterial = standard(0xffffff);
const bricks = new THREE.InstancedMesh(
brickGeometry,
brickMaterial,
brickTransforms.length
);
const brickMatrix = new THREE.Matrix4();
const brickColor = new THREE.Color();
brickTransforms.forEach((brick, index) => {
brickMatrix.makeTranslation(brick.x, brick.y, brick.z);
bricks.setMatrixAt(index, brickMatrix);
brickColor.setHSL(0.055, 0.39, brick.tint * 0.39);
bricks.setColorAt(index, brickColor);
});
bricks.instanceMatrix.needsUpdate = true;
if (bricks.instanceColor) bricks.instanceColor.needsUpdate = true;
bricks.castShadow = true;
bricks.receiveShadow = true;
scene.add(bricks);
for (const side of [-1, 1]) {
addBox(0.43, 0.13, 18.2, 0x927153, side * 2.2, 0.65, 0);
}
// Downstream outlet frame.
addBox(0.45, 1.35, 0.5, 0x82654e, -1.75, 0.35, 8.55);
addBox(0.45, 1.35, 0.5, 0x82654e, 1.75, 0.35, 8.55);
addBox(3.95, 0.35, 0.5, 0x735744, 0, 0.88, 8.55);
addBox(3.05, 0.12, 1.2, 0x2b302e, 0, -0.05, 8.7);
// ------------------------------------------------------------
// Illustrative water route
// ------------------------------------------------------------
const mainCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-0.15, 0.10, -8.3),
new THREE.Vector3(-0.08, 0.11, -5.3),
new THREE.Vector3(0.12, 0.11, -2.6),
new THREE.Vector3(0.03, 0.10, -0.3),
new THREE.Vector3(0.10, 0.10, 0.8),
new THREE.Vector3(0.17, 0.10, 2.2),
new THREE.Vector3(-0.07, 0.10, 4.7),
new THREE.Vector3(0.04, 0.10, 6.6),
new THREE.Vector3(0.00, 0.10, 8.5)
],
false,
"catmullrom",
0.18
);
const flowTube = new THREE.Mesh(
new THREE.TubeGeometry(mainCurve, 90, 0.055, 5, false),
new THREE.MeshBasicMaterial({
color: 0x59dce9,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
scene.add(flowTube);
const flowLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(mainCurve.getPoints(100)),
new THREE.LineDashedMaterial({
color: 0x8cf4fb,
dashSize: 0.23,
gapSize: 0.15,
transparent: true,
opacity: 0.55
})
);
flowLine.computeLineDistances();
scene.add(flowLine);
// A faint schematic route floats just above the covers, making the
// direction understandable even before a slab is lifted.
const schematicCurve = new THREE.CatmullRomCurve3(
mainCurve.points.map(
(point) => new THREE.Vector3(point.x, 1.16, point.z)
),
false,
"catmullrom",
0.18
);
const schematicLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(schematicCurve.getPoints(100)),
new THREE.LineDashedMaterial({
color: 0x65e7f2,
dashSize: 0.24,
gapSize: 0.18,
transparent: true,
opacity: 0.24,
depthWrite: false
})
);
schematicLine.computeLineDistances();
scene.add(schematicLine);
const markerGeometry = new THREE.OctahedronGeometry(0.075, 0);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x8af5fb,
transparent: true,
opacity: 0.38,
depthWrite: false
});
for (let i = 0; i < 12; i++) {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.copy(schematicCurve.getPointAt(i / 11));
marker.position.y += 0.08;
scene.add(marker);
schematicMarkers.push(marker);
}
const arrowGeometry = new THREE.ConeGeometry(0.105, 0.29, 3);
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x79f3ff,
transparent: true,
opacity: 0.88
});
for (let i = 0; i < 17; i++) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
scene.add(arrow);
flowArrows.push(arrow);
}
function createBranch(start, end) {
const midpoint = start.clone().lerp(end, 0.52);
midpoint.y += 0.035;
const curve = new THREE.CatmullRomCurve3([
start,
midpoint,
end
]);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 22, 0.035, 5, false),
new THREE.MeshBasicMaterial({
color: 0x59dce9,
transparent: true,
opacity: 0.2,
depthWrite: false
})
);
scene.add(tube);
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
scene.add(arrow);
branchArrows.push({ arrow, curve });
}
createBranch(
new THREE.Vector3(-2.45, 0.13, -3.8),
mainCurve.getPointAt(0.27)
);
createBranch(
new THREE.Vector3(2.45, 0.13, -1.25),
mainCurve.getPointAt(0.42)
);
const blockageProgress = 0.60;
const blockPoint = mainCurve.getPointAt(blockageProgress);
const pool = new THREE.Mesh(
new THREE.CircleGeometry(0.6, 20),
new THREE.MeshBasicMaterial({
color: 0x5ee6ef,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
})
);
pool.rotation.x = -Math.PI / 2;
pool.position.set(blockPoint.x, 0.09, blockPoint.z - 0.65);
pool.scale.set(1.25, 0.7, 1);
scene.add(pool);
// ------------------------------------------------------------
// Cover slabs
// ------------------------------------------------------------
const slabBaseY = 0.87;
const slabZ = [-7.1, -5.05, -3.0, -0.95, 1.1, 3.15, 5.2, 7.25];
slabZ.forEach((z, index) => {
const group = new THREE.Group();
group.position.set(0, slabBaseY, z);
scene.add(group);
const body = addBox(
4.9,
0.26,
1.88,
index % 2 === 0 ? 0x947858 : 0x8d7154,
0,
0,
0,
group
);
body.userData = { kind: "slab", index };
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
new THREE.LineBasicMaterial({
color: 0xe9b65f,
transparent: true,
opacity: 0.8
})
);
group.add(edges);
// Recessed stone grip.
for (const x of [-0.27, 0.27]) {
const support = addBox(
0.1,
0.11,
0.13,
0x594a3d,
x,
0.18,
0,
group
);
support.userData = { kind: "slab", index };
}
const grip = addBox(
0.65,
0.09,
0.13,
0x514337,
0,
0.24,
0,
group
);
grip.userData = { kind: "slab", index };
// Shallow seams give the stone a low-poly, weathered appearance.
for (const x of [-1.42, 1.42]) {
const seam = addBox(
0.025,
0.012,
1.43,
0x604f40,
x,
0.136,
0,
group
);
seam.userData = { kind: "slab", index };
}
pickables.push(body, grip);
const guideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(2.28, 1.01, z),
new THREE.Vector3(2.28, 1.01, z)
]);
const guide = new THREE.Line(
guideGeometry,
new THREE.LineBasicMaterial({
color: 0x65e7f2,
transparent: true,
opacity: 0
})
);
scene.add(guide);
slabs.push({
index,
group,
edges,
guide,
lift: 0,
targetLift: 0
});
});
// ------------------------------------------------------------
// Blockage and inspection marker
// ------------------------------------------------------------
const blockage = new THREE.Group();
blockage.position.set(blockPoint.x, 0.04, blockPoint.z);
scene.add(blockage);
const debrisMaterial = standard(0x4a3529);
const wetMaterial = standard(0x2d302b);
const rootMaterial = standard(0x715338);
const debrisPieces = [
[-0.18, 0.28, 0.03, 0.38],
[0.25, 0.24, 0.08, 0.31],
[-0.36, 0.18, -0.18, 0.25],
[0.43, 0.16, -0.12, 0.22],
[0.02, 0.45, -0.05, 0.24]
];
debrisPieces.forEach((piece, index) => {
const [x, y, z, size] = piece;
const mesh = new THREE.Mesh(
new THREE.DodecahedronGeometry(size, 0),
index % 2 === 0 ? debrisMaterial : wetMaterial
);
mesh.position.set(x, y, z);
mesh.rotation.set(index * 0.4, index * 0.7, index * 0.25);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData = { kind: "blockage" };
blockage.add(mesh);
pickables.push(mesh);
});
const rootPaths = [
[new THREE.Vector3(-0.65, 0.16, 0.3), new THREE.Vector3(0.05, 0.32, 0.02)],
[new THREE.Vector3(0.55, 0.18, -0.35), new THREE.Vector3(-0.05, 0.38, 0.05)],
[new THREE.Vector3(-0.25, 0.1, -0.5), new THREE.Vector3(0.18, 0.35, 0.04)],
[new THREE.Vector3(0.12, 0.08, -0.55), new THREE.Vector3(0.46, 0.3, 0.02)]
];
rootPaths.forEach((path) => {
const root = rodBetween(
blockage,
path[0],
path[1],
0.055,
rootMaterial
);
root.userData = { kind: "blockage" };
pickables.push(root);
});
const marker = new THREE.Group();
marker.position.set(blockPoint.x, 0, blockPoint.z);
marker.visible = false;
scene.add(marker);
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.56, 0.035, 4, 24),
new THREE.MeshBasicMaterial({
color: 0xff785f,
transparent: true,
opacity: 0.88
})
);
markerRing.rotation.x = Math.PI / 2;
markerRing.position.y = 1.24;
markerRing.userData = { kind: "blockage" };
marker.add(markerRing);
pickables.push(markerRing);
const markerStem = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.8, 5),
new THREE.MeshBasicMaterial({ color: 0xff785f })
);
markerStem.position.y = 0.84;
marker.add(markerStem);
const markerDiamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.16, 0),
new THREE.MeshBasicMaterial({ color: 0xff785f })
);
markerDiamond.position.y = 1.52;
markerDiamond.userData = { kind: "blockage" };
marker.add(markerDiamond);
pickables.push(markerDiamond);
// ------------------------------------------------------------
// Low-poly maintenance worker
// ------------------------------------------------------------
const worker = new THREE.Group();
worker.position.set(1.08, 0.03, 7.2);
worker.visible = false;
scene.add(worker);
addBox(0.43, 0.58, 0.29, 0xe17b36, 0, 0.95, 0, worker);
addBox(0.45, 0.1, 0.31, 0xf3d269, 0, 0.96, 0, worker);
const workerHead = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 8, 5),
standard(0x9b6748)
);
workerHead.position.y = 1.42;
workerHead.castShadow = true;
worker.add(workerHead);
const helmet = new THREE.Mesh(
new THREE.SphereGeometry(0.205, 8, 4, 0, Math.PI * 2, 0, Math.PI / 2),
standard(0xf0c341)
);
helmet.position.y = 1.46;
helmet.castShadow = true;
worker.add(helmet);
addBox(0.36, 0.06, 0.22, 0xf0c341, 0, 1.46, 0.12, worker);
addBox(0.14, 0.53, 0.15, 0x243b48, -0.11, 0.39, 0, worker);
addBox(0.14, 0.53, 0.15, 0x243b48, 0.11, 0.39, 0, worker);
addBox(0.14, 0.5, 0.14, 0x243b48, 0.3, 0.91, 0, worker);
const workerArm = new THREE.Group();
workerArm.position.set(-0.27, 1.08, 0);
worker.add(workerArm);
addBox(0.13, 0.48, 0.14, 0xe17b36, 0, -0.18, 0, workerArm);
const tool = addBox(
0.055,
0.86,
0.055,
0x6e4b32,
-0.14,
-0.35,
0,
workerArm
);
tool.rotation.z = 0.45;
const broom = addBox(
0.35,
0.08,
0.13,
0xb48a4e,
-0.3,
-0.76,
0,
workerArm
);
broom.rotation.z = 0.45;
// ------------------------------------------------------------
// Custom orbit camera controls
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.25, 0),
radius: 14,
theta: 0.69,
phi: 0.94
};
const initialCamera = {
target: new THREE.Vector3(0, 0.25, 0),
radius: 14,
theta: 0.69,
phi: 0.94
};
let cameraTween = null;
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function tweenCamera(target, radius, theta, phi, duration = 0.9) {
cameraTween = {
time: 0,
duration,
fromTarget: cameraState.target.clone(),
toTarget: target.clone(),
fromRadius: cameraState.radius,
toRadius: radius,
fromTheta: cameraState.theta,
toTheta: theta,
fromPhi: cameraState.phi,
toPhi: phi
};
}
applyCamera();
const pointer = {
active: false,
moved: false,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointer.active = true;
pointer.moved = false;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active) return;
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
const totalDistance = Math.hypot(
event.clientX - pointer.startX,
event.clientY - pointer.startY
);
if (totalDistance > 5) pointer.moved = true;
if (pointer.moved) {
cameraTween = null;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.38, 1.34);
applyCamera();
}
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointer.active) return;
const wasClick = !pointer.moved;
pointer.active = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (wasClick) pickAt(event);
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.active = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.5,
23
);
applyCamera();
},
{ passive: false }
);
function pickAt(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const intersections = raycaster.intersectObjects(pickables, false);
if (!intersections.length) return;
const hit = intersections[0].object;
if (hit.userData.kind === "slab") {
toggleSlab(hit.userData.index);
} else if (hit.userData.kind === "blockage") {
locateBlockage();
}
}
// ------------------------------------------------------------
// Interface actions
// ------------------------------------------------------------
const liftBtn = document.getElementById("liftBtn");
const lowerBtn = document.getElementById("lowerBtn");
const locateBtn = document.getElementById("locateBtn");
const traceBtn = document.getElementById("traceBtn");
const maintenanceBtn = document.getElementById("maintenanceBtn");
const resetBtn = document.getElementById("resetBtn");
const revealOrder = [4, 3, 5, 2, 6, 1, 7, 0];
function toggleSlab(index) {
const slab = slabs[index];
slab.targetLift = slab.targetLift > 0.5 ? 0 : 1;
notify(
slab.targetLift > 0.5
? `Cover slab ${index + 1} raised. The lane beneath is now visible.`
: `Cover slab ${index + 1} lowered.`
);
updateUI();
}
function liftNextSlab() {
const next = revealOrder.find((index) => slabs[index].targetLift < 0.5);
if (next === undefined) {
notify("All cover slabs are already raised.");
return;
}
slabs[next].targetLift = 1;
notify(`Cover slab ${next + 1} raised for inspection.`);
updateUI();
}
function lowerCovers() {
slabs.forEach((slab) => {
slab.targetLift = 0;
});
notify("All cover slabs are being lowered.");
updateUI();
}
function traceFlow() {
traceDone = true;
traceBoost = 2.2;
tweenCamera(
new THREE.Vector3(0, 0.18, 0),
12.6,
0.69,
0.91,
1.0
);
notify(
"Cyan markers show the illustrative flow direction. Raise a slab to inspect the channel."
);
updateUI();
}
function locateBlockage() {
located = true;
marker.visible = true;
// Raise the cover directly over the obstruction for inspection.
slabs[4].targetLift = 1;
tweenCamera(
new THREE.Vector3(blockPoint.x, 0.42, blockPoint.z),
7.5,
0.48,
1.01,
0.95
);
notify(
"Blockage located: a silt-and-root plug is restricting the downstream connection."
);
updateUI();
}
function startMaintenance() {
if (!located || isClear || phase === "maintenance") return;
phase = "maintenance";
maintenanceStart = elapsed;
worker.visible = true;
worker.position.set(1.08, 0.03, 7.2);
workerArm.rotation.x = -0.35;
blockage.visible = true;
blockage.scale.setScalar(1);
notify("Maintenance underway: the obstruction is being removed.");
updateUI();
}
function resetReconstruction() {
slabs.forEach((slab) => {
slab.targetLift = 0;
});
located = false;
isClear = false;
traceDone = false;
phase = "blocked";
flowLimit = 0.6;
traceBoost = 0;
marker.visible = false;
blockage.visible = true;
blockage.scale.setScalar(1);
blockage.rotation.set(0, 0, 0);
worker.visible = false;
tweenCamera(
initialCamera.target,
initialCamera.radius,
initialCamera.theta,
initialCamera.phi,
1.0
);
notify("Reconstruction reset. Begin by raising a cover slab.");
updateUI();
}
liftBtn.addEventListener("click", liftNextSlab);
lowerBtn.addEventListener("click", lowerCovers);
locateBtn.addEventListener("click", locateBlockage);
traceBtn.addEventListener("click", traceFlow);
maintenanceBtn.addEventListener("click", startMaintenance);
resetBtn.addEventListener("click", resetReconstruction);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
liftNextSlab();
} else if (event.key.toLowerCase() === "t") {
traceFlow();
} else if (event.key.toLowerCase() === "l") {
locateBlockage();
} else if (event.key.toLowerCase() === "m") {
startMaintenance();
} else if (event.key.toLowerCase() === "r") {
resetReconstruction();
}
});
// ------------------------------------------------------------
// UI state
// ------------------------------------------------------------
const conditionTitle = document.getElementById("conditionTitle");
const conditionText = document.getElementById("conditionText");
const statusPill = document.getElementById("statusPill");
const statusPillText = document.getElementById("statusPillText");
const meterFill = document.getElementById("meterFill");
const flowPercent = document.getElementById("flowPercent");
const stepElements = [
document.getElementById("step0"),
document.getElementById("step1"),
document.getElementById("step2"),
document.getElementById("step3")
];
function updateUI() {
const liftedCount = slabs.filter((slab) => slab.targetLift > 0.5).length;
if (isClear) {
conditionTitle.textContent = "Connection restored";
conditionText.textContent =
"The obstruction is removed. Water can pass through the lane and reconnect to the downstream outlet.";
statusPillText.textContent = "Restored";
statusPill.classList.add("clear");
meterFill.style.width = "100%";
flowPercent.textContent = "100%";
} else if (phase === "maintenance") {
conditionTitle.textContent = "Maintenance underway";
conditionText.textContent =
"The worker is loosening and removing the silt-and-root plug from the drain bed.";
statusPillText.textContent = "Servicing";
statusPill.classList.remove("clear");
meterFill.style.width = "28%";
flowPercent.textContent = "28%";
} else if (located) {
conditionTitle.textContent = "Blockage located";
conditionText.textContent =
"Silt, refuse, and roots have collected around the obstruction. The downstream route is still interrupted.";
statusPillText.textContent = "Blocked";
statusPill.classList.remove("clear");
meterFill.style.width = "0%";
flowPercent.textContent = "0%";
} else {
conditionTitle.textContent = "Connection interrupted";
conditionText.textContent =
"A mixed plug of silt, refuse, and roots is restricting the lane.";
statusPillText.textContent = "Blocked";
statusPill.classList.remove("clear");
meterFill.style.width = "0%";
flowPercent.textContent = "0%";
}
maintenanceBtn.disabled = !located || isClear || phase === "maintenance";
maintenanceBtn.textContent = isClear
? "Connection restored"
: phase === "maintenance"
? "Servicing…"
: "Clear blockage";
const completed = [
liftedCount > 0,
traceDone,
located,
isClear
];
let activeSet = false;
stepElements.forEach((element, index) => {
element.classList.toggle("done", completed[index]);
if (!completed[index] && !activeSet) {
element.classList.add("active");
activeSet = true;
} else {
element.classList.remove("active");
}
});
}
updateUI();
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const up = new THREE.Vector3(0, 1, 0);
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
// Camera interpolation.
if (cameraTween) {
cameraTween.time += dt;
const t = smoothstep(cameraTween.time / cameraTween.duration);
cameraState.target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
t
);
cameraState.radius = lerp(
cameraTween.fromRadius,
cameraTween.toRadius,
t
);
cameraState.theta = lerp(
cameraTween.fromTheta,
cameraTween.toTheta,
t
);
cameraState.phi = lerp(
cameraTween.fromPhi,
cameraTween.toPhi,
t
);
applyCamera();
if (cameraTween.time >= cameraTween.duration) {
cameraTween = null;
}
}
// Slab lifting and guide lines.
slabs.forEach((slab) => {
const easing = 1 - Math.exp(-dt * 4.2);
slab.lift = lerp(slab.lift, slab.targetLift, easing);
slab.group.position.y = slabBaseY + slab.lift * 2.45;
const positions = slab.guide.geometry.attributes.position;
positions.setY(1, slab.group.position.y);
positions.needsUpdate = true;
slab.guide.material.opacity = slab.lift * 0.48;
slab.edges.material.color.lerpColors(
new THREE.Color(0xe9b65f),
new THREE.Color(0x65e7f2),
slab.lift
);
});
// Trace emphasis slowly fades.
traceBoost = Math.max(0, traceBoost - dt * 0.32);
const traceAmount = Math.min(1, traceBoost);
schematicLine.material.opacity = 0.22 + traceAmount * 0.65;
markerMaterial.opacity = 0.34 + traceAmount * 0.5;
flowTube.material.opacity = 0.22 + traceAmount * 0.25;
flowLine.material.opacity = 0.42 + traceAmount * 0.35;
schematicMarkers.forEach((item, index) => {
const pulse = 1 + Math.sin(elapsed * 3.2 + index * 0.7) * 0.22;
item.scale.setScalar(pulse * (1 + traceAmount * 0.5));
item.rotation.y += dt * 0.8;
});
// Flow advances only to the blockage until maintenance is complete.
const targetFlowLimit = isClear ? 1 : 0.60;
flowLimit = lerp(
flowLimit,
targetFlowLimit,
1 - Math.exp(-dt * 3.1)
);
flowArrows.forEach((arrow, index) => {
const normalized =
(elapsed * (isClear ? 0.058 : 0.042) + index / flowArrows.length) % 1;
const progress = normalized * flowLimit;
const point = mainCurve.getPointAt(progress);
const tangent = mainCurve.getTangentAt(progress).normalize();
arrow.position.copy(point);
arrow.position.y += 0.12;
arrow.quaternion.setFromUnitVectors(up, tangent);
const nearBlockage =
Math.abs(progress - blockageProgress) < 0.035 && !isClear;
arrow.scale.setScalar(
(nearBlockage ? 1.25 : 1) * (1 + traceAmount * 0.15)
);
});
branchArrows.forEach(({ arrow, curve }, branchIndex) => {
const progress =
(elapsed * 0.045 + branchIndex * 0.47) % 1;
const point = curve.getPointAt(progress);
const tangent = curve.getTangentAt(progress).normalize();
arrow.position.copy(point);
arrow.position.y += 0.1;
arrow.quaternion.setFromUnitVectors(up, tangent);
arrow.scale.setScalar(1 + traceAmount * 0.12);
});
pool.material.opacity = isClear
? Math.max(0, pool.material.opacity - dt * 0.5)
: 0.18 + Math.sin(elapsed * 2.5) * 0.035;
// Inspection marker pulse.
if (marker.visible) {
const pulse = 1 + Math.sin(elapsed * 3.4) * 0.12;
markerRing.scale.setScalar(pulse);
markerRing.rotation.z += dt * 0.85;
markerDiamond.rotation.y += dt * 1.4;
markerDiamond.position.y = 1.52 + Math.sin(elapsed * 3.4) * 0.08;
}
// Maintenance sequence.
if (phase === "maintenance" || phase === "reconnecting") {
const maintenanceTime = elapsed - maintenanceStart;
if (maintenanceTime < 2.25) {
const arrival = smoothstep(maintenanceTime / 2.25);
worker.position.z = lerp(
7.2,
blockPoint.z + 1.0,
arrival
);
worker.rotation.y = lerp(0, -0.35, arrival);
}
if (maintenanceTime > 1.5) {
workerArm.rotation.x =
-0.55 + Math.sin(maintenanceTime * 8.5) * 0.38;
}
if (maintenanceTime > 2.35 && !isClear) {
const removal = clamp((maintenanceTime - 2.35) / 1.1, 0, 1);
blockage.scale.setScalar(Math.max(0.001, 1 - removal));
blockage.rotation.y = removal * 0.35;
}
if (maintenanceTime >= 3.45 && !isClear) {
isClear = true;
phase = "reconnecting";
blockage.visible = false;
marker.visible = false;
notify("Obstruction removed. The downstream connection has been restored.");
updateUI();
}
if (maintenanceTime >= 5.5 && phase === "reconnecting") {
phase = "restored";
worker.visible = false;
updateUI();
}
}
renderer.render(scene, camera);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```