Prompt specification
Build or customize the Three.js 3D scene "Algiers Casbah terrace-and-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: Algiers Casbah terrace-and-lane slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/algiers-casbah-terrace-and-lane-slice-x2891
Scene Description Prompt:
Build a voxel slice of Algiers's Casbah: stepped roofs, narrow lanes, and a courtyard following the hillside. One HTML file using Three.js from cdnjs.
Working Three.js Starter (algiers-casbah-terrace-and-lane-slice-x2891):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Algiers — A Voxel Casbah</title>
<style>
:root {
--ink: #233534;
--paper: #f5ead4;
--accent: #bb553f;
--line: rgba(35, 53, 52, 0.24);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e6e3;
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;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 48%, rgba(30, 54, 54, 0.13) 120%),
linear-gradient(to bottom, rgba(255, 255, 255, 0.05), transparent 25%);
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title {
position: absolute;
top: clamp(22px, 4vw, 54px);
left: clamp(22px, 4vw, 58px);
max-width: 360px;
text-shadow: 0 1px 16px rgba(255, 255, 255, 0.45);
}
.eyebrow {
margin: 0 0 10px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.28em;
text-transform: uppercase;
color: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 72px);
line-height: 0.88;
font-weight: 500;
letter-spacing: -0.055em;
}
.subtitle {
margin: 17px 0 0;
max-width: 275px;
font-size: 12px;
line-height: 1.65;
letter-spacing: 0.04em;
color: rgba(35, 53, 52, 0.78);
}
.coordinates {
position: absolute;
top: clamp(24px, 4vw, 56px);
right: clamp(22px, 4vw, 58px);
text-align: right;
font-size: 10px;
line-height: 1.8;
letter-spacing: 0.16em;
text-transform: uppercase;
color: rgba(35, 53, 52, 0.72);
}
.coordinates strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 500;
letter-spacing: 0.04em;
text-transform: none;
}
.bottom {
position: absolute;
bottom: clamp(20px, 3vw, 40px);
left: clamp(22px, 4vw, 58px);
right: clamp(22px, 4vw, 58px);
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
}
.hint {
display: flex;
align-items: center;
gap: 12px;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.15em;
text-transform: uppercase;
color: rgba(35, 53, 52, 0.7);
}
.hint::before {
content: "";
width: 28px;
height: 1px;
background: var(--accent);
}
.controls {
pointer-events: auto;
display: flex;
gap: 8px;
}
button {
border: 1px solid var(--line);
background: rgba(245, 234, 212, 0.7);
color: var(--ink);
height: 38px;
padding: 0 15px;
border-radius: 2px;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(245, 234, 212, 0.96);
transform: translateY(-1px);
}
.zoom {
width: 38px;
padding: 0;
font-size: 18px;
font-weight: 400;
}
#loader {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #d9e6e3;
transition: opacity 600ms ease, visibility 600ms ease;
}
#loader.hidden {
opacity: 0;
visibility: hidden;
}
.loader-mark {
width: 120px;
text-align: center;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.25em;
text-transform: uppercase;
}
.loader-mark::after {
content: "";
display: block;
width: 100%;
height: 2px;
margin-top: 15px;
background: linear-gradient(90deg, transparent, var(--accent), transparent);
animation: breathe 1.3s ease-in-out infinite;
}
@keyframes breathe {
0%, 100% { opacity: 0.25; transform: scaleX(0.35); }
50% { opacity: 1; transform: scaleX(1); }
}
@media (max-width: 680px) {
.coordinates {
display: none;
}
.subtitle {
max-width: 220px;
}
.hint {
display: none;
}
.bottom {
justify-content: flex-end;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<div class="hud">
<section class="title">
<p class="eyebrow">Algiers · Algeria</p>
<h1>The<br />Casbah</h1>
<p class="subtitle">
A voxel study of stepped whitewashed roofs, shaded passages, and hillside courtyards
descending toward the Mediterranean.
</p>
</section>
<div class="coordinates">
<strong>35° 02′ N 3° 03′ E</strong>
Mediterranean hillside
</div>
<div class="bottom">
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="controls">
<button class="zoom" id="zoomIn" aria-label="Zoom in">+</button>
<button class="zoom" id="zoomOut" aria-label="Zoom out">−</button>
<button id="reset">Reset view</button>
</div>
</div>
</div>
<div id="loader">
<div class="loader-mark">Building the Casbah</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 loader = document.getElementById("loader");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e6e3);
scene.fog = new THREE.Fog(0xd9e6e3, 48, 118);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
220
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
container.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xeaf8ff, 0xa77b58, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d0, 3.35);
sun.position.set(-15, 26, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(innerWidth < 700 ? 1024 : 2048, innerWidth < 700 ? 1024 : 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbadce4, 0.72);
fill.position.set(18, 11, -20);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitEdges = new THREE.EdgesGeometry(unitBox);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x594a39,
transparent: true,
opacity: 0.18
});
const materialCache = new Map();
function matte(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0
})
);
}
return materialCache.get(color);
}
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x243c3e,
roughness: 0.35,
metalness: 0.08
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x332a24,
roughness: 0.94
});
const roofMaterial = matte(0xd6c5a6);
const trimMaterial = matte(0xf0e6cf);
const pathMaterial = matte(0x9c8b70);
const stepMaterial = matte(0xc6b391);
const stoneMaterial = matte(0xb9a587);
const rockMaterial = matte(0x8f7960);
function box(w, h, d, material, x, y, z, parent = scene, outline = false, cast = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
if (outline) {
const lines = new THREE.LineSegments(unitEdges, edgeMaterial);
mesh.add(lines);
}
return mesh;
}
let seed = 7319;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function beamBetween(a, b, thickness, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const mesh = box(thickness, length, thickness, material, 0, 0, 0, parent, false, false);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// Mediterranean water and the far edge of the city.
const seaMaterial = new THREE.MeshStandardMaterial({
color: 0x4f929a,
roughness: 0.58,
metalness: 0.04
});
const sea = new THREE.Mesh(new THREE.PlaneGeometry(180, 180), seaMaterial);
sea.rotation.x = -Math.PI / 2;
sea.position.y = -3.18;
sea.receiveShadow = true;
scene.add(sea);
box(52, 2.3, 15, matte(0x9e9b83), 0, -2.1, -29, scene, false, false);
const distantCity = new THREE.InstancedMesh(
unitBox,
matte(0xc8c3ad),
34
);
const cityDummy = new THREE.Object3D();
for (let i = 0; i < 34; i++) {
const w = 1.2 + random() * 2.8;
const h = 1.0 + random() * 5.2;
const d = 1.3 + random() * 2.7;
cityDummy.position.set(
-24 + random() * 48,
-0.95 + h / 2,
-24 - random() * 10
);
cityDummy.scale.set(w, h, d);
cityDummy.rotation.y = (random() - 0.5) * 0.22;
cityDummy.updateMatrix();
distantCity.setMatrixAt(i, cityDummy.matrix);
distantCity.setColorAt(
i,
new THREE.Color().setHSL(0.10 + random() * 0.025, 0.15, 0.69 + random() * 0.1)
);
}
distantCity.instanceMatrix.needsUpdate = true;
if (distantCity.instanceColor) distantCity.instanceColor.needsUpdate = true;
scene.add(distantCity);
// Stepped island and retaining walls.
box(28, 2.8, 32, rockMaterial, 0, -1.4, 0, scene, true);
box(27, 0.9, 10, stoneMaterial, 0, -0.45, 10, scene, true);
box(25, 1.8, 9, stoneMaterial, 0, 0.4, 1.5, scene, true);
box(23, 2.9, 9, stoneMaterial, 0, 1.15, -6.5, scene, true);
box(19, 2.9, 6, stoneMaterial, 0, 2.45, -13, scene, true);
function retainingWall(z, baseY, height, gapCenter = 0.35, gapWidth = 1.65) {
const leftEdge = -12;
const rightEdge = 12;
const gapLeft = gapCenter - gapWidth / 2;
const gapRight = gapCenter + gapWidth / 2;
for (const [start, end] of [[leftEdge, gapLeft], [gapRight, rightEdge]]) {
if (end <= start) continue;
const width = end - start;
box(width, height, 0.28, roofMaterial, (start + end) / 2, baseY + height / 2, z);
box(width + 0.12, 0.15, 0.42, trimMaterial, (start + end) / 2, baseY + height, z);
}
}
retainingWall(6, 0, 1.3);
retainingWall(-2, 1.3, 1.3);
retainingWall(-10, 2.6, 1.3);
// Main ascending lane.
box(1.6, 0.055, 10, pathMaterial, 0.35, 0.025, 10, scene, false, false);
box(1.6, 0.055, 9, pathMaterial, 0.35, 1.325, 1.5, scene, false, false);
box(1.6, 0.055, 9, pathMaterial, 0.35, 2.625, -6.5, scene, false, false);
box(1.6, 0.055, 6, pathMaterial, 0.35, 3.925, -13, scene, false, false);
box(24, 0.045, 1.05, pathMaterial, 0, 1.325, 4.35, scene, false, false);
box(22, 0.045, 0.95, pathMaterial, 0, 2.625, -2.7, scene, false, false);
box(18, 0.045, 0.9, pathMaterial, 0, 3.925, -10.7, scene, false, false);
function stairs(x, lowerZ, upperZ, baseY, topY, width = 1.45, count = 8) {
const depth = (lowerZ - upperZ) / count;
for (let i = 0; i < count; i++) {
const t = (i + 1) / count;
const stepTop = baseY + (topY - baseY) * t;
const stepHeight = stepTop - baseY;
const z = lowerZ - (i + 0.5) * depth;
box(
width,
stepHeight,
depth + 0.035,
i % 2 ? stepMaterial : roofMaterial,
x,
baseY + stepHeight / 2,
z
);
}
}
stairs(0.35, 8.7, 6, 0, 1.3);
stairs(0.35, 0.75, -2, 1.3, 2.6);
stairs(0.35, -7.15, -10, 2.6, 3.9);
// Instanced paving stones.
const paverPositions = [];
const paverColors = [];
const pavingPalette = [0xb5a78d, 0xc5b699, 0xa99a80, 0xd0c1a3];
function addPaverField(zMin, zMax, y, xCenter, width = 1.35) {
for (let z = zMin; z <= zMax; z += 0.43) {
for (let x = xCenter - width / 2; x <= xCenter + width / 2; x += 0.38) {
paverPositions.push({
x: x + (random() - 0.5) * 0.07,
y: y + 0.065,
z: z + (random() - 0.5) * 0.07,
sx: 0.25 + random() * 0.08,
sz: 0.18 + random() * 0.07,
ry: (random() - 0.5) * 0.22
});
paverColors.push(pavingPalette[Math.floor(random() * pavingPalette.length)]);
}
}
}
addPaverField(6.4, 14.5, 0, 0.35);
addPaverField(-1.6, 0.45, 1.3, 0.35);
addPaverField(-9.6, -2.35, 2.6, 0.35);
addPaverField(-15.5, -10.25, 3.9, 0.35);
for (let x = -11.5; x < 11.5; x += 0.48) {
paverPositions.push({
x,
y: 1.37,
z: 4.35 + (random() - 0.5) * 0.07,
sx: 0.3,
sz: 0.22,
ry: (random() - 0.5) * 0.15
});
paverColors.push(pavingPalette[Math.floor(random() * pavingPalette.length)]);
}
const paverMesh = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.96 }),
paverPositions.length
);
const paverDummy = new THREE.Object3D();
paverPositions.forEach((p, i) => {
paverDummy.position.set(p.x, p.y, p.z);
paverDummy.rotation.set(0, p.ry, 0);
paverDummy.scale.set(p.sx, 0.045, p.sz);
paverDummy.updateMatrix();
paverMesh.setMatrixAt(i, paverDummy.matrix);
paverMesh.setColorAt(i, new THREE.Color(p.paverColors ? p.paverColors[i] : p.paverColors));
});
// setColorAt receives one color per instance.
paverPositions.forEach((p, i) => {
paverMesh.setColorAt(i, new THREE.Color(paverColors[i]));
});
paverMesh.receiveShadow = true;
paverMesh.instanceMatrix.needsUpdate = true;
if (paverMesh.instanceColor) paverMesh.instanceColor.needsUpdate = true;
scene.add(paverMesh);
// Courtyard paving.
box(6.8, 0.08, 6.0, matte(0xd5c4a4), 4.0, 0.015, 9.2, scene, false, false);
for (let ix = 0; ix < 8; ix++) {
for (let iz = 0; iz < 7; iz++) {
const color = (ix + iz) % 2 ? 0xd8c8aa : 0xcbbb9e;
box(
0.79,
0.045,
0.79,
matte(color),
1.05 + ix * 0.84,
0.075,
6.65 + iz * 0.84,
scene,
false,
false
);
}
}
// A smaller planted courtyard on the middle terrace.
box(4.2, 0.08, 3.4, matte(0xcabb9e), 3.1, 1.31, 2.65, scene, false, false);
// Window and building helpers.
const shutterMaterials = [
matte(0x376b6d),
matte(0x4d7771),
matte(0x8d5e48),
matte(0x607b80)
];
function addWindow(parent, x, y, z, width, height, shutterMaterial, axis = "z") {
if (axis === "z") {
box(width, height, 0.065, glassMaterial, x, y, z, parent, false, false);
box(width * 0.25, height, 0.09, shutterMaterial, x - width * 0.62, y, z + 0.01, parent);
box(width * 0.25, height, 0.09, shutterMaterial, x + width * 0.62, y, z + 0.01, parent);
box(width + 0.2, 0.1, 0.13, trimMaterial, x, y - height / 2 - 0.06, z, parent);
} else {
box(0.065, height, width, glassMaterial, x, y, z, parent, false, false);
box(0.09, height, width * 0.25, shutterMaterial, x + 0.01, y, z - width * 0.62, parent);
box(0.09, height, width * 0.25, shutterMaterial, x + 0.01, y, z + width * 0.62, parent);
box(0.13, 0.1, width + 0.2, trimMaterial, x, y - height / 2 - 0.06, z, parent);
}
}
function addDoor(parent, z, x = 0, y = 0, width = 1.05, height = 1.75) {
box(width, height, 0.09, darkMaterial, x, y + height / 2, z, parent);
box(0.1, height + 0.12, 0.14, matte(0x755039), x - width / 2, y + height / 2, z + 0.01, parent);
box(0.1, height + 0.12, 0.14, matte(0x755039), x + width / 2, y + height / 2, z + 0.01, parent);
box(width + 0.25, 0.15, 0.35, roofMaterial, x, y + 0.075, z + 0.08, parent);
}
function addPlanter(x, y, z, size = 1) {
const pot = matte(0xb6684d);
const leaf = matte(0x4d7250);
box(0.58 * size, 0.42 * size, 0.58 * size, pot, x, y + 0.21 * size, z, scene, true);
box(0.48 * size, 0.08 * size, 0.48 * size, matte(0x68513a), x, y + 0.45 * size, z, scene);
box(0.42 * size, 0.52 * size, 0.42 * size, leaf, x, y + 0.7 * size, z, scene, true);
box(0.25 * size, 0.34 * size, 0.3 * size, matte(0x6d8557), x + 0.19 * size, y + 0.85 * size, z, scene);
}
function addTree(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
box(0.32 * scale, 1.65 * scale, 0.32 * scale, matte(0x75523a), 0, 0.82 * scale, 0, group, true);
box(1.25 * scale, 0.95 * scale, 1.05 * scale, matte(0x536f4c), 0, 1.9 * scale, 0, group, true);
box(0.85 * scale, 0.8 * scale, 0.8 * scale, matte(0x657e52), -0.45 * scale, 2.25 * scale, 0.1, group, true);
box(0.72 * scale, 0.72 * scale, 0.75 * scale, matte(0x748b57), 0.47 * scale, 2.18 * scale, -0.06, group, true);
box(0.62 * scale, 0.58 * scale, 0.62 * scale, matte(0x8c965c), 0.05 * scale, 2.58 * scale, 0, group, true);
}
function addBuilding(config) {
const group = new THREE.Group();
group.position.set(config.x, config.base, config.z);
scene.add(group);
const levels = config.levels?.length ? config.levels : [config.h];
const upperColor = config.upperColor || config.color;
let currentWidth = config.w;
let currentDepth = config.d;
let cursor = 0;
const groundDepth = config.d;
levels.forEach((height, levelIndex) => {
const wallMaterial = matte(levelIndex === 0 ? config.color : upperColor);
const levelBottom = cursor;
box(
currentWidth,
height,
currentDepth,
wallMaterial,
0,
levelBottom + height / 2,
0,
group,
true
);
const frontCount = Math.max(1, Math.floor(currentWidth / 1.65));
for (let i = 0; i < frontCount; i++) {
const x = -currentWidth / 2 + ((i + 1) * currentWidth) / (frontCount + 1);
if (levelIndex === 0 && Math.abs(x) < 0.72 && config.door !== false) continue;
addWindow(
group,
x,
levelBottom + height * 0.57,
currentDepth / 2 + 0.045,
0.62,
Math.min(0.88, height * 0.43),
shutterMaterials[(config.x * 3 + i + levelIndex) % shutterMaterials.length | 0],
"z"
);
}
const sideCount = Math.max(1, Math.floor(currentDepth / 1.8));
for (let i = 0; i < sideCount; i++) {
const z = -currentDepth / 2 + ((i + 1) * currentDepth) / (sideCount + 1);
if (levelIndex === 0 && Math.abs(z) < 0.65) continue;
addWindow(
group,
currentWidth / 2 + 0.045,
levelBottom + height * 0.57,
z,
0.6,
Math.min(0.85, height * 0.42),
shutterMaterials[(config.z + i + levelIndex) % shutterMaterials.length | 0],
"x"
);
}
if (levelIndex === 0 && config.door !== false) {
addDoor(group, groundDepth / 2 + 0.055);
addPlanter(config.x + 0.95, config.base, config.z + groundDepth / 2 + 0.7, 0.8);
}
if (levelIndex < levels.length - 1) {
box(
currentWidth + 0.16,
0.15,
currentDepth + 0.16,
roofMaterial,
0,
levelBottom + height + 0.065,
0,
group,
true
);
}
cursor += height;
currentWidth *= 0.72;
currentDepth *= 0.72;
});
const roofY = cursor;
box(currentWidth + 0.16, 0.18, currentDepth + 0.16, roofMaterial, 0, roofY + 0.09, 0, group, true);
const parapetHeight = 0.42;
box(currentWidth, parapetHeight, 0.14, trimMaterial, 0, roofY + parapetHeight / 2 + 0.12, currentDepth / 2, group);
box(currentWidth, parapetHeight, 0.14, trimMaterial, 0, roofY + parapetHeight / 2 + 0.12, -currentDepth / 2, group);
box(0.14, parapetHeight, currentDepth, trimMaterial, currentWidth / 2, roofY + parapetHeight / 2 + 0.12, 0, group);
box(0.14, parapetHeight, currentDepth, trimMaterial, -currentWidth / 2, roofY + parapetHeight / 2 + 0.12, 0, group);
const roofNumber = Math.abs(Math.sin((config.x + 17) * (config.z - 8)) * 100);
if (roofNumber > 0.28) {
box(0.68, 0.52, 0.58, matte(0x66716d), currentWidth * 0.22, roofY + 0.45, -currentDepth * 0.15, group, true);
box(0.42, 0.12, 0.4, matte(0x4d5754), currentWidth * 0.22, roofY + 0.77, -currentDepth * 0.15, group);
}
if (roofNumber > 0.55) {
box(0.52, 0.38, 0.52, matte(0x9b6548), -currentWidth * 0.2, roofY + 0.38, currentDepth * 0.1, group, true);
box(0.38, 0.28, 0.4, matte(0x5f7952), -currentWidth * 0.2, roofY + 0.69, currentDepth * 0.1, group);
}
if (config.balcony) {
const balconyY = 2.25;
const balconyZ = groundDepth / 2 + 0.32;
box(2.25, 0.13, 0.68, roofMaterial, 0, balconyY, balconyZ, group, true);
box(2.15, 0.08, 0.08, darkMaterial, 0, balconyY + 0.65, balconyZ + 0.29, group);
for (const x of [-1.02, -0.34, 0.34, 1.02]) {
box(0.065, 0.67, 0.065, darkMaterial, x, balconyY + 0.34, balconyZ + 0.29, group);
}
for (const x of [-0.85, 0.55]) {
addWindow(group, x, balconyY + 0.43, groundDepth / 2 + 0.055, 0.6, 0.78, shutterMaterials[1], "z");
}
}
return group;
}
const buildingConfigs = [
// Lower terrace.
{ x: -9.2, z: 10, w: 6.1, d: 6, h: 4.4, base: 0, color: 0xe4d5b7, levels: [4.4, 2.0], balcony: true },
{ x: -3.7, z: 11.3, w: 4, d: 5, h: 3.6, base: 0, color: 0xcd8c72, levels: [3.6, 1.5] },
{ x: 10.2, z: 10.4, w: 5.7, d: 6.2, h: 4.8, base: 0, color: 0xeee5cf, levels: [4.8, 2.1] },
// Middle terrace.
{ x: -9, z: 1.3, w: 6.2, d: 6, h: 5.4, base: 1.3, color: 0xd9bd91, levels: [5.4, 2.0] },
{ x: -3.8, z: 0.7, w: 4.2, d: 5, h: 4.6, base: 1.3, color: 0xeee3ca, levels: [4.6, 1.7] },
{ x: 8, z: 0.8, w: 5.2, d: 6, h: 5.8, base: 1.3, color: 0xd3a382, levels: [5.8, 2.4, 1.3], balcony: true },
// Upper terrace.
{ x: -8.6, z: -6.7, w: 6.1, d: 6, h: 6.2, base: 2.6, color: 0xefe6d1, levels: [6.2, 2.1] },
{ x: -3.4, z: -6.8, w: 4.2, d: 5.4, h: 5.5, base: 2.6, color: 0xd9b27f, levels: [5.5, 1.9] },
{ x: 3.7, z: -6.5, w: 4.7, d: 6, h: 6.8, base: 2.6, color: 0xe8d9b8, levels: [6.8, 2.3, 1.2] },
{ x: 8.2, z: -7.4, w: 4.2, d: 5, h: 5.2, base: 2.6, color: 0xc7836c, levels: [5.2, 1.8] },
// Summit edge.
{ x: 6.2, z: -13, w: 4.4, d: 4.8, h: 5.8, base: 3.9, color: 0xe8dfca, levels: [5.8, 2.0] }
];
buildingConfigs.forEach(addBuilding);
// Mosque and stepped minaret.
function voxelArch(parent, centerX, baseY, z, width, height) {
box(width, height - 0.46, 0.08, darkMaterial, centerX, baseY + (height - 0.46) / 2, z, parent);
box(width * 0.72, 0.28, 0.08, darkMaterial, centerX, baseY + height - 0.37, z, parent);
box(width * 0.42, 0.18, 0.08, darkMaterial, centerX, baseY + height - 0.14, z, parent);
}
const mosque = new THREE.Group();
mosque.position.set(-2.7, 3.9, -13);
scene.add(mosque);
box(8.4, 4.8, 4.5, matte(0xf0ead8), 0, 2.4, 0, mosque, true);
box(8.6, 0.2, 4.7, roofMaterial, 0, 4.88, 0, mosque, true);
box(8.4, 0.5, 0.15, trimMaterial, 0, 5.15, 2.25, mosque);
box(8.4, 0.5, 0.15, trimMaterial, 0, 5.15, -2.25, mosque);
box(0.15, 0.5, 4.5, trimMaterial, 4.2, 5.15, 0, mosque);
box(0.15, 0.5, 4.5, trimMaterial, -4.2, 5.15, 0, mosque);
voxelArch(mosque, 0, 0, 2.31, 1.6, 2.6);
for (const x of [-2.8, -1.5, 1.5, 2.8]) {
voxelArch(mosque, x, 1.1, 2.31, 0.78, 1.9);
}
const minaret = new THREE.Group();
minaret.position.set(4.15, 0, 1.78);
mosque.add(minaret);
box(1.9, 8.2, 1.9, matte(0xeee7d4), 0, 4.1, 0, minaret, true);
box(2.35, 0.2, 2.35, trimMaterial, 0, 6.1, 0, minaret, true);
box(2.15, 0.18, 2.15, matte(0x3d7770), 0, 6.28, 0, minaret, true);
box(1.55, 2.5, 1.55, matte(0xf0e8d5), 0, 7.58, 0, minaret, true);
box(1.8, 0.18, 1.8, matte(0x39756d), 0, 8.9, 0, minaret, true);
box(0.85, 0.75, 0.85, matte(0xe9dfc9), 0, 9.35, 0, minaret, true);
box(0.18, 1.1, 0.18, darkMaterial, 0, 10.25, 0, minaret);
for (const y of [2.2, 4.1]) {
box(0.07, 0.72, 0.35, glassMaterial, 0.965, y, 0, minaret);
}
// Courtyard fountain.
box(1.85, 0.34, 1.85, matte(0xd4c5a8), 4.25, 0.25, 9.3, scene, true);
box(1.4, 0.22, 1.4, matte(0xeee2c8), 4.25, 0.53, 9.3, scene, true);
box(1.08, 0.055, 1.08, new THREE.MeshStandardMaterial({
color: 0x4c9ca3,
roughness: 0.24,
metalness: 0.12
}), 4.25, 0.67, 9.3, scene, false, false);
box(0.28, 1.0, 0.28, matte(0xe8dcc3), 4.25, 1.05, 9.3, scene, true);
box(0.62, 0.12, 0.18, matte(0xe8dcc3), 4.25, 1.48, 9.3, scene);
addTree(6.55, 0.08, 11.2, 1.05);
addTree(4.35, 1.36, 3.4, 0.78);
addPlanter(6.25, 1.36, 2.0, 0.9);
addPlanter(1.5, 1.36, 3.7, 0.85);
addPlanter(6.7, 0.08, 6.75, 1.0);
addPlanter(-0.85, 0.08, 13.5, 0.9);
// Laundry lines between façades.
const laundryCloths = [];
const clothMaterials = [
matte(0xeee7d8),
matte(0x668e91),
matte(0xd77862),
matte(0xe5bf65)
];
function addLaundry(a, b, count) {
beamBetween(a, b, 0.025, darkMaterial);
for (let i = 0; i < count; i++) {
const t = (i + 1) / (count + 1);
const point = new THREE.Vector3().lerpVectors(a, b, t);
const cloth = box(
0.34 + random() * 0.12,
0.48 + random() * 0.18,
0.035,
clothMaterials[i % clothMaterials.length],
point.x,
point.y - 0.29,
point.z,
scene,
false,
false
);
laundryCloths.push({ mesh: cloth, phase: random() * Math.PI * 2 });
}
}
addLaundry(new THREE.Vector3(-1.75, 3.25, 12.35), new THREE.Vector3(7.35, 4.0, 12.3), 7);
addLaundry(new THREE.Vector3(-1.72, 4.85, 2.45), new THREE.Vector3(5.38, 5.25, 2.4), 5);
// Simple street lamps.
const lampGlow = new THREE.MeshStandardMaterial({
color: 0xffe2a1,
emissive: 0xe7a34f,
emissiveIntensity: 0.35,
roughness: 0.65
});
function addLamp(x, y, z) {
box(0.08, 2.25, 0.08, darkMaterial, x, y + 1.125, z, scene, true);
box(0.34, 0.34, 0.34, lampGlow, x, y + 2.25, z, scene, true);
box(0.46, 0.09, 0.46, darkMaterial, x, y + 2.47, z, scene);
}
addLamp(1.25, 0, 8.15);
addLamp(1.25, 1.3, 0.15);
addLamp(1.25, 2.6, -8.2);
addLamp(7.15, 0, 6.7);
// Rooftop railings and water tanks.
box(1.05, 0.55, 0.85, matte(0x69736f), 0.2, 8.0, 0, scene, true);
box(0.8, 0.12, 0.67, matte(0x525d59), 0.2, 8.33, 0, scene);
// Animated water glints.
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0xd1e7df,
transparent: true,
opacity: 0.42,
depthWrite: false
});
const waveCount = 74;
const waveMesh = new THREE.InstancedMesh(unitBox, waveMaterial, waveCount);
const waves = [];
for (let i = 0; i < waveCount; i++) {
const angle = random() * Math.PI * 2;
const radius = 22 + random() * 52;
waves.push({
x: Math.cos(angle) * radius,
z: Math.sin(angle) * radius,
length: 0.7 + random() * 2.4,
phase: random() * Math.PI * 2
});
}
waveMesh.frustumCulled = false;
scene.add(waveMesh);
// Block-like clouds.
const clouds = [];
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf6f3e8,
roughness: 1,
transparent: true,
opacity: 0.83,
depthWrite: false
});
for (let i = 0; i < 7; i++) {
const cloud = new THREE.Group();
cloud.position.set(-38 + i * 13 + random() * 5, 15 + random() * 7, -38 - random() * 20);
scene.add(cloud);
const chunks = 3 + Math.floor(random() * 4);
for (let j = 0; j < chunks; j++) {
box(
3 + random() * 4,
0.7 + random() * 0.8,
1.5 + random() * 2.5,
cloudMaterial,
j * 2.3,
random() * 0.7,
random() * 1.2,
cloud,
false,
false
);
}
clouds.push({ group: cloud, speed: 0.08 + random() * 0.08 });
}
// Custom camera controls, implemented without external controls modules.
const target = new THREE.Vector3(0, 2.9, 0);
const home = {
theta: 0.72,
phi: 0.96,
radius: 41
};
let theta = home.theta;
let phi = home.phi;
let radius = home.radius;
let currentTheta = theta;
let currentPhi = phi;
let currentRadius = radius;
const pointers = new Map();
let lastPinchDistance = 0;
function clampCamera() {
phi = THREE.MathUtils.clamp(phi, 0.42, 1.38);
radius = THREE.MathUtils.clamp(radius, 24, 62);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
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) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
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) {
theta -= dx * 0.005;
phi += dy * 0.004;
clampCamera();
} else 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 && distance > 0) {
radius *= lastPinchDistance / distance;
clampCamera();
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("pointerleave", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius += event.deltaY * 0.025;
clampCamera();
},
{ passive: false }
);
function resetView() {
theta = home.theta;
phi = home.phi;
radius = home.radius;
}
document.getElementById("reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("zoomIn").addEventListener("click", () => {
radius -= 3;
clampCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
radius += 3;
clampCamera();
});
addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") theta += 0.12;
if (event.key === "ArrowRight") theta -= 0.12;
if (event.key === "ArrowUp") phi -= 0.08;
if (event.key === "ArrowDown") phi += 0.08;
if (event.key === "+" || event.key === "=") radius -= 2;
if (event.key === "-" || event.key === "_") radius += 2;
if (event.key.toLowerCase() === "r") resetView();
clampCamera();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
const spherical = new THREE.Spherical();
const waveDummy = new THREE.Object3D();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 8);
currentTheta = THREE.MathUtils.lerp(currentTheta, theta, smoothing);
currentPhi = THREE.MathUtils.lerp(currentPhi, phi, smoothing);
currentRadius = THREE.MathUtils.lerp(currentRadius, radius, smoothing);
spherical.set(currentRadius, currentPhi, currentTheta);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
waves.forEach((wave, i) => {
waveDummy.position.set(
wave.x + Math.sin(elapsed * 0.22 + wave.phase) * 0.35,
-3.13,
wave.z
);
waveDummy.rotation.set(0, 0, 0);
waveDummy.scale.set(wave.length, 0.015, 0.055 + (i % 3) * 0.012);
waveDummy.updateMatrix();
waveMesh.setMatrixAt(i, waveDummy.matrix);
});
waveMesh.instanceMatrix.needsUpdate = true;
laundryCloths.forEach(({ mesh, phase }) => {
mesh.rotation.z = Math.sin(elapsed * 1.15 + phase) * 0.055;
});
clouds.forEach(({ group, speed }) => {
group.position.x += speed * delta;
if (group.position.x > 48) group.position.x = -48;
});
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loader.classList.add("hidden");
});
</script>
</body>
</html>
```