Prompt specification
Build or customize the Three.js 3D scene "Al Fahidi courtyard and Creek-side 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: Al Fahidi courtyard and Creek-side slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/al-fahidi-courtyard-and-creek-side-slice-x2907
Scene Description Prompt:
A voxel Dubai Al Fahidi slice with wind towers, courtyard, narrow passages, and a partial Creek edge. Three.js from cdnjs, one HTML file.
Working Three.js Starter (al-fahidi-courtyard-and-creek-side-slice-x2907):
```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="#cbb995" />
<title>Al Fahidi — Wind & Water</title>
<style>
:root {
color-scheme: light;
--ink: #302d28;
--paper: rgba(246, 238, 218, 0.88);
--line: rgba(67, 57, 43, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbb995;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.eyebrow {
margin: 0 0 0.65rem;
font-size: 0.68rem;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
opacity: 0.72;
}
.title-block {
position: absolute;
left: clamp(1.2rem, 3.2vw, 3.4rem);
bottom: clamp(1.4rem, 4vw, 3.5rem);
max-width: min(29rem, calc(100vw - 2.4rem));
}
.title-block h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(2.5rem, 6vw, 5.6rem);
font-weight: 400;
line-height: 0.86;
letter-spacing: -0.055em;
text-shadow: 0 1px 16px rgba(255, 247, 224, 0.22);
}
.title-block p:last-child {
margin: 1.15rem 0 0;
max-width: 24rem;
font-size: clamp(0.74rem, 1.4vw, 0.9rem);
line-height: 1.6;
opacity: 0.74;
}
.topbar {
position: absolute;
top: clamp(1rem, 2.8vw, 2.5rem);
right: clamp(1rem, 2.8vw, 2.5rem);
display: flex;
align-items: center;
gap: 0.65rem;
pointer-events: auto;
}
.control-chip,
#reset {
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 8px 24px rgba(73, 57, 35, 0.08);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.control-chip {
padding: 0.72rem 0.9rem;
border-radius: 999px;
font-size: 0.67rem;
font-weight: 650;
letter-spacing: 0.055em;
white-space: nowrap;
}
.control-chip span {
opacity: 0.48;
padding: 0 0.35rem;
}
#reset {
width: 2.55rem;
height: 2.55rem;
border-radius: 50%;
color: var(--ink);
cursor: pointer;
font-size: 1.05rem;
transition:
transform 160ms ease,
background 160ms ease;
}
#reset:hover {
transform: rotate(-18deg) scale(1.05);
background: rgba(255, 250, 236, 0.96);
}
.compass {
position: absolute;
right: clamp(1.25rem, 3vw, 3rem);
bottom: clamp(1.25rem, 3vw, 2.8rem);
width: 3.25rem;
height: 3.25rem;
border: 1px solid var(--line);
border-radius: 50%;
display: grid;
place-items: center;
background: rgba(244, 235, 213, 0.35);
}
#compass-arrow {
width: 1.15rem;
height: 2.15rem;
position: relative;
transition: transform 80ms linear;
}
#compass-arrow::before {
content: "";
position: absolute;
left: 50%;
top: 0;
width: 0;
height: 0;
transform: translateX(-50%);
border-left: 0.38rem solid transparent;
border-right: 0.38rem solid transparent;
border-bottom: 1.25rem solid #4d4436;
}
#compass-arrow::after {
content: "";
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
border-left: 0.25rem solid transparent;
border-right: 0.25rem solid transparent;
border-bottom: 0.85rem solid rgba(77, 68, 54, 0.38);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #cbb995;
transition: opacity 600ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
width: 3rem;
height: 3rem;
border: 2px solid rgba(64, 54, 40, 0.2);
border-top-color: rgba(64, 54, 40, 0.75);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 650px) {
.control-chip {
display: none;
}
.title-block p:last-child {
max-width: 17rem;
}
.compass {
width: 2.6rem;
height: 2.6rem;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<div class="title-block">
<p class="eyebrow">Dubai · Historic District</p>
<h1>Wind &<br />Water</h1>
<p>
A voxel slice of Al Fahidi: shaded courtyards, wind towers,
narrow passages, and a fragment of the Creek.
</p>
</div>
<div class="topbar">
<div class="control-chip">
Drag to orbit <span>·</span> Shift-drag to pan <span>·</span> Scroll to zoom
</div>
<button id="reset" type="button" title="Reset view" aria-label="Reset view">↺</button>
</div>
<div class="compass" aria-hidden="true">
<div id="compass-arrow"></div>
</div>
</div>
<div id="loading">
<div class="loader"></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 container = document.getElementById("scene");
const resetButton = document.getElementById("reset");
const compassArrow = document.getElementById("compass-arrow");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbb995);
scene.fog = new THREE.Fog(0xcbb995, 46, 92);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.03;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 12.5, -12.5, 0.1, 180);
const controls = {
target: new THREE.Vector3(-0.4, 1.6, 0.3),
theta: 0.72,
phi: 0.88,
zoom: 1,
radius: 48
};
const initialControls = {
target: controls.target.clone(),
theta: controls.theta,
phi: controls.phi,
zoom: controls.zoom
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const rippleObjects = [];
const boat = new THREE.Group();
function material(color, roughness = 0.82, metalness = 0, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
...options
});
}
const mats = {
sand: material(0xc9aa73),
sandLight: material(0xdcc28e),
sandPale: material(0xe2cda1),
sandRose: material(0xc89f72),
plaster: material(0xd8bd89),
plasterLight: material(0xe4ce9f),
base: material(0x9c744d),
baseDark: material(0x74563e),
stone: material(0xb99c72),
stoneLight: material(0xd0b78c),
wood: material(0x67442e, 0.9),
woodLight: material(0x8d633c, 0.9),
darkWood: material(0x3f3027, 0.95),
window: material(0x263537, 0.42, 0.05),
windowWarm: material(0x745238, 0.65),
water: material(0x3d8791, 0.3, 0.05),
waterDark: material(0x286976, 0.38, 0.03),
waterLight: material(0x86b8b2, 0.38, 0),
green: material(0x526d45, 0.92),
greenLight: material(0x718153, 0.9),
greenDark: material(0x384d35, 0.95),
terracotta: material(0xa95e42, 0.88),
cream: material(0xe9d6aa, 0.8),
rust: material(0x9d5138, 0.78),
blue: material(0x466d79, 0.8),
ground: material(0xc8b38d, 1),
charcoal: material(0x34302b, 0.9),
shadow: material(0x7c715f, 1)
};
function box(parent, sx, sy, sz, x, y, z, mat, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent, x = 0, y = 0, z = 0) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
// Lighting
const hemi = new THREE.HemisphereLight(0xffefd1, 0x65716d, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe5b8, 3.6);
sun.position.set(-16, 28, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -31;
sun.shadow.camera.right = 31;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d6d8, 0.75);
fill.position.set(20, 12, -18);
scene.add(fill);
// Large matte table/ground beneath the diorama.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
mats.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.32;
ground.receiveShadow = true;
scene.add(ground);
// Diorama base: land on the left, water on the right.
box(scene, 26.3, 1.3, 22, -3.35, -0.65, 0, mats.base);
box(scene, 26.4, 0.18, 22.1, -3.35, -1.16, 0, mats.baseDark);
box(scene, 6.7, 1.2, 22, 13.15, -0.72, 0, mats.waterDark);
box(scene, 6.7, 0.12, 22, 13.15, -0.12, 0, mats.water);
// Creek retaining wall and promenade.
box(scene, 0.38, 1.5, 22, 9.82, -0.22, 0, mats.stone);
box(scene, 0.64, 0.2, 22.1, 9.7, 0.54, 0, mats.stoneLight);
box(scene, 0.42, 0.08, 21.8, 9.55, 0.03, 0, mats.sandPale, false);
// Water ripples made from low rectangular tiles.
let seed = 8473;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 52; i++) {
const ripple = box(
scene,
0.45 + random() * 1.8,
0.018,
0.035 + random() * 0.045,
10.35 + random() * 5.9,
-0.045,
-10.5 + random() * 21,
i % 3 === 0 ? mats.waterLight : mats.stoneLight,
false
);
ripple.material = ripple.material.clone();
ripple.material.transparent = true;
ripple.material.opacity = 0.2 + random() * 0.35;
rippleObjects.push({
mesh: ripple,
phase: random() * Math.PI * 2,
baseOpacity: ripple.material.opacity
});
}
// Steps from the quay to the water.
for (let i = 0; i < 4; i++) {
box(
scene,
1.15,
0.25,
2.8,
10.05 + i * 0.48,
0.35 - i * 0.23,
-6.2,
mats.stoneLight
);
}
// Wind tower: an open, louvred barjeel.
function windTower(parent, x, z, baseY, size = 1.6, height = 2.6) {
const tower = group(parent, x, baseY, z);
const post = 0.23;
const half = size / 2 - post / 2;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
tower,
post,
height,
post,
sx * half,
height / 2,
sz * half,
mats.plasterLight
);
}
}
// Upper ring.
box(tower, size, 0.18, 0.18, 0, height - 0.08, -half, mats.stoneLight);
box(tower, size, 0.18, 0.18, 0, height - 0.08, half, mats.stoneLight);
box(tower, 0.18, 0.18, size, -half, height - 0.08, 0, mats.stoneLight);
box(tower, 0.18, 0.18, size, half, height - 0.08, 0, mats.stoneLight);
// Louvres on two sides.
for (const y of [height * 0.62, height * 0.79]) {
box(tower, size * 0.7, 0.10, 0.11, 0, y, -half, mats.woodLight);
box(tower, 0.11, 0.10, size * 0.7, half, y, 0, mats.woodLight);
}
// Small roof cap.
box(tower, size + 0.25, 0.28, size + 0.25, 0, height + 0.1, 0, mats.plasterLight);
box(tower, size * 0.78, 0.18, size * 0.78, 0, height + 0.32, 0, mats.sandPale);
// Recessed dark slot under the cap.
box(
tower,
size * 0.48,
0.38,
0.05,
0,
height - 0.35,
-half - 0.015,
mats.window,
false
);
box(
tower,
0.05,
0.38,
size * 0.48,
-half - 0.015,
height - 0.35,
0,
mats.window,
false
);
return tower;
}
// Windows and doors on z-facing walls.
function zWindow(parent, x, y, z, sign, width = 0.64, height = 0.78) {
box(
parent,
width,
height,
0.055,
x,
y,
z + sign * 0.037,
mats.window,
false
);
box(
parent,
width + 0.15,
0.09,
0.12,
x,
y + height / 2 + 0.04,
z + sign * 0.065,
mats.woodLight,
false
);
box(
parent,
0.055,
height,
0.12,
x,
y,
z + sign * 0.065,
mats.wood,
false
);
}
// Windows and doors on x-facing walls.
function xWindow(parent, x, y, z, sign, width = 0.64, height = 0.78) {
box(
parent,
0.055,
height,
width,
x + sign * 0.037,
y,
z,
mats.window,
false
);
box(
parent,
0.12,
0.09,
width + 0.15,
x + sign * 0.065,
y + height / 2 + 0.04,
z,
mats.woodLight,
false
);
box(
parent,
0.12,
height,
0.055,
x + sign * 0.065,
y,
z,
mats.wood,
false
);
}
function zDoor(parent, x, z, sign) {
box(parent, 0.92, 1.55, 0.07, x, 0.82, z + sign * 0.045, mats.darkWood, false);
box(parent, 1.16, 0.14, 0.17, x, 1.66, z + sign * 0.09, mats.woodLight);
box(parent, 0.1, 1.62, 0.13, x - 0.5, 0.83, z + sign * 0.09, mats.wood);
box(parent, 0.1, 1.62, 0.13, x + 0.5, 0.83, z + sign * 0.09, mats.wood);
box(parent, 0.52, 0.3, 0.07, x, 1.86, z + sign * 0.045, mats.darkWood, false);
}
function xDoor(parent, x, z, sign) {
box(parent, 0.07, 1.55, 0.92, x + sign * 0.045, 0.82, z, mats.darkWood, false);
box(parent, 0.17, 0.14, 1.16, x + sign * 0.09, 1.66, z, mats.woodLight);
box(parent, 0.13, 1.62, 0.1, x + sign * 0.09, 0.83, z - 0.5, mats.wood);
box(parent, 0.13, 1.62, 0.1, x + sign * 0.09, 0.83, z + 0.5, mats.wood);
}
function building({
x,
z,
w,
d,
h,
mat = mats.sand,
towers = 1,
roofMaterial = mats.plasterLight,
sideDoor = false
}) {
const g = group(scene, x, 0, z);
box(g, w, h, d, 0, h / 2, 0, mat);
box(g, w + 0.16, 0.32, d + 0.16, 0, 0.16, 0, mats.stone);
box(g, w + 0.22, 0.24, d + 0.22, 0, h - 0.12, 0, roofMaterial);
// Parapets.
box(g, w, 0.45, 0.25, 0, h + 0.12, -d / 2, roofMaterial);
box(g, w, 0.45, 0.25, 0, h + 0.12, d / 2, roofMaterial);
box(g, 0.25, 0.45, d, -w / 2, h + 0.12, 0, roofMaterial);
box(g, 0.25, 0.45, d, w / 2, h + 0.12, 0, roofMaterial);
// Corner accents.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
g,
0.22,
h - 0.2,
0.22,
sx * (w / 2 - 0.09),
(h - 0.2) / 2,
sz * (d / 2 - 0.09),
roofMaterial
);
}
}
const floors = Math.max(1, Math.floor((h - 0.8) / 2.1));
const zCount = Math.max(2, Math.min(4, Math.floor(w / 1.8)));
const xCount = Math.max(2, Math.min(3, Math.floor(d / 2)));
for (let floor = 0; floor < floors; floor++) {
const wy = 1.25 + floor * 2.05;
for (const sign of [-1, 1]) {
for (let i = 0; i < zCount; i++) {
const wx = -w * 0.36 + (i * w * 0.72) / Math.max(1, zCount - 1);
zWindow(g, wx, wy, sign * d / 2, sign);
}
}
for (let i = 0; i < xCount; i++) {
const wz = -d * 0.28 + (i * d * 0.56) / Math.max(1, xCount - 1);
xWindow(g, w / 2, wy, wz, 1);
}
}
zDoor(g, -w * 0.12, d / 2, 1);
if (w > 5.8) zDoor(g, w * 0.15, -d / 2, -1);
if (sideDoor) xDoor(g, w / 2, -d * 0.14, 1);
// Projecting timber beams.
box(g, w * 0.86, 0.12, 0.18, 0, h - 0.72, d / 2 + 0.12, mats.wood);
box(g, 0.18, 0.12, d * 0.82, w / 2 + 0.12, h - 0.72, 0, mats.wood);
// Rooftop storage boxes and jars.
box(g, 0.75, 0.55, 0.65, -w * 0.28, h + 0.58, -d * 0.18, mats.woodLight);
box(g, 0.55, 0.4, 0.55, w * 0.25, h + 0.5, d * 0.16, mats.terracotta);
if (towers > 0) {
if (towers === 1) {
windTower(g, 0, -0.05, h + 0.25, 1.55, 2.55);
} else {
windTower(g, -w * 0.22, -d * 0.08, h + 0.25, 1.5, 2.6);
windTower(g, w * 0.22, d * 0.08, h + 0.25, 1.5, 2.35);
}
}
return g;
}
// A compact courtyard, deliberately enclosed but open to the camera.
box(scene, 5.7, 0.09, 8.0, -3.55, 0.055, -0.5, mats.sandLight, false);
// Paving joints.
for (let x = -6.2; x <= -0.7; x += 1.1) {
box(scene, 0.045, 0.015, 7.85, x, 0.108, -0.5, mats.stone, false);
}
for (let z = -4.35; z <= 3.35; z += 1.05) {
box(scene, 5.55, 0.015, 0.045, -3.55, 0.109, z, mats.stone, false);
}
// Main building cluster around the courtyard.
building({
x: -13.0,
z: -4.4,
w: 4.2,
d: 6.1,
h: 6.9,
mat: mats.plaster,
towers: 1
});
building({
x: -13.0,
z: 4.7,
w: 4.2,
d: 5.4,
h: 5.3,
mat: mats.sandRose,
towers: 1
});
building({
x: -7.6,
z: -0.7,
w: 3.2,
d: 8.2,
h: 6.2,
mat: mats.sandLight,
towers: 1,
sideDoor: true
});
building({
x: -3.0,
z: -6.2,
w: 6.8,
d: 3.4,
h: 6.6,
mat: mats.plaster,
towers: 2
});
building({
x: -3.0,
z: 5.25,
w: 7.0,
d: 3.5,
h: 4.8,
mat: mats.sand,
towers: 1
});
building({
x: 0.9,
z: -0.4,
w: 3.2,
d: 7.2,
h: 6.7,
mat: mats.sandRose,
towers: 1,
sideDoor: true
});
building({
x: 4.6,
z: -5.8,
w: 4.5,
d: 5.2,
h: 5.4,
mat: mats.sandLight,
towers: 1
});
building({
x: 4.5,
z: 1.8,
w: 4.2,
d: 5.2,
h: 6.1,
mat: mats.plasterLight,
towers: 1
});
building({
x: 4.2,
z: 6.7,
w: 5.0,
d: 3.1,
h: 4.3,
mat: mats.sandRose,
towers: 1
});
building({
x: -8.7,
z: 6.6,
w: 4.3,
d: 4.1,
h: 4.7,
mat: mats.sand,
towers: 1
});
// Narrow passage paving.
box(scene, 1.65, 0.055, 16.8, -10.05, 0.03, 0.3, mats.stoneLight, false);
box(scene, 1.75, 0.055, 17.8, 0.75, 0.031, 0.7, mats.stoneLight, false);
box(scene, 10.2, 0.055, 0.9, -3.3, 0.032, -4.25, mats.stoneLight, false);
// Low timber gates across the alleys.
function passageGate(x, z, width) {
const gate = group(scene, x, 0, z);
box(gate, 0.18, 2.9, 0.18, -width / 2, 1.45, 0, mats.darkWood);
box(gate, 0.18, 2.9, 0.18, width / 2, 1.45, 0, mats.darkWood);
box(gate, width + 0.25, 0.23, 0.22, 0, 2.9, 0, mats.wood);
for (let i = -1; i <= 1; i++) {
box(gate, 0.08, 1.8, 0.1, i * width * 0.27, 1.9, 0.03, mats.woodLight);
}
box(gate, width + 0.1, 0.14, 0.55, 0, 2.65, 0.18, mats.woodLight);
}
passageGate(-10.05, 0.8, 1.65);
passageGate(0.78, 4.65, 1.75);
// Courtyard steps.
for (let i = 0; i < 3; i++) {
box(
scene,
2.1,
0.13,
0.62,
-3.0,
0.13 + i * 0.035,
-4.3 + i * 0.48,
mats.stoneLight
);
}
// Small square fountain.
const fountain = group(scene, -3.35, 0, -0.65);
box(fountain, 1.8, 0.35, 1.8, 0, 0.2, 0, mats.stone);
box(fountain, 1.35, 0.08, 1.35, 0, 0.4, 0, mats.water, false);
box(fountain, 0.45, 0.58, 0.45, 0, 0.64, 0, mats.stoneLight);
box(fountain, 0.78, 0.12, 0.78, 0, 0.94, 0, mats.stone);
// Low seating and planters.
box(scene, 1.8, 0.34, 0.62, -4.75, 0.23, 1.9, mats.plasterLight);
box(scene, 0.55, 0.38, 1.65, -5.45, 0.24, -1.9, mats.plasterLight);
box(scene, 0.8, 0.45, 0.8, -1.55, 0.28, 2.2, mats.terracotta);
box(scene, 0.55, 0.45, 0.55, -1.55, 0.68, 2.2, mats.greenDark);
// Laundry line between two towers.
box(scene, 7.0, 0.035, 0.035, -3.45, 4.05, 1.45, mats.darkWood, false);
const clothMaterials = [mats.cream, mats.rust, mats.blue, mats.sandPale];
for (let i = 0; i < 7; i++) {
const cloth = box(
scene,
0.42,
0.58,
0.035,
-6.35 + i * 0.93,
3.72,
1.45,
clothMaterials[i % clothMaterials.length],
false
);
cloth.rotation.z = (i % 2 ? 1 : -1) * 0.035;
}
// Voxel date palm.
function palm(x, z, scale = 1) {
const g = group(scene, x, 0, z);
g.scale.setScalar(scale);
for (let i = 0; i < 6; i++) {
box(
g,
0.28,
0.58,
0.28,
Math.sin(i * 0.6) * 0.08,
0.28 + i * 0.52,
i * 0.035,
mats.woodLight
);
}
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = box(
g,
0.34,
0.18,
1.9,
Math.sin(angle) * 0.72,
3.18 + (i % 2) * 0.08,
Math.cos(angle) * 0.72,
i % 2 ? mats.green : mats.greenLight
);
leaf.rotation.y = angle;
leaf.rotation.x = 0.08;
}
box(g, 0.34, 0.3, 0.34, 0.18, 3.05, 0.1, mats.greenDark);
box(g, 0.3, 0.28, 0.3, -0.16, 3.05, -0.12, mats.greenDark);
return g;
}
palm(-5.2, 2.25, 0.88);
palm(8.65, -8.1, 1.02);
palm(8.55, 7.9, 0.8);
palm(12.0, -9.0, 0.72);
// Potted shrubs and small waterside plants.
function planter(x, z, size = 0.6) {
box(scene, size, size * 0.62, size, x, size * 0.31, z, mats.terracotta);
box(
scene,
size * 0.82,
size * 0.48,
size * 0.82,
x,
size * 0.78,
z,
mats.greenDark
);
box(
scene,
size * 0.48,
size * 0.42,
size * 0.48,
x + size * 0.12,
size * 1.05,
z,
mats.green
);
}
planter(-0.25, -3.55, 0.62);
planter(8.45, -3.5, 0.7);
planter(8.45, 2.9, 0.58);
planter(11.2, 8.5, 0.54);
// Quay bollards.
for (const z of [-8.8, -6.0, -2.0, 1.0, 4.0, 8.6]) {
box(scene, 0.23, 0.66, 0.23, 9.05, 0.38, z, mats.darkWood);
box(scene, 0.34, 0.12, 0.34, 9.05, 0.72, z, mats.wood);
}
// Crates and sacks near the waterfront.
box(scene, 0.8, 0.72, 0.8, 8.3, 0.39, 0.1, mats.woodLight);
box(scene, 0.72, 0.62, 0.72, 8.35, 1.02, 0.05, mats.wood);
box(scene, 0.75, 0.5, 0.65, 7.65, 0.28, 5.8, mats.terracotta);
box(scene, 0.65, 0.45, 0.6, 8.35, 0.25, 6.2, mats.cream);
// Small traditional dhow.
scene.add(boat);
boat.position.set(12.75, -0.05, 1.25);
boat.rotation.y = -0.3;
box(boat, 3.8, 0.48, 1.15, 0, 0.05, 0, mats.wood);
box(boat, 1.0, 0.58, 1.35, 1.95, 0.08, 0, mats.woodLight);
box(boat, 0.8, 0.5, 0.95, 2.9, 0.04, 0, mats.wood);
box(boat, 1.0, 0.45, 0.72, -2.1, 0.04, 0, mats.wood);
box(boat, 1.15, 0.22, 0.85, -2.85, 0.02, 0, mats.woodLight);
box(boat, 1.5, 0.85, 0.85, -0.65, 0.55, 0, mats.cream);
box(boat, 1.65, 0.12, 1.0, -0.65, 1.02, 0, mats.rust);
box(boat, 0.12, 3.4, 0.12, 0.35, 1.72, 0, mats.darkWood);
box(boat, 2.1, 0.1, 0.1, 0.65, 1.05, 0.1, mats.woodLight);
const sailGeometry = new THREE.BufferGeometry();
sailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0, 0,
0, 3.15, 0,
2.1, 0.42, 0
], 3)
);
sailGeometry.computeVertexNormals();
const sail = new THREE.Mesh(
sailGeometry,
new THREE.MeshStandardMaterial({
color: 0xe4cf9d,
roughness: 0.92,
side: THREE.DoubleSide
})
);
sail.position.set(0.3, 0.85, 0.13);
sail.castShadow = true;
boat.add(sail);
// A rope from quay to boat.
const ropePoints = [
new THREE.Vector3(9.0, 0.66, 1.0),
new THREE.Vector3(10.9, -0.05, 0.95),
new THREE.Vector3(11.1, 0.15, 1.05)
];
const rope = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(ropePoints),
new THREE.LineBasicMaterial({ color: 0x5b4633 })
);
scene.add(rope);
// Small birds over the Creek, built from dark narrow boxes.
function bird(x, y, z, scale = 1) {
const b = group(scene, x, y, z);
b.scale.setScalar(scale);
const left = box(b, 0.45, 0.035, 0.09, -0.18, 0, 0, mats.charcoal, false);
const right = box(b, 0.45, 0.035, 0.09, 0.18, 0, 0, mats.charcoal, false);
left.rotation.z = 0.22;
right.rotation.z = -0.22;
}
bird(12.7, 6.6, -3.4, 1.0);
bird(14.1, 7.3, -3.0, 0.7);
bird(11.9, 7.7, -2.7, 0.55);
// Custom camera controls.
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = aspect < 1 ? 37 / aspect : 25;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
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);
compassArrow.style.transform = `rotate(${-controls.theta * 180 / Math.PI}deg)`;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey || event.button === 2;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const units =
((camera.top - camera.bottom) / controls.zoom) /
window.innerHeight;
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.setY(0)
.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1)
.setY(0)
.normalize();
controls.target.addScaledVector(right, -dx * units);
controls.target.addScaledVector(up, dy * units);
} else {
controls.theta -= dx * 0.0055;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.0045,
0.38,
1.27
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * 0.001);
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * factor,
0.68,
2.6
);
updateCamera();
},
{ passive: false }
);
resetButton.addEventListener("click", () => {
controls.target.copy(initialControls.target);
controls.theta = initialControls.theta;
controls.phi = initialControls.phi;
controls.zoom = initialControls.zoom;
updateCamera();
});
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetButton.click();
} else if (key === "arrowleft") {
controls.theta -= 0.08;
} else if (key === "arrowright") {
controls.theta += 0.08;
} else if (key === "arrowup") {
controls.phi = Math.max(0.38, controls.phi - 0.05);
} else if (key === "arrowdown") {
controls.phi = Math.min(1.27, controls.phi + 0.05);
} else if (key === "+" || key === "=") {
controls.zoom = Math.min(2.6, controls.zoom * 1.1);
} else if (key === "-") {
controls.zoom = Math.max(0.68, controls.zoom / 1.1);
} else {
return;
}
event.preventDefault();
updateCamera();
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const ripple of rippleObjects) {
ripple.mesh.material.opacity =
ripple.baseOpacity * (0.72 + Math.sin(elapsed * 0.8 + ripple.phase) * 0.28);
}
boat.position.y = -0.05 + Math.sin(elapsed * 0.9) * 0.025;
boat.rotation.z = Math.sin(elapsed * 0.65) * 0.008;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```