Prompt specification
Build or customize the Three.js 3D scene "Town above a layered aquifer" 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: Town above a layered aquifer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/town-above-a-layered-aquifer-x1207
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a scene with a small town, recharge hillside, stream, and groundwater cutaway; mark recharge and well positions while labeling underground flow arrows as conceptual. Voxel style.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Keep the aquifer layers and surface terrain distinguishable without coplanar faces or z-fighting. Preserve the visible village, creek, and conceptual recharge arrows.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (town-above-a-layered-aquifer-x1207):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="data:,">
<title>Voxel Hydrogeological Town</title>
<style>
:root {
--ink: #17313a;
--muted: #526b73;
--panel: rgba(248, 252, 250, 0.92);
--border: rgba(23, 49, 58, 0.16);
--accent: #167d8d;
--concept: #d98b17;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcecef;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app, #viewport {
position: fixed;
inset: 0;
}
#viewport {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: 0 12px 34px rgba(31, 66, 76, 0.13);
backdrop-filter: blur(10px);
}
.intro {
top: 20px;
left: 20px;
width: min(440px, calc(100vw - 40px));
padding: 17px 19px 16px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.3vw, 30px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro p {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.controls {
top: 20px;
right: 20px;
padding: 10px;
display: flex;
gap: 7px;
align-items: center;
}
.controls button {
appearance: none;
border: 1px solid var(--border);
border-radius: 10px;
padding: 9px 11px;
background: rgba(255, 255, 255, 0.78);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background 0.16s ease, transform 0.16s ease;
}
.controls button:hover {
background: #fff;
transform: translateY(-1px);
}
.controls button.active {
color: #fff;
background: var(--accent);
border-color: var(--accent);
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
padding: 0 8px 0 4px;
color: var(--muted);
font-size: 12px;
font-weight: 700;
white-space: nowrap;
cursor: pointer;
}
.toggle input {
width: 16px;
height: 16px;
accent-color: var(--concept);
cursor: pointer;
}
.legend {
left: 20px;
bottom: 20px;
padding: 13px 15px;
pointer-events: none;
max-width: min(520px, calc(100vw - 40px));
}
.legend-title {
margin-bottom: 9px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-items {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
color: var(--muted);
font-size: 12px;
font-weight: 650;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 14px;
height: 14px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.surface { background: #64aa5d; }
.swatch.soil { background: #9a6747; }
.swatch.water { background: #439fc3; }
.swatch.concept { background: #f4bd4e; }
.concept-note {
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid var(--border);
color: #7b5a25;
font-size: 11px;
line-height: 1.35;
}
.help {
right: 20px;
bottom: 20px;
padding: 10px 13px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
transform: translate(-50%, -100%);
padding: 6px 9px;
border: 1px solid rgba(23, 49, 58, 0.18);
border-radius: 8px;
background: rgba(252, 254, 251, 0.94);
box-shadow: 0 5px 14px rgba(28, 59, 68, 0.12);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.055em;
line-height: 1.15;
text-align: center;
text-transform: uppercase;
white-space: nowrap;
transition: opacity 0.15s ease;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 12px;
background: rgba(23, 49, 58, 0.42);
}
.scene-label.water {
color: #176a87;
border-color: rgba(23, 106, 135, 0.24);
}
.scene-label.concept {
color: #86590f;
background: rgba(255, 248, 224, 0.96);
border-color: rgba(217, 139, 23, 0.35);
}
.scene-label.hidden { opacity: 0; }
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.intro p { display: none; }
.controls {
top: auto;
right: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
flex-wrap: wrap;
}
.help { display: none; }
.legend {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
padding: 10px 12px;
}
.legend-items { gap: 6px 10px; }
.concept-note { max-width: 290px; }
.scene-label { font-size: 9px; padding: 5px 7px; }
}
</style>
</head>
<body>
<main id="app">
<canvas id="viewport" aria-label="Interactive voxel hydrogeological town diorama"></canvas>
<div id="labels" aria-hidden="true"></div>
<section class="panel intro">
<div class="eyebrow">Voxel hydrogeological landscape</div>
<h1>Town, recharge hillside & groundwater cutaway</h1>
<p>A procedural town sits above a terraced recharge slope. The stream occupies carved voxel cells, while the exposed front section reveals unsaturated soil and groundwater.</p>
</section>
<nav class="panel controls" aria-label="Scene controls">
<button type="button" class="active" data-view="overview">Overview</button>
<button type="button" data-view="surface">Surface</button>
<button type="button" data-view="cutaway">Cutaway</button>
<label class="toggle" title="Show or hide the schematic underground flow arrows">
<input id="conceptToggle" type="checkbox" checked>
Conceptual arrows
</label>
</nav>
<aside class="panel legend">
<div class="legend-title">Section legend</div>
<div class="legend-items">
<div class="legend-item"><span class="swatch surface"></span>Surface</div>
<div class="legend-item"><span class="swatch soil"></span>Unsaturated soil</div>
<div class="legend-item"><span class="swatch water"></span>Groundwater</div>
<div class="legend-item"><span class="swatch concept"></span>Conceptual flow</div>
</div>
<div class="concept-note">Yellow arrows are deliberately schematic and do not represent calculated vectors, rates, or a measured hydraulic gradient.</div>
</aside>
<div class="panel help">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("viewport");
const labelRoot = document.getElementById("labels");
const conceptToggle = document.getElementById("conceptToggle");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcecef);
scene.fog = new THREE.Fog(0xdcecef, 58, 96);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemi = new THREE.HemisphereLight(0xe9fbff, 0x6b513d, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.1);
sun.position.set(-18, 28, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ccfe1, 0.8);
fill.position.set(22, 10, -18);
scene.add(fill);
const CELL = 1.2;
const MIN_X = -14;
const MAX_X = 14;
const MIN_Z = -6;
const MAX_Z = 6;
const GRID_WIDTH = (MAX_X - MIN_X + 1) * CELL;
const GRID_DEPTH = (MAX_Z - MIN_Z + 1) * CELL;
const FRONT_Z = GRID_DEPTH / 2;
const streamPath = [
[-13, -5], [-12, -5], [-11, -5],
[-10, -4], [-9, -4], [-8, -4],
[-7, -3], [-6, -3],
[-5, -2], [-4, -2],
[-3, -1], [-2, -1],
[-1, 0], [0, 0],
[1, 1], [2, 1],
[3, 2], [4, 2],
[5, 3], [6, 3],
[7, 4], [8, 4],
[9, 5]
];
const streamSet = new Set(streamPath.map(([x, z]) => `${x},${z}`));
function heightAt(gx, gz) {
if (streamSet.has(`${gx},${gz}`)) return -0.58;
let height = 0;
const hillRadius = Math.sqrt(
Math.pow((gx + 10) / 8, 2) +
Math.pow((gz + 2) / 6, 2)
);
if (hillRadius < 1) {
height = Math.max(height, Math.round((1 - hillRadius) * 3.2 * 2) / 2);
}
if (gx >= 4 && gz <= 1) {
height = Math.max(height, 0.5);
}
return height;
}
const material = {
bedrock: new THREE.MeshStandardMaterial({ color: 0x56636c, roughness: 0.92 }),
aquifer: new THREE.MeshStandardMaterial({ color: 0x419fc1, roughness: 0.38, metalness: 0.03 }),
unsaturated: new THREE.MeshStandardMaterial({ color: 0x946143, roughness: 0.98 }),
columnSoil: new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 1 }),
surface: new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.95 }),
water: new THREE.MeshStandardMaterial({ color: 0x3da9d4, roughness: 0.24, metalness: 0.04 }),
foam: new THREE.MeshStandardMaterial({ color: 0xd9f6fb, roughness: 0.5 }),
trunk: new THREE.MeshStandardMaterial({ color: 0x795038, roughness: 1 }),
leaves: new THREE.MeshStandardMaterial({ color: 0x3d8750, roughness: 0.92 }),
leavesLight: new THREE.MeshStandardMaterial({ color: 0x5da85e, roughness: 0.92 }),
marker: new THREE.MeshStandardMaterial({ color: 0xf08a36, roughness: 0.7 }),
markerDark: new THREE.MeshStandardMaterial({ color: 0x9e4d27, roughness: 0.8 }),
well: new THREE.MeshStandardMaterial({ color: 0x1e7897, roughness: 0.42, metalness: 0.15 }),
wellLight: new THREE.MeshStandardMaterial({ color: 0x68c7dc, roughness: 0.38, metalness: 0.1 }),
window: new THREE.MeshStandardMaterial({
color: 0x9bdce7,
roughness: 0.28,
emissive: 0x173f49,
emissiveIntensity: 0.22
}),
door: new THREE.MeshStandardMaterial({ color: 0x6f4635, roughness: 0.9 }),
path: new THREE.MeshStandardMaterial({ color: 0xc4aa83, roughness: 0.95 })
};
function addBox(parent, width, height, depth, x, y, z, mat, castShadow = false) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x324e55, opacity = 0.45) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({ color, transparent: true, opacity })
);
edges.position.copy(mesh.position);
mesh.parent.add(edges);
return edges;
}
// Three continuous geological layers. Their vertical boundaries touch exactly;
// no surface or soil geometry is placed on top of another surface.
const bedrock = addBox(
scene, GRID_WIDTH, 1.0, GRID_DEPTH,
0, -5.5, 0, material.bedrock
);
addEdges(bedrock, 0x34434a, 0.65);
const aquifer = addBox(
scene, GRID_WIDTH, 2.0, GRID_DEPTH,
0, -4.0, 0, material.aquifer
);
addEdges(aquifer, 0x226b84, 0.42);
const unsaturated = addBox(
scene, GRID_WIDTH, 2.0, GRID_DEPTH,
0, -2.0, 0, material.unsaturated
);
addEdges(unsaturated, 0x66412f, 0.42);
const brownInstances = [];
const greenInstances = [];
const waterInstances = [];
const dummy = new THREE.Object3D();
function addInstance(target, x, y, z, width, height, depth, color) {
target.push({ x, y, z, width, height, depth, color });
}
const greenPalette = [
0x65a95b, 0x70b365, 0x5b9f56, 0x79b769, 0x629f5a
];
const brownPalette = [0xa06a48, 0x996344, 0xa8734f, 0x915d40];
for (let gx = MIN_X; gx <= MAX_X; gx++) {
for (let gz = MIN_Z; gz <= MAX_Z; gz++) {
const x = gx * CELL;
const z = gz * CELL;
const h = heightAt(gx, gz);
if (streamSet.has(`${gx},${gz}`)) {
addInstance(
brownInstances, x, -0.79, z,
CELL - 0.035, 0.42, CELL - 0.035,
0x75503b
);
addInstance(
waterInstances, x, -0.50, z,
CELL - 0.025, 0.16, CELL - 0.025,
0x3ca9d3
);
continue;
}
const greenBottom = h - 0.45;
const brownHeight = greenBottom - (-1);
const brownCenter = (-1 + greenBottom) / 2;
const colorIndex = Math.abs((gx * 17 + gz * 31 + 100) % greenPalette.length);
addInstance(
brownInstances,
x, brownCenter, z,
CELL - 0.035, brownHeight, CELL - 0.035,
brownPalette[(gx + gz + 30) % brownPalette.length]
);
addInstance(
greenInstances,
x, h - 0.225, z,
CELL - 0.035, 0.45, CELL - 0.035,
greenPalette[colorIndex]
);
}
}
function buildInstances(target, mat) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const mesh = new THREE.InstancedMesh(geometry, mat, target.length);
mesh.receiveShadow = true;
mesh.castShadow = false;
mesh.frustumCulled = false;
target.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.scale.set(item.width, item.height, item.depth);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(item.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
scene.add(mesh);
return mesh;
}
buildInstances(brownInstances, material.columnSoil);
buildInstances(greenInstances, material.surface);
buildInstances(waterInstances, material.water);
// Small foam blocks sit directly on the stream surface.
for (let i = 2; i < streamPath.length; i += 4) {
const [gx, gz] = streamPath[i];
addBox(
scene, 0.36, 0.05, 0.12,
gx * CELL + 0.08, -0.395, gz * CELL + 0.12,
material.foam
);
}
function makeHouse(gx, gz, width = 1.55, depth = 1.4, wallHeight = 1.2, wallColor = 0xf0dfbd) {
const x = gx * CELL;
const z = gz * CELL;
const ground = heightAt(gx, gz);
const wallMat = new THREE.MeshStandardMaterial({ color: wallColor, roughness: 0.88 });
const roofMats = [
new THREE.MeshStandardMaterial({ color: 0xb94e38, roughness: 0.86 }),
new THREE.MeshStandardMaterial({ color: 0xc85a3e, roughness: 0.86 }),
new THREE.MeshStandardMaterial({ color: 0xd36a48, roughness: 0.86 })
];
addBox(scene, width, wallHeight, depth, x, ground + wallHeight / 2, z, wallMat, true);
let roofWidth = width + 0.42;
let roofDepth = depth + 0.38;
for (let i = 0; i < 3; i++) {
addBox(
scene,
roofWidth, 0.18, roofDepth,
x,
ground + wallHeight + 0.09 + i * 0.18,
z,
roofMats[i],
true
);
roofWidth -= 0.28;
roofDepth -= 0.12;
}
addBox(
scene, 0.30, 0.70, 0.055,
x, ground + 0.35, z + depth / 2 + 0.029,
material.door
);
const windowY = ground + wallHeight * 0.72;
addBox(
scene, 0.30, 0.31, 0.055,
x - width * 0.28, windowY, z + depth / 2 + 0.03,
material.window
);
addBox(
scene, 0.30, 0.31, 0.055,
x + width * 0.28, windowY, z + depth / 2 + 0.03,
material.window
);
addBox(
scene, 0.055, 0.31, 0.28,
x + width / 2 + 0.03, windowY, z,
material.window
);
}
makeHouse(5, -4, 1.55, 1.35, 1.20, 0xf2dfba);
makeHouse(8, -4, 1.65, 1.40, 1.30, 0xe7cda7);
makeHouse(11, -4, 1.45, 1.30, 1.15, 0xf5e6c8);
makeHouse(6, -2, 1.60, 1.35, 1.15, 0xd9e1ca);
makeHouse(9, -2, 1.50, 1.40, 1.35, 0xf0d5b0);
makeHouse(12, -1, 1.35, 1.25, 1.10, 0xe8d7bd);
makeHouse(7, 0, 1.45, 1.30, 1.20, 0xf3e6ca);
makeHouse(10, 0, 1.65, 1.40, 1.15, 0xdfc9a4);
// A pale plaza around the town, assembled from non-overlapping tiles.
for (let gx = 7; gx <= 10; gx++) {
for (let gz = -3; gz <= -3; gz++) {
addBox(
scene, CELL - 0.10, 0.06, CELL - 0.10,
gx * CELL, 0.53, gz * CELL,
material.path
);
}
}
function makeTree(gx, gz, scale = 1) {
const x = gx * CELL;
const z = gz * CELL;
const ground = heightAt(gx, gz);
addBox(
scene, 0.24 * scale, 0.66 * scale, 0.24 * scale,
x, ground + 0.33 * scale, z,
material.trunk, true
);
addBox(
scene, 0.96 * scale, 0.72 * scale, 0.96 * scale,
x, ground + 1.02 * scale, z,
material.leaves, true
);
addBox(
scene, 0.68 * scale, 0.64 * scale, 0.68 * scale,
x, ground + 1.70 * scale, z,
material.leavesLight, true
);
}
[
[-13, 3, 0.9], [-11, 4, 0.85], [-8, 4, 0.95],
[-6, 5, 0.8], [-2, 5, 0.9], [3, 5, 0.85],
[12, 4, 0.95], [13, 1, 0.85], [-4, -6, 0.9],
[2, -6, 0.85], [13, -5, 0.8]
].forEach(args => makeTree(...args));
// Recharge zone marker on the hillside.
const rechargeGX = -10;
const rechargeGZ = -1;
const rechargeX = rechargeGX * CELL;
const rechargeZ = rechargeGZ * CELL;
const rechargeGround = heightAt(rechargeGX, rechargeGZ);
addBox(
scene, 1.08, 0.08, 1.08,
rechargeX, rechargeGround + 0.04, rechargeZ,
material.wellLight
);
addBox(
scene, 0.12, 1.18, 0.12,
rechargeX, rechargeGround + 0.67, rechargeZ,
material.marker, true
);
addBox(
scene, 0.88, 0.46, 0.14,
rechargeX, rechargeGround + 1.13, rechargeZ,
material.marker, true
);
addBox(
scene, 0.54, 0.12, 0.16,
rechargeX, rechargeGround + 1.13, rechargeZ + 0.01,
material.markerDark
);
// Small recharge tiles lie on the slope surface without covering one another.
[
[-11, -1], [-9, -1], [-11, -2], [-9, -2]
].forEach(([gx, gz]) => {
addBox(
scene, 0.78, 0.055, 0.78,
gx * CELL, heightAt(gx, gz) + 0.0275, gz * CELL,
material.wellLight
);
});
// The well is placed at the exposed edge of the section. Its blue casing
// is intentionally drawn just in front of the cut face so it remains visible.
const wellX = 6 * CELL;
const wellSurfaceZ = 6 * CELL;
const sectionZ = FRONT_Z + 0.10;
addBox(
scene, 0.20, 6.05, 0.20,
wellX, -1.78, sectionZ,
material.well, true
);
addBox(
scene, 0.62, 0.64, 0.18,
wellX, -4.08, sectionZ + 0.01,
material.wellLight
);
addBox(
scene, 0.62, 0.16, 0.62,
wellX, 0.28, wellSurfaceZ,
material.well
);
addBox(
scene, 0.18, 0.90, 0.18,
wellX, 0.81, wellSurfaceZ,
material.well, true
);
addBox(
scene, 0.92, 0.18, 0.30,
wellX, 1.23, wellSurfaceZ,
material.wellLight, true
);
// Conceptual underground-flow arrows. These are explicitly diagrammatic.
const conceptGroup = new THREE.Group();
scene.add(conceptGroup);
const conceptMaterial = new THREE.MeshStandardMaterial({
color: 0xf4bd4e,
roughness: 0.55,
emissive: 0x5c3c05,
emissiveIntensity: 0.22
});
function makeHorizontalArrow(x, y, z, length = 2.35) {
const group = new THREE.Group();
group.position.set(x, y, z);
const shaftLength = length - 0.56;
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(shaftLength, 0.17, 0.17),
conceptMaterial
);
shaft.position.x = -0.28;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.30, 0.56, 4),
conceptMaterial
);
head.rotation.z = -Math.PI / 2;
head.position.x = length / 2 - 0.28;
group.add(head);
conceptGroup.add(group);
}
makeHorizontalArrow(-8.5, -3.78, FRONT_Z + 0.34);
makeHorizontalArrow(-2.5, -3.78, FRONT_Z + 0.34);
makeHorizontalArrow(3.5, -3.78, FRONT_Z + 0.34);
// Projected DOM labels avoid any additional renderer or addon dependency.
const labels = [];
function addLabel(text, position, className = "") {
const element = document.createElement("div");
element.className = `scene-label ${className}`.trim();
element.textContent = text;
labelRoot.appendChild(element);
labels.push({ element, position: position.clone() });
return element;
}
addLabel("Recharge hillside", new THREE.Vector3(rechargeX, rechargeGround + 2.05, rechargeZ), "water");
addLabel("Town", new THREE.Vector3(8.4, 3.15, -2.4));
addLabel("Stream", new THREE.Vector3(-1.2, 0.65, 1.2), "water");
addLabel("Well", new THREE.Vector3(wellX, 2.05, wellSurfaceZ), "water");
addLabel("Groundwater", new THREE.Vector3(-11.5, -3.55, FRONT_Z + 0.55), "water");
addLabel("Unsaturated soil", new THREE.Vector3(12.0, -1.72, FRONT_Z + 0.55));
const conceptLabel = addLabel(
"Conceptual underground flow — not to scale",
new THREE.Vector3(0.2, -5.05, FRONT_Z + 0.75),
"concept"
);
// Direct, addon-free orbit controls.
const orbit = {
target: new THREE.Vector3(0, -0.8, 0),
yaw: 0.67,
pitch: 0.49,
radius: 49,
dragging: false,
pointerX: 0,
pointerY: 0,
panButton: false
};
const presets = {
overview: {
target: new THREE.Vector3(0, -0.8, 0),
yaw: 0.67,
pitch: 0.49,
radius: 49
},
surface: {
target: new THREE.Vector3(0, 0.2, 0),
yaw: 0.72,
pitch: 0.88,
radius: 48
},
cutaway: {
target: new THREE.Vector3(0, -2.45, FRONT_Z),
yaw: 0,
pitch: 0.19,
radius: 40
}
};
function applyOrbit() {
const horizontal = Math.cos(orbit.pitch) * orbit.radius;
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontal,
orbit.target.y + Math.sin(orbit.pitch) * orbit.radius,
orbit.target.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(orbit.target);
}
function setView(name) {
const preset = presets[name];
orbit.target.copy(preset.target);
orbit.yaw = preset.yaw;
orbit.pitch = preset.pitch;
orbit.radius = preset.radius;
applyOrbit();
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
conceptToggle.addEventListener("change", () => {
conceptGroup.visible = conceptToggle.checked;
conceptLabel.classList.toggle("hidden", !conceptToggle.checked);
});
canvas.addEventListener("pointerdown", event => {
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
orbit.panButton = event.shiftKey;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.pointerX;
const dy = event.clientY - orbit.pointerY;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
if (orbit.panButton || event.shiftKey) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const forward = new THREE.Vector3().crossVectors(
camera.up,
right
).normalize();
const scale = orbit.radius * 0.0015;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(forward, dy * scale);
} else {
orbit.yaw = THREE.MathUtils.clamp(orbit.yaw - dx * 0.006, -1.3, 1.3);
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch + dy * 0.005, 0.06, 1.18);
}
applyOrbit();
});
function endDrag(event) {
orbit.dragging = false;
orbit.panButton = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
24,
72
);
applyOrbit();
}, { passive: false });
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach(label => {
projected.copy(label.position).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.classList.toggle("hidden", !visible);
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
applyOrbit();
function animate() {
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```