Prompt specification
Build or customize the Three.js 3D scene "Sea cliff with notch and fallen blocks" 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: Sea cliff with notch and fallen blocks
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sea-cliff-with-notch-and-fallen-blocks-x1121
Scene Description Prompt:
A low-poly layered sea cliff with an undercut base, beach, and fallen blocks. Build one HTML file with Three.js from cdnjs.
Working Three.js Starter (sea-cliff-with-notch-and-fallen-blocks-x1121):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Layered Sea Cliff</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a8c8cf;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 10;
max-width: min(360px, calc(100vw - 48px));
padding: 16px 18px;
color: #f7f1e4;
background: linear-gradient(135deg, rgba(28, 38, 39, 0.78), rgba(28, 38, 39, 0.46));
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 12px;
box-shadow: 0 12px 35px rgba(20, 35, 38, 0.16);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #d6c69e;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 4vw, 34px);
font-weight: 650;
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 9px;
color: rgba(247, 241, 228, 0.72);
font-size: 12px;
line-height: 1.45;
}
.controls {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 10;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
color: rgba(255, 255, 255, 0.84);
background: rgba(28, 38, 39, 0.58);
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 999px;
box-shadow: 0 8px 25px rgba(20, 35, 38, 0.14);
backdrop-filter: blur(8px);
font-size: 11px;
user-select: none;
}
.controls span {
white-space: nowrap;
}
button {
padding: 6px 10px;
color: #f7f1e4;
background: rgba(255, 255, 255, 0.09);
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 999px;
font: inherit;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.17);
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
background: #d0a16f;
border-radius: 2px;
transform: rotate(45deg);
}
@media (max-width: 640px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
}
}
</style>
</head>
<body>
<div class="title-card">
<div class="eyebrow">Coastal study · low-poly terrain</div>
<h1>Layered Sea Cliff</h1>
<div class="subtitle">
Wind-cut sandstone, an undercut shoreline, tidal foam, and fallen blocks.
</div>
</div>
<div class="controls">
<span class="swatch"></span>
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset</button>
</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.createElement("canvas");
canvas.setAttribute("aria-label", "Interactive low-poly layered sea cliff");
document.body.prepend(canvas);
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa8c8cf);
scene.fog = new THREE.Fog(0xa8c8cf, 38, 94);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const target = new THREE.Vector3(0, 5.5, 0);
const desired = {
radius: 33,
theta: -0.72,
phi: 1.22
};
const current = {
radius: 33,
theta: -0.72,
phi: 1.22
};
function updateCamera() {
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xd9eef2, 0x756044, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b0, 3.15);
sun.position.set(-18, 31, -13);
sun.target.position.set(0, 4, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -31;
sun.shadow.camera.right = 31;
sun.shadow.camera.top = 31;
sun.shadow.camera.bottom = -31;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00035;
scene.add(sun, sun.target);
const fill = new THREE.DirectionalLight(0x9ec6d0, 0.55);
fill.position.set(18, 12, 24);
scene.add(fill);
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
function pushTriangle(positions, colors, a, b, c, color) {
positions.push(...a, ...b, ...c);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
function edgeNoise(z) {
return Math.sin(z * 0.42) * 0.27 + Math.sin(z * 0.17 + 1.2) * 0.21;
}
function topHeight(x, z) {
return (
15.28 +
Math.sin(x * 0.53 + z * 0.14) * 0.09 +
Math.sin(z * 0.67 - x * 0.08) * 0.07
);
}
const cliffMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0,
flatShading: true
});
function addStratum({
y0,
y1,
front,
back = 30,
color,
topColor,
seed,
previousFront = null,
nextFront = null
}) {
const random = mulberry32(seed);
const zMin = -17;
const zMax = 17;
const segments = 14;
const positions = [];
const colors = [];
const rows = [];
for (let i = 0; i <= segments; i++) {
const z = THREE.MathUtils.lerp(zMin, zMax, i / segments);
rows.push({
z,
front: front + edgeNoise(z),
back
});
}
for (let i = 0; i < segments; i++) {
const r0 = rows[i];
const r1 = rows[i + 1];
const a = [r0.front, y0, r0.z];
const b = [r0.front, y1, r0.z];
const c = [r1.front, y1, r1.z];
const d = [r1.front, y0, r1.z];
const e = [back, y0, r0.z];
const f = [back, y1, r0.z];
const g = [back, y1, r1.z];
const h = [back, y0, r1.z];
const wallColor = new THREE.Color(color)
.multiplyScalar(0.86 + random() * 0.23);
pushTriangle(positions, colors, a, d, b, wallColor);
pushTriangle(positions, colors, b, d, c, wallColor);
// The lower face is omitted where the next stratum creates an overhang.
if (nextFront === null || nextFront >= front) {
const top = new THREE.Color(topColor)
.multiplyScalar(0.94 + random() * 0.12);
pushTriangle(positions, colors, a, d, e, top);
pushTriangle(positions, colors, d, h, e, top);
}
const undersideColor = new THREE.Color(color).multiplyScalar(0.48);
pushTriangle(positions, colors, e, f, h, undersideColor);
pushTriangle(positions, colors, f, g, h, undersideColor);
// Explicit downward-facing shelf under an undercut.
if (previousFront !== null && previousFront > front) {
const p0 = [front + edgeNoise(r0.z), y0, r0.z];
const p1 = [front + edgeNoise(r1.z), y0, r1.z];
const q0 = [previousFront + edgeNoise(r0.z), y0, r0.z];
const q1 = [previousFront + edgeNoise(r1.z), y0, r1.z];
pushTriangle(positions, colors, p0, q0, p1, undersideColor);
pushTriangle(positions, colors, p1, q0, q1, undersideColor);
}
}
const first = rows[0];
const last = rows[rows.length - 1];
const endColor = new THREE.Color(color).multiplyScalar(0.8);
pushTriangle(
positions,
colors,
[first.front, y0, first.z],
[first.front, y1, first.z],
[back, y1, first.z],
endColor
);
pushTriangle(
positions,
colors,
[first.front, y0, first.z],
[back, y1, first.z],
[back, y0, first.z],
endColor
);
pushTriangle(
positions,
colors,
[last.front, y0, last.z],
[back, y1, last.z],
[last.front, y1, last.z],
endColor
);
pushTriangle(
positions,
colors,
[last.front, y0, last.z],
[back, y0, last.z],
[back, y1, last.z],
endColor
);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, cliffMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
const strata = [
{
y0: -0.28,
y1: 2.15,
front: 3.15,
color: 0x625448,
topColor: 0x79604a
},
{
y0: 2.15,
y1: 3.22,
front: 2.95,
color: 0x87654d,
topColor: 0x977153
},
{
y0: 3.22,
y1: 4.18,
front: 0.76,
color: 0xb17b52,
topColor: 0xb77e52
},
{
y0: 4.18,
y1: 5.78,
front: 0.24,
color: 0xd09a68,
topColor: 0xc38a59
},
{
y0: 5.78,
y1: 7.28,
front: 0.54,
color: 0xb78057,
topColor: 0xb77b51
},
{
y0: 7.28,
y1: 8.72,
front: 0.06,
color: 0xd3aa77,
topColor: 0xc89a68
},
{
y0: 8.72,
y1: 10.18,
front: 0.45,
color: 0xa96f4c,
topColor: 0xb27850
},
{
y0: 10.18,
y1: 11.68,
front: -0.16,
color: 0xc99663,
topColor: 0xc18d5b
},
{
y0: 11.68,
y1: 13.18,
front: 0.29,
color: 0xdfb77e,
topColor: 0xd1a66e
},
{
y0: 13.18,
y1: 14.62,
front: -0.04,
color: 0xb77f54,
topColor: 0xb67a50
},
{
y0: 14.62,
y1: 15.22,
front: 0.52,
color: 0x866448,
topColor: 0x748052
}
];
strata.forEach((stratum, index) => {
addStratum({
...stratum,
seed: 410 + index * 97,
previousFront: index > 0 ? strata[index - 1].front : null,
nextFront: index < strata.length - 1 ? strata[index + 1].front : null
});
});
// Thin seam lines emphasize the horizontal bedding.
const seamMaterial = new THREE.LineBasicMaterial({
color: 0x4e392e,
transparent: true,
opacity: 0.4
});
strata.slice(1).forEach((stratum, index) => {
const points = [];
for (let i = 0; i <= 80; i++) {
const z = THREE.MathUtils.lerp(-17, 17, i / 80);
points.push(
new THREE.Vector3(
stratum.front + edgeNoise(z) - 0.045,
stratum.y0 + 0.025,
z
)
);
}
const seam = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
seamMaterial
);
scene.add(seam);
});
// Sparse vertical fractures in the exposed rock face.
const crackPositions = [];
const crackRandom = mulberry32(90210);
strata.forEach((stratum) => {
const count = Math.floor(crackRandom() * 3);
for (let i = 0; i < count; i++) {
const z = THREE.MathUtils.lerp(-16, 16, crackRandom());
const x = stratum.front + edgeNoise(z) - 0.07;
crackPositions.push(
x, stratum.y0 + 0.15, z,
x, stratum.y1 - 0.15, z
);
}
});
const crackGeometry = new THREE.BufferGeometry();
crackGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(crackPositions, 3)
);
scene.add(
new THREE.LineSegments(
crackGeometry,
new THREE.LineBasicMaterial({
color: 0x50392c,
transparent: true,
opacity: 0.28
})
)
);
// Faceted grassy plateau.
{
const positions = [];
const colors = [];
const random = mulberry32(712);
const zMin = -17;
const zMax = 17;
const zSegments = 24;
const xSegments = 8;
for (let zi = 0; zi < zSegments; zi++) {
const z0 = THREE.MathUtils.lerp(zMin, zMax, zi / zSegments);
const z1 = THREE.MathUtils.lerp(zMin, zMax, (zi + 1) / zSegments);
for (let xi = 0; xi < xSegments; xi++) {
const t0 = xi / xSegments;
const t1 = (xi + 1) / xSegments;
const x00 = THREE.MathUtils.lerp(0.34 + edgeNoise(z0), 30, t0);
const x01 = THREE.MathUtils.lerp(0.34 + edgeNoise(z0), 30, t1);
const x10 = THREE.MathUtils.lerp(0.34 + edgeNoise(z1), 30, t0);
const x11 = THREE.MathUtils.lerp(0.34 + edgeNoise(z1), 30, t1);
const p00 = [x00, topHeight(x00, z0), z0];
const p01 = [x01, topHeight(x01, z0), z0];
const p10 = [x10, topHeight(x10, z1), z1];
const p11 = [x11, topHeight(x11, z1), z1];
const c = new THREE.Color(0x758153)
.multiplyScalar(0.82 + random() * 0.3);
pushTriangle(positions, colors, p00, p10, p11, c);
pushTriangle(positions, colors, p00, p11, p01, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const grass = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
grass.receiveShadow = true;
scene.add(grass);
}
// Low, crossed grass blades add scale to the plateau.
{
const positions = [];
const colors = [];
const random = mulberry32(5544);
for (let i = 0; i < 85; i++) {
const x = 0.8 + random() * 24;
const z = -16.2 + random() * 32.4;
const y = topHeight(x, z);
const height = 0.18 + random() * 0.32;
const width = 0.08 + random() * 0.08;
const angle = random() * Math.PI;
for (let blade = 0; blade < 2; blade++) {
const a = angle + blade * Math.PI / 2;
const px = Math.cos(a);
const pz = Math.sin(a);
const left = [x - pz * width, y, z + px * width];
const right = [x + pz * width, y, z - px * width];
const tip = [x + px * height * 0.35, y + height, z + pz * height * 0.35];
const color = new THREE.Color(0x68774b)
.multiplyScalar(0.8 + random() * 0.35);
pushTriangle(positions, colors, left, right, tip, color);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
scene.add(
new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
side: THREE.DoubleSide,
roughness: 1
})
)
);
}
function shoreX(z) {
return -8.05 + Math.sin(z * 0.39) * 0.38 + Math.sin(z * 0.13 + 2) * 0.24;
}
// Sand beach.
{
const positions = [];
const colors = [];
const random = mulberry32(1852);
const segments = 60;
for (let i = 0; i < segments; i++) {
const z0 = THREE.MathUtils.lerp(-23, 23, i / segments);
const z1 = THREE.MathUtils.lerp(-23, 23, (i + 1) / segments);
const p0 = [shoreX(z0), 0.1, z0];
const p1 = [shoreX(z1), 0.1, z1];
const p2 = [3.65, 0.1, z1];
const p3 = [3.65, 0.1, z0];
const c = new THREE.Color(0xd8b77e)
.multiplyScalar(0.91 + random() * 0.16);
pushTriangle(positions, colors, p0, p1, p2, c);
pushTriangle(positions, colors, p0, p2, p3, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const beach = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
beach.receiveShadow = true;
scene.add(beach);
}
// Darker wet-sand strip.
{
const positions = [];
const segments = 60;
for (let i = 0; i < segments; i++) {
const z0 = THREE.MathUtils.lerp(-23, 23, i / segments);
const z1 = THREE.MathUtils.lerp(-23, 23, (i + 1) / segments);
const a = [shoreX(z0) - 0.45, 0.135, z0];
const b = [shoreX(z1) - 0.45, 0.135, z1];
const c = [shoreX(z1) + 0.95, 0.135, z1];
const d = [shoreX(z0) + 0.95, 0.135, z0];
positions.push(...a, ...b, ...c, ...a, ...c, ...d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const wetSand = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0xb49569,
roughness: 0.82,
side: THREE.DoubleSide
})
);
wetSand.receiveShadow = true;
scene.add(wetSand);
}
// Animated low-poly ocean.
const waterGeometry = new THREE.PlaneGeometry(25, 88, 24, 44);
waterGeometry.rotateX(-Math.PI / 2);
waterGeometry.translate(-19.3, -0.09, 0);
const waterBase = new Float32Array(
waterGeometry.attributes.position.array
);
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
color: 0x3f8790,
roughness: 0.46,
metalness: 0.04,
flatShading: true
})
);
water.receiveShadow = true;
scene.add(water);
// Irregular shoreline foam.
const foamMaterial = new THREE.MeshBasicMaterial({
color: 0xf1eee0,
transparent: true,
opacity: 0.78,
depthWrite: false,
side: THREE.DoubleSide
});
{
const positions = [];
const segments = 80;
for (let i = 0; i < segments; i++) {
const z0 = THREE.MathUtils.lerp(-25, 25, i / segments);
const z1 = THREE.MathUtils.lerp(-25, 25, (i + 1) / segments);
const w0 = 0.22 + Math.sin(i * 1.7) * 0.09;
const w1 = 0.22 + Math.sin((i + 1) * 1.7) * 0.09;
const a = [shoreX(z0) - 0.12, 0.19, z0];
const b = [shoreX(z1) - 0.12, 0.19, z1];
const c = [shoreX(z1) + w1, 0.19, z1];
const d = [shoreX(z0) + w0, 0.19, z0];
positions.push(...a, ...b, ...c, ...a, ...c, ...d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const foam = new THREE.Mesh(geometry, foamMaterial);
foam.renderOrder = 3;
scene.add(foam);
}
// Long offshore wave lines.
const waveLines = [];
[-11.6, -16.8, -22.5].forEach((x, index) => {
const points = [];
for (let i = 0; i <= 100; i++) {
const z = THREE.MathUtils.lerp(-31, 31, i / 100);
const waveX = x + Math.sin(z * 0.26 + index) * 0.55;
points.push(new THREE.Vector3(waveX, 0.1 + index * 0.01, z));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0xd9ebe4,
transparent: true,
opacity: 0.26 - index * 0.045
})
);
scene.add(line);
waveLines.push(line);
});
// Irregular low-poly rock geometry.
function makeRockGeometry(seed, colorHex) {
const random = mulberry32(seed);
const positions = [];
const colors = [];
const vertices = [
[-0.52, -0.43, -0.48],
[ 0.51, -0.46, -0.52],
[ 0.54, -0.39, 0.49],
[-0.49, -0.45, 0.52],
[-0.42, 0.46, -0.39],
[ 0.43, 0.39, -0.45],
[ 0.47, 0.44, 0.40],
[-0.47, 0.39, 0.43]
].map((vertex, index) => {
const edge = index < 4 ? -1 : 1;
return [
vertex[0] * (0.86 + random() * 0.28),
vertex[1] + edge * (random() - 0.5) * 0.12,
vertex[2] * (0.86 + random() * 0.28)
];
});
const faces = [
[0, 4, 5], [0, 5, 1],
[1, 5, 6], [1, 6, 2],
[2, 6, 7], [2, 7, 3],
[3, 7, 4], [3, 4, 0],
[4, 7, 6], [4, 6, 5],
[0, 1, 2], [0, 2, 3]
];
faces.forEach((face, index) => {
const shade = 0.76 + random() * 0.32;
const color = new THREE.Color(colorHex).multiplyScalar(shade);
const [a, b, c] = face.map((index) => vertices[index]);
pushTriangle(positions, colors, a, b, c, color);
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
return geometry;
}
const rockMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
flatShading: true
});
function addRock(position, scale, color, rotation, seed) {
const rock = new THREE.Mesh(
makeRockGeometry(seed, color),
rockMaterial
);
rock.position.set(...position);
rock.scale.set(...scale);
rock.rotation.set(...rotation);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
return rock;
}
// Large fallen blocks and talus around the undercut.
addRock([1.25, 0.52, -6.2], [2.35, 0.95, 1.5], 0xa8714d, [0.08, 0.45, -0.12], 11);
addRock([2.35, 0.43, -0.8], [1.45, 0.78, 1.1], 0xb98158, [-0.05, -0.34, 0.11], 22);
addRock([0.65, 0.42, 1.7], [1.2, 0.7, 0.92], 0x8e654b, [0.14, 0.82, -0.05], 33);
addRock([2.45, 0.36, 6.7], [1.65, 0.62, 1.18], 0xb17a53, [-0.09, 0.28, 0.08], 44);
addRock([1.15, 0.28, 9.6], [0.88, 0.48, 0.72], 0x9d6e4d, [0.17, -0.65, 0.03], 55);
addRock([2.85, 0.32, -10.3], [1.05, 0.58, 0.8], 0x765747, [0.02, 0.52, -0.08], 66);
const pebbleRandom = mulberry32(9041);
for (let i = 0; i < 34; i++) {
const z = -15 + pebbleRandom() * 30;
const x = shoreX(z) + 0.5 + pebbleRandom() * 2.45;
const size = 0.07 + pebbleRandom() * 0.18;
addRock(
[x, 0.12 + size * 0.4, z],
[size * 1.35, size * 0.7, size],
pebbleRandom() > 0.45 ? 0x8b765b : 0xb79b72,
[
pebbleRandom() * 0.35,
pebbleRandom() * Math.PI,
pebbleRandom() * 0.3
],
1000 + i
);
}
// A few distant seabirds.
const birds = [];
const birdMaterial = new THREE.LineBasicMaterial({
color: 0x3e5358,
transparent: true,
opacity: 0.7
});
[
[-8, 10.8, -10, 0.7],
[-12, 12.5, -14, 0.52],
[-6, 13.8, -17, 0.43]
].forEach((bird, index) => {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.55, 0, 0),
new THREE.Vector3(0, -0.18, 0),
new THREE.Vector3(0.55, 0, 0)
]);
const line = new THREE.Line(geometry, birdMaterial);
line.position.set(bird[0], bird[1], bird[2]);
line.scale.setScalar(bird[3]);
line.userData.phase = index * 1.8;
scene.add(line);
birds.push(line);
});
// Direct, dependency-free orbit controls.
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
desired.theta -= dx * 0.005;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.0045,
0.48,
1.48
);
lastX = event.clientX;
lastY = event.clientY;
});
function stopDragging(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
15,
62
);
},
{ passive: false }
);
function resetView() {
desired.radius = 33;
desired.theta = -0.72;
desired.phi = 1.22;
}
document.getElementById("reset").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "r" || event.key === "R") {
resetView();
}
if (event.key === "ArrowLeft") desired.theta -= 0.08;
if (event.key === "ArrowRight") desired.theta += 0.08;
if (event.key === "ArrowUp") desired.phi = Math.max(0.48, desired.phi - 0.06);
if (event.key === "ArrowDown") desired.phi = Math.min(1.48, desired.phi + 0.06);
});
const clock = new THREE.Clock();
let frame = 0;
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const damping = reducedMotion ? 1 : 0.11;
current.radius += (desired.radius - current.radius) * damping;
current.theta += (desired.theta - current.theta) * damping;
current.phi += (desired.phi - current.phi) * damping;
updateCamera();
const waterPositions = waterGeometry.attributes.position;
const motionScale = reducedMotion ? 0.25 : 1;
for (let i = 0; i < waterPositions.count; i++) {
const x = waterBase[i * 3];
const z = waterBase[i * 3 + 2];
const y =
-0.09 +
Math.sin(x * 0.53 + elapsed * 0.8) * 0.07 * motionScale +
Math.sin(z * 0.29 - elapsed * 0.58) * 0.045 * motionScale;
waterPositions.setY(i, y);
}
waterPositions.needsUpdate = true;
if (frame % 4 === 0) waterGeometry.computeVertexNormals();
foamMaterial.opacity = 0.7 + Math.sin(elapsed * 1.1) * 0.08 * motionScale;
waveLines.forEach((line, index) => {
line.position.x = Math.sin(elapsed * 0.25 + index) * 0.22 * motionScale;
});
birds.forEach((bird) => {
const phase = bird.userData.phase;
bird.position.y +=
Math.sin(elapsed * 0.8 + phase) * 0.0012 * motionScale;
bird.rotation.z = Math.sin(elapsed * 1.4 + phase) * 0.08 * motionScale;
});
frame++;
renderer.render(scene, camera);
}
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>
```