Prompt specification
Build or customize the Three.js 3D scene "Indus neighborhood lane and drainage network" 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: Indus neighborhood lane and drainage network
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/indus-neighborhood-lane-and-drainage-network-x2279
Scene Description Prompt:
A low-poly Indus settlement lane with courtyard entrances and local drains joining a larger street channel. One HTML file using Three.js from cdnjs.
Working Three.js Starter (indus-neighborhood-lane-and-drainage-network-x2279):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Indus Settlement — Courtyards and Drainage</title>
<style>
:root {
--ink: #33251d;
--paper: rgba(250, 241, 220, 0.92);
--line: rgba(80, 52, 35, 0.22);
--accent: #9c4e32;
--water: #287b7a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8c39c;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: absolute;
z-index: 10;
background: var(--paper);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 14px 40px rgba(66, 43, 25, 0.14);
backdrop-filter: blur(12px);
}
#title {
top: 20px;
left: 20px;
width: min(380px, calc(100vw - 40px));
padding: 18px 20px;
}
.eyebrow {
margin-bottom: 6px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 4vw, 34px);
font-weight: 500;
line-height: 1.05;
}
#title p {
margin: 10px 0 14px;
color: #6e5949;
font-size: 13px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
font-size: 11px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
background: #b76e43;
}
.swatch.drain {
background: var(--water);
}
.swatch.channel {
background: #176b70;
}
#view-panel {
top: 20px;
right: 20px;
display: flex;
gap: 7px;
padding: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 9px;
padding: 9px 12px;
background: rgba(255, 252, 244, 0.76);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: #fffaf0;
transform: translateY(-1px);
}
#help {
right: 20px;
bottom: 20px;
padding: 10px 13px;
color: #6f5b4c;
font-size: 11px;
line-height: 1.5;
text-align: right;
}
kbd {
display: inline-block;
min-width: 20px;
margin: 0 2px;
padding: 1px 5px;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font: inherit;
font-size: 10px;
text-align: center;
}
.scene-label {
position: absolute;
z-index: 5;
left: 0;
top: 0;
pointer-events: none;
transform: translate(-50%, -50%);
padding: 7px 10px;
border: 1px solid rgba(72, 47, 31, 0.2);
border-radius: 999px;
background: rgba(255, 249, 235, 0.88);
box-shadow: 0 6px 18px rgba(64, 40, 23, 0.13);
color: #4b3528;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.025em;
white-space: nowrap;
}
.scene-label::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
border-radius: 50%;
background: var(--accent);
vertical-align: 1px;
}
.scene-label.water::before {
background: var(--water);
}
#loading {
position: absolute;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #d8c39c;
color: #644534;
font-family: Georgia, serif;
font-size: 20px;
}
@media (max-width: 720px) {
#title {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
#title p,
.legend {
display: none;
}
#view-panel {
top: auto;
right: 12px;
bottom: 12px;
}
#help {
display: none;
}
.scene-label {
font-size: 9px;
padding: 5px 8px;
}
}
</style>
</head>
<body>
<div id="loading">Carving the settlement…</div>
<section id="title" class="panel">
<div class="eyebrow">Procedural Low-Poly Reconstruction</div>
<h1>Indus settlement lane</h1>
<p>
Mud-brick courtyard compounds connect to a shared drainage spine and
the larger street channel.
</p>
<div class="legend">
<span><i class="swatch"></i> Courtyard entrances</span>
<span><i class="swatch drain"></i> Local drains</span>
<span><i class="swatch channel"></i> Street channel</span>
</div>
</section>
<nav id="view-panel" class="panel" aria-label="Camera views">
<button id="reset" type="button">Reset</button>
<button id="plan" type="button">Plan</button>
<button id="drain" type="button">Drainage</button>
</nav>
<div id="help" class="panel">
<kbd>Drag</kbd> orbit · <kbd>Shift</kbd> + drag pan · <kbd>Wheel</kbd> zoom<br>
<kbd>←</kbd><kbd>→</kbd><kbd>↑</kbd><kbd>↓</kbd> move · <kbd>T</kbd> plan
</div>
<div id="label-gate" class="scene-label">Courtyard entrance</div>
<div id="label-drain" class="scene-label water">Local drain</div>
<div id="label-channel" class="scene-label water">Main street channel</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.querySelector("#loading");
const canvas = document.createElement("canvas");
document.body.prepend(canvas);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8c39c);
scene.fog = new THREE.Fog(0xd8c39c, 34, 72);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const view = {
theta: 0.77,
phi: 1.02,
radius: 29,
target: new THREE.Vector3(0, 0.65, 0)
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
updateCamera();
// Lighting
const hemi = new THREE.HemisphereLight(0xffe8bc, 0x735b49, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffd8a0, 3.3);
sun.position.set(-12, 20, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc7c4, 0.55);
fill.position.set(14, 8, -12);
scene.add(fill);
// Materials
const mat = (color, roughness = 0.9, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness,
flatShading: true,
...extra
});
const materials = {
base: mat(0x866044),
strata: mat(0xa27a51),
earth: mat(0xb99b68),
lane: mat(0xc9ad78),
stone: mat(0x9f8967),
stoneLight: mat(0xb8a17a),
stoneDark: mat(0x76624d),
mud: mat(0xb66e43),
mudLight: mat(0xd09960),
mudDark: mat(0x8d4d34),
plaster: mat(0xd4b07b),
wood: mat(0x5b3928),
woodLight: mat(0x86603b),
dark: mat(0x302820),
indigo: mat(0x405966),
rust: mat(0x9c4e32),
ochre: mat(0xc28a42),
leaf: mat(0x607d46),
leafDark: mat(0x455c38),
water: mat(0x287b7a, 0.3, {
transparent: true,
opacity: 0.82,
metalness: 0.05
}),
glint: mat(0xb7e3d9, 0.25, {
emissive: 0x4b9e98,
emissiveIntensity: 0.45
}),
smoke: mat(0xd9d0bf, 1, {
transparent: true,
opacity: 0.2,
depthWrite: false
})
};
function box(w, h, d, material, x, y, z, parent = scene, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(x = 0, y = 0, z = 0, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
return group;
}
function makeJar(x, y, z, scale = 1, parent = scene, alternate = false) {
const profile = [
new THREE.Vector2(0, 0),
new THREE.Vector2(0.24, 0),
new THREE.Vector2(0.34, 0.1),
new THREE.Vector2(0.39, 0.43),
new THREE.Vector2(0.31, 0.64),
new THREE.Vector2(0.17, 0.72),
new THREE.Vector2(0.17, 0.87),
new THREE.Vector2(0.23, 0.89),
new THREE.Vector2(0.23, 0.94),
new THREE.Vector2(0, 0.94)
];
const jar = new THREE.Mesh(
new THREE.LatheGeometry(profile, 10),
alternate ? materials.mudDark : materials.mud
);
jar.position.set(x, y, z);
jar.scale.setScalar(scale);
jar.castShadow = true;
jar.receiveShadow = true;
parent.add(jar);
return jar;
}
function makeBasket(x, y, z, scale = 1, parent = scene) {
const basket = cylinder(
0.36 * scale,
0.28 * scale,
0.48 * scale,
10,
materials.woodLight,
x,
y + 0.24 * scale,
z,
parent
);
cylinder(
0.38 * scale,
0.38 * scale,
0.08 * scale,
10,
materials.wood,
x,
y + 0.49 * scale,
z,
parent
);
return basket;
}
// Diorama foundation and surrounding ground
const outerGround = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
mat(0xc9ad78)
);
outerGround.rotation.x = -Math.PI / 2;
outerGround.position.y = -1.58;
outerGround.receiveShadow = true;
scene.add(outerGround);
box(24, 1.35, 34, materials.base, 0, -0.82, 0);
box(24.08, 0.15, 34.08, materials.strata, 0, -0.47, 0);
box(15.5, 0.22, 32.4, materials.earth, -2.25, -0.04, 0);
box(4.05, 0.22, 32.4, materials.earth, 9.53, -0.04, 0);
// Sand lane
box(7.25, 0.07, 29.5, materials.lane, 0.48, 0.035, 0);
// Sparse irregular paving
let seed = 8241;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
for (let z = -14; z <= 14; z += 1.18) {
for (let x = -2.7; x <= 3.75; x += 1.12) {
if (random() < 0.42) continue;
const w = 0.58 + random() * 0.45;
const d = 0.48 + random() * 0.54;
const tile = box(
w,
0.035 + random() * 0.025,
d,
random() > 0.5 ? materials.stoneLight : materials.stone,
x + (random() - 0.5) * 0.2,
0.095,
z + (random() - 0.5) * 0.2
);
tile.rotation.y = (random() - 0.5) * 0.08;
}
}
// Main street channel
const channelWater = box(
1.76,
0.055,
30.2,
materials.water,
6.46,
-0.025,
0,
scene,
false
);
channelWater.receiveShadow = true;
for (const x of [5.47, 7.45]) {
for (let z = -15; z <= 15; z += 1.35) {
const stone = box(
0.38 + random() * 0.18,
0.22 + random() * 0.12,
1.1 + random() * 0.28,
random() > 0.5 ? materials.stone : materials.stoneLight,
x + (random() - 0.5) * 0.06,
0.12,
z
);
stone.rotation.y = (random() - 0.5) * 0.08;
}
}
// Drainage spine and local drains
const collectorX = 4.62;
box(0.34, 0.035, 27.2, materials.dark, collectorX, 0.098, 0, scene, false);
box(0.1, 0.09, 27.2, materials.stoneDark, collectorX - 0.23, 0.115, 0);
box(0.1, 0.09, 27.2, materials.stoneDark, collectorX + 0.23, 0.115, 0);
const localDrainZ = [];
[-8, 0, 8].forEach((cz) => {
const z = cz + 1.78;
localDrainZ.push(z);
box(7.55, 0.035, 0.32, materials.dark, 0.72, 0.108, z, scene, false);
box(7.55, 0.09, 0.1, materials.stoneDark, 0.72, 0.125, z - 0.22);
box(7.55, 0.09, 0.1, materials.stoneDark, 0.72, 0.125, z + 0.22);
// Catch basin at the courtyard outlet
box(0.6, 0.13, 0.62, materials.stoneDark, -3.02, 0.12, z);
box(0.36, 0.025, 0.36, materials.water, -3.02, 0.195, z, scene, false);
});
// Connection from the drainage spine into the larger street channel
box(1.86, 0.035, 0.36, materials.dark, 5.54, 0.108, 5.5, scene, false);
box(1.86, 0.09, 0.1, materials.stoneDark, 5.54, 0.125, 5.29);
box(1.86, 0.09, 0.1, materials.stoneDark, 5.54, 0.125, 5.71);
// Courtyard compounds
function compound(cz, index) {
const wallMaterial = index === 1 ? materials.mudLight : materials.mud;
const houseMaterial = index === 2 ? materials.mudDark : wallMaterial;
// Courtyard floor
box(3.45, 0.08, 6.55, materials.plaster, -4.94, 0.085, cz);
// Compound side walls
box(3.42, 1.35, 0.28, wallMaterial, -4.96, 0.74, cz - 3.22);
box(3.42, 1.35, 0.28, wallMaterial, -4.96, 0.74, cz + 3.22);
// Front wall with a recessed gateway
const segmentLength = 2.6;
for (const side of [-1, 1]) {
box(
0.32,
1.42,
segmentLength,
wallMaterial,
-3.2,
0.78,
cz + side * 2.1
);
}
// Gateway posts and lintel
for (const side of [-1, 1]) {
box(0.52, 2.35, 0.34, materials.mudDark, -3.2, 1.25, cz + side * 0.87);
}
box(0.58, 0.3, 2.12, materials.wood, -3.2, 2.37, cz);
box(0.42, 0.12, 1.66, materials.woodLight, -3.08, 2.55, cz);
// Woven gate mat
box(0.045, 1.35, 0.68, materials.woodLight, -2.99, 1.56, cz + 0.57);
box(0.055, 0.07, 0.72, materials.wood, -2.96, 1.78, cz + 0.57);
// House at the back of the courtyard
box(2.45, 2.75, 4.85, houseMaterial, -7.83, 1.45, cz + 0.35);
box(2.62, 0.2, 5.08, materials.mudDark, -7.83, 2.92, cz + 0.35);
// Low parapet around the roof
box(2.7, 0.27, 0.22, wallMaterial, -7.83, 3.13, cz - 2.1);
box(2.7, 0.27, 0.22, wallMaterial, -7.83, 3.13, cz + 2.8);
box(0.22, 0.27, 4.65, wallMaterial, -9.02, 3.13, cz + 0.35);
box(0.22, 0.27, 4.65, wallMaterial, -6.64, 3.13, cz + 0.35);
// Door recess on the inner facade
box(0.08, 1.58, 1.02, materials.dark, -6.56, 0.92, cz + 0.42);
box(0.15, 0.14, 1.18, materials.wood, -6.49, 1.72, cz + 0.42);
box(0.06, 1.23, 0.72, materials.indigo, -6.47, 1.02, cz + 0.63);
// Small recessed window
box(0.06, 0.5, 0.58, materials.dark, -6.56, 2.0, cz - 1.18);
box(0.1, 0.08, 0.68, materials.woodLight, -6.49, 1.73, cz - 1.18);
// Courtyard furnishings
box(1.15, 0.06, 1.65, materials.indigo, -5.45, 0.15, cz - 1.55);
box(1.25, 0.09, 0.14, materials.rust, -5.45, 0.18, cz - 0.74);
makeJar(-4.62, 0.12, cz - 2.35, 0.85);
makeJar(-4.16, 0.12, cz - 2.05, 0.58, scene, true);
makeBasket(-5.22, 0.12, cz + 2.18, 0.9);
box(0.85, 0.5, 1.15, materials.wood, -5.6, 0.37, cz + 1.9);
box(0.95, 0.09, 1.25, materials.woodLight, -5.6, 0.66, cz + 1.9);
// Roof storage jar
makeJar(-8.55, 3.23, cz + 1.9, 0.68);
if (index !== 1) {
// Small upper room
box(1.6, 1.05, 1.8, houseMaterial, -7.85, 3.57, cz + 0.1);
box(1.78, 0.12, 1.98, materials.mudDark, -7.85, 4.12, cz + 0.1);
box(0.05, 0.4, 0.42, materials.dark, -7.02, 3.65, cz + 0.1);
}
// A few decorative wall niches
for (let i = 0; i < 3; i++) {
box(
0.05,
0.28,
0.18,
materials.dark,
-3.015,
0.73,
cz - 2.7 + i * 0.36
);
}
}
compound(-8, 0);
compound(0, 1);
compound(8, 2);
// Rear settlement structures
box(3.0, 3.15, 4.4, materials.mudDark, -7.4, 1.68, -14.8);
box(3.2, 0.18, 4.6, materials.mud, -7.4, 3.31, -14.8);
box(0.08, 1.55, 1.05, materials.dark, -5.86, 0.9, -14.7);
box(0.1, 0.13, 1.2, materials.wood, -5.79, 1.7, -14.7);
// Workshops on the far side of the street channel
box(2.65, 2.35, 4.0, materials.mud, 9.85, 1.27, -7.2);
box(2.85, 0.18, 4.2, materials.mudDark, 9.85, 2.52, -7.2);
box(0.07, 1.45, 0.9, materials.dark, 8.49, 0.83, -7.2);
box(0.12, 0.12, 1.05, materials.wood, 8.42, 1.58, -7.2);
box(2.55, 2.2, 4.6, materials.mudLight, 10.0, 1.2, 8.1);
box(2.75, 0.18, 4.8, materials.mudDark, 10.0, 2.37, 8.1);
box(0.07, 1.4, 0.92, materials.dark, 8.69, 0.8, 8.1);
// Low perimeter walls
box(0.28, 0.9, 29, materials.mudDark, -10.35, 0.5, 0);
box(0.3, 0.75, 27, materials.mudDark, 11.55, 0.42, 1.5);
// Kiln and animated smoke in the southern compound
const kiln = groupAt(-4.35, 0.12, 10.15);
cylinder(0.48, 0.68, 1.1, 9, materials.mudDark, 0, 0.55, 0, kiln);
cylinder(0.31, 0.48, 0.38, 9, materials.dark, 0, 1.2, 0, kiln);
const smoke = [];
for (let i = 0; i < 6; i++) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18 + i * 0.025, 0),
materials.smoke.clone()
);
puff.position.set(-4.35, 1.5 + i * 0.35, 10.15);
scene.add(puff);
smoke.push(puff);
}
// Low-poly date palms
function makePalm(x, z, scale = 1) {
const palm = groupAt(x, 0, z);
const trunkHeight = 4.2 * scale;
for (let i = 0; i < 7; i++) {
const segment = cylinder(
0.13 * scale,
0.18 * scale,
trunkHeight / 7 + 0.03,
7,
i % 2 ? materials.wood : materials.woodLight,
Math.sin(i * 0.45) * 0.025 * scale,
(i + 0.5) * trunkHeight / 7,
0,
palm
);
segment.rotation.z = Math.sin(i * 0.6) * 0.025;
}
const crown = groupAt(0, trunkHeight, 0, palm);
function frond(length, width, angle, lift) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0, 0,
-width, 0, length * 0.48,
0, -0.25 * scale, length,
width, 0, length * 0.48
], 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const material = materials.leaf.clone();
material.side = THREE.DoubleSide;
const leaf = new THREE.Mesh(geometry, material);
leaf.rotation.y = angle;
leaf.rotation.x = lift;
leaf.castShadow = true;
crown.add(leaf);
}
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2;
frond(
(2.1 + random() * 0.65) * scale,
0.42 * scale,
angle,
-0.12 + random() * 0.12
);
}
makeJar(0.25 * scale, trunkHeight - 0.08, 0, 0.42, palm);
return palm;
}
const palms = [
makePalm(9.65, -13.1, 0.92),
makePalm(9.8, 1.2, 1.02),
makePalm(9.7, 13.0, 0.86)
];
// Reeds and tufts beside the main channel
for (let i = 0; i < 18; i++) {
const z = -14 + i * 1.62 + random() * 0.5;
const x = i % 2 ? 5.55 : 7.36;
const reed = cylinder(
0.025,
0.055,
0.55 + random() * 0.4,
5,
materials.leafDark,
x,
0.42,
z
);
reed.rotation.z = (random() - 0.5) * 0.18;
}
// Water movement
const flowMeshes = [];
function addFlow(axis, start, end, fixed, width, count, speed, phase = 0) {
for (let i = 0; i < count; i++) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(
axis === "x" ? width : 0.055,
0.025,
axis === "z" ? width : 0.055
),
materials.glint
);
mesh.position.y = 0.19;
scene.add(mesh);
flowMeshes.push({
mesh,
axis,
start,
end,
fixed,
speed,
offset: phase + i / count
});
}
}
localDrainZ.forEach((z, i) => {
addFlow("x", -2.75, collectorX - 0.1, z, 0.25, 5, 0.16, i * 0.17);
});
addFlow("z", -13.4, 13.4, collectorX, 0.24, 12, 0.11, 0.08);
addFlow("x", collectorX, 6.45, 5.5, 0.25, 4, 0.18, 0.3);
const mainGlints = [];
for (let i = 0; i < 15; i++) {
const glint = new THREE.Mesh(
new THREE.BoxGeometry(0.07 + random() * 0.04, 0.022, 0.55 + random() * 0.65),
materials.glint
);
glint.position.set(6.46 + (random() - 0.5) * 1.1, 0.02, -14 + i * 1.9);
scene.add(glint);
mainGlints.push(glint);
}
// Hover labels
const labels = [
{
element: document.querySelector("#label-gate"),
position: new THREE.Vector3(-3.15, 2.95, -8)
},
{
element: document.querySelector("#label-drain"),
position: new THREE.Vector3(0.2, 0.32, -6.22)
},
{
element: document.querySelector("#label-channel"),
position: new THREE.Vector3(6.46, 0.38, 10.5)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// Custom orbit, pan, zoom, touch and keyboard controls
const pointers = new Map();
let activeButton = null;
let shiftHeld = false;
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function pan(dx, dy) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
right.crossVectors(forward, camera.up).normalize();
up.crossVectors(right, forward).normalize();
const distance = view.radius * 0.00145;
view.target.addScaledVector(right, -dx * distance);
view.target.addScaledVector(up, dy * distance);
view.target.x = THREE.MathUtils.clamp(view.target.x, -10, 10);
view.target.y = THREE.MathUtils.clamp(view.target.y, -0.3, 5);
view.target.z = THREE.MathUtils.clamp(view.target.z, -14, 14);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
activeButton = event.button;
shiftHeld = event.shiftKey;
if (pointers.size === 2) pinchDistance = pointerDistance();
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const oldX = previous.x;
const oldY = previous.y;
const dx = event.clientX - oldX;
const dy = event.clientY - oldY;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size >= 2) {
const newDistance = pointerDistance();
if (pinchDistance > 0 && newDistance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (pinchDistance / newDistance),
8,
50
);
}
pinchDistance = newDistance;
return;
}
if (shiftHeld || activeButton === 2) {
pan(dx, dy);
} else {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.005, 0.08, 1.48);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) activeButton = null;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
8,
50
);
},
{ passive: false }
);
const keys = new Set();
window.addEventListener("keydown", (event) => {
keys.add(event.key);
if (event.key.toLowerCase() === "t") setPlanView();
if (event.key.toLowerCase() === "r") resetView();
});
window.addEventListener("keyup", (event) => keys.delete(event.key));
function resetView() {
view.theta = 0.77;
view.phi = 1.02;
view.radius = 29;
view.target.set(0, 0.65, 0);
}
function setPlanView() {
view.theta = 0;
view.phi = 0.08;
view.radius = 31;
view.target.set(0, 0, 0);
}
document.querySelector("#reset").addEventListener("click", resetView);
document.querySelector("#plan").addEventListener("click", setPlanView);
document.querySelector("#drain").addEventListener("click", () => {
view.theta = 1.02;
view.phi = 0.94;
view.radius = 13.5;
view.target.set(3.0, 0.4, 4.2);
});
function updateKeyboard() {
if (keys.has("ArrowLeft")) view.theta += 0.065;
if (keys.has("ArrowRight")) view.theta -= 0.065;
if (keys.has("ArrowUp")) view.phi = Math.max(0.08, view.phi - 0.05);
if (keys.has("ArrowDown")) view.phi = Math.min(1.48, view.phi + 0.05);
}
// Resize
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// Animation
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateKeyboard();
updateCamera();
for (const flow of flowMeshes) {
const progress = (elapsed * flow.speed + flow.offset) % 1;
const value = THREE.MathUtils.lerp(flow.start, flow.end, progress);
if (flow.axis === "x") {
flow.mesh.position.x = value;
flow.mesh.position.z = flow.fixed;
} else {
flow.mesh.position.z = value;
flow.mesh.position.x = flow.fixed;
}
}
mainGlints.forEach((glint, i) => {
glint.position.z += delta * (0.24 + (i % 3) * 0.06);
glint.material.opacity = 0.68 + Math.sin(elapsed * 2 + i) * 0.2;
if (glint.position.z > 15.2) {
glint.position.z = -15.2;
glint.position.x = 6.46 + (random() - 0.5) * 1.1;
}
});
palms.forEach((palm, index) => {
palm.rotation.z = Math.sin(elapsed * 0.55 + index) * 0.008;
palm.rotation.x = Math.cos(elapsed * 0.42 + index * 1.7) * 0.006;
});
smoke.forEach((puff, i) => {
const age = (elapsed * 0.18 + i / smoke.length) % 1;
puff.position.y = 1.45 + age * 3.2;
puff.position.x = -4.35 + Math.sin(age * 5 + i) * 0.22;
puff.position.z = 10.15 + Math.cos(age * 4 + i) * 0.14;
puff.scale.setScalar(0.55 + age * 1.7);
puff.material.opacity = 0.22 * (1 - age);
});
materials.water.opacity = 0.78 + Math.sin(elapsed * 0.75) * 0.035;
updateLabels();
renderer.render(scene, camera);
}
loading.remove();
animate();
</script>
</body>
</html>
```