Prompt specification
Build or customize the Three.js 3D scene "Port terminal with road rail and ship edges" 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 terminal with road rail and ship edges
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/port-terminal-with-road-rail-and-ship-edges-x2531
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build a small container terminal with three transport modes and a short storage stack. Keep routes separate and trace one identified container through the complete transfer chain.
Working Three.js Starter (port-terminal-with-road-rail-and-ship-edges-x2531):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Terminal 07 — Intermodal Transfer</title>
<style>
:root {
--ink: #13242d;
--muted: #61747d;
--paper: rgba(248, 250, 248, 0.9);
--line: rgba(28, 54, 64, 0.13);
--orange: #ff6938;
--vessel: #36bdb6;
--road: #efb34d;
--rail: #df6c8d;
--shadow: 0 18px 55px rgba(22, 43, 53, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e6e8;
color: var(--ink);
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;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
header {
position: absolute;
top: 24px;
left: 26px;
display: flex;
align-items: flex-start;
gap: 18px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--orange);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 37px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 850;
}
.subtitle {
margin-top: 8px;
max-width: 360px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
position: absolute;
top: 24px;
right: 25px;
width: 190px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
backdrop-filter: blur(14px);
box-shadow: var(--shadow);
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 8px;
font-size: 11px;
font-weight: 650;
}
.legend-line {
width: 22px;
height: 3px;
border-radius: 99px;
background: var(--color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--color) 15%, transparent);
}
.legend-row.active .legend-line {
box-shadow: 0 0 0 5px color-mix(in srgb, var(--color) 22%, transparent);
}
.legend-note {
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.cargo-tag {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px 7px 8px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 9px;
background: rgba(255, 105, 56, 0.94);
color: white;
box-shadow: 0 8px 24px rgba(114, 50, 25, 0.2);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.07em;
transform: translate(-50%, -125%);
white-space: nowrap;
transition: opacity 120ms ease;
}
.cargo-tag::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 10px;
height: 10px;
background: var(--orange);
transform: translateX(-50%) rotate(45deg);
}
.cargo-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: white;
}
.bottom-panel {
position: absolute;
left: 50%;
bottom: 20px;
width: min(1050px, calc(100% - 34px));
padding: 15px 17px 13px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 18px;
background: rgba(248, 250, 248, 0.91);
backdrop-filter: blur(18px);
box-shadow: var(--shadow);
transform: translateX(-50%);
pointer-events: auto;
}
.panel-top {
display: grid;
grid-template-columns: minmax(175px, 0.8fr) minmax(450px, 2fr) auto;
align-items: center;
gap: 20px;
}
.sequence-label {
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.sequence-name {
margin-top: 3px;
font-size: 13px;
font-weight: 800;
}
.stages {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 5px;
}
.stage {
position: relative;
min-width: 0;
padding: 7px 5px 8px;
border: 0;
border-radius: 9px;
background: transparent;
color: #809097;
cursor: pointer;
text-align: left;
transition: 160ms ease;
}
.stage:hover {
background: rgba(20, 47, 58, 0.05);
color: var(--ink);
}
.stage::before {
content: "";
display: block;
width: 100%;
height: 3px;
margin-bottom: 7px;
border-radius: 99px;
background: #d9e1df;
}
.stage.active {
color: var(--ink);
background: rgba(255, 105, 56, 0.08);
}
.stage.active::before {
background: var(--orange);
}
.stage.done::before {
background: #9fc5ba;
}
.stage-number {
display: block;
margin-bottom: 2px;
color: #9aa8ad;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
}
.stage-name {
display: block;
overflow: hidden;
font-size: 9px;
font-weight: 750;
text-overflow: ellipsis;
white-space: nowrap;
}
.controls {
display: flex;
align-items: center;
gap: 7px;
}
button.control {
height: 34px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: white;
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
transition: 150ms ease;
}
button.control:hover {
border-color: rgba(255, 105, 56, 0.4);
transform: translateY(-1px);
}
button.primary {
min-width: 72px;
border-color: var(--orange);
background: var(--orange);
color: white;
}
.scrub-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 13px;
margin-top: 10px;
}
input[type="range"] {
width: 100%;
height: 3px;
margin: 0;
border-radius: 99px;
appearance: none;
background: linear-gradient(
to right,
var(--orange) 0%,
var(--orange) var(--progress, 0%),
#d7dfdd var(--progress, 0%),
#d7dfdd 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--orange);
box-shadow: 0 2px 8px rgba(34, 49, 54, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 8px;
height: 8px;
border: 3px solid white;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 2px 8px rgba(34, 49, 54, 0.25);
}
.time-readout {
min-width: 74px;
color: var(--muted);
font-size: 9px;
font-variant-numeric: tabular-nums;
font-weight: 750;
text-align: right;
}
.camera-hint {
position: absolute;
right: 26px;
bottom: 151px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(248, 250, 248, 0.75);
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 800px) {
header {
top: 15px;
left: 16px;
}
.subtitle,
.legend-note,
.camera-hint {
display: none;
}
.legend {
top: 14px;
right: 14px;
width: 145px;
padding: 11px;
}
.bottom-panel {
bottom: 10px;
width: calc(100% - 20px);
padding: 12px;
}
.panel-top {
grid-template-columns: 1fr auto;
gap: 10px;
}
.stages {
grid-column: 1 / -1;
grid-row: 2;
}
.stage-name {
font-size: 8px;
}
.stage-number {
display: none;
}
.sequence-label {
display: none;
}
.sequence-name {
font-size: 11px;
}
}
</style>
</head>
<body>
<div class="hud">
<header>
<div>
<div class="eyebrow">Intermodal operations / terminal 07</div>
<h1>One box.<br />Three journeys.</h1>
<div class="subtitle">
Follow container <strong>CX-204</strong> from vessel to yard,
road, and finally the rail departure.
</div>
</div>
</header>
<aside class="legend">
<div class="legend-title">Separated corridors</div>
<div class="legend-row" style="--color: var(--vessel)">
<span class="legend-line"></span><span>Vessel channel</span>
</div>
<div class="legend-row" style="--color: var(--road)">
<span class="legend-line"></span><span>Road corridor</span>
</div>
<div class="legend-row" style="--color: var(--rail)">
<span class="legend-line"></span><span>Rail corridor</span>
</div>
<div class="legend-note">
The highlighted orange unit is tracked continuously through every handoff.
</div>
</aside>
<div id="cargoTag" class="cargo-tag">
<span class="cargo-dot"></span>
<span>CX-204</span>
</div>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<section class="bottom-panel">
<div class="panel-top">
<div>
<div class="sequence-label">Current operation</div>
<div id="sequenceName" class="sequence-name">Vessel approach</div>
</div>
<div id="stages" class="stages"></div>
<div class="controls">
<button id="playButton" class="control primary" type="button">Pause</button>
<button id="restartButton" class="control" type="button">Restart</button>
<button id="cameraButton" class="control" type="button">Camera</button>
</div>
</div>
<div class="scrub-row">
<input id="timeline" type="range" min="0" max="1000" value="0" />
<div id="timeReadout" class="time-readout">00.0 / 18.2s</div>
</div>
</section>
</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, and custom camera controls
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e6e8);
scene.fog = new THREE.Fog(0xd9e6e8, 42, 78);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8f6ff, 0x8d8066, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d4, 3.0);
sun.position.set(-13, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -35;
sun.shadow.camera.right = 35;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const cameraTarget = new THREE.Vector3(-1.1, 1.4, 0);
let cameraTheta = 0.64;
let cameraPhi = 0.79;
let cameraRadius = 38;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTheta = 0.64;
cameraPhi = 0.79;
cameraRadius = 38;
updateCamera();
}
updateCamera();
const pointers = new Map();
let previousPinchDistance = 0;
let orbiting = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
orbiting = true;
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && orbiting) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi + dy * 0.005, 0.28, 1.35);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (previousPinchDistance / distance),
19,
62
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
orbiting = pointers.size === 1;
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
19,
62
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Materials and modeling helpers
// -------------------------------------------------------------------------
const COLORS = {
orange: 0xff6938,
orangeDark: 0xd94b25,
asphalt: 0x34464d,
concrete: 0xc6c1af,
concreteLight: 0xded9c7,
steel: 0x40515a,
dark: 0x23333b,
crane: 0xe4aa3f,
teal: 0x3c8f8b,
blue: 0x477b9a,
red: 0xad5c50,
cream: 0xe9e4d4,
green: 0x718d70
};
const materials = {};
for (const [key, color] of Object.entries(COLORS)) {
materials[key] = new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.05
});
}
function addBox(parent, size, position, material, shadows = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = shadows;
mesh.receiveShadow = shadows;
parent.add(mesh);
return mesh;
}
function beam(parent, start, end, thickness, material) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(length, thickness, thickness),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radius,
height,
position,
material,
radialSegments = 8,
rotation = [0, 0, 0]
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, radialSegments),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabelTexture(text, background = "#ff6938", foreground = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = foreground;
context.font = "800 76px Arial";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 82);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function createContainer(color, label = null) {
const group = new THREE.Group();
const length = 3.2;
const height = 1.2;
const depth = 1.25;
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.08
});
addBox(group, [length, height, depth], [0, 0, 0], bodyMaterial);
// Corrugated side ribs.
for (let i = 0; i < 17; i++) {
const x = -length / 2 + 0.18 + (i * (length - 0.36)) / 16;
for (const side of [-1, 1]) {
addBox(
group,
[0.055, height * 0.78, 0.045],
[x, 0, side * (depth / 2 + 0.018)],
bodyMaterial
);
}
}
// Top and bottom rails.
for (const side of [-1, 1]) {
addBox(
group,
[length + 0.04, 0.08, 0.08],
[0, side * (height / 2 - 0.03), depth / 2],
bodyMaterial
);
addBox(
group,
[length + 0.04, 0.08, 0.08],
[0, side * (height / 2 - 0.03), -depth / 2],
bodyMaterial
);
}
// Door hardware on one end.
for (const z of [-0.35, 0, 0.35]) {
addBox(
group,
[0.05, height * 0.82, 0.055],
[length / 2 + 0.025, 0, z],
materials.steel
);
}
if (label) {
const texture = makeLabelTexture(label);
const labelMaterial = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
});
const labelPlane = new THREE.Mesh(
new THREE.PlaneGeometry(2.05, 0.64),
labelMaterial
);
labelPlane.position.set(0.15, 0, depth / 2 + 0.055);
group.add(labelPlane);
}
return group;
}
function addWheel(parent, x, z, radius = 0.46) {
const wheel = addCylinder(
parent,
radius,
0.32,
[x, radius, z],
materials.dark,
10,
[Math.PI / 2, 0, 0]
);
return wheel;
}
function createTruck() {
const truck = new THREE.Group();
addBox(truck, [5.15, 0.32, 1.95], [-0.05, 0.72, 0], materials.dark);
addBox(truck, [3.55, 0.18, 1.85], [-0.7, 1.0, 0], materials.steel);
// Cab.
addBox(truck, [1.45, 1.45, 2.0], [1.85, 1.55, 0], materials.orange);
addBox(truck, [0.18, 0.72, 1.72], [2.58, 1.75, 0], materials.dark);
addBox(truck, [0.68, 0.12, 2.08], [1.75, 2.32, 0], materials.orange);
addBox(truck, [0.9, 0.44, 0.08], [1.88, 1.8, 1.015], materials.cream);
addBox(truck, [0.9, 0.44, 0.08], [1.88, 1.8, -1.015], materials.cream);
// Headlights.
for (const z of [-0.65, 0.65]) {
addBox(
truck,
[0.12, 0.24, 0.32],
[2.64, 1.25, z],
materials.cream
);
}
for (const x of [-1.8, -0.65, 1.75]) {
addWheel(truck, x, 1.03, 0.48);
addWheel(truck, x, -1.03, 0.48);
}
return truck;
}
function createFlatcar() {
const car = new THREE.Group();
addBox(car, [4.35, 0.25, 1.8], [0, 0.98, 0], materials.steel);
for (const x of [-1.35, 1.35]) {
for (const z of [-0.88, 0.88]) {
addWheel(car, x, z, 0.37);
}
}
for (const z of [-0.8, 0.8]) {
addBox(car, [4.15, 0.16, 0.16], [0, 1.17, z], materials.dark);
}
return car;
}
function createLocomotive() {
const loco = new THREE.Group();
addBox(loco, [3.6, 0.35, 2.0], [0, 0.76, 0], materials.dark);
addBox(loco, [3.3, 1.65, 1.9], [-0.05, 1.68, 0], materials.blue);
addBox(loco, [1.25, 1.15, 1.84], [0.85, 2.95, 0], materials.blue);
addBox(loco, [1.1, 0.5, 1.9], [0.83, 3.08, 0], materials.dark);
addBox(loco, [0.4, 0.75, 1.76], [1.52, 2.38, 0], materials.orange);
addBox(loco, [3.15, 0.15, 1.72], [-0.1, 2.65, 0], materials.steel);
for (const x of [-1.15, 0.95]) {
for (const z of [-0.98, 0.98]) {
addWheel(loco, x, z, 0.43);
}
}
return loco;
}
// -------------------------------------------------------------------------
// Terminal base, water, roads, rail, and routes
// -------------------------------------------------------------------------
const terminal = new THREE.Group();
scene.add(terminal);
const water = new THREE.Mesh(
new THREE.PlaneGeometry(34, 42),
new THREE.MeshStandardMaterial({
color: 0x4d9da5,
roughness: 0.44,
metalness: 0.06
})
);
water.rotation.x = -Math.PI / 2;
water.position.set(-17, -0.34, 0);
water.receiveShadow = true;
scene.add(water);
// Low-poly water glints.
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0xbce0dc,
transparent: true,
opacity: 0.25
});
const waves = [];
for (let i = 0; i < 30; i++) {
const wave = new THREE.Mesh(
new THREE.PlaneGeometry(0.8 + Math.random() * 2.1, 0.1),
waveMaterial
);
wave.rotation.x = -Math.PI / 2;
wave.rotation.z = (Math.random() - 0.5) * 0.8;
wave.position.set(
-29 + Math.random() * 22,
-0.29,
-17 + Math.random() * 34
);
scene.add(wave);
waves.push(wave);
}
addBox(
terminal,
[23.2, 0.55, 18],
[5.7, -0.28, 0],
materials.concrete
);
addBox(
terminal,
[23.2, 0.12, 18],
[5.7, 0.035, 0],
materials.concreteLight
);
// Quay edge and fenders.
addBox(terminal, [0.55, 1.1, 18], [-5.95, -0.05, 0], materials.steel);
for (let z = -7.5; z <= 7.5; z += 2.5) {
addBox(
terminal,
[0.22, 1.35, 0.8],
[-6.31, 0.15, z],
materials.dark
);
}
// Dedicated road corridor.
addBox(
terminal,
[20.5, 0.08, 3.35],
[6.0, 0.13, 4.8],
materials.asphalt
);
for (let x = -3.8; x < 16; x += 2.1) {
addBox(
terminal,
[1.05, 0.025, 0.09],
[x, 0.19, 4.8],
materials.cream,
false
);
}
for (const z of [3.18, 6.42]) {
addBox(
terminal,
[20.5, 0.025, 0.07],
[6.0, 0.19, z],
materials.cream,
false
);
}
// Dedicated rail corridor.
addBox(
terminal,
[21.0, 0.12, 3.0],
[6.1, 0.12, -4.8],
new THREE.MeshStandardMaterial({
color: 0x8f9187,
roughness: 1
})
);
for (let x = -4; x < 16.3; x += 0.85) {
addBox(
terminal,
[0.25, 0.12, 2.55],
[x, 0.23, -4.8],
materials.dark
);
}
for (const z of [-5.38, -4.22]) {
addBox(
terminal,
[21, 0.14, 0.1],
[6.1, 0.34, z],
materials.steel
);
}
// Yard stack pad.
addBox(
terminal,
[6.2, 0.12, 5.1],
[-0.75, 0.12, 0],
new THREE.MeshStandardMaterial({
color: 0xa9a797,
roughness: 0.95
})
);
function makeRoute(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.65,
gapSize: 0.42,
transparent: true,
opacity: 0.9,
linewidth: 1
});
const route = new THREE.Line(geometry, material);
route.computeLineDistances();
scene.add(route);
return route;
}
makeRoute(
[
[-18, -0.27, 0],
[-10, -0.27, 0]
],
0x78e0d5
);
makeRoute(
[
[-4.0, 0.24, 4.8],
[16.2, 0.24, 4.8]
],
0xf4bd55
);
makeRoute(
[
[-4.3, 0.43, -4.8],
[16.4, 0.43, -4.8]
],
0xed7fa0
);
// -------------------------------------------------------------------------
// Vessel
// -------------------------------------------------------------------------
const ship = new THREE.Group();
scene.add(ship);
const hullShape = new THREE.Shape();
hullShape.moveTo(-2.6, 9.5);
hullShape.lineTo(2.6, 9.5);
hullShape.lineTo(2.6, -8.0);
hullShape.lineTo(1.45, -10.1);
hullShape.lineTo(0, -11.0);
hullShape.lineTo(-1.45, -10.1);
hullShape.lineTo(-2.6, -8.0);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 1.55,
bevelEnabled: false
});
hullGeometry.rotateX(-Math.PI / 2);
const hull = new THREE.Mesh(hullGeometry, materials.dark);
hull.castShadow = true;
hull.receiveShadow = true;
ship.add(hull);
addBox(ship, [4.85, 0.18, 19.5], [0, 1.61, 0], materials.red);
addBox(ship, [4.25, 0.12, 17.7], [0, 1.75, 0], materials.steel);
// Stern superstructure.
addBox(ship, [3.6, 2.4, 2.8], [0, 2.95, -8.25], materials.cream);
addBox(ship, [4.0, 0.28, 3.0], [0, 4.25, -8.25], materials.cream);
addBox(ship, [3.85, 0.45, 2.92], [0, 3.72, -8.25], materials.dark);
addBox(ship, [2.1, 1.25, 2.2], [0, 5.0, -8.1], materials.cream);
addBox(ship, [2.18, 0.45, 2.25], [0, 5.05, -8.1], materials.dark);
addCylinder(ship, 0.32, 2.1, [0, 6.05, -8.1], materials.red, 8);
addCylinder(ship, 0.48, 0.18, [0, 7.05, -8.1], materials.dark, 8);
// Cargo already aboard.
const shipContainerColors = [0x4d8796, 0x9b5f55, 0x718b72, 0xb18449];
const shipContainerPositions = [
[-1.22, 5.0],
[1.22, 5.0],
[-1.22, 7.3],
[1.22, 7.3],
[-1.22, -2.5],
[1.22, -2.5]
];
shipContainerPositions.forEach((position, index) => {
const container = createContainer(shipContainerColors[index % shipContainerColors.length]);
container.rotation.y = Math.PI / 2;
container.position.set(position[0], 2.42, position[1]);
ship.add(container);
});
// -------------------------------------------------------------------------
// Storage stack
// -------------------------------------------------------------------------
const stackContainers = [
{ x: -2.35, y: 0.82, color: 0x4d8796 },
{ x: -2.35, y: 2.08, color: 0x9b5f55 },
{ x: 0.9, y: 0.82, color: 0x718b72 }
];
for (const item of stackContainers) {
const container = createContainer(item.color);
container.position.set(item.x, item.y, 0);
terminal.add(container);
}
// Small low-poly yard loader.
const yardLoader = new THREE.Group();
yardLoader.position.set(-3.7, 0.15, 2.1);
yardLoader.rotation.y = -0.35;
addBox(yardLoader, [1.65, 0.65, 1.1], [0, 0.55, 0], materials.crane);
addBox(yardLoader, [0.7, 1.05, 1.0], [-0.45, 1.25, 0], materials.crane);
addBox(yardLoader, [0.75, 0.55, 1.02], [-0.45, 1.85, 0], materials.dark);
beam(yardLoader, [0.45, 0.7, -0.35], [1.7, 0.35, -0.35], 0.12, materials.steel);
beam(yardLoader, [0.45, 0.7, 0.35], [1.7, 0.35, 0.35], 0.12, materials.steel);
for (const x of [-0.55, 0.55]) {
for (const z of [-0.58, 0.58]) {
addWheel(yardLoader, x, z, 0.31);
}
}
terminal.add(yardLoader);
// -------------------------------------------------------------------------
// Quay crane
// -------------------------------------------------------------------------
const quayCrane = new THREE.Group();
terminal.add(quayCrane);
for (const z of [-2.9, 2.9]) {
addBox(quayCrane, [1.7, 0.28, 1.15], [-5.75, 0.28, z], materials.steel);
addBox(quayCrane, [0.48, 7.1, 0.48], [-5.75, 3.75, z], materials.crane);
}
beam(
quayCrane,
[-5.75, 6.7, -2.9],
[-5.75, 6.7, 2.9],
0.46,
materials.crane
);
// Long boom reaching over the vessel and toward the yard.
for (const z of [-1.35, 1.35]) {
beam(
quayCrane,
[-13.1, 7.25, z],
[3.4, 7.25, z],
0.25,
materials.crane
);
beam(
quayCrane,
[-12.6, 6.55, z],
[2.9, 6.55, z],
0.15,
materials.crane
);
for (let x = -12; x < 3; x += 2.5) {
beam(
quayCrane,
[x, 7.25, z],
[x + 1.2, 6.55, z],
0.11,
materials.crane
);
}
}
beam(
quayCrane,
[-5.75, 7.25, -2.9],
[-5.75, 7.25, 2.9],
0.38,
materials.crane
);
beam(
quayCrane,
[-5.75, 7.25, -2.9],
[-12.5, 7.25, -1.35],
0.17,
materials.crane
);
beam(
quayCrane,
[-5.75, 7.25, 2.9],
[-12.5, 7.25, 1.35],
0.17,
materials.crane
);
const quayTrolley = new THREE.Group();
addBox(quayTrolley, [1.8, 0.45, 3.1], [0, 7.12, 0], materials.steel);
addBox(quayTrolley, [2.6, 0.16, 0.22], [0, 6.88, 0], materials.crane);
quayCrane.add(quayTrolley);
const quayCablePositions = new Float32Array(24);
const quayCableGeometry = new THREE.BufferGeometry();
quayCableGeometry.setAttribute(
"position",
new THREE.BufferAttribute(quayCablePositions, 3)
);
const quayCables = new THREE.LineSegments(
quayCableGeometry,
new THREE.LineBasicMaterial({ color: 0x25343b })
);
quayCables.frustumCulled = false;
scene.add(quayCables);
// -------------------------------------------------------------------------
// Rail gantry, truck, train, and warehouse
// -------------------------------------------------------------------------
const railGantry = new THREE.Group();
terminal.add(railGantry);
for (const x of [5.2, 10.8]) {
for (const z of [-5.6, 5.6]) {
addBox(
railGantry,
[0.38, 6.5, 0.38],
[x, 3.45, z],
materials.teal
);
addBox(
railGantry,
[1.2, 0.25, 1.2],
[x, 0.28, z],
materials.steel
);
}
beam(
railGantry,
[x, 6.65, -5.6],
[x, 6.65, 5.6],
0.3,
materials.teal
);
}
beam(
railGantry,
[5.2, 6.65, -5.6],
[10.8, 6.65, -5.6],
0.25,
materials.teal
);
beam(
railGantry,
[5.2, 6.65, 5.6],
[10.8, 6.65, 5.6],
0.25,
materials.teal
);
const railTrolley = new THREE.Group();
addBox(railTrolley, [2.7, 0.38, 1.5], [0, 6.55, 0], materials.steel);
railGantry.add(railTrolley);
const railCablePositions = new Float32Array(24);
const railCableGeometry = new THREE.BufferGeometry();
railCableGeometry.setAttribute(
"position",
new THREE.BufferAttribute(railCablePositions, 3)
);
const railCables = new THREE.LineSegments(
railCableGeometry,
new THREE.LineBasicMaterial({ color: 0x25343b })
);
railCables.frustumCulled = false;
scene.add(railCables);
const truck = createTruck();
truck.position.set(-2.8, 0.15, 4.8);
terminal.add(truck);
const train = new THREE.Group();
terminal.add(train);
const targetFlatcar = createFlatcar();
targetFlatcar.position.x = 8;
train.add(targetFlatcar);
const loadedFlatcar = createFlatcar();
loadedFlatcar.position.x = 4.25;
train.add(loadedFlatcar);
const trainContainerA = createContainer(0x4f8b83);
trainContainerA.position.set(4.25, 1.75, 0);
train.add(trainContainerA);
const trainContainerB = createContainer(0xa66b52);
trainContainerB.position.set(4.25, 3.0, 0);
train.add(trainContainerB);
const locomotive = createLocomotive();
locomotive.position.x = 12.1;
train.add(locomotive);
// Warehouse between, but clear of, road and rail.
const warehouse = new THREE.Group();
warehouse.position.set(13.0, 0.1, 0);
terminal.add(warehouse);
addBox(warehouse, [6.2, 3.5, 4.5], [0, 1.75, 0], materials.cream);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(4.1, 1.35, 4),
materials.blue
);
roof.position.y = 4.1;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.73;
roof.castShadow = true;
warehouse.add(roof);
for (const x of [-1.8, 0, 1.8]) {
addBox(warehouse, [1.25, 2.0, 0.08], [x, 1.0, 2.29], materials.steel);
}
// Small figures give scale to the yard.
function createWorker(x, z, color) {
const worker = new THREE.Group();
const vestMaterial = new THREE.MeshStandardMaterial({ color });
addCylinder(worker, 0.13, 0.58, [0, 0.85, 0], vestMaterial, 6);
addBox(worker, [0.34, 0.2, 0.28], [0, 1.22, 0], materials.cream);
addCylinder(worker, 0.18, 0.12, [0, 1.38, 0], materials.crane, 8);
worker.position.set(x, 0.15, z);
terminal.add(worker);
}
createWorker(-3.8, 2.7, 0xf3a934);
createWorker(2.3, 1.8, 0x3b8d84);
createWorker(11.8, -3.0, 0xf3a934);
// -------------------------------------------------------------------------
// Highlighted container
// -------------------------------------------------------------------------
const cargo = createContainer(COLORS.orange, "CX-204");
scene.add(cargo);
// -------------------------------------------------------------------------
// Timeline and user interface
// -------------------------------------------------------------------------
const stages = [
{ name: "Vessel approach", duration: 2.0 },
{ name: "Quay lift", duration: 3.0 },
{ name: "Yard stack", duration: 1.5 },
{ name: "Truck load", duration: 2.5 },
{ name: "Road haul", duration: 3.2 },
{ name: "Rail load", duration: 3.0 },
{ name: "Train depart", duration: 3.0 }
];
let totalDuration = 0;
const stageElements = [];
const stagesContainer = document.getElementById("stages");
stages.forEach((stage, index) => {
stage.start = totalDuration;
totalDuration += stage.duration;
stage.end = totalDuration;
const button = document.createElement("button");
button.className = "stage";
button.type = "button";
button.innerHTML = `
<span class="stage-number">${String(index + 1).padStart(2, "0")}</span>
<span class="stage-name">${stage.name}</span>
`;
button.addEventListener("click", () => {
timelineTime = stage.start + 0.001;
playing = true;
updatePlayButton();
});
stagesContainer.appendChild(button);
stageElements.push(button);
});
const timeline = document.getElementById("timeline");
const timelineTime = 0;
let currentTime = 0;
let playing = true;
const playButton = document.getElementById("playButton");
const restartButton = document.getElementById("restartButton");
const cameraButton = document.getElementById("cameraButton");
const sequenceName = document.getElementById("sequenceName");
const timeReadout = document.getElementById("timeReadout");
const cargoTag = document.getElementById("cargoTag");
function updatePlayButton() {
if (playing) {
playButton.textContent = "Pause";
} else if (currentTime >= totalDuration) {
playButton.textContent = "Replay";
} else {
playButton.textContent = "Play";
}
}
playButton.addEventListener("click", () => {
if (currentTime >= totalDuration) currentTime = 0;
playing = !playing;
updatePlayButton();
});
restartButton.addEventListener("click", () => {
currentTime = 0;
playing = true;
updatePlayButton();
});
cameraButton.addEventListener("click", resetCamera);
timeline.addEventListener("input", () => {
currentTime = (Number(timeline.value) / 1000) * totalDuration;
playing = false;
updatePlayButton();
});
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const clamp01 = (value) => THREE.MathUtils.clamp(value, 0, 1);
const lerp = THREE.MathUtils.lerp;
const smooth = (value) => {
const t = clamp01(value);
return t * t * (3 - 2 * t);
};
function getStageInfo(time) {
for (let index = stages.length - 1; index >= 0; index--) {
if (time >= stages[index].start) {
const stage = stages[index];
const localTime = THREE.MathUtils.clamp(
time - stage.start,
0,
stage.duration
);
return {
index,
stage,
localTime,
normalized: localTime / stage.duration
};
}
}
return {
index: 0,
stage: stages[0],
localTime: 0,
normalized: 0
};
}
const tempCargo = new THREE.Vector3();
const tempOffset = new THREE.Vector3();
const rotatedOffset = new THREE.Vector3();
function updateCables(
line,
positions,
trolleyPosition,
trolleyRotation,
cargoPosition,
cargoRotation,
halfLength,
halfWidth
) {
const corners = [
[-halfLength, -halfWidth],
[-halfLength, halfWidth],
[halfLength, -halfWidth],
[halfLength, halfWidth]
];
corners.forEach((corner, index) => {
const offset = index < 2 ? -1 : 1;
tempOffset.set(corner[0], 0, corner[1]).applyAxisAngle(
new THREE.Vector3(0, 1, 0),
trolleyRotation
);
positions[index * 6] = trolleyPosition.x + tempOffset.x;
positions[index * 6 + 1] = trolleyPosition.y;
positions[index * 6 + 2] = trolleyPosition.z + tempOffset.z;
rotatedOffset
.set(corner[0], 0.48, corner[1])
.applyAxisAngle(new THREE.Vector3(0, 1, 0), cargoRotation);
positions[index * 6 + 3] = cargoPosition.x + rotatedOffset.x;
positions[index * 6 + 4] = cargoPosition.y + rotatedOffset.y;
positions[index * 6 + 5] = cargoPosition.z + rotatedOffset.z;
});
line.geometry.attributes.position.needsUpdate = true;
}
const cargoPosition = new THREE.Vector3(-10, 2.45, 0);
let cargoRotation = Math.PI / 2;
let quayTrolleyX = -10;
let railTrolleyZ = 4.8;
function updateScene(time) {
const info = getStageInfo(time);
const { index, localTime, normalized } = info;
let truckX = -2.8;
let trainX = 0;
let quayVisible = index <= 2;
let railVisible = index === 5;
ship.position.x = -10;
ship.position.y = 0;
switch (index) {
case 0: {
ship.position.x = lerp(-11.2, -10, smooth(normalized));
ship.position.y = Math.sin(normalized * Math.PI * 2) * 0.035;
cargoPosition.set(ship.position.x, 2.45 + ship.position.y, 0);
cargoRotation = Math.PI / 2;
quayTrolleyX = ship.position.x;
break;
}
case 1: {
if (normalized < 0.28) {
const p = smooth(normalized / 0.28);
cargoPosition.set(-10, lerp(2.45, 6.25, p), 0);
} else if (normalized < 0.72) {
const p = smooth((normalized - 0.28) / 0.44);
cargoPosition.set(lerp(-10, 0.9, p), 6.25, 0);
} else {
const p = smooth((normalized - 0.72) / 0.28);
cargoPosition.set(0.9, lerp(6.25, 2.08, p), 0);
}
cargoRotation = lerp(
Math.PI / 2,
0,
smooth((normalized - 0.12) / 0.72)
);
quayTrolleyX = cargoPosition.x;
break;
}
case 2: {
cargoPosition.set(0.9, 2.08, 0);
cargoRotation = 0;
quayTrolleyX = 0.9;
break;
}
case 3: {
const truckApproach = smooth(localTime / 1.05);
truckX = lerp(-2.8, 1.6, truckApproach);
const transfer = clamp01((localTime - 1.05) / 1.45);
const eased = smooth(transfer);
cargoPosition.set(
lerp(0.9, truckX - 0.7, eased),
lerp(2.08, 1.68, eased) + Math.sin(transfer * Math.PI) * 1.05,
lerp(0, 4.8, eased)
);
cargoRotation = 0;
quayVisible = false;
break;
}
case 4: {
truckX = lerp(1.6, 8.7, smooth(normalized));
cargoPosition.set(truckX - 0.7, 1.68, 4.8);
cargoRotation = 0;
break;
}
case 5: {
truckX = 8.7;
const p = smooth(normalized);
const arc = Math.sin(normalized * Math.PI);
cargoPosition.set(
8,
lerp(1.68, 1.74, p) + arc * 3.5,
lerp(4.8, -4.8, p)
);
cargoRotation = 0;
railTrolleyZ = lerp(4.8, -4.8, p);
break;
}
case 6: {
truckX = 8.7;
trainX = lerp(0, 8.5, smooth(normalized));
cargoPosition.set(8 + trainX, 1.74, -4.8);
cargoRotation = 0;
break;
}
}
cargo.position.copy(cargoPosition);
cargo.rotation.y = cargoRotation;
truck.position.x = truckX;
train.position.x = trainX;
quayTrolley.position.x = quayTrolleyX;
quayTrolley.rotation.y = cargoRotation;
railTrolley.position.z = railTrolleyZ;
quayCables.visible = quayVisible;
railCables.visible = railVisible;
if (quayVisible) {
updateCables(
quayCables,
quayCablePositions,
new THREE.Vector3(quayTrolleyX, 6.9, 0),
cargoRotation,
cargoPosition,
cargoRotation,
1.35,
0.5
);
}
if (railVisible) {
updateCables(
railCables,
railCablePositions,
new THREE.Vector3(8, 6.35, railTrolleyZ),
0,
cargoPosition,
0,
1.35,
0.5
);
}
// Gentle wave motion.
waves.forEach((wave, index) => {
wave.position.x += 0.0018 * (index % 2 === 0 ? 1 : -1);
if (wave.position.x > -5.5) wave.position.x = -29;
if (wave.position.x < -30) wave.position.x = -8;
});
return info;
}
// -------------------------------------------------------------------------
// Main loop and UI projection
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projectedPosition = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
currentTime += delta;
if (currentTime >= totalDuration) {
currentTime = totalDuration;
playing = false;
updatePlayButton();
}
}
const info = updateScene(currentTime);
timeline.value = String((currentTime / totalDuration) * 1000);
timeline.style.setProperty(
"--progress",
`${(currentTime / totalDuration) * 100}%`
);
sequenceName.textContent = info.stage.name;
timeReadout.textContent = `${currentTime.toFixed(1).padStart(4, "0")} / ${totalDuration.toFixed(1)}s`;
stageElements.forEach((element, index) => {
element.classList.toggle("active", index === info.index);
element.classList.toggle("done", index < info.index);
});
// Project the highlighted container's label into screen space.
projectedPosition.copy(cargo.position);
projectedPosition.y += 1.05;
projectedPosition.project(camera);
const visible =
projectedPosition.z > -1 &&
projectedPosition.z < 1 &&
Math.abs(projectedPosition.x) < 1.15 &&
Math.abs(projectedPosition.y) < 1.15;
cargoTag.style.opacity = visible ? "1" : "0";
cargoTag.style.left = `${((projectedPosition.x + 1) / 2) * innerWidth}px`;
cargoTag.style.top = `${((-projectedPosition.y + 1) / 2) * innerHeight}px`;
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updatePlayButton();
animate();
</script>
</body>
</html>
```