Prompt specification
Build or customize the Three.js 3D scene "Cannaregio canal stair and mooring post" 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: Cannaregio canal stair and mooring post
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cannaregio-canal-stair-and-mooring-post-x2873
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Cannaregio's canals and footpaths in Venice. Build a referenced Venice canal-edge fragment with water steps, mooring post, and doorway. Show the separate elevations of boat access and pedestrian paving. Voxel style.
Working Three.js Starter (cannaregio-canal-stair-and-mooring-post-x2873):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dce4dd" />
<title>Cannaregio — At Water Level</title>
<style>
:root {
--ink: #213b3b;
--muted: #617270;
--paper: rgba(248, 246, 235, 0.9);
--paper-solid: #f5f0df;
--line: rgba(33, 59, 59, 0.15);
--water: #4e9b9b;
--paving: #c6b995;
--landing: #d09255;
--accent: #a34f3f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 16%, rgba(255, 249, 226, 0.92), transparent 34%),
linear-gradient(145deg, #d8e2dc 0%, #cbd8d2 55%, #c3d0ca 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
z-index: 5;
pointer-events: none;
}
.intro {
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 20px 22px 19px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 18px 48px rgba(39, 64, 61, 0.12);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3.1vw, 46px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
h1 em {
color: var(--accent);
font-weight: 400;
}
.intro p {
max-width: 310px;
margin: 14px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.place {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 16px;
}
.place span {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 2px;
color: #4a6260;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
top: 24px;
right: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.controls button {
min-height: 40px;
padding: 0 14px;
border: 1px solid rgba(33, 59, 59, 0.16);
border-radius: 2px;
background: rgba(248, 246, 235, 0.88);
color: var(--ink);
box-shadow: 0 10px 30px rgba(39, 64, 61, 0.1);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
.controls button:hover,
.controls button:focus-visible {
transform: translateY(-1px);
border-color: rgba(163, 79, 63, 0.48);
background: #fff9e9;
outline: none;
}
.controls button[aria-pressed="false"] {
color: #8b9693;
}
.section-card {
left: 24px;
bottom: 24px;
width: 315px;
padding: 17px 18px 16px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 3px;
background: rgba(248, 246, 235, 0.87);
box-shadow: 0 16px 40px rgba(39, 64, 61, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.section-head {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 13px;
}
.section-head strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
font-weight: 500;
}
.section-head span {
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.datum {
display: grid;
grid-template-columns: 18px 1fr auto;
align-items: center;
gap: 9px;
min-height: 29px;
border-top: 1px solid var(--line);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.datum:first-of-type {
border-top: 0;
}
.datum i {
width: 13px;
height: 13px;
border: 1px solid rgba(33, 59, 59, 0.14);
}
.datum strong {
font-size: 11px;
letter-spacing: 0;
}
.datum .paving {
background: var(--paving);
}
.datum .landing {
background: var(--landing);
}
.datum .water {
background: var(--water);
}
.section-note {
margin: 11px 0 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.hint {
right: 24px;
bottom: 24px;
display: flex;
gap: 15px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 2px;
background: rgba(248, 246, 235, 0.67);
color: #526663;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.hint span {
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 7px;
opacity: 0;
transition: opacity 140ms ease;
white-space: nowrap;
will-change: transform;
}
.world-label .pin {
position: relative;
width: 8px;
height: 8px;
border: 2px solid #fff8df;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 8px rgba(33, 59, 59, 0.28);
}
.world-label .pin::after {
content: "";
position: absolute;
left: 2px;
top: 6px;
width: 1px;
height: 24px;
background: linear-gradient(rgba(33, 59, 59, 0.6), transparent);
}
.world-label .text {
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 2px;
background: rgba(248, 246, 235, 0.91);
color: var(--ink);
box-shadow: 0 8px 24px rgba(39, 64, 61, 0.12);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.world-label .text small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 650;
letter-spacing: 0.04em;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d6e0da;
color: var(--ink);
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-mark {
text-align: center;
}
.loading-mark::before {
content: "";
display: block;
width: 52px;
height: 12px;
margin: 0 auto 14px;
border-top: 4px solid var(--accent);
border-bottom: 4px solid var(--water);
}
.loading-mark span {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 16px;
}
h1 {
max-width: 280px;
font-size: 31px;
}
.intro p {
display: none;
}
.place {
margin-top: 11px;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
flex-direction: column;
}
.controls button {
min-height: 36px;
padding: 0 10px;
}
.section-card {
left: 12px;
bottom: 12px;
width: min(270px, calc(100vw - 80px));
padding: 12px 13px;
}
.section-note,
.hint {
display: none;
}
.datum {
min-height: 24px;
}
}
@media (max-height: 650px) {
.intro p,
.place,
.section-note {
display: none;
}
.intro {
padding: 13px 16px;
}
.section-card {
padding: 11px 14px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel model of a Cannaregio canal edge in Venice"
></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="ui intro">
<div class="eyebrow">Venice · Cannaregio</div>
<h1>At water<br /><em>level.</em></h1>
<p>
An interpretive voxel fragment of Venice’s raised pedestrian quay,
stepped boat landing, striped mooring post, and canal-facing doorway.
</p>
<div class="place">
<span>Rio edge</span>
<span>Fondamenta</span>
<span>Elevation study</span>
</div>
</header>
<nav class="ui controls" aria-label="Scene controls">
<button id="reset" type="button">Reset view</button>
<button id="plan" type="button">Plan view</button>
<button id="toggle-labels" type="button" aria-pressed="true">Labels</button>
</nav>
<aside class="ui section-card" aria-label="Canal elevation legend">
<div class="section-head">
<strong>Three levels</strong>
<span>Relative section</span>
</div>
<div class="datum">
<i class="paving"></i>
<span>Pedestrian paving</span>
<strong>+1.65 m</strong>
</div>
<div class="datum">
<i class="landing"></i>
<span>Boat access</span>
<strong>+0.15 m</strong>
</div>
<div class="datum">
<i class="water"></i>
<span>Canal water</span>
<strong>0.00 m</strong>
</div>
<p class="section-note">
The quay protects foot traffic from the tide; a lower stone landing
meets the canal for boarding and unloading.
</p>
</aside>
<div class="ui hint" aria-hidden="true">
<span>Drag · orbit</span>
<span>Shift-drag · pan</span>
<span>Wheel · zoom</span>
</div>
<div id="loading">
<div class="loading-mark">
<span>Assembling the canal edge</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";
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd3ded7, 62, 118);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemisphere = new THREE.HemisphereLight(0xf5f4df, 0x65736e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6bc, 3.15);
sun.position.set(-14, 27, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9d3d1, 1.15);
fill.position.set(20, 12, -18);
scene.add(fill);
const root = new THREE.Group();
scene.add(root);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = [
color,
options.roughness ?? 0.88,
options.metalness ?? 0,
options.opacity ?? 1,
options.emissive ?? "",
options.transparent ?? false
].join("|");
if (!materialCache.has(key)) {
const mat = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 1
});
materialCache.set(key, mat);
}
return materialCache.get(key);
}
function addBox(
parent,
width,
height,
depth,
color,
x,
y,
z,
options = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(
geometry,
getMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
const random = seededRandom(7421);
function choose(palette) {
return palette[Math.floor(random() * palette.length)];
}
function addInstancedTiles({
xMin,
xMax,
zMin,
zMax,
y,
width,
depth,
palette,
seedOffset = 0
}) {
const columns = Math.round(xMax - xMin);
const rows = Math.round(zMax - zMin);
const geometry = new THREE.BoxGeometry(width, 0.065, depth);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.86
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
columns * rows
);
const dummy = new THREE.Object3D();
const tileRandom = seededRandom(1987 + seedOffset);
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
dummy.position.set(
xMin + column + width * 0.5,
y,
zMin + row + depth * 0.5
);
dummy.rotation.y = 0;
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const color = new THREE.Color(
palette[Math.floor(tileRandom() * palette.length)]
);
color.offsetHSL(0, 0, (tileRandom() - 0.5) * 0.045);
mesh.setColorAt(index, color);
index++;
}
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.receiveShadow = true;
root.add(mesh);
return mesh;
}
// Ground and cutaway diorama base.
addBox(
root,
120,
0.2,
120,
0xcbd5cd,
0,
-1.53,
0,
{ castShadow: false }
);
addBox(root, 44, 1, 26, 0x999c8d, 0, -0.92, 0);
addBox(root, 43.4, 0.24, 25.2, 0xb7b5a2, 0, -0.53, 0);
// Canal water: opaque voxel tiles establish a pixel-like surface.
addBox(root, 42.2, 0.5, 8.4, 0x397d7d, 0, -0.25, 0);
addInstancedTiles({
xMin: -20.5,
xMax: 20.5,
zMin: -3.5,
zMax: 3.5,
y: 0.015,
width: 0.98,
depth: 0.98,
palette: [
0x4f9290,
0x589d99,
0x468b8b,
0x64a39c,
0x3f8586
],
seedOffset: 10
});
// Small block reflections keep the water surface graphic and voxel-like.
for (let i = 0; i < 28; i++) {
const x = -19 + random() * 38;
const z = -3.3 + random() * 6.6;
const width = 0.25 + random() * 1.25;
addBox(
root,
width,
0.018,
0.07,
random() > 0.45 ? 0x87b9ad : 0x6ba7a2,
x,
0.06,
z,
{ castShadow: false }
);
}
// Raised north quay and lower south footpath.
addBox(root, 42.2, 2.05, 6.2, 0x8f9181, 0, 0.625, -7.3);
addBox(root, 42.2, 1.05, 6.2, 0x919382, 0, 0.125, 7.3);
addInstancedTiles({
xMin: -21,
xMax: 21,
zMin: -9.4,
zMax: -4.4,
y: 1.69,
width: 0.94,
depth: 0.94,
palette: [
0xc8bea0,
0xd0c5a6,
0xbeb397,
0xc6bba0,
0xd4c9ad
],
seedOffset: 30
});
addInstancedTiles({
xMin: -21,
xMax: 21,
zMin: 4.4,
zMax: 9.4,
y: 0.69,
width: 0.94,
depth: 0.94,
palette: [
0xb8b49d,
0xc2bda6,
0xaea994,
0xc7c1a9
],
seedOffset: 50
});
// Coursed retaining walls make the height change legible.
const northStone = [0xa7a58f, 0xb0ad96, 0x999b87];
const southStone = [0x9e9f8d, 0xa8a692];
for (let x = -20; x <= 20; x += 2) {
for (let row = 0; row < 3; row++) {
addBox(
root,
1.92,
0.5,
0.3,
choose(northStone),
x,
0.15 + row * 0.53,
-4.18
);
}
for (let row = 0; row < 2; row++) {
addBox(
root,
1.92,
0.48,
0.3,
choose(southStone),
x,
0.02 + row * 0.5,
4.18
);
}
}
addBox(root, 42.2, 0.14, 0.46, 0xc5bda1, 0, 1.68, -4.39);
addBox(root, 42.2, 0.12, 0.42, 0xb5b097, 0, 0.66, 4.38);
// Water stairs: five descending blocks and a low boat landing.
const stairs = new THREE.Group();
root.add(stairs);
for (let i = 0; i < 5; i++) {
const top = 1.62 - i * 0.294;
const z = -3.94 + i * 0.48;
const height = top + 0.4;
addBox(
stairs,
3.4,
height,
0.5,
i % 2 ? 0xc0b493 : 0xc9bea0,
-5,
(-0.4 + top) * 0.5,
z
);
addBox(
stairs,
3.42,
0.055,
0.09,
0xddd2b2,
-5,
top + 0.025,
z + 0.215
);
}
addBox(stairs, 3.4, 0.55, 1.0, 0xcbbd98, -5, -0.125, -1.43);
addBox(stairs, 3.42, 0.06, 1.01, 0xd9ccaa, -5, 0.18, -1.43);
// Traditional striped Venetian mooring post.
function addMooringPost(x, z, baseY, rotation = 0) {
const post = new THREE.Group();
post.position.set(x, baseY, z);
post.rotation.y = rotation;
root.add(post);
addBox(post, 0.67, 0.22, 0.62, 0x817c68, 0, 0.11, 0);
addBox(post, 0.38, 0.42, 0.38, 0xa64e3f, 0, 0.43, 0);
addBox(post, 0.38, 0.4, 0.38, 0xeee3c7, 0, 0.84, 0);
addBox(post, 0.38, 0.35, 0.38, 0xa64e3f, 0, 1.215, 0);
addBox(post, 0.82, 0.17, 0.46, 0x243a38, 0, 1.47, 0);
addBox(post, 0.53, 0.14, 0.5, 0xeee3c7, 0, 1.61, 0);
}
addMooringPost(-7.35, -3.62, 1.7);
addMooringPost(-1.65, 3.84, 0.67, 0.16);
// Canal buildings with block-built masonry and window recesses.
function addWindow(x, y, z, width = 1.05, height = 1.45, shutter = "#5c7770") {
addBox(root, width, height, 0.08, 0x263c3c, x, y, z + 0.025);
addBox(root, 0.11, height + 0.18, 0.13, 0xd6c9aa, x - width / 2 - 0.05, y, z + 0.09);
addBox(root, 0.11, height + 0.18, 0.13, 0xd6c9aa, x + width / 2 + 0.05, y, z + 0.09);
addBox(root, width + 0.22, 0.12, 0.15, 0xd6c9aa, x, y + height / 2 + 0.04, z + 0.1);
addBox(root, width + 0.34, 0.11, 0.28, 0xe0d2b0, x, y - height / 2 - 0.07, z + 0.13);
addBox(root, 0.27, height, 0.11, shutter, x - width / 2 - 0.28, y, z + 0.11);
addBox(root, 0.27, height, 0.11, shutter, x + width / 2 + 0.28, y, z + 0.11);
}
function addBuilding({
x,
width,
height,
color,
front = -9.55,
depth = 3.05,
windows = [],
doorOffset = null,
roofColor = "#795b4d"
}) {
const base = 1.7;
const left = x - width / 2;
const right = x + width / 2;
const centerZ = front - depth / 2;
if (doorOffset !== null) {
const doorX = x + doorOffset;
const doorWidth = 1.72;
const doorHeight = 2.65;
const doorTop = base + doorHeight;
const doorLeft = doorX - doorWidth / 2;
const doorRight = doorX + doorWidth / 2;
addBox(
root,
doorLeft - left,
height,
depth,
color,
(left + doorLeft) / 2,
base + height / 2,
centerZ
);
addBox(
root,
right - doorRight,
height,
depth,
color,
(doorRight + right) / 2,
base + height / 2,
centerZ
);
addBox(
root,
doorWidth,
height - doorHeight,
depth,
color,
doorX,
doorTop + (height - doorHeight) / 2,
centerZ
);
// Recessed opening, paired green door leaves, stone jambs and stepped arch.
addBox(root, doorWidth, doorHeight, 0.18, 0x172b2b, doorX, base + doorHeight / 2, front - 0.72);
addBox(root, 0.78, doorHeight - 0.08, 0.13, 0x365e50, doorX - 0.39, base + doorHeight / 2, front + 0.055);
addBox(root, 0.78, doorHeight - 0.08, 0.13, 0x3f6758, doorX + 0.39, base + doorHeight / 2, front + 0.055);
addBox(root, 0.08, doorHeight - 0.18, 0.08, 0x789184, doorX - 0.39, base + doorHeight / 2, front + 0.14);
addBox(root, 0.08, doorHeight - 0.18, 0.08, 0x789184, doorX + 0.39, base + doorHeight / 2, front + 0.14);
addBox(root, 0.58, 0.07, 0.08, 0x789184, doorX - 0.39, base + 1.12, front + 0.14);
addBox(root, 0.58, 0.07, 0.08, 0x789184, doorX + 0.39, base + 1.12, front + 0.14);
addBox(root, 0.18, doorHeight + 0.18, 0.24, 0xe0d2b0, doorLeft - 0.08, base + doorHeight / 2, front + 0.13);
addBox(root, 0.18, doorHeight + 0.18, 0.24, 0xe0d2b0, doorRight + 0.08, base + doorHeight / 2, front + 0.13);
addBox(root, doorWidth + 0.5, 0.2, 0.25, 0xe0d2b0, doorX, doorTop + 0.08, front + 0.13);
addBox(root, doorWidth + 0.12, 0.18, 0.26, 0xd2c3a0, doorX, doorTop + 0.28, front + 0.14);
addBox(root, doorWidth - 0.42, 0.17, 0.27, 0xc4b493, doorX, doorTop + 0.46, front + 0.15);
addBox(root, 2.05, 0.18, 0.8, 0xb5ad94, doorX, 1.75, front + 0.37);
addBox(root, 0.1, 0.11, 0.1, 0xd9b66a, doorX + 0.16, base + 1.12, front + 0.2);
} else {
addBox(root, width, height, depth, color, x, base + height / 2, centerZ);
}
// Base course, cornice, and stepped roof.
addBox(root, width + 0.12, 0.26, depth + 0.12, 0x817f6d, x, base + 0.13, centerZ);
addBox(root, width + 0.28, 0.22, depth + 0.28, 0xd0c3a1, x, base + height - 0.08, centerZ);
addBox(root, width - 0.2, 0.36, depth - 0.2, roofColor, x, base + height + 0.18, centerZ);
addBox(root, width - 1.05, 0.34, depth - 0.8, 0x645b4e, x, base + height + 0.5, centerZ);
// Small chimney.
addBox(root, 0.56, 0.8, 0.58, 0x9b6a52, x + width * 0.24, base + height + 0.78, centerZ - 0.35);
addBox(root, 0.7, 0.13, 0.7, 0x6f5548, x + width * 0.24, base + height + 1.22, centerZ - 0.35);
for (const window of windows) {
addWindow(
window.x,
window.y,
front,
window.width ?? 1.05,
window.height ?? 1.45,
window.shutter ?? "#5c7770"
);
}
}
addBuilding({
x: -15.4,
width: 6.4,
height: 6.8,
color: 0xc48663,
roofColor: 0x795044,
windows: [
{ x: -17.0, y: 4.2 },
{ x: -14.1, y: 4.2, shutter: "#8c6a49" },
{ x: -17.0, y: 6.35 },
{ x: -14.1, y: 6.35, shutter: "#8c6a49" }
]
});
addBuilding({
x: -8.0,
width: 7.9,
height: 8.3,
color: 0xd0ad73,
roofColor: 0x765f4e,
windows: [
{ x: -10.2, y: 4.35, shutter: "#4d6863" },
{ x: -7.6, y: 4.35, shutter: "#7e6649" },
{ x: -5.1, y: 4.35, shutter: "#4d6863" },
{ x: -10.2, y: 6.65 },
{ x: -7.6, y: 6.65, shutter: "#7e6649" },
{ x: -5.1, y: 6.65 }
]
});
addBuilding({
x: 2.65,
width: 10.3,
height: 7.35,
color: 0xb96750,
roofColor: 0x715447,
doorOffset: 0.65,
windows: [
{ x: -1.15, y: 4.45, shutter: "#526f68" },
{ x: 1.1, y: 4.45, shutter: "#526f68" },
{ x: 6.0, y: 4.45, shutter: "#8b694a" },
{ x: -1.15, y: 6.65 },
{ x: 1.1, y: 6.65, shutter: "#8b694a" },
{ x: 6.0, y: 6.65 }
]
});
addBuilding({
x: 9.05,
width: 4.8,
height: 8.7,
color: 0xd8c4a3,
roofColor: 0x6e6053,
windows: [
{ x: 7.8, y: 4.4, shutter: "#6b755d" },
{ x: 10.25, y: 4.4, shutter: "#6b755d" },
{ x: 7.8, y: 6.75 },
{ x: 10.25, y: 6.75, shutter: "#6b755d" }
]
});
// Small stepped shop awning beside the featured doorway.
for (let i = 0; i < 5; i++) {
addBox(
root,
0.36,
0.12,
1.35,
i % 2 ? 0xe5dcc4 : 0x53766a,
5.2 + i * 0.36,
3.45 - Math.floor(i / 2) * 0.08,
-8.95
);
}
// A simple block lamp and crates animate the footpath without textures.
addBox(root, 0.12, 2.1, 0.12, 0x263b38, 5.95, 2.77, -9.02);
addBox(root, 0.43, 0.48, 0.43, 0x273c39, 5.95, 3.92, -9.02);
addBox(root, 0.28, 0.3, 0.28, 0xf5d28b, 5.95, 3.92, -8.78, {
emissive: 0xf0b85e,
emissiveIntensity: 0.6
});
addBox(root, 0.65, 0.45, 0.65, 0x9d7549, 6.65, 1.95, -8.75);
addBox(root, 0.55, 0.4, 0.55, 0xb88a50, 7.3, 1.92, -8.5);
addBox(root, 0.45, 0.34, 0.45, 0x607e49, 6.62, 2.32, -8.73);
// Voxel arched bridge in the distance.
const bridge = new THREE.Group();
bridge.position.x = 14.15;
root.add(bridge);
const bridgeDeck = 2.55;
const bridgeStone = [0xb8b49d, 0xc4bea6, 0xaaa994];
for (let z = -4.5; z <= 4.51; z += 0.5) {
const normalized = z / 4.8;
const archY = 0.22 + 1.55 * Math.sqrt(Math.max(0, 1 - normalized * normalized));
const height = bridgeDeck - archY;
addBox(
bridge,
2.65,
height,
0.5,
choose(bridgeStone),
0,
archY + height / 2,
z
);
}
addBox(bridge, 2.85, 0.18, 9.9, 0xcac3aa, 0, bridgeDeck + 0.07, 0);
for (const side of [-1.35, 1.35]) {
for (let z = -4.5; z <= 4.51; z += 0.75) {
addBox(
bridge,
0.28,
0.63,
0.58,
0xc4bda3,
side,
bridgeDeck + 0.46,
z
);
}
addBox(bridge, 0.32, 0.13, 9.65, 0xd2c9ad, side, bridgeDeck + 0.83, 0);
}
// Bridge approach steps.
for (let i = 0; i < 3; i++) {
const top = 1.9 + i * 0.325;
addBox(
bridge,
2.55,
top + 0.4,
0.48,
0xc0b89e,
0,
(-0.4 + top) / 2,
-5.85 + i * 0.43
);
}
for (let i = 0; i < 6; i++) {
const top = 0.95 + i * 0.32;
addBox(
bridge,
2.55,
top + 0.4,
0.48,
0xbab399,
0,
(-0.4 + top) / 2,
5.92 - i * 0.43
);
}
// Gondola: tapering block hull, raised ends, and simple seats.
function addGondola(x, z) {
const boat = new THREE.Group();
boat.position.set(x, 0, z);
root.add(boat);
const widths = [0.34, 0.72, 1.06, 1.18, 1.06, 0.72, 0.34];
const segments = widths.length;
for (let i = 0; i < segments; i++) {
const px = (i - (segments - 1) / 2) * 0.96;
addBox(boat, 1.02, 0.42, widths[i], 0x1d2c2c, px, 0.22, 0);
addBox(boat, 1.02, 0.075, widths[i] + 0.045, 0x3e5450, px, 0.45, 0);
if (i === 0 || i === segments - 1) {
addBox(boat, 0.62, 0.32, widths[i] + 0.07, 0x243535, px, 0.57, 0);
}
}
addBox(boat, 0.67, 0.11, 0.75, 0x79593f, -1.45, 0.52, 0);
addBox(boat, 0.67, 0.11, 0.75, 0x79593f, 0, 0.52, 0);
addBox(boat, 0.67, 0.11, 0.75, 0x79593f, 1.45, 0.52, 0);
addBox(boat, 0.36, 0.13, 0.84, 0xd0ad68, 0.85, 0.61, 0);
}
addGondola(-1.8, 0.55);
// Small utility boat.
const utility = new THREE.Group();
utility.position.set(8.4, 0, 1.4);
root.add(utility);
addBox(utility, 4.2, 0.52, 1.35, 0xd8d5c2, 0, 0.25, 0);
addBox(utility, 3.7, 0.09, 1.42, 0x3f7b83, 0, 0.54, 0);
addBox(utility, 1.3, 0.58, 1.0, 0xb75e43, -0.55, 0.77, 0);
addBox(utility, 1.05, 0.38, 0.82, 0x4a6664, -0.55, 1.22, 0);
addBox(utility, 1.6, 0.24, 0.95, 0x8f7956, 1.05, 0.63, 0);
// A slender rope connects the quay post and the moored boat.
function addBeamBetween(a, b, width, color, parent = root) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const middle = new THREE.Vector3().addVectors(a, b).multiplyScalar(0.5);
const beam = addBox(parent, width, width, length, color, middle.x, middle.y, middle.z);
beam.lookAt(b);
return beam;
}
addBeamBetween(
new THREE.Vector3(-7.35, 3.18, -3.62),
new THREE.Vector3(-4.9, 0.58, -0.2),
0.035,
0xb39a70
);
// Voxel pedestrians reinforce the pedestrian-paving datum.
function addPerson(x, z, baseY, shirt, trousers, skin = 0xc99068, scale = 1) {
const person = new THREE.Group();
person.position.set(x, baseY, z);
person.scale.setScalar(scale);
root.add(person);
addBox(person, 0.13, 0.51, 0.14, trousers, -0.11, 0.27, 0);
addBox(person, 0.13, 0.51, 0.14, trousers, 0.11, 0.27, 0);
addBox(person, 0.46, 0.62, 0.26, shirt, 0, 0.81, 0);
addBox(person, 0.11, 0.48, 0.13, shirt, -0.29, 0.79, 0);
addBox(person, 0.11, 0.48, 0.13, shirt, 0.29, 0.79, 0);
addBox(person, 0.31, 0.32, 0.3, skin, 0, 1.31, 0);
addBox(person, 0.33, 0.09, 0.32, 0x3f4137, 0, 1.49, 0);
}
addPerson(-11.7, -6.4, 1.73, 0xa94f41, 0x394d52);
addPerson(-10.8, -6.0, 1.73, 0xe2d4ac, 0x62594e, 0xb87757, 0.96);
addPerson(-0.8, -7.0, 1.73, 0x456f71, 0x303d3f, 0xd49a73, 1.03);
addPerson(4.5, -7.2, 1.73, 0xc88354, 0x46544f, 0xc98d66, 0.95);
addPerson(6.8, -6.4, 1.73, 0x536b86, 0x4e4942, 0xdfad83, 0.91);
addPerson(-2.2, 6.3, 0.73, 0xd5c59b, 0x43535a, 0xba7a55, 0.98);
addPerson(12.5, 8.0, 0.73, 0x9e5949, 0x35474b, 0xd79b70, 0.94);
// World-space HTML labels.
const labelDefinitions = [
{
text: "Pedestrian paving",
sub: "+1.65 m above canal",
position: new THREE.Vector3(-11.4, 1.85, -6.3),
offset: [-6, 8]
},
{
text: "Boat access",
sub: "+0.15 m landing",
position: new THREE.Vector3(-5.0, 0.35, -1.45),
offset: [-14, 20]
},
{
text: "Canal doorway",
sub: "Raised pedestrian threshold",
position: new THREE.Vector3(3.3, 4.55, -9.35),
offset: [0, -8]
},
{
text: "Mooring post",
sub: "Striped briccola",
position: new THREE.Vector3(-7.35, 3.35, -3.62),
offset: [-15, -14]
},
{
text: "Stone bridge",
sub: "Canal crossing",
position: new THREE.Vector3(14.15, 3.65, 0.2),
offset: [0, -10]
}
];
const worldLabels = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = "world-label";
element.innerHTML = `
<span class="pin"></span>
<span class="text">
${definition.text}
<small>${definition.sub}</small>
</span>
`;
labelsLayer.appendChild(element);
return { ...definition, element };
});
// Custom orbit, pan, pinch and wheel controls — no external addons.
const orbit = {
theta: 0.72,
phi: 0.78,
radius: 48
};
const desiredOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius
};
const target = new THREE.Vector3(0, 1.1, -1.0);
const desiredTarget = target.clone();
const pointers = new Map();
let activePointer = null;
let previousX = 0;
let previousY = 0;
let lastPinchDistance = 0;
let labelsVisible = true;
function updateCamera(instant = false) {
const lerp = instant ? 1 : 0.09;
orbit.theta = THREE.MathUtils.lerp(orbit.theta, desiredOrbit.theta, lerp);
orbit.phi = THREE.MathUtils.lerp(orbit.phi, desiredOrbit.phi, lerp);
orbit.radius = THREE.MathUtils.lerp(orbit.radius, desiredOrbit.radius, lerp);
target.lerp(desiredTarget, lerp);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function panCamera(deltaX, deltaY) {
const scale = orbit.radius * 0.00145;
const right = new THREE.Vector3(
Math.cos(desiredOrbit.theta),
0,
-Math.sin(desiredOrbit.theta)
);
const forward = new THREE.Vector3(
Math.sin(desiredOrbit.theta),
0,
Math.cos(desiredOrbit.theta)
);
desiredTarget.addScaledVector(right, -deltaX * scale);
desiredTarget.addScaledVector(forward, deltaY * scale);
desiredTarget.x = THREE.MathUtils.clamp(desiredTarget.x, -18, 18);
desiredTarget.z = THREE.MathUtils.clamp(desiredTarget.z, -12, 12);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
}
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0 && distance > 0) {
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * (lastPinchDistance / distance),
22,
78
);
}
lastPinchDistance = distance;
return;
}
if (event.pointerId !== activePointer) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey || event.buttons === 2) {
panCamera(deltaX, deltaY);
} else {
desiredOrbit.theta -= deltaX * 0.006;
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi - deltaY * 0.005,
0.16,
1.34
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (activePointer === event.pointerId) activePointer = null;
if (pointers.size < 2) lastPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * Math.exp(event.deltaY * 0.001),
22,
78
);
},
{ passive: false }
);
function resetView() {
desiredOrbit.theta = 0.72;
desiredOrbit.phi = 0.78;
desiredOrbit.radius = 48;
desiredTarget.set(0, 1.1, -1.0);
}
document.querySelector("#reset").addEventListener("click", resetView);
document.querySelector("#plan").addEventListener("click", () => {
desiredOrbit.theta = 0.72;
desiredOrbit.phi = 0.17;
desiredOrbit.radius = 44;
desiredTarget.set(0, 0.6, -0.6);
});
const labelsButton = document.querySelector("#toggle-labels");
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelsButton.setAttribute("aria-pressed", String(labelsVisible));
labelsLayer.style.display = labelsVisible ? "block" : "none";
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
switch (event.key) {
case "ArrowLeft":
desiredOrbit.theta += 0.12;
break;
case "ArrowRight":
desiredOrbit.theta -= 0.12;
break;
case "ArrowUp":
desiredOrbit.phi = Math.max(0.16, desiredOrbit.phi - 0.08);
break;
case "ArrowDown":
desiredOrbit.phi = Math.min(1.34, desiredOrbit.phi + 0.08);
break;
case "+":
case "=":
desiredOrbit.radius = Math.max(22, desiredOrbit.radius - 3);
break;
case "-":
desiredOrbit.radius = Math.min(78, desiredOrbit.radius + 3);
break;
case "r":
case "R":
resetView();
break;
}
});
function updateLabels() {
if (!labelsVisible) return;
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of worldLabels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!visible) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * width + label.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + label.offset[1];
label.element.style.opacity = "1";
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
updateCamera(true);
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
updateCamera(false);
renderer.render(scene, camera);
updateLabels();
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("hidden"));
}
}
animate();
</script>
</body>
</html>
```