Prompt specification
Build or customize the Three.js 3D scene "Muttrah corniche railing and seawall curve" 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: Muttrah corniche railing and seawall curve
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/muttrah-corniche-railing-and-seawall-curve-x2945
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: Muttrah corniche railing and seawall curve. Build a referenced curved seawall fragment with railing and promenade paving. Show the relation between the public path, water edge, and rising terrain behind.
Working Three.js Starter (muttrah-corniche-railing-and-seawall-curve-x2945):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Muttrah Corniche — Voxel Seawall Study</title>
<style>
:root {
color-scheme: dark;
--ink: #102c39;
--paper: #f4ead7;
--blue: #24647f;
--sand: #c79d70;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d8e1;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene,
#scene canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 48%, rgba(9, 35, 45, 0.16)),
linear-gradient(to bottom, rgba(255,255,255,0.05), transparent 28%);
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--paper);
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 21px 17px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 4px;
background:
linear-gradient(135deg, rgba(15, 45, 57, 0.9), rgba(21, 66, 80, 0.76));
box-shadow: 0 16px 44px rgba(12, 37, 45, 0.18);
backdrop-filter: blur(9px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #d8bd91;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: #d8bd91;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 40px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 0;
color: rgba(244, 234, 215, 0.72);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px 12px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.13);
font-size: 10px;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 1px;
box-shadow: 0 0 0 1px rgba(255,255,255,0.2);
}
.sea { background: #36a6b6; }
.path { background: #dfc49a; }
.rail { background: #1d5878; }
.rock { background: #9b7653; }
.relationship {
position: absolute;
top: 27px;
right: 27px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,0.22);
border-radius: 3px;
background: rgba(17, 52, 65, 0.73);
color: rgba(244, 234, 215, 0.85);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.relationship b {
color: #e1bd88;
font-weight: 800;
}
.relationship i {
color: rgba(255,255,255,0.35);
font-style: normal;
}
.controls {
position: absolute;
bottom: 22px;
left: 50%;
display: flex;
align-items: center;
gap: 10px;
width: max-content;
max-width: calc(100vw - 32px);
padding: 9px 11px 9px 15px;
transform: translateX(-50%);
border: 1px solid rgba(255,255,255,0.18);
border-radius: 4px;
background: rgba(15, 43, 54, 0.76);
color: rgba(244, 234, 215, 0.78);
font-size: 10px;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
}
.controls kbd {
padding: 3px 5px;
border: 1px solid rgba(255,255,255,0.18);
border-radius: 3px;
background: rgba(255,255,255,0.08);
color: #f5ead4;
font: inherit;
}
.reset {
pointer-events: auto;
cursor: pointer;
padding: 6px 9px;
border: 1px solid rgba(255,255,255,0.18);
border-radius: 3px;
background: transparent;
color: #f5ead4;
font: inherit;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.reset:hover {
background: rgba(255,255,255,0.1);
}
.note {
position: absolute;
right: 25px;
bottom: 23px;
color: rgba(21, 54, 65, 0.66);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
.subtitle {
max-width: 290px;
}
.legend {
gap: 7px;
}
.relationship,
.note {
display: none;
}
.controls {
bottom: 13px;
gap: 6px;
padding-left: 10px;
font-size: 9px;
}
.controls .secondary {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<div id="hud">
<section class="title-card" aria-label="Scene information">
<div class="eyebrow">Muscat · Oman</div>
<h1>Muttrah<br />Corniche</h1>
<p class="subtitle">
An interpretive voxel study of the curved seawall, blue-and-white
geometric railing, public promenade, and the rocky terrain rising inland.
</p>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch sea"></i>Arabian Sea</span>
<span><i class="swatch path"></i>Public path</span>
<span><i class="swatch rail"></i>Corniche railing</span>
<span><i class="swatch rock"></i>Rising terrain</span>
</div>
</section>
<div class="relationship" aria-hidden="true">
<span>Sea edge</span><i>→</i>
<span>Walkway</span><i>→</i>
<b>Rocky slope</b>
</div>
<div class="controls">
<span><kbd>Drag</kbd> orbit</span>
<span class="secondary"><kbd>Shift</kbd> / right-drag pan</span>
<span class="secondary"><kbd>Scroll</kbd> zoom</span>
<button class="reset" id="reset" type="button">Reset</button>
</div>
<div class="note">Interpretive study · not a surveyed reconstruction</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, light
// ------------------------------------------------------------
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel reconstruction of Muttrah Corniche in Muscat"
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b8d8e1");
scene.fog = new THREE.FogExp2("#b8d8e1", 0.0065);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
420
);
const cameraState = {
target: new THREE.Vector3(0, 8.5, 4.5),
radius: 76,
theta: -1.04,
phi: 1.02
};
const defaultCamera = {
target: cameraState.target.clone(),
radius: cameraState.radius,
theta: cameraState.theta,
phi: cameraState.phi
};
function updateCamera() {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi, 0.25, 1.46);
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 27, 145);
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
updateCamera();
const hemi = new THREE.HemisphereLight("#d9f2f7", "#7e674c", 1.8);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0d4", 3.4);
sun.position.set(-28, 48, -32);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -72;
sun.shadow.camera.right = 72;
sun.shadow.camera.top = 62;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
sun.target.position.set(0, 5, 4);
scene.add(sun, sun.target);
// ------------------------------------------------------------
// Deterministic helpers
// ------------------------------------------------------------
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(24681357);
function tint(base, lightness = 0, saturation = 0) {
const color = new THREE.Color(base);
color.offsetHSL(0, saturation, lightness);
return color;
}
function addBox(
list,
x,
y,
z,
sx,
sy,
sz,
color,
rotation = 0
) {
list.push({
x, y, z,
sx, sy, sz,
color,
rotation
});
}
function addSegment(
list,
a,
b,
y,
height,
depth,
color
) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
list.push({
x: (a.x + b.x) * 0.5,
y,
z: (a.z + b.z) * 0.5,
sx: length,
sy: height,
sz: depth,
color,
rotation: -Math.atan2(dz, dx)
});
}
function makeInstanced(
items,
{
roughness = 0.85,
metalness = 0.0,
castShadow = true,
receiveShadow = true,
transparent = false,
opacity = 1
} = {}
) {
if (!items.length) return null;
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness,
metalness,
flatShading: true,
transparent,
opacity
});
const mesh = new THREE.InstancedMesh(geometry, material, items.length);
const dummy = new THREE.Object3D();
items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, item.rotation || 0, 0);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const color = item.color instanceof THREE.Color
? item.color.clone()
: new THREE.Color(item.color);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
mesh.computeBoundingSphere();
scene.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Curved corniche coordinate system
//
// X follows the length of the promenade.
// Positive local offset points inland.
// Negative local offset points toward the sea.
// ------------------------------------------------------------
const pathStart = -34;
const pathEnd = 34;
function curveZ(x) {
return 4.2 * Math.sin(x * 0.09) + 0.010 * x * x;
}
function curveDerivative(x) {
return 0.378 * Math.cos(x * 0.09) + 0.020 * x;
}
function pathPoint(x, offset = 0) {
const z = curveZ(x);
const dz = curveDerivative(x);
const length = Math.hypot(1, dz);
return {
x: x + (-dz / length) * offset,
z: z + (1 / length) * offset,
rotation: -Math.atan2(dz, 1),
normalX: -dz / length,
normalZ: 1 / length
};
}
function orientedBox(
list,
x,
offset,
y,
sx,
sy,
sz,
color,
extraRotation = 0
) {
const p = pathPoint(x, offset);
addBox(
list,
p.x,
y,
p.z,
sx,
sy,
sz,
color,
p.rotation + extraRotation
);
}
// ------------------------------------------------------------
// Sea
// ------------------------------------------------------------
const seaMaterial = new THREE.MeshStandardMaterial({
color: "#278fa8",
roughness: 0.38,
metalness: 0.08,
transparent: true,
opacity: 0.94
});
const sea = new THREE.Mesh(
new THREE.PlaneGeometry(260, 220),
seaMaterial
);
sea.rotation.x = -Math.PI / 2;
sea.position.set(0, 0, 4);
sea.receiveShadow = true;
scene.add(sea);
const waterGlints = [];
const glintColors = ["#64c1c9", "#8bd4d5", "#3ca8ba", "#b7e2df"];
for (let i = 0; i < 1450; i++) {
const x = random() * 142 - 71;
const seaLimit = curveZ(x) - 1.6;
if (seaLimit < -74) continue;
const z = -76 + random() * (seaLimit + 76);
const size = 0.08 + random() * 0.33;
addBox(
waterGlints,
x,
0.055 + random() * 0.025,
z,
size,
0.025,
size * (0.35 + random() * 0.8),
glintColors[Math.floor(random() * glintColors.length)],
random() < 0.5 ? 0 : Math.PI / 2
);
}
const glintMesh = makeInstanced(waterGlints, {
roughness: 0.45,
castShadow: false,
receiveShadow: false,
transparent: true,
opacity: 0.72
});
// Foam fragments tracing the seaward toe of the wall.
const foam = [];
for (let x = pathStart; x <= pathEnd; x += 0.52) {
const p = pathPoint(x, -1.02);
const count = random() > 0.55 ? 2 : 1;
for (let n = 0; n < count; n++) {
addBox(
foam,
p.x + (random() - 0.5) * 0.35,
0.1 + random() * 0.08,
p.z + (random() - 0.5) * 0.25,
0.16 + random() * 0.36,
0.08,
0.12 + random() * 0.17,
random() > 0.5 ? "#c7eee7" : "#8dd5d2",
p.rotation
);
}
}
makeInstanced(foam, {
roughness: 0.7,
castShadow: false,
receiveShadow: false,
transparent: true,
opacity: 0.85
});
// ------------------------------------------------------------
// Seawall: stacked masonry courses and projecting buttresses
// ------------------------------------------------------------
const masonry = [];
const capBlocks = [];
const stonePalette = ["#b99770", "#c7a77e", "#a98965", "#d0b18a"];
for (let x = pathStart; x < pathEnd; x += 0.82) {
const a = pathPoint(x, 0);
const b = pathPoint(Math.min(x + 0.82, pathEnd), 0);
for (let course = 0; course < 3; course++) {
const color =
course === 0
? tint("#80745d", -0.025, -0.08)
: tint(
stonePalette[
Math.floor(random() * stonePalette.length)
],
(random() - 0.5) * 0.045
);
addSegment(
masonry,
a,
b,
0.35 + course * 0.56,
0.52,
1.52 - course * 0.06,
color
);
}
addSegment(
capBlocks,
a,
b,
2.02,
0.28,
1.76,
random() > 0.5 ? "#dec39a" : "#d4b78e"
);
}
for (let x = pathStart + 2; x < pathEnd - 1; x += 4.2) {
orientedBox(
masonry,
x,
-0.73,
0.93,
0.58,
1.75,
1.42,
tint("#aa8a66", -0.015)
);
}
makeInstanced(masonry, { roughness: 0.93 });
makeInstanced(capBlocks, { roughness: 0.86 });
// ------------------------------------------------------------
// Promenade paving
// ------------------------------------------------------------
const paving = [];
const pavingRows = 7;
for (let row = 0; row < pavingRows; row++) {
const offset = 1.18 + row * 0.79;
for (let x = pathStart; x < pathEnd; x += 0.78) {
let color;
if (row === 0) {
color = random() > 0.5 ? "#e5d1ab" : "#d9c39b";
} else if (row === 1 || row === 5) {
color = random() > 0.42 ? "#6f9b9d" : "#c39b79";
} else {
const palette = ["#dec7a3", "#d4b78f", "#e8d5b4", "#c9a67f"];
color = palette[Math.floor(random() * palette.length)];
}
orientedBox(
paving,
x + 0.39,
offset,
2.27,
0.73,
0.19,
0.73,
tint(color, (random() - 0.5) * 0.025)
);
}
}
makeInstanced(paving, { roughness: 0.93 });
// Landward retaining edge between the path and rising terrain.
const retaining = [];
for (let x = pathStart; x < pathEnd; x += 1.1) {
const a = pathPoint(x, 6.5);
const b = pathPoint(Math.min(x + 1.1, pathEnd), 6.5);
addSegment(
retaining,
a,
b,
2.82,
1.2,
0.72,
random() > 0.5 ? "#b8956e" : "#c3a079"
);
}
makeInstanced(retaining, { roughness: 0.94 });
// ------------------------------------------------------------
// Muttrah-inspired blue-and-white geometric railing
// ------------------------------------------------------------
const railingBlue = [];
const railingIvory = [];
const railOffset = -0.58;
// Continuous segmented upper and lower rails.
for (let x = pathStart; x < pathEnd; x += 0.9) {
const a = pathPoint(x, railOffset);
const b = pathPoint(Math.min(x + 0.9, pathEnd), railOffset);
addSegment(
railingIvory,
a,
b,
3.32,
0.13,
0.14,
"#f0e7d3"
);
addSegment(
railingBlue,
a,
b,
2.57,
0.11,
0.12,
"#184f70"
);
}
// Main posts.
for (let x = pathStart; x <= pathEnd; x += 1.8) {
orientedBox(
railingBlue,
x,
railOffset,
2.76,
0.17,
1.2,
0.17,
"#184f70"
);
orientedBox(
railingIvory,
x,
railOffset,
3.29,
0.23,
0.12,
0.23,
"#f2e9d6"
);
}
// Fine vertical infill.
for (let x = pathStart + 0.45; x < pathEnd; x += 0.45) {
orientedBox(
railingBlue,
x,
railOffset,
2.96,
0.065,
0.75,
0.065,
"#1e5877"
);
}
// Voxel octagonal medallions in each main bay.
for (let x = pathStart + 0.9; x < pathEnd - 0.3; x += 1.8) {
const p = pathPoint(x, railOffset);
const radius = 0.32;
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const tangentX = Math.cos(p.rotation);
const tangentZ = -Math.sin(p.rotation);
addBox(
railingBlue,
p.x + tangentX * Math.cos(angle) * radius,
2.96 + Math.sin(angle) * radius,
p.z + tangentZ * Math.cos(angle) * radius,
0.115,
0.115,
0.115,
"#1e5877",
p.rotation
);
}
orientedBox(
railingIvory,
x,
railOffset,
2.96,
0.12,
0.12,
0.12,
"#f2e9d6"
);
}
makeInstanced(railingBlue, { roughness: 0.58, metalness: 0.12 });
makeInstanced(railingIvory, { roughness: 0.66 });
// ------------------------------------------------------------
// Rocky terrain rising behind the public path
// ------------------------------------------------------------
function terrainHeight(x, offset) {
const ridge = Math.max(0, offset - 7) * 0.33;
const westernPeak = 13.5 * Math.exp(
-(
((x + 15) * (x + 15)) / 225 +
((offset - 27) * (offset - 27)) / 260
)
);
const easternPeak = 18 * Math.exp(
-(
((x - 22) * (x - 22)) / 270 +
((offset - 34) * (offset - 34)) / 350
)
);
const noise =
1.8 * Math.sin(x * 0.33 + offset * 0.18) +
1.2 * Math.sin(x * 0.11 - offset * 0.27) +
0.9 * Math.sin((x + offset) * 0.49);
return Math.max(
3.5,
3.8 + ridge + westernPeak + easternPeak + noise
);
}
const terrain = [];
const terrainPalette = [
"#9d7856",
"#af8962",
"#bb9670",
"#88694f",
"#c1a07a"
];
for (let x = -55; x <= 55; x += 1.45) {
for (let offset = 7.2; offset <= 52; offset += 1.45) {
const p = pathPoint(x, offset);
const top = terrainHeight(x, offset);
const base = 2.18;
let y = base;
let level = 0;
while (top - y > 0.02) {
const chunkHeight = Math.min(2.45, top - y);
const levelColor = terrainPalette[
Math.floor(random() * terrainPalette.length)
];
const higher = level > 5 && random() > 0.78;
const color = higher
? "#6f7860"
: tint(levelColor, (random() - 0.5) * 0.045);
addBox(
terrain,
p.x,
y + chunkHeight * 0.5,
p.z,
1.42,
chunkHeight,
1.42,
color,
p.rotation
);
y += chunkHeight;
level++;
}
}
}
makeInstanced(terrain, { roughness: 0.98 });
// ------------------------------------------------------------
// Street furniture and people
// ------------------------------------------------------------
const props = [];
const darkMetal = "#244e5f";
const benchWood = "#8f5f3e";
// Benches along the landward side of the promenade.
for (const x of [-23, -3, 18]) {
orientedBox(props, x, 5.25, 2.93, 1.9, 0.16, 0.52, benchWood);
orientedBox(props, x, 5.53, 3.21, 1.9, 0.58, 0.12, benchWood);
for (const legX of [x - 0.65, x + 0.65]) {
orientedBox(props, legX, 5.25, 2.61, 0.12, 0.52, 0.42, darkMetal);
}
}
// Blue-and-white promenade lamps.
for (const x of [-29, -17, -5, 7, 19, 31]) {
orientedBox(props, x, 5.75, 3.03, 0.13, 1.35, 0.13, darkMetal);
orientedBox(props, x, 5.75, 3.76, 0.30, 0.23, 0.30, "#f0e5cb");
orientedBox(props, x, 5.75, 3.93, 0.43, 0.10, 0.43, darkMetal);
}
// Voxel pedestrians show the scale and public use of the path.
const people = [
[-26, 2.0, "#b75e49", "#e8b18a"],
[-20, 3.7, "#355e78", "#9e674d"],
[-11, 1.6, "#d8b76f", "#c68f68"],
[-6, 4.1, "#6d8c6d", "#e0ae87"],
[4, 2.4, "#8d5661", "#a9684c"],
[12, 3.8, "#e2d2af", "#b87e5d"],
[22, 1.9, "#315f6b", "#d19b74"],
[29, 4.0, "#bc7446", "#8f5c48"]
];
for (const [x, offset, shirt, skin] of people) {
const p = pathPoint(x, offset);
const heading = p.rotation + (random() - 0.5) * 0.6;
addBox(props, p.x - 0.13, 2.78, p.z, 0.16, 0.70, 0.18, "#384852", heading);
addBox(props, p.x + 0.13, 2.78, p.z, 0.16, 0.70, 0.18, "#384852", heading);
addBox(props, p.x, 3.35, p.z, 0.50, 0.72, 0.30, shirt, heading);
addBox(props, p.x, 3.91, p.z, 0.32, 0.32, 0.30, skin, heading);
}
// ------------------------------------------------------------
// Stylized date palms on the rising terrain
// ------------------------------------------------------------
const palms = [];
const palmGreen = ["#4e7855", "#62865d", "#3f6a50"];
const palmTrunk = "#896345";
const palmSites = [
[-30, 10.5],
[-15, 12.5],
[-3, 9.5],
[11, 12.0],
[25, 10.0],
[34, 13.0]
];
for (const [x, offset] of palmSites) {
const p = pathPoint(x, offset);
const baseY = terrainHeight(x, offset);
const crownY = baseY + 4.5;
for (let level = 0; level < 8; level++) {
addBox(
palms,
p.x + level * 0.025,
baseY + 0.28 + level * 0.55,
p.z,
0.42,
0.57,
0.42,
tint(palmTrunk, (random() - 0.5) * 0.025)
);
}
addBox(palms, p.x, crownY, p.z, 0.55, 0.5, 0.55, "#765039");
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2 + random() * 0.12;
const dx = Math.cos(angle);
const dz = Math.sin(angle);
addBox(
palms,
p.x + dx * 1.15,
crownY + 0.05 + (i % 2) * 0.12,
p.z + dz * 1.15,
2.55,
0.24,
0.68,
palmGreen[i % palmGreen.length],
-Math.atan2(dz, dx)
);
}
}
makeInstanced(palms, { roughness: 0.88 });
// A few blocky gulls over the water.
const birds = [];
for (let i = 0; i < 8; i++) {
const x = -32 + random() * 62;
const z = -37 + random() * 32;
const y = 11 + random() * 9;
const scale = 0.65 + random() * 0.55;
addBox(birds, x, y, z, 0.25 * scale, 0.08, 0.12 * scale, "#f6f0df");
addBox(birds, x - 0.28 * scale, y + 0.04, z, 0.42 * scale, 0.07, 0.12 * scale, "#f6f0df");
addBox(birds, x + 0.28 * scale, y + 0.04, z, 0.42 * scale, 0.07, 0.12 * scale, "#f6f0df");
}
makeInstanced(birds, {
roughness: 0.8,
castShadow: false,
receiveShadow: false
});
// ------------------------------------------------------------
// Direct camera controls — no external controls addon
// ------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let dragState = null;
let previousPinchDistance = 0;
function pointerDistance() {
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
);
}
function panCamera(dx, dy) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const amount = cameraState.radius * 0.00115;
cameraState.target.addScaledVector(right, -dx * amount);
cameraState.target.addScaledVector(up, dy * amount);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-38,
38
);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
2,
27
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-24,
32
);
}
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) {
dragState = {
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
} else if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
dragState = null;
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.radius *= previousPinchDistance / distance;
}
previousPinchDistance = distance;
updateCamera();
return;
}
if (!dragState) return;
const dx = event.clientX - dragState.x;
const dy = event.clientY - dragState.y;
dragState.x = event.clientX;
dragState.y = event.clientY;
if (dragState.pan || event.shiftKey || event.buttons === 2) {
panCamera(dx, dy);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi -= dy * 0.005;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
if (pointers.size === 0) {
dragState = null;
} else {
const remaining = [...pointers.values()][0];
dragState = {
x: remaining.x,
y: remaining.y,
pan: false
};
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
break;
case "ArrowRight":
cameraState.theta -= 0.08;
break;
case "ArrowUp":
cameraState.radius *= 0.92;
break;
case "ArrowDown":
cameraState.radius *= 1.08;
break;
case "r":
case "R":
resetCamera();
break;
default:
return;
}
event.preventDefault();
updateCamera();
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
if (glintMesh) {
glintMesh.material.opacity = 0.68 + Math.sin(elapsed * 0.55) * 0.07;
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```