Prompt specification
Build or customize the Three.js 3D scene "Lamu waterfront and interior-lane slice" 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: Lamu waterfront and interior-lane slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/lamu-waterfront-and-interior-lane-slice-x2935
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Lamu Old Town's waterfront and lanes. Build a bounded voxel scene with referenced waterfront facades, narrow lanes, and a small courtyard opening. Make the pedestrian-scale network legible without adding inappropriate broad vehicle roads. Voxel style.
Working Three.js Starter (lamu-waterfront-and-interior-lane-slice-x2935):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#d8cdb6">
<title>Lamu Old Town — Voxel Waterfront</title>
<style>
:root {
--ink: #342c27;
--paper: rgba(249, 242, 224, 0.91);
--line: rgba(66, 50, 38, 0.18);
--accent: #9d513e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8cec5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 14px 40px rgba(65, 48, 32, 0.13);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title {
top: 22px;
left: 22px;
max-width: 340px;
padding: 17px 19px 16px;
border-radius: 3px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 4vw, 38px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
#title p {
margin: 10px 0 0;
color: rgba(52, 44, 39, 0.72);
font-size: 12px;
line-height: 1.5;
}
#views {
top: 22px;
right: 22px;
display: flex;
gap: 4px;
padding: 5px;
border-radius: 3px;
}
button {
appearance: none;
border: 0;
border-radius: 2px;
padding: 9px 11px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
}
button:hover,
button:focus-visible {
outline: none;
background: rgba(157, 81, 62, 0.1);
color: var(--accent);
}
#legend {
bottom: 22px;
left: 22px;
display: flex;
align-items: center;
gap: 17px;
padding: 10px 13px;
border-radius: 3px;
color: rgba(52, 44, 39, 0.74);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
}
.swatch {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 6px;
vertical-align: -1px;
}
#hint {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 10;
max-width: 280px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 3px;
background: rgba(46, 50, 44, 0.72);
color: #f5eedf;
font-size: 10px;
line-height: 1.5;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #d8cdb6;
color: #6e4a38;
font-family: Georgia, serif;
font-size: 18px;
transition: opacity 0.5s ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#title {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 13px 15px;
}
#title p {
display: none;
}
#views {
top: auto;
right: 12px;
bottom: 62px;
}
#legend {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: space-between;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="title" class="panel">
<div class="eyebrow">Kenya · Swahili Coast</div>
<h1>Lamu Old Town</h1>
<p>
A bounded voxel study of coral-plaster waterfront houses, shaded lanes,
dhow moorings, and a hidden courtyard.
</p>
</section>
<nav id="views" class="panel" aria-label="Camera views">
<button data-view="overview">Overview</button>
<button data-view="lane">Lane</button>
<button data-view="court">Courtyard</button>
<button data-view="plan">Plan</button>
</nav>
<div id="legend" class="panel">
<span><i class="swatch" style="background:#c66f56"></i>Coral plaster</span>
<span><i class="swatch" style="background:#c6b38d"></i>Foot lanes</span>
<span><i class="swatch" style="background:#5f9695"></i>Tidal basin</span>
</div>
<div id="hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom · Arrow keys to orbit
</div>
<div id="loading">Building the old town…</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 container = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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.06;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b8cec5");
scene.fog = new THREE.Fog("#b8cec5", 45, 88);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemisphere = new THREE.HemisphereLight("#fff4d7", "#61736a", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#ffe0ae", 3.2);
sun.position.set(-18, 30, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 32;
sun.shadow.camera.bottom = -32;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const bounce = new THREE.DirectionalLight("#8fb6b8", 0.65);
bounce.position.set(18, 9, -22);
scene.add(bounce);
// ------------------------------------------------------------
// Shared geometry and materials
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, roughness = 0.86, metalness = 0) {
const key = `${color}|${roughness}|${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
})
);
}
return materialCache.get(key);
}
function box(w, h, d, x, y, z, mat, parent = scene, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
const M = {
stone: material("#b3a487"),
stoneLight: material("#c6b89a"),
stoneDark: material("#8f816d"),
path: material("#c8b792"),
pathLight: material("#d7c8a7"),
pathDark: material("#b5a17e"),
timber: material("#493027"),
timberLight: material("#77503a"),
dark: material("#25201d"),
brass: material("#a88742", 0.55, 0.25),
roof: material("#cfb27a"),
roofLight: material("#dfc995"),
cream: material("#eee0bd"),
coral: material("#c66f56"),
white: material("#eee8d4"),
shutter: material("#315c60"),
shutterBlue: material("#436d78"),
leaf: material("#4f704c"),
leafLight: material("#789060"),
terracotta: material("#a85d45"),
cloth: material("#eee2c5"),
clothRed: material("#a44c3e"),
water: material("#5f9695", 0.45, 0.05),
waterLight: material("#8bb5ac", 0.55),
waterDark: material("#477c80", 0.5),
sand: material("#d8c9a3"),
black: material("#171514")
};
let randomSeed = 41291;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6D2B79F5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
const pick = array => array[Math.floor(random() * array.length)];
const range = (a, b) => a + random() * (b - a);
const plasterColors = [
"#c66f56", "#d78668", "#e2a47d", "#dfbd88",
"#e8d4aa", "#c9855f", "#bd765e", "#e0c7a0"
];
const shutterColors = ["#315c60", "#436d78", "#536c54", "#6c5144"];
// ------------------------------------------------------------
// Bounded island, water, quay, and paths
// ------------------------------------------------------------
// Deep plinth makes the scene read as a collectible diorama.
box(33.2, 0.8, 34.2, 0, -1.1, -4.6, M.stoneDark);
box(33.0, 1.05, 24.2, 0, -0.48, 0, M.stone);
box(31.9, 0.16, 23.9, 0, 0.10, 0, M.sand);
// Finite tidal basin.
box(33.0, 0.72, 10.0, 0, -0.48, -17.0, M.waterDark);
box(32.7, 0.44, 9.7, 0, -0.13, -17.0, M.water);
// Stone quay.
box(32.0, 1.25, 0.72, 0, -0.15, -11.85, M.stoneDark);
box(32.1, 0.22, 0.80, 0, 0.46, -11.85, M.stoneLight);
function path(w, d, x, z, mat = M.path) {
return box(w, 0.09, d, x, 0.23, z, mat, scene, false, true);
}
// Waterfront walk and deliberately narrow pedestrian lanes.
path(31.7, 2.85, 0, -10.28, M.pathLight);
path(30.7, 1.78, 0, -4.90);
path(30.7, 1.78, 0, 4.30);
path(1.68, 19.0, -6.20, -0.25);
path(1.68, 19.0, 6.20, -0.25);
path(1.50, 19.4, 0, -0.2, M.pathLight);
// Courtyard paving.
path(5.35, 3.52, 0, 1.42, M.pathLight);
// Sparse voxel paving joints.
function pavingJoints(x0, x1, z0, z1, step = 0.72) {
for (let x = x0; x < x1; x += step) {
for (let z = z0; z < z1; z += step * 0.72) {
if (random() > 0.56) {
const mat = pick([M.path, M.pathLight, M.pathDark]);
box(
range(0.18, 0.35),
0.025,
range(0.12, 0.24),
x + range(-0.12, 0.12),
0.285,
z + range(-0.10, 0.10),
mat,
scene,
false,
true
);
}
}
}
}
pavingJoints(-15.3, 15.3, -11.55, -8.85, 0.85);
pavingJoints(-15.2, 15.2, -5.65, -4.15);
pavingJoints(-15.2, 15.2, 3.55, 5.05);
pavingJoints(-6.9, -5.5, -9.7, 9.8, 0.65);
pavingJoints(5.5, 6.9, -9.7, 9.8, 0.65);
pavingJoints(-0.55, 0.55, -8.7, 9.9, 0.62);
// Stacked retaining blocks define the south and side boundaries.
for (let x = -15.5; x <= 15.5; x += 1.05) {
box(0.96, 0.56, 0.62, x, 0.42, 11.85, random() > 0.5 ? M.stone : M.stoneLight);
}
for (const side of [-1, 1]) {
for (let z = -10.8; z <= 10.8; z += 1.08) {
box(
0.60,
0.58,
0.98,
side * 15.75,
0.42,
z,
random() > 0.5 ? M.stone : M.stoneLight
);
}
}
// Tidal steps down to the water.
for (let i = 0; i < 4; i++) {
box(
3.2,
0.24,
0.55,
-3.4,
0.16 - i * 0.20,
-12.05 - i * 0.48,
i % 2 ? M.stone : M.stoneLight
);
}
// ------------------------------------------------------------
// Architecture helpers
// ------------------------------------------------------------
function addWindow(parent, x, y, z, shutterMat, scale = 1) {
const w = 0.68 * scale;
const h = 0.78 * scale;
box(w, h, 0.09, x, y, z, M.dark, parent, false);
box(w + 0.12, 0.08, 0.13, x, y + h / 2, z + 0.02, M.cream, parent, false);
box(w + 0.12, 0.08, 0.13, x, y - h / 2, z + 0.02, M.timber, parent, false);
box(0.23 * scale, h, 0.12, x - w / 2 - 0.11 * scale, y, z + 0.04, shutterMat, parent, false);
box(0.23 * scale, h, 0.12, x + w / 2 + 0.11 * scale, y, z + 0.04, shutterMat, parent, false);
box(0.045, h, 0.14, x, y, z + 0.08, M.timber, parent, false);
box(w, 0.045, 0.14, x, y, z + 0.08, M.timber, parent, false);
}
function addDoor(parent, z, accentMat) {
box(0.92, 1.72, 0.10, 0, 0.90, z, M.dark, parent, false);
box(0.76, 1.50, 0.10, 0, 0.86, z + 0.07, M.timber, parent, false);
// Stepped Swahili-style arch.
box(0.17, 1.78, 0.16, -0.56, 0.91, z + 0.08, accentMat, parent, false);
box(0.17, 1.78, 0.16, 0.56, 0.91, z + 0.08, accentMat, parent, false);
box(0.28, 0.22, 0.16, -0.39, 1.87, z + 0.08, accentMat, parent, false);
box(0.28, 0.22, 0.16, 0.39, 1.87, z + 0.08, accentMat, parent, false);
box(0.62, 0.22, 0.16, 0, 2.06, z + 0.08, accentMat, parent, false);
for (const yy of [0.42, 1.02]) {
box(0.10, 0.10, 0.08, -0.23, yy, z + 0.14, M.brass, parent, false);
box(0.10, 0.10, 0.08, 0.23, yy, z + 0.14, M.brass, parent, false);
}
box(0.08, 0.08, 0.08, 0.31, 0.88, z + 0.15, M.brass, parent, false);
}
function addBalcony(parent, width, y, z) {
const bw = Math.min(width - 0.65, 2.25);
box(bw, 0.14, 0.58, 0, y, z + 0.22, M.timberLight, parent);
box(bw, 0.08, 0.08, 0, y + 0.68, z + 0.48, M.timber, parent);
for (const x of [-bw / 2, 0, bw / 2]) {
box(0.08, 0.72, 0.08, x, y + 0.36, z + 0.48, M.timber, parent);
}
}
function addBuilding({
x,
z,
w,
d,
h,
front = "south",
color = pick(plasterColors),
style = 0
}) {
const group = new THREE.Group();
group.position.set(x, 0.27, z);
scene.add(group);
const orientation = {
north: Math.PI,
south: 0,
east: Math.PI / 2,
west: -Math.PI / 2
}[front];
group.rotation.y = orientation;
const bodyMat = material(color);
const accentMat = random() > 0.45 ? M.cream : M.roofLight;
const shutterMat = material(pick(shutterColors));
const facadeZ = d / 2 + 0.025;
// Plinth and main coral-rag mass.
box(w + 0.12, 0.48, d + 0.12, 0, 0.24, 0, M.stoneDark, group);
box(w, h, d, 0, h / 2 + 0.20, 0, bodyMat, group);
// Timber corner posts and horizontal floor beams.
for (const xx of [-w / 2 + 0.09, w / 2 - 0.09]) {
box(0.12, h, 0.13, xx, h / 2 + 0.20, facadeZ + 0.055, M.timber, group);
}
const floors = Math.max(1, Math.floor((h - 0.35) / 1.55));
const floorHeight = (h - 0.45) / floors;
for (let f = 1; f < floors; f++) {
const yy = 0.38 + f * floorHeight;
box(w, 0.10, 0.13, 0, yy, facadeZ + 0.05, M.timber, group);
}
const hasDoor = w > 2.05 && style !== 4;
if (hasDoor) {
addDoor(group, facadeZ, accentMat);
}
const columns = Math.max(1, Math.floor((w - 0.85) / 1.28));
const spacing = (w - 0.8) / columns;
for (let floor = 0; floor < floors; floor++) {
const yy = 1.24 + floor * floorHeight;
for (let col = 0; col < columns; col++) {
const xx = -w / 2 + 0.48 + spacing * (col + 0.5);
if (floor === 0 && hasDoor && Math.abs(xx) < 0.72) continue;
const upper = floor > 0;
addWindow(
group,
xx,
yy,
facadeZ + 0.065,
shutterMat,
upper ? 0.88 : 1
);
}
}
// Projecting upper-storey details.
if ((style === 1 || style === 3) && floors > 1) {
addBalcony(group, w, 0.38 + floorHeight - 0.06, facadeZ);
}
if (style === 2 && floors > 1) {
const by = 0.38 + floorHeight + 0.10;
box(w * 0.65, 0.78, 0.34, 0, by + 0.32, facadeZ + 0.14, M.cream, group);
addWindow(group, 0, by + 0.32, facadeZ + 0.33, shutterMat, 0.65);
}
// Flat roof, parapet, and small rooftop details.
box(w + 0.10, 0.18, d + 0.10, 0, h + 0.25, 0, M.roof, group);
box(w, 0.35, 0.16, 0, h + 0.45, d / 2, M.roofLight, group);
box(w, 0.35, 0.16, 0, h + 0.45, -d / 2, M.roofLight, group);
box(0.16, 0.35, d, w / 2, h + 0.45, 0, M.roofLight, group);
box(0.16, 0.35, d, -w / 2, h + 0.45, 0, M.roofLight, group);
// Parapet cap modules provide a crisp voxel silhouette.
const capCount = Math.max(2, Math.floor(w / 0.62));
for (let i = 0; i < capCount; i++) {
const xx = -w / 2 + (w / capCount) * (i + 0.5);
box(w / capCount + 0.03, 0.11, 0.21, xx, h + 0.66, d / 2, M.cream, group);
}
if (style % 3 === 0) {
box(0.72, 0.54, 0.72, w * 0.23, h + 0.60, -d * 0.18, M.roofLight, group);
box(0.58, 0.10, 0.58, w * 0.23, h + 0.91, -d * 0.18, M.cream, group);
}
// Irregular plaster wear.
for (let i = 0; i < 4; i++) {
box(
range(0.08, 0.22),
range(0.05, 0.16),
0.04,
range(-w / 2 + 0.25, w / 2 - 0.25),
range(0.45, Math.max(0.7, h - 0.2)),
facadeZ + 0.075,
random() > 0.5 ? M.stoneLight : M.terracotta,
group,
false
);
}
return group;
}
function addRow(x0, x1, z, depth, front, count) {
const width = x1 - x0;
const cell = width / count;
for (let i = 0; i < count; i++) {
const w = cell - 0.10;
addBuilding({
x: x0 + cell * (i + 0.5),
z,
w,
d: depth,
h: range(3.6, 5.8),
front,
color: pick(plasterColors),
style: Math.floor(random() * 6)
});
}
}
// ------------------------------------------------------------
// Town plan: compact blocks separated by pedestrian-only lanes
// ------------------------------------------------------------
// Waterfront facades.
addRow(-14.85, -7.10, -7.02, 2.28, "north", 3);
addRow(-5.20, -1.03, -7.02, 2.28, "north", 2);
addRow(1.03, 5.20, -7.02, 2.28, "north", 2);
addRow(7.10, 14.85, -7.02, 2.28, "north", 3);
// Middle western and eastern rows.
addRow(-14.85, -7.10, -0.30, 5.70, "north", 4);
addRow(7.10, 14.85, -0.30, 5.70, "north", 4);
// Courtyard block: north wings leave a narrow axial opening.
addRow(-5.20, -1.04, -1.92, 3.00, "south", 2);
addRow(1.04, 5.20, -1.92, 3.00, "south", 2);
// Courtyard side wings.
addBuilding({
x: -3.46,
z: 1.40,
w: 3.38,
d: 1.42,
h: 4.6,
front: "east",
color: "#dfb47f",
style: 1
});
addBuilding({
x: 3.46,
z: 1.40,
w: 3.38,
d: 1.42,
h: 4.9,
front: "west",
color: "#c7785d",
style: 4
});
// Southern rows.
addRow(-14.85, -7.10, 7.88, 5.05, "north", 4);
addRow(-5.20, -1.03, 7.88, 5.05, "north", 2);
addRow(1.03, 5.20, 7.88, 5.05, "north", 2);
addRow(7.10, 14.85, 7.88, 5.05, "north", 4);
// Timber entrance markers to the small courtyard.
for (const x of [-1.05, 1.05]) {
box(0.22, 2.25, 0.26, x, 1.37, -0.33, M.timber);
box(0.33, 0.18, 0.34, x, 2.48, -0.33, M.cream);
}
box(2.30, 0.22, 0.30, 0, 2.52, -0.33, M.timber);
// Courtyard well / fountain.
box(1.38, 0.22, 1.38, 0, 0.39, 1.55, M.stoneLight);
box(0.44, 0.68, 0.44, 0, 0.80, 1.55, M.stone);
box(1.02, 0.20, 1.02, 0, 1.17, 1.55, M.stoneLight);
box(0.76, 0.07, 0.76, 0, 1.29, 1.55, M.water);
// ------------------------------------------------------------
// Waterfront details: fort, boats, market, and people
// ------------------------------------------------------------
// A small stone fort anchors the eastern quay.
box(6.1, 0.42, 4.6, 12.45, 0.02, -14.25, M.stoneDark);
box(5.7, 0.30, 4.2, 12.45, 0.34, -14.25, M.stoneLight);
const fort = new THREE.Group();
fort.position.set(12.45, 0.48, -14.25);
scene.add(fort);
box(4.45, 2.15, 3.85, 0, 1.08, 0, M.stone, fort);
box(4.60, 0.18, 4.00, 0, 2.20, 0, M.stoneLight, fort);
for (const x of [-1.85, 0, 1.85]) {
box(0.64, 0.46, 0.70, x, 2.48, -1.73, M.stoneLight, fort);
box(0.64, 0.46, 0.70, x, 2.48, 1.73, M.stoneLight, fort);
}
for (const z of [-1.48, 0, 1.48]) {
box(0.70, 0.46, 0.64, -2.02, 2.48, z, M.stoneLight, fort);
box(0.70, 0.46, 0.64, 2.02, 2.48, z, M.stoneLight, fort);
}
box(0.92, 1.55, 0.10, 0, 0.77, 1.96, M.dark, fort);
box(1.18, 0.16, 0.16, 0, 1.62, 1.98, M.stoneLight, fort);
// Small water tank and ladder.
box(0.58, 0.85, 0.58, -0.72, 2.68, 0.10, M.roofLight, fort);
box(0.10, 1.65, 0.10, 1.25, 2.65, 1.30, M.timber, fort);
box(0.10, 1.65, 0.10, 1.55, 2.65, 1.30, M.timber, fort);
for (let i = 0; i < 5; i++) {
box(0.40, 0.07, 0.07, 1.40, 2.05 + i * 0.28, 1.30, M.timber, fort);
}
// Stylized dhow.
function addDhow(x, z, scale = 1, hullColor = M.timber) {
const boat = new THREE.Group();
boat.position.set(x, 0.03, z);
boat.scale.setScalar(scale);
scene.add(boat);
box(3.45, 0.22, 0.72, 0, 0.10, 0, hullColor, boat);
box(2.75, 0.34, 1.04, 0, 0.24, 0, hullColor, boat);
box(0.60, 0.48, 0.76, -1.72, 0.37, 0, hullColor, boat);
box(0.42, 0.64, 0.62, 1.78, 0.43, 0, hullColor, boat);
box(2.85, 0.12, 0.92, 0, 0.44, 0, M.timberLight, boat);
box(0.11, 3.45, 0.11, 0.20, 2.05, 0, M.timber, boat);
box(0.08, 2.45, 0.08, -0.50, 1.55, 0, M.timber, boat);
// Lateen sail approximated by stacked voxel slats.
for (let i = 0; i < 9; i++) {
const t = i / 8;
const height = 0.55 + Math.sin(t * Math.PI) * 1.75;
box(
0.16,
height,
0.07,
0.30 + t * 1.65,
1.03 + height / 2,
0.03,
i % 3 === 0 ? M.clothRed : M.cloth,
boat
);
}
box(1.45, 0.09, 0.09, 0.82, 0.72, 0.15, M.timber, boat);
return boat;
}
addDhow(-9.7, -15.3, 1.05, M.timber);
addDhow(-3.9, -18.0, 0.82, M.timberLight);
addDhow(5.5, -16.0, 0.94, M.timber);
// Mooring posts.
for (const [x, z] of [
[-13.0, -12.0], [-6.1, -12.0], [0.9, -12.0],
[6.6, -12.0], [9.2, -12.0]
]) {
box(0.24, 0.90, 0.24, x, 0.72, z, M.timber);
box(0.34, 0.13, 0.34, x, 1.17, z, M.timberLight);
}
// Water ripples.
for (let i = 0; i < 78; i++) {
const waveMat = random() > 0.35 ? M.waterLight : M.waterDark;
box(
range(0.30, 1.45),
0.025,
range(0.06, 0.15),
range(-15.7, 15.7),
0.105,
range(-21.4, -12.5),
waveMat,
scene,
false,
false
);
}
// Market stall on the promenade.
const stall = new THREE.Group();
stall.position.set(-12.2, 0.27, -9.92);
scene.add(stall);
box(2.25, 0.20, 1.05, 0, 0.88, 0, M.timberLight, stall);
for (const x of [-1.0, 1.0]) {
for (const z of [-0.42, 0.42]) {
box(0.10, 2.05, 0.10, x, 1.02, z, M.timber, stall);
}
}
for (let i = 0; i < 6; i++) {
box(
0.40,
0.12,
1.25,
-1.0 + i * 0.40,
2.08,
0,
i % 2 ? M.cloth : M.clothRed,
stall
);
}
for (let i = 0; i < 5; i++) {
box(
range(0.25, 0.43),
range(0.18, 0.34),
range(0.25, 0.42),
-0.78 + i * 0.37,
1.12,
range(-0.18, 0.18),
pick([M.leaf, M.leafLight, M.terracotta]),
stall
);
}
// Crates and baskets along the waterfront.
for (const [x, z] of [
[-14.2, -10.8], [-13.3, -10.75], [8.6, -10.7], [9.35, -10.75]
]) {
box(0.65, 0.50, 0.58, x, 0.57, z, M.timberLight);
box(0.69, 0.08, 0.61, x, 0.57, z, M.timber);
if (random() > 0.45) {
box(0.48, 0.36, 0.44, x, 0.94, z, M.roofLight);
}
}
// Pots and small trees.
function pottedTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.27, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.48, 0.42, 0.48, 0, 0.21, 0, M.terracotta, group);
box(0.55, 0.12, 0.55, 0, 0.44, 0, M.cream, group);
box(0.16, 1.25, 0.16, 0, 1.05, 0, M.timber, group);
box(0.78, 0.58, 0.65, 0, 1.74, 0, M.leaf, group);
box(0.60, 0.46, 0.55, 0.18, 2.16, 0.05, M.leafLight, group);
box(0.46, 0.38, 0.48, -0.26, 2.08, -0.10, M.leaf, group);
}
pottedTree(-2.15, -10.6, 0.9);
pottedTree(2.30, -10.5, 0.8);
pottedTree(-2.10, 2.70, 0.8);
pottedTree(2.10, 2.65, 0.72);
pottedTree(15.15, -10.7, 0.85);
// Voxel pedestrians establish scale without introducing vehicles.
function person(x, z, shirtColor, rotation = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.27, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
const shirt = material(shirtColor);
const skin = material(pick(["#6f4632", "#9a6849", "#b9815e", "#d1a178"]));
box(0.16, 0.52, 0.18, -0.12, 0.27, 0, M.dark, group);
box(0.16, 0.52, 0.18, 0.12, 0.27, 0, M.dark, group);
box(0.43, 0.58, 0.25, 0, 0.81, 0, shirt, group);
box(0.13, 0.52, 0.16, -0.29, 0.78, 0, shirt, group);
box(0.13, 0.52, 0.16, 0.29, 0.78, 0, shirt, group);
box(0.30, 0.31, 0.28, 0, 1.28, 0, skin, group);
box(0.32, 0.10, 0.30, 0, 1.43, 0, M.dark, group);
}
const shirtColors = ["#b95c48", "#3e6f73", "#d3a653", "#eee1bd", "#5b6952"];
const people = [
[-12.9, -9.95], [-10.5, -10.45], [-7.0, -10.15],
[1.3, -10.35], [4.7, -9.95], [9.1, -10.3],
[-6.15, -3.2], [-5.8, 1.7], [6.2, -1.4],
[0.05, -3.7], [0.0, 1.2], [-0.15, 7.3],
[6.15, 6.9], [-12.9, 4.3], [13.7, 4.25]
];
people.forEach(([x, z], i) => {
person(
x,
z,
shirtColors[i % shirtColors.length],
range(-Math.PI, Math.PI),
range(0.87, 1.04)
);
});
// A few shaded benches and street-side stools.
for (const [x, z, rot] of [
[-15.05, -8.7, Math.PI / 2],
[15.05, -8.6, -Math.PI / 2],
[-5.35, 7.9, 0]
]) {
const bench = new THREE.Group();
bench.position.set(x, 0.27, z);
bench.rotation.y = rot;
scene.add(bench);
box(1.45, 0.14, 0.45, 0, 0.55, 0, M.timberLight, bench);
box(1.45, 0.42, 0.12, 0, 0.82, -0.20, M.timber, bench);
box(0.13, 0.55, 0.38, -0.52, 0.28, 0, M.timber, bench);
box(0.13, 0.55, 0.38, 0.52, 0.28, 0, M.timber, bench);
}
// ------------------------------------------------------------
// Custom orbit, pan, zoom, and view transitions
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.1, -1.0),
radius: 42,
theta: 0.72,
phi: 0.92
};
let cameraTween = null;
const views = {
overview: {
target: new THREE.Vector3(0, 1.1, -1.0),
radius: 42,
theta: 0.72,
phi: 0.92
},
lane: {
target: new THREE.Vector3(0, 1.35, -1.0),
radius: 11,
theta: Math.PI,
phi: 1.47
},
court: {
target: new THREE.Vector3(0, 1.0, 1.1),
radius: 13,
theta: 0.25,
phi: 1.12
},
plan: {
target: new THREE.Vector3(0, 0, -1.8),
radius: 43,
theta: 0,
phi: 0.19
}
};
function transitionTo(view) {
const destination = views[view];
cameraTween = {
elapsed: 0,
duration: 1.15,
fromTarget: controls.target.clone(),
toTarget: destination.target.clone(),
fromRadius: controls.radius,
toRadius: destination.radius,
fromTheta: controls.theta,
toTheta: destination.theta,
fromPhi: controls.phi,
toPhi: destination.phi
};
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => {
transitionTo(button.dataset.view);
});
});
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
const pointers = new Map();
let dragMode = "orbit";
let previousPinchDistance = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
}
cameraTween = null;
});
function panCamera(dx, dy) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const scale = controls.radius * 0.00135;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(up, dy * scale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -15, 15);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -13, 11);
controls.target.y = THREE.MathUtils.clamp(controls.target.y, 0, 4);
}
canvas.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 === 1) {
if (dragMode === "pan") {
panCamera(dx, dy);
} else {
controls.theta -= dx * 0.005;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0045,
0.16,
1.49
);
}
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (previousPinchDistance / distance),
6,
68
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraTween = null;
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
6,
68
);
}, { passive: false });
window.addEventListener("keydown", event => {
cameraTween = null;
if (event.key === "ArrowLeft") controls.theta += 0.08;
if (event.key === "ArrowRight") controls.theta -= 0.08;
if (event.key === "ArrowUp") controls.phi = Math.max(0.16, controls.phi - 0.06);
if (event.key === "ArrowDown") controls.phi = Math.min(1.49, controls.phi + 0.06);
if (event.key.toLowerCase() === "w") panCamera(0, 12);
if (event.key.toLowerCase() === "s") panCamera(0, -12);
if (event.key.toLowerCase() === "a") panCamera(12, 0);
if (event.key.toLowerCase() === "d") panCamera(-12, 0);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
if (cameraTween) {
cameraTween.elapsed += clock.getDelta();
const raw = Math.min(cameraTween.elapsed / cameraTween.duration, 1);
const t = raw * raw * (3 - 2 * raw);
controls.target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
t
);
controls.radius = THREE.MathUtils.lerp(
cameraTween.fromRadius,
cameraTween.toRadius,
t
);
controls.theta = THREE.MathUtils.lerp(
cameraTween.fromTheta,
cameraTween.toTheta,
t
);
controls.phi = THREE.MathUtils.lerp(
cameraTween.fromPhi,
cameraTween.toPhi,
t
);
if (raw >= 1) cameraTween = null;
}
updateCamera();
renderer.render(scene, camera);
}
updateCamera();
animate();
requestAnimationFrame(() => {
loading.classList.add("done");
setTimeout(() => loading.remove(), 600);
});
</script>
</body>
</html>
```