Prompt specification
Build or customize the Three.js 3D scene "Bicycle passing a Beijing courtyard entrance" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Bicycle passing a Beijing courtyard entrance
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bicycle-passing-a-beijing-courtyard-entrance-x2970
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Beijing's hutongs and courtyard compounds. Create a compact referenced lane vignette with bicycle, pedestrian, and open gate. Keep the shared route clear while showing a glimpse of an interior courtyard. Voxel style.
Working Three.js Starter (bicycle-passing-a-beijing-courtyard-entrance-x2970):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Beijing Hutong — Shared Lane</title>
<style>
:root {
--ink: #26332f;
--muted: #66736e;
--paper: rgba(247, 244, 234, 0.92);
--line: rgba(38, 51, 47, 0.16);
--accent: #a64032;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e0dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 12px 35px rgba(39, 52, 47, 0.12);
backdrop-filter: blur(12px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 4px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 330px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 42px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
#intro p {
margin: 13px 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.cues {
display: flex;
flex-wrap: wrap;
gap: 6px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.cue {
padding: 5px 7px;
border: 1px solid rgba(38, 51, 47, 0.13);
color: #596760;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#views {
top: 22px;
right: 22px;
display: flex;
gap: 4px;
padding: 5px;
border-radius: 4px;
}
button {
appearance: none;
border: 0;
border-radius: 2px;
padding: 9px 11px;
background: transparent;
color: var(--muted);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
button:hover,
button.active {
background: #26332f;
color: #f7f4ea;
}
#hint {
right: 22px;
bottom: 20px;
padding: 10px 13px;
border-radius: 3px;
color: #65716c;
font-size: 10px;
letter-spacing: 0.04em;
}
#route-note {
left: 22px;
bottom: 20px;
max-width: calc(100vw - 44px);
padding: 11px 14px;
border-radius: 3px;
color: #596760;
font-size: 11px;
}
#route-note strong {
color: var(--ink);
font-weight: 750;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d8e0dc;
color: #4f5d57;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 0.4s ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#intro {
top: 12px;
left: 12px;
width: min(310px, calc(100vw - 24px));
padding: 15px 16px;
}
#intro p { display: none; }
.cues { padding-top: 10px; }
#views {
top: auto;
right: 12px;
bottom: 57px;
}
#hint { display: none; }
#route-note {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel-style Beijing hutong lane"></canvas>
<section id="intro" class="panel">
<p class="eyebrow">Beijing · Hutong Study 07</p>
<h1>A shared lane, a private courtyard.</h1>
<p>
Grey brick, stepped tile roofs, red timber and a stone threshold frame
a glimpse into a traditional courtyard compound.
</p>
<div class="cues">
<span class="cue">Shared passage</span>
<span class="cue">Open gate</span>
<span class="cue">Bicycle</span>
<span class="cue">Pedestrian</span>
</div>
</section>
<nav id="views" class="panel" aria-label="Camera views">
<button data-view="overview" class="active">Overview</button>
<button data-view="courtyard">Courtyard</button>
<button data-view="lane">Lane</button>
</nav>
<div id="route-note" class="panel">
<strong>Keep the pale stone spine clear.</strong>
The bicycle and walker stay along its edge.
</div>
<div id="hint" class="panel">Drag to orbit · Scroll to zoom</div>
<div id="loading">Assembling the hutong…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera and lighting
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e0dc);
scene.fog = new THREE.Fog(0xd8e0dc, 29, 58);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const hemi = new THREE.HemisphereLight(0xeaf2ed, 0x6e6255, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe7bd, 3.25);
sun.position.set(-7, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaac9d6, 0.85);
fill.position.set(12, 8, -10);
scene.add(fill);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
function makeBrickTexture() {
const c = document.createElement("canvas");
c.width = c.height = 256;
const ctx = c.getContext("2d");
ctx.fillStyle = "#b6aa97";
ctx.fillRect(0, 0, 256, 256);
const colors = ["#958b7d", "#a39889", "#8d857a", "#aaa091", "#91887b"];
for (let row = 0; row < 8; row++) {
const offset = row % 2 ? -32 : 0;
for (let col = -1; col < 5; col++) {
const x = col * 64 + offset + 2;
const y = row * 32 + 2;
ctx.fillStyle = colors[(row * 3 + col + 8) % colors.length];
ctx.fillRect(x, y, 60, 28);
ctx.fillStyle = "rgba(255,255,255,.08)";
ctx.fillRect(x + 2, y + 2, 56, 3);
}
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3, 2);
texture.anisotropy = Math.min(renderer.capabilities.getMaxAnisotropy(), 8);
return texture;
}
const brickTexture = makeBrickTexture();
const mat = {
brick: new THREE.MeshStandardMaterial({
map: brickTexture,
color: 0xffffff,
roughness: 0.95
}),
brickDark: new THREE.MeshStandardMaterial({
map: brickTexture,
color: 0x9a9387,
roughness: 1
}),
stone: new THREE.MeshStandardMaterial({
color: 0xaaa797,
roughness: 0.96
}),
stoneLight: new THREE.MeshStandardMaterial({
color: 0xc7c1b2,
roughness: 0.94
}),
stoneDark: new THREE.MeshStandardMaterial({
color: 0x777a72,
roughness: 1
}),
earth: new THREE.MeshStandardMaterial({
color: 0x8d8c80,
roughness: 1
}),
road: new THREE.MeshStandardMaterial({
color: 0x777b74,
roughness: 1
}),
path: new THREE.MeshStandardMaterial({
color: 0xc5c1b2,
roughness: 0.98
}),
path2: new THREE.MeshStandardMaterial({
color: 0xb8b5a8,
roughness: 1
}),
path3: new THREE.MeshStandardMaterial({
color: 0xcecab9,
roughness: 0.98
}),
roof: new THREE.MeshStandardMaterial({
color: 0x414c50,
roughness: 0.88,
flatShading: true
}),
roofLight: new THREE.MeshStandardMaterial({
color: 0x536064,
roughness: 0.9,
flatShading: true
}),
red: new THREE.MeshStandardMaterial({
color: 0x9b3f32,
roughness: 0.8
}),
redDark: new THREE.MeshStandardMaterial({
color: 0x632c27,
roughness: 0.9
}),
gold: new THREE.MeshStandardMaterial({
color: 0xc79b4e,
roughness: 0.55,
metalness: 0.28
}),
wood: new THREE.MeshStandardMaterial({
color: 0x5d4132,
roughness: 0.95
}),
glass: new THREE.MeshStandardMaterial({
color: 0x273c3d,
roughness: 0.38,
metalness: 0.05
}),
foliage: new THREE.MeshStandardMaterial({
color: 0x4f6d4d,
roughness: 1,
flatShading: true
}),
foliageLight: new THREE.MeshStandardMaterial({
color: 0x71885b,
roughness: 1,
flatShading: true
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x71513a,
roughness: 1
}),
bike: new THREE.MeshStandardMaterial({
color: 0x276d70,
roughness: 0.58,
metalness: 0.16
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x252827,
roughness: 0.9
}),
skin: new THREE.MeshStandardMaterial({
color: 0xc98f6b,
roughness: 0.9
}),
coat: new THREE.MeshStandardMaterial({
color: 0x344f53,
roughness: 0.94
}),
trousers: new THREE.MeshStandardMaterial({
color: 0x30383a,
roughness: 1
}),
scarf: new THREE.MeshStandardMaterial({
color: 0xca8d3b,
roughness: 0.95
}),
hair: new THREE.MeshStandardMaterial({
color: 0x302c29,
roughness: 1
}),
lantern: new THREE.MeshStandardMaterial({
color: 0xb74330,
emissive: 0x7a1b10,
emissiveIntensity: 0.38,
roughness: 0.72
})
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(a, b, radius, material, parent = scene, segments = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), segments),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function steppedRoof(width, length, cx, cz, baseY, axis = "z") {
const count = 6;
const step = width / count;
const rise = 0.2;
for (const side of [-1, 1]) {
for (let i = 0; i < count; i++) {
const inset = width / 2 - (i + 0.5) * step;
const y = baseY + (i + 1) * rise;
const material = i % 2 ? mat.roof : mat.roofLight;
if (axis === "z") {
box(step * 1.1, 0.18, length, material, cx + side * inset, y, cz);
} else {
box(length, 0.18, step * 1.1, material, cx, y, cz + side * inset);
}
}
}
if (axis === "z") {
box(0.25, 0.2, length + 0.18, mat.roofLight, cx, baseY + (count + 0.6) * rise, cz);
} else {
box(length + 0.18, 0.2, 0.25, mat.roofLight, cx, baseY + (count + 0.6) * rise, cz);
}
}
function windowX(x, y, z, w = 0.9, h = 1.05) {
box(0.07, h, w, mat.glass, x, y, z);
box(0.13, h + 0.12, 0.09, mat.redDark, x + 0.02, y, z - w / 2);
box(0.13, h + 0.12, 0.09, mat.redDark, x + 0.02, y, z + w / 2);
box(0.13, 0.09, w + 0.12, mat.redDark, x + 0.02, y - h / 2, z);
box(0.13, 0.09, w + 0.12, mat.redDark, x + 0.02, y + h / 2, z);
for (let i = -1; i <= 1; i++) {
box(0.08, h, 0.045, mat.wood, x + 0.06, y, z + i * w * 0.29);
}
box(0.08, 0.045, w, mat.wood, x + 0.06, y, z);
}
function windowZ(x, y, z, w = 1.0, h = 1.05) {
box(w, h, 0.07, mat.glass, x, y, z);
box(w + 0.12, 0.09, 0.13, mat.redDark, x, y - h / 2, z + 0.02);
box(w + 0.12, 0.09, 0.13, mat.redDark, x, y + h / 2, z + 0.02);
box(0.09, h, 0.13, mat.redDark, x - w / 2, y, z + 0.02);
box(0.09, h, 0.13, mat.redDark, x + w / 2, y, z + 0.02);
for (let i = -1; i <= 1; i++) {
box(0.045, h, 0.08, mat.wood, x + i * w * 0.29, y, z + 0.06);
}
box(w, 0.045, 0.08, mat.wood, x, y, z + 0.06);
}
function sign(text, w, h, x, y, z, ry = 0, background = "#73352d") {
const c = document.createElement("canvas");
c.width = 512;
c.height = 160;
const ctx = c.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 512, 160);
ctx.strokeStyle = "#c69d55";
ctx.lineWidth = 8;
ctx.strokeRect(9, 9, 494, 142);
ctx.fillStyle = "#f0d69e";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "bold 88px Georgia, serif";
ctx.fillText(text, 256, 84);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(renderer.capabilities.getMaxAnisotropy(), 8);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.8,
side: THREE.DoubleSide
})
);
mesh.position.set(x, y, z);
mesh.rotation.y = ry;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function lantern(x, y, z) {
box(0.08, 0.4, 0.08, mat.wood, x + 0.17, y + 0.27, z);
box(0.34, 0.44, 0.34, mat.lantern, x, y, z);
box(0.38, 0.07, 0.38, mat.gold, x, y + 0.25, z);
box(0.38, 0.07, 0.38, mat.gold, x, y - 0.25, z);
box(0.05, 0.22, 0.05, mat.redDark, x, y - 0.36, z);
const light = new THREE.PointLight(0xff9b56, 0.65, 4.5, 2);
light.position.set(x, y, z);
scene.add(light);
}
// ------------------------------------------------------------
// Ground and the deliberately clear shared route
// ------------------------------------------------------------
box(15, 0.42, 18.2, mat.stoneDark, 0, -0.28, 0);
box(8.7, 0.12, 17.8, mat.road, 0, -0.035, 0);
const pathMaterials = [mat.path, mat.path2, mat.path3];
for (let i = 0; i < 16; i++) {
const z = 7.95 - i * 0.92;
const material = pathMaterials[i % pathMaterials.length];
box(1.68, 0.075, 0.84, material, 0, 0.075, z);
}
for (let i = 0; i < 17; i++) {
const z = 8.0 - i;
box(0.18, 0.13, 0.92, mat.stone, -2.35, 0.08, z);
box(0.18, 0.13, 0.92, mat.stone, 2.35, 0.08, z);
}
// A few side paving stones, kept outside the route spine.
for (let i = 0; i < 9; i++) {
const z = 6.5 - i * 1.45;
box(1.25, 0.045, 1.1, mat.stoneDark, -3.0, 0.04, z);
box(1.25, 0.045, 1.1, mat.stoneDark, 3.0, 0.04, z);
}
// ------------------------------------------------------------
// West compound wall and open gate
// ------------------------------------------------------------
const gateX = -4.15;
const openingStart = -0.35;
const openingEnd = 2.05;
const westStart = -6.7;
const westEnd = openingStart;
const westLength = westEnd - westStart;
const westCenter = (westStart + westEnd) / 2;
const westEnd2 = 5.2;
const westLength2 = westEnd2 - openingEnd;
const westCenter2 = (westEnd2 + openingEnd) / 2;
box(0.52, 3.18, westLength, mat.brick, gateX, 1.64, westCenter);
box(0.52, 3.18, westLength2, mat.brick, gateX, 1.64, westCenter2);
box(0.67, 0.22, westLength, mat.stone, gateX, 0.12, westCenter);
box(0.67, 0.22, westLength2, mat.stone, gateX, 0.12, westCenter2);
box(0.68, 0.18, westLength, mat.stoneLight, gateX, 3.28, westCenter);
box(0.68, 0.18, westLength2, mat.stoneLight, gateX, 3.28, westCenter2);
steppedRoof(1.65, 12.7, gateX, -0.75, 3.38, "z");
// Gate posts, lintel and threshold.
box(0.7, 2.65, 0.28, mat.red, -3.85, 1.38, openingStart);
box(0.7, 2.65, 0.28, mat.red, -3.85, 1.38, openingEnd);
box(0.72, 0.28, 2.78, mat.redDark, -3.83, 2.73, 0.85);
box(0.88, 0.14, 2.65, mat.stoneLight, -3.8, 0.13, 0.85);
// Door leaves open inward, revealing the courtyard.
function makeGateLeaf(hingeZ, direction) {
const hinge = new THREE.Group();
hinge.position.set(-4.25, 0, hingeZ);
hinge.rotation.y = direction > 0 ? -1.02 : 1.02;
scene.add(hinge);
box(0.13, 2.35, 1.13, mat.red, 0, 1.2, direction * 0.565, hinge);
box(0.07, 0.13, 1.08, mat.gold, 0.085, 2.12, direction * 0.565, hinge);
box(0.07, 0.13, 1.08, mat.gold, 0.085, 1.18, direction * 0.565, hinge);
box(0.07, 0.13, 1.08, mat.gold, 0.085, 0.28, direction * 0.565, hinge);
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 3; col++) {
box(0.06, 0.12, 0.12, mat.gold, 0.11, 0.62 + row * 0.63,
direction * (0.28 + col * 0.27), hinge);
}
}
box(0.08, 0.26, 0.08, mat.gold, 0.16, 1.18, direction * 0.98, hinge);
return hinge;
}
makeGateLeaf(openingStart, 1);
makeGateLeaf(openingEnd, -1);
sign("福", 0.62, 0.32, -3.82, 2.72, 0.85, Math.PI / 2);
lantern(-3.5, 2.22, -0.62);
lantern(-3.5, 2.22, 2.32);
// Small window in the compound wall.
windowX(-3.87, 1.6, -4.3, 1.05, 1.05);
// ------------------------------------------------------------
// Courtyard glimpse
// ------------------------------------------------------------
box(4.65, 0.1, 7.1, mat.stone, -6.75, 0.055, 0.65);
box(1.6, 0.08, 6.8, mat.path2, -5.45, 0.12, 0.65);
// Courtyard room at the back of the compound.
box(1.15, 2.85, 4.45, mat.brickDark, -8.05, 1.48, 0.75);
box(1.3, 0.18, 4.65, mat.stone, -8.05, 0.13, 0.75);
steppedRoof(1.9, 5.05, -8.05, 0.75, 2.98, "z");
// Door and lattice window face the lane.
box(0.09, 2.08, 0.95, mat.redDark, -7.44, 1.08, 1.7);
box(0.08, 1.05, 1.12, mat.glass, -7.44, 1.55, -0.6);
windowX(-7.36, 1.52, -0.6, 1.12, 1.05);
lantern(-7.18, 2.2, 1.7);
// Voxel courtyard tree.
const tree = new THREE.Group();
tree.position.set(-5.55, 0, 0.65);
scene.add(tree);
box(0.28, 1.6, 0.28, mat.trunk, 0, 0.8, 0, tree);
box(0.22, 0.9, 0.22, mat.trunk, 0.35, 1.55, 0.08, tree);
box(0.2, 0.85, 0.2, mat.trunk, -0.32, 1.42, 0.04, tree);
const foliage = [
[-0.42, 1.8, 0.1, 1.0, 0.78, 0.9, mat.foliage],
[0.38, 1.93, -0.02, 0.9, 0.85, 0.8, mat.foliageLight],
[0, 2.25, 0.08, 1.1, 0.9, 0.9, mat.foliage],
[-0.15, 2.62, -0.05, 0.75, 0.62, 0.7, mat.foliageLight],
[0.58, 2.35, 0.16, 0.62, 0.55, 0.62, mat.foliage],
[-0.63, 2.35, -0.04, 0.58, 0.52, 0.62, mat.foliageLight]
];
foliage.forEach(([x, y, z, w, h, d, material]) => {
box(w, h, d, material, x, y, z, tree);
});
// Stone planter and guardian lion.
box(0.95, 0.35, 0.95, mat.stoneLight, -5.45, 0.2, 2.25);
box(0.72, 0.06, 0.72, mat.trunk, -5.45, 0.4, 2.25);
const lion = new THREE.Group();
lion.position.set(-3.36, 0, 2.75);
scene.add(lion);
box(0.7, 0.16, 0.7, mat.stone, 0, 0.1, 0, lion);
box(0.48, 0.65, 0.46, mat.stoneLight, 0, 0.5, 0, lion);
box(0.48, 0.28, 0.28, mat.stone, 0.08, 0.25, -0.2, lion);
box(0.48, 0.28, 0.28, mat.stone, 0.08, 0.25, 0.2, lion);
box(0.64, 0.5, 0.58, mat.stone, -0.04, 0.98, 0, lion);
box(0.34, 0.3, 0.38, mat.stoneLight, 0.28, 0.96, 0, lion);
box(0.08, 0.08, 0.09, mat.stoneDark, 0.47, 1.04, -0.1, lion);
box(0.08, 0.08, 0.09, mat.stoneDark, 0.47, 1.04, 0.1, lion);
// ------------------------------------------------------------
// East side building and distant cross-lane house
// ------------------------------------------------------------
box(1.15, 3.2, 8.8, mat.brick, 4.25, 1.64, -2.35);
box(1.35, 0.2, 9.0, mat.stone, 4.25, 0.12, -2.35);
steppedRoof(2.0, 9.5, 4.25, -2.35, 3.32, "z");
// Details on the visible outer face.
windowX(4.85, 1.62, -5.15, 0.85, 1.0);
windowX(4.85, 1.62, -2.55, 0.85, 1.0);
windowX(4.85, 1.62, 0.05, 0.85, 1.0);
sign("胡同", 0.9, 0.3, 4.86, 2.63, -2.55, Math.PI / 2, "#414c50");
// Far building closes the view while leaving the lane visibly continuous.
box(9.0, 3.25, 1.4, mat.brick, 0, 1.68, -7.05);
box(9.25, 0.2, 1.62, mat.stone, 0, 0.12, -7.05);
steppedRoof(2.05, 9.85, 0, -7.05, 3.36, "x");
box(1.05, 2.12, 0.13, mat.redDark, 0, 1.12, -6.29);
box(0.08, 0.12, 0.12, mat.gold, 0.38, 1.08, -6.2);
box(1.25, 0.12, 0.55, mat.stoneLight, 0, 0.08, -5.92);
sign("福", 0.62, 0.32, 0, 2.62, -6.27, 0);
windowZ(-3.25, 1.67, -6.28, 1.15, 1.12);
windowZ(3.25, 1.67, -6.28, 1.15, 1.12);
windowZ(-1.72, 1.67, -6.28, 0.72, 1.12);
windowZ(1.72, 1.67, -6.28, 0.72, 1.12);
// ------------------------------------------------------------
// Voxel bicycle, parked at the lane edge
// ------------------------------------------------------------
const bicycle = new THREE.Group();
bicycle.position.set(2.12, 0.12, 3.75);
bicycle.rotation.y = -0.08;
scene.add(bicycle);
const rear = [0, 0.49, -0.72];
const front = [0, 0.49, 0.72];
const crank = [0, 0.56, -0.02];
const seatJoint = [0, 1.04, -0.3];
const headJoint = [0, 1.03, 0.5];
function bicycleWheel(center) {
const tire = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.065, 4, 12),
mat.rubber
);
tire.position.set(...center);
tire.rotation.y = Math.PI / 2;
tire.castShadow = true;
bicycle.add(tire);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.15, 8),
mat.stoneLight
);
hub.position.set(...center);
hub.rotation.z = Math.PI / 2;
bicycle.add(hub);
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 4;
beam(
[center[0], center[1], center[2]],
[
center[0],
center[1] + Math.cos(angle) * 0.38,
center[2] + Math.sin(angle) * 0.38
],
0.012,
mat.stoneLight,
bicycle,
4
);
}
}
bicycleWheel(rear);
bicycleWheel(front);
beam(rear, seatJoint, 0.035, mat.bike, bicycle);
beam(rear, crank, 0.035, mat.bike, bicycle);
beam(crank, seatJoint, 0.035, mat.bike, bicycle);
beam(seatJoint, headJoint, 0.038, mat.bike, bicycle);
beam(headJoint, crank, 0.035, mat.bike, bicycle);
beam(headJoint, front, 0.032, mat.bike, bicycle);
box(0.3, 0.08, 0.36, mat.wood, 0, 1.11, -0.32, bicycle);
box(0.035, 0.34, 0.035, mat.stoneLight, 0, 0.92, 0.57, bicycle);
beam([-0.28, 1.1, 0.58], [0.28, 1.1, 0.58], 0.03, mat.rubber, bicycle);
// Small front basket.
box(0.43, 0.08, 0.32, mat.wood, 0, 0.89, 0.79, bicycle);
box(0.08, 0.28, 0.32, mat.wood, -0.2, 1.02, 0.79, bicycle);
box(0.08, 0.28, 0.32, mat.wood, 0.2, 1.02, 0.79, bicycle);
box(0.43, 0.28, 0.07, mat.wood, 0, 1.02, 0.94, bicycle);
// ------------------------------------------------------------
// Voxel pedestrian walking along the edge of the shared route
// ------------------------------------------------------------
const pedestrian = new THREE.Group();
pedestrian.position.set(1.25, 0.1, -2.8);
scene.add(pedestrian);
function legPart(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.13, 0.68, 0);
pedestrian.add(pivot);
box(0.16, 0.5, 0.18, mat.trousers, 0, -0.25, 0, pivot);
box(0.19, 0.12, 0.33, mat.rubber, 0, -0.55, -0.06, pivot);
return pivot;
}
const leftLeg = legPart(-1);
const rightLeg = legPart(1);
box(0.5, 0.64, 0.31, mat.coat, 0, 0.98, 0, pedestrian);
box(0.39, 0.19, 0.33, mat.scarf, 0, 1.3, 0, pedestrian);
box(0.34, 0.34, 0.32, mat.skin, 0, 1.56, -0.01, pedestrian);
box(0.37, 0.12, 0.35, mat.hair, 0, 1.74, 0.01, pedestrian);
box(0.39, 0.18, 0.1, mat.hair, 0, 1.57, 0.15, pedestrian);
const leftArm = new THREE.Group();
leftArm.position.set(-0.31, 1.22, 0);
pedestrian.add(leftArm);
box(0.13, 0.51, 0.15, mat.coat, 0, -0.25, 0, leftArm);
box(0.12, 0.12, 0.13, mat.skin, 0, -0.55, 0, leftArm);
const rightArm = new THREE.Group();
rightArm.position.set(0.31, 1.22, 0);
pedestrian.add(rightArm);
box(0.13, 0.51, 0.15, mat.coat, 0, -0.25, 0, rightArm);
box(0.12, 0.12, 0.13, mat.skin, 0, -0.55, 0, rightArm);
// A small warm-colored carry bag.
box(0.25, 0.3, 0.16, mat.scarf, 0.39, 0.79, 0.02, pedestrian);
box(0.025, 0.32, 0.025, mat.wood, 0.31, 1.04, 0.02, pedestrian);
box(0.025, 0.32, 0.025, mat.wood, 0.47, 1.04, 0.02, pedestrian);
// ------------------------------------------------------------
// Small street details
// ------------------------------------------------------------
// Planters beside the distant house.
for (const x of [-2.8, 2.8]) {
box(0.48, 0.42, 0.48, mat.redDark, x, 0.24, -5.82);
box(0.38, 0.28, 0.38, mat.foliage, x, 0.58, -5.82);
}
// Drain stones along the curb.
for (let i = 0; i < 8; i++) {
box(0.34, 0.035, 0.48, mat.stoneDark, 2.28, 0.155, 5.7 - i * 1.7);
}
// ------------------------------------------------------------
// Direct camera controls — no external controls module
// ------------------------------------------------------------
const defaultTarget = new THREE.Vector3(0, 1.05, 0);
const viewState = {
theta: 0.67,
phi: 1.04,
radius: 22,
target: defaultTarget.clone()
};
const goal = {
theta: viewState.theta,
phi: viewState.phi,
radius: viewState.radius,
target: viewState.target.clone()
};
const views = {
overview: {
theta: 0.67,
phi: 1.04,
radius: 22,
target: new THREE.Vector3(0, 1.05, 0)
},
courtyard: {
theta: 1.02,
phi: 1.13,
radius: 10.8,
target: new THREE.Vector3(-4.25, 1.4, 0.8)
},
lane: {
theta: 0.24,
phi: 1.17,
radius: 17.5,
target: new THREE.Vector3(0, 0.9, 0.6)
}
};
function setView(name) {
const view = views[name];
goal.theta = view.theta;
goal.phi = view.phi;
goal.radius = view.radius;
goal.target.copy(view.target);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
document.querySelectorAll("[data-view]").forEach((b) => b.classList.remove("active"));
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
goal.theta -= dx * 0.006;
goal.phi = THREE.MathUtils.clamp(goal.phi - dy * 0.005, 0.48, 1.42);
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
goal.radius = THREE.MathUtils.clamp(
goal.radius + event.deltaY * 0.018,
8.5,
31
);
}, { passive: false });
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const t = clock.getElapsedTime();
// Smooth camera interpolation.
viewState.theta = THREE.MathUtils.lerp(viewState.theta, goal.theta, 0.075);
viewState.phi = THREE.MathUtils.lerp(viewState.phi, goal.phi, 0.075);
viewState.radius = THREE.MathUtils.lerp(viewState.radius, goal.radius, 0.075);
viewState.target.lerp(goal.target, 0.075);
const sinPhi = Math.sin(viewState.phi);
camera.position.set(
viewState.target.x + viewState.radius * sinPhi * Math.sin(viewState.theta),
viewState.target.y + viewState.radius * Math.cos(viewState.phi),
viewState.target.z + viewState.radius * sinPhi * Math.cos(viewState.theta)
);
camera.lookAt(viewState.target);
// The pedestrian walks on the outer paving, never on the central spine.
const walk = (t * 0.26) % 7.4;
pedestrian.position.z = -4.2 + walk;
pedestrian.position.y = 0.1 + Math.abs(Math.sin(t * 5.2)) * 0.012;
leftLeg.rotation.x = Math.sin(t * 5.2) * 0.28;
rightLeg.rotation.x = -Math.sin(t * 5.2) * 0.28;
leftArm.rotation.x = -Math.sin(t * 5.2) * 0.2;
rightArm.rotation.x = Math.sin(t * 5.2) * 0.2;
pedestrian.rotation.y = 0.02;
// A nearly imperceptible lantern glow.
const pulse = 0.62 + Math.sin(t * 2.4) * 0.035;
scene.traverse((object) => {
if (object.isPointLight) object.intensity = pulse;
});
renderer.render(scene, camera);
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("done");
});
</script>
</body>
</html>
```