Prompt specification
Build or customize the Three.js 3D scene "Choose a harbor access window" 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: Choose a harbor access window
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/choose-a-harbor-access-window-x1288
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a small low-poly harbor with a shallow entrance. Two breakwaters frame a channel, and a vessel waits outside beside a depth gauge. Add a tide slider that raises the water against a fixed chart datum; the seabed and vessel draft remain unchanged. A passage indicator turns available only when water depth exceeds draft by the displayed clearance allowance. Let the boat attempt the crossing after the user chooses a time. Show insufficient clearance as a blocked departure, not a collision animation. Use fictional dimensions, simple blue water, sandy bottom contours, and an oblique view into the channel.
Working Three.js Starter (choose-a-harbor-access-window-x1288):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pelican Reach — Harbor Clearance Simulator</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(10, 24, 37, 0.91);
--panel-border: rgba(174, 214, 230, 0.2);
--text: #eaf7fb;
--muted: #a9c0ca;
--accent: #63d3ed;
--green: #57df94;
--red: #ff6b70;
--amber: #f5c56f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d9e6;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
top: 16px;
left: 16px;
width: min(370px, calc(100vw - 32px));
max-height: calc(100vh - 32px);
overflow-y: auto;
padding: 18px;
border: 1px solid var(--panel-border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(3, 18, 30, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 1.45rem;
line-height: 1.15;
letter-spacing: -0.025em;
}
.subtitle {
margin: 8px 0 15px;
color: var(--muted);
font-size: 0.86rem;
line-height: 1.45;
}
.passage-pill {
display: flex;
align-items: center;
gap: 9px;
width: 100%;
margin-bottom: 16px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 11px;
background: rgba(255, 255, 255, 0.055);
font-size: 0.78rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.passage-pill .dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--red);
box-shadow: 0 0 13px currentColor;
color: var(--red);
}
.passage-pill.available .dot {
background: var(--green);
color: var(--green);
}
.passage-pill.available {
color: #caffdf;
}
.passage-pill.blocked {
color: #ffd2d4;
}
.control {
margin: 0 0 15px;
}
.control-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.control label {
color: #d9eaf0;
font-size: 0.8rem;
font-weight: 700;
}
.control output {
color: var(--accent);
font-variant-numeric: tabular-nums;
font-size: 0.86rem;
font-weight: 800;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--accent);
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: #77919d;
font-size: 0.68rem;
}
.small-note {
margin: 6px 0 0;
color: #829ba6;
font-size: 0.69rem;
line-height: 1.4;
}
.data-grid {
display: grid;
grid-template-columns: 1fr auto;
gap: 7px 12px;
margin: 2px 0 15px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 12px;
background: rgba(0, 0, 0, 0.12);
font-size: 0.78rem;
}
.data-grid span:nth-child(odd) {
color: var(--muted);
}
.data-grid span:nth-child(even) {
color: var(--text);
font-weight: 750;
font-variant-numeric: tabular-nums;
text-align: right;
}
.positive {
color: var(--green) !important;
}
.negative {
color: var(--red) !important;
}
.inline-controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 12px;
}
.box-control {
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 11px;
background: rgba(0, 0, 0, 0.1);
}
.box-control label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 0.7rem;
font-weight: 700;
}
input[type="number"],
input[type="time"] {
width: 100%;
min-width: 0;
padding: 7px 8px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
outline: none;
background: rgba(255, 255, 255, 0.075);
color: var(--text);
font: inherit;
font-size: 0.84rem;
font-variant-numeric: tabular-nums;
}
input:focus {
border-color: var(--accent);
}
.button-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
}
button {
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.07);
color: var(--text);
font: inherit;
font-size: 0.78rem;
font-weight: 800;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}
button:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.13);
transform: translateY(-1px);
}
button.primary {
border-color: rgba(99, 211, 237, 0.42);
background: #237f99;
}
button.primary:hover:not(:disabled) {
background: #2c95b2;
}
button:disabled,
input:disabled {
cursor: not-allowed;
opacity: 0.48;
}
.status {
margin-top: 14px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-left: 3px solid var(--accent);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
}
.status.blocked {
border-left-color: var(--red);
}
.status.available {
border-left-color: var(--green);
}
.status.warning {
border-left-color: var(--amber);
}
#statusTitle {
margin: 0 0 4px;
font-size: 0.83rem;
font-weight: 850;
}
#statusDetail {
margin: 0;
color: var(--muted);
font-size: 0.73rem;
line-height: 1.45;
}
.legend {
position: fixed;
z-index: 8;
right: 16px;
bottom: 16px;
display: flex;
gap: 12px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 10px;
background: rgba(10, 24, 37, 0.72);
color: #d9eaf0;
font-size: 0.68rem;
backdrop-filter: blur(8px);
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 14px;
height: 6px;
border-radius: 4px;
background: #43a9cc;
}
.swatch.sand {
background: #c9a766;
}
.swatch.datum {
background: #ef9a50;
}
.camera-hint {
position: fixed;
z-index: 7;
right: 16px;
top: 16px;
padding: 7px 10px;
border-radius: 8px;
background: rgba(10, 24, 37, 0.58);
color: #dcecf2;
font-size: 0.67rem;
pointer-events: none;
}
@media (max-width: 700px) {
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 56vh;
padding: 15px;
}
.camera-hint {
display: none;
}
.legend {
top: 12px;
right: 12px;
bottom: auto;
flex-direction: column;
gap: 5px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<section class="panel" aria-label="Harbor departure controls">
<p class="eyebrow">Fictional harbor operations</p>
<h1>Pelican Reach</h1>
<p class="subtitle">
Raise the tide against the fixed chart datum, set a clearance allowance,
then attempt a departure through the shallow entrance.
</p>
<div id="passagePill" class="passage-pill blocked">
<span class="dot"></span>
<span id="passageText">Passage blocked</span>
</div>
<div class="control">
<div class="control-heading">
<label for="tideSlider">Tide above chart datum</label>
<output id="tideOutput" for="tideSlider">+1.20 m</output>
</div>
<input
id="tideSlider"
type="range"
min="0"
max="2.5"
step="0.05"
value="1.2"
/>
<div class="range-ends">
<span>Datum 0.00 m</span>
<span>High water +2.50 m</span>
</div>
</div>
<div class="data-grid" aria-label="Clearance calculation">
<span>Depth at entrance shoal</span><span id="depthValue">—</span>
<span>Fixed vessel draft</span><span>1.05 m</span>
<span>Required depth</span><span id="requiredValue">—</span>
<span>Clearance margin</span><span id="marginValue">—</span>
</div>
<div class="inline-controls">
<div class="box-control">
<label for="clearanceInput">Clearance allowance</label>
<input
id="clearanceInput"
type="number"
min="0"
max="0.8"
step="0.05"
value="0.25"
/>
</div>
<div class="box-control">
<label for="departureTime">Chosen departure time</label>
<input id="departureTime" type="time" value="06:40" />
</div>
</div>
<p class="small-note">
Passage is available only when sounding depth is greater than vessel draft
plus the displayed allowance. The seabed and 1.05 m draft are fixed.
</p>
<div class="button-row">
<button id="departButton" class="primary" type="button">Attempt departure</button>
<button id="resetButton" type="button">Return to hold</button>
</div>
<div id="statusBox" class="status" role="status" aria-live="polite">
<p id="statusTitle">Vessel holding outside the entrance</p>
<p id="statusDetail">Adjust the tide or clearance allowance to assess passage.</p>
</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<div class="legend" aria-hidden="true">
<span><i class="swatch"></i>Water</span>
<span><i class="swatch sand"></i>Sandy contours</span>
<span><i class="swatch datum"></i>Chart datum</span>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const tideSlider = document.getElementById("tideSlider");
const tideOutput = document.getElementById("tideOutput");
const clearanceInput = document.getElementById("clearanceInput");
const departureTime = document.getElementById("departureTime");
const departButton = document.getElementById("departButton");
const resetButton = document.getElementById("resetButton");
const passagePill = document.getElementById("passagePill");
const passageText = document.getElementById("passageText");
const depthValue = document.getElementById("depthValue");
const requiredValue = document.getElementById("requiredValue");
const marginValue = document.getElementById("marginValue");
const statusBox = document.getElementById("statusBox");
const statusTitle = document.getElementById("statusTitle");
const statusDetail = document.getElementById("statusDetail");
const DRAFT = 1.05;
const CHART_DATUM_Y = 0;
const HOLDING_POSITION = new THREE.Vector3(1.6, 0, 7.2);
const state = {
tide: Number(tideSlider.value),
clearance: Number(clearanceInput.value),
depth: 0,
required: DRAFT + Number(clearanceInput.value),
margin: 0,
available: false,
crossing: null,
completed: false,
blockedFlashUntil: 0
};
// Renderer and scene ---------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d8e5);
scene.fog = new THREE.Fog(0xb8d8e5, 38, 80);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
140
);
const cameraState = {
target: new THREE.Vector3(0, 0, -1.2),
radius: 31,
theta: 0.68,
phi: 0.88
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
// Small, self-contained orbit controls; no Three.js addons are used.
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.theta -= deltaX * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.004,
0.48,
1.18
);
updateCamera();
});
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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
21,
46
);
updateCamera();
},
{ passive: false }
);
// Lighting --------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe8f7ff, 0x8a7453, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4da, 3.1);
sun.position.set(-12, 24, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ed9f0, 0.75);
fill.position.set(18, 8, -18);
scene.add(fill);
// Helpers ---------------------------------------------------------------
const clamp = THREE.MathUtils.clamp;
function seededRandom() {
seed = (seed * 9301 + 49297) % 233280;
return seed / 233280;
}
let seed = 29;
function makeLabel(text, width, color = "#eaf7fb") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
const gradient = context.createLinearGradient(0, 0, 512, 96);
gradient.addColorStop(0, "rgba(8, 28, 43, 0.94)");
gradient.addColorStop(1, "rgba(19, 55, 71, 0.94)");
context.fillStyle = gradient;
context.strokeStyle = "rgba(185, 225, 239, 0.42)";
context.lineWidth = 3;
const x = 8;
const y = 8;
const w = 496;
const h = 80;
const r = 17;
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + w - r, y);
context.quadraticCurveTo(x + w, y, x + w, y + r);
context.lineTo(x + w, y + h - r);
context.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
context.lineTo(x + r, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
context.fill();
context.stroke();
context.fillStyle = color;
context.font = "800 31px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 96 / 512, 1);
sprite.renderOrder = 10;
return sprite;
}
// Fixed sandy seabed ----------------------------------------------------
function bedHeight(x, z) {
const shoal = 1.48 * Math.exp(-Math.pow((z - 5.4) / 2.4, 2));
const channelGroove = -0.12 * Math.exp(-Math.pow(x / 2.5, 2));
const bankRise = Math.max(0, Math.abs(x) - 5.0) * 0.42;
const ripple = 0.035 * Math.sin(x * 1.7 + z * 0.55);
return -1.78 + shoal + channelGroove + bankRise + ripple;
}
const bedGeometry = new THREE.PlaneGeometry(32, 44, 28, 38);
bedGeometry.rotateX(-Math.PI / 2);
const bedPositions = bedGeometry.attributes.position;
const bedColors = new Float32Array(bedPositions.count * 3);
const deepSand = new THREE.Color(0xa98a4f);
const middleSand = new THREE.Color(0xc7a564);
const highSand = new THREE.Color(0xe0c78d);
const vertexColor = new THREE.Color();
for (let i = 0; i < bedPositions.count; i++) {
const x = bedPositions.getX(i);
const z = bedPositions.getZ(i);
const y = bedHeight(x, z);
bedPositions.setY(i, y);
const t = clamp((y + 1.8) / 2.1, 0, 1);
if (t < 0.58) {
vertexColor.lerpColors(deepSand, middleSand, t / 0.58);
} else {
vertexColor.lerpColors(
middleSand,
highSand,
(t - 0.58) / 0.42
);
}
bedColors[i * 3] = vertexColor.r;
bedColors[i * 3 + 1] = vertexColor.g;
bedColors[i * 3 + 2] = vertexColor.b;
}
bedGeometry.setAttribute("color", new THREE.BufferAttribute(bedColors, 3));
bedGeometry.computeVertexNormals();
const seabed = new THREE.Mesh(
bedGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
})
);
seabed.receiveShadow = true;
scene.add(seabed);
// Marching-squares style contour lines, generated from the fixed bed.
function addBedContour(level) {
const segments = [];
const columns = 28;
const rows = 38;
function point(index) {
return {
x: bedPositions.getX(index),
z: bedPositions.getZ(index),
y: bedPositions.getY(index)
};
}
function interpolate(a, b) {
const t = (level - a.y) / (b.y - a.y);
return [
THREE.MathUtils.lerp(a.x, b.x, t),
level + 0.018,
THREE.MathUtils.lerp(a.z, b.z, t)
];
}
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const a = point(row * (columns + 1) + column);
const b = point(row * (columns + 1) + column + 1);
const c = point((row + 1) * (columns + 1) + column + 1);
const d = point((row + 1) * (columns + 1) + column);
const corners = [a, b, c, d];
const intersections = [];
for (let edge = 0; edge < 4; edge++) {
const first = corners[edge];
const second = corners[(edge + 1) % 4];
const firstBelow = first.y < level;
const secondBelow = second.y < level;
if (firstBelow !== secondBelow) {
intersections.push(interpolate(first, second));
}
}
if (intersections.length === 2) {
segments.push(...intersections[0], ...intersections[1]);
} else if (intersections.length === 4) {
segments.push(...intersections[0], ...intersections[1]);
segments.push(...intersections[2], ...intersections[3]);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(segments, 3)
);
const contour = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0x8c6d38,
transparent: true,
opacity: 0.52
})
);
scene.add(contour);
}
[-1.5, -1.2, -0.9, -0.6, -0.3, 0.0, 0.3].forEach(addBedContour);
// Water surface ---------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(34, 46, 24, 32);
waterGeometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(
waterGeometry,
new THREE.MeshStandardMaterial({
color: 0x2e9bc4,
roughness: 0.78,
metalness: 0.02,
transparent: true,
opacity: 0.76,
depthWrite: false,
side: THREE.DoubleSide
})
);
water.position.y = state.tide;
water.receiveShadow = true;
scene.add(water);
const waterHighlights = new THREE.Group();
for (let i = 0; i < 24; i++) {
const x = (seededRandom() - 0.5) * 23;
const z = (seededRandom() - 0.5) * 30;
const length = 0.6 + seededRandom() * 1.5;
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x - length * 0.5, 0.025, z),
new THREE.Vector3(x + length * 0.5, 0.025, z + 0.08)
]);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0xc7f4ff,
transparent: true,
opacity: 0.15
})
);
waterHighlights.add(line);
}
waterHighlights.position.y = state.tide;
scene.add(waterHighlights);
// Fixed chart datum outline -------------------------------------------
const datumPoints = [
new THREE.Vector3(-5.8, CHART_DATUM_Y, -11.5),
new THREE.Vector3(-5.8, CHART_DATUM_Y, 11),
new THREE.Vector3(5.8, CHART_DATUM_Y, 11),
new THREE.Vector3(5.8, CHART_DATUM_Y, -11.5)
];
const datumLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(datumPoints),
new THREE.LineDashedMaterial({
color: 0xef9852,
dashSize: 0.28,
gapSize: 0.18,
transparent: true,
opacity: 0.65
})
);
datumLine.computeLineDistances();
scene.add(datumLine);
const datumLabel = makeLabel("CHART DATUM 0.00 m", 3.05, "#ffd0a3");
datumLabel.position.set(-5.7, 0.55, -6.8);
scene.add(datumLabel);
// Breakwaters, quay, and harbor structures -----------------------------
const rockGeometry = new THREE.DodecahedronGeometry(1, 0);
const rockMaterials = [
new THREE.MeshStandardMaterial({ color: 0x66747a, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x7b8587, roughness: 1, flatShading: true }),
new THREE.MeshStandardMaterial({ color: 0x59676d, roughness: 1, flatShading: true })
];
const concreteMaterial = new THREE.MeshStandardMaterial({
color: 0x777a72,
roughness: 0.95,
flatShading: true
});
for (const side of [-1, 1]) {
const core = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 1.05, 12.8),
concreteMaterial
);
core.position.set(side * 4.55, -0.05, -3.55);
core.castShadow = true;
core.receiveShadow = true;
scene.add(core);
for (let z = -9.7; z < 2.9; z += 1.15) {
for (let row = 0; row < 2; row++) {
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[Math.floor(seededRandom() * rockMaterials.length)]
);
rock.position.set(
side * (4.45 + (seededRandom() - 0.5) * 0.8),
0.38 + seededRandom() * 0.18,
z + (row - 0.5) * 0.56
);
rock.scale.set(
0.7 + seededRandom() * 0.45,
0.62 + seededRandom() * 0.5,
0.72 + seededRandom() * 0.5
);
rock.rotation.set(
seededRandom() * Math.PI,
seededRandom() * Math.PI,
seededRandom() * Math.PI
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
}
}
const quay = new THREE.Mesh(
new THREE.BoxGeometry(14, 1.1, 4.2),
new THREE.MeshStandardMaterial({
color: 0xb9a67d,
roughness: 1,
flatShading: true
})
);
quay.position.set(0, 0.05, -13.3);
quay.castShadow = true;
quay.receiveShadow = true;
scene.add(quay);
const shedMaterial = new THREE.MeshStandardMaterial({
color: 0xd5d0b9,
roughness: 0.95,
flatShading: true
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x536b72,
roughness: 0.9,
flatShading: true
});
for (const shed of [
{ x: -3.8, z: -13.4, w: 4.2 },
{ x: 2.4, z: -13.8, w: 3.5 }
]) {
const walls = new THREE.Mesh(
new THREE.BoxGeometry(shed.w, 1.8, 2.7),
shedMaterial
);
walls.position.set(shed.x, 1.45, shed.z);
walls.castShadow = true;
scene.add(walls);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(shed.w * 0.72, 0.8, 4),
roofMaterial
);
roof.position.set(shed.x, 2.75, shed.z);
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
scene.add(roof);
}
const entranceLabel = makeLabel("SHALLOW ENTRANCE", 3.35, "#ffe0a8");
entranceLabel.position.set(-0.2, 1.2, 4.45);
scene.add(entranceLabel);
// Passage signal mast ---------------------------------------------------
const signalMast = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.17, 3.6, 6),
new THREE.MeshStandardMaterial({
color: 0xd4d8d5,
roughness: 0.8
})
);
signalMast.position.set(4.55, 1.55, 2.05);
signalMast.castShadow = true;
scene.add(signalMast);
const signalHousing = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.88, 0.5),
new THREE.MeshStandardMaterial({
color: 0x263943,
roughness: 0.7
})
);
signalHousing.position.set(4.55, 3.35, 2.05);
signalHousing.castShadow = true;
scene.add(signalHousing);
const signalMaterial = new THREE.MeshStandardMaterial({
color: 0xff555d,
emissive: 0xff3038,
emissiveIntensity: 1.1,
roughness: 0.35
});
const signalLamp = new THREE.Mesh(
new THREE.SphereGeometry(0.27, 12, 8),
signalMaterial
);
signalLamp.position.set(4.55, 3.4, 2.34);
scene.add(signalLamp);
const signalLabel = makeLabel("PASSAGE SIGNAL", 2.35);
signalLabel.position.set(4.55, 4.08, 2.05);
scene.add(signalLabel);
// Depth gauge, datum staff, and changing depth column ------------------
const CRITICAL_X = 3.35;
const CRITICAL_Z = 5.35;
const CRITICAL_BED = bedHeight(CRITICAL_X, CRITICAL_Z);
const staff = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 3.7, 0.13),
new THREE.MeshStandardMaterial({
color: 0xe4e0cd,
roughness: 0.85
})
);
staff.position.set(3.9, 0.52, CRITICAL_Z);
staff.castShadow = true;
scene.add(staff);
for (let tenth = -2; tenth <= 10; tenth++) {
const isMajor = tenth % 4 === 0;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(isMajor ? 0.48 : 0.29, 0.035, 0.06),
new THREE.MeshBasicMaterial({ color: 0x3d5259 })
);
tick.position.set(3.78, tenth * 0.25, CRITICAL_Z - 0.09);
scene.add(tick);
}
const datumMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.08, 0.12),
new THREE.MeshBasicMaterial({ color: 0xff9253 })
);
datumMarker.position.set(3.75, CHART_DATUM_Y, CRITICAL_Z - 0.14);
scene.add(datumMarker);
const tideMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.6, 0.08, 0.17),
new THREE.MeshBasicMaterial({ color: 0x68ddf3 })
);
tideMarker.position.set(3.75, state.tide, CRITICAL_Z - 0.14);
scene.add(tideMarker);
const depthColumn = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 1, 8),
new THREE.MeshBasicMaterial({
color: 0x73e8f5,
transparent: true,
opacity: 0.85
})
);
depthColumn.position.set(CRITICAL_X, CRITICAL_BED, CRITICAL_Z);
scene.add(depthColumn);
const gaugeLabel = makeLabel("TIDE / DEPTH STAFF", 2.6, "#bfefff");
gaugeLabel.position.set(3.9, 2.9, CRITICAL_Z);
scene.add(gaugeLabel);
// Low-poly vessel -------------------------------------------------------
function createHullGeometry() {
const outline = [
[0.0, -2.15],
[0.72, -1.28],
[0.86, 0.28],
[0.56, 1.35],
[-0.56, 1.35],
[-0.86, 0.28],
[-0.72, -1.28]
];
const positions = [];
const topY = 0.34;
const bottomY = -DRAFT;
function triangle(a, b, c) {
positions.push(...a, ...b, ...c);
}
for (let i = 0; i < outline.length; i++) {
const next = (i + 1) % outline.length;
const current = outline[i];
const following = outline[next];
const topA = [current[0], topY, current[1]];
const topB = [following[0], topY, following[1]];
const bottomA = [current[0] * 0.56, bottomY, current[1] * 0.78];
const bottomB = [following[0] * 0.56, bottomY, following[1] * 0.78];
triangle([0, topY, 0], topA, topB);
triangle([0, bottomY, 0], bottomB, bottomA);
triangle(topA, bottomA, bottomB);
triangle(topA, bottomB, topB);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
const boat = new THREE.Group();
boat.position.copy(HOLDING_POSITION);
const hullMaterial = new THREE.MeshStandardMaterial({
color: 0xc9543f,
roughness: 0.76,
flatShading: true,
side: THREE.DoubleSide
});
const hull = new THREE.Mesh(createHullGeometry(), hullMaterial);
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
const deck = new THREE.Mesh(
new THREE.BoxGeometry(1.22, 0.16, 1.82),
new THREE.MeshStandardMaterial({
color: 0xe6c89a,
roughness: 0.9,
flatShading: true
})
);
deck.position.set(0, 0.39, 0.27);
deck.castShadow = true;
boat.add(deck);
const cabin = new THREE.Mesh(
new THREE.BoxGeometry(0.88, 0.68, 0.92),
new THREE.MeshStandardMaterial({
color: 0xe5e2d4,
roughness: 0.85,
flatShading: true
})
);
cabin.position.set(0, 0.76, 0.36);
cabin.castShadow = true;
boat.add(cabin);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(1.02, 0.12, 1.05),
new THREE.MeshStandardMaterial({
color: 0x34545d,
roughness: 0.8,
flatShading: true
})
);
roof.position.set(0, 1.15, 0.36);
roof.castShadow = true;
boat.add(roof);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x27566a,
roughness: 0.25,
metalness: 0.12
});
const frontWindow = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.27, 0.035),
windowMaterial
);
frontWindow.position.set(0, 0.82, -0.115);
boat.add(frontWindow);
for (const side of [-1, 1]) {
const sideWindow = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.27, 0.55),
windowMaterial
);
sideWindow.position.set(side * 0.455, 0.82, 0.38);
boat.add(sideWindow);
}
const draftLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(1.08, -DRAFT, 0),
new THREE.Vector3(1.08, 0, 0)
]),
new THREE.LineBasicMaterial({ color: 0xffffff })
);
boat.add(draftLine);
const draftLabel = makeLabel("DRAFT 1.05 m", 1.65, "#ffffff");
draftLabel.position.set(1.65, -0.48, 0);
boat.add(draftLabel);
const wake = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.55, 0.03, 1.1),
new THREE.Vector3(-1.05, 0.03, 2.6),
new THREE.Vector3(0.55, 0.03, 1.1),
new THREE.Vector3(1.05, 0.03, 2.6)
]),
new THREE.LineBasicMaterial({
color: 0xe5fbff,
transparent: true,
opacity: 0.7
})
);
wake.visible = false;
boat.add(wake);
scene.add(boat);
const holdingLabel = makeLabel("VESSEL HOLDING", 2.5, "#d8f4ff");
holdingLabel.position.set(1.6, 2.45, 7.2);
scene.add(holdingLabel);
const route = new THREE.CatmullRomCurve3([
new THREE.Vector3(1.6, 0, 7.2),
new THREE.Vector3(0.8, 0, 4.8),
new THREE.Vector3(0, 0, 1.0),
new THREE.Vector3(0, 0, -3.8),
new THREE.Vector3(0, 0, -8.0),
new THREE.Vector3(0, 0, -10.7)
]);
// UI calculations and scene updates ------------------------------------
function setStatus(title, detail, mode = "neutral") {
statusTitle.textContent = title;
statusDetail.textContent = detail;
statusBox.className = `status ${mode}`;
}
function updateSceneConditions() {
state.tide = Number(tideSlider.value);
state.clearance = Math.max(0, Number(clearanceInput.value) || 0);
state.required = DRAFT + state.clearance;
state.depth = Math.max(0, state.tide - CRITICAL_BED);
state.margin = state.depth - state.required;
state.available = state.margin > 0.000001;
tideOutput.textContent = `+${state.tide.toFixed(2)} m`;
depthValue.textContent = `${state.depth.toFixed(2)} m`;
requiredValue.textContent = `> ${state.required.toFixed(2)} m`;
marginValue.textContent = `${state.margin >= 0 ? "+" : ""}${state.margin.toFixed(2)} m`;
marginValue.className = state.margin > 0 ? "positive" : "negative";
water.position.y = state.tide;
waterHighlights.position.y = state.tide;
boat.position.y = state.tide;
tideMarker.position.y = state.tide;
const visibleDepth = Math.max(0.001, state.tide - CRITICAL_BED);
depthColumn.visible = state.tide > CRITICAL_BED;
depthColumn.scale.y = visibleDepth;
depthColumn.position.y = CRITICAL_BED + visibleDepth * 0.5;
if (state.available) {
passagePill.className = "passage-pill available";
passageText.textContent = "Passage available";
signalMaterial.color.setHex(0x54e68d);
signalMaterial.emissive.setHex(0x2cff76);
} else {
passagePill.className = "passage-pill blocked";
passageText.textContent = "Passage blocked";
signalMaterial.color.setHex(0xff555d);
signalMaterial.emissive.setHex(0xff3038);
}
}
function resetBoat(showStatus = true) {
state.crossing = null;
state.completed = false;
state.blockedFlashUntil = 0;
boat.position.copy(HOLDING_POSITION);
boat.position.y = state.tide;
boat.rotation.set(0, 0, 0);
wake.visible = false;
holdingLabel.visible = true;
tideSlider.disabled = false;
clearanceInput.disabled = false;
departButton.disabled = false;
if (showStatus) {
setStatus(
"Vessel returned to holding",
"The vessel is outside the breakwaters and has not attempted a crossing.",
"neutral"
);
}
}
function attemptDeparture() {
if (state.crossing) return;
if (!departureTime.value) {
setStatus(
"Choose a departure time",
"Select a time before attempting departure.",
"warning"
);
return;
}
updateSceneConditions();
if (!state.available) {
state.blockedFlashUntil = performance.now() + 2800;
const actualClearance = Math.max(0, state.depth - DRAFT);
let reason;
if (state.depth <= DRAFT) {
reason =
`The entrance has ${state.depth.toFixed(2)} m, but the fixed vessel draft is ` +
`${DRAFT.toFixed(2)} m.`;
} else {
reason =
`Only ${actualClearance.toFixed(2)} m remains above the draft; ` +
`the required allowance is ${state.clearance.toFixed(2)} m.`;
}
setStatus(
`Departure blocked at ${departureTime.value}`,
`${reason} The vessel remains on hold outside the entrance; no collision or grounding animation was triggered.`,
"blocked"
);
return;
}
if (state.completed) {
resetBoat(false);
}
state.crossing = {
start: performance.now(),
duration: 9000
};
state.completed = false;
holdingLabel.visible = false;
wake.visible = true;
tideSlider.disabled = true;
clearanceInput.disabled = true;
departButton.disabled = true;
setStatus(
`Departure accepted at ${departureTime.value}`,
`Entrance depth is ${state.depth.toFixed(2)} m, exceeding draft plus allowance by ` +
`${state.margin.toFixed(2)} m. The vessel is proceeding through the marked channel.`,
"available"
);
}
tideSlider.addEventListener("input", () => {
updateSceneConditions();
if (!state.crossing) {
setStatus(
"Vessel holding outside the entrance",
state.available
? `Passage is available with ${state.margin.toFixed(2)} m above the required clearance.`
: "The selected tide does not provide the required draft plus clearance allowance.",
state.available ? "available" : "blocked"
);
}
});
clearanceInput.addEventListener("input", () => {
updateSceneConditions();
if (!state.crossing) {
setStatus(
"Vessel holding outside the entrance",
state.available
? `Passage is available with ${state.margin.toFixed(2)} m above the required clearance.`
: "The selected allowance exceeds the available water above the vessel draft.",
state.available ? "available" : "blocked"
);
}
});
departButton.addEventListener("click", attemptDeparture);
resetButton.addEventListener("click", () => resetBoat(true));
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateSceneConditions();
setStatus(
"Vessel holding outside the entrance",
"Passage is currently available. Choose a departure time, then attempt the crossing.",
"available"
);
// Animation -------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
if (state.crossing) {
const elapsed = now - state.crossing.start;
const progress = clamp(elapsed / state.crossing.duration, 0, 1);
const eased = progress * progress * (3 - 2 * progress);
const point = route.getPointAt(eased);
const tangent = route.getTangentAt(eased);
boat.position.set(point.x, state.tide, point.z);
boat.rotation.y = Math.atan2(-tangent.x, -tangent.z);
if (progress >= 1) {
state.crossing = null;
state.completed = true;
wake.visible = false;
tideSlider.disabled = false;
clearanceInput.disabled = false;
departButton.disabled = false;
setStatus(
"Crossing completed",
"The vessel is safely inside the harbor. Return it to holding to run another departure test.",
"available"
);
}
}
const pulse = 0.5 + 0.5 * Math.sin(now * 0.006);
if (state.available) {
signalMaterial.emissiveIntensity = 0.9 + pulse * 0.35;
} else if (now < state.blockedFlashUntil) {
signalMaterial.emissiveIntensity = 0.85 + pulse * 1.15;
} else {
signalMaterial.emissiveIntensity = 0.82 + pulse * 0.18;
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```