Prompt specification
Build or customize the Three.js 3D scene "Hanoi tube-house frontage and recessed doorway" 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: Hanoi tube-house frontage and recessed doorway
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hanoi-tube-house-frontage-and-recessed-doorway-x2977
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Hanoi's Old Quarter. Build a referenced narrow-fronted facade fragment with upper balcony and deep doorway. Show the contrast between limited street frontage and suggested interior depth. Voxel style.
Working Three.js Starter (hanoi-tube-house-frontage-and-recessed-doorway-x2977):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hanoi Old Quarter — Voxel Architecture</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cdbb9d;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 2;
width: min(340px, calc(100vw - 48px));
padding: 18px 20px;
color: #fff7e8;
background: rgba(34, 31, 25, 0.78);
border: 1px solid rgba(255, 247, 232, 0.22);
border-radius: 4px;
box-shadow: 0 12px 38px rgba(39, 29, 17, 0.18);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #e9b86c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 5vw, 46px);
line-height: 0.95;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 0;
color: rgba(255, 247, 232, 0.76);
font-size: 12px;
line-height: 1.55;
}
.subtitle strong {
color: #fff7e8;
font-weight: 650;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 3;
display: flex;
align-items: center;
gap: 12px;
padding: 9px 11px;
color: rgba(255, 247, 232, 0.88);
background: rgba(34, 31, 25, 0.76);
border: 1px solid rgba(255, 247, 232, 0.18);
border-radius: 4px;
backdrop-filter: blur(10px);
user-select: none;
}
.controls span {
font-size: 11px;
letter-spacing: 0.03em;
}
button {
padding: 7px 10px;
color: #fff7e8;
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 3px;
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
background: rgba(233, 184, 108, 0.18);
border-color: rgba(233, 184, 108, 0.55);
}
.vertical-note {
position: fixed;
left: 22px;
bottom: 22px;
z-index: 2;
max-width: 220px;
padding-left: 12px;
color: rgba(48, 39, 28, 0.74);
border-left: 2px solid rgba(111, 76, 35, 0.5);
font-size: 10px;
line-height: 1.5;
letter-spacing: 0.05em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 640px) {
.title-card {
top: 14px;
left: 14px;
padding: 14px 16px;
}
.controls {
right: 14px;
bottom: 14px;
}
.vertical-note {
display: none;
}
}
</style>
</head>
<body>
<div class="title-card">
<div class="eyebrow">Architectural voxel study</div>
<h1>HÀ NỘI</h1>
<p class="subtitle">
<strong>Old Quarter / narrow-fronted tube house</strong><br>
A restrained street elevation conceals a deep, illuminated interior.
</p>
</div>
<div class="vertical-note">
Drag to orbit · Scroll to zoom · Double-click to reset
</div>
<div class="controls">
<span>Drag / scroll to explore</span>
<button id="reset" type="button">Reset view</button>
</div>
<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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xcdbb9d);
scene.fog = new THREE.Fog(0xcdbb9d, 21, 42);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const clock = new THREE.Clock();
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
let seed = 1954;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function material(color, roughness = 0.88, metalness = 0, extras = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true,
...extras
});
}
const M = {
hero: material(0xc59a58),
heroLight: material(0xd2aa68),
heroDark: material(0x9f7946),
trim: material(0x765335),
darkWood: material(0x4b3022),
iron: material(0x292a27, 0.72, 0.12),
glass: material(0x283d3b, 0.38, 0.08),
interior: material(0x62452f),
interiorDark: material(0x35271f),
warmFloor: material(0x997044),
teal: material(0x6c8c83),
tealDark: material(0x45645e),
coral: material(0xb66f58),
paleBlue: material(0x809b9c),
cream: material(0xe2c99c),
brick: material(0x9a5139),
terracotta: material(0xa75432),
roofDark: material(0x713a2b),
plasterDark: material(0x937552),
stone: material(0x77776e),
asphalt: material(0x756d60),
black: material(0x242321),
scooter: material(0x3b7775),
scooterRed: material(0xa54334),
green: material(0x4e6b3e),
greenLight: material(0x70834d),
soil: material(0x49382a),
skin: material(0xc18a61),
shirtBlue: material(0x385a6a),
shirtRed: material(0xa54e3d),
warmGlow: material(0xffb85e, 0.6, 0, {
emissive: 0xff7c26,
emissiveIntensity: 1.8
}),
paper: material(0xe8ddc5),
muted: material(0x9d927e)
};
function box(
parent,
w,
h,
d,
x,
y,
z,
mat,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function makeSignTexture(text, background, foreground, vertical = false) {
const canvas = document.createElement("canvas");
canvas.width = vertical ? 256 : 1024;
canvas.height = vertical ? 1024 : 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.55;
ctx.lineWidth = vertical ? 12 : 10;
ctx.strokeRect(
ctx.lineWidth / 2,
ctx.lineWidth / 2,
canvas.width - ctx.lineWidth,
canvas.height - ctx.lineWidth
);
ctx.globalAlpha = 1;
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
const lines = text.split("\n");
if (vertical) {
const lineHeight = canvas.height / (lines.length + 1);
lines.forEach((line, i) => {
const fontSize = Math.min(150, lineHeight * 0.68);
ctx.font = `800 ${fontSize}px Arial, sans-serif`;
ctx.fillText(
line,
canvas.width / 2,
lineHeight * (i + 1),
canvas.width * 0.82
);
});
} else {
const lineHeight = canvas.height / (lines.length + 1);
lines.forEach((line, i) => {
const fontSize = Math.min(
108,
(canvas.height / lines.length) * 0.72
);
ctx.font = `800 ${fontSize}px Arial, sans-serif`;
ctx.fillText(
line,
canvas.width / 2,
lineHeight * (i + 1),
canvas.width * 0.86
);
});
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function addSign(
parent,
text,
x,
y,
z,
w,
h,
background = "#173d3b",
foreground = "#f5dfb1",
vertical = false
) {
const backing = box(
parent,
w + 0.12,
h + 0.12,
0.14,
x,
y,
z,
M.darkWood
);
const texture = makeSignTexture(
text,
background,
foreground,
vertical
);
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
sign.position.set(x, y, z - 0.078);
sign.rotation.y = Math.PI;
parent.add(sign);
return backing;
}
function addWindow(
parent,
x,
y,
z,
w = 0.9,
h = 1.2,
shutters = false
) {
box(parent, w, h, 0.07, x, y, z, M.glass, false, true);
box(parent, w + 0.18, 0.09, 0.11, x, y + h / 2 + 0.04, z - 0.08, M.trim);
box(parent, w + 0.18, 0.09, 0.11, x, y - h / 2 - 0.04, z - 0.08, M.trim);
box(parent, 0.09, h + 0.14, 0.11, x - w / 2 - 0.04, y, z - 0.08, M.trim);
box(parent, 0.09, h + 0.14, 0.11, x + w / 2 + 0.04, y, z - 0.08, M.trim);
box(parent, 0.055, h, 0.09, x, y, z - 0.105, M.darkWood);
if (shutters) {
box(
parent,
w * 0.48,
h,
0.09,
x - w * 0.74,
y,
z - 0.12,
M.tealDark
);
box(
parent,
w * 0.48,
h,
0.09,
x + w * 0.74,
y,
z - 0.12,
M.tealDark
);
}
}
function addAwning(parent, x, y, z, width, color) {
const pieces = 9;
const stripeWidth = width / pieces;
for (let i = 0; i < pieces; i++) {
const stripe = box(
parent,
stripeWidth + 0.015,
0.09,
1.05,
x - width / 2 + stripeWidth * (i + 0.5),
y - i * 0.025,
z - 0.42,
i % 2 === 0 ? M.cream : color
);
stripe.rotation.x = -0.12;
}
box(parent, width + 0.12, 0.18, 0.12, x, y + 0.05, z - 0.92, M.trim);
}
function addPlanter(parent, x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
box(group, 0.52, 0.48, 0.52, 0, 0.24, 0, M.brick);
box(group, 0.58, 0.10, 0.58, 0, 0.49, 0, M.trim);
box(group, 0.43, 0.06, 0.43, 0, 0.54, 0, M.soil);
box(group, 0.14, 0.85, 0.14, -0.11, 0.85, 0, M.darkWood);
box(group, 0.42, 0.30, 0.28, 0.10, 0.91, 0.02, M.green);
box(group, 0.34, 0.26, 0.34, -0.08, 1.12, 0.01, M.greenLight);
box(group, 0.28, 0.24, 0.24, 0.14, 1.28, 0.02, M.green);
return group;
}
function addLantern(parent, x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
parent.add(group);
box(group, 0.05, 0.35, 0.05, 0, 0.22, 0, M.iron);
box(group, 0.34, 0.48, 0.34, 0, 0, 0, M.warmGlow);
box(group, 0.42, 0.07, 0.42, 0, 0.27, 0, M.darkWood);
box(group, 0.42, 0.07, 0.42, 0, -0.27, 0, M.darkWood);
box(group, 0.38, 0.045, 0.38, 0, 0, 0, M.brick);
return group;
}
function addPerson(parent, x, z, shirt, rotation = 0, scale = 1) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.rotation.y = rotation;
person.scale.setScalar(scale);
parent.add(person);
box(person, 0.19, 0.55, 0.22, -0.13, 0.28, 0, M.iron);
box(person, 0.19, 0.55, 0.22, 0.13, 0.28, 0, M.iron);
box(person, 0.56, 0.67, 0.34, 0, 0.88, 0, shirt);
box(person, 0.15, 0.55, 0.16, -0.36, 0.83, 0, shirt);
box(person, 0.15, 0.55, 0.16, 0.36, 0.83, 0, shirt);
box(person, 0.34, 0.37, 0.34, 0, 1.40, 0, M.skin);
box(person, 0.39, 0.08, 0.39, 0, 1.59, 0, M.darkWood);
}
function addScooter(parent, x, z, rotation, bodyMaterial) {
const scooter = new THREE.Group();
scooter.position.set(x, 0, z);
scooter.rotation.y = rotation;
parent.add(scooter);
box(scooter, 0.24, 0.56, 0.56, 0, 0.34, -0.62, M.black);
box(scooter, 0.24, 0.56, 0.56, 0, 0.34, 0.65, M.black);
box(scooter, 0.27, 0.12, 0.12, 0, 0.34, -0.62, M.stone);
box(scooter, 0.27, 0.12, 0.12, 0, 0.34, 0.65, M.stone);
box(scooter, 0.42, 0.38, 1.05, 0, 0.64, -0.10, bodyMaterial);
box(scooter, 0.52, 0.20, 0.70, 0, 0.83, -0.30, M.black);
box(scooter, 0.27, 0.76, 0.27, 0, 1.02, 0.48, bodyMaterial);
box(scooter, 0.78, 0.09, 0.11, 0, 1.34, 0.48, M.iron);
box(scooter, 0.22, 0.18, 0.12, 0, 1.16, 0.65, M.warmGlow);
box(scooter, 0.13, 0.13, 0.24, 0, 1.52, 0.47, M.iron);
box(scooter, 0.35, 0.25, 0.16, 0, 1.64, 0.47, M.iron);
return scooter;
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffefd4, 0x686457, 1.65));
const sun = new THREE.DirectionalLight(0xffd49a, 3.4);
sun.position.set(-7, 13, -8);
sun.target.position.set(0, 2.6, 3);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00025;
scene.add(sun);
scene.add(sun.target);
const rim = new THREE.DirectionalLight(0xb9d1d0, 0.75);
rim.position.set(9, 8, 12);
scene.add(rim);
// -------------------------------------------------------------------------
// Diorama base and street paving
// -------------------------------------------------------------------------
box(scene, 29, 0.48, 27, 0, -0.30, 3.5, M.asphalt);
const paverGeometry = new THREE.BoxGeometry(0.76, 0.09, 0.45);
const paverMaterial = material(0xffffff, 1);
const columns = 30;
const rows = 17;
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
columns * rows
);
pavers.castShadow = false;
pavers.receiveShadow = true;
const dummy = new THREE.Object3D();
const paverColors = [
new THREE.Color(0x80766a),
new THREE.Color(0x8b8072),
new THREE.Color(0x746c62),
new THREE.Color(0x918578),
new THREE.Color(0x7a746c)
];
let paverIndex = 0;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
dummy.position.set(
(col - columns / 2 + 0.5) * 0.79 + (row % 2) * 0.12,
0.005 + random() * 0.012,
-7.65 + row * 0.48
);
dummy.rotation.set(
0,
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.015
);
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
pavers.setColorAt(
paverIndex,
paverColors[Math.floor(random() * paverColors.length)]
);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
if (pavers.instanceColor) pavers.instanceColor.needsUpdate = true;
scene.add(pavers);
box(scene, 26, 0.07, 0.18, 0, 0.02, -1.15, M.iron);
box(scene, 26, 0.09, 0.26, 0, 0.03, -0.18, M.stone);
// -------------------------------------------------------------------------
// Hero building: a narrow frontage with an eight-metre-deep interior
// -------------------------------------------------------------------------
const hero = new THREE.Group();
scene.add(hero);
// Foundation and long shell.
box(hero, 4.55, 0.26, 8.85, 0, 0.10, 4.35, M.stone);
box(hero, 0.24, 8.15, 8.70, -2.10, 4.08, 4.35, M.hero);
box(hero, 0.24, 8.15, 8.70, 2.10, 4.08, 4.35, M.heroDark);
box(hero, 4.25, 8.15, 0.24, 0, 4.08, 8.72, M.plasterDark);
box(hero, 4.45, 0.22, 8.85, 0, 3.25, 4.35, M.heroLight);
box(hero, 4.45, 0.22, 8.85, 0, 6.35, 4.35, M.heroLight);
// Ground-floor façade pieces, leaving a real entrance void.
box(hero, 1.30, 3.05, 0.34, -1.47, 1.55, 0, M.hero);
box(hero, 1.30, 3.05, 0.34, 1.47, 1.55, 0, M.hero);
box(hero, 1.64, 0.57, 0.34, 0, 2.91, 0, M.heroLight);
// Deep stone doorway reveals.
box(hero, 0.17, 2.65, 1.22, -0.75, 1.32, 0.47, M.stone);
box(hero, 0.17, 2.65, 1.22, 0.75, 1.32, 0.47, M.stone);
box(hero, 1.66, 0.17, 1.22, 0, 2.66, 0.47, M.stone);
box(hero, 1.55, 0.08, 1.28, 0, 0.10, 0.46, M.stone);
// Wooden front frame.
box(hero, 0.12, 2.53, 0.16, -0.69, 1.31, -0.18, M.darkWood);
box(hero, 0.12, 2.53, 0.16, 0.69, 1.31, -0.18, M.darkWood);
box(hero, 1.51, 0.13, 0.17, 0, 2.57, -0.18, M.darkWood);
// The door swings inward, making the depth immediately legible.
const door = new THREE.Group();
door.position.set(-0.68, 1.30, 0.12);
door.rotation.y = -1.18;
hero.add(door);
box(door, 0.74, 2.34, 0.10, 0.37, 0, 0, M.darkWood);
box(door, 0.49, 1.28, 0.025, 0.37, 0.10, -0.065, M.trim);
box(door, 0.49, 0.45, 0.025, 0.37, -0.68, -0.065, M.trim);
box(door, 0.07, 0.07, 0.12, 0.65, 0, -0.08, M.stone);
// Upper facade with a central balcony-door opening.
box(hero, 4.22, 0.43, 0.36, 0, 3.48, 0, M.heroLight);
box(hero, 1.02, 2.55, 0.36, -1.60, 4.93, 0, M.hero);
box(hero, 1.02, 2.55, 0.36, 1.60, 4.93, 0, M.hero);
box(hero, 2.20, 0.31, 0.36, 0, 6.18, 0, M.heroLight);
// Recessed balcony doors.
box(hero, 1.96, 2.22, 0.07, 0, 4.91, 0.14, M.glass);
box(hero, 0.10, 2.30, 0.12, -0.99, 4.91, 0.08, M.darkWood);
box(hero, 0.10, 2.30, 0.12, 0.99, 4.91, 0.08, M.darkWood);
box(hero, 2.08, 0.11, 0.12, 0, 6.02, 0.08, M.darkWood);
box(hero, 0.08, 2.23, 0.11, 0, 4.91, 0.075, M.darkWood);
// Third storey.
box(hero, 4.22, 1.63, 0.36, 0, 7.22, 0, M.heroLight);
addWindow(hero, -1.03, 7.20, -0.205, 1.00, 1.12, false);
addWindow(hero, 1.03, 7.20, -0.205, 1.00, 1.12, false);
// Ground-level side display windows.
addWindow(hero, -1.47, 1.52, -0.205, 0.90, 1.60, false);
addWindow(hero, 1.47, 1.52, -0.205, 0.90, 1.60, false);
// Balcony slab and voxel railing.
box(hero, 3.66, 0.18, 1.28, 0, 3.73, -0.56, M.darkWood);
box(hero, 3.72, 0.07, 1.34, 0, 3.61, -0.56, M.trim);
for (let i = 0; i < 9; i++) {
const px = -1.60 + i * 0.40;
box(hero, 0.075, 0.88, 0.075, px, 4.25, -1.14, M.iron);
}
box(hero, 3.72, 0.10, 0.10, 0, 4.71, -1.14, M.iron);
box(hero, 3.72, 0.08, 0.08, 0, 3.91, -1.14, M.iron);
for (const side of [-1, 1]) {
box(hero, 0.08, 0.88, 0.08, side * 1.76, 4.25, -0.56, M.iron);
box(hero, 0.10, 0.10, 1.18, side * 1.76, 4.71, -0.56, M.iron);
}
addPlanter(hero, -1.33, 3.82, -0.60, 0.68);
addPlanter(hero, 1.33, 3.82, -0.60, 0.68);
// Shallow voxel gable roof with terracotta slopes.
const leftRoof = box(
hero,
2.47,
0.18,
8.92,
-1.13,
8.22,
4.36,
M.terracotta
);
leftRoof.rotation.z = 0.145;
const rightRoof = box(
hero,
2.47,
0.18,
8.92,
1.13,
8.22,
4.36,
M.brick
);
rightRoof.rotation.z = -0.145;
box(hero, 0.25, 0.20, 9.00, 0, 8.43, 4.36, M.roofDark);
for (let i = 0; i < 15; i++) {
box(
hero,
0.26,
0.10,
0.19,
-2.28 + i * 0.325,
8.02,
-0.10,
M.roofDark
);
}
// Visible side elevation establishes the building's long depth.
const sideWindowGroup = new THREE.Group();
sideWindowGroup.rotation.y = -Math.PI / 2;
hero.add(sideWindowGroup);
addWindow(sideWindowGroup, 0, 0, 0, 1.03, 1.22, false);
sideWindowGroup.position.set(2.235, 4.72, 2.60);
const sideWindowGroup2 = new THREE.Group();
sideWindowGroup2.rotation.y = -Math.PI / 2;
hero.add(sideWindowGroup2);
addWindow(sideWindowGroup2, 0, 0, 0, 1.03, 1.22, false);
sideWindowGroup2.position.set(2.235, 4.72, 5.55);
box(hero, 0.12, 7.65, 0.12, 2.32, 3.88, -0.05, M.iron);
box(hero, 0.12, 0.48, 0.15, 2.37, 4.92, 2.60, M.stone);
box(hero, 0.85, 0.09, 0.12, 2.46, 4.80, 2.60, M.iron);
// Blocky plaster wear and stains.
for (let i = 0; i < 34; i++) {
const wx = -1.96 + random() * 3.92;
const wy = 0.45 + random() * 7.25;
const ww = 0.07 + random() * 0.32;
const wh = 0.05 + random() * 0.23;
if (wy < 2.7 && Math.abs(wx) < 0.72) continue;
box(
hero,
ww,
wh,
0.018,
wx,
wy,
-0.181,
i % 3 === 0 ? M.plasterDark : M.heroDark,
false,
false
);
}
// Main signage and address.
addSign(
hero,
"PHỞ HÀ NỘI",
0,
2.96,
-0.29,
1.72,
0.42,
"#193f3c",
"#f2d79f"
);
addSign(
hero,
"24",
-0.98,
2.43,
-0.28,
0.25,
0.25,
"#244d4b",
"#f5e7c8"
);
// -------------------------------------------------------------------------
// Deep interior: a long, narrow, warm passage
// -------------------------------------------------------------------------
box(hero, 3.90, 0.12, 8.45, 0, 0.17, 4.45, M.interior);
box(hero, 0.18, 2.72, 8.30, -0.82, 1.50, 4.55, M.interiorDark);
box(hero, 0.18, 2.72, 8.30, 0.82, 1.50, 4.55, M.interiorDark);
box(hero, 1.80, 0.15, 8.35, 0, 2.87, 4.55, M.interiorDark);
// Floor divisions lead the eye toward the back of the house.
for (let i = 0; i < 12; i++) {
box(
hero,
1.45,
0.025,
0.045,
0,
0.245,
0.70 + i * 0.66,
M.darkWood,
false,
false
);
}
box(hero, 0.52, 0.58, 2.50, 0.52, 0.54, 5.45, M.trim);
box(hero, 0.62, 0.13, 2.65, 0.52, 0.88, 5.45, M.darkWood);
// Rear room, shelving, and a glowing service opening.
box(hero, 1.34, 2.35, 0.06, 0, 1.46, 8.54, M.warmGlow, false, false);
box(hero, 0.58, 1.90, 0.32, -0.49, 1.35, 8.30, M.darkWood);
box(hero, 0.58, 1.90, 0.32, 0.49, 1.35, 8.30, M.darkWood);
for (let i = 0; i < 4; i++) {
box(hero, 0.42, 0.06, 0.12, -0.49, 0.63 + i * 0.42, 8.10, M.trim);
box(hero, 0.42, 0.06, 0.12, 0.49, 0.63 + i * 0.42, 8.10, M.trim);
}
addLantern(hero, 0, 2.44, 1.55, 0.62);
addLantern(hero, 0, 2.44, 4.45, 0.62);
addLantern(hero, 0, 2.44, 7.35, 0.62);
const interiorLights = [];
[1.45, 4.40, 7.20].forEach((z, i) => {
const light = new THREE.PointLight(0xff8a3c, 23, 4.7, 2);
light.position.set(0, 2.35, z);
light.userData.baseIntensity = 23;
light.userData.phase = i * 1.7;
hero.add(light);
interiorLights.push(light);
});
// -------------------------------------------------------------------------
// Neighboring narrow-fronted Old Quarter houses
// -------------------------------------------------------------------------
function makeNeighbor({
x,
front,
width,
height,
depth,
color,
darkColor,
sign,
verticalSign,
balcony
}) {
const g = new THREE.Group();
g.position.set(x, 0, front);
scene.add(g);
box(g, width, height, depth, 0, height / 2, depth / 2, color);
box(g, width + 0.12, 0.22, depth + 0.14, 0, 3.05, depth / 2, darkColor);
box(g, width + 0.12, 0.20, depth + 0.14, 0, 6.05, depth / 2, darkColor);
addWindow(g, -width * 0.25, 1.55, -0.05, 0.86, 1.65, true);
addWindow(g, width * 0.25, 1.55, -0.05, 0.86, 1.65, true);
const rows = height > 8 ? [4.25, 7.10] : [4.25];
rows.forEach((y) => {
addWindow(g, -width * 0.25, y, -0.05, 0.88, 1.18, true);
addWindow(g, width * 0.25, y, -0.05, 0.88, 1.18, true);
});
if (height > 8.5) {
addWindow(g, 0, 8.30, -0.05, 0.78, 0.95, false);
}
if (balcony) {
box(g, width * 0.82, 0.16, 1.08, 0, 3.30, -0.48, M.darkWood);
for (let i = 0; i < 7; i++) {
box(
g,
0.065,
0.75,
0.065,
-width * 0.33 + i * (width * 0.11),
3.72,
-0.94,
M.iron
);
}
box(g, width * 0.85, 0.08, 0.08, 0, 4.10, -0.94, M.iron);
}
if (sign) {
addSign(
g,
sign,
0,
2.72,
-0.28,
width * 0.62,
0.54,
darkColor === M.tealDark ? "#244f4b" : "#6f332b",
"#f7dfae"
);
}
if (verticalSign) {
addSign(
g,
verticalSign,
-width / 2 - 0.20,
5.00,
-0.27,
0.53,
2.52,
"#71382c",
"#f4d79f",
true
);
}
// Flat, stepped roof.
box(g, width + 0.16, 0.22, depth + 0.12, 0, height + 0.08, depth / 2, M.roofDark);
box(g, width * 0.65, 0.16, depth * 0.68, 0, height + 0.25, depth / 2, M.brick);
// Wall patches.
for (let i = 0; i < 18; i++) {
const px = -width / 2 + random() * width;
const py = 0.35 + random() * (height - 0.8);
box(
g,
0.08 + random() * 0.28,
0.05 + random() * 0.18,
0.015,
px,
py,
-0.018,
i % 2 ? darkColor : M.plasterDark,
false,
false
);
}
return g;
}
makeNeighbor({
x: -4.85,
front: 0.30,
width: 4.35,
height: 9.25,
depth: 8.20,
color: M.teal,
darkColor: M.tealDark,
sign: "CÀ PHÊ",
verticalSign: "TRÀ\nCHANH",
balcony: true
});
makeNeighbor({
x: 4.85,
front: 2.55,
width: 4.25,
height: 7.45,
depth: 7.20,
color: M.coral,
darkColor: M.brick,
sign: "BÚN CHẢ",
verticalSign: "PHỞ\nHÀN",
balcony: false
});
// Setback house at the end of the lane.
makeNeighbor({
x: -10.0,
front: 5.0,
width: 4.4,
height: 8.0,
depth: 7.5,
color: M.paleBlue,
darkColor: M.stone,
sign: "BÁNH MÌ",
verticalSign: null,
balcony: true
});
// Background blocks form a dense urban wall.
const backgroundColors = [
material(0x9d8c74),
material(0x8d9382),
material(0xa9856e),
material(0x839295)
];
for (let i = 0; i < 7; i++) {
const bg = new THREE.Group();
bg.position.set(-13 + i * 4.3, 0, 11.5 + (i % 2) * 1.1);
scene.add(bg);
const h = 6.8 + random() * 3.2;
box(bg, 4.0, h, 4.5, 0, h / 2, 0, backgroundColors[i % 4]);
box(bg, 4.12, 0.18, 4.62, 0, h, 0, M.roofDark);
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 2; col++) {
box(
bg,
0.42,
0.55,
0.03,
-0.85 + col * 1.7,
1.7 + row * 1.7,
-2.27,
M.glass,
false,
false
);
}
}
}
// -------------------------------------------------------------------------
// Street life and architectural clutter
// -------------------------------------------------------------------------
addAwning(scene, -4.70, 2.82, -0.02, 3.60, M.brick);
addAwning(scene, 4.85, 2.80, 2.48, 3.40, M.tealDark);
addLantern(scene, -2.62, 4.78, -0.52, 1.0);
addLantern(scene, 2.55, 4.63, 2.12, 0.90);
// Sign fixed between the hero building and its neighbor.
addSign(
scene,
"NEM\nLỰC",
-2.58,
5.10,
-0.42,
0.56,
1.85,
"#6c352c",
"#f2d99e",
true
);
// Overhead utility lines.
function addWire(points, color = 0x403b34) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color })
);
scene.add(line);
}
addWire([
[-8.0, 7.20, -0.20],
[-3.0, 6.95, -0.40],
[2.3, 6.72, -0.30],
[7.2, 7.10, 2.35]
]);
addWire([
[-7.8, 6.88, 0.10],
[-2.8, 6.58, -0.15],
[2.5, 6.42, -0.05],
[7.0, 6.92, 2.60]
], 0x554b40);
// Laundry line and simple cloth blocks.
addWire([
[-6.35, 5.42, -0.45],
[-3.95, 5.24, -0.60]
], 0x6a6256);
const clothMaterials = [M.paper, M.shirtBlue, M.shirtRed, M.cream];
for (let i = 0; i < 4; i++) {
const cloth = box(
scene,
0.38,
0.63,
0.035,
-6.05 + i * 0.54,
5.05,
-0.52,
clothMaterials[i]
);
cloth.rotation.z = (i - 1.5) * 0.025;
}
// Scooters.
addScooter(scene, 3.05, -3.10, -0.28, M.scooter);
addScooter(scene, -3.25, -4.25, 0.55, M.scooterRed);
// Planters and small street trees.
addPlanter(scene, -2.63, 0.08, -1.35, 1.05);
addPlanter(scene, 2.58, 0.08, -1.20, 0.90);
addPlanter(scene, -6.10, 0.08, -2.35, 1.15);
// Café table and chairs.
box(scene, 1.10, 0.10, 1.10, -5.10, 0.88, -2.25, M.darkWood);
box(scene, 0.18, 0.83, 0.18, -5.10, 0.43, -2.25, M.iron);
box(scene, 0.65, 0.08, 0.65, -5.10, 0.05, -2.25, M.iron);
for (const side of [-1, 1]) {
box(scene, 0.55, 0.08, 0.55, -5.10 + side * 0.95, 0.48, -2.25, M.tealDark);
box(scene, 0.55, 0.58, 0.10, -5.10 + side * 0.95, 0.77, -1.99, M.tealDark);
box(scene, 0.10, 0.44, 0.10, -5.10 + side * 0.95, 0.22, -2.25, M.iron);
}
// People provide scale.
addPerson(scene, -1.60, -2.25, M.shirtBlue, 0.30, 0.95);
addPerson(scene, 1.18, -4.20, M.shirtRed, -0.55, 1.02);
addPerson(scene, -5.78, -1.10, M.cream, 1.20, 0.90);
// A few utility boxes and drain covers.
box(scene, 0.62, 0.82, 0.48, 2.82, 0.44, 0.62, M.tealDark);
box(scene, 0.68, 0.06, 0.54, 2.82, 0.89, 0.62, M.stone);
for (let i = 0; i < 7; i++) {
box(scene, 0.05, 0.025, 0.34, -1.2 + i * 0.43, 0.065, -1.45, M.iron);
}
// -------------------------------------------------------------------------
// Camera controls implemented without external controls/addons
// -------------------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(0, 3.45, 2.55),
radius: 18.8,
theta: 2.72,
phi: 1.30
};
const controls = {
target: defaultView.target.clone(),
radius: defaultView.radius,
theta: defaultView.theta,
phi: defaultView.phi,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const horizontal = Math.sin(controls.phi) * controls.radius;
camera.position.set(
controls.target.x + horizontal * Math.sin(controls.theta),
controls.target.y + Math.cos(controls.phi) * controls.radius,
controls.target.z + horizontal * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetView() {
controls.target.copy(defaultView.target);
controls.radius = defaultView.radius;
controls.theta = defaultView.theta;
controls.phi = defaultView.phi;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
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;
controls.theta -= dx * 0.005;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.004,
0.72,
1.50
);
updateCamera();
});
function stopDragging(event) {
controls.dragging = false;
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
8.5,
30
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") controls.theta += 0.12;
if (event.key === "ArrowRight") controls.theta -= 0.12;
if (event.key === "ArrowUp") controls.phi -= 0.08;
if (event.key === "ArrowDown") controls.phi += 0.08;
if (event.key === "+" || event.key === "=") controls.radius -= 0.8;
if (event.key === "-" || event.key === "_") controls.radius += 0.8;
if (event.key.toLowerCase() === "r") resetView();
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.72, 1.50);
controls.radius = THREE.MathUtils.clamp(controls.radius, 8.5, 30);
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
interiorLights.forEach((light) => {
light.intensity =
light.userData.baseIntensity *
(1 + Math.sin(elapsed * 2.1 + light.userData.phase) * 0.045);
});
renderer.render(scene, camera);
});
</script>
</body>
</html>
```