Prompt specification
Build or customize the Three.js 3D scene "Figure Reaches Between Two Holds" 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: Figure Reaches Between Two Holds
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/figure-reaches-between-two-holds-x3610
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts climbing holds and geometric reach limits. Animate a stylized figure shifting one hand while other support points remain fixed. Use a simple joint model and display unreachable targets rather than stretching limbs. Voxel style.
Working Three.js Starter (figure-reaches-between-two-holds-x3610):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Reach — Climbing Kinematics</title>
<style>
:root {
color-scheme: dark;
--bg: #07111e;
--panel: rgba(9, 21, 36, 0.84);
--line: rgba(154, 198, 231, 0.18);
--muted: #8198ac;
--text: #e9f5ff;
--cyan: #63e7ff;
--mint: #43ddb5;
--amber: #ffb454;
--red: #ff5874;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.brand {
position: absolute;
top: 26px;
left: 28px;
max-width: 360px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}
.eyebrow {
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
}
.brand h1 {
margin: 0;
font-size: clamp(26px, 3.2vw, 46px);
line-height: 0.95;
letter-spacing: -0.055em;
}
.brand p {
margin: 12px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
}
.metrics {
position: absolute;
top: 24px;
right: 24px;
width: 272px;
padding: 6px;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.metric {
position: relative;
padding: 13px 14px;
border-bottom: 1px solid var(--line);
}
.metric:last-child {
border-bottom: 0;
}
.metric span,
.metric small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
}
.metric strong {
display: block;
margin: 6px 0 4px;
font-size: 18px;
letter-spacing: -0.03em;
}
.metric.cyan strong {
color: var(--cyan);
}
.metric.mint strong {
color: var(--mint);
}
.metric.red strong,
.metric.red small {
color: var(--red);
}
.control {
position: absolute;
left: 28px;
bottom: 27px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
line-height: 1.7;
letter-spacing: 0.12em;
}
.control b {
color: var(--text);
font-weight: 800;
}
.status {
position: absolute;
left: 50%;
bottom: 24px;
width: min(560px, calc(100vw - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: 1.35fr 0.85fr 0.85fr;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(14px);
}
.status-cell {
min-width: 0;
padding: 15px 17px;
border-right: 1px solid var(--line);
}
.status-cell:last-child {
border-right: 0;
}
.status-cell small {
display: block;
overflow: hidden;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-overflow: ellipsis;
white-space: nowrap;
}
.status-cell strong {
display: flex;
align-items: center;
gap: 8px;
margin-top: 7px;
font-size: 12px;
letter-spacing: 0.05em;
white-space: nowrap;
}
.dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 14px currentColor;
}
.track {
position: relative;
height: 3px;
margin-top: 10px;
overflow: hidden;
background: rgba(255, 255, 255, 0.08);
}
.track i {
position: absolute;
inset: 0;
transform: scaleX(0);
transform-origin: left center;
background: linear-gradient(90deg, var(--amber), var(--cyan));
}
.corner-note {
position: absolute;
right: 27px;
bottom: 28px;
max-width: 235px;
color: var(--muted);
font-size: 9px;
line-height: 1.6;
text-align: right;
}
.corner-note b {
color: var(--red);
}
@media (max-width: 1100px) {
.control {
display: none;
}
.corner-note {
display: none;
}
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 18px;
}
.brand p {
display: none;
}
.metrics {
display: none;
}
.status {
bottom: 16px;
grid-template-columns: 1.25fr 0.75fr;
}
.status-cell:last-child {
display: none;
}
.status-cell {
padding: 13px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<header class="brand">
<div class="eyebrow">KINEMATICS STUDY / 03</div>
<h1>VOXEL REACH</h1>
<p>Fixed-length limbs. Visible envelopes. Honest targets.</p>
</header>
<aside class="metrics">
<div class="metric cyan">
<span>SHOULDER ENVELOPE</span>
<strong>1.30 m</strong>
<small>2 × 0.65 m FIXED SEGMENTS</small>
</div>
<div class="metric mint">
<span>NEXT HOLD / B</span>
<strong id="reachableDistance">1.18 m</strong>
<small>REACHABLE</small>
</div>
<div class="metric red">
<span>TARGET / C6</span>
<strong id="unreachableDistance">2.30 m</strong>
<small id="unreachableRatio">177% OF REACH — UNREACHABLE</small>
</div>
</aside>
<div class="control">
<b>DRAG</b> TO ORBIT<br />
<b>SCROLL</b> TO ZOOM
</div>
<section class="status" aria-live="polite">
<div class="status-cell">
<small>RIGHT HAND / MOVING JOINT</small>
<strong>
<i id="stateDot" class="dot"></i>
<span id="stateText">HOLDING A</span>
</strong>
<div class="track"><i id="progressFill"></i></div>
</div>
<div class="status-cell">
<small>FIXED SUPPORTS</small>
<strong>3 JOINTS</strong>
</div>
<div class="status-cell">
<small>UNREACHABLE TARGET</small>
<strong style="color: var(--red)">NOT STRETCHED</strong>
</div>
</section>
<div class="corner-note">
Red target remains outside the analytic reach envelope.<br />
<b>No limb extension is simulated.</b>
</div>
</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 app = document.getElementById("app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x07111e, 1);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111e);
scene.fog = new THREE.Fog(0x07111e, 12, 25);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
50
);
const UP = new THREE.Vector3(0, 1, 0);
const Z_AXIS = new THREE.Vector3(0, 0, 1);
const vec = (x = 0, y = 0, z = 0) =>
new THREE.Vector3(x, y, z);
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0x06101b,
transparent: true,
opacity: 0.8
});
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0.03,
...options
});
}
function makeBox(parent, size, position, material, outlined = false) {
const geometry = new THREE.BoxGeometry(...size);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
outlineMaterial
);
edges.renderOrder = 4;
mesh.add(edges);
}
return mesh;
}
function makeSegment(width, depth, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, 1, depth),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function poseSegment(mesh, start, end) {
const direction = end.clone().sub(start);
const length = direction.length();
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(UP, direction.normalize());
}
// -----------------------------------------------------------------------
// Lighting
// -----------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa7ceff, 0x111421, 2.1));
const keyLight = new THREE.DirectionalLight(0xffefd7, 3.1);
keyLight.position.set(4.5, 6.5, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const cyanFill = new THREE.PointLight(0x44dfff, 14, 12, 2);
cyanFill.position.set(-4, 1.5, 4);
scene.add(cyanFill);
const amberFill = new THREE.PointLight(0xff9c43, 10, 10, 2);
amberFill.position.set(4, -1.5, 3);
scene.add(amberFill);
// -----------------------------------------------------------------------
// Voxel climbing wall
// -----------------------------------------------------------------------
const wallBaseMaterial = standardMaterial(0x14243a, {
roughness: 0.95
});
const frameMaterial = standardMaterial(0x2c435e, {
roughness: 0.72,
metalness: 0.12
});
makeBox(
scene,
[7.9, 5.45, 0.28],
[0, 0, -0.25],
wallBaseMaterial,
true
);
const columns = 12;
const rows = 8;
const step = 0.62;
const tileSize = 0.55;
const tileGeometry = new THREE.BoxGeometry(tileSize, tileSize, 0.16);
const tileMaterial = standardMaterial(0xffffff, {
roughness: 0.96
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
columns * rows
);
tiles.castShadow = false;
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = (column - (columns - 1) / 2) * step;
const y = (row - (rows - 1) / 2) * step;
dummy.position.set(x, y, -0.02);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const variation = Math.sin(column * 12.73 + row * 4.19) * 0.5 + 0.5;
const lightness = 0.105 + variation * 0.035;
const hue = 0.585 + variation * 0.025;
tileColor.setHSL(hue, 0.29, lightness);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
makeBox(scene, [0.18, 5.45, 0.34], [-3.84, 0, -0.02], frameMaterial, true);
makeBox(scene, [0.18, 5.45, 0.34], [3.84, 0, -0.02], frameMaterial, true);
makeBox(scene, [7.75, 0.18, 0.34], [0, 2.62, -0.02], frameMaterial, true);
makeBox(scene, [7.75, 0.18, 0.34], [0, -2.62, -0.02], frameMaterial, true);
const boltMaterial = standardMaterial(0x7890a6, {
metalness: 0.45,
roughness: 0.42
});
for (const x of [-3.62, 3.62]) {
for (const y of [-2.4, 2.4]) {
makeBox(scene, [0.1, 0.1, 0.08], [x, y, 0.19], boltMaterial);
}
}
// -----------------------------------------------------------------------
// Holds
// -----------------------------------------------------------------------
const holdMaterials = {
mint: standardMaterial(0x43ddb5, {
roughness: 0.64,
emissive: 0x073a2e,
emissiveIntensity: 0.35
}),
amber: standardMaterial(0xffb454, {
roughness: 0.65,
emissive: 0x4b2705,
emissiveIntensity: 0.3
}),
cyan: standardMaterial(0x63e7ff, {
roughness: 0.58,
emissive: 0x063947,
emissiveIntensity: 0.45
}),
red: standardMaterial(0xff5874, {
roughness: 0.6,
emissive: 0x4b0715,
emissiveIntensity: 0.5
}),
muted: standardMaterial(0x536e88, {
roughness: 0.9
})
};
function createHold(x, y, material, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, 0);
group.scale.setScalar(scale);
makeBox(group, [0.42, 0.28, 0.34], [0, 0, 0.2], material);
makeBox(group, [0.2, 0.16, 0.2], [0.08, 0.13, 0.34], material);
makeBox(group, [0.16, 0.12, 0.14], [-0.12, -0.08, 0.27], material);
scene.add(group);
return group;
}
const decorativeHolds = [
[-2.78, -1.55, "muted", 0.72],
[-2.86, 0.05, "muted", 0.62],
[-2.48, 2.08, "muted", 0.65],
[2.73, -1.02, "muted", 0.72],
[2.74, 0.28, "muted", 0.58],
[1.85, 2.32, "muted", 0.62],
[0.04, -2.22, "muted", 0.68],
[-1.86, -2.18, "muted", 0.58]
];
for (const [x, y, color, scale] of decorativeHolds) {
createHold(x, y, holdMaterials[color], scale);
}
// Support and route holds.
createHold(-1.3, 1.15, holdMaterials.mint);
createHold(-1.0, -1.58, holdMaterials.mint);
createHold(0.88, -1.78, holdMaterials.mint);
createHold(-0.35, 1.18, holdMaterials.amber);
createHold(0.78, 1.43, holdMaterials.cyan);
createHold(2.12, 1.85, holdMaterials.red);
// -----------------------------------------------------------------------
// Labels and support markers
// -----------------------------------------------------------------------
function makeLabelSprite(text, color, width = 1.4) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(7, 16, 29, 0.92)";
context.fillRect(5, 5, 502, 118);
context.strokeStyle = color;
context.lineWidth = 7;
context.strokeRect(5, 5, 502, 118);
context.fillStyle = color;
context.font =
"800 37px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.generateMipmaps = false;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
return sprite;
}
const holdBLabel = makeLabelSprite("B / REACHABLE", "#63e7ff", 1.55);
holdBLabel.position.set(0.78, 1.87, 0.68);
scene.add(holdBLabel);
const holdALabel = makeLabelSprite("A", "#ffb454", 0.45);
holdALabel.position.set(-0.35, 1.58, 0.66);
scene.add(holdALabel);
const unreachableLabel = makeLabelSprite(
"OUT OF REACH",
"#ff5874",
1.85
);
unreachableLabel.position.set(2.12, 2.47, 0.74);
scene.add(unreachableLabel);
const limitLabel = makeLabelSprite("1.30 m LIMIT", "#63e7ff", 1.25);
limitLabel.position.set(1.37, 0.92, 0.47);
scene.add(limitLabel);
function addSupportBracket(point, color) {
const group = new THREE.Group();
group.position.set(point.x, point.y, point.z);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.85
});
const size = 0.39;
const length = 0.12;
const thickness = 0.035;
for (const sx of [-1, 1]) {
for (const sy of [-1, 1]) {
makeBox(
group,
[length, thickness, thickness],
[sx * (size / 2 - length / 2), sy * size / 2, 0],
material
);
makeBox(
group,
[thickness, length, thickness],
[sx * size / 2, sy * (size / 2 - length / 2), 0],
material
);
}
}
scene.add(group);
}
addSupportBracket(vec(-1.3, 1.15, 0.47), 0x43ddb5);
addSupportBracket(vec(-1.0, -1.58, 0.43), 0x43ddb5);
addSupportBracket(vec(0.88, -1.78, 0.43), 0x43ddb5);
// -----------------------------------------------------------------------
// Reach envelopes
// -----------------------------------------------------------------------
function createReachEnvelope(center, radius, color, opacity) {
const group = new THREE.Group();
group.position.set(center.x, center.y, 0.17);
const fill = new THREE.Mesh(
new THREE.CircleGeometry(radius, 96),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.025,
depthWrite: false,
side: THREE.DoubleSide
})
);
fill.position.z = -0.01;
fill.renderOrder = 1;
group.add(fill);
const points = [];
for (let i = 0; i < 96; i++) {
const angle = (i / 96) * Math.PI * 2;
points.push(
vec(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0.01
)
);
}
const line = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color,
dashSize: 0.07,
gapSize: 0.055,
transparent: true,
opacity,
depthWrite: false
})
);
line.computeLineDistances();
line.renderOrder = 2;
group.add(line);
scene.add(group);
return group;
}
const leftShoulder = vec(-0.42, 0.3, 0.62);
const rightShoulder = vec(0.42, 0.3, 0.62);
const armReach = 1.3;
createReachEnvelope(leftShoulder, armReach, 0xffb454, 0.18);
createReachEnvelope(rightShoulder, armReach, 0x63e7ff, 0.4);
function dashedLine(points, color, opacity = 0.8) {
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color,
dashSize: 0.09,
gapSize: 0.055,
transparent: true,
opacity,
depthWrite: false
})
);
line.computeLineDistances();
scene.add(line);
return line;
}
dashedLine(
[
vec(-0.35, 1.18, 0.22),
vec(0.78, 1.43, 0.22)
],
0x63e7ff,
0.55
);
dashedLine(
[
vec(rightShoulder.x, rightShoulder.y, 0.23),
vec(2.12, 1.85, 0.23)
],
0xff5874,
0.72
);
// A small boundary marker emphasizes where the red route leaves the envelope.
const boundaryDirection = vec(
2.12 - rightShoulder.x,
1.85 - rightShoulder.y,
0
).normalize();
const boundaryPoint = rightShoulder
.clone()
.addScaledVector(boundaryDirection, armReach);
const boundaryMaterial = new THREE.MeshBasicMaterial({
color: 0x63e7ff
});
makeBox(
scene,
[0.11, 0.11, 0.04],
[boundaryPoint.x, boundaryPoint.y, 0.29],
boundaryMaterial
);
// Red X on the unreachable target.
const unreachableMarker = new THREE.Group();
unreachableMarker.position.set(2.12, 1.85, 0.51);
const markerBarA = makeBox(
unreachableMarker,
[0.48, 0.07, 0.07],
[0, 0, 0],
new THREE.MeshBasicMaterial({ color: 0xff5874 })
);
markerBarA.rotation.z = Math.PI / 4;
const markerBarB = makeBox(
unreachableMarker,
[0.48, 0.07, 0.07],
[0, 0, 0],
new THREE.MeshBasicMaterial({ color: 0xff5874 })
);
markerBarB.rotation.z = -Math.PI / 4;
scene.add(unreachableMarker);
function createSquareMarker(x, y, size, color) {
const points = [
vec(x - size / 2, y - size / 2, 0.49),
vec(x + size / 2, y - size / 2, 0.49),
vec(x + size / 2, y + size / 2, 0.49),
vec(x - size / 2, y + size / 2, 0.49)
];
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.8
});
const marker = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
material
);
marker.renderOrder = 6;
scene.add(marker);
return marker;
}
const nextHoldMarker = createSquareMarker(
0.78,
1.43,
0.58,
0x63e7ff
);
// -----------------------------------------------------------------------
// Figure: simple fixed-length 2-bone joint model
// -----------------------------------------------------------------------
const figure = new THREE.Group();
scene.add(figure);
const shirtMaterial = standardMaterial(0xffb454);
const movingArmMaterial = standardMaterial(0x63e7ff, {
roughness: 0.68,
emissive: 0x07323a,
emissiveIntensity: 0.22
});
const pantsMaterial = standardMaterial(0x263b58);
const jointMaterial = standardMaterial(0x102238);
const skinMaterial = standardMaterial(0xffd2a1);
const hairMaterial = standardMaterial(0x17263c);
const eyeMaterial = standardMaterial(0x07101b, {
roughness: 1
});
// Blocky torso, backpack, neck, and face.
makeBox(
figure,
[0.64, 0.66, 0.38],
[0, 0.03, 0.56],
shirtMaterial,
true
);
makeBox(
figure,
[0.76, 0.28, 0.4],
[0.02, 0.39, 0.54],
shirtMaterial,
true
);
makeBox(
figure,
[0.56, 0.34, 0.38],
[0, -0.48, 0.55],
pantsMaterial,
true
);
makeBox(
figure,
[0.5, 0.58, 0.22],
[0.01, 0.1, 0.28],
pantsMaterial,
true
);
makeBox(
figure,
[0.18, 0.17, 0.18],
[0.05, 0.64, 0.54],
skinMaterial
);
makeBox(
figure,
[0.45, 0.45, 0.4],
[0.05, 0.89, 0.55],
skinMaterial,
true
);
makeBox(
figure,
[0.47, 0.14, 0.42],
[0.05, 1.11, 0.54],
hairMaterial,
true
);
makeBox(
figure,
[0.07, 0.07, 0.035],
[-0.035, 0.91, 0.765],
eyeMaterial
);
makeBox(
figure,
[0.07, 0.07, 0.035],
[0.14, 0.91, 0.765],
eyeMaterial
);
makeBox(
figure,
[0.13, 0.035, 0.035],
[0.055, 0.8, 0.765],
eyeMaterial
);
// Analytic two-bone IK. It refuses targets outside the fixed bone lengths.
function solveIK(root, target, lengthA, lengthB, bendHint) {
const delta = target.clone().sub(root);
const distance = delta.length();
if (distance > lengthA + lengthB - 0.00001) {
console.warn(
"IK target exceeds fixed limb length. The limb was not stretched."
);
return null;
}
const direction = delta.normalize();
let along =
(lengthA * lengthA - lengthB * lengthB + distance * distance) /
(2 * distance);
along = THREE.MathUtils.clamp(
along,
-lengthA,
lengthA
);
const height = Math.sqrt(
Math.max(0, lengthA * lengthA - along * along)
);
const bend = bendHint
.clone()
.addScaledVector(direction, -bendHint.dot(direction));
if (bend.lengthSq() < 0.000001) {
bend.crossVectors(direction, Z_AXIS);
}
if (bend.lengthSq() < 0.000001) {
bend.crossVectors(direction, UP);
}
bend.normalize();
return root
.clone()
.addScaledVector(direction, along)
.addScaledVector(bend, height);
}
// Left arm: completely fixed.
const leftHandPosition = vec(-1.3, 1.15, 0.62);
const leftElbow = solveIK(
leftShoulder,
leftHandPosition,
0.65,
0.65,
vec(-1, -0.2, 0)
);
const leftUpperArm = makeSegment(0.18, 0.18, shirtMaterial);
const leftForearm = makeSegment(0.16, 0.16, shirtMaterial);
poseSegment(leftUpperArm, leftShoulder, leftElbow);
poseSegment(leftForearm, leftElbow, leftHandPosition);
makeBox(
figure,
[0.2, 0.2, 0.2],
leftShoulder.toArray(),
jointMaterial
);
makeBox(
figure,
[0.22, 0.22, 0.22],
leftElbow.toArray(),
jointMaterial
);
makeBox(
figure,
[0.26, 0.25, 0.28],
leftHandPosition.toArray(),
skinMaterial,
true
);
// Right arm: the only moving limb.
const rightStart = vec(-0.35, 1.18, 0.62);
const rightTarget = vec(0.78, 1.43, 0.62);
const rightWrist = rightStart.clone();
const rightUpperArm = makeSegment(0.18, 0.18, movingArmMaterial);
const rightForearm = makeSegment(0.16, 0.16, movingArmMaterial);
const rightShoulderJoint = makeBox(
figure,
[0.2, 0.2, 0.2],
rightShoulder.toArray(),
jointMaterial
);
const rightElbowJoint = makeBox(
figure,
[0.22, 0.22, 0.22],
rightShoulder.toArray(),
jointMaterial
);
const rightHand = makeBox(
figure,
[0.26, 0.25, 0.28],
rightStart.toArray(),
skinMaterial,
true
);
function updateRightArm(target) {
const elbow = solveIK(
rightShoulder,
target,
0.65,
0.65,
vec(1, -0.25, 0)
);
if (!elbow) return;
poseSegment(rightUpperArm, rightShoulder, elbow);
poseSegment(rightForearm, elbow, target);
rightElbowJoint.position.copy(elbow);
rightHand.position.copy(target);
}
updateRightArm(rightWrist);
// Legs: both feet remain fixed on their support holds.
const leftHip = vec(-0.18, -0.5, 0.55);
const rightHip = vec(0.18, -0.5, 0.55);
const leftFoot = vec(-1.0, -1.58, 0.5);
const rightFoot = vec(0.88, -1.78, 0.5);
const leftKnee = solveIK(
leftHip,
leftFoot,
0.75,
0.75,
vec(-1, 0, 0)
);
const rightKnee = solveIK(
rightHip,
rightFoot,
0.75,
0.75,
vec(1, 0, 0)
);
const leftThigh = makeSegment(0.23, 0.24, pantsMaterial);
const leftShin = makeSegment(0.2, 0.21, pantsMaterial);
const rightThigh = makeSegment(0.23, 0.24, pantsMaterial);
const rightShin = makeSegment(0.2, 0.21, pantsMaterial);
poseSegment(leftThigh, leftHip, leftKnee);
poseSegment(leftShin, leftKnee, leftFoot);
poseSegment(rightThigh, rightHip, rightKnee);
poseSegment(rightShin, rightKnee, rightFoot);
makeBox(figure, [0.23, 0.23, 0.23], leftKnee.toArray(), jointMaterial);
makeBox(figure, [0.23, 0.23, 0.23], rightKnee.toArray(), jointMaterial);
makeBox(
figure,
[0.34, 0.23, 0.4],
leftFoot.toArray(),
skinMaterial,
true
);
makeBox(
figure,
[0.34, 0.23, 0.4],
rightFoot.toArray(),
skinMaterial,
true
);
// -----------------------------------------------------------------------
// UI metrics
// -----------------------------------------------------------------------
const reachableDistance =
rightShoulder.distanceTo(rightTarget);
const unreachableDistance =
rightShoulder.distanceTo(vec(2.12, 1.85, 0));
document.getElementById("reachableDistance").textContent =
`${reachableDistance.toFixed(2)} m`;
document.getElementById("unreachableDistance").textContent =
`${unreachableDistance.toFixed(2)} m`;
document.getElementById("unreachableRatio").textContent =
`${Math.round((unreachableDistance / armReach) * 100)}% OF REACH — UNREACHABLE`;
// -----------------------------------------------------------------------
// Camera controls implemented without addons
// -----------------------------------------------------------------------
const cameraTarget = vec(0, 0.03, 0);
let azimuth = 0;
let elevation = 0.055;
let orbitDistance = 9.25;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const mobileScale = aspect < 1 ? 1.08 / aspect : 1;
const distance = orbitDistance * mobileScale;
camera.position.set(
Math.sin(azimuth) * Math.cos(elevation) * distance,
Math.sin(elevation) * distance + cameraTarget.y,
Math.cos(azimuth) * Math.cos(elevation) * distance
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth -= dx * 0.005;
elevation = THREE.MathUtils.clamp(
elevation + dy * 0.004,
-0.35,
0.48
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitDistance = THREE.MathUtils.clamp(
orbitDistance * Math.exp(event.deltaY * 0.001),
6.4,
14
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
updateCamera();
// -----------------------------------------------------------------------
// Animation
// -----------------------------------------------------------------------
const stateTextElement = document.getElementById("stateText");
const stateDotElement = document.getElementById("stateDot");
const progressElement = document.getElementById("progressFill");
let lastState = "";
const clock = new THREE.Clock();
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const phase = elapsed % 9.6;
let transfer = 0;
let state = "";
let stateColor = "#ffb454";
if (phase < 2.2) {
transfer = 0;
state = "HOLDING A";
stateColor = "#ffb454";
} else if (phase < 4.2) {
transfer = smoothstep((phase - 2.2) / 2);
state = "TRANSFER TO B";
stateColor = "#63e7ff";
} else if (phase < 6.6) {
transfer = 1;
state = "LOCKED ON B";
stateColor = "#63e7ff";
} else if (phase < 8.6) {
transfer = 1 - smoothstep((phase - 6.6) / 2);
state = "RETURNING TO A";
stateColor = "#ffb454";
} else {
transfer = 0;
state = "HOLDING A";
stateColor = "#ffb454";
}
rightWrist.lerpVectors(rightStart, rightTarget, transfer);
// A small outward arc makes the transfer readable while the two
// analytically solved arm segments remain exactly 0.65 m long.
rightWrist.y += Math.sin(transfer * Math.PI) * 0.08;
updateRightArm(rightWrist);
progressElement.style.transform = `scaleX(${transfer})`;
if (state !== lastState) {
stateTextElement.textContent = state;
stateDotElement.style.background = stateColor;
stateDotElement.style.color = stateColor;
lastState = state;
}
// Gentle indicators for the reachable and unreachable targets.
const targetPulse = 1 + Math.sin(elapsed * 4.2) * 0.055;
nextHoldMarker.scale.setScalar(targetPulse);
nextHoldMarker.material.opacity = 0.62 + Math.sin(elapsed * 4.2) * 0.2;
const errorPulse = 1 + Math.sin(elapsed * 3.4) * 0.08;
unreachableMarker.scale.setScalar(errorPulse);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```