Prompt specification
Build or customize the Three.js 3D scene "Reach across the service surface" 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: Reach across the service surface
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reach-across-the-service-surface-x0418
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing accessible service counters. Animate visitors with different seated heights reaching a shared document tray; reposition the tray until both reach paths remain clear in the simplified model. Low-poly.
Working Three.js Starter (reach-across-the-service-surface-x0418):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Counter — Shared Tray Reach Study</title>
<style>
:root {
color-scheme: light;
--ink: #23322f;
--muted: #64716d;
--panel: rgba(255, 252, 245, 0.94);
--border: rgba(35, 50, 47, 0.14);
--green: #238565;
--green-soft: #e1f2ea;
--red: #c95648;
--red-soft: #fae6e1;
--teal: #315f59;
--accent: #e2a15b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
#scene:focus-visible {
outline: 3px solid var(--accent);
outline-offset: -4px;
}
.title-block {
position: fixed;
top: 24px;
left: 28px;
z-index: 2;
max-width: 420px;
pointer-events: none;
text-shadow: 0 1px 12px rgba(255, 255, 255, 0.55);
}
.eyebrow {
margin: 0 0 6px;
color: var(--teal);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 390px;
font-size: clamp(1.6rem, 3vw, 2.65rem);
line-height: 1.02;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 360px;
margin: 10px 0 0;
color: #4f5f5b;
font-size: 0.92rem;
line-height: 1.45;
}
.panel {
position: fixed;
right: 24px;
top: 24px;
z-index: 3;
width: min(340px, calc(100vw - 48px));
padding: 18px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(47, 57, 51, 0.14),
0 2px 8px rgba(47, 57, 51, 0.08);
backdrop-filter: blur(12px);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.panel h2 {
margin: 0;
font-size: 1rem;
letter-spacing: -0.02em;
}
.model-note {
margin: 4px 0 0;
color: var(--muted);
font-size: 0.75rem;
line-height: 1.4;
}
#overallStatus {
display: inline-flex;
align-items: center;
flex: 0 0 auto;
min-height: 28px;
padding: 5px 9px;
border-radius: 999px;
background: #eee9df;
color: #5c625f;
font-size: 0.7rem;
font-weight: 800;
white-space: nowrap;
}
#overallStatus.good {
background: var(--green-soft);
color: var(--green);
}
#overallStatus.bad {
background: var(--red-soft);
color: var(--red);
}
.visitor-row {
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 10px;
padding: 11px 0;
border-top: 1px solid rgba(35, 50, 47, 0.09);
}
.visitor-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #9a9d99;
}
.visitor-dot.good {
background: var(--green);
}
.visitor-dot.bad {
background: var(--red);
}
.visitor-name {
font-size: 0.84rem;
font-weight: 750;
}
.visitor-reach {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 0.69rem;
}
.visitor-state {
font-size: 0.7rem;
font-weight: 800;
text-align: right;
}
.visitor-state.good {
color: var(--green);
}
.visitor-state.bad {
color: var(--red);
}
.position {
display: flex;
justify-content: space-between;
gap: 12px;
margin: 3px 0 14px;
padding: 10px 12px;
border-radius: 10px;
background: rgba(49, 95, 89, 0.07);
color: var(--teal);
font-size: 0.73rem;
font-weight: 700;
}
button {
width: 100%;
min-height: 42px;
border: 0;
border-radius: 11px;
background: var(--teal);
color: white;
font: inherit;
font-size: 0.82rem;
font-weight: 800;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover:not(:disabled) {
background: #264e49;
transform: translateY(-1px);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: wait;
opacity: 0.72;
}
button:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 3px;
}
.secondary-button {
width: auto;
min-height: 34px;
padding: 7px 11px;
background: transparent;
color: var(--teal);
border: 1px solid rgba(49, 95, 89, 0.2);
font-size: 0.7rem;
}
.secondary-button:hover:not(:disabled) {
background: rgba(49, 95, 89, 0.08);
}
.button-row {
display: flex;
gap: 8px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
margin-top: 13px;
color: var(--muted);
font-size: 0.68rem;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
display: inline-block;
width: 18px;
height: 3px;
border-radius: 3px;
background: var(--green);
}
.legend i.red {
background: var(--red);
}
.controls-hint {
position: fixed;
left: 28px;
bottom: 24px;
z-index: 2;
max-width: 420px;
padding: 10px 13px;
border: 1px solid rgba(35, 50, 47, 0.1);
border-radius: 11px;
background: rgba(255, 252, 245, 0.8);
color: #53605c;
font-size: 0.7rem;
line-height: 1.45;
pointer-events: none;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.title-block {
top: 16px;
left: 18px;
max-width: calc(100vw - 36px);
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 14px;
bottom: 14px;
width: min(340px, calc(100vw - 28px));
padding: 14px;
}
.panel-heading {
margin-bottom: 8px;
}
.visitor-row {
padding: 8px 0;
}
.controls-hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
role="img"
aria-label="Interactive low-poly scene of two visitors with different seated heights reaching toward a shared document tray at an accessible service counter."
aria-describedby="sceneDescription"
></canvas>
<header class="title-block">
<p class="eyebrow">Access study / 01</p>
<h1>Shared tray reach study</h1>
<p class="subtitle">
A simplified clearance model adjusts a common document tray until both
seated visitors have a reachable, unobstructed reach path.
</p>
</header>
<section class="panel" aria-labelledby="panelTitle">
<div class="panel-heading">
<div>
<h2 id="panelTitle">Live clearance check</h2>
<p class="model-note">
Geometric model: arm length, work-surface height, and path crossing.
</p>
</div>
<span id="overallStatus" role="status">Starting</span>
</div>
<div class="visitor-row">
<i id="lowDot" class="visitor-dot" aria-hidden="true"></i>
<div>
<div class="visitor-name">Lower seated visitor</div>
<span class="visitor-reach">Wheelchair position · 1.06 m reach</span>
</div>
<span id="lowStatus" class="visitor-state">Waiting</span>
</div>
<div class="visitor-row">
<i id="highDot" class="visitor-dot" aria-hidden="true"></i>
<div>
<div class="visitor-name">Higher seated visitor</div>
<span class="visitor-reach">Raised chair · 1.30 m reach</span>
</div>
<span id="highStatus" class="visitor-state">Waiting</span>
</div>
<div class="position">
<span>Tray position</span>
<output id="trayReadout">x 0.56 · y 0.88 m</output>
</div>
<div class="button-row">
<button id="runCheck" type="button">Run reach check</button>
<button id="resetView" class="secondary-button" type="button">
Reset view
</button>
</div>
<div class="legend" aria-label="Path color legend">
<span><i aria-hidden="true"></i> Reachable and clear</span>
<span><i class="red" aria-hidden="true"></i> Out of reach / conflict</span>
</div>
<p id="sceneDescription" class="sr-only">
The tray automatically moves along the accessible counter. Green lines
indicate valid reach paths and red lines indicate an unreachable or
conflicting path. This is a simplified geometric demonstration, not a
substitute for an ergonomic or accessibility assessment.
</p>
<div id="liveMessage" class="sr-only" aria-live="polite"></div>
</section>
<aside class="controls-hint">
Drag to orbit · Wheel or pinch to zoom · Arrow keys rotate ·
+ / − zoom · Home resets the camera
</aside>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const runButton = document.querySelector("#runCheck");
const resetViewButton = document.querySelector("#resetView");
const overallStatus = document.querySelector("#overallStatus");
const lowStatus = document.querySelector("#lowStatus");
const highStatus = document.querySelector("#highStatus");
const lowDot = document.querySelector("#lowDot");
const highDot = document.querySelector("#highDot");
const trayReadout = document.querySelector("#trayReadout");
const liveMessage = document.querySelector("#liveMessage");
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e1d4);
scene.fog = new THREE.Fog(0xe8e1d4, 10, 20);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(
42,
1,
0.1,
50
);
const cameraState = {
yaw: 0.42,
pitch: 0.32,
distance: 8.2,
target: new THREE.Vector3(0, 0.92, 0.25)
};
const defaultCamera = {
yaw: 0.42,
pitch: 0.32,
distance: 8.2,
target: new THREE.Vector3(0, 0.92, 0.25)
};
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
const horizontal = Math.cos(pitch) * distance;
camera.position.set(
target.x + Math.sin(yaw) * horizontal,
target.y + Math.sin(pitch) * distance,
target.z + Math.cos(yaw) * horizontal
);
camera.lookAt(target);
}
updateCamera();
const ambient = new THREE.HemisphereLight(0xfff8e8, 0x7e8b7c, 2.1);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff2dc, 3.2);
keyLight.position.set(-4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb7d8d3, 1.2);
fillLight.position.set(5, 3, 1);
scene.add(fillLight);
const yAxis = new THREE.Vector3(0, 1, 0);
const tempDirection = new THREE.Vector3();
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(
parent,
size,
position,
color,
options = {},
castShadow = true
) {
const material =
color instanceof THREE.Material ? color : makeMaterial(color, options);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
color,
radialSegments = 8,
options = {}
) {
const material =
color instanceof THREE.Material ? color : makeMaterial(color, options);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function alignCylinder(mesh, start, end) {
tempDirection.subVectors(end, start);
const length = tempDirection.length();
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(1, Math.max(length, 0.0001), 1);
if (length > 0.00001) {
mesh.quaternion.setFromUnitVectors(
yAxis,
tempDirection.clone().normalize()
);
}
}
function addLimb(parent, start, end, radius, color) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 1, 6),
makeMaterial(color)
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
alignCylinder(mesh, start, end);
return mesh;
}
// Room and low-poly architectural elements.
const room = new THREE.Group();
scene.add(room);
addBox(room, [12, 0.12, 9], [0, -0.06, 0], 0xcfc8b8, {}, false);
addBox(room, [12, 3.7, 0.16], [0, 1.85, -3.45], 0xe4ddcf);
addBox(room, [0.16, 3.7, 7], [-5.95, 1.85, 0], 0xded7c9);
const grid = new THREE.GridHelper(10, 20, 0xa9a496, 0xbeb6a6);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.23;
room.add(grid);
for (const x of [-2.25, 2.25]) {
addBox(
room,
[1.25, 0.8, 0.06],
[x, 2.28, -3.345],
0xc8bfae
);
}
// Counter: raised wings and an open-knee lowered center.
const counter = new THREE.Group();
scene.add(counter);
const counterTopMaterial = makeMaterial(0xe9d8b8);
const counterBodyMaterial = makeMaterial(0x466761);
const counterDarkMaterial = makeMaterial(0x344b47);
addBox(
counter,
[2.9, 0.12, 1.1],
[0, 0.72, -0.05],
counterTopMaterial
);
// Open front knee space; modesty panel is placed behind the visitor.
addBox(
counter,
[2.62, 0.52, 0.08],
[0, 0.34, -0.48],
counterDarkMaterial
);
for (const x of [-1.31, 1.31]) {
addBox(
counter,
[0.12, 0.66, 0.94],
[x, 0.33, -0.08],
counterBodyMaterial
);
}
for (const x of [-2.31, 2.31]) {
addBox(
counter,
[1.72, 0.14, 1.24],
[x, 0.9, -0.12],
counterTopMaterial
);
addBox(
counter,
[1.62, 0.78, 0.92],
[x, 0.45, -0.16],
counterBodyMaterial
);
addBox(
counter,
[1.42, 0.08, 0.03],
[x, 0.74, 0.315],
counterDarkMaterial
);
}
// Tray rail and a small desk fixture.
addBox(
counter,
[2.25, 0.035, 0.12],
[0, 0.798, -0.04],
makeMaterial(0x87918b, { metalness: 0.35, roughness: 0.5 })
);
addBox(
counter,
[0.28, 0.035, 0.22],
[1.76, 0.985, -0.24],
makeMaterial(0xd8d2c4)
);
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#315f59";
signContext.fillRect(0, 0, 1024, 256);
signContext.strokeStyle = "#e7ba7d";
signContext.lineWidth = 13;
signContext.beginPath();
signContext.arc(112, 128, 62, 0, Math.PI * 2);
signContext.stroke();
signContext.fillStyle = "#f8f1e4";
signContext.font = "700 57px sans-serif";
signContext.textAlign = "center";
signContext.textBaseline = "middle";
signContext.fillText("ACCESSIBLE SERVICE", 573, 119);
signContext.font = "500 27px sans-serif";
signContext.fillStyle = "#cfe0d8";
signContext.fillText("LOWERED COUNTER • SHARED DOCUMENT TRAY", 573, 185);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(3.4, 0.85),
new THREE.MeshBasicMaterial({ map: signTexture })
);
sign.position.set(0, 2.35, -3.35);
room.add(sign);
// Low-poly plant in the back corner.
addCylinder(room, 0.25, 0.18, 0.42, [4.1, 0.21, -2.65], 0xb9764f, 8);
addCylinder(room, 0.035, 0.05, 1.25, [4.1, 0.95, -2.65], 0x536e45, 6);
const leafMaterial = makeMaterial(0x668657);
for (let i = 0; i < 7; i++) {
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.25, 0.75, 5),
leafMaterial
);
const angle = (i / 7) * Math.PI * 2;
leaf.position.set(
4.1 + Math.cos(angle) * 0.18,
1.12 + (i % 3) * 0.13,
-2.65 + Math.sin(angle) * 0.18
);
leaf.rotation.z = Math.cos(angle) * 0.5;
leaf.rotation.x = Math.sin(angle) * 0.5;
leaf.castShadow = true;
room.add(leaf);
}
// Shared adjustable tray.
const tray = new THREE.Group();
scene.add(tray);
const trayMaterial = makeMaterial(0xd7834d, {
roughness: 0.65,
metalness: 0.08
});
const paperMaterial = makeMaterial(0xfffaf0);
addBox(tray, [0.68, 0.05, 0.42], [0, 0, 0], trayMaterial);
addBox(tray, [0.68, 0.055, 0.035], [0, 0.025, -0.19], trayMaterial);
addBox(tray, [0.68, 0.055, 0.035], [0, 0.025, 0.19], trayMaterial);
addBox(tray, [0.035, 0.055, 0.42], [-0.32, 0.025, 0], trayMaterial);
addBox(tray, [0.035, 0.055, 0.42], [0.32, 0.025, 0], trayMaterial);
const paperA = addBox(
tray,
[0.26, 0.012, 0.3],
[-0.08, 0.034, 0.01],
paperMaterial
);
paperA.rotation.y = -0.08;
const paperB = addBox(
tray,
[0.23, 0.014, 0.27],
[0.12, 0.04, -0.015],
0xf2eee2
);
paperB.rotation.y = 0.11;
// Low-poly visitor and wheelchair.
const lowerVisitor = new THREE.Group();
scene.add(lowerVisitor);
const lowerBody = makeMaterial(0xd87858);
const lowerSkin = makeMaterial(0x9e644c);
const lowerPants = makeMaterial(0x3f515a);
const lowHip = new THREE.Vector3(-0.78, 0.52, 1.4);
const lowShoulderCenter = new THREE.Vector3(-0.78, 1.0, 1.09);
const lowHead = new THREE.Vector3(-0.78, 1.27, 1.06);
const lowTorso = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.27, 1, 6),
lowerBody
);
lowTorso.castShadow = true;
lowerVisitor.add(lowTorso);
alignCylinder(lowTorso, lowHip, lowShoulderCenter);
addLimb(
lowerVisitor,
new THREE.Vector3(-0.78, 1.02, 1.09),
lowHead,
0.075,
lowerSkin
);
const lowHeadMesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 0),
lowerSkin
);
lowHeadMesh.position.copy(lowHead);
lowHeadMesh.castShadow = true;
lowerVisitor.add(lowHeadMesh);
addBox(
lowerVisitor,
[0.075, 0.065, 0.07],
[-0.78, 1.265, 0.895],
lowerSkin
);
for (const x of [-0.83, -0.73]) {
addBox(
lowerVisitor,
[0.028, 0.025, 0.02],
[x, 1.295, 0.896],
0x2b2927
);
}
addLimb(
lowerVisitor,
new THREE.Vector3(-0.78, 0.52, 1.4),
new THREE.Vector3(-0.76, 0.5, 0.95),
0.095,
lowerPants
);
addLimb(
lowerVisitor,
new THREE.Vector3(-0.76, 0.5, 0.95),
new THREE.Vector3(-0.76, 0.2, 0.89),
0.08,
lowerPants
);
addBox(
lowerVisitor,
[0.16, 0.1, 0.25],
[-0.76, 0.13, 0.83],
0x353a38
);
// Wheelchair frame and wheels.
addBox(
lowerVisitor,
[0.54, 0.07, 0.52],
[-0.78, 0.47, 1.38],
makeMaterial(0x2f4140)
);
addBox(
lowerVisitor,
[0.54, 0.54, 0.07],
[-0.78, 0.75, 1.64],
makeMaterial(0x2f4140)
);
for (const x of [-1.12, -0.44]) {
const wheel = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.045, 6, 12),
makeMaterial(0x343b39)
);
wheel.position.set(x, 0.35, 1.43);
wheel.rotation.y = Math.PI / 2;
wheel.castShadow = true;
lowerVisitor.add(wheel);
addCylinder(
lowerVisitor,
0.055,
0.055,
0.1,
[x, 0.35, 1.43],
0x9ca29e,
8
);
}
for (const x of [-1.03, -0.53]) {
addCylinder(
lowerVisitor,
0.075,
0.075,
0.1,
[x, 0.1, 1.01],
0x303634,
8
);
}
// Higher seated visitor and chair.
const higherVisitor = new THREE.Group();
scene.add(higherVisitor);
const highBody = makeMaterial(0x477d91);
const highSkin = makeMaterial(0xd4a07b);
const highPants = makeMaterial(0x555c68);
const highHip = new THREE.Vector3(0.78, 0.71, 1.4);
const highShoulderCenter = new THREE.Vector3(0.78, 1.24, 1.0);
const highHead = new THREE.Vector3(0.78, 1.51, 0.97);
const highTorso = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.27, 1, 6),
highBody
);
highTorso.castShadow = true;
higherVisitor.add(highTorso);
alignCylinder(highTorso, highHip, highShoulderCenter);
addLimb(
higherVisitor,
new THREE.Vector3(0.78, 1.26, 1.0),
highHead,
0.075,
highSkin
);
const highHeadMesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 0),
highSkin
);
highHeadMesh.position.copy(highHead);
highHeadMesh.castShadow = true;
higherVisitor.add(highHeadMesh);
addBox(
higherVisitor,
[0.075, 0.065, 0.07],
[0.78, 1.505, 0.805],
highSkin
);
for (const x of [0.73, 0.83]) {
addBox(
higherVisitor,
[0.028, 0.025, 0.02],
[x, 1.535, 0.806],
0x2b2927
);
}
addLimb(
higherVisitor,
new THREE.Vector3(0.78, 0.71, 1.4),
new THREE.Vector3(0.76, 0.66, 0.94),
0.095,
highPants
);
addLimb(
higherVisitor,
new THREE.Vector3(0.76, 0.66, 0.94),
new THREE.Vector3(0.76, 0.18, 0.87),
0.08,
highPants
);
addBox(
higherVisitor,
[0.16, 0.1, 0.25],
[0.76, 0.11, 0.81],
0x353a38
);
// Raised chair.
addBox(
higherVisitor,
[0.57, 0.08, 0.54],
[0.78, 0.67, 1.38],
makeMaterial(0x8b6b4d)
);
addBox(
higherVisitor,
[0.57, 0.66, 0.08],
[0.78, 1.0, 1.64],
makeMaterial(0x8b6b4d)
);
for (const x of [0.55, 1.01]) {
for (const z of [1.18, 1.57]) {
addBox(
higherVisitor,
[0.055, 0.62, 0.055],
[x, 0.31, z],
makeMaterial(0x5c5147)
);
}
}
// Reach definitions.
const lowerReach = {
shoulder: new THREE.Vector3(-0.57, 1.0, 1.05),
restHand: new THREE.Vector3(-0.46, 0.72, 1.25),
restElbow: new THREE.Vector3(-0.53, 0.84, 1.12),
maximum: 1.06,
color: lowerSkin
};
const higherReach = {
shoulder: new THREE.Vector3(0.58, 1.24, 0.94),
restHand: new THREE.Vector3(0.45, 0.96, 1.18),
restElbow: new THREE.Vector3(0.53, 1.08, 1.04),
maximum: 1.30,
color: highSkin
};
function createReachingArm(definition) {
const upper = addLimb(
scene,
definition.shoulder,
definition.restElbow,
0.068,
definition.color
);
const lower = addLimb(
scene,
definition.restElbow,
definition.restHand,
0.058,
definition.color
);
const hand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.085, 0),
makeMaterial(definition.color)
);
hand.castShadow = true;
scene.add(hand);
return { upper, lower, hand };
}
const lowerArm = createReachingArm(lowerReach);
const higherArm = createReachingArm(higherReach);
// The non-reaching arms rest naturally on each visitor's lap.
addLimb(
lowerVisitor,
new THREE.Vector3(-0.98, 1.0, 1.09),
new THREE.Vector3(-0.94, 0.78, 1.12),
0.065,
lowerSkin
);
addLimb(
lowerVisitor,
new THREE.Vector3(-0.94, 0.78, 1.12),
new THREE.Vector3(-0.86, 0.62, 1.28),
0.055,
lowerSkin
);
addLimb(
higherVisitor,
new THREE.Vector3(1.0, 1.23, 1.02),
new THREE.Vector3(0.98, 1.0, 1.08),
0.065,
highSkin
);
addLimb(
higherVisitor,
new THREE.Vector3(0.98, 1.0, 1.08),
new THREE.Vector3(0.91, 0.8, 1.27),
0.055,
highSkin
);
function createPathVisual(color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.86,
depthWrite: false
});
const line = new THREE.Mesh(
new THREE.CylinderGeometry(0.014, 0.014, 1, 6),
material
);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.055, 0),
new THREE.MeshBasicMaterial({ color })
);
scene.add(line, marker);
return { line, marker, material };
}
const lowerPath = createPathVisual(0xc95648);
const higherPath = createPathVisual(0x238565);
const countertopHeight = 0.78;
function targetsFor(position) {
return {
lower: new THREE.Vector3(
position.x - 0.17,
position.y + 0.035,
position.z + 0.16
),
higher: new THREE.Vector3(
position.x + 0.17,
position.y + 0.035,
position.z + 0.16
)
};
}
function orientation(a, b, c) {
return (
(b.x - a.x) * (c.y - a.y) -
(b.y - a.y) * (c.x - a.x)
);
}
function onSegment(a, b, p) {
return (
p.x <= Math.max(a.x, b.x) + 0.00001 &&
p.x >= Math.min(a.x, b.x) - 0.00001 &&
p.y <= Math.max(a.y, b.y) + 0.00001 &&
p.y >= Math.min(a.y, b.y) - 0.00001
);
}
// X/Z projection is sufficient for checking arm-path crossings.
function segmentsCross(a, b, c, d) {
const o1 = orientation(a, b, c);
const o2 = orientation(a, b, d);
const o3 = orientation(c, d, a);
const o4 = orientation(c, d, b);
if (
((o1 > 0 && o2 < 0) || (o1 < 0 && o2 > 0)) &&
((o3 > 0 && o4 < 0) || (o3 < 0 && o4 > 0))
) {
return true;
}
return (
(Math.abs(o1) < 0.00001 && onSegment(a, b, c)) ||
(Math.abs(o2) < 0.00001 && onSegment(a, b, d)) ||
(Math.abs(o3) < 0.00001 && onSegment(c, d, a)) ||
(Math.abs(o4) < 0.00001 && onSegment(c, d, b))
);
}
function pathStaysAboveCounter(start, end) {
for (let i = 0; i <= 20; i++) {
const t = i / 20;
const y = THREE.MathUtils.lerp(start.y, end.y, t);
if (y < countertopHeight - 0.002) {
return false;
}
}
return true;
}
function evaluatePosition(position) {
const targets = targetsFor(position);
const lowerDistance = lowerReach.shoulder.distanceTo(targets.lower);
const higherDistance = higherReach.shoulder.distanceTo(targets.higher);
const lowerReachable = lowerDistance <= lowerReach.maximum;
const higherReachable = higherDistance <= higherReach.maximum;
const surfaceClear =
pathStaysAboveCounter(lowerReach.shoulder, targets.lower) &&
pathStaysAboveCounter(higherReach.shoulder, targets.higher);
const noCrossing = !segmentsCross(
lowerReach.shoulder,
targets.lower,
higherReach.shoulder,
targets.higher
);
const orderedTargets = targets.lower.x < targets.higher.x;
return {
targets,
lowerDistance,
higherDistance,
lowerReachable,
higherReachable,
surfaceClear,
noCrossing,
orderedTargets,
clear:
lowerReachable &&
higherReachable &&
surfaceClear &&
noCrossing &&
orderedTargets
};
}
function pathIsIndividuallyClear(result, visitor) {
const reachable =
visitor === "lower"
? result.lowerReachable
: result.higherReachable;
return (
reachable &&
result.surfaceClear &&
result.noCrossing &&
result.orderedTargets
);
}
function updatePathVisual(visual, start, end, isClear) {
const color = isClear ? 0x238565 : 0xc95648;
visual.material.color.setHex(color);
visual.marker.material.color.setHex(color);
alignCylinder(visual.line, start, end);
visual.marker.position.copy(end);
}
function announce(message) {
liveMessage.textContent = message;
}
function setVisitorStatus(
element,
dot,
state,
goodText,
badText
) {
element.textContent = state;
element.classList.toggle("good", state === goodText);
element.classList.toggle("bad", state === badText);
dot.classList.toggle("good", state === goodText);
dot.classList.toggle("bad", state === badText);
}
function renderEvaluation(result, position) {
trayReadout.textContent =
`x ${position.x.toFixed(2)} · y ${position.y.toFixed(2)} m`;
if (result.clear) {
overallStatus.textContent = "Both clear";
overallStatus.className = "good";
} else {
overallStatus.textContent = "Adjusting";
overallStatus.className = "bad";
}
const lowState = result.lowerReachable
? result.noCrossing && result.surfaceClear
? "Clear"
: "Conflict"
: "Out of reach";
const highState = result.higherReachable
? result.noCrossing && result.surfaceClear
? "Clear"
: "Conflict"
: "Out of reach";
setVisitorStatus(
lowStatus,
lowDot,
lowState,
"Clear",
"Out of reach"
);
setVisitorStatus(
highStatus,
highDot,
highState,
"Clear",
"Out of reach"
);
if (!result.lowerReachable) {
lowStatus.textContent = "Out of reach";
lowStatus.classList.add("bad");
lowDot.classList.add("bad");
}
if (!result.higherReachable) {
highStatus.textContent = "Out of reach";
highStatus.classList.add("bad");
highDot.classList.add("bad");
}
}
// Candidate positions are tested in order. The first position satisfying
// all simplified clearance rules is retained.
const candidates = [
{ x: 0.56, y: 0.88, z: 0.0 },
{ x: 0.40, y: 0.87, z: 0.01 },
{ x: 0.24, y: 0.86, z: 0.02 },
{ x: 0.08, y: 0.81, z: 0.03 },
{ x: -0.08, y: 0.81, z: 0.03 },
{ x: -0.24, y: 0.82, z: 0.02 },
{ x: -0.40, y: 0.83, z: 0.01 }
];
const search = {
running: false,
index: 0,
phase: "idle",
moveStart: 0,
inspectStart: 0,
from: new THREE.Vector3(),
to: new THREE.Vector3(),
moveDuration: reducedMotion ? 120 : 850,
inspectDuration: reducedMotion ? 240 : 760
};
tray.position.set(
candidates[0].x,
candidates[0].y,
candidates[0].z
);
function beginSearch() {
if (search.running) {
return;
}
search.running = true;
search.index = 0;
search.phase = "move";
search.moveStart = performance.now();
search.from.copy(tray.position);
const candidate = candidates[search.index];
search.to.set(candidate.x, candidate.y, candidate.z);
runButton.disabled = true;
runButton.textContent = "Checking positions…";
overallStatus.textContent = "Moving";
overallStatus.className = "";
announce(
`Reach check started. Testing tray position ${search.index + 1} of ${candidates.length}.`
);
}
function moveToNextCandidate() {
search.index += 1;
if (search.index >= candidates.length) {
search.running = false;
search.phase = "failed";
runButton.disabled = false;
runButton.textContent = "Run reach check again";
overallStatus.textContent = "No match";
overallStatus.className = "bad";
announce("No candidate position satisfied the simplified clearance model.");
return;
}
search.phase = "move";
search.moveStart = performance.now();
search.from.copy(tray.position);
const candidate = candidates[search.index];
search.to.set(candidate.x, candidate.y, candidate.z);
announce(
`Testing tray position ${search.index + 1} of ${candidates.length}.`
);
}
function updateSearch(now) {
if (!search.running) {
return;
}
if (search.phase === "move") {
const raw = THREE.MathUtils.clamp(
(now - search.moveStart) / search.moveDuration,
0,
1
);
const eased =
raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
tray.position.lerpVectors(search.from, search.to, eased);
if (!reducedMotion) {
tray.position.y += Math.sin(raw * Math.PI) * 0.025;
}
if (raw >= 1) {
tray.position.copy(search.to);
search.phase = "inspect";
search.inspectStart = now;
const result = evaluatePosition(tray.position);
renderEvaluation(result, tray.position);
if (result.clear) {
announce(
`Both reach paths are clear at horizontal position ${tray.position.x.toFixed(2)} meters and height ${tray.position.y.toFixed(2)} meters.`
);
} else {
const reason = !result.lowerReachable
? "The lower seated visitor cannot reach this position."
: !result.higherReachable
? "The higher seated visitor cannot reach this position."
: "The modeled reach paths conflict.";
announce(reason + " Moving the tray.");
}
}
} else if (
search.phase === "inspect" &&
now - search.inspectStart >= search.inspectDuration
) {
const result = evaluatePosition(tray.position);
if (result.clear) {
search.running = false;
search.phase = "success";
runButton.disabled = false;
runButton.textContent = "Run reach check again";
overallStatus.textContent = "Both clear";
overallStatus.className = "good";
setVisitorStatus(
lowStatus,
lowDot,
"Clear",
"Clear",
"Out of reach"
);
setVisitorStatus(
highStatus,
highDot,
"Clear",
"Clear",
"Out of reach"
);
announce(
"The shared tray is positioned so both reach paths are reachable, above the work surface, and do not cross."
);
} else {
moveToNextCandidate();
}
}
}
function updateReachingArm(
definition,
arm,
target,
pulse,
isClear
) {
const shoulder = definition.shoulder;
const requiredVector = target.clone().sub(shoulder);
const requiredDistance = requiredVector.length();
// If the tray is out of reach, the hand stops at the modeled reach
// limit while the red required-path line continues to the tray.
const actualTarget = target.clone();
if (requiredDistance > definition.maximum) {
actualTarget
.copy(shoulder)
.add(requiredVector.normalize().multiplyScalar(definition.maximum));
}
const hand = definition.restHand.clone().lerp(actualTarget, pulse);
const extendedElbow = shoulder
.clone()
.lerp(hand, 0.52)
.add(new THREE.Vector3(0, -0.16, 0.035));
const elbow = definition.restElbow.clone().lerp(extendedElbow, pulse);
alignCylinder(arm.upper, shoulder, elbow);
alignCylinder(arm.lower, elbow, hand);
arm.hand.position.copy(hand);
updatePathVisual(
isClear ? lowerPath : lowerPath,
shoulder,
target,
isClear
);
}
function updateVisitors(elapsed) {
const result = evaluatePosition(tray.position);
const lowClear = pathIsIndividuallyClear(result, "lower");
const highClear = pathIsIndividuallyClear(result, "higher");
let lowPulse;
let highPulse;
if (reducedMotion) {
lowPulse = 0.78;
highPulse = 0.72;
} else {
const lowPhase = (elapsed * 0.62) % 1;
const highPhase = (elapsed * 0.62 + 0.22) % 1;
lowPulse = 0.5 - 0.5 * Math.cos(lowPhase * Math.PI * 2);
highPulse = 0.5 - 0.5 * Math.cos(highPhase * Math.PI * 2);
}
updateReachingArm(
lowerReach,
lowerArm,
result.targets.lower,
lowPulse,
lowClear
);
updateReachingArm(
higherReach,
higherArm,
result.targets.higher,
highPulse,
highClear
);
// The helper above is intentionally reused for both visitors, so the
// correct visual is selected afterward.
updatePathVisual(
lowerPath,
lowerReach.shoulder,
result.targets.lower,
lowClear
);
updatePathVisual(
higherPath,
higherReach.shoulder,
result.targets.higher,
highClear
);
}
// Camera controls are implemented directly without addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) {
return;
}
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) {
return;
}
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.0045,
0.12,
0.78
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
5.4,
11.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.yaw += 0.08;
break;
case "ArrowRight":
cameraState.yaw -= 0.08;
break;
case "ArrowUp":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + 0.06,
0.12,
0.78
);
break;
case "ArrowDown":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch - 0.06,
0.12,
0.78
);
break;
case "+":
case "=":
cameraState.distance = Math.max(5.4, cameraState.distance - 0.35);
break;
case "-":
case "_":
cameraState.distance = Math.min(11.5, cameraState.distance + 0.35);
break;
case "Home":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function resetCamera() {
cameraState.yaw = defaultCamera.yaw;
cameraState.pitch = defaultCamera.pitch;
cameraState.distance = defaultCamera.distance;
cameraState.target.copy(defaultCamera.target);
updateCamera();
}
runButton.addEventListener("click", beginSearch);
resetViewButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate(now) {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateSearch(now);
updateVisitors(elapsed);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
// Begin the demonstration shortly after the scene has settled.
window.setTimeout(beginSearch, 850);
</script>
</body>
</html>
```