Prompt specification
Build or customize the Three.js 3D scene "One Container Ship-to-Quay Transfer" 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: One Container Ship-to-Quay Transfer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/one-container-ship-to-quay-transfer-x2122
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: one container ship-to-quay transfer. Animate a schematic crane moving one container between a ship bay and marked quay slot. Keep the load attached and avoid intersections with the ship structure.
Working Three.js Starter (one-container-ship-to-quay-transfer-x2122):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Ship-to-Quay Transfer</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(13, 25, 34, 0.82);
--border: rgba(255, 255, 255, 0.15);
--yellow: #ffd166;
--cyan: #69d2e7;
--muted: #a9bac5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fc4d2;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
color: #f5fbff;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 14px;
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 16px 18px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(19px, 2.5vw, 26px);
line-height: 1.12;
letter-spacing: -0.025em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#status-card {
top: 18px;
right: 18px;
width: min(290px, calc(100vw - 36px));
padding: 14px 16px;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
}
#status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--yellow);
box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.14);
}
#status-title {
font-size: 13px;
font-weight: 750;
}
#status-detail {
min-height: 34px;
margin-top: 8px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#timeline-card {
left: 50%;
bottom: 18px;
width: min(760px, calc(100vw - 36px));
padding: 14px 16px;
transform: translateX(-50%);
}
.timeline-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.timeline-label {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.buttons {
display: flex;
gap: 7px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 8px;
padding: 7px 11px;
color: #f5fbff;
background: rgba(255, 255, 255, 0.08);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.15);
}
button.primary {
border-color: rgba(255, 209, 102, 0.4);
color: #17212a;
background: var(--yellow);
}
#progress-track {
position: relative;
height: 7px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.11);
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--yellow));
transition: width 0.05s linear;
}
.timeline-footer {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 8px;
color: #8298a6;
font-size: 10px;
}
.world-label {
position: absolute;
left: 0;
top: 0;
display: none;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 6px;
color: #f7fcff;
background: rgba(12, 25, 35, 0.76);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
transform: translate(-50%, -50%);
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #edf8fc;
background: #91b7c7;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
#title-card {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
}
#status-card {
top: auto;
right: 10px;
bottom: 122px;
width: calc(100vw - 20px);
}
#timeline-card {
bottom: 10px;
width: calc(100vw - 20px);
}
.timeline-footer span:last-child {
display: none;
}
.subtitle {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated voxel container ship-to-quay transfer"></canvas>
<div id="hud">
<section id="title-card" class="panel">
<div class="eyebrow">Port Operations / Animation 04</div>
<h1>Ship-to-Quay Transfer</h1>
<p class="subtitle">
A single voxel container is lifted vertically clear of the ship bay,
traversed above the quay edge, and lowered into marked slot Q-01.
</p>
</section>
<section id="status-card" class="panel" aria-live="polite">
<div class="status-row">
<span id="status-dot"></span>
<span id="status-title">Preparing transfer</span>
</div>
<div id="status-detail">Initializing port equipment…</div>
</section>
<section id="timeline-card" class="panel">
<div class="timeline-top">
<div class="timeline-label">Transfer Sequence</div>
<div class="buttons">
<button id="play-button" class="primary" type="button">Pause</button>
<button id="reset-button" type="button">Reset</button>
</div>
</div>
<div id="progress-track">
<div id="progress-fill"></div>
</div>
<div class="timeline-footer">
<span>Drag to orbit · Wheel/pinch to zoom · Double-click resets view</span>
<span>18.4 s cycle</span>
</div>
</section>
<div id="ship-label" class="world-label">SHIP / BAY A-03</div>
<div id="quay-label" class="world-label">QUAY / SLOT Q-01</div>
</div>
<div id="loading">Loading voxel port…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9fc4d2);
scene.fog = new THREE.Fog(0x9fc4d2, 42, 82);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const camera = new THREE.OrthographicCamera(-18, 18, 10, -10, 0.1, 100);
const hemi = new THREE.HemisphereLight(0xdff3ff, 0x536a61, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.1);
sun.position.set(-14, 23, 15);
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 = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ec9e6, 0.65);
fill.position.set(18, 9, -16);
scene.add(fill);
// Shared unit cube keeps the scene compact.
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, roughness = 0.82, metalness = 0.04) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
})
);
}
return materialCache.get(key);
}
function makeBox(parent, size, position, mat, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function box(
parent,
size,
position,
color,
roughness = 0.82,
metalness = 0.04
) {
return makeBox(
parent,
size,
position,
material(color, roughness, metalness),
true,
true
);
}
function group(parent = scene) {
const g = new THREE.Group();
parent.add(g);
return g;
}
function beamBetween(parent, a, b, width, color) {
const av = new THREE.Vector3(...a);
const bv = new THREE.Vector3(...b);
const direction = bv.clone().sub(av);
const length = direction.length();
const midpoint = av.clone().add(bv).multiplyScalar(0.5);
const beam = box(
parent,
[length, width, width],
midpoint.toArray(),
color,
0.72,
0.16
);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.normalize()
);
return beam;
}
function markingRect(parent, cx, cz, length, width, y, color) {
const t = 0.09;
const h = 0.025;
box(
parent,
[length, h, t],
[cx, y, cz - width / 2],
color,
0.65
);
box(
parent,
[length, h, t],
[cx, y, cz + width / 2],
color,
0.65
);
box(
parent,
[t, h, width],
[cx - length / 2, y, cz],
color,
0.65
);
box(
parent,
[t, h, width],
[cx + length / 2, y, cz],
color,
0.65
);
}
// -------------------------------------------------------------------------
// World dimensions
// -------------------------------------------------------------------------
const BAY_Z = -1.2;
const SLOT_Z = 4.8;
const SHIP_DECK_Y = 1.15;
const QUAY_Y = 1.35;
const CONTAINER_LENGTH = 2.6;
const CONTAINER_HEIGHT = 1.35;
const CONTAINER_WIDTH = 1.35;
// -------------------------------------------------------------------------
// Water and quay
// -------------------------------------------------------------------------
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x4b9fb2,
roughness: 0.34,
metalness: 0.12,
transparent: true,
opacity: 0.94
});
makeBox(
scene,
[46, 0.42, 34],
[0, -0.63, 2],
waterMaterial,
false,
true
);
const waves = [];
const waveMaterial = new THREE.MeshStandardMaterial({
color: 0x9ed8df,
roughness: 0.5,
transparent: true,
opacity: 0.48
});
for (let i = 0; i < 30; i++) {
const x = -21 + ((i * 5.17) % 42);
const z = -12 + ((i * 3.71) % 25);
const wave = makeBox(
scene,
[1.1 + (i % 4) * 0.45, 0.025, 0.10],
[x, -0.405, z],
waveMaterial,
false,
false
);
wave.userData.baseX = x;
wave.userData.baseZ = z;
wave.userData.phase = i * 0.71;
waves.push(wave);
}
const quay = group();
box(quay, [30, 2.4, 8.5], [0, 0, 6.75], 0x59656a);
box(quay, [30, 0.15, 8.5], [0, 1.275, 6.75], 0x8a9291);
// Concrete panel seams.
for (let x = -13; x <= 13; x += 2.6) {
box(
quay,
[0.025, 0.012, 8.35],
[x, QUAY_Y + 0.009, 6.75],
0x717d7d,
0.95
);
}
// Quay edge and alternating hazard blocks.
box(quay, [30, 0.42, 0.28], [0, 1.12, 2.46], 0x303c42);
for (let x = -14.25; x < 14.5; x += 0.75) {
box(
quay,
[0.7, 0.055, 0.30],
[x, QUAY_Y + 0.03, 2.47],
Math.round((x + 14.25) / 0.75) % 2 === 0
? 0xf2c14e
: 0x25333a,
0.72
);
}
// Crane rails.
for (const z of [2.85, 7.15]) {
box(quay, [28.5, 0.06, 0.14], [0, QUAY_Y + 0.03, z], 0x25343b, 0.42, 0.45);
}
// Marked destination slot.
markingRect(
quay,
0,
SLOT_Z,
3.45,
2.05,
QUAY_Y + 0.025,
0xffd166
);
// Small corner alignment blocks around the slot.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
quay,
[0.30, 0.10, 0.30],
[sx * 1.86, QUAY_Y + 0.05, SLOT_Z + sz * 1.15],
0xffd166,
0.65
);
}
}
// Bollards and edge fenders.
for (const x of [-10, -6, 6, 10]) {
box(quay, [0.30, 0.58, 0.30], [x, QUAY_Y + 0.29, 3.25], 0x26343a, 0.58, 0.25);
box(quay, [0.38, 0.12, 0.38], [x, QUAY_Y + 0.60, 3.25], 0xf0b83e, 0.62, 0.20);
}
for (const x of [-8, -4, 4, 8]) {
box(quay, [0.46, 0.80, 0.36], [x, 0.70, 2.30], 0x1d292e, 0.95);
}
// -------------------------------------------------------------------------
// Voxel ship
// -------------------------------------------------------------------------
const ship = group();
ship.position.z = BAY_Z;
// Lower hull, upper hull, and stepped bow.
box(ship, [16.4, 1.0, 4.2], [-0.4, -0.05, 0], 0x9d3d35, 0.74, 0.08);
box(ship, [16.4, 0.55, 4.15], [-0.4, 0.58, 0], 0x263d4b, 0.72, 0.16);
box(ship, [1.1, 1.0, 3.45], [-8.85, -0.05, 0], 0x9d3d35, 0.74, 0.08);
box(ship, [1.1, 0.55, 3.40], [-8.85, 0.58, 0], 0x263d4b, 0.72, 0.16);
box(ship, [0.8, 1.0, 3.85], [8.2, -0.05, 0], 0x9d3d35, 0.74, 0.08);
box(ship, [0.8, 0.55, 3.80], [8.2, 0.58, 0], 0x263d4b, 0.72, 0.16);
box(ship, [0.8, 1.0, 2.90], [8.9, -0.05, 0], 0x9d3d35, 0.74, 0.08);
box(ship, [0.8, 0.55, 2.85], [8.9, 0.58, 0], 0x263d4b, 0.72, 0.16);
box(ship, [0.65, 1.0, 1.85], [9.58, -0.05, 0], 0x9d3d35, 0.74, 0.08);
box(ship, [0.65, 0.55, 1.80], [9.58, 0.58, 0], 0x263d4b, 0.72, 0.16);
// Main deck.
box(ship, [16.45, 0.30, 4.0], [-0.4, 1.0, 0], 0x68777a, 0.9);
// Stepped bow deck.
box(ship, [0.8, 0.30, 3.80], [8.2, 1.0, 0], 0x68777a, 0.9);
box(ship, [0.8, 0.30, 2.85], [8.9, 1.0, 0], 0x68777a, 0.9);
box(ship, [0.65, 0.30, 1.80], [9.58, 1.0, 0], 0x68777a, 0.9);
// Low side walls. They remain outside the moving container's z corridor.
for (const z of [-2.03, 2.03]) {
box(ship, [16.35, 0.90, 0.18], [-0.4, 1.30, z], 0x324955, 0.76, 0.12);
box(ship, [16.35, 0.08, 0.24], [-0.4, 1.78, z], 0xd8e1df, 0.68);
}
// Stern superstructure.
box(ship, [2.45, 2.05, 3.05], [-7.10, 2.175, 0], 0xd9dfdc, 0.8);
box(ship, [2.70, 0.80, 3.25], [-7.10, 3.60, 0], 0xe9ece7, 0.74);
box(ship, [2.20, 0.72, 2.55], [-7.10, 4.35, 0], 0xc9d2d0, 0.8);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x173b4a,
roughness: 0.22,
metalness: 0.35
});
for (let z = -1.1; z <= 1.1; z += 0.55) {
makeBox(
ship,
[0.035, 0.36, 0.40],
[-5.735, 3.67, z],
glassMaterial,
false,
false
);
}
box(ship, [0.55, 1.05, 0.60], [-7.50, 5.15, -0.65], 0xd25d45, 0.76, 0.12);
box(ship, [0.08, 1.70, 0.08], [-6.85, 5.50, 0.55], 0xdfe5df, 0.66, 0.25);
box(ship, [0.62, 0.08, 0.08], [-6.85, 6.08, 0.55], 0xdfe5df, 0.66, 0.25);
// Bay A-03 markings.
markingRect(
ship,
0,
0,
3.12,
1.80,
SHIP_DECK_Y + 0.018,
0xf2c14e
);
// -------------------------------------------------------------------------
// Container geometry
// -------------------------------------------------------------------------
function makeContainer(color, accent = 0xe7ecec) {
const g = group();
const L = CONTAINER_LENGTH;
const H = CONTAINER_HEIGHT;
const W = CONTAINER_WIDTH;
// Main voxel body.
box(g, [L, H, W], [0, H / 2, 0], color, 0.76, 0.08);
// Top and bottom rails.
box(g, [L, 0.10, W + 0.07], [0, 0.05, 0], 0x44535a, 0.62, 0.18);
box(g, [L, 0.10, W + 0.07], [0, H - 0.05, 0], 0x44535a, 0.62, 0.18);
// Corrugated side ribs.
for (const side of [-1, 1]) {
for (let i = 0; i < 11; i++) {
const x = -L / 2 + 0.14 + (i * (L - 0.28)) / 10;
box(
g,
[0.055, H - 0.20, 0.045],
[x, H / 2, side * (W / 2 + 0.022)],
accent,
0.74,
0.12
);
}
}
// Corner posts.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
g,
[0.13, H, 0.13],
[sx * (L / 2 - 0.065), H / 2, sz * (W / 2 - 0.065)],
0x46555c,
0.58,
0.22
);
}
}
// Door end and locking bars.
for (const side of [-1, 1]) {
box(
g,
[0.055, H - 0.18, W * 0.46],
[-L / 2 - 0.027, H / 2, side * W * 0.23],
accent,
0.78,
0.12
);
}
for (const z of [-0.37, 0.37]) {
box(
g,
[0.055, H - 0.22, 0.055],
[-L / 2 - 0.075, H / 2, z],
0x34444b,
0.50,
0.32
);
}
return g;
}
// Static ship cargo establishes scale while leaving the x=0 lane clear.
const staticCargo = [
{ x: -4.2, z: 0, bottom: SHIP_DECK_Y, color: 0x3f7f91 },
{ x: 3.7, z: 0, bottom: SHIP_DECK_Y, color: 0x6c8e5e },
{
x: 3.7,
z: 0,
bottom: SHIP_DECK_Y + CONTAINER_HEIGHT,
color: 0x3d6f78
},
{ x: 6.4, z: 0, bottom: SHIP_DECK_Y, color: 0xb88448 }
];
for (const item of staticCargo) {
const c = makeContainer(item.color);
c.position.set(item.x, item.bottom, item.z);
ship.add(c);
}
// The only moving load.
const movingContainer = makeContainer(0xe85d42, 0xffb08f);
scene.add(movingContainer);
// -------------------------------------------------------------------------
// Schematic ship-to-shore gantry crane
// -------------------------------------------------------------------------
const crane = group();
const CRANE_ORANGE = 0xf0a52b;
const CRANE_DARK = 0x263943;
const legXs = [-3.35, 3.35];
const legZs = [2.85, 7.15];
const legBottom = QUAY_Y;
const legTop = 9.08;
const legHeight = legTop - legBottom;
for (const x of legXs) {
for (const z of legZs) {
box(
crane,
[0.58, legHeight, 0.58],
[x, legBottom + legHeight / 2, z],
CRANE_ORANGE,
0.66,
0.18
);
// Bogie and rail shoe.
box(crane, [1.25, 0.28, 0.85], [x, QUAY_Y + 0.14, z], CRANE_DARK, 0.52, 0.30);
box(crane, [0.74, 0.18, 0.72], [x, QUAY_Y + 0.38, z], 0x52616a, 0.50, 0.32);
}
}
// Portal crossbeams.
for (const z of legZs) {
box(crane, [7.25, 0.48, 0.60], [0, 9.25, z], CRANE_ORANGE, 0.65, 0.18);
beamBetween(
crane,
[-3.35, 7.20, z],
[-0.65, 9.05, z],
0.17,
CRANE_ORANGE
);
beamBetween(
crane,
[3.35, 7.20, z],
[0.65, 9.05, z],
0.17,
CRANE_ORANGE
);
}
// Water-side cantilever boom. It runs directly above the load path.
const boomStartZ = -3.50;
const boomEndZ = 7.15;
const boomLength = boomEndZ - boomStartZ;
const boomCenterZ = (boomStartZ + boomEndZ) / 2;
box(
crane,
[0.72, 0.48, boomLength],
[0, 9.25, boomCenterZ],
CRANE_ORANGE,
0.65,
0.18
);
// Dark trolley rails.
for (const x of [-0.28, 0.28]) {
box(
crane,
[0.075, 0.07, boomLength],
[x, 9.52, boomCenterZ],
CRANE_DARK,
0.38,
0.48
);
}
// Twin upper masts, positioned away from the central trolley lane.
for (const x of [-2.15, 2.15]) {
box(crane, [0.32, 3.15, 0.36], [x, 10.98, 2.85], CRANE_ORANGE, 0.68, 0.18);
}
box(crane, [4.60, 0.32, 0.38], [0, 12.42, 2.85], CRANE_ORANGE, 0.68, 0.18);
// Boom support stays.
beamBetween(
crane,
[-2.15, 12.20, 2.85],
[0, 9.48, -3.20],
0.105,
0x52636b
);
beamBetween(
crane,
[2.15, 12.20, 2.85],
[0, 9.48, -3.20],
0.105,
0x52636b
);
// Operator cabin, offset from the x=0 load corridor.
box(crane, [1.10, 1.20, 1.25], [2.72, 8.12, 6.80], CRANE_ORANGE, 0.62, 0.18);
makeBox(
crane,
[0.04, 0.60, 0.90],
[3.285, 8.28, 6.80],
glassMaterial,
false,
false
);
// Counterweights on the landside beam.
for (const x of [-2.55, 2.55]) {
box(crane, [1.35, 0.72, 1.00], [x, 8.65, 7.15], 0x59666b, 0.72, 0.25);
}
// Trolley.
const trolley = group();
box(trolley, [1.25, 0.46, 1.20], [0, 0, 0], CRANE_ORANGE, 0.58, 0.28);
box(trolley, [0.72, 0.28, 0.72], [0, -0.28, 0], CRANE_DARK, 0.48, 0.35);
for (const x of [-0.43, 0.43]) {
for (const z of [-0.38, 0.38]) {
box(
trolley,
[0.18, 0.22, 0.25],
[x, -0.23, z],
0x18262c,
0.40,
0.45
);
}
}
const beaconMaterial = new THREE.MeshStandardMaterial({
color: 0xffbf36,
emissive: 0xff7a00,
emissiveIntensity: 1.4,
roughness: 0.35
});
makeBox(
trolley,
[0.22, 0.20, 0.22],
[0, 0.34, 0],
beaconMaterial,
false,
false
);
// Spreader frame.
const spreader = group();
box(spreader, [2.90, 0.18, 0.24], [0, 0, 0], 0xffca3a, 0.55, 0.28);
box(spreader, [2.90, 0.18, 0.24], [0, 0, -0.62], 0xffca3a, 0.55, 0.28);
box(spreader, [2.90, 0.18, 0.24], [0, 0, 0.62], 0xffca3a, 0.55, 0.28);
box(spreader, [0.22, 0.18, 1.45], [-1.32, 0, 0], 0xffca3a, 0.55, 0.28);
box(spreader, [0.22, 0.18, 1.45], [1.32, 0, 0], 0xffca3a, 0.55, 0.28);
for (const x of [-1.32, 1.32]) {
for (const z of [-0.62, 0.62]) {
box(
spreader,
[0.20, 0.18, 0.20],
[x, -0.12, z],
0x38474d,
0.48,
0.35
);
}
}
// Four hoist ropes.
const ropes = [];
const ropeMaterial = material(0x25343a, 0.45, 0.40);
for (const x of [-1.12, 1.12]) {
for (const z of [-0.58, 0.58]) {
const rope = makeBox(
scene,
[0.045, 1, 0.045],
[x, 5, z],
ropeMaterial,
true,
false
);
ropes.push({ mesh: rope, x, z });
}
}
// -------------------------------------------------------------------------
// Transfer animation
//
// Collision-safe route:
// 1. Spreader descends directly onto the container in the open bay.
// 2. Container rises to bottom y=5.2, well above all ship-side structure.
// 3. Trolley travels in z at constant height.
// 4. Container lowers into the empty marked quay slot.
//
// The moving load stays geometrically attached to the spreader after lock.
// -------------------------------------------------------------------------
const DURATION = 18.4;
const ATTACH_TIME = 2.4;
const LIFT_START = 2.9;
const TRAVEL_START = 6.5;
const TRAVEL_END = 12.3;
const LOWER_END = 16.4;
const attachY = SHIP_DECK_Y + CONTAINER_HEIGHT + 0.10;
const transferY = 6.65;
const finalY = QUAY_Y + CONTAINER_HEIGHT + 0.10;
let elapsed = 0;
let playing = true;
let lastFrame = performance.now();
const statusTitle = document.querySelector("#status-title");
const statusDetail = document.querySelector("#status-detail");
const progressFill = document.querySelector("#progress-fill");
const playButton = document.querySelector("#play-button");
const resetButton = document.querySelector("#reset-button");
function clamp01(value) {
return Math.min(1, Math.max(0, value));
}
function smooth(value) {
const x = clamp01(value);
return x * x * (3 - 2 * x);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function setStatus(title, detail) {
if (statusTitle.textContent !== title) {
statusTitle.textContent = title;
statusDetail.textContent = detail;
}
}
function updateTransfer(time) {
let spreaderY;
let trolleyZ;
if (time < ATTACH_TIME) {
const p = smooth(time / ATTACH_TIME);
spreaderY = lerp(4.20, attachY, p);
trolleyZ = BAY_Z;
} else if (time < LIFT_START) {
spreaderY = attachY;
trolleyZ = BAY_Z;
} else if (time < TRAVEL_START) {
const p = smooth((time - LIFT_START) / (TRAVEL_START - LIFT_START));
spreaderY = lerp(attachY, transferY, p);
trolleyZ = BAY_Z;
} else if (time < TRAVEL_END) {
const p = smooth((time - TRAVEL_START) / (TRAVEL_END - TRAVEL_START));
spreaderY = transferY;
trolleyZ = lerp(BAY_Z, SLOT_Z, p);
} else if (time < LOWER_END) {
const p = smooth((time - TRAVEL_END) / (LOWER_END - TRAVEL_END));
spreaderY = lerp(transferY, finalY, p);
trolleyZ = SLOT_Z;
} else {
spreaderY = finalY;
trolleyZ = SLOT_Z;
}
spreader.position.set(0, spreaderY, trolleyZ);
trolley.position.set(0, 9.77, trolleyZ);
// Before lock, the container remains on the ship deck. After lock,
// its transform is derived directly from the spreader transform.
const loadBottom =
time < ATTACH_TIME
? SHIP_DECK_Y
: spreaderY - 0.10 - CONTAINER_HEIGHT;
movingContainer.position.set(0, loadBottom, trolleyZ);
// Update the four vertical hoist ropes.
const ropeTop = 9.48;
const ropeBottom = spreaderY + 0.12;
const ropeLength = Math.max(0.05, ropeTop - ropeBottom);
for (const rope of ropes) {
rope.mesh.position.set(
rope.x,
(ropeTop + ropeBottom) / 2,
trolleyZ + rope.z
);
rope.mesh.scale.set(0.045, ropeLength, 0.045);
}
progressFill.style.width = `${clamp01(time / DURATION) * 100}%`;
if (time < ATTACH_TIME) {
setStatus(
"Lowering spreader",
"The spreader approaches the container directly above the open ship bay."
);
} else if (time < LIFT_START) {
setStatus(
"Load locked",
"The spreader and container are locked together and ready to lift."
);
} else if (time < TRAVEL_START) {
setStatus(
"Hoisting clear",
"The load rises vertically above the deck and nearby cargo stacks."
);
} else if (time < TRAVEL_END) {
setStatus(
"Trolley transfer",
"The attached load travels at constant height across the quay edge."
);
} else if (time < LOWER_END) {
setStatus(
"Lowering to quay",
"The container descends into the empty marked slot Q-01."
);
} else {
setStatus(
"Transfer complete",
"Container Q-01 is seated in the marked quay slot; the spreader remains attached."
);
}
}
// -------------------------------------------------------------------------
// Custom orthographic orbit and zoom controls
// -------------------------------------------------------------------------
const cameraState = {
azimuth: 0.78,
polar: 1.03,
zoom: 1.0,
target: new THREE.Vector3(0, 3.25, 1.0)
};
function updateCamera() {
const radius = 36;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x + radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + radius * Math.cos(cameraState.azimuth === undefined ? 0 : cameraState.polar),
cameraState.target.z + radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.azimuth = 0.78;
cameraState.polar = 1.03;
cameraState.zoom = 1.0;
updateCamera();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
let frustumWidth = 35.6;
let frustumHeight = 20;
if (aspect < 1.2) {
frustumWidth = 34;
frustumHeight = frustumWidth / aspect;
} else {
frustumHeight = 20;
frustumWidth = frustumHeight * aspect;
}
camera.left = -frustumWidth / 2;
camera.right = frustumWidth / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
updateCamera();
}
window.addEventListener("resize", resize);
const pointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
if (pointers.size >= 2) {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (distance / pinchDistance),
0.65,
1.85
);
updateCamera();
}
pinchDistance = distance;
} else {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.48,
1.38
);
updateCamera();
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.85
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// -------------------------------------------------------------------------
// Playback controls
// -------------------------------------------------------------------------
playButton.addEventListener("click", () => {
if (elapsed >= DURATION) {
elapsed = 0;
playing = true;
} else {
playing = !playing;
}
updatePlayButton();
});
resetButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
updatePlayButton();
});
function updatePlayButton() {
playButton.textContent =
elapsed >= DURATION ? "Replay" : playing ? "Pause" : "Play";
}
// -------------------------------------------------------------------------
// Projected scene labels
// -------------------------------------------------------------------------
const shipLabel = document.querySelector("#ship-label");
const quayLabel = document.querySelector("#quay-label");
const projected = new THREE.Vector3();
function placeLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
function animate(now) {
const dt = Math.min((now - lastFrame) / 1000, 0.05);
lastFrame = now;
if (playing) {
elapsed = Math.min(DURATION, elapsed + dt);
if (elapsed >= DURATION) {
playing = false;
updatePlayButton();
}
}
updateTransfer(elapsed);
// Gentle voxel-water shimmer.
for (const wave of waves) {
wave.position.x =
wave.userData.baseX + Math.sin(now * 0.00055 + wave.userData.phase) * 0.28;
wave.position.z =
wave.userData.baseZ + Math.cos(now * 0.00042 + wave.userData.phase) * 0.14;
}
updateCamera();
placeLabel(shipLabel, -0.8, 4.20, BAY_Z);
placeLabel(quayLabel, 1.45, 2.25, SLOT_Z);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
resetCamera();
updateTransfer(0);
updatePlayButton();
loading.style.display = "none";
requestAnimationFrame(animate);
</script>
</body>
</html>
```