Prompt specification
Build or customize the Three.js 3D scene "Harappan house drain entering a street" 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: Harappan house drain entering a street
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/harappan-house-drain-entering-a-street-x2278
Scene Description Prompt:
Create a stylized Harappan house corner with a washing platform and outlet connected to a covered street drain. Mark uncertain reconstruction details explicitly. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (harappan-house-drain-entering-a-street-x2278):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Harappan House Corner — Interpretive Voxel Reconstruction</title>
<style>
:root {
--ink: #38261f;
--paper: rgba(247, 236, 213, 0.93);
--brick: #a95535;
--teal: #287a78;
--uncertain: #e87516;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8c09a;
color: var(--ink);
font-family: Inter, "Segoe UI", system-ui, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#title-card {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
width: min(390px, calc(100vw - 36px));
padding: 15px 17px;
border-left: 5px solid var(--brick);
border-radius: 4px 12px 12px 4px;
background: var(--paper);
box-shadow: 0 8px 28px rgba(62, 39, 25, 0.18);
backdrop-filter: blur(8px);
pointer-events: none;
}
#title-card h1 {
margin: 0 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(20px, 2.2vw, 29px);
line-height: 1.08;
letter-spacing: 0.01em;
}
#title-card p {
margin: 0;
font-size: 12px;
line-height: 1.45;
color: #654b3e;
}
#uncertainty-panel {
position: fixed;
top: 18px;
right: 18px;
z-index: 12;
width: min(345px, calc(100vw - 36px));
padding: 14px 16px;
border: 1px solid rgba(232, 117, 22, 0.38);
border-radius: 12px;
background: rgba(255, 245, 227, 0.95);
box-shadow: 0 8px 28px rgba(62, 39, 25, 0.18);
backdrop-filter: blur(8px);
font-size: 12px;
line-height: 1.4;
}
#uncertainty-panel h2 {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 8px;
color: #b9550d;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 0.07em;
}
#uncertainty-panel h2::before {
content: "?";
display: grid;
place-items: center;
width: 22px;
height: 22px;
border-radius: 50%;
background: var(--uncertain);
color: white;
font-weight: 800;
}
#uncertainty-panel ul {
margin: 7px 0 0;
padding-left: 17px;
}
#uncertainty-panel li {
margin: 5px 0;
}
#uncertainty-panel .note {
margin: 10px 0 0;
padding-top: 9px;
border-top: 1px dashed rgba(181, 84, 13, 0.35);
color: #755444;
}
#labels {
position: fixed;
inset: 0;
z-index: 8;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: flex-start;
gap: 7px;
min-width: 145px;
max-width: 245px;
padding: 7px 9px;
transform: translate(-50%, -100%);
border: 1px solid rgba(42, 91, 89, 0.42);
border-radius: 7px;
background: rgba(244, 241, 222, 0.9);
box-shadow: 0 3px 12px rgba(53, 39, 30, 0.14);
color: #285e5c;
font-size: 10px;
line-height: 1.25;
white-space: normal;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 20px;
background: currentColor;
opacity: 0.65;
}
.scene-label b {
display: block;
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.scene-label small {
display: block;
margin-top: 2px;
opacity: 0.8;
}
.scene-label.uncertain {
border-color: rgba(232, 117, 22, 0.8);
background: rgba(255, 241, 213, 0.95);
color: #b9550d;
}
.question {
display: grid;
flex: 0 0 auto;
place-items: center;
width: 19px;
height: 19px;
border-radius: 50%;
background: var(--uncertain);
color: white;
font-size: 12px;
font-weight: 900;
}
#help {
position: fixed;
left: 50%;
bottom: 17px;
z-index: 11;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(56, 38, 31, 0.18);
border-radius: 999px;
background: rgba(248, 239, 221, 0.88);
box-shadow: 0 4px 16px rgba(56, 38, 31, 0.12);
color: #5b4438;
font-size: 11px;
white-space: nowrap;
pointer-events: none;
}
#legend {
position: fixed;
left: 18px;
bottom: 18px;
z-index: 11;
display: flex;
align-items: center;
gap: 14px;
padding: 9px 12px;
border-radius: 9px;
background: rgba(248, 239, 221, 0.9);
box-shadow: 0 4px 16px rgba(56, 38, 31, 0.12);
color: #5b4438;
font-size: 10px;
pointer-events: none;
}
.swatch {
display: inline-block;
width: 11px;
height: 11px;
margin-right: 5px;
vertical-align: -1px;
border-radius: 2px;
background: #aa5a39;
}
.swatch.water {
background: #4ca6a8;
}
.swatch.uncertain {
border: 2px dashed var(--uncertain);
background: transparent;
}
@media (max-width: 760px) {
#title-card {
top: 10px;
left: 10px;
padding: 11px 13px;
}
#uncertainty-panel {
top: auto;
right: 10px;
bottom: 58px;
width: 275px;
padding: 10px 12px;
font-size: 10px;
}
#uncertainty-panel h2 {
font-size: 11px;
}
#legend {
display: none;
}
#help {
bottom: 9px;
font-size: 9px;
}
.scene-label {
max-width: 190px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="labels" aria-hidden="true"></div>
<section id="title-card">
<h1>Harappan House Corner</h1>
<p>
Stylized interpretive reconstruction of a brick house, washing platform,
outlet, and covered street drain. Built from visible cuboid “voxels.”
</p>
</section>
<aside id="uncertainty-panel">
<h2>Interpretive details</h2>
<div>
Orange dashed boxes and “?” labels mark features whose precise form is
uncertain or diagrammatic:
</div>
<ul>
<li><strong>Outlet:</strong> aperture shape and fall are inferred.</li>
<li><strong>Drain covers:</strong> slab size and spacing are schematic.</li>
<li><strong>Parapet:</strong> the roof-edge profile is stylized.</li>
<li>Colors, scale, and water level are illustrative rather than measured.</li>
</ul>
<p class="note">
This is a teaching visualization, not a site-specific archaeological
reconstruction or an assertion that every shown element is attested.
</p>
</aside>
<div id="legend">
<span><i class="swatch"></i>Baked brick</span>
<span><i class="swatch water"></i>Water route</span>
<span><i class="swatch uncertain"></i>Uncertain reconstruction</span>
</div>
<div id="help">
Drag: orbit · Shift/right-drag: pan · Wheel: zoom · R: reset
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8c09a);
scene.fog = new THREE.Fog(0xd8c09a, 24, 48);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional Harappan house corner reconstruction"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(
-10,
10,
6.6,
-6.6,
0.1,
100
);
const controls = {
target: new THREE.Vector3(-0.35, 2.25, 0.35),
desiredTarget: new THREE.Vector3(-0.35, 2.25, 0.35),
radius: 18,
theta: 0.67,
desiredTheta: 0.67,
phi: 1.03,
desiredPhi: 1.03,
zoom: 0.9,
desiredZoom: 0.9
};
const home = {
target: controls.target.clone(),
theta: controls.theta,
phi: controls.phi,
zoom: controls.zoom
};
const hemisphere = new THREE.HemisphereLight(
0xfff0cf,
0x765341,
2.1
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3ae, 3.2);
sun.position.set(-9, 15, 10);
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 = 42;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ccbd0, 0.65);
fill.position.set(12, 7, -8);
scene.add(fill);
// ------------------------------------------------------------
// Deterministic random generator for repeatable block colors
// ------------------------------------------------------------
let randomSeed = 15432;
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;
}
function pick(palette) {
return palette[Math.floor(random() * palette.length)];
}
// ------------------------------------------------------------
// Cuboid helpers
// ------------------------------------------------------------
function makeBlocks(
blocks,
palette,
options = {}
) {
if (!blocks.length) return null;
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: options.roughness ?? 0.92,
metalness: options.metalness ?? 0.0,
vertexColors: true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
blocks.length
);
const dummy = new THREE.Object3D();
blocks.forEach((block, index) => {
dummy.position.set(block.x, block.y, block.z);
dummy.scale.set(block.sx, block.sy, block.sz);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color(
block.color ?? pick(palette)
);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.depthWrite === false) {
mesh.renderOrder = 2;
}
scene.add(mesh);
return mesh;
}
function addSolid(
x,
y,
z,
sx,
sy,
sz,
color,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.9,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
})
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = true;
if (options.depthWrite === false) {
mesh.depthWrite = false;
mesh.renderOrder = 2;
}
scene.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground and street
// ------------------------------------------------------------
const earthPalette = [
0x9b7452,
0xa27b56,
0x8f694b,
0xb0865d
];
addSolid(
0,
-0.19,
1.4,
23,
0.28,
16,
0x98704f,
{ castShadow: false }
);
const pavingBlocks = [];
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 15; col++) {
const x = -8.2 + col * 1.16 + (row % 2) * 0.12;
const z = 5.1 + row * 0.83;
pavingBlocks.push({
x,
y: -0.015 + random() * 0.018,
z,
sx: 1.02 + random() * 0.07,
sy: 0.11,
sz: 0.69 + random() * 0.07
});
}
}
makeBlocks(
pavingBlocks,
[0x9d927d, 0xaa9d86, 0x8f856f, 0xb2a58d, 0x958875],
{ roughness: 1 }
);
// A small paved apron around the washing area.
const apronBlocks = [];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 8; col++) {
apronBlocks.push({
x: -6.3 + col * 0.82 + (row % 2) * 0.08,
y: -0.005,
z: -1.45 + row * 0.75,
sx: 0.73,
sy: 0.09,
sz: 0.64
});
}
}
makeBlocks(apronBlocks, [0xa58b68, 0x997c5c, 0xb09270]);
// ------------------------------------------------------------
// House shell: mortar backing and baked-brick courses
// ------------------------------------------------------------
const mortarBlocks = [];
// Back wall backing, divided around the doorway and niche.
mortarBlocks.push(
{ x: -5.15, y: 3.03, z: -2.69, sx: 1.30, sy: 6.06, sz: 0.58 },
{ x: -2.025, y: 3.03, z: -2.69, sx: 2.35, sy: 6.06, sz: 0.58 },
{ x: 1.475, y: 3.03, z: -2.69, sx: 1.85, sy: 6.06, sz: 0.58 },
{ x: -3.85, y: 1.10, z: -2.69, sx: 1.30, sy: 2.20, sz: 0.58 },
{ x: -3.85, y: 4.90, z: -2.69, sx: 1.30, sy: 2.32, sz: 0.58 },
{ x: -0.15, y: 4.29, z: -2.69, sx: 1.40, sy: 3.54, sz: 0.58 }
);
// Right wall backing, divided around a high wall niche.
mortarBlocks.push(
{ x: 2.40, y: 3.03, z: -1.50, sx: 0.58, sy: 6.06, sz: 2.40 },
{ x: 2.40, y: 3.03, z: 1.85, sx: 0.58, sy: 6.06, sz: 1.70 },
{ x: 2.40, y: 1.10, z: 0.35, sx: 0.58, sy: 2.20, sz: 1.30 },
{ x: 2.40, y: 4.90, z: 0.35, sx: 0.58, sy: 2.32, sz: 1.30 }
);
makeBlocks(
mortarBlocks,
[0x705043, 0x765447],
{ roughness: 1 }
);
const brickPalette = [
0xa85635,
0xb66640,
0x984d31,
0xc07147,
0x8d4931,
0xb15c38,
0xbd7048
];
const backBricks = [];
const sideBricks = [];
const brickHeight = 0.42;
const brickLength = 0.95;
const wallHeight = 5.88;
const wallBase = 0.18;
// Back wall courses.
for (let row = 0; row < 14; row++) {
const y = wallBase + (row + 0.5) * brickHeight;
const offset = row % 2 ? brickLength * 0.5 : 0;
let cursor = -5.8 - offset;
while (cursor < 2.4) {
const left = Math.max(cursor, -5.8);
const right = Math.min(cursor + brickLength, 2.4);
if (right - left > 0.12) {
const overlapsDoor =
right > -0.85 &&
left < 0.55 &&
y < 2.72;
const overlapsNiche =
right > -4.5 &&
left < -3.2 &&
y > 2.15 &&
y < 3.84;
if (!overlapsDoor && !overlapsNiche) {
backBricks.push({
x: (left + right) * 0.5,
y,
z: -2.69,
sx: right - left - 0.035,
sy: brickHeight - 0.035,
sz: 0.66
});
}
}
cursor += brickLength;
}
}
// Right wall courses.
for (let row = 0; row < 14; row++) {
const y = wallBase + (row + 0.5) * brickHeight;
const offset = row % 2 ? brickLength * 0.5 : 0;
let cursor = -2.7 - offset;
while (cursor < 2.7) {
const front = Math.max(cursor, -2.7);
const back = Math.min(cursor + brickLength, 2.7);
if (back - front > 0.12) {
const overlapsNiche =
back > -0.3 &&
front < 1.0 &&
y > 2.15 &&
y < 3.84;
if (!overlapsNiche) {
sideBricks.push({
x: 2.40,
y,
z: (front + back) * 0.5,
sx: 0.66,
sy: brickHeight - 0.035,
sz: back - front - 0.035
});
}
}
cursor += brickLength;
}
}
makeBlocks(backBricks, brickPalette);
makeBlocks(sideBricks, brickPalette);
// Dark interior visible through the openings.
addSolid(
-0.15,
1.30,
-2.94,
1.42,
2.60,
0.14,
0x271c19
);
addSolid(
-3.85,
2.92,
-2.91,
1.25,
1.42,
0.12,
0x2d211d
);
addSolid(
2.04,
2.92,
0.35,
0.12,
1.42,
1.25,
0x2d211d
);
// Timber lintel and threshold.
addSolid(
-0.15,
2.64,
-2.29,
1.72,
0.23,
0.88,
0x5b3825
);
addSolid(
-0.15,
0.09,
-2.10,
1.55,
0.18,
0.88,
0x8b7963
);
// Stepped clay vessel in the rear niche.
const jarBlocks = [
{ x: -3.85, y: 2.38, z: -2.22, sx: 0.38, sy: 0.18, sz: 0.38 },
{ x: -3.85, y: 2.56, z: -2.22, sx: 0.58, sy: 0.25, sz: 0.48 },
{ x: -3.85, y: 2.73, z: -2.22, sx: 0.46, sy: 0.16, sz: 0.40 },
{ x: -3.85, y: 2.88, z: -2.22, sx: 0.28, sy: 0.18, sz: 0.28 },
{ x: -3.85, y: 3.00, z: -2.22, sx: 0.42, sy: 0.10, sz: 0.36 }
];
makeBlocks(
jarBlocks,
[0x9d4d30, 0xae5a34, 0x874128],
{ roughness: 0.95 }
);
// ------------------------------------------------------------
// Flat roof deck and stepped parapet
// ------------------------------------------------------------
const roofDeck = [];
for (let row = 0; row < 6; row++) {
for (let col = 0; col < 9; col++) {
roofDeck.push({
x: -5.35 + col * 0.98,
y: 6.17,
z: -2.38 + row * 0.96,
sx: 0.91,
sy: 0.22,
sz: 0.89
});
}
}
makeBlocks(
roofDeck,
[0xa9825f, 0xb48b65, 0x9d7857, 0xba916d]
);
const parapetBlocks = [];
// Front parapet, two courses.
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 9; col++) {
parapetBlocks.push({
x: -5.35 + col * 0.98 + (row % 2) * 0.08,
y: 6.42 + row * 0.42,
z: 2.76,
sx: 0.91,
sy: 0.37,
sz: 0.34
});
}
}
// Right parapet, two courses.
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 6; col++) {
parapetBlocks.push({
x: 2.47,
y: 6.42 + row * 0.42,
z: -2.38 + col * 0.98 + (row % 2) * 0.08,
sx: 0.34,
sy: 0.37,
sz: 0.91
});
}
}
// Rear and left parapet, one visible upper course.
for (let col = 0; col < 9; col++) {
parapetBlocks.push({
x: -5.35 + col * 0.98,
y: 6.42,
z: -2.76,
sx: 0.91,
sy: 0.37,
sz: 0.34
});
}
for (let col = 0; col < 6; col++) {
parapetBlocks.push({
x: -5.76,
y: 6.42,
z: -2.38 + col * 0.98,
sx: 0.34,
sy: 0.37,
sz: 0.91
});
}
makeBlocks(
parapetBlocks,
[0xa96a43, 0xb87449, 0x985b39, 0xc07b50]
);
// ------------------------------------------------------------
// Washing platform made from individual stone blocks
// ------------------------------------------------------------
const platformBase = [];
const platformTop = [];
const platformLeft = -5.3;
const platformRight = -0.9;
const platformFront = -1.2;
const platformBack = 1.5;
const columns = 6;
const rows = 4;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const x = platformLeft + (col + 0.5) * 0.733;
const z = platformFront + (row + 0.5) * 0.675;
platformBase.push({
x,
y: 0.22,
z,
sx: 0.68,
sy: 0.36,
sz: 0.62
});
// Leave an outlet approach at the front-right corner.
const outletApproach = col === columns - 1 && row >= 2;
if (!outletApproach) {
platformTop.push({
x,
y: 0.485,
z,
sx: 0.66,
sy: 0.13,
sz: 0.60
});
}
}
}
makeBlocks(
platformBase,
[0x8c806b, 0x988b75, 0x7f7563, 0xa0947d]
);
makeBlocks(
platformTop,
[0xb5a78e, 0xc0b197, 0xa99b83, 0xc7b99e],
{ roughness: 0.96 }
);
// A shallow wash basin suggested by a darker recessed surface.
addSolid(
-3.75,
0.557,
0.18,
1.70,
0.025,
0.70,
0x8e9d91,
{ castShadow: false }
);
// Outlet frame and dark aperture.
addSolid(-1.66, 0.45, 1.49, 0.14, 0.43, 0.30, 0x8c806b);
addSolid(-0.80, 0.45, 1.49, 0.14, 0.43, 0.30, 0x8c806b);
addSolid(-1.23, 0.70, 1.49, 1.00, 0.13, 0.30, 0x998d76);
addSolid(-1.23, 0.42, 1.48, 0.68, 0.30, 0.22, 0x292a25);
// ------------------------------------------------------------
// Open channel connecting the platform outlet to the drain
// ------------------------------------------------------------
const channelX = -1.23;
addSolid(
channelX,
0.015,
2.57,
0.74,
0.10,
2.22,
0x59564a
);
addSolid(
channelX - 0.44,
0.24,
2.57,
0.13,
0.42,
2.22,
0x8b806b
);
addSolid(
channelX + 0.44,
0.24,
2.57,
0.13,
0.42,
2.22,
0x8b806b
);
// ------------------------------------------------------------
// Covered street drain
// ------------------------------------------------------------
const drainZ = 4.25;
const drainLength = 13.4;
addSolid(
0,
0.015,
drainZ,
drainLength,
0.11,
0.95,
0x504e45
);
addSolid(
0,
0.19,
drainZ - 0.54,
drainLength,
0.38,
0.16,
0x8a806d
);
addSolid(
0,
0.19,
drainZ + 0.54,
drainLength,
0.38,
0.16,
0x8a806d
);
const drainCovers = [];
for (let i = 0; i < 12; i++) {
drainCovers.push({
x: -6.15 + i * 1.12,
y: 0.39,
z: drainZ,
sx: 1.03,
sy: 0.17,
sz: 1.08
});
}
makeBlocks(
drainCovers,
[0xaaa18d, 0xb5ab95, 0x9e9581, 0xc0b59d]
);
// Blocky water visible in the drain and through cover gaps.
const waterBlocks = [];
for (let i = 0; i < 14; i++) {
waterBlocks.push({
x: -6.05 + i * 0.94,
y: 0.115,
z: drainZ,
sx: 0.89,
sy: 0.07,
sz: 0.70
});
}
for (let i = 0; i < 5; i++) {
waterBlocks.push({
x: channelX,
y: 0.115,
z: 1.68 + i * 0.43,
sx: 0.55,
sy: 0.07,
sz: 0.40
});
}
makeBlocks(
waterBlocks,
[0x459a9b, 0x55a9a8, 0x3f9092],
{
roughness: 0.22,
transparent: true,
opacity: 0.76,
castShadow: false,
depthWrite: false
}
);
// ------------------------------------------------------------
// Explicit uncertainty overlays
// ------------------------------------------------------------
function addDashedBox(center, size) {
const geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(size.x, size.y, size.z)
);
const material = new THREE.LineDashedMaterial({
color: 0xff8a16,
dashSize: 0.16,
gapSize: 0.09,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
});
const line = new THREE.LineSegments(geometry, material);
line.position.copy(center);
line.computeLineDistances();
line.renderOrder = 20;
scene.add(line);
return line;
}
addDashedBox(
new THREE.Vector3(-1.23, 0.50, 1.48),
new THREE.Vector3(0.96, 0.82, 0.48)
);
addDashedBox(
new THREE.Vector3(1.45, 0.44, 4.25),
new THREE.Vector3(2.55, 0.58, 1.30)
);
addDashedBox(
new THREE.Vector3(-1.70, 6.60, 2.77),
new THREE.Vector3(8.65, 1.00, 0.42)
);
// ------------------------------------------------------------
// HTML labels projected into the 3D scene
// ------------------------------------------------------------
const labelRoot = document.getElementById("labels");
const sceneLabels = [];
function addSceneLabel(
title,
subtitle,
anchor,
uncertain = false,
offsetX = 0,
offsetY = 0
) {
const element = document.createElement("div");
element.className = `scene-label${uncertain ? " uncertain" : ""}`;
element.innerHTML = uncertain
? `<span class="question">?</span>
<span><b>${title}</b><small>${subtitle}</small></span>`
: `<span><b>${title}</b><small>${subtitle}</small></span>`;
labelRoot.appendChild(element);
sceneLabels.push({
element,
anchor: anchor.clone(),
offsetX,
offsetY
});
}
addSceneLabel(
"Washing platform",
"block-built washing surface",
new THREE.Vector3(-3.25, 1.05, 0.15),
false,
-20,
-8
);
addSceneLabel(
"Covered street drain",
"water remains beneath the slabs",
new THREE.Vector3(4.05, 0.92, 4.25),
false,
25,
-10
);
addSceneLabel(
"Uncertain: outlet",
"aperture shape and fall are schematic",
new THREE.Vector3(-1.23, 1.32, 1.48),
true,
-35,
-8
);
addSceneLabel(
"Uncertain: cover spacing",
"slab dimensions and gaps are diagrammatic",
new THREE.Vector3(1.45, 1.12, 4.25),
true,
35,
-12
);
addSceneLabel(
"Uncertain: parapet",
"roof-edge profile is stylized",
new THREE.Vector3(-1.70, 7.48, 2.77),
true,
0,
-8
);
const projected = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
for (const label of sceneLabels) {
projected.copy(label.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
label.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width + label.offsetX;
const y = (-projected.y * 0.5 + 0.5) * height + label.offsetY;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, and reset
// ------------------------------------------------------------
let dragging = false;
let dragMode = "orbit";
let lastX = 0;
let lastY = 0;
let activePointer = null;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
if (activePointer !== null) return;
activePointer = event.pointerId;
dragging = true;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (dragMode === "orbit") {
controls.desiredTheta -= dx * 0.006;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi + dy * 0.005,
0.55,
1.42
);
} else {
const worldPerPixel =
(camera.top - camera.bottom) /
(camera.zoom * renderer.domElement.clientHeight);
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1);
controls.desiredTarget
.addScaledVector(right, -dx * worldPerPixel)
.addScaledVector(up, dy * worldPerPixel);
controls.desiredTarget.x = THREE.MathUtils.clamp(
controls.desiredTarget.x,
-6,
6
);
controls.desiredTarget.y = THREE.MathUtils.clamp(
controls.desiredTarget.y,
0.5,
4.5
);
controls.desiredTarget.z = THREE.MathUtils.clamp(
controls.desiredTarget.z,
-4,
7
);
}
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredZoom = THREE.MathUtils.clamp(
controls.desiredZoom * Math.exp(-event.deltaY * 0.001),
0.62,
2.25
);
},
{ passive: false }
);
function resetCamera() {
controls.desiredTarget.copy(home.target);
controls.desiredTheta = home.theta;
controls.desiredPhi = home.phi;
controls.desiredZoom = home.zoom;
}
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = 6.6;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
function animate() {
const smoothing = 0.12;
controls.theta +=
(controls.desiredTheta - controls.theta) * smoothing;
controls.phi +=
(controls.desiredPhi - controls.phi) * smoothing;
controls.zoom +=
(controls.desiredZoom - controls.zoom) * smoothing;
controls.target.lerp(
controls.desiredTarget,
smoothing
);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```