Prompt specification
Build or customize the Three.js 3D scene "Port warehouse linked to inland delivery" 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: Port warehouse linked to inland delivery
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/port-warehouse-linked-to-inland-delivery-x2607
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts ancient Mediterranean amphora shipping. Build a compact referenced harbor scene connecting ship, quay, warehouse, and cart road. Show the same cargo containers passing through distinct transport and storage stages. Low-poly.
Working Three.js Starter (port-warehouse-linked-to-inland-delivery-x2607):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Amphora Freight — Ancient Mediterranean Harbor</title>
<style>
:root {
--ink: #29251f;
--paper: #efe3c7;
--terracotta: #ad5636;
--gold: #d5a84d;
--sea: #315f69;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a8c5c7;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
touch-action: none;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 17px 18px 15px;
background: rgba(239, 227, 199, 0.92);
border: 1px solid rgba(70, 54, 38, 0.35);
box-shadow: 0 10px 30px rgba(36, 34, 26, 0.16);
backdrop-filter: blur(7px);
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.05;
letter-spacing: 0.02em;
}
.subtitle {
margin: 7px 0 13px;
color: #695c4a;
font: 12px/1.35 system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#stage {
padding: 9px 10px;
margin-bottom: 10px;
background: var(--ink);
color: var(--paper);
font: 700 12px/1.2 system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stages {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
font: 11px/1.2 system-ui, sans-serif;
}
.stage-item {
padding: 7px 8px;
border: 1px solid rgba(77, 62, 45, 0.22);
color: #695f50;
transition: 160ms ease;
}
.stage-item b {
display: block;
color: var(--terracotta);
font-size: 10px;
margin-bottom: 3px;
}
.stage-item.active {
color: #fff7e6;
background: var(--terracotta);
border-color: var(--terracotta);
}
.stage-item.active b { color: #f8d997; }
#progressTrack {
height: 4px;
margin-top: 12px;
overflow: hidden;
background: rgba(60, 47, 34, 0.16);
}
#progress {
width: 0;
height: 100%;
background: var(--terracotta);
}
.buttons {
display: flex;
gap: 7px;
margin-top: 12px;
pointer-events: auto;
}
button {
flex: 1;
padding: 8px 7px;
border: 1px solid #7d654a;
background: transparent;
color: var(--ink);
cursor: pointer;
font: 700 10px/1 system-ui, sans-serif;
letter-spacing: 0.06em;
text-transform: uppercase;
}
button:hover { background: #d8c49c; }
#hint {
position: absolute;
right: 18px;
bottom: 16px;
padding: 9px 12px;
background: rgba(35, 40, 37, 0.76);
color: #f5e8ca;
font: 11px/1.35 system-ui, sans-serif;
letter-spacing: 0.04em;
text-align: right;
}
#legend {
position: absolute;
right: 18px;
top: 18px;
padding: 10px 12px;
background: rgba(239, 227, 199, 0.86);
border: 1px solid rgba(70, 54, 38, 0.25);
font: 11px/1.45 system-ui, sans-serif;
}
#legend span {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 6px;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #d9cfb7;
color: #51412e;
font: 14px system-ui, sans-serif;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
@media (max-width: 700px) {
.panel { top: 10px; left: 10px; width: calc(100vw - 20px); }
h1 { font-size: 20px; }
#legend { display: none; }
#hint { right: 10px; bottom: 10px; }
}
</style>
</head>
<body>
<div id="loading">Preparing the harbor…</div>
<div id="ui">
<section class="panel">
<h1>Amphora Freight</h1>
<div class="subtitle">Ancient Mediterranean harbor logistics</div>
<div id="stage">01 · Shipboard storage</div>
<div class="stages">
<div class="stage-item active" data-stage="0"><b>01</b>Shipboard storage</div>
<div class="stage-item" data-stage="1"><b>02</b>Quay transfer</div>
<div class="stage-item" data-stage="2"><b>03</b>Cart road</div>
<div class="stage-item" data-stage="3"><b>04</b>Warehouse storage</div>
</div>
<div id="progressTrack"><div id="progress"></div></div>
<div class="buttons">
<button id="pause">Pause</button>
<button id="replay">Replay</button>
<button id="home">Camera</button>
</div>
</section>
<aside id="legend">
<div><span style="background:#795438"></span>Numbered crates contain the same amphora cargo.</div>
<div><span style="background:#ad5636"></span>Mediterranean terracotta</div>
<div><span style="background:#d2b574"></span>Sun-baked stone and road</div>
</aside>
<div id="hint">
Drag to orbit · Scroll to zoom<br>
Arrow keys rotate · + / − zoom
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9c7ca);
scene.fog = new THREE.Fog(0xa9c7ca, 28, 70);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, 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 camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
160
);
const hemi = new THREE.HemisphereLight(0xd8edf0, 0x6f5436, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe1a5, 3.0);
sun.position.set(-9, 19, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.0007;
scene.add(sun);
const clock = new THREE.Clock();
const M = {
stone: new THREE.MeshStandardMaterial({
color: 0xcbb98f, roughness: 1, flatShading: true
}),
paleStone: new THREE.MeshStandardMaterial({
color: 0xe0cfaa, roughness: 1, flatShading: true
}),
road: new THREE.MeshStandardMaterial({
color: 0xbda477, roughness: 1, flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x795238, roughness: 1, flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x493529, roughness: 1, flatShading: true
}),
rope: new THREE.LineBasicMaterial({ color: 0x65503a }),
terracotta: new THREE.MeshStandardMaterial({
color: 0xad5636, roughness: 0.95, flatShading: true
}),
roof: new THREE.MeshStandardMaterial({
color: 0x9d4933, roughness: 1, flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x405b3d, roughness: 1, flatShading: true
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x64764a, roughness: 1, flatShading: true
}),
skin: new THREE.MeshStandardMaterial({
color: 0x9a6747, roughness: 1, flatShading: true
}),
linen: new THREE.MeshStandardMaterial({
color: 0xe8d8b3, roughness: 1, side: THREE.DoubleSide
})
};
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;
}
function cylinder(rt, rb, h, segments, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLine(points, material = M.rope, parent = scene) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, material);
parent.add(line);
return line;
}
function pointBeam(a, b, radius, material, parent = scene, segments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), segments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 7719;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
// ------------------------------------------------------------
// Low-poly sea
// ------------------------------------------------------------
const seaGeometry = new THREE.PlaneGeometry(72, 48, 30, 20);
seaGeometry.rotateX(-Math.PI / 2);
const seaPositions = seaGeometry.attributes.position;
const seaColors = [];
const seaColor = new THREE.Color();
for (let i = 0; i < seaPositions.count; i++) {
const x = seaPositions.getX(i);
const z = seaPositions.getZ(i);
const y = Math.sin(x * 0.55 + z * 0.28) * 0.055 +
Math.cos(z * 0.72 - x * 0.16) * 0.035;
seaPositions.setY(i, y);
const c = 0.29 + random() * 0.055;
seaColor.setHSL(0.52, 0.31, c);
seaColors.push(seaColor.r, seaColor.g, seaColor.b);
}
seaGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(seaColors, 3)
);
seaGeometry.computeVertexNormals();
const seaMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.68,
metalness: 0.04,
flatShading: true
});
const sea = new THREE.Mesh(seaGeometry, seaMaterial);
sea.position.set(-10, -0.08, 0);
sea.receiveShadow = true;
scene.add(sea);
// Decorative low-poly wave strokes.
for (let i = 0; i < 42; i++) {
const x = -28 + random() * 24;
const z = -18 + random() * 36;
if (x > -2.5) continue;
const length = 0.8 + random() * 1.8;
const points = [
new THREE.Vector3(x, 0.03, z),
new THREE.Vector3(x + length * 0.45, 0.04, z + 0.08),
new THREE.Vector3(x + length, 0.025, z)
];
makeLine(points, new THREE.LineBasicMaterial({
color: 0x91b4b5,
transparent: true,
opacity: 0.52
}));
}
// ------------------------------------------------------------
// Quay, road and stone details
// ------------------------------------------------------------
box(20.5, 1.15, 18, M.stone, 8.05, 0.25, 0);
box(20.5, 0.08, 18, M.paleStone, 8.05, 0.86, 0);
// Quay face blocks.
for (let i = 0; i < 15; i++) {
const block = box(
0.58, 0.75, 1.02,
i % 2 ? M.stone : M.paleStone,
-2.18, 0.22, -8.45 + i * 1.2
);
block.rotation.y = (random() - 0.5) * 0.025;
}
// Road and warehouse approach.
box(18.2, 0.07, 3.25, M.road, 7.5, 0.91, 0.65);
box(3.25, 0.075, 3.5, M.road, 8.4, 0.915, -0.85);
// Instanced cobbles.
const cobbleGeometry = new THREE.BoxGeometry(0.38, 0.055, 0.29);
const cobbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff, roughness: 1, flatShading: true
});
const cobbles = new THREE.InstancedMesh(
cobbleGeometry, cobbleMaterial, 125
);
const dummy = new THREE.Object3D();
for (let i = 0; i < 125; i++) {
let x, z;
if (i < 98) {
x = -1.0 + random() * 17.3;
z = -0.68 + random() * 2.65;
} else {
x = 7.05 + random() * 2.7;
z = -2.25 + random() * 2.9;
}
dummy.position.set(x, 0.96, z);
dummy.rotation.set(0, (random() - 0.5) * 0.22, 0);
dummy.scale.set(0.8 + random() * 0.5, 1, 0.75 + random() * 0.45);
dummy.updateMatrix();
cobbles.setMatrixAt(i, dummy.matrix);
const shade = new THREE.Color().setHSL(
0.105, 0.23, 0.55 + random() * 0.13
);
cobbles.setColorAt(i, shade);
}
cobbles.receiveShadow = true;
scene.add(cobbles);
// Bollards.
for (const z of [-5.2, -1.8, 2.8, 6.3]) {
cylinder(0.17, 0.23, 0.58, 8, M.darkWood, -1.85, 1.17, z);
cylinder(0.25, 0.19, 0.13, 8, M.darkWood, -1.85, 1.51, z);
}
// ------------------------------------------------------------
// Merchant ship
// ------------------------------------------------------------
const ship = new THREE.Group();
ship.position.set(-4.9, 0, 0);
scene.add(ship);
function createHull() {
const sections = [
{ z: -5.6, w: 0.20 },
{ z: -4.2, w: 1.48 },
{ z: 3.8, w: 1.42 },
{ z: 5.6, w: 0.18 }
];
const positions = [];
const indices = [];
for (const section of sections) {
const { z, w } = section;
positions.push(
-w, 0.95, z,
w, 0.95, z,
-w * 0.62, -0.18, z,
w * 0.62, -0.18, z
);
}
for (let s = 0; s < sections.length - 1; s++) {
const a = s * 4;
const b = (s + 1) * 4;
indices.push(
a, b, a + 1,
a + 1, b, b + 1,
a + 2, a, a + 3,
a + 3, b, b + 3,
a, a + 2, b,
b, a + 2, b + 2,
a + 1, b + 1, a + 3,
a + 3, b + 1, b + 3
);
}
const end = (sections.length - 1) * 4;
indices.push(0, 1, 2, 1, 3, 2);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0x69442f,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
ship.add(mesh);
}
createHull();
box(2.65, 0.13, 8.4, M.wood, 0, 1.03, -0.1, ship);
box(2.9, 0.16, 0.25, M.darkWood, 0, 1.2, -4.25, ship);
box(2.9, 0.16, 0.25, M.darkWood, 0, 1.2, 4.15, ship);
// Hull rails.
for (const side of [-1, 1]) {
for (let z = -3.9; z <= 3.9; z += 1.3) {
cylinder(0.06, 0.07, 0.62, 6, M.darkWood, side * 1.37, 1.38, z, ship);
}
pointBeam(
new THREE.Vector3(side * 1.37, 1.65, -4.2),
new THREE.Vector3(side * 1.37, 1.65, 4.2),
0.055, M.darkWood, ship
);
}
// Mast, yard and sail.
cylinder(0.12, 0.16, 6.1, 8, M.darkWood, 0, 3.9, -0.1, ship);
box(0.16, 0.16, 5.3, M.darkWood, 0, 5.65, -0.1, ship);
const sailGeometry = new THREE.BufferGeometry();
sailGeometry.setAttribute("position", new THREE.Float32BufferAttribute([
0.12, 5.45, -2.45,
0.12, 2.35, -1.95,
0.12, 2.35, 1.75,
0.12, 5.45, 2.25
], 3));
sailGeometry.setIndex([0, 1, 2, 0, 2, 3]);
sailGeometry.computeVertexNormals();
const sail = new THREE.Mesh(sailGeometry, M.linen);
sail.castShadow = true;
ship.add(sail);
// Sail seams.
for (let y = 2.8; y < 5.3; y += 0.65) {
pointBeam(
new THREE.Vector3(0.14, y, -2.1),
new THREE.Vector3(0.14, y, 1.95),
0.018, M.road, ship
);
}
makeLine([
new THREE.Vector3(0, 6.4, -0.1),
new THREE.Vector3(-1.3, 1.3, -3.7)
], M.rope, ship);
makeLine([
new THREE.Vector3(0, 6.4, -0.1),
new THREE.Vector3(1.3, 1.3, 3.7)
], M.rope, ship);
// Mooring ropes.
makeLine([
new THREE.Vector3(-3.45, 1.25, -3.2),
new THREE.Vector3(-1.85, 1.45, -1.8)
]);
makeLine([
new THREE.Vector3(-3.45, 1.25, 3.0),
new THREE.Vector3(-1.85, 1.45, 2.8)
]);
// ------------------------------------------------------------
// Warehouse
// ------------------------------------------------------------
const warehouse = new THREE.Group();
warehouse.position.set(9, 0, -3.2);
scene.add(warehouse);
// Floor and walls.
box(8.2, 0.16, 6.25, M.paleStone, 0, 0.86, 0, warehouse);
box(8.2, 3.75, 0.32, M.paleStone, 0, 2.75, -3.0, warehouse);
box(0.32, 3.75, 6.0, M.paleStone, -4.0, 2.75, 0, warehouse);
box(0.32, 3.75, 6.0, M.paleStone, 4.0, 2.75, 0, warehouse);
// Front piers and lintel.
box(0.68, 3.7, 0.42, M.stone, -3.7, 2.75, 3.0, warehouse);
box(0.68, 3.7, 0.42, M.stone, 3.7, 2.75, 3.0, warehouse);
box(7.45, 0.48, 0.5, M.stone, 0, 4.25, 3.0, warehouse);
// Stone arch above the opening.
const arch = new THREE.Mesh(
new THREE.TorusGeometry(2.7, 0.15, 5, 18, Math.PI),
M.stone
);
arch.position.set(0, 3.05, 3.04);
arch.castShadow = true;
warehouse.add(arch);
// Roof slabs.
const roofAngle = 0.36;
const roofLength = 3.2;
const rearRoof = box(
8.75, 0.24, roofLength, M.roof,
0, 4.82, -1.5, warehouse
);
rearRoof.rotation.x = -roofAngle;
const frontRoof = box(
8.75, 0.24, roofLength, M.roof,
0, 4.82, 1.5, warehouse
);
frontRoof.rotation.x = roofAngle;
// Decorative roof ridge.
box(8.9, 0.18, 0.2, M.darkWood, 0, 5.52, 0, warehouse);
// Door frame and interior shelf supports.
for (const x of [-3.35, 3.35]) {
box(0.22, 2.35, 0.35, M.darkWood, x, 2.08, 2.72, warehouse);
}
for (const x of [-1.3, 1.3]) {
box(0.16, 2.5, 0.3, M.darkWood, x, 2.15, -1.3, warehouse);
}
// Side loading awning.
const awning = box(2.1, 0.13, 3.0, M.wood, 4.7, 3.25, 1.55, warehouse);
awning.rotation.z = -0.12;
// ------------------------------------------------------------
// Mediterranean background architecture and landscape
// ------------------------------------------------------------
// Small portico behind the quay.
for (let i = 0; i < 5; i++) {
const x = -0.6 + i * 1.45;
cylinder(0.23, 0.28, 2.9, 8, M.paleStone, x, 2.25, -7.25);
box(0.64, 0.22, 0.64, M.stone, x, 0.9, -7.25);
box(0.64, 0.22, 0.64, M.stone, x, 3.72, -7.25);
}
box(7.2, 0.38, 1.2, M.stone, 2.3, 4.0, -7.25);
const pediment = new THREE.Mesh(
new THREE.CylinderGeometry(0.01, 4.2, 2.5, 3),
M.paleStone
);
pediment.rotation.z = Math.PI / 2;
pediment.rotation.y = Math.PI / 2;
pediment.position.set(2.3, 5.1, -7.25);
pediment.scale.z = 0.3;
pediment.castShadow = true;
scene.add(pediment);
function cypress(x, z, scale = 1) {
cylinder(0.16, 0.22, 1.1 * scale, 7, M.darkWood, x, 1.3 * scale, z);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.75 * scale, 3.3 * scale, 7),
M.leaf
);
crown.position.set(x, 2.65 * scale, z);
crown.castShadow = true;
scene.add(crown);
}
cypress(15.4, -6.8, 1.1);
cypress(16.5, -3.8, 0.9);
cypress(3.8, -7.8, 0.85);
// Low-poly hills across the water.
function hill(x, z, radius, height, color) {
const mesh = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 7),
new THREE.MeshStandardMaterial({
color, roughness: 1, flatShading: true
})
);
mesh.position.set(x, height * 0.5 - 0.1, z);
mesh.scale.z = 0.65;
scene.add(mesh);
}
hill(-22, -22, 9, 7.5, 0x66735b);
hill(-13, -24, 7, 5.0, 0x788064);
hill(-30, -15, 6, 4.2, 0x526b58);
hill(17, -25, 8, 6.2, 0x6b765a);
// Sun disc.
const sunDisc = new THREE.Mesh(
new THREE.SphereGeometry(2.1, 12, 8),
new THREE.MeshBasicMaterial({ color: 0xffd58b })
);
sunDisc.position.set(-18, 15, -30);
scene.add(sunDisc);
// ------------------------------------------------------------
// Amphorae, workers and the cargo crates
// ------------------------------------------------------------
function amphoraGeometry() {
const points = [
new THREE.Vector2(0.07, 0),
new THREE.Vector2(0.18, 0.04),
new THREE.Vector2(0.25, 0.18),
new THREE.Vector2(0.23, 0.31),
new THREE.Vector2(0.13, 0.48),
new THREE.Vector2(0.07, 0.59),
new THREE.Vector2(0.07, 0.72),
new THREE.Vector2(0.11, 0.74),
new THREE.Vector2(0.08, 0.79),
new THREE.Vector2(0, 0.79)
];
return new THREE.LatheGeometry(points, 8);
}
const amphoraGeometryShared = amphoraGeometry();
function worker(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.9, z);
group.rotation.y = rotation;
scene.add(group);
cylinder(0.19, 0.29, 0.72, 7, M.linen, 0, 0.55, 0, group);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.18, 0),
M.skin
);
head.position.y = 1.08;
head.castShadow = true;
group.add(head);
const armGeometry = new THREE.CylinderGeometry(0.065, 0.075, 0.62, 6);
const armL = new THREE.Mesh(armGeometry, M.skin);
armL.position.set(-0.25, 0.58, 0);
armL.rotation.z = 0.42;
group.add(armL);
const armR = armL.clone();
armR.position.x = 0.25;
armR.rotation.z = -0.42;
group.add(armR);
for (const side of [-1, 1]) {
cylinder(0.07, 0.08, 0.38, 6, M.skin, side * 0.11, 0.12, 0, group);
}
return group;
}
worker(-1.7, 1.8, -0.6);
worker(3.9, 2.25, 0.4);
worker(11.8, 1.25, Math.PI);
function makeLabelTexture(numeral) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "#ead8ae";
context.fillRect(0, 0, 128, 128);
context.strokeStyle = "#6e4931";
context.lineWidth = 8;
context.strokeRect(8, 8, 112, 112);
context.fillStyle = "#3b2c22";
context.font = "bold 64px Georgia";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(numeral, 64, 68);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const numerals = ["I", "II", "III", "IV", "V", "VI"];
function createCrate(index) {
const group = new THREE.Group();
group.userData.index = index;
// Open wooden slat crate.
box(0.74, 0.09, 0.74, M.darkWood, 0, 0.045, 0, group);
for (const x of [-0.34, 0.34]) {
for (const z of [-0.34, 0.34]) {
box(0.085, 0.7, 0.085, M.wood, x, 0.36, z, group);
}
}
for (const z of [-0.365, 0.365]) {
for (const y of [0.16, 0.36, 0.57]) {
box(0.76, 0.095, 0.055, M.wood, 0, y, z, group);
}
}
for (const x of [-0.365, 0.365]) {
for (const y of [0.16, 0.36, 0.57]) {
box(0.055, 0.095, 0.76, M.wood, x, y, 0, group);
}
}
// Cargo amphora visible above the crate.
const amphora = new THREE.Mesh(
amphoraGeometryShared,
M.terracotta
);
amphora.position.y = 0.08;
amphora.castShadow = true;
group.add(amphora);
for (const side of [-1, 1]) {
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.024, 4, 6),
M.terracotta
);
handle.position.set(side * 0.145, 0.67, 0);
handle.rotation.y = Math.PI / 2;
group.add(handle);
}
// Roman numeral label makes every transfer identifiable.
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.29, 0.29),
new THREE.MeshBasicMaterial({
map: makeLabelTexture(numerals[index]),
side: THREE.DoubleSide
})
);
label.position.set(0, 0.37, 0.402);
group.add(label);
scene.add(group);
return group;
}
const cargo = numerals.map((_, index) => createCrate(index));
// Decorative amphora storage beside the warehouse.
function standingAmphora(x, y, z, scale = 1) {
const mesh = new THREE.Mesh(
amphoraGeometryShared,
M.terracotta
);
mesh.position.set(x, y, z);
mesh.scale.setScalar(scale);
mesh.castShadow = true;
scene.add(mesh);
}
for (let i = 0; i < 5; i++) {
standingAmphora(14.5 + (i % 2) * 0.48, 0.95, -2.2 + Math.floor(i / 2) * 0.52, 0.86);
}
for (let i = 0; i < 3; i++) {
standingAmphora(1.7 + i * 0.5, 0.95, -2.8 + i * 0.22, 0.78);
}
// ------------------------------------------------------------
// Wooden transfer derrick
// ------------------------------------------------------------
const crane = new THREE.Group();
crane.position.set(-1.42, 0.9, 0.65);
scene.add(crane);
box(0.38, 4.2, 0.38, M.darkWood, 0, 2.1, 0, crane);
box(1.1, 0.18, 1.05, M.wood, 0, 0.08, 0, crane);
box(4.35, 0.22, 0.22, M.wood, -2.15, 4.13, 0, crane);
pointBeam(
new THREE.Vector3(0, 2.75, 0),
new THREE.Vector3(-3.25, 4.08, 0),
0.11, M.wood, crane
);
const ropeGeometry = new THREE.BufferGeometry();
ropeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const craneRope = new THREE.Line(
ropeGeometry,
new THREE.LineBasicMaterial({ color: 0x3d3026 })
);
scene.add(craneRope);
const hook = new THREE.Mesh(
new THREE.TorusGeometry(0.09, 0.022, 5, 8, Math.PI * 1.5),
M.darkWood
);
hook.rotation.y = Math.PI / 2;
scene.add(hook);
// ------------------------------------------------------------
// Ox cart
// ------------------------------------------------------------
const cart = new THREE.Group();
cart.position.set(-0.7, 0.9, 0.65);
scene.add(cart);
box(1.65, 0.18, 1.45, M.wood, 0, 0.43, 0, cart);
box(1.75, 0.25, 0.12, M.darkWood, 0, 0.61, 0.64, cart);
box(1.75, 0.25, 0.12, M.darkWood, 0, 0.61, -0.64, cart);
for (const z of [-0.83, 0.83]) {
const wheel = new THREE.Group();
wheel.position.set(-0.48, 0.56, z);
cart.add(wheel);
const rim = new THREE.Mesh(
new THREE.CylinderGeometry(0.59, 0.59, 0.14, 12),
M.darkWood
);
rim.rotation.x = Math.PI / 2;
rim.castShadow = true;
wheel.add(rim);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.21, 8),
M.wood
);
hub.rotation.x = Math.PI / 2;
wheel.add(hub);
for (let i = 0; i < 8; i++) {
const spoke = box(
0.07, 1.02, 0.06, M.wood, 0, 0, 0, wheel
);
spoke.rotation.z = i * Math.PI / 8;
}
}
// Cart shaft.
pointBeam(
new THREE.Vector3(0.55, 0.45, 0.48),
new THREE.Vector3(1.75, 0.25, 0.48),
0.065, M.darkWood, cart
);
pointBeam(
new THREE.Vector3(0.55, 0.45, -0.48),
new THREE.Vector3(1.75, 0.25, -0.48),
0.065, M.darkWood, cart
);
// Low-poly ox.
const ox = new THREE.Group();
ox.position.set(2.1, 0, 0);
cart.add(ox);
box(1.25, 0.68, 0.72, new THREE.MeshStandardMaterial({
color: 0x796657, roughness: 1, flatShading: true
}), 0, 0.87, 0, ox);
box(0.65, 0.6, 0.56, new THREE.MeshStandardMaterial({
color: 0x6f5b4c, roughness: 1, flatShading: true
}), 0.78, 1.12, 0, ox);
for (const z of [-0.25, 0.25]) {
pointBeam(
new THREE.Vector3(0.83, 1.24, z),
new THREE.Vector3(1.17, 1.38, z),
0.055, M.paleStone, ox
);
}
for (const x of [-0.42, 0.42]) {
for (const z of [-0.27, 0.27]) {
cylinder(0.085, 0.11, 0.65, 6, M.skin, x, 0.35, z, ox);
}
}
// ------------------------------------------------------------
// Cargo route and timeline
// ------------------------------------------------------------
const shipPositions = [
new THREE.Vector3(-4.25, 1.11, -2.45),
new THREE.Vector3(-5.40, 1.11, -1.45),
new THREE.Vector3(-4.25, 1.11, -0.45),
new THREE.Vector3(-5.40, 1.11, 0.55),
new THREE.Vector3(-4.25, 1.11, 1.55),
new THREE.Vector3(-5.40, 1.11, 2.55)
];
const quayPositions = shipPositions.map((_, i) =>
new THREE.Vector3(-0.15 + i * 0.76, 0.965, 0.65)
);
const warehousePositions = shipPositions.map((_, i) =>
new THREE.Vector3(6.3 + i * 1.03, 0.965, -1.25)
);
const SHIP_END = 4;
const UNLOAD_END = 11;
const HAUL_SEGMENT = 5.2;
const HAUL_END = UNLOAD_END + HAUL_SEGMENT * cargo.length;
const TOTAL_TIME = HAUL_END + 4;
let simulationTime = 0;
let paused = false;
let activeUIStage = -1;
const smooth = t => t * t * (3 - 2 * t);
const clamp01 = t => Math.max(0, Math.min(1, t));
function updateCargo(t) {
const cartLoadPosition = new THREE.Vector3();
if (t < SHIP_END) {
cargo.forEach((crate, i) => {
crate.position.copy(shipPositions[i]);
});
return;
}
// First stage: transfer all six crates from the ship to the quay.
if (t < UNLOAD_END) {
cargo.forEach((crate, i) => {
const start = SHIP_END + i * 1.12;
const end = start + 1.0;
if (t <= start) {
crate.position.copy(shipPositions[i]);
} else if (t < end) {
crate.position.lerpVectors(
shipPositions[i],
quayPositions[i],
smooth(clamp01((t - start) / (end - start)))
);
} else {
crate.position.copy(quayPositions[i]);
}
});
return;
}
// Second stage: the cart visits each crate in order.
cargo.forEach((crate, i) => {
const segmentStart = UNLOAD_END + i * HAUL_SEGMENT;
const segmentEnd = segmentStart + HAUL_SEGMENT;
if (t >= segmentEnd) {
crate.position.copy(warehousePositions[i]);
return;
}
if (t < segmentStart) {
crate.position.copy(quayPositions[i]);
return;
}
const local = t - segmentStart;
const pickupX = quayPositions[i].x;
const deliveryX = 8.2;
let cartX;
if (local < 0.8) {
cartX = THREE.MathUtils.lerp(
-0.7, pickupX, smooth(clamp01(local / 0.8))
);
} else if (local < 1.4) {
cartX = pickupX;
} else if (local < 3.1) {
cartX = THREE.MathUtils.lerp(
pickupX, deliveryX, smooth(clamp01((local - 1.4) / 1.7))
);
} else if (local < 3.6) {
cartX = deliveryX;
} else {
cartX = THREE.MathUtils.lerp(
deliveryX, -0.7, smooth(clamp01((local - 3.6) / 1.6))
);
}
cart.position.x = cartX;
cartLoadPosition.set(cartX, 1.35, 0.65);
if (local < 0.8) {
crate.position.copy(quayPositions[i]);
} else if (local < 1.4) {
crate.position.lerpVectors(
quayPositions[i],
cartLoadPosition,
smooth(clamp01((local - 0.8) / 0.6))
);
} else if (local < 3.1) {
crate.position.copy(cartLoadPosition);
} else if (local < 3.6) {
crate.position.lerpVectors(
cartLoadPosition,
warehousePositions[i],
smooth(clamp01((local - 3.1) / 0.5))
);
} else {
crate.position.copy(warehousePositions[i]);
}
});
}
function updateCrane(t) {
let activeCrate = null;
if (t >= SHIP_END && t < UNLOAD_END) {
activeCrate = cargo.find((_, i) => {
const start = SHIP_END + i * 1.12;
const end = start + 1.0;
return t >= start && t <= end;
});
}
craneRope.visible = !!activeCrate;
hook.visible = !!activeCrate;
if (!activeCrate) return;
const directionX = activeCrate.position.x - crane.position.x;
const directionZ = activeCrate.position.z - crane.position.z;
crane.rotation.y = Math.atan2(directionZ, -directionX);
crane.updateMatrixWorld(true);
const tip = new THREE.Vector3(-4.15, 4.13, 0);
crane.localToWorld(tip);
const hookPosition = activeCrate.position.clone();
hookPosition.y += 0.78;
const ropePositions = ropeGeometry.attributes.position;
ropePositions.setXYZ(0, tip.x, tip.y, tip.z);
ropePositions.setXYZ(1, hookPosition.x, hookPosition.y, hookPosition.z);
ropePositions.needsUpdate = true;
hook.position.copy(hookPosition);
}
const stageElement = document.getElementById("stage");
const progressElement = document.getElementById("progress");
const stageItems = [...document.querySelectorAll(".stage-item")];
function updateUI(t) {
let stage;
if (t < SHIP_END) stage = 0;
else if (t < UNLOAD_END) stage = 1;
else if (t < HAUL_END) stage = 2;
else stage = 3;
if (stage !== activeUIStage) {
activeUIStage = stage;
const names = [
"01 · Shipboard storage",
"02 · Quay transfer",
"03 · Cart road",
"04 · Warehouse storage"
];
stageElement.textContent = names[stage];
stageItems.forEach((item, i) => {
item.classList.toggle("active", i === stage);
});
}
progressElement.style.width = `${clamp01(t / TOTAL_TIME) * 100}%`;
}
// ------------------------------------------------------------
// Direct camera controls; no external control modules
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(2.2, 1.15, 0),
yaw: 0.78,
pitch: 0.86,
radius: 25,
desiredYaw: 0.78,
desiredPitch: 0.86,
desiredRadius: 25,
dragging: false,
lastX: 0,
lastY: 0
};
function applyCamera() {
const current = new THREE.Spherical(
controls.radius,
controls.pitch,
controls.yaw
);
const offset = new THREE.Vector3().setFromSpherical(current);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
}
renderer.domElement.addEventListener("pointerdown", event => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3();
camera.getWorldDirection(right);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3().crossVectors(
camera.up, right
).normalize();
const scale = controls.radius * 0.0012;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, -dy * scale);
} else {
controls.desiredYaw -= dx * 0.006;
controls.desiredPitch = THREE.MathUtils.clamp(
controls.desiredPitch - dy * 0.005,
0.34,
1.38
);
}
});
function stopDragging(event) {
controls.dragging = false;
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
11,
43
);
}, { passive: false });
addEventListener("keydown", event => {
if (event.key === "ArrowLeft") controls.desiredYaw += 0.1;
if (event.key === "ArrowRight") controls.desiredYaw -= 0.1;
if (event.key === "ArrowUp") controls.desiredPitch -= 0.07;
if (event.key === "ArrowDown") controls.desiredPitch += 0.07;
if (event.key === "+" || event.key === "=") {
controls.desiredRadius = Math.max(11, controls.desiredRadius - 1.5);
}
if (event.key === "-" || event.key === "_") {
controls.desiredRadius = Math.min(43, controls.desiredRadius + 1.5);
}
});
function resetCamera() {
controls.target.set(2.2, 1.15, 0);
controls.desiredYaw = 0.78;
controls.desiredPitch = 0.86;
controls.desiredRadius = 25;
}
// UI controls.
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
document.getElementById("replay").addEventListener("click", () => {
simulationTime = 0;
paused = false;
pauseButton.textContent = "Pause";
});
document.getElementById("home").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
let ambientTime = 0;
let frame = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
ambientTime += delta;
if (!paused) {
simulationTime += delta;
if (simulationTime > TOTAL_TIME) simulationTime = TOTAL_TIME;
}
updateCargo(simulationTime);
updateCrane(simulationTime);
updateUI(simulationTime);
// Gentle sea motion.
if (frame % 2 === 0) {
const positions = seaGeometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const z = positions.getZ(i);
positions.setY(
i,
Math.sin(x * 0.55 + z * 0.28 + ambientTime * 0.8) * 0.055 +
Math.cos(z * 0.72 - x * 0.16 + ambientTime * 0.55) * 0.035
);
}
positions.needsUpdate = true;
seaGeometry.computeVertexNormals();
}
// Gentle cloth movement.
sail.rotation.z = Math.sin(ambientTime * 0.75) * 0.018;
sail.position.x = Math.sin(ambientTime * 0.55) * 0.025;
// Camera smoothing.
controls.yaw = THREE.MathUtils.lerp(
controls.yaw, controls.desiredYaw, 0.09
);
controls.pitch = THREE.MathUtils.lerp(
controls.pitch, controls.desiredPitch, 0.09
);
controls.radius = THREE.MathUtils.lerp(
controls.radius, controls.desiredRadius, 0.09
);
applyCamera();
renderer.render(scene, camera);
frame++;
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
applyCamera();
updateCargo(0);
updateUI(0);
animate();
const loading = document.getElementById("loading");
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 450);
</script>
</body>
</html>
```