Prompt specification
Build or customize the Three.js 3D scene "Museum visibility layout game" 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: Museum visibility layout game
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/museum-visibility-layout-game-x0192
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly museum room whose exhibit layout can be rearranged. Use several glass cases, solid display plinths, wall-mounted objects, and movable spotlights. Mark a visitor path through the room and allow the cases to slide between a small set of valid positions. Show blocked sightlines from selected visitor viewpoints and use a clearly symbolic glare overlay on designated object faces when a light is badly placed. Users should be able to improve visibility while keeping the walking route connected. Preserve the cases' thickness and reflections so they read as physical enclosures rather than invisible boxes. Include one tall case that hides a smaller exhibit from a chosen viewpoint, creating a concrete placement problem beyond simply keeping the floor clear.
Working Three.js Starter (museum-visibility-layout-game-x0192):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Museum — Visibility Lab</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(22, 28, 34, 0.94);
--panel-2: rgba(38, 47, 55, 0.94);
--line: rgba(255, 255, 255, 0.12);
--text: #edf3f5;
--muted: #a9b5bc;
--cyan: #57d8df;
--green: #70e0a6;
--red: #ff6673;
--amber: #ffc857;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9c6bc;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#title {
position: fixed;
top: 18px;
left: 20px;
z-index: 3;
max-width: 390px;
pointer-events: none;
color: #182027;
text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
#title h1 {
margin: 0;
font-size: clamp(19px, 2.2vw, 30px);
letter-spacing: -.04em;
}
#title p {
margin: 5px 0 0;
font-size: 12px;
font-weight: 700;
letter-spacing: .07em;
text-transform: uppercase;
opacity: .72;
}
#panel {
position: fixed;
z-index: 5;
top: 14px;
right: 14px;
width: min(350px, calc(100vw - 28px));
max-height: calc(100vh - 28px);
overflow: auto;
padding: 15px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0,0,0,.28);
backdrop-filter: blur(14px);
scrollbar-width: thin;
}
#panel h2 {
margin: 0 0 11px;
font-size: 16px;
letter-spacing: -.015em;
}
.section {
padding: 12px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type { border-top: 0; padding-top: 4px; }
.row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 9px 0;
}
label, .label {
font-size: 12px;
font-weight: 700;
color: #dce4e7;
}
select, button {
font: inherit;
}
select {
width: 100%;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--text);
background: #26313a;
font-size: 12px;
outline: none;
}
button {
border: 1px solid var(--line);
border-radius: 8px;
padding: 7px 9px;
background: #2c3943;
color: var(--text);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: background .15s, border-color .15s, transform .15s;
}
button:hover {
background: #394a57;
border-color: rgba(255,255,255,.25);
}
button:active { transform: translateY(1px); }
button.primary {
color: #0e292c;
background: var(--cyan);
border-color: transparent;
}
button.primary:hover { background: #77e5e9; }
.button-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.status {
margin-top: 9px;
padding: 9px 10px;
border-radius: 9px;
background: rgba(0,0,0,.18);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.status strong { color: var(--text); }
.good { color: var(--green) !important; }
.bad { color: var(--red) !important; }
.warn { color: var(--amber) !important; }
#candidateButtons {
display: grid;
gap: 7px;
margin-top: 9px;
}
.candidate {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
text-align: left;
padding: 9px 10px;
}
.candidate small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
.dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 10px currentColor;
}
.dot.bad { background: var(--red); }
.dot.warn { background: var(--amber); }
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
.slider-label {
display: grid;
grid-template-columns: 67px 1fr 44px;
align-items: center;
gap: 7px;
margin: 7px 0;
font-size: 11px;
color: var(--muted);
}
.slider-label output {
text-align: right;
color: var(--text);
font-variant-numeric: tabular-nums;
}
.check {
display: flex;
align-items: center;
gap: 7px;
margin: 7px 0;
font-size: 11px;
color: var(--muted);
}
.check input { accent-color: var(--cyan); }
#legend {
position: fixed;
z-index: 3;
left: 18px;
bottom: 17px;
padding: 10px 12px;
border-radius: 11px;
background: rgba(22,28,34,.86);
box-shadow: 0 8px 30px rgba(0,0,0,.18);
font-size: 10px;
line-height: 1.65;
pointer-events: none;
color: #dbe4e7;
}
.legend-row {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 20px;
height: 4px;
border-radius: 3px;
background: var(--cyan);
}
.swatch.blocked { background: var(--red); }
.swatch.glare { background: var(--amber); }
#toast {
position: fixed;
z-index: 8;
left: 50%;
bottom: 26px;
transform: translate(-50%, 15px);
max-width: min(520px, calc(100vw - 30px));
padding: 10px 15px;
border-radius: 10px;
background: rgba(19,25,30,.94);
border: 1px solid var(--line);
color: var(--text);
font-size: 12px;
box-shadow: 0 8px 30px rgba(0,0,0,.25);
opacity: 0;
pointer-events: none;
transition: opacity .2s, transform .2s;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.help {
margin: 8px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 760px) {
#title { top: 12px; left: 14px; }
#title p { display: none; }
#panel {
top: auto;
bottom: 10px;
right: 10px;
width: min(340px, calc(100vw - 20px));
max-height: 55vh;
}
#legend { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="title">
<h1>Visibility Lab</h1>
<p>Low-poly museum · route-safe exhibit rearrangement</p>
</div>
<aside id="panel">
<h2>Curator Controls</h2>
<div class="section">
<div class="row">
<label for="viewpointSelect">Visitor viewpoint</label>
</div>
<select id="viewpointSelect">
<option value="V1">V1 · Front-right eye</option>
<option value="V2">V2 · Front-left eye</option>
<option value="V3">V3 · Rear-right eye</option>
<option value="V4">V4 · Rear-left eye</option>
</select>
<div id="sightStatus" class="status">Calculating sightlines…</div>
</div>
<div class="section">
<div class="row">
<label for="exhibitSelect">Movable exhibit</label>
</div>
<select id="exhibitSelect">
<option value="tall">Tall archive case</option>
<option value="blue">Blue mineral case</option>
<option value="ceramic">Ceramics case</option>
<option value="amber">Amber relic plinth</option>
<option value="neutral">Neutral sculpture plinth</option>
</select>
<div id="candidateButtons"></div>
<div class="help">
Click a glowing numbered floor pad, or use the buttons. Red pads would
disconnect a required exit or cause an overlap.
</div>
</div>
<div class="section">
<div class="row">
<label for="lightSelect">Movable spotlight</label>
</div>
<select id="lightSelect">
<option value="L1">L1 · Amber key light</option>
<option value="L2">L2 · Wall wash</option>
<option value="L3">L3 · Case accent</option>
</select>
<div class="slider-label">
<span>Floor X</span>
<input id="lightX" type="range" min="-8" max="8" step="0.1">
<output id="lightXOut"></output>
</div>
<div class="slider-label">
<span>Floor Z</span>
<input id="lightZ" type="range" min="-5.8" max="5.8" step="0.1">
<output id="lightZOut"></output>
</div>
<div class="slider-label">
<span>Aim X</span>
<input id="aimX" type="range" min="-8" max="8" step="0.1">
<output id="aimXOut"></output>
</div>
<div class="slider-label">
<span>Aim Z</span>
<input id="aimZ" type="range" min="-6" max="6" step="0.1">
<output id="aimZOut"></output>
</div>
<div class="slider-label">
<span>Power</span>
<input id="lightPower" type="range" min="0" max="140" step="1">
<output id="lightPowerOut"></output>
</div>
<div id="glareStatus" class="status">Checking designated faces…</div>
<div class="help">
A spotlight can also be dragged directly on the floor. Dragging it away
from the visitor–face reflection axis removes the symbolic glare.
</div>
</div>
<div class="section">
<div class="row"><span class="label">Route and analysis</span></div>
<div id="routeStatus" class="status"></div>
<label class="check">
<input id="showSightlines" type="checkbox" checked>
Show selected-viewpoint sightlines
</label>
<label class="check">
<input id="showSlots" type="checkbox" checked>
Show valid placement pads
</label>
<div class="button-row" style="margin-top:10px">
<button id="resetLayout" class="primary">Reset layout</button>
<button id="resetCamera">Reset camera</button>
</div>
</div>
</aside>
<div id="legend">
<div class="legend-row"><span class="swatch"></span> Connected walking route</div>
<div class="legend-row"><span class="swatch blocked"></span> Blocked route edge / blocked sightline</div>
<div class="legend-row"><span class="swatch glare"></span> Symbolic glare on designated face</div>
</div>
<div id="toast"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Core setup
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const panel = document.querySelector("#panel");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9c6bc);
scene.fog = new THREE.Fog(0xc9c6bc, 22, 42);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
43, innerWidth / innerHeight, 0.1, 100
);
const hemisphere = new THREE.HemisphereLight(0xf4f7f2, 0x685e4f, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 2.8);
sun.position.set(-5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.bias = -0.0008;
scene.add(sun);
// A procedural environment gives the glass visible reflections without addons.
function makeEnvironment() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 0, 256);
gradient.addColorStop(0, "#d9eef1");
gradient.addColorStop(0.46, "#f5ead9");
gradient.addColorStop(1, "#535c61");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 512, 256);
ctx.fillStyle = "#ffffff";
ctx.fillRect(48, 28, 34, 118);
ctx.fillStyle = "#fff4c9";
ctx.fillRect(284, 42, 22, 104);
ctx.fillStyle = "#b9e8ec";
ctx.fillRect(388, 24, 60, 88);
const texture = new THREE.CanvasTexture(canvas);
texture.mapping = THREE.EquirectangularReflectionMapping;
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
scene.environment = makeEnvironment();
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xb8b3a7, roughness: 0.88, metalness: 0.02
}),
wall: new THREE.MeshStandardMaterial({
color: 0xe2ded2, roughness: 0.82, metalness: 0
}),
wallTrim: new THREE.MeshStandardMaterial({
color: 0x39464d, roughness: 0.45, metalness: 0.35
}),
plinth: new THREE.MeshStandardMaterial({
color: 0xe5dfd2, roughness: 0.68, metalness: 0.02
}),
plinthDark: new THREE.MeshStandardMaterial({
color: 0x3a464d, roughness: 0.42, metalness: 0.22
}),
frame: new THREE.MeshStandardMaterial({
color: 0x36454d, roughness: 0.22, metalness: 0.78
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0xb9e2e8,
transparent: true,
opacity: 0.38,
transmission: 0.2,
thickness: 0.065,
roughness: 0.07,
metalness: 0.05,
clearcoat: 1,
clearcoatRoughness: 0.08,
envMapIntensity: 1.8,
side: THREE.DoubleSide,
depthWrite: false
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffad28,
emissive: 0x6b2e00,
emissiveIntensity: 0.22,
roughness: 0.18,
metalness: 0.48,
flatShading: true
}),
blue: new THREE.MeshStandardMaterial({
color: 0x3d8fc2,
roughness: 0.34,
metalness: 0.2,
flatShading: true
}),
ceramic: new THREE.MeshStandardMaterial({
color: 0xd56a58,
roughness: 0.5,
metalness: 0.04,
flatShading: true
}),
baffle: new THREE.MeshStandardMaterial({
color: 0x34464e,
roughness: 0.5,
metalness: 0.2,
flatShading: true
})
};
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = !material.transparent;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, color = "#dce8ea", background = "rgba(26,33,38,.84)") {
const canvas = document.createElement("canvas");
canvas.width = 384;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 4, 376, 88, 18);
ctx.fill();
ctx.strokeStyle = "rgba(255,255,255,.22)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "700 32px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 192, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
sprite.scale.set(2.1, 0.525, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Room
// -------------------------------------------------------------------------
const floor = box(18, 0.22, 13.2, materials.floor, 0, -0.11, 0);
floor.receiveShadow = true;
box(18.2, 5.4, 0.32, materials.wall, 0, 2.6, -6.65);
box(0.32, 5.4, 13.2, materials.wall, -9.05, 2.6, 0);
box(0.32, 0.9, 13.2, materials.wall, 9.05, 0.35, 0);
// Low front walls leave the room open to the camera.
box(3.1, 0.55, 0.3, materials.wall, -7.45, 0.17, 6.55);
box(3.1, 0.55, 0.3, materials.wall, 7.45, 0.17, 6.55);
box(3.0, 0.55, 0.3, materials.wall, -3.0, 0.17, 6.55);
box(3.0, 0.55, 0.3, materials.wall, 3.0, 0.17, 6.55);
box(18.0, 0.12, 0.08, materials.wallTrim, 0, 0.06, -6.43);
box(0.08, 0.12, 13.0, materials.wallTrim, -8.84, 0.06, 0);
box(0.08, 0.12, 13.0, materials.wallTrim, 8.84, 0.06, 0);
const tilePositions = [];
for (let x = -9; x <= 9; x += 1.5) {
tilePositions.push(x, 0.012, -6.4, x, 0.012, 6.4);
}
for (let z = -6; z <= 6; z += 1.5) {
tilePositions.push(-8.8, 0.012, z, 8.8, 0.012, z);
}
const tileGeometry = new THREE.BufferGeometry();
tileGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tilePositions, 3)
);
scene.add(new THREE.LineSegments(
tileGeometry,
new THREE.LineBasicMaterial({
color: 0x8e8a81, transparent: true, opacity: 0.28
})
));
const galleryTitle = makeLabel("GALLERY 04", "#e7f4f4");
galleryTitle.position.set(0, 4.65, -6.34);
galleryTitle.scale.set(3.2, 0.8, 1);
scene.add(galleryTitle);
// -------------------------------------------------------------------------
// Walkable route graph
// -------------------------------------------------------------------------
const routeNodes = [
{ name: "ENTRY", p: new THREE.Vector2(-8, 6) },
{ name: "J1", p: new THREE.Vector2(-4, 6) },
{ name: "J2", p: new THREE.Vector2(-4, 2) },
{ name: "J3", p: new THREE.Vector2( 0, 2) },
{ name: "J4", p: new THREE.Vector2( 4, 2) },
{ name: "J5", p: new THREE.Vector2( 8, 2) },
{ name: "EXIT A", p: new THREE.Vector2( 8, 6) },
{ name: "REAR LEFT", p: new THREE.Vector2(-8,-2) },
{ name: "REAR MID", p: new THREE.Vector2( 0,-2) },
{ name: "REAR RIGHT",p: new THREE.Vector2( 8,-2) },
{ name: "EXIT B", p: new THREE.Vector2( 0,-6) }
];
const routeEdges = [
[0,1], [1,2], [2,3], [3,4], [4,5], [5,6],
[0,7], [2,7], [7,8], [8,9], [9,5],
[2,8], [4,8], [8,10]
];
const routeGroup = new THREE.Group();
scene.add(routeGroup);
routeEdges.forEach(([a,b], index) => {
const start = routeNodes[a].p;
const end = routeNodes[b].p;
const delta = end.clone().sub(start);
const length = delta.length();
const angle = -Math.atan2(delta.y, delta.x);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const stripMaterial = new THREE.MeshBasicMaterial({
color: 0x42cbd3,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
});
const strip = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.018, 0.48),
stripMaterial
);
strip.position.set(midpoint.x, 0.03, midpoint.y);
strip.rotation.y = angle;
strip.renderOrder = 1;
routeGroup.add(strip);
const lineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(start.x, 0.045, start.y),
new THREE.Vector3(end.x, 0.045, end.y)
]);
const line = new THREE.Line(
lineGeometry,
new THREE.LineDashedMaterial({
color: 0xcfffff,
dashSize: 0.22,
gapSize: 0.13,
transparent: true,
opacity: 0.7
})
);
line.computeLineDistances();
routeGroup.add(line);
routeEdges[index].visual = { strip, line };
});
[0,6,10].forEach((index, i) => {
const label = makeLabel(
routeNodes[index].name,
i === 0 ? "#77e5e9" : "#a7f0bc",
"rgba(22,29,34,.9)"
);
label.position.set(
routeNodes[index].p.x,
0.62,
routeNodes[index].p.y
);
label.scale.set(1.9, 0.48, 1);
scene.add(label);
});
// -------------------------------------------------------------------------
// Exhibit helpers and shared state
// -------------------------------------------------------------------------
const blockers = [];
const pickables = [];
const movableExhibits = [];
const slotRecords = [];
const slotMeshes = [];
const glareFaces = [];
const viewpointMeshes = [];
function addBlocker(mesh, ownerId) {
mesh.userData.ownerId = ownerId;
blockers.push(mesh);
return mesh;
}
function addSelectionOutline(group, width, depth) {
const geometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(width + 0.14, 0.04, depth + 0.14)
);
const outline = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color: 0x60e5e7,
transparent: true,
opacity: 0.95
})
);
outline.position.y = 0.04;
outline.visible = false;
group.add(outline);
return outline;
}
function createCase(config) {
const group = new THREE.Group();
group.position.set(config.pos.x, 0, config.pos.y);
const base = addBlocker(
box(
config.width, config.baseHeight, config.depth,
config.dark ? materials.plinthDark : materials.plinth,
0, config.baseHeight / 2, 0, group
),
config.id
);
base.userData.blockerType = "case-base";
const glassHeight = config.height - config.baseHeight;
const glassY = config.baseHeight + glassHeight / 2;
const front = box(
config.width, glassHeight, 0.065, materials.glass,
0, glassY, config.depth / 2, group
);
const back = box(
config.width, glassHeight, 0.065, materials.glass,
0, glassY, -config.depth / 2, group
);
const left = box(
0.065, glassHeight, config.depth, materials.glass,
-config.width / 2, glassY, 0, group
);
const right = box(
0.065, glassHeight, config.depth, materials.glass,
config.width / 2, glassY, 0, group
);
const top = box(
config.width, 0.065, config.depth, materials.glass,
0, config.height, 0, group
);
[front, back, left, right, top].forEach(mesh => {
mesh.castShadow = false;
mesh.receiveShadow = true;
mesh.renderOrder = 3;
});
// Thin metal frames make the enclosure's physical thickness legible.
for (const x of [-config.width / 2, config.width / 2]) {
for (const z of [-config.depth / 2, config.depth / 2]) {
box(
0.045, glassHeight, 0.045, materials.frame,
x, glassY, z, group
);
}
}
for (const z of [-config.depth / 2, config.depth / 2]) {
box(
config.width, 0.045, 0.045, materials.frame,
0, config.height, z, group
);
box(
config.width, 0.045, 0.045, materials.frame,
0, config.baseHeight + 0.025, z, group
);
}
for (const x of [-config.width / 2, config.width / 2]) {
box(
0.045, 0.045, config.depth, materials.frame,
x, config.height, 0, group
);
}
box(
config.width - 0.16, 0.08, config.depth - 0.16,
materials.plinthDark, 0, config.baseHeight + 0.04, 0, group
);
if (config.id === "tall") {
// An opaque archive tower inside the tall enclosure is the concrete
// sightline blocker. The surrounding enclosure still reads as glass.
addBlocker(
box(
1.42, 2.12, 0.56, materials.baffle,
0, 1.78, 0, group
),
config.id
);
const strip = box(
0.12, 1.72, 0.59, materials.blue,
-0.38, 1.75, 0.015, group
);
strip.castShadow = false;
}
if (config.id === "blue") {
for (let i = 0; i < 5; i++) {
const crystal = new THREE.Mesh(
new THREE.OctahedronGeometry(0.28 + i * 0.025, 0),
materials.blue
);
crystal.position.set(
(i - 2) * 0.25,
0.95 + (i % 2) * 0.18,
(i % 2 ? 0.13 : -0.08)
);
crystal.rotation.set(0.2 * i, 0.65 * i, -0.15 * i);
crystal.castShadow = true;
group.add(crystal);
}
}
if (config.id === "ceramic") {
const vase = new THREE.Mesh(
new THREE.CylinderGeometry(0.24, 0.42, 1.18, 7),
materials.ceramic
);
vase.position.y = 1.1;
vase.castShadow = true;
group.add(vase);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.25, 0.055, 5, 12),
materials.plinthDark
);
rim.position.y = 1.69;
rim.rotation.x = Math.PI / 2;
group.add(rim);
}
const outline = addSelectionOutline(
group, config.width, config.depth
);
group.userData.exhibitId = config.id;
group.traverse(child => {
if (child.isMesh) child.userData.exhibitId = config.id;
});
scene.add(group);
pickables.push(group);
const record = {
id: config.id,
name: config.name,
short: config.short,
group,
pos: new THREE.Vector2(config.pos.x, config.pos.y),
targetPos: new THREE.Vector2(config.pos.x, config.pos.y),
width: config.width,
depth: config.depth,
slots: [],
slotIndex: 0,
outline
};
movableExhibits.push(record);
return record;
}
function createPlinth(config) {
const group = new THREE.Group();
group.position.set(config.pos.x, 0, config.pos.y);
addBlocker(
box(
config.width, config.height, config.depth,
materials.plinth, 0, config.height / 2, 0, group
),
config.id
);
box(
config.width + 0.08, 0.08, config.depth + 0.08,
materials.plinthDark, 0, config.height + 0.035, 0, group
);
const outline = addSelectionOutline(
group, config.width, config.depth
);
group.userData.exhibitId = config.id;
group.traverse(child => {
if (child.isMesh) child.userData.exhibitId = config.id;
});
scene.add(group);
pickables.push(group);
const record = {
id: config.id,
name: config.name,
short: config.short,
group,
pos: new THREE.Vector2(config.pos.x, config.pos.y),
targetPos: new THREE.Vector2(config.pos.x, config.pos.y),
width: config.width,
depth: config.depth,
slots: [],
slotIndex: 0,
outline
};
movableExhibits.push(record);
return record;
}
const tallExhibit = createCase({
id: "tall",
name: "Tall archive case",
short: "T",
pos: new THREE.Vector2(4.8, 1.25),
width: 2.2,
depth: 1.4,
baseHeight: 0.65,
height: 3.38,
dark: true
});
const blueExhibit = createCase({
id: "blue",
name: "Blue mineral case",
short: "B",
pos: new THREE.Vector2(-6.7, 0.5),
width: 2.0,
depth: 1.2,
baseHeight: 0.52,
height: 2.42
});
const ceramicExhibit = createCase({
id: "ceramic",
name: "Ceramics case",
short: "C",
pos: new THREE.Vector2(2.7, 0.3),
width: 1.8,
depth: 1.2,
baseHeight: 0.52,
height: 2.34
});
const amberExhibit = createPlinth({
id: "amber",
name: "Amber relic plinth",
short: "A",
pos: new THREE.Vector2(4.7, -3.6),
width: 1.4,
depth: 1.3,
height: 0.76
});
const neutralExhibit = createPlinth({
id: "neutral",
name: "Neutral sculpture plinth",
short: "N",
pos: new THREE.Vector2(-7.8, 3.5),
width: 1.3,
depth: 1.3,
height: 0.76
});
const amberGem = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.43, 0),
materials.amber
);
amberGem.position.y = 1.22;
amberGem.rotation.set(0.15, 0.45, -0.1);
amberGem.castShadow = true;
amberExhibit.group.add(amberGem);
const neutralSculpture = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.52, 0),
new THREE.MeshStandardMaterial({
color: 0x9a9183,
roughness: 0.7,
flatShading: true
})
);
neutralSculpture.position.y = 1.25;
neutralSculpture.scale.set(0.75, 1.25, 0.75);
neutralSculpture.castShadow = true;
neutralExhibit.group.add(neutralSculpture);
// -------------------------------------------------------------------------
// Wall-mounted exhibits
// -------------------------------------------------------------------------
function createWallRelief(x, color, title) {
const group = new THREE.Group();
group.position.set(x, 2.55, -6.36);
box(
2.05, 1.62, 0.16, materials.plinthDark,
0, 0, 0, group
);
const faceMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.5,
metalness: 0.12,
flatShading: true
});
const relief = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.55, 0),
faceMaterial
);
relief.scale.set(1.15, 0.8, 0.23);
relief.position.set(-0.33, 0.08, 0.14);
relief.castShadow = true;
group.add(relief);
for (let i = 0; i < 4; i++) {
const bar = box(
0.12, 0.8 - i * 0.12, 0.11, faceMaterial,
0.2 + i * 0.19, -0.03, 0.17, group
);
bar.rotation.z = -0.25;
}
const label = makeLabel(title, "#eaf4f4");
label.position.set(x, 1.12, -6.25);
label.scale.set(1.8, 0.45, 1);
scene.add(label);
scene.add(group);
return group;
}
const wallRelief = createWallRelief(-4.5, 0xb44755, "RELIEF 01");
const wallReliefTwo = createWallRelief(4.7, 0x4f7fa4, "RELIEF 02");
// -------------------------------------------------------------------------
// Symbolic glare overlays
// -------------------------------------------------------------------------
function makeHatchTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 128, 128);
ctx.fillStyle = "rgba(255, 190, 35, .24)";
ctx.fillRect(0, 0, 128, 128);
ctx.strokeStyle = "rgba(255, 231, 121, .98)";
ctx.lineWidth = 13;
for (let x = -128; x < 256; x += 31) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x - 128, 128);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.5, 1.5);
return texture;
}
const hatchTexture = makeHatchTexture();
function addGlareFace(anchor, centerLocal, normalLocal, width, height, name) {
const material = new THREE.MeshBasicMaterial({
map: hatchTexture,
color: 0xffd35c,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -2
});
const overlay = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
overlay.position.copy(centerLocal);
overlay.renderOrder = 10;
anchor.add(overlay);
glareFaces.push({
anchor,
centerLocal: centerLocal.clone(),
normalLocal: normalLocal.clone(),
overlay,
material,
name
});
}
addGlareFace(
amberExhibit.group,
new THREE.Vector3(0, 1.22, 0.435),
new THREE.Vector3(0, 0, 1),
0.62, 0.52,
"Amber relic front face"
);
addGlareFace(
wallRelief,
new THREE.Vector3(-0.34, 0.08, 0.365),
new THREE.Vector3(0, 0, 1),
0.92, 0.72,
"Relief 01 designated face"
);
// -------------------------------------------------------------------------
// Placement pads
// -------------------------------------------------------------------------
const slotDefinitions = {
tall: [
{ name: "Front sightline", p: new THREE.Vector2(4.8, 1.25) },
{ name: "Rear-right bay", p: new THREE.Vector2(7.8, -4.8) },
{ name: "Rear-left bay", p: new THREE.Vector2(-2.4, -4.8) }
],
blue: [
{ name: "Left gallery", p: new THREE.Vector2(-6.7, 0.5) },
{ name: "Center-left bay", p: new THREE.Vector2(-1.8, 0.1) },
{ name: "Rear-left bay", p: new THREE.Vector2(-7.2, -4.8) }
],
ceramic: [
{ name: "Center-right bay", p: new THREE.Vector2(2.7, 0.3) },
{ name: "Front-right bay", p: new THREE.Vector2(7.9, 0.3) },
{ name: "Rear-center bay", p: new THREE.Vector2(0.5, -4.8) }
],
amber: [
{ name: "Original plinth", p: new THREE.Vector2(4.7, -3.6) },
{ name: "Rear-right plinth", p: new THREE.Vector2(6.7, -5.1) },
{ name: "Rear-left plinth", p: new THREE.Vector2(-3.5, -4.9) }
],
neutral: [
{ name: "Front-left plinth", p: new THREE.Vector2(-7.8, 3.5) },
{ name: "Rear-center plinth", p: new THREE.Vector2(2.4, -4.9) },
{ name: "Front-right plinth", p: new THREE.Vector2(8.0, 4.8) }
]
};
movableExhibits.forEach(exhibit => {
slotDefinitions[exhibit.id].forEach((slot, index) => {
const marker = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.035, 6, 24),
new THREE.MeshBasicMaterial({
color: 0x57d8df,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
marker.rotation.x = Math.PI / 2;
marker.position.set(slot.p.x, 0.065, slot.p.y);
marker.renderOrder = 8;
const code = `${exhibit.short}${index + 1}`;
const label = makeLabel(code, "#d8ffff");
label.position.set(slot.p.x, 0.34, slot.p.y);
label.scale.set(0.72, 0.18, 1);
label.visible = false;
const record = {
exhibit,
index,
code,
name: slot.name,
pos: slot.p.clone(),
marker,
label
};
marker.userData.slotRecord = record;
marker.userData.pickType = "slot";
scene.add(marker, label);
slotMeshes.push(marker);
slotRecords.push(record);
exhibit.slots.push(record);
});
});
// -------------------------------------------------------------------------
// Visitor viewpoints
// -------------------------------------------------------------------------
const viewpoints = {
V1: { name: "Front-right eye", pos: new THREE.Vector3(4.8, 1.65, 4.8) },
V2: { name: "Front-left eye", pos: new THREE.Vector3(-6.8, 1.65, 4.7) },
V3: { name: "Rear-right eye", pos: new THREE.Vector3(7.8, 1.65, -4.8) },
V4: { name: "Rear-left eye", pos: new THREE.Vector3(-7.4, 1.65, -4.8) }
};
let selectedViewpoint = "V1";
Object.entries(viewpoints).forEach(([id, data]) => {
const group = new THREE.Group();
group.position.set(data.pos.x, 0, data.pos.z);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.36, 0.035, 6, 20),
new THREE.MeshBasicMaterial({ color: 0x94f2e7 })
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.05;
group.add(ring);
const eye = new THREE.Mesh(
new THREE.OctahedronGeometry(0.19, 0),
new THREE.MeshStandardMaterial({
color: 0x8de9df,
emissive: 0x185d5d,
emissiveIntensity: 0.65,
roughness: 0.3
})
);
eye.position.y = 1.65;
group.add(eye);
const label = makeLabel(id, "#b9fff8");
label.position.set(0, 2.14, 0);
label.scale.set(0.75, 0.19, 1);
group.add(label);
group.userData.viewpointId = id;
group.traverse(child => {
if (child.isMesh) child.userData.viewpointId = id;
});
scene.add(group);
viewpointMeshes.push(group);
data.group = group;
data.ring = ring;
});
// -------------------------------------------------------------------------
// Movable spotlights
// -------------------------------------------------------------------------
const spotlights = {};
function createSpotlight(id, name, pos, aim, power, color) {
const light = new THREE.SpotLight(
color, power, 19, 0.39, 0.55, 1.4
);
light.castShadow = id === "L1";
if (light.shadow) {
light.shadow.mapSize.set(1024, 1024);
light.shadow.bias = -0.001;
}
const target = new THREE.Object3D();
target.position.set(aim.x, 1.15, aim.y);
scene.add(target);
light.target = target;
scene.add(light);
const fixture = new THREE.Group();
fixture.position.set(pos.x, 0, pos.y);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.33, 0.42, 0.12, 8),
materials.plinthDark
);
base.position.y = 0.06;
base.castShadow = true;
fixture.add(base);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 3.75, 8),
materials.frame
);
pole.position.y = 1.95;
pole.castShadow = true;
fixture.add(pole);
const head = new THREE.Group();
head.position.y = 3.95;
fixture.add(head);
const housing = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.29, 0.52, 10),
materials.plinthDark
);
housing.rotation.x = Math.PI / 2;
housing.castShadow = true;
head.add(housing);
const lens = new THREE.Mesh(
new THREE.CircleGeometry(0.205, 20),
new THREE.MeshBasicMaterial({ color: 0xffedb0 })
);
lens.position.z = 0.27;
head.add(lens);
fixture.userData.lightId = id;
fixture.traverse(child => {
if (child.isMesh) child.userData.lightId = id;
});
scene.add(fixture);
pickables.push(fixture);
const beamGeometry = new THREE.ConeGeometry(0.55, 1, 24, 1, true);
beamGeometry.translate(0, -0.5, 0);
const beam = new THREE.Mesh(
beamGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.032,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending
})
);
beam.renderOrder = 1;
scene.add(beam);
const record = {
id, name, fixture, head, light, target, beam,
pos: new THREE.Vector2(pos.x, pos.y),
aim: new THREE.Vector2(aim.x, aim.y),
power
};
spotlights[id] = record;
return record;
}
createSpotlight(
"L1", "Amber key light",
new THREE.Vector2(4.8, -0.1),
new THREE.Vector2(4.7, -3.6),
92, 0xffd88c
);
createSpotlight(
"L2", "Wall wash",
new THREE.Vector2(-6.0, 4.8),
new THREE.Vector2(-4.5, -6.25),
76, 0xd6edff
);
createSpotlight(
"L3", "Case accent",
new THREE.Vector2(1.5, 3.6),
new THREE.Vector2(2.7, 0.3),
58, 0xf5d9ff
);
let selectedLight = "L1";
function updateSpotlight(record) {
record.light.position.set(record.pos.x, 4.05, record.pos.y);
record.light.intensity = record.power;
record.target.position.set(record.aim.x, 1.15, record.aim.y);
record.fixture.position.set(record.pos.x, 0, record.pos.y);
record.head.lookAt(record.target.position);
const start = record.light.position;
const end = record.target.position;
const direction = end.clone().sub(start);
const length = direction.length();
direction.normalize();
record.beam.position.copy(start);
record.beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, -1, 0),
direction
);
const desiredRadius = Math.tan(record.light.angle) * length;
record.beam.scale.set(
desiredRadius / 0.55,
length,
desiredRadius / 0.55
);
record.beam.material.opacity = record.power > 2 ? 0.032 : 0;
}
Object.values(spotlights).forEach(updateSpotlight);
// -------------------------------------------------------------------------
// Route geometry, overlap and connectivity validation
// -------------------------------------------------------------------------
function footprintRect(exhibit, position = exhibit.pos) {
return new THREE.Box2(
new THREE.Vector2(
position.x - exhibit.width / 2,
position.y - exhibit.depth / 2
),
new THREE.Vector2(
position.x + exhibit.width / 2,
position.y + exhibit.depth / 2
)
);
}
function overlaps(a, b, margin = 0.04) {
return (
a.min.x < b.max.x - margin &&
a.max.x > b.min.x + margin &&
a.min.y < b.max.y - margin &&
a.max.y > b.min.y + margin
);
}
function segmentIntersectsRect(a, b, rect) {
let t0 = 0;
let t1 = 1;
const dx = b.x - a.x;
const dz = b.y - a.y;
const axes = [
[a.x, dx, rect.min.x, rect.max.x],
[a.y, dz, rect.min.y, rect.max.y]
];
for (const [origin, delta, min, max] of axes) {
if (Math.abs(delta) < 1e-8) {
if (origin < min || origin > max) return false;
} else {
let near = (min - origin) / delta;
let far = (max - origin) / delta;
if (near > far) [near, far] = [far, near];
t0 = Math.max(t0, near);
t1 = Math.min(t1, far);
if (t0 > t1) return false;
}
}
return true;
}
function computeRouteState(override = null) {
const positions = new Map(
movableExhibits.map(exhibit => [exhibit.id, exhibit.pos])
);
if (override) positions.set(override.exhibit.id, override.pos);
const blocked = routeEdges.map(([a,b]) => {
const start = routeNodes[a].p;
const end = routeNodes[b].p;
return movableExhibits.some(exhibit => {
const rect = footprintRect(exhibit, positions.get(exhibit.id));
rect.expandByScalar(0.22);
return segmentIntersectsRect(start, end, rect);
});
});
const adjacency = routeEdges.map(() => []);
routeEdges.forEach(([a,b], index) => {
if (!blocked[index]) {
adjacency[a].push(b);
adjacency[b].push(a);
}
});
function reachable(start) {
const seen = new Set([start]);
const queue = [start];
while (queue.length) {
const current = queue.shift();
for (const next of adjacency[current]) {
if (!seen.has(next)) {
seen.add(next);
queue.push(next);
}
}
}
return seen;
}
const fromEntry = reachable(0);
const exitA = fromEntry.has(6);
const exitB = fromEntry.has(10);
return {
blocked,
exitA,
exitB,
connected: exitA && exitB,
reachable: fromEntry
};
}
function evaluateCandidate(exhibit, slot) {
const ownRect = footprintRect(exhibit, slot.pos);
const collision = movableExhibits.some(other => {
if (other === exhibit) return false;
return overlaps(ownRect, footprintRect(other));
});
const route = computeRouteState({
exhibit,
pos: slot.pos
});
let reason = "Route remains connected";
let valid = true;
if (collision) {
valid = false;
reason = "Would overlap another exhibit";
} else if (!route.connected) {
valid = false;
reason = `Would disconnect ${!route.exitA ? "Exit A" : "Exit B"}`;
}
return { valid, reason, route };
}
function updateRouteVisuals(state) {
routeEdges.forEach((edge, index) => {
const blocked = state.blocked[index];
const reachable = state.reachable.has(routeEdges[index][0]) &&
state.reachable.has(routeEdges[index][1]);
edge.visual.strip.material.color.setHex(
blocked ? 0xff5265 : (reachable ? 0x42cbd3 : 0x789197)
);
edge.visual.strip.material.opacity = blocked ? 0.18 : 0.2;
edge.visual.line.material.color.setHex(
blocked ? 0xff6673 : 0xcfffff
);
edge.visual.line.material.opacity = blocked ? 0.9 : 0.65;
});
const routeStatus = document.querySelector("#routeStatus");
routeStatus.className = "status " + (state.connected ? "good" : "bad");
routeStatus.innerHTML = state.connected
? `<strong>Route connected.</strong> Both required exits are reachable from the entry.`
: `<strong>Route disconnected.</strong> At least one required exit cannot be reached.`;
const hint = document.querySelector("#hint");
if (hint) {
hint.textContent = state.connected
? "Try moving the tall archive case to a rear bay, then shift the amber key light sideways."
: "Move an exhibit off a red route edge to reconnect the required exits.";
}
}
// -------------------------------------------------------------------------
// UI and selection
// -------------------------------------------------------------------------
const exhibitSelect = document.querySelector("#exhibitSelect");
const candidateButtons = document.querySelector("#candidateButtons");
const viewpointSelect = document.querySelector("#viewpointSelect");
const lightSelect = document.querySelector("#lightSelect");
const showSlots = document.querySelector("#showSlots");
const showSightlines = document.querySelector("#showSightlines");
let selectedExhibit = tallExhibit;
function selectExhibit(exhibit) {
selectedExhibit = exhibit;
exhibitSelect.value = exhibit.id;
movableExhibits.forEach(item => {
item.outline.visible = item === exhibit;
});
renderCandidates();
updateSlotVisibility();
analysisDirty = true;
}
function renderCandidates() {
candidateButtons.innerHTML = "";
selectedExhibit.slots.forEach(slot => {
const evaluation = evaluateCandidate(selectedExhibit, slot);
const active = selectedExhibit.slotIndex === slot.index;
const button = document.createElement("button");
button.className = "candidate";
button.innerHTML = `
<span>
${slot.code} · ${slot.name}
<small>${active ? "Current position · " : ""}${evaluation.reason}</small>
</span>
<span class="dot ${evaluation.valid ? "" : "bad"}"></span>
`;
button.addEventListener("click", () => moveExhibit(slot));
candidateButtons.appendChild(button);
slot.evaluation = evaluation;
slot.marker.material.color.setHex(
evaluation.valid ? 0x57d8df : 0xff6673
);
slot.marker.material.opacity = active ? 1 : 0.78;
slot.marker.scale.setScalar(active ? 1.18 : 1);
});
updateSlotVisibility();
}
function updateSlotVisibility() {
slotRecords.forEach(slot => {
const visible = showSlots.checked && slot.exhibit === selectedExhibit;
slot.marker.visible = visible;
slot.label.visible = visible;
});
}
let toastTimer;
function toast(message) {
const element = document.querySelector("#toast");
element.textContent = message;
element.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => element.classList.remove("show"), 2600);
}
function moveExhibit(slot) {
const evaluation = evaluateCandidate(selectedExhibit, slot);
if (!evaluation.valid) {
toast(`${slot.code} rejected: ${evaluation.reason}.`);
return;
}
selectedExhibit.slotIndex = slot.index;
selectedExhibit.pos.copy(slot.pos);
selectedExhibit.targetPos.copy(slot.pos);
const route = computeRouteState();
updateRouteVisuals(route);
renderCandidates();
analysisDirty = true;
toast(`${selectedExhibit.name} slid to ${slot.name}. The walking route remains connected.`);
}
exhibitSelect.addEventListener("change", () => {
const exhibit = movableExhibits.find(item => item.id === exhibitSelect.value);
selectExhibit(exhibit);
});
viewpointSelect.addEventListener("change", () => {
selectedViewpoint = viewpointSelect.value;
Object.values(viewpoints).forEach(data => {
data.ring.material.color.setHex(
data === viewpoints[selectedViewpoint] ? 0xffffff : 0x65cbc7
);
});
analysisDirty = true;
});
showSlots.addEventListener("change", updateSlotVisibility);
showSightlines.addEventListener("change", () => {
analysisDirty = true;
});
// -------------------------------------------------------------------------
// Spotlight controls
// -------------------------------------------------------------------------
const lightInputs = {
x: document.querySelector("#lightX"),
z: document.querySelector("#lightZ"),
aimX: document.querySelector("#aimX"),
aimZ: document.querySelector("#aimZ"),
power: document.querySelector("#lightPower")
};
const lightOutputs = {
x: document.querySelector("#lightXOut"),
z: document.querySelector("#lightZOut"),
aimX: document.querySelector("#aimXOut"),
aimZ: document.querySelector("#aimZOut"),
power: document.querySelector("#lightPowerOut")
};
function updateLightUI() {
const spot = spotlights[selectedLight];
lightInputs.x.value = spot.pos.x;
lightInputs.z.value = spot.pos.y;
lightInputs.aimX.value = spot.aim.x;
lightInputs.aimZ.value = spot.aim.y;
lightInputs.power.value = spot.power;
lightOutputs.x.value = spot.pos.x.toFixed(1);
lightOutputs.z.value = spot.pos.y.toFixed(1);
lightOutputs.aimX.value = spot.aim.x.toFixed(1);
lightOutputs.aimZ.value = spot.aim.y.toFixed(1);
lightOutputs.power.value = String(Math.round(spot.power));
}
function selectLight(id) {
selectedLight = id;
lightSelect.value = id;
updateLightUI();
analysisDirty = true;
}
lightSelect.addEventListener("change", () => selectLight(lightSelect.value));
lightInputs.x.addEventListener("input", () => {
spotlights[selectedLight].pos.x = Number(lightInputs.x.value);
updateSpotlight(spotlights[selectedLight]);
updateLightUI();
analysisDirty = true;
});
lightInputs.z.addEventListener("input", () => {
spotlights[selectedLight].pos.y = Number(lightInputs.z.value);
updateSpotlight(spotlights[selectedLight]);
updateLightUI();
analysisDirty = true;
});
lightInputs.aimX.addEventListener("input", () => {
spotlights[selectedLight].aim.x = Number(lightInputs.aimX.value);
updateSpotlight(spotlights[selectedLight]);
updateLightUI();
analysisDirty = true;
});
lightInputs.aimZ.addEventListener("input", () => {
spotlights[selectedLight].aim.y = Number(lightInputs.aimZ.value);
updateSpotlight(spotlights[selectedLight]);
updateLightUI();
analysisDirty = true;
});
lightInputs.power.addEventListener("input", () => {
spotlights[selectedLight].power = Number(lightInputs.power.value);
updateSpotlight(spotlights[selectedLight]);
updateLightUI();
analysisDirty = true;
});
// -------------------------------------------------------------------------
// Sightline and glare analysis
// -------------------------------------------------------------------------
const sightGroup = new THREE.Group();
scene.add(sightGroup);
const raycaster = new THREE.Raycaster();
const analysisInfo = {
blocked: [],
glare: []
};
function getAnalysisTargets() {
const amber = amberExhibit.group.localToWorld(
new THREE.Vector3(0, 1.22, 0)
);
const blue = blueExhibit.group.localToWorld(
new THREE.Vector3(0, 1.18, 0)
);
const wall = wallRelief.localToWorld(new THREE.Vector3(0, 0, 0));
return [
{ name: "Amber relic", point: amber, ownerId: "amber" },
{ name: "Blue mineral", point: blue, ownerId: "blue" },
{ name: "Wall relief", point: wall, ownerId: "wall" }
];
}
function clearSightGroup() {
while (sightGroup.children.length) {
const child = sightGroup.children.pop();
child.geometry?.dispose();
child.material?.dispose();
}
}
function updateSightlines() {
scene.updateMatrixWorld(true);
clearSightGroup();
const eye = viewpoints[selectedViewpoint].pos;
let blockedCount = 0;
const blockedNames = [];
for (const target of getAnalysisTargets()) {
const direction = target.point.clone().sub(eye);
const distance = direction.length();
direction.normalize();
raycaster.set(eye, direction);
raycaster.near = 0.05;
raycaster.far = distance - 0.08;
const intersections = raycaster.intersectObjects(blockers, false);
let hit = null;
for (const intersection of intersections) {
if (intersection.object.userData.ownerId === target.ownerId) continue;
hit = intersection;
break;
}
const geometry = new THREE.BufferGeometry().setFromPoints([
eye,
target.point
]);
if (hit) {
blockedCount++;
blockedNames.push(target.name);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color: 0xff596a,
dashSize: 0.18,
gapSize: 0.1,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
line.computeLineDistances();
line.renderOrder = 12;
sightGroup.add(line);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 10, 8),
new THREE.MeshBasicMaterial({
color: 0xff596a,
depthTest: false,
transparent: true,
opacity: 0.95
})
);
marker.position.copy(hit.point);
marker.renderOrder = 13;
sightGroup.add(marker);
} else {
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x70e0a6,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
line.renderOrder = 12;
sightGroup.add(line);
}
}
sightGroup.visible = showSightlines.checked;
analysisInfo.blocked = blockedNames;
const sightStatus = document.querySelector("#sightStatus");
sightStatus.className = "status " + (blockedCount ? "bad" : "good");
sightStatus.innerHTML = blockedCount
? `<strong>${blockedCount} blocked sightline${blockedCount > 1 ? "s" : ""}.</strong> Red rays stop at the obstruction.`
: `<strong>All selected sightlines are clear.</strong> Green rays reach every target.`;
const hint = document.querySelector("#hint");
if (hint && blockedCount) {
hint.textContent =
"The tall archive case can hide the amber relic from V1. Move it to a rear bay; the route has an alternate connected path.";
}
}
function updateGlare() {
scene.updateMatrixWorld(true);
const eye = viewpoints[selectedViewpoint].pos;
const activeFaces = [];
for (const face of glareFaces) {
const center = face.anchor.localToWorld(face.centerLocal.clone());
const quaternion = face.anchor.getWorldQuaternion(new THREE.Quaternion());
const normal = face.normalLocal.clone().applyQuaternion(quaternion).normalize();
let bestScore = 0;
let bestLight = null;
for (const spot of Object.values(spotlights)) {
const toLight = spot.light.position.clone().sub(center);
const toViewer = eye.clone().sub(center);
// Horizontal reflection geometry keeps the warning symbolic and
// understandable without pretending to be a full BRDF.
const lightHorizontal = new THREE.Vector3(toLight.x, 0, toLight.z);
const viewerHorizontal = new THREE.Vector3(toViewer.x, 0, toViewer.z);
if (lightHorizontal.lengthSq() < 1e-6 ||
viewerHorizontal.lengthSq() < 1e-6) continue;
lightHorizontal.normalize();
viewerHorizontal.normalize();
const faceAlignment = Math.max(0, normal.dot(lightHorizontal));
const viewerAlignment = Math.max(0, normal.dot(viewerHorizontal));
const reflectionAlignment = Math.max(
0, lightHorizontal.dot(viewerHorizontal)
);
const score =
faceAlignment *
viewerAlignment *
Math.pow(reflectionAlignment, 3);
if (score > bestScore) {
bestScore = score;
bestLight = spot;
}
}
const bad = bestScore > 0.68 && bestLight?.power > 45;
face.material.opacity = bad ? 0.88 : 0;
face.overlay.visible = bad;
if (bad) {
activeFaces.push(`${face.name} ← ${bestLight.name}`);
}
}
analysisInfo.glare = activeFaces;
const glareStatus = document.querySelector("#glareStatus");
glareStatus.className = "status " + (activeFaces.length ? "warn" : "good");
glareStatus.innerHTML = activeFaces.length
? `<strong>Glare overlay active.</strong> ${activeFaces.join("<br>")}`
: `<strong>No symbolic glare.</strong> The designated faces are clear from this eye.`;
}
let analysisDirty = true;
function updateAnalysis() {
if (!analysisDirty) return;
analysisDirty = false;
updateSightlines();
updateGlare();
}
// -------------------------------------------------------------------------
// Custom camera and pointer controls — no addon imports
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 1.15, 0),
theta: 0.66,
phi: 0.82,
radius: 18.2
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.target.set(0, 1.15, 0);
orbit.theta = 0.66;
orbit.phi = 0.82;
orbit.radius = 18.2;
}
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
const pointer = new THREE.Vector2();
const rayPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const floorPoint = new THREE.Vector3();
let pointerDown = false;
let orbiting = false;
let panning = false;
let draggingLight = null;
let pendingSlot = null;
let lastX = 0;
let lastY = 0;
let downX = 0;
let downY = 0;
let moved = false;
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 pickInteractive(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const slotHits = raycaster.intersectObjects(slotMeshes, false);
if (slotHits.length && slotHits[0].object.visible) {
return {
type: "slot",
record: slotHits[0].object.userData.slotRecord
};
}
const viewpointHits = raycaster.intersectObjects(viewpointMeshes, true);
if (viewpointHits.length) {
return {
type: "viewpoint",
id: viewpointHits[0].object.userData.viewpointId
};
}
const objectHits = raycaster.intersectObjects(pickables, true);
if (objectHits.length) {
const hit = objectHits[0].object;
if (hit.userData.lightId) {
return { type: "light", id: hit.userData.lightId };
}
if (hit.userData.exhibitId) {
return { type: "exhibit", id: hit.userData.exhibitId };
}
}
return null;
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
moved = false;
downX = lastX = event.clientX;
downY = lastY = event.clientY;
pendingSlot = null;
draggingLight = null;
renderer.domElement.setPointerCapture(event.pointerId);
if (event.button === 2) {
panning = true;
return;
}
const hit = pickInteractive(event);
if (hit?.type === "slot") {
pendingSlot = hit.record;
return;
}
if (hit?.type === "light") {
selectLight(hit.id);
draggingLight = spotlights[hit.id];
return;
}
orbiting = true;
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.hypot(event.clientX - downX, event.clientY - downY) > 4) {
moved = true;
}
if (draggingLight) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(rayPlane, floorPoint)) {
draggingLight.pos.x = THREE.MathUtils.clamp(floorPoint.x, -8, 8);
draggingLight.pos.y = THREE.MathUtils.clamp(floorPoint.z, -5.8, 5.8);
updateSpotlight(draggingLight);
updateLightUI();
analysisDirty = true;
}
} else if (panning) {
const right = new THREE.Vector3();
const forward = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, new THREE.Vector3(), forward);
forward.y = 0;
forward.normalize();
right.y = 0;
right.normalize();
const scale = orbit.radius * 0.0014;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(forward, -dy * scale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -7, 7);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -5, 5);
} else if (orbiting) {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.28,
1.35
);
}
lastX = event.clientX;
lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointerDown) return;
if (pendingSlot && !moved) {
moveExhibit(pendingSlot);
} else if (!moved) {
const hit = pickInteractive(event);
if (hit?.type === "exhibit") {
const exhibit = movableExhibits.find(item => item.id === hit.id);
if (exhibit) selectExhibit(exhibit);
} else if (hit?.type === "viewpoint") {
selectedViewpoint = hit.id;
viewpointSelect.value = hit.id;
viewpointSelect.dispatchEvent(new Event("change"));
}
}
pointerDown = false;
orbiting = false;
panning = false;
draggingLight = null;
pendingSlot = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
orbiting = false;
panning = false;
draggingLight = null;
pendingSlot = null;
});
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
7,
29
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Reset and animation
// -------------------------------------------------------------------------
const initialPositions = {
tall: new THREE.Vector2(4.8, 1.25),
blue: new THREE.Vector2(-6.7, 0.5),
ceramic: new THREE.Vector2(2.7, 0.3),
amber: new THREE.Vector2(4.7, -3.6),
neutral: new THREE.Vector2(-7.8, 3.5)
};
document.querySelector("#resetLayout").addEventListener("click", () => {
movableExhibits.forEach(exhibit => {
exhibit.pos.copy(initialPositions[exhibit.id]);
exhibit.targetPos.copy(initialPositions[exhibit.id]);
exhibit.slotIndex = 0;
});
spotlights.L1.pos.set(4.8, -0.1);
spotlights.L1.aim.set(4.7, -3.6);
spotlights.L1.power = 92;
spotlights.L2.pos.set(-6.0, 4.8);
spotlights.L2.aim.set(-4.5, -6.25);
spotlights.L2.power = 76;
spotlights.L3.pos.set(1.5, 3.6);
spotlights.L3.aim.set(2.7, 0.3);
spotlights.L3.power = 58;
Object.values(spotlights).forEach(updateSpotlight);
updateLightUI();
const route = computeRouteState();
updateRouteVisuals(route);
renderCandidates();
analysisDirty = true;
toast("The original difficult placement has been restored.");
});
selectExhibit(tallExhibit);
selectLight("L1");
updateRouteVisuals(computeRouteState());
updateCamera();
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
let exhibitMoving = false;
for (const exhibit of movableExhibits) {
const dx = exhibit.targetPos.x - exhibit.group.position.x;
const dz = exhibit.targetPos.y - exhibit.group.position.z;
if (Math.abs(dx) + Math.abs(dz) > 0.006) {
exhibit.group.position.x += dx * 0.12;
exhibit.group.position.z += dz * 0.12;
exhibitMoving = true;
} else {
exhibit.group.position.x = exhibit.targetPos.x;
exhibit.group.position.z = exhibit.targetPos.y;
}
}
if (exhibitMoving) analysisDirty = true;
const pulse = 0.72 + Math.sin(clock.elapsedTime * 5.2) * 0.18;
for (const face of glareFaces) {
if (face.overlay.visible) {
face.material.opacity = pulse;
}
}
updateCamera();
updateAnalysis();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```