Prompt specification
Build or customize the Three.js 3D scene "Co-Housing Common Room Layout" 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: Co-Housing Common Room Layout
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/co-housing-common-room-layout-x3239
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing negotiated boundaries between personal and shared space. Create a small co-housing floor plan with private rooms, shared kitchen, and quiet area. Test circulation and booking rules without implying a particular legal property arrangement. Voxel style.
Acceptance criteria: Use only local button events for room reservations, and show the effects of each successful reservation on room state and simulated circulation.
Technical checks: Use a local button for a room reservation. Reflect successful bookings in the room state and show their effect on circulation.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (co-housing-common-room-layout-x3239):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Ground — Boundary & Circulation Lab</title>
<style>
:root {
--ink: #25312d;
--muted: #66716c;
--paper: #f7f5ee;
--line: rgba(37, 49, 45, 0.14);
--green: #237a58;
--green-soft: #dff1e6;
--orange: #d46f46;
--orange-soft: #f8e5d9;
--blue: #287d9b;
--panel: rgba(250, 248, 241, 0.94);
--shadow: 0 18px 55px rgba(50, 61, 55, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.95), transparent 34%),
linear-gradient(135deg, #e9e7de 0%, #deddd4 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
top: 22px;
left: 26px;
right: 420px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
pointer-events: none;
z-index: 3;
}
.brand {
display: flex;
align-items: center;
gap: 11px;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.brand-mark {
width: 29px;
height: 29px;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 3px;
transform: rotate(45deg);
}
.brand-mark span {
background: var(--ink);
border-radius: 2px;
}
.brand-mark span:nth-child(2),
.brand-mark span:nth-child(3) {
background: var(--orange);
}
.mode {
padding: 8px 12px;
border: 1px solid rgba(37, 49, 45, 0.18);
border-radius: 999px;
background: rgba(255, 255, 255, 0.42);
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
#intro {
position: fixed;
top: 91px;
left: 27px;
width: min(430px, calc(100vw - 430px));
pointer-events: none;
z-index: 2;
}
.eyebrow {
margin-bottom: 10px;
color: var(--orange);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
max-width: 410px;
margin: 0;
font-size: clamp(30px, 3.2vw, 52px);
line-height: 0.98;
letter-spacing: -0.055em;
}
#intro p {
max-width: 365px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.zone-chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 15px;
}
.zone-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid rgba(37, 49, 45, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.5);
color: #53615b;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
backdrop-filter: blur(7px);
}
.zone-chip i {
width: 7px;
height: 7px;
border-radius: 2px;
background: #e5b680;
}
.zone-chip.shared i {
background: #62aebd;
}
.zone-chip.quiet i {
background: #9180c5;
}
#panel {
position: fixed;
z-index: 5;
top: 16px;
right: 16px;
bottom: 16px;
width: 372px;
overflow: auto;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 22px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(37, 49, 45, 0.22) transparent;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
padding-bottom: 16px;
border-bottom: 1px solid var(--line);
}
.panel-heading h2 {
margin: 0;
font-size: 19px;
letter-spacing: -0.025em;
}
.panel-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.live-dot {
display: flex;
align-items: center;
gap: 6px;
margin-top: 2px;
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.live-dot::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #39a875;
box-shadow: 0 0 0 4px rgba(57, 168, 117, 0.12);
}
.section {
padding: 16px 0;
border-bottom: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title strong {
color: var(--ink);
font-size: 11px;
letter-spacing: 0;
text-transform: none;
}
.control-row {
display: flex;
gap: 6px;
margin-top: 8px;
}
.control-row.wrap {
flex-wrap: wrap;
}
.pill-button {
min-height: 31px;
flex: 1;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.55);
color: var(--muted);
cursor: pointer;
font-size: 10px;
font-weight: 750;
transition: 140ms ease;
}
.pill-button:hover {
border-color: rgba(37, 49, 45, 0.32);
color: var(--ink);
transform: translateY(-1px);
}
.pill-button.active {
border-color: var(--green);
background: var(--green);
color: white;
box-shadow: 0 5px 13px rgba(35, 122, 88, 0.18);
}
.room-list {
display: grid;
gap: 9px;
}
.room-card {
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.56);
cursor: pointer;
transition: 150ms ease;
}
.room-card:hover,
.room-card.selected {
border-color: rgba(35, 122, 88, 0.45);
box-shadow: 0 8px 20px rgba(48, 66, 58, 0.08);
transform: translateY(-1px);
}
.room-card.reserved {
background: linear-gradient(120deg, rgba(223, 241, 230, 0.92), rgba(255, 255, 255, 0.66));
}
.room-top {
display: grid;
grid-template-columns: 13px 1fr auto;
align-items: start;
gap: 9px;
}
.room-swatch {
width: 11px;
height: 11px;
margin-top: 3px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(37, 49, 45, 0.12);
}
.room-top h3 {
margin: 0;
font-size: 12px;
letter-spacing: -0.01em;
}
.room-type {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.availability {
padding: 4px 6px;
border-radius: 6px;
background: #eeece5;
color: #6e756f;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.availability.booked {
background: var(--green-soft);
color: var(--green);
}
.room-rule {
margin: 9px 0 10px 22px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.reserve-button {
width: calc(100% - 22px);
min-height: 32px;
margin-left: 22px;
border: 0;
border-radius: 8px;
background: var(--ink);
color: white;
cursor: pointer;
font-size: 10px;
font-weight: 800;
transition: 140ms ease;
}
.reserve-button:hover {
background: var(--green);
transform: translateY(-1px);
}
.reserve-button.booked {
background: var(--green);
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 10px;
}
.metric {
min-height: 57px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.48);
}
.metric strong {
display: block;
font-size: 18px;
line-height: 1;
letter-spacing: -0.04em;
}
.metric span {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.route-list {
display: grid;
gap: 6px;
}
.route-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 8px;
padding: 7px 8px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.45);
}
.route-row i {
width: 7px;
height: 7px;
border-radius: 2px;
}
.route-row b {
display: block;
font-size: 10px;
}
.route-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.route-row span {
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
.empty-state {
padding: 13px;
border: 1px dashed rgba(37, 49, 45, 0.2);
border-radius: 10px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
text-align: center;
}
.primary-button {
width: 100%;
min-height: 38px;
margin-top: 10px;
border: 0;
border-radius: 10px;
background: var(--orange);
color: white;
cursor: pointer;
font-size: 11px;
font-weight: 850;
box-shadow: 0 8px 18px rgba(212, 111, 70, 0.2);
transition: 140ms ease;
}
.primary-button:hover {
filter: brightness(0.95);
transform: translateY(-1px);
}
.booking-list {
display: grid;
gap: 6px;
}
.booking-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
align-items: center;
padding: 8px 9px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.5);
}
.booking-row b {
display: block;
font-size: 10px;
}
.booking-row small {
color: var(--muted);
font-size: 8px;
}
.release-button {
border: 0;
border-radius: 6px;
background: var(--orange-soft);
color: var(--orange);
cursor: pointer;
padding: 6px 7px;
font-size: 8px;
font-weight: 850;
text-transform: uppercase;
}
.event-log {
display: grid;
gap: 7px;
}
.event {
display: grid;
grid-template-columns: 7px 1fr;
gap: 8px;
align-items: start;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.event::before {
content: "";
width: 6px;
height: 6px;
margin-top: 3px;
border-radius: 50%;
background: #9aa39e;
}
.event.success::before {
background: var(--green);
}
.event.denied::before {
background: var(--orange);
}
.disclaimer {
margin: 15px 0 2px;
color: #858c87;
font-size: 9px;
line-height: 1.5;
}
#legend {
position: fixed;
z-index: 3;
left: 26px;
bottom: 22px;
display: flex;
align-items: center;
gap: 14px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 12px;
background: rgba(250, 248, 241, 0.74);
box-shadow: 0 9px 28px rgba(50, 61, 55, 0.09);
backdrop-filter: blur(10px);
pointer-events: auto;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.legend-item i {
width: 8px;
height: 8px;
border-radius: 2px;
}
.legend-divider {
width: 1px;
height: 18px;
background: var(--line);
}
.view-button {
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 7px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 9px;
font-weight: 750;
}
#toast {
position: fixed;
z-index: 20;
left: 50%;
top: 20px;
max-width: min(420px, calc(100vw - 30px));
padding: 11px 15px;
border-radius: 10px;
background: var(--ink);
color: white;
box-shadow: 0 12px 30px rgba(37, 49, 45, 0.25);
font-size: 11px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transform: translate(-50%, -14px);
transition: 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.denied {
background: #9c4d31;
}
#toast.success {
background: var(--green);
}
@media (max-width: 900px) {
.topbar {
right: 24px;
}
#intro {
top: 78px;
width: min(360px, calc(100vw - 48px));
}
#intro p,
.zone-chips {
display: none;
}
#panel {
top: auto;
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
max-height: 48vh;
border-radius: 18px;
}
#legend {
bottom: calc(48vh + 24px);
}
.mode {
display: none;
}
}
@media (max-width: 540px) {
.topbar {
left: 16px;
top: 16px;
}
#intro {
left: 16px;
top: 65px;
}
h1 {
font-size: 29px;
}
#legend {
left: 12px;
gap: 9px;
}
.legend-item {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel floor plan"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><span></span><span></span><span></span><span></span></div>
Common Ground
</div>
<div class="mode">Boundary lab · room-use sandbox</div>
</header>
<section id="intro">
<div class="eyebrow">Co-housing planning study</div>
<h1>Negotiated space,<br />one room at a time.</h1>
<p>
Reserve a personal or shared room, test access rules, and watch the circulation model respond
in real time. The colored boundaries show operational use zones—not legal ownership.
</p>
<div class="zone-chips" aria-hidden="true">
<span class="zone-chip"><i></i>Personal</span>
<span class="zone-chip shared"><i></i>Shared</span>
<span class="zone-chip quiet"><i></i>Quiet</span>
</div>
</section>
<aside id="panel" aria-label="Booking and circulation controls">
<div class="panel-heading">
<div>
<h2>Booking desk</h2>
<p>Test a schedule and movement together.</p>
</div>
<div class="live-dot">Live model</div>
</div>
<section class="section">
<div class="section-title">Booking profile <strong id="profileSummary">Occupant · 1 person</strong></div>
<div class="control-row" id="profileControls">
<button type="button" class="pill-button active" data-profile="occupant" aria-pressed="true">Occupant</button>
<button type="button" class="pill-button" data-profile="guest" aria-pressed="false">Guest</button>
</div>
<div class="control-row" id="partyControls">
<button type="button" class="pill-button active" data-party="1" aria-pressed="true">1</button>
<button type="button" class="pill-button" data-party="2" aria-pressed="false">2</button>
<button type="button" class="pill-button" data-party="3" aria-pressed="false">3</button>
<button type="button" class="pill-button" data-party="4" aria-pressed="false">4</button>
</div>
</section>
<section class="section">
<div class="section-title">Start time <strong id="slotSummary">09:00</strong></div>
<div class="control-row wrap" id="slotControls">
<button type="button" class="pill-button active" data-slot="540" aria-pressed="true">09:00</button>
<button type="button" class="pill-button" data-slot="630" aria-pressed="false">10:30</button>
<button type="button" class="pill-button" data-slot="720" aria-pressed="false">12:00</button>
<button type="button" class="pill-button" data-slot="840" aria-pressed="false">14:00</button>
<button type="button" class="pill-button" data-slot="960" aria-pressed="false">16:00</button>
</div>
</section>
<section class="section">
<div class="section-title">Rooms <strong id="roomSummary">5 zones</strong></div>
<div class="room-list" id="roomList"></div>
</section>
<section class="section">
<div class="section-title">Simulated circulation <strong id="simulationStatus">Waiting</strong></div>
<div class="metrics">
<div class="metric"><strong id="routeCount">0</strong><span>Routes</span></div>
<div class="metric"><strong id="walkTime">0</strong><span>Route min</span></div>
<div class="metric"><strong id="pinchCount">0</strong><span>Shared cells</span></div>
</div>
<div class="route-list" id="routeList"></div>
<button type="button" class="primary-button" id="runSimulation">Run circulation test</button>
</section>
<section class="section">
<div class="section-title">Reservations <strong id="bookingCount">0 total</strong></div>
<div class="booking-list" id="bookingList"></div>
</section>
<section class="section">
<div class="section-title">Activity</div>
<div class="event-log" id="eventLog"></div>
</section>
<p class="disclaimer">
Operational simulation only. This sandbox does not determine ownership, tenancy, access rights,
property status, or any other legal arrangement.
</p>
</aside>
<div id="legend" aria-label="Floor plan legend and controls">
<div class="legend-item"><i style="background:#e6bc88"></i>Personal</div>
<div class="legend-item"><i style="background:#78b8c5"></i>Shared</div>
<div class="legend-item"><i style="background:#9c8bcd"></i>Quiet</div>
<div class="legend-divider"></div>
<span class="legend-item">Drag · orbit</span>
<span class="legend-item">Scroll · zoom</span>
<button type="button" class="view-button" id="resetView">Reset view</button>
</div>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e6de);
scene.fog = new THREE.Fog(0xe8e6de, 26, 48);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraState = {
radius: 19,
azimuth: 0.62,
elevation: 0.73,
zoom: 1,
target: new THREE.Vector3(0, 0.25, 0)
};
function updateCamera() {
const { radius, azimuth, elevation, zoom, target } = cameraState;
camera.position.set(
target.x + radius * Math.cos(elevation) * Math.sin(azimuth),
target.y + radius * Math.sin(elevation),
target.z + radius * Math.cos(elevation) * Math.cos(azimuth)
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = 12.8;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemi = new THREE.HemisphereLight(0xfffbf0, 0x9ca39a, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4df, 3.1);
sun.position.set(8, 15, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e7ee, 0.8);
fill.position.set(-10, 7, -6);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function materialFor(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.0
}));
}
return materialCache.get(color);
}
function box(parent, width, height, depth, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(unitBox, options.material || materialFor(color));
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
const grid = new THREE.GridHelper(34, 34, 0xc4c4ba, 0xd2d1c7);
grid.position.y = -0.51;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.ShadowMaterial({ color: 0x59625b, opacity: 0.16 })
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -0.5;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
box(scene, 14.2, 0.42, 10.2, 0, -0.25, 0, 0xc8c7bd);
box(scene, 13.75, 0.12, 9.75, 0, 0.01, 0, 0xe1dfd5);
const roomDefs = [
{
id: "willow",
name: "Willow Room",
type: "Personal room",
category: "personal",
x: -4.55, z: -2.05, w: 3.6, d: 3.1,
color: 0xe8bf8e,
capacity: 2,
duration: 120,
occupantOnly: true,
destination: [-3.55, -2.0],
routeColor: 0xe98562,
rule: "Personal-use boundary · occupants only · max 2 · 2 hours"
},
{
id: "pine",
name: "Pine Room",
type: "Personal room",
category: "personal",
x: -4.55, z: 1.55, w: 3.6, d: 3.1,
color: 0xdfb789,
capacity: 2,
duration: 120,
occupantOnly: true,
destination: [-3.55, 1.55],
routeColor: 0xe5aa45,
rule: "Personal-use boundary · occupants only · max 2 · 2 hours"
},
{
id: "sage",
name: "Sage Room",
type: "Personal room",
category: "personal",
x: 1.55, z: -2.15, w: 2.8, d: 3.0,
color: 0xc6d6a9,
capacity: 2,
duration: 120,
occupantOnly: true,
destination: [2.25, -1.25],
routeColor: 0x62b87c,
rule: "Personal-use boundary · occupants only · max 2 · 2 hours"
},
{
id: "kitchen",
name: "Common Table",
type: "Shared kitchen",
category: "shared",
x: 3.45, z: 1.3, w: 4.7, d: 3.9,
color: 0x9ecbd1,
capacity: 4,
duration: 90,
occupantOnly: false,
destination: [1.65, 1.75],
routeColor: 0x258eae,
rule: "Shared-use kitchen · all profiles · max 4 together · 90 minutes"
},
{
id: "quiet",
name: "Hush Room",
type: "Quiet area",
category: "quiet",
x: 4.55, z: -2.2, w: 2.45, d: 3.0,
color: 0xc5bee0,
capacity: 1,
duration: 45,
occupantOnly: true,
destination: [4.55, -2.05],
routeColor: 0x8c70c8,
rule: "Low-noise boundary · occupants only · 1 person · 45 minutes"
}
];
const roomMap = new Map();
const roomFloors = [];
function gridTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, 128, 128);
ctx.strokeStyle = "rgba(70,75,70,0.13)";
ctx.lineWidth = 2;
ctx.strokeRect(1, 1, 126, 126);
ctx.beginPath();
ctx.moveTo(64, 0);
ctx.lineTo(64, 128);
ctx.moveTo(0, 64);
ctx.lineTo(128, 64);
ctx.stroke();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
return texture;
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function drawRoomLabel(room, statusText, statusColor) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 190;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 640, 190);
roundedRect(ctx, 7, 7, 626, 176, 25);
ctx.fillStyle = "rgba(255,255,255,0.94)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = statusColor;
ctx.stroke();
ctx.fillStyle = "#25312d";
ctx.font = "800 42px system-ui, sans-serif";
ctx.fillText(room.name.toUpperCase(), 32, 68);
ctx.fillStyle = "#6c756f";
ctx.font = "700 22px system-ui, sans-serif";
ctx.fillText(room.type.toUpperCase(), 32, 105);
roundedRect(ctx, 32, 126, 220, 34, 10);
ctx.fillStyle = statusColor;
ctx.fill();
ctx.fillStyle = "white";
ctx.font = "850 18px system-ui, sans-serif";
ctx.fillText(statusText.toUpperCase(), 47, 149);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function makeRoom(room) {
const group = new THREE.Group();
scene.add(group);
const texture = gridTexture();
texture.repeat.set(room.w / 0.48, room.d / 0.48);
const floorMaterial = new THREE.MeshStandardMaterial({
color: room.color,
map: texture,
roughness: 0.9
});
const floor = box(group, room.w, 0.12, room.d, room.x, 0.075, room.z, 0xffffff, {
material: floorMaterial,
castShadow: false
});
floor.userData.roomId = room.id;
roomFloors.push(floor);
const overlayMaterial = new THREE.MeshStandardMaterial({
color: 0x2f9a68,
emissive: 0x164d36,
emissiveIntensity: 0.18,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const overlay = box(group, room.w - 0.12, 0.026, room.d - 0.12, room.x, 0.151, room.z, 0x2f9a68, {
material: overlayMaterial,
castShadow: false,
receiveShadow: false
});
overlay.visible = false;
const linePoints = [
new THREE.Vector3(room.x - room.w / 2 + 0.08, 0.17, room.z - room.d / 2 + 0.08),
new THREE.Vector3(room.x + room.w / 2 - 0.08, 0.17, room.z - room.d / 2 + 0.08),
new THREE.Vector3(room.x + room.w / 2 - 0.08, 0.17, room.z + room.d / 2 - 0.08),
new THREE.Vector3(room.x - room.w / 2 + 0.08, 0.17, room.z + room.d / 2 - 0.08)
];
const boundary = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(linePoints),
new THREE.LineDashedMaterial({
color: 0x6d746e,
dashSize: 0.18,
gapSize: 0.11,
transparent: true,
opacity: 0.8
})
);
boundary.computeLineDistances();
group.add(boundary);
const beaconMaterial = new THREE.MeshStandardMaterial({
color: 0xd09a45,
emissive: 0x6f4514,
emissiveIntensity: 0.25,
roughness: 0.55
});
const beacon = new THREE.Group();
beacon.position.set(room.x, 0.15, room.z + room.d * 0.29);
box(beacon, 0.22, 0.16, 0.22, 0, 0.08, 0, 0xffffff, { material: beaconMaterial });
box(beacon, 0.15, 0.12, 0.15, 0, 0.22, 0, 0xffffff, { material: beaconMaterial });
group.add(beacon);
const label = new THREE.Sprite(new THREE.SpriteMaterial({
map: drawRoomLabel(room, "Available", "#8a918c"),
transparent: true,
depthWrite: false
}));
label.scale.set(2.75, 0.82, 1);
label.position.set(room.x, 1.35, room.z + room.d * 0.12);
group.add(label);
roomMap.set(room.id, {
...room,
group,
floor,
overlay,
boundary,
beacon,
beaconMaterial,
label
});
}
roomDefs.forEach(makeRoom);
function wallX(z, x1, x2, height = 0.78, color = 0xf4f1e7) {
const length = Math.abs(x2 - x1);
const count = Math.max(1, Math.ceil(length / 0.48));
const piece = length / count;
for (let i = 0; i < count; i++) {
const x = x1 + (i + 0.5) * piece;
box(scene, piece - 0.018, height, 0.22, x, height / 2 + 0.08, z, color);
box(scene, piece - 0.06, 0.055, 0.26, x, height + 0.09, z, 0xfffaf0);
}
}
function wallZ(x, z1, z2, height = 0.78, color = 0xf4f1e7) {
const length = Math.abs(z2 - z1);
const count = Math.max(1, Math.ceil(length / 0.48));
const piece = length / count;
for (let i = 0; i < count; i++) {
const z = z1 + (i + 0.5) * piece;
box(scene, 0.22, height, piece - 0.018, x, height / 2 + 0.08, z, color);
box(scene, 0.26, 0.055, piece - 0.06, x, height + 0.09, z, 0xfffaf0);
}
}
wallX(-4.72, -6.75, 6.75, 0.72);
wallZ(-6.75, -4.72, 4.72, 0.62);
wallZ(6.75, -4.72, 4.72, 0.62);
wallX(4.72, -6.75, -2.05, 0.5);
wallX(4.72, -0.35, 6.75, 0.5);
wallZ(-2.5, -4.72, -1.25, 0.88);
wallZ(-2.5, -0.55, 1.25, 0.88);
wallZ(-2.5, 1.95, 4.72, 0.88);
wallX(-0.2, -6.75, -2.5, 0.88);
wallZ(0.2, -4.72, -1.7, 0.82);
wallZ(0.2, -1.0, 1.4, 0.82);
wallZ(0.2, 2.2, 4.72, 0.82);
wallX(-0.65, 1.05, 4.4, 0.82);
wallX(-0.65, 5.3, 6.75, 0.82);
wallZ(3.15, -4.72, -0.65, 0.78);
const thresholdMaterial = new THREE.MeshStandardMaterial({ color: 0xd98155, roughness: 0.8 });
box(scene, 0.32, 0.035, 0.62, -2.5, 0.16, -0.9, 0xffffff, { material: thresholdMaterial, castShadow: false });
box(scene, 0.32, 0.035, 0.62, -2.5, 0.16, 1.6, 0xffffff, { material: thresholdMaterial, castShadow: false });
box(scene, 0.62, 0.035, 0.32, 0.2, 0.16, -1.35, 0xffffff, { material: thresholdMaterial, castShadow: false });
box(scene, 0.62, 0.035, 0.32, 0.2, 0.16, 1.8, 0xffffff, { material: thresholdMaterial, castShadow: false });
box(scene, 0.78, 0.035, 0.32, 4.85, 0.16, -0.65, 0xffffff, { material: thresholdMaterial, castShadow: false });
function plant(parent, x, z, scale = 1) {
box(parent, 0.33 * scale, 0.33 * scale, 0.33 * scale, x, 0.25 * scale, z, 0xc97854);
box(parent, 0.10 * scale, 0.65 * scale, 0.10 * scale, x, 0.67 * scale, z, 0x47755b);
box(parent, 0.42 * scale, 0.18 * scale, 0.22 * scale, x - 0.12 * scale, 0.86 * scale, z, 0x6d9b67);
box(parent, 0.22 * scale, 0.20 * scale, 0.42 * scale, x + 0.12 * scale, 0.98 * scale, z, 0x81aa70);
}
function bed(parent, x, z, width = 1.25, depth = 1.85) {
box(parent, width, 0.24, depth, x, 0.23, z, 0x80695c);
box(parent, width - 0.08, 0.18, depth - 0.08, x, 0.43, z, 0xf5eee3);
box(parent, width - 0.08, 0.09, depth * 0.62, x, 0.56, z + depth * 0.14, 0x8ba8a0);
box(parent, width * 0.62, 0.15, 0.34, x, 0.58, z - depth * 0.36, 0xfffaf0);
}
function desk(parent, x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
parent.add(group);
box(group, 1.05, 0.12, 0.55, 0, 0.65, 0, 0xb5845d);
box(group, 0.1, 0.55, 0.1, -0.4, 0.32, 0, 0x4e625b);
box(group, 0.1, 0.55, 0.1, 0.4, 0.32, 0, 0x4e625b);
box(group, 0.42, 0.32, 0.08, 0.1, 0.88, -0.12, 0x435a59);
box(group, 0.34, 0.23, 0.08, 0.1, 0.88, -0.175, 0x9fd2d3);
box(group, 0.35, 0.12, 0.35, 0, 0.35, 0.5, 0x6f7f75);
}
const willow = roomMap.get("willow");
bed(willow.group, -5.45, -2.45);
desk(willow.group, -3.55, -3.15, 0);
plant(willow.group, -3.1, -1.05, 0.8);
const pine = roomMap.get("pine");
bed(pine.group, -5.45, 1.75);
desk(pine.group, -3.55, 0.75, 0);
plant(pine.group, -3.05, 2.9, 0.78);
const sage = roomMap.get("sage");
bed(sage.group, 0.95, -2.75, 1.08, 1.5);
box(sage.group, 0.75, 0.5, 0.75, 2.35, 0.36, -1.05, 0x9c8060);
box(sage.group, 0.77, 0.13, 0.77, 2.35, 0.67, -1.05, 0xc59f72);
plant(sage.group, 2.55, -3.3, 0.72);
const kitchen = roomMap.get("kitchen");
box(kitchen.group, 4.35, 0.48, 0.62, 3.5, 0.34, 2.88, 0xd9d2c4);
box(kitchen.group, 4.4, 0.08, 0.68, 3.5, 0.62, 2.88, 0xf5f0e5);
box(kitchen.group, 0.75, 0.55, 0.7, 5.25, 0.39, 0.85, 0xe7e1d5);
box(kitchen.group, 0.78, 0.08, 0.73, 5.25, 0.7, 0.85, 0xaab6ae);
box(kitchen.group, 1.8, 0.43, 0.9, 3.75, 0.33, 1.2, 0xb8784e);
box(kitchen.group, 1.95, 0.1, 1.02, 3.75, 0.59, 1.2, 0xf0d7b2);
box(kitchen.group, 0.25, 0.24, 0.25, 3.4, 0.77, 1.15, 0x5d7975);
box(kitchen.group, 0.35, 0.42, 0.35, 2.85, 0.32, 2.7, 0x789d8d);
plant(kitchen.group, 5.45, 2.85, 0.85);
const quiet = roomMap.get("quiet");
box(quiet.group, 0.48, 1.05, 2.1, 5.47, 0.61, -2.25, 0x84725f);
for (let i = 0; i < 4; i++) {
box(quiet.group, 0.33, 0.34, 0.22, 5.35, 0.37 + i * 0.34, -3.05 + i * 0.48, [0x738d78, 0xc18c6c, 0x7a92a0, 0xb3a66d][i]);
}
box(quiet.group, 1.35, 0.35, 0.55, 4.25, 0.3, -3.05, 0x9f8769);
box(quiet.group, 1.4, 0.12, 0.59, 4.25, 0.53, -3.05, 0xd9cdb9);
plant(quiet.group, 3.75, -3.35, 0.7);
function createEntryLabel() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 246, 86, 18);
ctx.fillStyle = "rgba(37,49,45,0.9)";
ctx.fill();
ctx.fillStyle = "white";
ctx.font = "850 31px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("ENTRY", 128, 59);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map: texture, transparent: true }));
sprite.scale.set(1.35, 0.51, 1);
sprite.position.set(-1.2, 0.5, 4.22);
scene.add(sprite);
}
createEntryLabel();
const state = {
profile: "occupant",
party: 1,
slot: 540,
selectedRoom: "willow",
bookings: [],
events: [],
nextBookingId: 1
};
const slots = [
{ value: 540, label: "09:00" },
{ value: 630, label: "10:30" },
{ value: 720, label: "12:00" },
{ value: 840, label: "14:00" },
{ value: 960, label: "16:00" }
];
function timeLabel(minutes) {
const hour = Math.floor(minutes / 60);
const minute = minutes % 60;
return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
}
function timeRange(minutes, duration) {
return `${timeLabel(minutes)}–${timeLabel(minutes + duration)}`;
}
function overlaps(booking, start, duration) {
return booking.start < start + duration && start < booking.start + booking.duration;
}
function activeBooking(roomId, start = state.slot) {
return state.bookings.find(booking =>
booking.roomId === roomId && overlaps(booking, start, booking.duration)
);
}
function currentSlotLabel() {
return slots.find(slot => slot.value === state.slot)?.label || timeLabel(state.slot);
}
const roomList = document.getElementById("roomList");
const roomCards = new Map();
for (const room of roomDefs) {
const card = document.createElement("article");
card.className = "room-card";
card.dataset.room = room.id;
card.innerHTML = `
<div class="room-top">
<span class="room-swatch" style="background:#${room.color.toString(16).padStart(6, "0")}"></span>
<div>
<h3>${room.name}</h3>
<span class="room-type">${room.type}</span>
</div>
<span class="availability">Available</span>
</div>
<p class="room-rule">${room.rule}</p>
<button type="button" class="reserve-button">Reserve ${currentSlotLabel()}</button>
`;
card.addEventListener("click", event => {
if (event.target.closest("button")) return;
state.selectedRoom = room.id;
updateUI();
});
const button = card.querySelector("button");
button.addEventListener("click", event => {
event.stopPropagation();
state.selectedRoom = room.id;
reserveRoom(room.id);
});
roomList.appendChild(card);
roomCards.set(room.id, card);
}
function updateRoomVisuals() {
for (const room of roomMap.values()) {
const booking = activeBooking(room.id);
room.overlay.visible = Boolean(booking);
room.beaconMaterial.color.setHex(booking ? 0x2d9c67 : 0xd09a45);
room.beaconMaterial.emissive.setHex(booking ? 0x14563a : 0x6f4514);
room.boundary.material.color.setHex(
state.selectedRoom === room.id ? 0x237a58 : 0x6d746e
);
room.boundary.material.opacity = state.selectedRoom === room.id ? 1 : 0.72;
const oldTexture = room.label.material.map;
const statusText = booking
? `${booking.slotLabel} · ${booking.party} ${booking.party === 1 ? "person" : "people"}`
: `Available · ${currentSlotLabel()}`;
room.label.material.map = drawRoomLabel(
room,
statusText,
booking ? "#237a58" : "#8a918c"
);
room.label.material.needsUpdate = true;
if (oldTexture) oldTexture.dispose();
}
}
function showToast(message, type = "") {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.className = `show ${type}`;
clearTimeout(showToast.timer);
showToast.timer = setTimeout(() => {
toast.className = type;
}, 3200);
}
function addEvent(message, type = "") {
state.events.unshift({ message, type });
state.events = state.events.slice(0, 5);
const log = document.getElementById("eventLog");
log.innerHTML = "";
for (const event of state.events) {
const item = document.createElement("div");
item.className = `event ${event.type}`;
item.textContent = event.message;
log.appendChild(item);
}
}
function denyReservation(message) {
addEvent(message, "denied");
showToast(message, "denied");
}
function reserveRoom(roomId) {
const room = roomMap.get(roomId);
const start = state.slot;
if (room.occupantOnly && state.profile === "guest") {
denyReservation(`${room.name} is occupant-only in this operational test.`);
return;
}
if (state.party > room.capacity) {
denyReservation(`${room.name} allows up to ${room.capacity} ${room.capacity === 1 ? "person" : "people"}.`);
return;
}
const sameRoom = state.bookings.filter(booking => booking.roomId === roomId);
if (sameRoom.some(booking => overlaps(booking, start, room.duration))) {
denyReservation(`${room.name} is already reserved for an overlapping time.`);
return;
}
if (room.id === "kitchen") {
const concurrentParty = sameRoom
.filter(booking => overlaps(booking, start, room.duration))
.reduce((sum, booking) => sum + booking.party, 0);
if (concurrentParty + state.party > room.capacity) {
denyReservation(`Common Table already holds ${concurrentParty}; shared capacity is ${room.capacity}.`);
return;
}
}
const booking = {
id: state.nextBookingId++,
roomId,
roomName: room.name,
start,
duration: room.duration,
slotLabel: currentSlotLabel(),
profile: state.profile,
party: state.party,
color: room.routeColor,
route: [],
overlap: 0,
delay: 0,
walkMinutes: 0
};
state.bookings.push(booking);
addEvent(
`${room.name} reserved for ${state.party} at ${currentSlotLabel()}; circulation recalculated.`,
"success"
);
showToast(`${room.name} reserved. Room state and circulation updated.`, "success");
updateUI();
recomputeSimulation();
}
document.getElementById("profileControls").addEventListener("click", event => {
const button = event.target.closest("button[data-profile]");
if (!button) return;
state.profile = button.dataset.profile;
updateUI();
});
document.getElementById("partyControls").addEventListener("click", event => {
const button = event.target.closest("button[data-party]");
if (!button) return;
state.party = Number(button.dataset.party);
updateUI();
});
document.getElementById("slotControls").addEventListener("click", event => {
const button = event.target.closest("button[data-slot]");
if (!button) return;
state.slot = Number(button.dataset.slot);
updateUI();
recomputeSimulation();
});
document.getElementById("runSimulation").addEventListener("click", () => {
recomputeSimulation();
const count = state.bookings.filter(booking => overlaps(booking, state.slot, booking.duration)).length;
showToast(count ? `${count} circulation route${count === 1 ? "" : "s"} tested.` : "No overlapping reservations at this time.");
addEvent(count ? `Circulation test completed for ${count} route${count === 1 ? "" : "s"}.` : "Circulation test completed with no active routes.");
});
document.getElementById("resetView").addEventListener("click", () => {
cameraState.azimuth = 0.62;
cameraState.elevation = 0.73;
cameraState.zoom = 1;
updateCamera();
});
const GRID = {
minX: -6.25,
maxX: 6.15,
minZ: -4.15,
maxZ: 4.15,
step: 0.35
};
GRID.nx = Math.floor((GRID.maxX - GRID.minX) / GRID.step) + 1;
GRID.nz = Math.floor((GRID.maxZ - GRID.minZ) / GRID.step) + 1;
const obstacles = [
[-2.62, -4.15, -2.38, -1.25],
[-2.62, -0.55, -2.38, 1.25],
[-2.62, 1.95, -2.38, 4.15],
[-6.75, -0.32, -2.5, -0.08],
[0.08, -4.15, 0.32, -1.7],
[0.08, -1.0, 0.32, 1.4],
[0.08, 2.2, 0.32, 4.15],
[1.05, -0.77, 4.4, -0.53],
[5.3, -0.77, 6.15, -0.53],
[3.03, -4.15, 3.27, -0.53],
[-6.15, -3.4, -4.85, -1.5],
[-6.15, 0.6, -4.85, 2.7],
[0.3, -3.5, 1.4, -2.0],
[3.0, 0.65, 4.8, 1.55]
];
const blocked = new Uint8Array(GRID.nx * GRID.nz);
function insideObstacle(x, z) {
return obstacles.some(([x1, z1, x2, z2]) => x >= x1 && x <= x2 && z >= z1 && z <= z2);
}
for (let row = 0; row < GRID.nz; row++) {
for (let col = 0; col < GRID.nx; col++) {
const x = GRID.minX + col * GRID.step;
const z = GRID.minZ + row * GRID.step;
blocked[row * GRID.nx + col] = insideObstacle(x, z) ? 1 : 0;
}
}
function nodeForPoint(x, z) {
const col = Math.max(0, Math.min(GRID.nx - 1, Math.round((x - GRID.minX) / GRID.step)));
const row = Math.max(0, Math.min(GRID.nz - 1, Math.round((z - GRID.minZ) / GRID.step)));
let index = row * GRID.nx + col;
if (blocked[index]) {
for (let radius = 1; radius < 8; radius++) {
let found = false;
for (let dr = -radius; dr <= radius; dr++) {
for (let dc = -radius; dc <= radius; dc++) {
const rr = row + dr;
const cc = col + dc;
if (rr < 0 || rr >= GRID.nz || cc < 0 || cc >= GRID.nx) continue;
const test = rr * GRID.nx + cc;
if (!blocked[test]) {
index = test;
found = true;
break;
}
}
if (found) break;
}
if (found) break;
}
}
return index;
}
function findPath(destination, congestion = new Map()) {
const startIndex = nodeForPoint(-1.2, 4.0);
const endIndex = nodeForPoint(destination[0], destination[1]);
const count = GRID.nx * GRID.nz;
const gScore = new Float64Array(count);
const fScore = new Float64Array(count);
const cameFrom = new Int32Array(count);
const closed = new Uint8Array(count);
const open = [startIndex];
gScore.fill(Infinity);
fScore.fill(Infinity);
cameFrom.fill(-1);
gScore[startIndex] = 0;
fScore[startIndex] = 0;
const endRow = Math.floor(endIndex / GRID.nx);
const endCol = endIndex % GRID.nx;
function heuristic(index) {
const row = Math.floor(index / GRID.nx);
const col = index % GRID.nx;
return Math.abs(row - endRow) + Math.abs(col - endCol);
}
while (open.length) {
let bestOpen = 0;
for (let i = 1; i < open.length; i++) {
if (fScore[open[i]] < fScore[open[bestOpen]]) bestOpen = i;
}
const current = open.splice(bestOpen, 1)[0];
if (current === endIndex) break;
if (closed[current]) continue;
closed[current] = 1;
const row = Math.floor(current / GRID.nx);
const col = current % GRID.nx;
const neighbors = [];
if (col > 0) neighbors.push(current - 1);
if (col < GRID.nx - 1) neighbors.push(current + 1);
if (row > 0) neighbors.push(current - GRID.nx);
if (row < GRID.nz - 1) neighbors.push(current + GRID.nx);
for (const next of neighbors) {
if (blocked[next] || closed[next]) continue;
const congestionWeight = 1 + (congestion.get(next) || 0) * 1.45;
const tentative = gScore[current] + congestionWeight;
if (tentative < gScore[next]) {
cameFrom[next] = current;
gScore[next] = tentative;
fScore[next] = tentative + heuristic(next);
if (!open.includes(next)) open.push(next);
}
}
}
if (startIndex !== endIndex && cameFrom[endIndex] === -1) return [];
const indices = [];
let cursor = endIndex;
while (cursor !== -1) {
indices.push(cursor);
if (cursor === startIndex) break;
cursor = cameFrom[cursor];
}
indices.reverse();
return indices.map(index => ({
x: GRID.minX + (index % GRID.nx) * GRID.step,
z: GRID.minZ + Math.floor(index / GRID.nx) * GRID.step,
index
}));
}
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeAvatars = [];
function clearRoutes() {
routeGroup.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (object.material.map) object.material.map.dispose();
object.material.dispose();
}
});
routeGroup.clear();
routeAvatars.length = 0;
}
function renderRoute(booking, route, index) {
if (!route.length) return;
const offset = ((index % 3) - 1) * 0.075;
const geometry = new THREE.BoxGeometry(0.15, 0.045, 0.15);
const material = new THREE.MeshStandardMaterial({
color: booking.color,
emissive: booking.color,
emissiveIntensity: 0.42,
roughness: 0.55
});
const mesh = new THREE.InstancedMesh(geometry, material, route.length);
const matrix = new THREE.Matrix4();
route.forEach((point, routeIndex) => {
matrix.makeTranslation(point.x + offset, 0.19, point.z);
mesh.setMatrixAt(routeIndex, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
routeGroup.add(mesh);
const end = route[route.length - 1];
box(routeGroup, 0.3, 0.08, 0.3, end.x, 0.22, end.z, booking.color);
box(routeGroup, 0.18, 0.18, 0.18, end.x, 0.34, end.z, booking.color);
const avatar = new THREE.Group();
box(avatar, 0.2, 0.35, 0.2, 0, 0.34, 0, booking.color);
box(avatar, 0.23, 0.22, 0.23, 0, 0.61, 0, 0xf2d9bd);
routeGroup.add(avatar);
const distances = [0];
let totalDistance = 0;
for (let i = 1; i < route.length; i++) {
totalDistance += Math.hypot(route[i].x - route[i - 1].x, route[i].z - route[i - 1].z);
distances.push(totalDistance);
}
routeAvatars.push({
avatar,
route,
distances,
totalDistance,
phase: index * 0.23
});
}
function recomputeSimulation() {
clearRoutes();
const active = state.bookings
.filter(booking => overlaps(booking, state.slot, booking.duration))
.sort((a, b) => a.start - b.start || a.id - b.id);
const congestion = new Map();
let totalWalk = 0;
let maxShared = 0;
active.forEach((booking, index) => {
const route = findPath(booking.room ? booking.room.destination : roomMap.get(booking.roomId).destination, congestion);
const routeKeys = new Set(route.map(point => point.index));
let overlap = 0;
for (const key of routeKeys) overlap += congestion.get(key) || 0;
overlap = Math.round(overlap / Math.max(1, Math.floor(route.length / 7)));
const distance = Math.max(0, route.length - 1) * GRID.step;
const delay = overlap * 0.16;
const walkMinutes = distance / 1.1 + delay;
booking.route = route;
booking.overlap = overlap;
booking.delay = delay;
booking.walkMinutes = walkMinutes;
for (const key of routeKeys) congestion.set(key, (congestion.get(key) || 0) + 1);
maxShared = Math.max(maxShared, overlap);
totalWalk = Math.max(totalWalk, walkMinutes);
renderRoute(booking, route, index);
});
document.getElementById("routeCount").textContent = active.length;
document.getElementById("walkTime").textContent = totalWalk ? totalWalk.toFixed(1) : "0";
document.getElementById("pinchCount").textContent = maxShared;
document.getElementById("simulationStatus").textContent = active.length ? "Active" : "No routes";
const routeList = document.getElementById("routeList");
routeList.innerHTML = "";
if (!active.length) {
const empty = document.createElement("div");
empty.className = "empty-state";
empty.textContent = "Reserve a room at this time to generate a circulation route from the entry.";
routeList.appendChild(empty);
} else {
active.forEach(booking => {
const row = document.createElement("div");
row.className = "route-row";
row.innerHTML = `
<i style="background:#${booking.color.toString(16).padStart(6, "0")}"></i>
<div>
<b>${booking.roomName}</b>
<small>${booking.slotLabel} · ${booking.party} ${booking.party === 1 ? "person" : "people"}</small>
</div>
<span>${booking.walkMinutes.toFixed(1)} min</span>
`;
routeList.appendChild(row);
});
}
}
function updateBookingList() {
const list = document.getElementById("bookingList");
list.innerHTML = "";
if (!state.bookings.length) {
const empty = document.createElement("div");
empty.className = "empty-state";
empty.textContent = "No reservations yet. Choose a profile, time, and room.";
list.appendChild(empty);
return;
}
for (const booking of state.bookings) {
const row = document.createElement("div");
row.className = "booking-row";
row.innerHTML = `
<div>
<b>${booking.roomName} · ${booking.slotLabel}</b>
<small>${booking.profile === "occupant" ? "Occupant" : "Guest"} · ${booking.party} · until ${timeLabel(booking.start + booking.duration)}</small>
</div>
<button type="button" class="release-button">Release</button>
`;
row.querySelector("button").addEventListener("click", () => {
state.bookings = state.bookings.filter(item => item.id !== booking.id);
addEvent(`${booking.roomName} reservation released; circulation recalculated.`);
updateUI();
recomputeSimulation();
});
list.appendChild(row);
}
}
function updateUI() {
document.getElementById("profileSummary").textContent =
`${state.profile === "occupant" ? "Occupant" : "Guest"} · ${state.party} ${state.party === 1 ? "person" : "people"}`;
document.getElementById("slotSummary").textContent = currentSlotLabel();
document.getElementById("bookingCount").textContent = `${state.bookings.length} total`;
document.querySelectorAll("[data-profile]").forEach(button => {
const active = button.dataset.profile === state.profile;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
document.querySelectorAll("[data-party]").forEach(button => {
const active = Number(button.dataset.party) === state.party;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
document.querySelectorAll("[data-slot]").forEach(button => {
const active = Number(button.dataset.slot) === state.slot;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
for (const room of roomDefs) {
const card = roomCards.get(room.id);
const availability = card.querySelector(".availability");
const button = card.querySelector("button");
const booking = activeBooking(room.id);
card.classList.toggle("selected", state.selectedRoom === room.id);
card.classList.toggle("reserved", Boolean(booking));
availability.textContent = booking ? "Reserved" : "Available";
availability.classList.toggle("booked", Boolean(booking));
button.textContent = booking
? `Reserved · ${booking.slotLabel}`
: `Reserve ${currentSlotLabel()}`;
button.classList.toggle("booked", Boolean(booking));
}
updateBookingList();
updateRoomVisuals();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.dataset.downX = event.clientX;
renderer.domElement.dataset.downY = event.clientY;
renderer.domElement.dataset.dragging = "false";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!renderer.domElement.hasPointerCapture(event.pointerId)) return;
const lastX = Number(renderer.domElement.dataset.lastX || event.clientX);
const lastY = Number(renderer.domElement.dataset.lastY || event.clientY);
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
const totalDx = event.clientX - Number(renderer.domElement.dataset.downX);
const totalDy = event.clientY - Number(renderer.domElement.dataset.downY);
if (Math.abs(totalDx) + Math.abs(totalDy) > 4) {
renderer.domElement.dataset.dragging = "true";
}
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(cameraState.elevation + dy * 0.004, 0.42, 1.12);
renderer.domElement.dataset.lastX = event.clientX;
renderer.domElement.dataset.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
const wasDragging = renderer.domElement.dataset.dragging === "true";
renderer.domElement.releasePointerCapture(event.pointerId);
if (!wasDragging) {
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;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(roomFloors, false);
if (hits.length) {
state.selectedRoom = hits[0].object.userData.roomId;
updateUI();
}
}
});
renderer.domElement.addEventListener("pointercancel", event => {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.65
);
updateCamera();
}, { passive: false });
addEvent("Sandbox ready. Choose a slot and reserve a room.");
updateUI();
recomputeSimulation();
let previousTime = performance.now();
function animate(now) {
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
const elapsed = now / 1000;
for (const item of routeAvatars) {
if (!item.totalDistance) continue;
let distance = (elapsed * 0.82 + item.phase) % item.totalDistance;
let segment = 0;
while (segment < item.distances.length - 1 && item.distances[segment + 1] < distance) {
segment++;
}
const a = item.route[segment];
const b = item.route[Math.min(segment + 1, item.route.length - 1)];
const segmentLength = item.distances[segment + 1] - item.distances[segment] || 1;
const ratio = THREE.MathUtils.clamp((distance - item.distances[segment]) / segmentLength, 0, 1);
item.avatar.position.set(
THREE.MathUtils.lerp(a.x, b.x, ratio),
0.12,
THREE.MathUtils.lerp(a.z, b.z, ratio)
);
item.avatar.rotation.y = Math.atan2(b.x - a.x, b.z - a.z);
}
for (const room of roomMap.values()) {
const pulse = 1 + Math.sin(elapsed * 2.6 + room.x) * 0.08;
room.beacon.scale.setScalar(pulse);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```