Prompt specification
Build or customize the Three.js 3D scene "Guanajuato hillside street junction scene" 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 hillside street junction scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/guanajuato-hillside-street-junction-scene-x2739
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Guanajuato's hillside lanes. Build a bounded voxel block with colorful referenced facades, narrow lanes, stair connections, and steep terrain. Avoid combining distant landmarks into an impossible single junction. Voxel style.
Working Three.js Starter (guanajuato-hillside-street-junction-scene-x2739):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Guanajuato — Voxel Hillside Lanes</title>
<style>
:root {
--ink: #2c2928;
--paper: rgba(255, 250, 241, 0.92);
--accent: #bd665d;
--line: rgba(74, 54, 46, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e2dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
touch-action: none;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 17px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 4px;
box-shadow: 0 12px 40px rgba(65, 42, 35, 0.13);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 6px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 4vw, 38px);
font-weight: 500;
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 10px;
color: rgba(44, 41, 40, 0.72);
font-size: 12px;
line-height: 1.55;
}
.palette {
display: flex;
gap: 5px;
margin-top: 13px;
}
.palette span {
width: 21px;
height: 7px;
border-radius: 1px;
}
#controls {
position: absolute;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 4px;
box-shadow: 0 10px 30px rgba(65, 42, 35, 0.12);
pointer-events: auto;
backdrop-filter: blur(12px);
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 3px;
padding: 9px 12px;
background: rgba(255, 255, 255, 0.52);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
}
button:hover {
background: white;
}
button.active {
border-color: var(--accent);
background: var(--accent);
color: white;
}
.hint {
position: absolute;
left: 22px;
bottom: 22px;
max-width: 340px;
padding: 10px 12px;
background: rgba(255, 250, 241, 0.76);
border-left: 2px solid var(--accent);
color: rgba(44, 41, 40, 0.74);
font-size: 10px;
line-height: 1.55;
letter-spacing: 0.02em;
backdrop-filter: blur(8px);
}
.world-label {
position: absolute;
z-index: 3;
min-width: 116px;
padding: 7px 9px;
background: rgba(255, 250, 241, 0.91);
border: 1px solid rgba(74, 54, 46, 0.16);
border-radius: 3px;
box-shadow: 0 6px 18px rgba(65, 42, 35, 0.12);
text-align: center;
transform: translate(-50%, -100%);
pointer-events: none;
transition: opacity 120ms linear;
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 14px;
background: rgba(74, 54, 46, 0.45);
}
.world-label strong {
display: block;
font-size: 9px;
letter-spacing: 0.13em;
}
.world-label small {
display: block;
margin-top: 2px;
color: rgba(44, 41, 40, 0.6);
font-size: 8px;
}
#districtTag {
position: absolute;
top: 22px;
right: 22px;
padding: 9px 11px;
background: rgba(44, 41, 40, 0.76);
color: #fff9ef;
border-radius: 3px;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
@media (max-width: 720px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
display: none;
}
#districtTag {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
}
.hint {
left: 12px;
bottom: 67px;
max-width: calc(100vw - 24px);
}
}
</style>
</head>
<body>
<div id="ui">
<section class="panel">
<div class="eyebrow">Voxel district 01 · Mexico</div>
<h1>Guanajuato<br />Hillside Lanes</h1>
<p class="subtitle">
A compact terraced block of rose-quarry masonry, saturated portals,
shuttered windows, iron balconies, and steep pedestrian stair lanes.
</p>
<div class="palette" aria-label="Facade palette">
<span style="background:#d8757c"></span>
<span style="background:#e8a35d"></span>
<span style="background:#79a99e"></span>
<span style="background:#8ca7bf"></span>
<span style="background:#c78f7b"></span>
<span style="background:#ead9ba"></span>
</div>
</section>
<div id="districtTag">Lower chapel / upper belvedere · separate districts</div>
<div class="hint" id="hint">
<strong>Overview:</strong> drag to orbit · wheel to zoom · WASD to pan ·
Q/E to change height.<br />
<strong>Street:</strong> drag to look · WASD to walk · wheel to move forward.
</div>
<div id="controls">
<button id="overviewBtn" class="active">Overview</button>
<button id="streetBtn">Street view</button>
<button id="resetBtn">Reset</button>
</div>
<div id="chapelLabel" class="world-label">
<strong>LOWER CHAPEL</strong>
<small>western lower district</small>
</div>
<div id="belvedereLabel" class="world-label">
<strong>UPPER BELVEDERE</strong>
<small>eastern upper terrace</small>
</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e2dc);
scene.fog = new THREE.Fog(0xd8e2dc, 88, 165);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
240
);
camera.rotation.order = "YXZ";
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
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 hemi = new THREE.HemisphereLight(0xf9f1df, 0x75665f, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe4b8, 3.25);
sun.position.set(-34, 62, 38);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -52;
sun.shadow.camera.right = 52;
sun.shadow.camera.top = 54;
sun.shadow.camera.bottom = -54;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 140;
sun.shadow.bias = -0.0003;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaac9d7, 0.72);
fill.position.set(38, 22, -35);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
// -------------------------------------------------------------------------
// Shared voxel construction helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, metalness = 0, roughness = 0.86, emissive = null) {
const key = `${color}|${metalness}|${roughness}|${emissive || ""}`;
if (!materialCache.has(key)) {
const options = {
color,
metalness,
roughness
};
if (emissive) {
options.emissive = new THREE.Color(emissive);
options.emissiveIntensity = 1.25;
}
materialCache.set(key, new THREE.MeshStandardMaterial(options));
}
return materialCache.get(key);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const mesh = new THREE.Mesh(
unitBox,
material(
color,
options.metalness || 0,
options.roughness || 0.86,
options.emissive || null
)
);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
let seed = 83741;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function pick(list) {
return list[Math.floor(random() * list.length)];
}
// -------------------------------------------------------------------------
// Palette and bounded stepped terrain
// -------------------------------------------------------------------------
const palette = [
"#d8757c",
"#e3a05c",
"#7fa99d",
"#8ca7bf",
"#c76759",
"#c99091",
"#e7d3a9",
"#d9b27e",
"#aeb88e",
"#b98073"
];
const cantera = "#c78f7b";
const canteraDark = "#a96f64";
const roadColor = "#a58e80";
const tileColors = ["#b9573f", "#c76748", "#d47b55", "#a94c3b"];
const iron = "#344441";
const glass = "#294b4c";
const roadStoneColors = ["#aa9585", "#b49e8c", "#9d887a", "#bba795"];
const terraces = [
{ z0: -34, z1: -19, top: 16.0 },
{ z0: -17, z1: -5, top: 11.5 },
{ z0: -3, z1: 8, top: 7.0 },
{ z0: 10, z1: 19, top: 3.5 },
{ z0: 21, z1: 32, top: 0.0 }
];
box(
world,
66,
1.0,
69,
0,
-2.3,
-1,
"#8e5c59"
);
box(
world,
180,
0.25,
180,
0,
-2.95,
0,
"#d1d8cf",
{ castShadow: false }
);
for (const terrace of terraces) {
const depth = terrace.z1 - terrace.z0;
const centerZ = (terrace.z0 + terrace.z1) * 0.5;
const bottom = -1.8;
const bodyTop = terrace.top - 0.14;
box(
world,
64,
bodyTop - bottom,
depth,
0,
(bodyTop + bottom) * 0.5,
centerZ,
cantera
);
box(
world,
64,
0.14,
depth,
0,
terrace.top - 0.07,
centerZ,
"#d1aa89"
);
// Horizontal quarry-stone courses on exposed terrace faces.
for (let y = Math.max(0.4, terrace.top - 2.4); y > bottom; y -= 1.35) {
box(
world,
64,
0.11,
0.08,
0,
y,
terrace.z1 + 0.025,
canteraDark,
{ castShadow: false }
);
}
// Sparse individual masonry blocks emphasize the stepped retaining walls.
for (let x = -29; x < 30; x += 3.1) {
const blockHeight = 0.45 + random() * 0.45;
const blockY = bottom + 0.6 + random() * Math.max(0.4, terrace.top - 1.1);
if (blockY + blockHeight * 0.5 < terrace.top) {
box(
world,
1.7 + random() * 1.1,
blockHeight,
0.07,
x + random() * 0.7,
blockY,
terrace.z1 + 0.045,
random() > 0.5 ? "#b77b70" : "#cd947d",
{ castShadow: false }
);
}
}
// Side strata visible on the bounded diorama.
for (const side of [-1, 1]) {
for (let y = bottom + 0.8; y < terrace.top; y += 1.25) {
box(
world,
0.08,
0.11,
depth,
side * 32.02,
y,
centerZ,
canteraDark,
{ castShadow: false }
);
}
}
}
// -------------------------------------------------------------------------
// Roads, cobbles and stair lanes
// -------------------------------------------------------------------------
function addRoad(ground, z, depth = 3.15) {
box(
world,
61.5,
0.09,
depth,
0,
ground + 0.045,
z,
roadColor,
{ castShadow: false }
);
for (let i = 0; i < 145; i++) {
const x = -30.2 + random() * 60.4;
const stoneZ = z + (random() - 0.5) * (depth - 0.35);
if (Math.abs(x) < 3.0) continue;
box(
world,
0.25 + random() * 0.55,
0.035,
0.22 + random() * 0.42,
x,
ground + 0.115,
stoneZ,
pick(roadStoneColors),
{ castShadow: false }
);
}
// Narrow stone gutters.
for (const side of [-1, 1]) {
box(
world,
61.5,
0.09,
0.16,
0,
ground + 0.065,
z + side * (depth * 0.5 + 0.08),
"#c3aa91",
{ castShadow: false }
);
}
}
addRoad(0, 27.8, 4.2);
addRoad(3.5, 14.5);
addRoad(7.0, 2.5);
addRoad(11.5, -10.5);
addRoad(16.0, -26.0);
function addStair(x, zLow, zHigh, yLow, yHigh, width = 4.2, steps = 13) {
const run = (zLow - zHigh) / steps;
const rise = (yHigh - yLow) / steps;
const bottom = -1.75;
for (let i = 0; i < steps; i++) {
const z = zLow - (i + 0.5) * run;
const top = yLow + (i + 1) * rise;
const height = top - bottom;
box(
world,
width,
height,
run + 0.025,
x,
bottom + height * 0.5,
z,
i % 2 ? "#bd8876" : "#c79480"
);
box(
world,
width,
0.065,
0.075,
x,
top + 0.025,
z + run * 0.44,
"#9f6d64",
{ castShadow: false }
);
for (const side of [-1, 1]) {
box(
world,
0.32,
height,
run + 0.04,
x + side * (width * 0.5 + 0.14),
bottom + height * 0.5,
z,
"#b37c6e"
);
}
}
// Boxy iron handrails following each short, steep flight.
for (const side of [-1, 1]) {
const railX = x + side * (width * 0.5 + 0.08);
const railPoints = [];
for (let i = 0; i <= steps; i += 3) {
const z = zLow - i * run;
const y = yLow + i * rise;
const postHeight = 0.95;
box(
world,
0.09,
postHeight,
0.09,
railX,
y + postHeight * 0.5,
z,
iron
);
railPoints.push(new THREE.Vector3(railX, y + postHeight, z));
}
for (let i = 0; i < railPoints.length - 1; i++) {
const a = railPoints[i];
const b = railPoints[i + 1];
const delta = new THREE.Vector3().subVectors(b, a);
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const rail = box(
world,
0.08,
0.08,
delta.length(),
midpoint.x,
midpoint.y,
midpoint.z,
iron
);
rail.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
delta.clone().normalize()
);
}
}
}
addStair(0, 21, 19, 0, 3.5, 4.3, 14);
addStair(0, 10, 8, 3.5, 7.0, 4.2, 13);
addStair(0, -3, -5, 7.0, 11.5, 4.15, 14);
addStair(0, -17, -19, 11.5, 16.0, 4.1, 14);
// -------------------------------------------------------------------------
// Colonial-inspired voxel facades
// -------------------------------------------------------------------------
function addDoor(group, dir, depth, trim, accent) {
const surface = dir * (depth * 0.5);
const z = surface + dir * 0.07;
box(group, 1.35, 2.35, 0.12, 0, 1.18, z, "#503e37");
box(group, 1.02, 2.08, 0.12, 0, 1.13, z + dir * 0.065, accent);
box(group, 0.14, 2.35, 0.18, -0.73, 1.18, z + dir * 0.02, trim);
box(group, 0.14, 2.35, 0.18, 0.73, 1.18, z + dir * 0.02, trim);
box(group, 1.62, 0.18, 0.2, 0, 2.42, z + dir * 0.025, trim);
box(group, 1.68, 0.12, 0.34, 0, 0.06, surface + dir * 0.17, "#b9836f");
box(group, 1.9, 0.13, 0.48, 0, -0.04, surface + dir * 0.3, "#d0a081");
box(
group,
0.08,
0.08,
0.08,
0.35,
1.18,
z + dir * 0.14,
"#e9c477",
{ metalness: 0.55, roughness: 0.35 }
);
}
function addWindow(
group,
dir,
depth,
u,
y,
width,
height,
trim,
accent,
style,
balcony = false
) {
const surface = dir * (depth * 0.5);
const z = surface + dir * 0.07;
box(group, width, height, 0.12, u, y, z, glass);
for (const side of [-1, 1]) {
box(
group,
0.13,
height + 0.22,
0.17,
u + side * (width * 0.5 + 0.04),
y,
z + dir * 0.035,
trim
);
}
box(group, width + 0.26, 0.14, 0.18, u, y - height * 0.5 - 0.08, z + dir * 0.035, trim);
box(group, width + 0.3, 0.16, 0.22, u, y + height * 0.5 + 0.08, z + dir * 0.04, trim);
if (style % 2 === 0) {
box(
group,
width * 0.42,
height * 0.96,
0.12,
u - width * 0.73,
y,
z + dir * 0.06,
accent
);
box(
group,
0.05,
height * 0.92,
0.14,
u - width * 0.56,
y,
z + dir * 0.085,
trim,
{ castShadow: false }
);
} else {
box(
group,
width * 0.36,
height * 0.98,
0.12,
u + width * 0.76,
y,
z + dir * 0.06,
accent
);
}
if (style % 3 === 2) {
// Stepped, block-built arch instead of a curved opening.
box(group, width * 0.66, 0.16, 0.18, u, y + height * 0.5 + 0.15, z + dir * 0.04, trim);
box(group, width * 0.34, 0.16, 0.18, u, y + height * 0.5 + 0.29, z + dir * 0.04, trim);
}
if (balcony) {
const balconyZ = surface + dir * 0.5;
const floorY = y - height * 0.5 - 0.28;
box(group, width + 1.05, 0.11, 0.92, u, floorY, balconyZ, iron);
box(group, width + 1.05, 0.07, 0.07, u, y + 0.03, balconyZ + dir * 0.42, iron);
for (let i = -3; i <= 3; i++) {
box(
group,
0.055,
0.88,
0.055,
u + i * ((width + 0.8) / 7),
floorY + 0.43,
balconyZ + dir * 0.42,
iron
);
}
for (const side of [-1, 1]) {
box(
group,
0.055,
0.88,
0.055,
u + side * (width * 0.5 + 0.5),
floorY + 0.43,
balconyZ,
iron
);
}
}
if (style % 4 === 3) {
const potZ = surface + dir * 0.32;
box(group, 0.48, 0.28, 0.28, u, y - height * 0.5 - 0.22, potZ, "#b76451");
box(group, 0.38, 0.34, 0.26, u, y - height * 0.5 - 0.02, potZ, "#668a63");
}
}
function addAwning(group, dir, depth, width, accent) {
const z = dir * (depth * 0.5 + 0.42);
const count = 8;
const stripeWidth = width / count;
for (let i = 0; i < count; i++) {
box(
group,
stripeWidth + 0.01,
0.12,
0.86,
-width * 0.5 + stripeWidth * (i + 0.5),
3.25,
z,
i % 2 ? "#f1dfbb" : accent
);
}
for (const x of [-width * 0.48, width * 0.48]) {
box(group, 0.07, 0.95, 0.07, x, 2.82, z + dir * 0.31, iron);
}
}
function makeBuilding({
x,
z,
ground,
width,
depth,
height,
color,
accent,
style = 0,
dir = 1
}) {
const group = new THREE.Group();
group.position.set(x, ground, z);
world.add(group);
const trim = style % 2 ? "#e2c29b" : "#d8a28a";
box(group, width + 0.18, 0.42, depth + 0.18, 0, 0.21, 0, cantera);
box(group, width, height, depth, 0, height * 0.5 + 0.35, 0, color);
box(group, width + 0.24, 0.18, depth + 0.24, 0, 0.53, 0, trim);
box(group, width + 0.3, 0.23, depth + 0.3, 0, height + 0.23, 0, trim);
// A thin color band helps separate the upper facade from the quarry base.
if (style % 2 === 0) {
box(
group,
width + 0.08,
0.13,
depth + 0.08,
0,
height * 0.54,
0,
accent,
{ castShadow: false }
);
}
addDoor(group, dir, depth, trim, accent);
const lowerY = 2.75;
addWindow(
group,
dir,
depth,
-width * 0.29,
lowerY,
0.94,
1.48,
trim,
accent,
style
);
addWindow(
group,
dir,
depth,
width * 0.29,
lowerY,
0.94,
1.48,
trim,
accent,
style
);
if (height > 6.2) {
const upperY = height > 8.5 ? 6.25 : 4.9;
const positions = [-width * 0.27, 0, width * 0.27];
positions.forEach((u, index) => {
addWindow(
group,
dir,
depth,
u,
upperY,
index === 1 ? 1.08 : 0.92,
1.65,
trim,
accent,
style,
style % 3 === 1 && index === 1
);
});
}
if (height > 9.2) {
const topY = 8.25;
addWindow(group, dir, depth, -width * 0.22, topY, 0.9, 1.35, trim, accent, style);
addWindow(group, dir, depth, width * 0.22, topY, 0.9, 1.35, trim, accent, style);
}
// Sparse windows on the side walls.
for (const side of [-1, 1]) {
const sideZ = depth * 0.12;
box(
group,
0.1,
1.28,
0.72,
side * (width * 0.5 + 0.02),
3.15,
sideZ,
glass
);
box(
group,
0.16,
0.12,
0.92,
side * (width * 0.5 + 0.05),
2.47,
sideZ,
trim
);
}
if (style % 5 === 4) {
addAwning(group, dir, depth, Math.min(width - 0.7, 5.6), accent);
}
if (style % 3 === 0) {
// Stepped terracotta roof.
const rows = 4;
for (let i = 0; i < rows; i++) {
const rowDepth = depth / rows + 0.045;
const rowZ = -depth * 0.5 + (i + 0.5) * (depth / rows);
const rowY = height + 0.43 + i * 0.15;
box(
group,
width + 0.34,
0.2,
rowDepth,
0,
rowY,
rowZ,
tileColors[(style + i) % tileColors.length]
);
}
box(
group,
width + 0.4,
0.18,
0.3,
0,
height + 0.96,
depth * 0.5 - 0.1,
"#a84e3b"
);
box(group, 0.62, 1.35, 0.62, width * 0.25, height + 1.1, -depth * 0.22, "#bd7054");
box(group, 0.75, 0.18, 0.75, width * 0.25, height + 1.83, -depth * 0.22, "#a95742");
} else {
// Flat roof with a low parapet and terracotta floor.
box(group, width + 0.24, 0.18, depth + 0.24, 0, height + 0.43, 0, "#ba6047");
for (const side of [-1, 1]) {
box(
group,
width + 0.35,
0.58,
0.22,
0,
height + 0.75,
side * (depth * 0.5 + 0.05),
color
);
box(
group,
0.22,
0.58,
depth + 0.35,
side * (width * 0.5 + 0.05),
height + 0.75,
0,
color
);
}
}
return group;
}
// -------------------------------------------------------------------------
// Dense rows of houses, with a clear gap around the stair lane
// -------------------------------------------------------------------------
function addHouseRow(ground, z, dir, xs, heightBias = 0) {
xs.forEach((x, index) => {
const width = 4.8 + (index % 3) * 0.7;
const depth = 3.5 + (index % 2) * 0.35;
const height = 5.7 + ((index * 1.31 + heightBias) % 3.6);
makeBuilding({
x,
z,
ground,
width,
depth,
height,
color: palette[(index * 3 + Math.round(heightBias)) % palette.length],
accent: palette[(index * 5 + 2) % palette.length],
style: (index + Math.round(heightBias)) % 6,
dir
});
});
}
// Middle terrace: warm row on the downhill side, cool row above.
addHouseRow(3.5, 11.65, 1, [-24, -16, -8, 8, 16, 24], 0);
addHouseRow(3.5, 17.35, -1, [-23, -15, -7, 7, 15, 23], 2);
addHouseRow(7.0, -1.0, 1, [-24, -16, -8, 8, 16, 24], 3);
addHouseRow(7.0, 6.0, -1, [-23, -15, -7, 7, 15, 23], 1);
addHouseRow(11.5, -13.0, 1, [-25, -17, -9, 8, 16, 24], 4);
addHouseRow(11.5, -7.9, -1, [-24, -16, -8, 8, 16, 24], 2);
// Upper district leaves the eastern side open for the belvedere.
addHouseRow(16.0, -29.5, 1, [-25, -17, -9, 6], 1);
addHouseRow(16.0, -22.8, -1, [-24, -16, -8, 5], 3);
// Low shops at the far edge of the lower district.
[12, 19, 26].forEach((x, index) => {
makeBuilding({
x,
z: 26.5,
ground: 0,
width: 5.4,
depth: 4.1,
height: 4.65,
color: palette[(index + 3) % palette.length],
accent: palette[(index + 6) % palette.length],
style: 4,
dir: 1
});
});
// -------------------------------------------------------------------------
// Lower chapel — intentionally placed in the western lower district
// -------------------------------------------------------------------------
const chapel = new THREE.Group();
chapel.position.set(-21, 0, 25.4);
world.add(chapel);
box(chapel, 16.5, 0.18, 5.7, 0, 0.09, 3.3, "#b8a08a");
box(chapel, 8.7, 0.48, 9.2, 0, 0.24, 0, cantera);
box(chapel, 8.0, 7.2, 8.2, 0, 3.96, 0, "#d8b46f");
box(chapel, 8.35, 0.24, 8.55, 0, 7.55, 0, "#ead3a4");
addDoor(chapel, 1, 8.2, "#ead3a4", "#9d5149");
addWindow(chapel, 1, 8.2, -2.55, 3.65, 0.95, 1.8, "#ead3a4", "#688a76", 2);
addWindow(chapel, 1, 8.2, 2.55, 3.65, 0.95, 1.8, "#ead3a4", "#688a76", 2);
// Simple buttresses.
for (const x of [-4.15, 4.15]) {
box(chapel, 0.45, 4.6, 1.1, x, 2.4, 3.9, "#e4c584");
box(chapel, 0.65, 0.24, 1.3, x, 4.72, 3.9, "#f0dba4");
}
// Attached bell tower.
box(chapel, 2.7, 10.9, 3.6, -3.55, 5.45, -0.65, "#d9b36d");
box(chapel, 3.05, 0.3, 3.95, -3.55, 10.93, -0.65, "#ead3a4");
box(chapel, 2.2, 1.45, 0.13, -3.55, 8.3, 1.16, "#493b36");
for (let i = 0; i < 4; i++) {
const size = 3.0 - i * 0.62;
box(
chapel,
size,
0.46,
size,
-3.55,
11.2 + i * 0.4,
-0.65,
i % 2 ? "#b96e53" : "#c77d58"
);
}
box(chapel, 0.12, 1.1, 0.12, -3.55, 13.18, -0.65, iron);
box(chapel, 0.68, 0.12, 0.12, -3.55, 13.48, -0.65, iron);
// -------------------------------------------------------------------------
// Upper belvedere — a separate landmark on the far eastern upper terrace
// -------------------------------------------------------------------------
const belvedere = new THREE.Group();
belvedere.position.set(18, 16, -31.1);
world.add(belvedere);
box(belvedere, 13.5, 0.48, 5.2, 0, 0.24, 0, "#b88772");
box(belvedere, 13.0, 0.12, 4.7, 0, 0.54, 0, "#d0a47f");
for (const x of [-5.7, 5.7]) {
box(belvedere, 0.4, 3.5, 4.4, x, 2.3, 0, "#d2a06f");
}
for (let i = 0; i < 5; i++) {
const x = -4.5 + i * 2.25;
box(belvedere, 0.62, 3.1, 0.62, x, 2.2, -1.3, "#dfb67b");
box(belvedere, 0.82, 0.24, 0.82, x, 3.85, -1.3, "#efd29b");
}
box(belvedere, 12.2, 0.35, 4.35, 0, 4.13, 0, "#d8b175");
box(belvedere, 12.7, 0.18, 4.75, 0, 4.38, 0, "#bf7454");
// Low side parapets leave the downhill view open.
for (const x of [-5.9, 5.9]) {
box(belvedere, 0.35, 1.0, 4.6, x, 1.1, 0, "#c98c6f");
}
// -------------------------------------------------------------------------
// Lower plaza fountain, lamps, trees and people
// -------------------------------------------------------------------------
box(world, 3.4, 0.35, 3.4, 0, 0.175, 26.2, "#b97e6d");
box(world, 2.8, 0.12, 2.8, 0, 0.41, 26.2, "#6f9fa0");
box(world, 0.65, 1.15, 0.65, 0, 0.98, 26.2, "#c88b75");
box(world, 1.4, 0.18, 1.4, 0, 1.58, 26.2, "#d6a07f");
box(world, 0.26, 0.8, 0.26, 0, 1.93, 26.2, "#d6a07f");
function addLamp(x, ground, z) {
box(world, 0.18, 0.25, 0.18, x, ground + 0.12, z, iron);
box(world, 0.11, 2.8, 0.11, x, ground + 1.55, z, iron);
box(world, 0.48, 0.55, 0.48, x, ground + 3.1, z, "#f2cf88", {
emissive: "#d89143"
});
box(world, 0.62, 0.14, 0.62, x, ground + 3.43, z, iron);
box(world, 0.52, 0.12, 0.52, x, ground + 2.8, z, iron);
}
[
[-6, 0, 22.7],
[6, 0, 22.7],
[-6, 3.5, 16.35],
[6, 3.5, 16.35],
[-11, 7, 4.35],
[11, 7, 4.35],
[-6, 11.5, -8.65],
[6, 11.5, -8.65],
[-12, 16, -24.2],
[5, 16, -24.2]
].forEach(([x, y, z]) => addLamp(x, y, z));
function addCypress(x, ground, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, ground, z);
group.scale.setScalar(scale);
world.add(group);
box(group, 0.35, 2.2, 0.35, 0, 1.1, 0, "#795a43");
box(group, 1.55, 2.0, 1.55, 0, 2.6, 0, "#526e50");
box(group, 1.25, 1.7, 1.25, 0, 4.0, 0, "#607b57");
box(group, 0.85, 1.35, 0.85, 0, 5.15, 0, "#718a5f");
box(group, 0.45, 0.95, 0.45, 0, 6.0, 0, "#7b9163");
}
[
[-29.2, 3.5, 10.8, 0.85],
[29.0, 7, 6.9, 0.9],
[-29.5, 11.5, -15.8, 0.82],
[29.0, 16, -18.7, 0.95],
[-28.8, 16, -32.1, 0.78],
[10.4, 16, -31.4, 0.75],
[27.1, 16, -32.0, 0.86]
].forEach(([x, y, z, scale]) => addCypress(x, y, z, scale));
function addShrub(x, ground, z) {
box(world, 0.85, 0.65, 0.8, x, ground + 0.33, z, "#748661");
box(world, 0.55, 0.45, 0.55, x + 0.35, ground + 0.22, z + 0.12, "#879768");
}
[
[-27, 0, 30.7],
[8, 0, 30.8],
[-18, 16, -24.1],
[7, 16, -28.0],
[26, 11.5, -14.9]
].forEach(([x, y, z]) => addShrub(x, y, z));
function addPerson(x, ground, z, shirtColor, scale = 1, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, ground, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
world.add(group);
box(group, 0.23, 0.65, 0.24, -0.16, 0.42, 0, "#3e4542");
box(group, 0.23, 0.65, 0.24, 0.16, 0.42, 0, "#3e4542");
box(group, 0.58, 0.7, 0.34, 0, 1.08, 0, shirtColor);
box(group, 0.16, 0.58, 0.18, -0.38, 1.03, 0, shirtColor);
box(group, 0.16, 0.58, 0.18, 0.38, 1.03, 0, shirtColor);
box(group, 0.38, 0.38, 0.38, 0, 1.61, 0, "#b98769");
box(group, 0.48, 0.09, 0.48, 0, 1.84, 0, "#685347");
}
[
[-5.3, 3.5, 14.1, "#486f73", 1.0, 0.3],
[10.5, 3.5, 14.8, "#b85d52", 0.94, -0.4],
[-12.5, 7, 2.3, "#d6a24f", 1.03, 1.2],
[13.5, 7, 2.1, "#6c8170", 0.9, -0.8],
[-5.8, 11.5, -10.4, "#a85754", 1.02, 0.7],
[14.0, 11.5, -10.8, "#637c93", 0.93, -1.1],
[7.8, 16, -25.6, "#d38a4f", 1.0, 2.8],
[-17.0, 16, -26.3, "#5c827b", 0.92, 0.8],
[-18.7, 0, 28.3, "#556b7b", 0.98, 0.4],
[1.2, 0, 25.0, "#c16b5a", 0.9, -1.0]
].forEach(([x, y, z, color, scale, rotation]) => {
addPerson(x, y, z, color, scale, rotation);
});
// -------------------------------------------------------------------------
// Custom camera controls: orbit overview and street-level walking
// -------------------------------------------------------------------------
const overview = {
target: new THREE.Vector3(0, 6, -1),
radius: 72,
theta: 0.66,
phi: 1.02
};
const walk = {
yaw: 0,
pitch: -0.08
};
let mode = "overview";
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
const keys = new Set();
const overviewButton = document.getElementById("overviewBtn");
const streetButton = document.getElementById("streetBtn");
const resetButton = document.getElementById("resetBtn");
function updateOverviewCamera() {
const sinPhi = Math.sin(overview.phi);
const cosPhi = Math.cos(overview.phi);
camera.position.set(
overview.target.x + overview.radius * sinPhi * Math.sin(overview.theta),
overview.target.y + overview.radius * cosPhi,
overview.target.z + overview.radius * sinPhi * Math.cos(overview.theta)
);
camera.lookAt(overview.target);
}
function setMode(nextMode) {
mode = nextMode;
overviewButton.classList.toggle("active", mode === "overview");
streetButton.classList.toggle("active", mode === "street");
if (mode === "street") {
camera.position.set(0, 1.7, 28.2);
walk.yaw = 0;
walk.pitch = -0.08;
camera.rotation.set(walk.pitch, walk.yaw, 0, "YXZ");
} else {
updateOverviewCamera();
}
}
function resetView() {
overview.target.set(0, 6, -1);
overview.radius = 72;
overview.theta = 0.66;
overview.phi = 1.02;
setMode("overview");
}
overviewButton.addEventListener("click", () => setMode("overview"));
streetButton.addEventListener("click", () => setMode("street"));
resetButton.addEventListener("click", resetView);
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (mode === "overview") {
overview.theta -= dx * 0.005;
overview.phi = THREE.MathUtils.clamp(
overview.phi - dy * 0.005,
0.34,
1.38
);
} else {
walk.yaw -= dx * 0.004;
walk.pitch = THREE.MathUtils.clamp(
walk.pitch - dy * 0.004,
-1.1,
0.9
);
}
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
if (mode === "overview") {
overview.radius = THREE.MathUtils.clamp(
overview.radius + event.deltaY * 0.035,
28,
105
);
} else {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
camera.position.addScaledVector(forward, -Math.sign(event.deltaY) * 2.2);
}
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
keys.add(event.code);
if (
["KeyW", "KeyA", "KeyS", "KeyD", "KeyQ", "KeyE", "Space"].includes(event.code)
) {
event.preventDefault();
}
});
window.addEventListener("keyup", (event) => {
keys.delete(event.code);
});
window.addEventListener("blur", () => keys.clear());
function groundHeightAt(z) {
if (z >= 21) return 0;
if (z > 19) return ((21 - z) / 2) * 3.5;
if (z >= 10) return 3.5;
if (z > 8) return 3.5 + ((10 - z) / 2) * 3.5;
if (z >= -3) return 7;
if (z > -5) return 7 + ((-3 - z) / 2) * 4.5;
if (z >= -17) return 11.5;
if (z > -19) return 11.5 + ((-17 - z) / 2) * 4.5;
return 16;
}
const forwardVector = new THREE.Vector3();
const rightVector = new THREE.Vector3();
const upVector = new THREE.Vector3(0, 1, 0);
const movement = new THREE.Vector3();
function updateCamera(dt) {
if (mode === "overview") {
camera.getWorldDirection(forwardVector);
forwardVector.y = 0;
forwardVector.normalize();
rightVector.crossVectors(forwardVector, upVector).normalize();
movement.set(0, 0, 0);
movement.addScaledVector(forwardVector, Number(keys.has("KeyW")) - Number(keys.has("KeyS")));
movement.addScaledVector(rightVector, Number(keys.has("KeyD")) - Number(keys.has("KeyA")));
movement.multiplyScalar(dt * 10);
overview.target.add(movement);
overview.target.x = THREE.MathUtils.clamp(overview.target.x, -28, 28);
overview.target.z = THREE.MathUtils.clamp(overview.target.z, -31, 29);
overview.target.y = THREE.MathUtils.clamp(
overview.target.y + (Number(keys.has("KeyE")) - Number(keys.has("KeyQ"))) * dt * 7,
-1,
20
);
updateOverviewCamera();
} else {
camera.rotation.set(walk.pitch, walk.yaw, 0, "YXZ");
camera.getWorldDirection(forwardVector);
forwardVector.y = 0;
forwardVector.normalize();
rightVector.crossVectors(forwardVector, upVector).normalize();
movement.set(0, 0, 0);
movement.addScaledVector(forwardVector, Number(keys.has("KeyW")) - Number(keys.has("KeyS")));
movement.addScaledVector(rightVector, Number(keys.has("KeyD")) - Number(keys.has("KeyA")));
movement.normalize().multiplyScalar(dt * 4.8);
camera.position.add(movement);
camera.position.x = THREE.MathUtils.clamp(camera.position.x, -31, 31);
camera.position.z = THREE.MathUtils.clamp(camera.position.z, -33, 31.5);
const targetY = groundHeightAt(camera.position.z) + 1.7;
camera.position.y = THREE.MathUtils.lerp(
camera.position.y,
targetY,
1 - Math.pow(0.0005, dt)
);
}
}
// -------------------------------------------------------------------------
// Projected district labels
// -------------------------------------------------------------------------
const chapelLabel = document.getElementById("chapelLabel");
const belvedereLabel = document.getElementById("belvedereLabel");
const projected = new THREE.Vector3();
function placeLabel(element, x, y, z) {
projected.set(x, y, z).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
updateCamera(dt);
placeLabel(chapelLabel, -21, 14.0, 29.6);
placeLabel(belvedereLabel, 18, 21.2, -31.0);
renderer.render(scene, camera);
}
updateOverviewCamera();
requestAnimationFrame(animate);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
});
</script>
</body>
</html>
```