Prompt specification
Build or customize the Three.js 3D scene "Ship rising inside one canal lock" 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: Ship rising inside one canal lock
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ship-rising-inside-one-canal-lock-x2458
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a referenced early Panama Canal lock vignette with one ship and changing chamber water level. Keep the vessel floating with the water and gates closed during filling. Voxel style.
Working Three.js Starter (ship-rising-inside-one-canal-lock-x2458):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Early Panama Canal Lock — Voxel Vignette</title>
<style>
:root {
--ink: #182b2d;
--paper: rgba(244, 237, 216, 0.93);
--paper-solid: #f4edd8;
--line: rgba(24, 43, 45, 0.24);
--green: #244f48;
--gold: #c68b3d;
--blue: #31879b;
--locked: #9e4936;
--open: #3f7d59;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9bc5c7;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
cursor: grab;
touch-action: none;
}
#app canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid var(--line);
box-shadow:
0 12px 35px rgba(20, 40, 40, 0.16),
inset 0 0 0 4px rgba(255, 255, 255, 0.24);
backdrop-filter: blur(8px);
}
#title-card {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 17px 20px 16px;
border-top: 5px solid var(--green);
}
.eyebrow {
margin-bottom: 5px;
color: var(--gold);
font-family: Arial, sans-serif;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 36px);
font-weight: 600;
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: rgba(24, 43, 45, 0.72);
font-family: Arial, sans-serif;
font-size: 12px;
line-height: 1.5;
}
#readout {
top: 22px;
right: 22px;
width: 250px;
padding: 16px;
font-family: Arial, sans-serif;
}
.readout-heading {
display: flex;
justify-content: space-between;
align-items: center;
color: rgba(24, 43, 45, 0.63);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#level-value {
margin-top: 7px;
color: var(--green);
font-family: Georgia, "Times New Roman", serif;
font-size: 29px;
font-weight: 700;
letter-spacing: -0.04em;
}
.gauge {
position: relative;
height: 8px;
margin: 11px 0 14px;
overflow: visible;
background: rgba(24, 43, 45, 0.12);
border: 1px solid rgba(24, 43, 45, 0.16);
}
#level-fill {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
background: linear-gradient(90deg, #3a8ea0, #62b4b4);
transition: height 80ms linear;
}
#level-marker {
position: absolute;
bottom: 0;
left: 50%;
width: 3px;
height: 16px;
background: var(--gold);
border: 1px solid rgba(24, 43, 45, 0.35);
transform: translate(-50%, 50%);
transition: bottom 80ms linear;
}
.gate-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
align-items: center;
margin-top: 7px;
font-size: 11px;
}
.gate-state {
min-width: 68px;
padding: 4px 7px;
border: 1px solid currentColor;
color: var(--locked);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-align: center;
text-transform: uppercase;
}
.gate-state.open {
color: var(--open);
}
.gate-state.moving {
color: #a06c25;
}
#status {
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
#phase-label {
margin-bottom: 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-weight: 700;
}
#phase-detail {
color: rgba(24, 43, 45, 0.68);
font-size: 11px;
line-height: 1.45;
}
#controls {
left: 50%;
bottom: 24px;
display: flex;
gap: 8px;
padding: 8px;
transform: translateX(-50%);
font-family: Arial, sans-serif;
}
button {
min-width: 112px;
padding: 11px 14px;
border: 1px solid rgba(24, 43, 45, 0.3);
border-radius: 0;
background: transparent;
color: var(--ink);
font: 700 10px/1 Arial, sans-serif;
letter-spacing: 0.11em;
text-transform: uppercase;
cursor: pointer;
transition:
color 140ms ease,
background 140ms ease,
transform 140ms ease;
}
button:hover:not(:disabled) {
background: var(--green);
color: #fff8e6;
transform: translateY(-1px);
}
button:disabled {
cursor: default;
opacity: 0.35;
}
#fill-button {
border-color: var(--green);
}
#reset-button {
min-width: 84px;
}
#camera-hint {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 5;
padding: 8px 10px;
background: rgba(244, 237, 216, 0.75);
color: rgba(24, 43, 45, 0.7);
font: 9px/1.35 Arial, sans-serif;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #9bc5c7;
color: var(--green);
font: 700 12px/1 Arial, sans-serif;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 12px 15px;
}
.subtitle {
display: none;
}
#readout {
top: auto;
right: 12px;
bottom: 82px;
width: 210px;
padding: 12px;
}
#controls {
bottom: 12px;
width: calc(100vw - 24px);
justify-content: center;
}
button {
min-width: 0;
flex: 1;
padding: 11px 7px;
font-size: 8px;
}
#reset-button {
flex: 0 0 68px;
}
#camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header id="title-card" class="panel">
<div class="eyebrow">Steam-era engineering study · 1914</div>
<h1>Panama Canal Lock</h1>
<p class="subtitle">
A voxel vignette of an early lock chamber, with the S.S. Ancon
rising and falling with the water.
</p>
</header>
<aside id="readout" class="panel">
<div class="readout-heading">
<span>Relative lock datum</span>
<span>17.0 m lift</span>
</div>
<div id="level-value">−8.5 m</div>
<div class="gauge">
<div id="level-fill"></div>
<div id="level-marker"></div>
</div>
<div class="gate-row">
<span>Lower gates</span>
<span id="lower-gate" class="gate-state">Sealed</span>
</div>
<div class="gate-row">
<span>Upper gates</span>
<span id="upper-gate" class="gate-state">Sealed</span>
</div>
<div id="status">
<div id="phase-label">Preparing chamber</div>
<div id="phase-detail">
The gates are closed. The chamber will fill automatically.
</div>
</div>
</aside>
<nav id="controls" class="panel" aria-label="Lock controls">
<button id="fill-button">Fill chamber</button>
<button id="drain-button">Drain chamber</button>
<button id="pause-button">Pause</button>
<button id="reset-button">Reset</button>
</nav>
<div id="camera-hint">
Drag to orbit · Scroll to zoom<br>
Double-click to reset view
</div>
<div id="loading">Building the canal…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
// ------------------------------------------------------------
// Renderer and atmosphere
// ------------------------------------------------------------
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;
$("app").appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9bc5c7);
scene.fog = new THREE.Fog(0x9bc5c7, 34, 76);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xdaf2ee, 0x536343, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0c4, 3.1);
sun.position.set(-14, 24, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -26;
sun.shadow.camera.right = 26;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xa8dbe0, 0.75);
fillLight.position.set(18, 10, -15);
scene.add(fillLight);
// ------------------------------------------------------------
// Shared voxel geometry and materials
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
function box(
width,
height,
depth,
mat,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 1914;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function choose(items) {
return items[Math.floor(random() * items.length)];
}
const materials = {
earth: material(0x756a45),
earthDark: material(0x5d583b),
grass: material(0x627748),
grassLight: material(0x76864c),
masonry: [
material(0xa79f84),
material(0xb8ad8e),
material(0x958d73),
material(0xc1b596)
],
coping: material(0xc8bfa2),
darkStone: material(0x69695d),
wood: material(0x654432),
iron: material(0x343b38, { roughness: 0.58, metalness: 0.35 }),
rust: material(0x8a5033),
cream: material(0xe7dfc4),
darkCream: material(0xc6b995),
roof: material(0x38574d),
window: material(0x29444b, { roughness: 0.3, metalness: 0.12 }),
hullRed: material(0x7e382d),
hullBlack: material(0x202b2e),
deck: material(0xa88855),
trunk: material(0x66503a),
leaves: [
material(0x395f3b),
material(0x4b7040),
material(0x5f7d43),
material(0x78904b)
],
gold: material(0xc99743),
red: material(0xa64532),
cloud: material(0xe9f0df, { roughness: 1 })
};
// ------------------------------------------------------------
// Terrain and masonry lock walls
// ------------------------------------------------------------
box(74, 1.2, 64, materials.earth, 0, -3.2, 0);
// Raised tropical ground on both sides of the lock.
box(10, 2.6, 29, materials.grass, -10.5, -1.3, 0);
box(10, 2.6, 29, materials.grass, 10.5, -1.3, 0);
// Land beyond the two pools.
box(21, 2.6, 12, materials.grass, 0, -1.3, 19.5);
box(21, 2.6, 12, materials.grass, 0, -1.3, -19.5);
// Uneven voxel grass patches.
for (let i = 0; i < 36; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * (6.2 + random() * 8.2);
const z = -13.5 + random() * 27;
box(
0.8 + random() * 2.1,
0.12 + random() * 0.18,
0.8 + random() * 2.0,
choose([materials.grass, materials.grassLight, materials.earthDark]),
x,
0.08,
z
);
}
// Masonry side walls, built from offset voxel blocks.
for (const side of [-1, 1]) {
for (let row = 0; row < 11; row++) {
const z = -12 + row * 2.4;
for (let layer = 0; layer < 6; layer++) {
const y = -1.81 + layer * 0.82;
const depth = 2.28 - (row % 2) * 0.04;
box(
1.42,
0.79,
depth,
choose(materials.masonry),
side * 4.92,
y,
z
);
}
box(
1.62,
0.58,
2.30,
materials.coping,
side * 4.92,
2.98,
z
);
}
// Simple safety railing along the central chamber.
for (let z = -5.4; z <= 5.4; z += 1.8) {
box(0.11, 0.72, 0.11, materials.iron, side * 4.92, 3.63, z);
}
box(0.10, 0.10, 12.2, materials.iron, side * 4.92, 3.96, 0);
}
// Chamber floor.
box(8.35, 0.34, 12.3, materials.darkStone, 0, -2.37, 0);
// Level marks and a ladder on the far inner wall.
for (let i = 0; i < 9; i++) {
box(
0.10,
0.08,
0.58,
i % 2 === 0 ? materials.gold : materials.cream,
-4.17,
-1.55 + i * 0.52,
2.35
);
}
box(0.10, 3.3, 0.09, materials.gold, -4.12, 0.45, 2.10);
box(0.10, 3.3, 0.09, materials.gold, -4.12, 0.45, 2.60);
for (let y = -1.0; y <= 2.0; y += 0.45) {
box(0.10, 0.08, 0.55, materials.gold, -4.12, y, 2.35);
}
// ------------------------------------------------------------
// Voxel water surfaces
// ------------------------------------------------------------
function createWater(width, length, columns, rows) {
const group = new THREE.Group();
scene.add(group);
const bodyMaterial = material(0x318fa3, {
transparent: true,
opacity: 0.58,
roughness: 0.25,
depthWrite: false
});
const body = new THREE.Mesh(unitBox, bodyMaterial);
body.scale.set(width, 0.32, length);
body.position.y = -0.18;
body.castShadow = false;
body.receiveShadow = false;
body.renderOrder = 1;
group.add(body);
const tileMaterial = material(0xffffff, {
transparent: true,
opacity: 0.78,
roughness: 0.28,
depthWrite: false
});
const tileMesh = new THREE.InstancedMesh(
unitBox,
tileMaterial,
columns * rows
);
tileMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
tileMesh.castShadow = false;
tileMesh.receiveShadow = true;
tileMesh.renderOrder = 2;
group.add(tileMesh);
const tileWidth = width / columns;
const tileLength = length / rows;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = -width / 2 + (column + 0.5) * tileWidth;
const z = -length / 2 + (row + 0.5) * tileLength;
dummy.position.set(x, 0, z);
dummy.scale.set(tileWidth * 0.91, 0.055, tileLength * 0.91);
dummy.updateMatrix();
tileMesh.setMatrixAt(index, dummy.matrix);
color.setHSL(
0.51 + random() * 0.025,
0.36 + random() * 0.12,
0.44 + random() * 0.10
);
tileMesh.setColorAt(index, color);
index++;
}
}
tileMesh.instanceColor.needsUpdate = true;
function update(time) {
let i = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = -width / 2 + (column + 0.5) * tileWidth;
const z = -length / 2 + (row + 0.5) * tileLength;
dummy.position.set(
x,
Math.sin(time * 1.3 + column * 0.72 + row * 0.38) * 0.024,
z
);
dummy.scale.set(
tileWidth * 0.91,
0.055,
tileLength * 0.91
);
dummy.updateMatrix();
tileMesh.setMatrixAt(i, dummy.matrix);
i++;
}
}
tileMesh.instanceMatrix.needsUpdate = true;
}
return { group, update };
}
const LOW_LEVEL = -1.15;
const HIGH_LEVEL = 1.65;
const chamberWater = createWater(8.25, 12.25, 10, 15);
chamberWater.group.position.y = LOW_LEVEL;
const lowerPool = createWater(8.25, 6.45, 10, 8);
lowerPool.group.position.set(0, LOW_LEVEL, -9.65);
const upperPool = createWater(8.25, 6.45, 10, 8);
upperPool.group.position.set(0, HIGH_LEVEL, 9.65);
// ------------------------------------------------------------
// Miter gates
// ------------------------------------------------------------
function createGate(z, swingDirection) {
const root = new THREE.Group();
root.position.z = z;
scene.add(root);
function createLeaf(hingeX, direction) {
const leaf = new THREE.Group();
leaf.position.x = hingeX;
root.add(leaf);
box(
4.02,
4.48,
0.25,
materials.wood,
direction * 2.01,
0.35,
0,
leaf
);
for (let i = 0; i < 5; i++) {
box(
0.19,
4.74,
0.47,
materials.iron,
direction * (0.36 + i * 0.82),
0.35,
0,
leaf
);
}
for (const y of [-1.55, -0.35, 0.85, 2.18]) {
box(
4.18,
0.18,
0.52,
materials.iron,
direction * 2.01,
y,
0,
leaf
);
}
box(
0.24,
0.36,
0.66,
materials.rust,
direction * 3.87,
0.35,
0,
leaf
);
return leaf;
}
const left = createLeaf(-4.16, 1);
const right = createLeaf(4.16, -1);
function setOpen(amount) {
left.rotation.y =
-swingDirection * Math.PI * 0.5 * amount;
right.rotation.y =
swingDirection * Math.PI * 0.5 * amount;
}
setOpen(0);
return { root, left, right, setOpen };
}
const lowerGate = createGate(-6.25, 1);
const upperGate = createGate(6.25, -1);
// Abutments emphasize the gate structures.
for (const side of [-1, 1]) {
box(2.4, 5.4, 2.1, materials.darkStone, side * 5.1, 0.55, -6.25);
box(2.4, 5.4, 2.1, materials.darkStone, side * 5.1, 0.55, 6.25);
}
// ------------------------------------------------------------
// Lock furniture, keeper's house, and lamps
// ------------------------------------------------------------
for (const side of [-1, 1]) {
for (const z of [-4.5, 0, 4.5]) {
box(
0.15,
1.65,
0.15,
materials.iron,
side * 4.92,
4.10,
z
);
box(
0.48,
0.42,
0.48,
materials.cream,
side * 4.92,
5.00,
z
);
box(
0.52,
0.08,
0.52,
materials.roof,
side * 4.92,
5.24,
z
);
}
}
// Small lockkeeper's house.
const house = new THREE.Group();
house.position.set(7.6, 0, -3.7);
scene.add(house);
box(2.5, 2.15, 2.4, materials.cream, 0, 1.075, 0, house);
box(2.8, 0.24, 2.7, materials.roof, 0, 2.27, 0, house);
box(2.25, 0.20, 2.15, materials.roof, 0, 2.48, 0, house);
// Side facing the camera.
box(0.08, 0.62, 0.55, materials.window, 1.29, 1.40, 0.42, house);
box(0.08, 0.62, 0.55, materials.window, 1.29, 1.40, -0.45, house);
box(0.08, 1.35, 0.58, materials.wood, 1.29, 0.68, -0.02, house);
// Sign and small chimney.
box(0.10, 0.30, 1.15, materials.gold, 1.35, 2.05, 0, house);
box(0.46, 0.78, 0.46, materials.rust, -0.5, 2.65, -0.45, house);
// ------------------------------------------------------------
// Tropical voxel vegetation
// ------------------------------------------------------------
function addTree(x, z, scale = 1) {
const trunkHeight = 2.5 * scale;
box(
0.43 * scale,
trunkHeight,
0.43 * scale,
materials.trunk,
x,
trunkHeight / 2,
z
);
box(
1.85 * scale,
1.45 * scale,
1.75 * scale,
choose(materials.leaves),
x,
trunkHeight + 0.42 * scale,
z
);
box(
1.35 * scale,
1.15 * scale,
1.40 * scale,
choose(materials.leaves),
x - 0.48 * scale,
trunkHeight + 1.02 * scale,
z + 0.28 * scale
);
box(
1.10 * scale,
1.10 * scale,
1.05 * scale,
choose(materials.leaves),
x + 0.58 * scale,
trunkHeight + 0.70 * scale,
z - 0.24 * scale
);
}
for (let i = 0; i < 27; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * (6.15 + random() * 8.0);
const z = -13 + random() * 26;
// Keep the keeper's house visible.
if (side > 0 && x < 9.3 && z > -6 && z < -1) {
continue;
}
addTree(x, z, 0.72 + random() * 0.65);
}
// Low shrubs and rocks.
for (let i = 0; i < 38; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * (5.9 + random() * 8.5);
const z = -13 + random() * 26;
if (random() > 0.45) {
box(
0.7 + random(),
0.45 + random() * 0.6,
0.7 + random(),
choose(materials.leaves),
x,
0.25,
z
);
} else {
box(
0.6 + random() * 0.8,
0.4 + random() * 0.5,
0.6 + random() * 0.8,
choose([materials.darkStone, materials.earthDark]),
x,
0.2,
z
);
}
}
// Blocky clouds.
function addCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
scene.add(cloud);
const pieces = [
[-1.4, 0, 0, 2.2, 0.75, 1.1],
[0, 0.25, 0, 2.8, 1.1, 1.4],
[1.5, 0, 0.1, 1.8, 0.7, 1.0],
[0.2, -0.38, 0.2, 3.4, 0.55, 1.3]
];
for (const p of pieces) {
const mesh = box(
p[3] * scale,
p[4] * scale,
p[5] * scale,
materials.cloud,
p[0] * scale,
p[1] * scale,
p[2] * scale,
cloud
);
mesh.castShadow = false;
mesh.receiveShadow = false;
}
}
addCloud(-11, 10.7, -13, 1.1);
addCloud(10, 12.2, 4, 0.8);
addCloud(2, 11.4, 18, 1.2);
// ------------------------------------------------------------
// Steam-era cargo ship, entirely constructed from voxel blocks
// ------------------------------------------------------------
const ship = new THREE.Group();
scene.add(ship);
// Lower hull, black upper hull, and timber deck.
box(2.55, 0.48, 4.55, materials.hullRed, 0, -0.43, 0, ship);
box(2.78, 0.48, 4.35, materials.hullBlack, 0, -0.08, 0, ship);
box(2.68, 0.16, 4.22, materials.deck, 0, 0.24, 0, ship);
// Tapered bow and stern.
box(2.18, 0.55, 0.95, materials.hullBlack, 0, -0.11, 2.35, ship);
box(1.28, 0.49, 0.58, materials.hullBlack, 0, -0.15, 2.90, ship);
box(2.30, 0.55, 0.82, materials.hullBlack, 0, -0.10, -2.37, ship);
box(1.42, 0.50, 0.50, materials.hullBlack, 0, -0.14, -2.86, ship);
// Cream superstructure.
box(2.05, 0.76, 2.12, materials.cream, 0, 0.70, -0.72, ship);
box(1.42, 0.66, 1.30, materials.cream, 0, 1.39, -0.55, ship);
box(1.70, 0.16, 1.55, materials.roof, 0, 1.80, -0.55, ship);
// Windows.
box(0.08, 0.34, 0.44, materials.window, 0.74, 1.47, -0.36, ship);
box(0.08, 0.34, 0.44, materials.window, 0.74, 1.47, -0.78, ship);
box(0.08, 0.34, 0.44, materials.window, -0.74, 1.47, -0.36, ship);
box(0.08, 0.34, 0.44, materials.window, -0.74, 1.47, -0.78, ship);
box(0.95, 0.34, 0.08, materials.window, 0, 1.47, 0.13, ship);
// Brick-red funnel with black cap.
box(0.58, 1.62, 0.60, materials.rust, 0, 1.53, -1.62, ship);
box(0.64, 0.28, 0.66, materials.hullBlack, 0, 2.43, -1.62, ship);
// Deck cargo.
box(0.82, 0.62, 0.88, materials.wood, -0.60, 0.62, 1.16, ship);
box(0.72, 0.52, 0.78, materials.darkCream, 0.45, 0.57, 1.08, ship);
box(0.65, 0.46, 0.65, materials.wood, 0.52, 1.03, 1.10, ship);
// Mast and yard.
box(0.10, 2.45, 0.10, materials.iron, 0, 1.58, 0.52, ship);
box(1.55, 0.08, 0.08, materials.iron, 0, 2.42, 0.52, ship);
box(0.06, 0.42, 0.06, materials.gold, 0.25, 2.32, 0.52, ship);
// Small red pennant.
box(0.52, 0.22, 0.045, materials.red, 0.28, 2.77, 0.52, ship);
// Railings around the cargo deck.
for (const side of [-1, 1]) {
for (let z = 0.05; z <= 2.2; z += 0.45) {
box(
0.055,
0.38,
0.055,
materials.cream,
side * 1.29,
0.48,
z,
ship
);
}
box(
0.055,
0.055,
2.45,
materials.cream,
side * 1.29,
0.67,
1.14,
ship
);
}
// Ship name plaque.
box(0.04, 0.18, 0.95, materials.gold, 1.405, 0.03, 0.15, ship);
// ------------------------------------------------------------
// Lock operating state
// ------------------------------------------------------------
const state = {
phase: "idle",
nextPhase: null,
phaseElapsed: 0,
level: LOW_LEVEL,
levelStart: LOW_LEVEL,
levelEnd: LOW_LEVEL,
levelDuration: 7,
lowerGate: 0,
upperGate: 0,
lowerTarget: 0,
upperTarget: 0,
paused: false
};
function smoothStep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function setStatus(label, detail) {
$("phase-label").textContent = label;
$("phase-detail").textContent = detail;
}
function beginClosing(nextPhase) {
state.phase = "closingGates";
state.nextPhase = nextPhase;
state.phaseElapsed = 0;
state.lowerTarget = 0;
state.upperTarget = 0;
setStatus(
"Seating the miter gates",
"Both gates are closed before any water is allowed to move."
);
}
function beginLevelChange(direction) {
state.levelStart = state.level;
state.phaseElapsed = 0;
if (direction === "filling") {
state.levelEnd = HIGH_LEVEL;
state.levelDuration = 7;
state.phase = "filling";
setStatus(
"Filling the chamber",
"Upper and lower gates are sealed. The ship rises with the water."
);
} else {
state.levelEnd = LOW_LEVEL;
state.levelDuration = 8;
state.phase = "draining";
setStatus(
"Draining the chamber",
"Both gates remain sealed while the chamber and ship descend."
);
}
}
function updateGateReadout() {
function gateLabel(amount, target) {
if (amount < 0.025) return ["Sealed", ""];
if (amount > 0.975) return ["Open", "open"];
return ["Moving", "moving"];
}
const lower = gateLabel(state.lowerGate, state.lowerTarget);
const upper = gateLabel(state.upperGate, state.upperTarget);
$("lower-gate").textContent = lower[0];
$("lower-gate").className = `gate-state ${lower[1]}`;
$("upper-gate").textContent = upper[0];
$("upper-gate").className = `gate-state ${upper[1]}`;
}
function updateLevelReadout() {
const normalized =
(state.level - LOW_LEVEL) / (HIGH_LEVEL - LOW_LEVEL);
const meters = -8.5 + normalized * 17.0;
const sign = meters >= 0 ? "+" : "−";
const value = Math.abs(meters).toFixed(1);
$("level-value").textContent = `${sign}${value} m`;
$("level-fill").style.height = `${normalized * 100}%`;
$("level-marker").style.bottom = `${normalized * 100}%`;
}
function updateControls() {
const busy = [
"closingGates",
"filling",
"draining",
"openingUpper",
"openingLower"
].includes(state.phase);
$("fill-button").disabled =
busy || state.phase === "high";
$("drain-button").disabled =
busy || state.phase === "low";
$("pause-button").textContent =
state.paused ? "Resume" : "Pause";
}
function updateSimulation(dt) {
if (state.paused) return;
state.phaseElapsed += dt;
// Gates move toward their current targets.
const gateEase = 1 - Math.exp(-dt * 3.4);
state.lowerGate +=
(state.lowerTarget - state.lowerGate) * gateEase;
state.upperGate +=
(state.upperTarget - state.upperGate) * gateEase;
lowerGate.setOpen(state.lowerGate);
upperGate.setOpen(state.upperGate);
switch (state.phase) {
case "idle":
if (state.phaseElapsed > 1.6) {
beginClosing("filling");
}
break;
case "closingGates":
// The chamber cannot change level until both leaves are shut.
if (
state.lowerGate < 0.012 &&
state.upperGate < 0.012
) {
if (state.nextPhase === "filling") {
beginLevelChange("filling");
} else if (state.nextPhase === "draining") {
beginLevelChange("draining");
}
}
break;
case "filling": {
const progress = state.phaseElapsed / state.levelDuration;
state.level = THREE.MathUtils.lerp(
state.levelStart,
state.levelEnd,
smoothStep(progress)
);
if (progress >= 1) {
state.level = HIGH_LEVEL;
state.phase = "openingUpper";
state.phaseElapsed = 0;
state.upperTarget = 1;
setStatus(
"Upper pool reached",
"The chamber is full. The upper miter gates can now be opened."
);
}
break;
}
case "openingUpper":
if (state.upperGate > 0.985) {
state.phase = "high";
state.phaseElapsed = 0;
setStatus(
"Chamber at upper level",
"The ship is floating level with the upper pool. Drain to begin another cycle."
);
}
break;
case "high":
break;
case "draining": {
const progress = state.phaseElapsed / state.levelDuration;
state.level = THREE.MathUtils.lerp(
state.levelStart,
state.levelEnd,
smoothStep(progress)
);
if (progress >= 1) {
state.level = LOW_LEVEL;
state.phase = "openingLower";
state.phaseElapsed = 0;
state.lowerTarget = 1;
setStatus(
"Lower pool reached",
"The chamber is empty. Opening the lower gates to the lower pool."
);
}
break;
}
case "openingLower":
if (state.lowerGate > 0.985) {
state.phase = "low";
state.phaseElapsed = 0;
setStatus(
"Chamber at lower level",
"The lower pool is ready. Fill the chamber to raise the ship."
);
}
break;
case "low":
break;
}
updateGateReadout();
updateLevelReadout();
updateControls();
}
// ------------------------------------------------------------
// Custom orbit controls — no external controls addon
// ------------------------------------------------------------
const cameraState = {
radius: 31,
theta: 0.70,
phi: 1.02,
target: new THREE.Vector3(0, 0.15, 0)
};
function updateCamera() {
const portraitMultiplier =
window.innerWidth / window.innerHeight < 0.8 ? 1.38 : 1;
const radius = cameraState.radius * portraitMultiplier;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
radius * Math.cos(cameraState.phi),
cameraState.target.z +
radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.radius = 31;
cameraState.theta = 0.70;
cameraState.phi = 1.02;
cameraState.target.set(0, 0.15, 0);
updateCamera();
}
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;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.38
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
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 * Math.exp(event.deltaY * 0.001),
20,
48
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", (e) => e.preventDefault());
// ------------------------------------------------------------
// UI controls
// ------------------------------------------------------------
$("fill-button").addEventListener("click", () => {
if (!$("fill-button").disabled) {
beginClosing("filling");
}
});
$("drain-button").addEventListener("click", () => {
if (!$("drain-button").disabled) {
beginClosing("draining");
}
});
$("pause-button").addEventListener("click", () => {
state.paused = !state.paused;
updateControls();
if (state.paused) {
setStatus(
"Simulation paused",
"The camera remains available. Resume to continue the lock cycle."
);
}
});
$("reset-button").addEventListener("click", () => {
state.phase = "idle";
state.nextPhase = null;
state.phaseElapsed = 0;
state.level = LOW_LEVEL;
state.levelStart = LOW_LEVEL;
state.levelEnd = LOW_LEVEL;
state.lowerGate = 0;
state.upperGate = 0;
state.lowerTarget = 0;
state.upperTarget = 0;
state.paused = false;
lowerGate.setOpen(0);
upperGate.setOpen(0);
setStatus(
"Preparing chamber",
"The gates are closed. The chamber will fill automatically."
);
updateGateReadout();
updateLevelReadout();
updateControls();
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateSimulation(dt);
chamberWater.group.position.y = state.level;
chamberWater.update(time);
lowerPool.update(time);
upperPool.update(time);
// The vessel's vertical position is tied directly to the
// chamber water surface, with only a tiny floating bob.
ship.position.y =
state.level + 0.015 + Math.sin(time * 1.25) * 0.022;
ship.rotation.x = Math.sin(time * 0.78) * 0.006;
ship.rotation.z = Math.cos(time * 0.66) * 0.004;
renderer.render(scene, camera);
});
updateCamera();
updateGateReadout();
updateLevelReadout();
updateControls();
requestAnimationFrame(() => {
$("loading").classList.add("hidden");
});
</script>
</body>
</html>
```