Prompt specification
Build or customize the Three.js 3D scene "Bo-Kaap: three-arm junction at Wale and Rose" 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: three-arm junction at Wale and Rose
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bo-kaap-three-arm-junction-at-wale-and-rose-x2887
Scene Description Prompt:
Create a bounded voxel street fragment of the Wale Street and Rose Street T junction in Bo-Kaap, Cape Town. Use the map node https://www.openstreetmap.org/node/36682265 and Rose Street https://www.openstreetmap.org/way/5216820, and locate the museum on the southwest side of the hub at https://www.openstreetmap.org/way/428530536 and https://www.iziko.org.za/museums/bo-kaap-museum/. Wale has a northwest and a southeast arm. Rose approaches from the northeast and stops at Wale. Show a clear three-arm plan, regular frontage heights with some variation, doors, curb edges, and illustrative stepped terrain in an oblique cutaway. Do not draw a fourth arm or assign unverified individual facades. Use a few ordinary people and vehicles following the roads.
Return one self-contained HTML file with procedural Three.js (cdnjs r160 module) and controls that work in a sandbox allowing scripts. Keep the subject readable in the default camera. Use local event handlers and no runtime requests besides Three.js.
Working Three.js Starter (bo-kaap-three-arm-junction-at-wale-and-rose-x2887):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#d9c7b2">
<link rel="icon" href="data:,">
<title>Wale Street × Rose Street — Bo-Kaap Voxel Fragment</title>
<style>
:root {
color-scheme: light;
--ink: #302b32;
--paper: rgba(255, 248, 237, 0.92);
--line: rgba(55, 43, 45, 0.18);
--accent: #a64f46;
--blue: #537b83;
--museum: #b27745;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9c7b2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene, #scene canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.panel {
position: absolute;
z-index: 5;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 12px 36px rgba(61, 39, 40, 0.13);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: max(18px, env(safe-area-inset-top));
left: max(18px, env(safe-area-inset-left));
width: min(390px, calc(100vw - 36px));
padding: 18px 20px 17px;
border-radius: 4px 18px 18px 18px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3.2vw, 46px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
#intro .subtitle {
max-width: 330px;
margin: 10px 0 0;
color: #5e5356;
font-size: 12px;
line-height: 1.45;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
}
.chip {
padding: 5px 8px;
border: 1px solid rgba(64, 45, 47, 0.14);
border-radius: 999px;
background: rgba(255,255,255,0.42);
color: #57494b;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#plan-card {
top: max(18px, env(safe-area-inset-top));
right: max(18px, env(safe-area-inset-right));
width: 238px;
padding: 13px 14px 12px;
border-radius: 16px 4px 16px 16px;
pointer-events: none;
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: #695c5d;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.north {
display: inline-flex;
align-items: center;
gap: 4px;
color: #6e5a50;
}
.north svg { width: 13px; height: 13px; }
#plan-card svg {
display: block;
width: 100%;
height: auto;
overflow: visible;
}
.plan-caption {
margin-top: 6px;
color: #6e6262;
font-size: 9px;
line-height: 1.4;
}
#controls {
left: max(18px, env(safe-area-inset-left));
bottom: max(18px, env(safe-area-inset-bottom));
display: flex;
align-items: center;
gap: 5px;
padding: 7px;
border-radius: 14px;
}
button {
appearance: none;
border: 1px solid rgba(56, 43, 46, 0.15);
border-radius: 9px;
padding: 9px 11px;
background: rgba(255,255,255,0.62);
color: #4a4042;
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
transition: background 140ms ease, transform 140ms ease;
}
button:hover { background: #fffaf1; }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
#hint {
margin-left: 6px;
padding: 0 7px;
color: #75686a;
font-size: 9px;
line-height: 1.25;
}
#sources {
right: max(18px, env(safe-area-inset-right));
bottom: max(18px, env(safe-area-inset-bottom));
width: min(350px, calc(100vw - 36px));
padding: 13px 15px;
border-radius: 16px 16px 4px 16px;
pointer-events: none;
}
#sources strong {
display: block;
margin-bottom: 5px;
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#sources p {
margin: 0;
color: #6c6061;
font-size: 9px;
line-height: 1.48;
}
#sources .note {
margin-top: 7px;
padding-top: 7px;
border-top: 1px solid var(--line);
color: #54484a;
font-weight: 650;
}
#loading {
position: absolute;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d9c7b2;
color: #5d4d4d;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
#intro { width: min(330px, calc(100vw - 36px)); padding: 14px 16px; }
#intro .subtitle { display: none; }
#plan-card { width: 180px; padding: 10px; }
.plan-caption { display: none; }
#sources { display: none; }
#hint { display: none; }
button { padding: 8px 9px; }
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive oblique voxel model of the Wale Street and Rose Street junction"></main>
<section id="intro" class="panel">
<p class="eyebrow">Cape Town · Bo-Kaap</p>
<h1>Wale × Rose</h1>
<p class="subtitle">
A bounded, three-arm voxel street fragment. Wale runs northwest–southeast;
Rose approaches from the northeast and terminates at the junction.
</p>
<div class="chips">
<span class="chip">Three arms only</span>
<span class="chip">Illustrative terrain</span>
<span class="chip">Museum southwest</span>
</div>
</section>
<aside id="plan-card" class="panel" aria-label="Orientation plan">
<div class="card-heading">
<span>Orientation</span>
<span class="north">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M10 1 16 17 10 13 4 17Z" fill="#a64f46"/>
</svg>
N
</span>
</div>
<svg viewBox="0 0 220 145" role="img" aria-label="Wale Street northwest-southeast with Rose Street approaching from northeast">
<path d="M28 18 L192 125" fill="none" stroke="#70666a" stroke-width="15" stroke-linecap="square"/>
<path d="M28 18 L192 125" fill="none" stroke="#39373d" stroke-width="9" stroke-linecap="square"/>
<path d="M194 18 L111 74" fill="none" stroke="#70666a" stroke-width="15" stroke-linecap="square"/>
<path d="M194 18 L111 74" fill="none" stroke="#39373d" stroke-width="9" stroke-linecap="square"/>
<rect x="73" y="88" width="31" height="20" rx="2" fill="#c99358" stroke="#835638" stroke-width="2"/>
<circle cx="111" cy="74" r="7" fill="#f3e7d5" stroke="#a64f46" stroke-width="3"/>
<g fill="#5e5356" font-family="system-ui, sans-serif" font-size="10" font-weight="700">
<text x="11" y="12">NW</text>
<text x="184" y="142">SE</text>
<text x="182" y="14">NE</text>
</g>
<text x="50" y="120" fill="#704f3b" font-family="system-ui, sans-serif" font-size="8" font-weight="700">MUSEUM</text>
</svg>
<div class="plan-caption">Schematic plan; Rose has no continuation southwest of Wale.</div>
</aside>
<nav id="controls" class="panel" aria-label="Camera controls">
<button type="button" id="reset">Reset</button>
<button type="button" id="plan">Plan</button>
<button type="button" id="left" aria-label="Rotate left">↶</button>
<button type="button" id="right" aria-label="Rotate right">↷</button>
<button type="button" id="zoom-in" aria-label="Zoom in">+</button>
<button type="button" id="zoom-out" aria-label="Zoom out">−</button>
<span id="hint">Drag to orbit · wheel to zoom</span>
</nav>
<aside id="sources" class="panel">
<strong>Location anchors & limits</strong>
<p>
OSM junction node 36682265 · Rose Street way 5216820 ·
Bo-Kaap Museum way 428530536. Museum identity: Iziko Bo-Kaap Museum.
</p>
<p class="note">
Generic representative frontage massing and stepped ground are illustrative.
No individual facade is identified or reproduced as verified geometry.
</p>
</aside>
<div id="loading">Building the street fragment…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// Spatial anchors:
// OSM node 36682265 defines the Wale/Rose junction.
// Rose Street is OSM way 5216820 and approaches from the northeast.
// The museum is placed southwest of the hub from OSM way 428530536 and
// Iziko's museum listing. Building forms below are deliberately generic.
const container = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9c7b2);
scene.fog = new THREE.Fog(0xd9c7b2, 230, 390);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute("aria-label", "Orbitable 3D model of Wale and Rose streets");
renderer.domElement.tabIndex = 0;
container.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-100, 100, 100, -100, 0.1, 500);
const target = new THREE.Vector3(0, 3.5, 0);
const cameraState = {
yaw: 0.10,
pitch: 0.72,
zoom: 1,
defaultYaw: 0.10,
defaultPitch: 0.72
};
const hemisphere = new THREE.HemisphereLight(0xfff1d9, 0x716278, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6bf, 3.15);
sun.position.set(-70, 105, 55);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -105;
sun.shadow.camera.right = 105;
sun.shadow.camera.top = 105;
sun.shadow.camera.bottom = -105;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 260;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cc7d3, 0.55);
fill.position.set(85, 35, -80);
scene.add(fill);
const cube = new THREE.BoxGeometry(1, 1, 1);
const SQRT2 = Math.SQRT2;
// u runs along Wale from northwest to southeast.
// v runs perpendicular to Wale, positive toward the northeast.
function uvWorld(u, v, y = 0) {
return new THREE.Vector3(
(u + v) / SQRT2,
y,
(u - v) / SQRT2
);
}
const WALE_ANGLE = -Math.PI / 4;
const ROSE_ANGLE = Math.PI / 4;
function material(color, roughness = 0.84) {
return new THREE.MeshStandardMaterial({ color, roughness });
}
function box(w, h, d, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(cube, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function orientedBox(w, h, d, mat, u, v, y, angle, parent = scene) {
const mesh = box(w, h, d, mat, 0, 0, 0, parent);
mesh.position.copy(uvWorld(u, v, y));
mesh.rotation.y = angle;
return mesh;
}
// Stratified cutaway base.
const baseBottom = material(0x6e5260);
const baseMiddle = material(0xa86e63);
const baseTop = material(0xc79b78);
box(160, 4, 160, baseBottom, 0, -6, 0);
box(159, 3, 159, baseMiddle, 0, -2.5, 0);
box(158, 1, 158, baseTop, 0, -0.5, 0);
// Stepped terrain, carved away around the two road corridors.
function terrainLevel(u, v) {
let level = 0;
if (v > 13) level = Math.min(3, 1 + Math.floor((v - 13) / 10));
if (u > 63) level = Math.min(3, 1 + Math.floor((u - 63) / 10));
if (v < -34) level = Math.max(level, 1);
if (u < -66) level = Math.max(level, 1);
return level;
}
function isMuseumParcel(u, v) {
return u > -21 && u < 21 && v > -33 && v < -5;
}
function distanceToRoad(u, v) {
let distance = 999;
if (u > -76 && u < 76) distance = Math.min(distance, Math.abs(v));
if (v > 3 && v < 65) distance = Math.min(distance, Math.abs(u));
return distance;
}
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = mulberry32(428530536);
const terrainMaterials = [
material(0xc99e7c),
material(0xd4aa85),
material(0xbf8e73),
material(0xd8b18d),
material(0xc59780)
];
const tileSize = 8;
for (let ix = -10; ix < 10; ix++) {
for (let iz = -10; iz < 10; iz++) {
const x = -76 + ix * tileSize;
const z = -76 + iz * tileSize;
const u = (x + z) / SQRT2;
const v = (x - z) / SQRT2;
if (distanceToRoad(u, v) < 12.2 || isMuseumParcel(u, v)) continue;
const level = terrainLevel(u, v);
const mat = terrainMaterials[
Math.floor(random() * terrainMaterials.length)
];
box(tileSize, Math.max(0.4, level), tileSize, mat, x, level / 2, z);
}
}
// Street surfaces.
const sidewalkMat = material(0xd8c7aa);
const curbMat = material(0xf0dfc2);
const roadMat = material(0x3f3d45);
const roadPaint = material(0xe8dcc1);
const amberPaint = material(0xc58a4b);
// Wale: continuous northwest–southeast arm.
orientedBox(146, 0.13, 16, sidewalkMat, 0, 0, 0.075, WALE_ANGLE);
orientedBox(146, 0.23, 9, roadMat, 0, 0, 0.235, WALE_ANGLE);
// Rose: only the northeast approach; it stops at Wale.
orientedBox(58, 0.13, 16, sidewalkMat, 0, 33.5, 0.075, ROSE_ANGLE);
orientedBox(57.5, 0.23, 9, roadMat, 0, 33.25, 0.235, ROSE_ANGLE);
// Curbs are interrupted where Rose meets Wale.
for (const side of [-1, 1]) {
for (const [start, end] of [[-72, -7], [7, 72]]) {
orientedBox(
end - start, 0.34, 0.32, curbMat,
(start + end) / 2, side * 4.72, 0.31,
WALE_ANGLE
);
}
orientedBox(55.5, 0.34, 0.32, curbMat, side * 4.72, 34, 0.31, ROSE_ANGLE);
}
orientedBox(0.32, 0.34, 9.2, curbMat, 0, 62, 0.31, ROSE_ANGLE);
// Restrained road markings.
for (let u = -67; u <= 67; u += 8) {
if (Math.abs(u) < 10) continue;
orientedBox(3.3, 0.035, 0.18, roadPaint, u, 0, 0.375, WALE_ANGLE);
}
orientedBox(0.30, 0.035, 7.6, roadPaint, 0, 7.4, 0.375, ROSE_ANGLE);
for (let i = -2; i <= 2; i++) {
orientedBox(2.4, 0.035, 0.48, roadPaint, 10.5, i * 1.35, 0.375, WALE_ANGLE);
}
// Highlight the three-arm hub with four small amber corner blocks.
for (const side of [-1, 1]) {
orientedBox(0.34, 0.05, 0.34, amberPaint, side * 5.8, 5.8, 0.39, WALE_ANGLE);
orientedBox(0.34, 0.05, 0.34, amberPaint, side * 5.8, -5.8, 0.39, WALE_ANGLE);
}
// Museum parcel: a low platform on the southwest side of the hub.
const museumFoundationMat = material(0xb89470);
orientedBox(38, 0.34, 27, museumFoundationMat, 0, -19, 0.17, WALE_ANGLE);
const foundationMat = material(0xa68b78);
const plinthMat = material(0xcab9a0);
const roofMat = material(0x786b68);
const glassMat = material(0x405c63, 0.38);
const doorMat = material(0x36555d, 0.42);
const trimMat = material(0xf1dfc3);
const facadePalette = [
material(0xc87966),
material(0xd0a064),
material(0x73999a),
material(0xe3d0ad),
material(0xb9a4a0),
material(0xc9947c)
];
function addBuilding({
u, v, w, d, h, color, road = "wale", frontSign = -1,
baseLevel = terrainLevel(u, v), label = null, setback = false
}) {
const group = new THREE.Group();
group.position.copy(uvWorld(u, v, baseLevel));
group.rotation.y = road === "wale" ? WALE_ANGLE : ROSE_ANGLE;
scene.add(group);
if (baseLevel > 0) {
box(w + 1.0, baseLevel, d + 1.0, foundationMat, 0, -baseLevel / 2, 0, group);
}
box(w + 0.45, 0.48, d + 0.45, plinthMat, 0, 0.24, 0, group);
box(w, h, d, color, 0, 0.48 + h / 2, 0, group);
box(w + 0.35, 0.28, d + 0.35, roofMat, 0, h + 0.62, 0, group);
if (setback) {
box(w * 0.68, 1.7, d * 0.72, color, w * 0.06, h + 1.55, -0.25, group);
box(w * 0.70, 0.22, d * 0.74, roofMat, w * 0.06, h + 2.50, -0.25, group);
}
// Simple parapet blocks preserve the voxel character.
box(w + 0.22, 0.55, 0.22, roofMat, 0, h + 1.0, d / 2, group);
box(w + 0.22, 0.55, 0.22, roofMat, 0, h + 1.0, -d / 2, group);
const frontZ = frontSign * (d / 2 + 0.07);
const doorX = -w * 0.22;
// Door and its simple threshold.
box(1.65, 2.45, 0.16, doorMat, doorX, 1.70, frontZ, group);
box(2.05, 0.18, 0.25, trimMat, doorX, 3.02, frontZ, group);
// Two or three generic bays, without assigning a named facade.
const windowXs = [-w * 0.32, 0, w * 0.32];
windowXs.forEach((x, index) => {
if (Math.abs(x - doorX) < 1.45) return;
box(1.65, 1.85, 0.16, trimMat, x, 3.35, frontZ, group);
box(1.25, 1.45, 0.18, glassMat, x, 3.35, frontZ + frontSign * 0.06, group);
if (h > 8.7 && index !== 1) {
box(1.45, 1.65, 0.14, trimMat, x, 6.55, frontZ, group);
box(1.08, 1.25, 0.17, glassMat, x, 6.55, frontZ + frontSign * 0.06, group);
}
});
// A restrained, generic awning on some representative buildings.
if (h > 9.4) {
box(2.45, 0.22, 1.05, roofMat, doorX, 3.28, frontZ + frontSign * 0.42, group);
}
// Small steps connect the raised frontage to the sidewalk.
box(2.8, 0.34, 0.70, plinthMat,
doorX, -baseLevel + 0.48, frontSign * (d / 2 + 0.52), group);
box(2.2, 0.32, 0.55, plinthMat,
doorX, -baseLevel + 0.80, frontSign * (d / 2 + 0.24), group);
if (label) {
const sign = new THREE.Group();
sign.position.copy(uvWorld(u, v, baseLevel + h + 4.8));
scene.add(sign);
}
return group;
}
// Representative frontages along Wale's northwest arm.
addBuilding({ u: -59, v: 18, w: 15, d: 11, h: 9.7, color: facadePalette[0], setback: true });
addBuilding({ u: -40, v: 18, w: 15, d: 12, h: 11.0, color: facadePalette[1] });
addBuilding({ u: -21, v: 18, w: 14, d: 11, h: 9.5, color: facadePalette[2] });
// Representative frontages along Wale's southeast arm.
addBuilding({ u: 24, v: -18, w: 14, d: 11, h: 9.2, color: facadePalette[3] });
addBuilding({ u: 44, v: -18, w: 16, d: 12, h: 10.8, color: facadePalette[2], setback: true });
addBuilding({ u: 63, v: -16, w: 12, d: 10, h: 8.7, color: facadePalette[1] });
addBuilding({ u: 37, v: 18, w: 15, d: 11, h: 10.2, color: facadePalette[5] });
addBuilding({ u: 58, v: 18, w: 13, d: 11, h: 11.6, color: facadePalette[3] });
// Rose frontages on either side of its northeast approach.
addBuilding({ u: 17, v: 25, w: 14, d: 11, h: 9.6, color: facadePalette[4], road: "rose", frontSign: -1 });
addBuilding({ u: 17, v: 44, w: 16, d: 12, h: 10.9, color: facadePalette[0], road: "rose", frontSign: -1, setback: true });
addBuilding({ u: -16, v: 24, w: 14, d: 11, h: 9.2, color: facadePalette[1], road: "rose", frontSign: 1 });
addBuilding({ u: -16, v: 44, w: 15, d: 12, h: 10.5, color: facadePalette[2], road: "rose", frontSign: 1 });
// Generic museum massing, located southwest of the hub.
addBuilding({
u: 0, v: -19, w: 26, d: 11, h: 8.8,
color: material(0xe0c9a1),
road: "wale", frontSign: -1,
baseLevel: 0.34
});
// Museum plot edge and a few low voxel shrubs.
const planterMat = material(0x9b7259);
const shrubMat = material(0x6f8260);
for (const [u, v] of [[-17,-11], [16,-11], [-17,-28], [16,-28]]) {
orientedBox(2.3, 0.65, 1.35, planterMat, u, v, 0.67, WALE_ANGLE);
orientedBox(1.75, 1.25, 0.9, shrubMat, u, v, 1.55, WALE_ANGLE);
}
// Street lamps and bollards.
const poleMat = material(0x4a4449);
const lampMat = material(0xf1d8a2);
function lamp(u, v, angle) {
const group = new THREE.Group();
group.position.copy(uvWorld(u, v, 0.2));
group.rotation.y = angle;
scene.add(group);
box(0.22, 4.8, 0.22, poleMat, 0, 2.4, 0, group);
box(1.55, 0.18, 0.18, poleMat, 0.65, 4.75, 0, group);
box(0.65, 0.18, 0.48, lampMat, 1.25, 4.61, 0, group);
}
lamp(-29, 6.8, WALE_ANGLE);
lamp(26, 6.8, WALE_ANGLE);
lamp(54, 6.8, WALE_ANGLE);
lamp(6.8, 30, ROSE_ANGLE);
const bollardMat = material(0x78615d);
for (const [u, v] of [[-8,6.3],[8,6.3],[-6.3,12],[6.3,12]]) {
orientedBox(0.38, 1.05, 0.38, bollardMat, u, v, 0.72, WALE_ANGLE);
}
// Local CanvasTexture labels; no external images or font requests.
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function textSprite(text, options = {}) {
const {
foreground = "#fff7e8",
background = "rgba(48,43,50,0.88)",
border = "rgba(255,255,255,0.18)",
width = 25
} = options;
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 12, 752, 136, 28);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 3;
ctx.strokeStyle = border;
ctx.stroke();
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "700 48px system-ui, sans-serif";
ctx.fillText(text, 384, 82, 700);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const mat = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(mat);
sprite.scale.set(width, width * canvas.height / canvas.width, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
const waleNorthLabel = textSprite("WALE STREET", { width: 22 });
waleNorthLabel.position.copy(uvWorld(-52, 0, 2.7));
const waleSouthLabel = textSprite("WALE STREET", { width: 22 });
waleSouthLabel.position.copy(uvWorld(49, 0, 2.7));
const roseLabel = textSprite("ROSE STREET", { width: 21 });
roseLabel.position.copy(uvWorld(0, 43, 2.8));
const museumLabel = textSprite("IZIKO BO-KAAP MUSEUM", {
width: 29,
foreground: "#51382d",
background: "rgba(241,214,170,0.95)",
border: "rgba(114,76,50,0.30)"
});
museumLabel.position.copy(uvWorld(0, -19, 14.4));
const junctionLabel = textSprite("T JUNCTION", {
width: 15,
foreground: "#fff5df",
background: "rgba(166,79,70,0.92)"
});
junctionLabel.position.copy(uvWorld(-8.5, -7.8, 4.8));
// North arrow on the fragment's northwest edge.
const compass = new THREE.Group();
const compassPos = uvWorld(-69, -54, 0.5);
compass.position.copy(compassPos);
scene.add(compass);
box(0.45, 0.18, 8.5, poleMat, 0, 0, -3.7, compass);
const headA = box(0.45, 0.18, 4.3, amberPaint, 0, 0, -8.7, compass);
headA.rotation.y = Math.PI / 4;
const headB = box(0.45, 0.18, 4.3, amberPaint, 0, 0, -8.7, compass);
headB.rotation.y = -Math.PI / 4;
const northSprite = textSprite("N", {
width: 5,
foreground: "#5c493e",
background: "rgba(244,226,198,0.92)"
});
northSprite.position.copy(uvWorld(-69, -54, 4.2));
// Ordinary voxel pedestrians.
function createPerson(shirtColor, trousersColor) {
const group = new THREE.Group();
const skin = material(0x9b674e);
const shirt = material(shirtColor);
const trousers = material(trousersColor);
const shoes = material(0x39363b);
box(0.72, 0.88, 0.42, shirt, 0, 1.03, 0, group);
box(0.43, 0.43, 0.43, skin, 0, 1.70, 0, group);
box(0.50, 0.18, 0.48, trousers, 0, 1.50, 0, group);
const leftLeg = box(0.25, 0.68, 0.27, trousers, -0.21, 0.34, 0, group);
const rightLeg = box(0.25, 0.68, 0.27, trousers, 0.21, 0.34, 0, group);
box(0.29, 0.15, 0.36, shoes, -0.21, 0.05, 0.05, group);
box(0.29, 0.15, 0.36, shoes, 0.21, 0.05, 0.05, group);
box(0.20, 0.64, 0.22, shirt, -0.48, 1.02, 0, group);
box(0.20, 0.64, 0.22, shirt, 0.48, 1.02, 0, group);
group.userData.legs = [leftLeg, rightLeg];
scene.add(group);
return group;
}
const pedestrians = [
createPerson(0xc46c55, 0x4c5962),
createPerson(0xe0b65d, 0x5b4960),
createPerson(0x5d8992, 0x413d48),
createPerson(0xd7d0b6, 0x695548),
createPerson(0x8c6a92, 0x3d4e58)
];
// Ordinary voxel vehicles.
function createCar(color, van = false) {
const group = new THREE.Group();
const body = material(color, 0.48);
const trim = material(0x39434a, 0.4);
const tire = material(0x29292d);
const glass = material(0x6e929a, 0.28);
if (van) {
box(4.6, 1.55, 1.85, body, 0, 1.05, 0, group);
box(2.0, 0.82, 1.62, trim, -1.25, 1.12, 0, group);
box(1.58, 0.54, 1.66, glass, -1.28, 1.2, 0, group);
} else {
box(4.2, 0.72, 1.72, body, 0, 0.77, 0, group);
box(2.25, 0.72, 1.52, trim, -0.15, 1.42, 0, group);
box(1.78, 0.48, 1.55, glass, -0.18, 1.45, 0, group);
box(1.10, 0.25, 1.50, body, 1.45, 1.06, 0, group);
}
box(0.38, 0.18, 0.42, material(0xf2dda6), 2.12, 0.85, 0.58, group);
box(0.38, 0.18, 0.42, material(0xf2dda6), 2.12, 0.85, -0.58, group);
box(0.38, 0.18, 0.42, material(0xa94c42), -2.12, 0.85, 0.58, group);
box(0.38, 0.18, 0.42, material(0xa94c42), -2.12, 0.85, -0.58, group);
const wheelPositions = [[-1.35,1],[1.35,1],[-1.35,-1],[1.35,-1]];
wheelPositions.forEach(([x,z]) => {
box(0.72, 0.66, 0.26, tire, x, 0.47, z * 0.88, group);
});
scene.add(group);
return group;
}
const vehicles = [
createCar(0xc26d56),
createCar(0x668e98),
createCar(0xe0d3ad, true)
];
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clock = new THREE.Clock();
function animatePeople(time) {
const paths = [
{ person: pedestrians[0], road: "wale", u: -46 + ((time * 2.0) % 91), v: 6.25, reverse: false },
{ person: pedestrians[1], road: "wale", u: 51 - ((time * 1.65) % 101), v: -6.25, reverse: true },
{ person: pedestrians[2], road: "rose", u: 6.25, v: 15 + ((time * 1.35) % 43), reverse: false },
{ person: pedestrians[3], road: "rose", u: -6.25, v: 57 - ((time * 1.25) % 49), reverse: true },
{ person: pedestrians[4], road: "wale", u: -8 + ((time * 1.1) % 77), v: 6.25, reverse: false }
];
paths.forEach((path, index) => {
const p = path.person;
if (path.road === "wale") {
p.position.copy(uvWorld(path.u, path.v, 0.38));
p.rotation.y = path.reverse ? WALE_ANGLE + Math.PI : WALE_ANGLE;
} else {
p.position.copy(uvWorld(path.u, path.v, 0.38));
p.rotation.y = path.reverse ? ROSE_ANGLE + Math.PI : ROSE_ANGLE;
}
const stride = Math.sin(time * 5.8 + index) * 0.26;
p.userData.legs[0].rotation.z = stride;
p.userData.legs[1].rotation.z = -stride;
p.position.y += Math.abs(Math.sin(time * 5.8 + index)) * 0.035;
});
}
function animateVehicles(time) {
const u1 = -64 + ((time * 8.2) % 128);
const u2 = 64 - ((time * 6.7) % 128);
const roseTravel = (time * 6.1) % 52;
const roseV = 56 - roseTravel;
vehicles[0].position.copy(uvWorld(u1, 0, 0.38));
vehicles[0].rotation.y = WALE_ANGLE;
vehicles[1].position.copy(uvWorld(u2, 0, 0.38));
vehicles[1].rotation.y = WALE_ANGLE + Math.PI;
// This vehicle remains on Rose and never continues through the hub.
vehicles[2].position.copy(uvWorld(0, roseV, 0.38));
vehicles[2].rotation.y = ROSE_ANGLE + Math.PI;
}
// Direct camera controls: no addons or external control libraries.
let fitSize = 112;
let width = 1;
let height = 1;
function updateProjection() {
const aspect = width / Math.max(1, height);
fitSize = Math.max(112, 176 / aspect);
const size = fitSize * cameraState.zoom;
camera.left = -size * aspect / 2;
camera.right = size * aspect / 2;
camera.top = size / 2;
camera.bottom = -size / 2;
camera.updateProjectionMatrix();
}
function updateCamera() {
const radius = 190;
camera.position.set(
target.x + radius * Math.cos(cameraState.pitch) * Math.sin(cameraState.yaw),
target.y + radius * Math.sin(cameraState.pitch),
target.z + radius * Math.cos(cameraState.pitch) * Math.cos(cameraState.yaw)
);
camera.lookAt(target);
updateProjection();
}
function resize() {
width = Math.max(1, container.clientWidth);
height = Math.max(1, container.clientHeight);
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
const pointers = new Map();
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) pinchDistance = pointerDistance();
});
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 === 1) {
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.34,
1.48
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (pinchDistance / distance),
0.56,
1.75
);
}
pinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(event.deltaY * 0.001),
0.56,
1.75
);
updateCamera();
}, { passive: false });
document.getElementById("reset").addEventListener("click", () => {
cameraState.yaw = cameraState.defaultYaw;
cameraState.pitch = cameraState.defaultPitch;
cameraState.zoom = 1;
updateCamera();
});
document.getElementById("plan").addEventListener("click", () => {
cameraState.yaw = 0;
cameraState.pitch = 1.47;
cameraState.zoom = 0.93;
updateCamera();
});
document.getElementById("left").addEventListener("click", () => {
cameraState.yaw -= 0.18;
updateCamera();
});
document.getElementById("right").addEventListener("click", () => {
cameraState.yaw += 0.18;
updateCamera();
});
document.getElementById("zoom-in").addEventListener("click", () => {
cameraState.zoom = Math.max(0.56, cameraState.zoom * 0.9);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
cameraState.zoom = Math.min(1.75, cameraState.zoom / 0.9);
updateCamera();
});
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraState.yaw += 0.12;
else if (key === "arrowright") cameraState.yaw -= 0.12;
else if (key === "arrowup") cameraState.pitch = Math.min(1.48, cameraState.pitch + 0.08);
else if (key === "arrowdown") cameraState.pitch = Math.max(0.34, cameraState.pitch - 0.08);
else if (key === "+" || key === "=") cameraState.zoom = Math.max(0.56, cameraState.zoom * 0.92);
else if (key === "-") cameraState.zoom = Math.min(1.75, cameraState.zoom / 0.92);
else return;
event.preventDefault();
updateCamera();
});
resize();
updateCamera();
function render() {
const time = clock.getElapsedTime();
if (!reducedMotion) {
animatePeople(time);
animateVehicles(time);
}
renderer.render(scene, camera);
requestAnimationFrame(render);
}
renderer.render(scene, camera);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
render();
</script>
</body>
</html>
```