Prompt specification
Build or customize the Three.js 3D scene "Ponte Vecchio shop projection and support detail" 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 shop projection and support detail
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ponte-vecchio-shop-projection-and-support-detail-x2829
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Ponte Vecchio in Florence. Build a referenced shop-bay fragment projecting from the bridge edge. Show wall, window, and support relationships while preserving a clear distinction between building and river below. Low-poly.
Working Three.js Starter (ponte-vecchio-shop-projection-and-support-detail-x2829):
```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 — Riverside Shop-Bay Study</title>
<style>
:root {
--ink: #28343a;
--paper: #f3ecdf;
--ochre: #d7a33e;
--timber: #674535;
--river: #387c82;
--glass: #29474d;
--green: #41645b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded7ca;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(40, 52, 58, 0.24);
background: rgba(243, 236, 223, 0.91);
box-shadow: 0 14px 35px rgba(32, 40, 43, 0.12);
backdrop-filter: blur(8px);
}
#title {
top: 22px;
left: 22px;
max-width: 390px;
padding: 17px 20px 16px;
pointer-events: none;
}
#title .eyebrow,
#detail-card .eyebrow {
margin-bottom: 6px;
color: #7f6540;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#title h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1.02;
}
#title p {
margin: 10px 0 0;
max-width: 330px;
color: rgba(40, 52, 58, 0.72);
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 1.5;
}
#detail-card {
top: 22px;
right: 22px;
width: 286px;
padding: 17px 18px 16px;
}
#detail-card h2 {
margin: 0 0 6px;
font-size: 21px;
font-weight: 500;
}
#detail-card > p {
margin: 0 0 14px;
color: rgba(40, 52, 58, 0.72);
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
line-height: 1.5;
}
.legend {
display: grid;
gap: 7px;
margin: 0 0 15px;
padding: 12px 0;
border-top: 1px solid rgba(40, 52, 58, 0.15);
border-bottom: 1px solid rgba(40, 52, 58, 0.15);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
}
.swatch {
width: 13px;
height: 13px;
flex: 0 0 auto;
border: 1px solid rgba(40, 52, 58, 0.18);
}
.swatch.wall { background: var(--ochre); }
.swatch.window { background: var(--glass); }
.swatch.support { background: var(--timber); }
.swatch.river { background: var(--river); }
.button-row {
display: flex;
gap: 7px;
}
button {
flex: 1;
min-height: 34px;
padding: 8px 10px;
border: 1px solid rgba(40, 52, 58, 0.35);
border-radius: 0;
background: transparent;
color: var(--ink);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
transition: background 140ms ease, color 140ms ease;
}
button:hover,
button:focus-visible {
background: var(--ink);
color: var(--paper);
outline: none;
}
#help {
position: fixed;
z-index: 10;
bottom: 18px;
left: 22px;
padding: 8px 11px;
background: rgba(243, 236, 223, 0.78);
color: rgba(40, 52, 58, 0.7);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
#detail-tag {
position: fixed;
z-index: 8;
top: 0;
left: 0;
padding: 6px 8px;
border-left: 2px solid var(--ochre);
background: rgba(243, 236, 223, 0.88);
color: var(--ink);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -115%);
white-space: nowrap;
}
@media (max-width: 760px) {
#title {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 12px 15px;
}
#title p {
display: none;
}
#detail-card {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 13px 15px;
}
#detail-card > p,
.legend {
display: none;
}
#detail-card h2 {
margin-bottom: 10px;
font-size: 17px;
}
#help {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly model of Ponte Vecchio"></canvas>
<section id="title" class="panel">
<div class="eyebrow">Florence · Arno River</div>
<h1>Ponte Vecchio</h1>
<p>
A low-poly architectural study of the bridge’s inhabited edge, with one
projecting riverside shop bay selected as the reference fragment.
</p>
</section>
<aside id="detail-card" class="panel">
<div class="eyebrow">Reference fragment · 01</div>
<h2>Riverside shop bay</h2>
<p>
The ochre volume projects beyond the bridge cornice. Its dark window is
inset into the wall, while timber brackets carry the bay above the Arno.
</p>
<div class="legend">
<div class="legend-row">
<span class="swatch wall"></span>
<span>Projecting wall volume</span>
</div>
<div class="legend-row">
<span class="swatch window"></span>
<span>Inset window and shutters</span>
</div>
<div class="legend-row">
<span class="swatch support"></span>
<span>Timber support brackets</span>
</div>
<div class="legend-row">
<span class="swatch river"></span>
<span>River plane below</span>
</div>
</div>
<div class="button-row">
<button id="view-whole" type="button">Whole bridge</button>
<button id="view-detail" type="button">Focus bay</button>
</div>
</aside>
<div id="detail-tag">01 / Shop-bay reference</div>
<div id="help">Drag to orbit · Right-drag to pan · Scroll to zoom · Click the ochre bay</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 detailTag = document.querySelector("#detail-tag");
const renderer = new THREE.WebGLRenderer({
canvas,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded7ca);
scene.fog = new THREE.Fog(0xded7ca, 42, 92);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
// ---------------------------------------------------------------------
// Camera controls implemented directly, without addons.
// ---------------------------------------------------------------------
const currentView = {
target: new THREE.Vector3(0, 3.25, 0),
spherical: new THREE.Spherical(29, 1.16, 0.69)
};
const desiredView = {
target: currentView.target.clone(),
spherical: currentView.spherical.clone()
};
const cameraOffset = new THREE.Vector3();
function updateCamera(dt) {
const smoothing = 1 - Math.pow(0.0007, dt);
currentView.target.lerp(desiredView.target, smoothing);
const thetaDifference = Math.atan2(
Math.sin(desiredView.spherical.theta - currentView.spherical.theta),
Math.cos(desiredView.spherical.theta - currentView.spherical.theta)
);
currentView.spherical.radius = THREE.MathUtils.lerp(
currentView.spherical.radius,
desiredView.spherical.radius,
smoothing
);
currentView.spherical.phi = THREE.MathUtils.lerp(
currentView.spherical.phi,
desiredView.spherical.phi,
smoothing
);
currentView.spherical.theta += thetaDifference * smoothing;
cameraOffset.setFromSpherical(currentView.spherical);
camera.position.copy(cameraOffset).add(currentView.target);
camera.lookAt(currentView.target);
}
function setView(target, radius, phi, theta) {
desiredView.target.copy(target);
desiredView.spherical.radius = radius;
desiredView.spherical.phi = phi;
desiredView.spherical.theta = theta;
}
const pointers = new Map();
let controlMode = "orbit";
let lastPinchDistance = 0;
let dragDistance = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
controlMode = event.button === 2 ? "pan" : "orbit";
dragDistance = 0;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragDistance += Math.hypot(dx, dy);
if (controlMode === "orbit") {
currentView.spherical.theta -= dx * 0.006;
currentView.spherical.phi -= dy * 0.006;
currentView.spherical.phi = THREE.MathUtils.clamp(
currentView.spherical.phi,
0.22,
1.46
);
desiredView.spherical.theta = currentView.spherical.theta;
desiredView.spherical.phi = currentView.spherical.phi;
} else {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
const matrix = new THREE.Matrix4();
matrix.extractRotation(camera.matrix);
right.setFromMatrixColumn(matrix, 0);
up.setFromMatrixColumn(matrix, 1);
const scale = currentView.spherical.radius * 0.00125;
currentView.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
currentView.target.y = THREE.MathUtils.clamp(
currentView.target.y,
0.5,
12
);
desiredView.target.copy(currentView.target);
}
} else 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) {
const scale = lastPinchDistance / distance;
currentView.spherical.radius = THREE.MathUtils.clamp(
currentView.spherical.radius * scale,
7,
65
);
desiredView.spherical.radius = currentView.spherical.radius;
}
lastPinchDistance = distance;
}
});
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
canvas.addEventListener("pointerup", (event) => {
const wasSinglePointer = pointers.size === 1;
pointers.delete(event.pointerId);
if (pointers.size < 2) {
lastPinchDistance = 0;
}
if (wasSinglePointer && dragDistance < 5 && event.button === 0) {
const bounds = canvas.getBoundingClientRect();
pointerNDC.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
if (raycaster.intersectObject(detailGroup, true).length > 0) {
focusDetail();
}
}
});
canvas.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
lastPinchDistance = 0;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
currentView.spherical.radius = THREE.MathUtils.clamp(
currentView.spherical.radius * factor,
7,
65
);
desiredView.spherical.radius = currentView.spherical.radius;
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Lighting and materials.
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff4d8, 0x42676b, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe8bd, 3.0);
sun.position.set(-14, 24, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8bb7c1, 0.8);
fill.position.set(18, 9, -16);
scene.add(fill);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
flatShading: true,
...extra
});
const mat = {
stone: material(0xb9a98d),
stoneLight: material(0xcdbda0),
stoneDark: material(0x8f8069),
bank: material(0xa99f88),
timber: material(0x654432),
timberLight: material(0x806048),
roof: material(0x9e4f3f),
roofDark: material(0x7c4038),
wallGold: material(0xd2a03b),
wallOchre: material(0xc58f3d),
wallCream: material(0xdccba2),
wallRose: material(0xc9896f),
wallPale: material(0xc9b99a),
wallSage: material(0xb8ad83),
glass: material(0x203c42, { roughness: 0.42, metalness: 0.08 }),
shutter: material(0x3d655d),
shutterLight: material(0x52776c),
trim: material(0xe4d7bb),
selectedTrim: material(0xf2d898),
dark: material(0x3c484a)
};
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
mat
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBeam(parent, start, end, width, mat) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const beam = new THREE.Mesh(
new THREE.BoxGeometry(width, length, width),
mat
);
beam.position.copy(midpoint);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
beam.castShadow = true;
beam.receiveShadow = true;
parent.add(beam);
return beam;
}
function addOutline(parent, size, position, rotation = null) {
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(size.x, size.y, size.z)),
new THREE.LineBasicMaterial({
color: 0xffedb8,
transparent: true,
opacity: 0.72
})
);
outline.position.copy(position);
if (rotation) {
outline.rotation.copy(rotation);
}
parent.add(outline);
return outline;
}
// ---------------------------------------------------------------------
// Faceted river and riverbanks.
// ---------------------------------------------------------------------
const riverGroup = new THREE.Group();
scene.add(riverGroup);
const waterBase = new THREE.Mesh(
new THREE.PlaneGeometry(23, 70),
material(0x36777d, { roughness: 0.38, metalness: 0.08 })
);
waterBase.rotation.x = -Math.PI / 2;
waterBase.position.y = -0.22;
waterBase.receiveShadow = true;
riverGroup.add(waterBase);
function makeFacetedWater() {
const nx = 12;
const nz = 36;
const width = 23;
const length = 70;
const positions = [];
const indices = [];
for (let iz = 0; iz <= nz; iz++) {
for (let ix = 0; ix <= nx; ix++) {
positions.push(
-width / 2 + (ix / nx) * width,
-0.13 + Math.sin(ix * 1.71 + iz * 0.93) * 0.025,
-length / 2 + (iz / nz) * length
);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
if ((ix + iz) % 2 === 0) {
indices.push(a, c, b, b, c, d);
} else {
indices.push(a, d, c, a, b, d);
}
}
}
let geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry = geometry.toNonIndexed();
const colors = [];
const waterPalette = [
new THREE.Color(0x3d8589),
new THREE.Color(0x34777d),
new THREE.Color(0x458f91),
new THREE.Color(0x2f7077)
];
const positionAttribute = geometry.getAttribute("position");
for (let i = 0; i < positionAttribute.count; i += 3) {
const color =
waterPalette[Math.floor(Math.random() * waterPalette.length)];
for (let j = 0; j < 3; j++) {
colors.push(color.r, color.g, color.b);
}
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
const water = new THREE.Mesh(
geometry,
material(0xffffff, {
vertexColors: true,
roughness: 0.44,
metalness: 0.06
})
);
water.receiveShadow = true;
riverGroup.add(water);
}
makeFacetedWater();
addBox(
scene,
new THREE.Vector3(26, 1.1, 80),
new THREE.Vector3(-24.5, -0.35, 0),
mat.bank,
false
);
addBox(
scene,
new THREE.Vector3(26, 1.1, 80),
new THREE.Vector3(24.5, -0.35, 0),
mat.bank,
false
);
// ---------------------------------------------------------------------
// Ponte Vecchio bridge: piers, faceted arch rings, deck and cornice.
// ---------------------------------------------------------------------
const bridgeGroup = new THREE.Group();
scene.add(bridgeGroup);
const archCenters = [-7.5, 0, 7.5];
const innerRadiusX = 3.7;
const innerRadiusY = 2.05;
const outerRadiusX = 4.25;
const outerRadiusY = 2.6;
const springHeight = 1.0;
const archSegments = 12;
function createArchSegment(centerX, angleA, angleB, materialIndex) {
const shape = new THREE.Shape();
const innerA = new THREE.Vector2(
centerX + Math.cos(angleA) * innerRadiusX,
springHeight + Math.sin(angleA) * innerRadiusY
);
const innerB = new THREE.Vector2(
centerX + Math.cos(angleB) * innerRadiusX,
springHeight + Math.sin(angleB) * innerRadiusY
);
const outerB = new THREE.Vector2(
centerX + Math.cos(angleB) * outerRadiusX,
springHeight + Math.sin(angleB) * outerRadiusY
);
const outerA = new THREE.Vector2(
centerX + Math.cos(angleA) * outerRadiusX,
springHeight + Math.sin(angleA) * outerRadiusY
);
shape.moveTo(innerA.x, innerA.y);
shape.lineTo(innerB.x, innerB.y);
shape.lineTo(outerB.x, outerB.y);
shape.lineTo(outerA.x, outerA.y);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 5.0,
bevelEnabled: false,
curveSegments: 1
});
const archMaterial = [
mat.stone,
mat.stoneLight,
mat.stoneDark
][materialIndex % 3];
const mesh = new THREE.Mesh(geometry, archMaterial);
mesh.position.z = -2.5;
mesh.castShadow = true;
mesh.receiveShadow = true;
bridgeGroup.add(mesh);
}
archCenters.forEach((centerX, centerIndex) => {
for (let i = 0; i < archSegments; i++) {
createArchSegment(
centerX,
(i / archSegments) * Math.PI,
((i + 1) / archSegments) * Math.PI,
i + centerIndex
);
}
});
[-11.7, -3.75, 3.75, 11.7].forEach((x, index) => {
addBox(
bridgeGroup,
new THREE.Vector3(index === 0 || index === 3 ? 1.15 : 1.05, 4.15, 5.15),
new THREE.Vector3(x, 2.15, 0),
index % 2 ? mat.stoneDark : mat.stone
);
});
addBox(
bridgeGroup,
new THREE.Vector3(25.2, 0.48, 5.25),
new THREE.Vector3(0, 4.18, 0),
mat.stoneLight
);
addBox(
bridgeGroup,
new THREE.Vector3(25.45, 0.28, 5.5),
new THREE.Vector3(0, 4.55, 0),
mat.stone
);
[-2.48, 2.48].forEach((z) => {
addBox(
bridgeGroup,
new THREE.Vector3(25.0, 0.48, 0.34),
new THREE.Vector3(0, 4.83, z),
mat.stoneLight
);
});
// ---------------------------------------------------------------------
// Reusable inset windows with shutters.
// ---------------------------------------------------------------------
function makeWindow(width, height, frameMaterial = mat.trim) {
const group = new THREE.Group();
const pane = addBox(
group,
new THREE.Vector3(width, height, 0.09),
new THREE.Vector3(0, 0, 0),
mat.glass,
false
);
pane.receiveShadow = true;
addBox(
group,
new THREE.Vector3(0.12, height + 0.25, 0.14),
new THREE.Vector3(-width / 2 - 0.06, 0, 0.07),
frameMaterial,
false
);
addBox(
group,
new THREE.Vector3(0.12, height + 0.25, 0.14),
new THREE.Vector3(width / 2 + 0.06, 0, 0.07),
frameMaterial,
false
);
addBox(
group,
new THREE.Vector3(width + 0.26, 0.12, 0.14),
new THREE.Vector3(0, height / 2 + 0.06, 0.07),
frameMaterial,
false
);
addBox(
group,
new THREE.Vector3(width + 0.26, 0.12, 0.14),
new THREE.Vector3(0, -height / 2 - 0.06, 0.07),
frameMaterial,
false
);
addBox(
group,
new THREE.Vector3(0.07, height, 0.12),
new THREE.Vector3(0, 0, 0.09),
frameMaterial,
false
);
addBox(
group,
new THREE.Vector3(0.07, height, 0.12),
new THREE.Vector3(0, 0, 0.09),
frameMaterial,
false
);
const shutterWidth = width * 0.46;
const shutterOffset = width / 2 + shutterWidth * 0.62;
const leftShutter = addBox(
group,
new THREE.Vector3(shutterWidth, height + 0.12, 0.11),
new THREE.Vector3(-shutterOffset, 0, 0.05),
mat.shutter,
false
);
const rightShutter = addBox(
group,
new THREE.Vector3(shutterWidth, height + 0.12, 0.11),
new THREE.Vector3(shutterOffset, 0, 0.05),
mat.shutterLight,
false
);
for (const shutter of [leftShutter, rightShutter]) {
for (let i = 0; i < 3; i++) {
addBox(
group,
new THREE.Vector3(shutterWidth * 0.72, 0.045, 0.035),
new THREE.Vector3(
shutter.position.x,
-height * 0.3 + i * height * 0.3,
0.12
),
mat.shutterLight,
false
);
}
}
return group;
}
// ---------------------------------------------------------------------
// Continuous inhabited shop corridor on the bridge.
// ---------------------------------------------------------------------
const corridorGroup = new THREE.Group();
scene.add(corridorGroup);
const moduleXs = [-10.5, -7.5, -4.5, -1.5, 1.5, 4.5, 7.5, 10.5];
const corridorMaterials = [
mat.wallOchre,
mat.wallCream,
mat.wallRose,
mat.wallSage,
mat.wallPale,
mat.wallGold,
mat.wallCream,
mat.wallRose
];
for (const side of [-1, 1]) {
moduleXs.forEach((x, index) => {
addBox(
corridorGroup,
new THREE.Vector3(2.98, 4.18, 2.45),
new THREE.Vector3(x, 6.84, side * 1.24),
corridorMaterials[(index + (side > 0 ? 2 : 0)) % corridorMaterials.length]
);
const skipNearSelectedBay = side === 1 && index === 4;
if (!skipNearSelectedBay) {
const windowGroup = makeWindow(0.78, 1.22);
windowGroup.position.set(x, 7.05, side * 2.49);
windowGroup.rotation.y = side === 1 ? 0 : Math.PI;
corridorGroup.add(windowGroup);
}
addBox(
corridorGroup,
new THREE.Vector3(2.85, 0.16, 2.75),
new THREE.Vector3(x, 8.96, side * 1.24),
index % 2 ? mat.roofDark : mat.roof,
false
);
});
const roof = addBox(
corridorGroup,
new THREE.Vector3(24.3, 0.17, 3.08),
new THREE.Vector3(0, 9.48, side * 1.25),
side === 1 ? mat.roof : mat.roofDark
);
roof.rotation.x = side * 0.43;
}
addBox(
corridorGroup,
new THREE.Vector3(24.3, 0.18, 0.24),
new THREE.Vector3(0, 10.02, 0),
mat.roofDark
);
// ---------------------------------------------------------------------
// Selected shop-bay fragment projecting over the river.
// ---------------------------------------------------------------------
const detailGroup = new THREE.Group();
scene.add(detailGroup);
const bayX = 1.5;
const bayWidth = 2.65;
const bayDepth = 1.55;
const bayHeight = 3.0;
const bayCenterY = 7.38;
const bayCenterZ = 3.0;
const bayWall = addBox(
detailGroup,
new THREE.Vector3(bayWidth, bayHeight, bayDepth),
new THREE.Vector3(bayX, bayCenterY, bayCenterZ),
mat.wallGold
);
addOutline(
detailGroup,
new THREE.Vector3(bayWidth, bayHeight, bayDepth),
new THREE.Vector3(bayX, bayCenterY, bayCenterZ)
);
const selectedWindow = makeWindow(1.12, 1.52, mat.selectedTrim);
selectedWindow.position.set(bayX, 7.35, bayCenterZ + bayDepth / 2 + 0.045);
detailGroup.add(selectedWindow);
const bayRoof = addBox(
detailGroup,
new THREE.Vector3(2.88, 0.17, 1.82),
new THREE.Vector3(bayX, 8.94, 3.02),
mat.roof
);
bayRoof.rotation.x = 0.13;
addOutline(
detailGroup,
new THREE.Vector3(2.88, 0.17, 1.82),
new THREE.Vector3(bayX, 8.94, 3.02),
bayRoof.rotation
);
// Wall-foot beam and diagonal timber brackets.
const lowerBeam = addBox(
detailGroup,
new THREE.Vector3(2.82, 0.25, 1.65),
new THREE.Vector3(bayX, 5.84, 3.0),
mat.timber
);
addOutline(
detailGroup,
new THREE.Vector3(2.82, 0.25, 1.65),
new THREE.Vector3(bayX, 5.84, 3.0)
);
for (const offset of [-0.93, 0.93]) {
addBeam(
detailGroup,
new THREE.Vector3(bayX + offset, 4.78, 2.49),
new THREE.Vector3(bayX + offset, 5.93, 3.65),
0.18,
mat.timber
);
addBox(
detailGroup,
new THREE.Vector3(0.34, 0.34, 0.28),
new THREE.Vector3(bayX + offset, 4.83, 2.48),
mat.timberLight
);
}
// A narrow ledge visually binds the bay to the bridge edge.
addBox(
detailGroup,
new THREE.Vector3(2.95, 0.12, 0.42),
new THREE.Vector3(bayX, 5.02, 2.48),
mat.timberLight
);
// ---------------------------------------------------------------------
// Low-poly city context on both banks.
// ---------------------------------------------------------------------
const cityGroup = new THREE.Group();
scene.add(cityGroup);
function makeRoof(width, depth, rise, x, y, z, roofMaterial) {
const shape = new THREE.Shape();
shape.moveTo(-depth / 2, 0);
shape.lineTo(depth / 2, 0);
shape.lineTo(0, rise);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: width,
bevelEnabled: false,
curveSegments: 1
});
geometry.rotateY(Math.PI / 2);
const roof = new THREE.Mesh(geometry, roofMaterial);
roof.position.set(x - width / 2, y, z);
roof.castShadow = true;
roof.receiveShadow = true;
cityGroup.add(roof);
}
function cityBuilding(x, z, width, depth, height, wallMaterial, roofMaterial) {
const baseY = 0.2;
addBox(
cityGroup,
new THREE.Vector3(width, height, depth),
new THREE.Vector3(x, baseY + height / 2, z),
wallMaterial
);
makeRoof(
width + 0.22,
depth + 0.22,
1.35,
x,
baseY + height,
z,
roofMaterial
);
const facingRiver = x < 0 ? 1 : -1;
const faceX = x + facingRiver * (width / 2 + 0.035);
const floors = height > 10 ? 3 : 2;
for (let floor = 0; floor < floors; floor++) {
const windowY = baseY + 2.0 + floor * 2.65;
const columns = Math.max(2, Math.floor(depth / 2.2));
for (let column = 0; column < columns; column++) {
const windowZ =
z -
depth / 2 +
((column + 0.5) / columns) * depth;
const windowGroup = makeWindow(0.68, 1.08, mat.trim);
windowGroup.position.set(faceX, windowY, windowZ);
windowGroup.rotation.y = facingRiver > 0 ? Math.PI / 2 : -Math.PI / 2;
cityGroup.add(windowGroup);
}
}
}
cityBuilding(-16.2, -7.0, 5.5, 7.8, 9.5, mat.wallCream, mat.roofDark);
cityBuilding(-17.0, 2.2, 6.2, 7.4, 12.2, mat.wallRose, mat.roof);
cityBuilding(-16.0, 10.5, 5.4, 6.1, 8.7, mat.wallOchre, mat.roofDark);
cityBuilding(16.2, -7.3, 5.5, 7.8, 9.2, mat.wallOchre, mat.roof);
cityBuilding(18.0, 2.0, 6.8, 7.5, 12.6, mat.wallCream, mat.roofDark);
cityBuilding(16.2, 10.3, 5.4, 6.2, 8.9, mat.wallRose, mat.roof);
// A few faceted stones along the bridge deck clarify its construction.
for (let i = 0; i < 14; i++) {
const x = -11.1 + i * 1.72;
addBox(
bridgeGroup,
new THREE.Vector3(1.48, 0.08, 0.39),
new THREE.Vector3(x, 4.77, 2.49),
i % 2 ? mat.stone : mat.stoneLight,
false
);
}
// ---------------------------------------------------------------------
// UI actions and detail marker.
// ---------------------------------------------------------------------
function focusWhole() {
setView(
new THREE.Vector3(0, 3.25, 0),
29,
1.16,
0.69
);
}
function focusDetail() {
setView(
new THREE.Vector3(bayX, 7.05, 3.0),
10.6,
1.18,
0.55
);
}
document.querySelector("#view-whole").addEventListener("click", focusWhole);
document.querySelector("#view-detail").addEventListener("click", focusDetail);
const detailMarkerPosition = new THREE.Vector3(bayX, 9.35, 3.15);
const projectedMarker = new THREE.Vector3();
function updateDetailMarker() {
projectedMarker.copy(detailMarkerPosition).project(camera);
const visible =
projectedMarker.z > -1 &&
projectedMarker.z < 1 &&
Math.abs(projectedMarker.x) < 1.08 &&
Math.abs(projectedMarker.y) < 1.08;
detailTag.style.display = visible ? "block" : "none";
if (visible) {
const x = (projectedMarker.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedMarker.y * 0.5 + 0.5) * window.innerHeight;
detailTag.style.left = `${x}px`;
detailTag.style.top = `${y}px`;
}
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
updateCamera(dt);
updateDetailMarker();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```