Prompt specification
Build or customize the Three.js 3D scene "Ponte Vecchio and one riverbank approach" 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: Ponte Vecchio and one riverbank approach
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ponte-vecchio-and-one-riverbank-approach-x2831
Scene Description Prompt:
Make a voxel Ponte Vecchio in Florence with bridge shops and one adjoining riverbank approach. Three.js from cdnjs, one HTML file.
Working Three.js Starter (ponte-vecchio-and-one-riverbank-approach-x2831):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ponte Vecchio — Voxel Florence</title>
<style>
:root {
color-scheme: light;
--ink: #283b3f;
--paper: rgba(255, 250, 238, 0.9);
--gold: #d99a3d;
--line: rgba(40, 59, 63, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9e1e3;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 10;
top: 22px;
left: 24px;
max-width: min(390px, calc(100vw - 48px));
padding: 17px 20px 15px;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 3px;
box-shadow: 0 12px 35px rgba(44, 65, 67, 0.14);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #a86f29;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 43px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.98;
}
.subtitle {
margin-top: 9px;
color: rgba(40, 59, 63, 0.72);
font-size: 12px;
line-height: 1.45;
}
.controls {
position: fixed;
z-index: 12;
right: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: calc(100vw - 44px);
}
button {
appearance: none;
border: 1px solid rgba(40, 59, 63, 0.14);
border-radius: 3px;
padding: 9px 12px;
color: var(--ink);
background: rgba(255, 250, 238, 0.9);
box-shadow: 0 6px 18px rgba(44, 65, 67, 0.1);
font: 700 10px/1 Inter, ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-2px);
background: #fffaf0;
}
button.active {
color: #fffaf0;
background: #31585a;
border-color: #31585a;
}
.hint {
position: fixed;
z-index: 10;
left: 24px;
bottom: 22px;
padding: 9px 12px;
color: rgba(40, 59, 63, 0.72);
background: rgba(255, 250, 238, 0.76);
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 3px;
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
backdrop-filter: blur(10px);
}
.tag {
position: fixed;
z-index: 8;
top: 0;
left: 0;
padding: 5px 8px;
color: #fffaf0;
background: rgba(37, 61, 63, 0.82);
border: 1px solid rgba(255, 255, 255, 0.26);
border-radius: 2px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
backdrop-filter: blur(5px);
}
.loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: #31585a;
background: #d7e8e6;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
transition: opacity 500ms ease;
}
.loading.hide {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
gap: 5px;
}
button {
padding: 8px 9px;
font-size: 9px;
}
.hint {
left: 12px;
bottom: 55px;
max-width: 160px;
line-height: 1.4;
}
}
</style>
</head>
<body>
<section class="title-card">
<div class="eyebrow">Voxel Florence · The Arno</div>
<h1>Ponte Vecchio</h1>
<div class="subtitle">
A block-built interpretation of Florence’s bridge of shops, with its
three stone arches and a single detailed quay approach.
</div>
</section>
<div class="tag" id="tag-shops">Bridge shops</div>
<div class="tag" id="tag-arno">The Arno</div>
<div class="tag" id="tag-quay">Quay approach</div>
<div class="hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom
</div>
<nav class="controls" aria-label="Camera views">
<button data-view="overview" class="active">Overview</button>
<button data-view="shops">Shops</button>
<button data-view="arches">Arches</button>
<button data-view="quay">Quay</button>
<button id="auto-orbit" aria-pressed="false">Auto orbit</button>
</nav>
<div class="loading" id="loading">Building Florence…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, scene, camera
// ---------------------------------------------------------------------
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.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9e1e3);
scene.fog = new THREE.Fog(0xc9e1e3, 25, 58);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xe8f5f3, 0x7e7662, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4b5, 3.1);
sun.position.set(-12, 24, 15);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -22;
sun.shadow.camera.right = 22;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8d5df, 0.8);
fill.position.set(15, 9, -14);
scene.add(fill);
// ---------------------------------------------------------------------
// Shared voxel geometry and material helpers
// ---------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.0
})
);
}
return materialCache.get(key);
}
function box(
parent,
width,
height,
depth,
x,
y,
z,
color,
castShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 1847;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
// ---------------------------------------------------------------------
// Procedural pixel textures
// ---------------------------------------------------------------------
function createMosaicTexture(colors, cells = 16) {
const canvas = document.createElement("canvas");
const size = 256;
const cell = size / cells;
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext("2d");
ctx.fillStyle = colors[0];
ctx.fillRect(0, 0, size, size);
for (let y = 0; y < cells; y++) {
for (let x = 0; x < cells; x++) {
ctx.fillStyle = choose(colors);
ctx.fillRect(
Math.floor(x * cell),
Math.floor(y * cell),
Math.ceil(cell),
Math.ceil(cell)
);
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.LinearMipmapLinearFilter;
return texture;
}
function createCobbleTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#77756c";
ctx.fillRect(0, 0, 256, 256);
const colors = ["#a49d8d", "#918d80", "#b3aa96", "#89877c", "#c0b6a0"];
for (let row = 0; row < 12; row++) {
for (let col = 0; col < 12; col++) {
const offset = row % 2 === 0 ? 0 : 10;
const x = col * 22 - offset;
const y = row * 22;
ctx.fillStyle = choose(colors);
ctx.fillRect(x + 1, y + 1, 19, 19);
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.magFilter = THREE.NearestFilter;
return texture;
}
const waterTexture = createMosaicTexture(
["#3f8291", "#4b95a0", "#347887", "#5a9ca5", "#438c98"],
18
);
waterTexture.repeat.set(11, 15);
const waterMaterial = new THREE.MeshStandardMaterial({
map: waterTexture,
color: 0xffffff,
roughness: 0.34,
metalness: 0.06
});
const river = new THREE.Mesh(new THREE.PlaneGeometry(32, 40), waterMaterial);
river.rotation.x = -Math.PI / 2;
river.position.set(0, -0.035, 0);
river.receiveShadow = true;
scene.add(river);
box(scene, 32, 0.5, 40, 0, -0.34, 0, "#235762", false);
const cobbleTexture = createCobbleTexture();
const cobbleMaterial = new THREE.MeshStandardMaterial({
map: cobbleTexture,
roughness: 0.96
});
function cobblePlane(width, depth, x, z, repeatX, repeatY, y = 2.535) {
const texture = cobbleTexture.clone();
texture.repeat.set(repeatX, repeatY);
texture.needsUpdate = true;
const mat = cobbleMaterial.clone();
mat.map = texture;
const plane = new THREE.Mesh(new THREE.PlaneGeometry(width, depth), mat);
plane.rotation.x = -Math.PI / 2;
plane.position.set(x, y, z);
plane.receiveShadow = true;
scene.add(plane);
return plane;
}
// ---------------------------------------------------------------------
// Riverbanks: one detailed approach at the near end
// ---------------------------------------------------------------------
const stoneColors = ["#b7aa92", "#aa9f8b", "#c1b59c", "#9f9888", "#b0a58f"];
// Near bank, detailed.
box(scene, 26, 2.45, 8.3, 0, 1.225, 10.25, "#737d68", false);
// Near quay retaining wall.
for (let row = 0; row < 5; row++) {
for (let x = -12; x < 12; x += 2) {
box(
scene,
1.93,
0.46,
0.56,
x + 0.96,
0.25 + row * 0.49,
5.93,
choose(stoneColors),
false
);
}
}
// Far bank is deliberately quieter and serves only as geographic context.
box(scene, 26, 2.25, 8.0, 0, 1.125, -10.15, "#75806d", false);
for (let x = -12; x < 12; x += 2) {
box(scene, 1.93, 0.43, 0.5, x + 0.96, 1.13, -6.12, "#999b8d", false);
}
// Approach paving and its direct connection to the bridge.
cobblePlane(3.0, 5.7, 0, 7.45, 1.8, 4.2);
cobblePlane(10.5, 4.2, 0, 8.65, 6.4, 2.7);
// Subtle edge bands around the quay plaza.
box(scene, 11.0, 0.12, 0.28, 0, 2.49, 10.82, "#c0b39a", false);
box(scene, 0.28, 0.12, 4.5, -5.1, 2.49, 8.55, "#c0b39a", false);
box(scene, 0.28, 0.12, 4.5, 5.1, 2.49, 8.55, "#c0b39a", false);
// Quay railing, interrupted at the bridge entrance.
for (let x = -11; x <= 11; x += 2) {
if (Math.abs(x) < 2.5) continue;
box(scene, 0.26, 0.72, 0.26, x, 2.82, 6.22, "#b2a68e");
box(scene, 0.16, 0.12, 0.16, x, 3.22, 6.22, "#8e8777");
}
for (const [left, right] of [[-11.2, -2.3], [2.3, 11.2]]) {
const width = right - left;
box(scene, width, 0.14, 0.18, (left + right) / 2, 3.12, 6.22, "#b9ad93");
}
// Stairway descending from the quay to a lower riverside landing.
for (let i = 0; i < 10; i++) {
const top = 2.38 - i * 0.225;
const z = 5.95 - i * 0.43;
box(scene, 2.25, top, 0.45, 6.4, top / 2, z, choose(stoneColors));
}
box(scene, 2.55, 0.28, 0.8, 6.4, 0.14, 1.53, "#aaa18d");
// Mooring posts.
for (const x of [-9.0, -5.0, 3.8, 9.2]) {
box(scene, 0.34, 0.62, 0.34, x, 2.55, 5.58, "#575951");
box(scene, 0.48, 0.14, 0.48, x, 2.85, 5.58, "#696a60");
}
// Voxel cypress trees.
function cypress(x, z, scale = 1) {
box(scene, 0.32 * scale, 1.7 * scale, 0.32 * scale,
x, 2.45 + 0.85 * scale, z, "#67513b");
const foliage = ["#355b42", "#3f694b", "#496f4d", "#2e533c"];
box(scene, 1.45 * scale, 2.15 * scale, 1.35 * scale,
x, 2.45 + 2.35 * scale, z, foliage[0]);
box(scene, 1.14 * scale, 1.8 * scale, 1.05 * scale,
x, 2.45 + 3.65 * scale, z, foliage[1]);
box(scene, 0.78 * scale, 1.35 * scale, 0.76 * scale,
x, 2.45 + 4.82 * scale, z, foliage[2]);
box(scene, 0.38 * scale, 0.72 * scale, 0.4 * scale,
x, 2.45 + 5.7 * scale, z, foliage[3]);
}
cypress(-8.2, 10.7, 1.0);
cypress(8.4, 11.0, 0.84);
cypress(-10.0, 8.2, 0.72);
// Warm, block-shaped quay lanterns.
const lanternMaterial = new THREE.MeshStandardMaterial({
color: 0xffd17a,
emissive: 0xe99a36,
emissiveIntensity: 1.8,
roughness: 0.45
});
function lantern(x, z) {
box(scene, 0.44, 0.12, 0.44, x, 2.51, z, "#4d5650");
box(scene, 0.12, 2.15, 0.12, x, 3.62, z, "#394643");
box(scene, 0.42, 0.48, 0.42, x, 4.82, z, lanternMaterial);
box(scene, 0.54, 0.12, 0.54, x, 5.12, z, "#3c4945");
box(scene, 0.15, 0.18, 0.15, x, 5.27, z, "#3c4945");
}
lantern(-2.7, 7.0);
lantern(2.7, 7.0);
lantern(-6.3, 9.7);
lantern(6.8, 10.0);
// ---------------------------------------------------------------------
// Ponte Vecchio deck and three segmental arches
// ---------------------------------------------------------------------
const DECK_TOP = 2.70;
const DECK_BOTTOM = 2.35;
const BRIDGE_MIN = -6.1;
const BRIDGE_MAX = 6.15;
const bridgeLength = BRIDGE_MAX - BRIDGE_MIN;
// Deck blocks.
const deckCount = 19;
const deckStep = bridgeLength / deckCount;
for (let i = 0; i < deckCount; i++) {
const z = BRIDGE_MIN + deckStep * (i + 0.5);
box(
scene,
3.4,
0.35,
deckStep * 0.97,
0,
DECK_TOP - 0.175,
z,
i % 3 === 0 ? "#b6aa91" : "#c1b49a"
);
}
// Central pedestrian paving.
for (let z = BRIDGE_MIN + 0.25; z < BRIDGE_MAX; z += 0.58) {
box(
scene,
2.32,
0.055,
0.52,
0,
DECK_TOP + 0.025,
z,
Math.round(z * 3) % 2 === 0 ? "#c8bca3" : "#b9ad94",
false
);
}
// Four piers define three broad arches.
const pierPositions = [-5.7, -2.1, 2.1, 5.7];
for (const z of pierPositions) {
box(scene, 3.18, 2.55, 0.62, 0, 1.275, z, "#8f8b7d");
box(scene, 3.55, 0.30, 0.88, 0, 0.15, z, "#787d73");
box(scene, 3.22, 0.22, 0.72, 0, 2.38, z, "#b0a58e");
}
function buildArchSpan(startZ, endZ, side) {
const center = (startZ + endZ) / 2;
const halfSpan = (endZ - startZ) / 2;
const rise = 1.94;
const base = 0.34;
// Spandrel masonry above each curved opening.
const blocks = 19;
for (let i = 0; i < blocks; i++) {
const t = (i + 0.5) / blocks;
const z = startZ + (endZ - startZ) * t;
const u = (z - center) / halfSpan;
const archY = base + rise * Math.sqrt(Math.max(0, 1 - u * u));
const bottom = Math.min(archY + 0.24, DECK_BOTTOM - 0.05);
const height = Math.max(0.06, DECK_BOTTOM - bottom);
box(
scene,
0.45,
height,
(endZ - startZ) / blocks + 0.025,
side * 1.48,
bottom + height / 2,
z,
choose(stoneColors),
false
);
}
// Rectangular voussoirs form the visible arch curve.
const ringBlocks = 18;
for (let i = 0; i < ringBlocks; i++) {
const angle = (i / (ringBlocks - 1)) * Math.PI;
const z = center + Math.cos(angle) * halfSpan;
const y = base + Math.sin(angle) * rise;
const dz = -halfSpan * Math.sin(angle);
const dy = rise * Math.cos(angle);
const rotation = Math.atan2(dz, dy);
const block = box(
scene,
0.56,
0.43,
0.43,
side * 1.50,
y,
z,
choose(["#c8bba1", "#b9ad96", "#d0c2a6", "#aaa18e"])
);
block.rotation.x = rotation;
}
}
for (const side of [-1, 1]) {
buildArchSpan(-5.7, -2.1, side);
buildArchSpan(-2.1, 2.1, side);
buildArchSpan(2.1, 5.7, side);
}
// Low bridge parapets and the open central loggia.
for (const side of [-1, 1]) {
box(
scene,
0.38,
0.44,
bridgeLength,
side * 1.49,
DECK_TOP + 0.20,
(BRIDGE_MIN + BRIDGE_MAX) / 2,
"#b8aa90"
);
box(
scene,
0.48,
0.10,
bridgeLength,
side * 1.49,
DECK_TOP + 0.46,
(BRIDGE_MIN + BRIDGE_MAX) / 2,
"#c6b89c"
);
}
// ---------------------------------------------------------------------
// Bridge shops and upper stories
// ---------------------------------------------------------------------
const signTextureCache = new Map();
function signTexture(text) {
if (signTextureCache.has(text)) return signTextureCache.get(text);
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#493127";
ctx.fillRect(0, 0, 512, 96);
ctx.strokeStyle = "#d8ad5c";
ctx.lineWidth = 6;
ctx.strokeRect(7, 7, 498, 82);
ctx.fillStyle = "#f4dda4";
ctx.font = "600 38px Georgia";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 50);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.LinearFilter;
signTextureCache.set(text, texture);
return texture;
}
const shopColors = [
"#d0a34f",
"#c77b46",
"#ddbd78",
"#b96945",
"#d7a95d",
"#c98c52"
];
const upperColors = ["#e0b866", "#d69b54", "#c98750", "#e3c17a", "#d49b62"];
const roofColors = ["#9f4937", "#aa5139", "#913f34", "#b35a3c"];
const shutterColors = ["#476456", "#526d5c", "#5f493b", "#42606a"];
const shopNames = [
"GIOIELLI",
"ARTIGIANI",
"FIRENZE",
"ORAFO",
"CAFFÈ",
"GALLERIA"
];
function addWindow(side, z, y, outerX, shutterColor, width = 0.55, height = 0.78) {
// Pale stone frame.
box(
scene,
0.09,
height + 0.16,
width + 0.16,
side * (outerX + 0.025),
y,
z,
"#e0d3b6",
false
);
// Dark glazing.
box(
scene,
0.11,
height,
width,
side * (outerX + 0.078),
y,
z,
"#243a3d",
false
);
// A central mullion.
box(
scene,
0.13,
height,
0.055,
side * (outerX + 0.142),
y,
z,
"#d3c5a7",
false
);
// Wooden shutters.
box(
scene,
0.10,
height + 0.02,
width * 0.44,
side * (outerX + 0.14),
y,
z - width * 0.76,
shutterColor,
false
);
box(
scene,
0.10,
height + 0.02,
width * 0.44,
side * (outerX + 0.14),
y,
z + width * 0.76,
shutterColor,
false
);
}
function addBalcony(side, z, length, y, outerX) {
box(
scene,
0.72,
0.12,
length * 0.78,
side * (outerX + 0.16),
y,
z,
"#c1b397"
);
const barCount = Math.max(3, Math.round(length * 4));
for (let i = 0; i < barCount; i++) {
const localZ = z - length * 0.32 + (length * 0.64 * i) / (barCount - 1);
box(
scene,
0.065,
0.38,
0.065,
side * (outerX + 0.44),
y + 0.24,
localZ,
"#705643",
false
);
}
box(
scene,
0.10,
0.075,
length * 0.72,
side * (outerX + 0.44),
y + 0.46,
z,
"#705643",
false
);
}
function buildShop(side, startZ, endZ, index) {
const gap = 0.09;
const span = endZ - startZ - gap;
const z = startZ + gap / 2 + span / 2;
const lowerColor = shopColors[index % shopColors.length];
const upperColor = upperColors[index % upperColors.length];
const roofColor = roofColors[index % roofColors.length];
const shutterColor = shutterColors[index % shutterColors.length];
// Projecting lower shop volume.
box(scene, 1.43, 2.83, span, side * 2.03, 4.115, z, lowerColor);
box(scene, 1.52, 0.16, span + 0.08, side * 2.03, 2.76, z, "#8c6246");
// Upper residential story, slightly set back.
box(scene, 1.25, 2.38, span - 0.03, side * 1.98, 6.83, z, upperColor);
box(scene, 1.34, 0.16, span + 0.05, side * 1.98, 5.58, z, "#c7b38d");
// Stepped terracotta roof with ridge running along the bridge.
box(scene, 1.58, 0.23, span + 0.12, side * 1.98, 8.10, z, roofColor);
box(scene, 1.22, 0.22, span + 0.10, side * 1.98, 8.32, z, roofColor);
box(scene, 0.83, 0.20, span + 0.08, side * 1.98, 8.52, z, roofColor);
box(scene, 0.43, 0.18, span + 0.07, side * 1.98, 8.70, z, roofColor);
// Shop windows.
addWindow(side, z, 3.55, 2.755, shutterColor, 0.72, 0.93);
// Upper windows.
addWindow(side, z - span * 0.20, 6.62, 2.625, shutterColor, 0.43, 0.77);
addWindow(side, z + span * 0.20, 6.62, 2.625, shutterColor, 0.43, 0.77);
// Projecting balcony.
addBalcony(side, z, span, 6.06, 2.60);
// Bracketed shop overhang.
box(scene, 0.54, 0.40, 0.18, side * 2.27, 2.73, z - span * 0.32, "#705442");
box(scene, 0.54, 0.40, 0.18, side * 2.27, 2.73, z + span * 0.32, "#705442");
// Striped fabric awning.
const stripeCount = 7;
const stripeWidth = (span * 0.85) / stripeCount;
for (let i = 0; i < stripeCount; i++) {
const localZ = z - span * 0.425 + stripeWidth * (i + 0.5);
const awning = box(
scene,
0.78,
0.075,
stripeWidth * 0.92,
side * 2.96,
4.48,
localZ,
i % 2 === 0 ? "#f1ddb3" : (index % 2 ? "#7e3d32" : "#3e6656"),
false
);
awning.rotation.z = side > 0 ? -0.19 : 0.19;
}
// Painted shop sign.
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(span * 0.74, 0.38),
new THREE.MeshBasicMaterial({
map: signTexture(shopNames[index % shopNames.length]),
toneMapped: false
})
);
sign.position.set(side * 2.765, 5.22, z);
sign.rotation.y = side > 0 ? Math.PI / 2 : -Math.PI / 2;
scene.add(sign);
// Small chimney.
box(scene, 0.30, 0.52, 0.34, side * 1.82, 8.72, z + span * 0.24, "#a66b4c");
box(scene, 0.42, 0.11, 0.45, side * 1.82, 9.02, z + span * 0.24, "#765447");
}
const shopRanges = [
[-5.25, -1.05],
[1.05, 5.25]
];
let shopIndex = 0;
for (const side of [-1, 1]) {
for (const range of shopRanges) {
const count = 3;
const total = range[1] - range[0];
const part = total / count;
for (let i = 0; i < count; i++) {
buildShop(
side,
range[0] + part * i,
range[0] + part * (i + 1),
shopIndex++
);
}
}
}
// ---------------------------------------------------------------------
// Water highlights and pixel-like river movement
// ---------------------------------------------------------------------
const foamMaterial = new THREE.MeshStandardMaterial({
color: 0xc5e1dc,
roughness: 0.55,
transparent: true,
opacity: 0.72
});
const foam = [];
for (const z of [-5.7, -2.1, 2.1, 5.7]) {
for (let i = 0; i < 6; i++) {
const mesh = box(
scene,
0.22 + random() * 0.42,
0.045,
0.14 + random() * 0.24,
(random() - 0.5) * 4.4,
0.025,
z + (random() - 0.5) * 1.1,
foamMaterial,
false
);
foam.push({
mesh,
phase: random() * Math.PI * 2,
baseX: mesh.position.x,
baseScaleX: mesh.scale.x
});
}
}
// Sparse distant voxel clouds.
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf5f1df,
roughness: 1
});
function cloud(x, y, z, scale) {
box(scene, 3.0 * scale, 0.75 * scale, 1.0 * scale, x, y, z, cloudMaterial, false);
box(scene, 1.6 * scale, 1.0 * scale, 0.9 * scale, x - 0.7 * scale, y + 0.45 * scale, z, cloudMaterial, false);
box(scene, 1.5 * scale, 0.8 * scale, 0.9 * scale, x + 0.9 * scale, y + 0.3 * scale, z, cloudMaterial, false);
}
cloud(-12, 15, -15, 1.2);
cloud(10, 17, -19, 1.6);
cloud(-18, 18, 2, 1.0);
// ---------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom and view presets
// ---------------------------------------------------------------------
const controls = {
theta: 0.72,
phi: 1.08,
radius: 24,
target: new THREE.Vector3(0, 3.4, 0.8)
};
const desired = {
theta: controls.theta,
phi: controls.phi,
radius: controls.radius,
target: controls.target.clone()
};
function applyCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function setView(name) {
const views = {
overview: {
theta: 0.72,
phi: 1.08,
radius: 24,
target: new THREE.Vector3(0, 3.4, 0.8)
},
shops: {
theta: 1.16,
phi: 1.10,
radius: 12.8,
target: new THREE.Vector3(2.1, 5.0, 1.1)
},
arches: {
theta: 0.55,
phi: 1.38,
radius: 12.5,
target: new THREE.Vector3(0, 1.45, 0.1)
},
quay: {
theta: 0.62,
phi: 1.08,
radius: 13.8,
target: new THREE.Vector3(3.5, 2.6, 7.0)
}
};
const view = views[name];
if (!view) return;
desired.theta = view.theta;
desired.phi = view.phi;
desired.radius = view.radius;
desired.target.copy(view.target);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let autoOrbit = false;
const autoButton = document.getElementById("auto-orbit");
autoButton.addEventListener("click", () => {
autoOrbit = !autoOrbit;
autoButton.classList.toggle("active", autoOrbit);
autoButton.setAttribute("aria-pressed", String(autoOrbit));
autoButton.textContent = autoOrbit ? "Stop orbit" : "Auto orbit";
});
let dragging = false;
let panning = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (panning) {
const scale = desired.radius * 0.00115;
const rightX = Math.cos(desired.theta);
const rightZ = -Math.sin(desired.theta);
const forwardX = -Math.sin(desired.theta);
const forwardZ = -Math.cos(desired.theta);
desired.target.x += (-dx * rightX + dy * forwardX) * scale;
desired.target.z += (-dx * rightZ + dy * forwardZ) * scale;
desired.target.y += dy * scale * 0.25;
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -10, 10);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -8, 11);
desired.target.y = THREE.MathUtils.clamp(desired.target.y, 0.5, 9);
} else {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.24,
1.48
);
}
});
function endDrag(event) {
dragging = false;
panning = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
7.5,
38
);
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Projected labels
// ---------------------------------------------------------------------
const labelData = [
{
element: document.getElementById("tag-shops"),
position: new THREE.Vector3(3.0, 6.2, 2.4)
},
{
element: document.getElementById("tag-arno"),
position: new THREE.Vector3(-6.0, 0.25, -1.2)
},
{
element: document.getElementById("tag-quay"),
position: new THREE.Vector3(4.2, 3.0, 7.6)
}
];
function updateLabels() {
for (const item of labelData) {
const projected = item.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
item.element.style.opacity = visible ? "1" : "0";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
item.element.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (autoOrbit && !dragging) {
desired.theta += dt * 0.065;
}
const damping = 1 - Math.exp(-dt * 8);
controls.theta += (desired.theta - controls.theta) * damping;
controls.phi += (desired.phi - controls.phi) * damping;
controls.radius += (desired.radius - controls.radius) * damping;
controls.target.lerp(desired.target, damping);
applyCamera();
waterTexture.offset.x = (waterTexture.offset.x + dt * 0.008) % 1;
waterTexture.offset.y = (waterTexture.offset.y + dt * 0.002) % 1;
for (const item of foam) {
item.mesh.position.x = item.baseX + Math.sin(time * 0.55 + item.phase) * 0.12;
item.mesh.position.y = 0.025 + Math.sin(time * 1.7 + item.phase) * 0.018;
item.mesh.scale.x = item.baseScaleX * (0.88 + Math.sin(time + item.phase) * 0.12);
}
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("hide");
}
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
applyCamera();
animate();
</script>
</body>
</html>
```