Prompt specification
Build or customize the Three.js 3D scene "George Town shophouse shutter and covered walkway" 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: George Town shophouse shutter and covered walkway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/george-town-shophouse-shutter-and-covered-walkway-x3013
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing George Town's shophouses in Penang. Build a referenced Penang shophouse fragment with timber shutter, tiled threshold, and covered walkway. Use original decorative patterns and keep the sheltered public route continuous. Voxel style.
Working Three.js Starter (george-town-shophouse-shutter-and-covered-walkway-x3013):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#244e4c">
<title>George Town — Covered Shophouse Walk</title>
<style>
:root {
--ink: #173a38;
--paper: #f5ead6;
--accent: #d79a59;
--glass: rgba(20, 55, 52, 0.82);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e4df;
font-family: Georgia, "Times New Roman", serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 10;
max-width: min(420px, calc(100vw - 48px));
padding: 18px 20px 16px;
color: var(--paper);
background: var(--glass);
border: 1px solid rgba(255, 255, 255, 0.22);
border-left: 5px solid var(--accent);
box-shadow: 0 12px 36px rgba(22, 43, 40, 0.18);
backdrop-filter: blur(8px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: #efc58f;
font: 700 11px/1.2 Arial, sans-serif;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 37px);
font-weight: 500;
line-height: 1;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 0;
color: rgba(245, 234, 214, 0.78);
font: 12px/1.5 Arial, sans-serif;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 10;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 2px;
padding: 11px 15px;
color: var(--paper);
background: var(--glass);
box-shadow: 0 7px 20px rgba(22, 43, 40, 0.14);
font: 700 11px/1 Arial, sans-serif;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(29, 77, 73, 0.96);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid #f0bd7c;
outline-offset: 3px;
}
.legend {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 10;
max-width: 300px;
padding: 10px 13px;
color: rgba(245, 234, 214, 0.84);
background: rgba(23, 58, 56, 0.74);
border-left: 3px solid #dfad69;
font: 11px/1.55 Arial, sans-serif;
backdrop-filter: blur(7px);
pointer-events: none;
}
.legend strong {
color: #fff2d9;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: #244e4c;
background: #d8e4df;
font: 700 12px/1 Arial, sans-serif;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
padding: 14px 15px 13px;
}
.subtitle {
display: none;
}
.legend {
left: 14px;
bottom: 68px;
max-width: 230px;
}
.controls {
right: 14px;
bottom: 14px;
width: calc(100% - 28px);
justify-content: stretch;
}
button {
flex: 1;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel-style George Town shophouses with a continuous covered walkway"></canvas>
<section class="title-card">
<p class="eyebrow">Penang heritage study · 05</p>
<h1>George Town Shophouses</h1>
<p class="subtitle">
A voxel interpretation of the sheltered five-foot way: timber shutters,
tiled thresholds, patterned vents and a continuous public route.
</p>
</section>
<aside class="legend">
<strong>Explore:</strong> drag to orbit · scroll to zoom · arrow keys to move<br>
<strong>Detail:</strong> original geometric plaster panels and louvered timber shutters
</aside>
<nav class="controls" aria-label="Camera controls">
<button id="walkButton" type="button">Walk the covered route</button>
<button id="resetButton" type="button">Overview</button>
</nav>
<div id="loading">Building George Town…</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 scene
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const resetButton = document.getElementById("resetButton");
const walkButton = document.getElementById("walkButton");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e4df);
scene.fog = new THREE.Fog(0xd8e4df, 38, 76);
const camera = new THREE.OrthographicCamera(-20, 20, 13, -13, 0.1, 120);
const cameraTarget = new THREE.Vector3(0, 4.8, -0.6);
const orbit = {
theta: 0.34,
phi: 1.31,
zoom: 1
};
const defaultOrbit = {
theta: 0.34,
phi: 1.31,
zoom: 1
};
let tour = null;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf5f1df, 0x506b68, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0ae, 3.25);
sun.position.set(-16, 26, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -26;
sun.shadow.camera.right = 26;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc9c4, 0.75);
fill.position.set(14, 10, -10);
scene.add(fill);
// -------------------------------------------------------------------------
// Procedural pixel textures. No external image assets are used.
// -------------------------------------------------------------------------
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(50205);
function colorTexture(base, seed = 1) {
const c = document.createElement("canvas");
c.width = c.height = 64;
const ctx = c.getContext("2d");
const rnd = seededRandom(seed);
ctx.fillStyle = base;
ctx.fillRect(0, 0, 64, 64);
for (let i = 0; i < 190; i++) {
const value = Math.floor(188 + rnd() * 67);
ctx.fillStyle = `rgba(${value},${value},${value},${0.035 + rnd() * 0.07})`;
const size = 1 + Math.floor(rnd() * 4);
ctx.fillRect(
Math.floor(rnd() * 64),
Math.floor(rnd() * 64),
size,
size
);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2, 2);
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestMipmapNearestFilter;
return texture;
}
function woodTexture() {
const c = document.createElement("canvas");
c.width = c.height = 64;
const ctx = c.getContext("2d");
ctx.fillStyle = "#6f412a";
ctx.fillRect(0, 0, 64, 64);
for (let y = 0; y < 64; y += 4) {
ctx.fillStyle = y % 8 === 0 ? "#825235" : "#5e3625";
ctx.fillRect(0, y, 64, 2);
}
for (let i = 0; i < 22; i++) {
ctx.fillStyle = "rgba(31,17,11,.22)";
ctx.fillRect(Math.floor(random() * 61), Math.floor(random() * 64), 2, 1);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.5, 1.5);
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestMipmapNearestFilter;
return texture;
}
function patternTexture(variant, background, foreground, accent) {
const c = document.createElement("canvas");
c.width = c.height = 64;
const ctx = c.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 64, 64);
ctx.fillStyle = accent;
ctx.fillRect(3, 3, 58, 3);
ctx.fillRect(3, 58, 58, 3);
ctx.fillRect(3, 3, 3, 58);
ctx.fillRect(58, 3, 3, 58);
ctx.fillStyle = foreground;
if (variant === 0) {
// Stepped diamond.
ctx.fillRect(28, 10, 8, 44);
ctx.fillRect(20, 18, 24, 28);
ctx.fillRect(12, 26, 40, 12);
ctx.fillRect(26, 26, 12, 12);
ctx.fillStyle = background;
ctx.fillRect(28, 28, 8, 8);
ctx.fillStyle = accent;
ctx.fillRect(29, 29, 6, 6);
} else if (variant === 1) {
// Interlocking block wave.
for (let row = 0; row < 3; row++) {
const y = 13 + row * 15;
ctx.fillRect(9, y, 10, 6);
ctx.fillRect(19, y + 3, 10, 6);
ctx.fillRect(29, y, 10, 6);
ctx.fillRect(39, y + 3, 10, 6);
ctx.fillRect(49, y, 6, 6);
}
ctx.fillStyle = accent;
ctx.fillRect(8, 47, 48, 4);
} else {
// Pixel flower / sun motif.
ctx.fillRect(28, 9, 8, 12);
ctx.fillRect(28, 43, 8, 12);
ctx.fillRect(9, 28, 12, 8);
ctx.fillRect(43, 28, 12, 8);
ctx.fillRect(17, 17, 10, 10);
ctx.fillRect(37, 17, 10, 10);
ctx.fillRect(17, 37, 10, 10);
ctx.fillRect(37, 37, 10, 10);
ctx.fillStyle = background;
ctx.fillRect(26, 26, 12, 12);
ctx.fillStyle = accent;
ctx.fillRect(29, 29, 6, 6);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestMipmapNearestFilter;
return texture;
}
function signTexture(title, subtitle, background, foreground) {
const c = document.createElement("canvas");
c.width = 256;
c.height = 96;
const ctx = c.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 256, 96);
ctx.strokeStyle = foreground;
ctx.lineWidth = 5;
ctx.strokeRect(6, 6, 244, 84);
ctx.fillStyle = foreground;
ctx.fillRect(15, 15, 7, 7);
ctx.fillRect(234, 15, 7, 7);
ctx.fillRect(15, 74, 7, 7);
ctx.fillRect(234, 74, 7, 7);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "bold 27px monospace";
ctx.fillText(title, 128, 39);
ctx.font = "bold 13px monospace";
ctx.fillText(subtitle, 128, 69);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestMipmapLinearFilter;
return texture;
}
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const plasterColors = ["#ca855f", "#72a18b", "#b96f68"];
const wallMaterials = plasterColors.map((color, i) =>
new THREE.MeshStandardMaterial({
map: colorTexture(color, 120 + i * 11),
roughness: 0.95,
metalness: 0
})
);
const trimMaterials = [
new THREE.MeshStandardMaterial({ color: 0xe3cbb0, roughness: 0.86 }),
new THREE.MeshStandardMaterial({ color: 0xe7d2b4, roughness: 0.86 }),
new THREE.MeshStandardMaterial({ color: 0xdfc7ae, roughness: 0.86 })
];
const woodMaterial = new THREE.MeshStandardMaterial({
map: woodTexture(),
roughness: 0.83,
metalness: 0
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x4e3024,
roughness: 0.92
});
const roofMaterials = [
new THREE.MeshStandardMaterial({ color: 0xa94f38, roughness: 0.92 }),
new THREE.MeshStandardMaterial({ color: 0xba6041, roughness: 0.92 }),
new THREE.MeshStandardMaterial({ color: 0x8f4535, roughness: 0.94 })
];
const pathMaterials = [
new THREE.MeshStandardMaterial({ color: 0xc8b69d, roughness: 0.98 }),
new THREE.MeshStandardMaterial({ color: 0xbcaa90, roughness: 0.98 }),
new THREE.MeshStandardMaterial({ color: 0xd3c0a6, roughness: 0.98 })
];
const thresholdMaterial = new THREE.MeshStandardMaterial({
color: 0xb76645,
roughness: 0.96
});
const plasterDarkMaterial = new THREE.MeshStandardMaterial({
color: 0xded0b8,
roughness: 0.92
});
const recessMaterial = new THREE.MeshStandardMaterial({
color: 0x263b38,
roughness: 1
});
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x355451,
roughness: 0.28,
metalness: 0.08,
emissive: 0x142927,
emissiveIntensity: 0.28
});
const warmGlassMaterial = new THREE.MeshStandardMaterial({
color: 0xc59256,
emissive: 0x8a4f1e,
emissiveIntensity: 0.42,
roughness: 0.42
});
const patternMaterials = [
new THREE.MeshStandardMaterial({
map: patternTexture(0, "#ead8b7", "#b55f43", "#547e70"),
roughness: 0.9
}),
new THREE.MeshStandardMaterial({
map: patternTexture(1, "#d8c7aa", "#315e59", "#bb7249"),
roughness: 0.9
}),
new THREE.MeshStandardMaterial({
map: patternTexture(2, "#ead7ba", "#526f69", "#b65d49"),
roughness: 0.9
})
];
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function box(w, h, d, material, x, y, z, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLouverShutter(parent, x, y, z, width, height, openAngle = 0) {
const pivot = new THREE.Group();
pivot.position.set(x, y, z);
pivot.rotation.y = openAngle;
parent.add(pivot);
const slatCount = Math.max(5, Math.floor(height / 0.22));
const gap = height / slatCount;
for (let i = 0; i < slatCount; i++) {
box(
width,
gap * 0.58,
0.10,
woodMaterial,
width / 2,
-height / 2 + gap * (i + 0.5),
0,
pivot,
false
);
}
box(0.12, height + 0.12, 0.15, darkWoodMaterial, 0, 0, 0, pivot, false);
box(0.12, height + 0.12, 0.15, darkWoodMaterial, width, 0, 0, pivot, false);
box(width + 0.12, 0.12, 0.15, darkWoodMaterial, width / 2, -height / 2, 0, pivot, false);
box(width + 0.12, 0.12, 0.15, darkWoodMaterial, width / 2, height / 2, 0, pivot, false);
return pivot;
}
function makeUpperWindow(parent, x, y, width, height, shutterAngle = 0) {
box(width, height, 0.14, recessMaterial, x, y, 0.14, parent, false);
box(width - 0.28, height - 0.28, 0.08, glassMaterial, x, y, 0.24, parent, false);
box(0.13, height + 0.24, 0.17, darkWoodMaterial, x - width / 2, y, 0.30, parent, false);
box(0.13, height + 0.24, 0.17, darkWoodMaterial, x + width / 2, y, 0.30, parent, false);
box(width + 0.25, 0.14, 0.17, darkWoodMaterial, x, y - height / 2, 0.30, parent, false);
box(width + 0.25, 0.14, 0.17, darkWoodMaterial, x, y + height / 2, 0.30, parent, false);
box(0.09, height - 0.18, 0.12, darkWoodMaterial, x, y, 0.32, parent, false);
box(width - 0.20, 0.09, 0.12, darkWoodMaterial, x, y, 0.32, parent, false);
makeLouverShutter(
parent,
x - width / 2 + 0.05,
y,
0.43,
width - 0.10,
height - 0.12,
shutterAngle
);
box(width + 0.40, 0.16, 0.36, plasterDarkMaterial, x, y + height / 2 + 0.22, 0.20, parent, false);
box(width + 0.14, 0.13, 0.32, plasterDarkMaterial, x, y + height / 2 + 0.36, 0.19, parent, false);
box(0.38, 0.28, 0.30, plasterDarkMaterial, x, y + height / 2 + 0.53, 0.18, parent, false);
}
function makeSign(parent, x, y, z, width, height, title, subtitle, palette) {
const back = new THREE.MeshStandardMaterial({
color: palette[0],
roughness: 0.82
});
box(width + 0.14, height + 0.14, 0.13, back, x, y, z - 0.03, parent, false);
const faceMaterial = new THREE.MeshStandardMaterial({
map: signTexture(title, subtitle, palette[0], palette[1]),
roughness: 0.85
});
const face = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
faceMaterial
);
face.position.set(x, y, z + 0.045);
parent.add(face);
}
// -------------------------------------------------------------------------
// Ground, street and the continuous tiled public route
// -------------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x73827d,
roughness: 1
});
const streetMaterial = new THREE.MeshStandardMaterial({
color: 0x4c5956,
roughness: 1
});
const curbMaterial = new THREE.MeshStandardMaterial({
color: 0xb9aa91,
roughness: 0.98
});
box(42, 0.9, 24, groundMaterial, 0, -0.58, 2.0, scene, false);
box(39, 0.20, 11.5, streetMaterial, 0, -0.10, 8.2, scene, false);
box(30.2, 0.22, 3.0, curbMaterial, 0, 0.05, 1.35, scene, false);
// Individual walkway pavers continue uninterrupted across the whole fragment.
for (let ix = -15; ix <= 15; ix++) {
for (let iz = 0; iz < 3; iz++) {
const material = pathMaterials[(ix + iz * 2 + 30) % pathMaterials.length];
box(
0.94,
0.10,
0.72,
material,
ix + 0.5,
0.19 + ((ix + iz) % 2) * 0.006,
0.40 + iz * 0.78,
scene,
false
);
}
}
// A narrow central tile band makes the continuous route legible.
for (let x = -14.5; x < 14.6; x += 1) {
box(
0.50,
0.055,
2.30,
pathMaterials[2],
x,
0.265,
1.39,
scene,
false
);
}
// Street curb, channel and repeated drain covers.
box(30.4, 0.28, 0.28, curbMaterial, 0, 0.05, 3.02, scene, false);
box(30.4, 0.07, 0.34, recessMaterial, 0, 0.015, 3.30, scene, false);
for (let x = -13; x <= 13; x += 2.5) {
box(0.86, 0.06, 0.28, darkWoodMaterial, x, 0.075, 3.31, scene, false);
for (let i = 0; i < 5; i++) {
box(0.055, 0.07, 0.26, recessMaterial, x - 0.32 + i * 0.16, 0.09, 3.31, scene, false);
}
}
// -------------------------------------------------------------------------
// Covered walkway / five-foot-way canopy
// -------------------------------------------------------------------------
const columnMaterial = new THREE.MeshStandardMaterial({
color: 0xe0cbb0,
roughness: 0.92
});
const columnBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x57766c,
roughness: 0.9
});
const columnPositions = [-14.5, -11.7, -3.9, 3.9, 11.7, 14.5];
for (const x of columnPositions) {
box(0.66, 0.22, 0.66, columnBaseMaterial, x, 0.37, 2.22, scene, false);
box(0.43, 4.48, 0.43, columnMaterial, x, 2.70, 2.22, scene, true);
box(0.63, 0.22, 0.63, columnMaterial, x, 4.92, 2.22, scene, false);
box(0.72, 0.14, 0.72, columnBaseMaterial, x, 5.08, 2.22, scene, false);
}
// Wall ledger, outer beam and exposed rafters.
box(30.2, 0.25, 0.34, darkWoodMaterial, 0, 5.18, 0.07, scene, true);
box(30.2, 0.25, 0.34, darkWoodMaterial, 0, 4.98, 2.22, scene, true);
for (let x = -14.5; x <= 14.6; x += 1.94) {
box(0.15, 0.18, 2.52, darkWoodMaterial, x, 5.10, 1.19, scene, false);
}
// Stepped, voxel-like terracotta canopy roof.
for (let row = 0; row < 4; row++) {
const z = 0.35 + row * 0.73;
const y = 5.48 - row * 0.10;
box(
30.35,
0.18,
0.77,
roofMaterials[(row + 1) % roofMaterials.length],
0,
y,
z,
scene,
true
);
for (let x = -14.85; x < 15; x += 0.66) {
box(
0.57,
0.10,
0.79,
roofMaterials[(Math.floor(x * 10) + row + 20) % roofMaterials.length],
x + 0.31,
y + 0.13,
z,
scene,
false
);
}
}
box(30.5, 0.17, 0.20, darkWoodMaterial, 0, 5.04, 2.70, scene, false);
// Small gutter downpipes at the ends.
for (const x of [-14.5, 14.5]) {
box(0.13, 4.68, 0.13, darkWoodMaterial, x, 2.62, 2.69, scene, false);
box(0.34, 0.13, 0.34, darkWoodMaterial, x, 0.45, 2.69, scene, false);
}
// -------------------------------------------------------------------------
// Three adjacent shophouse bays
// -------------------------------------------------------------------------
const unitCenters = [-7.8, 0, 7.8];
const signPalettes = [
["#315e59", "#f2d7a5"],
["#704632", "#f1d49f"],
["#9d4e3c", "#f6dfb3"]
];
function makeShophouse(centerX, index) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
const wall = wallMaterials[index];
const trim = trimMaterials[index];
const patterned = patternMaterials[index];
// Deep building mass gives the fragment a genuine shophouse depth.
box(7.8, 10.35, 7.25, wall, 0, 5.18, -3.85, group, true);
box(7.72, 10.22, 0.30, wall, 0, 5.15, -0.16, group, true);
box(7.88, 0.48, 0.48, trim, 0, 0.36, 0.02, group, true);
// Ground-floor recess.
box(6.00, 3.54, 0.13, recessMaterial, 0, 2.12, 0.10, group, false);
box(6.20, 0.18, 0.30, darkWoodMaterial, 0, 3.93, 0.20, group, false);
box(6.12, 0.34, 0.28, trim, 0, 0.56, 0.20, group, false);
// Left shop window and timber louvered shutter.
box(2.62, 2.72, 0.09, warmGlassMaterial, -1.37, 2.10, 0.22, group, false);
box(0.13, 2.86, 0.18, darkWoodMaterial, -2.73, 2.10, 0.31, group, false);
box(0.13, 2.86, 0.18, darkWoodMaterial, -0.01, 2.10, 0.31, group, false);
box(2.86, 0.14, 0.18, darkWoodMaterial, -1.37, 0.70, 0.31, group, false);
box(2.86, 0.14, 0.18, darkWoodMaterial, -1.37, 3.50, 0.31, group, false);
makeLouverShutter(
group,
-2.65,
2.10,
0.43,
2.50,
2.60,
index === 1 ? -0.62 : 0
);
// Timber plank door.
box(1.56, 3.05, 0.12, recessMaterial, 1.48, 1.99, 0.20, group, false);
box(1.36, 2.78, 0.14, woodMaterial, 1.48, 1.91, 0.30, group, false);
for (let plank = 0; plank < 6; plank++) {
box(0.025, 2.70, 0.035, darkWoodMaterial, 0.91 + plank * 0.225, 1.91, 0.39, group, false);
}
box(0.16, 3.12, 0.18, darkWoodMaterial, 0.66, 2.00, 0.38, group, false);
box(0.16, 3.12, 0.18, darkWoodMaterial, 2.30, 2.00, 0.38, group, false);
box(1.80, 0.17, 0.18, darkWoodMaterial, 1.48, 0.48, 0.38, group, false);
box(1.80, 0.17, 0.18, darkWoodMaterial, 1.48, 3.53, 0.38, group, false);
box(0.10, 0.10, 0.10, roofMaterials[1], 2.05, 1.95, 0.49, group, false);
// Patterned frieze and shop sign.
box(6.10, 0.36, 0.15, patterned, 0, 4.28, 0.14, group, false);
box(6.30, 0.12, 0.22, trim, 0, 4.51, 0.18, group, false);
const titles = ["KEDAI KUNING", "PENANG", "TOKO HARI"];
const subtitles = ["HERITAGE No. 05", "GEORGE TOWN", "FINE GOODS"];
makeSign(
group,
index === 1 ? 0 : (index === 0 ? -0.35 : 0.35),
4.00,
0.42,
3.35,
0.76,
titles[index],
subtitles[index],
signPalettes[index]
);
// Upper-storey windows.
makeUpperWindow(group, -1.77, 7.13, 2.08, 2.25, index === 2 ? -0.48 : 0);
makeUpperWindow(group, 1.77, 7.13, 2.08, 2.25, index === 0 ? 0.44 : 0);
// Original geometric ventilation panel.
box(1.40, 1.38, 0.17, trim, 0, 9.33, 0.16, group, false);
box(1.18, 1.16, 0.09, patterned, 0, 9.33, 0.28, group, false);
box(0.22, 0.22, 0.14, trim, 0, 10.05, 0.27, group, false);
// Cornice and parapet.
box(7.90, 0.28, 0.72, trim, 0, 10.18, 0.12, group, true);
box(7.98, 0.18, 0.58, darkWoodMaterial, 0, 9.96, 0.08, group, false);
box(7.72, 0.42, 0.54, wall, 0, 10.56, -0.05, group, true);
for (let i = 0; i < 5; i++) {
box(0.28, 0.30, 0.32, trim, -2.7 + i * 1.35, 9.84, 0.31, group, false);
}
// Stepped clay-tile roof behind the parapet.
for (let row = 0; row < 9; row++) {
const z = -0.42 - row * 0.82;
const ridge = 1 - Math.abs(row - 4) / 4;
const y = 10.55 + ridge * 1.15;
box(
7.86,
0.22,
0.87,
roofMaterials[(row + index) % roofMaterials.length],
0,
y,
z,
group,
true
);
for (let col = 0; col < 10; col++) {
box(
0.68,
0.11,
0.80,
roofMaterials[(col + row + index) % roofMaterials.length],
-3.52 + col * 0.78,
y + 0.15,
z,
group,
false
);
}
}
// Small roof lantern and chimney.
box(0.84, 1.25, 0.84, wall, -1.65, 12.17, -4.20, group, true);
box(1.02, 0.20, 1.02, trim, -1.65, 12.86, -4.20, group, true);
box(0.57, 1.70, 0.62, trim, 2.35, 11.95, -5.35, group, true);
box(0.77, 0.18, 0.80, roofMaterials[0], 2.35, 12.86, -5.35, group, true);
return group;
}
unitCenters.forEach((x, i) => makeShophouse(x, i));
// Side elevation of the fragment, visible from the oblique overview.
box(0.16, 2.00, 1.68, recessMaterial, 11.75, 7.25, -2.45, scene, false);
box(0.22, 2.16, 0.15, darkWoodMaterial, 11.86, 7.25, -3.35, scene, false);
box(0.22, 2.16, 0.15, darkWoodMaterial, 11.86, 7.25, -1.55, scene, false);
box(0.22, 0.15, 1.95, darkWoodMaterial, 11.86, 6.15, -2.45, scene, false);
box(0.22, 0.15, 1.95, darkWoodMaterial, 11.86, 8.35, -2.45, scene, false);
// Tiled threshold in front of every shophouse.
for (const centerX of unitCenters) {
for (let row = 0; row < 2; row++) {
for (let tile = 0; tile < 9; tile++) {
box(
0.72,
0.12,
0.38,
thresholdMaterial,
centerX - 3.22 + tile * 0.805,
0.33,
0.16 + row * 0.43,
scene,
false
);
}
}
}
// Hanging sign with a very slight ambient sway.
const hangingSign = new THREE.Group();
hangingSign.position.set(-5.55, 4.78, 1.60);
scene.add(hangingSign);
box(1.58, 0.08, 0.10, darkWoodMaterial, 0, 0.10, 0, hangingSign, false);
box(0.07, 0.47, 0.07, darkWoodMaterial, -0.67, -0.15, 0, hangingSign, false);
box(0.07, 0.47, 0.07, darkWoodMaterial, 0.67, -0.15, 0, hangingSign, false);
box(1.70, 0.83, 0.12, darkWoodMaterial, 0, -0.52, 0, hangingSign, false);
const hangingFace = new THREE.Mesh(
new THREE.PlaneGeometry(1.54, 0.69),
new THREE.MeshStandardMaterial({
map: signTexture("JALAN", "PENANG", "#ead8b7", "#315e59"),
roughness: 0.88
})
);
hangingFace.position.set(0, -0.52, 0.075);
hangingSign.add(hangingFace);
// -------------------------------------------------------------------------
// Small voxel plants and street-edge details
// -------------------------------------------------------------------------
const leafMaterials = [
new THREE.MeshStandardMaterial({ color: 0x3e735e, roughness: 0.95 }),
new THREE.MeshStandardMaterial({ color: 0x5e8b61, roughness: 0.95 }),
new THREE.MeshStandardMaterial({ color: 0x78965d, roughness: 0.95 })
];
function makePlant(x, z, scale = 1) {
const plant = new THREE.Group();
plant.position.set(x, 0, z);
plant.scale.setScalar(scale);
scene.add(plant);
box(0.86, 0.62, 0.86, roofMaterials[1], 0, 0.42, 0, plant, true);
box(1.02, 0.16, 1.02, roofMaterials[0], 0, 0.77, 0, plant, true);
box(0.16, 2.00, 0.16, darkWoodMaterial, 0, 1.62, 0, plant, true);
const offsets = [
[-0.46, 1.55, 0.05, 0.43],
[0.44, 1.74, 0.12, 0.52],
[-0.24, 2.30, -0.08, 0.40],
[0.32, 2.48, 0.00, 0.46],
[-0.52, 2.06, -0.14, 0.36],
[0.58, 2.13, -0.08, 0.34]
];
offsets.forEach((offset, i) => {
box(
offset[3],
offset[3] * 0.72,
offset[3],
leafMaterials[i % leafMaterials.length],
offset[0],
offset[1],
offset[2],
plant,
true
);
});
}
makePlant(-13.35, 3.82, 1.05);
makePlant(13.25, 3.95, 0.95);
// Small kerb stones and a simple street drain reinforce the urban setting.
for (let x = -14; x < 15; x += 2) {
box(1.85, 0.12, 0.42, pathMaterials[0], x, 0.12, 3.57, scene, false);
}
// -------------------------------------------------------------------------
// Direct camera controls
// -------------------------------------------------------------------------
function applyOrbitCamera() {
const radius = 36;
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + radius * cosPhi,
cameraTarget.z + radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
tour = null;
orbit.theta = defaultOrbit.theta;
orbit.phi = defaultOrbit.phi;
orbit.zoom = defaultOrbit.zoom;
walkButton.textContent = "Walk the covered route";
applyOrbitCamera();
}
function startWalk() {
orbit.zoom = 1;
tour = {
started: performance.now(),
duration: 12500
};
walkButton.textContent = "Touring · drag to exit";
}
canvas.addEventListener("pointerdown", event => {
if (tour) {
tour = null;
walkButton.textContent = "Walk the covered route";
applyOrbitCamera();
}
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.0055;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.0045, 1.04, 1.49);
});
function stopDragging() {
dragging = false;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
tour = null;
walkButton.textContent = "Walk the covered route";
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.85
);
applyOrbitCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") orbit.theta += 0.08;
else if (event.key === "ArrowRight") orbit.theta -= 0.08;
else if (event.key === "ArrowUp") orbit.phi = Math.max(1.04, orbit.phi - 0.05);
else if (event.key === "ArrowDown") orbit.phi = Math.min(1.49, orbit.phi + 0.05);
else if (event.key === "+" || event.key === "=") orbit.zoom = Math.min(1.85, orbit.zoom * 1.08);
else if (event.key === "-") orbit.zoom = Math.max(0.68, orbit.zoom / 1.08);
else if (event.key.toLowerCase() === "r") {
resetCamera();
return;
} else {
return;
}
tour = null;
walkButton.textContent = "Walk the covered route";
applyOrbitCamera();
});
resetButton.addEventListener("click", resetCamera);
walkButton.addEventListener("click", startWalk);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
const halfHeight = Math.max(13, 15.8 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
applyOrbitCamera();
// -------------------------------------------------------------------------
// Render loop and guided walk
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate(now) {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
hangingSign.rotation.z = Math.sin(elapsed * 0.75) * 0.025;
hangingSign.rotation.y = Math.sin(elapsed * 0.52) * 0.035;
if (tour) {
const progress = THREE.MathUtils.clamp((now - tour.started) / tour.duration, 0, 1);
const eased = progress * progress * (3 - 2 * progress);
const x = THREE.MathUtils.lerp(-11.5, 11.5, eased);
camera.position.set(x, 2.55, 1.38);
camera.lookAt(x + 4.6, 2.85, 0.63);
camera.zoom = 1.58;
camera.updateProjectionMatrix();
if (progress >= 1) {
tour = null;
walkButton.textContent = "Walk the covered route";
applyOrbitCamera();
}
} else {
applyOrbitCamera();
}
renderer.render(scene, camera);
if (loading && loading.style.opacity !== "0") {
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 450);
}
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```