Prompt specification
Build or customize the Three.js 3D scene "Jemaa el-Fna square-edge activity 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: Jemaa el-Fna square-edge activity slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/jemaa-el-fna-square-edge-activity-slice-x2939
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: Jemaa el-Fna square-edge activity slice. Build a bounded voxel scene with referenced square edge, selected facades, temporary stalls, and varied everyday activity. Avoid treating performers as the square's only users. Return one self-contained HTML file.
Working Three.js Starter (jemaa-el-fna-square-edge-activity-slice-x2939):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jemaa el-Fnaa — Square-Edge Activity Slice</title>
<style>
:root {
--ink: #3c2925;
--paper: rgba(255, 247, 226, 0.92);
--accent: #b54c32;
--line: rgba(60, 41, 37, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 68% 22%, rgba(255, 247, 204, 0.95), transparent 34%),
linear-gradient(180deg, #edc897 0%, #d99c75 58%, #a66557 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
#title-card {
top: 22px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 17px 19px 16px;
border: 1px solid rgba(255,255,255,0.35);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(70, 35, 28, 0.15);
backdrop-filter: blur(10px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #8e4d37;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: #c65b3e;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(26px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
#title-card p {
margin: 11px 0 0;
max-width: 300px;
color: rgba(60, 41, 37, 0.72);
font-size: 12px;
line-height: 1.45;
}
#legend {
left: 24px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 7px;
max-width: min(570px, calc(100vw - 48px));
}
.legend-chip {
padding: 7px 10px;
border: 1px solid rgba(255,255,255,0.26);
border-radius: 2px;
background: rgba(255, 247, 226, 0.82);
box-shadow: 0 4px 14px rgba(60, 41, 37, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-chip::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
background: var(--chip);
vertical-align: 1px;
}
#controls {
right: 22px;
bottom: 22px;
z-index: 20;
display: flex;
align-items: center;
gap: 7px;
pointer-events: auto;
}
.control-button {
min-width: 38px;
height: 38px;
padding: 0 12px;
border: 1px solid rgba(255,255,255,0.42);
border-radius: 2px;
background: rgba(255, 247, 226, 0.9);
color: var(--ink);
box-shadow: 0 6px 18px rgba(60, 41, 37, 0.13);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
.control-button:hover {
transform: translateY(-2px);
background: #fff9e9;
}
.control-button.active {
background: #633d32;
color: #fff4d7;
}
#hint {
right: 24px;
top: 24px;
padding: 8px 11px;
border-radius: 2px;
background: rgba(255, 247, 226, 0.7);
color: rgba(60, 41, 37, 0.68);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.annotation {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: max-content;
padding: 7px 9px;
border: 1px solid rgba(255,255,255,0.5);
border-radius: 2px;
background: rgba(48, 34, 29, 0.82);
color: #fff4dc;
box-shadow: 0 5px 16px rgba(50, 30, 22, 0.18);
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
will-change: left, top;
}
.annotation::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 16px;
background: rgba(48, 34, 29, 0.65);
}
.annotation .number {
color: #ef9b62;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
}
.annotation .text {
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #e9bc88;
color: #5d372d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#title-card p { display: none; }
#hint { display: none; }
#legend { left: 12px; bottom: 60px; max-width: calc(100vw - 24px); }
#controls { right: 12px; bottom: 12px; }
.control-button { padding: 0 9px; }
.annotation .text { font-size: 8px; }
}
</style>
</head>
<body>
<main id="app" aria-label="Interactive voxel scene of the edge of Jemaa el-Fnaa"></main>
<section id="title-card" class="hud">
<div class="eyebrow">Voxel activity slice · Marrakech</div>
<h1>Jemaa el-Fnaa,<br>at the edge.</h1>
<p>A bounded study of a permanent square edge, temporary market stalls, performers, vendors, workers, families, visitors, and everyday errands sharing the same public space.</p>
</section>
<div id="hint" class="hud">Drag to orbit · Scroll to zoom · Arrow keys to explore</div>
<div id="legend" class="hud">
<div class="legend-chip" style="--chip:#c66b43">Permanent facades</div>
<div class="legend-chip" style="--chip:#e7b64f">Temporary stalls</div>
<div class="legend-chip" style="--chip:#8d6954">Everyday users</div>
<div class="legend-chip" style="--chip:#b63e32">Performance circle</div>
</div>
<div id="labels" aria-hidden="true">
<div class="annotation" id="label-facades">
<span class="number">01</span><span class="text">Permanent square edge</span>
</div>
<div class="annotation" id="label-stalls">
<span class="number">02</span><span class="text">Temporary market row</span>
</div>
<div class="annotation" id="label-story">
<span class="number">03</span><span class="text">Story and music circle</span>
</div>
<div class="annotation" id="label-daily">
<span class="number">04</span><span class="text">Daily errands</span>
</div>
<div class="annotation" id="label-family">
<span class="number">05</span><span class="text">Families and shoppers</span>
</div>
</div>
<nav id="controls" aria-label="Scene controls">
<button class="control-button active" data-view="overview" title="Overview">Overview</button>
<button class="control-button" data-view="street" title="Street-level market view">Street</button>
<button class="control-button" id="labels-toggle" title="Toggle annotations" aria-pressed="true">Labels</button>
<button class="control-button" id="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
<button class="control-button" id="zoom-out" title="Zoom out" aria-label="Zoom out">−</button>
</nav>
<div id="loading">Assembling the square edge…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Voxel diorama of Jemaa el-Fnaa's square edge");
renderer.domElement.tabIndex = 0;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe0b58d, 48, 96);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const world = new THREE.Group();
scene.add(world);
const GROUND = 0.18;
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true
}));
}
return materialCache.get(color);
}
function box(parent, x, y, z, w, h, d, color, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, getMaterial(color));
mesh.position.set(x, y, z);
mesh.scale.set(w, h, d);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent, x = 0, y = 0, z = 0, rotation = 0) {
const g = new THREE.Group();
g.position.set(x, y, z);
g.rotation.y = rotation;
parent.add(g);
return g;
}
function seededRandom(seed) {
let s = seed >>> 0;
return () => {
s = (s * 1664525 + 1013904223) >>> 0;
return s / 4294967296;
};
}
const random = seededRandom(48271);
// Lighting: warm afternoon sun, cool ambient fill, and long readable shadows.
const hemisphere = new THREE.HemisphereLight(0xffe4b7, 0x765149, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd39b, 3.4);
sun.position.set(-19, 31, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -31;
sun.shadow.camera.right = 31;
sun.shadow.camera.top = 29;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 82;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
sun.target.position.set(0, 0, -2);
scene.add(sun, sun.target);
const fill = new THREE.DirectionalLight(0xa9c7d1, 0.55);
fill.position.set(20, 13, -18);
scene.add(fill);
// Bounded, stepped display plinth.
box(world, 0, -0.72, 0, 42, 1.28, 32, 0x69463d);
box(world, 0, -0.08, 0, 41.45, 0.18, 31.45, 0xa56f53);
// Instanced paving creates a fine voxel-like ground without hundreds of draw calls.
const tileGeometry = new THREE.BoxGeometry(1.075, 0.12, 1.075);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
metalness: 0
});
const columns = 39;
const rows = 29;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, columns * rows);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
const pavingPalette = [0xc8aa7d, 0xd0b489, 0xbe9a70, 0xc5a177, 0xd4b98d];
let tileIndex = 0;
for (let iz = 0; iz < rows; iz++) {
for (let ix = 0; ix < columns; ix++) {
const x = -19.6 + ix * 1.03;
const z = -14.3 + iz * 1.03;
dummy.position.set(x, GROUND - 0.06, z);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
let color;
if (z > 11.6) {
color = [0x9e735b, 0xa87a60, 0x946a55][(ix + iz) % 3];
} else if (z < -4 && Math.abs(x) < 12) {
color = [0xc89267, 0xd09a70, 0xbd855e][(ix + iz) % 3];
} else {
color = pavingPalette[(ix * 3 + iz * 5) % pavingPalette.length];
}
tileColor.setHex(color);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
world.add(tiles);
// Front and right-edge curbs make the slice visibly bounded.
for (let x = -19.5; x <= 19.5; x += 2) {
box(world, x, 0.28, 14.55, 1.88, 0.23, 0.35, x % 4 < 2 ? 0xd0a578 : 0xc09269);
}
for (let z = -12.5; z <= 12.5; z += 2) {
box(world, 19.65, 0.28, z, 0.35, 0.23, 1.88, 0xc59a70);
}
for (const x of [-18.6, -6.2, 6.2, 18.6]) {
box(world, x, 0.63, 14.45, 0.46, 0.9, 0.46, 0x8f5f45);
box(world, x, 1.08, 14.45, 0.58, 0.16, 0.58, 0xc28a60);
}
// Permanent facade maker.
function makeFacade({
x, z, width, height, color, trim, shutter, accent,
rotation = 0, balcony = false, crenellated = false
}) {
const g = group(world, x, GROUND, z, rotation);
const depth = 1.15;
const front = depth / 2;
box(g, 0, 0.25, 0, width + 0.12, 0.5, depth + 0.28, 0x9b6c53);
box(g, 0, height / 2 + 0.5, 0, width, height, depth, color);
box(g, 0, 3.65, front + 0.035, width, 0.12, 0.13, trim);
box(g, 0, height - 0.16, front + 0.035, width, 0.15, 0.13, trim);
box(g, 0, height + 0.57, 0, width + 0.22, 0.24, depth + 0.3, trim);
box(g, 0, height + 0.74, 0, width + 0.08, 0.15, depth + 0.15, color);
function windowUnit(wx, wy, ww = 0.9) {
box(g, wx, wy, front + 0.055, ww, 1.12, 0.12, 0x34444a);
box(g, wx - ww / 2 - 0.19, wy, front + 0.12, 0.28, 1.18, 0.13, shutter);
box(g, wx + ww / 2 + 0.19, wy, front + 0.12, 0.28, 1.18, 0.13, shutter);
box(g, wx, wy - 0.63, front + 0.13, ww + 0.76, 0.14, 0.25, trim);
box(g, wx, wy + 0.63, front + 0.11, ww + 0.7, 0.15, 0.18, trim);
box(g, wx, wy, front + 0.13, 0.06, 1.08, 0.08, 0x5b4c40, false);
}
// Central stepped doorway.
box(g, 0, 1.37, front + 0.06, 1.45, 2.45, 0.14, 0x4c3028);
box(g, 0, 2.62, front + 0.09, 0.93, 0.35, 0.14, 0x4c3028);
box(g, 0, 2.83, front + 0.09, 0.48, 0.22, 0.14, 0x4c3028);
box(g, -0.86, 1.38, front + 0.13, 0.16, 2.55, 0.17, trim);
box(g, 0.86, 1.38, front + 0.13, 0.16, 2.55, 0.17, trim);
box(g, 0, 0.11, front + 0.39, 1.85, 0.22, 0.72, trim);
if (width > 4.8) {
windowUnit(-width * 0.31, 1.8, 0.86);
windowUnit(width * 0.31, 1.8, 0.86);
}
const upperWindowCount = width > 7 ? 4 : 3;
for (let i = 0; i < upperWindowCount; i++) {
const spread = upperWindowCount === 4
? [-0.33, -0.11, 0.11, 0.33]
: [-0.28, 0, 0.28];
windowUnit(spread[i] * width, Math.max(5.1, height * 0.67), 0.82);
}
// Segmented shop awning.
const awningSegments = 6;
for (let i = 0; i < awningSegments; i++) {
const sw = width / awningSegments;
box(
g,
-width / 2 + sw * (i + 0.5),
3.03,
front + 0.42,
sw,
0.16,
0.88,
i % 2 === 0 ? accent : 0xe7d6ad
);
}
box(g, 0, 2.82, front + 0.85, width, 0.28, 0.1, accent);
if (balcony) {
box(g, 0, 4.15, front + 0.52, width * 0.48, 0.18, 0.92, trim);
box(g, 0, 4.49, front + 0.91, width * 0.48, 0.68, 0.1, shutter);
for (let i = 0; i < 7; i++) {
box(
g,
-width * 0.21 + i * width * 0.07,
4.47,
front + 0.95,
0.055,
0.58,
0.08,
trim,
false
);
}
}
if (crenellated) {
const count = Math.floor(width / 0.9);
for (let i = 0; i < count; i++) {
box(
g,
-width / 2 + 0.45 + i * (width / count),
height + 1.02,
front - 0.03,
0.5,
0.47,
depth + 0.12,
trim
);
}
}
// Small rooftop domestic details.
box(g, -width * 0.22, height + 1.03, -0.12, 0.55, 0.48, 0.55, 0xa97857);
box(g, width * 0.28, height + 0.98, 0.08, 0.85, 0.32, 0.58, 0xc69269);
return g;
}
const backFacades = [
{ x: -12.8, width: 7.0, height: 8.1, color: 0xc98565, trim: 0xe1b98d, shutter: 0x466b62, accent: 0xe4bb66 },
{ x: -6.0, width: 6.2, height: 10.2, color: 0xd39a73, trim: 0xedc89c, shutter: 0x3f6670, accent: 0xb9503c, balcony: true },
{ x: 1.0, width: 6.5, height: 8.7, color: 0xb96f58, trim: 0xdcb083, shutter: 0x596d50, accent: 0xe5c06c, crenellated: true },
{ x: 8.0, width: 7.0, height: 11.1, color: 0xcf8664, trim: 0xe8bd8e, shutter: 0x3d625d, accent: 0xc65539, balcony: true },
{ x: 15.0, width: 6.0, height: 8.5, color: 0xdc9b70, trim: 0xf0c995, shutter: 0x526975, accent: 0xd9a747 }
];
backFacades.forEach(f => makeFacade({ ...f, z: -12.55 }));
makeFacade({
x: -18.55, z: -7.1, width: 6.8, height: 9.2,
color: 0xb8735c, trim: 0xe2b185, shutter: 0x45645c,
accent: 0xdfb756, rotation: Math.PI / 2
});
makeFacade({
x: -18.55, z: 0.2, width: 6.6, height: 11.0,
color: 0xd38b67, trim: 0xebc08c, shutter: 0x4a626d,
accent: 0xbb4f39, rotation: Math.PI / 2, balcony: true
});
makeFacade({
x: -18.55, z: 7.3, width: 6.8, height: 8.6,
color: 0xc78563, trim: 0xe4b78b, shutter: 0x536950,
accent: 0xe1b654, rotation: Math.PI / 2
});
// A simplified minaret anchors the recognizable square-edge skyline.
const minaret = group(world, -15.9, GROUND, -14.0);
box(minaret, 0, 0.45, 0, 3.8, 0.9, 3.6, 0x9b654d);
box(minaret, 0, 4.4, 0, 3.0, 7.2, 2.8, 0xc18761);
box(minaret, 0, 7.95, 0, 3.45, 0.32, 3.15, 0xe0b27e);
box(minaret, 0, 9.05, 0, 2.45, 1.9, 2.35, 0xc99067);
box(minaret, 0, 10.12, 0, 2.85, 0.25, 2.7, 0xe6bc86);
box(minaret, 0, 11.0, 0, 2.25, 1.55, 2.2, 0xc48b64);
box(minaret, 0, 11.9, 0, 2.75, 0.28, 2.7, 0xe4b981);
box(minaret, 0, 12.55, 0, 1.8, 1.0, 1.8, 0xb87a59);
box(minaret, 0, 13.2, 0, 2.15, 0.22, 2.15, 0xe5b780);
box(minaret, 0, 13.65, 0, 1.05, 0.65, 1.05, 0xc18760);
box(minaret, 0, 14.12, 0, 0.32, 0.45, 0.32, 0xe3af73);
box(minaret, 0, 5.2, 1.43, 0.43, 1.2, 0.11, 0x5a5146, false);
box(minaret, 0, 9.1, 1.2, 0.5, 0.95, 0.12, 0x5a5146, false);
box(minaret, 0, 11.0, 1.13, 0.44, 0.85, 0.12, 0x5a5146, false);
// Voxel people, with separate standing, walking, seated and carrying poses.
function makePerson(parent, x, z, options = {}) {
const {
shirt = 0xb95e45,
trousers = 0x46565a,
skin = 0xb87954,
hair = 0x332822,
scarf = null,
hat = null,
scale = 1,
rotation = 0,
seated = false,
walk = false,
bag = false,
basket = false,
camera = false,
broom = false,
scarfTail = false
} = options;
const g = group(parent, x, 0, z, rotation);
g.scale.setScalar(scale);
if (seated) {
box(g, -0.15, 0.52, 0.17, 0.27, 0.25, 0.68, trousers);
box(g, 0.15, 0.52, 0.17, 0.27, 0.25, 0.68, trousers);
box(g, -0.15, 0.22, 0.47, 0.24, 0.48, 0.25, trousers);
box(g, 0.15, 0.22, 0.47, 0.24, 0.48, 0.25, trousers);
box(g, -0.15, 0.91, 0, 0.57, 0.72, 0.34, shirt);
box(g, -0.42, 0.89, 0.04, 0.2, 0.63, 0.24, shirt);
box(g, 0.42, 0.89, 0.04, 0.2, 0.63, 0.24, shirt);
box(g, 0, 1.52, 0.02, 0.43, 0.43, 0.4, skin);
box(g, 0, 1.74, -0.01, 0.45, 0.14, 0.42, hair);
} else {
const leftLeg = box(g, -0.15, 0.38, 0, 0.27, 0.72, 0.29, trousers);
const rightLeg = box(g, 0.15, 0.38, 0, 0.27, 0.72, 0.29, trousers);
if (walk) {
leftLeg.rotation.z = -0.16;
rightLeg.rotation.z = 0.16;
}
box(g, 0, 1.02, 0, 0.59, 0.7, 0.36, shirt);
const leftArm = box(g, -0.41, 1.03, 0, 0.19, 0.66, 0.23, shirt);
const rightArm = box(g, 0.41, 1.03, 0, 0.19, 0.66, 0.23, shirt);
if (walk) {
leftArm.rotation.z = 0.15;
rightArm.rotation.z = -0.15;
}
box(g, 0, 1.68, 0.01, 0.43, 0.43, 0.41, skin);
box(g, 0, 1.89, -0.01, 0.45, 0.13, 0.43, hair);
}
if (scarf) {
box(g, 0, seated ? 1.53 : 1.69, 0.01, 0.49, 0.47, 0.46, scarf);
box(g, 0, seated ? 1.55 : 1.71, 0.25, 0.3, 0.27, 0.08, skin, false);
if (scarfTail) {
box(g, 0, seated ? 1.22 : 1.38, -0.22, 0.42, 0.62, 0.12, scarf);
}
}
if (hat) {
box(g, 0, seated ? 1.8 : 1.98, 0, 0.56, 0.12, 0.54, hat);
box(g, 0, seated ? 1.96 : 2.12, -0.02, 0.35, 0.26, 0.36, hat);
}
if (bag) {
box(g, 0.58, seated ? 0.5 : 0.64, 0.05, 0.36, 0.4, 0.25, 0x8c5a3e);
box(g, 0.58, seated ? 0.75 : 0.9, 0.05, 0.08, 0.22, 0.06, 0x5f493c, false);
}
if (basket) {
box(g, 0.61, seated ? 0.53 : 0.66, 0.18, 0.42, 0.3, 0.34, 0xb98351);
box(g, 0.61, seated ? 0.67 : 0.8, 0.18, 0.31, 0.06, 0.23, 0x6b4c36, false);
}
if (camera) {
box(g, 0.48, seated ? 1.08 : 1.28, 0.3, 0.28, 0.19, 0.18, 0x303638);
box(g, 0.48, seated ? 1.08 : 1.28, 0.41, 0.11, 0.11, 0.07, 0x8eb0b5, false);
}
if (broom) {
box(g, 0.56, 0.88, 0.16, 0.07, 1.72, 0.07, 0x9b7047);
box(g, 0.56, 0.08, 0.18, 0.46, 0.16, 0.22, 0x7d603e);
}
return g;
}
// Temporary market stall.
function makeStall(x, z, accent, type, rotation = 0) {
const g = group(world, x, GROUND, z, rotation);
const wood = 0x8f603e;
const darkWood = 0x674531;
box(g, 0, 0.35, 0.44, 3.8, 0.55, 1.45, darkWood);
box(g, 0, 1.25, 0.46, 4.0, 0.18, 1.55, wood);
box(g, 0, 0.66, -0.72, 3.55, 0.14, 0.52, wood);
for (const px of [-1.82, 1.82]) {
for (const pz of [-0.72, 0.72]) {
box(g, px, 1.42, pz, 0.12, 2.64, 0.12, darkWood);
}
}
for (let i = 0; i < 8; i++) {
box(
g,
-1.75 + i * 0.5,
2.76,
0,
0.5,
0.18,
2.15,
i % 2 === 0 ? accent : 0xead9ad
);
}
for (let i = 0; i < 8; i++) {
box(
g,
-1.75 + i * 0.5,
2.48,
1.04,
0.5,
0.33,
0.09,
i % 2 === 0 ? accent : 0xead9ad
);
}
if (type === "produce") {
for (let i = 0; i < 4; i++) {
box(g, -1.35 + i * 0.9, 1.46, 0.47, 0.7, 0.24, 0.72, 0x705238);
const fruitColors = [0xd85c32, 0xe1a52f, 0x718b3e, 0xc94b31];
for (let j = 0; j < 3; j++) {
box(
g,
-1.48 + i * 0.9 + (j % 2) * 0.23,
1.67,
0.32 + Math.floor(j / 2) * 0.25,
0.2,
0.2,
0.2,
fruitColors[(i + j) % fruitColors.length]
);
}
}
} else if (type === "food") {
box(g, -1.1, 1.51, 0.28, 1.25, 0.3, 0.75, 0x3e4340);
box(g, -1.1, 1.71, 0.28, 1.02, 0.12, 0.56, 0x6d5540);
box(g, 0.85, 1.48, 0.24, 0.62, 0.29, 0.62, 0x454744);
box(g, 0.85, 1.68, 0.24, 0.42, 0.12, 0.42, 0x303532);
for (let i = 0; i < 4; i++) {
box(g, 0.16 + i * 0.31, 1.45, 0.63, 0.25, 0.18, 0.25, 0xc58b4d);
}
} else if (type === "juice") {
box(g, -1.15, 1.48, 0.25, 1.55, 0.28, 0.86, 0x8c623e);
for (let i = 0; i < 6; i++) {
box(g, -1.62 + i * 0.2, 1.78, 0.28, 0.13, 0.34, 0.13, 0xe19a26);
box(g, -1.62 + i * 0.2, 1.97, 0.28, 0.15, 0.05, 0.15, 0xf3d38a, false);
}
box(g, 0.78, 1.45, 0.24, 0.85, 0.24, 0.68, 0x9b6c42);
for (let i = 0; i < 4; i++) {
box(g, 0.51 + i * 0.2, 1.67, 0.24, 0.14, 0.28, 0.14, 0xe3a22d);
}
} else if (type === "textile") {
const rugs = [0x9d3f32, 0xd09b45, 0x496f69, 0x76506c];
for (let i = 0; i < 4; i++) {
box(g, -1.25 + i * 0.82, 1.72, -0.7, 0.62, 1.35, 0.08, rugs[i]);
box(g, -1.25 + i * 0.82, 2.34, -0.64, 0.44, 0.12, 0.08, 0xe1b273, false);
}
box(g, 1.3, 1.45, 0.32, 0.65, 0.22, 0.72, 0xb5814f);
}
return g;
}
const foodStall = makeStall(-9.0, -7.1, 0x3f7b70, "food");
const juiceStall = makeStall(-3.9, -7.0, 0xe49b2e, "juice");
const produceStall = makeStall(1.35, -7.25, 0x729044, "produce");
const textileStall = makeStall(7.0, -7.0, 0xa34234, "textile");
makePerson(foodStall, -0.6, -0.45, {
shirt: 0xe3d5ad, trousers: 0x5f5143, skin: 0xa96543,
scarf: 0xeee0bd, rotation: 0
});
makePerson(juiceStall, 0.35, -0.48, {
shirt: 0x4f7880, trousers: 0x58483e, skin: 0xc88c62,
scarf: 0xe2d7b5, rotation: 0
});
makePerson(produceStall, -0.2, -0.5, {
shirt: 0x9d573d, trousers: 0x485454, skin: 0x9e6246,
hat: 0xd5b46e, rotation: 0
});
makePerson(textileStall, 0.55, -0.45, {
shirt: 0x795f83, trousers: 0x514a42, skin: 0xc98d64,
scarf: 0x744a6c, scarfTail: true, rotation: 0
});
// Small overhead stall lights and bunting.
box(world, 0.5, 4.08, -4.72, 23.2, 0.055, 0.055, 0x5a493d);
const flagColors = [0xc54d37, 0xe0ad42, 0x4c7a72, 0xe6d7ad];
for (let i = 0; i < 15; i++) {
const flag = box(
world,
-10.2 + i * 1.52,
3.86,
-4.72,
0.24,
0.38,
0.07,
flagColors[i % flagColors.length]
);
flag.rotation.z = (i % 2 ? 1 : -1) * 0.08;
}
// Story and music circle: one performance zone among many other uses.
const rug = group(world, 7.0, GROUND + 0.015, 4.65);
const rugColors = [0x9c4035, 0xd09a4e, 0x496f68, 0x704f68];
for (let ix = 0; ix < 8; ix++) {
for (let iz = 0; iz < 5; iz++) {
box(
rug,
-3.15 + ix * 0.9,
0,
-1.8 + iz * 0.9,
0.87,
0.055,
0.87,
rugColors[(ix + iz * 2) % rugColors.length],
false
);
}
}
const storyteller = makePerson(world, 7.0, 3.0, {
shirt: 0xb44735, trousers: 0x4b4c42, skin: 0xb97751,
scarf: 0xe2c78e, rotation: 0, scale: 1.03
});
box(storyteller, 0.55, 1.07, 0.3, 0.08, 1.15, 0.08, 0x8d613c);
box(storyteller, 0.55, 1.63, 0.3, 0.34, 0.3, 0.08, 0xe8c58a);
makePerson(world, 9.25, 3.85, {
shirt: 0x55776c, trousers: 0x654f3e, skin: 0xa96748,
seated: true, rotation: -1.65
});
box(world, 9.02, 0.72, 4.6, 0.82, 0.72, 0.82, 0xa86f3f);
box(world, 9.02, 1.11, 4.6, 0.88, 0.1, 0.88, 0xd4a15f);
box(world, 9.35, 1.16, 4.6, 0.08, 0.08, 0.85, 0xe6d19f);
const audience = [
[4.5, 5.55, 0x567b82, 0xc98d63],
[5.75, 6.55, 0xc77745, 0x9b6146],
[7.15, 6.75, 0x7a5f7e, 0xd19a70],
[8.65, 6.35, 0x52765c, 0xa96c4e],
[10.0, 5.4, 0xd3a547, 0xc1845d]
];
audience.forEach(([x, z, shirt, skin]) => {
makePerson(world, x, z, {
shirt,
trousers: 0x4e5149,
skin,
seated: true,
rotation: Math.atan2(7.0 - x, 3.0 - z)
});
});
// Bench and a resting elder near the facade edge.
function makeBench(x, z, rotation = 0) {
const g = group(world, x, GROUND, z, rotation);
box(g, 0, 0.63, 0, 2.65, 0.18, 0.72, 0x8c5b3e);
box(g, 0, 1.13, -0.3, 2.65, 0.78, 0.14, 0x9c6844);
box(g, -1.05, 0.31, 0, 0.18, 0.62, 0.62, 0x654936);
box(g, 1.05, 0.31, 0, 0.18, 0.62, 0.62, 0x654936);
return g;
}
makeBench(-15.65, 2.0, Math.PI / 2);
makePerson(world, -15.25, 2.0, {
shirt: 0x78666a, trousers: 0x505151, skin: 0xbd8967,
seated: true, rotation: Math.PI / 2, scarf: 0xd7d0bb
});
makePerson(world, -14.75, 2.2, {
shirt: 0x5c7771, trousers: 0x554b43, skin: 0x8f5c44,
seated: true, rotation: Math.PI / 2
});
// Shoppers and visitors circulate between the stalls and open square.
makePerson(world, -5.8, -4.75, {
shirt: 0xe1b44b, trousers: 0x5e6a62, skin: 0xc28760,
basket: true, rotation: 0.1, walk: true
});
makePerson(world, -1.9, -5.2, {
shirt: 0x4d7480, trousers: 0x73503e, skin: 0x9f6748,
scarf: 0xdbd2b7, scarfTail: true, rotation: -0.25, walk: true
});
makePerson(world, 2.8, -5.3, {
shirt: 0xc65d42, trousers: 0x4d5654, skin: 0xd29a70,
basket: true, rotation: 0.25
});
makePerson(world, 8.2, -5.15, {
shirt: 0xe1d5b4, trousers: 0x685144, skin: 0xb97b57,
scarf: 0xede3c7, rotation: -0.15
});
makePerson(world, -4.8, 5.15, {
shirt: 0x566f86, trousers: 0x3f4e51, skin: 0xd3a17a,
camera: true, rotation: 0.75
});
makePerson(world, -3.7, 5.7, {
shirt: 0xbd6846, trousers: 0x675346, skin: 0xba805c,
bag: true, rotation: 0.55, walk: true
});
// Family and child in the open foreground.
makePerson(world, 11.0, 8.8, {
shirt: 0x3f7772, trousers: 0x55483f, skin: 0xb97955,
scarf: 0xe7d5b0, rotation: -0.65
});
makePerson(world, 12.1, 8.3, {
shirt: 0xe0a93d, trousers: 0x76503f, skin: 0xc88b61,
scale: 0.67, rotation: -0.45, walk: true
});
// Street cleaner and broom.
makePerson(world, 12.3, 2.0, {
shirt: 0x577568, trousers: 0x4c5553, skin: 0x9f6649,
broom: true, rotation: -0.8, walk: true
});
// Tea table and social stop.
box(world, 14.0, 0.95, -2.2, 1.35, 0.16, 1.35, 0x93603e);
box(world, 14.0, 0.48, -2.2, 0.24, 0.9, 0.24, 0x6c4935);
box(world, 14.0, 0.12, -2.2, 0.75, 0.16, 0.75, 0x6c4935);
for (const [x, z] of [[12.9, -2.3], [15.0, -2.1], [14.2, -3.3]]) {
box(world, x, 0.45, z, 0.55, 0.15, 0.55, 0xb37a4b);
box(world, x, 0.21, z, 0.18, 0.42, 0.18, 0x73503b);
}
for (let i = 0; i < 4; i++) {
box(world, 13.55 + i * 0.28, 1.18, -2.2, 0.12, 0.3, 0.12, 0xe2bd65);
}
makePerson(world, 12.9, -2.3, {
shirt: 0x8d4f3f, trousers: 0x4e5148, skin: 0xb87b55,
seated: true, rotation: 0.3
});
// Delivery motorcycle, deliberately blocky like the rest of the scene.
const motorbike = group(world, 14.0, GROUND, 1.9, -0.45);
for (const z of [-0.85, 0.85]) {
box(motorbike, 0, 0.5, z, 0.58, 0.72, 0.68, 0x303335);
box(motorbike, 0.02, 0.5, z, 0.62, 0.18, 0.18, 0x9b9a8d);
}
box(motorbike, 0, 0.9, 0, 0.64, 0.48, 1.55, 0x4d766d);
box(motorbike, 0, 1.32, -0.62, 0.72, 0.75, 0.8, 0xd49b3c);
box(motorbike, 0, 1.45, 0.45, 0.58, 0.16, 0.62, 0x3f3b35);
box(motorbike, 0, 1.66, 0.72, 0.12, 0.68, 0.12, 0x3f4544);
box(motorbike, 0, 1.94, 0.72, 0.78, 0.1, 0.1, 0x3f4544);
box(motorbike, 0, 1.76, 0.12, 0.58, 0.65, 0.35, 0x466b86);
box(motorbike, 0, 2.24, 0.12, 0.42, 0.42, 0.4, 0xb87952);
box(motorbike, 0, 2.46, 0.1, 0.44, 0.13, 0.42, 0x39312c);
box(motorbike, -0.34, 1.77, 0.4, 0.16, 0.55, 0.18, 0x466b86);
box(motorbike, 0.34, 1.77, 0.4, 0.16, 0.55, 0.18, 0x466b86);
// Handcart and porter.
const handcart = group(world, -9.5, GROUND, 8.8, 0.25);
box(handcart, 0, 0.76, 0, 1.75, 0.76, 1.3, 0x9a6740);
box(handcart, 0, 1.17, 0, 1.88, 0.13, 1.42, 0xb67d4d);
box(handcart, -0.92, 0.35, 0, 0.42, 0.62, 0.8, 0x3f3934);
box(handcart, 0.92, 0.35, 0, 0.42, 0.62, 0.8, 0x3f3934);
box(handcart, 0, 0.94, 1.45, 0.12, 0.12, 2.0, 0x6f4a32);
box(handcart, 0, 1.35, 0.3, 1.4, 0.4, 0.85, 0xc8a05c);
makePerson(world, -11.65, 8.2, {
shirt: 0xc98b45, trousers: 0x545a53, skin: 0xa96c49,
rotation: 0.25, walk: true
});
// More everyday crossing traffic.
makePerson(world, 0.2, 10.5, {
shirt: 0x9b4737, trousers: 0x4f5550, skin: 0xc58b63,
bag: true, rotation: 1.1, walk: true
});
makePerson(world, 1.5, 10.9, {
shirt: 0x59766c, trousers: 0x675144, skin: 0x936047,
rotation: 1.0, walk: true
});
makePerson(world, 16.1, 5.9, {
shirt: 0xd8b84f, trousers: 0x4f5d5b, skin: 0xb67a55,
rotation: -1.3, walk: true
});
// Pigeons and other small signs of urban life.
function makePigeon(x, z, rotation = 0, color = 0x8a8b83) {
const g = group(world, x, GROUND, z, rotation);
box(g, 0, 0.29, 0, 0.32, 0.28, 0.52, color);
box(g, 0, 0.47, 0.25, 0.22, 0.22, 0.22, 0xa6a69a);
box(g, 0, 0.49, 0.08, 0.31, 0.18, 0.22, color);
box(g, 0, 0.3, -0.35, 0.22, 0.12, 0.34, 0x666c67);
box(g, -0.1, 0.08, 0.04, 0.05, 0.2, 0.05, 0xb2774d, false);
box(g, 0.1, 0.08, 0.04, 0.05, 0.2, 0.05, 0xb2774d, false);
}
makePigeon(-6.6, 3.3, 0.4);
makePigeon(-5.7, 3.6, -0.7, 0x777d79);
makePigeon(10.0, 7.1, 1.2, 0xb0a797);
makePigeon(10.6, 6.8, 0.5);
makePigeon(4.1, 10.8, -0.5, 0x85877f);
// Palm and potted tree mark the outer corner of the bounded slice.
const palm = group(world, 17.2, GROUND, -10.2);
for (let i = 0; i < 7; i++) {
box(palm, i * 0.045, 0.55 + i * 0.72, 0, 0.52 - i * 0.025, 0.74, 0.52 - i * 0.025, i % 2 ? 0x9a714c : 0xaa7b50);
}
const palmTop = 5.65;
for (let i = 0; i < 7; i++) {
const a = i * Math.PI * 2 / 7;
const frond = box(
palm,
Math.cos(a) * 1.28,
palmTop - 0.12,
Math.sin(a) * 1.28,
2.45,
0.22,
0.52,
i % 2 ? 0x526b45 : 0x627a4c
);
frond.rotation.y = -a;
frond.rotation.z = Math.sin(a) * 0.12;
}
box(palm, 0, 5.28, 0, 0.7, 0.55, 0.7, 0x74553a);
const tree = group(world, 17.0, GROUND, 9.4);
box(tree, 0, 0.22, 0, 2.3, 0.44, 2.3, 0xa56f51);
box(tree, 0, 1.55, 0, 0.45, 2.6, 0.45, 0x76513b);
const leafColors = [0x4e7046, 0x5c7d4c, 0x69864e];
for (let i = 0; i < 15; i++) {
const a = i * 2.399;
const radius = i < 5 ? 0.45 : 1.05;
box(
tree,
Math.cos(a) * radius,
2.55 + (i % 4) * 0.4,
Math.sin(a) * radius,
1.15,
0.85,
1.15,
leafColors[i % leafColors.length]
);
}
for (let i = 0; i < 5; i++) {
box(tree, -0.8 + i * 0.4, 2.6 + (i % 2) * 0.65, 1.05, 0.19, 0.19, 0.19, 0xd98731);
}
// Fine airborne dust, rendered as tiny square points.
const dustCount = 70;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (random() - 0.5) * 40;
dustPositions[i * 3 + 1] = 0.8 + random() * 11;
dustPositions[i * 3 + 2] = (random() - 0.5) * 28;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffdda3,
size: 0.085,
transparent: true,
opacity: 0.38,
depthWrite: false,
sizeAttenuation: true
})
);
world.add(dust);
// Camera controls are implemented directly, without addons.
const desired = {
target: new THREE.Vector3(0, 2.7, -0.5),
yaw: 0.67,
pitch: 0.48,
radius: 48
};
const current = {
target: desired.target.clone(),
yaw: desired.yaw,
pitch: desired.pitch,
radius: desired.radius
};
function applyCamera() {
const horizontal = Math.cos(current.pitch) * current.radius;
camera.position.set(
current.target.x + Math.sin(current.yaw) * horizontal,
current.target.y + Math.sin(current.pitch) * current.radius,
current.target.z + Math.cos(current.yaw) * horizontal
);
camera.lookAt(current.target);
}
function setView(name) {
if (name === "street") {
desired.target.set(-2.0, 2.2, -5.2);
desired.yaw = 0.28;
desired.pitch = 0.30;
desired.radius = 27;
} else {
desired.target.set(0, 2.7, -0.5);
desired.yaw = 0.67;
desired.pitch = 0.48;
desired.radius = 48;
}
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let labelsVisible = true;
const labelsToggle = document.getElementById("labels-toggle");
labelsToggle.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsToggle.classList.toggle("active", labelsVisible);
labelsToggle.setAttribute("aria-pressed", String(labelsVisible));
document.getElementById("labels").style.display = labelsVisible ? "block" : "none";
});
document.getElementById("zoom-in").addEventListener("click", () => {
desired.radius = THREE.MathUtils.clamp(desired.radius * 0.86, 18, 70);
});
document.getElementById("zoom-out").addEventListener("click", () => {
desired.radius = THREE.MathUtils.clamp(desired.radius * 1.16, 18, 70);
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (event.shiftKey) {
const scale = desired.radius * 0.0015;
const right = new THREE.Vector3(Math.cos(desired.yaw), 0, -Math.sin(desired.yaw));
const forward = new THREE.Vector3(Math.sin(desired.yaw), 0, Math.cos(desired.yaw));
desired.target.addScaledVector(right, -dx * scale);
desired.target.addScaledVector(forward, -dy * scale);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -16, 16);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -13, 12);
} else {
desired.yaw -= dx * 0.006;
desired.pitch = THREE.MathUtils.clamp(desired.pitch + dy * 0.0045, 0.16, 1.03);
}
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
18,
70
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => setView("overview"));
window.addEventListener("keydown", event => {
const key = event.key;
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "+", "=", "-"].includes(key)) {
event.preventDefault();
}
if (key === "ArrowLeft") desired.yaw += 0.12;
if (key === "ArrowRight") desired.yaw -= 0.12;
if (key === "ArrowUp") desired.pitch = THREE.MathUtils.clamp(desired.pitch + 0.08, 0.16, 1.03);
if (key === "ArrowDown") desired.pitch = THREE.MathUtils.clamp(desired.pitch - 0.08, 0.16, 1.03);
if (key === "+" || key === "=") desired.radius = Math.max(18, desired.radius * 0.9);
if (key === "-") desired.radius = Math.min(70, desired.radius * 1.1);
if (key.toLowerCase() === "r") setView("overview");
});
// Screen-space annotations use plain DOM and projected Three.js positions.
const annotations = [
{ id: "label-facades", position: new THREE.Vector3(-7.4, 8.7, -12.0), dx: 0, dy: -8 },
{ id: "label-stalls", position: new THREE.Vector3(-3.9, 3.4, -6.7), dx: 0, dy: -6 },
{ id: "label-story", position: new THREE.Vector3(7.1, 2.6, 4.5), dx: 0, dy: -8 },
{ id: "label-daily", position: new THREE.Vector3(13.1, 2.8, 1.5), dx: 30, dy: -5 },
{ id: "label-family", position: new THREE.Vector3(11.1, 2.1, 8.5), dx: 5, dy: -5 }
].map(item => ({
...item,
element: document.getElementById(item.id)
}));
const projected = new THREE.Vector3();
function updateAnnotations() {
if (!labelsVisible) return;
const width = window.innerWidth;
const height = window.innerHeight;
annotations.forEach(annotation => {
projected.copy(annotation.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width + annotation.dx;
const y = (-projected.y * 0.5 + 0.5) * height + annotation.dy;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
});
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
function shortestAngleDifference(a, b) {
return Math.atan2(Math.sin(b - a), Math.cos(b - a));
}
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-dt * 7.5);
current.target.lerp(desired.target, smoothing);
current.yaw += shortestAngleDifference(current.yaw, desired.yaw) * smoothing;
current.pitch += (desired.pitch - current.pitch) * smoothing;
current.radius += (desired.radius - current.radius) * smoothing;
applyCamera();
dust.rotation.y += dt * 0.008;
dust.position.y = Math.sin(performance.now() * 0.00018) * 0.12;
renderer.render(scene, camera);
updateAnnotations();
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
renderer.shadowMap.autoUpdate = false;
}
}
resize();
applyCamera();
animate();
</script>
</body>
</html>
```