Prompt specification
Build or customize the Three.js 3D scene "Commuter transferring from escalator to a side street" 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: Commuter transferring from escalator to a side street
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/commuter-transferring-from-escalator-to-a-side-street-x2986
Scene Description Prompt:
A voxel commuter leaves Hong Kong's Mid-Levels escalator and turns into a narrow side street. Build one HTML scene using Three.js from cdnjs.
Working Three.js Starter (commuter-transferring-from-escalator-to-a-side-street-x2986):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mid-Levels — A Voxel Commute</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #111b28;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: #f7f1e5;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.6);
}
.title {
position: absolute;
top: clamp(20px, 4vw, 48px);
left: clamp(20px, 4vw, 52px);
max-width: min(440px, calc(100vw - 40px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #ffcf68;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: #ffcf68;
box-shadow: 0 0 14px #ffcf68;
}
h1 {
margin: 0;
font-size: clamp(30px, 5vw, 62px);
font-weight: 850;
line-height: 0.95;
letter-spacing: -0.055em;
}
h1 span {
display: block;
margin-top: 7px;
color: #9ed8e8;
font-size: 0.46em;
font-weight: 650;
letter-spacing: 0.04em;
}
.caption {
position: absolute;
right: clamp(18px, 4vw, 48px);
bottom: clamp(18px, 4vw, 40px);
width: min(340px, calc(100vw - 36px));
padding: 16px 18px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 12px;
background: rgba(13, 22, 34, 0.62);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.caption strong {
display: block;
margin-bottom: 5px;
color: #ffcf68;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.caption p {
margin: 0;
color: rgba(255, 255, 255, 0.78);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: absolute;
bottom: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 52px);
color: rgba(255, 255, 255, 0.63);
font-size: 11px;
line-height: 1.7;
letter-spacing: 0.035em;
}
.controls b {
color: rgba(255, 255, 255, 0.93);
font-weight: 650;
}
.route {
position: absolute;
top: clamp(22px, 4vw, 48px);
right: clamp(20px, 4vw, 48px);
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 999px;
background: rgba(13, 22, 34, 0.55);
color: rgba(255, 255, 255, 0.74);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.route i {
width: 7px;
height: 7px;
border-radius: 50%;
background: #ffcf68;
box-shadow: 0 0 12px #ffcf68;
animation: pulse 1.8s infinite;
}
@keyframes pulse {
50% {
opacity: 0.35;
transform: scale(0.75);
}
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #111b28;
color: #ffcf68;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 0.5s ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.caption {
display: none;
}
.route {
top: auto;
right: 18px;
bottom: 20px;
}
.controls {
max-width: 55%;
}
}
</style>
</head>
<body>
<div id="loading">Building the neighborhood…</div>
<div class="hud">
<header class="title">
<div class="eyebrow">Hong Kong · 22:16</div>
<h1>
Mid-Levels
<span>Escalator to side street</span>
</h1>
</header>
<div class="route">
<i></i>
Live voxel commute
</div>
<div class="controls">
<b>Drag</b> orbit · <b>Scroll / pinch</b> zoom<br>
<b>Right-drag</b> pan · <b>Arrows</b> move
</div>
<aside class="caption">
<strong>Scene 01 / The last turn</strong>
<p>
A commuter rides the Mid-Levels escalator, steps into the humid evening,
and turns into one of the city’s narrow, illuminated side streets.
</p>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x172334);
scene.fog = new THREE.Fog(0x172334, 29, 66);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel scene of Hong Kong's Mid-Levels escalator and side street"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0x9cc7df, 0x403526, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffc98f, 3.25);
sun.position.set(-15, 27, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -34;
sun.shadow.camera.right = 34;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x6fb6df, 0.8);
coolFill.position.set(18, 12, -18);
scene.add(coolFill);
// ------------------------------------------------------------
// Shared voxel geometry and materials
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, emissive = false) {
const key = `${color}-${emissive}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: emissive ? 0.48 : 0.84,
metalness: emissive ? 0.05 : 0.025,
emissive: emissive ? color : 0x000000,
emissiveIntensity: emissive ? 1.35 : 0
})
);
}
return materialCache.get(key);
}
function box(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
overrideMaterial = null
) {
const mesh = new THREE.Mesh(
unitBox,
overrideMaterial || material(color)
);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = width * height * depth > 0.12;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const up = new THREE.Vector3(0, 1, 0);
function beam(
parent,
start,
end,
width,
depth,
color,
overrideMaterial = null
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = box(
parent,
width,
length,
depth,
color,
(a.x + b.x) / 2,
(a.y + b.y) / 2,
(a.z + b.z) / 2,
overrideMaterial
);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
return mesh;
}
let randomSeed = 94127;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
// ------------------------------------------------------------
// Canvas-generated signage
// ------------------------------------------------------------
function sign(
parent,
title,
subtitle = "",
x = 0,
y = 0,
z = 0,
width = 3,
height = 0.9,
options = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
const background = options.background || "#c82935";
const foreground = options.foreground || "#fff5d8";
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = options.border || "rgba(255,255,255,.48)";
context.lineWidth = 10;
context.strokeRect(16, 16, canvas.width - 32, canvas.height - 32);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = foreground;
context.font = `800 ${subtitle ? 78 : 96}px "Microsoft JhengHei", "Noto Sans CJK TC", sans-serif`;
context.fillText(title, 512, subtitle ? 104 : 132, 940);
if (subtitle) {
context.fillStyle = options.subColor || foreground;
context.font = '600 38px Inter, Arial, sans-serif';
context.fillText(subtitle, 512, 181, 930);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
transparent: !!options.transparent
})
);
mesh.position.set(x, y, z);
mesh.rotation.y = options.rotationY || 0;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground, streets and raised escalator approach
// ------------------------------------------------------------
const ground = box(scene, 46, 0.35, 42, 0x313a3d, 0, -0.28, -2);
ground.receiveShadow = true;
box(scene, 6.1, 0.08, 19.2, 0x252d32, -2.8, -0.03, -6.4);
box(scene, 15.2, 0.09, 3.8, 0x293138, 5.8, 0.02, 1.5);
// Main-road paving and sidewalk blocks.
box(scene, 1.15, 0.18, 18.2, 0x566064, -5.48, 0.03, -6.7);
box(scene, 1.15, 0.18, 18.2, 0x566064, 0.04, 0.03, -6.7);
// Alley pavement.
box(scene, 15.8, 0.18, 0.55, 0x6b706b, 5.7, 0.02, -0.12);
box(scene, 15.8, 0.18, 0.55, 0x6b706b, 5.7, 0.02, 3.13);
// Painted road marks.
for (let i = 0; i < 6; i++) {
box(
scene,
0.12,
0.025,
0.95,
0xe2c572,
-5.0,
0.035,
-13.5 + i * 2.55
);
}
// Drain grates.
for (const z of [-9, -3, 3]) {
box(scene, 0.8, 0.035, 0.36, 0x171d20, -0.25, 0.06, z);
for (let i = 0; i < 4; i++) {
box(
scene,
0.045,
0.04,
0.29,
0x6e7778,
-0.53 + i * 0.19,
0.075,
z
);
}
}
// Upper approach.
box(scene, 6.2, 0.42, 5.8, 0x555b5b, -2.8, 5.0, -11.7);
box(scene, 6.2, 0.12, 5.8, 0x696d69, -2.8, 5.24, -11.7);
box(scene, 6.2, 4.9, 0.45, 0x4b5253, -2.8, 2.65, -14.35);
// ------------------------------------------------------------
// Voxel buildings
// ------------------------------------------------------------
function building({
x,
z,
w,
d,
h,
color,
windowColor = 0x344d59,
roofColor = 0x343c40
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(group, w, h, d, color, 0, h / 2, 0);
box(group, w + 0.16, 0.22, d + 0.16, roofColor, 0, h + 0.1, 0);
// Front windows, facing positive Z.
const frontColumns = Math.max(2, Math.floor(w / 1.55));
const frontSpacing = w / (frontColumns + 1);
for (let row = 0; row < Math.floor((h - 1.4) / 2); row++) {
const y = 1.6 + row * 2;
for (let column = 0; column < frontColumns; column++) {
const lit = random() > 0.68;
box(
group,
0.62,
0.76,
0.055,
lit ? 0xffd28a : windowColor,
-w / 2 + frontSpacing * (column + 1),
y,
d / 2 + 0.035,
lit ? material(0xffd28a, true) : null
);
}
}
// Right-side windows.
const sideColumns = Math.max(2, Math.floor(d / 1.65));
const sideSpacing = d / (sideColumns + 1);
for (let row = 0; row < Math.floor((h - 1.4) / 2); row++) {
const y = 1.6 + row * 2;
for (let column = 0; column < sideColumns; column++) {
const lit = random() > 0.72;
box(
group,
0.055,
0.72,
0.62,
lit ? 0xffcf7d : windowColor,
w / 2 + 0.035,
y,
-d / 2 + sideSpacing * (column + 1),
lit ? material(0xffcf7d, true) : null
);
}
}
// Rooftop utility blocks and water tanks.
box(group, 1.3, 0.65, 1.0, 0x69716f, -w * 0.22, h + 0.48, d * 0.13);
box(group, 1.0, 0.85, 0.9, 0x6d6256, w * 0.25, h + 0.55, -d * 0.2);
box(group, 0.09, 2.1, 0.09, 0x353e41, w * 0.34, h + 1.1, d * 0.26);
// Wall-mounted air conditioners.
const airConditionerCount = Math.floor(h / 5);
for (let i = 0; i < airConditionerCount; i++) {
const side = i % 2 === 0 ? -1 : 1;
box(
group,
0.72,
0.5,
0.42,
0xa4aaa3,
side * (w / 2 - 0.4),
2.7 + i * 4.2,
d / 2 + 0.22
);
box(
group,
0.48,
0.32,
0.03,
0x465154,
side * (w / 2 - 0.4),
2.7 + i * 4.2,
d / 2 + 0.44
);
}
return group;
}
const westTower = building({
x: -9.2,
z: -6.2,
w: 7,
d: 20,
h: 14.5,
color: 0x505c61
});
const westLow = building({
x: -9.2,
z: 7.2,
w: 7,
d: 7.2,
h: 9.5,
color: 0x666b66
});
const upperEast = building({
x: 2.2,
z: -9.1,
w: 6.1,
d: 10.8,
h: 18,
color: 0x555d60,
windowColor: 0x30444e
});
const alleyNorth = building({
x: 5.3,
z: -2.3,
w: 11.1,
d: 3.8,
h: 11.4,
color: 0x66625b,
windowColor: 0x324853
});
const alleySouth = building({
x: 6.4,
z: 5.4,
w: 14,
d: 4,
h: 7.4,
color: 0x596568,
windowColor: 0x304550
});
const endBlock = building({
x: 14.5,
z: 1.5,
w: 4.2,
d: 7.3,
h: 10.5,
color: 0x4b575c
});
// A few projecting balconies.
for (let i = 0; i < 5; i++) {
box(
alleyNorth,
1.45,
0.13,
0.78,
0x8b8980,
-3.8 + i * 2.05,
3.25 + (i % 2) * 3.8,
2.13
);
box(
alleyNorth,
1.45,
0.55,
0.08,
0x555d5b,
-3.8 + i * 2.05,
3.48 + (i % 2) * 3.8,
2.5
);
}
// Drainpipes.
beam(alleyNorth, [-0.02, 0.2, 1.98], [-0.02, 11.2, 1.98], 0.12, 0.12, 0x30383a);
beam(alleySouth, [12.9, 0.2, -1.94], [12.9, 7.2, -1.94], 0.12, 0.12, 0x30383a);
// ------------------------------------------------------------
// Escalator
// ------------------------------------------------------------
const escalator = new THREE.Group();
scene.add(escalator);
const escalatorX = -2.8;
const topZ = -8.7;
const bottomZ = -0.2;
const topY = 5.15;
const bottomY = 0.2;
const stepCount = 24;
for (let i = 0; i < stepCount; i++) {
const p = i / (stepCount - 1);
const z = THREE.MathUtils.lerp(topZ, bottomZ, p);
const y = THREE.MathUtils.lerp(topY, bottomY, p);
box(escalator, 2.15, 0.21, 0.53, 0x8a9393, escalatorX, y, z);
box(
escalator,
2.08,
0.055,
0.07,
0xe6bd4e,
escalatorX,
y + 0.13,
z + 0.225
);
}
// Bottom landing.
box(escalator, 2.8, 0.22, 1.7, 0x828b89, escalatorX, 0.08, 0.58);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x9bd5dc,
transparent: true,
opacity: 0.24,
roughness: 0.24,
metalness: 0.12,
depthWrite: false,
side: THREE.DoubleSide
});
for (const side of [-1, 1]) {
const x = escalatorX + side * 1.22;
beam(
escalator,
[x, topY + 0.35, topZ],
[x, bottomY + 0.35, bottomZ],
0.09,
0.8,
0x9bd5dc,
glassMaterial
);
beam(
escalator,
[x, topY + 0.88, topZ],
[x, bottomY + 0.88, bottomZ],
0.17,
0.17,
0xb82f37
);
beam(
escalator,
[x, topY + 0.05, topZ],
[x, bottomY + 0.05, bottomZ],
0.16,
0.16,
0x424b4c
);
}
// Escalator supports.
for (const z of [-7.5, -4.9, -2.2]) {
const p = (z - topZ) / (bottomZ - topZ);
const y = THREE.MathUtils.lerp(topY, bottomY, p);
box(escalator, 0.22, y, 0.22, 0x485153, escalatorX - 1.05, y / 2, z);
box(escalator, 0.22, y, 0.22, 0x485153, escalatorX + 1.05, y / 2, z);
}
// Direction lights.
const motionLights = [];
for (let i = 0; i < 8; i++) {
const light = box(
escalator,
0.11,
0.07,
0.2,
0xffb83f,
escalatorX + 1.22,
6,
topZ,
material(0xffb83f, true)
);
motionLights.push(light);
}
// Escalator entrance sign and posts.
box(escalator, 0.11, 2.4, 0.11, 0x343d40, -4.18, 6.35, -9.1);
box(escalator, 0.11, 2.4, 0.11, 0x343d40, -1.42, 6.35, -9.1);
sign(
escalator,
"中環 MID-LEVELS",
"ESCALATOR ↑ CENTRAL",
-2.8,
7.32,
-9.04,
4.4,
1.02,
{
background: "#b52d38",
foreground: "#fff3ce",
subColor: "#ffd978"
}
);
// ------------------------------------------------------------
// Alley storefronts, awnings, signs and lights
// ------------------------------------------------------------
// Dark shop windows on the north side.
for (let i = 0; i < 4; i++) {
box(
alleyNorth,
1.5,
1.45,
0.08,
0x1d3138,
-3.4 + i * 2.25,
1.25,
1.94
);
}
// Red and cream striped awning.
for (let i = 0; i < 8; i++) {
box(
scene,
0.56,
0.12,
0.78,
i % 2 === 0 ? 0xb92d38 : 0xe7d9b8,
0.75 + i * 0.56,
2.55,
-0.03
);
}
sign(
scene,
"士多 CORNER",
"ICE COLD BEER · INSTANT NOODLES",
3.15,
3.25,
-0.34,
3.8,
0.92,
{
background: "#173a49",
foreground: "#75e6eb",
subColor: "#ffdb70"
}
);
sign(
scene,
"24H",
"OPEN",
9.6,
3.05,
-0.34,
1.55,
0.72,
{
background: "#8c2632",
foreground: "#ffe6a4"
}
);
// Vertical-looking projecting sign made from stacked cubes.
box(scene, 0.18, 3.3, 0.18, 0x283438, 10.9, 4.1, 0.5);
for (let i = 0; i < 4; i++) {
box(
scene,
1.15,
0.65,
0.18,
i % 2 ? 0xdd3d48 : 0xf4dca8,
10.9,
2.95 + i * 0.72,
0.72,
i % 2 ? material(0xdd3d48, true) : material(0xf4dca8, true)
);
}
function streetLamp(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(group, 0.11, 2.75, 0.11, 0x30383b, 0, 1.37, 0);
box(group, 0.75, 0.09, 0.11, 0x30383b, 0.31, 2.7, 0);
box(
group,
0.38,
0.15,
0.25,
0xffd17b,
0.63,
2.62,
0,
material(0xffd17b, true)
);
const pool = new THREE.Mesh(
new THREE.CircleGeometry(1.2, 16),
new THREE.MeshBasicMaterial({
color: 0xffc96d,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
pool.rotation.x = -Math.PI / 2;
pool.position.set(0.63, 0.09, 0);
group.add(pool);
}
streetLamp(0.25, 2.65, Math.PI);
streetLamp(5.6, -0.02, 0);
streetLamp(11.1, 2.78, Math.PI);
// Laundry line across the alley.
beam(
scene,
[1.7, 5.25, 0.35],
[10.2, 5.45, 0.35],
0.025,
0.025,
0x1f292c
);
const laundryColors = [0xe5e1cf, 0x5da9c5, 0xd45762, 0xe0ad4e];
for (let i = 0; i < 7; i++) {
const x = 2.1 + i * 1.17;
const y = 5.25 + (x - 1.7) / 8.5 * 0.2 - 0.55;
box(
scene,
0.54,
0.75,
0.08,
laundryColors[i % laundryColors.length],
x,
y,
0.35
);
}
// Small string lights.
for (let i = 0; i < 13; i++) {
const x = 1.4 + i * 0.7;
const y = 6.15 - Math.sin((i / 12) * Math.PI) * 0.65;
box(
scene,
0.11,
0.11,
0.11,
i % 2 ? 0xffc867 : 0x68dbe5,
x,
y,
0.1,
material(i % 2 ? 0xffc867 : 0x68dbe5, true)
);
}
// ------------------------------------------------------------
// Street objects
// ------------------------------------------------------------
// Waste bins.
for (let i = 0; i < 3; i++) {
const x = 1.0 + i * 0.56;
box(scene, 0.48, 0.86, 0.48, i === 1 ? 0x386d55 : 0x3e5360, x, 0.48, 2.58);
box(scene, 0.53, 0.1, 0.53, 0x263337, x, 0.95, 2.58);
}
// Crates and sacks.
box(scene, 0.85, 0.65, 0.75, 0x9a6b3e, 11.65, 0.38, 2.67);
box(scene, 0.72, 0.55, 0.65, 0x765035, 11.68, 1.0, 2.67);
box(scene, 0.62, 0.42, 0.6, 0x4c514b, 0.15, 0.28, 2.55);
// Parked voxel scooter.
const scooter = new THREE.Group();
scooter.position.set(8.0, 0, 2.42);
scooter.rotation.y = -0.12;
scene.add(scooter);
box(scooter, 0.36, 0.42, 1.18, 0xda3d49, 0, 0.42, 0);
box(scooter, 0.32, 0.18, 0.7, 0x22282a, 0, 0.7, -0.08);
box(scooter, 0.58, 0.08, 0.14, 0x242a2c, 0, 0.92, 0.48);
box(scooter, 0.1, 0.62, 0.1, 0x30383a, 0, 0.85, 0.52);
box(scooter, 0.1, 0.52, 0.1, 0x30383a, 0, 0.7, -0.5);
box(scooter, 0.08, 0.08, 0.65, 0x30383a, 0, 1.16, 0.52);
box(scooter, 0.42, 0.26, 0.42, 0x202628, 0, 0.22, 0.38);
box(scooter, 0.42, 0.26, 0.42, 0x202628, 0, 0.22, -0.43);
// Potted plant.
box(scene, 0.55, 0.55, 0.55, 0x9b6441, 12.3, 0.33, 0.1);
box(scene, 0.08, 0.8, 0.08, 0x365c3b, 12.3, 0.9, 0.1);
box(scene, 0.6, 0.2, 0.32, 0x477348, 12.08, 1.25, 0.1);
box(scene, 0.55, 0.18, 0.3, 0x5b884e, 12.5, 1.48, 0.1);
// Shallow puddles reflecting the evening light.
box(
scene,
1.6,
0.018,
0.55,
0x426879,
4.6,
0.083,
2.34,
new THREE.MeshStandardMaterial({
color: 0x426879,
roughness: 0.15,
metalness: 0.4,
transparent: true,
opacity: 0.55
})
);
// ------------------------------------------------------------
// Iconic red Hong Kong minibus on the upper approach
// ------------------------------------------------------------
const minibus = new THREE.Group();
minibus.position.set(-3.25, 5.3, -12.1);
minibus.rotation.y = 0.06;
scene.add(minibus);
box(minibus, 1.65, 1.18, 3.35, 0xb72431, 0, 0.78, 0);
box(minibus, 1.58, 0.72, 2.3, 0xc9333d, 0, 1.62, -0.1);
box(minibus, 1.42, 0.48, 0.07, 0x1d343d, 0, 1.66, 1.08);
box(minibus, 0.07, 0.48, 1.85, 0x21343b, 0.84, 1.63, -0.25);
box(minibus, 0.07, 0.48, 1.85, 0x21343b, -0.84, 1.63, -0.25);
box(minibus, 1.75, 0.18, 0.16, 0xe4d7b4, 0, 0.43, 1.75);
box(minibus, 0.36, 0.16, 0.05, 0xffe6a3, -0.5, 0.72, 1.71, material(0xffe6a3, true));
box(minibus, 0.36, 0.16, 0.05, 0xffe6a3, 0.5, 0.72, 1.71, material(0xffe6a3, true));
box(minibus, 0.44, 0.44, 0.3, 0x202628, -0.83, 0.26, 1.05);
box(minibus, 0.44, 0.44, 0.3, 0x202628, 0.83, 0.26, 1.05);
box(minibus, 0.44, 0.44, 0.3, 0x202628, -0.83, 0.26, -1.05);
box(minibus, 0.44, 0.44, 0.3, 0x202628, 0.83, 0.26, -1.05);
// ------------------------------------------------------------
// Voxel commuter
// Local forward direction is positive Z.
// ------------------------------------------------------------
const commuter = new THREE.Group();
scene.add(commuter);
const skin = 0xd69b73;
const jacket = 0x327f9b;
const trousers = 0x25334d;
const backpack = 0xe2aa3c;
function characterPart(parent, w, h, d, color, x, y, z) {
const mesh = box(parent, w, h, d, color, x, y, z);
mesh.castShadow = true;
return mesh;
}
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.17, 0.65, 0);
rightLeg.position.set(0.17, 0.65, 0);
commuter.add(leftLeg, rightLeg);
characterPart(leftLeg, 0.25, 0.58, 0.27, trousers, 0, -0.27, 0);
characterPart(rightLeg, 0.25, 0.58, 0.27, trousers, 0, -0.27, 0);
characterPart(leftLeg, 0.29, 0.16, 0.43, 0xe8e1cf, 0, -0.57, 0.08);
characterPart(rightLeg, 0.29, 0.16, 0.43, 0xe8e1cf, 0, -0.57, 0.08);
characterPart(commuter, 0.68, 0.64, 0.38, jacket, 0, 0.93, 0);
characterPart(commuter, 0.72, 0.09, 0.4, 0x244f63, 0, 1.2, 0);
characterPart(commuter, 0.18, 0.15, 0.18, skin, 0, 1.32, 0);
characterPart(commuter, 0.48, 0.48, 0.45, skin, 0, 1.57, 0);
characterPart(commuter, 0.51, 0.16, 0.48, 0x24252c, 0, 1.8, -0.01);
characterPart(commuter, 0.06, 0.07, 0.035, 0x15191c, -0.11, 1.61, 0.238);
characterPart(commuter, 0.06, 0.07, 0.035, 0x15191c, 0.11, 1.61, 0.238);
// Backpack and straps.
characterPart(commuter, 0.5, 0.54, 0.24, backpack, 0, 0.98, -0.29);
characterPart(commuter, 0.31, 0.2, 0.05, 0xb87826, 0, 0.92, -0.425);
characterPart(commuter, 0.08, 0.48, 0.08, 0x735b32, -0.22, 1.08, -0.19);
characterPart(commuter, 0.08, 0.48, 0.08, 0x735b32, 0.22, 1.08, -0.19);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.42, 1.16, 0);
rightArm.position.set(0.42, 1.16, 0);
commuter.add(leftArm, rightArm);
characterPart(leftArm, 0.2, 0.52, 0.22, jacket, 0, -0.23, 0);
characterPart(rightArm, 0.2, 0.52, 0.22, jacket, 0, -0.23, 0);
characterPart(leftArm, 0.18, 0.18, 0.18, skin, 0, -0.55, 0.01);
characterPart(rightArm, 0.18, 0.18, 0.18, skin, 0, -0.55, 0.01);
// A softly glowing route marker under the walker.
const routeMarker = new THREE.Mesh(
new THREE.CircleGeometry(0.42, 20),
new THREE.MeshBasicMaterial({
color: 0xffcf68,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
routeMarker.rotation.x = -Math.PI / 2;
commuter.add(routeMarker);
routeMarker.position.y = 0.015;
const COMMUTE_CYCLE = 24;
function updateCommuter(time) {
const t = time % COMMUTE_CYCLE;
let x;
let y;
let z;
let yaw = 0;
let walking = false;
if (t < 13) {
// Down the escalator.
const p = t / 13;
x = escalatorX;
y = THREE.MathUtils.lerp(5.23, 0.15, p);
z = THREE.MathUtils.lerp(-8.45, -0.15, p);
} else if (t < 15) {
// Step off and make the turn into the side street.
const p = (t - 13) / 2;
const eased = p * p * (3 - 2 * p);
x = THREE.MathUtils.lerp(escalatorX, -1.1, eased);
z = THREE.MathUtils.lerp(-0.15, 1.52, eased);
y = 0.11;
yaw = Math.atan2(1.7, 1.67);
walking = true;
} else if (t < 22) {
// Continue east along the narrow street.
const p = (t - 15) / 7;
x = THREE.MathUtils.lerp(-1.1, 6.3, p);
z = 1.52;
y = 0.1;
yaw = Math.PI / 2;
walking = true;
} else {
x = 6.3;
z = 1.52;
y = 0.1;
yaw = Math.PI / 2;
}
commuter.visible = t < 23.25;
commuter.position.set(x, y, z);
// Smooth the turn rather than snapping between headings.
const currentYaw = commuter.rotation.y;
let yawDifference = yaw - currentYaw;
while (yawDifference > Math.PI) yawDifference -= Math.PI * 2;
while (yawDifference < -Math.PI) yawDifference += Math.PI * 2;
commuter.rotation.y += yawDifference * 0.18;
const stride = walking ? Math.sin(t * 12.5) : 0;
leftLeg.rotation.x = stride * 0.62;
rightLeg.rotation.x = -stride * 0.62;
leftArm.rotation.x = -stride * 0.48;
rightArm.rotation.x = stride * 0.48;
if (walking) {
commuter.position.y += Math.abs(Math.sin(t * 12.5)) * 0.035;
}
routeMarker.material.opacity = 0.1 + Math.sin(time * 3) * 0.035;
}
// ------------------------------------------------------------
// Custom camera controls — no addon imports
// ------------------------------------------------------------
const cameraState = {
theta: 0.69,
phi: 0.92,
radius: 28.5,
target: new THREE.Vector3(0.4, 2.1, -1.3),
desiredTheta: 0.69,
desiredPhi: 0.92,
desiredRadius: 28.5,
desiredTarget: new THREE.Vector3(0.4, 2.1, -1.3)
};
const pointerMap = new Map();
let activeButton = 0;
let lastPinchDistance = 0;
const clamp = THREE.MathUtils.clamp;
function updateCamera(immediate = false) {
const lerpAmount = immediate ? 1 : 0.12;
cameraState.theta +=
(cameraState.desiredTheta - cameraState.theta) * lerpAmount;
cameraState.phi +=
(cameraState.desiredPhi - cameraState.phi) * lerpAmount;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * lerpAmount;
cameraState.target.lerp(cameraState.desiredTarget, lerpAmount);
const sinPhi = Math.sin(cameraState.phi);
const offset = new THREE.Vector3(
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.radius * Math.cos(cameraState.phi),
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.desiredTheta = 0.69;
cameraState.desiredPhi = 0.92;
cameraState.desiredRadius = 28.5;
cameraState.desiredTarget.set(0.4, 2.1, -1.3);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
activeButton = event.button;
if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointerMap.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 2) {
const points = [...pointerMap.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
cameraState.desiredRadius = clamp(
cameraState.desiredRadius * (lastPinchDistance / distance),
12,
48
);
}
lastPinchDistance = distance;
return;
}
if (activeButton === 2 || event.shiftKey) {
// Pan across the camera's local right and up axes.
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const cameraUp = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = cameraState.radius * 0.0015;
cameraState.desiredTarget.addScaledVector(right, -dx * panScale);
cameraState.desiredTarget.addScaledVector(cameraUp, dy * panScale);
cameraState.desiredTarget.x = clamp(
cameraState.desiredTarget.x,
-14,
18
);
cameraState.desiredTarget.y = clamp(
cameraState.desiredTarget.y,
-1,
14
);
cameraState.desiredTarget.z = clamp(
cameraState.desiredTarget.z,
-18,
16
);
} else {
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = clamp(
cameraState.desiredPhi - dy * 0.005,
0.3,
1.35
);
}
});
function releasePointer(event) {
pointerMap.delete(event.pointerId);
if (pointerMap.size < 2) {
lastPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"pointerleave",
(event) => {
if (event.buttons === 0) releasePointer(event);
}
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
12,
48
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
const step = 0.08;
switch (event.key) {
case "ArrowLeft":
cameraState.desiredTheta += step;
break;
case "ArrowRight":
cameraState.desiredTheta -= step;
break;
case "ArrowUp":
cameraState.desiredPhi = clamp(
cameraState.desiredPhi - step * 0.5,
0.3,
1.35
);
break;
case "ArrowDown":
cameraState.desiredPhi = clamp(
cameraState.desiredPhi + step * 0.5,
0.3,
1.35
);
break;
case "+":
case "=":
cameraState.desiredRadius = clamp(
cameraState.desiredRadius - 1,
12,
48
);
break;
case "-":
cameraState.desiredRadius = clamp(
cameraState.desiredRadius + 1,
12,
48
);
break;
case "r":
case "R":
resetCamera();
break;
}
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
updateCamera();
updateCommuter(elapsed);
for (let i = 0; i < motionLights.length; i++) {
const p = (elapsed * 0.17 + i / motionLights.length) % 1;
motionLights[i].position.z = THREE.MathUtils.lerp(
topZ,
bottomZ,
p
);
motionLights[i].position.y =
THREE.MathUtils.lerp(topY, bottomY, p) + 0.96;
}
renderer.render(scene, camera);
}
updateCamera(true);
updateCommuter(0);
renderer.render(scene, camera);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("done");
});
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```