Prompt specification
Build or customize the Three.js 3D scene "Ponta Negra promenade and beach stair" 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: Ponta Negra promenade and beach stair
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ponta-negra-promenade-and-beach-stair-x2673
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Ponta Negra beach in Natal. Build a referenced promenade-to-beach stair fragment with railing and sloping sand. Show the elevation difference and keep the access path distinct from the waterline. Voxel style.
Working Three.js Starter (ponta-negra-promenade-and-beach-stair-x2673):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ponta Negra — Voxel Beach Access</title>
<style>
:root {
--ink: #17343b;
--paper: rgba(255, 248, 229, 0.92);
--sand: #e7c27b;
--coral: #e86f51;
--blue: #218da7;
--line: rgba(23, 52, 59, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9e5ed;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app, canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 22px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid rgba(255,255,255,.55);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 16px 44px rgba(28, 74, 85, .15);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--coral);
font-size: 11px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 38px);
line-height: .96;
letter-spacing: -.045em;
}
.subtitle {
margin: 10px 0 0;
max-width: 330px;
color: rgba(23, 52, 59, .72);
font-size: 13px;
line-height: 1.45;
}
.metrics {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 15px;
}
.metric {
min-width: 0;
padding: 9px 8px;
border-radius: 10px;
background: rgba(23, 52, 59, .065);
}
.metric span {
display: block;
overflow: hidden;
color: rgba(23, 52, 59, .58);
font-size: 8px;
font-weight: 800;
letter-spacing: .08em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.metric strong {
display: block;
margin-top: 4px;
font-size: 15px;
letter-spacing: -.03em;
white-space: nowrap;
}
.metric.drop strong { color: var(--coral); }
.compass {
position: absolute;
top: 25px;
right: 25px;
width: 58px;
height: 58px;
display: grid;
place-items: center;
border: 1px solid rgba(255,255,255,.7);
border-radius: 50%;
background: rgba(255,248,229,.72);
box-shadow: 0 10px 30px rgba(28,74,85,.12);
backdrop-filter: blur(8px);
}
.compass::before {
content: "";
position: absolute;
top: 10px;
width: 0;
height: 0;
border-right: 5px solid transparent;
border-bottom: 15px solid var(--coral);
border-left: 5px solid transparent;
}
.compass b {
margin-top: 22px;
font-size: 10px;
letter-spacing: .08em;
}
.help {
position: absolute;
left: 24px;
bottom: 23px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,.5);
border-radius: 11px;
background: rgba(255,248,229,.78);
color: rgba(23,52,59,.72);
font-size: 11px;
backdrop-filter: blur(8px);
}
.buttons {
position: absolute;
right: 24px;
bottom: 23px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(255,255,255,.65);
border-radius: 11px;
padding: 11px 14px;
background: rgba(255,248,229,.88);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 10px 24px rgba(28,74,85,.12);
backdrop-filter: blur(8px);
}
button:hover { background: #fff8e5; }
button:active { transform: translateY(1px); }
.world-label {
position: absolute;
z-index: 5;
display: none;
transform: translate(-50%, -50%);
padding: 7px 10px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 8px;
background: rgba(255,248,229,.9);
box-shadow: 0 7px 18px rgba(28,74,85,.14);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: .055em;
text-transform: uppercase;
white-space: nowrap;
backdrop-filter: blur(6px);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 16px;
background: currentColor;
opacity: .45;
}
.world-label.path { color: #b64e37; }
.world-label.water { color: #167d96; }
.world-label.delta {
color: #b64e37;
background: #fff5dd;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #b9e5ed;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
transition: opacity .35s ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 700px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 84px);
padding: 14px;
}
.subtitle { display: none; }
.metrics { margin-top: 11px; gap: 4px; }
.metric { padding: 7px 5px; }
.metric strong { font-size: 12px; }
.compass { top: 13px; right: 12px; }
.help { display: none; }
.buttons { right: 12px; bottom: 12px; }
.world-label { font-size: 8px; }
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<section class="brand">
<div class="eyebrow">Natal · Rio Grande do Norte</div>
<h1>Ponta Negra</h1>
<p class="subtitle">
Voxel study of the promenade-to-beach stair fragment, with a separate
access path kept clear of the Atlantic waterline.
</p>
<div class="metrics">
<div class="metric"><span>Promenade</span><strong>+6.0 m</strong></div>
<div class="metric"><span>Path</span><strong>+2.0 m</strong></div>
<div class="metric"><span>Waterline</span><strong>0.0 m</strong></div>
<div class="metric drop"><span>Stair drop</span><strong>−4.0 m</strong></div>
</div>
</section>
<div class="compass"><b>N</b></div>
<div id="label-prom" class="world-label">Promenade · +6.0 m</div>
<div id="label-path" class="world-label path">Access path · +2.0 m</div>
<div id="label-water" class="world-label water">Waterline · 0.0 m</div>
<div id="label-delta" class="world-label delta">Elevation difference · 4.0 m</div>
<div class="help">Drag to orbit · Wheel/pinch to zoom · WASD to pan · R to reset</div>
<div class="buttons">
<button id="access-view" type="button">Stair view</button>
<button id="reset-view" type="button">Reset</button>
</div>
</div>
<div id="loading" class="loading">Building Ponta Negra…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b9e5ed");
scene.fog = new THREE.Fog("#b9e5ed", 52, 125);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
app.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight("#dff8ff", "#a77745", 2.15);
scene.add(hemi);
const sunLight = new THREE.DirectionalLight("#fff2cf", 3.15);
sunLight.position.set(-28, 48, 24);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -58;
sunLight.shadow.camera.right = 58;
sunLight.shadow.camera.top = 55;
sunLight.shadow.camera.bottom = -55;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 125;
sunLight.shadow.bias = -0.0005;
scene.add(sunLight);
const materialCache = new Map();
function material(color) {
if (color?.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function addBox(w, h, d, color, x, y, z, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, thickness, color, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(thickness, thickness, length),
material(color)
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const palette = {
sand: ["#e8c57e", "#efc98b", "#deb16e", "#f1d298", "#dbaa67"],
water: ["#197f9f", "#218da9", "#2b9caf", "#3ca7b4", "#176f8e"],
basalt: ["#303a3c", "#394346", "#283235"],
promenade: ["#e9dfc7", "#e4d6ba", "#eee4cf", "#dfd1b3"],
coral: "#e86f51",
cream: "#fff3d8",
green: ["#3f7750", "#4c8757", "#5b9562"]
};
// ------------------------------------------------------------------
// Ocean: a solid base plus hundreds of small, square wave tiles.
// ------------------------------------------------------------------
addBox(86, 0.8, 44, "#116f8b", 0, -0.65, -18, scene, false);
const waterRows = [];
const waterColumns = 43;
for (let z = -38; z <= 2; z += 2) {
waterRows.push(z);
}
const waterCount = waterRows.length * waterColumns;
const waterTiles = new THREE.InstancedMesh(
new THREE.BoxGeometry(2, 0.55, 2),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.42,
metalness: 0.06
}),
waterCount
);
waterTiles.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
waterTiles.receiveShadow = true;
const dummy = new THREE.Object3D();
let waterIndex = 0;
for (const z of waterRows) {
for (let x = -42; x <= 42; x += 2) {
const wave =
Math.sin(x * 0.19 + z * 0.31) * 0.55 +
Math.cos(x * 0.11 - z * 0.17) * 0.35;
const level = Math.round(wave * 4) / 4 - 0.08;
const top = level + 0.04;
dummy.position.set(x, top - 0.275, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
waterTiles.setMatrixAt(waterIndex, dummy.matrix);
const color = new THREE.Color(
palette.water[
Math.abs(Math.round(wave * 4 + 2)) % palette.water.length
]
);
color.offsetHSL(0, 0, (Math.random() - 0.5) * 0.025);
waterTiles.setColorAt(waterIndex, color);
waterIndex++;
}
}
waterTiles.instanceMatrix.needsUpdate = true;
waterTiles.instanceColor.needsUpdate = true;
scene.add(waterTiles);
// Animated turquoise wave crests.
const crestCount = 55;
const crests = new THREE.InstancedMesh(
new THREE.BoxGeometry(1.35, 0.11, 0.34),
new THREE.MeshStandardMaterial({
color: "#8fd9d5",
roughness: 0.48,
transparent: true,
opacity: 0.72
}),
crestCount
);
crests.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
crests.receiveShadow = true;
const crestData = [];
for (let i = 0; i < crestCount; i++) {
crestData.push({
x: -40 + Math.random() * 80,
z: -34 + Math.random() * 31,
y: -0.02 + Math.random() * 0.12,
phase: Math.random() * Math.PI * 2,
length: 0.55 + Math.random() * 1.2
});
}
scene.add(crests);
// ------------------------------------------------------------------
// Sloping voxel beach. The upper promenade is at +6 m; sea level is 0.
// ------------------------------------------------------------------
const beachColumns = 43;
const beachRows = [];
for (let z = 4; z < 32; z += 1.5) beachRows.push(z);
const beachCount = beachColumns * beachRows.length;
const beach = new THREE.InstancedMesh(
new THREE.BoxGeometry(2, 1, 1.5),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
}),
beachCount
);
beach.receiveShadow = true;
function normalBeachHeight(x, z) {
const raw = THREE.MathUtils.clamp((z - 4) / 28, 0, 1) * 6;
return Math.round(raw / 0.25) * 0.25;
}
function stairTopAt(z) {
const step = THREE.MathUtils.clamp(
Math.floor(Math.max(0, 32 - z) / 0.95) + 1,
1,
20
);
return 6 - step * 0.2;
}
let beachIndex = 0;
for (const z of beachRows) {
for (let x = -42; x <= 42; x += 2) {
let top = normalBeachHeight(x, z + 0.75);
// Cut a stair-shaped channel through the sand.
if (Math.abs(x) < 3.2 && z < 32 && z > 12) {
top = Math.min(top, stairTopAt(z + 0.75) - 0.38);
}
const bottom = -1.2;
dummy.position.set(x, (top + bottom) * 0.5, z + 0.75);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, top - bottom, 1);
dummy.updateMatrix();
beach.setMatrixAt(beachIndex, dummy.matrix);
const color = new THREE.Color(
palette.sand[Math.floor(Math.random() * palette.sand.length)]
);
color.offsetHSL(0, 0, (Math.random() - 0.5) * 0.035);
beach.setColorAt(beachIndex, color);
beachIndex++;
}
}
beach.instanceMatrix.needsUpdate = true;
beach.instanceColor.needsUpdate = true;
scene.add(beach);
// Shoreline foam, visibly separated from the inland access path.
const foamCount = 66;
const foam = new THREE.InstancedMesh(
new THREE.BoxGeometry(1.15, 0.14, 0.5),
new THREE.MeshStandardMaterial({
color: "#fff8df",
roughness: 0.75
}),
foamCount
);
foam.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(foam);
// ------------------------------------------------------------------
// Promenade deck, basalt retaining wall, paving and railing.
// ------------------------------------------------------------------
addBox(84, 1.0, 8.2, "#c9b58f", 0, 5.40, 36.1, scene, false);
for (let x = -42; x <= 42; x += 2) {
for (let z = 32; z < 42; z += 2) {
const color =
Math.abs(x) < 4 && z === 32
? "#d4c5a5"
: palette.promenade[
Math.floor(Math.random() * palette.promenade.length)
];
addBox(1.96, 0.1, 1.96, color, x, 5.95, z, scene, false);
}
}
// A restrained basalt wave-mosaic strip along the promenade edge.
for (let x = -40; x <= 40; x += 2) {
const waveIndex = Math.floor((x + 40) / 2);
if (waveIndex % 6 < 3) {
addBox(1.4, 0.11, 0.36, "#334146", x, 6.04, 32.28, scene, false);
}
}
function buildRetainingWall(startX, endX) {
for (let x = startX; x < endX; x += 2.4) {
for (let row = 0; row < 4; row++) {
const color =
palette.basalt[(row + Math.round(x / 2.4)) % palette.basalt.length];
addBox(
2.32,
1.34,
0.95,
color,
x + 1.18,
0.67 + row * 1.38,
31.75
);
}
}
}
buildRetainingWall(-42, -3.2);
buildRetainingWall(3.2, 42);
function promenadeRail(startX, endX) {
const railY = 7.02;
beamBetween(
new THREE.Vector3(startX, railY, 32.15),
new THREE.Vector3(endX, railY, 32.15),
0.12,
"#26383b"
);
for (let x = startX; x <= endX; x += 3) {
addBox(0.14, 1.1, 0.14, "#26383b", x, 6.52, 32.15);
}
}
promenadeRail(-40, -3);
promenadeRail(3, 40);
// ------------------------------------------------------------------
// Main stair fragment: 20 square treads descending 4 m.
// ------------------------------------------------------------------
const stairWidth = 5.2;
const stairRun = 0.95;
const stairSteps = 20;
// Upper landing aligns with the promenade.
addBox(stairWidth, 0.55, 0.78, "#d3c29f", 0, 5.72, 32.38);
for (let i = 0; i < stairSteps; i++) {
const top = 6 - (i + 1) * 0.2;
const z = 32 - (i + 0.5) * stairRun;
const color = i % 2 === 0 ? "#d8c49d" : "#cdb88e";
addBox(stairWidth, top + 0.62, stairRun, color, 0, (top - 0.62) * 0.5, z);
// Bright block nosing makes the riser/tread rhythm legible.
addBox(
stairWidth,
0.075,
0.11,
i % 5 === 0 ? "#e9a16e" : "#f2e3bd",
0,
top + 0.04,
z + stairRun * 0.5 - 0.06,
scene,
false
);
}
// Dark side cheek blocks.
for (const side of [-1, 1]) {
for (let i = 0; i < stairSteps; i++) {
const top = 6 - (i + 1) * 0.2;
const z = 32 - (i + 0.5) * stairRun;
addBox(
0.28,
top + 0.38,
stairRun,
i % 3 === 0 ? "#3a4140" : "#30393a",
side * 2.72,
(top - 0.38) * 0.5,
z
);
}
}
// Square-section handrails and vertical posts.
for (const side of [-1, 1]) {
const x = side * 2.72;
beamBetween(
new THREE.Vector3(x, 7.02, 32.0),
new THREE.Vector3(x, 3.02, 13.0),
0.13,
"#253638"
);
beamBetween(
new THREE.Vector3(x, 6.50, 32.0),
new THREE.Vector3(x, 2.50, 13.0),
0.09,
"#314143"
);
for (let s = 0; s <= 20; s += 2) {
const z = 32 - s * stairRun;
const y = 6 - s * 0.2;
addBox(0.14, 1.12, 0.14, "#253638", x, y + 0.56, z);
}
}
// ------------------------------------------------------------------
// Dedicated inland access path. It stays at least ~6 m from the sea.
// ------------------------------------------------------------------
const pathPoints = [
{ x: 0.0, z: 13.05, h: 2.00 },
{ x: 1.45, z: 11.75, h: 1.70 },
{ x: 3.05, z: 10.65, h: 1.45 },
{ x: 4.80, z: 10.45, h: 1.45 },
{ x: 6.25, z: 11.15, h: 1.70 },
{ x: 7.55, z: 12.75, h: 2.00 }
];
let pathPaverIndex = 0;
for (let i = 0; i < pathPoints.length - 1; i++) {
const a = pathPoints[i];
const b = pathPoints[i + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const distance = Math.hypot(dx, dz);
const count = Math.ceil(distance / 0.72);
const yaw = Math.atan2(dx, dz);
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
const h = THREE.MathUtils.lerp(a.h, b.h, t);
const paver = addBox(
1.72,
0.16,
0.67,
pathPaverIndex % 3 === 0 ? "#fff0ce" : "#dd7959",
x,
h + 0.08,
z,
scene,
false
);
paver.rotation.y = yaw;
pathPaverIndex++;
}
}
// Small path markers help distinguish it from the open shoreline.
const markerPositions = [
[-0.9, 13.25, 2.0],
[3.9, 9.95, 1.45],
[7.75, 12.4, 2.0]
];
for (const [x, z, h] of markerPositions) {
addBox(0.18, 1.05, 0.18, "#364446", x, h + 0.52, z);
addBox(0.34, 0.22, 0.34, "#e86f51", x, h + 1.05, z);
}
// ------------------------------------------------------------------
// Elevation bracket beside the stair.
// ------------------------------------------------------------------
const bracketX = 4.55;
const bracketZ = 29.8;
beamBetween(
new THREE.Vector3(bracketX, 2.0, bracketZ),
new THREE.Vector3(bracketX, 6.0, bracketZ),
0.08,
"#b65740"
);
for (const y of [2, 6]) {
beamBetween(
new THREE.Vector3(bracketX - 0.65, y, bracketZ),
new THREE.Vector3(bracketX + 0.65, y, bracketZ),
0.11,
"#b65740"
);
}
// ------------------------------------------------------------------
// Beach and promenade context: palms, guard cabin, umbrellas, lamps.
// ------------------------------------------------------------------
function palmTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 6, z);
group.scale.setScalar(scale);
scene.add(group);
let trunkY = 0;
let offset = 0;
for (let i = 0; i < 7; i++) {
const h = 1.05;
offset = i < 4 ? offset + 0.06 : offset - 0.05;
addBox(
0.42,
h,
0.42,
i % 2 ? "#9f7248" : "#b88652",
offset,
trunkY + h * 0.5,
0,
group
);
trunkY += h * 0.96;
}
const crown = new THREE.Group();
crown.position.set(offset, trunkY, 0);
group.add(crown);
for (let i = 0; i < 7; i++) {
const pivot = new THREE.Group();
pivot.rotation.y = (i / 7) * Math.PI * 2;
crown.add(pivot);
const frond = addBox(
0.52,
0.23,
3.8,
palette.green[i % palette.green.length],
0,
0,
1.75,
pivot
);
frond.rotation.x = 0.28;
}
addBox(0.58, 0.48, 0.58, "#8f653d", 0.22, -0.12, 0.05, crown);
addBox(0.5, 0.46, 0.5, "#a07848", -0.2, -0.08, -0.12, crown);
}
palmTree(-34, 38, 1.05);
palmTree(-22, 38, 0.9);
palmTree(-11, 39, 1.0);
palmTree(13, 39, 0.95);
palmTree(25, 38, 1.08);
palmTree(36, 39, 0.9);
function promenadeLamp(x, z) {
addBox(0.18, 3.6, 0.18, "#344345", x, 7.8, z);
addBox(0.62, 0.28, 0.62, "#344345", x, 9.67, z);
const glow = new THREE.MeshStandardMaterial({
color: "#ffe3a0",
emissive: "#ffbf55",
emissiveIntensity: 1.2,
roughness: 0.5
});
addBox(0.42, 0.45, 0.42, glow, x, 9.92, z);
}
[-27, -16, -7, 8, 18, 29, 39].forEach((x) =>
promenadeLamp(x, 35.6)
);
// Colorful, block-built lifeguard station.
const guardX = -16;
const guardZ = 13;
const guardBase = normalBeachHeight(guardX, guardZ);
for (const dx of [-1.05, 1.05]) {
for (const dz of [-0.9, 0.9]) {
addBox(
0.22,
2.8,
0.22,
"#efe3c4",
guardX + dx,
guardBase + 1.4,
guardZ + dz
);
}
}
addBox(3.2, 1.55, 2.45, "#f3e7ca", guardX, guardBase + 3.4, guardZ);
addBox(3.55, 0.28, 2.8, "#e86f51", guardX, guardBase + 4.3, guardZ);
addBox(
2.1,
0.7,
0.08,
"#317f91",
guardX,
guardBase + 3.55,
guardZ + 1.27,
scene,
false
);
function umbrella(x, z, color) {
const h = normalBeachHeight(x, z);
addBox(0.12, 3.0, 0.12, "#6a5843", x, h + 1.5, z);
addBox(3.2, 0.18, 1.25, color, x, h + 3.0, z - 0.42);
addBox(2.55, 0.19, 1.15, "#fff0ce", x, h + 3.18, z);
addBox(1.65, 0.2, 1.05, color, x, h + 3.36, z + 0.1);
addBox(0.7, 0.2, 0.9, "#fff0ce", x, h + 3.53, z + 0.1);
}
umbrella(-22, 18, "#e86f51");
umbrella(19, 19, "#e4b64f");
umbrella(25, 24, "#e86f51");
// A few simple beach loungers.
for (const [x, z] of [[-24, 16], [17, 17], [23, 22]]) {
const h = normalBeachHeight(x, z);
addBox(0.85, 0.18, 1.9, "#f7e9ca", x, h + 0.38, z);
const back = addBox(
0.85,
0.18,
0.95,
"#f7e9ca",
x,
h + 0.72,
z - 0.72
);
back.rotation.x = -0.55;
addBox(0.12, 0.45, 0.12, "#566465", x - 0.3, h + 0.18, z + 0.6);
addBox(0.12, 0.45, 0.12, "#566465", x + 0.3, h + 0.18, z + 0.6);
}
// Sparse dune blocks near the ends of the beach.
for (const side of [-1, 1]) {
for (let i = 0; i < 11; i++) {
const x = side * (27 + Math.random() * 13);
const z = 24 + Math.random() * 6;
const h = normalBeachHeight(x, z);
addBox(
0.6 + Math.random(),
0.5 + Math.random() * 0.6,
0.6 + Math.random(),
palette.green[i % palette.green.length],
x,
h + 0.3,
z,
scene,
false
);
}
}
// ------------------------------------------------------------------
// Voxel clouds and a square sun.
// ------------------------------------------------------------------
const cloudMaterial = new THREE.MeshBasicMaterial({
color: "#f8fcf7",
transparent: true,
opacity: 0.78,
depthWrite: false
});
function cloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
const blocks = [
[-1.6, 0, 0, 2.3, 0.8, 1.2],
[0, 0.25, 0, 2.8, 1.05, 1.5],
[1.8, 0, 0.1, 2.1, 0.75, 1.1],
[-0.5, 0.75, 0, 2.1, 0.75, 1.1]
];
for (const [bx, by, bz, w, h, d] of blocks) {
addBox(w, h, d, cloudMaterial, bx, by, bz, group, false);
}
}
cloud(-24, 21, -17, 1.4);
cloud(17, 25, -26, 1.1);
cloud(38, 19, -11, 0.9);
const sunBlock = new THREE.Mesh(
new THREE.BoxGeometry(5.5, 5.5, 1.4),
new THREE.MeshBasicMaterial({ color: "#ffe9a7", fog: false })
);
sunBlock.position.set(-38, 32, -51);
scene.add(sunBlock);
// ------------------------------------------------------------------
// Camera controls implemented directly, without external add-ons.
// ------------------------------------------------------------------
const view = {
target: new THREE.Vector3(0, 2.5, 20),
radius: 42,
theta: 0.34,
phi: 1.06
};
const homeView = {
target: new THREE.Vector3(0, 2.5, 20),
radius: 42,
theta: 0.34,
phi: 1.06
};
function applyCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
function resetView() {
view.target.copy(homeView.target);
view.radius = homeView.radius;
view.theta = homeView.theta;
view.phi = homeView.phi;
applyCamera();
}
document.getElementById("reset-view").addEventListener("click", resetView);
document.getElementById("access-view").addEventListener("click", () => {
view.target.set(1.2, 3.0, 21.5);
view.radius = 29;
view.theta = 0.19;
view.phi = 1.08;
applyCamera();
});
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.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 === 1) {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.005,
0.12,
Math.PI * 0.485
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
view.radius = THREE.MathUtils.clamp(
view.radius * (previousPinchDistance / distance),
14,
76
);
}
previousPinchDistance = distance;
}
applyCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
14,
76
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const keys = new Set();
addEventListener("keydown", (event) => {
keys.add(event.key.toLowerCase());
if (event.key.toLowerCase() === "r") resetView();
if (["w", "a", "s", "d", "arrowleft", "arrowright", "arrowup", "arrowdown"].includes(
event.key.toLowerCase()
)) {
event.preventDefault();
}
});
addEventListener("keyup", (event) => {
keys.delete(event.key.toLowerCase());
});
function updateKeyboardCamera(dt) {
const forward = new THREE.Vector3()
.subVectors(view.target, camera.position)
.setY(0)
.normalize();
const right = new THREE.Vector3().crossVectors(forward, new THREE.Vector3(0, 1, 0));
const movement = new THREE.Vector3();
const speed = dt * 12;
if (keys.has("w") || keys.has("arrowup")) movement.add(forward);
if (keys.has("s") || keys.has("arrowdown")) movement.sub(forward);
if (keys.has("d") || keys.has("arrowright")) movement.add(right);
if (keys.has("a") || keys.has("arrowleft")) movement.sub(right);
if (keys.has("arrowleft")) view.theta += dt * 0.75;
if (keys.has("arrowright")) view.theta -= dt * 0.75;
if (movement.lengthSq() > 0) {
view.target.add(movement.normalize().multiplyScalar(speed));
view.target.x = THREE.MathUtils.clamp(view.target.x, -30, 30);
view.target.z = THREE.MathUtils.clamp(view.target.z, -15, 38);
}
if (movement.lengthSq() > 0) applyCamera();
}
// ------------------------------------------------------------------
// Screen-space labels projected from world anchors.
// ------------------------------------------------------------------
const labelData = [
{
element: document.getElementById("label-prom"),
position: new THREE.Vector3(-8.5, 7.7, 34)
},
{
element: document.getElementById("label-path"),
position: new THREE.Vector3(6.7, 3.2, 11.9)
},
{
element: document.getElementById("label-water"),
position: new THREE.Vector3(18, 0.9, 3.9)
},
{
element: document.getElementById("label-delta"),
position: new THREE.Vector3(6.1, 4.1, 29.8)
}
];
function updateLabels() {
for (const item of labelData) {
const projected = item.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
item.element.style.display = visible ? "block" : "none";
if (visible) {
item.element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
item.element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
}
// ------------------------------------------------------------------
// Animation.
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const dt = Math.min(clock.getDelta(), 0.05);
updateKeyboardCamera(dt);
// Foam breaks along the shoreline.
for (let i = 0; i < foamCount; i++) {
const x = -41 + i * 1.26;
const pulse = Math.sin(elapsed * 1.25 + i * 0.61);
dummy.position.set(
x + Math.sin(i * 0.8) * 0.16,
0.13 + pulse * 0.025,
3.9 + pulse * 0.22
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(
0.82 + 0.22 * (0.5 + 0.5 * Math.sin(i * 0.33)),
1,
1
);
dummy.updateMatrix();
foam.setMatrixAt(i, dummy.matrix);
}
foam.instanceMatrix.needsUpdate = true;
// Offshore voxel wave crests.
for (let i = 0; i < crestCount; i++) {
const wave = crestData[i];
const pulse = Math.sin(elapsed * 1.1 + wave.phase);
dummy.position.set(
wave.x,
wave.y + pulse * 0.055,
wave.z + pulse * 0.08
);
dummy.rotation.set(0, wave.phase * 0.2, 0);
dummy.scale.set(wave.length, 0.8 + pulse * 0.18, 1);
dummy.updateMatrix();
crests.setMatrixAt(i, dummy.matrix);
}
crests.instanceMatrix.needsUpdate = true;
updateLabels();
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
});
applyCamera();
renderer.setAnimationLoop(animate);
loading.classList.add("hidden");
</script>
</body>
</html>
```