Prompt specification
Build or customize the Three.js 3D scene "Pedestrians moving between stair and tunnel entrance" 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: Pedestrians moving between stair and tunnel entrance
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pedestrians-moving-between-stair-and-tunnel-entrance-x2738
Scene Description Prompt:
Voxel pedestrians navigate Guanajuato's hillside stairs beside a lower tunnel entrance, keeping road and walking levels distinct. Standalone HTML with Three.js from cdnjs.
Working Three.js Starter (pedestrians-moving-between-stair-and-tunnel-entrance-x2738):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Guanajuato — Between Levels</title>
<style>
:root {
--ink: #263a3a;
--paper: #fff4dc;
--road: #466267;
--walk: #d8684f;
--line: rgba(38, 58, 58, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfaa78;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 1px 20px rgba(255, 238, 205, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
content: "";
background: var(--walk);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(35px, 5vw, 66px);
font-weight: 500;
line-height: 0.91;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 315px;
margin: 15px 0 0;
font-size: 12px;
font-weight: 600;
line-height: 1.55;
opacity: 0.78;
}
.legend {
position: fixed;
top: 28px;
right: 28px;
display: grid;
gap: 9px;
padding: 12px;
border: 1px solid rgba(255, 244, 220, 0.45);
border-radius: 12px;
background: rgba(255, 244, 220, 0.68);
box-shadow: 0 10px 30px rgba(67, 42, 27, 0.1);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-swatch {
width: 23px;
height: 7px;
border-radius: 1px;
}
.legend-swatch.road {
background: var(--road);
}
.legend-swatch.walk {
background: var(--walk);
}
.world-label {
position: fixed;
z-index: 5;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 7px;
background: rgba(34, 52, 53, 0.88);
box-shadow: 0 8px 20px rgba(38, 31, 24, 0.16);
color: #fff5df;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 160ms ease;
}
.world-label::after {
position: absolute;
bottom: -15px;
left: 50%;
width: 1px;
height: 15px;
content: "";
background: rgba(34, 52, 53, 0.8);
}
.world-label .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #f0a34c;
box-shadow: 0 0 0 3px rgba(240, 163, 76, 0.18);
}
.world-label.walk-label .dot {
background: #78c6b4;
box-shadow: 0 0 0 3px rgba(120, 198, 180, 0.18);
}
.controls {
position: fixed;
right: 28px;
bottom: 25px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.34);
border-radius: 8px;
background: rgba(255, 244, 220, 0.72);
box-shadow: 0 8px 25px rgba(67, 42, 27, 0.1);
color: var(--ink);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
pointer-events: none;
backdrop-filter: blur(10px);
}
.controls kbd {
display: inline-block;
min-width: 21px;
margin: 0 2px;
padding: 2px 5px;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.48);
font: inherit;
text-align: center;
}
.credit {
position: fixed;
left: 30px;
bottom: 26px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
opacity: 0.62;
pointer-events: none;
}
@media (max-width: 720px) {
.title-card {
top: 20px;
left: 20px;
}
h1 {
font-size: 42px;
}
.subtitle {
display: none;
}
.legend {
top: auto;
right: 16px;
bottom: 64px;
}
.controls {
right: 16px;
bottom: 16px;
}
.credit {
display: none;
}
.world-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel diorama of Guanajuato"></main>
<header class="title-card">
<div class="eyebrow">Hillside study / 01</div>
<h1>Between<br />Levels</h1>
<p class="subtitle">
Guanajuato's lower tunnel road and elevated pedestrian stair share the
hillside without losing their distinct routes.
</p>
</header>
<aside class="legend" aria-label="Level legend">
<div class="legend-row">
<span class="legend-swatch road"></span>
<span>Road level · +0 m</span>
</div>
<div class="legend-row">
<span class="legend-swatch walk"></span>
<span>Walking terrace · +5 m</span>
</div>
</aside>
<div id="tunnel-label" class="world-label">
<span class="dot"></span>
Lower tunnel · +0 m
</div>
<div id="walk-label" class="world-label walk-label">
<span class="dot"></span>
Pedestrian stairs · +5 m
</div>
<div class="controls">
<kbd>Drag</kbd> orbit · <kbd>Scroll</kbd> zoom ·
<kbd>R</kbd> reset
</div>
<div class="credit">Voxel Guanajuato · Procedural diorama</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe3b17d);
scene.fog = new THREE.Fog(0xe3b17d, 48, 88);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.querySelector("#scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xffecc9, 0x70564a, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.25);
sun.position.set(-18, 30, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const warmFill = new THREE.DirectionalLight(0xe98e60, 0.75);
warmFill.position.set(20, 12, -18);
scene.add(warmFill);
const controls = {
theta: 0.63,
phi: 1.15,
radius: innerWidth / innerHeight < 0.8 ? 53 : 42,
target: new THREE.Vector3(0, 3.2, -1.2)
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
// -------------------------------------------------------------------------
// Shared materials and geometry helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
earth: material(0x9a6046),
earthDark: material(0x70483d),
terrace: material(0xb97855),
stone: material(0xc59b73),
stoneLight: material(0xdec095),
stoneDark: material(0x9d745a),
cream: material(0xf1d7a2),
white: material(0xfff0cf),
road: material(0x414b4e, { roughness: 1 }),
roadEdge: material(0x707775),
yellow: material(0xe9b844),
window: material(0x25464b, { roughness: 0.5 }),
windowLight: material(0x466d70, { roughness: 0.55 }),
metal: material(0x385256, { metalness: 0.25, roughness: 0.62 }),
black: material(0x172426),
trunk: material(0x78513a),
leaf: material(0x4f7853),
leafLight: material(0x72915d),
leafDark: material(0x365c48),
lamp: material(0xffd78c, {
emissive: 0xffa640,
emissiveIntensity: 1.8
}),
red: material(0xb74d3f),
blue: material(0x4f8199),
teal: material(0x4f9a8d),
pink: material(0xd98282),
yellowWall: material(0xd8a446),
purple: material(0x826b91),
orange: material(0xd56e48),
paleBlue: material(0x87a8aa),
skinA: material(0xd79b72),
skinB: material(0x9e6044),
skinC: material(0xe7b88f),
hair: material(0x382c29),
cloud: material(0xffedcf, { fog: false })
};
function box(w, h, d, x, y, z, mat, parent = scene) {
const mesh = new THREE.Mesh(unitBox, 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 beam(a, b, thickness, mat, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(a, b)
.multiplyScalar(0.5);
const mesh = box(
thickness,
thickness,
length,
midpoint.x,
midpoint.y,
midpoint.z,
mat,
parent
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
return mesh;
}
let seed = 47;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
// -------------------------------------------------------------------------
// Terrain pedestal, lower road, and upper retaining terrace
// -------------------------------------------------------------------------
box(38, 0.9, 34, 0, -0.65, 0, M.earthDark);
box(38, 0.42, 34, 0, -0.12, 0, M.stone);
// Lower road approaches the tunnel from the foreground.
box(5.2, 0.16, 14.3, 8, 0.08, 6.0, M.road);
box(0.58, 0.28, 14.3, 5.14, 0.14, 6.0, M.roadEdge);
box(0.58, 0.28, 14.3, 10.86, 0.14, 6.0, M.roadEdge);
// Centerline dashes.
for (let z = 12.1; z > -0.2; z -= 1.55) {
box(0.12, 0.025, 0.78, 8, 0.177, z, M.yellow);
}
// Road edge stripes.
for (let z = 12.8; z > 0; z -= 1.2) {
box(0.07, 0.022, 0.55, 5.58, 0.176, z, M.cream);
box(0.07, 0.022, 0.55, 10.42, 0.176, z, M.cream);
}
// Upper hillside block and its distinct elevated top.
box(30, 4.8, 12, 0, 2.4, -7, M.terrace);
// Decorative retaining-wall blocks, with the tunnel kept open.
for (let row = 0; row < 7; row++) {
const y = 0.34 + row * 0.67;
for (let x = -14.25; x < 14.8; x += 1.5) {
const inTunnel = x > 5.55 && x < 10.45 && row < 5;
if (inTunnel) continue;
const mat = choose([M.stone, M.stoneLight, M.stoneDark]);
box(
1.38,
0.57,
0.18,
x + (row % 2) * 0.12,
y,
-0.955,
mat
);
}
}
// Elevated pedestrian terrace and its colored route.
box(22.5, 0.18, 1.95, -1.25, 4.86, -2.0, M.cream);
box(22.5, 0.055, 0.18, -1.25, 4.975, -2.83, M.teal);
box(22.5, 0.055, 0.18, -1.25, 4.975, -1.17, M.orange);
// Landing at the top of the stairs.
box(3.15, 0.2, 1.25, 1.8, 4.86, -1.05, M.stoneLight);
// -------------------------------------------------------------------------
// The long voxel stairway
// -------------------------------------------------------------------------
const stair = {
x: 1.8,
bottomY: 0.28,
topY: 4.96,
bottomZ: 10.5,
topZ: -0.9,
count: 28
};
const stairRun =
(stair.bottomZ - stair.topZ) / stair.count;
const stairRise =
(stair.topY - stair.bottomY) / stair.count;
for (let i = 0; i < stair.count; i++) {
const stepTop = stair.bottomY + (i + 1) * stairRise;
const z = stair.bottomZ - (i + 0.5) * stairRun;
box(
2.8,
stepTop,
stairRun + 0.025,
stair.x,
stepTop / 2,
z,
i % 2 ? M.stoneLight : M.stone
);
// Contrasting nosing makes the pedestrian level legible.
box(
2.78,
0.055,
0.075,
stair.x,
stepTop + 0.028,
z + stairRun * 0.42,
i % 4 === 0 ? M.orange : M.cream
);
}
// Stair rails and posts.
const railStartLeft = new THREE.Vector3(
stair.x - 1.5,
stair.bottomY + 0.9,
stair.bottomZ
);
const railEndLeft = new THREE.Vector3(
stair.x - 1.5,
stair.topY + 0.9,
stair.topZ
);
const railStartRight = new THREE.Vector3(
stair.x + 1.5,
stair.bottomY + 0.9,
stair.bottomZ
);
const railEndRight = new THREE.Vector3(
stair.x + 1.5,
stair.topY + 0.9,
stair.topZ
);
beam(railStartLeft, railEndLeft, 0.105, M.metal);
beam(railStartRight, railEndRight, 0.105, M.metal);
for (let i = 0; i <= stair.count; i += 3) {
const t = i / stair.count;
const z = stair.bottomZ + (stair.topZ - stair.bottomZ) * t;
const y = stair.bottomY + (stair.topY - stair.bottomY) * t;
box(0.11, 0.92, 0.11, stair.x - 1.5, y + 0.46, z, M.metal);
box(0.11, 0.92, 0.11, stair.x + 1.5, y + 0.46, z, M.metal);
}
// Upper terrace railing, interrupted by the stair landing.
function terraceRail(x1, x2) {
const length = x2 - x1;
const count = Math.max(2, Math.floor(length / 1.45));
box(length, 0.09, 0.09, (x1 + x2) / 2, 5.73, -1.13, M.metal);
box(length, 0.065, 0.065, (x1 + x2) / 2, 5.32, -1.13, M.metal);
for (let i = 0; i <= count; i++) {
const x = x1 + (length * i) / count;
box(0.09, 0.98, 0.09, x, 5.25, -1.13, M.metal);
}
}
terraceRail(-14.4, 0.3);
terraceRail(3.3, 14.4);
// -------------------------------------------------------------------------
// Lower tunnel entrance
// -------------------------------------------------------------------------
// Stepped black opening.
box(3.42, 2.7, 0.16, 8, 1.35, -0.93, M.black);
box(2.62, 0.43, 0.16, 8, 2.88, -0.93, M.black);
box(1.68, 0.28, 0.16, 8, 3.19, -0.93, M.black);
// Voxel masonry pillars.
for (let row = 0; row < 5; row++) {
const y = 0.34 + row * 0.64;
box(0.72, 0.55, 0.55, 5.76, y, -0.69, M.stoneDark);
box(0.72, 0.55, 0.55, 10.24, y, -0.69, M.stoneDark);
const innerLeft = box(
0.28,
0.55,
0.48,
6.25,
y,
-0.72,
row % 2 ? M.stone : M.stoneLight
);
const innerRight = box(
0.28,
0.55,
0.48,
9.75,
y,
-0.72,
row % 2 ? M.stoneLight : M.stone
);
}
// Stepped arch courses.
for (let x = 5.4; x <= 10.6; x += 0.8) {
box(0.73, 0.45, 0.58, x, 3.28, -0.68, M.stoneLight);
}
for (let x = 5.8; x <= 10.2; x += 0.8) {
box(0.73, 0.43, 0.58, x, 3.68, -0.68, M.stone);
}
for (let x = 6.2; x <= 9.8; x += 0.8) {
box(0.73, 0.42, 0.58, x, 4.07, -0.68, M.stoneLight);
}
// -------------------------------------------------------------------------
// Canvas-based signs
// -------------------------------------------------------------------------
function textTexture(text, background = "#29484a", foreground = "#fff0cf") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.globalAlpha = 0.35;
context.lineWidth = 4;
context.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
context.globalAlpha = 1;
context.fillStyle = foreground;
context.font = "800 52px sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function sign(text, x, y, z, width, height, background, foreground) {
const texture = textTexture(text, background, foreground);
const mat = new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), mat);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
sign("TÚNEL", 8, 4.49, -0.355, 2.55, 0.58, "#315455", "#ffe8b7");
sign("C. VALENTÍN", 1.8, 5.58, -1.61, 2.2, 0.48, "#b95542", "#fff0cf");
// -------------------------------------------------------------------------
// Guanajuato-style stacked pastel architecture
// -------------------------------------------------------------------------
function building({
x,
z,
w,
d,
h,
bodyMat,
trimMat = M.cream,
base = 4.8
}) {
box(w, h, d, x, base + h / 2, z, bodyMat);
// Flat roof and parapet.
box(w + 0.24, 0.22, d + 0.24, x, base + h + 0.11, z, trimMat);
box(w + 0.1, 0.28, 0.13, x, base + h + 0.31, z + d / 2, bodyMat);
box(w + 0.1, 0.28, 0.13, x, base + h + 0.31, z - d / 2, bodyMat);
box(0.13, 0.28, d + 0.1, x + w / 2, base + h + 0.31, z, bodyMat);
box(0.13, 0.28, d + 0.1, x - w / 2, base + h + 0.31, z, bodyMat);
const frontZ = z + d / 2 + 0.035;
const columns = Math.max(2, Math.floor(w / 1.35));
const rows = Math.max(1, Math.floor((h - 1.1) / 1.5));
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const windowX =
x - w / 2 + ((col + 0.5) * w) / columns;
const windowY = base + 1.1 + row * 1.5;
const windowMat = (row + col) % 4 === 0 ? M.windowLight : M.window;
box(0.58, 0.72, 0.07, windowX, windowY, frontZ, windowMat);
box(
0.11,
0.78,
0.08,
windowX - 0.39,
windowY,
frontZ + 0.012,
trimMat
);
box(
0.11,
0.78,
0.08,
windowX + 0.39,
windowY,
frontZ + 0.012,
trimMat
);
if ((row + col) % 3 === 0) {
box(
0.86,
0.08,
0.26,
windowX,
windowY - 0.44,
frontZ + 0.11,
M.cream
);
}
}
}
// Front doorway.
box(0.72, 1.36, 0.08, x, base + 0.68, frontZ + 0.015, M.window);
box(0.87, 0.1, 0.16, x, base + 1.39, frontZ + 0.03, M.cream);
// A few side windows add depth to the voxel blocks.
const sideX = x + w / 2 + 0.035;
for (let row = 0; row < rows; row++) {
box(
0.06,
0.65,
0.5,
sideX,
base + 1.05 + row * 1.5,
z - d * 0.18,
M.window
);
}
}
building({
x: -11.8,
z: -7.0,
w: 4.2,
d: 4.4,
h: 5.4,
bodyMat: M.red
});
building({
x: -7.05,
z: -7.15,
w: 4.0,
d: 4.25,
h: 7.3,
bodyMat: M.yellowWall,
trimMat: M.cream
});
building({
x: -2.55,
z: -7.35,
w: 4.15,
d: 4.0,
h: 5.8,
bodyMat: M.pink
});
building({
x: 2.1,
z: -7.55,
w: 4.3,
d: 4.35,
h: 8.2,
bodyMat: M.paleBlue
});
building({
x: 7.05,
z: -8.0,
w: 4.05,
d: 4.3,
h: 6.3,
bodyMat: M.teal
});
building({
x: 12.0,
z: -7.2,
w: 4.7,
d: 4.45,
h: 8.6,
bodyMat: M.purple
});
// Rear row.
building({
x: -9.8,
z: -11.55,
w: 3.7,
d: 3.35,
h: 4.7,
bodyMat: M.cream,
trimMat: M.red
});
building({
x: -5.45,
z: -11.7,
w: 3.8,
d: 3.4,
h: 5.5,
bodyMat: M.teal
});
building({
x: -0.9,
z: -11.75,
w: 4.1,
d: 3.45,
h: 6.7,
bodyMat: M.yellowWall
});
building({
x: 4.05,
z: -11.8,
w: 3.9,
d: 3.5,
h: 4.8,
bodyMat: M.orange
});
building({
x: 9.05,
z: -11.8,
w: 4.0,
d: 3.45,
h: 6.3,
bodyMat: M.blue
});
// Rooftop annexes evoke Guanajuato's tightly stacked buildings.
building({
x: -11.7,
z: -7.25,
w: 2.25,
d: 2.15,
h: 2.25,
bodyMat: M.cream,
trimMat: M.red,
base: 10.2
});
building({
x: -7.15,
z: -7.5,
w: 2.0,
d: 2.0,
h: 2.1,
bodyMat: M.pink,
trimMat: M.cream,
base: 12.1
});
building({
x: 2.15,
z: -7.65,
w: 2.2,
d: 2.05,
h: 2.25,
bodyMat: M.orange,
trimMat: M.cream,
base: 13.0
});
// Church-like bell tower.
box(2.25, 9.4, 2.4, -13.0, 9.5, -11.35, M.cream);
box(2.55, 0.25, 2.7, -13.0, 14.27, -11.35, M.red);
box(1.8, 0.55, 1.9, -13.0, 14.65, -11.35, M.cream);
box(0.16, 1.0, 0.16, -13.0, 15.38, -11.35, M.metal);
box(0.72, 0.16, 0.16, -13.0, 15.62, -11.35, M.metal);
// Bell openings.
box(0.72, 1.25, 0.1, -13.42, 13.12, -10.11, M.window);
box(0.72, 1.25, 0.1, -12.58, 13.12, -10.11, M.window);
// -------------------------------------------------------------------------
// Trees, planters, lamps, and street furniture
// -------------------------------------------------------------------------
function tree(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.38, 2.5, 0.38, 0, 1.25, 0, M.trunk, group);
box(2.1, 1.25, 1.7, 0, 3.0, 0, M.leaf, group);
box(1.35, 1.1, 1.5, -0.65, 3.7, 0.05, M.leafLight, group);
box(1.25, 1.2, 1.35, 0.7, 3.65, -0.08, M.leafDark, group);
box(0.85, 0.8, 0.9, 0.05, 4.25, 0.05, M.leafLight, group);
}
tree(-8.7, 0.08, 7.2, 1.18);
tree(-12.4, 0.08, 5.7, 0.95);
tree(-14.1, 4.8, -3.3, 0.8);
tree(13.9, 4.8, -3.4, 0.78);
function planter(x, y, z, w = 2.2) {
box(w, 0.52, 0.8, x, y + 0.26, z, M.stoneDark);
box(w - 0.2, 0.12, 0.62, x, y + 0.56, z, M.leafDark);
for (let i = 0; i < 4; i++) {
box(
0.32,
0.65 + (i % 2) * 0.18,
0.32,
x - w * 0.3 + i * (w * 0.2),
y + 0.91,
z,
i % 2 ? M.leaf : M.leafLight
);
}
}
planter(-4.6, 0.08, 11.4, 2.6);
planter(-4.6, 0.08, 8.7, 2.6);
planter(4.1, 4.8, -3.35, 1.9);
function streetLamp(x, groundY, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, groundY, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.42, 0.22, 0.42, 0, 0.11, 0, M.metal, group);
box(0.14, 3.7, 0.14, 0, 1.85, 0, M.metal, group);
box(0.95, 0.13, 0.13, -0.42, 3.65, 0, M.metal, group);
box(0.42, 0.34, 0.34, -0.82, 3.48, 0, M.lamp, group);
box(0.54, 0.08, 0.46, -0.82, 3.66, 0, M.metal, group);
}
streetLamp(11.75, 0.08, 4.5, 1.0);
streetLamp(11.75, 0.08, 10.8, 1.0);
streetLamp(-4.8, 4.8, -3.35, 0.85);
streetLamp(6.1, 4.8, -3.35, 0.85);
// A small voxel bench at the lower plaza.
box(2.2, 0.18, 0.65, -1.1, 0.68, 11.75, M.wood || M.trunk);
box(0.18, 0.65, 0.55, -2.0, 0.34, 11.75, M.metal);
box(0.18, 0.65, 0.55, -0.2, 0.34, 11.75, M.metal);
box(2.2, 0.62, 0.15, -1.1, 1.03, 11.43, M.trunk);
// -------------------------------------------------------------------------
// Voxel car on the lower road
// -------------------------------------------------------------------------
function createCar() {
const group = new THREE.Group();
box(1.65, 0.48, 2.8, 0, 0.42, 0, M.red, group);
box(1.36, 0.5, 1.5, 0, 0.86, -0.08, M.red, group);
box(1.39, 0.34, 0.08, 0, 0.9, 0.69, M.window, group);
box(1.39, 0.34, 0.08, 0, 0.9, -0.85, M.window, group);
box(0.08, 0.34, 1.2, 0.69, 0.9, -0.08, M.window, group);
box(0.08, 0.34, 1.2, -0.69, 0.9, -0.08, M.window, group);
box(0.36, 0.25, 0.08, -0.52, 0.48, 1.42, M.lamp, group);
box(0.36, 0.25, 0.08, 0.52, 0.48, 1.42, M.lamp, group);
box(0.36, 0.25, 0.08, -0.52, 0.48, -1.42, M.red, group);
box(0.36, 0.25, 0.08, 0.52, 0.48, -1.42, M.red, group);
for (const x of [-0.88, 0.88]) {
for (const z of [-0.88, 0.88]) {
box(0.22, 0.42, 0.42, x, 0.2, z, M.black, group);
}
}
scene.add(group);
return group;
}
const car = createCar();
// -------------------------------------------------------------------------
// Voxel pedestrians
// -------------------------------------------------------------------------
const pedestrians = [];
function createPedestrian({
shirt,
pants = M.metal,
skin = M.skinA,
hair = M.hair,
route,
phase,
speed,
offset = 0,
scale = 1,
backpack = false
}) {
const group = new THREE.Group();
group.scale.setScalar(scale);
scene.add(group);
box(0.43, 0.56, 0.29, 0, 0.79, 0, shirt, group);
box(0.33, 0.34, 0.32, 0, 1.24, 0, skin, group);
box(0.35, 0.11, 0.34, 0, 1.43, -0.015, hair, group);
box(0.35, 0.18, 0.08, 0, 1.29, 0.17, skin, group);
const leftLeg = box(0.14, 0.48, 0.16, -0.12, 0.29, 0, pants, group);
const rightLeg = box(0.14, 0.48, 0.16, 0.12, 0.29, 0, pants, group);
const leftArm = box(0.12, 0.48, 0.14, -0.29, 0.78, 0, shirt, group);
const rightArm = box(0.12, 0.48, 0.14, 0.29, 0.78, 0, shirt, group);
box(0.17, 0.1, 0.27, -0.12, 0.055, 0.06, M.black, group);
box(0.17, 0.1, 0.27, 0.12, 0.055, 0.06, M.black, group);
if (backpack) {
box(0.34, 0.39, 0.16, 0, 0.83, -0.22, M.orange, group);
}
const pedestrian = {
group,
leftLeg,
rightLeg,
leftArm,
rightArm,
route,
phase,
speed,
offset
};
pedestrians.push(pedestrian);
return pedestrian;
}
const shirtMaterials = [M.red, M.blue, M.teal, M.yellowWall, M.pink, M.purple];
const skinMaterials = [M.skinA, M.skinB, M.skinC];
// Five pedestrians distributed over the staircase.
for (let i = 0; i < 5; i++) {
createPedestrian({
shirt: shirtMaterials[i % shirtMaterials.length],
pants: i % 2 ? M.metal : M.earthDark,
skin: skinMaterials[i % skinMaterials.length],
hair: i % 3 === 0 ? M.earthDark : M.hair,
route: "stairs",
phase: i * 0.21 + 0.04,
speed: 0.034,
offset: (i % 2 ? 1 : -1) * (0.22 + (i % 3) * 0.14),
scale: 0.96 + (i % 3) * 0.05,
backpack: i === 2 || i === 4
});
}
// Three pedestrians on the upper pedestrian terrace.
for (let i = 0; i < 3; i++) {
createPedestrian({
shirt: shirtMaterials[(i + 2) % shirtMaterials.length],
pants: i % 2 ? M.metal : M.earthDark,
skin: skinMaterials[(i + 1) % skinMaterials.length],
route: "terrace",
phase: i * 0.36 + 0.08,
speed: 0.024,
offset: (i - 1) * 0.34,
scale: 1.02,
backpack: i === 1
});
}
// Two pedestrians on the lower sidewalk.
for (let i = 0; i < 2; i++) {
createPedestrian({
shirt: shirtMaterials[(i + 4) % shirtMaterials.length],
pants: M.metal,
skin: skinMaterials[i % skinMaterials.length],
route: "lower",
phase: i * 0.47 + 0.1,
speed: 0.026,
offset: (i - 0.5) * 0.18,
scale: 0.98,
backpack: i === 1
});
}
function updatePedestrians(time) {
for (const person of pedestrians) {
const t = (person.phase + time * person.speed) % 1;
const walk = Math.sin(time * 8.2 + person.phase * 17);
const swing = Math.sin(time * 8.2 + person.phase * 17) * 0.48;
person.leftLeg.rotation.x = swing;
person.rightLeg.rotation.x = -swing;
person.leftArm.rotation.x = -swing * 0.78;
person.rightArm.rotation.x = swing * 0.78;
person.group.position.y += Math.abs(walk) * 0.025;
if (person.route === "stairs") {
const stairT = t;
person.group.position.set(
stair.x + person.offset,
stair.bottomY +
(stair.topY - stair.bottomY) * stairT +
Math.abs(walk) * 0.018,
stair.bottomZ + (stair.topZ - stair.bottomZ) * stairT
);
person.group.rotation.y = Math.PI + Math.sin(time * 1.7 + person.phase) * 0.035;
} else if (person.route === "terrace") {
person.group.position.set(
8.9 - t * 19.5,
4.98 + Math.abs(walk) * 0.025,
-2.02 + person.offset
);
person.group.rotation.y = -Math.PI / 2;
} else {
person.group.position.set(
11.18 + person.offset,
0.3 + Math.abs(walk) * 0.025,
10.2 - t * 10.2
);
person.group.rotation.y = Math.PI;
}
}
}
// -------------------------------------------------------------------------
// Decorative voxel clouds
// -------------------------------------------------------------------------
function cloud(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
const cloudMat = M.cloud.clone();
cloudMat.transparent = true;
cloudMat.opacity = 0.72;
cloudMat.depthWrite = false;
box(2.3, 0.75, 0.8, 0, 0, 0, cloudMat, group);
box(1.35, 1.1, 0.85, -0.75, 0.2, 0, cloudMat, group);
box(1.45, 0.9, 0.8, 0.55, 0.15, 0, cloudMat, group);
box(0.8, 0.65, 0.7, 1.55, -0.1, 0, cloudMat, group);
scene.add(group);
}
cloud(-12, 16.5, -19, 1.1);
cloud(9, 18.5, -22, 1.35);
cloud(20, 14.5, -16, 0.8);
// -------------------------------------------------------------------------
// Projected labels
// -------------------------------------------------------------------------
const tunnelLabel = document.querySelector("#tunnel-label");
const walkLabel = document.querySelector("#walk-label");
const tunnelLabelPoint = new THREE.Vector3(8, 4.55, -0.25);
const walkLabelPoint = new THREE.Vector3(1.8, 6.15, 1.2);
function positionLabel(element, point) {
const projected = point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
// -------------------------------------------------------------------------
// Direct orbit controls: no addons or examples modules
// -------------------------------------------------------------------------
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
controls.theta -= deltaX * 0.0055;
controls.phi = THREE.MathUtils.clamp(
controls.phi - deltaY * 0.0045,
0.48,
1.46
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
23,
68
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
controls.theta = 0.63;
controls.phi = 1.15;
controls.radius = innerWidth / innerHeight < 0.8 ? 53 : 42;
controls.target.set(0, 3.2, -1.2);
updateCamera();
}
canvas.addEventListener("dblclick", resetCamera);
addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
} else if (event.key === "ArrowLeft") {
controls.theta += 0.09;
} else if (event.key === "ArrowRight") {
controls.theta -= 0.09;
} else if (event.key === "ArrowUp") {
controls.phi = Math.max(0.48, controls.phi - 0.07);
} else if (event.key === "ArrowDown") {
controls.phi = Math.min(1.46, controls.phi + 0.07);
} else if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(23, controls.radius - 2);
} else if (event.key === "-") {
controls.radius = Math.min(68, controls.radius + 2);
}
updateCamera();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
updatePedestrians(time);
// The car advances toward and into the lower tunnel.
const carTravel = (time * 1.25 + 2.1) % 13.5;
car.position.set(8, 0.12, 11.7 - carTravel);
car.visible = car.position.z > -1.1;
positionLabel(tunnelLabel, tunnelLabelPoint);
positionLabel(walkLabel, walkLabelPoint);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```