Prompt specification
Build or customize the Three.js 3D scene "Cape resupply harbor loading vignette" 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: Cape resupply harbor loading vignette
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cape-resupply-harbor-loading-vignette-x2578
Scene Description Prompt:
I'd like to see this as a cutaway Three.js scene: Cape resupply harbor loading vignette. Create a historically referenced Cape harbor transfer scene with ship, casks, and shore storage. Include sourced context about labor and power rather than presenting a purely technical port story. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (cape-resupply-harbor-loading-vignette-x2578):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#172b2d">
<title>Table Bay — A Cape Resupply Vignette</title>
<style>
:root {
--ink: #172b2d;
--ink-soft: #405457;
--paper: #f4efe3;
--paper-deep: #e6ddcb;
--sea: #467f89;
--gold: #c98d3b;
--rust: #9b4f35;
--line: rgba(23, 43, 45, .19);
--shadow: 0 18px 50px rgba(13, 29, 31, .20);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7dfda;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.masthead {
position: fixed;
top: 28px;
left: 30px;
z-index: 10;
width: min(560px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 1px 18px rgba(244, 239, 227, .88);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--ink-soft);
font-size: 10px;
font-weight: 800;
letter-spacing: .17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: var(--rust);
}
h1 {
margin: 0;
max-width: 520px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 4.7vw, 68px);
font-weight: 500;
line-height: .93;
letter-spacing: -.045em;
}
.subtitle {
max-width: 490px;
margin: 13px 0 0;
color: #405457;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
line-height: 1.5;
}
.top-actions {
position: fixed;
z-index: 30;
top: 26px;
right: 26px;
display: flex;
gap: 9px;
}
.button {
min-height: 40px;
border: 1px solid rgba(23, 43, 45, .22);
border-radius: 999px;
background: rgba(244, 239, 227, .91);
color: var(--ink);
padding: 0 15px;
box-shadow: 0 5px 18px rgba(23, 43, 45, .10);
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform .16s ease, background .16s ease, border-color .16s ease;
font-size: 12px;
font-weight: 750;
letter-spacing: .025em;
}
.button:hover,
.button:focus-visible {
transform: translateY(-1px);
border-color: rgba(23, 43, 45, .48);
background: #fffaf0;
outline: none;
}
.button.primary {
border-color: var(--rust);
background: var(--rust);
color: #fff8e9;
}
.button.primary:hover,
.button.primary:focus-visible {
background: #85432f;
}
.power-strip {
position: fixed;
z-index: 10;
top: 82px;
right: 27px;
width: 228px;
padding: 14px 16px;
border: 1px solid rgba(23, 43, 45, .14);
border-radius: 12px;
background: rgba(244, 239, 227, .80);
box-shadow: 0 10px 30px rgba(23, 43, 45, .09);
backdrop-filter: blur(10px);
}
.power-strip .strip-title {
margin-bottom: 9px;
color: var(--ink-soft);
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.power-row {
display: grid;
grid-template-columns: 55px 1fr;
gap: 8px;
padding: 6px 0;
border-top: 1px solid var(--line);
font-size: 10px;
line-height: 1.3;
}
.power-row:first-of-type { border-top: 0; }
.power-row b { color: var(--rust); text-transform: uppercase; letter-spacing: .06em; }
.power-row span { color: var(--ink-soft); }
.context-card {
position: fixed;
z-index: 20;
left: 28px;
bottom: 28px;
width: min(430px, calc(100vw - 56px));
padding: 20px 22px 18px;
border: 1px solid rgba(23, 43, 45, .16);
border-radius: 15px;
background: rgba(244, 239, 227, .94);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.context-card .kicker {
color: var(--rust);
font-size: 9px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
.context-card h2 {
margin: 7px 30px 8px 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
font-weight: 500;
line-height: 1.08;
letter-spacing: -.025em;
}
.context-card p {
margin: 0;
color: var(--ink-soft);
font-family: Georgia, "Times New Roman", serif;
font-size: 13.5px;
line-height: 1.55;
}
.context-card .source-line {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #637276;
font-size: 10px;
line-height: 1.4;
}
.citation {
color: var(--rust);
font-weight: 850;
text-decoration: none;
border-bottom: 1px dotted currentColor;
}
.citation:hover { color: #65301f; }
.context-card .back-link {
display: inline-block;
margin-top: 12px;
padding: 0;
border: 0;
background: none;
color: var(--rust);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
#hotspots {
position: fixed;
inset: 0;
z-index: 15;
pointer-events: none;
}
.hotspot {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 0;
border: 0;
background: none;
color: var(--ink);
cursor: pointer;
pointer-events: auto;
transform: translate(-50%, -50%);
filter: drop-shadow(0 4px 8px rgba(23, 43, 45, .22));
}
.hotspot .dot {
position: relative;
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 2px solid rgba(255, 248, 233, .94);
border-radius: 50%;
background: var(--rust);
color: #fff;
box-shadow: 0 0 0 1px rgba(23, 43, 45, .34);
font-family: Georgia, serif;
font-size: 12px;
font-weight: 700;
}
.hotspot .dot::after {
content: "";
position: absolute;
inset: -7px;
border: 1px solid rgba(155, 79, 53, .45);
border-radius: 50%;
animation: pulse 2.4s ease-out infinite;
}
.hotspot .tag {
padding: 6px 9px;
border: 1px solid rgba(23, 43, 45, .17);
border-radius: 4px;
background: rgba(244, 239, 227, .91);
font-size: 9px;
font-weight: 850;
letter-spacing: .10em;
text-transform: uppercase;
white-space: nowrap;
}
@keyframes pulse {
0% { transform: scale(.72); opacity: .9; }
72%, 100% { transform: scale(1.35); opacity: 0; }
}
.view-tools {
position: fixed;
z-index: 20;
right: 27px;
bottom: 28px;
display: grid;
justify-items: end;
gap: 8px;
}
.control-row {
display: flex;
gap: 7px;
}
.icon-button {
display: grid;
width: 39px;
height: 39px;
place-items: center;
border: 1px solid rgba(23, 43, 45, .20);
border-radius: 50%;
background: rgba(244, 239, 227, .93);
color: var(--ink);
box-shadow: 0 5px 18px rgba(23, 43, 45, .10);
cursor: pointer;
font-size: 17px;
}
.icon-button:hover,
.icon-button:focus-visible {
background: #fffaf0;
outline: 2px solid rgba(155, 79, 53, .35);
outline-offset: 2px;
}
.hint {
color: rgba(23, 43, 45, .72);
font-size: 9px;
letter-spacing: .06em;
text-align: right;
text-shadow: 0 1px 5px rgba(244, 239, 227, .9);
}
.route-status {
display: none;
min-width: 190px;
padding: 10px 12px;
border: 1px solid rgba(23, 43, 45, .17);
border-radius: 9px;
background: rgba(244, 239, 227, .93);
box-shadow: var(--shadow);
}
.route-status.visible { display: block; }
.route-status b {
display: block;
margin-bottom: 6px;
color: var(--rust);
font-size: 9px;
letter-spacing: .13em;
text-transform: uppercase;
}
.route-bar {
height: 3px;
overflow: hidden;
border-radius: 2px;
background: rgba(23, 43, 45, .13);
}
.route-bar i {
display: block;
width: 0;
height: 100%;
background: var(--rust);
}
.route-status span {
display: block;
margin-top: 6px;
color: var(--ink-soft);
font-size: 10px;
}
.source-overlay {
position: fixed;
inset: 0;
z-index: 40;
display: none;
background: rgba(14, 28, 30, .27);
backdrop-filter: blur(2px);
}
.source-overlay.open { display: block; }
.source-panel {
position: absolute;
top: 0;
right: 0;
width: min(510px, 100vw);
height: 100%;
overflow-y: auto;
padding: 30px 32px 40px;
background: var(--paper);
box-shadow: -20px 0 60px rgba(14, 28, 30, .22);
}
.source-panel .close {
position: absolute;
top: 19px;
right: 20px;
}
.source-panel h2 {
margin: 7px 40px 8px 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 34px;
font-weight: 500;
letter-spacing: -.035em;
}
.source-intro {
margin: 0 0 22px;
color: var(--ink-soft);
font-family: Georgia, serif;
font-size: 14px;
line-height: 1.58;
}
.method-note {
margin: 0 0 25px;
padding: 14px 15px;
border-left: 3px solid var(--rust);
background: rgba(155, 79, 53, .065);
color: var(--ink-soft);
font-size: 12px;
line-height: 1.55;
}
.source-list {
display: grid;
gap: 17px;
}
.source-item {
padding-top: 14px;
border-top: 1px solid var(--line);
}
.source-item .number {
display: inline-grid;
width: 22px;
height: 22px;
margin-right: 7px;
place-items: center;
border-radius: 50%;
background: var(--ink);
color: var(--paper);
font-size: 10px;
font-weight: 800;
}
.source-item a {
color: var(--ink);
font-family: Georgia, serif;
font-size: 14px;
font-weight: 700;
text-decoration-color: var(--rust);
text-underline-offset: 3px;
}
.source-item p {
margin: 6px 0 0 30px;
color: var(--ink-soft);
font-size: 11px;
line-height: 1.5;
}
.source-item .source-use {
color: var(--rust);
font-size: 10px;
font-weight: 750;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #d7dfda;
color: var(--ink);
transition: opacity .5s ease, visibility .5s ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-inner {
text-align: center;
}
.loading-mark {
width: 48px;
height: 48px;
margin: 0 auto 17px;
border: 2px solid rgba(23, 43, 45, .20);
border-top-color: var(--rust);
border-radius: 50%;
animation: spin 1s linear infinite;
}
.loading-inner b {
display: block;
margin-bottom: 6px;
font-family: Georgia, serif;
font-size: 21px;
font-weight: 500;
}
.loading-inner span {
color: var(--ink-soft);
font-size: 10px;
letter-spacing: .14em;
text-transform: uppercase;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 800px) {
.masthead { top: 20px; left: 19px; width: calc(100vw - 38px); }
.top-actions { top: auto; right: 17px; bottom: 17px; }
.power-strip { display: none; }
.context-card {
left: 16px;
bottom: 16px;
width: min(370px, calc(100vw - 32px));
padding: 16px 17px;
}
.context-card h2 { font-size: 21px; }
.context-card p { font-size: 12px; }
.view-tools { right: 16px; bottom: 76px; }
.hint { display: none; }
.hotspot .tag { display: none; }
.source-panel { padding: 26px 22px 35px; }
}
@media (max-height: 640px) {
.subtitle, .power-strip, .hint { display: none; }
.context-card { padding: 13px 16px; }
.context-card p { line-height: 1.4; }
.context-card .source-line { margin-top: 8px; padding-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
.hotspot .dot::after { animation: none; }
.loading-mark { animation-duration: 2s; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive cutaway of a ship transferring casks to shore storage at Table Bay"></div>
<header class="masthead">
<div class="eyebrow">Interpretive reconstruction · Table Bay, c. 1740</div>
<h1>Wind moved the ship.<br>People moved everything else.</h1>
<p class="subtitle">A Cape refreshment stop: cargo crosses from an ocean-going ship to a lighter, timber landing and a cutaway shore store.</p>
</header>
<div class="top-actions">
<button class="button" id="sources-button" type="button">Context & sources</button>
<button class="button primary" id="trace-button" type="button">Trace a transfer</button>
</div>
<aside class="power-strip" aria-label="Power and labor relationships">
<div class="strip-title">Power was layered</div>
<div class="power-row"><b>Wind</b><span>Canvas and sail moved the ocean ship.</span></div>
<div class="power-row"><b>Muscle</b><span>People loaded the lighter and worked the shore.</span></div>
<div class="power-row"><b>Order</b><span>Company power made the transfer possible.</span></div>
</aside>
<div id="hotspots">
<button class="hotspot" type="button" data-hotspot="sail" aria-label="Read about sail power">
<span class="dot">1</span><span class="tag">Wind & sail</span>
</button>
<button class="hotspot" type="button" data-hotspot="labor" aria-label="Read about harbor labor">
<span class="dot">2</span><span class="tag">Human muscle</span>
</button>
<button class="hotspot" type="button" data-hotspot="store" aria-label="Read about company storage">
<span class="dot">3</span><span class="tag">Company order</span>
</button>
</div>
<section class="context-card" id="context-card" aria-live="polite">
<div class="kicker" id="context-kicker">A company refreshment stop</div>
<h2 id="context-title">The ship was only the beginning.</h2>
<p id="context-text">This composite reconstruction shows Table Bay in the mid-eighteenth century. The Company ship needed provisions, fresh water and reliable stores; Company rule and a mixed, unequal workforce turned those needs into cargo handling.</p>
<div class="source-line" id="context-sources">
Historical orientation:
<a class="citation" href="#source-1" data-open-sources>[1]</a>
<a class="citation" href="#source-2" data-open-sources>[2]</a>
<a class="citation" href="#source-4" data-open-sources>[4]</a>
· The scene is interpretive, not a depiction of one documented incident.
</div>
<button class="back-link" id="overview-button" type="button" hidden>← Return to overview</button>
</section>
<div class="view-tools">
<div class="route-status" id="route-status">
<b id="route-phase">Ship → lighter</b>
<div class="route-bar"><i id="route-progress"></i></div>
<span>Illustrative cargo route</span>
</div>
<div class="control-row">
<button class="icon-button" id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button class="icon-button" id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button class="icon-button" id="reset-view" type="button" aria-label="Reset camera" title="Reset view">↺</button>
</div>
<div class="hint">Drag to orbit · wheel to zoom · right-drag to pan</div>
</div>
<div class="source-overlay" id="source-overlay" aria-hidden="true">
<aside class="source-panel" role="dialog" aria-modal="true" aria-labelledby="source-heading">
<button class="icon-button close" id="close-sources" type="button" aria-label="Close sources">×</button>
<div class="eyebrow">Historical frame</div>
<h2 id="source-heading">Sources & method</h2>
<p class="source-intro">The maritime setting and social context are drawn from institutional histories. The exact ship, landing, warehouse, cargo and human figures are a teaching reconstruction rather than evidence of one named event.</p>
<div class="method-note"><strong>Reading the scene honestly:</strong> Table Bay’s shoreline changed repeatedly. Clothing and skin tones here do not assign a legal status to any individual. The figures deliberately represent the labor force as mixed and unequal, not as a single stereotyped “port worker.”</div>
<div class="source-list">
<article class="source-item" id="source-1">
<a href="https://www.sahistory.org.za/article/cape-under-dutch-east-india-company-1652-1795" target="_blank" rel="noopener noreferrer">
<span class="number">1</span>South African History Online — “The Cape under the Dutch East India Company, 1652–1795”
</a>
<p>Used for the VOC’s role at the Cape, the refreshment function of Table Bay, colonial administration and the socially differentiated workforce.</p>
<p class="source-use">Source use: Company power, provisioning and port society.</p>
</article>
<article class="source-item" id="source-2">
<a href="https://www.sahistory.org.za/article/slavery-cape" target="_blank" rel="noopener noreferrer">
<span class="number">2</span>South African History Online — “Slavery at the Cape”
</a>
<p>Used for the legal framework of enslavement, the expansion of coerced labor and the central role of enslaved people in the colonial economy.</p>
<p class="source-use">Source use: coercion, slavery and the limits of a purely technical harbor story.</p>
</article>
<article class="source-item" id="source-3">
<a href="https://www.iziko.org.za/slave-lodge/" target="_blank" rel="noopener noreferrer">
<span class="number">3</span>Iziko Museums — Slave Lodge Museum
</a>
<p>Used as an institutional point of reference for the history and public memory of enslavement at the Cape.</p>
<p class="source-use">Source use: context and responsible interpretation.</p>
</article>
<article class="source-item" id="source-4">
<a href="https://www.britannica.com/place/Cape-Town-South-Africa/History" target="_blank" rel="noopener noreferrer">
<span class="number">4</span>Encyclopaedia Britannica — “Cape Town: History”
</a>
<p>Used for Table Bay’s development as a maritime roadstead and refreshment point and for the changing built waterfront.</p>
<p class="source-use">Source use: maritime geography and waterfront change.</p>
</article>
<article class="source-item" id="source-5">
<a href="https://www.rijksmuseum.nl/en/collection/explore-the-voc" target="_blank" rel="noopener noreferrer">
<span class="number">5</span>Rijksmuseum — “Explore the VOC”
</a>
<p>Used for the corporate organization of the Dutch East India Company and the scale and structure of its maritime network.</p>
<p class="source-use">Source use: company shipping and commercial power.</p>
</article>
</div>
</aside>
</div>
<div id="loading">
<div class="loading-inner">
<div class="loading-mark"></div>
<b>Table Bay</b>
<span>Building the cutaway</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";
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7dfda);
scene.fog = new THREE.Fog(0xd7dfda, 42, 78);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
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.tabIndex = 0;
renderer.domElement.setAttribute("aria-label", "Three-dimensional Table Bay cutaway. Drag to orbit, wheel to zoom.");
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 0.1, 150);
const orbit = {
target: new THREE.Vector3(-0.8, 1.2, 0),
yaw: 0.16,
pitch: 0.56,
distance: 39
};
const defaultOrbit = { ...orbit, target: orbit.target.clone() };
function updateCamera() {
const horizontal = Math.cos(orbit.pitch) * orbit.distance;
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontal,
orbit.target.y + Math.sin(orbit.pitch) * orbit.distance,
orbit.target.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xe8f2ee, 0x675544, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd3, 3.25);
sun.position.set(-14, 25, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8c5c7, 1.0);
fill.position.set(18, 10, -15);
scene.add(fill);
const warmInterior = new THREE.PointLight(0xffc977, 12, 12, 2);
warmInterior.position.set(8, 2.2, -2.2);
scene.add(warmInterior);
// Deterministic procedural textures keep the file self-contained.
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
function makeSandTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 512;
const ctx = canvas.getContext("2d");
const rand = seededRandom(1740);
ctx.fillStyle = "#bca778";
ctx.fillRect(0, 0, 512, 512);
for (let i = 0; i < 9000; i++) {
const shade = 145 + Math.floor(rand() * 55);
ctx.fillStyle = `rgba(${shade},${shade - 20},${shade - 55},${0.08 + rand() * 0.12})`;
const r = 0.5 + rand() * 2.3;
ctx.beginPath();
ctx.arc(rand() * 512, rand() * 512, r, 0, Math.PI * 2);
ctx.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(4, 5);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const rand = seededRandom(83);
ctx.fillStyle = "#805539";
ctx.fillRect(0, 0, 256, 512);
for (let x = 0; x < 256; x += 8) {
const v = 105 + Math.floor(rand() * 36);
ctx.fillStyle = `rgba(${v + 25},${v - 20},${v - 45},.30)`;
ctx.fillRect(x, 0, 7, 512);
}
for (let i = 0; i < 80; i++) {
ctx.strokeStyle = `rgba(50,25,12,${0.04 + rand() * 0.08})`;
ctx.beginPath();
const x = rand() * 256;
ctx.moveTo(x, 0);
ctx.bezierCurveTo(x + rand() * 12, 160, x - rand() * 10, 330, x + rand() * 9, 512);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeSailTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 256;
const ctx = canvas.getContext("2d");
const rand = seededRandom(42);
ctx.fillStyle = "#d9cbaa";
ctx.fillRect(0, 0, 256, 256);
for (let x = 0; x <= 256; x += 32) {
ctx.fillStyle = "rgba(104,85,58,.13)";
ctx.fillRect(x, 0, 2, 256);
ctx.strokeStyle = "rgba(89,70,45,.24)";
ctx.setLineDash([3, 3]);
ctx.beginPath();
ctx.moveTo(x + 3, 0);
ctx.lineTo(x + 3, 256);
ctx.stroke();
ctx.setLineDash([]);
}
for (let i = 0; i < 190; i++) {
ctx.fillStyle = `rgba(104,82,48,${0.015 + rand() * 0.045})`;
ctx.beginPath();
ctx.arc(rand() * 256, rand() * 256, 2 + rand() * 15, 0, Math.PI * 2);
ctx.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const sandTexture = makeSandTexture();
const woodTexture = makeWoodTexture();
const sailTexture = makeSailTexture();
const M = {
plinth: new THREE.MeshStandardMaterial({ color: 0x203c3e, roughness: 0.86, metalness: 0.03 }),
earth: new THREE.MeshStandardMaterial({ color: 0x8c6c48, roughness: 1 }),
earthDark: new THREE.MeshStandardMaterial({ color: 0x5f4936, roughness: 1 }),
earthPale: new THREE.MeshStandardMaterial({ color: 0xb89a68, roughness: 1 }),
sand: new THREE.MeshStandardMaterial({ map: sandTexture, color: 0xd0ba8c, roughness: 1 }),
water: new THREE.MeshPhysicalMaterial({
color: 0x4d91a0,
roughness: 0.2,
metalness: 0.04,
transparent: true,
opacity: 0.72,
transmission: 0.08,
thickness: 1.5,
depthWrite: false
}),
waterSurface: new THREE.MeshStandardMaterial({
color: 0x71a9af,
roughness: 0.34,
metalness: 0.08,
transparent: true,
opacity: 0.72,
depthWrite: false
}),
timber: new THREE.MeshStandardMaterial({ map: woodTexture, color: 0x9a704c, roughness: 0.87 }),
darkTimber: new THREE.MeshStandardMaterial({ map: woodTexture, color: 0x503727, roughness: 0.9 }),
paleTimber: new THREE.MeshStandardMaterial({ map: woodTexture, color: 0xc19b6c, roughness: 0.88 }),
iron: new THREE.MeshStandardMaterial({ color: 0x2e3030, roughness: 0.55, metalness: 0.55 }),
rope: new THREE.LineBasicMaterial({ color: 0x4a3a2a, transparent: true, opacity: 0.8 }),
sail: new THREE.MeshStandardMaterial({
map: sailTexture,
color: 0xf0e2c5,
roughness: 0.94,
side: THREE.DoubleSide
}),
plaster: new THREE.MeshStandardMaterial({ color: 0xd7c6a7, roughness: 0.95 }),
roof: new THREE.MeshStandardMaterial({ color: 0x8d4734, roughness: 0.87, side: THREE.DoubleSide }),
brass: new THREE.MeshStandardMaterial({ color: 0xb58a48, roughness: 0.42, metalness: 0.45 }),
foam: new THREE.LineBasicMaterial({ color: 0xe9f0e8, transparent: true, opacity: 0.48 })
};
function addMesh(geometry, material, position, parent = scene, cast = true, receive = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(a, b, radius, material, parent = scene, radialSegments = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(start).add(end).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;
}
function addLine(points, material = M.rope, parent = scene) {
const geometry = new THREE.BufferGeometry().setFromPoints(points.map(p => new THREE.Vector3(...p)));
const line = new THREE.Line(geometry, material);
parent.add(line);
return line;
}
function addQuad(points, material, parent = scene) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(points.flat(), 3));
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
return addMesh(geometry, material, [0, 0, 0], parent);
}
// Diorama plinth and cutaway geology.
const plinth = addMesh(new THREE.BoxGeometry(36, 1.25, 20), M.plinth, [0, -2.25, 0]);
const plinthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(plinth.geometry),
new THREE.LineBasicMaterial({ color: 0x839b97, transparent: true, opacity: 0.34 })
);
plinth.add(plinthEdges);
addMesh(new THREE.BoxGeometry(19, 2.15, 18), M.water, [-7.5, -0.62, 0], scene, false, true);
const waterSurface = addMesh(new THREE.BoxGeometry(19, 0.09, 18), M.waterSurface, [-7.5, 0.48, 0], scene, false, false);
addMesh(new THREE.BoxGeometry(15, 2.15, 18), M.earth, [9.5, -0.62, 0]);
addMesh(new THREE.BoxGeometry(15, 0.17, 18), M.sand, [9.5, 0.53, 0]);
// Exposed geological strata on the cut face.
addMesh(new THREE.BoxGeometry(15, 0.42, 0.08), M.earthPale, [9.5, -0.05, 9.04], scene, false, true);
addMesh(new THREE.BoxGeometry(15, 0.75, 0.09), M.earth, [9.5, -0.62, 9.05], scene, false, true);
addMesh(new THREE.BoxGeometry(15, 0.62, 0.10), M.earthDark, [9.5, -1.30, 9.06], scene, false, true);
// Sparse stones in the shallows and low Cape scrub.
const stoneMats = [0x756a55, 0x8b8068, 0x5e6158];
for (let i = 0; i < 18; i++) {
const rand = seededRandom(510 + i);
const stone = addMesh(
new THREE.DodecahedronGeometry(0.12 + rand() * 0.22, 0),
new THREE.MeshStandardMaterial({ color: stoneMats[i % 3], roughness: 1 }),
[-15.5 + rand() * 15.5, 0.35, -7.5 + rand() * 15],
scene,
true,
true
);
stone.scale.set(1, 0.55 + rand() * 0.4, 0.8 + rand() * 0.5);
stone.rotation.set(rand(), rand() * Math.PI, rand());
}
for (let i = 0; i < 7; i++) {
const hill = addMesh(
new THREE.DodecahedronGeometry(1.6 + (i % 3) * 0.45, 1),
new THREE.MeshStandardMaterial({ color: i % 2 ? 0xa98e62 : 0xb39a70, roughness: 1 }),
[4.2 + i * 2.0, 0.67, -7.4 - (i % 2) * 0.45],
scene,
true,
true
);
hill.scale.set(1.65, 0.45 + (i % 3) * 0.08, 0.8);
hill.rotation.y = i * 0.7;
}
// Moving wake marks.
const waveMarks = [];
for (let i = 0; i < 28; i++) {
const rand = seededRandom(400 + i);
const x = -16 + rand() * 17;
const z = -8 + rand() * 16;
const length = 0.25 + rand() * 0.85;
const wave = addLine([
[x, 0.535, z],
[x + length * 0.45, 0.54, z + 0.035],
[x + length, 0.535, z]
], M.foam);
wave.userData = { baseX: x, baseZ: z, phase: rand() * Math.PI * 2, speed: 0.12 + rand() * 0.15 };
waveMarks.push(wave);
}
// Barrels use a lathed profile, wooden staves and iron hoops.
function createCask(scale = 1, highlighted = false) {
const group = new THREE.Group();
const woodMaterial = highlighted
? new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xf0a047,
roughness: 0.58,
emissive: 0x5a2607,
emissiveIntensity: 0.45
})
: M.timber;
const profile = [
new THREE.Vector2(0.37, -0.50),
new THREE.Vector2(0.46, -0.36),
new THREE.Vector2(0.49, -0.10),
new THREE.Vector2(0.49, 0.10),
new THREE.Vector2(0.46, 0.36),
new THREE.Vector2(0.37, 0.50)
];
const body = new THREE.Mesh(new THREE.LatheGeometry(profile, 18), woodMaterial);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
for (const y of [-0.32, 0, 0.32]) {
const hoop = new THREE.Mesh(new THREE.TorusGeometry(0.465, 0.032, 6, 22), M.iron);
hoop.rotation.x = Math.PI / 2;
hoop.position.y = y;
hoop.castShadow = true;
group.add(hoop);
}
const lid = new THREE.Mesh(new THREE.CylinderGeometry(0.365, 0.365, 0.025, 18), M.paleTimber);
lid.position.y = 0.505;
lid.castShadow = true;
group.add(lid);
group.scale.setScalar(scale);
return group;
}
// Procedural hull with pointed bow and stern.
function createHull() {
const group = new THREE.Group();
const stations = [
[-4.2, 0.08, 0.66, -0.18],
[-3.45, 0.72, 0.74, -0.37],
[-2.1, 1.13, 0.78, -0.48],
[1.85, 1.10, 0.78, -0.48],
[3.45, 0.65, 0.72, -0.35],
[4.2, 0.08, 0.62, -0.16]
];
const vertices = [];
const indices = [];
stations.forEach(s => {
const [x, w, top, keel] = s;
vertices.push(x, top, -w, x, top, w, x, keel, 0);
});
for (let i = 0; i < stations.length - 1; i++) {
const a = i * 3;
const b = (i + 1) * 3;
indices.push(a, b, a + 2, b, b + 2, a + 2);
indices.push(a + 1, a + 2, b + 1, b + 1, a + 2, b + 2);
}
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
hullGeometry.setIndex(indices);
hullGeometry.computeVertexNormals();
const hullMaterial = M.darkTimber.clone();
hullMaterial.side = THREE.DoubleSide;
const hull = new THREE.Mesh(hullGeometry, hullMaterial);
hull.castShadow = true;
hull.receiveShadow = true;
group.add(hull);
const deckShape = new THREE.Shape();
const deckPoints = [
[-4.1, 0], [-3.45, .70], [-2.1, 1.11], [1.85, 1.08],
[3.45, .63], [4.1, 0], [3.45, -.63], [1.85, -1.08],
[-2.1, -1.11], [-3.45, -.70]
];
deckPoints.forEach((p, i) => i ? deckShape.lineTo(p[0], p[1]) : deckShape.moveTo(p[0], p[1]));
deckShape.closePath();
const deck = new THREE.Mesh(new THREE.ShapeGeometry(deckShape), M.paleTimber);
deck.rotation.x = -Math.PI / 2;
deck.position.y = 0.755;
deck.castShadow = true;
deck.receiveShadow = true;
group.add(deck);
for (const side of [-1, 1]) {
const railPoints = stations.map(s => new THREE.Vector3(s[0], s[2] + 0.08, side * s[1] * 0.97));
const rail = new THREE.Mesh(
new THREE.TubeGeometry(new THREE.CatmullRomCurve3(railPoints), 40, 0.045, 6, false),
M.timber
);
rail.castShadow = true;
group.add(rail);
}
return group;
}
function makeSail(width, height) {
const geometry = new THREE.PlaneGeometry(width, height, 10, 6);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const y = position.getY(i);
const u = x / width + 0.5;
const v = y / height + 0.5;
const bulge = Math.sin(u * Math.PI) * (0.13 + Math.sin(v * Math.PI) * 0.18);
position.setZ(i, bulge);
}
geometry.computeVertexNormals();
const sail = new THREE.Mesh(geometry, M.sail);
sail.rotation.y = Math.PI / 2;
sail.castShadow = true;
sail.receiveShadow = true;
return sail;
}
// Main ocean-going Company ship.
const ship = new THREE.Group();
ship.position.set(-9.0, 0.52, -2.35);
ship.rotation.y = -0.05;
scene.add(ship);
ship.add(createHull());
const mastData = [
{ x: -2.25, height: 5.9, sailW: 2.15, sailH: 2.35, y: 3.65 },
{ x: 0.25, height: 7.05, sailW: 2.55, sailH: 3.05, y: 4.05 },
{ x: 2.65, height: 5.7, sailW: 2.0, sailH: 2.35, y: 3.55 }
];
mastData.forEach((d, index) => {
addCylinderBetween([d.x, 0.72, 0], [d.x, d.height, 0], 0.075, M.darkTimber, ship);
const yardY = d.y + d.sailH * 0.45;
const yard = addCylinderBetween(
[d.x, yardY, -d.sailW * 0.56],
[d.x, yardY, d.sailW * 0.56],
0.045,
M.darkTimber,
ship
);
yard.castShadow = true;
const sail = makeSail(d.sailW, d.sailH);
sail.position.set(d.x, d.y, 0);
ship.add(sail);
if (index === 1) {
const lower = makeSail(2.35, 2.1);
lower.position.set(d.x, 2.3, 0);
ship.add(lower);
const lowerYard = addCylinderBetween(
[d.x, 3.25, -1.32], [d.x, 3.25, 1.32], 0.04, M.darkTimber, ship
);
lowerYard.castShadow = true;
}
});
addCylinderBetween([-3.25, .78, -.55], [-3.25, 1.65, -.55], .06, M.darkTimber, ship);
addCylinderBetween([2.95, .78, .55], [2.95, 1.55, .55], .06, M.darkTimber, ship);
addMesh(new THREE.BoxGeometry(.75, .45, .85), M.paleTimber, [2.85, 1.0, .52], ship);
for (const side of [-1, 1]) {
addLine([
[-2.25, 5.75, side * .95], [-4.0, .8, side * .35], [-1.5, .8, side * .85]
], M.rope, ship);
addLine([
[.25, 6.9, side * 1.2], [-3.65, .8, side * .55], [3.75, .8, side * .55]
], M.rope, ship);
addLine([
[2.65, 5.55, side * .9], [4.05, .78, side * .2], [.4, .78, side * .9]
], M.rope, ship);
}
const deckCasks = [
[2.35, 1.26, -.38, .8],
[2.65, 1.23, .45, .72],
[-2.85, 1.22, .28, .68]
];
deckCasks.forEach(data => {
const cask = createCask(data[3]);
cask.position.set(data[0], data[1], data[2]);
ship.add(cask);
});
// Timber landing and piles.
for (let i = 0; i < 10; i++) {
addMesh(
new THREE.BoxGeometry(4.5, 0.13, 0.24),
i % 2 ? M.timber : M.paleTimber,
[3.05, 0.74, 1.34 + i * 0.235]
);
}
for (const x of [1.05, 4.95]) {
for (const z of [1.25, 3.43]) {
addCylinderBetween([x, -0.8, z], [x, 1.25, z], .11, M.darkTimber);
}
}
addCylinderBetween([1.08, 1.12, 1.25], [4.92, 1.12, 1.25], .07, M.darkTimber);
addCylinderBetween([1.08, 1.12, 3.43], [4.92, 1.12, 3.43], .07, M.darkTimber);
// Shore store, deliberately opened at the front like an architectural cutaway.
const warehouse = new THREE.Group();
warehouse.position.set(8, 0.62, -2.85);
scene.add(warehouse);
addMesh(new THREE.BoxGeometry(6.5, .25, 5.0), M.paleTimber, [0, 0, 0], warehouse);
addMesh(new THREE.BoxGeometry(6.5, 3.05, .22), M.plaster, [0, 1.55, -2.5], warehouse);
addMesh(new THREE.BoxGeometry(.22, 3.05, 5.0), M.plaster, [-3.25, 1.55, 0], warehouse);
addMesh(new THREE.BoxGeometry(.22, 3.05, 5.0), M.plaster, [3.25, 1.55, 0], warehouse);
for (const x of [-3.05, 0, 3.05]) {
addMesh(new THREE.BoxGeometry(.20, 3.25, .20), M.darkTimber, [x, 1.62, 2.38], warehouse);
}
addMesh(new THREE.BoxGeometry(6.45, .20, .22), M.darkTimber, [0, 3.08, 2.38], warehouse);
// Rear half of the tiled roof remains, revealing the interior.
addQuad([
[-3.5, 3.12, -2.65], [0, 4.73, -2.65],
[0, 4.73, -0.45], [-3.5, 3.12, -0.45]
], M.roof, warehouse);
addQuad([
[0, 4.73, -2.65], [3.5, 3.12, -2.65],
[3.5, 3.12, -0.45], [0, 4.73, -0.45]
], M.roof, warehouse);
addCylinderBetween([0, 4.75, -2.68], [0, 4.75, .05], .09, M.darkTimber, warehouse);
for (const z of [-2.55, -1.65, -.72]) {
addCylinderBetween([-3.38, 3.14, z], [0, 4.72, z], .065, M.darkTimber, warehouse);
addCylinderBetween([0, 4.72, z], [3.38, 3.14, z], .065, M.darkTimber, warehouse);
}
const storedCasks = [
[-2.1, .69, -.15, .9], [-1.1, .69, -.15, .9],
[-2.1, .69, 1.0, .9], [-1.1, .69, 1.0, .9],
[.2, .67, .25, .85], [1.15, .67, .25, .85],
[.2, .67, 1.35, .85], [1.15, .67, 1.35, .85]
];
storedCasks.forEach((d, i) => {
const cask = createCask(d[3]);
cask.position.set(d[0], d[1], d[2]);
cask.rotation.y = i * .41;
warehouse.add(cask);
});
// Additional stacked casks beneath a simple lean-to.
addCylinderBetween([4.3, 2.5, -5.9], [4.3, 2.5, -2.2], .07, M.darkTimber);
addCylinderBetween([7.6, 2.5, -5.9], [7.6, 2.5, -2.2], .07, M.darkTimber);
addQuad([
[4.1, 2.6, -5.9], [7.8, 2.6, -5.9],
[7.8, 2.6, -2.1], [4.1, 2.6, -2.1]
], M.roof);
for (let i = 0; i < 6; i++) {
const cask = createCask(.78);
cask.position.set(4.65 + (i % 3) * 1.05, 1.16, -5.15 + Math.floor(i / 3) * 1.35);
scene.add(cask);
}
// Lighter carrying cargo between ship and shore.
const lighter = new THREE.Group();
lighter.position.set(-1.15, 0.62, 2.67);
lighter.rotation.y = 0.055;
scene.add(lighter);
const lighterHull = createHull();
lighterHull.scale.set(.47, .64, .62);
lighter.add(lighterHull);
addMesh(new THREE.BoxGeometry(2.8, .12, 1.18), M.paleTimber, [0, .73, 0], lighter);
for (let i = 0; i < 6; i++) {
const cask = createCask(.72);
cask.position.set(-.85 + (i % 3) * .82, 1.19, i < 3 ? -.29 : .29);
lighter.add(cask);
}
// Stylized workers. No legal status is encoded by clothing or complexion.
const workers = [];
function makeWorker({ position, shirt = 0x8a5a43, trousers = 0x4d5350, skin = 0x8d5f43, hat = true, phase = 0, carrying = false, scale = 1 }) {
const group = new THREE.Group();
group.position.set(...position);
group.scale.setScalar(scale);
scene.add(group);
const cloth = new THREE.MeshStandardMaterial({ color: shirt, roughness: 0.95 });
const trouserMat = new THREE.MeshStandardMaterial({ color: trousers, roughness: 0.96 });
const skinMat = new THREE.MeshStandardMaterial({ color: skin, roughness: 0.9 });
const hairMat = new THREE.MeshStandardMaterial({ color: 0x2e2925, roughness: 1 });
addMesh(new THREE.CylinderGeometry(.18, .24, .62, 8), cloth, [0, 1.03, 0], group);
addMesh(new THREE.SphereGeometry(.16, 10, 8), skinMat, [0, 1.49, 0], group);
addMesh(new THREE.SphereGeometry(.165, 10, 8, 0, Math.PI * 2, 0, Math.PI * .52), hairMat, [0, 1.51, 0], group);
addCylinderBetween([-.10, .78, 0], [-.13, .08, .06], .075, trouserMat, group);
addCylinderBetween([.10, .78, 0], [.16, .08, -.04], .075, trouserMat, group);
addCylinderBetween([-.19, 1.26, 0], [-.44, .79, .08], .065, cloth, group);
addCylinderBetween([.19, 1.26, 0], [.43, .88, .12], .065, cloth, group);
if (hat) {
addMesh(new THREE.CylinderGeometry(.18, .19, .11, 10), cloth, [0, 1.65, 0], group);
addMesh(new THREE.CylinderGeometry(.29, .29, .025, 12), cloth, [0, 1.60, 0], group);
}
if (carrying) {
const carried = createCask(.54);
carried.position.set(.42, .93, .15);
group.add(carried);
}
group.userData = { phase, baseY: position[1], baseRotation: group.rotation.z };
workers.push(group);
return group;
}
makeWorker({ position: [-1.55, .75, 3.00], shirt: 0x7b4a39, trousers: 0x3b4848, skin: 0x6f4934, phase: .2, carrying: true, scale: .93 });
makeWorker({ position: [-.25, .75, 2.35], shirt: 0xa68b65, trousers: 0x55483b, skin: 0xb27d58, phase: 1.7 });
makeWorker({ position: [1.55, .84, 3.12], shirt: 0x686f62, trousers: 0x3f4542, skin: 0x82543d, phase: 2.4, carrying: true, scale: .98 });
makeWorker({ position: [2.68, .84, 2.20], shirt: 0x967050, trousers: 0x4a4842, skin: 0x9e6c4c, phase: .8 });
makeWorker({ position: [4.48, .84, 3.05], shirt: 0x6e7772, trousers: 0x474844, skin: 0x6c4533, phase: 3.2, carrying: true });
makeWorker({ position: [5.32, .84, 1.75], shirt: 0x8d5c43, trousers: 0x3f494a, skin: 0xb17d59, phase: 1.2 });
makeWorker({ position: [6.14, .64, -.75], shirt: 0xa08a68, trousers: 0x51473d, skin: 0x7a5038, phase: 2.8, scale: .94 });
// Hand cart: a second transfer technology, still powered by people.
const cart = new THREE.Group();
cart.position.set(4.05, .77, 3.00);
cart.rotation.y = -0.18;
scene.add(cart);
addMesh(new THREE.BoxGeometry(2.1, .16, 1.05), M.timber, [0, .52, 0], cart);
addMesh(new THREE.BoxGeometry(2.1, .35, .08), M.paleTimber, [0, .76, .49], cart);
addMesh(new THREE.BoxGeometry(2.1, .35, .08), M.paleTimber, [0, .76, -.49], cart);
addCylinderBetween([-.55, .48, -.61], [-.55, .48, .61], .045, M.iron, cart);
for (const x of [-.68, .68]) {
for (const z of [-.61, .61]) {
const wheel = new THREE.Mesh(new THREE.TorusGeometry(.36, .065, 7, 18), M.darkTimber);
wheel.position.set(x, .36, z);
wheel.castShadow = true;
cart.add(wheel);
for (let a = 0; a < 6; a++) {
const angle = a * Math.PI / 3;
addCylinderBetween(
[x, .36, z],
[x + Math.cos(angle) * .31, .36 + Math.sin(angle) * .31, z],
.025,
M.paleTimber,
cart,
5
);
}
}
}
const cartCask = createCask(.78);
cartCask.position.set(.1, 1.18, 0);
cart.add(cartCask);
// Tiny quay-side crates and sacks add scale.
for (let i = 0; i < 5; i++) {
const crate = addMesh(
new THREE.BoxGeometry(.58, .48, .52),
i % 2 ? M.timber : M.paleTimber,
[10.3 + (i % 3) * .66, .91, 2.1 + Math.floor(i / 3) * .62]
);
crate.rotation.y = i * .23;
}
// Schematic route used only when requested.
const routeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-6.45, 1.65, -2.05),
new THREE.Vector3(-2.1, 1.55, 2.55),
new THREE.Vector3(1.65, 1.28, 2.62),
new THREE.Vector3(4.15, 1.86, 3.0),
new THREE.Vector3(7.15, 1.25, -.85)
], false, "centripetal");
const routeGeometry = new THREE.BufferGeometry().setFromPoints(routeCurve.getPoints(120));
const routeMaterial = new THREE.LineDashedMaterial({
color: 0xc57b3c,
dashSize: .22,
gapSize: .13,
transparent: true,
opacity: .82,
depthTest: false
});
const routeLine = new THREE.Line(routeGeometry, routeMaterial);
routeLine.computeLineDistances();
routeLine.visible = false;
routeLine.renderOrder = 8;
scene.add(routeLine);
const routeCask = createCask(.77, true);
routeCask.visible = false;
routeCask.renderOrder = 7;
scene.add(routeCask);
// Projected HTML hotspots.
const hotspotDefinitions = [
{ element: document.querySelector('[data-hotspot="sail"]'), point: new THREE.Vector3(-8.8, 7.25, -2.3) },
{ element: document.querySelector('[data-hotspot="labor"]'), point: new THREE.Vector3(1.0, 2.55, 3.0) },
{ element: document.querySelector('[data-hotspot="store"]'), point: new THREE.Vector3(8.1, 5.55, -2.7) }
];
function projectHotspots() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of hotspotDefinitions) {
const projected = item.point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
item.element.style.display = visible ? "flex" : "none";
item.element.style.left = `${(projected.x * .5 + .5) * width}px`;
item.element.style.top = `${(-projected.y * .5 + .5) * height}px`;
}
}
// Context cards foreground labor and power rather than only logistics.
const context = {
overview: {
kicker: "A company refreshment stop",
title: "The ship was only the beginning.",
text: "This composite reconstruction shows Table Bay in the mid-eighteenth century. The Company ship needed provisions, fresh water and reliable stores; Company rule and a mixed, unequal workforce turned those needs into cargo handling.",
sources: `Historical orientation:
<a class="citation" href="#source-1" data-open-sources>[1]</a>
<a class="citation" href="#source-2" data-open-sources>[2]</a>
<a class="citation" href="#source-4" data-open-sources>[4]</a>
· The scene is interpretive, not a depiction of one documented incident.`
},
sail: {
kicker: "Power 1 · Wind and sail",
title: "The ocean crossing was the least human part.",
text: "Wind supplied the ship’s motive power and sailors managed canvas, rigging and navigation. But arrival did not make cargo handling automatic: the refreshment stop depended on shoreside workers, local knowledge and the Company’s demand for reliable stores.",
sources: `Context:
<a class="citation" href="#source-1" data-open-sources>[1]</a>
<a class="citation" href="#source-4" data-open-sources>[4]</a>
<a class="citation" href="#source-5" data-open-sources>[5]</a>
· The generic ship is not identified with a specific vessel.`
},
labor: {
kicker: "Power 2 · Human muscle",
title: "A mixed workforce under unequal rules.",
text: "Company servants, soldiers, convicts, free residents, enslaved people and Khoekhoe people all contributed labor at the Cape under changing and unequal legal and political arrangements. Enslaved labor was integral to the colonial economy; describing a harbor only as an efficient machine erases the people inside that system.",
sources: `Context:
<a class="citation" href="#source-1" data-open-sources>[1]</a>
<a class="citation" href="#source-2" data-open-sources>[2]</a>
<a class="citation" href="#source-3" data-open-sources>[3]</a>
· Figures are illustrative and do not identify legal status.`
},
store: {
kicker: "Power 3 · Company order",
title: "Storage was control made visible.",
text: "Company warehouses and accounting converted cargo into managed assets. At the Cape, that commercial order rested on colonial monopoly and coerced labor. The cutaway store therefore represents more than shelter: it shows the administrative architecture that kept the refreshment system operating.",
sources: `Context:
<a class="citation" href="#source-1" data-open-sources>[1]</a>
<a class="citation" href="#source-5" data-open-sources>[5]</a>
· The building is a composite, not a measured reconstruction of one warehouse.`
}
};
function showContext(key) {
const data = context[key];
document.getElementById("context-kicker").textContent = data.kicker;
document.getElementById("context-title").textContent = data.title;
document.getElementById("context-text").textContent = data.text;
document.getElementById("context-sources").innerHTML = data.sources;
document.getElementById("overview-button").hidden = key === "overview";
bindSourceLinks();
}
document.querySelectorAll("[data-hotspot]").forEach(button => {
button.addEventListener("click", event => {
event.stopPropagation();
showContext(button.dataset.hotspot);
});
});
document.getElementById("overview-button").addEventListener("click", () => showContext("overview"));
// Sources drawer.
const sourceOverlay = document.getElementById("source-overlay");
function openSources() {
sourceOverlay.classList.add("open");
sourceOverlay.setAttribute("aria-hidden", "false");
document.getElementById("close-sources").focus();
}
function closeSources() {
sourceOverlay.classList.remove("open");
sourceOverlay.setAttribute("aria-hidden", "true");
document.getElementById("sources-button").focus();
}
function bindSourceLinks() {
document.querySelectorAll("[data-open-sources]").forEach(link => {
link.onclick = event => {
event.preventDefault();
openSources();
};
});
}
bindSourceLinks();
document.getElementById("sources-button").addEventListener("click", openSources);
document.getElementById("close-sources").addEventListener("click", closeSources);
sourceOverlay.addEventListener("click", event => {
if (event.target === sourceOverlay) closeSources();
});
window.addEventListener("keydown", event => {
if (event.key === "Escape" && sourceOverlay.classList.contains("open")) closeSources();
});
// Transfer animation.
let routeActive = false;
let routeTime = 0;
const traceButton = document.getElementById("trace-button");
const routeStatus = document.getElementById("route-status");
const routeProgress = document.getElementById("route-progress");
const routePhase = document.getElementById("route-phase");
const routePhases = ["Ship → lighter", "Lighter → landing", "Landing → cart", "Cart → shore store"];
traceButton.addEventListener("click", () => {
routeActive = !routeActive;
traceButton.textContent = routeActive ? "Stop transfer" : "Trace a transfer";
traceButton.classList.toggle("primary", !routeActive);
routeLine.visible = routeActive;
routeCask.visible = routeActive;
routeStatus.classList.toggle("visible", routeActive);
if (!routeActive) {
routeTime = 0;
routeProgress.style.width = "0%";
}
});
// Custom orbit, pan and zoom — no external controls module.
let pointerState = null;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
pointerState = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
button: event.button,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerState || pointerState.id !== event.pointerId) return;
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 1) pointerState.moved = true;
if (pointerState.button === 2 || event.shiftKey) {
const scale = orbit.distance * .00125;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.z += dy * scale;
} else {
orbit.yaw -= dx * .006;
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch + dy * .004, .25, 1.12);
}
updateCamera();
});
function endPointer(event) {
if (pointerState && pointerState.id === event.pointerId) pointerState = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(orbit.distance * Math.exp(event.deltaY * .001), 24, 60);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("keydown", event => {
const step = 2.5;
if (event.key === "ArrowLeft") orbit.target.x -= step;
if (event.key === "ArrowRight") orbit.target.x += step;
if (event.key === "ArrowUp") orbit.target.z -= step;
if (event.key === "ArrowDown") orbit.target.z += step;
if (event.key === "+" || event.key === "=") orbit.distance = Math.max(24, orbit.distance - 2);
if (event.key === "-") orbit.distance = Math.min(60, orbit.distance + 2);
updateCamera();
});
document.getElementById("zoom-in").addEventListener("click", () => {
orbit.distance = Math.max(24, orbit.distance - 3);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
orbit.distance = Math.min(60, orbit.distance + 3);
updateCamera();
});
document.getElementById("reset-view").addEventListener("click", () => {
orbit.target.copy(defaultOrbit.target);
orbit.yaw = defaultOrbit.yaw;
orbit.pitch = defaultOrbit.pitch;
orbit.distance = defaultOrbit.distance;
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Animation.
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const dt = Math.min(clock.getDelta(), .04);
if (!reducedMotion) {
ship.position.y = .52 + Math.sin(elapsed * .72) * .055;
ship.rotation.z = Math.sin(elapsed * .48) * .009;
lighter.position.y = .62 + Math.sin(elapsed * 1.15 + .9) * .055;
lighter.rotation.z = Math.sin(elapsed * .82) * .013;
workers.forEach((worker, index) => {
const phase = worker.userData.phase;
worker.position.y = worker.userData.baseY + Math.sin(elapsed * 1.3 + phase) * .012;
worker.rotation.z = worker.userData.baseRotation + Math.sin(elapsed * .85 + phase) * .014;
worker.rotation.y = Math.sin(elapsed * .42 + index) * .018;
});
waveMarks.forEach(wave => {
wave.position.x = Math.sin(elapsed * wave.userData.speed + wave.userData.phase) * .16;
wave.position.z = Math.cos(elapsed * wave.userData.speed * .72 + wave.userData.phase) * .07;
wave.material.opacity = .39 + Math.sin(elapsed * .8 + wave.userData.phase) * .09;
});
}
if (routeActive) {
routeTime = (routeTime + dt / 13) % 1;
const point = routeCurve.getPointAt(routeTime);
routeCask.position.copy(point);
routeCask.rotation.y = routeTime * Math.PI * 5;
routeCask.rotation.z = Math.sin(routeTime * Math.PI * 4) * .08;
routeProgress.style.width = `${routeTime * 100}%`;
routePhase.textContent = routePhases[Math.min(3, Math.floor(routeTime * 4))];
}
projectHotspots();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => document.getElementById("loading").classList.add("hidden"));
}
}
animate();
</script>
</body>
</html>
```