Prompt specification
Build or customize the Three.js 3D scene "Pelourinho facade and stepped doorway" 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: Pelourinho facade and stepped doorway
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pelourinho-facade-and-stepped-doorway-x2701
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Pelourinho's sloping streets in Salvador. Build one referenced Salvador historic facade with a doorway meeting a sloped street. Make the threshold steps and changing pavement elevation visible in the small model. Low-poly.
Working Three.js Starter (pelourinho-facade-and-stepped-doorway-x2701):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pelourinho — Sloping Street Study</title>
<style>
:root {
--ink: #17383b;
--paper: rgba(248, 245, 232, 0.92);
--accent: #b8523f;
--line: rgba(23, 56, 59, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e6e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
canvas {
display: block;
outline: none;
touch-action: none;
}
.intro,
.notes,
.toolbar,
.world-label {
position: fixed;
z-index: 2;
}
.intro {
top: 24px;
left: 26px;
max-width: 420px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.eyebrow {
margin: 0 0 6px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4.7vw, 62px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.045em;
}
.subtitle {
margin: 11px 0 0;
max-width: 355px;
font-size: 13px;
line-height: 1.5;
}
.notes {
top: 24px;
right: 24px;
width: 275px;
padding: 17px 18px;
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 12px 40px rgba(31, 55, 53, 0.12);
backdrop-filter: blur(9px);
pointer-events: none;
}
.notes h2 {
margin: 0 0 10px;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.notes p {
margin: 7px 0;
font-size: 12px;
line-height: 1.5;
}
.notes strong {
color: var(--accent);
}
.notes .disclaimer {
padding-top: 10px;
border-top: 1px solid var(--line);
color: rgba(23, 56, 59, 0.66);
font-size: 10px;
}
.toolbar {
bottom: 22px;
left: 50%;
display: flex;
gap: 8px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 12px;
background: rgba(248, 245, 232, 0.9);
box-shadow: 0 12px 34px rgba(31, 55, 53, 0.16);
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
.toolbar button {
min-width: 92px;
padding: 10px 13px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.toolbar button:hover,
.toolbar button.active {
background: var(--ink);
color: #fffaf0;
}
.toolbar button:active {
transform: translateY(1px);
}
.world-label {
display: none;
max-width: 210px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 7px;
background: rgba(248, 245, 232, 0.86);
box-shadow: 0 5px 18px rgba(25, 49, 48, 0.12);
color: var(--ink);
font-size: 10px;
font-weight: 750;
line-height: 1.25;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
}
.world-label::after {
position: absolute;
bottom: -10px;
left: 50%;
width: 1px;
height: 10px;
background: rgba(23, 56, 59, 0.58);
content: "";
}
.world-label.steps {
color: #963f31;
}
.world-label.grade {
color: #235d61;
}
.help {
position: fixed;
right: 25px;
bottom: 25px;
z-index: 2;
color: rgba(23, 56, 59, 0.62);
font-size: 10px;
letter-spacing: 0.035em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #d8e6e3;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 17px;
left: 18px;
}
.intro .subtitle {
display: none;
}
.notes {
top: auto;
right: 14px;
bottom: 80px;
width: 225px;
padding: 12px 14px;
}
.notes h2 {
font-size: 16px;
}
.notes p {
font-size: 10px;
}
.notes .disclaimer {
display: none;
}
.toolbar {
bottom: 14px;
}
.toolbar button {
min-width: auto;
padding: 9px 10px;
font-size: 10px;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="loading">Building Salvador</div>
<header class="intro">
<p class="eyebrow">Salvador · Bahia · Brazil</p>
<h1>Pelourinho<br>in the slope</h1>
<p class="subtitle">
A low-poly study of a Portas do Carmo-inspired colonial facade,
its threshold steps, and the changing level of the patterned street.
</p>
</header>
<aside class="notes">
<h2>Reading the model</h2>
<p><strong>Facade:</strong> pastel masonry, arched timber opening, shutters, and iron balcony.</p>
<p><strong>Grade:</strong> the modeled road falls at 8.5%, with terraced sidewalk levels.</p>
<p><strong>Steps:</strong> five separate stone treads connect the raised doorway to the incline.</p>
<p class="disclaimer">
Interpretive architectural model, not a surveyed reconstruction of a specific property.
</p>
</aside>
<nav class="toolbar" aria-label="Camera presets">
<button data-preset="overview" class="active">Overview</button>
<button data-preset="doorway">Doorway</button>
<button data-preset="grade">Street grade</button>
</nav>
<div class="help">Drag to orbit · Wheel to zoom · Right-drag to pan</div>
<div id="label-steps" class="world-label steps">RAISED DOOR THRESHOLD</div>
<div id="label-grade" class="world-label grade">8.5% STREET FALL</div>
<div id="label-facade" class="world-label">COLONIAL FACADE STUDY</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 app = document.querySelector("#app");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e6e3);
scene.fog = new THREE.Fog(0xd8e6e3, 26, 62);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8f5f1, 0x795b48, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe3b0, 3.1);
sun.position.set(-10, 18, 11);
sun.target.position.set(1, 0, -1);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
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(0x8bb8c2, 0.75);
fill.position.set(12, 7, -15);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
function standard(color, roughness = 0.85, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness,
flatShading: true,
...extra
});
}
const mat = {
ground: standard(0xb9aa8e),
roadBase: standard(0x685f53),
pavingLight: standard(0xd7d0bd, 0.96),
pavingDark: standard(0x263b3c, 0.98),
sidewalk: standard(0xb8aa91),
curb: standard(0x6c6255),
facade: standard(0xb85f47),
facadeShade: standard(0x9e4c3b),
trim: standard(0xf0dfbd),
stone: standard(0xcdb995),
foundation: standard(0x786654),
roof: standard(0x994a37),
roofDark: standard(0x78392f),
glass: standard(0x294a50, 0.35),
shutter: standard(0x315e5d),
shutterAlt: standard(0x3f6264),
wood: standard(0x3f2924),
iron: standard(0x263536, 0.58),
terracotta: standard(0xa75339),
leaf: standard(0x3f7545),
leafLight: standard(0x679151),
pole: standard(0x263638, 0.52),
lantern: standard(0xffd48a, 0.4, {
emissive: 0xe9a54b,
emissiveIntensity: 0.8
})
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function geometryFromPositions(positions) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
function addQuad(positions, a, b, c, d) {
positions.push(
...a, ...b, ...c,
...a, ...c, ...d
);
}
function mesh(geometry, material, x = 0, y = 0, z = 0) {
const object = new THREE.Mesh(geometry, material);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
return object;
}
function box(w, h, d, material, x = 0, y = 0, z = 0) {
return mesh(
new THREE.BoxGeometry(w, h, d),
material,
x,
y,
z
);
}
function cylinder(rt, rb, h, segments, material, x = 0, y = 0, z = 0) {
return mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material,
x,
y,
z
);
}
// The street rises toward negative Z.
function grade(z) {
return -0.085 * z;
}
function pavementPoint(x, z) {
const crown = 0.028 * (1 - Math.min(Math.abs(x) / 4.15, 1));
return [x, grade(z) + 0.025 + crown, z];
}
// A prism whose lower edge follows the street grade.
function makeSlopedPrism(
x0,
x1,
z0,
z1,
bottomAt,
topAt,
material
) {
const p = [];
const b00 = bottomAt(z0);
const b10 = bottomAt(z1);
const b01 = bottomAt(z0);
const b11 = bottomAt(z1);
const t00 = topAt(z0);
const t10 = topAt(z1);
const f00 = [x0, b00, z0];
const f10 = [x0, b10, z1];
const f11 = [x0, t10, z1];
const f01 = [x0, t00, z0];
const k00 = [x1, b01, z0];
const k10 = [x1, b11, z1];
const k11 = [x1, t10, z1];
const k01 = [x1, t00, z0];
addQuad(p, f00, f10, f11, f01);
addQuad(p, k00, k01, k11, k10);
addQuad(p, f00, f01, k01, k00);
addQuad(p, f10, k10, k11, f11);
addQuad(p, f01, f11, k11, k01);
addQuad(p, f00, k00, k10, f10);
return mesh(geometryFromPositions(p), material);
}
// -------------------------------------------------------------------------
// Terrain, patterned paving, and stepped sidewalks
// -------------------------------------------------------------------------
const ground = mesh(
new THREE.PlaneGeometry(90, 90),
mat.ground,
0,
-2.25,
0
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
makeSlopedPrism(
-4.18,
4.18,
-22,
22,
z => grade(z) - 0.075,
() => -2.15,
mat.roadBase
);
// Seven undulating black-and-white bands evoke Salvador's wave mosaic.
const lightPaving = [];
const darkPaving = [];
const bandCount = 7;
const zSegments = 88;
const roadWidth = 8.3;
function boundary(band, z) {
return (
-roadWidth / 2 +
(band * roadWidth) / bandCount +
0.29 * Math.sin(z * 0.47 + band * 0.78)
);
}
for (let band = 0; band < bandCount; band++) {
const target = band % 2 === 0 ? darkPaving : lightPaving;
for (let i = 0; i < zSegments; i++) {
const z0 = -22 + (i / zSegments) * 44;
const z1 = -22 + ((i + 1) / zSegments) * 44;
const x0 = boundary(band, z0);
const x1 = boundary(band + 1, z0);
const x2 = boundary(band + 1, z1);
const x3 = boundary(band, z1);
addQuad(
target,
pavementPoint(x0, z0),
pavementPoint(x3, z1),
pavementPoint(x2, z1),
pavementPoint(x1, z0)
);
}
}
mesh(geometryFromPositions(lightPaving), mat.pavingLight);
mesh(geometryFromPositions(darkPaving), mat.pavingDark);
// Sidewalk blocks form visible terraces along the sloping street.
const sidewalkStart = -22;
const sidewalkEnd = 22;
const sidewalkStep = 1.5;
for (let z = sidewalkStart; z < sidewalkEnd; z += sidewalkStep) {
const z1 = Math.min(z + sidewalkStep, sidewalkEnd);
const mid = (z + z1) / 2;
const top = grade(mid) + 0.18;
const bottom = Math.min(grade(z), grade(z1)) - 0.20;
const h = top - bottom;
box(0.58, h, z1 - z + 0.012, mat.sidewalk, 4.43, bottom + h / 2, mid);
box(0.58, h, z1 - z + 0.012, mat.sidewalk, -4.43, bottom + h / 2, mid);
box(0.075, 0.10, z1 - z + 0.016, mat.curb, 4.13, top - 0.02, mid);
box(0.075, 0.10, z1 - z + 0.016, mat.curb, -4.13, top - 0.02, mid);
}
// -------------------------------------------------------------------------
// Historic facade
// -------------------------------------------------------------------------
const facadeX = 4.65;
const buildingBackX = 9.45;
const facadeZ0 = -5.8;
const facadeZ1 = 5.8;
const facadeTop = 7.18;
makeSlopedPrism(
facadeX,
buildingBackX,
facadeZ0,
facadeZ1,
z => grade(z) - 0.18,
() => facadeTop,
mat.facade
);
// Dark, sloping plinth anchors the building to the grade.
makeSlopedPrism(
4.47,
4.70,
facadeZ0,
facadeZ1,
z => grade(z) - 0.24,
z => grade(z) + 0.40,
mat.foundation
);
// Corner pilasters and horizontal string courses.
for (const z of [-5.56, 5.56]) {
box(0.22, 6.95, 0.24, mat.trim, 4.48, 3.55, z);
}
for (const y of [2.60, 5.02, 7.03]) {
box(0.25, 0.15, 11.65, mat.trim, 4.47, y, 0);
}
box(0.48, 0.24, 11.9, mat.trim, 4.38, 7.16, 0);
box(0.21, 0.16, 11.55, mat.foundation, 4.48, 0.26, 0);
function addWindow(z, y, width = 0.86, height = 1.42, alternate = false) {
const shutterMat = alternate ? mat.shutterAlt : mat.shutter;
// Recess-like dark glazing.
box(0.10, height, width, mat.glass, 4.56, y, z);
// Cream frame.
box(0.22, height + 0.20, 0.09, mat.trim, 4.43, y, z - width / 2);
box(0.22, height + 0.20, 0.09, mat.trim, 4.43, y, z + width / 2);
box(0.22, 0.10, width + 0.20, mat.trim, 4.43, y + height / 2, z);
box(0.34, 0.12, width + 0.36, mat.trim, 4.38, y - height / 2, z);
// Slightly opened louvered shutters.
const shutter = box(
0.12,
height * 0.93,
0.42,
shutterMat,
4.35,
y,
z - width / 2 - 0.22
);
shutter.rotation.y = -0.48;
const shutter2 = box(
0.12,
height * 0.93,
0.42,
shutterMat,
4.35,
y,
z + width / 2 + 0.22
);
shutter2.rotation.y = 0.48;
}
// Ground-floor windows leave the center for the arched doorway.
addWindow(-3.55, 1.36, 0.92, 1.42, false);
addWindow(3.45, 1.36, 0.92, 1.42, true);
// First upper floor.
addWindow(-4.08, 3.68, 0.88, 1.40, false);
addWindow(-1.82, 3.68, 0.88, 1.40, true);
addWindow(2.05, 3.68, 0.88, 1.40, false);
addWindow(4.40, 3.68, 0.88, 1.40, true);
// Second upper floor.
addWindow(-4.10, 5.92, 0.84, 1.32, true);
addWindow(-1.98, 5.92, 0.84, 1.32, false);
addWindow(0.30, 5.92, 0.84, 1.32, true);
addWindow(2.56, 5.92, 0.84, 1.32, false);
addWindow(4.50, 5.92, 0.84, 1.32, true);
// -------------------------------------------------------------------------
// Arched doorway and visible threshold steps
// -------------------------------------------------------------------------
const doorZ = 0.30;
const doorFloor = grade(doorZ) + 0.78;
const doorSpring = doorFloor + 1.40;
const doorRadius = 0.69;
const doorShape = new THREE.Shape();
doorShape.moveTo(-doorRadius, 0);
doorShape.lineTo(doorRadius, 0);
doorShape.lineTo(doorRadius, 1.40);
doorShape.absarc(0, 1.40, doorRadius, 0, Math.PI, false);
doorShape.lineTo(-doorRadius, 0);
const doorOpening = mesh(
new THREE.ShapeGeometry(doorShape, 18),
new THREE.MeshStandardMaterial({
color: 0x142829,
roughness: 0.95,
side: THREE.DoubleSide,
flatShading: true
}),
4.555,
doorFloor,
doorZ
);
doorOpening.rotation.y = -Math.PI / 2;
// Timber double doors.
box(0.09, 1.34, 0.61, mat.wood, 4.47, doorFloor + 0.69, doorZ - 0.315);
box(0.09, 1.34, 0.61, mat.wood, 4.47, doorFloor + 0.69, doorZ + 0.315);
box(0.11, 0.06, 0.05, mat.trim, 4.40, doorFloor + 0.72, doorZ - 0.06);
box(0.11, 0.06, 0.05, mat.trim, 4.40, doorFloor + 0.72, doorZ + 0.06);
// Fanlight.
const fanShape = new THREE.Shape();
fanShape.moveTo(-0.59, 0);
fanShape.lineTo(0.59, 0);
fanShape.absarc(0, 0, 0.59, 0, Math.PI, false);
fanShape.lineTo(-0.59, 0);
const fanlight = mesh(
new THREE.ShapeGeometry(fanShape, 16),
mat.glass,
4.45,
doorSpring,
doorZ
);
fanlight.rotation.y = -Math.PI / 2;
// Stone jambs.
for (const side of [-1, 1]) {
box(
0.22,
1.42,
0.22,
mat.stone,
4.43,
doorFloor + 0.71,
doorZ + side * 0.84
);
}
// Low-poly voussoirs around the arch.
const archRadius = 0.88;
for (let i = 0; i < 11; i++) {
const angle = (i / 10) * Math.PI;
const voussoir = box(
0.20,
0.22,
0.35,
mat.stone,
4.42,
doorSpring + Math.sin(angle) * archRadius,
doorZ + Math.cos(angle) * archRadius
);
voussoir.rotation.x = -angle;
}
// Five actual treads descend from the raised threshold to the sidewalk.
const stepBottom = grade(doorZ) - 0.18;
for (let i = 0; i < 5; i++) {
const top = doorFloor - i * 0.15;
const h = top - stepBottom;
box(
0.49,
h,
1.78,
mat.stone,
4.46 - i * 0.32,
stepBottom + h / 2,
doorZ
);
}
// Small iron balcony above the entrance.
box(0.94, 0.15, 2.75, mat.trim, 4.12, 2.62, doorZ);
box(0.07, 0.07, 2.72, mat.iron, 3.66, 3.22, doorZ);
box(0.07, 0.07, 2.72, mat.iron, 3.66, 2.85, doorZ);
for (let i = 0; i <= 9; i++) {
const z = doorZ - 1.33 + (i / 9) * 2.66;
box(0.055, 0.56, 0.055, mat.iron, 3.66, 2.93, z);
}
// -------------------------------------------------------------------------
// Low-poly tiled roof
// -------------------------------------------------------------------------
const roofPositions = [];
const eaveX0 = 4.38;
const eaveX1 = 9.72;
const ridgeX = 7.05;
const eaveY = 7.25;
const ridgeY = 8.92;
const roofZ0 = -6.02;
const roofZ1 = 6.02;
addQuad(
roofPositions,
[eaveX0, eaveY, roofZ0],
[ridgeX, ridgeY, roofZ0],
[ridgeX, ridgeY, roofZ1],
[eaveX0, eaveY, roofZ1]
);
addQuad(
roofPositions,
[ridgeX, ridgeY, roofZ0],
[eaveX1, eaveY, roofZ0],
[eaveX1, eaveY, roofZ1],
[ridgeX, ridgeY, roofZ1]
);
const roofMaterial = mat.roof.clone();
roofMaterial.side = THREE.DoubleSide;
mesh(geometryFromPositions(roofPositions), roofMaterial);
// Gable ends.
const gablePositions = [];
addQuad(
gablePositions,
[eaveX0, eaveY, roofZ0],
[ridgeX, ridgeY, roofZ0],
[eaveX1, eaveY, roofZ0],
[eaveX0, eaveY, roofZ0]
);
addQuad(
gablePositions,
[eaveX0, eaveY, roofZ1],
[ridgeX, ridgeY, roofZ1],
[eaveX1, eaveY, roofZ1],
[eaveX0, eaveY, roofZ1]
);
const gableMaterial = mat.facade.clone();
gableMaterial.side = THREE.DoubleSide;
mesh(geometryFromPositions(gablePositions), gableMaterial);
// Roof ridge and a small chimney.
box(0.22, 0.20, 12.2, mat.roofDark, ridgeX, ridgeY + 0.02, 0);
box(0.65, 1.15, 0.68, mat.trim, 8.20, 8.18, -3.50);
box(0.82, 0.16, 0.84, mat.roofDark, 8.20, 8.80, -3.50);
// -------------------------------------------------------------------------
// Street furniture
// -------------------------------------------------------------------------
function addLamp(x, z) {
const y = grade(z);
cylinder(0.12, 0.17, 0.28, 6, mat.pole, x, y + 0.14, z);
cylinder(0.055, 0.075, 3.55, 6, mat.pole, x, y + 1.88, z);
box(0.50, 0.08, 0.08, mat.pole, x + 0.20, y + 3.55, z);
box(0.28, 0.38, 0.28, mat.lantern, x + 0.39, y + 3.29, z);
box(0.39, 0.10, 0.39, mat.pole, x + 0.39, y + 3.53, z);
box(0.34, 0.09, 0.34, mat.pole, x + 0.39, y + 3.06, z);
}
addLamp(-3.73, -8.4);
addLamp(-3.73, 8.8);
function addPlanter(x, z) {
const y = grade(z) + 0.18;
cylinder(0.29, 0.22, 0.43, 7, mat.terracotta, x, y + 0.215, z);
cylinder(0.31, 0.31, 0.07, 7, mat.foundation, x, y + 0.43, z);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const radius = 0.16 + (i % 2) * 0.06;
const leaf = mesh(
new THREE.ConeGeometry(0.16, 0.78 + (i % 3) * 0.11, 5),
i % 2 ? mat.leafLight : mat.leaf,
x + Math.cos(angle) * radius,
y + 0.83 + (i % 2) * 0.08,
z + Math.sin(angle) * radius
);
leaf.rotation.z = Math.cos(angle) * 0.42;
leaf.rotation.x = Math.sin(angle) * 0.42;
}
}
addPlanter(4.03, 3.52);
addPlanter(-3.98, -2.65);
// A simple human figure provides scale without obscuring the architecture.
function addFigure(x, z) {
const y = grade(z) + 0.025;
const body = cylinder(0.13, 0.20, 0.62, 6, mat.shutter, x, y + 0.91, z);
body.rotation.z = 0.025;
mesh(new THREE.SphereGeometry(0.15, 7, 5), mat.wood, x, y + 1.40, z);
box(0.10, 0.55, 0.12, mat.iron, x - 0.09, y + 0.30, z);
box(0.10, 0.55, 0.12, mat.iron, x + 0.09, y + 0.30, z);
box(0.09, 0.48, 0.10, mat.shutter, x - 0.20, y + 0.98, z);
box(0.09, 0.48, 0.10, mat.shutter, x + 0.20, y + 0.98, z);
}
addFigure(2.72, 1.70);
// -------------------------------------------------------------------------
// Direct camera controls — no addons or external controls
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(1.2, 2.05, 0),
desiredTarget: new THREE.Vector3(1.2, 2.05, 0),
yaw: -0.74,
desiredYaw: -0.74,
pitch: 1.22,
desiredPitch: 1.22,
radius: 22.0,
desiredRadius: 22.0
};
const presets = {
overview: {
target: [1.2, 2.05, 0],
yaw: -0.74,
pitch: 1.22,
radius: 22.0
},
doorway: {
target: [3.25, 1.40, 0.30],
yaw: -1.10,
pitch: 1.18,
radius: 8.4
},
grade: {
target: [0.0, 0.20, 0.0],
yaw: -1.57,
pitch: 1.30,
radius: 25.5
}
};
function applyPreset(name) {
const preset = presets[name];
controls.desiredTarget.set(...preset.target);
controls.desiredYaw = preset.yaw;
controls.desiredPitch = preset.pitch;
controls.desiredRadius = preset.radius;
document.querySelectorAll("[data-preset]").forEach(button => {
button.classList.toggle("active", button.dataset.preset === name);
});
}
document.querySelectorAll("[data-preset]").forEach(button => {
button.addEventListener("click", () => {
applyPreset(button.dataset.preset);
});
});
const pointers = new Map();
let orbiting = false;
let panning = false;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
orbiting = event.button !== 2;
panning = event.button === 2;
}
});
canvas.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
if (pointers.size === 1) {
if (orbiting) {
controls.desiredYaw -= dx * 0.005;
controls.desiredPitch = THREE.MathUtils.clamp(
controls.desiredPitch - dy * 0.0045,
0.40,
1.47
);
} else if (panning) {
const scale = controls.desiredRadius * 0.0014;
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
controls.desiredTarget.addScaledVector(right, -dx * scale);
controls.desiredTarget.addScaledVector(up, dy * scale);
}
} else if (pointers.size === 2) {
const entries = [...pointers.values()];
if (entries.length < 2) return;
const oldDistance = Math.hypot(
entries[0].x - entries[1].x,
entries[0].y - entries[1].y
);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const updated = [...pointers.values()];
const newDistance = Math.hypot(
updated[0].x - updated[1].x,
updated[0].y - updated[1].y
);
if (oldDistance > 0 && newDistance > 0) {
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * (oldDistance / newDistance),
4.5,
42
);
}
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
orbiting = false;
panning = false;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
4.5,
42
);
},
{ passive: false }
);
function updateCamera() {
const damping = 0.12;
controls.yaw = THREE.MathUtils.lerp(
controls.yaw,
controls.desiredYaw,
damping
);
controls.pitch = THREE.MathUtils.lerp(
controls.pitch,
controls.desiredPitch,
damping
);
controls.radius = THREE.MathUtils.lerp(
controls.radius,
controls.desiredRadius,
damping
);
controls.target.lerp(controls.desiredTarget, damping);
const offset = new THREE.Vector3().setFromSphericalCoords(
controls.radius,
controls.pitch,
controls.yaw
);
camera.position.copy(controls.target).add(offset);
camera.lookAt(controls.target);
}
// -------------------------------------------------------------------------
// Projected model annotations
// -------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#label-steps"),
position: new THREE.Vector3(3.25, 1.08, 0.30)
},
{
element: document.querySelector("#label-grade"),
position: new THREE.Vector3(-0.75, 0.38, -7.6)
},
{
element: document.querySelector("#label-facade"),
position: new THREE.Vector3(4.22, 6.15, 3.20)
}
];
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
label.element.style.display = visible ? "block" : "none";
if (visible) {
label.element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
let firstFrame = true;
renderer.setAnimationLoop(() => {
updateCamera();
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
}
});
</script>
</body>
</html>
```