Prompt specification
Build or customize the Three.js 3D scene "Neighbors talking beside a Bo-Kaap stoop" 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: Neighbors talking beside a Bo-Kaap stoop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighbors-talking-beside-a-bo-kaap-stoop-x2902
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Bo-Kaap's hillside streets in Cape Town. Create a compact neighborhood vignette with residents, doorstep seating, and a passing pedestrian. Keep the scene respectful and ground details in local references rather than tourism stereotypes. Voxel style.
Working Three.js Starter (neighbors-talking-beside-a-bo-kaap-stoop-x2902):
```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 — An Afternoon on the Hill</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8dfe3;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 22px;
left: 24px;
z-index: 2;
max-width: min(360px, calc(100vw - 48px));
padding: 15px 17px 14px;
color: #173c3b;
background: rgba(248, 244, 231, 0.88);
border: 1px solid rgba(23, 60, 59, 0.18);
border-radius: 4px;
box-shadow: 0 8px 24px rgba(37, 48, 45, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
color: #6f5040;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 31px);
line-height: 1.08;
font-weight: 760;
letter-spacing: -0.035em;
}
.subtitle {
margin: 7px 0 0;
font-size: 12px;
line-height: 1.45;
color: rgba(23, 60, 59, 0.75);
}
#reset {
position: fixed;
top: 22px;
right: 24px;
z-index: 3;
padding: 9px 12px;
border: 1px solid rgba(23, 60, 59, 0.22);
border-radius: 4px;
color: #173c3b;
background: rgba(248, 244, 231, 0.86);
font: 650 11px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.04em;
cursor: pointer;
backdrop-filter: blur(8px);
}
#reset:hover {
background: rgba(255, 251, 239, 0.97);
}
.controls {
position: fixed;
right: 24px;
bottom: 20px;
z-index: 2;
padding: 8px 10px;
border-radius: 4px;
color: rgba(248, 244, 231, 0.9);
background: rgba(23, 60, 59, 0.66);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 600px) {
.title-card {
top: 12px;
left: 12px;
padding: 12px 14px;
}
#reset {
top: 12px;
right: 12px;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel scene of a Bo-Kaap hillside street"></main>
<header class="title-card">
<p class="eyebrow">Cape Town · Late afternoon</p>
<h1>Bo-Kaap, at street level</h1>
<p class="subtitle">
A lived-in hillside lane of stoeps, residents, and everyday movement.
</p>
</header>
<button id="reset" type="button">RESET VIEW</button>
<div class="controls">
DRAG TO ORBIT · SCROLL TO ZOOM · ARROW KEYS TO PAN
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8dfe3);
scene.fog = new THREE.Fog(0xc8dfe3, 30, 86);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
160
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Voxel-style Bo-Kaap street scene. Drag to orbit and scroll to zoom."
);
host.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xd9eff2, 0x6a5648, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffd4a0, 3.4);
sun.position.set(13, 19, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 75;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dbe3, 0.75);
fill.position.set(-10, 8, -15);
scene.add(fill);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
const materials = {
road: standard(0x554f49),
cobble: standard(0xffffff, { roughness: 1 }),
curb: standard(0xa99e8e),
pavement: standard(0xb8ae9d),
earth: standard(0x766858),
stone: standard(0x8a8174),
darkStone: standard(0x56504b),
trim: standard(0xf1e7d3),
roof: standard(0x6b6259),
glass: standard(0x263d43, { roughness: 0.28, metalness: 0.12 }),
shutter: standard(0x294d45),
door: standard(0x764638),
wood: standard(0x665044),
metal: standard(0x303838, { roughness: 0.5, metalness: 0.45 }),
plant: standard(0x426d47),
plantLight: standard(0x6c8c55),
pot: standard(0xa45e43),
cream: standard(0xe6dfcb),
lamp: standard(0xffd08a, {
emissive: 0xff9b45,
emissiveIntensity: 0.7,
roughness: 0.55
}),
cable: standard(0x303638),
mountain: standard(0x71898a),
mountainDark: standard(0x647d7f),
skinA: standard(0x9a6749),
skinB: standard(0xb9825e),
skinC: standard(0x744b38),
hair: standard(0x282522),
shirtBlue: standard(0x4e7184),
shirtSand: standard(0xb69b73),
trousers: standard(0x3f4545),
shoes: standard(0x2b2927),
bag: standard(0xa16b4d)
};
function box(parent, size, position, material, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.cast ?? true;
mesh.receiveShadow = options.receive ?? true;
parent.add(mesh);
return mesh;
}
function terraceTop(z) {
const index = THREE.MathUtils.clamp(
Math.floor((12 - z) / 2),
0,
13
);
return index * 0.22;
}
function smoothRoadHeight(z) {
return THREE.MathUtils.clamp((10 - z) / 2, 0, 13) * 0.22;
}
// Broad ground beneath the stepped lane.
box(
scene,
[70, 1.1, 95],
[0, -0.85, -20],
materials.earth,
{ cast: false }
);
// The road is assembled from short voxel terraces.
const roadSegmentCount = 14;
for (let i = 0; i < roadSegmentCount; i++) {
const z = 11 - i * 2;
const top = i * 0.22;
box(
scene,
[8.15, 0.28, 2.02],
[0, top - 0.14, z],
materials.road,
{ cast: false }
);
box(
scene,
[0.28, 0.30, 2.02],
[4.16, top + 0.02, z],
materials.curb
);
box(
scene,
[0.68, 0.22, 1.98],
[4.57, top + 0.02, z],
materials.pavement
);
box(
scene,
[0.16, 0.08, 1.88],
[3.82, top + 0.025, z],
materials.darkStone,
{ cast: false }
);
// A stepped earth bank on the open side of the street.
const bankHeight = Math.max(0.55, top + 0.55);
box(
scene,
[4.3, bankHeight, 2.02],
[6.43, top - 0.11, z],
materials.earth,
{ cast: false }
);
box(
scene,
[4.25, 0.12, 1.94],
[6.43, top - 0.06, z],
materials.stone,
{ cast: false }
);
}
// Instanced, slightly varied cobblestones.
const columns = 16;
const rows = 4;
const cobbleCount = roadSegmentCount * columns * rows;
const cobbleGeometry = new THREE.BoxGeometry(0.46, 0.11, 0.44);
const cobbleMaterial = standard(0xffffff, { roughness: 1 });
const cobbles = new THREE.InstancedMesh(
cobbleGeometry,
cobbleMaterial,
cobbleCount
);
cobbles.receiveShadow = true;
cobbles.castShadow = false;
scene.add(cobbles);
const dummy = new THREE.Object3D();
const instanceColor = new THREE.Color();
let cobbleIndex = 0;
for (let segment = 0; segment < roadSegmentCount; segment++) {
const centerZ = 11 - segment * 2;
const top = segment * 0.22;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = -3.65 + column * 0.49;
const z = centerZ - 0.75 + row * 0.5;
dummy.position.set(x, top + 0.025, z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
cobbles.setMatrixAt(cobbleIndex, dummy.matrix);
const tone = 0.38 + Math.random() * 0.15;
instanceColor.setHSL(
0.08 + Math.random() * 0.025,
0.05 + Math.random() * 0.06,
tone
);
cobbles.setColorAt(cobbleIndex, instanceColor);
cobbleIndex++;
}
}
}
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) {
cobbles.instanceColor.needsUpdate = true;
}
// Local architectural details.
function addWindow(group, z, y, width = 1.05, height = 1.22) {
const front = 2.87;
box(
group,
[0.13, height + 0.18, width + 0.18],
[front, y, z],
materials.trim
);
box(
group,
[0.08, height, width],
[front + 0.09, y, z],
materials.glass
);
box(
group,
[0.11, height, 0.055],
[front + 0.14, y, z],
materials.trim
);
box(
group,
[0.11, 0.055, width],
[front + 0.14, y, z],
materials.trim
);
box(
group,
[0.11, height + 0.08, 0.34],
[front + 0.08, y, z - width / 2 - 0.23],
materials.shutter
);
box(
group,
[0.11, height + 0.08, 0.34],
[front + 0.08, y, z + width / 2 + 0.23],
materials.shutter
);
}
function addDoor(group, doorZ, color) {
const front = 2.87;
const doorMaterial = standard(color);
box(
group,
[0.13, 2.55, 1.26],
[front, 1.275, doorZ],
materials.trim
);
box(
group,
[0.16, 2.34, 1.03],
[front + 0.10, 1.17, doorZ],
doorMaterial
);
box(
group,
[0.18, 0.66, 0.76],
[front + 0.20, 1.78, doorZ],
materials.glass
);
box(
group,
[0.18, 0.72, 0.76],
[front + 0.20, 0.68, doorZ],
materials.shutter
);
box(
group,
[0.16, 0.08, 0.08],
[front + 0.32, 1.03, doorZ + 0.35],
materials.metal
);
}
function addWallLamp(group, z) {
box(
group,
[0.42, 0.08, 0.08],
[3.06, 2.79, z],
materials.metal
);
box(
group,
[0.20, 0.30, 0.20],
[3.23, 2.69, z],
materials.lamp
);
}
function makeStreetSign() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = "#234d47";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#f1e7d3";
context.lineWidth = 7;
context.strokeRect(10, 10, canvas.width - 20, canvas.height - 20);
context.fillStyle = "#f5eedf";
context.font = "700 61px sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("WALE ST.", 256, 83);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return new THREE.Mesh(
new THREE.PlaneGeometry(2.15, 0.67),
new THREE.MeshBasicMaterial({ map: texture })
);
}
const houseSpecs = [
{
z: 7.6,
height: 4.7,
color: 0xd78b68,
door: 0x754838,
doorZ: -0.55,
trim: 0xf2e8d6
},
{
z: 2.5,
height: 5.0,
color: 0x759d91,
door: 0x315b58,
doorZ: 0.45,
trim: 0xf0e7d4
},
{
z: -2.6,
height: 4.6,
color: 0xc75f54,
door: 0x704c43,
doorZ: -0.35,
trim: 0xf5e9d6
},
{
z: -7.7,
height: 5.2,
color: 0x7196a2,
door: 0x5b4538,
doorZ: 0.55,
trim: 0xf0e6d1
},
{
z: -12.8,
height: 4.8,
color: 0xd8ad59,
door: 0x375f53,
doorZ: -0.4,
trim: 0xf4ead5
}
];
const houses = [];
houseSpecs.forEach((spec, index) => {
const group = new THREE.Group();
const baseY = terraceTop(spec.z);
group.position.set(-6.45, baseY, spec.z);
scene.add(group);
houses.push(group);
const facade = standard(spec.color);
const trim = standard(spec.trim);
box(
group,
[5.64, 0.66, 4.82],
[0, -0.19, 0],
materials.stone
);
box(
group,
[5.6, spec.height, 4.75],
[0, spec.height / 2, 0],
facade
);
box(
group,
[5.84, 0.18, 4.96],
[0, spec.height + 0.08, 0],
materials.roof
);
box(
group,
[0.18, 0.55, 4.96],
[2.75, spec.height + 0.36, 0],
trim
);
box(
group,
[0.18, 0.55, 4.96],
[-2.75, spec.height + 0.36, 0],
trim
);
box(
group,
[5.65, 0.55, 0.18],
[0, spec.height + 0.36, -2.34],
trim
);
box(
group,
[5.65, 0.55, 0.18],
[0, spec.height + 0.36, 2.34],
trim
);
addDoor(group, spec.doorZ, spec.door);
addWindow(group, -1.52, spec.height - 1.4, 1.02, 1.18);
addWindow(group, 1.52, spec.height - 1.4, 1.02, 1.18);
const lowerWindowZ = spec.doorZ > 0 ? -1.53 : 1.53;
addWindow(group, lowerWindowZ, 1.48, 0.72, 0.9);
// Downpipe attached to the front corner.
box(
group,
[0.12, spec.height - 0.15, 0.12],
[2.91, (spec.height - 0.15) / 2, 2.19],
materials.metal
);
addWallLamp(group, spec.doorZ + 1.02);
// Stoep and a lower step.
box(
group,
[1.35, 0.22, 2.25],
[3.34, 0.11, spec.doorZ],
materials.pavement
);
box(
group,
[0.66, 0.12, 1.48],
[4.12, 0.06, spec.doorZ],
materials.curb
);
// Rooftop water tank and supports.
if (index === 1 || index === 3) {
box(
group,
[1.28, 0.92, 1.28],
[-0.8, spec.height + 0.70, 0.4],
materials.metal
);
for (const dx of [-0.45, 0.45]) {
for (const dz of [-0.45, 0.45]) {
box(
group,
[0.10, 0.34, 0.10],
[-0.8 + dx, spec.height + 0.31, 0.4 + dz],
materials.metal
);
}
}
}
// Small roof parapet details.
if (index === 2) {
box(
group,
[1.4, 0.12, 2.2],
[3.22, 3.13, 0],
materials.pavement
);
for (let p = 0; p < 5; p++) {
box(
group,
[0.07, 0.64, 0.07],
[3.78, 3.48, -0.9 + p * 0.45],
materials.metal
);
}
box(
group,
[0.08, 0.08, 2.05],
[3.78, 3.77, 0],
materials.metal
);
}
if (index === 0) {
const sign = makeStreetSign();
sign.rotation.y = Math.PI / 2;
sign.position.set(3.02, spec.height - 0.38, 1.45);
group.add(sign);
}
});
// A short, steep side stair is a common feature on these lanes.
const sideStairZ = -6.3;
const sideStartY = terraceTop(sideStairZ) + 0.15;
for (let i = 0; i < 12; i++) {
const x = 4.18 + i * 0.48;
const top = sideStartY + i * 0.2;
const height = top + 0.5;
box(
scene,
[0.52, height, 2.12],
[x, top - height / 2, sideStairZ],
materials.stone
);
box(
scene,
[0.54, 0.12, 2.14],
[x, top - 0.04, sideStairZ],
materials.pavement
);
}
// Utility poles and straight overhead wires.
const polePositions = [8.0, -5.8];
const poleTop = 7.7;
for (const z of polePositions) {
const base = terraceTop(z);
const height = poleTop - base;
box(
scene,
[0.17, height, 0.17],
[5.22, base + height / 2, z],
materials.wood
);
box(
scene,
[1.55, 0.13, 0.13],
[5.22, poleTop - 0.18, z],
materials.wood
);
}
for (const x of [4.78, 5.22, 5.66]) {
box(
scene,
[0.025, 0.025, 13.8],
[x, poleTop - 0.16, 1.1],
materials.cable,
{ cast: false }
);
}
// A quiet minaret on the skyline, used as a local architectural reference.
const minaret = new THREE.Group();
minaret.position.set(1.45, terraceTop(-20.5), -20.5);
scene.add(minaret);
box(
minaret,
[1.08, 7.0, 1.08],
[0, 3.5, 0],
materials.cream
);
box(
minaret,
[1.48, 0.22, 1.48],
[0, 6.55, 0],
materials.trim
);
box(
minaret,
[0.98, 0.95, 0.98],
[0, 7.12, 0],
materials.cream
);
box(
minaret,
[0.75, 0.45, 0.75],
[0, 7.78, 0],
materials.trim
);
box(
minaret,
[0.48, 0.38, 0.48],
[0, 8.16, 0],
materials.cream
);
box(
minaret,
[0.10, 0.42, 0.10],
[0, 8.53, 0],
materials.metal
);
// Blocky Table Mountain silhouettes in the distance.
const mountainBlocks = [
[-30, 16, 10, 13],
[-13, 20, 15, 13],
[7, 24, 12, 13],
[29, 19, 10, 13]
];
mountainBlocks.forEach((entry, index) => {
const [x, width, height, depth] = entry;
box(
scene,
[width, height, depth],
[x, height / 2 - 1, -48 - index * 2],
index % 2 ? materials.mountain : materials.mountainDark,
{ cast: false, receive: false }
);
});
// Everyday doorstep objects.
function addPlant(parent, x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
box(group, [0.36, 0.38, 0.36], [0, 0.19, 0], materials.pot);
box(group, [0.31, 0.05, 0.31], [0, 0.39, 0], materials.wood);
box(group, [0.07, 0.38, 0.07], [0, 0.58, 0], materials.plant);
const leafA = box(
group,
[0.13, 0.38, 0.15],
[-0.11, 0.72, 0],
materials.plant
);
leafA.rotation.z = -0.55;
const leafB = box(
group,
[0.13, 0.42, 0.15],
[0.11, 0.77, 0],
materials.plantLight
);
leafB.rotation.z = 0.58;
const leafC = box(
group,
[0.16, 0.28, 0.15],
[0, 0.94, 0],
materials.plant
);
leafC.rotation.z = 0.2;
}
function addChair(parent, x, y, z) {
const chair = new THREE.Group();
chair.position.set(x, y, z);
parent.add(chair);
box(chair, [0.72, 0.12, 0.70], [0, 0.48, 0], materials.wood);
box(chair, [0.12, 0.85, 0.70], [-0.31, 0.88, 0], materials.wood);
for (const dx of [-0.25, 0.25]) {
for (const dz of [-0.25, 0.25]) {
box(
chair,
[0.09, 0.48, 0.09],
[dx, 0.24, dz],
materials.wood
);
}
}
}
function addTable(parent, x, y, z) {
const table = new THREE.Group();
table.position.set(x, y, z);
parent.add(table);
box(table, [0.72, 0.10, 0.68], [0, 0.64, 0], materials.wood);
for (const dx of [-0.26, 0.26]) {
for (const dz of [-0.23, 0.23]) {
box(
table,
[0.08, 0.62, 0.08],
[dx, 0.31, dz],
materials.wood
);
}
}
box(table, [0.13, 0.14, 0.13], [-0.14, 0.76, 0.08], materials.trim);
box(table, [0.13, 0.14, 0.13], [0.15, 0.76, -0.08], materials.trim);
}
const firstHouseY = terraceTop(houseSpecs[0].z);
addChair(scene, -2.58, firstHouseY + 0.22, 6.95);
addTable(scene, -2.63, firstHouseY + 0.22, 8.02);
addPlant(scene, -2.55, firstHouseY + 0.22, 5.82, 1.05);
// Voxel people use ordinary contemporary clothing.
function makeStandingPerson(options) {
const group = new THREE.Group();
const skin = options.skin;
const shirt = options.shirt;
const pants = options.pants;
const torso = box(
group,
[0.62, 0.73, 0.38],
[0, 1.13, 0],
shirt
);
box(group, [0.18, 0.16, 0.18], [0, 1.56, 0], skin);
box(group, [0.39, 0.39, 0.38], [0, 1.76, 0], skin);
box(group, [0.41, 0.12, 0.40], [0, 1.94, -0.01], materials.hair);
box(group, [0.09, 0.10, 0.09], [0, 1.74, -0.22], skin);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.17, 0.77, 0);
rightLeg.position.set(0.17, 0.77, 0);
group.add(leftLeg, rightLeg);
for (const leg of [leftLeg, rightLeg]) {
box(leg, [0.21, 0.66, 0.24], [0, -0.33, 0], pants);
box(leg, [0.25, 0.14, 0.36], [0, -0.67, -0.07], materials.shoes);
}
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.42, 1.43, 0);
rightArm.position.set(0.42, 1.43, 0);
group.add(leftArm, rightArm);
for (const arm of [leftArm, rightArm]) {
box(arm, [0.17, 0.58, 0.20], [0, -0.29, 0], shirt);
box(arm, [0.16, 0.17, 0.17], [0, -0.64, 0], skin);
}
return {
group,
torso,
leftLeg,
rightLeg,
leftArm,
rightArm
};
}
// A resident seated outside on the stoep.
const seated = new THREE.Group();
seated.position.set(-2.49, firstHouseY + 0.22, 6.96);
scene.add(seated);
const seatedSkin = materials.skinB;
const seatedShirt = materials.shirtSand;
box(seated, [0.53, 0.66, 0.45], [0.02, 1.02, 0], seatedShirt);
box(seated, [0.18, 0.16, 0.18], [0.03, 1.43, 0], seatedSkin);
box(seated, [0.38, 0.38, 0.37], [0.03, 1.63, 0], seatedSkin);
box(seated, [0.40, 0.11, 0.39], [0.03, 1.80, -0.01], materials.hair);
box(seated, [0.09, 0.09, 0.09], [0.24, 1.61, 0], seatedSkin);
for (const z of [-0.15, 0.15]) {
box(seated, [0.58, 0.18, 0.19], [0.24, 0.55, z], materials.trousers);
box(seated, [0.19, 0.48, 0.19], [0.48, 0.28, z], materials.trousers);
box(seated, [0.34, 0.14, 0.22], [0.54, 0.08, z], materials.shoes);
}
box(seated, [0.50, 0.16, 0.42], [-0.02, 0.66, 0], materials.trousers);
box(seated, [0.48, 0.17, 0.16], [0.18, 0.91, -0.31], seatedShirt);
box(seated, [0.48, 0.17, 0.16], [0.18, 0.91, 0.31], seatedShirt);
// Another resident standing in a doorway with a small cup.
const secondHouseY = terraceTop(houseSpecs[1].z);
const resident = makeStandingPerson({
skin: materials.skinA,
shirt: materials.shirtBlue,
pants: materials.trousers
});
resident.group.position.set(-3.13, secondHouseY + 0.22, 2.93);
resident.group.rotation.y = -Math.PI / 2;
resident.rightArm.rotation.x = -0.8;
box(
resident.rightArm,
[0.15, 0.14, 0.15],
[0, -0.73, 0],
materials.trim
);
scene.add(resident.group);
// A passing pedestrian with a simple shopping tote.
const pedestrian = makeStandingPerson({
skin: materials.skinC,
shirt: materials.shirtBlue,
pants: standard(0x9b8c72)
});
pedestrian.group.position.set(0.72, 0.1, 9.5);
scene.add(pedestrian.group);
box(
pedestrian.rightArm,
[0.34, 0.42, 0.15],
[0, -0.76, 0],
materials.bag
);
// Camera controls: orbit, zoom, keyboard pan, and reset.
const target = new THREE.Vector3(-1.2, 2.0, -1.0);
let yaw = 0.49;
let pitch = 0.39;
let radius = 24;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const horizontalRadius = Math.cos(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontalRadius,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontalRadius
);
camera.lookAt(target);
}
function resetCamera() {
target.set(-1.2, 2.0, -1.0);
yaw = 0.49;
pitch = 0.39;
radius = 24;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
yaw -= deltaX * 0.005;
pitch = THREE.MathUtils.clamp(
pitch + deltaY * 0.004,
0.13,
0.78
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
12,
34
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const panStep = 0.45;
if (event.key === "ArrowLeft") {
target.x -= panStep;
} else if (event.key === "ArrowRight") {
target.x += panStep;
} else if (event.key === "ArrowUp") {
target.z -= panStep;
} else if (event.key === "ArrowDown") {
target.z += panStep;
} else if (event.key.toLowerCase() === "r") {
resetCamera();
} else {
return;
}
updateCamera();
});
document.getElementById("reset").addEventListener("click", resetCamera);
resetCamera();
function handleResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", handleResize);
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const motionTime = reducedMotion ? elapsed * 0.35 : elapsed;
// The pedestrian walks uphill, pauses out of view, and returns.
const walkCycle = (motionTime * 0.76) % 24;
pedestrian.group.visible = walkCycle < 22;
if (pedestrian.group.visible) {
const z = 9.5 - walkCycle;
const phase = motionTime * 5.4;
const stride = Math.sin(phase);
pedestrian.group.position.set(
0.72,
smoothRoadHeight(z) + 0.1,
z
);
pedestrian.leftLeg.rotation.x = stride * 0.58;
pedestrian.rightLeg.rotation.x = -stride * 0.58;
pedestrian.leftArm.rotation.x = -stride * 0.43;
pedestrian.rightArm.rotation.x = stride * 0.43;
pedestrian.group.position.y += Math.abs(Math.sin(phase)) * 0.025;
}
// A nearly imperceptible shift in the wall lamps suggests evening.
const lampStrength = 0.62 + Math.sin(elapsed * 0.4) * 0.05;
materials.lamp.emissiveIntensity = lampStrength;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```