Prompt specification
Build or customize the Three.js 3D scene "Lookout height and visible harbor" 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: Lookout height and visible harbor
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/lookout-height-and-visible-harbor-x1326
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring landmark visibility across terrain. Create a lookout platform facing a harbor over a low wall. Raising the viewpoint reveals additional markers while hidden objects remain physically present behind obstructions. A 3D cutaway view.
Working Three.js Starter (lookout-height-and-visible-harbor-x1326):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tideline — Landmark Visibility Study</title>
<style>
:root {
color-scheme: dark;
--ink: #edf7f3;
--muted: #9db4b0;
--panel: rgba(10, 24, 29, 0.82);
--border: rgba(187, 225, 215, 0.16);
--accent: #75e2c3;
--blocked: #ff806b;
--amber: #ffc66d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0a171d;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#viewport,
#labels {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
#labels {
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.topbar {
position: absolute;
z-index: 10;
top: 24px;
left: 26px;
max-width: min(430px, calc(100vw - 52px));
pointer-events: none;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 27px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 48px);
font-weight: 540;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.inventory {
position: absolute;
z-index: 10;
top: 24px;
right: 24px;
width: 274px;
padding: 17px;
border: 1px solid var(--border);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.inventory-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.inventory h2 {
margin: 0;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.inventory p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#count {
min-width: 47px;
padding: 6px 8px;
border: 1px solid rgba(117, 226, 195, 0.25);
border-radius: 9px;
color: var(--accent);
background: rgba(117, 226, 195, 0.08);
font-size: 12px;
font-weight: 750;
text-align: center;
white-space: nowrap;
}
#markerList {
display: grid;
gap: 7px;
margin: 0;
padding: 0;
list-style: none;
}
.marker-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 9px;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.055);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.marker-row .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px rgba(117, 226, 195, 0.75);
}
.marker-row strong {
display: block;
font-size: 11px;
font-weight: 650;
}
.marker-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.marker-row .state {
color: var(--accent);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.marker-row.masked .dot {
background: var(--blocked);
box-shadow: 0 0 12px rgba(255, 128, 107, 0.45);
}
.marker-row.masked .state {
color: var(--blocked);
}
.controls {
position: absolute;
z-index: 12;
left: 50%;
bottom: 22px;
width: min(660px, calc(100vw - 32px));
padding: 15px 17px 14px;
border: 1px solid var(--border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 20px 65px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(18px);
transform: translateX(-50%);
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.control-copy {
min-width: 165px;
}
.control-copy label {
display: block;
margin-bottom: 3px;
color: var(--accent);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.control-copy strong {
font-size: 16px;
font-weight: 620;
}
.control-copy small {
color: var(--muted);
font-size: 10px;
}
.slider-wrap {
flex: 1;
min-width: 160px;
}
#elevation {
width: 100%;
height: 5px;
margin: 10px 0 6px;
border-radius: 999px;
outline: none;
appearance: none;
background:
linear-gradient(
90deg,
var(--accent) 0%,
var(--accent) var(--fill, 0%),
rgba(255, 255, 255, 0.12) var(--fill, 0%)
);
cursor: pointer;
}
#elevation::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 3px solid #10252a;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
#elevation::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid #10252a;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
.range-labels {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
}
.presets {
display: flex;
gap: 6px;
}
button {
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 255, 255, 0.045);
font-size: 10px;
font-weight: 650;
cursor: pointer;
transition: 160ms ease;
}
button:hover {
border-color: rgba(117, 226, 195, 0.45);
background: rgba(117, 226, 195, 0.09);
}
.control-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.legend {
display: flex;
align-items: center;
gap: 14px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 15px;
height: 2px;
border-radius: 2px;
background: var(--accent);
}
.legend i.blocked {
background: var(--blocked);
}
.switches {
display: flex;
gap: 14px;
}
.switch {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
cursor: pointer;
user-select: none;
}
.switch input {
width: 13px;
height: 13px;
margin: 0;
accent-color: var(--accent);
}
.hint {
position: absolute;
z-index: 8;
right: 26px;
bottom: 25px;
color: rgba(224, 240, 236, 0.58);
font-size: 9px;
letter-spacing: 0.06em;
pointer-events: none;
}
.marker-label {
position: absolute;
top: 0;
left: 0;
min-width: 105px;
padding: 7px 9px;
border: 1px solid rgba(117, 226, 195, 0.28);
border-radius: 8px;
color: var(--ink);
background: rgba(7, 23, 27, 0.83);
box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
opacity: 0;
transition: opacity 180ms ease;
white-space: nowrap;
}
.marker-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
content: "";
background: linear-gradient(var(--accent), transparent);
}
.marker-label strong {
display: block;
font-size: 10px;
font-weight: 650;
}
.marker-label small {
display: block;
margin-top: 2px;
color: var(--accent);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-stamp {
position: absolute;
z-index: 7;
top: 50%;
left: 18px;
color: rgba(229, 243, 239, 0.42);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
writing-mode: vertical-rl;
transform: translateY(-50%);
pointer-events: none;
}
#loading {
position: absolute;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: #0a171d;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
.inventory {
top: auto;
right: 14px;
bottom: 168px;
width: 230px;
}
.inventory p,
.hint,
.section-stamp {
display: none;
}
.control-top {
flex-wrap: wrap;
}
.slider-wrap {
order: 3;
flex-basis: 100%;
}
.control-bottom {
align-items: flex-start;
flex-direction: column;
}
}
@media (max-width: 520px) {
.topbar {
top: 17px;
left: 18px;
}
.subtitle {
display: none;
}
.inventory {
display: none;
}
.controls {
bottom: 10px;
width: calc(100vw - 20px);
padding: 13px;
}
.presets button {
padding: 7px 8px;
font-size: 9px;
}
.legend {
flex-wrap: wrap;
}
}
</style>
</head>
<body>
<main id="app">
<div id="viewport"></div>
<div id="labels"></div>
<header class="topbar">
<div class="eyebrow">Tideline / Section 04</div>
<h1>Harbor lookout</h1>
<p class="subtitle">
Raise the observer to clear the seawall. New landmarks enter the sightline;
masked objects remain physically present in the model.
</p>
</header>
<aside class="inventory">
<div class="inventory-header">
<div>
<h2>Sightline inventory</h2>
<p>Landmarks currently visible to the observer.</p>
</div>
<div id="count">2 / 4</div>
</div>
<ul id="markerList"></ul>
</aside>
<section class="controls" aria-label="Scene controls">
<div class="control-top">
<div class="control-copy">
<label for="elevation">Observer elevation</label>
<strong id="elevationValue">1.3 m</strong>
<small> above platform</small>
</div>
<div class="slider-wrap">
<input
id="elevation"
type="range"
min="0"
max="100"
value="0"
aria-label="Observer elevation"
/>
<div class="range-labels">
<span>Eye level</span>
<span>Survey height</span>
</div>
</div>
<div class="presets" aria-label="Elevation presets">
<button data-level="0">Low</button>
<button data-level="0.48">Raised</button>
<button data-level="1">Survey</button>
</div>
</div>
<div class="control-bottom">
<div class="legend">
<span><i></i>Clear sightline</span>
<span><i class="blocked"></i>Blocked by obstruction</span>
</div>
<div class="switches">
<label class="switch">
<input id="cutaway" type="checkbox" checked />
Cutaway layers
</label>
<label class="switch">
<input id="rays" type="checkbox" checked />
Sightlines
</label>
</div>
</div>
</section>
<div class="hint">DRAG TO ORBIT · WHEEL TO ZOOM</div>
<div class="section-stamp">Section A—A · Coastal edge</div>
<div id="loading">Building harbor section…</div>
</main>
<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 viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labels");
const elevationInput = document.getElementById("elevation");
const elevationValue = document.getElementById("elevationValue");
const countElement = document.getElementById("count");
const markerList = document.getElementById("markerList");
const cutawayInput = document.getElementById("cutaway");
const raysInput = document.getElementById("rays");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a171d);
scene.fog = new THREE.FogExp2(0x0a171d, 0.017);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xc8e9e4,
0x263331,
2.25
);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffe0b7, 3.1);
sunLight.position.set(10, 17, 8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -18;
sunLight.shadow.camera.right = 18;
sunLight.shadow.camera.top = 18;
sunLight.shadow.camera.bottom = -18;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 55;
sunLight.shadow.bias = -0.00035;
scene.add(sunLight);
const rimLight = new THREE.DirectionalLight(0x68c8bd, 1.35);
rimLight.position.set(-12, 8, -16);
scene.add(rimLight);
const world = new THREE.Group();
scene.add(world);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function standard(color, roughness = 0.82, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const materials = {
soilBase: standard(0x38434a, 1),
soilMiddle: standard(0x6c665a, 1),
soilUpper: standard(0x9b7658, 1),
turf: standard(0x667d62, 0.95),
wall: standard(0x8e9690, 0.95),
wallCap: standard(0xb4b9b0, 0.9),
concrete: standard(0xaeb5ac, 0.95),
darkConcrete: standard(0x56625f, 0.95),
timber: standard(0x8c6c4b, 0.88),
timberLight: standard(0xa88860, 0.9),
metal: standard(0x53686a, 0.48, 0.48),
pale: standard(0xd8d4c2, 0.82),
red: standard(0xc95d4f, 0.7),
amber: standard(0xe5a84b, 0.55),
teal: standard(0x4fb9aa, 0.5),
foliage: standard(0x355a4e, 0.92),
foliageLight: standard(0x4f7860, 0.9),
trunk: standard(0x66503b, 1)
};
function box(parent, size, position, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
segments = 24
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function torus(parent, radius, tube, position, material) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 8, 48),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.x = Math.PI / 2;
parent.add(mesh);
return mesh;
}
function outline(size, position, color = 0xb8d7cf, opacity = 0.26) {
const geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(size[0], size[1], size[2])
);
const lines = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
lines.position.set(position[0], position[1], position[2]);
return lines;
}
// -------------------------------------------------------------------------
// Cutaway terrain and harbor water
// -------------------------------------------------------------------------
const layerDefinitions = [
{ size: [16.4, 0.75, 8.1], pos: [0, 0.375, 4], mat: materials.soilBase },
{ size: [16.2, 0.55, 8], pos: [0, 1.025, 4], mat: materials.soilMiddle },
{ size: [15.95, 0.28, 7.95], pos: [0, 1.44, 4], mat: materials.soilUpper },
{ size: [15.75, 0.16, 7.85], pos: [0, 1.66, 4], mat: materials.turf }
];
for (const layer of layerDefinitions) {
box(world, layer.size, layer.pos, layer.mat);
}
const sectionGroup = new THREE.Group();
const shellGroup = new THREE.Group();
world.add(sectionGroup, shellGroup);
for (const layer of layerDefinitions) {
sectionGroup.add(
outline(
layer.size,
layer.pos,
layer.mat === materials.turf ? 0xd8eadc : 0xb7c4bb,
0.24
)
);
}
// The shell is visible only when the analytical cutaway is hidden.
box(
shellGroup,
[16.4, 1.74, 0.08],
[0, 0.87, 8.08],
materials.soilBase
);
box(
shellGroup,
[0.08, 1.74, 8.1],
[8.23, 0.87, 4],
materials.soilBase
);
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x277b86,
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity: 0.72,
transmission: 0.08,
depthWrite: false
});
box(
world,
[25, 1.15, 18],
[0, -0.575, -9],
waterMaterial,
false,
true
);
const waterSurfaceMaterial = new THREE.MeshPhysicalMaterial({
color: 0x2a8a94,
roughness: 0.22,
metalness: 0.08,
transparent: true,
opacity: 0.82,
depthWrite: false
});
const waterSurface = new THREE.Mesh(
new THREE.PlaneGeometry(25, 18),
waterSurfaceMaterial
);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.position.set(0, 0.012, -9);
waterSurface.receiveShadow = true;
world.add(waterSurface);
// Fine water lines are built from core Three.js line geometry.
const wavePositions = [];
for (let row = 0; row < 14; row++) {
const z = -2.2 - row * 1.08;
for (let col = 0; col < 18; col++) {
const x = -11.2 + col * 1.3 + Math.sin(row * 1.9) * 0.25;
const length = 0.35 + 0.25 * (0.5 + 0.5 * Math.sin(row + col));
wavePositions.push(x, 0.035, z, x + length, 0.035, z);
}
}
const waveGeometry = new THREE.BufferGeometry();
waveGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(wavePositions, 3)
);
const waveMaterial = new THREE.LineBasicMaterial({
color: 0xa8e3dc,
transparent: true,
opacity: 0.23
});
scene.add(new THREE.LineSegments(waveGeometry, waveMaterial));
// -------------------------------------------------------------------------
// Lookout platform and the seawall
// -------------------------------------------------------------------------
const platform = new THREE.Group();
world.add(platform);
box(platform, [5.5, 0.25, 3.9], [1.3, 1.82, 3.8], materials.timber);
for (let i = 0; i < 10; i++) {
box(
platform,
[5.35, 0.045, 0.31],
[1.3, 1.965, 2.06 + i * 0.38],
i % 2 ? materials.timberLight : materials.timber,
false,
true
);
}
for (const x of [-0.9, 3.5]) {
for (const z of [2.35, 5.25]) {
box(
platform,
[0.28, 1.7, 0.28],
[x, 0.91, z],
materials.darkConcrete
);
}
}
// Approach path.
box(
world,
[1.9, 0.035, 2.5],
[1.3, 1.76, 0.92],
materials.timberLight,
false,
true
);
// A continuous low seawall masks the near landmarks at eye level.
const wall = box(
world,
[15.15, 0.92, 0.52],
[0, 2.18, 0.22],
materials.wall
);
const wallCap = box(
world,
[15.28, 0.14, 0.64],
[0, 2.69, 0.22],
materials.wallCap
);
const blockers = [wall, wallCap];
// Masonry seams.
for (let x = -7.1; x <= 7.1; x += 1.05) {
box(
world,
[0.025, 0.75, 0.025],
[x, 2.15, 0.492],
materials.darkConcrete,
false,
false
);
}
// Small side rails leave the seawall as the primary obstruction.
for (const x of [-1.28, 3.88]) {
box(
platform,
[0.09, 0.65, 3.45],
[x, 2.3, 3.8],
materials.metal
);
box(
platform,
[0.13, 0.09, 3.65],
[x, 2.65, 3.8],
materials.metal
);
}
// Bench.
box(platform, [2.0, 0.15, 0.48], [1.25, 2.34, 4.55], materials.timberLight);
for (const x of [0.48, 2.02]) {
box(platform, [0.12, 0.38, 0.35], [x, 2.09, 4.55], materials.metal);
}
// Sign created with a local canvas texture.
const signCanvas = document.createElement("canvas");
signCanvas.width = 512;
signCanvas.height = 128;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#17322f";
signContext.fillRect(0, 0, 512, 128);
signContext.strokeStyle = "#9ac9bc";
signContext.lineWidth = 5;
signContext.strokeRect(8, 8, 496, 112);
signContext.fillStyle = "#e6f2ea";
signContext.font = "700 45px sans-serif";
signContext.textAlign = "center";
signContext.textBaseline = "middle";
signContext.fillText("LOOKOUT 04", 256, 65);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
box(
platform,
[2.15, 0.58, 0.1],
[1.3, 2.62, 5.68],
materials.metal
);
const signFace = new THREE.Mesh(
new THREE.PlaneGeometry(2.0, 0.5),
new THREE.MeshBasicMaterial({ map: signTexture })
);
signFace.position.set(1.3, 2.62, 5.74);
platform.add(signFace);
// -------------------------------------------------------------------------
// Exposed services in the cutaway
// -------------------------------------------------------------------------
const drainCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-6.8, 0.62, 8.13),
new THREE.Vector3(-3.2, 0.7, 8.14),
new THREE.Vector3(0.3, 0.82, 8.14),
new THREE.Vector3(3.4, 0.98, 8.14)
]);
const drain = new THREE.Mesh(
new THREE.TubeGeometry(drainCurve, 48, 0.075, 8, false),
materials.amber
);
sectionGroup.add(drain);
const branchCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(3.4, 0.98, 8.14),
new THREE.Vector3(4.0, 1.25, 8.14),
new THREE.Vector3(4.0, 1.52, 8.14)
]);
const branch = new THREE.Mesh(
new THREE.TubeGeometry(branchCurve, 24, 0.075, 8, false),
materials.amber
);
sectionGroup.add(branch);
box(
sectionGroup,
[1.3, 0.46, 0.16],
[1.2, 0.92, 8.16],
materials.concrete,
false,
false
);
const sidePipeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(8.28, 0.58, 6.9),
new THREE.Vector3(8.28, 0.63, 3.2),
new THREE.Vector3(8.28, 0.78, 0.5)
]);
const sidePipe = new THREE.Mesh(
new THREE.TubeGeometry(sidePipeCurve, 42, 0.07, 8, false),
materials.teal
);
sectionGroup.add(sidePipe);
// -------------------------------------------------------------------------
// Trees and harbor structures
// -------------------------------------------------------------------------
function createTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 1.74, z);
tree.scale.setScalar(scale);
cylinder(tree, 0.12, 0.18, 1.2, [0, 0.6, 0], materials.trunk, 10);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.82, 1.8, 8),
materials.foliage
);
lower.position.y = 1.55;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.62, 1.45, 8),
materials.foliageLight
);
upper.position.y = 2.25;
upper.castShadow = true;
tree.add(upper);
world.add(tree);
}
createTree(-6.5, 5.8, 1.15);
createTree(-4.8, 6.7, 0.78);
createTree(6.4, 6.1, 1.05);
// Pier and pilings.
box(
world,
[0.92, 0.17, 4.0],
[-1.8, 0.68, -5.85],
materials.timber
);
for (const z of [-4.3, -5.8, -7.45]) {
for (const x of [-2.1, -1.5]) {
cylinder(
world,
0.075,
0.09,
1.15,
[x, 0.1, z],
materials.timber,
10
);
}
}
// Outer breakwater.
box(
world,
[4.5, 0.45, 1.1],
[5, 0.24, -10.5],
materials.darkConcrete
);
// Lighthouse island.
const island = cylinder(
world,
1.9,
2.15,
0.55,
[-6, 0.18, -13.2],
materials.soilUpper,
32
);
island.receiveShadow = true;
cylinder(
world,
0.48,
0.74,
3.05,
[-6, 1.78, -13.2],
materials.pale,
24
);
cylinder(
world,
0.63,
0.63,
0.55,
[-6, 2.48, -13.2],
materials.red,
24
);
cylinder(
world,
0.54,
0.54,
0.18,
[-6, 3.35, -13.2],
materials.metal,
20
);
const lanternMaterial = new THREE.MeshStandardMaterial({
color: 0xffe8a0,
emissive: 0xffb83e,
emissiveIntensity: 1.8,
roughness: 0.3
});
const lantern = cylinder(
world,
0.34,
0.34,
0.55,
[-6, 3.67, -13.2],
lanternMaterial,
16
);
cylinder(
world,
0,
0.47,
0.35,
[-6, 4.11, -13.2],
materials.red,
16
);
// Small moored vessel.
const ship = new THREE.Group();
ship.position.set(1.2, 0.26, -9.4);
ship.rotation.y = -0.15;
world.add(ship);
box(ship, [2.8, 0.42, 1.05], [0, 0, 0], materials.darkConcrete);
box(ship, [1.8, 0.75, 0.85], [-0.3, 0.56, 0], materials.pale);
box(ship, [0.62, 0.38, 0.9], [0.86, 0.39, 0], materials.red);
cylinder(ship, 0.08, 0.08, 1.4, [-0.65, 1.1, 0], materials.metal, 10);
// -------------------------------------------------------------------------
// Marker objects and metadata
// -------------------------------------------------------------------------
const markers = [];
function addMarker({
id,
name,
detail,
anchor,
color,
build
}) {
const group = new THREE.Group();
world.add(group);
const beaconMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.6,
roughness: 0.3
});
build(group, beaconMaterial);
const haloMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.72,
depthWrite: false
});
const halo = torus(
group,
0.42,
0.025,
[anchor[0], anchor[1], anchor[2]],
haloMaterial
);
const label = document.createElement("div");
label.className = "marker-label";
label.innerHTML = `
<strong>${name}</strong>
<small>Landmark visible</small>
`;
labelLayer.appendChild(label);
const row = document.createElement("li");
row.className = "marker-row";
row.innerHTML = `
<span class="dot"></span>
<span>
<strong>${name}</strong>
<small>${detail}</small>
</span>
<span class="state">In sight</span>
`;
markerList.appendChild(row);
markers.push({
id,
name,
anchor: new THREE.Vector3(...anchor),
group,
halo,
beaconMaterial,
label,
row,
visible: false
});
}
addMarker({
id: "pier",
name: "Pier Head",
detail: "Near harbor structure",
anchor: [-1.8, 1.32, -7.8],
color: 0xff806b,
build(group, beaconMaterial) {
cylinder(group, 0.09, 0.12, 0.65, [-1.8, 1.03, -7.8], materials.metal, 12);
const light = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 14, 10),
beaconMaterial
);
light.position.set(-1.8, 1.32, -7.8);
group.add(light);
}
});
addMarker({
id: "buoy",
name: "Channel Buoy",
detail: "Navigation marker",
anchor: [3.3, 1.05, -4.5],
color: 0xff806b,
build(group, beaconMaterial) {
cylinder(group, 0.22, 0.34, 0.42, [3.3, 0.2, -4.5], materials.red, 16);
cylinder(group, 0.065, 0.075, 0.72, [3.3, 0.65, -4.5], materials.metal, 12);
const light = new THREE.Mesh(
new THREE.SphereGeometry(0.15, 14, 10),
beaconMaterial
);
light.position.set(3.3, 1.05, -4.5);
group.add(light);
}
});
addMarker({
id: "outer",
name: "Outer Beacon",
detail: "Breakwater head",
anchor: [5, 2.95, -10.5],
color: 0xffc66d,
build(group, beaconMaterial) {
cylinder(group, 0.24, 0.38, 1.95, [5, 1.3, -10.5], materials.pale, 16);
cylinder(group, 0.32, 0.32, 0.35, [5, 2.35, -10.5], materials.red, 16);
const light = new THREE.Mesh(
new THREE.SphereGeometry(0.18, 14, 10),
beaconMaterial
);
light.position.set(5, 2.95, -10.5);
group.add(light);
}
});
addMarker({
id: "light",
name: "Harbor Light",
detail: "Northern lighthouse",
anchor: [-6, 3.92, -13.2],
color: 0xffc66d,
build(group, beaconMaterial) {
const light = new THREE.Mesh(
new THREE.SphereGeometry(0.28, 16, 12),
beaconMaterial
);
light.position.set(-6, 3.92, -13.2);
group.add(light);
}
});
// -------------------------------------------------------------------------
// Observer and dynamic sightlines
// -------------------------------------------------------------------------
const observer = new THREE.Group();
world.add(observer);
const observerMaterial = new THREE.MeshBasicMaterial({
color: 0x75e2c3,
transparent: true,
opacity: 0.95
});
const observerOrb = new THREE.Mesh(
new THREE.OctahedronGeometry(0.22),
observerMaterial
);
observer.add(observerOrb);
const observerRing = torus(
observer,
0.42,
0.025,
[0, 0, 0],
new THREE.MeshBasicMaterial({
color: 0x75e2c3,
transparent: true,
opacity: 0.65,
depthWrite: false
})
);
const observerGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(1.3, 1.98, 4.2),
new THREE.Vector3(1.3, 3.05, 4.2)
]),
new THREE.LineDashedMaterial({
color: 0x75e2c3,
transparent: true,
opacity: 0.38,
dashSize: 0.14,
gapSize: 0.12
})
);
observerGuide.computeLineDistances();
world.add(observerGuide);
let sightlineGeometry = new THREE.BufferGeometry();
const sightlineMaterial = new THREE.LineBasicMaterial({
vertexColors: true,
transparent: true,
opacity: 0.78
});
const sightlines = new THREE.LineSegments(
sightlineGeometry,
sightlineMaterial
);
scene.add(sightlines);
const raycaster = new THREE.Raycaster();
const observerPosition = new THREE.Vector3();
const state = {
elevation: 0,
theta: 0.36,
phi: 1.30,
radius: 22,
target: new THREE.Vector3(0, 1.0, -1.8)
};
function updateObserver() {
const eyeHeight = 3.05 + state.elevation * 6.8;
observerPosition.set(1.3, eyeHeight, 4.2);
observer.position.copy(observerPosition);
observerRing.rotation.z = state.elevation * 2.5;
observerGuide.geometry.dispose();
observerGuide.geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(1.3, 1.98, 4.2),
observerPosition.clone()
]);
observerGuide.computeLineDistances();
elevationValue.textContent = `${(eyeHeight - 1.98).toFixed(1)} m`;
elevationInput.style.setProperty(
"--fill",
`${state.elevation * 100}%`
);
}
function updateVisibility() {
const positions = [];
const colors = [];
const clear = new THREE.Color(0x75e2c3);
const blocked = new THREE.Color(0xff806b);
const mutedBlocked = new THREE.Color(0x8f5049);
let visibleCount = 0;
for (const marker of markers) {
const direction = marker.anchor.clone().sub(observerPosition);
const distance = direction.length();
direction.normalize();
raycaster.set(observerPosition, direction);
raycaster.near = 0.02;
raycaster.far = distance;
const hit = raycaster.intersectObjects(blockers, false)[0];
marker.visible = !hit;
if (marker.visible) {
visibleCount++;
positions.push(
observerPosition.x,
observerPosition.y,
observerPosition.z,
marker.anchor.x,
marker.anchor.y,
marker.anchor.z
);
colors.push(clear.r, clear.g, clear.b, clear.r, clear.g, clear.b);
} else {
const hitPoint = hit.point;
positions.push(
observerPosition.x,
observerPosition.y,
observerPosition.z,
hitPoint.x,
hitPoint.y,
hitPoint.z
);
colors.push(
blocked.r,
blocked.g,
blocked.b,
blocked.r,
blocked.g,
blocked.b
);
positions.push(
hitPoint.x,
hitPoint.y,
hitPoint.z,
marker.anchor.x,
marker.anchor.y,
marker.anchor.z
);
colors.push(
mutedBlocked.r,
mutedBlocked.g,
mutedBlocked.b,
mutedBlocked.r,
mutedBlocked.g,
mutedBlocked.b
);
}
marker.halo.visible = marker.visible;
marker.row.classList.toggle("masked", !marker.visible);
marker.row.querySelector(".state").textContent = marker.visible
? "In sight"
: "Masked";
marker.row.querySelector("small").textContent = marker.visible
? "Clear line of sight"
: "Behind seawall";
}
countElement.textContent = `${visibleCount} / ${markers.length}`;
sightlineGeometry.dispose();
sightlineGeometry = new THREE.BufferGeometry();
sightlines.geometry = sightlineGeometry;
sightlineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
sightlineGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
}
function setElevation(value) {
state.elevation = THREE.MathUtils.clamp(value, 0, 1);
state.phi = 1.30 - state.elevation * 0.32;
elevationInput.value = String(Math.round(state.elevation * 100));
updateObserver();
updateVisibility();
}
// -------------------------------------------------------------------------
// Custom camera controls — no Three.js examples/addons
// -------------------------------------------------------------------------
function updateCamera() {
const sinPhi = Math.sin(state.phi);
camera.position.set(
state.target.x + state.radius * sinPhi * Math.sin(state.theta),
state.target.y + state.radius * Math.cos(state.phi),
state.target.z + state.radius * sinPhi * Math.cos(state.theta)
);
camera.lookAt(state.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
state.theta -= dx * 0.005;
setElevation(state.elevation - dy * 0.0018);
pointerX = event.clientX;
pointerY = event.clientY;
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
state.radius = THREE.MathUtils.clamp(
state.radius + event.deltaY * 0.012,
14,
34
);
},
{ passive: false }
);
elevationInput.addEventListener("input", () => {
setElevation(Number(elevationInput.value) / 100);
});
document.querySelectorAll("[data-level]").forEach((button) => {
button.addEventListener("click", () => {
setElevation(Number(button.dataset.level));
});
});
cutawayInput.addEventListener("change", () => {
sectionGroup.visible = cutawayInput.checked;
shellGroup.visible = !cutawayInput.checked;
});
raysInput.addEventListener("change", () => {
sightlines.visible = raysInput.checked;
});
// -------------------------------------------------------------------------
// Projection and animation
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
for (const marker of markers) {
projected.copy(marker.anchor);
projected.y += 0.38;
projected.project(camera);
const onScreen =
marker.visible &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
marker.label.style.opacity = onScreen ? "1" : "0";
if (onScreen) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
marker.label.style.left = `${x}px`;
marker.label.style.top = `${y}px`;
marker.label.style.transform = "translate(-50%, -100%)";
}
}
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", onResize);
scene.updateMatrixWorld(true);
setElevation(0);
updateCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
updateCamera();
for (let i = 0; i < markers.length; i++) {
const marker = markers[i];
marker.beaconMaterial.emissiveIntensity =
1.25 + Math.sin(time * 2.3 + i * 1.4) * 0.38;
if (marker.halo.visible) {
const pulse = 1 + Math.sin(time * 2.1 + i) * 0.08;
marker.halo.scale.setScalar(pulse);
marker.halo.material.opacity = 0.55 + Math.sin(time * 2 + i) * 0.16;
}
}
observerOrb.rotation.y = time * 0.7;
observerOrb.rotation.x = time * 0.35;
waveMaterial.opacity = 0.2 + Math.sin(time * 0.65) * 0.035;
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```