Prompt specification
Build or customize the Three.js 3D scene "Harbor beside a sediment-moving beach" 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: Harbor beside a sediment-moving beach
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/harbor-beside-a-sediment-moving-beach-x1123
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: harbor beside a sediment-moving beach. Build a small breakwater, beach, and headland; use arrows for conceptual alongshore transport and clearly mark the sheltered harbor basin versus exposed coast.
Working Three.js Starter (harbor-beside-a-sediment-moving-beach-x1123):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Harbor & Sediment-Moving Beach</title>
<style>
:root {
color-scheme: light;
--ink: #12313c;
--panel: rgba(247, 251, 250, 0.92);
--border: rgba(20, 61, 72, 0.16);
--orange: #ffad3f;
--cyan: #6bc9f2;
--shelter: #31b9aa;
--exposed: #3c8fc5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9dce7;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 17px 18px 15px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(28, 63, 73, 0.13);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 5px;
color: #4d737d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.6vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 13px;
color: #56727a;
font-size: 12px;
line-height: 1.45;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
padding-top: 12px;
border-top: 1px solid var(--border);
font-size: 11px;
font-weight: 650;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 15px;
height: 8px;
flex: 0 0 auto;
border-radius: 99px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.09);
}
.swatch.orange { background: var(--orange); }
.swatch.cyan { background: var(--cyan); }
.swatch.shelter { background: var(--shelter); }
.swatch.exposed { background: var(--exposed); }
.controls {
position: absolute;
top: 20px;
right: 20px;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 10px 28px rgba(28, 63, 73, 0.12);
pointer-events: auto;
}
button {
min-width: 38px;
height: 36px;
padding: 0 11px;
border: 0;
border-radius: 9px;
background: #e6efef;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: background 120ms ease, transform 120ms ease;
}
button:hover {
background: #d6e4e5;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.hint {
position: absolute;
right: 20px;
bottom: 18px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(247, 251, 250, 0.86);
color: #57747c;
font-size: 11px;
font-weight: 650;
box-shadow: 0 7px 22px rgba(28, 63, 73, 0.08);
}
.note {
position: absolute;
left: 20px;
bottom: 18px;
color: rgba(18, 49, 60, 0.72);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
.subtitle {
display: none;
}
.legend {
margin-top: 10px;
padding-top: 10px;
gap: 6px;
font-size: 10px;
}
.controls {
top: auto;
right: 12px;
bottom: 48px;
}
.hint {
display: none;
}
.note {
left: 12px;
bottom: 14px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel harbor and sediment transport scene"></canvas>
<div class="overlay">
<section class="title-card">
<div class="eyebrow">Conceptual coastal processes</div>
<h1>Harbor beside a moving beach</h1>
<p class="subtitle">
The breakwater shelters the harbor basin, while the exposed coast receives
waves that drive sediment along the shore toward the harbor.
</p>
<div class="legend">
<div class="legend-item">
<span class="swatch orange"></span>
Alongshore sediment arrows
</div>
<div class="legend-item">
<span class="swatch cyan"></span>
Incoming wave force
</div>
<div class="legend-item">
<span class="swatch shelter"></span>
Sheltered harbor water
</div>
<div class="legend-item">
<span class="swatch exposed"></span>
Exposed coastal water
</div>
</div>
</section>
<nav class="controls" aria-label="Camera controls">
<button id="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoom-out" title="Zoom out" aria-label="Zoom out">−</button>
<button id="reset" title="Reset camera" aria-label="Reset camera">Reset</button>
</nav>
<div class="hint">Drag to orbit · wheel to zoom · shift/right-drag to pan</div>
<div class="note">Conceptual diagram · arrows not to scale</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9dce7);
scene.fog = new THREE.Fog(0xb9dce7, 105, 190);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
260
);
// ---------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, and reset.
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.8, 1.5),
goalTarget: new THREE.Vector3(0, 0.8, 1.5),
radius: 68,
goalRadius: 68,
theta: 0.72,
goalTheta: 0.72,
phi: 0.82,
goalPhi: 0.82
};
function defaultRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.75) return 112;
if (aspect < 1.15) return 88;
return 68;
}
controls.radius = controls.goalRadius = defaultRadius();
function applyCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
applyCamera();
let dragging = false;
let panMode = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
function panBy(dx, dy) {
const forward = new THREE.Vector3()
.subVectors(controls.goalTarget, camera.position)
.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const amount = controls.goalRadius * 0.0016;
controls.goalTarget.addScaledVector(right, -dx * amount);
controls.goalTarget.addScaledVector(up, dy * amount);
controls.goalTarget.x = THREE.MathUtils.clamp(
controls.goalTarget.x, -22, 22
);
controls.goalTarget.z = THREE.MathUtils.clamp(
controls.goalTarget.z, -12, 16
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panMode = event.button === 2 || event.shiftKey;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panMode) {
panBy(dx, dy);
} else {
controls.goalTheta -= dx * 0.006;
controls.goalPhi = THREE.MathUtils.clamp(
controls.goalPhi - dy * 0.005,
0.32,
1.36
);
}
});
function stopDragging(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
panMode = false;
pointerId = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.goalRadius = THREE.MathUtils.clamp(
controls.goalRadius * Math.exp(event.deltaY * 0.001),
28,
135
);
},
{ passive: false }
);
function resetCamera() {
controls.goalTarget.set(0, 0.8, 1.5);
controls.goalTheta = 0.72;
controls.goalPhi = 0.82;
controls.goalRadius = defaultRadius();
}
document.querySelector("#zoom-in").addEventListener("click", () => {
controls.goalRadius = THREE.MathUtils.clamp(
controls.goalRadius * 0.86, 28, 135
);
});
document.querySelector("#zoom-out").addEventListener("click", () => {
controls.goalRadius = THREE.MathUtils.clamp(
controls.goalRadius * 1.16, 28, 135
);
});
document.querySelector("#reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "+" || event.key === "=") {
controls.goalRadius = Math.max(28, controls.goalRadius * 0.9);
}
if (event.key === "-" || event.key === "_") {
controls.goalRadius = Math.min(135, controls.goalRadius * 1.1);
}
if (event.key.toLowerCase() === "r") resetCamera();
});
// ---------------------------------------------------------------------
// Lighting and diorama base.
// ---------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xe9fbff, 0x5d6653, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3d4, 3.2);
sun.position.set(-24, 42, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -46;
sun.shadow.camera.right = 46;
sun.shadow.camera.top = 38;
sun.shadow.camera.bottom = -38;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 110;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x9dd8ff, 0.85);
rim.position.set(30, 16, -30);
scene.add(rim);
const base = new THREE.Mesh(
new THREE.BoxGeometry(64, 1.2, 44),
new THREE.MeshStandardMaterial({
color: 0x59666b,
roughness: 0.94
})
);
base.position.set(0, -1.15, 0);
base.receiveShadow = true;
scene.add(base);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function hash2(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453;
return value - Math.floor(value);
}
function shorelineZ(x) {
if (x <= -23) {
return -3.2 + Math.sin(x * 0.32) * 1.3;
}
if (x <= -4) {
return 8;
}
return (
7.2 +
Math.sin(x * 0.23) * 1.15 +
Math.sin(x * 0.51) * 0.45
);
}
// ---------------------------------------------------------------------
// Voxel terrain, exposed water, and sheltered harbor water.
// ---------------------------------------------------------------------
const landBlocks = [];
const exposedWater = [];
const shelteredWater = [];
for (let x = -31; x <= 31; x++) {
const shore = shorelineZ(x);
for (let z = -21; z <= 22; z++) {
if (z >= shore) {
const distanceInland = z - shore;
const n = hash2(x, z);
const headland = x <= -23;
let height;
let color;
if (headland) {
height = 2.15 + n * 1.55 + Math.max(0, -x - 25) * 0.12;
color = new THREE.Color(
n > 0.7 ? 0x858b84 : n > 0.34 ? 0x747c79 : 0x646d70
);
} else if (distanceInland < 1.6) {
height = 0.72 + n * 0.12;
color = new THREE.Color(0xb99453);
} else if (distanceInland < 4.8) {
height = 0.9 + n * 0.18;
color = new THREE.Color(n > 0.5 ? 0xe5c783 : 0xd8b66f);
} else if (distanceInland < 7.2) {
height = 1.08 + n * 0.2;
color = new THREE.Color(n > 0.5 ? 0xc8aa63 : 0xb99a57);
} else {
height = 1.38 + n * 0.3;
color = new THREE.Color(n > 0.55 ? 0x7f9d63 : 0x6f8d55);
}
if (z > 20) height += 0.25;
landBlocks.push({
x,
z,
height,
color
});
} else {
const sheltered =
x >= -21 &&
x <= -5 &&
z >= -9 &&
z <= 7;
const n = hash2(x + 10, z - 10);
const color = sheltered
? new THREE.Color().setHSL(
0.47,
0.48,
0.35 + n * 0.035
)
: new THREE.Color().setHSL(
0.55,
0.58,
0.41 + n * 0.045
);
(sheltered ? shelteredWater : exposedWater).push({
x,
z,
color
});
}
}
}
function makeBlockInstances(blocks, material, kind) {
const mesh = new THREE.InstancedMesh(
unitBox,
material,
blocks.length
);
blocks.forEach((block, index) => {
if (kind === "land") {
dummy.position.set(
block.x,
block.height / 2 - 0.55,
block.z
);
dummy.scale.set(0.97, block.height, 0.97);
} else {
dummy.position.set(block.x, -0.08, block.z);
dummy.scale.set(0.985, 0.18, 0.985);
}
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, block.color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = kind === "land";
mesh.receiveShadow = true;
mesh.frustumCulled = false;
scene.add(mesh);
return mesh;
}
const terrainMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
metalness: 0
});
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.36,
metalness: 0.08
});
makeBlockInstances(landBlocks, terrainMaterial, "land");
makeBlockInstances(exposedWater, waterMaterial, "water");
makeBlockInstances(shelteredWater, waterMaterial, "water");
// ---------------------------------------------------------------------
// Small U-shaped rubble breakwater.
// ---------------------------------------------------------------------
const breakwaterPath = [
[-22, 7], [-22, 5], [-22, 3], [-22, 1],
[-22, -1], [-22, -3], [-22, -5], [-22, -7],
[-21, -9], [-19, -10], [-17, -10], [-15, -10],
[-13, -10], [-11, -10], [-9, -10], [-8, -9],
[-7, -7], [-7, -5], [-7, -3], [-7, -1],
[-7, 1], [-7, 3], [-7, 5]
];
const rockBlocks = [];
breakwaterPath.forEach(([x, z], index) => {
const n = hash2(x * 2.3, z * 1.9);
rockBlocks.push({
x: x + (n - 0.5) * 0.16,
z: z + (hash2(z, x) - 0.5) * 0.16,
height: 1.55 + n * 0.75,
color: new THREE.Color(
n > 0.65 ? 0x7b8587 : n > 0.28 ? 0x626d72 : 0x505b62
)
});
if (index % 3 === 0) {
rockBlocks.push({
x: x + 0.3,
z: z - 0.22,
height: 0.8 + n * 0.35,
color: new THREE.Color(0x919795)
});
}
});
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
});
makeBlockInstances(rockBlocks, rockMaterial, "rock");
// Voxel grass on the dunes.
const grassBlocks = [];
for (let x = 0; x <= 30; x += 2) {
for (let z = 12; z <= 17; z += 2) {
if (hash2(x, z) > 0.48) {
grassBlocks.push({
x: x + hash2(z, x) * 0.5,
z,
height: 0.35 + hash2(x + 4, z) * 0.35,
color: new THREE.Color(0x526f43)
});
}
}
}
makeBlockInstances(grassBlocks, rockMaterial, "rock");
// ---------------------------------------------------------------------
// Harbor pier and a small moored voxel sailboat.
// ---------------------------------------------------------------------
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x8e6544,
roughness: 0.9
});
const dock = new THREE.Group();
const deck = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.25, 10.2),
woodMaterial
);
deck.position.set(-17, 0.85, 2.1);
deck.castShadow = true;
deck.receiveShadow = true;
dock.add(deck);
for (let i = 0; i < 16; i++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(1.5, 0.11, 0.48),
new THREE.MeshStandardMaterial({
color: i % 2 ? 0xa37650 : 0x936947,
roughness: 0.92
})
);
plank.position.set(-17, 1.03, -2.75 + i * 0.62);
plank.castShadow = true;
dock.add(plank);
}
for (let z = -2.5; z <= 7; z += 2.3) {
for (const x of [-17.56, -16.44]) {
const piling = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 1.75, 0.22),
new THREE.MeshStandardMaterial({
color: 0x614936,
roughness: 0.95
})
);
piling.position.set(x, 0.25, z);
piling.castShadow = true;
dock.add(piling);
}
}
scene.add(dock);
const boat = new THREE.Group();
boat.position.set(-15.35, 0.08, 0.3);
boat.rotation.y = -0.08;
const hullMaterial = new THREE.MeshStandardMaterial({
color: 0xf1e6c9,
roughness: 0.68
});
const blueMaterial = new THREE.MeshStandardMaterial({
color: 0x2d8295,
roughness: 0.65
});
const hull = new THREE.Mesh(
new THREE.BoxGeometry(0.95, 0.36, 2.65),
hullMaterial
);
hull.castShadow = true;
boat.add(hull);
const bow = new THREE.Mesh(
new THREE.BoxGeometry(0.6, 0.36, 0.65),
hullMaterial
);
bow.position.z = 1.55;
bow.castShadow = true;
boat.add(bow);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(1.0, 0.13, 2.25),
blueMaterial
);
stripe.position.y = -0.02;
boat.add(stripe);
const cabin = new THREE.Mesh(
new THREE.BoxGeometry(0.66, 0.56, 0.86),
hullMaterial
);
cabin.position.set(0, 0.42, -0.45);
cabin.castShadow = true;
boat.add(cabin);
const mast = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 3.4, 0.12),
new THREE.MeshStandardMaterial({ color: 0x66503b })
);
mast.position.set(0, 2.0, 0.38);
mast.castShadow = true;
boat.add(mast);
for (let row = 0; row < 5; row++) {
const width = 0.9 - row * 0.16;
const sail = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.32, 0.09),
new THREE.MeshStandardMaterial({
color: row % 2 ? 0xf7f4e7 : 0xffcf74,
roughness: 0.85
})
);
sail.position.set(width / 2 + 0.06, 1.16 + row * 0.34, 0.38);
sail.castShadow = true;
boat.add(sail);
}
scene.add(boat);
// ---------------------------------------------------------------------
// Entrance beacon and marker buoy.
// ---------------------------------------------------------------------
const beacon = new THREE.Group();
beacon.position.set(-7, 0, 5);
const beaconBase = new THREE.Mesh(
new THREE.BoxGeometry(1.0, 0.42, 1.0),
new THREE.MeshStandardMaterial({ color: 0x596268 })
);
beaconBase.position.y = 1.96;
beaconBase.castShadow = true;
beacon.add(beaconBase);
const tower = new THREE.Mesh(
new THREE.BoxGeometry(0.66, 1.2, 0.66),
new THREE.MeshStandardMaterial({ color: 0xf3f0df })
);
tower.position.y = 2.77;
tower.castShadow = true;
beacon.add(tower);
const redBand = new THREE.Mesh(
new THREE.BoxGeometry(0.69, 0.35, 0.69),
new THREE.MeshStandardMaterial({ color: 0xd9573f })
);
redBand.position.y = 3.02;
beacon.add(redBand);
const lantern = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.5, 0.58),
new THREE.MeshStandardMaterial({
color: 0xffd66b,
emissive: 0xffa52e,
emissiveIntensity: 1.5,
roughness: 0.35
})
);
lantern.position.y = 3.62;
beacon.add(lantern);
const beaconLight = new THREE.PointLight(0xffb83f, 2.2, 7, 2);
beaconLight.position.set(0, 3.7, 0);
beacon.add(beaconLight);
scene.add(beacon);
const buoy = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.85, 0.5),
new THREE.MeshStandardMaterial({
color: 0xf3bd3f,
emissive: 0x9d5f00,
emissiveIntensity: 0.25
})
);
buoy.position.set(-5.2, 0.48, 6.5);
buoy.castShadow = true;
scene.add(buoy);
// ---------------------------------------------------------------------
// Voxel arrows: orange alongshore transport and cyan incoming waves.
// ---------------------------------------------------------------------
function makeVoxelArrow(hex, scale = 1) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: hex,
emissive: hex,
emissiveIntensity: 0.22,
roughness: 0.45
});
function block(x, z, sx, sz) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, 0, z);
mesh.scale.set(sx, 0.28, sz);
mesh.castShadow = true;
group.add(mesh);
}
// Arrow points toward local +X.
block(-0.65, 0, 2.8, 0.4);
block(1.65, 0, 0.62, 0.62);
block(1.25, -0.58, 0.62, 0.62);
block(1.25, 0.58, 0.62, 0.62);
block(0.85, -1.15, 0.62, 0.62);
block(0.85, 1.15, 0.62, 0.62);
group.scale.setScalar(scale);
return group;
}
[
[25, 3.8, 0.95],
[14, 3.5, 1.0],
[3, 3.2, 0.95]
].forEach(([x, z, scale]) => {
const arrow = makeVoxelArrow(0xffa62f, scale);
arrow.position.set(x, 0.68, z);
arrow.rotation.y = Math.PI; // points left, toward the harbor
scene.add(arrow);
});
[
[11, -7.0, 0.78],
[23, -6.0, 0.78]
].forEach(([x, z, scale]) => {
const arrow = makeVoxelArrow(0x7cd7ff, scale);
arrow.position.set(x, 0.62, z);
arrow.rotation.y = -Math.PI / 2; // points landward
scene.add(arrow);
});
// ---------------------------------------------------------------------
// Animated foam pixels along the exposed beach.
// ---------------------------------------------------------------------
const foamData = [];
for (let x = 0; x <= 30; x += 1.35) {
foamData.push({
x,
z: shorelineZ(x) - 1.55,
phase: hash2(x, 2) * Math.PI * 2,
size: 0.55 + hash2(x, 9) * 0.38
});
if (x % 2.7 < 1.3) {
foamData.push({
x: x + 0.35,
z: shorelineZ(x) - 3.2,
phase: hash2(x, 4) * Math.PI * 2,
size: 0.32 + hash2(x, 6) * 0.22
});
}
}
const foam = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xeafaff,
emissive: 0x8fd8ea,
emissiveIntensity: 0.12,
roughness: 0.5,
transparent: true,
opacity: 0.9
}),
foamData.length
);
foam.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
foam.frustumCulled = false;
scene.add(foam);
// ---------------------------------------------------------------------
// Animated sand grains moving along the exposed surf and into the basin.
// ---------------------------------------------------------------------
const sedimentCount = 34;
const sediment = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xe9a43c,
emissive: 0xa85709,
emissiveIntensity: 0.12,
roughness: 0.62
}),
sedimentCount
);
for (let i = 0; i < sedimentCount; i++) {
sediment.setColorAt(
i,
new THREE.Color(i % 3 === 0 ? 0xf5bf58 : 0xdf8d2d)
);
}
sediment.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
sediment.frustumCulled = false;
scene.add(sediment);
// ---------------------------------------------------------------------
// Canvas-generated scene labels. These are Sprites, so no addons needed.
// ---------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width, y + height, x + width - r, y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(mainText, subtitle, accent, worldWidth = 13) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 256;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 1024, 256);
ctx.shadowColor = "rgba(9, 31, 38, 0.25)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 7;
roundedRect(ctx, 16, 16, 992, 224, 30);
ctx.fillStyle = "rgba(8, 34, 43, 0.91)";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.lineWidth = 7;
ctx.strokeStyle = accent;
ctx.stroke();
roundedRect(ctx, 35, 38, 12, 180, 6);
ctx.fillStyle = accent;
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#ffffff";
ctx.font = "800 49px system-ui, sans-serif";
ctx.fillText(mainText, 530, 91);
ctx.fillStyle = "#c5dadd";
ctx.font = "600 30px system-ui, sans-serif";
ctx.fillText(subtitle, 530, 165);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(worldWidth, worldWidth * 0.25, 1);
sprite.renderOrder = 20;
return sprite;
}
const harborLabel = makeLabel(
"SHELTERED HARBOR BASIN",
"calm water • lower wave energy",
"#4be0c7",
14
);
harborLabel.position.set(-13.1, 4.4, -2.4);
scene.add(harborLabel);
const exposedLabel = makeLabel(
"EXPOSED COAST",
"open waves • active sediment supply",
"#72cbff",
13
);
exposedLabel.position.set(18.7, 4.2, -2.4);
scene.add(exposedLabel);
const transportLabel = makeLabel(
"ALONGSHORE TRANSPORT",
"orange arrows: sediment moves left toward the harbor",
"#ffae42",
16
);
transportLabel.position.set(16.2, 6.7, 3.7);
scene.add(transportLabel);
const beachLabel = makeLabel(
"SEDIMENT-MOVING BEACH",
"sand supplied and carried along the shore",
"#ffd16b",
14
);
beachLabel.position.set(16.1, 2.7, 14.1);
scene.add(beachLabel);
const breakwaterLabel = makeLabel(
"BREAKWATER",
"shields the harbor basin",
"#dce4e5",
10.5
);
breakwaterLabel.position.set(-13.5, 4.3, -10.9);
scene.add(breakwaterLabel);
const headlandLabel = makeLabel(
"HEADLAND",
"rocky coastal edge",
"#c3c9c4",
9.2
);
headlandLabel.position.set(-27.1, 5.8, 1.2);
scene.add(headlandLabel);
const waveLabel = makeLabel(
"WAVE FORCE",
"incoming energy from the open coast",
"#74cfff",
10
);
waveLabel.position.set(23.2, 2.8, -10.4);
scene.add(waveLabel);
// ---------------------------------------------------------------------
// Animation loop.
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
const smoothing = 1 - Math.exp(-8 * delta);
controls.theta +=
(controls.goalTheta - controls.theta) * smoothing;
controls.phi +=
(controls.goalPhi - controls.phi) * smoothing;
controls.radius +=
(controls.goalRadius - controls.radius) * smoothing;
controls.target.lerp(controls.goalTarget, smoothing);
applyCamera();
// Foam pixels oscillate slightly along the exposed shoreline.
foamData.forEach((particle, index) => {
dummy.position.set(
particle.x,
0.14,
particle.z +
Math.sin(elapsed * 1.8 + particle.phase) * 0.28
);
dummy.scale.set(
particle.size,
0.12,
0.28 + particle.size * 0.16
);
dummy.updateMatrix();
foam.setMatrixAt(index, dummy.matrix);
});
foam.instanceMatrix.needsUpdate = true;
// Sand grains travel from the exposed beach toward the harbor mouth.
for (let i = 0; i < sedimentCount; i++) {
let x;
let z;
let size;
if (i < 25) {
const travel = (elapsed * 2.05 + i * 1.16) % 32.5;
x = 29.3 - travel;
z = shorelineZ(x) - 0.82 +
Math.sin(i * 2.1 + elapsed * 2.4) * 0.22;
size = 0.16 + hash2(i, 11) * 0.17;
} else {
const travel = (elapsed * 1.12 + (i - 25) * 0.77) % 8;
x = -4.35 - travel;
z = 6.65 - travel * 0.82 +
Math.sin(elapsed * 2 + i) * 0.24;
size = 0.16 + hash2(i, 15) * 0.14;
}
dummy.position.set(x, 0.21, z);
dummy.scale.setScalar(size);
dummy.rotation.y = elapsed * 0.7 + i;
dummy.updateMatrix();
sediment.setMatrixAt(i, dummy.matrix);
}
sediment.instanceMatrix.needsUpdate = true;
// Gentle mooring motion.
boat.position.y = 0.1 + Math.sin(elapsed * 1.25) * 0.07;
boat.rotation.z = Math.sin(elapsed * 0.85) * 0.018;
buoy.position.y = 0.48 + Math.sin(elapsed * 1.6 + 1.2) * 0.08;
beaconLight.intensity = 2.0 + Math.sin(elapsed * 2.2) * 0.35;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```