Prompt specification
Build or customize the Three.js 3D scene "Wheelchair Turns Through a Doorway" 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: Wheelchair Turns Through a Doorway
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wheelchair-turns-through-a-doorway-x3694
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: wheelchair turns through a doorway. Animate a simple wheelchair proxy through a bounded doorway using its full footprint. Show collisions and turning clearance rather than shrinking the chair to fit. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (wheelchair-turns-through-a-doorway-x3694):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Wheelchair Doorway — Full-Footprint Clearance Study</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1420;
--panel: rgba(13, 25, 39, 0.86);
--border: rgba(168, 205, 226, 0.18);
--text: #edf7fb;
--muted: #91a9ba;
--mint: #5ee7c4;
--amber: #ffc45e;
--red: #ff6178;
--blue: #70bfff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
touch-action: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#header {
position: fixed;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
padding: 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 29px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.badge-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.badge {
padding: 6px 9px;
border: 1px solid rgba(94, 231, 196, 0.25);
border-radius: 999px;
background: rgba(94, 231, 196, 0.08);
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#metrics {
position: fixed;
top: 18px;
right: 18px;
width: min(320px, calc(100vw - 36px));
padding: 16px;
}
.metric-title {
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
padding: 9px 0;
border-top: 1px solid rgba(168, 205, 226, 0.1);
}
.metric-label {
color: var(--muted);
font-size: 12px;
}
.metric-value {
font-variant-numeric: tabular-nums;
font-size: 15px;
font-weight: 750;
white-space: nowrap;
}
#status {
margin: 11px 0 14px;
padding: 10px 11px;
border: 1px solid rgba(94, 231, 196, 0.24);
border-radius: 10px;
background: rgba(94, 231, 196, 0.08);
color: var(--mint);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#status.tight {
border-color: rgba(255, 196, 94, 0.3);
background: rgba(255, 196, 94, 0.09);
color: var(--amber);
}
#status.contact {
border-color: rgba(255, 97, 120, 0.38);
background: rgba(255, 97, 120, 0.11);
color: var(--red);
}
#eventText {
min-height: 31px;
margin-top: 10px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.control-label {
display: flex;
justify-content: space-between;
margin: 8px 0 7px;
color: var(--muted);
font-size: 11px;
}
#doorReadout {
color: var(--text);
font-weight: 750;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0 13px;
border-radius: 999px;
outline: none;
background: linear-gradient(
90deg,
var(--mint) 0%,
var(--mint) var(--range-fill, 40%),
rgba(168, 205, 226, 0.15) var(--range-fill, 40%),
rgba(168, 205, 226, 0.15) 100%
);
appearance: none;
-webkit-appearance: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #102131;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 1px rgba(94, 231, 196, 0.5);
cursor: pointer;
appearance: none;
-webkit-appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #102131;
border-radius: 50%;
background: var(--mint);
cursor: pointer;
}
.button-row {
display: flex;
gap: 7px;
}
button,
select {
border: 1px solid rgba(168, 205, 226, 0.18);
border-radius: 9px;
background: rgba(168, 205, 226, 0.07);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
}
button {
flex: 1;
padding: 9px 8px;
}
button:hover,
select:hover {
border-color: rgba(94, 231, 196, 0.45);
background: rgba(94, 231, 196, 0.1);
}
button.primary {
border-color: rgba(94, 231, 196, 0.35);
background: rgba(94, 231, 196, 0.12);
color: var(--mint);
}
button.warning {
border-color: rgba(255, 196, 94, 0.28);
background: rgba(255, 196, 94, 0.08);
color: var(--amber);
}
#legend {
position: fixed;
bottom: 18px;
left: 18px;
width: min(315px, calc(100vw - 36px));
padding: 14px 16px;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 7px 0;
color: var(--muted);
font-size: 11px;
}
.swatch {
width: 18px;
height: 8px;
border-radius: 3px;
flex: 0 0 auto;
}
.swatch.mint {
border: 1px solid var(--mint);
background: rgba(94, 231, 196, 0.2);
}
.swatch.amber {
border: 1px solid rgba(255, 196, 94, 0.8);
background: rgba(255, 196, 94, 0.12);
}
.swatch.line {
height: 2px;
background: var(--mint);
}
.swatch.red {
border: 1px solid var(--red);
background: rgba(255, 97, 120, 0.18);
}
#timelinePanel {
position: fixed;
bottom: 18px;
left: 50%;
display: flex;
align-items: center;
gap: 10px;
width: min(620px, calc(100vw - 390px));
min-width: 360px;
padding: 12px;
transform: translateX(-50%);
}
#timelinePanel button {
flex: 0 0 auto;
min-width: 76px;
}
#timeline {
flex: 1;
min-width: 100px;
margin: 0;
}
#timeReadout {
width: 67px;
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
text-align: right;
}
#cameraHelp {
position: fixed;
right: 20px;
bottom: 21px;
color: rgba(205, 224, 236, 0.55);
font-size: 10px;
pointer-events: none;
text-align: right;
}
@media (max-width: 900px) {
#header {
width: min(320px, calc(100vw - 36px));
}
#metrics {
top: auto;
bottom: 102px;
width: min(300px, calc(100vw - 36px));
}
#legend {
display: none;
}
#timelinePanel {
right: 18px;
left: 18px;
width: auto;
min-width: 0;
transform: none;
}
#cameraHelp {
display: none;
}
}
@media (max-width: 580px) {
#header {
padding: 13px;
}
.subtitle {
margin-bottom: 10px;
}
#metrics {
bottom: 92px;
padding: 12px;
}
#eventText,
.metric-title {
display: none;
}
.metric {
padding: 6px 0;
}
#timelinePanel {
gap: 6px;
padding: 9px;
}
#timelinePanel button {
min-width: 58px;
padding: 9px 6px;
}
#timeReadout {
width: 52px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="header" class="panel">
<div class="eyebrow">Geometry / Motion Study</div>
<h1>Doorway Turning Clearance</h1>
<p class="subtitle">
A fixed-size wheelchair proxy rotates through a bounded opening.
Collision tests use the complete footprint, including wheels and footplate.
</p>
<div class="badge-row">
<span class="badge">Never scaled</span>
<span class="badge">0.84 × 1.17 m footprint</span>
<span class="badge">Real footprint collision</span>
</div>
</section>
<section id="metrics" class="panel">
<div class="metric-title">Clearance Monitor</div>
<div class="metric">
<span class="metric-label">Live nearest clearance</span>
<span id="liveClearance" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Minimum swept clearance</span>
<span id="sweepClearance" class="metric-value">—</span>
</div>
<div class="metric">
<span class="metric-label">Current heading</span>
<span id="headingReadout" class="metric-value">0.0°</span>
</div>
<div id="status">Clear</div>
<div id="eventText">Evaluating the sampled turning envelope…</div>
<div class="control-label">
<span>Door clear width</span>
<span id="doorReadout">1.20 m</span>
</div>
<input
id="doorWidth"
type="range"
min="0.82"
max="1.50"
step="0.01"
value="1.20"
aria-label="Door clear width"
/>
<div class="button-row">
<button id="stressButton" class="warning" type="button">
0.90 m stress test
</button>
<button id="safeButton" class="primary" type="button">
Restore 1.20 m
</button>
</div>
</section>
<section id="legend" class="panel">
<div class="legend-row">
<span class="swatch mint"></span>
<span>Current full rigid footprint</span>
</div>
<div class="legend-row">
<span class="swatch amber"></span>
<span>Sampled turning / swept envelope</span>
</div>
<div class="legend-row">
<span class="swatch line"></span>
<span>Nearest obstacle-clearance line</span>
</div>
<div class="legend-row">
<span class="swatch red"></span>
<span>Footprint–jamb collision</span>
</div>
</section>
<section id="timelinePanel" class="panel">
<button id="playButton" class="primary" type="button">❚❚ Pause</button>
<button id="replayButton" type="button">↻ Replay</button>
<input
id="timeline"
type="range"
min="0"
max="1000"
step="1"
value="0"
aria-label="Animation timeline"
/>
<span id="timeReadout">0.0 / 12s</span>
</section>
<div id="cameraHelp">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM / renderer
// -------------------------------------------------------------------------
const container = document.getElementById("scene");
const doorWidthInput = document.getElementById("doorWidth");
const doorReadout = document.getElementById("doorReadout");
const liveClearanceEl = document.getElementById("liveClearance");
const sweepClearanceEl = document.getElementById("sweepClearance");
const headingReadout = document.getElementById("headingReadout");
const statusEl = document.getElementById("status");
const eventTextEl = document.getElementById("eventText");
const playButton = document.getElementById("playButton");
const replayButton = document.getElementById("replayButton");
const stressButton = document.getElementById("stressButton");
const safeButton = document.getElementById("safeButton");
const timeline = document.getElementById("timeline");
const timeReadout = document.getElementById("timeReadout");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.12;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1420);
scene.fog = new THREE.Fog(0x0b1420, 10, 20);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
40
);
// -------------------------------------------------------------------------
// Lighting and floor
// -------------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xd9efff, 0x182536, 2.0);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff4df, 3.2);
key.position.set(4.5, 8.5, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.00025;
scene.add(key);
const rimLight = new THREE.PointLight(0x46d9c3, 12, 12, 2);
rimLight.position.set(-3.5, 3.0, -3.0);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(10, 10),
new THREE.MeshStandardMaterial({
color: 0x152536,
roughness: 0.88,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(10, 20, 0x42647a, 0x294154);
grid.position.y = 0.007;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
// -------------------------------------------------------------------------
// Path and fixed footprint
// Local +Z is the chair's forward direction.
// The footprint is a convex rigid envelope around wheels, frame and footplate.
// -------------------------------------------------------------------------
const footprintLocal = [
{ x: -0.36, z: -0.48 },
{ x: 0.36, z: -0.48 },
{ x: 0.42, z: -0.25 },
{ x: 0.42, z: 0.42 },
{ x: 0.28, z: 0.69 },
{ x: -0.28, z: 0.69 },
{ x: -0.42, z: 0.42 },
{ x: -0.42, z: -0.25 }
];
const pathPoints = [
new THREE.Vector3(-1.55, 0, -2.85),
new THREE.Vector3(-1.52, 0, -2.15),
new THREE.Vector3(-1.32, 0, -1.55),
new THREE.Vector3(-0.82, 0, -1.10),
new THREE.Vector3(-0.25, 0, -0.72),
new THREE.Vector3( 0.00, 0, -0.48),
new THREE.Vector3( 0.00, 0, -0.18),
new THREE.Vector3( 0.00, 0, 0.45),
new THREE.Vector3( 0.00, 0, 1.25),
new THREE.Vector3( 0.00, 0, 2.15),
new THREE.Vector3( 0.00, 0, 2.95)
];
const yawKeys = [
0.00, 0.02, 0.14, 0.32, 0.27,
0.18, 0.02, 0.00, 0.00, 0.00, 0.00
];
const positionCurve = new THREE.CatmullRomCurve3(
pathPoints,
false,
"centripetal"
);
const pathLength = positionCurve.getLength();
function yawAt(u) {
if (u >= 1) return yawKeys[yawKeys.length - 1];
const scaled = u * (yawKeys.length - 1);
const index = Math.floor(scaled);
let t = scaled - index;
t = t * t * (3 - 2 * t);
return THREE.MathUtils.lerp(yawKeys[index], yawKeys[index + 1], t);
}
function poseAt(u) {
const p = positionCurve.getPoint(Math.max(0, Math.min(1, u)));
return {
x: p.x,
z: p.z,
yaw: yawAt(u)
};
}
function transformFootprint(pose) {
const c = Math.cos(pose.yaw);
const s = Math.sin(pose.yaw);
return footprintLocal.map((p) => ({
x: pose.x + p.x * c + p.z * s,
z: pose.z - p.x * s + p.z * c
}));
}
// -------------------------------------------------------------------------
// Stylized wheelchair model
// -------------------------------------------------------------------------
const chair = new THREE.Group();
scene.add(chair);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x9cc5d7,
metalness: 0.62,
roughness: 0.3
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x17212d,
metalness: 0.2,
roughness: 0.66
});
const tireMaterial = new THREE.MeshStandardMaterial({
color: 0x111821,
metalness: 0.08,
roughness: 0.82
});
const seatMaterial = new THREE.MeshStandardMaterial({
color: 0xf08b61,
metalness: 0.02,
roughness: 0.76
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0x5ee7c4,
metalness: 0.12,
roughness: 0.5
});
const personMaterial = new THREE.MeshStandardMaterial({
color: 0x86a8ff,
roughness: 0.8
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xf1c7a5,
roughness: 0.85
});
function addBox(parent, size, position, material, rotation = null) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
if (rotation) mesh.rotation.set(rotation.x, rotation.y, rotation.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, radius, material, radialSegments = 10) {
const start = new THREE.Vector3(a.x, a.y, a.z);
const end = new THREE.Vector3(b.x, b.y, b.z);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Seat and back.
addBox(
chair,
new THREE.Vector3(0.51, 0.075, 0.47),
new THREE.Vector3(0, 0.53, -0.015),
seatMaterial
);
addBox(
chair,
new THREE.Vector3(0.51, 0.47, 0.075),
new THREE.Vector3(0, 0.83, -0.275),
seatMaterial,
new THREE.Vector3(-0.08, 0, 0)
);
// Push handles.
cylinderBetween(
chair,
{ x: -0.245, y: 1.05, z: -0.30 },
{ x: -0.245, y: 1.12, z: -0.48 },
0.017,
frameMaterial
);
cylinderBetween(
chair,
{ x: 0.245, y: 1.05, z: -0.30 },
{ x: 0.245, y: 1.12, z: -0.48 },
0.017,
frameMaterial
);
cylinderBetween(
chair,
{ x: -0.245, y: 1.12, z: -0.48 },
{ x: 0.245, y: 1.12, z: -0.48 },
0.019,
darkMaterial
);
// Armrests.
for (const side of [-1, 1]) {
cylinderBetween(
chair,
{ x: side * 0.275, y: 0.78, z: -0.22 },
{ x: side * 0.275, y: 0.78, z: 0.20 },
0.016,
darkMaterial
);
cylinderBetween(
chair,
{ x: side * 0.275, y: 0.53, z: -0.18 },
{ x: side * 0.275, y: 0.78, z: -0.18 },
0.015,
frameMaterial
);
}
// Main frame.
for (const side of [-1, 1]) {
cylinderBetween(
chair,
{ x: side * 0.29, y: 0.37, z: -0.14 },
{ x: side * 0.24, y: 0.20, z: 0.46 },
0.022,
frameMaterial
);
cylinderBetween(
chair,
{ x: side * 0.29, y: 0.37, z: -0.14 },
{ x: side * 0.25, y: 0.88, z: -0.28 },
0.022,
frameMaterial
);
cylinderBetween(
chair,
{ x: side * 0.23, y: 0.52, z: -0.02 },
{ x: side * 0.23, y: 0.52, z: 0.20 },
0.019,
frameMaterial
);
}
cylinderBetween(
chair,
{ x: -0.27, y: 0.23, z: 0.42 },
{ x: 0.27, y: 0.23, z: 0.42 },
0.022,
frameMaterial
);
// Footplate.
addBox(
chair,
new THREE.Vector3(0.49, 0.035, 0.22),
new THREE.Vector3(0, 0.145, 0.58),
darkMaterial
);
for (const side of [-1, 1]) {
cylinderBetween(
chair,
{ x: side * 0.19, y: 0.18, z: 0.38 },
{ x: side * 0.19, y: 0.145, z: 0.55 },
0.014,
frameMaterial
);
}
const rearWheelGroups = [];
const frontWheelGroups = [];
function createRearWheel(side) {
const group = new THREE.Group();
group.position.set(side * 0.37, 0.34, -0.14);
const tire = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.035, 12, 36),
tireMaterial
);
tire.rotation.y = Math.PI / 2;
tire.castShadow = true;
group.add(tire);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.275, 0.012, 8, 36),
frameMaterial
);
rim.rotation.y = Math.PI / 2;
group.add(rim);
for (let i = 0; i < 8; i++) {
const a = (i / 8) * Math.PI * 2;
cylinderBetween(
group,
{ x: 0, y: 0, z: 0 },
{ x: 0, y: Math.cos(a) * 0.265, z: Math.sin(a) * 0.265 },
0.006,
frameMaterial,
6
);
}
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.10, 12),
accentMaterial
);
hub.rotation.z = Math.PI / 2;
group.add(hub);
chair.add(group);
rearWheelGroups.push(group);
}
function createFrontWheel(side) {
const group = new THREE.Group();
group.position.set(side * 0.245, 0.115, 0.46);
const tire = new THREE.Mesh(
new THREE.TorusGeometry(0.09, 0.021, 9, 24),
tireMaterial
);
tire.rotation.y = Math.PI / 2;
tire.castShadow = true;
group.add(tire);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.027, 0.06, 10),
accentMaterial
);
hub.rotation.z = Math.PI / 2;
group.add(hub);
chair.add(group);
frontWheelGroups.push(group);
}
createRearWheel(-1);
createRearWheel(1);
createFrontWheel(-1);
createFrontWheel(1);
// Simple seated person for scale.
addBox(
chair,
new THREE.Vector3(0.34, 0.39, 0.22),
new THREE.Vector3(0, 1.00, -0.10),
personMaterial,
new THREE.Vector3(-0.08, 0, 0)
);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.125, 20, 16),
skinMaterial
);
head.position.set(0, 1.31, -0.13);
head.castShadow = true;
chair.add(head);
for (const side of [-1, 1]) {
cylinderBetween(
chair,
{ x: side * 0.11, y: 0.76, z: 0.05 },
{ x: side * 0.11, y: 0.58, z: 0.35 },
0.075,
personMaterial
);
cylinderBetween(
chair,
{ x: side * 0.11, y: 0.58, z: 0.35 },
{ x: side * 0.11, y: 0.27, z: 0.42 },
0.055,
personMaterial
);
addBox(
chair,
new THREE.Vector3(0.12, 0.075, 0.20),
new THREE.Vector3(side * 0.11, 0.235, 0.48),
darkMaterial
);
}
// -------------------------------------------------------------------------
// Full rigid footprint visualization
// -------------------------------------------------------------------------
const footprintShape = new THREE.Shape();
footprintShape.moveTo(footprintLocal[0].x, footprintLocal[0].z);
for (let i = 1; i < footprintLocal.length; i++) {
footprintShape.lineTo(footprintLocal[i].x, footprintLocal[i].z);
}
footprintShape.closePath();
const footprintGeometry = new THREE.ShapeGeometry(footprintShape);
footprintGeometry.rotateX(Math.PI / 2);
const footprintMaterial = new THREE.MeshBasicMaterial({
color: 0x5ee7c4,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false
});
const footprintMesh = new THREE.Mesh(
footprintGeometry,
footprintMaterial
);
footprintMesh.position.y = 0.031;
footprintMesh.renderOrder = 4;
chair.add(footprintMesh);
const footprintOutlineMaterial = new THREE.LineBasicMaterial({
color: 0x5ee7c4,
transparent: true,
opacity: 0.95
});
const footprintOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(
footprintLocal.map(
(p) => new THREE.Vector3(p.x, 0.036, p.z)
)
),
footprintOutlineMaterial
);
footprintOutline.renderOrder = 5;
chair.add(footprintOutline);
// Heading arrow.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.075, 0.72);
arrowShape.lineTo(0.075, 0.72);
arrowShape.lineTo(0, 0.88);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
arrowGeometry.rotateX(Math.PI / 2);
const headingArrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshBasicMaterial({
color: 0x70bfff,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthWrite: false
})
);
headingArrow.position.y = 0.041;
headingArrow.renderOrder = 6;
chair.add(headingArrow);
// -------------------------------------------------------------------------
// Doorway and obstacles
// -------------------------------------------------------------------------
const wallMaterialLeft = new THREE.MeshStandardMaterial({
color: 0xd9e3e9,
roughness: 0.78,
metalness: 0.03,
emissive: 0x000000,
emissiveIntensity: 0
});
const wallMaterialRight = wallMaterialLeft.clone();
function createWall(material) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(1, 2.18, 0.34),
material
);
body.position.y = 1.09;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.065, 0.39),
new THREE.MeshStandardMaterial({
color: 0x9eb6c5,
roughness: 0.58,
metalness: 0.15
})
);
cap.position.y = 2.21;
cap.castShadow = true;
group.add(cap);
scene.add(group);
return group;
}
const leftWall = createWall(wallMaterialLeft);
const rightWall = createWall(wallMaterialRight);
const trimMaterialLeft = new THREE.MeshBasicMaterial({
color: 0x5ee7c4
});
const trimMaterialRight = new THREE.MeshBasicMaterial({
color: 0x5ee7c4
});
const leftTrim = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 2.25, 0.40),
trimMaterialLeft
);
const rightTrim = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 2.25, 0.40),
trimMaterialRight
);
scene.add(leftTrim, rightTrim);
const lintel = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.12, 0.40),
new THREE.MeshStandardMaterial({
color: 0xb8c9d3,
roughness: 0.62,
metalness: 0.08
})
);
lintel.position.y = 2.26;
lintel.castShadow = true;
scene.add(lintel);
const threshold = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.012, 0.34),
new THREE.MeshStandardMaterial({
color: 0x668395,
roughness: 0.7,
metalness: 0.12
})
);
threshold.position.y = 0.012;
scene.add(threshold);
const measurementMaterial = new THREE.MeshBasicMaterial({
color: 0x70bfff,
transparent: true,
opacity: 0.78
});
const measurementLine = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.012, 0.022),
measurementMaterial
);
measurementLine.position.set(0, 0.055, 0.40);
scene.add(measurementLine);
const measurementTicks = [-1, 1].map(() => {
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.018, 0.014, 0.16),
measurementMaterial
);
tick.position.set(0, 0.056, 0.40);
scene.add(tick);
return tick;
});
let measurementLabel = null;
let obstacles = [];
let doorWidth = 1.2;
function makeTextSprite(text, color = "#eaf6fb") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.fillStyle = "rgba(8, 18, 29, 0.78)";
ctx.fillRect(8, 16, 496, 96);
ctx.strokeStyle = "rgba(120, 205, 224, 0.35)";
ctx.lineWidth = 3;
ctx.strokeRect(8, 16, 496, 96);
ctx.fillStyle = color;
ctx.font = "700 43px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.85, 0.46, 1);
return sprite;
}
function makeFloorLabel(text, x, z, width, color = "#8ca9bc") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.fillStyle = color;
ctx.font = "800 54px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 64);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width / 4),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
opacity: 0.65,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.024, z);
scene.add(mesh);
}
makeFloorLabel("APPROACH", -1.55, -2.05, 1.38);
makeFloorLabel("EXIT", 0.0, 2.20, 0.86, "#5ee7c4");
const envelopeLabel = makeTextSprite("TURNING ENVELOPE", "#ffc45e");
envelopeLabel.scale.set(1.65, 0.41, 1);
envelopeLabel.position.set(-0.75, 0.20, -1.28);
scene.add(envelopeLabel);
function rectanglePolygon(x0, x1, z0, z1) {
return [
{ x: x0, z: z0 },
{ x: x1, z: z0 },
{ x: x1, z: z1 },
{ x: x0, z: z1 }
];
}
function updateMeasurementLabel(width) {
if (measurementLabel) {
scene.remove(measurementLabel);
measurementLabel.material.map?.dispose();
measurementLabel.material.dispose();
}
measurementLabel = makeTextSprite(
`${width.toFixed(2)} m CLEAR`,
"#9dd9ff"
);
measurementLabel.position.set(0, 0.33, 0.47);
scene.add(measurementLabel);
}
function updateDoorWidth(value) {
doorWidth = THREE.MathUtils.clamp(value, 0.82, 1.50);
const half = doorWidth / 2;
const outer = 4.2;
const leftMin = -outer;
const leftMax = -half;
const rightMin = half;
const rightMax = outer;
leftWall.scale.x = leftMax - leftMin;
leftWall.position.x = (leftMin + leftMax) / 2;
rightWall.scale.x = rightMax - rightMin;
rightWall.position.x = (rightMin + rightMax) / 2;
leftTrim.position.set(-half, 1.125, 0);
rightTrim.position.set(half, 1.125, 0);
lintel.scale.x = doorWidth;
lintel.position.x = 0;
threshold.scale.x = doorWidth;
threshold.position.x = 0;
measurementLine.scale.x = doorWidth;
measurementTicks[0].position.x = -half;
measurementTicks[1].position.x = half;
obstacles = [
rectanglePolygon(leftMin, leftMax, -0.17, 0.17),
rectanglePolygon(rightMin, rightMax, -0.17, 0.17)
];
doorWidthInput.value = doorWidth.toFixed(2);
doorReadout.textContent = `${doorWidth.toFixed(2)} m`;
const sliderMin = Number(doorWidthInput.min);
const sliderMax = Number(doorWidthInput.max);
const fill =
((doorWidth - sliderMin) / (sliderMax - sliderMin)) * 100;
doorWidthInput.style.setProperty("--range-fill", `${fill}%`);
updateMeasurementLabel(doorWidth);
recomputeSweepClearance();
}
// -------------------------------------------------------------------------
// Center path
// -------------------------------------------------------------------------
const pathLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(
positionCurve.getPoints(220).map(
(p) => new THREE.Vector3(p.x, 0.035, p.z)
)
),
new THREE.LineDashedMaterial({
color: 0x70bfff,
dashSize: 0.10,
gapSize: 0.075,
transparent: true,
opacity: 0.75
})
);
pathLine.computeLineDistances();
scene.add(pathLine);
// Small sampled path nodes.
const nodeGeometry = new THREE.CircleGeometry(0.035, 12);
nodeGeometry.rotateX(-Math.PI / 2);
const nodeMaterial = new THREE.MeshBasicMaterial({
color: 0x70bfff,
transparent: true,
opacity: 0.65
});
for (let i = 0; i <= 12; i++) {
const p = positionCurve.getPoint(i / 12);
const node = new THREE.Mesh(nodeGeometry, nodeMaterial);
node.position.set(p.x, 0.04, p.z);
scene.add(node);
}
// -------------------------------------------------------------------------
// Sampled turning envelope
// -------------------------------------------------------------------------
const envelopeSamples = [];
const allSweepSamples = [];
for (let i = 0; i <= 160; i++) {
const u = i / 160;
allSweepSamples.push({
u,
polygon: transformFootprint(poseAt(u))
});
}
for (let i = 0; i <= 110; i++) {
const u = THREE.MathUtils.lerp(0.18, 0.68, i / 110);
envelopeSamples.push(transformFootprint(poseAt(u)));
}
const envelopePositions = [];
for (const polygon of envelopeSamples) {
for (let i = 1; i < polygon.length - 1; i++) {
envelopePositions.push(
polygon[0].x, 0.018, polygon[0].z,
polygon[i].x, 0.018, polygon[i].z,
polygon[i + 1].x, 0.018, polygon[i + 1].z
);
}
}
const envelopeGeometry = new THREE.BufferGeometry();
envelopeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(envelopePositions, 3)
);
const envelopeMaterial = new THREE.MeshBasicMaterial({
color: 0xffc45e,
transparent: true,
opacity: 0.055,
side: THREE.DoubleSide,
depthWrite: false
});
const envelopeMesh = new THREE.Mesh(
envelopeGeometry,
envelopeMaterial
);
envelopeMesh.renderOrder = 1;
scene.add(envelopeMesh);
const envelopeLinePositions = [];
for (let i = 0; i < envelopeSamples.length; i += 4) {
const polygon = envelopeSamples[i];
for (let j = 0; j < polygon.length; j++) {
const a = polygon[j];
const b = polygon[(j + 1) % polygon.length];
envelopeLinePositions.push(
a.x, 0.021, a.z,
b.x, 0.021, b.z
);
}
}
const envelopeLines = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(envelopeLinePositions, 3)
),
new THREE.LineBasicMaterial({
color: 0xffc45e,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
envelopeLines.renderOrder = 2;
scene.add(envelopeLines);
// -------------------------------------------------------------------------
// 2D polygon collision and distance utilities
// -------------------------------------------------------------------------
function polygonsIntersect(a, b) {
const epsilon = 1e-7;
for (const polygon of [a, b]) {
for (let i = 0; i < polygon.length; i++) {
const p = polygon[i];
const q = polygon[(i + 1) % polygon.length];
const axisX = -(q.z - p.z);
const axisZ = q.x - p.x;
const axisLength = Math.hypot(axisX, axisZ);
if (axisLength < epsilon) continue;
let minA = Infinity;
let maxA = -Infinity;
let minB = Infinity;
let maxB = -Infinity;
for (const v of a) {
const projection = v.x * axisX + v.z * axisZ;
minA = Math.min(minA, projection);
maxA = Math.max(maxA, projection);
}
for (const v of b) {
const projection = v.x * axisX + v.z * axisZ;
minB = Math.min(minB, projection);
maxB = Math.max(maxB, projection);
}
if (maxA < minB - epsilon || maxB < minA - epsilon) {
return false;
}
}
}
return true;
}
function pointInPolygon(point, polygon) {
let inside = false;
for (
let i = 0, j = polygon.length - 1;
i < polygon.length;
j = i++
) {
const zi = polygon[i].z;
const zj = polygon[j].z;
if (
(zi > point.z) !== (zj > point.z) &&
point.x <
((polygon[j].x - polygon[i].x) *
(point.z - zi)) /
(zj - zi) +
polygon[i].x
) {
inside = !inside;
}
}
return inside;
}
function contactPoint(a, b) {
for (const p of a) {
if (pointInPolygon(p, b)) return { x: p.x, z: p.z };
}
for (const p of b) {
if (pointInPolygon(p, a)) return { x: p.x, z: p.z };
}
return {
x: (a[0].x + b[0].x) / 2,
z: (a[0].z + b[0].z) / 2
};
}
function closestPointsOnSegments(p1, p2, q1, q2) {
const dx1 = p2.x - p1.x;
const dz1 = p2.z - p1.z;
const dx2 = q2.x - q1.x;
const dz2 = q2.z - q1.z;
const rx = p1.x - q1.x;
const rz = p1.z - q1.z;
const a = dx1 * dx1 + dz1 * dz1;
const e = dx2 * dx2 + dz2 * dz2;
const f = dx2 * rx + dz2 * rz;
const epsilon = 1e-12;
let s = 0;
let t = 0;
if (a <= epsilon && e <= epsilon) {
return {
a: { x: p1.x, z: p1.z },
b: { x: q1.x, z: q1.z }
};
}
if (a <= epsilon) {
t = THREE.MathUtils.clamp(f / e, 0, 1);
} else {
const c = dx1 * rx + dz1 * rz;
if (e <= epsilon) {
t = 0;
s = THREE.MathUtils.clamp(-c / a, 0, 1);
} else {
const b = dx1 * dx2 + dz1 * dz2;
const denominator = a * e - b * b;
s =
denominator !== 0
? THREE.MathUtils.clamp(
(b * f - c * e) / denominator,
0,
1
)
: 0;
t = (b * s + f) / e;
if (t < 0) {
t = 0;
s = THREE.MathUtils.clamp(-c / a, 0, 1);
} else if (t > 1) {
t = 1;
s = THREE.MathUtils.clamp((b - c) / a, 0, 1);
}
}
}
return {
a: {
x: p1.x + dx1 * s,
z: p1.z + dz1 * s
},
b: {
x: q1.x + dx2 * t,
z: q1.z + dz2 * t
}
};
}
function polygonDistance(a, b) {
let bestDistance = Infinity;
let bestA = null;
let bestB = null;
for (let i = 0; i < a.length; i++) {
const a1 = a[i];
const a2 = a[(i + 1) % a.length];
for (let j = 0; j < b.length; j++) {
const b1 = b[j];
const b2 = b[(j + 1) % b.length];
const closest = closestPointsOnSegments(a1, a2, b1, b2);
const distance = Math.hypot(
closest.a.x - closest.b.x,
closest.a.z - closest.b.z
);
if (distance < bestDistance) {
bestDistance = distance;
bestA = closest.a;
bestB = closest.b;
}
}
}
return {
distance: bestDistance,
a: bestA,
b: bestB
};
}
function evaluatePose(polygon) {
let nearest = null;
let contact = null;
for (let obstacleIndex = 0; obstacleIndex < obstacles.length; obstacleIndex++) {
const obstacle = obstacles[obstacleIndex];
if (polygonsIntersect(polygon, obstacle)) {
const point = contactPoint(polygon, obstacle);
if (!contact) {
contact = {
distance: 0,
a: point,
b: point,
obstacleIndex
};
}
} else {
const result = polygonDistance(polygon, obstacle);
if (!nearest || result.distance < nearest.distance) {
nearest = {
...result,
obstacleIndex
};
}
}
}
return contact || nearest;
}
let sweepMinimum = Infinity;
let sweepHasCollision = false;
function recomputeSweepClearance() {
sweepMinimum = Infinity;
sweepHasCollision = false;
for (const sample of allSweepSamples) {
for (let i = 0; i < obstacles.length; i++) {
const obstacle = obstacles[i];
if (polygonsIntersect(sample.polygon, obstacle)) {
sweepMinimum = 0;
sweepHasCollision = true;
} else {
const result = polygonDistance(sample.polygon, obstacle);
sweepMinimum = Math.min(sweepMinimum, result.distance);
}
}
}
sweepClearanceEl.textContent =
sweepMinimum < 0.0005
? "0 mm"
: `${Math.round(sweepMinimum * 1000)} mm`;
const collisionColor = new THREE.Color(0xff6178);
const envelopeColor = new THREE.Color(0xffc45e);
envelopeMaterial.color.copy(
sweepHasCollision ? collisionColor : envelopeColor
);
envelopeLines.material.color.copy(
sweepHasCollision ? collisionColor : envelopeColor
);
}
// -------------------------------------------------------------------------
// Live clearance visualization
// -------------------------------------------------------------------------
const clearanceGeometry = new THREE.BufferGeometry();
clearanceGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const clearanceLineMaterial = new THREE.LineBasicMaterial({
color: 0x5ee7c4,
transparent: true,
opacity: 0.95,
depthTest: false
});
const clearanceLine = new THREE.Line(
clearanceGeometry,
clearanceLineMaterial
);
clearanceLine.frustumCulled = false;
clearanceLine.renderOrder = 20;
scene.add(clearanceLine);
const clearancePointMaterial = new THREE.MeshBasicMaterial({
color: 0x5ee7c4,
depthTest: false
});
const clearancePointA = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 12, 8),
clearancePointMaterial
);
const clearancePointB = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 12, 8),
clearancePointMaterial
);
clearancePointA.renderOrder = 21;
clearancePointB.renderOrder = 21;
scene.add(clearancePointA, clearancePointB);
const contactRing = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.018, 8, 32),
new THREE.MeshBasicMaterial({
color: 0xff6178,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
contactRing.rotation.x = Math.PI / 2;
contactRing.position.y = 0.085;
contactRing.visible = false;
contactRing.renderOrder = 22;
scene.add(contactRing);
const COLORS = {
clear: new THREE.Color(0x5ee7c4),
tight: new THREE.Color(0xffc45e),
contact: new THREE.Color(0xff6178)
};
function setWallCollisionState(obstacleIndex) {
wallMaterialLeft.emissive.setHex(0x000000);
wallMaterialRight.emissive.setHex(0x000000);
wallMaterialLeft.emissiveIntensity = 0;
wallMaterialRight.emissiveIntensity = 0;
trimMaterialLeft.color.setHex(0x5ee7c4);
trimMaterialRight.color.setHex(0x5ee7c4);
if (obstacleIndex === 0) {
wallMaterialLeft.emissive.setHex(0x5b1020);
wallMaterialLeft.emissiveIntensity = 0.75;
trimMaterialLeft.color.setHex(0xff6178);
} else if (obstacleIndex === 1) {
wallMaterialRight.emissive.setHex(0x5b1020);
wallMaterialRight.emissiveIntensity = 0.75;
trimMaterialRight.color.setHex(0xff6178);
}
}
function updateClearanceVisual(result) {
const positions = clearanceGeometry.attributes.position;
if (!result) {
positions.setXYZ(0, 0, 0, 0);
positions.setXYZ(1, 0, 0, 0);
positions.needsUpdate = true;
clearanceLine.visible = false;
clearancePointA.visible = false;
clearancePointB.visible = false;
return;
}
positions.setXYZ(
0,
result.a.x,
0.082,
result.a.z
);
positions.setXYZ(
1,
result.b.x,
0.082,
result.b.z
);
positions.needsUpdate = true;
clearanceLine.visible = true;
clearancePointA.visible = true;
clearancePointB.visible = true;
clearancePointA.position.set(result.a.x, 0.082, result.a.z);
clearancePointB.position.set(result.b.x, 0.082, result.b.z);
contactRing.visible = result.distance < 0.0005;
if (contactRing.visible) {
contactRing.position.set(
(result.a.x + result.b.x) / 2,
0.085,
(result.a.z + result.b.z) / 2
);
}
}
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const duration = 12;
let elapsed = 0;
let progress = 0;
let playing = true;
let lastTime = performance.now();
function updatePlayButton() {
playButton.textContent = playing ? "❚❚ Pause" : "▶ Play";
}
function setProgress(value) {
progress = THREE.MathUtils.clamp(value, 0, 1);
elapsed = progress * duration;
timeline.value = Math.round(progress * 1000);
timeReadout.textContent = `${elapsed.toFixed(1)} / ${duration}s`;
}
function resetPlayback() {
setProgress(0);
playing = true;
updatePlayButton();
}
function updateChairPose(u) {
const pose = poseAt(u);
chair.position.set(pose.x, 0, pose.z);
chair.rotation.y = pose.yaw;
const wheelRotation = progress * pathLength;
for (const wheel of rearWheelGroups) {
wheel.rotation.x = wheelRotation / 0.31;
}
for (const wheel of frontWheelGroups) {
wheel.rotation.x = wheelRotation / 0.09;
}
const worldFootprint = transformFootprint(pose);
const result = evaluatePose(worldFootprint);
const distance = result ? result.distance : Infinity;
const hasContact = distance < 0.0005;
const isTight = !hasContact && distance < 0.14;
let stateColor = COLORS.clear;
if (hasContact) stateColor = COLORS.contact;
else if (isTight) stateColor = COLORS.tight;
footprintMaterial.color.copy(stateColor);
footprintOutlineMaterial.color.copy(stateColor);
clearanceLineMaterial.color.copy(stateColor);
clearancePointMaterial.color.copy(stateColor);
if (hasContact) {
setWallCollisionState(result.obstacleIndex);
} else {
setWallCollisionState(-1);
}
updateClearanceVisual(result);
liveClearanceEl.textContent =
distance === Infinity
? "—"
: `${Math.round(distance * 1000)} mm`;
headingReadout.textContent = `${THREE.MathUtils.radToDeg(pose.yaw).toFixed(1)}°`;
statusEl.classList.remove("tight", "contact");
if (hasContact) {
statusEl.classList.add("contact");
statusEl.textContent = `Contact · ${result.obstacleIndex === 0 ? "Left" : "Right"} jamb`;
} else if (isTight) {
statusEl.classList.add("tight");
statusEl.textContent = `Tight · ${Math.round(distance * 1000)} mm`;
} else {
statusEl.textContent = `Clear · ${Math.round(distance * 1000)} mm`;
}
if (hasContact) {
eventTextEl.textContent =
"The rigid footprint intersects the jamb. The proxy is not scaled or clipped to conceal the contact.";
} else if (sweepHasCollision) {
eventTextEl.textContent =
"The sampled turn envelope contains a jamb contact. Red envelope areas mark the potential conflict.";
} else if (sweepMinimum < 0.14) {
eventTextEl.textContent =
"The turn clears the jambs, but the swept footprint leaves limited maneuvering margin.";
} else {
eventTextEl.textContent =
"Every sampled pose clears both jambs without reducing the wheelchair footprint.";
}
return pose;
}
// -------------------------------------------------------------------------
// Custom camera controls — no Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.67,
phi: 0.82,
radius: 8.2,
target: new THREE.Vector3(0, 0.52, -0.12)
};
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = 0.67;
cameraState.phi = 0.82;
cameraState.radius = 8.2;
cameraState.target.set(0, 0.52, -0.12);
applyCamera();
}
function topCamera() {
cameraState.theta = 0;
cameraState.phi = 0.055;
cameraState.radius = 7.0;
cameraState.target.set(0, 0.1, 0.0);
applyCamera();
}
let dragging = false;
let draggingWithPan = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
draggingWithPan =
event.button === 2 || event.button === 1 || event.shiftKey;
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;
if (draggingWithPan) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(0, 0, -1).applyQuaternion(
camera.quaternion
);
forward.y = 0;
forward.normalize();
cameraState.target.addScaledVector(
right,
-dx * cameraState.radius * 0.0014
);
cameraState.target.addScaledVector(
forward,
-dy * cameraState.radius * 0.0014
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.055,
1.42
);
}
applyCamera();
});
function endDrag(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
3.7,
14
);
applyCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
doorWidthInput.addEventListener("input", () => {
updateDoorWidth(Number(doorWidthInput.value));
});
stressButton.addEventListener("click", () => {
updateDoorWidth(0.90);
resetPlayback();
});
safeButton.addEventListener("click", () => {
updateDoorWidth(1.20);
resetPlayback();
});
playButton.addEventListener("click", () => {
if (progress >= 1) {
setProgress(0);
}
playing = !playing;
updatePlayButton();
});
replayButton.addEventListener("click", resetPlayback);
timeline.addEventListener("input", () => {
playing = false;
updatePlayButton();
setProgress(Number(timeline.value) / 1000);
});
window.addEventListener("keydown", (event) => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLSelectElement ||
event.target instanceof HTMLButtonElement
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
playing = !playing;
updatePlayButton();
} else if (event.key.toLowerCase() === "r") {
resetPlayback();
} else if (event.key.toLowerCase() === "t") {
topCamera();
} else if (event.key.toLowerCase() === "c") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
updateDoorWidth(1.20);
updateChairPose(0);
applyCamera();
updatePlayButton();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
elapsed += dt;
if (elapsed >= duration) {
elapsed = duration;
playing = false;
updatePlayButton();
}
setProgress(elapsed / duration);
}
updateChairPose(progress);
if (contactRing.visible) {
const pulse = 1 + Math.sin(now * 0.012) * 0.16;
contactRing.scale.setScalar(pulse);
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```