Prompt specification
Build or customize the Three.js 3D scene "School corridor storage planning" 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: School corridor storage planning
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/school-corridor-storage-planning-x0172
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: school corridor storage planning. Build a corridor with bench modules, backpack spaces, and classroom doors; users position storage to serve several visitors while an animated route checks passage continuity. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (school-corridor-storage-planning-x0172):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Corridor Storage Planner</title>
<style>
:root {
--ink: #edf5ff;
--muted: #9eb0c8;
--panel: rgba(15, 25, 43, 0.9);
--panel-light: rgba(255, 255, 255, 0.07);
--stroke: rgba(255, 255, 255, 0.13);
--mint: #70e1ba;
--coral: #ff7b76;
--blue: #77a9ff;
--amber: #ffc76a;
--shadow: 0 18px 55px rgba(3, 10, 24, 0.32);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce6ef;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#app, #scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
outline: none;
touch-action: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--stroke);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.header {
position: fixed;
z-index: 5;
top: 18px;
left: 20px;
right: 20px;
height: 66px;
border-radius: 18px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 18px;
pointer-events: none;
}
.brand, .header-actions {
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
.brand-mark {
width: 38px;
height: 38px;
border-radius: 12px;
display: grid;
place-items: center;
background: linear-gradient(145deg, var(--mint), #9ae7ff);
color: #102239;
font-weight: 900;
box-shadow: 0 7px 20px rgba(112, 225, 186, 0.25);
}
.brand h1 {
margin: 0;
font-size: 16px;
letter-spacing: 0.01em;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
}
.pill {
min-height: 34px;
padding: 0 13px;
border: 1px solid var(--stroke);
border-radius: 11px;
color: var(--ink);
background: rgba(255, 255, 255, 0.07);
cursor: pointer;
font-size: 12px;
font-weight: 700;
transition: 160ms ease;
}
.pill:hover {
background: rgba(255, 255, 255, 0.13);
transform: translateY(-1px);
}
.pill.primary {
color: #102239;
border-color: transparent;
background: var(--mint);
}
.panel {
position: fixed;
z-index: 4;
top: 100px;
bottom: 98px;
width: 310px;
border-radius: 20px;
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(255,255,255,.18) transparent;
}
.planner {
left: 20px;
padding: 18px;
}
.inspector {
right: 20px;
width: 250px;
padding: 18px;
}
.section {
padding-bottom: 17px;
margin-bottom: 17px;
border-bottom: 1px solid var(--stroke);
}
.section:last-child {
border-bottom: 0;
margin-bottom: 0;
padding-bottom: 0;
}
.eyebrow {
color: var(--mint);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h2 {
margin: 5px 0 14px;
font-size: 18px;
line-height: 1.2;
}
h3 {
margin: 0 0 10px;
font-size: 12px;
letter-spacing: 0.02em;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-bottom: 12px;
}
.metric {
min-height: 70px;
border: 1px solid var(--stroke);
border-radius: 14px;
background: rgba(255, 255, 255, 0.055);
padding: 11px;
}
.metric strong {
display: block;
font-size: 22px;
line-height: 1;
margin-bottom: 7px;
}
.metric span {
color: var(--muted);
font-size: 10px;
line-height: 1.3;
display: block;
}
.metric.warn strong { color: var(--amber); }
.metric.good strong { color: var(--mint); }
.button-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.tool-button {
min-height: 43px;
border: 1px solid var(--stroke);
border-radius: 12px;
background: rgba(255, 255, 255, 0.065);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: 160ms ease;
}
.tool-button:hover {
background: rgba(255, 255, 255, 0.12);
transform: translateY(-1px);
}
.tool-button.bench:hover { border-color: rgba(112,225,186,.65); }
.tool-button.cubby:hover { border-color: rgba(119,169,255,.65); }
.visitor-list {
display: grid;
gap: 8px;
}
.visitor {
display: grid;
grid-template-columns: 9px 1fr;
gap: 10px;
align-items: start;
padding: 10px;
border-radius: 13px;
background: rgba(255, 255, 255, 0.045);
border: 1px solid rgba(255, 255, 255, 0.07);
}
.visitor-dot {
width: 8px;
height: 8px;
border-radius: 50%;
margin-top: 4px;
box-shadow: 0 0 12px currentColor;
}
.visitor-main {
min-width: 0;
display: flex;
justify-content: space-between;
gap: 8px;
font-size: 11px;
font-weight: 800;
}
.visitor-room {
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.visitor-storage {
margin-top: 5px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.check-button {
width: 100%;
min-height: 46px;
margin-top: 13px;
border: 0;
border-radius: 13px;
color: #102239;
background: linear-gradient(135deg, var(--mint), #8be6ff);
cursor: pointer;
font-weight: 900;
font-size: 12px;
box-shadow: 0 10px 24px rgba(112, 225, 186, 0.18);
transition: 160ms ease;
}
.check-button:hover { transform: translateY(-2px); }
.check-button:disabled { opacity: .6; cursor: wait; transform: none; }
.hint {
margin-top: 9px;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
text-align: center;
}
.inspector h2 { margin-bottom: 5px; }
.type-badge {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
margin-bottom: 15px;
}
.type-badge::before {
content: "";
width: 8px;
height: 8px;
border-radius: 3px;
background: var(--mint);
}
.property {
display: flex;
justify-content: space-between;
align-items: center;
padding: 9px 0;
border-bottom: 1px solid rgba(255,255,255,.08);
color: var(--muted);
font-size: 10px;
}
.property strong {
color: var(--ink);
font-size: 11px;
}
.inspector-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.danger {
color: #ffaaa6 !important;
border-color: rgba(255, 123, 118, .25) !important;
background: rgba(255, 123, 118, .08) !important;
}
.status-bar {
position: fixed;
z-index: 4;
left: 350px;
right: 290px;
bottom: 20px;
min-height: 58px;
border-radius: 17px;
padding: 10px 15px;
display: flex;
align-items: center;
gap: 12px;
}
.status-icon {
width: 33px;
height: 33px;
flex: 0 0 auto;
border-radius: 11px;
display: grid;
place-items: center;
color: var(--mint);
background: rgba(112,225,186,.12);
font-size: 15px;
}
.status-copy { min-width: 0; flex: 1; }
.status-copy strong {
display: block;
font-size: 11px;
margin-bottom: 3px;
}
.status-copy span {
display: block;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.legend {
display: flex;
gap: 12px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.legend span {
display: flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 50%;
display: inline-block;
}
.toast {
position: fixed;
z-index: 10;
left: 50%;
top: 98px;
transform: translate(-50%, -12px);
opacity: 0;
pointer-events: none;
padding: 10px 15px;
border-radius: 12px;
color: #102239;
background: var(--mint);
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 900;
transition: 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 900px) {
.inspector { display: none; }
.status-bar { right: 20px; }
.legend { display: none; }
}
@media (max-width: 650px) {
.header { left: 10px; right: 10px; top: 10px; }
.header .pill:not(.primary) { display: none; }
.panel {
top: auto;
bottom: 84px;
left: 10px;
right: 10px;
width: auto;
max-height: 42vh;
}
.status-bar { left: 10px; right: 10px; bottom: 10px; }
.brand p { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly school corridor storage planner"></canvas>
<header class="header glass">
<div class="brand">
<div class="brand-mark">CS</div>
<div>
<h1>Corridor Storage Planner</h1>
<p>Arrange shared spaces. Protect the route to every classroom.</p>
</div>
</div>
<div class="header-actions">
<button class="pill" id="cameraReset">Reset view</button>
<button class="pill" id="planReset">Reset plan</button>
<button class="pill primary" id="toggleAnimation">Pause routes</button>
</div>
</header>
<aside class="panel planner glass">
<section class="section">
<div class="eyebrow">Shared capacity</div>
<h2>Storage plan</h2>
<div class="metrics">
<div class="metric" id="benchMetric">
<strong>0 / 6</strong>
<span>Bench seats assigned</span>
</div>
<div class="metric" id="cubbyMetric">
<strong>0 / 6</strong>
<span>Backpack spaces assigned</span>
</div>
</div>
<div class="button-grid">
<button class="tool-button bench" id="addBench">+ Bench module</button>
<button class="tool-button cubby" id="addCubby">+ Backpack cubby</button>
</div>
</section>
<section class="section">
<div class="eyebrow">Visitors</div>
<h2>Arrival group</h2>
<div class="visitor-list" id="visitorList"></div>
</section>
<section class="section">
<button class="check-button" id="checkRoutes">Check passage continuity</button>
<div class="hint">Drag furniture to move it. Drag empty space to orbit; scroll to zoom.</div>
</section>
</aside>
<aside class="panel inspector glass">
<div class="eyebrow">Selection</div>
<h2 id="selectedTitle">Nothing selected</h2>
<div class="type-badge" id="selectedType">Choose a storage module</div>
<div class="property">
<span>Position</span>
<strong id="selectedPosition">—</strong>
</div>
<div class="property">
<span>Rotation</span>
<strong id="selectedRotation">—</strong>
</div>
<div class="property">
<span>Assigned visitors</span>
<strong id="selectedOccupancy">—</strong>
</div>
<div class="property">
<span>Route clearance</span>
<strong>0.55 m minimum</strong>
</div>
<div class="inspector-actions">
<button class="tool-button" id="rotateSelected">Rotate 90°</button>
<button class="tool-button danger" id="deleteSelected">Remove</button>
</div>
</aside>
<div class="status-bar glass">
<div class="status-icon" id="statusIcon">✓</div>
<div class="status-copy">
<strong id="statusTitle">Ready to check</strong>
<span id="statusDetail">Arrange storage modules, then run the animated continuity check.</span>
</div>
<div class="legend">
<span><i style="background:#70e1ba"></i>Open route</span>
<span><i style="background:#ff7b76"></i>Blocked</span>
<span><i style="background:#77a9ff"></i>Visitor path</span>
</div>
</div>
<div class="toast" 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";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce6ef);
scene.fog = new THREE.Fog(0xdce6ef, 34, 65);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0, 0);
const cameraState = { theta: 0, phi: 0.69, radius: 29 };
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xf5fbff, 0x8895a7, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff5df, 3.1);
sun.position.set(-8, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.bias = -0.0006;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8d7ff, 1.1);
fill.position.set(13, 9, -12);
scene.add(fill);
const palette = {
floor: 0xd7d9d3,
floorDark: 0xb8beb9,
wall: 0xe7edf0,
wallCap: 0x9aabc0,
frame: 0x7e91a8,
mint: 0x70e1ba,
blue: 0x77a9ff,
coral: 0xff7b76,
amber: 0xffc76a,
wood: 0xd79d64,
dark: 0x23324a
};
const modules = [];
const visitors = [];
const routesGroup = new THREE.Group();
const beaconGroup = new THREE.Group();
scene.add(routesGroup, beaconGroup);
let selectedId = null;
let moduleCounter = 0;
let routeRunning = true;
let routeTime = 0;
let scanStart = 0;
let scanning = false;
let lastNetwork = null;
let toastTimer = 0;
const DOORS = [
{ name: "201", x: -10, side: -1, color: 0xff8f83 },
{ name: "202", x: -10, side: 1, color: 0x70e1ba },
{ name: "203", x: 0, side: -1, color: 0x77a9ff },
{ name: "204", x: 0, side: 1, color: 0xffc76a },
{ name: "205", x: 10, side: -1, color: 0xb796ff },
{ name: "206", x: 10, side: 1, color: 0x62d7ef }
];
const visitorDefinitions = [
{ name: "Maya", door: 0, color: 0xff7b76 },
{ name: "Leo", door: 1, color: 0x70e1ba },
{ name: "Noor", door: 2, color: 0x77a9ff },
{ name: "Eli", door: 3, color: 0xffc76a },
{ name: "Zoe", door: 4, color: 0xb796ff },
{ name: "Ari", door: 5, color: 0x62d7ef }
];
const START = { x: -14.25, z: 0.25 };
const CLEARANCE = 0.55;
const GRID = {
cell: 0.5,
minX: -14.5,
maxX: 14.5,
minZ: -4.25,
maxZ: 4.25
};
GRID.nx = Math.round((GRID.maxX - GRID.minX) / GRID.cell) + 1;
GRID.nz = Math.round((GRID.maxZ - GRID.minZ) / GRID.cell) + 1;
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(text, bg = "#263850", fg = "#ffffff", width = 320, height = 80) {
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = fg;
ctx.font = `800 ${Math.floor(height * 0.48)}px system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function sign(text, width, height, bg, fg) {
const texture = makeCanvasTexture(text, bg, fg);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture, transparent: true, side: THREE.DoubleSide })
);
return mesh;
}
// Corridor shell.
const floorMat = material(palette.floor);
const floor = box(32.5, 0.32, 10.3, floorMat, 0, -0.2, 0);
floor.castShadow = false;
const tilePoints = [];
for (let x = -16; x <= 16; x += 2) {
tilePoints.push(new THREE.Vector3(x, -0.025, -5), new THREE.Vector3(x, -0.025, 5));
}
for (let z = -5; z <= 5; z += 2) {
tilePoints.push(new THREE.Vector3(-16, -0.025, z), new THREE.Vector3(16, -0.025, z));
}
const tileGeometry = new THREE.BufferGeometry().setFromPoints(tilePoints);
scene.add(new THREE.LineSegments(
tileGeometry,
new THREE.LineBasicMaterial({ color: 0xbec5c1, transparent: true, opacity: 0.6 })
));
const wallMat = material(palette.wall);
const wallCapMat = material(palette.wallCap);
const glassMat = material(0xb9d7e8, {
transparent: true,
opacity: 0.22,
roughness: 0.25,
side: THREE.DoubleSide
});
glassMat.depthWrite = false;
for (const side of [-1, 1]) {
box(32.4, 1.15, 0.25, wallMat, 0, 0.55, side * 5.02);
box(32.4, 0.13, 0.32, wallCapMat, 0, 1.15, side * 5.02);
box(32.2, 2.65, 0.08, glassMat, 0, 2.48, side * 5.02);
for (let x = -15; x <= 15; x += 5) {
box(0.26, 3.85, 0.32, wallCapMat, x, 1.9, side * 5.02);
}
}
// Classroom doors.
const doorMat = material(0x536a82);
const frameMat = material(0xf4f1e9);
for (const door of DOORS) {
const z = door.side * 4.86;
box(1.9, 2.6, 0.16, frameMat, door.x, 1.3, z);
box(1.58, 2.38, 0.18, doorMat, door.x, 1.18, z - door.side * 0.04);
box(0.55, 0.48, 0.06, material(0xa9d8e9), door.x - 0.34, 1.78, z - door.side * 0.15);
box(0.08, 0.08, 0.08, material(0xf4c66e), door.x + 0.52, 1.04, z - door.side * 0.17);
const roomSign = sign(
`ROOM ${door.name}`,
1.55,
0.38,
`#${new THREE.Color(door.color).getHexString()}`,
"#14243a"
);
roomSign.position.set(door.x, 2.86, z - door.side * 0.18);
roomSign.rotation.y = door.side < 0 ? 0 : Math.PI;
scene.add(roomSign);
}
// Entrance portal and floor marker.
const portalMat = material(0x748ba3);
box(0.3, 3.5, 0.35, portalMat, -15.8, 1.7, -2.4);
box(0.3, 3.5, 0.35, portalMat, -15.8, 1.7, 2.4);
box(0.3, 0.35, 5.15, portalMat, -15.8, 3.3, 0);
const entranceSign = sign("MAIN ENTRANCE", 3.1, 0.52, "#263850", "#ffffff");
entranceSign.position.set(-15.62, 3.25, 0);
entranceSign.rotation.y = Math.PI / 2;
scene.add(entranceSign);
const entryMarker = new THREE.Mesh(
new THREE.CircleGeometry(0.62, 6),
new THREE.MeshBasicMaterial({ color: 0x70e1ba, transparent: true, opacity: 0.45 })
);
entryMarker.rotation.x = -Math.PI / 2;
entryMarker.position.set(-14.25, -0.01, 0.25);
scene.add(entryMarker);
// Low-poly ceiling lights.
for (const x of [-10, 0, 10]) {
const fixture = box(2.2, 0.12, 0.55, material(0xf5f3e8), x, 4.0, 0);
fixture.castShadow = false;
box(2.0, 0.03, 0.38, material(0xffffff, {
emissive: 0xfff4cf,
emissiveIntensity: 0.65
}), x, 3.92, 0);
}
// Selection outline.
const selectionGeometry = new THREE.BufferGeometry();
selectionGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(15), 3)
);
const selectionMaterial = new THREE.LineBasicMaterial({
color: 0x70e1ba,
transparent: true,
opacity: 0.95,
depthTest: false
});
const selectionOutline = new THREE.LineLoop(selectionGeometry, selectionMaterial);
selectionOutline.visible = false;
selectionOutline.renderOrder = 10;
scene.add(selectionOutline);
// Moving continuity scanner.
const scanner = new THREE.Group();
const scannerMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 3.8, 9.9),
new THREE.MeshBasicMaterial({
color: 0x70e1ba,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
scannerMesh.position.y = 1.85;
scanner.add(scannerMesh);
const scannerEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(scannerMesh.geometry),
new THREE.LineBasicMaterial({ color: 0x70e1ba, transparent: true, opacity: 0.9 })
);
scannerEdge.position.y = 1.85;
scanner.add(scannerEdge);
scanner.visible = false;
scene.add(scanner);
function moduleBaseSize(type) {
return type === "bench"
? { w: 3.4, d: 1.0 }
: { w: 2.1, d: 0.78 };
}
function moduleExtents(module) {
const base = moduleBaseSize(module.type);
const swap = Math.abs(Math.round(module.rotation / (Math.PI / 2))) % 2 === 1;
return {
hw: (swap ? base.d : base.w) / 2,
hd: (swap ? base.w : base.d) / 2
};
}
function createModuleVisual(module) {
const group = new THREE.Group();
group.userData.moduleId = module.id;
if (module.type === "bench") {
const wood = material(palette.wood);
const support = material(0x4e647c);
const cushion = material(palette.mint);
box(3.4, 0.22, 1.0, wood, 0, 0.68, 0, group);
box(3.12, 0.10, 0.78, cushion, 0, 0.84, 0, group);
box(3.4, 0.68, 0.16, wood, 0, 1.12, -0.43, group);
for (const x of [-1.28, 1.28]) {
box(0.16, 0.66, 0.78, support, x, 0.33, 0, group);
}
const divider = box(0.055, 0.018, 0.76, material(0x4c6a78), 0, 0.9, 0, group);
divider.castShadow = false;
} else {
const shell = material(0x83a9c7);
const back = material(0x426781);
const slotColors = [0xff9b83, 0xffcf78, 0x8bdac4, 0x99b9ff];
box(2.1, 1.75, 0.13, back, 0, 0.9, -0.32, group);
box(0.13, 1.75, 0.72, shell, -1.0, 0.9, 0, group);
box(0.13, 1.75, 0.72, shell, 1.0, 0.9, 0, group);
box(2.1, 0.13, 0.72, shell, 0, 0.12, 0, group);
box(2.1, 0.13, 0.72, shell, 0, 0.88, 0, group);
box(2.1, 0.13, 0.72, shell, 0, 1.72, 0, group);
box(0.11, 1.6, 0.72, shell, 0, 0.9, 0, group);
for (let i = 0; i < 4; i++) {
const sx = i % 2 === 0 ? -0.49 : 0.49;
const sy = i < 2 ? 0.48 : 1.27;
const bag = box(0.55, 0.43, 0.28, material(slotColors[i]), sx, sy, 0.03, group);
bag.rotation.z = (i % 2 ? -1 : 1) * 0.035;
box(0.25, 0.07, 0.04, material(0x394a60), sx, sy + 0.2, 0.19, group);
}
}
group.traverse((child) => {
if (child.isMesh) {
child.userData.moduleId = module.id;
child.castShadow = true;
child.receiveShadow = true;
}
});
return group;
}
function addModule(type, position, rotation = 0, explicitName = null) {
const id = `${type}-${++moduleCounter}`;
const module = {
id,
type,
name: explicitName || `${type === "bench" ? "Bench" : "Cubby"} ${String(moduleCounter).padStart(2, "0")}`,
group: null,
rotation
};
module.group = createModuleVisual(module);
module.group.position.set(position.x, 0, position.z);
module.group.rotation.y = rotation;
scene.add(module.group);
modules.push(module);
return module;
}
function removeModule(module) {
scene.remove(module.group);
module.group.traverse((child) => {
if (child.isMesh) {
child.geometry?.dispose();
if (Array.isArray(child.material)) child.material.forEach(m => m.dispose());
else child.material?.dispose();
}
});
}
function findOpenPosition(type) {
const base = moduleBaseSize(type);
const candidates = [];
for (let z of [-4.05, 4.05, -3.8, 3.8]) {
for (let x = -12; x <= 12; x += 2) candidates.push({ x, z });
}
return candidates.find(p => {
const hw = base.w / 2 + 0.15;
const hd = base.d / 2 + 0.15;
const nearDoor = DOORS.some(d =>
Math.abs(d.x - p.x) < d.side * 0 + 1.25 + base.w / 2 &&
Math.abs(d.side * 5 - p.z) < 2
);
if (nearDoor) return false;
return !modules.some(m => {
const e = moduleExtents(m);
return Math.abs(m.group.position.x - p.x) < e.hw + hw &&
Math.abs(m.group.position.z - p.z) < e.hd + hd;
});
}) || { x: 0, z: 0 };
}
function resetPlan() {
for (const module of modules) removeModule(module);
modules.length = 0;
moduleCounter = 0;
selectedId = null;
addModule("bench", { x: -6, z: -4.05 }, 0, "Bench 01");
addModule("bench", { x: 6, z: -4.05 }, 0, "Bench 02");
addModule("bench", { x: -5, z: 4.05 }, Math.PI, "Bench 03");
addModule("cubby", { x: -2.5, z: 4.05 }, Math.PI, "Cubby 01");
addModule("cubby", { x: 4.5, z: 4.05 }, Math.PI, "Cubby 02");
routeTime = 0;
scanning = false;
scanner.visible = false;
refreshPlan();
notify("Default storage plan restored");
}
function assignmentFor(index) {
const benches = modules.filter(m => m.type === "bench");
const cubbies = modules.filter(m => m.type === "cubby");
return {
bench: benches.length ? benches[index % benches.length] : null,
cubby: cubbies.length ? cubbies[Math.floor(index / 2) % cubbies.length] : null
};
}
function worldToCell(point) {
const x = THREE.MathUtils.clamp(
Math.round((point.x - GRID.minX) / GRID.cell),
0,
GRID.nx - 1
);
const z = THREE.MathUtils.clamp(
Math.round((point.z - GRID.minZ) / GRID.cell),
0,
GRID.nz - 1
);
return { x, z };
}
function cellToWorld(x, z) {
return {
x: GRID.minX + x * GRID.cell,
z: GRID.minZ + z * GRID.cell
};
}
function cellIndex(x, z) {
return z * GRID.nx + x;
}
function buildBlockedGrid() {
const blocked = new Uint8Array(GRID.nx * GRID.nz);
for (let iz = 0; iz < GRID.nz; iz++) {
for (let ix = 0; ix < GRID.nx; ix++) {
const p = cellToWorld(ix, iz);
const hit = modules.some(module => {
const e = moduleExtents(module);
return Math.abs(p.x - module.group.position.x) <= e.hw + CLEARANCE &&
Math.abs(p.z - module.group.position.z) <= e.hd + CLEARANCE;
});
blocked[cellIndex(ix, iz)] = hit ? 1 : 0;
}
}
return blocked;
}
function findPath(startPoint, endPoint, blocked = buildBlockedGrid()) {
const start = worldToCell(startPoint);
const end = worldToCell(endPoint);
const startIndex = cellIndex(start.x, start.z);
const endIndex = cellIndex(end.x, end.z);
if (blocked[startIndex] || blocked[endIndex]) return null;
const parent = new Int32Array(GRID.nx * GRID.nz);
parent.fill(-1);
const queue = new Int32Array(GRID.nx * GRID.nz);
let head = 0;
let tail = 0;
queue[tail++] = startIndex;
parent[startIndex] = startIndex;
const directions = [[1,0], [-1,0], [0,1], [0,-1]];
while (head < tail) {
const current = queue[head++];
if (current === endIndex) break;
const cx = current % GRID.nx;
const cz = Math.floor(current / GRID.nx);
for (const [dx, dz] of directions) {
const nx = cx + dx;
const nz = cz + dz;
if (nx < 0 || nx >= GRID.nx || nz < 0 || nz >= GRID.nz) continue;
const ni = cellIndex(nx, nz);
if (blocked[ni] || parent[ni] !== -1) continue;
parent[ni] = current;
queue[tail++] = ni;
}
}
if (parent[endIndex] === -1) return null;
const path = [];
let current = endIndex;
while (true) {
const x = current % GRID.nx;
const z = Math.floor(current / GRID.nx);
path.push(cellToWorld(x, z));
if (current === startIndex) break;
current = parent[current];
}
path.reverse();
return path;
}
function pathLength(path) {
if (!path) return Infinity;
let length = 0;
for (let i = 1; i < path.length; i++) {
length += Math.hypot(
path[i].x - path[i - 1].x,
path[i].z - path[i - 1].z
);
}
return length;
}
function simplifyPath(path) {
if (!path || path.length < 3) return path || [];
const simplified = [path[0]];
for (let i = 1; i < path.length - 1; i++) {
const a = simplified[simplified.length - 1];
const b = path[i];
const c = path[i + 1];
const cross = (b.x - a.x) * (c.z - a.z) - (b.z - a.z) * (c.x - a.x);
if (Math.abs(cross) > 0.0001) simplified.push(b);
}
simplified.push(path[path.length - 1]);
return simplified;
}
function findAccessPoint(module, blocked) {
const e = moduleExtents(module);
const x = module.group.position.x;
const z = module.group.position.z;
const offset = 0.72;
const candidates = [
{ x, z: z - e.hd - offset },
{ x, z: z + e.hd + offset },
{ x: x - e.hw - offset, z },
{ x: x + e.hw + offset, z },
{ x: x - e.hw - offset, z: z - e.hd - offset },
{ x: x + e.hw + offset, z: z - e.hd - offset },
{ x: x - e.hw - offset, z: z + e.hd + offset },
{ x: x + e.hw + offset, z: z + e.hd + offset }
];
let best = null;
for (const candidate of candidates) {
const path = findPath(START, candidate, blocked);
if (!path) continue;
const length = pathLength(path);
if (!best || length < best.length) {
best = { point: candidate, path, length };
}
}
return best;
}
function computeNetwork() {
const blocked = buildBlockedGrid();
const classroom = DOORS.map(door => {
const target = { x: door.x, z: door.side * 3.75 };
return {
door,
target,
path: findPath(START, target, blocked),
open: !!findPath(START, target, blocked)
};
});
const routes = visitorDefinitions.map((definition, index) => {
const assignment = assignmentFor(index);
if (!assignment.bench || !assignment.cubby) {
return { assignment, path: null, open: false };
}
const benchAccess = findAccessPoint(assignment.bench, blocked);
const cubbyAccess = findAccessPoint(assignment.cubby, blocked);
if (!benchAccess || !cubbyAccess) {
return { assignment, path: null, open: false };
}
const benchToCubby = findPath(benchAccess.point, cubbyAccess.point, blocked);
const doorTarget = { x: DOORS[definition.door].x, z: DOORS[definition.door].side * 3.75 };
const cubbyToDoor = findPath(cubbyAccess.point, doorTarget, blocked);
if (!benchToCubby || !cubbyToDoor) {
return { assignment, path: null, open: false };
}
const path = simplifyPath([
...benchAccess.path,
...benchToCubby.slice(1),
...cubbyToDoor.slice(1)
]);
return { assignment, path, open: true };
});
return {
classroom,
routes,
classroomOpen: classroom.filter(c => c.open).length,
visitorOpen: routes.filter(r => r.open).length,
ok: classroom.every(c => c.open) && routes.every(r => r.open)
};
}
function createVisitorVisual(color) {
const group = new THREE.Group();
const bodyMat = material(color);
const skinMat = material(0xf2c9a5);
const darkMat = material(0x27364e);
const body = new THREE.Mesh(new THREE.CylinderGeometry(0.22, 0.29, 0.72, 6), bodyMat);
body.position.y = 0.7;
body.castShadow = true;
group.add(body);
const head = new THREE.Mesh(new THREE.DodecahedronGeometry(0.24, 0), skinMat);
head.position.y = 1.27;
head.castShadow = true;
group.add(head);
for (const x of [-0.1, 0.1]) {
const leg = new THREE.Mesh(new THREE.CylinderGeometry(0.065, 0.075, 0.42, 5), darkMat);
leg.position.set(x, 0.25, 0);
leg.castShadow = true;
group.add(leg);
}
const ring = new THREE.Mesh(
new THREE.RingGeometry(0.31, 0.39, 16),
new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.7, side: THREE.DoubleSide })
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.015;
group.add(ring);
return group;
}
visitorDefinitions.forEach((definition, index) => {
const group = createVisitorVisual(definition.color);
group.position.set(START.x - index * 0.12, 0, START.z + (index - 2.5) * 0.13);
scene.add(group);
const beacon = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 8, 6),
new THREE.MeshBasicMaterial({ color: definition.color })
);
beaconGroup.add(beacon);
visitors.push({
...definition,
group,
beacon,
route: null,
routeLength: 0
});
});
function clearRoutes() {
while (routesGroup.children.length) {
const child = routesGroup.children.pop();
child.geometry?.dispose();
child.material?.dispose();
}
}
function renderNetwork(network) {
clearRoutes();
network.routes.forEach((route, index) => {
if (!route.path || route.path.length < 2) return;
const points = route.path.map(p => new THREE.Vector3(p.x, 0.06, p.z));
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const lineMaterial = new THREE.LineDashedMaterial({
color: visitorDefinitions[index].color,
dashSize: 0.28,
gapSize: 0.16,
transparent: true,
opacity: 0.78,
depthWrite: false
});
const line = new THREE.Line(geometry, lineMaterial);
line.computeLineDistances();
line.renderOrder = 2;
routesGroup.add(line);
});
}
function pointAlongPath(path, distance) {
if (!path || path.length < 2) return { x: START.x, z: START.z, dx: 1, dz: 0 };
let remaining = distance;
for (let i = 1; i < path.length; i++) {
const a = path[i - 1];
const b = path[i];
const dx = b.x - a.x;
const dz = b.z - a.z;
const segment = Math.hypot(dx, dz);
if (remaining <= segment || i === path.length - 1) {
const t = segment > 0 ? THREE.MathUtils.clamp(remaining / segment, 0, 1) : 0;
return {
x: a.x + dx * t,
z: a.z + dz * t,
dx,
dz
};
}
remaining -= segment;
}
return { x: path[0].x, z: path[0].z, dx: 1, dz: 0 };
}
function updateVisitorAnimation(delta) {
if (routeRunning) routeTime += delta;
visitors.forEach((visitor, index) => {
const routeData = lastNetwork?.routes[index];
visitor.route = routeData?.path || null;
visitor.routeLength = pathLength(visitor.route);
if (!visitor.route || visitor.routeLength === Infinity) {
visitor.group.position.set(START.x - index * 0.12, 0, START.z + (index - 2.5) * 0.13);
visitor.beacon.visible = false;
return;
}
visitor.beacon.visible = true;
const distance = (routeTime * 1.55 + index * 0.85) % visitor.routeLength;
const point = pointAlongPath(visitor.route, distance);
visitor.group.position.set(point.x, 0, point.z);
visitor.group.rotation.y = Math.atan2(point.dx, point.dz);
const beaconDistance = (distance + 0.38) % visitor.routeLength;
const beaconPoint = pointAlongPath(visitor.route, beaconDistance);
visitor.beacon.position.set(beaconPoint.x, 0.12, beaconPoint.z);
});
routesGroup.children.forEach(line => {
if (line.material?.dashOffset !== undefined) {
line.material.dashOffset = -routeTime * 0.8;
}
});
}
function updateSelectionOutline() {
const module = modules.find(m => m.id === selectedId);
if (!module) {
selectionOutline.visible = false;
return;
}
const e = moduleExtents(module);
const x = module.group.position.x;
const z = module.group.position.z;
const y = 0.045;
const positions = selectionGeometry.attributes.position;
const points = [
[x - e.hw, y, z - e.hd],
[x + e.hw, y, z - e.hd],
[x + e.hw, y, z + e.hd],
[x - e.hw, y, z + e.hd],
[x - e.hw, y, z - e.hd]
];
points.forEach((p, i) => positions.setXYZ(i, ...p));
positions.needsUpdate = true;
selectionGeometry.computeBoundingSphere();
selectionOutline.visible = true;
selectionMaterial.color.set(lastNetwork?.ok ? 0x70e1ba : 0xff7b76);
}
function updateInspector() {
const module = modules.find(m => m.id === selectedId);
if (!module) {
document.getElementById("selectedTitle").textContent = "Nothing selected";
document.getElementById("selectedType").textContent = "Choose a storage module";
document.getElementById("selectedPosition").textContent = "—";
document.getElementById("selectedRotation").textContent = "—";
document.getElementById("selectedOccupancy").textContent = "—";
document.getElementById("rotateSelected").disabled = true;
document.getElementById("deleteSelected").disabled = true;
return;
}
const assignment = visitorDefinitions.map((_, i) => assignmentFor(i));
const assigned = assignment.filter(a =>
a.bench?.id === module.id || a.cubby?.id === module.id
).length;
document.getElementById("selectedTitle").textContent = module.name;
document.getElementById("selectedType").textContent =
module.type === "bench" ? "Bench module · 2 seats" : "Backpack cubby · 4 spaces";
document.getElementById("selectedPosition").textContent =
`X ${module.group.position.x.toFixed(1)} · Z ${module.group.position.z.toFixed(1)}`;
document.getElementById("selectedRotation").textContent =
`${Math.round(module.rotation * 180 / Math.PI) % 360}°`;
document.getElementById("selectedOccupancy").textContent =
`${assigned} visitor${assigned === 1 ? "" : "s"}`;
document.getElementById("rotateSelected").disabled = false;
document.getElementById("deleteSelected").disabled = false;
}
function updateVisitorUI() {
const visitorList = document.getElementById("visitorList");
visitorList.innerHTML = visitorDefinitions.map((visitor, index) => {
const assignment = assignmentFor(index);
const benchName = assignment.bench?.name || "No bench";
const cubbyName = assignment.cubby?.name || "No cubby";
const color = `#${new THREE.Color(visitor.color).getHexString()}`;
return `
<div class="visitor">
<div class="visitor-dot" style="background:${color};color:${color}"></div>
<div>
<div class="visitor-main">
<span>${visitor.name}</span>
<span class="visitor-room">Room ${DOORS[visitor.door].name}</span>
</div>
<div class="visitor-storage">${benchName} · ${cubbyName}</div>
</div>
</div>
`;
}).join("");
}
function updateMetrics() {
const benches = modules.filter(m => m.type === "bench");
const cubbies = modules.filter(m => m.type === "cubby");
const benchCapacity = benches.length * 2;
const cubbyCapacity = cubbies.length * 4;
const benchMetric = document.getElementById("benchMetric");
const cubbyMetric = document.getElementById("cubbyMetric");
benchMetric.innerHTML = `<strong>${Math.min(6, benchCapacity)} / 6</strong><span>Bench seats assigned</span>`;
cubbyMetric.innerHTML = `<strong>${Math.min(6, cubbyCapacity)} / 6</strong><span>Backpack spaces assigned</span>`;
benchMetric.className = `metric ${benchCapacity >= 6 ? "good" : "warn"}`;
cubbyMetric.className = `metric ${cubbyCapacity >= 6 ? "good" : "warn"}`;
}
function setStatus(title, detail, tone = "good") {
document.getElementById("statusTitle").textContent = title;
document.getElementById("statusDetail").textContent = detail;
document.getElementById("statusIcon").textContent = tone === "bad" ? "!" : tone === "scan" ? "↻" : "✓";
document.getElementById("statusIcon").style.color =
tone === "bad" ? "var(--coral)" : tone === "scan" ? "var(--amber)" : "var(--mint)";
document.getElementById("statusIcon").style.background =
tone === "bad" ? "rgba(255,123,118,.12)" :
tone === "scan" ? "rgba(255,199,106,.12)" : "rgba(112,225,186,.12)";
}
function refreshPlan() {
lastNetwork = computeNetwork();
renderNetwork(lastNetwork);
updateSelectionOutline();
updateInspector();
updateVisitorUI();
updateMetrics();
if (!scanning) {
if (lastNetwork.ok) {
setStatus(
"Passage continuity confirmed",
`${lastNetwork.classroomOpen}/6 classroom routes and ${lastNetwork.visitorOpen}/6 visitor routes are open · 0.55 m clearance`,
"good"
);
} else {
const classroomText = lastNetwork.classroomOpen === 6
? "All classroom doors are reachable"
: `${6 - lastNetwork.classroomOpen} classroom route(s) blocked`;
const visitorText = lastNetwork.visitorOpen === 6
? "all visitor journeys are clear"
: `${6 - lastNetwork.visitorOpen} visitor journey(s) blocked`;
setStatus("Layout needs adjustment", `${classroomText}; ${visitorText}.`, "bad");
}
}
}
function runCheck() {
lastNetwork = computeNetwork();
renderNetwork(lastNetwork);
scanning = true;
scanStart = performance.now();
scanner.visible = true;
scanner.position.x = -15;
routeRunning = true;
routeTime = 0;
document.getElementById("toggleAnimation").textContent = "Pause routes";
setStatus("Scanning corridor continuity", "Checking every classroom, storage approach and visitor journey…", "scan");
document.getElementById("checkRoutes").disabled = true;
}
function notify(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2200);
}
// Raycasting and direct manipulation.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const planeHit = new THREE.Vector3();
let drag = null;
let orbit = null;
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function moduleAtPointer() {
const hits = raycaster.intersectObjects(modules.map(m => m.group), true);
if (!hits.length) return null;
const id = hits[0].object.userData.moduleId;
return modules.find(m => m.id === id) || null;
}
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
setPointer(event);
const module = moduleAtPointer();
if (module) {
selectedId = module.id;
if (raycaster.ray.intersectPlane(dragPlane, planeHit)) {
drag = {
module,
offsetX: planeHit.x - module.group.position.x,
offsetZ: planeHit.z - module.group.position.z,
moved: false
};
}
canvas.setPointerCapture(event.pointerId);
} else {
orbit = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
}
updateSelectionOutline();
updateInspector();
});
canvas.addEventListener("pointermove", event => {
setPointer(event);
if (drag) {
if (raycaster.ray.intersectPlane(dragPlane, planeHit)) {
const e = moduleExtents(drag.module);
const x = THREE.MathUtils.clamp(
Math.round((planeHit.x - drag.offsetX) * 4) / 4,
-14.9 + e.hw,
14.9 - e.hw
);
const z = THREE.MathUtils.clamp(
Math.round((planeHit.z - drag.offsetZ) * 4) / 4,
-4.9 + e.hd,
4.9 - e.hd
);
drag.module.group.position.x = x;
drag.module.group.position.z = z;
drag.moved = true;
updateSelectionOutline();
updateInspector();
}
} else if (orbit) {
const dx = event.clientX - orbit.x;
const dy = event.clientY - orbit.y;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + dy * 0.005, 0.28, 1.25);
orbit.x = event.clientX;
orbit.y = event.clientY;
updateCamera();
}
});
function endPointer(event) {
if (drag) {
const moved = drag.moved;
drag = null;
if (moved) {
scanning = false;
scanner.visible = false;
document.getElementById("checkRoutes").disabled = false;
refreshPlan();
}
}
orbit = null;
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.018,
16,
46
);
updateCamera();
}, { passive: false });
document.getElementById("addBench").addEventListener("click", () => {
const module = addModule("bench", findOpenPosition("bench"));
selectedId = module.id;
refreshPlan();
notify("Bench added — drag it into a clear wall zone");
});
document.getElementById("addCubby").addEventListener("click", () => {
const module = addModule("cubby", findOpenPosition("cubby"));
selectedId = module.id;
refreshPlan();
notify("Backpack cubby added — drag it into position");
});
document.getElementById("rotateSelected").addEventListener("click", () => {
const module = modules.find(m => m.id === selectedId);
if (!module) return;
module.rotation += Math.PI / 2;
module.group.rotation.y = module.rotation;
refreshPlan();
});
document.getElementById("deleteSelected").addEventListener("click", () => {
const index = modules.findIndex(m => m.id === selectedId);
if (index < 0) return;
removeModule(modules[index]);
modules.splice(index, 1);
selectedId = null;
refreshPlan();
notify("Storage module removed");
});
document.getElementById("checkRoutes").addEventListener("click", runCheck);
document.getElementById("toggleAnimation").addEventListener("click", () => {
routeRunning = !routeRunning;
document.getElementById("toggleAnimation").textContent =
routeRunning ? "Pause routes" : "Resume routes";
});
document.getElementById("cameraReset").addEventListener("click", () => {
cameraState.theta = 0;
cameraState.phi = 0.69;
cameraState.radius = 29;
cameraTarget.set(0, 0, 0);
updateCamera();
});
document.getElementById("planReset").addEventListener("click", resetPlan);
window.addEventListener("keydown", event => {
if (event.key === "Escape") {
selectedId = null;
updateSelectionOutline();
updateInspector();
}
if ((event.key === "Delete" || event.key === "Backspace") && selectedId) {
const activeTag = document.activeElement?.tagName;
if (activeTag !== "INPUT" && activeTag !== "TEXTAREA") {
document.getElementById("deleteSelected").click();
}
}
if (event.key.toLowerCase() === "r" && selectedId) {
document.getElementById("rotateSelected").click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
resetPlan();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (scanning) {
const elapsed = performance.now() - scanStart;
const t = THREE.MathUtils.clamp(elapsed / 1250, 0, 1);
scanner.position.x = THREE.MathUtils.lerp(-15, 15, t);
scannerEdge.material.opacity = 0.55 + Math.sin(elapsed * 0.02) * 0.25;
if (elapsed >= 1250) {
scanning = false;
scanner.visible = false;
document.getElementById("checkRoutes").disabled = false;
if (lastNetwork.ok) {
setStatus(
"Passage continuity confirmed",
`All 6 classrooms are reachable and all 6 visitors can reach storage and class · 0.55 m clearance`,
"good"
);
} else {
const details = [];
if (lastNetwork.classroomOpen < 6) details.push(`${6 - lastNetwork.classroomOpen} classroom route(s) blocked`);
if (lastNetwork.visitorOpen < 6) details.push(`${6 - lastNetwork.visitorOpen} visitor journey(s) blocked`);
setStatus("Adjustment required", `${details.join(" · ")}. Move or rotate the highlighted storage.`, "bad");
}
}
}
updateVisitorAnimation(delta);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```