Prompt specification
Build or customize the Three.js 3D scene "Hội An riverside block and footbridge scene" 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: Hội An riverside block and footbridge scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/h-i-an-riverside-block-and-footbridge-scene-x2983
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Hội An's riverside streets. Build a bounded voxel slice with referenced roof forms, river edge, one bridge cue, and original shopfronts. Keep landmark relationships coherent and avoid an entire town reconstruction. Voxel style.
Working Three.js Starter (h-i-an-riverside-block-and-footbridge-scene-x2983):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hội An — Riverside Voxel Slice</title>
<style>
:root {
--ink: #233b35;
--muted: #63746b;
--paper: rgba(248, 244, 226, 0.91);
--line: rgba(35, 59, 53, 0.17);
--accent: #a95035;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce3db;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#wash {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(247, 242, 221, 0.15), transparent 25%),
radial-gradient(circle at 50% 45%, transparent 50%, rgba(31, 50, 44, 0.12));
}
.panel {
position: fixed;
z-index: 3;
pointer-events: none;
}
#title {
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 32px;
height: 1px;
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(39px, 5vw, 64px);
font-weight: 500;
line-height: 0.9;
letter-spacing: -0.045em;
}
.subtitle {
margin: 13px 0 0;
max-width: 350px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 17px;
}
.chip {
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 2px;
background: rgba(248, 244, 226, 0.64);
color: #40564d;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
#details {
top: 28px;
right: 30px;
width: 220px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 14px 38px rgba(38, 55, 48, 0.08);
backdrop-filter: blur(12px);
}
#details strong {
display: block;
margin-bottom: 10px;
font-size: 9px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.detail-row {
display: grid;
grid-template-columns: 8px 1fr;
gap: 9px;
align-items: start;
margin-top: 8px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.swatch {
width: 7px;
height: 7px;
margin-top: 3px;
border-radius: 1px;
background: #a95035;
}
.swatch.water { background: #568e8e; }
.swatch.roof { background: #8c5143; }
#footer {
left: 30px;
bottom: 25px;
color: rgba(35, 59, 53, 0.74);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#controls {
right: 30px;
bottom: 24px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.control-note {
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 2px;
background: var(--paper);
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
button {
min-width: 38px;
height: 34px;
padding: 0 11px;
border: 1px solid rgba(35, 59, 53, 0.25);
border-radius: 2px;
background: var(--ink);
color: #f7f0d9;
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
button:hover { background: #365149; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.world-tag {
position: fixed;
z-index: 2;
pointer-events: none;
transform: translate(-50%, -100%);
padding: 5px 8px;
border: 1px solid rgba(35, 59, 53, 0.2);
border-radius: 2px;
background: rgba(248, 244, 226, 0.88);
color: #334b42;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
box-shadow: 0 5px 18px rgba(35, 59, 53, 0.08);
backdrop-filter: blur(7px);
}
.world-tag::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: rgba(35, 59, 53, 0.45);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #dce3db;
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 0.5s ease, visibility 0.5s ease;
}
#loading.done {
opacity: 0;
visibility: hidden;
}
@media (max-width: 760px) {
#title {
top: 18px;
left: 18px;
}
h1 { font-size: 43px; }
.subtitle { max-width: 270px; font-size: 11px; }
.chips { display: none; }
#details {
display: none;
}
#footer {
left: 18px;
bottom: 18px;
max-width: 190px;
line-height: 1.4;
}
#controls {
right: 16px;
bottom: 16px;
}
.control-note { display: none; }
.world-tag { font-size: 7px; }
}
</style>
</head>
<body>
<div id="wash"></div>
<section id="title" class="panel">
<div class="eyebrow">A bounded voxel study</div>
<h1>Hội An</h1>
<p class="subtitle">
A small riverside slice of the Thu Bơn: low tiled gables, shaded shopfronts,
warm lanterns, and a single covered-bridge cue.
</p>
<div class="chips">
<span class="chip">Voxel architecture</span>
<span class="chip">Original storefronts</span>
<span class="chip">One bridge</span>
</div>
</section>
<aside id="details" class="panel">
<strong>Scene references</strong>
<div class="detail-row">
<span class="swatch roof"></span>
<span>Stepped clay-tile gables and shaded eaves</span>
</div>
<div class="detail-row">
<span class="swatch"></span>
<span>Fictional independent shops and hanging lanterns</span>
</div>
<div class="detail-row">
<span class="swatch water"></span>
<span>Stone-edged Thu Bơn riverfront promenade</span>
</div>
<div class="detail-row">
<span class="swatch roof"></span>
<span>A modest covered bridge, not a full-town reconstruction</span>
</div>
</aside>
<div id="footer" class="panel">36 × 26 unit river slice · fictional shopfronts</div>
<div id="controls" class="panel">
<span class="control-note">Drag to orbit · scroll to zoom</span>
<button id="reset" type="button" aria-label="Reset camera">Reset view</button>
</div>
<div id="riverTag" class="world-tag">Thu Bơn river</div>
<div id="bridgeTag" class="world-tag">Covered bridge cue</div>
<div id="loading">Building the riverside slice…</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 camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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.06;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce3db);
scene.fog = new THREE.Fog(0xdce3db, 58, 105);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
160
);
const controls = {
target: new THREE.Vector3(0, 1.8, 7),
radius: 44,
theta: 2.56,
phi: 1.13,
defaultRadius: 44
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
// Direct pointer camera controls; no examples/addons are used.
const pointer = {
active: false,
id: null,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
controls.theta -= dx * 0.0055;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0045,
0.64,
1.43
);
updateCamera();
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
28,
78
);
updateCamera();
}, { passive: false });
function resetView() {
const narrow = window.innerWidth / window.innerHeight < 0.8;
controls.radius = narrow ? 66 : controls.defaultRadius;
controls.theta = 2.56;
controls.phi = 1.13;
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
});
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xfff3d4, 0x52685f, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffdfaa, 3.2);
sun.position.set(-16, 26, -18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -27;
sun.shadow.camera.right = 27;
sun.shadow.camera.top = 27;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 80;
sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d7d0, 0.8);
fill.position.set(20, 12, 24);
scene.add(fill);
// ------------------------------------------------------------
// Shared geometry and material helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const unitPlane = new THREE.PlaneGeometry(1, 1);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}:${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function box(parent, size, position, mat, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(unitBox, mat);
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 hexCss(hex) {
return `#${hex.toString(16).padStart(6, "0")}`;
}
function makeTileTexture(baseColor) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = hexCss(baseColor);
ctx.fillRect(0, 0, 256, 256);
const shade = new THREE.Color(baseColor).multiplyScalar(0.68);
const light = new THREE.Color(baseColor).lerp(new THREE.Color(0xffffff), 0.18);
ctx.fillStyle = `#${shade.getHexString()}`;
for (let row = 0; row < 8; row++) {
const y = row * 32;
ctx.fillRect(0, y + 28, 256, 4);
for (let col = -1; col < 9; col++) {
const x = col * 32 + (row % 2) * 16;
ctx.fillRect(x, y + 4, 3, 24);
}
}
ctx.fillStyle = `#${light.getHexString()}`;
for (let row = 0; row < 8; row++) {
ctx.fillRect(0, row * 32 + 5, 256, 2);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3.2, 1.25);
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeSignTexture(text, background = "#334b42", foreground = "#f4e5b8") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.5;
ctx.lineWidth = 3;
ctx.strokeRect(10, 10, canvas.width - 20, canvas.height - 20);
ctx.globalAlpha = 1;
let fontSize = 58;
ctx.font = `700 ${fontSize}px Georgia, serif`;
while (ctx.measureText(text).width > canvas.width - 70 && fontSize > 25) {
fontSize -= 2;
ctx.font = `700 ${fontSize}px Georgia, serif`;
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function addSign(parent, text, width, height, position, options = {}) {
const {
background = "#334b42",
foreground = "#f4e5b8",
boardColor = 0x2b4039
} = options;
box(
parent,
[width + 0.08, height + 0.08, 0.12],
[position[0], position[1], position[2] + 0.04],
material(boardColor)
);
const texture = makeSignTexture(text, background, foreground);
const signMaterial = new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
const sign = new THREE.Mesh(unitPlane, signMaterial);
sign.scale.set(width, height, 1);
sign.position.set(
position[0],
position[1],
position[2] - 0.025
);
sign.rotation.y = Math.PI;
parent.add(sign);
return sign;
}
// ------------------------------------------------------------
// Bounded diorama base, river, promenade, and river edge
// ------------------------------------------------------------
const groundY = 0.35;
box(
scene,
[37, 1.2, 26],
[0, -0.86, 7.5],
material(0x746d5d)
);
box(
scene,
[37.12, 0.18, 26.12],
[0, -0.25, 7.5],
material(0xa69b7d)
);
// Far bank ground and riverside street.
box(
scene,
[36, 0.54, 10.25],
[0, 0.02, 14.55],
material(0xbdb28f)
);
box(
scene,
[35.6, 0.18, 2.8],
[0, 0.29, 11.05],
material(0xd5c9a6)
);
// Near bank, visible only as the cut edge of the slice.
box(
scene,
[36, 0.48, 2.45],
[0, 0.01, -1.08],
material(0xb9ae8c)
);
const riverMaterial = new THREE.MeshStandardMaterial({
color: 0x4e8587,
roughness: 0.28,
metalness: 0.08
});
box(
scene,
[35.8, 0.28, 9.42],
[0, -0.09, 4.72],
riverMaterial,
false,
true
);
// Voxel stone courses along both river edges.
const stoneA = material(0x9b947e);
const stoneB = material(0xaaa087);
const stoneC = material(0x8c8876);
for (let x = -17.4; x <= 17.4; x += 1.05) {
const variation = Math.abs(Math.round(x * 10)) % 3;
const edgeMat = variation === 0 ? stoneA : variation === 1 ? stoneB : stoneC;
box(
scene,
[1.0, 0.55, 0.34],
[x, 0.01, 9.53],
edgeMat
);
box(
scene,
[1.0, 0.5, 0.31],
[x, 0.0, 0.02],
edgeMat
);
}
// Mossy interruptions in the masonry.
const moss = material(0x65795a);
for (const [x, z] of [
[-12.8, 9.52], [-4.3, 9.52], [3.7, 9.52],
[12.1, 9.52], [-8.5, 0.02], [4.2, 0.02]
]) {
box(scene, [0.72, 0.18, 0.37], [x, 0.16, z], moss);
}
// Promenade paving joints and alternating stone tiles.
const paving = [
material(0xd8ccaa),
material(0xcdbf9b),
material(0xe0d4b2)
];
for (let x = -16.5; x <= 16.5; x += 1.55) {
for (let row = 0; row < 3; row++) {
const idx = (Math.round(x * 2) + row + 20) % 3;
box(
scene,
[1.48, 0.035, 0.68],
[x, 0.395, 9.92 + row * 0.83],
paving[idx],
false
);
}
}
// Low, flat voxel reflections on the water.
const waterPatchMaterials = [
material(0x609495, { roughness: 0.32, metalness: 0.04 }),
material(0x487d82, { roughness: 0.35, metalness: 0.03 })
];
for (let i = 0; i < 22; i++) {
const x = -16.5 + Math.random() * 33;
const z = 0.65 + Math.random() * 8.1;
const w = 0.35 + Math.random() * 1.55;
const d = 0.08 + Math.random() * 0.16;
box(
scene,
[w, 0.012, d],
[x, 0.058, z],
waterPatchMaterials[i % 2],
false,
false
);
}
// ------------------------------------------------------------
// Stepped tiled roof builder
// ------------------------------------------------------------
function addSteppedRoof(parent, options) {
const {
width,
depth,
baseY,
wallMaterial,
roofColor,
overhang = 0.8
} = options;
const texture = makeTileTexture(roofColor);
const roofMaterial = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.9
});
const trimMaterial = material(
new THREE.Color(roofColor).multiplyScalar(0.65).getHex()
);
const roofDepth = depth + overhang;
const levels = 8;
const stripDepth = roofDepth / levels;
const stepHeight = 0.17;
box(
parent,
[width + overhang + 0.12, 0.18, roofDepth + 0.08],
[0, baseY + 0.02, 0],
trimMaterial
);
for (const side of [-1, 1]) {
for (let level = 0; level < levels; level++) {
const z = side * (
-roofDepth / 2 + stripDepth / 2 + level * stripDepth
);
const roofY = baseY + 0.17 + (levels - 1 - level) * stepHeight;
box(
parent,
[width + overhang, 0.26, stripDepth + 0.025],
[0, roofY, z],
roofMaterial
);
// Stepped gable infill at the ends of the building.
const gableHeight = Math.max(
0.04,
roofY - baseY - 0.10
);
for (const end of [-1, 1]) {
box(
parent,
[0.12, gableHeight, stripDepth + 0.015],
[end * (width / 2 - 0.02), baseY + gableHeight / 2, z],
wallMaterial
);
}
}
}
const ridgeY = baseY + 0.17 + (levels - 1) * stepHeight;
box(
parent,
[width + overhang + 0.08, 0.24, 0.25],
[0, ridgeY, 0],
trimMaterial
);
}
// ------------------------------------------------------------
// Original fictional shopfronts
// ------------------------------------------------------------
const lanternGroups = [];
const shopShops = [];
function addHangingLantern(parent, x, y, z, color = 0xd86f3c) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const glow = material(color, {
emissive: color,
emissiveIntensity: 0.32,
roughness: 0.72
});
const dark = material(0x654331);
box(group, [0.38, 0.5, 0.38], [0, 0, 0], glow, false);
box(group, [0.43, 0.08, 0.43], [0, 0.29, 0], dark, false);
box(group, [0.43, 0.08, 0.43], [0, -0.29, 0], dark, false);
box(group, [0.035, 0.58, 0.42], [0, 0, 0], dark, false);
box(group, [0.42, 0.58, 0.035], [0, 0, 0], dark, false);
box(group, [0.025, 0.34, 0.025], [0, 0.46, 0], dark, false);
group.userData.phase = Math.random() * Math.PI * 2;
lanternGroups.push(group);
}
function addShop(spec, index) {
const group = new THREE.Group();
group.position.set(spec.x, 0, spec.z);
scene.add(group);
const w = spec.width;
const d = spec.depth;
const h = spec.height;
const front = -d / 2;
const wall = material(spec.wall);
const wallDark = material(
new THREE.Color(spec.wall).multiplyScalar(0.82).getHex()
);
const timber = material(spec.timber);
const recess = material(0x29443f);
const trim = material(0xe7d9b4);
const shutter = material(spec.shutter);
box(
group,
[w, h, d],
[0, groundY + h / 2, 0],
wall
);
box(
group,
[w + 0.08, 0.34, d + 0.05],
[0, groundY + 0.17, 0],
wallDark
);
box(
group,
[w + 0.16, 0.24, d + 0.13],
[0, groundY + h - 0.12, 0],
trim
);
// Three recessed facade bays.
const bayWidth = w * 0.21;
const bays = [-w * 0.28, 0, w * 0.28];
for (let i = 0; i < bays.length; i++) {
const x = bays[i];
const openingHeight = 2.45;
box(
group,
[bayWidth, openingHeight, 0.09],
[x, groundY + openingHeight / 2, front - 0.045],
recess
);
box(
group,
[0.07, openingHeight + 0.13, 0.11],
[x - bayWidth / 2, groundY + openingHeight / 2, front - 0.105],
timber
);
box(
group,
[0.07, openingHeight + 0.13, 0.11],
[x + bayWidth / 2, groundY + openingHeight / 2, front - 0.105],
timber
);
box(
group,
[bayWidth + 0.13, 0.1, 0.11],
[x, groundY + openingHeight, front - 0.11],
timber
);
// Door mullions and handles.
box(
group,
[0.055, openingHeight - 0.16, 0.07],
[x, groundY + openingHeight / 2, front - 0.12],
timber
);
box(
group,
[0.13, 0.08, 0.09],
[x + 0.17, groundY + 1.18, front - 0.14],
material(0xc69a48, { metalness: 0.45, roughness: 0.5 })
);
// Shallow wooden shutters beside each opening.
for (const side of [-1, 1]) {
box(
group,
[0.24, 2.05, 0.07],
[
x + side * (bayWidth / 2 + 0.16),
groundY + 1.22,
front - 0.12
],
shutter
);
}
}
// Upper windows for the taller units.
if (h > 5.15) {
for (const x of [-w * 0.28, 0, w * 0.28]) {
box(
group,
[w * 0.16, 1.12, 0.09],
[x, groundY + h * 0.73, front - 0.05],
recess
);
box(
group,
[0.07, 1.2, 0.1],
[x, groundY + h * 0.73, front - 0.11],
timber
);
box(
group,
[w * 0.16 + 0.1, 0.08, 0.11],
[x, groundY + h * 0.73, front - 0.11],
timber
);
}
}
// Awning made from alternating voxel fabric strips.
const awningY = groundY + 2.94;
const awningDepth = 0.95;
const stripeCount = Math.max(7, Math.round(w / 0.62));
const stripeWidth = (w - 0.25) / stripeCount;
for (let i = 0; i < stripeCount; i++) {
const stripeMaterial = material(
i % 2 === 0 ? spec.awning : 0xe7d8b7
);
box(
group,
[stripeWidth + 0.01, 0.14, awningDepth],
[
-w / 2 + 0.125 + stripeWidth * (i + 0.5),
awningY,
front - awningDepth / 2 - 0.04
],
stripeMaterial
);
}
box(
group,
[w - 0.1, 0.29, 0.09],
[0, awningY - 0.18, front - awningDepth - 0.02],
material(spec.awning)
);
// Original fictional shop sign.
addSign(
group,
spec.sign,
w * 0.72,
0.66,
[0, groundY + 3.66, front - 0.16],
{
background: spec.signBackground,
foreground: spec.signForeground,
boardColor: spec.timber
}
);
// Lanterns under the awning.
addHangingLantern(
group,
-w * 0.37,
awningY - 0.55,
front - 0.48,
index % 2 === 0 ? 0xcf6139 : 0xd68b35
);
addHangingLantern(
group,
w * 0.37,
awningY - 0.55,
front - 0.48,
index % 2 === 0 ? 0xd68b35 : 0xba5138
);
addSteppedRoof(group, {
width: w,
depth: d,
baseY: groundY + h,
wallMaterial: wall,
roofColor: spec.roof
});
// Small side awning bracket and threshold.
box(
group,
[0.14, 0.7, 0.8],
[-w / 2 + 0.08, groundY + 2.8, front - 0.35],
timber
);
box(
group,
[bayWidth + 0.35, 0.12, 0.55],
[0, groundY + 0.06, front - 0.25],
material(0xb5a783)
);
shopShops.push({ group, x: spec.x, z: spec.z });
return group;
}
const shopSpecs = [
{
x: -13.35,
z: 15.25,
width: 5.25,
depth: 4.75,
height: 4.65,
wall: 0xd6b978,
timber: 0x5e4937,
shutter: 0x3d6a60,
awning: 0x537e6b,
roof: 0x995644,
sign: "MOSS & BEAN",
signBackground: "#38594e",
signForeground: "#f2dfaa"
},
{
x: -7.0,
z: 15.35,
width: 5.1,
depth: 4.9,
height: 5.6,
wall: 0xe5cf99,
timber: 0x694634,
shutter: 0x9d503c,
awning: 0xa95035,
roof: 0x7f4b3e,
sign: "SAFFRON STUDIO",
signBackground: "#7e3f31",
signForeground: "#f8e3b4"
},
{
x: -0.55,
z: 15.2,
width: 4.8,
depth: 4.7,
height: 4.7,
wall: 0xc7c39b,
timber: 0x4c5140,
shutter: 0x475d70,
awning: 0x51667b,
roof: 0x8d5848,
sign: "RIVER LOOM",
signBackground: "#415b6c",
signForeground: "#efe2bd"
},
{
x: 6.0,
z: 15.35,
width: 5.35,
depth: 4.85,
height: 5.75,
wall: 0xce8f72,
timber: 0x584839,
shutter: 0x527468,
awning: 0x68866f,
roof: 0x79483d,
sign: "LANTERN FIELD",
signBackground: "#4f685b",
signForeground: "#f5dfad"
},
{
x: 13.0,
z: 15.25,
width: 4.6,
depth: 4.75,
height: 4.55,
wall: 0xe0b968,
timber: 0x5a4434,
shutter: 0x345e62,
awning: 0x426f70,
roof: 0xa25b43,
sign: "BAMBOO DECK",
signBackground: "#345f60",
signForeground: "#f5dfac"
}
];
shopSpecs.forEach(addShop);
// ------------------------------------------------------------
// One covered bridge cue
// ------------------------------------------------------------
const bridge = new THREE.Group();
bridge.position.x = 9.15;
scene.add(bridge);
const bridgeStone = material(0xbab49b);
const bridgeStoneDark = material(0x9f9a84);
const bridgeRed = material(0x874a37);
const bridgeRedDark = material(0x64392f);
const bridgeSegments = 15;
const bridgeStart = 0.1;
const bridgeEnd = 12.1;
const bridgeLength = bridgeEnd - bridgeStart;
const segmentLength = bridgeLength / bridgeSegments;
function bridgeHeightAt(t) {
return 0.56 + Math.sin(Math.PI * t) * 1.05;
}
for (let i = 0; i < bridgeSegments; i++) {
const t0 = i / bridgeSegments;
const t1 = (i + 1) / bridgeSegments;
const tm = (t0 + t1) / 2;
const z = bridgeStart + tm * bridgeLength;
const y = bridgeHeightAt(tm);
const nextY = bridgeHeightAt(t1);
const slope = (nextY - y) / segmentLength;
const rotationX = -Math.atan(slope);
const deck = box(
bridge,
[2.65, 0.25, segmentLength + 0.07],
[0, y, z],
i % 2 === 0 ? bridgeStone : bridgeStoneDark
);
deck.rotation.x = rotationX;
for (const side of [-1, 1]) {
const rail = box(
bridge,
[0.12, 0.13, segmentLength + 0.07],
[side * 1.26, y + 0.72, z],
bridgeRedDark
);
rail.rotation.x = rotationX;
}
}
for (let i = 0; i <= bridgeSegments; i += 2) {
const t = i / bridgeSegments;
const z = bridgeStart + t * bridgeLength;
const y = bridgeHeightAt(t);
for (const side of [-1, 1]) {
box(
bridge,
[0.16, 0.88, 0.16],
[side * 1.26, y + 0.43, z],
bridgeRed
);
}
}
// Covered central pavilion.
const pavilionZ = 5.15;
for (const x of [-1.18, 1.18]) {
for (const z of [pavilionZ - 1.15, pavilionZ + 1.15]) {
box(
bridge,
[0.18, 2.8, 0.18],
[x, 2.35, z],
bridgeRed
);
}
}
box(
bridge,
[2.65, 0.22, 2.65],
[0, 3.72, pavilionZ],
bridgeRedDark
);
addSteppedRoof(bridge, {
width: 2.8,
depth: 2.8,
baseY: 3.83,
wallMaterial: bridgeRed,
roofColor: 0x914a38,
overhang: 0.55
});
// ------------------------------------------------------------
// Street furniture, trees, crates, and people
// ------------------------------------------------------------
const lampDark = material(0x35463e);
const planter = material(0x8e7457);
function addStreetLamp(x, z, lanternColor = 0xe19443) {
box(scene, [0.12, 3.35, 0.12], [x, groundY + 1.68, z], lampDark);
box(scene, [0.68, 0.09, 0.09], [x, groundY + 3.34, z], lampDark);
const lamp = material(lanternColor, {
emissive: lanternColor,
emissiveIntensity: 0.4
});
box(
scene,
[0.42, 0.58, 0.42],
[x + 0.24, groundY + 3.08, z],
lamp,
false
);
box(
scene,
[0.5, 0.08, 0.5],
[x + 0.24, groundY + 3.42, z],
lampDark,
false
);
}
[-16.2, -10.4, -4.7, 1.4, 5.0, 14.7, 16.7].forEach((x, i) => {
addStreetLamp(x, 10.35, i % 2 === 0 ? 0xdb873e : 0xc95b3b);
});
function addPlanter(x, z, size = 1) {
box(
scene,
[1.15 * size, 0.52, 1.15 * size],
[x, groundY + 0.26, z],
planter
);
const foliage = material(0x647d50);
const foliageLight = material(0x7e925c);
box(
scene,
[0.86 * size, 0.78 * size, 0.86 * size],
[x, groundY + 0.78 * size + 0.17, z],
foliage
);
box(
scene,
[0.55 * size, 0.55 * size, 0.58 * size],
[x + 0.28 * size, groundY + 1.23 * size + 0.17, z - 0.13],
foliageLight
);
}
addPlanter(-12.1, 10.45, 0.86);
addPlanter(-5.7, 10.35, 0.8);
addPlanter(2.2, 10.5, 0.9);
addPlanter(12.3, 10.35, 0.86);
function addTree(x, z, scale = 1) {
const trunk = material(0x6e5038);
const leaf = material(0x526c48);
const leafLight = material(0x708452);
box(
scene,
[0.34 * scale, 3.4 * scale, 0.34 * scale],
[x, groundY + 1.7 * scale, z],
trunk
);
box(
scene,
[2.2 * scale, 1.9 * scale, 2.0 * scale],
[x, groundY + 3.55 * scale, z],
leaf
);
box(
scene,
[1.55 * scale, 1.25 * scale, 1.5 * scale],
[x + 0.62 * scale, groundY + 4.3 * scale, z - 0.18],
leafLight
);
box(
scene,
[1.15 * scale, 1.05 * scale, 1.2 * scale],
[x - 0.55 * scale, groundY + 3.85 * scale, z + 0.35],
leafLight
);
}
addTree(-16.0, 18.2, 1.08);
addTree(-10.4, 18.55, 0.92);
addTree(1.6, 18.45, 1.05);
addTree(16.2, 18.1, 1.0);
const crateMaterial = material(0x9a7147);
const crateDark = material(0x704e36);
function addCrates(x, z) {
box(scene, [0.76, 0.62, 0.7], [x, groundY + 0.31, z], crateMaterial);
box(scene, [0.65, 0.5, 0.61], [x + 0.75, groundY + 0.25, z + 0.1], crateDark);
box(scene, [0.7, 0.05, 0.05], [x, groundY + 0.45, z - 0.36], crateDark);
}
addCrates(-11.3, 12.2);
addCrates(-2.2, 12.3);
addCrates(11.6, 12.25);
function addPerson(x, z, shirtColor, skinColor, facing = 0) {
const group = new THREE.Group();
group.position.set(x, groundY, z);
group.rotation.y = facing;
scene.add(group);
const shirt = material(shirtColor);
const skin = material(skinColor);
const trousers = material(0x3d4d4b);
box(group, [0.32, 0.58, 0.24], [0, 0.93, 0], shirt);
box(group, [0.28, 0.28, 0.28], [0, 1.4, 0], skin, false);
box(group, [0.11, 0.57, 0.14], [-0.09, 0.3, 0], trousers);
box(group, [0.11, 0.57, 0.14], [0.09, 0.3, 0], trousers);
box(group, [0.11, 0.44, 0.14], [-0.24, 0.92, 0], shirt);
box(group, [0.11, 0.44, 0.14], [0.24, 0.92, 0], shirt);
}
addPerson(-8.9, 10.9, 0xa94f3d, 0xbe8862, 0.25);
addPerson(-8.35, 11.0, 0x3c6d67, 0xa9714f, -0.2);
addPerson(-1.3, 10.75, 0xd09b44, 0xc58f67, 0.1);
addPerson(3.7, 11.2, 0x6f809d, 0xb87e59, -0.35);
addPerson(11.8, 10.9, 0x7b8554, 0xa86e4f, 0.4);
// ------------------------------------------------------------
// Small river boat
// ------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(-5.2, 0.15, 5.25);
boat.rotation.y = 0.12;
scene.add(boat);
const hull = material(0x6f4931);
const hullLight = material(0x956b43);
box(boat, [3.5, 0.38, 1.0], [0, 0.24, 0], hull);
box(boat, [0.7, 0.33, 0.8], [2.05, 0.25, 0], hullLight);
box(boat, [0.7, 0.33, 0.8], [-2.05, 0.25, 0], hullLight);
box(boat, [2.55, 0.13, 0.75], [0, 0.48, 0], hullLight);
box(boat, [0.12, 0.12, 2.35], [-0.3, 0.56, 0], material(0x533b2d));
box(boat, [2.6, 0.12, 0.15], [0, 0.55, 0], material(0xc59b5f));
// ------------------------------------------------------------
// Animated water glints
// ------------------------------------------------------------
const glintCount = 90;
const glintMaterial = new THREE.MeshBasicMaterial({
color: 0xd6e2cf,
transparent: true,
opacity: 0.24,
depthWrite: false,
toneMapped: false
});
const glints = new THREE.InstancedMesh(unitBox, glintMaterial, glintCount);
glints.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
glints.frustumCulled = false;
scene.add(glints);
const glintData = [];
const dummy = new THREE.Object3D();
for (let i = 0; i < glintCount; i++) {
const data = {
x: -16.5 + Math.random() * 33,
z: 0.6 + Math.random() * 8.1,
length: 0.35 + Math.random() * 1.45,
phase: Math.random() * Math.PI * 2,
speed: 0.45 + Math.random() * 0.7
};
glintData.push(data);
const color = new THREE.Color().setHSL(
0.39 + Math.random() * 0.04,
0.22,
0.72 + Math.random() * 0.16
);
glints.setColorAt(i, color);
}
if (glints.instanceColor) glints.instanceColor.needsUpdate = true;
// ------------------------------------------------------------
// Ground shadow plane and title plaque
// ------------------------------------------------------------
const shadowFloor = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
material(0xd7ded5, { roughness: 1 })
);
shadowFloor.rotation.x = -Math.PI / 2;
shadowFloor.position.y = -1.49;
shadowFloor.receiveShadow = true;
scene.add(shadowFloor);
addSign(
scene,
"THU BƠN · RIVER SLICE",
8.2,
0.5,
[0, -0.82, -5.53],
{
background: "#706b59",
foreground: "#e8ddbd",
boardColor: 0x625e50
}
);
// ------------------------------------------------------------
// World-space annotations
// ------------------------------------------------------------
const riverTag = document.getElementById("riverTag");
const bridgeTag = document.getElementById("bridgeTag");
const riverAnchor = new THREE.Vector3(-7.1, 0.4, 4.8);
const bridgeAnchor = new THREE.Vector3(9.15, 4.6, 5.15);
function positionTag(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
if (projected.z > 1 || projected.z < -1) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
camera.aspect = aspect;
camera.fov = aspect < 0.8 ? 52 : 39;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
let startTime = performance.now();
let firstFrame = true;
function animate(now) {
const time = (now - startTime) / 1000;
for (let i = 0; i < glintCount; i++) {
const data = glintData[i];
const pulse = 0.55 + 0.45 * Math.sin(time * data.speed + data.phase);
dummy.position.set(
data.x + Math.sin(time * 0.22 + data.phase) * 0.16,
0.071,
data.z
);
dummy.scale.set(
data.length * pulse,
0.012,
0.028 + pulse * 0.018
);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
glints.setMatrixAt(i, dummy.matrix);
}
glints.instanceMatrix.needsUpdate = true;
for (const lantern of lanternGroups) {
lantern.rotation.z = Math.sin(
time * 1.2 + lantern.userData.phase
) * 0.025;
}
boat.position.y = 0.15 + Math.sin(time * 1.1) * 0.025;
boat.rotation.z = Math.sin(time * 0.8) * 0.006;
positionTag(riverTag, riverAnchor);
positionTag(bridgeTag, bridgeAnchor);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("done");
}
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```