Prompt specification
Build or customize the Three.js 3D scene "Warehouse lifting beam and hanging hook" 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: Warehouse lifting beam and hanging hook
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/warehouse-lifting-beam-and-hanging-hook-x2353
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Hanseatic warehouse logistics in a Baltic port. Model a projecting timber lifting beam above a high warehouse opening. Show the suspended hook aligned with the loading point and keep the rope continuous. Stylized solid forms.
Working Three.js Starter (warehouse-lifting-beam-and-hanging-hook-x2353):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hanseatic Warehouse — Baltic Port</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9dbbc0;
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#title-card {
position: fixed;
left: 24px;
bottom: 24px;
max-width: 380px;
padding: 15px 18px;
color: #f6ead4;
background: rgba(35, 29, 24, 0.78);
border-left: 4px solid #b96e43;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
pointer-events: none;
backdrop-filter: blur(6px);
}
#title-card h1 {
margin: 0 0 5px;
font-size: 20px;
font-weight: normal;
letter-spacing: 0.04em;
}
#title-card p {
margin: 0;
font-family: Arial, sans-serif;
font-size: 12px;
line-height: 1.45;
color: #d9cbb8;
}
#controls {
position: fixed;
top: 18px;
right: 18px;
display: flex;
gap: 8px;
align-items: center;
}
button {
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 4px;
padding: 9px 13px;
color: #fff4e4;
background: rgba(38, 31, 25, 0.75);
font: 12px Arial, sans-serif;
cursor: pointer;
}
button:hover {
background: rgba(112, 70, 43, 0.9);
}
#hint {
position: fixed;
top: 21px;
left: 22px;
padding: 8px 11px;
color: rgba(255, 248, 234, 0.9);
background: rgba(38, 31, 25, 0.55);
border-radius: 3px;
font: 11px Arial, sans-serif;
pointer-events: none;
}
@media (max-width: 700px) {
#hint {
display: none;
}
#title-card {
left: 12px;
right: 12px;
bottom: 12px;
max-width: none;
}
}
</style>
</head>
<body>
<div id="hint">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
<div id="controls">
<button id="reset-view" type="button">Reset view</button>
</div>
<div id="title-card">
<h1>Hanseatic Warehouse Logistics</h1>
<p>
A Baltic quay beside a stepped-gable brick storehouse. The projecting
oak hoist beam carries a continuous rope over its pulley, suspending
the iron hook directly above the marked loading point.
</p>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9ebdc2);
scene.fog = new THREE.Fog(0x9ebdc2, 25, 58);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
target: new THREE.Vector3(0, 3.1, 1.1),
radius: 20.2,
theta: 0.58,
phi: 1.22
};
const initialOrbit = {
target: orbit.target.clone(),
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xc6e0e4,
0x65513d,
2.05
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6bd, 3.25);
sun.position.set(-9, 15, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x9bcbd7, 0.65);
coolFill.position.set(12, 7, -12);
scene.add(coolFill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function material(color, roughness = 0.82, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
}
const materials = {
brick: material(0x914d38),
brickLight: material(0xb46148),
brickDark: material(0x6f392e),
mortar: material(0xb58668),
oak: material(0x62402a),
oakLight: material(0x8a603b),
darkOak: material(0x3b281d),
stone: material(0x77766d),
stoneDark: material(0x555650),
quay: material(0x77746a),
iron: material(0x25282a, 0.48, 0.45),
rope: material(0xc0a172, 0.95),
crate: material(0xa47745),
crateDark: material(0x6c4629),
barrel: material(0x86532d),
sail: material(0xd9c9a6),
coatBlue: material(0x455b63),
coatRust: material(0x91503c),
skin: material(0xc99d78),
sack: material(0xb8a27d),
window: material(0x1b2528, 0.38, 0.12),
water: new THREE.MeshStandardMaterial({
color: 0x477f88,
roughness: 0.34,
metalness: 0.16
})
};
function box(
width,
height,
depth,
mat,
x = 0,
y = 0,
z = 0,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
topRadius,
bottomRadius,
height,
mat,
x = 0,
y = 0,
z = 0,
segments = 12,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(
radius,
mat,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 12, 8),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, thickness, mat, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const midpoint = new THREE.Vector3()
.copy(a)
.add(b)
.multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(
thickness,
direction.length(),
thickness
),
mat
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rodBetween(a, b, radius, mat, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const midpoint = new THREE.Vector3()
.copy(a)
.add(b)
.multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
8
),
mat
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Quay and Baltic water
// ------------------------------------------------------------
box(15, 0.55, 19, materials.quay, -0.5, -0.275, 1);
const water = new THREE.Mesh(
new THREE.PlaneGeometry(16, 32),
materials.water
);
water.rotation.x = -Math.PI / 2;
water.position.set(15, -0.69, 0);
water.receiveShadow = true;
scene.add(water);
// Stone blocks along the quay edge.
for (let z = -8.3; z < 10; z += 1.15) {
box(
0.72,
0.58,
1.02,
materials.stoneDark,
7.02,
-0.27,
z
);
box(
0.74,
0.12,
1.02,
materials.stone,
6.95,
0.02,
z
);
}
const waves = [];
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0xb1d4d3,
transparent: true,
opacity: 0.35
});
for (let i = 0; i < 34; i++) {
const length = 0.35 + Math.random() * 1.1;
const wave = box(
length,
0.018,
0.035,
waveMaterial,
7.8 + Math.random() * 13,
-0.665,
-14 + Math.random() * 27,
scene,
false
);
wave.rotation.y = (Math.random() - 0.5) * 0.35;
wave.userData.speed = 0.12 + Math.random() * 0.18;
waves.push(wave);
}
// ------------------------------------------------------------
// Hanseatic warehouse shell
// ------------------------------------------------------------
const warehouse = new THREE.Group();
scene.add(warehouse);
// Side and rear walls.
box(0.42, 7, 7.2, materials.brick, -5, 3.5, -3.55, warehouse);
box(0.42, 7, 7.2, materials.brick, 5, 3.5, -3.55, warehouse);
box(10.4, 7, 0.42, materials.brickDark, 0, 3.5, -7.05, warehouse);
// Front wall around a high rectangular loading opening.
box(3.2, 7, 0.46, materials.brick, -3.4, 3.5, 0, warehouse);
box(3.2, 7, 0.46, materials.brick, 3.4, 3.5, 0, warehouse);
box(3.6, 2.15, 0.46, materials.brick, 0, 5.875, 0, warehouse);
// Dark recessed interior.
box(
3.53,
4.72,
0.12,
materials.window,
0,
2.36,
-0.52,
warehouse,
false
);
// Heavy timber opening surround.
box(0.28, 4.86, 0.3, materials.darkOak, -1.87, 2.43, 0.27, warehouse);
box(0.28, 4.86, 0.3, materials.darkOak, 1.87, 2.43, 0.27, warehouse);
box(4.02, 0.3, 0.32, materials.darkOak, 0, 4.83, 0.28, warehouse);
// Raised stone threshold.
box(3.8, 0.16, 0.8, materials.stone, 0, 0.08, 0.2, warehouse);
// Masonry courses across the facade.
for (let y = 0.48; y < 6.8; y += 0.47) {
box(3.11, 0.045, 0.035, materials.mortar, -3.4, y, 0.245, warehouse, false);
box(3.11, 0.045, 0.035, materials.mortar, 3.4, y, 0.245, warehouse, false);
if (y > 4.95) {
box(3.5, 0.045, 0.035, materials.mortar, 0, y, 0.245, warehouse, false);
}
}
// Stone base courses.
box(3.15, 0.62, 0.12, materials.stoneDark, -3.4, 0.31, 0.26, warehouse);
box(3.15, 0.62, 0.12, materials.stoneDark, 3.4, 0.31, 0.26, warehouse);
// Upper windows.
function facadeWindow(x, y, width = 0.62, height = 0.9) {
box(width, height, 0.07, materials.darkOak, x, y, 0.27, warehouse);
box(width - 0.12, height - 0.12, 0.08, materials.window, x, y, 0.32, warehouse);
box(0.045, height - 0.08, 0.09, materials.oak, x, y, 0.37, warehouse);
box(width - 0.06, 0.045, 0.09, materials.oak, x, y, 0.37, warehouse);
}
facadeWindow(-3.35, 5.62);
facadeWindow(3.35, 5.62);
facadeWindow(-1.15, 6.25, 0.5, 0.68);
facadeWindow(1.15, 6.25, 0.5, 0.68);
// Side windows.
for (const z of [-2.2, -4.5]) {
box(0.07, 0.9, 0.62, materials.darkOak, 5.23, 5.35, z, warehouse);
box(0.08, 0.76, 0.48, materials.window, 5.28, 5.35, z, warehouse);
box(0.09, 0.045, 0.55, materials.oak, 5.32, 5.35, z, warehouse);
}
// Stepped Hanseatic gable.
const gableWidths = [9.8, 8.8, 7.8, 6.8, 5.8, 4.8];
for (let i = 0; i < gableWidths.length; i++) {
box(
gableWidths[i],
0.46,
0.36,
i % 2 ? materials.brickLight : materials.brick,
0,
7.18 + i * 0.46,
0.02,
warehouse
);
}
facadeWindow(-2.05, 8.12, 0.48, 0.62);
facadeWindow(0, 8.55, 0.48, 0.62);
facadeWindow(2.05, 8.12, 0.48, 0.62);
// Two sloping roof planes.
const roofAngle = Math.atan(2.3 / 5);
const roofLength = Math.sqrt(5 * 5 + 2.3 * 2.3);
const roofLeft = box(
roofLength,
0.25,
7.25,
materials.brickDark,
-2.5,
8.15,
-3.48,
warehouse
);
roofLeft.rotation.z = roofAngle;
const roofRight = box(
roofLength,
0.25,
7.25,
materials.brickDark,
2.5,
8.15,
-3.48,
warehouse
);
roofRight.rotation.z = -roofAngle;
box(0.27, 0.27, 7.35, materials.darkOak, 0, 9.34, -3.48, warehouse);
// Goods glimpsed inside the opening.
box(0.7, 0.62, 0.72, materials.crateDark, -1.05, 0.45, -0.05, warehouse);
box(0.65, 0.7, 0.65, materials.crate, 1.02, 0.5, -0.12, warehouse);
// ------------------------------------------------------------
// Projecting timber lifting beam
// ------------------------------------------------------------
const hoist = new THREE.Group();
scene.add(hoist);
// Cross member fixed to the facade.
box(3.2, 0.42, 0.42, materials.darkOak, 0, 6.15, 0.28, hoist);
// Main beam projects from the warehouse over the loading point.
box(0.42, 0.42, 4.95, materials.oak, 0, 6.15, 2.58, hoist);
// Iron straps around the beam.
for (const z of [0.65, 2.1, 3.45, 4.8]) {
box(0.49, 0.49, 0.105, materials.iron, 0, 6.15, z, hoist);
box(0.5, 0.08, 0.08, materials.iron, 0, 6.38, z, hoist);
}
// Diagonal knee braces from the facade to the projecting beam.
beamBetween(
new THREE.Vector3(-0.58, 4.92, 0.3),
new THREE.Vector3(-0.58, 5.93, 1.58),
0.22,
materials.oak,
hoist
);
beamBetween(
new THREE.Vector3(0.58, 4.92, 0.3),
new THREE.Vector3(0.58, 5.93, 1.58),
0.22,
materials.oak,
hoist
);
// Winch drum at the wall end.
const drum = cylinder(
0.34,
0.34,
0.72,
materials.oakLight,
0,
6.55,
0.82,
20,
hoist
);
drum.rotation.z = Math.PI / 2;
const drumRim = new THREE.Mesh(
new THREE.TorusGeometry(0.315, 0.035, 8, 24),
materials.iron
);
drumRim.rotation.y = Math.PI / 2;
drumRim.position.set(0.37, 6.55, 0.82);
drumRim.castShadow = true;
hoist.add(drumRim);
// Crank handle.
rodBetween(
new THREE.Vector3(0.47, 6.55, 0.82),
new THREE.Vector3(0.47, 6.55, 1.13),
0.035,
materials.iron,
hoist
);
rodBetween(
new THREE.Vector3(0.47, 6.55, 1.13),
new THREE.Vector3(0.47, 6.25, 1.13),
0.045,
materials.oak,
hoist
);
// Pulley at the distal end of the beam.
const pulleyCenter = new THREE.Vector3(0, 6.49, 4.61);
const pulleyRadius = 0.35;
const pulleyWheel = cylinder(
pulleyRadius,
pulleyRadius,
0.17,
materials.darkOak,
pulleyCenter.x,
pulleyCenter.y,
pulleyCenter.z,
24,
hoist
);
pulleyWheel.rotation.z = Math.PI / 2;
const pulleyRim = new THREE.Mesh(
new THREE.TorusGeometry(pulleyRadius, 0.052, 8, 28),
materials.iron
);
pulleyRim.rotation.y = Math.PI / 2;
pulleyRim.position.copy(pulleyCenter);
pulleyRim.castShadow = true;
hoist.add(pulleyRim);
const hub = cylinder(
0.11,
0.11,
0.32,
materials.iron,
pulleyCenter.x,
pulleyCenter.y,
pulleyCenter.z,
14,
hoist
);
hub.rotation.z = Math.PI / 2;
// Axle brackets.
box(0.1, 0.78, 0.12, materials.iron, -0.2, 6.34, 4.61, hoist);
box(0.1, 0.78, 0.12, materials.iron, 0.2, 6.34, 4.61, hoist);
// ------------------------------------------------------------
// Continuous rope: drum tangent -> pulley top -> pulley arc
// -> vertical fall -> hook eye.
// ------------------------------------------------------------
class ArcYZ extends THREE.Curve {
constructor(center, radius, startAngle, endAngle) {
super();
this.center = center.clone();
this.radius = radius;
this.startAngle = startAngle;
this.endAngle = endAngle;
}
getPoint(t, target = new THREE.Vector3()) {
const angle = THREE.MathUtils.lerp(
this.startAngle,
this.endAngle,
t
);
return target.set(
this.center.x,
this.center.y + this.radius * Math.cos(angle),
this.center.z + this.radius * Math.sin(angle)
);
}
}
const ropeCenter = new THREE.Vector3(0, 6.49, 4.61);
const ropeRadius = 0.39;
const verticalRopeZ = ropeCenter.z + ropeRadius;
const ropeCurve = new THREE.CurvePath();
ropeCurve.add(
new THREE.LineCurve3(
new THREE.Vector3(0, 6.89, 0.82),
new THREE.Vector3(0, 6.88, ropeCenter.z)
)
);
ropeCurve.add(
new ArcYZ(
ropeCenter,
ropeRadius,
0,
Math.PI / 2
)
);
ropeCurve.add(
new THREE.LineCurve3(
new THREE.Vector3(0, ropeCenter.y, verticalRopeZ),
new THREE.Vector3(0, 3.82, verticalRopeZ)
)
);
const rope = new THREE.Mesh(
new THREE.TubeGeometry(ropeCurve, 180, 0.045, 8, false),
materials.rope
);
rope.castShadow = true;
rope.receiveShadow = true;
scene.add(rope);
// Shackle joining the rope and hook.
const shackle = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.035, 8, 20),
materials.iron
);
shackle.position.set(0, 3.68, verticalRopeZ);
shackle.castShadow = true;
scene.add(shackle);
// Continuous forged hook, aligned with x = 0 and the load center.
const hookCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 3.59, verticalRopeZ),
new THREE.Vector3(0, 3.30, verticalRopeZ),
new THREE.Vector3(-0.02, 3.10, verticalRopeZ),
new THREE.Vector3(-0.17, 2.94, verticalRopeZ),
new THREE.Vector3(-0.38, 2.91, verticalRopeZ),
new THREE.Vector3(-0.51, 3.04, verticalRopeZ),
new THREE.Vector3(-0.49, 3.22, verticalRopeZ)
]);
const hook = new THREE.Mesh(
new THREE.TubeGeometry(hookCurve, 48, 0.085, 8, false),
materials.iron
);
hook.castShadow = true;
hook.receiveShadow = true;
scene.add(hook);
// ------------------------------------------------------------
// Cargo and loading point
// ------------------------------------------------------------
function createCrate(x, z, scale = 1, y = 0, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
scene.add(group);
const w = 1.42 * scale;
const h = 1.02 * scale;
const d = 1.22 * scale;
box(w, h, d, materials.crate, 0, h / 2, 0, group);
// Pale reinforcing slats on the front.
for (const px of [-w * 0.34, 0, w * 0.34]) {
box(
0.11 * scale,
h * 0.94,
0.055 * scale,
materials.oakLight,
px,
h / 2,
d / 2 + 0.035 * scale,
group
);
}
box(
w * 0.98,
0.11 * scale,
0.065 * scale,
materials.oakLight,
0,
h * 0.19,
d / 2 + 0.045 * scale,
group
);
box(
w * 0.98,
0.11 * scale,
0.065 * scale,
materials.oakLight,
0,
h * 0.81,
d / 2 + 0.045 * scale,
group
);
// Top boards.
for (const pz of [-d * 0.25, d * 0.25]) {
box(
w * 0.98,
0.07 * scale,
d * 0.38,
materials.crateDark,
0,
h + 0.035 * scale,
pz,
group
);
}
return group;
}
function createBarrel(x, z, scale = 1, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.58 * scale, z);
group.rotation.y = rotation;
scene.add(group);
cylinder(
0.43 * scale,
0.49 * scale,
1.04 * scale,
materials.barrel,
0,
0,
0,
14,
group
);
for (const y of [-0.35, 0, 0.35]) {
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(
(0.465 + Math.abs(y) * 0.035) * scale,
0.027 * scale,
7,
18
),
materials.iron
);
hoop.rotation.x = Math.PI / 2;
hoop.position.y = y * scale;
hoop.castShadow = true;
group.add(hoop);
}
return group;
}
// Pallet directly beneath the hook.
for (const px of [-0.62, 0, 0.62]) {
box(0.16, 0.13, 1.58, materials.darkOak, px, 0.075, 5, scene);
}
for (const pz of [4.42, 4.78, 5.14, 5.5]) {
box(1.62, 0.09, 0.22, materials.oakLight, 0, 0.18, pz, scene);
}
// The suspended hook is exactly aligned with this crate.
createCrate(0, 5, 1.28, 0.225, 0);
// Other quay cargo.
createCrate(2.55, 2.45, 0.93, 0.02, -0.14);
createCrate(3.5, 3.45, 0.8, 0.02, 0.18);
createCrate(-2.65, 2.7, 1.0, 0.02, 0.12);
createBarrel(2.2, 4.3, 1.0, 0.2);
createBarrel(3.0, 4.55, 0.9, -0.15);
createBarrel(-3.25, 3.7, 1.05, 0.4);
// Sacks.
const sackA = sphere(0.48, materials.sack, -1.9, 0.45, 4.5);
sackA.scale.set(1, 1.2, 0.85);
const sackB = sphere(0.43, materials.sack, -2.65, 0.4, 4.1);
sackB.scale.set(0.95, 1.15, 0.9);
// ------------------------------------------------------------
// Stylized dock workers
// ------------------------------------------------------------
function createWorker(x, z, rotation, coat, hat = true) {
const worker = new THREE.Group();
worker.position.set(x, 0, z);
worker.rotation.y = rotation;
scene.add(worker);
// Boots.
box(0.22, 0.16, 0.38, materials.darkOak, -0.15, 0.09, 0.06, worker);
box(0.22, 0.16, 0.38, materials.darkOak, 0.15, 0.09, 0.06, worker);
// Legs.
rodBetween(
new THREE.Vector3(-0.14, 0.16, 0),
new THREE.Vector3(-0.12, 0.68, 0),
0.09,
materials.coatBlue,
worker
);
rodBetween(
new THREE.Vector3(0.14, 0.16, 0),
new THREE.Vector3(0.12, 0.68, 0),
0.09,
materials.coatBlue,
worker
);
// Tunic.
cylinder(0.26, 0.34, 0.65, coat, 0, 0.98, 0, 8, worker);
// Arms.
rodBetween(
new THREE.Vector3(-0.24, 1.2, 0),
new THREE.Vector3(-0.39, 0.82, 0.18),
0.075,
coat,
worker
);
rodBetween(
new THREE.Vector3(0.24, 1.2, 0),
new THREE.Vector3(0.43, 0.91, 0.34),
0.075,
coat,
worker
);
// Hands and head.
sphere(0.085, materials.skin, -0.39, 0.79, 0.18, worker);
sphere(0.085, materials.skin, 0.43, 0.88, 0.34, worker);
sphere(0.19, materials.skin, 0, 1.49, 0, worker);
if (hat) {
cylinder(0.21, 0.21, 0.055, materials.oak, 0, 1.65, 0, 10, worker);
cylinder(0.14, 0.16, 0.18, materials.oak, 0, 1.75, 0, 8, worker);
}
return worker;
}
createWorker(1.4, 4.65, -1.2, materials.coatRust, true);
createWorker(-2.25, 1.35, 0.45, materials.coatBlue, false);
// ------------------------------------------------------------
// Bollards, rope coil, and small port details
// ------------------------------------------------------------
function createBollard(x, z) {
cylinder(0.18, 0.24, 0.72, materials.iron, x, 0.36, z, 10);
cylinder(0.27, 0.2, 0.15, materials.iron, x, 0.72, z, 10);
sphere(0.12, materials.iron, x, 0.8, z);
}
createBollard(6.35, 1.6);
createBollard(6.35, 5.7);
createBollard(6.35, 8.3);
// Coiled rope beside a bollard.
for (let i = 0; i < 3; i++) {
const coil = new THREE.Mesh(
new THREE.TorusGeometry(0.29 + i * 0.055, 0.028, 7, 24),
materials.rope
);
coil.rotation.x = Math.PI / 2;
coil.position.set(5.8, 0.045 + i * 0.025, 2.65);
coil.castShadow = true;
scene.add(coil);
}
// A short stack of loose timber.
for (let i = 0; i < 5; i++) {
const timber = box(
1.85,
0.13,
0.18,
materials.oakLight,
-4.05,
0.1 + i * 0.14,
5.0 + (i % 2) * 0.04,
scene
);
timber.rotation.y = (i % 2 ? 1 : -1) * 0.025;
}
// ------------------------------------------------------------
// Small Baltic trading ship
// ------------------------------------------------------------
const ship = new THREE.Group();
ship.position.set(12.7, -0.28, -5.7);
ship.rotation.y = -0.19;
scene.add(ship);
const hullShape = new THREE.Shape();
hullShape.moveTo(-2.35, 0.42);
hullShape.lineTo(2.35, 0.42);
hullShape.lineTo(1.72, -0.58);
hullShape.lineTo(-1.72, -0.58);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 1.55,
bevelEnabled: true,
bevelSize: 0.08,
bevelThickness: 0.08,
bevelSegments: 1
});
const hull = new THREE.Mesh(hullGeometry, materials.darkOak);
hull.position.z = -0.775;
hull.castShadow = true;
hull.receiveShadow = true;
ship.add(hull);
box(4.2, 0.16, 1.32, materials.oakLight, 0, 0.48, 0, ship);
box(0.65, 1.3, 1.05, materials.oak, -1.72, 1.03, 0, ship);
box(0.65, 0.85, 1.05, materials.oak, 1.8, 0.8, 0, ship);
// Mast, yard, and triangular sail.
cylinder(0.075, 0.11, 4.8, materials.darkOak, 0.1, 2.55, 0, 10, ship);
rodBetween(
new THREE.Vector3(-1.75, 3.45, 0),
new THREE.Vector3(2.0, 3.45, 0),
0.045,
materials.oak,
ship
);
const sailGeometry = new THREE.BufferGeometry();
sailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-0.02, 0.9, 0.04,
1.82, 0.9, 0.04,
0.06, 3.35, 0.04
], 3)
);
sailGeometry.computeVertexNormals();
const sailMaterial = materials.sail.clone();
sailMaterial.side = THREE.DoubleSide;
const sail = new THREE.Mesh(sailGeometry, sailMaterial);
sail.castShadow = true;
ship.add(sail);
// Simple flag.
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0.15, 4.85, 0,
0.92, 4.63, 0,
0.15, 4.43, 0
], 3)
);
flagGeometry.computeVertexNormals();
const flag = new THREE.Mesh(
flagGeometry,
new THREE.MeshStandardMaterial({
color: 0xa44836,
side: THREE.DoubleSide,
flatShading: true
})
);
ship.add(flag);
// ------------------------------------------------------------
// Distant waterfront silhouettes
// ------------------------------------------------------------
for (let i = 0; i < 8; i++) {
const width = 1.5 + (i % 3) * 0.6;
const height = 1.4 + (i % 4) * 0.35;
box(
width,
height,
2.2,
materials.brickDark,
8.8 + i * 1.8,
height / 2 - 0.55,
-14 - (i % 2) * 1.3,
scene,
false
);
const distantRoof = box(
width * 0.75,
0.18,
2.3,
materials.darkOak,
8.8 + i * 1.8,
height - 0.45,
-14 - (i % 2) * 1.3,
scene,
false
);
distantRoof.rotation.z = 0.15;
}
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom
// ------------------------------------------------------------
const pointer = {
active: false,
x: 0,
y: 0,
button: 0
};
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", event => {
pointer.active = true;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.button = event.button;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointer.active) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (event.shiftKey || pointer.button === 2) {
const right = new THREE.Vector3();
camera.getWorldDirection(right);
right.cross(camera.up).normalize();
const panScale = orbit.radius * 0.00125;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.y += dy * panScale;
} else {
orbit.theta -= dx * 0.005;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.28,
1.48
);
}
updateCamera();
});
function stopPointer() {
pointer.active = false;
}
canvas.addEventListener("pointerup", stopPointer);
canvas.addEventListener("pointercancel", stopPointer);
canvas.addEventListener("lostpointercapture", stopPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
8.5,
34
);
updateCamera();
}, { passive: false });
document.getElementById("reset-view").addEventListener("click", () => {
orbit.target.copy(initialOrbit.target);
orbit.radius = initialOrbit.radius;
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
for (const wave of waves) {
wave.position.z += wave.userData.speed * delta;
if (wave.position.z > 13) {
wave.position.z = -15;
}
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```