Prompt specification
Build or customize the Three.js 3D scene "Compare shoreline change under two schematic wave directions" 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: Compare shoreline change under two schematic wave directions
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compare-shoreline-change-under-two-schematic-wave-dire-x3080
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Great Lakes shorelines and dunes. Let users switch an illustrative wave approach while viewing sediment-motion arrows. Keep the model qualitative and avoid predicting actual erosion rates or property impacts. Low-poly.
Working Three.js Starter (compare-shoreline-change-under-two-schematic-wave-dire-x3080):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dce8e3" />
<title>Great Lakes Shoreline & Dunes — Qualitative Model</title>
<style>
:root {
--ink: #17343b;
--muted: #60747a;
--paper: #f8f5eb;
--line: rgba(23, 52, 59, 0.16);
--water: #4c93a4;
--sand: #d7bd7e;
--motion: #ee9d2f;
--green: #607a51;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: #dce8e3;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
width: 100%;
height: 100dvh;
}
.topbar {
position: relative;
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 28px;
padding: 18px 26px 16px;
background: var(--paper);
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 18px;
min-width: 0;
}
.brand-mark {
position: relative;
flex: 0 0 auto;
width: 42px;
height: 42px;
border: 1px solid rgba(23, 52, 59, 0.45);
border-radius: 50%;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
left: 6px;
right: 6px;
height: 7px;
border-top: 2px solid var(--water);
border-radius: 50%;
}
.brand-mark::before {
top: 12px;
}
.brand-mark::after {
top: 22px;
}
.eyebrow {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(22px, 3vw, 35px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.025em;
}
h1 em {
color: var(--water);
font-weight: 500;
}
.header-copy {
max-width: 480px;
margin-left: auto;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.reset-button {
flex: 0 0 auto;
padding: 9px 13px;
color: var(--ink);
background: transparent;
border: 1px solid var(--line);
border-radius: 999px;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease;
}
.reset-button:hover {
background: rgba(76, 147, 164, 0.08);
border-color: rgba(76, 147, 164, 0.45);
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
isolation: isolate;
background: #dce8e3;
}
#stage canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#stage canvas:active {
cursor: grabbing;
}
.scene-badge {
position: absolute;
z-index: 5;
top: 18px;
left: 20px;
display: flex;
align-items: center;
gap: 9px;
padding: 8px 11px;
color: var(--ink);
background: rgba(248, 245, 235, 0.82);
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 4px;
box-shadow: 0 7px 22px rgba(29, 55, 60, 0.08);
backdrop-filter: blur(9px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-badge::before {
content: "";
width: 7px;
height: 7px;
background: var(--water);
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(76, 147, 164, 0.17);
}
.control-panel {
position: absolute;
z-index: 10;
right: 20px;
bottom: 20px;
width: min(360px, calc(100% - 40px));
padding: 18px;
background: rgba(248, 245, 235, 0.92);
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 8px;
box-shadow: 0 18px 50px rgba(31, 61, 66, 0.16);
backdrop-filter: blur(12px);
}
.panel-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.panel-heading span {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.mode-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.mode-button {
position: relative;
min-width: 0;
padding: 11px 7px 10px;
color: var(--muted);
background: rgba(255, 255, 255, 0.38);
border: 1px solid var(--line);
border-radius: 5px;
text-align: left;
cursor: pointer;
transition:
color 160ms ease,
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.mode-button:hover {
transform: translateY(-1px);
border-color: rgba(76, 147, 164, 0.5);
}
.mode-button[aria-pressed="true"] {
color: #f9f6ed;
background: var(--ink);
border-color: var(--ink);
}
.mode-button .number {
display: block;
margin-bottom: 5px;
color: var(--water);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.mode-button[aria-pressed="true"] .number {
color: #9dd0d8;
}
.mode-button strong {
display: block;
font-size: 12px;
line-height: 1.1;
}
.mode-button small {
display: block;
margin-top: 4px;
opacity: 0.72;
font-size: 9px;
line-height: 1.2;
}
.mode-readout {
display: flex;
gap: 11px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.motion-key {
position: relative;
flex: 0 0 34px;
height: 28px;
margin-top: 2px;
}
.motion-key::before {
content: "";
position: absolute;
top: 13px;
left: 3px;
width: 24px;
height: 2px;
background: var(--motion);
transform: rotate(-12deg);
transform-origin: left center;
}
.motion-key::after {
content: "";
position: absolute;
top: 5px;
right: 0;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 8px solid var(--motion);
transform: rotate(-12deg);
transform-origin: left center;
}
.mode-readout b {
display: block;
margin-bottom: 3px;
font-size: 11px;
}
.mode-readout p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.legend {
position: absolute;
z-index: 6;
left: 20px;
bottom: 20px;
display: grid;
gap: 8px;
padding: 10px 12px;
color: var(--ink);
background: rgba(248, 245, 235, 0.78);
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 5px;
backdrop-filter: blur(8px);
font-size: 10px;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.legend-line {
display: inline-block;
width: 23px;
height: 2px;
background: #e8f8f6;
box-shadow: 0 1px 0 rgba(23, 52, 59, 0.25);
}
.legend-arrow {
display: inline-block;
width: 23px;
height: 2px;
background: var(--motion);
position: relative;
}
.legend-arrow::after {
content: "";
position: absolute;
top: -3px;
right: -1px;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 7px solid var(--motion);
}
.gesture-hint {
position: absolute;
z-index: 5;
right: 20px;
top: 20px;
padding: 7px 10px;
color: var(--muted);
background: rgba(248, 245, 235, 0.68);
border-radius: 4px;
backdrop-filter: blur(7px);
font-size: 10px;
}
.world-label {
position: absolute;
z-index: 4;
top: 0;
left: 0;
padding: 5px 8px;
color: rgba(23, 52, 59, 0.8);
background: rgba(248, 245, 235, 0.64);
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 3px;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 15px;
background: rgba(23, 52, 59, 0.3);
}
footer {
position: relative;
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 10px 26px;
color: var(--muted);
background: var(--paper);
border-top: 1px solid var(--line);
font-size: 10px;
line-height: 1.4;
}
footer strong {
color: var(--ink);
}
.footer-note {
flex: 0 0 auto;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 760px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100dvh;
}
.topbar {
padding: 13px 15px;
}
.brand-mark,
.header-copy {
display: none;
}
.reset-button {
padding: 7px 10px;
font-size: 11px;
}
#stage {
height: 72dvh;
min-height: 560px;
}
.control-panel {
right: 12px;
bottom: 12px;
width: calc(100% - 24px);
padding: 14px;
}
.legend {
top: 58px;
bottom: auto;
left: 12px;
}
.gesture-hint {
display: none;
}
.scene-badge {
top: 12px;
left: 12px;
}
footer {
display: block;
padding: 12px 15px;
}
.footer-note {
display: block;
margin-top: 5px;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<span class="eyebrow">Coastal systems / field note 01</span>
<h1>Great Lakes <em>Shoreline & Dunes</em></h1>
</div>
</div>
<div class="header-copy">
A schematic freshwater coast showing how an illustrative wave approach can
change the direction of visible sediment motion across the surf zone.
</div>
<button class="reset-button" id="reset-view" type="button">
Reset view
</button>
</header>
<main id="stage">
<div class="scene-badge">Schematic · qualitative</div>
<div class="gesture-hint">Drag to orbit · Scroll or pinch to zoom</div>
<div id="label-open-water" class="world-label">Open water</div>
<div id="label-dunes" class="world-label">Beach & dunes</div>
<div id="label-inland" class="world-label">Inland vegetation</div>
<div class="legend" aria-label="Model legend">
<div class="legend-row">
<span class="legend-line"></span>
<span>Illustrative wave crest</span>
</div>
<div class="legend-row">
<span class="legend-arrow"></span>
<span>Sediment-motion direction</span>
</div>
</div>
<section class="control-panel" aria-labelledby="wave-heading">
<div class="panel-heading">
<h2 id="wave-heading">Wave approach</h2>
<span>Choose a direction</span>
</div>
<div class="mode-buttons" role="group" aria-label="Illustrative wave approach">
<button
class="mode-button"
type="button"
data-mode="head"
aria-pressed="true"
>
<span class="number">01</span>
<strong>Head-on</strong>
<small>parallel crests</small>
</button>
<button
class="mode-button"
type="button"
data-mode="oblique"
aria-pressed="false"
>
<span class="number">02</span>
<strong>Oblique</strong>
<small>diagonal crests</small>
</button>
<button
class="mode-button"
type="button"
data-mode="alongshore"
aria-pressed="false"
>
<span class="number">03</span>
<strong>Alongshore</strong>
<small>glancing angle</small>
</button>
</div>
<div class="mode-readout">
<span class="motion-key" aria-hidden="true"></span>
<div>
<b id="mode-name">Head-on approach</b>
<p id="mode-description">
Wave crests run parallel to shore, with arrows showing mostly
onshore sediment motion.
</p>
</div>
</div>
</section>
</main>
<footer>
<div>
<strong>Interpretation:</strong> arrows and particles illustrate relative
direction only. This schematic does not estimate erosion rates,
sediment budgets, storm frequency, or property impacts.
</div>
<div class="footer-note">Not a surveyed or predictive engineering model</div>
</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly illustration of a Great Lakes shoreline, dunes, waves, and sediment motion"
);
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e3);
scene.fog = new THREE.Fog(0xdce8e3, 95, 185);
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 300);
const cameraState = {
target: new THREE.Vector3(-1.5, 1.0, 0),
radius: 79,
theta: 2.28,
phi: 0.96
};
const hemiLight = new THREE.HemisphereLight(0xf4fbff, 0x687158, 2.15);
scene.add(hemiLight);
const sunLight = new THREE.DirectionalLight(0xffefd0, 3.0);
sunLight.position.set(-28, 47, 31);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -60;
sunLight.shadow.camera.right = 60;
sunLight.shadow.camera.top = 55;
sunLight.shadow.camera.bottom = -55;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 130;
sunLight.shadow.bias = -0.0004;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0xa9d7df, 0.65);
fillLight.position.set(35, 20, -30);
scene.add(fillLight);
let randomSeed = 87431;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const waterMinX = -48;
const waterMaxZ = 39;
const landMinZ = -35;
const landMaxZ = 35;
const landWidth = 44;
function coastX(z) {
return (
2.3 * Math.sin(z * 0.075) +
1.05 * Math.sin(z * 0.21 + 1.3) +
0.45 * Math.sin(z * 0.43)
);
}
function terrainHeight(u, z) {
const primaryDune =
2.8 * Math.exp(-Math.pow((u - 0.115) / 0.055, 2));
const secondaryDune =
1.35 * Math.exp(-Math.pow((u - 0.225) / 0.115, 2));
const inlandRise = 0.08 + u * 0.7;
const facets =
0.16 *
Math.sin(z * 0.42 + u * 11.0) *
Math.sin(Math.PI * u) +
0.08 * Math.cos(z * 0.7 - u * 9.0);
return inlandRise + primaryDune + secondaryDune + facets;
}
function addTriangle(positions, colors, a, b, c, color) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
function buildWater() {
const positions = [];
const colors = [];
const nx = 20;
const nz = 30;
const point = (u, z) =>
new THREE.Vector3(
THREE.MathUtils.lerp(waterMinX, coastX(z), u),
0,
z
);
const deep = new THREE.Color(0x286b83);
const shallow = new THREE.Color(0x68a9b2);
for (let iz = 0; iz < nz; iz++) {
const z0 = THREE.MathUtils.lerp(-waterMaxZ, waterMaxZ, iz / nz);
const z1 = THREE.MathUtils.lerp(
-waterMaxZ,
waterMaxZ,
(iz + 1) / nz
);
for (let ix = 0; ix < nx; ix++) {
const u0 = ix / nx;
const u1 = (ix + 1) / nx;
const a = point(u0, z0);
const b = point(u1, z0);
const c = point(u0, z1);
const d = point(u1, z1);
const centerU = (u0 + u1) * 0.5;
const color = deep.clone().lerp(shallow, centerU);
color.offsetHSL(
(random() - 0.5) * 0.012,
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.035
);
addTriangle(positions, colors, a, c, b, color);
addTriangle(positions, colors, b, c, d, color.clone());
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.36,
metalness: 0.04,
flatShading: true
});
const water = new THREE.Mesh(geometry, material);
water.receiveShadow = true;
scene.add(water);
}
function terrainColor(u) {
if (u < 0.045) {
return new THREE.Color(0xd9c38d);
}
if (u < 0.245) {
return new THREE.Color(0xbda66b);
}
return new THREE.Color(0x5f7950);
}
function buildTerrain() {
const positions = [];
const colors = [];
const nx = 20;
const nz = 32;
const point = (u, z) =>
new THREE.Vector3(
coastX(z) + u * landWidth,
terrainHeight(u, z),
z
);
for (let iz = 0; iz < nz; iz++) {
const z0 = THREE.MathUtils.lerp(landMinZ, landMaxZ, iz / nz);
const z1 = THREE.MathUtils.lerp(
landMinZ,
landMaxZ,
(iz + 1) / nz
);
for (let ix = 0; ix < nx; ix++) {
const u0 = ix / nx;
const u1 = (ix + 1) / nx;
const a = point(u0, z0);
const b = point(u1, z0);
const c = point(u0, z1);
const d = point(u1, z1);
const centerU = (u0 + u1) * 0.5;
const color = terrainColor(centerU);
color.offsetHSL(
(random() - 0.5) * 0.018,
(random() - 0.5) * 0.045,
(random() - 0.5) * 0.065
);
addTriangle(positions, colors, a, c, b, color);
addTriangle(positions, colors, b, c, d, color.clone());
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const terrain = new THREE.Mesh(geometry, material);
terrain.castShadow = true;
terrain.receiveShadow = true;
scene.add(terrain);
}
function createWall(path, color) {
const positions = [];
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
const ab = new THREE.Vector3(a.x, -2.4, a.z);
const bb = new THREE.Vector3(b.x, -2.4, b.z);
positions.push(
a.x, a.y, a.z,
ab.x, ab.y, ab.z,
b.x, b.y, b.z,
b.x, b.y, b.z,
ab.x, ab.y, ab.z,
bb.x, bb.y, bb.z
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.95,
side: THREE.DoubleSide,
flatShading: true
});
const wall = new THREE.Mesh(geometry, material);
wall.receiveShadow = true;
scene.add(wall);
}
function buildDioramaEdges() {
const frontLand = [];
const backLand = [];
const farLand = [];
for (let i = 0; i <= 24; i++) {
const u = i / 24;
frontLand.push(
new THREE.Vector3(
coastX(landMaxZ) + u * landWidth,
terrainHeight(u, landMaxZ),
landMaxZ
)
);
backLand.push(
new THREE.Vector3(
coastX(landMinZ) + u * landWidth,
terrainHeight(u, landMinZ),
landMinZ
)
);
}
for (let i = 0; i <= 28; i++) {
const z = THREE.MathUtils.lerp(landMinZ, landMaxZ, i / 28);
farLand.push(
new THREE.Vector3(
coastX(z) + landWidth,
terrainHeight(1, z),
z
)
);
}
createWall(frontLand, 0x987d50);
createWall(backLand, 0x987d50);
createWall(farLand, 0x806c47);
const frontWater = [];
const backWater = [];
const farWater = [];
for (let i = 0; i <= 24; i++) {
const x = THREE.MathUtils.lerp(
waterMinX,
coastX(waterMaxZ),
i / 24
);
frontWater.push(new THREE.Vector3(x, 0, waterMaxZ));
const backX = THREE.MathUtils.lerp(
waterMinX,
coastX(-waterMaxZ),
i / 24
);
backWater.push(new THREE.Vector3(backX, 0, -waterMaxZ));
}
for (let i = 0; i <= 28; i++) {
const z = THREE.MathUtils.lerp(
-waterMaxZ,
waterMaxZ,
i / 28
);
farWater.push(new THREE.Vector3(waterMinX, 0, z));
}
createWall(frontWater, 0x285e72);
createWall(backWater, 0x285e72);
createWall(farWater, 0x285e72);
}
function buildShoreline() {
const points = [];
for (let i = 0; i <= 150; i++) {
const z = THREE.MathUtils.lerp(
landMinZ,
landMaxZ,
i / 150
);
points.push(
new THREE.Vector3(coastX(z) - 0.16, 0.11, z)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0xf4eed8,
transparent: true,
opacity: 0.92
});
const shoreline = new THREE.Line(geometry, material);
scene.add(shoreline);
}
function buildVegetation() {
const count = 105;
const geometry = new THREE.ConeGeometry(0.34, 0.92, 5);
geometry.translate(0, 0.46, 0);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const shrubs = new THREE.InstancedMesh(
geometry,
material,
count
);
shrubs.castShadow = true;
shrubs.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
for (let i = 0; i < count; i++) {
const z = THREE.MathUtils.lerp(
landMinZ + 1,
landMaxZ - 1,
random()
);
const u = 0.28 + random() * 0.67;
const x = coastX(z) + u * landWidth;
const y = terrainHeight(u, z);
dummy.position.set(x, y, z);
dummy.rotation.set(
(random() - 0.5) * 0.12,
random() * Math.PI * 2,
(random() - 0.5) * 0.12
);
const scale = 0.55 + random() * 1.2;
dummy.scale.set(scale, scale * (0.8 + random() * 0.7), scale);
dummy.updateMatrix();
shrubs.setMatrixAt(i, dummy.matrix);
color.setHSL(
0.25 + (random() - 0.5) * 0.035,
0.25 + random() * 0.16,
0.25 + random() * 0.13
);
shrubs.setColorAt(i, color);
}
shrubs.instanceMatrix.needsUpdate = true;
if (shrubs.instanceColor) {
shrubs.instanceColor.needsUpdate = true;
}
scene.add(shrubs);
}
buildWater();
buildTerrain();
buildDioramaEdges();
buildShoreline();
buildVegetation();
// Low-poly foam fragments along the waterline.
const foamCount = 110;
const foamGeometry = new THREE.CircleGeometry(0.25, 7);
foamGeometry.rotateX(-Math.PI / 2);
const foamMaterial = new THREE.MeshBasicMaterial({
color: 0xf6f2df,
transparent: true,
opacity: 0.72,
depthWrite: false
});
const foam = new THREE.InstancedMesh(
foamGeometry,
foamMaterial,
foamCount
);
foam.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(foam);
const foamData = [];
const foamDummy = new THREE.Object3D();
for (let i = 0; i < foamCount; i++) {
foamData.push({
z: THREE.MathUtils.lerp(
landMinZ,
landMaxZ,
random()
),
offset: 0.18 + random() * 0.65,
size: 0.45 + random() * 1.2,
phase: random() * Math.PI * 2
});
}
// Animated wave-crest segments.
const waveCount = 14;
const waveMaterials = [];
const waveGeometries = [];
const waveMeshes = [];
for (let i = 0; i < waveCount; i++) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(96 * 6), 3)
);
geometry.setDrawRange(0, 0);
const material = new THREE.LineBasicMaterial({
color: 0xe8fbf6,
transparent: true,
opacity: 0.35,
depthWrite: false
});
const mesh = new THREE.LineSegments(geometry, material);
mesh.frustumCulled = false;
scene.add(mesh);
waveGeometries.push(geometry);
waveMaterials.push(material);
waveMeshes.push(mesh);
}
// Custom low-poly motion arrows.
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xee9d2f,
emissive: 0x7c3900,
emissiveIntensity: 0.12,
roughness: 0.68,
flatShading: true
});
const shaftGeometry = new THREE.CylinderGeometry(
0.065,
0.065,
1.45,
5
);
shaftGeometry.translate(0, 0.725, 0);
const coneGeometry = new THREE.ConeGeometry(0.29, 0.65, 6);
coneGeometry.translate(0, 1.78, 0);
const arrows = [];
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < 21; i++) {
const group = new THREE.Group();
const shaft = new THREE.Mesh(shaftGeometry, arrowMaterial);
const head = new THREE.Mesh(coneGeometry, arrowMaterial);
shaft.castShadow = true;
head.castShadow = true;
group.add(shaft, head);
scene.add(group);
const z = THREE.MathUtils.lerp(
landMinZ + 2,
landMaxZ - 2,
random()
);
arrows.push({
group,
z,
offshore: 0.65 + random() * 4.9,
phase: random() * Math.PI * 2
});
}
// Moving sediment grains.
const sedimentCount = 48;
const sedimentGeometry = new THREE.TetrahedronGeometry(0.2, 0);
const sedimentMaterial = new THREE.MeshStandardMaterial({
color: 0xd59a43,
roughness: 0.9,
flatShading: true
});
const sediment = new THREE.InstancedMesh(
sedimentGeometry,
sedimentMaterial,
sedimentCount
);
sediment.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(sediment);
const sedimentData = [];
const sedimentDummy = new THREE.Object3D();
for (let i = 0; i < sedimentCount; i++) {
sedimentData.push({
z0: THREE.MathUtils.lerp(-30, 30, random()),
phase: random() * 10,
size: 0.55 + random() * 0.8
});
}
const modes = {
head: {
angle: 0,
drift: new THREE.Vector2(1, 0.06),
name: "Head-on approach",
description:
"Wave crests run parallel to shore, with arrows showing mostly onshore sediment motion."
},
oblique: {
angle: 0.38,
drift: new THREE.Vector2(0.74, 0.67),
name: "Oblique approach",
description:
"Waves arrive diagonally; arrows combine onshore and alongshore sediment motion."
},
alongshore: {
angle: 0.78,
drift: new THREE.Vector2(0.22, 0.98),
name: "Alongshore approach",
description:
"Waves arrive at a glancing angle; arrows emphasize movement parallel to the shoreline."
}
};
let selectedMode = "head";
let targetAngle = modes.head.angle;
let currentAngle = targetAngle;
const targetDrift = modes.head.drift.clone();
const currentDrift = targetDrift.clone();
const modeName = document.getElementById("mode-name");
const modeDescription = document.getElementById("mode-description");
const modeButtons = [
...document.querySelectorAll(".mode-button")
];
function selectMode(mode) {
selectedMode = mode;
const config = modes[mode];
targetAngle = config.angle;
targetDrift.copy(config.drift);
modeName.textContent = config.name;
modeDescription.textContent = config.description;
modeButtons.forEach((button) => {
button.setAttribute(
"aria-pressed",
String(button.dataset.mode === mode)
);
});
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
selectMode(button.dataset.mode);
});
});
// Camera controls are implemented directly, without examples or addons.
const pointers = new Map();
let lastPinchDistance = 0;
function clampCamera() {
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi,
0.32,
1.38
);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
48,
118
);
}
function resetCamera() {
cameraState.target.set(-1.5, 1.0, 0);
cameraState.radius = 79;
cameraState.theta = 2.28;
cameraState.phi = 0.96;
}
document.getElementById("reset-view").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
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
});
if (pointers.size === 1) {
cameraState.theta -= dx * 0.006;
cameraState.phi -= dy * 0.005;
clampCamera();
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
cameraState.radius *=
lastPinchDistance / distance;
clampCamera();
}
lastPinchDistance = distance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
clampCamera();
},
{ passive: false }
);
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.cos(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const labelDefinitions = [
{
element: document.getElementById("label-open-water"),
position: new THREE.Vector3(-25, 0.4, -15)
},
{
element: document.getElementById("label-dunes"),
position: new THREE.Vector3(
coastX(6) + 4.2,
terrainHeight(0.11, 6) + 0.6,
6
)
},
{
element: document.getElementById("label-inland"),
position: new THREE.Vector3(
coastX(-12) + 27,
terrainHeight(0.62, -12) + 0.5,
-12
)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const label of labelDefinitions) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
const clock = new THREE.Clock();
function updateFoam(time) {
foamMaterial.opacity = 0.62 + Math.sin(time * 1.25) * 0.1;
for (let i = 0; i < foamCount; i++) {
const item = foamData[i];
const pulse = 0.82 + Math.sin(time * 1.8 + item.phase) * 0.16;
foamDummy.position.set(
coastX(item.z) - item.offset,
0.13 + Math.sin(time * 1.4 + item.phase) * 0.025,
item.z
);
foamDummy.rotation.set(0, 0, 0);
foamDummy.scale.set(
item.size * pulse,
1,
item.size * pulse * (1.6 + random() * 0.01)
);
foamDummy.updateMatrix();
foam.setMatrixAt(i, foamDummy.matrix);
}
foam.instanceMatrix.needsUpdate = true;
}
function updateWaves(time) {
for (let i = 0; i < waveCount; i++) {
const geometry = waveGeometries[i];
const positions = geometry.attributes.position.array;
const phase = (time * 0.075 + i / waveCount) % 1;
const distance = 2.5 + phase * 45.5;
const centerZ = -32 + ((i * 17) % 64);
const angle = currentAngle;
const tangentX = -Math.sin(angle);
const tangentZ = Math.cos(angle);
let segmentCount = 0;
function wavePoint(t) {
const z = centerZ + t * tangentZ;
const x =
coastX(z) -
distance +
t * tangentX;
return { x, z };
}
for (let segment = 0; segment < 96; segment++) {
const t0 = -36 + (segment / 96) * 72;
const t1 = -36 + ((segment + 1) / 96) * 72;
const p0 = wavePoint(t0);
const p1 = wavePoint(t1);
const valid0 =
p0.x < coastX(p0.z) - 0.38 &&
p0.x > waterMinX + 0.4;
const valid1 =
p1.x < coastX(p1.z) - 0.38 &&
p1.x > waterMinX + 0.4;
if (valid0 && valid1 && segmentCount < 96) {
const offset = segmentCount * 6;
positions[offset] = p0.x;
positions[offset + 1] = 0.13;
positions[offset + 2] = p0.z;
positions[offset + 3] = p1.x;
positions[offset + 4] = 0.13;
positions[offset + 5] = p1.z;
segmentCount++;
}
}
geometry.setDrawRange(0, segmentCount * 2);
geometry.attributes.position.needsUpdate = true;
waveMaterials[i].opacity =
0.12 + Math.sin(Math.PI * phase) * 0.42;
}
}
function updateArrows(time) {
for (const arrow of arrows) {
const flutter = Math.sin(time * 1.2 + arrow.phase) * 0.035;
const direction = new THREE.Vector2(
currentDrift.x,
currentDrift.y + flutter
).normalize();
const movement =
Math.sin(time * 1.15 + arrow.phase) * 0.24;
const x =
coastX(arrow.z) -
arrow.offshore +
direction.x * movement;
const z =
arrow.z +
direction.y * movement;
arrow.group.position.set(x, 0.31, z);
const direction3 = new THREE.Vector3(
direction.x,
0,
direction.y
).normalize();
arrow.group.quaternion.setFromUnitVectors(
up,
direction3
);
}
}
function updateSediment(time) {
const alongshoreStrength = Math.abs(currentDrift.y);
const travelSpeed = 0.35 + alongshoreStrength * 1.8;
for (let i = 0; i < sedimentCount; i++) {
const item = sedimentData[i];
const travel =
(item.phase + time * travelSpeed * 0.22) % 42;
const z =
-30 +
((item.z0 + 30 + travel * currentDrift.y) % 60);
const distance =
0.55 +
((item.phase * 4.7 + time * 0.38) % 8.4);
const x = coastX(z) - distance;
sedimentDummy.position.set(
x,
0.18 + Math.sin(time * 1.4 + item.phase) * 0.035,
z
);
sedimentDummy.rotation.set(
time * 0.8 + item.phase,
time * 0.45 + item.phase,
time * 0.6
);
sedimentDummy.scale.setScalar(item.size);
sedimentDummy.updateMatrix();
sediment.setMatrixAt(i, sedimentDummy.matrix);
}
sediment.instanceMatrix.needsUpdate = true;
}
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
const blend = 1 - Math.exp(-dt * 4.8);
currentAngle = THREE.MathUtils.lerp(
currentAngle,
targetAngle,
blend
);
currentDrift.lerp(targetDrift, blend);
updateCamera();
updateFoam(time);
updateWaves(time);
updateArrows(time);
updateSediment(time);
updateLabels();
renderer.render(scene, camera);
}
selectMode("head");
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```