Prompt specification
Build or customize the Three.js 3D scene "Compare routes during a fictional neighborhood event" 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: Compare routes during a fictional neighborhood event
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-routes-during-a-fictional-neighborhood-event-x3028
Scene Description Prompt:
Plan a fictional voxel event in Singapore's Kampong Glam, preserving pedestrian routes and designated worship access. Three.js from cdnjs, one HTML file.
Working Three.js Starter (compare-routes-during-a-fictional-neighborhood-event-x3028):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kampong Glam Voxel Night Market</title>
<style>
:root {
--ink: #102c31;
--muted: #5b7173;
--paper: rgba(250, 247, 238, 0.94);
--line: rgba(16, 44, 49, 0.14);
--public: #24ad9b;
--worship: #e6a928;
--event: #ed725f;
--violet: #6558a6;
--shadow: 0 18px 55px rgba(16, 44, 49, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #dce7df;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 22px;
left: 22px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
.brand-mark {
display: grid;
place-items: center;
width: 46px;
height: 46px;
border-radius: 14px;
background: var(--ink);
color: #fff7df;
box-shadow: var(--shadow);
font-weight: 900;
letter-spacing: -0.08em;
}
.brand-copy {
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 13px;
background: rgba(250, 247, 238, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.brand-copy small,
.eyebrow {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand-copy strong {
font-size: 13px;
}
.panel {
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.plan-panel {
position: absolute;
top: 92px;
bottom: 106px;
left: 22px;
width: 340px;
padding: 20px;
overflow: auto;
scrollbar-width: thin;
}
.concept-pill {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 14px;
padding: 6px 9px;
border-radius: 999px;
background: #e4f3ee;
color: #137e70;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.concept-pill::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--public);
content: "";
}
h1 {
margin: 0;
font-size: clamp(27px, 2.5vw, 37px);
line-height: 0.99;
letter-spacing: -0.055em;
}
.intro {
margin: 13px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.facts {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
margin-bottom: 18px;
}
.fact {
min-height: 64px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.46);
}
.fact strong {
display: block;
margin-bottom: 3px;
font-size: 17px;
letter-spacing: -0.03em;
}
.fact span {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.section {
padding-top: 17px;
margin-top: 17px;
border-top: 1px solid var(--line);
}
.section-title {
margin: 0 0 10px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.02em;
}
.route-row,
.toggle-row {
display: flex;
align-items: flex-start;
gap: 10px;
margin: 9px 0;
}
.route-swatch,
.toggle-swatch {
flex: 0 0 auto;
width: 11px;
height: 11px;
margin-top: 3px;
border-radius: 3px;
}
.route-copy {
flex: 1;
}
.route-copy strong {
display: block;
margin-bottom: 2px;
font-size: 12px;
}
.route-copy small {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.42;
}
.route-button {
flex: 0 0 auto;
padding: 4px 7px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.58);
cursor: pointer;
font-size: 10px;
font-weight: 800;
}
.route-button:hover,
.route-button:focus-visible {
border-color: var(--ink);
outline: none;
}
.toggle-row {
align-items: center;
cursor: pointer;
}
.toggle-row input {
width: 15px;
height: 15px;
accent-color: var(--ink);
}
.toggle-row span:last-child {
font-size: 12px;
font-weight: 700;
}
.principles {
margin: 0;
padding-left: 17px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.principles li {
margin: 5px 0;
}
.legend {
position: absolute;
top: 22px;
right: 22px;
width: 236px;
padding: 14px 16px;
pointer-events: auto;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
font-size: 11px;
font-weight: 700;
}
.legend-line {
width: 24px;
height: 5px;
border-radius: 4px;
}
.compass {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.north {
display: grid;
place-items: center;
width: 28px;
height: 28px;
border: 1px solid var(--line);
border-radius: 50%;
color: var(--ink);
}
.timeline {
position: absolute;
right: 22px;
bottom: 22px;
left: 384px;
display: grid;
grid-template-columns: 150px 1fr 130px;
align-items: center;
gap: 18px;
padding: 15px 18px;
pointer-events: auto;
}
.phase-title {
font-size: 15px;
font-weight: 850;
letter-spacing: -0.02em;
}
.phase-title small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
accent-color: var(--event);
cursor: pointer;
}
.time-readout {
text-align: right;
}
.time-readout strong {
display: block;
font-size: 23px;
letter-spacing: -0.05em;
}
.time-readout span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.inspector {
position: absolute;
right: 22px;
bottom: 106px;
width: 318px;
padding: 17px;
pointer-events: auto;
}
.inspector h2 {
margin: 3px 0 8px;
font-size: 19px;
letter-spacing: -0.035em;
}
.inspector p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.52;
}
.inspector-facts {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 11px;
}
.inspector-facts span {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.5);
font-size: 9px;
font-weight: 800;
}
.hint {
position: absolute;
right: 24px;
bottom: 87px;
color: rgba(16, 44, 49, 0.58);
font-size: 10px;
font-weight: 750;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}
.disclaimer {
position: absolute;
bottom: 88px;
left: 24px;
max-width: 320px;
color: rgba(16, 44, 49, 0.58);
font-size: 9px;
line-height: 1.45;
}
@media (max-width: 900px) {
.brand-copy {
display: none;
}
.plan-panel {
top: 80px;
bottom: 116px;
width: min(320px, calc(100vw - 44px));
}
.legend {
top: 80px;
right: 14px;
width: 195px;
}
.timeline {
right: 14px;
bottom: 14px;
left: 14px;
grid-template-columns: 105px 1fr 80px;
gap: 10px;
}
.inspector,
.disclaimer {
display: none;
}
}
@media (max-width: 560px) {
.legend {
top: 76px;
width: 160px;
padding: 10px;
}
.legend-row {
font-size: 9px;
}
.plan-panel {
top: 74px;
max-height: 45vh;
}
.timeline {
grid-template-columns: 82px 1fr 60px;
padding: 12px;
}
.phase-title {
font-size: 12px;
}
.time-readout strong {
font-size: 18px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel plan of a fictional event in Kampong Glam"></main>
<div class="ui">
<header class="brand">
<div class="brand-mark">KG</div>
<div class="brand-copy">
<small>Singapore · Kampong Glam</small>
<strong>Voxel Event Planning Study</strong>
</div>
</header>
<aside class="panel plan-panel" aria-label="Event plan">
<div class="concept-pill">Fictional concept</div>
<h1>Kampong Glam<br>Voxel Night Market</h1>
<p class="intro">
A compact evening market concept around the existing pedestrian grain
of Kampong Glam, with Sultan Mosque treated as a protected quiet and
worship-access zone.
</p>
<div class="facts">
<div class="fact">
<strong>17:00–22:00</strong>
<span>Illustrative hours</span>
</div>
<div class="fact">
<strong>1,800</strong>
<span>Peak planning cap</span>
</div>
<div class="fact">
<strong>6</strong>
<span>Modular market bays</span>
</div>
<div class="fact">
<strong>2.4 m</strong>
<span>Worship access spine</span>
</div>
</div>
<section class="section">
<h2 class="section-title">Circulation & access</h2>
<div class="route-row">
<span class="route-swatch" style="background: var(--public)"></span>
<span class="route-copy">
<strong>Public pedestrian loop</strong>
<small>Continuous 1.8 m marked route linking MRT, bus, stalls, and exits.</small>
</span>
<button class="route-button" data-focus="public">View</button>
</div>
<div class="route-row">
<span class="route-swatch" style="background: var(--worship)"></span>
<span class="route-copy">
<strong>Designated worship access</strong>
<small>Protected 2.4 m approach from mosque entrance to accessible drop-off.</small>
</span>
<button class="route-button" data-focus="worship">View</button>
</div>
<div class="route-row">
<span class="route-swatch" style="background: var(--event)"></span>
<span class="route-copy">
<strong>Event operating envelope</strong>
<small>Stalls, queues, and stages remain outside the worship spine and mosque frontage.</small>
</span>
<button class="route-button" data-focus="event">View</button>
</div>
</section>
<section class="section">
<h2 class="section-title">Map layers</h2>
<label class="toggle-row">
<input type="checkbox" data-layer="public" checked>
<span class="toggle-swatch" style="background: var(--public)"></span>
<span>Public pedestrian routes</span>
</label>
<label class="toggle-row">
<input type="checkbox" data-layer="worship" checked>
<span class="toggle-swatch" style="background: var(--worship)"></span>
<span>Worship access spine</span>
</label>
<label class="toggle-row">
<input type="checkbox" data-layer="zones" checked>
<span class="toggle-swatch" style="background: var(--event)"></span>
<span>Event operating zones</span>
</label>
</section>
<section class="section">
<h2 class="section-title">Planning principles</h2>
<ul class="principles">
<li>No queues, cooking, amplified sound, or temporary structures in the mosque frontage.</li>
<li>Crossings of the worship spine use priority markings and staffed event periods.</li>
<li>Step-free access remains available from the public loop to the worship drop-off.</li>
<li>Delivery, waste, and emergency access use existing road edges outside event hours.</li>
</ul>
</section>
</aside>
<section class="panel legend" aria-label="Legend">
<div class="legend-row">
<span class="legend-line" style="background: var(--public)"></span>
Public walking route
</div>
<div class="legend-row">
<span class="legend-line" style="background: var(--worship)"></span>
Worship access
</div>
<div class="legend-row">
<span class="legend-line" style="background: var(--event)"></span>
Event footprint
</div>
<div class="legend-row">
<span class="legend-line" style="background: var(--violet)"></span>
Priority crossing
</div>
<div class="compass">
<span>Illustrative site</span>
<span class="north">N ↑</span>
</div>
</section>
<section class="panel inspector" id="inspector" aria-live="polite"></section>
<section class="panel timeline" aria-label="Event time preview">
<div class="phase-title">
<span id="phaseName">Setup</span>
<small>Time preview</small>
</div>
<div>
<input
id="timeSlider"
type="range"
min="15"
max="22"
step="0.25"
value="15"
aria-label="Preview event time"
>
<div class="legend-row" style="justify-content: space-between; margin: 2px 0 0">
<span style="font-size: 9px; color: var(--muted)">15:00</span>
<span style="font-size: 9px; color: var(--muted)">17:00 OPEN</span>
<span style="font-size: 9px; color: var(--muted)">20:00 PEAK</span>
<span style="font-size: 9px; color: var(--muted)">22:00</span>
</div>
</div>
<div class="time-readout">
<strong id="timeValue">15:00</strong>
<span id="occupancyLabel">Crew only</span>
</div>
</section>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom · Click a hotspot</div>
<div class="disclaimer">
Fictional, non-surveyed planning visualization. Access arrangements must be
validated with the relevant authorities, mosque management, and property owners.
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Application state
// ------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const inspector = document.querySelector("#inspector");
const timeSlider = document.querySelector("#timeSlider");
const timeValue = document.querySelector("#timeValue");
const phaseName = document.querySelector("#phaseName");
const occupancyLabel = document.querySelector("#occupancyLabel");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce7df");
scene.fog = new THREE.Fog("#dce7df", 100, 175);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
300
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
const hemisphere = new THREE.HemisphereLight("#fff8df", "#668277", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff1ce", 3.2);
sun.position.set(-32, 52, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 58;
sun.shadow.camera.bottom = -58;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 130;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d8ff", 0.7);
fill.position.set(38, 24, -35);
scene.add(fill);
const routePublic = new THREE.Group();
const routeWorship = new THREE.Group();
const eventZones = new THREE.Group();
const eventStructures = new THREE.Group();
const cityGroup = new THREE.Group();
const mosqueGroup = new THREE.Group();
const crowdGroup = new THREE.Group();
scene.add(
cityGroup,
mosqueGroup,
eventZones,
eventStructures,
routePublic,
routeWorship,
crowdGroup
);
const pickables = [];
const routeMaterials = [];
const crowd = [];
const animatedFoliage = [];
const cameraState = {
theta: 0.78,
phi: 0.96,
radius: 86,
target: new THREE.Vector3(0, 0, 0),
goalTheta: 0.78,
goalPhi: 0.96,
goalRadius: 86,
goalTarget: new THREE.Vector3(0, 0, 0)
};
const colors = {
ground: "#a9c3a8",
pavement: "#e7dfca",
road: "#4b5555",
roadMark: "#f2ead4",
sand: "#d7c59b",
cream: "#f1dfb4",
gold: "#e6aa37",
darkGold: "#b97a21",
teal: "#24ad9b",
coral: "#ed725f",
violet: "#6558a6",
ink: "#18383a",
white: "#f6f0df"
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function box(
parent,
size,
position,
color,
options = {}
) {
const {
roughness = 0.84,
metalness = 0,
castShadow = true,
receiveShadow = true,
...materialOptions
} = options;
const geometry = new THREE.BoxGeometry(
size[0],
size[1],
size[2]
);
const material = new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
...materialOptions
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function registerPickable(root, id) {
root.traverse((object) => {
if (object.isMesh) {
object.userData.pickId = id;
}
});
pickables.push(root);
}
function roundedRect(ctx, x, y, w, h, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function addLabel(
text,
position,
width = 13,
background = "#15383b",
foreground = "#fff8e7"
) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 12, 624, 104, 22);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,.35)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = "800 32px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 320, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(position[0], position[1], position[2]);
sprite.scale.set(width, width * 0.2, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function addArrow(parent, x, z, heading, material) {
const arrow = new THREE.Group();
arrow.position.set(x, 0.38, z);
arrow.rotation.y = -heading;
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.85, 0.07, 0.16),
material
);
shaft.position.x = -0.3;
arrow.add(shaft);
const headA = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.07, 0.16),
material
);
headA.position.set(0.33, 0, 0.17);
headA.rotation.y = -0.58;
arrow.add(headA);
const headB = headA.clone();
headB.position.z = -0.17;
headB.rotation.y = 0.58;
arrow.add(headB);
parent.add(arrow);
}
function addRoute(parent, points, width, color, arrowEvery = 6) {
const material = new THREE.MeshStandardMaterial({
color,
transparent: true,
opacity: 0.72,
roughness: 0.7,
depthWrite: false
});
const arrowMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
});
routeMaterials.push(material, arrowMaterial);
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const heading = Math.atan2(dz, dx);
const segment = box(
parent,
[length, 0.075, width],
[(a[0] + b[0]) / 2, 0.28, (a[1] + b[1]) / 2],
color,
{
transparent: true,
opacity: 0.72,
depthWrite: false,
castShadow: false,
receiveShadow: false
}
);
segment.rotation.y = -heading;
const arrowCount = Math.max(1, Math.floor(length / arrowEvery));
for (let n = 1; n <= arrowCount; n++) {
const t = n / (arrowCount + 1);
addArrow(
parent,
a[0] + dx * t,
a[1] + dz * t,
heading,
arrowMaterial
);
}
}
}
function addCrossing(x, z) {
const group = new THREE.Group();
for (let i = -2; i <= 2; i++) {
box(
group,
[2.5, 0.09, 0.18],
[x, 0.39, z + i * 0.42],
colors.violet,
{
transparent: true,
opacity: 0.9,
castShadow: false,
receiveShadow: false
}
);
}
scene.add(group);
registerPickable(group, "crossing");
}
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
box(group, [0.55 * scale, 2.7 * scale, 0.55 * scale], [0, 1.35 * scale, 0], "#76583e");
box(group, [2.8 * scale, 2.4 * scale, 2.8 * scale], [0, 3.35 * scale, 0], "#4f8564");
box(group, [2.1 * scale, 1.5 * scale, 2.1 * scale], [0.4 * scale, 4.45 * scale, 0.15 * scale], "#65966b");
box(group, [1.3 * scale, 1.1 * scale, 1.3 * scale], [-0.45 * scale, 5.2 * scale, -0.2 * scale], "#75a474");
group.position.set(x, 0, z);
cityGroup.add(group);
animatedFoliage.push(group);
}
function addShophouse(x, z, width, depth, height, color) {
const group = new THREE.Group();
box(group, [width, height, depth], [0, height / 2, 0], color);
box(group, [width + 0.45, 0.45, depth + 0.45], [0, height + 0.2, 0], "#385457");
const floors = Math.max(1, Math.floor(height / 3));
const windowsPerFloor = Math.max(1, Math.floor(width / 2.4));
for (let floor = 0; floor < floors; floor++) {
const y = 1.5 + floor * 2.6;
for (let i = 0; i < windowsPerFloor; i++) {
const wx = -width / 2 + 1.5 + i * 2.4;
if (Math.abs(wx) > width / 2 - 0.5) continue;
box(
group,
[0.85, 1.05, 0.12],
[wx, y, depth / 2 + 0.07],
"#244b58",
{ roughness: 0.35, metalness: 0.1 }
);
}
}
box(
group,
[width * 0.86, 0.24, 1.1],
[0, 2.25, depth / 2 + 0.55],
"#efb95d"
);
box(
group,
[1.1, 1.8, 0.18],
[0, 1.05, depth / 2 + 0.1],
"#315253"
);
group.position.set(x, 0, z);
cityGroup.add(group);
return group;
}
function addPlanter(x, z) {
const group = new THREE.Group();
box(group, [0.8, 0.75, 1.8], [0, 0.45, 0], "#b6b79f");
box(group, [0.85, 0.4, 1.65], [0, 0.95, 0], "#4e825f");
box(group, [0.35, 0.55, 0.35], [0.12, 1.3, 0], "#6e9a68");
group.position.set(x, 0, z);
scene.add(group);
}
// ------------------------------------------------------------
// Ground, streets, and urban context
// ------------------------------------------------------------
box(cityGroup, [86, 1.2, 80], [0, -0.72, 0], colors.ground);
box(cityGroup, [79, 0.22, 73], [0, -0.05, 0], colors.pavement);
// Existing edge roads.
box(cityGroup, [78, 0.12, 4], [0, 0.13, 35], colors.road, { castShadow: false });
box(cityGroup, [4, 0.12, 69], [36, 0.13, 0], colors.road, { castShadow: false });
box(cityGroup, [4, 0.12, 69], [-37, 0.13, 0], colors.road, { castShadow: false });
// Road centre markings.
for (let x = -32; x <= 32; x += 5) {
if (x > 3 && x < 9) continue;
box(cityGroup, [2.1, 0.05, 0.13], [x, 0.22, 35], colors.roadMark, { castShadow: false });
}
for (let z = -28; z <= 28; z += 5) {
if (z > 1 && z < 9) continue;
box(cityGroup, [0.13, 0.05, 2.1], [36, 0.22, z], colors.roadMark, { castShadow: false });
}
// Public pedestrian loop and connections.
const publicPoints = [
[-9, 3],
[25, 3],
[25, 30],
[-9, 30],
[-9, 3]
];
const publicLinks = [
[[-9, 30], [-9, 35]],
[[25, 30], [36, 30]]
];
addRoute(routePublic, publicPoints, 1.8, colors.teal, 7);
for (const link of publicLinks) {
addRoute(routePublic, link, 1.8, colors.teal, 7);
}
// Worship access spine, extended to the south curb.
const worshipPoints = [
[6, -14],
[6, 35]
];
addRoute(routeWorship, worshipPoints, 2.4, colors.gold, 6);
// Physical separation except at marked public crossings.
for (const z of [-9, -3, 9, 15, 21, 27]) {
addPlanter(3.65, z);
addPlanter(8.35, z);
}
addCrossing(6, 3);
addCrossing(6, 30);
// Context blocks.
const westColors = ["#b75d51", "#d4a552", "#4f8390", "#c97b67", "#708d68"];
const eastColors = ["#6f8994", "#d08a5f", "#8d756e", "#809b76", "#b99456"];
[-23, -12, -1, 10, 21].forEach((z, i) => {
addShophouse(-42, z, 7.5, 8.5, 8 + (i % 3) * 2.5, westColors[i]);
});
[-21, -9, 3, 15, 27].forEach((z, i) => {
addShophouse(42, z, 7.5, 8.5, 8 + ((i + 1) % 3) * 2.5, eastColors[i]);
});
addShophouse(-30, -37, 8, 6, 10, "#7b8b78");
addShophouse(-18, -37, 7, 6, 8, "#b26b5d");
addShophouse(29, -37, 9, 6, 11, "#81929a");
[
[-33, 25],
[-32, -6],
[-31, 16],
[30, 22],
[31, -18],
[30, -29],
[-15, 37],
[17, 37],
[40, 8]
].forEach(([x, z], i) => addTree(x, z, 0.85 + (i % 3) * 0.12));
// ------------------------------------------------------------
// Stylized Sultan Mosque and protected compound
// ------------------------------------------------------------
box(mosqueGroup, [45, 0.34, 23], [0, 0.17, -23], "#c9bc98");
// Compound walls, with a deliberate opening at the worship access.
box(mosqueGroup, [22, 1.35, 0.55], [-10.5, 0.78, -11.5], colors.sand);
box(mosqueGroup, [11, 1.35, 0.55], [15.5, 0.78, -11.5], colors.sand);
box(mosqueGroup, [0.55, 1.35, 21], [-22, 0.78, -23], colors.sand);
box(mosqueGroup, [0.55, 1.35, 21], [22, 0.78, -23], colors.sand);
// Prayer hall.
box(mosqueGroup, [28, 8, 12], [0, 4.2, -26], colors.cream);
box(mosqueGroup, [29, 0.55, 13], [0, 8.25, -26], "#d0b66f");
box(mosqueGroup, [25, 0.38, 10], [0, 8.65, -26], colors.gold);
// Stepped voxel dome.
const domeTiers = [
[14, 0.9, 11],
[12, 0.85, 9.5],
[10, 0.85, 8],
[8, 0.85, 6.5],
[6, 0.85, 5],
[4, 0.9, 3.6],
[2.3, 1.1, 2.3]
];
let domeY = 9.0;
for (const tier of domeTiers) {
box(mosqueGroup, tier, [0, domeY, -26], colors.gold);
domeY += tier[1];
}
box(mosqueGroup, [0.35, 2.2, 0.35], [0, domeY + 0.8, -26], colors.darkGold);
box(mosqueGroup, [0.9, 0.35, 0.9], [0, domeY + 1.85, -26], colors.gold);
// Minarets.
for (const x of [-16, 16]) {
box(mosqueGroup, [2.4, 12, 2.4], [x, 6.2, -24], colors.cream);
box(mosqueGroup, [3.2, 0.65, 3.2], [x, 12.3, -24], colors.gold);
box(mosqueGroup, [1.9, 2.4, 1.9], [x, 13.7, -24], colors.cream);
box(mosqueGroup, [2.7, 0.55, 2.7], [x, 15, -24], colors.gold);
box(mosqueGroup, [1.4, 1.5, 1.4], [x, 15.8, -24], colors.gold);
box(mosqueGroup, [0.3, 1.6, 0.3], [x, 17.2, -24], colors.darkGold);
}
// Entrance portico aligned with the worship access spine.
box(mosqueGroup, [6.5, 0.55, 5.2], [6, 5.1, -17.1], colors.gold);
for (const x of [3.5, 8.5]) {
box(mosqueGroup, [0.55, 4.7, 0.55], [x, 2.65, -16.5], colors.cream);
}
box(mosqueGroup, [2.4, 3.4, 0.3], [6, 1.95, -15.0], "#315354");
box(mosqueGroup, [3.3, 0.35, 0.55], [6, 4.15, -15.05], colors.gold);
// Arched windows approximated with voxel frames.
for (const x of [-10, -5, 0, 11, 15]) {
box(mosqueGroup, [2.0, 3.0, 0.18], [x, 4.4, -19.92], "#315c63", { roughness: 0.35 });
box(mosqueGroup, [0.25, 3.5, 0.28], [x, 4.4, -19.8], colors.gold);
box(mosqueGroup, [2.35, 0.25, 0.28], [x, 4.4, -19.8], colors.gold);
}
registerPickable(mosqueGroup, "mosque");
addLabel(
"SULTAN MOSQUE · QUIET FRONTAGE",
[0, 19, -24],
20,
"#7b5520"
);
// ------------------------------------------------------------
// Event operating zones
// ------------------------------------------------------------
function addZone(x, z, width, depth, id, color = colors.coral) {
const zone = box(
eventZones,
[width, 0.1, depth],
[x, 0.31, z],
color,
{
transparent: true,
opacity: 0.24,
depthWrite: false,
castShadow: false,
receiveShadow: false
}
);
zone.userData.pickId = id;
pickables.push(zone);
return zone;
}
addZone(-27, -3, 20, 16, "stage");
addZone(-14, 13, 7.2, 25, "stalls");
addZone(14, 12, 12, 17, "craft");
addZone(-12, 23, 7, 8, "entry");
addZone(-27, 23, 10, 8, "operations");
addZone(29, 15, 7, 10, "amenities");
// Main stage, facing south toward the market.
const stage = new THREE.Group();
box(stage, [14, 1.1, 7], [0, 0.7, 0], "#43585a");
box(stage, [15, 0.4, 8], [0, 0.2, 0], "#263f42");
box(stage, [10.5, 5.5, 0.6], [0, 4.25, -3.2], "#24383d");
box(stage, [9.6, 4.6, 0.2], [0, 4.35, -2.84], "#315c66", {
emissive: "#173a44",
emissiveIntensity: 0.5
});
for (let i = 0; i < 8; i++) {
box(
stage,
[0.75, 0.75, 0.22],
[-4.1 + i * 1.18, 4.4 + Math.sin(i * 0.8) * 1.1, -2.66],
["#ed725f", "#f2bc55", "#52b6a8", "#7771b6"][i % 4],
{ emissive: "#253c3e", emissiveIntensity: 0.25 }
);
}
for (const x of [-7, 7]) {
box(stage, [0.65, 7.5, 0.65], [x, 4, 0.3], "#253f42");
box(stage, [0.9, 0.45, 0.9], [x, 7.85, 0.3], colors.gold);
}
stage.position.set(-27, 0, -3);
eventStructures.add(stage);
registerPickable(stage, "stage");
// Six modular food and craft bays.
function addStall(x, z, color, index) {
const group = new THREE.Group();
box(group, [4.3, 1.15, 2.4], [0, 0.75, 0], "#b88b58");
box(group, [4.8, 0.3, 3], [0, 3.4, 0], color);
for (const sx of [-2, 2]) {
for (const sz of [-1.1, 1.1]) {
box(group, [0.18, 3.1, 0.18], [sx, 1.65, sz], "#486363");
}
}
for (let i = 0; i < 4; i++) {
box(
group,
[0.65, 0.55, 0.65],
[-1.3 + i * 0.85, 1.55, 0.15],
["#f3c45b", "#e77861", "#75b7a1", "#f0e5c7"][(i + index) % 4]
);
}
group.position.set(x, 0, z);
eventStructures.add(group);
registerPickable(group, "stalls");
}
[2, 8, 14, 20].forEach((z, i) => {
addStall(-14, z, ["#ed725f", "#e3b54f", "#3ba695", "#776aa9"][i], i);
});
addStall(13, 7, "#e4b34d", 4);
addStall(13, 15, "#5ba99a", 5);
// Entry, security, and step-free approach.
const entry = new THREE.Group();
for (const x of [-2.4, 2.4]) {
box(entry, [0.65, 4.2, 0.65], [x, 2.1, 0], "#355558");
box(entry, [1.1, 0.4, 1.1], [x, 4.35, 0], colors.gold);
}
box(entry, [5.4, 0.55, 0.8], [0, 4.2, 0], "#e4b54d");
box(entry, [3.2, 1.0, 2.1], [0, 0.65, 0], "#d6b16a");
entry.position.set(-12, 0, 27);
eventStructures.add(entry);
registerPickable(entry, "entry");
// Operations, medical aid, and toilets.
const operations = new THREE.Group();
box(operations, [6.5, 3.2, 4.6], [0, 1.7, 0], "#dce2d2");
box(operations, [7, 0.35, 5.1], [0, 3.45, 0], "#375b5e");
box(operations, [1.2, 2.1, 0.12], [0, 1.2, 2.35], "#315b62");
operations.position.set(-27, 0, 23);
eventStructures.add(operations);
registerPickable(operations, "operations");
const medical = new THREE.Group();
box(medical, [4.8, 2.7, 3.5], [0, 1.45, 0], "#f0e9d6");
box(medical, [5.4, 0.35, 4.1], [0, 3.0, 0], "#5ca797");
box(medical, [0.65, 1.65, 0.15], [0, 1.7, 1.82], "#df6458");
box(medical, [1.65, 0.65, 0.15], [0, 1.7, 1.82], "#df6458");
medical.position.set(-17, 0, 27);
eventStructures.add(medical);
registerPickable(medical, "operations");
const amenities = new THREE.Group();
for (const x of [-1.5, 1.5]) {
box(amenities, [2.3, 3.1, 2.7], [x, 1.65, 0], "#708b83");
box(amenities, [2.5, 0.3, 2.9], [x, 3.3, 0], "#f1e8d0");
box(amenities, [0.9, 1.2, 0.12], [x, 1.8, 1.4], "#25484d");
}
amenities.position.set(29, 0, 15);
eventStructures.add(amenities);
registerPickable(amenities, "amenities");
// Wayfinding labels.
addLabel("MAIN STAGE", [-27, 10, -5], 10, "#9c443a");
addLabel("FOOD + CRAFT", [-14, 7, 13], 11, "#9c443a");
addLabel("STEP-FREE ENTRY", [-12, 7.2, 28], 12, "#315c61");
addLabel("OPS · FIRST AID", [-24, 7.2, 23], 12, "#315c61");
addLabel("PUBLIC LOOP", [18, 6.5, 4], 11, "#176f67");
addLabel("2.4 M WORSHIP ACCESS", [6, 6.5, 11], 15, "#8b631c");
addLabel("PRIORITY CROSSING", [6, 5.8, 29], 12, "#50458d");
addLabel("MRT LINK", [-9, 5.5, 34], 9, "#176f67");
// ------------------------------------------------------------
// Voxel visitors
// ------------------------------------------------------------
let randomSeed = 4917;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const shirtColors = [
"#e77b66",
"#e9bc57",
"#3ba695",
"#7568aa",
"#4c7f96",
"#d9d1b8",
"#8e705c"
];
const skinColors = ["#d8a57b", "#bc805c", "#8f6046", "#efc7a0"];
function addPerson(x, z, rotation = 0) {
const group = new THREE.Group();
const shirt = shirtColors[Math.floor(random() * shirtColors.length)];
const skin = skinColors[Math.floor(random() * skinColors.length)];
box(group, [0.32, 0.56, 0.25], [0, 0.53, 0], shirt);
box(group, [0.27, 0.27, 0.27], [0, 0.96, 0], skin);
box(group, [0.1, 0.28, 0.12], [-0.1, 0.17, 0], "#304c50");
box(group, [0.1, 0.28, 0.12], [0.1, 0.17, 0], "#304c50");
group.position.set(x, 0.17, z);
group.rotation.y = rotation;
group.userData.baseY = group.position.y;
group.userData.phase = random();
group.userData.bob = 0.8 + random() * 1.2;
crowdGroup.add(group);
crowd.push(group);
}
const crowdSegments = [
[[-9, 3], [25, 3]],
[[25, 3], [25, 30]],
[[25, 30], [-9, 30]],
[[-9, 30], [-9, 3]],
[[-9, 30], [-9, 35]],
[[25, 30], [36, 30]]
];
for (let i = 0; i < 72; i++) {
const segment = crowdSegments[Math.floor(random() * crowdSegments.length)];
const t = random();
const x = segment[0][0] + (segment[1][0] - segment[0][0]) * t;
const z = segment[0][1] + (segment[1][1] - segment[0][1]) * t;
const jitterX = (random() - 0.5) * 0.9;
const jitterZ = (random() - 0.5) * 0.9;
addPerson(x + jitterX, z + jitterZ, random() * Math.PI * 2);
}
// Small queues remain beside the market, not in the worship corridor.
for (let i = 0; i < 16; i++) {
addPerson(-11.3 - random() * 1.2, 3 + random() * 19, Math.PI / 2);
}
// ------------------------------------------------------------
// Hotspot information
// ------------------------------------------------------------
const hotspotInfo = {
mosque: {
eyebrow: "Protected worship zone",
title: "Sultan Mosque frontage",
body:
"A quiet buffer is retained between the mosque and event activity. " +
"The event entrance, queues, stage, and food preparation remain outside this frontage.",
facts: ["Quiet buffer", "No event queue", "Stewarded crossings"]
},
worship: {
eyebrow: "Priority access",
title: "Designated worship approach",
body:
"The gold spine illustrates a continuous step-free route from the mosque entrance " +
"to the south curb. It is kept free of stalls, queues, and event structures.",
facts: ["2.4 m clear width", "Step-free", "Separate from queues"]
},
public: {
eyebrow: "Public circulation",
title: "Continuous pedestrian loop",
body:
"The teal loop connects the MRT direction, bus stop, market bays, stage, and " +
"amenities. Crossing points are marked where the public route meets worship access.",
facts: ["1.8 m marked route", "MRT linked", "Bus linked"]
},
stage: {
eyebrow: "Entertainment zone",
title: "Compact main stage",
body:
"The stage faces the market rather than the mosque. Audio is directed south, " +
"with an early finish and a monitored event boundary.",
facts: ["South-facing", "No mosque frontage", "Low-profile screens"]
},
stalls: {
eyebrow: "Market zone",
title: "Food and craft bays",
body:
"Six modular bays line the public route. Cooking extraction, waste handling, " +
"and delivery servicing occur from the western service edge.",
facts: ["6 modular bays", "Queue pockets", "Service access"]
},
craft: {
eyebrow: "Community zone",
title: "Craft and seating pods",
body:
"Low seating and demonstration pods occupy the interior of the public loop. " +
"The gold worship spine remains unobstructed.",
facts: ["Low-profile", "Inside loop", "Clear sightlines"]
},
entry: {
eyebrow: "Arrival control",
title: "Step-free event entry",
body:
"Entry screening is positioned at the south-west arrival point. A level route " +
"connects the public loop, MRT direction, and accessible drop-off.",
facts: ["Level access", "Bag check", "Two-way flow"]
},
operations: {
eyebrow: "Event operations",
title: "Operations and first aid",
body:
"A consolidated service compound holds first aid, event control, and staff " +
"rest space, reducing the number of separate support structures.",
facts: ["First aid", "Event control", "Staff area"]
},
amenities: {
eyebrow: "Amenities",
title: "Accessible toilets",
body:
"Toilet units sit on the eastern edge with direct access from the bus-linked " +
"side of the public loop.",
facts: ["East edge", "Loop access", "Away from worship route"]
},
crossing: {
eyebrow: "Conflict point",
title: "Priority crossing",
body:
"These locations require clear markings, slow speed, and event stewards during " +
"peak periods so the worship spine remains continuous.",
facts: ["Staffed at peak", "Yield signage", "Clear sightlines"]
}
};
function showInfo(id) {
const item = hotspotInfo[id] || hotspotInfo.public;
inspector.innerHTML = `
<span class="eyebrow">${item.eyebrow}</span>
<h2>${item.title}</h2>
<p>${item.body}</p>
<div class="inspector-facts">
${item.facts.map((fact) => `<span>${fact}</span>`).join("")}
</div>
`;
}
showInfo("public");
// ------------------------------------------------------------
// Time-of-day preview
// ------------------------------------------------------------
function crowdDensityAt(time) {
if (time < 17) return 0.08;
if (time < 19) return 0.12 + ((time - 17) / 2) * 0.24;
if (time < 21) return 0.42 + ((time - 19) / 2) * 0.38;
if (time < 21.75) return 0.8 - ((time - 21) / 0.75) * 0.35;
return Math.max(0.04, 0.45 - ((time - 21.75) / 0.25) * 0.41);
}
function phaseAt(time) {
if (time < 17) {
return {
name: "Setup",
occupancy: "Crew only",
density: crowdDensityAt(time)
};
}
if (time < 19) {
return {
name: "Soft opening",
occupancy: "Low occupancy",
density: crowdDensityAt(time)
};
}
if (time < 21) {
return {
name: "Market active",
occupancy: "Peak planning range",
density: crowdDensityAt(time)
};
}
if (time < 21.75) {
return {
name: "Wind-down",
occupancy: "Departing visitors",
density: crowdDensityAt(time)
};
}
return {
name: "Close",
occupancy: "Event staff",
density: crowdDensityAt(time)
};
}
function updateTime() {
const time = Number(timeSlider.value);
const hours = Math.floor(time);
const minutes = Math.round((time - hours) * 60);
const formatted = `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
const phase = phaseAt(time);
timeValue.textContent = formatted;
phaseName.textContent = phase.name;
occupancyLabel.textContent = phase.occupancy;
crowd.forEach((person) => {
person.visible = person.userData.phase <= phase.density;
});
const daylight = THREE.MathUtils.clamp(
1 - Math.max(0, time - 19) * 0.16,
0.7,
1
);
sun.intensity = 3.2 * daylight;
hemisphere.intensity = 2.25 * daylight;
renderer.toneMappingExposure = 0.96 + daylight * 0.17;
}
timeSlider.addEventListener("input", updateTime);
updateTime();
// ------------------------------------------------------------
// Layer controls and camera focus shortcuts
// ------------------------------------------------------------
document.querySelectorAll("[data-layer]").forEach((input) => {
input.addEventListener("change", () => {
const layer = input.dataset.layer;
if (layer === "public") routePublic.visible = input.checked;
if (layer === "worship") routeWorship.visible = input.checked;
if (layer === "zones") eventZones.visible = input.checked;
});
});
const focusViews = {
public: {
target: new THREE.Vector3(7, 0, 16),
radius: 70,
theta: 0.78,
phi: 0.96
},
worship: {
target: new THREE.Vector3(6, 0, 10),
radius: 60,
theta: 0.24,
phi: 1.12
},
event: {
target: new THREE.Vector3(-17, 0, 10),
radius: 65,
theta: 0.86,
phi: 1.02
}
};
document.querySelectorAll("[data-focus]").forEach((button) => {
button.addEventListener("click", () => {
const view = focusViews[button.dataset.focus];
cameraState.goalTarget.copy(view.target);
cameraState.goalRadius = view.radius;
cameraState.goalTheta = view.theta;
cameraState.goalPhi = view.phi;
});
});
// ------------------------------------------------------------
// Custom orbit, pan, zoom, picking, and keyboard controls
// ------------------------------------------------------------
const pointer = {
active: false,
x: 0,
y: 0,
startX: 0,
startY: 0,
distance: 0,
button: 0
};
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.goalTarget.set(0, 0, 0);
cameraState.goalRadius = 86;
cameraState.goalTheta = 0.78;
cameraState.goalPhi = 0.96;
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.startX = event.clientX;
pointer.startY = event.clientY;
pointer.distance = 0;
pointer.button = event.button;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.distance += Math.abs(dx) + Math.abs(dy);
if (event.button === 2 || event.shiftKey) {
const scale = cameraState.radius * 0.0015;
const direction = new THREE.Vector3();
camera.getWorldDirection(direction);
const right = new THREE.Vector3()
.crossVectors(direction, camera.up)
.normalize();
const forward = new THREE.Vector3()
.crossVectors(right, camera.up)
.normalize();
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
cameraState.goalTarget.copy(cameraState.target);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.28,
1.43
);
cameraState.goalTheta = cameraState.theta;
cameraState.goalPhi = cameraState.phi;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick = pointer.distance < 6;
pointer.active = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (!wasClick) return;
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const intersections = raycaster.intersectObjects(pickables, true);
if (intersections.length) {
const id = intersections[0].object.userData.pickId;
if (id) showInfo(id);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.active = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.055,
28,
125
);
cameraState.goalRadius = cameraState.radius;
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (["INPUT", "TEXTAREA", "SELECT"].includes(document.activeElement?.tagName)) {
return;
}
if (event.key === "ArrowLeft") cameraState.theta -= 0.08;
if (event.key === "ArrowRight") cameraState.theta += 0.08;
if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.28, cameraState.phi - 0.06);
}
if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.43, cameraState.phi + 0.06);
}
if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(28, cameraState.radius - 4);
}
if (event.key === "-" || event.key === "_") {
cameraState.radius = Math.min(125, cameraState.radius + 4);
}
if (event.key.toLowerCase() === "r") resetCamera();
cameraState.goalTheta = cameraState.theta;
cameraState.goalPhi = cameraState.phi;
cameraState.goalRadius = cameraState.radius;
});
// ------------------------------------------------------------
// Animation and resize
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
cameraState.target.lerp(cameraState.goalTarget, 0.075);
cameraState.radius += (cameraState.goalRadius - cameraState.radius) * 0.075;
cameraState.theta += (cameraState.goalTheta - cameraState.theta) * 0.075;
cameraState.phi += (cameraState.goalPhi - cameraState.phi) * 0.075;
updateCamera();
routeMaterials.forEach((material, index) => {
const baseOpacity = index % 2 === 0 ? 0.68 : 0.92;
material.opacity =
baseOpacity + Math.sin(elapsed * 1.8 + index * 0.4) * 0.08;
});
crowd.forEach((person) => {
if (!person.visible) return;
const wave = Math.sin(elapsed * person.userData.bob + person.userData.phase * 8);
person.position.y = person.userData.baseY + wave * 0.025;
});
animatedFoliage.forEach((tree, index) => {
tree.rotation.z = Math.sin(elapsed * 0.65 + index) * 0.004;
});
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
animate();
</script>
</body>
</html>
```