Prompt specification
Build or customize the Three.js 3D scene "Superquadra path beneath a residential block" 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: Superquadra path beneath a residential block
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/superquadra-path-beneath-a-residential-block-x2650
Scene Description Prompt:
Superquadra path beneath a residential block. Create a compact Brasília residential vignette with shaded path, planted ground, and an open pilotis passage. Animate a pedestrian route beneath the building rather than around a solid wall. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (superquadra-path-beneath-a-residential-block-x2650):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Superquadra — Pilotis Walk</title>
<style>
:root {
--ink: #19342f;
--paper: rgba(248, 246, 237, 0.9);
--accent: #d79a38;
--teal: #2d7774;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e4df;
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;
}
.panel {
position: fixed;
z-index: 10;
pointer-events: none;
}
.title-panel {
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid rgba(25, 52, 47, 0.12);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 14px 45px rgba(35, 59, 49, 0.12);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 38px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
max-width: 285px;
margin: 10px 0 0;
font-size: 12px;
line-height: 1.5;
opacity: 0.72;
}
.view-panel {
top: 24px;
right: 24px;
display: flex;
gap: 7px;
padding: 6px;
border: 1px solid rgba(25, 52, 47, 0.12);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(35, 59, 49, 0.1);
backdrop-filter: blur(12px);
pointer-events: auto;
}
button {
border: 0;
border-radius: 2px;
padding: 9px 12px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(45, 119, 116, 0.09);
}
button:active {
transform: translateY(1px);
}
button.active {
background: var(--ink);
color: #fffdf5;
}
.route-panel {
bottom: 24px;
left: 24px;
width: min(355px, calc(100vw - 48px));
padding: 14px 16px;
border: 1px solid rgba(25, 52, 47, 0.12);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(35, 59, 49, 0.12);
backdrop-filter: blur(12px);
}
.route-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status {
display: flex;
align-items: center;
gap: 7px;
color: var(--teal);
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(215, 154, 56, 0.15);
}
.progress-track {
position: relative;
height: 3px;
overflow: hidden;
background: rgba(25, 52, 47, 0.12);
}
.progress-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0%;
background: var(--accent);
transition: width 100ms linear;
}
.help {
position: fixed;
right: 25px;
bottom: 24px;
z-index: 10;
color: rgba(25, 52, 47, 0.72);
font-size: 10px;
letter-spacing: 0.06em;
pointer-events: none;
text-shadow: 0 1px 3px rgba(255, 255, 255, 0.7);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #d8e4df;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 680px) {
.title-panel {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.view-panel {
top: auto;
right: 14px;
bottom: 76px;
}
.route-panel {
bottom: 14px;
left: 14px;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building Superquadra</div>
<section class="panel title-panel">
<div class="eyebrow">Brasília · Superquadra 03</div>
<h1>Pilotis Walk</h1>
<p class="subtitle">
A shaded pedestrian route passing directly through the open ground
floor of a residential slab.
</p>
</section>
<nav class="panel view-panel" aria-label="Camera views">
<button id="overview" class="active" type="button">Overview</button>
<button id="follow" type="button">Follow route</button>
</nav>
<section class="panel route-panel">
<div class="route-heading">
<span>Pedestrian passage</span>
<span id="status" class="status">
<span class="status-dot"></span>
<span id="statusText">Approach</span>
</span>
</div>
<div class="progress-track">
<div id="progress" class="progress-fill"></div>
</div>
</section>
<div class="help">
Drag to orbit · Wheel to zoom · Arrow keys to rotate · R to reset
</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 loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e4df);
scene.fog = new THREE.Fog(0xd8e4df, 48, 105);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
160
);
const clock = new THREE.Clock();
const hemisphere = new THREE.HemisphereLight(
0xeaf7ef,
0x6c7250,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.1);
sun.position.set(-24, 36, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -43;
sun.shadow.camera.right = 43;
sun.shadow.camera.top = 43;
sun.shadow.camera.bottom = -43;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const bounce = new THREE.DirectionalLight(0x8db9bc, 0.48);
bounce.position.set(25, 10, -28);
scene.add(bounce);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
grass: standard(0x829b6b),
grassLight: standard(0x91aa78),
grassDark: standard(0x718c61),
path: standard(0xc7c1ac),
pathEdge: standard(0xa8a38e),
concrete: standard(0xe5dfcf),
concreteShade: standard(0xcac6b8),
facade: standard(0xeee8d9),
frame: standard(0xd8d1c0),
glass: standard(0x355d61, {
roughness: 0.3,
metalness: 0.22
}),
glassLight: standard(0x5a7e7d, {
roughness: 0.38,
metalness: 0.12
}),
soil: standard(0x71654b),
trunk: standard(0x6b5035),
leafA: standard(0x547b50),
leafB: standard(0x668e58),
leafC: standard(0x78985f),
metal: standard(0x38504a, {
roughness: 0.56,
metalness: 0.45
}),
route: standard(0xf0ae43, {
roughness: 0.48,
emissive: 0x7d4510,
emissiveIntensity: 0.28
}),
skin: standard(0xc98f64),
shirt: standard(0xd76745),
trousers: standard(0x294d55),
shoe: standard(0x25312f),
hair: standard(0x342c26),
accent: standard(0x3f8580)
};
function addBox(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground, planted areas, and the path
// ------------------------------------------------------------
addBox(82, 0.3, 76, materials.grass, 0, -0.17, 0, scene, false);
// Flat low-poly planting patches.
const patchGeometry = new THREE.CircleGeometry(1, 8);
function plantingPatch(x, z, radius, material, rotation = 0) {
const patch = new THREE.Mesh(patchGeometry, material);
patch.rotation.x = -Math.PI / 2;
patch.rotation.z = rotation;
patch.position.set(x, 0.006, z);
patch.scale.set(radius, radius * 0.65, 1);
patch.receiveShadow = true;
scene.add(patch);
}
plantingPatch(-12, 17, 8.5, materials.grassLight, 0.3);
plantingPatch(12, 12, 9.2, materials.grassDark, -0.2);
plantingPatch(-14, -11, 10.5, materials.grassDark, 0.5);
plantingPatch(13, -15, 8.2, materials.grassLight, -0.4);
plantingPatch(-25, 2, 7, materials.grassLight, 0.1);
// The pedestrian route continues uninterrupted through the pilotis.
addBox(4.8, 0.09, 60, materials.path, 0, 0.015, 0, scene, false);
addBox(0.18, 0.13, 60, materials.pathEdge, -2.49, 0.025, 0, scene, false);
addBox(0.18, 0.13, 60, materials.pathEdge, 2.49, 0.025, 0, scene, false);
// Soil beds parallel to the route.
[-1, 1].forEach((side) => {
for (const z of [-19, -8, 9, 20]) {
addBox(
5.7,
0.08,
6.4,
materials.soil,
side * 6.35,
0.02,
z,
scene,
false
);
}
});
// ------------------------------------------------------------
// Residential slab and open pilotis
// ------------------------------------------------------------
const building = new THREE.Group();
scene.add(building);
const floorLevels = [4.8, 8.0, 11.2, 14.4, 17.6];
// Horizontal concrete slabs.
floorLevels.forEach((y) => {
addBox(30, 0.42, 11.2, materials.concrete, 0, y, 0, building);
});
// Residential facade bands, windows, and brise-soleil fins.
for (let floor = 0; floor < floorLevels.length - 1; floor++) {
const bottom = floorLevels[floor];
const top = floorLevels[floor + 1];
const mid = (bottom + top) * 0.5;
[-1, 1].forEach((side) => {
const z = side * 5.42;
// Spandrel below the windows.
addBox(
29.6,
2.55,
0.38,
materials.facade,
0,
mid - 0.08,
z,
building
);
for (let i = 0; i < 10; i++) {
const x = -12.85 + i * 2.85;
// Recessed window frame and glass.
addBox(
2.25,
1.76,
0.14,
materials.frame,
x,
mid + 0.32,
side * 5.66,
building
);
addBox(
2.02,
1.53,
0.12,
i % 3 === 0 ? materials.glassLight : materials.glass,
x,
mid + 0.32,
side * 5.76,
building
);
// A central mullion.
addBox(
0.055,
1.54,
0.08,
materials.frame,
x,
mid + 0.32,
side * 5.84,
building,
false
);
// Vertical sun-shading fins.
addBox(
0.15,
2.4,
0.9,
materials.frame,
x - 1.38,
mid + 0.25,
side * 5.83,
building
);
// Selected projecting balconies.
if (i % 3 === 1) {
addBox(
3.55,
0.14,
1.15,
materials.concrete,
x,
mid - 0.93,
side * 6.0,
building
);
addBox(
3.55,
0.63,
0.13,
materials.concreteShade,
x,
mid - 0.58,
side * 6.53,
building
);
for (let rail = -1; rail <= 1; rail++) {
addBox(
0.055,
0.57,
0.055,
materials.metal,
x + rail * 1.65,
mid - 0.58,
side * 6.48,
building,
false
);
}
}
}
});
// End walls give the slab a readable residential volume.
addBox(
0.46,
2.75,
10.85,
materials.facade,
-14.78,
mid,
0,
building
);
addBox(
0.46,
2.75,
10.85,
materials.facade,
14.78,
mid,
0,
building
);
}
// Pilotis columns: the central 9.2 m bay remains completely open.
const columnXs = [-13.8, -9.2, -4.6, 4.6, 9.2, 13.8];
columnXs.forEach((x) => {
[-4.6, 4.6].forEach((z) => {
addBox(
0.62,
4.58,
0.62,
materials.concrete,
x,
2.29,
z,
building
);
// Slightly wider footings.
addBox(
0.86,
0.16,
0.86,
materials.concreteShade,
x,
0.08,
z,
building
);
});
});
// Longitudinal pilotis beams.
[-4.6, 4.6].forEach((z) => {
addBox(29.7, 0.43, 0.48, materials.concreteShade, 0, 4.48, z, building);
});
// Roof-top details.
addBox(3.5, 1.15, 2.8, materials.concreteShade, 5, 18.38, -1, building);
addBox(2.3, 0.9, 2.1, materials.concrete, -6.8, 18.32, 1.5, building);
const waterTank = addCylinder(
1.5,
1.65,
1.65,
10,
materials.accent,
-10,
18.7,
-0.8,
building
);
waterTank.castShadow = true;
// Warm linear lights make the shaded passage legible.
const passageLight = new THREE.PointLight(0xffd99a, 18, 20, 2);
passageLight.position.set(0, 4.1, 0);
scene.add(passageLight);
[-2.8, 2.8].forEach((x) => {
addBox(
0.06,
0.045,
10.1,
new THREE.MeshStandardMaterial({
color: 0xffe6a9,
emissive: 0xffbd61,
emissiveIntensity: 1.4
}),
x,
4.54,
0,
building,
false
);
});
// ------------------------------------------------------------
// Route markings
// ------------------------------------------------------------
const routeDashes = [];
for (let z = 24; z >= -24; z -= 2.2) {
const dash = addBox(
0.17,
0.035,
1.05,
materials.route,
0,
0.09,
z,
scene,
false
);
routeDashes.push(dash);
}
const arrowGeometry = new THREE.BufferGeometry();
arrowGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-0.35, 0, -0.58,
0.35, 0, -0.58,
0, 0, 0.48
],
3
)
);
arrowGeometry.computeVertexNormals();
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xf0ae43,
emissive: 0x74400e,
emissiveIntensity: 0.2,
roughness: 0.6,
side: THREE.DoubleSide
});
for (let z = 21; z >= -21; z -= 6) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.position.set(0, 0.105, z);
arrow.receiveShadow = true;
scene.add(arrow);
}
const passageRing = new THREE.Mesh(
new THREE.TorusGeometry(1.15, 0.045, 6, 40),
materials.route
);
passageRing.rotation.x = Math.PI / 2;
passageRing.position.set(0, 0.12, 0);
scene.add(passageRing);
// ------------------------------------------------------------
// Low-poly vegetation and street furniture
// ------------------------------------------------------------
function makeTree(x, z, scale = 1, variation = 0) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addCylinder(
0.16,
0.25,
2.15,
5,
materials.trunk,
0,
1.08,
0,
tree
);
const canopyMaterial = [
materials.leafA,
materials.leafB,
materials.leafC
][variation % 3];
const canopyGeometry = new THREE.IcosahedronGeometry(1, 0);
const crown = new THREE.Mesh(canopyGeometry, canopyMaterial);
crown.position.set(0, 2.65, 0);
crown.scale.set(1.25, 1.45, 1.15);
crown.rotation.set(0.2, variation * 0.7, 0.1);
crown.castShadow = true;
crown.receiveShadow = true;
tree.add(crown);
const left = new THREE.Mesh(canopyGeometry, materials.leafA);
left.position.set(-0.75, 2.25, 0.15);
left.scale.set(0.85, 0.95, 0.85);
left.rotation.set(0.1, 1.2, 0.4);
left.castShadow = true;
tree.add(left);
const right = new THREE.Mesh(canopyGeometry, materials.leafB);
right.position.set(0.72, 2.4, -0.08);
right.scale.set(0.88, 1.0, 0.9);
right.rotation.set(0.5, 2.1, 0.2);
right.castShadow = true;
tree.add(right);
scene.add(tree);
}
const treePositions = [
[-8.6, 18.5, 1.12, 0],
[8.2, 17.0, 1.02, 1],
[-10.5, 10.2, 0.88, 2],
[11.4, 7.2, 0.9, 0],
[-9.0, -1.5, 0.8, 1],
[9.5, -2.8, 0.86, 2],
[-8.8, -13.8, 1.1, 2],
[8.6, -18.5, 1.18, 0],
[-18.5, 20.0, 1.35, 1],
[19.0, 15.0, 1.3, 2],
[-21.0, -17.0, 1.45, 0],
[20.5, -10.0, 1.28, 1]
];
treePositions.forEach((args) => makeTree(...args));
const shrubGeometry = new THREE.IcosahedronGeometry(0.62, 0);
function makeShrub(x, z, scale = 1, index = 0) {
const shrub = new THREE.Mesh(
shrubGeometry,
[materials.leafA, materials.leafB, materials.leafC][index % 3]
);
shrub.position.set(x, 0.48 * scale, z);
shrub.scale.set(scale, scale * 0.75, scale);
shrub.rotation.set(index * 0.13, index * 0.7, index * 0.21);
shrub.castShadow = true;
shrub.receiveShadow = true;
scene.add(shrub);
}
let shrubIndex = 0;
[-1, 1].forEach((side) => {
[-19, -8, 9, 20].forEach((bedZ) => {
for (let i = 0; i < 5; i++) {
makeShrub(
side * (4.65 + (i % 2) * 1.15),
bedZ - 2.2 + i * 1.05,
0.62 + (i % 3) * 0.11,
shrubIndex++
);
}
});
});
function makeBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
addBox(2.2, 0.15, 0.58, materials.trunk, 0, 0.58, 0, bench);
addBox(2.2, 0.62, 0.12, materials.trunk, 0, 0.94, -0.25, bench);
[-0.78, 0.78].forEach((legX) => {
addBox(0.12, 0.58, 0.42, materials.metal, legX, 0.29, 0, bench);
});
scene.add(bench);
}
makeBench(3.7, 13.5, Math.PI / 2);
makeBench(-3.7, -14.0, Math.PI / 2);
makeBench(7.8, 4.0, 0);
// Low planters at the entrance and exit.
[-1, 1].forEach((side) => {
[23, -23].forEach((z) => {
addBox(
1.45,
0.65,
2.6,
materials.concreteShade,
side * 3.45,
0.325,
z
);
addBox(
1.18,
0.08,
2.3,
materials.soil,
side * 3.45,
0.68,
z,
scene,
false
);
makeShrub(side * 3.45, z + 0.55, 0.7, side + z);
makeShrub(side * 3.45, z - 0.55, 0.62, side + z + 1);
});
});
// Slim lamps along the path.
[-1, 1].forEach((side) => {
[19, -19].forEach((z) => {
addCylinder(
0.055,
0.075,
3.4,
6,
materials.metal,
side * 3.05,
1.7,
z
);
addBox(
0.45,
0.1,
0.25,
materials.metal,
side * 2.9,
3.42,
z
);
});
});
// ------------------------------------------------------------
// Pilotis wayfinding sign
// ------------------------------------------------------------
function makeSignTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = "#19342f";
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#f5b64f";
context.fillRect(0, 0, 18, canvas.height);
context.fillStyle = "#faf7eb";
context.font = "700 48px sans-serif";
context.fillText("PILOTIS", 48, 73);
context.fillStyle = "#9fc7bd";
context.font = "500 25px sans-serif";
context.fillText("PASSAGEM 03 →", 49, 118);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(3.4, 1.06),
new THREE.MeshBasicMaterial({ map: makeSignTexture() })
);
sign.position.set(3.8, 1.65, 10.8);
scene.add(sign);
addCylinder(0.055, 0.075, 1.8, 6, materials.metal, 3.8, 0.9, 10.8);
// ------------------------------------------------------------
// Distant context blocks
// ------------------------------------------------------------
function distantBlock(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
addBox(20, 0.4, 7.5, materials.concreteShade, 0, 4.1, 0, group);
for (let floor = 0; floor < 3; floor++) {
const y = 5.35 + floor * 2.8;
addBox(20, 2.5, 7.2, materials.concreteShade, 0, y, 0, group);
addBox(20, 0.28, 7.5, materials.concrete, 0, y + 1.3, 0, group);
for (let i = 0; i < 7; i++) {
addBox(
1.7,
1.1,
0.12,
materials.glassLight,
-8 + i * 2.7,
y + 0.2,
3.66,
group
);
}
}
[-8, 0, 8].forEach((columnX) => {
addBox(0.55, 3.9, 0.55, materials.concreteShade, columnX, 1.95, 0, group);
});
scene.add(group);
}
distantBlock(-34, -29, 0.12);
distantBlock(33, -33, -0.14);
// ------------------------------------------------------------
// Animated pedestrian
// ------------------------------------------------------------
const pedestrian = new THREE.Group();
scene.add(pedestrian);
const torso = addBox(
0.46,
0.65,
0.29,
materials.shirt,
0,
1.08,
0,
pedestrian
);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.235, 1),
materials.skin
);
head.position.set(0, 1.62, 0);
head.castShadow = true;
pedestrian.add(head);
const hair = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.245, 0),
materials.hair
);
hair.position.set(0, 1.69, 0.035);
hair.scale.set(1, 0.72, 1);
hair.castShadow = true;
pedestrian.add(hair);
// Small nose establishes the walking direction.
addBox(
0.07,
0.07,
0.09,
materials.skin,
0,
1.61,
-0.23,
pedestrian,
false
);
function makeLimb(x, y, material, length, width) {
const pivot = new THREE.Group();
pivot.position.set(x, y, 0);
pedestrian.add(pivot);
addBox(
width,
length,
width,
material,
0,
-length * 0.5,
0,
pivot
);
return pivot;
}
const leftArm = makeLimb(-0.3, 1.36, materials.shirt, 0.58, 0.13);
const rightArm = makeLimb(0.3, 1.36, materials.shirt, 0.58, 0.13);
const leftLeg = makeLimb(-0.13, 0.76, materials.trousers, 0.7, 0.16);
const rightLeg = makeLimb(0.13, 0.76, materials.trousers, 0.7, 0.16);
addBox(0.17, 0.12, 0.3, materials.shoe, 0, -0.73, -0.07, leftLeg);
addBox(0.17, 0.12, 0.3, materials.shoe, 0, -0.73, -0.07, rightLeg);
addBox(
0.32,
0.42,
0.15,
materials.accent,
0,
1.08,
0.22,
pedestrian
);
// The pedestrian traverses the route beneath the building.
const routeStart = 24;
const routeEnd = -24;
const routeLength = routeStart - routeEnd;
const walkSpeed = 2.15;
let pedestrianRotation = 0;
function updatePedestrian(elapsed, delta) {
const phase = (elapsed * walkSpeed / routeLength) % 2;
const forward = phase <= 1;
const z = forward
? routeStart - phase * routeLength
: routeEnd + (phase - 1) * routeLength;
pedestrian.position.set(0, 0.08 + Math.abs(Math.sin(elapsed * 8)) * 0.025, z);
const desiredRotation = forward ? 0 : Math.PI;
const angleDifference = Math.atan2(
Math.sin(desiredRotation - pedestrianRotation),
Math.cos(desiredRotation - pedestrianRotation)
);
pedestrianRotation += angleDifference * (1 - Math.exp(-delta * 8));
pedestrian.rotation.y = pedestrianRotation;
const stride = Math.sin(elapsed * 8.2);
leftLeg.rotation.x = stride * 0.62;
rightLeg.rotation.x = -stride * 0.62;
leftArm.rotation.x = -stride * 0.48;
rightArm.rotation.x = stride * 0.48;
torso.rotation.z = stride * 0.018;
return phase;
}
// ------------------------------------------------------------
// Custom camera controls
// ------------------------------------------------------------
const overviewFocus = new THREE.Vector3(0, 2.7, 0);
const currentFocus = overviewFocus.clone();
const desiredFocus = overviewFocus.clone();
const orbitTarget = {
theta: 0.52,
phi: 1.36,
radius: 42
};
const orbitCurrent = {
theta: orbitTarget.theta,
phi: orbitTarget.phi,
radius: orbitTarget.radius
};
let cameraMode = "overview";
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function sphericalOffset(theta, phi, radius) {
return new THREE.Vector3(
radius * Math.sin(phi) * Math.sin(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.cos(theta)
);
}
camera.position.copy(
overviewFocus.clone().add(
sphericalOffset(
orbitCurrent.theta,
orbitCurrent.phi,
orbitCurrent.radius
)
)
);
camera.lookAt(currentFocus);
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbitTarget.theta -= deltaX * 0.0055;
orbitTarget.phi = THREE.MathUtils.clamp(
orbitTarget.phi - deltaY * 0.0045,
0.42,
1.52
);
});
function releasePointer(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitTarget.radius = THREE.MathUtils.clamp(
orbitTarget.radius * Math.exp(event.deltaY * 0.001),
7,
65
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
setCameraMode("overview");
});
window.addEventListener("keydown", (event) => {
switch (event.key.toLowerCase()) {
case "arrowleft":
orbitTarget.theta += 0.12;
break;
case "arrowright":
orbitTarget.theta -= 0.12;
break;
case "arrowup":
orbitTarget.phi = Math.max(0.42, orbitTarget.phi - 0.08);
break;
case "arrowdown":
orbitTarget.phi = Math.min(1.52, orbitTarget.phi + 0.08);
break;
case "+":
case "=":
orbitTarget.radius = Math.max(7, orbitTarget.radius - 2);
break;
case "-":
orbitTarget.radius = Math.min(65, orbitTarget.radius + 2);
break;
case "r":
setCameraMode("overview");
break;
}
});
const overviewButton = document.querySelector("#overview");
const followButton = document.querySelector("#follow");
function setCameraMode(mode) {
cameraMode = mode;
overviewButton.classList.toggle("active", mode === "overview");
followButton.classList.toggle("active", mode === "follow");
if (mode === "overview") {
orbitTarget.theta = 0.52;
orbitTarget.phi = 1.36;
orbitTarget.radius = 42;
} else {
orbitTarget.theta = 0.52;
orbitTarget.phi = 1.4;
orbitTarget.radius = 13;
}
}
overviewButton.addEventListener("click", () => setCameraMode("overview"));
followButton.addEventListener("click", () => setCameraMode("follow"));
// ------------------------------------------------------------
// UI and animation loop
// ------------------------------------------------------------
const progressElement = document.querySelector("#progress");
const statusText = document.querySelector("#statusText");
function updateCamera(delta) {
if (cameraMode === "follow") {
desiredFocus.set(
pedestrian.position.x,
pedestrian.position.y + 1.12,
pedestrian.position.z
);
} else {
desiredFocus.copy(overviewFocus);
}
const focusDamping = 1 - Math.exp(-delta * 3.2);
const orbitDamping = 1 - Math.exp(-delta * 7);
currentFocus.lerp(desiredFocus, focusDamping);
orbitCurrent.theta = THREE.MathUtils.lerp(
orbitCurrent.theta,
orbitTarget.theta,
orbitDamping
);
orbitCurrent.phi = THREE.MathUtils.lerp(
orbitCurrent.phi,
orbitTarget.phi,
orbitDamping
);
orbitCurrent.radius = THREE.MathUtils.lerp(
orbitCurrent.radius,
orbitTarget.radius,
orbitDamping
);
const desiredCameraPosition = currentFocus.clone().add(
sphericalOffset(
orbitCurrent.theta,
orbitCurrent.phi,
orbitCurrent.radius
)
);
camera.position.lerp(
desiredCameraPosition,
1 - Math.exp(-delta * 4.5)
);
camera.lookAt(currentFocus);
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const routePhase = updatePedestrian(elapsed, delta);
updateCamera(delta);
// Gentle route-marker pulse.
materials.route.emissiveIntensity =
0.24 + Math.sin(elapsed * 2.5) * 0.09;
passageRing.rotation.z = elapsed * 0.25;
const progress = routePhase <= 1
? routePhase * 50
: (2 - routePhase) * 50;
progressElement.style.width = `${progress}%`;
const underBuilding = Math.abs(pedestrian.position.z) < 6.2;
statusText.textContent = underBuilding ? "Under pilotis" : "Approach";
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```