Prompt specification
Build or customize the Three.js 3D scene "Bo-Kaap stepped stoop and facade 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: Bo-Kaap stepped stoop and facade corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bo-kaap-stepped-stoop-and-facade-corner-x2901
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Bo-Kaap's hillside streets in Cape Town. Build a referenced Cape Town residential facade fragment with stoop, shutter, and rising street edge. Vary shape as well as color to preserve architectural character. Voxel style.
Working Three.js Starter (bo-kaap-stepped-stoop-and-facade-corner-x2901):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bo-Kaap — Voxel Streetscape</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fc6cf;
font-family: Georgia, "Times New Roman", serif;
}
body {
color: #fff9ec;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 26px;
z-index: 10;
max-width: min(430px, calc(100vw - 52px));
padding: 17px 20px 18px;
border-left: 4px solid #f2c14e;
background: linear-gradient(
110deg,
rgba(25, 37, 40, 0.88),
rgba(25, 37, 40, 0.58)
);
box-shadow: 0 12px 35px rgba(19, 31, 35, 0.18);
pointer-events: none;
backdrop-filter: blur(7px);
}
.eyebrow {
margin-bottom: 6px;
color: #f2c14e;
font: 700 10px/1.2 Arial, sans-serif;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 46px);
font-weight: 700;
line-height: 0.98;
letter-spacing: 0.025em;
}
.subtitle {
margin-top: 10px;
color: rgba(255, 249, 236, 0.82);
font: 13px/1.45 Arial, sans-serif;
letter-spacing: 0.035em;
}
.controls {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 10;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 3px;
background: rgba(25, 37, 40, 0.72);
color: rgba(255, 255, 255, 0.86);
font: 11px/1 Arial, sans-serif;
letter-spacing: 0.04em;
backdrop-filter: blur(6px);
}
button {
border: 1px solid rgba(242, 193, 78, 0.7);
border-radius: 2px;
padding: 7px 9px;
background: rgba(242, 193, 78, 0.1);
color: #f8d77c;
font: 700 10px/1 Arial, sans-serif;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: rgba(242, 193, 78, 0.22);
}
.credit {
position: fixed;
left: 26px;
bottom: 22px;
z-index: 10;
color: rgba(255, 255, 255, 0.72);
font: 10px/1.4 Arial, sans-serif;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
@media (max-width: 700px) {
.title-card {
top: 15px;
left: 15px;
padding: 14px 15px;
}
.subtitle {
max-width: 290px;
}
.credit {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<section class="title-card" aria-label="Scene title">
<div class="eyebrow">Cape Town · South Africa</div>
<h1>BO-KAAP</h1>
<div class="subtitle">
A voxel hillside streetscape with narrow plastered facades,
raised stoops, painted shutters, and Cape Dutch rooflines.
</div>
</section>
<div class="controls">
<span>DRAG TO ORBIT · SCROLL TO ZOOM</span>
<button id="reset" type="button">Reset</button>
</div>
<div class="credit">Architectural study · 33°55′S 18°25′E</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 lighting
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9fc6cf);
scene.fog = new THREE.Fog(0x9fc6cf, 34, 82);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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 hemiLight = new THREE.HemisphereLight(0xd9f1f4, 0x6b5347, 1.9);
scene.add(hemiLight);
const sunLight = new THREE.DirectionalLight(0xffe6b6, 3.2);
sunLight.position.set(-15, 25, 17);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -28;
sunLight.shadow.camera.right = 28;
sunLight.shadow.camera.top = 26;
sunLight.shadow.camera.bottom = -20;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 75;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.025;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0x8fb8d0, 0.65);
fillLight.position.set(18, 12, -15);
scene.add(fillLight);
// ------------------------------------------------------------
// Shared voxel primitives
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
castsShadow = true
) {
const material =
typeof color === "object" ? color : getMaterial(color);
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = castsShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
// The road rises by roughly 22 percent from left to right.
const slope = 0.22;
const slopeAngle = Math.atan(slope);
const groundHeight = (x) => 0.22 * (x + 18);
// Deterministic randomness for paving and small details.
let seed = 81723;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function pick(values) {
return values[Math.floor(random() * values.length)];
}
// ------------------------------------------------------------
// Voxel Table Mountain and sky details
// ------------------------------------------------------------
const distantRock = new THREE.MeshStandardMaterial({
color: 0x54747a,
roughness: 1
});
const distantRockLight = new THREE.MeshStandardMaterial({
color: 0x66868a,
roughness: 1
});
box(scene, 20, 7.5, 6, -9, 3.2, -29, distantRock, false);
box(scene, 26, 6, 6, 3, 4.1, -30, distantRockLight, false);
box(scene, 29, 4.2, 6, -2, 8.0, -30, distantRock, false);
box(scene, 19, 3.1, 6, -3, 11.5, -30, distantRockLight, false);
box(scene, 8, 4.0, 6, 13, 7.4, -30, distantRock, false);
const sunMaterial = new THREE.MeshStandardMaterial({
color: 0xffdc83,
emissive: 0xffbd58,
emissiveIntensity: 1.3,
roughness: 1
});
box(scene, 3.8, 3.8, 1.1, -19, 20.5, -34, sunMaterial, false);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xdde9e7,
roughness: 1
});
function cloud(x, y, z, scale) {
box(scene, 4.2 * scale, 0.8 * scale, 1.3, x, y, z, cloudMaterial, false);
box(scene, 2.5 * scale, 1.3 * scale, 1.4, x - 0.8 * scale, y + 0.2 * scale, z, cloudMaterial, false);
box(scene, 2.2 * scale, 0.9 * scale, 1.4, x + 1.5 * scale, y + 0.1 * scale, z, cloudMaterial, false);
}
cloud(-12, 17, -22, 1.15);
cloud(14, 15.5, -25, 0.85);
cloud(4, 21, -36, 0.75);
// ------------------------------------------------------------
// Sloping ground, road, stepped sidewalk, and curb
// ------------------------------------------------------------
box(
scene,
48,
0.8,
60,
0,
-2.8,
-8,
0x75695c,
false
);
const hillside = box(
scene,
40.5,
4.4,
10.5,
0,
groundHeight(0) - 2.35,
-7.1,
0x77685d,
false
);
hillside.rotation.z = slopeAngle;
const roadBase = box(
scene,
39.7,
0.38,
8.2,
0,
groundHeight(0) - 0.21,
1.75,
0x3f494c,
false
);
roadBase.rotation.z = slopeAngle;
// Individual pavers preserve the block-like visual language.
const paverGeometry = new THREE.BoxGeometry(1, 1, 1);
const paverMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98
});
const paverColumns = 31;
const paverRows = 8;
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
paverColumns * paverRows
);
pavers.receiveShadow = true;
pavers.castShadow = false;
const dummy = new THREE.Object3D();
const paverColor = new THREE.Color();
let paverIndex = 0;
for (let column = 0; column < paverColumns; column++) {
const x = -18.3 + column * 1.21;
for (let row = 0; row < paverRows; row++) {
const z = -1.77 + row * 0.96;
const height = groundHeight(x);
dummy.position.set(x, height + 0.045, z);
dummy.rotation.set(0, 0, slopeAngle);
dummy.scale.set(1.14, 0.075, 0.88);
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
const tone = 0.86 + random() * 0.2;
paverColor.setHSL(
0.53 + (random() - 0.5) * 0.025,
0.09 + random() * 0.04,
0.27 * tone
);
pavers.setColorAt(paverIndex, paverColor);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
pavers.instanceColor.needsUpdate = true;
scene.add(pavers);
// Horizontally stepped paving makes the rising street edge explicit.
for (let x = -19; x < 19.2; x += 1.15) {
const y = groundHeight(x);
box(
scene,
1.11,
0.38,
1.72,
x + 0.575,
y + 0.02,
-3.27,
pick([0xc7bda9, 0xbeb4a3, 0xd0c4ae, 0xb9b1a4]),
false
);
box(
scene,
1.10,
0.34,
0.20,
x + 0.575,
y + 0.11,
-2.34,
0xe0d4bc,
false
);
}
// ------------------------------------------------------------
// Architectural details
// ------------------------------------------------------------
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x263f49,
roughness: 0.22,
metalness: 0.28
});
const reflectionMaterial = new THREE.MeshStandardMaterial({
color: 0x9cc4cf,
roughness: 0.3,
metalness: 0.1
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xd6aa52,
roughness: 0.35,
metalness: 0.65
});
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0xffd77a,
emissive: 0xffb84d,
emissiveIntensity: 0.85,
roughness: 0.45
});
function createWindow(group, x, y, z, definition, width = 1.05, height = 1.34) {
// Recess-like frame and dark glazing.
box(group, width + 0.24, height + 0.24, 0.14, x, y, z, definition.trim);
box(group, width, height, 0.08, x, y, z + 0.09, glassMaterial);
box(group, 0.065, height, 0.055, x, y, z + 0.15, definition.trim);
box(group, width, 0.065, 0.055, x, y + 0.05, z + 0.15, definition.trim);
// A single offset reflection gives the glass a graphic quality.
box(
group,
0.13,
height * 0.66,
0.025,
x - width * 0.27,
y + height * 0.10,
z + 0.18,
reflectionMaterial,
false
);
// Painted timber shutters, open against the plaster.
const shutterX = width / 2 + 0.24;
for (const side of [-1, 1]) {
const panelX = x + side * shutterX;
box(
group,
0.34,
height + 0.02,
0.11,
panelX,
y,
z + 0.12,
definition.shutter
);
// Horizontal louver slats.
for (let slat = 0; slat < 5; slat++) {
box(
group,
0.27,
0.045,
0.035,
panelX,
y - height * 0.38 + slat * height * 0.19,
z + 0.19,
definition.shutter,
false
);
}
}
// Projecting sill and small lintel.
box(group, width + 0.42, 0.11, 0.28, x, y - height / 2 - 0.11, z + 0.08, definition.trim);
box(group, width + 0.38, 0.12, 0.19, x, y + height / 2 + 0.11, z + 0.07, definition.trim);
}
function createPlant(group, x, y, z, scale = 1) {
box(
group,
0.50 * scale,
0.43 * scale,
0.48 * scale,
x,
y + 0.215 * scale,
z,
0xb85f42
);
box(
group,
0.48 * scale,
0.34 * scale,
0.43 * scale,
x - 0.13 * scale,
y + 0.57 * scale,
z,
0x527d49
);
box(
group,
0.37 * scale,
0.31 * scale,
0.39 * scale,
x + 0.17 * scale,
y + 0.52 * scale,
z + 0.03,
0x688f51
);
box(
group,
0.25 * scale,
0.25 * scale,
0.28 * scale,
x,
y + 0.78 * scale,
z - 0.02,
0x789c58
);
}
function createFacade(definition) {
const group = new THREE.Group();
group.position.set(definition.x, groundHeight(definition.x), -7.1);
scene.add(group);
const {
width,
height,
color,
trim,
door,
shutter,
shape
} = definition;
const depth = 6.2;
const front = depth / 2;
// Main plastered mass.
box(group, width, height, depth, 0, height / 2, 0, color);
box(group, width + 0.08, 0.32, depth + 0.08, 0, 0.16, 0, trim);
// Horizontal string course.
box(group, width + 0.07, 0.11, 0.13, 0, 3.18, front + 0.08, trim);
// Quoins or corner pilasters vary the facade silhouette.
if (definition.pilasters) {
for (const side of [-1, 1]) {
box(
group,
0.17,
height - 0.25,
0.16,
side * (width / 2 - 0.16),
height / 2,
front + 0.09,
trim
);
}
} else {
for (const side of [-1, 1]) {
for (let course = 0; course < 5; course++) {
box(
group,
0.22,
0.16,
0.13,
side * (width / 2 - 0.15),
0.65 + course * 0.88,
front + 0.08,
trim,
false
);
}
}
}
// Different Cape-inspired roof profiles.
box(group, width + 0.18, 0.20, depth + 0.15, 0, height + 0.10, 0, trim);
if (shape === "gable") {
const levels = [
[1.00, 0.39],
[0.82, 0.39],
[0.64, 0.39],
[0.46, 0.39]
];
levels.forEach(([levelWidth, levelHeight], index) => {
box(
group,
width * levelWidth,
levelHeight,
0.25,
0,
height + 0.30 + index * 0.38,
front + 0.04,
index % 2 === 0 ? trim : color
);
});
box(group, width * 0.50, 0.15, 0.32, 0, height + 1.90, front + 0.05, trim);
} else if (shape === "stepped") {
box(group, width + 0.08, 0.48, 0.20, 0, height + 0.39, front + 0.04, trim);
box(group, width * 0.78, 0.30, 0.20, 0, height + 0.76, front + 0.04, color);
box(group, width * 0.48, 0.23, 0.20, 0, height + 1.00, front + 0.04, trim);
} else {
// Flat roof with a front parapet and visible side walls.
box(group, width + 0.10, 0.62, 0.19, 0, height + 0.42, front + 0.02, trim);
box(group, 0.19, 0.62, depth + 0.10, -width / 2, height + 0.42, 0, trim);
box(group, 0.19, 0.62, depth + 0.10, width / 2, height + 0.42, 0, trim);
}
// Chimneys and rooftop pots.
if (definition.chimney) {
box(group, 0.48, 1.20, 0.48, width * 0.24, height + 0.85, -0.9, 0x9f5948);
box(group, 0.58, 0.15, 0.58, width * 0.24, height + 1.48, -0.9, trim);
}
createPlant(group, -width * 0.28, height + 0.20, front - 0.42, 0.78);
// Raised front door and stoop.
const doorX = -width * 0.23;
const doorBottom = 0.95;
const doorHeight = 2.10;
// Three chunky steps descend toward the pavement.
for (let step = 0; step < 3; step++) {
const stepHeight = 0.95 - step * 0.30;
const stepZ = front + 0.23 + step * 0.43;
box(
group,
1.48,
stepHeight,
0.47,
doorX,
stepHeight / 2,
stepZ,
step === 0 ? trim : definition.stoop
);
}
if (definition.cheekWalls) {
for (const side of [-1, 1]) {
box(
group,
0.13,
0.91,
1.28,
doorX + side * 0.79,
0.455,
front + 0.65,
trim
);
}
}
// Door surround, timber leaf, fanlight and panels.
box(
group,
1.34,
2.38,
0.15,
doorX,
doorBottom + doorHeight / 2,
front + 0.11,
trim
);
box(
group,
1.05,
doorHeight,
0.12,
doorX,
doorBottom + doorHeight / 2,
front + 0.22,
door
);
box(
group,
0.76,
0.36,
0.035,
doorX,
doorBottom + 1.80,
front + 0.295,
glassMaterial,
false
);
box(
group,
0.76,
0.82,
0.04,
doorX,
doorBottom + 0.55,
front + 0.295,
door,
false
);
box(
group,
0.68,
0.66,
0.025,
doorX,
doorBottom + 0.55,
front + 0.32,
definition.shutter,
false
);
box(
group,
0.09,
0.09,
0.10,
doorX + 0.33,
doorBottom + 0.94,
front + 0.32,
brassMaterial,
false
);
// Small house number plaque.
box(
group,
0.19,
0.25,
0.035,
doorX + 0.50,
doorBottom + 1.38,
front + 0.29,
brassMaterial,
false
);
if (definition.canopy) {
box(group, 1.70, 0.12, 0.73, doorX, doorBottom + 2.46, front + 0.38, door);
for (const side of [-1, 1]) {
box(
group,
0.07,
0.55,
0.07,
doorX + side * 0.67,
doorBottom + 2.18,
front + 0.59,
brassMaterial
);
}
}
// Upper-floor shuttered windows.
const upperY = height - 1.52;
if (width >= 4.65) {
createWindow(group, -width * 0.21, upperY, front + 0.12, definition, 0.93, 1.26);
createWindow(group, width * 0.22, upperY, front + 0.12, definition, 1.05, 1.34);
} else {
createWindow(group, width * 0.18, upperY, front + 0.12, definition, 1.05, 1.34);
}
// Some facades include an additional ground-floor window.
if (definition.extraWindow) {
createWindow(
group,
width * 0.30,
1.95,
front + 0.12,
definition,
0.82,
1.08
);
}
// Downpipe attached to the facade.
box(
group,
0.075,
height - 0.5,
0.075,
width / 2 - 0.10,
height / 2,
front + 0.20,
0x565d59
);
// Planter beside the entrance.
createPlant(group, doorX + 1.10, 0, front + 0.72, 0.86);
}
const facades = [
{
x: -15.4,
width: 4.3,
height: 5.8,
color: 0xe46f55,
trim: 0xf7e7c8,
stoop: 0xe9d5b5,
door: 0x244b59,
shutter: 0x244b59,
shape: "flat",
pilasters: true,
chimney: true,
extraWindow: true
},
{
x: -10.7,
width: 4.2,
height: 6.6,
color: 0xf1bd45,
trim: 0xfff1cf,
stoop: 0xe8d8ba,
door: 0x7f3f4b,
shutter: 0x315d5a,
shape: "gable",
chimney: false,
extraWindow: false
},
{
x: -6.0,
width: 4.5,
height: 5.7,
color: 0x438f86,
trim: 0xf3e8ce,
stoop: 0xd9c7a7,
door: 0xe6b84e,
shutter: 0x193f54,
shape: "stepped",
pilasters: false,
chimney: true,
extraWindow: true
},
{
x: -1.4,
width: 4.2,
height: 6.8,
color: 0xe8d6a4,
trim: 0xfff6df,
stoop: 0xdfcba7,
door: 0x3f6d82,
shutter: 0x7a3f4b,
shape: "gable",
chimney: true,
extraWindow: false
},
{
x: 3.2,
width: 4.6,
height: 6.1,
color: 0xd75c70,
trim: 0xf7dfc4,
stoop: 0xe5c8ad,
door: 0x2e5d55,
shutter: 0x30465e,
shape: "flat",
cheekWalls: true,
canopy: true,
extraWindow: true
},
{
x: 8.2,
width: 4.2,
height: 6.9,
color: 0x5f7eae,
trim: 0xf3e8ce,
stoop: 0xdac8aa,
door: 0x963f4d,
shutter: 0x244b59,
shape: "stepped",
pilasters: true,
chimney: true,
extraWindow: false
},
{
x: 12.7,
width: 4.5,
height: 5.9,
color: 0xee9953,
trim: 0xffe8c5,
stoop: 0xe7d0ad,
door: 0x326c6b,
shutter: 0x7c3e4a,
shape: "gable",
chimney: false,
extraWindow: true
},
{
x: 17.3,
width: 4.3,
height: 6.5,
color: 0x7fa17c,
trim: 0xf4e7c9,
stoop: 0xdcc7a5,
door: 0x6f3f56,
shutter: 0x294d61,
shape: "flat",
cheekWalls: true,
canopy: true,
extraWindow: false
}
];
facades.forEach(createFacade);
// ------------------------------------------------------------
// Street lamps
// ------------------------------------------------------------
function createLamp(x) {
const group = new THREE.Group();
group.position.set(x, groundHeight(x), -2.03);
scene.add(group);
box(group, 0.31, 0.15, 0.31, 0, 0.075, 0, 0x3e4545);
box(group, 0.11, 3.45, 0.11, 0, 1.80, 0, 0x343b3c);
box(group, 0.52, 0.10, 0.10, 0.18, 3.53, 0, 0x343b3c);
box(group, 0.36, 0.45, 0.36, 0.39, 3.34, 0, lampMaterial);
box(group, 0.47, 0.10, 0.47, 0.39, 3.59, 0, 0x343b3c);
box(group, 0.25, 0.09, 0.25, 0.39, 3.68, 0, 0x343b3c);
}
[-13.7, -5.0, 5.8, 15.0].forEach(createLamp);
// ------------------------------------------------------------
// Voxel trees at the outer edge of the street
// ------------------------------------------------------------
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, groundHeight(x), z);
scene.add(group);
box(group, 0.36 * scale, 2.9 * scale, 0.36 * scale, 0, 1.45 * scale, 0, 0x72513b);
box(group, 1.9 * scale, 1.55 * scale, 1.7 * scale, 0, 3.30 * scale, 0, 0x4f7547);
box(group, 1.35 * scale, 1.25 * scale, 1.45 * scale, -0.80 * scale, 2.90 * scale, 0.08, 0x66864c);
box(group, 1.25 * scale, 1.20 * scale, 1.35 * scale, 0.82 * scale, 3.05 * scale, -0.10, 0x769552);
box(group, 0.90 * scale, 0.90 * scale, 0.95 * scale, 0.05 * scale, 4.15 * scale, 0, 0x8da35d);
}
createTree(-13.5, 5.8, 0.95);
createTree(9.7, 5.8, 0.85);
createTree(17.8, 5.9, 1.0);
// ------------------------------------------------------------
// Voxel pedestrians
// ------------------------------------------------------------
function createPerson(x, z, shirtColor, skinColor = 0x9b684c) {
const group = new THREE.Group();
group.position.set(x, groundHeight(x) + 0.24, z);
scene.add(group);
box(group, 0.18, 0.65, 0.20, -0.12, 0.33, 0, 0x34404b);
box(group, 0.18, 0.65, 0.20, 0.12, 0.33, 0, 0x34404b);
box(group, 0.54, 0.68, 0.32, 0, 0.96, 0, shirtColor);
box(group, 0.32, 0.32, 0.32, 0, 1.48, 0, skinColor);
box(group, 0.36, 0.13, 0.35, 0, 1.67, 0, 0x40342d);
box(group, 0.14, 0.58, 0.16, -0.34, 0.93, 0, shirtColor);
box(group, 0.14, 0.58, 0.16, 0.34, 0.93, 0, shirtColor);
}
createPerson(-8.3, -3.35, 0xe0a64b);
createPerson(-7.7, -3.20, 0x486c7f);
createPerson(6.8, -3.28, 0x8c4d66);
createPerson(7.35, -3.25, 0xd7d0b5);
// ------------------------------------------------------------
// Voxel cars for scale and street character
// ------------------------------------------------------------
function createCar(x, z, color) {
const group = new THREE.Group();
group.position.set(x, groundHeight(x) + 0.10, z);
group.rotation.z = slopeAngle;
scene.add(group);
box(group, 3.65, 0.63, 1.58, 0, 0.58, 0, color);
box(group, 2.12, 0.68, 1.42, -0.10, 1.17, 0, color);
box(group, 1.88, 0.46, 1.46, -0.10, 1.23, 0, glassMaterial);
box(group, 0.10, 0.49, 1.50, -0.10, 1.24, 0, color);
for (const wheelX of [-1.12, 1.12]) {
for (const wheelZ of [-0.81, 0.81]) {
box(group, 0.50, 0.50, 0.22, wheelX, 0.31, wheelZ, 0x252d30);
}
}
box(group, 0.18, 0.14, 0.38, 1.80, 0.68, -0.48, 0xffe0a0);
box(group, 0.18, 0.14, 0.38, 1.80, 0.68, 0.48, 0xffe0a0);
}
createCar(-3.0, 2.35, 0xc88d3f);
createCar(11.5, 3.15, 0x526f7c);
// ------------------------------------------------------------
// Direct camera controls — no external examples or addons
// ------------------------------------------------------------
const target = new THREE.Vector3(0.5, 4.5, -0.8);
let yaw = 0.52;
let pitch = 0.48;
let radius = 33;
let dragging = false;
let previousX = 0;
let previousY = 0;
const initialView = {
yaw: 0.52,
pitch: 0.48,
radius: 33
};
function updateCamera() {
const horizontalRadius = radius * Math.cos(pitch);
camera.position.set(
target.x + Math.sin(yaw) * horizontalRadius,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontalRadius
);
camera.lookAt(target);
}
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 deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
yaw -= deltaX * 0.005;
pitch = clamp(pitch + deltaY * 0.004, 0.16, 1.12);
previousX = event.clientX;
previousY = event.clientY;
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(
"wheel",
(event) => {
event.preventDefault();
radius = clamp(radius * Math.exp(event.deltaY * 0.001), 16, 52);
updateCamera();
},
{ passive: false }
);
addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") yaw += 0.08;
if (event.key === "ArrowRight") yaw -= 0.08;
if (event.key === "ArrowUp") pitch = clamp(pitch + 0.06, 0.16, 1.12);
if (event.key === "ArrowDown") pitch = clamp(pitch - 0.06, 0.16, 1.12);
if (event.key === "+" || event.key === "=") radius = clamp(radius - 1, 16, 52);
if (event.key === "-") radius = clamp(radius + 1, 16, 52);
updateCamera();
});
document.getElementById("reset").addEventListener("click", () => {
yaw = initialView.yaw;
pitch = initialView.pitch;
radius = initialView.radius;
updateCamera();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
renderer.setAnimationLoop(() => renderer.render(scene, camera));
</script>
</body>
</html>
```