Prompt specification
Build or customize the Three.js 3D scene "Library Counter Access Comparison" 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: Library Counter Access Comparison
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/library-counter-access-comparison-x3202
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing accessibility across different abilities and ways of moving. Show a service counter with high and low sections, knee clearance, and turning space. Move a simple wheelchair proxy through the layout without clipping furniture. Stylized solid forms.
Working Three.js Starter (library-counter-access-comparison-x3202):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Accessible Service Counter — Three.js</title>
<style>
:root {
--ink: #17383d;
--muted: #607477;
--panel: rgba(249, 251, 247, 0.94);
--line: rgba(23, 56, 61, 0.13);
--teal: #167d7a;
--teal-light: #d9efea;
--orange: #d4773f;
--orange-light: #f8e5d6;
--purple: #6e628d;
--shadow: 0 18px 50px rgba(31, 55, 54, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #e8eee9;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.wash {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(90deg, rgba(238, 244, 239, 0.34), transparent 36%),
linear-gradient(0deg, rgba(28, 55, 54, 0.08), transparent 26%);
z-index: 1;
}
.hero {
position: fixed;
z-index: 6;
top: 24px;
left: 28px;
width: min(570px, calc(100vw - 410px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
padding: 7px 11px;
border: 1px solid rgba(23, 56, 61, 0.13);
border-radius: 999px;
color: var(--teal);
background: rgba(250, 252, 248, 0.8);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 125, 122, 0.12);
}
h1 {
margin: 0;
max-width: 550px;
font-size: clamp(30px, 4.1vw, 55px);
line-height: 0.98;
letter-spacing: -0.052em;
text-wrap: balance;
}
.hero p {
max-width: 510px;
margin: 15px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
right: 20px;
width: 340px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 24px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
}
.panel h2 {
margin: 3px 0 5px;
font-size: 20px;
letter-spacing: -0.025em;
}
.panel-intro {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.section-label {
margin: 18px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.profiles {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.profile {
min-height: 68px;
padding: 9px 5px;
border: 1px solid var(--line);
border-radius: 14px;
color: var(--ink);
background: rgba(255, 255, 255, 0.62);
cursor: pointer;
transition:
transform 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
.profile:hover {
transform: translateY(-1px);
border-color: rgba(22, 125, 122, 0.45);
}
.profile[aria-pressed="true"] {
border-color: var(--teal);
background: var(--teal-light);
box-shadow: inset 0 0 0 1px rgba(22, 125, 122, 0.08);
}
.profile svg {
display: block;
width: 28px;
height: 24px;
margin: 0 auto 4px;
color: var(--teal);
}
.profile span {
display: block;
font-size: 11px;
font-weight: 750;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
min-height: 70px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.54);
}
.metric strong {
display: block;
margin-bottom: 4px;
font-size: 20px;
letter-spacing: -0.04em;
}
.metric span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.progress-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 56, 61, 0.09);
}
.progress-fill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), #4fb4a3);
transition: width 120ms linear;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 8px 0 13px;
}
#status {
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.status-dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 6px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 125, 122, 0.1);
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.action {
min-height: 39px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
background: rgba(255, 255, 255, 0.68);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.action:hover {
transform: translateY(-1px);
border-color: rgba(22, 125, 122, 0.45);
background: white;
}
.action.primary {
border-color: var(--teal);
color: white;
background: var(--teal);
}
.action[aria-pressed="true"] {
border-color: var(--teal);
color: var(--teal);
background: var(--teal-light);
}
.features {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.feature {
padding: 6px 8px;
border-radius: 999px;
color: #385d5c;
background: rgba(22, 125, 122, 0.08);
font-size: 10px;
font-weight: 650;
}
.note {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #728184;
font-size: 10px;
line-height: 1.45;
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: 145px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-left: 4px solid var(--teal);
border-radius: 11px;
background: rgba(250, 252, 248, 0.9);
box-shadow: 0 8px 24px rgba(39, 67, 64, 0.13);
backdrop-filter: blur(9px);
transform: translate(-50%, -50%);
}
.scene-label b {
display: block;
margin-bottom: 2px;
font-size: 10px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.scene-label span {
display: block;
color: var(--muted);
font-size: 10px;
white-space: nowrap;
}
.scene-label.high {
border-left-color: var(--orange);
}
.scene-label.mini {
min-width: auto;
padding: 6px 9px;
border-left-width: 3px;
border-radius: 999px;
}
.scene-label.mini b {
margin: 0;
font-size: 9px;
}
.controls-hint {
position: fixed;
z-index: 6;
left: 28px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 999px;
background: rgba(249, 251, 247, 0.78);
box-shadow: 0 7px 24px rgba(33, 59, 57, 0.09);
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(10px);
pointer-events: none;
}
.controls-hint strong {
color: var(--ink);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #e8eee9;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 850px) {
.hero {
top: 16px;
left: 16px;
width: calc(100vw - 32px);
}
h1 {
max-width: 460px;
font-size: 32px;
}
.hero p {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 43vh;
padding: 15px;
border-radius: 20px;
}
.panel h2,
.panel-intro,
.note {
display: none;
}
.section-label {
margin-top: 12px;
}
.metrics {
grid-template-columns: repeat(4, 1fr);
}
.metric {
min-height: 57px;
padding: 8px;
}
.metric strong {
font-size: 16px;
}
.metric span {
font-size: 8px;
}
.controls-hint {
display: none;
}
.scene-label:not(.priority) {
display: none !important;
}
}
@media (max-width: 520px) {
.profiles {
gap: 5px;
}
.profile {
min-height: 59px;
}
.profile span {
font-size: 9px;
}
.metrics {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D accessible service counter"></canvas>
<div class="wash"></div>
<header class="hero">
<div class="eyebrow">Access / Motion Lab</div>
<h1>One service point.<br>More ways to arrive.</h1>
<p>
Compare a wheelchair, walker, and cane through a step-free service area.
Routes use a conservative clearance envelope and are planned around the
furniture.
</p>
</header>
<aside class="panel" aria-label="Simulation controls">
<h2>Movement profile</h2>
<p class="panel-intro">
Switch profiles to rebuild the route using each movement’s footprint.
</p>
<div class="section-label">Choose a proxy</div>
<div class="profiles" role="group" aria-label="Movement profile">
<button class="profile" data-profile="wheelchair" aria-pressed="true">
<svg viewBox="0 0 32 26" fill="none" aria-hidden="true">
<circle cx="10" cy="18" r="6" stroke="currentColor" stroke-width="2"/>
<circle cx="23" cy="21" r="2.5" stroke="currentColor" stroke-width="2"/>
<path d="M10 12v6h9l4 3M12 8h8v7M20 5h4v5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
<span>Wheelchair</span>
</button>
<button class="profile" data-profile="walker" aria-pressed="false">
<svg viewBox="0 0 32 26" fill="none" aria-hidden="true">
<circle cx="15" cy="5" r="3" stroke="currentColor" stroke-width="2"/>
<path d="M15 9v8l-4 7M15 13h7l3 8M8 11v10h12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span>Walker</span>
</button>
<button class="profile" data-profile="cane" aria-pressed="false">
<svg viewBox="0 0 32 26" fill="none" aria-hidden="true">
<circle cx="15" cy="5" r="3" stroke="currentColor" stroke-width="2"/>
<path d="M15 9v8l-3 7M15 12h7l2 11" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
<span>Cane</span>
</button>
</div>
<div class="section-label">Live clearances</div>
<div class="metrics">
<div class="metric">
<strong id="envelope">1.24 m</strong>
<span>Swept route envelope</span>
</div>
<div class="metric">
<strong id="route-length">—</strong>
<span>Route length</span>
</div>
<div class="metric">
<strong>1.60 m</strong>
<span>Turning circle</span>
</div>
<div class="metric">
<strong>0.78 m</strong>
<span>Low counter top</span>
</div>
</div>
<div class="section-label">Journey</div>
<div class="progress-track" aria-hidden="true">
<div class="progress-fill" id="progress"></div>
</div>
<div class="status-row">
<div id="status" aria-live="polite">
<span class="status-dot"></span>Preparing the accessible route…
</div>
</div>
<div class="actions">
<button class="action primary" id="play">Pause motion</button>
<button class="action" id="restart">Restart route</button>
<button class="action" id="iso-view">Isometric view</button>
<button class="action" id="top-view">Top view</button>
<button class="action" id="toggle-labels" aria-pressed="true">
Show labels
</button>
</div>
<div class="section-label">Inclusive features</div>
<div class="features">
<span class="feature">Step-free floor</span>
<span class="feature">High + low counters</span>
<span class="feature">Knee clearance</span>
<span class="feature">Turning space</span>
<span class="feature">Visual + hearing alerts</span>
<span class="feature">Quiet waiting</span>
</div>
<p class="note">
Concept dimensions use a conservative clearance envelope. This model is
an accessibility communication aid, not a local code-compliance plan.
</p>
</aside>
<div id="labels" aria-hidden="true"></div>
<div class="controls-hint">
<strong>Drag</strong> to orbit
<span>·</span>
<strong>Scroll</strong> to zoom
<span>·</span>
<strong>Arrows</strong> rotate
<span>·</span>
<strong>Space</strong> play / pause
</div>
<div id="loading">Building accessible space…</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 scene
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eee9);
scene.fog = new THREE.Fog(0xe8eee9, 28, 52);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xf7fbf7, 0x83938d, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff6df, 3.1);
sun.position.set(7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d8d5, 0.7);
fill.position.set(-8, 6, -2);
scene.add(fill);
const cameraState = {
target: new THREE.Vector3(-0.65, 0.25, -0.65),
yaw: 0.62,
pitch: 0.69,
radius: 17.8
};
function updateCamera() {
const { target, yaw, pitch, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
updateCamera();
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 650 ? 54 : 38;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Stylized solid-form helpers
// -------------------------------------------------------------------------
const material = (color, roughness = 0.82, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
const MAT = {
floor: material(0xf3f0e7),
wall: material(0xe4e9df),
wallTrim: material(0xd1dcd2),
cream: material(0xe9e3d5),
white: material(0xfbfcf7),
wood: material(0xb9825b),
woodDark: material(0x8c6046),
teal: material(0x167d7a),
tealDark: material(0x27575c),
tealPale: material(0x9bc8bf),
orange: material(0xd4773f),
orangePale: material(0xefc6a9),
purple: material(0x6e628d),
metal: material(0x66777a, 0.48, 0.22),
dark: material(0x263d40),
leaf: material(0x557c56),
leafLight: material(0x78986a),
soil: material(0x594c43)
};
function addBox(parent, size, position, mat) {
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 = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
topRadius,
bottomRadius,
height,
position,
mat,
segments = 24
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, radius, position, mat) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 20, 14),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(parent, start, end, radius, mat) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 12),
mat
);
mesh.position.copy(a).add(b).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;
}
function addTorus(parent, radius, tube, position, mat) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 10, 36),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createWallSign(title, subtitle, width, height, x, y, z, background) {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const ctx = signCanvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, 1024, 256);
ctx.fillStyle = "#e4b35e";
ctx.fillRect(0, 0, 28, 256);
ctx.textAlign = "center";
ctx.fillStyle = "#f8fbf7";
ctx.font = "800 82px system-ui, sans-serif";
ctx.fillText(title, 512, subtitle ? 112 : 148);
if (subtitle) {
ctx.fillStyle = "#d7e8e3";
ctx.font = "650 32px system-ui, sans-serif";
ctx.fillText(subtitle, 512, 178);
}
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
})
);
sign.position.set(x, y, z);
scene.add(sign);
return sign;
}
// -------------------------------------------------------------------------
// Architectural layout, measured in approximate meters
// -------------------------------------------------------------------------
addBox(scene, [18, 0.18, 11.5], [0, -0.1, 0], MAT.floor);
addBox(scene, [18, 3.7, 0.18], [0, 1.75, -5.65], MAT.wall);
addBox(scene, [18, 0.12, 0.06], [0, 0.06, -5.53], MAT.wallTrim);
const floorGrid = new THREE.GridHelper(18, 36, 0xa9b8af, 0xc9d1c8);
floorGrid.position.y = 0.002;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.19;
scene.add(floorGrid);
// High service section: 1.10 m top.
addBox(scene, [4.4, 0.98, 0.72], [-2.75, 0.49, -3.84], MAT.cream);
addBox(scene, [4.6, 0.12, 0.92], [-2.75, 1.04, -3.82], MAT.wood);
addBox(
scene,
[4.38, 0.08, 0.035],
[-2.75, 0.82, -3.465],
MAT.orange
);
// Low service section:
// 0.78 m top, 0.70 m underside, approximately 0.66 m knee depth.
addBox(scene, [3.9, 0.08, 0.92], [2.55, 0.74, -3.82], MAT.wood);
addBox(scene, [0.8, 0.70, 0.72], [1.05, 0.35, -3.84], MAT.cream);
addBox(scene, [0.16, 0.70, 0.72], [4.38, 0.35, -3.84], MAT.cream);
addBox(scene, [3.55, 0.70, 0.12], [2.55, 0.35, -4.08], MAT.cream);
addBox(
scene,
[3.87, 0.05, 0.035],
[2.55, 0.69, -3.345],
MAT.teal
);
// A terminal on the high counter.
addBox(scene, [0.48, 0.05, 0.35], [-1.2, 1.125, -3.78], MAT.dark);
addCylinder(
scene,
0.035,
0.035,
0.17,
[-1.2, 1.205, -3.78],
MAT.metal,
12
);
addBox(
scene,
[0.5, 0.31, 0.05],
[-1.2, 1.39, -3.87],
MAT.tealDark
);
// Service bell on the accessible counter.
addCylinder(scene, 0.11, 0.13, 0.035, [3.92, 0.797, -3.73], MAT.metal, 20);
addSphere(scene, 0.075, [3.92, 0.85, -3.73], MAT.orange);
// 1.50 m highlighted knee-clearance footprint.
const kneePoints = [
new THREE.Vector3(1.80, 0.025, -3.96),
new THREE.Vector3(3.30, 0.025, -3.96),
new THREE.Vector3(3.30, 0.025, -3.28),
new THREE.Vector3(1.80, 0.025, -3.28),
new THREE.Vector3(1.80, 0.025, -3.96)
];
const kneeGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(kneePoints),
new THREE.LineDashedMaterial({
color: 0x167d7a,
dashSize: 0.11,
gapSize: 0.07,
transparent: true,
opacity: 0.55
})
);
kneeGuide.computeLineDistances();
scene.add(kneeGuide);
// Central information island: a real pathfinding obstacle.
addBox(scene, [2.2, 0.75, 1.1], [-1.6, 0.375, 0.15], MAT.tealDark);
addBox(scene, [2.35, 0.08, 1.2], [-1.6, 0.79, 0.15], MAT.wood);
addBox(scene, [0.42, 0.17, 0.32], [-2.1, 0.915, 0.12], MAT.orangePale);
addBox(scene, [0.34, 0.23, 0.28], [-1.5, 0.945, 0.17], MAT.tealPale);
addBox(scene, [0.28, 0.19, 0.26], [-0.95, 0.925, 0.12], MAT.white);
// Quiet waiting area.
addBox(scene, [2.9, 0.014, 1.4], [6.05, 0.002, 1.8], MAT.orangePale);
addBox(scene, [2.2, 0.13, 0.62], [6.1, 0.46, 1.75], MAT.wood);
addBox(scene, [2.2, 0.56, 0.12], [6.1, 0.79, 1.42], MAT.woodDark);
addBox(scene, [0.12, 0.43, 0.12], [5.25, 0.215, 1.75], MAT.metal);
addBox(scene, [0.12, 0.43, 0.12], [6.95, 0.215, 1.75], MAT.metal);
// Stylized planter.
addCylinder(scene, 0.56, 0.46, 0.62, [-7.0, 0.31, -0.7], MAT.cream, 18);
addCylinder(scene, 0.49, 0.49, 0.035, [-7.0, 0.64, -0.7], MAT.soil, 18);
addSphere(scene, 0.55, [-7.0, 1.03, -0.7], MAT.leaf);
addSphere(scene, 0.35, [-7.28, 1.32, -0.68], MAT.leafLight);
addSphere(scene, 0.31, [-6.73, 1.38, -0.75], MAT.leaf);
// Assistance sign post.
addCylinder(scene, 0.035, 0.045, 1.35, [5.85, 0.675, -1.2], MAT.metal, 12);
addBox(scene, [0.58, 0.28, 0.06], [5.85, 1.2, -1.2], MAT.tealDark);
// 1.60 m turning space.
const turnCenter = new THREE.Vector2(2.55, -1.45);
const turnFill = new THREE.Mesh(
new THREE.CircleGeometry(0.8, 64),
new THREE.MeshBasicMaterial({
color: 0x167d7a,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
})
);
turnFill.rotation.x = -Math.PI / 2;
turnFill.position.set(turnCenter.x, 0.011, turnCenter.y);
scene.add(turnFill);
const turnRing = addTorus(
scene,
0.8,
0.022,
[turnCenter.x, 0.025, turnCenter.y],
MAT.teal
);
turnRing.rotation.x = Math.PI / 2;
// Wall-mounted inclusive wayfinding.
createWallSign(
"SERVICE",
"HIGH + LOW COUNTERS",
4.8,
1.0,
-1.1,
2.55,
-5.535,
"#27575c"
);
createWallSign(
"ASSISTANCE",
"VISUAL + HEARING ALERTS",
3.0,
0.75,
-6.45,
2.15,
-5.535,
"#167d7a"
);
createWallSign(
"QUIET WAITING",
"SEATING + SUPPORT",
2.7,
0.7,
6.05,
2.15,
-5.535,
"#8c6046"
);
// -------------------------------------------------------------------------
// Movement profiles and proxy geometry
// -------------------------------------------------------------------------
const PROFILES = {
wheelchair: {
name: "Wheelchair",
radius: 0.62,
clearance: 1.24,
speed: 0.85,
color: 0x167d7a
},
walker: {
name: "Walker",
radius: 0.43,
clearance: 0.86,
speed: 0.76,
color: 0xd4773f
},
cane: {
name: "Cane",
radius: 0.34,
clearance: 0.68,
speed: 0.68,
color: 0x6e628d
}
};
let activeProfileKey = "wheelchair";
let activeProfile = PROFILES.wheelchair;
let agent = null;
function buildWheelchairProxy() {
const root = new THREE.Group();
const frame = material(0x294f54, 0.56, 0.08);
const upholstery = material(0x167d7a, 0.9);
const person = material(0xe4a269, 0.92);
const clothes = material(0x365c67, 0.9);
const skin = material(0xd9aa83, 0.92);
const wheels = [];
[-0.34, 0.34].forEach((x) => {
const pivot = new THREE.Group();
pivot.position.set(x, 0.3, -0.08);
root.add(pivot);
const tire = addTorus(pivot, 0.28, 0.045, [0, 0, 0], MAT.dark);
tire.rotation.y = Math.PI / 2;
const hub = addCylinder(pivot, 0.052, 0.052, 0.07, [0, 0, 0], MAT.metal, 14);
hub.rotation.z = Math.PI / 2;
addBox(pivot, [0.024, 0.49, 0.024], [0, 0, 0], MAT.metal);
addBox(pivot, [0.024, 0.024, 0.49], [0, 0, 0], MAT.metal);
wheels.push(pivot);
});
[-0.29, 0.29].forEach((x) => {
const pivot = new THREE.Group();
pivot.position.set(x, 0.095, 0.43);
root.add(pivot);
const caster = addTorus(pivot, 0.082, 0.027, [0, 0, 0], MAT.dark);
caster.rotation.y = Math.PI / 2;
wheels.push(pivot);
});
addBox(root, [0.58, 0.10, 0.53], [0, 0.56, 0.01], upholstery);
addBox(root, [0.58, 0.57, 0.09], [0, 0.85, -0.27], upholstery);
addBox(root, [0.62, 0.07, 0.07], [0, 0.25, -0.11], frame);
addBox(root, [0.62, 0.07, 0.07], [0, 0.25, 0.36], frame);
addCylinderBetween(root, [-0.28, 0.25, -0.26], [-0.28, 0.66, -0.26], 0.024, frame);
addCylinderBetween(root, [0.28, 0.25, -0.26], [0.28, 0.66, -0.26], 0.024, frame);
addCylinderBetween(root, [-0.28, 0.66, -0.28], [-0.28, 0.72, -0.38], 0.024, frame);
addCylinderBetween(root, [0.28, 0.66, -0.28], [0.28, 0.72, -0.38], 0.024, frame);
addCylinder(root, 0.17, 0.20, 0.39, [0, 0.84, 0.02], clothes, 16);
addSphere(root, 0.135, [0, 1.16, 0.02], skin);
addCylinderBetween(root, [-0.15, 0.99, 0.01], [-0.24, 0.72, 0.18], 0.052, clothes);
addCylinderBetween(root, [0.15, 0.99, 0.01], [0.24, 0.72, 0.18], 0.052, clothes);
addCylinderBetween(root, [-0.14, 0.64, 0.08], [-0.14, 0.31, 0.32], 0.058, person);
addCylinderBetween(root, [0.14, 0.64, 0.08], [0.14, 0.31, 0.32], 0.058, person);
addBox(root, [0.13, 0.09, 0.24], [-0.14, 0.22, 0.40], MAT.dark);
addBox(root, [0.13, 0.09, 0.24], [0.14, 0.22, 0.40], MAT.dark);
root.userData.wheels = wheels;
return root;
}
function buildWalkerProxy() {
const root = new THREE.Group();
const frame = material(0xc66b38, 0.55, 0.12);
const clothes = material(0x657c73, 0.9);
const skin = material(0xd9aa83, 0.92);
addSphere(root, 0.135, [0, 1.22, 0], skin);
addCylinder(root, 0.17, 0.20, 0.42, [0, 0.91, 0], clothes, 16);
addCylinderBetween(root, [-0.14, 1.06, 0], [-0.25, 0.76, 0.14], 0.052, clothes);
addCylinderBetween(root, [0.14, 1.06, 0], [0.25, 0.76, 0.14], 0.052, clothes);
addCylinderBetween(root, [-0.11, 0.71, 0], [-0.15, 0.13, 0.04], 0.065, clothes);
addCylinderBetween(root, [0.11, 0.71, 0], [0.16, 0.13, -0.05], 0.065, clothes);
addBox(root, [0.15, 0.09, 0.27], [-0.15, 0.06, 0.13], MAT.dark);
addBox(root, [0.15, 0.09, 0.27], [0.16, 0.06, 0.02], MAT.dark);
[-0.26, 0.26].forEach((x) => {
addCylinderBetween(root, [x, 0.83, -0.13], [x, 0.83, 0.30], 0.022, frame);
addCylinderBetween(root, [x, 0.83, 0.30], [x, 0.16, 0.30], 0.022, frame);
addCylinderBetween(root, [x, 0.83, -0.13], [x, 0.17, -0.13], 0.022, frame);
addCylinderBetween(root, [x, 0.16, 0.30], [x, 0.16, -0.13], 0.022, frame);
});
return root;
}
function buildCaneProxy() {
const root = new THREE.Group();
const clothes = material(0x70668d, 0.9);
const skin = material(0xd9aa83, 0.92);
const cane = material(0x765842, 0.65);
addSphere(root, 0.135, [0, 1.22, 0], skin);
addCylinder(root, 0.17, 0.20, 0.42, [0, 0.91, 0], clothes, 16);
addCylinderBetween(root, [-0.14, 1.06, 0], [-0.24, 0.73, 0.10], 0.052, clothes);
addCylinderBetween(root, [0.14, 1.06, 0], [0.20, 0.72, 0.10], 0.052, clothes);
addCylinderBetween(root, [-0.11, 0.71, 0], [-0.15, 0.13, 0.04], 0.065, clothes);
addCylinderBetween(root, [0.11, 0.71, 0], [0.16, 0.13, -0.05], 0.065, clothes);
addBox(root, [0.15, 0.09, 0.27], [-0.15, 0.06, 0.13], MAT.dark);
addBox(root, [0.15, 0.09, 0.27], [0.16, 0.06, 0.02], MAT.dark);
addCylinderBetween(root, [0.20, 0.72, 0.10], [0.22, 0.02, 0.31], 0.018, cane);
return root;
}
function createAgent(profileKey) {
if (agent) {
agent.traverse((child) => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const list = Array.isArray(child.material)
? child.material
: [child.material];
list.forEach((mat) => mat.dispose());
}
});
agent.removeFromParent();
}
if (profileKey === "walker") {
agent = buildWalkerProxy();
} else if (profileKey === "cane") {
agent = buildCaneProxy();
} else {
agent = buildWheelchairProxy();
}
scene.add(agent);
}
// -------------------------------------------------------------------------
// Collision-aware A* pathfinding
//
// Every obstacle is inflated by the proxy's conservative radius. The
// resulting centerline therefore keeps the full proxy envelope clear.
// -------------------------------------------------------------------------
const OBSTACLES = [
{ minX: -5.0, maxX: -0.45, minZ: -4.35, maxZ: -3.35 }, // high counter
{ minX: 0.65, maxX: 4.55, minZ: -4.35, maxZ: -3.35 }, // low counter
{ minX: -2.95, maxX: -0.65, minZ: -0.35, maxZ: 0.95 }, // island
{ minX: 4.85, maxX: 7.15, minZ: 1.38, maxZ: 2.20 }, // bench
{ minX: -7.58, maxX: -6.42, minZ: -1.30, maxZ: -0.10 },// planter
{ minX: 5.52, maxX: 6.18, minZ: -1.48, maxZ: -0.92 } // sign post
];
const START = new THREE.Vector2(-6.45, 4.35);
const GOAL = new THREE.Vector2(2.55, -2.35);
class MinHeap {
constructor() {
this.items = [];
}
push(item) {
this.items.push(item);
let index = this.items.length - 1;
while (index > 0) {
const parent = Math.floor((index - 1) / 2);
if (this.items[parent].f <= item.f) break;
this.items[index] = this.items[parent];
index = parent;
}
this.items[index] = item;
}
pop() {
if (!this.items.length) return null;
const root = this.items[0];
const last = this.items.pop();
if (this.items.length) {
let index = 0;
while (true) {
const left = index * 2 + 1;
const right = left + 1;
if (left >= this.items.length) break;
let child = left;
if (
right < this.items.length &&
this.items[right].f < this.items[left].f
) {
child = right;
}
if (this.items[child].f >= last.f) break;
this.items[index] = this.items[child];
index = child;
}
this.items[index] = last;
}
return root;
}
get size() {
return this.items.length;
}
}
function calculateRoute(radius) {
const bounds = {
minX: -8.2,
maxX: 8.2,
minZ: -5.0,
maxZ: 5.25
};
const step = 0.22;
const columns = Math.floor((bounds.maxX - bounds.minX) / step) + 1;
const rows = Math.floor((bounds.maxZ - bounds.minZ) / step) + 1;
const total = columns * rows;
const centerOf = (index) => {
const row = Math.floor(index / columns);
const column = index - row * columns;
return new THREE.Vector2(
bounds.minX + (column + 0.5) * step,
bounds.minZ + (row + 0.5) * step
);
};
const blocked = (x, z) => {
for (const obstacle of OBSTACLES) {
if (
x > obstacle.minX - radius &&
x < obstacle.maxX + radius &&
z > obstacle.minZ - radius &&
z < obstacle.maxZ + radius
) {
return true;
}
}
return false;
};
const nearestCell = (point) => {
let best = -1;
let bestDistance = Infinity;
for (let i = 0; i < total; i++) {
const center = centerOf(i);
if (blocked(center.x, center.y)) continue;
const distance =
(center.x - point.x) ** 2 + (center.y - point.y) ** 2;
if (distance < bestDistance) {
bestDistance = distance;
best = i;
}
}
return best;
};
const segmentClear = (a, b) => {
const distance = a.distanceTo(b);
const samples = Math.max(2, Math.ceil(distance / 0.07));
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 (blocked(x, z)) return false;
}
return true;
};
const startIndex = nearestCell(START);
const goalIndex = nearestCell(GOAL);
if (startIndex < 0 || goalIndex < 0) return [];
const costs = new Float32Array(total);
costs.fill(Infinity);
const previous = new Int32Array(total);
previous.fill(-1);
const closed = new Uint8Array(total);
const open = new MinHeap();
const heuristic = (index) => {
const a = centerOf(index);
const dx = Math.abs(a.x - GOAL.x);
const dz = Math.abs(a.y - GOAL.y);
const diagonal = Math.min(dx, dz);
return (diagonal * Math.SQRT2 + (dx + dz - diagonal * 2)) * step;
};
costs[startIndex] = 0;
open.push({ index: startIndex, f: heuristic(startIndex) });
const directions = [
[-1, -1], [0, -1], [1, -1],
[-1, 0], [1, 0],
[-1, 1], [0, 1], [1, 1]
];
while (open.size) {
const current = open.pop();
if (closed[current.index]) continue;
if (current.index === goalIndex) break;
closed[current.index] = 1;
const currentCenter = centerOf(current.index);
const row = Math.floor(current.index / columns);
const column = current.index - row * columns;
for (const [dx, dz] of directions) {
const nextColumn = column + dx;
const nextRow = row + dz;
if (
nextColumn < 0 ||
nextColumn >= columns ||
nextRow < 0 ||
nextRow >= rows
) {
continue;
}
const nextIndex = nextRow * columns + nextColumn;
const nextCenter = centerOf(nextIndex);
if (closed[nextIndex] || blocked(nextCenter.x, nextCenter.y)) {
continue;
}
if (
dx !== 0 &&
dz !== 0 &&
(
blocked(
bounds.minX + (column + dx + 0.5) * step,
bounds.minZ + (row + 0.5) * step
) ||
blocked(
bounds.minX + (column + 0.5) * step,
bounds.minZ + (row + dz + 0.5) * step
)
)
) {
continue;
}
const movementCost = dx !== 0 && dz !== 0 ? Math.SQRT2 : 1;
const newCost = costs[current.index] + movementCost * step;
if (newCost + 1e-6 < costs[nextIndex]) {
costs[nextIndex] = newCost;
previous[nextIndex] = current.index;
open.push({
index: nextIndex,
f: newCost + heuristic(nextIndex)
});
}
}
}
if (previous[goalIndex] === -1 && startIndex !== goalIndex) {
return [];
}
const rawPath = [];
let cursor = goalIndex;
while (cursor !== -1) {
rawPath.push(centerOf(cursor));
if (cursor === startIndex) break;
cursor = previous[cursor];
}
rawPath.reverse();
if (segmentClear(rawPath[0], START)) {
rawPath.unshift(START.clone());
}
if (segmentClear(rawPath[rawPath.length - 1], GOAL)) {
rawPath.push(GOAL.clone());
}
// Simplify only when the entire straight segment preserves clearance.
const simplified = [rawPath[0]];
let current = 0;
while (current < rawPath.length - 1) {
let next = rawPath.length - 1;
while (
next > current + 1 &&
!segmentClear(rawPath[current], rawPath[next])
) {
next--;
}
simplified.push(rawPath[next]);
current = next;
}
return simplified;
}
// -------------------------------------------------------------------------
// Route graphics and journey state
// -------------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
let route = [];
let routeLength = 0;
let currentIndex = 0;
let journeyPhase = "out";
let phaseTimer = 0;
let playing = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const startPoint = new THREE.Mesh(
new THREE.RingGeometry(0.17, 0.22, 36),
new THREE.MeshBasicMaterial({
color: 0x6e628d,
side: THREE.DoubleSide
})
);
startPoint.rotation.x = -Math.PI / 2;
startPoint.position.set(START.x, 0.035, START.y);
scene.add(startPoint);
const goalPoint = new THREE.Mesh(
new THREE.RingGeometry(0.17, 0.22, 36),
new THREE.MeshBasicMaterial({
color: 0xd4773f,
side: THREE.DoubleSide
})
);
goalPoint.rotation.x = -Math.PI / 2;
goalPoint.position.set(GOAL.x, 0.038, GOAL.y);
scene.add(goalPoint);
function clearRouteGraphics() {
routeGroup.traverse((child) => {
if (child.geometry) child.geometry.dispose();
if (child.material) child.material.dispose();
});
routeGroup.clear();
}
function addCorridorSegment(a, b, width, color) {
const direction = new THREE.Vector3(b.x - a.x, 0, b.y - a.y);
const length = direction.length();
direction.normalize();
const perpendicular = new THREE.Vector3(
-direction.z,
0,
direction.x
).multiplyScalar(width / 2);
const p1 = new THREE.Vector3(a.x, 0.012, a.y);
const p2 = new THREE.Vector3(b.x, 0.012, b.y);
const vertices = new Float32Array([
p1.x + perpendicular.x, p1.y, p1.z + perpendicular.z,
p1.x - perpendicular.x, p1.y, p1.z - perpendicular.z,
p2.x - perpendicular.x, p2.y, p2.z - perpendicular.z,
p2.x + perpendicular.x, p2.y, p2.z + perpendicular.z
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(vertices, 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.085,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.renderOrder = 1;
routeGroup.add(mesh);
}
function buildRouteGraphics() {
clearRouteGraphics();
const color = activeProfile.color;
for (let i = 0; i < route.length - 1; i++) {
const a = route[i];
const b = route[i + 1];
addCorridorSegment(a, b, activeProfile.clearance, color);
addCylinderBetween(
routeGroup,
[a.x, 0.035, a.y],
[b.x, 0.035, b.y],
0.022,
material(color, 0.72)
);
}
route.forEach((point) => {
const dot = addCylinder(
routeGroup,
0.045,
0.045,
0.018,
[point.x, 0.045, point.y],
material(color, 0.7),
14
);
dot.castShadow = false;
});
}
function updateStatus(message) {
const status = document.getElementById("status");
const next = `<span class="status-dot"></span>${message}`;
if (status.innerHTML !== next) status.innerHTML = next;
}
function setPlaying(value) {
playing = value;
const button = document.getElementById("play");
button.textContent = playing ? "Pause motion" : "Play motion";
updateStatus(
playing
? "Following the clear route to the low counter."
: "Motion paused. The full clearance envelope remains visible."
);
}
function resetJourney() {
if (!agent || route.length === 0) return;
currentIndex = 0;
journeyPhase = "out";
phaseTimer = 0;
agent.position.set(route[0].x, 0, route[0].y);
if (route.length > 1) {
const next = route[1];
agent.rotation.y = Math.atan2(
next.x - route[0].x,
next.y - route[0].y
);
}
document.getElementById("progress").style.width = "0%";
updateStatus("Following the clear route to the low counter.");
}
function rebuildJourney(profileKey) {
activeProfileKey = profileKey;
activeProfile = PROFILES[profileKey];
route = calculateRoute(activeProfile.radius);
if (!route.length) {
route = [
START.clone(),
new THREE.Vector2(-4.7, 3.3),
new THREE.Vector2(-4.25, -1.55),
new THREE.Vector2(-0.1, -2.05),
new THREE.Vector2(1.7, -2.25),
GOAL.clone()
];
}
routeLength = route.slice(1).reduce((sum, point, index) => {
return sum + point.distanceTo(route[index]);
}, 0);
buildRouteGraphics();
createAgent(profileKey);
resetJourney();
document.getElementById("envelope").textContent =
`${activeProfile.clearance.toFixed(2)} m`;
document.getElementById("route-length").textContent =
`${routeLength.toFixed(1)} m`;
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelLayer = document.getElementById("labels");
const sceneLabels = [];
let labelsVisible = true;
function addSceneLabel(html, position, className = "") {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.innerHTML = html;
labelLayer.appendChild(element);
sceneLabels.push({
element,
position: new THREE.Vector3(...position)
});
}
addSceneLabel(
"<b>Low service counter</b><span>780 mm top · 700 mm clear</span>",
[2.55, 1.2, -3.72],
"priority"
);
addSceneLabel(
"<b>High service counter</b><span>1,100 mm standing height</span>",
[-2.75, 1.56, -3.74],
"high priority"
);
addSceneLabel(
"<b>Knee space</b><span>660 mm deep</span>",
[2.55, 0.33, -3.0],
"mini priority"
);
addSceneLabel(
"<b>Turning space</b><span>1.60 m diameter</span>",
[3.48, 0.22, -1.45],
"mini priority"
);
addSceneLabel(
"<b>Clear circulation</b><span>Furniture-aware route</span>",
[-3.65, 0.32, 2.35],
"mini"
);
addSceneLabel(
"<b>Quiet waiting</b><span>Supportive seating</span>",
[6.1, 1.15, 1.72],
"mini"
);
const projected = new THREE.Vector3();
const cameraDirection = new THREE.Vector3();
function updateLabels() {
camera.getWorldDirection(cameraDirection);
for (const label of sceneLabels) {
const toLabel = label.position.clone().sub(camera.position);
const inFront = toLabel.dot(cameraDirection) > 0;
projected.copy(label.position).project(camera);
const visible =
labelsVisible &&
inFront &&
projected.z > -1 &&
projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// -------------------------------------------------------------------------
// UI and camera controls implemented without external controls addons
// -------------------------------------------------------------------------
document.querySelectorAll("[data-profile]").forEach((button) => {
button.addEventListener("click", () => {
const key = button.dataset.profile;
document.querySelectorAll("[data-profile]").forEach((other) => {
other.setAttribute(
"aria-pressed",
String(other.dataset.profile === key)
);
});
rebuildJourney(key);
setPlaying(playing);
});
});
document.getElementById("play").addEventListener("click", () => {
setPlaying(!playing);
});
document.getElementById("restart").addEventListener("click", () => {
resetJourney();
setPlaying(true);
});
document.getElementById("toggle-labels").addEventListener("click", (event) => {
labelsVisible = !labelsVisible;
event.currentTarget.setAttribute("aria-pressed", String(labelsVisible));
event.currentTarget.textContent = labelsVisible
? "Show labels"
: "Hide labels";
});
function setCameraView(view) {
if (view === "top") {
cameraState.target.set(-0.35, 0, -0.35);
cameraState.yaw = 0;
cameraState.pitch = 1.48;
cameraState.radius = 16.8;
} else {
cameraState.target.set(-0.65, 0.25, -0.65);
cameraState.yaw = 0.62;
cameraState.pitch = 0.69;
cameraState.radius = 17.8;
}
updateCamera();
}
document.getElementById("iso-view").addEventListener("click", () => {
setCameraView("iso");
});
document.getElementById("top-view").addEventListener("click", () => {
setCameraView("top");
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.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.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.28,
1.49
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
27
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => setCameraView("iso"));
window.addEventListener("keydown", (event) => {
const tag = event.target?.tagName;
if (tag === "INPUT" || tag === "TEXTAREA") return;
switch (event.code) {
case "ArrowLeft":
cameraState.yaw += 0.09;
updateCamera();
break;
case "ArrowRight":
cameraState.yaw -= 0.09;
updateCamera();
break;
case "ArrowUp":
cameraState.pitch = Math.min(1.49, cameraState.pitch + 0.06);
updateCamera();
break;
case "ArrowDown":
cameraState.pitch = Math.max(0.28, cameraState.pitch - 0.06);
updateCamera();
break;
case "Equal":
case "NumpadAdd":
cameraState.radius = Math.max(10, cameraState.radius - 1);
updateCamera();
break;
case "Minus":
case "NumpadSubtract":
cameraState.radius = Math.min(27, cameraState.radius + 1);
updateCamera();
break;
case "Space":
event.preventDefault();
setPlaying(!playing);
break;
case "KeyR":
resetJourney();
setPlaying(true);
break;
case "KeyT":
setCameraView("top");
break;
case "Digit1":
document.querySelector('[data-profile="wheelchair"]').click();
break;
case "Digit2":
document.querySelector('[data-profile="walker"]').click();
break;
case "Digit3":
document.querySelector('[data-profile="cane"]').click();
break;
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const progressFill = document.getElementById("progress");
const targetPosition = new THREE.Vector3();
function angleDifference(a, b) {
return Math.atan2(Math.sin(b - a), Math.cos(b - a));
}
function animateAgent(dt) {
if (!agent || route.length < 2 || !playing) return;
if (journeyPhase === "pauseEnd" || journeyPhase === "pauseStart") {
phaseTimer -= dt;
if (phaseTimer <= 0) {
if (journeyPhase === "pauseEnd") {
journeyPhase = "back";
updateStatus("Returning along the same furniture-free route.");
} else {
journeyPhase = "out";
currentIndex = 0;
updateStatus("Following the clear route to the low counter.");
}
}
return;
}
const forward = journeyPhase === "out";
const targetIndex = forward
? currentIndex + 1
: currentIndex - 1;
if (
targetIndex < 0 ||
targetIndex >= route.length ||
(forward && currentIndex === route.length - 1)
) {
if (forward) {
journeyPhase = "pauseEnd";
phaseTimer = 1.5;
updateStatus("At the accessible service point.");
} else {
journeyPhase = "pauseStart";
phaseTimer = 1.1;
updateStatus("Returning to the waiting area.");
}
return;
}
const current = route[currentIndex];
const target = route[targetIndex];
targetPosition.set(target.x, 0, target.y);
const dx = target.x - agent.position.x;
const dz = target.y - agent.position.z;
const distance = Math.hypot(dx, dz);
const movement = activeProfile.speed * dt;
const desiredYaw = Math.atan2(dx, dz);
agent.rotation.y += angleDifference(
agent.rotation.y,
desiredYaw
) * Math.min(1, dt * 9);
if (distance <= movement || distance < 0.0001) {
agent.position.x = target.x;
agent.position.z = target.y;
currentIndex = targetIndex;
const traveled = movement / Math.max(distance, 0.0001);
if (agent.userData.wheels) {
agent.userData.wheels.forEach((wheel, index) => {
wheel.rotation.x -=
(movement / (index < 2 ? 0.28 : 0.082)) *
(distance < 0.0001 ? traveled : 1);
});
}
} else {
agent.position.x += (dx / distance) * movement;
agent.position.z += (dz / distance) * movement;
if (agent.userData.wheels) {
agent.userData.wheels.forEach((wheel, index) => {
wheel.rotation.x -=
(movement / (index < 2 ? 0.28 : 0.082));
});
}
}
const progress =
forward
? currentIndex / (route.length - 1)
: 1 - currentIndex / (route.length - 1);
progressFill.style.width = `${Math.max(0, progress) * 100}%`;
}
rebuildJourney("wheelchair");
setPlaying(playing);
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.04);
animateAgent(dt);
renderer.render(scene, camera);
updateLabels();
});
document.getElementById("loading")?.remove();
</script>
</body>
</html>
```