Prompt specification
Build or customize the Three.js 3D scene "Suzhou Creek bridge-and-waterfront slice" 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: Suzhou Creek bridge-and-waterfront slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/suzhou-creek-bridge-and-waterfront-slice-x3023
Scene Description Prompt:
Shanghai's Suzhou Creek in voxels: bridge, warehouse forms, linear waterfront, and small public space. Make one HTML file using Three.js from cdnjs.
Working Three.js Starter (suzhou-creek-bridge-and-waterfront-slice-x3023):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shanghai — Suzhou Creek in Voxels</title>
<style>
:root {
--ink: #172326;
--paper: #f2eee3;
--muted: rgba(242, 238, 227, 0.68);
--line: rgba(242, 238, 227, 0.18);
--water: #75aeb0;
--brick: #c87762;
--green: #9db77c;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #aab8b4;
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #172326;
color: #f2eee3;
font: 600 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
#ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.title-panel {
position: absolute;
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
padding: 20px 22px 18px;
border: 1px solid var(--line);
background: linear-gradient(135deg, rgba(15, 27, 30, 0.9), rgba(15, 27, 30, 0.7));
box-shadow: 0 16px 45px rgba(12, 24, 25, 0.16);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 21px;
height: 2px;
background: #d8795f;
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 47px);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.045em;
}
h1 span {
color: #d8795f;
}
.subtitle {
margin: 14px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 9px;
height: 9px;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.2);
}
.swatch.water { background: var(--water); }
.swatch.brick { background: var(--brick); }
.swatch.public { background: var(--green); }
.toolbar {
position: absolute;
top: 28px;
right: 30px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid var(--line);
background: rgba(15, 27, 30, 0.82);
color: var(--paper);
padding: 11px 14px;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(39, 61, 63, 0.95);
transform: translateY(-1px);
}
.bottom-note {
position: absolute;
left: 30px;
right: 30px;
bottom: 24px;
display: flex;
justify-content: space-between;
align-items: end;
color: rgba(23, 35, 38, 0.76);
font: 700 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
text-shadow: 0 1px rgba(255,255,255,.3);
}
.bottom-note .hint {
padding: 9px 12px;
background: rgba(240, 238, 227, 0.67);
border: 1px solid rgba(23, 35, 38, 0.12);
backdrop-filter: blur(8px);
}
.north {
display: flex;
align-items: center;
gap: 8px;
}
.north b {
display: inline-grid;
place-items: center;
width: 26px;
height: 26px;
background: rgba(240, 238, 227, 0.7);
border: 1px solid rgba(23, 35, 38, 0.12);
}
@media (max-width: 700px) {
.title-panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
.subtitle, .legend { display: none; }
h1 { font-size: 30px; }
.toolbar { top: auto; bottom: 58px; right: 14px; }
button { padding: 10px 11px; font-size: 9px; }
.bottom-note { left: 14px; right: 14px; bottom: 14px; }
.bottom-note > span:first-child { display: none; }
}
</style>
</head>
<body>
<div id="loading">Constructing the waterfront…</div>
<div id="ui">
<section class="title-panel">
<div class="eyebrow">Shanghai · 31.24° N</div>
<h1>Suzhou Creek<br><span>in voxels</span></h1>
<p class="subtitle">
An industrial waterfront reduced to blocks: brick warehouses,
a steel truss bridge and a small public commons.
</p>
<div class="legend">
<span><i class="swatch water"></i> Creek</span>
<span><i class="swatch brick"></i> Warehouse edge</span>
<span><i class="swatch public"></i> Public space</span>
</div>
</section>
<nav class="toolbar" aria-label="Scene controls">
<button id="reset" type="button">Reset view</button>
<button id="labels" type="button">Hide labels</button>
<button id="dusk" type="button">Dusk</button>
</nav>
<div class="bottom-note">
<span class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</span>
<span class="north"><b>↑</b> North / upriver</span>
</div>
</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 scene = new THREE.Scene();
const labelGroup = new THREE.Group();
scene.add(labelGroup);
const dayColor = new THREE.Color(0xaab8b4);
const duskColor = new THREE.Color(0x1c2b33);
scene.background = dayColor.clone();
scene.fog = new THREE.Fog(dayColor.clone(), 175, 310);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-80, 80, 50, -50, 0.1, 500);
const hemi = new THREE.HemisphereLight(0xe4eee6, 0x51483d, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.7);
sun.position.set(-38, 82, 48);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -82;
sun.shadow.camera.right = 82;
sun.shadow.camera.top = 65;
sun.shadow.camera.bottom = -65;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 190;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc6cf, 0.7);
fill.position.set(60, 35, -55);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
const M = {
foundation: material(0x263236),
ground: material(0xaeb8ae),
land: material(0x8e927b),
landLight: material(0x999a82),
landDark: material(0x7e836f),
quay: material(0xb9b3a3),
quayDark: material(0x8f9188),
paver: material(0xc7beaa),
paverDark: material(0x9e998d),
road: material(0x454c4b),
roadEdge: material(0x777b73),
water: material(0x477e82, { roughness: 0.3, metalness: 0.18 }),
waterAlt: material(0x4b8587, { roughness: 0.32, metalness: 0.15 }),
waterLight: material(0x78aaab, { roughness: 0.26, metalness: 0.1 }),
brick: material(0xa95542),
brickLight: material(0xbd6c52),
brickDark: material(0x7d443a),
plaster: material(0xc1b69d),
roof: material(0x505957, { roughness: 0.72, metalness: 0.14 }),
roofLight: material(0x6b706a, { roughness: 0.75 }),
metal: material(0x35585d, { roughness: 0.48, metalness: 0.38 }),
metalLight: material(0x6f8887, { roughness: 0.5, metalness: 0.28 }),
rust: material(0xa5523f, { roughness: 0.7, metalness: 0.2 }),
window: material(0x233c44, { roughness: 0.28, metalness: 0.42 }),
windowLit: material(0x9b7950, {
emissive: 0xe6a75e,
emissiveIntensity: 0.25,
roughness: 0.45
}),
wood: material(0x8b6849),
woodLight: material(0xa9845d),
soil: material(0x625744),
grass: material(0x78905f),
grassLight: material(0x91a46d),
leaf: material(0x607c50),
leafLight: material(0x78935b),
leafDark: material(0x4c6847),
orange: material(0xd8753f),
yellow: material(0xd0a447),
blue: material(0x4d7083),
cream: material(0xe4dac3),
white: material(0xe4e1d5),
black: material(0x263033),
skin: material(0xc98e6b),
lamp: material(0xf0cb75, {
emissive: 0xffc45f,
emissiveIntensity: 0.35
})
};
// -------------------------------------------------------------------------
// Instanced voxel builder
// -------------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const batches = new Map();
const tempPosition = new THREE.Vector3();
const tempScale = new THREE.Vector3();
const tempQuaternion = new THREE.Quaternion();
const tempEuler = new THREE.Euler();
const tempMatrix = new THREE.Matrix4();
function voxel(mat, x, y, z, w, h, d, rx = 0, ry = 0, rz = 0) {
if (!batches.has(mat)) batches.set(mat, []);
tempPosition.set(x, y, z);
tempScale.set(w, h, d);
tempEuler.set(rx, ry, rz);
tempQuaternion.setFromEuler(tempEuler);
tempMatrix.compose(tempPosition, tempQuaternion, tempScale);
batches.get(mat).push(tempMatrix.clone());
}
function flushVoxels() {
for (const [mat, matrices] of batches) {
const mesh = new THREE.InstancedMesh(cubeGeometry, mat, matrices.length);
matrices.forEach((matrix, index) => mesh.setMatrixAt(index, matrix));
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = mat !== M.water && mat !== M.waterAlt;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
scene.add(mesh);
}
batches.clear();
}
let seed = 78123;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const hash = (x, z) => {
const n = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return n - Math.floor(n);
};
// -------------------------------------------------------------------------
// Terrain: a long, gently shifting voxel creek
// -------------------------------------------------------------------------
const NX = 56;
const NZ = 32;
const TILE = 2;
function creekCenter(x) {
return -1 + 3.8 * Math.sin(x * 0.045) + x * 0.025;
}
function creekWidth(x) {
return 12 + 1.2 * Math.sin(x * 0.06);
}
const cells = [];
for (let ix = 0; ix < NX; ix++) {
const x = -55 + ix * TILE;
for (let iz = 0; iz < NZ; iz++) {
const z = -31 + iz * TILE;
const center = creekCenter(x);
const water = Math.abs(z - center) < creekWidth(x) * 0.5;
cells.push({ ix, iz, x, z, water });
}
}
voxel(M.foundation, 0, -1.5, 0, 112, 1.1, 64);
voxel(M.waterAlt, 0, -0.62, 0, 112, 0.28, 64);
function isWaterAt(ix, iz) {
if (ix < 0 || ix >= NX || iz < 0 || iz >= NZ) return false;
return cells[iz * NX + ix].water;
}
for (const cell of cells) {
if (cell.water) {
const waterMat = (cell.ix + cell.iz * 3) % 7 === 0 ? M.waterAlt : M.water;
voxel(waterMat, cell.x, -0.30, cell.z, 1.98, 0.30, 1.98);
continue;
}
const adjacentWater =
isWaterAt(cell.ix - 1, cell.iz) ||
isWaterAt(cell.ix + 1, cell.iz) ||
isWaterAt(cell.ix, cell.iz - 1) ||
isWaterAt(cell.ix, cell.iz + 1);
const variation = hash(cell.ix, cell.iz);
const landMat = adjacentWater
? M.quay
: variation > 0.66
? M.landLight
: variation < 0.3
? M.landDark
: M.land;
voxel(landMat, cell.x, -0.15, cell.z, 2, 1.5, 2);
}
// Northern access road and sidewalk.
voxel(M.roadEdge, 0, 0.66, 22.7, 108, 0.13, 2.2);
voxel(M.road, 0, 0.70, 26.0, 108, 0.16, 5.2);
for (let x = -50; x <= 50; x += 8) {
voxel(M.cream, x, 0.805, 26, 3.4, 0.035, 0.18);
}
// Continuous waterfront paths follow the meander of the creek.
for (let x = -52; x <= 52; x += 4) {
const center = creekCenter(x);
const half = creekWidth(x) * 0.5;
const north = center + half + 1.25;
const south = center - half - 1.25;
voxel(M.paver, x, 0.67, north, 4, 0.14, 2.35);
voxel(M.paver, x, 0.67, south, 4, 0.14, 2.35);
voxel(M.quayDark, x, 0.23, center + half, 4, 1.05, 0.38);
voxel(M.quayDark, x, 0.23, center - half, 4, 1.05, 0.38);
if (Math.abs(x - 10) > 7) {
voxel(M.metal, x - 1.7, 1.02, center + half + 0.5, 0.22, 0.8, 0.22);
voxel(M.metal, x - 1.7, 1.02, center - half - 0.5, 0.22, 0.8, 0.22);
}
}
// -------------------------------------------------------------------------
// Warehouses
// -------------------------------------------------------------------------
function warehouse(x, z, w, d, h, wallMat, name) {
const base = 0.6;
const top = base + h;
voxel(wallMat, x, base + h * 0.5, z, w, h, d);
// Horizontal masonry bands.
voxel(M.brickLight, x, base + 0.45, z - d * 0.5 - 0.06, w, 0.32, 0.15);
voxel(M.brickDark, x, top - 0.38, z - d * 0.5 - 0.08, w, 0.38, 0.18);
// Stepped gable roof.
for (let i = 0; i < 3; i++) {
voxel(
i === 1 ? M.roofLight : M.roof,
x,
top + 0.24 + i * 0.38,
z,
w + 1.1,
0.46,
d + 1 - i * 3.25
);
}
// Front elevation: large loading door and industrial windows.
const front = z - d * 0.5 - 0.10;
voxel(M.brickDark, x - w * 0.18, base + 1.8, front, 2.8, 3.6, 0.20);
voxel(M.metalLight, x - w * 0.18, base + 1.8, front - 0.13, 0.16, 3.4, 0.12);
const columns = Math.max(3, Math.floor((w - 4) / 3.3));
const rows = h > 8.8 ? 3 : 2;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const wx = x - w * 0.34 + col * ((w * 0.68) / Math.max(1, columns - 1));
const wy = base + 2.5 + row * 2.05;
const winMat = (row + col + Math.round(x)) % 6 === 0
? M.windowLit
: M.window;
voxel(M.brickDark, wx, wy, front - 0.08, 1.55, 1.42, 0.18);
voxel(winMat, wx, wy, front - 0.20, 1.18, 1.12, 0.12);
voxel(M.roofLight, wx, wy, front - 0.28, 0.09, 1.15, 0.08);
}
}
// Rooftop monitor blocks and chimney.
for (let i = 0; i < 4; i++) {
const rx = x - w * 0.31 + i * (w * 0.62 / 3);
voxel(M.brickDark, rx, top + 1.05, z + 0.4, 2.5, 1.25, 2.7);
voxel(M.window, rx, top + 1.15, z - 1.0, 2.0, 0.62, 0.13);
}
voxel(M.brickDark, x + w * 0.34, top + 1.4, z + d * 0.22, 1.7, 2.8, 1.7);
voxel(M.roof, x + w * 0.34, top + 2.88, z + d * 0.22, 2.0, 0.25, 2.0);
// Side annex and a small dock/platform.
voxel(wallMat, x - w * 0.5 - 2.2, base + 2.25, z + 1.2, 4.4, 4.5, 7);
voxel(M.roof, x - w * 0.5 - 2.2, base + 4.62, z + 1.2, 4.8, 0.35, 7.4);
voxel(M.paverDark, x, base + 0.06, z - d * 0.5 - 2.4, w + 1, 0.2, 4.6);
addLabel(name, "WAREHOUSE", x, top + 4.0, front - 0.8);
}
warehouse(-37, 14, 22, 12, 7.8, M.brick, "07");
warehouse(-10, 15.5, 18, 10.5, 10.2, M.brickLight, "12");
warehouse(30, 19, 27, 11, 7.1, M.brickDark, "03");
// A lower corrugated workshop.
voxel(M.roofLight, 47.5, 3.35, 20, 8, 5.5, 10);
voxel(M.roadEdge, 47.5, 6.18, 20, 8.5, 0.35, 10.5);
for (let i = 0; i < 5; i++) {
voxel(M.metal, 44.25 + i * 1.7, 3.2, 14.92, 0.12, 4.8, 0.12);
}
// -------------------------------------------------------------------------
// Steel truss bridge
// -------------------------------------------------------------------------
const bridgeX = 10;
const bridgeZ = 1;
const bridgeLength = 26;
voxel(M.quayDark, bridgeX, 1.18, bridgeZ, 7.6, 0.85, bridgeLength);
voxel(M.road, bridgeX, 1.63, bridgeZ, 6.2, 0.12, bridgeLength);
voxel(M.metalLight, bridgeX - 3.55, 1.83, bridgeZ, 0.38, 0.55, bridgeLength);
voxel(M.metalLight, bridgeX + 3.55, 1.83, bridgeZ, 0.38, 0.55, bridgeLength);
// Piers descending into the water.
for (const z of [-3.4, 5.2]) {
voxel(M.quayDark, bridgeX, -0.15, z, 3.4, 3.1, 2.0);
voxel(M.quay, bridgeX, 1.35, z, 4.3, 0.35, 2.5);
}
// Abutment ramps.
for (let i = 0; i < 4; i++) {
const stepHeight = 0.22 * (4 - i);
voxel(M.quayDark, bridgeX, 1.45 - i * 0.2, -14.2 + i * 0.85,
7.3, 0.34, 1.0);
voxel(M.quayDark, bridgeX, 1.45 - i * 0.2, 15.0 + i * 0.85,
7.3, 0.34, 1.0);
void stepHeight;
}
for (const side of [-3.15, 3.15]) {
const x = bridgeX + side;
// Lower and upper chords.
voxel(M.rust, x, 2.05, bridgeZ, 0.42, 0.42, bridgeLength);
voxel(M.rust, x, 5.55, bridgeZ, 0.42, 0.42, bridgeLength);
for (let z = -12; z <= 14; z += 3.1) {
voxel(M.rust, x, 3.78, z, 0.30, 3.65, 0.30);
}
// Alternating diagonal members.
for (let z = -12; z < 11; z += 3.1) {
const angle = Math.atan2(3.5, 3.1);
voxel(M.rust, x, 3.75, z + 1.55, 0.25, 0.25, 4.7,
(Math.floor((z + 12) / 3.1) % 2 ? 1 : -1) * angle);
}
}
for (let z = -12; z <= 14; z += 3.1) {
voxel(M.metal, bridgeX, 5.55, z, 6.6, 0.25, 0.25);
if (Math.round((z + 12) / 3.1) % 2 === 0) {
voxel(M.lamp, bridgeX, 5.95, z, 0.36, 0.36, 0.36);
}
}
for (let z = -10; z <= 12; z += 4) {
voxel(M.cream, bridgeX, 1.72, z, 0.13, 0.035, 1.8);
}
addLabel("STEEL TRUSS", "1912 / RENOVATED", bridgeX, 7.4, bridgeZ);
// -------------------------------------------------------------------------
// Small public space: Creek Commons
// -------------------------------------------------------------------------
voxel(M.paverDark, -9, 0.72, -16.2, 26, 0.22, 12.8);
voxel(M.paver, -9, 0.84, -16.2, 25.4, 0.12, 12.2);
// Paving grid.
for (let x = -20; x <= 2; x += 2.5) {
voxel(M.paverDark, x, 0.915, -16.2, 0.055, 0.025, 12.2);
}
for (let z = -21; z <= -11; z += 2.5) {
voxel(M.paverDark, -9, 0.915, z, 25.4, 0.025, 0.055);
}
// Soft lawn block and stepped seating.
voxel(M.grass, 0.5, 0.96, -20.2, 6.2, 0.38, 5.0);
for (let i = 0; i < 3; i++) {
voxel(M.quay, -7 + i * 2.2, 0.96 + i * 0.25, -11.2 - i * 0.7,
2.3, 0.45, 1.6);
}
// Small creek-side kiosk.
voxel(M.cream, -16.7, 2.45, -18.4, 5.4, 3.7, 4.2);
voxel(M.orange, -16.7, 4.48, -18.4, 6.1, 0.45, 5.0);
voxel(M.roof, -16.7, 4.85, -18.4, 5.2, 0.35, 4.2);
voxel(M.window, -16.7, 2.35, -20.56, 3.8, 2.2, 0.18);
voxel(M.wood, -14.95, 1.8, -18.8, 0.22, 2.5, 3.2);
voxel(M.cream, -16.7, 3.45, -20.72, 3.2, 0.6, 0.18);
// Planters.
function planter(x, z, w = 2.4, d = 1.6) {
voxel(M.quayDark, x, 1.05, z, w, 0.65, d);
voxel(M.soil, x, 1.39, z, w - 0.28, 0.12, d - 0.28);
}
planter(-11.5, -11.1, 3.1, 1.4);
planter(-3.2, -11.1, 2.6, 1.4);
planter(1.7, -15.6, 2.0, 3.8);
addLabel("CREEK COMMONS", "PUBLIC SPACE", -9, 5.2, -13.5);
// Trees.
function tree(x, z, scale = 1, base = 0.6) {
voxel(M.wood, x, base + 1.2 * scale, z,
0.42 * scale, 2.4 * scale, 0.42 * scale);
voxel(M.leafDark, x, base + 2.75 * scale, z,
2.55 * scale, 1.45 * scale, 2.45 * scale);
voxel(M.leaf, x, base + 3.65 * scale, z - 0.12,
2.05 * scale, 1.35 * scale, 2.0 * scale);
voxel(M.leafLight, x - 0.2, base + 4.35 * scale, z + 0.1,
1.15 * scale, 0.8 * scale, 1.2 * scale);
}
const publicTrees = [
[-21, -18, 0.95], [-20.5, -13.2, 0.78],
[-12, -13.6, 0.85], [-5.5, -19.8, 0.9],
[-1, -17.7, 0.75], [3.4, -18.3, 0.82]
];
publicTrees.forEach(([x, z, s]) => {
planter(x, z, 2.5 * s, 2.5 * s);
tree(x, z, s, 0.9);
});
// A linear row of trees along the south promenade.
for (const x of [-43, -35, -28, 20, 29, 38, 46]) {
const z = creekCenter(x) - creekWidth(x) * 0.5 - 2.2;
tree(x, z, 0.7 + random() * 0.15, 0.6);
}
// Benches.
function bench(x, z, rotation = 0) {
const c = Math.cos(rotation);
const s = Math.sin(rotation);
const addRotated = (mat, dx, dy, dz, w, h, d) => {
voxel(mat, x + dx * c - dz * s, dy, z + dx * s + dz * c,
w, h, d, 0, rotation, 0);
};
addRotated(M.woodLight, 0, 1.38, 0, 2.6, 0.25, 0.7);
addRotated(M.wood, 0, 1.78, -0.3, 2.6, 0.65, 0.15);
addRotated(M.metal, -0.9, 1.0, 0, 0.18, 0.7, 0.6);
addRotated(M.metal, 0.9, 1.0, 0, 0.18, 0.7, 0.6);
}
bench(-14, -14.2, 0);
bench(-8.5, -19.2, Math.PI / 2);
bench(-2.2, -14.2, 0);
bench(19.5, -13.0, 0);
bench(35.5, -10.7, 0);
// Lamps.
function lamp(x, z) {
voxel(M.metal, x, 2.7, z, 0.18, 4.2, 0.18);
voxel(M.metalLight, x, 4.77, z, 0.72, 0.22, 0.72);
voxel(M.lamp, x, 4.56, z, 0.48, 0.25, 0.48);
}
lamp(-19, -12);
lamp(-6.8, -12);
lamp(4, -15);
lamp(23, -11.4);
lamp(40, -9.6);
// Tiny block people.
function person(x, z, shirtMat, base = 0.9, scale = 1) {
const s = scale;
voxel(shirtMat, x, base + 1.0 * s, z, 0.48 * s, 0.72 * s, 0.36 * s);
voxel(M.skin, x, base + 1.54 * s, z, 0.36 * s, 0.36 * s, 0.36 * s);
voxel(M.black, x - 0.13 * s, base + 0.43 * s, z, 0.16 * s, 0.7 * s, 0.19 * s);
voxel(M.black, x + 0.13 * s, base + 0.43 * s, z, 0.16 * s, 0.7 * s, 0.19 * s);
}
person(-13.2, -15.5, M.orange);
person(-11.8, -16.0, M.blue, 0.9, 0.88);
person(-5.2, -17.6, M.cream);
person(-4.4, -18.2, M.rust, 0.9, 0.95);
person(1.2, -12.8, M.yellow, 0.9, 0.82);
person(18.8, -12.5, M.blue);
person(28.5, -11.8, M.orange, 0.9, 0.92);
// -------------------------------------------------------------------------
// Industrial details: containers, crane and cargo
// -------------------------------------------------------------------------
function container(x, y, z, w, h, d, mat) {
voxel(mat, x, y + h * 0.5, z, w, h, d);
for (let i = -w * 0.35; i <= w * 0.35; i += 0.55) {
voxel(M.roofLight, x + i, y + h * 0.5, z - d * 0.5 - 0.025,
0.07, h * 0.9, 0.06);
}
}
container(48.5, 0.8, 15.0, 6.5, 2.5, 2.8, M.blue);
container(48.5, 3.3, 15.0, 6.5, 2.5, 2.8, M.rust);
container(43.2, 0.8, 14.4, 5.5, 2.5, 2.7, M.orange);
// Voxel gantry crane at the eastern quay.
const craneX = 47;
const craneZ = 10.8;
voxel(M.quayDark, craneX, 0.95, craneZ, 5.2, 0.65, 4.5);
for (const dx of [-1.65, 1.65]) {
for (const dz of [-1.45, 1.45]) {
voxel(M.yellow, craneX + dx, 8.7, craneZ + dz, 0.42, 15.4, 0.42);
}
}
for (let y = 2; y < 15; y += 2.8) {
voxel(M.yellow, craneX, y, craneZ - 1.45, 3.6, 0.26, 0.26);
voxel(M.yellow, craneX, y, craneZ + 1.45, 3.6, 0.26, 0.26);
voxel(M.yellow, craneX - 1.65, y, craneZ, 0.25, 0.25, 3.2);
voxel(M.yellow, craneX + 1.65, y, craneZ, 0.25, 0.25, 3.2);
}
voxel(M.yellow, craneX, 16.2, 5.7, 1.15, 1.0, 12.0);
voxel(M.yellow, craneX, 16.2, 12.3, 1.15, 1.0, 7.0);
voxel(M.black, craneX, 14.6, 2.0, 0.12, 3.0, 0.12);
voxel(M.metal, craneX, 12.9, 2.0, 1.5, 0.65, 1.3);
// -------------------------------------------------------------------------
// Water, barges and reflections
// -------------------------------------------------------------------------
// Flat voxel glints on the creek.
for (let i = 0; i < 78; i++) {
const x = -52 + random() * 104;
const z = creekCenter(x) + (random() - 0.5) * (creekWidth(x) - 2.2);
const w = 0.8 + random() * 2.8;
voxel(M.waterLight, x, -0.095, z, w, 0.035, 0.12 + random() * 0.12);
}
function meshBox(group, mat, x, y, z, w, h, d) {
const mesh = new THREE.Mesh(cubeGeometry, mat);
mesh.position.set(x, y, z);
mesh.scale.set(w, h, d);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
const barge = new THREE.Group();
barge.position.set(-24, 0, creekCenter(-24));
meshBox(barge, M.black, 0, 0.03, 0, 13.5, 0.85, 4.5);
meshBox(barge, M.rust, 0, 0.5, 0, 13.8, 0.22, 4.7);
meshBox(barge, M.cream, -4.6, 1.45, 0, 2.8, 1.8, 3.3);
meshBox(barge, M.window, -4.6, 1.65, -1.69, 2.1, 0.85, 0.12);
meshBox(barge, M.roof, -4.6, 2.45, 0, 3.2, 0.25, 3.7);
meshBox(barge, M.blue, 1.7, 1.55, 0.7, 4.8, 2.0, 1.65);
meshBox(barge, M.orange, 1.7, 1.55, -0.8, 4.8, 2.0, 1.65);
meshBox(barge, M.cream, 3.2, 3.1, 0.3, 1.2, 0.9, 1.1);
scene.add(barge);
const wake = new THREE.Group();
wake.position.set(-31.3, 0, creekCenter(-24));
meshBox(wake, M.waterLight, 0, -0.07, 0.3, 2.2, 0.04, 0.2);
meshBox(wake, M.waterLight, -0.7, -0.065, -0.8, 3.4, 0.04, 0.16);
meshBox(wake, M.waterLight, -1.4, -0.06, 1.1, 2.8, 0.04, 0.14);
scene.add(wake);
// -------------------------------------------------------------------------
// Labels made entirely with core Three.js canvas textures
// -------------------------------------------------------------------------
function addLabel(title, subtitle, x, y, z) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 150;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(20, 35, 38, 0.92)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#d8795f";
ctx.fillRect(0, 0, 10, canvas.height);
ctx.strokeStyle = "rgba(255,255,255,0.2)";
ctx.lineWidth = 2;
ctx.strokeRect(1, 1, canvas.width - 2, canvas.height - 2);
ctx.fillStyle = "#f2eee3";
ctx.font = "700 42px system-ui, sans-serif";
ctx.fillText(title, 30, 58);
ctx.fillStyle = "rgba(242,238,227,0.65)";
ctx.font = "600 20px monospace";
ctx.fillText(subtitle, 31, 103);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.position.set(x, y, z);
sprite.scale.set(13.2, 3.9, 1);
sprite.renderOrder = 20;
labelGroup.add(sprite);
const stem = new THREE.Mesh(cubeGeometry, M.metal);
stem.position.set(x, y - 2.6, z);
stem.scale.set(0.12, 1.8, 0.12);
labelGroup.add(stem);
}
// -------------------------------------------------------------------------
// Ground plane and final voxel flush
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(500, 500),
M.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.08;
ground.receiveShadow = true;
scene.add(ground);
flushVoxels();
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan and zoom
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, 0.8, -1);
const desiredTarget = target.clone();
let theta = 0.62;
let phi = 0.84;
let zoom = 1.0;
let desiredTheta = theta;
let desiredPhi = phi;
let desiredZoom = zoom;
const cameraRadius = 145;
const pointer = new THREE.Vector2();
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
const viewDirection = new THREE.Vector3();
const right = new THREE.Vector3();
const flatForward = new THREE.Vector3();
const worldUp = new THREE.Vector3(0, 1, 0);
function updateCamera() {
const x = target.x + cameraRadius * Math.sin(phi) * Math.sin(theta);
const y = target.y + cameraRadius * Math.cos(phi);
const z = target.z + cameraRadius * Math.sin(phi) * Math.cos(theta);
camera.position.set(x, y, z);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(43, 70 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
camera.getWorldDirection(viewDirection);
right.crossVectors(viewDirection, worldUp).normalize();
flatForward.crossVectors(right, worldUp).normalize();
const panScale = 0.09 / camera.zoom;
desiredTarget.addScaledVector(right, -dx * panScale);
desiredTarget.addScaledVector(flatForward, dy * panScale);
desiredTarget.x = THREE.MathUtils.clamp(desiredTarget.x, -45, 45);
desiredTarget.z = THREE.MathUtils.clamp(desiredTarget.z, -28, 28);
} else {
desiredTheta -= dx * 0.005;
desiredPhi = THREE.MathUtils.clamp(desiredPhi - dy * 0.004, 0.42, 1.18);
}
});
function stopDragging(event) {
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("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
desiredZoom = THREE.MathUtils.clamp(
desiredZoom * Math.exp(-event.deltaY * 0.001),
0.58,
2.65
);
}, { passive: false });
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key === "ArrowLeft") desiredTheta += 0.12;
if (event.key === "ArrowRight") desiredTheta -= 0.12;
if (event.key === "ArrowUp") desiredPhi = THREE.MathUtils.clamp(desiredPhi - 0.08, 0.42, 1.18);
if (event.key === "ArrowDown") desiredPhi = THREE.MathUtils.clamp(desiredPhi + 0.08, 0.42, 1.18);
if (event.key === "+" || event.key === "=") desiredZoom = Math.min(2.65, desiredZoom * 1.1);
if (event.key === "-") desiredZoom = Math.max(0.58, desiredZoom / 1.1);
});
function resetView() {
desiredTheta = 0.62;
desiredPhi = 0.84;
desiredZoom = 1.0;
desiredTarget.set(0, 0.8, -1);
}
document.getElementById("reset").addEventListener("click", resetView);
let labelsVisible = true;
document.getElementById("labels").addEventListener("click", (event) => {
labelsVisible = !labelsVisible;
labelGroup.visible = labelsVisible;
event.currentTarget.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
let dusk = false;
document.getElementById("dusk").addEventListener("click", (event) => {
dusk = !dusk;
scene.background.copy(dusk ? duskColor : dayColor);
scene.fog.color.copy(dusk ? duskColor : dayColor);
hemi.intensity = dusk ? 0.72 : 2.15;
hemi.color.set(dusk ? 0x7794a4 : 0xe4eee6);
sun.intensity = dusk ? 1.15 : 3.7;
sun.color.set(dusk ? 0xffb16d : 0xfff0cf);
fill.intensity = dusk ? 0.42 : 0.7;
renderer.toneMappingExposure = dusk ? 0.92 : 1.08;
M.windowLit.emissiveIntensity = dusk ? 1.65 : 0.25;
M.lamp.emissiveIntensity = dusk ? 2.3 : 0.35;
event.currentTarget.textContent = dusk ? "Day" : "Dusk";
});
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const smooth = 0.085;
theta += (desiredTheta - theta) * smooth;
phi += (desiredPhi - phi) * smooth;
zoom += (desiredZoom - zoom) * smooth;
target.lerp(desiredTarget, smooth);
updateCamera();
const t = clock.getElapsedTime();
barge.position.y = Math.sin(t * 0.8) * 0.06;
barge.rotation.z = Math.sin(t * 0.65) * 0.004;
wake.position.x = -31.3 - Math.sin(t * 0.8) * 0.12;
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```