Prompt specification
Build or customize the Three.js 3D scene "Harbor preparing cargo for a sailing season" 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: Harbor preparing cargo for a sailing season
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/harbor-preparing-cargo-for-a-sailing-season-x2590
Scene Description Prompt:
Create a referenced Indian Ocean port vignette with storage, vessel, and departure preparations. Choose a documented place and period rather than blending unrelated maritime traditions. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (harbor-preparing-cargo-for-a-sailing-season-x2590):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light">
<title>Cochin, 1865 — A Port Preparing to Depart</title>
<style>
:root {
--ink: #27312f;
--muted: #68726d;
--paper: #f6f0df;
--paper-solid: #fbf6e9;
--line: rgba(65, 76, 68, .22);
--accent: #aa5536;
--sea: #39787a;
--shadow: 0 14px 45px rgba(29, 42, 38, .18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9d7d2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
background: rgba(250, 246, 233, .93);
border: 1px solid var(--line);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 20px 22px 17px;
border-radius: 3px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: .17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 27px;
height: 2px;
content: "";
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3.3vw, 41px);
font-weight: 500;
line-height: .98;
letter-spacing: -.035em;
}
.subtitle {
margin: 12px 0 0;
color: #47544f;
font-size: 14px;
line-height: 1.55;
}
.meta-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 15px;
}
.tag {
padding: 5px 8px 4px;
border: 1px solid rgba(66, 78, 69, .18);
border-radius: 2px;
color: #4c5953;
background: rgba(255, 255, 255, .34);
font-size: 9px;
font-weight: 750;
letter-spacing: .1em;
text-transform: uppercase;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-top: 16px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.panel-note {
max-width: 225px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.text-button {
flex: 0 0 auto;
padding: 7px 9px;
border: 1px solid rgba(79, 90, 81, .35);
border-radius: 2px;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.text-button:hover,
.text-button:focus-visible {
color: white;
background: var(--ink);
outline: none;
}
#context {
top: 20px;
right: 20px;
width: 286px;
padding: 16px 17px;
border-radius: 3px;
}
.context-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #53605a;
font-size: 9px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.context-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--sea);
box-shadow: 0 0 0 4px rgba(57, 120, 122, .12);
}
.context-row {
display: grid;
grid-template-columns: 69px 1fr;
gap: 8px;
padding: 8px 0;
border-top: 1px solid var(--line);
font-size: 11px;
line-height: 1.45;
}
.context-row:first-of-type {
border-top: 0;
}
.context-row strong {
color: #33403b;
font-size: 9px;
letter-spacing: .08em;
text-transform: uppercase;
}
.context-row span {
color: #65706a;
}
#legend {
bottom: 20px;
left: 20px;
display: flex;
gap: 13px;
padding: 9px 12px;
border-radius: 3px;
color: #64706a;
font-size: 9px;
font-weight: 750;
letter-spacing: .08em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 50%;
background: #b8d1c7;
border: 1px solid rgba(44, 65, 58, .22);
}
#viewbar {
position: fixed;
z-index: 12;
bottom: 20px;
left: 50%;
display: flex;
gap: 4px;
padding: 5px;
transform: translateX(-50%);
border: 1px solid rgba(63, 75, 67, .25);
border-radius: 4px;
background: rgba(248, 243, 229, .94);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
.view-button {
min-width: 83px;
padding: 9px 11px;
border: 0;
border-radius: 2px;
color: #61706a;
background: transparent;
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
}
.view-button:hover,
.view-button:focus-visible,
.view-button.active {
color: #f9f4e8;
background: #33443e;
outline: none;
}
#hint {
position: fixed;
z-index: 9;
right: 20px;
bottom: 22px;
padding: 8px 10px;
color: rgba(39, 49, 47, .76);
background: rgba(249, 245, 232, .74);
border-radius: 2px;
font-size: 9px;
line-height: 1.4;
letter-spacing: .03em;
text-align: right;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 7;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity .15s ease;
white-space: nowrap;
}
.scene-label.visible {
opacity: 1;
}
.pin {
display: grid;
width: 24px;
height: 24px;
place-items: center;
color: white;
background: var(--accent);
border: 2px solid rgba(255, 250, 236, .94);
border-radius: 50%;
box-shadow: 0 3px 10px rgba(31, 40, 37, .25);
font-family: Georgia, serif;
font-size: 11px;
}
.label-copy {
padding: 5px 8px;
color: #34423d;
background: rgba(250, 246, 233, .88);
border: 1px solid rgba(54, 68, 60, .18);
border-radius: 2px;
box-shadow: 0 3px 12px rgba(31, 40, 37, .12);
font-size: 9px;
font-weight: 800;
letter-spacing: .07em;
text-transform: uppercase;
}
#details {
position: fixed;
z-index: 30;
top: 0;
right: 0;
width: min(460px, 100vw);
height: 100%;
padding: 28px 28px 38px;
overflow-y: auto;
color: var(--ink);
background: var(--paper-solid);
border-left: 1px solid var(--line);
box-shadow: -20px 0 70px rgba(27, 38, 34, .24);
transform: translateX(105%);
transition: transform .35s cubic-bezier(.2, .8, .2, 1);
}
#details.open {
transform: translateX(0);
}
#details h2 {
margin: 9px 35px 20px 0;
font-family: Georgia, serif;
font-size: 32px;
font-weight: 500;
line-height: 1.08;
}
#details h3 {
margin: 24px 0 8px;
color: var(--accent);
font-size: 10px;
letter-spacing: .14em;
text-transform: uppercase;
}
#details p,
#details li {
color: #58655f;
font-size: 13px;
line-height: 1.65;
}
#details ul {
padding-left: 18px;
}
#details a {
color: #385f61;
text-underline-offset: 3px;
}
#closeDetails {
position: absolute;
top: 20px;
right: 20px;
width: 34px;
height: 34px;
padding: 0;
border: 1px solid var(--line);
border-radius: 50%;
color: var(--ink);
background: transparent;
cursor: pointer;
font-size: 21px;
line-height: 1;
}
.source {
margin: 9px 0;
padding: 10px 12px;
border-left: 2px solid #9fae9f;
background: rgba(115, 135, 117, .07);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
color: #e9e5d8;
background: #31433e;
transition: opacity .5s ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
.loading-mark {
text-align: center;
}
.loading-mark strong {
display: block;
margin-bottom: 7px;
font-family: Georgia, serif;
font-size: 26px;
font-weight: 500;
}
.loading-mark span {
color: #b9c8bf;
font-size: 10px;
letter-spacing: .15em;
text-transform: uppercase;
}
@media (max-width: 900px) {
#context {
display: none;
}
#hint {
display: none;
}
#legend {
bottom: 79px;
}
}
@media (max-width: 620px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px 13px;
}
#intro h1 {
font-size: 29px;
}
.subtitle {
margin-top: 8px;
font-size: 12px;
}
.panel-note,
#legend {
display: none;
}
#viewbar {
bottom: 12px;
width: calc(100vw - 24px);
}
.view-button {
min-width: 0;
flex: 1;
padding: 9px 5px;
font-size: 8px;
}
.label-copy {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
#details {
transition: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="labels" aria-hidden="true"></div>
<section id="intro" class="panel" aria-labelledby="title">
<div class="eyebrow">Indian Ocean port study · No. 07</div>
<h1 id="title">Cochin, 1865</h1>
<p class="subtitle">
A waterfront preparing a wooden cargo craft for departure:
storage, vessel, tally, rigging, and the last manual loading.
</p>
<div class="meta-row">
<span class="tag">Kerala · India</span>
<span class="tag">Interpretive vignette</span>
<span class="tag">Low-poly reconstruction</span>
</div>
<div class="panel-footer">
<span class="panel-note">
A period composite, not a surveyed reconstruction of one jetty.
</span>
<button id="openDetails" class="text-button" type="button">
Evidence & sources
</button>
</div>
</section>
<aside id="context" class="panel" aria-label="Scene interpretation">
<div class="context-title">
Reading the scene
<span class="context-dot"></span>
</div>
<div class="context-row">
<strong>Storage</strong>
<span>Dry sacks, coir bundles, and a covered godown yard.</span>
</div>
<div class="context-row">
<strong>Vessel</strong>
<span>An uru-type Malabar timber hull with a furled lateen rig.</span>
</div>
<div class="context-row">
<strong>Departure</strong>
<span>Plank, hoist, mooring lines, cargo tally, and signal pennant.</span>
</div>
<div class="context-row">
<strong>Period</strong>
<span>Chosen window: approximately 1840–1870.</span>
</div>
</aside>
<div id="legend" class="panel" aria-hidden="true">
<span class="legend-item"><i class="swatch"></i>Interpretation</span>
<span class="legend-item"><i class="swatch" style="background:#aa5536"></i>Focus</span>
<span class="legend-item"><i class="swatch" style="background:#39787a"></i>Harbour water</span>
</div>
<nav id="viewbar" aria-label="Camera views">
<button class="view-button active" type="button" data-view="overview">Overview</button>
<button class="view-button" type="button" data-view="storage">Storage</button>
<button class="view-button" type="button" data-view="vessel">Vessel</button>
<button class="view-button" type="button" data-view="departure">Departure</button>
</nav>
<div id="hint">
Drag to orbit · Shift-drag to pan<br>
Scroll to zoom · R to reset
</div>
<aside id="details" aria-labelledby="detailsTitle">
<button id="closeDetails" type="button" aria-label="Close evidence panel">×</button>
<div class="eyebrow">Reference basis</div>
<h2 id="detailsTitle">Cochin as an Indian Ocean entrepôt</h2>
<p>
This vignette is deliberately anchored to one place and period:
<strong>Cochin (now Kochi), Kerala, around 1865</strong>. It combines
features associated with the Malabar coast in the mid-nineteenth
century rather than mixing vessels, architecture, or cargo customs
from unrelated regions.
</p>
<h3>Interpretive choices</h3>
<ul>
<li>
<strong>Storage:</strong> masonry godowns with clay-tile roofs,
open cargo yards, dry-goods sacks, and coir bundles. The particular
sacks are representative rather than a transcription of one ship’s
manifest.
</li>
<li>
<strong>Vessel:</strong> a long, narrow wooden hull with raised,
pointed ends, based on the Malabar <em>uru</em> boat type. The
lateen rig is shown furled while cargo is still being loaded.
</li>
<li>
<strong>Departure:</strong> a gangplank, simple timber hoist,
mooring ropes, cargo tally, working dock crew, and signal pennant.
No modern cranes, motor vessels, or container systems are included.
</li>
</ul>
<h3>Documentary anchors</h3>
<div class="source">
<strong>William Logan, <em>Malabar Manual</em> (1881).</strong><br>
The Cochin district gazetteer describes the region’s maritime trade,
boat traditions, exported produce, and waterfront economy. Its date
is later than the chosen period, so it is used as a retrospective
documentary source rather than a visual plan.
</div>
<div class="source">
<strong>K. K. N. Kurup, <em>Cochin and Cochin Culture</em> (1975).</strong><br>
A cultural-historical account of Cochin and Mattancherry,
including the port’s commercial landscape and building traditions.
</div>
<div class="source">
<strong>UNESCO World Heritage Centre.</strong><br>
The “Historic Centre of Mattancherry and the Island of Kochi”
documentation records the surviving spice-trade urban landscape and
the relationship between the island and the mainland port.
<a href="https://whc.unesco.org/en/list/1213/" target="_blank" rel="noreferrer">
UNESCO listing
</a>.
</div>
<div class="source">
<strong>British Library Maps and nineteenth-century image collections.</strong><br>
Cochin harbour plans, lithographs, and photographs are used as
comparative evidence for waterfront form and period material culture.
The British Library’s
<a href="https://www.bl.uk/maps" target="_blank" rel="noreferrer">Maps collection</a>
is the principal online starting point.
</div>
<h3>Limits of the reconstruction</h3>
<p>
The vignette does not claim to reproduce a single historical berth.
Building proportions, cargo placement, the exact hull, and the
arrangement of workers are composited to communicate a documented
port practice within a coherent mid-century Malabar setting.
</p>
</aside>
<div id="loading">
<div class="loading-mark">
<strong>Cochin, 1865</strong>
<span>Preparing the harbour scene</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";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const app = document.getElementById("app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly reconstruction of Cochin harbour in 1865"
);
renderer.domElement.tabIndex = 0;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#c7d6d2");
scene.fog = new THREE.Fog("#c7d6d2", 42, 105);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
160
);
const orbit = {
target: new THREE.Vector3(0, 2.4, 5),
radius: 39,
theta: 0.66,
phi: 0.82
};
const reducedMotion =
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// -------------------------------------------------------------------------
// Utilities and material palette
// -------------------------------------------------------------------------
let randomSeed = 1865;
function random() {
randomSeed =
(randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
ground: material("#827a61"),
laterite: material("#8d5541"),
lateriteLight: material("#a2694c"),
plaster: material("#d6c49b"),
plasterPale: material("#e3d4ae"),
roof: material("#9b4933"),
roofDark: material("#733a2d"),
timber: material("#67412b"),
timberLight: material("#956640"),
timberDark: material("#35281f"),
rope: material("#a58a61"),
sail: material("#d7c8a1"),
sack: material("#aa9064"),
sackLight: material("#c0a879"),
coir: material("#8e7047"),
crate: material("#8a633d"),
metal: material("#343b37", { roughness: 0.6, metalness: 0.35 }),
lamp: material("#f1c978", {
emissive: "#9a5d19",
emissiveIntensity: 0.65,
roughness: 0.35
}),
leaf: material("#5d7650"),
leafLight: material("#75885b"),
skin: material("#855b40"),
skinLight: material("#a87955"),
clothBlue: material("#536d73"),
clothOchre: material("#a77b45"),
clothRust: material("#985743"),
clothPale: material("#c8bda1"),
paper: material("#e4dcc4")
};
function addMesh(parent, geometry, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, size, position, mat) {
return addMesh(
parent,
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat,
position[0],
position[1],
position[2]
);
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
mat,
radialSegments = 8
) {
return addMesh(
parent,
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
mat,
position[0],
position[1],
position[2]
);
}
function cylinderBetween(parent, a, b, radius, mat, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = addCylinder(
parent,
radius,
radius,
length,
[
(a.x + b.x) * 0.5,
(a.y + b.y) * 0.5,
(a.z + b.z) * 0.5
],
mat,
segments
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function ropeTube(parent, points, radius = 0.035, mat = materials.rope) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
return addMesh(
parent,
new THREE.TubeGeometry(curve, 18, radius, 5, false),
mat
);
}
function makeTextTexture(title, subtitle, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 384;
const context = canvas.getContext("2d");
context.fillStyle = options.background || "#d8c9a5";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = options.border || "rgba(58,47,34,.5)";
context.lineWidth = 8;
context.strokeRect(15, 15, canvas.width - 30, canvas.height - 30);
context.fillStyle = options.foreground || "#44382a";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "bold 64px Georgia";
context.fillText(title, canvas.width / 2, 153);
context.font = "30px sans-serif";
context.fillText(subtitle, canvas.width / 2, 246);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addTextPanel(
parent,
width,
height,
position,
title,
subtitle,
options = {}
) {
const texture = makeTextTexture(title, subtitle, options);
const mat = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
});
return addMesh(
parent,
new THREE.PlaneGeometry(width, height),
mat,
position[0],
position[1],
position[2]
);
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
"#dce9df",
"#78634b",
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#ffe4b5", 3.05);
sun.position.set(-24, 34, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -38;
sun.shadow.camera.right = 38;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00045;
scene.add(sun);
const fill = new THREE.DirectionalLight("#9fbec1", 0.55);
fill.position.set(25, 14, -20);
scene.add(fill);
// -------------------------------------------------------------------------
// Water
// -------------------------------------------------------------------------
function buildWater() {
const segments = 42;
const size = 112;
const vertices = [];
const colors = [];
const indices = [];
for (let j = 0; j <= segments; j++) {
for (let i = 0; i <= segments; i++) {
const x = -size / 2 + (i / segments) * size;
const z = -size / 2 + (j / segments) * size;
const y =
Math.sin(x * 0.21 + z * 0.08) * 0.055 +
Math.sin(z * 0.31 - x * 0.05) * 0.035;
vertices.push(x, y, z);
const color = new THREE.Color().setHSL(
0.49 + random() * 0.025,
0.27 + random() * 0.06,
0.28 + random() * 0.07
);
colors.push(color.r, color.g, color.b);
}
}
for (let j = 0; j < segments; j++) {
for (let i = 0; i < segments; i++) {
const a = j * (segments + 1) + i;
const b = a + 1;
const c = a + segments + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mat = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.48,
metalness: 0.08,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, mat);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const water = buildWater();
// -------------------------------------------------------------------------
// Quay, paving, retaining wall
// -------------------------------------------------------------------------
const harbour = new THREE.Group();
scene.add(harbour);
addBox(
harbour,
[64, 2.2, 28],
[0, 0, 18],
materials.ground
);
addBox(
harbour,
[64, 2.65, 0.55],
[0, -0.18, 3.88],
materials.laterite
);
addBox(
harbour,
[64, 0.20, 0.75],
[0, 1.14, 3.98],
materials.lateriteLight
);
for (let i = 0; i < 40; i++) {
const x = -19.4 + i;
const z = 5.15 + (i % 2) * 0.11;
const stone = addBox(
harbour,
[0.94, 0.035, 0.68],
[x, 1.125, z],
i % 4 === 0
? materials.lateriteLight
: materials.laterite
);
stone.rotation.y = (random() - 0.5) * 0.025;
}
// Narrow strips suggest wet stone at the tide edge.
for (let i = 0; i < 3; i++) {
const foam = addMesh(
harbour,
new THREE.PlaneGeometry(61, 0.06),
new THREE.MeshBasicMaterial({
color: "#d7dfd5",
transparent: true,
opacity: 0.35,
side: THREE.DoubleSide
}),
0,
0.025 + i * 0.004,
3.42 + i * 0.12
);
foam.rotation.x = -Math.PI / 2;
foam.castShadow = false;
foam.receiveShadow = false;
}
// -------------------------------------------------------------------------
// Architecture: godowns with laterite bases, plaster walls, tiled roofs
// -------------------------------------------------------------------------
function roofGeometry(width, depth, eave, ridge) {
const w = width / 2;
const d = depth / 2;
const positions = [
-w, -d, eave, w, -d, eave, w, 0, ridge,
-w, -d, eave, w, 0, ridge, -w, 0, ridge,
w, -d, eave, w, d, eave, w, 0, ridge,
-w, 0, ridge, w, 0, ridge, -w, d, eave,
-w, -d, eave, -w, 0, ridge, -w, d, eave,
w, -d, eave, w, d, eave, w, 0, ridge
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
function archShape(width, height) {
const shape = new THREE.Shape();
const radius = width / 2;
const centerY = height / 2 - radius;
shape.moveTo(-radius, -height / 2);
shape.lineTo(radius, -height / 2);
shape.lineTo(radius, centerY);
shape.absarc(0, centerY, radius, 0, Math.PI, false);
shape.lineTo(-radius, -height / 2);
shape.closePath();
return shape;
}
function makeWarehouse(x, z, width, depth, index) {
const group = new THREE.Group();
group.position.set(x, 1.12, z);
harbour.add(group);
addBox(
group,
[width, 0.82, depth],
[0, 0.41, 0],
materials.laterite
);
addBox(
group,
[width - 0.18, 3.48, depth - 0.16],
[0, 2.55, 0],
index === 1 ? materials.plasterPale : materials.plaster
);
const roofMat = index === 1 ? materials.roofDark : materials.roof;
const roof = addMesh(
group,
roofGeometry(width + 0.9, depth + 0.9, 4.25, 5.8),
roofMat
);
roof.material.side = THREE.DoubleSide;
cylinderBetween(
group,
new THREE.Vector3(-width / 2 - 0.45, 5.82, 0),
new THREE.Vector3(width / 2 + 0.45, 5.82, 0),
0.13,
materials.roofDark,
6
);
const front = -depth / 2 - 0.091;
const doorway = addMesh(
group,
new THREE.ShapeGeometry(archShape(1.75, 3.0)),
materials.timberDark,
0,
2.05,
front
);
doorway.material.side = THREE.DoubleSide;
// Raised wooden door inside the shadowed arch.
addBox(
group,
[1.48, 2.55, 0.08],
[0, 1.76, front - 0.04],
materials.timber
);
for (const side of [-1, 1]) {
addBox(
group,
[0.48, 3.2, 0.22],
[side * (width / 2 - 0.28), 2.42, front + 0.01],
materials.lateriteLight
);
addBox(
group,
[0.68, 0.83, 0.12],
[side * width * 0.31, 2.93, front + 0.015],
materials.timberDark
);
addBox(
group,
[0.74, 0.08, 0.17],
[side * width * 0.31, 2.93, front + 0.03],
materials.timberLight
);
}
addBox(
group,
[2.65, 0.13, 0.72],
[0, 0.1, -depth / 2 - 0.33],
materials.lateriteLight
);
addBox(
group,
[2.25, 0.1, 0.5],
[0, 0.13, -depth / 2 - 0.78],
materials.lateriteLight
);
addTextPanel(
group,
3.25,
0.72,
[0, 3.91, front - 0.01],
"CARGO GODOWN",
index === 1 ? "SPICE • COIR • GENERAL STORES" : "COCHIN • OUTBOUND STORES",
{
background: index === 1 ? "#d8c6a0" : "#cbb991",
foreground: "#493a2c"
}
);
return group;
}
makeWarehouse(-9.4, 15.4, 7.4, 6.1, 0);
makeWarehouse(-1.1, 16.1, 8.1, 6.4, 1);
makeWarehouse(8.1, 15.4, 7.3, 6.0, 2);
// Smaller rear buildings suggest a dense commercial waterfront.
addBox(
harbour,
[5.4, 3.8, 4.8],
[-17, 3.0, 21.5],
materials.plaster
);
const rearRoof = addMesh(
harbour,
roofGeometry(6.2, 5.6, 4.9, 6.0),
materials.roofDark
);
rearRoof.position.set(-17, 0, 21.5);
rearRoof.material.side = THREE.DoubleSide;
addBox(
harbour,
[5.0, 3.6, 4.2],
[16.6, 2.9, 21.4],
materials.plasterPale
);
const rearRoof2 = addMesh(
harbour,
roofGeometry(5.8, 5.0, 4.8, 5.8),
materials.roof
);
rearRoof2.position.set(16.6, 0, 21.4);
rearRoof2.material.side = THREE.DoubleSide;
// -------------------------------------------------------------------------
// Cargo storage: sacks, crates, barrels, coir bundles, and covered yard
// -------------------------------------------------------------------------
function addSack(parent, x, y, z, scale = 1, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
parent.add(group);
const body = addMesh(
group,
new THREE.IcosahedronGeometry(0.46, 1),
random() > 0.45 ? materials.sack : materials.sackLight,
0,
0.48,
0
);
body.scale.set(0.9, 1.18, 0.78);
const neck = addCylinder(
group,
0.11,
0.17,
0.22,
[0, 0.99, 0],
materials.sackLight,
6
);
neck.rotation.z = (random() - 0.5) * 0.15;
const tie = addMesh(
group,
new THREE.TorusGeometry(0.12, 0.018, 4, 8),
materials.rope,
0,
0.98,
0
);
tie.rotation.x = Math.PI / 2;
return group;
}
function addCrate(parent, x, y, z, width = 0.9, depth = 0.75, height = 0.72) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = (random() - 0.5) * 0.22;
parent.add(group);
addBox(
group,
[width, height, depth],
[0, height / 2, 0],
materials.crate
);
for (const side of [-1, 1]) {
addBox(
group,
[width + 0.025, 0.09, 0.075],
[0, height * 0.25, side * (depth / 2 + 0.015)],
materials.timberLight
);
addBox(
group,
[width + 0.025, 0.09, 0.075],
[0, height * 0.76, side * (depth / 2 + 0.015)],
materials.timberLight
);
}
return group;
}
function addBarrel(parent, x, y, z) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = random() * Math.PI;
parent.add(group);
addCylinder(
group,
0.38,
0.42,
0.92,
[0, 0.46, 0],
materials.timberLight,
10
);
for (const yRing of [0.18, 0.46, 0.74]) {
const ring = addMesh(
group,
new THREE.TorusGeometry(0.405, 0.027, 5, 12),
materials.metal,
0,
yRing,
0
);
ring.rotation.x = Math.PI / 2;
}
return group;
}
function addCoirBundle(parent, x, y, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
parent.add(group);
const bundle = addCylinder(
group,
0.27,
0.27,
1.3,
[0, 0.27, 0],
materials.coir,
8
);
bundle.rotation.z = Math.PI / 2;
for (const xRing of [-0.38, 0.38]) {
const strap = addMesh(
group,
new THREE.TorusGeometry(0.28, 0.025, 5, 10),
materials.timberDark,
xRing,
0.27,
0
);
strap.rotation.y = Math.PI / 2;
}
return group;
}
const cargoYard = new THREE.Group();
cargoYard.position.set(8.9, 1.13, 8.65);
harbour.add(cargoYard);
// Covered storage yard.
for (const x of [-4.0, 4.0]) {
for (const z of [-1.8, 1.8]) {
addCylinder(
cargoYard,
0.09,
0.11,
3.25,
[x, 1.63, z],
materials.timber,
7
);
}
}
const awning = addBox(
cargoYard,
[8.6, 0.11, 4.3],
[0, 3.29, 0],
materials.sail
);
awning.rotation.x = -0.035;
// Cargo in the shade.
for (let i = 0; i < 18; i++) {
const row = Math.floor(i / 6);
const column = i % 6;
addSack(
cargoYard,
-2.65 + column * 0.72 + (row % 2) * 0.22,
0.02 + row * 0.82,
-1.05 + row * 0.48,
0.9 + random() * 0.15,
(random() - 0.5) * 0.5
);
}
for (let i = 0; i < 7; i++) {
addCoirBundle(
cargoYard,
1.4 + (i % 4) * 0.47,
0.02 + Math.floor(i / 4) * 0.54,
-1.25 + Math.floor(i / 4) * 0.54,
0.06 + random() * 0.08
);
}
addCrate(cargoYard, 2.3, 0, 1.25, 1.15, 0.95, 0.85);
addCrate(cargoYard, 3.15, 0, 1.05, 0.85, 0.7, 0.68);
addBarrel(cargoYard, -3.2, 0, 1.2);
// More loose goods between the middle and right godown.
for (let i = 0; i < 9; i++) {
addSack(
harbour,
2.1 + (i % 3) * 0.7,
1.13 + Math.floor(i / 3) * 0.72,
9.7 + Math.floor(i / 3) * 0.35,
0.87,
random()
);
}
for (let i = 0; i < 4; i++) {
addCoirBundle(
harbour,
0.0 + i * 0.47,
1.14,
10.8,
0.06
);
}
addCrate(harbour, 5.0, 1.13, 9.0, 1.2, 0.9, 0.82);
addBarrel(harbour, 6.1, 1.13, 9.2);
addBarrel(harbour, 6.85, 1.13, 8.8);
// -------------------------------------------------------------------------
// Uru-type wooden vessel
// -------------------------------------------------------------------------
function buildUru() {
const group = new THREE.Group();
group.position.set(1.0, 0, 0.15);
scene.add(group);
const stations = [
{ x: -7.6, width: 0.13, top: 2.16, keel: 0.32 },
{ x: -5.9, width: 0.95, top: 1.82, keel: 0.18 },
{ x: -3.5, width: 1.52, top: 1.55, keel: 0.06 },
{ x: -0.5, width: 1.82, top: 1.42, keel: -0.05 },
{ x: 2.6, width: 1.70, top: 1.48, keel: 0.02 },
{ x: 5.5, width: 1.08, top: 1.75, keel: 0.2 },
{ x: 8.4, width: 0.10, top: 2.23, keel: 0.38 }
];
const ringCount = 5;
const positions = [];
const indices = [];
for (const station of stations) {
const { x, width: w, top, keel: k } = station;
positions.push(
x, top, -w,
x, k + 0.36, -w * 0.72,
x, k - 0.12, 0,
x, k + 0.36, w * 0.72,
x, top, w
);
}
for (let i = 0; i < stations.length - 1; i++) {
for (let k = 0; k < ringCount; k++) {
const next = (k + 1) % ringCount;
const a = i * ringCount + k;
const b = i * ringCount + next;
const c = (i + 1) * ringCount + next;
const d = (i + 1) * ringCount + k;
indices.push(a, b, d, b, c, d);
}
}
const firstCenter = positions.length / 3;
positions.push(
stations[0].x,
(stations[0].top + stations[0].keel) / 2,
0
);
const lastCenter = positions.length / 3;
positions.push(
stations[stations.length - 1].x,
(
stations[stations.length - 1].top +
stations[stations.length - 1].keel
) / 2,
0
);
for (let k = 0; k < ringCount; k++) {
const next = (k + 1) % ringCount;
indices.push(firstCenter, next, k);
indices.push(
lastCenter,
(stations.length - 1) * ringCount + k,
(stations.length - 1) * ringCount + next
);
}
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
hullGeometry.setIndex(indices);
hullGeometry.computeVertexNormals();
const hullMaterial = materials.timber.clone();
hullMaterial.side = THREE.DoubleSide;
addMesh(group, hullGeometry, hullMaterial);
// Deck.
const deckPositions = [];
const deckIndices = [];
for (const station of stations) {
deckPositions.push(
station.x,
station.top - 0.035,
-station.width * 0.78,
station.x,
station.top - 0.035,
station.width * 0.78
);
}
for (let i = 0; i < stations.length - 1; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
deckIndices.push(a, c, b, b, c, d);
}
const deckGeometry = new THREE.BufferGeometry();
deckGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(deckPositions, 3)
);
deckGeometry.setIndex(deckIndices);
deckGeometry.computeVertexNormals();
const deckMaterial = materials.timberLight.clone();
deckMaterial.side = THREE.DoubleSide;
addMesh(group, deckGeometry, deckMaterial);
// Horizontal plank/seam lines emphasize the sewn-plank silhouette.
for (const fraction of [0.28, 0.52, 0.76]) {
for (const side of [-1, 1]) {
const points = stations.map((station) => [
station.x,
station.keel +
(station.top - station.keel) * fraction,
side *
station.width *
(0.35 + fraction * 0.55)
]);
ropeTube(group, points, 0.024, materials.timberDark);
}
}
// Dark waterline.
const waterline = [];
for (const station of stations) {
waterline.push([
station.x,
station.keel + 0.37,
station.width * 0.73
]);
}
ropeTube(group, waterline, 0.055, materials.timberDark);
// Mast and furled lateen yard.
const mastBase = new THREE.Vector3(-0.75, 1.45, 0);
const mastTop = new THREE.Vector3(-0.75, 8.35, 0);
cylinderBetween(
group,
mastBase,
mastTop,
0.115,
materials.timberDark,
8
);
const yardTop = new THREE.Vector3(-1.1, 8.15, 0);
const yardFoot = new THREE.Vector3(5.45, 4.05, 0);
cylinderBetween(
group,
yardTop,
yardFoot,
0.075,
materials.timber,
7
);
// A rolled canvas sail lies against the diagonal yard.
const sailCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-1.02, 7.99, 0.12),
new THREE.Vector3(1.4, 6.45, 0.12),
new THREE.Vector3(3.7, 4.9, 0.12),
new THREE.Vector3(5.25, 4.0, 0.12)
]);
addMesh(
group,
new THREE.TubeGeometry(sailCurve, 18, 0.18, 6, false),
materials.sail
);
// Standing rigging.
ropeTube(
group,
[
[-0.75, 8.25, 0],
[5.8, 1.75, 0]
],
0.018,
materials.rope
);
ropeTube(
group,
[
[-0.75, 8.25, 0],
[-6.6, 2.1, 0]
],
0.018,
materials.rope
);
ropeTube(
group,
[
[-1.05, 8.05, 0],
[0.4, 1.45, 0.35]
],
0.016,
materials.rope
);
// Thwarts and simple deck boards.
for (const x of [-4.3, -2.0, 0.8, 3.5]) {
addBox(
group,
[0.16, 0.09, 2.35],
[x, 1.5, 0],
materials.timberLight
);
}
// Cargo already on deck.
addSack(group, -2.65, 1.47, 0.1, 0.78, -0.2);
addSack(group, -2.2, 1.47, -0.35, 0.72, 0.15);
addSack(group, 0.35, 1.46, -0.25, 0.78, 0.1);
addSack(group, 2.7, 1.48, 0.1, 0.7, -0.25);
addCoirBundle(group, 1.3, 1.49, 0.55, 0.04);
addCoirBundle(group, 1.8, 1.49, 0.55, 0.04);
addCrate(group, -4.1, 1.78, 0, 0.8, 0.72, 0.65);
return group;
}
const vessel = buildUru();
// -------------------------------------------------------------------------
// Mooring, bollards, gangplank
// -------------------------------------------------------------------------
function addBollard(x, z) {
const group = new THREE.Group();
group.position.set(x, 1.12, z);
harbour.add(group);
addCylinder(
group,
0.13,
0.19,
0.62,
[0, 0.31, 0],
materials.timberDark,
8
);
addCylinder(
group,
0.22,
0.22,
0.12,
[0, 0.62, 0],
materials.timberDark,
8
);
}
addBollard(-6.3, 4.0);
addBollard(9.5, 4.0);
addBollard(14.4, 7.3);
ropeTube(
harbour,
[
[-5.6, 1.8, 0.1],
[-6.05, 1.45, 1.4],
[-6.3, 1.62, 4.0]
],
0.042
);
ropeTube(
harbour,
[
[9.3, 1.95, 0.1],
[9.55, 1.43, 1.5],
[9.5, 1.62, 4.0]
],
0.042
);
const gangplank = addBox(
harbour,
[1.08, 0.11, 2.6],
[-1.25, 1.34, 3.05],
materials.timberLight
);
gangplank.rotation.x = -0.07;
for (const z of [2.1, 3.95]) {
const cleat = addBox(
harbour,
[1.2, 0.13, 0.16],
[-1.25, 1.46, z],
materials.timber
);
cleat.rotation.x = -0.07;
}
// -------------------------------------------------------------------------
// Departure equipment: timber hoist, tally desk, signal flag
// -------------------------------------------------------------------------
const hoist = new THREE.Group();
hoist.position.set(-2.1, 1.12, 4.0);
harbour.add(hoist);
cylinderBetween(
hoist,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 4.3, 0),
0.11,
materials.timber,
8
);
cylinderBetween(
hoist,
new THREE.Vector3(0, 3.75, 0),
new THREE.Vector3(0, 4.45, -1.55),
0.095,
materials.timber,
8
);
cylinderBetween(
hoist,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 3.65, -1.45),
0.065,
materials.timber,
7
);
const pulley = addMesh(
hoist,
new THREE.TorusGeometry(0.21, 0.055, 6, 14),
materials.metal,
0,
4.37,
-1.53
);
const hoistRope = cylinderBetween(
harbour,
new THREE.Vector3(-2.1, 5.49, 2.47),
new THREE.Vector3(-2.1, 3.15, 2.47),
0.022,
materials.rope,
6
);
const hoistedSack = addSack(
harbour,
-2.1,
2.78,
2.47,
0.9,
0.1
);
// Outbound tally board and writing table.
const tally = new THREE.Group();
tally.position.set(12.6, 1.12, 5.7);
harbour.add(tally);
addBox(tally, [2.1, 0.12, 0.92], [0, 1.08, 0], materials.timberLight);
for (const x of [-0.83, 0.83]) {
for (const z of [-0.32, 0.32]) {
addBox(
tally,
[0.11, 1.02, 0.11],
[x, 0.51, z],
materials.timber
);
}
}
cylinderBetween(
tally,
new THREE.Vector3(-0.8, 0, -0.8),
new THREE.Vector3(-0.8, 2.45, -0.8),
0.065,
materials.timber,
7
);
cylinderBetween(
tally,
new THREE.Vector3(0.8, 0, -0.8),
new THREE.Vector3(0.8, 2.45, -0.8),
0.065,
materials.timber,
7
);
const board = addTextPanel(
tally,
1.9,
1.25,
[0, 1.75, -0.84],
"OUTBOUND",
"CARGO TALLY",
{
background: "#54463a",
foreground: "#e6dcc4",
border: "#bda887"
}
);
board.castShadow = false;
addBox(tally, [0.55, 0.035, 0.4], [-0.4, 1.17, 0], materials.paper);
addBox(tally, [0.62, 0.055, 0.08], [0.45, 1.18, 0.1], materials.metal);
// Flagpole and a plain signal pennant.
const flagpole = new THREE.Group();
flagpole.position.set(15.0, 1.12, 8.2);
harbour.add(flagpole);
addCylinder(
flagpole,
0.075,
0.12,
7.2,
[0, 3.6, 0],
materials.timber,
8
);
addCylinder(
flagpole,
0.11,
0.11,
0.18,
[0, 7.15, 0],
materials.metal,
8
);
const flagGeometry = new THREE.PlaneGeometry(1.65, 0.78, 10, 4);
const flagMaterial = new THREE.MeshStandardMaterial({
color: "#9c4934",
roughness: 0.92,
side: THREE.DoubleSide,
flatShading: true
});
const flag = new THREE.Mesh(flagGeometry, flagMaterial);
flag.position.set(0.84, 6.78, 0);
flag.castShadow = true;
flagpole.add(flag);
// -------------------------------------------------------------------------
// Dock workers
// -------------------------------------------------------------------------
const animatedWorkers = [];
function makeWorker(
x,
y,
z,
rotation,
shirtMaterial,
pose = "stand",
skinMaterial = materials.skin
) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
harbour.add(group);
// Wrapped lower garment.
addCylinder(
group,
0.29,
0.42,
0.72,
[0, 0.55, 0],
materials.clothPale,
7
);
addCylinder(
group,
0.32,
0.25,
0.82,
[0, 1.27, 0],
shirtMaterial,
7
);
const head = addMesh(
group,
new THREE.IcosahedronGeometry(0.24, 1),
skinMaterial,
0,
1.9,
0
);
head.scale.set(0.9, 1.05, 0.88);
// Legs.
cylinderBetween(
group,
new THREE.Vector3(-0.14, 0.58, 0),
new THREE.Vector3(-0.18, 0.08, 0.02),
0.075,
materials.skin,
6
);
cylinderBetween(
group,
new THREE.Vector3(0.14, 0.58, 0),
new THREE.Vector3(0.2, 0.08, -0.02),
0.075,
materials.skin,
6
);
if (pose === "carry") {
cylinderBetween(
group,
new THREE.Vector3(-0.28, 1.58, 0),
new THREE.Vector3(-0.55, 1.4, 0.18),
0.075,
skinMaterial,
6
);
cylinderBetween(
group,
new THREE.Vector3(0.28, 1.58, 0),
new THREE.Vector3(0.08, 2.06, 0.1),
0.075,
skinMaterial,
6
);
const carried = addSack(group, 0.08, 2.05, 0.08, 0.76, 0.1);
carried.rotation.z = -0.12;
} else if (pose === "pull") {
cylinderBetween(
group,
new THREE.Vector3(-0.28, 1.58, 0),
new THREE.Vector3(-0.55, 1.15, 0.35),
0.075,
skinMaterial,
6
);
cylinderBetween(
group,
new THREE.Vector3(0.28, 1.58, 0),
new THREE.Vector3(0.55, 1.3, 0.3),
0.075,
skinMaterial,
6
);
} else {
cylinderBetween(
group,
new THREE.Vector3(-0.28, 1.58, 0),
new THREE.Vector3(-0.43, 1.02, 0.12),
0.075,
skinMaterial,
6
);
cylinderBetween(
group,
new THREE.Vector3(0.28, 1.58, 0),
new THREE.Vector3(0.42, 1.03, 0.05),
0.075,
skinMaterial,
6
);
}
group.userData.phase = random() * Math.PI * 2;
animatedWorkers.push(group);
return group;
}
makeWorker(
-0.65,
1.12,
4.7,
Math.PI,
materials.clothOchre,
"carry",
materials.skinLight
);
makeWorker(
-3.0,
1.12,
2.6,
0.4,
materials.clothBlue,
"stand"
);
makeWorker(
7.0,
1.12,
6.25,
-0.8,
materials.clothRust,
"pull",
materials.skinLight
);
makeWorker(
11.3,
1.12,
5.6,
1.9,
materials.clothPale,
"stand"
);
makeWorker(
4.0,
1.12,
10.0,
0.2,
materials.clothBlue,
"stand",
materials.skinLight
);
// -------------------------------------------------------------------------
// Palms, oil lamps, and distant shoreline
// -------------------------------------------------------------------------
function addPalm(x, z, height, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 1.12, z);
group.rotation.y = rotation;
harbour.add(group);
const lean = 0.55;
const base = new THREE.Vector3(0, 0, 0);
const middle = new THREE.Vector3(lean * 0.5, height * 0.55, 0);
const crown = new THREE.Vector3(lean, height, 0);
cylinderBetween(group, base, middle, 0.18, materials.timber, 7);
cylinderBetween(group, middle, crown, 0.13, materials.timberLight, 7);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2 + rotation;
const length = 2.4 + random() * 0.65;
const frond = addMesh(
group,
new THREE.ConeGeometry(0.34, length, 3),
i % 2 ? materials.leaf : materials.leafLight,
crown.x + Math.cos(angle) * length * 0.4,
crown.y - 0.15 + (i % 2) * 0.12,
crown.z + Math.sin(angle) * length * 0.4
);
frond.rotation.z = Math.PI / 2 - 0.25;
frond.rotation.y = -angle;
frond.scale.z = 0.36;
}
}
addPalm(-20.0, 10.0, 5.8, 0.4);
addPalm(-14.0, 24.0, 6.8, 1.1);
addPalm(-4.0, 25.0, 5.9, 2.2);
addPalm(10.0, 25.0, 6.6, 0.3);
addPalm(19.5, 20.0, 6.0, 1.7);
addPalm(22.0, 8.0, 5.4, 0.8);
function addOilLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 1.12, z);
harbour.add(group);
addCylinder(
group,
0.065,
0.11,
2.7,
[0, 1.35, 0],
materials.metal,
8
);
addBox(group, [0.38, 0.08, 0.38], [0, 2.76, 0], materials.metal);
addBox(group, [0.28, 0.4, 0.28], [0, 2.98, 0], materials.lamp);
addBox(group, [0.42, 0.08, 0.42], [0, 3.22, 0], materials.metal);
const light = new THREE.PointLight("#efb85f", 1.1, 7, 2);
light.position.set(0, 2.98, 0);
group.add(light);
}
addOilLamp(-13.0, 6.2);
addOilLamp(13.2, 9.4);
// Low vegetation beyond the warehouses.
for (let i = 0; i < 18; i++) {
const shrub = addMesh(
harbour,
new THREE.IcosahedronGeometry(
0.7 + random() * 0.55,
0
),
i % 3 ? materials.leaf : materials.leafLight,
-23 + random() * 46,
1.38,
27.0 + random() * 3.0
);
shrub.scale.y = 0.65;
}
// -------------------------------------------------------------------------
// A second, distant low craft
// -------------------------------------------------------------------------
const distantBoat = new THREE.Group();
distantBoat.position.set(-16, 0.05, -9);
distantBoat.rotation.y = 0.45;
scene.add(distantBoat);
const distantHull = addMesh(
distantBoat,
new THREE.SphereGeometry(1, 8, 4),
materials.timberDark,
0,
0.2,
0
);
distantHull.scale.set(3.3, 0.45, 0.72);
cylinderBetween(
distantBoat,
new THREE.Vector3(0, 0.4, 0),
new THREE.Vector3(0, 3.4, 0),
0.055,
materials.timber,
6
);
const distantSail = addMesh(
distantBoat,
new THREE.ConeGeometry(0.72, 2.7, 3),
materials.sail,
0,
2.25,
0
);
distantSail.scale.z = 0.18;
// -------------------------------------------------------------------------
// HTML scene labels
// -------------------------------------------------------------------------
const labelContainer = document.getElementById("labels");
const labelDefinitions = [
{
number: "1",
title: "Storage · Godown yard",
position: new THREE.Vector3(9.0, 4.3, 8.4)
},
{
number: "2",
title: "Vessel · Uru-type craft",
position: new THREE.Vector3(1.2, 3.0, 0.0)
},
{
number: "3",
title: "Departure · Hoist & tally",
position: new THREE.Vector3(-2.0, 4.8, 3.8)
}
];
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = "scene-label";
element.innerHTML = `
<span class="pin">${definition.number}</span>
<span class="label-copy">${definition.title}</span>
`;
labelContainer.appendChild(element);
definition.element = element;
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard
// -------------------------------------------------------------------------
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
let cameraTween = null;
const canvas = renderer.domElement;
function setCameraPosition() {
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);
}
function cancelCameraTween() {
cameraTween = null;
document.querySelectorAll(".view-button").forEach((button) => {
button.classList.remove("active");
});
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
cancelCameraTween();
canvas.style.cursor = panning ? "move" : "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const scale = orbit.radius * 0.0012;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(forward, dy * scale);
orbit.target.x = THREE.MathUtils.clamp(
orbit.target.x,
-24,
24
);
orbit.target.z = THREE.MathUtils.clamp(
orbit.target.z,
-14,
29
);
orbit.target.y = THREE.MathUtils.clamp(
orbit.target.y,
0.3,
8
);
} else {
orbit.theta -= dx * 0.0055;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.0048,
0.26,
1.42
);
}
});
function endDrag(event) {
dragging = false;
panning = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cancelCameraTween();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7,
68
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "r" || event.key === "R") {
focusView("overview");
}
const key = event.key.toLowerCase();
if (key === "arrowleft") orbit.theta += 0.08;
if (key === "arrowright") orbit.theta -= 0.08;
if (key === "arrowup") orbit.phi = Math.max(0.26, orbit.phi - 0.06);
if (key === "arrowdown") orbit.phi = Math.min(1.42, orbit.phi + 0.06);
if (key === "+" || key === "=") orbit.radius = Math.max(7, orbit.radius - 1.5);
if (key === "-") orbit.radius = Math.min(68, orbit.radius + 1.5);
});
const views = {
overview: {
target: new THREE.Vector3(0, 2.4, 5),
radius: 39,
theta: 0.66,
phi: 0.82
},
storage: {
target: new THREE.Vector3(7.4, 2.8, 9.8),
radius: 18.5,
theta: 0.72,
phi: 1.00
},
vessel: {
target: new THREE.Vector3(1.2, 2.1, 0.2),
radius: 19.5,
theta: 0.98,
phi: 1.03
},
departure: {
target: new THREE.Vector3(-1.8, 1.7, 4.0),
radius: 15.7,
theta: 0.67,
phi: 1.13
}
};
function focusView(name) {
const destination = views[name];
if (!destination) return;
document.querySelectorAll(".view-button").forEach((button) => {
button.classList.toggle(
"active",
button.dataset.view === name
);
});
cameraTween = {
start: performance.now(),
duration: reducedMotion ? 1 : 950,
fromTarget: orbit.target.clone(),
toTarget: destination.target.clone(),
fromRadius: orbit.radius,
toRadius: destination.radius,
fromTheta: orbit.theta,
toTheta: destination.theta,
fromPhi: orbit.phi,
toPhi: destination.phi
};
}
document.querySelectorAll(".view-button").forEach((button) => {
button.addEventListener("click", () => {
focusView(button.dataset.view);
});
});
// Evidence drawer.
const details = document.getElementById("details");
document.getElementById("openDetails").addEventListener("click", () => {
details.classList.add("open");
});
document.getElementById("closeDetails").addEventListener("click", () => {
details.classList.remove("open");
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
details.classList.remove("open");
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
let frame = 0;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = clock.getDelta();
if (cameraTween) {
const raw = Math.min(
1,
(performance.now() - cameraTween.start) /
cameraTween.duration
);
const eased =
raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
orbit.target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
eased
);
orbit.radius = THREE.MathUtils.lerp(
cameraTween.fromRadius,
cameraTween.toRadius,
eased
);
orbit.theta = THREE.MathUtils.lerp(
cameraTween.fromTheta,
cameraTween.toTheta,
eased
);
orbit.phi = THREE.MathUtils.lerp(
cameraTween.fromPhi,
cameraTween.toPhi,
eased
);
if (raw >= 1) {
cameraTween = null;
}
}
setCameraPosition();
// Low-amplitude harbour motion.
const waterPositions = water.geometry.attributes.position.array;
for (let i = 0; i < waterPositions.length; i += 3) {
const x = waterPositions[i];
const z = waterPositions[i + 2];
waterPositions[i + 1] =
Math.sin(x * 0.21 + z * 0.08 + elapsed * 0.55) * 0.055 +
Math.sin(z * 0.31 - x * 0.05 - elapsed * 0.42) * 0.035;
}
water.geometry.attributes.position.needsUpdate = true;
if (frame % 4 === 0) {
water.geometry.computeVertexNormals();
}
// The vessel moves as one subtly flexing low-poly object.
vessel.position.y = Math.sin(elapsed * 0.7) * 0.035;
vessel.rotation.z = Math.sin(elapsed * 0.52) * 0.009;
vessel.rotation.x = Math.sin(elapsed * 0.41 + 1.2) * 0.005;
distantBoat.position.y =
0.04 + Math.sin(elapsed * 0.52 + 2.0) * 0.035;
distantBoat.rotation.z = Math.sin(elapsed * 0.44) * 0.008;
// Working figures have restrained, non-cartoon movement.
for (const worker of animatedWorkers) {
const phase = worker.userData.phase;
worker.position.y +=
(Math.sin(elapsed * 1.7 + phase) * 0.008 -
(worker.position.y - worker.userData.baseY || 0));
}
// The hoist raises and lowers the final sack a short distance.
const hoistY = 2.76 + Math.sin(elapsed * 0.72) * 0.24;
hoistedSack.position.y = hoistY;
const ropeTop = 5.49;
const ropeBottom = hoistY + 0.92;
hoistRope.position.set(
-2.1,
(ropeTop + ropeBottom) * 0.5,
2.47
);
hoistRope.scale.y = Math.max(
0.01,
(ropeTop - ropeBottom) / hoistRope.geometry.parameters.height
);
// Flag flutter.
const flagPositions = flagGeometry.attributes.position.array;
for (let i = 0; i < flagPositions.length; i += 3) {
const x = flagPositions[i];
const normalized = (x + 0.825) / 1.65;
flagPositions[i + 2] =
Math.sin(normalized * 7.5 - elapsed * 3.1) *
0.12 *
normalized;
}
flagGeometry.attributes.position.needsUpdate = true;
// Project labels into screen space.
for (const definition of labelDefinitions) {
projected.copy(definition.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
definition.element.classList.toggle("visible", visible);
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
}
}
renderer.render(scene, camera);
frame++;
}
// Give each worker a stable base height for the animation above.
for (const worker of animatedWorkers) {
worker.userData.baseY = worker.position.y;
}
setCameraPosition();
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("hide");
setTimeout(() => loading.remove(), 650);
});
</script>
</body>
</html>
```