Prompt specification
Build or customize the Three.js 3D scene "Fjord cliff ledge and tiny quay" 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: Fjord cliff ledge and tiny quay
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fjord-cliff-ledge-and-tiny-quay-x3101
Scene Description Prompt:
Use Three.js from cdnjs to build a referenced Norwegian fjord-edge fragment with steep rock, narrow ledge, and small quay. Show how little level ground separates the cliff from the water. Deliver one self-contained HTML file with stylized solid shapes.
Working Three.js Starter (fjord-cliff-ledge-and-tiny-quay-x3101):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Norwegian Fjord Edge</title>
<style>
:root {
color-scheme: dark;
--paper: #f4f0e4;
--ink: #173035;
--glass: rgba(244, 240, 228, 0.9);
--line: rgba(23, 48, 53, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aac4c8;
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: 26px;
left: 28px;
z-index: 10;
width: min(355px, calc(100vw - 56px));
padding: 19px 21px 18px;
color: var(--ink);
background: var(--glass);
border: 1px solid rgba(255, 255, 255, 0.46);
border-radius: 3px;
box-shadow: 0 14px 40px rgba(25, 48, 51, 0.14);
backdrop-filter: blur(10px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: #c4573e;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 47px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.summary {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
font-size: 12px;
line-height: 1.55;
color: rgba(23, 48, 53, 0.76);
}
.view-panel {
position: fixed;
right: 26px;
top: 26px;
z-index: 20;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 2px;
padding: 10px 13px;
color: var(--ink);
background: rgba(244, 240, 228, 0.86);
box-shadow: 0 8px 24px rgba(25, 48, 51, 0.11);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
background: #f8f4e9;
transform: translateY(-1px);
}
button.active {
color: #f8f4e9;
background: #214249;
}
.help {
position: fixed;
right: 26px;
bottom: 24px;
z-index: 10;
padding: 10px 13px;
color: rgba(244, 240, 228, 0.88);
background: rgba(20, 49, 54, 0.66);
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 2px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend {
position: fixed;
left: 28px;
bottom: 26px;
z-index: 10;
display: flex;
gap: 15px;
align-items: center;
padding: 11px 14px;
color: var(--ink);
background: rgba(244, 240, 228, 0.82);
border: 1px solid rgba(255, 255, 255, 0.38);
border-radius: 2px;
box-shadow: 0 10px 28px rgba(25, 48, 51, 0.1);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: #67716b;
}
.swatch.ledge {
background: #c9b993;
}
.swatch.quay {
background: #865d3e;
}
#leader-layer {
position: fixed;
inset: 0;
z-index: 8;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leader-layer line {
stroke: rgba(250, 246, 232, 0.88);
stroke-width: 1.2;
}
#leader-layer circle {
fill: #f6e7b2;
stroke: rgba(23, 48, 53, 0.6);
stroke-width: 1;
}
.annotation {
position: fixed;
z-index: 9;
min-width: 128px;
padding: 8px 10px 9px;
color: #f6f2e6;
background: rgba(25, 52, 57, 0.84);
border-left: 2px solid #e0c27f;
box-shadow: 0 8px 22px rgba(14, 35, 39, 0.13);
transform: translate(-50%, -50%);
pointer-events: none;
backdrop-filter: blur(6px);
}
.annotation strong {
display: block;
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.annotation small {
display: block;
margin-top: 3px;
color: rgba(246, 242, 230, 0.72);
font-size: 9px;
line-height: 1.35;
}
@media (max-width: 700px) {
.title-card {
top: 16px;
left: 16px;
width: min(310px, calc(100vw - 32px));
padding: 15px 17px;
}
.summary {
display: none;
}
.view-panel {
top: auto;
right: 16px;
bottom: 62px;
}
button {
padding: 9px 10px;
font-size: 9px;
}
.help {
right: 16px;
bottom: 16px;
max-width: calc(100vw - 32px);
text-align: center;
}
.legend {
display: none;
}
.annotation {
min-width: 105px;
padding: 6px 8px;
}
.annotation small {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional Norwegian fjord edge"></canvas>
<header class="title-card">
<div class="eyebrow">Coastal fragment · Norway</div>
<h1>Fjord Edge</h1>
<p class="subtitle">Rock · ledge · quay</p>
<p class="summary">
A steep Norwegian rock face drops almost directly to the fjord.
Only a slim strip of level ground remains between the cliff and water.
</p>
</header>
<nav class="view-panel" aria-label="Camera views">
<button data-view="perspective" class="active">Perspective</button>
<button data-view="plan">Overhead</button>
<button data-view="section">Section</button>
</nav>
<div class="legend" aria-hidden="true">
<span><i class="swatch"></i> Steep rock</span>
<span><i class="swatch ledge"></i> Narrow ledge</span>
<span><i class="swatch quay"></i> Small quay</span>
</div>
<div class="help">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom
</div>
<svg id="leader-layer" aria-hidden="true"></svg>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene
// ------------------------------------------------------------
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9c4c8);
scene.fog = new THREE.Fog(0xa9c4c8, 38, 82);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemisphere = new THREE.HemisphereLight(0xe3f2f1, 0x565b52, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd1, 3.25);
sun.position.set(-13, 25, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8db8c2, 1.05);
fill.position.set(18, 12, -10);
scene.add(fill);
// Deterministic random values keep the composition repeatable.
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;
};
}
const random = mulberry32(73419);
const clamp = THREE.MathUtils.clamp;
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function horizontalMesh(points, y, material, name = "horizontal shape") {
const vectors = points.map((p) => new THREE.Vector2(p[0], p[1]));
const faces = THREE.ShapeUtils.triangulateShape(vectors, []);
const positions = [];
for (const face of faces) {
let a = points[face[0]];
let b = points[face[1]];
let c = points[face[2]];
// In the XZ plane, a clockwise triangle faces upward in world space.
const cross =
(b[0] - a[0]) * (c[1] - a[1]) -
(b[1] - a[1]) * (c[0] - a[0]);
if (cross > 0) [b, c] = [c, b];
positions.push(
a[0], y, a[1],
b[0], y, b[1],
c[0], y, c[1]
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.name = name;
mesh.receiveShadow = true;
return mesh;
}
function prismFromOutline(points, topY, bottomY, topMaterial, sideMaterial) {
const group = new THREE.Group();
group.add(horizontalMesh(points, topY, topMaterial, "upper surface"));
const positions = [];
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
positions.push(
a[0], topY, a[1],
a[0], bottomY, a[1],
b[0], bottomY, b[1],
a[0], topY, a[1],
b[0], bottomY, b[1],
b[0], topY, b[1]
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const sides = new THREE.Mesh(geometry, sideMaterial);
sides.castShadow = true;
sides.receiveShadow = true;
group.add(sides);
return group;
}
function box(width, height, depth, material, x, y, z, name = "") {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (name) mesh.name = name;
return mesh;
}
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.43,
metalness: 0.08,
flatShading: true
});
const shelfTopMaterial = new THREE.MeshStandardMaterial({
color: 0x7a7e72,
roughness: 1,
flatShading: true
});
const shelfSideMaterial = new THREE.MeshStandardMaterial({
color: 0x505a58,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
const cliffMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true
});
const cliffSideMaterial = new THREE.MeshStandardMaterial({
color: 0x505b59,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
const pathMaterial = new THREE.MeshStandardMaterial({
color: 0xc2b28c,
roughness: 1,
flatShading: true
});
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x66706d,
roughness: 0.96,
flatShading: true
});
const stoneDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x485653,
roughness: 1,
flatShading: true
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x80583c,
roughness: 0.92,
flatShading: true
});
const woodLightMaterial = new THREE.MeshStandardMaterial({
color: 0x9a714c,
roughness: 0.9,
flatShading: true
});
const ironMaterial = new THREE.MeshStandardMaterial({
color: 0x293638,
roughness: 0.7,
metalness: 0.45,
flatShading: true
});
const redMaterial = new THREE.MeshStandardMaterial({
color: 0xa64232,
roughness: 0.88,
flatShading: true
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x303b3c,
roughness: 0.92,
flatShading: true,
side: THREE.DoubleSide
});
const mossMaterial = new THREE.MeshStandardMaterial({
color: 0x64705a,
roughness: 1,
flatShading: true
});
const foamMaterial = new THREE.MeshBasicMaterial({
color: 0xdce9e4,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide
});
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0x8cb4b5,
transparent: true,
opacity: 0.32,
side: THREE.DoubleSide
});
// ------------------------------------------------------------
// Faceted fjord water
// ------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(80, 80, 30, 30);
const waterPosition = waterGeometry.attributes.position;
for (let i = 0; i < waterPosition.count; i++) {
waterPosition.setZ(i, (random() - 0.5) * 0.045);
}
waterGeometry.rotateX(-Math.PI / 2);
const facetedWater = waterGeometry.toNonIndexed();
const waterColors = [];
const waterPalette = [0x3f7580, 0x447d86, 0x396f79, 0x4d858d];
for (let i = 0; i < facetedWater.attributes.position.count; i += 3) {
const color = new THREE.Color(
waterPalette[Math.floor(random() * waterPalette.length)]
);
for (let j = 0; j < 3; j++) waterColors.push(color.r, color.g, color.b);
}
facetedWater.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
facetedWater.computeVertexNormals();
const water = new THREE.Mesh(facetedWater, waterMaterial);
water.name = "faceted fjord water";
water.receiveShadow = true;
scene.add(water);
// ------------------------------------------------------------
// Narrow shelf between cliff and water
// ------------------------------------------------------------
const shelfOutline = [
[-12, -5.2],
[-10, -2.0],
[-7, -1.35],
[-3, -1.15],
[0, -1.5],
[3, -1.1],
[6, -1.45],
[10, -1.9],
[12, -5.2]
].reverse();
const shelf = prismFromOutline(
shelfOutline,
1.5,
-0.65,
shelfTopMaterial,
shelfSideMaterial
);
shelf.name = "very narrow level shelf";
scene.add(shelf);
// The pale path is deliberately only a small strip wide.
const pathBack = [];
const pathFront = [];
for (let i = 0; i <= 14; i++) {
const x = -8 + i * (15 / 14);
const backZ = -2.48 + Math.sin(i * 0.72) * 0.08;
pathBack.push([x, backZ]);
pathFront.push([x, backZ + 0.62]);
}
const pathPoints = [...pathBack, ...pathFront.reverse()];
const path = horizontalMesh(pathPoints, 1.535, pathMaterial, "narrow ledge path");
path.castShadow = true;
scene.add(path);
// ------------------------------------------------------------
// Steep faceted cliff
// ------------------------------------------------------------
const xPositions = [-11.5, -9, -6.5, -4, -1.5, 1, 3.5, 6, 8.5, 11.5];
const cliffRows = [
{
y: [1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5],
z: [-2.62, -2.72, -2.56, -2.7, -2.61, -2.66, -2.55, -2.7, -2.6, -2.76]
},
{
y: [5.8, 7.1, 6.4, 8.0, 7.2, 8.7, 7.6, 6.8, 7.7, 5.5],
z: [-3.7, -3.4, -3.6, -3.3, -3.5, -3.25, -3.55, -3.45, -3.35, -3.8]
},
{
y: [10.2, 11.8, 12.8, 11.1, 12.5, 13.4, 12.1, 11.4, 12.6, 9.8],
z: [-4.8, -4.4, -4.9, -4.2, -4.6, -4.1, -4.5, -4.3, -4.4, -4.9]
},
{
y: [9.9, 11.1, 11.7, 10.7, 11.6, 12.1, 11.2, 10.8, 11.5, 9.4],
z: [-10, -10, -10, -10, -10, -10, -10, -10, -10, -10]
}
];
const cliffPositions = [];
const cliffIndices = [];
for (const row of cliffRows) {
for (let i = 0; i < xPositions.length; i++) {
cliffPositions.push(xPositions[i], row.y[i], row.z[i]);
}
}
const rowLength = xPositions.length;
for (let row = 0; row < cliffRows.length - 1; row++) {
for (let i = 0; i < xPositions.length - 1; i++) {
const a = row * rowLength + i;
const b = a + 1;
const c = (row + 1) * rowLength + i + 1;
const d = (row + 1) * rowLength + i;
cliffIndices.push(a, b, c, a, c, d);
}
}
const indexedCliff = new THREE.BufferGeometry();
indexedCliff.setAttribute(
"position",
new THREE.Float32BufferAttribute(cliffPositions, 3)
);
indexedCliff.setIndex(cliffIndices);
let cliffGeometry = indexedCliff.toNonIndexed();
cliffGeometry.computeVertexNormals();
const cliffPalette = [
0x59615d,
0x646b65,
0x6f746c,
0x505b58,
0x70756b,
0x5b655f
];
const cliffColors = [];
for (let i = 0; i < cliffGeometry.attributes.position.count; i += 3) {
const vertical = Math.floor(i / 3 / ((rowLength - 1) * 2));
const color = new THREE.Color(
cliffPalette[Math.floor(random() * cliffPalette.length)]
);
if (vertical === 2) color.lerp(new THREE.Color(0x718064), 0.24);
color.offsetHSL((random() - 0.5) * 0.025, 0, (random() - 0.5) * 0.07);
for (let j = 0; j < 3; j++) cliffColors.push(color.r, color.g, color.b);
}
cliffGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(cliffColors, 3)
);
const cliff = new THREE.Mesh(cliffGeometry, cliffMaterial);
cliff.name = "steep Norwegian rock face";
cliff.castShadow = true;
cliff.receiveShadow = true;
scene.add(cliff);
function createCliffSide(x, profile, facing) {
const shapePoints = profile.map((p) => new THREE.Vector2(p[0], p[1]));
const faces = THREE.ShapeUtils.triangulateShape(shapePoints, []);
const positions = [];
for (const face of faces) {
let points = face.map((index) => profile[index]);
const a = points[0];
const b = points[1];
const c = points[2];
const crossX =
(b[1] - a[1]) * (c[0] - a[0]) -
(b[0] - a[0]) * (c[1] - a[1]);
if (crossX * facing < 0) points = [points[0], points[2], points[1]];
for (const p of points) positions.push(x, p[1], p[0]);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, cliffSideMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
const leftProfile = [
[-2.62, 1.5],
[-3.7, 5.8],
[-4.8, 10.2],
[-10, 9.9],
[-10, -1.5],
[-2.62, -1.5]
];
const rightProfile = [
[-2.76, 1.5],
[-3.8, 5.5],
[-4.9, 9.8],
[-10, 9.4],
[-10, -1.5],
[-2.76, -1.5]
];
createCliffSide(-11.5, leftProfile, -1);
createCliffSide(11.5, rightProfile, 1);
// Angular vertical buttresses give the cliff a more geological profile.
const buttressMaterial = new THREE.MeshStandardMaterial({
color: 0x626b65,
roughness: 1,
flatShading: true
});
const buttressData = [
[-8.1, 3.7, -3.05, 0.9],
[-4.3, 4.0, -3.0, 1.05],
[2.4, 4.2, -3.0, 1.0],
[7.2, 3.8, -3.08, 0.9]
];
for (const [x, y, z, scale] of buttressData) {
const buttress = new THREE.Mesh(
new THREE.CylinderGeometry(0.3, 1.05, 4.8, 5, 1, false),
buttressMaterial
);
buttress.position.set(x, y, z);
buttress.scale.z = 0.7;
buttress.rotation.y = random() * Math.PI;
buttress.castShadow = true;
buttress.receiveShadow = true;
scene.add(buttress);
}
// Small angular rocks and moss on the cliff crown.
const summitRocks = [
[-3.4, 12.1, -5.1, 1.4],
[1.4, 13.5, -4.7, 1.1],
[5.2, 11.9, -4.8, 1.35],
[-7.4, 12.4, -5.0, 1.0]
];
for (const [x, y, z, scale] of summitRocks) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
random() > 0.45 ? mossMaterial : buttressMaterial
);
rock.position.set(x, y, z);
rock.scale.y = 0.6;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
scene.add(rock);
}
// ------------------------------------------------------------
// Small red shed pressed against the cliff
// ------------------------------------------------------------
const shed = new THREE.Group();
shed.name = "small red shoreline shed";
shed.position.set(8.65, 0, -2.5);
shed.add(box(2.0, 1.74, 1.1, redMaterial, 0, 2.42, 0, "red shed walls"));
const roofPositions = [
-1.15, 3.3, 0.7,
1.15, 3.3, 0.7,
-1.15, 3.3, -0.7,
1.15, 3.3, -0.7,
-1.15, 4.0, 0,
1.15, 4.0, 0
];
const roofIndices = [
0, 4, 5, 0, 5, 1,
2, 3, 5, 2, 5, 4
];
const roofGeometry = new THREE.BufferGeometry();
roofGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(roofPositions, 3)
);
roofGeometry.setIndex(roofIndices);
roofGeometry.computeVertexNormals();
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.castShadow = true;
shed.add(roof);
shed.add(box(0.46, 1.18, 0.055, woodMaterial, -0.32, 2.22, 0.58));
shed.add(box(0.43, 0.38, 0.06, stoneDarkMaterial, 0.48, 2.7, 0.58));
scene.add(shed);
// ------------------------------------------------------------
// Small timber and stone quay
// ------------------------------------------------------------
const quay = new THREE.Group();
quay.name = "small quay";
quay.add(box(2.8, 1.7, 4.7, stoneMaterial, -0.8, 0.55, 0.95, "quay foundation"));
quay.add(box(2.93, 0.22, 4.75, woodLightMaterial, -0.8, 1.43, 0.95));
for (let i = 0; i < 11; i++) {
const plank = box(
2.82,
0.16,
0.37,
i % 2 === 0 ? woodMaterial : woodLightMaterial,
-0.8,
1.61,
-1.12 + i * 0.41
);
quay.add(plank);
}
const bollardPositions = [
[-1.92, -0.7],
[0.32, -0.7],
[-1.92, 2.7],
[0.32, 2.7]
];
for (const [x, z] of bollardPositions) {
const bollard = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.16, 0.45, 8),
ironMaterial
);
bollard.position.set(x, 1.88, z);
bollard.castShadow = true;
quay.add(bollard);
}
// A short solid rope between two bollards.
const ropeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.32, 2.03, -0.7),
new THREE.Vector3(0.31, 1.82, 0.0),
new THREE.Vector3(0.32, 1.82, 0.95),
new THREE.Vector3(0.32, 2.03, 2.7)
]);
const rope = new THREE.Mesh(
new THREE.TubeGeometry(ropeCurve, 24, 0.027, 6, false),
new THREE.MeshStandardMaterial({ color: 0xb4a47a, roughness: 1 })
);
rope.castShadow = true;
quay.add(rope);
// Crates and a compact winch.
quay.add(box(0.55, 0.48, 0.55, woodMaterial, -1.35, 1.9, 1.55));
quay.add(box(0.48, 0.42, 0.48, woodLightMaterial, -1.28, 2.3, 1.53));
quay.add(box(0.12, 0.95, 0.12, woodMaterial, -1.72, 2.08, 0.55));
quay.add(box(0.12, 0.12, 0.95, woodMaterial, -1.72, 2.55, 0.1));
const spool = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.32, 10),
ironMaterial
);
spool.rotation.z = Math.PI / 2;
spool.position.set(-1.72, 2.26, 0.08);
quay.add(spool);
// Tiny figure for scale.
const figure = new THREE.Group();
figure.position.set(0.05, 1.7, 1.95);
const jacket = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.2, 0.53, 7),
new THREE.MeshStandardMaterial({ color: 0xd6a33b, roughness: 1 })
);
jacket.position.y = 0.73;
jacket.castShadow = true;
figure.add(jacket);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.14, 0),
new THREE.MeshStandardMaterial({ color: 0xd0a37d, roughness: 1 })
);
head.position.y = 1.16;
head.castShadow = true;
figure.add(head);
figure.add(box(0.1, 0.47, 0.12, ironMaterial, -0.1, 0.24, 0));
figure.add(box(0.1, 0.47, 0.12, ironMaterial, 0.1, 0.24, 0));
quay.add(figure);
scene.add(quay);
// ------------------------------------------------------------
// Foam and angular water marks
// ------------------------------------------------------------
const shoreControls = [
[-10, -2.0],
[-7, -1.35],
[-3, -1.15],
[0, -1.5],
[3, -1.1],
[6, -1.45],
[10, -1.9]
];
function shoreZ(x) {
for (let i = 0; i < shoreControls.length - 1; i++) {
const a = shoreControls[i];
const b = shoreControls[i + 1];
if (x >= a[0] && x <= b[0]) {
const t = (x - a[0]) / (b[0] - a[0]);
return THREE.MathUtils.lerp(a[1], b[1], t);
}
}
return x < -10 ? -2 : -1.9;
}
for (let i = 0; i < 21; i++) {
const x = -9.5 + random() * 19;
const z = shoreZ(x) + 0.08 + random() * 0.16;
const length = 0.35 + random() * 0.95;
const width = 0.035 + random() * 0.065;
const foam = horizontalMesh(
[
[x - length / 2, z],
[x - length * 0.18, z + width],
[x + length / 2, z + width * 0.4],
[x + length * 0.28, z - width * 0.5]
],
0.075,
foamMaterial,
"shore foam"
);
scene.add(foam);
}
for (let i = 0; i < 34; i++) {
const x = (random() - 0.5) * 32;
const z = 4 + random() * 17;
const length = 0.35 + random() * 1.35;
const width = 0.025 + random() * 0.055;
const ripple = horizontalMesh(
[
[x - length / 2, z],
[x, z + width],
[x + length / 2, z],
[x, z - width]
],
0.055,
rippleMaterial,
"water facet mark"
);
scene.add(ripple);
}
// A small dimension line makes the thin ground plane explicit.
const dimensionPositions = [
-3.5, 1.68, -2.55,
-3.5, 1.68, -1.22,
-3.68, 1.68, -2.55,
-3.32, 1.68, -2.55,
-3.68, 1.68, -1.22,
-3.32, 1.68, -1.22
];
const dimensionGeometry = new THREE.BufferGeometry();
dimensionGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dimensionPositions, 3)
);
const dimension = new THREE.LineSegments(
dimensionGeometry,
new THREE.LineBasicMaterial({
color: 0xf1d88f,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
dimension.renderOrder = 5;
scene.add(dimension);
// ------------------------------------------------------------
// Annotations, projected without an add-on renderer
// ------------------------------------------------------------
const annotationDefinitions = [
{
id: "cliff",
title: "Steep rock",
detail: "fjord wall",
anchor: new THREE.Vector3(-1.3, 8.1, -3.0),
offset: [135, -55]
},
{
id: "ledge",
title: "≈ 1 m ledge",
detail: "little level ground",
anchor: new THREE.Vector3(-3.5, 1.85, -1.9),
offset: [-120, 47]
},
{
id: "quay",
title: "Small quay",
detail: "timber landing",
anchor: new THREE.Vector3(-0.8, 1.95, 2.7),
offset: [105, 58]
}
];
const svg = document.querySelector("#leader-layer");
for (const definition of annotationDefinitions) {
const group = document.createElementNS(
"http://www.w3.org/2000/svg",
"g"
);
group.innerHTML = `
<line></line>
<circle r="4"></circle>
`;
svg.appendChild(group);
const element = document.createElement("div");
element.className = "annotation";
element.innerHTML = `
<strong>${definition.title}</strong>
<small>${definition.detail}</small>
`;
document.body.appendChild(element);
definition.group = group;
definition.line = group.querySelector("line");
definition.dot = group.querySelector("circle");
definition.element = element;
}
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const definition of annotationDefinitions) {
const cameraSpace = definition.anchor.clone().applyMatrix4(
camera.matrixWorldInverse
);
const projected = definition.anchor.clone().project(camera);
const visible = cameraSpace.z < 0 && projected.z > -1 && projected.z < 1;
definition.group.style.display = visible ? "" : "none";
definition.element.style.display = visible ? "" : "none";
if (!visible) continue;
const ax = (projected.x * 0.5 + 0.5) * width;
const ay = (-projected.y * 0.5 + 0.5) * height;
const lx = clamp(
ax + definition.offset[0],
85,
width - 85
);
const ly = clamp(
ay + definition.offset[1],
85,
height - 85
);
definition.line.setAttribute("x1", ax);
definition.line.setAttribute("y1", ay);
definition.line.setAttribute("x2", lx);
definition.line.setAttribute("y2", ly);
definition.dot.setAttribute("cx", ax);
definition.dot.setAttribute("cy", ay);
definition.element.style.left = `${lx}px`;
definition.element.style.top = `${ly}px`;
}
}
// ------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, touch pinch
// ------------------------------------------------------------
const desired = {
theta: 0.67,
phi: 1.02,
radius: 30,
target: new THREE.Vector3(0, 3.0, -1.7)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
const views = {
perspective: {
theta: 0.67,
phi: 1.02,
radius: 30,
target: new THREE.Vector3(0, 3.0, -1.7)
},
plan: {
theta: 0.015,
phi: 0.12,
radius: 27,
target: new THREE.Vector3(0, 1.5, -2.0)
},
section: {
theta: 0.015,
phi: 1.40,
radius: 31,
target: new THREE.Vector3(0, 4.0, -1.6)
}
};
const viewButtons = [...document.querySelectorAll("[data-view]")];
function activateView(name) {
const view = views[name];
if (!view) return;
desired.theta = view.theta;
desired.phi = view.phi;
desired.radius = view.radius;
desired.target.copy(view.target);
for (const button of viewButtons) {
button.classList.toggle("active", button.dataset.view === name);
}
}
for (const button of viewButtons) {
button.addEventListener("click", () => activateView(button.dataset.view));
}
const pointers = new Map();
let interactionMode = "orbit";
let pinchDistance = 0;
function clearActiveButtons() {
for (const button of viewButtons) button.classList.remove("active");
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
interactionMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
} else if (pointers.size === 2) {
interactionMode = "pinch";
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
clearActiveButtons();
});
canvas.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 === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0 && distance > 0) {
desired.radius = clamp(
desired.radius * (pinchDistance / distance),
13,
52
);
}
pinchDistance = distance;
return;
}
if (interactionMode === "orbit") {
desired.theta -= dx * 0.006;
desired.phi = clamp(desired.phi - dy * 0.005, 0.08, 1.49);
} else if (interactionMode === "pan") {
const right = new THREE.Vector3();
const forward = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, new THREE.Vector3(), forward);
right.y = 0;
forward.y = 0;
right.normalize();
forward.normalize();
const scale = desired.radius * 0.00135;
desired.target
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, dy * scale);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
interactionMode = "orbit";
pointers.set([...pointers.keys()][0], remaining);
pinchDistance = 0;
} else if (pointers.size === 0) {
interactionMode = "orbit";
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
13,
52
);
clearActiveButtons();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") desired.theta -= 0.08;
if (event.key === "ArrowRight") desired.theta += 0.08;
if (event.key === "ArrowUp") desired.phi = clamp(desired.phi - 0.06, 0.08, 1.49);
if (event.key === "ArrowDown") desired.phi = clamp(desired.phi + 0.06, 0.08, 1.49);
if (event.key === "+" || event.key === "=") desired.radius = clamp(desired.radius - 1, 13, 52);
if (event.key === "-") desired.radius = clamp(desired.radius + 1, 13, 52);
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
function animate() {
requestAnimationFrame(animate);
const damping = 0.075;
current.theta = THREE.MathUtils.lerp(
current.theta,
desired.theta,
damping
);
current.phi = THREE.MathUtils.lerp(
current.phi,
desired.phi,
damping
);
current.radius = THREE.MathUtils.lerp(
current.radius,
desired.radius,
damping
);
current.target.lerp(desired.target, damping);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x +
current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z +
current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
camera.updateMatrixWorld();
renderer.render(scene, camera);
updateAnnotations();
}
animate();
</script>
</body>
</html>
```