Prompt specification
Build or customize the Three.js 3D scene "Desk and shelf reach scene" 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: Desk and shelf reach scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/desk-and-shelf-reach-scene-x1027
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows spinal posture and loads. Compose a seated figure, desk, nearby shelf, and movable object; compare reaching postures geometrically while avoiding a universal claim about one correct posture. Voxel style.
Working Three.js Starter (desk-and-shelf-reach-scene-x1027):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ece8df">
<title>Spine & Load Lab — Voxel Reach Study</title>
<style>
:root {
--ink: #17252b;
--muted: #617177;
--paper: rgba(249, 247, 241, 0.91);
--paper-solid: #f7f4ed;
--line: rgba(23, 37, 43, 0.13);
--teal: #287b78;
--teal-soft: #d9e9e5;
--amber: #ed9d3f;
--coral: #df6755;
--navy: #25394b;
--shadow: 0 18px 50px rgba(42, 48, 45, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: #ece8df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
position: fixed;
inset: 0;
overflow: hidden;
}
#viewport {
position: absolute;
inset: 0;
overflow: hidden;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
canvas:focus-visible {
outline: 3px solid rgba(40, 123, 120, 0.38);
outline-offset: -3px;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
padding: 6px 9px;
border: 1px solid rgba(23, 37, 43, 0.12);
border-radius: 7px;
background: rgba(249, 247, 241, 0.88);
box-shadow: 0 6px 18px rgba(42, 48, 45, 0.09);
color: #34464d;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
will-change: transform;
transform: translate(-50%, -50%);
}
.scene-label.load {
border-color: rgba(223, 103, 85, 0.3);
color: #a94638;
}
.scene-label.object {
border-color: rgba(237, 157, 63, 0.42);
color: #8d581b;
}
.masthead {
position: absolute;
top: 24px;
left: 26px;
z-index: 5;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
}
.mark {
display: grid;
grid-template-columns: repeat(3, 7px);
grid-template-rows: repeat(3, 7px);
gap: 3px;
padding: 11px;
border-radius: 10px;
background: var(--ink);
box-shadow: var(--shadow);
}
.mark i {
display: block;
background: #f4f0e8;
}
.mark i:nth-child(2),
.mark i:nth-child(4),
.mark i:nth-child(6),
.mark i:nth-child(8) {
background: var(--amber);
}
.eyebrow {
margin: 0 0 3px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(19px, 2.2vw, 28px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.masthead p:last-child {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
}
.live-badge {
position: absolute;
top: 27px;
right: 27px;
z-index: 5;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(249, 247, 241, 0.75);
color: #52646a;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(12px);
}
.live-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(40, 123, 120, 0.12);
}
.panel {
position: absolute;
z-index: 8;
border: 1px solid rgba(23, 37, 43, 0.12);
border-radius: 16px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(1.05);
}
.controls {
top: 112px;
left: 24px;
width: 328px;
max-height: calc(100vh - 174px);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(23, 37, 43, 0.22) transparent;
}
.analysis {
top: 112px;
right: 24px;
width: 346px;
max-height: calc(100vh - 174px);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: rgba(23, 37, 43, 0.22) transparent;
}
.panel-inner {
padding: 18px;
}
.section + .section {
margin-top: 18px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.section-title h2 {
margin: 0;
font-size: 12px;
font-weight: 820;
letter-spacing: 0.02em;
}
.section-title span {
color: var(--muted);
font-size: 10px;
}
.hint {
margin: 8px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.segmented button {
min-height: 38px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.42);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: 150ms ease;
}
.segmented button:hover {
border-color: rgba(40, 123, 120, 0.35);
background: #fff;
}
.segmented button.active {
border-color: var(--teal);
background: var(--teal);
color: white;
box-shadow: 0 5px 14px rgba(40, 123, 120, 0.18);
}
.posture-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.posture-button {
position: relative;
min-height: 66px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.43);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.posture-button:hover {
transform: translateY(-1px);
border-color: rgba(40, 123, 120, 0.35);
background: white;
}
.posture-button.active {
border-color: var(--teal);
background: var(--teal-soft);
box-shadow: inset 0 0 0 1px rgba(40, 123, 120, 0.14);
}
.posture-button .index {
display: block;
margin-bottom: 5px;
color: var(--teal);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
}
.posture-button strong {
display: block;
font-size: 11px;
}
.posture-button small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.mass-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.mass-row label {
font-size: 11px;
font-weight: 700;
}
.mass-value {
color: var(--coral);
font-size: 12px;
font-weight: 850;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0;
border-radius: 99px;
accent-color: var(--coral);
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: #829095;
font-size: 9px;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.metric {
min-height: 65px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.42);
}
.metric .label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 720;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.metric strong {
font-size: 19px;
letter-spacing: -0.04em;
}
.metric em {
margin-left: 3px;
color: var(--muted);
font-size: 10px;
font-style: normal;
}
.comparison-note {
margin: 0 0 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.compare-row {
width: 100%;
margin-bottom: 7px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.42);
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.compare-row:hover {
background: #fff;
border-color: rgba(40, 123, 120, 0.28);
}
.compare-row.active {
border-color: rgba(40, 123, 120, 0.52);
background: var(--teal-soft);
}
.compare-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.compare-head strong {
font-size: 11px;
}
.compare-head span {
color: var(--coral);
font-size: 10px;
font-weight: 800;
}
.compare-data {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.demand-track {
height: 4px;
margin-top: 8px;
overflow: hidden;
border-radius: 99px;
background: rgba(23, 37, 43, 0.09);
}
.demand-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--teal);
transition: width 220ms ease;
}
.legend {
display: grid;
gap: 7px;
margin-top: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 10px;
}
.swatch {
width: 18px;
height: 8px;
border-radius: 2px;
}
.swatch.object {
background: var(--amber);
}
.swatch.load {
background: var(--coral);
}
.swatch.spine {
background: var(--teal);
}
.disclaimer {
margin-top: 15px;
padding: 12px;
border-left: 3px solid var(--teal);
border-radius: 0 8px 8px 0;
background: rgba(40, 123, 120, 0.07);
color: #52646a;
font-size: 10px;
line-height: 1.52;
}
.disclaimer strong {
color: var(--ink);
}
.footer-note {
position: absolute;
left: 50%;
bottom: 18px;
z-index: 6;
padding: 8px 12px;
border: 1px solid rgba(23, 37, 43, 0.1);
border-radius: 999px;
background: rgba(249, 247, 241, 0.72);
color: #66767b;
font-size: 10px;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(10px);
white-space: nowrap;
}
@media (max-width: 1050px) {
.controls {
width: 288px;
}
.analysis {
width: 308px;
}
.panel-inner {
padding: 15px;
}
}
@media (max-width: 760px) {
body {
overflow: auto;
}
#app {
position: relative;
height: auto;
min-height: 100vh;
overflow: visible;
}
#viewport {
position: relative;
height: 56vh;
min-height: 410px;
}
.masthead {
top: 13px;
left: 14px;
}
.masthead p:last-child,
.live-badge {
display: none;
}
.panel {
position: relative;
top: auto;
right: auto;
left: auto;
width: auto;
max-height: none;
margin: 12px;
}
.footer-note {
position: relative;
left: auto;
bottom: auto;
margin: 0 12px 18px;
transform: none;
text-align: center;
white-space: normal;
}
}
@media (max-width: 420px) {
.posture-list {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<main id="app">
<div id="viewport">
<canvas
id="scene"
tabindex="0"
role="img"
aria-label="Interactive voxel scene of a seated person, desk, shelf, and movable load"
></canvas>
<div id="labels" aria-hidden="true">
<div id="label-object" class="scene-label object">Movable load</div>
<div id="label-desk" class="scene-label">Desk</div>
<div id="label-shelf" class="scene-label">Shelf</div>
<div id="label-load" class="scene-label load">Load path</div>
</div>
</div>
<header class="masthead">
<div class="mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<p class="eyebrow">Spine & Load Lab</p>
<h1>Voxel reach study</h1>
<p>Compare posture geometry without prescribing one “correct” posture.</p>
</div>
</header>
<div class="live-badge">Interactive 3D</div>
<aside class="panel controls" aria-label="Model controls">
<div class="panel-inner">
<section class="section">
<div class="section-title">
<h2>Object position</h2>
<span id="location-status">On desk</span>
</div>
<div class="segmented">
<button type="button" data-location="desk" class="active" aria-pressed="true">
On desk
</button>
<button type="button" data-location="shelf" aria-pressed="false">
On shelf
</button>
</div>
<p class="hint">Drag the amber block on either surface to create a custom target.</p>
</section>
<section class="section">
<div class="section-title">
<h2>Posture variant</h2>
<span>One modeled person</span>
</div>
<div id="posture-list" class="posture-list"></div>
</section>
<section class="section">
<div class="section-title">
<h2>Load model</h2>
<span>Simplified</span>
</div>
<div class="mass-row">
<label for="mass">Movable object mass</label>
<output id="mass-value" class="mass-value" for="mass">3.0 kg</output>
</div>
<input id="mass" type="range" min="0.5" max="8" step="0.1" value="3">
<div class="range-ends">
<span>0.5 kg</span>
<span>8.0 kg</span>
</div>
<p class="hint">
The shoulder moment is a simple force × horizontal-distance proxy,
not a biomechanical diagnosis.
</p>
</section>
<section class="section">
<div class="section-title">
<h2>Selected geometry</h2>
<span>Live values</span>
</div>
<div class="metric-grid">
<div class="metric">
<span class="label">Trunk angle</span>
<strong id="metric-lean">18</strong><em>°</em>
</div>
<div class="metric">
<span class="label">Reach demand</span>
<strong id="metric-reach">0</strong><em>%</em>
</div>
<div class="metric">
<span class="label">Elbow bend</span>
<strong id="metric-elbow">0</strong><em>°</em>
</div>
<div class="metric">
<span class="label">Moment proxy</span>
<strong id="metric-moment">0</strong><em>N·m</em>
</div>
</div>
</section>
</div>
</aside>
<aside class="panel analysis" aria-label="Posture comparison">
<div class="panel-inner">
<section class="section">
<div class="section-title">
<h2>Four ways to reach</h2>
<span>Same target</span>
</div>
<p class="comparison-note">
Each row changes the body geometry relative to the same object.
This is a comparison, not a ranking or universal recommendation.
</p>
<div id="comparison-list"></div>
</section>
<section class="section">
<div class="section-title">
<h2>Reading the scene</h2>
<span>Legend</span>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch object"></span>
<span>Movable object and its weight</span>
</div>
<div class="legend-item">
<span class="swatch load"></span>
<span>External load path toward the shoulder</span>
</div>
<div class="legend-item">
<span class="swatch spine"></span>
<span>Direction of the modeled axial load</span>
</div>
</div>
</section>
<section class="section">
<div class="disclaimer">
<strong>Geometry, not a verdict.</strong>
These snapshots describe one modeled body and task. Comfort,
fatigue, anatomy, task duration, assistive equipment, and work
context also matter. A different posture may be preferable for
different reasons, so no posture here is labeled universally best.
</div>
</section>
</div>
</aside>
<div class="footer-note">
Drag empty space to orbit · Scroll to zoom · Drag the amber object to move the target
</div>
<noscript>This visualization requires JavaScript.</noscript>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const canvas = document.querySelector("#scene");
const ui = {
postureList: document.querySelector("#posture-list"),
comparisonList: document.querySelector("#comparison-list"),
mass: document.querySelector("#mass"),
massValue: document.querySelector("#mass-value"),
locationStatus: document.querySelector("#location-status"),
metricLean: document.querySelector("#metric-lean"),
metricReach: document.querySelector("#metric-reach"),
metricElbow: document.querySelector("#metric-elbow"),
metricMoment: document.querySelector("#metric-moment"),
labelObject: document.querySelector("#label-object"),
labelDesk: document.querySelector("#label-desk"),
labelShelf: document.querySelector("#label-shelf"),
labelLoad: document.querySelector("#label-load")
};
const scene = new THREE.Scene();
scene.background = new THREE.Color("#ece8df");
scene.fog = new THREE.Fog("#ece8df", 15, 29);
const camera = new THREE.PerspectiveCamera(
38,
viewport.clientWidth / viewport.clientHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const hemisphere = new THREE.HemisphereLight("#fff8e9", "#74838a", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff2d6", 3.0);
sun.position.set(-5, 9, -6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight("#c6e2e3", 1.2);
fill.position.set(6, 4, 7);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(parent, size, position, color, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function setLimb(mesh, a, b, width, depth) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(width, Math.max(length, 0.001), depth);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
}
function limb(parent, a, b, width, depth, color) {
const mesh = new THREE.Mesh(unitBox, material(color));
setLimb(mesh, a, b, width, depth);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and architectural grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: "#e7e3da",
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(20, 40, "#b8b6ae", "#cfccc3");
grid.position.y = 0.003;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// Desk.
const desk = new THREE.Group();
scene.add(desk);
box(desk, [3.1, 0.16, 1.3], [0.05, 1.35, -1.2], "#a86f42");
box(desk, [0.16, 1.28, 0.16], [-1.32, 0.64, -1.68], "#40525a");
box(desk, [0.16, 1.28, 0.16], [1.42, 0.64, -1.68], "#40525a");
box(desk, [0.16, 1.28, 0.16], [-1.32, 0.64, -0.72], "#40525a");
box(desk, [0.16, 1.28, 0.16], [1.42, 0.64, -0.72], "#40525a");
box(desk, [2.74, 0.42, 0.08], [0.05, 0.95, -1.52], "#875b39");
// Monitor, stand, keyboard and desk blocks.
box(desk, [0.12, 0.18, 0.12], [-0.86, 1.51, -1.4], "#34464d");
box(desk, [0.78, 0.46, 0.08], [-0.86, 1.83, -1.4], "#263943");
box(desk, [0.68, 0.36, 0.025], [-0.86, 1.83, -1.448], "#789ca0", false);
box(desk, [0.91, 0.035, 0.27], [-0.78, 1.455, -1.0], "#d9d6cd");
box(desk, [0.30, 0.035, 0.22], [0.98, 1.455, -1.03], "#e8e1d1");
box(desk, [0.10, 0.18, 0.10], [0.98, 1.52, -1.03], "#365c61");
// Nearby voxel shelf.
const shelf = new THREE.Group();
shelf.position.set(2.03, 0, -1.04);
scene.add(shelf);
box(shelf, [0.13, 3.08, 0.13], [-0.54, 1.54, -0.43], "#53666b");
box(shelf, [0.13, 3.08, 0.13], [0.54, 1.54, -0.43], "#53666b");
box(shelf, [0.13, 3.08, 0.13], [-0.54, 1.54, 0.43], "#53666b");
box(shelf, [0.13, 3.08, 0.13], [0.54, 1.54, 0.43], "#53666b");
[0.48, 1.52, 2.56].forEach((y, index) => {
box(shelf, [1.19, 0.12, 0.96], [0, y, 0], "#78918f");
if (index === 0) {
box(shelf, [0.16, 0.36, 0.28], [-0.32, y + 0.24, -0.14], "#d47e61");
box(shelf, [0.12, 0.29, 0.26], [-0.12, y + 0.205, -0.12], "#e6b75f");
}
if (index === 1) {
box(shelf, [0.13, 0.40, 0.26], [-0.31, y + 0.26, -0.12], "#4b6c89");
box(shelf, [0.12, 0.33, 0.24], [-0.14, y + 0.225, -0.11], "#d5846c");
}
if (index === 2) {
box(shelf, [0.27, 0.25, 0.27], [0.29, y + 0.185, -0.12], "#db9a4a");
box(shelf, [0.25, 0.19, 0.25], [-0.22, y + 0.155, 0.1], "#6f8e78");
}
});
// Chair.
const chair = new THREE.Group();
chair.position.set(-0.55, 0, 0.42);
scene.add(chair);
box(chair, [0.78, 0.14, 0.68], [0, 0.72, 0], "#344c59");
box(chair, [0.76, 0.72, 0.12], [0, 1.12, 0.31], "#344c59");
box(chair, [0.09, 0.67, 0.09], [-0.31, 0.34, 0.21], "#40545d");
box(chair, [0.09, 0.67, 0.09], [0.31, 0.34, 0.21], "#40545d");
box(chair, [0.09, 0.67, 0.09], [-0.31, 0.34, -0.21], "#40545d");
box(chair, [0.09, 0.67, 0.09], [0.31, 0.34, -0.21], "#40545d");
// Seated voxel figure.
const figure = new THREE.Group();
figure.position.set(-0.55, 0, 0.32);
scene.add(figure);
const torsoPivot = new THREE.Group();
torsoPivot.position.set(0, 1.02, 0);
figure.add(torsoPivot);
box(figure, [0.66, 0.31, 0.49], [0, 0.91, 0.02], "#293d50");
box(torsoPivot, [0.56, 0.22, 0.36], [0, 0.08, 0], "#31495a");
box(torsoPivot, [0.68, 0.67, 0.41], [0, 0.47, -0.015], "#2c827d");
box(torsoPivot, [0.12, 0.52, 0.025], [0, 0.46, -0.229], "#65a7a0", false);
// Pixel-like spine load path along the side/back of the torso.
[0.18, 0.32, 0.46, 0.60].forEach((y, index) => {
box(
torsoPivot,
[0.07, 0.08, 0.07],
[0.365, y, 0.08 + index * 0.004],
index === 3 ? "#e2944f" : "#efb45b",
false
);
});
const headPivot = new THREE.Group();
headPivot.position.set(0, 0.87, -0.01);
torsoPivot.add(headPivot);
box(headPivot, [0.17, 0.15, 0.17], [0, 0.03, 0], "#d99570");
box(headPivot, [0.47, 0.44, 0.44], [0, 0.25, 0], "#efb58d");
box(headPivot, [0.49, 0.14, 0.46], [0, 0.47, 0.015], "#3c3834");
box(headPivot, [0.49, 0.23, 0.11], [0, 0.38, 0.18], "#3c3834");
box(headPivot, [0.055, 0.055, 0.028], [-0.105, 0.28, -0.229], "#253039", false);
box(headPivot, [0.055, 0.055, 0.028], [0.105, 0.28, -0.229], "#253039", false);
box(headPivot, [0.055, 0.045, 0.03], [0, 0.21, -0.238], "#d78268", false);
// Legs and shoes.
[-0.22, 0.22].forEach((x) => {
const hip = new THREE.Vector3(x, 0.91, -0.02);
const knee = new THREE.Vector3(x, 0.78, -0.63);
const ankle = new THREE.Vector3(x, 0.18, -0.80);
limb(figure, hip, knee, 0.26, 0.27, "#2a4053");
limb(figure, knee, ankle, 0.22, 0.23, "#30495c");
box(figure, [0.28, 0.15, 0.43], [x, 0.10, -0.91], "#1f2e38");
});
// Reaching arm.
const reachUpper = limb(
figure,
new THREE.Vector3(0.42, 0.73, 0),
new THREE.Vector3(0.55, 0.5, -0.25),
0.22,
0.22,
"#2c827d"
);
const reachFore = limb(
figure,
new THREE.Vector3(0.55, 0.5, -0.25),
new THREE.Vector3(0.36, 0.77, -0.52),
0.18,
0.18,
"#e7aa83"
);
const reachHand = box(
figure,
[0.23, 0.18, 0.23],
[0.36, 0.77, -0.52],
"#efb58d"
);
const reachShoulder = box(
figure,
[0.25, 0.25, 0.25],
[0.42, 0.73, 0],
"#2c827d"
);
// Resting arm.
const restShoulder = new THREE.Vector3(-0.42, 0.73, 0);
const restElbow = new THREE.Vector3(-0.56, 0.43, -0.06);
const restWrist = new THREE.Vector3(-0.27, 0.82, -0.48);
limb(figure, restShoulder, restElbow, 0.21, 0.21, "#2c827d");
limb(figure, restElbow, restWrist, 0.17, 0.17, "#e7aa83");
box(figure, [0.22, 0.17, 0.22], restWrist.toArray(), "#efb58d");
// Movable object.
const objectGroup = new THREE.Group();
objectGroup.position.set(0.62, 1.62, -0.88);
scene.add(objectGroup);
const objectBody = box(
objectGroup,
[0.42, 0.40, 0.40],
[0, 0, 0],
"#ed9d3f"
);
box(objectGroup, [0.25, 0.07, 0.08], [0, 0.23, 0], "#f6bd6c");
box(objectGroup, [0.06, 0.12, 0.07], [-0.095, 0.18, 0], "#d67e2f");
box(objectGroup, [0.06, 0.12, 0.07], [0.095, 0.18, 0], "#d67e2f");
const draggableMeshes = [objectBody];
// Voxel-style arrows.
function createVoxelArrow(color) {
const group = new THREE.Group();
const shaft = new THREE.Mesh(unitBox, material(color));
shaft.castShadow = true;
group.add(shaft);
const tip = new THREE.Mesh(unitBox, material(color));
tip.castShadow = true;
group.add(tip);
group.userData.shaft = shaft;
group.userData.tip = tip;
scene.add(group);
return group;
}
function updateVoxelArrow(group, origin, direction, length) {
const shaft = group.userData.shaft;
const tip = group.userData.tip;
const shaftLength = Math.max(0.06, length - 0.15);
group.position.copy(origin);
group.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
shaft.scale.set(0.075, shaftLength, 0.075);
shaft.position.set(0, shaftLength * 0.5, 0);
tip.scale.set(0.19, 0.19, 0.19);
tip.position.set(0, length - 0.08, 0);
}
const objectArrow = createVoxelArrow("#df6755");
const spineArrow = createVoxelArrow("#e2954f");
// Load path from object to hand to shoulder.
const loadPath = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineDashedMaterial({
color: "#df6755",
dashSize: 0.10,
gapSize: 0.065,
transparent: true,
opacity: 0.9
})
);
figure.add(loadPath);
const targetMarker = box(
scene,
[0.09, 0.09, 0.09],
[0, 2, 0],
"#df6755",
false
);
// Posture definitions. Yaw is calculated relative to the current target.
const postures = [
{
key: "forward",
name: "Forward reach",
short: "Forward",
lean: -18,
turnFactor: 0.18,
side: 0,
detail: "Trunk travels toward the target"
},
{
key: "side",
name: "Side shift",
short: "Side",
lean: -8,
turnFactor: 0.22,
side: 0.22,
detail: "Shoulder shifts laterally"
},
{
key: "turned",
name: "Turned reach",
short: "Turned",
lean: -10,
turnFactor: 0.92,
side: 0,
detail: "Body rotates toward the target"
},
{
key: "low",
name: "Low reach",
short: "Low",
lean: -42,
turnFactor: 0.30,
side: 0,
detail: "Trunk flexes toward the target"
}
];
const rootPosition = new THREE.Vector3(-0.55, 0, 0.32);
const armUpperLength = 0.90;
const armForeLength = 0.86;
const armSpan = armUpperLength + armForeLength;
let selectedPosture = postures[0];
let mass = 3;
let location = "desk";
let support = "desk";
let currentLean = postures[0].lean;
let currentYaw = 0;
let currentSide = postures[0].side;
const targetY = new THREE.Vector3();
const worldShoulder = new THREE.Vector3();
const currentTorsoQuaternion = new THREE.Quaternion();
const xAxis = new THREE.Vector3(1, 0, 0);
const yAxis = new THREE.Vector3(0, 1, 0);
function objectHandleWorld() {
return objectGroup.position.clone().add(new THREE.Vector3(0, 0.22, 0));
}
function baseYawToTarget() {
const target = objectHandleWorld();
const dx = target.x - rootPosition.x;
const dz = target.z - rootPosition.z;
return Math.atan2(-dx, -dz);
}
function postureConfig(posture) {
return {
...posture,
yaw: baseYawToTarget() * posture.turnFactor
};
}
function shoulderLocal(config) {
const q = new THREE.Quaternion().setFromAxisAngle(
xAxis,
config.lean
);
const shoulder = new THREE.Vector3(
config.side,
0.73,
0
).applyQuaternion(q);
shoulder.add(torsoPivot.position);
return shoulder;
}
function shoulderWorld(config) {
const local = shoulderLocal(config);
return local
.applyAxisAngle(yAxis, config.yaw)
.add(rootPosition);
}
function elbowAngleFor(distance) {
const d = THREE.MathUtils.clamp(distance, 0.001, armSpan);
const cosine = THREE.MathUtils.clamp(
(armUpperLength ** 2 + armForeLength ** 2 - d ** 2) /
(2 * armUpperLength * armForeLength),
-1,
1
);
return THREE.MathUtils.radToDeg(Math.acos(cosine));
}
function evaluatePosture(posture) {
const config = postureConfig(posture);
const shoulder = shoulderWorld(config);
const target = objectHandleWorld();
const delta = target.clone().sub(shoulder);
const distance = delta.length();
const horizontalDistance = Math.hypot(delta.x, delta.z);
const reachDemand = distance / armSpan * 100;
const momentProxy = mass * 9.81 * horizontalDistance;
return {
config,
distance,
horizontalDistance,
reachDemand,
momentProxy,
lean: Math.abs(config.lean),
elbow: elbowAngleFor(distance),
gap: Math.max(0, distance - armSpan)
};
}
// Build posture buttons.
const postureButtons = new Map();
postures.forEach((posture, index) => {
const button = document.createElement("button");
button.type = "button";
button.className = "posture-button";
button.setAttribute("aria-pressed", index === 0 ? "true" : "false");
button.innerHTML = `
<span class="index">${String(index + 1).padStart(2, "0")}</span>
<strong>${posture.name}</strong>
<small>${Math.abs(posture.lean)}° trunk</small>
`;
button.addEventListener("click", () => {
selectedPosture = posture;
postureButtons.forEach((entry, key) => {
const active = key === posture.key;
entry.button.classList.toggle("active", active);
entry.button.setAttribute("aria-pressed", String(active));
});
updateUI();
});
ui.postureList.appendChild(button);
postureButtons.set(posture.key, { button });
});
postureButtons.get("forward").button.classList.add("active");
// Build comparison rows.
const comparisonRows = new Map();
postures.forEach((posture) => {
const row = document.createElement("button");
row.type = "button";
row.className = "compare-row";
row.setAttribute("aria-pressed", "false");
row.innerHTML = `
<div class="compare-head">
<strong>${posture.name}</strong>
<span class="row-reach">0% reach</span>
</div>
<div class="compare-data">
<span class="row-lean">0° trunk</span>
<span class="row-moment">0 N·m proxy</span>
</div>
<div class="demand-track">
<div class="demand-fill"></div>
</div>
`;
row.addEventListener("click", () => {
selectedPosture = posture;
postureButtons.forEach((entry, key) => {
const active = key === posture.key;
entry.button.classList.toggle("active", active);
entry.button.setAttribute("aria-pressed", String(active));
});
updateUI();
});
ui.comparisonList.appendChild(row);
comparisonRows.set(posture.key, {
row,
reach: row.querySelector(".row-reach"),
lean: row.querySelector(".row-lean"),
moment: row.querySelector(".row-moment"),
fill: row.querySelector(".demand-fill")
});
});
function updateUI() {
const selected = evaluatePosture(selectedPosture);
ui.massValue.value = `${mass.toFixed(1)} kg`;
ui.metricLean.textContent = selected.lean.toFixed(0);
ui.metricReach.textContent = selected.reachDemand.toFixed(0);
ui.metricElbow.textContent = selected.elbow.toFixed(0);
ui.metricMoment.textContent = selected.momentProxy.toFixed(0);
postures.forEach((posture) => {
const result = evaluatePosture(posture);
const row = comparisonRows.get(posture.key);
const active = posture.key === selectedPosture.key;
row.row.classList.toggle("active", active);
row.row.setAttribute("aria-pressed", String(active));
row.reach.textContent = `${result.reachDemand.toFixed(0)}% reach`;
row.lean.textContent = `${result.lean.toFixed(0)}° trunk`;
row.moment.textContent = `${result.momentProxy.toFixed(0)} N·m proxy`;
row.fill.style.width =
`${Math.min(100, result.reachDemand / 1.6)}%`;
});
ui.labelObject.textContent = `${mass.toFixed(1)} kg · movable load`;
}
// Object placement controls.
const locationButtons = [
...document.querySelectorAll("[data-location]")
];
function setObjectLocation(nextLocation) {
location = nextLocation;
support = nextLocation;
if (nextLocation === "desk") {
objectGroup.position.set(0.62, 1.62, -0.88);
ui.locationStatus.textContent = "On desk";
} else if (nextLocation === "shelf") {
objectGroup.position.set(2.03, 1.80, -1.04);
ui.locationStatus.textContent = "On shelf";
}
locationButtons.forEach((button) => {
const active = button.dataset.location === location;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
updateUI();
}
locationButtons.forEach((button) => {
button.addEventListener("click", () => {
setObjectLocation(button.dataset.location);
});
});
ui.mass.addEventListener("input", () => {
mass = Number(ui.mass.value);
updateUI();
});
// Custom orbit camera, implemented without addons.
const cameraTarget = new THREE.Vector3(0.22, 1.27, -0.28);
let cameraAzimuth = 2.34;
let cameraPolar = 1.01;
let cameraRadius = 9.35;
function updateCamera() {
const sinPolar = Math.sin(cameraPolar);
camera.position.set(
cameraTarget.x + cameraRadius * sinPolar * Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * Math.cos(cameraPolar),
cameraTarget.z + cameraRadius * sinPolar * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Pointer interaction: drag the object, or orbit the camera.
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const dragPoint = new THREE.Vector3();
const dragOffset = new THREE.Vector3();
let draggingObject = false;
let orbiting = false;
let lastPointerX = 0;
let lastPointerY = 0;
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
canvas.focus({ preventScroll: true });
setPointer(event);
const hits = raycaster.intersectObjects(draggableMeshes, false);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (hits.length) {
draggingObject = true;
orbiting = false;
dragPlane.constant = -objectGroup.position.y;
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
dragOffset.copy(objectGroup.position).sub(dragPoint);
} else {
dragOffset.set(0, 0, 0);
}
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
} else {
orbiting = true;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
}
});
canvas.addEventListener("pointermove", (event) => {
setPointer(event);
if (draggingObject) {
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
const desired = dragPoint.clone().add(dragOffset);
if (support === "shelf") {
objectGroup.position.x = THREE.MathUtils.clamp(desired.x, 1.68, 2.38);
objectGroup.position.z = THREE.MathUtils.clamp(desired.z, -1.30, -0.77);
objectGroup.position.y = 1.80;
} else {
objectGroup.position.x = THREE.MathUtils.clamp(desired.x, -1.08, 1.28);
objectGroup.position.z = THREE.MathUtils.clamp(desired.z, -1.65, -0.70);
objectGroup.position.y = 1.62;
}
}
location = "custom";
ui.locationStatus.textContent = "Custom position";
locationButtons.forEach((button) => {
button.classList.remove("active");
button.setAttribute("aria-pressed", "false");
});
updateUI();
return;
}
if (orbiting) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraAzimuth -= dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar + dy * 0.005,
0.48,
1.38
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
} else {
const hits = raycaster.intersectObjects(draggableMeshes, false);
canvas.style.cursor = hits.length ? "grab" : "default";
}
});
function endPointer(event) {
draggingObject = false;
orbiting = false;
canvas.style.cursor = "default";
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
window.addEventListener("blur", () => endPointer());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.007,
5.8,
14.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const handled = [
"ArrowLeft",
"ArrowRight",
"ArrowUp",
"ArrowDown",
"+",
"=",
"-",
"_"
].includes(event.key);
if (!handled) return;
event.preventDefault();
if (event.key === "ArrowLeft") cameraAzimuth -= 0.09;
if (event.key === "ArrowRight") cameraAzimuth += 0.09;
if (event.key === "ArrowUp") cameraPolar -= 0.07;
if (event.key === "ArrowDown") cameraPolar += 0.07;
if (event.key === "+" || event.key === "=") cameraRadius -= 0.4;
if (event.key === "-" || event.key === "_") cameraRadius += 0.4;
cameraPolar = THREE.MathUtils.clamp(cameraPolar, 0.48, 1.38);
cameraRadius = THREE.MathUtils.clamp(cameraRadius, 5.8, 14.5);
updateCamera();
});
// Resize handling.
const resizeObserver = new ResizeObserver(() => {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
});
resizeObserver.observe(viewport);
// Arm IK in the figure's local coordinate system.
function solveElbow(shoulder, target) {
const delta = target.clone().sub(shoulder);
const actualDistance = delta.length();
const distance = Math.min(actualDistance, armSpan - 0.0001);
const direction = delta.normalize();
const along =
(armUpperLength ** 2 - armForeLength ** 2 + distance ** 2) /
(2 * distance);
const height = Math.sqrt(
Math.max(0, armUpperLength ** 2 - along ** 2)
);
const pole = new THREE.Vector3().crossVectors(
new THREE.Vector3(0, -1, 0),
direction
);
if (pole.lengthSq() < 0.001) {
pole.set(1, 0, 0);
} else {
pole.normalize();
}
const elbow = shoulder
.clone()
.addScaledVector(direction, along)
.addScaledVector(pole, height);
const hand = shoulder.clone().addScaledVector(direction, distance);
return { elbow, hand };
}
function lerpAngle(current, target, amount) {
let difference = ((target - current + Math.PI) % (Math.PI * 2)) - Math.PI;
if (difference < -Math.PI) difference += Math.PI * 2;
return current + difference * amount;
}
function updateFigure(delta) {
const selectedConfig = postureConfig(selectedPosture);
const damping = 1 - Math.exp(-7.5 * delta);
currentLean = THREE.MathUtils.lerp(
currentLean,
selectedConfig.lean,
damping
);
currentSide = THREE.MathUtils.lerp(
currentSide,
selectedConfig.side,
damping
);
currentYaw = lerpAngle(
currentYaw,
selectedConfig.yaw,
damping
);
figure.rotation.y = currentYaw;
torsoPivot.rotation.x = currentLean;
figure.updateMatrixWorld(true);
const currentConfig = {
lean: currentLean,
side: currentSide,
yaw: currentYaw
};
const shoulder = shoulderLocal(currentConfig);
const localTarget = figure.worldToLocal(objectHandleWorld());
const { elbow, hand } = solveElbow(shoulder, localTarget);
setLimb(reachUpper, shoulder, elbow, 0.22, 0.22);
setLimb(reachFore, elbow, hand, 0.18, 0.18);
reachHand.position.copy(hand);
reachShoulder.position.copy(shoulder);
// Aim the head partly toward the target without exaggerating neck motion.
const targetBearing = Math.atan2(
-(localTarget.x - shoulder.x),
-(localTarget.z - shoulder.z)
);
headPivot.rotation.y = THREE.MathUtils.clamp(
targetBearing * 0.55,
-0.78,
0.78
);
// Load path through the hand toward the shoulder.
loadPath.geometry.setFromPoints([localTarget, hand, shoulder]);
loadPath.computeLineDistances();
// Object's downward gravity vector.
const arrowLength = 0.35 + mass * 0.075;
updateVoxelArrow(
objectArrow,
objectGroup.position.clone().add(new THREE.Vector3(0, 0.98, 0)),
new THREE.Vector3(0, -1, 0),
arrowLength
);
// Simplified axial-load direction aligned with the trunk.
worldShoulder.copy(shoulder)
.applyAxisAngle(yAxis, currentYaw)
.add(rootPosition);
currentTorsoQuaternion.setFromAxisAngle(xAxis, currentLean);
const axialDirection = new THREE.Vector3(0, -1, 0)
.applyQuaternion(currentTorsoQuaternion)
.applyAxisAngle(yAxis, currentYaw);
updateVoxelArrow(
spineArrow,
worldShoulder.clone().add(new THREE.Vector3(0.46, 0.15, 0)),
axialDirection,
0.56
);
targetMarker.position.copy(objectHandleWorld());
updateLabels(worldShoulder);
}
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
if (!visible) {
element.style.display = "none";
return;
}
element.style.display = "block";
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
function updateLabels(shoulderWorld) {
placeLabel(
ui.labelObject,
objectGroup.position.clone().add(new THREE.Vector3(0, 0.72, 0))
);
placeLabel(ui.labelDesk, new THREE.Vector3(-0.15, 1.53, -1.80));
placeLabel(ui.labelShelf, new THREE.Vector3(2.03, 3.20, -1.04));
placeLabel(
ui.labelLoad,
shoulderWorld.clone().add(new THREE.Vector3(0.55, 0.35, 0))
);
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
updateFigure(delta);
renderer.render(scene, camera);
}
setObjectLocation("desk");
updateUI();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```