Prompt specification
Build or customize the Three.js 3D scene "Family walking between an Isfahan arcade and garden path" 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: Family walking between an Isfahan arcade and garden path
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/family-walking-between-an-isfahan-arcade-and-garden-pa-x2918
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Naqsh-e Jahan Square in Isfahan. Create a compact referenced square vignette with varied visitors, planted area, and arcade entrance. Keep activities ordinary and represent the setting respectfully. Low-poly.
Working Three.js Starter (family-walking-between-an-isfahan-arcade-and-garden-pa-x2918):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Naqsh-e Jahan Square — Low-Poly Vignette</title>
<style>
:root {
color-scheme: light;
--ink: #263b39;
--muted: #62736f;
--paper: rgba(250, 247, 238, 0.9);
--line: rgba(54, 82, 75, 0.17);
--accent: #267c78;
--gold: #bd8d3c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe3dd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 45px rgba(47, 61, 52, 0.13);
backdrop-filter: blur(13px);
-webkit-backdrop-filter: blur(13px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 4vw, 38px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1.02;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.landmark-list {
display: none;
grid-template-columns: 1fr 1fr;
gap: 7px 14px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.landmark-list.visible {
display: grid;
}
.landmark-list span {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-weight: 750;
}
.toolbar {
position: fixed;
top: 22px;
right: 22px;
display: flex;
gap: 8px;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(47, 61, 52, 0.1);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf7;
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.hint {
position: fixed;
left: 22px;
bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(250, 247, 238, 0.82);
color: var(--muted);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
font-size: 10px;
pointer-events: none;
}
.mouse {
width: 17px;
height: 24px;
border: 1.5px solid var(--accent);
border-radius: 9px;
position: relative;
}
.mouse::after {
content: "";
position: absolute;
top: 4px;
left: 6px;
width: 3px;
height: 6px;
border-radius: 2px;
background: var(--accent);
}
#loader {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #e8e4d9;
color: #416a62;
font: 700 11px/1.5 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loader.ready {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.toolbar {
top: auto;
right: 12px;
bottom: 54px;
}
button {
padding: 0 10px;
}
.hint {
left: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive low-poly vignette of Naqsh-e Jahan Square"></main>
<section class="title-card">
<div class="eyebrow">Isfahan · Iran</div>
<h1>Naqsh-e Jahan</h1>
<p class="subtitle">
A compact, respectful interpretation of the historic square: formal gardens,
shaded arcades and ordinary moments of daily life.
</p>
<div class="landmark-list" id="landmarkList">
<div><span>East</span>Shah Mosque portal</div>
<div><span>West</span>Sheikh Lotfollah Mosque</div>
<div><span>North</span>Ali Qapu</div>
<div><span>South</span>Bazaar arcade entrance</div>
</div>
</section>
<nav class="toolbar" aria-label="Scene controls">
<button id="infoButton" type="button">Landmarks</button>
<button id="lifeButton" type="button">Pause life</button>
<button id="moodButton" type="button">Golden hour</button>
<button id="resetButton" type="button">Reset view</button>
</nav>
<div class="hint">
<span class="mouse" aria-hidden="true"></span>
<span>Drag to orbit · Scroll to zoom · Arrow keys to pan</span>
</div>
<div id="loader">Composing the square…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loader = document.getElementById("loader");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5df);
scene.fog = new THREE.Fog(0xdce5df, 58, 112);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.08;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly model of Naqsh-e Jahan Square with gardens, visitors and arcades"
);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
160
);
const hemi = new THREE.HemisphereLight(0xeaf5f1, 0x9c7650, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe4b4, 3.25);
sun.position.set(-25, 38, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -38;
sun.shadow.camera.right = 38;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 2;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xb9d8e0, 0.65);
fillLight.position.set(28, 14, -22);
scene.add(fillLight);
function mulberry32(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(7421);
const pick = (list) => list[Math.floor(random() * list.length)];
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0,
flatShading: true,
...options
});
}
const mat = {
base: material(0xa77c55),
baseEdge: material(0x815b43),
paving: material(0xd8c7a4),
pavingLight: material(0xe2d2b0),
path: material(0xeadbbc),
sandstone: material(0xd8b980),
sandstoneLight: material(0xe9d19d),
sandstoneDark: material(0xa97c50),
recess: material(0x2d2924),
turquoise: material(0x287f7d),
turquoiseLight: material(0x60aaa0),
turquoiseDark: material(0x175b61),
gold: material(0xbe913f, { roughness: 0.55 }),
cream: material(0xf0dfb8),
grass: material(0x738c55),
grassDark: material(0x536f43),
leaf: material(0x789657),
leafLight: material(0x91a868),
leafDark: material(0x526f48),
trunk: material(0x76513b),
soil: material(0x786348),
water: material(0x4b9e9a, {
roughness: 0.2,
metalness: 0.12,
transparent: true,
opacity: 0.91
}),
poolEdge: material(0xc5a977),
wood: material(0x76503a),
metal: material(0x3d4d49, { roughness: 0.5, metalness: 0.35 }),
lamp: material(0xffe6a8, {
emissive: 0xffbd5c,
emissiveIntensity: 1.4
}),
distant: material(0xbda98c),
distantRoof: material(0x8c8873)
};
function makeTileTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#277d7b";
ctx.fillRect(0, 0, 256, 256);
ctx.strokeStyle = "#e3bd62";
ctx.lineWidth = 7;
for (let y = -64; y < 320; y += 64) {
for (let x = -64; x < 320; x += 64) {
ctx.beginPath();
ctx.moveTo(x, y - 19);
ctx.lineTo(x + 19, y);
ctx.lineTo(x, y + 19);
ctx.lineTo(x - 19, y);
ctx.closePath();
ctx.stroke();
ctx.fillStyle = "#e8d39a";
ctx.beginPath();
ctx.arc(x, y, 4, 0, Math.PI * 2);
ctx.fill();
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2.2, 2.2);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const tileMaterial = new THREE.MeshStandardMaterial({
map: makeTileTexture(),
roughness: 0.67,
metalness: 0.04
});
function box(parent, width, height, depth, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
mat,
x = 0,
y = 0,
z = 0
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function pointedArchShape(cx, width, spring, apex) {
const shape = new THREE.Shape();
shape.moveTo(cx - width / 2, 0);
shape.lineTo(cx + width / 2, 0);
shape.lineTo(cx + width / 2, spring);
shape.bezierCurveTo(
cx + width / 2,
spring + (apex - spring) * 0.73,
cx + width * 0.17,
apex,
cx,
apex
);
shape.bezierCurveTo(
cx - width * 0.17,
apex,
cx - width / 2,
spring + (apex - spring) * 0.73,
cx - width / 2,
spring
);
shape.lineTo(cx - width / 2, 0);
shape.closePath();
return shape;
}
function buildFacade({ length, height, openings }) {
const group = new THREE.Group();
const wallShape = new THREE.Shape();
wallShape.moveTo(-length / 2, 0);
wallShape.lineTo(length / 2, 0);
wallShape.lineTo(length / 2, height);
wallShape.lineTo(-length / 2, height);
wallShape.closePath();
for (const opening of openings) {
const hole = new THREE.Path();
hole.moveTo(opening.x - opening.width / 2, 0);
hole.lineTo(opening.x + opening.width / 2, 0);
hole.lineTo(opening.x + opening.width / 2, opening.spring);
hole.bezierCurveTo(
opening.x + opening.width / 2,
opening.spring + (opening.apex - opening.spring) * 0.73,
opening.x + opening.width * 0.17,
opening.apex,
opening.x,
opening.apex
);
hole.bezierCurveTo(
opening.x - opening.width * 0.17,
opening.apex,
opening.x - opening.width / 2,
opening.spring + (opening.apex - opening.spring) * 0.73,
opening.x - opening.width / 2,
opening.spring
);
hole.lineTo(opening.x - opening.width / 2, 0);
hole.closePath();
wallShape.holes.push(hole);
}
const wallGeometry = new THREE.ExtrudeGeometry(wallShape, {
depth: 0.7,
bevelEnabled: false,
curveSegments: 8
});
const wall = new THREE.Mesh(wallGeometry, mat.sandstone);
wall.position.z = -0.35;
wall.castShadow = true;
wall.receiveShadow = true;
group.add(wall);
box(
group,
length,
height * 0.93,
6,
mat.sandstoneDark,
0,
height * 0.465,
-3.65
);
box(group, length + 0.6, 0.38, 1.35, mat.sandstoneLight, 0, height + 0.08, -0.15);
box(group, length + 0.2, 0.24, 0.9, mat.sandstoneDark, 0, height - 0.35, 0.1);
for (const opening of openings) {
const fillShape = pointedArchShape(
opening.x,
opening.width,
opening.spring,
opening.apex
);
const fill = new THREE.Mesh(
new THREE.ShapeGeometry(fillShape, 8),
opening.material || mat.recess
);
fill.position.z = -0.18;
fill.receiveShadow = true;
group.add(fill);
}
return group;
}
function archCurve(cx, width, spring, apex) {
const points = [
new THREE.Vector3(cx - width / 2, 0, 0),
new THREE.Vector3(cx - width / 2, spring, 0),
new THREE.Vector3(
cx - width * 0.42,
spring + (apex - spring) * 0.73,
0
),
new THREE.Vector3(cx - width * 0.17, apex, 0),
new THREE.Vector3(cx, apex, 0),
new THREE.Vector3(cx + width * 0.17, apex, 0),
new THREE.Vector3(
cx + width * 0.42,
spring + (apex - spring) * 0.73,
0
),
new THREE.Vector3(cx + width / 2, spring, 0),
new THREE.Vector3(cx + width / 2, 0, 0)
];
return new THREE.CatmullRomCurve3(points, false, "centripetal", 0.18);
}
function addArchTrim(group, cx, width, spring, apex, z = 0.44) {
const inner = new THREE.Mesh(
new THREE.TubeGeometry(archCurve(cx, width, spring, apex), 34, 0.15, 4, false),
mat.gold
);
inner.position.z = z;
inner.castShadow = true;
group.add(inner);
const outer = new THREE.Mesh(
new THREE.TubeGeometry(
archCurve(cx, width + 0.85, spring, apex + 0.6),
34,
0.13,
4,
false
),
mat.turquoiseLight
);
outer.position.z = z - 0.02;
outer.castShadow = true;
group.add(outer);
box(
group,
0.24,
spring + 0.25,
0.24,
mat.gold,
cx - width / 2 - 0.43,
(spring + 0.25) / 2,
z
);
box(
group,
0.24,
spring + 0.25,
0.24,
mat.gold,
cx + width / 2 + 0.43,
(spring + 0.25) / 2,
z
);
}
function addDome(group, x, y, z, radius, domeMat = mat.turquoise) {
cylinder(group, radius * 0.79, radius * 0.82, 0.72, 16, mat.sandstoneLight, x, y + 0.36, z);
const dome = new THREE.Mesh(
new THREE.SphereGeometry(
radius,
16,
8,
0,
Math.PI * 2,
0,
Math.PI / 2
),
domeMat
);
dome.position.set(x, y + 0.72, z);
dome.scale.y = 0.73;
dome.castShadow = true;
dome.receiveShadow = true;
group.add(dome);
cylinder(group, 0.07, 0.1, 1.15, 6, mat.gold, x, y + radius * 0.73 + 0.75, z);
const finial = new THREE.Mesh(
new THREE.OctahedronGeometry(0.16, 0),
mat.gold
);
finial.position.set(x, y + radius * 0.73 + 1.35, z);
finial.castShadow = true;
group.add(finial);
}
function addMinaret(group, x, z, height = 14) {
cylinder(group, 0.43, 0.58, height, 10, mat.turquoise, x, height / 2, z);
cylinder(group, 0.72, 0.72, 0.28, 10, mat.sandstoneLight, x, height * 0.67, z);
cylinder(group, 0.72, 0.72, 0.2, 10, mat.gold, x, height * 0.71, z);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.66, 1.3, 10),
mat.turquoiseDark
);
cap.position.set(x, height + 0.55, z);
cap.castShadow = true;
group.add(cap);
}
// -------------------------------------------------------------------------
// The diorama base and paved square
// -------------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
material(0xc7c4ae)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.06;
ground.receiveShadow = true;
world.add(ground);
box(world, 42, 1, 32, mat.base, 0, -0.55, 0);
box(world, 41.2, 0.13, 31.2, mat.baseEdge, 0, -0.1, 0);
box(world, 38.4, 0.2, 28.4, mat.paving, 0, 0, 0);
// Fine paving joints.
const pavingPoints = [];
for (let x = -18; x <= 18; x += 2) {
pavingPoints.push(new THREE.Vector3(x, 0.108, -13.8), new THREE.Vector3(x, 0.108, 13.8));
}
for (let z = -12; z <= 12; z += 2) {
pavingPoints.push(new THREE.Vector3(-18.8, 0.108, z), new THREE.Vector3(18.8, 0.108, z));
}
const pavingGeometry = new THREE.BufferGeometry().setFromPoints(pavingPoints);
const pavingLines = new THREE.LineSegments(
pavingGeometry,
new THREE.LineBasicMaterial({
color: 0x9f896b,
transparent: true,
opacity: 0.2
})
);
world.add(pavingLines);
// Central pedestrian paths.
box(world, 34.5, 0.035, 3.4, mat.path, 0, 0.125, 0);
box(world, 3.4, 0.035, 23.8, mat.path, 0, 0.126, 0);
// -------------------------------------------------------------------------
// Formal planted areas and water basins
// -------------------------------------------------------------------------
function makeTree(x, z, type = "broad", scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0.18, z);
tree.scale.setScalar(scale);
if (type === "cypress") {
cylinder(tree, 0.1, 0.14, 1.35, 7, mat.trunk, 0, 0.67, 0);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.67, 2.65, 7),
pick([mat.leafDark, mat.leaf, mat.leafLight])
);
crown.position.y = 2.0;
crown.castShadow = true;
tree.add(crown);
} else {
cylinder(tree, 0.15, 0.23, 1.6, 7, mat.trunk, 0, 0.8, 0);
const crownGeometry = new THREE.IcosahedronGeometry(1, 0);
const crown1 = new THREE.Mesh(crownGeometry, mat.leaf);
crown1.position.set(0, 2.25, 0);
crown1.scale.set(1.15, 1.05, 1.05);
crown1.castShadow = true;
tree.add(crown1);
const crown2 = new THREE.Mesh(crownGeometry, mat.leafLight);
crown2.position.set(0.62, 2.05, 0.12);
crown2.scale.setScalar(0.75);
crown2.castShadow = true;
tree.add(crown2);
const crown3 = new THREE.Mesh(crownGeometry, mat.leafDark);
crown3.position.set(-0.55, 2.0, -0.1);
crown3.scale.setScalar(0.72);
crown3.castShadow = true;
tree.add(crown3);
}
world.add(tree);
}
function makeGarden(cx, cz) {
box(world, 11.4, 0.11, 6.25, mat.soil, cx, 0.165, cz);
box(world, 11.0, 0.08, 5.85, mat.grass, cx, 0.235, cz);
box(world, 10.8, 0.28, 0.22, mat.grassDark, cx, 0.34, cz - 2.8);
box(world, 10.8, 0.28, 0.22, mat.grassDark, cx, 0.34, cz + 2.8);
box(world, 0.22, 0.28, 5.35, mat.grassDark, cx - 5.3, 0.34, cz);
box(world, 0.22, 0.28, 5.35, mat.grassDark, cx + 5.3, 0.34, cz);
for (const dx of [-4.7, 4.7]) {
for (const dz of [-2.15, 2.15]) {
makeTree(
cx + dx + (random() - 0.5) * 0.35,
cz + dz + (random() - 0.5) * 0.35,
random() > 0.7 ? "cypress" : "broad",
0.72 + random() * 0.15
);
}
}
// Low flower clusters.
const flowerColors = [0xe4c06a, 0xd88c7c, 0xb9a1c5, 0xf0e2b1];
for (let i = 0; i < 14; i++) {
const flower = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.08, 0),
material(pick(flowerColors))
);
flower.position.set(
cx + (random() - 0.5) * 9.6,
0.38,
cz + (random() - 0.5) * 4.8
);
flower.castShadow = true;
world.add(flower);
}
}
makeGarden(-9, -6.25);
makeGarden(9, -6.25);
makeGarden(-9, 6.25);
makeGarden(9, 6.25);
function makePool(x) {
box(world, 7.35, 0.17, 2.55, mat.poolEdge, x, 0.2, 0);
box(world, 6.85, 0.045, 2.05, mat.water, x, 0.307, 0);
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xb5ddd3,
transparent: true,
opacity: 0.34
});
for (let i = 0; i < 3; i++) {
const ripple = new THREE.Mesh(
new THREE.RingGeometry(0.4 + i * 0.28, 0.43 + i * 0.28, 32),
rippleMaterial
);
ripple.rotation.x = -Math.PI / 2;
ripple.position.set(x - 1.7 + i * 1.55, 0.334, 0);
world.add(ripple);
}
}
makePool(-5.25);
makePool(5.25);
// -------------------------------------------------------------------------
// Landmark architecture
// -------------------------------------------------------------------------
// East: Shah Mosque monumental portal.
const shah = buildFacade({
length: 30,
height: 12.8,
openings: [
{
x: 0,
width: 7.6,
spring: 4.2,
apex: 10.7,
material: tileMaterial
},
{ x: -10.2, width: 2.55, spring: 2.4, apex: 5.2 },
{ x: -13.2, width: 2.25, spring: 2.3, apex: 4.9 },
{ x: 10.2, width: 2.55, spring: 2.4, apex: 5.2 },
{ x: 13.2, width: 2.25, spring: 2.3, apex: 4.9 }
]
});
shah.position.set(18.05, 0.1, 0);
shah.rotation.y = -Math.PI / 2;
world.add(shah);
addArchTrim(shah, 0, 7.6, 4.2, 10.7);
addMinaret(shah, -6.75, -1.25, 15.2);
addMinaret(shah, 6.75, -1.25, 15.2);
addDome(shah, 0, 12.9, -8.4, 3.45, mat.turquoise);
addDome(shah, 0, 13.25, -8.4, 2.95, mat.turquoiseLight);
// Decorative geometric plaques around the portal.
for (const x of [-5.0, 5.0]) {
for (const y of [7.0, 9.1]) {
const plaque = new THREE.Mesh(
new THREE.OctahedronGeometry(0.42, 0),
mat.gold
);
plaque.position.set(x, y, 0.5);
plaque.scale.set(0.72, 1.2, 0.3);
plaque.castShadow = true;
shah.add(plaque);
}
}
// North: Ali Qapu-inspired pavilion.
const aliQapu = buildFacade({
length: 31,
height: 7.4,
openings: [
{ x: 0, width: 5.4, spring: 3.25, apex: 6.7, material: mat.recess },
{ x: -8.0, width: 2.45, spring: 2.35, apex: 5.1 },
{ x: -12.7, width: 2.45, spring: 2.35, apex: 5.1 },
{ x: 8.0, width: 2.45, spring: 2.35, apex: 5.1 },
{ x: 12.7, width: 2.45, spring: 2.35, apex: 5.1 }
]
});
aliQapu.position.set(0, 0.1, -13.25);
world.add(aliQapu);
addArchTrim(aliQapu, 0, 5.4, 3.25, 6.7);
box(aliQapu, 9.2, 4.0, 6.1, mat.sandstoneLight, 0, 9.35, -3.6);
box(aliQapu, 10.1, 0.32, 7.1, mat.sandstone, 0, 11.48, -3.4);
box(aliQapu, 9.7, 0.22, 6.7, mat.gold, 0, 11.76, -3.4);
for (let i = -4; i <= 4; i++) {
cylinder(aliQapu, 0.12, 0.14, 1.65, 8, mat.sandstoneDark, i, 12.5, -0.6);
}
box(aliQapu, 9.5, 0.3, 1.9, mat.sandstone, 0, 13.45, -0.5);
addDome(aliQapu, 0, 13.55, -3.4, 1.45, mat.turquoise);
// West: Sheikh Lotfollah-inspired mosque and dome.
const sheikh = buildFacade({
length: 29,
height: 8.3,
openings: [
{ x: 0, width: 5.25, spring: 3.15, apex: 7.15, material: mat.recess },
{ x: -9.0, width: 2.45, spring: 2.35, apex: 5.1 },
{ x: -13.0, width: 2.45, spring: 2.35, apex: 5.1 },
{ x: 9.0, width: 2.45, spring: 2.35, apex: 5.1 },
{ x: 13.0, width: 2.45, spring: 2.35, apex: 5.1 }
]
});
sheikh.position.set(-18.05, 0.1, 0);
sheikh.rotation.y = Math.PI / 2;
world.add(sheikh);
addArchTrim(sheikh, 0, 5.25, 3.15, 7.15);
addDome(sheikh, 0, 8.45, -6.3, 3.1, mat.cream);
addDome(sheikh, 0, 8.75, -6.3, 2.72, mat.turquoiseLight);
// South: a low bazaar arcade entrance.
const bazaar = buildFacade({
length: 29,
height: 5.7,
openings: [
{ x: -11, width: 3.25, spring: 2.45, apex: 4.85 },
{ x: -5.5, width: 3.25, spring: 2.45, apex: 4.85 },
{ x: 0, width: 3.5, spring: 2.55, apex: 5.0 },
{ x: 5.5, width: 3.25, spring: 2.45, apex: 4.85 },
{ x: 11, width: 3.25, spring: 2.45, apex: 4.85 }
]
});
bazaar.position.set(0, 0.1, 13.25);
bazaar.rotation.y = Math.PI;
world.add(bazaar);
// Warm shop recesses and simple fabric awnings behind the south arcade.
for (const x of [-11, -5.5, 0, 5.5, 11]) {
box(bazaar, 3.0, 0.08, 1.25, x === 0 ? mat.turquoise : mat.gold, x, 4.45, -0.42);
box(bazaar, 2.7, 0.45, 0.08, mat.lamp, x, 3.95, -0.25);
}
// -------------------------------------------------------------------------
// Distant low-poly city forms
// -------------------------------------------------------------------------
const distantGroup = new THREE.Group();
world.add(distantGroup);
for (let i = 0; i < 18; i++) {
const width = 3 + random() * 4.5;
const height = 2.3 + random() * 4.1;
const depth = 3 + random() * 4.5;
const x = -33 + i * 3.9 + (random() - 0.5) * 1.4;
const z = -26 - random() * 9;
box(distantGroup, width, height, depth, mat.distant, x, height / 2 - 1, z);
box(distantGroup, width + 0.3, 0.24, depth + 0.3, mat.distantRoof, x, height - 0.85, z);
if (random() > 0.58) {
const dome = new THREE.Mesh(
new THREE.SphereGeometry(
width * 0.31,
10,
5,
0,
Math.PI * 2,
0,
Math.PI / 2
),
mat.distantRoof
);
dome.position.set(x, height - 0.75, z);
dome.scale.y = 0.72;
dome.castShadow = true;
distantGroup.add(dome);
}
}
// -------------------------------------------------------------------------
// Benches, lamps and small street furniture
// -------------------------------------------------------------------------
function makeBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0.11, z);
bench.rotation.y = rotation;
for (let i = 0; i < 4; i++) {
box(bench, 2.05, 0.09, 0.13, mat.wood, 0, 0.54, -0.24 + i * 0.16);
}
for (let i = 0; i < 3; i++) {
box(bench, 2.05, 0.09, 0.13, mat.wood, 0, 0.75 + i * 0.15, 0.33);
}
box(bench, 0.11, 0.63, 0.11, mat.metal, -0.77, 0.29, 0);
box(bench, 0.11, 0.63, 0.11, mat.metal, 0.77, 0.29, 0);
box(bench, 0.11, 0.68, 0.11, mat.metal, -0.77, 0.87, 0.29);
box(bench, 0.11, 0.68, 0.11, mat.metal, 0.77, 0.87, 0.29);
world.add(bench);
return bench;
}
makeBench(-1.7, -9.2, Math.PI / 2);
makeBench(1.7, 9.2, -Math.PI / 2);
makeBench(-14.5, 1.4, Math.PI / 2);
makeBench(14.5, -1.4, -Math.PI / 2);
makeBench(-4.1, 10.0, 0);
makeBench(4.1, -10.0, 0);
function makeLamp(x, z) {
const lamp = new THREE.Group();
lamp.position.set(x, 0.12, z);
cylinder(lamp, 0.075, 0.12, 3.05, 8, mat.metal, 0, 1.52, 0);
cylinder(lamp, 0.24, 0.24, 0.12, 8, mat.gold, 0, 3.08, 0);
box(lamp, 0.42, 0.55, 0.42, mat.lamp, 0, 3.38, 0);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.39, 0.36, 4),
mat.metal
);
cap.position.y = 3.83;
cap.rotation.y = Math.PI / 4;
cap.castShadow = true;
lamp.add(cap);
world.add(lamp);
}
for (const [x, z] of [
[-3.4, -10.8], [3.4, -10.8], [-3.4, 10.8], [3.4, 10.8],
[-16.2, -2.5], [-16.2, 2.5], [16.2, -2.5], [16.2, 2.5],
[0, -2.6], [0, 2.6]
]) {
makeLamp(x, z);
}
// Small drinking fountain / basin.
cylinder(world, 1.2, 1.35, 0.34, 12, mat.sandstoneLight, 0, 0.27, 0);
cylinder(world, 0.98, 0.98, 0.08, 12, mat.water, 0, 0.48, 0);
cylinder(world, 0.12, 0.17, 0.65, 8, mat.gold, 0, 0.77, 0);
// -------------------------------------------------------------------------
// Visitors: shared low-poly parts and varied poses
// -------------------------------------------------------------------------
const bodyGeometry = new THREE.CylinderGeometry(0.21, 0.31, 0.73, 6);
const headGeometry = new THREE.SphereGeometry(0.195, 8, 6);
const hairGeometry = new THREE.SphereGeometry(
0.205,
8,
5,
0,
Math.PI * 2,
0,
Math.PI / 2
);
const limbGeometry = new THREE.CylinderGeometry(0.055, 0.07, 0.54, 5);
const legGeometry = new THREE.CylinderGeometry(0.065, 0.075, 0.64, 5);
const noseGeometry = new THREE.SphereGeometry(0.035, 5, 4);
const clothingPalette = [
0x496d73, 0x8e5849, 0xd2b05f, 0x566b4f, 0x78627d,
0xc17b61, 0x365b61, 0x9b8b68, 0x5f748a, 0xa84e52
];
const skinMaterials = [
material(0xd6a477),
material(0xb97c55),
material(0x8d5d40),
material(0xe5bb91),
material(0x6f4936)
];
const hairMaterials = [
material(0x28231f),
material(0x4a3024),
material(0x6f5943),
material(0x8f8068)
];
function makePerson(options = {}) {
const {
x = 0,
z = 0,
seated = false,
heading = 0,
scale = 1,
scarf = false,
backpack = false
} = options;
const person = new THREE.Group();
person.position.set(x, 0.12, z);
person.rotation.y = heading;
person.scale.setScalar(scale);
const clothing = material(pick(clothingPalette));
const skin = pick(skinMaterials);
const hair = pick(hairMaterials);
const limbs = [];
const body = new THREE.Mesh(bodyGeometry, clothing);
body.castShadow = true;
body.receiveShadow = true;
person.add(body);
const head = new THREE.Mesh(headGeometry, skin);
head.castShadow = true;
person.add(head);
const hairCap = new THREE.Mesh(hairGeometry, scarf ? clothing : hair);
hairCap.castShadow = true;
person.add(hairCap);
const nose = new THREE.Mesh(noseGeometry, skin);
person.add(nose);
if (seated) {
body.position.set(0, 0.62, 0);
head.position.set(0, 1.12, 0);
hairCap.position.set(0, 1.14, 0);
nose.position.set(0, 1.12, 0.19);
for (const side of [-1, 1]) {
const thigh = box(person, 0.13, 0.13, 0.52, mat.metal, side * 0.12, 0.25, 0.2);
const shin = box(person, 0.12, 0.48, 0.12, mat.metal, side * 0.12, 0.02, 0.44);
thigh.rotation.x = -0.1;
shin.rotation.x = 0.06;
}
} else {
body.position.y = 1.05;
head.position.y = 1.62;
hairCap.position.y = 1.65;
nose.position.set(0, 1.62, 0.19);
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(legGeometry, mat.metal);
leg.position.set(side * 0.13, 0.36, 0);
leg.castShadow = true;
person.add(leg);
limbs.push(leg);
const arm = new THREE.Mesh(limbGeometry, clothing);
arm.position.set(side * 0.31, 1.08, 0);
arm.rotation.z = side * 0.12;
arm.castShadow = true;
person.add(arm);
limbs.push(arm);
}
}
if (scarf) {
const scarfShape = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.235, 0.39, 8),
clothing
);
scarfShape.position.set(0, 1.48, 0);
scarfShape.castShadow = true;
person.add(scarfShape);
}
if (backpack) {
box(person, 0.34, 0.42, 0.17, pick(clothingPalette.map((c) => material(c))), 0, 1.08, -0.25);
}
person.userData.limbs = limbs;
world.add(person);
return person;
}
// Static everyday moments.
makePerson({ x: -1.9, z: -9.2, seated: true, heading: Math.PI / 2, scale: 0.98 });
makePerson({ x: 1.9, z: 9.2, seated: true, heading: -Math.PI / 2, scale: 1.03 });
makePerson({ x: -14.4, z: 1.5, seated: true, heading: -Math.PI / 2, scale: 0.96 });
makePerson({ x: 14.4, z: -1.5, seated: true, heading: Math.PI / 2, scale: 1.02 });
// Two small conversation groups.
makePerson({ x: -6.0, z: -10.0, heading: 0.7, scale: 1.0 });
makePerson({ x: -5.1, z: -10.1, heading: -2.3, scale: 0.96, scarf: true });
makePerson({ x: 6.2, z: 10.1, heading: 0.8, scale: 1.01 });
makePerson({ x: 7.1, z: 9.95, heading: -2.4, scale: 0.94, backpack: true });
// Visitors standing and looking toward the architecture.
makePerson({ x: 12.8, z: -0.4, heading: -1.55, scale: 1.03, backpack: true });
makePerson({ x: -11.5, z: 0.8, heading: 1.55, scale: 0.98, scarf: true });
makePerson({ x: 3.0, z: -7.4, heading: 2.2, scale: 0.92 });
makePerson({ x: -3.2, z: 7.2, heading: -0.9, scale: 0.95, scarf: true });
// Animated walkers.
const walkerPaths = [
new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-16.2, 0, -11.5),
new THREE.Vector3(16.2, 0, -11.5),
new THREE.Vector3(16.2, 0, 11.5),
new THREE.Vector3(-16.2, 0, 11.5)
],
true,
"catmullrom",
0.08
),
new THREE.CatmullRomCurve3(
[
new THREE.Vector3(0, 0, -11.4),
new THREE.Vector3(0, 0, 11.4)
],
false,
"catmullrom",
0
),
new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-14.3, 0, -2.0),
new THREE.Vector3(14.3, 0, -2.0),
new THREE.Vector3(14.3, 0, 2.0),
new THREE.Vector3(-14.3, 0, 2.0)
],
true,
"catmullrom",
0.08
)
];
const walkers = [];
for (let i = 0; i < 9; i++) {
const person = makePerson({
scale: 0.88 + random() * 0.2,
scarf: random() > 0.76,
backpack: random() > 0.78
});
walkers.push({
person,
curve: walkerPaths[i % walkerPaths.length],
offset: random(),
speed: 0.014 + random() * 0.008,
phase: random() * Math.PI * 2
});
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom and keyboard pan
// -------------------------------------------------------------------------
const cameraState = {
theta: 2.28,
phi: 1.02,
radius: 48,
target: new THREE.Vector3(0, 2.1, 0)
};
function resetCamera() {
cameraState.theta = 2.28;
cameraState.phi = 1.02;
cameraState.radius = 48;
cameraState.target.set(0, 2.1, 0);
updateCamera();
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.cos(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const pointers = new Map();
let previousPinchDistance = 0;
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 [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.0045,
0.46,
1.35
);
updateCamera();
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + (previousPinchDistance - distance) * 0.035,
27,
72
);
previousPinchDistance = distance;
updateCamera();
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.025,
27,
72
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
const step = 0.11;
if (event.key === "ArrowLeft") {
cameraState.theta -= step;
} else if (event.key === "ArrowRight") {
cameraState.theta += step;
} else if (event.key === "ArrowUp") {
cameraState.target.z -= step * 2;
} else if (event.key === "ArrowDown") {
cameraState.target.z += step * 2;
} else if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(27, cameraState.radius - 2);
} else if (event.key === "-" || event.key === "_") {
cameraState.radius = Math.min(72, cameraState.radius + 2);
} else {
return;
}
event.preventDefault();
updateCamera();
});
// -------------------------------------------------------------------------
// Interface and lighting mood
// -------------------------------------------------------------------------
let lifePaused = false;
let goldenHour = false;
const lifeButton = document.getElementById("lifeButton");
const moodButton = document.getElementById("moodButton");
const infoButton = document.getElementById("infoButton");
const landmarkList = document.getElementById("landmarkList");
lifeButton.addEventListener("click", () => {
lifePaused = !lifePaused;
lifeButton.textContent = lifePaused ? "Resume life" : "Pause life";
});
infoButton.addEventListener("click", () => {
landmarkList.classList.toggle("visible");
infoButton.textContent = landmarkList.classList.contains("visible")
? "Hide landmarks"
: "Landmarks";
});
function applyMood() {
if (goldenHour) {
scene.background.set(0xe3c8aa);
scene.fog.color.set(0xe3c8aa);
sun.color.set(0xffb768);
sun.intensity = 3.65;
hemi.color.set(0xe8d9c2);
hemi.groundColor.set(0x8e6649);
hemi.intensity = 1.65;
fillLight.color.set(0x7fabc0);
fillLight.intensity = 0.78;
renderer.toneMappingExposure = 1.03;
} else {
scene.background.set(0xdce5df);
scene.fog.color.set(0xdce5df);
sun.color.set(0xffe4b4);
sun.intensity = 3.25;
hemi.color.set(0xeaf5f1);
hemi.groundColor.set(0x9c7650);
hemi.intensity = 2.05;
fillLight.color.set(0xb9d8e0);
fillLight.intensity = 0.65;
renderer.toneMappingExposure = 1.08;
}
}
moodButton.addEventListener("click", () => {
goldenHour = !goldenHour;
moodButton.textContent = goldenHour ? "Daylight" : "Golden hour";
applyMood();
});
document.getElementById("resetButton").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const animationTime = lifePaused ? clock.getElapsedTime() * 0 : elapsed;
for (const walker of walkers) {
const u = (walker.offset + animationTime * walker.speed) % 1;
const point = walker.curve.getPointAt(Math.min(u, 0.99999));
const tangent = walker.curve.getTangentAt(Math.min(u, 0.99999));
walker.person.position.x = point.x;
walker.person.position.z = point.z;
walker.person.rotation.y = Math.atan2(tangent.x, tangent.z);
const gait = Math.sin(animationTime * 7.2 + walker.phase);
walker.person.position.y = 0.12 + Math.abs(gait) * 0.025;
const limbs = walker.person.userData.limbs;
if (limbs.length === 4) {
limbs[0].rotation.x = gait * 0.42;
limbs[2].rotation.x = -gait * 0.42;
limbs[1].rotation.x = -gait * 0.34;
limbs[3].rotation.x = gait * 0.34;
}
}
renderer.render(scene, camera);
loader.classList.add("ready");
}
animate();
</script>
</body>
</html>
```