Prompt specification
Build or customize the Three.js 3D scene "Goods transfer from dhow landing to a narrow lane" 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: Goods transfer from dhow landing to a narrow lane
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/goods-transfer-from-dhow-landing-to-a-narrow-lane-x2934
Scene Description Prompt:
A low-poly Lamu landing: goods move from a dhow toward a narrow lane with a working donkey. Three.js from cdnjs, one HTML file.
Working Three.js Starter (goods-transfer-from-dhow-landing-to-a-narrow-lane-x2934):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lamu Landing</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #b9d7d7;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
max-width: min(360px, calc(100vw - 48px));
color: #fff9e9;
text-shadow: 0 2px 12px rgba(17, 34, 35, 0.4);
pointer-events: none;
}
.eyebrow {
display: inline-block;
margin-bottom: 8px;
padding: 5px 9px;
border: 1px solid rgba(255, 249, 233, 0.55);
border-radius: 999px;
background: rgba(29, 59, 59, 0.22);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 5vw, 58px);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
max-width: 285px;
font-size: 12px;
line-height: 1.45;
letter-spacing: 0.025em;
}
.controls {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 10;
display: flex;
align-items: center;
gap: 8px;
}
button {
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 999px;
padding: 10px 14px;
color: #fffaf0;
background: rgba(22, 48, 49, 0.48);
backdrop-filter: blur(10px);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.04em;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(22, 48, 49, 0.76);
transform: translateY(-1px);
}
button.active {
color: #173536;
background: #f4dfb1;
}
.hint {
position: fixed;
left: 24px;
bottom: 23px;
z-index: 10;
color: rgba(255, 250, 237, 0.88);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.11em;
text-transform: uppercase;
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: #27484a;
background: #b9d7d7;
font-family: Georgia, serif;
font-size: 22px;
transition: opacity 500ms ease;
pointer-events: none;
}
#loading.hidden {
opacity: 0;
}
@media (max-width: 600px) {
.panel {
top: 16px;
left: 16px;
}
.subtitle {
display: none;
}
.hint {
left: 16px;
bottom: 16px;
max-width: 120px;
line-height: 1.5;
}
.controls {
right: 12px;
bottom: 12px;
}
button {
padding: 9px 11px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="loading">Lamu Landing…</div>
<header class="panel">
<div class="eyebrow">Kenya · Indian Ocean</div>
<h1>Lamu<br>Landing</h1>
<p class="subtitle">
Morning cargo moves from a sail-rigged dhow into the coral-stone lanes.
</p>
</header>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="controls">
<button id="follow" type="button">Follow cargo</button>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9d7d7);
scene.fog = new THREE.Fog(0xb9d7d7, 38, 88);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemisphere = new THREE.HemisphereLight(0xd9f2ed, 0x8c684b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b3, 3.25);
sun.position.set(-18, 30, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bd7df, 0.55);
fill.position.set(20, 10, -20);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const materials = {
sand: standard(0xd9bd83),
sandLight: standard(0xe6cf9c),
path: standard(0xc4a574),
stone: standard(0xb9a17d),
stoneDark: standard(0x81745f),
wood: standard(0x765039),
woodLight: standard(0xa87848),
woodDark: standard(0x49382e),
rope: standard(0xbca276),
sail: standard(0xf2dfb2, { side: THREE.DoubleSide }),
sailPatch: standard(0xb86e48, { side: THREE.DoubleSide }),
sack: standard(0xc9a46b),
sackLight: standard(0xdfc58d),
metal: standard(0x465052, { metalness: 0.12 }),
black: standard(0x252a29),
green: standard(0x61794a),
greenDark: standard(0x455b3c),
blue: standard(0x547f89),
orange: standard(0xc87542),
cream: standard(0xe8d4a7),
coral: standard(0xc48667),
white: standard(0xf4edcf),
skin: standard(0x754b35)
};
let randomSeed = 9147;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function addBox(parent, sx, sy, sz, x, y, z, material, shadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
rTop,
rBottom,
height,
x,
y,
z,
material,
segments = 6
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const up = new THREE.Vector3(0, 1, 0);
function cylinderBetween(parent, a, b, radius, material, segments = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = addCylinder(
parent,
radius,
radius,
direction.length(),
midpoint.x,
midpoint.y,
midpoint.z,
material,
segments
);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
return mesh;
}
function addSack(parent, x, y, z, scale = 1, material = materials.sack) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.46, 1),
material
);
body.scale.set(1.05, 0.84, 0.9);
body.rotation.set(random(), random() * 0.5, random() * 0.3);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
addCylinder(
group,
0.09,
0.12,
0.18,
0,
0.39,
0,
materials.sackLight,
5
);
parent.add(group);
return group;
}
function addCrate(parent, x, y, z, sx = 0.72, sy = 0.6, sz = 0.72) {
const group = new THREE.Group();
group.position.set(x, y, z);
addBox(group, sx, sy, sz, 0, 0, 0, materials.wood, true);
const slat = materials.woodLight;
addBox(group, sx + 0.025, 0.07, 0.07, 0, sy * 0.28, sz * 0.51, slat);
addBox(group, sx + 0.025, 0.07, 0.07, 0, -sy * 0.28, sz * 0.51, slat);
addBox(group, 0.07, sy + 0.025, 0.07, sx * 0.51, 0, sz * 0.51, slat);
addBox(group, 0.07, sy + 0.025, 0.07, -sx * 0.51, 0, sz * 0.51, slat);
parent.add(group);
return group;
}
function addJerryCan(parent, x, y, z) {
const group = new THREE.Group();
group.position.set(x, y, z);
addBox(group, 0.42, 0.58, 0.25, 0, 0.29, 0, materials.orange);
addCylinder(group, 0.07, 0.07, 0.08, 0.08, 0.61, 0, materials.black, 6);
addBox(group, 0.17, 0.08, 0.08, -0.04, 0.61, 0, materials.black);
parent.add(group);
return group;
}
// ---------------------------------------------------------------------
// Water
// ---------------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(110, 110, 36, 36);
waterGeometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(
waterGeometry,
standard(0x327f88, {
roughness: 0.58,
metalness: 0.08,
transparent: true,
opacity: 0.96
})
);
water.receiveShadow = true;
world.add(water);
const waterPositions = waterGeometry.attributes.position;
// ---------------------------------------------------------------------
// Irregular island and lane
// ---------------------------------------------------------------------
const landShape = new THREE.Shape();
landShape.moveTo(1.1, -8);
landShape.lineTo(-0.2, -5.1);
landShape.lineTo(1.25, -2.5);
landShape.lineTo(0.7, 1.5);
landShape.lineTo(0.95, 7);
landShape.lineTo(0.55, 13);
landShape.lineTo(1.05, 19);
landShape.lineTo(1.8, 25.8);
landShape.lineTo(20.5, 26.4);
landShape.lineTo(21.2, 14);
landShape.lineTo(20.4, 3);
landShape.lineTo(21, -8);
landShape.closePath();
const landGeometry = new THREE.ExtrudeGeometry(landShape, {
depth: 1.5,
bevelEnabled: false
});
landGeometry.rotateX(Math.PI / 2);
const land = new THREE.Mesh(landGeometry, materials.sand);
land.position.y = 1.05;
land.castShadow = true;
land.receiveShadow = true;
world.add(land);
const lane = new THREE.Mesh(
new THREE.PlaneGeometry(3.5, 26),
materials.path
);
lane.rotation.x = -Math.PI / 2;
lane.position.set(6.2, 1.065, 11.5);
lane.receiveShadow = true;
world.add(lane);
// Small sandy patches and stones beside the lane.
for (let i = 0; i < 36; i++) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.08 + random() * 0.17, 0),
i % 3 === 0 ? materials.stoneDark : materials.stone
);
rock.position.set(
3.7 + random() * 5.2,
1.08,
-2 + random() * 27
);
rock.scale.y = 0.45 + random() * 0.4;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
world.add(rock);
}
// Foam fragments along the shore.
const foam = [];
for (let i = 0; i < 23; i++) {
const foamMesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.34 + random() * 0.25, 0),
new THREE.MeshBasicMaterial({
color: 0xe8eee1,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
foamMesh.position.set(0.35 + random() * 0.7, 0.08, -5 + random() * 27);
foamMesh.scale.set(1.5, 0.045, 0.35 + random() * 0.3);
world.add(foamMesh);
foam.push(foamMesh);
}
// ---------------------------------------------------------------------
// Coral-stone buildings lining the narrow lane
// ---------------------------------------------------------------------
const wallPalette = [
standard(0xd5c095),
standard(0xc99a76),
standard(0xe0cfaa),
standard(0xb78060),
standard(0xb8b19a),
standard(0xd1aa78)
];
const windowMaterial = standard(0x35494a);
const shutterMaterial = standard(0x536d61);
function makeBuilding(cx, cz, width, depth, height, wallMaterial, leftSide) {
const building = new THREE.Group();
building.position.set(cx, 1.05, cz);
addBox(building, width, height, depth, 0, height / 2, 0, wallMaterial);
// Flat roof and parapet.
addBox(
building,
width + 0.2,
0.18,
depth + 0.2,
0,
height + 0.08,
0,
materials.cream
);
const faceX = leftSide
? width / 2 - 0.035
: -width / 2 + 0.035;
// Door.
addBox(
building,
0.11,
1.65,
0.86,
faceX,
0.825,
-0.7,
materials.woodDark
);
addBox(
building,
0.16,
0.12,
1.05,
faceX,
1.72,
-0.7,
materials.wood
);
// Windows facing the lane.
for (const offset of [1.15, 2.25]) {
addBox(
building,
0.15,
0.82,
0.92,
faceX,
2.55,
offset,
materials.woodDark
);
addBox(
building,
0.17,
0.62,
0.72,
faceX + (leftSide ? 0.015 : -0.015),
2.55,
offset,
windowMaterial
);
// A narrow shutter catches the sunlight.
addBox(
building,
0.1,
0.72,
0.26,
faceX + (leftSide ? 0.035 : -0.035),
2.54,
offset + 0.48,
shutterMaterial
);
}
// Irregular coral patches on the facade.
for (let i = 0; i < 7; i++) {
addBox(
building,
0.07,
0.15 + random() * 0.22,
0.22 + random() * 0.38,
faceX + (leftSide ? 0.018 : -0.018),
0.35 + random() * (height - 0.7),
-depth / 2 + 0.5 + random() * (depth - 1),
i % 2 ? materials.cream : materials.stone,
false
);
}
// Raised roof blocks.
addBox(
building,
0.9,
0.55,
0.9,
-width * 0.18,
height + 0.43,
depth * 0.18,
wallMaterial
);
world.add(building);
return building;
}
const buildingRows = [
{ side: -1, x: 2.2, z: 4.5, height: 4.8, width: 4.5 },
{ side: -1, x: 2.2, z: 10.5, height: 5.8, width: 4.4 },
{ side: -1, x: 2.2, z: 16.5, height: 4.35, width: 4.5 },
{ side: -1, x: 2.2, z: 22.5, height: 5.15, width: 4.4 },
{ side: 1, x: 10.25, z: 4.5, height: 4.15, width: 4.55 },
{ side: 1, x: 10.25, z: 10.5, height: 4.8, width: 4.5 },
{ side: 1, x: 10.25, z: 16.5, height: 3.9, width: 4.55 },
{ side: 1, x: 10.25, z: 22.5, height: 4.55, width: 4.5 }
];
buildingRows.forEach((row, index) => {
makeBuilding(
row.x,
row.z,
row.width,
5.05,
row.height,
wallPalette[index % wallPalette.length],
row.side < 0
);
});
// A striped shop awning extending into the lane.
const awning = new THREE.Group();
awning.position.set(7.65, 3.45, 10.5);
for (let i = 0; i < 6; i++) {
const stripe = addBox(
awning,
1.55,
0.09,
0.63,
-0.57,
0,
-1.6 + i * 0.64,
i % 2 ? materials.white : materials.orange
);
stripe.rotation.z = -0.09;
}
world.add(awning);
// Washing line between the buildings.
cylinderBetween(
world,
[4.45, 5.25, 13.6],
[7.95, 4.85, 13.6],
0.018,
materials.rope,
5
);
const laundryColors = [materials.blue, materials.white, materials.orange, materials.green];
for (let i = 0; i < 4; i++) {
const cloth = addBox(
world,
0.43,
0.65,
0.035,
4.95 + i * 0.72,
4.88 - i * 0.03,
13.6,
laundryColors[i],
false
);
cloth.rotation.z = (random() - 0.5) * 0.12;
}
// ---------------------------------------------------------------------
// Landing and dhow
// ---------------------------------------------------------------------
const dock = new THREE.Group();
dock.position.set(-1.8, 0, -2.55);
addBox(dock, 6.6, 0.8, 3.0, 0, 0.58, 0, materials.stoneDark);
addBox(dock, 6.8, 0.12, 3.15, 0, 1.02, 0, materials.wood);
for (let i = 0; i < 12; i++) {
addBox(
dock,
0.5,
0.08,
2.92,
-3.08 + i * 0.56,
1.11,
0,
i % 2 ? materials.woodLight : materials.wood
);
}
for (const x of [-2.9, 0, 2.9]) {
for (const z of [-1.32, 1.32]) {
addCylinder(dock, 0.09, 0.11, 0.8, x, 0.42, z, materials.woodDark, 6);
}
}
world.add(dock);
addSack(dock, -1.9, 1.34, 0.55, 1.05);
addSack(dock, -1.3, 1.3, 0.1, 0.85, materials.sackLight);
addCrate(dock, 0.15, 1.42, 0.45);
addJerryCan(dock, 1.0, 1.11, -0.55);
const dhow = new THREE.Group();
dhow.position.set(-7.3, 0, -2.7);
dhow.rotation.y = -0.08;
const hullShape = new THREE.Shape();
hullShape.moveTo(0, 5.6);
hullShape.lineTo(0.8, 4.15);
hullShape.lineTo(1.22, 1.45);
hullShape.lineTo(1.25, -2.4);
hullShape.lineTo(0.78, -4.25);
hullShape.lineTo(0, -5.15);
hullShape.lineTo(-0.78, -4.25);
hullShape.lineTo(-1.25, -2.4);
hullShape.lineTo(-1.22, 1.45);
hullShape.lineTo(-0.8, 4.15);
hullShape.closePath();
const hullGeometry = new THREE.ExtrudeGeometry(hullShape, {
depth: 0.76,
bevelEnabled: false
});
hullGeometry.rotateX(Math.PI / 2);
const hull = new THREE.Mesh(hullGeometry, materials.wood);
hull.position.y = 0.84;
hull.castShadow = true;
hull.receiveShadow = true;
dhow.add(hull);
const deckShape = new THREE.Shape();
deckShape.moveTo(0, 5.0);
deckShape.lineTo(0.63, 3.75);
deckShape.lineTo(0.98, 1.2);
deckShape.lineTo(0.96, -2.05);
deckShape.lineTo(0.58, -3.8);
deckShape.lineTo(0, -4.55);
deckShape.lineTo(-0.58, -3.8);
deckShape.lineTo(-0.96, -2.05);
deckShape.lineTo(-0.98, 1.2);
deckShape.lineTo(-0.63, 3.75);
deckShape.closePath();
const deckGeometry = new THREE.ExtrudeGeometry(deckShape, {
depth: 0.07,
bevelEnabled: false
});
deckGeometry.rotateX(Math.PI / 2);
const deck = new THREE.Mesh(deckGeometry, materials.woodLight);
deck.position.y = 0.9;
deck.receiveShadow = true;
dhow.add(deck);
// Gunwale rails.
cylinderBetween(dhow, [-0.95, 1.03, -2.8], [-0.55, 1.03, -4.4], 0.055, materials.woodDark);
cylinderBetween(dhow, [-0.55, 1.03, -4.4], [0, 1.03, -5.1], 0.055, materials.woodDark);
cylinderBetween(dhow, [0, 1.03, -5.1], [0.64, 1.03, -4.25], 0.055, materials.woodDark);
cylinderBetween(dhow, [-1.18, 1.03, -2.4], [-1.16, 1.03, 1.4], 0.055, materials.woodDark);
// Mast and lateen sail.
addCylinder(dhow, 0.07, 0.1, 5.85, 0, 3.7, -0.25, materials.woodDark, 7);
const sailGeometry = new THREE.BufferGeometry();
sailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0.0, 6.25, -0.2,
0.18, 3.7, 2.0,
0.0, 1.58, 4.8,
0.0, 1.76, -3.55,
0.24, 2.7, -0.35
], 3)
);
sailGeometry.setIndex([
0, 1, 4,
1, 2, 4,
2, 3, 4,
3, 0, 4
]);
sailGeometry.computeVertexNormals();
const sail = new THREE.Mesh(sailGeometry, materials.sail);
sail.castShadow = true;
dhow.add(sail);
cylinderBetween(
dhow,
[0, 6.25, -0.2],
[0, 1.58, 4.8],
0.055,
materials.wood
);
cylinderBetween(
dhow,
[0, 1.76, -3.55],
[0, 6.25, -0.2],
0.045,
materials.wood
);
cylinderBetween(
dhow,
[0, 6.15, -0.2],
[0, 1.1, 5.3],
0.018,
materials.rope,
5
);
cylinderBetween(
dhow,
[0, 6.15, -0.2],
[0, 1.1, -4.8],
0.018,
materials.rope,
5
);
// Cargo aboard the dhow.
addSack(dhow, -0.28, 1.28, -1.25, 1.05);
addSack(dhow, 0.32, 1.23, -0.65, 0.9, materials.sackLight);
addCrate(dhow, -0.3, 1.25, 1.25, 0.68, 0.55, 0.72);
addCrate(dhow, 0.38, 1.2, 1.9, 0.55, 0.48, 0.6);
addJerryCan(dhow, 0.25, 0.92, -2.7);
world.add(dhow);
// ---------------------------------------------------------------------
// Palm trees and distant clouds
// ---------------------------------------------------------------------
function makePalm(x, z, height, lean = 0.5) {
const palm = new THREE.Group();
palm.position.set(x, 1.05, z);
const segments = 6;
let previous = new THREE.Vector3(0, 0, 0);
for (let i = 0; i < segments; i++) {
const t = (i + 1) / segments;
const next = new THREE.Vector3(
lean * t * t,
height * t,
lean * 0.42 * t * t
);
cylinderBetween(
palm,
previous.toArray(),
next.toArray(),
0.22 - i * 0.018,
i % 2 ? materials.wood : materials.woodLight,
7
);
previous = next;
}
const crown = previous;
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2 + 0.2;
const frond = new THREE.Mesh(
new THREE.ConeGeometry(0.38, 2.65, 4),
i % 2 ? materials.green : materials.greenDark
);
frond.scale.z = 0.38;
frond.position.set(
crown.x + Math.sin(angle) * 0.9,
crown.y + 0.06,
crown.z + Math.cos(angle) * 0.9
);
frond.rotation.order = "YXZ";
frond.rotation.y = angle;
frond.rotation.z = Math.PI / 2;
frond.rotateX(0.25);
frond.castShadow = true;
palm.add(frond);
}
for (let i = 0; i < 3; i++) {
const coconut = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.13, 0),
materials.woodDark
);
coconut.position.set(
crown.x + (random() - 0.5) * 0.35,
crown.y - 0.15,
crown.z + (random() - 0.5) * 0.35
);
palm.add(coconut);
}
world.add(palm);
}
makePalm(14.3, 18.3, 6.2, 0.65);
makePalm(16.0, 6.0, 5.5, -0.48);
makePalm(12.8, 25.1, 4.9, 0.5);
const clouds = [];
function makeCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
for (let i = 0; i < 4; i++) {
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.2, 1),
standard(0xf5f0dc)
);
puff.position.set(i * 1.45, random() * 0.35, random() * 0.45);
puff.scale.set(1.4, 0.65 + random() * 0.25, 0.8);
cloud.add(puff);
}
world.add(cloud);
clouds.push(cloud);
}
makeCloud(-23, 15, -26, 1.8);
makeCloud(20, 17, -34, 2.2);
makeCloud(-38, 13, 13, 1.4);
// ---------------------------------------------------------------------
// Working donkey, harness, cart, and guide
// ---------------------------------------------------------------------
const cargoTeam = new THREE.Group();
world.add(cargoTeam);
const donkey = new THREE.Group();
cargoTeam.add(donkey);
const donkeyMaterial = standard(0x77736a);
const donkeyLight = standard(0x969083);
const donkeyDark = standard(0x454844);
const body = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.82, 1),
donkeyMaterial
);
body.position.set(0, 1.45, -0.05);
body.scale.set(0.77, 0.68, 1.17);
body.castShadow = true;
body.receiveShadow = true;
donkey.add(body);
const belly = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.55, 0),
donkeyLight
);
belly.position.set(0, 1.23, 0.05);
belly.scale.set(0.85, 0.62, 1.15);
donkey.add(belly);
const neck = addBox(
donkey,
0.46,
0.82,
0.62,
0,
1.73,
0.88,
donkeyMaterial
);
neck.rotation.x = -0.3;
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.42, 0),
donkeyMaterial
);
head.position.set(0, 2.02, 1.2);
head.scale.set(0.78, 0.92, 1.08);
head.rotation.x = -0.28;
head.castShadow = true;
donkey.add(head);
const muzzle = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.3, 0),
donkeyDark
);
muzzle.position.set(0, 1.84, 1.57);
muzzle.scale.set(0.8, 0.7, 0.9);
muzzle.castShadow = true;
donkey.add(muzzle);
for (const side of [-1, 1]) {
const ear = addCylinder(
donkey,
0.015,
0.13,
0.52,
side * 0.22,
2.48,
1.08,
donkeyMaterial,
4
);
ear.rotation.z = side * 0.22;
ear.rotation.x = -0.12;
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 6, 4),
materials.black
);
eye.position.set(side * 0.3, 2.08, 1.39);
donkey.add(eye);
}
const legs = [];
function makeLeg(x, z, phaseOffset, rear = false) {
const pivot = new THREE.Group();
pivot.position.set(x, 1.28, z);
donkey.add(pivot);
const upper = addCylinder(
pivot,
0.1,
0.12,
0.6,
0,
-0.3,
0,
rear ? donkeyDark : donkeyMaterial,
5
);
const knee = new THREE.Group();
knee.position.y = -0.58;
pivot.add(knee);
addCylinder(
knee,
0.07,
0.085,
0.55,
0,
-0.275,
0,
donkeyMaterial,
5
);
addBox(knee, 0.17, 0.14, 0.22, 0, -0.57, 0.025, donkeyDark);
legs.push({ pivot, knee, offset: phaseOffset });
}
makeLeg(-0.34, 0.56, 0);
makeLeg(0.34, 0.56, Math.PI);
makeLeg(-0.34, -0.61, Math.PI);
makeLeg(0.34, -0.61, 0);
// Tail.
cylinderBetween(
donkey,
[0, 1.48, -0.87],
[0.1, 1.02, -1.08],
0.045,
donkeyDark,
5
);
const tailTuft = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.14, 0),
donkeyDark
);
tailTuft.position.set(0.1, 0.98, -1.1);
donkey.add(tailTuft);
// Harness over the chest and body.
addBox(donkey, 0.79, 0.09, 0.12, 0, 1.62, 0.72, materials.woodDark);
addBox(donkey, 0.1, 0.56, 0.1, -0.28, 1.49, 0.72, materials.woodDark);
addBox(donkey, 0.1, 0.56, 0.1, 0.28, 1.49, 0.72, materials.woodDark);
addBox(donkey, 0.85, 0.09, 0.12, 0, 1.58, -0.3, materials.woodDark);
// Cart.
const cart = new THREE.Group();
cart.position.set(0, 0, -2.45);
donkey.add(cart);
addBox(cart, 1.45, 0.15, 1.72, 0, 0.67, 0, materials.wood);
addBox(cart, 0.11, 0.48, 1.78, -0.72, 0.93, 0, materials.woodLight);
addBox(cart, 0.11, 0.48, 1.78, 0.72, 0.93, 0, materials.woodLight);
addBox(cart, 1.43, 0.48, 0.11, 0, 0.93, -0.83, materials.woodLight);
addBox(cart, 1.43, 0.48, 0.11, 0, 0.93, 0.83, materials.woodLight);
cylinderBetween(
cart,
[-0.52, 0.63, 0.8],
[-0.3, 1.2, 1.8],
0.055,
materials.wood
);
cylinderBetween(
cart,
[0.52, 0.63, 0.8],
[0.3, 1.2, 1.8],
0.055,
materials.wood
);
const wheelGeometry = new THREE.CylinderGeometry(0.48, 0.48, 0.13, 10);
wheelGeometry.rotateZ(Math.PI / 2);
const wheels = [];
for (const side of [-1, 1]) {
const wheel = new THREE.Mesh(wheelGeometry, materials.woodDark);
wheel.position.set(side * 0.79, 0.49, 0.03);
wheel.castShadow = true;
cart.add(wheel);
wheels.push(wheel);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.17, 8),
materials.metal
);
hub.rotation.z = Math.PI / 2;
hub.position.copy(wheel.position);
cart.add(hub);
}
// Cargo on the cart.
addSack(cart, -0.33, 1.02, 0.25, 0.92);
addSack(cart, 0.31, 1.0, -0.2, 0.88, materials.sackLight);
addSack(cart, 0.02, 1.04, 0.47, 0.75);
addCrate(cart, -0.29, 1.04, -0.48, 0.58, 0.55, 0.58);
addCrate(cart, 0.36, 1.02, 0.42, 0.52, 0.48, 0.58);
// Rope around the cargo.
cylinderBetween(
cart,
[-0.54, 1.2, -0.35],
[0.54, 1.2, -0.35],
0.018,
materials.rope,
5
);
// A porter walking beside the donkey.
const guide = new THREE.Group();
guide.position.set(1.25, 0, 0.6);
donkey.add(guide);
const guideLegs = [];
for (const side of [-1, 1]) {
const legPivot = new THREE.Group();
legPivot.position.set(side * 0.13, 0.82, 0);
guide.add(legPivot);
addCylinder(
legPivot,
0.07,
0.085,
0.7,
0,
-0.35,
0,
materials.blue,
5
);
addBox(legPivot, 0.17, 0.12, 0.25, 0, -0.7, 0.04, materials.black);
guideLegs.push({ pivot: legPivot, offset: side < 0 ? 0 : Math.PI });
}
addBox(guide, 0.48, 0.65, 0.3, 0, 1.1, 0, materials.orange);
addCylinder(
guide,
0.09,
0.1,
0.48,
-0.29,
1.12,
0,
materials.skin,
5
).rotation.z = 0.75;
addCylinder(
guide,
0.09,
0.1,
0.5,
0.29,
1.1,
0,
materials.skin,
5
).rotation.z = -0.65;
const guideHead = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.23, 0),
materials.skin
);
guideHead.position.set(0, 1.66, 0.02);
guideHead.castShadow = true;
guide.add(guideHead);
addCylinder(
guide,
0.35,
0.35,
0.08,
0,
1.88,
0,
materials.sackLight,
8
);
addCylinder(
guide,
0.19,
0.25,
0.18,
0,
2.0,
0,
materials.sackLight,
8
);
// ---------------------------------------------------------------------
// Cargo route: dhow landing, into the lane, around the back of town
// ---------------------------------------------------------------------
const route = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-1.8, 1.08, -2.4),
new THREE.Vector3(2.4, 1.08, -0.8),
new THREE.Vector3(5.2, 1.08, 3.2),
new THREE.Vector3(6.1, 1.08, 8.0),
new THREE.Vector3(6.1, 1.08, 14.2),
new THREE.Vector3(6.8, 1.08, 20.2),
new THREE.Vector3(10.1, 1.08, 24.5),
new THREE.Vector3(16.7, 1.08, 23.2),
new THREE.Vector3(18.2, 1.08, 14.4),
new THREE.Vector3(17.4, 1.08, 4.0),
new THREE.Vector3(12.2, 1.08, -1.6),
new THREE.Vector3(-4.7, 1.08, -3.8)
],
true,
"catmullrom",
0.28
);
route.arcLengthDivisions = 500;
// ---------------------------------------------------------------------
// Small shoreline details
// ---------------------------------------------------------------------
for (let i = 0; i < 8; i++) {
const bollard = addCylinder(
world,
0.13,
0.16,
0.55,
-4.8 + i * 0.85,
1.32,
-3.9,
materials.woodDark,
6
);
bollard.rotation.z = (random() - 0.5) * 0.08;
}
// A small distant boat.
const distantBoat = new THREE.Group();
distantBoat.position.set(-19, 0.15, -17);
distantBoat.rotation.y = 0.6;
const distantHull = addBox(
distantBoat,
0.65,
0.45,
3.1,
0,
0.25,
0,
materials.woodDark
);
distantHull.rotation.y = 0.04;
addCylinder(distantBoat, 0.035, 0.05, 3.7, 0, 2.0, 0, materials.wood, 5);
const tinySail = new THREE.Mesh(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 3.65, 0),
new THREE.Vector3(0, 0.8, 1.3),
new THREE.Vector3(0, 0.8, -1.2)
]),
materials.sail
);
tinySail.geometry.setIndex([0, 1, 2]);
tinySail.geometry.computeVertexNormals();
distantBoat.add(tinySail);
world.add(distantBoat);
// ---------------------------------------------------------------------
// Custom camera controls
// ---------------------------------------------------------------------
const defaultTarget = new THREE.Vector3(2.2, 1.8, 4.0);
const currentTarget = defaultTarget.clone();
const view = {
theta: 0.61,
phi: 1.12,
radius: 30
};
let following = false;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
const followButton = document.getElementById("follow");
const resetButton = document.getElementById("reset");
function resetView() {
view.theta = 0.61;
view.phi = 1.12;
view.radius = 30;
following = false;
currentTarget.copy(defaultTarget);
followButton.classList.remove("active");
followButton.textContent = "Follow cargo";
}
resetButton.addEventListener("click", resetView);
followButton.addEventListener("click", () => {
following = !following;
followButton.classList.toggle("active", following);
followButton.textContent = following ? "Wide view" : "Follow cargo";
});
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
if (event.shiftKey && !following) {
const right = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, new THREE.Vector3(), new THREE.Vector3());
currentTarget.addScaledVector(right, -dx * view.radius * 0.0012);
currentTarget.y += dy * view.radius * 0.0008;
} else {
view.theta -= dx * 0.005;
view.phi -= dy * 0.004;
view.phi = THREE.MathUtils.clamp(view.phi, 0.32, 1.43);
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius *= Math.exp(event.deltaY * 0.001);
view.radius = THREE.MathUtils.clamp(view.radius, 12, 55);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const tangent = new THREE.Vector3();
const followTarget = new THREE.Vector3();
const cameraOffset = new THREE.Vector3();
let frame = 0;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const dt = Math.min(clock.getDelta(), 0.05);
// Low-poly water.
for (let i = 0; i < waterPositions.count; i++) {
const x = waterPositions.getX(i);
const z = waterPositions.getZ(i);
const wave =
Math.sin(x * 0.24 + elapsed * 0.8) * 0.075 +
Math.cos(z * 0.18 + elapsed * 0.62) * 0.055 +
Math.sin((x + z) * 0.12 - elapsed * 0.45) * 0.035;
waterPositions.setY(i, wave);
}
waterPositions.needsUpdate = true;
if (frame % 3 === 0) {
waterGeometry.computeVertexNormals();
}
// Foam gently follows the surf.
foam.forEach((foamMesh, index) => {
foamMesh.position.y = 0.075 + Math.sin(elapsed * 1.3 + index) * 0.025;
foamMesh.material.opacity = 0.39 + Math.sin(elapsed + index * 0.8) * 0.12;
});
// Dhow rides the swell.
dhow.position.y = Math.sin(elapsed * 0.72) * 0.075;
dhow.rotation.z = Math.sin(elapsed * 0.57) * 0.025;
dhow.rotation.x = Math.cos(elapsed * 0.64) * 0.012;
// Cargo team moves along the closed working route.
const progress = (elapsed * 0.0135) % 1;
route.getPointAt(progress, cargoTeam.position);
route.getTangentAt(progress, tangent);
cargoTeam.rotation.y = Math.atan2(tangent.x, tangent.z);
const gait = elapsed * 8.2;
const walkingBob = Math.sin(gait * 2) * 0.035;
legs.forEach((leg, index) => {
const stride = Math.sin(gait + leg.offset);
leg.pivot.rotation.x = stride * 0.42;
leg.knee.rotation.x = Math.max(0, -stride) * 0.42;
});
guideLegs.forEach((leg) => {
leg.pivot.rotation.x = Math.sin(gait * 0.92 + leg.offset) * 0.34;
});
body.position.y = 1.45 + walkingBob;
belly.position.y = 1.23 + walkingBob;
cart.position.y = walkingBob * 0.35;
wheels.forEach((wheel, index) => {
wheel.rotation.x -= elapsed * dt * (index === 0 ? 1.8 : 1.8);
});
// Clouds drift slowly.
clouds.forEach((cloud, index) => {
cloud.position.x += dt * (0.08 + index * 0.025);
if (cloud.position.x > 45) cloud.position.x = -45;
});
// Update the camera without using any external controls addon.
if (following) {
followTarget.copy(cargoTeam.position);
followTarget.y += 1.6;
currentTarget.lerp(followTarget, 0.055);
}
const sinPhi = Math.sin(view.phi);
cameraOffset.set(
view.radius * sinPhi * Math.sin(view.theta),
view.radius * Math.cos(view.phi),
view.radius * sinPhi * Math.cos(view.theta)
);
camera.position.copy(currentTarget).add(cameraOffset);
camera.lookAt(currentTarget);
renderer.render(scene, camera);
frame++;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// Put the camera at its initial position before the first render.
camera.position.set(19, 13, 27);
camera.lookAt(defaultTarget);
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => document.getElementById("loading").remove(), 600);
});
</script>
</body>
</html>
```