Prompt specification
Build or customize the Three.js 3D scene "Porter moving goods through a shaded Mombasa 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: Porter moving goods through a shaded Mombasa lane
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/porter-moving-goods-through-a-shaded-mombasa-lane-x2942
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Mombasa Old Town's lanes and harbor approaches. Create a compact referenced lane vignette with goods carrier, shop entrance, and overhanging balcony. Keep enough clearance for both delivery and pedestrian passage. Voxel style.
Working Three.js Starter (porter-moving-goods-through-a-shaded-mombasa-lane-x2942):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#173f43">
<title>Mombasa Old Town — Between Shade & Salt</title>
<style>
:root {
--ink: #173f43;
--paper: rgba(248, 238, 214, 0.92);
--line: rgba(23, 63, 67, 0.18);
--coral: #b96045;
--gold: #c89445;
--blue: #377d83;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 66% 19%, rgba(255, 241, 190, 0.9), transparent 22%),
linear-gradient(#9fc6c3 0%, #d9cfad 49%, #d9b77f 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.title-card {
position: fixed;
z-index: 5;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(58, 44, 25, 0.16);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--coral);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: var(--coral);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 48px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 330px;
margin: 13px 0 0;
color: rgba(23, 63, 67, 0.78);
font-size: 12px;
line-height: 1.55;
}
.view-panel {
position: fixed;
z-index: 6;
right: 24px;
bottom: 24px;
width: 255px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 14px 38px rgba(58, 44, 25, 0.16);
backdrop-filter: blur(12px);
}
.panel-label {
margin: 0 0 10px;
color: rgba(23, 63, 67, 0.62);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.views {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
}
button {
appearance: none;
min-height: 34px;
padding: 8px 10px;
border: 1px solid rgba(23, 63, 67, 0.15);
border-radius: 2px;
background: rgba(255, 255, 255, 0.35);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.7);
transform: translateY(-1px);
}
button.active {
border-color: var(--ink);
background: var(--ink);
color: #f7e8c7;
}
.reference-list {
display: grid;
gap: 8px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.reference-item {
display: grid;
grid-template-columns: 9px 1fr;
align-items: center;
gap: 9px;
color: rgba(23, 63, 67, 0.76);
font-size: 10px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 1px;
background: var(--coral);
}
.swatch.gold {
background: var(--gold);
}
.swatch.blue {
background: var(--blue);
}
.controls-hint {
position: fixed;
z-index: 5;
left: 24px;
bottom: 24px;
padding: 9px 12px;
border: 1px solid rgba(23, 63, 67, 0.12);
border-radius: 2px;
background: rgba(248, 238, 214, 0.76);
color: rgba(23, 63, 67, 0.72);
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(8px);
}
.clearance {
position: fixed;
z-index: 5;
top: 24px;
right: 24px;
padding: 10px 13px;
border-left: 3px solid var(--coral);
background: rgba(248, 238, 214, 0.78);
color: rgba(23, 63, 67, 0.78);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
backdrop-filter: blur(8px);
pointer-events: none;
}
.loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #d9cfad;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
h1 {
max-width: 280px;
font-size: 31px;
}
.subtitle {
max-width: 290px;
font-size: 10px;
}
.clearance {
display: none;
}
.view-panel {
right: 14px;
bottom: 14px;
width: 210px;
padding: 11px;
}
.reference-list {
display: none;
}
.controls-hint {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 242px);
font-size: 8px;
line-height: 1.5;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Constructing the old town</div>
<header class="title-card">
<div class="eyebrow">Mombasa · Old Town edge</div>
<h1>Between Shade<br>& Salt</h1>
<p class="subtitle">
A compact voxel vignette of a Swahili trading lane: coral-stone shop,
shaded balcony, goods carrier, and the harbor waiting at the far end.
</p>
</header>
<div class="clearance">5.4 m clear lane · shared passage</div>
<aside class="view-panel" aria-label="Scene views">
<p class="panel-label">Reference viewpoints</p>
<div class="views">
<button class="active" data-view="lane">Lane</button>
<button data-view="harbor">Harbor</button>
<button data-view="shop">Shop</button>
<button data-view="balcony">Balcony</button>
<button data-view="plan">Plan</button>
</div>
<div class="reference-list">
<div class="reference-item">
<span class="swatch"></span>
<span>Coral-stone masonry & shaded shopfront</span>
</div>
<div class="reference-item">
<span class="swatch gold"></span>
<span>Timber balcony & warm upper storey</span>
</div>
<div class="reference-item">
<span class="swatch blue"></span>
<span>Blue water, cargo, and dhow beyond</span>
</div>
</div>
</aside>
<div class="controls-hint">
Drag to orbit · wheel / pinch to zoom · right-drag to pan
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.querySelector("#loading");
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.domElement.setAttribute("aria-label", "Interactive Mombasa Old Town voxel scene");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd5c6a7, 18, 48);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xc9e5e2, 0x9e704b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0a1, 3.35);
sun.position.set(-9, 16, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc6d1, 0.75);
fill.position.set(8, 7, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
const M = {
coralStone: standard(0xb77958),
coralDark: standard(0x945d48),
plasterA: standard(0xe0b477),
plasterB: standard(0xcf8c65),
plasterC: standard(0xe5c795),
plasterD: standard(0xc77d58),
cream: standard(0xefdbad),
wood: standard(0x624638),
woodLight: standard(0x8c6948),
darkWood: standard(0x3f332b),
teal: standard(0x3f7d79),
blue: standard(0x3b6f85),
red: standard(0xa94f3f),
dark: standard(0x273638),
interior: standard(0x343330),
sack: standard(0xc5a66f),
rope: standard(0xe1c693),
skin: standard(0x8b593b),
cloth: standard(0xf0dfb9),
water: standard(0x4e9296, {
roughness: 0.36,
metalness: 0.05
}),
sand: standard(0xc9b184),
leaf: standard(0x617a49),
leafLight: standard(0x7c8f51)
};
const geometries = {
box: new THREE.BoxGeometry(1, 1, 1),
plane: new THREE.PlaneGeometry(1, 1)
};
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(geometries.box, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function plane(w, h, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(geometries.plane, material);
mesh.scale.set(w, h, 1);
mesh.position.set(x, y, z);
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let seed = 91827;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
// -------------------------------------------------------------------------
// Voxel lane paving
// -------------------------------------------------------------------------
const road = box(5.55, 0.18, 17.4, M.sand, 0, -0.12, -0.55);
road.receiveShadow = true;
const columns = 7;
const rows = 19;
const cobbleGeometry = new THREE.BoxGeometry(0.73, 0.11, 0.82);
const cobbleMaterial = standard(0xc3b28e, { vertexColors: true });
const cobbles = new THREE.InstancedMesh(
cobbleGeometry,
cobbleMaterial,
columns * rows
);
const dummy = new THREE.Object3D();
const cobbleColor = new THREE.Color();
let cobbleIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = (column - (columns - 1) / 2) * 0.79;
const z = -8.55 + row * 0.92;
const offset = row % 2 ? 0.07 : -0.03;
dummy.position.set(
x + offset + range(-0.025, 0.025),
range(-0.005, 0.035),
z + range(-0.025, 0.025)
);
dummy.rotation.set(0, range(-0.018, 0.018), 0);
dummy.scale.set(range(0.93, 1.04), 1, range(0.94, 1.03));
dummy.updateMatrix();
cobbles.setMatrixAt(cobbleIndex, dummy.matrix);
cobbleColor.setHSL(
range(0.095, 0.125),
range(0.22, 0.36),
range(0.61, 0.72)
);
cobbles.setColorAt(cobbleIndex, cobbleColor);
cobbleIndex++;
}
}
cobbles.instanceMatrix.needsUpdate = true;
cobbles.instanceColor.needsUpdate = true;
cobbles.castShadow = false;
cobbles.receiveShadow = true;
scene.add(cobbles);
// -------------------------------------------------------------------------
// Lane architecture
// -------------------------------------------------------------------------
function building(side, z, depth, height, material) {
const centerX = side * 4.05;
box(2.7, 1.55, depth, M.coralStone, centerX, 0.775, z);
box(
2.7,
height - 1.55,
depth,
material,
centerX,
1.55 + (height - 1.55) / 2,
z
);
box(2.92, 0.22, depth + 0.16, M.cream, centerX, height + 0.03, z);
box(2.78, 0.38, depth + 0.08, M.plasterC, centerX, height + 0.26, z);
// Small parapet blocks create a stepped roof silhouette.
const parapetCount = Math.max(2, Math.floor(depth / 2.6));
for (let i = 0; i < parapetCount; i++) {
const pz = z - depth / 2 + 0.65 + (i * (depth - 1.3)) / (parapetCount - 1);
box(2.72, range(0.3, 0.62), 0.24, material, centerX, height + 0.52, pz);
}
// Weathered plaster patches on the lane-facing elevation.
for (let i = 0; i < 8; i++) {
box(
0.035,
range(0.25, 0.85),
range(0.35, 1.25),
random() > 0.5 ? M.plasterD : M.cream,
side * 2.68,
range(2.1, height - 0.6),
z + range(-depth / 2 + 0.35, depth / 2 - 0.35)
);
}
}
building(-1, 4.2, 6.6, 7.4, M.plasterB);
building(-1, -3.3, 6.8, 8.5, M.plasterA);
building(1, 2.4, 9.2, 8.1, M.plasterC);
building(1, -4.8, 4.6, 6.3, M.plasterD);
function addWindow(side, z, y, width = 1.1, height = 1.45) {
const x = side * 2.59;
box(0.085, height, width, M.interior, x, y, z);
box(0.16, height + 0.18, 0.13, M.woodLight, x, y, z - width / 2);
box(0.16, height + 0.18, 0.13, M.woodLight, x, y, z + width / 2);
box(0.16, 0.13, width + 0.16, M.woodLight, x, y - height / 2, z);
box(0.16, 0.13, width + 0.16, M.woodLight, x, y + height / 2, z);
// Louvered timber shutters folded against the opening.
box(
0.105,
height * 0.92,
width * 0.34,
M.teal,
x - side * 0.035,
y,
z - width * 0.31
);
box(
0.105,
height * 0.92,
width * 0.34,
M.woodLight,
x - side * 0.035,
y,
z + width * 0.31
);
for (let i = 0; i < 4; i++) {
box(
0.125,
0.035,
width * 0.31,
M.wood,
x - side * 0.045,
y - height * 0.3 + i * height * 0.2,
z - width * 0.31
);
}
}
addWindow(-1, 1.45, 5.25, 0.9, 1.35);
addWindow(-1, 6.0, 5.0, 1.1, 1.5);
addWindow(-1, 5.8, 6.45, 0.7, 0.8);
addWindow(-1, -1.25, 6.55, 1.1, 1.5);
addWindow(-1, -4.75, 4.9, 1.0, 1.35);
addWindow(1, 4.8, 5.7, 1.0, 1.4);
addWindow(1, 2.0, 6.7, 0.85, 1.2);
addWindow(1, 0.45, 5.85, 1.15, 1.45);
addWindow(1, -4.6, 4.25, 0.9, 1.25);
function balcony(side, z, floorY, width = 2.6) {
const wallX = side * 2.7;
const innerX = side * 1.03;
const centerX = (wallX + innerX) / 2;
box(wallX - innerX, 0.18, width, M.woodLight, centerX, floorY, z);
box(wallX - innerX, 0.13, width + 0.08, M.darkWood, centerX, floorY - 0.13, z);
// Stepped brackets preserve the blocky construction language.
for (const offset of [-width * 0.31, width * 0.31]) {
box(0.18, 0.68, 0.18, M.wood, side * 2.43, floorY - 0.48, z + offset);
box(0.56, 0.16, 0.18, M.wood, side * 2.12, floorY - 0.25, z + offset);
box(0.48, 0.16, 0.18, M.wood, side * 1.87, floorY - 0.54, z + offset);
}
box(0.12, 0.12, width, M.teal, innerX, floorY + 0.98, z);
box(0.12, 0.08, width, M.wood, innerX, floorY + 0.48, z);
const postCount = 5;
for (let i = 0; i < postCount; i++) {
const pz = z - width / 2 + 0.12 + (i * (width - 0.24)) / (postCount - 1);
box(0.11, 0.98, 0.11, M.teal, innerX, floorY + 0.5, pz);
}
box(0.12, 0.11, width, M.teal, innerX, floorY + 0.98, z);
box(0.1, 0.85, 0.1, M.wood, innerX, floorY + 0.48, z - width / 2);
box(0.1, 0.85, 0.1, M.wood, innerX, floorY + 0.48, z + width / 2);
// A folded cloth provides a small inhabited accent.
box(
0.08,
1.1,
0.7,
M.cloth,
innerX - side * 0.03,
floorY - 0.5,
z + width * 0.24
);
}
balcony(-1, -2.35, 4.15, 2.7);
balcony(1, 0.55, 4.55, 2.65);
// -------------------------------------------------------------------------
// Recessed shop entrance
// -------------------------------------------------------------------------
const shopZ = 3.25;
box(0.1, 2.72, 2.5, M.interior, -2.61, 1.38, shopZ);
box(0.22, 2.95, 0.2, M.coralDark, -2.49, 1.47, shopZ - 1.33);
box(0.22, 2.95, 0.2, M.coralDark, -2.49, 1.47, shopZ + 1.33);
box(0.25, 0.2, 2.86, M.coralDark, -2.46, 2.91, shopZ);
// Stepped coral-stone lintel.
box(0.25, 0.24, 1.1, M.coralStone, -2.45, 3.12, shopZ);
box(0.25, 0.24, 0.55, M.coralStone, -2.45, 3.33, shopZ);
box(0.25, 0.23, 2.9, M.cream, -2.45, 3.53, shopZ);
// Partly open timber door.
box(0.11, 2.4, 0.82, M.wood, -2.36, 1.27, shopZ - 0.72);
box(0.13, 2.4, 0.12, M.woodLight, -2.29, 1.27, shopZ - 1.13);
box(0.08, 0.12, 0.5, M.darkWood, -2.27, 1.28, shopZ - 0.72);
// Shallow shop awning, leaving the lane open below.
box(1.55, 0.12, 3.05, M.cloth, -1.9, 3.22, shopZ);
box(1.55, 0.24, 0.12, M.red, -1.9, 3.13, shopZ - 1.43);
box(1.55, 0.24, 0.12, M.red, -1.9, 3.13, shopZ + 1.43);
for (const offset of [-1.12, 1.12]) {
box(0.16, 0.16, 0.16, M.darkWood, -1.35, 3.06, shopZ + offset);
box(0.14, 0.85, 0.14, M.wood, -2.45, 2.7, shopZ + offset);
}
// Shop counter, sacks, and a low cargo chest.
box(0.82, 0.67, 1.25, M.woodLight, -2.22, 0.34, shopZ + 0.37);
box(0.9, 0.12, 1.35, M.wood, -2.2, 0.73, shopZ + 0.37);
box(0.55, 0.42, 0.58, M.sack, -2.25, 0.92, shopZ + 0.52);
box(0.5, 0.38, 0.5, M.sack, -2.24, 1.31, shopZ + 0.51);
box(0.58, 0.36, 0.68, M.woodLight, -2.2, 0.28, shopZ - 0.63);
// A warm lantern under the awning.
box(0.28, 0.38, 0.28, M.darkWood, -1.7, 2.72, shopZ - 1.1);
const lampMaterial = standard(0xffc76b, {
emissive: 0xff9c35,
emissiveIntensity: 1.3
});
box(0.18, 0.22, 0.18, lampMaterial, -1.7, 2.7, shopZ - 1.1);
const shopLight = new THREE.PointLight(0xffb24f, 11, 5, 2);
shopLight.position.set(-1.65, 2.65, shopZ - 1.05);
scene.add(shopLight);
function labelTexture(text, background = "#244f50", foreground = "#f4dfb7") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.lineWidth = 7;
context.strokeRect(12, 12, canvas.width - 24, canvas.height - 24);
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "700 62px Georgia";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 4);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const shopSignMaterial = new THREE.MeshBasicMaterial({
map: labelTexture("AMANI GOODS"),
side: THREE.DoubleSide
});
const shopSign = plane(2.2, 0.5, shopSignMaterial, -2.33, 3.94, shopZ);
shopSign.rotation.y = Math.PI / 2;
// -------------------------------------------------------------------------
// Goods carrier in the middle of the lane
// -------------------------------------------------------------------------
const carrier = new THREE.Group();
carrier.position.set(0.35, 0.03, 1.35);
carrier.rotation.y = -0.24;
scene.add(carrier);
const carrierShoes = standard(0x40352d);
const carrierShirt = standard(0x347b78);
const carrierWrap = standard(0xc8924e);
box(0.25, 0.16, 0.46, carrierShoes, -0.17, 0.08, -0.05, carrier);
box(0.25, 0.16, 0.46, carrierShoes, 0.17, 0.08, 0.05, carrier);
box(0.22, 0.72, 0.24, M.darkWood, -0.16, 0.48, 0, carrier);
box(0.22, 0.72, 0.24, M.darkWood, 0.16, 0.48, 0, carrier);
box(0.64, 0.76, 0.38, carrierShirt, 0, 1.17, 0, carrier);
box(0.68, 0.15, 0.42, carrierWrap, 0, 0.88, 0, carrier);
box(0.39, 0.4, 0.36, M.skin, 0, 1.86, 0, carrier);
box(0.43, 0.16, 0.4, carrierWrap, 0, 2.06, 0, carrier);
// Raised arms support the wrapped load.
box(0.18, 0.72, 0.18, M.skin, -0.39, 1.83, 0, carrier);
box(0.18, 0.72, 0.18, M.skin, 0.39, 1.83, 0, carrier);
box(0.2, 0.16, 0.22, M.skin, -0.39, 2.22, 0, carrier);
box(0.2, 0.16, 0.22, M.skin, 0.39, 2.22, 0, carrier);
const cargo = box(0.82, 0.48, 0.62, carrierWrap, 0, 2.42, 0, carrier);
box(0.13, 0.5, 0.64, M.rope, -0.18, 2.42, 0, carrier);
box(0.13, 0.5, 0.64, M.rope, 0.18, 2.42, 0, carrier);
// A small stool and empty handcart stay inside the shop recess.
box(0.52, 0.12, 0.52, M.wood, -2.23, 0.13, 4.35);
box(0.1, 0.42, 0.1, M.wood, -2.23, 0.32, 4.35);
// -------------------------------------------------------------------------
// Harbor approach, quay, dhow, cargo, and palms
// -------------------------------------------------------------------------
box(36, 0.12, 24, M.water, 0, -0.12, -20.5);
box(11, 0.52, 2.35, M.coralStone, 0, -0.05, -9.0);
box(11.1, 0.16, 2.45, M.cream, 0, 0.26, -9.0);
for (const x of [-2.25, 0, 2.25]) {
box(0.22, 0.7, 0.22, M.darkWood, x, 0.65, -9.55);
box(0.3, 0.12, 0.3, M.woodLight, x, 0.98, -9.55);
}
// Harbor warehouse blocks.
box(10, 3.7, 4.2, M.plasterD, -4.8, 1.65, -21);
box(6.5, 2.8, 3.5, M.plasterA, 4.8, 1.2, -20);
box(10.2, 0.2, 4.4, M.coralDark, -4.8, 3.62, -21);
box(6.7, 0.2, 3.7, M.coralDark, 4.8, 2.7, -20);
for (let i = 0; i < 5; i++) {
box(
1.3,
0.75,
1.1,
i % 2 ? M.teal : M.red,
-6.5 + i * 1.45,
0.78,
-10.1 - (i % 2) * 0.15
);
}
// Simple harbor crane.
box(0.34, 5.5, 0.34, M.darkWood, 6.3, 2.6, -12.8);
box(4.6, 0.3, 0.3, M.darkWood, 4.45, 5.15, -12.8);
box(0.12, 2.2, 0.12, M.woodLight, 2.35, 4.15, -12.8);
box(0.8, 0.45, 0.65, M.darkWood, 2.35, 2.98, -12.8);
// Voxel dhow.
const dhow = new THREE.Group();
dhow.position.set(1.65, 0.08, -14.2);
scene.add(dhow);
box(4.3, 0.48, 1.15, M.wood, 0, 0.18, 0, dhow);
box(3.4, 0.34, 1.3, M.woodLight, 0, 0.43, 0, dhow);
box(0.7, 0.7, 0.95, M.wood, 2.2, 0.36, 0, dhow);
box(0.55, 0.52, 0.82, M.wood, -2.25, 0.32, 0, dhow);
box(0.16, 4.25, 0.16, M.darkWood, 0.3, 2.35, 0, dhow);
box(2.55, 0.12, 0.14, M.darkWood, 0.25, 3.92, 0, dhow);
// Stepped lateen-like sail.
box(2.25, 0.92, 0.09, M.cloth, 0.25, 2.0, 0.18, dhow);
box(1.78, 0.9, 0.09, M.cloth, 0.25, 2.92, 0.18, dhow);
box(1.25, 0.88, 0.09, M.cloth, 0.25, 3.8, 0.18, dhow);
box(0.1, 3.8, 0.11, M.red, -0.25, 2.85, 0.24, dhow);
function palm(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
for (let i = 0; i < 6; i++) {
box(
0.3 - i * 0.018,
0.72,
0.3 - i * 0.018,
M.woodLight,
i * 0.035,
0.36 + i * 0.68,
0,
group
);
}
const crownY = 4.35;
box(0.45, 0.35, 0.45, M.wood, 0.18, crownY, 0, group);
const fronds = [
[1.65, 0.16, 0.2, -0.25],
[-1.55, 0.16, 0.2, 0.25],
[0.2, 0.16, 1.7, 0],
[0.2, 0.16, -1.6, 0],
[1.2, 0.16, 1.15, -0.25],
[-1.15, 0.16, -1.1, 0.25]
];
for (const [fx, fy, fz, ry] of fronds) {
const frond = box(
1.7,
0.17,
0.28,
random() > 0.45 ? M.leaf : M.leafLight,
fx * 0.55,
crownY + 0.2,
fz * 0.55,
group
);
frond.rotation.y = ry;
frond.rotation.z = fx > 0 ? -0.13 : 0.13;
}
}
palm(-4.7, -9.1, 1.05);
palm(5.15, -10.0, 0.9);
palm(-7.2, -13.0, 0.8);
// Small harbor reflections, all kept as thin voxel slabs.
const reflections = [];
for (let i = 0; i < 18; i++) {
const material = standard(0xa9c5b9, {
transparent: true,
opacity: range(0.15, 0.38),
roughness: 0.5
});
const reflection = box(
range(0.4, 1.5),
0.025,
range(0.08, 0.18),
material,
range(-7, 7),
0.02,
range(-17, -10.5)
);
reflections.push({ mesh: reflection, speed: range(0.08, 0.2), phase: range(0, 6) });
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, and touch pinch
// -------------------------------------------------------------------------
const goal = {
yaw: 0.015,
pitch: 0.31,
distance: 16.5,
target: new THREE.Vector3(0, 2.15, -2.4)
};
const current = {
yaw: goal.yaw,
pitch: goal.pitch,
distance: goal.distance,
target: goal.target.clone()
};
const pointers = new Map();
let dragMode = "orbit";
let lastPinchDistance = 0;
function updateCamera() {
const horizontal = Math.cos(current.pitch) * current.distance;
camera.position.set(
current.target.x + Math.sin(current.yaw) * horizontal,
current.target.y + Math.sin(current.pitch) * current.distance,
current.target.z + Math.cos(current.yaw) * horizontal
);
camera.lookAt(current.target);
}
updateCamera();
function panCamera(dx, dy) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const up = new THREE.Vector3().crossVectors(right, forward).normalize();
const scale = current.distance * 0.0012;
goal.target.addScaledVector(right, -dx * scale);
goal.target.addScaledVector(up, dy * scale);
goal.target.x = THREE.MathUtils.clamp(goal.target.x, -5.5, 5.5);
goal.target.y = THREE.MathUtils.clamp(goal.target.y, 0.6, 6.5);
goal.target.z = THREE.MathUtils.clamp(goal.target.z, -11, 10);
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0) {
goal.distance = THREE.MathUtils.clamp(
goal.distance * (lastPinchDistance / distance),
5.5,
30
);
}
lastPinchDistance = distance;
return;
}
if (dragMode === "pan") {
panCamera(dx, dy);
} else {
goal.yaw -= dx * 0.0045;
goal.pitch = THREE.MathUtils.clamp(
goal.pitch + dy * 0.0035,
0.08,
1.18
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
goal.distance = THREE.MathUtils.clamp(
goal.distance * Math.exp(event.deltaY * 0.001),
5.5,
30
);
},
{ passive: false }
);
const views = {
lane: {
yaw: 0.015,
pitch: 0.31,
distance: 16.5,
target: [0, 2.15, -2.4]
},
harbor: {
yaw: 0.08,
pitch: 0.18,
distance: 12.8,
target: [0, 2.2, -8.2]
},
shop: {
yaw: 0.52,
pitch: 0.18,
distance: 8.8,
target: [-1.6, 1.8, 3.15]
},
balcony: {
yaw: 0.48,
pitch: 0.17,
distance: 9.2,
target: [-1.45, 3.6, -2.25]
},
plan: {
yaw: 0,
pitch: 0.88,
distance: 23.5,
target: [0, 0.8, -0.8]
}
};
const buttons = [...document.querySelectorAll("[data-view]")];
function selectView(name) {
const view = views[name];
goal.yaw = view.yaw;
goal.pitch = view.pitch;
goal.distance = view.distance;
goal.target.set(...view.target);
buttons.forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
buttons.forEach(button => {
button.addEventListener("click", () => selectView(button.dataset.view));
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
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();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const smoothing = 1 - Math.exp(-delta * 6);
current.yaw = THREE.MathUtils.lerp(current.yaw, goal.yaw, smoothing);
current.pitch = THREE.MathUtils.lerp(current.pitch, goal.pitch, smoothing);
current.distance = THREE.MathUtils.lerp(
current.distance,
goal.distance,
smoothing
);
current.target.lerp(goal.target, smoothing);
updateCamera();
// Quiet, continuous signs of life without obstructing the passage.
carrier.position.y = 0.03 + Math.sin(elapsed * 2.1) * 0.018;
carrier.rotation.z = Math.sin(elapsed * 1.25) * 0.008;
dhow.position.y = 0.08 + Math.sin(elapsed * 1.15) * 0.035;
dhow.rotation.z = Math.sin(elapsed * 0.72) * 0.006;
for (const reflection of reflections) {
reflection.mesh.position.x += Math.sin(elapsed * 0.4 + reflection.phase) * 0.0015;
reflection.mesh.scale.x = 1 + Math.sin(elapsed * reflection.speed + reflection.phase) * 0.15;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
});
</script>
</body>
</html>
```