Prompt specification
Build or customize the Three.js 3D scene "Baltic port hoist lifting a barrel" 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: Baltic port hoist lifting a barrel
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/baltic-port-hoist-lifting-a-barrel-x2354
Scene Description Prompt:
I'd like to see this as a cutaway Three.js scene: Baltic port hoist lifting a barrel. Create a referenced late medieval port vignette with quay, barrel, and warehouse hoist. Animate one vertical lift into a clear opening without intersecting the facade. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (baltic-port-hoist-lifting-a-barrel-x2354):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Baltic Port Warehouse Hoist</title>
<style>
:root {
color-scheme: dark;
--paper: #eee4cd;
--ink: #171b19;
--amber: #d6a85f;
--panel: rgba(21, 27, 25, 0.86);
--line: rgba(238, 228, 205, 0.22);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aab5b3;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
position: absolute;
top: 20px;
left: 20px;
width: min(430px, calc(100vw - 40px));
padding: 17px 19px 16px;
border-radius: 4px;
}
.eyebrow {
margin-bottom: 6px;
color: var(--amber);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--paper);
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 3vw, 34px);
font-weight: 500;
line-height: 1.05;
}
.subtitle {
margin: 8px 0 0;
color: rgba(238, 228, 205, 0.72);
font-size: 12px;
line-height: 1.45;
}
#controls {
position: absolute;
top: 20px;
right: 20px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: min(460px, calc(100vw - 40px));
pointer-events: auto;
}
button {
min-height: 36px;
padding: 8px 12px;
border: 1px solid rgba(238, 228, 205, 0.25);
border-radius: 3px;
background: rgba(21, 27, 25, 0.88);
color: var(--paper);
font: 600 11px/1 system-ui, sans-serif;
letter-spacing: 0.04em;
cursor: pointer;
backdrop-filter: blur(10px);
transition: background 140ms ease, border-color 140ms ease;
}
button:hover,
button:focus-visible {
border-color: var(--amber);
background: rgba(55, 48, 34, 0.95);
outline: none;
}
button.active {
color: #201b13;
border-color: var(--amber);
background: var(--amber);
}
#reference {
position: absolute;
left: 20px;
bottom: 20px;
width: min(370px, calc(100vw - 40px));
border-radius: 4px;
overflow: hidden;
pointer-events: auto;
}
#reference summary {
padding: 11px 14px;
color: var(--paper);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
user-select: none;
}
#reference .body {
padding: 0 14px 14px;
color: rgba(238, 228, 205, 0.72);
font-size: 11px;
line-height: 1.55;
}
#reference ul {
margin: 0 0 10px;
padding-left: 17px;
}
#reference .note {
color: rgba(238, 228, 205, 0.52);
font-style: italic;
}
#status {
position: absolute;
right: 20px;
bottom: 20px;
width: min(350px, calc(100vw - 40px));
padding: 12px 14px;
border-radius: 4px;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
color: var(--paper);
font-size: 11px;
}
#status-detail {
color: rgba(238, 228, 205, 0.58);
font-size: 10px;
text-align: right;
}
#progress-track {
height: 3px;
margin-top: 9px;
overflow: hidden;
background: rgba(238, 228, 205, 0.16);
}
#progress-fill {
width: 0%;
height: 100%;
background: var(--amber);
transition: width 80ms linear;
}
#hint {
position: absolute;
left: 50%;
bottom: 19px;
transform: translateX(-50%);
color: rgba(255, 255, 255, 0.75);
font-size: 10px;
letter-spacing: 0.08em;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.75);
white-space: nowrap;
}
#opening-tag {
position: absolute;
display: none;
transform: translate(12px, -50%);
padding: 5px 8px;
border-left: 2px solid var(--amber);
background: rgba(20, 24, 21, 0.78);
color: var(--paper);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #aab5b3;
color: #29312e;
font-family: Georgia, serif;
font-size: 18px;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
#controls {
top: 132px;
left: 12px;
right: 12px;
justify-content: flex-start;
max-width: none;
}
#reference {
display: none;
}
#status {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the quay…</div>
<div id="hud">
<section id="title-card" class="panel">
<div class="eyebrow">Interpretive Baltic port · c. 1400–1500</div>
<h1>Warehouse Hoist</h1>
<p class="subtitle">
A coopered barrel rises on a fixed timber headstock and rope sling,
guided through the open loading bay of a late-medieval Hanseatic warehouse.
</p>
</section>
<nav id="controls" aria-label="Scene controls">
<button id="pause" type="button">Pause lift</button>
<button id="replay" type="button">Replay lift</button>
<button id="guide" type="button" aria-pressed="false">Clearance guide</button>
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button id="reset" type="button">Reset view</button>
</nav>
<details id="reference" class="panel">
<summary>Reference notes</summary>
<div class="body">
<ul>
<li>Timber post-and-beam warehouse with plank infill and broad gabled roof.</li>
<li>Fixed headstock, iron sheave, hemp rope, four-leg sling, and oak cooperage.</li>
<li>Clear central loading bay keeps the barrel’s vertical path outside solid wall geometry.</li>
</ul>
<div class="note">
This is a scene-based historical reconstruction rather than a surveyed monument.
</div>
</div>
</details>
<section id="status" class="panel" aria-live="polite">
<div class="status-row">
<span id="status-text">Preparing the lift</span>
<span id="status-detail">One vertical lift</span>
</div>
<div id="progress-track"><div id="progress-fill"></div></div>
</section>
<div id="hint">Drag to orbit · wheel or buttons to zoom · arrow keys to rotate</div>
<div id="opening-tag">CLEAR LOADING BAY</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const statusText = document.getElementById("status-text");
const statusDetail = document.getElementById("status-detail");
const progressFill = document.getElementById("progress-fill");
const pauseButton = document.getElementById("pause");
const guideButton = document.getElementById("guide");
const openingTag = document.getElementById("opening-tag");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaab6b4);
scene.fog = new THREE.Fog(0xaab6b4, 27, 62);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 120);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive Three.js reconstruction of a medieval Baltic warehouse hoist");
document.body.prepend(renderer.domElement);
const maxAnisotropy = renderer.capabilities.getMaxAnisotropy();
let randomSeed = 827341;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function canvasTexture(size, draw) {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = size;
draw(canvas.getContext("2d"), size);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = maxAnisotropy;
return texture;
}
const cobbleTexture = canvasTexture(512, (ctx, size) => {
ctx.fillStyle = "#4c514d";
ctx.fillRect(0, 0, size, size);
const rows = 10;
const cell = size / rows;
for (let row = -1; row < rows + 1; row++) {
const offset = row % 2 ? cell * 0.5 : 0;
for (let col = -1; col < rows + 1; col++) {
const x = col * cell + offset + 2;
const y = row * cell + 2;
const w = cell - 4 - random() * 7;
const h = cell - 4 - random() * 5;
const shade = 78 + Math.floor(random() * 37);
ctx.fillStyle = `rgb(${shade + 5},${shade + 4},${shade})`;
ctx.beginPath();
ctx.roundRect(x, y, w, h, 4 + random() * 3);
ctx.fill();
ctx.strokeStyle = "rgba(225,220,200,.08)";
ctx.stroke();
}
}
});
cobbleTexture.repeat.set(7, 6);
const woodTexture = canvasTexture(512, (ctx, size) => {
ctx.fillStyle = "#80603f";
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 210; i++) {
const x = random() * size;
const width = 0.5 + random() * 2.4;
const alpha = 0.035 + random() * 0.13;
ctx.strokeStyle = `rgba(30,18,9,${alpha})`;
ctx.lineWidth = width;
ctx.beginPath();
ctx.moveTo(x, 0);
for (let y = 0; y <= size; y += 24) {
ctx.lineTo(x + Math.sin(y * 0.027 + i) * (2 + random() * 4), y);
}
ctx.stroke();
}
for (let i = 0; i < 18; i++) {
const x = random() * size;
const y = random() * size;
ctx.strokeStyle = "rgba(255,225,175,.08)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.ellipse(x, y, 3 + random() * 6, 14 + random() * 20, 0, 0, Math.PI * 2);
ctx.stroke();
}
});
woodTexture.repeat.set(2, 3);
const waterTexture = canvasTexture(512, (ctx, size) => {
ctx.fillStyle = "#58797c";
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 180; i++) {
const y = random() * size;
const x = random() * size;
const length = 12 + random() * 65;
ctx.strokeStyle = random() > 0.5
? "rgba(212,232,226,.13)"
: "rgba(18,48,54,.16)";
ctx.lineWidth = 1 + random() * 2;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.quadraticCurveTo(x + length * 0.5, y - 2, x + length, y);
ctx.stroke();
}
});
waterTexture.repeat.set(8, 8);
const materials = {
wood: new THREE.MeshStandardMaterial({
color: 0xb28a59, map: woodTexture, roughness: 0.88
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x584331, map: woodTexture, roughness: 0.93
}),
beam: new THREE.MeshStandardMaterial({
color: 0x4b3828, map: woodTexture, roughness: 0.92
}),
roof: new THREE.MeshStandardMaterial({
color: 0x493f38, map: woodTexture, roughness: 0.9
}),
stone: new THREE.MeshStandardMaterial({
color: 0x777971, roughness: 0.98
}),
iron: new THREE.MeshStandardMaterial({
color: 0x272c2b, metalness: 0.78, roughness: 0.5
}),
rope: new THREE.MeshStandardMaterial({
color: 0x9b8053, roughness: 1
}),
barrel: new THREE.MeshStandardMaterial({
color: 0x9b6a38, map: woodTexture, roughness: 0.85
}),
dark: new THREE.MeshStandardMaterial({
color: 0x141a18, roughness: 1
}),
clothRed: new THREE.MeshStandardMaterial({
color: 0x754039, roughness: 0.98
}),
clothBlue: new THREE.MeshStandardMaterial({
color: 0x455d62, roughness: 0.98
}),
skin: new THREE.MeshStandardMaterial({
color: 0xb68d6d, roughness: 0.92
}),
sack: new THREE.MeshStandardMaterial({
color: 0x998467, roughness: 1
})
};
const hemi = new THREE.HemisphereLight(0xd9e4e1, 0x51483b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0ad, 3.4);
sun.position.set(-12, 20, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8c9d0, 0.75);
fill.position.set(12, 8, -8);
scene.add(fill);
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function beamBetween(a, b, width, depth, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, depth),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function orientCylinder(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.clone().normalize());
mesh.scale.set(1, length, 1);
}
function cylinderBetween(radius, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 8),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Baltic water and the raised stone quay.
const water = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
new THREE.MeshStandardMaterial({
color: 0x6d9293,
map: waterTexture,
roughness: 0.28,
metalness: 0.12,
transparent: true,
opacity: 0.9
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.68;
water.receiveShadow = true;
scene.add(water);
box(24, 1.1, 22, materials.stone, 0, -0.55, -0.5);
const cobbles = new THREE.Mesh(
new THREE.PlaneGeometry(24, 22),
new THREE.MeshStandardMaterial({
color: 0xa4a197,
map: cobbleTexture,
roughness: 0.98
})
);
cobbles.rotation.x = -Math.PI / 2;
cobbles.position.set(0, 0.015, -0.5);
cobbles.receiveShadow = true;
scene.add(cobbles);
// Warehouse shell. The central bay is intentionally left open.
box(12.3, 0.38, 6.1, materials.stone, 0, 0.18, -7.2);
box(12, 7.8, 0.28, materials.darkWood, 0, 3.95, -10.05);
box(0.28, 7.8, 5.9, materials.darkWood, -6, 3.95, -7.15);
box(0.28, 7.8, 5.9, materials.darkWood, 6, 3.95, -7.15);
const interior = new THREE.Mesh(
new THREE.PlaneGeometry(11.8, 7.7),
new THREE.MeshStandardMaterial({ color: 0x111714, roughness: 1 })
);
interior.position.set(0, 3.9, -9.88);
scene.add(interior);
// Facade planks, leaving x = -1.6..1.6 and y = 0..6.1 clear.
for (const side of [-1, 1]) {
for (let i = 0; i < 10; i++) {
const x = side * (1.84 + i * 0.43);
box(0.39, 7.8, 0.28, materials.wood, x, 3.95, -4.2);
}
box(4.4, 0.18, 0.38, materials.beam, side * 3.8, 1.05, -3.99);
box(4.4, 0.18, 0.38, materials.beam, side * 3.8, 3.55, -3.99);
box(4.4, 0.18, 0.38, materials.beam, side * 3.8, 5.82, -3.99);
beamBetween(
new THREE.Vector3(side * 1.82, 0.45, -3.98),
new THREE.Vector3(side * 5.75, 3.45, -3.98),
0.17, 0.2, materials.beam
);
beamBetween(
new THREE.Vector3(side * 1.82, 3.65, -3.98),
new THREE.Vector3(side * 5.75, 5.7, -3.98),
0.14, 0.18, materials.beam
);
}
box(3.2, 1.9, 0.28, materials.wood, 0, 7.05, -4.2);
box(0.24, 6.2, 0.42, materials.beam, -1.62, 3.1, -3.98);
box(0.24, 6.2, 0.42, materials.beam, 1.62, 3.1, -3.98);
box(3.48, 0.25, 0.44, materials.beam, 0, 6.12, -3.98);
// Gable and broad pitched roof.
const gableShape = new THREE.Shape();
gableShape.moveTo(-6.05, 8);
gableShape.lineTo(0, 9.48);
gableShape.lineTo(6.05, 8);
gableShape.closePath();
const gable = new THREE.Mesh(
new THREE.ExtrudeGeometry(gableShape, {
depth: 0.3,
bevelEnabled: false
}),
materials.darkWood
);
gable.position.z = -4.35;
gable.castShadow = true;
gable.receiveShadow = true;
scene.add(gable);
const roofAngle = Math.atan2(1.65, 6.4);
const roofLength = Math.hypot(6.4, 1.65);
const roofRight = box(roofLength, 0.25, 6.45, materials.roof, 3.2, 8.52, -7.05);
roofRight.rotation.z = -roofAngle;
const roofLeft = box(roofLength, 0.25, 6.45, materials.roof, -3.2, 8.52, -7.05);
roofLeft.rotation.z = roofAngle;
// Stone footings only beside the open loading bay.
for (const side of [-1, 1]) {
for (let i = 0; i < 8; i++) {
box(0.5, 0.36, 0.48, materials.stone,
side * (1.95 + i * 0.53), 0.2, -3.98);
}
}
// Loading threshold sits in front of the open bay.
box(3.25, 0.22, 1.35, materials.stone, 0, 0.11, -3.7);
// Interior ladder, set behind the vertical lifting corridor.
for (const x of [1.05, 1.55]) {
box(0.09, 5.8, 0.09, materials.beam, x, 2.95, -6.1);
}
for (let y = 0.4; y < 5.8; y += 0.48) {
box(0.58, 0.075, 0.09, materials.beam, 1.3, y, -6.08);
}
// Fixed warehouse hoist.
box(4.15, 0.3, 0.48, materials.beam, 0, 6.35, -3.86);
beamBetween(
new THREE.Vector3(-1.95, 7.55, -3.98),
new THREE.Vector3(-1.45, 6.38, -3.8),
0.2, 0.22, materials.beam
);
beamBetween(
new THREE.Vector3(1.95, 7.55, -3.98),
new THREE.Vector3(1.45, 6.38, -3.8),
0.2, 0.22, materials.beam
);
const wheel = new THREE.Group();
wheel.position.set(0, 5.9, -3.49);
scene.add(wheel);
const pulley = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.06, 10, 36),
materials.iron
);
pulley.castShadow = true;
wheel.add(pulley);
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.52, 12),
materials.iron
);
axle.rotation.x = Math.PI / 2;
axle.castShadow = true;
wheel.add(axle);
box(0.08, 0.08, 0.2, materials.iron, 0.25, 0, 0, wheel);
const drumRotor = new THREE.Group();
drumRotor.position.set(2.45, 6.02, -3.58);
scene.add(drumRotor);
const drum = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.64, 16),
materials.darkWood
);
drum.rotation.z = Math.PI / 2;
drum.castShadow = true;
drumRotor.add(drum);
const crank = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.025, 8, 20),
materials.iron
);
crank.rotation.y = Math.PI / 2;
crank.position.x = 0.38;
crankRotorVisible(crank);
drumRotor.add(crank);
function crankRotorVisible(mesh) {
mesh.castShadow = true;
}
const winchRope = cylinderBetween(0.018, materials.rope);
orientCylinder(
winchRope,
new THREE.Vector3(2.12, 6.02, -3.51),
new THREE.Vector3(0.24, 6.18, -3.49)
);
// The coopered barrel.
const barrelRig = new THREE.Group();
barrelRig.position.set(0, 0.94, -3.48);
scene.add(barrelRig);
const profile = [
new THREE.Vector2(0.52, -0.68),
new THREE.Vector2(0.61, -0.42),
new THREE.Vector2(0.67, 0),
new THREE.Vector2(0.61, 0.42),
new THREE.Vector2(0.52, 0.68)
];
const barrelBody = new THREE.Mesh(
new THREE.LatheGeometry(profile, 36),
materials.barrel
);
barrelBody.castShadow = true;
barrelBody.receiveShadow = true;
barrelRig.add(barrelBody);
const seamMaterial = new THREE.LineBasicMaterial({
color: 0x4b301d,
transparent: true,
opacity: 0.65
});
for (let i = 0; i < 14; i++) {
const angle = (i / 14) * Math.PI * 2;
const points = [];
for (const p of profile) {
points.push(new THREE.Vector3(
Math.cos(angle) * (p.x + 0.006),
p.y,
Math.sin(angle) * (p.x + 0.006)
));
}
const seam = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
seamMaterial
);
barrelRig.add(seam);
}
for (const y of [-0.55, -0.31, 0.25, 0.55]) {
const radius = 0.535 + 0.13 * (1 - Math.abs(y) / 0.7);
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.035, 8, 32),
materials.iron
);
hoop.rotation.x = Math.PI / 2;
hoop.position.y = y;
hoop.castShadow = true;
barrelRig.add(hoop);
}
const barrelTop = new THREE.Mesh(
new THREE.CylinderGeometry(0.53, 0.53, 0.045, 24),
materials.darkWood
);
barrelTop.position.y = 0.69;
barrelTop.castShadow = true;
barrelRig.add(barrelTop);
const bung = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.085, 0.02, 12),
materials.darkWood
);
bung.position.set(0.15, 0.725, 0.04);
barrelRig.add(bung);
// Four-leg rope sling and the moving hoist fall.
const slingApex = new THREE.Vector3(0, 1.02, 0);
const slingPoints = [
new THREE.Vector3(0.54, 0.42, 0),
new THREE.Vector3(-0.54, 0.42, 0),
new THREE.Vector3(0, 0.42, 0.54),
new THREE.Vector3(0, 0.42, -0.54)
];
const slingLines = slingPoints.map(() => cylinderBetween(0.018, materials.rope, barrelRig));
const mainRope = cylinderBetween(0.021, materials.rope);
function updateRopes() {
slingLines.forEach((line, index) => {
orientCylinder(line, slingApex, slingPoints[index]);
});
const worldApex = slingApex.clone().add(barrelRig.position);
orientCylinder(
mainRope,
new THREE.Vector3(0, 5.56, -3.49),
worldApex
);
}
updateRopes();
// Optional clearance corridor.
const clearanceGroup = new THREE.Group();
const clearanceMaterial = new THREE.LineDashedMaterial({
color: 0xf0c36d,
dashSize: 0.17,
gapSize: 0.11,
transparent: true,
opacity: 0.85
});
const clearancePoints = [
new THREE.Vector3(-0.95, 0.3, -3.39),
new THREE.Vector3(0.95, 0.3, -3.39),
new THREE.Vector3(0.95, 5.82, -3.39),
new THREE.Vector3(-0.95, 5.82, -3.39),
new THREE.Vector3(-0.95, 0.3, -3.39)
];
const clearanceLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(clearancePoints),
clearanceMaterial
);
clearanceLine.computeLineDistances();
clearanceGroup.add(clearanceLine);
clearanceGroup.visible = false;
scene.add(clearanceGroup);
// Cargo and quay life.
function makeCrate(x, y, z, size = 1, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
scene.add(group);
box(size, size * 0.86, size * 0.82, materials.wood, 0, 0, 0, group);
for (const sx of [-1, 1]) {
box(size * 0.08, size * 0.9, size * 0.87, materials.darkWood,
sx * size * 0.38, 0, 0, group);
}
for (const sy of [-1, 1]) {
box(size * 1.02, size * 0.07, size * 0.87, materials.darkWood,
0, sy * size * 0.34, 0, group);
}
return group;
}
makeCrate(-4.4, 0.52, -1.5, 1.05, 0.08);
makeCrate(-4.25, 1.55, -1.55, 0.92, -0.04);
makeCrate(4.8, 0.52, -1.4, 1.0, -0.09);
makeCrate(-6.8, 0.48, 1.8, 0.9, 0.14);
function makeSack(x, z, scale = 1) {
const sack = new THREE.Mesh(
new THREE.SphereGeometry(0.45, 12, 9),
materials.sack
);
sack.position.set(x, 0.42 * scale, z);
sack.scale.set(scale, 1.12 * scale, 0.85 * scale);
sack.castShadow = true;
sack.receiveShadow = true;
scene.add(sack);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.16, 0.2, 8),
materials.sack
);
neck.position.set(x, 0.87 * scale, z);
scene.add(neck);
}
makeSack(-5.85, -0.5, 1.05);
makeSack(-5.4, -0.15, 0.85);
makeSack(5.8, -0.4, 0.95);
function makeWorker(x, z, rotation, clothMaterial) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
const leftLeg = new THREE.Mesh(
new THREE.CylinderGeometry(0.1, 0.11, 0.65, 8),
materials.darkWood
);
leftLeg.position.set(-0.13, 0.34, 0);
const rightLeg = leftLeg.clone();
rightLeg.position.x = 0.13;
leftLeg.castShadow = rightLeg.castShadow = true;
group.add(leftLeg, rightLeg);
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.34, 0.76, 8),
clothMaterial
);
body.position.y = 1.02;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.21, 14, 10),
materials.skin
);
head.position.y = 1.64;
head.castShadow = true;
group.add(head);
const hood = new THREE.Mesh(
new THREE.ConeGeometry(0.25, 0.34, 8),
clothMaterial
);
hood.position.set(0, 1.79, -0.035);
hood.castShadow = true;
group.add(hood);
beamBetween(
new THREE.Vector3(-0.22, 1.27, 0),
new THREE.Vector3(-0.42, 0.83, 0.1),
0.14, 0.14, clothMaterial, group
);
beamBetween(
new THREE.Vector3(0.22, 1.27, 0),
new THREE.Vector3(0.4, 0.92, 0.14),
0.14, 0.14, clothMaterial, group
);
return group;
}
makeWorker(-3.25, -1.85, -0.65, materials.clothRed);
makeWorker(3.5, -1.25, 0.9, materials.clothBlue);
// Bollards and slack mooring ropes.
const bollardMaterial = new THREE.MeshStandardMaterial({
color: 0x3d3025, map: woodTexture, roughness: 0.9
});
function makeBollard(x, z) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.25, 0.62, 10),
bollardMaterial
);
post.position.set(x, 0.31, z);
post.castShadow = true;
scene.add(post);
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.2, 10, 7),
bollardMaterial
);
cap.scale.y = 0.45;
cap.position.set(x, 0.61, z);
scene.add(cap);
}
[-8.5, -4.6, 4.4, 8.4].forEach((x, i) => {
makeBollard(x, 8.2 + (i % 2) * 0.35);
});
function makeMooringRope(a, b) {
const middleA = a.clone().lerp(b, 0.5);
middleA.y -= 0.42;
const middleB = b.clone().lerp(b, 0.5);
middleB.y -= 0.42;
const curve = new THREE.CatmullRomCurve3([a, middleA, middleB, b]);
const rope = new THREE.Mesh(
new THREE.TubeGeometry(curve, 30, 0.035, 7, false),
materials.rope
);
rope.castShadow = true;
scene.add(rope);
}
makeMooringRope(
new THREE.Vector3(-8.5, 0.46, 8.2),
new THREE.Vector3(-4.6, 0.46, 8.55)
);
makeMooringRope(
new THREE.Vector3(4.4, 0.46, 8.55),
new THREE.Vector3(8.4, 0.46, 8.2)
);
// Distant masts reinforce the port setting without competing with the hoist.
const mastMaterial = new THREE.MeshStandardMaterial({
color: 0x4d4032, roughness: 0.9
});
for (let i = 0; i < 5; i++) {
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.08, 5 + i * 0.35, 8),
mastMaterial
);
mast.position.set(-16 - i * 2.2, 2.2, -8 - i * 2);
scene.add(mast);
}
// Custom orbit camera controls; no addons are used.
const cameraState = {
target: new THREE.Vector3(0, 3.25, -3.55),
radius: 23.5,
theta: 0.56,
phi: 1.1
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
function resetCamera() {
cameraState.target.set(0, 3.25, -3.55);
cameraState.radius = 23.5;
cameraState.theta = 0.56;
cameraState.phi = 1.1;
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.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.42,
1.48
);
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 * Math.exp(event.deltaY * 0.001),
10,
38
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
document.getElementById("zoom-in").addEventListener("click", () => {
cameraState.radius = Math.max(10, cameraState.radius - 2);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
cameraState.radius = Math.min(38, cameraState.radius + 2);
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.theta += 0.08;
else if (event.key === "ArrowRight") cameraState.theta -= 0.08;
else if (event.key === "ArrowUp") cameraState.phi = Math.max(0.42, cameraState.phi - 0.06);
else if (event.key === "ArrowDown") cameraState.phi = Math.min(1.48, cameraState.phi + 0.06);
else if (event.key === "+" || event.key === "=") cameraState.radius = Math.max(10, cameraState.radius - 2);
else if (event.key === "-" || event.key === "_") cameraState.radius = Math.min(38, cameraState.radius + 2);
else if (event.key.toLowerCase() === "r") replayLift();
else if (event.code === "Space") togglePause();
else return;
event.preventDefault();
updateCamera();
});
guideButton.addEventListener("click", () => {
clearanceGroup.visible = !clearanceGroup.visible;
guideButton.classList.toggle("active", clearanceGroup.visible);
guideButton.setAttribute("aria-pressed", String(clearanceGroup.visible));
});
// One lift only: it begins automatically, pauses, and does not loop.
const LIFT = {
startY: 0.94,
endY: 4.43,
duration: 7200,
delay: 750
};
const lift = {
elapsed: 0,
startedAt: performance.now() + LIFT.delay,
playing: true,
done: false
};
function replayLift() {
lift.elapsed = 0;
lift.startedAt = performance.now() + 250;
lift.playing = true;
lift.done = false;
pauseButton.textContent = "Pause lift";
progressFill.style.width = "0%";
statusText.textContent = "Lift reset";
statusDetail.textContent = "One vertical lift";
}
function togglePause() {
if (lift.done) {
replayLift();
return;
}
if (lift.playing) {
lift.elapsed = THREE.MathUtils.clamp((performance.now() - lift.startedAt) / LIFT.duration, 0, 1);
lift.playing = false;
pauseButton.textContent = "Resume lift";
statusText.textContent = "Lift paused";
} else {
lift.startedAt = performance.now() - lift.elapsed * LIFT.duration;
lift.playing = true;
pauseButton.textContent = "Pause lift";
}
}
pauseButton.addEventListener("click", togglePause);
document.getElementById("replay").addEventListener("click", replayLift);
const tagPoint = new THREE.Vector3(1.62, 5.45, -3.85);
const projectedTag = new THREE.Vector3();
function updateOpeningTag() {
projectedTag.copy(tagPoint).project(camera);
const visible = projectedTag.z > -1 && projectedTag.z < 1;
if (!visible) {
openingTag.style.display = "none";
return;
}
openingTag.style.display = "block";
openingTag.style.left = `${(projectedTag.x * 0.5 + 0.5) * innerWidth}px`;
openingTag.style.top = `${(-projectedTag.y * 0.5 + 0.5) * innerHeight}px`;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const now = performance.now();
if (lift.playing && !lift.done) {
lift.elapsed = THREE.MathUtils.clamp(
(now - lift.startedAt) / LIFT.duration,
0,
1
);
}
const p = lift.elapsed;
const eased = p * p * (3 - 2 * p);
// Strictly vertical translation: x and z never change.
barrelRig.position.x = 0;
barrelRig.position.z = -3.48;
barrelRig.position.y = THREE.MathUtils.lerp(LIFT.startY, LIFT.endY, eased);
barrelRig.rotation.y = 0;
wheel.rotation.z = -(barrelRig.position.y - LIFT.startY) * 5.0;
drumRotor.rotation.y = -(barrelRig.position.y - LIFT.startY) * 2.4;
updateRopes();
waterTexture.offset.x = clock.getElapsedTime() * 0.004;
waterTexture.offset.y = clock.getElapsedTime() * 0.002;
progressFill.style.width = `${p * 100}%`;
if (!lift.done) {
if (!lift.playing) {
statusText.textContent = "Lift paused";
statusDetail.textContent = "Horizontal drift 0.00 m";
} else if (p === 0) {
statusText.textContent = "Preparing the lift";
statusDetail.textContent = "Horizontal drift 0.00 m";
} else if (p < 1) {
const meters = ((barrelRig.position.y - LIFT.startY) * 0.72).toFixed(2);
statusText.textContent = "Lifting vertically";
statusDetail.textContent = `${meters} m · drift 0.00 m`;
} else {
lift.done = true;
lift.playing = false;
statusText.textContent = "Clear opening reached";
statusDetail.textContent = "No facade intersection";
pauseButton.textContent = "Replay lift";
}
}
camera.updateMatrixWorld();
updateOpeningTag();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("hidden"));
}
});
</script>
</body>
</html>
```