Prompt specification
Build or customize the Three.js 3D scene "Vendor setting a small Hanoi sidewalk table" 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: Vendor setting a small Hanoi sidewalk table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/vendor-setting-a-small-hanoi-sidewalk-table-x2978
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Hanoi's Old Quarter. Create a compact referenced Old Quarter vignette with original vendor, table, parked bicycle, and pedestrian. Keep the walking path legible and avoid turning all activity into visual clutter. Voxel style.
Working Three.js Starter (vendor-setting-a-small-hanoi-sidewalk-table-x2978):
```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="#d9d4c8" />
<title>Hanoi Old Quarter — Voxel Vignette</title>
<style>
:root {
color-scheme: light;
--ink: #2f302c;
--muted: #6f7068;
--paper: rgba(250, 246, 235, 0.88);
--line: rgba(70, 65, 52, 0.16);
--accent: #9c4b38;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9d4c8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 48%, rgba(65, 58, 44, 0.1) 115%);
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
width: min(340px, calc(100vw - 48px));
padding: 18px 19px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 14px 45px rgba(57, 49, 35, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
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(28px, 4vw, 38px);
font-weight: 500;
line-height: 1;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 14px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.scene-key {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.scene-key span {
padding: 5px 8px;
border: 1px solid rgba(79, 70, 52, 0.12);
border-radius: 999px;
background: rgba(255, 255, 255, 0.52);
color: #55564f;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
}
.controls {
position: fixed;
left: 24px;
right: 24px;
bottom: 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.hint,
.reset-button {
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 8px 28px rgba(57, 49, 35, 0.1);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.hint {
padding: 10px 13px;
border-radius: 12px;
color: #66675f;
font-size: 11px;
line-height: 1;
}
.reset-button {
min-height: 38px;
padding: 0 15px;
border-radius: 12px;
color: #484943;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
pointer-events: auto;
transition: transform 150ms ease, background 150ms ease;
}
.reset-button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.94);
}
.reset-button:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #d9d4c8;
color: #6e6252;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
pointer-events: none;
}
#loading.hidden {
opacity: 0;
}
@media (max-width: 600px) {
.title-card {
top: 14px;
left: 14px;
width: min(290px, calc(100vw - 28px));
padding: 14px 15px;
}
.subtitle {
display: none;
}
.scene-key {
margin-top: 12px;
}
.controls {
left: 14px;
right: 14px;
bottom: 14px;
}
.hint {
max-width: 210px;
line-height: 1.35;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel vignette of Hanoi's Old Quarter"></div>
<div class="vignette"></div>
<header class="title-card">
<p class="eyebrow">Hà Nội · Việt Nam</p>
<h1>Old Quarter</h1>
<p class="subtitle">
A compact voxel street study of narrow shophouses and everyday life.
</p>
<div class="scene-key" aria-label="Scene elements">
<span>Vendor</span>
<span>Café table</span>
<span>Parked bicycle</span>
<span>Pedestrian</span>
</div>
</header>
<div class="controls">
<div class="hint">Drag to orbit · Scroll or pinch to zoom · R to reset</div>
<button class="reset-button" id="reset" type="button">Reset view</button>
</div>
<div id="loading">Building the street</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 lighting
// -------------------------------------------------------------------------
const host = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d4c8);
scene.fog = new THREE.Fog(0xd9d4c8, 55, 105);
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;
host.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 15, -15, 0.1, 200);
const cameraTarget = new THREE.Vector3(0, 2.2, -0.8);
let azimuth = 0.67;
let elevation = 0.57;
let zoom = 1.03;
const hemisphere = new THREE.HemisphereLight(0xfff0d6, 0x647067, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b0, 3.4);
sun.position.set(-12, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 2;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
sun.target.position.set(0, 0, -2);
scene.add(sun, sun.target);
const fill = new THREE.DirectionalLight(0xb9d4dc, 0.85);
fill.position.set(18, 10, -12);
scene.add(fill);
// -------------------------------------------------------------------------
// Voxel construction helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, options = {}) {
if (color && color.isMaterial) return color;
const roughness = options.roughness ?? 0.84;
const metalness = options.metalness ?? 0;
const emissive = options.emissive ?? 0x000000;
const emissiveIntensity = options.emissiveIntensity ?? 0;
const key = `${color}:${roughness}:${metalness}:${emissive}:${emissiveIntensity}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
emissive,
emissiveIntensity,
flatShading: true
})
);
}
return materialCache.get(key);
}
function block(parent, size, position, color, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(unitBox, getMaterial(color));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function beam(parent, start, end, thickness, color) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const mesh = block(
parent,
[thickness, length, thickness],
midpoint.toArray(),
color
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function cssColor(hex) {
return `#${hex.toString(16).padStart(6, "0")}`;
}
function makeSignTexture(text, background, foreground = 0xf8e7c7) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = cssColor(background);
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "rgba(255,245,220,0.78)";
context.lineWidth = 7;
context.strokeRect(7, 7, canvas.width - 14, canvas.height - 14);
context.fillStyle = cssColor(foreground);
context.font = "700 62px Arial, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function addSign(parent, text, background, position, width, height) {
block(
parent,
[width + 0.13, height + 0.13, 0.12],
position,
background
);
const material = new THREE.MeshBasicMaterial({
map: makeSignTexture(text, background),
toneMapped: false,
side: THREE.DoubleSide
});
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
plane.position.set(
position[0],
position[1],
position[2] + 0.068
);
parent.add(plane);
return plane;
}
// -------------------------------------------------------------------------
// Diorama base and street
// -------------------------------------------------------------------------
block(scene, [180, 0.12, 180], [0, -1.42, 0], 0xd9d4c8, false, true);
block(scene, [32, 1.2, 17.8], [0, -0.72, 0], 0x68594a);
block(scene, [31.6, 0.4, 17.4], [0, -0.05, 0], 0xb9aa91);
// Raised sidewalk in front of the shophouses.
block(scene, [31.6, 0.42, 2.5], [0, 0.29, -3.25], 0xd3c5a9);
// Quiet foreground apron.
block(scene, [31.6, 0.08, 4.65], [0, 0.18, 5.73], 0xc5b79e);
// A clearly legible, uninterrupted walking path.
const tileColors = [0xd8cfbc, 0xd2c8b5, 0xded6c4, 0xd4cab8];
const tilePitchX = 1.03;
const tilePitchZ = 1.04;
const tileStartX = -14.42;
const tileStartZ = -1.95;
for (let x = 0; x < 28; x++) {
for (let z = 0; z < 5; z++) {
const color = tileColors[(x * 3 + z * 2) % tileColors.length];
block(
scene,
[0.97, 0.08, 0.97],
[
tileStartX + x * tilePitchX,
0.22,
tileStartZ + z * tilePitchZ
],
color,
false,
true
);
}
}
block(scene, [29.3, 0.12, 0.13], [0, 0.23, -2.01], 0x8f826e);
block(scene, [29.3, 0.12, 0.13], [0, 0.23, 3.29], 0x8f826e);
// Sparse street details keep the path open.
block(scene, [1.05, 0.035, 1.05], [3.2, 0.235, 6.05], 0x9f9481, false, true);
block(scene, [0.72, 0.035, 0.72], [3.2, 0.254, 6.05], 0xaaa08e, false, true);
// -------------------------------------------------------------------------
// Narrow shophouses
// -------------------------------------------------------------------------
const houseSpecs = [
{
x: -14.65, w: 4.05, h: 8.4,
color: 0xc27d58, sign: "PHỞ 24", signColor: 0x743d31,
awning: 0x9b4b3b
},
{
x: -10.45, w: 4.05, h: 9.8,
color: 0xc49a62, sign: "CÀ PHÊ", signColor: 0x345449,
awning: 0xd3ae63
},
{
x: -6.25, w: 4.05, h: 7.8,
color: 0x87937a, sign: "BÚN CHẢ", signColor: 0x704333,
awning: 0xdcc782
},
{
x: -2.05, w: 4.05, h: 9.2,
color: 0x78919a, sign: "MÌ", signColor: 0x344e5c,
awning: 0xb75d4d
},
{
x: 2.15, w: 4.05, h: 8.2,
color: 0xc8a45e, sign: "CHÈ", signColor: 0x694938,
awning: 0x6e8c70
},
{
x: 6.35, w: 4.05, h: 10.1,
color: 0xa66e63, sign: "HOA", signColor: 0x395849,
awning: 0xd3ae63
},
{
x: 10.55, w: 4.05, h: 8.7,
color: 0xba8c6b, sign: "MÁ", signColor: 0x6d3c34,
awning: 0x587f79
}
];
function makeLantern(parent, x, y, z) {
const lanternMaterial = new THREE.MeshStandardMaterial({
color: 0xce4938,
roughness: 0.7,
emissive: 0x7d1e13,
emissiveIntensity: 0.22,
flatShading: true
});
block(parent, [0.34, 0.46, 0.34], [x, y, z], lanternMaterial);
block(parent, [0.39, 0.09, 0.39], [x, y + 0.26, z], 0xd9b768);
block(parent, [0.38, 0.08, 0.38], [x, y - 0.26, z], 0xd9b768);
block(parent, [0.035, 0.28, 0.035], [x, y + 0.43, z], 0x493d31);
}
function buildHouse(spec, index) {
const group = new THREE.Group();
group.position.x = spec.x;
scene.add(group);
const bottom = 0.5;
const top = bottom + spec.h;
const frontZ = -4.45;
const bodyDepth = 4.2;
block(
group,
[spec.w, spec.h, bodyDepth],
[0, bottom + spec.h / 2, -6.55],
spec.color
);
// Roof cornice and narrow vertical pilasters.
block(group, [spec.w + 0.18, 0.18, 4.38], [0, top + 0.08, -6.55], 0xe1d2b6);
block(group, [0.17, spec.h, 0.16], [-spec.w / 2 + 0.09, bottom + spec.h / 2, frontZ + 0.08], 0xe6d6b8);
block(group, [0.17, spec.h, 0.16], [spec.w / 2 - 0.09, bottom + spec.h / 2, frontZ + 0.08], 0xe6d6b8);
// Ground-floor shop recess.
block(
group,
[spec.w - 0.42, 1.92, 0.10],
[0, 1.35, frontZ + 0.04],
0x3f3d34
);
block(group, [1.07, 1.84, 0.12], [0.72, 1.34, frontZ + 0.12], 0x554333);
block(group, [0.08, 0.10, 0.08], [1.08, 1.25, frontZ + 0.20], 0xd1b774);
block(group, [1.58, 1.34, 0.12], [-0.86, 1.36, frontZ + 0.12], 0x263c3c);
block(group, [0.08, 1.35, 0.08], [-0.86, 1.36, frontZ + 0.20], 0x9b7c54);
for (let slat = 0; slat < 4; slat++) {
block(
group,
[0.055, 1.34, 0.08],
[-1.48 + slat * 0.41, 1.36, frontZ + 0.20],
0x94724d
);
}
block(group, [1.64, 0.09, 0.09], [-0.86, 1.36, frontZ + 0.20], 0x94724d);
block(group, [1.64, 0.09, 0.09], [-0.86, 0.67, frontZ + 0.20], 0x94724d);
// Awning made from broad voxel stripes.
const stripeWidth = spec.w / 6;
for (let stripe = 0; stripe < 6; stripe++) {
const stripeColor = stripe % 2 === 0 ? spec.awning : 0xead9b7;
const stripeX = -spec.w / 2 + stripeWidth * (stripe + 0.5);
block(
group,
[stripeWidth - 0.035, 0.13, 1.3],
[stripeX, 2.47, frontZ + 0.63],
stripeColor
);
block(
group,
[stripeWidth - 0.035, 0.28, 0.10],
[stripeX, 2.31, frontZ + 1.25],
stripeColor
);
}
addSign(
group,
spec.sign,
spec.signColor,
[0, 3.02, frontZ + 0.15],
Math.min(2.82, spec.w - 0.7),
0.58
);
// Upper windows, shutters and occasional balconies.
const levels = [3.9, 6.25, 8.6];
levels.forEach((level, floorIndex) => {
if (level + 0.85 > top) return;
block(
group,
[1.82, 1.36, 0.10],
[0, level, frontZ + 0.04],
0x253a3b
);
const shutterColor = new THREE.Color(spec.color).multiplyScalar(0.76);
block(group, [0.38, 1.36, 0.12], [-1.01, level, frontZ + 0.11], shutterColor);
block(group, [0.38, 1.36, 0.12], [1.01, level, frontZ + 0.11], shutterColor);
block(group, [1.82, 0.08, 0.09], [0, level, frontZ + 0.15], 0xd7c4a0);
block(group, [0.08, 1.36, 0.09], [0, level, frontZ + 0.15], 0xd7c4a0);
if (index % 2 === 0 && floorIndex === 0) {
block(group, [2.62, 0.13, 0.88], [0, level - 0.82, frontZ + 0.40], 0xcbb790);
block(group, [2.62, 0.08, 0.08], [0, level - 0.26, frontZ + 0.79], 0x5b5548);
[-1.14, 0, 1.14].forEach((railX) => {
block(
group,
[0.075, 0.53, 0.075],
[railX, level - 0.53, frontZ + 0.79],
0x5b5548
);
});
}
});
if (index === 1 || index === 3 || index === 5) {
makeLantern(group, -spec.w / 2 + 0.43, 2.02, frontZ + 1.02);
makeLantern(group, spec.w / 2 - 0.43, 2.02, frontZ + 1.02);
}
// Sparse rooftop utilities.
if (index === 0 || index === 3 || index === 6) {
block(group, [0.76, 0.56, 0.66], [0.48, top + 0.46, -6.48], 0x8d9691);
block(group, [0.10, 0.28, 0.10], [0.48, top + 0.88, -6.48], 0x656d68);
}
if (index === 2 || index === 5) {
block(group, [0.06, 1.25, 0.06], [-0.65, top + 0.78, -6.6], 0x6e655a);
block(group, [0.68, 0.05, 0.05], [-0.65, top + 1.16, -6.6], 0x6e655a);
}
return group;
}
houseSpecs.forEach(buildHouse);
// -------------------------------------------------------------------------
// Human figures
// -------------------------------------------------------------------------
function makeHuman({
shirt = 0xc39a42,
trousers = 0x384b62,
hair = 0x2f2924,
skin = 0xc88d64,
apron = null,
hat = null,
backpack = false
} = {}) {
const group = new THREE.Group();
const torso = block(group, [0.64, 0.73, 0.38], [0, 1.16, 0], shirt);
block(group, [0.48, 0.47, 0.47], [0, 1.73, 0.01], skin);
block(group, [0.52, 0.14, 0.51], [0, 1.98, -0.01], hair);
block(group, [0.13, 0.12, 0.08], [0, 1.73, 0.27], skin);
block(group, [0.055, 0.055, 0.035], [-0.11, 1.79, 0.245], 0x312c28);
block(group, [0.055, 0.055, 0.035], [0.11, 1.79, 0.245], 0x312c28);
const legLeft = new THREE.Group();
const legRight = new THREE.Group();
legLeft.position.set(-0.17, 0.78, 0);
legRight.position.set(0.17, 0.78, 0);
group.add(legLeft, legRight);
[legLeft, legRight].forEach((leg) => {
block(leg, [0.25, 0.58, 0.28], [0, -0.29, 0], trousers);
block(leg, [0.29, 0.16, 0.41], [0, -0.67, 0.07], 0x2c2d2b);
});
const armLeft = new THREE.Group();
const armRight = new THREE.Group();
armLeft.position.set(-0.42, 1.46, 0);
armRight.position.set(0.42, 1.46, 0);
group.add(armLeft, armRight);
[armLeft, armRight].forEach((arm) => {
block(arm, [0.19, 0.55, 0.22], [0, -0.27, 0], shirt);
block(arm, [0.20, 0.18, 0.22], [0, -0.60, 0], skin);
});
if (apron !== null) {
block(group, [0.55, 0.70, 0.055], [0, 1.04, 0.215], apron);
block(group, [0.14, 0.48, 0.05], [-0.20, 1.53, 0.215], apron);
block(group, [0.14, 0.48, 0.05], [0.20, 1.53, 0.215], apron);
}
if (hat !== null) {
block(group, [0.70, 0.07, 0.60], [0, 2.02, 0.01], hat);
block(group, [0.43, 0.18, 0.43], [0, 2.13, 0.01], hat);
}
if (backpack) {
block(group, [0.49, 0.60, 0.20], [0, 1.19, -0.28], 0x7d503b);
block(group, [0.10, 0.52, 0.05], [-0.20, 1.31, 0.205], 0x584431);
block(group, [0.10, 0.52, 0.05], [0.20, 1.31, 0.205], 0x584431);
}
return {
group,
torso,
legLeft,
legRight,
armLeft,
armRight
};
}
// Walking pedestrian on the clear path.
const pedestrian = makeHuman({
shirt: 0xc89c3f,
trousers: 0x3c5068,
hair: 0x28231f,
skin: 0xc78b62,
backpack: true
});
pedestrian.group.position.set(-10, 0.26, 0.85);
scene.add(pedestrian.group);
// -------------------------------------------------------------------------
// Street vendor and food cart
// -------------------------------------------------------------------------
const cart = new THREE.Group();
cart.position.set(9.75, 0, -2.50);
scene.add(cart);
block(cart, [2.85, 0.92, 1.18], [0, 1.00, 0], 0x356b62);
block(cart, [3.04, 0.14, 1.35], [0, 1.51, 0], 0xa9794f);
block(cart, [0.16, 1.08, 0.16], [-1.36, 2.02, -0.48], 0x51483a);
block(cart, [0.16, 1.08, 0.16], [1.36, 2.02, -0.48], 0x51483a);
block(cart, [0.16, 1.08, 0.16], [-1.36, 2.02, 0.48], 0x51483a);
block(cart, [0.16, 1.08, 0.16], [1.36, 2.02, 0.48], 0x51483a);
for (let stripe = 0; stripe < 8; stripe++) {
const color = stripe % 2 === 0 ? 0xb54d38 : 0xe6d4ad;
block(
cart,
[0.39, 0.13, 1.58],
[-1.365 + stripe * 0.39, 2.62, 0],
color
);
block(
cart,
[0.39, 0.28, 0.09],
[-1.365 + stripe * 0.39, 2.47, 0.77],
color
);
}
// Voxel cart wheels.
block(cart, [0.43, 0.43, 0.18], [-0.94, 0.60, 0.61], 0x302e2b);
block(cart, [0.43, 0.43, 0.18], [0.94, 0.60, 0.61], 0x302e2b);
block(cart, [0.17, 0.17, 0.21], [-0.94, 0.60, 0.68], 0x8b704d);
block(cart, [0.17, 0.17, 0.21], [0.94, 0.60, 0.68], 0x8b704d);
// Pots, bowls and stacked containers.
block(cart, [0.58, 0.48, 0.55], [0.65, 1.82, -0.04], 0x3d4645);
block(cart, [0.64, 0.08, 0.60], [0.65, 2.09, -0.04], 0x7d817a);
block(cart, [0.14, 0.18, 0.14], [0.65, 2.17, -0.04], 0x474a47);
block(cart, [0.48, 0.22, 0.45], [-0.58, 1.68, 0.02], 0xe4d6b5);
block(cart, [0.42, 0.18, 0.40], [-0.58, 1.86, 0.02], 0xe8ddc2);
addSign(
cart,
"BÚN CHẢ",
0x713a2f,
[0, 0.96, 0.62],
2.15,
0.53
);
const vendor = makeHuman({
shirt: 0xa94736,
trousers: 0x35445a,
hair: 0x28221e,
skin: 0xc98c61,
apron: 0x355c73,
hat: 0xc6a35f
});
vendor.group.position.set(9.75, 0.50, -3.27);
vendor.group.rotation.y = 0.05;
vendor.armLeft.rotation.x = -0.34;
vendor.armRight.rotation.x = -0.55;
scene.add(vendor.group);
// Subtle voxel steam above the cooking pot.
const steamPuffs = [];
for (let puff = 0; puff < 3; puff++) {
const steamMaterial = new THREE.MeshBasicMaterial({
color: 0xfff5df,
transparent: true,
opacity: 0.22,
depthWrite: false,
toneMapped: false
});
const puffMesh = new THREE.Mesh(unitBox, steamMaterial);
puffMesh.castShadow = false;
puffMesh.receiveShadow = false;
cart.add(puffMesh);
steamPuffs.push({ mesh: puffMesh, offset: puff / 3 });
}
// -------------------------------------------------------------------------
// Café table and two stools
// -------------------------------------------------------------------------
const table = new THREE.Group();
table.position.set(13.05, 0.50, -2.83);
scene.add(table);
block(table, [1.48, 0.14, 1.08], [0, 1.05, 0], 0x9a704a);
block(table, [0.13, 1.00, 0.13], [-0.55, 0.50, -0.35], 0x5e4c39);
block(table, [0.13, 1.00, 0.13], [0.55, 0.50, -0.35], 0x5e4c39);
block(table, [0.13, 1.00, 0.13], [-0.55, 0.50, 0.35], 0x5e4c39);
block(table, [0.13, 1.00, 0.13], [0.55, 0.50, 0.35], 0x5e4c39);
block(table, [0.16, 0.20, 0.16], [-0.31, 1.22, 0.10], 0xe9dfc5);
block(table, [0.16, 0.20, 0.16], [0.28, 1.22, -0.08], 0xe9dfc5);
block(table, [0.36, 0.05, 0.25], [0.02, 1.16, 0.04], 0xd8c7a6);
function addStool(x, z) {
const stool = new THREE.Group();
stool.position.set(x, 0.50, z);
block(stool, [0.62, 0.13, 0.58], [0, 0.57, 0], 0x876143);
block(stool, [0.12, 0.55, 0.12], [-0.21, 0.27, -0.19], 0x594b3b);
block(stool, [0.12, 0.55, 0.12], [0.21, 0.27, -0.19], 0x594b3b);
block(stool, [0.12, 0.55, 0.12], [-0.21, 0.27, 0.19], 0x594b3b);
block(stool, [0.12, 0.55, 0.12], [0.21, 0.27, 0.19], 0x594b3b);
scene.add(stool);
}
addStool(11.98, -2.83);
addStool(14.10, -2.83);
// -------------------------------------------------------------------------
// Parked bicycle, built entirely from small voxel elements
// -------------------------------------------------------------------------
function addPixelWheel(parent, centerX, centerY) {
const radius = 0.43;
const segmentCount = 16;
for (let segment = 0; segment < segmentCount; segment++) {
const angle = (segment / segmentCount) * Math.PI * 2;
block(
parent,
[0.14, 0.14, 0.13],
[
centerX + Math.cos(angle) * radius,
centerY + Math.sin(angle) * radius,
0
],
0x292a28
);
}
block(parent, [0.88, 0.035, 0.05], [centerX, centerY, 0.01], 0x8b806b);
block(parent, [0.035, 0.88, 0.05], [centerX, centerY, 0.01], 0x8b806b);
}
const bicycle = new THREE.Group();
bicycle.position.set(-10.85, 0.96, -4.07);
bicycle.rotation.y = -0.04;
scene.add(bicycle);
const bikeFrame = 0x3c7772;
addPixelWheel(bicycle, -0.61, 0);
addPixelWheel(bicycle, 0.61, 0);
beam(bicycle, [-0.61, 0, 0], [-0.08, -0.08, 0], 0.075, bikeFrame);
beam(bicycle, [-0.08, -0.08, 0], [-0.29, 0.47, 0], 0.075, bikeFrame);
beam(bicycle, [-0.29, 0.47, 0], [0.43, 0.47, 0], 0.075, bikeFrame);
beam(bicycle, [0.43, 0.47, 0], [0.61, 0, 0], 0.075, bikeFrame);
beam(bicycle, [-0.08, -0.08, 0], [0.43, 0.47, 0], 0.075, bikeFrame);
beam(bicycle, [-0.08, -0.08, 0], [-0.29, 0.47, 0], 0.075, bikeFrame);
block(bicycle, [0.34, 0.11, 0.22], [-0.30, 0.57, 0], 0x5a3d2c);
beam(bicycle, [0.43, 0.47, 0], [0.43, 0.70, 0], 0.065, 0x3b3b38);
block(bicycle, [0.08, 0.07, 0.36], [0.43, 0.71, 0], 0x3b3b38);
block(bicycle, [0.22, 0.07, 0.08], [-0.08, -0.08, 0.08], 0x3b3b38);
beam(bicycle, [-0.18, -0.08, 0.08], [0.02, -0.08, 0.08], 0.045, 0x8d8171);
beam(bicycle, [-0.29, 0.43, 0], [-0.08, -0.08, 0], 0.035, 0x8d8171);
// A restrained foreground planter gives the diorama a frame.
const planter = new THREE.Group();
planter.position.set(-13.45, 0, 5.95);
scene.add(planter);
block(planter, [1.46, 0.46, 1.40], [0, 0.39, 0], 0x9d6d4e);
block(planter, [1.23, 0.09, 1.17], [0, 0.66, 0], 0x3f4537);
block(planter, [0.24, 1.50, 0.24], [0, 1.36, 0], 0x66503b);
block(planter, [1.12, 0.78, 1.02], [0, 2.12, 0], 0x66795a);
block(planter, [0.68, 0.58, 0.75], [-0.35, 2.67, 0.05], 0x78916a);
block(planter, [0.63, 0.52, 0.63], [0.38, 2.55, -0.08], 0x728964);
// -------------------------------------------------------------------------
// Direct camera controls: drag, wheel, pinch and reset
// -------------------------------------------------------------------------
function updateCamera() {
const distance = 48;
camera.position.set(
cameraTarget.x + Math.sin(azimuth) * Math.cos(elevation) * distance,
cameraTarget.y + Math.sin(elevation) * distance,
cameraTarget.z + Math.cos(azimuth) * Math.cos(elevation) * distance
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
azimuth = 0.67;
elevation = 0.57;
zoom = 1.03;
updateCamera();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(23, 34 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
const pointers = new Map();
let previousPinchDistance = null;
function pointerDistance() {
const values = Array.from(pointers.values());
if (values.length < 2) return null;
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 });
renderer.domElement.classList.add("dragging");
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
azimuth -= deltaX * 0.006;
elevation = THREE.MathUtils.clamp(
elevation + deltaY * 0.005,
0.28,
1.12
);
updateCamera();
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (distance && previousPinchDistance) {
zoom = THREE.MathUtils.clamp(
zoom * (distance / previousPinchDistance),
0.72,
1.8
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pointerDistance() : null;
if (pointers.size === 0) {
renderer.domElement.classList.remove("dragging");
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.8
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
});
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
// The pedestrian walks slowly and turns at the ends of the path.
const pingPong = (time * 0.055) % 2;
const progress = pingPong <= 1 ? pingPong : 2 - pingPong;
const direction = pingPong <= 1 ? 1 : -1;
const stride = Math.sin(time * 7.4);
pedestrian.group.position.x = -11.5 + progress * 23;
pedestrian.group.position.y = 0.26 + Math.abs(stride) * 0.025;
pedestrian.group.rotation.y = direction > 0 ? Math.PI / 2 : -Math.PI / 2;
pedestrian.legLeft.rotation.x = stride * 0.52;
pedestrian.legRight.rotation.x = -stride * 0.52;
pedestrian.armLeft.rotation.x = -stride * 0.42;
pedestrian.armRight.rotation.x = stride * 0.42;
vendor.armRight.rotation.x = -0.55 + Math.sin(time * 2.2) * 0.07;
steamPuffs.forEach(({ mesh, offset }) => {
const life = (time * 0.36 + offset) % 1;
mesh.position.set(
0.65 + Math.sin(time * 2 + offset * 8) * 0.07,
2.24 + life * 0.96,
-0.04 + Math.cos(time * 1.7 + offset * 6) * 0.04
);
mesh.scale.setScalar(0.10 + life * 0.20);
mesh.material.opacity = 0.25 * (1 - life);
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```