Prompt specification
Build or customize the Three.js 3D scene "Malá Strana lane and bridge-approach slice" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Malá Strana lane and bridge-approach slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mal-strana-lane-and-bridge-approach-slice-x2859
Scene Description Prompt:
A compact voxel Malá Strana fragment with a rising lane, facades, tower silhouette, and bridge approach. Three.js from cdnjs, one HTML file.
Working Three.js Starter (mal-strana-lane-and-bridge-approach-slice-x2859):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Malá Strana — Voxel Fragment</title>
<style>
:root {
--ink: #26312f;
--paper: #e9e3d6;
--accent: #9c5144;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 42%, transparent 48%, rgba(51, 48, 38, 0.13) 115%),
linear-gradient(to bottom, rgba(255,255,255,0.08), transparent 24%);
z-index: 2;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.heading {
position: absolute;
top: clamp(22px, 4vw, 48px);
left: clamp(22px, 4vw, 52px);
max-width: 390px;
text-shadow: 0 1px 12px rgba(244, 239, 226, 0.5);
}
.eyebrow {
margin-bottom: 9px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.24em;
text-transform: uppercase;
color: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 76px);
font-weight: 400;
line-height: 0.93;
letter-spacing: -0.045em;
}
.subtitle {
margin: 13px 0 0;
max-width: 320px;
font-size: 12px;
line-height: 1.55;
color: rgba(38, 49, 47, 0.73);
}
.coordinates {
position: absolute;
top: clamp(24px, 4vw, 48px);
right: clamp(22px, 4vw, 48px);
padding: 10px 13px;
border: 1px solid rgba(38, 49, 47, 0.18);
border-radius: 999px;
background: rgba(239, 234, 222, 0.66);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend {
position: absolute;
left: clamp(22px, 4vw, 52px);
bottom: clamp(22px, 4vw, 42px);
display: flex;
gap: 24px;
align-items: flex-end;
}
.legend-title {
max-width: 230px;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
line-height: 1.3;
}
.legend-copy {
max-width: 290px;
font-size: 10px;
line-height: 1.5;
color: rgba(38, 49, 47, 0.65);
}
.controls {
position: absolute;
right: clamp(22px, 4vw, 48px);
bottom: clamp(22px, 4vw, 42px);
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.control-hint {
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
color: rgba(38, 49, 47, 0.6);
}
button {
border: 1px solid rgba(38, 49, 47, 0.2);
border-radius: 50%;
width: 42px;
height: 42px;
background: rgba(239, 234, 222, 0.78);
color: var(--ink);
cursor: pointer;
backdrop-filter: blur(8px);
transition: transform 160ms ease, background 160ms ease;
}
button:hover {
transform: rotate(-12deg);
background: rgba(255, 252, 243, 0.95);
}
button svg { width: 17px; height: 17px; }
.marker {
position: absolute;
left: 0;
top: 0;
padding: 5px 8px;
border: 1px solid rgba(38, 49, 47, 0.17);
border-radius: 3px;
background: rgba(241, 235, 222, 0.84);
color: rgba(38, 49, 47, 0.88);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, calc(-100% - 12px));
backdrop-filter: blur(6px);
box-shadow: 0 4px 18px rgba(40, 42, 35, 0.08);
}
.marker::after {
content: "";
position: absolute;
width: 1px;
height: 12px;
left: 50%;
top: 100%;
background: rgba(38, 49, 47, 0.45);
}
@media (max-width: 700px) {
.coordinates, .legend-copy, .control-hint { display: none; }
.heading { max-width: 260px; }
.subtitle { max-width: 230px; }
.legend-title { font-size: 13px; }
.controls { bottom: 20px; right: 20px; }
}
</style>
</head>
<body>
<div class="vignette"></div>
<div class="hud">
<header class="heading">
<div class="eyebrow">Voxel study · Prague</div>
<h1>Malá<br />Strana</h1>
<p class="subtitle">
A compact hillside fragment of pastel façades, stepped lanes,
church towers and the stone approach to Charles Bridge.
</p>
</header>
<div class="coordinates">50.0875° N / 14.4026° E</div>
<div class="legend">
<div class="legend-title">The lane climbs toward the river.</div>
<div class="legend-copy">
Drag to orbit · Scroll to zoom · Double-click to reset
</div>
</div>
<div class="controls">
<span class="control-hint">Drag · Zoom</span>
<button id="reset" aria-label="Reset camera" title="Reset camera">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 11a8 8 0 1 1 2.34 5.66" stroke="currentColor"
stroke-width="1.8" stroke-linecap="round"/>
<path d="M4 5v6h6" stroke="currentColor"
stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
<div class="marker" id="lane-label">Rising lane</div>
<div class="marker" id="tower-label">Church tower</div>
<div class="marker" id="bridge-label">Bridge approach</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
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.05;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d8ca);
scene.fog = new THREE.Fog(0xd9d8ca, 39, 78);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xf4ead6, 0x6d756a, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefcf, 3.25);
sun.position.set(-15, 25, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb6c9c7, 0.65);
fill.position.set(20, 12, -18);
scene.add(fill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
const M = {
ground: material(0xb8b19d),
plinth: material(0x77766a),
terrace: material(0xb8aa91),
road: material(0x918b7e),
curb: material(0xc9bca3),
cobble: material(0xa39b8c),
stone: material(0xc5b69b),
stoneDark: material(0x9e907b),
cream: material(0xd8cbb0),
plaster: material(0xe2d5bb),
pink: material(0xc98e82),
rose: material(0xb86e65),
sage: material(0x91a79b),
blue: material(0x8fa9af),
ochre: material(0xc4a15f),
redRoof: material(0x9d5548),
brownRoof: material(0x79594b),
darkRoof: material(0x594f49),
greenRoof: material(0x52786b),
darkGreen: material(0x486a5d),
window: material(0x354748, { roughness: 0.48 }),
windowLight: material(0xc5b77b, {
emissive: 0x6f5422,
emissiveIntensity: 0.18
}),
door: material(0x53635c),
wood: material(0x675245),
lamp: material(0xf0c779, {
emissive: 0xc88932,
emissiveIntensity: 0.65
}),
iron: material(0x3e4945),
water: material(0x789b9b, {
roughness: 0.36,
metalness: 0.08
}),
waterLight: material(0xa8c1ba, {
transparent: true,
opacity: 0.38,
roughness: 0.5
}),
foliage: material(0x6f8469),
foliageLight: material(0x829377),
trunk: material(0x685847),
skin: material(0xc89f7c),
red: material(0xa65348),
navy: material(0x405b67),
creamLight: material(0xf0e4cc)
};
function box(w, h, d, mat, x, y, z, options = {}) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) mesh.rotation.set(...options.rotation);
if (options.parent) options.parent.add(mesh);
else scene.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, mat, x, y, z, segments = 8, options = {}) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.parent) options.parent.add(mesh);
else scene.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Diorama ground, river and stepped hillside
// ------------------------------------------------------------
box(90, 0.3, 90, M.ground, 0, -2.55, -4);
// Dark foundation under the compact urban fragment.
box(20.5, 2.2, 36.5, M.plinth, -2, -1.1, -3.4);
const terraceCount = 10;
const terraceDepth = 2.7;
const terraceStartZ = 13;
const terraceHeights = [];
for (let i = 0; i < terraceCount; i++) {
const z = terraceStartZ - i * terraceDepth;
const top = 0.15 + i * 0.38;
terraceHeights.push(top);
const height = top + 2.2;
box(
19,
height,
terraceDepth + 0.03,
i % 2 === 0 ? M.terrace : M.stoneDark,
-2,
(top - 2.2) / 2,
z
);
// Main cobbled lane.
box(3.9, 0.12, terraceDepth - 0.18, M.road, 0, top + 0.02, z);
// Raised stone curbs.
box(0.28, 0.2, terraceDepth - 0.12, M.curb, -2.08, top + 0.06, z);
box(0.28, 0.2, terraceDepth - 0.12, M.curb, 2.08, top + 0.06, z);
// Individual voxel paving stones.
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 5; col++) {
box(
0.64,
0.055,
0.91,
(row + col) % 3 === 0 ? M.cobble : M.road,
-1.45 + col * 0.725,
top + 0.105,
z - 0.59 + row * 1.18
);
}
}
}
function groundAt(z) {
const index = THREE.MathUtils.clamp(
Math.round((terraceStartZ - z) / terraceDepth),
0,
terraceCount - 1
);
return terraceHeights[index];
}
// River and the narrow opposite bank.
box(9.7, 0.28, 38, material(0x536e6d), 12.2, -0.28, -3);
box(9.7, 0.08, 38, M.water, 12.2, -0.10, -3);
box(3.2, 2.4, 37, M.plinth, 18.75, -1.15, -3);
box(3.25, 0.24, 37, M.stoneDark, 18.75, 0.1, -3);
// Quiet, graphic water reflections.
for (let i = 0; i < 17; i++) {
const x = 8.1 + (i * 1.37) % 7.8;
const z = 10 - (i * 3.13) % 34;
box(
0.7 + (i % 3) * 0.35,
0.018,
0.06,
M.waterLight,
x,
-0.045,
z
);
}
// ------------------------------------------------------------
// Charles Bridge approach and stepped stone arches
// ------------------------------------------------------------
const bridgeTop = 3.57;
const bridgeZ = -11.35;
box(17.1, 0.44, 3.25, M.stone, 8.85, bridgeTop - 0.22, bridgeZ);
box(17.1, 0.28, 0.34, M.stoneDark, 8.85, bridgeTop + 0.12, bridgeZ - 1.42);
box(17.1, 0.28, 0.34, M.stoneDark, 8.85, bridgeTop + 0.12, bridgeZ + 1.42);
// Parapet coping.
box(17.1, 0.18, 0.48, M.curb, 8.85, bridgeTop + 0.35, bridgeZ - 1.42);
box(17.1, 0.18, 0.48, M.curb, 8.85, bridgeTop + 0.35, bridgeZ + 1.42);
// Piers.
for (const x of [7.0, 11.85, 16.65]) {
box(1.05, 3.65, 2.75, M.stoneDark, x, 1.52, bridgeZ);
box(1.3, 0.38, 3.05, M.stone, x, 3.38, bridgeZ);
}
// Block-built arch crowns on the camera-facing side.
for (const centerX of [9.42, 14.25]) {
for (let i = 0; i <= 8; i++) {
const angle = (i / 8) * Math.PI;
const x = centerX + Math.cos(angle) * 2.05;
const y = 1.25 + Math.sin(angle) * 1.75;
box(
0.62,
0.5,
0.38,
i % 2 ? M.stone : M.stoneDark,
x,
y,
bridgeZ + 1.47
);
}
}
// Small bridge posts and lamps.
for (let i = 0; i < 9; i++) {
const x = 2.1 + i * 1.86;
box(0.34, 0.64, 0.42, M.stone, x, bridgeTop + 0.48, bridgeZ - 1.42);
box(0.34, 0.64, 0.42, M.stone, x, bridgeTop + 0.48, bridgeZ + 1.42);
}
// ------------------------------------------------------------
// Voxel buildings
// ------------------------------------------------------------
function addWindow(x, y, z, orientation, lit = false) {
const frameMat = M.creamLight;
const glassMat = lit ? M.windowLight : M.window;
if (orientation === "z") {
box(0.68, 0.96, 0.09, frameMat, x, y, z);
box(0.5, 0.77, 0.105, glassMat, x, y, z + 0.025);
box(0.055, 0.78, 0.12, M.wood, x, y, z + 0.04);
} else {
box(0.09, 0.96, 0.68, frameMat, x, y, z);
box(0.105, 0.77, 0.5, glassMat, x + (x > 0 ? 0.025 : -0.025), y, z);
box(0.12, 0.78, 0.055, M.wood, x + (x > 0 ? 0.04 : -0.04), y, z);
}
}
function building(x, z, w, d, h, bodyMat, roofMat, options = {}) {
const base = groundAt(z) - 0.12;
const side = options.side || 1;
const floors = Math.max(2, Math.floor(h / 2.25));
// Foundation and body.
box(w + 0.12, 0.42, d + 0.12, M.stoneDark, x, base + 0.08, z);
box(w, h, d, bodyMat, x, base + h / 2, z);
// Floor bands.
for (let f = 1; f < floors; f++) {
const y = base + f * (h / floors);
box(w + 0.08, 0.09, d + 0.08, M.creamLight, x, y, z);
}
// Windows on the south-facing façade.
const frontZ = z + d / 2 + 0.055;
const columns = Math.max(2, Math.floor(w / 1.45));
for (let floor = 0; floor < floors; floor++) {
const y = base + 1.35 + floor * (h / floors);
if (y > base + h - 0.65) continue;
for (let col = 0; col < columns; col++) {
const wx = x - w / 2 + (w / columns) * (col + 0.5);
const lit = ((floor * 3 + col + Math.round(x)) % 7) === 0;
addWindow(wx, y, frontZ, "z", lit);
}
}
// Windows on the lane-facing side.
const laneX = x + side * (w / 2 + 0.055);
const sideColumns = Math.max(2, Math.floor(d / 1.55));
for (let floor = 0; floor < floors; floor++) {
const y = base + 1.35 + floor * (h / floors);
if (y > base + h - 0.65) continue;
for (let col = 0; col < sideColumns; col++) {
const wz = z - d / 2 + (d / sideColumns) * (col + 0.5);
const lit = ((floor + col + 1) % 8) === 0;
addWindow(laneX, y, wz, "x", lit);
}
}
// A simple dark door on the lane side.
const doorZ = z + (options.doorOffset || 0);
box(
side > 0 ? 0.12 : 0.12,
1.52,
0.78,
M.door,
laneX,
base + 0.76,
doorZ
);
// Stepped hipped roof.
for (let layer = 0; layer < 4; layer++) {
const layerW = w + 0.35 - layer * 0.14;
const layerD = d + 0.35 - layer * (d * 0.19);
box(
layerW,
0.46,
layerD,
roofMat,
x,
base + h + 0.23 + layer * 0.44,
z
);
}
// Chimney.
box(
0.48,
1.2,
0.52,
bodyMat,
x + w * 0.24,
base + h + 1.25,
z - d * 0.18
);
box(
0.62,
0.18,
0.65,
M.stoneDark,
x + w * 0.24,
base + h + 1.88,
z - d * 0.18
);
// Small roof dormer.
if (h > 7.2) {
box(0.8, 0.9, 0.8, bodyMat, x - w * 0.14, base + h + 1.05, z + d * 0.18);
box(0.48, 0.55, 0.08, M.window,
x - w * 0.14, base + h + 1.05, z + d * 0.18 + 0.43);
}
}
// Left bank.
building(-7.0, 10.3, 6.2, 4.7, 7.1, M.pink, M.redRoof, { side: 1, doorOffset: 0.7 });
building(-6.9, 5.0, 6.1, 4.8, 8.7, M.sage, M.darkRoof, { side: 1, doorOffset: -0.5 });
building(-7.0, -0.5, 6.3, 4.8, 6.9, M.cream, M.brownRoof, { side: 1, doorOffset: 0.4 });
building(-7.1, -5.8, 6.1, 4.7, 8.1, M.ochre, M.redRoof, { side: 1, doorOffset: -0.5 });
// Right bank.
building(6.1, 9.7, 5.8, 4.7, 6.5, M.cream, M.brownRoof, { side: -1, doorOffset: -0.6 });
building(6.3, 4.4, 6.0, 4.8, 8.2, M.rose, M.redRoof, { side: -1, doorOffset: 0.6 });
building(6.3, -0.9, 5.8, 4.6, 7.0, M.blue, M.darkRoof, { side: -1, doorOffset: -0.4 });
// ------------------------------------------------------------
// Church and tower silhouette
// ------------------------------------------------------------
const churchBase = 3.43;
// Low church body behind the tower.
box(5.7, 6.2, 5.0, M.plaster, -4.8, churchBase + 3.1, -18.0);
box(6.2, 0.45, 5.5, M.stoneDark, -4.8, churchBase + 6.35, -18.0);
box(4.8, 1.8, 3.8, M.greenRoof, -4.8, churchBase + 7.25, -18.0);
// Tower shaft.
box(3.35, 7.7, 3.35, M.cream, -4.8, churchBase + 3.85, -15.15);
box(3.65, 0.42, 3.65, M.stoneDark, -4.8, churchBase + 7.7, -15.15);
box(3.35, 0.42, 3.35, M.plaster, -4.8, churchBase + 8.25, -15.15);
// Dark belfry openings.
box(0.62, 1.25, 0.1, M.window, -5.6, churchBase + 9.15, -13.44);
box(0.62, 1.25, 0.1, M.window, -4.0, churchBase + 9.15, -13.44);
box(0.1, 1.25, 0.62, M.window, -3.09, churchBase + 9.15, -15.9);
box(0.1, 1.25, 0.62, M.window, -3.09, churchBase + 9.15, -14.45);
// Stepped copper cap and pointed finial.
box(3.55, 0.48, 3.55, M.greenRoof, -4.8, churchBase + 10.02, -15.15);
box(2.85, 0.9, 2.85, M.darkGreen, -4.8, churchBase + 10.72, -15.15);
box(2.1, 0.78, 2.1, M.greenRoof, -4.8, churchBase + 11.55, -15.15);
box(1.35, 0.68, 1.35, M.darkGreen, -4.8, churchBase + 12.25, -15.15);
const spire = new THREE.Mesh(
new THREE.ConeGeometry(0.8, 2.35, 4),
M.greenRoof
);
spire.position.set(-4.8, churchBase + 13.65, -15.15);
spire.rotation.y = Math.PI / 4;
spire.castShadow = true;
scene.add(spire);
box(0.11, 1.05, 0.11, M.iron, -4.8, churchBase + 15.15, -15.15);
box(0.55, 0.11, 0.11, M.iron, -4.8, churchBase + 15.25, -15.15);
// Clock face on the tower.
const clockFace = new THREE.Mesh(
new THREE.CircleGeometry(0.62, 24),
M.creamLight
);
clockFace.position.set(-4.8, churchBase + 5.65, -13.46);
scene.add(clockFace);
const clockRim = new THREE.Mesh(
new THREE.RingGeometry(0.54, 0.63, 24),
M.brownRoof
);
clockRim.position.set(-4.8, churchBase + 5.65, -13.43);
scene.add(clockRim);
box(0.055, 0.43, 0.04, M.iron, -4.8, churchBase + 5.78, -13.39);
box(0.34, 0.055, 0.04, M.iron, -4.67, churchBase + 5.65, -13.38);
// ------------------------------------------------------------
// Street details, trees and tiny pedestrians
// ------------------------------------------------------------
function tree(x, z, scale = 1) {
const y = groundAt(z);
box(0.28 * scale, 1.8 * scale, 0.28 * scale, M.trunk,
x, y + 0.9 * scale, z);
box(1.45 * scale, 1.15 * scale, 1.35 * scale, M.foliage,
x, y + 2.05 * scale, z);
box(1.05 * scale, 0.9 * scale, 1.0 * scale, M.foliageLight,
x + 0.28 * scale, y + 2.75 * scale, z - 0.08 * scale);
}
tree(-3.65, 9.3, 0.82);
tree(-3.7, 2.1, 0.92);
tree(3.72, -4.9, 0.8);
tree(3.85, 7.4, 0.72);
tree(-9.3, -11.8, 1.0);
function lamp(x, z, y = groundAt(z)) {
box(0.11, 2.55, 0.11, M.iron, x, y + 1.275, z);
box(0.52, 0.12, 0.52, M.iron, x, y + 2.55, z);
box(0.34, 0.5, 0.34, M.lamp, x, y + 2.25, z);
box(0.45, 0.12, 0.45, M.iron, x, y + 2.52, z);
}
lamp(2.55, 8.4);
lamp(-2.55, 3.0);
lamp(2.55, -2.8);
lamp(-2.55, -7.9);
lamp(6.0, bridgeZ + 1.45, bridgeTop);
lamp(11.9, bridgeZ + 1.45, bridgeTop);
function person(x, y, z, shirt, options = {}) {
const s = options.scale || 1;
box(0.17 * s, 0.48 * s, 0.2 * s, M.navy,
x - 0.11 * s, y + 0.24 * s, z);
box(0.17 * s, 0.48 * s, 0.2 * s, M.navy,
x + 0.11 * s, y + 0.24 * s, z);
box(0.48 * s, 0.66 * s, 0.29 * s, shirt,
x, y + 0.82 * s, z);
box(0.29 * s, 0.29 * s, 0.29 * s, M.skin,
x, y + 1.29 * s, z);
}
person(-0.45, 0.22, 9.8, M.red, { scale: 0.9 });
person(0.75, 1.32, 4.5, M.navy, { scale: 0.95 });
person(-0.85, 2.07, -1.8, M.cream, { scale: 0.88 });
person(0.55, 2.45, -6.7, M.red, { scale: 0.92 });
person(7.1, bridgeTop + 0.03, bridgeZ + 0.2, M.navy, { scale: 0.86 });
person(11.8, bridgeTop + 0.03, bridgeZ - 0.25, M.ochre, { scale: 0.9 });
// Distant opposite-bank architecture.
building(19.1, -7.5, 4.2, 4.5, 7.2, M.cream, M.brownRoof, { side: -1 });
building(19.2, -13.4, 4.5, 4.8, 8.4, M.pink, M.darkRoof, { side: -1 });
building(19.0, -19.0, 4.2, 4.6, 6.5, M.sage, M.redRoof, { side: -1 });
// Small distant skyline blocks.
const distantMats = [M.cream, M.stoneDark, M.ochre, M.blue];
for (let i = 0; i < 12; i++) {
const x = -15 + i * 2.9;
const z = -26 - (i % 3) * 1.3;
const h = 3.5 + ((i * 7) % 5);
box(2.3, h, 2.8, distantMats[i % distantMats.length], x, h / 2, z);
box(2.5, 0.35, 3, M.brownRoof, x, h + 0.18, z);
}
// ------------------------------------------------------------
// Camera controls — implemented directly, without addons
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 4.1, -3.4),
theta: 0.63,
phi: 1.03,
radius: 34,
targetTheta: 0.63,
targetPhi: 1.03,
targetRadius: 34
};
let dragging = false;
let lastX = 0;
let lastY = 0;
let pointerId = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
controls.targetTheta -= dx * 0.005;
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - dy * 0.004,
0.46,
1.34
);
});
function endDrag(event) {
if (pointerId !== null && canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
dragging = false;
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
20,
54
);
}, { passive: false });
function resetCamera() {
controls.targetTheta = 0.63;
controls.targetPhi = 1.03;
controls.targetRadius = 34;
controls.target.set(0, 4.1, -3.4);
}
document.getElementById("reset").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.targetTheta += 0.08;
if (event.key === "ArrowRight") controls.targetTheta -= 0.08;
if (event.key === "ArrowUp") controls.targetPhi -= 0.06;
if (event.key === "ArrowDown") controls.targetPhi += 0.06;
if (event.key.toLowerCase() === "r") resetCamera();
});
// ------------------------------------------------------------
// Projected labels
// ------------------------------------------------------------
const annotations = [
{
element: document.getElementById("lane-label"),
point: new THREE.Vector3(-0.4, 1.25, 3.4)
},
{
element: document.getElementById("tower-label"),
point: new THREE.Vector3(-4.8, 17.2, -15.15)
},
{
element: document.getElementById("bridge-label"),
point: new THREE.Vector3(10.6, 4.3, -10.0)
}
];
function updateAnnotations() {
for (const annotation of annotations) {
const projected = annotation.point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
}
}
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
const smoothing = 0.075;
controls.theta += (controls.targetTheta - controls.theta) * smoothing;
controls.phi += (controls.targetPhi - controls.phi) * smoothing;
controls.radius += (controls.targetRadius - controls.radius) * smoothing;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
renderer.render(scene, camera);
updateAnnotations();
}
animate();
</script>
</body>
</html>
```