Prompt specification
Build or customize the Three.js 3D scene "Balat bay window and steep doorway threshold" 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: Balat bay window and steep doorway threshold
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/balat-bay-window-and-steep-doorway-threshold-x2921
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Balat's hillside streets in Istanbul. Build a referenced Istanbul facade fragment with projecting bay window and stepped entrance. Show how the structure meets a sloping street while keeping the walls vertical. Voxel style.
Working Three.js Starter (balat-bay-window-and-steep-doorway-threshold-x2921):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Balat — Sloping Istanbul Facade</title>
<style>
:root {
--ink: #18313a;
--paper: rgba(250, 244, 225, 0.92);
--accent: #d76245;
--teal: #287b7d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a9cbd0;
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%;
touch-action: none;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 10;
max-width: min(390px, calc(100vw - 48px));
padding: 17px 19px 16px;
border: 1px solid rgba(24, 49, 58, 0.18);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 12px 36px rgba(24, 49, 58, 0.14);
backdrop-filter: blur(10px);
}
.eyebrow {
margin: 0 0 5px;
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(29px, 4vw, 45px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
font-size: 13px;
line-height: 1.45;
color: rgba(24, 49, 58, 0.76);
}
.legend {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 10;
width: min(270px, calc(100vw - 48px));
padding: 14px 15px;
border: 1px solid rgba(24, 49, 58, 0.16);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(24, 49, 58, 0.13);
backdrop-filter: blur(10px);
}
.legend-row {
display: grid;
grid-template-columns: 14px 1fr;
gap: 9px;
align-items: center;
margin: 7px 0;
font-size: 12px;
line-height: 1.25;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 1px;
border: 1px solid rgba(0, 0, 0, 0.16);
}
.controls {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 10;
display: flex;
align-items: center;
gap: 12px;
}
button {
appearance: none;
border: 1px solid rgba(24, 49, 58, 0.25);
border-radius: 3px;
padding: 10px 14px;
background: var(--paper);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 700;
box-shadow: 0 8px 20px rgba(24, 49, 58, 0.1);
}
button:hover {
background: #fffaf0;
transform: translateY(-1px);
}
.help {
max-width: 280px;
padding: 8px 10px;
border-radius: 3px;
background: rgba(250, 244, 225, 0.78);
color: rgba(24, 49, 58, 0.75);
font-size: 11px;
line-height: 1.4;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #a9cbd0;
color: #18313a;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 0.45s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.legend {
right: 14px;
bottom: 14px;
width: 220px;
}
.controls {
left: 14px;
bottom: 14px;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Assembling Balat…</div>
<section class="title-card">
<p class="eyebrow">Istanbul · Fatih</p>
<h1>Balat<br />Hillside</h1>
<p class="subtitle">
A voxel study of an Ottoman-era street facade: projecting bay window,
stepped stoop, and masonry foundations cut to a rising street.
</p>
</section>
<section class="legend" aria-label="Scene legend">
<div class="legend-row">
<span class="swatch" style="background:#cbb58c"></span>
<span>Stepped masonry base follows the street grade</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#287b7d"></span>
<span>Projecting timber bay window</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#b85e40"></span>
<span>Voxel-built stoop and recessed entrance</span>
</div>
</section>
<div class="controls">
<button id="reset" type="button">Reset view</button>
<div class="help">
Drag to orbit · Shift-drag to pan · Scroll to zoom<br />
Arrow keys rotate · R resets
</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 loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9cbd0);
scene.fog = new THREE.Fog(0xa9cbd0, 31, 78);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
140
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe5f6ff, 0x76614d, 1.8);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe4b5, 3.15);
sun.position.set(-13, 23, 15);
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 = 70;
sun.shadow.bias = -0.00035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x87bed2, 0.55);
coolFill.position.set(16, 9, -14);
scene.add(coolFill);
// ------------------------------------------------------------
// Shared voxel geometry and material helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${String(color)}|${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function box(parent, x, y, z, w, h, d, color, options = {}) {
const mesh = new THREE.Mesh(
unitBox,
typeof color === "object" && color.isMaterial
? color
: material(color, options)
);
mesh.position.set(x, y, z);
mesh.scale.set(w, h, d);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, thickness, color) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = box(
scene,
midpoint.x,
midpoint.y,
midpoint.z,
thickness,
direction.length(),
thickness,
color
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// ------------------------------------------------------------
// Sloping street geometry
//
// The road surface rises toward +X. The principal facade stays
// vertically plumb; only the stepped masonry base changes height.
// ------------------------------------------------------------
const streetSlope = 0.14;
const streetAngle = Math.atan(streetSlope);
const groundY = (x) => 0.7 + streetSlope * x;
const road = box(
scene,
0,
0.7 - 0.275 / Math.cos(streetAngle),
5.7,
39,
0.55,
10.4,
0x4f504b
);
road.rotation.z = streetAngle;
const sidewalk = box(
scene,
0,
0.7 + 0.14 - 0.12 / Math.cos(streetAngle),
0.58,
39,
0.24,
1.35,
0xb9aa8f
);
sidewalk.rotation.z = streetAngle;
const curb = box(
scene,
0,
0.7 + 0.11 - 0.09 / Math.cos(streetAngle),
1.25,
39,
0.18,
0.22,
0xd2c4a9
);
curb.rotation.z = streetAngle;
// Instanced voxel paving stones.
const paverGeometry = new THREE.BoxGeometry(1, 1, 1);
const paverMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
vertexColors: true
});
const paverCount = 47 * 17;
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
paverCount
);
pavers.receiveShadow = true;
pavers.castShadow = false;
const dummy = new THREE.Object3D();
const paverColor = new THREE.Color();
let paverIndex = 0;
for (let row = 0; row < 17; row++) {
for (let col = 0; col < 47; col++) {
const x = -18.8 + col * 0.41 + (row % 2) * 0.08;
const z = 1.45 + row * 0.61;
dummy.position.set(x, groundY(x) + 0.035, z);
dummy.rotation.set(0, 0, streetAngle);
dummy.scale.set(
0.35 + Math.random() * 0.035,
0.1,
0.51 + Math.random() * 0.055
);
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
const shade = 0.43 + Math.random() * 0.16;
paverColor.setHSL(0.105, 0.08, shade);
pavers.setColorAt(paverIndex, paverColor);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
if (pavers.instanceColor) pavers.instanceColor.needsUpdate = true;
scene.add(pavers);
// ------------------------------------------------------------
// Main facade fragment
// ------------------------------------------------------------
const facade = new THREE.Group();
facade.name = "Balat facade fragment";
scene.add(facade);
const plaster = 0xe8c98f;
const upperPlaster = 0xf0d8aa;
const trim = 0xf5ead0;
const wood = 0x563d32;
const darkWood = 0x3c302b;
const roofTile = 0x9b4f3d;
const glass = 0x244c58;
// Vertical facade walls. Their lower edge is level; the masonry
// foundation below is stepped to meet the sloping pavement.
box(facade, -1, 3.985, -0.18, 9, 3.13, 0.36, plaster);
box(facade, -1, 7.0, -0.18, 9, 2.9, 0.36, upperPlaster);
// Visible right return wall and rear wall.
box(facade, 3.5, 5.44, -2.0, 0.34, 6.04, 3.72, 0xd6b783);
box(facade, -5.5, 5.44, -2.0, 0.34, 6.04, 3.72, 0xd6b783);
box(facade, -1, 5.44, -3.84, 9, 6.04, 0.28, 0xc8a97a);
// Horizontal string courses and eaves.
box(facade, -1, 2.52, 0.06, 9.2, 0.22, 0.22, trim);
box(facade, -1, 5.53, 0.08, 9.18, 0.2, 0.25, trim);
box(facade, -1, 8.48, 0.04, 9.42, 0.26, 0.55, trim);
box(facade, -1, 8.62, -1.95, 9.45, 0.22, 4.5, darkWood);
// Stepped stone foundation: individual vertical masonry blocks rise
// from the sloping pavement to one constant horizontal datum.
const stoneColors = [
0xb6a27d,
0xc4b28d,
0xa89473,
0xcab894,
0xb09b77
];
for (let i = 0; i < 11; i++) {
const x = -5.05 + i * 0.9;
let bottom = groundY(x) + 0.13;
let course = 0;
while (bottom < 2.42) {
const desiredHeight = 0.39 + (course % 2) * 0.055;
const height = Math.min(desiredHeight, 2.42 - bottom);
box(
facade,
x,
bottom + height / 2,
0.03,
0.84,
height,
0.43,
stoneColors[(i + course) % stoneColors.length]
);
bottom += height;
course++;
}
}
// ------------------------------------------------------------
// Windows and shutters
// ------------------------------------------------------------
function addWindow(
parent,
x,
y,
z,
width,
height,
shutterColor = 0x287b7d,
frameColor = wood
) {
box(parent, x, y, z + 0.025, width, height, 0.07, glass);
box(parent, x, y + height / 2 + 0.045, z + 0.09, width + 0.18, 0.09, 0.13, frameColor);
box(parent, x, y - height / 2 - 0.045, z + 0.09, width + 0.18, 0.09, 0.13, frameColor);
box(parent, x - width / 2 - 0.045, y, z + 0.09, 0.09, height, 0.13, frameColor);
box(parent, x + width / 2 + 0.045, y, z + 0.09, 0.09, height, 0.13, frameColor);
box(parent, x, y, z + 0.1, 0.055, height, 0.09, frameColor);
if (shutterColor !== null) {
box(
parent,
x - width / 2 - 0.22,
y,
z + 0.12,
0.34,
height,
0.1,
shutterColor
);
box(
parent,
x + width / 2 + 0.22,
y,
z + 0.12,
0.34,
height,
0.1,
shutterColor
);
for (const shutterX of [
x - width / 2 - 0.22,
x + width / 2 + 0.22
]) {
for (let slat = -1; slat <= 1; slat++) {
box(
parent,
shutterX,
y + slat * height * 0.25,
z + 0.185,
0.28,
0.035,
0.035,
darkWood
);
}
}
}
}
addWindow(facade, -4.45, 4.15, 0.03, 1.15, 1.65, 0x476d8a);
addWindow(facade, -4.25, 7.12, 0.03, 1.25, 1.55, 0xbd6348);
addWindow(facade, 1.65, 7.12, 0.03, 1.35, 1.55, 0x287b7d);
// Small upper window in the narrow wall area.
addWindow(facade, -0.85, 7.62, 0.03, 0.62, 0.82, null);
// ------------------------------------------------------------
// Projecting bay window / oriel
// ------------------------------------------------------------
const bayX = -1.75;
const bayWidth = 3.2;
const bayFront = 1.45;
// Under-window projection and supporting corbels.
box(facade, bayX, 3.13, 0.7, bayWidth + 0.22, 0.22, 1.75, darkWood);
for (const x of [-3.05, -1.75, -0.45]) {
box(facade, x, 2.86, 0.48, 0.25, 0.42, 0.9, wood);
box(facade, x, 2.68, 0.3, 0.38, 0.18, 1.15, darkWood);
}
// Bay cheeks and central timber face.
box(facade, -3.35, 4.88, 0.71, 0.2, 3.35, 1.42, 0x6f4937);
box(facade, -0.15, 4.88, 0.71, 0.2, 3.35, 1.42, 0x6f4937);
box(facade, bayX, 4.88, 1.34, 2.98, 3.35, 0.22, 0x684334);
// Three glazed panels.
for (const x of [-2.72, -1.75, -0.78]) {
box(facade, x, 4.94, 1.48, 0.75, 2.18, 0.06, glass);
// Pixel-like reflections.
box(facade, x - 0.19, 5.27, 1.52, 0.1, 0.68, 0.025, 0x4d8290);
box(facade, x + 0.12, 4.36, 1.52, 0.16, 0.3, 0.025, 0x395f69);
}
// Timber mullions and rails.
for (const x of [-3.32, -2.24, -1.26, -0.18]) {
box(facade, x, 4.94, 1.58, 0.11, 3.28, 0.13, wood);
}
for (const y of [3.31, 4.35, 5.65, 6.67]) {
box(facade, bayX, y, 1.59, 3.25, 0.12, 0.15, wood);
}
// Decorative lower panels.
for (const x of [-2.72, -1.75, -0.78]) {
box(facade, x, 3.55, 1.56, 0.66, 0.28, 0.08, 0x81513b);
box(facade, x, 3.55, 1.61, 0.45, 0.12, 0.035, 0x342d2b);
}
// Bay crown.
box(facade, bayX, 6.83, 0.77, bayWidth + 0.32, 0.22, 1.82, darkWood);
box(facade, bayX, 6.99, 1.02, bayWidth + 0.18, 0.15, 1.43, trim);
box(facade, bayX, 7.13, 1.15, bayWidth + 0.04, 0.12, 1.16, wood);
// ------------------------------------------------------------
// Stepped entrance
// ------------------------------------------------------------
const entryX = 1.65;
// Six deep, block-built stoop steps.
const stepZ = [2.92, 2.43, 1.94, 1.45, 0.96, 0.47];
const stepTop = [1.27, 1.57, 1.87, 2.17, 2.47, 2.77];
for (let i = 0; i < stepZ.length; i++) {
const bottom = groundY(entryX) - 0.03;
const height = stepTop[i] - bottom;
box(
facade,
entryX,
bottom + height / 2,
stepZ[i],
2.02,
height,
0.56,
i % 2 === 0 ? 0xcab697 : 0xbba98b
);
}
// Upper landing.
box(facade, entryX, 2.87, 0.08, 2.22, 0.3, 0.8, 0xd1bd99);
box(facade, entryX, 3.05, 0.08, 2.35, 0.09, 0.88, trim);
// Door and frame.
box(facade, entryX, 4.55, 0.085, 1.52, 2.92, 0.15, 0x59382e);
box(facade, entryX - 0.86, 4.55, 0.17, 0.16, 3.15, 0.18, wood);
box(facade, entryX + 0.86, 4.55, 0.17, 0.16, 3.15, 0.18, wood);
box(facade, entryX, 6.08, 0.17, 1.88, 0.17, 0.18, wood);
// Stepped voxel arch around the top of the door.
box(facade, entryX, 6.25, 0.16, 1.18, 0.17, 0.18, wood);
box(facade, entryX - 0.59, 6.17, 0.16, 0.17, 0.17, 0.18, wood);
box(facade, entryX + 0.59, 6.17, 0.16, 0.17, 0.17, 0.18, wood);
box(facade, entryX, 6.42, 0.16, 0.55, 0.17, 0.18, wood);
box(facade, entryX, 6.57, 0.16, 0.18, 0.15, 0.18, wood);
// Door panels and handle.
for (const x of [entryX - 0.34, entryX + 0.34]) {
box(facade, x, 4.48, 0.18, 0.52, 1.86, 0.07, 0x704537);
box(facade, x, 4.95, 0.225, 0.36, 0.72, 0.025, 0x56362f);
}
box(facade, entryX + 0.5, 4.38, 0.24, 0.07, 0.07, 0.07, 0xd6a54c);
// Small balcony / stoop rail.
box(facade, entryX - 1.13, 3.58, 0.15, 0.08, 1.1, 0.08, darkWood);
box(facade, entryX + 1.13, 3.58, 0.15, 0.08, 1.1, 0.08, darkWood);
box(facade, entryX, 4.1, 0.15, 2.34, 0.08, 0.08, darkWood);
// Block-letter BALAT sign.
const signY = 6.95;
box(facade, entryX, signY, 0.14, 2.3, 0.79, 0.16, 0x315a5b);
box(facade, entryX, signY + 0.43, 0.22, 2.43, 0.08, 0.12, wood);
const glyphs = {
B: ["11110", "10001", "10001", "11110", "10001", "10001", "11110"],
A: ["01110", "10001", "10001", "11111", "10001", "10001", "10001"],
L: ["10000", "10000", "10000", "10000", "10000", "10000", "11111"],
T: ["11111", "00100", "00100", "00100", "00100", "00100", "00100"]
};
const word = "BALAT";
const pixel = 0.083;
const startX = entryX - ((word.length * 6 - 1) * pixel) / 2;
for (let c = 0; c < word.length; c++) {
const pattern = glyphs[word[c]];
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 5; col++) {
if (pattern[row][col] === "1") {
box(
facade,
startX + (c * 6 + col) * pixel,
signY + (3 - row) * pixel,
0.245,
pixel * 0.83,
pixel * 0.83,
0.035,
0xf1dba4
);
}
}
}
}
// ------------------------------------------------------------
// Voxel roof
// ------------------------------------------------------------
const roofColors = [0x9d4e3c, 0xad5942, 0x8e493b, 0xb86248];
for (let row = 0; row < 6; row++) {
const z = 0.03 - row * 0.68;
const y = 8.72 + row * 0.12;
for (let col = 0; col < 21; col++) {
const x = -5.67 + col * 0.455;
const tile = box(
facade,
x,
y,
z,
0.42,
0.18,
0.62,
roofColors[(row + col) % roofColors.length]
);
tile.rotation.z = ((col + row) % 3 - 1) * 0.012;
}
}
// Roof ridge and chimney.
box(facade, -1, 9.49, -1.73, 9.7, 0.17, 0.25, 0x6f392f);
box(facade, 1.9, 9.39, -2.7, 0.72, 1.35, 0.7, 0xbd8e69);
box(facade, 1.9, 10.1, -2.7, 0.88, 0.16, 0.86, trim);
// ------------------------------------------------------------
// Adjacent facades and distant hillside
// ------------------------------------------------------------
function simpleHouse(x, z, width, height, color, roofColor) {
const house = new THREE.Group();
scene.add(house);
const base = 2.38;
box(house, x, base + height / 2, z, width, height, 3.2, color);
box(house, x, base + 0.05, z + 1.64, width + 0.18, 0.2, 0.18, trim);
box(house, x, base + height - 0.05, z + 1.65, width + 0.3, 0.2, 0.3, trim);
for (let row = 0; row < 3; row++) {
box(
house,
x,
base + height + 0.1 + row * 0.13,
z + 0.2 - row * 0.58,
width + 0.38,
0.17,
0.56,
roofColor
);
}
const columns = Math.max(2, Math.floor(width / 2.0));
for (let row = 0; row < Math.floor(height / 2.1); row++) {
for (let col = 0; col < columns; col++) {
const wx =
x - width / 2 + width / columns * (col + 0.5);
const wy = base + 1.5 + row * 2.1;
box(house, wx, wy, z + 1.64, 0.62, 0.92, 0.06, glass);
box(house, wx, wy + 0.5, z + 1.7, 0.74, 0.08, 0.1, wood);
box(house, wx, wy - 0.5, z + 1.7, 0.74, 0.08, 0.1, wood);
}
}
return house;
}
simpleHouse(7.15, -2.55, 5.7, 5.8, 0x86b5aa, 0x9d4e3c);
simpleHouse(-9.35, -1.65, 4.8, 5.4, 0xc87557, 0x9b4f3d);
function backgroundHouse(x, z, base, width, height, color) {
box(scene, x, base + height / 2, z, width, height, 2.2, color);
box(
scene,
x,
base + height + 0.18,
z - 0.45,
width + 0.25,
0.3,
1.2,
0x965044
);
const windows = Math.max(1, Math.floor(width / 1.25));
for (let row = 0; row < 2; row++) {
for (let col = 0; col < windows; col++) {
const wx =
x - width / 2 + (width / windows) * (col + 0.5);
const wy = base + 0.85 + row * 1.3;
box(scene, wx, wy, z + 1.12, 0.43, 0.65, 0.05, 0x3b5c63);
box(scene, wx, wy, z + 1.15, 0.05, 0.67, 0.04, 0xddd0ae);
}
}
}
const hillColors = [
0xc8916e,
0xe0ad7c,
0x9eb6a3,
0xd8785d,
0xd8c28c,
0x789d9d
];
for (let row = 0; row < 3; row++) {
const z = -17 - row * 6.1;
const base = 5.2 + row * 1.95;
box(
scene,
-1,
base - 2.2,
z - 0.7,
38,
4.2,
7.0,
row % 2 === 0 ? 0x927d62 : 0x88735d
);
for (let col = 0; col < 10; col++) {
const x = -18 + col * 3.8 + (row % 2) * 0.8;
const width = 2.25 + Math.random() * 0.75;
const height = 2.1 + Math.random() * 1.2;
const color =
hillColors[(col + row * 2) % hillColors.length];
backgroundHouse(
x,
z + Math.random() * 0.5,
base + Math.random() * 0.65,
width,
height,
color
);
}
}
// Distant minaret, rendered as stacked voxel forms.
box(scene, 10.8, 11.7, -22.5, 1.05, 8.5, 1.05, 0xc8c2ae);
box(scene, 10.8, 15.7, -22.5, 1.5, 0.35, 1.5, 0xd9d1b8);
box(scene, 10.8, 16.0, -22.5, 0.95, 0.25, 0.95, 0xc8c2ae);
box(scene, 10.8, 16.35, -22.5, 0.55, 0.5, 0.55, 0x6d7774);
box(scene, 10.8, 16.75, -22.5, 0.16, 0.6, 0.16, 0xd3bd85);
// Blocky clouds.
const cloud = new THREE.Group();
scene.add(cloud);
for (const [x, y, z, s] of [
[-11, 15.2, -31, 1.8],
[1, 17.0, -38, 2.2],
[14, 14.4, -34, 1.55]
]) {
box(cloud, x, y, z, 3.4 * s, 0.75 * s, 1.1 * s, 0xe6ece8);
box(cloud, x - 0.8 * s, y + 0.38 * s, z, 1.8 * s, 0.85 * s, 1.0 * s, 0xe6ece8);
box(cloud, x + 0.65 * s, y + 0.5 * s, z, 2.0 * s, 1.0 * s, 1.05 * s, 0xf2f3eb);
}
// ------------------------------------------------------------
// Street life and Balat details
// ------------------------------------------------------------
function voxelPerson(x, z, shirtColor, scale = 1) {
const group = new THREE.Group();
const base = groundY(x) + 0.1;
group.position.set(x, base, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, -0.14, 0.42, 0, 0.19, 0.8, 0.22, 0x334b56);
box(group, 0.14, 0.42, 0, 0.19, 0.8, 0.22, 0x334b56);
box(group, 0, 1.12, 0, 0.72, 0.78, 0.38, shirtColor);
box(group, -0.46, 1.13, 0, 0.18, 0.67, 0.22, 0xb98868);
box(group, 0.46, 1.13, 0, 0.18, 0.67, 0.22, 0xb98868);
box(group, 0, 1.72, 0, 0.48, 0.48, 0.45, 0xd6a17b);
box(group, 0, 1.93, 0, 0.52, 0.14, 0.48, 0x4b3a31);
box(group, -0.1, 1.74, 0.235, 0.07, 0.07, 0.025, 0x3a302d);
box(group, 0.1, 1.74, 0.235, 0.07, 0.07, 0.025, 0x3a302d);
return group;
}
voxelPerson(-0.25, 3.35, 0xd86e50, 0.95);
voxelPerson(4.35, 2.2, 0x397e83, 0.82);
// Street lamp.
const lampX = 5.45;
const lampZ = 1.62;
const lampBase = groundY(lampX) + 0.12;
box(scene, lampX, lampBase + 0.15, lampZ, 0.48, 0.3, 0.48, 0x4d514d);
box(scene, lampX, lampBase + 2.15, lampZ, 0.13, 4.0, 0.13, 0x3c4443);
box(scene, lampX, lampBase + 4.2, lampZ, 0.55, 0.13, 0.55, 0x3c4443);
box(scene, lampX, lampBase + 4.55, lampZ, 0.44, 0.58, 0.44, 0xf0d693);
const lampGlow = new THREE.PointLight(0xffc66f, 2.3, 7, 2);
lampGlow.position.set(lampX, lampBase + 4.45, lampZ);
scene.add(lampGlow);
// Planter and cubic foliage.
const planterX = -6.45;
const planterZ = 1.0;
const planterBase = groundY(planterX) + 0.14;
box(scene, planterX, planterBase + 0.28, planterZ, 1.15, 0.56, 0.72, 0xa65f43);
box(scene, planterX, planterBase + 0.61, planterZ, 0.95, 0.15, 0.58, 0x554638);
box(scene, planterX, planterBase + 1.05, planterZ, 0.48, 0.72, 0.45, 0x4f7957);
box(scene, planterX - 0.3, planterBase + 1.45, planterZ, 0.58, 0.55, 0.52, 0x638a5a);
box(scene, planterX + 0.28, planterBase + 1.3, planterZ + 0.08, 0.52, 0.62, 0.5, 0x789a61);
// Small street tree.
const treeX = -8.1;
const treeZ = 2.2;
const treeBase = groundY(treeX) + 0.08;
box(scene, treeX, treeBase + 1.35, treeZ, 0.42, 2.7, 0.42, 0x70503b);
box(scene, treeX, treeBase + 2.65, treeZ, 1.8, 1.35, 1.55, 0x5d8052);
box(scene, treeX - 0.55, treeBase + 3.25, treeZ + 0.1, 1.2, 1.0, 1.1, 0x78915b);
box(scene, treeX + 0.45, treeBase + 3.45, treeZ - 0.08, 1.35, 1.2, 1.25, 0x668653);
// Laundry line across the right side.
beamBetween([4.0, 7.1, 2.25], [8.8, 6.55, 2.55], 0.035, 0x3f4240);
box(scene, 4.0, 6.35, 2.25, 0.09, 1.55, 0.09, 0x5b5148);
box(scene, 8.8, 5.82, 2.55, 0.09, 1.5, 0.09, 0x5b5148);
const laundry = [
[4.65, 6.82, 0xefe2bc, 0.48, 0.72],
[5.45, 6.72, 0x4e8992, 0.55, 0.62],
[6.2, 6.63, 0xd96f4e, 0.43, 0.74],
[7.0, 6.55, 0xe8d39c, 0.55, 0.58],
[7.85, 6.45, 0x7b8eaa, 0.46, 0.68]
];
for (const [x, y, color, w, h] of laundry) {
box(scene, x, y - h / 2, 2.42, w, h, 0.045, color);
}
// A few overhead utility lines.
beamBetween([-13, 10.3, -1.5], [3.4, 9.6, -1.0], 0.027, 0x3f4545);
beamBetween([-13, 10.05, -1.4], [3.4, 9.35, -0.9], 0.027, 0x3f4545);
beamBetween([5.5, 10.4, -4], [14, 11.2, -8], 0.028, 0x3f4545);
// Crates and flower pots.
box(scene, -3.95, groundY(-3.95) + 0.32, 1.95, 0.62, 0.62, 0.62, 0x8c6546);
box(scene, -3.28, groundY(-3.28) + 0.28, 1.7, 0.54, 0.54, 0.54, 0xa9794e);
box(scene, 6.6, groundY(6.6) + 0.28, 1.45, 0.52, 0.52, 0.52, 0xa25d42);
// ------------------------------------------------------------
// Custom orbit, pan, pinch, wheel and keyboard camera controls
// ------------------------------------------------------------
const desired = {
theta: 0.48,
phi: 1.34,
radius: 23,
target: new THREE.Vector3(-0.65, 4.55, 0)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
const cameraSpherical = new THREE.Spherical();
const pointers = new Map();
let lastPinchDistance = 0;
let panning = false;
function resetCamera() {
desired.theta = 0.48;
desired.phi = 1.34;
desired.radius = 23;
desired.target.set(-0.65, 4.55, 0);
}
function updateCamera() {
current.theta = THREE.MathUtils.lerp(current.theta, desired.theta, 0.12);
current.phi = THREE.MathUtils.lerp(current.phi, desired.phi, 0.12);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, 0.12);
current.target.lerp(desired.target, 0.12);
cameraSpherical.set(
current.radius,
current.phi,
current.theta
);
camera.position.setFromSpherical(cameraSpherical).add(current.target);
camera.lookAt(current.target);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
panning = event.button === 2 || event.shiftKey;
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (lastPinchDistance / distance),
10,
39
);
}
lastPinchDistance = distance;
return;
}
if (panning) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const panScale = desired.radius * 0.00145;
desired.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -13, 13);
desired.target.y = THREE.MathUtils.clamp(desired.target.y, 1.5, 11);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -9, 9);
} else {
desired.theta -= dx * 0.0055;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.0045,
0.55,
1.48
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
panning = false;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.015,
10,
39
);
},
{ passive: false }
);
addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") desired.theta += step;
if (event.key === "ArrowRight") desired.theta -= step;
if (event.key === "ArrowUp") desired.phi = Math.max(0.55, desired.phi - step);
if (event.key === "ArrowDown") desired.phi = Math.min(1.48, desired.phi + step);
if (event.key === "+" || event.key === "=") {
desired.radius = Math.max(10, desired.radius - 1.2);
}
if (event.key === "-" || event.key === "_") {
desired.radius = Math.min(39, desired.radius + 1.2);
}
if (event.key.toLowerCase() === "r") resetCamera();
});
document.getElementById("reset").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", onResize);
updateCamera();
renderer.setAnimationLoop(() => {
updateCamera();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```