Prompt specification
Build or customize the Three.js 3D scene "Kampong Glam shophouse arch and five-foot-way fragment" 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: Kampong Glam shophouse arch and five-foot-way fragment
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/kampong-glam-shophouse-arch-and-five-foot-way-fragment-x3025
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a Kampong Glam shophouse in Singapore. Build a referenced shophouse bay with upper window, arcade opening, and covered walkway. Show the public passage continuing through the facade rhythm at ground level. Low-poly.
Working Three.js Starter (kampong-glam-shophouse-arch-and-five-foot-way-fragment-x3025):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kampong Glam Shophouse</title>
<style>
:root {
--cream: #f7edd9;
--ink: #283f3b;
--gold: #d4a54b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9d4;
color: var(--ink);
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
max-width: 360px;
padding: 18px 20px 16px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-left: 5px solid var(--gold);
background: rgba(248, 239, 219, 0.9);
box-shadow: 0 12px 35px rgba(32, 50, 46, 0.16);
backdrop-filter: blur(9px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: #8b6333;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 36px);
font-weight: 500;
line-height: 1.03;
}
.subtitle {
margin-top: 9px;
color: rgba(40, 63, 59, 0.72);
font-size: 12px;
line-height: 1.45;
}
.controls {
position: fixed;
right: 22px;
bottom: 20px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.38);
border-radius: 4px;
background: rgba(35, 54, 50, 0.78);
color: #f8f0df;
font-size: 11px;
letter-spacing: 0.04em;
backdrop-filter: blur(8px);
pointer-events: none;
}
.controls strong {
color: #f0c46c;
font-weight: 700;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #d6dfd9;
color: #405d55;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 0.5s ease;
pointer-events: none;
}
#loading.done {
opacity: 0;
}
@media (max-width: 650px) {
.title-card {
top: 12px;
left: 12px;
right: 12px;
max-width: none;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="title-card">
<div class="eyebrow">Singapore · Conservation Area</div>
<h1>Kampong Glam</h1>
<div class="subtitle">
A low-poly study of the conserved Peranakan shophouse frontage:
pastel upper storeys, shuttered windows, arched ground-level openings,
and a continuous covered public passage.
</div>
</header>
<div class="controls">
<strong>Drag</strong> orbit · <strong>Scroll / pinch</strong> zoom ·
<strong>Double-click</strong> reset
</div>
<div id="loading">Building the shophouse arcade…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, scene, and lighting
// ---------------------------------------------------------------------
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd9d4);
scene.fog = new THREE.Fog(0xcbd9d4, 28, 65);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(
0xe7f2ed,
0x806d55,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b0, 3.3);
sun.position.set(-13, 22, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaacbd0, 0.75);
fill.position.set(14, 9, -8);
scene.add(fill);
// ---------------------------------------------------------------------
// Small geometry helpers
// ---------------------------------------------------------------------
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.0,
flatShading: true,
...options
});
}
function box(
width, height, depth,
x, y, z,
mat,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
topRadius, bottomRadius, height,
x, y, z,
mat,
segments = 8,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, radius, mat, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 6),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
Y_AXIS,
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function octahedron(radius, x, y, z, mat, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.OctahedronGeometry(radius, 0),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function makeSignTexture(title, subtitle, background, foreground) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.lineWidth = 7;
ctx.strokeRect(12, 12, canvas.width - 24, canvas.height - 24);
ctx.strokeStyle = foreground;
ctx.lineWidth = 2;
ctx.strokeRect(25, 25, canvas.width - 50, canvas.height - 50);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = "600 47px Georgia";
ctx.fillText(title, canvas.width / 2, 82);
ctx.font = "700 20px Arial";
ctx.fillText(subtitle, canvas.width / 2, 137);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addSign(title, subtitle, x, y, width, palette, parent) {
const group = new THREE.Group();
group.position.set(x, y, 0);
parent.add(group);
box(
width + 0.12, 0.58, 0.16,
0, 0, 0.10,
palette.trim,
group
);
const texture = makeSignTexture(
title,
subtitle,
palette.signBackground,
palette.signText
);
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width, 0.43),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide
})
);
plane.position.z = 0.195;
group.add(plane);
return group;
}
// ---------------------------------------------------------------------
// Shared materials
// ---------------------------------------------------------------------
const groundMaterial = material(0x777c73);
const asphaltMaterial = material(0x4d5653);
const sidewalkMaterial = material(0xc9bda3);
const pavingMaterial = material(0xe4d8bc);
const pavingAltMaterial = material(0xd6c7a9);
const seamMaterial = material(0xb9aa8e);
const curbMaterial = material(0xe0d5bd);
const roadMarkMaterial = material(0xe6d8b5);
const interiorMaterial = material(0x233b38);
const interiorFloorMaterial = material(0x52645a);
const darkWoodMaterial = material(0x4a3429);
const brassMaterial = material(0xc79a43, {
roughness: 0.55,
metalness: 0.25
});
// ---------------------------------------------------------------------
// Street, pavement, and the continuous covered passage
// ---------------------------------------------------------------------
const buildingWidth = 21;
const facadeGroup = new THREE.Group();
scene.add(facadeGroup);
box(
80, 0.16, 55,
0, -0.18, 20,
asphaltMaterial,
scene,
false
);
box(
52, 0.16, 7.3,
0, -0.05, 5.65,
sidewalkMaterial,
scene,
false
);
box(
60, 0.24, 0.28,
0, -0.02, 9.35,
curbMaterial,
scene,
false
);
// Road markings.
for (let x = -28; x <= 28; x += 5) {
box(
2.4, 0.015, 0.13,
x, -0.085, 15.5,
roadMarkMaterial,
scene,
false
);
}
// Drain grates.
for (const x of [-7.8, 6.5]) {
box(
1.0, 0.025, 0.38,
x, 0.045, 8.9,
material(0x555a55),
scene,
false
);
for (let i = 0; i < 7; i++) {
box(
0.055, 0.035, 0.34,
x - 0.42 + i * 0.14,
0.063,
8.9,
material(0x242c29),
scene,
false
);
}
}
// Public walkway paving continues horizontally beneath every bay.
box(
buildingWidth + 0.4, 0.055, 2.0,
0, 0.035, 1.0,
pavingMaterial,
scene,
false
);
for (let x = -10; x <= 10; x += 1.05) {
box(
0.018, 0.012, 1.88,
x, 0.069, 1.0,
seamMaterial,
scene,
false
);
}
// A second paving rhythm outside the covered arcade.
for (let x = -18; x <= 18; x += 1.8) {
for (let z = 2.8; z < 9; z += 1.55) {
const alternate = Math.round((x + z) * 2) % 2 === 0;
box(
1.72, 0.018, 1.47,
x, 0.05, z,
alternate ? sidewalkMaterial : pavingAltMaterial,
scene,
false
);
}
}
// ---------------------------------------------------------------------
// Five conserved shophouse bays
// ---------------------------------------------------------------------
const bayWidth = 4.2;
const bayCount = 5;
const openingRadius = 1.47;
const archSpring = 1.22;
const palettes = [
{
wall: material(0xe3c17e),
trim: material(0xf5e7c6),
shutter: material(0x367f75),
roof: material(0x8d5046),
accent: material(0xb84e43),
signBackground: "#3b6660",
signText: "#f7e8bd"
},
{
wall: material(0x79aa9e),
trim: material(0xf1dfb9),
shutter: material(0xd66a50),
roof: material(0x784f45),
accent: material(0xd4a44d),
signBackground: "#70473e",
signText: "#fff0c8"
},
{
wall: material(0xd86d58),
trim: material(0xf5dfbd),
shutter: material(0x28746c),
roof: material(0x73564b),
accent: material(0xd0a044),
signBackground: "#245e59",
signText: "#f8e7b9"
},
{
wall: material(0xdba3a5),
trim: material(0xf7e9cb),
shutter: material(0x467b8e),
roof: material(0x805348),
accent: material(0xc79246),
signBackground: "#536a7e",
signText: "#fff0cf"
},
{
wall: material(0x7c9caf),
trim: material(0xf2dfbd),
shutter: material(0xb85b4f),
roof: material(0x785047),
accent: material(0xd1a34b),
signBackground: "#775047",
signText: "#f9e7bd"
}
];
const signNames = [
["MELAKA HOUSE", "PERANAKAN SHOPHOUSE"],
["ISTANA", "KAMPONG GLAM"],
["KAMPONG GLAM", "CONSERVATION AREA"],
["PERANAKAN", "ARTS AND CRAFTS"],
["GALAXY", "SHOPHOUSE GALLERY"]
];
for (let i = 0; i < bayCount; i++) {
const x = (i - (bayCount - 1) / 2) * bayWidth;
const p = palettes[i];
const isCentral = i === 2;
// Upper-storey mass.
box(
bayWidth - 0.035, 3.52, 4.8,
x, 5.04, -2.4,
p.wall,
facadeGroup
);
// Recessed terrace roof behind the cornice.
box(
bayWidth - 0.08, 0.2, 4.86,
x, 6.88, -2.4,
p.roof,
facadeGroup
);
// Ground-floor side piers, leaving an actual open passage.
const pierWidth = bayWidth / 2 - openingRadius;
const pierOffset = openingRadius + pierWidth / 2;
box(
pierWidth, 3.18, 0.46,
x - pierOffset, 1.59, -0.02,
p.wall,
facadeGroup
);
box(
pierWidth, 3.18, 0.46,
x + pierOffset, 1.59, -0.02,
p.wall,
facadeGroup
);
// Spandrel above the semicircular opening.
const spandrelShape = new THREE.Shape();
spandrelShape.moveTo(-openingRadius, archSpring);
spandrelShape.lineTo(-openingRadius, 3.18);
spandrelShape.lineTo(openingRadius, 3.18);
spandrelShape.lineTo(openingRadius, archSpring);
for (let segment = 0; segment <= 16; segment++) {
const angle = segment / 16 * Math.PI;
spandrelShape.lineTo(
Math.cos(angle) * openingRadius,
archSpring + Math.sin(angle) * openingRadius
);
}
spandrelShape.closePath();
const spandrel = new THREE.Mesh(
new THREE.ShapeGeometry(spandrelShape),
p.wall
);
spandrel.position.set(x, 0, 0.018);
spandrel.castShadow = true;
spandrel.receiveShadow = true;
facadeGroup.add(spandrel);
// Arch ring and vertical jambs.
const arch = new THREE.Mesh(
new THREE.TorusGeometry(
openingRadius + 0.075,
0.105,
4,
16,
Math.PI
),
p.trim
);
arch.position.set(x, archSpring, 0.105);
arch.castShadow = true;
facadeGroup.add(arch);
box(
0.15, archSpring, 0.19,
x - openingRadius, archSpring / 2, 0.10,
p.trim,
facadeGroup
);
box(
0.15, archSpring, 0.19,
x + openingRadius, archSpring / 2, 0.10,
p.trim,
facadeGroup
);
box(
0.30, 0.32, 0.20,
x, archSpring + openingRadius + 0.04, 0.12,
p.accent,
facadeGroup
);
// Recess walls and floor make the opening read as a deep passage.
box(
bayWidth - 0.30, 3.12, 0.16,
x, 1.56, -4.08,
interiorMaterial,
facadeGroup
);
box(
0.14, 3.10, 3.75,
x - bayWidth / 2 + 0.07, 1.55, -2.15,
interiorMaterial,
facadeGroup
);
box(
0.14, 3.10, 3.75,
x + bayWidth / 2 - 0.07, 1.55, -2.15,
interiorMaterial,
facadeGroup
);
box(
bayWidth - 0.28, 0.05, 4.05,
x, 0.055, -2.05,
interiorFloorMaterial,
facadeGroup,
false
);
// A warm rear panel and pendant suggest occupied shop interiors.
box(
1.65, 0.82, 0.06,
x, 1.55, -3.96,
material(0xb48a57, {
emissive: 0x7f4d22,
emissiveIntensity: 0.22
}),
facadeGroup,
false
);
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 8, 6),
material(0xffd18b, {
emissive: 0xffad45,
emissiveIntensity: 1.25
})
);
lamp.position.set(x, 2.25, -2.55);
facadeGroup.add(lamp);
beamBetween(
[x, 3.02, -2.55],
[x, 2.30, -2.55],
0.012,
darkWoodMaterial,
facadeGroup
);
// Furniture is kept simple and recessed from the public passage.
if (isCentral) {
box(
2.25, 0.16, 0.40,
x, 0.68, -3.18,
p.trim,
facadeGroup
);
box(
0.15, 0.58, 0.34,
x - 0.90, 0.34, -3.18,
darkWoodMaterial,
facadeGroup
);
box(
0.15, 0.58, 0.34,
x + 0.90, 0.34, -3.18,
darkWoodMaterial,
facadeGroup
);
} else {
box(
1.15, 0.68, 0.58,
x + 0.72, 0.40, -3.10,
darkWoodMaterial,
facadeGroup
);
box(
0.76, 0.38, 0.64,
x - 0.72, 0.25, -3.14,
p.trim,
facadeGroup
);
for (let item = 0; item < 3; item++) {
cylinder(
0.09, 0.13, 0.28,
x - 0.92 + item * 0.20,
1.00,
-3.44,
item % 2 ? p.shutter : brassMaterial,
6,
facadeGroup
);
}
}
// String courses and upper pilasters.
box(
bayWidth - 0.04, 0.18, 0.19,
x, 3.29, 0.08,
p.trim,
facadeGroup
);
box(
bayWidth - 0.04, 0.15, 0.18,
x, 6.75, 0.08,
p.trim,
facadeGroup
);
box(
0.13, 2.55, 0.14,
x - 1.82, 5.0, 0.09,
p.trim,
facadeGroup
);
box(
0.13, 2.55, 0.14,
x + 1.82, 5.0, 0.09,
p.trim,
facadeGroup
);
// Shophouse signboard.
addSign(
signNames[i][0],
signNames[i][1],
x,
3.69,
2.58,
p,
facadeGroup
);
// Upper window recess.
box(
1.58, 1.78, 0.09,
x, 5.08, 0.055,
material(0x233b39),
facadeGroup,
false
);
// Window frame and mullions.
box(
0.09, 1.92, 0.18,
x - 0.83, 5.08, 0.12,
p.trim,
facadeGroup
);
box(
0.09, 1.92, 0.18,
x + 0.83, 5.08, 0.12,
p.trim,
facadeGroup
);
box(
1.74, 0.10, 0.18,
x, 4.15, 0.12,
p.trim,
facadeGroup
);
box(
1.74, 0.10, 0.18,
x, 6.01, 0.12,
p.trim,
facadeGroup
);
box(
0.065, 1.78, 0.16,
x, 5.08, 0.13,
p.trim,
facadeGroup
);
box(
1.60, 0.055, 0.15,
x, 5.02, 0.13,
p.trim,
facadeGroup
);
// Sill.
box(
1.96, 0.13, 0.34,
x, 4.05, 0.13,
p.trim,
facadeGroup
);
// Open louvered shutters.
for (const side of [-1, 1]) {
const shutter = new THREE.Group();
shutter.position.set(x + side * 0.78, 5.08, 0.18);
shutter.rotation.y = -side * 0.23;
facadeGroup.add(shutter);
box(
0.67, 1.86, 0.09,
side * 0.36, 0, 0,
p.shutter,
shutter
);
for (let slat = 0; slat < 10; slat++) {
box(
0.58, 0.035, 0.055,
side * 0.36,
-0.80 + slat * 0.175,
0.065,
p.trim,
shutter
);
}
}
// Central bay gets a small balcony, emphasizing the reference bay.
if (isCentral) {
box(
2.18, 0.11, 0.56,
x, 3.98, 0.18,
p.trim,
facadeGroup
);
box(
2.12, 0.06, 0.06,
x, 4.45, 0.46,
p.shutter,
facadeGroup
);
for (let baluster = 0; baluster < 8; baluster++) {
box(
0.045, 0.46, 0.045,
x - 0.92 + baluster * 0.263,
4.23,
0.46,
p.shutter,
facadeGroup
);
}
box(
0.06, 0.46, 0.06,
x - 1.02, 4.23, 0.46,
p.shutter,
facadeGroup
);
box(
0.06, 0.46, 0.06,
x + 1.02, 4.23, 0.46,
p.shutter,
facadeGroup
);
}
// Small triangular pediment.
const pedimentShape = new THREE.Shape();
pedimentShape.moveTo(-0.72, 0);
pedimentShape.lineTo(0.72, 0);
pedimentShape.lineTo(0, 0.38);
pedimentShape.closePath();
const pediment = new THREE.Mesh(
new THREE.ShapeGeometry(pedimentShape),
p.accent
);
pediment.position.set(x, 6.10, 0.14);
pediment.castShadow = true;
facadeGroup.add(pediment);
// Rosette and relief ornaments.
const rosette = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.15, 0.07, 10),
brassMaterial
);
rosette.rotation.x = Math.PI / 2;
rosette.position.set(x, 6.35, 0.14);
rosette.castShadow = true;
facadeGroup.add(rosette);
for (const side of [-1, 1]) {
const diamond = octahedron(
0.13,
x + side * 1.30,
4.54,
0.13,
p.accent,
facadeGroup
);
diamond.scale.set(1, 1.45, 0.42);
}
// Fine cornice trim.
box(
bayWidth + 0.02, 0.13, 0.30,
x, 6.91, 0.10,
p.trim,
facadeGroup
);
}
// ---------------------------------------------------------------------
// Continuous five-foot-way arcade columns and roof
// ---------------------------------------------------------------------
const arcadeTrim = material(0xf0dfbd);
const arcadeUnderside = material(0x8f7760);
const roofEdge = material(0x805247);
for (let columnIndex = 0; columnIndex <= bayCount; columnIndex++) {
const x = -buildingWidth / 2 + columnIndex * bayWidth;
box(
0.50, 0.18, 0.50,
x, 0.15, 1.82,
arcadeTrim,
facadeGroup
);
cylinder(
0.145, 0.18, 2.56,
x, 1.48, 1.82,
arcadeTrim,
8,
facadeGroup
);
box(
0.44, 0.18, 0.44,
x, 2.82, 1.82,
arcadeTrim,
facadeGroup
);
// Low-poly diagonal braces support the covered walkway.
beamBetween(
[x, 2.58, 1.82],
[x, 3.10, 0.32],
0.065,
arcadeTrim,
facadeGroup
);
beamBetween(
[x, 2.58, 1.82],
[x, 3.10, 2.02],
0.055,
arcadeTrim,
facadeGroup
);
}
// Covered walkway roof.
box(
buildingWidth + 0.55, 0.21, 2.18,
0, 3.23, 1.0,
roofEdge,
facadeGroup
);
box(
buildingWidth + 0.35, 0.10, 2.02,
0, 3.085, 1.0,
arcadeUnderside,
facadeGroup
);
box(
buildingWidth + 0.60, 0.31, 0.18,
0, 3.23, 0.05,
arcadeTrim,
facadeGroup
);
// Decorative brackets repeated along the roof fascia.
for (let x = -9.8; x <= 9.8; x += 0.65) {
box(
0.09, 0.20, 0.10,
x, 3.02, 0.10,
brassMaterial,
facadeGroup
);
}
// ---------------------------------------------------------------------
// Street furniture and tropical planting
// ---------------------------------------------------------------------
function addPlanter(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.05, z);
group.scale.setScalar(scale);
scene.add(group);
const planterMaterial = material(0xb7654f);
const soilMaterial = material(0x40352a);
const leafMaterials = [
material(0x416d4d),
material(0x527c55),
material(0x315f45)
];
box(
1.20, 0.58, 1.10,
0, 0.29, 0,
planterMaterial,
group
);
box(
1.08, 0.05, 0.98,
0, 0.60, 0,
soilMaterial,
group
);
box(
1.31, 0.12, 1.20,
0, 0.57, 0,
material(0xc9795d),
group
);
for (let leafIndex = 0; leafIndex < 9; leafIndex++) {
const angle = leafIndex / 9 * Math.PI * 2;
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(
0.20 + (leafIndex % 2) * 0.035,
0.88 + (leafIndex % 3) * 0.12,
4
),
leafMaterials[leafIndex % leafMaterials.length]
);
leaf.position.set(
Math.cos(angle) * 0.24,
0.94,
Math.sin(angle) * 0.24
);
leaf.rotation.z = -Math.cos(angle) * 0.68;
leaf.rotation.x = Math.sin(angle) * 0.68;
leaf.castShadow = true;
group.add(leaf);
}
}
addPlanter(-9.3, 4.0, 1.0);
addPlanter(9.0, 4.3, 1.08);
addPlanter(-5.7, 7.7, 0.76);
// Traditional-style streetlamp.
const lampMetal = material(0x30413d);
const lampGlass = material(0xffd28b, {
emissive: 0xffa33d,
emissiveIntensity: 1.1
});
cylinder(
0.075, 0.10, 4.6,
-11.7, 2.3, 5.1,
lampMetal,
8,
scene
);
cylinder(
0.23, 0.28, 0.18,
-11.7, 0.12, 5.1,
lampMetal,
8,
scene
);
box(
0.38, 0.54, 0.38,
-11.7, 4.72, 5.1,
lampGlass,
scene
);
const lampCap = new THREE.Mesh(
new THREE.ConeGeometry(0.38, 0.28, 4),
lampMetal
);
lampCap.position.set(-11.7, 5.10, 5.1);
lampCap.rotation.y = Math.PI / 4;
lampCap.castShadow = true;
scene.add(lampCap);
// Bollards reinforce the edge of the pedestrian zone.
for (const x of [-6.2, 0, 6.2]) {
cylinder(
0.07, 0.10, 0.80,
x, 0.43, 8.55,
lampMetal,
8,
scene
);
cylinder(
0.12, 0.12, 0.10,
x, 0.86, 8.55,
brassMaterial,
8,
scene
);
}
// ---------------------------------------------------------------------
// Simple low-poly pedestrians for scale
// ---------------------------------------------------------------------
function addPerson(x, z, shirtColor, trouserColor, rotation = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
const shirt = material(shirtColor);
const trousers = material(trouserColor);
const skin = material(0xb98462);
const hair = material(0x302822);
cylinder(
0.17, 0.22, 0.68,
0, 1.10, 0,
shirt,
6,
group
);
cylinder(
0.075, 0.085, 0.68,
-0.11, 0.48, 0,
trousers,
6,
group
);
cylinder(
0.075, 0.085, 0.68,
0.11, 0.48, 0,
trousers,
6,
group
);
box(
0.16, 0.10, 0.30,
-0.11, 0.10, 0.06,
material(0x332f2a),
group
);
box(
0.16, 0.10, 0.30,
0.11, 0.10, 0.06,
material(0x332f2a),
group
);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.22, 1),
skin
);
head.position.y = 1.68;
head.castShadow = true;
group.add(head);
const hairMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.225, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2),
hair
);
hairMesh.position.y = 1.73;
hairMesh.castShadow = true;
group.add(hairMesh);
beamBetween(
[-0.19, 1.34, 0],
[-0.25, 0.85, 0.06],
0.065,
shirt,
group
);
beamBetween(
[0.19, 1.34, 0],
[0.26, 0.88, 0.03],
0.065,
shirt,
group
);
}
addPerson(1.05, 1.08, 0xe8d3ae, 0x385b65, -0.55, 0.96);
addPerson(-3.35, 5.15, 0xc66c55, 0x40514d, 0.70, 1.02);
addPerson(5.10, 6.25, 0x6d9d8d, 0x5b4d42, -1.20, 0.90);
// ---------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pinch, keyboard, and reset
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 3.05, 0.15);
const initialCamera = {
theta: 0.30,
phi: 1.16,
distance: window.innerWidth < 700 ? 27 : 20.5
};
const desired = { ...initialCamera };
const current = { ...initialCamera };
const pointers = new Map();
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
let movedWhilePressed = false;
function clampCamera() {
desired.phi = THREE.MathUtils.clamp(desired.phi, 0.28, 1.43);
desired.distance = THREE.MathUtils.clamp(desired.distance, 10, 42);
}
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
});
movedWhilePressed = false;
if (pointers.size === 1) {
previousX = event.clientX;
previousY = event.clientY;
}
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 dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 1) {
movedWhilePressed = true;
}
desired.theta -= dx * 0.006;
desired.phi -= dy * 0.005;
clampCamera();
}
if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
desired.distance *= previousPinchDistance / distance;
clampCamera();
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
previousX = remaining.x;
previousY = remaining.y;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desired.distance *= Math.exp(event.deltaY * 0.001);
clampCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
Object.assign(desired, initialCamera);
});
window.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
desired.theta += 0.10;
break;
case "ArrowRight":
desired.theta -= 0.10;
break;
case "ArrowUp":
desired.phi -= 0.08;
break;
case "ArrowDown":
desired.phi += 0.08;
break;
case "+":
case "=":
desired.distance -= 1.2;
break;
case "-":
case "_":
desired.distance += 1.2;
break;
case "r":
case "R":
Object.assign(desired, initialCamera);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
clampCamera();
}
});
function updateCamera(deltaTime) {
const easing = 1 - Math.exp(-8 * deltaTime);
current.theta += (desired.theta - current.theta) * easing;
current.phi += (desired.phi - current.phi) * easing;
current.distance += (desired.distance - current.distance) * easing;
const spherical = new THREE.Spherical(
current.distance,
current.phi,
current.theta
);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const deltaTime = Math.min(clock.getDelta(), 0.05);
updateCamera(deltaTime);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("done");
}
});
</script>
</body>
</html>
```