Prompt specification
Build or customize the Three.js 3D scene "Historic Malacca waterfront transfer platform" 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: Historic Malacca waterfront transfer platform
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/historic-malacca-waterfront-transfer-platform-x2602
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: Historic Malacca waterfront transfer platform. Create a referenced Malacca port vignette with quay, warehouses, and small-boat transfer. Use a specific historical period and show cargo moving between vessels of different sizes.
Working Three.js Starter (historic-malacca-waterfront-transfer-platform-x2602):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Melaka Waterfront — 1891</title>
<style>
:root {
--ink: #f3ead7;
--muted: #c7bda9;
--panel: rgba(19, 31, 32, 0.88);
--line: rgba(235, 217, 178, 0.25);
--gold: #d7ad62;
--teal: #70b7ae;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #71969c;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 50px rgba(8, 18, 20, 0.22);
backdrop-filter: blur(12px);
}
#title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 3px;
}
.eyebrow {
margin: 0 0 9px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.21em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 4vw, 43px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.025em;
}
h1 span {
display: block;
margin-top: 9px;
color: var(--muted);
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#period {
display: inline-flex;
align-items: center;
gap: 8px;
margin: 16px 0 12px;
padding: 7px 10px;
border: 1px solid rgba(215, 173, 98, 0.38);
border-radius: 2px;
color: #efd6a8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#period::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 4px rgba(215, 173, 98, 0.12);
}
#title-card p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#reference-card {
top: 22px;
right: 22px;
width: 280px;
padding: 16px 18px;
border-radius: 3px;
}
#reference-card h2 {
margin: 0 0 8px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#reference-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
#reference-card .fine {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #9fa89e;
font-size: 9px;
}
#hotspots {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.hotspot {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(244, 232, 204, 0.3);
border-radius: 2px;
background: rgba(20, 33, 34, 0.78);
color: #f4ead5;
box-shadow: 0 7px 18px rgba(0, 0, 0, 0.16);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
}
.hotspot::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: rgba(244, 232, 204, 0.55);
}
.hotspot b {
display: grid;
place-items: center;
width: 17px;
height: 17px;
border-radius: 50%;
background: var(--gold);
color: #263031;
font-size: 9px;
}
#controls {
left: 50%;
bottom: 22px;
z-index: 20;
display: flex;
align-items: center;
gap: 5px;
padding: 6px;
border-radius: 3px;
transform: translateX(-50%);
}
button {
appearance: none;
border: 1px solid transparent;
border-radius: 2px;
padding: 9px 13px;
background: transparent;
color: var(--muted);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}
button:hover,
button.active {
border-color: rgba(215, 173, 98, 0.28);
background: rgba(215, 173, 98, 0.11);
color: #f3dfb6;
}
#pause { min-width: 116px; }
#hint {
position: fixed;
left: 22px;
bottom: 22px;
z-index: 8;
color: rgba(245, 238, 218, 0.85);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #233638;
color: #e9d5ad;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 820px) {
#reference-card { display: none; }
#title-card { padding: 16px 18px; }
#title-card p { display: none; }
#period { margin-bottom: 0; }
#hint { display: none; }
#controls { bottom: 12px; max-width: calc(100vw - 20px); }
button { padding: 9px 10px; font-size: 9px; }
#pause { min-width: 96px; }
.hotspot { font-size: 8px; }
}
</style>
</head>
<body>
<div id="stage"></div>
<section id="title-card" class="panel">
<p class="eyebrow">A Port Vignette</p>
<h1>
Melaka
<span>Strait-side cargo transfer</span>
</h1>
<div id="period">Circa 1891 · Straits Settlements</div>
<p>
Ocean cargo is worked from a deep-draft barque into a local bumboat,
then carried toward the bonded warehouses at the masonry quay.
</p>
</section>
<aside id="reference-card" class="panel">
<h2>Historical Lens</h2>
<p>
In 1891 Melaka was a British Straits Settlement. Before the later
expansion of the commercial harbour, ocean-going sailing vessels
transferred cargo through small native lighters.
</p>
<p class="fine">
Interpretive reconstruction. Buildings, vessels and working practices
combine documented period references rather than a surveyed site model.
</p>
</aside>
<div id="hotspots">
<div class="hotspot" data-point="ship"><b>1</b>Ocean-going barque</div>
<div class="hotspot" data-point="boat"><b>2</b>Bumboat lighter</div>
<div class="hotspot" data-point="warehouse"><b>3</b>Bonded warehouses</div>
<div class="hotspot" data-point="quay"><b>4</b>Stone quay</div>
</div>
<nav id="controls" class="panel" aria-label="Scene controls">
<button class="active" data-view="overview">Overview</button>
<button data-view="cargo">Cargo transfer</button>
<button data-view="quay">Quay</button>
<button id="pause">Pause transfer</button>
</nav>
<div id="hint">Drag to orbit · Scroll to zoom · Arrow keys to pan</div>
<div id="loading">Building the waterfront…</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 stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x779ca2);
scene.fog = new THREE.Fog(0x779ca2, 34, 76);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const cameraState = {
yaw: 0.72,
pitch: 0.46,
distance: 35,
target: new THREE.Vector3(-1.2, 2.0, -1.0)
};
const cameraGoal = {
yaw: cameraState.yaw,
pitch: cameraState.pitch,
distance: cameraState.distance,
target: cameraState.target.clone()
};
function updateCamera(dt) {
const ease = 1 - Math.exp(-dt * 8);
cameraState.yaw += (cameraGoal.yaw - cameraState.yaw) * ease;
cameraState.pitch += (cameraGoal.pitch - cameraState.pitch) * ease;
cameraState.distance += (cameraGoal.distance - cameraState.distance) * ease;
cameraState.target.lerp(cameraGoal.target, ease);
const horizontal =
Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
updateCamera(1);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xc4dfe0, 0x4d4435, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe1a6, 3.2);
sun.position.set(-14, 25, 16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x7ca5bb, 0.75);
fill.position.set(20, 8, -20);
scene.add(fill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.0,
flatShading: true,
...options
});
}
const mats = {
water: material(0x3f7d87, { roughness: 0.58, metalness: 0.12 }),
stone: material(0x8e8878),
stoneDark: material(0x655f55),
stoneLight: material(0xa59d88),
paving: material(0x817b6e),
timber: material(0x705039),
timberLight: material(0xa47b4e),
timberDark: material(0x423326),
plaster: material(0xd5c9a8),
plasterWarm: material(0xc7b38d),
roof: material(0xa6533f),
roofDark: material(0x713b31),
door: material(0x355d5b),
dark: material(0x202a29),
rope: material(0x9b855d),
sail: material(0xd8c8a2, { side: THREE.DoubleSide }),
sailShade: material(0xbfae87, { side: THREE.DoubleSide }),
crate: material(0x9b6b3e),
crateLight: material(0xb5854d),
burlap: material(0xa99262),
hull: material(0x433127),
hullTrim: material(0xb08a50),
smallHull: material(0x64452f),
bamboo: material(0xb49a55),
skin: material(0x9b6847),
white: material(0xe5dfc9),
blue: material(0x294f78),
red: material(0xa84436),
green: material(0x506b43),
leaf: material(0x466b47),
leafLight: material(0x638050)
};
let randomSeed = 1891;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function mesh(geometry, mat, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, mat, x, y, z, parent = scene) {
const object = mesh(new THREE.BoxGeometry(w, h, d), mat, parent);
object.position.set(x, y, z);
return object;
}
function cylinder(
rt, rb, h, segments, mat, x, y, z, parent = scene
) {
const object = mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat,
parent
);
object.position.set(x, y, z);
return object;
}
function ico(radius, detail, mat, x, y, z, parent = scene) {
const object = mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat,
parent
);
object.position.set(x, y, z);
return object;
}
function cylinderBetween(a, b, radius, mat, parent = scene, segments = 7) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const object = cylinder(
radius,
radius,
length,
segments,
mat,
0,
0,
0,
parent
);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
function line(points, color = 0x4b4335, opacity = 1, parent = scene) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map(p => new THREE.Vector3(...p))
);
const object = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
})
);
parent.add(object);
return object;
}
function signTexture(title, subtitle = "") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#263c3b";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "#b89960";
ctx.lineWidth = 9;
ctx.strokeRect(13, 13, canvas.width - 26, canvas.height - 26);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#efe0bc";
ctx.font = "600 66px Georgia, serif";
ctx.fillText(title, 512, subtitle ? 102 : 132);
if (subtitle) {
ctx.fillStyle = "#c8b993";
ctx.font = "700 27px Arial, sans-serif";
ctx.fillText(subtitle, 512, 183);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
renderer.capabilities.getMaxAnisotropy(),
8
);
return texture;
}
function makeSign(
title, subtitle, width, height,
x, y, z, parent = scene
) {
const material = new THREE.MeshBasicMaterial({
map: signTexture(title, subtitle),
transparent: true,
side: THREE.DoubleSide
});
const object = mesh(
new THREE.PlaneGeometry(width, height),
material,
parent
);
object.position.set(x, y, z);
object.castShadow = false;
return object;
}
function crate(x, y, z, scale = 1, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
box(0.9, 0.72, 0.78, mats.crate, 0, 0.36, 0, group);
box(0.95, 0.08, 0.82, mats.timberDark, 0, 0.61, 0, group);
box(0.95, 0.08, 0.82, mats.timberDark, 0, 0.12, 0, group);
box(0.07, 0.74, 0.84, mats.timberDark, -0.31, 0.36, 0, group);
box(0.07, 0.74, 0.84, mats.timberDark, 0.31, 0.36, 0, group);
return group;
}
function barrel(x, y, z, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
cylinder(0.34, 0.30, 0.8, 10, mats.crate, 0, 0.4, 0, group);
cylinder(0.355, 0.355, 0.07, 10, mats.timberDark, 0, 0.17, 0, group);
cylinder(0.355, 0.355, 0.07, 10, mats.timberDark, 0, 0.64, 0, group);
cylinder(0.31, 0.31, 0.04, 10, mats.timberLight, 0, 0.81, 0, group);
return group;
}
// ------------------------------------------------------------
// Faceted water
// ------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(100, 100, 30, 30);
waterGeometry.rotateX(-Math.PI / 2);
const waterColors = [];
const waterPositions = waterGeometry.attributes.position;
for (let i = 0; i < waterPositions.count; i++) {
const c = new THREE.Color();
const shade = 0.84 + random() * 0.19;
c.setRGB(0.22 * shade, 0.46 * shade, 0.52 * shade);
waterColors.push(c.r, c.g, c.b);
}
waterGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
const water = mesh(
waterGeometry,
material(0xffffff, {
vertexColors: true,
roughness: 0.55,
metalness: 0.14
})
);
water.position.y = -0.16;
water.castShadow = false;
water.receiveShadow = true;
// ------------------------------------------------------------
// Quay and bonded warehouses
// ------------------------------------------------------------
box(15, 3.5, 25, mats.stoneDark, -10.5, 0, 0);
box(15.1, 0.2, 25.1, mats.paving, -10.5, 1.82, 0);
for (let z = -11.5; z < 12; z += 1.55) {
box(
0.5, 1.05, 1.42,
(z + 12) % 3 < 1 ? mats.stone : mats.stoneDark,
-2.93, 0.85, z
);
}
for (let z = -10; z <= 10; z += 2.5) {
box(0.35, 0.08, 2.35, mats.stoneLight, -3.75, 1.95, z);
}
function gableRoof(w, d, eave, rise, x, z, parent = scene) {
for (const side of [-1, 1]) {
const vertices = new Float32Array([
-w / 2, eave, side * d / 2,
w / 2, eave, side * d / 2,
w / 2, eave + rise, 0,
-w / 2, eave + rise, 0
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(vertices, 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const roof = mesh(
geometry,
mats.roof,
parent
);
roof.position.set(x, 0, z);
roof.material.side = THREE.DoubleSide;
}
for (let row = -3; row <= 3; row++) {
const zOffset = row * d / 8;
const y = eave + rise * (1 - Math.abs(zOffset) / (d / 2));
box(
w + 0.12,
0.045,
0.07,
mats.roofDark,
x,
y + 0.035,
z + zOffset,
parent
);
}
box(w + 0.25, 0.13, 0.15, mats.roofDark, x, eave + rise + 0.05, z, parent);
}
function warehouse(cx, cz, w, d, h, title, subtitle) {
const group = new THREE.Group();
group.position.set(cx, 0, cz);
scene.add(group);
const base = 1.94;
box(w, h, d, mats.plaster, 0, base + h / 2, 0, group);
box(w + 0.28, 0.28, d + 0.28, mats.stoneLight, 0, base - 0.02, 0, group);
const eave = base + h;
gableRoof(w + 0.55, d + 0.55, eave, 1.45, 0, 0, group);
// Front doors, frames and loading windows.
box(2.05, 3.05, 0.16, mats.door, 0, base + 1.52, d / 2 + 0.08, group);
box(2.25, 0.12, 0.22, mats.timberDark, 0, base + 3.06, d / 2 + 0.11, group);
for (const x of [-2.65, 2.65]) {
box(1.25, 1.25, 0.14, mats.dark, x, base + 2.25, d / 2 + 0.09, group);
box(1.42, 1.42, 0.1, mats.timberLight, x, base + 2.25, d / 2 + 0.03, group);
box(0.06, 1.3, 0.16, mats.timberDark, x, base + 2.25, d / 2 + 0.13, group);
box(1.3, 0.06, 0.16, mats.timberDark, x, base + 2.25, d / 2 + 0.13, group);
}
makeSign(
title,
subtitle,
Math.min(w * 0.68, 5.2),
1.02,
0,
base + 4.0,
d / 2 + 0.16,
group
);
// Side pilasters.
for (const side of [-1, 1]) {
box(0.2, h, 0.18, mats.plasterWarm, side * (w / 2 - 0.15), base + h / 2, d / 2 + 0.08, group);
}
return group;
}
warehouse(-10.0, -6.0, 8.0, 5.0, 3.7, "MELAKA STORES", "BONDED WAREHOUSE");
warehouse(-10.3, 3.2, 7.0, 4.6, 3.4, "EAST INDIA HOUSE", "MERCHANDISE WAREHOUSE");
// Small colonial office at the back of the quay.
box(5.1, 3.1, 4.2, mats.plasterWarm, -14.1, 3.49, -10.0);
gableRoof(5.55, 4.65, 5.04, 1.15, -14.1, -10.0);
box(1.05, 2.1, 0.16, mats.door, -13.15, 3.0, -7.83);
box(0.85, 1.0, 0.13, mats.dark, -15.0, 3.95, -7.83);
makeSign("HARBOUR OFFICE", "1891", 2.2, 0.48, -14.2, 4.65, -7.82);
// Quay cargo, capstan, bollards and steps.
for (const [x, z, s] of [
[-6.4, -1.4, 1], [-5.5, -1.2, 0.8], [-6.2, 0.0, 0.9],
[-7.0, 5.1, 1.1], [-5.9, 5.2, 0.8], [-7.4, 8.4, 1]
]) {
crate(x, 1.94, z, s);
}
barrel(-4.8, 1.94, 7.2);
barrel(-4.1, 1.94, 7.6);
barrel(-4.6, 1.94, 8.3);
for (const z of [-10, -7, -3.5, 0, 4, 7.5, 10]) {
cylinder(0.13, 0.18, 0.62, 8, mats.dark, -3.65, 2.22, z);
cylinder(0.25, 0.25, 0.12, 8, mats.dark, -3.65, 2.53, z);
}
cylinder(0.42, 0.56, 0.9, 10, mats.timberDark, -4.4, 2.4, -3.1);
cylinder(0.18, 0.18, 1.8, 8, mats.timberLight, -4.4, 2.75, -3.1);
line([[-5.8, 3.55, -3.1], [-4.4, 2.7, -3.1]], 0x705b3d);
line([[-4.4, 2.7, -3.1], [-3.1, 3.55, -3.1]], 0x705b3d);
// Palm tree and vegetation at the quay edge.
function palm(x, z) {
const group = new THREE.Group();
group.position.set(x, 1.92, z);
scene.add(group);
const trunkPoints = [];
for (let i = 0; i < 6; i++) {
trunkPoints.push(new THREE.Vector3(
x + i * 0.09,
1.92 + i * 0.72,
z
));
}
for (let i = 0; i < trunkPoints.length - 1; i++) {
cylinderBetween(
trunkPoints[i],
trunkPoints[i + 1],
0.18 - i * 0.012,
mats.timber,
scene,
7
);
}
const crown = trunkPoints[trunkPoints.length - 1];
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = ico(1.15, 0, i % 2 ? mats.leaf : mats.leafLight,
crown.x + Math.cos(angle) * 0.82,
crown.y + 0.1,
crown.z + Math.sin(angle) * 0.82
);
leaf.scale.set(1.6, 0.32, 0.8);
leaf.rotation.y = -angle;
}
}
palm(-15.0, -9.2);
palm(-16.3, 8.8);
// ------------------------------------------------------------
// Timber transfer platform
// ------------------------------------------------------------
const platform = new THREE.Group();
scene.add(platform);
for (const x of [-3.2, -1.4, 0.45]) {
for (const z of [-2.0, 0, 2.0]) {
cylinder(0.14, 0.18, 3.0, 7, mats.timberDark, x, 0.0, z, platform);
}
}
for (let z = -2.3; z <= 2.3; z += 0.31) {
box(4.8, 0.25, 0.27, mats.timberLight, -1.15, 1.28, z, platform);
}
box(0.46, 0.19, 4.8, mats.timber, -3.25, 1.38, 0, platform);
for (let i = 0; i < 5; i++) {
box(0.75, 0.18, 1.35, mats.timberLight,
-3.35 + i * 0.42, 1.67 - i * 0.22, 2.8, platform);
}
// Simple rail on the seaward corner.
for (const z of [-2.1, 2.1]) {
cylinder(0.055, 0.065, 1.15, 7, mats.timberDark, 0.95, 1.98, z, platform);
}
cylinderBetween(
new THREE.Vector3(0.95, 2.5, -2.1),
new THREE.Vector3(0.95, 2.5, 2.1),
0.055,
mats.timberDark,
platform
);
// ------------------------------------------------------------
// Low-poly ship hull builder
// ------------------------------------------------------------
function createHull(length, beam, topY, bottomY, hullMat, deckMat) {
const group = new THREE.Group();
const top = [
[-length * 0.50, topY, 0],
[-length * 0.36, topY, -beam * 0.32],
[ length * 0.25, topY, -beam * 0.50],
[ length * 0.48, topY, -beam * 0.18],
[ length * 0.52, topY, 0],
[ length * 0.48, topY, beam * 0.18],
[ length * 0.25, topY, beam * 0.50],
[-length * 0.36, topY, beam * 0.32]
];
const bottom = [
[-length * 0.43, bottomY, 0],
[-length * 0.30, bottomY, -beam * 0.21],
[ length * 0.19, bottomY, -beam * 0.29],
[ length * 0.41, bottomY, -beam * 0.07],
[ length * 0.48, bottomY, 0],
[ length * 0.41, bottomY, beam * 0.07],
[ length * 0.19, bottomY, beam * 0.29],
[-length * 0.30, bottomY, beam * 0.21]
];
const vertices = [];
const indices = [];
top.forEach(p => vertices.push(...p));
bottom.forEach(p => vertices.push(...p));
for (let i = 0; i < 8; i++) {
const next = (i + 1) % 8;
indices.push(i, next, 8 + next);
indices.push(i, 8 + next, 8 + i);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const hull = mesh(geometry, hullMat, group);
hull.material.side = THREE.DoubleSide;
const deckVertices = [0, topY + 0.035, 0];
top.forEach(p => deckVertices.push(p[0], p[1] + 0.035, p[2]));
const deckIndices = [];
for (let i = 0; i < 8; i++) {
deckIndices.push(0, i + 1, ((i + 1) % 8) + 1);
}
const deckGeometry = new THREE.BufferGeometry();
deckGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(deckVertices, 3)
);
deckGeometry.setIndex(deckIndices);
deckGeometry.computeVertexNormals();
const deck = mesh(deckGeometry, deckMat, group);
deck.material.side = THREE.DoubleSide;
return group;
}
// ------------------------------------------------------------
// Ocean-going barque
// ------------------------------------------------------------
const barque = new THREE.Group();
barque.position.set(9.0, 0, -4.0);
scene.add(barque);
const barqueHull = createHull(
14.0, 5.1, 1.55, -0.9,
mats.hull, mats.timberLight
);
barque.add(barqueHull);
// Hull trim, stern castle and deckhouse.
box(11.7, 0.15, 5.14, mats.hullTrim, -0.15, 1.42, 0, barque);
box(2.4, 1.8, 3.1, mats.plaster, -4.9, 2.48, 0, barque);
box(2.7, 0.18, 3.35, mats.roofDark, -4.9, 3.44, 0, barque);
box(1.5, 1.0, 1.4, mats.plaster, -4.9, 2.08, 0, barque);
for (const x of [-5.7, -4.8, -3.9]) {
const port = cylinder(0.12, 0.12, 0.1, 8, mats.dark, x, 0.85, 2.56, barque);
port.rotation.x = Math.PI / 2;
}
makeSign("MELAKA", "TRADING BARQUE", 2.1, 0.48, -4.9, 2.55, 2.58, barque);
function makeSail(mastX, centerY, width, height, mat) {
const geometry = new THREE.PlaneGeometry(width, height, 4, 4);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const y = position.getY(i);
const bulge = Math.cos((x / width) * Math.PI) * 0.32;
const lowerCurve = Math.max(0, (-y / height) + 0.5) * 0.18;
position.setZ(i, bulge + lowerCurve);
}
geometry.computeVertexNormals();
geometry.rotateY(Math.PI / 2);
const sail = mesh(geometry, mat, barque);
sail.position.set(mastX, centerY, 0);
return sail;
}
const mastData = [
{ x: -2.5, y: 11.2, sailY: 7.3, sailW: 4.5, sailH: 4.5 },
{ x: 1.2, y: 12.4, sailY: 8.1, sailW: 5.1, sailH: 5.0 },
{ x: 4.4, y: 10.7, sailY: 7.0, sailW: 4.1, sailH: 4.3 }
];
for (const mast of mastData) {
cylinder(0.11, 0.15, mast.y - 1.55, 8, mats.timberDark,
mast.x, (mast.y + 1.55) / 2, 0, barque);
cylinderBetween(
new THREE.Vector3(mast.x, mast.sailY + mast.sailH / 2, -mast.sailW / 2),
new THREE.Vector3(mast.x, mast.sailY + mast.sailH / 2, mast.sailW / 2),
0.075,
mats.timber,
barque
);
makeSail(mast.x, mast.sailY, mast.sailW, mast.sailH, mats.sail);
line([
[mast.x, mast.y, 0],
[6.3, 1.7, 0]
], 0x5a4b39, 0.82, barque);
line([
[mast.x, mast.y, 0],
[-6.3, 1.7, 0]
], 0x5a4b39, 0.82, barque);
}
// Additional furled canvas and cargo booms.
cylinderBetween(
new THREE.Vector3(-5.7, 3.6, -1.7),
new THREE.Vector3(-0.8, 3.6, -1.7),
0.17,
mats.sailShade,
barque
);
for (const x of [-0.1, 2.0, 4.2]) {
cylinderBetween(
new THREE.Vector3(x, 2.0, 1.8),
new THREE.Vector3(x + 0.5, 5.1, 1.8),
0.065,
mats.timber,
barque
);
}
// Working cargo boom; its tip anchors the animated transfer line.
const craneAnchor = new THREE.Vector3(6.0, 7.0, -1.2);
cylinderBetween(
new THREE.Vector3(-2.5, 10.5, 0),
craneAnchor,
0.11,
mats.timber,
barque
);
// A simplified British-style ensign at the stern.
cylinder(0.055, 0.07, 4.4, 7, mats.timberDark, -6.4, 5.8, 0, barque);
box(1.35, 0.78, 0.035, mats.blue, -5.75, 7.25, 0, barque);
box(0.62, 0.08, 0.045, mats.white, -5.88, 7.25, 0.03, barque);
box(0.08, 0.55, 0.045, mats.white, -5.88, 7.25, 0.03, barque);
box(0.42, 0.08, 0.045, mats.red, -5.88, 7.25, 0.035, barque);
box(0.08, 0.42, 0.045, mats.red, -5.88, 7.25, 0.035, barque);
// Deck cargo.
crate(-3.3, 1.6, 0.8, 1.0, barque);
crate(-2.3, 1.6, 0.9, 0.85, barque);
crate(-2.35, 2.28, 0.9, 0.75, barque);
barrel(-0.2, 1.6, 1.0, barque);
barrel(0.45, 1.6, 1.0, barque);
// Ship's boat and anchors.
box(2.4, 0.55, 0.9, mats.crateLight, -3.8, 4.1, 1.9, barque);
for (const x of [3.8, 5.0]) {
const anchor = box(0.10, 0.9, 0.11, mats.dark, x, 0.75, 2.61, barque);
anchor.rotation.z = -0.12;
}
// ------------------------------------------------------------
// Native bumboat / cargo lighter
// ------------------------------------------------------------
const bumboat = new THREE.Group();
bumboat.position.set(4.25, 0, 1.25);
scene.add(bumboat);
const bumboatHull = createHull(
5.8, 2.45, 0.92, -0.48,
mats.smallHull, mats.timberLight
);
bumboat.add(bumboatHull);
box(4.9, 0.12, 2.48, mats.hullTrim, 0, 0.82, 0, bumboat);
// Bamboo canopy aft.
for (const x of [-2.0, -0.4]) {
for (const z of [-0.9, 0.9]) {
cylinder(0.055, 0.065, 1.65, 6, mats.bamboo, x, 1.65, z, bumboat);
}
}
const canopyGeometry = new THREE.BufferGeometry();
canopyGeometry.setAttribute("position", new THREE.Float32BufferAttribute([
-2.25, 2.38, -1.08,
-0.15, 2.38, -1.08,
-0.15, 2.76, 0,
-2.25, 2.76, 0,
-2.25, 2.38, 1.08,
-0.15, 2.38, 1.08
], 3));
canopyGeometry.setIndex([
0, 1, 2, 0, 2, 3,
4, 3, 2, 4, 2, 5
]);
canopyGeometry.computeVertexNormals();
const canopyMat = mats.sail.clone();
canopyMat.side = THREE.DoubleSide;
mesh(canopyGeometry, canopyMat, bumboat);
for (let i = 0; i < 6; i++) {
const x = -2.2 + i * 0.36;
box(0.035, 0.035, 2.14, mats.bamboo, x, 2.66, 0, bumboat);
}
// Cargo in the open bow and a steerage oar.
crate(0.75, 0.96, -0.15, 0.72, bumboat);
crate(1.55, 0.96, 0.1, 0.68, bumboat);
crate(1.55, 1.45, 0.1, 0.58, bumboat);
const sack = ico(0.42, 1, mats.burlap, 0.85, 1.35, 0.55, bumboat);
sack.scale.set(1.0, 1.35, 0.85);
cylinderBetween(
new THREE.Vector3(0.5, 1.2, 1.05),
new THREE.Vector3(2.65, 0.35, 1.55),
0.055,
mats.bamboo,
bumboat
);
makeSign("BUMBOAT No. 4", "STRAITS LIGHTER", 1.85, 0.42, -0.25, 0.47, 1.25, bumboat);
// Mooring line to the platform.
line([
[-2.25, 0.95, 0.5],
[-3.7, 1.5, 0.1],
[-3.0, 1.55, -0.6]
], 0x8d7651, 0.95);
// ------------------------------------------------------------
// Workers
// ------------------------------------------------------------
const workers = [];
function worker(x, y, z, shirtMat, rotation = 0, scale = 1, active = false) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.10, 0.12, 0.56, 6, mats.dark, -0.13, 0.29, 0, group);
cylinder(0.10, 0.12, 0.56, 6, mats.dark, 0.13, 0.29, 0, group);
cylinder(0.22, 0.29, 0.65, 7, shirtMat, 0, 0.91, 0, group);
ico(0.20, 1, mats.skin, 0, 1.42, 0, group);
cylinder(0.23, 0.23, 0.075, 9, mats.bamboo, 0, 1.61, 0, group);
cylinder(0.14, 0.16, 0.16, 8, mats.bamboo, 0, 1.69, 0, group);
const armPivots = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.27, 1.12, 0);
group.add(pivot);
cylinder(0.075, 0.09, 0.55, 6, shirtMat, 0, -0.23, 0, pivot);
ico(0.09, 0, mats.skin, 0, -0.52, 0, pivot);
armPivots.push(pivot);
}
workers.push({ group, armPivots, active, phase: random() * 6.28 });
return group;
}
worker(6.0, 1.59, -2.8, mats.white, 0.8, 0.93, true);
worker(5.2, 1.59, -3.15, mats.blue, -0.5, 0.93, true);
worker(5.55, 0.96, 1.25, mats.white, 2.6, 0.88, true);
worker(-0.25, 1.43, -0.6, mats.burlap, 1.1, 0.94, true);
worker(-4.9, 1.94, -1.1, mats.blue, 1.3, 1, true);
worker(-6.7, 1.94, 1.0, mats.white, -0.8, 1, false);
worker(-8.8, 1.94, -7.0, mats.burlap, 2.2, 1, false);
// ------------------------------------------------------------
// Animated cargo transfer from barque to bumboat
// ------------------------------------------------------------
const transferStart = new THREE.Vector3(6.5, 1.94, -3.1);
const transferEnd = new THREE.Vector3(4.75, 1.32, 1.15);
const control1 = new THREE.Vector3(6.4, 5.75, -2.6);
const control2 = new THREE.Vector3(4.55, 4.5, 0.25);
function cubicBezier(t, p0, p1, p2, p3) {
const mt = 1 - t;
return new THREE.Vector3(
mt * mt * mt * p0.x + 3 * mt * mt * t * p1.x +
3 * mt * t * t * p2.x + t * t * t * p3.x,
mt * mt * mt * p0.y + 3 * mt * mt * t * p1.y +
3 * mt * t * t * p2.y + t * t * t * p3.y,
mt * mt * mt * p0.z + 3 * mt * mt * t * p1.z +
3 * mt * t * t * p2.z + t * t * t * p3.z
);
}
function suspendedLoad(type) {
const group = new THREE.Group();
scene.add(group);
if (type === 0) {
box(0.92, 0.67, 0.76, mats.crateLight, 0, 0, 0, group);
box(0.97, 0.07, 0.81, mats.timberDark, 0, 0.28, 0, group);
box(0.07, 0.70, 0.81, mats.timberDark, -0.31, 0, 0, group);
box(0.07, 0.70, 0.81, mats.timberDark, 0.31, 0, 0, group);
} else {
const sack = ico(0.45, 1, mats.burlap, 0, 0, 0, group);
sack.scale.set(1.0, 1.2, 0.9);
const smaller = ico(0.31, 1, mats.burlap, 0.26, 0.05, 0.12, group);
smaller.scale.set(1, 1.1, 0.9);
}
// Slings from the cargo corners to the hook.
line([
[-0.35, 0.34, -0.28],
[0, 1.15, 0]
], 0x746344, 1, group);
line([
[0.35, 0.34, -0.28],
[0, 1.15, 0]
], 0x746344, 1, group);
line([
[-0.35, 0.34, 0.28],
[0, 1.15, 0]
], 0x746344, 1, group);
line([
[0.35, 0.34, 0.28],
[0, 1.15, 0]
], 0x746344, 1, group);
const ropeGeometry = new THREE.BufferGeometry();
ropeGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(9), 3)
);
const rope = new THREE.Line(
ropeGeometry,
new THREE.LineBasicMaterial({ color: 0x3e3b31 })
);
scene.add(rope);
return { group, rope, ropeGeometry, phase: random() };
}
const loads = [
suspendedLoad(0),
suspendedLoad(1),
suspendedLoad(0)
];
let transferTime = 0;
let transferPaused = false;
function updateTransfer(dt) {
if (!transferPaused) transferTime += dt;
for (let i = 0; i < loads.length; i++) {
const load = loads[i];
const t = ((transferTime / 8.5) + i / loads.length + load.phase * 0.025) % 1;
const visible = t > 0.018 && t < 0.975;
load.group.visible = visible;
load.rope.visible = visible;
if (!visible) continue;
const pos = cubicBezier(
t, transferStart, control1, control2, transferEnd
);
load.group.position.copy(pos);
load.group.rotation.y = Math.sin(t * Math.PI * 2) * 0.09;
load.group.rotation.z = Math.sin(t * Math.PI * 4) * 0.035;
const hook = pos.clone();
hook.y += 1.15;
const attr = load.ropeGeometry.attributes.position;
attr.setXYZ(0, craneAnchor.x, craneAnchor.y, craneAnchor.z);
attr.setXYZ(1, hook.x, hook.y, hook.z);
attr.setXYZ(2, pos.x, pos.y + 0.34, pos.z);
attr.needsUpdate = true;
}
}
// ------------------------------------------------------------
// Distant port silhouettes
// ------------------------------------------------------------
const distantGroup = new THREE.Group();
distantGroup.position.set(-5, 0, -31);
scene.add(distantGroup);
box(45, 1.2, 8, mats.stoneDark, 0, 0.1, 0, distantGroup);
for (let i = 0; i < 11; i++) {
const w = 2.4 + random() * 2.4;
const h = 1.8 + random() * 2.3;
const x = -20 + i * 4;
const z = -1 + random() * 1.5;
box(w, h, 2.8, i % 2 ? mats.plasterWarm : mats.plaster,
x, 0.65 + h / 2, z, distantGroup);
gableRoof(w + 0.25, 3.0, 0.7 + h, 0.65, x, z, distantGroup);
}
// A tiny distant sailboat.
const distantBoat = new THREE.Group();
distantBoat.position.set(18, 0, -26);
scene.add(distantBoat);
box(2.4, 0.5, 0.65, mats.hull, 0, 0.15, 0, distantBoat);
cylinder(0.04, 0.05, 4.0, 5, mats.timberDark, 0, 2.0, 0, distantBoat);
const tinySail = box(1.5, 2.1, 0.035, mats.sail, 0, 2.3, 0, distantBoat);
tinySail.rotation.y = 0.25;
// ------------------------------------------------------------
// Camera interaction — no addons
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraGoal.yaw -= dx * 0.006;
cameraGoal.pitch = THREE.MathUtils.clamp(
cameraGoal.pitch + dy * 0.005,
0.14,
1.12
);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraGoal.distance = THREE.MathUtils.clamp(
cameraGoal.distance + event.deltaY * 0.025,
12,
52
);
}, { passive: false });
window.addEventListener("keydown", event => {
const step = 0.6;
if (event.key === "ArrowLeft") cameraGoal.target.x -= step;
if (event.key === "ArrowRight") cameraGoal.target.x += step;
if (event.key === "ArrowUp") cameraGoal.target.z -= step;
if (event.key === "ArrowDown") cameraGoal.target.z += step;
if (event.key === "+" || event.key === "=") {
cameraGoal.distance = Math.max(12, cameraGoal.distance - 2);
}
if (event.key === "-" || event.key === "_") {
cameraGoal.distance = Math.min(52, cameraGoal.distance + 2);
}
});
const views = {
overview: {
yaw: 0.72, pitch: 0.46, distance: 35,
target: new THREE.Vector3(-1.2, 2.0, -1.0)
},
cargo: {
yaw: 1.02, pitch: 0.32, distance: 18,
target: new THREE.Vector3(5.4, 2.6, -1.0)
},
quay: {
yaw: 0.48, pitch: 0.46, distance: 22,
target: new THREE.Vector3(-7.8, 2.8, -1.0)
}
};
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => {
const view = views[button.dataset.view];
cameraGoal.yaw = view.yaw;
cameraGoal.pitch = view.pitch;
cameraGoal.distance = view.distance;
cameraGoal.target.copy(view.target);
document.querySelectorAll("[data-view]").forEach(other => {
other.classList.toggle("active", other === button);
});
});
});
const pauseButton = document.querySelector("#pause");
pauseButton.addEventListener("click", () => {
transferPaused = !transferPaused;
pauseButton.textContent = transferPaused ? "Resume transfer" : "Pause transfer";
});
// ------------------------------------------------------------
// HTML hotspot projection
// ------------------------------------------------------------
const hotspotDefinitions = {
ship: new THREE.Vector3(10.0, 9.7, -4.0),
boat: new THREE.Vector3(4.25, 3.05, 1.25),
warehouse: new THREE.Vector3(-10.0, 7.0, -6.0),
quay: new THREE.Vector3(-3.0, 2.6, 5.3)
};
const hotspotElements = {};
document.querySelectorAll(".hotspot").forEach(element => {
hotspotElements[element.dataset.point] = element;
});
function updateHotspots() {
for (const [key, point] of Object.entries(hotspotDefinitions)) {
const projected = point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
const element = hotspotElements[key];
element.style.opacity = visible ? "1" : "0";
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let frame = 0;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
frame++;
updateCamera(dt);
updateTransfer(dt);
// Gentle movement of the faceted water.
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const z = waterPositions.getZ(i);
const y =
Math.sin(x * 0.34 + elapsed * 0.7) * 0.045 +
Math.cos(z * 0.41 + elapsed * 0.55) * 0.035;
waterPositions.setY(i, y);
}
waterPositions.needsUpdate = true;
if (frame % 8 === 0) waterGeometry.computeVertexNormals();
// Working workers make small, deliberate arm motions.
for (const worker of workers) {
if (!worker.active) continue;
const swing = Math.sin(elapsed * 3.3 + worker.phase);
worker.armPivots[0].rotation.x = swing * 0.45;
worker.armPivots[1].rotation.x = -swing * 0.45;
}
camera.updateMatrixWorld();
updateHotspots();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```