Prompt specification
Build or customize the Three.js 3D scene "Yanaka Ginza street-and-stair slice" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Yanaka Ginza street-and-stair slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/yanaka-ginza-street-and-stair-slice-x3039
Scene Description Prompt:
A voxel Yanaka Ginza street in Tokyo, with low-rise shops, everyday activity, and a connecting staircase. Use Three.js from cdnjs in standalone HTML.
Working Three.js Starter (yanaka-ginza-street-and-stair-slice-x3039):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Yanaka Ginza — Voxel Tokyo</title>
<style>
:root {
color-scheme: dark;
--ink: #fff9ec;
--muted: rgba(255, 249, 236, 0.68);
--glass: rgba(24, 24, 25, 0.72);
--line: rgba(255, 249, 236, 0.16);
--accent: #ffbf69;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eabf9e;
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;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--ink);
}
.title {
position: absolute;
top: 26px;
left: 28px;
max-width: min(430px, calc(100vw - 56px));
text-shadow: 0 2px 18px rgba(54, 28, 16, 0.35);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
padding: 6px 10px;
border: 1px solid rgba(255,255,255,0.28);
border-radius: 999px;
background: rgba(45, 35, 30, 0.2);
backdrop-filter: blur(10px);
color: rgba(255,255,255,0.84);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 5vw, 68px);
font-weight: 500;
line-height: 0.93;
letter-spacing: -0.055em;
}
h1 span {
display: block;
margin-top: 10px;
color: rgba(255,255,255,0.76);
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.28em;
text-transform: uppercase;
}
.caption {
position: absolute;
left: 28px;
bottom: 25px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--glass);
backdrop-filter: blur(14px);
color: var(--muted);
font-size: 11px;
line-height: 1.65;
box-shadow: 0 12px 40px rgba(40, 20, 12, 0.14);
}
.caption strong {
color: var(--ink);
font-weight: 650;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 7px;
pointer-events: auto;
}
.controls button {
width: 38px;
height: 38px;
padding: 0;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--glass);
color: var(--ink);
font: 600 17px/1 system-ui, sans-serif;
cursor: pointer;
backdrop-filter: blur(12px);
transition: background 150ms, transform 150ms;
}
.controls button:hover {
background: rgba(50, 45, 42, 0.9);
transform: translateY(-2px);
}
.controls button:last-child {
width: auto;
padding: 0 13px;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.badge {
position: absolute;
top: 26px;
right: 26px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--glass);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
@media (max-width: 640px) {
.title { top: 18px; left: 18px; }
.caption { left: 14px; bottom: 14px; max-width: 230px; }
.controls { right: 14px; bottom: 14px; }
.badge { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel view of Yanaka Ginza, Tokyo"></canvas>
<div class="hud">
<div class="title">
<div class="eyebrow">Tokyo · late afternoon</div>
<h1>Yanaka Ginza<span>Shōwa-era neighborhood study</span></h1>
</div>
<div class="badge">35.7272° N · 139.7668° E</div>
<div class="caption">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom<br>
Arrow keys to look around · <strong>R</strong> to reset
</div>
<div class="controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="reset" title="Reset camera">Reset</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8bfa2);
scene.fog = new THREE.Fog(0xe8bfa2, 27, 64);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemi = new THREE.HemisphereLight(0xffead1, 0x62596b, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffd4a0, 3.1);
sun.position.set(-15, 24, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ec5dc, 0.65);
fill.position.set(12, 10, -16);
scene.add(fill);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(...size);
const material = options.material || getMaterial(color);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, thickness, color) {
const va = new THREE.Vector3(...a);
const vb = new THREE.Vector3(...b);
const direction = vb.clone().sub(va);
const mesh = box(
parent,
[thickness, thickness, direction.length()],
va.clone().add(vb).multiplyScalar(0.5).toArray(),
color
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
return mesh;
}
function makeTextTexture(text, background, foreground, sub = "", vertical = false) {
const c = document.createElement("canvas");
c.width = vertical ? 192 : 768;
c.height = vertical ? 768 : 192;
const ctx = c.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.35;
ctx.lineWidth = vertical ? 5 : 7;
ctx.strokeRect(8, 8, c.width - 16, c.height - 16);
ctx.globalAlpha = 1;
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
if (vertical) {
const chars = [...text];
const spacing = Math.min(112, 620 / chars.length);
const start = c.height / 2 - ((chars.length - 1) * spacing) / 2;
ctx.font = `700 ${Math.min(72, spacing * 0.82)}px "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif`;
chars.forEach((char, i) => ctx.fillText(char, c.width / 2, start + i * spacing));
} else {
ctx.font = `700 58px "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif`;
ctx.fillText(text, c.width / 2, sub ? 70 : c.height / 2, c.width - 50);
if (sub) {
ctx.globalAlpha = 0.8;
ctx.font = `600 25px Inter, system-ui, sans-serif`;
ctx.letterSpacing = "4px";
ctx.fillText(sub, c.width / 2, 138, c.width - 60);
ctx.globalAlpha = 1;
}
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function signPlane(parent, texture, size, position, rotationY = 0) {
const material = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(...size), material);
mesh.position.set(...position);
mesh.rotation.y = rotationY;
parent.add(mesh);
return mesh;
}
// Street and sidewalks
box(scene, [80, 0.25, 90], [0, -0.32, 0], 0xb7a18e);
box(scene, [8.2, 0.22, 40], [0, -0.1, 0], 0x555356);
box(scene, [0.08, 0.012, 39], [0, 0.018, 0], 0xd6b780, { castShadow: false });
for (let z = -18; z < 19; z += 3.5) {
box(scene, [0.09, 0.018, 1.35], [0, 0.025, z], 0xe6ca94, { castShadow: false });
}
for (const side of [-1, 1]) {
box(scene, [5.8, 0.28, 40], [side * 7.1, 0.02, 0], 0xa9a09a);
box(scene, [0.18, 0.38, 40], [side * 4.2, 0.05, 0], 0xc5b6a5);
for (let z = -19; z < 20; z += 1.35) {
box(scene, [0.025, 0.014, 1.12], [side * 5.25, 0.17, z], 0xc8beb2, {
castShadow: false
});
}
}
// Zebra crossing
for (let i = 0; i < 9; i++) {
box(
scene,
[0.57, 0.018, 2.15],
[-3.35 + i * 0.83, 0.027, 11.6],
0xe8e1d0,
{ castShadow: false }
);
}
// Drain and utility covers
for (const z of [-12, 2.5, 16]) {
box(scene, [0.55, 0.025, 0.8], [2.3, 0.025, z], 0x414044, {
castShadow: false
});
}
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x31505b,
emissive: 0x18343d,
emissiveIntensity: 0.5,
roughness: 0.28,
metalness: 0.18,
transparent: true,
opacity: 0.88
});
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x344d58,
emissive: 0x111d25,
emissiveIntensity: 0.38,
roughness: 0.3,
metalness: 0.22
});
const shopData = [
{
side: -1, z: -13.2, height: 5.2, color: 0xd98572,
name: "花と青物", sub: "FLOWERS & GREENS", vertical: "生花"
},
{
side: -1, z: -6.6, height: 6.4, color: 0xd8bd8b,
name: "喫茶 むぎ", sub: "COFFEE", vertical: "喫茶"
},
{
side: -1, z: 0, height: 4.9, color: 0x9ab6a0,
name: "古道具", sub: "ANTIQUE GOODS", vertical: "古道具"
},
{
side: -1, z: 6.6, height: 6.1, color: 0xd9b55d,
name: "やなか食堂", sub: "HOME COOKING", vertical: "食堂"
},
{
side: -1, z: 13.2, height: 5.0, color: 0x7898aa,
name: "洋品店", sub: "CLOTHING", vertical: "洋品"
},
{
side: 1, z: -13.2, height: 6.2, color: 0xb7aa92,
name: "SPON", sub: "BAKERY & COFFEE", vertical: "パン"
},
{
side: 1, z: -6.6, height: 4.7, color: 0xc9876c,
name: "青葉堂", sub: "TOBACCO & STATIONERY", vertical: "青葉堂"
},
{
side: 1, z: 0, height: 6.4, color: 0x9ba9b5,
name: "天文舎", sub: "CAMERAS & BOOKS", vertical: "写真"
},
{
side: 1, z: 6.6, height: 5.3, color: 0xc7ae79,
name: "小料理", sub: "LITTLE KITCHEN", vertical: "小料理"
},
{
side: 1, z: 13.2, height: 6.0, color: 0xa7929f,
name: "銀座レコード", sub: "RECORDS", vertical: "レコード"
}
];
function makeBuilding(data) {
const group = new THREE.Group();
scene.add(group);
const { side, z, height, color } = data;
const front = side * 5.3;
const inwardRotation = side === 1 ? -Math.PI / 2 : Math.PI / 2;
box(group, [4.8, height, 5.8], [side * 7.7, 0.18 + height / 2, z], color);
box(group, [4.95, 0.15, 5.95], [side * 7.7, 0.18 + height, z], 0x655e59);
box(group, [0.15, 0.42, 5.85], [front - side * 0.01, 0.38, z], 0x625e59);
const glass = new THREE.Mesh(new THREE.PlaneGeometry(4.85, 1.58), glassMaterial);
glass.rotation.y = inwardRotation;
glass.position.set(side * 5.255, 1.18, z);
group.add(glass);
for (const dz of [-2.48, 0, 2.48]) {
box(group, [0.12, 1.86, 0.09], [side * 5.20, 1.18, z + dz], 0x4d4948);
}
box(group, [0.12, 0.10, 5.08], [side * 5.20, 1.96, z], 0x4d4948);
box(group, [0.12, 0.10, 5.08], [side * 5.20, 0.40, z], 0x4d4948);
// Striped awning
for (let i = 0; i < 9; i++) {
box(
group,
[1.22, 0.12, 0.55],
[side * 4.73, 2.03, z - 2.45 + i * 0.61],
i % 2 ? 0xf0dfbd : 0x9d5f50
);
}
box(group, [1.28, 0.22, 5.7], [side * 4.73, 1.91, z], 0x584a43);
const signTexture = makeTextTexture(
data.name,
"#f0dfbd",
"#443a35",
data.sub,
false
);
signPlane(
group,
signTexture,
[3.95, 0.67],
[side * 5.16, 2.63, z],
inwardRotation
);
// Projecting vertical shop sign
const verticalTexture = makeTextTexture(
data.vertical,
"#eee0c2",
"#343438",
"",
true
);
box(group, [0.16, 2.75, 0.92], [side * 4.88, 3.65, z + 2.16], 0x514947);
signPlane(
group,
verticalTexture,
[0.77, 2.58],
[side * 4.785, 3.65, z + 2.16],
inwardRotation
);
// Upper-floor windows and trim
const rows = height > 5.7 ? [3.8, 5.45] : [3.8];
rows.forEach((y, rowIndex) => {
box(group, [0.14, 0.10, 5.35], [side * 5.25, y - 0.72, z], 0xe3d5be);
for (const dz of [-1.72, 0, 1.72]) {
const window = new THREE.Mesh(
new THREE.PlaneGeometry(1.12, 1.2),
windowMaterial
);
window.rotation.y = inwardRotation;
window.position.set(side * 5.255, y, z + dz);
group.add(window);
box(group, [0.12, 1.36, 0.09], [side * 5.20, y, z + dz - 0.61], 0x514f4d);
box(group, [0.12, 1.36, 0.09], [side * 5.20, y, z + dz + 0.61], 0x514f4d);
box(group, [0.12, 0.09, 1.31], [side * 5.20, y + 0.66, z + dz], 0x514f4d);
box(group, [0.12, 0.09, 1.31], [side * 5.20, y - 0.66, z + dz], 0x514f4d);
box(group, [0.13, 1.22, 0.06], [side * 5.19, y, z + dz], 0x625d58);
if (rowIndex === 0 && dz === 0) {
box(group, [0.62, 0.52, 0.78], [side * 4.97, y - 0.1, z + dz], 0xc3beb3);
for (let g = 0; g < 4; g++) {
box(
group,
[0.03, 0.045, 0.65],
[side * 4.64, y - 0.26 + g * 0.10, z + dz],
0x777872,
{ castShadow: false }
);
}
}
}
});
// Rooftop utility boxes and water tank
box(group, [1.25, 0.78, 1.4], [side * 7.55, height + 0.63, z - 1.1], 0x9a9b96);
box(group, [0.18, 0.38, 0.18], [side * 7.55, height + 1.18, z - 1.1], 0x70716e);
box(group, [0.9, 0.85, 0.9], [side * 8.6, height + 0.58, z + 1.3], 0x8b8176);
box(group, [0.55, 0.30, 0.55], [side * 6.5, height + 0.31, z + 1.7], 0x77736f);
// Small air vents and pipes
box(group, [0.11, height - 0.7, 0.11], [side * 5.15, (height + 0.5) / 2, z - 2.7], 0x77716a);
}
shopData.forEach(makeBuilding);
// Connecting staircase and elevated passage
const stairGroup = new THREE.Group();
scene.add(stairGroup);
const stepCount = 12;
const stepRun = 0.58;
const stepRise = 0.28;
const stairX = 4.32;
const stairBottomZ = 1.5;
for (let i = 0; i < stepCount; i++) {
const height = (i + 1) * stepRise;
box(
stairGroup,
[1.58, height, stepRun],
[stairX, 0.18 + height / 2, stairBottomZ - i * stepRun],
i % 2 ? 0x777777 : 0x828080
);
box(
stairGroup,
[1.47, 0.025, 0.08],
[stairX, 0.19 + height, stairBottomZ - i * stepRun + stepRun / 2 - 0.04],
0xc4b58a,
{ castShadow: false }
);
}
box(stairGroup, [1.75, 0.18, 1.45], [stairX, 3.45, -6.02], 0x6f7170);
box(stairGroup, [10.35, 0.18, 1.18], [0, 3.45, -6.02], 0x727472);
for (const x of [-4.2, -1.4, 1.4, 4.2]) {
box(stairGroup, [0.18, 3.36, 0.18], [x, 1.68, -6.02], 0x686b69);
}
box(stairGroup, [8.9, 0.14, 0.14], [0, 1.18, -6.02], 0x6a6d6b);
for (const x of [stairX - 0.82, stairX + 0.82]) {
beam(
stairGroup,
[x, 1.25, stairBottomZ + 0.15],
[x, 4.27, stairBottomZ - (stepCount - 1) * stepRun],
0.085,
0x3f4544
);
for (let i = 0; i < stepCount; i += 3) {
const z = stairBottomZ - i * stepRun;
const floor = 0.18 + (i + 1) * stepRise;
box(stairGroup, [0.085, 0.82, 0.085], [x, floor + 0.41, z], 0x454a48);
}
}
for (const z of [-6.65, -5.38]) {
beam(stairGroup, [-5.16, 4.28, z], [5.16, 4.28, z], 0.075, 0x3f4544);
for (let x = -5; x <= 5; x += 1.25) {
box(stairGroup, [0.075, 0.82, 0.075], [x, 3.95, z], 0x454a48);
}
}
const passageTexture = makeTextTexture(
"連絡階段",
"#d5b978",
"#35383a",
"CONNECTING PASSAGE",
false
);
signPlane(stairGroup, passageTexture, [3.4, 0.66], [0, 4.05, -5.40]);
// Street lamps
function addStreetLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.18, z);
scene.add(group);
box(group, [0.13, 3.8, 0.13], [0, 1.9, 0], 0x454646);
box(group, [0.65, 0.12, 0.22], [-0.24, 3.78, 0], 0x454646);
box(
group,
[0.46, 0.16, 0.38],
[-0.47, 3.67, 0],
0xffdca0,
{ material: new THREE.MeshStandardMaterial({
color: 0xffdca0,
emissive: 0xffa63d,
emissiveIntensity: 1.7,
roughness: 0.5
})}
);
}
addStreetLamp(-4.55, 4.2);
addStreetLamp(-4.55, -10.4);
addStreetLamp(4.62, 14.6);
addStreetLamp(4.62, -11.5);
// Utility poles and wires
for (const z of [-10, 4, 15]) {
for (const side of [-1, 1]) {
box(scene, [0.16, 6.3, 0.16], [side * 10.35, 3.15, z], 0x655e58);
box(scene, [1.2, 0.13, 0.13], [side * 9.9, 5.75, z], 0x595550);
}
}
function addSaggingWire(z, y, offset = 0) {
const points = [];
for (let i = 0; i <= 16; i++) {
const t = i / 16;
const x = -10.4 + t * 20.8;
const sag = Math.sin(t * Math.PI) * 0.55;
points.push(new THREE.Vector3(x, y - sag + offset, z));
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
scene.add(new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color: 0x393a3b, transparent: true, opacity: 0.82 })
));
}
addSaggingWire(-10, 5.72);
addSaggingWire(-10, 5.35, 0.18);
addSaggingWire(4, 5.72);
addSaggingWire(4, 5.35, 0.18);
addSaggingWire(15, 5.72);
addSaggingWire(15, 5.35, 0.18);
// Festoon bulbs
const bulbMaterial = new THREE.MeshStandardMaterial({
color: 0xffd48c,
emissive: 0xff963b,
emissiveIntensity: 1.4,
roughness: 0.45
});
const festoon = [];
for (let i = 0; i <= 14; i++) {
const t = i / 14;
const x = -4.25 + t * 8.5;
const y = 4.75 - Math.sin(t * Math.PI) * 0.75;
const bulb = box(scene, [0.12, 0.17, 0.12], [x, y, 7.85], 0xffd48c, {
material: bulbMaterial,
castShadow: false
});
festoon.push(bulb);
}
// Vending machine
const vending = new THREE.Group();
vending.position.set(4.85, 0.18, 3.3);
vending.rotation.y = -Math.PI / 2;
scene.add(vending);
box(vending, [1.03, 1.82, 0.72], [0, 0.91, 0], 0xbc4e43);
box(vending, [0.84, 1.23, 0.04], [-0.05, 1.04, 0.38], 0xe7e1ce);
box(vending, [0.73, 0.36, 0.05], [-0.05, 0.34, 0.38], 0x31383b);
const drinkColors = [0xe9684f, 0x68a9c1, 0xe7bd4d, 0x6fa36c, 0xd98daf];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 4; col++) {
box(
vending,
[0.12, 0.19, 0.045],
[-0.33 + col * 0.17, 0.67 + row * 0.28, 0.42],
drinkColors[(row + col) % drinkColors.length],
{ castShadow: false }
);
}
}
// Bicycle
const bicycle = new THREE.Group();
bicycle.position.set(-4.86, 0.2, 1.1);
bicycle.rotation.y = -0.13;
scene.add(bicycle);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x303132,
roughness: 0.72
});
for (const z of [-0.62, 0.62]) {
const wheel = new THREE.Mesh(
new THREE.TorusGeometry(0.37, 0.045, 6, 16),
wheelMaterial
);
wheel.position.set(0, 0.42, z);
bicycle.add(wheel);
}
beam(bicycle, [0, 0.42, -0.62], [0, 0.48, 0.05], 0.055, 0x8e5144);
beam(bicycle, [0, 0.48, 0.05], [0, 0.42, 0.62], 0.055, 0x8e5144);
beam(bicycle, [0, 0.42, 0.62], [0, 0.95, 0.13], 0.055, 0x8e5144);
beam(bicycle, [0, 0.42, -0.62], [0, 0.92, -0.12], 0.055, 0x8e5144);
beam(bicycle, [0, 0.92, -0.12], [0, 0.95, 0.13], 0.055, 0x8e5144);
box(bicycle, [0.3, 0.08, 0.28], [0, 1.0, -0.12], 0x303132);
box(bicycle, [0.52, 0.06, 0.08], [0, 1.11, 0.13], 0x303132);
// Planters, bins, benches and café furniture
function planter(x, z, size = 1) {
box(scene, [0.62 * size, 0.42 * size, 0.62 * size], [x, 0.39 * size, z], 0x8b6251);
box(scene, [0.5 * size, 0.08 * size, 0.5 * size], [x, 0.59 * size, z], 0x4b493d);
box(scene, [0.48 * size, 0.78 * size, 0.48 * size], [x, 0.9 * size, z], 0x607b52);
box(scene, [0.35 * size, 0.55 * size, 0.4 * size], [x + 0.12 * size, 1.24 * size, z], 0x789363);
}
planter(-4.8, 8.2, 0.9);
planter(-4.85, -3.0, 1.05);
planter(4.82, 8.5, 0.85);
planter(4.85, -13.4, 1.1);
planter(-10.4, 0.5, 1.25);
planter(10.4, 8.2, 1.2);
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.18, z);
group.rotation.y = rotation;
scene.add(group);
box(group, [0.68, 0.12, 1.8], [0, 0.62, 0], 0x99704d);
box(group, [0.12, 0.65, 1.8], [0.28, 1.0, 0], 0x99704d);
for (const z2 of [-0.62, 0.62]) {
box(group, [0.48, 0.58, 0.12], [0, 0.3, z2], 0x4d4c4b);
}
}
bench(-4.73, 9.6, Math.PI / 2);
bench(4.7, -9.5, -Math.PI / 2);
for (const z of [3.8, 12.6]) {
box(scene, [0.58, 0.82, 0.58], [-4.78, 0.59, z], 0x55585a);
box(scene, [0.62, 0.08, 0.62], [-4.78, 1.03, z], 0x3f4243);
}
// Tiny café tables
for (const [x, z] of [[-4.8, 5.0], [-4.8, 5.9], [4.75, -1.4], [4.75, -2.3]]) {
box(scene, [0.55, 0.08, 0.55], [x, 0.82, z], 0xc58b56);
box(scene, [0.09, 0.68, 0.09], [x, 0.48, z], 0x55504c);
box(scene, [0.34, 0.05, 0.34], [x, 0.16, z], 0x55504c);
}
// Traffic sign and bollards
box(scene, [0.09, 2.4, 0.09], [3.72, 1.38, 8.1], 0x6c6b68);
box(scene, [0.08, 0.52, 0.52], [3.72, 2.55, 8.1], 0xb54b43);
for (let z = -15; z < 18; z += 3.3) {
box(scene, [0.13, 0.65, 0.13], [-4.18, 0.48, z], 0x454646);
box(scene, [0.14, 0.08, 0.14], [-4.18, 0.75, z], 0xc6b69a);
}
// Blocky pedestrians
function createPerson(shirtColor, options = {}) {
const group = new THREE.Group();
const skin = options.skin || 0xd8a37f;
const pants = options.pants || 0x3e4653;
const scale = options.scale || 1;
box(group, [0.57, 0.72, 0.35], [0, 1.12, 0], shirtColor);
box(group, [0.43, 0.43, 0.41], [0, 1.73, 0], skin);
box(group, [0.46, 0.13, 0.44], [0, 1.96, -0.015], options.hair || 0x3c302d);
box(group, [0.14, 0.08, 0.08], [0, 1.74, 0.22], skin);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.39, 1.43, 0);
rightArm.position.set(0.39, 1.43, 0);
group.add(leftArm, rightArm);
box(leftArm, [0.17, 0.61, 0.19], [0, -0.28, 0], shirtColor);
box(rightArm, [0.17, 0.61, 0.19], [0, -0.28, 0], shirtColor);
box(leftArm, [0.16, 0.16, 0.17], [0, -0.64, 0], skin);
box(rightArm, [0.16, 0.16, 0.17], [0, -0.64, 0], skin);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.16, 0.78, 0);
rightLeg.position.set(0.16, 0.78, 0);
group.add(leftLeg, rightLeg);
box(leftLeg, [0.20, 0.67, 0.22], [0, -0.31, 0], pants);
box(rightLeg, [0.20, 0.67, 0.22], [0, -0.31, 0], pants);
box(leftLeg, [0.23, 0.13, 0.34], [0, -0.69, 0.06], 0x343333);
box(rightLeg, [0.23, 0.13, 0.34], [0, -0.69, 0.06], 0x343333);
if (options.bag) {
box(group, [0.23, 0.37, 0.17], [0.43, 0.82, 0], options.bag);
}
group.scale.setScalar(scale);
group.userData = { leftArm, rightArm, leftLeg, rightLeg };
return group;
}
const people = [];
const staticPeople = [];
function addStaticPerson(x, y, z, rotation, shirt, options = {}) {
const person = createPerson(shirt, options);
person.position.set(x, y, z);
person.rotation.y = rotation;
scene.add(person);
staticPeople.push(person);
return person;
}
addStaticPerson(-4.65, 0.18, 5.35, -Math.PI / 2, 0xc36e62, { bag: 0xd9b667 });
addStaticPerson(-4.72, 0.18, 5.72, -Math.PI / 2, 0x5c728e);
addStaticPerson(4.68, 0.18, -1.9, Math.PI / 2, 0x4e7568, { bag: 0x9c654e });
addStaticPerson(4.62, 0.18, -0.1, Math.PI / 2, 0xe1b550);
addStaticPerson(-4.76, 0.18, -2.55, -Math.PI / 2, 0x8f6d92, { bag: 0xcfb078 });
addStaticPerson(0.7, 3.54, -6.0, Math.PI / 2, 0x66839a, { scale: 0.92 });
const shirtPalette = [0xb65d57, 0x4f7e83, 0xd8aa4b, 0x6a7f57, 0x75678b, 0xb87d62];
for (let i = 0; i < 6; i++) {
const person = createPerson(shirtPalette[i % shirtPalette.length], {
scale: 0.88 + (i % 3) * 0.07,
hair: i % 2 ? 0x282526 : 0x4b3931
});
person.position.set(-4.72, 0.18, -13 + i * 5.1);
person.rotation.y = i % 2 ? 0 : Math.PI;
scene.add(person);
people.push({
group: person,
mode: "z",
speed: 0.42 + (i % 3) * 0.11,
direction: i % 2 ? 1 : -1,
phase: i * 1.7
});
}
for (let i = 0; i < 3; i++) {
const person = createPerson(shirtPalette[(i + 2) % shirtPalette.length], {
scale: 0.9
});
person.position.set(-3.8 + i * 3.8, 0.18, 11.65);
person.rotation.y = Math.PI / 2;
scene.add(person);
people.push({
group: person,
mode: "cross",
speed: 0.52 + i * 0.08,
direction: i % 2 ? 1 : -1,
phase: i * 2.1
});
}
// Distant neighborhood blocks
for (const side of [-1, 1]) {
for (let i = 0; i < 7; i++) {
const z = -23 + i * 7.1;
const height = 4.5 + (i % 3) * 1.8;
box(
scene,
[5.4, height, 5.8],
[side * (13.3 + (i % 2) * 0.7), height / 2, z],
[0xa99a8e, 0xb6a99a, 0x968f91][i % 3]
);
}
}
// Voxel clouds
const clouds = [];
function addCloud(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, [2.5, 0.65, 0.8], [0, 0, 0], 0xffeed8, { castShadow: false });
box(group, [1.25, 0.9, 0.85], [-0.7, 0.38, 0], 0xffeed8, { castShadow: false });
box(group, [1.55, 1.1, 0.9], [0.65, 0.45, 0], 0xffeed8, { castShadow: false });
clouds.push({ group, speed: 0.045 + scale * 0.015 });
}
addCloud(-14, 13.5, -30, 1.2);
addCloud(10, 15, -37, 1.5);
addCloud(25, 12, -18, 0.9);
// Small birds
const birdMaterial = new THREE.MeshBasicMaterial({ color: 0x5c4f50 });
for (let i = 0; i < 7; i++) {
const bird = new THREE.Group();
bird.position.set(-8 + i * 2.4, 8.5 + (i % 3) * 0.7, -16 - (i % 2) * 4);
const left = box(bird, [0.48, 0.07, 0.16], [-0.24, 0, 0], 0x5c4f50, {
material: birdMaterial,
castShadow: false
});
const right = box(bird, [0.48, 0.07, 0.16], [0.24, 0, 0], 0x5c4f50, {
material: birdMaterial,
castShadow: false
});
bird.userData = { left, right, phase: i * 0.9 };
scene.add(bird);
}
// Direct camera controls, implemented without addons
const controls = {
target: new THREE.Vector3(0, 2.4, 0.6),
theta: 0.64,
phi: 1.02,
radius: 30,
desiredTheta: 0.64,
desiredPhi: 1.02,
desiredRadius: 30
};
const pointer = {
active: false,
id: null,
x: 0,
y: 0
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
canvas.addEventListener("pointerdown", event => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
controls.desiredTheta -= dx * 0.005;
controls.desiredPhi = clamp(controls.desiredPhi + dy * 0.0045, 0.38, 1.38);
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.desiredRadius = clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
13,
48
);
}, { passive: false });
function resetCamera() {
controls.desiredTheta = 0.64;
controls.desiredPhi = 1.02;
controls.desiredRadius = 30;
controls.target.set(0, 2.4, 0.6);
}
document.querySelector("#zoomIn").addEventListener("click", () => {
controls.desiredRadius = clamp(controls.desiredRadius * 0.84, 13, 48);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
controls.desiredRadius = clamp(controls.desiredRadius * 1.16, 13, 48);
});
document.querySelector("#reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (event.key === "ArrowLeft") controls.desiredTheta += 0.09;
if (event.key === "ArrowRight") controls.desiredTheta -= 0.09;
if (event.key === "ArrowUp") controls.desiredPhi = clamp(controls.desiredPhi - 0.07, 0.38, 1.38);
if (event.key === "ArrowDown") controls.desiredPhi = clamp(controls.desiredPhi + 0.07, 0.38, 1.38);
if (key === "+" || key === "=") controls.desiredRadius = clamp(controls.desiredRadius * 0.9, 13, 48);
if (key === "-" || key === "_") controls.desiredRadius = clamp(controls.desiredRadius * 1.1, 13, 48);
if (key === "r") resetCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animatePerson(person, phase, amount, time) {
const data = person.userData;
const swing = Math.sin(time * 6 + phase) * amount;
data.leftLeg.rotation.x = swing;
data.rightLeg.rotation.x = -swing;
data.leftArm.rotation.x = -swing * 0.75;
data.rightArm.rotation.x = swing * 0.75;
}
function updatePeople(dt, time) {
for (const walker of people) {
if (walker.mode === "z") {
walker.group.position.z += walker.speed * walker.direction * dt;
walker.group.rotation.y = walker.direction > 0 ? 0 : Math.PI;
if (walker.group.position.z > 17) walker.group.position.z = -17;
if (walker.group.position.z < -17) walker.group.position.z = 17;
} else {
walker.group.position.x += walker.speed * walker.direction * dt;
walker.group.rotation.y = walker.direction > 0 ? Math.PI / 2 : -Math.PI / 2;
if (walker.group.position.x > 4.1) walker.group.position.x = -4.1;
if (walker.group.position.x < -4.1) walker.group.position.x = 4.1;
}
animatePerson(walker.group, walker.phase, 0.48, time);
}
staticPeople.forEach((person, index) => {
const data = person.userData;
data.leftArm.rotation.x = Math.sin(time * 1.2 + index) * 0.06 - 0.05;
data.rightArm.rotation.x = -Math.sin(time * 1.2 + index) * 0.06 - 0.05;
person.position.y += Math.sin(time * 1.7 + index) * 0.0007;
});
}
function updateCamera() {
controls.theta += (controls.desiredTheta - controls.theta) * 0.09;
controls.phi += (controls.desiredPhi - controls.phi) * 0.09;
controls.radius += (controls.desiredRadius - controls.radius) * 0.09;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updatePeople(dt, time);
updateCamera();
for (const cloud of clouds) {
cloud.group.position.x += cloud.speed * dt;
if (cloud.group.position.x > 34) cloud.group.position.x = -34;
}
scene.traverse(object => {
if (object.userData && object.userData.left && object.userData.right) {
const flap = Math.sin(time * 8 + object.userData.phase) * 0.45;
object.userData.left.rotation.z = flap;
object.userData.right.rotation.z = -flap;
}
});
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```