Prompt specification
Build or customize the Three.js 3D scene "Shift fog-layer height across a fixed coastal ridge" 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: Shift fog-layer height across a fixed coastal ridge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shift-fog-layer-height-across-a-fixed-coastal-ridge-x3052
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring coastal fog and ridges in the Atacama Desert. Let users move the schematic fog layer vertically. Show where it intersects terrain and how collection opportunities change, without presenting the model as a water-yield forecast. Voxel style.
Working Three.js Starter (shift-fog-layer-height-across-a-fixed-coastal-ridge-x3052):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Atacama Coastal Fog — Schematic Ridge Interface</title>
<style>
:root {
--ink: #273137;
--muted: #667177;
--paper: #eee8dc;
--panel: #f7f3ea;
--line: #d7cfc0;
--fog: #eaf1f1;
--intersection: #44e0cf;
--active: #f2aa3b;
--coast: #477986;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
width: 100%;
min-height: 100%;
overflow: hidden;
background: #c9b99f;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 365px;
width: 100vw;
height: 100vh;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 25% 18%, rgba(255, 246, 218, 0.46), transparent 35%),
linear-gradient(180deg, #d8ccb7 0%, #bfa98d 100%);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.scene-heading {
position: absolute;
z-index: 3;
top: 26px;
left: 28px;
max-width: 470px;
pointer-events: none;
text-shadow: 0 1px 16px rgba(255, 247, 226, 0.55);
}
.eyebrow {
margin: 0 0 7px;
color: #59605c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.scene-heading h1 {
margin: 0;
max-width: 440px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3.4vw, 52px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.scene-heading p {
max-width: 400px;
margin: 13px 0 0;
color: #4d5758;
font-size: 13px;
line-height: 1.5;
}
.schematic-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 15px;
padding: 7px 10px;
border: 1px solid rgba(50, 66, 69, 0.25);
border-radius: 2px;
background: rgba(248, 244, 231, 0.7);
color: #3f5054;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.schematic-badge::before {
width: 7px;
height: 7px;
background: var(--active);
content: "";
}
.scene-help {
position: absolute;
z-index: 3;
left: 28px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 7px;
pointer-events: none;
}
.scene-help span {
padding: 6px 9px;
border: 1px solid rgba(54, 68, 70, 0.16);
background: rgba(247, 243, 234, 0.72);
color: #4b595c;
font-size: 10px;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
}
.legend {
position: absolute;
z-index: 3;
right: 22px;
bottom: 23px;
display: grid;
gap: 8px;
padding: 12px 14px;
border: 1px solid rgba(54, 68, 70, 0.16);
background: rgba(247, 243, 234, 0.78);
color: #455356;
font-size: 10px;
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 1px;
}
.swatch.fog {
background: #e9eff0;
border: 1px solid #bec9ca;
}
.swatch.contact {
background: var(--intersection);
box-shadow: 0 0 9px rgba(68, 224, 207, 0.6);
}
.swatch.collector {
background: var(--active);
}
#collector-label {
position: absolute;
z-index: 4;
display: none;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 2px;
background: rgba(31, 43, 46, 0.82);
color: white;
font-size: 10px;
line-height: 1.35;
pointer-events: none;
transform: translate(-50%, -100%);
backdrop-filter: blur(7px);
}
#loading {
position: absolute;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #d7c8b1;
color: #4d5a5b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#panel {
position: relative;
z-index: 5;
overflow-y: auto;
padding: 27px 25px 24px;
border-left: 1px solid rgba(78, 72, 61, 0.18);
background:
linear-gradient(rgba(247, 243, 234, 0.96), rgba(247, 243, 234, 0.96)),
repeating-linear-gradient(
0deg,
transparent,
transparent 18px,
rgba(61, 71, 70, 0.04) 19px
);
box-shadow: -15px 0 40px rgba(55, 45, 35, 0.12);
}
.panel-kicker {
margin: 0 0 8px;
color: #847969;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#panel h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
line-height: 1.06;
letter-spacing: -0.025em;
}
.panel-intro {
margin: 10px 0 20px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section {
padding: 18px 0;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.section-title h3 {
margin: 0;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.section-title span {
color: #8d877b;
font-size: 10px;
}
.altitude-readout {
display: flex;
align-items: flex-end;
justify-content: space-between;
margin-bottom: 12px;
}
.altitude-value {
font-family: Georgia, "Times New Roman", serif;
font-size: 38px;
line-height: 0.9;
}
.altitude-unit {
margin-left: 5px;
color: #77766f;
font-family: ui-sans-serif, system-ui, sans-serif;
font-size: 11px;
}
.contact-mode {
max-width: 135px;
padding: 6px 8px;
border-left: 2px solid var(--coast);
color: #59686b;
font-size: 10px;
line-height: 1.35;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 22px;
margin: 0;
accent-color: #536d70;
cursor: ew-resize;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #8d877d;
font-size: 9px;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric {
min-height: 78px;
padding: 12px;
border: 1px solid #d7cfc1;
background: rgba(255, 255, 255, 0.3);
}
.metric-value {
display: block;
margin-bottom: 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
line-height: 1;
}
.metric-label {
color: #73766f;
font-size: 9px;
font-weight: 750;
line-height: 1.35;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.status {
margin: 11px 0 0;
color: #5d6869;
font-size: 11px;
line-height: 1.5;
}
#profile {
width: 100%;
height: auto;
overflow: visible;
}
.profile-note {
margin: 5px 0 0;
color: #858277;
font-size: 9px;
line-height: 1.45;
}
.collector-list {
display: grid;
gap: 5px;
}
.collector-row {
display: grid;
grid-template-columns: 45px 1fr auto;
align-items: center;
gap: 8px;
width: 100%;
padding: 8px 9px;
border: 1px solid transparent;
background: rgba(255, 255, 255, 0.23);
color: #667073;
cursor: pointer;
text-align: left;
transition: 140ms ease;
}
.collector-row:hover,
.collector-row.selected {
border-color: #bdb5a7;
background: rgba(255, 255, 255, 0.6);
}
.collector-id {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.04em;
}
.collector-height {
font-size: 9px;
color: #89877f;
}
.collector-state {
padding: 4px 6px;
border-radius: 1px;
background: #e2e4df;
color: #687174;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.collector-row.active .collector-state {
background: var(--active);
color: #493316;
}
.disclaimer {
margin: 0;
padding: 13px 14px;
border-left: 3px solid #d39232;
background: #ece3d2;
color: #655d51;
font-size: 10px;
line-height: 1.55;
}
.disclaimer strong {
display: block;
margin-bottom: 4px;
color: #4e4941;
font-size: 10px;
letter-spacing: 0.03em;
}
.method {
margin: 10px 0 0;
color: #858176;
font-size: 9px;
line-height: 1.5;
}
@media (max-width: 850px) {
html,
body {
overflow: auto;
}
#app {
display: block;
height: auto;
}
#viewport {
height: 58vh;
min-height: 430px;
}
#panel {
height: auto;
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.scene-heading {
top: 20px;
left: 20px;
}
.scene-heading h1 {
font-size: 34px;
}
.legend {
right: 14px;
bottom: 14px;
}
.scene-help {
left: 14px;
bottom: 14px;
max-width: 50%;
}
}
</style>
</head>
<body>
<main id="app">
<section id="viewport" aria-label="Interactive schematic 3D scene">
<div class="scene-heading">
<p class="eyebrow">Pacific coast · schematic field study</p>
<h1>Atacama fog meets the ridges</h1>
<p>
Move the voxel fog bank vertically to reveal terrain contact and
illustrative collector–intake overlap.
</p>
<div class="schematic-badge">Geometry only · not a forecast</div>
</div>
<div class="scene-help">
<span>Drag: orbit</span>
<span>Shift/right-drag: pan</span>
<span>Wheel/pinch: zoom</span>
</div>
<div class="legend" aria-hidden="true">
<div class="legend-row">
<span class="swatch fog"></span>
<span>Schematic fog band</span>
</div>
<div class="legend-row">
<span class="swatch contact"></span>
<span>Terrain intersection</span>
</div>
<div class="legend-row">
<span class="swatch collector"></span>
<span>Illustrative intake overlap</span>
</div>
</div>
<div id="collector-label"></div>
<div id="loading">Building voxel terrain…</div>
</section>
<aside id="panel">
<p class="panel-kicker">Interactive section 01</p>
<h2>Fog-layer altitude</h2>
<p class="panel-intro">
The fog bank is a movable schematic volume. Its intersection with the
voxel terrain and with each collector’s illustrative intake zone updates
immediately.
</p>
<section class="section">
<div class="section-title">
<h3>Vertical position</h3>
<span>Model units</span>
</div>
<div class="altitude-readout">
<div>
<span id="altitude-value" class="altitude-value">12.0</span>
<span class="altitude-unit">m</span>
</div>
<div id="contact-mode" class="contact-mode">Slope contact</div>
</div>
<input
id="altitude"
type="range"
min="0"
max="28"
step="0.1"
value="12"
aria-label="Schematic fog layer altitude"
/>
<div class="range-labels">
<span>Coastal plain</span>
<span>Ridge level</span>
</div>
</section>
<section class="section">
<div class="section-title">
<h3>Schematic contact</h3>
<span>At current altitude</span>
</div>
<div class="metrics">
<div class="metric">
<span id="intersection-count" class="metric-value">0</span>
<span class="metric-label">Terrain cells intersected</span>
</div>
<div class="metric">
<span id="active-count" class="metric-value">0</span>
<span class="metric-label">Illustrative intake overlaps</span>
</div>
</div>
<p id="contact-status" class="status"></p>
</section>
<section class="section">
<div class="section-title">
<h3>Opportunity profile</h3>
<span>Altitude against intake zones</span>
</div>
<svg
id="profile"
viewBox="0 0 320 145"
role="img"
aria-label="Collector intake overlap profile"
></svg>
<p class="profile-note">
Horizontal amber segments mark illustrative intake zones. The vertical
line follows the fog-layer altitude.
</p>
</section>
<section class="section">
<div class="section-title">
<h3>Collector positions</h3>
<span>Select to inspect</span>
</div>
<div id="collector-list" class="collector-list"></div>
</section>
<section class="section">
<p class="disclaimer">
<strong>Not a water-yield forecast.</strong>
Terrain, fog density, elevations, intake geometry, and overlap counts
are illustrative. This scene does not estimate fog-water production,
extraction volume, recharge, yield, or operational feasibility.
</p>
<p class="method">
An “opportunity” is shown only when the movable fog band overlaps an
illustrative intake volume. It is a geometric comparison, not a
hydrologic prediction.
</p>
</section>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const altitudeInput = document.getElementById("altitude");
const altitudeValue = document.getElementById("altitude-value");
const intersectionCount = document.getElementById("intersection-count");
const activeCount = document.getElementById("active-count");
const contactStatus = document.getElementById("contact-status");
const contactMode = document.getElementById("contact-mode");
const collectorList = document.getElementById("collector-list");
const profile = document.getElementById("profile");
const collectorLabel = document.getElementById("collector-label");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8ccb7);
scene.fog = new THREE.Fog(0xd8ccb7, 72, 155);
const camera = new THREE.PerspectiveCamera(
43,
viewport.clientWidth / viewport.clientHeight,
0.1,
300
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.domElement.setAttribute(
"aria-label",
"Voxel terrain model with a vertically movable coastal fog layer"
);
renderer.domElement.tabIndex = 0;
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xfff2d4,
0x4c4544,
2.2
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffddb0, 3.1);
sun.position.set(-34, 58, 32);
scene.add(sun);
const oceanLight = new THREE.DirectionalLight(0x9ac9d1, 0.75);
oceanLight.position.set(28, 18, 42);
scene.add(oceanLight);
const GRID_X = 48;
const GRID_Z = 42;
const CELL = 1.25;
const BASE_Y = -4;
const FOG_HALF_HEIGHT = 2.2;
const MAX_ALTITUDE = 28;
const cells = [];
const dummy = new THREE.Object3D();
const tempColor = new THREE.Color();
function random(ix, iz, salt = 0) {
const value = Math.sin(
ix * 127.1 + iz * 311.7 + salt * 74.7
) * 43758.5453123;
return value - Math.floor(value);
}
function coastZ(x) {
return 12 + 1.8 * Math.sin(x * 0.18);
}
function landHeight(x, z) {
const distanceInland = Math.max(0, coastZ(x) - z);
const firstRidge =
10.5 *
Math.exp(-Math.pow((distanceInland - 11.5) / 5.8, 2));
const secondRidge =
18 *
Math.exp(-Math.pow((distanceInland - 24) / 6.4, 2));
const crossRelief =
(Math.sin(x * 0.31 + z * 0.08) * 1.7 +
Math.cos(z * 0.24 - x * 0.11) * 1.1) *
Math.min(1, distanceInland / 7);
return Math.max(
0.08,
distanceInland * 0.11 + firstRidge + secondRidge + crossRelief
);
}
// ---------------------------------------------------------------------
// Voxel terrain
// ---------------------------------------------------------------------
for (let iz = 0; iz < GRID_Z; iz++) {
for (let ix = 0; ix < GRID_X; ix++) {
const x = (ix - (GRID_X - 1) / 2) * CELL;
const z = (iz - (GRID_Z - 1) / 2) * CELL;
const isSea = z > coastZ(x);
const height = isSea ? -1.35 : landHeight(x, z);
cells.push({
ix,
iz,
x,
z,
height,
isSea,
coveredByFog: false
});
}
}
const terrainColumns = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshLambertMaterial({ color: 0xffffff }),
cells.length
);
terrainColumns.instanceMatrix.setUsage(THREE.StaticDrawUsage);
terrainColumns.castShadow = false;
terrainColumns.receiveShadow = false;
const landCapCells = cells.filter((cell) => !cell.isSea);
const seaCells = cells.filter((cell) => cell.isSea);
const terrainCaps = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshLambertMaterial({ color: 0xffffff }),
landCapCells.length
);
const oceanTiles = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshLambertMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.88
}),
seaCells.length
);
const shoreCells = seaCells.filter((cell) => {
return cell.iz > 0 &&
cells.find(
(candidate) =>
candidate.ix === cell.ix &&
candidate.iz === cell.iz - 1 &&
!candidate.isSea
);
});
const shoreTiles = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshLambertMaterial({
color: 0xb7d2cf,
transparent: true,
opacity: 0.48
}),
shoreCells.length
);
cells.forEach((cell, index) => {
const columnHeight = cell.height - BASE_Y;
dummy.position.set(cell.x, BASE_Y + columnHeight / 2, cell.z);
dummy.scale.set(CELL * 0.965, columnHeight, CELL * 0.965);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
terrainColumns.setMatrixAt(index, dummy.matrix);
const variation = random(cell.ix, cell.iz, 2) * 0.08 - 0.04;
tempColor.setHSL(
0.065 + variation * 0.3,
cell.isSea ? 0.22 : 0.31,
cell.isSea ? 0.25 : 0.34 + variation
);
terrainColumns.setColorAt(index, tempColor);
});
landCapCells.forEach((cell, index) => {
const height = cell.height;
const variation = random(cell.ix, cell.iz, 7);
dummy.position.set(cell.x, height + 0.055, cell.z);
dummy.scale.set(CELL * 0.94, 0.19, CELL * 0.94);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
terrainCaps.setMatrixAt(index, dummy.matrix);
if (height < 2.5) {
tempColor.setHSL(0.095, 0.43, 0.55 + variation * 0.07);
} else if (height < 9) {
tempColor.setHSL(0.065, 0.45, 0.43 + variation * 0.08);
} else if (height < 17) {
tempColor.setHSL(0.035, 0.37, 0.34 + variation * 0.08);
} else {
tempColor.setHSL(0.045, 0.28, 0.39 + variation * 0.1);
}
terrainCaps.setColorAt(index, tempColor);
});
seaCells.forEach((cell, index) => {
dummy.position.set(cell.x, -0.98, cell.z);
dummy.scale.set(CELL * 0.98, 0.3, CELL * 0.98);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
oceanTiles.setMatrixAt(index, dummy.matrix);
const variation = random(cell.ix, cell.iz, 11);
tempColor.setHSL(0.52 + variation * 0.025, 0.28, 0.35 + variation * 0.08);
oceanTiles.setColorAt(index, tempColor);
});
shoreCells.forEach((cell, index) => {
dummy.position.set(cell.x, -0.79, cell.z);
dummy.scale.set(CELL * 0.91, 0.09, CELL * 0.91);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
shoreTiles.setMatrixAt(index, dummy.matrix);
});
scene.add(terrainColumns, terrainCaps, oceanTiles, shoreTiles);
// ---------------------------------------------------------------------
// Movable voxel fog bank
// ---------------------------------------------------------------------
const fogGroupDefinitions = [
{ opacity: 0.075, color: 0xe8eeee },
{ opacity: 0.105, color: 0xdce7e8 },
{ opacity: 0.14, color: 0xf0eee5 }
];
const fogGroups = fogGroupDefinitions.map((definition) => {
const material = new THREE.MeshLambertMaterial({
color: definition.color,
transparent: true,
opacity: definition.opacity,
depthWrite: false,
emissive: definition.color,
emissiveIntensity: 0.08
});
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
material,
cells.length
);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
mesh.renderOrder = 3;
scene.add(mesh);
return {
...definition,
mesh,
items: []
};
});
cells.forEach((cell) => {
const coastalDensity =
0.19 + 0.73 * Math.exp(-Math.pow((cell.z - 6) / 13, 2));
const edgeFade =
1 - 0.45 * Math.pow(Math.abs(cell.x) / 31, 3);
const density = coastalDensity * edgeFade;
if (random(cell.ix, cell.iz, 31) < density) {
cell.coveredByFog = true;
const selector = random(cell.ix, cell.iz, 37);
const groupIndex =
selector < 0.48 ? 0 : selector < 0.8 ? 1 : 2;
fogGroups[groupIndex].items.push({
x: cell.x,
z: cell.z,
offset:
(random(cell.ix, cell.iz, 41) - 0.5) * 1.8,
width:
CELL *
(0.82 + random(cell.ix, cell.iz, 43) * 0.25),
height:
1.6 + random(cell.ix, cell.iz, 47) * 1.8,
depth:
CELL *
(0.82 + random(cell.ix, cell.iz, 53) * 0.25)
});
}
});
// ---------------------------------------------------------------------
// Collectors
// ---------------------------------------------------------------------
const collectorSpecs = [
{ x: -21, z: 6 },
{ x: -14, z: 2 },
{ x: -7, z: 3 },
{ x: 0, z: 0 },
{ x: 7, z: 2 },
{ x: 15, z: 5 },
{ x: -10, z: -9 },
{ x: 9, z: -12 }
];
const collectors = [];
const clickTargets = [];
const collectorGroup = new THREE.Group();
scene.add(collectorGroup);
const mastMaterial = new THREE.MeshLambertMaterial({
color: 0x35464a
});
const padMaterial = new THREE.MeshLambertMaterial({
color: 0x655a50
});
collectorSpecs.forEach((spec, index) => {
const ground = landHeight(spec.x, spec.z);
const intake = ground + 2.15;
const captureBottom = ground + 0.65;
const captureTop = ground + 3.65;
const group = new THREE.Group();
group.position.set(spec.x, 0, spec.z);
collectorGroup.add(group);
const pad = new THREE.Mesh(
new THREE.BoxGeometry(1.75, 0.24, 1.75),
padMaterial
);
pad.position.y = ground + 0.1;
group.add(pad);
const mast = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 1.65, 0.19),
mastMaterial
);
mast.position.y = ground + 0.92;
group.add(mast);
const intakeMaterial = new THREE.MeshLambertMaterial({
color: 0x71888b
});
const intakeMesh = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.78, 1.05),
intakeMaterial
);
intakeMesh.position.y = intake;
intakeMesh.userData.collectorIndex = index;
group.add(intakeMesh);
clickTargets.push(intakeMesh);
const sideMaterial = new THREE.MeshLambertMaterial({
color: 0x4d6062
});
for (const side of [-1, 1]) {
const fin = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.68, 0.72),
sideMaterial
);
fin.position.set(side * 0.61, intake, 0);
group.add(fin);
}
const captureMaterial = new THREE.MeshBasicMaterial({
color: 0x8ca4a6,
transparent: true,
opacity: 0.045,
wireframe: true,
depthWrite: false
});
const captureVolume = new THREE.Mesh(
new THREE.BoxGeometry(2.05, 3.0, 2.05),
captureMaterial
);
captureVolume.position.y = ground + 2.15;
captureVolume.renderOrder = 4;
group.add(captureVolume);
const beaconMaterial = new THREE.MeshLambertMaterial({
color: 0x71888b,
emissive: 0x000000
});
const beacon = new THREE.Mesh(
new THREE.BoxGeometry(0.24, 0.24, 0.24),
beaconMaterial
);
beacon.position.y = intake + 0.65;
group.add(beacon);
collectors.push({
index,
x: spec.x,
z: spec.z,
ground,
intake,
captureBottom,
captureTop,
group,
intakeMesh,
intakeMaterial,
captureVolume,
captureMaterial,
beacon,
beaconMaterial,
active: false,
state: "below"
});
// A denser local fog voxel keeps the intake visually legible.
fogGroups[0].items.push({
x: spec.x,
z: spec.z,
offset: 0,
width: 1.45,
height: 3.2,
depth: 1.45
});
});
const selectionBox = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(2.8, 5.6, 2.8)),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.78
})
);
scene.add(selectionBox);
// ---------------------------------------------------------------------
// Terrain intersection markers
// ---------------------------------------------------------------------
const intersectionMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshLambertMaterial({
color: 0x44e0cf,
emissive: 0x20b7aa,
emissiveIntensity: 0.75
}),
cells.length
);
intersectionMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
intersectionMesh.count = 0;
intersectionMesh.renderOrder = 5;
scene.add(intersectionMesh);
// ---------------------------------------------------------------------
// Voxel altitude ruler
// ---------------------------------------------------------------------
const ruler = new THREE.Group();
ruler.position.set(33, 0, 9);
scene.add(ruler);
const rulerMaterial = new THREE.MeshLambertMaterial({
color: 0x52666a
});
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.12, MAX_ALTITUDE + 1, 0.12),
rulerMaterial
);
post.position.y = (MAX_ALTITUDE + 1) / 2;
ruler.add(post);
for (let value = 0; value <= MAX_ALTITUDE; value += 5) {
const tick = new THREE.Mesh(
new THREE.BoxGeometry(1.2, 0.08, 0.12),
rulerMaterial
);
tick.position.set(0.55, value, 0);
ruler.add(tick);
}
const altitudeMarker = new THREE.Mesh(
new THREE.BoxGeometry(3.1, 0.2, 0.5),
new THREE.MeshLambertMaterial({
color: 0xf2aa3b,
emissive: 0x6b3900,
emissiveIntensity: 0.35
})
);
altitudeMarker.position.x = -0.8;
ruler.add(altitudeMarker);
// ---------------------------------------------------------------------
// Camera controls — implemented without addons
// ---------------------------------------------------------------------
const cameraState = {
yaw: 0.72,
pitch: 0.47,
radius: 72,
target: new THREE.Vector3(0, 7, -2)
};
function updateCamera() {
const horizontalRadius =
cameraState.radius * Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
horizontalRadius * Math.sin(cameraState.yaw),
cameraState.target.y +
cameraState.radius * Math.sin(cameraState.pitch),
cameraState.target.z +
horizontalRadius * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const pointers = new Map();
let previousPinchDistance = 0;
let dragMoved = false;
let downX = 0;
let downY = 0;
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function panCamera(dx, dy) {
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.yaw),
0,
-Math.cos(cameraState.yaw)
);
const scale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-25,
25
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-25,
25
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
downX = event.clientX;
downY = event.clientY;
dragMoved = false;
if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (Math.abs(event.clientX - downX) + Math.abs(event.clientY - downY) > 4) {
dragMoved = true;
}
if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius *
(previousPinchDistance / Math.max(1, distance)),
28,
105
);
}
previousPinchDistance = distance;
} else if (event.shiftKey || event.buttons === 2) {
panCamera(dx, dy);
} else {
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.16,
1.03
);
}
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
!dragMoved &&
Math.abs(event.clientX - downX) +
Math.abs(event.clientY - downY) <
5;
if (wasClick && event.button === 0) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hit = raycaster.intersectObjects(
clickTargets,
false
)[0];
if (hit) {
selectCollector(hit.object.userData.collectorIndex);
}
}
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
});
renderer.domElement.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
28,
105
);
updateCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Scene state and updates
// ---------------------------------------------------------------------
let altitude = Number(altitudeInput.value);
let selectedCollector = 0;
function updateFog() {
fogGroups.forEach((group) => {
group.items.forEach((item, index) => {
dummy.position.set(item.x, altitude + item.offset, item.z);
dummy.scale.set(item.width, item.height, item.depth);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
group.mesh.setMatrixAt(index, dummy.matrix);
});
group.mesh.instanceMatrix.needsUpdate = true;
});
altitudeMarker.position.y = altitude;
}
function updateIntersections() {
let count = 0;
let elevationSum = 0;
for (const cell of cells) {
if (
cell.isSea ||
!cell.coveredByFog ||
Math.abs(cell.height - altitude) > FOG_HALF_HEIGHT
) {
continue;
}
dummy.position.set(
cell.x,
cell.height + 0.23,
cell.z
);
dummy.scale.set(CELL * 0.72, 0.13, CELL * 0.72);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
intersectionMesh.setMatrixAt(count, dummy.matrix);
elevationSum += cell.height;
count++;
}
intersectionMesh.count = count;
intersectionMesh.instanceMatrix.needsUpdate = true;
return {
count,
meanElevation:
count > 0 ? elevationSum / count : null
};
}
function updateCollectorStates() {
const bandBottom = altitude - FOG_HALF_HEIGHT;
const bandTop = altitude + FOG_HALF_HEIGHT;
collectors.forEach((collector) => {
const overlaps =
bandTop >= collector.captureBottom &&
bandBottom <= collector.captureTop;
collector.active = overlaps;
if (overlaps) {
collector.state = "overlap";
} else if (bandBottom > collector.captureTop) {
collector.state = "above";
} else {
collector.state = "below";
}
const activeColor = new THREE.Color(0xf2aa3b);
const inactiveColor = new THREE.Color(0x71888b);
collector.intakeMaterial.color.copy(
overlaps ? activeColor : inactiveColor
);
collector.intakeMaterial.emissive.set(
overlaps ? 0x6b3900 : 0x000000
);
collector.intakeMaterial.emissiveIntensity = overlaps ? 0.35 : 0;
collector.captureMaterial.color.copy(
overlaps ? activeColor : new THREE.Color(0x8ca4a6)
);
collector.captureMaterial.opacity = overlaps ? 0.2 : 0.045;
collector.beaconMaterial.color.copy(
overlaps ? activeColor : inactiveColor
);
collector.beaconMaterial.emissive.set(
overlaps ? 0xa96109 : 0x000000
);
collector.beaconMaterial.emissiveIntensity = overlaps ? 0.4 : 0;
});
}
function profileX(value) {
return 42 + (value / MAX_ALTITUDE) * 267;
}
function updateProfile() {
const currentX = profileX(altitude);
const rows = collectors
.map((collector, index) => {
const y = 12 + index * 14;
const start = profileX(collector.captureBottom);
const end = profileX(collector.captureTop);
const color = collector.active ? "#f2aa3b" : "#aab5b5";
return `
<text x="1" y="${y + 3}" fill="#747c7b" font-size="8">
C${String(index + 1).padStart(2, "0")}
</text>
<line
x1="${start}"
y1="${y}"
x2="${end}"
y2="${y}"
stroke="${color}"
stroke-width="5"
stroke-linecap="square"
/>
<circle
cx="${profileX(collector.intake)}"
cy="${y}"
r="2.1"
fill="${color}"
/>
`;
})
.join("");
profile.innerHTML = `
<g font-family="Inter, system-ui, sans-serif">
<line
x1="42" y1="4" x2="42" y2="124"
stroke="#d0c9bb" stroke-width="1"
/>
${rows}
<line
x1="${currentX}" y1="3" x2="${currentX}" y2="125"
stroke="#344e52" stroke-width="1.5"
/>
<polygon
points="${currentX - 4},3 ${currentX + 4},3 ${currentX},8"
fill="#344e52"
/>
<text x="42" y="139" fill="#89867d" font-size="8">0</text>
<text x="166" y="139" fill="#89867d" font-size="8">14</text>
<text x="293" y="139" fill="#89867d" font-size="8">28 m</text>
</g>
`;
}
function updateCollectorList() {
collectorList.innerHTML = collectors
.map((collector) => {
const stateText =
collector.state === "overlap"
? "overlap"
: collector.state === "above"
? "fog above"
: "fog below";
return `
<button
type="button"
class="collector-row
${collector.active ? "active" : ""}
${selectedCollector === collector.index ? "selected" : ""}"
data-collector="${collector.index}"
>
<span class="collector-id">
C${String(collector.index + 1).padStart(2, "0")}
</span>
<span class="collector-height">
intake ${collector.intake.toFixed(1)} m
</span>
<span class="collector-state">${stateText}</span>
</button>
`;
})
.join("");
collectorList
.querySelectorAll("[data-collector]")
.forEach((button) => {
button.addEventListener("click", () => {
selectCollector(Number(button.dataset.collector));
});
});
}
function selectCollector(index) {
selectedCollector = index;
const collector = collectors[index];
selectionBox.position.set(
collector.x,
collector.ground + 2.15,
collector.z
);
collectorLabel.innerHTML = `
<strong>C${String(index + 1).padStart(2, "0")}</strong><br>
intake ${collector.intake.toFixed(1)} m ·
${collector.active ? "band overlap" : collector.state}
`;
updateCollectorList();
}
function updateReadouts(intersections) {
const active = collectors.filter(
(collector) => collector.active
).length;
altitudeValue.textContent = altitude.toFixed(1);
intersectionCount.textContent = intersections.count;
activeCount.textContent = active;
if (
intersections.meanElevation === null
) {
contactMode.textContent = "No terrain contact";
contactMode.style.borderLeftColor = "#9b968c";
} else if (intersections.meanElevation > 16) {
contactMode.textContent = "Upper-ridge contact";
contactMode.style.borderLeftColor = "#8f5948";
} else if (intersections.meanElevation > 7) {
contactMode.textContent = "Lower-slope contact";
contactMode.style.borderLeftColor = "#9b704d";
} else {
contactMode.textContent = "Coastal-plain contact";
contactMode.style.borderLeftColor = "#477986";
}
if (active === 0) {
contactStatus.textContent =
"The fog band does not overlap an illustrative intake zone at this elevation.";
} else {
contactStatus.textContent =
`${active} illustrative intake ${active === 1 ? "zone overlaps" : "zones overlap"} the fog band; ` +
`${intersections.count} terrain cells intersect it.`;
}
updateProfile();
updateCollectorList();
}
function setAltitude(value) {
altitude = THREE.MathUtils.clamp(
Number(value),
0,
MAX_ALTITUDE
);
altitudeInput.value = altitude.toFixed(1);
updateFog();
const intersections = updateIntersections();
updateCollectorStates();
updateReadouts(intersections);
}
altitudeInput.addEventListener("input", (event) => {
setAltitude(event.target.value);
});
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
if (event.key === "ArrowUp" || event.key === "ArrowRight") {
event.preventDefault();
setAltitude(altitude + 0.5);
}
if (event.key === "ArrowDown" || event.key === "ArrowLeft") {
event.preventDefault();
setAltitude(altitude - 0.5);
}
if (event.key.toLowerCase() === "r") {
cameraState.yaw = 0.72;
cameraState.pitch = 0.47;
cameraState.radius = 72;
cameraState.target.set(0, 7, -2);
updateCamera();
}
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const projectedLabel = new THREE.Vector3();
function animate() {
const selected = collectors[selectedCollector];
projectedLabel.set(
selected.x,
selected.ground + 4.25,
selected.z
).project(camera);
const visible =
projectedLabel.z > -1 &&
projectedLabel.z < 1 &&
Math.abs(projectedLabel.x) < 1.15 &&
Math.abs(projectedLabel.y) < 1.15;
collectorLabel.style.display = visible ? "block" : "none";
if (visible) {
collectorLabel.style.left =
`${(projectedLabel.x * 0.5 + 0.5) * viewport.clientWidth}px`;
collectorLabel.style.top =
`${(-projectedLabel.y * 0.5 + 0.5) * viewport.clientHeight}px`;
}
renderer.render(scene, camera);
}
setAltitude(altitude);
selectCollector(0);
resize();
updateCamera();
document.getElementById("loading").style.display = "none";
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```