Prompt specification
Build or customize the Three.js 3D scene "Inclusive room layout workshop" 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: Inclusive room layout workshop
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inclusive-room-layout-workshop-x0452
Scene Description Prompt:
Arrange low-poly restroom fixtures, door, and storage; compare approach paths using geometric templates in a schematic accessibility exercise. Three.js from cdnjs, one HTML file.
Working Three.js Starter (inclusive-room-layout-workshop-x0452):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Restroom Access Lab</title>
<style>
:root {
--paper: #f2efe7;
--panel: rgba(252, 250, 245, 0.94);
--ink: #172421;
--muted: #65706c;
--line: #d8d4ca;
--teal: #147d78;
--teal-light: #d9eeea;
--orange: #e97745;
--orange-light: #f8e2d7;
--lime: #bfd36c;
--shadow: 0 16px 50px rgba(31, 42, 37, 0.13);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
#app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 68px 1fr;
}
header {
position: relative;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
background: #fbfaf6;
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.mark {
width: 34px;
height: 34px;
display: grid;
place-items: center;
flex: 0 0 auto;
color: #fff;
background: var(--ink);
border-radius: 9px;
font-weight: 900;
letter-spacing: -1px;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1.1;
letter-spacing: 0.02em;
white-space: nowrap;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.header-note {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 11px;
text-align: right;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--lime);
box-shadow: 0 0 0 4px rgba(191, 211, 108, 0.23);
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
}
#viewport {
position: absolute;
inset: 0;
touch-action: none;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
.panel {
position: absolute;
z-index: 5;
background: var(--panel);
border: 1px solid rgba(126, 129, 117, 0.25);
border-radius: 16px;
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.controls {
left: 20px;
top: 20px;
bottom: 20px;
width: 294px;
padding: 18px;
overflow: auto;
scrollbar-width: thin;
}
.eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.controls h2,
.metrics h2 {
margin: 5px 0 15px;
font-size: 19px;
letter-spacing: -0.025em;
}
.section {
padding: 15px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type {
border-top: 0;
padding-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.section-number {
color: #999b91;
font-weight: 600;
}
label.field-label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
select {
width: 100%;
height: 38px;
padding: 0 34px 0 11px;
color: var(--ink);
background: #fff;
border: 1px solid var(--line);
border-radius: 9px;
outline: none;
}
.route-list {
display: grid;
gap: 8px;
}
.route-card {
width: 100%;
padding: 11px;
text-align: left;
color: var(--ink);
background: #fff;
border: 1px solid var(--line);
border-radius: 11px;
cursor: pointer;
transition: 150ms ease;
}
.route-card:hover {
transform: translateY(-1px);
border-color: #aaa99f;
}
.route-card.active {
border-color: var(--route-color);
box-shadow: inset 0 0 0 1px var(--route-color);
background: var(--route-bg);
}
.route-head {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 850;
}
.route-swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--route-color);
}
.route-card small {
display: block;
margin: 6px 0 0 18px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.range-row {
margin-top: 12px;
}
.range-label {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
color: var(--muted);
font-size: 11px;
}
.range-label output {
color: var(--ink);
font-weight: 800;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 4px 0;
accent-color: var(--teal);
cursor: pointer;
}
.toggle-grid {
display: grid;
gap: 8px;
}
.toggle {
display: flex;
align-items: center;
gap: 9px;
color: #48514d;
font-size: 11px;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: var(--teal);
}
.metrics {
right: 20px;
top: 20px;
width: 270px;
padding: 18px;
}
.comparison-summary {
margin: 0 0 15px;
padding: 12px;
color: #4e5854;
background: #eeeee8;
border-radius: 10px;
font-size: 11px;
line-height: 1.55;
}
.metric-route {
margin-top: 10px;
padding: 12px;
background: #fff;
border: 1px solid var(--line);
border-radius: 11px;
}
.metric-route-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
}
.metric-route-name {
display: flex;
align-items: center;
gap: 7px;
font-size: 11px;
font-weight: 850;
}
.badge {
padding: 4px 7px;
border-radius: 20px;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.badge.clear {
color: #23635b;
background: var(--teal-light);
}
.badge.conflict {
color: #99411f;
background: var(--orange-light);
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.metric-grid div {
min-width: 0;
}
.metric-grid span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.metric-grid strong {
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.legend {
position: absolute;
z-index: 4;
left: 332px;
bottom: 78px;
display: flex;
flex-wrap: wrap;
gap: 12px;
padding: 9px 12px;
background: rgba(252, 250, 245, 0.86);
border: 1px solid rgba(126, 129, 117, 0.22);
border-radius: 10px;
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(8px);
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 9px;
height: 9px;
border-radius: 50%;
}
.toolbar {
position: absolute;
z-index: 5;
left: 50%;
bottom: 20px;
display: flex;
align-items: center;
gap: 5px;
padding: 6px;
transform: translateX(-50%);
background: rgba(252, 250, 245, 0.94);
border: 1px solid rgba(126, 129, 117, 0.25);
border-radius: 12px;
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
.toolbar button {
height: 34px;
padding: 0 12px;
color: #4c5651;
background: transparent;
border: 0;
border-radius: 8px;
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.toolbar button:hover {
color: var(--ink);
background: #ece9e0;
}
.toolbar .primary {
color: #fff;
background: var(--ink);
}
.toolbar .primary:hover {
color: #fff;
background: #2c3d37;
}
.toolbar .divider {
width: 1px;
height: 22px;
margin: 0 3px;
background: var(--line);
}
.hint {
position: absolute;
right: 20px;
bottom: 20px;
z-index: 3;
color: #7b817d;
font-size: 9px;
letter-spacing: 0.03em;
text-align: right;
line-height: 1.5;
}
@media (max-width: 1000px) {
.metrics {
top: auto;
bottom: 78px;
width: 250px;
}
.legend {
display: none;
}
.hint {
display: none;
}
}
@media (max-width: 720px) {
#app {
grid-template-rows: 58px 1fr;
}
header {
padding: 0 14px;
}
.brand p,
.header-note {
display: none;
}
.controls {
left: 10px;
top: 10px;
bottom: 64px;
width: min(270px, calc(100vw - 20px));
padding: 14px;
}
.controls.collapsed {
display: none;
}
.metrics {
display: none;
}
.toolbar {
bottom: 10px;
white-space: nowrap;
}
.toolbar button {
padding: 0 8px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="mark">RA</div>
<div>
<h1>RESTROOM / ACCESS LAB</h1>
<p>Geometric approach-path study</p>
</div>
</div>
<div class="header-note">
<span class="status-dot"></span>
<span>Schematic exercise · verify all dimensions with local codes</span>
</div>
</header>
<main id="stage">
<div id="viewport"></div>
<aside class="panel controls" id="controlsPanel">
<div class="eyebrow">Spatial exercise</div>
<h2>Test the approach</h2>
<section class="section">
<div class="section-title">
<span>Arrange fixtures</span>
<span class="section-number">01</span>
</div>
<label class="field-label" for="layout">Storage island position</label>
<select id="layout">
<option value="balanced">Balanced — central pinch point</option>
<option value="tight">Tighter — left of center</option>
<option value="open">Open — shifted to the right</option>
</select>
</section>
<section class="section">
<div class="section-title">
<span>Compare paths</span>
<span class="section-number">02</span>
</div>
<div class="route-list">
<button
class="route-card active"
id="routeCardA"
data-route="A"
style="--route-color: var(--orange); --route-bg: #fff8f3;"
>
<span class="route-head">
<i class="route-swatch"></i>
A · Direct centerline
</span>
<small>Shortest approach with a compact turning template.</small>
</button>
<button
class="route-card"
id="routeCardB"
data-route="B"
style="--route-color: var(--teal); --route-bg: #f4fbf9;"
>
<span class="route-head">
<i class="route-swatch"></i>
B · Offset / full turn
</span>
<small>Longer offset route using a wider corridor and 1.50 m turn.</small>
</button>
</div>
<div class="range-row">
<div class="range-label">
<span>Route A corridor</span>
<output id="widthAOut">0.80 m</output>
</div>
<input id="widthA" type="range" min="0.60" max="1.30" step="0.05" value="0.80">
</div>
<div class="range-row">
<div class="range-label">
<span>Route B corridor</span>
<output id="widthBOut">1.20 m</output>
</div>
<input id="widthB" type="range" min="0.90" max="1.60" step="0.05" value="1.20">
</div>
</section>
<section class="section">
<div class="section-title">
<span>Templates + overlays</span>
<span class="section-number">03</span>
</div>
<div class="toggle-grid">
<label class="toggle">
<input id="showZones" type="checkbox" checked>
Access clearance templates
</label>
<label class="toggle">
<input id="showDims" type="checkbox" checked>
Room dimensions
</label>
<label class="toggle">
<input id="showDoor" type="checkbox" checked>
Door swing envelope
</label>
<label class="toggle">
<input id="showA" type="checkbox" checked>
Route A geometry
</label>
<label class="toggle">
<input id="showB" type="checkbox" checked>
Route B geometry
</label>
</div>
</section>
<section class="section">
<div class="section-title">
<span>Door condition</span>
<span class="section-number">04</span>
</div>
<div class="range-row">
<div class="range-label">
<span>Inward opening</span>
<output id="doorOut">75°</output>
</div>
<input id="doorAngle" type="range" min="15" max="100" step="1" value="75">
</div>
</section>
</aside>
<aside class="panel metrics">
<div class="eyebrow">Live comparison</div>
<h2>Path metrics</h2>
<p class="comparison-summary" id="comparisonSummary"></p>
<div class="metric-route">
<div class="metric-route-head">
<div class="metric-route-name">
<i class="route-swatch" style="background: var(--orange)"></i>
Route A · Direct
</div>
<span id="badgeA" class="badge conflict">Conflict</span>
</div>
<div class="metric-grid">
<div><span>Length</span><strong id="lengthA">—</strong></div>
<div><span>Corridor</span><strong id="corridorA">—</strong></div>
<div><span>Cabinet gap</span><strong id="gapA">—</strong></div>
<div><span>Turning Ø</span><strong>1.00 m</strong></div>
</div>
</div>
<div class="metric-route">
<div class="metric-route-head">
<div class="metric-route-name">
<i class="route-swatch" style="background: var(--teal)"></i>
Route B · Offset
</div>
<span id="badgeB" class="badge clear">Clear</span>
</div>
<div class="metric-grid">
<div><span>Length</span><strong id="lengthB">—</strong></div>
<div><span>Corridor</span><strong id="corridorB">—</strong></div>
<div><span>Cabinet gap</span><strong id="gapB">—</strong></div>
<div><span>Turning Ø</span><strong>1.50 m</strong></div>
</div>
</div>
</aside>
<div class="legend">
<span><i style="background:#e97745"></i>Direct route</span>
<span><i style="background:#147d78"></i>Offset route</span>
<span><i style="background:#bfd36c"></i>Transfer bay</span>
<span><i style="background:#9d8ed1"></i>Turning circle</span>
</div>
<div class="toolbar">
<button id="isoView">Isometric</button>
<button id="topView">Plan</button>
<button id="resetView">Reset</button>
<div class="divider"></div>
<button id="walkRoute" class="primary">Walk route A</button>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom<br>
Plan dimensions in meters
</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and camera
// ---------------------------------------------------------------------
const viewport = document.querySelector("#viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf0ede5);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
viewport.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-7, 7, 4.5, -4.5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.15, 0);
const cameraState = {
yaw: 0.69,
polar: 0.83,
zoom: 1.08
};
const hemi = new THREE.HemisphereLight(0xfff9ec, 0x82918b, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff5df, 3.2);
sun.position.set(-4, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcbe3df, 1.1);
fill.position.set(6, 4, -6);
scene.add(fill);
function updateCamera() {
const radius = 14;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(cameraState.yaw),
cameraTarget.y + radius * Math.cos(cameraState.polar),
cameraTarget.z + radius * sinPolar * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
const aspect = width / height;
const viewHeight = aspect < 1 ? 9.4 : 8.1;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
resize();
// Direct camera controls: orbit, zoom and plan/isometric presets.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.007;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.005,
0.035,
1.36
);
updateCamera();
});
const stopDrag = () => { dragging = false; };
renderer.domElement.addEventListener("pointerup", stopDrag);
renderer.domElement.addEventListener("pointercancel", stopDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.2
);
updateCamera();
}, { passive: false });
document.querySelector("#isoView").onclick = () => {
cameraState.yaw = 0.69;
cameraState.polar = 0.83;
cameraState.zoom = 1.08;
updateCamera();
};
document.querySelector("#topView").onclick = () => {
cameraState.yaw = 0;
cameraState.polar = 0.035;
cameraState.zoom = 1.02;
updateCamera();
};
document.querySelector("#resetView").onclick = () => {
cameraTarget.set(0, 0.15, 0);
cameraState.yaw = 0.69;
cameraState.polar = 0.83;
cameraState.zoom = 1.08;
updateCamera();
};
// ---------------------------------------------------------------------
// Shared helpers
// ---------------------------------------------------------------------
const room = { width: 7.2, depth: 5.4 };
const storageState = { x: 0.75, z: 0.55 };
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
floor: material(0xe8e4da),
wall: material(0xd3d7ce),
wallCap: material(0xbec6bc),
white: material(0xf6f4ec),
porcelain: material(0xe8eee9, { roughness: 0.38 }),
teal: material(0x497f78),
tealDark: material(0x315d59),
wood: material(0xbd9368),
woodDark: material(0x8c694c),
metal: material(0x87928f, { metalness: 0.7, roughness: 0.28 }),
black: material(0x26322e),
orange: material(0xe97745),
purple: material(0x9d8ed1),
lime: material(0xbfd36c)
};
function box(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, mat) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 8),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, options = {}) {
const {
color = "#273630",
background = "rgba(251,249,242,0.92)",
border = "rgba(50,65,58,0.22)",
scale = 0.095
} = options;
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
const font = "700 38px system-ui, sans-serif";
context.font = font;
const width = Math.ceil(context.measureText(text).width + 44);
const height = 72;
canvas.width = width;
canvas.height = height;
context.clearRect(0, 0, width, height);
context.fillStyle = background;
context.strokeStyle = border;
context.lineWidth = 3;
context.beginPath();
context.roundRect(2, 2, width - 4, height - 4, 13);
context.fill();
context.stroke();
context.font = font;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = color;
context.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width * scale / 38, height * scale / 38, 1);
sprite.renderOrder = 30;
return sprite;
}
function disposeObject(object) {
object.traverse((child) => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const list = Array.isArray(child.material)
? child.material
: [child.material];
list.forEach((mat) => {
if (mat.map) mat.map.dispose();
mat.dispose();
});
}
});
}
// ---------------------------------------------------------------------
// Room shell and low-poly fixtures
// ---------------------------------------------------------------------
const roomGroup = new THREE.Group();
scene.add(roomGroup);
box(
roomGroup,
[room.width, 0.12, room.depth],
[0, -0.075, 0],
materials.floor,
false
);
const gridPoints = [];
for (let x = -3.5; x <= 3.5; x += 0.5) {
gridPoints.push(x, 0.012, -2.7, x, 0.012, 2.7);
}
for (let z = -2.5; z <= 2.5; z += 0.5) {
gridPoints.push(-3.6, 0.012, z, 3.6, 0.012, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPoints, 3)
);
roomGroup.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0xc9c8bf,
transparent: true,
opacity: 0.42
})
));
// Cutaway walls.
box(
roomGroup,
[room.width, 0.55, 0.12],
[0, 0.275, -2.7],
materials.wall
);
box(
roomGroup,
[0.12, 0.55, room.depth],
[-3.6, 0.275, 0],
materials.wall
);
box(
roomGroup,
[0.12, 0.55, room.depth],
[3.6, 0.275, 0],
materials.wall
);
// Front wall is interrupted by the entry.
const doorHingeX = 1.85;
const doorWidth = 1.10;
const doorZ = 2.68;
box(
roomGroup,
[doorHingeX + 3.6, 0.32, 0.12],
[(doorHingeX - 3.6) / 2, 0.16, 2.7],
materials.wall
);
box(
roomGroup,
[3.6 - (doorHingeX + doorWidth), 0.32, 0.12],
[(3.6 + doorHingeX + doorWidth) / 2, 0.16, 2.7],
materials.wall
);
// Toilet.
const toilet = new THREE.Group();
toilet.position.set(-2.25, 0, -1.78);
scene.add(toilet);
box(toilet, [0.42, 0.38, 0.52], [0, 0.19, 0.10], materials.porcelain);
box(toilet, [0.58, 0.52, 0.25], [0, 0.51, -0.37], materials.white);
box(toilet, [0.48, 0.22, 0.38], [0, 0.42, 0.04], materials.porcelain);
const bowl = new THREE.Mesh(
new THREE.CylinderGeometry(0.30, 0.24, 0.22, 10),
materials.porcelain
);
bowl.position.set(0, 0.55, 0.08);
bowl.castShadow = true;
toilet.add(bowl);
const seat = new THREE.Mesh(
new THREE.TorusGeometry(0.245, 0.052, 6, 14),
materials.white
);
seat.rotation.x = Math.PI / 2;
seat.scale.z = 1.18;
seat.position.set(0, 0.68, 0.08);
seat.castShadow = true;
toilet.add(seat);
box(toilet, [0.11, 0.03, 0.03], [0, 0.79, -0.27], materials.metal);
// Grab bars.
cylinderBetween(toilet, [-0.46, 0.77, -0.38], [-0.46, 0.77, 0.42], 0.025, materials.metal);
cylinderBetween(toilet, [-0.46, 0.38, 0.42], [-0.46, 0.77, 0.42], 0.025, materials.metal);
cylinderBetween(toilet, [-0.46, 0.77, -0.38], [0.46, 0.77, -0.38], 0.025, materials.metal);
const toiletLabel = makeLabel("TOILET", {
scale: 0.072,
color: "#31443e",
background: "rgba(247,246,239,0.88)"
});
toiletLabel.position.set(0, 1.18, -0.2);
toilet.add(toiletLabel);
// Sink and vanity.
const sink = new THREE.Group();
sink.position.set(2.18, 0, -1.87);
scene.add(sink);
box(sink, [0.88, 0.74, 0.57], [0, 0.37, 0], materials.tealDark);
box(sink, [0.96, 0.10, 0.65], [0, 0.79, 0], materials.white);
const basin = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.27, 0.16, 10),
materials.porcelain
);
basin.position.set(0, 0.89, 0.03);
basin.scale.z = 0.72;
basin.castShadow = true;
sink.add(basin);
const basinInset = new THREE.Mesh(
new THREE.CylinderGeometry(0.245, 0.245, 0.012, 10),
material(0x7d918a, { roughness: 0.55 })
);
basinInset.position.set(0, 0.978, 0.03);
basinInset.scale.z = 0.72;
sink.add(basinInset);
cylinderBetween(sink, [0, 0.83, -0.22], [0, 1.17, -0.22], 0.025, materials.metal);
cylinderBetween(sink, [0, 1.17, -0.22], [0, 1.17, -0.04], 0.025, materials.metal);
box(sink, [0.30, 0.025, 0.025], [0, 1.17, 0.01], materials.metal);
const sinkLabel = makeLabel("BASIN", {
scale: 0.072,
color: "#2d514a"
});
sinkLabel.position.set(0, 1.47, 0);
sink.add(sinkLabel);
// Storage island / cabinet.
const storage = new THREE.Group();
scene.add(storage);
box(storage, [1.50, 1.35, 0.08], [0, 0.675, -0.28], materials.wood);
box(storage, [0.08, 1.35, 0.64], [-0.71, 0.675, 0], materials.woodDark);
box(storage, [0.08, 1.35, 0.64], [0.71, 0.675, 0], materials.woodDark);
box(storage, [1.50, 0.08, 0.64], [0, 1.31, 0], materials.wood);
box(storage, [1.50, 0.08, 0.64], [0, 0.08, 0], materials.wood);
box(storage, [1.38, 0.06, 0.56], [0, 0.61, 0], materials.wood);
box(storage, [0.36, 0.22, 0.34], [-0.31, 0.79, 0], materials.teal);
box(storage, [0.34, 0.24, 0.31], [0.24, 0.79, -0.02], material(0xc7b48e));
const storageDoorPivot = new THREE.Group();
storageDoorPivot.position.set(-0.71, 0, 0.34);
storageDoorPivot.rotation.y = -0.58;
storage.add(storageDoorPivot);
box(storageDoorPivot, [0.68, 1.20, 0.07], [0.34, 0.60, 0], materials.wood);
box(storageDoorPivot, [0.035, 0.22, 0.035], [0.59, 0.65, 0.05], materials.metal);
const storageLabel = makeLabel("STORAGE", {
scale: 0.075,
color: "#61482f",
background: "rgba(250,241,224,0.92)"
});
storageLabel.position.set(0, 1.59, 0);
storage.add(storageLabel);
function positionStorage() {
storage.position.set(storageState.x, 0, storageState.z);
}
positionStorage();
// Entry door.
const entryDoor = new THREE.Group();
entryDoor.position.set(doorHingeX, 0, doorZ);
scene.add(entryDoor);
box(entryDoor, [doorWidth, 1.72, 0.065], [doorWidth / 2, 0.86, 0], materials.wood);
box(entryDoor, [0.035, 0.18, 0.04], [doorWidth - 0.14, 0.90, 0.055], materials.metal);
box(roomGroup, [0.075, 1.95, 0.12], [doorHingeX, 0.975, doorZ], materials.wallCap);
box(roomGroup, [0.075, 1.95, 0.12], [doorHingeX + doorWidth, 0.975, doorZ], materials.wallCap);
box(roomGroup, [doorWidth + 0.15, 0.075, 0.12], [doorHingeX + doorWidth / 2, 1.95, doorZ], materials.wallCap);
const entryLabel = makeLabel("ENTRY", {
scale: 0.07,
color: "#315b55"
});
entryLabel.position.set(doorHingeX + 0.56, 2.18, doorZ);
roomGroup.add(entryLabel);
// ---------------------------------------------------------------------
// Door swing
// ---------------------------------------------------------------------
const doorSwingGroup = new THREE.Group();
scene.add(doorSwingGroup);
let doorSwingFill = null;
let doorSwingOutline = null;
function updateDoorSwing(angleDegrees) {
entryDoor.rotation.y = THREE.MathUtils.degToRad(angleDegrees);
document.querySelector("#doorOut").value = `${angleDegrees}°`;
if (doorSwingFill) {
disposeObject(doorSwingFill);
doorSwingGroup.remove(doorSwingFill);
}
if (doorSwingOutline) {
disposeObject(doorSwingOutline);
doorSwingGroup.remove(doorSwingOutline);
}
const shape = new THREE.Shape();
const radius = doorWidth;
shape.moveTo(0, 0);
const steps = 40;
for (let i = 0; i <= steps; i++) {
const angle = (i / steps) * THREE.MathUtils.degToRad(angleDegrees);
shape.lineTo(
Math.cos(angle) * radius,
Math.sin(angle) * radius
);
}
shape.closePath();
doorSwingFill = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
new THREE.MeshBasicMaterial({
color: 0x789b91,
transparent: true,
opacity: 0.13,
depthWrite: false,
side: THREE.DoubleSide
})
);
doorSwingFill.rotation.x = -Math.PI / 2;
doorSwingFill.position.set(doorHingeX, 0.029, doorZ);
doorSwingGroup.add(doorSwingFill);
const points = [];
for (let i = 0; i <= steps; i++) {
const angle = (i / steps) * THREE.MathUtils.degToRad(angleDegrees);
points.push(
new THREE.Vector3(
doorHingeX + Math.cos(angle) * radius,
0.043,
doorZ - Math.sin(angle) * radius
)
);
}
doorSwingOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color: 0x4d766e,
dashSize: 0.11,
gapSize: 0.07,
transparent: true,
opacity: 0.85
})
);
doorSwingOutline.computeLineDistances();
doorSwingGroup.add(doorSwingOutline);
}
// ---------------------------------------------------------------------
// Access clearance templates
// ---------------------------------------------------------------------
const zoneGroup = new THREE.Group();
scene.add(zoneGroup);
function addRectangleZone(width, depth, x, z, color, label, labelOffset = [0, 0.19, 0]) {
const group = new THREE.Group();
const fill = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.10,
depthWrite: false,
side: THREE.DoubleSide
})
);
fill.rotation.x = -Math.PI / 2;
fill.position.set(x, 0.026, z);
group.add(fill);
const points = [
new THREE.Vector3(x - width / 2, 0.045, z - depth / 2),
new THREE.Vector3(x + width / 2, 0.045, z - depth / 2),
new THREE.Vector3(x + width / 2, 0.045, z + depth / 2),
new THREE.Vector3(x - width / 2, 0.045, z + depth / 2)
];
const outline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color,
dashSize: 0.10,
gapSize: 0.065,
transparent: true,
opacity: 0.9
})
);
outline.computeLineDistances();
group.add(outline);
const text = makeLabel(label, {
color: `#${new THREE.Color(color).getHexString()}`,
scale: 0.060
});
text.position.set(
x + labelOffset[0],
labelOffset[1],
z + labelOffset[2]
);
group.add(text);
zoneGroup.add(group);
return group;
}
addRectangleZone(
0.90, 1.30, -3.08, -1.16, 0x91aa45,
"0.90 × 1.30 TRANSFER", [0, 0.20, 0]
);
addRectangleZone(
0.90, 1.20, 2.18, -0.92, 0x5b9d92,
"BASIN APPROACH", [0, 0.18, 0]
);
addRectangleZone(
1.10, 1.50, 2.40, 1.88, 0xbca15f,
"ENTRY APPROACH", [0, 0.17, 0]
);
// ---------------------------------------------------------------------
// Room dimensions
// ---------------------------------------------------------------------
const dimensionGroup = new THREE.Group();
scene.add(dimensionGroup);
function addDimension(a, b, tickDirection, text) {
const points = [
new THREE.Vector3(a[0], 0.035, a[1]),
new THREE.Vector3(b[0], 0.035, b[1])
];
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0x65716c,
transparent: true,
opacity: 0.65
})
);
dimensionGroup.add(line);
[a, b].forEach((point) => {
const p1 = new THREE.Vector3(
point[0] - tickDirection[0] * 0.12,
0.035,
point[1] - tickDirection[1] * 0.12
);
const p2 = new THREE.Vector3(
point[0] + tickDirection[0] * 0.12,
0.035,
point[1] + tickDirection[1] * 0.12
);
const tick = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([p1, p2]),
new THREE.LineBasicMaterial({ color: 0x65716c })
);
dimensionGroup.add(tick);
});
const label = makeLabel(text, {
scale: 0.063,
color: "#4b5752",
background: "rgba(241,238,229,0.90)"
});
label.position.set((a[0] + b[0]) / 2, 0.24, (a[1] + b[1]) / 2);
dimensionGroup.add(label);
}
addDimension([-3.6, 3.05], [3.6, 3.05], [0, 1], "7.20 m");
addDimension([3.95, -2.7], [3.95, 2.7], [1, 0], "5.40 m");
// ---------------------------------------------------------------------
// Route geometry and geometric calculations
// ---------------------------------------------------------------------
const routeColors = {
A: 0xe97745,
B: 0x147d78
};
const routeGroups = {
A: new THREE.Group(),
B: new THREE.Group()
};
scene.add(routeGroups.A, routeGroups.B);
const routeData = {
A: [],
B: []
};
function rebuildRouteDefinitions() {
routeData.A = [
new THREE.Vector2(2.45, 2.43),
new THREE.Vector2(-2.25, -0.30)
];
const bypassX = storageState.x > 1.5 ? 1.05 : storageState.x - 0.95;
const bypassZ = storageState.x > 1.5 ? 1.70 : 1.55;
routeData.B = [
new THREE.Vector2(2.45, 2.43),
new THREE.Vector2(2.58, bypassZ),
new THREE.Vector2(bypassX, bypassZ),
new THREE.Vector2(-1.25, 1.03),
new THREE.Vector2(-2.25, -0.30)
];
}
function pathLength(points) {
let total = 0;
for (let i = 1; i < points.length; i++) {
total += points[i].distanceTo(points[i - 1]);
}
return total;
}
function pointSegmentDistance(px, pz, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const lengthSquared = dx * dx + dz * dz;
if (lengthSquared === 0) {
return Math.hypot(px - ax, pz - az);
}
let t = ((px - ax) * dx + (pz - az) * dz) / lengthSquared;
t = THREE.MathUtils.clamp(t, 0, 1);
return Math.hypot(
px - (ax + t * dx),
pz - (az + t * dz)
);
}
function pointInsideRect(x, z, rect) {
return x >= rect.minX && x <= rect.maxX &&
z >= rect.minZ && z <= rect.maxZ;
}
function segmentRectDistance(a, b, rect) {
const edges = [
[rect.minX, rect.minZ, rect.maxX, rect.minZ],
[rect.maxX, rect.minZ, rect.maxX, rect.maxZ],
[rect.maxX, rect.maxZ, rect.minX, rect.maxZ],
[rect.minX, rect.maxZ, rect.minX, rect.minZ]
];
let minimum = Infinity;
const samples = 100;
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const x = THREE.MathUtils.lerp(a.x, b.x, t);
const z = THREE.MathUtils.lerp(a.y, b.y, t);
if (pointInsideRect(x, z, rect)) return 0;
for (const edge of edges) {
minimum = Math.min(
minimum,
pointSegmentDistance(
x, z,
edge[0], edge[1],
edge[2], edge[3]
)
);
}
}
return minimum;
}
function routeObstacleClearance(points) {
const rect = {
minX: storageState.x - 0.75,
maxX: storageState.x + 0.75,
minZ: storageState.z - 0.32,
maxZ: storageState.z + 0.32
};
let minimum = Infinity;
for (let i = 1; i < points.length; i++) {
minimum = Math.min(
minimum,
segmentRectDistance(points[i - 1], points[i], rect)
);
}
return minimum;
}
function addRouteCircle(group, center, diameter, color, labelText, y) {
const fill = new THREE.Mesh(
new THREE.CircleGeometry(diameter / 2, 48),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.055,
depthWrite: false,
side: THREE.DoubleSide
})
);
fill.rotation.x = -Math.PI / 2;
fill.position.set(center.x, y, center.y);
group.add(fill);
const points = [];
for (let i = 0; i < 64; i++) {
const angle = (i / 64) * Math.PI * 2;
points.push(new THREE.Vector3(
center.x + Math.cos(angle) * diameter / 2,
y + 0.015,
center.y + Math.sin(angle) * diameter / 2
));
}
const outline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color,
dashSize: 0.12,
gapSize: 0.07,
transparent: true,
opacity: 0.9
})
);
outline.computeLineDistances();
group.add(outline);
const label = makeLabel(labelText, {
color: `#${new THREE.Color(color).getHexString()}`,
scale: 0.055,
background: "rgba(251,249,243,0.90)"
});
label.position.set(center.x - 0.02, 0.20, center.y - diameter / 2 - 0.06);
group.add(label);
}
function createRouteVisual(route, width, color, diameter) {
const old = routeGroups[route];
while (old.children.length) {
const child = old.children[0];
disposeObject(child);
old.remove(child);
}
const points = routeData[route];
const y = route === "A" ? 0.043 : 0.055;
const ribbonMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: route === "A" ? 0.16 : 0.13,
depthWrite: false,
side: THREE.DoubleSide
});
const borderMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.75
});
for (let i = 1; i < points.length; i++) {
const a = points[i - 1];
const b = points[i];
const dx = b.x - a.x;
const dz = b.y - a.y;
const length = Math.hypot(dx, dz);
const segment = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.014, width),
ribbonMaterial
);
segment.position.set((a.x + b.x) / 2, y, (a.y + b.y) / 2);
segment.rotation.y = -Math.atan2(dz, dx);
segment.renderOrder = 2;
old.add(segment);
const normalX = -dz / length;
const normalZ = dx / length;
const half = width / 2;
for (const side of [-1, 1]) {
const border = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
a.x + normalX * half * side,
y + 0.013,
a.y + normalZ * half * side
),
new THREE.Vector3(
b.x + normalX * half * side,
y + 0.013,
b.y + normalZ * half * side
)
]),
borderMaterial
);
old.add(border);
}
// Direction arrow.
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.27, 3),
new THREE.MeshBasicMaterial({ color })
);
arrow.position.set(
THREE.MathUtils.lerp(a.x, b.x, 0.64),
y + 0.045,
THREE.MathUtils.lerp(a.y, b.y, 0.64)
);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(dx, 0, dz).normalize()
);
old.add(arrow);
}
const centerLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(point.x, y + 0.026, point.y))
),
new THREE.LineDashedMaterial({
color,
dashSize: 0.18,
gapSize: 0.11,
transparent: true,
opacity: 0.95
})
);
centerLine.computeLineDistances();
old.add(centerLine);
const end = points[points.length - 1];
addRouteCircle(
old,
end,
diameter,
color,
`${route} · Ø ${diameter.toFixed(2)}`,
y + 0.007
);
old.visible = document.querySelector(`#show${route}`).checked;
}
// ---------------------------------------------------------------------
// Metrics and route controls
// ---------------------------------------------------------------------
const widthAInput = document.querySelector("#widthA");
const widthBInput = document.querySelector("#widthB");
let activeRoute = "A";
let walking = false;
let walkProgress = 0;
function updateMetrics() {
const result = {};
for (const route of ["A", "B"]) {
const width = route === "A"
? Number(widthAInput.value)
: Number(widthBInput.value);
const centerToCabinet = routeObstacleClearance(routeData[route]);
const signedClearance = centerToCabinet - width / 2;
result[route] = {
length: pathLength(routeData[route]),
width,
signedClearance
};
document.querySelector(`#length${route}`).textContent =
`${result[route].length.toFixed(2)} m`;
document.querySelector(`#corridor${route}`).textContent =
`${width.toFixed(2)} m`;
const gapElement = document.querySelector(`#gap${route}`);
const badge = document.querySelector(`#badge${route}`);
if (signedClearance < -0.005) {
gapElement.textContent = `${Math.abs(signedClearance).toFixed(2)} m in`;
badge.textContent = "Conflict";
badge.className = "badge conflict";
} else {
gapElement.textContent = `${signedClearance.toFixed(2)} m`;
badge.textContent = "Clear";
badge.className = "badge clear";
}
}
const lengthDifference = result.B.length - result.A.length;
const summary = document.querySelector("#comparisonSummary");
if (result.A.signedClearance < 0) {
summary.innerHTML =
`<strong>Route A is ${lengthDifference.toFixed(2)} m shorter</strong>, ` +
`but its corridor enters the storage footprint by ` +
`${Math.abs(result.A.signedClearance).toFixed(2)} m. ` +
`Route B keeps a ${result.B.signedClearance.toFixed(2)} m buffer.`;
} else {
summary.innerHTML =
`<strong>Route A is ${lengthDifference.toFixed(2)} m shorter</strong> ` +
`and clears the storage footprint by ` +
`${result.A.signedClearance.toFixed(2)} m in this arrangement.`;
}
}
function rebuildRoutes() {
rebuildRouteDefinitions();
createRouteVisual("A", Number(widthAInput.value), routeColors.A, 1.0);
createRouteVisual("B", Number(widthBInput.value), routeColors.B, 1.5);
updateMetrics();
}
widthAInput.addEventListener("input", () => {
document.querySelector("#widthAOut").value =
`${Number(widthAInput.value).toFixed(2)} m`;
rebuildRoutes();
});
widthBInput.addEventListener("input", () => {
document.querySelector("#widthBOut").value =
`${Number(widthBInput.value).toFixed(2)} m`;
rebuildRoutes();
});
document.querySelector("#layout").addEventListener("change", (event) => {
const layouts = {
tight: { x: 0.25, z: 0.55 },
balanced: { x: 0.75, z: 0.55 },
open: { x: 2.05, z: 0.55 }
};
storageState.x = layouts[event.target.value].x;
storageState.z = layouts[event.target.value].z;
positionStorage();
rebuildRoutes();
});
document.querySelector("#showA").addEventListener("change", (event) => {
routeGroups.A.visible = event.target.checked;
});
document.querySelector("#showB").addEventListener("change", (event) => {
routeGroups.B.visible = event.target.checked;
});
document.querySelector("#showZones").addEventListener("change", (event) => {
zoneGroup.visible = event.target.checked;
});
document.querySelector("#showDims").addEventListener("change", (event) => {
dimensionGroup.visible = event.target.checked;
});
document.querySelector("#showDoor").addEventListener("change", (event) => {
doorSwingGroup.visible = event.target.checked;
});
document.querySelector("#doorAngle").addEventListener("input", (event) => {
updateDoorSwing(Number(event.target.value));
});
function setActiveRoute(route, startWalking = false) {
activeRoute = route;
document.querySelectorAll(".route-card").forEach((card) => {
card.classList.toggle("active", card.dataset.route === route);
});
document.querySelector("#walkRoute").textContent = `Walk route ${route}`;
if (startWalking) {
walking = true;
walkProgress = 0;
}
}
document.querySelectorAll(".route-card").forEach((card) => {
card.addEventListener("click", () => setActiveRoute(card.dataset.route, true));
});
document.querySelector("#walkRoute").addEventListener("click", () => {
walking = !walking;
if (walking) walkProgress = 0;
});
// ---------------------------------------------------------------------
// Walking marker
// ---------------------------------------------------------------------
const walker = new THREE.Group();
scene.add(walker);
const walkerBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.16, 0.44, 6),
material(0xd34f71)
);
walkerBody.position.y = 0.56;
walkerBody.castShadow = true;
walker.add(walkerBody);
const walkerHead = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 8, 6),
material(0xe2b08d)
);
walkerHead.position.y = 0.91;
walkerHead.castShadow = true;
walker.add(walkerHead);
box(walker, [0.07, 0.27, 0.09], [-0.075, 0.19, 0], materials.black);
box(walker, [0.07, 0.27, 0.09], [0.075, 0.19, 0], materials.black);
const walkerRing = new THREE.Mesh(
new THREE.RingGeometry(0.18, 0.25, 20),
new THREE.MeshBasicMaterial({
color: 0xd34f71,
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide
})
);
walkerRing.rotation.x = -Math.PI / 2;
walkerRing.position.y = 0.035;
walker.add(walkerRing);
walker.visible = false;
function samplePolyline(points, progress) {
const total = pathLength(points);
let remaining = progress * total;
for (let i = 1; i < points.length; i++) {
const a = points[i - 1];
const b = points[i];
const segmentLength = a.distanceTo(b);
if (remaining <= segmentLength || i === points.length - 1) {
const t = segmentLength ? THREE.MathUtils.clamp(remaining / segmentLength, 0, 1) : 0;
return {
position: new THREE.Vector2(
THREE.MathUtils.lerp(a.x, b.x, t),
THREE.MathUtils.lerp(a.y, b.y, t)
),
direction: new THREE.Vector2(b.x - a.x, b.y - a.y).normalize()
};
}
remaining -= segmentLength;
}
return {
position: points[points.length - 1].clone(),
direction: new THREE.Vector2(1, 0)
};
}
// ---------------------------------------------------------------------
// Initial state and render loop
// ---------------------------------------------------------------------
updateDoorSwing(75);
rebuildRoutes();
updateCamera();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (walking && routeGroups[activeRoute].visible) {
walker.visible = true;
walkProgress = (walkProgress + delta * 0.12) % 1;
const sample = samplePolyline(routeData[activeRoute], walkProgress);
walker.position.set(
sample.position.x,
0.025 + Math.abs(Math.sin(performance.now() * 0.011)) * 0.025,
sample.position.y
);
walker.rotation.y = -Math.atan2(sample.direction.y, sample.direction.x);
} else {
walker.visible = false;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// A small-screen affordance: tap the logo to collapse the control panel.
document.querySelector(".brand").addEventListener("click", () => {
if (window.innerWidth <= 720) {
document.querySelector("#controlsPanel").classList.toggle("collapsed");
}
});
</script>
</body>
</html>
```