Prompt specification
Build or customize the Three.js 3D scene "Repair worker outside a Penang shopfront" 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: Repair worker outside a Penang shopfront
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/repair-worker-outside-a-penang-shopfront-x3014
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring George Town's shophouses in Penang. Create a compact referenced vignette with an original repair stall, customer, and passing pedestrian. Show skilled work and distinct commercial functions rather than repeating identical souvenir shops. Voxel style.
Working Three.js Starter (repair-worker-outside-a-penang-shopfront-x3014):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>George Town Trade Walk — A Voxel Vignette</title>
<style>
:root {
color-scheme: light;
--ink: #173f3b;
--paper: #fff9e9;
--accent: #d85c3f;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #acd9d1;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
color: var(--ink);
}
#title {
top: 20px;
left: 20px;
max-width: min(470px, calc(100vw - 40px));
}
.eyebrow {
display: inline-block;
padding: 5px 9px;
margin-bottom: 8px;
border: 2px solid var(--ink);
background: var(--paper);
font-size: 11px;
font-weight: 900;
letter-spacing: .13em;
box-shadow: 4px 4px 0 rgba(23, 63, 59, .18);
}
h1 {
margin: 0;
font-size: clamp(22px, 3.6vw, 42px);
line-height: .98;
letter-spacing: -.055em;
text-shadow: 0 2px 0 rgba(255, 249, 233, .4);
}
#subtitle {
margin: 9px 0 0;
max-width: 420px;
font-size: 12px;
line-height: 1.45;
font-weight: 700;
}
#trade-strip {
left: 20px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 6px;
max-width: calc(100vw - 190px);
}
.trade {
padding: 5px 8px;
border: 1px solid rgba(23, 63, 59, .65);
background: rgba(255, 249, 233, .88);
box-shadow: 2px 2px 0 rgba(23, 63, 59, .12);
font-size: 10px;
font-weight: 900;
letter-spacing: .06em;
}
#controls {
right: 18px;
bottom: 18px;
padding: 10px 12px;
border: 2px solid var(--ink);
background: rgba(255, 249, 233, .92);
box-shadow: 4px 4px 0 rgba(23, 63, 59, .16);
font-size: 10px;
line-height: 1.55;
font-weight: 800;
text-align: right;
}
#reset {
margin-top: 7px;
padding: 5px 9px;
border: 2px solid var(--ink);
background: var(--accent);
color: white;
font: inherit;
font-weight: 900;
cursor: pointer;
pointer-events: auto;
}
#reset:hover { background: #b8412b; }
#reset:active { transform: translate(1px, 1px); }
#loading {
position: fixed;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #acd9d1;
color: var(--ink);
font-weight: 900;
letter-spacing: .12em;
}
@media (max-width: 650px) {
#title { top: 12px; left: 12px; }
#subtitle { max-width: 290px; font-size: 10px; }
#trade-strip {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
#controls {
right: 12px;
bottom: 88px;
padding: 7px 9px;
}
.trade { font-size: 8px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="title" class="hud">
<div class="eyebrow">GEORGE TOWN · PENANG</div>
<h1>TRADE WALK</h1>
<p id="subtitle">
A compact five-foot-way vignette: pastel shophouses, working trades,
and an original key-and-lock repair stall.
</p>
</div>
<div id="trade-strip" class="hud">
<span class="trade">KOFFEE</span>
<span class="trade">TAILOR</span>
<span class="trade">TEH TARIK</span>
<span class="trade">PRINT</span>
<span class="trade">ELECTRIC</span>
<span class="trade" style="background:#ffd4a8">PANG FIX LAB</span>
</div>
<div id="controls" class="hud">
DRAG · ORBIT<br>
WHEEL · ZOOM<br>
SHIFT-DRAG · PAN
<br><button id="reset">RESET VIEW</button>
</div>
<div id="loading">BUILDING THE FIVE-FOOT WAY…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.getElementById("scene");
const loading = document.getElementById("loading");
const COLORS = {
ink: 0x173f3b,
cream: 0xfff2ce,
road: 0x455b5a,
roadDark: 0x344846,
sidewalk: 0xd7c8a8,
brass: 0xe9b84b,
red: 0xd85c3f,
teal: 0x337d76,
blue: 0x5d91ad,
pink: 0xe7a391,
green: 0x5b9365
};
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WEBGL COULD NOT START";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel scene of George Town shophouses and a repair stall"
);
sceneRoot.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xacd9d1);
scene.fog = new THREE.Fog(0xacd9d1, 25, 48);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const hemi = new THREE.HemisphereLight(0xe8fff4, 0x6b6255, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.4);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const materialCache = new Map();
function getMaterial(color, options = {}) {
if (color && color.isMaterial) return color;
const key = [
color,
options.opacity ?? 1,
options.roughness ?? 0.86,
options.metalness ?? 0,
options.emissive ?? 0,
options.emissiveIntensity ?? 1
].join("|");
if (!materialCache.has(key)) {
const settings = {
color,
roughness: options.roughness ?? 0.86,
metalness: options.metalness ?? 0
};
if (options.opacity !== undefined) {
settings.transparent = true;
settings.opacity = options.opacity;
}
if (options.emissive !== undefined) {
settings.emissive = options.emissive;
settings.emissiveIntensity = options.emissiveIntensity ?? 1;
}
materialCache.set(key, new THREE.MeshStandardMaterial(settings));
}
return materialCache.get(key);
}
function box(parent, w, h, d, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
getMaterial(color, options)
);
mesh.position.set(x, y, z);
if (options.rot) {
mesh.rotation.set(
options.rot[0] || 0,
options.rot[1] || 0,
options.rot[2] || 0
);
}
mesh.castShadow = !options.noShadow;
mesh.receiveShadow = options.noShadow !== true;
parent.add(mesh);
return mesh;
}
function beam(parent, a, b, thickness, color) {
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 = box(
parent,
thickness,
thickness,
direction.length(),
midpoint.x,
midpoint.y,
midpoint.z,
color
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
return mesh;
}
function createSign(
parent,
title,
subtitle,
w,
h,
x,
y,
z,
bg = "#173f3b",
fg = "#fff2ce"
) {
box(parent, w + 0.05, h + 0.05, 0.075, x, y, z - 0.018, bg);
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 200;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = fg;
ctx.lineWidth = 7;
ctx.strokeRect(9, 9, canvas.width - 18, canvas.height - 18);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = fg;
let fontSize = title.length > 15 ? 48 : 62;
ctx.font = `900 ${fontSize}px ui-monospace, Menlo, Consolas, monospace`;
while (ctx.measureText(title).width > 590 && fontSize > 24) {
fontSize -= 2;
ctx.font = `900 ${fontSize}px ui-monospace, Menlo, Consolas, monospace`;
}
ctx.fillText(title, 320, 74);
ctx.font = `800 ${subtitle.length > 18 ? 27 : 31}px ui-monospace, Menlo, Consolas, monospace`;
ctx.fillText(subtitle, 320, 139);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({ map: texture })
);
sign.position.set(x, y, z + 0.022);
parent.add(sign);
return sign;
}
function createFan(parent, x, y, z, scale = 1) {
const fan = new THREE.Group();
fan.position.set(x, y, z);
fan.scale.setScalar(scale);
parent.add(fan);
box(fan, 0.62, 0.62, 0.12, 0, 0, 0, 0x365e61);
box(fan, 0.50, 0.50, 0.08, 0, 0, 0.07, 0xb7d4cb);
const blades = new THREE.Group();
blades.position.z = 0.13;
fan.add(blades);
box(blades, 0.08, 0.44, 0.035, 0, 0, 0, COLORS.ink);
box(blades, 0.44, 0.08, 0.035, 0, 0, 0, COLORS.ink);
box(blades, 0.32, 0.07, 0.035, 0, 0, 0, COLORS.ink, {
rot: [0, 0, Math.PI / 4]
});
box(blades, 0.32, 0.07, 0.035, 0, 0, 0, COLORS.ink, {
rot: [0, 0, -Math.PI / 4]
});
box(fan, 0.12, 0.12, 0.04, 0, 0, 0.17, COLORS.red);
box(fan, 0.15, 0.24, 0.15, 0, -0.42, -0.04, COLORS.ink);
box(fan, 0.46, 0.08, 0.28, 0, -0.56, -0.04, COLORS.ink);
return { fan, blades };
}
// ------------------------------------------------------------
// Ground, road, covered walkway and drainage
// ------------------------------------------------------------
const ground = new THREE.Group();
scene.add(ground);
box(ground, 14.8, 0.68, 9.7, 0, -0.43, 0.15, 0x55756d);
box(ground, 14.65, 0.12, 4.95, 0, -0.02, 2.42, COLORS.road);
box(ground, 14.62, 0.15, 1.65, 0, 0.055, -0.91, COLORS.sidewalk);
// Individual walkway tiles
for (let x = -6.4; x <= 6.4; x += 0.4) {
for (let z = -1.58; z <= -0.22; z += 0.31) {
const shade = (Math.round(x * 10 + z * 10) % 3 === 0)
? 0xd0bf9e
: 0xdfd0af;
box(ground, 0.375, 0.025, 0.285, x, 0.142, z, shade, {
noShadow: true
});
}
}
// Curbs and storm drain
box(ground, 14.55, 0.18, 0.16, 0, 0.05, -0.05, 0xb5a889);
box(ground, 14.55, 0.16, 0.14, 0, 0.025, 4.83, 0x9f947c);
for (let x = -3.0; x <= 3.0; x += 0.23) {
box(ground, 0.055, 0.025, 0.60, x, 0.145, -0.16, 0x2b3938);
}
// Road markings and utility covers
for (let x = -6.2; x < 6.4; x += 1.65) {
box(ground, 0.86, 0.012, 0.075, x, 0.047, 4.18, 0xd9c77d, {
noShadow: true
});
}
box(ground, 0.72, 0.025, 0.72, 4.8, 0.047, 1.58, 0x354847);
for (let i = -2; i <= 2; i++) {
box(ground, 0.52, 0.03, 0.035, 4.8, 0.065, 1.58 + i * 0.11, 0x657270);
}
// Small puddle reflections
box(ground, 1.2, 0.012, 0.55, -4.8, 0.052, 1.38, 0x6f9894, {
opacity: 0.48,
noShadow: true
});
box(ground, 0.66, 0.012, 0.34, 5.8, 0.052, 3.14, 0x6f9894, {
opacity: 0.4,
noShadow: true
});
// ------------------------------------------------------------
// Shophouses
// ------------------------------------------------------------
const shops = [
{
x: -5.25,
wall: 0xe6a66f,
upper: 0xf2c991,
accent: 0x80533b,
title: "KAYA & KOFFEE",
subtitle: "咖啡室 · COFFEE",
type: "coffee"
},
{
x: -2.62,
wall: 0x78b5a8,
upper: 0xafd8c7,
accent: 0x255f5d,
title: "LIM TAILOR",
subtitle: "裁缝 · TAILOR",
type: "tailor"
},
{
x: 0,
wall: 0xd8836f,
upper: 0xefaa91,
accent: 0x743f37,
title: "DAWN TEH TARIK",
subtitle: "茶室 · TEA",
type: "tea"
},
{
x: 2.62,
wall: 0x8da6c4,
upper: 0xb8c9dd,
accent: 0x3b5875,
title: "PAPER & INK",
subtitle: "印坊 · PRINT",
type: "print"
},
{
x: 5.25,
wall: 0xd2b66b,
upper: 0xe7d194,
accent: 0x6c5730,
title: "CHAN ELECTRIC",
subtitle: "电器 · ELECTRIC",
type: "electric"
}
];
const shopFans = [];
function addCoffeeDetails(g) {
box(g, 1.24, 0.78, 0.52, -0.48, 0.51, -1.02, 0x82583d);
box(g, 1.34, 0.10, 0.60, -0.48, 0.94, -1.02, 0xd6b477);
for (let i = 0; i < 4; i++) {
const x = -0.92 + i * 0.29;
box(g, 0.16, 0.18, 0.16, x, 1.08, -1.00, 0xf7ead0);
box(g, 0.13, 0.035, 0.13, x, 1.185, -1.00, 0x63483a);
}
box(g, 0.31, 0.33, 0.31, 0.47, 1.10, -1.02, 0xc9c1ad);
box(g, 0.12, 0.08, 0.08, 0.68, 1.10, -1.02, COLORS.brass);
// Hanging cup-shaped sign
box(g, 0.48, 0.48, 0.11, 0.91, 1.58, -0.05, 0xf2e4c4);
box(g, 0.12, 0.28, 0.11, 1.21, 1.58, -0.05, 0xf2e4c4);
box(g, 0.20, 0.16, 0.12, 0.91, 1.87, -0.05, 0xf2e4c4);
box(g, 0.12, 0.38, 0.09, 0.91, 1.58, -0.10, COLORS.red);
}
function addTailorDetails(g) {
// Voxel mannequin
box(g, 0.38, 0.08, 0.38, -0.57, 0.25, -1.05, COLORS.ink);
box(g, 0.09, 0.76, 0.09, -0.57, 0.65, -1.05, 0xb9aa8e);
box(g, 0.48, 0.64, 0.26, -0.57, 1.28, -1.05, 0x385f78);
box(g, 0.16, 0.14, 0.16, -0.57, 1.69, -1.05, 0xd5a079);
box(g, 0.16, 0.09, 0.17, -0.57, 1.78, -1.05, 0x3e342e);
box(g, 0.18, 0.42, 0.18, -0.87, 1.29, -1.05, 0x385f78, {
rot: [0, 0, -0.10]
});
box(g, 0.18, 0.42, 0.18, -0.27, 1.29, -1.05, 0x385f78, {
rot: [0, 0, 0.10]
});
// Fabric bolts
const fabrics = [0xc45d50, 0xe3b956, 0x4e777b, 0x77516e];
fabrics.forEach((color, i) => {
box(g, 0.18, 0.72, 0.18, 0.20 + i * 0.19, 0.50, -1.08, color);
box(g, 0.20, 0.08, 0.20, 0.20 + i * 0.19, 0.88, -1.08, 0xefe0bd);
});
box(g, 0.50, 0.32, 0.28, 0.67, 0.31, -0.42, 0x704b35);
box(g, 0.18, 0.35, 0.025, 0.67, 0.48, -0.26, 0xc9c4ad);
}
function addTeaDetails(g) {
box(g, 1.22, 0.72, 0.50, 0.42, 0.50, -1.02, 0x89543b);
box(g, 1.30, 0.10, 0.58, 0.42, 0.91, -1.02, 0xe5c78e);
box(g, 0.38, 0.31, 0.31, 0.36, 1.10, -1.02, 0xb8b4a3);
box(g, 0.24, 0.09, 0.24, 0.36, 1.30, -1.02, 0x4e514d);
box(g, 0.09, 0.22, 0.09, 0.64, 1.11, -1.02, 0x4e514d);
box(g, 0.14, 0.07, 0.14, 0.09, 1.10, -1.02, 0x4e514d);
for (let i = 0; i < 3; i++) {
box(g, 0.13, 0.15, 0.13, 0.00 + i * 0.37, 1.06, -0.73, 0xe9dcc0);
}
// Two low stools
box(g, 0.48, 0.10, 0.42, -0.73, 0.57, -0.43, 0x80553b);
box(g, 0.12, 0.48, 0.12, -0.73, 0.30, -0.43, 0x80553b);
box(g, 0.48, 0.10, 0.42, 0.69, 0.57, -0.43, 0x80553b);
box(g, 0.12, 0.48, 0.12, 0.69, 0.30, -0.43, 0x80553b);
}
function addPrintDetails(g) {
box(g, 1.26, 0.18, 0.48, 0.25, 0.68, -1.00, 0x4a433b);
box(g, 1.26, 0.75, 0.12, 0.25, 1.10, -1.18, 0x52606a);
const paperColors = [0xe96852, 0x3c7d87, 0xe7bd4f, 0xf1e7ca];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 4; col++) {
box(
g,
0.19,
0.24,
0.025,
-0.15 + col * 0.27,
0.93 + row * 0.31,
-1.105,
paperColors[(row + col) % paperColors.length]
);
}
}
box(g, 0.55, 0.25, 0.38, 0.23, 0.88, -0.78, 0x304e5d);
box(g, 0.34, 0.025, 0.24, 0.23, 1.02, -0.77, 0xe7dfc7);
box(g, 0.34, 0.025, 0.16, 0.23, 0.98, -0.76, 0xd9a553);
}
function addElectricDetails(g) {
box(g, 0.85, 1.14, 0.50, 0.53, 0.70, -1.04, 0x3c6676);
box(g, 0.76, 0.78, 0.035, 0.53, 0.72, -0.775, 0x8da6a7);
box(g, 0.24, 0.07, 0.07, 0.53, 0.93, -0.73, 0x273f45);
const fan = createFan(g, 0.30, 1.70, -1.02, 0.70);
shopFans.push(fan.blades);
box(g, 0.20, 0.45, 0.20, -0.50, 0.37, -1.05, 0xc68d3e);
box(g, 0.20, 0.08, 0.20, -0.50, 0.63, -1.05, 0xb6a789);
box(g, 0.22, 0.24, 0.22, -0.50, 0.24, -0.78, 0x475657);
}
function buildShophouse(config, index) {
const g = new THREE.Group();
g.position.x = config.x;
scene.add(g);
const w = 2.53;
const d = 2.55;
const front = -1.70;
// Lower and upper storeys
box(g, w, 2.52, d, 0, 1.38, -3.00, config.wall);
box(g, w + 0.06, 2.38, d - 0.03, 0, 3.82, -3.015, config.upper);
// Plinth and cornices
box(g, w + 0.10, 0.22, d + 0.08, 0, 0.25, -3.00, config.accent);
box(g, w + 0.14, 0.16, d + 0.10, 0, 2.59, -3.00, config.accent);
box(g, w + 0.18, 0.19, d + 0.14, 0, 5.03, -3.00, config.accent);
box(g, w + 0.08, 0.16, d + 0.06, 0, 5.19, -3.00, 0x786951);
// Recessed-looking shop opening
box(g, 2.05, 1.88, 0.07, 0, 1.28, front + 0.015, 0x294846);
box(g, 0.08, 2.00, 0.11, -1.05, 1.30, front + 0.07, config.accent);
box(g, 0.08, 2.00, 0.11, 1.05, 1.30, front + 0.07, config.accent);
box(g, 2.13, 0.09, 0.11, 0, 2.26, front + 0.07, config.accent);
// Door and louvered shutter panels
box(g, 0.66, 1.62, 0.09, -0.68, 1.10, front + 0.09, 0x37615c);
box(g, 0.50, 0.52, 0.025, -0.68, 1.42, front + 0.15, 0x8db6a8);
box(g, 0.07, 0.09, 0.07, -0.40, 0.86, front + 0.16, COLORS.brass);
for (let y = 0.52; y < 1.94; y += 0.17) {
box(g, 0.83, 0.055, 0.055, 0.53, y, front + 0.095, 0x4b7770);
}
// Upper windows
for (const wx of [-0.61, 0.61]) {
box(g, 0.90, 1.13, 0.08, wx, 3.77, front + 0.055, 0x416a68);
box(g, 0.74, 0.95, 0.03, wx, 3.77, front + 0.105, 0x9dc5b7);
box(g, 0.055, 1.03, 0.07, wx, 3.77, front + 0.14, 0xe8d8b1);
box(g, 0.85, 0.07, 0.07, wx, 3.77, front + 0.14, 0xe8d8b1);
// Shutters
box(g, 0.29, 1.06, 0.09, wx - 0.60, 3.77, front + 0.08, config.accent);
box(g, 0.29, 1.06, 0.09, wx + 0.60, 3.77, front + 0.08, config.accent);
for (let y = 3.30; y < 4.30; y += 0.14) {
box(g, 0.25, 0.045, 0.035, wx - 0.60, y, front + 0.14, 0xeee0bb);
box(g, 0.25, 0.045, 0.035, wx + 0.60, y, front + 0.14, 0xeee0bb);
}
}
// Small balcony on alternating shophouses
if (index % 2 === 0) {
box(g, 1.28, 0.09, 0.46, 0, 3.06, front + 0.25, 0xdfd1ae);
for (let x = -0.56; x <= 0.57; x += 0.19) {
box(g, 0.045, 0.42, 0.045, x, 3.27, front + 0.45, COLORS.ink);
}
box(g, 1.25, 0.06, 0.06, 0, 3.48, front + 0.45, COLORS.ink);
}
// Air-conditioning box and drain pipe
box(g, 0.66, 0.39, 0.40, 0.80, 4.76, front + 0.15, 0xd2d2bd);
box(g, 0.51, 0.25, 0.025, 0.80, 4.76, front + 0.37, 0x74817d);
box(g, 0.07, 2.22, 0.08, -1.20, 3.76, front + 0.09, 0x4f665d);
// Striped five-foot-way awning
const awningColors = [config.accent, 0xf0dfb6];
const stripeWidth = 0.31;
for (let i = 0; i < 8; i++) {
const x = -1.085 + i * 0.31;
box(
g,
0.30,
0.10,
1.60,
x,
2.35,
-0.90,
awningColors[i % 2]
);
box(
g,
0.30,
0.29,
0.10,
x,
2.15,
-0.10,
awningColors[i % 2]
);
}
// Arcade post
box(g, 0.13, 2.22, 0.13, -1.17, 1.22, -0.13, config.accent);
box(g, 0.23, 0.13, 0.23, -1.17, 0.22, -0.13, 0x756a52);
createSign(
g,
config.title,
config.subtitle,
2.10,
0.58,
0,
2.78,
front + 0.12,
"#173f3b",
"#fff0c8"
);
// Projecting hanging sign
const signX = index % 2 === 0 ? 1.02 : -1.02;
box(g, 0.035, 0.76, 0.035, signX, 1.92, -0.45, COLORS.ink);
createSign(
g,
config.type === "electric" ? "ELECTRIC" : config.type.toUpperCase(),
"OPEN",
0.66,
0.46,
signX,
1.48,
-0.37,
"#f6e7bd",
"#173f3b"
);
// Warm voxel lantern under each awning
box(g, 0.18, 0.26, 0.18, 0.93, 1.98, -0.50, 0xffd478, {
emissive: 0xffa93d,
emissiveIntensity: 1.25
});
if (config.type === "coffee") addCoffeeDetails(g);
if (config.type === "tailor") addTailorDetails(g);
if (config.type === "tea") addTeaDetails(g);
if (config.type === "print") addPrintDetails(g);
if (config.type === "electric") addElectricDetails(g);
}
shops.forEach(buildShophouse);
// ------------------------------------------------------------
// Original repair stall: PANG FIX LAB
// ------------------------------------------------------------
const stall = new THREE.Group();
stall.position.set(-1.56, 0, 0);
scene.add(stall);
// Four canopy posts
for (const x of [-1.56, 1.56]) {
for (const z of [0.25, 1.74]) {
box(stall, 0.12, 2.45, 0.12, x, 1.34, z, 0x3d5b51);
}
}
// Patchwork tarpaulin
const canopyColors = [
0xe5b95f, 0xe9dcc0, 0x5b8d83, 0xe59a6d,
0xe5b95f, 0xe9dcc0, 0x5b8d83, 0xe59a6d,
0xe5b95f, 0xe9dcc0
];
for (let i = 0; i < 10; i++) {
const x = -1.55 + i * 0.345;
box(
stall,
0.34,
0.10,
1.72,
x,
2.58,
0.99,
canopyColors[i]
);
box(
stall,
0.34,
0.31,
0.10,
x,
2.37,
1.84,
canopyColors[i]
);
}
createSign(
stall,
"PANG FIX LAB",
"KEYS · LOCKS · FANS",
2.68,
0.65,
0,
2.28,
1.91,
"#d85c3f",
"#fff4d2"
);
// Tool board
box(stall, 3.05, 1.13, 0.12, 0, 1.49, 0.24, 0x345b58);
box(stall, 3.15, 0.10, 0.17, 0, 2.08, 0.24, 0x273f3e);
// Peg holes
for (let x = -1.32; x <= 1.32; x += 0.22) {
for (let y = 1.08; y <= 1.91; y += 0.21) {
box(stall, 0.035, 0.035, 0.025, x, y, 0.307, 0x183d3b, {
noShadow: true
});
}
}
// Hanging key blanks
for (let i = 0; i < 7; i++) {
const x = -1.24 + i * 0.18;
box(stall, 0.035, 0.28, 0.035, x, 1.75, 0.35, COLORS.brass);
box(stall, 0.12, 0.035, 0.035, x + 0.03, 1.88, 0.35, COLORS.brass);
box(stall, 0.035, 0.09, 0.035, x + 0.055, 1.63, 0.35, COLORS.brass);
}
// Wrenches and pliers
box(stall, 0.09, 0.48, 0.06, -0.72, 1.45, 0.37, 0xb9c4bf);
box(stall, 0.22, 0.08, 0.06, -0.72, 1.68, 0.37, 0xb9c4bf);
box(stall, 0.08, 0.43, 0.06, -0.33, 1.43, 0.37, 0xc4ccc7);
box(stall, 0.17, 0.08, 0.06, -0.33, 1.64, 0.37, 0xc4ccc7);
box(stall, 0.06, 0.28, 0.06, 0.34, 1.43, 0.37, COLORS.red, {
rot: [0, 0, -0.18]
});
box(stall, 0.06, 0.28, 0.06, 0.49, 1.43, 0.37, COLORS.red, {
rot: [0, 0, 0.18]
});
// Workbench
box(stall, 3.03, 0.16, 0.83, 0, 0.98, 1.05, 0x9a6c43);
box(stall, 3.13, 0.08, 0.91, 0, 0.88, 1.05, 0x634a35);
for (const x of [-1.34, 1.34]) {
box(stall, 0.14, 0.79, 0.14, x, 0.49, 1.04, 0x5a4636);
}
// Drawer cabinet
box(stall, 0.88, 0.74, 0.68, -0.99, 0.52, 1.02, 0x7b563d);
for (let i = 0; i < 3; i++) {
box(stall, 0.73, 0.16, 0.035, -0.99, 0.30 + i * 0.21, 1.38, 0x9c7050);
box(stall, 0.18, 0.035, 0.045, -0.99, 0.30 + i * 0.21, 1.42, COLORS.brass);
}
// Key-cutting machine
box(stall, 0.68, 0.29, 0.42, -0.37, 1.20, 1.02, 0xd56c42);
box(stall, 0.36, 0.20, 0.28, -0.29, 1.43, 1.00, 0x456c6b);
box(stall, 0.09, 0.18, 0.09, -0.62, 1.42, 0.94, 0x2d4646);
box(stall, 0.27, 0.04, 0.04, -0.52, 1.43, 0.86, COLORS.brass);
box(stall, 0.20, 0.04, 0.12, -0.13, 1.25, 0.88, 0x3f5252);
// Bench vise, lock, papers and mug
box(stall, 0.27, 0.19, 0.25, 0.28, 1.15, 1.13, 0x466969);
box(stall, 0.12, 0.28, 0.10, 0.40, 1.18, 1.13, 0x557a78);
box(stall, 0.05, 0.22, 0.05, 0.45, 1.35, 1.13, COLORS.brass);
box(stall, 0.17, 0.20, 0.12, 0.75, 1.16, 0.91, COLORS.brass);
box(stall, 0.12, 0.16, 0.13, 0.75, 1.31, 0.91, 0x9a7741);
box(stall, 0.035, 0.17, 0.025, 0.75, 1.22, 1.00, 0x3b4140);
box(stall, 0.47, 0.018, 0.32, 0.94, 1.075, 1.09, 0xf1e7ce, {
rot: [0, 0.12, 0]
});
box(stall, 0.47, 0.018, 0.32, 0.96, 1.095, 1.09, 0xf7efd7, {
rot: [0, -0.08, 0]
});
box(stall, 0.18, 0.21, 0.18, 1.21, 1.17, 1.29, 0x4d8982);
box(stall, 0.22, 0.05, 0.22, 1.21, 1.30, 1.29, 0xefe4ca);
// Repair fan on the stall's right
const repairFan = createFan(stall, 1.22, 1.67, 0.30, 0.62);
shopFans.push(repairFan.blades);
// Under-stall crate and toolbox
box(stall, 0.69, 0.42, 0.53, 1.10, 0.34, 0.50, 0x846444);
box(stall, 0.76, 0.08, 0.58, 1.10, 0.58, 0.50, 0x4f3b30);
box(stall, 0.42, 0.22, 0.27, -0.93, 1.19, 1.17, 0x436f6d);
// ------------------------------------------------------------
// Voxel people
// ------------------------------------------------------------
function createPerson(options = {}) {
const group = new THREE.Group();
const skin = options.skin ?? 0xd5a078;
const shirt = options.shirt ?? 0x4e7f79;
const pants = options.pants ?? 0x364b52;
const hair = options.hair ?? 0x302d2a;
// Torso
box(group, 0.48, 0.58, 0.31, 0, 1.07, 0, shirt);
box(group, 0.19, 0.14, 0.19, 0, 1.43, 0, skin);
// Head and face
box(group, 0.38, 0.38, 0.37, 0, 1.64, 0, skin);
box(group, 0.40, 0.12, 0.39, 0, 1.82, -0.01, hair);
box(group, 0.07, 0.08, 0.025, -0.09, 1.67, 0.195, COLORS.ink);
box(group, 0.07, 0.08, 0.025, 0.09, 1.67, 0.195, COLORS.ink);
box(group, 0.10, 0.025, 0.025, 0, 1.56, 0.198, 0x9b5c4b);
// Arms as pivoting voxel limbs
function makeArm(x) {
const pivot = new THREE.Group();
pivot.position.set(x, 1.29, 0);
group.add(pivot);
box(pivot, 0.16, 0.35, 0.18, 0, -0.16, 0, shirt);
const forearm = new THREE.Group();
forearm.position.set(0, -0.34, 0);
pivot.add(forearm);
box(forearm, 0.15, 0.30, 0.16, 0, -0.14, 0, shirt);
box(forearm, 0.16, 0.15, 0.16, 0, -0.35, 0, skin);
return { pivot, forearm };
}
const leftArm = makeArm(-0.32);
const rightArm = makeArm(0.32);
// Legs as pivoting voxel limbs
function makeLeg(x) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.79, 0);
group.add(pivot);
box(pivot, 0.19, 0.64, 0.21, 0, -0.30, 0, pants);
box(pivot, 0.23, 0.14, 0.34, 0, -0.67, 0.07, 0x2d3433);
return pivot;
}
const leftLeg = makeLeg(-0.13);
const rightLeg = makeLeg(0.13);
// Apron, cap or other role-specific clothing
if (options.apron) {
box(group, 0.40, 0.54, 0.045, 0, 0.98, 0.178, options.apron);
box(group, 0.08, 0.33, 0.04, -0.15, 1.35, 0.177, options.apron);
box(group, 0.08, 0.33, 0.04, 0.15, 1.35, 0.177, options.apron);
}
if (options.hat) {
box(group, 0.45, 0.12, 0.43, 0, 1.91, 0, options.hat);
box(group, 0.51, 0.05, 0.27, 0, 1.85, 0.20, options.hat);
}
if (options.bag) {
box(group, 0.30, 0.36, 0.18, 0.33, 0.85, -0.05, options.bag);
box(group, 0.04, 0.66, 0.04, 0.31, 1.25, -0.04, 0x4a4037);
}
return {
group,
leftArm,
rightArm,
leftLeg,
rightLeg
};
}
// Repair artisan
const artisan = createPerson({
skin: 0xc98f68,
shirt: 0x3e7771,
pants: 0x394c4b,
hair: 0x282b29,
apron: 0xc77a43,
hat: 0x345f5b
});
stall.add(artisan.group);
artisan.group.position.set(-0.67, 0.05, 0.54);
artisan.group.rotation.y = 0.03;
artisan.rightArm.pivot.rotation.x = -0.57;
artisan.leftArm.pivot.rotation.x = -0.68;
artisan.leftArm.pivot.rotation.z = -0.15;
// Hammer in the artisan's hand
box(
artisan.rightArm.forearm,
0.055,
0.32,
0.055,
0,
-0.42,
0.03,
0x795a3f
);
box(
artisan.rightArm.forearm,
0.25,
0.10,
0.11,
0,
-0.57,
0.03,
0x758687
);
// Waiting customer
const customer = createPerson({
skin: 0xe0b088,
shirt: 0xe4b850,
pants: 0x4d5b70,
hair: 0x3a2c27,
bag: 0x7c4d48
});
stall.add(customer.group);
customer.group.position.set(0.72, 0.04, 2.09);
customer.group.rotation.y = Math.PI + 0.10;
// Broken brass padlock offered on the counter
box(customer.group, 0.20, 0.20, 0.13, 0.02, 1.03, 0.42, COLORS.brass);
box(customer.group, 0.16, 0.15, 0.14, 0.02, 1.18, 0.42, 0x9a7741);
box(customer.group, 0.035, 0.11, 0.035, 0.02, 1.10, 0.51, 0x3d4342);
customer.leftArm.pivot.rotation.x = -1.00;
customer.rightArm.pivot.rotation.x = -0.90;
// Passing pedestrian
const pedestrian = createPerson({
skin: 0xa76f50,
shirt: 0x5d83b4,
pants: 0x465764,
hair: 0x252728,
bag: 0xc87b50
});
scene.add(pedestrian.group);
pedestrian.group.position.set(-7, 0.03, 3.72);
pedestrian.group.rotation.y = Math.PI / 2;
// ------------------------------------------------------------
// Street details, plants, wires, lanterns and clouds
// ------------------------------------------------------------
function createPlant(x, z, scale = 1) {
const plant = new THREE.Group();
plant.position.set(x, 0.12, z);
plant.scale.setScalar(scale);
scene.add(plant);
box(plant, 0.62, 0.57, 0.62, 0, 0.28, 0, 0xb86e4d);
box(plant, 0.72, 0.12, 0.72, 0, 0.59, 0, 0xd58c62);
box(plant, 0.48, 0.08, 0.48, 0, 0.67, 0, 0x514c35);
box(plant, 0.08, 0.75, 0.08, 0, 1.02, 0, 0x4d7448);
const leafColors = [0x4f8859, 0x6e9b5c, 0x3f7650];
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2;
const radius = 0.38;
const leaf = box(
plant,
0.58,
0.13,
0.28,
Math.cos(angle) * radius,
1.10 + (i % 3) * 0.17,
Math.sin(angle) * radius,
leafColors[i % leafColors.length],
{ rot: [0, angle, 0.48 * (i % 2 ? 1 : -1)] }
);
leaf.castShadow = true;
}
}
createPlant(-6.87, -0.72, 0.86);
createPlant(6.88, -0.70, 0.92);
createPlant(6.86, 4.18, 0.70);
// Small planter under an upper window
box(ground, 0.65, 0.24, 0.25, -3.23, 3.24, -1.35, 0xa75e44);
for (let i = 0; i < 4; i++) {
box(
ground,
0.23,
0.37,
0.18,
-3.46 + i * 0.15,
3.52,
-1.35,
i % 2 ? 0x5c8b5f : 0x3f7753,
{ rot: [0, 0, (i - 1.5) * 0.12] }
);
}
// Utility poles and sagging overhead wires
for (const x of [-7.18, 7.18]) {
box(ground, 0.16, 6.65, 0.16, x, 3.30, -1.16, 0x776c57);
box(ground, 1.20, 0.12, 0.13, x, 5.95, -1.16, 0x5e5c50);
box(ground, 0.18, 0.27, 0.18, x, 6.10, -1.16, 0x3b4d48);
}
for (let wire = 0; wire < 3; wire++) {
const z = -1.16 + wire * 0.16;
for (let i = 0; i < 14; i++) {
const t0 = i / 14;
const t1 = (i + 1) / 14;
const y0 = 5.96 - Math.sin(t0 * Math.PI) * (0.55 + wire * 0.10);
const y1 = 5.96 - Math.sin(t1 * Math.PI) * (0.55 + wire * 0.10);
beam(
ground,
[-7.18 + t0 * 14.36, y0, z],
[-7.18 + t1 * 14.36, y1, z],
0.035,
0x344642
);
}
}
// Block clouds
const clouds = [];
function createCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
box(cloud, 1.45, 0.52, 0.58, 0, 0, 0, 0xf4f3df, { noShadow: true });
box(cloud, 0.82, 0.78, 0.62, -0.30, 0.22, 0, 0xf4f3df, { noShadow: true });
box(cloud, 0.95, 0.72, 0.60, 0.36, 0.16, 0, 0xf4f3df, { noShadow: true });
clouds.push(cloud);
}
createCloud(-4.4, 7.8, -6.0, 1.0);
createCloud(3.8, 8.4, -7.2, 0.78);
// Market-style hanging lanterns
for (const x of [-4.0, 1.8]) {
box(ground, 0.035, 0.52, 0.035, x, 2.06, 0.04, COLORS.ink);
box(ground, 0.31, 0.40, 0.31, x, 1.65, 0.04, 0xe8784d, {
emissive: 0xd34725,
emissiveIntensity: 0.65
});
box(ground, 0.34, 0.08, 0.34, x, 1.87, 0.04, 0x754533);
box(ground, 0.34, 0.08, 0.34, x, 1.43, 0.04, 0x754533);
}
// Warm practical lights
const stallLight = new THREE.PointLight(0xffb55f, 8, 5.5, 2);
stallLight.position.set(-1.5, 2.15, 0.95);
scene.add(stallLight);
const arcadeLightA = new THREE.PointLight(0xffc77a, 6, 4.5, 2);
arcadeLightA.position.set(-4.4, 2.0, -0.65);
scene.add(arcadeLightA);
const arcadeLightB = new THREE.PointLight(0xffc77a, 6, 4.5, 2);
arcadeLightB.position.set(4.4, 2.0, -0.65);
scene.add(arcadeLightB);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom and pan
// ------------------------------------------------------------
const controls = {
theta: 0.43,
phi: 0.58,
zoom: 1,
target: new THREE.Vector3(0, 1.80, 0),
dragging: false,
mode: "orbit",
lastX: 0,
lastY: 0
};
function updateCamera() {
const distance = 22;
const horizontal = Math.cos(controls.phi) * distance;
camera.position.set(
controls.target.x + Math.sin(controls.theta) * horizontal,
controls.target.y + Math.sin(controls.phi) * distance,
controls.target.z + Math.cos(controls.theta) * horizontal
);
camera.lookAt(controls.target);
camera.updateProjectionMatrix();
}
function updateProjection() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
let viewHeight = Math.max(10.7, 16.2 / aspect);
viewHeight /= controls.zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
function resetView() {
controls.theta = 0.43;
controls.phi = 0.58;
controls.zoom = 1;
controls.target.set(0, 1.80, 0);
updateCamera();
updateProjection();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.mode = event.shiftKey || event.button === 2 ? "pan" : "orbit";
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (controls.mode === "orbit") {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.004,
0.24,
1.25
);
} else {
controls.target.x -= dx * 0.012;
controls.target.z += dy * 0.012;
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -4, 4);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -2, 3);
}
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * (event.deltaY > 0 ? 0.90 : 1.10),
0.65,
1.85
);
updateProjection();
}, { passive: false });
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
updateProjection();
updateCamera();
});
resetView();
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const t = clock.getElapsedTime();
// The pedestrian crosses the street and wraps around.
pedestrian.group.position.x = ((t * 0.88 + 9.5) % 16) - 8;
const walk = Math.sin(t * 7.5);
pedestrian.leftLeg.rotation.x = walk * 0.52;
pedestrian.rightLeg.rotation.x = -walk * 0.52;
pedestrian.leftArm.pivot.rotation.x = -walk * 0.38;
pedestrian.rightArm.pivot.rotation.x = walk * 0.38;
// The repairman works the lock with a small, repeated motion.
artisan.rightArm.pivot.rotation.x = -0.58 + Math.sin(t * 5.4) * 0.16;
artisan.rightArm.forearm.rotation.x = -0.22 + Math.sin(t * 5.4 + 0.8) * 0.12;
artisan.leftArm.pivot.rotation.x = -0.66 + Math.sin(t * 2.2) * 0.05;
// A subtle customer shift.
customer.group.position.y = 0.04 + Math.sin(t * 1.8) * 0.008;
customer.leftArm.pivot.rotation.z = Math.sin(t * 1.4) * 0.035;
// Fans turn at different speeds.
shopFans.forEach((blades, index) => {
blades.rotation.z += 0.025 * (index % 2 ? -1 : 1);
});
// Clouds drift slowly.
clouds[0].position.x = -4.4 + ((t * 0.12 + 10) % 15) - 7.5;
clouds[1].position.x = 3.8 + ((t * 0.08 + 7) % 15) - 7.5;
renderer.render(scene, camera);
}
loading.remove();
animate();
</script>
</body>
</html>
```