Prompt specification
Build or customize the Three.js 3D scene "Borough Market roof truss and counter bay" 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: Borough Market roof truss and counter bay
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/borough-market-roof-truss-and-counter-bay-x2841
Scene Description Prompt:
Borough Market roof truss and counter bay. Build a referenced market roof-truss fragment above an original produce counter. Distinguish the structural span from the removable stall furniture and preserve a clear passage beside it. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (borough-market-roof-truss-and-counter-bay-x2841):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Borough Market — Roof Truss and Produce Counter</title>
<style>
:root {
--ink: #26312f;
--paper: #f6f1e7;
--structure: #29343b;
--furniture: #b88743;
--aisle: #31846a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded8cc;
color: var(--ink);
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
pointer-events: none;
background: rgba(248, 244, 235, 0.93);
border: 1px solid rgba(38, 49, 47, 0.16);
box-shadow: 0 10px 30px rgba(41, 47, 44, 0.13);
backdrop-filter: blur(8px);
}
#title-card {
top: 22px;
left: 22px;
width: min(420px, calc(100vw - 44px));
padding: 18px 20px 16px;
}
.eyebrow {
margin-bottom: 8px;
color: #6c756f;
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(25px, 3vw, 38px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 11px;
color: #5f6964;
font-size: 12px;
line-height: 1.45;
}
#legend {
top: 22px;
right: 22px;
width: 260px;
padding: 15px 17px;
}
.legend-title {
margin-bottom: 10px;
color: #727a75;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 18px 1fr;
gap: 9px;
align-items: start;
margin-top: 9px;
font-size: 11px;
line-height: 1.3;
}
.swatch {
width: 18px;
height: 18px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.swatch.structure {
background: var(--structure);
}
.swatch.furniture {
background: linear-gradient(135deg, #386b5c 50%, var(--furniture) 50%);
}
.swatch.aisle {
background: #a7d6c1;
}
.legend-row strong {
display: block;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend-row span {
color: #69716c;
}
#views {
position: fixed;
z-index: 12;
bottom: 22px;
left: 50%;
display: flex;
gap: 6px;
padding: 6px;
transform: translateX(-50%);
background: rgba(248, 244, 235, 0.94);
border: 1px solid rgba(38, 49, 47, 0.16);
border-radius: 7px;
box-shadow: 0 8px 24px rgba(41, 47, 44, 0.12);
}
#views button {
appearance: none;
padding: 9px 13px;
border: 0;
border-radius: 4px;
background: transparent;
color: #4c5853;
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#views button:hover,
#views button.active {
background: #293d36;
color: #fffaf0;
}
#hint {
position: fixed;
z-index: 9;
bottom: 25px;
left: 24px;
color: rgba(38, 49, 47, 0.68);
font-size: 10px;
line-height: 1.55;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 7;
min-width: 155px;
max-width: 235px;
padding: 10px 12px 10px 13px;
transform: translate(-50%, -100%);
background: rgba(255, 253, 247, 0.95);
border: 1px solid rgba(35, 45, 42, 0.16);
border-left: 4px solid;
box-shadow: 0 7px 22px rgba(36, 45, 42, 0.14);
pointer-events: none;
transition: opacity 120ms linear;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 12px;
height: 12px;
transform: translateX(-50%) rotate(45deg);
background: #fffdf7;
border-right: 1px solid rgba(35, 45, 42, 0.16);
border-bottom: 1px solid rgba(35, 45, 42, 0.16);
}
.world-label strong {
display: block;
margin-bottom: 4px;
color: #25312e;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
line-height: 1.25;
text-transform: uppercase;
}
.world-label small {
display: block;
color: #69736e;
font-size: 10px;
line-height: 1.35;
}
#label-structure {
border-left-color: var(--structure);
}
#label-counter {
border-left-color: var(--furniture);
}
#label-aisle {
border-left-color: var(--aisle);
}
@media (max-width: 720px) {
#legend {
display: none;
}
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle {
max-width: 330px;
}
#hint {
display: none;
}
#views {
bottom: 12px;
}
#views button {
padding: 9px 10px;
font-size: 9px;
}
.world-label {
min-width: 130px;
padding: 8px 9px;
}
}
</style>
</head>
<body>
<div id="title-card" class="panel">
<div class="eyebrow">Spatial study · market hall fragment</div>
<h1>Borough Market<br />Truss & Counter Bay</h1>
<div class="subtitle">
A referenced iron roof-truss fragment above an original, freestanding
produce counter. A separate tiled route preserves a clear passage beside it.
</div>
</div>
<div id="legend" class="panel">
<div class="legend-title">Reading the bay</div>
<div class="legend-row">
<div class="swatch structure"></div>
<div>
<strong>Permanent structure</strong>
<span>Fixed columns, chords, web and roof members.</span>
</div>
</div>
<div class="legend-row">
<div class="swatch furniture"></div>
<div>
<strong>Removable furniture</strong>
<span>Independent timber counter on visible castors.</span>
</div>
</div>
<div class="legend-row">
<div class="swatch aisle"></div>
<div>
<strong>Clear passage</strong>
<span>Unoccupied tiled aisle, approximately 2 m wide.</span>
</div>
</div>
</div>
<div id="hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom<br />
Double-click to return to the overview
</div>
<div id="views">
<button class="active" data-view="overview">Overview</button>
<button data-view="counter">Counter</button>
<button data-view="truss">Truss</button>
</div>
<div id="label-structure" class="world-label">
<strong>Permanent structural span</strong>
<small>Dark iron frame anchored to the market hall.</small>
</div>
<div id="label-counter" class="world-label">
<strong>Removable stall furniture</strong>
<small>Original produce counter with castors; no fixed attachment.</small>
</div>
<div id="label-aisle" class="world-label">
<strong>Keep passage clear</strong>
<small>Approximately 2 m of unobstructed circulation space.</small>
</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 and camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.05;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of Borough Market roof truss and produce counter"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded8cc);
scene.fog = new THREE.Fog(0xded8cc, 23, 43);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
const controls = {
target: new THREE.Vector3(0, 3.2, 0),
radius: 19,
yaw: 0.64,
pitch: 0.43
};
function applyCamera() {
const cp = Math.cos(controls.pitch);
camera.position.set(
controls.target.x + controls.radius * cp * Math.sin(controls.yaw),
controls.target.y + controls.radius * Math.sin(controls.pitch),
controls.target.z + controls.radius * cp * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
applyCamera();
const hemi = new THREE.HemisphereLight(0xfff5de, 0x65736c, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.2);
sun.position.set(-9, 15, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfd9dc, 0.7);
fill.position.set(11, 7, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Palette and instanced voxel builder
// -------------------------------------------------------------------------
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0,
...options
});
const mat = {
ground: standard(0xb8b1a4),
floorA: standard(0xc8c0b2),
floorB: standard(0xd0c8b9),
floorC: standard(0xbbb4a7),
aisle: standard(0xa9d4bf),
aisleEdge: standard(0xd8b45c),
brickA: standard(0xa65f49),
brickB: standard(0x934f3e),
brickC: standard(0xb36b52),
mortar: standard(0xc1aa91),
window: standard(0x344c51, { roughness: 0.34, metalness: 0.12 }),
cream: standard(0xe8dfc9),
structure: standard(0x28343a, { roughness: 0.48, metalness: 0.64 }),
structureAlt: standard(0x3a484d, { roughness: 0.5, metalness: 0.58 }),
stone: standard(0x8d9189),
roof: standard(0x66767b, { roughness: 0.72, metalness: 0.18 }),
roofAlt: standard(0x78878a, { roughness: 0.72, metalness: 0.16 }),
cabinet: standard(0x386b59),
cabinetDark: standard(0x274f43),
timber: standard(0xb87d43),
timberLight: standard(0xd3a165),
timberDark: standard(0x84552f),
brass: standard(0xc29a4c, { roughness: 0.38, metalness: 0.68 }),
rubber: standard(0x222624),
tomato: standard(0xc94e37),
lemon: standard(0xe1b83f),
leaf: standard(0x4c7d3a),
orange: standard(0xd77a31),
aubergine: standard(0x5d3b4c),
paper: standard(0xeee5ce)
};
const batches = new Map();
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const transform = new THREE.Object3D();
function addBox(x, y, z, sx, sy, sz, material) {
let batch = batches.get(material.uuid);
if (!batch) {
batch = { material, items: [] };
batches.set(material.uuid, batch);
}
transform.position.set(x, y, z);
transform.rotation.set(0, 0, 0);
transform.scale.set(sx, sy, sz);
transform.updateMatrix();
batch.items.push(transform.matrix.clone());
}
function voxelBeam(a, b, size, material, alternate = material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const distance = start.distanceTo(end);
const count = Math.max(1, Math.ceil(distance / (size * 1.035)));
for (let i = 0; i < count; i++) {
const t = count === 1 ? 0.5 : i / (count - 1);
const p = start.clone().lerp(end, t);
addBox(
p.x,
p.y,
p.z,
size,
size,
size,
i % 3 === 0 ? alternate : material
);
}
}
// -------------------------------------------------------------------------
// Ground and tiled market floor
// -------------------------------------------------------------------------
addBox(0, -0.19, 0, 24, 0.18, 18, mat.ground);
const floorMaterials = [mat.floorA, mat.floorB, mat.floorC];
const nx = 19;
const nz = 13;
const spacing = 0.98;
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const x = (ix - (nx - 1) / 2) * spacing;
const z = (iz - (nz - 1) / 2) * spacing;
const isAisle = x > 0.3 && x < 2.65;
const material = isAisle
? mat.aisle
: floorMaterials[(ix * 7 + iz * 3) % floorMaterials.length];
addBox(x, -0.075, z, 0.94, 0.15, 0.94, material);
}
}
// Dashed boundary markings and blocky directional arrows.
for (const x of [0.46, 2.48]) {
for (let z = -5.5; z <= 5.5; z += 0.72) {
addBox(x, 0.015, z, 0.055, 0.035, 0.38, mat.aisleEdge);
}
}
for (const z of [-4.1, -1.45, 1.2, 3.85]) {
addBox(1.47, 0.075, z - 0.27, 0.16, 0.07, 0.58, mat.aisleEdge);
addBox(1.24, 0.075, z + 0.1, 0.16, 0.07, 0.28, mat.aisleEdge);
addBox(1.70, 0.075, z + 0.1, 0.16, 0.07, 0.28, mat.aisleEdge);
addBox(1.47, 0.075, z + 0.22, 0.16, 0.07, 0.18, mat.aisleEdge);
}
// -------------------------------------------------------------------------
// Brick rear wall and window openings
// -------------------------------------------------------------------------
const wallZ = -6.2;
const wallWidth = 0.92;
const wallHeight = 0.39;
for (let row = 0; row < 8; row++) {
const y = 0.21 + row * wallHeight;
const offset = row % 2 ? 0.46 : 0;
for (let x = -9.1 + offset; x <= 9.1; x += wallWidth) {
const inWindow =
y > 1.1 &&
((x > -5.3 && x < -1.7) || (x > 2.2 && x < 5.8));
if (inWindow) continue;
const brickMaterial =
(row + Math.round(Math.abs(x))) % 3 === 0
? mat.brickB
: (row + Math.round(Math.abs(x))) % 2 === 0
? mat.brickA
: mat.brickC;
addBox(x, y, wallZ, 0.87, 0.35, 0.34, brickMaterial);
}
}
for (const [left, right] of [[-5.35, -1.65], [2.15, 5.85]]) {
const center = (left + right) / 2;
const width = right - left;
addBox(center, 2.08, wallZ + 0.06, width, 1.85, 0.12, mat.window);
addBox(center, 2.08, wallZ + 0.15, 0.09, 1.95, 0.12, mat.cream);
addBox(center, 2.08, wallZ + 0.15, width, 0.09, 0.12, mat.cream);
addBox(left, 1.08, wallZ + 0.13, 0.13, 2.12, 0.15, mat.cream);
addBox(right, 1.08, wallZ + 0.13, 0.13, 2.12, 0.15, mat.cream);
}
// -------------------------------------------------------------------------
// Permanent iron roof-truss fragment
// -------------------------------------------------------------------------
const trussZ = 0.15;
const xLeft = -7.5;
const xRight = 7.5;
const lowerY = 5.55;
const eaveY = 6.62;
const peakY = 8.55;
function upperHeight(x) {
return eaveY + (peakY - eaveY) * (1 - Math.abs(x) / 7.5);
}
// Column bases establish that the truss is fixed to the building.
for (const x of [xLeft, xRight]) {
addBox(x, 0.18, trussZ, 0.86, 0.36, 0.86, mat.stone);
addBox(x, 0.49, trussZ, 0.67, 0.25, 0.67, mat.stone);
voxelBeam(
[x, 0.62, trussZ],
[x, lowerY, trussZ],
0.31,
mat.structure,
mat.structureAlt
);
// Capital blocks.
addBox(x, lowerY - 0.07, trussZ, 0.68, 0.22, 0.66, mat.structureAlt);
}
// Lower horizontal chord.
voxelBeam(
[xLeft, lowerY, trussZ],
[xRight, lowerY, trussZ],
0.27,
mat.structure,
mat.structureAlt
);
// Pitched upper chords.
voxelBeam(
[xLeft, eaveY, trussZ],
[0, peakY, trussZ],
0.28,
mat.structure,
mat.structureAlt
);
voxelBeam(
[0, peakY, trussZ],
[xRight, eaveY, trussZ],
0.28,
mat.structure,
mat.structureAlt
);
// Warren-style vertical and diagonal web members.
const webX = [-5.8, -3.65, -1.45, 0, 1.45, 3.65, 5.8];
for (const x of webX) {
voxelBeam(
[x, lowerY, trussZ],
[x, upperHeight(x), trussZ],
0.19,
mat.structureAlt,
mat.structure
);
addBox(
x,
upperHeight(x),
trussZ,
0.36,
0.36,
0.34,
mat.structure
);
}
for (let i = 0; i < webX.length - 1; i++) {
const a = webX[i];
const b = webX[i + 1];
if (i % 2 === 0) {
voxelBeam(
[a, lowerY, trussZ],
[b, upperHeight(b), trussZ],
0.18,
mat.structure,
mat.structureAlt
);
} else {
voxelBeam(
[a, upperHeight(a), trussZ],
[b, lowerY, trussZ],
0.18,
mat.structure,
mat.structureAlt
);
}
}
// Gusset blocks at the principal joints.
for (const x of [xLeft, 0, xRight]) {
const y = x === 0 ? peakY : eaveY;
addBox(x, y, trussZ + 0.19, 0.48, 0.48, 0.12, mat.structureAlt);
addBox(x, y, trussZ + 0.27, 0.18, 0.18, 0.08, mat.brass);
}
// Longitudinal roof members show the fragment continues into the hall.
for (const x of [-5.8, 0, 5.8]) {
voxelBeam(
[x, upperHeight(x) + 0.08, trussZ],
[x, upperHeight(x) + 0.08, -5.95],
0.2,
mat.structureAlt,
mat.structure
);
}
// A partial roof skin, intentionally cut away to expose the iron frame.
for (let ix = 0; ix < 7; ix++) {
for (let iz = 0; iz < 7; iz++) {
const x = -6.6 + ix * 0.78;
const z = -5.55 + iz * 0.78;
if (x > -0.7) continue;
addBox(
x,
upperHeight(x) + 0.25,
z,
0.73,
0.13,
0.73,
(ix + iz) % 2 ? mat.roof : mat.roofAlt
);
}
}
// -------------------------------------------------------------------------
// Removable produce counter
// -------------------------------------------------------------------------
const counterX = -3;
const counterZ = 0;
const counterWidth = 6.2;
const counterDepth = 2.55;
// Visible castors emphasize that this is independent furniture.
for (const dx of [-counterWidth / 2 + 0.34, counterWidth / 2 - 0.34]) {
for (const dz of [-0.94, 0.94]) {
addBox(counterX + dx, 0.24, counterZ + dz, 0.34, 0.38, 0.34, mat.rubber);
addBox(counterX + dx, 0.24, counterZ + dz + 0.18, 0.12, 0.12, 0.06, mat.brass);
}
}
// Cabinet frame.
addBox(counterX, 0.55, counterZ, counterWidth - 0.18, 0.24, counterDepth - 0.22, mat.cabinetDark);
addBox(counterX, 1.48, counterZ, counterWidth - 0.15, 0.18, counterDepth - 0.14, mat.timberDark);
for (const dx of [-counterWidth / 2 + 0.22, counterWidth / 2 - 0.22]) {
for (const dz of [-counterDepth / 2 + 0.16, counterDepth / 2 - 0.16]) {
addBox(counterX + dx, 1.03, counterZ + dz, 0.19, 0.91, 0.19, mat.timberDark);
}
}
// Front cabinet panels, separated by narrow reveals.
for (let i = 0; i < 6; i++) {
const panelWidth = 0.88;
const x = counterX - 2.5 + i * 1;
addBox(
x,
1.01,
counterZ + counterDepth / 2 - 0.12,
panelWidth,
0.76,
0.15,
i % 2 ? mat.cabinet : mat.cabinetDark
);
addBox(
x + 0.24,
1.04,
counterZ + counterDepth / 2 - 0.025,
0.13,
0.13,
0.07,
mat.brass
);
}
// Rear cabinet panels.
for (let i = 0; i < 6; i++) {
addBox(
counterX - 2.5 + i,
1.02,
counterZ - counterDepth / 2 + 0.12,
0.89,
0.73,
0.12,
mat.cabinetDark
);
}
// Thick timber worktop, assembled from visible rectangular blocks.
for (let i = 0; i < 10; i++) {
addBox(
counterX - 2.79 + i * 0.62,
1.68,
counterZ,
0.59,
0.2,
counterDepth + 0.12,
i % 3 === 0 ? mat.timberLight : mat.timber
);
}
// Produce crates.
function addCrate(cx, produceMaterial) {
const cz = 0.02;
const baseY = 1.84;
const width = 1.72;
const depth = 1.35;
// Base slats.
for (let i = 0; i < 5; i++) {
addBox(
cx - 0.65 + i * 0.325,
baseY,
cz,
0.24,
0.12,
depth,
mat.timberDark
);
}
// Corner posts.
for (const dx of [-width / 2 + 0.07, width / 2 - 0.07]) {
for (const dz of [-depth / 2 + 0.07, depth / 2 - 0.07]) {
addBox(cx + dx, baseY + 0.28, cz + dz, 0.13, 0.62, 0.13, mat.timber);
}
}
// Front and back slats.
for (const dz of [-depth / 2 + 0.04, depth / 2 - 0.04]) {
for (const y of [baseY + 0.17, baseY + 0.42]) {
addBox(cx, y, cz + dz, width, 0.12, 0.1, mat.timberLight);
}
}
// Side slats.
for (const dx of [-width / 2 + 0.04, width / 2 - 0.04]) {
for (const y of [baseY + 0.17, baseY + 0.42]) {
addBox(cx + dx, y, cz, 0.1, 0.12, depth, mat.timberLight);
}
}
// Voxel produce, arranged in offset rows.
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 5; col++) {
const px = cx - 0.6 + col * 0.3 + (row % 2) * 0.07;
const pz = cz - 0.4 + row * 0.37;
const py = baseY + 0.32 + ((row + col) % 2) * 0.04;
addBox(px, py, pz, 0.25, 0.24, 0.25, produceMaterial);
if ((row + col) % 3 === 0) {
addBox(px, py + 0.13, pz, 0.1, 0.08, 0.1, mat.leaf);
}
}
}
// Small market price card.
addBox(cx, baseY + 0.28, cz + depth / 2 + 0.08, 0.48, 0.25, 0.045, mat.paper);
addBox(cx, baseY + 0.28, cz + depth / 2 + 0.11, 0.31, 0.055, 0.025, produceMaterial);
}
addCrate(-5.05, mat.tomato);
addCrate(-3.0, mat.lemon);
addCrate(-0.95, mat.leaf);
// A few contrasting produce blocks placed by hand on the top.
addBox(-5.46, 2.25, 0.53, 0.27, 0.27, 0.27, mat.orange);
addBox(-0.5, 2.24, -0.35, 0.26, 0.26, 0.26, mat.aubergine);
addBox(-0.62, 2.22, -0.05, 0.24, 0.24, 0.24, mat.tomato);
// -------------------------------------------------------------------------
// Text panels, generated locally with canvas
// -------------------------------------------------------------------------
function makeTextPanel(lines, width, height, background, foreground) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 320;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.lineWidth = 8;
ctx.strokeRect(14, 14, canvas.width - 28, canvas.height - 28);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
lines.forEach((line, index) => {
const isMain = index === 0;
ctx.font = isMain
? "700 86px Georgia, serif"
: "700 31px Arial, sans-serif";
ctx.fillText(
line,
canvas.width / 2,
isMain ? 135 : 235
);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshBasicMaterial({ map: texture });
const panel = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
return panel;
}
const marketSign = makeTextPanel(
["BOROUGH MARKET", "PRODUCE HALL · SHARED ROOF"],
4.8,
1.5,
"#29483e",
"#f0e5cd"
);
marketSign.position.set(0, 3.62, -5.96);
scene.add(marketSign);
const counterSign = makeTextPanel(
["LOCAL PRODUCE", "NEIGHBOURHOOD COUNTER"],
2.45,
0.68,
"#e8ddc1",
"#29483e"
);
counterSign.position.set(counterX + 0.95, 1.04, counterZ + counterDepth / 2 + 0.03);
scene.add(counterSign);
// -------------------------------------------------------------------------
// Commit all boxes as material-batched InstancedMeshes
// -------------------------------------------------------------------------
for (const batch of batches.values()) {
const mesh = new THREE.InstancedMesh(
unitBox,
batch.material,
batch.items.length
);
batch.items.forEach((matrix, index) => {
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.frustumCulled = false;
scene.add(mesh);
}
// -------------------------------------------------------------------------
// Projected labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-structure"),
anchor: new THREE.Vector3(-5.1, 7.45, trussZ)
},
{
element: document.getElementById("label-counter"),
anchor: new THREE.Vector3(-2.7, 2.8, 1.25)
},
{
element: document.getElementById("label-aisle"),
anchor: new THREE.Vector3(1.48, 0.55, 2.2)
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const point = label.anchor.clone().project(camera);
const visible =
point.z > -1 &&
point.z < 1 &&
point.x > -1.2 &&
point.x < 1.2 &&
point.y > -1.2 &&
point.y < 1.2;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${(point.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-point.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom and presets
// -------------------------------------------------------------------------
const presets = {
overview: {
target: new THREE.Vector3(0, 3.2, 0),
radius: 19,
yaw: 0.64,
pitch: 0.43
},
counter: {
target: new THREE.Vector3(-2.7, 2.0, 0),
radius: 10.3,
yaw: 0.42,
pitch: 0.28
},
truss: {
target: new THREE.Vector3(-0.2, 6.0, 0),
radius: 13.5,
yaw: 0.66,
pitch: 0.25
}
};
function setPreset(name) {
const preset = presets[name];
controls.target.copy(preset.target);
controls.radius = preset.radius;
controls.yaw = preset.yaw;
controls.pitch = preset.pitch;
applyCamera();
document.querySelectorAll("#views button").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("#views button").forEach((button) => {
button.addEventListener("click", () => setPreset(button.dataset.view));
});
const canvas = renderer.domElement;
let drag = null;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
drag = {
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!drag) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
if (drag.pan) {
const scale = controls.radius * 0.0014;
controls.target.x = THREE.MathUtils.clamp(
controls.target.x - dx * scale,
-7,
7
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z + dy * scale,
-5,
5
);
} else {
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.005,
0.12,
1.12
);
}
drag.x = event.clientX;
drag.y = event.clientY;
applyCamera();
});
function endDrag(event) {
if (drag && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
drag = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
7,
29
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => setPreset("overview"));
window.addEventListener("keydown", (event) => {
if (event.key === "1") setPreset("overview");
if (event.key === "2") setPreset("counter");
if (event.key === "3") setPreset("truss");
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```