Prompt specification
Build or customize the Three.js 3D scene "Plan an evening cultural walking circuit" 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: Plan an evening cultural walking circuit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/plan-an-evening-cultural-walking-circuit-x2792
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Bellavista at the foot of Santiago's hills. Let users select a few fictional venues in the modeled block. Trace a connected walking route and keep lighting changes separate from the underlying spatial task. Voxel style.
Working Three.js Starter (plan-an-evening-cultural-walking-circuit-x2792):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bellavista — Hillside Walks</title>
<style>
:root {
--ink: #172a36;
--muted: #64747b;
--paper: rgba(255, 252, 244, 0.95);
--line: rgba(23, 42, 54, 0.13);
--accent: #e55e48;
--accent-dark: #b83e31;
--teal: #237b78;
--navy: rgba(20, 37, 51, 0.94);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #a8d6e7;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
#scene:focus-visible {
outline: 3px solid rgba(255, 255, 255, 0.9);
outline-offset: -5px;
}
.topbar {
position: fixed;
z-index: 20;
top: 0;
left: 0;
right: 0;
height: 78px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
color: #153241;
pointer-events: none;
background: linear-gradient(
to bottom,
rgba(255, 255, 255, 0.6),
rgba(255, 255, 255, 0)
);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
text-shadow: 0 1px 8px rgba(255, 255, 255, 0.5);
}
.brand-mark {
width: 38px;
height: 38px;
border: 2px solid currentColor;
border-radius: 11px 11px 11px 3px;
display: grid;
place-items: center;
font-size: 20px;
font-weight: 800;
transform: rotate(-4deg);
}
.brand-copy {
display: grid;
gap: 2px;
}
.brand-copy strong {
font-size: 15px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand-copy span {
font-size: 12px;
letter-spacing: 0.06em;
opacity: 0.76;
}
.top-actions {
display: flex;
gap: 8px;
pointer-events: auto;
}
.top-button {
border: 1px solid rgba(23, 42, 54, 0.16);
background: rgba(255, 255, 255, 0.78);
color: var(--ink);
border-radius: 999px;
padding: 9px 13px;
font-size: 12px;
font-weight: 700;
box-shadow: 0 5px 18px rgba(31, 54, 65, 0.08);
backdrop-filter: blur(12px);
}
#light-toggle {
display: none;
}
.panel {
position: fixed;
z-index: 15;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(25, 44, 53, 0.18);
backdrop-filter: blur(16px);
}
.task-panel {
top: 94px;
left: 22px;
width: 342px;
max-height: calc(100vh - 116px);
overflow: auto;
padding: 21px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.layer-badge {
padding: 4px 7px;
color: var(--teal);
background: rgba(35, 123, 120, 0.09);
border-radius: 999px;
letter-spacing: 0.08em;
}
h1 {
margin: 0;
font-size: 28px;
line-height: 1.04;
letter-spacing: -0.035em;
}
.intro {
margin: 11px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 17px 0 9px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#selection-count {
color: var(--muted);
font-weight: 600;
letter-spacing: 0;
text-transform: none;
}
.venue-list {
display: grid;
gap: 7px;
}
.venue-row {
position: relative;
display: grid;
grid-template-columns: 19px 1fr 20px;
align-items: center;
gap: 9px;
min-height: 52px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.6);
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.venue-row:hover {
transform: translateY(-1px);
border-color: rgba(35, 123, 120, 0.4);
}
.venue-row.selected {
background: rgba(35, 123, 120, 0.08);
border-color: rgba(35, 123, 120, 0.4);
}
.venue-row input {
width: 17px;
height: 17px;
margin: 0;
accent-color: var(--teal);
cursor: pointer;
}
.venue-name {
min-width: 0;
}
.venue-name strong,
.venue-name small {
display: block;
}
.venue-name strong {
overflow: hidden;
font-size: 13px;
text-overflow: ellipsis;
white-space: nowrap;
}
.venue-name small {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.02em;
}
.venue-swatch {
width: 9px;
height: 9px;
margin-right: 2px;
border-radius: 2px;
display: inline-block;
vertical-align: 1px;
}
.plus {
width: 20px;
height: 20px;
border-radius: 6px;
display: grid;
place-items: center;
color: var(--muted);
background: rgba(23, 42, 54, 0.06);
font-size: 16px;
line-height: 1;
}
.selected .plus {
color: white;
background: var(--teal);
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 16px;
}
.primary,
.secondary {
min-height: 43px;
border-radius: 11px;
padding: 0 14px;
font-size: 12px;
font-weight: 800;
}
.primary {
border: 0;
color: white;
background: var(--accent);
box-shadow: 0 8px 18px rgba(229, 94, 72, 0.25);
}
.primary:hover:not(:disabled) {
background: var(--accent-dark);
}
.primary:disabled {
cursor: not-allowed;
opacity: 0.42;
box-shadow: none;
}
.secondary {
border: 1px solid var(--line);
color: var(--muted);
background: transparent;
}
.secondary:hover {
background: rgba(23, 42, 54, 0.05);
}
.route-card {
margin-top: 14px;
padding: 13px;
border-radius: 13px;
background: rgba(23, 42, 54, 0.055);
border: 1px solid var(--line);
}
.route-card.ready {
background: rgba(229, 94, 72, 0.08);
border-color: rgba(229, 94, 72, 0.22);
}
.route-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
}
.route-heading strong {
font-size: 13px;
}
#route-distance {
color: var(--accent-dark);
font-size: 18px;
font-weight: 850;
letter-spacing: -0.03em;
}
#route-status {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#route-order {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 10px;
}
.stop-chip {
display: inline-flex;
align-items: center;
gap: 5px;
max-width: 100%;
padding: 5px 7px;
border-radius: 7px;
color: var(--ink);
background: rgba(255, 255, 255, 0.78);
font-size: 9px;
font-weight: 700;
}
.stop-chip b {
width: 16px;
height: 16px;
border-radius: 5px;
display: grid;
place-items: center;
color: white;
background: var(--accent);
font-size: 9px;
}
.light-panel {
top: 94px;
right: 22px;
width: 278px;
padding: 19px;
color: #edf6f7;
background: var(--navy);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.light-panel .eyebrow {
color: #f59a83;
}
.light-panel .layer-badge {
color: #a5d9d5;
background: rgba(165, 217, 213, 0.1);
}
.light-panel h2 {
margin: 0;
font-size: 21px;
letter-spacing: -0.025em;
}
.light-copy {
margin: 7px 0 14px;
color: #afc0c8;
font-size: 11px;
line-height: 1.45;
}
.preset-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.preset {
min-height: 48px;
padding: 6px 4px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
color: #c8d5da;
background: rgba(255, 255, 255, 0.045);
font-size: 10px;
font-weight: 700;
}
.preset span {
display: block;
margin-bottom: 4px;
font-size: 17px;
}
.preset.active {
color: white;
border-color: rgba(245, 154, 131, 0.55);
background: rgba(245, 154, 131, 0.13);
}
.control {
margin-top: 15px;
}
.control label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #c8d5da;
font-size: 10px;
font-weight: 650;
}
.control output {
color: #f3a089;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 999px;
appearance: none;
background: rgba(255, 255, 255, 0.16);
accent-color: #f08b70;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 2px solid #f9a48d;
border-radius: 50%;
appearance: none;
background: #203a4b;
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #f9a48d;
border-radius: 50%;
background: #203a4b;
cursor: pointer;
}
.shadow-toggle {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 17px;
color: #c8d5da;
font-size: 11px;
}
.shadow-toggle input {
width: 17px;
height: 17px;
accent-color: #f08b70;
}
.separation-note {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
color: #91a7b0;
font-size: 10px;
line-height: 1.45;
}
#label-layer {
position: fixed;
z-index: 8;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.venue-label {
position: absolute;
min-width: 100px;
max-width: 170px;
padding: 7px 9px 7px 8px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 9px;
color: #1b3542;
background: rgba(255, 253, 247, 0.92);
box-shadow: 0 7px 20px rgba(22, 42, 51, 0.16);
pointer-events: auto;
text-align: left;
transform: translate(-50%, -100%);
transition:
background 150ms ease,
border-color 150ms ease,
box-shadow 150ms ease;
}
.venue-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 9px;
height: 9px;
border-right: 1px solid rgba(255, 255, 255, 0.82);
border-bottom: 1px solid rgba(255, 255, 255, 0.82);
background: rgba(255, 253, 247, 0.92);
transform: translateX(-50%) rotate(45deg);
}
.venue-label strong {
display: block;
overflow: hidden;
font-size: 10px;
line-height: 1.15;
text-overflow: ellipsis;
white-space: nowrap;
}
.venue-label small {
display: block;
margin-top: 3px;
color: #708088;
font-size: 8px;
}
.venue-label.selected {
border-color: rgba(35, 123, 120, 0.62);
background: rgba(236, 251, 247, 0.96);
box-shadow:
0 8px 22px rgba(22, 42, 51, 0.18),
0 0 0 2px rgba(35, 123, 120, 0.12);
}
.stop-index {
position: absolute;
top: -8px;
left: -8px;
width: 20px;
height: 20px;
border-radius: 6px;
display: none;
place-items: center;
color: white;
background: var(--accent);
font-size: 10px;
font-weight: 850;
box-shadow: 0 4px 10px rgba(229, 94, 72, 0.3);
}
.venue-label.routed .stop-index {
display: grid;
}
.legend {
position: fixed;
z-index: 10;
left: 50%;
bottom: 21px;
display: flex;
align-items: center;
gap: 14px;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 999px;
color: #314c58;
background: rgba(255, 255, 255, 0.8);
box-shadow: 0 8px 25px rgba(22, 42, 51, 0.12);
backdrop-filter: blur(12px);
transform: translateX(-50%);
pointer-events: none;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.03em;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.legend-line {
width: 24px;
border-top: 4px dotted var(--accent);
}
.legend-square {
width: 10px;
height: 10px;
border: 2px solid var(--teal);
border-radius: 2px;
}
.legend-hill {
width: 15px;
height: 9px;
border-radius: 2px 2px 0 0;
background: #718d70;
}
.controls-hint {
position: fixed;
z-index: 10;
right: 24px;
bottom: 21px;
color: rgba(25, 47, 57, 0.72);
font-size: 9px;
font-weight: 700;
pointer-events: none;
text-shadow: 0 1px 5px white;
}
.compass {
position: fixed;
z-index: 9;
right: 25px;
top: 88px;
width: 45px;
height: 45px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 50%;
display: grid;
place-items: center;
color: #183a49;
background: rgba(255, 255, 255, 0.65);
box-shadow: 0 5px 16px rgba(22, 42, 51, 0.11);
pointer-events: none;
font-size: 10px;
font-weight: 850;
}
.compass::before {
content: "";
position: absolute;
top: 5px;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 9px solid var(--accent);
}
#toast {
position: fixed;
z-index: 30;
left: 50%;
top: 86px;
padding: 10px 14px;
border-radius: 10px;
color: white;
background: rgba(20, 37, 51, 0.92);
box-shadow: 0 8px 25px rgba(22, 42, 51, 0.2);
transform: translate(-50%, -15px);
opacity: 0;
pointer-events: none;
transition: 180ms ease;
font-size: 11px;
font-weight: 700;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
color: #173b4b;
background: #a8d6e7;
transition: opacity 300ms ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
.loading-card {
padding: 20px 25px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 15px;
background: rgba(255, 255, 255, 0.74);
box-shadow: 0 14px 40px rgba(25, 49, 60, 0.14);
text-align: center;
font-size: 12px;
font-weight: 750;
}
.loading-card span {
display: block;
margin-top: 5px;
color: #66808a;
font-size: 10px;
font-weight: 500;
}
@media (max-width: 900px) {
.topbar {
height: 66px;
padding: 0 13px;
}
.brand-copy strong {
font-size: 12px;
}
.brand-copy span {
display: none;
}
.brand-mark {
width: 33px;
height: 33px;
border-radius: 9px 9px 9px 3px;
}
#light-toggle {
display: inline-block;
}
#reset-view {
display: none;
}
.task-panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 45vh;
padding: 16px;
border-radius: 17px;
}
.task-panel h1 {
font-size: 23px;
}
.intro {
margin-bottom: 11px;
}
.venue-list {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.venue-row {
min-height: 47px;
}
.venue-name small {
display: none;
}
.light-panel {
top: 72px;
right: 10px;
width: min(320px, calc(100vw - 20px));
display: none;
}
body.lights-open .light-panel {
display: block;
}
.legend,
.controls-hint,
.compass {
display: none;
}
.venue-label {
min-width: 82px;
max-width: 130px;
padding: 5px 7px;
}
.venue-label strong {
font-size: 9px;
}
.venue-label small {
display: none;
}
}
@media (max-width: 520px) {
.top-button {
padding: 8px 10px;
font-size: 10px;
}
.venue-list {
grid-template-columns: 1fr;
}
.venue-name small {
display: block;
}
.route-card {
padding: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0" aria-label="Interactive voxel map of Bellavista"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">B</div>
<div class="brand-copy">
<strong>Bellavista</strong>
<span>Foot of Santiago’s hills · schematic walk finder</span>
</div>
</div>
<div class="top-actions">
<button class="top-button" id="reset-view" type="button">Reset view</button>
<button class="top-button" id="light-toggle" type="button" aria-expanded="false">
Lighting
</button>
</div>
</header>
<aside class="panel task-panel" aria-label="Walking route task">
<div class="eyebrow">
<span>Spatial task</span>
<span class="layer-badge">Route layer</span>
</div>
<h1>A few places,<br>one continuous walk.</h1>
<p class="intro">
Select two to five fictional venues. The route is optimized over the
connected street graph, including the Mirador passage.
</p>
<div class="section-title">
<span>Choose venues</span>
<span id="selection-count">0 of 5 selected</span>
</div>
<div class="venue-list" id="venue-list"></div>
<div class="actions">
<button class="primary" id="trace-route" type="button" disabled>
Trace connected walk
</button>
<button class="secondary" id="clear-route" type="button">Clear</button>
</div>
<div class="route-card" id="route-card" aria-live="polite">
<div class="route-heading">
<strong>Walk estimate</strong>
<span id="route-distance">—</span>
</div>
<p id="route-status">
Choose at least two venues to trace a connected walking route.
</p>
<div id="route-order"></div>
</div>
</aside>
<aside class="panel light-panel" aria-label="Scene lighting controls">
<div class="eyebrow">
<span>Scene lighting</span>
<span class="layer-badge">Independent</span>
</div>
<h2>Change the atmosphere.</h2>
<p class="light-copy">
Lighting changes only the scene’s sun, sky, shadows, and windows.
It does not alter the route graph, venue selection, or walking order.
</p>
<div class="preset-grid">
<button class="preset active" type="button" data-preset="day">
<span>☀</span>Clear day
</button>
<button class="preset" type="button" data-preset="amber">
<span>◒</span>Amber
</button>
<button class="preset" type="button" data-preset="blue">
<span>☾</span>Blue hour
</button>
</div>
<div class="control">
<label for="sun-azimuth">
Sun azimuth <output id="sun-azimuth-value">−45°</output>
</label>
<input id="sun-azimuth" type="range" min="-180" max="180" step="1" value="-45">
</div>
<div class="control">
<label for="sun-elevation">
Sun elevation <output id="sun-elevation-value">48°</output>
</label>
<input id="sun-elevation" type="range" min="8" max="72" step="1" value="48">
</div>
<div class="control">
<label for="sun-intensity">
Sun intensity <output id="sun-intensity-value">2.4</output>
</label>
<input id="sun-intensity" type="range" min="0" max="4" step="0.1" value="2.4">
</div>
<label class="shadow-toggle">
<span>Cast scene shadows</span>
<input id="shadows" type="checkbox" checked>
</label>
<div class="separation-note">
Spatial layer: venues + street graph + route.<br>
Presentation layer: light only.
</div>
</aside>
<div id="label-layer"></div>
<div class="compass" aria-hidden="true">N</div>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="legend-line"></span>Walking route</div>
<div class="legend-item"><span class="legend-square"></span>Selected venue</div>
<div class="legend-item"><span class="legend-hill"></span>Cerro foothills</div>
</div>
<div class="controls-hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom · Double-click to reset
</div>
<div id="toast" role="status"></div>
<div id="loading">
<div class="loading-card">
Building the Bellavista block…
<span>Assembling streets, venues, and foothills</span>
</div>
</div>
<noscript>This interactive map requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const venueListElement = document.querySelector("#venue-list");
const traceButton = document.querySelector("#trace-route");
const clearButton = document.querySelector("#clear-route");
const selectionCount = document.querySelector("#selection-count");
const routeCard = document.querySelector("#route-card");
const routeDistance = document.querySelector("#route-distance");
const routeStatus = document.querySelector("#route-status");
const routeOrder = document.querySelector("#route-order");
const labelLayer = document.querySelector("#label-layer");
const toastElement = document.querySelector("#toast");
const lightToggle = document.querySelector("#light-toggle");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.7));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#a8d6e7");
scene.fog = new THREE.Fog("#a8d6e7", 185, 520);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
1200
);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
const materials = {
ground: material("#c8b995"),
groundEdge: material("#9c8b69"),
sidewalk: material("#d7cbb1"),
road: material("#55636a"),
promenade: material("#b7a27b"),
roof: material("#73594d"),
darkRoof: material("#4e4a48"),
trunk: material("#6d4d38"),
leafA: material("#57785e"),
leafB: material("#6f8d67"),
leafC: material("#456d5d"),
hillA: material("#789171"),
hillB: material("#6c876c"),
hillC: material("#5f7c68"),
mountainA: material("#738b95"),
mountainB: material("#607c88"),
mountainC: material("#526e7d"),
window: material("#fff0b6", {
emissive: "#ffc36f",
emissiveIntensity: 0.12,
roughness: 0.55
})
};
function makeBox(width, height, depth, x, y, z, mat, parent = scene) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function pathSegment(a, b, width, y, mat, parent = scene) {
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const mesh = makeBox(
width,
0.16,
length,
(a[0] + b[0]) / 2,
y,
(a[1] + b[1]) / 2,
mat,
parent
);
mesh.rotation.y = Math.atan2(dx, dz);
return mesh;
}
// ------------------------------------------------------------------
// Ground, streets, and the connected pedestrian graph
// ------------------------------------------------------------------
makeBox(700, 3, 430, 0, -7, -170, materials.groundEdge);
makeBox(280, 4, 230, 0, -2, 15, materials.ground);
const horizontalRoads = [-50, 10, 70];
const verticalRoads = [-90, -30, 30, 90];
for (const z of horizontalRoads) {
makeBox(220, 0.28, 14, 0, 0.12, z, materials.sidewalk);
makeBox(220, 0.18, 10, 0, 0.18, z, materials.road);
}
for (const x of verticalRoads) {
makeBox(14, 0.28, 140, x, 0.12, 10, materials.sidewalk);
makeBox(10, 0.18, 140, x, 0.18, 10, materials.road);
}
// The Mirador passage cuts diagonally across one city block.
pathSegment([30, -50], [-30, 10], 4.4, 0.34, materials.promenade);
const graphNodes = {
A: [-90, -50],
B: [-30, -50],
C: [30, -50],
D: [90, -50],
E: [-90, 10],
F: [-30, 10],
G: [30, 10],
H: [90, 10],
I: [-90, 70],
J: [-30, 70],
K: [30, 70],
L: [90, 70]
};
const venues = [
{
id: "patio",
name: "Patio Cobalto",
note: "fictional courtyard café",
node: "B",
access: [-40, -34],
building: [-40, -40],
color: "#c86852",
height: 13
},
{
id: "estudio",
name: "Estudio Ladera",
note: "fictional print workshop",
node: "C",
access: [40, -34],
building: [40, -40],
color: "#c49a43",
height: 15
},
{
id: "sombra",
name: "Sombra Café",
note: "fictional neighborhood café",
node: "F",
access: [-40, 26],
building: [-40, 20],
color: "#287c78",
height: 12
},
{
id: "trama",
name: "Casa Trama",
note: "fictional weaving studio",
node: "G",
access: [40, 26],
building: [40, 20],
color: "#b96578",
height: 14
},
{
id: "fermat",
name: "Mercado Fermat",
note: "fictional market hall",
node: "J",
access: [-42, 52],
building: [-42, 46],
color: "#547c92",
height: 16
},
{
id: "chispa",
name: "Teatro Chispa",
note: "fictional pocket theater",
node: "K",
access: [42, 52],
building: [42, 46],
color: "#a65b45",
height: 15
}
];
const graphEdges = [
["A", "B"], ["B", "C"], ["C", "D"],
["E", "F"], ["F", "G"], ["G", "H"],
["I", "J"], ["J", "K"], ["K", "L"],
["A", "E"], ["B", "F"], ["C", "G"], ["D", "H"],
["E", "I"], ["F", "J"], ["G", "K"], ["H", "L"],
["C", "F"]
];
// Add a short access spur from each street intersection to its venue door.
for (const venue of venues) {
graphNodes[`v-${venue.id}`] = venue.access;
graphEdges.push([venue.node, `v-${venue.id}`]);
pathSegment(
graphNodes[venue.node],
venue.access,
3.1,
0.35,
materials.promenade
);
}
const adjacency = new Map();
function addGraphEdge(a, b) {
const pa = graphNodes[a];
const pb = graphNodes[b];
const weight = Math.hypot(pb[0] - pa[0], pb[1] - pa[1]);
if (!adjacency.has(a)) adjacency.set(a, []);
if (!adjacency.has(b)) adjacency.set(b, []);
adjacency.get(a).push({ node: b, weight });
adjacency.get(b).push({ node: a, weight });
}
for (const [a, b] of graphEdges) addGraphEdge(a, b);
// ------------------------------------------------------------------
// Voxel buildings
// ------------------------------------------------------------------
let randomSeed = 2841;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const buildingPalette = [
"#d9c3a0",
"#bd7c68",
"#789494",
"#d3a754",
"#a86c79",
"#cabfa7",
"#688879"
];
function createBuilding(cx, cz, width, depth, height, color, isVenue = false) {
const bodyMaterial = material(color);
const body = makeBox(
width,
height,
depth,
cx,
height / 2 + 0.25,
cz,
bodyMaterial
);
makeBox(
width + 0.8,
0.75,
depth + 0.8,
cx,
height + 0.55,
cz,
isVenue ? materials.roof : materials.darkRoof
);
const floors = Math.max(2, Math.floor(height / 4));
const columns = Math.max(2, Math.floor(width / 5));
for (let floor = 0; floor < floors; floor++) {
for (let column = 0; column < columns; column++) {
const wx = cx - width / 2 + 3.5 + column * ((width - 7) / Math.max(1, columns - 1));
const wy = 3.3 + floor * 3.5;
if (wy + 0.8 < height) {
const windowMesh = makeBox(
1.6,
1.65,
0.12,
wx,
wy,
cz + depth / 2 + 0.08,
materials.window
);
windowMesh.castShadow = false;
}
}
}
makeBox(
2.4,
3.1,
0.18,
cx + width * 0.22,
1.8,
cz + depth / 2 + 0.12,
materials.darkRoof
);
if (isVenue) {
makeBox(
width * 0.72,
1.25,
0.22,
cx,
height - 1.5,
cz + depth / 2 + 0.13,
material("#fff1cd")
);
makeBox(
width * 0.82,
0.45,
1.8,
cx,
3.5,
cz + depth / 2 + 0.7,
material(color, { roughness: 0.72 })
);
}
return body;
}
const plotCenters = [-60, 0, 60];
const plotRows = [-20, 40];
const genericPositions = [
[-18, -12],
[16, -11],
[-15, 17],
[18, 16]
];
for (const cx of plotCenters) {
for (const cz of plotRows) {
for (const [ox, oz] of genericPositions) {
const x = cx + ox;
const z = cz + oz;
const nearVenue = venues.some(
venue =>
Math.hypot(
x - venue.building[0],
z - venue.building[1]
) < 24
);
// Keep the Mirador passage clear.
const nearPassage = Math.abs(x + z + 20) < 9;
if (nearVenue || nearPassage) continue;
const width = 10 + random() * 7;
const depth = 10 + random() * 7;
const height = 8 + random() * 13;
const color = buildingPalette[Math.floor(random() * buildingPalette.length)];
createBuilding(x, z, width, depth, height, color);
}
}
}
for (const venue of venues) {
createBuilding(
venue.building[0],
venue.building[1],
15,
12,
venue.height,
venue.color,
true
);
}
function createTree(x, z, scale = 1) {
makeBox(
1.1 * scale,
4.8 * scale,
1.1 * scale,
x,
2.5 * scale,
z,
materials.trunk
);
const leaf = [materials.leafA, materials.leafB, materials.leafC][
Math.floor(random() * 3)
];
makeBox(
5.8 * scale,
5.4 * scale,
5.8 * scale,
x,
6.6 * scale,
z,
leaf
);
makeBox(
4.1 * scale,
3.7 * scale,
4.3 * scale,
x + 0.8 * scale,
9.1 * scale,
z - 0.4 * scale,
leaf
);
}
const treePositions = [
[-82, -30], [-82, 35], [-42, -28], [40, -28],
[82, -30], [82, 35], [-42, 34], [40, 35],
[-82, 82], [-42, 82], [40, 82], [82, 82],
[-76, -76], [-10, -78], [68, -78]
];
for (const [x, z] of treePositions) createTree(x, z, 0.72 + random() * 0.18);
// ------------------------------------------------------------------
// Stepped Santiago foothills and distant block-like mountains
// ------------------------------------------------------------------
for (let layer = 0; layer < 6; layer++) {
const height = 9 + layer * 9;
const depth = 28;
const z = -101 - layer * 25;
const width = 435 - layer * 20;
const hillMaterial = [materials.hillA, materials.hillB, materials.hillC][layer % 3];
makeBox(
width,
height,
depth,
0,
height / 2,
z,
hillMaterial
);
}
for (let i = 0; i < 21; i++) {
const x = -260 + i * 26;
const baseHeight = 20 + random() * 38;
const width = 30 + random() * 19;
const z = -275 - random() * 35;
const mountainMaterial = [
materials.mountainA,
materials.mountainB,
materials.mountainC
][i % 3];
makeBox(
width,
baseHeight,
34 + random() * 20,
x,
baseHeight / 2 - 5,
z,
mountainMaterial
);
makeBox(
width * 0.62,
18 + random() * 20,
24,
x + 3,
baseHeight + 7,
z - 2,
mountainMaterial
);
}
// Small street lamps.
const lampMaterial = material("#3c4d52");
const lampGlow = material("#fff2bc", {
emissive: "#ffbf65",
emissiveIntensity: 0.7
});
for (const [x, z] of [
[-82, -50], [-18, -50], [82, -50],
[-82, 10], [82, 10], [-82, 70], [82, 70]
]) {
makeBox(0.45, 6.5, 0.45, x, 3.4, z, lampMaterial);
makeBox(1.6, 0.6, 1.1, x, 6.6, z, lampGlow);
}
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight("#d7efff", "#77664c", 1.45);
scene.add(hemisphere);
const ambient = new THREE.AmbientLight("#ffffff", 0.18);
scene.add(ambient);
const sun = new THREE.DirectionalLight("#fff1cd", 2.4);
sun.position.set(-120, 165, 150);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -180;
sun.shadow.camera.right = 180;
sun.shadow.camera.top = 180;
sun.shadow.camera.bottom = -180;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 520;
sun.shadow.bias = -0.0006;
scene.add(sun);
scene.add(sun.target);
const sunDiscMaterial = new THREE.MeshBasicMaterial({ color: "#fff1b8" });
const sunDisc = new THREE.Mesh(new THREE.SphereGeometry(10, 16, 12), sunDiscMaterial);
scene.add(sunDisc);
const lightingPresets = {
day: {
background: "#a8d6e7",
fog: "#a8d6e7",
sunColor: "#fff1cd",
hemiSky: "#d7efff",
hemiGround: "#77664c",
sunIntensity: 2.4,
hemiIntensity: 1.45,
ambientIntensity: 0.18,
elevation: 48,
azimuth: -45,
exposure: 1.05
},
amber: {
background: "#e8a074",
fog: "#e8a074",
sunColor: "#ffad61",
hemiSky: "#e8c5ba",
hemiGround: "#5a4437",
sunIntensity: 3.0,
hemiIntensity: 0.75,
ambientIntensity: 0.2,
elevation: 14,
azimuth: 112,
exposure: 0.98
},
blue: {
background: "#203653",
fog: "#203653",
sunColor: "#8caeff",
hemiSky: "#6988b8",
hemiGround: "#172438",
sunIntensity: 0.7,
hemiIntensity: 0.48,
ambientIntensity: 0.23,
elevation: 8,
azimuth: 158,
exposure: 0.88
}
};
const azimuthInput = document.querySelector("#sun-azimuth");
const elevationInput = document.querySelector("#sun-elevation");
const intensityInput = document.querySelector("#sun-intensity");
const shadowsInput = document.querySelector("#shadows");
function updateLightingReadouts() {
document.querySelector("#sun-azimuth-value").textContent =
`${Number(azimuthInput.value) < 0 ? "−" : ""}${Math.abs(azimuthInput.value)}°`;
document.querySelector("#sun-elevation-value").textContent =
`${elevationInput.value}°`;
document.querySelector("#sun-intensity-value").textContent =
Number(intensityInput.value).toFixed(1);
}
function applyLighting() {
const azimuth = THREE.MathUtils.degToRad(Number(azimuthInput.value));
const elevation = THREE.MathUtils.degToRad(Number(elevationInput.value));
const intensity = Number(intensityInput.value);
sun.color.set("#fff1cd");
sun.intensity = intensity;
const radius = 220;
sun.position.set(
Math.cos(elevation) * Math.sin(azimuth) * radius,
Math.sin(elevation) * radius + 16,
Math.cos(elevation) * Math.cos(azimuth) * radius
);
sunDisc.position.copy(sun.position).multiplyScalar(1.38);
sunDiscMaterial.color.set(intensity < 0.9 ? "#a9c4ff" : "#fff1b8");
const daylight = Math.max(0, Math.sin(elevation));
materials.window.emissiveIntensity = 0.08 + (1 - daylight) * 0.85;
renderer.shadowMap.enabled = shadowsInput.checked;
sun.castShadow = shadowsInput.checked;
renderer.toneMappingExposure = 0.88 + daylight * 0.2;
updateLightingReadouts();
}
function applyPreset(name) {
const preset = lightingPresets[name];
scene.background.set(preset.background);
scene.fog.color.set(preset.fog);
sun.color.set(preset.sunColor);
sun.intensity = preset.sunIntensity;
hemisphere.color.set(preset.hemiSky);
hemisphere.groundColor.set(preset.hemiGround);
hemisphere.intensity = preset.hemiIntensity;
ambient.intensity = preset.ambientIntensity;
azimuthInput.value = preset.azimuth;
elevationInput.value = preset.elevation;
intensityInput.value = preset.sunIntensity;
document.querySelectorAll(".preset").forEach(button => {
button.classList.toggle("active", button.dataset.preset === name);
});
applyLighting();
}
document.querySelectorAll(".preset").forEach(button => {
button.addEventListener("click", () => applyPreset(button.dataset.preset));
});
for (const input of [azimuthInput, elevationInput, intensityInput]) {
input.addEventListener("input", () => {
document.querySelectorAll(".preset").forEach(button => {
button.classList.remove("active");
});
applyLighting();
});
}
shadowsInput.addEventListener("change", applyLighting);
applyPreset("day");
// ------------------------------------------------------------------
// Venue labels and selection state
// ------------------------------------------------------------------
const selectedVenues = new Set();
const venueById = new Map(venues.map(venue => [venue.id, venue]));
function createSelectionMarker(x, z) {
const group = new THREE.Group();
const markerMaterial = new THREE.MeshBasicMaterial({ color: "#2bb3aa" });
const size = 7;
const thickness = 0.85;
makeBox(size, 0.25, thickness, x, 0.48, z - size / 2, markerMaterial, group);
makeBox(size, 0.25, thickness, x, 0.48, z + size / 2, markerMaterial, group);
makeBox(thickness, 0.25, size, x - size / 2, 0.48, z, markerMaterial, group);
makeBox(thickness, 0.25, size, x + size / 2, 0.48, z, markerMaterial, group);
group.visible = false;
scene.add(group);
return group;
}
for (const venue of venues) {
venue.marker = createSelectionMarker(venue.access[0], venue.access[1]);
const label = document.createElement("button");
label.className = "venue-label";
label.type = "button";
label.setAttribute("aria-label", `Select ${venue.name}`);
label.innerHTML = `
<span class="stop-index"></span>
<strong>${venue.name}</strong>
<small>${venue.note}</small>
`;
label.addEventListener("click", () => {
toggleVenue(venue.id);
});
labelLayer.appendChild(label);
venue.labelElement = label;
const row = document.createElement("label");
row.className = "venue-row";
row.innerHTML = `
<input type="checkbox" aria-label="Select ${venue.name}">
<span class="venue-name">
<strong>
<span class="venue-swatch" style="background:${venue.color}"></span>
${venue.name}
</strong>
<small>${venue.note}</small>
</span>
<span class="plus" aria-hidden="true">+</span>
`;
const checkbox = row.querySelector("input");
checkbox.addEventListener("change", () => {
if (checkbox.checked) {
if (selectedVenues.size >= 5) {
checkbox.checked = false;
showToast("Choose up to five venues for a compact walk.");
return;
}
selectedVenues.add(venue.id);
} else {
selectedVenues.delete(venue.id);
}
invalidateRoute();
syncSelectionUI();
});
venue.checkbox = checkbox;
venueListElement.appendChild(row);
}
function syncSelectionUI() {
selectionCount.textContent = `${selectedVenues.size} of 5 selected`;
traceButton.disabled = selectedVenues.size < 2;
for (const venue of venues) {
const selected = selectedVenues.has(venue.id);
venue.checkbox.checked = selected;
venue.marker.visible = selected;
venue.labelElement.classList.toggle("selected", selected);
venue.labelElement.setAttribute(
"aria-pressed",
selected ? "true" : "false"
);
}
}
function toggleVenue(id) {
if (selectedVenues.has(id)) {
selectedVenues.delete(id);
} else {
if (selectedVenues.size >= 5) {
showToast("Choose up to five venues for a compact walk.");
return;
}
selectedVenues.add(id);
}
invalidateRoute();
syncSelectionUI();
}
// ------------------------------------------------------------------
// Route solver: Dijkstra shortest paths + exact stop-order search
// ------------------------------------------------------------------
const shortestPathCache = new Map();
function dijkstra(start, end) {
const cacheKey = `${start}|${end}`;
if (shortestPathCache.has(cacheKey)) {
return shortestPathCache.get(cacheKey);
}
const distances = new Map();
const previous = new Map();
const unvisited = new Set(adjacency.keys());
for (const node of unvisited) distances.set(node, Infinity);
distances.set(start, 0);
while (unvisited.size) {
let current = null;
let currentDistance = Infinity;
for (const node of unvisited) {
const distance = distances.get(node);
if (distance < currentDistance) {
current = node;
currentDistance = distance;
}
}
if (current === null) break;
if (current === end) break;
unvisited.delete(current);
for (const edge of adjacency.get(current)) {
if (!unvisited.has(edge.node)) continue;
const alternative = currentDistance + edge.weight;
if (alternative < distances.get(edge.node)) {
distances.set(edge.node, alternative);
previous.set(edge.node, current);
}
}
}
const path = [];
let cursor = end;
if (!Number.isFinite(distances.get(end))) {
const result = { distance: Infinity, path: [] };
shortestPathCache.set(cacheKey, result);
return result;
}
while (cursor !== undefined) {
path.unshift(cursor);
if (cursor === start) break;
cursor = previous.get(cursor);
}
const result = { distance: distances.get(end), path };
shortestPathCache.set(cacheKey, result);
return result;
}
function permutations(items) {
if (items.length <= 1) return [items];
const output = [];
for (let index = 0; index < items.length; index++) {
const rest = [...items.slice(0, index), ...items.slice(index + 1)];
for (const permutation of permutations(rest)) {
output.push([items[index], ...permutation]);
}
}
return output;
}
function solveRoute() {
if (selectedVenues.size < 2) return;
const stopNodes = [...selectedVenues].map(id => `v-${id}`);
let bestOrder = null;
let bestDistance = Infinity;
for (const order of permutations(stopNodes)) {
let distance = 0;
let valid = true;
for (let index = 0; index < order.length - 1; index++) {
const leg = dijkstra(order[index], order[index + 1]);
if (!Number.isFinite(leg.distance)) {
valid = false;
break;
}
distance += leg.distance;
}
if (valid && distance < bestDistance) {
bestDistance = distance;
bestOrder = order;
}
}
if (!bestOrder) {
showToast("No connected route could be found.");
return;
}
const paths = [];
for (let index = 0; index < bestOrder.length - 1; index++) {
paths.push(dijkstra(bestOrder[index], bestOrder[index + 1]).path);
}
drawRoute(paths, bestOrder, bestDistance);
updateRouteSummary(bestOrder, bestDistance);
}
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeMaterial = new THREE.MeshBasicMaterial({
color: "#ff5e4a",
transparent: true,
opacity: 0.97
});
const routeLineMaterial = new THREE.LineBasicMaterial({
color: "#ff5e4a",
transparent: true,
opacity: 0.78
});
function drawRoute(paths, order, distance) {
routeGroup.clear();
const points = [];
for (const path of paths) {
for (const node of path) {
const point = graphNodes[node];
points.push(new THREE.Vector3(point[0], 0.66, point[1]));
}
}
const deduplicated = points.filter((point, index) => {
if (index === 0) return true;
return point.distanceToSquared(points[index - 1]) > 0.01;
});
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(deduplicated),
routeLineMaterial
);
routeGroup.add(line);
let dashCount = 0;
for (let index = 0; index < deduplicated.length - 1; index++) {
dashCount += Math.max(
1,
Math.floor(deduplicated[index].distanceTo(deduplicated[index + 1]) / 7)
);
}
const dashMesh = new THREE.InstancedMesh(
unitBox,
routeMaterial,
dashCount
);
const dummy = new THREE.Object3D();
let instance = 0;
for (let index = 0; index < deduplicated.length - 1; index++) {
const a = deduplicated[index];
const b = deduplicated[index + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const count = Math.max(1, Math.floor(length / 7));
const angle = Math.atan2(dx, dz);
for (let dash = 0; dash < count; dash++) {
const t = (dash + 0.5) / count;
dummy.position.set(
THREE.MathUtils.lerp(a.x, b.x, t),
0.72,
THREE.MathUtils.lerp(a.z, b.z, t)
);
dummy.rotation.set(0, angle, 0);
dummy.scale.set(1.35, 0.34, Math.min(4.6, length / count * 0.7));
dummy.updateMatrix();
dashMesh.setMatrixAt(instance++, dummy.matrix);
}
}
dashMesh.instanceMatrix.needsUpdate = true;
routeGroup.add(dashMesh);
order.forEach((node, index) => {
const venueId = node.slice(2);
const venue = venueById.get(venueId);
const point = graphNodes[node];
makeBox(
4.6,
1.1,
4.6,
point[0],
0.8,
point[1],
routeMaterial,
routeGroup
);
makeBox(
2.1,
1.15,
2.1,
point[0],
1.65,
point[1],
new THREE.MeshBasicMaterial({ color: "#fff8e9" }),
routeGroup
);
venue.routeOrder = index + 1;
venue.labelElement.querySelector(".stop-index").textContent = index + 1;
venue.labelElement.classList.add("routed");
});
}
function updateRouteSummary(order, distance) {
const rounded = Math.round(distance / 10) * 10;
const minutes = Math.max(1, Math.ceil(distance / 75));
routeCard.classList.add("ready");
routeDistance.textContent = `${rounded} m`;
routeStatus.textContent =
`${order.length} stops · about ${minutes} min on foot · optimized continuous route`;
routeOrder.replaceChildren();
order.forEach((node, index) => {
const venue = venueById.get(node.slice(2));
const chip = document.createElement("span");
chip.className = "stop-chip";
chip.innerHTML = `<b>${index + 1}</b>${venue.name}`;
routeOrder.appendChild(chip);
});
}
function invalidateRoute() {
routeGroup.clear();
routeData = null;
for (const venue of venues) {
venue.routeOrder = null;
venue.labelElement.classList.remove("routed");
venue.labelElement.querySelector(".stop-index").textContent = "";
}
routeCard.classList.remove("ready");
routeDistance.textContent = "—";
routeOrder.replaceChildren();
if (selectedVenues.size < 2) {
routeStatus.textContent =
"Choose at least two venues to trace a connected walking route.";
} else {
routeStatus.textContent =
`${selectedVenues.size} venues selected. Ready to trace the route.`;
}
}
let routeData = null;
traceButton.addEventListener("click", () => {
solveRoute();
routeData = true;
});
clearButton.addEventListener("click", () => {
selectedVenues.clear();
invalidateRoute();
syncSelectionUI();
});
syncSelectionUI();
// ------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard, touch pinch
// ------------------------------------------------------------------
const cameraState = {
theta: 0.7,
phi: 1.03,
radius: 270,
target: new THREE.Vector3(0, 9, 3)
};
const desiredCamera = {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
};
function resetCamera() {
desiredCamera.theta = 0.7;
desiredCamera.phi = 1.03;
desiredCamera.radius = 270;
desiredCamera.target.set(0, 9, 3);
}
document.querySelector("#reset-view").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
const pointers = new Map();
const pointerModes = new Map();
let previousGesture = null;
function readGesture() {
const values = [...pointers.values()];
if (!values.length) return null;
const first = values[0];
const second = values[1];
return {
x: first.x,
y: first.y,
centerX: values.reduce((sum, point) => sum + point.x, 0) / values.length,
centerY: values.reduce((sum, point) => sum + point.y, 0) / values.length,
distance: second ? Math.hypot(second.x - first.x, second.y - first.y) : 0
};
}
function panCamera(dx, dy) {
const scale = desiredCamera.radius * 0.00125;
const theta = desiredCamera.theta;
const right = new THREE.Vector3(Math.cos(theta), 0, -Math.sin(theta));
const forward = new THREE.Vector3(-Math.sin(theta), 0, -Math.cos(theta));
desiredCamera.target.addScaledVector(right, -dx * scale);
desiredCamera.target.addScaledVector(forward, -dy * scale);
desiredCamera.target.x = THREE.MathUtils.clamp(desiredCamera.target.x, -150, 150);
desiredCamera.target.z = THREE.MathUtils.clamp(desiredCamera.target.z, -140, 130);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
pointerModes.set(
event.pointerId,
event.button === 2 || event.shiftKey ? "pan" : "orbit"
);
previousGesture = readGesture();
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
const gesture = readGesture();
if (!gesture || !previousGesture) return;
if (pointers.size >= 2) {
if (previousGesture.distance > 0 && gesture.distance > 0) {
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius *
(previousGesture.distance / gesture.distance),
120,
430
);
}
panCamera(
gesture.centerX - previousGesture.centerX,
gesture.centerY - previousGesture.centerY
);
} else {
const dx = gesture.x - previousGesture.x;
const dy = gesture.y - previousGesture.y;
if (pointerModes.get(event.pointerId) === "pan" || event.shiftKey) {
panCamera(dx, dy);
} else {
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.42,
1.43
);
}
}
previousGesture = gesture;
});
function endPointer(event) {
pointers.delete(event.pointerId);
pointerModes.delete(event.pointerId);
previousGesture = readGesture();
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
120,
430
);
},
{ passive: false }
);
canvas.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (["arrowleft", "arrowright", "arrowup", "arrowdown", "+", "=", "-"].includes(key)) {
event.preventDefault();
}
if (key === "arrowleft") desiredCamera.theta -= 0.12;
if (key === "arrowright") desiredCamera.theta += 0.12;
if (key === "arrowup") desiredCamera.phi = Math.max(0.42, desiredCamera.phi - 0.08);
if (key === "arrowdown") desiredCamera.phi = Math.min(1.43, desiredCamera.phi + 0.08);
if (key === "+" || key === "=") desiredCamera.radius = Math.max(120, desiredCamera.radius - 15);
if (key === "-") desiredCamera.radius = Math.min(430, desiredCamera.radius + 15);
if (key === "home") resetCamera();
});
function updateCamera() {
const smoothing = 0.12;
cameraState.theta += (desiredCamera.theta - cameraState.theta) * smoothing;
cameraState.phi += (desiredCamera.phi - cameraState.phi) * smoothing;
cameraState.radius += (desiredCamera.radius - cameraState.radius) * smoothing;
cameraState.target.lerp(desiredCamera.target, smoothing);
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);
}
// ------------------------------------------------------------------
// HTML labels projected directly from the Three.js camera
// ------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
for (const venue of venues) {
projected.set(
venue.building[0],
venue.height + 5.5,
venue.building[1]
);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
venue.labelElement.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
venue.labelElement.style.left = `${x}px`;
venue.labelElement.style.top = `${y}px`;
}
}
// ------------------------------------------------------------------
// UI feedback and resize
// ------------------------------------------------------------------
let toastTimer;
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.classList.remove("show");
}, 2600);
}
lightToggle.addEventListener("click", () => {
const open = document.body.classList.toggle("lights-open");
lightToggle.setAttribute("aria-expanded", open ? "true" : "false");
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.7));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Render loop.
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading").classList.add("hide");
}
}
animate();
</script>
</body>
</html>
```