Prompt specification
Build or customize the Three.js 3D scene "Dihua Street historic commercial block 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: Dihua Street historic commercial block slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/dihua-street-historic-commercial-block-slice-x3035
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: Dihua Street historic commercial block slice. Build a bounded voxel scene with referenced facade variation, continuous arcade, and intersecting lane. Use original signs and represent active businesses rather than a static row of decorative fronts. Return one self-contained HTML file.
Working Three.js Starter (dihua-street-historic-commercial-block-slice-x3035):
```html
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>迪化街商鋪切片 — Dihua Street</title>
<style>
:root {
color-scheme: light;
--ink: #233330;
--paper: rgba(248, 242, 224, 0.92);
--line: rgba(35, 51, 48, 0.22);
--accent: #b84932;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9c7c4;
font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 22px 22px auto 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
z-index: 5;
}
.card {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.64);
box-shadow: 0 12px 34px rgba(38, 50, 47, 0.14);
backdrop-filter: blur(10px);
}
#title-card {
max-width: 390px;
padding: 17px 19px 16px;
border-radius: 3px;
border-left: 5px solid var(--accent);
}
.eyebrow {
margin-bottom: 7px;
color: #7d4338;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(24px, 3vw, 38px);
line-height: 1.05;
letter-spacing: 0.06em;
}
.subtitle {
margin-top: 8px;
color: #56645f;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
line-height: 1.55;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#stats {
display: flex;
gap: 7px;
margin-top: 12px;
flex-wrap: wrap;
}
.stat {
padding: 5px 7px;
border: 1px solid var(--line);
color: #53605b;
font-size: 10px;
letter-spacing: 0.08em;
background: rgba(255,255,255,0.25);
}
#views {
display: flex;
gap: 6px;
padding: 7px;
border-radius: 3px;
pointer-events: auto;
}
button {
border: 1px solid var(--line);
background: transparent;
color: var(--ink);
padding: 8px 10px;
border-radius: 2px;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
cursor: pointer;
}
button:hover,
button.active {
color: #fff9e9;
background: var(--ink);
border-color: var(--ink);
}
#help {
position: fixed;
left: 22px;
bottom: 18px;
padding: 9px 12px;
border-radius: 2px;
color: #485651;
font: 600 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
pointer-events: none;
z-index: 5;
}
#edition {
position: fixed;
right: 22px;
bottom: 18px;
color: rgba(35,51,48,0.62);
font: 700 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.11em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
z-index: 5;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
color: #34443f;
background: #c4cfcb;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 0.5s ease;
z-index: 20;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
#hud {
inset: 12px 12px auto 12px;
flex-direction: column;
gap: 8px;
}
#title-card {
max-width: calc(100vw - 24px);
padding: 13px 15px;
}
#stats { display: none; }
#views { align-self: flex-end; }
#edition { display: none; }
#help { left: 12px; bottom: 12px; }
}
</style>
</head>
<body>
<div id="loading">Assembling the market block…</div>
<div id="hud">
<section class="card" id="title-card">
<div class="eyebrow">Dihua Street · Historic Commercial Slice</div>
<h1>迪化街商鋪切片</h1>
<div class="subtitle">
A living voxel arcade / original shop identities<br />
Dihua Street · Taipei-inspired block study
</div>
<div id="stats">
<span class="stat">09 OPEN SHOPS</span>
<span class="stat">CONTINUOUS ARCADE</span>
<span class="stat">CROSS LANE</span>
<span class="stat">18:40 MARKET LIGHT</span>
</div>
</section>
<nav class="card" id="views" aria-label="Camera views">
<button data-view="corner" class="active">CORNER</button>
<button data-view="street">STREET</button>
<button data-view="top">PLAN</button>
</nav>
</div>
<div class="card" id="help">DRAG ROTATE · WHEEL / PINCH ZOOM · SHIFT + DRAG PAN · R RESET</div>
<div id="edition">Original fictional businesses<br />Built as a bounded Three.js 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 and scene
// -------------------------------------------------------------------------
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.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbcc9c5);
scene.fog = new THREE.Fog(0xbcc9c5, 65, 145);
const camera = new THREE.PerspectiveCamera(36, window.innerWidth / window.innerHeight, 0.1, 240);
const hemisphere = new THREE.HemisphereLight(0xdce8e3, 0x71675c, 1.7);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd4a0, 3.2);
sun.position.set(-18, 31, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -38;
sun.shadow.camera.right = 38;
sun.shadow.camera.top = 32;
sun.shadow.camera.bottom = -32;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x9bc6d4, 0.75);
coolFill.position.set(22, 14, -20);
scene.add(coolFill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitPlane = new THREE.PlaneGeometry(1, 1);
const maxAnisotropy = renderer.capabilities.getMaxAnisotropy();
// -------------------------------------------------------------------------
// Materials and small construction helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}:${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
}));
}
return materialCache.get(key);
}
const M = {
asphalt: material(0x4b5553, { roughness: 0.97 }),
asphaltPatch: material(0x59615e, { roughness: 0.98 }),
base: material(0x3f4845),
baseEdge: material(0x655f52),
curb: material(0xb3aa96),
pavementA: material(0xc6bba7),
pavementB: material(0xb6ad9c),
pavementC: material(0xccc1aa),
stoneDark: material(0x6d746f),
wood: material(0x76503a),
woodLight: material(0xa87950),
woodDark: material(0x4c382d),
cream: material(0xe1d3b4),
white: material(0xf2ead7),
black: material(0x252b29),
steel: material(0x465451, { metalness: 0.42, roughness: 0.52 }),
window: material(0x243a3d, {
roughness: 0.35,
metalness: 0.18,
emissive: 0xffbd70,
emissiveIntensity: 0.22
}),
warmLight: material(0xffc777, {
emissive: 0xff9f42,
emissiveIntensity: 2.4,
roughness: 0.5
}),
redLantern: material(0xb93c2f, {
emissive: 0x7d1b12,
emissiveIntensity: 0.55
}),
leaf: material(0x587653),
leafLight: material(0x718861),
brick: material(0x8c5548),
roadPaint: material(0xddd6c3),
skin: material(0xd4a27c),
skinDark: material(0xb87c58)
};
function box(w, h, d, x, y, z, mat, parent = scene, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function beam2D(parent, x1, y1, x2, y2, z, thickness, mat) {
const length = Math.hypot(x2 - x1, y2 - y1);
const mesh = box(length, thickness, thickness, (x1 + x2) / 2, (y1 + y2) / 2, z, mat, parent);
mesh.rotation.z = Math.atan2(y2 - y1, x2 - x1);
return mesh;
}
function tileZone(x0, x1, z0, z1, step = 1) {
const colors = [M.pavementA, M.pavementB, M.pavementC];
for (let x = x0 + step / 2; x < x1; x += step) {
for (let z = z0 + step / 2; z < z1; z += step) {
const index = Math.abs(Math.round(x + z * 1.7)) % colors.length;
box(step - 0.045, 0.055, step - 0.045, x, 0.12, z, colors[index], scene, false, true);
}
}
}
let seed = 1947;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// -------------------------------------------------------------------------
// Original canvas-drawn signage
// -------------------------------------------------------------------------
function signTexture(title, subtitle, background, foreground, vertical = false) {
const canvas = document.createElement("canvas");
canvas.width = vertical ? 256 : 1024;
canvas.height = vertical ? 768 : 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.lineWidth = vertical ? 8 : 7;
ctx.strokeRect(13, 13, canvas.width - 26, canvas.height - 26);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.6;
ctx.lineWidth = 2;
ctx.strokeRect(24, 24, canvas.width - 48, canvas.height - 48);
ctx.globalAlpha = 1;
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = '800 78px "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif';
if (vertical) {
const chars = [...title];
const spacing = 112;
const start = canvas.height / 2 - ((chars.length - 1) * spacing) / 2 - 35;
chars.forEach((char, i) => ctx.fillText(char, canvas.width / 2, start + i * spacing));
ctx.font = '700 22px ui-monospace, monospace';
ctx.fillText(subtitle, canvas.width / 2, canvas.height - 50);
} else {
ctx.font = '800 86px "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif';
ctx.fillText(title, canvas.width / 2, 102);
ctx.font = '700 24px ui-monospace, monospace';
ctx.fillText(subtitle, canvas.width / 2, 194);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = maxAnisotropy;
return texture;
}
function signMaterial(texture) {
return new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.62,
metalness: 0,
emissive: 0xffffff,
emissiveMap: texture,
emissiveIntensity: 0.13
});
}
function textPlane(parent, texture, width, height, x, y, z) {
const mesh = new THREE.Mesh(unitPlane, signMaterial(texture));
mesh.scale.set(width, height, 1);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
const animatedSigns = [];
const steamPuffs = [];
const walkingPeople = [];
// -------------------------------------------------------------------------
// Voxel people and street objects
// -------------------------------------------------------------------------
function createPerson({
x = 0,
z = 0,
shirt = 0x517e83,
trousers = 0x394440,
skin = M.skin,
vendor = false,
facing = 0,
bag = false,
walking = false,
phase = 0
} = {}) {
const group = new THREE.Group();
group.position.set(x, 0.15, z);
group.rotation.y = facing;
scene.add(group);
const shirtMat = material(shirt);
const trouserMat = material(trousers);
box(0.42, 0.56, 0.28, 0, 1.06, 0, shirtMat, group);
box(0.31, 0.32, 0.31, 0, 1.52, 0, skin, group);
box(0.33, 0.10, 0.33, 0, 1.70, -0.01, material(0x342e29), group);
box(0.11, 0.12, 0.11, 0, 1.34, 0, skin, group);
const leftLeg = box(0.14, 0.48, 0.16, -0.11, 0.49, 0, trouserMat, group);
const rightLeg = box(0.14, 0.48, 0.16, 0.11, 0.49, 0, trouserMat, group);
box(0.17, 0.10, 0.27, -0.11, 0.20, 0.05, M.black, group);
box(0.17, 0.10, 0.27, 0.11, 0.20, 0.05, M.black, group);
const leftArm = box(0.12, 0.49, 0.14, -0.28, 1.04, 0, shirtMat, group);
const rightArm = box(0.12, 0.49, 0.14, 0.28, 1.04, 0, shirtMat, group);
box(0.12, 0.12, 0.13, -0.28, 0.76, 0, skin, group);
box(0.12, 0.12, 0.13, 0.28, 0.76, 0, skin, group);
box(0.055, 0.045, 0.025, -0.075, 1.57, 0.166, M.black, group);
box(0.055, 0.045, 0.025, 0.075, 1.57, 0.166, M.black, group);
if (vendor) {
box(0.35, 0.45, 0.035, 0, 0.87, 0.16, M.cream, group);
box(0.37, 0.08, 0.37, 0, 1.73, 0, M.woodDark, group);
}
if (bag) {
box(0.28, 0.31, 0.15, 0.34, 0.58, 0.02, material(0xb38b5d), group);
box(0.05, 0.35, 0.05, 0.34, 0.83, 0.02, M.woodDark, group);
}
if (walking) {
group.userData.phase = phase;
group.userData.limbs = [leftLeg, rightLeg, leftArm, rightArm];
walkingPeople.push(group);
}
return group;
}
function pixelWheel(parent, x, y, z, radius = 0.33) {
for (let i = 0; i < 12; i++) {
const a = i * Math.PI / 6;
const piece = box(
0.16,
0.16,
0.11,
x + Math.cos(a) * radius,
y + Math.sin(a) * radius,
z,
M.black,
parent
);
piece.rotation.z = a;
}
box(0.09, 0.09, 0.13, x, y, z, M.steel, parent);
}
function addBicycle(x, z, accent = 0x5c7770) {
const group = new THREE.Group();
group.position.set(x, 0.14, z);
group.rotation.y = -0.08;
scene.add(group);
const frameMat = material(accent);
pixelWheel(group, -0.63, 0.36, 0);
pixelWheel(group, 0.63, 0.36, 0);
beam2D(group, -0.63, 0.36, -0.08, 0.84, 0, 0.07, frameMat);
beam2D(group, -0.08, 0.84, 0.48, 0.37, 0, 0.07, frameMat);
beam2D(group, 0.48, 0.37, -0.63, 0.36, 0, 0.07, frameMat);
beam2D(group, -0.08, 0.84, 0.48, 0.37, 0, 0.07, frameMat);
beam2D(group, 0.48, 0.37, 0.63, 0.36, 0, 0.07, frameMat);
beam2D(group, 0.48, 0.37, 0.57, 0.98, 0, 0.07, frameMat);
box(0.35, 0.09, 0.22, -0.13, 0.90, 0, M.black, group);
box(0.48, 0.07, 0.08, 0.60, 1.02, 0, M.black, group);
box(0.32, 0.27, 0.34, 0.73, 0.80, 0, material(0xb08a59), group);
return group;
}
function addCrateStack(x, z, count = 3, accent = 0x9b7047) {
const group = new THREE.Group();
group.position.set(x, 0.14, z);
scene.add(group);
const crateMat = material(accent);
for (let i = 0; i < count; i++) {
const y = 0.17 + i * 0.33;
const offset = (i % 2) * 0.08;
box(0.64, 0.29, 0.56, offset, y, 0, crateMat, group);
box(0.68, 0.045, 0.59, offset, y + 0.13, 0, M.woodDark, group);
}
return group;
}
function addTree(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.14, z);
scene.add(group);
box(1.55, 0.45, 1.55, 0, 0.23, 0, M.stoneDark, group);
box(0.35, 2.25, 0.35, 0, 1.4, 0, M.woodDark, group);
box(1.75, 1.25, 1.65, 0, 3.05, 0, M.leaf, group);
box(1.25, 1.10, 1.25, -0.55, 3.95, 0.15, M.leafLight, group);
box(1.20, 0.95, 1.15, 0.65, 3.75, -0.15, M.leaf, group);
box(0.85, 0.80, 0.85, 0.10, 4.55, 0.15, M.leafLight, group);
}
// -------------------------------------------------------------------------
// Bounded ground, streets, crossing lane and pavement
// -------------------------------------------------------------------------
box(52, 0.72, 30, 0, -0.36, 0, M.baseEdge, scene, false, true);
box(51.65, 0.12, 29.65, 0, 0.02, 0, M.stoneDark, scene, false, true);
// Main street and sidewalks.
box(48.8, 0.08, 7.0, 0, 0.075, 6.95, M.asphalt, scene, false, true);
tileZone(-24, 5.0, 2.08, 3.48, 0.86);
tileZone(9.45, 24, 2.08, 3.48, 0.86);
tileZone(-24, 5.0, 10.4, 13.5, 0.92);
tileZone(9.45, 24, 10.4, 13.5, 0.92);
// Perpendicular lane crosses the commercial street.
box(4.35, 0.10, 28.8, 7.22, 0.095, 0, M.asphaltPatch, scene, false, true);
for (let z = -14.1; z < 14.1; z += 0.95) {
for (let x = 5.30; x < 9.35; x += 0.95) {
const tint = material(
(Math.round(x * 3 + z) % 3 === 0) ? 0x747b74 : (Math.round(x + z) % 2 ? 0x69726d : 0x7d827a),
{ roughness: 0.96 }
);
box(0.90, 0.055, 0.90, x, 0.165, z, tint, scene, false, true);
}
}
// Drain channel and crossing marks.
box(0.17, 0.08, 28.1, 5.38, 0.20, -0.1, M.black, scene, false, true);
for (let i = 0; i < 7; i++) {
box(0.30, 0.026, 1.15, 5.48 + i * 0.55, 0.205, 2.72, M.roadPaint, scene, false, true);
}
for (let i = 0; i < 7; i++) {
box(0.30, 0.026, 1.15, 5.48 + i * 0.55, 0.205, 11.75, M.roadPaint, scene, false, true);
}
// Curbs, interrupted at the intersecting lane.
box(29, 0.24, 0.20, -9.5, 0.20, 3.48, M.curb, scene, false, true);
box(14.55, 0.24, 0.20, 16.72, 0.20, 3.48, M.curb, scene, false, true);
box(29, 0.24, 0.20, -9.5, 0.20, 10.37, M.curb, scene, false, true);
box(14.55, 0.24, 0.20, 16.72, 0.20, 10.37, M.curb, scene, false, true);
// Subtle asphalt patches.
[
[-18, 5.0, 5.8, 1.2], [-5, 8.9, 4.2, 0.9], [13, 5.4, 5.0, 1.4], [21, 8.4, 3.2, 1.0]
].forEach(([x, z, w, d]) => box(w, 0.012, d, x, 0.122, z, M.asphaltPatch, scene, false, true));
// Background receiving shadow.
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(220, 220),
material(0xb8c5c0, { roughness: 1 })
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -0.74;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
// -------------------------------------------------------------------------
// Shop definitions and interiors
// -------------------------------------------------------------------------
const shopDefinitions = [
{
title: "青禾茶行", sub: "QING HE · TEA & TEAWARE", vertical: "茶",
category: "茶葉・茶器", facade: 0xb6bca5, accent: 0x346b59,
awning: 0x386e58, width: 4.5, height: 7.2, type: "tea"
},
{
title: "日新米行", sub: "RI SHIN · RICE & GRAIN", vertical: "米",
category: "稻米・雜糧", facade: 0xc9957b, accent: 0x9e3e2f,
awning: 0xa64432, width: 5.0, height: 8.5, type: "rice"
},
{
title: "文成布莊", sub: "WEN CHENG · SILK & CLOTH", vertical: "布",
category: "布料・織品", facade: 0xc8b996, accent: 0x355f73,
awning: 0x3e6978, width: 4.3, height: 7.6, type: "fabric"
},
{
title: "永豐南北貨", sub: "YUNG FUNG · PANTRY GOODS", vertical: "貨",
category: "乾貨・罐頭", facade: 0xb87c67, accent: 0x7f352c,
awning: 0x8d4636, width: 4.8, height: 9.3, type: "dry"
},
{
title: "和安藥行", sub: "HO AN · HERBAL APOTHECARY", vertical: "藥",
category: "本草・丸散", facade: 0xc4b88c, accent: 0x637347,
awning: 0x6c7950, width: 4.4, height: 7.5, type: "medicine"
},
{
title: "合興五金", sub: "HO HSING · HARDWARE", vertical: "五金",
category: "工具・鐵器", facade: 0x9aa59b, accent: 0x405b56,
awning: 0x4c6862, width: 4.0, height: 8.2, type: "hardware"
},
{
title: "長樂香舖", sub: "CHANG LE · INCENSE & CANDLES", vertical: "香",
category: "香・燭・紙", facade: 0xb99078, accent: 0x9a4333,
awning: 0x9e4935, width: 4.4, height: 9.6, type: "incense"
},
{
title: "瑞成紙行", sub: "RUE CHENG · PAPER & RIBBON", vertical: "紙",
category: "紙品・禮儀", facade: 0xc9bda0, accent: 0x5a6380,
awning: 0x596783, width: 4.6, height: 7.8, type: "paper"
},
{
title: "大川漬物", sub: "DA CHUAN · PICKLED GOODS", vertical: "漬",
category: "醬菜・漬物", facade: 0xa9b4a0, accent: 0x4f7052,
awning: 0x57765a, width: 4.6, height: 8.7, type: "pickle"
}
];
const columnPositions = [];
function addShelving(group, width, type, accent) {
const shelfMat = M.woodDark;
const backX = -width * 0.36;
for (let level = 0; level < 3; level++) {
const y = 0.72 + level * 0.62;
box(width * 0.55, 0.08, 0.50, 0, y, -2.55, shelfMat, group);
const count = 5 + (level % 2);
for (let i = 0; i < count; i++) {
const x = backX + (i / (count - 1)) * width * 0.39;
let itemMat = material([0x8d5e3f, 0xc5a466, 0x71826a, 0x9b493d, 0x6a7880][(i + level) % 5]);
if (type === "fabric") itemMat = material([0xba5d50, 0xd5b66d, 0x4d7180, 0x7e8b6e][i % 4]);
if (type === "medicine") itemMat = material(0x9b6a42);
if (type === "pickle") itemMat = material(0x6e7651);
if (type === "paper") itemMat = M.white;
const h = type === "fabric" ? 0.40 : 0.28;
box(0.20, h, 0.23, x, y + 0.04 + h / 2, -2.42, itemMat, group);
if (type === "fabric") {
box(0.22, 0.04, 0.25, x, y + 0.12, -2.40, M.cream, group);
}
}
}
if (type === "medicine") {
const cabinetMat = M.wood;
box(width * 0.50, 1.70, 0.32, width * 0.23, 1.20, -2.72, cabinetMat, group);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 5; col++) {
box(0.18, 0.20, 0.05,
width * 0.23 - 0.36 + col * 0.18,
0.53 + row * 0.29,
-2.53,
material(row % 2 ? 0x9c7148 : 0x8b603d),
group
);
}
}
}
if (type === "fabric") {
for (let i = 0; i < 4; i++) {
box(0.20, 1.55, 0.24, width * 0.31 + i * 0.25, 1.22, -2.34,
material([0xa74f46, 0xd0b36c, 0x4f6f78, 0x6f815e][i]), group);
}
}
if (type === "hardware") {
box(0.75, 0.80, 0.35, -width * 0.25, 1.70, -2.55, M.steel, group);
for (let i = 0; i < 5; i++) {
box(0.055, 0.52, 0.08, -width * 0.25 - 0.24 + i * 0.12, 1.72, -2.31, M.black, group);
}
}
// Hanging packages above the counter.
for (let i = 0; i < 4; i++) {
box(0.16, 0.35, 0.12, -width * 0.29 + i * 0.36, 2.25, -2.28,
material(i % 2 ? accent : 0xb89761), group);
}
}
function addCounterGoods(group, width, type, accent) {
const counterMat = M.woodLight;
box(width * 0.58, 0.78, 0.64, 0, 0.55, -0.98, counterMat, group);
box(width * 0.61, 0.10, 0.70, 0, 0.98, -0.98, M.woodDark, group);
box(0.30, 0.24, 0.24, width * 0.16, 1.16, -0.98, M.steel, group);
box(0.18, 0.09, 0.13, width * 0.16, 1.31, -0.98, M.black, group);
if (type === "rice") {
for (let i = 0; i < 3; i++) {
box(0.42, 0.34, 0.36, -0.55 + i * 0.48, 1.20, -0.92, M.cream, group);
box(0.15, 0.13, 0.10, -0.55 + i * 0.48, 1.42, -0.92, M.woodDark, group);
}
} else if (type === "fabric") {
for (let i = 0; i < 4; i++) {
box(0.17, 0.15, 0.38, -0.70 + i * 0.35, 1.12, -0.95,
material([0xb95c51, 0xd6b974, 0x507987, 0x87916c][i]), group);
}
} else if (type === "pickle" || type === "tea" || type === "dry") {
for (let i = 0; i < 5; i++) {
box(0.19, 0.26, 0.22, -0.70 + i * 0.34, 1.17, -0.91,
material(i % 2 ? accent : 0x7e704b), group);
}
} else {
box(0.27, 0.13, 0.25, -0.55, 1.10, -0.91, M.steel, group);
box(0.08, 0.36, 0.08, -0.18, 1.21, -0.91, M.black, group);
box(0.32, 0.14, 0.22, 0.32, 1.11, -0.91, M.cream, group);
}
}
function createShop(definition, centerX, index) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
const facadeMat = material(definition.facade);
const accentMat = material(definition.accent);
const awningMat = material(definition.awning);
const width = definition.width;
const height = definition.height;
const upperHeight = height - 3.18;
// Upper masonry mass.
box(width, upperHeight, 8.75, 0, 3.18 + upperHeight / 2, -4.36, facadeMat, group);
box(width + 0.22, 0.22, 8.94, 0, height - 0.02, -4.36, accentMat, group);
box(width + 0.10, 0.12, 8.82, 0, height + 0.13, -4.36, M.cream, group);
// Arcade slab and awning.
box(width + 0.03, 0.10, 2.30, 0, 0.15, 1.00, M.pavementA, group, false, true);
box(width + 0.03, 0.24, 2.35, 0, 3.13, 0.94, accentMat, group);
const stripeCount = Math.max(5, Math.round(width / 0.55));
const stripeWidth = width / stripeCount;
for (let i = 0; i < stripeCount; i++) {
const x = -width / 2 + stripeWidth * (i + 0.5);
box(stripeWidth, 0.08, 1.28, x, 2.91, 0.60, i % 2 ? M.cream : awningMat, group);
box(stripeWidth, 0.25, 0.06, x, 2.71, 1.25, i % 2 ? M.cream : awningMat, group);
}
// Ground-floor partitions and stocked interior.
box(width - 0.12, 3.02, 0.16, 0, 1.62, -2.98, M.woodDark, group);
box(0.13, 2.95, 3.05, -width / 2 + 0.08, 1.62, -1.42, M.woodDark, group);
box(width * 0.70, 0.06, 0.35, 0, 2.64, -2.72, M.warmLight, group, false, false);
addShelving(group, width, definition.type, definition.accent);
addCounterGoods(group, width, definition.type, definition.accent);
// Warm merchant.
const merchantShirts = [0x5f7771, 0x8b5545, 0x4f667a, 0x716547, 0x4f6f5b, 0x695c6e, 0x8a503e, 0x596678, 0x57705a];
createPerson({
x: index % 2 ? -0.45 : 0.35,
z: -1.55,
shirt: merchantShirts[index],
trousers: 0x3f433e,
vendor: true
});
// A few shoppers interact with counters.
if ([0, 1, 2, 3, 5, 7].includes(index)) {
createPerson({
x: index % 2 ? -0.55 : 0.55,
z: 0.55,
shirt: [0x8a5c49, 0x4f7478, 0x8b7b4e, 0x6b6478, 0x3f665a, 0x9a664e][index % 6],
trousers: 0x3e4541,
facing: Math.PI,
bag: index % 2 === 0
});
}
// Vertical pilasters and a ceramic band.
box(0.18, upperHeight, 0.11, -width / 2 + 0.08, 3.18 + upperHeight / 2, 0.08, accentMat, group);
box(0.18, upperHeight, 0.11, width / 2 - 0.08, 3.18 + upperHeight / 2, 0.08, accentMat, group);
box(width - 0.15, 0.18, 0.09, 0, 3.37, 0.12, accentMat, group);
// Windows, shutters, balconies and floor strings.
const levels = height > 8.0 ? 2 : 1;
const windowCount = width > 4.4 ? 2 : 1;
for (let level = 0; level < levels; level++) {
const y = 4.56 + level * 2.18;
box(width - 0.18, 0.12, 0.13, 0, 3.42 + level * 2.18, 0.13, accentMat, group);
for (let w = 0; w < windowCount; w++) {
const x = windowCount === 1 ? 0 : (w === 0 ? -width * 0.22 : width * 0.22);
box(1.16, 1.38, 0.13, x, y, 0.09, M.woodDark, group);
box(0.96, 1.18, 0.15, x, y, 0.17, M.window, group, false, false);
box(0.055, 1.19, 0.06, x, y, 0.26, M.woodDark, group);
box(0.97, 0.055, 0.06, x, y + 0.05, 0.26, M.woodDark, group);
if ((index + w + level) % 2 === 0) {
box(0.35, 1.27, 0.11, x - 0.76, y, 0.12, accentMat, group);
box(0.35, 1.27, 0.11, x + 0.76, y, 0.12, accentMat, group);
for (let slat = 0; slat < 5; slat++) {
box(0.35, 0.035, 0.05, x - 0.76, y - 0.48 + slat * 0.24, 0.20, M.woodDark, group);
box(0.35, 0.035, 0.05, x + 0.76, y - 0.48 + slat * 0.24, 0.20, M.woodDark, group);
}
}
if (level === 0 && index % 3 !== 1) {
box(1.66, 0.11, 0.56, x, y - 0.76, 0.34, M.woodLight, group);
box(1.66, 0.07, 0.07, x, y - 0.27, 0.60, M.steel, group);
for (let p = 0; p < 7; p++) {
box(0.045, 0.48, 0.045, x - 0.72 + p * 0.24, y - 0.50, 0.59, M.steel, group);
}
}
}
}
// Small attic opening on taller facades.
if (height > 9.0) {
box(0.82, 0.78, 0.12, 0, 8.48, 0.08, M.woodDark, group);
box(0.64, 0.59, 0.14, 0, 8.48, 0.16, M.window, group, false, false);
}
// Drain pipe.
box(0.07, upperHeight - 0.2, 0.09, width / 2 - 0.21, 3.18 + upperHeight / 2, 0.22, M.steel, group);
// Original horizontal sign.
const signTex = signTexture(definition.title, definition.sub, `#${definition.accent.toString(16).padStart(6, "0")}`, "#f4e6c7");
box(width * 0.83, 0.76, 0.18, 0, 3.70, 0.22, M.woodDark, group);
textPlane(group, signTex, width * 0.78, 0.62, 0, 3.70, 0.322);
// Original projecting vertical sign.
const verticalGroup = new THREE.Group();
verticalGroup.position.set(width / 2 - 0.28, 5.02, 0.43);
group.add(verticalGroup);
box(0.61, 2.10, 0.18, 0, 0, 0, M.woodDark, verticalGroup);
const verticalTex = signTexture(definition.vertical, definition.category, `#${definition.accent.toString(16).padStart(6, "0")}`, "#f4e6c7", true);
textPlane(verticalGroup, verticalTex, 0.50, 1.95, 0, 0, 0.101);
animatedSigns.push({ group: verticalGroup, phase: index * 0.8, baseY: verticalGroup.rotation.y });
// Arcade lantern.
box(0.30, 0.42, 0.30, -width / 2 + 0.48, 2.69, 1.47, M.redLantern, group, false, false);
box(0.36, 0.06, 0.36, -width / 2 + 0.48, 2.91, 1.47, M.woodDark, group);
box(0.36, 0.06, 0.36, -width / 2 + 0.48, 2.47, 1.47, M.woodDark, group);
// Rooftop water tank and antenna.
if ([0, 2, 3, 6].includes(index)) {
box(1.05, 0.72, 0.94, -0.45, height + 0.55, -4.50, M.steel, group);
box(1.15, 0.10, 1.04, -0.45, height + 0.95, -4.50, M.black, group);
for (const sx of [-0.78, -0.12]) {
box(0.08, 0.45, 0.08, sx, height + 0.23, -4.50, M.woodDark, group);
}
}
if (index % 2 === 0) {
box(0.05, 1.25, 0.05, width * 0.30, height + 0.75, -5.55, M.steel, group);
box(0.55, 0.04, 0.04, width * 0.30, height + 1.05, -5.55, M.steel, group);
box(0.42, 0.04, 0.04, width * 0.30, height + 1.25, -5.55, M.steel, group);
}
// Side-facing windows make the crossing lane legible.
if (index === 5 || index === 6) {
const side = index === 5 ? -1 : 1;
for (let level = 0; level < 2; level++) {
for (let j = 0; j < 3; j++) {
const z = -1.45 - j * 1.65;
const y = 4.55 + level * 2.12;
box(0.12, 1.18, 0.94, side * (width / 2 + 0.025), y, z, M.woodDark, group);
box(0.14, 0.98, 0.76, side * (width / 2 + 0.05), y, z, M.window, group, false, false);
}
}
}
// Selective practical lighting.
if (index % 2 === 0) {
const light = new THREE.PointLight(0xffb762, 13, 5.3, 2);
light.position.set(0, 2.05, -1.15);
group.add(light);
}
// Steam from a food counter.
if (definition.type === "pickle" || definition.type === "rice") {
const steamMat = new THREE.MeshBasicMaterial({
color: 0xf1eee3,
transparent: true,
opacity: 0.17,
depthWrite: false
});
for (let i = 0; i < 3; i++) {
const puff = box(0.16, 0.16, 0.16, 0.65, 1.25 + i * 0.24, -0.80, steamMat, group, false, false);
steamPuffs.push({ mesh: puff, baseY: 1.25 + i * 0.24, phase: index + i * 1.7 });
}
}
columnPositions.push(centerX - width / 2);
return group;
}
// Build left and right groups, separated by the intersecting lane.
let cursor = -22;
shopDefinitions.slice(0, 6).forEach((definition, i) => {
createShop(definition, cursor + definition.width / 2, i);
cursor += definition.width;
});
const leftEnd = cursor;
cursor = 9.4;
shopDefinitions.slice(6).forEach((definition, i) => {
createShop(definition, cursor + definition.width / 2, i + 6);
cursor += definition.width;
});
const rightEnd = cursor;
columnPositions.push(rightEnd);
// Arcade columns: one per structural bay.
for (const x of columnPositions) {
box(0.30, 2.94, 0.30, x, 1.64, 1.80, M.cream, scene);
box(0.46, 0.16, 0.46, x, 0.29, 1.80, M.stoneDark, scene);
box(0.48, 0.18, 0.48, x, 2.98, 1.80, M.cream, scene);
}
// Continuous covered gallery bridges the lane overhead.
box(4.52, 0.27, 2.35, 7.2, 3.13, 0.95, material(0x667267), scene);
box(4.28, 0.12, 2.10, 7.2, 2.95, 0.95, M.cream, scene);
for (const z of [0.15, 1.70]) {
box(4.25, 0.12, 0.16, 7.2, 2.88, z, M.woodDark, scene);
}
const streetPlaqueTexture = signTexture("迪化街", "DIHUA STREET", "#263b37", "#efd9a8");
box(1.72, 0.60, 0.14, 7.2, 2.42, 1.13, M.woodDark, scene);
textPlane(scene, streetPlaqueTexture, 1.56, 0.45, 7.2, 2.42, 1.212);
// -------------------------------------------------------------------------
// Rear lane, street furniture, shop spillover and active street life
// -------------------------------------------------------------------------
// Rear end of the intersecting lane.
box(4.35, 3.75, 0.28, 7.2, 1.98, -14.30, material(0x8b5c4e), scene);
box(0.95, 2.25, 0.12, 7.2, 1.24, -14.12, M.woodDark, scene);
box(0.73, 1.90, 0.15, 7.2, 1.28, -14.02, material(0x314643), scene);
box(0.24, 0.24, 0.18, 7.52, 1.20, -13.91, M.steel, scene);
addCrateStack(5.8, -12.8, 2, 0x7d6549);
addCrateStack(8.4, -11.5, 3, 0x936342);
// Bollards along the crossing.
for (const z of [-1.6, 0.2, 2.0]) {
for (const x of [5.03, 9.42]) {
box(0.22, 0.70, 0.22, x, 0.50, z, M.steel, scene);
box(0.28, 0.10, 0.28, x, 0.86, z, M.cream, scene);
}
}
// Arcade lamps and streetlight poles.
function addStreetLamp(x, z) {
box(0.15, 3.65, 0.15, x, 1.98, z, M.steel, scene);
box(0.13, 0.13, 0.75, x, 3.74, z + 0.28, M.steel, scene);
box(0.43, 0.19, 0.43, x, 3.66, z + 0.65, M.warmLight, scene, false, false);
box(0.50, 0.07, 0.50, x, 3.80, z + 0.65, M.steel, scene);
}
addStreetLamp(-18.7, 2.92);
addStreetLamp(-8.0, 2.92);
addStreetLamp(15.5, 2.92);
addStreetLamp(22.2, 2.92);
// Shop spillover.
addCrateStack(-20.7, 2.66, 2, 0x946843);
addCrateStack(-13.5, 2.68, 3, 0x866448);
addCrateStack(11.1, 2.70, 2, 0x9b714a);
addCrateStack(20.4, 2.64, 3, 0x8c6345);
addBicycle(-10.8, 2.75, 0x597970);
addBicycle(16.6, 2.72, 0x8a5543);
addBicycle(6.0, -5.3, 0x6c7557);
addTree(-23.1, 2.68);
addTree(23.0, 2.68);
// Sidewalk pedestrians.
createPerson({
x: -16.8, z: 2.82, shirt: 0x9a654f, trousers: 0x465049,
bag: true, walking: true, phase: 0.2
});
createPerson({
x: -4.8, z: 2.60, shirt: 0x4d777a, trousers: 0x414b48,
facing: Math.PI / 2, walking: true, phase: 1.4
});
createPerson({
x: 18.4, z: 11.65, shirt: 0x7e724c, trousers: 0x3f4743,
bag: true, walking: true, phase: 2.1
});
createPerson({
x: 7.25, z: 8.1, shirt: 0x7c4e42, trousers: 0x3d4744,
facing: -Math.PI / 2, walking: true, phase: 3.0
});
// A small newspaper kiosk across the street.
const kiosk = new THREE.Group();
kiosk.position.set(-11.2, 0.15, 11.85);
scene.add(kiosk);
box(1.65, 1.30, 0.90, 0, 0.65, 0, M.wood, kiosk);
box(1.80, 0.16, 1.05, 0, 1.38, 0, material(0x3b6863), kiosk);
box(1.30, 0.56, 0.10, 0, 0.93, 0.49, M.black, kiosk);
box(1.12, 0.38, 0.12, 0, 0.93, 0.55, M.warmLight, kiosk, false, false);
for (let i = 0; i < 5; i++) {
box(0.23, 0.12, 0.32, -0.52 + i * 0.26, 1.49, 0.10, M.white, kiosk);
}
const kioskSign = signTexture("街角書報", "CORNER NEWS", "#365d58", "#f1e4c4");
textPlane(kiosk, kioskSign, 1.25, 0.32, 0, 1.38, 0.535);
// Utility boxes across the street.
box(1.20, 1.15, 0.58, 5.8, 0.70, 11.85, material(0x71827b), scene);
box(0.88, 0.78, 0.06, 5.8, 0.74, 12.16, M.steel, scene);
box(0.72, 0.95, 0.56, 13.0, 0.61, 12.10, material(0x9a7256), scene);
// -------------------------------------------------------------------------
// Moving delivery scooter
// -------------------------------------------------------------------------
const delivery = new THREE.Group();
delivery.position.set(-22, 0.14, 7.0);
scene.add(delivery);
pixelWheel(delivery, -0.67, 0.34, 0, 0.30);
pixelWheel(delivery, 0.70, 0.34, 0, 0.30);
box(0.88, 0.19, 0.43, -0.05, 0.43, 0, material(0x9a4b3a), delivery);
box(0.42, 0.40, 0.38, 0.49, 0.69, 0, material(0x9a4b3a), delivery);
box(0.12, 0.88, 0.12, 0.63, 1.12, 0, M.steel, delivery);
box(0.70, 0.07, 0.08, 0.63, 1.52, 0, M.black, delivery);
box(0.44, 0.07, 0.45, -0.22, 0.57, 0, M.black, delivery);
box(0.62, 0.55, 0.62, -0.78, 0.87, 0, material(0xa9814f), delivery);
box(0.66, 0.08, 0.66, -0.78, 1.18, 0, M.cream, delivery);
// Seated rider.
box(0.42, 0.52, 0.30, 0.10, 1.17, 0, material(0x355f67), delivery);
box(0.31, 0.31, 0.31, 0.14, 1.60, 0, M.skin, delivery);
box(0.34, 0.10, 0.34, 0.14, 1.78, 0, M.woodDark, delivery);
beam2D(delivery, 0.10, 1.31, 0.59, 1.32, 0, 0.11, material(0x355f67));
beam2D(delivery, 0.10, 1.31, 0.57, 0.72, 0, 0.11, material(0x355f67));
box(0.18, 0.39, 0.19, 0.40, 0.78, 0.10, material(0x3c4745), delivery);
box(0.18, 0.39, 0.19, 0.40, 0.78, -0.10, material(0x3c4745), delivery);
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0.2, 3.15, -0.4),
yaw: 0.72,
pitch: 0.48,
distance: 54
};
const viewPresets = {
corner: { yaw: 0.72, pitch: 0.48, distance: 54, target: [0.2, 3.15, -0.4] },
street: { yaw: 0.10, pitch: 0.24, distance: 43, target: [0, 3.0, 0.1] },
top: { yaw: 0.46, pitch: 0.97, distance: 57, target: [0.4, 1.2, 0.0] }
};
function updateCamera() {
const { target, yaw, pitch, distance } = cameraState;
camera.position.set(
target.x + distance * Math.sin(yaw) * Math.cos(pitch),
target.y + distance * Math.sin(pitch),
target.z + distance * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
function applyView(name) {
const preset = viewPresets[name];
cameraState.yaw = preset.yaw;
cameraState.pitch = preset.pitch;
cameraState.distance = preset.distance;
cameraState.target.set(...preset.target);
document.querySelectorAll("#views button").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
updateCamera();
}
document.querySelectorAll("#views button").forEach(button => {
button.addEventListener("click", () => applyView(button.dataset.view));
});
const canvas = renderer.domElement;
const pointers = new Map();
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
let pinchDistance = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragging = true;
panning = event.shiftKey || event.button === 2;
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
const points = [...pointers.values()];
pinchDistance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
dragging = false;
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const points = [...pointers.values()];
const nextDistance = Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
if (pinchDistance > 0 && nextDistance > 0) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * (pinchDistance / nextDistance),
22,
88
);
updateCamera();
}
pinchDistance = nextDistance;
return;
}
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const right = new THREE.Vector3(Math.cos(cameraState.yaw), 0, -Math.sin(cameraState.yaw));
const forward = new THREE.Vector3(Math.sin(cameraState.yaw), 0, Math.cos(cameraState.yaw));
const scale = cameraState.distance * 0.0015;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(cameraState.target.x, -23, 23);
cameraState.target.z = THREE.MathUtils.clamp(cameraState.target.z, -13, 12);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(cameraState.pitch + dy * 0.0045, 0.15, 1.20);
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) dragging = false;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
22,
88
);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") applyView("corner");
if (event.key === "+" || event.key === "=") cameraState.distance = Math.max(22, cameraState.distance - 3);
if (event.key === "-") cameraState.distance = Math.min(88, cameraState.distance + 3);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const dt = Math.min(clock.getDelta(), 0.05);
// Delivery scooter loops along the main street.
delivery.position.x += dt * 1.05;
if (delivery.position.x > 25.5) delivery.position.x = -25.5;
// Small bicycle and pedestrian motion.
for (const person of walkingPeople) {
const phase = person.userData.phase + elapsed * 4.6;
person.position.y = 0.15 + Math.abs(Math.sin(phase)) * 0.018;
const limbs = person.userData.limbs;
limbs[0].rotation.x = Math.sin(phase) * 0.40;
limbs[1].rotation.x = -Math.sin(phase) * 0.40;
limbs[2].rotation.x = -Math.sin(phase) * 0.30;
limbs[3].rotation.x = Math.sin(phase) * 0.30;
}
// Hanging shop signs gently sway.
for (const sign of animatedSigns) {
sign.group.rotation.y = sign.baseY + Math.sin(elapsed * 0.8 + sign.phase) * 0.035;
}
// Voxel steam rises and fades by scaling.
for (const puff of steamPuffs) {
const cycle = (elapsed * 0.38 + puff.phase) % 1;
puff.mesh.position.y = puff.baseY + cycle * 0.82;
const scale = 0.65 + cycle * 1.4;
puff.mesh.scale.set(scale, scale, scale);
puff.mesh.rotation.y = elapsed * 0.4 + puff.phase;
}
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```