Prompt specification
Build or customize the Three.js 3D scene "Coastal access planning model" 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: Coastal access planning model
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/coastal-access-planning-model-x1124
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring coastal erosion. Let viewers switch between a boardwalk, restored dune, and seawall on one bounded shoreline; show geometric access and exposure changes without claiming engineering protection performance. Low-poly.
Working Three.js Starter (coastal-access-planning-model-x1124):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Coastal Geometry — Shoreline Alternatives</title>
<style>
:root {
--ink: #17353a;
--muted: #607579;
--paper: rgba(248, 246, 238, 0.91);
--line: rgba(23, 53, 58, 0.16);
--cyan: #087f86;
--cyan-soft: #d4ecea;
--amber: #d58432;
--amber-soft: #f4e3ca;
--shadow: 0 18px 55px rgba(25, 53, 56, 0.15);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe6e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
max-width: 430px;
padding: 16px 19px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 16px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 20px;
height: 2px;
background: currentColor;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.4vw, 30px);
font-weight: 680;
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.view-tools {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
pointer-events: auto;
}
.tool-button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 11px;
background: var(--paper);
box-shadow: 0 7px 24px rgba(25, 53, 56, 0.09);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
backdrop-filter: blur(12px);
}
.tool-button:hover {
background: #fffdf7;
transform: translateY(-1px);
}
.panel {
position: fixed;
z-index: 6;
left: 24px;
bottom: 22px;
width: min(390px, calc(100vw - 48px));
max-height: calc(100vh - 145px);
overflow: auto;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
}
.mode-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
padding: 4px;
margin-bottom: 17px;
border-radius: 12px;
background: rgba(23, 53, 58, 0.065);
}
.mode-tab {
min-height: 38px;
padding: 7px 5px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: 160ms ease;
}
.mode-tab:hover { color: var(--ink); }
.mode-tab[aria-pressed="true"] {
background: var(--ink);
color: #fffdf5;
box-shadow: 0 4px 12px rgba(23, 53, 58, 0.18);
}
.panel-kicker {
color: var(--cyan);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h2 {
margin: 5px 0 7px;
font-size: 22px;
font-weight: 720;
letter-spacing: -0.025em;
}
.description {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.geometry-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 14px 0;
}
.geometry-note {
min-height: 104px;
padding: 12px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.56);
border: 1px solid var(--line);
}
.geometry-note.access {
border-top: 3px solid var(--cyan);
}
.geometry-note.exposure {
border-top: 3px solid var(--amber);
}
.note-label {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 6px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.access .note-label { color: var(--cyan); }
.exposure .note-label { color: var(--amber); }
.note-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
}
.geometry-note p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.48;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-bottom: 12px;
}
.metric {
padding: 10px 9px;
border-radius: 10px;
background: rgba(23, 53, 58, 0.055);
}
.metric-label {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 12px;
font-weight: 760;
line-height: 1.25;
}
.disclaimer {
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.legend {
position: fixed;
z-index: 5;
right: 24px;
bottom: 24px;
width: 205px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 14px;
background: rgba(248, 246, 238, 0.84);
box-shadow: 0 10px 35px rgba(25, 53, 56, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: var(--muted);
font-size: 10px;
}
.swatch {
width: 25px;
height: 3px;
border-radius: 4px;
background: var(--cyan);
}
.swatch.amber { background: var(--amber); }
.swatch.boundary {
height: 0;
border-top: 2px dashed rgba(23, 53, 58, 0.56);
background: none;
}
.legend-note {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.annotation {
position: fixed;
z-index: 4;
top: 0;
left: 0;
max-width: 220px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 9px;
background: rgba(248, 246, 238, 0.91);
box-shadow: 0 8px 25px rgba(25, 53, 56, 0.13);
color: var(--ink);
font-size: 10px;
font-weight: 750;
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
white-space: nowrap;
}
.annotation::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
background: rgba(248, 246, 238, 0.91);
transform: translateX(-50%) rotate(45deg);
}
.help {
position: fixed;
z-index: 3;
right: 24px;
top: 78px;
color: rgba(23, 53, 58, 0.68);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-align: right;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #dbe6e3;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.brand {
max-width: 250px;
padding: 12px 13px;
}
.brand .subtitle { display: none; }
.view-tools {
max-width: 130px;
}
.tool-button {
padding: 0 10px;
font-size: 10px;
}
.panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
max-height: 47vh;
padding: 13px;
}
.legend {
display: none;
}
.help {
top: 67px;
right: 12px;
}
.geometry-note { min-height: 90px; }
.annotation { display: none; }
}
@media (max-height: 650px) and (min-width: 761px) {
.panel {
max-height: calc(100vh - 115px);
}
.geometry-note { min-height: 90px; }
.subtitle { display: none; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive low-poly coastal erosion geometry scene"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Coastal geometry / study 01</div>
<h1>One shoreline.<br>Three spatial arrangements.</h1>
<p class="subtitle">
Compare access routes and visible exposure geometry on the same bounded coastal reach.
</p>
</div>
<div class="view-tools">
<button class="tool-button" id="planButton" type="button">Plan view</button>
<button class="tool-button" id="resetButton" type="button">Reset view</button>
</div>
</header>
<div class="help">DRAG TO ORBIT · SCROLL TO ZOOM · RIGHT-DRAG TO PAN</div>
<aside class="panel" aria-live="polite">
<nav class="mode-tabs" aria-label="Shoreline arrangement">
<button class="mode-tab" data-mode="boardwalk" aria-pressed="true" type="button">
Boardwalk
</button>
<button class="mode-tab" data-mode="dune" aria-pressed="false" type="button">
Restored dune
</button>
<button class="mode-tab" data-mode="seawall" aria-pressed="false" type="button">
Seawall
</button>
</nav>
<div class="panel-kicker">Selected arrangement</div>
<h2 id="modeTitle">Elevated boardwalk</h2>
<p class="description" id="modeDescription"></p>
<div class="geometry-grid">
<article class="geometry-note access">
<div class="note-label"><span class="note-dot"></span>Access geometry</div>
<p id="accessText"></p>
</article>
<article class="geometry-note exposure">
<div class="note-label"><span class="note-dot"></span>Exposure geometry</div>
<p id="exposureText"></p>
</article>
</div>
<div class="metrics" id="metrics"></div>
<div class="disclaimer">
Illustrative spatial geometry only. This is not a simulation, engineering assessment,
or evidence of erosion-control performance. Wave loading, sediment transport,
foundations, scour, vegetation rooting, and overtopping are not represented.
</div>
</aside>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Reading the model</div>
<div class="legend-row"><span class="swatch"></span>Access route</div>
<div class="legend-row"><span class="swatch amber"></span>Water approach</div>
<div class="legend-row"><span class="swatch boundary"></span>Study boundary</div>
<div class="legend-note">
92 m modeled reach · dimensions are schematic.
Amber arrows show direction only, not wave energy or risk.
</div>
</aside>
<div class="annotation" id="annotation"></div>
<div id="loading">Building shoreline model…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe6e3);
scene.fog = new THREE.Fog(0xdbe6e3, 105, 190);
const camera = new THREE.PerspectiveCamera(
46,
innerWidth / innerHeight,
0.1,
300
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.02;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("tabindex", "0");
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional coastal geometry. Drag to orbit, scroll to zoom."
);
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf1f7ef, 0x647063, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d2, 3.0);
sun.position.set(-34, 58, 31);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -65;
sun.shadow.camera.right = 65;
sun.shadow.camera.top = 55;
sun.shadow.camera.bottom = -55;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7d7df, 0.65);
fill.position.set(40, 22, -30);
scene.add(fill);
const LAND_WIDTH = 92;
const LAND_DEPTH = 24;
const HALF_WIDTH = LAND_WIDTH / 2;
const WATER_DEPTH = 16;
const modeData = {
boardwalk: {
title: "Elevated boardwalk",
description:
"A narrow timber deck runs parallel to the water and is reached by one inland ramp. Open space remains visible beneath the elevated route.",
access:
"A direct inland approach meets a single ramp, then a level deck running along the coast.",
exposure:
"Water-facing edges remain open. The modeled deck is offset landward, but no wave loading or erosion reduction is represented.",
metrics: [
["Access", "1 ramp"],
["Setback", "3.2 m"],
["Deck level", "1.3 m"]
],
annotation: "Elevated deck · open space below",
anchor: new THREE.Vector3(-19, 2.15, 3.2),
exposureEnd: 1.85
},
dune: {
title: "Restored dune",
description:
"An irregular ridge changes the walk line into a longer landward approach. The path ends on the landward side of the modeled dune.",
access:
"The route bends across the inland area and approaches the ridge obliquely instead of following one direct line.",
exposure:
"A raised, uneven landform changes the visible surface profile. Sediment movement and vegetation performance are not simulated.",
metrics: [
["Approach", "31 m"],
["Ridge", "≈ 4 m"],
["Path bends", "4"]
],
annotation: "Illustrative ridge profile",
anchor: new THREE.Vector3(-10, 4.6, 4.5),
exposureEnd: 1.6
},
seawall: {
title: "Segmented seawall",
description:
"A concrete wall stands at the water edge. An inclined ramp creates a single elevated connection from the inland area.",
access:
"The inland route rises on one inclined ramp and meets the top of the wall at a narrow access point.",
exposure:
"The wall interrupts the modeled direct water-to-land corridor. Foundations, scour, overtopping, and reflection are not represented.",
metrics: [
["Access", "Inclined ramp"],
["Height", "2.3 m"],
["Thickness", "0.7 m"]
],
annotation: "Segmented wall face",
anchor: new THREE.Vector3(18, 2.55, -0.8),
exposureEnd: -0.8
}
};
const modeNames = ["boardwalk", "dune", "seawall"];
const weights = { boardwalk: 1, dune: 0, seawall: 0 };
const targetWeights = { ...weights };
let activeMode = "boardwalk";
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function hashNoise(x, z) {
return (
Math.sin(x * 1.713 + z * 0.391) * 0.5 +
Math.sin(x * 0.437 - z * 1.129) * 0.3 +
Math.sin(x * 2.117 + z * 0.829) * 0.2
);
}
function baseLandHeight(x, z) {
const inlandRise = 0.92 * Math.pow(clamp(z / LAND_DEPTH, 0, 1), 1.45);
const beachSlope = 0.025 * z;
const facets = hashNoise(x, z) * 0.10;
return 0.24 + inlandRise + beachSlope + facets;
}
function heightForMode(mode, x, z) {
const base = baseLandHeight(x, z);
if (mode === "dune") {
const ridgeCenter = 4.45 + Math.sin(x * 0.17) * 0.42;
const ridgeAmplitude =
3.55 * (0.89 + 0.11 * Math.sin(x * 0.31 + 0.8));
const ridge =
ridgeAmplitude *
Math.exp(-Math.pow((z - ridgeCenter) / 2.18, 2));
const toe =
0.38 *
Math.exp(-Math.pow((z - 1.45) / 1.25, 2)) *
(0.82 + 0.18 * Math.sin(x * 0.23));
return base + ridge + toe;
}
if (mode === "seawall") {
const gradedToe =
0.22 *
Math.exp(-Math.pow((z - 1.15) / 1.45, 2));
return base + gradedToe;
}
return base;
}
function currentHeight(x, z) {
return (
weights.boardwalk * heightForMode("boardwalk", x, z) +
weights.dune * heightForMode("dune", x, z) +
weights.seawall * heightForMode("seawall", x, z)
);
}
const baseSlab = new THREE.Mesh(
new THREE.BoxGeometry(94, 0.65, 42),
new THREE.MeshStandardMaterial({
color: 0x6c807b,
roughness: 0.95,
flatShading: true
})
);
baseSlab.position.set(0, -1.48, 4);
baseSlab.receiveShadow = true;
scene.add(baseSlab);
const waterBed = new THREE.Mesh(
new THREE.BoxGeometry(92, 0.8, WATER_DEPTH),
new THREE.MeshStandardMaterial({
color: 0x376e78,
roughness: 0.86,
flatShading: true
})
);
waterBed.position.set(0, -0.46, -WATER_DEPTH / 2);
scene.add(waterBed);
const waterGeometry = new THREE.PlaneGeometry(
LAND_WIDTH,
WATER_DEPTH,
30,
9
);
waterGeometry.rotateX(-Math.PI / 2);
waterGeometry.translate(0, 0, -WATER_DEPTH / 2);
const waterPositions = waterGeometry.attributes.position;
const waterColors = [];
const deepWater = new THREE.Color(0x397f8a);
const paleWater = new THREE.Color(0x78afb0);
const tempColor = new THREE.Color();
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const z = waterPositions.getZ(i);
const mix = clamp((z + WATER_DEPTH) / WATER_DEPTH, 0, 1);
tempColor.copy(deepWater).lerp(paleWater, mix * 0.65 + 0.12);
const variation = 0.025 * hashNoise(x * 1.3, z);
tempColor.offsetHSL(0, 0, variation);
waterColors.push(tempColor.r, tempColor.g, tempColor.b);
}
waterGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
const waterMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.56,
metalness: 0.03,
flatShading: true
});
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.receiveShadow = true;
scene.add(water);
const terrainNX = 36;
const terrainNZ = 16;
const terrainPositions = new Float32Array(
(terrainNX + 1) * (terrainNZ + 1) * 3
);
const terrainColors = new Float32Array(terrainPositions.length);
const terrainIndices = [];
for (let iz = 0; iz <= terrainNZ; iz++) {
for (let ix = 0; ix <= terrainNX; ix++) {
const i = iz * (terrainNX + 1) + ix;
const x = -HALF_WIDTH + (ix / terrainNX) * LAND_WIDTH;
const z = (iz / terrainNZ) * LAND_DEPTH;
terrainPositions[i * 3] = x;
terrainPositions[i * 3 + 1] = currentHeight(x, z);
terrainPositions[i * 3 + 2] = z;
}
}
for (let iz = 0; iz < terrainNZ; iz++) {
for (let ix = 0; ix < terrainNX; ix++) {
const a = iz * (terrainNX + 1) + ix;
const b = a + 1;
const c = a + terrainNX + 1;
const d = c + 1;
if ((ix + iz) % 2 === 0) {
terrainIndices.push(a, c, b, b, c, d);
} else {
terrainIndices.push(a, d, c, a, b, d);
}
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(terrainPositions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
terrainGeometry.setAttribute(
"color",
new THREE.BufferAttribute(terrainColors, 3)
.setUsage(THREE.DynamicDrawUsage)
);
terrainGeometry.setIndex(terrainIndices);
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
flatShading: true
})
);
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
const sandColor = new THREE.Color(0xd7c49b);
const meadowColor = new THREE.Color(0xa5ae7c);
const duneColor = new THREE.Color(0x83966a);
const dryColor = new THREE.Color(0xb8b78b);
function updateTerrain() {
for (let iz = 0; iz <= terrainNZ; iz++) {
for (let ix = 0; ix <= terrainNX; ix++) {
const i = iz * (terrainNX + 1) + ix;
const x = -HALF_WIDTH + (ix / terrainNX) * LAND_WIDTH;
const z = (iz / terrainNZ) * LAND_DEPTH;
const h = currentHeight(x, z);
terrainPositions[i * 3 + 1] = h;
const inlandBlend = clamp((z - 5.0) / 13.0, 0, 1);
tempColor.copy(sandColor).lerp(meadowColor, inlandBlend);
const duneBlend =
weights.dune * clamp((h - 0.9) / 1.7, 0, 1);
tempColor.lerp(duneColor, duneBlend * 0.82);
tempColor.lerp(dryColor, weights.dune * 0.16);
terrainColors[i * 3] = tempColor.r;
terrainColors[i * 3 + 1] = tempColor.g;
terrainColors[i * 3 + 2] = tempColor.b;
}
}
terrainGeometry.attributes.position.needsUpdate = true;
terrainGeometry.attributes.color.needsUpdate = true;
terrainGeometry.computeVertexNormals();
}
const skirtMaterial = new THREE.MeshStandardMaterial({
color: 0xa18561,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
function createSkirtEdge(segmentCount, pointAt) {
const positions = new Float32Array(segmentCount * 18);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
const mesh = new THREE.Mesh(geometry, skirtMaterial);
mesh.receiveShadow = true;
mesh.castShadow = true;
scene.add(mesh);
return {
geometry,
positions,
segmentCount,
pointAt,
update() {
for (let s = 0; s < segmentCount; s++) {
const a = pointAt(s / segmentCount);
const b = pointAt((s + 1) / segmentCount);
const ah = currentHeight(a.x, a.z);
const bh = currentHeight(b.x, b.z);
const offset = s * 18;
positions[offset] = a.x;
positions[offset + 1] = ah;
positions[offset + 2] = a.z;
positions[offset + 3] = a.x;
positions[offset + 4] = -1.15;
positions[offset + 5] = a.z;
positions[offset + 6] = b.x;
positions[offset + 7] = bh;
positions[offset + 8] = b.z;
positions[offset + 9] = b.x;
positions[offset + 10] = bh;
positions[offset + 11] = b.z;
positions[offset + 12] = a.x;
positions[offset + 13] = -1.15;
positions[offset + 14] = a.z;
positions[offset + 15] = b.x;
positions[offset + 16] = -1.15;
positions[offset + 17] = b.z;
}
geometry.attributes.position.needsUpdate = true;
geometry.computeVertexNormals();
}
};
}
const skirts = [
createSkirtEdge(36, t => ({
x: -HALF_WIDTH + t * LAND_WIDTH,
z: 0
})),
createSkirtEdge(36, t => ({
x: -HALF_WIDTH + t * LAND_WIDTH,
z: LAND_DEPTH
})),
createSkirtEdge(16, t => ({
x: -HALF_WIDTH,
z: t * LAND_DEPTH
})),
createSkirtEdge(16, t => ({
x: HALF_WIDTH,
z: t * LAND_DEPTH
}))
];
const boundaryPoints = [];
for (let i = 0; i <= 40; i++) {
const x = -HALF_WIDTH + (i / 40) * LAND_WIDTH;
boundaryPoints.push(
new THREE.Vector3(x, currentHeight(x, LAND_DEPTH) + 0.08, LAND_DEPTH)
);
}
for (let i = 1; i <= 16; i++) {
const z = -WATER_DEPTH + (i / 16) * (LAND_DEPTH + WATER_DEPTH);
const y = z >= 0 ? currentHeight(HALF_WIDTH, z) + 0.08 : 0.11;
boundaryPoints.push(new THREE.Vector3(HALF_WIDTH, y, z));
}
boundaryPoints.push(new THREE.Vector3(-HALF_WIDTH, 0.11, -WATER_DEPTH));
for (let i = 1; i <= 40; i++) {
const x = HALF_WIDTH - (i / 40) * LAND_WIDTH;
boundaryPoints.push(new THREE.Vector3(x, 0.11, -WATER_DEPTH));
}
for (let i = 1; i <= 16; i++) {
const z = LAND_DEPTH - (i / 16) * (LAND_DEPTH + WATER_DEPTH);
const y = z >= 0 ? currentHeight(-HALF_WIDTH, z) + 0.08 : 0.11;
boundaryPoints.push(new THREE.Vector3(-HALF_WIDTH, y, z));
}
boundaryPoints.push(boundaryPoints[0].clone());
const boundary = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(boundaryPoints),
new THREE.LineDashedMaterial({
color: 0xf7f7ec,
dashSize: 1.15,
gapSize: 0.7,
transparent: true,
opacity: 0.85
})
);
boundary.computeLineDistances();
scene.add(boundary);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
flatShading: true,
...options
});
}
function addBox(group, size, position, material, rotationY = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(...position);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
const xAxis = new THREE.Vector3(1, 0, 0);
const zAxis = new THREE.Vector3(0, 0, 1);
function addHorizontalBeam(
group, a, b, thickness, width, material
) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, thickness, width),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(xAxis, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function addRamp(group, a, b, width, material, railMaterial = null) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.18, length),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(zAxis, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
if (railMaterial) {
for (const side of [-1, 1]) {
const offset = new THREE.Vector3(side * width * 0.5, 0.7, 0);
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.10, 0.10, length),
railMaterial
);
rail.position.copy(a).add(b).multiplyScalar(0.5).add(offset);
rail.quaternion.copy(mesh.quaternion);
rail.castShadow = true;
group.add(rail);
const postCount = Math.max(3, Math.round(length / 2.4));
for (let i = 0; i <= postCount; i++) {
const t = i / postCount;
const p = new THREE.Vector3().lerpVectors(a, b, t);
p.x += side * width * 0.5;
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.10, 0.78, 0.10),
railMaterial
);
post.position.copy(p).add(new THREE.Vector3(0, 0.38, 0));
post.castShadow = true;
group.add(post);
}
}
}
return mesh;
}
function addPath(group, points, width, material) {
for (let i = 0; i < points.length - 1; i++) {
addHorizontalBeam(
group,
points[i],
points[i + 1],
0.10,
width,
material
);
}
}
function collectFadeMaterials(group) {
const materials = new Set();
group.traverse(object => {
if (!object.material) return;
const list = Array.isArray(object.material)
? object.material
: [object.material];
list.forEach(material => materials.add(material));
});
return [...materials];
}
const boardwalkGroup = new THREE.Group();
scene.add(boardwalkGroup);
const boardwalkWoodA = standardMaterial(0xa8794d);
const boardwalkWoodB = standardMaterial(0xbd8d5d);
const boardwalkDark = standardMaterial(0x72523b);
const boardwalkPathMaterial = standardMaterial(0xb4a47f);
for (let i = 0; i < 51; i++) {
const x = -35 + i * 1.4;
addBox(
boardwalkGroup,
[1.30, 0.18, 2.2],
[x, 1.3, 3.2],
i % 2 ? boardwalkWoodA : boardwalkWoodB
);
}
addBox(boardwalkGroup, [70.5, 0.24, 0.20], [0, 1.05, 2.23], boardwalkDark);
addBox(boardwalkGroup, [70.5, 0.24, 0.20], [0, 1.05, 4.17], boardwalkDark);
for (let x = -34; x <= 34; x += 5.7) {
for (const z of [2.23, 4.17]) {
const ground = heightForMode("boardwalk", x, z);
const postHeight = 1.18 - ground;
addBox(
boardwalkGroup,
[0.19, postHeight, 0.19],
[x, ground + postHeight / 2, z],
boardwalkDark
);
}
}
for (const z of [2.18, 4.22]) {
addBox(boardwalkGroup, [70.5, 0.12, 0.12], [0, 2.02, z], boardwalkDark);
for (let x = -35; x <= 35; x += 3.5) {
addBox(boardwalkGroup, [0.12, 0.88, 0.12], [x, 1.62, z], boardwalkDark);
}
}
const boardwalkPathPoints = [
new THREE.Vector3(
10,
heightForMode("boardwalk", 10, 20) + 0.08,
20
),
new THREE.Vector3(
10,
heightForMode("boardwalk", 10, 11) + 0.08,
11
)
];
addPath(boardwalkGroup, boardwalkPathPoints, 1.5, boardwalkPathMaterial);
addRamp(
boardwalkGroup,
new THREE.Vector3(10, 0.78, 11),
new THREE.Vector3(10, 1.30, 4.3),
1.7,
boardwalkWoodA,
boardwalkDark
);
for (let i = 0; i <= 8; i++) {
const t = i / 8;
const z = THREE.MathUtils.lerp(11, 4.3, t);
const y = THREE.MathUtils.lerp(0.88, 1.40, t);
addBox(boardwalkGroup, [1.72, 0.06, 0.18], [10, y, z], boardwalkWoodB);
}
const duneGroup = new THREE.Group();
scene.add(duneGroup);
const dunePathMaterial = standardMaterial(0xc0aa7e);
const duneWood = standardMaterial(0x8f704b);
const duneGrassMaterial = standardMaterial(0x627c4b);
const duneShrubMaterial = standardMaterial(0x718252);
const dunePathCoordinates = [
[21, 20],
[18, 17],
[12, 15],
[14, 11],
[9, 8],
[4, 6.5]
];
const dunePathPoints = dunePathCoordinates.map(([x, z]) =>
new THREE.Vector3(
x,
heightForMode("dune", x, z) + 0.10,
z
)
);
addPath(duneGroup, dunePathPoints, 1.45, dunePathMaterial);
const platformY =
heightForMode("dune", 4, 6.5) + 0.10;
addBox(duneGroup, [4.0, 0.18, 2.4], [4, platformY, 6.5], duneWood);
for (let i = 0; i <= 8; i++) {
const t = i / 8;
const p = new THREE.Vector3().lerpVectors(
dunePathPoints[1],
dunePathPoints[dunePathPoints.length - 1],
t
);
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 1.05, 0.12),
duneWood
);
post.position.copy(p).add(new THREE.Vector3(0.65, 0.52, 0));
post.castShadow = true;
duneGroup.add(post);
}
const grassGeometry = new THREE.ConeGeometry(0.13, 0.95, 4);
grassGeometry.translate(0, 0.475, 0);
const grassCount = 95;
const grass = new THREE.InstancedMesh(
grassGeometry,
duneGrassMaterial,
grassCount
);
grass.castShadow = true;
grass.receiveShadow = true;
duneGroup.add(grass);
const grassData = [];
const dummy = new THREE.Object3D();
for (let i = 0; i < grassCount; i++) {
const x = -43 + (i / (grassCount - 1)) * 86 +
Math.sin(i * 12.31) * 0.32;
const z = 2.15 + ((i * 0.6180339887) % 1) * 5.25;
grassData.push({
x,
z,
scale: 0.55 + ((i * 0.37) % 1) * 0.8,
rotation: i * 1.71
});
}
function updateDuneGrass() {
for (let i = 0; i < grassCount; i++) {
const item = grassData[i];
dummy.position.set(
item.x,
currentHeight(item.x, item.z) + 0.02,
item.z
);
dummy.rotation.set(0, item.rotation, 0);
dummy.scale.setScalar(item.scale);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
}
grass.instanceMatrix.needsUpdate = true;
}
const shrubGeometry = new THREE.IcosahedronGeometry(0.48, 0);
for (let i = 0; i < 19; i++) {
const x = -42 + ((i * 7.13) % 84);
const z = 3.3 + ((i * 3.71) % 5.8);
const shrub = new THREE.Mesh(shrubGeometry, duneShrubMaterial);
shrub.position.set(x, currentHeight(x, z) + 0.35, z);
shrub.scale.set(
0.75 + (i % 4) * 0.12,
0.60 + (i % 3) * 0.13,
0.75 + ((i + 1) % 4) * 0.10
);
shrub.rotation.y = i * 0.91;
shrub.castShadow = true;
duneGroup.add(shrub);
}
const seawallGroup = new THREE.Group();
scene.add(seawallGroup);
const concrete = standardMaterial(0xb8b8ac);
const concreteDark = standardMaterial(0x92968d);
const wallCap = standardMaterial(0xd0cec0);
const wallPathMaterial = standardMaterial(0xb2a17c);
const wallRail = standardMaterial(0x66716d);
for (let i = 0; i < 14; i++) {
const x = -39 + i * 6;
addBox(
seawallGroup,
[5.84, 2.20, 0.68],
[x, 1.06, -0.8],
i % 2 ? concrete : concreteDark
);
addBox(
seawallGroup,
[5.95, 0.18, 0.86],
[x, 2.23, -0.8],
wallCap
);
}
const wallPathPoints = [
new THREE.Vector3(
15,
heightForMode("seawall", 15, 20) + 0.08,
20
),
new THREE.Vector3(
15,
heightForMode("seawall", 15, 12) + 0.08,
12
)
];
addPath(seawallGroup, wallPathPoints, 1.8, wallPathMaterial);
addRamp(
seawallGroup,
new THREE.Vector3(15, 0.91, 12),
new THREE.Vector3(15, 2.32, -0.35),
2.1,
concrete,
wallRail
);
for (const z of [8, 4, 0]) {
const t = clamp((12 - z) / 12.35, 0, 1);
const y = THREE.MathUtils.lerp(0.91, 2.32, t);
const ground = heightForMode("seawall", 15, Math.max(z, 0));
const postHeight = Math.max(0.2, y - ground);
addBox(
seawallGroup,
[0.22, postHeight, 0.22],
[15, ground + postHeight / 2, z],
concreteDark
);
}
const fadeMaterials = {
boardwalk: collectFadeMaterials(boardwalkGroup),
dune: collectFadeMaterials(duneGroup),
seawall: collectFadeMaterials(seawallGroup)
};
function setGroupFade(group, amount, materials) {
group.visible = amount > 0.012;
materials.forEach(material => {
material.transparent = true;
material.opacity = amount;
material.depthWrite = amount > 0.97;
});
}
const treeGroup = new THREE.Group();
scene.add(treeGroup);
const trunkMaterial = standardMaterial(0x76523a);
const canopyMaterial = standardMaterial(0x687b54);
const trunkGeometry = new THREE.CylinderGeometry(0.13, 0.18, 1.2, 5);
const canopyGeometry = new THREE.ConeGeometry(0.82, 2.4, 5);
const treeCount = 24;
const trunks = new THREE.InstancedMesh(
trunkGeometry,
trunkMaterial,
treeCount
);
const canopies = new THREE.InstancedMesh(
canopyGeometry,
canopyMaterial,
treeCount
);
trunks.castShadow = true;
canopies.castShadow = true;
canopies.receiveShadow = true;
treeGroup.add(trunks, canopies);
for (let i = 0; i < treeCount; i++) {
const x = -43 + ((i * 11.37) % 86);
const z = 15.5 + ((i * 5.71) % 7.2);
const ground = currentHeight(x, z);
const scale = 0.72 + ((i * 0.61) % 1) * 0.55;
dummy.position.set(x, ground + 0.6 * scale, z);
dummy.rotation.set(0, i * 0.72, 0);
dummy.scale.setScalar(scale);
dummy.updateMatrix();
trunks.setMatrixAt(i, dummy.matrix);
dummy.position.set(x, ground + 1.95 * scale, z);
dummy.updateMatrix();
canopies.setMatrixAt(i, dummy.matrix);
}
trunks.instanceMatrix.needsUpdate = true;
canopies.instanceMatrix.needsUpdate = true;
const exposureGroup = new THREE.Group();
scene.add(exposureGroup);
const exposureArrows = [];
for (let i = 0; i < 7; i++) {
const x = -31 + i * 10.3;
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(x, 0.23, -14),
15.8,
0xd58432,
0.95,
0.55
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.78;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.85;
exposureArrows.push(arrow);
exposureGroup.add(arrow);
}
const exposureField = new THREE.Mesh(
new THREE.BoxGeometry(84, 0.015, 1),
new THREE.MeshBasicMaterial({
color: 0xe0a15c,
transparent: true,
opacity: 0.085,
depthWrite: false
})
);
exposureField.position.set(0, 0.075, -6.2);
exposureGroup.add(exposureField);
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeMaterial = new THREE.MeshBasicMaterial({
color: 0x087f86,
transparent: true,
opacity: 0.94
});
function clearRoute() {
while (routeGroup.children.length) {
const child = routeGroup.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
});
}
}
function buildRoute() {
clearRoute();
let points;
if (activeMode === "boardwalk") {
points = [
new THREE.Vector3(
10,
heightForMode("boardwalk", 10, 20) + 0.16,
20
),
new THREE.Vector3(
10,
heightForMode("boardwalk", 10, 11) + 0.16,
11
),
new THREE.Vector3(10, 1.48, 9),
new THREE.Vector3(10, 1.48, 4.25),
new THREE.Vector3(-13, 1.48, 3.2)
];
} else if (activeMode === "dune") {
points = dunePathCoordinates.map(([x, z]) =>
new THREE.Vector3(
x,
heightForMode("dune", x, z) + 0.20,
z
)
);
} else {
points = [
new THREE.Vector3(
15,
heightForMode("seawall", 15, 20) + 0.16,
20
),
new THREE.Vector3(
15,
heightForMode("seawall", 15, 12) + 0.16,
12
),
new THREE.Vector3(15, 1.15, 9),
new THREE.Vector3(15, 1.75, 4),
new THREE.Vector3(15, 2.52, -0.3)
];
}
const curve = new THREE.CatmullRomCurve3(
points,
false,
"catmullrom",
0.12
);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 100, 0.085, 5, false),
routeMaterial
);
routeGroup.add(tube);
const markerGeometry = new THREE.IcosahedronGeometry(0.19, 0);
const markerIndices = [0, points.length - 1];
markerIndices.forEach(index => {
const marker = new THREE.Mesh(markerGeometry, routeMaterial);
marker.position.copy(points[index]);
marker.scale.setScalar(1.25);
routeGroup.add(marker);
});
}
const foamLines = [];
for (let i = 0; i < 8; i++) {
const points = [];
for (let j = 0; j <= 16; j++) {
points.push(new THREE.Vector3(-44 + j * 5.5, 0.12, -14 + i * 1.8));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0xd9efea,
transparent: true,
opacity: 0.25
})
);
foamLines.push({ line, baseZ: -13.5 + i * 1.75, phase: i * 0.7 });
scene.add(line);
}
const annotationElement = document.getElementById("annotation");
const modeTitle = document.getElementById("modeTitle");
const modeDescription = document.getElementById("modeDescription");
const accessText = document.getElementById("accessText");
const exposureText = document.getElementById("exposureText");
const metricsElement = document.getElementById("metrics");
const modeButtons = [...document.querySelectorAll(".mode-tab")];
function updatePanel() {
const data = modeData[activeMode];
modeTitle.textContent = data.title;
modeDescription.textContent = data.description;
accessText.textContent = data.access;
exposureText.textContent = data.exposure;
annotationElement.textContent = data.annotation;
metricsElement.innerHTML = data.metrics.map(([label, value]) => `
<div class="metric">
<span class="metric-label">${label}</span>
<span class="metric-value">${value}</span>
</div>
`).join("");
modeButtons.forEach(button => {
button.setAttribute(
"aria-pressed",
String(button.dataset.mode === activeMode)
);
});
}
function setMode(mode) {
if (!modeNames.includes(mode)) return;
activeMode = mode;
modeNames.forEach(name => {
targetWeights[name] = name === mode ? 1 : 0;
});
updatePanel();
buildRoute();
}
modeButtons.forEach(button => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
addEventListener("keydown", event => {
if (event.key === "1") setMode("boardwalk");
if (event.key === "2") setMode("dune");
if (event.key === "3") setMode("seawall");
});
const overviewRadius = innerWidth < 760 ? 101 : 78;
const cameraGoal = {
theta: 0.63,
phi: 0.88,
radius: overviewRadius,
target: new THREE.Vector3(0, 0.6, 4)
};
const cameraCurrent = {
theta: cameraGoal.theta,
phi: cameraGoal.phi,
radius: cameraGoal.radius,
target: cameraGoal.target.clone()
};
let planView = false;
function applyCameraGoal() {
cameraGoal.phi = clamp(cameraGoal.phi, 0.13, 1.35);
cameraGoal.radius = clamp(cameraGoal.radius, 32, 125);
}
document.getElementById("planButton").addEventListener("click", event => {
planView = !planView;
if (planView) {
cameraGoal.theta = 0;
cameraGoal.phi = 0.14;
cameraGoal.radius = innerWidth < 760 ? 105 : 79;
cameraGoal.target.set(0, 0, 4);
} else {
cameraGoal.theta = 0.63;
cameraGoal.phi = 0.88;
cameraGoal.radius = overviewRadius;
cameraGoal.target.set(0, 0.6, 4);
}
event.currentTarget.textContent = planView ? "Overview" : "Plan view";
});
document.getElementById("resetButton").addEventListener("click", () => {
planView = false;
cameraGoal.theta = 0.63;
cameraGoal.phi = 0.88;
cameraGoal.radius = overviewRadius;
cameraGoal.target.set(0, 0.6, 4);
document.getElementById("planButton").textContent = "Plan view";
});
const pointers = new Map();
let previousPinchDistance = null;
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
previousPinchDistance = null;
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: previous.button
});
if (pointers.size === 1) {
if (previous.button === 2 || event.shiftKey) {
const forward = new THREE.Vector3()
.subVectors(cameraGoal.target, camera.position)
.setY(0)
.normalize();
const right = new THREE.Vector3()
.crossVectors(new THREE.Vector3(0, 1, 0), forward)
.normalize();
const scale = cameraGoal.radius * 0.0014;
cameraGoal.target.addScaledVector(right, -dx * scale);
cameraGoal.target.addScaledVector(forward, dy * scale);
} else {
cameraGoal.theta -= dx * 0.0055;
cameraGoal.phi += dy * 0.0045;
}
} else 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) {
cameraGoal.radius *= previousPinchDistance / distance;
}
previousPinchDistance = distance;
}
applyCameraGoal();
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraGoal.radius *= Math.exp(event.deltaY * 0.001);
applyCameraGoal();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraGoal.theta = 0.63;
cameraGoal.phi = 0.88;
cameraGoal.radius = overviewRadius;
cameraGoal.target.set(0, 0.6, 4);
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
buildRoute();
updatePanel();
updateTerrain();
updateDuneGrass();
const clock = new THREE.Clock();
let frame = 0;
let previousTerrainMode = "";
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const smoothing = 1 - Math.exp(-delta * 5.2);
const cameraSmoothing = 1 - Math.exp(-delta * 7.5);
modeNames.forEach(name => {
weights[name] +=
(targetWeights[name] - weights[name]) * smoothing;
});
setGroupFade(
boardwalkGroup,
weights.boardwalk,
fadeMaterials.boardwalk
);
setGroupFade(duneGroup, weights.dune, fadeMaterials.dune);
setGroupFade(seawallGroup, weights.seawall, fadeMaterials.seawall);
const modeSignature = modeNames
.map(name => weights[name].toFixed(3))
.join("|");
if (modeSignature !== previousTerrainMode) {
updateTerrain();
updateDuneGrass();
skirts.forEach(skirt => skirt.update());
previousTerrainMode = modeSignature;
}
const endZ =
weights.boardwalk * modeData.boardwalk.exposureEnd +
weights.dune * modeData.dune.exposureEnd +
weights.seawall * modeData.seawall.exposureEnd;
const arrowLength = endZ + 14;
exposureArrows.forEach(arrow => {
arrow.setLength(arrowLength, 0.95, 0.55);
});
exposureField.scale.z = arrowLength;
exposureField.position.z = -14 + arrowLength / 2;
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const z = waterPositions.getZ(i);
const y =
0.025 +
Math.sin(x * 0.57 + elapsed * 0.8) * 0.045 +
Math.sin(z * 0.91 - elapsed * 0.65) * 0.032;
waterPositions.setY(i, y);
}
waterPositions.needsUpdate = true;
if (frame % 4 === 0) {
waterGeometry.computeVertexNormals();
}
foamLines.forEach((foam, index) => {
const attribute = foam.line.geometry.attributes.position;
for (let i = 0; i < attribute.count; i++) {
const x = attribute.getX(i);
const z =
foam.baseZ +
Math.sin(elapsed * 0.52 + foam.phase + x * 0.08) * 0.28;
attribute.setZ(i, z);
attribute.setY(i, 0.12 + Math.sin(x * 0.55 + elapsed) * 0.018);
}
attribute.needsUpdate = true;
foam.line.material.opacity = 0.16 + 0.12 * (0.5 + 0.5 * Math.sin(elapsed + index));
});
cameraCurrent.theta +=
(cameraGoal.theta - cameraCurrent.theta) * cameraSmoothing;
cameraCurrent.phi +=
(cameraGoal.phi - cameraCurrent.phi) * cameraSmoothing;
cameraCurrent.radius +=
(cameraGoal.radius - cameraCurrent.radius) * cameraSmoothing;
cameraCurrent.target.lerp(cameraGoal.target, cameraSmoothing);
const sinPhi = Math.sin(cameraCurrent.phi);
camera.position.set(
cameraCurrent.target.x +
cameraCurrent.radius * sinPhi * Math.sin(cameraCurrent.theta),
cameraCurrent.target.y +
cameraCurrent.radius * Math.cos(cameraCurrent.phi),
cameraCurrent.target.z +
cameraCurrent.radius * sinPhi * Math.cos(cameraCurrent.theta)
);
camera.lookAt(cameraCurrent.target);
const projected = modeData[activeMode].anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
annotationElement.style.opacity = visible ? "1" : "0";
annotationElement.style.left =
`${(projected.x * 0.5 + 0.5) * innerWidth}px`;
annotationElement.style.top =
`${(-projected.y * 0.5 + 0.5) * innerHeight - 12}px`;
renderer.render(scene, camera);
frame++;
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```