Prompt specification
Build or customize the Three.js 3D scene "Compare cargo unloading before a portage" 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: Compare cargo unloading before a portage
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-cargo-unloading-before-a-portage-x2640
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Viking river routes and overland portages. Let users choose how much fictional cargo to remove before overland transfer. Display handling steps and assumed force requirements, labeling the mechanical model as simplified. Voxel style.
Working Three.js Starter (compare-cargo-unloading-before-a-portage-x2640):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Viking River Route & Portage</title>
<style>
:root {
--ink: #17272a;
--paper: #f3ead7;
--panel: rgba(21, 35, 38, 0.95);
--panel-soft: rgba(31, 49, 51, 0.86);
--line: rgba(243, 234, 215, 0.18);
--muted: #a9b9b5;
--amber: #e9a63a;
--amber-light: #ffd17a;
--blue: #69b9ce;
--green: #8eae75;
--red: #d8674f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fc5c9;
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.brand {
position: absolute;
top: 18px;
left: 18px;
z-index: 6;
display: flex;
align-items: center;
gap: 11px;
padding: 10px 14px 10px 10px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 12px;
background: rgba(20, 38, 41, 0.86);
box-shadow: 0 8px 30px rgba(24, 38, 37, 0.18);
backdrop-filter: blur(10px);
pointer-events: none;
}
.brand-mark {
display: grid;
place-items: center;
width: 38px;
height: 38px;
border-radius: 9px;
background: var(--amber);
color: #243236;
font-size: 25px;
font-weight: 800;
}
.brand strong {
display: block;
font-size: 13px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.brand span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.04em;
}
#panelToggle {
position: absolute;
top: 20px;
right: 18px;
z-index: 12;
display: none;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 10px;
padding: 10px 13px;
background: rgba(20, 38, 41, 0.92);
color: var(--paper);
cursor: pointer;
}
.panel {
position: absolute;
top: 18px;
left: 18px;
z-index: 8;
width: 372px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(16, 27, 29, 0.3);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: #6a7a76 transparent;
}
.eyebrow {
color: var(--amber-light);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.panel h2 {
margin: 6px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
line-height: 1.08;
}
.intro {
margin: 0 0 17px;
color: #c4ceca;
font-size: 12px;
line-height: 1.55;
}
.control-block {
padding: 14px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--panel-soft);
}
.control-label {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.control-label span {
color: #d4ddd8;
font-size: 12px;
font-weight: 650;
}
.control-label output {
color: var(--amber-light);
font-size: 12px;
font-weight: 800;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 5px 0 8px;
border-radius: 99px;
appearance: none;
background:
linear-gradient(
to right,
var(--amber) 0%,
var(--amber) var(--range-fill, 22%),
rgba(255, 255, 255, 0.13) var(--range-fill, 22%),
rgba(255, 255, 255, 0.13) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 19px;
height: 19px;
border: 3px solid #203639;
border-radius: 50%;
appearance: none;
background: var(--amber-light);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid #203639;
border-radius: 50%;
background: var(--amber-light);
}
.range-scale {
display: flex;
justify-content: space-between;
color: #829590;
font-size: 10px;
}
.inventory {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 13px 0;
padding: 11px 12px;
border-left: 3px solid var(--blue);
border-radius: 6px;
background: rgba(105, 185, 206, 0.09);
color: #c7d8d6;
font-size: 11px;
}
.inventory strong {
display: block;
margin-top: 2px;
color: white;
font-size: 15px;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 72px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
}
.metric span {
display: block;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 7px;
color: #fff8e9;
font-size: 19px;
font-weight: 750;
}
.metric small {
display: block;
margin-top: 2px;
color: #93a6a1;
font-size: 10px;
}
.force-card {
margin-top: 9px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(233, 166, 58, 0.065);
}
.force-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 9px;
font-size: 11px;
}
.force-head span {
color: #c6d2ce;
}
.status {
padding: 4px 7px;
border-radius: 99px;
background: rgba(133, 181, 126, 0.18);
color: #b9dfa7;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.status.over {
background: rgba(216, 103, 79, 0.18);
color: #f0a28e;
}
.force-track {
height: 8px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.09);
}
#forceFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #9dbc75, #e9a63a);
transition: width 180ms ease;
}
.force-foot {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #91a39e;
font-size: 9px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 17px 0 9px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-size: 9px;
font-weight: 500;
letter-spacing: 0;
text-transform: none;
}
.steps {
margin: 0;
padding: 0;
list-style: none;
counter-reset: step;
}
.steps li {
position: relative;
min-height: 43px;
padding: 2px 0 11px 38px;
color: #c5d0cc;
font-size: 11px;
line-height: 1.42;
counter-increment: step;
}
.steps li::before {
content: counter(step);
position: absolute;
top: 0;
left: 0;
display: grid;
place-items: center;
width: 26px;
height: 26px;
border: 1px solid rgba(233, 166, 58, 0.4);
border-radius: 7px;
background: rgba(233, 166, 58, 0.1);
color: var(--amber-light);
font-size: 10px;
font-weight: 800;
}
.steps strong {
display: block;
margin-bottom: 2px;
color: #f5eee0;
font-size: 12px;
}
.model-note {
margin-top: 8px;
padding: 12px;
border: 1px solid rgba(233, 166, 58, 0.28);
border-radius: 9px;
background: rgba(233, 166, 58, 0.07);
color: #b8c5c0;
font-size: 10px;
line-height: 1.5;
}
.model-note strong {
display: block;
margin-bottom: 4px;
color: var(--amber-light);
font-size: 11px;
}
.formula {
display: block;
margin: 7px 0;
padding: 7px;
border-radius: 5px;
background: rgba(0, 0, 0, 0.18);
color: #e2e7df;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.world-label {
position: absolute;
z-index: 4;
min-width: 115px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 7px;
background: rgba(24, 40, 42, 0.83);
box-shadow: 0 5px 20px rgba(20, 31, 32, 0.18);
color: white;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-align: center;
text-transform: uppercase;
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(7px);
transition: opacity 120ms ease;
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
background: rgba(255, 255, 255, 0.58);
}
.world-label small {
display: block;
margin-top: 3px;
color: #b6c5c1;
font-size: 8px;
font-weight: 500;
letter-spacing: 0.04em;
text-transform: none;
}
.world-label.portage {
border-color: rgba(233, 166, 58, 0.6);
background: rgba(71, 52, 26, 0.88);
color: #ffe0a1;
}
.legend {
position: absolute;
right: 18px;
bottom: 18px;
z-index: 5;
display: flex;
align-items: center;
gap: 14px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 9px;
background: rgba(20, 38, 41, 0.84);
color: #c5d1cd;
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(9px);
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
}
.legend .hint {
padding-left: 12px;
border-left: 1px solid rgba(255, 255, 255, 0.16);
color: #8fa29d;
}
@media (max-width: 760px) {
.brand {
top: 10px;
left: 10px;
max-width: calc(100vw - 142px);
}
.brand-mark {
width: 32px;
height: 32px;
}
.brand strong {
font-size: 10px;
}
.brand span {
overflow: hidden;
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
#panelToggle {
top: 10px;
right: 10px;
display: block;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 66vh;
transform: translateY(calc(100% + 20px));
transition: transform 180ms ease;
}
.panel.open {
transform: translateY(0);
}
.legend {
right: 10px;
bottom: 10px;
}
.legend .hint,
.legend .cache-key {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" tabindex="0" aria-label="Interactive voxel Viking river and portage scene"></canvas>
<div class="brand">
<div class="brand-mark">ᛉ</div>
<div>
<strong>Northern Route / 01</strong>
<span>Fictional Viking cargo logistics</span>
</div>
</div>
<button id="panelToggle" type="button" aria-controls="panel">Adjust transfer</button>
<aside class="panel" id="panel" aria-label="Portage cargo controls">
<div class="eyebrow">River landing → eastern outpost</div>
<h2>Before the overland carry</h2>
<p class="intro">
Set aside part of the fictional river cargo at the landing. The remaining
load is carried along the highlighted 180 m portage.
</p>
<div class="control-block">
<div class="control-label">
<span>Cargo removed before transfer</span>
<output id="removedValue" for="cargoRange">4 crates · 400 kg</output>
</div>
<input
id="cargoRange"
type="range"
min="0"
max="18"
step="1"
value="4"
aria-label="Number of 100 kilogram cargo crates removed before portage"
/>
<div class="range-scale">
<span>Keep all aboard</span>
<span>Set aside all 18</span>
</div>
<div class="inventory">
<div>Remaining overland load</div>
<strong id="remainingValue">14 crates · 1,400 kg</strong>
</div>
</div>
<div class="metric-grid">
<div class="metric">
<span>Portage trips</span>
<strong id="tripsValue">6</strong>
<small>maximum 240 kg per trip</small>
</div>
<div class="metric">
<span>Combined pull</span>
<strong id="pullValue">2.61 kN</strong>
<small>equivalent sled-haul force</small>
</div>
<div class="metric">
<span>Per porter</span>
<strong id="porterValue">0.43 kN</strong>
<small>600 N assumed limit</small>
</div>
<div class="metric">
<span>Estimated work</span>
<strong id="estimateValue">1.8 h</strong>
<small>round trips + handling</small>
</div>
</div>
<div class="force-card">
<div class="force-head">
<span>Team effort against assumed capacity</span>
<span class="status" id="forceStatus">Within limit</span>
</div>
<div class="force-track"><div id="forceFill"></div></div>
<div class="force-foot">
<span id="forceCurrent">0.00 kN per porter</span>
<span>0.60 kN limit</span>
</div>
</div>
<div class="section-title">
Handling sequence <span id="loadSummary">1,400 kg remaining</span>
</div>
<ol class="steps" id="steps"></ol>
<div class="model-note">
<strong>Mechanical model: simplified.</strong>
This is an illustrative force model, not a historical reconstruction.
It assumes 18 fictional 100 kg crates, 6 porters, 40 kg carried per porter
per trip, a 180 m route, 3% grade, and 0.16 sliding friction.
<span class="formula">F = m · g · (μ + sin θ)</span>
A crate is assumed to be lifted by two people. Porters are assumed to
sustain 600 N each. Crew mass, pauses, terrain variation, weather,
acceleration, and individual differences are not modeled.
</div>
</aside>
<div class="world-label" id="labelRiver">
River route
<small>cargo run · upstream</small>
</div>
<div class="world-label" id="labelLanding">
Landing cache
<small>cargo removed here</small>
</div>
<div class="world-label portage" id="labelPortage">
Overland portage
<small>180 m · 3% grade</small>
</div>
<div class="world-label" id="labelOutpost">
Eastern outpost
<small>transfer destination</small>
</div>
<div class="legend">
<span><i class="swatch" style="background:#5ca9c0"></i>River</span>
<span><i class="swatch" style="background:#dfa342"></i>Portage</span>
<span class="cache-key"><i class="swatch" style="background:#a86643"></i>Cargo</span>
<span class="hint">Drag to orbit · scroll to zoom</span>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9fc5c9);
scene.fog = new THREE.Fog(0x9fc5c9, 66, 125);
const camera = new THREE.OrthographicCamera(-40, 40, 23, -23, 0.1, 250);
const cameraTarget = new THREE.Vector3(2.5, 0, 3.5);
const hemisphere = new THREE.HemisphereLight(0xd9f1ff, 0x344333, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0ce, 3.2);
sun.position.set(-24, 45, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -52;
sun.shadow.camera.right = 52;
sun.shadow.camera.top = 42;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 120;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8dc7da, 0.65);
fill.position.set(30, 15, -28);
scene.add(fill);
const materials = {
wood: new THREE.MeshStandardMaterial({ color: 0x6f4931, roughness: 0.92 }),
woodLight: new THREE.MeshStandardMaterial({ color: 0xa16b3e, roughness: 0.9 }),
woodDark: new THREE.MeshStandardMaterial({ color: 0x493226, roughness: 1 }),
cargo: new THREE.MeshStandardMaterial({ color: 0xb06b40, roughness: 0.9 }),
cargoBand: new THREE.MeshStandardMaterial({ color: 0x5b3929, roughness: 1 }),
metal: new THREE.MeshStandardMaterial({ color: 0x8e9b99, roughness: 0.56, metalness: 0.35 }),
cloth: new THREE.MeshStandardMaterial({ color: 0xe8dfc7, roughness: 1 }),
red: new THREE.MeshStandardMaterial({ color: 0xaa4f42, roughness: 0.9 }),
blue: new THREE.MeshStandardMaterial({ color: 0x476b78, roughness: 0.9 }),
amber: new THREE.MeshStandardMaterial({ color: 0xd99a35, roughness: 0.9 }),
dark: new THREE.MeshStandardMaterial({ color: 0x263538, roughness: 1 }),
skin: new THREE.MeshStandardMaterial({ color: 0xc9956b, roughness: 0.95 }),
rock: new THREE.MeshStandardMaterial({ color: 0x68716d, roughness: 1 }),
path: new THREE.MeshStandardMaterial({ color: 0xd9a244, roughness: 1 })
};
function box(parent, w, h, d, material, x = 0, y = 0, z = 0, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Deterministic helpers
// -------------------------------------------------------------------------
let seed = 872341;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function riverZ(x) {
return 7 - 0.18 * x + 1.2 * Math.sin(x * 0.12);
}
const pathPoints = [
new THREE.Vector3(13.0, 0.9, riverZ(13)),
new THREE.Vector3(17.5, 0.9, 2.0),
new THREE.Vector3(23.0, 0.9, -2.0),
new THREE.Vector3(30.0, 0.9, -3.2)
];
function distanceToSegment2D(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const t = THREE.MathUtils.clamp(
((px - ax) * dx + (pz - az) * dz) / (dx * dx + dz * dz),
0,
1
);
const cx = ax + t * dx;
const cz = az + t * dz;
return Math.hypot(px - cx, pz - cz);
}
function distanceToPath(x, z) {
let best = Infinity;
for (let i = 0; i < pathPoints.length - 1; i++) {
best = Math.min(
best,
distanceToSegment2D(
x,
z,
pathPoints[i].x,
pathPoints[i].z,
pathPoints[i + 1].x,
pathPoints[i + 1].z
)
);
}
return best;
}
// -------------------------------------------------------------------------
// Voxel terrain, shoreline, and river
// -------------------------------------------------------------------------
const landData = [];
const waterData = [];
const cell = 1.4;
for (let x = -34; x <= 34; x += cell) {
for (let z = -20; z <= 20; z += cell) {
const isRiver = x < 14.5 && Math.abs(z - riverZ(x)) < 2.15;
if (isRiver) {
waterData.push({ x, z });
continue;
}
const onRoute = distanceToPath(x, z) < 1.35;
const nearLanding = Math.hypot(x - 13.5, z - 6.8) < 5.2;
const nearOutpost = Math.hypot(x - 30, z - -3.2) < 6.4;
let top = 0.67 + random() * 0.27;
if (onRoute || nearLanding || nearOutpost) top = 0.82;
let color;
if (x < 15 && Math.abs(z - riverZ(x)) < 3.4) {
color = new THREE.Color(0x9d9069);
} else if (z < -10) {
color = new THREE.Color(0x718164);
} else {
const greens = [0x789464, 0x829b69, 0x6f8e5c, 0x91a675];
color = new THREE.Color(greens[Math.floor(random() * greens.length)]);
}
landData.push({ x, z, top, color });
}
}
const landGeometry = new THREE.BoxGeometry(1, 1, 1);
const landMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const landMesh = new THREE.InstancedMesh(
landGeometry,
landMaterial,
landData.length
);
landMesh.receiveShadow = true;
landMesh.castShadow = false;
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const position = new THREE.Vector3();
landData.forEach((tile, i) => {
const height = tile.top + 1.2;
position.set(tile.x, -1.2 + height / 2, tile.z);
scale.set(cell * 0.97, height, cell * 0.97);
matrix.compose(position, quaternion, scale);
landMesh.setMatrixAt(i, matrix);
landMesh.setColorAt(i, tile.color);
});
landMesh.instanceMatrix.needsUpdate = true;
landMesh.instanceColor.needsUpdate = true;
scene.add(landMesh);
const waterGeometry = new THREE.BoxGeometry(1, 1, 1);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x4b9eb7,
roughness: 0.28,
metalness: 0.08,
flatShading: true
});
const waterMesh = new THREE.InstancedMesh(
waterGeometry,
waterMaterial,
waterData.length
);
waterMesh.receiveShadow = true;
waterData.forEach((tile, i) => {
position.set(tile.x, -0.14, tile.z);
scale.set(cell * 0.985, 0.76, cell * 0.985);
matrix.compose(position, quaternion, scale);
waterMesh.setMatrixAt(i, matrix);
});
waterMesh.instanceMatrix.needsUpdate = true;
scene.add(waterMesh);
// A darker earth block gives the terrain a solid voxel silhouette.
box(scene, 100, 2.4, 58, materials.woodDark, 0, -2.35, 0, false);
// -------------------------------------------------------------------------
// Portage path
// -------------------------------------------------------------------------
const pathGroup = new THREE.Group();
scene.add(pathGroup);
for (let i = 0; i < pathPoints.length - 1; i++) {
const a = pathPoints[i];
const b = pathPoints[i + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const count = Math.ceil(length / 0.72);
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const marker = box(
pathGroup,
0.72,
0.1,
0.72,
materials.path,
THREE.MathUtils.lerp(a.x, b.x, t),
0.89,
THREE.MathUtils.lerp(a.z, b.z, t),
false
);
marker.rotation.y = -Math.atan2(dz, dx);
}
}
// Small trail-side stakes.
for (let i = 0; i < pathPoints.length - 1; i++) {
const a = pathPoints[i];
const b = pathPoints[i + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const nx = -dz / length;
const nz = dx / length;
for (let d = 1.5; d < length; d += 3.6) {
const t = d / length;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.z, b.z, t);
for (const side of [-1, 1]) {
box(pathGroup, 0.12, 0.95, 0.12, materials.woodDark, x + nx * side, 1.18, z + nz * side);
box(pathGroup, 0.18, 0.18, 0.18, materials.amber, x + nx * side, 1.68, z + nz * side);
}
}
}
// -------------------------------------------------------------------------
// Trees, rocks, and distant voxel mountains
// -------------------------------------------------------------------------
const leafMaterials = [
new THREE.MeshStandardMaterial({ color: 0x4d7356, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x5e805c, roughness: 1 }),
new THREE.MeshStandardMaterial({ color: 0x6f8b5d, roughness: 1 })
];
let treeCount = 0;
for (let attempt = 0; attempt < 900 && treeCount < 58; attempt++) {
const x = -31 + random() * 62;
const z = -17 + random() * 34;
if (x < 15 && Math.abs(z - riverZ(x)) < 3.2) continue;
if (distanceToPath(x, z) < 2.3) continue;
if (Math.hypot(x - 13.5, z - 6.8) < 5.5) continue;
if (Math.hypot(x - 30, z + 3.2) < 6.5) continue;
const tree = new THREE.Group();
tree.position.set(x, 0.72, z);
const scale = 0.75 + random() * 0.55;
box(tree, 0.35, 1.7, 0.35, materials.woodDark, 0, 0.85, 0);
box(tree, 1.65 * scale, 1.1 * scale, 1.55 * scale, leafMaterials[treeCount % 3], 0, 1.9, 0);
box(tree, 1.25 * scale, 0.9 * scale, 1.25 * scale, leafMaterials[(treeCount + 1) % 3], 0.15, 2.65, 0.1);
box(tree, 0.75 * scale, 0.65 * scale, 0.8 * scale, leafMaterials[(treeCount + 2) % 3], -0.12, 3.2, -0.08);
scene.add(tree);
treeCount++;
}
function addMountain(x, z, scale = 1) {
const mountain = new THREE.Group();
mountain.position.set(x, 0.6, z);
box(mountain, 7 * scale, 2.1 * scale, 4.5 * scale, materials.rock, 0, 1.0, 0);
box(mountain, 5.3 * scale, 1.7 * scale, 3.8 * scale, materials.rock, 0.2, 2.7, 0);
box(mountain, 3.6 * scale, 1.3 * scale, 2.8 * scale, materials.rock, -0.2, 4.0, 0.1);
box(mountain, 1.7 * scale, 0.9 * scale, 1.6 * scale, materials.rock, -0.3, 5.0, 0.05);
scene.add(mountain);
}
addMountain(-24, -17, 1.25);
addMountain(-12, -19, 0.9);
addMountain(3, -19, 1.05);
addMountain(19, -18, 0.85);
addMountain(31, -15, 1.05);
for (let i = 0; i < 35; i++) {
const x = -30 + random() * 59;
const z = -14 + random() * 30;
if (x < 15 && Math.abs(z - riverZ(x)) < 3) continue;
if (distanceToPath(x, z) < 1.8) continue;
const size = 0.25 + random() * 0.65;
box(scene, size, size * 0.7, size, materials.rock, x, 0.9 + size * 0.35, z);
}
// -------------------------------------------------------------------------
// Crates and blocky people
// -------------------------------------------------------------------------
function makeCrate(parent, size = 0.5) {
const group = new THREE.Group();
box(group, size, size, size, materials.cargo, 0, 0, 0);
box(group, size * 1.03, size * 0.16, size * 1.04, materials.cargoBand, 0, size * 0.25, 0);
box(group, size * 0.16, size * 1.02, size * 1.04, materials.cargoBand, -size * 0.28, 0, 0);
box(group, size * 0.16, size * 1.02, size * 1.04, materials.cargoBand, size * 0.28, 0, 0);
parent.add(group);
return group;
}
function makePerson(coatMaterial, carryCrate = false) {
const group = new THREE.Group();
const legs = [];
const leftLeg = box(group, 0.19, 0.58, 0.22, materials.dark, -0.14, 0.31, 0);
const rightLeg = box(group, 0.19, 0.58, 0.22, materials.dark, 0.14, 0.31, 0);
legs.push(leftLeg, rightLeg);
box(group, 0.53, 0.67, 0.34, coatMaterial, 0, 0.96, 0);
box(group, 0.18, 0.58, 0.2, coatMaterial, -0.36, 1.0, 0);
box(group, 0.18, 0.58, 0.2, coatMaterial, 0.36, 1.0, 0);
box(group, 0.33, 0.33, 0.32, materials.skin, 0, 1.48, 0);
box(group, 0.43, 0.18, 0.42, materials.metal, 0, 1.7, 0);
box(group, 0.08, 0.1, 0.08, materials.dark, -0.08, 1.48, 0.18);
box(group, 0.08, 0.1, 0.08, materials.dark, 0.08, 1.48, 0.18);
let crate = null;
if (carryCrate) {
crate = makeCrate(group, 0.56);
crate.position.set(0, 1.18, 0.43);
}
return { group, legs, crate };
}
// -------------------------------------------------------------------------
// Longship
// -------------------------------------------------------------------------
const ship = new THREE.Group();
const shipX = 7.8;
const shipZ = riverZ(shipX);
const riverSlope = -0.18 + 0.144 * Math.cos(shipX * 0.12);
ship.position.set(shipX, 0.56, shipZ);
ship.rotation.y = -Math.atan(riverSlope);
scene.add(ship);
box(ship, 6.5, 0.48, 1.55, materials.woodDark, 0, 0, 0);
box(ship, 6.0, 0.25, 1.25, materials.woodLight, 0, 0.29, 0);
box(ship, 6.7, 0.28, 0.18, materials.wood, 0, 0.34, 0.74);
box(ship, 6.7, 0.28, 0.18, materials.wood, 0, 0.34, -0.74);
for (const side of [-1, 1]) {
for (let i = 0; i < 7; i++) {
const shield = box(
ship,
0.58,
0.42,
0.12,
i % 2 ? materials.red : materials.blue,
-2.5 + i * 0.84,
0.45,
side * 0.84
);
shield.castShadow = true;
}
}
// Stepped voxel prow and stern.
for (const side of [-1, 1]) {
box(ship, 0.85, 0.52, 1.05, materials.wood, side * 3.35, 0.18, 0);
box(ship, 0.58, 0.65, 0.65, materials.woodLight, side * 3.78, 0.38, 0);
box(ship, 0.42, 0.48, 0.42, materials.wood, side * 4.08, 0.67, 0);
}
// Mast and square sail.
box(ship, 0.18, 4.4, 0.18, materials.woodDark, -0.5, 2.55, 0);
box(ship, 3.25, 2.15, 0.12, materials.cloth, -0.5, 3.0, 0.04);
box(ship, 3.25, 0.23, 0.14, materials.red, -0.5, 2.72, 0.03);
box(ship, 3.25, 0.23, 0.14, materials.blue, -0.5, 3.3, 0.03);
box(ship, 4.0, 0.13, 0.13, materials.woodDark, -0.5, 2.18, 0);
// Voxel oars.
for (const side of [-1, 1]) {
for (const x of [-1.8, 1.4]) {
const oar = box(ship, 0.12, 0.12, 2.7, materials.wood, x, 0.55, side * 1.25);
oar.rotation.x = side * 0.12;
box(ship, 0.35, 0.08, 0.65, materials.woodLight, x, 0.4, side * 2.5);
}
}
const shipCargo = [];
for (let i = 0; i < 18; i++) {
const crate = makeCrate(ship, 0.35);
crate.position.set(
-2.2 + (i % 6) * 0.84,
0.58,
-0.34 + Math.floor(i / 6) * 0.34
);
shipCargo.push(crate);
}
// Three crew members.
for (let i = 0; i < 3; i++) {
const crew = makePerson(i % 2 ? materials.blue : materials.red);
crew.group.scale.setScalar(0.62);
crew.group.position.set(-1.6 + i * 1.45, 0.42, i === 1 ? 0.52 : -0.55);
ship.add(crew.group);
}
// -------------------------------------------------------------------------
// Landing, cache, and porters
// -------------------------------------------------------------------------
const landing = new THREE.Group();
landing.position.set(12.5, 0.78, 5.9);
scene.add(landing);
for (let i = 0; i < 6; i++) {
box(landing, 0.32, 0.18, 4.3, materials.woodLight, -1.15 + i * 0.46, 0.08, 0.4);
}
box(landing, 0.28, 1.55, 0.28, materials.woodDark, 1.45, 0.7, -1.55);
box(landing, 1.1, 0.7, 0.18, materials.amber, 1.45, 1.5, -1.55);
box(landing, 0.32, 0.15, 0.32, materials.red, 1.45, 1.96, -1.55);
const cacheCrates = [];
for (let i = 0; i < 18; i++) {
const level = Math.floor(i / 9);
const index = i % 9;
const crate = makeCrate(scene, 0.62);
crate.position.set(
14.25 + (index % 3) * 0.78,
1.18 + level * 0.64,
7.7 + Math.floor(index / 3) * 0.74
);
cacheCrates.push(crate);
}
const porters = [];
const porterCoats = [materials.red, materials.blue, materials.amber];
for (let i = 0; i < 6; i++) {
const porter = makePerson(porterCoats[i % porterCoats.length], true);
scene.add(porter.group);
porters.push(porter);
}
// -------------------------------------------------------------------------
// Eastern outpost
// -------------------------------------------------------------------------
const outpost = new THREE.Group();
outpost.position.set(30.5, 0.85, -3.4);
scene.add(outpost);
box(outpost, 7.2, 0.28, 5.2, materials.woodLight, 0, 0.05, 0);
for (let i = 0; i < 9; i++) {
box(outpost, 0.72, 0.1, 4.9, materials.wood, -3.1 + i * 0.78, 0.23, 0);
}
// Longhouse.
box(outpost, 5.0, 1.75, 2.6, materials.wood, -0.6, 1.22, -0.45);
box(outpost, 5.65, 0.3, 3.05, materials.woodDark, -0.6, 2.22, -0.45);
box(outpost, 4.75, 0.28, 2.55, materials.woodDark, -0.6, 2.48, -0.45);
box(outpost, 3.8, 0.27, 2.0, materials.woodDark, -0.6, 2.73, -0.45);
box(outpost, 2.8, 0.25, 1.45, materials.woodDark, -0.6, 2.96, -0.45);
box(outpost, 0.9, 1.25, 0.12, materials.dark, -0.55, 0.95, 0.88);
// Palisade.
for (let i = 0; i < 8; i++) {
box(outpost, 0.25, 2.0, 0.25, materials.woodDark, -3.25 + i * 0.92, 1.16, 2.1);
box(outpost, 0.3, 0.16, 0.3, materials.wood, -3.25 + i * 0.92, 2.18, 2.1);
}
for (let i = 0; i < 6; i++) {
box(outpost, 0.25, 1.8, 0.25, materials.woodDark, 3.15, 1.05, -1.8 + i * 0.72);
}
// Flag.
box(outpost, 0.16, 3.4, 0.16, materials.woodDark, 2.8, 1.85, -1.5);
box(outpost, 1.15, 0.65, 0.1, materials.amber, 3.35, 3.05, -1.5);
// Decorative outpost supplies, separate from the modeled inventory.
for (let i = 0; i < 5; i++) {
const crate = makeCrate(outpost, 0.56);
crate.position.set(1.45 + (i % 2) * 0.62, 0.64 + Math.floor(i / 3) * 0.58, 1.05);
}
// -------------------------------------------------------------------------
// Water highlights
// -------------------------------------------------------------------------
const foamMaterial = new THREE.MeshStandardMaterial({
color: 0xd5f1ed,
roughness: 0.7,
transparent: true,
opacity: 0.85
});
const foam = [];
for (let i = 0; i < 24; i++) {
const x = -31 + i * 1.7;
const mesh = box(
scene,
0.35 + random() * 0.45,
0.06,
0.12 + random() * 0.18,
foamMaterial,
x,
0.27,
riverZ(x) + (random() - 0.5) * 2.4,
false
);
foam.push({ mesh, x, phase: random() * Math.PI * 2 });
}
// Bright voxel rapids upstream.
for (let i = 0; i < 15; i++) {
const x = -3.5 + random() * 4.8;
box(
scene,
0.32 + random() * 0.5,
0.07,
0.18 + random() * 0.25,
foamMaterial,
x,
0.3,
riverZ(x) + (random() - 0.5) * 3.0,
false
);
}
// -------------------------------------------------------------------------
// Cargo model and UI
// -------------------------------------------------------------------------
const TOTAL_CRATES = 18;
const CRATE_KG = 100;
const PORTERS = 6;
const CARRY_CAPACITY_KG = 40;
const TRIP_CAPACITY_KG = PORTERS * CARRY_CAPACITY_KG;
const DISTANCE_M = 180;
const GRADE = 0.03;
const MU = 0.16;
const GRAVITY = 9.81;
const SUSTAINED_FORCE_N = 600;
const CARRY_SPEED_MPS = 0.55;
const cargoRange = document.querySelector("#cargoRange");
const removedValue = document.querySelector("#removedValue");
const remainingValue = document.querySelector("#remainingValue");
const tripsValue = document.querySelector("#tripsValue");
const pullValue = document.querySelector("#pullValue");
const porterValue = document.querySelector("#porterValue");
const estimateValue = document.querySelector("#estimateValue");
const forceStatus = document.querySelector("#forceStatus");
const forceFill = document.querySelector("#forceFill");
const forceCurrent = document.querySelector("#forceCurrent");
const loadSummary = document.querySelector("#loadSummary");
const steps = document.querySelector("#steps");
const number = new Intl.NumberFormat("en-US");
function updateCargoModel() {
const removedCrates = Number(cargoRange.value);
const remainingCrates = TOTAL_CRATES - removedCrates;
const remainingKg = remainingCrates * CRATE_KG;
const trips = remainingKg > 0 ? Math.ceil(remainingKg / TRIP_CAPACITY_KG) : 0;
const angle = Math.atan(GRADE);
const totalPullN = remainingKg * GRAVITY * (MU + Math.sin(angle));
const perPorterN = totalPullN / PORTERS;
const liftPerPorterN = (CRATE_KG * GRAVITY) / 2;
const cratesPerTrip = Math.min(TRIP_CAPACITY_KG / CRATE_KG, remainingCrates);
const secondsPerTrip =
(2 * DISTANCE_M) / CARRY_SPEED_MPS + cratesPerTrip * 45 + 90;
const hours = trips * secondsPerTrip / 3600;
removedValue.textContent = `${removedCrates} crate${removedCrates === 1 ? "" : "s"} · ${number.format(removedCrates * CRATE_KG)} kg`;
remainingValue.textContent = `${remainingCrates} crates · ${number.format(remainingKg)} kg`;
tripsValue.textContent = String(trips);
pullValue.textContent = `${(totalPullN / 1000).toFixed(2)} kN`;
porterValue.textContent = `${(perPorterN / 1000).toFixed(2)} kN`;
estimateValue.textContent = hours > 0 ? `${hours.toFixed(1)} h` : "—";
loadSummary.textContent = `${number.format(remainingKg)} kg remaining`;
const forceRatio = perPorterN / SUSTAINED_FORCE_N;
forceFill.style.width = `${Math.min(100, forceRatio * 100)}%`;
forceCurrent.textContent = `${(perPorterN / 1000).toFixed(2)} kN per porter`;
if (remainingCrates === 0) {
forceStatus.textContent = "Transfer cleared";
forceStatus.classList.remove("over");
} else if (perPorterN <= SUSTAINED_FORCE_N) {
forceStatus.textContent = "Within limit";
forceStatus.classList.remove("over");
} else {
forceStatus.textContent = "Over limit";
forceStatus.classList.add("over");
}
cargoRange.style.setProperty(
"--range-fill",
`${(removedCrates / TOTAL_CRATES) * 100}%`
);
steps.innerHTML = `
<li>
<strong>Unload and set aside ${removedCrates} crate${removedCrates === 1 ? "" : "s"}</strong>
Place ${number.format(removedCrates * CRATE_KG)} kg in the landing cache.
Each 100 kg crate assumes a ${Math.round(liftPerPorterN)} N lift share for two porters.
</li>
<li>
<strong>Form ${trips} overland trip${trips === 1 ? "" : "s"}</strong>
${PORTERS} porters move up to ${TRIP_CAPACITY_KG} kg per trip.
${remainingCrates > 0 ? `${trips * Math.min(6, remainingCrates)} crate-handling events are assumed.` : "No load remains to move."}
</li>
<li>
<strong>Haul ${DISTANCE_M} m at ${(GRADE * 100).toFixed(0)}% grade</strong>
Equivalent combined pull is ${(totalPullN / 1000).toFixed(2)} kN, or
${(perPorterN / 1000).toFixed(2)} kN per porter.
</li>
<li>
<strong>Break down the load at the outpost</strong>
${remainingKg > 0 ? `${number.format(remainingKg)} kg is delivered for onward handling.` : "All modeled cargo remains in the riverside cache."}
</li>
`;
// Keep the visual inventory consistent with the selected scenario.
const activeBatch = Math.min(PORTERS, remainingCrates);
const shipVisible = Math.max(0, remainingCrates - activeBatch);
shipCargo.forEach((crate, i) => {
crate.visible = i < shipVisible;
});
cacheCrates.forEach((crate, i) => {
crate.visible = i < removedCrates;
});
porters.forEach((porter, i) => {
porter.group.visible = i < activeBatch;
});
}
cargoRange.addEventListener("input", updateCargoModel);
updateCargoModel();
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
let yaw = -0.64;
let pitch = 0.72;
let zoom = 1;
let dragging = false;
let lastX = 0;
let lastY = 0;
function updateCamera() {
const distance = 70;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * Math.cos(pitch) * distance,
cameraTarget.y + Math.sin(pitch) * distance,
cameraTarget.z + Math.cos(yaw) * Math.cos(pitch) * distance
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
yaw = -0.64;
pitch = 0.72;
zoom = 1;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.004, 0.28, 1.25);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.4
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") yaw += 0.08;
else if (event.key === "ArrowRight") yaw -= 0.08;
else if (event.key === "ArrowUp") pitch = THREE.MathUtils.clamp(pitch + 0.06, 0.28, 1.25);
else if (event.key === "ArrowDown") pitch = THREE.MathUtils.clamp(pitch - 0.06, 0.28, 1.25);
else if (event.key.toLowerCase() === "r") resetCamera();
else return;
event.preventDefault();
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 1 ? 68 : 46;
renderer.setSize(width, height, false);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// Mobile panel control.
const panel = document.querySelector("#panel");
const panelToggle = document.querySelector("#panelToggle");
panelToggle.addEventListener("click", () => {
panel.classList.toggle("open");
panelToggle.textContent = panel.classList.contains("open")
? "Close panel"
: "Adjust transfer";
});
// -------------------------------------------------------------------------
// World labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#labelRiver"),
position: new THREE.Vector3(-7, 4.1, riverZ(-7))
},
{
element: document.querySelector("#labelLanding"),
position: new THREE.Vector3(14.3, 3.0, 7.7)
},
{
element: document.querySelector("#labelPortage"),
position: new THREE.Vector3(20.5, 2.8, 0.0)
},
{
element: document.querySelector("#labelOutpost"),
position: new THREE.Vector3(30.5, 5.0, -3.4)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach((label) => {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const pathSegments = [];
let totalPathLength = 0;
for (let i = 0; i < pathPoints.length - 1; i++) {
const a = pathPoints[i];
const b = pathPoints[i + 1];
const length = Math.hypot(b.x - a.x, b.z - a.z);
pathSegments.push({ a, b, length, start: totalPathLength });
totalPathLength += length;
}
function samplePath(distance) {
const d = THREE.MathUtils.clamp(distance, 0, totalPathLength);
let segment = pathSegments[pathSegments.length - 1];
for (const candidate of pathSegments) {
if (d <= candidate.start + candidate.length) {
segment = candidate;
break;
}
}
const t = (d - segment.start) / segment.length;
return {
x: THREE.MathUtils.lerp(segment.a.x, segment.b.x, t),
z: THREE.MathUtils.lerp(segment.a.z, segment.b.z, t),
angle: Math.atan2(
segment.b.x - segment.a.x,
segment.b.z - segment.a.z
)
};
}
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Gentle boat motion.
ship.position.y = 0.56 + Math.sin(elapsed * 1.35) * 0.035;
ship.rotation.z = Math.sin(elapsed * 0.9) * 0.006;
// Moving porters and their first visible batch.
porters.forEach((porter, i) => {
if (!porter.group.visible) return;
const phase = (elapsed * 0.016 + i * 0.095) % 1;
const point = samplePath(phase * totalPathLength);
const bob = Math.abs(Math.sin(elapsed * 5.2 + i)) * 0.045;
porter.group.position.set(point.x, 0.9 + bob, point.z);
porter.group.rotation.y = point.angle;
porter.legs[0].rotation.x = Math.sin(elapsed * 5.2 + i) * 0.45;
porter.legs[1].rotation.x = -Math.sin(elapsed * 5.2 + i) * 0.45;
if (porter.crate) {
porter.crate.rotation.z = Math.sin(elapsed * 3 + i) * 0.015;
}
});
// Water highlights drift and pulse.
foam.forEach((item, i) => {
item.mesh.position.x = item.x + Math.sin(elapsed * 0.22 + item.phase) * 0.35;
item.mesh.position.y = 0.28 + Math.sin(elapsed * 2 + i) * 0.015;
item.mesh.scale.y = 0.7 + Math.sin(elapsed * 2.4 + item.phase) * 0.2;
});
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```