Prompt specification
Build or customize the Three.js 3D scene "Small apartment circulation sandbox" 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: Small apartment circulation sandbox
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-apartment-circulation-sandbox-x0236
Scene Description Prompt:
Let me move a furniture box through a low-poly apartment while swapping door types and checking clearance. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (small-apartment-circulation-sandbox-x0236):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Apartment Clearance Lab</title>
<style>
:root {
--ink: #24343a;
--muted: #718087;
--panel: rgba(250, 251, 248, 0.94);
--line: rgba(36, 52, 58, 0.13);
--green: #25866b;
--green-bg: #e2f3ec;
--amber: #b87822;
--amber-bg: #fff0d7;
--red: #c65045;
--red-bg: #fbe6e2;
--accent: #e77852;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #dfe8eb;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
button, input { font: inherit; }
#app {
position: fixed;
inset: 0;
}
.panel {
position: fixed;
top: 20px;
left: 20px;
width: 330px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 20px;
background: var(--panel);
box-shadow:
0 20px 60px rgba(40, 55, 60, 0.17),
0 2px 8px rgba(40, 55, 60, 0.08);
backdrop-filter: blur(16px);
z-index: 10;
scrollbar-width: thin;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 9px 0 19px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.section {
padding: 16px 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.1em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-size: 10px;
font-weight: 600;
letter-spacing: 0;
text-transform: none;
}
.door-options {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.door-button {
min-width: 0;
padding: 10px 5px 9px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
cursor: pointer;
transition: 150ms ease;
}
.door-button:hover {
transform: translateY(-1px);
border-color: rgba(36, 52, 58, 0.28);
}
.door-button.active {
border-color: var(--accent);
background: #fff3ed;
box-shadow: 0 0 0 2px rgba(231, 120, 82, 0.12);
}
.door-symbol {
display: block;
margin-bottom: 5px;
font-size: 18px;
line-height: 1;
}
.door-name {
display: block;
font-size: 11px;
font-weight: 750;
}
.door-width {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.dimensions {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.field label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.input-wrap {
position: relative;
}
.input-wrap input {
width: 100%;
height: 36px;
padding: 0 25px 0 9px;
border: 1px solid var(--line);
border-radius: 9px;
outline: none;
background: rgba(255, 255, 255, 0.78);
color: var(--ink);
font-size: 12px;
font-weight: 700;
}
.input-wrap input:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(231, 120, 82, 0.1);
}
.input-wrap span {
position: absolute;
top: 11px;
right: 8px;
color: var(--muted);
font-size: 9px;
pointer-events: none;
}
.orientation-row {
display: flex;
align-items: center;
gap: 11px;
margin-top: 13px;
}
.orientation-row label {
flex: 0 0 auto;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 4px;
accent-color: var(--accent);
cursor: pointer;
}
#orientationValue {
flex: 0 0 38px;
text-align: right;
color: var(--ink);
font-size: 11px;
font-weight: 750;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 10px;
}
.metric {
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.55);
}
.metric-label {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.metric-value {
font-size: 16px;
font-weight: 800;
letter-spacing: -0.02em;
}
.status {
display: flex;
gap: 10px;
align-items: flex-start;
padding: 12px;
border-radius: 12px;
transition: 160ms ease;
}
.status.good {
background: var(--green-bg);
color: var(--green);
}
.status.warn {
background: var(--amber-bg);
color: var(--amber);
}
.status.bad {
background: var(--red-bg);
color: var(--red);
}
.status-icon {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 23px;
height: 23px;
border: 1px solid currentColor;
border-radius: 50%;
font-size: 12px;
font-weight: 900;
}
.status-title {
margin-bottom: 3px;
font-size: 12px;
font-weight: 850;
}
.status-detail {
font-size: 10px;
line-height: 1.4;
opacity: 0.82;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
padding-top: 15px;
border-top: 1px solid var(--line);
}
.primary-button, .secondary-button {
height: 39px;
border-radius: 10px;
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: 150ms ease;
}
.primary-button {
border: 0;
background: var(--ink);
color: white;
box-shadow: 0 5px 14px rgba(36, 52, 58, 0.18);
}
.primary-button:hover {
transform: translateY(-1px);
background: #17272c;
}
.secondary-button {
padding: 0 13px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.7);
color: var(--ink);
}
.secondary-button:hover {
background: white;
}
.help {
margin-top: 13px;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
kbd {
display: inline-block;
min-width: 17px;
padding: 1px 4px;
border: 1px solid rgba(36, 52, 58, 0.17);
border-bottom-width: 2px;
border-radius: 4px;
background: white;
color: var(--ink);
font-family: inherit;
font-size: 8px;
font-weight: 800;
text-align: center;
}
.legend {
position: fixed;
right: 20px;
top: 20px;
z-index: 9;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
background: rgba(250, 251, 248, 0.82);
color: var(--muted);
box-shadow: 0 8px 24px rgba(40, 55, 60, 0.1);
backdrop-filter: blur(12px);
font-size: 9px;
line-height: 1.7;
}
.legend strong { color: var(--ink); }
#labels {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 4;
overflow: hidden;
}
.door-tag {
position: absolute;
min-width: 102px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 10px;
background: rgba(250, 251, 248, 0.91);
box-shadow: 0 6px 18px rgba(40, 55, 60, 0.13);
transform: translate(-50%, -50%);
text-align: center;
backdrop-filter: blur(8px);
}
.door-tag b {
display: block;
color: var(--ink);
font-size: 9px;
}
.door-tag span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.door-tag em {
display: inline-block;
margin-top: 4px;
padding: 2px 5px;
border-radius: 5px;
background: var(--green-bg);
color: var(--green);
font-size: 7px;
font-style: normal;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.door-tag em.short {
background: var(--red-bg);
color: var(--red);
}
#toast {
position: fixed;
left: 50%;
bottom: 27px;
z-index: 20;
max-width: min(460px, calc(100vw - 30px));
padding: 11px 16px;
border-radius: 11px;
background: rgba(36, 52, 58, 0.93);
color: white;
box-shadow: 0 12px 36px rgba(36, 52, 58, 0.22);
transform: translate(-50%, 18px);
opacity: 0;
pointer-events: none;
font-size: 11px;
font-weight: 700;
transition: 180ms ease;
}
#toast.visible {
transform: translate(-50%, 0);
opacity: 1;
}
@media (max-width: 720px) {
.panel {
top: 10px;
left: 10px;
width: min(310px, calc(100vw - 20px));
max-height: calc(100vh - 20px);
padding: 15px;
border-radius: 16px;
}
h1 { font-size: 21px; }
.subtitle { margin-bottom: 12px; }
.legend { display: none; }
}
</style>
</head>
<body>
<div id="app"></div>
<aside class="panel">
<div class="eyebrow">Interactive floor plan</div>
<h1>Apartment Clearance Lab</h1>
<p class="subtitle">
Move a furniture box through the apartment, compare doorway systems,
and test whether the box fits.
</p>
<section class="section">
<div class="section-title">
Door system
<span>Applied to both doors</span>
</div>
<div class="door-options">
<button class="door-button active" data-style="swing">
<span class="door-symbol">◫</span>
<span class="door-name">Swing</span>
<span class="door-width">95 cm clear</span>
</button>
<button class="door-button" data-style="sliding">
<span class="door-symbol">↔</span>
<span class="door-name">Sliding</span>
<span class="door-width">150 cm clear</span>
</button>
<button class="door-button" data-style="double">
<span class="door-symbol">⌶</span>
<span class="door-name">Double</span>
<span class="door-width">165 cm clear</span>
</button>
</div>
</section>
<section class="section">
<div class="section-title">
Furniture box
<span>Plan-view footprint</span>
</div>
<div class="dimensions">
<div class="field">
<label for="boxWidth">Width</label>
<div class="input-wrap">
<input id="boxWidth" type="number" min="40" max="180" step="1" value="105" />
<span>cm</span>
</div>
</div>
<div class="field">
<label for="boxDepth">Depth</label>
<div class="input-wrap">
<input id="boxDepth" type="number" min="35" max="150" step="1" value="72" />
<span>cm</span>
</div>
</div>
<div class="field">
<label for="boxHeight">Height</label>
<div class="input-wrap">
<input id="boxHeight" type="number" min="30" max="180" step="1" value="70" />
<span>cm</span>
</div>
</div>
</div>
<div class="orientation-row">
<label for="orientation">Rotation</label>
<input id="orientation" type="range" min="0" max="180" step="1" value="18" />
<span id="orientationValue">18°</span>
</div>
</section>
<section class="section">
<div class="section-title">
Clearance report
<span>Live calculation</span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Needed width</span>
<span class="metric-value" id="neededValue">101 cm</span>
</div>
<div class="metric">
<span class="metric-label">Door clearance</span>
<span class="metric-value" id="availableValue">95 cm</span>
</div>
</div>
<div class="status warn" id="statusBox">
<div class="status-icon" id="statusIcon">!</div>
<div>
<div class="status-title" id="statusTitle">Checking clearance</div>
<div class="status-detail" id="statusDetail">Calculating the box footprint.</div>
</div>
</div>
</section>
<div class="actions">
<button class="primary-button" id="routeButton">Run straight-route test</button>
<button class="secondary-button" id="resetButton">Reset</button>
</div>
<div class="help">
<kbd>Drag</kbd> move the box · <kbd>WASD</kbd> nudge ·
<kbd>Q</kbd>/<kbd>E</kbd> rotate<br />
<kbd>Right drag</kbd> orbit · <kbd>Middle drag</kbd> pan ·
<kbd>Wheel</kbd> zoom
</div>
</aside>
<div class="legend">
<strong>Scene guide</strong><br />
Orange line = straight test route<br />
Green = clearance · amber = tight · red = blocked
</div>
<div id="labels">
<div class="door-tag" id="doorTag0"></div>
<div class="door-tag" id="doorTag1"></div>
</div>
<div id="toast"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const DOOR_TYPES = {
swing: {
name: "Swing door",
clear: 0.95,
color: 0xe77852
},
sliding: {
name: "Sliding door",
clear: 1.50,
color: 0x4f91a6
},
double: {
name: "Double door",
clear: 1.65,
color: 0x8873a6
}
};
const DOOR_X = [-1.5, 3.5];
const DOOR_Z = 0;
const WALL_HEIGHT = 1.9;
const WALL_THICKNESS = 0.18;
const state = {
doorStyle: "swing",
width: 1.05,
depth: 0.72,
height: 0.70,
yaw: THREE.MathUtils.degToRad(18),
routeTesting: false,
routeTime: 0,
routeOverride: null,
blockedHint: null,
lastToast: 0
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe8eb);
scene.fog = new THREE.Fog(0xdfe8eb, 26, 55);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
$("app").appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const view = {
target: new THREE.Vector3(0, 0, 0),
yaw: 0.72,
pitch: 0.82,
zoom: 0.9
};
const hemisphere = new THREE.HemisphereLight(0xf8fcff, 0x829196, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e6f2, 0.8);
fill.position.set(8, 7, -10);
scene.add(fill);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e7df,
roughness: 0.88
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0xf7f6f0,
roughness: 0.75
});
const cardboardMaterial = new THREE.MeshStandardMaterial({
color: 0xc98a4d,
roughness: 0.82,
emissive: 0x000000,
emissiveIntensity: 0.25
});
const tapeMaterial = new THREE.MeshStandardMaterial({
color: 0xefd59d,
roughness: 0.7
});
const obstacleList = [];
const doorGroup = new THREE.Group();
scene.add(doorGroup);
function addMesh(geometry, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addObstacle(x, z, width, depth, yaw, label, dynamic = false) {
const obstacle = {
x,
z,
hw: width / 2,
hd: depth / 2,
yaw,
label,
dynamic
};
obstacleList.push(obstacle);
return obstacle;
}
function addWall(width, height, depth, x, z, label, dynamic = false) {
addMesh(
new THREE.BoxGeometry(width, height, depth),
wallMaterial,
x,
height / 2,
z
);
addObstacle(x, z, width, depth, 0, label, dynamic);
}
function addFurnitureBox({
x,
z,
width,
depth,
height,
color,
yaw = 0,
label = "Furniture"
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = yaw;
scene.add(group);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.82
});
addMesh(
new THREE.BoxGeometry(width, height, depth),
material,
0,
height / 2,
0,
group
);
addObstacle(x, z, width, depth, yaw, label);
return group;
}
function makeTextSprite(text, color = "#42545b") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(250,251,248,.88)";
context.beginPath();
context.roundRect(4, 4, 504, 104, 22);
context.fill();
context.fillStyle = color;
context.font = "800 30px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 58);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.3, 0.5, 1);
scene.add(sprite);
return sprite;
}
// Ground and apartment slab
const ground = addMesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({ color: 0xd6e1e3, roughness: 1 }),
0,
-0.22,
0
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
addMesh(
new THREE.BoxGeometry(14, 0.18, 9),
new THREE.MeshStandardMaterial({ color: 0xb9c2bf, roughness: 0.92 }),
0,
-0.09,
0
);
function addFloorPatch(x, z, width, depth, color) {
const patch = addMesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshStandardMaterial({ color, roughness: 0.98 }),
x,
0.006,
z
);
patch.rotation.x = -Math.PI / 2;
patch.castShadow = false;
}
addFloorPatch(-4.25, 0, 5.5, 9, 0xe8d8bd);
addFloorPatch(1.0, 0, 5.0, 9, 0xd8ded7);
addFloorPatch(5.25, 0, 3.5, 9, 0xcdd8d3);
const grid = new THREE.GridHelper(14, 28, 0x899795, 0xa7b2af);
grid.position.y = 0.014;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
// Exterior walls: lower front walls preserve the cutaway view.
addWall(14, 2.35, 0.18, 0, -4.5, "Exterior wall");
addWall(0.18, 1.35, 9, -7, 0, "Exterior wall");
addWall(0.18, 0.65, 9, 7, 0, "Exterior wall");
addWall(14, 0.38, 0.18, 0, 4.5, "Exterior wall");
// Small decorative skirting.
addMesh(
new THREE.BoxGeometry(13.7, 0.10, 0.08),
trimMaterial,
0,
0.06,
-4.38
);
// Living-room rug.
const rug = addMesh(
new THREE.BoxGeometry(3.5, 0.018, 2.6),
new THREE.MeshStandardMaterial({ color: 0xc8795f, roughness: 1 }),
-4.35,
0.028,
0.15
);
rug.castShadow = false;
const rugInner = addMesh(
new THREE.BoxGeometry(3.05, 0.021, 2.15),
new THREE.MeshStandardMaterial({ color: 0xe7b78f, roughness: 1 }),
-4.35,
0.035,
0.15
);
rugInner.castShadow = false;
// Sofa.
const sofa = new THREE.Group();
sofa.position.set(-4.55, 0, -2.75);
scene.add(sofa);
const sofaMaterial = new THREE.MeshStandardMaterial({
color: 0x718a84,
roughness: 0.9
});
addMesh(new THREE.BoxGeometry(3.0, 0.42, 1.05), sofaMaterial, 0, 0.26, 0, sofa);
addMesh(new THREE.BoxGeometry(3.0, 0.72, 0.18), sofaMaterial, 0, 0.70, -0.43, sofa);
addMesh(new THREE.BoxGeometry(0.18, 0.62, 1.05), sofaMaterial, -1.41, 0.53, 0, sofa);
addMesh(new THREE.BoxGeometry(0.18, 0.62, 1.05), sofaMaterial, 1.41, 0.53, 0, sofa);
for (let i = -1; i <= 1; i++) {
addMesh(
new THREE.BoxGeometry(0.82, 0.16, 0.72),
new THREE.MeshStandardMaterial({ color: 0x91a69f, roughness: 0.95 }),
i * 0.88,
0.53,
0.10,
sofa
);
}
addObstacle(-4.55, -2.75, 3.0, 1.05, 0, "Sofa");
// Coffee table.
const table = new THREE.Group();
table.position.set(-4.45, 0, 1.65);
scene.add(table);
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x9d7454,
roughness: 0.78
});
addMesh(new THREE.BoxGeometry(1.8, 0.13, 0.9), woodMaterial, 0, 0.55, 0, table);
for (const x of [-0.72, 0.72]) {
for (const z of [-0.32, 0.32]) {
addMesh(
new THREE.BoxGeometry(0.09, 0.5, 0.09),
woodMaterial,
x,
0.25,
z,
table
);
}
}
addObstacle(-4.45, 1.65, 1.8, 0.9, 0, "Coffee table");
// Kitchen counter.
const counter = new THREE.Group();
counter.position.set(-5.55, 0, -3.85);
scene.add(counter);
addMesh(
new THREE.BoxGeometry(2.45, 0.78, 0.62),
new THREE.MeshStandardMaterial({ color: 0x657c7c, roughness: 0.75 }),
0,
0.39,
0,
counter
);
addMesh(
new THREE.BoxGeometry(2.52, 0.08, 0.68),
new THREE.MeshStandardMaterial({ color: 0xe3dfd3, roughness: 0.62 }),
0,
0.82,
0,
counter
);
addObstacle(-5.55, -3.85, 2.45, 0.62, 0, "Kitchen counter");
// Bedroom bed.
const bed = new THREE.Group();
bed.position.set(5.2, 0, -2.15);
scene.add(bed);
const bedFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x806451,
roughness: 0.9
});
addMesh(new THREE.BoxGeometry(2.75, 0.35, 3.25), bedFrameMaterial, 0, 0.18, 0, bed);
addMesh(
new THREE.BoxGeometry(2.66, 0.30, 3.12),
new THREE.MeshStandardMaterial({ color: 0xf0eee5, roughness: 0.92 }),
0,
0.50,
0,
bed
);
addMesh(
new THREE.BoxGeometry(2.58, 0.08, 1.55),
new THREE.MeshStandardMaterial({ color: 0x819ba0, roughness: 0.9 }),
0,
0.69,
0.62,
bed
);
addMesh(
new THREE.BoxGeometry(1.05, 0.18, 0.55),
new THREE.MeshStandardMaterial({ color: 0xf8f5ea, roughness: 1 }),
-0.63,
0.74,
-1.12,
bed
);
addMesh(
new THREE.BoxGeometry(1.05, 0.18, 0.55),
new THREE.MeshStandardMaterial({ color: 0xf8f5ea, roughness: 1 }),
0.63,
0.74,
-1.12,
bed
);
addObstacle(5.2, -2.15, 2.75, 3.25, 0, "Bed");
// Bedroom desk.
const desk = new THREE.Group();
desk.position.set(5.05, 0, 2.55);
scene.add(desk);
addMesh(
new THREE.BoxGeometry(2.1, 0.12, 0.78),
woodMaterial,
0,
0.8,
0,
desk
);
for (const x of [-0.88, 0.88]) {
addMesh(
new THREE.BoxGeometry(0.10, 0.75, 0.65),
woodMaterial,
x,
0.38,
0,
desk
);
}
addObstacle(5.05, 2.55, 2.1, 0.78, 0, "Desk");
// Low-poly plant.
const plant = new THREE.Group();
plant.position.set(1.15, 0, 2.8);
scene.add(plant);
addMesh(
new THREE.CylinderGeometry(0.28, 0.22, 0.42, 7),
new THREE.MeshStandardMaterial({ color: 0xc47c5d, roughness: 0.9 }),
0,
0.21,
0,
plant
);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x638e68,
roughness: 0.95,
flatShading: true
});
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = addMesh(
new THREE.IcosahedronGeometry(0.34, 0),
leafMaterial,
Math.cos(angle) * 0.26,
0.76 + (i % 2) * 0.12,
Math.sin(angle) * 0.26,
plant
);
leaf.scale.set(0.72, 1.45, 0.72);
leaf.rotation.z = Math.cos(angle) * 0.35;
leaf.rotation.x = Math.sin(angle) * 0.35;
}
addObstacle(1.15, 2.8, 0.58, 0.58, 0, "Plant");
// Straight route guide.
const routeGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-6.25, 0.045, DOOR_Z),
new THREE.Vector3(6.25, 0.045, DOOR_Z)
]);
const routeLine = new THREE.Line(
routeGeometry,
new THREE.LineDashedMaterial({
color: 0xe77852,
dashSize: 0.24,
gapSize: 0.15,
transparent: true,
opacity: 0.85
})
);
routeLine.computeLineDistances();
scene.add(routeLine);
for (const x of DOOR_X) {
const marker = addMesh(
new THREE.RingGeometry(0.15, 0.22, 24),
new THREE.MeshBasicMaterial({
color: 0xe77852,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.65
}),
x,
0.05,
DOOR_Z
);
marker.rotation.x = -Math.PI / 2;
marker.castShadow = false;
}
// Room labels.
const livingLabel = makeTextSprite("LIVING ROOM");
livingLabel.position.set(-4.4, 0.24, -0.8);
const hallLabel = makeTextSprite("HALL");
hallLabel.position.set(0.9, 0.24, -1.25);
const bedroomLabel = makeTextSprite("BEDROOM");
bedroomLabel.position.set(5.15, 0.24, -0.25);
// Dynamic doors and partition walls.
function clearDynamicObjects() {
for (let i = obstacleList.length - 1; i >= 0; i--) {
if (obstacleList[i].dynamic) obstacleList.splice(i, 1);
}
while (doorGroup.children.length) {
const child = doorGroup.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
}
}
function rebuildDoors() {
clearDynamicObjects();
const type = DOOR_TYPES[state.doorStyle];
const clear = type.clear;
DOOR_X.forEach((doorX, doorIndex) => {
const gapHalf = clear / 2;
// Partition wall segments.
const northStart = -4.5;
const northEnd = -gapHalf;
const southStart = gapHalf;
const southEnd = 4.5;
const northLength = northEnd - northStart;
const southLength = southEnd - southStart;
addWall(
WALL_THICKNESS,
WALL_HEIGHT,
northLength,
doorX,
(northStart + northEnd) / 2,
`Door ${doorIndex + 1} partition`,
true
);
addWall(
WALL_THICKNESS,
WALL_HEIGHT,
southLength,
doorX,
(southStart + southEnd) / 2,
`Door ${doorIndex + 1} partition`,
true
);
// Header above the opening.
addMesh(
new THREE.BoxGeometry(WALL_THICKNESS, 0.22, clear),
wallMaterial,
doorX,
WALL_HEIGHT - 0.11,
DOOR_Z,
doorGroup
);
// Slim frames.
for (const side of [-1, 1]) {
addMesh(
new THREE.BoxGeometry(WALL_THICKNESS + 0.06, WALL_HEIGHT, 0.06),
trimMaterial,
doorX,
WALL_HEIGHT / 2,
side * (gapHalf + 0.03),
doorGroup
);
}
addMesh(
new THREE.BoxGeometry(WALL_THICKNESS + 0.06, 0.07, clear + 0.12),
trimMaterial,
doorX,
WALL_HEIGHT - 0.035,
DOOR_Z,
doorGroup
);
const leafMaterial = new THREE.MeshStandardMaterial({
color: type.color,
roughness: 0.62,
metalness: 0.02
});
if (state.doorStyle === "swing") {
const leafLength = clear * 0.96;
const leafZ = -gapHalf - 0.04;
const leafX = doorX + leafLength / 2;
addMesh(
new THREE.BoxGeometry(leafLength, 1.76, 0.075),
leafMaterial,
leafX,
0.88,
leafZ,
doorGroup
);
addMesh(
new THREE.SphereGeometry(0.055, 10, 8),
new THREE.MeshStandardMaterial({
color: 0x39484c,
roughness: 0.35,
metalness: 0.6
}),
leafX + leafLength * 0.36,
0.95,
leafZ - 0.055,
doorGroup
);
addObstacle(
leafX,
leafZ,
leafLength,
0.075,
0,
`Open door ${doorIndex + 1} leaf`,
true
);
}
if (state.doorStyle === "sliding") {
const panelLength = 1.44;
const panelZ = -gapHalf - panelLength / 2 - 0.12;
const panelX = doorX - 0.13;
addMesh(
new THREE.BoxGeometry(0.075, 1.76, panelLength),
leafMaterial,
panelX,
0.88,
panelZ,
doorGroup
);
addMesh(
new THREE.BoxGeometry(0.10, 1.88, 0.05),
new THREE.MeshStandardMaterial({
color: 0x405158,
roughness: 0.4,
metalness: 0.55
}),
panelX,
0.94,
panelZ + panelLength * 0.33,
doorGroup
);
addObstacle(
panelX,
panelZ,
0.075,
panelLength,
0,
`Sliding door ${doorIndex + 1} panel`,
true
);
}
if (state.doorStyle === "double") {
const leafLength = clear * 0.48;
const leftZ = -gapHalf - 0.04;
const rightZ = gapHalf + 0.04;
const leftX = doorX + leafLength / 2;
const rightX = doorX - leafLength / 2;
addMesh(
new THREE.BoxGeometry(leafLength, 1.76, 0.075),
leafMaterial,
leftX,
0.88,
leftZ,
doorGroup
);
addMesh(
new THREE.BoxGeometry(leafLength, 1.76, 0.075),
leafMaterial,
rightX,
0.88,
rightZ,
doorGroup
);
addObstacle(
leftX,
leftZ,
leafLength,
0.075,
0,
`Door ${doorIndex + 1} leaf`,
true
);
addObstacle(
rightX,
rightZ,
leafLength,
0.075,
0,
`Door ${doorIndex + 1} leaf`,
true
);
}
});
}
rebuildDoors();
// Furniture box.
const boxRoot = new THREE.Group();
boxRoot.position.set(-5.25, 0, 2.55);
scene.add(boxRoot);
let boxBody = null;
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 128;
const labelContext = labelCanvas.getContext("2d");
labelContext.fillStyle = "#f5edda";
labelContext.fillRect(0, 0, 256, 128);
labelContext.strokeStyle = "#9f7445";
labelContext.lineWidth = 5;
labelContext.strokeRect(7, 7, 242, 114);
labelContext.fillStyle = "#6f5235";
labelContext.font = "800 31px system-ui, sans-serif";
labelContext.textAlign = "center";
labelContext.fillText("FRAGILE", 128, 57);
labelContext.font = "700 23px system-ui, sans-serif";
labelContext.fillText("↑ THIS WAY UP", 128, 96);
const boxLabelTexture = new THREE.CanvasTexture(labelCanvas);
boxLabelTexture.colorSpace = THREE.SRGBColorSpace;
function rebuildBox() {
if (boxBody) {
boxRoot.remove(boxBody);
boxBody.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
}
boxBody = new THREE.Group();
boxBody.position.y = state.height / 2;
boxRoot.add(boxBody);
const bodyGeometry = new THREE.BoxGeometry(
state.width,
state.height,
state.depth
);
const body = addMesh(
bodyGeometry,
cardboardMaterial,
0,
0,
0,
boxBody
);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(bodyGeometry),
new THREE.LineBasicMaterial({ color: 0x80552f })
);
body.add(edges);
addMesh(
new THREE.BoxGeometry(state.width * 0.16, 0.012, state.depth + 0.008),
tapeMaterial,
0,
state.height / 2 + 0.008,
0,
boxBody
);
addMesh(
new THREE.BoxGeometry(state.width * 0.16, state.height, 0.008),
tapeMaterial,
0,
0,
state.depth / 2 + 0.006,
boxBody
);
const label = addMesh(
new THREE.PlaneGeometry(state.width * 0.57, state.width * 0.285),
new THREE.MeshStandardMaterial({
map: boxLabelTexture,
roughness: 0.9
}),
state.width * 0.18,
0,
state.depth / 2 + 0.012,
boxBody
);
label.castShadow = false;
// Selection ring.
const ring = addMesh(
new THREE.RingGeometry(
Math.max(state.width, state.depth) * 0.59,
Math.max(state.width, state.depth) * 0.62,
32
),
new THREE.MeshBasicMaterial({
color: 0xe77852,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.68
}),
0,
-state.height / 2 + 0.018,
0,
boxBody
);
ring.rotation.x = -Math.PI / 2;
ring.castShadow = false;
boxRoot.rotation.y = state.yaw;
}
rebuildBox();
// OBB / AABB separating-axis collision test.
function getAxes(obstacle) {
const cosine = Math.cos(obstacle.yaw);
const sine = Math.sin(obstacle.yaw);
return [
{ x: cosine, z: -sine }, // local X axis
{ x: sine, z: cosine } // local Z axis
];
}
function overlaps(a, b) {
const aAxes = getAxes(a);
const bAxes = getAxes(b);
const axes = [...aAxes, ...bAxes];
const deltaX = b.x - a.x;
const deltaZ = b.z - a.z;
for (const axis of axes) {
const distance = Math.abs(deltaX * axis.x + deltaZ * axis.z);
const aRadius =
a.hw * Math.abs(axis.x * aAxes[0].x + axis.z * aAxes[0].z) +
a.hd * Math.abs(axis.x * aAxes[1].x + axis.z * aAxes[1].z);
const bRadius =
b.hw * Math.abs(axis.x * bAxes[0].x + axis.z * bAxes[0].z) +
b.hd * Math.abs(axis.x * bAxes[1].x + axis.z * bAxes[1].z);
if (distance >= aRadius + bRadius - 0.0001) return false;
}
return true;
}
function boxAt(x, z) {
return {
x,
z,
hw: state.width / 2,
hd: state.depth / 2,
yaw: state.yaw,
label: "Furniture box"
};
}
function collisionsAt(x, z) {
const movingBox = boxAt(x, z);
return obstacleList.filter((obstacle) => overlaps(movingBox, obstacle));
}
function requiredDoorWidth() {
return (
state.width * Math.abs(Math.sin(state.yaw)) +
state.depth * Math.abs(Math.cos(state.yaw))
);
}
function setCardboardLevel(level) {
cardboardMaterial.emissive.set(
level === "bad" ? 0x5c120d :
level === "warn" ? 0x5c3907 :
level === "good" ? 0x0d3326 : 0x000000
);
cardboardMaterial.emissiveIntensity = 0.3;
}
function updateStatus() {
const needed = requiredDoorWidth();
const available = DOOR_TYPES[state.doorStyle].clear;
const margin = available - needed;
$("neededValue").textContent = `${Math.round(needed * 100)} cm`;
$("availableValue").textContent = `${Math.round(available * 100)} cm`;
const currentHits = collisionsAt(boxRoot.position.x, boxRoot.position.z);
let level = "good";
let title = "Clearance looks good";
let detail = `${Math.round(margin * 100)} cm of margin at the narrowest doorway.`;
if (margin < 0) {
level = "bad";
title = "Doorway blocked";
detail =
`The box needs ${Math.round(needed * 100)} cm, but the ` +
`${DOOR_TYPES[state.doorStyle].name.toLowerCase()} provides ` +
`${Math.round(available * 100)} cm.`;
} else if (margin < 0.08) {
level = "warn";
title = "Tight clearance";
detail = `Only ${Math.round(margin * 100)} cm of side clearance remains.`;
}
if (currentHits.length) {
level = "bad";
title = "Object collision";
detail = `The box overlaps ${currentHits[0].label.toLowerCase()}.`;
}
if (
state.blockedHint &&
performance.now() < state.blockedHint.until
) {
level = "bad";
title = "Movement blocked";
detail = state.blockedHint.text;
}
if (
state.routeOverride &&
performance.now() < state.routeOverride.until
) {
level = state.routeOverride.level;
title = state.routeOverride.title;
detail = state.routeOverride.detail;
}
if (state.routeTesting) {
level = "warn";
title = "Route test running";
detail = "Moving the box through both doors along the orange guide.";
}
const statusBox = $("statusBox");
statusBox.className = `status ${level}`;
$("statusIcon").textContent = level === "good" ? "✓" : level === "warn" ? "!" : "×";
$("statusTitle").textContent = title;
$("statusDetail").textContent = detail;
setCardboardLevel(level);
}
function showToast(message) {
const now = performance.now();
if (now - state.lastToast < 700 && state.lastToast !== 0) return;
state.lastToast = now;
$("toast").textContent = message;
$("toast").classList.add("visible");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => {
$("toast").classList.remove("visible");
}, 2600);
}
function tryMove(x, z) {
const hits = collisionsAt(x, z);
if (!hits.length) {
boxRoot.position.x = x;
boxRoot.position.z = z;
return true;
}
// Allow sliding along a wall instead of stopping completely.
if (!collisionsAt(x, boxRoot.position.z).length) {
boxRoot.position.x = x;
} else if (!collisionsAt(boxRoot.position.x, z).length) {
boxRoot.position.z = z;
} else {
state.blockedHint = {
text: `Cannot pass ${hits[0].label.toLowerCase()}.`,
until: performance.now() + 900
};
showToast(`Blocked by ${hits[0].label.toLowerCase()}.`);
}
return false;
}
function runRouteTest() {
if (state.routeTesting) return;
state.routeTesting = true;
state.routeTime = 0;
state.routeOverride = null;
state.blockedHint = null;
boxRoot.position.set(-5.85, 0, DOOR_Z);
showToast("Testing the straight route with the current rotation.");
}
function updateDoorTags() {
const needed = requiredDoorWidth();
const available = DOOR_TYPES[state.doorStyle].clear;
const fits = needed <= available;
DOOR_X.forEach((x, index) => {
const tag = $(`doorTag${index}`);
tag.innerHTML = `
<b>DOOR ${index + 1}</b>
<span>${Math.round(available * 100)} cm clear</span>
<em class="${fits ? "" : "short"}">
${fits ? "box fits" : `${Math.round((needed - available) * 100)} cm short`}
</em>
`;
});
}
// UI events.
document.querySelectorAll(".door-button").forEach((button) => {
button.addEventListener("click", () => {
state.doorStyle = button.dataset.style;
document.querySelectorAll(".door-button").forEach((candidate) => {
candidate.classList.toggle("active", candidate === button);
});
rebuildDoors();
updateDoorTags();
updateStatus();
showToast(
`${DOOR_TYPES[state.doorStyle].name}: ` +
`${Math.round(DOOR_TYPES[state.doorStyle].clear * 100)} cm clear.`
);
});
});
function updateBoxDimensions() {
state.width = THREE.MathUtils.clamp(Number($("boxWidth").value) / 100, 0.40, 1.80);
state.depth = THREE.MathUtils.clamp(Number($("boxDepth").value) / 100, 0.35, 1.50);
state.height = THREE.MathUtils.clamp(Number($("boxHeight").value) / 100, 0.30, 1.80);
rebuildBox();
updateDoorTags();
updateStatus();
}
$("boxWidth").addEventListener("input", updateBoxDimensions);
$("boxDepth").addEventListener("input", updateBoxDimensions);
$("boxHeight").addEventListener("input", updateBoxDimensions);
$("orientation").addEventListener("input", () => {
state.yaw = THREE.MathUtils.degToRad(Number($("orientation").value));
$("orientationValue").textContent = `${$("orientation").value}°`;
boxRoot.rotation.y = state.yaw;
updateDoorTags();
updateStatus();
});
$("routeButton").addEventListener("click", runRouteTest);
$("resetButton").addEventListener("click", () => {
state.routeTesting = false;
state.routeOverride = null;
state.blockedHint = null;
state.width = 1.05;
state.depth = 0.72;
state.height = 0.70;
state.yaw = THREE.MathUtils.degToRad(18);
$("boxWidth").value = 105;
$("boxDepth").value = 72;
$("boxHeight").value = 70;
$("orientation").value = 18;
$("orientationValue").textContent = "18°";
boxRoot.position.set(-5.25, 0, 2.55);
rebuildBox();
updateDoorTags();
updateStatus();
showToast("Box and measurements reset.");
});
// Camera and direct manipulation controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const floorPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const floorPoint = new THREE.Vector3();
let pointerMode = null;
let dragOffset = new THREE.Vector3();
let lastPointer = { x: 0, y: 0 };
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
lastPointer = { x: event.clientX, y: event.clientY };
if (event.button === 2) {
pointerMode = "orbit";
return;
}
if (event.button === 1) {
pointerMode = "pan";
return;
}
if (event.button === 0) {
updatePointer(event);
const hits = raycaster.intersectObject(boxRoot, true);
if (hits.length && raycaster.ray.intersectPlane(floorPlane, floorPoint)) {
pointerMode = "box";
dragOffset.set(
boxRoot.position.x - floorPoint.x,
0,
boxRoot.position.z - floorPoint.z
);
document.body.style.cursor = "grabbing";
}
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const dx = event.clientX - lastPointer.x;
const dy = event.clientY - lastPointer.y;
lastPointer = { x: event.clientX, y: event.clientY };
if (pointerMode === "orbit") {
view.yaw -= dx * 0.006;
view.pitch = THREE.MathUtils.clamp(view.pitch + dy * 0.005, 0.42, 1.25);
}
if (pointerMode === "pan") {
const rect = renderer.domElement.getBoundingClientRect();
const worldPerPixel = (camera.right - camera.left) / camera.zoom / rect.width;
const right = new THREE.Vector3(Math.cos(view.yaw), 0, -Math.sin(view.yaw));
const forward = new THREE.Vector3(-Math.sin(view.yaw), 0, -Math.cos(view.yaw));
view.target.addScaledVector(right, -dx * worldPerPixel);
view.target.addScaledVector(forward, -dy * worldPerPixel);
}
if (pointerMode === "box") {
updatePointer(event);
if (raycaster.ray.intersectPlane(floorPlane, floorPoint)) {
tryMove(
floorPoint.x + dragOffset.x,
floorPoint.z + dragOffset.z
);
}
}
});
function endPointer() {
pointerMode = null;
document.body.style.cursor = "";
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(
view.zoom * Math.exp(-event.deltaY * 0.001),
0.58,
2.35
);
}, { passive: false });
// Keyboard movement.
const keys = new Set();
window.addEventListener("keydown", (event) => {
if (["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(document.activeElement.tagName)) {
return;
}
keys.add(event.code);
if (event.code === "KeyQ" || event.code === "KeyE") {
const direction = event.code === "KeyQ" ? -1 : 1;
const degrees = (Number($("orientation").value) + direction * 15 + 360) % 360;
$("orientation").value = degrees;
$("orientation").dispatchEvent(new Event("input"));
}
if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Space"].includes(event.code)) {
event.preventDefault();
}
});
window.addEventListener("keyup", (event) => {
keys.delete(event.code);
});
window.addEventListener("blur", () => keys.clear());
function updateKeyboardMovement(delta) {
if (state.routeTesting) return;
let x = 0;
let z = 0;
const speed = keys.has("ShiftLeft") || keys.has("ShiftRight") ? 0.42 : 0.15;
if (keys.has("KeyW") || keys.has("ArrowUp")) z -= speed * delta;
if (keys.has("KeyS") || keys.has("ArrowDown")) z += speed * delta;
if (keys.has("KeyA") || keys.has("ArrowLeft")) x -= speed * delta;
if (keys.has("KeyD") || keys.has("ArrowRight")) x += speed * delta;
if (x || z) {
tryMove(boxRoot.position.x + x, boxRoot.position.z + z);
}
}
function updateCamera() {
const radius = 18;
const horizontal = radius * Math.sin(view.pitch);
camera.position.set(
view.target.x + horizontal * Math.sin(view.yaw),
view.target.y + radius * Math.cos(view.pitch),
view.target.z + horizontal * Math.cos(view.yaw)
);
camera.lookAt(view.target);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const frustumHeight = 13;
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
const projected = new THREE.Vector3();
function updateWorldLabels() {
DOOR_X.forEach((x, index) => {
projected.set(x, 2.28, DOOR_Z).project(camera);
const tag = $(`doorTag${index}`);
tag.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
tag.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
tag.style.display = projected.z > 1 ? "none" : "block";
});
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateKeyboardMovement(delta);
if (state.routeTesting) {
state.routeTime += delta / 3.15;
const x = THREE.MathUtils.lerp(-5.85, 5.85, Math.min(state.routeTime, 1));
boxRoot.position.x = x;
boxRoot.position.z = DOOR_Z;
const hits = collisionsAt(x, DOOR_Z);
if (hits.length) {
state.routeTesting = false;
state.routeOverride = {
level: "bad",
title: "Route blocked",
detail:
`Stopped at ${hits[0].label.toLowerCase()}. ` +
`The box needs ${Math.round(requiredDoorWidth() * 100)} cm of doorway width.`,
until: performance.now() + 8000
};
showToast(`Route blocked: ${hits[0].label}.`);
} else if (state.routeTime >= 1) {
state.routeTesting = false;
state.routeOverride = {
level: "good",
title: "Route passed",
detail: "The box cleared both doorways and reached the bedroom.",
until: performance.now() + 8000
};
showToast("Route passed: both doorways are clear.");
}
}
updateCamera();
updateWorldLabels();
updateStatus();
renderer.render(scene, camera);
}
updateDoorTags();
updateStatus();
animate();
</script>
</body>
</html>
```