Prompt specification
Build or customize the Three.js 3D scene "Lamu waterfront stair and plastered niche" 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: Lamu waterfront stair and plastered niche
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/lamu-waterfront-stair-and-plastered-niche-x2933
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a waterfront stair and plastered niche in Lamu Old Town. Build a referenced waterfront stair fragment with plastered wall and shallow niche. Show the transition from boat landing to pedestrian level through clear step geometry. Voxel style.
Working Three.js Starter (lamu-waterfront-stair-and-plastered-niche-x2933):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lamu Old Town — Waterfront Stair Fragment</title>
<style>
:root {
color-scheme: light;
--ink: #173c3d;
--paper: rgba(250, 242, 224, 0.92);
--line: rgba(23, 60, 61, 0.18);
--accent: #b65f43;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 18%, rgba(255, 246, 207, 0.95), transparent 28%),
linear-gradient(180deg, #d9e7df 0%, #b9d3cc 55%, #78a9a7 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.info {
position: fixed;
top: 26px;
left: 26px;
z-index: 2;
width: min(360px, calc(100vw - 52px));
padding: 20px 22px 18px;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 3px;
box-shadow: 0 14px 45px rgba(29, 61, 58, 0.16);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 4vw, 44px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.04em;
}
.description {
margin: 13px 0 17px;
font-size: 12px;
line-height: 1.55;
color: rgba(23, 60, 61, 0.74);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
padding-top: 13px;
border-top: 1px solid var(--line);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 1px;
box-shadow: inset 0 0 0 1px rgba(23, 60, 61, 0.12);
}
.controls {
position: fixed;
right: 24px;
top: 24px;
z-index: 3;
display: flex;
align-items: center;
gap: 10px;
}
.hint {
padding: 10px 12px;
color: var(--ink);
background: rgba(250, 242, 224, 0.8);
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 3px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(10px);
pointer-events: none;
}
button {
padding: 11px 13px;
color: var(--ink);
background: rgba(250, 242, 224, 0.92);
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 3px;
box-shadow: 0 8px 24px rgba(29, 61, 58, 0.12);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: #fff9eb;
transform: translateY(-1px);
}
.caption {
position: fixed;
z-index: 2;
left: 26px;
bottom: 24px;
max-width: calc(100vw - 52px);
padding: 9px 11px;
color: rgba(250, 247, 232, 0.9);
background: rgba(23, 60, 61, 0.72);
border-radius: 2px;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 700px) {
.info {
top: 16px;
left: 16px;
width: min(300px, calc(100vw - 32px));
padding: 16px;
}
.description {
display: none;
}
.legend {
margin-top: 10px;
}
.controls {
top: auto;
right: 16px;
bottom: 52px;
}
.hint {
display: none;
}
.caption {
left: 16px;
bottom: 16px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel-style reconstruction of a Lamu waterfront stair, plastered niche, tidal landing, and dhow."
></canvas>
<section class="info">
<div class="eyebrow">Lamu Old Town · Waterfront Study 01</div>
<h1>Tidal<br>Stair Fragment</h1>
<p class="description">
A voxel interpretation of Lamu’s coral-rag waterfront: eight clear risers
descend from the pedestrian lane to the boat landing, beside a shallow
recess in a weathered plaster wall.
</p>
<div class="legend">
<span><i class="swatch" style="background:#d8b184"></i>Plaster</span>
<span><i class="swatch" style="background:#b86f52"></i>Coral rag</span>
<span><i class="swatch" style="background:#4a9b9a"></i>Tidal water</span>
</div>
</section>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom</div>
<button id="reset" type="button">Reset view</button>
</div>
<div class="caption">
Pedestrian level +3.20 m / 8 stepped risers / Tidal landing +0.40 m
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
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.fog = new THREE.Fog(0xc4d9d2, 18, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const world = new THREE.Group();
scene.add(world);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, roughness = 0.86, metalness = 0.0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
})
);
}
return materialCache.get(key);
}
function addBox(
parent,
size,
position,
color,
castShadow = true,
receiveShadow = true,
roughness = 0.86
) {
const mesh = new THREE.Mesh(unitBox, material(color, roughness));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let value = Math.imul(seed ^ (seed >>> 15), 1 | seed);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(4071);
const pick = (array) =>
array[Math.floor(random() * array.length)];
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff0d2,
0x4e8582,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2ad, 3.45);
sun.position.set(-7, 12, -9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9dc8c6, 0.8);
fill.position.set(8, 6, 8);
scene.add(fill);
// ------------------------------------------------------------
// Water: a grid of shallow square voxel tiles
// ------------------------------------------------------------
addBox(
world,
[15.2, 0.12, 20],
[-5.9, -0.13, -0.4],
"#287c81",
false,
true
);
const waterColors = [
"#3b9696",
"#439f9d",
"#348b8e",
"#4ca5a1",
"#398f92",
"#57aaa4"
];
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.38,
metalness: 0.04
});
const waterData = [];
const waterStep = 0.59;
for (let x = -11.45; x < 1.35; x += waterStep) {
for (let z = -8.8; z < 8.8; z += waterStep) {
waterData.push({
x: x + (random() - 0.5) * 0.035,
z: z + (random() - 0.5) * 0.035,
phase: random() * Math.PI * 2,
amplitude: 0.012 + random() * 0.025,
color: pick(waterColors)
});
}
}
const water = new THREE.InstancedMesh(
unitBox,
waterMaterial,
waterData.length
);
water.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
water.receiveShadow = true;
water.frustumCulled = false;
const dummy = new THREE.Object3D();
waterData.forEach((tile, index) => {
dummy.position.set(tile.x, -0.025, tile.z);
dummy.scale.set(0.565, 0.065, 0.565);
dummy.updateMatrix();
water.setMatrixAt(index, dummy.matrix);
water.setColorAt(index, new THREE.Color(tile.color));
});
water.instanceMatrix.needsUpdate = true;
water.instanceColor.needsUpdate = true;
scene.add(water);
// Small square reflections, also animated as voxel marks.
const shimmerData = [];
const shimmerMaterial = new THREE.MeshStandardMaterial({
color: 0xc6e1d5,
roughness: 0.5,
transparent: true,
opacity: 0.48,
depthWrite: false
});
for (let i = 0; i < 30; i++) {
shimmerData.push({
x: -10.8 + random() * 11.3,
z: -7.5 + random() * 15,
width: 0.2 + random() * 0.65,
phase: random() * Math.PI * 2
});
}
const shimmer = new THREE.InstancedMesh(
unitBox,
shimmerMaterial,
shimmerData.length
);
shimmer.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
shimmer.frustumCulled = false;
scene.add(shimmer);
// ------------------------------------------------------------
// Pedestrian level / raised promenade
// ------------------------------------------------------------
addBox(
world,
[5.2, 3.08, 4.8],
[4.6, 1.54, -0.55],
"#b97758"
);
const pavingColors = [
"#d8b98b",
"#e1c69c",
"#cfa87d",
"#dcc097",
"#c89b72"
];
const pavingMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92
});
const pavingItems = [];
for (let x = 2.14; x < 7.14; x += 0.55) {
for (let z = -2.64; z < 1.58; z += 0.55) {
pavingItems.push({
position: [x, 3.14, z],
scale: [0.525, 0.12, 0.525],
color: pick(pavingColors)
});
}
}
const paving = new THREE.InstancedMesh(
unitBox,
pavingMaterial,
pavingItems.length
);
pavingItems.forEach((item, index) => {
dummy.position.set(...item.position);
dummy.scale.set(...item.scale);
dummy.updateMatrix();
paving.setMatrixAt(index, dummy.matrix);
paving.setColorAt(index, new THREE.Color(item.color));
});
paving.instanceMatrix.needsUpdate = true;
paving.instanceColor.needsUpdate = true;
paving.receiveShadow = true;
world.add(paving);
// Exposed masonry courses on the seaward face of the promenade.
const courseColors = ["#9f604d", "#ae6b51", "#c07a59"];
for (let course = 0; course < 5; course++) {
const y = 0.42 + course * 0.53;
for (let x = 2.16; x < 7.1; x += 0.64) {
addBox(
world,
[0.61, 0.43, 0.065],
[x, y, -2.985],
courseColors[(course + Math.floor(x)) % courseColors.length]
);
}
}
// Narrow drainage channel along the top edge of the stair.
addBox(
world,
[0.12, 0.025, 3.0],
[2.04, 3.215, -0.05],
"#526f66",
false,
true
);
// ------------------------------------------------------------
// Clear stepped transition: promenade to tidal landing
// ------------------------------------------------------------
const stepRun = 0.66;
const stepRise = 0.35;
const stepCount = 8;
const promenadeY = 3.2;
const stepBodyColors = [
"#b96f52",
"#c17a59",
"#ae674f",
"#c5825e"
];
for (let i = 0; i < stepCount; i++) {
const xRight = 2.0 - i * stepRun;
const xLeft = xRight - stepRun;
const top = promenadeY - (i + 1) * stepRise;
const centerX = (xLeft + xRight) * 0.5;
const bodyTop = top - 0.1;
addBox(
world,
[stepRun + 0.006, bodyTop - 0.02, 3.05],
[centerX, (bodyTop + 0.02) * 0.5, -0.05],
stepBodyColors[i % stepBodyColors.length]
);
// Pale limestone tread cap makes each level immediately legible.
addBox(
world,
[stepRun - 0.012, 0.1, 3.025],
[centerX, top - 0.05, -0.05],
i % 2 === 0 ? "#e3c9a1" : "#d8bc92"
);
}
// Low boat landing, just above the tidal water.
const landingRight = 2.0 - stepCount * stepRun;
const landingLeft = landingRight - 1.9;
const landingTop = promenadeY - stepCount * stepRise;
addBox(
world,
[1.9, landingTop - 0.02, 3.3],
[(landingLeft + landingRight) * 0.5, (landingTop + 0.02) * 0.5, -0.05],
"#a96550"
);
for (let x = landingLeft + 0.26; x < landingRight; x += 0.48) {
for (let z = -1.48; z < 1.4; z += 0.48) {
addBox(
world,
[0.45, 0.08, 0.45],
[x, landingTop - 0.04, z],
pick(["#c9a276", "#d4b184", "#bd956d"])
);
}
}
// Tidal discoloration along the two lowest risers.
for (let i = 5; i < stepCount; i++) {
const xLeft = 2.0 - (i + 1) * stepRun;
addBox(
world,
[0.028, 0.2, 2.94],
[xLeft - 0.018, 0.16, -0.05],
i % 2 === 0 ? "#467d6c" : "#4d7b68",
false,
true
);
}
addBox(
world,
[0.035, 0.17, 3.18],
[landingLeft - 0.02, 0.15, -0.05],
"#3e7568",
false,
true
);
// Voxel mooring posts on the landing.
for (const z of [-1.25, 1.08]) {
addBox(
world,
[0.22, 0.52, 0.22],
[landingLeft + 0.35, landingTop + 0.26, z],
"#5d4938"
);
addBox(
world,
[0.33, 0.12, 0.33],
[landingLeft + 0.35, landingTop + 0.57, z],
"#6e5540"
);
}
// ------------------------------------------------------------
// Plastered wall with a genuine shallow niche
// ------------------------------------------------------------
const wallPalette = [
"#d5ad81",
"#dfbd91",
"#cfa579",
"#e5c69d",
"#d8b287",
"#c99c72"
];
const wallBlocks = [];
const wallCell = 0.5;
const wallMinX = -4.25;
const wallMinY = 0.5;
const wallColumns = 13;
const wallRows = 10;
// Niche opening aligns exactly with the wall's voxel grid.
const niche = {
x0: -1.25,
x1: 0.25,
y0: 2.0,
y1: 3.5,
centerX: -0.5,
centerY: 2.75
};
for (let row = 0; row < wallRows; row++) {
for (let column = 0; column < wallColumns; column++) {
const x = wallMinX + wallCell * (column + 0.5);
const y = wallMinY + wallCell * (row + 0.5);
const insideNiche =
x > niche.x0 &&
x < niche.x1 &&
y > niche.y0 &&
y < niche.y1;
if (insideNiche) continue;
wallBlocks.push({
position: [x, y, 2.02],
scale: [wallCell, wallCell, 0.68],
color: pick(wallPalette)
});
}
}
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
});
const wall = new THREE.InstancedMesh(
unitBox,
wallMaterial,
wallBlocks.length
);
wallBlocks.forEach((block, index) => {
dummy.position.set(...block.position);
dummy.scale.set(...block.scale);
dummy.updateMatrix();
wall.setMatrixAt(index, dummy.matrix);
wall.setColorAt(index, new THREE.Color(block.color));
});
wall.instanceMatrix.needsUpdate = true;
wall.instanceColor.needsUpdate = true;
wall.castShadow = true;
wall.receiveShadow = true;
world.add(wall);
// Niche back wall: visibly behind the facade plane.
addBox(
world,
[1.5, 1.5, 0.08],
[niche.centerX, niche.centerY, 2.285],
"#bb7256"
);
// Side reveals and top reveal form the shallow recess.
addBox(
world,
[0.16, 1.66, 0.57],
[-1.30, 2.75, 1.99],
"#d3a87d"
);
addBox(
world,
[0.16, 1.66, 0.57],
[0.30, 2.75, 1.99],
"#c99d72"
);
addBox(
world,
[1.76, 0.16, 0.58],
[-0.5, 3.57, 1.99],
"#dfb98a"
);
// Projecting sill catches the sunlight and makes the depth obvious.
addBox(
world,
[1.94, 0.18, 0.84],
[-0.5, 1.95, 1.76],
"#e2c092"
);
// A stepped plaster lintel above the opening.
addBox(
world,
[1.12, 0.18, 0.82],
[-0.5, 3.70, 1.66],
"#e1b98a"
);
addBox(
world,
[0.32, 0.18, 0.82],
[-1.05, 3.88, 1.66],
"#d5ab7d"
);
addBox(
world,
[0.32, 0.18, 0.82],
[0.05, 3.88, 1.66],
"#d5ab7d"
);
// Small ceramic vessel inside the niche, built from square blocks.
addBox(
world,
[0.3, 0.3, 0.26],
[-0.72, 2.18, 2.08],
"#355f62"
);
addBox(
world,
[0.18, 0.13, 0.17],
[-0.72, 2.385, 2.08],
"#3f7273"
);
addBox(
world,
[0.26, 0.22, 0.23],
[-0.22, 2.14, 2.1],
"#e2b36f"
);
// Warm light emphasizing the niche.
const nicheLight = new THREE.PointLight(0xffa765, 7.5, 4.2, 2);
nicheLight.position.set(-0.5, 3.0, 1.52);
scene.add(nicheLight);
// Irregular repair patches across the plaster face.
const patchColors = [
"#e7c79e",
"#caa078",
"#dcb98c",
"#e0bd8d"
];
for (let i = 0; i < 25; i++) {
const x = -4.0 + random() * 5.85;
const y = 0.75 + random() * 4.35;
if (
x > niche.x0 - 0.3 &&
x < niche.x1 + 0.3 &&
y > niche.y0 - 0.2 &&
y < niche.y1 + 0.2
) {
continue;
}
addBox(
world,
[0.12 + random() * 0.24, 0.08 + random() * 0.18, 0.025],
[x, y, 1.67],
pick(patchColors),
false,
true
);
}
// Coping blocks cap the wall.
for (let i = 0; i < 13; i++) {
addBox(
world,
[0.5, 0.16, 0.78],
[-4 + i * 0.5, 5.56, 2.0],
i % 2 === 0 ? "#e4c49a" : "#d8b588"
);
}
// ------------------------------------------------------------
// Small voxel dhow at the boat landing
// ------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(-7.05, -0.015, -2.55);
boat.rotation.y = -0.27;
world.add(boat);
addBox(boat, [3.4, 0.34, 0.84], [0, 0.19, 0], "#694633");
addBox(boat, [2.85, 0.27, 0.64], [-0.05, 0.46, 0], "#8a5b3b");
addBox(boat, [0.58, 0.3, 0.58], [1.73, 0.4, 0], "#795036");
addBox(boat, [0.42, 0.25, 0.54], [-1.78, 0.39, 0], "#755039");
addBox(boat, [0.1, 0.12, 1.14], [0.05, 0.65, 0], "#b1814c");
addBox(boat, [0.11, 3.9, 0.11], [0.28, 2.45, 0], "#5b4434");
// Stepped lateen-style sail, assembled from horizontal voxel strips.
for (let row = 0; row < 11; row++) {
const width = 2.28 - row * 0.205;
const x = -0.83 + width * 0.5 + row * 0.035;
addBox(
boat,
[width, 0.255, 0.045],
[x, 0.95 + row * 0.255, -0.075],
row % 4 === 0 ? "#d9c8a0" : "#eee1bd",
true,
true
);
}
// A small warm patch on the sail.
addBox(
boat,
[0.34, 0.32, 0.055],
[-0.35, 2.18, -0.11],
"#bd7556",
false,
true
);
addBox(boat, [0.08, 0.8, 0.08], [1.36, 0.87, 0], "#5b4434");
// ------------------------------------------------------------
// Camera controls implemented directly, without addons
// ------------------------------------------------------------
const target = new THREE.Vector3(-0.75, 1.95, -0.1);
let azimuth = 2.42;
let polar = 1.13;
let cameraRadius = 15.7;
function updateCamera() {
const spherical = new THREE.Spherical(
cameraRadius,
THREE.MathUtils.clamp(polar, 0.35, 1.42),
azimuth
);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(target).add(offset);
camera.lookAt(target);
}
updateCamera();
const pointers = new Map();
let lastPinchDistance = 0;
function pinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.focus();
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
lastPinchDistance = pinchDistance();
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar + dy * 0.005, 0.35, 1.42);
} else if (pointers.size === 2) {
const distance = pinchDistance();
if (lastPinchDistance > 0 && distance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (lastPinchDistance / distance),
8.5,
24
);
}
lastPinchDistance = distance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = pinchDistance();
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
8.5,
24
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset").addEventListener("click", () => {
azimuth = 2.42;
polar = 1.13;
cameraRadius = 15.7;
updateCamera();
});
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
azimuth -= 0.12;
break;
case "ArrowRight":
azimuth += 0.12;
break;
case "ArrowUp":
polar = Math.max(0.35, polar - 0.08);
break;
case "ArrowDown":
polar = Math.min(1.42, polar + 0.08);
break;
case "+":
case "=":
cameraRadius = Math.max(8.5, cameraRadius - 0.8);
break;
case "-":
case "_":
cameraRadius = Math.min(24, cameraRadius + 0.8);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
waterData.forEach((tile, index) => {
const wave =
-0.025 +
Math.sin(time * 0.75 + tile.phase) * tile.amplitude +
Math.sin(time * 0.31 + tile.phase * 1.7) * 0.008;
dummy.position.set(tile.x, wave, tile.z);
dummy.scale.set(0.565, 0.065, 0.565);
dummy.updateMatrix();
water.setMatrixAt(index, dummy.matrix);
});
water.instanceMatrix.needsUpdate = true;
shimmerData.forEach((mark, index) => {
const pulse = 0.35 + 0.65 * (0.5 + 0.5 * Math.sin(time * 1.1 + mark.phase));
dummy.position.set(mark.x, 0.04, mark.z);
dummy.scale.set(mark.width * pulse, 0.018, 0.035);
dummy.updateMatrix();
shimmer.setMatrixAt(index, dummy.matrix);
});
shimmer.instanceMatrix.needsUpdate = true;
boat.position.y = -0.015 + Math.sin(time * 0.78) * 0.025;
boat.rotation.z = Math.sin(time * 0.63) * 0.012;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```