Prompt specification
Build or customize the Three.js 3D scene "Forodhani gardens and Stone Town edge" 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: Forodhani gardens and Stone Town edge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/forodhani-gardens-and-stone-town-edge-x2959
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Forodhani Gardens and Zanzibar's Stone Town. Build a bounded voxel slice with referenced garden paths, waterfront edge, and selected historic facades. Show several ordinary public-space uses without reducing the district to a single market activity. Voxel style.
Working Three.js Starter (forodhani-gardens-and-stone-town-edge-x2959):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Forodhani Gardens — Stone Town Waterfront</title>
<style>
:root {
--ink: #183c43;
--muted: #577078;
--paper: rgba(250, 246, 233, 0.92);
--line: rgba(24, 60, 67, 0.16);
--green: #4e8060;
--water: #298fa0;
--coral: #bd725d;
--gold: #d5a44a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe5df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px 16px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 4px;
box-shadow: 0 16px 50px rgba(37, 66, 66, 0.12);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--coral);
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(26px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.coordinates {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
position: absolute;
right: 24px;
top: 24px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
max-width: 420px;
pointer-events: auto;
}
.controls button {
appearance: none;
border: 1px solid rgba(24, 60, 67, 0.16);
border-radius: 3px;
padding: 9px 11px;
background: rgba(250, 246, 233, 0.9);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 8px 24px rgba(37, 66, 66, 0.08);
backdrop-filter: blur(10px);
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.controls button:hover {
transform: translateY(-1px);
background: #fffdf4;
}
.controls button.active {
border-color: var(--ink);
background: var(--ink);
color: #fff9e9;
}
.legend {
position: absolute;
left: 24px;
bottom: 24px;
display: grid;
gap: 7px;
padding: 12px 14px;
border-left: 3px solid var(--coral);
background: rgba(250, 246, 233, 0.86);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
backdrop-filter: blur(10px);
}
.legend strong {
color: var(--ink);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
background: var(--green);
box-shadow: 0 0 0 1px rgba(24, 60, 67, 0.13);
}
.swatch.water {
background: var(--water);
}
.swatch.stone {
background: var(--coral);
}
.hint {
position: absolute;
right: 24px;
bottom: 24px;
padding: 9px 12px;
border-radius: 3px;
background: rgba(24, 60, 67, 0.83);
color: #fff9e9;
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(8px);
}
.map-label {
position: absolute;
z-index: 4;
transform: translate(-50%, -100%);
padding: 7px 9px;
border: 0;
border-left: 3px solid var(--gold);
background: rgba(251, 247, 235, 0.94);
color: var(--ink);
box-shadow: 0 8px 22px rgba(22, 53, 59, 0.15);
font: inherit;
text-align: left;
white-space: nowrap;
pointer-events: auto;
cursor: pointer;
transition:
opacity 180ms ease,
background 180ms ease;
}
.map-label:hover {
background: #fffdf5;
}
.map-label strong {
display: block;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.map-label span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.map-label.green {
border-left-color: var(--green);
}
.map-label.blue {
border-left-color: var(--water);
}
.map-label.coral {
border-left-color: var(--coral);
}
.labels-off .map-label {
opacity: 0;
pointer-events: none;
}
.north {
position: absolute;
left: 50%;
bottom: 27px;
transform: translateX(-50%);
color: rgba(24, 60, 67, 0.65);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle,
.coordinates {
display: none;
}
.controls {
top: 112px;
right: 12px;
left: 12px;
max-width: none;
}
.controls button {
padding: 7px 8px;
font-size: 9px;
}
.legend {
display: none;
}
.hint {
right: 12px;
bottom: 12px;
font-size: 9px;
}
.north {
display: none;
}
.map-label span {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel model of Forodhani Gardens and Stone Town"></canvas>
<div class="ui" id="ui">
<section class="title-card">
<div class="eyebrow">Zanzibar · Archipelago Field Study 01</div>
<h1>Forodhani<br />& Stone Town</h1>
<p class="subtitle">
An interpretive voxel slice of the formal garden, sea wall, and
historic coral-stone waterfront.
</p>
<div class="coordinates">
<span>Forodhani Gardens</span>
<span>06°09′S · 39°11′E</span>
</div>
</section>
<nav class="controls" aria-label="Scene controls">
<button class="active" data-view="overview">Overview</button>
<button data-view="garden">Garden</button>
<button data-view="waterfront">Waterfront</button>
<button data-view="stone">Stone Town</button>
<button id="toggle-labels" aria-pressed="true">Labels</button>
</nav>
<aside class="legend" aria-label="Scene legend">
<strong>Reading the slice</strong>
<div class="legend-row">
<i class="swatch"></i> Formal paths, lawns, and shade
</div>
<div class="legend-row">
<i class="swatch water"></i> Indian Ocean edge and landing
</div>
<div class="legend-row">
<i class="swatch stone"></i> Historic coral-stone fabric
</div>
<div class="legend-row">
Public life: football, exercise, reading, gardening,
walking, refreshment, and fishing
</div>
<div style="opacity: 0.72; font-style: italic">
Interpretive and diagrammatic, not a survey.
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Select a view</div>
<div class="north">North ↑</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const ui = document.querySelector("#ui");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe5df);
scene.fog = new THREE.Fog(0xdbe5df, 100, 190);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
300
);
const hemi = new THREE.HemisphereLight(0xfff2d8, 0x657c78, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe3b8, 3.35);
sun.position.set(-38, 64, -34);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 58;
sun.shadow.camera.bottom = -58;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 150;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.0002;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9de, 0.65);
fill.position.set(45, 28, 45);
scene.add(fill);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
...options
});
const M = {
stage: standard(0xe9e4d4),
earthDark: standard(0x765443),
earth: standard(0x9d7258),
earthLight: standard(0xb78968),
sand: standard(0xd4c29d),
path: standard(0xe0cdaa),
pathLight: standard(0xecddbd),
road: standard(0xa89a84),
water: [
standard(0x2f9ead),
standard(0x38a5b2),
standard(0x2996a8),
standard(0x47aeb7)
],
wave: standard(0xa8d9d4),
foam: standard(0xd8e9dd),
lawn: standard(0x618c57),
lawnDark: standard(0x527d4e),
lawnLight: standard(0x739c62),
hedge: standard(0x396d4b),
hedgeLight: standard(0x477c50),
trunk: standard(0x694c38),
foliage: [
standard(0x39704d),
standard(0x477f50),
standard(0x5d9158),
standard(0x6c9c5c)
],
coralA: standard(0xc98568),
coralB: standard(0xd89b79),
coralC: standard(0xb9705d),
coralDark: standard(0x8f574c),
trim: standard(0xe7c9a2),
roof: standard(0x875044),
roofDark: standard(0x65413b),
wood: standard(0x68452f),
woodLight: standard(0x966744),
dark: standard(0x293d3e),
window: standard(0x294a50, { roughness: 0.55 }),
metal: standard(0x3a4b4c, { roughness: 0.65 }),
cream: standard(0xf4e8c8),
white: standard(0xf5f1df),
soil: standard(0x6c5038),
flowerRed: standard(0xd45c50),
flowerGold: standard(0xe6b74d),
flowerPink: standard(0xd87c89),
shirtBlue: standard(0x3f7890),
shirtRed: standard(0xb9574d),
shirtGold: standard(0xd2a04c),
shirtGreen: standard(0x54805c),
shirtPurple: standard(0x796986),
skinDark: standard(0x754936),
skinMedium: standard(0xa36b48),
skinLight: standard(0xd2a17a)
};
M.stage.userData.noShadow = true;
M.water.forEach((m) => (m.userData.noShadow = true));
M.wave.userData.noShadow = true;
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const batches = new Map();
const dummy = new THREE.Object3D();
let seed = 731;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function addBox(
x, y, z,
width, height, depth,
material,
rotationX = 0,
rotationY = 0,
rotationZ = 0
) {
dummy.position.set(x, y, z);
dummy.rotation.set(rotationX, rotationY, rotationZ);
dummy.scale.set(width, height, depth);
dummy.updateMatrix();
if (!batches.has(material)) batches.set(material, []);
batches.get(material).push(dummy.matrix.clone());
}
function buildBatches() {
for (const [material, matrices] of batches) {
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
matrices.length
);
matrices.forEach((matrix, index) => {
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
mesh.castShadow = !material.userData.noShadow;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
scene.add(mesh);
}
}
// ---------------------------------------------------------------------
// Landscape: a deliberately bounded geological and urban slice.
// ---------------------------------------------------------------------
addBox(0, -4.32, 0, 220, 0.25, 180, M.stage);
addBox(0, -2.05, 0, 66, 4.1, 52, M.earthDark);
addBox(0, -0.22, 0, 65.2, 0.42, 51.2, M.earthLight);
addBox(0, -0.66, 4.75, 64.5, 0.62, 40.5, M.earth);
// Front cut face strata.
addBox(0, -1.15, -25.15, 65.5, 0.48, 0.18, M.coralDark);
addBox(0, -2.45, -25.15, 65.5, 0.42, 0.18, M.sand);
addBox(0, -3.2, -25.15, 65.5, 0.38, 0.18, M.coralC);
// Water tiles.
for (let x = -31; x <= 31; x += 2) {
for (let z = -24; z <= -16; z += 2) {
const material = M.water[Math.floor(random() * M.water.length)];
addBox(x, 0.06 + random() * 0.025, z, 1.94, 0.12, 1.94, material);
}
}
// Broken voxel wave bands.
for (let row = 0; row < 7; row++) {
const z = -23.4 + row * 1.1;
for (let col = 0; col < 7; col++) {
const x = -27 + col * 8.4 + (row % 2) * 2.1;
addBox(x, 0.18, z, 2.2 + random() * 2.4, 0.045, 0.13, M.wave);
if (random() > 0.55) {
addBox(x + 0.7, 0.19, z + 0.45, 0.8, 0.035, 0.1, M.foam);
}
}
}
// Land, promenade, garden, and street.
addBox(0, 0.05, -12.55, 64, 0.18, 5.2, M.path);
addBox(0, 0.03, 3.0, 43, 0.22, 26.2, M.sand);
addBox(0, 0.02, 16.8, 64, 0.2, 3.3, M.road);
// Sea wall.
addBox(0, 0.73, -15.35, 64, 1.45, 1.05, M.coralC);
addBox(0, 1.49, -15.35, 64.2, 0.18, 1.22, M.pathLight);
// Seawall joints.
for (let x = -30; x <= 30; x += 3) {
addBox(x, 0.76, -15.91, 0.11, 1.25, 0.09, M.coralDark);
}
// Landing steps descending toward the water.
for (let i = 0; i < 5; i++) {
addBox(-4.8, 0.95 - i * 0.22, -16.05 - i * 0.62, 4.3, 0.45, 1.25, M.pathLight);
}
// Garden perimeter and axial paths.
addBox(-5, 0.24, -9.3, 42.2, 0.24, 1.9, M.pathLight);
addBox(-5, 0.24, 15.25, 42.2, 0.24, 1.9, M.pathLight);
addBox(-25.1, 0.24, 3, 1.9, 0.24, 26.2, M.pathLight);
addBox(15.1, 0.24, 3, 1.9, 0.24, 26.2, M.pathLight);
addBox(-5, 0.25, 3, 3.1, 0.26, 26.2, M.path);
addBox(-5, 0.27, 3.5, 42.2, 0.26, 3.1, M.path);
// Four formal lawn compartments.
addBox(-17.5, 0.29, -3.5, 17.5, 0.28, 10.5, M.lawn);
addBox(4.7, 0.29, -3.5, 17.1, 0.28, 10.5, M.lawnLight);
addBox(-17.5, 0.29, 9.5, 17.5, 0.28, 10.5, M.lawnDark);
addBox(4.7, 0.29, 9.5, 17.1, 0.28, 10.5, M.lawn);
// Mown-grid marks in the lawns.
for (const x of [-21, -17, -13, 1, 5, 9]) {
for (const z of [-6, -2, 7, 11]) {
addBox(x, 0.445, z, 0.07, 0.025, 5.8, M.lawnDark);
}
}
// Low clipped hedges.
const hedgeRuns = [
[-17.5, -8.55, 17.5, 0.65],
[4.7, -8.55, 17.1, 0.65],
[-17.5, 14.45, 17.5, 0.65],
[4.7, 14.45, 17.1, 0.65],
[-25.75, 3, 0.65, 10.5],
[-9.2, -3.5, 0.65, 10.5],
[-0.85, -3.5, 0.65, 10.5],
[13.8, -3.5, 0.65, 10.5]
];
for (const [x, z, w, d] of hedgeRuns) {
addBox(x, 0.78, z, w, 0.8, d, M.hedge);
addBox(x, 1.2, z, w * 0.98, 0.12, d * 0.96, M.hedgeLight);
}
// Fountain at the principal crossing.
addBox(-5, 0.5, 1.35, 4.8, 0.55, 0.75, M.trim);
addBox(-5, 0.5, 5.65, 4.8, 0.55, 0.75, M.trim);
addBox(-7.15, 0.5, 3.5, 0.75, 0.55, 3.55, M.trim);
addBox(-2.85, 0.5, 3.5, 0.75, 0.55, 3.55, M.trim);
addBox(-5, 0.43, 3.5, 3.6, 0.22, 3.55, M.water[1]);
addBox(-5, 1.0, 3.5, 0.85, 1.0, 0.85, M.trim);
addBox(-5, 1.58, 3.5, 1.45, 0.26, 1.45, M.trim);
addBox(-5, 1.94, 3.5, 0.32, 0.55, 0.32, M.water[1]);
// -------------------------------------------------------------------
// Historic facades: old fort, coral row, Christ Church, merchant house.
// -------------------------------------------------------------------
function frontWindow(x, y, z, width = 0.72, height = 1.08) {
addBox(x, y, z, width, height, 0.13, M.window);
addBox(x, y - height * 0.5 - 0.08, z - 0.02, width + 0.32, 0.14, 0.28, M.trim);
addBox(x - width * 0.5 - 0.18, y, z - 0.03, 0.14, height + 0.12, 0.12, M.coralDark);
addBox(x + width * 0.5 + 0.18, y, z - 0.03, 0.14, height + 0.12, 0.12, M.coralDark);
}
function reliefStones(x, frontZ, width, height, count = 18) {
for (let i = 0; i < count; i++) {
addBox(
x + (random() - 0.5) * width,
0.8 + random() * (height - 1),
frontZ - 0.08,
0.18 + random() * 0.46,
0.14 + random() * 0.25,
0.1,
random() > 0.5 ? M.coralB : M.coralC
);
}
}
// Old Fort.
addBox(-21.3, 0.32, 20.55, 16.1, 0.65, 7.2, M.coralDark);
addBox(-21.3, 3.1, 20.55, 15.6, 5.6, 6.75, M.coralA);
addBox(-21.3, 6.05, 20.55, 16.1, 0.35, 7.2, M.coralB);
for (let x = -28; x <= -14.5; x += 1.65) {
addBox(x, 6.5, 17.08, 0.86, 0.75, 0.7, M.coralA);
}
addBox(-28.1, 4.05, 20.0, 4.25, 7.45, 5.65, M.coralB);
addBox(-28.1, 7.95, 20.0, 4.65, 0.35, 6.0, M.coralA);
for (const x of [-29.55, -26.65]) {
addBox(x, 8.35, 17.15, 0.72, 0.7, 0.7, M.coralA);
}
addBox(-21.3, 1.72, 17.12, 2.3, 3.45, 0.2, M.dark);
addBox(-22.58, 1.85, 16.97, 0.42, 3.8, 0.42, M.trim);
addBox(-20.02, 1.85, 16.97, 0.42, 3.8, 0.42, M.trim);
addBox(-21.3, 3.65, 16.96, 2.95, 0.42, 0.42, M.trim);
addBox(-21.3, 4.13, 16.95, 2.1, 0.35, 0.42, M.trim);
reliefStones(-21.3, 17.1, 15.2, 5.2, 28);
// Narrow carved coral houses.
const rowHouses = [
{ x: -7.6, w: 3.8, h: 6.2, material: M.coralB },
{ x: -3.45, w: 3.8, h: 7.2, material: M.coralC },
{ x: 0.7, w: 3.8, h: 6.5, material: M.coralA }
];
for (const house of rowHouses) {
addBox(house.x, 0.25, 20.45, house.w + 0.25, 0.5, 6.25, M.coralDark);
addBox(house.x, house.h * 0.5 + 0.25, 20.45, house.w, house.h, 5.9, house.material);
addBox(house.x, house.h + 0.37, 20.45, house.w + 0.2, 0.28, 6.2, M.trim);
addBox(house.x, 1.55, 17.42, 1.1, 2.45, 0.16, M.wood);
addBox(house.x, 1.55, 17.32, 0.1, 2.45, 0.08, M.woodLight);
frontWindow(house.x, 3.65, 17.39, 0.72, 1.05);
if (house.h > 6.8) {
frontWindow(house.x, 5.55, 17.39, 0.62, 0.9);
}
reliefStones(house.x, 17.43, house.w - 0.3, house.h - 0.5, 9);
}
// Projecting timber balcony on a carved house.
addBox(-3.45, 2.85, 16.92, 2.75, 0.18, 1.45, M.wood);
for (const x of [-4.55, -3.45, -2.35]) {
addBox(x, 3.28, 16.35, 0.13, 0.83, 0.13, M.woodLight);
}
addBox(-3.45, 3.7, 16.35, 2.75, 0.13, 0.13, M.woodLight);
addBox(-3.45, 3.35, 16.35, 2.55, 0.1, 0.1, M.wood);
// Christ Church Cathedral.
addBox(7.2, 0.3, 20.45, 7.65, 0.6, 6.6, M.coralDark);
addBox(7.2, 3.55, 20.45, 7.35, 6.5, 6.25, M.coralB);
addBox(7.2, 6.95, 20.45, 7.7, 0.35, 6.6, M.trim);
// Stepped voxel roof.
addBox(7.2, 7.35, 20.45, 6.7, 0.45, 5.7, M.roof);
addBox(7.2, 7.8, 20.45, 5.6, 0.45, 4.9, M.roof);
addBox(7.2, 8.25, 20.45, 4.5, 0.45, 4.1, M.roofDark);
addBox(12.35, 5.75, 20.1, 3.45, 11.5, 4.55, M.coralA);
addBox(12.35, 11.65, 20.1, 3.85, 0.35, 4.9, M.trim);
addBox(12.35, 12.05, 20.1, 3.0, 0.45, 4.15, M.roofDark);
for (const x of [11.1, 13.6]) {
addBox(x, 12.48, 19.1, 0.7, 0.62, 0.7, M.coralA);
}
addBox(12.35, 9.6, 17.76, 1.25, 2.1, 0.18, M.dark);
addBox(7.2, 1.75, 17.28, 1.45, 3.15, 0.2, M.dark);
addBox(6.22, 1.85, 17.08, 0.38, 3.45, 0.4, M.trim);
addBox(8.18, 1.85, 17.08, 0.38, 3.45, 0.4, M.trim);
addBox(7.2, 3.55, 17.06, 2.35, 0.38, 0.4, M.trim);
addBox(7.2, 4.0, 17.05, 1.55, 0.32, 0.4, M.trim);
// Voxel cross.
addBox(12.35, 13.2, 20.1, 0.16, 1.6, 0.16, M.dark);
addBox(12.35, 13.4, 20.1, 1.25, 0.16, 0.16, M.dark);
reliefStones(7.2, 17.28, 7, 6, 14);
// Merchant house with bay and balcony.
addBox(23.1, 0.32, 20.6, 11.7, 0.65, 7.0, M.coralDark);
addBox(23.1, 4.75, 20.6, 11.3, 8.25, 6.65, M.coralA);
addBox(23.1, 9.05, 20.6, 11.7, 0.35, 7.05, M.trim);
addBox(23.1, 9.55, 20.6, 10.2, 0.45, 6.25, M.roof);
addBox(23.1, 10.0, 20.6, 8.8, 0.4, 5.3, M.roofDark);
addBox(23.1, 1.65, 17.22, 1.45, 3.0, 0.18, M.wood);
frontWindow(19.4, 3.45, 17.2, 0.8, 1.15);
frontWindow(26.8, 3.45, 17.2, 0.8, 1.15);
frontWindow(23.1, 5.7, 17.16, 1.2, 1.5);
addBox(23.1, 6.55, 16.9, 3.45, 2.15, 1.3, M.coralB);
addBox(23.1, 6.55, 16.18, 2.7, 1.4, 0.16, M.window);
addBox(23.1, 5.37, 16.38, 4.0, 0.18, 1.45, M.wood);
for (const x of [21.4, 22.35, 23.3, 24.25, 25.2]) {
addBox(x, 5.82, 15.88, 0.12, 0.85, 0.12, M.woodLight);
}
addBox(23.3, 6.23, 15.88, 4.0, 0.12, 0.12, M.woodLight);
reliefStones(23.1, 17.18, 10.8, 8, 24);
// -------------------------------------------------------------------
// Garden furniture, planting, and public-life vignettes.
// -------------------------------------------------------------------
function tree(x, z, scale = 1, baseY = 0.4) {
const trunkHeight = 1.8 * scale;
addBox(x, baseY + trunkHeight * 0.5, z, 0.36 * scale, trunkHeight, 0.36 * scale, M.trunk);
const canopyY = baseY + trunkHeight + 0.65 * scale;
addBox(x, canopyY, z, 2.5 * scale, 1.75 * scale, 2.45 * scale, M.foliage[0]);
addBox(x - 0.8 * scale, canopyY + 0.65 * scale, z + 0.25 * scale,
1.45 * scale, 1.2 * scale, 1.55 * scale, M.foliage[1]);
addBox(x + 0.75 * scale, canopyY + 0.5 * scale, z - 0.15 * scale,
1.45 * scale, 1.35 * scale, 1.65 * scale, M.foliage[2]);
addBox(x + 0.1 * scale, canopyY + 1.15 * scale, z,
1.2 * scale, 0.75 * scale, 1.3 * scale, M.foliage[3]);
}
function bench(x, z, rotation = 0, baseY = 0.28) {
const cos = Math.cos(rotation);
const sin = Math.sin(rotation);
const local = (lx, lz) => ({
x: x + lx * cos + lz * sin,
z: z - lx * sin + lz * cos
});
for (const lz of [-0.28, 0.28]) {
for (const lx of [-0.75, 0.75]) {
const p = local(lx, lz);
addBox(p.x, baseY + 0.3, p.z, 0.13, 0.6, 0.13, M.metal);
}
}
for (const lz of [-0.24, 0, 0.24]) {
const p = local(0, lz);
addBox(p.x, baseY + 0.62, p.z, 2.25, 0.12, 0.18, M.wood, 0, rotation);
}
for (const y of [0.9, 1.18]) {
const p = local(0, 0.44);
addBox(p.x, baseY + y, p.z, 2.25, 0.13, 0.12, M.wood, 0, rotation);
}
}
function lamp(x, z) {
addBox(x, 0.45, z, 0.46, 0.9, 0.46, M.coralDark);
addBox(x, 1.65, z, 0.16, 2.45, 0.16, M.metal);
addBox(x, 2.95, z, 0.66, 0.18, 0.66, M.metal);
addBox(x, 2.73, z, 0.48, 0.36, 0.48, M.cream);
addBox(x, 3.14, z, 0.78, 0.18, 0.78, M.roofDark);
}
function person(
x, z,
shirt,
skin = M.skinMedium,
pose = "stand",
scale = 1,
baseY = 0.43
) {
const s = scale;
const shirtMaterial = typeof shirt === "string" ? M[shirt] : shirt;
addBox(x - 0.13 * s, baseY + 0.36 * s, z, 0.18 * s, 0.58 * s, 0.2 * s, M.dark);
addBox(x + 0.13 * s, baseY + 0.36 * s, z, 0.18 * s, 0.58 * s, 0.2 * s, M.dark);
addBox(x, baseY + 0.88 * s, z, 0.48 * s, 0.58 * s, 0.29 * s, shirtMaterial);
addBox(x, baseY + 1.36 * s, z, 0.34 * s, 0.34 * s, 0.34 * s, skin);
addBox(x, baseY + 1.56 * s, z, 0.37 * s, 0.12 * s, 0.37 * s, M.dark);
if (pose === "kick") {
addBox(x - 0.14 * s, baseY + 0.43 * s, z, 0.18 * s, 0.62 * s, 0.2 * s,
M.dark, 0, 0, -0.48);
addBox(x + 0.35 * s, baseY + 0.9 * s, z, 0.17 * s, 0.52 * s, 0.18 * s,
skin, 0, 0, -0.75);
} else if (pose === "walk") {
addBox(x - 0.14 * s, baseY + 0.36 * s, z, 0.18 * s, 0.58 * s, 0.2 * s,
M.dark, 0, 0, -0.28);
addBox(x - 0.36 * s, baseY + 0.88 * s, z, 0.16 * s, 0.5 * s, 0.18 * s,
skin, 0, 0, -0.3);
addBox(x + 0.36 * s, baseY + 0.88 * s, z, 0.16 * s, 0.5 * s, 0.18 * s,
skin, 0, 0, 0.25);
} else if (pose === "exercise") {
addBox(x - 0.39 * s, baseY + 1.05 * s, z, 0.16 * s, 0.55 * s, 0.18 * s,
skin, 0, 0, -0.75);
addBox(x + 0.39 * s, baseY + 1.05 * s, z, 0.16 * s, 0.55 * s, 0.18 * s,
skin, 0, 0, 0.75);
} else if (pose === "read") {
addBox(x - 0.14 * s, baseY + 0.22 * s, z - 0.2 * s,
0.17 * s, 0.42 * s, 0.18 * s, M.dark, -1.35);
addBox(x + 0.14 * s, baseY + 0.22 * s, z - 0.2 * s,
0.17 * s, 0.42 * s, 0.18 * s, M.dark, -1.35);
addBox(x - 0.27 * s, baseY + 0.87 * s, z - 0.16 * s,
0.16 * s, 0.42 * s, 0.18 * s, skin, 0.6);
addBox(x + 0.27 * s, baseY + 0.87 * s, z - 0.16 * s,
0.16 * s, 0.42 * s, 0.18 * s, skin, 0.6);
addBox(x, baseY + 0.98 * s, z - 0.28 * s,
0.42 * s, 0.09 * s, 0.3 * s, M.white);
} else {
addBox(x - 0.34 * s, baseY + 0.88 * s, z, 0.16 * s, 0.5 * s, 0.18 * s, skin);
addBox(x + 0.34 * s, baseY + 0.88 * s, z, 0.16 * s, 0.5 * s, 0.18 * s, skin);
}
}
function flowerBed(x, z, width = 4.5, depth = 2.1) {
addBox(x, 0.46, z, width, 0.32, depth, M.soil);
addBox(x, 0.58, z - depth * 0.5, width + 0.2, 0.32, 0.18, M.trim);
addBox(x, 0.58, z + depth * 0.5, width + 0.2, 0.32, 0.18, M.trim);
const flowerMaterials = [M.flowerRed, M.flowerGold, M.flowerPink];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 8; col++) {
const fx = x - width * 0.43 + col * (width * 0.86 / 7);
const fz = z + (row - 0.5) * 0.85;
addBox(fx, 0.8, fz, 0.22, 0.25, 0.22, flowerMaterials[(col + row) % 3]);
}
}
}
function dhow(x, z, scale = 1) {
addBox(x, 0.42, z, 5.4 * scale, 0.65, 1.8 * scale, M.wood);
addBox(x, 0.84, z, 4.45 * scale, 0.48, 1.5 * scale, M.coralDark);
addBox(x - 2.7 * scale, 0.5, z, 0.65 * scale, 0.85, 1.55 * scale, M.wood);
addBox(x + 2.7 * scale, 0.5, z, 0.65 * scale, 0.85, 1.55 * scale, M.wood);
addBox(x, 2.9 * scale, z, 0.12 * scale, 4.7 * scale, 0.12 * scale, M.woodLight);
addBox(x, 3.15 * scale, z, 2.6 * scale, 2.0 * scale, 0.11 * scale, M.cream);
addBox(x, 4.7 * scale, z, 1.55 * scale, 1.15 * scale, 0.11 * scale, M.white);
addBox(x, 5.55 * scale, z, 0.6 * scale, 0.6 * scale, 0.11 * scale, M.cream);
addBox(x, 1.03 * scale, z, 3.8 * scale, 0.12, 0.12, M.woodLight);
}
// Shade trees around the garden perimeter.
const treePositions = [
[-24, -8.2, 0.95], [-24, 0.8, 1.05], [-24, 12.8, 0.9],
[-11.5, -8.2, 0.8], [11.8, -8.2, 0.9],
[12.0, 1.2, 0.78], [12.0, 13.2, 0.9],
[-13.2, 13.4, 0.82], [-0.8, 14.2, 0.78],
[-29.5, -12.7, 0.92], [29.5, -12.7, 0.9]
];
for (const [x, z, scale] of treePositions) {
tree(x, z, scale, z > -11 ? 0.48 : 0.22);
}
// Promenade furniture.
for (const x of [-24, -12, 0, 12, 24]) {
lamp(x, -13.45);
}
bench(-18, -12.2);
bench(-10, -11.5, Math.PI);
bench(2, -12.2);
bench(15, -11.4, Math.PI);
bench(-8.8, 6.1);
bench(-1.8, 6.1, Math.PI);
bench(-12, 3.5, Math.PI / 2);
bench(2.4, 3.5, Math.PI / 2);
// Bollards.
for (let x = -27; x <= 27; x += 4.5) {
addBox(x, 0.85, -14.45, 0.28, 0.8, 0.28, M.metal);
addBox(x, 1.28, -14.45, 0.38, 0.12, 0.38, M.dark);
}
flowerBed(10.7, 10.7, 4.4, 2.0);
flowerBed(-22.7, 10.6, 3.3, 1.8);
// Small refreshment terrace, not a market.
addBox(24.1, 0.78, -11.3, 1.7, 0.16, 1.7, M.woodLight);
addBox(24.1, 0.43, -11.3, 0.22, 0.75, 0.22, M.metal);
addBox(22.35, 0.63, -11.3, 0.8, 0.15, 0.8, M.wood);
addBox(25.9, 0.63, -11.3, 0.8, 0.15, 0.8, M.wood);
addBox(24.1, 1.8, -11.3, 0.16, 2.7, 0.16, M.metal);
addBox(24.1, 3.22, -11.3, 3.1, 0.18, 2.6, M.cream);
addBox(24.1, 3.45, -11.3, 2.45, 0.22, 2.05, M.coralB);
// Football / informal kick-about in the western lawn.
addBox(-23.0, 1.08, -4.6, 0.13, 1.8, 0.13, M.cream);
addBox(-19.5, 1.08, -4.6, 0.13, 1.8, 0.13, M.cream);
addBox(-21.25, 1.94, -4.6, 3.65, 0.13, 0.13, M.cream);
person(-18.8, -3.4, M.shirtRed, M.skinDark, "kick", 1.05, 0.46);
person(-21.0, -2.1, M.shirtBlue, M.skinLight, "stand", 0.98, 0.46);
person(-15.8, -2.0, M.shirtGold, M.skinMedium, "walk", 1.0, 0.46);
addBox(-18.0, 0.71, -3.8, 0.35, 0.35, 0.35, M.white);
addBox(-18.0, 0.91, -3.8, 0.18, 0.06, 0.18, M.dark);
// Group exercise in the southern-western lawn.
person(-19.4, 8.4, M.shirtGreen, M.skinLight, "exercise", 1.05, 0.46);
person(-17.7, 9.1, M.shirtPurple, M.skinMedium, "exercise", 1.0, 0.46);
person(-16.1, 8.6, M.shirtBlue, M.skinDark, "exercise", 1.05, 0.46);
person(-18.0, 10.2, M.shirtRed, M.skinLight, "exercise", 1.0, 0.46);
// Reading and gardening.
person(-8.8, 5.85, M.shirtPurple, M.skinMedium, "read", 0.96, 0.46);
person(11.6, 9.45, M.shirtGold, M.skinDark, "stand", 1.0, 0.46);
person(12.8, 11.4, M.shirtGreen, M.skinLight, "stand", 0.95, 0.46);
// Walking, pausing, and fishing at the waterfront.
person(6.4, -12.3, M.shirtBlue, M.skinMedium, "walk", 1.04, 0.3);
person(7.45, -12.45, M.shirtRed, M.skinLight, "walk", 1.0, 0.3);
person(25.2, -11.2, M.shirtGold, M.skinMedium, "read", 0.95, 0.3);
person(22.7, -11.3, M.shirtBlue, M.skinLight, "stand", 0.95, 0.3);
person(-14.6, -14.55, M.shirtGreen, M.skinDark, "stand", 1.0, 0.78);
addBox(-14.6, 1.1, -15.4, 0.12, 2.1, 0.12, M.woodLight);
addBox(-14.6, 1.85, -15.4, 0.08, 0.08, 1.65, M.cream);
// Dhows and waterfront utility.
dhow(12.8, -20.2, 1.0);
dhow(-23.5, -22.0, 0.72);
// A few cubes suggest gulls above the water.
addBox(-2.2, 13.6, -14.2, 0.65, 0.15, 0.22, M.white);
addBox(-1.65, 13.78, -14.2, 0.42, 0.14, 0.2, M.white, 0, 0, 0.18);
addBox(-2.75, 13.78, -14.2, 0.42, 0.14, 0.2, M.white, 0, 0, -0.18);
addBox(18.2, 11.8, -16.0, 0.55, 0.13, 0.2, M.white);
addBox(18.6, 11.95, -16.0, 0.36, 0.12, 0.18, M.white, 0, 0, 0.16);
buildBatches();
// -------------------------------------------------------------------
// Projected HTML labels.
// -------------------------------------------------------------------
const labelData = [
{
title: "Forodhani Gardens",
detail: "formal paths · clipped shade",
position: new THREE.Vector3(-5, 1.2, 2.2),
className: "green",
view: "garden"
},
{
title: "Waterfront promenade",
detail: "walking · fishing · pausing",
position: new THREE.Vector3(7, 2.4, -12.6),
className: "blue",
view: "waterfront"
},
{
title: "Old Fort",
detail: "massive coral-stone enclosure",
position: new THREE.Vector3(-21, 8.9, 19.5),
className: "coral",
view: "stone"
},
{
title: "Christ Church",
detail: "Gothic voxel silhouette",
position: new THREE.Vector3(10.2, 14.1, 19.5),
className: "coral",
view: "stone"
},
{
title: "Carved coral houses",
detail: "doors · shutters · balconies",
position: new THREE.Vector3(-1.6, 9.1, 20.0),
className: "coral",
view: "stone"
},
{
title: "Football and exercise",
detail: "ordinary lawn use",
position: new THREE.Vector3(-18.6, 3.1, -3.8),
className: "green",
view: "garden"
},
{
title: "Reading and gardening",
detail: "quiet everyday activity",
position: new THREE.Vector3(2.1, 3.1, 9.4),
className: "green",
view: "garden"
}
];
const labels = labelData.map((data) => {
const element = document.createElement("button");
element.className = `map-label ${data.className || ""}`;
element.innerHTML = `<strong>${data.title}</strong><span>${data.detail}</span>`;
element.setAttribute("aria-label", `Focus on ${data.title}`);
element.addEventListener("click", () => setView(data.view));
document.body.appendChild(element);
return { ...data, element };
});
// -------------------------------------------------------------------
// Custom camera controls — no external controls module is used.
// -------------------------------------------------------------------
const desired = {
target: new THREE.Vector3(0, 2.2, 0),
theta: 2.62,
phi: 0.93,
radius: 72
};
const current = {
target: desired.target.clone(),
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
const views = {
overview: {
target: new THREE.Vector3(0, 2.2, 0),
theta: 2.62,
phi: 0.93,
radius: 72
},
garden: {
target: new THREE.Vector3(-5, 1.3, 3),
theta: 2.53,
phi: 0.98,
radius: 49
},
waterfront: {
target: new THREE.Vector3(4, 0.4, -14),
theta: 2.72,
phi: 1.08,
radius: 43
},
stone: {
target: new THREE.Vector3(-2, 4, 18),
theta: 2.32,
phi: 0.92,
radius: 55
}
};
function setView(name) {
const view = views[name];
if (!view) return;
desired.target.copy(view.target);
desired.theta = view.theta;
desired.phi = view.phi;
desired.radius = view.radius;
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const toggle = document.querySelector("#toggle-labels");
toggle.addEventListener("click", () => {
const hidden = ui.classList.toggle("labels-off");
toggle.classList.toggle("active", !hidden);
toggle.setAttribute("aria-pressed", String(!hidden));
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= deltaX * 0.0052;
desired.phi = THREE.MathUtils.clamp(
desired.phi - deltaY * 0.0045,
0.32,
1.35
);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.remove("active");
});
});
function endDrag(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.045,
25,
105
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") desired.theta += 0.12;
if (event.key === "ArrowRight") desired.theta -= 0.12;
if (event.key === "ArrowUp") desired.phi = Math.max(0.32, desired.phi - 0.08);
if (event.key === "ArrowDown") desired.phi = Math.min(1.35, desired.phi + 0.08);
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
}
window.addEventListener("resize", resize);
const projected = new THREE.Vector3();
const spherical = new THREE.Spherical();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-delta * 5.5);
current.target.lerp(desired.target, damping);
current.theta = THREE.MathUtils.lerp(current.theta, desired.theta, damping);
current.phi = THREE.MathUtils.lerp(current.phi, desired.phi, damping);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, damping);
spherical.set(current.radius, current.phi, current.theta);
camera.position.setFromSpherical(spherical).add(current.target);
camera.lookAt(current.target);
camera.updateMatrixWorld();
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```