Prompt specification
Build or customize the Three.js 3D scene "Airlift cargo pallet and loading rollers" 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: Airlift cargo pallet and loading rollers
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/airlift-cargo-pallet-and-loading-rollers-x2413
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows the Berlin Airlift of 1948–1949. Build a period-appropriate cargo pallet beside a simple aircraft loading opening. Show package dimensions and a clear transfer path without claiming a particular aircraft's exact internal layout. Stylized solid forms.
Working Three.js Starter (airlift-cargo-pallet-and-loading-rollers-x2413):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Berlin Airlift 1948–1949 — Cargo Transfer Study</title>
<style>
:root {
--paper: #eee9dc;
--paper-light: #faf7ed;
--ink: #172d36;
--muted: #59696b;
--line: rgba(23, 45, 54, 0.22);
--orange: #e16f36;
--teal: #0b8f8a;
--yellow: #f1bd54;
--shadow: 0 12px 35px rgba(23, 45, 54, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
z-index: 1;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
#leaders {
position: fixed;
inset: 0;
z-index: 3;
width: 100%;
height: 100%;
pointer-events: none;
}
#leaders line {
stroke: rgba(23, 45, 54, 0.58);
stroke-width: 1.25;
stroke-dasharray: 4 4;
}
#annotations {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.annotation {
position: absolute;
width: max-content;
max-width: 190px;
padding: 9px 11px 8px;
transform: translate(-50%, -50%);
background: rgba(250, 247, 237, 0.94);
border: 1px solid rgba(23, 45, 54, 0.18);
border-left: 4px solid var(--orange);
border-radius: 2px;
box-shadow: 0 7px 20px rgba(23, 45, 54, 0.12);
backdrop-filter: blur(6px);
}
.annotation.teal {
border-left-color: var(--teal);
}
.annotation small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.annotation strong {
display: block;
font-size: 12px;
line-height: 1.3;
letter-spacing: 0.01em;
}
.annotation span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.25;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.masthead {
position: absolute;
top: 28px;
left: 30px;
max-width: 390px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.roundel {
display: inline-grid;
width: 30px;
height: 30px;
place-items: center;
border: 1px solid var(--ink);
border-radius: 50%;
color: var(--paper-light);
background: var(--ink);
font-family: Georgia, serif;
font-size: 11px;
letter-spacing: 0;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(39px, 5vw, 67px);
font-weight: 500;
line-height: 0.88;
letter-spacing: -0.045em;
}
.years {
display: inline-block;
margin-top: 13px;
padding: 5px 9px 4px;
color: var(--paper-light);
background: var(--orange);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.24em;
}
.masthead p {
max-width: 340px;
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.note-card {
position: absolute;
top: 28px;
right: 28px;
width: min(330px, calc(100vw - 56px));
padding: 17px 18px 16px;
border: 1px solid var(--line);
background: rgba(250, 247, 237, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
}
.card-label {
margin-bottom: 8px;
color: var(--orange);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.note-card h2 {
margin: 0 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.note-card p {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.55;
}
.manifest {
position: absolute;
right: 28px;
bottom: 28px;
width: 330px;
padding: 16px 18px 17px;
border: 1px solid var(--line);
background: rgba(250, 247, 237, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
}
.manifest-header {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
padding-bottom: 9px;
border-bottom: 1px solid var(--line);
}
.manifest-header strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 500;
}
.manifest-header span {
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.manifest-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
padding: 8px 0;
border-bottom: 1px solid rgba(23, 45, 54, 0.1);
font-size: 10px;
}
.manifest-row:last-child {
padding-bottom: 0;
border-bottom: 0;
}
.manifest-row b {
color: var(--muted);
font-weight: 600;
}
.manifest-row span {
font-variant-numeric: tabular-nums;
font-weight: 800;
text-align: right;
}
.order-note {
margin-top: 10px;
color: var(--muted);
font-size: 8.5px;
line-height: 1.45;
}
.controls {
position: absolute;
bottom: 28px;
left: 30px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.controls button {
min-height: 34px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 2px;
color: var(--ink);
background: rgba(250, 247, 237, 0.92);
box-shadow: 0 4px 14px rgba(23, 45, 54, 0.08);
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
transition: background 140ms ease, transform 140ms ease;
}
.controls button:hover {
background: #fffdf5;
transform: translateY(-1px);
}
.controls button[aria-pressed="false"] {
color: #829092;
background: rgba(235, 232, 220, 0.84);
}
.control-hint {
margin-left: 7px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scale-note {
position: absolute;
right: 28px;
bottom: 8px;
color: rgba(23, 45, 54, 0.48);
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#no-webgl {
position: fixed;
inset: 0;
z-index: 100;
display: none;
place-items: center;
padding: 30px;
background: var(--paper);
color: var(--ink);
text-align: center;
}
@media (max-width: 1000px) {
.note-card {
width: 285px;
}
.manifest {
width: 285px;
}
.masthead {
max-width: 320px;
}
h1 {
font-size: 48px;
}
.control-hint {
display: none;
}
}
@media (max-width: 720px) {
.masthead {
top: 18px;
left: 18px;
}
.eyebrow {
margin-bottom: 8px;
font-size: 8px;
}
.roundel {
width: 25px;
height: 25px;
font-size: 9px;
}
h1 {
font-size: 38px;
}
.years {
margin-top: 9px;
font-size: 9px;
}
.masthead p,
.note-card,
.manifest,
.scale-note {
display: none;
}
.controls {
bottom: 16px;
left: 18px;
}
.controls button {
min-height: 32px;
padding: 7px 9px;
font-size: 8px;
}
.annotation {
max-width: 160px;
padding: 7px 9px;
}
.annotation strong {
font-size: 10px;
}
.annotation span {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.controls button {
transition: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive stylized model of a Berlin Airlift cargo pallet and generic aircraft loading opening"></div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="annotations" aria-hidden="true">
<div class="annotation" id="anno-pallet">
<small>Wooden pallet</small>
<strong>1.35 × 0.95 × 0.18 m</strong>
<span>Width × depth × deck height</span>
</div>
<div class="annotation" id="anno-crate">
<small>Timber crate</small>
<strong>0.62 × 0.46 × 0.52 m</strong>
<span>Illustrative package dimensions</span>
</div>
<div class="annotation" id="anno-sack">
<small>Burlap sack</small>
<strong>Ø 0.44 × 0.66 m</strong>
<span>Diameter × height</span>
</div>
<div class="annotation" id="anno-opening">
<small>Generic opening mock-up</small>
<strong>1.40 × 1.30 m</strong>
<span>Illustrative only — not an aircraft specification</span>
</div>
<div class="annotation teal" id="anno-path">
<small>Transfer sequence</small>
<strong>Pallet → ramp → opening</strong>
<span>Direction shown by moving arrowheads</span>
</div>
</div>
<main class="hud">
<header class="masthead">
<div class="eyebrow">
<span class="roundel">BA</span>
U.S. “Vittles” · British “Plainfare”
</div>
<h1>Berlin Airlift</h1>
<div class="years">1948—1949</div>
<p>A period cargo-handling study: wooden pallet, ration crates, burlap packing, and a clear apron-to-hold transfer path.</p>
</header>
<aside class="note-card">
<div class="card-label">Interpretive scene</div>
<h2>Deliberately generic aircraft</h2>
<p>
The cargo forms and handling sequence evoke the 1948–1949 airlift.
The aircraft body and opening are schematic. The shown opening dimensions
are illustrative and do not describe the internal arrangement or loading
specification of any particular aircraft type.
</p>
</aside>
<section class="manifest" aria-label="Illustrative package dimensions">
<div class="manifest-header">
<strong>Illustrative load</strong>
<span>metres</span>
</div>
<div class="manifest-row">
<b>Wooden pallet</b>
<span>1.35 × 0.95 × 0.18</span>
</div>
<div class="manifest-row">
<b>Timber crate</b>
<span>0.62 × 0.46 × 0.52</span>
</div>
<div class="manifest-row">
<b>Burlap sack</b>
<span>Ø 0.44 × 0.66</span>
</div>
<div class="manifest-row">
<b>Small ration crate</b>
<span>0.34 × 0.28 × 0.28</span>
</div>
<div class="order-note">
Package figures describe this interpretive model. Dimensions are listed as
width × depth × height unless marked with a diameter symbol.
</div>
</section>
<nav class="controls" aria-label="Scene controls">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-dimensions" type="button" aria-pressed="true">Dimensions</button>
<button id="toggle-path" type="button" aria-pressed="true">Transfer path</button>
<span class="control-hint">Drag to orbit · Scroll to zoom · R to reset</span>
</nav>
<div class="scale-note">Stylized solid-form study · Dimensions apply only to this model</div>
</main>
<div id="no-webgl">
<div>
<h2>WebGL is required</h2>
<p>This scene needs a browser with WebGL enabled.</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const leaderSvg = document.getElementById("leaders");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
document.getElementById("no-webgl").style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Interactive Berlin Airlift cargo scene");
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdcded7);
scene.fog = new THREE.Fog(0xdcded7, 12, 27);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const controls = {
target: new THREE.Vector3(0.65, 1.02, 0.48),
radius: window.innerWidth < 720 ? 13.8 : 9.1,
theta: 0.56,
phi: 1.13
};
const initialControls = { ...controls, target: controls.target.clone() };
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
// ---------------------------------------------------------------------
// Lighting and ground
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x617173, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d5, 3.1);
keyLight.position.set(-4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbad9dd, 1.0);
fillLight.position.set(6, 3, -5);
scene.add(fillLight);
const apron = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xc9cbc4,
roughness: 0.96,
metalness: 0
})
);
apron.rotation.x = -Math.PI / 2;
apron.receiveShadow = true;
scene.add(apron);
const gridMaterial = new THREE.LineBasicMaterial({
color: 0x87918e,
transparent: true,
opacity: 0.18
});
const gridPoints = [];
for (let x = -12; x <= 12; x += 2) {
gridPoints.push(new THREE.Vector3(x, 0.004, -12), new THREE.Vector3(x, 0.004, 12));
}
for (let z = -12; z <= 12; z += 2) {
gridPoints.push(new THREE.Vector3(-12, 0.004, z), new THREE.Vector3(12, 0.004, z));
}
const grid = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(gridPoints),
gridMaterial
);
scene.add(grid);
// Painted apron guide stripe, kept subtle.
const stripe = new THREE.Mesh(
new THREE.PlaneGeometry(9.2, 0.09),
new THREE.MeshBasicMaterial({
color: 0xe6c54f,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
stripe.rotation.x = -Math.PI / 2;
stripe.position.set(-0.25, 0.008, 2.8);
scene.add(stripe);
// ---------------------------------------------------------------------
// Shared materials
// ---------------------------------------------------------------------
const materials = {
aircraft: new THREE.MeshStandardMaterial({
color: 0xaeb8b5,
roughness: 0.78,
metalness: 0.16
}),
aircraftLight: new THREE.MeshStandardMaterial({
color: 0xc9cfca,
roughness: 0.72,
metalness: 0.12
}),
aircraftDark: new THREE.MeshStandardMaterial({
color: 0x33464b,
roughness: 0.72,
metalness: 0.28
}),
hold: new THREE.MeshStandardMaterial({
color: 0x26373b,
roughness: 0.96
}),
wood: new THREE.MeshStandardMaterial({
color: 0xa86e3e,
roughness: 0.93
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0xc58b50,
roughness: 0.9
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x74462e,
roughness: 0.96
}),
burlap: new THREE.MeshStandardMaterial({
color: 0xb79761,
roughness: 1
}),
strap: new THREE.MeshStandardMaterial({
color: 0x34413e,
roughness: 0.9
}),
steel: new THREE.MeshStandardMaterial({
color: 0x687171,
roughness: 0.56,
metalness: 0.62
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x1d2728,
roughness: 0.96
}),
route: new THREE.MeshBasicMaterial({
color: 0x0b8f8a,
transparent: true,
opacity: 0.86
}),
arrow: new THREE.MeshBasicMaterial({
color: 0xf19a42
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Generic aircraft body: a schematic cutout, not an aircraft type
// ---------------------------------------------------------------------
const aircraft = new THREE.Group();
scene.add(aircraft);
const fuselageShape = new THREE.Shape();
fuselageShape.moveTo(0.55, 0.42);
fuselageShape.lineTo(5.63, 0.42);
fuselageShape.quadraticCurveTo(5.97, 0.48, 6.02, 0.86);
fuselageShape.lineTo(6.02, 2.08);
fuselageShape.quadraticCurveTo(5.93, 2.56, 5.43, 2.83);
fuselageShape.lineTo(2.05, 3.03);
fuselageShape.quadraticCurveTo(0.86, 3.03, 0.59, 2.35);
fuselageShape.lineTo(0.55, 0.42);
const openingHole = new THREE.Path();
openingHole.moveTo(1.10, 0.58);
openingHole.lineTo(2.55, 0.58);
openingHole.lineTo(2.55, 1.88);
openingHole.lineTo(1.10, 1.88);
openingHole.closePath();
fuselageShape.holes.push(openingHole);
const fuselageGeometry = new THREE.ExtrudeGeometry(fuselageShape, {
depth: 1.35,
steps: 1,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.055,
bevelThickness: 0.055,
curveSegments: 16
});
fuselageGeometry.translate(0, 0, -0.675);
const fuselage = new THREE.Mesh(fuselageGeometry, materials.aircraft);
fuselage.castShadow = true;
fuselage.receiveShadow = true;
aircraft.add(fuselage);
// Simplified tail silhouette, deliberately non-specific.
const tailShape = new THREE.Shape();
tailShape.moveTo(4.68, 2.66);
tailShape.lineTo(5.30, 3.55);
tailShape.lineTo(5.74, 3.55);
tailShape.lineTo(5.74, 2.67);
tailShape.closePath();
const tailGeometry = new THREE.ExtrudeGeometry(tailShape, {
depth: 1.35,
bevelEnabled: true,
bevelSize: 0.04,
bevelThickness: 0.04,
bevelSegments: 1
});
tailGeometry.translate(0, 0, -0.675);
const tail = new THREE.Mesh(tailGeometry, materials.aircraftLight);
tail.castShadow = true;
aircraft.add(tail);
// Far-side wing suggestion.
addBox(
aircraft,
new THREE.Vector3(1.85, 0.09, 2.25),
new THREE.Vector3(3.55, 1.00, -1.15),
materials.aircraft
);
// Dark interior behind the opening.
addBox(
aircraft,
new THREE.Vector3(1.62, 1.48, 0.06),
new THREE.Vector3(1.825, 1.21, -0.59),
materials.hold
);
addBox(
aircraft,
new THREE.Vector3(1.52, 0.08, 1.20),
new THREE.Vector3(1.825, 0.54, 0.00),
new THREE.MeshStandardMaterial({
color: 0x4e5d55,
roughness: 0.93
})
);
// Opening frame.
const frameZ = 0.715;
addBox(
aircraft,
new THREE.Vector3(0.075, 1.40, 0.075),
new THREE.Vector3(1.07, 1.23, frameZ),
materials.aircraftDark
);
addBox(
aircraft,
new THREE.Vector3(0.075, 1.40, 0.075),
new THREE.Vector3(2.58, 1.23, frameZ),
materials.aircraftDark
);
addBox(
aircraft,
new THREE.Vector3(1.58, 0.075, 0.075),
new THREE.Vector3(1.825, 1.92, frameZ),
materials.aircraftDark
);
addBox(
aircraft,
new THREE.Vector3(1.58, 0.075, 0.075),
new THREE.Vector3(1.825, 0.545, frameZ),
materials.aircraftDark
);
// A few small cabin windows, purely schematic.
const windowGeometry = new THREE.CircleGeometry(0.105, 20);
for (const x of [3.05, 3.43, 3.81, 4.19, 4.57]) {
const windowMesh = new THREE.Mesh(windowGeometry, materials.aircraftDark);
windowMesh.position.set(x, 2.25, 0.691);
aircraft.add(windowMesh);
}
// Landing gear and wheels.
for (const x of [1.40, 4.85]) {
addBox(
aircraft,
new THREE.Vector3(0.10, 0.42, 0.10),
new THREE.Vector3(x, 0.30, 0.18),
materials.steel
);
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.18, 24),
materials.rubber
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.255, 0.50);
wheel.castShadow = true;
aircraft.add(wheel);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.095, 0.19, 20),
materials.steel
);
hub.rotation.x = Math.PI / 2;
hub.position.set(x, 0.255, 0.51);
aircraft.add(hub);
}
// ---------------------------------------------------------------------
// Wooden cargo pallet
// ---------------------------------------------------------------------
const pallet = new THREE.Group();
scene.add(pallet);
const palletCenter = new THREE.Vector3(-1.40, 0, 1.70);
// Bottom runners.
for (const zOffset of [-0.34, 0, 0.34]) {
addBox(
pallet,
new THREE.Vector3(1.27, 0.05, 0.13),
new THREE.Vector3(
palletCenter.x,
0.025,
palletCenter.z + zOffset
),
materials.woodDark
);
}
// Blocks.
for (const xOffset of [-0.52, 0, 0.52]) {
for (const zOffset of [-0.34, 0.34]) {
addBox(
pallet,
new THREE.Vector3(0.18, 0.075, 0.18),
new THREE.Vector3(
palletCenter.x + xOffset,
0.0875,
palletCenter.z + zOffset
),
materials.woodDark
);
}
}
// Cross beams.
for (const xOffset of [-0.50, 0.50]) {
addBox(
pallet,
new THREE.Vector3(0.13, 0.065, 0.91),
new THREE.Vector3(
palletCenter.x + xOffset,
0.125,
palletCenter.z
),
materials.woodDark
);
}
// Deck boards.
for (let i = 0; i < 7; i++) {
const z = palletCenter.z - 0.42 + i * 0.14;
addBox(
pallet,
new THREE.Vector3(1.35, 0.06, 0.12),
new THREE.Vector3(palletCenter.x, 0.145, z),
i % 2 === 0 ? materials.woodLight : materials.wood
);
}
// Metal corner protectors.
for (const x of [-0.64, 0.64]) {
for (const z of [-0.43, 0.43]) {
addBox(
pallet,
new THREE.Vector3(0.08, 0.035, 0.08),
new THREE.Vector3(
palletCenter.x + x,
0.185,
palletCenter.z + z
),
materials.steel
);
}
}
// Main timber crate.
const crate = new THREE.Group();
crate.position.set(-1.73, 0.18, 1.48);
pallet.add(crate);
addBox(
crate,
new THREE.Vector3(0.62, 0.52, 0.46),
new THREE.Vector3(0, 0.26, 0),
materials.woodLight
);
// Front battens.
for (const x of [-0.22, 0, 0.22]) {
addBox(
crate,
new THREE.Vector3(0.055, 0.51, 0.025),
new THREE.Vector3(x, 0.26, 0.242),
materials.woodDark
);
}
for (const y of [0.09, 0.43]) {
addBox(
crate,
new THREE.Vector3(0.61, 0.055, 0.025),
new THREE.Vector3(0, y, 0.242),
materials.woodDark
);
}
// Simple dark securing straps.
for (const x of [-0.18, 0.18]) {
addBox(
crate,
new THREE.Vector3(0.035, 0.535, 0.485),
new THREE.Vector3(x, 0.26, 0),
materials.strap
);
}
// Burlap sack, modeled as a faceted solid.
const sackProfile = [
new THREE.Vector2(0.17, 0.00),
new THREE.Vector2(0.215, 0.055),
new THREE.Vector2(0.22, 0.17),
new THREE.Vector2(0.205, 0.31),
new THREE.Vector2(0.17, 0.44),
new THREE.Vector2(0.115, 0.54),
new THREE.Vector2(0.075, 0.60),
new THREE.Vector2(0.09, 0.63),
new THREE.Vector2(0.055, 0.66),
new THREE.Vector2(0.00, 0.66)
];
const sack = new THREE.Mesh(
new THREE.LatheGeometry(sackProfile, 16),
materials.burlap
);
sack.position.set(-0.98, 0.18, 1.51);
sack.rotation.y = 0.22;
sack.castShadow = true;
sack.receiveShadow = true;
pallet.add(sack);
const sackTie = new THREE.Mesh(
new THREE.TorusGeometry(0.086, 0.015, 8, 18),
materials.strap
);
sackTie.rotation.x = Math.PI / 2;
sackTie.position.set(-0.98, 0.805, 1.51);
pallet.add(sackTie);
// Small ration crate.
const smallCrate = new THREE.Group();
smallCrate.position.set(-1.72, 0.18, 1.96);
pallet.add(smallCrate);
addBox(
smallCrate,
new THREE.Vector3(0.34, 0.28, 0.28),
new THREE.Vector3(0, 0.14, 0),
materials.wood
);
addBox(
smallCrate,
new THREE.Vector3(0.045, 0.29, 0.29),
new THREE.Vector3(-0.11, 0.14, 0),
materials.woodDark
);
addBox(
smallCrate,
new THREE.Vector3(0.045, 0.29, 0.29),
new THREE.Vector3(0.11, 0.14, 0),
materials.woodDark
);
// ---------------------------------------------------------------------
// Ramp and animated transfer path
// ---------------------------------------------------------------------
const rampStart = new THREE.Vector3(0.25, 0.19, 1.72);
const rampEnd = new THREE.Vector3(1.25, 0.54, 0.73);
const rampVector = rampEnd.clone().sub(rampStart);
const rampLength = rampVector.length();
const ramp = new THREE.Mesh(
new THREE.BoxGeometry(rampLength, 0.075, 0.78),
new THREE.MeshStandardMaterial({
color: 0x777f79,
roughness: 0.82,
metalness: 0.24
})
);
ramp.position.copy(rampStart).add(rampEnd).multiplyScalar(0.5);
ramp.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
rampVector.clone().normalize()
);
ramp.castShadow = true;
ramp.receiveShadow = true;
scene.add(ramp);
const pathGroup = new THREE.Group();
scene.add(pathGroup);
const transferCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.68, 0.235, 1.68),
new THREE.Vector3(0.10, 0.235, 1.68),
new THREE.Vector3(0.42, 0.285, 1.51),
new THREE.Vector3(0.78, 0.39, 1.20),
new THREE.Vector3(1.18, 0.54, 0.82),
new THREE.Vector3(1.66, 0.70, 0.45)
]);
const pathTube = new THREE.Mesh(
new THREE.TubeGeometry(transferCurve, 80, 0.027, 8, false),
materials.route
);
pathGroup.add(pathTube);
const arrowGeometry = new THREE.ConeGeometry(0.085, 0.21, 12);
const movingArrows = [];
for (let i = 0; i < 3; i++) {
const arrow = new THREE.Mesh(arrowGeometry, materials.arrow);
arrow.userData.marker = true;
arrow.userData.phase = i / 3;
pathGroup.add(arrow);
movingArrows.push(arrow);
}
const upAxis = new THREE.Vector3(0, 1, 0);
function placeArrow(arrow, t) {
const point = transferCurve.getPoint(t);
const tangent = transferCurve.getTangent(t).normalize();
arrow.position.copy(point);
arrow.quaternion.setFromUnitVectors(upAxis, tangent);
}
if (reducedMotion) {
movingArrows.forEach((arrow, index) => {
placeArrow(arrow, [0.16, 0.48, 0.80][index]);
});
}
// ---------------------------------------------------------------------
// Dimension lines
// ---------------------------------------------------------------------
const dimensionGroup = new THREE.Group();
scene.add(dimensionGroup);
function addDimensionLine(a, b, tickDirection, color = 0xe16f36) {
const tick = tickDirection.clone().normalize().multiplyScalar(0.07);
const points = [
a, b,
a.clone().sub(tick), a.clone().add(tick),
b.clone().sub(tick), b.clone().add(tick)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({ color })
);
dimensionGroup.add(line);
}
// Pallet width.
addDimensionLine(
new THREE.Vector3(-2.075, 0.085, 2.225),
new THREE.Vector3(-0.725, 0.085, 2.225),
new THREE.Vector3(0, 1, 0)
);
// Main crate width.
addDimensionLine(
new THREE.Vector3(-2.04, 0.71, 1.73),
new THREE.Vector3(-1.42, 0.71, 1.73),
new THREE.Vector3(0, 1, 0)
);
// Sack height.
addDimensionLine(
new THREE.Vector3(-0.755, 0.18, 1.51),
new THREE.Vector3(-0.755, 0.84, 1.51),
new THREE.Vector3(1, 0, 0)
);
// Generic opening width.
addDimensionLine(
new THREE.Vector3(1.10, 1.965, 0.73),
new THREE.Vector3(2.55, 1.965, 0.73),
new THREE.Vector3(0, 1, 0),
0x0b8f8a
);
// ---------------------------------------------------------------------
// Screen-space annotations
// ---------------------------------------------------------------------
const annotations = [
{
element: document.getElementById("anno-pallet"),
anchor: new THREE.Vector3(-1.40, 0.11, 2.23),
offset: new THREE.Vector2(-128, 84),
type: "dimension"
},
{
element: document.getElementById("anno-crate"),
anchor: new THREE.Vector3(-1.73, 0.71, 1.73),
offset: new THREE.Vector2(-125, -80),
type: "dimension"
},
{
element: document.getElementById("anno-sack"),
anchor: new THREE.Vector3(-0.98, 0.84, 1.51),
offset: new THREE.Vector2(62, -91),
type: "dimension"
},
{
element: document.getElementById("anno-opening"),
anchor: new THREE.Vector3(1.825, 1.96, 0.73),
offset: new THREE.Vector2(67, -83),
type: "dimension"
},
{
element: document.getElementById("anno-path"),
anchor: new THREE.Vector3(0.25, 0.30, 1.55),
offset: new THREE.Vector2(-80, 92),
type: "path"
}
];
const svgNS = "http://www.w3.org/2000/svg";
for (const annotation of annotations) {
const line = document.createElementNS(svgNS, "line");
leaderSvg.appendChild(line);
annotation.line = line;
}
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
projected.copy(annotation.anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.display = visible ? "block" : "none";
annotation.line.style.display = visible ? "block" : "none";
if (!visible) continue;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const desiredX = anchorX + annotation.offset.x;
const desiredY = anchorY + annotation.offset.y;
const x = THREE.MathUtils.clamp(
desiredX,
90,
Math.max(90, width - 90)
);
const y = THREE.MathUtils.clamp(
desiredY,
85,
Math.max(85, height - 65)
);
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
annotation.line.setAttribute("x1", anchorX.toFixed(1));
annotation.line.setAttribute("y1", anchorY.toFixed(1));
annotation.line.setAttribute("x2", x.toFixed(1));
annotation.line.setAttribute("y2", y.toFixed(1));
}
}
// ---------------------------------------------------------------------
// Direct camera controls — no add-ons
// ---------------------------------------------------------------------
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.35,
1.48
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", (event) => {
if (dragging && event.buttons === 0) endDrag(event);
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
5.4,
17
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetView);
function resetView() {
controls.radius = initialControls.radius;
controls.theta = initialControls.theta;
controls.phi = initialControls.phi;
controls.target.copy(initialControls.target);
}
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetView();
} else if (key === "arrowleft") {
controls.theta += 0.09;
} else if (key === "arrowright") {
controls.theta -= 0.09;
} else if (key === "arrowup") {
controls.phi = Math.max(0.35, controls.phi - 0.07);
} else if (key === "arrowdown") {
controls.phi = Math.min(1.48, controls.phi + 0.07);
} else if (key === "+" || key === "=") {
controls.radius = Math.max(5.4, controls.radius - 0.45);
} else if (key === "-") {
controls.radius = Math.min(17, controls.radius + 0.45);
}
});
document.getElementById("reset-view").addEventListener("click", resetView);
const dimensionsButton = document.getElementById("toggle-dimensions");
const pathButton = document.getElementById("toggle-path");
dimensionsButton.addEventListener("click", () => {
const visible = dimensionsButton.getAttribute("aria-pressed") !== "true";
dimensionsButton.setAttribute("aria-pressed", String(visible));
dimensionGroup.visible = visible;
for (const annotation of annotations) {
if (annotation.type === "dimension") {
annotation.element.style.visibility = visible ? "visible" : "hidden";
annotation.line.style.visibility = visible ? "visible" : "hidden";
}
}
});
pathButton.addEventListener("click", () => {
const visible = pathButton.getAttribute("aria-pressed") !== "true";
pathButton.setAttribute("aria-pressed", String(visible));
pathGroup.visible = visible;
for (const annotation of annotations) {
if (annotation.type === "path") {
annotation.element.style.visibility = visible ? "visible" : "hidden";
annotation.line.style.visibility = visible ? "visible" : "hidden";
}
}
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
leaderSvg.setAttribute("viewBox", `0 0 ${window.innerWidth} ${window.innerHeight}`);
});
leaderSvg.setAttribute(
"viewBox",
`0 0 ${window.innerWidth} ${window.innerHeight}`
);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (!reducedMotion) {
movingArrows.forEach((arrow) => {
const t = (elapsed * 0.15 + arrow.userData.phase) % 1;
placeArrow(arrow, t);
});
}
updateCamera();
camera.updateMatrixWorld();
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```