Prompt specification
Build or customize the Three.js 3D scene "Central–Mid-Levels street and elevated-link slice" 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: Central–Mid-Levels street and elevated-link slice
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/central-mid-levels-street-and-elevated-link-slice-x2987
Scene Description Prompt:
Central–Mid-Levels street and elevated-link slice. Build a bounded low-poly scene with referenced steep streets, dense facades, and a short escalator segment. Keep the network readable rather than filling the entire skyline with towers. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (central-mid-levels-street-and-elevated-link-slice-x2987):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Central ↗ Mid-Levels — Urban Section</title>
<style>
:root {
--ink: #183139;
--paper: rgba(247, 244, 234, 0.92);
--line: rgba(24, 49, 57, 0.18);
--teal: #2d7f82;
--red: #d55343;
--gold: #d6a64f;
--shadow: 0 16px 48px rgba(28, 46, 51, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7e0df;
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;
outline: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.68);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
position: absolute;
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 4px;
}
.eyebrow {
margin-bottom: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
color: var(--teal);
}
h1 {
margin: 0;
font-size: clamp(24px, 3.3vw, 38px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
}
h1 span {
color: var(--red);
font-weight: 450;
}
#title-card p {
margin: 12px 0 16px;
max-width: 31em;
font-size: 12px;
line-height: 1.55;
color: rgba(24, 49, 57, 0.74);
}
.tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.tag {
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 2px;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#views {
position: absolute;
top: 22px;
right: 22px;
display: flex;
gap: 5px;
padding: 6px;
border-radius: 4px;
pointer-events: auto;
}
#views button,
#reset {
border: 0;
border-radius: 2px;
padding: 9px 11px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 760;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: background 150ms ease, color 150ms ease;
}
#views button:hover,
#reset:hover {
background: var(--ink);
color: #fff8e9;
}
#legend {
position: absolute;
left: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 13px;
max-width: calc(100vw - 44px);
padding: 12px 15px;
border-radius: 3px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
font-size: 9px;
font-weight: 740;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.swatch {
width: 17px;
height: 5px;
border-radius: 1px;
}
#instructions {
position: absolute;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border-radius: 3px;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#instructions span {
opacity: 0.66;
}
#reset {
padding: 7px 9px;
border: 1px solid var(--line);
}
#labels {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
transform: translate(-50%, -100%);
min-width: 90px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 2px;
background: rgba(246, 242, 229, 0.91);
box-shadow: 0 5px 18px rgba(25, 44, 49, 0.13);
color: var(--ink);
text-align: center;
white-space: nowrap;
opacity: 0;
transition: opacity 160ms ease;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: currentColor;
opacity: 0.5;
}
.scene-label strong {
display: block;
font-size: 9px;
line-height: 1.1;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scene-label small {
display: block;
margin-top: 3px;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.08em;
opacity: 0.58;
}
.scene-label.red { border-left: 3px solid var(--red); }
.scene-label.teal { border-left: 3px solid var(--teal); }
.scene-label.gold { border-left: 3px solid var(--gold); }
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #d7e0df;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
padding: 15px 16px;
}
#title-card p { display: none; }
.tags { margin-top: 10px; }
#views {
top: auto;
right: 12px;
bottom: 61px;
flex-direction: column;
}
#views button { text-align: left; }
#legend {
left: 12px;
bottom: 12px;
gap: 9px;
}
#instructions { display: none; }
.scene-label {
transform: translate(-50%, -100%) scale(0.9);
}
}
</style>
</head>
<body>
<div id="loading">Assembling urban section</div>
<div id="hud">
<section id="title-card" class="panel">
<div class="eyebrow">Urban network study · 01</div>
<h1>Central <span>↗</span><br>Mid-Levels</h1>
<p>
A bounded low-poly section following the readable rise from Central
streets to the Mid-Levels, with a short escalator and elevated link.
</p>
<div class="tags">
<span class="tag">Hong Kong</span>
<span class="tag">Steep street</span>
<span class="tag">Urban section</span>
</div>
</section>
<nav id="views" class="panel" aria-label="Camera views">
<button data-view="overview">Overview</button>
<button data-view="central">Central</button>
<button data-view="escalator">Escalator</button>
<button data-view="upper">Mid-Levels</button>
</nav>
<div id="legend" class="panel">
<div class="legend-item">
<span class="swatch" style="background:#425159"></span> Central streets
</div>
<div class="legend-item">
<span class="swatch" style="background:#d55343"></span> Escalator
</div>
<div class="legend-item">
<span class="swatch" style="background:#2d7f82"></span> Elevated link
</div>
<div class="legend-item">
<span class="swatch" style="background:#d6a64f"></span> Upper district
</div>
</div>
<div id="instructions" class="panel">
<span>Drag to orbit · Shift-drag to pan · Scroll to zoom</span>
<button id="reset" type="button">Reset</button>
</div>
<div id="labels"></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, camera and custom orbit/pan/zoom controls
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive Central to Mid-Levels low-poly city model");
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7e0df);
scene.fog = new THREE.Fog(0xd7e0df, 88, 150);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
240
);
const orbit = {
theta: 0.78,
phi: 0.86,
radius: 64,
target: new THREE.Vector3(0, 4, 0)
};
const goal = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius,
target: orbit.target.clone()
};
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
pan: false
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
orbit.theta += (goal.theta - orbit.theta) * 0.11;
orbit.phi += (goal.phi - orbit.phi) * 0.11;
orbit.radius += (goal.radius - orbit.radius) * 0.11;
orbit.target.lerp(goal.target, 0.11);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.pan = event.button === 2 || event.shiftKey;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.pan) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = orbit.radius * 0.0012;
goal.target.addScaledVector(right, -dx * scale);
goal.target.addScaledVector(up, dy * scale);
goal.target.x = clamp(goal.target.x, -27, 27);
goal.target.y = clamp(goal.target.y, 0, 18);
goal.target.z = clamp(goal.target.z, -24, 24);
} else {
goal.theta -= dx * 0.006;
goal.phi = clamp(goal.phi - dy * 0.005, 0.28, 1.38);
}
});
function stopPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
renderer.domElement.addEventListener("pointerup", stopPointer);
renderer.domElement.addEventListener("pointercancel", stopPointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
goal.radius = clamp(
goal.radius * Math.exp(event.deltaY * 0.001),
24,
92
);
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") goal.theta += 0.12;
if (event.key === "ArrowRight") goal.theta -= 0.12;
if (event.key === "ArrowUp") goal.phi = clamp(goal.phi - 0.08, 0.28, 1.38);
if (event.key === "ArrowDown") goal.phi = clamp(goal.phi + 0.08, 0.28, 1.38);
if (event.key === "+" || event.key === "=") goal.radius = clamp(goal.radius - 4, 24, 92);
if (event.key === "-") goal.radius = clamp(goal.radius + 4, 24, 92);
if (event.key.toLowerCase() === "r") setView("overview");
});
const views = {
overview: {
theta: 0.78, phi: 0.86, radius: 64,
target: new THREE.Vector3(0, 4, 0)
},
central: {
theta: 0.62, phi: 1.02, radius: 39,
target: new THREE.Vector3(-5, 3, 13)
},
escalator: {
theta: 0.50, phi: 1.03, radius: 29,
target: new THREE.Vector3(1.5, 3.8, 7)
},
upper: {
theta: 0.80, phi: 0.94, radius: 43,
target: new THREE.Vector3(0, 11, -13)
}
};
function setView(name) {
const view = views[name];
if (!view) return;
goal.theta = view.theta;
goal.phi = view.phi;
goal.radius = view.radius;
goal.target.copy(view.target);
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
document.querySelector("#reset").addEventListener("click", () => setView("overview"));
// -------------------------------------------------------------------------
// Lighting and materials
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf4f2df, 0x73868a, 2.05));
const sun = new THREE.DirectionalLight(0xfff0cf, 3.1);
sun.position.set(-24, 38, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -48;
sun.shadow.camera.right = 48;
sun.shadow.camera.top = 42;
sun.shadow.camera.bottom = -42;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.0003;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x9ac8d0, 0.8);
rim.position.set(24, 14, -30);
scene.add(rim);
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
...extra
});
}
const materials = {
plinth: standard(0x26343a),
plinthEdge: standard(0x526167),
ground: standard(0xc8c2ae),
plateau: standard(0xa7a99f),
plateauTop: standard(0xc9c6b5),
retaining: standard(0x777f79),
retainingBand: standard(0x91978d),
asphalt: standard(0x414d53),
asphaltUpper: standard(0x505c60),
curb: standard(0xd0cbb9),
marking: standard(0xf0ead4),
sidewalk: standard(0xb9b6a7),
link: standard(0x2d7f82, { metalness: 0.25 }),
linkDeck: standard(0x426369),
glass: standard(0xa7d2d0, {
transparent: true,
opacity: 0.32,
roughness: 0.2,
metalness: 0.12,
depthWrite: false
}),
escalator: standard(0xd55343),
escalatorDark: standard(0x343b3d),
escalatorMetal: standard(0x8b9797, { metalness: 0.45 }),
darkWindow: standard(0x263f49, { roughness: 0.32, metalness: 0.15 }),
litWindow: standard(0xffd28b, {
emissive: 0xffa84d,
emissiveIntensity: 1.35,
roughness: 0.4
}),
roof: standard(0x6d7470),
tree: standard(0x637b58),
trunk: standard(0x7b624a),
planter: standard(0x8c8e7d)
};
const palette = [
0xd7cbb8, 0xb9c5c0, 0xc78f78, 0x8fa8ae,
0xd5b263, 0xa6b0a4, 0xe0d8c9, 0xa77c68,
0x9da7af, 0xc3aa91
];
const buildingMaterials = palette.map(color => standard(color));
const unitBox = new THREE.BoxGeometry(1, 1, 1);
let seed = 47;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function box(width, height, depth, material, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function beamBetween(a, b, width, depth, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, length, depth);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function segmentBasis(a, b) {
const zAxis = new THREE.Vector3().subVectors(b, a).normalize();
const xAxis = new THREE.Vector3(0, 1, 0).cross(zAxis).normalize();
const yAxis = new THREE.Vector3().crossVectors(zAxis, xAxis).normalize();
const matrix = new THREE.Matrix4().makeBasis(xAxis, yAxis, zAxis);
const quaternion = new THREE.Quaternion().setFromRotationMatrix(matrix);
return { quaternion, xAxis, yAxis, zAxis };
}
// -------------------------------------------------------------------------
// Bounded base, terraces and retaining walls
// -------------------------------------------------------------------------
box(64, 1.5, 42, materials.plinth, 0, -0.72, 0);
box(64.5, 0.22, 42.5, materials.plinthEdge, 0, -1.52, 0);
box(63.8, 0.25, 41.8, materials.ground, 0, 0.02, 0);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(220, 220),
standard(0xd7e0df, { roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.66;
floor.receiveShadow = true;
scene.add(floor);
// Two upper terraces leave a readable central street canyon.
for (const side of [-1, 1]) {
const centerX = side * 16.65;
box(26.7, 9.35, 14.1, materials.retaining, centerX, 4.67, -14);
box(26.9, 0.28, 14.3, materials.plateauTop, centerX, 9.48, -14);
// Horizontal retaining-wall bands.
for (const y of [2.55, 5.15, 7.75]) {
box(26.85, 0.14, 0.14, materials.retainingBand, centerX, y, -6.88);
}
// Vertical seams and buttresses.
for (let x = 3.9; x < 29.5; x += 3.05) {
const worldX = side * x;
if (worldX * side > 3.15) {
box(0.08, 8.9, 0.09, materials.retainingBand, worldX, 4.6, -6.86);
}
}
}
// -------------------------------------------------------------------------
// Street network
// -------------------------------------------------------------------------
function roadSegment(a, b, width, material = materials.asphalt, markings = true) {
const { quaternion, xAxis } = segmentBasis(a, b);
const length = a.distanceTo(b);
const center = a.clone().add(b).multiplyScalar(0.5);
center.addScaledVector(xAxis, -0.06);
const road = new THREE.Mesh(unitBox, material);
road.scale.set(width, 0.12, length);
road.position.copy(center);
road.quaternion.copy(quaternion);
road.receiveShadow = true;
scene.add(road);
for (const offset of [-width / 2 - 0.09, width / 2 + 0.09]) {
const curbCenter = center.clone().addScaledVector(xAxis, offset);
curbCenter.y += 0.05;
const curb = new THREE.Mesh(unitBox, materials.curb);
curb.scale.set(0.2, 0.24, length);
curb.position.copy(curbCenter);
curb.quaternion.copy(quaternion);
curb.castShadow = true;
curb.receiveShadow = true;
scene.add(curb);
}
if (markings && length > 3) {
const count = Math.max(1, Math.floor(length / 3.4));
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const position = a.clone().lerp(b, t);
position.y += 0.08;
const dash = new THREE.Mesh(unitBox, materials.marking);
dash.scale.set(0.13, 0.025, Math.min(1.35, length * 0.22));
dash.position.copy(position);
dash.quaternion.copy(quaternion);
dash.receiveShadow = true;
scene.add(dash);
}
}
return road;
}
// Lower Central street.
roadSegment(
new THREE.Vector3(-30, 0.25, 14),
new THREE.Vector3(30, 0.25, 14),
4.1
);
// Upper Mid-Levels street.
roadSegment(
new THREE.Vector3(-30, 9.77, -12.2),
new THREE.Vector3(30, 9.77, -12.2),
3.6,
materials.asphaltUpper
);
// Short side streets clarify the network without filling the skyline.
roadSegment(
new THREE.Vector3(-18, 0.25, 14),
new THREE.Vector3(-18, 0.25, 18.4),
2.4,
materials.asphalt,
false
);
roadSegment(
new THREE.Vector3(18, 9.77, -12.2),
new THREE.Vector3(18, 9.77, -18.4),
2.5,
materials.asphaltUpper,
false
);
// The steep route: Central → Pottinger Street → upper terrace.
const steepPoints = [
new THREE.Vector3(0, 0.25, 16.5),
new THREE.Vector3(1.4, 3.45, 9.0),
new THREE.Vector3(-0.7, 6.85, 1.5),
new THREE.Vector3(0, 9.77, -6.8)
];
for (let i = 0; i < steepPoints.length - 1; i++) {
roadSegment(steepPoints[i], steepPoints[i + 1], 5.15);
}
// Flat upper connector over the street canyon.
roadSegment(
new THREE.Vector3(0, 9.77, -6.8),
new THREE.Vector3(0, 9.77, -12.2),
4.2,
materials.asphaltUpper
);
// Bridge structure beneath the upper connector.
box(7.2, 0.36, 5.6, materials.retaining, 0, 9.35, -9.5);
box(0.5, 9.1, 0.5, materials.retaining, -3.5, 4.6, -9.5);
box(0.5, 9.1, 0.5, materials.retaining, 3.5, 4.6, -9.5);
// Zebra crossings.
for (const crossing of [
{ x: 0, y: 0.32, z: 14, horizontal: true },
{ x: 0, y: 9.84, z: -12.2, horizontal: true }
]) {
for (let i = 0; i < 6; i++) {
box(
crossing.horizontal ? 0.42 : 3.0,
0.035,
crossing.horizontal ? 3.0 : 0.42,
materials.marking,
crossing.x + (crossing.horizontal ? (i - 2.5) * 0.67 : 0),
crossing.y,
crossing.z + (crossing.horizontal ? 0 : (i - 2.5) * 0.67),
false
);
}
}
// -------------------------------------------------------------------------
// Facades with instanced windows
// -------------------------------------------------------------------------
const darkWindowMatrices = [];
const litWindowMatrices = [];
function addWindow(position, scale, rotationY, lit) {
const matrix = new THREE.Matrix4();
matrix.compose(
position,
new THREE.Quaternion().setFromEuler(new THREE.Euler(0, rotationY, 0)),
scale
);
(lit ? litWindowMatrices : darkWindowMatrices).push(matrix);
}
function signMaterial(text, background = "#173b45", foreground = "#fff1cf") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 512, 128);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.45;
ctx.strokeRect(7, 7, 498, 114);
ctx.globalAlpha = 1;
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `700 ${text.length > 9 ? 37 : 47}px Arial, sans-serif`;
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.85,
side: THREE.DoubleSide
});
}
function addBuilding({
x, z, width, depth, floors, base = 0.26,
material = 0, face = 1, sign = null
}) {
const group = new THREE.Group();
group.position.set(x, base, z);
scene.add(group);
const height = floors * 1.15;
const body = new THREE.Mesh(unitBox, buildingMaterials[material % buildingMaterials.length]);
body.scale.set(width, height, depth);
body.position.y = height / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const cap = new THREE.Mesh(unitBox, materials.roof);
cap.scale.set(width + 0.22, 0.22, depth + 0.22);
cap.position.y = height + 0.1;
cap.castShadow = true;
group.add(cap);
// Street-facing shopfront.
const shop = new THREE.Mesh(unitBox, materials.darkWindow);
shop.scale.set(width * 0.91, 0.76, 0.11);
shop.position.set(0, 0.53, face * (depth / 2 + 0.055));
group.add(shop);
const awning = new THREE.Mesh(
unitBox,
standard([0xb55743, 0x376e72, 0xbc914c][Math.floor(random() * 3)])
);
awning.scale.set(width * 0.86, 0.13, 0.58);
awning.position.set(0, 1.03, face * (depth / 2 + 0.25));
awning.castShadow = true;
group.add(awning);
if (sign) {
const signMesh = new THREE.Mesh(
new THREE.PlaneGeometry(Math.min(width * 0.72, 3.6), 0.61),
signMaterial(sign)
);
signMesh.position.set(0, 0.62, face * (depth / 2 + 0.12));
if (face < 0) signMesh.rotation.y = Math.PI;
group.add(signMesh);
}
// Front and rear windows.
const columns = Math.max(2, Math.floor(width / 1.15));
const columnSpacing = width / (columns + 1);
for (let floor = 1; floor < floors; floor++) {
const y = base + floor * 1.15 + 0.25;
for (let column = 0; column < columns; column++) {
const wx = -width / 2 + columnSpacing * (column + 1);
for (const side of [-1, 1]) {
addWindow(
new THREE.Vector3(
x + wx,
y,
z + side * (depth / 2 + 0.035)
),
new THREE.Vector3(0.64, 0.58, 0.065),
0,
random() < 0.13
);
}
}
// Side windows.
const sideColumns = Math.max(1, Math.floor(depth / 1.3));
const sideSpacing = depth / (sideColumns + 1);
for (let column = 0; column < sideColumns; column++) {
const wz = -depth / 2 + sideSpacing * (column + 1);
for (const side of [-1, 1]) {
addWindow(
new THREE.Vector3(
x + side * (width / 2 + 0.035),
y,
z + wz
),
new THREE.Vector3(0.065, 0.58, 0.64),
Math.PI / 2,
random() < 0.13
);
}
}
}
// Sparse rooftop service volumes.
if (random() > 0.22) {
const ac = new THREE.Mesh(unitBox, materials.roof);
ac.scale.set(0.75, 0.4, 0.62);
ac.position.set(
x + (random() - 0.5) * width * 0.5,
base + height + 0.4,
z + (random() - 0.5) * depth * 0.4
);
ac.castShadow = true;
scene.add(ac);
}
if (random() > 0.64) {
const tank = new THREE.Mesh(
new THREE.CylinderGeometry(0.42, 0.52, 0.85, 6),
materials.roof
);
tank.position.set(
x + (random() - 0.5) * width * 0.45,
base + height + 0.7,
z + (random() - 0.5) * depth * 0.4
);
tank.castShadow = true;
scene.add(tank);
}
}
const lowerNear = [
[-25.1, 7.0, 5.0, 4.6, 7, 0, "CENTRAL"],
[-19.0, 7.3, 4.6, 4.4, 6, 1, "MARKET"],
[-13.0, 7.0, 5.0, 4.8, 8, 3, "CAFÉ"],
[-7.1, 7.6, 4.3, 4.4, 5, 5, null],
[7.0, 7.4, 4.5, 4.6, 6, 2, "MTR"],
[13.0, 7.0, 5.1, 4.7, 8, 4, "HOTEL"],
[19.1, 7.2, 4.7, 4.5, 6, 6, "BAKERY"],
[25.0, 7.0, 5.0, 4.7, 7, 7, "SHOP"]
];
for (const [x, z, width, depth, floors, material, sign] of lowerNear) {
addBuilding({
x, z, width, depth, floors, material,
face: 1, sign
});
}
const lowerBack = [
[-25, 18.3, 5.0, 2.6, 3, 4],
[-19, 18.3, 4.6, 2.6, 4, 6],
[-13, 18.4, 5.1, 2.5, 3, 2],
[-7, 18.2, 4.6, 2.7, 2, 8],
[7, 18.3, 4.8, 2.5, 3, 3],
[13, 18.3, 5.1, 2.6, 4, 5],
[19, 18.4, 4.7, 2.5, 3, 0],
[25, 18.2, 5.0, 2.7, 4, 7]
];
for (const [x, z, width, depth, floors, material] of lowerBack) {
addBuilding({
x, z, width, depth, floors, material,
face: -1
});
}
const upperNear = [
[-25.0, -8.7, 5.0, 3.6, 5, 6, "半山"],
[-18.8, -8.7, 5.2, 3.7, 7, 1, "HILL"],
[-12.5, -8.6, 5.0, 3.7, 6, 4, "DINER"],
[-6.5, -8.6, 4.5, 3.6, 4, 8, null],
[6.5, -8.6, 4.5, 3.6, 5, 3, "TEA"],
[12.5, -8.7, 5.0, 3.6, 6, 6, "GALLERY"],
[18.8, -8.7, 5.2, 3.7, 7, 2, "HOUSE"],
[25.0, -8.6, 5.0, 3.6, 5, 7, null]
];
for (const [x, z, width, depth, floors, material, sign] of upperNear) {
addBuilding({
x, z, width, depth, floors, material,
base: 9.68, face: -1, sign
});
}
const upperBack = [
[-25, -18.5, 5.0, 2.7, 4, 5],
[-19, -18.5, 4.7, 2.8, 3, 2],
[-13, -18.5, 5.0, 2.7, 5, 8],
[-7, -18.5, 4.5, 2.7, 3, 1],
[7, -18.5, 4.6, 2.8, 4, 7],
[13, -18.5, 5.0, 2.7, 5, 3],
[19, -18.5, 4.7, 2.8, 3, 4],
[25, -18.5, 5.0, 2.7, 4, 0]
];
for (const [x, z, width, depth, floors, material] of upperBack) {
addBuilding({
x, z, width, depth, floors, material,
base: 9.68, face: 1
});
}
function createWindowInstances(matrices, material) {
if (!matrices.length) return;
const mesh = new THREE.InstancedMesh(unitBox, material, matrices.length);
matrices.forEach((matrix, index) => mesh.setMatrixAt(index, matrix));
mesh.instanceMatrix.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
createWindowInstances(darkWindowMatrices, materials.darkWindow);
createWindowInstances(litWindowMatrices, materials.litWindow);
// -------------------------------------------------------------------------
// Short escalator segment
// -------------------------------------------------------------------------
const escalatorA = new THREE.Vector3(2.48, 0.34, 13.8);
const escalatorB = new THREE.Vector3(2.13, 6.97, 1.0);
const stepCount = 27;
for (let i = 0; i < stepCount; i++) {
const t = (i + 0.5) / stepCount;
const position = escalatorA.clone().lerp(escalatorB, t);
position.y -= 0.12;
const step = box(
1.28,
0.28,
(escalatorA.z - escalatorB.z) / stepCount * 1.04,
materials.escalatorDark,
position.x,
position.y,
position.z,
false
);
step.receiveShadow = true;
const tread = box(
1.17,
0.025,
0.14,
materials.escalatorMetal,
position.x,
position.y + 0.15,
position.z + 0.12,
false
);
tread.receiveShadow = true;
}
for (const side of [-1, 1]) {
const offset = new THREE.Vector3(side * 0.76, 0, 0);
const lowerStringer = escalatorA.clone().add(offset);
lowerStringer.y -= 0.06;
const upperStringer = escalatorB.clone().add(offset);
upperStringer.y -= 0.06;
beamBetween(
lowerStringer,
upperStringer,
0.18,
0.26,
materials.escalator
);
const lowerRail = escalatorA.clone().add(offset);
lowerRail.y += 0.92;
const upperRail = escalatorB.clone().add(offset);
upperRail.y += 0.92;
beamBetween(
lowerRail,
upperRail,
0.095,
0.095,
materials.escalator
);
beamBetween(
escalatorA.clone().add(offset),
escalatorB.clone().add(offset),
0.06,
0.07,
materials.escalatorMetal
);
// End handrail returns.
beamBetween(
lowerRail,
escalatorA.clone().add(offset),
0.095,
0.095,
materials.escalator
);
beamBetween(
upperRail,
escalatorB.clone().add(offset),
0.095,
0.095,
materials.escalator
);
}
// Escalator landing and MTR marker.
box(1.8, 0.18, 1.2, materials.escalatorMetal, 2.48, 0.24, 14.0);
box(0.12, 2.2, 0.12, materials.escalator, 3.25, 1.1, 13.5);
const mtrSign = new THREE.Mesh(
new THREE.PlaneGeometry(1.25, 0.42),
signMaterial("MTR", "#d55343", "#fff7df")
);
mtrSign.position.set(3.32, 1.9, 13.44);
mtrSign.rotation.y = Math.PI;
scene.add(mtrSign);
// Moving indicator on the escalator handrail.
const indicator = box(
0.12, 0.12, 0.12,
standard(0xffd06b, { emissive: 0xffa632, emissiveIntensity: 1.4 }),
2.48, 0, 0,
false
);
// -------------------------------------------------------------------------
// Short elevated link crossing the steep street
// -------------------------------------------------------------------------
const linkY = 11.55;
const linkZ = -4.15;
box(29, 0.55, 2.65, materials.linkDeck, 0, linkY - 0.275, linkZ);
box(28.5, 0.075, 2.18, materials.sidewalk, 0, linkY + 0.04, linkZ);
for (const x of [-11.6, -5.25, 5.25, 11.6]) {
box(0.46, 10.75, 0.46, materials.link, x, 5.55, linkZ);
box(1.7, 0.3, 1.25, materials.linkDeck, x, 11.03, linkZ);
}
// Under-deck cross bracing.
for (const x of [-11.6, -5.25, 5.25, 11.6]) {
beamBetween(
new THREE.Vector3(x - 0.8, 8.8, linkZ),
new THREE.Vector3(x + 0.8, 10.95, linkZ),
0.14,
0.14,
materials.link
);
}
for (const side of [-1, 1]) {
const railZ = linkZ + side * 1.18;
box(28.5, 0.68, 0.055, materials.glass, 0, linkY + 0.5, railZ, false);
for (let x = -14; x <= 14; x += 2) {
box(0.08, 0.92, 0.08, materials.link, x, linkY + 0.48, railZ);
}
box(29, 0.09, 0.09, materials.link, 0, linkY + 0.98, railZ);
box(29, 0.06, 0.06, materials.link, 0, linkY + 0.18, railZ);
}
// Small end platforms.
for (const x of [-14.7, 14.7]) {
box(1.2, 0.5, 3.0, materials.linkDeck, x, linkY - 0.25, linkZ);
}
// -------------------------------------------------------------------------
// Street furniture, planters and low-poly trees
// -------------------------------------------------------------------------
function addTree(x, y, z, size = 1) {
box(1.45, 0.36, 1.45, materials.planter, x, y + 0.18, z);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.16, 1.3 * size, 6),
materials.trunk
);
trunk.position.set(x, y + 0.98 * size, z);
trunk.castShadow = true;
scene.add(trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.82 * size, 0),
materials.tree
);
crown.position.set(x, y + 1.95 * size, z);
crown.scale.y = 1.12;
crown.castShadow = true;
scene.add(crown);
}
[
[-28.2, 0.25, 10.8, 0.85],
[27.9, 0.25, 10.5, 0.8],
[-28.2, 9.68, -15.7, 0.85],
[27.8, 9.68, -15.6, 0.78],
[-10.2, 9.68, -15.8, 0.7],
[10.2, 9.68, -15.8, 0.72]
].forEach(values => addTree(...values));
function addLamp(x, y, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotation;
scene.add(group);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.075, 2.5, 6),
materials.escalatorMetal
);
pole.position.y = 1.25;
pole.castShadow = true;
group.add(pole);
const arm = box(0.7, 0.07, 0.07, materials.escalatorMetal, 0.31, 2.43, 0);
const head = box(0.35, 0.12, 0.18, materials.marking, 0.61, 2.39, 0);
head.castShadow = false;
return arm;
}
[
[-16, 0.25, 16.25], [-8, 0.25, 16.25],
[8, 0.25, 16.25], [16, 0.25, 16.25],
[-20, 9.68, -10.25], [20, 9.68, -10.25],
[-24, 9.68, -14.35], [24, 9.68, -14.35]
].forEach(([x, y, z]) => addLamp(x, y, z));
// -------------------------------------------------------------------------
// Low-poly people and vehicles
// -------------------------------------------------------------------------
function createPerson(color) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.15, 0.48, 6),
standard(color)
);
body.position.y = 0.56;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 7, 5),
standard(0xd6aa84)
);
head.position.y = 0.93;
head.castShadow = true;
group.add(head);
const legs = box(0.14, 0.32, 0.12, materials.escalatorDark, 0, 0.18, 0);
group.add(legs);
scene.add(group);
return group;
}
const movingPeople = [];
const personColors = [0x3f7477, 0xb45d4d, 0xc6a556, 0x4e5d77, 0x8c6d52];
for (let i = 0; i < 10; i++) {
const upper = i > 5;
const person = createPerson(personColors[i % personColors.length]);
person.scale.setScalar(0.9 + random() * 0.25);
person.position.set(
-24 + random() * 48,
upper ? 9.72 : 0.28,
upper ? -10.35 : 16.3
);
movingPeople.push({
object: person,
upper,
speed: (upper ? -1 : 1) * (0.65 + random() * 0.4),
offset: random() * 48
});
}
// Static figures on and beside the escalator.
createPerson(0x315f77).position.set(2.45, 3.35, 8.1);
createPerson(0xc45744).position.set(1.8, 0.35, 13.3);
createPerson(0xd0a04a).position.set(4.0, 0.25, 10.0);
function createCar(color, taxi = false) {
const group = new THREE.Group();
const body = new THREE.Mesh(unitBox, standard(color));
body.scale.set(2.45, 0.55, 1.16);
body.position.y = 0.55;
body.castShadow = true;
group.add(body);
const cabin = new THREE.Mesh(unitBox, materials.darkWindow);
cabin.scale.set(1.25, 0.48, 1.03);
cabin.position.set(-0.13, 1.02, 0);
cabin.castShadow = true;
group.add(cabin);
for (const x of [-0.78, 0.78]) {
for (const z of [-0.58, 0.58]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.22, 0.14, 8),
materials.escalatorDark
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.27, z);
group.add(wheel);
}
}
if (taxi) {
box(0.7, 0.19, 0.36, standard(0xffd26c, {
emissive: 0xffae42,
emissiveIntensity: 0.7
}), -0.1, 1.37, 0, false);
}
scene.add(group);
return group;
}
const vehicles = [
{ object: createCar(0xb94f43, true), y: 0.38, z: 13.65, speed: 2.4, offset: -20 },
{ object: createCar(0xd2d6d1), y: 0.38, z: 14.35, speed: -2.0, offset: 12 },
{ object: createCar(0x467b72), y: 9.9, z: -12.2, speed: 1.8, offset: -8 },
{ object: createCar(0xd2a044, true), y: 9.9, z: -11.95, speed: -1.7, offset: 10 }
];
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const labelContainer = document.querySelector("#labels");
const labelDefinitions = [
{
anchor: new THREE.Vector3(-14, 5.1, 14),
title: "Central / 中環",
subtitle: "Lower street network",
className: ""
},
{
anchor: new THREE.Vector3(-13, 16.0, -13),
title: "Mid-Levels / 半山",
subtitle: "Upper terrace",
className: "gold"
},
{
anchor: new THREE.Vector3(-3.9, 7.4, 3.1),
title: "Pottinger Street",
subtitle: "Steep urban rise",
className: ""
},
{
anchor: new THREE.Vector3(2.5, 7.9, 6.2),
title: "Mid-Levels Escalator",
subtitle: "Short segment",
className: "red"
},
{
anchor: new THREE.Vector3(8.5, 14.0, -4.1),
title: "Elevated Link",
subtitle: "Cross-street connection",
className: "teal"
}
];
const labels = labelDefinitions.map(definition => {
const element = document.createElement("div");
element.className = `scene-label ${definition.className}`;
element.innerHTML = `
<strong>${definition.title}</strong>
<small>${definition.subtitle}</small>
`;
labelContainer.appendChild(element);
return { ...definition, element };
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
labels.forEach(label => {
projected.copy(label.anchor).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
label.element.style.opacity = visible ? "1" : "0";
});
}
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
vehicles.forEach(vehicle => {
const span = 62;
const raw = ((vehicle.offset + elapsed * vehicle.speed) % span + span) % span;
vehicle.object.position.x = -31 + raw;
vehicle.object.position.y = vehicle.y;
vehicle.object.position.z = vehicle.z;
});
movingPeople.forEach(person => {
const span = 48;
const raw = ((person.offset + elapsed * person.speed) % span + span) % span;
person.object.position.x = -24 + raw;
person.object.position.y = person.upper ? 9.72 : 0.28;
person.object.position.z = person.upper ? -10.35 : 16.3;
person.object.rotation.y = person.speed > 0 ? Math.PI / 2 : -Math.PI / 2;
});
const escalatorT = (elapsed * 0.055) % 1;
indicator.position.lerpVectors(escalatorA, escalatorB, escalatorT);
indicator.position.y += 1.01;
indicator.position.x += 0.82;
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```