Prompt specification
Build or customize the Three.js 3D scene "Lifting a book anatomy vignette" 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: Lifting a book anatomy vignette
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/lifting-a-book-anatomy-vignette-x0979
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a scene with a simplified person raising a book with a visible arm inset; show load direction and elbow rotation without calculating clinical muscle forces. Voxel style.
Working Three.js Starter (lifting-a-book-anatomy-vignette-x0979):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Arm Kinematics</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 22, 38, 0.88);
--panel-border: rgba(130, 192, 255, 0.18);
--text: #e8f2ff;
--muted: #91a8c2;
--cyan: #54d9ff;
--orange: #ff9f43;
--green: #63e6be;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
#mainCanvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#mainCanvas.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
max-width: 430px;
pointer-events: none;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
content: "";
background: var(--cyan);
box-shadow: 0 0 15px var(--cyan);
}
.brand h1 {
margin: 0;
font-size: clamp(24px, 3.2vw, 42px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.brand p {
max-width: 390px;
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.badge {
padding: 6px 9px;
border: 1px solid rgba(84, 217, 255, 0.25);
border-radius: 4px;
background: rgba(9, 24, 40, 0.72);
color: #b9d9ed;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.badge.warning {
border-color: rgba(255, 159, 67, 0.35);
color: #ffc27e;
}
#armInset {
position: fixed;
top: 22px;
right: 24px;
z-index: 20;
width: 326px;
overflow: hidden;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow:
0 22px 60px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(16px);
}
.inset-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 16px 11px;
border-bottom: 1px solid rgba(135, 185, 225, 0.11);
}
.inset-header strong {
font-size: 11px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.inset-header span {
color: var(--orange);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.inset-stage {
position: relative;
height: 252px;
background:
linear-gradient(rgba(84, 217, 255, 0.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(84, 217, 255, 0.025) 1px, transparent 1px),
rgba(3, 11, 21, 0.48);
background-size: 24px 24px;
}
#insetCanvas {
width: 100%;
height: 100%;
display: block;
}
#insetAngle {
position: absolute;
min-width: 52px;
padding: 5px 7px;
transform: translate(-50%, -50%);
border: 1px solid rgba(255, 159, 67, 0.55);
border-radius: 4px;
background: rgba(27, 18, 9, 0.92);
color: #ffd09f;
font-size: 11px;
font-weight: 850;
text-align: center;
pointer-events: none;
}
.inset-key {
position: absolute;
right: 12px;
bottom: 10px;
left: 12px;
display: flex;
justify-content: space-between;
gap: 10px;
color: #7f99b4;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
pointer-events: none;
}
.key-item {
display: flex;
align-items: center;
gap: 6px;
}
.key-line {
width: 18px;
height: 0;
border-top: 2px solid var(--orange);
}
.key-line.dashed {
border-top-style: dashed;
border-color: #8ba8c2;
}
.inset-copy {
padding: 11px 15px 14px;
border-top: 1px solid rgba(135, 185, 225, 0.1);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.inset-copy strong {
color: var(--text);
}
.world-label {
position: fixed;
z-index: 8;
transform: translate(-50%, -100%);
padding: 7px 9px;
border: 1px solid rgba(255, 159, 67, 0.4);
border-radius: 5px;
background: rgba(11, 20, 31, 0.86);
color: #ffd09f;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
line-height: 1.35;
text-align: center;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
}
.world-label small {
display: block;
margin-top: 2px;
color: #a7b8c9;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.06em;
}
#elbowLabel {
border-color: rgba(84, 217, 255, 0.4);
color: #a8ebff;
}
.controls {
position: fixed;
bottom: 22px;
left: 50%;
z-index: 30;
width: min(720px, calc(100vw - 48px));
padding: 14px 16px 12px;
transform: translateX(-50%);
border: 1px solid var(--panel-border);
border-radius: 12px;
background: rgba(8, 19, 33, 0.9);
box-shadow: 0 20px 55px rgba(0, 0, 0, 0.36);
backdrop-filter: blur(16px);
}
.control-row {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 15px;
}
.button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(84, 217, 255, 0.35);
border-radius: 6px;
background: rgba(84, 217, 255, 0.1);
color: #bdefff;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease,
border-color 150ms ease;
}
.button:hover {
border-color: rgba(84, 217, 255, 0.65);
background: rgba(84, 217, 255, 0.18);
}
.button:active {
transform: translateY(1px);
}
.button.secondary {
border-color: rgba(137, 168, 194, 0.25);
background: rgba(137, 168, 194, 0.07);
color: #b5c5d6;
}
.slider-wrap {
min-width: 0;
}
.slider-title {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.slider-title output {
color: var(--orange);
font-size: 11px;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 10px;
outline: none;
appearance: none;
background:
linear-gradient(
90deg,
var(--orange) 0%,
var(--orange) var(--fill, 50%),
rgba(130, 160, 190, 0.2) var(--fill, 50%),
rgba(130, 160, 190, 0.2) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 2px solid #152233;
border-radius: 3px;
appearance: none;
background: #ffb263;
box-shadow: 0 0 0 1px rgba(255, 178, 99, 0.4);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #152233;
border-radius: 3px;
background: #ffb263;
}
.control-note {
margin: 10px 0 0;
color: #7189a2;
font-size: 9px;
line-height: 1.45;
}
.control-note strong {
color: #a4b7ca;
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
}
.brand h1 {
font-size: 25px;
}
.brand p {
display: none;
}
.badges {
margin-top: 9px;
}
#armInset {
top: auto;
right: 12px;
bottom: 170px;
width: 238px;
}
.inset-stage {
height: 180px;
}
.inset-copy {
display: none;
}
.inset-key {
font-size: 7px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
transform: none;
}
.control-row {
grid-template-columns: auto 1fr;
gap: 10px;
}
#resetView {
display: none;
}
.button {
padding: 0 10px;
font-size: 9px;
}
.control-note {
font-size: 8px;
}
.world-label {
font-size: 7px;
}
}
@media (max-height: 640px) and (min-width: 761px) {
#armInset {
width: 285px;
}
.inset-stage {
height: 195px;
}
.brand p {
display: none;
}
}
</style>
</head>
<body>
<canvas id="mainCanvas" aria-label="Interactive voxel person raising a book"></canvas>
<header class="brand">
<div class="eyebrow">Voxel movement study</div>
<h1>Book lift:<br />elbow rotation</h1>
<p>
A simplified kinematic view of a person raising a voxel book, with an
enlarged elbow detail and the direction of the external book load.
</p>
<div class="badges">
<span class="badge">Kinematic only</span>
<span class="badge">Directional load</span>
<span class="badge warning">No muscle-force calculation</span>
</div>
</header>
<aside id="armInset" aria-label="Enlarged arm inset">
<div class="inset-header">
<strong>Arm detail</strong>
<span>Elbow rotation</span>
</div>
<div class="inset-stage">
<canvas id="insetCanvas" aria-label="Enlarged elbow rotation diagram"></canvas>
<div id="insetAngle" aria-live="polite">68°</div>
<div class="inset-key">
<span class="key-item"><i class="key-line"></i> rotation arc</span>
<span class="key-item"><i class="key-line dashed"></i> neutral</span>
</div>
</div>
<div class="inset-copy">
<strong>Relative rotation</strong> is measured between the forearm and
the straight continuation of the upper arm. The orange arc shows the
direction of elbow rotation.
</div>
</aside>
<div id="loadLabel" class="world-label">
External book load
<small>Direction only</small>
</div>
<div id="elbowLabel" class="world-label">
Elbow · 68°
</div>
<section class="controls" aria-label="Animation controls">
<div class="control-row">
<button id="playMotion" class="button" type="button" aria-pressed="true">
Pause motion
</button>
<div class="slider-wrap">
<label class="slider-title" for="elbowSlider">
<span>Relative elbow rotation</span>
<output id="angleOutput" for="elbowSlider">68°</output>
</label>
<input
id="elbowSlider"
type="range"
min="25"
max="100"
step="1"
value="68"
aria-label="Relative elbow rotation in degrees"
/>
</div>
<button id="resetView" class="button secondary" type="button">
Reset view
</button>
</div>
<p class="control-note">
<strong>Descriptive visualization only.</strong>
The load arrow indicates direction, not magnitude. No clinical muscle
forces, moments, or tissue stresses are calculated.
</p>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Shared helpers
// -------------------------------------------------------------------------
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const DEG = Math.PI / 180;
function clamp(value, min, max) {
return Math.min(max, Math.max(min, value));
}
function easeInOutSine(t) {
return -(Math.cos(Math.PI * t) - 1) * 0.5;
}
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
...options
});
}
function makeBox(width, height, depth, material, x, y, z, parent) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createVoxelLimb(material, count = 5, spacing = 0.18, width = 0.22) {
const group = new THREE.Group();
const segmentHeight = spacing * 0.88;
for (let i = 0; i < count; i += 1) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, segmentHeight, width),
material
);
mesh.position.y = (i - (count - 1) / 2) * spacing;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
group.userData.baseLength =
(count - 1) * spacing + segmentHeight;
return group;
}
function positionVoxelLimb(group, start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
group.position.copy(midpoint);
group.quaternion.setFromUnitVectors(
Y_AXIS,
direction.normalize()
);
group.scale.set(1, length / group.userData.baseLength, 1);
}
function replaceLineGeometry(line, points) {
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints(points);
}
function makeArcArrow(color, radius, lineWidth = 1) {
const line = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
line.renderOrder = 20;
const arrowhead = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.18, 4),
new THREE.MeshBasicMaterial({
color,
depthTest: false
})
);
arrowhead.renderOrder = 21;
return {
line,
arrowhead,
radius,
lineWidth,
update(center, startAngle, endAngle) {
const points = [];
const segments = 44;
for (let i = 0; i <= segments; i += 1) {
const t = i / segments;
const angle = THREE.MathUtils.lerp(startAngle, endAngle, t);
points.push(
new THREE.Vector3(
center.x + Math.cos(angle) * radius,
center.y + Math.sin(angle) * radius,
center.z
)
);
}
replaceLineGeometry(line, points);
const tangent = new THREE.Vector3(
Math.sin(startAngle),
-Math.cos(startAngle),
0
);
const endpoint = points[0];
arrowhead.quaternion.setFromUnitVectors(Y_AXIS, tangent);
arrowhead.position
.copy(endpoint)
.addScaledVector(tangent, -0.09);
}
};
}
// -------------------------------------------------------------------------
// Main scene
// -------------------------------------------------------------------------
const mainCanvas = document.querySelector("#mainCanvas");
const renderer = new THREE.WebGLRenderer({
canvas: mainCanvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 9, 19);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 50);
const cameraTarget = new THREE.Vector3(-0.25, 2.55, 0);
const hemisphere = new THREE.HemisphereLight(0xa8ddff, 0x172033, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.3);
keyLight.position.set(4.5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4dd8ff, 1.35);
rimLight.position.set(-4, 4, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9f43, 9, 7, 2);
warmLight.position.set(-0.5, 4.8, 2.5);
scene.add(warmLight);
const materials = {
skin: makeMaterial(0xefaa78),
skinLight: makeMaterial(0xf7bd8c),
jacket: makeMaterial(0x2a91a7),
jacketDark: makeMaterial(0x1f687b),
shirt: makeMaterial(0xdcecf4),
pants: makeMaterial(0x263957),
pantsDark: makeMaterial(0x1b2940),
shoe: makeMaterial(0x111c2c),
hair: makeMaterial(0x25202a),
eye: makeMaterial(0x111820),
bookCover: makeMaterial(0xe95d35),
bookCoverDark: makeMaterial(0xb93c28),
pages: makeMaterial(0xf2dfb0),
cyan: makeMaterial(0x2b7184),
blue: makeMaterial(0x244c70),
neutral: makeMaterial(0x172b43)
};
// Ground and voxel stage.
const grid = new THREE.GridHelper(16, 32, 0x31506b, 0x1a2b40);
grid.position.y = 0.015;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
makeBox(3.3, 0.16, 2.25, materials.neutral, -0.38, -0.08, 0, scene);
makeBox(2.65, 0.05, 1.72, materials.blue, -0.38, 0.025, 0, scene);
// Decorative voxel blocks.
const blockSpecs = [
[1.65, 0.35, 0.55, 0.35, materials.cyan],
[2.05, 0.35, 0.55, 0.35, materials.blue],
[1.85, 0.35, 0.55, 0.35, materials.cyan],
[-2.15, 0.25, 0.65, 0.25, materials.blue],
[-2.4, 0.25, 0.65, 0.25, materials.neutral],
[1.95, 0.18, -1.1, 0.18, materials.neutral],
[2.25, 0.18, -1.1, 0.18, materials.blue]
];
for (const [x, y, z, width, material] of blockSpecs) {
makeBox(width, width, width, material, x, y, z, scene);
}
// -------------------------------------------------------------------------
// Voxel person
// -------------------------------------------------------------------------
const bodyX = -0.4;
// Legs and shoes.
makeBox(0.29, 0.68, 0.32, materials.pants, bodyX - 0.18, 0.57, 0, scene);
makeBox(0.29, 0.61, 0.32, materials.pantsDark, bodyX - 0.18, 0.25, 0.01, scene);
makeBox(0.29, 0.68, 0.32, materials.pants, bodyX + 0.19, 0.57, 0, scene);
makeBox(0.29, 0.61, 0.32, materials.pantsDark, bodyX + 0.19, 0.25, 0.01, scene);
makeBox(0.35, 0.16, 0.49, materials.shoe, bodyX - 0.16, 0.08, 0.08, scene);
makeBox(0.35, 0.16, 0.49, materials.shoe, bodyX + 0.21, 0.08, 0.08, scene);
// Pelvis, torso, and clothing details.
makeBox(0.67, 0.31, 0.42, materials.pantsDark, bodyX, 1.16, 0, scene);
makeBox(0.72, 1.02, 0.43, materials.jacket, bodyX, 1.92, 0, scene);
makeBox(0.27, 0.68, 0.025, materials.shirt, bodyX + 0.06, 1.98, 0.228, scene);
makeBox(0.06, 0.8, 0.035, materials.jacketDark, bodyX + 0.06, 1.93, 0.25, scene);
makeBox(0.74, 0.12, 0.46, materials.jacketDark, bodyX, 2.38, 0, scene);
// Neck and head.
makeBox(0.23, 0.22, 0.24, materials.skin, bodyX, 2.56, 0, scene);
makeBox(0.52, 0.52, 0.49, materials.skinLight, bodyX, 2.91, 0, scene);
makeBox(0.54, 0.14, 0.51, materials.hair, bodyX, 3.17, -0.01, scene);
makeBox(0.15, 0.25, 0.51, materials.hair, bodyX - 0.23, 2.98, -0.01, scene);
makeBox(0.09, 0.08, 0.035, materials.eye, bodyX - 0.13, 2.97, 0.257, scene);
makeBox(0.09, 0.08, 0.035, materials.eye, bodyX + 0.13, 2.97, 0.257, scene);
makeBox(0.10, 0.10, 0.09, materials.skin, bodyX, 2.83, 0.285, scene);
// Active shoulder.
const shoulder = new THREE.Vector3(-0.78, 2.53, 0.24);
const elbow = new THREE.Vector3(-0.98, 3.48, 0.24);
const upperArm = createVoxelLimb(materials.skin, 5, 0.19, 0.23);
const forearm = createVoxelLimb(materials.skinLight, 6, 0.18, 0.21);
scene.add(upperArm, forearm);
makeBox(0.31, 0.31, 0.34, materials.jacketDark, ...shoulder.toArray(), scene);
makeBox(0.28, 0.28, 0.29, materials.skin, ...elbow.toArray(), scene);
// The inactive arm remains beside the body.
const otherShoulder = new THREE.Vector3(-0.03, 2.48, -0.05);
const otherElbow = new THREE.Vector3(0.02, 1.83, -0.04);
const otherWrist = new THREE.Vector3(0.14, 1.23, -0.02);
const otherUpper = createVoxelLimb(materials.skin, 4, 0.18, 0.2);
const otherForearm = createVoxelLimb(materials.skinLight, 4, 0.18, 0.19);
scene.add(otherUpper, otherForearm);
positionVoxelLimb(otherUpper, otherShoulder, otherElbow);
positionVoxelLimb(otherForearm, otherElbow, otherWrist);
makeBox(0.22, 0.25, 0.22, materials.skinLight, ...otherWrist.toArray(), scene);
// Voxel book.
const book = new THREE.Group();
scene.add(book);
makeBox(0.94, 0.17, 0.66, materials.pages, 0, 0, 0, book);
makeBox(1.01, 0.055, 0.72, materials.bookCover, 0, 0.115, 0, book);
makeBox(1.01, 0.055, 0.72, materials.bookCover, 0, -0.115, 0, book);
makeBox(0.075, 0.28, 0.73, materials.bookCoverDark, -0.48, 0, 0, book);
makeBox(0.18, 0.035, 0.29, materials.bookCoverDark, -0.475, 0.15, 0.04, book);
const hand = makeBox(
0.23,
0.23,
0.24,
materials.skinLight,
0,
0,
0,
scene
);
// Downward external-load direction arrow.
const loadArrow = new THREE.Group();
scene.add(loadArrow);
const loadShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.026, 0.026, 0.72, 8),
new THREE.MeshBasicMaterial({ color: 0xffa14a })
);
loadShaft.position.y = 0.6;
loadArrow.add(loadShaft);
const loadHead = new THREE.Mesh(
new THREE.ConeGeometry(0.115, 0.24, 4),
new THREE.MeshBasicMaterial({ color: 0xffa14a })
);
loadHead.position.y = 0.12;
loadHead.rotation.z = Math.PI;
loadArrow.add(loadHead);
// Main-view elbow arc.
const mainArc = makeArcArrow(0xffa14a, 0.34);
scene.add(mainArc.line, mainArc.arrowhead);
const neutralAngle = Math.atan2(
elbow.y - shoulder.y,
elbow.x - shoulder.x
);
// -------------------------------------------------------------------------
// Enlarged inset scene
// -------------------------------------------------------------------------
const insetCanvas = document.querySelector("#insetCanvas");
const insetStage = document.querySelector(".inset-stage");
const insetRenderer = new THREE.WebGLRenderer({
canvas: insetCanvas,
antialias: true,
alpha: true
});
insetRenderer.outputColorSpace = THREE.SRGBColorSpace;
insetRenderer.toneMapping = THREE.ACESFilmicToneMapping;
insetRenderer.toneMappingExposure = 1.15;
insetRenderer.setClearColor(0x07111f, 0.24);
const insetScene = new THREE.Scene();
const insetCamera = new THREE.OrthographicCamera(-1.6, 1.6, 1.25, -1.25, 0.1, 20);
insetCamera.position.set(0, 0, 5);
insetCamera.lookAt(0, 0, 0);
insetScene.add(new THREE.HemisphereLight(0xc8ecff, 0x142033, 2.3));
const insetKey = new THREE.DirectionalLight(0xffffff, 3.0);
insetKey.position.set(2, 4, 5);
insetScene.add(insetKey);
const insetRim = new THREE.DirectionalLight(0x4fd8ff, 1.8);
insetRim.position.set(-3, 1, -3);
insetScene.add(insetRim);
const insetMaterials = {
skin: makeMaterial(0xefaa78),
skinLight: makeMaterial(0xffc293),
joint: makeMaterial(0x54d9ff, {
emissive: 0x123a48,
emissiveIntensity: 0.5
})
};
const insetShoulder = new THREE.Vector3(0.95, -0.78, 0);
const insetElbow = new THREE.Vector3(0, 0, 0);
const insetWrist = new THREE.Vector3();
const insetUpper = createVoxelLimb(insetMaterials.skin, 5, 0.2, 0.25);
const insetForearm = createVoxelLimb(insetMaterials.skinLight, 6, 0.19, 0.23);
insetScene.add(insetUpper, insetForearm);
const insetShoulderJoint = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.28, 0.3),
insetMaterials.joint
);
insetShoulderJoint.position.copy(insetShoulder);
insetScene.add(insetShoulderJoint);
const insetElbowJoint = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.32, 0.34),
insetMaterials.joint
);
insetElbowJoint.position.copy(insetElbow);
insetScene.add(insetElbowJoint);
const insetHand = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.25, 0.27),
insetMaterials.skinLight
);
insetScene.add(insetHand);
// Dashed neutral straight-arm reference.
const insetNeutralLine = new THREE.Line(
new THREE.BufferGeometry(),
new THREE.LineDashedMaterial({
color: 0x8ba8c2,
dashSize: 0.09,
gapSize: 0.07,
transparent: true,
opacity: 0.85
})
);
insetScene.add(insetNeutralLine);
// Filled angular sector.
const insetWedge = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshBasicMaterial({
color: 0xff9f43,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
})
);
insetScene.add(insetWedge);
const insetArc = makeArcArrow(0xffa14a, 0.52);
insetScene.add(insetArc.line, insetArc.arrowhead);
const insetNeutralAngle = Math.atan2(
insetElbow.y - insetShoulder.y,
insetElbow.x - insetShoulder.x
);
// -------------------------------------------------------------------------
// Pose update
// -------------------------------------------------------------------------
const loadLabel = document.querySelector("#loadLabel");
const elbowLabel = document.querySelector("#elbowLabel");
const insetAngleLabel = document.querySelector("#insetAngle");
const angleOutput = document.querySelector("#angleOutput");
const elbowSlider = document.querySelector("#elbowSlider");
const playMotion = document.querySelector("#playMotion");
let elbowRotation = 68;
let playing = true;
function updateWedge(actualAngle, neutral) {
const radius = 0.43;
const shape = new THREE.Shape();
shape.moveTo(0, 0);
shape.lineTo(
Math.cos(actualAngle) * radius,
Math.sin(actualAngle) * radius
);
shape.absarc(0, 0, radius, actualAngle, neutral, false);
shape.lineTo(0, 0);
insetWedge.geometry.dispose();
insetWedge.geometry = new THREE.ShapeGeometry(shape);
}
function updatePose(degrees) {
const rotationRadians = degrees * DEG;
const forearmAngle = neutralAngle - rotationRadians;
const forearmDirection = new THREE.Vector3(
Math.cos(forearmAngle),
Math.sin(forearmAngle),
0
);
const wrist = elbow.clone().addScaledVector(forearmDirection, 1.05);
positionVoxelLimb(upperArm, shoulder, elbow);
positionVoxelLimb(forearm, elbow, wrist);
hand.position.copy(wrist).add(new THREE.Vector3(-0.015, 0, 0));
hand.rotation.z = forearmAngle;
book.position.copy(wrist).add(new THREE.Vector3(0.13, 0.13, 0));
book.rotation.z = -0.035;
const bookTop = book.position.y + 0.15;
const arrowTip = bookTop + 0.16;
loadArrow.position.set(book.position.x, arrowTip, 0.34);
mainArc.update(
elbow,
forearmAngle,
neutralAngle
);
// Inset kinematics.
const insetForearmAngle = insetNeutralAngle - rotationRadians;
insetWrist.set(
Math.cos(insetForearmAngle) * 1.16,
Math.sin(insetForearmAngle) * 1.16,
0
);
positionVoxelLimb(insetUpper, insetShoulder, insetElbow);
positionVoxelLimb(insetForearm, insetElbow, insetWrist);
insetHand.position.copy(insetWrist);
insetHand.rotation.z = insetForearmAngle;
const neutralEnd = new THREE.Vector3(
Math.cos(insetNeutralAngle) * 1.4,
Math.sin(insetNeutralAngle) * 1.4,
0
);
replaceLineGeometry(insetNeutralLine, [
insetElbow,
neutralEnd
]);
insetNeutralLine.computeLineDistances();
insetArc.update(
insetElbow,
insetForearmAngle,
insetNeutralAngle
);
updateWedge(insetForearmAngle, insetNeutralAngle);
const rounded = Math.round(degrees);
angleOutput.value = `${rounded}°`;
angleOutput.textContent = `${rounded}°`;
insetAngleLabel.textContent = `${rounded}°`;
elbowLabel.innerHTML = `Elbow · ${rounded}°`;
const fill =
((degrees - Number(elbowSlider.min)) /
(Number(elbowSlider.max) - Number(elbowSlider.min))) *
100;
elbowSlider.style.setProperty("--fill", `${fill}%`);
}
function projectWorldLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.opacity = "0";
return;
}
element.style.opacity = "1";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function updateInsetAngleLabel() {
const actual = insetNeutralAngle - elbowRotation * DEG;
const middle = THREE.MathUtils.lerp(actual, insetNeutralAngle, 0.5);
const point = new THREE.Vector3(
Math.cos(middle) * 0.78,
Math.sin(middle) * 0.78,
0.1
).project(insetCamera);
const canvasRect = insetCanvas.getBoundingClientRect();
const stageRect = insetStage.getBoundingClientRect();
insetAngleLabel.style.left =
`${canvasRect.left - stageRect.left + (point.x * 0.5 + 0.5) * canvasRect.width}px`;
insetAngleLabel.style.top =
`${canvasRect.top - stageRect.top + (-point.y * 0.5 + 0.5) * canvasRect.height}px`;
}
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
elbowSlider.addEventListener("input", () => {
playing = false;
playMotion.setAttribute("aria-pressed", "false");
playMotion.textContent = "Play motion";
elbowRotation = Number(elbowSlider.value);
});
playMotion.addEventListener("click", () => {
playing = !playing;
playMotion.setAttribute("aria-pressed", String(playing));
playMotion.textContent = playing ? "Pause motion" : "Play motion";
});
// Direct camera controls implemented without addons.
const cameraState = {
yaw: 0.48,
pitch: 0.29,
radius: 8.6
};
const defaultCamera = { ...cameraState };
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.cos(pitch) * Math.sin(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
Object.assign(cameraState, defaultCamera);
updateCamera();
}
mainCanvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
mainCanvas.setPointerCapture(event.pointerId);
mainCanvas.classList.add("dragging");
});
mainCanvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = clamp(
cameraState.pitch + dy * 0.0045,
0.08,
0.95
);
updateCamera();
});
function endDrag(event) {
dragging = false;
mainCanvas.classList.remove("dragging");
if (mainCanvas.hasPointerCapture(event.pointerId)) {
mainCanvas.releasePointerCapture(event.pointerId);
}
}
mainCanvas.addEventListener("pointerup", endDrag);
mainCanvas.addEventListener("pointercancel", endDrag);
mainCanvas.addEventListener("contextmenu", (event) => event.preventDefault());
mainCanvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.006,
5.8,
12.5
);
updateCamera();
},
{ passive: false }
);
mainCanvas.addEventListener("dblclick", resetCamera);
document.querySelector("#resetView").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
const insetWidth = insetCanvas.clientWidth;
const insetHeight = insetCanvas.clientHeight;
const insetAspect = insetWidth / insetHeight;
const viewHeight = 2.5;
insetRenderer.setPixelRatio(
Math.min(window.devicePixelRatio || 1, 2)
);
insetRenderer.setSize(insetWidth, insetHeight, false);
insetCamera.left = (-viewHeight * insetAspect) / 2;
insetCamera.right = (viewHeight * insetAspect) / 2;
insetCamera.top = viewHeight / 2;
insetCamera.bottom = -viewHeight / 2;
insetCamera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
updatePose(elbowRotation);
const loadLabelPosition = new THREE.Vector3();
const elbowLabelPosition = new THREE.Vector3();
function animate(time) {
requestAnimationFrame(animate);
if (playing) {
// A smooth raise/lower cycle: the book rises as the relative rotation
// decreases, then returns to the lower position.
elbowRotation = 65 - 30 * Math.sin(time * 0.00062);
elbowSlider.value = elbowRotation.toFixed(0);
}
updatePose(elbowRotation);
loadLabelPosition.set(
book.position.x,
loadArrow.position.y + 1.0,
0.4
);
elbowLabelPosition.set(
elbow.x - 0.3,
elbow.y + 0.1,
0.42
);
projectWorldLabel(loadLabel, loadLabelPosition);
projectWorldLabel(elbowLabel, elbowLabelPosition);
updateInsetAngleLabel();
renderer.render(scene, camera);
insetRenderer.render(insetScene, insetCamera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```