Prompt specification
Build or customize the Three.js 3D scene "Chicago Riverwalk stair and water-edge bench" 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: Chicago Riverwalk stair and water-edge bench
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/chicago-riverwalk-stair-and-water-edge-bench-x2729
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: Chicago Riverwalk stair and water-edge bench. Build a referenced riverwalk fragment with descending steps, seating, and a retaining edge. Show the height difference between the upper street and lower waterfront path. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (chicago-riverwalk-stair-and-water-edge-bench-x2729):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#dce5e4">
<title>Chicago Riverwalk — Voxel Stair & Waterfront Bench</title>
<style>
:root {
--ink: #243034;
--muted: #617073;
--paper: rgba(250, 249, 244, 0.9);
--line: rgba(36, 48, 52, 0.15);
--accent: #bd623e;
--water: #3f8991;
--stone: #b9b5aa;
--street: #4b5557;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5e4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
user-select: none;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.62);
background: var(--paper);
box-shadow: 0 12px 32px rgba(38, 51, 52, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 3px;
background: var(--accent);
content: "";
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 0.98;
}
#intro p {
max-width: 340px;
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#controls {
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 4px;
}
button {
appearance: none;
min-height: 36px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 2px;
background: rgba(255, 255, 255, 0.62);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 720;
letter-spacing: 0.02em;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
background: #fff;
transform: translateY(-1px);
}
button[aria-pressed="false"] {
color: #8a9495;
}
#legend {
left: 22px;
bottom: 22px;
min-width: 270px;
padding: 13px 15px;
border-radius: 4px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
color: #4d5c5f;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.swatch {
width: 20px;
height: 8px;
border-radius: 1px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.upper {
background: var(--street);
}
.swatch.lower {
background: var(--stone);
}
.swatch.water {
background: var(--water);
}
.hint {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #778285;
font-size: 10px;
line-height: 1.5;
}
#scale-note {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 10;
max-width: 250px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 3px;
background: rgba(248, 248, 243, 0.72);
color: #687578;
font-size: 10px;
line-height: 1.45;
text-align: right;
backdrop-filter: blur(8px);
}
.scene-tag {
position: fixed;
z-index: 8;
min-width: 132px;
padding: 8px 10px;
border: 1px solid rgba(36, 48, 52, 0.16);
border-left: 3px solid var(--accent);
border-radius: 2px;
background: rgba(253, 251, 245, 0.92);
box-shadow: 0 8px 22px rgba(35, 47, 49, 0.14);
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 180ms ease;
}
.scene-tag strong {
display: block;
color: var(--ink);
font-size: 9px;
font-weight: 820;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.scene-tag span {
display: block;
margin-top: 3px;
color: var(--accent);
font-size: 12px;
font-weight: 800;
}
#lowerTag {
border-left-color: #547f7c;
}
#lowerTag span {
color: #547f7c;
}
#dropTag {
min-width: 105px;
border-left-color: #bd623e;
text-align: center;
}
#dropTag span {
font-size: 13px;
}
body.labels-off .scene-tag {
opacity: 0;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #dce5e4;
color: #516164;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.ready {
opacity: 0;
pointer-events: none;
}
.loading-mark {
display: grid;
gap: 12px;
justify-items: center;
}
.loading-mark::before {
width: 42px;
height: 42px;
border: 5px solid rgba(36, 48, 52, 0.12);
border-top-color: var(--accent);
content: "";
animation: spin 900ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 700px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#intro p {
display: none;
}
#controls {
top: auto;
right: 12px;
bottom: 12px;
}
#legend {
left: 12px;
bottom: 12px;
min-width: 0;
padding: 10px 12px;
}
.legend-row {
margin: 5px 0;
font-size: 9px;
}
.hint,
#scale-note {
display: none;
}
.scene-tag {
min-width: 108px;
padding: 6px 8px;
}
.scene-tag strong {
font-size: 8px;
}
.scene-tag span {
font-size: 10px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel model of a Chicago Riverwalk stair and waterfront bench"></main>
<section id="intro" class="panel">
<div class="eyebrow">Chicago Riverwalk · Voxel Study</div>
<h1>Stair to the Water</h1>
<p>
A fragment of the lower Riverwalk: stepped granite descent, upper-street retaining
wall, paved waterfront path, and a slatted bench facing the Chicago River.
</p>
</section>
<nav id="controls" class="panel" aria-label="Scene controls">
<button id="resetButton" type="button" title="Reset camera (R)">Reset view</button>
<button id="labelButton" type="button" aria-pressed="true" title="Toggle callouts (L)">
Callouts
</button>
</nav>
<aside id="legend" class="panel" aria-label="Scene legend">
<div class="legend-row"><span class="swatch upper"></span>Upper street</div>
<div class="legend-row"><span class="swatch lower"></span>Lower waterfront path</div>
<div class="legend-row"><span class="swatch water"></span>Chicago River</div>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
</aside>
<div id="scale-note">
Schematic vertical grades<br />
Upper street +9 ft · Lower path +2 ft
</div>
<div id="upperTag" class="scene-tag">
<strong>Upper street</strong>
<span>+9 ft</span>
</div>
<div id="lowerTag" class="scene-tag">
<strong>Lower waterfront</strong>
<span>+2 ft</span>
</div>
<div id="dropTag" class="scene-tag">
<strong>Grade change</strong>
<span>7 ft drop</span>
</div>
<div id="loading">
<div class="loading-mark">Building Riverwalk</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5e4);
scene.fog = new THREE.Fog(0xdce5e4, 32, 68);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Orbitable voxel Chicago Riverwalk scene. Drag to orbit, shift-drag to pan, and scroll to zoom."
);
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 120);
const view = {
theta: 2.47,
phi: 1.20,
radius: 28,
zoom: 1,
target: new THREE.Vector3(0, 1.45, 1.7)
};
const homeView = {
theta: 2.47,
phi: 1.20,
radius: 28,
zoom: 1,
target: new THREE.Vector3(0, 1.45, 1.7)
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
const offset = new THREE.Vector3(
Math.sin(view.theta) * sinPhi * view.radius,
Math.cos(view.phi) * view.radius,
Math.cos(view.theta) * sinPhi * view.radius
);
camera.position.copy(view.target).add(offset);
camera.lookAt(view.target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 1.15 ? 25 / aspect : 18;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xeef8f7, 0x756b5e, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedce, 3.0);
sun.position.set(-11, 19, -13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 58;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9d6dc, 0.85);
fill.position.set(13, 8, 12);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
...options
});
const mats = {
land: material(0x8f918a),
concrete: material(0xb4b0a5),
concreteLight: material(0xd0c8b8),
concreteDark: material(0x89877f),
seam: material(0x73756f),
curb: material(0xcfccbf),
asphalt: material(0x495254),
paint: material(0xe6d6a5),
whitePaint: material(0xe7e7dc),
metal: material(0x293437, { roughness: 0.5, metalness: 0.48 }),
metalLight: material(0x4c595a, { roughness: 0.45, metalness: 0.42 }),
wood: material(0x946441),
woodLight: material(0xb17b50),
soil: material(0x584c3d),
leaf: material(0x57745a),
leafLight: material(0x6c8768),
leafDark: material(0x405e49),
brick: material(0x9b6250),
grayBuilding: material(0xaaa79e),
tanBuilding: material(0xb4a68e),
blueBuilding: material(0x87999b),
window: material(0xcad9d3, {
emissive: 0x8fa8a4,
emissiveIntensity: 0.18,
roughness: 0.35
}),
lamp: material(0xffe7ad, {
emissive: 0xffc96c,
emissiveIntensity: 1.2
}),
dimension: material(0xbd623e, {
emissive: 0x7e2f1b,
emissiveIntensity: 0.16
}),
water: material(0x347d86, {
roughness: 0.26,
metalness: 0.16,
transparent: true,
opacity: 0.96
}),
waterDark: material(0x286c76, {
roughness: 0.32,
metalness: 0.12,
transparent: true,
opacity: 0.56
}),
waterLight: material(0xb0ded8, {
roughness: 0.25,
metalness: 0.08,
transparent: true,
opacity: 0.34,
depthWrite: false
})
};
function box(width, height, depth, x, y, z, mat, cast = true, receive = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
const WATER = -0.186;
const LOWER = 0.5;
const UPPER = 2.9;
const STAIR_WIDTH = 4.5;
const STAIR_DEPTH = 0.44;
const STAIR_RISE = (UPPER - LOWER) / 10;
// Lower land mass and the Chicago River.
box(24, 0.92, 17.25, 0, -0.46, 5.925, mats.land, false, true);
box(42, 0.28, 16, 0, WATER - 0.14, -10.72, mats.water, false, true);
// Raised street platform behind the retaining wall.
box(24, 2.38, 7.15, 0, 1.65, 8.125, mats.concreteDark, true, true);
box(24, 6.2, 0.12, 0, 2.84, 17.82, mats.concrete, true, true);
// Upper sidewalk and road.
box(24, 0.12, 1.95, 0, 2.86, 5.525, mats.concreteLight, false, true);
box(24, 0.13, 5.1, 0, 2.835, 9.05, mats.asphalt, false, true);
for (let x = -11; x <= 11; x += 3.1) {
box(1.65, 0.022, 0.1, x, 2.912, 9.12, mats.paint, false, false);
}
// Retaining wall, leaving the stair opening in the center.
const wallBottom = LOWER;
const wallHeight = UPPER - LOWER;
const wallCenterY = (UPPER + LOWER) / 2;
const leftWallWidth = 9.5;
const rightWallWidth = 9.5;
box(leftWallWidth, wallHeight, 0.3, -7.25, wallCenterY, 4.42, mats.concrete, true, true);
box(rightWallWidth, wallHeight, 0.3, 7.25, wallCenterY, 4.42, mats.concrete, true, true);
box(leftWallWidth + 0.08, 0.13, 0.46, -7.25, UPPER + 0.035, 4.38, mats.curb, true, true);
box(rightWallWidth + 0.08, 0.13, 0.46, 7.25, UPPER + 0.035, 4.38, mats.curb, true, true);
// Masonry joints emphasize the retaining edge.
for (let x = -11.5; x <= -2.7; x += 1.5) {
box(0.025, wallHeight - 0.12, 0.025, x, wallCenterY, 4.257, mats.seam, false, false);
}
for (let x = 2.7; x <= 11.5; x += 1.5) {
box(0.025, wallHeight - 0.12, 0.025, x, wallCenterY, 4.257, mats.seam, false, false);
}
// Water-edge retaining wall and cap.
box(24, 0.95, 0.28, 0, 0.025, -2.72, mats.concreteDark, true, true);
box(24.1, 0.12, 0.44, 0, 0.54, -2.71, mats.concreteLight, true, true);
for (let x = -11.5; x <= 11.5; x += 1.5) {
box(0.026, 0.88, 0.025, x, 0.025, -2.868, mats.seam, false, false);
}
// Lower path pavers.
const tileGeometry = new THREE.BoxGeometry(0.775, 0.04, 0.675);
const tileMaterials = [
material(0xb7b6ac),
material(0xc2c0b5),
material(0xadaea6),
material(0xcbc7ba)
];
const tileBuckets = tileMaterials.map(() => []);
for (let row = 0; row < 4; row++) {
for (let column = 0; column < 30; column++) {
const x = -11.6 + column * 0.8;
const z = -2.16 + row * 0.7;
const bucket = (row * 7 + column * 3) % tileMaterials.length;
tileBuckets[bucket].push({ x, z });
}
}
const dummy = new THREE.Object3D();
tileBuckets.forEach((entries, index) => {
const mesh = new THREE.InstancedMesh(tileGeometry, tileMaterials[index], entries.length);
entries.forEach((entry, instanceIndex) => {
dummy.position.set(entry.x, 0.48, entry.z);
dummy.updateMatrix();
mesh.setMatrixAt(instanceIndex, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
});
// Upper sidewalk pavers.
const upperTileGeometry = new THREE.BoxGeometry(0.775, 0.045, 0.87);
for (let row = 0; row < 2; row++) {
for (let column = 0; column < 30; column++) {
const x = -11.6 + column * 0.8;
const z = 4.99 + row * 0.98;
const upperTileMat = (row + column) % 3 === 0 ? mats.concrete : mats.concreteLight;
box(0.775, 0.045, 0.87, x, 2.92, z, upperTileMat, false, true);
}
}
// Ten descending voxel steps.
for (let i = 0; i < 10; i++) {
const top = UPPER - (i + 1) * STAIR_RISE;
const z = 4.18 - i * STAIR_DEPTH;
const bottom = -0.45;
const height = top - bottom;
const centerY = (top + bottom) / 2;
box(STAIR_WIDTH, height, STAIR_DEPTH, 0, centerY, z, mats.concreteLight, true, true);
// Contrasting nosing at the lower edge of every tread.
box(STAIR_WIDTH - 0.12, 0.045, 0.075, 0, top + 0.018, z - STAIR_DEPTH / 2 + 0.035, mats.curb, false, true);
// Stepped stone cheeks frame the descent.
const cheekTop = top + 0.22;
const cheekHeight = cheekTop - bottom;
for (const side of [-1, 1]) {
box(
0.25,
cheekHeight,
STAIR_DEPTH,
side * 2.375,
(cheekTop + bottom) / 2,
z,
mats.concrete,
true,
true
);
box(
0.29,
0.06,
STAIR_DEPTH + 0.015,
side * 2.375,
cheekTop + 0.025,
z,
mats.concreteLight,
true,
true
);
}
}
// Waterfront bench: black metal frame and warm wood slats.
function addBench(x, z) {
const legHeight = 0.54;
const legY = LOWER + legHeight / 2;
for (const lx of [-1.22, 1.22]) {
for (const lz of [-0.31, 0.31]) {
box(0.12, legHeight, 0.12, x + lx, legY, z + lz, mats.metal, true, true);
}
}
box(2.9, 0.11, 0.11, x, 0.99, z, mats.metal, true, true);
for (let slat = 0; slat < 5; slat++) {
box(
3.4,
0.1,
0.14,
x,
1.08,
z - 0.36 + slat * 0.18,
slat % 2 === 0 ? mats.wood : mats.woodLight,
true,
true
);
}
for (const px of [-1.28, 1.28]) {
box(0.11, 0.76, 0.11, x + px, 1.37, z + 0.47, mats.metal, true, true);
}
for (let slat = 0; slat < 3; slat++) {
box(
3.4,
0.17,
0.09,
x,
1.25 + slat * 0.22,
z + 0.47,
slat === 1 ? mats.woodLight : mats.wood,
true,
true
);
}
}
addBench(4.45, -1.87);
// Short voxel bollards along the lower path.
for (const x of [-10.5, -8.6, -6.7, -4.8, 6.7, 8.6, 10.5]) {
box(0.18, 0.67, 0.18, x, LOWER + 0.335, -0.24, mats.metal, true, true);
box(0.23, 0.075, 0.23, x, LOWER + 0.7, -0.24, mats.metalLight, true, true);
}
// Block-built street lamps.
function addLamp(x, z, baseY) {
box(0.34, 0.18, 0.34, x, baseY + 0.09, z, mats.metal, true, true);
box(0.11, 3.45, 0.11, x, baseY + 1.82, z, mats.metal, true, true);
box(0.84, 0.11, 0.11, x + 0.34, baseY + 3.51, z, mats.metal, true, true);
box(0.38, 0.22, 0.38, x + 0.7, baseY + 3.38, z, mats.metal, true, true);
box(0.29, 0.035, 0.29, x + 0.7, baseY + 3.255, z, mats.lamp, false, false);
}
addLamp(-7.8, 5.78, 2.92);
addLamp(7.9, 5.78, 2.92);
// Voxel planters and trees.
function addTree(x, z, baseY, scale = 1) {
box(1.25 * scale, 0.43 * scale, 1.25 * scale, x, baseY + 0.215 * scale, z, mats.concreteDark, true, true);
box(1.02 * scale, 0.08 * scale, 1.02 * scale, x, baseY + 0.445 * scale, z, mats.soil, false, true);
box(0.26 * scale, 1.55 * scale, 0.26 * scale, x, baseY + 1.2 * scale, z, mats.wood, true, true);
box(1.22 * scale, 1.0 * scale, 1.05 * scale, x, baseY + 2.13 * scale, z, mats.leaf, true, true);
box(0.83 * scale, 0.86 * scale, 0.82 * scale, x - 0.52 * scale, baseY + 2.05 * scale, z + 0.12 * scale, mats.leafLight, true, true);
box(0.82 * scale, 0.82 * scale, 0.8 * scale, x + 0.55 * scale, baseY + 2.12 * scale, z - 0.06 * scale, mats.leafDark, true, true);
box(0.75 * scale, 0.68 * scale, 0.72 * scale, x + 0.02 * scale, baseY + 2.79 * scale, z + 0.04 * scale, mats.leafLight, true, true);
}
addTree(-7.2, 5.62, 2.92, 0.92);
addTree(6.45, 5.58, 2.92, 0.92);
addTree(-7.0, -1.78, LOWER, 0.82);
// Distant voxel Chicago buildings.
function addBuilding(x, z, width, depth, height, facadeMat) {
box(width, height, depth, x, UPPER + height / 2, z, facadeMat, true, true);
box(width + 0.16, 0.18, depth + 0.16, x, UPPER + height + 0.09, z, mats.concreteDark, true, true);
const rows = Math.max(2, Math.floor((height - 0.8) / 1.15));
const columns = Math.max(2, Math.floor((width - 0.55) / 0.72));
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const wx = x - width / 2 + 0.48 + column * ((width - 0.8) / Math.max(columns - 1, 1));
const wy = UPPER + 0.9 + row * 1.15;
if (wy < UPPER + height - 0.35) {
box(0.34, 0.43, 0.035, wx, wy, z - depth / 2 - 0.022, mats.window, false, false);
}
}
}
box(width * 0.32, 0.42, depth * 0.3, x - width * 0.12, UPPER + height + 0.36, z, facadeMat, true, true);
}
addBuilding(-9.0, 14.5, 3.6, 3.2, 6.8, mats.brick);
addBuilding(-4.8, 15.2, 3.5, 3.3, 9.2, mats.grayBuilding);
addBuilding(0.2, 14.7, 4.1, 3.4, 6.2, mats.tanBuilding);
addBuilding(5.0, 15.5, 3.7, 3.2, 10.3, mats.blueBuilding);
addBuilding(9.4, 14.8, 3.3, 3.1, 7.3, mats.brick);
// Water highlights: deliberately rectangular and voxel-like.
const glints = [];
let randomSeed = 48291;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
for (let i = 0; i < 46; i++) {
const width = 0.4 + random() * 1.8;
const depth = 0.045 + random() * 0.065;
const x = -18 + random() * 36;
const z = -17 + random() * 13.5;
const mat = i % 4 === 0 ? mats.waterDark : mats.waterLight;
const glint = box(
width,
0.012,
depth,
x,
WATER + 0.012,
z,
mat,
false,
false
);
glints.push({ mesh: glint, baseX: x, phase: random() * Math.PI * 2 });
}
// A small in-scene vertical dimension reinforces the two street grades.
const dimensionX = -3.55;
const dimensionZ = 3.72;
box(0.055, UPPER - LOWER, 0.055, dimensionX, (UPPER + LOWER) / 2, dimensionZ, mats.dimension, false, false);
box(0.58, 0.055, 0.055, dimensionX, UPPER, dimensionZ, mats.dimension, false, false);
box(0.58, 0.055, 0.055, dimensionX, LOWER, dimensionZ, mats.dimension, false, false);
box(0.13, 0.13, 0.13, dimensionX, UPPER + 0.11, dimensionZ, mats.dimension, false, false);
box(0.13, 0.13, 0.13, dimensionX, LOWER - 0.11, dimensionZ, mats.dimension, false, false);
// DOM callouts projected from 3D anchors.
const tags = [
{
element: document.querySelector("#upperTag"),
position: new THREE.Vector3(-4.6, 3.18, 4.35),
offset: [-58, -8]
},
{
element: document.querySelector("#lowerTag"),
position: new THREE.Vector3(-4.15, 0.82, -1.55),
offset: [-55, -6]
},
{
element: document.querySelector("#dropTag"),
position: new THREE.Vector3(dimensionX, (UPPER + LOWER) / 2, dimensionZ),
offset: [35, 3]
}
];
const projected = new THREE.Vector3();
function positionTags() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
tags.forEach((tag) => {
projected.copy(tag.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
tag.element.style.opacity = visible ? "" : "0";
tag.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
tag.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
tag.element.style.transform = `translate(-50%, -100%) translate(${tag.offset[0]}px, ${tag.offset[1]}px)`;
});
}
// Direct camera controls: orbit, pan, mouse wheel, and touch pinch.
const pointers = new Map();
let lastX = 0;
let lastY = 0;
let lastPinchDistance = 0;
let interactionMode = "orbit";
const canvas = renderer.domElement;
function pinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.focus();
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
lastX = event.clientX;
lastY = event.clientY;
interactionMode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
} else if (pointers.size === 2) {
interactionMode = "pinch";
lastPinchDistance = pinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const distance = pinchDistance();
if (lastPinchDistance > 0 && distance > 0) {
view.zoom = THREE.MathUtils.clamp(
view.zoom * (distance / lastPinchDistance),
0.55,
2.5
);
updateCamera();
}
lastPinchDistance = distance;
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (interactionMode === "pan") {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const worldPerPixel =
((camera.top - camera.bottom) / renderer.domElement.clientHeight) / camera.zoom;
view.target.addScaledVector(right, -dx * worldPerPixel);
view.target.addScaledVector(up, dy * worldPerPixel);
view.target.x = THREE.MathUtils.clamp(view.target.x, -7, 7);
view.target.z = THREE.MathUtils.clamp(view.target.z, -4, 8);
view.target.y = THREE.MathUtils.clamp(view.target.y, 0.5, 3.5);
} else {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.005, 0.52, 1.46);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
interactionMode = "orbit";
} else if (pointers.size === 0) {
interactionMode = "orbit";
}
lastPinchDistance = 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * 0.001);
view.zoom = THREE.MathUtils.clamp(view.zoom * factor, 0.55, 2.5);
updateCamera();
},
{ passive: false }
);
function resetView() {
view.theta = homeView.theta;
view.phi = homeView.phi;
view.radius = homeView.radius;
view.zoom = homeView.zoom;
view.target.copy(homeView.target);
updateCamera();
}
let labelsVisible = true;
const labelButton = document.querySelector("#labelButton");
function toggleLabels() {
labelsVisible = !labelsVisible;
document.body.classList.toggle("labels-off", !labelsVisible);
labelButton.setAttribute("aria-pressed", String(labelsVisible));
}
document.querySelector("#resetButton").addEventListener("click", resetView);
labelButton.addEventListener("click", toggleLabels);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "l") toggleLabels();
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
glints.forEach((glint) => {
glint.mesh.position.x =
glint.baseX + Math.sin(elapsed * 0.28 + glint.phase) * 0.34;
});
positionTags();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
positionTags();
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
loading.classList.add("ready");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```