Prompt specification
Build or customize the Three.js 3D scene "Shaded pedestrian passage in São Luís" 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: Shaded pedestrian passage in São Luís
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shaded-pedestrian-passage-in-s-o-lu-s-x2706
Scene Description Prompt:
Shaded pedestrian passage in São Luís. Create a compact historic street vignette with tiled facades, projecting balconies, and a pedestrian. Show the shaded route produced by building geometry under a fixed sun direction. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (shaded-pedestrian-passage-in-s-o-lu-s-x2706):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>São Luís — Shaded Pedestrian Passage</title>
<style>
:root {
color-scheme: light;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9d2c8;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
top: 22px;
left: 22px;
z-index: 2;
width: min(340px, calc(100vw - 44px));
padding: 16px 18px;
color: #27312e;
background: rgba(248, 243, 226, 0.88);
border: 1px solid rgba(55, 67, 61, 0.18);
border-radius: 12px;
box-shadow: 0 12px 35px rgba(44, 45, 37, 0.14);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #a55d36;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(23px, 4vw, 32px);
font-weight: 500;
line-height: 1.05;
}
.subtitle {
margin: 9px 0 0;
color: #5e675f;
font-size: 12px;
line-height: 1.5;
}
.sun {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(55, 67, 61, 0.13);
color: #72502d;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.sun-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #e3a24b;
box-shadow: 0 0 0 4px rgba(227, 162, 75, 0.18);
}
.controls {
position: fixed;
right: 20px;
bottom: 18px;
z-index: 3;
display: flex;
align-items: center;
gap: 10px;
color: rgba(35, 45, 41, 0.78);
font-size: 11px;
text-shadow: 0 1px 3px rgba(255, 255, 255, 0.8);
pointer-events: none;
}
button {
padding: 9px 12px;
color: #35413c;
background: rgba(248, 243, 226, 0.9);
border: 1px solid rgba(55, 67, 61, 0.2);
border-radius: 8px;
font: inherit;
font-size: 11px;
cursor: pointer;
pointer-events: auto;
}
button:hover {
background: #fff8e7;
}
@media (max-width: 640px) {
.hud {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div class="hud">
<div class="eyebrow">Historic pedestrian passage</div>
<h1>São Luís, Brasil</h1>
<p class="subtitle">
Azulejo facades, iron balconies, and a slow pedestrian beneath the fixed
afternoon sun.
</p>
<div class="sun">
<span class="sun-dot"></span>
Fixed sun · geometry-driven shade
</div>
</div>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</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(0xcbd7cf);
scene.fog = new THREE.Fog(0xcbd7cf, 25, 52);
const camera = new THREE.PerspectiveCamera(
48,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const cameraState = {
yaw: 0,
pitch: 0.29,
radius: 23.5,
target: new THREE.Vector3(0, 2.25, -1.35)
};
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
updateCamera();
// -------------------------------------------------------------------------
// Fixed sunlight and ambient illumination
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xe9f2e9,
0x74604a,
1.45
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd49a, 3.6);
sun.position.set(-14, 26, 10);
sun.target.position.set(0, 0, -1);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
scene.add(sun.target);
// -------------------------------------------------------------------------
// Shared geometry and materials
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function makeMaterial(color, roughness = 0.85, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const stuccoMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9
});
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.56,
metalness: 0.02
});
const backingMaterial = makeMaterial(0x9d8064, 0.98);
const stoneMaterial = makeMaterial(0xc9b99d, 0.92);
const darkMaterial = makeMaterial(0x243333, 0.72);
const ironMaterial = makeMaterial(0x303536, 0.48, 0.48);
const woodMaterial = makeMaterial(0x674735, 0.88);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x38535a,
roughness: 0.25,
metalness: 0.15,
emissive: 0x102125,
emissiveIntensity: 0.25
});
const greenMaterial = makeMaterial(0x426a60, 0.75);
const flowerRedMaterial = makeMaterial(0xa9453e, 0.85);
const flowerYellowMaterial = makeMaterial(0xd2a444, 0.85);
function addBox(
size,
position,
material,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function addInstanceBoxes(entries, material, castShadow = true) {
const mesh = new THREE.InstancedMesh(
unitBox,
material,
entries.length
);
const dummy = new THREE.Object3D();
entries.forEach((entry, index) => {
dummy.position.set(
entry.position[0],
entry.position[1],
entry.position[2]
);
dummy.scale.set(entry.size[0], entry.size[1], entry.size[2]);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (entry.color !== undefined) {
mesh.setColorAt(index, new THREE.Color(entry.color));
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Procedural Portuguese-style azulejo texture
// -------------------------------------------------------------------------
function createAzulejoTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#eee7d2";
ctx.fillRect(0, 0, 256, 256);
const blue = "#315f8a";
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 2; col++) {
const ox = col * 128;
const oy = row * 128;
ctx.fillStyle = row === col ? "#f4ecd7" : "#e8e2cf";
ctx.fillRect(ox, oy, 128, 128);
ctx.strokeStyle = blue;
ctx.lineWidth = 5;
ctx.strokeRect(ox + 8, oy + 8, 112, 112);
ctx.lineWidth = 2;
ctx.strokeRect(ox + 16, oy + 16, 96, 96);
ctx.save();
ctx.translate(ox + 64, oy + 64);
ctx.strokeStyle = blue;
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(0, -31);
ctx.lineTo(31, 0);
ctx.lineTo(0, 31);
ctx.lineTo(-31, 0);
ctx.closePath();
ctx.stroke();
ctx.fillStyle = blue;
for (let petal = 0; petal < 4; petal++) {
ctx.save();
ctx.rotate((Math.PI / 2) * petal);
ctx.beginPath();
ctx.ellipse(0, -16, 8, 16, 0, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
ctx.fillStyle = "#eee7d2";
ctx.beginPath();
ctx.arc(0, 0, 7, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = blue;
ctx.lineWidth = 2;
ctx.stroke();
ctx.restore();
ctx.fillStyle = blue;
[
[ox + 27, oy + 27],
[ox + 101, oy + 27],
[ox + 27, oy + 101],
[ox + 101, oy + 101]
].forEach(([x, y]) => {
ctx.beginPath();
ctx.arc(x, y, 4, 0, Math.PI * 2);
ctx.fill();
});
}
}
ctx.strokeStyle = "rgba(49, 95, 138, 0.42)";
ctx.lineWidth = 2;
ctx.strokeRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
tileMaterial.map = createAzulejoTexture();
tileMaterial.needsUpdate = true;
// -------------------------------------------------------------------------
// Cobblestone paving made from low voxel blocks
// -------------------------------------------------------------------------
const paving = [];
const pavingStep = 0.55;
const pavingWidth = 9.8;
const pavingLength = 24.5;
const pavingStartZ = -10.4;
for (let x = -pavingWidth / 2 + 0.25; x < pavingWidth / 2; x += pavingStep) {
for (
let z = pavingStartZ;
z < pavingStartZ + pavingLength;
z += pavingStep
) {
const variation = 0.88 + Math.random() * 0.15;
const warm = Math.random() > 0.88 ? 0xd0b99b : 0xb8aa96;
paving.push({
size: [0.515, 0.075, 0.515],
position: [x, -0.037 + Math.random() * 0.009, z],
color: new THREE.Color(warm).multiplyScalar(variation)
});
}
}
addInstanceBoxes(paving, stuccoMaterial, false);
// A shallow central drainage line emphasizes the pedestrian route.
addBox(
[0.16, 0.035, 23.4],
[0.2, 0.012, 0.1],
makeMaterial(0x625d53, 0.98),
scene,
false
);
// -------------------------------------------------------------------------
// Historic facades
// -------------------------------------------------------------------------
function addWindow(side, z, y, addBalcony, flowerColor = null) {
const recessX = side * 4.37;
const frameX = side * 3.91;
addBox(
[0.1, 1.08, 1.08],
[recessX, y, z],
glassMaterial
);
// Stone frame.
addBox([0.18, 1.34, 0.12], [frameX, y, z - 0.65], stoneMaterial);
addBox([0.18, 1.34, 0.12], [frameX, y, z + 0.65], stoneMaterial);
addBox([0.18, 0.13, 1.42], [frameX, y + 0.61, z], stoneMaterial);
addBox([0.18, 0.13, 1.42], [frameX, y - 0.61, z], stoneMaterial);
// Central mullion and horizontal divider.
addBox([0.12, 1.12, 0.07], [frameX, y, z], woodMaterial);
addBox([0.12, 0.07, 1.12], [frameX, y, z], woodMaterial);
// Timber shutters folded beside the opening.
addBox(
[0.11, 1.0, 0.31],
[side * 3.94, y, z - 0.82],
woodMaterial
);
if (addBalcony) {
const balconyY = y - 0.69;
// Projecting slab.
addBox(
[1.38, 0.14, 1.82],
[side * 3.55, balconyY, z],
stoneMaterial
);
// Inner railing.
const railX = side * 2.88;
addBox(
[0.1, 0.09, 1.76],
[railX, balconyY + 0.73, z],
ironMaterial
);
addBox(
[0.08, 0.08, 1.76],
[railX, balconyY + 0.25, z],
ironMaterial
);
for (let post = -3; post <= 3; post++) {
addBox(
[0.07, 0.58, 0.07],
[railX, balconyY + 0.38, z + post * 0.24],
ironMaterial
);
}
// Short returns at the ends of the balcony.
for (const sideZ of [-0.88, 0.88]) {
addBox(
[1.3, 0.08, 0.08],
[side * 3.55, balconyY + 0.73, z + sideZ],
ironMaterial
);
addBox(
[0.07, 0.58, 0.07],
[railX, balconyY + 0.38, z + sideZ],
ironMaterial
);
}
} else if (flowerColor !== null) {
addBox(
[0.38, 0.19, 1.05],
[side * 3.76, y - 0.72, z],
woodMaterial
);
for (let flower = 0; flower < 5; flower++) {
addBox(
[0.16, 0.12, 0.16],
[
side * 3.67,
y - 0.58,
z - 0.4 + flower * 0.2
],
flowerColor
);
}
}
}
function addDoor(side, z) {
const recessX = side * 4.37;
const frameX = side * 3.91;
addBox(
[0.12, 1.76, 1.08],
[recessX, 0.9, z],
greenMaterial
);
addBox([0.2, 0.15, 1.42], [frameX, 1.83, z], stoneMaterial);
addBox([0.2, 1.9, 0.13], [frameX, 0.93, z - 0.64], stoneMaterial);
addBox([0.2, 1.9, 0.13], [frameX, 0.93, z + 0.64], stoneMaterial);
// Panel inset and handle.
addBox(
[0.12, 1.2, 0.7],
[side * 4.25, 0.9, z],
woodMaterial
);
addBox(
[0.13, 0.09, 0.09],
[side * 3.98, 0.92, z + 0.25],
ironMaterial
);
// Step.
addBox(
[0.55, 0.12, 1.48],
[side * 3.92, 0.06, z],
stoneMaterial
);
// Small decorative azulejo panel above the doorway.
addBox(
[0.07, 0.48, 0.74],
[side * 3.91, 2.14, z],
tileMaterial
);
}
function createFacade({
side,
z0,
length,
height,
color,
tiled,
seed
}) {
const facadeX = side * 4.25;
const material = tiled ? tileMaterial : stuccoMaterial;
// Solid building mass behind the voxel facade.
addBox(
[1.25, height, length],
[side * 4.88, height / 2, z0 + length / 2],
backingMaterial
);
const blocks = [];
const spacing = 0.6;
const cubeSize = 0.555;
const windowOffsets = [1.8, 4.2, 6.6].filter(
(offset) => offset < length - 1.05
);
const doorZ = z0 + 3.0;
const floors = height > 5.5 ? [1.8, 4.0] : [1.8];
for (
let z = z0 + 0.3;
z < z0 + length - 0.2;
z += spacing
) {
for (
let y = 0.3;
y < height - 0.1;
y += spacing
) {
let opening = false;
for (const floor of floors) {
for (const offset of windowOffsets) {
if (
Math.abs(z - (z0 + offset)) < 0.61 &&
y > floor - 0.6 &&
y < floor + 0.6
) {
opening = true;
}
}
}
if (
Math.abs(z - doorZ) < 0.61 &&
y < 1.8
) {
opening = true;
}
if (!opening) {
const shade = 0.9 + Math.random() * 0.12;
const blockColor = tiled
? new THREE.Color(0xffffff).multiplyScalar(shade)
: new THREE.Color(color).multiplyScalar(shade);
blocks.push({
size: [cubeSize, cubeSize, cubeSize],
position: [facadeX, y, z],
color: blockColor
});
}
}
}
addInstanceBoxes(blocks, material);
// Continuous cornice and plinth emphasize the stepped voxel silhouette.
addBox(
[0.2, 0.14, length + 0.12],
[side * 3.91, height - 0.03, z0 + length / 2],
stoneMaterial
);
addBox(
[0.2, 0.18, length + 0.08],
[side * 3.93, 0.13, z0 + length / 2],
stoneMaterial
);
// Upper roof blocks.
const roofBlocks = [];
for (
let z = z0 + 0.3;
z < z0 + length - 0.2;
z += spacing
) {
roofBlocks.push({
size: [0.58, 0.3, 0.58],
position: [facadeX, height + 0.12, z],
color: new THREE.Color(color).multiplyScalar(0.86)
});
}
addInstanceBoxes(roofBlocks, stuccoMaterial);
addDoor(side, doorZ);
windowOffsets.forEach((offset, windowIndex) => {
floors.forEach((floor, floorIndex) => {
const hasBalcony =
floorIndex === 0 &&
(seed + windowIndex) % 2 === 0;
const flowerColors = [
flowerRedMaterial,
flowerYellowMaterial,
greenMaterial
];
addWindow(
side,
z0 + offset,
floor,
hasBalcony,
hasBalcony
? null
: flowerColors[(seed + windowIndex) % flowerColors.length]
);
});
});
}
createFacade({
side: -1,
z0: -8.4,
length: 6.2,
height: 6.3,
color: 0xe3c693,
tiled: true,
seed: 0
});
createFacade({
side: -1,
z0: -2.0,
length: 6.4,
height: 6.9,
color: 0xcf8c72,
tiled: false,
seed: 2
});
createFacade({
side: -1,
z0: 4.6,
length: 5.2,
height: 5.7,
color: 0xd9b676,
tiled: true,
seed: 4
});
createFacade({
side: 1,
z0: -8.4,
length: 6.8,
height: 6.6,
color: 0xe1b080,
tiled: false,
seed: 1
});
createFacade({
side: 1,
z0: -1.4,
length: 6.5,
height: 6.1,
color: 0x9eb8b3,
tiled: true,
seed: 3
});
createFacade({
side: 1,
z0: 5.3,
length: 4.5,
height: 6.6,
color: 0xd7a17c,
tiled: true,
seed: 5
});
// -------------------------------------------------------------------------
// Voxel arch closing the distant end of the passage
// -------------------------------------------------------------------------
const endBlocks = [];
for (
let x = -4.05;
x <= 4.05;
x += 0.6
) {
for (
let y = 0.3;
y <= 6.0;
y += 0.6
) {
const inDoor = Math.abs(x) < 1.2 && y < 2.4;
const archWidth =
1.8 - Math.max(0, y - 2.4) * 0.9;
const inArch =
y >= 2.4 &&
y < 3.7 &&
Math.abs(x) < archWidth;
if (!inDoor && !inArch) {
endBlocks.push({
size: [0.565, 0.565, 0.565],
position: [x, y, -9.35],
color: new THREE.Color(0xd7a078).multiplyScalar(
0.9 + Math.random() * 0.13
)
});
}
}
}
addInstanceBoxes(endBlocks, stuccoMaterial);
// A warm opening beyond the arch suggests a sunlit street.
const beyondMaterial = new THREE.MeshBasicMaterial({
color: 0xf1cf8e
});
addBox(
[2.45, 3.65, 0.08],
[0, 1.75, -10.05],
beyondMaterial,
scene,
false,
false
);
addBox(
[0.24, 0.24, 0.65],
[0, 3.65, -9.32],
stoneMaterial
);
// -------------------------------------------------------------------------
// Voxel pedestrian
// -------------------------------------------------------------------------
const pedestrian = new THREE.Group();
scene.add(pedestrian);
const skinMaterial = makeMaterial(0x865b42, 0.92);
const shirtMaterial = makeMaterial(0xe6d6b7, 0.92);
const trousersMaterial = makeMaterial(0x344c59, 0.92);
const shoesMaterial = makeMaterial(0x302c29, 0.85);
const hatMaterial = makeMaterial(0xb89b68, 0.95);
const bagMaterial = makeMaterial(0x8b4939, 0.88);
// Torso and hips.
addBox(
[0.46, 0.62, 0.3],
[0, 1.03, 0],
shirtMaterial,
pedestrian
);
addBox(
[0.4, 0.2, 0.28],
[0, 0.67, 0],
trousersMaterial,
pedestrian
);
// Neck and head.
addBox(
[0.18, 0.16, 0.18],
[0, 1.4, 0],
skinMaterial,
pedestrian
);
addBox(
[0.34, 0.36, 0.34],
[0, 1.63, 0],
skinMaterial,
pedestrian
);
// Hat and brim.
addBox(
[0.38, 0.16, 0.36],
[0, 1.83, 0],
hatMaterial,
pedestrian
);
addBox(
[0.5, 0.06, 0.48],
[0, 1.77, 0],
hatMaterial,
pedestrian
);
function makeLimb(size, position, material) {
const pivot = new THREE.Group();
pivot.position.set(...position);
pedestrian.add(pivot);
addBox(
size,
[0, -size[1] / 2, 0],
material,
pivot
);
return pivot;
}
const leftLeg = makeLimb(
[0.18, 0.62, 0.22],
[-0.11, 0.65, 0],
trousersMaterial
);
const rightLeg = makeLimb(
[0.18, 0.62, 0.22],
[0.11, 0.65, 0],
trousersMaterial
);
addBox(
[0.2, 0.12, 0.32],
[0, -0.62, -0.04],
shoesMaterial,
leftLeg
);
addBox(
[0.2, 0.12, 0.32],
[0, -0.62, -0.04],
shoesMaterial,
rightLeg
);
const leftArm = makeLimb(
[0.15, 0.56, 0.18],
[-0.3, 1.25, 0],
shirtMaterial
);
const rightArm = makeLimb(
[0.15, 0.56, 0.18],
[0.3, 1.25, 0],
shirtMaterial
);
addBox(
[0.14, 0.16, 0.14],
[0, -0.58, 0],
skinMaterial,
leftArm
);
addBox(
[0.14, 0.16, 0.14],
[0, -0.58, 0],
skinMaterial,
rightArm
);
// Shoulder bag.
addBox(
[0.31, 0.36, 0.15],
[0.3, 0.91, -0.02],
bagMaterial,
pedestrian
);
addBox(
[0.08, 0.56, 0.08],
[0.27, 1.2, 0.08],
bagMaterial,
pedestrian
);
pedestrian.position.set(0.15, 0, 3.0);
// -------------------------------------------------------------------------
// Small street details
// -------------------------------------------------------------------------
// Wall lamps beside selected doors.
for (const side of [-1, 1]) {
const z = side < 0 ? -1.7 : 3.8;
addBox(
[0.15, 0.15, 0.15],
[side * 3.8, 2.55, z],
ironMaterial
);
addBox(
[0.28, 0.38, 0.28],
[side * 3.68, 2.5, z],
new THREE.MeshStandardMaterial({
color: 0xf4d28d,
emissive: 0x7b4c19,
emissiveIntensity: 0.35,
roughness: 0.6
})
);
}
// -------------------------------------------------------------------------
// Direct camera controls — no examples/addons
// -------------------------------------------------------------------------
let dragging = false;
let lastX = 0;
let lastY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
cameraState.yaw -= dx * 0.005;
cameraState.pitch += dy * 0.004;
cameraState.yaw = THREE.MathUtils.clamp(
cameraState.yaw,
-0.95,
0.95
);
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch,
0.08,
0.68
);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.015,
9,
31
);
updateCamera();
},
{ passive: false }
);
function resetView() {
cameraState.yaw = 0;
cameraState.pitch = 0.29;
cameraState.radius = 23.5;
cameraState.target.set(0, 2.25, -1.35);
updateCamera();
}
document.getElementById("resetView").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.yaw -= 0.08;
if (event.key === "ArrowRight") cameraState.yaw += 0.08;
if (event.key === "ArrowUp") cameraState.pitch += 0.05;
if (event.key === "ArrowDown") cameraState.pitch -= 0.05;
if (event.key === "+" || event.key === "=") {
cameraState.radius -= 1;
}
if (event.key === "-") cameraState.radius += 1;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch,
0.08,
0.68
);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius,
9,
31
);
updateCamera();
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const walkPhase = elapsed * 3.7;
// Slow walk through the shaded route. The sunlight never moves.
pedestrian.position.z = 3.0 - ((elapsed * 0.38) % 11.2);
pedestrian.position.x = 0.12 + Math.sin(elapsed * 0.7) * 0.08;
pedestrian.position.y = Math.abs(Math.sin(walkPhase)) * 0.035;
const stride = Math.sin(walkPhase) * 0.42;
leftLeg.rotation.x = stride;
rightLeg.rotation.x = -stride;
leftArm.rotation.x = -stride * 0.7;
rightArm.rotation.x = stride * 0.7;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```