Prompt specification
Build or customize the Three.js 3D scene "Container transfer from truck to rail wagon" 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: Container transfer from truck to rail wagon
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/container-transfer-from-truck-to-rail-wagon-x2530
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: Container transfer from truck to rail wagon. Create a compact intermodal transfer vignette with crane, truck, and rail wagon. Move the same container between platforms while preserving its dimensions and orientation constraints. Return one self-contained HTML file.
Working Three.js Starter (container-transfer-from-truck-to-rail-wagon-x2530):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<meta name="theme-color" content="#0b131d">
<title>Intermodal Container Transfer</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5f7;
--muted: #95a7b2;
--panel: rgba(13, 23, 32, 0.82);
--line: rgba(193, 220, 229, 0.14);
--accent: #f2b84b;
--cyan: #65d5d0;
--progress: 0%;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b131d;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
button, input { font: inherit; }
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 42%, rgba(2, 8, 13, 0.28) 100%),
linear-gradient(180deg, rgba(3, 9, 14, 0.16), transparent 24%, transparent 76%, rgba(3, 9, 14, 0.22));
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(16px) saturate(125%);
-webkit-backdrop-filter: blur(16px) saturate(125%);
}
#title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 14px rgba(242, 184, 75, 0.8);
}
h1 {
margin: 7px 0 3px;
font-size: clamp(24px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.035em;
font-weight: 760;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.015em;
}
#metrics-card {
top: 22px;
right: 22px;
width: 280px;
padding: 15px;
border-radius: 18px;
}
.metrics-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--cyan);
}
.live::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.metrics-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.metric {
min-width: 0;
padding: 10px 8px 9px;
border: 1px solid rgba(255,255,255,0.07);
border-radius: 11px;
background: rgba(255,255,255,0.035);
}
.metric b {
display: block;
white-space: nowrap;
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.metric span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.constraint {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
padding: 10px 11px;
border-radius: 11px;
color: #b9f2ed;
background: rgba(101, 213, 208, 0.09);
border: 1px solid rgba(101, 213, 208, 0.15);
font-size: 11px;
}
.constraint strong {
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#status-card {
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 15px 17px;
border-radius: 16px;
}
.status-row {
display: flex;
align-items: center;
gap: 11px;
}
.status-icon {
position: relative;
flex: 0 0 35px;
width: 35px;
height: 35px;
border-radius: 11px;
display: grid;
place-items: center;
color: var(--accent);
background: rgba(242, 184, 75, 0.11);
border: 1px solid rgba(242, 184, 75, 0.2);
font-weight: 900;
}
#phase-title {
font-size: 14px;
font-weight: 750;
}
#phase-detail {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
#controls {
right: 22px;
bottom: 22px;
width: min(510px, calc(100vw - 44px));
padding: 14px;
border-radius: 17px;
}
.transport {
display: flex;
align-items: center;
gap: 10px;
}
.icon-button {
flex: 0 0 auto;
width: 38px;
height: 38px;
border: 1px solid rgba(255,255,255,0.1);
border-radius: 11px;
color: var(--ink);
background: rgba(255,255,255,0.055);
cursor: pointer;
transition: 160ms ease;
}
.icon-button:hover {
background: rgba(255,255,255,0.11);
border-color: rgba(255,255,255,0.18);
transform: translateY(-1px);
}
#play-button {
width: 42px;
height: 42px;
color: #14212a;
border-color: transparent;
background: var(--accent);
font-size: 15px;
font-weight: 900;
}
#play-button:hover {
background: #ffd06e;
}
.timeline-wrap {
flex: 1;
min-width: 80px;
}
#timeline {
--progress: 0%;
width: 100%;
height: 5px;
margin: 0;
border-radius: 99px;
appearance: none;
background: linear-gradient(
90deg,
var(--accent) 0 var(--progress),
rgba(255,255,255,0.12) var(--progress) 100%
);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 3px solid #16232d;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(242,184,75,0.55);
}
#timeline::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #16232d;
border-radius: 50%;
background: var(--accent);
}
.time {
min-width: 70px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
#speed-button {
width: 48px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
}
.control-help {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 10px;
color: #6f8490;
font-size: 9px;
letter-spacing: 0.035em;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #0b131d;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader {
width: 42px;
height: 42px;
border: 3px solid rgba(255,255,255,0.12);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
#metrics-card {
top: 128px;
right: 12px;
width: 225px;
padding: 11px;
}
.metric { padding: 8px 6px; }
.metric b { font-size: 11px; }
.constraint { display: none; }
#status-card {
left: 12px;
bottom: 96px;
width: calc(100vw - 24px);
}
#controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.control-help { display: none; }
h1 { font-size: 25px; }
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<section id="title-card" class="panel">
<div class="eyebrow">Intermodal operations / Unit 07</div>
<h1>Container Transfer</h1>
<p class="subtitle">Road load → gantry crane → rail wagon</p>
</section>
<section id="metrics-card" class="panel">
<div class="metrics-title">
<span>ISO 40′ rigid container</span>
<span class="live">Tracked</span>
</div>
<div class="metrics-grid">
<div class="metric"><b>12.20 m</b><span>Length</span></div>
<div class="metric"><b>2.44 m</b><span>Width</span></div>
<div class="metric"><b>2.59 m</b><span>Height</span></div>
</div>
<div class="constraint">
<span>Scale locked · no deformation</span>
<strong>↔ X-axis</strong>
</div>
</section>
<section id="status-card" class="panel">
<div class="status-row">
<div class="status-icon" id="status-icon">01</div>
<div>
<div id="phase-title">Secured on truck</div>
<div id="phase-detail">The spreader is engaged and the container is ready to lift.</div>
</div>
</div>
</section>
<section id="controls" class="panel">
<div class="transport">
<button id="play-button" class="icon-button" aria-label="Pause animation" title="Play / pause">Ⅱ</button>
<button id="restart-button" class="icon-button" aria-label="Restart animation" title="Restart">↺</button>
<div class="timeline-wrap">
<input id="timeline" type="range" min="0" max="16" step="0.01" value="0" aria-label="Transfer timeline">
</div>
<div class="time"><span id="current-time">00.0</span> / 16.0</div>
<button id="speed-button" class="icon-button" aria-label="Change speed" title="Change speed">1×</button>
<button id="camera-button" class="icon-button" aria-label="Reset camera" title="Reset camera">⌖</button>
</div>
<div class="control-help">
<span>DRAG TO ORBIT · WHEEL TO ZOOM · RIGHT-DRAG TO PAN</span>
<span>SPACE: PLAY/PAUSE · R: RESTART · V: VIEW</span>
</div>
</section>
<div id="loading"><div class="loader"></div></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Core setup
// -------------------------------------------------------------------------
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b131d);
scene.fog = new THREE.Fog(0x0b131d, 44, 88);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 140);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
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.08;
app.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xb8d8ee, 0x25221d, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffead1, 3.1);
sun.position.set(-12, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -27;
sun.shadow.camera.right = 27;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x5ca9d8, 1.15);
rim.position.set(17, 10, -16);
scene.add(rim);
// -------------------------------------------------------------------------
// Geometry and material helpers
// -------------------------------------------------------------------------
const standard = (color, metalness = 0, roughness = 0.7, extra = {}) =>
new THREE.MeshStandardMaterial({ color, metalness, roughness, ...extra });
const materials = {
concrete: standard(0x28343c, 0.02, 0.95),
concreteEdge: standard(0x3b4951, 0.02, 0.9),
asphalt: standard(0x171d22, 0.02, 0.96),
railBed: standard(0x22282b, 0.08, 0.88),
sleeper: standard(0x3b3128, 0.02, 0.96),
rail: standard(0x9aa8ae, 0.86, 0.28),
crane: standard(0xe9aa32, 0.36, 0.48),
craneDark: standard(0x343a3c, 0.64, 0.46),
truck: standard(0x284c66, 0.48, 0.45),
truckDark: standard(0x142633, 0.52, 0.47),
glass: standard(0x173747, 0.65, 0.18),
tire: standard(0x111416, 0.02, 0.93),
hub: standard(0x89949a, 0.8, 0.31),
wagon: standard(0x245b5d, 0.58, 0.49),
wagonDark: standard(0x173d40, 0.64, 0.48),
yellow: standard(0xf3bd49, 0.32, 0.5),
black: standard(0x111719, 0.08, 0.86),
orange: standard(0xef6c34, 0.12, 0.64),
white: standard(0xd8dedf, 0.18, 0.58),
container: standard(0xc75d3d, 0.38, 0.56),
containerDark: standard(0x94442f, 0.42, 0.61),
containerFrame: standard(0xe16a42, 0.38, 0.51),
warehouse: standard(0x202d36, 0.12, 0.9),
window: standard(0x4b8594, 0.25, 0.35, {
emissive: 0x17343f,
emissiveIntensity: 0.55
})
};
function box(w, h, d, material, x = 0, y = 0, z = 0, 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(radius, height, material, x = 0, y = 0, z = 0, parent = scene, segments = 18) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const rodDirection = new THREE.Vector3();
const rodMidpoint = new THREE.Vector3();
const upAxis = new THREE.Vector3(0, 1, 0);
function makeRod(radius, material, parent = scene) {
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 9),
material
);
rod.castShadow = true;
rod.receiveShadow = true;
parent.add(rod);
return rod;
}
function setRod(rod, a, b) {
rodDirection.subVectors(b, a);
const length = rodDirection.length();
rodMidpoint.addVectors(a, b).multiplyScalar(0.5);
rod.position.copy(rodMidpoint);
rod.scale.set(1, length, 1);
rod.quaternion.setFromUnitVectors(upAxis, rodDirection.normalize());
}
function groundText(text, x, z, width, color = "#d8e0e2") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = color;
ctx.font = "800 104px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 512, 130);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 0.25),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
opacity: 0.7
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.115, z);
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Site, roadway, railway, and background
// -------------------------------------------------------------------------
box(42, 0.6, 19, materials.concrete, -1.2, -0.32, -1.8);
box(42.2, 0.12, 19.2, materials.concreteEdge, -1.2, -0.64, -1.8);
box(18.6, 0.09, 5.25, materials.asphalt, -9.6, 0.055, 0);
box(17.3, 0.08, 4.7, materials.railBed, 6.55, 0.045, 0);
for (let x = -17.6; x <= -1.4; x += 1.55) {
box(0.78, 0.018, 0.08, materials.yellow, x, 0.111, -2.31);
box(0.78, 0.018, 0.08, materials.yellow, x, 0.111, 2.31);
}
for (let x = -1.9; x <= 14.6; x += 0.74) {
box(0.27, 0.13, 3.45, materials.sleeper, x, 0.09, 0);
}
box(16.8, 0.12, 0.11, materials.rail, 6.35, 0.205, -0.76);
box(16.8, 0.12, 0.11, materials.rail, 6.35, 0.205, 0.76);
groundText("ROAD TRANSFER", -8.4, 2.03, 5.8);
groundText("RAIL", 8.0, 2.02, 2.8, "#f0bd55");
// Distant warehouse keeps the scene grounded without distracting from the load.
box(20.5, 3.5, 3.8, materials.warehouse, 0.2, 1.75, -10.0);
box(21.3, 0.28, 4.25, materials.craneDark, 0.2, 3.61, -10.0);
for (let x = -7.5; x <= 8; x += 2.2) {
box(1.55, 0.9, 0.06, materials.window, x, 2.35, -8.07);
}
box(3.1, 2.7, 0.1, materials.craneDark, 4.5, 1.35, -8.02);
// -------------------------------------------------------------------------
// Truck: road chassis, cab, wheels, and deck
// -------------------------------------------------------------------------
const truck = new THREE.Group();
scene.add(truck);
box(14.0, 0.24, 1.0, materials.truckDark, -8.0, 1.04, 0, truck);
box(13.4, 0.18, 2.62, materials.truckDark, -8.0, 1.30, 0, truck);
for (let x = -13.8; x < -2.0; x += 0.72) {
box(0.10, 0.025, 2.54, materials.rail, x, 1.405, 0, truck);
}
box(2.36, 2.34, 2.42, materials.truck, -15.34, 2.04, 0, truck);
box(2.12, 0.17, 2.50, materials.truck, -15.32, 3.27, 0, truck);
box(0.08, 0.83, 2.05, materials.glass, -16.55, 2.53, 0, truck);
box(1.02, 0.76, 0.055, materials.glass, -15.08, 2.53, 1.225, truck);
box(1.02, 0.76, 0.055, materials.glass, -15.08, 2.53, -1.225, truck);
box(0.12, 0.30, 2.7, materials.craneDark, -16.58, 0.98, 0, truck);
box(1.3, 0.16, 0.22, materials.craneDark, -15.15, 3.42, 0, truck);
const lampMaterial = standard(0xffe3a0, 0.1, 0.28, {
emissive: 0xffbd4c,
emissiveIntensity: 1.4
});
box(0.08, 0.25, 0.38, lampMaterial, -16.64, 1.48, 0.77, truck);
box(0.08, 0.25, 0.38, lampMaterial, -16.64, 1.48, -0.77, truck);
function wheel(x, z, radius, parent) {
const tire = cylinder(radius, 0.34, materials.tire, x, radius, z, parent, 22);
tire.rotation.x = Math.PI / 2;
const hub = cylinder(radius * 0.48, 0.36, materials.hub, x, radius, z, parent, 18);
hub.rotation.x = Math.PI / 2;
}
for (const x of [-15.45, -4.45, -3.28, -2.11]) {
wheel(x, 1.34, 0.53, truck);
wheel(x, -1.34, 0.53, truck);
}
box(3.0, 0.10, 0.58, materials.black, -3.28, 1.12, 1.34, truck);
box(3.0, 0.10, 0.58, materials.black, -3.28, 1.12, -1.34, truck);
const fuelTank = cylinder(0.32, 1.45, materials.hub, -11.8, 0.85, -1.34, truck);
fuelTank.rotation.z = Math.PI / 2;
// -------------------------------------------------------------------------
// Rail wagon and bogies
// -------------------------------------------------------------------------
const railWagon = new THREE.Group();
scene.add(railWagon);
const wagonX = 5.35;
box(13.3, 0.26, 2.78, materials.wagon, wagonX, 1.27, 0, railWagon);
box(13.55, 0.22, 0.18, materials.wagonDark, wagonX, 1.18, 1.36, railWagon);
box(13.55, 0.22, 0.18, materials.wagonDark, wagonX, 1.18, -1.36, railWagon);
box(0.32, 0.54, 2.92, materials.wagonDark, wagonX - 6.66, 1.2, 0, railWagon);
box(0.32, 0.54, 2.92, materials.wagonDark, wagonX + 6.66, 1.2, 0, railWagon);
for (const bogieX of [1.62, 9.08]) {
box(2.7, 0.34, 1.75, materials.craneDark, bogieX, 0.91, 0, railWagon);
for (const dx of [-0.78, 0.78]) {
wheel(bogieX + dx, 0.84, 0.45, railWagon);
wheel(bogieX + dx, -0.84, 0.45, railWagon);
}
}
box(1.35, 0.22, 0.42, materials.craneDark, -1.6, 0.9, 0, railWagon);
box(1.35, 0.22, 0.42, materials.craneDark, 12.3, 0.9, 0, railWagon);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(0.26, 0.13, 0.22, materials.yellow, wagonX + sx * 5.92, 1.46, sz * 1.09, railWagon);
}
}
// -------------------------------------------------------------------------
// One and only one ISO container. Its transform is never scaled or rotated.
// -------------------------------------------------------------------------
const CONTAINER_LENGTH = 12.20;
const CONTAINER_WIDTH = 2.44;
const CONTAINER_HEIGHT = 2.59;
const container = new THREE.Group();
container.name = "ISO_40FT_TRANSFER_CONTAINER";
container.userData.constraints = Object.freeze({
length: CONTAINER_LENGTH,
width: CONTAINER_WIDTH,
height: CONTAINER_HEIGHT,
longitudinalAxis: "X",
scaleLocked: true,
rotationLocked: true
});
scene.add(container);
box(
CONTAINER_LENGTH,
CONTAINER_HEIGHT,
CONTAINER_WIDTH,
materials.container,
0, 0, 0,
container
);
// Corrugated side walls.
const ribCount = 42;
for (let i = 0; i < ribCount; i++) {
const x = -CONTAINER_LENGTH / 2 + 0.18 + i * (CONTAINER_LENGTH - 0.36) / (ribCount - 1);
box(
0.065,
CONTAINER_HEIGHT - 0.20,
0.065,
materials.containerDark,
x, 0, CONTAINER_WIDTH / 2 + 0.026,
container
);
box(
0.065,
CONTAINER_HEIGHT - 0.20,
0.065,
materials.containerDark,
x, 0, -CONTAINER_WIDTH / 2 - 0.026,
container
);
}
// Top and bottom perimeter rails.
for (const z of [-1, 1]) {
box(CONTAINER_LENGTH, 0.15, 0.13, materials.containerFrame, 0, CONTAINER_HEIGHT / 2 - 0.06, z * 1.19, container);
box(CONTAINER_LENGTH, 0.15, 0.13, materials.containerFrame, 0, -CONTAINER_HEIGHT / 2 + 0.06, z * 1.19, container);
}
for (const x of [-CONTAINER_LENGTH / 2 + 0.06, CONTAINER_LENGTH / 2 - 0.06]) {
box(0.14, CONTAINER_HEIGHT, 2.43, materials.containerFrame, x, 0, 0, container);
}
// Roof ribs.
for (let i = 0; i < 25; i++) {
const x = -CONTAINER_LENGTH / 2 + 0.28 + i * (CONTAINER_LENGTH - 0.56) / 24;
box(0.07, 0.055, CONTAINER_WIDTH - 0.16, materials.containerDark, x, CONTAINER_HEIGHT / 2 + 0.025, 0, container);
}
// Door end: split leaves and locking bars.
const doorX = CONTAINER_LENGTH / 2 + 0.075;
box(0.055, CONTAINER_HEIGHT - 0.20, CONTAINER_WIDTH / 2 - 0.10, materials.containerDark, doorX, 0, CONTAINER_WIDTH / 4, container);
box(0.055, CONTAINER_HEIGHT - 0.20, CONTAINER_WIDTH / 2 - 0.10, materials.containerDark, doorX, 0, -CONTAINER_WIDTH / 4, container);
for (const z of [-0.78, -0.27, 0.27, 0.78]) {
cylinder(0.025, CONTAINER_HEIGHT - 0.38, materials.containerFrame, doorX + 0.055, 0, z, container, 10);
box(0.10, 0.08, 0.27, materials.rail, doorX + 0.09, -0.18, z, container);
}
// Printed side placard.
const placardCanvas = document.createElement("canvas");
placardCanvas.width = 1024;
placardCanvas.height = 256;
const placardCtx = placardCanvas.getContext("2d");
placardCtx.fillStyle = "rgba(22, 28, 30, 0.88)";
placardCtx.fillRect(0, 0, 1024, 256);
placardCtx.strokeStyle = "#e9b05c";
placardCtx.lineWidth = 7;
placardCtx.strokeRect(10, 10, 1004, 236);
placardCtx.fillStyle = "#f1f4ef";
placardCtx.font = "800 88px system-ui, sans-serif";
placardCtx.fillText("NORTHLINE", 48, 113);
placardCtx.fillStyle = "#e9b05c";
placardCtx.font = "700 40px system-ui, sans-serif";
placardCtx.fillText("45G1 · 40 FT · UNIT 07", 50, 190);
const placardTexture = new THREE.CanvasTexture(placardCanvas);
placardTexture.colorSpace = THREE.SRGBColorSpace;
const placardMaterial = new THREE.MeshStandardMaterial({
map: placardTexture,
roughness: 0.72,
metalness: 0.05
});
const placard = new THREE.Mesh(new THREE.PlaneGeometry(4.5, 1.125), placardMaterial);
placard.position.set(-1.75, 0.28, CONTAINER_WIDTH / 2 + 0.095);
container.add(placard);
// -------------------------------------------------------------------------
// Gantry crane: fixed runway, moving bridge, trolley, spreader, and cables.
// -------------------------------------------------------------------------
const crane = new THREE.Group();
scene.add(crane);
const legXs = [-16.45, 12.25];
const legZs = [-4.75, 4.75];
for (const x of legXs) {
for (const z of legZs) {
box(0.46, 8.95, 0.46, materials.crane, x, 4.48, z, crane);
box(1.05, 0.28, 1.05, materials.craneDark, x, 0.18, z, crane);
box(0.78, 0.48, 0.78, materials.crane, x, 0.54, z, crane);
for (let i = 0; i < 4; i++) {
const stripe = box(0.17, 0.48, 0.80, i % 2 ? materials.black : materials.yellow, x - 0.28 + i * 0.18, 0.55, z, crane);
stripe.rotation.y = -0.25;
}
}
}
box(29.55, 0.54, 0.68, materials.crane, -2.10, 9.18, -4.75, crane);
box(29.55, 0.54, 0.68, materials.crane, -2.10, 9.18, 4.75, crane);
box(0.55, 0.34, 9.95, materials.craneDark, -16.45, 8.77, 0, crane);
box(0.55, 0.34, 9.95, materials.craneDark, 12.25, 8.77, 0, crane);
// Diagonal braces at the ends.
for (const x of legXs) {
const braceA = makeRod(0.075, materials.craneDark, crane);
setRod(braceA, new THREE.Vector3(x, 1.05, -4.72), new THREE.Vector3(x, 8.72, 4.72));
const braceB = makeRod(0.075, materials.craneDark, crane);
setRod(braceB, new THREE.Vector3(x, 1.05, 4.72), new THREE.Vector3(x, 8.72, -4.72));
}
// Crane operator cabin.
box(1.45, 1.55, 1.30, materials.crane, 12.25, 7.72, 4.78, crane);
box(1.12, 0.78, 0.055, materials.glass, 12.25, 7.94, 5.46, crane);
box(0.055, 0.78, 1.00, materials.glass, 11.50, 7.94, 4.78, crane);
const bridge = new THREE.Group();
scene.add(bridge);
box(0.48, 0.72, 9.75, materials.crane, -0.72, 9.03, 0, bridge);
box(0.48, 0.72, 9.75, materials.crane, 0.72, 9.03, 0, bridge);
box(2.15, 0.42, 0.52, materials.craneDark, 0, 8.82, -4.75, bridge);
box(2.15, 0.42, 0.52, materials.craneDark, 0, 8.82, 4.75, bridge);
// Trolley and long hoist beam.
box(2.35, 0.58, 1.65, materials.craneDark, 0, 8.48, 0, bridge);
box(1.10, 0.38, 1.15, materials.yellow, 0, 8.05, 0, bridge);
box(11.65, 0.23, 0.30, materials.craneDark, 0, 8.20, 0, bridge);
const beaconMaterial = standard(0xff9d32, 0.05, 0.3, {
emissive: 0xff5e16,
emissiveIntensity: 2.4
});
const beacon = new THREE.Mesh(new THREE.SphereGeometry(0.14, 14, 10), beaconMaterial);
beacon.position.set(0, 8.88, 0);
bridge.add(beacon);
// Spreader frame.
const spreader = new THREE.Group();
scene.add(spreader);
box(11.45, 0.18, 0.18, materials.yellow, 0, 0, 0.69, spreader);
box(11.45, 0.18, 0.18, materials.yellow, 0, 0, -0.69, spreader);
box(0.24, 0.22, 1.60, materials.yellow, 5.72, 0, 0, spreader);
box(0.24, 0.22, 1.60, materials.yellow, -5.72, 0, 0, spreader);
box(1.2, 0.25, 1.25, materials.craneDark, 0, 0.02, 0, spreader);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(0.20, 0.28, 0.20, materials.craneDark, sx * 5.72, -0.16, sz * 0.69, spreader);
}
}
const cables = [];
for (let i = 0; i < 4; i++) {
cables.push(makeRod(0.027, materials.black, scene));
}
// Small safety cones around the transfer zone.
function cone(x, z) {
const coneMesh = new THREE.Mesh(new THREE.ConeGeometry(0.24, 0.72, 14), materials.orange);
coneMesh.position.set(x, 0.47, z);
coneMesh.castShadow = true;
scene.add(coneMesh);
const stripe = cylinder(0.145, 0.13, materials.white, x, 0.47, z, scene, 14);
stripe.castShadow = false;
}
cone(-0.25, 2.30);
cone(-0.25, -2.30);
// -------------------------------------------------------------------------
// Transfer choreography
// -------------------------------------------------------------------------
const START_X = -8.0;
const TARGET_X = 5.35;
const START_Y = 1.43 + CONTAINER_HEIGHT / 2;
const TARGET_Y = 1.43 + CONTAINER_HEIGHT / 2;
const LIFT_Y = 5.95;
const HOIST_START = 1.4;
const HOIST_END = 4.2;
const TRAVEL_END = 9.2;
const LOWER_END = 12.0;
const RELEASE_END = 13.4;
const DURATION = 16.0;
const smooth = value => {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
};
const lerp = THREE.MathUtils.lerp;
const cableA = new THREE.Vector3();
const cableB = new THREE.Vector3();
function updateTransfer(time) {
let x = START_X;
let y = START_Y;
if (time >= HOIST_START && time < HOIST_END) {
const t = smooth((time - HOIST_START) / (HOIST_END - HOIST_START));
y = lerp(START_Y, LIFT_Y, t);
} else if (time >= HOIST_END && time < TRAVEL_END) {
const t = smooth((time - HOIST_END) / (TRAVEL_END - HOIST_END));
x = lerp(START_X, TARGET_X, t);
y = LIFT_Y;
} else if (time >= TRAVEL_END && time < LOWER_END) {
const t = smooth((time - TRAVEL_END) / (LOWER_END - TRAVEL_END));
x = TARGET_X;
y = lerp(LIFT_Y, TARGET_Y, t);
} else if (time >= LOWER_END) {
x = TARGET_X;
y = TARGET_Y;
}
// The same mesh is moved. Its dimensions, scale, and world orientation are locked.
container.position.set(x, y, 0);
container.scale.set(1, 1, 1);
container.quaternion.identity();
bridge.position.x = x;
let spreaderY = y + CONTAINER_HEIGHT / 2 + 0.22;
if (time >= LOWER_END) {
const release = smooth((time - LOWER_END) / (RELEASE_END - LOWER_END));
spreaderY += release * 1.18;
}
spreader.position.set(x, spreaderY, 0);
let cableIndex = 0;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
cableA.set(x + sx * 5.55, 8.10, sz * 0.25);
cableB.set(x + sx * 5.72, spreaderY + 0.10, sz * 0.69);
setRod(cables[cableIndex++], cableA, cableB);
}
}
beaconMaterial.emissiveIntensity = 1.5 + Math.sin(time * 7.0) * 0.85;
}
// -------------------------------------------------------------------------
// Custom camera controls implemented directly with core Three.js
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-1.0, 2.3, 0);
const spherical = new THREE.Spherical(42, 1.08, 0.64);
const cameraRight = new THREE.Vector3();
const cameraUp = new THREE.Vector3();
function applyCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTarget.set(-1.0, 2.3, 0);
spherical.set(42, 1.08, 0.64);
applyCamera();
}
let dragging = false;
let dragButton = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragButton = event.button;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragButton === 2 || event.shiftKey) {
const panScale = spherical.radius * 0.00125;
cameraRight.setFromMatrixColumn(camera.matrixWorld, 0);
cameraUp.setFromMatrixColumn(camera.matrixWorld, 1);
cameraTarget.addScaledVector(cameraRight, -dx * panScale);
cameraTarget.addScaledVector(cameraUp, dy * panScale);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 0.2, 9);
} else {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(spherical.phi - dy * 0.006, 0.30, 1.48);
}
applyCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
22,
62
);
applyCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Interface and playback
// -------------------------------------------------------------------------
const playButton = document.getElementById("play-button");
const restartButton = document.getElementById("restart-button");
const speedButton = document.getElementById("speed-button");
const cameraButton = document.getElementById("camera-button");
const timeline = document.getElementById("timeline");
const currentTime = document.getElementById("current-time");
const phaseTitle = document.getElementById("phase-title");
const phaseDetail = document.getElementById("phase-detail");
const statusIcon = document.getElementById("status-icon");
let elapsed = 0;
let playing = true;
let speed = 1;
let previousPhase = "";
const phases = {
ready: {
icon: "01",
title: "Secured on truck",
detail: "The spreader is engaged and the container is ready to lift."
},
hoist: {
icon: "02",
title: "Vertical hoist",
detail: "The load rises vertically; its dimensions and X-axis orientation remain locked."
},
travel: {
icon: "03",
title: "Bridge transfer",
detail: "The crane carries the same container from the road chassis to the rail wagon."
},
lower: {
icon: "04",
title: "Precision lowering",
detail: "The spreader descends toward the wagon corner locks with no yaw or roll."
},
release: {
icon: "05",
title: "Spreader release",
detail: "The twistlocks disengage while the container remains supported by the rail wagon."
},
complete: {
icon: "✓",
title: "Transfer complete",
detail: "One container, unchanged dimensions, now secured lengthwise on the rail wagon."
}
};
function phaseAt(time) {
if (time < HOIST_START) return "ready";
if (time < HOIST_END) return "hoist";
if (time < TRAVEL_END) return "travel";
if (time < LOWER_END) return "lower";
if (time < RELEASE_END) return "release";
return "complete";
}
function updateInterface(time) {
const phase = phaseAt(time);
if (phase !== previousPhase) {
previousPhase = phase;
const info = phases[phase];
phaseTitle.textContent = info.title;
phaseDetail.textContent = info.detail;
statusIcon.textContent = info.icon;
}
timeline.value = time.toFixed(2);
timeline.style.setProperty("--progress", `${(time / DURATION) * 100}%`);
currentTime.textContent = time.toFixed(1).padStart(4, "0");
}
function togglePlayback() {
if (elapsed >= DURATION) elapsed = 0;
playing = !playing;
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute("aria-label", playing ? "Pause animation" : "Play animation");
}
playButton.addEventListener("click", togglePlayback);
restartButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
playButton.textContent = "Ⅱ";
updateTransfer(elapsed);
updateInterface(elapsed);
});
speedButton.addEventListener("click", () => {
const speeds = [0.5, 1, 1.5, 2];
speed = speeds[(speeds.indexOf(speed) + 1) % speeds.length];
speedButton.textContent = `${speed}×`;
});
cameraButton.addEventListener("click", resetCamera);
timeline.addEventListener("input", () => {
elapsed = Number(timeline.value);
playing = false;
playButton.textContent = "▶";
updateTransfer(elapsed);
updateInterface(elapsed);
});
addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
togglePlayback();
} else if (event.key.toLowerCase() === "r") {
elapsed = 0;
playing = true;
playButton.textContent = "Ⅱ";
} else if (event.key.toLowerCase() === "v") {
resetCamera();
}
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
applyCamera();
updateTransfer(0);
updateInterface(0);
let lastTime = performance.now();
renderer.setAnimationLoop(now => {
const delta = Math.min(0.05, (now - lastTime) / 1000);
lastTime = now;
if (playing) {
elapsed = Math.min(DURATION, elapsed + delta * speed);
if (elapsed >= DURATION) {
playing = false;
playButton.textContent = "▶";
}
}
updateTransfer(elapsed);
updateInterface(elapsed);
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```