Prompt specification
Build or customize the Three.js 3D scene "Tikal-inspired rainwater collection corner" 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: Tikal-inspired rainwater collection corner
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tikal-inspired-rainwater-collection-corner-x2290
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a referenced Tikal-inspired courtyard draining toward a water basin. Animate rain runoff and label the simplified geometry without claiming an exact archaeological reconstruction. A 3D cutaway view.
Working Three.js Starter (tikal-inspired-rainwater-collection-corner-x2290):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tikal-Inspired Courtyard — Runoff Cutaway</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(17, 28, 29, 0.88);
--line: rgba(183, 225, 220, 0.28);
--accent: #78d4d0;
--warm: #e5c78e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #142022;
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;
}
#title-panel {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 17px 19px 16px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(10px);
pointer-events: none;
}
#title-panel .eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#title-panel h1 {
margin: 0 0 8px;
color: #f4ead3;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(23px, 3vw, 31px);
font-weight: 500;
line-height: 1.06;
}
#title-panel p {
margin: 0;
color: #c4d0ca;
font-size: 12px;
line-height: 1.48;
}
#title-panel strong {
color: #f0d49d;
font-weight: 600;
}
#legend {
position: fixed;
z-index: 10;
left: 20px;
bottom: 20px;
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
max-width: calc(100vw - 40px);
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(17, 28, 29, 0.82);
color: #c5d1cc;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 16px;
height: 4px;
border-radius: 3px;
background: #78d4d0;
box-shadow: 0 0 8px rgba(120, 212, 208, 0.55);
}
.swatch.stone {
background: #c0a16e;
box-shadow: none;
}
.swatch.soil {
background: #9a5e40;
box-shadow: none;
}
#controls-hint {
position: fixed;
z-index: 10;
right: 20px;
bottom: 20px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(17, 28, 29, 0.78);
color: #b8c6c1;
font-size: 11px;
pointer-events: none;
}
#leaders {
position: fixed;
z-index: 3;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke: rgba(220, 235, 225, 0.58);
stroke-width: 1;
}
#leaders circle {
fill: #e9d19d;
stroke: rgba(28, 42, 42, 0.8);
stroke-width: 1.5;
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
max-width: 190px;
padding: 6px 9px;
transform: translate(-50%, -50%);
border: 1px solid rgba(209, 230, 220, 0.25);
border-left: 2px solid #e4c98f;
border-radius: 4px;
background: rgba(15, 25, 26, 0.84);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.2);
color: #e5eee9;
font-size: 11px;
line-height: 1.25;
white-space: nowrap;
backdrop-filter: blur(5px);
}
.scene-label.water {
border-left-color: var(--accent);
}
@media (max-width: 720px) {
#title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#title-panel p {
font-size: 11px;
}
#legend {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
#controls-hint {
display: none;
}
.scene-label {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="title-panel">
<div class="eyebrow">Interpretive runoff study</div>
<h1>Tikal-Inspired Courtyard</h1>
<p>
A schematic 3D cutaway showing rain moving across sloped paving,
entering a central stone runnel, and draining into an open basin.
<strong>Simplified geometry only — not an exact archaeological reconstruction.</strong>
</p>
</div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<div id="legend">
<span class="legend-item">
<span class="swatch"></span>
Animated runoff
</span>
<span class="legend-item">
<span class="swatch stone"></span>
Schematic stonework
</span>
<span class="legend-item">
<span class="swatch soil"></span>
Exposed soil section
</span>
</div>
<div id="controls-hint">
Drag: orbit · Shift/right-drag: pan · Wheel: zoom · Double-click: 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, camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x152326);
scene.fog = new THREE.FogExp2(0x152326, 0.016);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const target = new THREE.Vector3(0, 1.0, 0.35);
let currentTheta = 0.73;
let currentPhi = 1.04;
let currentRadius = 23.5;
let desiredTheta = currentTheta;
let desiredPhi = currentPhi;
let desiredRadius = currentRadius;
function updateCamera() {
const sinPhi = Math.sin(currentPhi);
camera.position.set(
target.x + currentRadius * sinPhi * Math.sin(currentTheta),
target.y + currentRadius * Math.cos(currentPhi),
target.z + currentRadius * sinPhi * Math.cos(currentTheta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xbad8d4,
0x3b281d,
1.65
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffddb0, 3.0);
sun.position.set(-9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x8fc9d5, 0.8);
rim.position.set(11, 8, -10);
scene.add(rim);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const limestone = new THREE.MeshStandardMaterial({
color: 0xb99c69,
roughness: 0.93,
metalness: 0.01
});
const paleStone = new THREE.MeshStandardMaterial({
color: 0xd0b887,
roughness: 0.9
});
const darkStone = new THREE.MeshStandardMaterial({
color: 0x756246,
roughness: 0.96
});
const doorway = new THREE.MeshStandardMaterial({
color: 0x171b18,
roughness: 1
});
const clay = new THREE.MeshStandardMaterial({
color: 0x9c7657,
roughness: 1
});
const redSoil = new THREE.MeshStandardMaterial({
color: 0x985538,
roughness: 1
});
const rubble = new THREE.MeshStandardMaterial({
color: 0x76654e,
roughness: 1
});
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x318f99,
emissive: 0x0b3438,
emissiveIntensity: 0.45,
roughness: 0.24,
metalness: 0.05,
transparent: true,
opacity: 0.78
});
function addBox(width, height, depth, x, y, z, material, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function random(min, max) {
return min + Math.random() * (max - min);
}
function courtY(x, z) {
// A modest longitudinal fall plus a slight inward cross-fall.
return (
0.52 -
(z + 4.5) * 0.035 +
Math.min(Math.abs(x), 7) * 0.02
);
}
function channelY(z) {
return courtY(0, z) - 0.13;
}
// ------------------------------------------------------------
// Ground and exposed cutaway section
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0x26332e,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.23;
ground.receiveShadow = true;
scene.add(ground);
// Layered foundation: lower clay, red soil, upper compacted fill,
// and a thin rubble bedding course.
addBox(13.8, 0.8, 10.0, 0, -1.8, 0, clay);
addBox(13.8, 0.7, 10.0, 0, -1.05, 0, redSoil);
addBox(13.8, 0.55, 10.0, 0, -0.425, 0, rubble);
addBox(13.8, 0.15, 10.0, 0, -0.075, 0, darkStone);
// Visible foundation stones on the front cut face, leaving an
// opening at the center for the drainage outlet.
for (let side = -1; side <= 1; side += 2) {
for (let i = 0; i < 7; i++) {
const x = side * (0.69 + i * 0.94);
addBox(
0.88,
0.48,
0.18,
x,
-0.42,
5.08,
i % 2 === 0 ? limestone : darkStone
);
}
}
// Exposed right side of the cutaway.
for (let i = 0; i < 10; i++) {
addBox(
0.18,
0.48,
0.88,
6.96,
-0.42,
-4.45 + i * 0.98,
i % 2 === 0 ? limestone : darkStone
);
}
// ------------------------------------------------------------
// Sloped stone paving
// ------------------------------------------------------------
const paverGeometry = new THREE.BoxGeometry(0.93, 0.14, 0.93);
const paverMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
});
const paverCount = 14 * 10;
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
paverCount
);
pavers.castShadow = true;
pavers.receiveShadow = true;
const dummy = new THREE.Object3D();
const paverColor = new THREE.Color();
let paverIndex = 0;
for (const side of [-1, 1]) {
for (let column = 0; column < 7; column++) {
const x = side * (0.49 + column * 0.98);
for (let row = 0; row < 10; row++) {
const z = -4.25 + row * 0.98;
const y = courtY(x, z);
dummy.position.set(x, y - 0.07, z);
dummy.rotation.set(
random(-0.004, 0.004),
random(-0.012, 0.012),
random(-0.004, 0.004)
);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
paverColor.setHSL(
random(0.095, 0.115),
random(0.25, 0.39),
random(0.43, 0.57)
);
pavers.setColorAt(paverIndex, paverColor);
paverIndex++;
}
}
}
pavers.instanceMatrix.needsUpdate = true;
pavers.instanceColor.needsUpdate = true;
scene.add(pavers);
// ------------------------------------------------------------
// Central stone runnel
// ------------------------------------------------------------
const runnelStart = -4.45;
const runnelEnd = 5.05;
const runnelSegments = 19;
const runnelLength =
(runnelEnd - runnelStart) / runnelSegments;
const channelFloor = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
darkStone,
runnelSegments
);
const channelKerbs = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
limestone,
runnelSegments * 2
);
const channelWater = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
waterMaterial,
runnelSegments
);
for (let i = 0; i < runnelSegments; i++) {
const z = runnelStart + (i + 0.5) * runnelLength;
dummy.position.set(0, channelY(z) - 0.04, z);
dummy.rotation.set(Math.atan(0.035), 0, 0);
dummy.scale.set(0.58, 0.08, runnelLength * 0.94);
dummy.updateMatrix();
channelFloor.setMatrixAt(i, dummy.matrix);
dummy.position.set(0, channelY(z) + 0.045, z);
dummy.scale.set(0.34, 0.025, runnelLength * 0.96);
dummy.updateMatrix();
channelWater.setMatrixAt(i, dummy.matrix);
for (let side = -1; side <= 1; side += 2) {
const kerbIndex = i * 2 + (side === -1 ? 0 : 1);
dummy.position.set(side * 0.37, channelY(z) + 0.02, z);
dummy.scale.set(0.14, 0.14, runnelLength * 0.97);
dummy.updateMatrix();
channelKerbs.setMatrixAt(kerbIndex, dummy.matrix);
}
}
channelFloor.castShadow = true;
channelFloor.receiveShadow = true;
channelKerbs.castShadow = true;
channelKerbs.receiveShadow = true;
channelWater.receiveShadow = true;
scene.add(channelFloor, channelKerbs, channelWater);
// ------------------------------------------------------------
// Simplified stepped sanctuary and flank markers
// ------------------------------------------------------------
const tiers = [
{ w: 9.6, h: 0.70, d: 4.5, y: 0.83 },
{ w: 8.1, h: 0.65, d: 3.9, y: 1.48 },
{ w: 6.7, h: 0.62, d: 3.4, y: 2.10 },
{ w: 5.4, h: 0.60, d: 2.8, y: 2.70 }
];
tiers.forEach((tier, index) => {
addBox(
tier.w,
tier.h,
tier.d,
0,
tier.y,
-6.75,
index % 2 === 0 ? limestone : paleStone
);
});
// Sanctuary body.
addBox(4.1, 2.25, 1.75, 0, 4.12, -6.85, paleStone);
// Dark, simplified doorway.
addBox(1.18, 1.65, 0.08, 0, 3.94, -5.94, doorway, false);
// Lintel and facade blocks.
addBox(1.85, 0.28, 0.25, 0, 4.92, -5.92, limestone);
addBox(0.42, 1.95, 0.26, -1.46, 4.08, -5.90, limestone);
addBox(0.42, 1.95, 0.26, 1.46, 4.08, -5.90, limestone);
// Simplified roof crest, deliberately non-specific.
for (let i = 0; i < 5; i++) {
addBox(
0.48,
0.65 + (i % 2) * 0.18,
0.48,
-1.05 + i * 0.52,
5.48 + (i % 2) * 0.08,
-6.9,
limestone
);
}
// Low front stair at the base of the stepped platform.
for (let i = 0; i < 4; i++) {
addBox(
3.2 - i * 0.18,
0.16,
0.52,
0,
0.58 + i * 0.16,
-4.63 + i * 0.48,
i % 2 === 0 ? paleStone : limestone
);
}
// Simplified stela-like markers; no glyphs or replica claims.
for (const x of [-4.65, 4.65]) {
const baseY = courtY(x, -2.25);
addBox(0.9, 0.28, 0.85, x, baseY + 0.14, -2.25, darkStone);
addBox(0.58, 1.95, 0.42, x, baseY + 1.22, -2.25, limestone);
for (let i = 0; i < 4; i++) {
addBox(
0.34,
0.07,
0.035,
x,
baseY + 0.72 + i * 0.27,
-2.025,
darkStone,
false
);
}
}
// ------------------------------------------------------------
// Open retention basin
// ------------------------------------------------------------
// Basin support / lower cutaway mass.
addBox(7.25, 0.85, 3.75, 0, -1.62, 6.65, redSoil);
addBox(6.9, 0.28, 3.45, 0, -0.82, 6.65, limestone);
// Side walls.
addBox(0.38, 1.28, 3.45, -3.28, -0.22, 6.65, paleStone);
addBox(0.38, 1.28, 3.45, 3.28, -0.22, 6.65, paleStone);
// Rear wall is split to leave a central inlet.
addBox(2.72, 1.25, 0.38, -1.88, -0.22, 5.02, paleStone);
addBox(2.72, 1.25, 0.38, 1.88, -0.22, 5.02, paleStone);
// Low front wall makes the basin section readable.
addBox(6.95, 0.42, 0.38, 0, -0.61, 8.27, limestone);
// Water surface.
const basinWater = new THREE.Mesh(
new THREE.PlaneGeometry(6.18, 2.75),
waterMaterial
);
basinWater.rotation.x = -Math.PI / 2;
basinWater.position.set(0, -0.365, 6.67);
basinWater.receiveShadow = true;
scene.add(basinWater);
// ------------------------------------------------------------
// Rain
// ------------------------------------------------------------
const rainCount = 220;
const rainPositions = new Float32Array(rainCount * 2 * 3);
const rainGeometry = new THREE.BufferGeometry();
rainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(rainPositions, 3)
);
const rainMaterial = new THREE.LineBasicMaterial({
color: 0xc1edf0,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const rain = new THREE.LineSegments(rainGeometry, rainMaterial);
rain.frustumCulled = false;
scene.add(rain);
const rainDrops = Array.from({ length: rainCount }, () => ({
x: random(-7.2, 7.2),
y: random(0.2, 8.8),
z: random(-4.6, 8.0),
speed: random(6.5, 10.5),
length: random(0.22, 0.48)
}));
function updateRain(dt) {
for (let i = 0; i < rainCount; i++) {
const drop = rainDrops[i];
drop.y -= drop.speed * dt;
drop.x -= 0.24 * dt;
if (drop.y < -0.1) {
drop.x = random(-7.2, 7.2);
drop.y = random(7.5, 9.3);
drop.z = random(-4.6, 8.0);
}
const index = i * 6;
rainPositions[index] = drop.x;
rainPositions[index + 1] = drop.y;
rainPositions[index + 2] = drop.z;
rainPositions[index + 3] = drop.x + 0.035;
rainPositions[index + 4] = drop.y - drop.length;
rainPositions[index + 5] = drop.z;
}
rainGeometry.attributes.position.needsUpdate = true;
}
// ------------------------------------------------------------
// Runoff tracers: paving → runnel → basin
// ------------------------------------------------------------
const runoffCount = 42;
const runoffGeometry = new THREE.SphereGeometry(0.065, 7, 5);
const runoffMaterial = new THREE.MeshBasicMaterial({
color: 0x8ce6e1,
transparent: true,
opacity: 0.9
});
const runoff = new THREE.InstancedMesh(
runoffGeometry,
runoffMaterial,
runoffCount
);
runoff.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
runoff.frustumCulled = false;
scene.add(runoff);
const runoffPaths = [];
for (let i = 0; i < runoffCount; i++) {
const side = Math.random() > 0.5 ? 1 : -1;
const startX = side * random(1.0, 6.25);
const startZ = random(-3.9, 3.65);
const basinX = random(-2.7, 2.7);
const basinZ = random(5.7, 7.8);
const points = [
new THREE.Vector3(
startX,
courtY(startX, startZ) + 0.09,
startZ
),
new THREE.Vector3(
side * 0.57,
courtY(side * 0.57, startZ) + 0.09,
startZ
),
new THREE.Vector3(
0,
channelY(startZ) + 0.10,
startZ + 0.18
),
new THREE.Vector3(
0,
channelY(4.70) + 0.10,
4.70
),
new THREE.Vector3(
0,
-0.18,
5.28
),
new THREE.Vector3(
basinX,
-0.29,
basinZ
)
];
runoffPaths.push({
curve: new THREE.CatmullRomCurve3(
points,
false,
"centripetal",
0.5
),
offset: Math.random(),
speed: random(0.036, 0.064)
});
}
// Brighter moving dashes within the narrow runnel.
const flowCount = 25;
const flowDashes = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.05, 6, 4),
new THREE.MeshBasicMaterial({
color: 0xb0fffa,
transparent: true,
opacity: 0.85
}),
flowCount
);
flowDashes.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
flowDashes.frustumCulled = false;
scene.add(flowDashes);
function updateRunoff(elapsed) {
for (let i = 0; i < runoffCount; i++) {
const path = runoffPaths[i];
const t = (elapsed * path.speed + path.offset) % 1;
const point = path.curve.getPointAt(t);
dummy.position.copy(point);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 0.8, 1.5);
dummy.updateMatrix();
runoff.setMatrixAt(i, dummy.matrix);
}
runoff.instanceMatrix.needsUpdate = true;
for (let i = 0; i < flowCount; i++) {
const t = (elapsed * 0.12 + i / flowCount) % 1;
const z = THREE.MathUtils.lerp(-4.25, 4.85, t);
dummy.position.set(
Math.sin(i * 2.1) * 0.055,
channelY(z) + 0.09,
z
);
dummy.rotation.set(Math.atan(0.035), 0, 0);
dummy.scale.set(0.7, 0.5, 3.0);
dummy.updateMatrix();
flowDashes.setMatrixAt(i, dummy.matrix);
}
flowDashes.instanceMatrix.needsUpdate = true;
}
// ------------------------------------------------------------
// Basin ripples
// ------------------------------------------------------------
const ripples = [];
for (let i = 0; i < 6; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0xa6f2ed,
transparent: true,
opacity: 0.4,
side: THREE.DoubleSide,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.39, 0.42, 36),
material
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(
Math.sin(i * 1.7) * 0.8,
-0.345,
5.55 + (i % 3) * 0.65
);
scene.add(ring);
ripples.push(ring);
}
function updateRipples(elapsed) {
ripples.forEach((ring, i) => {
const t = (elapsed * 0.32 + i / ripples.length) % 1;
const scale = 0.45 + t * 3.6;
ring.scale.setScalar(scale);
ring.material.opacity = 0.42 * (1 - t);
});
basinWater.position.y = -0.365 + Math.sin(elapsed * 1.4) * 0.008;
}
// ------------------------------------------------------------
// Projected scene labels
// ------------------------------------------------------------
const labelDefinitions = [
{
text: "Simplified stepped sanctuary",
anchor: new THREE.Vector3(0, 5.55, -6.9),
offset: [-138, -28],
water: false
},
{
text: "Sloped rain-fed stone paving",
anchor: new THREE.Vector3(-4.0, 0.65, -0.9),
offset: [-105, 24],
water: false
},
{
text: "Central stone runnel",
anchor: new THREE.Vector3(0, 0.28, 2.25),
offset: [128, 10],
water: true
},
{
text: "Open retention basin",
anchor: new THREE.Vector3(1.6, -0.2, 6.9),
offset: [120, -12],
water: true
},
{
text: "Cutaway: foundation and soil strata",
anchor: new THREE.Vector3(5.2, -0.9, 5.08),
offset: [135, 48],
water: false
},
{
text: "Schematic stela marker",
anchor: new THREE.Vector3(4.65, 2.0, -2.25),
offset: [125, -22],
water: false
}
];
const labelsRoot = document.getElementById("labels");
const leadersRoot = document.getElementById("leaders");
const svgNS = "http://www.w3.org/2000/svg";
const projected = new THREE.Vector3();
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `scene-label${definition.water ? " water" : ""}`;
element.textContent = definition.text;
labelsRoot.appendChild(element);
const line = document.createElementNS(svgNS, "line");
const dot = document.createElementNS(svgNS, "circle");
dot.setAttribute("r", "3");
leadersRoot.appendChild(line);
leadersRoot.appendChild(dot);
definition.element = element;
definition.line = line;
definition.dot = dot;
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of labelDefinitions) {
projected.copy(definition.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.3 &&
Math.abs(projected.y) < 1.3;
definition.element.style.display = visible ? "block" : "none";
definition.line.style.display = visible ? "block" : "none";
definition.dot.style.display = visible ? "block" : "none";
if (!visible) continue;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
let labelX = anchorX + definition.offset[0];
let labelY = anchorY + definition.offset[1];
labelX = THREE.MathUtils.clamp(labelX, 85, width - 85);
labelY = THREE.MathUtils.clamp(labelY, 42, height - 42);
definition.element.style.left = `${labelX}px`;
definition.element.style.top = `${labelY}px`;
definition.line.setAttribute("x1", anchorX);
definition.line.setAttribute("y1", anchorY);
definition.line.setAttribute("x2", labelX);
definition.line.setAttribute("y2", labelY);
definition.dot.setAttribute("cx", anchorX);
definition.dot.setAttribute("cy", anchorY);
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, reset
// ------------------------------------------------------------
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
pan: false
};
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.pan =
event.button === 2 ||
event.button === 1 ||
event.shiftKey;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.pan) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
right.y = 0;
right.normalize();
const scale = currentRadius * 0.0014;
target.addScaledVector(right, -dx * scale);
target.y = THREE.MathUtils.clamp(
target.y + dy * scale,
-1.0,
5.0
);
} else {
desiredTheta -= dx * 0.005;
desiredPhi = THREE.MathUtils.clamp(
desiredPhi - dy * 0.005,
0.28,
1.42
);
}
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
11,
36
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
desiredTheta = 0.73;
desiredPhi = 1.04;
desiredRadius = 23.5;
target.set(0, 1.0, 0.35);
});
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const easing = Math.min(1, dt * 8);
currentTheta += (desiredTheta - currentTheta) * easing;
currentPhi += (desiredPhi - currentPhi) * easing;
currentRadius += (desiredRadius - currentRadius) * easing;
updateCamera();
updateRain(dt);
updateRunoff(elapsed);
updateRipples(elapsed);
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```