Prompt specification
Build or customize the Three.js 3D scene "Pedestrian approaching a San Juan city gate" 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: Pedestrian approaching a San Juan city gate
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pedestrian-approaching-a-san-juan-city-gate-x2786
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing the walls and gates of Old San Juan. Create a compact referenced gate vignette with wall, sloping path, and coastal glimpse. Keep the path continuous through the opening and distinguish defensive structure from current public use. Voxel style.
Working Three.js Starter (pedestrian-approaching-a-san-juan-city-gate-x2786):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Old San Juan — Walls & Gates</title>
<style>
:root {
--ink: #183b3b;
--paper: rgba(248, 243, 226, 0.94);
--stone: #806f57;
--public: #d6c9aa;
--accent: #bc6845;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#stage canvas {
touch-action: none;
cursor: grab;
}
#stage canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
width: min(460px, calc(100vw - 48px));
padding: 18px 20px 17px;
background: var(--paper);
border: 1px solid rgba(24, 59, 59, 0.18);
border-left: 5px solid var(--accent);
box-shadow: 0 12px 38px rgba(31, 48, 44, 0.13);
backdrop-filter: blur(8px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.5vw, 40px);
line-height: 0.98;
letter-spacing: -0.045em;
text-transform: uppercase;
}
.subtitle {
margin: 9px 0 0;
color: #506866;
font-size: 13px;
line-height: 1.45;
}
.reference {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid rgba(24, 59, 59, 0.13);
color: #61716d;
font-size: 10px;
line-height: 1.45;
}
.legend {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 5;
width: min(390px, calc(100vw - 48px));
padding: 15px 17px;
background: var(--paper);
border: 1px solid rgba(24, 59, 59, 0.18);
box-shadow: 0 12px 38px rgba(31, 48, 44, 0.13);
backdrop-filter: blur(8px);
}
.legend h2 {
margin: 0 0 10px;
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 18px 1fr;
gap: 9px;
align-items: start;
margin-top: 8px;
font-size: 11px;
line-height: 1.4;
color: #425d59;
}
.swatch {
width: 16px;
height: 16px;
margin-top: 1px;
border: 1px solid rgba(24, 59, 59, 0.15);
}
.swatch.defense {
background:
linear-gradient(135deg, transparent 44%, #675a49 45% 55%, transparent 56%),
#b89c69;
}
.swatch.public {
background:
linear-gradient(90deg, #eee4cd 0 62%, #a99b82 63% 100%);
}
.legend-row strong {
color: var(--ink);
}
.controls {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
display: flex;
align-items: center;
gap: 10px;
}
.hint {
padding: 9px 12px;
background: rgba(248, 243, 226, 0.86);
border: 1px solid rgba(24, 59, 59, 0.14);
color: #48625f;
font-size: 10px;
letter-spacing: 0.03em;
box-shadow: 0 8px 24px rgba(31, 48, 44, 0.09);
}
button {
border: 1px solid rgba(24, 59, 59, 0.24);
background: var(--ink);
color: #f7f0dc;
padding: 10px 13px;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 8px 24px rgba(31, 48, 44, 0.14);
}
button:hover {
background: #285451;
}
button:focus-visible {
outline: 3px solid rgba(188, 104, 69, 0.5);
outline-offset: 2px;
}
.scene-label {
position: fixed;
z-index: 4;
pointer-events: none;
transform: translate(-50%, -100%);
white-space: nowrap;
padding: 7px 9px;
background: rgba(24, 59, 59, 0.91);
color: #fff5dc;
border: 1px solid rgba(255, 245, 220, 0.26);
box-shadow: 0 6px 20px rgba(20, 36, 34, 0.16);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 20px;
background: rgba(24, 59, 59, 0.65);
}
.scene-label.public {
background: rgba(244, 235, 210, 0.95);
color: var(--ink);
border-color: rgba(24, 59, 59, 0.25);
}
.scene-label.public::after {
background: rgba(24, 59, 59, 0.45);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dce8e4;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 0.35s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.subtitle {
display: none;
}
.reference {
margin-top: 8px;
}
.legend {
left: 12px;
bottom: 62px;
width: calc(100vw - 24px);
padding: 11px 13px;
}
.legend-row {
margin-top: 5px;
}
.controls {
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
.scene-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive voxel model of Old San Juan walls and a public gate"></div>
<header class="title-card">
<div class="eyebrow">Puerto Rico · Interpretive Voxel Vignette</div>
<h1>Old San Juan<br>Walls & Gates</h1>
<p class="subtitle">
A heavy defensive portal now forms part of an open, everyday pedestrian route.
</p>
<div class="reference">
Reference concept: Puerta de San Juan and the adjoining Old San Juan
wall circuit. This compact model is simplified and is not a surveyed reconstruction.
</div>
</header>
<aside class="legend" aria-label="Interpretive legend">
<h2>Read the gate</h2>
<div class="legend-row">
<span class="swatch defense"></span>
<span><strong>Defensive structure:</strong> thick masonry, elevated lookout,
crenellations and a deeply recessed portal.</span>
</div>
<div class="legend-row">
<span class="swatch public"></span>
<span><strong>Current public use:</strong> an uninterrupted paved through-route,
modern lighting, wayfinding and visitors.</span>
</div>
</aside>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<button id="reset" type="button">Reset view</button>
</div>
<div id="defense-label" class="scene-label">Defensive fabric</div>
<div id="public-label" class="scene-label public">Public walkway</div>
<div id="loading">Building the gate vignette…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
// -------------------------------------------------------------------------
// Renderer, scene and camera
// -------------------------------------------------------------------------
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e4);
scene.fog = new THREE.Fog(0xdce8e4, 28, 88);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
180
);
const target = new THREE.Vector3(0, 2.15, -1.4);
const spherical = {
theta: 0.36,
phi: 1.14,
radius: 22
};
const initialView = { ...spherical };
function updateCamera() {
const sinPhi = Math.sin(spherical.phi);
camera.position.set(
target.x + spherical.radius * sinPhi * Math.sin(spherical.theta),
target.y + spherical.radius * Math.cos(spherical.phi),
target.z + spherical.radius * sinPhi * Math.cos(spherical.theta)
);
camera.lookAt(target);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf5f3df, 0x68796f, 2.05));
const sun = new THREE.DirectionalLight(0xfff0cb, 3.25);
sun.position.set(-10, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const coastalFill = new THREE.DirectionalLight(0xaed9df, 1.05);
coastalFill.position.set(12, 8, -18);
scene.add(coastalFill);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.91,
metalness: 0
})
);
}
return materialCache.get(color);
}
function addBox(
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const mesh = new THREE.Mesh(cubeGeometry, getMaterial(color));
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
scene.add(mesh);
return mesh;
}
function makeInstances(entries, options = {}) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
metalness: 0
});
const mesh = new THREE.InstancedMesh(geometry, material, entries.length);
const dummy = new THREE.Object3D();
entries.forEach((entry, index) => {
dummy.position.set(entry.p[0], entry.p[1], entry.p[2]);
dummy.scale.set(entry.s[0], entry.s[1], entry.s[2]);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(entry.c));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Land, paving and sea
// -------------------------------------------------------------------------
// Warm city-side promenade platform.
addBox(
25,
0.8,
15,
0,
-0.4,
6.5,
0xc6b692,
{ castShadow: false }
);
// Lower coastal ground behind the wall.
addBox(
50,
1.6,
13,
0,
-2.25,
-7.5,
0x78836e,
{ castShadow: false }
);
// Ocean.
addBox(
100,
0.2,
42,
0,
-1.56,
-35,
0x4f9eac,
{ castShadow: false }
);
// A slightly lighter offshore band gives the sea depth in voxel steps.
addBox(
100,
0.08,
10,
0,
-1.43,
-30,
0x5baeb7,
{ castShadow: false }
);
// Side paving slabs distinguish the contemporary public realm from the wall.
const plazaEntries = [];
const plazaColors = [0xd5c9ad, 0xcabd9f, 0xdbcfb4];
for (const z of [1.4, 4.4, 7.4, 10.4]) {
for (const x of [-8.8, -5.4, -2.2, 2.2, 5.4, 8.8]) {
if (Math.abs(x) < 1.8) continue;
plazaEntries.push({
p: [x, 0.035, z],
s: [2.75, 0.07, 2.65],
c: plazaColors[Math.floor(Math.abs(x + z)) % plazaColors.length]
});
}
}
makeInstances(plazaEntries, { castShadow: false });
// -------------------------------------------------------------------------
// The continuous public path
// -------------------------------------------------------------------------
function pathTop(z) {
if (z >= 0) {
return 0.06 + 0.24 * (1 - Math.min(z, 13) / 13);
}
return 0.30 + (-1.05 - 0.30) * (Math.min(-z, 13) / 13);
}
const pathBaseEntries = [];
const pathSurfaceEntries = [];
const segmentLength = 0.5;
const segmentCount = 54;
for (let i = 0; i < segmentCount; i++) {
const z = 13.25 - (i + 0.5) * segmentLength;
const top = pathTop(z) - 0.045;
const bottom = z > -1.05 ? 0.01 : -1.45;
const height = Math.max(0.15, top - bottom);
pathBaseEntries.push({
p: [0, (top + bottom) * 0.5, z],
s: [2.72, height, segmentLength + 0.012],
c: 0xa4967b
});
pathSurfaceEntries.push({
p: [0, pathTop(z) - 0.022, z],
s: [1.58, 0.055, segmentLength + 0.015],
c: i % 4 === 0 ? 0xe0d6bf : 0xd8cdb4
});
}
makeInstances(pathBaseEntries);
makeInstances(pathSurfaceEntries, { castShadow: false });
// Small coastal overlook at the end of the descending ramp.
addBox(4.2, 0.22, 2.1, 0, -1.16, -12.55, 0xd5c8aa);
// Low retaining blocks beneath the ramp.
for (let i = 0; i < 15; i++) {
const z = -2.2 - i * 0.72;
const top = pathTop(z) - 0.08;
addBox(
0.28,
top + 1.45,
0.68,
-1.48,
(top - 1.45) * 0.5,
z,
i % 2 ? 0x8f8169 : 0x9b8d73
);
addBox(
0.28,
top + 1.45,
0.68,
1.48,
(top - 1.45) * 0.5,
z,
i % 2 ? 0x8f8169 : 0x9b8d73
);
}
// -------------------------------------------------------------------------
// Defensive wall, gate and lookout tower
// -------------------------------------------------------------------------
const wallEntries = [];
const lowerPalette = [0x8e826d, 0x9a8d74, 0x857964, 0xa09278];
const upperPalette = [0xc1a875, 0xcbb184, 0xbba06e, 0xd0b787];
function insideOpening(x, y) {
if (y < 3.04) {
return Math.abs(x) < 1.55;
}
const dy = y - 3.04;
const radius = 1.58;
return dy < radius && x * x + dy * dy < radius * radius;
}
for (let row = 0; row < 10; row++) {
const y = 0.31 + row * 0.62;
for (let column = 0; column < 22; column++) {
const x = -10.5 + column;
if (insideOpening(x, y)) continue;
const palette = row < 4 ? lowerPalette : upperPalette;
const color = palette[(row * 3 + column * 5) % palette.length];
wallEntries.push({
p: [x, y, -0.05],
s: [0.965, 0.585, 1.6],
c: color
});
}
}
makeInstances(wallEntries);
// Continuous parapet cap.
for (let column = 0; column < 22; column++) {
addBox(
0.97,
0.31,
1.72,
-10.5 + column,
6.28,
-0.05,
column % 3 === 0 ? 0xc3aa78 : 0xbba171
);
}
// Crenellations make the defensive function immediately legible.
for (let x = -5.3; x <= 10.3; x += 1.8) {
addBox(0.84, 0.72, 1.65, x, 6.76, -0.05, 0xc4aa76);
}
// Voxel arch surround: stepped, block-built rather than smooth.
for (let i = 0; i <= 12; i++) {
const angle = (i / 12) * Math.PI;
const x = 1.68 * Math.cos(angle);
const y = 3.04 + 1.68 * Math.sin(angle);
addBox(0.36, 0.36, 0.28, x, y, 0.82, 0x736854);
}
// Heavy side jambs.
addBox(0.28, 3.06, 1.72, -1.64, 1.53, -0.02, 0x776a55);
addBox(0.28, 3.06, 1.72, 1.64, 1.53, -0.02, 0x776a55);
// A narrow defensive embrasure on the right.
addBox(0.24, 1.02, 0.1, 6.25, 4.46, 0.81, 0x272b28, {
castShadow: false
});
addBox(0.58, 0.15, 0.18, 6.25, 5.02, 0.86, 0x7d705a);
// -------------------------------------------------------------------------
// Square lookout tower
// -------------------------------------------------------------------------
const towerEntries = [];
for (let row = 0; row < 14; row++) {
const y = 0.29 + row * 0.58;
for (let column = 0; column < 4; column++) {
const x = -9.72 + column * 0.9;
const palette = row < 5
? lowerPalette
: upperPalette;
towerEntries.push({
p: [x, y, -0.25],
s: [0.865, 0.555, 2.5],
c: palette[(row + column * 2) % palette.length]
});
}
}
makeInstances(towerEntries);
// Tower cap and merlons.
for (let column = 0; column < 4; column++) {
const x = -9.72 + column * 0.9;
addBox(0.88, 0.36, 2.62, x, 8.28, -0.25, 0xc2a775);
}
for (const x of [-9.72, -8.82, -7.92, -7.02]) {
addBox(0.78, 0.68, 0.76, x, 8.79, 0.79, 0xc7ac78);
addBox(0.78, 0.68, 0.76, x, 8.79, -1.29, 0xb99f70);
}
// Tower observation slit.
addBox(0.3, 1.22, 0.1, -8.32, 6.42, 1.07, 0x252925, {
castShadow: false
});
addBox(0.62, 0.15, 0.17, -8.32, 7.08, 1.1, 0x7b6e58);
// -------------------------------------------------------------------------
// Current public use: lighting, bollards, sign and people
// -------------------------------------------------------------------------
function addLamp(x, z, baseY) {
addBox(0.16, 0.14, 0.16, x, baseY + 0.07, z, 0x273b39);
addBox(0.09, 3.0, 0.09, x, baseY + 1.55, z, 0x273b39);
addBox(0.58, 0.08, 0.08, x + 0.22, baseY + 3.04, z, 0x273b39);
addBox(0.28, 0.18, 0.28, x + 0.45, baseY + 2.91, z, 0xf5df9a);
}
addLamp(-3.25, 4.0, 0.04);
addLamp(3.35, 6.0, 0.04);
addLamp(-3.2, -4.2, -1.42);
for (const z of [7.1, 9.5, 11.8]) {
addBox(0.17, 0.66, 0.17, -1.78, 0.33, z, 0x304643);
addBox(0.17, 0.66, 0.17, 1.78, 0.33, z, 0x304643);
}
function makeSignTexture() {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 320;
const context = canvas.getContext("2d");
context.fillStyle = "#173b3b";
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#bc6845";
context.fillRect(0, 0, canvas.width, 18);
context.textAlign = "center";
context.fillStyle = "#fff2ce";
context.font = "800 49px Arial, sans-serif";
context.fillText("PUBLIC WALKWAY", 320, 104);
context.fillStyle = "#c9d9cd";
context.font = "700 27px Arial, sans-serif";
context.fillText("PASEO PÚBLICO · WALLS TRAIL", 320, 154);
// Block-arrow symbol, matching the voxel visual language.
context.fillStyle = "#f5df9a";
context.fillRect(265, 207, 110, 20);
context.fillRect(350, 190, 20, 20);
context.fillRect(350, 224, 20, 20);
context.fillRect(370, 177, 20, 20);
context.fillRect(370, 237, 20, 20);
context.fillRect(390, 164, 20, 20);
context.fillRect(390, 250, 20, 20);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const signTexture = makeSignTexture();
const signMaterial = new THREE.MeshBasicMaterial({ map: signTexture });
const signFace = new THREE.Mesh(
new THREE.PlaneGeometry(1.9, 0.95),
signMaterial
);
signFace.position.set(3.55, 1.46, 2.48);
scene.add(signFace);
addBox(2.04, 1.06, 0.12, 3.55, 1.46, 2.4, 0x213f3b);
addBox(0.1, 1.55, 0.1, 3.55, 0.74, 2.4, 0x263f3c);
function addPerson(x, z, baseY, shirtColor, pantsColor, skinColor) {
addBox(0.16, 0.56, 0.17, x - 0.13, baseY + 0.28, z, pantsColor);
addBox(0.16, 0.56, 0.17, x + 0.13, baseY + 0.28, z, pantsColor);
addBox(0.5, 0.64, 0.29, x, baseY + 0.87, z, shirtColor);
addBox(0.13, 0.52, 0.14, x - 0.33, baseY + 0.84, z, shirtColor);
addBox(0.13, 0.52, 0.14, x + 0.33, baseY + 0.84, z, shirtColor);
addBox(0.33, 0.34, 0.32, x, baseY + 1.37, z, skinColor);
addBox(0.35, 0.12, 0.34, x, baseY + 1.57, z, 0x3a3730);
}
addPerson(-2.05, 5.25, 0.08, 0xc76845, 0x334a54, 0xb9825f);
addPerson(2.2, 8.2, 0.08, 0xe1c56b, 0x465356, 0x8f6044);
addPerson(-2.15, 1.85, 0.08, 0x5d8f91, 0x7e6450, 0xd0a276);
addPerson(0.92, -3.4, pathTop(-3.4), 0x7f688a, 0x35494b, 0xb87952);
// -------------------------------------------------------------------------
// Coastal glimpse: surf, distant block lighthouse and small sailboat
// -------------------------------------------------------------------------
const foamEntries = [];
for (let i = 0; i < 25; i++) {
const x = -15 + i * 1.25;
foamEntries.push({
p: [x, -1.42, -14.25 - (i % 3) * 0.23],
s: [0.8 + (i % 4) * 0.16, 0.07, 0.22],
c: 0xd9ece6
});
}
makeInstances(foamEntries, { castShadow: false });
// Distant El Morro-inspired lighthouse silhouette, visible through the arch.
const lighthouseX = -12.7;
const lighthouseZ = -23.5;
addBox(3.0, 0.65, 3.0, lighthouseX, -1.1, lighthouseZ, 0x9e9a85, {
castShadow: false
});
const lighthouseColors = [0xd7d0b5, 0xe4ddc2, 0xd7d0b5, 0xe4ddc2];
for (let i = 0; i < 4; i++) {
addBox(
1.42 - i * 0.13,
1.28,
1.42 - i * 0.13,
lighthouseX,
-0.05 + i * 1.22,
lighthouseZ,
lighthouseColors[i],
{ castShadow: false }
);
}
addBox(1.62, 0.2, 1.62, lighthouseX, 4.95, lighthouseZ, 0x6d776e, {
castShadow: false
});
addBox(1.12, 0.72, 1.12, lighthouseX, 5.4, lighthouseZ, 0xe8b65f, {
castShadow: false
});
addBox(1.4, 0.22, 1.4, lighthouseX, 5.87, lighthouseZ, 0x4d5853, {
castShadow: false
});
// Small blocky sailboat.
addBox(2.3, 0.38, 0.85, 8.5, -1.16, -29.5, 0x5d564a, {
castShadow: false
});
addBox(0.12, 2.7, 0.12, 8.5, 0.12, -29.5, 0x685d4b, {
castShadow: false
});
addBox(1.25, 1.8, 0.08, 8.95, 0.44, -29.5, 0xf2e4bd, {
castShadow: false
});
addBox(0.8, 1.2, 0.08, 8.05, 0.05, -29.5, 0xe4d4ab, {
castShadow: false
});
// Sparse coastal rock blocks.
const rockEntries = [
{ p: [-7.6, -1.13, -10.5], s: [2.2, 0.65, 1.8], c: 0x8b8974 },
{ p: [-9.2, -1.25, -12.1], s: [3.0, 0.42, 2.1], c: 0x96917a },
{ p: [7.8, -1.18, -10.2], s: [2.8, 0.55, 2.0], c: 0x85846f },
{ p: [10.0, -1.22, -12.5], s: [3.4, 0.45, 2.3], c: 0x918b73 }
];
makeInstances(rockEntries, { castShadow: false });
// -------------------------------------------------------------------------
// Labels projected from world space
// -------------------------------------------------------------------------
const defenseAnchor = new THREE.Vector3(-8.3, 9.55, 0.6);
const publicAnchor = new THREE.Vector3(3.55, 2.2, 2.45);
const defenseLabel = document.getElementById("defense-label");
const publicLabel = document.getElementById("public-label");
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.05 &&
projected.x < 1.05 &&
projected.y > -1.05 &&
projected.y < 1.05;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// -------------------------------------------------------------------------
// Direct camera controls: no addons or example modules
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
spherical.theta -= deltaX * 0.005;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi + deltaY * 0.004,
0.62,
1.42
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("lostpointercapture", () => {
dragging = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
13,
33
);
updateCamera();
},
{ passive: false }
);
function resetView() {
spherical.theta = initialView.theta;
spherical.phi = initialView.phi;
spherical.radius = initialView.radius;
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") {
spherical.theta += step;
} else if (event.key === "ArrowRight") {
spherical.theta -= step;
} else if (event.key === "ArrowUp") {
spherical.phi = Math.max(0.62, spherical.phi - step);
} else if (event.key === "ArrowDown") {
spherical.phi = Math.min(1.42, spherical.phi + step);
} else if (event.key === "+" || event.key === "=") {
spherical.radius = Math.max(13, spherical.radius - 1);
} else if (event.key === "-" || event.key === "_") {
spherical.radius = Math.min(33, spherical.radius + 1);
} else if (event.key.toLowerCase() === "r") {
resetView();
} else {
return;
}
updateCamera();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Very subtle motion in the offshore band keeps the scene alive.
const offshoreBand = scene.children.find(
(object) => object.geometry &&
object.geometry.type === "BoxGeometry" &&
object.position.z === -30
);
if (offshoreBand) {
offshoreBand.position.x = Math.sin(elapsed * 0.12) * 0.35;
}
positionLabel(defenseLabel, defenseAnchor);
positionLabel(publicLabel, publicAnchor);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
animate();
</script>
</body>
</html>
```