Prompt specification
Build or customize the Three.js 3D scene "Mombasa balcony and carved doorway 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: Mombasa balcony and carved doorway fragment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mombasa-balcony-and-carved-doorway-fragment-x2941
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a balcony and carved doorway in Mombasa Old Town. Build a referenced Old Town balcony and doorway bay with visible timber projections. Show how the upper structure shades the street without copying a private facade in exact detail. Voxel style.
Working Three.js Starter (mombasa-balcony-and-carved-doorway-fragment-x2941):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mombasa Old Town — Balcony & Carved Doorway</title>
<style>
:root {
--ink: #20302e;
--paper: rgba(248, 240, 222, 0.92);
--line: rgba(32, 48, 46, 0.18);
--accent: #b8563f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8d8d4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 12px 32px rgba(40, 46, 41, 0.12);
backdrop-filter: blur(10px);
}
#title {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
border-radius: 4px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 38px);
font-weight: 500;
line-height: 1.04;
letter-spacing: -0.025em;
}
#title p {
margin: 11px 0 0;
max-width: 330px;
font-size: 12px;
line-height: 1.55;
opacity: 0.72;
}
#legend {
right: 24px;
bottom: 24px;
max-width: 330px;
padding: 14px 16px;
border-radius: 4px;
font-size: 11px;
line-height: 1.5;
}
#legend strong {
display: block;
margin-bottom: 5px;
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.key {
display: inline-block;
min-width: 22px;
margin: 0 2px 2px 0;
padding: 2px 5px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(255, 255, 255, 0.45);
text-align: center;
font-size: 10px;
font-weight: 700;
}
#reset {
position: fixed;
right: 24px;
top: 24px;
z-index: 11;
padding: 11px 15px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 12px 32px rgba(40, 46, 41, 0.12);
cursor: pointer;
font: 700 10px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#reset:hover {
background: #fff9ec;
}
.hotspot {
position: fixed;
z-index: 8;
display: flex;
align-items: center;
gap: 8px;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
}
.hotspot .dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border: 2px solid rgba(255, 255, 255, 0.9);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 8px rgba(31, 43, 40, 0.35);
}
.hotspot .label {
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.34);
border-radius: 3px;
background: rgba(30, 43, 40, 0.83);
color: #fff8e9;
box-shadow: 0 5px 16px rgba(31, 43, 40, 0.16);
white-space: nowrap;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #d8e2dc;
color: #30413e;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#title {
top: 14px;
left: 14px;
width: calc(100vw - 110px);
padding: 14px;
}
#title p {
display: none;
}
#reset {
top: 14px;
right: 14px;
padding: 10px 11px;
}
#legend {
right: 14px;
bottom: 14px;
left: 14px;
max-width: none;
}
.hotspot .label {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the Old Town bay…</div>
<header id="title" class="panel">
<div class="eyebrow">Mombasa · Coastal Architecture</div>
<h1>Balcony &<br />Carved Doorway</h1>
<p>
A generalized voxel interpretation of Mombasa Old Town: coral plaster,
deep-set carved timber, a projecting balcony, and a shaded street edge.
Not a literal reconstruction of a private façade.
</p>
</header>
<button id="reset" type="button" aria-label="Reset camera view">
Reset view
</button>
<div id="legend" class="panel">
<strong>Explore the bay</strong>
Drag to orbit · Scroll or pinch to zoom ·
<span class="key">←</span><span class="key">→</span> rotate ·
<span class="key">+</span><span class="key">−</span> zoom ·
<span class="key">R</span> reset
</div>
<div class="hotspot" id="spot-timber">
<span class="dot"></span>
<span class="label">Projecting timber joists</span>
</div>
<div class="hotspot" id="spot-door">
<span class="dot"></span>
<span class="label">Stepped carved doorway</span>
</div>
<div class="hotspot" id="spot-shade">
<span class="dot"></span>
<span class="label">Shade at street level</span>
</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 palette
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8d8d4);
scene.fog = new THREE.Fog(0xc8d8d4, 20, 48);
const camera = new THREE.PerspectiveCamera(
45,
innerWidth / innerHeight,
0.1,
100
);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
document.getElementById("loading").textContent =
"This scene requires a browser with WebGL enabled.";
throw error;
}
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
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 palette = {
plaster: 0xc77b61,
plasterLight: 0xd99073,
plasterDark: 0xa85f4f,
ochre: 0xc7a16b,
paleOchre: 0xd9bd88,
cream: 0xe7cda3,
stone: 0x9c8e78,
stoneLight: 0xb8aa91,
street: 0x68716b,
wood: 0x43271d,
woodMid: 0x6a3d27,
woodLight: 0x99613a,
carved: 0xb78043,
teal: 0x397a72,
blue: 0x486f78,
dark: 0x171b19,
metal: 0x66543e
};
function mat(color, roughness = 0.86, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const M = {
plaster: mat(palette.plaster),
plasterLight: mat(palette.plasterLight),
plasterDark: mat(palette.plasterDark),
ochre: mat(palette.ochre),
paleOchre: mat(palette.paleOchre),
cream: mat(palette.cream),
stone: mat(palette.stone),
stoneLight: mat(palette.stoneLight),
wood: mat(palette.wood),
woodMid: mat(palette.woodMid),
woodLight: mat(palette.woodLight),
carved: mat(palette.carved),
teal: mat(palette.teal),
blue: mat(palette.blue),
dark: mat(palette.dark),
metal: mat(palette.metal, 0.58, 0.18)
};
// Shared cube geometry keeps the scene lightweight.
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(
parent,
width,
height,
depth,
x,
y,
z,
material,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, thickness, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = box(
parent,
thickness,
length,
thickness,
midpoint.x,
midpoint.y,
midpoint.z,
material
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// Deterministic randomness for repeatable masonry and paving.
let seed = 1937;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(a, b) {
return a + (b - a) * random();
}
// ------------------------------------------------------------
// Light
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe9f3ed, 0x74665b, 1.55);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4b8, 3.7);
sun.position.set(-5, 14, 10);
sun.target.position.set(-1.5, 0, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun, sun.target);
const bounce = new THREE.DirectionalLight(0x86b8bd, 0.6);
bounce.position.set(8, 5, -8);
scene.add(bounce);
// ------------------------------------------------------------
// Street and paving
// ------------------------------------------------------------
const architecture = new THREE.Group();
scene.add(architecture);
box(
architecture,
38,
0.4,
25,
0,
-0.25,
5.5,
mat(palette.street),
false,
true
);
// Raised pavement immediately in front of the façades.
box(
architecture,
32,
0.2,
2.65,
0,
-0.02,
1.15,
M.stoneLight,
false,
true
);
const pavingGeometry = new THREE.BoxGeometry(1, 1, 1);
const pavingMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const pavingRows = 4;
const pavingColumns = 28;
const pavingCount = pavingRows * pavingColumns;
const paving = new THREE.InstancedMesh(
pavingGeometry,
pavingMaterial,
pavingCount
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < pavingRows; row++) {
for (let col = 0; col < pavingColumns; col++) {
const offset = row % 2 === 0 ? 0 : 0.55;
dummy.position.set(
-14 + col * 1.08 + offset,
0.105 + range(-0.008, 0.008),
0.15 + row * 0.64
);
dummy.rotation.set(0, range(-0.015, 0.015), 0);
dummy.scale.set(
range(0.94, 1.04),
range(0.07, 0.12),
range(0.54, 0.61)
);
dummy.updateMatrix();
paving.setMatrixAt(tileIndex, dummy.matrix);
const warmth = range(0, 0.13);
tileColor.setHSL(0.105, 0.12, 0.61 + warmth);
paving.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
paving.receiveShadow = true;
architecture.add(paving);
// Instanced voxel cobbles in the road.
const cobbleColumns = 36;
const cobbleRows = 19;
const cobbleCount = cobbleColumns * cobbleRows;
const cobbles = new THREE.InstancedMesh(
pavingGeometry,
pavingMaterial,
cobbleCount
);
let cobbleIndex = 0;
for (let row = 0; row < cobbleRows; row++) {
for (let col = 0; col < cobbleColumns; col++) {
const offset = row % 2 === 0 ? 0 : 0.3;
dummy.position.set(
-17.7 + col * 1.0 + offset + range(-0.08, 0.08),
-0.018 + range(-0.012, 0.012),
3.05 + row * 0.61 + range(-0.06, 0.06)
);
dummy.rotation.set(0, range(-0.05, 0.05), 0);
dummy.scale.set(
range(0.76, 0.96),
range(0.07, 0.13),
range(0.44, 0.58)
);
dummy.updateMatrix();
cobbles.setMatrixAt(cobbleIndex, dummy.matrix);
const lightness = range(0.30, 0.43);
tileColor.setHSL(range(0.08, 0.15), range(0.05, 0.12), lightness);
cobbles.setColorAt(cobbleIndex, tileColor);
cobbleIndex++;
}
}
cobbles.receiveShadow = true;
architecture.add(cobbles);
// ------------------------------------------------------------
// Reusable architectural details
// ------------------------------------------------------------
function makeWindow(
parent,
x,
y,
width,
height,
z,
accent = M.teal,
lattice = true
) {
box(parent, width, height, 0.08, x, y, z, M.dark);
// Projecting frame.
box(
parent,
width + 0.32,
0.17,
0.19,
x,
y + height / 2 + 0.08,
z + 0.1,
M.cream
);
box(
parent,
width + 0.32,
0.17,
0.19,
x,
y - height / 2 - 0.08,
z + 0.1,
M.cream
);
for (const side of [-1, 1]) {
box(
parent,
0.17,
height + 0.28,
0.19,
x + side * (width / 2 + 0.08),
y,
z + 0.1,
M.cream
);
}
// Narrow timber sash.
box(
parent,
0.09,
height,
0.12,
x,
y,
z + 0.13,
M.woodMid
);
box(
parent,
width,
0.09,
0.12,
x,
y,
z + 0.13,
M.woodMid
);
if (lattice) {
for (let i = 1; i < 4; i++) {
box(
parent,
0.065,
height - 0.08,
0.1,
x - width / 2 + (width * i) / 4,
y,
z + 0.19,
accent
);
}
for (let i = 1; i < 3; i++) {
box(
parent,
width - 0.08,
0.055,
0.1,
x,
y - height / 2 + (height * i) / 3,
z + 0.19,
accent
);
}
}
// Sill.
box(
parent,
width + 0.48,
0.14,
0.38,
x,
y - height / 2 - 0.16,
z + 0.12,
M.stoneLight
);
}
function addPlasterPatches(parent, x0, x1, y0, y1, z, count) {
const colors = [M.plaster, M.plasterLight, M.plasterDark];
for (let i = 0; i < count; i++) {
const w = range(0.18, 0.55);
const h = range(0.12, 0.38);
box(
parent,
w,
h,
range(0.025, 0.06),
range(x0, x1),
range(y0, y1),
z + range(0.015, 0.04),
colors[Math.floor(random() * colors.length)],
false,
true
);
}
}
function makeSimpleDoor(parent, x, y, width, height, z, color) {
box(parent, width, height, 0.12, x, y, z, M.dark);
box(parent, width - 0.12, height - 0.12, 0.1, x, y, z + 0.08, color);
for (const side of [-1, 1]) {
box(
parent,
0.16,
height + 0.18,
0.18,
x + side * (width / 2 + 0.07),
y,
z + 0.12,
M.cream
);
}
box(
parent,
width + 0.3,
0.18,
0.22,
x,
y + height / 2 + 0.06,
z + 0.13,
M.cream
);
box(
parent,
0.07,
0.2,
0.09,
x + width * 0.25,
y,
z + 0.18,
M.carved
);
}
// ------------------------------------------------------------
// Main Old Town bay
// ------------------------------------------------------------
const hero = new THREE.Group();
architecture.add(hero);
// Lower storey, split around a recessed doorway.
box(hero, 3.1, 3.5, 3.3, -4.45, 1.75, -1.65, M.plaster);
box(hero, 3.3, 3.5, 3.3, 0.95, 1.75, -1.65, M.plaster);
// Upper storey.
box(hero, 9, 3.5, 3.3, -1.7, 5.25, -1.6, M.plasterLight);
// Recess behind the carved entrance.
box(hero, 2.2, 3.05, 0.16, -1.8, 1.525, -0.34, M.dark);
// Upper cornice and parapet.
box(hero, 9.3, 0.2, 3.5, -1.7, 7.08, -1.55, M.cream);
box(hero, 9.05, 0.42, 3.25, -1.7, 7.35, -1.6, M.plaster);
box(hero, 9.4, 0.14, 3.55, -1.7, 7.62, -1.55, M.cream);
// Vertical façade strips.
for (const x of [-5.82, 2.34]) {
box(hero, 0.24, 7.05, 0.18, x, 3.525, 0.09, M.cream);
box(hero, 0.38, 0.18, 0.26, x, 0.16, 0.12, M.stoneLight);
}
// Plaster irregularities, kept as shallow voxel patches.
addPlasterPatches(hero, -5.7, 2.2, 0.5, 3.35, 0.03, 42);
addPlasterPatches(hero, -5.7, 2.2, 3.9, 6.85, 0.08, 48);
// ----------------------------------------------------------
// Carved doorway
// ----------------------------------------------------------
const doorway = new THREE.Group();
hero.add(doorway);
// Deep-set timber leaf.
box(doorway, 1.68, 2.08, 0.13, -1.8, 1.04, -0.17, M.wood);
box(doorway, 1.35, 1.78, 0.08, -1.8, 1.0, -0.085, M.woodMid);
// Stepped wooden crown of the recessed opening.
box(doorway, 1.68, 0.28, 0.13, -1.8, 2.22, -0.17, M.wood);
box(doorway, 1.32, 0.28, 0.13, -1.8, 2.5, -0.17, M.woodMid);
box(doorway, 0.96, 0.28, 0.13, -1.8, 2.78, -0.17, M.wood);
// Stone jambs.
for (const side of [-1, 1]) {
box(
doorway,
0.2,
2.72,
0.27,
-1.8 + side * 1.08,
1.36,
0.04,
M.cream
);
box(
doorway,
0.34,
0.18,
0.36,
-1.8 + side * 1.13,
0.12,
0.1,
M.stoneLight
);
}
// Stepped lintel and crown blocks.
box(doorway, 2.48, 0.23, 0.3, -1.8, 2.72, 0.06, M.cream);
box(doorway, 2.14, 0.23, 0.31, -1.8, 2.94, 0.08, M.cream);
box(doorway, 1.78, 0.23, 0.32, -1.8, 3.16, 0.1, M.cream);
// Carved timber lintel and alternating relief cubes.
box(doorway, 2.26, 0.16, 0.38, -1.8, 2.5, 0.16, M.woodMid);
for (let i = 0; i < 10; i++) {
const x = -2.77 + i * 0.215;
const protrusion = i % 2 === 0 ? 0.34 : 0.26;
box(
doorway,
0.12,
0.13,
protrusion,
x,
2.5,
0.1 + protrusion / 2,
i % 3 === 0 ? M.carved : M.woodLight
);
}
// Relief blocks down the jambs.
for (const side of [-1, 1]) {
for (let i = 0; i < 10; i++) {
box(
doorway,
0.25,
0.13,
0.27,
-1.8 + side * 1.08,
0.35 + i * 0.225,
0.18,
i % 2 === 0 ? M.carved : M.woodLight
);
box(
doorway,
0.09,
0.09,
0.36,
-1.8 + side * 1.08,
0.47 + i * 0.225,
0.2,
M.woodMid
);
}
}
// Geometric motifs beside the door.
for (const side of [-1, 1]) {
const motifX = -1.8 + side * 1.64;
box(doorway, 0.52, 0.12, 0.12, motifX, 1.78, 0.13, M.teal);
box(doorway, 0.12, 0.52, 0.12, motifX, 1.78, 0.13, M.teal);
box(doorway, 0.25, 0.08, 0.14, motifX, 1.78, 0.18, M.carved);
box(doorway, 0.08, 0.25, 0.14, motifX, 1.78, 0.18, M.carved);
}
// Door panels and iron-like studs.
for (const side of [-1, 1]) {
box(
doorway,
0.56,
1.42,
0.08,
-1.8 + side * 0.39,
1.08,
-0.015,
M.wood
);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 2; col++) {
box(
doorway,
0.055,
0.055,
0.045,
-1.8 + side * 0.39 + (col - 0.5) * 0.2,
0.62 + row * 0.22,
0.015,
M.carved
);
}
}
}
box(doorway, 0.08, 0.3, 0.09, -1.8 + 0.28, 1.13, 0.02, M.metal);
// Stone threshold and shallow steps.
box(hero, 2.45, 0.14, 0.62, -1.8, 0.16, 0.18, M.stoneLight);
box(hero, 2.8, 0.12, 0.32, -1.8, 0.07, 0.52, M.stone);
// ----------------------------------------------------------
// Upper windows
// ----------------------------------------------------------
makeWindow(hero, -3.28, 5.3, 1.18, 1.65, 0.08, M.teal, true);
makeWindow(hero, -0.35, 5.3, 1.18, 1.65, 0.08, M.teal, true);
// Small blocked or shaded opening near the right.
box(hero, 0.8, 0.9, 0.08, 1.55, 5.35, 0.08, M.dark);
box(hero, 0.58, 0.68, 0.08, 1.55, 5.35, 0.13, M.blue);
// ----------------------------------------------------------
// Projecting balcony and exposed timber structure
// ----------------------------------------------------------
const balcony = new THREE.Group();
hero.add(balcony);
const balconyCenterX = -1.7;
const balconyWidth = 8.5;
const balconyY = 3.57;
// Individual floorboards.
const boardCount = 14;
const boardWidth = balconyWidth / boardCount;
for (let i = 0; i < boardCount; i++) {
const x = balconyCenterX - balconyWidth / 2 + boardWidth * (i + 0.5);
box(
balcony,
boardWidth - 0.025,
0.2,
1.28,
x,
balconyY,
0.39,
i % 3 === 0 ? M.woodMid : M.wood
);
}
// Deep fascia beam at the street-facing edge.
box(
balcony,
balconyWidth + 0.15,
0.32,
0.25,
balconyCenterX,
balconyY - 0.14,
1.03,
M.woodMid
);
// Exposed joists projecting from the wall.
const joistCount = 13;
for (let i = 0; i < joistCount; i++) {
const x = -5.55 + i * 0.64;
box(
balcony,
0.15,
0.25,
1.43,
x,
balconyY - 0.22,
0.36,
M.woodLight
);
// Stepped carved end of each projecting joist.
box(
balcony,
0.18,
0.28,
0.18,
x,
balconyY - 0.25,
1.1,
M.woodMid
);
box(
balcony,
0.12,
0.14,
0.25,
x,
balconyY - 0.4,
1.04,
M.carved
);
}
// Diagonal brackets and corbels visible from below.
const bracketXs = [-5.25, -3.25, 0.05, 1.85];
for (const x of bracketXs) {
beam(
balcony,
[x, 2.55, 0.12],
[x, 3.3, 0.96],
0.19,
M.woodMid
);
box(balcony, 0.38, 0.2, 0.42, x, 2.61, 0.24, M.wood);
box(balcony, 0.28, 0.16, 0.55, x, 2.83, 0.34, M.woodMid);
box(balcony, 0.2, 0.12, 0.68, x, 3.02, 0.46, M.woodLight);
}
// Front railing.
const railZ = 1.02;
const railBottom = 3.72;
const railTop = 4.92;
const railX0 = -5.75;
const railX1 = 2.35;
const railPosts = 14;
box(
balcony,
balconyWidth,
0.15,
0.18,
balconyCenterX,
railBottom,
railZ,
M.woodMid
);
box(
balcony,
balconyWidth + 0.16,
0.2,
0.22,
balconyCenterX,
railTop,
railZ,
M.wood
);
for (let i = 0; i <= railPosts; i++) {
const x = railX0 + ((railX1 - railX0) * i) / railPosts;
box(
balcony,
0.13,
railTop - railBottom + 0.13,
0.15,
x,
(railBottom + railTop) / 2,
railZ,
M.woodLight
);
// Small square finial.
box(
balcony,
0.19,
0.14,
0.19,
x,
railTop + 0.12,
railZ,
M.carved
);
}
// Fine diagonal timber lattice in alternating bays.
for (let i = 0; i < railPosts; i++) {
const xa = railX0 + ((railX1 - railX0) * i) / railPosts;
const xb = railX0 + ((railX1 - railX0) * (i + 1)) / railPosts;
if (i % 2 === 0) {
beam(
balcony,
[xa + 0.08, railBottom + 0.13, railZ + 0.04],
[xb - 0.08, railTop - 0.12, railZ + 0.04],
0.055,
M.woodLight
);
} else {
beam(
balcony,
[xa + 0.08, railTop - 0.12, railZ + 0.04],
[xb - 0.08, railBottom + 0.13, railZ + 0.04],
0.055,
M.woodLight
);
}
}
// Side railings.
for (const x of [railX0, railX1]) {
box(balcony, 0.14, 0.16, 1.28, x, railBottom, 0.45, M.woodMid);
box(balcony, 0.17, 0.2, 1.35, x, railTop, 0.45, M.wood);
box(balcony, 0.13, 1.1, 0.13, x, 4.25, 0.45, M.woodLight);
}
// ----------------------------------------------------------
// Neighbouring façades for urban context
// ----------------------------------------------------------
const rightBuilding = new THREE.Group();
architecture.add(rightBuilding);
box(rightBuilding, 7.4, 8.1, 2.5, 6.4, 4.05, -1.8, M.ochre);
box(rightBuilding, 7.7, 0.22, 2.75, 6.4, 8.15, -1.75, M.cream);
box(rightBuilding, 7.5, 0.38, 2.6, 6.4, 8.42, -1.8, M.paleOchre);
box(rightBuilding, 7.8, 0.14, 2.8, 6.4, 8.66, -1.75, M.cream);
makeWindow(rightBuilding, 4.65, 6.55, 1.25, 1.6, -0.49, M.teal);
makeWindow(rightBuilding, 7.0, 6.55, 1.25, 1.6, -0.49, M.teal);
makeWindow(rightBuilding, 9.1, 6.55, 1.05, 1.4, -0.49, M.blue, false);
makeSimpleDoor(rightBuilding, 6.15, 1.4, 1.35, 2.8, -0.48, M.blue);
// A smaller contextual balcony, distinct from the main bay.
box(rightBuilding, 3.6, 0.2, 1.0, 5.85, 3.35, -0.08, M.wood);
box(rightBuilding, 3.7, 0.23, 0.2, 5.85, 3.22, 0.4, M.woodMid);
for (let i = 0; i < 7; i++) {
const x = 4.25 + i * 0.53;
box(rightBuilding, 0.12, 1.05, 0.13, x, 3.95, 0.4, M.woodLight);
box(rightBuilding, 0.14, 1.35, 0.18, x, 3.35, 0.1, M.woodMid);
}
box(rightBuilding, 3.65, 0.16, 0.18, 5.85, 4.5, 0.4, M.wood);
beam(
rightBuilding,
[4.3, 3.5, 0.08],
[5.1, 3.25, 0.36],
0.13,
M.woodMid
);
beam(
rightBuilding,
[7.65, 3.5, 0.08],
[6.75, 3.25, 0.36],
0.13,
M.woodMid
);
const leftBuilding = new THREE.Group();
architecture.add(leftBuilding);
box(leftBuilding, 8.8, 7.6, 2.7, -10.5, 3.8, -2.05, M.plasterDark);
box(leftBuilding, 9.0, 0.2, 2.9, -10.5, 7.68, -2.0, M.cream);
box(leftBuilding, 8.8, 0.34, 2.75, -10.5, 7.95, -2.05, M.plaster);
makeWindow(leftBuilding, -12.4, 5.8, 1.25, 1.65, -0.64, M.blue);
makeWindow(leftBuilding, -9.9, 5.8, 1.25, 1.65, -0.64, M.blue);
makeWindow(leftBuilding, -7.45, 5.8, 1.1, 1.55, -0.64, M.teal, false);
makeSimpleDoor(leftBuilding, -9.8, 1.35, 1.3, 2.7, -0.64, M.teal);
addPlasterPatches(
leftBuilding,
-14.6,
-6.3,
0.4,
7.2,
-0.65,
68
);
// Upper background mass helps create an enclosed old-town street.
box(
architecture,
10,
8.5,
3.2,
0.7,
4.25,
-7,
mat(0xb7a789),
true,
true
);
// ------------------------------------------------------------
// Street-scale details
// ------------------------------------------------------------
// Simple voxel street lamp.
const lamp = new THREE.Group();
architecture.add(lamp);
box(lamp, 0.2, 4.1, 0.2, 10.3, 2.05, 3.0, M.metal);
box(lamp, 0.72, 0.12, 0.72, 10.3, 4.13, 3.0, M.metal);
box(lamp, 0.48, 0.48, 0.48, 10.3, 3.87, 3.0, M.cream);
box(lamp, 0.58, 0.1, 0.58, 10.3, 4.25, 3.0, M.metal);
// Low curb blocks, retaining the voxel rhythm.
for (let i = 0; i < 14; i++) {
box(
architecture,
0.88,
0.22,
0.34,
-12.3 + i * 1.72,
0.12,
2.67,
i % 3 === 0 ? M.stoneLight : M.stone,
true,
true
);
}
// ------------------------------------------------------------
// Custom orbit controls — no Three.js addons
// ------------------------------------------------------------
const controlState = {
target: new THREE.Vector3(-1.4, 3.05, 0.35),
desiredTarget: new THREE.Vector3(-1.4, 3.05, 0.35),
theta: 0.52,
phi: 1.19,
radius: 15.6,
desiredTheta: 0.52,
desiredPhi: 1.19,
desiredRadius: 15.6
};
function updateCamera() {
controlState.theta +=
(controlState.desiredTheta - controlState.theta) * 0.1;
controlState.phi +=
(controlState.desiredPhi - controlState.phi) * 0.1;
controlState.radius +=
(controlState.desiredRadius - controlState.radius) * 0.1;
controlState.target.lerp(controlState.desiredTarget, 0.1);
const sinPhi = Math.sin(controlState.phi);
camera.position.set(
controlState.target.x +
controlState.radius * sinPhi * Math.sin(controlState.theta),
controlState.target.y + controlState.radius * Math.cos(controlState.phi),
controlState.target.z +
controlState.radius * sinPhi * Math.cos(controlState.theta)
);
camera.lookAt(controlState.target);
}
function resetCamera() {
controlState.desiredTheta = 0.52;
controlState.desiredPhi = 1.19;
controlState.desiredRadius = 15.6;
controlState.desiredTarget.set(-1.4, 3.05, 0.35);
}
document.getElementById("reset").addEventListener("click", resetCamera);
const canvas = renderer.domElement;
const pointers = new Map();
let lastPointer = null;
let lastPinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.classList.add("dragging");
if (pointers.size === 1) {
lastPointer = { x: event.clientX, y: event.clientY };
} else if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && lastPointer) {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
controlState.desiredTheta -= dx * 0.006;
controlState.desiredPhi = THREE.MathUtils.clamp(
controlState.desiredPhi + dy * 0.005,
0.38,
1.47
);
lastPointer = { x: event.clientX, y: event.clientY };
} 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) {
const factor = lastPinchDistance / Math.max(distance, 1);
controlState.desiredRadius = THREE.MathUtils.clamp(
controlState.desiredRadius * factor,
7.5,
27
);
}
lastPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
lastPointer = null;
lastPinchDistance = 0;
canvas.classList.remove("dragging");
} else if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastPointer = { x: remaining.x, y: remaining.y };
lastPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controlState.desiredRadius = THREE.MathUtils.clamp(
controlState.desiredRadius * Math.exp(event.deltaY * 0.001),
7.5,
27
);
},
{ passive: false }
);
addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
controlState.desiredTheta += 0.09;
break;
case "ArrowRight":
controlState.desiredTheta -= 0.09;
break;
case "ArrowUp":
controlState.desiredPhi = Math.max(
0.38,
controlState.desiredPhi - 0.06
);
break;
case "ArrowDown":
controlState.desiredPhi = Math.min(
1.47,
controlState.desiredPhi + 0.06
);
break;
case "+":
case "=":
controlState.desiredRadius = Math.max(
7.5,
controlState.desiredRadius - 0.7
);
break;
case "-":
case "_":
controlState.desiredRadius = Math.min(
27,
controlState.desiredRadius + 0.7
);
break;
case "r":
case "R":
resetCamera();
break;
}
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Screen-space feature labels
// ------------------------------------------------------------
const hotspotData = [
{
element: document.getElementById("spot-timber"),
position: new THREE.Vector3(-4.25, 3.27, 1.12)
},
{
element: document.getElementById("spot-door"),
position: new THREE.Vector3(-1.8, 1.55, 0.35)
},
{
element: document.getElementById("spot-shade"),
position: new THREE.Vector3(-1.8, 0.2, 1.75)
}
];
const projected = new THREE.Vector3();
function updateHotspots() {
for (const hotspot of hotspotData) {
projected.copy(hotspot.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
hotspot.element.style.opacity = visible ? "1" : "0";
hotspot.element.style.left =
`${(projected.x * 0.5 + 0.5) * innerWidth}px`;
hotspot.element.style.top =
`${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
updateCamera();
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateHotspots();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```