Prompt specification
Build or customize the Three.js 3D scene "Goods restocking beneath a Taipei arcade" 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: Goods restocking beneath a Taipei arcade
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/goods-restocking-beneath-a-taipei-arcade-x3034
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Dihua Street's commercial arcades in Taipei. Create a compact referenced vignette with original dry-goods shop, delivery cart, and pedestrian. Animate stock moving inside while preserving the covered through-route. Low-poly.
Working Three.js Starter (goods-restocking-beneath-a-taipei-arcade-x3034):
```html
<!doctype html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>迪化街・青禾布行 — Three.js Vignette</title>
<style>
:root {
color-scheme: light;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
"Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d1bf;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.title-card {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
max-width: min(390px, calc(100vw - 48px));
padding: 16px 18px 15px;
color: #243638;
background: rgba(246, 241, 225, 0.91);
border: 1px solid rgba(45, 61, 59, 0.2);
border-left: 4px solid #aa513d;
box-shadow: 0 12px 30px rgba(53, 42, 30, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
color: #9b4939;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1.08;
font-weight: 800;
letter-spacing: 0.02em;
}
.subtitle {
margin-top: 8px;
font-size: 12px;
line-height: 1.55;
color: #566360;
}
.controls {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 10;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(35, 54, 56, 0.26);
border-radius: 3px;
padding: 9px 12px;
color: #26383a;
background: rgba(247, 242, 226, 0.92);
box-shadow: 0 5px 16px rgba(39, 33, 24, 0.1);
font: 650 11px/1.2 system-ui, sans-serif;
letter-spacing: 0.035em;
cursor: pointer;
backdrop-filter: blur(7px);
}
button:hover {
background: #fff9e9;
border-color: rgba(35, 54, 56, 0.52);
}
button:focus-visible {
outline: 2px solid #aa513d;
outline-offset: 2px;
}
.hint {
position: fixed;
left: 24px;
bottom: 20px;
z-index: 9;
padding: 8px 10px;
color: rgba(35, 53, 54, 0.78);
background: rgba(246, 241, 225, 0.7);
border-radius: 3px;
font-size: 10px;
letter-spacing: 0.05em;
pointer-events: none;
}
.loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #354847;
background: #d8d1bf;
font-size: 12px;
letter-spacing: 0.14em;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.title-card {
top: 12px;
left: 12px;
padding: 12px 14px;
}
.subtitle {
display: none;
}
.hint {
left: 12px;
bottom: 12px;
max-width: 180px;
line-height: 1.45;
}
.controls {
right: 12px;
bottom: 12px;
}
button {
padding: 8px 9px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="loading" class="loading">正在搭建迪化街騎樓…</div>
<section class="title-card" aria-label="Scene information">
<div class="eyebrow">Taipei · Interpretive Low-Poly Miniature</div>
<h1>迪化街・青禾布行</h1>
<div class="subtitle">
An original fictional dry-goods shop beneath a continuous covered arcade.
Fabric stock moves inside while the pedestrian through-route remains open.
</div>
</section>
<div class="hint">拖曳旋轉 · 滾輪縮放 · 雙擊重設視角</div>
<div class="controls">
<button id="roofButton" type="button">完整屋頂</button>
<button id="motionButton" type="button">暫停動態</button>
<button id="resetButton" type="button">重設視角</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.querySelector("#loading");
const roofButton = document.querySelector("#roofButton");
const motionButton = document.querySelector("#motionButton");
const resetButton = document.querySelector("#resetButton");
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d1bf);
scene.fog = new THREE.Fog(0xd8d1bf, 27, 62);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.body.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf4edda, 0x756556, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc7, 3.0);
sun.position.set(-9, 16, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x91b6bd, 0.85);
fill.position.set(12, 8, -9);
scene.add(fill);
// ------------------------------------------------------------
// Shared helpers
// ------------------------------------------------------------
const palette = {
brick: 0xa95742,
brickDark: 0x743c32,
brickLight: 0xc16d50,
stone: 0xc8b895,
stoneDark: 0x8e8069,
wood: 0x674734,
woodLight: 0x98734b,
darkWood: 0x3f342c,
teal: 0x315d60,
tealLight: 0x5f8b83,
cream: 0xe8dcc1,
road: 0x5d6260,
sidewalk: 0xb5ad99,
asphalt: 0x444b4a,
red: 0xb83f32,
ink: 0x23383a
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function box(
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
options = {}
) {
const mat = color?.isMaterial ? color : material(color, options);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
segments,
color,
x = 0,
y = 0,
z = 0,
parent = scene,
options = {}
) {
const mat = color?.isMaterial ? color : material(color, options);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function icosahedron(radius, color, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 0),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function canvasTexture(
width,
height,
draw,
repeatX = 1,
repeatY = 1
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(repeatX, repeatY);
return texture;
}
function signPlane(texture, width, height, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: false,
side: THREE.DoubleSide
})
);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function makeHorizontalSign(main, sub, background, foreground) {
const texture = canvasTexture(640, 190, (ctx, w, h) => {
ctx.fillStyle = background;
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = foreground;
ctx.lineWidth = 6;
ctx.strokeRect(12, 12, w - 24, h - 24);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = '800 72px "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif';
ctx.fillText(main, w / 2, h * 0.43);
ctx.font = '600 22px system-ui, sans-serif';
ctx.letterSpacing = "4px";
ctx.fillText(sub, w / 2, h * 0.78);
});
return texture;
}
function makeVerticalSign(text, background, foreground) {
return canvasTexture(260, 720, (ctx, w, h) => {
ctx.fillStyle = background;
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = foreground;
ctx.lineWidth = 7;
ctx.strokeRect(13, 13, w - 26, h - 26);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = '800 104px "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif';
const chars = [...text];
const start = 105;
const gap = 132;
chars.forEach((char, index) => {
ctx.fillText(char, w / 2, start + index * gap);
});
});
}
function makeSmallSign(text, background, foreground) {
return canvasTexture(520, 130, (ctx, w, h) => {
ctx.fillStyle = background;
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = foreground;
ctx.lineWidth = 4;
ctx.strokeRect(8, 8, w - 16, h - 16);
ctx.fillStyle = foreground;
ctx.font = '700 40px "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif';
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2 + 2);
});
}
// ------------------------------------------------------------
// Ground, road, and paving
// ------------------------------------------------------------
const ground = box(70, 0.22, 70, 0xa9a18d, 0, -0.28, 0);
ground.castShadow = false;
const sidewalk = box(28, 0.18, 7.0, palette.sidewalk, 0, -0.02, 0);
sidewalk.castShadow = false;
const road = box(70, 0.14, 25, palette.road, 0, -0.16, 15.7);
road.castShadow = false;
const curb = box(28, 0.24, 0.24, 0xc8bea8, 0, 0.04, 3.58);
curb.castShadow = false;
const gutter = box(28, 0.025, 0.18, 0x444a48, 0, 0.015, 3.95);
gutter.castShadow = false;
// Paving seams under the covered arcade.
for (let x = -13; x <= 13; x += 1.3) {
box(0.025, 0.015, 6.4, 0x8d8879, x, 0.085, 0.1);
}
for (let z = -3.1; z <= 3.2; z += 1.3) {
box(26.8, 0.016, 0.025, 0x8d8879, 0, 0.087, z);
}
// A discreet central road drain.
box(1.25, 0.03, 0.24, 0x303838, 6.5, -0.07, 4.05);
for (let i = 0; i < 8; i++) {
box(0.055, 0.034, 0.22, 0x77796f, 6.04 + i * 0.13, -0.05, 4.05);
}
// ------------------------------------------------------------
// Main arcade building
// ------------------------------------------------------------
const building = new THREE.Group();
scene.add(building);
const bayWidth = 3.2;
const bayCenters = [];
const columnXs = [];
for (let i = 0; i < 8; i++) {
bayCenters.push(-9.6 + i * bayWidth);
columnXs.push(-11.2 + i * bayWidth);
}
columnXs.push(11.2);
const brickMaterial = material(palette.brick);
const brickDarkMaterial = material(palette.brickDark);
const brickLightMaterial = material(palette.brickLight);
const stoneMaterial = material(palette.stone);
const stoneDarkMaterial = material(palette.stoneDark);
// Rear wall and side walls.
box(22.8, 6.6, 0.34, brickMaterial, 0, 3.25, -3.45, building);
box(0.34, 6.6, 3.55, brickDarkMaterial, -11.35, 3.25, -1.7, building);
box(0.34, 6.6, 3.55, brickDarkMaterial, 11.35, 3.25, -1.7, building);
// Upper facade.
box(22.8, 2.55, 0.34, brickMaterial, 0, 5.35, 0.02, building);
box(23.0, 0.22, 0.48, brickLightMaterial, 0, 6.62, 0.04, building);
box(22.8, 0.18, 0.40, stoneDarkMaterial, 0, 4.10, 0.05, building);
// Decorative horizontal mortar bands.
for (let y = 4.5; y < 6.5; y += 0.55) {
box(22.5, 0.035, 0.025, 0x7e493d, 0, y, 0.205, building);
}
// Bay divisions and lower facade columns.
for (const x of columnXs) {
box(0.50, 4.12, 0.55, brickLightMaterial, x, 2.04, 0.16, building);
box(0.67, 0.25, 0.70, stoneDarkMaterial, x, 0.12, 0.18, building);
box(0.65, 0.18, 0.68, stoneMaterial, x, 3.93, 0.18, building);
}
// Low-poly semicircular arch rings.
function addArch(centerX, z) {
const segments = 10;
const innerRadius = 1.35;
const outerRadius = 1.57;
const springY = 2.52;
const radialWidth = outerRadius - innerRadius;
const middleRadius = (innerRadius + outerRadius) / 2;
const tangentLength = (Math.PI * middleRadius) / segments * 1.12;
for (let i = 0; i < segments; i++) {
const angle = ((i + 0.5) / segments) * Math.PI;
const stone = i % 3 === 0 ? stoneDarkMaterial : stoneMaterial;
const segment = box(
radialWidth,
tangentLength,
0.46,
stone,
centerX + Math.cos(angle) * middleRadius,
springY + Math.sin(angle) * middleRadius,
z,
building
);
segment.rotation.z = angle;
}
// Small keystone.
const key = box(
0.34,
0.47,
0.52,
stoneDarkMaterial,
centerX,
springY + outerRadius + 0.05,
z + 0.015,
building
);
key.rotation.z = Math.PI / 4;
}
bayCenters.forEach((x) => addArch(x, 0.22));
// Upper-floor windows.
bayCenters.forEach((x, index) => {
const frame = box(1.42, 1.32, 0.11, 0x423d35, x, 5.68, 0.25, building);
box(1.12, 1.02, 0.08, index % 2 ? 0x36545a : 0x45696b, x, 5.68, 0.325, building);
box(0.065, 1.04, 0.05, 0xb8ad91, x, 5.68, 0.375, building);
box(1.13, 0.065, 0.05, 0xb8ad91, x, 5.68, 0.375, building);
});
// Closed neighboring shopfront shutters.
const shutterColors = [0x65746a, 0x8b7657, 0x526b6b, 0x8f6752, 0x6e756d, 0x7b715e, 0x5d7670];
let shutterIndex = 0;
bayCenters.forEach((x, index) => {
if (index === 3) return; // Central bay is the open dry-goods shop.
const shutter = box(
2.64,
2.50,
0.13,
shutterColors[shutterIndex++ % shutterColors.length],
x,
1.25,
0.29,
building
);
for (let y = 0.22; y < 2.5; y += 0.19) {
box(2.55, 0.035, 0.025, 0x3d4641, x, y, 0.37, building);
}
box(2.75, 0.11, 0.24, stoneDarkMaterial, x, 0.12, 0.33, building);
});
// Neighboring shop signs.
const neighboringSigns = [
[-9.6, "山城茶莊", "TEA & TEA LEAVES"],
[-6.4, "文昌紙墨", "PAPER & INK"],
[-3.2, "豐年香舖", "INCENSE & GIFTS"],
[3.2, "新聲鐘錶", "CLOCKS & REPAIRS"],
[6.4, "永昌陶具", "CERAMIC GOODS"],
[9.6, "南街雜貨", "HOUSEHOLD GOODS"]
];
neighboringSigns.forEach(([x, title, subtitle], index) => {
const texture = makeHorizontalSign(
title,
subtitle,
index % 2 ? "#d9ccb0" : "#294c4e",
index % 2 ? "#344444" : "#efe3c9"
);
signPlane(texture, 2.72, 0.72, x, 4.58, 0.43, building);
});
// ------------------------------------------------------------
// Covered arcade / 騎樓
// ------------------------------------------------------------
const arcade = new THREE.Group();
scene.add(arcade);
// Front edge columns remain at the street edge, leaving the route open.
columnXs.forEach((x) => {
box(0.40, 4.06, 0.40, stoneMaterial, x, 2.03, 3.18, arcade);
box(0.55, 0.22, 0.55, stoneDarkMaterial, x, 0.11, 3.18, arcade);
box(0.55, 0.18, 0.55, stoneMaterial, x, 3.95, 3.18, arcade);
});
// Continuous longitudinal beams.
box(22.9, 0.25, 0.34, stoneDarkMaterial, 0, 4.22, 0.20, arcade);
box(22.9, 0.28, 0.38, stoneDarkMaterial, 0, 4.22, 3.18, arcade);
// Cross rafters.
columnXs.forEach((x) => {
box(0.15, 0.16, 3.12, 0x776c58, x, 4.34, 1.68, arcade);
});
// A transparent default is an architectural cutaway; the button restores
// the full covered roof without moving any of the arcade supports.
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x446866,
roughness: 0.86,
metalness: 0,
flatShading: true,
transparent: true,
opacity: 0.16,
depthWrite: false,
side: THREE.DoubleSide
});
const roof = new THREE.Mesh(
new THREE.PlaneGeometry(22.8, 3.15),
roofMaterial
);
roof.rotation.x = -Math.PI / 2;
roof.position.set(0, 4.43, 1.68);
roof.receiveShadow = true;
arcade.add(roof);
// Small route marker attached to the outer arcade beam.
const arcadeSignTexture = makeSmallSign(
"騎樓通廊 · COVERED ARCADE",
"#315557",
"#eee2c7"
);
signPlane(arcadeSignTexture, 4.6, 0.42, -6.4, 4.18, 3.405, arcade);
// ------------------------------------------------------------
// Original dry-goods shop: 青禾布行
// ------------------------------------------------------------
const dryShop = new THREE.Group();
scene.add(dryShop);
// Interior floor, back wall, and side partitions.
box(3.18, 0.10, 3.45, 0x887457, 0, 0.13, -1.56, dryShop);
box(3.18, 3.78, 0.18, 0xb48363, 0, 1.98, -3.27, dryShop);
box(0.16, 3.75, 3.25, 0x9b6d51, -1.55, 1.96, -1.65, dryShop);
box(0.16, 3.75, 3.25, 0x9b6d51, 1.55, 1.96, -1.65, dryShop);
// Main sign.
const dryShopSign = makeHorizontalSign(
"青禾布行",
"QINGHE · COTTON, LINEN & RIBBONS",
"#254d4f",
"#f1e4c8"
);
signPlane(dryShopSign, 3.45, 0.86, 0, 4.73, 0.44, dryShop);
// Vertical original-shop sign.
const verticalSignTexture = makeVerticalSign(
"青禾布行",
"#9e4939",
"#f4e6c9"
);
signPlane(verticalSignTexture, 0.76, 2.55, -1.91, 2.82, 0.58, dryShop);
// Front counter.
box(2.72, 0.78, 0.62, palette.wood, 0, 0.55, -0.08, dryShop);
box(2.86, 0.12, 0.76, palette.woodLight, 0, 0.99, -0.05, dryShop);
// Counter drawers and trim.
for (const x of [-0.88, 0, 0.88]) {
box(0.74, 0.48, 0.035, 0x765037, x, 0.57, 0.245, dryShop);
box(0.18, 0.055, 0.055, 0xc5a66e, x, 0.65, 0.28, dryShop);
}
// Shelves against the rear wall.
const shelfYs = [0.70, 1.48, 2.28];
shelfYs.forEach((y) => {
box(2.68, 0.10, 0.56, palette.woodLight, 0, y, -2.82, dryShop);
box(2.68, 0.15, 0.07, palette.darkWood, 0, y - 0.10, -2.53, dryShop);
});
const textileColors = [
0xbd6a55, 0x4f7a72, 0xd3b56d, 0x6a7894,
0x9b7354, 0x83905c, 0xc78a78, 0x45656b
];
// Rolls of cloth on the shelves.
shelfYs.forEach((shelfY, shelfIndex) => {
for (let i = 0; i < 6; i++) {
const roll = cylinder(
0.115,
0.115,
0.73,
8,
textileColors[(i + shelfIndex * 2) % textileColors.length],
-1.04 + i * 0.41,
shelfY + 0.19,
-2.78,
dryShop,
{ roughness: 0.95 }
);
roll.rotation.z = Math.PI / 2;
}
});
// Folded cloth stacks on the middle shelf.
for (let stack = 0; stack < 2; stack++) {
for (let layer = 0; layer < 3; layer++) {
box(
0.58,
0.13,
0.38,
textileColors[(stack * 3 + layer) % textileColors.length],
-0.88 + stack * 1.65,
1.65 + layer * 0.135,
-2.78,
dryShop
);
}
}
// Interior stock conveyor / visible moving parcels.
box(2.95, 0.08, 0.12, 0x4d5048, 0, 0.82, -1.15, dryShop);
box(2.95, 0.055, 0.06, 0xa7a083, 0, 0.87, -1.08, dryShop);
const movingStock = [];
function makeTextileParcel(color, parent) {
const group = new THREE.Group();
parent.add(group);
box(0.46, 0.14, 0.39, color, 0, 0.08, 0, group);
box(0.43, 0.13, 0.37, color, 0.025, 0.21, 0, group);
box(0.39, 0.12, 0.35, color, -0.02, 0.33, 0, group);
box(0.075, 0.45, 0.405, 0xdac493, 0, 0.20, 0, group);
return group;
}
for (let i = 0; i < 4; i++) {
const parcel = makeTextileParcel(
textileColors[(i + 3) % textileColors.length],
dryShop
);
parcel.position.set(-1.35 + i * 0.75, 0.88, -1.13);
movingStock.push(parcel);
}
// Hanging textile samples.
[-1.18, 1.18].forEach((x, index) => {
const sample = box(
0.25,
1.18,
0.035,
index ? 0x5b8177 : 0xb45f4d,
x,
2.13,
-1.53,
dryShop
);
sample.rotation.z = index ? -0.045 : 0.045;
});
// Red shop lanterns.
function addLantern(x, y, z, parent) {
const body = cylinder(0.18, 0.18, 0.42, 8, palette.red, x, y, z, parent);
const top = cylinder(0.11, 0.14, 0.07, 8, 0x503a31, x, y + 0.24, z, parent);
const bottom = cylinder(0.11, 0.14, 0.07, 8, 0x503a31, x, y - 0.24, z, parent);
box(0.025, 0.22, 0.025, 0x4b3b30, x, y + 0.39, z, parent);
return body;
}
addLantern(-1.38, 3.36, 0.72, dryShop);
addLantern(1.38, 3.36, 0.72, dryShop);
const warmInterior = new THREE.PointLight(0xffbd73, 13, 7.5, 2);
warmInterior.position.set(0, 2.8, -1.25);
dryShop.add(warmInterior);
// ------------------------------------------------------------
// Delivery cart
// ------------------------------------------------------------
const deliveryCart = new THREE.Group();
scene.add(deliveryCart);
const cartWood = material(0x795235);
const cartDark = material(0x463a2f);
const cartBlue = material(0x47777a);
// Bed and sideboards.
box(1.42, 0.16, 1.10, cartWood, 0, 0.88, 0, deliveryCart);
box(1.42, 0.48, 0.10, cartWood, 0, 1.15, -0.50, deliveryCart);
box(1.42, 0.48, 0.10, cartWood, 0, 1.15, 0.50, deliveryCart);
box(0.10, 0.48, 1.10, cartWood, -0.66, 1.15, 0, deliveryCart);
box(0.10, 0.48, 1.10, cartWood, 0.66, 1.15, 0, deliveryCart);
// Cargo crates.
box(0.43, 0.36, 0.43, 0xa77950, -0.28, 1.15, 0.15, deliveryCart);
box(0.39, 0.31, 0.39, 0xc39b69, 0.22, 1.12, -0.13, deliveryCart);
// Low-poly tarp.
box(1.38, 0.12, 1.10, cartBlue, 0, 1.72, 0, deliveryCart);
const tarpLeft = box(
1.38,
0.48,
0.10,
cartBlue,
0,
1.55,
-0.50,
deliveryCart
);
tarpLeft.rotation.x = -0.22;
const tarpRight = box(
1.38,
0.48,
0.10,
cartBlue,
0,
1.55,
0.50,
deliveryCart
);
tarpRight.rotation.x = 0.22;
const tarpFront = box(
0.10,
0.48,
1.10,
0x3e686d,
0.66,
1.55,
0,
deliveryCart
);
tarpFront.rotation.z = 0.20;
// Handle.
box(0.10, 0.10, 0.85, cartDark, -0.97, 1.03, 0, deliveryCart);
box(0.10, 0.72, 0.10, cartDark, -0.97, 1.34, -0.35, deliveryCart);
box(0.10, 0.72, 0.10, cartDark, -0.97, 1.34, 0.35, deliveryCart);
box(0.10, 0.10, 0.82, cartDark, -0.97, 1.70, 0, deliveryCart);
// Wheels use pivots so they visibly rotate.
const cartWheels = [];
[-0.63, 0.63].forEach((x) => {
[-0.60, 0.60].forEach((z) => {
const pivot = new THREE.Group();
pivot.position.set(x, 0.38, z);
deliveryCart.add(pivot);
const wheel = cylinder(
0.34,
0.34,
0.16,
10,
0x303534,
0,
0,
0,
pivot
);
wheel.rotation.x = Math.PI / 2;
const hub = cylinder(
0.11,
0.11,
0.18,
8,
0x8f8065,
0,
0,
0,
pivot
);
hub.rotation.x = Math.PI / 2;
cartWheels.push(pivot);
});
});
const cartLabelTexture = makeSmallSign(
"松信號・日常配送",
"#d4c29d",
"#384440"
);
signPlane(cartLabelTexture, 1.18, 0.28, 0, 1.19, 0.565, deliveryCart);
deliveryCart.position.set(-6.2, 0.11, 1.58);
// ------------------------------------------------------------
// Pedestrian
// ------------------------------------------------------------
const pedestrian = new THREE.Group();
scene.add(pedestrian);
const skin = material(0xd9a67e);
const shirt = material(0x477a76);
const trousers = material(0x39484b);
const bagMaterial = material(0xa95c46);
// Torso and neck.
box(0.50, 0.66, 0.28, shirt, 0, 1.12, 0, pedestrian);
cylinder(0.10, 0.11, 0.17, 8, skin, 0, 1.54, 0, pedestrian);
// Head and hat.
icosahedron(0.235, skin, 0, 1.73, 0, pedestrian);
cylinder(0.25, 0.28, 0.10, 10, 0x8c7650, 0, 1.91, 0, pedestrian);
cylinder(0.33, 0.33, 0.045, 10, 0x8c7650, 0, 1.86, 0, pedestrian);
// Leg pivots.
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.14, 0.85, 0);
rightLeg.position.set(0.14, 0.85, 0);
pedestrian.add(leftLeg, rightLeg);
[-1, 1].forEach((side) => {
const pivot = side < 0 ? leftLeg : rightLeg;
box(0.20, 0.59, 0.22, trousers, 0, -0.30, 0, pivot);
box(0.23, 0.13, 0.37, 0x303332, 0, -0.61, 0.055, pivot);
});
// Arm pivots.
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.34, 1.39, 0);
rightArm.position.set(0.34, 1.39, 0);
pedestrian.add(leftArm, rightArm);
box(0.17, 0.53, 0.20, shirt, 0, -0.25, 0, leftArm);
box(0.17, 0.53, 0.20, shirt, 0, -0.25, 0, rightArm);
icosahedron(0.105, skin, 0, -0.56, 0, leftArm);
icosahedron(0.105, skin, 0, -0.56, 0, rightArm);
// Canvas tote.
box(0.33, 0.42, 0.16, bagMaterial, 0.43, 0.91, 0.05, pedestrian);
const handle = box(
0.025,
0.26,
0.025,
0xd7bd83,
0.43,
1.23,
0.05,
pedestrian
);
handle.rotation.z = -0.18;
pedestrian.position.set(5.5, 0.12, 2.30);
pedestrian.rotation.y = Math.PI;
// ------------------------------------------------------------
// Street furniture
// ------------------------------------------------------------
// Slim street lamps at the curb, outside the clear through-route.
function addStreetLamp(x, z) {
const group = new THREE.Group();
scene.add(group);
cylinder(0.075, 0.11, 4.4, 8, 0x46504c, x, 2.2, z, group);
box(0.60, 0.10, 0.13, 0x46504c, x + 0.22, 4.37, z, group);
box(0.36, 0.12, 0.26, 0xd2b982, x + 0.43, 4.28, z, group);
const light = new THREE.PointLight(0xffd394, 7, 7, 2);
light.position.set(x + 0.43, 4.1, z);
group.add(light);
}
addStreetLamp(-10.4, 4.35);
addStreetLamp(10.4, 4.35);
// Small planter, kept beyond the covered walkway.
box(0.88, 0.64, 0.88, 0x9d8064, -7.8, 0.33, 4.55);
cylinder(0.11, 0.15, 2.2, 7, 0x70563b, -7.8, 1.66, 4.55);
icosahedron(0.82, 0x71875e, -7.8, 2.76, 4.55);
icosahedron(0.54, 0x879567, -8.25, 2.45, 4.65);
// Distant simple roof forms behind the vignette.
box(28, 0.35, 7.5, 0x6e5548, 0, 6.78, -2.05);
// ------------------------------------------------------------
// Custom camera controls — no addons
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.05, -0.10),
radius: 20.6,
theta: 0.58,
phi: 1.245
};
const defaultCameraState = {
radius: 20.6,
theta: 0.58,
phi: 1.245
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.004,
0.45,
1.48
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event?.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
33
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.radius = defaultCameraState.radius;
cameraState.theta = defaultCameraState.theta;
cameraState.phi = defaultCameraState.phi;
updateCamera();
});
renderer.domElement.style.cursor = "grab";
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.theta += 0.08;
if (event.key === "ArrowRight") cameraState.theta -= 0.08;
if (event.key === "ArrowUp") cameraState.phi -= 0.05;
if (event.key === "ArrowDown") cameraState.phi += 0.05;
if (event.key === "+" || event.key === "=") cameraState.radius -= 0.6;
if (event.key === "-") cameraState.radius += 0.6;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi, 0.45, 1.48);
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 10, 33);
updateCamera();
});
resetButton.addEventListener("click", () => {
cameraState.radius = defaultCameraState.radius;
cameraState.theta = defaultCameraState.theta;
cameraState.phi = defaultCameraState.phi;
updateCamera();
});
let fullRoof = false;
roofButton.addEventListener("click", () => {
fullRoof = !fullRoof;
roofMaterial.opacity = fullRoof ? 0.92 : 0.16;
roofMaterial.depthWrite = fullRoof;
roofMaterial.needsUpdate = true;
roofButton.textContent = fullRoof ? "剖視屋頂" : "完整屋頂";
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
let motionEnabled = true;
let simulationTime = 0;
const clock = new THREE.Clock();
motionButton.addEventListener("click", () => {
motionEnabled = !motionEnabled;
motionButton.textContent = motionEnabled ? "暫停動態" : "繼續動態";
});
function positiveModulo(value, divisor) {
return ((value % divisor) + divisor) % divisor;
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (motionEnabled) {
simulationTime += delta;
}
const t = simulationTime;
// Stock parcels loop continuously on the interior rail.
movingStock.forEach((parcel, index) => {
const travel = positiveModulo(index * 0.75 + t * 0.72, 3.0);
parcel.position.x = -1.35 + travel;
parcel.rotation.y = Math.sin(t * 1.4 + index) * 0.025;
});
// Delivery cart moves slowly along the covered route.
const cartTravel = positiveModulo(t * 0.62, 18.5);
const nextCartX = -9.25 + cartTravel;
const previousCartX = deliveryCart.position.x;
deliveryCart.position.x = nextCartX;
const cartDelta = nextCartX - previousCartX;
cartWheels.forEach((wheel) => {
wheel.rotation.z -= cartDelta / 0.34;
});
// Pedestrian walks in the opposite direction, still beneath the arcade.
const walkTravel = positiveModulo(t * 0.73 + 2.0, 18.5);
pedestrian.position.x = 9.25 - walkTravel;
pedestrian.position.y = 0.12 + Math.abs(Math.sin(t * 4.6)) * 0.025;
const stride = Math.sin(t * 4.6);
leftLeg.rotation.x = stride * 0.48;
rightLeg.rotation.x = -stride * 0.48;
leftArm.rotation.x = -stride * 0.34;
rightArm.rotation.x = stride * 0.34;
// Gentle secondary motion keeps the still scene alive.
deliveryCart.position.y = 0.11 + Math.sin(t * 3.2) * 0.012;
pedestrian.rotation.z = Math.sin(t * 2.35) * 0.012;
renderer.render(scene, camera);
}
updateCamera();
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
window.setTimeout(() => {
loading.classList.add("hidden");
window.setTimeout(() => loading.remove(), 500);
}, 450);
</script>
</body>
</html>
```