Prompt specification
Build or customize the Three.js 3D scene "Pedestrian moving from a shop lane to a forecourt" 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: Pedestrian moving from a shop lane to a forecourt
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pedestrian-moving-from-a-shop-lane-to-a-forecourt-x3026
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Create a compact referenced Kampong Glam vignette with original shop display and a respectful religious-landmark backdrop. Keep access routes clear and avoid treating worship space as decorative entertainment.
Working Three.js Starter (pedestrian-moving-from-a-shop-lane-to-a-forecourt-x3026):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kampong Glam — Voxel Courtyard Vignette</title>
<style>
:root {
color-scheme: light;
--ink: #263c3a;
--muted: #61706c;
--paper: rgba(250, 247, 237, 0.9);
--line: rgba(38, 60, 58, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4d8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 2;
max-width: min(390px, calc(100vw - 32px));
padding: 17px 19px;
color: var(--ink);
background: var(--paper);
border: 1px solid var(--line);
border-radius: 4px;
box-shadow: 0 12px 36px rgba(40, 49, 45, 0.12);
backdrop-filter: blur(10px);
}
#intro {
top: 20px;
left: 20px;
}
.eyebrow {
margin: 0 0 7px;
color: #9b654e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 3vw, 34px);
font-weight: 500;
line-height: 1.08;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.rule {
width: 38px;
height: 2px;
margin: 13px 0;
background: #c39168;
}
.context {
margin: 0;
color: #50635f;
font-size: 11px;
line-height: 1.55;
}
#hint {
position: fixed;
z-index: 2;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 9px 13px;
color: #425754;
background: rgba(250, 247, 237, 0.82);
border: 1px solid var(--line);
border-radius: 3px;
font-size: 11px;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
}
#reset {
position: fixed;
z-index: 3;
right: 20px;
bottom: 20px;
padding: 10px 13px;
color: #f7f3e8;
background: #294743;
border: 0;
border-radius: 3px;
box-shadow: 0 8px 20px rgba(34, 55, 51, 0.18);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#reset:hover { background: #37635d; }
#reset:focus-visible { outline: 3px solid #d7b47d; outline-offset: 3px; }
@media (max-width: 700px) {
#intro { top: 12px; left: 12px; padding: 13px 15px; }
.context, .rule { display: none; }
.subtitle { max-width: 270px; font-size: 11px; }
#hint {
bottom: 12px;
max-width: calc(100vw - 90px);
overflow: hidden;
text-overflow: ellipsis;
}
#reset { right: 12px; bottom: 12px; }
}
</style>
</head>
<body>
<main
id="viewport"
aria-label="Interactive voxel interpretation of a Kampong Glam courtyard with shophouses, a fictional boutique, and Sultan Mosque in the background"
></main>
<section id="intro" class="panel">
<p class="eyebrow">Kampong Glam · Singapore</p>
<h1>A compact urban vignette</h1>
<p class="subtitle">
Pastel shophouse references, an original colour-and-craft boutique,
and a respectful Sultan Mosque backdrop.
</p>
<div class="rule"></div>
<p class="context">
Retail occupies the side bays. The contrasting central pedestrian route
remains unobstructed, and the mosque is treated as an active place of
worship behind a low precinct boundary.
</p>
</section>
<div id="hint">Drag to orbit · Scroll or pinch to zoom · Arrow keys to pan · R to reset</div>
<button id="reset" type="button">Reset view</button>
<script type="module">
import * as THREE from
'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const viewport = document.getElementById('viewport');
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: 'high-performance'
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
'aria-label',
'Voxel Kampong Glam architectural scene'
);
renderer.domElement.tabIndex = 0;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4d8);
scene.fog = new THREE.Fog(0xe9e4d8, 38, 76);
const camera = new THREE.PerspectiveCamera(
38,
viewport.clientWidth / viewport.clientHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(
0xfff8e8,
0x69736c,
2.0
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefd3, 3.0);
sun.position.set(13, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -23;
sun.shadow.camera.right = 23;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d7d4, 0.65);
fill.position.set(-16, 11, -12);
scene.add(fill);
// ---------------------------------------------------------------------
// Shared voxel primitives
// ---------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function materialFor(color) {
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(key);
}
function box(
parent,
x, y, z,
width, height, depth,
color,
options = {}
) {
const material = options.material || (
options.emissive
? new THREE.MeshStandardMaterial({
color,
emissive: options.emissive,
emissiveIntensity: options.emissiveIntensity ?? 1,
roughness: 0.65
})
: materialFor(color)
);
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.rotationY) mesh.rotation.y = options.rotationY;
if (options.rotationX) mesh.rotation.x = options.rotationX;
parent.add(mesh);
return mesh;
}
function groupAt(x, y, z, rotationY = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotationY;
scene.add(group);
return group;
}
// Procedural sign textures keep the file self-contained.
function makeSignMaterial(title, subtitle, background, foreground) {
const canvas = document.createElement('canvas');
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext('2d');
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = foreground;
context.globalAlpha = 0.13;
context.fillRect(28, 24, canvas.width - 56, 7);
context.globalAlpha = 1;
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillStyle = foreground;
context.font = '700 78px Arial, sans-serif';
context.fillText(title, 512, subtitle ? 93 : 128, 925);
if (subtitle) {
context.globalAlpha = 0.82;
context.font = '600 28px Arial, sans-serif';
context.fillText(subtitle, 512, 183, 925);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
}
function sign(
parent,
title,
subtitle,
x, y, z,
width, height,
background = '#264c47',
foreground = '#f7f1df'
) {
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
makeSignMaterial(title, subtitle, background, foreground)
);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
const roofInstanceMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94
});
function addRoofTiles(group, width, depth, y, colors) {
const columns = Math.max(3, Math.round(width / 0.53));
const rows = Math.max(4, Math.round(depth / 0.48));
const tileWidth = width / columns * 0.92;
const tileDepth = depth / rows * 0.9;
const tiles = new THREE.InstancedMesh(
cubeGeometry,
roofInstanceMaterial,
columns * rows
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
dummy.position.set(
-width / 2 + (column + 0.5) * width / columns,
y,
-depth / 2 + (row + 0.5) * depth / rows
);
dummy.scale.set(tileWidth, 0.13, tileDepth);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
color.set(colors[(row + column) % colors.length]);
tiles.setColorAt(index, color);
index++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.castShadow = true;
tiles.receiveShadow = true;
group.add(tiles);
}
// ---------------------------------------------------------------------
// Base and paving
// ---------------------------------------------------------------------
box(scene, 0, -0.48, 0, 32.4, 0.96, 24.4, 0x976957);
box(scene, 0, -0.08, 0, 32.05, 0.16, 24.05, 0xc8c0b1);
const tileCountX = 32;
const tileCountZ = 24;
const paving = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
}),
tileCountX * tileCountZ
);
const dummy = new THREE.Object3D();
const pavingColor = new THREE.Color();
let seed = 1947;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
let pavingIndex = 0;
for (let zIndex = 0; zIndex < tileCountZ; zIndex++) {
for (let xIndex = 0; xIndex < tileCountX; xIndex++) {
const x = xIndex - 15.5;
const z = zIndex - 11.5;
let baseColor;
if (Math.abs(x) < 3.25 && z > -6.05) {
baseColor = 0xe8d9bb;
} else if (Math.abs(x) < 1.75 && z <= -5.45) {
baseColor = 0xe8d9bb;
} else if (z < -5.8) {
baseColor = 0xd8d3c3;
} else {
baseColor = 0xc5c7bf;
}
pavingColor.set(baseColor);
pavingColor.offsetHSL(
0,
0,
(random() - 0.5) * 0.035
);
dummy.position.set(x, 0.035, z);
dummy.scale.set(0.975, 0.07, 0.975);
dummy.updateMatrix();
paving.setMatrixAt(pavingIndex, dummy.matrix);
paving.setColorAt(pavingIndex, pavingColor);
pavingIndex++;
}
}
paving.instanceMatrix.needsUpdate = true;
paving.instanceColor.needsUpdate = true;
paving.receiveShadow = true;
scene.add(paving);
// Fine inlays identify the protected central pedestrian route.
for (const x of [-3.42, 3.42]) {
box(
scene, x, 0.085, 2.45,
0.07, 0.025, 17.1,
0xb98a62,
{ castShadow: false }
);
}
const routeLabel = sign(
scene,
'PEDESTRIAN ACCESS',
'KEEP THE CENTRAL LANE CLEAR',
0, 0.091, 9.2,
3.8, 0.82,
'#e8d9bb',
'#756e5e'
);
routeLabel.rotation.x = -Math.PI / 2;
// ---------------------------------------------------------------------
// Generic shophouses
// ---------------------------------------------------------------------
function makeShophouse({
x,
z,
rotationY,
width,
color,
upperColor,
trim,
title,
subtitle,
roofColors
}) {
const group = groupAt(x, 0.08, z, rotationY);
const depth = 6.0;
const front = depth / 2;
// Lower and upper floors.
box(group, 0, 1.35, 0, width, 2.7, depth, color);
box(group, 0, 4.025, -0.08, width, 2.65, depth * 0.96, upperColor);
// Slightly projecting cornices.
box(group, 0, 2.72, 0.04, width + 0.16, 0.18, depth + 0.12, trim);
box(group, 0, 5.34, -0.08, width + 0.18, 0.18, depth * 0.96 + 0.18, trim);
box(group, 0, 5.43, -0.08, width + 0.12, 0.14, depth * 0.96 + 0.10, 0x744f43);
addRoofTiles(group, width + 0.08, depth * 0.96, 5.55, roofColors);
// Five-foot covered walkway.
box(group, 0, 2.78, front + 0.55, width + 0.12, 0.18, 1.28, trim);
box(group, 0, 2.61, front + 1.18, width + 0.12, 0.36, 0.13, color);
for (const side of [-1, 1]) {
box(
group,
side * (width / 2 - 0.22), 1.34, front + 1.05,
0.16, 2.68, 0.16,
0xeee4cf
);
}
// Lower storefront openings.
const doorX = -width * 0.25;
box(group, doorX, 1.08, front + 0.045, 0.78, 1.92, 0.09, 0x334b49);
box(group, doorX + 0.24, 1.1, front + 0.102, 0.045, 1.75, 0.035, 0xb88b61);
const shopWindowX = width * 0.24;
box(group, shopWindowX, 1.40, front + 0.045, 1.12, 1.25, 0.09, 0x425b58);
box(group, shopWindowX, 1.40, front + 0.105, 0.06, 1.18, 0.03, 0xc4b99f);
box(group, shopWindowX, 1.40, front + 0.105, 1.05, 0.06, 0.03, 0xc4b99f);
for (const side of [-1, 1]) {
box(
group,
shopWindowX + side * 0.76, 1.4, front + 0.055,
0.36, 1.38, 0.12,
trim
);
}
// Upper-floor windows and shutters.
for (const side of [-1, 1]) {
const windowX = side * width * 0.23;
box(group, windowX, 4.08, front + 0.045, 1.02, 1.18, 0.09, 0x3b5552);
box(group, windowX, 4.08, front + 0.105, 0.055, 1.10, 0.03, 0xe8dfc9);
box(group, windowX, 4.08, front + 0.105, 0.95, 0.055, 0.03, 0xe8dfc9);
for (const shutterSide of [-1, 1]) {
box(
group,
windowX + shutterSide * 0.77, 4.08, front + 0.06,
0.40, 1.34, 0.13,
trim
);
}
}
sign(
group,
title,
subtitle,
0, 2.60, front + 1.26,
width * 0.86, 0.48,
'#294a46',
'#f8f1de'
);
// Drainpipe and small wall lamps.
box(
group,
width / 2 - 0.05, 2.7, front + 0.08,
0.10, 5.2, 0.12,
0x8f684f
);
box(
group,
width * 0.34, 2.40, front + 0.12,
0.18, 0.18, 0.18,
0xffd68a,
{ emissive: 0xffbd5d, emissiveIntensity: 0.7 }
);
return group;
}
makeShophouse({
x: -9.5, z: -2.45, rotationY: Math.PI / 2,
width: 3.7,
color: 0xe8bd78,
upperColor: 0xd88e73,
trim: 0x4c7d75,
title: 'KETUM',
subtitle: 'TEA & SMALL GOODS',
roofColors: [0xa8654e, 0xba7458, 0x945847]
});
makeShophouse({
x: -9.5, z: 7.55, rotationY: Math.PI / 2,
width: 3.55,
color: 0x91b9b1,
upperColor: 0xefc2a1,
trim: 0xb25d4f,
title: 'LITTLE ATLAS',
subtitle: 'BOOKS & PAPER',
roofColors: [0xa7624d, 0xb87157, 0x925341]
});
makeShophouse({
x: 9.5, z: -1.85, rotationY: -Math.PI / 2,
width: 3.8,
color: 0xc9a0aa,
upperColor: 0x8eb6b2,
trim: 0xe0b468,
title: 'MORI WORKS',
subtitle: 'HOME & GIFT',
roofColors: [0xa25f4b, 0xb36c52, 0x8f503f]
});
makeShophouse({
x: 9.5, z: 2.85, rotationY: -Math.PI / 2,
width: 3.8,
color: 0xe2c878,
upperColor: 0xca806d,
trim: 0x477d76,
title: 'PAPER FIELD',
subtitle: 'STATIONERY & POST',
roofColors: [0x9c5a48, 0xae6750, 0x874b3c]
});
makeShophouse({
x: 9.5, z: 7.55, rotationY: -Math.PI / 2,
width: 3.55,
color: 0x8faeb3,
upperColor: 0xe1b7a1,
trim: 0x8b5d52,
title: 'TINT',
subtitle: 'DAILY OBJECTS',
roofColors: [0xa7604b, 0xb57054, 0x8f503f]
});
// ---------------------------------------------------------------------
// Original boutique: NILA Colour & Craft
// ---------------------------------------------------------------------
function makeVase(parent, x, baseY, z, color, scale = 1) {
const s = scale;
box(parent, x, baseY + 0.30 * s, z, 0.58 * s, 0.60 * s, 0.58 * s, color);
box(parent, x, baseY + 0.72 * s, z, 0.34 * s, 0.36 * s, 0.34 * s, color);
box(parent, x, baseY + 0.94 * s, z, 0.48 * s, 0.12 * s, 0.48 * s, color);
box(parent, x, baseY + 0.995 * s, z, 0.30 * s, 0.045 * s, 0.30 * s, 0xeadfc6);
}
function makeBoutique() {
const group = groupAt(-9.5, 0.08, 2.65, Math.PI / 2);
const width = 4.7;
const depth = 6.2;
const front = depth / 2;
// Open lower shop, solid upper floor.
box(group, 0, 0.08, 0, width, 0.16, depth, 0xb9aa91);
box(group, 0, 1.35, -depth / 2 + 0.10, width, 2.7, 0.20, 0xefe0c2);
box(group, -width / 2 + 0.10, 1.35, 0, 0.20, 2.7, depth, 0xe7d4b6);
box(group, width / 2 - 0.10, 1.35, 0, 0.20, 2.7, depth, 0xe7d4b6);
box(group, 0, 4.025, -0.08, width, 2.65, depth * 0.96, 0xb96556);
// Interior backdrop and original dyed panels.
box(group, 0, 1.40, -depth / 2 + 0.23, width - 0.45, 2.35, 0.08, 0x304743);
box(group, -1.38, 1.55, -depth / 2 + 0.30, 0.70, 1.55, 0.10, 0xd99274);
box(group, -0.48, 1.55, -depth / 2 + 0.30, 0.70, 1.55, 0.10, 0x4e9b92);
box(group, 0.42, 1.55, -depth / 2 + 0.30, 0.70, 1.55, 0.10, 0xe2bd62);
box(group, 1.32, 1.55, -depth / 2 + 0.30, 0.70, 1.55, 0.10, 0x7b7898);
// Display plinths.
box(group, -1.25, 0.38, 1.38, 0.82, 0.76, 0.82, 0xd6c5a8);
box(group, 0.00, 0.25, 1.38, 0.86, 0.50, 0.82, 0xcbbb9e);
box(group, 1.25, 0.38, 1.38, 0.82, 0.76, 0.82, 0xd6c5a8);
// Handmade voxel vessels.
makeVase(group, -1.25, 0.76, 1.38, 0x4e9b92, 1.15);
makeVase(group, -1.25, 0.76, 0.98, 0xe0aa62, 0.64);
// Folded textiles.
const textileColors = [0xcd766a, 0x4e8e89, 0xe0b968, 0x7b6d91];
for (let index = 0; index < 4; index++) {
box(
group,
0, 0.61 + index * 0.18, 1.38,
0.73 - index * 0.035,
0.16,
0.68 - index * 0.025,
textileColors[index]
);
}
// Small dye jars.
for (let index = 0; index < 3; index++) {
const jarX = 0.96 + index * 0.29;
const jarColors = [0xa85e50, 0xd3a34f, 0x477d76];
box(group, jarX, 0.94, 1.40, 0.23, 0.34, 0.23, jarColors[index]);
box(group, jarX, 1.14, 1.40, 0.26, 0.08, 0.26, 0xe7dcc2);
}
// Glass storefront with slender frames.
const glassMaterial = new THREE.MeshBasicMaterial({
color: 0xc9eee9,
transparent: true,
opacity: 0.14,
depthWrite: false,
side: THREE.DoubleSide
});
const glass = new THREE.Mesh(
new THREE.PlaneGeometry(width - 0.52, 2.14),
glassMaterial
);
glass.position.set(0, 1.38, front + 0.035);
group.add(glass);
for (const x of [-width / 2 + 0.24, 0, width / 2 - 0.24]) {
box(group, x, 1.38, front + 0.075, 0.055, 2.18, 0.055, 0x425a54);
}
box(group, 0, 2.45, front + 0.075, width - 0.44, 0.055, 0.055, 0x425a54);
box(group, 0, 0.31, front + 0.075, width - 0.44, 0.055, 0.055, 0x425a54);
// Alternating fabric awning.
const awningDepth = 1.28;
for (let index = 0; index < 10; index++) {
const stripeWidth = width / 10;
const color = index % 2 === 0 ? 0x3e7772 : 0xeee0c3;
box(
group,
-width / 2 + (index + 0.5) * stripeWidth,
2.81,
front + awningDepth / 2,
stripeWidth * 0.96,
0.16,
awningDepth,
color
);
}
for (const side of [-1, 1]) {
box(
group,
side * (width / 2 - 0.22), 1.35, front + 1.12,
0.16, 2.7, 0.16,
0x405d58
);
}
// Original sign.
sign(
group,
'NILA',
'COLOUR & CRAFT STUDIO',
0, 3.18, front + 0.09,
3.35, 0.66,
'#294d49',
'#f7edda'
);
// Upper windows.
for (const x of [-1.15, 1.15]) {
box(group, x, 4.18, front + 0.05, 1.02, 1.05, 0.08, 0x405955);
box(group, x, 4.18, front + 0.105, 0.055, 0.98, 0.03, 0xdfd3b9);
box(group, x, 4.18, front + 0.105, 0.95, 0.05, 0.03, 0xdfd3b9);
}
box(group, 0, 5.34, -0.08, width + 0.18, 0.18, depth * 0.96 + 0.16, 0xe8d2aa);
box(group, 0, 5.43, -0.08, width + 0.12, 0.14, depth * 0.96 + 0.10, 0x744f43);
addRoofTiles(group, width + 0.08, depth * 0.96, 5.55, [0x9f5c49, 0xb36d51, 0x8d4e3e]);
// Warm display light without animation or spectacle.
const boutiqueLight = new THREE.PointLight(0xffc779, 7, 5.5, 2);
boutiqueLight.position.set(0, 2.30, 1.3);
group.add(boutiqueLight);
for (const x of [-1.3, 0, 1.3]) {
box(
group,
x, 2.55, 1.35,
0.18, 0.12, 0.18,
0xffdf9e,
{ emissive: 0xffbc61, emissiveIntensity: 1.3 }
);
}
}
makeBoutique();
// ---------------------------------------------------------------------
// Landscape and side-bay street furniture
// ---------------------------------------------------------------------
function planter(x, z, accent = 0x4f765c) {
const group = groupAt(x, 0.08, z);
box(group, 0, 0.30, 0, 0.88, 0.60, 0.88, 0xa87459);
box(group, 0, 0.62, 0, 0.96, 0.10, 0.96, 0xc38a68);
box(group, 0, 0.68, 0, 0.76, 0.08, 0.76, 0x5a5545);
box(group, 0, 1.05, 0, 0.18, 0.75, 0.18, 0x72583e);
box(group, -0.23, 1.18, 0.04, 0.55, 0.50, 0.55, accent);
box(group, 0.27, 1.08, -0.10, 0.55, 0.48, 0.50, 0x78936b);
box(group, 0.03, 1.55, 0.01, 0.55, 0.48, 0.52, 0x52765b);
return group;
}
function bench(x, z, rotationY = 0) {
const group = groupAt(x, 0.08, z, rotationY);
box(group, 0, 0.53, 0, 1.75, 0.16, 0.48, 0x9b694f);
box(group, 0, 0.95, -0.20, 1.75, 0.48, 0.12, 0x9b694f);
for (const side of [-1, 1]) {
box(group, side * 0.63, 0.25, 0, 0.13, 0.50, 0.38, 0x4a5b55);
}
}
function streetLamp(x, z) {
const group = groupAt(x, 0.08, z);
box(group, 0, 0.10, 0, 0.42, 0.20, 0.42, 0x40534f);
box(group, 0, 1.65, 0, 0.13, 3.10, 0.13, 0x40534f);
box(group, 0, 3.18, 0, 0.18, 0.30, 0.18, 0xffd58a, {
emissive: 0xffbb59,
emissiveIntensity: 0.85
});
box(group, 0, 3.38, 0, 0.42, 0.12, 0.42, 0x40534f);
}
planter(-4.65, 9.45);
planter(4.65, 9.45);
planter(-4.65, 0.15, 0x647f58);
planter(4.65, 5.75, 0x6a8056);
bench(-6.25, 9.45, Math.PI / 2);
bench(6.25, 9.45, -Math.PI / 2);
streetLamp(-4.35, 7.55);
streetLamp(4.35, 1.15);
streetLamp(-4.35, -4.65);
streetLamp(4.35, -4.65);
// ---------------------------------------------------------------------
// Respectful Sultan Mosque backdrop and prayer precinct
// ---------------------------------------------------------------------
const mosque = groupAt(0, 0, 0);
const ivory = 0xf0e4c9;
const mosqueTeal = 0x346d68;
const mosqueGold = 0xc89d43;
// Low precinct boundary, with a central access opening.
for (const side of [-1, 1]) {
box(
mosque,
side * 6.95, 0.65, -5.70,
10.1, 1.30, 0.36,
0xe7dcc4
);
box(
mosque,
side * 6.95, 1.34, -5.70,
10.1, 0.12, 0.48,
mosqueTeal
);
box(
mosque,
side * 1.92, 0.88, -5.70,
0.38, 1.76, 0.52,
ivory
);
box(
mosque,
side * 1.92, 1.79, -5.70,
0.50, 0.12, 0.62,
mosqueTeal
);
}
// Restrained shrubs remain behind the boundary and outside the route.
for (const x of [-10.6, -8.6, -6.6, -4.6, 4.6, 6.6, 8.6, 10.6]) {
box(mosque, x, 0.45, -6.02, 1.25, 0.80, 0.74, 0x66785c);
box(mosque, x + 0.12, 0.94, -6.02, 0.78, 0.38, 0.52, 0x82916a);
}
// Platform and shallow, aligned entrance steps.
box(mosque, 0, 0.20, -9.0, 11.2, 0.40, 6.0, 0xd9ceb5);
box(mosque, 0, 0.13, -5.82, 4.2, 0.26, 0.58, 0xe5d9bd);
box(mosque, 0, 0.25, -6.20, 3.7, 0.50, 0.50, 0xeee2c6);
// Main prayer hall.
box(mosque, 0, 2.50, -9.0, 9.0, 4.20, 4.20, ivory);
box(mosque, 0, 4.62, -9.0, 9.45, 0.25, 4.65, mosqueTeal);
box(mosque, 0, 0.53, -9.0, 9.35, 0.28, 4.55, 0xd7cbb0);
// Stepped voxel entrance.
box(mosque, 0, 1.52, -6.865, 1.62, 2.22, 0.12, 0x315853);
box(mosque, 0, 2.77, -6.855, 1.05, 0.46, 0.14, 0x315853);
box(mosque, 0, 3.12, -6.845, 0.50, 0.24, 0.15, 0x315853);
for (const side of [-1, 1]) {
box(mosque, side * 0.98, 1.60, -6.81, 0.20, 2.80, 0.20, mosqueGold);
}
box(mosque, 0, 3.05, -6.80, 2.15, 0.18, 0.20, mosqueGold);
box(mosque, 0, 3.37, -6.78, 0.92, 0.18, 0.20, mosqueGold);
// Side windows.
for (const x of [-2.7, -1.75, 1.75, 2.7, 3.65]) {
box(mosque, x, 2.35, -6.855, 0.48, 1.18, 0.12, mosqueTeal);
box(mosque, x, 2.35, -6.785, 0.055, 1.05, 0.03, 0xd2b46d);
}
// Dome drum and stepped gold dome.
box(mosque, 0, 4.99, -9.0, 3.55, 0.58, 3.55, mosqueTeal);
const domeWidths = [3.20, 2.78, 2.32, 1.88, 1.42, 0.94, 0.50];
domeWidths.forEach((width, index) => {
box(
mosque,
0,
5.37 + index * 0.34,
-9.0,
width,
0.42,
width,
index % 2 === 0 ? mosqueGold : 0xd5aa50
);
});
box(mosque, 0, 7.68, -9.0, 0.13, 0.62, 0.13, mosqueGold);
box(mosque, 0, 7.96, -9.0, 0.24, 0.14, 0.24, mosqueGold);
// Minarets with restrained detailing.
function minaret(x) {
box(mosque, x, 0.54, -8.72, 1.05, 0.38, 1.05, 0xd9cdb2);
box(mosque, x, 3.50, -8.72, 0.64, 5.65, 0.64, ivory);
box(mosque, x, 2.65, -8.365, 0.36, 0.85, 0.10, mosqueTeal);
box(mosque, x, 6.38, -8.72, 1.18, 0.28, 1.18, mosqueTeal);
box(mosque, x, 6.88, -8.72, 0.54, 0.95, 0.54, ivory);
box(mosque, x, 7.43, -8.72, 0.78, 0.26, 0.78, mosqueGold);
box(mosque, x, 7.70, -8.72, 0.58, 0.26, 0.58, mosqueGold);
box(mosque, x, 7.92, -8.72, 0.32, 0.22, 0.32, mosqueGold);
box(mosque, x, 8.10, -8.72, 0.10, 0.30, 0.10, mosqueGold);
}
minaret(-4.85);
minaret(4.85);
// Subtle civic plaque at the precinct edge, rather than a theme-park sign.
sign(
mosque,
'SULTAN MOSQUE',
'ACTIVE PLACE OF WORSHIP',
-6.95, 0.77, -5.49,
2.80, 0.50,
'#ded4bd',
'#52645e'
);
// ---------------------------------------------------------------------
// Custom camera controls: orbit, zoom, keyboard, touch pinch
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 2.2, -0.8);
const initialView = {
theta: 0.58,
phi: 0.92,
radius: 30.5
};
const view = { ...initialView };
const goal = { ...initialView };
const pointers = new Map();
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function cameraPosition() {
const horizontal = Math.sin(view.phi) * view.radius;
camera.position.set(
target.x + horizontal * Math.sin(view.theta),
target.y + Math.cos(view.phi) * view.radius,
target.z + horizontal * Math.cos(view.theta)
);
camera.lookAt(target);
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener('pointerdown', event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener('pointermove', event => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
goal.theta -= deltaX * 0.006;
goal.phi = THREE.MathUtils.clamp(
goal.phi + deltaY * 0.0045,
0.38,
1.38
);
previousX = event.clientX;
previousY = event.clientY;
} else {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
goal.radius = THREE.MathUtils.clamp(
goal.radius * (previousPinchDistance / distance),
19,
43
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
renderer.domElement.addEventListener('pointerup', releasePointer);
renderer.domElement.addEventListener('pointercancel', releasePointer);
renderer.domElement.addEventListener('lostpointercapture', releasePointer);
renderer.domElement.addEventListener('wheel', event => {
event.preventDefault();
goal.radius = THREE.MathUtils.clamp(
goal.radius * Math.exp(event.deltaY * 0.001),
19,
43
);
}, { passive: false });
function resetView() {
goal.theta = initialView.theta;
goal.phi = initialView.phi;
goal.radius = initialView.radius;
}
document.getElementById('reset').addEventListener('click', resetView);
window.addEventListener('keydown', event => {
const key = event.key.toLowerCase();
if (key === 'r') {
resetView();
return;
}
if (key === 'arrowleft') {
goal.theta += 0.10;
event.preventDefault();
} else if (key === 'arrowright') {
goal.theta -= 0.10;
event.preventDefault();
} else if (key === 'arrowup') {
goal.phi = THREE.MathUtils.clamp(goal.phi - 0.07, 0.38, 1.38);
event.preventDefault();
} else if (key === 'arrowdown') {
goal.phi = THREE.MathUtils.clamp(goal.phi + 0.07, 0.38, 1.38);
event.preventDefault();
} else if (key === '+' || key === '=') {
goal.radius = THREE.MathUtils.clamp(goal.radius - 1.5, 19, 43);
} else if (key === '-') {
goal.radius = THREE.MathUtils.clamp(goal.radius + 1.5, 19, 43);
}
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener('resize', resize);
resize();
cameraPosition();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.exp(-8 * delta);
view.theta = THREE.MathUtils.lerp(view.theta, goal.theta, easing);
view.phi = THREE.MathUtils.lerp(view.phi, goal.phi, easing);
view.radius = THREE.MathUtils.lerp(view.radius, goal.radius, easing);
cameraPosition();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```