Prompt specification
Build or customize the Three.js 3D scene "Guanajuato narrow-lane balcony fragment" 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: Guanajuato narrow-lane balcony fragment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/guanajuato-narrow-lane-balcony-fragment-x2737
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Guanajuato's hillside lanes. Build a referenced narrow-lane facade fragment with balcony, doorway, and rising pavement. Make the opposing building spacing and changing ground level clear in the small model. Voxel style.
Working Three.js Starter (guanajuato-narrow-lane-balcony-fragment-x2737):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Guanajuato — Hillside Lane</title>
<style>
:root {
--ink: #242a2b;
--paper: #f7edda;
--accent: #c8573f;
--line: rgba(36, 42, 43, 0.24);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8d3b4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 30px;
left: 34px;
max-width: 390px;
text-shadow: 0 1px 12px rgba(247, 237, 218, 0.6);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5.2vw, 74px);
font-weight: 500;
line-height: 0.88;
letter-spacing: -0.045em;
}
.subtitle {
margin: 13px 0 0;
font-size: 12px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
position: absolute;
top: 28px;
right: 28px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 13px;
background: rgba(247, 237, 218, 0.78);
box-shadow: 0 12px 35px rgba(63, 43, 29, 0.13);
backdrop-filter: blur(12px);
pointer-events: auto;
}
button {
min-height: 34px;
padding: 0 13px;
border: 0;
border-radius: 9px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(36, 42, 43, 0.08);
}
button:active { transform: translateY(1px); }
button.active {
background: var(--ink);
color: var(--paper);
}
.metrics {
position: absolute;
right: 28px;
bottom: 28px;
display: grid;
grid-template-columns: auto auto;
gap: 7px 22px;
padding: 15px 17px;
border: 1px solid rgba(255, 255, 255, 0.46);
border-radius: 13px;
background: rgba(247, 237, 218, 0.82);
box-shadow: 0 12px 35px rgba(63, 43, 29, 0.12);
backdrop-filter: blur(12px);
}
.metrics span {
align-self: center;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
opacity: 0.67;
}
.metrics strong {
justify-self: end;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.hint {
position: absolute;
left: 34px;
bottom: 30px;
display: flex;
align-items: center;
gap: 10px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.mouse {
position: relative;
width: 17px;
height: 24px;
border: 1.5px solid currentColor;
border-radius: 9px;
opacity: 0.7;
}
.mouse::after {
content: "";
position: absolute;
top: 4px;
left: 6px;
width: 3px;
height: 6px;
border-radius: 2px;
background: currentColor;
}
#annotations {
position: absolute;
inset: 0;
transition: opacity 180ms ease;
}
#annotations.off { opacity: 0; }
.annotation {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 7px;
background: rgba(247, 237, 218, 0.9);
box-shadow: 0 6px 18px rgba(55, 38, 27, 0.12);
white-space: nowrap;
transform: translate(-50%, -50%);
will-change: left, top;
}
.annotation::before {
content: "";
position: absolute;
left: -4px;
top: 50%;
width: 7px;
height: 7px;
border: 2px solid var(--paper);
border-radius: 50%;
background: var(--accent);
transform: translateY(-50%);
box-shadow: 0 0 0 1px rgba(36, 42, 43, 0.25);
}
.annotation b {
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.annotation span {
padding-left: 8px;
border-left: 1px solid var(--line);
color: var(--accent);
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8d3b4;
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
.loading.hide { opacity: 0; pointer-events: none; }
@media (max-width: 720px) {
.brand { top: 20px; left: 20px; }
.subtitle { max-width: 220px; line-height: 1.5; }
.controls {
top: auto;
right: 16px;
bottom: 18px;
}
.metrics {
right: 16px;
bottom: 70px;
padding: 11px 13px;
}
.hint { left: 20px; bottom: 22px; }
.annotation { transform: translate(-50%, -50%) scale(.88); }
}
</style>
</head>
<body>
<div class="loading" id="loading">Building the lane…</div>
<div class="ui">
<header class="brand">
<div class="eyebrow">20°42′ N · 101°16′ W</div>
<h1>Guanajuato</h1>
<p class="subtitle">Hillside lane · voxel architectural study</p>
</header>
<nav class="controls" aria-label="Model views">
<button class="active" data-view="street">Lane</button>
<button data-view="model">Model</button>
<button id="labelToggle" aria-pressed="true">Labels</button>
<button id="reset" title="Reset view" aria-label="Reset view">↺</button>
</nav>
<div id="annotations">
<div class="annotation" id="ann-balcony"><b>Balcony</b><span>+2.75 m</span></div>
<div class="annotation" id="ann-door"><b>Doorway</b><span>street level</span></div>
<div class="annotation" id="ann-span"><b>Clear lane</b><span>5.5 m</span></div>
<div class="annotation" id="ann-grade"><b>Upper terrace</b><span>+3.10 m</span></div>
</div>
<aside class="metrics">
<span>Clear span</span><strong>5.5 m</strong>
<span>Total rise</span><strong>+3.1 m</strong>
</aside>
<div class="hint"><span class="mouse"></span> Drag to orbit · Scroll to zoom</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, scene and camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8d3b4);
scene.fog = new THREE.Fog(0xe8d3b4, 20, 43);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xffefd5, 0x655043, 1.8);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4b5, 2.7);
sun.position.set(-7, 15, -10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0003;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d8db, 1.15);
fill.position.set(10, 7, 7);
scene.add(fill);
// ------------------------------------------------------------
// Shared voxel geometry and materials
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(w, h, d, x, y, z, color, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const LANE_HALF = 2.75;
const colors = {
coral: 0xd86b4d,
rose: 0xc75e6b,
ochre: 0xe0a64b,
teal: 0x4e8b82,
cream: 0xf0d8ae,
red: 0xb94f3c,
wood: 0x633b2e,
dark: 0x17272a,
iron: 0x26393a,
green: 0x4e7149,
stone: 0xa88c70
};
// ------------------------------------------------------------
// Raised, stepped street
// ------------------------------------------------------------
const terraces = [
{ z0: -8.0, z1: -3.0, y: 0.00 },
{ z0: -3.0, z1: 0.0, y: 0.45 },
{ z0: 0.0, z1: 3.0, y: 1.05 },
{ z0: 3.0, z1: 6.0, y: 1.95 },
{ z0: 6.0, z1: 9.0, y: 3.10 }
];
function streetY(z) {
for (const t of terraces) {
if (z < t.z1) return t.y;
}
return terraces[terraces.length - 1].y;
}
// Display base.
box(60, 0.18, 60, 0, -0.64, 0, 0xe8d6b9, false);
box(14.8, 0.48, 19.2, 0, -0.32, 0.5, 0xb18d6e, false);
// Terrace masses; their exposed vertical faces make the grade legible.
for (const t of terraces) {
const bottom = -0.2;
const h = t.y - bottom;
box(
14.0,
h,
t.z1 - t.z0,
0,
bottom + h / 2,
(t.z0 + t.z1) / 2,
0xa98b70,
false
);
}
// Instanced cobblestones keep the scene light while preserving the voxel look.
const cobbleMatrices = [];
const cobbleColors = [];
const cobblePalette = [
0x8e7967, 0xa18a74, 0xb59b80, 0x9b806c,
0xc0a68a, 0x887668, 0xb4977d
];
const dummy = new THREE.Object3D();
let seed = 8241;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (const t of terraces) {
const rowCount = Math.floor((t.z1 - t.z0) / 0.43);
const rowDepth = (t.z1 - t.z0) / rowCount;
const colCount = 12;
const colWidth = 5.08 / colCount;
for (let row = 0; row < rowCount; row++) {
const z = t.z0 + rowDepth * (row + 0.5);
const offset = row % 2 ? colWidth * 0.5 : 0;
for (let col = -1; col <= colCount; col++) {
const x = -2.54 + col * colWidth + offset;
// A narrow drainage channel remains visible along the right side.
if (x > 2.08 && x < 2.34) continue;
dummy.position.set(x, t.y + 0.025, z);
dummy.scale.set(colWidth * 0.91, 0.12, rowDepth * 0.89);
dummy.updateMatrix();
cobbleMatrices.push(dummy.matrix.clone());
cobbleColors.push(new THREE.Color(
cobblePalette[Math.floor(random() * cobblePalette.length)]
));
}
}
}
const cobbles = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 1 }),
cobbleMatrices.length
);
cobbleMatrices.forEach((matrix, i) => {
cobbles.setMatrixAt(i, matrix);
cobbles.setColorAt(i, cobbleColors[i]);
});
cobbles.instanceMatrix.needsUpdate = true;
cobbles.instanceColor.needsUpdate = true;
cobbles.receiveShadow = true;
scene.add(cobbles);
// Voxel risers at each change in elevation.
const riserMatrices = [];
const riserColors = [];
for (let i = 0; i < terraces.length - 1; i++) {
const current = terraces[i];
const next = terraces[i + 1];
const rise = next.y - current.y;
const count = 12;
const width = 5.0 / count;
for (let col = 0; col < count; col++) {
dummy.position.set(
-2.5 + width * (col + 0.5),
current.y + rise / 2,
current.z1 - 0.035
);
dummy.scale.set(width * 0.91, rise * 0.92, 0.09);
dummy.updateMatrix();
riserMatrices.push(dummy.matrix.clone());
riserColors.push(new THREE.Color(
cobblePalette[Math.floor(random() * cobblePalette.length)]
));
}
}
const risers = new THREE.InstancedMesh(
unitBox,
new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 1 }),
riserMatrices.length
);
riserMatrices.forEach((matrix, i) => {
risers.setMatrixAt(i, matrix);
risers.setColorAt(i, riserColors[i]);
});
risers.instanceMatrix.needsUpdate = true;
risers.instanceColor.needsUpdate = true;
risers.receiveShadow = true;
scene.add(risers);
// Dark linear drain, broken at each terrace.
for (const t of terraces) {
box(
0.15,
0.035,
t.z1 - t.z0 - 0.24,
2.21,
t.y + 0.025,
(t.z0 + t.z1) / 2,
0x514c45,
false
);
}
// ------------------------------------------------------------
// Facade construction helpers
// ------------------------------------------------------------
function addBuilding(side, z0, z1, base, height, color) {
const length = z1 - z0;
const centerZ = (z0 + z1) / 2;
// Building mass: inner facade is exactly at ±LANE_HALF.
box(
3.65,
height,
length,
side * (LANE_HALF + 1.825),
base + height / 2,
centerZ,
color
);
// Foundation and cornice emphasize the stepped street.
box(
0.18,
0.48,
length - 0.12,
side * (LANE_HALF - 0.06),
base + 0.24,
centerZ,
0x765f51
);
box(
3.88,
0.18,
length + 0.10,
side * (LANE_HALF + 1.76),
base + height + 0.02,
centerZ,
colors.cream
);
// Vertical corner strips.
for (const z of [z0 + 0.12, z1 - 0.12]) {
box(
0.13,
height - 0.18,
0.18,
side * (LANE_HALF - 0.055),
base + height / 2,
z,
0xf1d5aa
);
}
// Small roof forms, seen from the model view.
const roofY = base + height + 0.11;
box(
0.48,
0.38,
0.48,
side * (LANE_HALF + 1.05),
roofY + 0.19,
centerZ - length * 0.25,
0x9f7257
);
box(
0.58,
0.22,
0.76,
side * (LANE_HALF + 2.45),
roofY + 0.11,
centerZ + length * 0.22,
0x67746b
);
}
function addWindow(side, z, y, width = 0.88, height = 1.18, shutters = true) {
const x = side * (LANE_HALF - 0.045);
// Recess-like dark pane.
box(0.075, height, width, x, y, z, colors.dark, false);
// Frame.
box(0.14, height + 0.18, 0.11, side * (LANE_HALF - 0.10), y, z - width / 2, colors.cream);
box(0.14, height + 0.18, 0.11, side * (LANE_HALF - 0.10), y, z + width / 2, colors.cream);
box(0.14, 0.11, width + 0.20, side * (LANE_HALF - 0.10), y + height / 2, z, colors.cream);
box(0.14, 0.11, width + 0.20, side * (LANE_HALF - 0.10), y - height / 2, z, colors.cream);
// Central mullion.
box(0.13, height, 0.065, side * (LANE_HALF - 0.115), y, z, colors.wood, false);
// Projecting sill.
box(
0.36,
0.11,
width + 0.28,
side * (LANE_HALF - 0.14),
y - height / 2 - 0.06,
z,
0xe8cda4
);
if (shutters) {
for (const direction of [-1, 1]) {
box(
0.11,
height + 0.04,
0.23,
side * (LANE_HALF - 0.075),
y,
z + direction * (width / 2 + 0.18),
colors.green
);
}
}
}
function addDoor(side, z, bottom, width = 1.22) {
const height = 2.12;
const x = side * (LANE_HALF - 0.045);
// Dark reveal and timber leaf.
box(0.08, height, width + 0.14, x, bottom + height / 2, z, colors.dark, false);
box(
0.07,
height - 0.12,
width - 0.12,
side * (LANE_HALF - 0.095),
bottom + (height - 0.12) / 2,
z,
colors.wood,
false
);
// Door panels.
for (const y of [bottom + 0.56, bottom + 1.43]) {
box(
0.025,
0.61,
width - 0.33,
side * (LANE_HALF - 0.14),
y,
z,
0x7b4934,
false
);
}
// Frame and lintel.
box(0.16, height + 0.14, 0.12, side * (LANE_HALF - 0.12), bottom + height / 2, z - width / 2, colors.cream);
box(0.16, height + 0.14, 0.12, side * (LANE_HALF - 0.12), bottom + height / 2, z + width / 2, colors.cream);
box(0.18, 0.15, width + 0.30, side * (LANE_HALF - 0.11), bottom + height + 0.02, z, colors.cream);
// Handle.
box(
0.08,
0.12,
0.08,
side * (LANE_HALF - 0.17),
bottom + 1.03,
z + width * 0.28,
0xd9ad54,
false
);
// Stone threshold projecting into the lane.
box(
0.82,
0.14,
width + 0.32,
side * (LANE_HALF - 0.40),
bottom + 0.07,
z,
0xbba184
);
}
function addBalcony(side, z, y, width = 1.72) {
// Slab and underside brackets.
box(
1.00,
0.13,
width,
side * (LANE_HALF - 0.48),
y,
z,
colors.cream
);
for (const dz of [-width * 0.32, width * 0.32]) {
box(
0.70,
0.12,
0.12,
side * (LANE_HALF - 0.31),
y - 0.14,
z + dz,
colors.wood
);
}
// Front rail.
const railX = side * (LANE_HALF - 0.95);
box(0.08, 0.08, width, railX, y + 0.94, z, colors.iron);
box(0.08, 0.08, width, railX, y + 0.48, z, colors.iron);
const balusterCount = 7;
for (let i = 0; i < balusterCount; i++) {
const bz = z - width / 2 + (width / (balusterCount - 1)) * i;
box(0.065, 0.92, 0.065, railX, y + 0.49, bz, colors.iron);
}
// Return rails at each end.
for (const dz of [-width / 2, width / 2]) {
box(0.08, 0.92, 0.08, railX, y + 0.49, z + dz, colors.iron);
box(
0.95,
0.08,
0.08,
side * (LANE_HALF - 0.48),
y + 0.94,
z + dz,
colors.iron
);
}
// Small voxel planter.
const potZ = z + width * 0.30;
box(
0.30,
0.28,
0.38,
side * (LANE_HALF - 0.55),
y + 0.21,
potZ,
0xa94f38
);
box(
0.28,
0.24,
0.30,
side * (LANE_HALF - 0.55),
y + 0.43,
potZ,
colors.green
);
box(
0.20,
0.20,
0.22,
side * (LANE_HALF - 0.55),
y + 0.62,
potZ,
0x668554
);
}
function addLamp(side, z, y) {
box(
0.18,
0.08,
0.08,
side * (LANE_HALF - 0.10),
y + 0.16,
z,
colors.iron
);
box(
0.18,
0.28,
0.20,
side * (LANE_HALF - 0.24),
y,
z,
0xf0b95f
);
box(
0.22,
0.06,
0.24,
side * (LANE_HALF - 0.24),
y + 0.16,
z,
colors.iron
);
}
// ------------------------------------------------------------
// Opposing facades
// ------------------------------------------------------------
addBuilding(-1, -7.2, -2.2, 0.00, 5.90, colors.coral);
addBuilding(-1, -2.2, 2.4, 0.62, 6.50, colors.rose);
addBuilding(-1, 2.4, 7.8, 1.55, 5.80, colors.ochre);
addBuilding( 1, -7.2, -3.0, 0.00, 5.00, colors.teal);
addBuilding( 1, -3.0, 3.2, 0.65, 7.20, colors.ochre);
addBuilding( 1, 3.2, 7.8, 1.80, 6.40, colors.red);
// Hero left facade: ground doorway and upper balcony.
addDoor(-1, -4.78, 0.00, 1.22);
addWindow(-1, -4.78, 3.72, 1.16, 1.58, false);
addBalcony(-1, -4.78, 2.82, 1.86);
addWindow(-1, -6.43, 3.70, 0.88, 1.18);
addWindow(-1, -6.45, 1.30, 0.78, 1.08);
addWindow(-1, -3.08, 3.76, 0.80, 1.10);
addLamp(-1, -3.78, 2.34);
// Left middle facade.
addWindow(-1, -1.16, 2.02, 0.90, 1.20);
addWindow(-1, 1.10, 2.02, 0.82, 1.16);
addWindow(-1, -1.10, 5.02, 0.94, 1.18);
addWindow(-1, 1.14, 5.02, 0.84, 1.18);
addDoor(-1, 0.05, 1.05, 1.04);
// Left rear facade.
addWindow(-1, 3.72, 3.35, 0.92, 1.18);
addWindow(-1, 6.20, 3.35, 0.84, 1.14);
addWindow(-1, 3.78, 5.72, 0.92, 1.18);
addWindow(-1, 6.18, 5.72, 0.84, 1.14);
// Right foreground facade.
addWindow(1, -6.38, 1.30, 0.90, 1.16);
addWindow(1, -4.18, 1.30, 0.84, 1.12);
addWindow(1, -6.38, 3.55, 0.90, 1.18);
addWindow(1, -4.18, 3.55, 0.84, 1.18);
addDoor(1, -5.30, 0.00, 1.06);
// Right middle facade, opposite the hero fragment.
addDoor(1, -1.45, 0.45, 1.16);
addWindow(1, 0.70, 2.05, 0.92, 1.22);
addWindow(1, 2.25, 2.05, 0.82, 1.16);
addWindow(1, -0.92, 5.10, 0.92, 1.18);
addWindow(1, 1.00, 5.10, 0.90, 1.18);
addBalcony(1, 0.95, 4.22, 1.38);
addLamp(1, -2.22, 2.38);
// Right rear facade.
addWindow(1, 4.38, 3.38, 0.88, 1.16);
addWindow(1, 6.55, 3.38, 0.86, 1.16);
addWindow(1, 4.42, 5.72, 0.90, 1.18);
addWindow(1, 6.55, 5.72, 0.86, 1.18);
// ------------------------------------------------------------
// Far end: stepped voxel archway
// ------------------------------------------------------------
const archBase = 3.10;
const archZ = 8.05;
box(4.45, 5.20, 1.35, -3.60, archBase + 2.60, archZ + 0.52, colors.rose);
box(4.45, 5.20, 1.35, 3.60, archBase + 2.60, archZ + 0.52, colors.teal);
box(7.20, 1.55, 1.35, 0, archBase + 4.73, archZ + 0.52, colors.ochre);
// Recessed dark passage.
box(2.68, 3.82, 0.18, 0, archBase + 1.91, archZ + 1.11, 0x253437, false);
box(2.44, 0.20, 0.30, 0, archBase + 0.08, archZ + 0.98, 0x806956, false);
// Stepped arch stones.
const archPositions = [
[-1.28, 3.02], [-1.02, 3.55], [-0.50, 3.90],
[0.00, 4.02], [0.50, 3.90], [1.02, 3.55], [1.28, 3.02]
];
for (const [x, y] of archPositions) {
box(0.48, 0.43, 0.22, x, archBase + y, archZ - 0.03, colors.cream);
}
// Small distant blocks visible through the passage.
box(0.70, 1.45, 0.75, -0.65, archBase + 0.72, archZ + 1.48, 0xcb7850, false);
box(0.85, 1.75, 0.80, 0.62, archBase + 0.87, archZ + 1.48, 0xd5ad65, false);
// ------------------------------------------------------------
// Scale figure, signs and street details
// ------------------------------------------------------------
function addPerson(x, z, heading = 0) {
const y = streetY(z);
const group = new THREE.Group();
function personBox(w, h, d, px, py, pz, color) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(w, h, d);
mesh.position.set(px, py, pz);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
personBox(0.18, 0.52, 0.19, -0.12, 0.28, 0, 0x334b55);
personBox(0.18, 0.52, 0.19, 0.12, 0.28, 0, 0x334b55);
personBox(0.48, 0.68, 0.28, 0, 0.86, 0, 0xb8533f);
personBox(0.12, 0.54, 0.18, -0.32, 0.83, 0, 0xb8533f);
personBox(0.12, 0.54, 0.18, 0.32, 0.83, 0, 0xb8533f);
personBox(0.31, 0.33, 0.30, 0, 1.36, 0, 0xc99069);
personBox(0.35, 0.09, 0.34, 0, 1.54, 0, 0x5f4537);
group.position.set(x, y, z);
group.rotation.y = heading;
scene.add(group);
}
addPerson(0.72, 0.55, -0.12);
addPerson(-0.35, 5.02, 0.45);
// A slim level gauge near the foreground.
for (let i = 0; i < 8; i++) {
box(
0.14,
0.13,
0.14,
1.95,
0.065 + i * 0.13,
-5.65,
i % 2 === 0 ? 0xf0dfbd : 0xb84d3a,
false
);
}
// Voxel cactus against the right foreground wall.
const cactusX = 2.31;
const cactusZ = -6.55;
box(0.28, 0.92, 0.28, cactusX, 0.46, cactusZ, 0x527454, false);
box(0.22, 0.40, 0.22, cactusX - 0.20, 0.52, cactusZ, 0x527454, false);
box(0.22, 0.32, 0.22, cactusX + 0.20, 0.68, cactusZ, 0x527454, false);
box(0.44, 0.10, 0.44, cactusX, 0.05, cactusZ, 0xa75b42, false);
// ------------------------------------------------------------
// Camera controls implemented directly, without addons
// ------------------------------------------------------------
const desired = {
theta: Math.PI,
phi: 1.25,
radius: 17.2,
target: new THREE.Vector3(0, 2.35, 0.35)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
const pointers = new Map();
let lastPinchDistance = 0;
let dragged = false;
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragged = false;
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (Math.abs(dx) + Math.abs(dy) > 1) dragged = true;
if (pointers.size === 1) {
desired.theta -= dx * 0.0048;
desired.phi = THREE.MathUtils.clamp(
desired.phi + dy * 0.0042,
0.68,
1.42
);
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (lastPinchDistance / distance),
10.5,
25
);
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.008,
10.5,
25
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => setView("street"));
function setView(name) {
if (name === "street") {
desired.theta = Math.PI;
desired.phi = 1.25;
desired.radius = 17.2;
desired.target.set(0, 2.35, 0.35);
} else {
desired.theta = Math.PI - 0.55;
desired.phi = 0.82;
desired.radius = 20.0;
desired.target.set(0, 2.10, 0.65);
}
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
document.getElementById("reset").addEventListener("click", () => setView("street"));
const annotationLayer = document.getElementById("annotations");
const labelToggle = document.getElementById("labelToggle");
labelToggle.addEventListener("click", () => {
const isOff = annotationLayer.classList.toggle("off");
labelToggle.classList.toggle("active", !isOff);
labelToggle.setAttribute("aria-pressed", String(!isOff));
});
// ------------------------------------------------------------
// Projected HTML annotations
// ------------------------------------------------------------
const annotations = [
{
element: document.getElementById("ann-balcony"),
point: new THREE.Vector3(-2.60, 3.90, -4.78),
offset: [-44, -8]
},
{
element: document.getElementById("ann-door"),
point: new THREE.Vector3(-2.57, 1.15, -4.78),
offset: [-42, 18]
},
{
element: document.getElementById("ann-span"),
point: new THREE.Vector3(0.00, 3.28, -0.80),
offset: [0, -10]
},
{
element: document.getElementById("ann-grade"),
point: new THREE.Vector3(1.25, 1.75, 4.35),
offset: [43, 18]
}
];
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
const projected = annotation.point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
annotation.element.style.display = visible ? "flex" : "none";
if (visible) {
annotation.element.style.left =
`${(projected.x * 0.5 + 0.5) * width + annotation.offset[0]}px`;
annotation.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height + annotation.offset[1]}px`;
}
}
}
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-dt * 8.5);
current.theta += (desired.theta - current.theta) * smoothing;
current.phi += (desired.phi - current.phi) * smoothing;
current.radius += (desired.radius - current.radius) * smoothing;
current.target.lerp(desired.target, smoothing);
const horizontal = current.radius * Math.sin(current.phi);
camera.position.set(
current.target.x + horizontal * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + horizontal * Math.cos(current.theta)
);
camera.lookAt(current.target);
updateAnnotations();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
document.getElementById("loading").classList.add("hide");
</script>
</body>
</html>
```