Prompt specification
Build or customize the Three.js 3D scene "Reconfigure a market aisle around a delivery window" 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: Reconfigure a market aisle around a delivery window
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reconfigure-a-market-aisle-around-a-delivery-window-x2844
Scene Description Prompt:
Rearrange low-poly displays in London's Borough Market while preserving delivery access, exits, building forms, and viaduct. Use Three.js from cdnjs in standalone HTML.
Working Three.js Starter (reconfigure-a-market-aisle-around-a-delivery-window-x2844):
```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 — Protected Rearrangement</title>
<style>
:root {
--ink: #14221f;
--muted: #65736e;
--paper: rgba(250, 249, 243, 0.94);
--line: rgba(20, 34, 31, 0.13);
--green: #236b58;
--green-soft: #dcebe3;
--teal: #168c91;
--gold: #d49b3f;
--red: #b84b45;
--shadow: 0 14px 45px rgba(32, 48, 43, 0.16);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #dce3df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
border: 0;
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.topbar {
position: fixed;
top: 16px;
left: 16px;
right: 16px;
height: 66px;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 18px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 17px;
background: rgba(248, 248, 241, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 280px;
}
.brand-mark {
width: 39px;
height: 39px;
display: grid;
place-items: center;
border-radius: 12px;
color: white;
background: var(--green);
font-weight: 800;
letter-spacing: -1px;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.brand-copy strong {
display: block;
font-size: 14px;
letter-spacing: -0.02em;
}
.brand-copy span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
letter-spacing: .09em;
text-transform: uppercase;
}
.top-status {
display: flex;
align-items: center;
gap: 18px;
}
.proposal {
color: var(--muted);
font-size: 12px;
}
.proposal strong {
color: var(--ink);
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 8px 11px;
border-radius: 999px;
color: var(--green);
background: var(--green-soft);
font-size: 11px;
font-weight: 750;
white-space: nowrap;
}
.status-pill::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 0 4px rgba(35, 107, 88, .09);
}
.status-pill.invalid {
color: var(--red);
background: #f7e4df;
}
.top-actions {
display: flex;
gap: 8px;
}
.button {
min-height: 36px;
padding: 0 13px;
border-radius: 10px;
color: var(--ink);
background: rgba(20, 34, 31, .065);
font-size: 12px;
font-weight: 700;
transition: transform .15s, background .15s;
}
.button:hover {
transform: translateY(-1px);
background: rgba(20, 34, 31, .10);
}
.button.primary {
color: white;
background: var(--green);
}
.button.primary:hover {
background: #195644;
}
.panel {
position: fixed;
z-index: 8;
top: 98px;
width: 282px;
padding: 18px;
border: 1px solid rgba(255,255,255,.62);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.left-panel { left: 16px; }
.right-panel { right: 16px; width: 294px; }
.eyebrow {
margin-bottom: 7px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1 {
margin-bottom: 8px;
font-size: 22px;
line-height: 1.12;
letter-spacing: -.045em;
}
h2 {
margin-bottom: 4px;
font-size: 17px;
letter-spacing: -.025em;
}
.intro {
margin-bottom: 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 15px 0 18px;
}
.metric {
padding: 11px 8px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255,255,255,.42);
}
.metric strong {
display: block;
font-size: 19px;
line-height: 1;
}
.metric span {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 9px;
letter-spacing: .07em;
text-transform: uppercase;
}
.section-label {
margin: 18px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .11em;
text-transform: uppercase;
}
.layer {
display: flex;
align-items: center;
gap: 9px;
min-height: 34px;
padding: 5px 0;
cursor: pointer;
font-size: 12px;
}
.layer input {
width: 15px;
height: 15px;
accent-color: var(--green);
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
flex: 0 0 auto;
}
.lock {
margin-left: auto;
color: #8c9893;
font-size: 10px;
letter-spacing: .05em;
}
.selected-card {
padding: 13px;
margin: 15px 0;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255,255,255,.48);
}
.selected-top {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 10px;
}
.selected-id {
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: .11em;
}
.clear-badge {
padding: 4px 7px;
border-radius: 999px;
color: var(--green);
background: var(--green-soft);
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
}
.clear-badge.invalid {
color: var(--red);
background: #f7e4df;
}
.selected-name {
margin: 5px 0 2px;
font-size: 16px;
font-weight: 750;
letter-spacing: -.025em;
}
.selected-category {
color: var(--muted);
font-size: 11px;
}
.details {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 15px;
}
.detail {
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255,255,255,.35);
}
.detail span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: .07em;
text-transform: uppercase;
}
.detail strong {
display: block;
margin-top: 4px;
font-size: 12px;
}
.control-heading {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: .09em;
text-transform: uppercase;
}
.nudge-pad {
display: grid;
grid-template-columns: repeat(3, 39px);
grid-template-rows: repeat(2, 35px);
justify-content: center;
gap: 6px;
margin: 12px 0 14px;
}
.nudge-pad button {
border: 1px solid var(--line);
border-radius: 9px;
color: var(--ink);
background: rgba(255,255,255,.56);
font-weight: 800;
}
.nudge-pad button:hover {
color: white;
background: var(--green);
}
.nudge-pad .up { grid-column: 2; }
.nudge-pad .left { grid-column: 1; grid-row: 2; }
.nudge-pad .down { grid-column: 2; grid-row: 2; }
.nudge-pad .right { grid-column: 3; grid-row: 2; }
.wide {
width: 100%;
margin-top: 7px;
}
.keyboard-note {
margin: 12px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
text-align: center;
}
kbd {
padding: 1px 4px;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 4px;
color: var(--ink);
background: white;
font-family: inherit;
font-size: 9px;
}
.bottom-bar {
position: fixed;
z-index: 8;
left: 50%;
bottom: 16px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 16px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,.65);
border-radius: 14px;
background: rgba(248,248,241,.88);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
white-space: nowrap;
}
.legend {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 10px;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
}
.hint {
padding-left: 15px;
border-left: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.hint strong { color: var(--ink); }
.toast {
position: fixed;
z-index: 30;
left: 50%;
top: 94px;
transform: translate(-50%, -12px);
max-width: 440px;
padding: 10px 15px;
border-radius: 999px;
color: white;
background: rgba(20,34,31,.92);
box-shadow: var(--shadow);
opacity: 0;
pointer-events: none;
transition: opacity .2s, transform .2s;
font-size: 12px;
text-align: center;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1050px) {
.left-panel { display: none; }
.proposal { display: none; }
}
@media (max-width: 680px) {
.topbar {
top: 9px;
left: 9px;
right: 9px;
height: 58px;
padding: 0 11px;
}
.brand-copy span, .status-pill, #exportButton { display: none; }
.right-panel {
top: auto;
right: 9px;
bottom: 64px;
width: 250px;
padding: 13px;
}
.selected-card, .details { margin: 10px 0; }
.nudge-pad { margin: 8px 0; }
.bottom-bar { left: 9px; right: 9px; transform: none; justify-content: center; }
.hint { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D plan of Borough Market"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark">BM</div>
<div class="brand-copy">
<strong>Borough Market</strong>
<span>Protected rearrangement plan</span>
</div>
</div>
<div class="top-status">
<div class="proposal">Proposal <strong>04 / Market operations</strong></div>
<div id="globalStatus" class="status-pill">Plan valid</div>
<div class="top-actions">
<button id="exportButton" class="button">Export plan</button>
<button id="resetViewButton" class="button">Reset view</button>
</div>
</div>
</header>
<aside class="panel left-panel">
<div class="eyebrow">Layout brief</div>
<h1>More trading,<br />same access.</h1>
<p class="intro">
Displays are grouped by trade while delivery access, public exits,
market buildings and the railway viaduct remain protected.
</p>
<div class="metrics">
<div class="metric"><strong id="displayMetric">17</strong><span>Displays</span></div>
<div class="metric"><strong id="conflictMetric">0</strong><span>Conflicts</span></div>
<div class="metric"><strong>5</strong><span>Protected</span></div>
</div>
<div class="section-label">Protected layers</div>
<label class="layer">
<input type="checkbox" data-layer="delivery" checked />
<i class="swatch" style="background:#168c91"></i>
Delivery access
<span class="lock">LOCKED</span>
</label>
<label class="layer">
<input type="checkbox" data-layer="exits" checked />
<i class="swatch" style="background:#d49b3f"></i>
Public exits
<span class="lock">LOCKED</span>
</label>
<label class="layer">
<input type="checkbox" data-layer="access" checked />
<i class="swatch" style="background:#6986aa"></i>
Pedestrian spine
<span class="lock">LOCKED</span>
</label>
<label class="layer">
<input type="checkbox" data-layer="buildings" checked />
<i class="swatch" style="background:#956c57"></i>
Building forms
<span class="lock">LOCKED</span>
</label>
<label class="layer">
<input type="checkbox" data-layer="viaduct" checked />
<i class="swatch" style="background:#5e6b68"></i>
Rail viaduct
<span class="lock">LOCKED</span>
</label>
<div class="section-label">Display key</div>
<div class="legend"><i style="background:#e68b76"></i> Flowers</div>
<div class="legend" style="margin-top:8px"><i style="background:#75a95e"></i> Produce</div>
<div class="legend" style="margin-top:8px"><i style="background:#d9a850"></i> Bakery</div>
<div class="legend" style="margin-top:8px"><i style="background:#f0e6cd"></i> Cheese</div>
<div class="legend" style="margin-top:8px"><i style="background:#7698b4"></i> Specialty</div>
<div class="legend" style="margin-top:8px"><i style="background:#4f9ca2"></i> Seafood</div>
</aside>
<aside class="panel right-panel">
<div class="eyebrow">Selected display</div>
<h2 id="selectedName">Sourdough & Co.</h2>
<p id="selectedDescription" class="intro">
Select any canopy in the plan, then nudge or rotate it.
</p>
<div class="selected-card">
<div class="selected-top">
<div>
<div id="selectedId" class="selected-id">D07</div>
<div id="selectedCategory" class="selected-category">BAKERY</div>
</div>
<div id="selectedClearance" class="clear-badge">CLEAR</div>
</div>
</div>
<div class="details">
<div class="detail">
<span>Grid position</span>
<strong id="selectedCoords">X −12.0 / Z 6.4</strong>
</div>
<div class="detail">
<span>Footprint</span>
<strong id="selectedFootprint">2.8 × 2.0 m</strong>
</div>
</div>
<div class="control-heading">
<span>Nudge display</span>
<span>0.5 m steps</span>
</div>
<div class="nudge-pad">
<button class="up" data-nudge="0,-1" title="Move north">↑</button>
<button class="left" data-nudge="-1,0" title="Move west">←</button>
<button class="down" data-nudge="0,1" title="Move south">↓</button>
<button class="right" data-nudge="1,0" title="Move east">→</button>
</div>
<button id="rotateButton" class="button wide">Rotate 90°</button>
<button id="arrangeButton" class="button primary wide">Re-run valid arrangement</button>
<p class="keyboard-note">
<kbd>↑</kbd><kbd>↓</kbd><kbd>←</kbd><kbd>→</kbd> to move ·
<kbd>R</kbd> to rotate<br />
Drag to orbit · Right-drag to pan · Scroll to zoom
</p>
</aside>
<div class="bottom-bar">
<div class="legend"><i style="background:#168c91"></i> Clear delivery route</div>
<div class="legend"><i style="background:#d49b3f"></i> Clear public exit</div>
<div class="legend"><i style="background:#6986aa"></i> Clear pedestrian spine</div>
<div class="hint"><strong>Click</strong> a display to inspect it</div>
</div>
<div id="toast" class="toast"></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.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce3df");
scene.fog = new THREE.Fog("#dce3df", 65, 110);
const camera = new THREE.OrthographicCamera(-30, 30, 22, -22, 0.1, 180);
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
yaw: -0.58,
polar: 0.78,
distance: 62,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight("#f7f1df", "#6e8179", 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff3d9", 3.15);
sun.position.set(-24, 42, 22);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -40;
sun.shadow.camera.right = 40;
sun.shadow.camera.top = 40;
sun.shadow.camera.bottom = -40;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.00035;
scene.add(sun);
const groundGroup = new THREE.Group();
const buildingGroup = new THREE.Group();
const viaductGroup = new THREE.Group();
const deliveryGroup = new THREE.Group();
const exitGroup = new THREE.Group();
const accessGroup = new THREE.Group();
const stallGroup = new THREE.Group();
scene.add(
groundGroup,
buildingGroup,
viaductGroup,
deliveryGroup,
exitGroup,
accessGroup,
stallGroup
);
const fixedRects = [];
const pickables = [];
const layerGroups = {
delivery: deliveryGroup,
exits: exitGroup,
access: accessGroup,
buildings: buildingGroup,
viaduct: viaductGroup
};
const protectedZones = [
{
id: "delivery",
name: "delivery access",
minX: -24.5,
maxX: 24.5,
minZ: 13,
maxZ: 16.3,
color: "#168c91"
},
{
id: "west-exit",
name: "west public exit",
minX: -17.2,
maxX: -14.2,
minZ: -12,
maxZ: 16.3,
color: "#d49b3f"
},
{
id: "east-exit",
name: "east public exit",
minX: 17,
maxX: 19.8,
minZ: -12,
maxZ: 16.3,
color: "#d49b3f"
},
{
id: "pedestrian-spine",
name: "pedestrian spine",
minX: -2,
maxX: 2,
minZ: -11.4,
maxZ: 13,
color: "#6986aa"
}
];
const colors = {
FLOWERS: "#e68b76",
PRODUCE: "#75a95e",
BAKERY: "#d9a850",
CHEESE: "#f0e6cd",
SPECIALTY: "#7698b4",
SEAFOOD: "#4f9ca2"
};
function makeTextSprite(text, options = {}) {
const {
background = "rgba(250,248,239,0.93)",
foreground = "#14221f",
border = "rgba(20,34,31,0.12)",
scale = [4, 1],
fontSize = 46
} = options;
const c = document.createElement("canvas");
c.width = 640;
c.height = 160;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
ctx.fillStyle = background;
ctx.fillRect(4, 4, c.width - 8, c.height - 8);
if (border) {
ctx.strokeStyle = border;
ctx.lineWidth = 5;
ctx.strokeRect(5, 5, c.width - 10, c.height - 10);
}
let size = fontSize;
ctx.font = `800 ${size}px system-ui, sans-serif`;
while (ctx.measureText(text).width > c.width - 50 && size > 20) {
size -= 2;
ctx.font = `800 ${size}px system-ui, sans-serif`;
}
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 2);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: options.depthTest ?? false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scale[0], scale[1], 1);
sprite.renderOrder = 20;
return sprite;
}
function material(color, roughness = 0.82, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
}
function box(w, h, d, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function registerFixed(rect, label) {
fixedRects.push({ ...rect, label });
}
function makeGround() {
const base = box(
58,
0.5,
42,
material("#b7bcb4"),
0,
-0.3,
0
);
base.castShadow = false;
groundGroup.add(base);
const pavement = box(
51,
0.12,
36,
material("#d9d5c9"),
0,
0,
0
);
pavement.castShadow = false;
groundGroup.add(pavement);
const roadSouth = box(
56,
0.08,
6,
material("#777f7c"),
0,
0.07,
15.5
);
roadSouth.castShadow = false;
groundGroup.add(roadSouth);
const roadWest = box(
5,
0.08,
34,
material("#7a817e"),
-25.1,
0.07,
-1
);
roadWest.castShadow = false;
groundGroup.add(roadWest);
const grid = new THREE.GridHelper(50, 25, "#6f8178", "#9ba49d");
grid.position.y = 0.08;
grid.material.transparent = true;
grid.material.opacity = 0.13;
grid.material.depthWrite = false;
groundGroup.add(grid);
for (let x = -22; x <= 22; x += 5.5) {
const stripe = box(2.4, 0.025, 0.22, material("#e5e2d8"), x, 0.13, 15.5);
stripe.castShadow = false;
groundGroup.add(stripe);
}
}
function makeZone(zone, group) {
const width = zone.maxX - zone.minX;
const depth = zone.maxZ - zone.minZ;
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshBasicMaterial({
color: zone.color,
transparent: true,
opacity: zone.id === "delivery" ? 0.13 : 0.1,
depthWrite: false,
side: THREE.DoubleSide
})
);
plane.rotation.x = -Math.PI / 2;
plane.position.set(
(zone.minX + zone.maxX) / 2,
0.16,
(zone.minZ + zone.maxZ) / 2
);
group.add(plane);
const y = 0.2;
const points = [
new THREE.Vector3(zone.minX, y, zone.minZ),
new THREE.Vector3(zone.maxX, y, zone.minZ),
new THREE.Vector3(zone.maxX, y, zone.maxZ),
new THREE.Vector3(zone.minX, y, zone.maxZ),
new THREE.Vector3(zone.minX, y, zone.minZ)
];
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color: zone.color,
dashSize: 0.9,
gapSize: 0.5,
transparent: true,
opacity: 0.95
})
);
line.computeLineDistances();
group.add(line);
let label = "";
let labelX = 0;
let labelZ = 0;
if (zone.id === "delivery") {
label = "DELIVERY ACCESS · KEEP CLEAR";
labelX = 2;
labelZ = 14.7;
} else if (zone.id === "west-exit") {
label = "PUBLIC EXIT";
labelX = -15.7;
labelZ = 0;
} else if (zone.id === "east-exit") {
label = "PUBLIC EXIT";
labelX = 18.4;
labelZ = 0;
} else {
label = "PEDESTRIAN SPINE";
labelX = 0;
labelZ = 1;
}
const labelSprite = makeTextSprite(label, {
scale: zone.id === "delivery" ? [7.2, 1.05] : [3.4, .82],
background: "rgba(250,248,239,0.92)",
foreground: zone.color,
fontSize: 37
});
labelSprite.position.set(labelX, 0.62, labelZ);
group.add(labelSprite);
}
function arrow(x, z, color, group) {
const shape = new THREE.Shape();
shape.moveTo(-0.7, -0.3);
shape.lineTo(0.1, -0.3);
shape.lineTo(0.1, -0.6);
shape.lineTo(0.8, 0);
shape.lineTo(0.1, 0.6);
shape.lineTo(0.1, 0.3);
shape.lineTo(-0.7, 0.3);
shape.closePath();
const mesh = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.7,
side: THREE.DoubleSide,
depthWrite: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.23, z);
group.add(mesh);
}
function createBuilding(x, z, w, d, h, color, label) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const wall = material(color);
const roofMat = material("#56615e");
const windowMat = material("#36534f", .38, .12);
const litMat = material("#e7c477", .5, .05);
group.add(box(w, h, d, wall, 0, h / 2, 0));
group.add(box(w + .35, .28, d + .35, roofMat, 0, h + .14, 0));
const floors = Math.max(2, Math.floor(h / 2.8));
const cols = Math.max(2, Math.floor(w / 1.7));
for (let floor = 0; floor < floors; floor++) {
const wy = 2.2 + floor * 2.45;
if (wy > h - .5) continue;
for (let col = 0; col < cols; col++) {
const wx = -w / 2 + (col + .5) * (w / cols);
const isLit = (col + floor + x) % 4 === 0;
group.add(
box(
.62,
.9,
.055,
isLit ? litMat : windowMat,
wx,
wy,
d / 2 + .035
)
);
}
}
group.add(
box(
w * .72,
1.25,
.08,
material("#304b45"),
0,
.75,
d / 2 + .04
)
);
if (label) {
const sign = makeTextSprite(label, {
scale: [Math.min(w * .7, 7), .9],
fontSize: 38
});
sign.position.set(0, Math.min(h - .7, 4.2), d / 2 + .3);
group.add(sign);
}
buildingGroup.add(group);
registerFixed(
{
minX: x - w / 2,
maxX: x + w / 2,
minZ: z - d / 2,
maxZ: z + d / 2
},
label || "building"
);
return group;
}
function gableGeometry(w, d, h) {
const a = [-w / 2, 0, -d / 2];
const b = [w / 2, 0, -d / 2];
const c = [0, h, -d / 2];
const dd = [-w / 2, 0, d / 2];
const e = [w / 2, 0, d / 2];
const f = [0, h, d / 2];
const positions = [
...a, ...c, ...b,
...dd, ...f, ...e,
...a, ...dd, ...c,
...c, ...dd, ...f,
...c, ...f, ...e,
...b, ...c, ...e,
...a, ...b, ...dd,
...b, ...e, ...dd
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
function createMarketHall() {
const x = 8.5;
const z = 7.5;
const w = 8;
const d = 4.6;
const group = new THREE.Group();
group.position.set(x, 0, z);
group.add(box(w, 2.5, d, material("#b9c1b5"), 0, 1.25, 0));
const roof = new THREE.Mesh(
gableGeometry(w + .55, d + .5, 1.7),
material("#708a7c", .72, .12)
);
roof.position.y = 2.5;
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
const windowMat = material("#42645d", .32, .16);
for (let i = 0; i < 6; i++) {
group.add(
box(
.82,
1.25,
.055,
windowMat,
-w / 2 + .75 + i * 1.3,
1.45,
d / 2 + .04
)
);
}
const ribs = material("#d9ded3");
for (let i = 0; i <= 4; i++) {
group.add(
box(
.09,
1.72,
d + .55,
ribs,
-w / 2 + (i * w) / 4,
3.33,
0
)
);
}
const sign = makeTextSprite("MARKET HALL · PROTECTED", {
scale: [6.2, .82],
foreground: "#315b4f",
fontSize: 36
});
sign.position.set(0, 3.75, 2.65);
group.add(sign);
buildingGroup.add(group);
registerFixed(
{
minX: x - w / 2,
maxX: x + w / 2,
minZ: z - d / 2,
maxZ: z + d / 2
},
"market hall"
);
}
function createViaduct() {
const group = new THREE.Group();
group.position.z = -2;
const stone = material("#6e7772");
const dark = material("#4c5753");
const rail = material("#3c4542", .42, .42);
group.add(box(50, .5, 5.2, stone, 0, 6.65, 0));
for (let x = -22; x <= 22; x += 5) {
for (const z of [-2.35, 2.35]) {
group.add(box(.48, 4.15, .48, stone, x, 2.08, z));
const arch = new THREE.Mesh(
new THREE.TorusGeometry(2.05, .27, 4, 9, Math.PI),
stone
);
arch.position.set(x + 2.5, 4.15, z);
arch.scale.y = 1.08;
arch.castShadow = true;
group.add(arch);
}
}
for (const z of [-1.85, .85]) {
group.add(box(50, .12, .13, rail, 0, 6.98, z));
}
for (let x = -24; x <= 24; x += 1.25) {
group.add(box(.18, .12, 3.2, dark, x, 6.94, 0));
}
const sign = makeTextSprite("LONDON BRIDGE · RAIL VIADUCT", {
scale: [7.5, .8],
foreground: "#4b5753",
fontSize: 34
});
sign.position.set(-7, 7.65, 3.05);
group.add(sign);
viaductGroup.add(group);
registerFixed(
{
minX: -25,
maxX: 25,
minZ: -4.8,
maxZ: .8
},
"rail viaduct"
);
}
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
group.add(
box(.26, 1.8, .26, material("#7a6650"), 0, .9, 0)
);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.15, 0),
material("#64866a")
);
crown.position.y = 2.25;
crown.castShadow = true;
group.add(crown);
groundGroup.add(group);
}
function createLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.add(box(.11, 3.8, .11, material("#44504c"), 0, 1.9, 0));
group.add(box(.7, .12, .42, material("#44504c"), .25, 3.82, 0));
group.add(
box(.42, .09, .28, material("#f2d892", .45, .05), .46, 3.72, 0)
);
groundGroup.add(group);
}
function createDeliveryTruck() {
const group = new THREE.Group();
group.position.set(-19.5, 0, 9.5);
group.rotation.y = Math.PI / 2;
group.add(box(2.2, 2.25, 4.2, material("#eeeadd"), 0, 1.35, -.65));
group.add(box(2.05, 1.6, 1.6, material("#d8e0d8"), 0, 1.05, 2.25));
group.add(box(1.75, .62, .05, material("#41615b"), 0, 1.45, 3.08));
group.add(box(.12, 1.8, .12, material("#53605b"), 0, 2.7, .8));
for (const x of [-1.1, 1.1]) {
for (const z of [-1.7, 1.8]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(.46, .46, .3, 10),
material("#353b38")
);
wheel.rotation.z = Math.PI / 2;
wheel.position.set(x, .48, z);
group.add(wheel);
}
}
groundGroup.add(group);
}
function createStall(record) {
const group = new THREE.Group();
group.position.set(record.x, 0, record.z);
group.rotation.y = record.rot ? Math.PI / 2 : 0;
group.userData.stall = record;
record.group = group;
const frame = material("#5b5147");
const counter = material("#d4c5a8");
const dark = material("#3d4a44");
const awningA = material(record.color);
const awningB = material("#f2ead8");
const addPickable = mesh => {
mesh.userData.stall = record;
pickables.push(mesh);
group.add(mesh);
return mesh;
};
for (const x of [-1.05, 1.05]) {
for (const z of [-.68, .68]) {
addPickable(box(.09, 2.25, .09, frame, x, 1.12, z));
}
}
addPickable(box(2.65, .62, 1.18, counter, 0, .72, 0));
addPickable(box(2.85, .12, 1.32, dark, 0, 1.08, 0));
for (let i = 0; i < 10; i++) {
const stripe = box(
.28,
.11,
2.18,
i % 2 ? awningB : awningA,
-1.26 + i * .28,
2.28,
0
);
stripe.castShadow = true;
group.add(stripe);
}
addPickable(box(2.85, .35, .07, awningA, 0, 2.08, 1.08));
addPickable(box(2.85, .35, .07, awningB, 0, 2.08, -1.08));
const crateMat = material("#8d7052");
const goodsMat = material(record.color);
for (let i = 0; i < 3; i++) {
const x = -.8 + i * .8;
addPickable(box(.5, .28, .58, crateMat, x, 1.27, -.02));
const goods = new THREE.Mesh(
new THREE.IcosahedronGeometry(.18, 0),
goodsMat
);
goods.position.set(x, 1.53, -.02);
goods.castShadow = true;
group.add(goods);
}
const sign = makeTextSprite(`${record.id} ${record.category}`, {
scale: [2.65, .58],
foreground: record.color,
fontSize: 40
});
sign.position.set(0, 2.82, 0);
group.add(sign);
stallGroup.add(group);
}
const stalls = [
{ id: "D01", name: "Petal & Stem", category: "FLOWERS", x: -11, z: -8.5, rot: 0 },
{ id: "D02", name: "Mallow Flowers", category: "FLOWERS", x: -7, z: -8.5, rot: 0 },
{ id: "D03", name: "Rose Street", category: "FLOWERS", x: -4.5, z: -8.5, rot: 0 },
{ id: "D04", name: "Orchard Row", category: "PRODUCE", x: 5, z: -8.5, rot: 0 },
{ id: "D05", name: "Green Basket", category: "PRODUCE", x: 8.5, z: -8.5, rot: 0 },
{ id: "D06", name: "Seasonal Fruits", category: "PRODUCE", x: 12, z: -8.5, rot: 0 },
{ id: "D07", name: "Sourdough & Co.", category: "BAKERY", x: -12, z: 3.2, rot: 0 },
{ id: "D08", name: "Crumb Bakery", category: "BAKERY", x: -12, z: 6.4, rot: 0 },
{ id: "D09", name: "Morning Loaf", category: "BAKERY", x: -12, z: 9.6, rot: 0 },
{ id: "D10", name: "The Cheese Room", category: "CHEESE", x: -7.5, z: 4.2, rot: 0 },
{ id: "D11", name: "Truckle & Co.", category: "CHEESE", x: -7.5, z: 7.5, rot: 0 },
{ id: "D12", name: "Wheelhouse", category: "CHEESE", x: -7.5, z: 10.6, rot: 0 },
{ id: "D13", name: "Little London", category: "SPECIALTY", x: -3.7, z: 3.5, rot: 0 },
{ id: "D14", name: "The Borough Edit", category: "SPECIALTY", x: -3.7, z: 10.4, rot: 0 },
{ id: "D15", name: "South Shore Fish", category: "SEAFOOD", x: 14.6, z: 3.5, rot: 0 },
{ id: "D16", name: "Net & Knot", category: "SEAFOOD", x: 14.6, z: 6.7, rot: 0 },
{ id: "D17", name: "Pier 57", category: "SEAFOOD", x: 14.6, z: 9.9, rot: 0 }
];
makeGround();
createBuilding(-16, -15.5, 11, 6, 10, "#a87865", "BOROUGH MARKET");
createBuilding(-2.5, -15.5, 12, 6, 12.5, "#9c7466", "ST JAMES'S");
createBuilding(11.5, -15.5, 13, 6, 9.5, "#b08369", "TOWER BRIDGE");
createBuilding(-23, -4, 4, 12, 8, "#8d7569", "");
createBuilding(23, -2, 4, 16, 11, "#92715f", "");
createMarketHall();
createViaduct();
protectedZones.forEach(zone => {
if (zone.id === "delivery") makeZone(zone, deliveryGroup);
else if (zone.id === "pedestrian-spine") makeZone(zone, accessGroup);
else makeZone(zone, exitGroup);
});
for (const x of [-16, -5, 5, 15]) arrow(x, 14.7, "#168c91", deliveryGroup);
createTree(-20, 5.5, .9);
createTree(-20, 11.5, .82);
createTree(20.5, 4, .85);
createTree(20.5, 10.5, .75);
createTree(-19, -10.5, .8);
createTree(19.5, -10.5, .85);
createTree(0, -11.4, .65);
createLamp(-13.5, 12);
createLamp(-2.8, 12);
createLamp(3.2, 12);
createLamp(13.5, 12);
createLamp(-19.5, 1.5);
createLamp(20.5, 1.5);
createDeliveryTruck();
stalls.forEach(createStall);
const selectionMaterial = new THREE.LineBasicMaterial({
color: "#ffffff",
transparent: true,
opacity: 0.95,
depthTest: false
});
const selectionPoints = [
new THREE.Vector3(-1.55, 0, -1.15),
new THREE.Vector3(1.55, 0, -1.15),
new THREE.Vector3(1.55, 0, 1.15),
new THREE.Vector3(-1.55, 0, 1.15)
];
const selectionRing = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(selectionPoints),
selectionMaterial
);
selectionRing.position.y = 0.27;
selectionRing.renderOrder = 30;
scene.add(selectionRing);
let selected = stalls.find(s => s.id === "D07");
function rectForStall(stall) {
const hx = stall.rot ? 1.0 : 1.4;
const hz = stall.rot ? 1.4 : 1.0;
return {
minX: stall.x - hx,
maxX: stall.x + hx,
minZ: stall.z - hz,
maxZ: stall.z + hz
};
}
function overlaps(a, b, padding = 0.02) {
return (
a.minX < b.maxX + padding &&
a.maxX > b.minX - padding &&
a.minZ < b.maxZ + padding &&
a.maxZ > b.minZ - padding
);
}
function candidateViolation(stall, x, z, rotation, ignoreId = stall.id) {
const candidate = {
id: stall.id,
x,
z,
rot: rotation ? 1 : 0
};
const rect = rectForStall(candidate);
if (rect.minX < -20.7 || rect.maxX > 20.7 || rect.minZ < -11.4 || rect.maxZ > 12.7) {
return "The display would leave the operating market area.";
}
for (const zone of protectedZones) {
if (overlaps(rect, zone)) {
return `${zone.name.charAt(0).toUpperCase() + zone.name.slice(1)} must remain clear.`;
}
}
for (const fixed of fixedRects) {
if (overlaps(rect, fixed)) {
return `${fixed.label.charAt(0).toUpperCase() + fixed.label.slice(1)} is a protected building form.`;
}
}
for (const other of stalls) {
if (other.id === ignoreId) continue;
if (overlaps(rect, rectForStall(other))) {
return `${other.id} would overlap the display footprint.`;
}
}
return null;
}
function validateAll() {
const violations = [];
for (const stall of stalls) {
const issue = candidateViolation(stall, stall.x, stall.z, stall.rot);
if (issue) violations.push({ id: stall.id, issue });
}
return violations;
}
function updateSelection() {
if (!selected) return;
selected.group.position.x = selected.x;
selected.group.position.z = selected.z;
selected.group.rotation.y = selected.rot ? Math.PI / 2 : 0;
selectionRing.position.set(selected.x, 0.27, selected.z);
selectionRing.rotation.y = selected.rot ? Math.PI / 2 : 0;
const issue = candidateViolation(
selected,
selected.x,
selected.z,
selected.rot
);
document.getElementById("selectedId").textContent = selected.id;
document.getElementById("selectedName").textContent = selected.name;
document.getElementById("selectedCategory").textContent = selected.category;
document.getElementById("selectedDescription").textContent =
`${selected.name} is ${issue ? "currently blocked" : "clear of all protected access routes"}.`;
document.getElementById("selectedCoords").textContent =
`X ${selected.x.toFixed(1)} / Z ${selected.z.toFixed(1)}`;
document.getElementById("selectedFootprint").textContent = selected.rot
? "2.0 × 2.8 m"
: "2.8 × 2.0 m";
const badge = document.getElementById("selectedClearance");
badge.textContent = issue ? "BLOCKED" : "CLEAR";
badge.classList.toggle("invalid", Boolean(issue));
updateValidationUI();
}
function updateValidationUI() {
const violations = validateAll();
const count = violations.length;
document.getElementById("displayMetric").textContent = stalls.length;
document.getElementById("conflictMetric").textContent = count;
const globalStatus = document.getElementById("globalStatus");
globalStatus.textContent = count ? `${count} conflict${count === 1 ? "" : "s"}` : "Plan valid";
globalStatus.classList.toggle("invalid", count > 0);
}
function toast(message) {
const el = document.getElementById("toast");
el.textContent = message;
el.classList.add("show");
clearTimeout(toast.timer);
toast.timer = setTimeout(() => el.classList.remove("show"), 2600);
}
function selectStall(stall) {
selected = stall;
updateSelection();
}
function nudge(dx, dz) {
if (!selected) return;
const x = selected.x + dx * .5;
const z = selected.z + dz * .5;
const issue = candidateViolation(selected, x, z, selected.rot);
if (issue) {
toast(`Move blocked: ${issue}`);
return;
}
selected.x = x;
selected.z = z;
updateSelection();
}
function rotateSelected() {
if (!selected) return;
const rotation = selected.rot ? 0 : 1;
const issue = candidateViolation(
selected,
selected.x,
selected.z,
rotation
);
if (issue) {
toast(`Rotation blocked: ${issue}`);
return;
}
selected.rot = rotation;
updateSelection();
toast(`${selected.id} rotated. Protected clearances preserved.`);
}
function candidateOffsets() {
const offsets = [[0, 0]];
for (let radius = 1; radius <= 5; radius++) {
for (let dx = -radius; dx <= radius; dx++) {
for (let dz = -radius; dz <= radius; dz++) {
if (Math.max(Math.abs(dx), Math.abs(dz)) === radius) {
offsets.push([dx * .35, dz * .35]);
}
}
}
}
return offsets;
}
function runArrangement() {
const anchors = {
FLOWERS: [
[-11, -8.5],
[-7, -8.5],
[-4.5, -8.5]
],
PRODUCE: [
[5, -8.5],
[8.5, -8.5],
[12, -8.5]
],
BAKERY: [
[-12, 3.2],
[-12, 6.4],
[-12, 9.6]
],
CHEESE: [
[-7.5, 4.2],
[-7.5, 7.5],
[-7.5, 10.6]
],
SPECIALTY: [
[-3.7, 3.5],
[-3.7, 10.4]
],
SEAFOOD: [
[14.6, 3.5],
[14.6, 6.7],
[14.6, 9.9]
]
};
const order = [
"FLOWERS",
"PRODUCE",
"BAKERY",
"SEAFOOD",
"CHEESE",
"SPECIALTY"
];
const placed = [];
const results = [];
for (const category of order) {
const categoryStalls = stalls.filter(s => s.category === category);
for (let index = 0; index < categoryStalls.length; index++) {
const stall = categoryStalls[index];
const categoryAnchors = anchors[category];
let found = null;
for (
let anchorIndex = 0;
anchorIndex < categoryAnchors.length && !found;
anchorIndex++
) {
const anchor = categoryAnchors[
(anchorIndex + index) % categoryAnchors.length
];
for (const [ox, oz] of candidateOffsets()) {
const x = anchor[0] + ox;
const z = anchor[1] + oz;
const trial = { ...stall, x, z };
const issue = candidateViolation(trial, x, z, stall.rot);
if (!issue) {
const rect = rectForStall(trial);
const collision = placed.some(
p => overlaps(rect, rectForStall(p))
);
if (!collision) {
found = { id: stall.id, x, z, rot: stall.rot };
break;
}
}
}
}
if (!found) {
toast("A fully valid compact arrangement could not be placed.");
return;
}
placed.push(found);
results.push(found);
}
}
for (const result of results) {
const stall = stalls.find(s => s.id === result.id);
stall.x = result.x;
stall.z = result.z;
stall.rot = result.rot;
}
updateSelection();
toast(`${stalls.length} displays consolidated with zero protected-route conflicts.`);
}
function exportPlan() {
const payload = {
project: "London Borough Market — Protected Display Rearrangement",
proposal: "04",
units: "metres",
protectedZones,
fixedElements: fixedRects,
displays: stalls.map(({ id, name, category, x, z, rot }) => ({
id,
name,
category,
x,
z,
rotation: rot ? 90 : 0
})),
validation: {
conflicts: validateAll().length,
deliveryAccess: "clear",
publicExits: "clear",
pedestrianSpine: "clear",
buildingForms: "unchanged",
viaduct: "unchanged"
}
};
const blob = new Blob([JSON.stringify(payload, null, 2)], {
type: "application/json"
});
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "borough-market-rearrangement.json";
a.click();
URL.revokeObjectURL(url);
toast("Plan exported with protected zones and display coordinates.");
}
document.querySelectorAll("[data-nudge]").forEach(button => {
button.addEventListener("click", () => {
const [dx, dz] = button.dataset.nudge.split(",").map(Number);
nudge(dx, dz);
});
});
document.getElementById("rotateButton").addEventListener(
"click",
rotateSelected
);
document.getElementById("arrangeButton").addEventListener(
"click",
runArrangement
);
document.getElementById("exportButton").addEventListener(
"click",
exportPlan
);
document.querySelectorAll("[data-layer]").forEach(input => {
input.addEventListener("change", () => {
const group = layerGroups[input.dataset.layer];
if (group) group.visible = input.checked;
});
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const drag = {
active: false,
moved: false,
button: 0,
lastX: 0,
lastY: 0,
mode: "orbit"
};
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickDisplay(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (!hits.length) return;
const stall = hits[0].object.userData.stall;
if (stall) selectStall(stall);
}
function updateCamera() {
const { target, yaw, polar, distance } = cameraState;
const horizontal = Math.sin(polar) * distance;
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + Math.cos(polar) * distance,
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resetView() {
cameraState.target.set(0, 0, 0);
cameraState.yaw = -0.58;
cameraState.polar = 0.78;
cameraState.zoom = 1;
updateCamera();
}
document.getElementById("resetViewButton").addEventListener(
"click",
resetView
);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
drag.active = true;
drag.moved = false;
drag.button = event.button;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
drag.mode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!drag.active) return;
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) drag.moved = true;
if (drag.mode === "orbit") {
cameraState.yaw -= dx * .006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * .005,
.38,
1.32
);
updateCamera();
} else {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(
forward,
new THREE.Vector3(0, 1, 0)
);
const worldPerPixel =
(camera.top - camera.bottom) /
(window.innerHeight * camera.zoom);
cameraState.target.addScaledVector(
right,
-dx * worldPerPixel
);
cameraState.target.addScaledVector(
forward,
dy * worldPerPixel
);
updateCamera();
}
});
canvas.addEventListener("pointerup", event => {
if (!drag.moved && drag.button === 0) pickDisplay(event);
drag.active = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
drag.active = false;
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (event.deltaY > 0 ? .9 : 1.1),
.65,
2.6
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (!selected) return;
if (/INPUT|TEXTAREA|SELECT/.test(document.activeElement.tagName)) return;
const key = event.key.toLowerCase();
if (key === "arrowup") {
event.preventDefault();
nudge(0, -1);
} else if (key === "arrowdown") {
event.preventDefault();
nudge(0, 1);
} else if (key === "arrowleft") {
event.preventDefault();
nudge(-1, 0);
} else if (key === "arrowright") {
event.preventDefault();
nudge(1, 0);
} else if (key === "r") {
rotateSelected();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
let halfHeight = 22;
if (aspect < 1.4) halfHeight = 31 / aspect;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
updateSelection();
updateCamera();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```