Prompt specification
Build or customize the Three.js 3D scene "Temporary exhibition layout challenge" 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: Temporary exhibition layout challenge
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/temporary-exhibition-layout-challenge-x0216
Scene Description Prompt:
Rearrange low-poly gallery screens and artworks while keeping every exhibit reachable from two exits. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (temporary-exhibition-layout-challenge-x0216):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gallery Flow — Low-Poly Layout Studio</title>
<style>
:root {
--ink: #172423;
--muted: #6c7975;
--paper: #f7f8f3;
--panel: rgba(250, 251, 247, 0.92);
--line: rgba(35, 57, 52, 0.12);
--green: #168b7b;
--green-soft: #d9f2e9;
--orange: #e99a4b;
--red: #d65e58;
--shadow: 0 18px 45px rgba(34, 52, 47, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe7e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 0;
left: 0;
right: 0;
height: 74px;
padding: 0 24px;
display: flex;
align-items: center;
justify-content: space-between;
background: rgba(247, 248, 243, 0.9);
border-bottom: 1px solid var(--line);
backdrop-filter: blur(18px);
box-shadow: 0 5px 20px rgba(35, 52, 47, 0.06);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 35px;
height: 35px;
transform: rotate(-6deg);
}
.brand-mark span {
position: absolute;
display: block;
border-radius: 3px;
}
.brand-mark span:nth-child(1) {
inset: 2px 15px 15px 2px;
background: var(--green);
}
.brand-mark span:nth-child(2) {
inset: 15px 2px 2px 15px;
background: var(--orange);
}
.brand-mark span:nth-child(3) {
inset: 5px 5px 5px 5px;
border: 2px solid var(--ink);
background: rgba(247, 248, 243, 0.85);
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1;
letter-spacing: 0.01em;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.project-meta {
display: flex;
align-items: center;
gap: 20px;
}
.project-copy {
text-align: right;
}
.project-copy strong {
display: block;
font-size: 12px;
letter-spacing: 0.02em;
}
.project-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
color: #0f6d61;
background: var(--green-soft);
border: 1px solid rgba(22, 139, 123, 0.15);
border-radius: 999px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.live-pill::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #21aa91;
box-shadow: 0 0 0 4px rgba(33, 170, 145, 0.12);
}
.panel {
position: fixed;
z-index: 15;
top: 94px;
width: 292px;
max-height: calc(100vh - 194px);
padding: 21px;
overflow: auto;
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(35, 57, 52, 0.18) transparent;
}
.panel.left {
left: 20px;
}
.panel.right {
right: 20px;
width: 318px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 21px;
letter-spacing: -0.035em;
}
.panel-intro {
margin: 8px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.filters {
display: flex;
gap: 6px;
margin-bottom: 12px;
}
.filter-button {
flex: 1;
padding: 8px 6px;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.filter-button.active {
color: white;
background: var(--ink);
border-color: var(--ink);
}
.inventory {
display: grid;
gap: 7px;
}
.exhibit-row {
width: 100%;
padding: 10px;
display: grid;
grid-template-columns: 32px 1fr auto;
align-items: center;
gap: 10px;
text-align: left;
border: 1px solid transparent;
border-radius: 11px;
background: rgba(255, 255, 255, 0.58);
cursor: pointer;
transition: 150ms ease;
}
.exhibit-row:hover {
transform: translateX(2px);
background: white;
}
.exhibit-row.selected {
border-color: rgba(22, 139, 123, 0.3);
background: #eef7f2;
box-shadow: inset 3px 0 0 var(--green);
}
.exhibit-row.issue {
border-color: rgba(214, 94, 88, 0.28);
background: #fff4f1;
}
.exhibit-icon {
position: relative;
width: 32px;
height: 32px;
border-radius: 8px;
background: var(--swatch);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.exhibit-icon::after {
content: "";
position: absolute;
inset: 7px;
border: 2px solid rgba(255, 255, 255, 0.78);
border-radius: 2px;
}
.exhibit-icon.screen::after {
inset: 9px 5px;
}
.exhibit-name {
min-width: 0;
}
.exhibit-name strong,
.exhibit-name span {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.exhibit-name strong {
font-size: 11px;
}
.exhibit-name span {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.route-dots {
display: flex;
gap: 4px;
}
.route-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 2px rgba(22, 139, 123, 0.1);
}
.route-dot.bad {
background: var(--red);
box-shadow: 0 0 0 2px rgba(214, 94, 88, 0.1);
}
.route-dot.b {
background: var(--orange);
box-shadow: 0 0 0 2px rgba(233, 154, 75, 0.11);
}
.legend {
display: grid;
gap: 7px;
margin-top: 17px;
padding-top: 15px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.legend-line {
width: 22px;
height: 3px;
border-radius: 99px;
background: var(--green);
}
.legend-line.b {
background: var(--orange);
}
.audit-hero {
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.56);
}
.audit-hero.pass {
border-color: rgba(22, 139, 123, 0.19);
background: linear-gradient(135deg, #e6f5ed, rgba(255, 255, 255, 0.65));
}
.audit-hero.fail {
border-color: rgba(214, 94, 88, 0.2);
background: linear-gradient(135deg, #fff0ed, rgba(255, 255, 255, 0.65));
}
.audit-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.audit-title strong {
font-size: 13px;
}
.audit-badge {
padding: 5px 8px;
color: white;
background: var(--green);
border-radius: 999px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.fail .audit-badge {
background: var(--red);
}
.audit-hero p {
margin: 8px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.exit-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 12px 0;
}
.exit-card {
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.52);
}
.exit-card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 5px;
font-size: 10px;
font-weight: 800;
}
.exit-letter {
display: grid;
width: 23px;
height: 23px;
place-items: center;
color: white;
border-radius: 7px;
background: var(--green);
font-size: 10px;
}
.exit-card.b .exit-letter {
background: var(--orange);
}
.exit-count {
display: block;
margin-top: 10px;
font-size: 20px;
font-weight: 800;
letter-spacing: -0.04em;
}
.exit-count small {
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0;
}
.section-label {
margin: 17px 0 9px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.issue-list {
display: grid;
gap: 6px;
}
.issue-row,
.all-clear {
display: flex;
gap: 8px;
align-items: flex-start;
padding: 9px 10px;
color: var(--muted);
border-radius: 9px;
background: rgba(255, 255, 255, 0.45);
font-size: 10px;
line-height: 1.4;
}
.issue-row {
color: #9c4541;
background: rgba(214, 94, 88, 0.08);
}
.check-icon {
color: var(--green);
font-weight: 900;
}
.issue-row .check-icon {
color: var(--red);
}
.selected-card {
margin-top: 14px;
padding: 12px;
border: 1px dashed rgba(35, 57, 52, 0.22);
border-radius: 12px;
}
.selected-card .selected-title {
display: flex;
justify-content: space-between;
gap: 10px;
font-size: 11px;
font-weight: 800;
}
.selected-card .selected-title span:last-child {
color: var(--green);
}
.selected-meta {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: var(--muted);
font-size: 9px;
}
.guard {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding: 11px 0 0;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.switch {
position: relative;
width: 35px;
height: 20px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
}
.switch-track {
position: absolute;
inset: 0;
border-radius: 99px;
background: #c7cfca;
cursor: pointer;
transition: 150ms ease;
}
.switch-track::after {
content: "";
position: absolute;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
transition: 150ms ease;
}
.switch input:checked + .switch-track {
background: var(--green);
}
.switch input:checked + .switch-track::after {
transform: translateX(15px);
}
.toolbar {
position: fixed;
z-index: 25;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 7px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 15px;
background: rgba(247, 248, 243, 0.92);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.tool-button {
min-width: 38px;
height: 38px;
padding: 0 12px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 7px;
border: 1px solid transparent;
border-radius: 10px;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 750;
white-space: nowrap;
transition: 140ms ease;
}
.tool-button:hover {
background: rgba(23, 36, 35, 0.07);
}
.tool-button.primary {
color: white;
background: var(--ink);
}
.tool-button.primary:hover {
background: #2c403d;
}
.tool-button.accent {
color: white;
background: var(--green);
}
.tool-button.accent:hover {
background: #117b6d;
}
.tool-button.icon {
padding: 0;
font-size: 17px;
}
.tool-divider {
width: 1px;
height: 24px;
background: var(--line);
}
.hint {
position: fixed;
z-index: 12;
left: 50%;
bottom: 78px;
transform: translateX(-50%);
padding: 7px 11px;
color: rgba(23, 36, 35, 0.72);
border-radius: 999px;
background: rgba(247, 248, 243, 0.72);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(10px);
}
.toast {
position: fixed;
z-index: 40;
left: 50%;
top: 92px;
transform: translate(-50%, -15px);
max-width: min(420px, calc(100vw - 40px));
padding: 11px 16px;
color: white;
border-radius: 10px;
background: rgba(23, 36, 35, 0.94);
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 650;
opacity: 0;
pointer-events: none;
transition: 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1000px) {
.panel.left {
width: 250px;
}
.panel.right {
width: 270px;
}
.tool-button .button-label {
display: none;
}
.tool-button {
padding: 0 10px;
}
}
@media (max-width: 760px) {
.project-copy,
.hint {
display: none;
}
.topbar {
height: 64px;
padding: 0 14px;
}
.panel {
top: 76px;
max-height: calc(100vh - 152px);
padding: 15px;
}
.panel.left {
left: 10px;
width: 205px;
}
.panel.right {
right: 10px;
width: 220px;
}
.panel h2 {
font-size: 17px;
}
.panel-intro,
.legend,
.selected-card,
.section-label,
.issue-list {
display: none;
}
.inventory {
max-height: 255px;
overflow: auto;
}
.exhibit-row {
grid-template-columns: 27px 1fr;
}
.exhibit-icon {
width: 27px;
height: 27px;
}
.route-dots {
display: none;
}
.toolbar {
bottom: 8px;
width: calc(100vw - 16px);
justify-content: center;
flex-wrap: wrap;
}
}
@media (max-width: 520px) {
.panel.right {
display: none;
}
.panel.left {
width: 180px;
}
.live-pill {
padding: 8px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div>
<h1>Gallery Flow</h1>
<p>Low-poly layout studio</p>
</div>
</div>
<div class="project-meta">
<div class="project-copy">
<strong>Project 07 / Modern Forms</strong>
<span>8 exhibits · 2 exits</span>
</div>
<div class="live-pill">Live plan</div>
</div>
</header>
<aside class="panel left">
<div class="eyebrow">Collection</div>
<h2>Exhibit layout</h2>
<p class="panel-intro">
Drag screens and artworks directly on the gallery floor. Access routes update
automatically while you arrange.
</p>
<div class="filters">
<button class="filter-button active" data-filter="all">All</button>
<button class="filter-button" data-filter="screen">Screens</button>
<button class="filter-button" data-filter="artwork">Artworks</button>
</div>
<div id="inventory" class="inventory"></div>
<div class="legend">
<div class="legend-row">
<span class="legend-line"></span>
Exit A route
</div>
<div class="legend-row">
<span class="legend-line b"></span>
Exit B route
</div>
<div class="legend-row">Drag empty space to orbit · scroll to zoom</div>
</div>
</aside>
<aside class="panel right">
<div class="eyebrow">Path audit</div>
<h2>Dual-exit access</h2>
<p class="panel-intro">
Every exhibit must have a navigable approach from both marked exits.
</p>
<div id="audit-hero" class="audit-hero pass">
<div class="audit-title">
<strong id="audit-title">Layout is clear</strong>
<span id="audit-badge" class="audit-badge">Pass</span>
</div>
<p id="audit-copy">All exhibits are reachable from both exits.</p>
</div>
<div class="exit-list">
<div class="exit-card">
<div class="exit-card-top">
<span class="exit-letter">A</span>
<span>Exit A</span>
</div>
<span id="exit-a-count" class="exit-count">8 <small>/ 8 reached</small></span>
</div>
<div class="exit-card b">
<div class="exit-card-top">
<span class="exit-letter">B</span>
<span>Exit B</span>
</div>
<span id="exit-b-count" class="exit-count">8 <small>/ 8 reached</small></span>
</div>
</div>
<div class="section-label">Audit findings</div>
<div id="issues" class="issue-list"></div>
<div id="selected-card" class="selected-card"></div>
<label class="guard">
<span>Protect dual-exit access while moving</span>
<span class="switch">
<input id="protect-toggle" type="checkbox" checked />
<span class="switch-track"></span>
</span>
</label>
</aside>
<div class="hint">Drag an exhibit to move it · R to rotate · Arrow keys to nudge</div>
<nav class="toolbar" aria-label="Layout tools">
<button class="tool-button primary" data-action="audit" title="Validate and show routes">
✓ <span class="button-label">Audit routes</span>
</button>
<button class="tool-button accent" data-action="arrange" title="Create a safe arrangement">
✦ <span class="button-label">Safe layout</span>
</button>
<button class="tool-button" data-action="rotate" title="Rotate selected exhibit">
↻ <span class="button-label">Rotate</span>
</button>
<div class="tool-divider"></div>
<button class="tool-button icon" data-action="zoom-in" title="Zoom in">+</button>
<button class="tool-button icon" data-action="zoom-out" title="Zoom out">−</button>
<button class="tool-button icon" data-action="camera" title="Reset camera">⌂</button>
<button class="tool-button icon" data-action="reset" title="Reset layout">⟲</button>
</nav>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const inventoryEl = document.getElementById("inventory");
const issuesEl = document.getElementById("issues");
const selectedCardEl = document.getElementById("selected-card");
const auditHeroEl = document.getElementById("audit-hero");
const auditTitleEl = document.getElementById("audit-title");
const auditBadgeEl = document.getElementById("audit-badge");
const auditCopyEl = document.getElementById("audit-copy");
const exitACountEl = document.getElementById("exit-a-count");
const exitBCountEl = document.getElementById("exit-b-count");
const protectToggle = document.getElementById("protect-toggle");
const toastEl = document.getElementById("toast");
const COLS = 20;
const ROWS = 14;
const CELL = 1.5;
const ORIGIN_X = -((COLS - 1) * CELL) / 2;
const ORIGIN_Z = -((ROWS - 1) * CELL) / 2;
const WORLD_W = 30;
const WORLD_D = 20;
const EXIT_A = { id: "a", name: "Exit A", col: 2, row: 13, color: 0x168b7b };
const EXIT_B = { id: "b", name: "Exit B", col: 17, row: 13, color: 0xe99a4b };
const initialItems = [
{
id: "S-01",
name: "Chromatic Pulse",
type: "screen",
visual: "screen",
col: 3,
row: 2,
rotation: 0,
swatch: "#647bc4"
},
{
id: "S-02",
name: "Signal / Noise",
type: "screen",
visual: "screen",
col: 7,
row: 2,
rotation: 0,
swatch: "#df7961"
},
{
id: "S-03",
name: "Soft Geometry",
type: "screen",
visual: "screen",
col: 12,
row: 2,
rotation: 0,
swatch: "#3e9b89"
},
{
id: "S-04",
name: "Infinite Field",
type: "screen",
visual: "screen",
col: 16,
row: 2,
rotation: 0,
swatch: "#9670b7"
},
{
id: "A-01",
name: "Folded Horizon",
type: "artwork",
visual: "panel",
col: 4,
row: 6,
rotation: 0,
swatch: "#d59b58"
},
{
id: "A-02",
name: "Counterweight",
type: "artwork",
visual: "sculpture",
col: 9,
row: 5,
rotation: 0,
swatch: "#c5675d"
},
{
id: "A-03",
name: "Quiet Assembly",
type: "artwork",
visual: "panel",
col: 15,
row: 6,
rotation: 0,
swatch: "#578f91"
},
{
id: "A-04",
name: "Afterimage",
type: "artwork",
visual: "sculpture",
col: 8,
row: 9,
rotation: 0,
swatch: "#8167a0"
}
];
let items = initialItems.map(item => ({ ...item }));
let selectedId = "S-02";
let activeFilter = "all";
let showRoutes = true;
let latestAudit = null;
let toastTimer = null;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe7e3);
scene.fog = new THREE.Fog(0xdfe7e3, 43, 78);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
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.08;
viewport.appendChild(renderer.domElement);
const hemiLight = new THREE.HemisphereLight(0xf8fff9, 0x7d8e86, 2.25);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.25);
sun.position.set(-13, 25, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -20;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d8ff, 0.65);
fill.position.set(18, 12, -16);
scene.add(fill);
const gallery = new THREE.Group();
scene.add(gallery);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e9df,
roughness: 0.88,
metalness: 0.02
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(WORLD_W, 0.34, WORLD_D),
floorMaterial
);
floor.position.y = -0.2;
floor.receiveShadow = true;
gallery.add(floor);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(WORLD_W + 0.4, 0.45, WORLD_D + 0.4),
new THREE.MeshStandardMaterial({ color: 0xb9c4bd, roughness: 0.92 })
);
plinth.position.y = -0.56;
plinth.receiveShadow = true;
gallery.add(plinth);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xf5f3e9,
roughness: 0.82,
metalness: 0
});
const wallSideMaterial = new THREE.MeshStandardMaterial({
color: 0xe4e6dc,
roughness: 0.86,
metalness: 0
});
function addWall(x, z, width, depth, height = 1.55, material = wallMaterial) {
const wall = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
wall.position.set(x, height / 2, z);
wall.castShadow = true;
wall.receiveShadow = true;
gallery.add(wall);
return wall;
}
addWall(0, -10, 30, 0.3, 2.05);
addWall(-15, 0, 0.3, 20, 1.55, wallSideMaterial);
addWall(15, 0, 0.3, 20, 1.55, wallSideMaterial);
// Front wall with two 3 m exit openings centered at x = ±11.25.
addWall(-13.875, 10, 2.25, 0.3, 1.25, wallSideMaterial);
addWall(0, 10, 19.5, 0.3, 1.25, wallSideMaterial);
addWall(13.875, 10, 2.25, 0.3, 1.25, wallSideMaterial);
const gridPoints = [];
for (let c = 0; c < COLS; c++) {
const x = ORIGIN_X + c * CELL;
gridPoints.push(x, 0.012, -10, x, 0.012, 10);
}
for (let r = 0; r < ROWS; r++) {
const z = ORIGIN_Z + r * CELL;
gridPoints.push(-15, 0.012, z, 15, 0.012, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPoints, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x71827a,
transparent: true,
opacity: 0.13
})
);
gallery.add(grid);
function createExit(exit) {
const x = cellCenter(exit.col);
const group = new THREE.Group();
const threshold = new THREE.Mesh(
new THREE.PlaneGeometry(2.7, 0.95),
new THREE.MeshBasicMaterial({
color: exit.color,
transparent: true,
opacity: 0.28
})
);
threshold.rotation.x = -Math.PI / 2;
threshold.position.set(x, 0.035, 9.52);
group.add(threshold);
const postMaterial = new THREE.MeshStandardMaterial({
color: exit.color,
roughness: 0.55,
emissive: exit.color,
emissiveIntensity: 0.08
});
[-1.35, 1.35].forEach(dx => {
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 2.0, 0.18),
postMaterial
);
post.position.set(x + dx, 1.0, 9.82);
post.castShadow = true;
group.add(post);
});
const sign = createLabelSprite(
`${exit.name.toUpperCase()} • ${exit.id.toUpperCase()}`,
exit.color,
"#ffffff",
320,
76
);
sign.scale.set(3.25, 0.77, 1);
sign.position.set(x, 2.55, 9.78);
group.add(sign);
gallery.add(group);
}
createExit(EXIT_A);
createExit(EXIT_B);
// A few non-blocking architectural details along the outer wall.
const benchMaterial = new THREE.MeshStandardMaterial({
color: 0xa8815e,
roughness: 0.8
});
[-7.5, 0, 7.5].forEach(x => {
const bench = new THREE.Mesh(
new THREE.BoxGeometry(2.2, 0.22, 0.55),
benchMaterial
);
bench.position.set(x, 0.48, -9.25);
bench.castShadow = true;
gallery.add(bench);
[-0.78, 0.78].forEach(dx => {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.42, 0.35),
new THREE.MeshStandardMaterial({ color: 0x40534e, roughness: 0.75 })
);
leg.position.set(x + dx, 0.22, -9.25);
leg.castShadow = true;
gallery.add(leg);
});
});
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const itemGroups = new Map();
const itemMeshes = new Map();
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (1664525 * value + 1013904223) >>> 0;
return value / 4294967296;
};
}
function createScreenTexture(index) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 432;
const ctx = canvas.getContext("2d");
const random = seededRandom(100 + index * 41);
const palettes = [
["#142b36", "#47c6b6", "#f3b75b", "#ed6f62"],
["#32224d", "#b06dc6", "#ffad70", "#6dc6d7"],
["#183d3a", "#74c9a8", "#f1e0aa", "#eb8f6f"],
["#172a4d", "#728fd3", "#ef8fa1", "#f1ce79"]
];
const colors = palettes[index % palettes.length];
const gradient = ctx.createLinearGradient(0, 0, 768, 432);
gradient.addColorStop(0, colors[0]);
gradient.addColorStop(1, "#101719");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 768, 432);
for (let i = 0; i < 10; i++) {
ctx.beginPath();
ctx.moveTo(random() * 768, random() * 432);
ctx.lineTo(random() * 768, random() * 432);
ctx.lineTo(random() * 768, random() * 432);
ctx.closePath();
ctx.fillStyle = colors[1 + Math.floor(random() * 3)];
ctx.globalAlpha = 0.2 + random() * 0.45;
ctx.fill();
}
ctx.globalAlpha = 1;
ctx.strokeStyle = "rgba(255,255,255,0.5)";
ctx.lineWidth = 2;
for (let i = 0; i < 6; i++) {
ctx.beginPath();
const y = 50 + i * 63;
ctx.moveTo(36, y);
ctx.bezierCurveTo(
190,
y - random() * 100,
490,
y + random() * 100,
730,
y
);
ctx.stroke();
}
ctx.fillStyle = "rgba(255,255,255,0.88)";
ctx.font = "700 18px sans-serif";
ctx.fillText("MODERN FORMS / GALLERY SIGNAL", 34, 394);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createArtTexture(index) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 640;
const ctx = canvas.getContext("2d");
const random = seededRandom(700 + index * 97);
const palettes = [
["#f0dfb6", "#d36f53", "#345e61", "#e5a047"],
["#dbe5d8", "#567d73", "#e4a05b", "#314f59"],
["#e9d8d0", "#a95053", "#355b66", "#d4af62"],
["#d8d2eb", "#5e6eaa", "#e78e67", "#34514a"]
];
const colors = palettes[index % palettes.length];
ctx.fillStyle = colors[0];
ctx.fillRect(0, 0, 512, 640);
for (let i = 0; i < 8; i++) {
ctx.save();
ctx.translate(random() * 512, random() * 640);
ctx.rotate((random() - 0.5) * 1.4);
ctx.fillStyle = colors[1 + Math.floor(random() * 3)];
ctx.globalAlpha = 0.55 + random() * 0.4;
if (i % 2 === 0) {
ctx.fillRect(-90, -80, 180 + random() * 160, 150);
} else {
ctx.beginPath();
ctx.arc(0, 0, 65 + random() * 75, 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
}
ctx.globalAlpha = 1;
ctx.strokeStyle = "rgba(30,40,38,0.5)";
ctx.lineWidth = 4;
ctx.strokeRect(28, 28, 456, 584);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createLabelSprite(text, background, foreground = "#ffffff", width = 256, height = 70) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 4, width - 8, height - 8, 16);
ctx.fill();
ctx.fillStyle = foreground;
ctx.font = `800 ${Math.floor(height * 0.29)}px sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 20;
return sprite;
}
function createSelectionMarker(item) {
const geometry =
item.type === "screen"
? new THREE.RingGeometry(0.72, 0.82, 40)
: new THREE.RingGeometry(0.82, 0.94, 40);
const material = new THREE.MeshBasicMaterial({
color: 0x168b7b,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthWrite: false
});
const marker = new THREE.Mesh(geometry, material);
marker.rotation.x = -Math.PI / 2;
marker.position.y = 0.04;
if (item.type === "screen") marker.scale.set(2.05, 0.78, 1);
marker.visible = false;
return marker;
}
function createItem(item, index) {
const group = new THREE.Group();
group.userData.itemId = item.id;
group.position.set(cellCenter(item.col), 0, cellCenterRow(item.row));
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x253330,
roughness: 0.48,
metalness: 0.25
});
if (item.visual === "screen") {
[-1.04, 1.04].forEach(x => {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 1.05, 0.16),
darkMaterial
);
leg.position.set(x, 0.53, 0);
leg.castShadow = true;
group.add(leg);
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.65, 0.08, 0.55),
darkMaterial
);
foot.position.set(x, 0.05, 0);
foot.castShadow = true;
group.add(foot);
});
const frame = new THREE.Mesh(
new THREE.BoxGeometry(3.0, 1.7, 0.26),
darkMaterial
);
frame.position.y = 1.72;
frame.castShadow = true;
group.add(frame);
const screen = new THREE.Mesh(
new THREE.PlaneGeometry(2.72, 1.42),
new THREE.MeshBasicMaterial({
map: createScreenTexture(index),
toneMapped: false
})
);
screen.position.set(0, 1.72, 0.137);
group.add(screen);
const badge = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.11, 0.03),
new THREE.MeshBasicMaterial({ color: item.swatch })
);
badge.position.set(1.33, 0.98, 0.15);
group.add(badge);
} else {
const pedestal = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.62, 1.25),
new THREE.MeshStandardMaterial({
color: 0xd7d8cd,
roughness: 0.88
})
);
pedestal.position.y = 0.31;
pedestal.castShadow = true;
pedestal.receiveShadow = true;
group.add(pedestal);
if (item.visual === "panel") {
const frame = new THREE.Mesh(
new THREE.BoxGeometry(1.72, 2.02, 0.16),
new THREE.MeshStandardMaterial({
color: 0x2f3935,
roughness: 0.48,
metalness: 0.18
})
);
frame.position.y = 1.7;
frame.castShadow = true;
group.add(frame);
const art = new THREE.Mesh(
new THREE.PlaneGeometry(1.48, 1.78),
new THREE.MeshBasicMaterial({
map: createArtTexture(index),
toneMapped: false
})
);
art.position.set(0, 1.7, 0.086);
group.add(art);
} else {
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.17, 1.15, 6),
new THREE.MeshStandardMaterial({
color: 0x40514d,
roughness: 0.6,
metalness: 0.2
})
);
stem.position.y = 1.2;
stem.castShadow = true;
group.add(stem);
const shapeMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(item.swatch),
roughness: 0.64,
metalness: 0.05,
flatShading: true
});
const shape = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.74, 0),
shapeMaterial
);
shape.position.y = 2.0;
shape.rotation.set(0.3, 0.6, 0.1);
shape.castShadow = true;
group.add(shape);
const accent = new THREE.Mesh(
new THREE.OctahedronGeometry(0.42, 0),
new THREE.MeshStandardMaterial({
color: 0xe8b35f,
roughness: 0.58,
flatShading: true
})
);
accent.position.set(0.4, 1.35, 0.15);
accent.castShadow = true;
group.add(accent);
}
}
const label = createLabelSprite(
item.id,
item.type === "screen" ? "#243633" : "#7b6252",
"#ffffff",
180,
62
);
label.scale.set(1.55, 0.53, 1);
label.position.y = item.visual === "screen" ? 3.0 : 3.05;
group.add(label);
const selection = createSelectionMarker(item);
group.add(selection);
itemMeshes.set(item.id, selection);
gallery.add(group);
itemGroups.set(item.id, group);
}
items.forEach(createItem);
function cellCenter(col) {
return ORIGIN_X + col * CELL;
}
function cellCenterRow(row) {
return ORIGIN_Z + row * CELL;
}
function itemWorld(item) {
return { x: cellCenter(item.col), z: cellCenterRow(item.row) };
}
function syncItemTransform(item) {
const group = itemGroups.get(item.id);
const position = itemWorld(item);
group.position.set(position.x, 0, position.z);
group.rotation.y = item.rotation * Math.PI / 2;
}
items.forEach(syncItemTransform);
function footprintFor(item) {
let width = item.type === "screen" ? 3.0 : 1.45;
let depth = item.type === "screen" ? 0.8 : 1.45;
if (item.type === "screen" && item.rotation % 2 !== 0) {
[width, depth] = [depth, width];
}
const position = itemWorld(item);
const cells = [];
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
const dx = Math.abs(cellCenter(col) - position.x);
const dz = Math.abs(cellCenterRow(row) - position.z);
if (dx <= width / 2 + 0.04 && dz <= depth / 2 + 0.04) {
cells.push({ col, row, index: row * COLS + col });
}
}
}
return cells;
}
function getOccupancy() {
const map = new Map();
const blocked = new Set();
const overlapIds = new Set();
const issues = [];
items.forEach(item => {
const cells = footprintFor(item);
map.set(item.id, cells);
cells.forEach(cell => blocked.add(cell.index));
});
for (let a = 0; a < items.length; a++) {
for (let b = a + 1; b < items.length; b++) {
const cellsA = map.get(items[a].id);
const cellsB = map.get(items[b].id);
const overlap = cellsA.some(cellA =>
cellsB.some(cellB => cellA.index === cellB.index)
);
if (overlap) {
overlapIds.add(items[a].id);
overlapIds.add(items[b].id);
issues.push(`${items[a].id} overlaps ${items[b].id}.`);
}
}
}
return { map, blocked, overlapIds, overlapIssues: issues };
}
function bfs(start, blocked) {
const distance = new Int32Array(COLS * ROWS);
distance.fill(-1);
const previous = new Int32Array(COLS * ROWS);
previous.fill(-1);
const queue = new Int32Array(COLS * ROWS);
let head = 0;
let tail = 0;
let startIndex = start.row * COLS + start.col;
if (blocked.has(startIndex)) {
const alternatives = [
[start.col, start.row - 1],
[start.col - 1, start.row],
[start.col + 1, start.row]
];
const alternative = alternatives.find(([col, row]) => {
if (col < 0 || col >= COLS || row < 0 || row >= ROWS) return false;
return !blocked.has(row * COLS + col);
});
if (!alternative) {
return { distance, previous, startIndex };
}
startIndex = alternative[1] * COLS + alternative[0];
}
queue[tail++] = startIndex;
distance[startIndex] = 0;
while (head < tail) {
const index = queue[head++];
const col = index % COLS;
const row = Math.floor(index / COLS);
const neighbors = [
[col - 1, row],
[col + 1, row],
[col, row - 1],
[col, row + 1]
];
for (const [nextCol, nextRow] of neighbors) {
if (
nextCol < 0 ||
nextCol >= COLS ||
nextRow < 0 ||
nextRow >= ROWS
) {
continue;
}
const nextIndex = nextRow * COLS + nextCol;
if (blocked.has(nextIndex) || distance[nextIndex] !== -1) continue;
distance[nextIndex] = distance[index] + 1;
previous[nextIndex] = index;
queue[tail++] = nextIndex;
}
}
return { distance, previous, startIndex };
}
function neighborCells(cells) {
const result = [];
const seen = new Set();
cells.forEach(cell => {
const candidates = [
[cell.col - 1, cell.row],
[cell.col + 1, cell.row],
[cell.col, cell.row - 1],
[cell.col, cell.row + 1]
];
candidates.forEach(([col, row]) => {
if (col < 0 || col >= COLS || row < 0 || row >= ROWS) return;
const index = row * COLS + col;
if (seen.has(index)) return;
seen.add(index);
result.push({ col, row, index });
});
});
return result;
}
function findApproach(item, cells, search) {
const candidates = neighborCells(cells);
let best = null;
candidates.forEach(candidate => {
const distance = search.distance[candidate.index];
if (distance < 0) return;
if (!best || distance < best.distance) {
best = { ...candidate, distance };
}
});
return best;
}
function reconstructPath(search, targetIndex) {
if (targetIndex < 0 || search.distance[targetIndex] < 0) return null;
const path = [];
let current = targetIndex;
while (current !== -1) {
path.push(current);
current = search.previous[current];
}
return path.reverse();
}
function validateLayout() {
const occupancy = getOccupancy();
const searchA = bfs(EXIT_A, occupancy.blocked);
const searchB = bfs(EXIT_B, occupancy.blocked);
const itemStatuses = new Map();
const issues = [...occupancy.overlapIssues];
items.forEach(item => {
const cells = occupancy.map.get(item.id);
const approachA = findApproach(item, cells, searchA);
const approachB = findApproach(item, cells, searchB);
itemStatuses.set(item.id, {
a: Boolean(approachA),
b: Boolean(approachB),
approachA,
approachB
});
if (!approachA) issues.push(`${item.id} is blocked from Exit A.`);
if (!approachB) issues.push(`${item.id} is blocked from Exit B.`);
});
const reachedA = [...itemStatuses.values()].filter(status => status.a).length;
const reachedB = [...itemStatuses.values()].filter(status => status.b).length;
const dual = [...itemStatuses.values()].filter(
status => status.a && status.b
).length;
return {
valid: issues.length === 0,
occupancy,
itemStatuses,
issues,
reachedA,
reachedB,
dual,
searchA,
searchB
};
}
function clearRoutes() {
while (routeGroup.children.length) {
const child = routeGroup.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach(material => material.dispose());
} else {
object.material.dispose();
}
}
});
}
}
function createRouteCylinder(from, to, color) {
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
if (length < 0.001) return;
const geometry = new THREE.CylinderGeometry(0.035, 0.035, length, 7);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.86,
depthWrite: false
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(from).add(to).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
routeGroup.add(mesh);
}
function drawRoute(path, color) {
if (!path || path.length < 2) return;
const points = path.map(index => {
const col = index % COLS;
const row = Math.floor(index / COLS);
return new THREE.Vector3(cellCenter(col), 0.105, cellCenterRow(row));
});
for (let i = 0; i < points.length - 1; i++) {
createRouteCylinder(points[i], points[i + 1], color);
}
const end = points[points.length - 1];
const marker = new THREE.Mesh(
new THREE.RingGeometry(0.22, 0.31, 24),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthWrite: false
})
);
marker.rotation.x = -Math.PI / 2;
marker.position.set(end.x, 0.12, end.z);
routeGroup.add(marker);
}
function updateRoutes() {
clearRoutes();
if (!showRoutes || !latestAudit) return;
const item = items.find(entry => entry.id === selectedId);
if (!item) return;
const status = latestAudit.itemStatuses.get(item.id);
if (!status) return;
if (status.approachA) {
const path = reconstructPath(
latestAudit.searchA,
status.approachA.index
);
drawRoute(path, EXIT_A.color);
}
if (status.approachB) {
const path = reconstructPath(
latestAudit.searchB,
status.approachB.index
);
drawRoute(path, EXIT_B.color);
}
}
function updateSelectionMarkers() {
items.forEach(item => {
const marker = itemMeshes.get(item.id);
const status = latestAudit?.itemStatuses.get(item.id);
const invalid =
!status ||
!status.a ||
!status.b ||
latestAudit.occupancy.overlapIds.has(item.id);
marker.visible = item.id === selectedId;
marker.material.color.setHex(invalid ? 0xd65e58 : 0x168b7b);
marker.material.opacity = invalid ? 0.95 : 0.82;
});
}
function updateUI() {
latestAudit = validateLayout();
const visibleItems = items.filter(
item => activeFilter === "all" || item.type === activeFilter
);
inventoryEl.innerHTML = visibleItems
.map(item => {
const status = latestAudit.itemStatuses.get(item.id);
const issue =
!status.a ||
!status.b ||
latestAudit.occupancy.overlapIds.has(item.id);
return `
<button
class="exhibit-row ${item.id === selectedId ? "selected" : ""}
${issue ? "issue" : ""}"
data-item="${item.id}"
>
<span class="exhibit-icon ${item.type}" style="--swatch:${item.swatch}"></span>
<span class="exhibit-name">
<strong>${item.name}</strong>
<span>${item.id} · ${item.type}</span>
</span>
<span class="route-dots" title="Routes from Exit A and Exit B">
<span class="route-dot ${status.a ? "" : "bad"}"></span>
<span class="route-dot b ${status.b ? "" : "bad"}"></span>
</span>
</button>
`;
})
.join("");
auditHeroEl.classList.toggle("pass", latestAudit.valid);
auditHeroEl.classList.toggle("fail", !latestAudit.valid);
auditBadgeEl.textContent = latestAudit.valid ? "Pass" : "Review";
auditTitleEl.textContent = latestAudit.valid
? "Layout is clear"
: "Access conflict found";
auditCopyEl.textContent = latestAudit.valid
? `${latestAudit.dual} exhibits have a clear approach from both exits.`
: `${latestAudit.issues.length} issue${latestAudit.issues.length === 1 ? "" : "s"} need attention.`;
exitACountEl.innerHTML = `${latestAudit.reachedA} <small>/ ${items.length} reached</small>`;
exitBCountEl.innerHTML = `${latestAudit.reachedB} <small>/ ${items.length} reached</small>`;
if (latestAudit.issues.length === 0) {
issuesEl.innerHTML = `
<div class="all-clear">
<span class="check-icon">✓</span>
<span>No conflicts. Every exhibit has a navigable approach from both exits.</span>
</div>
`;
} else {
issuesEl.innerHTML = latestAudit.issues
.map(issue => `<div class="issue-row"><span class="check-icon">!</span><span>${issue}</span></div>`)
.join("");
}
const selected = items.find(item => item.id === selectedId);
if (selected) {
const status = latestAudit.itemStatuses.get(selected.id);
const routeText = status.a && status.b
? "Dual route confirmed"
: "Route conflict";
selectedCardEl.innerHTML = `
<div class="selected-title">
<span>${selected.name}</span>
<span>${routeText}</span>
</div>
<div class="selected-meta">
<span>${selected.id}</span>
<span>Grid ${selected.col + 1} · ${selected.row + 1}</span>
<span>${selected.rotation * 90}°</span>
</div>
`;
}
updateSelectionMarkers();
updateRoutes();
}
function selectItem(id) {
selectedId = id;
showRoutes = true;
updateUI();
}
function showToast(message) {
toastEl.textContent = message;
toastEl.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toastEl.classList.remove("show"), 2600);
}
function setItemPosition(item, x, z) {
const width = item.type === "screen"
? item.rotation % 2 === 0 ? 3.0 : 0.8
: 1.45;
const depth = item.type === "screen"
? item.rotation % 2 === 0 ? 0.8 : 3.0
: 1.45;
const minX = -WORLD_W / 2 + width / 2 + 0.35;
const maxX = WORLD_W / 2 - width / 2 - 0.35;
const minZ = -WORLD_D / 2 + depth / 2 + 0.4;
const maxZ = WORLD_D / 2 - depth / 2 - 0.4;
const col = THREE.MathUtils.clamp(
Math.round((x - ORIGIN_X) / CELL),
0,
COLS - 1
);
const row = THREE.MathUtils.clamp(
Math.round((z - ORIGIN_Z) / CELL),
0,
ROWS - 1
);
const snappedX = THREE.MathUtils.clamp(cellCenter(col), minX, maxX);
const snappedZ = THREE.MathUtils.clamp(cellCenterRow(row), minZ, maxZ);
item.col = Math.round((snappedX - ORIGIN_X) / CELL);
item.row = Math.round((snappedZ - ORIGIN_Z) / CELL);
syncItemTransform(item);
}
function rotateSelected() {
const item = items.find(entry => entry.id === selectedId);
if (!item) return;
const oldRotation = item.rotation;
item.rotation = (item.rotation + 1) % 4;
syncItemTransform(item);
const audit = validateLayout();
if (protectToggle.checked && !audit.valid) {
item.rotation = oldRotation;
syncItemTransform(item);
updateUI();
showToast("Rotation blocked to preserve dual-exit access.");
return;
}
updateUI();
}
function safeLayout() {
const layout = {
"S-01": [3, 2],
"S-02": [7, 2],
"S-03": [12, 2],
"S-04": [16, 2],
"A-01": [4, 6],
"A-02": [9, 5],
"A-03": [15, 6],
"A-04": [8, 9]
};
items.forEach(item => {
[item.col, item.row] = layout[item.id];
item.rotation = 0;
syncItemTransform(item);
});
showRoutes = true;
updateUI();
showToast("Safe layout applied. All 8 exhibits have routes from both exits.");
}
function resetLayout() {
items = initialItems.map(item => ({ ...item }));
items.forEach(syncItemTransform);
selectedId = "S-02";
showRoutes = true;
updateUI();
showToast("Original gallery plan restored.");
}
inventoryEl.addEventListener("click", event => {
const row = event.target.closest("[data-item]");
if (row) selectItem(row.dataset.item);
});
document.querySelectorAll(".filter-button").forEach(button => {
button.addEventListener("click", () => {
activeFilter = button.dataset.filter;
document.querySelectorAll(".filter-button").forEach(entry => {
entry.classList.toggle("active", entry === button);
});
updateUI();
});
});
protectToggle.addEventListener("change", () => {
if (protectToggle.checked) {
const audit = validateLayout();
if (!audit.valid) {
safeLayout();
showToast("Access protection enabled and the safe layout was restored.");
} else {
showToast("Dual-exit access protection enabled.");
}
}
});
document.querySelectorAll("[data-action]").forEach(button => {
button.addEventListener("click", () => {
const action = button.dataset.action;
if (action === "audit") {
showRoutes = true;
updateUI();
showToast(
latestAudit.valid
? "Audit passed: every exhibit is reachable from Exit A and Exit B."
: "Audit found an access conflict."
);
}
if (action === "arrange") safeLayout();
if (action === "rotate") rotateSelected();
if (action === "reset") resetLayout();
if (action === "camera") resetCamera();
if (action === "zoom-in") cameraState.radius = Math.max(17, cameraState.radius - 3);
if (action === "zoom-out") cameraState.radius = Math.min(54, cameraState.radius + 3);
});
});
const cameraState = {
theta: 0.77,
phi: 0.88,
radius: 36,
target: new THREE.Vector3(0, 0.6, 0)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.77;
cameraState.phi = 0.88;
cameraState.radius = 36;
cameraState.target.set(0, 0.6, 0);
updateCamera();
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const planePoint = new THREE.Vector3();
let dragState = null;
let orbitState = null;
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function findItemFromIntersection(intersections) {
for (const intersection of intersections) {
let object = intersection.object;
while (object) {
if (object.userData.itemId) return object.userData.itemId;
object = object.parent;
}
}
return null;
}
renderer.domElement.addEventListener("pointerdown", event => {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (event.button === 0) {
const intersections = raycaster.intersectObjects(
[...itemGroups.values()],
true
);
const id = findItemFromIntersection(intersections);
if (id) {
selectItem(id);
const item = items.find(entry => entry.id === id);
const group = itemGroups.get(id);
if (raycaster.ray.intersectPlane(dragPlane, planePoint)) {
dragState = {
id,
item,
group,
offsetX: group.position.x - planePoint.x,
offsetZ: group.position.z - planePoint.z,
original: { ...item }
};
}
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
return;
}
}
orbitState = {
x: event.clientX,
y: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (dragState) {
if (raycaster.ray.intersectPlane(dragPlane, planePoint)) {
const x = planePoint.x + dragState.offsetX;
const z = planePoint.z + dragState.offsetZ;
setItemPosition(dragState.item, x, z);
updateUI();
}
return;
}
if (orbitState) {
const dx = event.clientX - orbitState.x;
const dy = event.clientY - orbitState.y;
orbitState.x = event.clientX;
orbitState.y = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.38,
1.22
);
updateCamera();
return;
}
const intersections = raycaster.intersectObjects(
[...itemGroups.values()],
true
);
renderer.domElement.style.cursor =
findItemFromIntersection(intersections) ? "grab" : "default";
});
function finishPointer(event) {
if (dragState) {
const audit = validateLayout();
if (protectToggle.checked && !audit.valid) {
dragState.item.col = dragState.original.col;
dragState.item.row = dragState.original.row;
dragState.item.rotation = dragState.original.rotation;
syncItemTransform(dragState.item);
updateUI();
showToast("Move blocked. Both exit routes must remain clear.");
} else {
updateUI();
showToast(
audit.valid
? `${dragState.id} moved. Dual-exit access is still clear.`
: `${dragState.id} moved with an access warning.`
);
}
dragState = null;
}
orbitState = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "default";
}
renderer.domElement.addEventListener("pointerup", finishPointer);
renderer.domElement.addEventListener("pointercancel", finishPointer);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
17,
54
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLInputElement) return;
if (event.key.toLowerCase() === "r") {
rotateSelected();
}
const item = items.find(entry => entry.id === selectedId);
if (!item) return;
const position = itemWorld(item);
let dx = 0;
let dz = 0;
if (event.key === "ArrowLeft") dx = -CELL;
if (event.key === "ArrowRight") dx = CELL;
if (event.key === "ArrowUp") dz = -CELL;
if (event.key === "ArrowDown") dz = CELL;
if (dx || dz) {
event.preventDefault();
const old = { ...item };
setItemPosition(item, position.x + dx, position.z + dz);
const audit = validateLayout();
if (protectToggle.checked && !audit.valid) {
item.col = old.col;
item.row = old.row;
syncItemTransform(item);
updateUI();
showToast("Nudge blocked to preserve dual-exit access.");
} else {
updateUI();
}
}
if (event.key === "Escape") {
showRoutes = false;
updateRoutes();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateUI();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```