Prompt specification
Build or customize the Three.js 3D scene "Boat keel resting on timber 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: Boat keel resting on timber rollers
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/boat-keel-resting-on-timber-rollers-x2637
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Viking river routes and overland portages. Model a small referenced boat hull supported on timber rollers beside a riverbank. Show ground contact and the distinct geometry of water transport versus overland movement. Voxel style.
Working Three.js Starter (boat-keel-resting-on-timber-rollers-x2637):
```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 Routes & Portages</title>
<style>
:root {
color-scheme: dark;
--ink: #f4ead3;
--muted: #c8d2c6;
--river: #69c5c8;
--portage: #d8a75d;
--panel: rgba(20, 37, 38, 0.78);
--line: rgba(244, 234, 211, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 75% 12%, #d8e7dc 0, transparent 28%),
linear-gradient(155deg, #8fb8bd 0%, #b8d1c9 43%, #728f83 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(to bottom, rgba(10, 30, 32, 0.12), transparent 23%),
radial-gradient(ellipse at center, transparent 48%, rgba(9, 26, 28, 0.28) 115%);
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--ink);
}
.title-block {
position: absolute;
top: clamp(22px, 4vw, 54px);
left: clamp(22px, 4vw, 58px);
max-width: min(480px, 70vw);
text-shadow: 0 2px 18px rgba(8, 30, 31, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #f4dca7;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 30px;
height: 2px;
background: #e7b76d;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4.6vw, 64px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 390px;
margin: 14px 0 0;
color: var(--muted);
font-size: clamp(12px, 1.2vw, 15px);
line-height: 1.55;
}
.legend {
position: absolute;
bottom: clamp(22px, 4vw, 50px);
left: clamp(22px, 4vw, 58px);
display: grid;
gap: 10px;
padding: 14px 17px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 12px 34px rgba(7, 24, 26, 0.18);
backdrop-filter: blur(10px);
}
.legend-row {
display: flex;
align-items: center;
gap: 11px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.swatch {
width: 24px;
height: 10px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}
.swatch.water {
background: var(--river);
}
.swatch.land {
background: var(--portage);
}
.info {
position: absolute;
right: clamp(22px, 4vw, 58px);
bottom: clamp(22px, 4vw, 50px);
width: min(250px, calc(100vw - 44px));
padding: 15px 17px;
border-left: 2px solid #d8a75d;
background: rgba(20, 37, 38, 0.72);
backdrop-filter: blur(10px);
}
.info strong {
display: block;
margin-bottom: 6px;
color: #f4dca7;
font-size: 11px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.info p {
margin: 0;
color: #d9dfd3;
font-size: 12px;
line-height: 1.55;
}
.controls {
position: absolute;
top: clamp(24px, 4vw, 54px);
right: clamp(22px, 4vw, 58px);
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(20, 37, 38, 0.58);
color: #e2e7dd;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 10;
background: #8fb8bd;
color: #173638;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
transition: opacity 0.45s ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.subtitle {
max-width: 280px;
}
.info {
display: none;
}
.controls {
top: auto;
right: 18px;
bottom: 22px;
}
.legend {
bottom: 22px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel diorama of Viking river travel and an overland portage"
></canvas>
<div class="vignette"></div>
<div class="hud">
<section class="title-block">
<div class="eyebrow">Northern Waterways</div>
<h1>River &<br>Portage</h1>
<p class="subtitle">
A voxel reconstruction of a clinker-built river boat hauled across a
timber-roller crossing between navigable waters.
</p>
</section>
<div class="controls">Drag to orbit · Scroll to zoom · R to reset</div>
<section class="legend" aria-label="Route legend">
<div class="legend-row">
<span class="swatch water"></span>
Water transport route
</div>
<div class="legend-row">
<span class="swatch land"></span>
Overland portage
</div>
</section>
<aside class="info">
<strong>Portage crossing</strong>
<p>
Stepped keel<br>
Oak rollers<br>
Cargo sled and guide stakes
</p>
</aside>
</div>
<div id="loading">Building the northern crossing…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera and lighting
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xa9c4bc, 29, 58);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xe5f6ff, 0x5a4935, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc7, 3.1);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8dbe4, 0.65);
fill.position.set(12, 7, -10);
scene.add(fill);
// ------------------------------------------------------------
// Shared geometry and helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
function hash(ix, iz) {
const value = Math.sin(ix * 127.1 + iz * 311.7) * 43758.5453;
return value - Math.floor(value);
}
function addBox(parent, material, x, y, z, sx, sy, sz, cast = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeStandard(colorValue, roughness = 0.8, metalness = 0) {
return new THREE.MeshStandardMaterial({
color: colorValue,
roughness,
metalness
});
}
function makeInstancedBoxes(items, parent, options = {}) {
const mesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0
}),
items.length
);
items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(
item.rx ?? 0,
item.ry ?? 0,
item.rz ?? 0
);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, color.set(item.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function distanceToSegment2D(px, pz, ax, az, bx, bz) {
const vx = bx - ax;
const vz = bz - az;
const wx = px - ax;
const wz = pz - az;
const lengthSq = vx * vx + vz * vz;
const t = lengthSq
? THREE.MathUtils.clamp((wx * vx + wz * vz) / lengthSq, 0, 1)
: 0;
const dx = px - (ax + t * vx);
const dz = pz - (az + t * vz);
return Math.sqrt(dx * dx + dz * dz);
}
function distanceToPolyline(x, z, points) {
let result = Infinity;
for (let i = 0; i < points.length - 1; i++) {
result = Math.min(
result,
distanceToSegment2D(
x, z,
points[i][0], points[i][1],
points[i + 1][0], points[i + 1][1]
)
);
}
return result;
}
function cylinderBetween(a, b, radius, material, parent, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
segments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Voxel terrain, river and inland pond
// ------------------------------------------------------------
const CELL = 0.75;
const NX = 32;
const NZ = 24;
const BASE_Y = -1.18;
const portagePath = [
[-3.15, 1.65],
[-1.35, 1.15],
[0.55, 0.02],
[2.45, -1.35],
[5.20, -3.70],
[6.05, -4.35]
];
function riverX(z) {
return -5.2 + 0.70 * Math.sin(z * 0.45) + 0.18 * z;
}
function riverDerivative(z) {
return 0.315 * Math.cos(z * 0.45) + 0.18;
}
const pond = {
x: 8.0,
z: -4.5,
rx: 2.75,
rz: 1.95
};
function pondValue(x, z) {
const dx = (x - pond.x) / pond.rx;
const dz = (z - pond.z) / pond.rz;
return Math.sqrt(dx * dx + dz * dz);
}
const baseMaterial = makeStandard(0x4e3b2c, 0.95);
addBox(scene, baseMaterial, 0, -1.43, 0, 24.3, 0.52, 18.3, false);
const bedItems = [];
const surfaceItems = [];
const waterItems = [];
for (let ix = 0; ix < NX; ix++) {
for (let iz = 0; iz < NZ; iz++) {
const x = (ix - NX / 2 + 0.5) * CELL;
const z = (iz - NZ / 2 + 0.5) * CELL;
const riverDistance = Math.abs(x - riverX(z));
const pondDistance = pondValue(x, z);
const pathDistance = distanceToPolyline(x, z, portagePath);
const variation = hash(ix, iz);
const isWater = riverDistance < 1.68 || pondDistance < 1;
let landTop = 0.16 + variation * 0.12;
if (riverDistance < 2.28) landTop = 0.055 + variation * 0.035;
if (pondDistance < 1.23 && pondDistance >= 1) {
landTop = 0.08 + variation * 0.05;
}
if (pathDistance < 0.58) landTop = 0.235;
if (isWater) {
const bedTop = -0.43;
const height = bedTop - BASE_Y;
bedItems.push({
x,
y: BASE_Y + height / 2,
z,
sx: CELL * 0.99,
sy: height,
sz: CELL * 0.99,
color: new THREE.Color(0x554a36).multiplyScalar(0.88 + variation * 0.17)
});
waterItems.push({
x,
y: -0.27,
z,
sx: CELL * 0.965,
sy: 0.105,
sz: CELL * 0.965,
color: new THREE.Color(0x3c9fa7).multiplyScalar(0.92 + variation * 0.13)
});
} else {
const soilTop = landTop - 0.135;
const height = soilTop - BASE_Y;
bedItems.push({
x,
y: BASE_Y + height / 2,
z,
sx: CELL * 0.99,
sy: height,
sz: CELL * 0.99,
color: new THREE.Color(0x705239).multiplyScalar(0.86 + variation * 0.18)
});
let surfaceColor = new THREE.Color(0x66824d);
if (riverDistance < 2.28 || (pondDistance < 1.23 && pondDistance >= 1)) {
surfaceColor = new THREE.Color(0x947044);
}
if (pathDistance < 0.58) {
surfaceColor = new THREE.Color(0xa77c49);
}
surfaceColor.multiplyScalar(0.90 + variation * 0.18);
surfaceItems.push({
x,
y: landTop - 0.0675,
z,
sx: CELL * 0.975,
sy: 0.135,
sz: CELL * 0.975,
color: surfaceColor
});
}
}
}
makeInstancedBoxes(bedItems, scene, { roughness: 0.96 });
makeInstancedBoxes(surfaceItems, scene, { roughness: 0.95 });
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.27,
metalness: 0.08
});
const waterMesh = new THREE.InstancedMesh(
unitBox,
waterMaterial,
waterItems.length
);
waterItems.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
waterMesh.setMatrixAt(index, dummy.matrix);
waterMesh.setColorAt(index, color.set(item.color));
});
waterMesh.instanceMatrix.needsUpdate = true;
if (waterMesh.instanceColor) waterMesh.instanceColor.needsUpdate = true;
waterMesh.receiveShadow = true;
scene.add(waterMesh);
// ------------------------------------------------------------
// Water-route chevrons and floating glints
// ------------------------------------------------------------
const routeArrows = [];
const arrowMaterial = makeStandard(0xbbe7dd, 0.42);
const glintMaterial = new THREE.MeshStandardMaterial({
color: 0xa8e5df,
transparent: true,
opacity: 0.48,
roughness: 0.22
});
function addWaterChevron(z, phase) {
const group = new THREE.Group();
group.position.set(riverX(z), -0.205, z);
group.rotation.y = -Math.atan(riverDerivative(z));
addBox(group, arrowMaterial, -0.14, 0, -0.04, 0.07, 0.025, 0.63, false)
.rotation.y = -0.56;
addBox(group, arrowMaterial, 0.14, 0, -0.04, 0.07, 0.025, 0.63, false)
.rotation.y = 0.56;
group.userData.phase = phase;
group.userData.baseY = group.position.y;
routeArrows.push(group);
scene.add(group);
}
[-7.8, -4.8, -1.7, 3.0, 6.4].forEach((z, i) => {
addWaterChevron(z, i * 0.9);
});
const glints = [];
for (let i = 0; i < 34; i++) {
const z = -8.6 + hash(i, 71) * 17.2;
const x = riverX(z) + (hash(i, 91) - 0.5) * 2.5;
const mesh = addBox(
scene,
glintMaterial,
x,
-0.205,
z,
0.18 + hash(i, 17) * 0.25,
0.015,
0.035,
false
);
mesh.rotation.y = hash(i, 33) * Math.PI;
glints.push({ mesh, phase: hash(i, 52) * Math.PI * 2 });
}
// ------------------------------------------------------------
// Portage sleepers, markers and landing stage
// ------------------------------------------------------------
const sleeperMaterial = makeStandard(0x9b7040, 0.92);
const markerPostMaterial = makeStandard(0x644129, 0.9);
const markerTopMaterial = makeStandard(0xe6a94d, 0.8);
const flags = [];
for (let segment = 0; segment < portagePath.length - 1; segment++) {
const a = portagePath[segment];
const b = portagePath[segment + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const count = Math.max(1, Math.floor(length / 0.44));
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const x = a[0] + dx * t;
const z = a[1] + dz * t;
const angle = Math.atan2(dz, dx);
addBox(
scene,
sleeperMaterial,
x,
0.273,
z,
0.37,
0.075,
0.25
).rotation.y = -angle;
}
const markerCount = Math.floor(length / 1.45);
for (let i = 0; i <= markerCount; i++) {
const t = markerCount ? i / markerCount : 0.35;
const x = a[0] + dx * t;
const z = a[1] + dz * t;
const perpendicularX = -dz / length;
const perpendicularZ = dx / length;
for (const side of [-1, 1]) {
const px = x + perpendicularX * side * 0.58;
const pz = z + perpendicularZ * side * 0.58;
addBox(
scene,
markerPostMaterial,
px,
0.56,
pz,
0.085,
0.64,
0.085
);
const flag = addBox(
scene,
markerTopMaterial,
px,
0.83,
pz,
0.19,
0.13,
0.07
);
flags.push({ mesh: flag, phase: hash(px * 10, pz * 10) * 6 });
}
}
}
const dockWood = makeStandard(0x765035, 0.9);
const dockDark = makeStandard(0x4f382a, 0.95);
const dockZ = 2.75;
const dockLandEdge = riverX(dockZ) + 1.82;
for (let i = 0; i < 8; i++) {
addBox(
scene,
dockWood,
dockLandEdge - 0.15 - i * 0.245,
0.02,
dockZ,
0.22,
0.12,
1.08
);
}
for (const x of [dockLandEdge - 0.12, dockLandEdge - 1.83]) {
for (const z of [dockZ - 0.44, dockZ + 0.44]) {
addBox(scene, dockDark, x, -0.27, z, 0.14, 1.18, 0.14);
}
}
// Small river navigation stakes.
for (const z of [-6.0, 5.4]) {
const x = riverX(z) - 1.05;
addBox(scene, dockDark, x, 0.05, z, 0.15, 0.52, 0.15);
addBox(scene, markerTopMaterial, x, 0.31, z, 0.21, 0.15, 0.21);
}
// ------------------------------------------------------------
// Main clinker-built Viking boat on timber rollers
// ------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(-0.65, 0.24, 0.35);
boat.rotation.y = -0.025;
scene.add(boat);
const hullItems = [];
const hullRows = [
{ y: 0.64, z: 0.29, half: 2.55, color: 0x704025 },
{ y: 0.85, z: 0.49, half: 2.35, color: 0x824b29 },
{ y: 1.06, z: 0.68, half: 2.15, color: 0x94582f },
{ y: 1.27, z: 0.82, half: 1.95, color: 0xa36335 }
];
for (let rowIndex = 0; rowIndex < hullRows.length; rowIndex++) {
const row = hullRows[rowIndex];
const segments = Math.floor((row.half * 2) / 0.45);
const segmentLength = (row.half * 2) / segments;
for (const side of [-1, 1]) {
for (let segment = 0; segment < segments; segment++) {
const x = -row.half + segmentLength * (segment + 0.5);
const normalized = (x + row.half) / (row.half * 2);
const taper =
0.46 +
0.54 * Math.pow(Math.sin(normalized * Math.PI), 0.55);
const plankColor = new THREE.Color(row.color).multiplyScalar(
0.88 + hash(segment + rowIndex * 9, side + 2) * 0.18
);
hullItems.push({
x,
y: row.y,
z: side * row.z * taper,
sx: segmentLength * 0.97,
sy: 0.18,
sz: 0.18,
color: plankColor
});
}
}
}
// Upper gunwales.
const topRow = hullRows[hullRows.length - 1];
const railSegments = Math.floor((topRow.half * 2) / 0.38);
const railLength = (topRow.half * 2) / railSegments;
for (const side of [-1, 1]) {
for (let segment = 0; segment < railSegments; segment++) {
const x = -topRow.half + railLength * (segment + 0.5);
const normalized = (x + topRow.half) / (topRow.half * 2);
const taper =
0.46 +
0.54 * Math.pow(Math.sin(normalized * Math.PI), 0.55);
hullItems.push({
x,
y: 1.39,
z: side * topRow.z * taper,
sx: railLength * 0.98,
sy: 0.105,
sz: 0.135,
color: new THREE.Color(0xb6753d).multiplyScalar(
0.90 + hash(segment + 18, side + 4) * 0.15
)
});
}
}
// Keel and interior floor boards.
hullItems.push({
x: 0,
y: 0.50,
z: 0,
sx: 4.85,
sy: 0.18,
sz: 0.20,
color: 0x4e301f
});
for (let i = 0; i < 9; i++) {
const x = -1.86 + i * 0.46;
const width = 1.13 * (1 - Math.pow(Math.abs(x) / 2.5, 1.5) * 0.34);
hullItems.push({
x,
y: 0.735,
z: 0,
sx: 0.43,
sy: 0.075,
sz: width,
color: new THREE.Color(0x9b6338).multiplyScalar(
0.86 + hash(i, 66) * 0.18
)
});
}
makeInstancedBoxes(hullItems, boat, { roughness: 0.84 });
const darkWood = makeStandard(0x4d3020, 0.88);
const lightWood = makeStandard(0xb9793f, 0.82);
const paleWood = makeStandard(0xd39a59, 0.84);
const gold = makeStandard(0xd5a13f, 0.55, 0.12);
const ropeMaterial = makeStandard(0xb89c68, 0.95);
const canvasMaterial = makeStandard(0xd7c49d, 0.96);
// Cross benches.
for (const x of [-1.45, -0.52, 0.42, 1.34]) {
const width = 1.30 * (1 - Math.pow(Math.abs(x) / 2.6, 1.4) * 0.27);
addBox(boat, paleWood, x, 1.13, 0, 0.31, 0.11, width);
}
// Blocky carved prow and stern posts.
addBox(boat, darkWood, 2.10, 1.43, 0, 0.31, 0.38, 0.29);
addBox(boat, darkWood, 2.32, 1.38, 0, 0.30, 0.17, 0.23);
addBox(boat, gold, 2.205, 1.48, 0.151, 0.075, 0.075, 0.025);
addBox(boat, gold, 2.205, 1.48, -0.151, 0.075, 0.075, 0.025);
addBox(boat, lightWood, -2.17, 1.35, 0, 0.24, 0.45, 0.24);
// Furled canvas and stowed mast.
const furledSail = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 1.78, 8),
canvasMaterial
);
furledSail.position.set(0.05, 1.42, 0);
furledSail.rotation.z = Math.PI / 2;
furledSail.castShadow = true;
boat.add(furledSail);
addBox(boat, lightWood, -0.1, 1.30, 0, 2.72, 0.055, 0.055);
// Stowed oars.
for (const side of [-1, 1]) {
addBox(boat, lightWood, 0, 1.43, side * 0.53, 3.22, 0.065, 0.065);
addBox(boat, paleWood, -1.38, 1.43, side * 0.53, 0.48, 0.045, 0.17);
}
// Square shields on the visible side of the hull.
const shieldColors = [0x9d493b, 0x3f6d78, 0xb48639];
[-1.18, 0, 1.18].forEach((x, index) => {
const shield = addBox(
boat,
makeStandard(shieldColors[index], 0.8),
x,
1.04,
0.79,
0.43,
0.39,
0.085
);
shield.rotation.y = -0.025;
addBox(
boat,
gold,
x,
1.04,
0.842,
0.11,
0.11,
0.035
);
});
// Five low-poly timber rollers, with axes crossing beneath the keel.
const rollerGeometry = new THREE.CylinderGeometry(0.22, 0.22, 1.66, 10, 1);
const rollerMaterials = [
makeStandard(0x7c5030, 0.94),
makeStandard(0x92613a, 0.94)
];
[-2.05, -1.02, 0, 1.02, 2.05].forEach((x, index) => {
const roller = new THREE.Mesh(
rollerGeometry,
rollerMaterials[index % rollerMaterials.length]
);
roller.position.set(x, 0.22, 0);
roller.rotation.x = Math.PI / 2;
roller.castShadow = true;
roller.receiveShadow = true;
boat.add(roller);
});
// ------------------------------------------------------------
// Voxel porters and cargo sled
// ------------------------------------------------------------
const skinMaterial = makeStandard(0xd4a47b, 0.95);
const darkClothMaterial = makeStandard(0x3d4340, 0.95);
const bootMaterial = makeStandard(0x332c28, 0.95);
function createPerson(x, z, coatColor, rotation = 0) {
const person = new THREE.Group();
person.position.set(x, 0.24, z);
person.rotation.y = rotation;
const coat = makeStandard(coatColor, 0.95);
addBox(person, bootMaterial, -0.12, 0.10, 0, 0.17, 0.20, 0.20);
addBox(person, bootMaterial, 0.12, 0.10, 0, 0.17, 0.20, 0.20);
addBox(person, darkClothMaterial, -0.12, 0.34, 0, 0.13, 0.34, 0.15);
addBox(person, darkClothMaterial, 0.12, 0.34, 0, 0.13, 0.34, 0.15);
addBox(person, coat, 0, 0.69, 0, 0.39, 0.47, 0.27);
addBox(person, skinMaterial, 0.025, 1.07, 0, 0.25, 0.26, 0.24);
addBox(person, darkWood, 0.015, 1.22, 0, 0.28, 0.11, 0.26);
addBox(person, coat, 0.23, 0.73, 0, 0.13, 0.36, 0.13).rotation.z = -0.48;
addBox(person, coat, -0.23, 0.73, 0, 0.13, 0.36, 0.13).rotation.z = 0.48;
scene.add(person);
return person;
}
const puller = createPerson(2.65, 0.17, 0xb75b3f, 0);
createPerson(-2.65, 0.52, 0x596d58, Math.PI);
const sled = new THREE.Group();
const sledAngle = Math.atan2(-1.35 - 0.02, 2.45 - 0.55);
sled.position.set(3.72, 0.24, -2.25);
sled.rotation.y = -sledAngle;
scene.add(sled);
addBox(sled, darkWood, 0, 0.13, -0.34, 1.52, 0.09, 0.09);
addBox(sled, darkWood, 0, 0.13, 0.34, 1.52, 0.09, 0.09);
for (const x of [-0.53, -0.18, 0.18, 0.53]) {
addBox(sled, paleWood, x, 0.22, 0, 0.22, 0.09, 0.78);
}
addBox(sled, makeStandard(0x8e5931, 0.9), -0.24, 0.47, 0, 0.50, 0.43, 0.46);
addBox(sled, gold, -0.24, 0.47, 0.238, 0.12, 0.12, 0.025);
const barrel = new THREE.Mesh(
new THREE.CylinderGeometry(0.24, 0.24, 0.50, 8),
makeStandard(0x74472b, 0.9)
);
barrel.position.set(0.37, 0.49, 0);
barrel.castShadow = true;
sled.add(barrel);
addBox(sled, darkWood, 0.41, 0.49, 0, 0.49, 0.065, 0.49);
createPerson(4.85, -2.95, 0x6f7f61, -sledAngle);
// Tow line from the boat's prow to the forward porter.
cylinderBetween(
new THREE.Vector3(1.58, 1.42, 0.35),
new THREE.Vector3(2.46, 0.98, 0.17),
0.018,
ropeMaterial,
scene,
6
);
// Small stacked supplies on the inland shore.
const shoreX = 5.85;
const shoreZ = -4.8;
addBox(scene, sleeperMaterial, shoreX, 0.42, shoreZ, 0.60, 0.44, 0.58);
addBox(scene, lightWood, shoreX + 0.10, 0.87, shoreZ, 0.50, 0.38, 0.48);
addBox(scene, gold, shoreX + 0.10, 0.87, shoreZ + 0.25, 0.10, 0.10, 0.025);
// ------------------------------------------------------------
// In-scene route labels
// ------------------------------------------------------------
function makeLabel(text, position, accent = "#6ec7ca") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(20, 37, 38, 0.88)";
context.fillRect(8, 16, 496, 96);
context.fillStyle = accent;
context.fillRect(8, 16, 10, 96);
context.strokeStyle = "rgba(255,255,255,0.22)";
context.strokeRect(8, 16, 496, 96);
context.fillStyle = "#f4ead3";
context.font = "700 31px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 262, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(3.3, 0.83, 1);
scene.add(sprite);
}
makeLabel(
"RIVER ROUTE",
new THREE.Vector3(riverX(-5.5), 1.0, -5.5),
"#69c5c8"
);
makeLabel(
"OVERLAND PORTAGE",
new THREE.Vector3(3.1, 1.55, -1.25),
"#d8a75d"
);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset and touch pinch
// ------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(-0.45, 0.05, -0.15),
radius: 27,
theta: 0.78,
phi: 0.82
};
const defaultOrbit = {
target: orbit.target.clone(),
radius: 27,
theta: 0.78,
phi: 0.82
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const pointers = new Map();
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
previousX = event.clientX;
previousY = event.clientY;
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (previousPinchDistance / distance),
15,
39
);
}
previousPinchDistance = distance;
} else {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.27,
1.35
);
}
previousX = event.clientX;
previousY = event.clientY;
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
15,
39
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") orbit.theta += step;
if (event.key === "ArrowRight") orbit.theta -= step;
if (event.key === "ArrowUp") orbit.phi = Math.max(0.27, orbit.phi - step);
if (event.key === "ArrowDown") orbit.phi = Math.min(1.35, orbit.phi + step);
if (event.key === "+" || event.key === "=") orbit.radius = Math.max(15, orbit.radius - 1.2);
if (event.key === "-") orbit.radius = Math.min(39, orbit.radius + 1.2);
if (event.key.toLowerCase() === "r") {
orbit.target.copy(defaultOrbit.target);
orbit.radius = defaultOrbit.radius;
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
}
});
// ------------------------------------------------------------
// Animation and resize
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
routeArrows.forEach((arrow, index) => {
arrow.position.y =
arrow.userData.baseY + Math.sin(elapsed * 1.5 + arrow.userData.phase) * 0.008;
arrow.rotation.z = Math.sin(elapsed * 0.8 + index) * 0.015;
});
glints.forEach(({ mesh, phase }) => {
mesh.material.opacity = 0.38 + Math.sin(elapsed * 1.2 + phase) * 0.10;
});
flags.forEach(({ mesh, phase }) => {
mesh.rotation.y = Math.sin(elapsed * 2.0 + phase) * 0.08;
});
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.render(scene, camera);
loading.classList.add("done");
setTimeout(() => loading.remove(), 500);
animate();
</script>
</body>
</html>
```