Prompt specification
Build or customize the Three.js 3D scene "Olinda hilltop stair and church-wall corner" 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: Olinda hilltop stair and church-wall corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/olinda-hilltop-stair-and-church-wall-corner-x2677
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: Olinda hilltop stair and church-wall corner. Build a referenced stair-and-wall fragment near Alto da Sé. Show the relation between steps, retaining edge, and elevated viewpoint through clear level changes. Return one self-contained HTML file.
Working Three.js Starter (olinda-hilltop-stair-and-church-wall-corner-x2677):
```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="#dbe5df" />
<title>Olinda — Alto da Sé Stair & Church Wall</title>
<style>
:root {
color-scheme: light;
--ink: #263b3b;
--muted: #667775;
--paper: rgba(246, 241, 226, 0.88);
--line: rgba(38, 59, 59, 0.19);
--ochre: #b47745;
--sage: #7d9275;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe5df;
color: var(--ink);
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.identity {
position: fixed;
top: clamp(20px, 4vw, 46px);
left: clamp(20px, 4vw, 52px);
z-index: 5;
width: min(420px, calc(100vw - 40px));
pointer-events: none;
text-shadow: 0 1px 12px rgba(240, 238, 220, 0.42);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 11px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: var(--ochre);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(42px, 6.5vw, 78px);
font-weight: 400;
line-height: 0.88;
letter-spacing: -0.045em;
}
.subtitle {
margin: 16px 0 0;
color: #536664;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.08em;
line-height: 1.5;
text-transform: uppercase;
}
.levels {
position: fixed;
right: clamp(18px, 3vw, 42px);
top: 50%;
z-index: 5;
width: 178px;
padding: 17px 17px 16px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 2px;
background: rgba(244, 240, 222, 0.76);
box-shadow: 0 16px 45px rgba(50, 67, 62, 0.09);
backdrop-filter: blur(12px);
transform: translateY(-50%);
pointer-events: none;
}
.levels-title {
margin-bottom: 14px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.level {
display: grid;
grid-template-columns: 25px 1fr auto;
align-items: center;
gap: 9px;
min-height: 31px;
border-top: 1px solid var(--line);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.level:first-of-type {
border-top: 0;
}
.swatch {
width: 14px;
height: 9px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.low {
background: #c8b58e;
}
.swatch.stair {
background: #dfcda6;
}
.swatch.high {
background: #eee7d3;
}
.level-value {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.controls {
position: fixed;
right: clamp(18px, 3vw, 42px);
bottom: clamp(18px, 3vw, 36px);
z-index: 6;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(38, 59, 59, 0.18);
border-radius: 2px;
padding: 10px 13px;
background: rgba(246, 241, 226, 0.83);
color: var(--ink);
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(255, 252, 239, 0.98);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--ochre);
outline-offset: 2px;
}
.hint {
position: fixed;
left: clamp(20px, 4vw, 52px);
bottom: clamp(18px, 3vw, 36px);
z-index: 5;
display: flex;
align-items: center;
gap: 10px;
color: rgba(38, 59, 59, 0.68);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.hint::before {
width: 24px;
height: 24px;
content: "";
border: 1px solid rgba(38, 59, 59, 0.3);
border-radius: 50%;
background:
linear-gradient(90deg, transparent 47%, rgba(38, 59, 59, 0.35) 48% 52%, transparent 53%),
linear-gradient(0deg, transparent 47%, rgba(38, 59, 59, 0.35) 48% 52%, transparent 53%);
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dbe5df;
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading span {
padding-bottom: 10px;
border-bottom: 1px solid var(--ochre);
}
@media (max-width: 760px) {
.identity {
top: 22px;
}
.subtitle {
max-width: 290px;
font-size: 10px;
}
.levels {
top: auto;
right: 18px;
bottom: 76px;
width: 154px;
transform: none;
}
.hint {
display: none;
}
.controls {
right: 18px;
bottom: 18px;
}
}
@media (max-height: 590px) {
.levels {
display: none;
}
.identity {
top: 18px;
}
h1 {
font-size: 42px;
}
.subtitle {
margin-top: 9px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel reconstruction of a hilltop stair and church-wall corner in Olinda"></main>
<header class="identity">
<div class="eyebrow">Architectural field note · 01</div>
<h1>OLINDA</h1>
<p class="subtitle">Alto da Sé · stair, retaining edge & elevated church corner</p>
</header>
<aside class="levels" aria-label="Level legend">
<div class="levels-title">Level relationship</div>
<div class="level">
<span class="swatch low"></span>
<span>Lower square</span>
<span class="level-value">0.0 m</span>
</div>
<div class="level">
<span class="swatch stair"></span>
<span>Stair landing</span>
<span class="level-value">+3.6 m</span>
</div>
<div class="level">
<span class="swatch high"></span>
<span>Church terrace</span>
<span class="level-value">elevated</span>
</div>
</aside>
<div class="hint">Drag to orbit · wheel to zoom · shift-drag to pan</div>
<nav class="controls" aria-label="Camera views">
<button id="overview" type="button">Overview</button>
<button id="detail" type="button">Stair detail</button>
</nav>
<div id="loading" class="loading"><span>Building the hilltop fragment</span></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe5df);
scene.fog = new THREE.Fog(0xdbe5df, 34, 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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Voxel model of Olinda hilltop stairs and church wall");
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(38, window.innerWidth / window.innerHeight, 0.1, 120);
const hemisphere = new THREE.HemisphereLight(0xf2f6eb, 0x826a50, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.1);
sun.position.set(12, 20, 11);
sun.target.position.set(0, 2.3, -2.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun, sun.target);
const fill = new THREE.DirectionalLight(0x9ec8cf, 0.65);
fill.position.set(-13, 8, -8);
scene.add(fill);
const cube = new THREE.BoxGeometry(1, 1, 1);
const standard = (color, roughness = 0.86) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness: 0 });
const M = {
earth: standard(0x927050),
earthDark: standard(0x76583f),
earthLight: standard(0xb08a61),
grass: standard(0x839269),
grassLight: standard(0x93a27a),
grassDark: standard(0x68775a),
paver: standard(0xcbb994),
paverLight: standard(0xd9c8a5),
paverDark: standard(0xb7a27e),
stone: standard(0xbca581),
stoneLight: standard(0xd2bea0),
stoneWarm: standard(0xc6a87e),
stoneDark: standard(0x9f8768),
plaster: standard(0xeee7d4),
plasterWarm: standard(0xe2d7bf),
plasterShade: standard(0xcfc1a6),
trim: standard(0xb97b50),
roof: standard(0xa95039),
roofLight: standard(0xbf6548),
wood: standard(0x654834),
dark: standard(0x243b3d),
window: standard(0x365b5e, 0.5),
leaf: standard(0x667e58),
leafLight: standard(0x809363),
leafDark: standard(0x536b4d),
teal: standard(0x537a78),
ochre: standard(0xbd7c45),
skin: standard(0xb9815d),
cream: standard(0xf0e5c8),
shadowPlane: standard(0xdbe5df)
};
const paverMats = [
standard(0xd0bd98),
standard(0xc3b087),
standard(0xdac9a8),
standard(0xbbaa87),
standard(0xd3c19e)
];
const stoneMats = [
standard(0xc4b18e),
standard(0xb59d77),
standard(0xd0bea0),
standard(0xc8b28a),
standard(0xbda47d)
];
const plasterMats = [
standard(0xeee7d5),
standard(0xe6dcc5),
standard(0xf2ead7),
standard(0xdfd3b9),
standard(0xeadfc9)
];
let seed = 1929;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function pick(array) {
return array[Math.floor(random() * array.length)];
}
function box(w, h, d, x, y, z, material, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(cube, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Neutral ground plane catches the model's long afternoon shadows.
const floor = new THREE.Mesh(new THREE.PlaneGeometry(180, 180), M.shadowPlane);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.48;
floor.receiveShadow = true;
scene.add(floor);
// Cutaway terrain block: the compact maquette base also establishes the lower level.
box(25, 1.22, 22, 0, -0.86, 0, M.earth);
box(25, 0.23, 22, 0, -0.135, 0, M.grass, scene, false);
// Uneven voxel vegetation around the built fragment.
const terrainBlocks = [
[-9.2, 0.35, -7.4, 3.1, 0.7, 2.6, M.grassDark],
[-10.0, 0.8, -2.7, 2.4, 1.6, 3.2, M.grass],
[-8.5, 0.55, 8.5, 3.5, 1.1, 1.8, M.grassLight],
[8.8, 0.5, -7.0, 3.1, 1.0, 2.7, M.grassDark],
[9.5, 0.9, 4.8, 2.8, 1.8, 3.4, M.grass],
[8.7, 0.4, 9.3, 3.8, 0.8, 1.7, M.grassLight],
[-8.8, 0.25, 2.6, 2.0, 0.5, 1.6, M.grassLight],
[8.0, 0.25, -2.0, 1.8, 0.5, 1.4, M.grassLight]
];
terrainBlocks.forEach(([x, y, z, w, h, d, material]) => {
box(w, h, d, x, y, z, material);
});
// Lower cobbled square.
for (let ix = 0; ix < 11; ix++) {
for (let iz = 0; iz < 7; iz++) {
const x = -5.1 + ix * 1.02;
const z = 3.65 + iz * 1.02;
const mat = pick(paverMats);
box(0.97, 0.09, 0.97, x, 0.015, z, mat, scene, false);
}
}
// Broad stair: twelve crisp rises make the vertical transition legible.
const stepCount = 12;
const rise = 0.30;
const tread = 0.68;
const stairWidth = 4.28;
const stairFront = 7.4;
for (let i = 0; i < stepCount; i++) {
const top = (i + 1) * rise;
const z = stairFront - (i + 0.5) * tread;
box(stairWidth, top + 0.02, tread - 0.015, 0, top / 2, z, M.stone);
// Individually colored voxel tread pavers.
for (let p = 0; p < 7; p++) {
const px = -stairWidth / 2 + (p + 0.5) * (stairWidth / 7);
box(stairWidth / 7 - 0.025, 0.055, tread - 0.07, px, top + 0.018, z, pick(paverMats), scene, false);
}
// Darker nosing marks the front edge of every step.
box(stairWidth, 0.085, 0.105, 0, top - 0.018, z + tread / 2 - 0.065, M.stoneDark, scene, false);
}
// Stepped retaining walls. The right wall rises higher, exposing the structural edge.
for (let i = 0; i < stepCount; i++) {
const stairTop = (i + 1) * rise;
const z = stairFront - (i + 0.5) * tread;
const rightTop = stairTop + 0.72;
const leftTop = stairTop + 0.18;
const course = 0.39;
for (let y = 0; y < rightTop - 0.07; y += course) {
const h = Math.min(course, rightTop - 0.07 - y);
box(0.55, h - 0.025, tread - 0.035, 2.46, y + h / 2, z, pick(stoneMats));
}
box(0.64, 0.16, tread - 0.02, 2.46, rightTop + 0.015, z, M.stoneLight);
for (let y = 0; y < leftTop - 0.06; y += course) {
const h = Math.min(course, leftTop - 0.06 - y);
box(0.43, h - 0.02, tread - 0.035, -2.43, y + h / 2, z, pick(stoneMats));
}
box(0.52, 0.14, tread - 0.02, -2.43, leftTop + 0.01, z, M.stoneWarm);
}
// Small shadowed drainage recesses in the high retaining wall.
[3, 7].forEach((i) => {
const stairTop = (i + 1) * rise;
const z = stairFront - (i + 0.5) * tread;
box(0.045, 0.13, 0.22, 2.175, stairTop + 0.37, z, M.dark, scene, false);
});
// Elevated terrace core.
const terraceTop = stepCount * rise;
const terraceFront = stairFront - stepCount * tread;
const terraceBack = -10.4;
const terraceDepth = terraceFront - terraceBack;
const terraceCenterZ = (terraceFront + terraceBack) / 2;
box(10.8, terraceTop + 0.03, terraceDepth, 0, terraceTop / 2 - 0.015, terraceCenterZ, M.stoneWarm);
// Stone facing on the visible terrace elevation.
for (let y = 0; y < terraceTop - 0.08; y += 0.42) {
const h = Math.min(0.42, terraceTop - 0.08 - y);
for (let x = -5.28; x < 2.1; x += 0.82) {
const width = Math.min(0.79, 2.1 - x);
if (width > 0.05) box(width, h - 0.02, 0.09, x + width / 2, y + h / 2, terraceFront + 0.01, pick(stoneMats));
}
for (let x = 2.25; x < 5.28; x += 0.82) {
const width = Math.min(0.79, 5.28 - x);
if (width > 0.05) box(width, h - 0.02, 0.09, x + width / 2, y + h / 2, terraceFront + 0.01, pick(stoneMats));
}
}
// Right-hand cut face of the raised terrace.
for (let y = 0; y < terraceTop - 0.07; y += 0.42) {
const h = Math.min(0.42, terraceTop - 0.07 - y);
let z = terraceFront;
while (z > -4.05) {
const depth = Math.min(0.78, z + 4.05);
box(0.1, h - 0.02, depth - 0.025, 5.36, y + h / 2, z - depth / 2, pick(stoneMats));
z -= depth;
}
}
// Terrace paving.
for (let ix = 0; ix < 10; ix++) {
for (let iz = 0; iz < 9; iz++) {
const x = -4.62 + ix * 1.025;
const z = -9.88 + iz * 1.025;
box(0.985, 0.075, 0.985, x, terraceTop + 0.035, z, pick(paverMats), scene, false);
}
}
// Low parapets frame the upper viewpoint while leaving the stair opening clear.
function frontParapet(startX, endX) {
const blocks = Math.max(1, Math.round((endX - startX) / 0.82));
const width = (endX - startX) / blocks;
for (let i = 0; i < blocks; i++) {
const x = startX + (i + 0.5) * width;
box(width - 0.025, 0.66, 0.34, x, terraceTop + 0.38, terraceFront + 0.12, M.stoneLight);
box(width - 0.015, 0.13, 0.43, x, terraceTop + 0.765, terraceFront + 0.12, M.stoneWarm);
}
}
frontParapet(-5.35, -2.35);
frontParapet(2.35, 5.35);
for (let z = -3.95; z < terraceFront - 0.05; z += 0.78) {
const depth = Math.min(0.74, terraceFront - 0.05 - z);
if (depth <= 0) break;
box(0.34, 0.65, depth - 0.02, 5.18, terraceTop + 0.37, z + depth / 2, M.stoneLight);
box(0.43, 0.13, depth, 5.18, terraceTop + 0.755, z + depth / 2, M.stoneWarm);
}
// Church-wall fragment: an L-shaped whitewashed colonial wall with a warm stone plinth.
const churchBase = terraceTop + 0.08;
const backZ = -9.24;
const backLeft = -4.72;
const backRight = 3.78;
const wallThickness = 0.58;
const backHeight = 5.05;
const sideHeight = 4.55;
const sideFront = -4.08;
// Stone plinth beneath the plastered walls.
let px = backLeft;
while (px < backRight) {
const width = Math.min(1.0, backRight - px);
box(width - 0.02, 0.46, wallThickness + 0.16, px + width / 2, churchBase + 0.23, backZ, pick(stoneMats));
px += width;
}
let pz = backZ;
while (pz < sideFront) {
const depth = Math.min(0.92, sideFront - pz);
box(wallThickness + 0.16, 0.46, depth - 0.02, 3.78, churchBase + 0.23, pz + depth / 2, pick(stoneMats));
pz += depth;
}
// Main rear facade in staggered voxel courses.
const courseHeight = 0.47;
for (let row = 0; row < Math.floor(backHeight / courseHeight); row++) {
const h = courseHeight - 0.018;
const y = churchBase + 0.47 + row * courseHeight + h / 2;
let x = backLeft + (row % 2 ? 0.35 : 0);
while (x < backRight) {
const width = Math.min(0.82 + random() * 0.42, backRight - x);
if (width > 0.04) {
box(width - 0.025, h, wallThickness, x + width / 2, y, backZ, pick(plasterMats));
}
x += width;
}
}
// Side wing, slightly lower, creates the prominent corner.
for (let row = 0; row < Math.floor(sideHeight / courseHeight); row++) {
const h = courseHeight - 0.018;
const y = churchBase + 0.47 + row * courseHeight + h / 2;
let z = backZ + (row % 2 ? 0.34 : 0);
while (z < sideFront) {
const depth = Math.min(0.82 + random() * 0.36, sideFront - z);
if (depth > 0.04) {
box(wallThickness, h, depth - 0.025, 3.78, y, z + depth / 2, pick(plasterMats));
}
z += depth;
}
}
// Quoins emphasize the re-entrant corner and the outer end of the wing.
for (let i = 0; i < 10; i++) {
const y = churchBase + 0.5 + i * 0.47;
const width = i % 2 ? 0.82 : 0.68;
box(width, 0.42, 0.78, 3.58, y, backZ + 0.18, i % 2 ? M.plasterWarm : M.plaster);
box(0.78, 0.42, width, 3.64, y, sideFront - 0.16, i % 2 ? M.plasterWarm : M.plaster);
}
// Restrained corner buttresses.
[-8.05, -5.05].forEach((z) => {
box(0.62, 4.45, 0.72, 4.25, churchBase + 2.23, z, M.plasterWarm);
box(0.83, 0.22, 0.94, 4.31, churchBase + 4.48, z, M.plaster);
box(0.94, 0.18, 1.05, 4.36, churchBase + 4.66, z, M.trim);
});
// Terracotta cornice caps, suggesting the church roof beyond the retained fragment.
let cx = backLeft;
while (cx < backRight) {
const width = Math.min(1.05, backRight - cx);
box(width - 0.025, 0.2, 0.78, cx + width / 2, churchBase + backHeight + 0.08, backZ, iRoof());
cx += width;
}
let cz = backZ;
while (cz < sideFront) {
const depth = Math.min(1.0, sideFront - cz);
box(0.78, 0.2, depth - 0.025, 3.78, churchBase + sideHeight + 0.08, cz + depth / 2, iRoof());
cz += depth;
}
function iRoof() {
return random() > 0.5 ? M.roof : M.roofLight;
}
// Dark church doorway with a stepped voxel arch.
const doorX = -1.6;
const doorBottom = churchBase + 0.47;
const doorW = 1.48;
const doorH = 2.48;
const facadeFront = backZ + wallThickness / 2 + 0.028;
box(doorW, doorH, 0.075, doorX, doorBottom + doorH / 2, facadeFront, M.dark, scene, false);
box(0.07, doorH, 0.09, doorX, doorBottom + doorH / 2, facadeFront + 0.055, M.wood, scene, false);
box(doorW, 0.07, 0.09, doorX, doorBottom + doorH * 0.53, facadeFront + 0.055, M.wood, scene, false);
box(doorW + 0.28, 0.18, 0.22, doorX, doorBottom - 0.03, facadeFront + 0.06, M.trim);
const archRows = [
{ y: 2.48, offsets: [-0.51, -0.17, 0.17, 0.51], size: 0.28 },
{ y: 2.72, offsets: [-0.59, -0.17, 0.25, 0.59], size: 0.32 },
{ y: 2.99, offsets: [-0.68, 0, 0.68], size: 0.34 }
];
archRows.forEach((row) => {
row.offsets.forEach((offset) => {
box(row.size, row.size, 0.18, doorX + offset, doorBottom + row.y, facadeFront + 0.08, M.trim);
});
});
// Two recessed, narrow church windows with simple mullions.
function churchWindow(x, bottom, width = 0.64, height = 1.26) {
const y = bottom + height / 2;
box(width, height, 0.075, x, y, facadeFront + 0.02, M.window, scene, false);
box(0.06, height, 0.1, x, y, facadeFront + 0.075, M.trim, scene, false);
box(width, 0.07, 0.1, x, y + 0.05, facadeFront + 0.075, M.trim, scene, false);
box(width + 0.24, 0.15, 0.24, x, bottom - 0.06, facadeFront + 0.08, M.trim);
box(0.24, 0.24, 0.18, x, bottom + height + 0.03, facadeFront + 0.08, M.trim);
}
churchWindow(1.48, churchBase + 1.35);
churchWindow(-3.72, churchBase + 1.35);
// Small cross above the main wall.
const crossY = churchBase + backHeight + 0.54;
box(0.12, 0.72, 0.12, doorX, crossY, backZ + 0.18, M.wood);
box(0.48, 0.12, 0.12, doorX, crossY + 0.13, backZ + 0.18, M.wood);
// Small threshold blocks at the upper landing.
box(1.95, 0.13, 0.62, doorX, churchBase + 0.055, backZ + 0.68, M.stoneLight);
box(2.25, 0.12, 0.38, doorX, churchBase - 0.02, backZ + 1.16, M.stoneWarm);
// A potted plant marks the narrow side walkway and gives the corner scale.
box(0.58, 0.64, 0.58, 4.65, terraceTop + 0.38, -3.15, M.trim);
box(0.46, 0.22, 0.46, 4.65, terraceTop + 0.76, -3.15, M.earthDark);
box(0.42, 0.72, 0.42, 4.65, terraceTop + 1.18, -3.15, M.leaf);
box(0.62, 0.48, 0.54, 4.72, terraceTop + 1.63, -3.12, M.leafLight);
// Stylized visitor on the elevated terrace.
function person(x, z, groundY, shirt, hatColor = M.ochre) {
box(0.19, 0.49, 0.2, x - 0.13, groundY + 0.25, z, M.dark);
box(0.19, 0.49, 0.2, x + 0.13, groundY + 0.25, z, M.dark);
box(0.57, 0.61, 0.32, x, groundY + 0.79, z, shirt);
box(0.14, 0.52, 0.17, x - 0.37, groundY + 0.78, z, shirt);
box(0.14, 0.52, 0.17, x + 0.37, groundY + 0.78, z, shirt);
box(0.34, 0.34, 0.34, x, groundY + 1.28, z, M.skin);
box(0.48, 0.08, 0.46, x, groundY + 1.48, z, hatColor);
box(0.32, 0.22, 0.3, x, groundY + 1.57, z, hatColor);
}
person(4.62, -2.35, terraceTop + 0.08, M.teal);
person(4.55, 8.75, 0.07, M.ochre, M.cream);
// Lower bench, built as small timber blocks.
box(1.65, 0.13, 0.48, -5.1, 0.58, 6.55, M.wood);
box(1.65, 0.58, 0.12, -5.1, 0.88, 6.31, M.wood);
box(0.16, 0.5, 0.44, -5.72, 0.28, 6.55, M.dark);
box(0.16, 0.5, 0.44, -4.48, 0.28, 6.55, M.dark);
// Street lamp at the lower edge of the square.
function lamp(x, z, groundY) {
box(0.48, 0.12, 0.48, x, groundY + 0.06, z, M.stoneDark);
box(0.13, 2.15, 0.13, x, groundY + 1.08, z, M.dark);
box(0.42, 0.12, 0.42, x, groundY + 2.17, z, M.dark);
box(0.34, 0.45, 0.34, x, groundY + 1.93, z, M.cream);
box(0.48, 0.12, 0.48, x, groundY + 2.26, z, M.dark);
}
lamp(-3.7, 9.0, 0.05);
lamp(5.25, 4.1, 0.05);
// Voxel trees frame the fragment and suggest Olinda's subtropical vegetation.
function tree(x, z, scale = 1) {
const baseY = -0.02;
box(0.34 * scale, 1.9 * scale, 0.34 * scale, x, baseY + 0.95 * scale, z, M.wood);
box(0.24 * scale, 0.82 * scale, 0.24 * scale, x + 0.34 * scale, baseY + 1.55 * scale, z, M.wood);
box(0.24 * scale, 0.7 * scale, 0.24 * scale, x - 0.31 * scale, baseY + 1.67 * scale, z + 0.08, M.wood);
const clusters = [
[-0.55, 2.15, -0.2, 1.25, 1.05, 1.2, M.leaf],
[0.5, 2.25, 0.1, 1.35, 1.15, 1.3, M.leafLight],
[0.0, 2.8, -0.25, 1.45, 1.2, 1.25, M.leaf],
[-0.78, 2.7, 0.3, 0.95, 0.95, 0.95, M.leafDark],
[0.72, 2.85, -0.32, 0.95, 0.95, 1.0, M.leafDark],
[0.05, 3.35, 0.05, 1.1, 0.75, 1.05, M.leafLight]
];
clusters.forEach(([dx, dy, dz, w, h, d, mat]) => {
box(w * scale, h * scale, d * scale, x + dx * scale, baseY + dy * scale, z + dz * scale, mat);
});
}
tree(-7.65, 6.55, 1.06);
tree(7.35, 6.35, 1.12);
tree(-8.15, -3.4, 0.92);
// Small grass voxel accents along the site edges.
for (let i = 0; i < 28; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = side * (6.1 + random() * 5.0);
const z = -9.5 + random() * 18.5;
if (Math.abs(x) < 6.0 && z > 2.0 && z < 10.5) continue;
const h = 0.15 + random() * 0.25;
box(0.12 + random() * 0.1, h, 0.12 + random() * 0.1, x, h / 2, z, random() > 0.5 ? M.grassDark : M.grassLight);
}
// Camera controls implemented directly, without addons.
const view = {
theta: 0.69,
phi: 0.49,
radius: 26.5,
target: new THREE.Vector3(0.1, 2.55, -1.45)
};
const overview = {
theta: 0.69,
phi: 0.49,
radius: 26.5,
target: new THREE.Vector3(0.1, 2.55, -1.45)
};
const detail = {
theta: 0.57,
phi: 0.43,
radius: 16.5,
target: new THREE.Vector3(0.0, 2.2, 1.55)
};
function updateCamera() {
const horizontal = Math.sin(view.phi) * view.radius;
camera.position.set(
view.target.x + horizontal * Math.sin(view.theta),
view.target.y + Math.cos(view.phi) * view.radius,
view.target.z + horizontal * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
function setView(next) {
view.theta = next.theta;
view.phi = next.phi;
view.radius = next.radius;
view.target.copy(next.target);
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3(Math.cos(view.theta), 0, -Math.sin(view.theta));
const forward = new THREE.Vector3(-Math.sin(view.theta), 0, -Math.cos(view.theta));
const panScale = view.radius * 0.00125;
view.target.addScaledVector(right, -dx * panScale);
view.target.addScaledVector(forward, -dy * panScale);
view.target.x = THREE.MathUtils.clamp(view.target.x, -8, 8);
view.target.y = THREE.MathUtils.clamp(view.target.y, 0.4, 6.5);
view.target.z = THREE.MathUtils.clamp(view.target.z, -7, 7);
} else {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi + dy * 0.005, 0.2, 1.27);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(view.radius * Math.exp(event.deltaY * 0.001), 10.5, 39);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => setView(overview));
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") view.theta += 0.08;
else if (event.key === "ArrowRight") view.theta -= 0.08;
else if (event.key === "ArrowUp") view.phi = Math.max(0.2, view.phi - 0.06);
else if (event.key === "ArrowDown") view.phi = Math.min(1.27, view.phi + 0.06);
else if (event.key === "+" || event.key === "=") view.radius = Math.max(10.5, view.radius - 1);
else if (event.key === "-") view.radius = Math.min(39, view.radius + 1);
else return;
updateCamera();
});
document.querySelector("#overview").addEventListener("click", () => setView(overview));
document.querySelector("#detail").addEventListener("click", () => setView(detail));
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(() => loading.classList.add("hidden"));
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```