Prompt specification
Build or customize the Three.js 3D scene "Bang Luang wooden walkway and landing stair" 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: Bang Luang wooden walkway and landing stair
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bang-luang-wooden-walkway-and-landing-stair-x2965
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Khlong Bang Luang's canal neighborhood in Bangkok. Build a referenced canal-side fragment with timber walkway, landing steps, and house threshold. Make the separate water-access and pedestrian levels clear within the small model. Voxel style.
Working Three.js Starter (bang-luang-wooden-walkway-and-landing-stair-x2965):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Khlong Bang Luang — Voxel Canal Study</title>
<style>
:root {
color-scheme: light;
--ink: #18383b;
--paper: rgba(247, 244, 232, 0.92);
--upper: #d99a45;
--lower: #43b8ad;
--threshold: #d86f58;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9d4;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(24, 56, 59, 0.18);
box-shadow: 0 12px 35px rgba(24, 56, 59, 0.12);
backdrop-filter: blur(10px);
}
.brand {
top: 22px;
left: 22px;
max-width: min(430px, calc(100vw - 44px));
padding: 17px 20px 16px;
border-radius: 4px;
}
.eyebrow {
margin: 0 0 7px;
color: #688084;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 36px);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
margin: 9px 0 0;
color: #567075;
font-size: 11px;
line-height: 1.5;
}
.reset {
top: 22px;
right: 22px;
padding: 12px 15px;
border-radius: 3px;
color: var(--ink);
font: 700 10px/1 ui-monospace, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
.reset:hover {
background: #fff9e9;
transform: translateY(-1px);
}
.reset:active {
transform: translateY(0);
}
.legend {
right: 22px;
bottom: 22px;
width: 270px;
padding: 16px 17px;
border-radius: 4px;
}
.legend-title {
margin: 0 0 12px;
color: #688084;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr auto;
gap: 9px;
align-items: center;
margin: 9px 0;
font-size: 10px;
}
.legend-row strong {
font-size: 10px;
font-weight: 750;
}
.legend-row span:last-child {
color: #587176;
font-size: 9px;
}
.swatch {
width: 8px;
height: 24px;
border-radius: 1px;
}
.swatch.upper {
background: var(--upper);
}
.swatch.lower {
background: var(--lower);
}
.swatch.threshold {
background: var(--threshold);
}
.hint {
left: 22px;
bottom: 22px;
padding: 10px 13px;
border-radius: 3px;
color: #577176;
font-size: 9px;
line-height: 1.45;
letter-spacing: 0.02em;
}
@media (max-width: 700px) {
.brand {
top: 12px;
left: 12px;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.reset {
top: 12px;
right: 12px;
padding: 10px 11px;
}
.legend {
right: 12px;
bottom: 12px;
width: 218px;
padding: 12px 13px;
}
.hint {
left: 12px;
bottom: 12px;
max-width: 125px;
padding: 8px 9px;
}
.legend-row {
grid-template-columns: 9px 1fr auto;
gap: 7px;
margin: 7px 0;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="panel brand">
<p class="eyebrow">Bangkok · interpretive fragment</p>
<h1>Khlong Bang Luang</h1>
<p class="subtitle">
A voxel study of the canal edge: elevated timber promenade,
stepped water landing, and the threshold of a canal house.
</p>
</header>
<button class="panel reset" id="reset" type="button" aria-label="Reset camera">
Reset view
</button>
<aside class="panel legend" aria-label="Scene level legend">
<p class="legend-title">Three readable levels</p>
<div class="legend-row">
<i class="swatch upper"></i>
<strong>Pedestrian promenade</strong>
<span>+2.2 m</span>
</div>
<div class="legend-row">
<i class="swatch lower"></i>
<strong>Water-access landing</strong>
<span>+0.4 m</span>
</div>
<div class="legend-row">
<i class="swatch threshold"></i>
<strong>House threshold</strong>
<span>+2.5 m</span>
</div>
</aside>
<div class="panel hint">
Drag to orbit<br />
Scroll to zoom<br />
Double-click to reset
</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd9d4);
scene.fog = new THREE.Fog(0xcbd9d4, 38, 68);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of a Bangkok canal-side neighborhood"
);
document.getElementById("scene").appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-16, 16, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.7, -1.4);
const home = {
theta: 0.54,
phi: 0.87,
radius: 30,
zoom: 1
};
const cameraState = { ...home };
const model = new THREE.Group();
scene.add(model);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Preserve the entire cutaway model in narrow portrait layouts.
const frustumHeight = Math.max(19, 34 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
function updateCamera() {
const { theta, phi, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(theta) * Math.sin(phi),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.cos(theta) * Math.sin(phi)
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resetCamera() {
Object.assign(cameraState, home);
updateCamera();
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf1f4df, 0x59665f, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2b6, 3.6);
sun.position.set(-10, 20, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0xa9d8d5, 1.1);
coolFill.position.set(12, 8, -13);
scene.add(coolFill);
// -------------------------------------------------------------------------
// Geometry and material helpers
// -------------------------------------------------------------------------
const geometryCache = new Map();
const materialCache = new Map();
function getMaterial(color, options = {}) {
if (color && color.isMaterial) return color;
const key = `${color}:${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function box(
parent,
width,
height,
depth,
color,
x,
y,
z,
options = {}
) {
const geometryKey = `${width}:${height}:${depth}`;
if (!geometryCache.has(geometryKey)) {
geometryCache.set(
geometryKey,
new THREE.BoxGeometry(width, height, depth)
);
}
const material =
options.material || getMaterial(color, options.materialOptions || {});
const mesh = new THREE.Mesh(
geometryCache.get(geometryKey),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function beam(parent, start, end, thickness, color, options = {}) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = box(
parent,
thickness,
thickness,
length,
color,
(a.x + b.x) / 2,
(a.y + b.y) / 2,
(a.z + b.z) / 2,
options
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
return mesh;
}
function plant(parent, x, y, z, scale = 1, potColor = 0xa65f45) {
const plantGroup = new THREE.Group();
plantGroup.position.set(x, y, z);
plantGroup.scale.setScalar(scale);
parent.add(plantGroup);
box(plantGroup, 0.38, 0.34, 0.38, potColor, 0, 0.17, 0);
box(plantGroup, 0.42, 0.08, 0.42, 0x714337, 0, 0.36, 0);
box(plantGroup, 0.08, 0.58, 0.08, 0x536e42, 0, 0.65, 0);
box(plantGroup, 0.52, 0.28, 0.28, 0x4f7a4a, -0.12, 0.82, 0);
box(plantGroup, 0.28, 0.45, 0.34, 0x638d4e, 0.2, 0.91, 0.02);
box(plantGroup, 0.36, 0.24, 0.32, 0x759951, 0.04, 1.15, -0.03);
return plantGroup;
}
function makeCanvasTexture(draw, width = 768, height = 192) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
return texture;
}
function addSceneLabel(text, accent, position, width = 4.8) {
const texture = makeCanvasTexture(
(context, canvasWidth, canvasHeight) => {
context.clearRect(0, 0, canvasWidth, canvasHeight);
context.fillStyle = "rgba(20, 48, 51, 0.92)";
context.fillRect(0, 0, canvasWidth, canvasHeight);
context.fillStyle = accent;
context.fillRect(0, 0, 18, canvasHeight);
context.fillStyle = "#f7f2dc";
context.font = "700 31px monospace";
context.textBaseline = "middle";
context.fillText(text, 40, canvasHeight / 2 + 1);
context.strokeStyle = "rgba(255,255,255,0.18)";
context.strokeRect(1, 1, canvasWidth - 2, canvasHeight - 2);
},
768,
144
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(...position);
sprite.scale.set(width, width * (144 / 768), 1);
sprite.renderOrder = 20;
model.add(sprite);
return sprite;
}
// -------------------------------------------------------------------------
// Canal cutaway and embankment
// -------------------------------------------------------------------------
box(model, 30, 0.72, 10.2, 0x504d45, 0, -0.83, 5.0);
box(model, 30, 1.8, 11.6, 0x766f60, 0, 0.52, -5.8);
box(model, 30, 0.12, 10.0, 0x3f9399, 0, -0.02, 5.0, {
materialOptions: {
roughness: 0.34,
metalness: 0.08,
transparent: true,
opacity: 0.92
}
});
// Front section of the model, making the water depth readable.
box(model, 30, 0.18, 0.16, 0x344d50, 0, -0.28, 10.02);
box(model, 30, 0.18, 0.16, 0x344d50, 0, -1.11, 10.02);
const stoneColors = [
0x9d9583, 0xaaa08c, 0x8f8879, 0xb0a58f, 0x958e7d
];
for (let i = 0; i < 25; i++) {
const x = -14.4 + i * 1.2;
const color = stoneColors[i % stoneColors.length];
box(
model,
1.13,
1.46,
0.52,
color,
x,
0.69,
0.02
);
}
box(model, 30, 0.15, 0.66, 0xb1a58d, 0, 1.48, 0.04);
// Blocky water ripples.
const rippleMaterial = getMaterial(0xb4ddd5, {
transparent: true,
opacity: 0.62,
roughness: 0.38
});
const ripples = [
[-12.0, 2.4, 1.8, 0.09],
[-10.8, 2.4, 2.5, 0.08],
[-7.4, 6.2, 2.1, 0.08],
[-3.8, 1.8, 1.4, 0.08],
[-2.4, 1.8, 1.8, 0.08],
[0.2, 6.9, 2.8, 0.09],
[7.2, 7.2, 2.3, 0.08],
[8.0, 7.2, 1.4, 0.08],
[11.7, 2.1, 1.7, 0.08],
[11.0, 8.6, 2.2, 0.08]
];
for (const [x, z, width, depth] of ripples) {
box(model, width, 0.025, depth, rippleMaterial, x, 0.065, z, {
castShadow: false
});
}
// -------------------------------------------------------------------------
// Raised pedestrian promenade
// -------------------------------------------------------------------------
const WALK_Y = 2.2;
// Under-structure.
for (const z of [-1.13, 0.15]) {
box(model, 25.8, 0.28, 0.24, 0x4b3428, 0, 1.91, z);
}
for (let x = -12.2; x <= 12.3; x += 3.05) {
for (const z of [-1.12, 0.12]) {
box(model, 0.3, 2.62, 0.3, 0x4d382c, x, 0.73, z);
box(model, 0.42, 0.14, 0.42, 0x342921, x, -0.57, z);
}
}
// Individual teak planks.
const plankColors = [
0x9a673f, 0xa87448, 0x8e5d39, 0xb07b4c, 0x98623d
];
for (let i = 0; i < 49; i++) {
const x = -12.48 + i * 0.52;
box(
model,
0.49,
0.18,
1.78,
plankColors[i % plankColors.length],
x,
WALK_Y - 0.09,
-0.48
);
}
// A narrow ochre edge strip identifies the pedestrian level.
box(model, 25.9, 0.08, 0.13, 0xd99a45, 0, WALK_Y + 0.025, 0.39);
// Canal-side railing, interrupted where the access stair descends.
function railingSegment(x1, x2, z, baseY = WALK_Y) {
const count = Math.max(2, Math.round((x2 - x1) / 1.55));
const step = (x2 - x1) / count;
for (let i = 0; i <= count; i++) {
const x = x1 + i * step;
box(model, 0.13, 0.86, 0.13, 0x593b2c, x, baseY + 0.43, z);
box(model, 0.2, 0.08, 0.2, 0x70452e, x, baseY + 0.04, z);
}
box(model, x2 - x1, 0.12, 0.14, 0x69432e, (x1 + x2) / 2, baseY + 0.83, z);
box(model, x2 - x1, 0.09, 0.11, 0x69432e, (x1 + x2) / 2, baseY + 0.42, z);
}
railingSegment(-12.7, 1.55, 0.39);
railingSegment(5.25, 12.7, 0.39);
// -------------------------------------------------------------------------
// Stair and lower water-access landing
// -------------------------------------------------------------------------
const stairX = 3.4;
const stairWidth = 2.4;
const stepCount = 9;
const stepDepth = 0.37;
for (let i = 0; i < stepCount; i++) {
const top = WALK_Y - i * 0.225;
const z = 0.36 + i * stepDepth;
const bottom = -0.28;
const bodyHeight = top - bottom - 0.06;
box(
model,
stairWidth,
bodyHeight,
stepDepth + 0.04,
i % 2 ? 0xa69b86 : 0xb0a58d,
stairX,
bottom + bodyHeight / 2,
z
);
box(
model,
stairWidth + 0.05,
0.06,
stepDepth + 0.05,
i % 2 ? 0x855538 : 0x93613d,
stairX,
top - 0.03,
z
);
}
// Floating/low landing just above the canal water.
box(model, 2.85, 0.22, 1.48, 0x8b5a3b, stairX, 0.29, 4.03);
box(model, 2.85, 0.07, 0.12, 0x43b8ad, stairX, 0.44, 4.72);
for (const x of [stairX - 1.1, stairX + 1.1]) {
box(model, 0.25, 1.18, 0.25, 0x4c382d, x, -0.05, 4.1);
}
// Stair handrails.
for (const x of [stairX - 1.32, stairX + 1.32]) {
beam(
model,
[x, 3.02, 0.34],
[x, 1.25, 3.47],
0.11,
0x69452f
);
for (const i of [0, 2, 4, 6, 8]) {
const y = WALK_Y - i * 0.225;
const z = 0.36 + i * stepDepth;
box(model, 0.1, 0.92, 0.1, 0x69452f, x, y + 0.46, z);
}
}
// Landing marker and a small mooring cleat.
box(model, 0.1, 1.45, 0.1, 0x344d50, stairX + 1.62, 1.08, 4.15);
box(model, 0.48, 0.28, 0.08, 0x43b8ad, stairX + 1.62, 1.74, 4.15);
box(model, 0.38, 0.12, 0.12, 0x333b39, stairX + 0.85, 0.55, 4.55);
// -------------------------------------------------------------------------
// House approach deck and main canal house
// -------------------------------------------------------------------------
// Deck joining the promenade to the house.
for (let i = 0; i < 18; i++) {
const x = 1.55 + i * 0.52;
box(
model,
0.49,
0.18,
2.9,
plankColors[(i + 2) % plankColors.length],
x,
WALK_Y - 0.09,
-2.78
);
}
// Visible piles under the approach.
for (const x of [2.0, 4.2, 6.4, 8.6, 10.5]) {
box(model, 0.26, 1.5, 0.26, 0x4e392b, x, 1.0, -3.85);
}
const houseX = 6.7;
const houseFront = -4.1;
const houseBack = -9.25;
const houseCenterZ = (houseFront + houseBack) / 2;
// Stilts and floor.
for (const x of [2.8, 6.7, 10.6]) {
for (const z of [-4.45, -6.7, -8.9]) {
box(model, 0.3, 1.65, 0.3, 0x4e382b, x, 1.6, z);
}
}
box(model, 8.55, 0.28, 5.65, 0x6f4932, houseX, 2.34, houseCenterZ);
// Main plaster mass.
box(
model,
8.0,
2.76,
5.15,
0xc4ae82,
houseX,
3.86,
houseCenterZ
);
// Exposed corner posts.
for (const x of [2.73, 10.67]) {
box(model, 0.22, 2.86, 0.22, 0x60402f, x, 3.86, houseFront + 0.03);
box(model, 0.22, 2.86, 0.22, 0x60402f, x, 3.86, houseBack - 0.02);
}
// Door.
box(model, 1.38, 2.12, 0.11, 0x3d3029, 5.05, 3.55, houseFront + 0.07);
box(model, 1.12, 1.98, 0.08, 0x70452e, 5.05, 3.51, houseFront + 0.14);
box(model, 0.88, 1.66, 0.05, 0x835638, 5.05, 3.45, houseFront + 0.20);
box(model, 0.08, 0.12, 0.1, 0xd4b75c, 5.48, 3.42, houseFront + 0.28);
// Raised door threshold, visibly distinct from the promenade.
box(model, 1.62, 0.28, 0.78, 0x8a5738, 5.05, 2.34, houseFront + 0.25);
box(model, 1.65, 0.06, 0.13, 0xd86f58, 5.05, 2.51, houseFront + 0.57);
// Windows.
const windowGlow = getMaterial(0xf1bd64, {
emissive: 0xe69531,
emissiveIntensity: 0.75,
roughness: 0.55
});
for (const x of [7.25, 9.25]) {
box(model, 1.62, 1.12, 0.11, 0x3d4036, x, 3.83, houseFront + 0.08);
box(model, 1.36, 0.88, 0.06, windowGlow, x, 3.83, houseFront + 0.16);
box(model, 0.09, 0.96, 0.09, 0x315f5b, x, 3.83, houseFront + 0.22);
box(model, 1.46, 0.09, 0.09, 0x315f5b, x, 3.83, houseFront + 0.22);
// Teal shutters.
box(model, 0.31, 1.23, 0.1, 0x315f5b, x - 0.98, 3.83, houseFront + 0.17);
box(model, 0.31, 1.23, 0.1, 0x315f5b, x + 0.98, 3.83, houseFront + 0.17);
}
// Horizontal timber lintel.
box(model, 8.15, 0.2, 0.18, 0x68442f, houseX, 5.19, houseFront + 0.09);
// Stepped voxel roof: front slope to a center ridge, then rear slope.
const roofColors = [0x315e5b, 0x376864, 0x2d5654];
for (let i = 0; i < 6; i++) {
const z = -3.94 - i * 0.52;
const y = 5.27 + i * 0.16;
box(
model,
8.95,
0.2,
0.59,
roofColors[i % roofColors.length],
houseX,
y,
z
);
box(
model,
8.95,
0.2,
0.59,
roofColors[(i + 1) % roofColors.length],
houseX,
6.07 - i * 0.16,
-7.14 - i * 0.52
);
}
box(model, 9.05, 0.2, 0.34, 0x244947, houseX, 6.19, -6.55);
// Eave beams.
box(model, 9.05, 0.18, 0.22, 0x4d372b, houseX, 5.21, -3.78);
box(model, 9.05, 0.18, 0.22, 0x4d372b, houseX, 5.21, -9.34);
// Warm porch lanterns.
const lanternMaterial = getMaterial(0xf7c66d, {
emissive: 0xffa43a,
emissiveIntensity: 1.25
});
for (const x of [3.65, 6.48]) {
box(model, 0.12, 0.46, 0.12, 0x3d3029, x, 4.75, houseFront + 0.38);
box(model, 0.3, 0.4, 0.3, lanternMaterial, x, 4.34, houseFront + 0.38);
box(model, 0.38, 0.08, 0.38, 0x4b3628, x, 4.11, houseFront + 0.38);
}
// -------------------------------------------------------------------------
// Smaller neighboring timber house and market front
// -------------------------------------------------------------------------
const leftX = -6.25;
const leftFront = -4.75;
const leftBack = -9.05;
const leftCenter = (leftFront + leftBack) / 2;
for (const x of [-9.1, -6.3, -3.5]) {
for (const z of [-5.05, -8.75]) {
box(model, 0.27, 1.65, 0.27, 0x4a382d, x, 1.58, z);
}
}
box(model, 6.5, 0.25, 4.8, 0x69442f, leftX, 2.31, leftCenter);
box(model, 6.05, 2.58, 4.3, 0x765039, leftX, 3.73, leftCenter);
// Front framing and open shop bay.
box(model, 6.25, 0.18, 0.18, 0x4b3227, leftX, 5.02, leftFront + 0.05);
box(model, 0.2, 2.6, 0.2, 0x4b3227, leftX - 3.0, 3.73, leftFront + 0.05);
box(model, 0.2, 2.6, 0.2, 0x4b3227, leftX + 3.0, 3.73, leftFront + 0.05);
box(model, 0.18, 2.5, 0.2, 0x4b3227, leftX - 0.05, 3.73, leftFront + 0.05);
box(model, 2.0, 1.55, 0.09, 0x2f302a, leftX - 1.42, 3.48, leftFront + 0.12);
box(model, 1.72, 1.3, 0.06, windowGlow, leftX - 1.42, 3.48, leftFront + 0.19);
box(model, 0.08, 1.38, 0.08, 0x56402e, leftX - 1.42, 3.48, leftFront + 0.25);
box(model, 1.55, 1.45, 0.08, 0x35443c, leftX + 1.68, 3.5, leftFront + 0.12);
box(model, 1.3, 1.16, 0.05, windowGlow, leftX + 1.68, 3.5, leftFront + 0.19);
box(model, 0.08, 1.24, 0.08, 0x60432e, leftX + 1.68, 3.5, leftFront + 0.25);
// Corrugated, stepped roof.
for (let i = 0; i < 6; i++) {
const z = leftFront + 0.18 + i * 0.72;
box(
model,
6.75,
0.18,
0.79,
i % 2 ? 0x6f4b3c : 0x7d5542,
leftX,
5.08 + i * 0.085,
z
);
}
// Market awning in alternating blocks.
const awningColors = [0xb85f45, 0xe1c98e, 0xb85f45, 0xe1c98e, 0xb85f45];
for (let i = 0; i < 5; i++) {
box(
model,
1.05,
0.14,
1.05,
awningColors[i],
leftX - 2.1 + i * 1.05,
4.68,
leftFront + 0.53
);
}
// Mounted canvas sign.
const marketSignTexture = makeCanvasTexture((context, width, height) => {
context.fillStyle = "#244a49";
context.fillRect(0, 0, width, height);
context.strokeStyle = "#d7b66d";
context.lineWidth = 8;
context.strokeRect(10, 10, width - 20, height - 20);
context.fillStyle = "#f4dfb0";
context.textAlign = "center";
context.font = "700 52px monospace";
context.fillText("BANG LUANG", width / 2, 82);
context.font = "600 28px monospace";
context.fillStyle = "#d7b66d";
context.fillText("CANAL MARKET", width / 2, 130);
});
const marketSign = new THREE.Mesh(
new THREE.PlaneGeometry(3.9, 0.98),
new THREE.MeshBasicMaterial({ map: marketSignTexture })
);
marketSign.position.set(leftX, 4.08, leftFront + 0.28);
model.add(marketSign);
// Counter and little goods.
box(model, 2.05, 0.7, 0.75, 0x865438, leftX - 1.35, 2.67, leftFront + 0.6);
box(model, 2.2, 0.13, 0.9, 0xa87449, leftX - 1.35, 3.08, leftFront + 0.62);
for (let i = 0; i < 5; i++) {
box(
model,
0.24,
0.25,
0.25,
i % 2 ? 0x7f9a49 : 0xd79b3f,
leftX - 2.05 + i * 0.36,
3.28,
leftFront + 0.58
);
}
// -------------------------------------------------------------------------
// Neighborhood details
// -------------------------------------------------------------------------
// Back wall and a compact background roof silhouette.
box(model, 28, 2.45, 0.3, 0x9c8f76, 0, 2.64, -10.48);
box(model, 5.6, 2.5, 2.2, 0x8d765c, -0.45, 3.76, -10.25);
box(model, 6.2, 0.22, 2.55, 0x5e493b, -0.45, 5.05, -10.2);
// Utility pole.
box(model, 0.19, 4.45, 0.19, 0x514236, -11.35, 3.63, -3.65);
box(model, 2.1, 0.12, 0.14, 0x514236, -11.35, 5.25, -3.65);
box(model, 1.45, 0.1, 0.12, 0x514236, -11.35, 4.75, -3.65);
// Laundry line and hanging cloth.
beam(
model,
[-10.65, 5.05, -3.65],
[-3.55, 4.58, -4.5],
0.045,
0x394746
);
const laundryColors = [0xd86f58, 0x4f91a0, 0xe4d5a6, 0x719365];
for (let i = 0; i < 4; i++) {
const t = i / 4;
const x = -10.1 + i * 1.52;
const y = 5.02 - t * 0.25 - 0.28;
const z = -3.75 - t * 0.62;
box(
model,
0.58,
0.78,
0.045,
laundryColors[i],
x,
y,
z
);
}
// Bench on the pedestrian promenade.
box(model, 2.2, 0.13, 0.55, 0x7f5638, -3.3, 2.65, -0.65);
box(model, 2.2, 0.55, 0.11, 0x8d603d, -3.3, 2.98, -0.92);
for (const x of [-4.1, -2.5]) {
box(model, 0.16, 0.55, 0.42, 0x4d382b, x, 2.42, -0.65);
}
// Pots, herbs, and house-front objects.
plant(model, 1.4, WALK_Y, -2.7, 0.85);
plant(model, 9.95, WALK_Y, -2.85, 1.05);
plant(model, 10.8, WALK_Y, -3.55, 0.72, 0x87664e);
plant(model, -10.7, WALK_Y, -1.55, 0.9);
plant(model, -2.0, WALK_Y, -2.55, 0.75, 0x92714f);
// Blocky tree at the edge of the fragment.
box(model, 0.42, 3.0, 0.42, 0x66513a, -13.0, 2.75, -5.6);
box(model, 2.3, 1.15, 1.8, 0x5d7847, -13.0, 4.25, -5.6);
box(model, 1.6, 1.25, 1.9, 0x718b51, -12.2, 5.15, -5.7);
box(model, 1.45, 0.85, 1.4, 0x4f7045, -13.7, 5.05, -5.4);
// Small exterior stair linking the house deck to its raised threshold.
box(model, 1.7, 0.13, 0.48, 0x7f5337, 5.05, 2.09, houseFront + 0.96);
box(model, 1.55, 0.07, 0.14, 0xd86f58, 5.05, 2.18, houseFront + 1.16);
// -------------------------------------------------------------------------
// Voxel long-tail boat
// -------------------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(-5.4, 0, 4.45);
model.add(boat);
box(boat, 3.45, 0.38, 1.02, 0x46342d, 0, 0.25, 0);
box(boat, 1.15, 0.34, 0.78, 0x46342d, -2.1, 0.25, 0);
box(boat, 0.65, 0.27, 0.52, 0x46342d, -2.85, 0.25, 0);
box(boat, 1.05, 0.42, 0.92, 0x46342d, 2.05, 0.27, 0);
box(boat, 0.6, 0.32, 0.62, 0x46342d, 2.77, 0.28, 0);
box(boat, 2.8, 0.09, 0.72, 0x8a603e, -0.15, 0.48, 0);
box(boat, 0.85, 0.08, 0.55, 0x8a603e, 1.78, 0.52, 0);
// Canopy.
box(boat, 1.62, 0.14, 1.18, 0x3b7772, -0.58, 1.28, 0);
for (const x of [-1.23, 0.08]) {
for (const z of [-0.47, 0.47]) {
box(boat, 0.08, 0.72, 0.08, 0x72513a, x, 0.85, z);
}
}
// Driver, motor, and long-tail propeller housing.
box(boat, 0.32, 0.57, 0.35, 0xcba05e, 1.0, 0.82, 0.05);
box(boat, 0.42, 0.42, 0.42, 0x252c2b, 2.05, 0.78, 0);
box(boat, 0.14, 0.14, 1.25, 0x252c2b, 2.55, 0.18, 0);
box(boat, 0.08, 0.72, 0.08, 0x252c2b, 2.87, 0.55, 0);
// Boat reflection strips.
box(boat, 2.2, 0.035, 0.08, rippleMaterial, -0.35, 0.08, 0.74, {
castShadow: false
});
box(boat, 1.4, 0.035, 0.06, rippleMaterial, 1.35, 0.08, -0.62, {
castShadow: false
});
// -------------------------------------------------------------------------
// Readable level labels
// -------------------------------------------------------------------------
addSceneLabel(
"PEDESTRIAN +2.2 m",
"#d99a45",
[-8.0, 3.58, 0.75],
4.9
);
addSceneLabel(
"WATER ACCESS +0.4 m",
"#43b8ad",
[7.55, 1.05, 4.65],
5.25
);
addSceneLabel(
"DOOR THRESHOLD +2.5 m",
"#d86f58",
[8.05, 3.42, -3.65],
5.25
);
// -------------------------------------------------------------------------
// Custom pointer / keyboard camera controls
// -------------------------------------------------------------------------
const pointer = {
active: false,
id: null,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
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;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.52,
1.32
);
updateCamera();
});
function stopDragging(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
if (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();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.85
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
cameraState.theta += 0.12;
} else if (event.key === "ArrowRight") {
cameraState.theta -= 0.12;
} else if (event.key === "ArrowUp") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi - 0.08, 0.52, 1.32);
} else if (event.key === "ArrowDown") {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + 0.08, 0.52, 1.32);
} else if (event.key === "+" || event.key === "=") {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom + 0.1, 0.62, 1.85);
} else if (event.key === "-") {
cameraState.zoom = THREE.MathUtils.clamp(cameraState.zoom - 0.1, 0.62, 1.85);
} else if (event.key.toLowerCase() === "r") {
resetCamera();
} else {
return;
}
updateCamera();
});
// -------------------------------------------------------------------------
// Start
// -------------------------------------------------------------------------
resize();
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```