Prompt specification
Build or customize the Three.js 3D scene "Seated figure reach-envelope model" 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: Seated figure reach-envelope model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/seated-figure-reach-envelope-model-x1037
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a seated figure's reach envelope. Build a simplified seated figure with adjustable arm lengths and a transparent reachable region above a desk; label the envelope geometric rather than a clinical ergonomic standard. A 3D cutaway view.
Working Three.js Starter (seated-figure-reach-envelope-model-x1037):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Seated Reach Envelope — Geometric Cutaway</title>
<style>
:root {
--ink: #17313d;
--muted: #60747d;
--accent: #0c9eb4;
--accent-bright: #35d4e9;
--panel: rgba(250, 252, 252, 0.9);
--border: rgba(23, 49, 61, 0.13);
--warning: #b6553e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #dfe7ea;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.masthead {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
max-width: 480px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 3.4vw, 48px);
font-weight: 680;
letter-spacing: -0.045em;
line-height: 0.98;
}
.intro {
max-width: 430px;
margin: 13px 0 0;
color: #526872;
font-size: 14px;
line-height: 1.55;
}
.model-badge {
position: fixed;
z-index: 5;
top: 24px;
right: 25px;
display: flex;
align-items: center;
gap: 9px;
max-width: 340px;
padding: 10px 13px;
border: 1px solid rgba(182, 85, 62, 0.2);
border-radius: 999px;
color: #774333;
background: rgba(255, 248, 243, 0.82);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
line-height: 1.35;
text-transform: uppercase;
pointer-events: none;
}
.model-badge::before {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--warning);
content: "";
}
.controls {
position: fixed;
z-index: 6;
bottom: 22px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(26, 49, 58, 0.14),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(18px) saturate(120%);
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 17px;
}
.control-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.total-readout {
color: var(--accent);
font-size: 12px;
font-weight: 800;
white-space: nowrap;
}
.control-row + .control-row {
margin-top: 15px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 16px;
margin-bottom: 8px;
font-size: 13px;
font-weight: 650;
}
output {
color: var(--muted);
font-variant-numeric: tabular-nums;
font-weight: 700;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--accent) 0,
var(--accent) var(--fill),
rgba(23, 49, 61, 0.13) var(--fill),
rgba(23, 49, 61, 0.13) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid #f9fcfc;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 7px rgba(12, 158, 180, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #f9fcfc;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 7px rgba(12, 158, 180, 0.35);
}
.control-footer {
display: flex;
align-items: center;
gap: 8px;
margin-top: 17px;
padding-top: 14px;
border-top: 1px solid var(--border);
}
.control-footer button {
min-height: 34px;
padding: 0 12px;
border: 1px solid var(--border);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 255, 255, 0.65);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.control-footer button:hover {
border-color: rgba(12, 158, 180, 0.4);
background: white;
transform: translateY(-1px);
}
.control-footer button[aria-pressed="true"] {
border-color: rgba(12, 158, 180, 0.35);
color: #08798b;
background: rgba(53, 212, 233, 0.1);
}
.legend {
display: flex;
align-items: center;
gap: 8px;
margin-left: auto;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.legend-swatch {
width: 11px;
height: 11px;
border: 1px solid rgba(12, 158, 180, 0.45);
border-radius: 3px;
background: rgba(53, 212, 233, 0.2);
}
.disclaimer {
margin: 13px 2px 0;
color: #6f625d;
font-size: 10px;
line-height: 1.45;
}
.camera-hint {
position: fixed;
z-index: 5;
right: 25px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(23, 49, 61, 0.62);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.camera-hint svg {
width: 17px;
height: 17px;
stroke: currentColor;
}
.scene-label {
position: fixed;
z-index: 3;
padding: 8px 10px;
border: 1px solid rgba(12, 158, 180, 0.25);
border-radius: 8px;
color: #164c58;
background: rgba(246, 253, 254, 0.82);
box-shadow: 0 6px 22px rgba(21, 60, 72, 0.1);
backdrop-filter: blur(8px);
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
pointer-events: none;
white-space: nowrap;
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 16px;
background: rgba(12, 158, 180, 0.55);
content: "";
}
.scene-label b {
display: block;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.scene-label small {
display: block;
margin-top: 3px;
color: #64818a;
font-size: 9px;
}
.scene-label.neutral {
border-color: rgba(23, 49, 61, 0.15);
color: #3d5964;
background: rgba(250, 252, 252, 0.78);
}
.scene-label.neutral::after {
background: rgba(23, 49, 61, 0.35);
}
.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) {
.masthead {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
h1 {
font-size: 32px;
}
.intro {
max-width: 330px;
font-size: 12px;
}
.model-badge {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 14px;
}
.control-heading {
margin-bottom: 12px;
}
.control-row + .control-row {
margin-top: 10px;
}
.control-footer {
margin-top: 12px;
padding-top: 11px;
}
.camera-hint {
display: none;
}
.scene-label {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="masthead">
<div class="eyebrow">Workspace geometry / 3D cutaway</div>
<h1>Seated Reach<br />Envelope</h1>
<p class="intro">
Adjust the illustrated arm segments to examine a simplified,
shoulder-centered spherical region above the desk plane.
</p>
</header>
<div class="model-badge">
Geometric illustration · not a clinical ergonomic standard
</div>
<section class="controls" aria-label="Reach model controls">
<div class="control-heading">
<h2>Arm segment lengths</h2>
<div class="total-readout" id="totalReadout" aria-live="polite">
Total reach 72 cm
</div>
</div>
<div class="control-row">
<label class="control-label" for="upperArm">
<span>Upper arm</span>
<output id="upperOutput" for="upperArm">36 cm</output>
</label>
<input
id="upperArm"
type="range"
min="28"
max="48"
step="1"
value="36"
/>
</div>
<div class="control-row">
<label class="control-label" for="forearm">
<span>Forearm</span>
<output id="forearmOutput" for="forearm">36 cm</output>
</label>
<input
id="forearm"
type="range"
min="28"
max="52"
step="1"
value="36"
/>
</div>
<div class="control-footer">
<button id="resetView" type="button">Reset view</button>
<button id="toggleEnvelope" type="button" aria-pressed="true">
Hide envelope
</button>
<div class="legend">
<span class="legend-swatch"></span>
Reach region
</div>
</div>
<p class="disclaimer">
Geometric visualization only. This is not a clinical ergonomic
standard, exposure limit, or assessment of an individual.
</p>
</section>
<div class="camera-hint" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke-width="1.7">
<path d="M8 10V7a2 2 0 0 1 4 0v3" />
<path d="M12 10V5a2 2 0 0 1 4 0v7" />
<path d="M16 11V8a2 2 0 0 1 4 0v6c0 4-3 7-7 7h-1c-3 0-5-2-6-4l-2-4a2 2 0 0 1 3-2l3 3" />
</svg>
Drag to orbit · Scroll to zoom
</div>
<div class="scene-label" id="envelopeLabel" aria-hidden="true">
<b>Geometric reach envelope</b>
<small>spherical cap · above desk plane</small>
</div>
<div class="scene-label neutral" id="shoulderLabel" aria-hidden="true">
<b>Shoulder datum</b>
<small>sphere center</small>
</div>
<div class="scene-label neutral" id="deskLabel" aria-hidden="true">
<b>Desk clipping plane</b>
<small>lower envelope boundary</small>
</div>
<div id="status" class="sr-only" aria-live="polite"></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 viewport = document.getElementById("scene");
const status = document.getElementById("status");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
status.textContent = "This scene requires a browser with WebGL enabled.";
viewport.innerHTML =
'<div style="padding:2rem;font:16px system-ui">' +
"This scene requires a browser with WebGL enabled." +
"</div>";
throw error;
}
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.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional seated reach-envelope model"
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe7ea);
scene.fog = new THREE.Fog(0xdfe7ea, 6.5, 12);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.05,
30
);
const cameraTarget = new THREE.Vector3(0, 0.98, 0.24);
const cameraState = {
theta: 0.62,
phi: 1.12,
radius: 4.35,
targetTheta: 0.62,
targetPhi: 1.12,
targetRadius: 4.35
};
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xeaf8ff,
0x857765,
1.7
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff5e7, 3.1);
keyLight.position.set(3.4, 6.2, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -3.2;
keyLight.shadow.camera.right = 3.2;
keyLight.shadow.camera.top = 3.2;
keyLight.shadow.camera.bottom = -3.2;
keyLight.shadow.camera.near = 0.1;
keyLight.shadow.camera.far = 12;
keyLight.shadow.bias = -0.0003;
keyLight.target.position.set(0, 0.8, 0.2);
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0xc8edff, 1.25);
fillLight.position.set(-3, 3.2, 2.5);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
wall: new THREE.MeshStandardMaterial({
color: 0xf1f0eb,
roughness: 0.95
}),
floor: new THREE.MeshStandardMaterial({
color: 0xcbd5d9,
roughness: 0.88
}),
wallCut: new THREE.MeshStandardMaterial({
color: 0xd9785d,
roughness: 0.75
}),
wood: new THREE.MeshStandardMaterial({
color: 0xc89c6d,
roughness: 0.66
}),
woodEdge: new THREE.MeshStandardMaterial({
color: 0x9e714c,
roughness: 0.75
}),
metal: new THREE.MeshStandardMaterial({
color: 0x52646b,
metalness: 0.55,
roughness: 0.38
}),
dark: new THREE.MeshStandardMaterial({
color: 0x263a45,
roughness: 0.7
}),
shirt: new THREE.MeshStandardMaterial({
color: 0x3e7180,
roughness: 0.78
}),
pants: new THREE.MeshStandardMaterial({
color: 0x344a59,
roughness: 0.85
}),
skin: new THREE.MeshStandardMaterial({
color: 0xd39a78,
roughness: 0.8
}),
hair: new THREE.MeshStandardMaterial({
color: 0x263238,
roughness: 0.9
}),
chair: new THREE.MeshStandardMaterial({
color: 0x3f515c,
roughness: 0.72
}),
paper: new THREE.MeshStandardMaterial({
color: 0xf7f3e8,
roughness: 0.95
}),
accent: new THREE.MeshStandardMaterial({
color: 0x1eafc4,
roughness: 0.4
})
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addBox(size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...size),
material
);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addSphere(scale, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(1, 32, 24),
material
);
mesh.scale.set(...scale);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addBone(a, b, radius, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 20),
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;
scene.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x60747d, opacity = 0.35) {
const edgeMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
edges.position.copy(mesh.position);
edges.quaternion.copy(mesh.quaternion);
edges.scale.copy(mesh.scale);
scene.add(edges);
return edges;
}
// -------------------------------------------------------------------------
// Open-front room shell: the cutaway is formed by two retained walls
// -------------------------------------------------------------------------
addBox([3.5, 0.12, 2.9], [0, -0.07, 0.05], materials.floor, false);
const grid = new THREE.GridHelper(3.5, 18, 0x6d858d, 0x8ba0a7);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
addBox([3.5, 2.7, 0.09], [0, 1.3, -1.38], materials.wall, false);
addBox([0.09, 2.7, 2.9], [-1.7, 1.3, 0.05], materials.wall, false);
// Colored cut faces make the architectural section explicit.
addBox([3.5, 0.026, 0.1], [0, 2.655, -1.38], materials.wallCut, false);
addBox([0.1, 0.026, 2.9], [-1.7, 2.655, 0.05], materials.wallCut, false);
addBox([0.1, 2.7, 0.026], [-1.7, 1.3, 1.5], materials.wallCut, false);
addBox([3.5, 0.07, 0.035], [0, 0.05, -1.325], materials.woodEdge, false);
addBox([0.035, 0.07, 2.9], [-1.645, 0.05, 0.05], materials.woodEdge, false);
// -------------------------------------------------------------------------
// Chair
// -------------------------------------------------------------------------
const seat = addBox(
[0.64, 0.08, 0.56],
[0, 0.43, -0.08],
materials.chair
);
addEdges(seat, 0x1e3039, 0.25);
const chairBack = addBox(
[0.64, 0.62, 0.08],
[0, 0.78, -0.31],
materials.chair
);
chairBack.rotation.x = -0.06;
addEdges(chairBack, 0x1e3039, 0.25);
addBone([0, 0.4, -0.08], [0, 0.04, -0.08], 0.045, materials.metal);
addBox([0.62, 0.035, 0.055], [0, 0.035, -0.08], materials.metal);
// -------------------------------------------------------------------------
// Desk
// -------------------------------------------------------------------------
const DESK_Y = 0.84;
const desktop = addBox(
[1.85, 0.09, 0.66],
[0, 0.795, 0.53],
materials.wood
);
addEdges(desktop, 0x745438, 0.28);
addBox(
[1.86, 0.025, 0.025],
[0, 0.76, 0.865],
materials.woodEdge,
false
);
for (const x of [-0.77, 0.77]) {
for (const z of [0.27, 0.79]) {
addBox(
[0.055, 0.71, 0.055],
[x, 0.405, z],
materials.metal
);
}
}
addBox(
[1.45, 0.045, 0.045],
[0, 0.14, 0.79],
materials.metal
);
// Desktop objects.
addBox(
[0.59, 0.025, 0.19],
[-0.12, 0.855, 0.48],
materials.dark
);
const mouse = addSphere(
[0.052, 0.028, 0.075],
[0.38, 0.87, 0.51],
materials.dark
);
mouse.rotation.y = -0.15;
addBox(
[0.26, 0.012, 0.32],
[-0.64, 0.847, 0.48],
materials.paper,
false
);
const cup = new THREE.Mesh(
new THREE.CylinderGeometry(0.072, 0.064, 0.16, 24),
materials.accent
);
cup.position.set(0.67, 0.92, 0.58);
cup.castShadow = true;
scene.add(cup);
// -------------------------------------------------------------------------
// Simplified seated figure
// -------------------------------------------------------------------------
addSphere(
[0.29, 0.17, 0.21],
[0, 0.56, 0.01],
materials.pants
);
addSphere(
[0.34, 0.39, 0.21],
[0, 0.99, 0.02],
materials.shirt
);
addBone([0, 1.3, 0.02], [0, 1.48, 0.025], 0.075, materials.skin);
addSphere(
[0.17, 0.215, 0.165],
[0, 1.62, 0.035],
materials.skin
);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(
1,
32,
18,
0,
Math.PI * 2,
0,
Math.PI * 0.58
),
materials.hair
);
hair.scale.set(0.176, 0.221, 0.171);
hair.position.set(0, 1.625, 0.027);
hair.castShadow = true;
scene.add(hair);
addSphere([0.028, 0.04, 0.028], [-0.165, 1.62, 0.025], materials.skin);
addSphere([0.028, 0.04, 0.028], [0.165, 1.62, 0.025], materials.skin);
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x1d2a2e,
roughness: 0.5
});
addSphere([0.012, 0.012, 0.009], [-0.055, 1.65, 0.197], eyeMaterial, false);
addSphere([0.012, 0.012, 0.009], [0.055, 1.65, 0.197], eyeMaterial, false);
addSphere([0.018, 0.024, 0.022], [0, 1.615, 0.207], materials.skin, false);
for (const side of [-1, 1]) {
addBone(
[side * 0.15, 0.54, 0.05],
[side * 0.165, 0.49, 0.39],
0.095,
materials.pants
);
addBone(
[side * 0.165, 0.49, 0.39],
[side * 0.17, 0.105, 0.43],
0.072,
materials.pants
);
addBox(
[0.17, 0.105, 0.3],
[side * 0.17, 0.055, 0.51],
materials.dark
);
}
// -------------------------------------------------------------------------
// Dynamic arm geometry
// -------------------------------------------------------------------------
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 20);
const unitSphere = new THREE.SphereGeometry(1, 24, 18);
function createArm() {
const group = new THREE.Group();
const upper = new THREE.Mesh(unitCylinder, materials.shirt);
const fore = new THREE.Mesh(unitCylinder, materials.skin);
const elbow = new THREE.Mesh(unitSphere, materials.skin);
const hand = new THREE.Mesh(unitSphere, materials.skin);
for (const mesh of [upper, fore, elbow, hand]) {
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
hand.scale.set(0.07, 0.055, 0.095);
scene.add(group);
return { group, upper, fore, elbow, hand };
}
const rightArm = createArm();
const leftArm = createArm();
const yAxis = new THREE.Vector3(0, 1, 0);
function setBoneTransform(mesh, start, end, radius) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(radius, length, radius);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
}
function solveElbow(shoulder, target, upperLength, foreLength, bendHint) {
const direction = new THREE.Vector3().subVectors(target, shoulder);
const distance = THREE.MathUtils.clamp(
direction.length(),
Math.abs(upperLength - foreLength) + 0.0001,
upperLength + foreLength - 0.0001
);
direction.normalize();
const along =
(
upperLength * upperLength -
foreLength * foreLength +
distance * distance
) /
(2 * distance);
const height = Math.sqrt(
Math.max(0, upperLength * upperLength - along * along)
);
const bend = bendHint.clone();
bend.addScaledVector(direction, -bend.dot(direction));
if (bend.lengthSq() < 0.0001) {
bend.set(0, 0, 1);
bend.addScaledVector(direction, -bend.dot(direction));
}
bend.normalize();
const elbow = shoulder
.clone()
.addScaledVector(direction, along)
.addScaledVector(bend, height);
return elbow;
}
function updateArm(arm, shoulderArray, directionArray, reachFactor, bendArray) {
const shoulder = new THREE.Vector3(...shoulderArray);
const direction = new THREE.Vector3(...directionArray).normalize();
const upperLength = Number(upperArmInput.value) / 100;
const foreLength = Number(forearmInput.value) / 100;
const total = upperLength + foreLength;
const target = shoulder
.clone()
.addScaledVector(direction, reachFactor * total);
const elbow = solveElbow(
shoulder,
target,
upperLength,
foreLength,
new THREE.Vector3(...bendArray)
);
setBoneTransform(arm.upper, shoulder, elbow, 0.073);
setBoneTransform(arm.fore, elbow, target, 0.058);
arm.elbow.position.copy(elbow);
arm.elbow.scale.setScalar(0.066);
arm.hand.position.copy(target);
}
function updateArms() {
// The right arm reaches over the desktop.
updateArm(
rightArm,
[0.29, 1.29, 0.02],
[0, -0.52, 0.854],
0.79,
[1, -0.1, 0]
);
// The left arm remains lowered beside the seated body.
updateArm(
leftArm,
[-0.29, 1.29, 0.02],
[-0.23, -0.94, 0.25],
0.76,
[-1, 0.15, 0]
);
}
// -------------------------------------------------------------------------
// Reach envelope
//
// The illustrative region is the portion of a sphere with:
// radius = upper arm + forearm
// center = midpoint between shoulder datums
// lower boundary = desk plane
// -------------------------------------------------------------------------
const reachGroup = new THREE.Group();
scene.add(reachGroup);
const capMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
vertexColors: true,
transparent: true,
opacity: 0.145,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
});
const baseMaterial = new THREE.MeshBasicMaterial({
color: 0x3bcae0,
transparent: true,
opacity: 0.055,
side: THREE.DoubleSide,
depthWrite: false,
toneMapped: false
});
const gridMaterial = new THREE.LineBasicMaterial({
color: 0x28bdd4,
transparent: true,
opacity: 0.29,
depthWrite: false,
toneMapped: false
});
const axisMaterial = new THREE.LineDashedMaterial({
color: 0x159aaf,
transparent: true,
opacity: 0.5,
dashSize: 0.045,
gapSize: 0.035,
depthWrite: false,
toneMapped: false
});
const envelopeAnchor = new THREE.Vector3();
const shoulderAnchor = new THREE.Vector3(-0.31, 1.3, 0.02);
const deskAnchor = new THREE.Vector3(0.76, 0.87, 0.82);
function clearReachGroup() {
for (const child of reachGroup.children) {
if (child.geometry) {
child.geometry.dispose();
}
}
reachGroup.clear();
}
function addHorizontalCircle(center, radius, y) {
const points = [];
for (let i = 0; i < 72; i++) {
const angle = (i / 72) * Math.PI * 2;
points.push(
new THREE.Vector3(
center.x + Math.cos(angle) * radius,
y,
center.z + Math.sin(angle) * radius
)
);
}
const line = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
gridMaterial
);
reachGroup.add(line);
}
function rebuildEnvelope() {
clearReachGroup();
const radius =
(Number(upperArmInput.value) + Number(forearmInput.value)) / 100;
const center = new THREE.Vector3(0, 1.29, 0.02);
const planeY = DESK_Y + 0.003;
const ratio = THREE.MathUtils.clamp(
(planeY - center.y) / radius,
-1,
1
);
const maxPolar = Math.acos(ratio);
const segments = 64;
const rings = 24;
const positions = [];
const colors = [];
const uvs = [];
const indices = [];
const topColor = new THREE.Color(0x76edf4);
const bottomColor = new THREE.Color(0x278fea);
const color = new THREE.Color();
for (let ring = 0; ring <= rings; ring++) {
const t = ring / rings;
const theta = maxPolar * t;
const y = center.y + radius * Math.cos(theta);
const radial = radius * Math.sin(theta);
color.lerpColors(topColor, bottomColor, t);
for (let segment = 0; segment <= segments; segment++) {
const u = segment / segments;
const phi = u * Math.PI * 2;
positions.push(
center.x + radial * Math.cos(phi),
y,
center.z + radial * Math.sin(phi)
);
colors.push(color.r, color.g, color.b);
uvs.push(u, t);
}
}
for (let ring = 0; ring < rings; ring++) {
for (let segment = 0; segment < segments; segment++) {
const a = ring * (segments + 1) + segment;
const b = a + segments + 1;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d);
indices.push(b, c, d);
}
}
const capGeometry = new THREE.BufferGeometry();
capGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
capGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
capGeometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
capGeometry.setIndex(indices);
capGeometry.computeVertexNormals();
const cap = new THREE.Mesh(capGeometry, capMaterial);
cap.renderOrder = 3;
reachGroup.add(cap);
// Latitude rings.
for (const fraction of [0.18, 0.36, 0.54, 0.72, 0.9]) {
const theta = maxPolar * fraction;
const y = center.y + radius * Math.cos(theta);
const ringRadius = radius * Math.sin(theta);
addHorizontalCircle(center, ringRadius, y);
}
// Meridians.
for (let meridian = 0; meridian < 8; meridian++) {
const phi = (meridian / 8) * Math.PI * 2;
const points = [];
for (let step = 0; step <= 40; step++) {
const theta = maxPolar * (step / 40);
const radial = radius * Math.sin(theta);
points.push(
new THREE.Vector3(
center.x + radial * Math.cos(phi),
center.y + radius * Math.cos(theta),
center.z + radial * Math.sin(phi)
)
);
}
reachGroup.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
gridMaterial
)
);
}
// The intersection of the sphere and desk plane.
const boundaryRadius = radius * Math.sin(maxPolar);
addHorizontalCircle(center, boundaryRadius, planeY);
const baseDisc = new THREE.Mesh(
new THREE.CircleGeometry(boundaryRadius, 64),
baseMaterial
);
baseDisc.rotation.x = -Math.PI / 2;
baseDisc.position.set(center.x, planeY, center.z);
baseDisc.renderOrder = 2;
reachGroup.add(baseDisc);
// Center axis from the desk plane to the top of the spherical cap.
const axis = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(center.x, planeY, center.z),
new THREE.Vector3(center.x, center.y + radius, center.z)
]),
axisMaterial
);
axis.computeLineDistances();
reachGroup.add(axis);
envelopeAnchor.set(
radius * 0.72,
center.y + radius * 0.35,
center.z + radius * 0.45
);
}
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const upperArmInput = document.getElementById("upperArm");
const forearmInput = document.getElementById("forearm");
const upperOutput = document.getElementById("upperOutput");
const forearmOutput = document.getElementById("forearmOutput");
const totalReadout = document.getElementById("totalReadout");
const toggleEnvelope = document.getElementById("toggleEnvelope");
const resetView = document.getElementById("resetView");
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updateModel() {
upperOutput.textContent = `${upperArmInput.value} cm`;
forearmOutput.textContent = `${forearmInput.value} cm`;
const total =
Number(upperArmInput.value) + Number(forearmInput.value);
totalReadout.textContent = `Total reach ${total} cm`;
status.textContent =
`Upper arm ${upperArmInput.value} centimeters. ` +
`Forearm ${forearmInput.value} centimeters. ` +
`Total geometric reach ${total} centimeters.`;
updateRangeFill(upperArmInput);
updateRangeFill(forearmInput);
updateArms();
rebuildEnvelope();
}
upperArmInput.addEventListener("input", updateModel);
forearmInput.addEventListener("input", updateModel);
toggleEnvelope.addEventListener("click", () => {
reachGroup.visible = !reachGroup.visible;
toggleEnvelope.setAttribute(
"aria-pressed",
String(reachGroup.visible)
);
toggleEnvelope.textContent = reachGroup.visible
? "Hide envelope"
: "Show envelope";
});
resetView.addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, wheel zoom, keyboard, and touch pinch
// -------------------------------------------------------------------------
const activePointers = new Map();
let singlePointer = null;
let pinchDistance = 0;
function pointerDistance() {
const points = [...activePointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.focus({ preventScroll: true });
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
singlePointer = {
x: event.clientX,
y: event.clientY
};
} else if (activePointers.size === 2) {
pinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1 && singlePointer) {
const dx = event.clientX - singlePointer.x;
const dy = event.clientY - singlePointer.y;
cameraState.targetTheta -= dx * 0.006;
cameraState.targetPhi -= dy * 0.005;
singlePointer.x = event.clientX;
singlePointer.y = event.clientY;
} else if (activePointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
cameraState.targetRadius *=
pinchDistance / distance;
}
pinchDistance = distance;
}
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 1) {
const remaining = [...activePointers.values()][0];
singlePointer = { ...remaining };
} else {
singlePointer = null;
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius *= Math.exp(event.deltaY * 0.001);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
cameraState.targetTheta += 0.08;
break;
case "ArrowRight":
cameraState.targetTheta -= 0.08;
break;
case "ArrowUp":
cameraState.targetPhi -= 0.06;
break;
case "ArrowDown":
cameraState.targetPhi += 0.06;
break;
case "+":
case "=":
cameraState.targetRadius *= 0.9;
break;
case "-":
case "_":
cameraState.targetRadius *= 1.1;
break;
case "Home":
resetCamera();
break;
}
});
function resetCamera() {
cameraState.targetTheta = 0.62;
cameraState.targetPhi = 1.12;
cameraState.targetRadius = 4.35;
}
// -------------------------------------------------------------------------
// Projected HTML annotations
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("envelopeLabel"),
anchor: envelopeAnchor,
envelope: true
},
{
element: document.getElementById("shoulderLabel"),
anchor: shoulderAnchor,
envelope: false
},
{
element: document.getElementById("deskLabel"),
anchor: deskAnchor,
envelope: false
}
];
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labels) {
if (label.envelope && !reachGroup.visible) {
label.element.style.opacity = "0";
continue;
}
const projected = label.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
label.element.style.opacity = visible ? "1" : "0";
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateModel();
renderer.setAnimationLoop(() => {
const damping = 0.09;
cameraState.theta +=
(cameraState.targetTheta - cameraState.theta) * damping;
cameraState.phi +=
(cameraState.targetPhi - cameraState.phi) * damping;
cameraState.radius +=
(cameraState.targetRadius - cameraState.radius) * damping;
// Keep the camera in the open-front quadrant so the cutaway stays legible.
cameraState.targetTheta = THREE.MathUtils.clamp(
cameraState.targetTheta,
0.14,
1.25
);
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi,
0.72,
1.36
);
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius,
2.7,
6.4
);
const sinPhiRadius =
Math.sin(cameraState.phi) * cameraState.radius;
camera.position.set(
cameraTarget.x +
sinPhiRadius * Math.sin(cameraState.theta),
cameraTarget.y + Math.cos(cameraState.phi) * cameraState.radius,
cameraTarget.z +
sinPhiRadius * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```