Prompt specification
Build or customize the Three.js 3D scene "Hand Follows Shoulder and Elbow Rotations" 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: Hand Follows Shoulder and Elbow Rotations
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/hand-follows-shoulder-and-elbow-rotations-x3734
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring joint hierarchies and linked body rotations. Animate an original character raising an arm through parent and child rotations. Display the resulting hand path and distinguish local from world coordinates. A 3D cutaway view.
Working Three.js Starter (hand-follows-shoulder-and-elbow-rotations-x3734):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>IONA — Kinetic Anatomy / Three.js Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #071019;
--panel: rgba(9, 19, 30, 0.82);
--line: rgba(172, 216, 235, 0.17);
--text: #e8f2f5;
--muted: #8da5b3;
--world: #5ee7ff;
--local: #ffb45c;
--accent: #b89cff;
}
* { box-sizing: border-box; }
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
button,
select,
input {
font: inherit;
}
button,
select {
color: var(--text);
background: rgba(24, 40, 54, 0.88);
border: 1px solid var(--line);
border-radius: 8px;
}
button {
min-height: 34px;
padding: 7px 11px;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease;
}
button:hover {
background: rgba(44, 68, 85, 0.95);
border-color: rgba(94, 231, 255, 0.42);
}
select {
min-height: 34px;
padding: 6px 9px;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid var(--line);
background:
linear-gradient(145deg, rgba(25, 43, 58, 0.32), transparent 58%),
var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#identity {
top: 20px;
left: 20px;
width: min(365px, calc(100vw - 40px));
padding: 18px 18px 16px;
border-radius: 14px;
}
.eyebrow {
color: var(--world);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 6px 0 1px;
font-size: 30px;
line-height: 1;
letter-spacing: 0.11em;
font-weight: 760;
}
h1 span {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 600;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.description {
margin: 13px 0 15px;
color: #aec0ca;
font-size: 12px;
line-height: 1.55;
}
.hierarchy {
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
padding: 10px 0;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.65;
color: var(--muted);
}
.hierarchy .active { color: var(--text); }
.hierarchy .parent { color: var(--accent); }
.hierarchy .child { color: var(--local); }
.hierarchy .leaf { color: var(--world); }
.joint-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 13px;
}
.joint {
min-width: 0;
padding: 8px 7px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.025);
}
.joint small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.joint strong {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
font-weight: 650;
}
#coordinates {
top: 20px;
right: 20px;
width: 310px;
padding: 15px;
border-radius: 14px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: #b8cbd5;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.coordinate-row {
padding: 10px 0;
border-top: 1px solid var(--line);
}
.coordinate-row:first-of-type {
border-top: 0;
}
.coordinate-label {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 7px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
display: inline-block;
}
.dot.world {
background: var(--world);
box-shadow: 0 0 12px rgba(94, 231, 255, 0.8);
}
.dot.local {
background: var(--local);
box-shadow: 0 0 12px rgba(255, 180, 92, 0.75);
}
.coordinates-value {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
color: #f2f8fa;
white-space: nowrap;
}
.legend-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.options {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.options label {
display: flex;
align-items: center;
gap: 6px;
color: #b8cbd5;
font-size: 10px;
cursor: pointer;
}
.options input {
accent-color: var(--world);
}
#viewBadge {
position: absolute;
top: 21px;
left: 50%;
transform: translateX(-50%);
padding: 7px 12px;
border: 1px solid rgba(184, 156, 255, 0.32);
border-radius: 999px;
background: rgba(9, 19, 30, 0.68);
color: #d9ceff;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
#controls {
left: 50%;
bottom: 20px;
transform: translateX(-50%);
display: grid;
grid-template-columns: auto minmax(180px, 360px) auto auto auto;
align-items: center;
gap: 10px;
width: min(920px, calc(100vw - 40px));
padding: 11px;
border-radius: 13px;
}
#play {
min-width: 82px;
border-color: rgba(94, 231, 255, 0.32);
color: var(--world);
}
#timeline {
width: 100%;
accent-color: var(--world);
cursor: pointer;
}
#speed {
min-width: 74px;
}
#reset {
color: var(--muted);
}
.view-buttons {
position: absolute;
right: 20px;
bottom: 88px;
display: flex;
gap: 6px;
pointer-events: auto;
}
.view-buttons button {
background: rgba(9, 19, 30, 0.78);
font-size: 10px;
}
#hint {
position: absolute;
left: 21px;
bottom: 88px;
color: rgba(190, 209, 219, 0.55);
font-size: 10px;
letter-spacing: 0.04em;
}
@media (max-width: 820px) {
#identity {
width: 290px;
padding: 13px;
}
.description,
.hierarchy {
display: none;
}
#coordinates {
top: 16px;
right: 16px;
width: 245px;
padding: 12px;
}
#viewBadge {
display: none;
}
#controls {
grid-template-columns: auto 1fr auto;
width: calc(100vw - 24px);
bottom: 12px;
}
#reset,
.view-buttons,
#hint {
display: none;
}
}
@media (max-width: 560px) {
#identity {
top: 10px;
left: 10px;
width: 220px;
}
h1 { font-size: 23px; }
.joint-grid {
grid-template-columns: repeat(2, 1fr);
}
#coordinates {
top: 10px;
right: 10px;
width: calc(100vw - 250px);
min-width: 135px;
}
.coordinate-row { padding: 7px 0; }
.coordinates-value { font-size: 9px; }
.legend-note { display: none; }
.options { gap: 7px; }
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div id="ui">
<section class="panel" id="identity">
<div class="eyebrow">Original Character / Kinematic Study 07</div>
<h1>IONA <span>Kinetic anatomy</span></h1>
<p class="description">
A three-digit biomechanical observer with an exposed vertebral drive.
The arm is animated with forward kinematics: shoulder rotation carries
the elbow, elbow rotation carries the wrist, and wrist rotation carries
the tracked palm point.
</p>
<div class="hierarchy">
ROOT <span class="active">→ PELVIS → SPINE → CHEST</span><br />
<span class="parent">CHEST → SHOULDER</span> →
<span class="child">UPPER ARM → ELBOW</span> →
<span class="leaf">WRIST → HAND</span>
</div>
<div class="joint-grid">
<div class="joint">
<small>Chest</small>
<strong id="chestAngle">0°</strong>
</div>
<div class="joint">
<small>Shoulder</small>
<strong id="shoulderAngle">0°</strong>
</div>
<div class="joint">
<small>Elbow</small>
<strong id="elbowAngle">0°</strong>
</div>
<div class="joint">
<small>Wrist</small>
<strong id="wristAngle">0°</strong>
</div>
</div>
</section>
<section class="panel" id="coordinates">
<div class="panel-title">
<span>Tracked Palm Point</span>
<span>FK / LIVE</span>
</div>
<div class="coordinate-row">
<div class="coordinate-label">
<span class="dot world"></span>
WORLD COORDINATES
</div>
<div class="coordinates-value" id="worldCoords">X 0.000 Y 0.000 Z 0.000</div>
</div>
<div class="coordinate-row">
<div class="coordinate-label">
<span class="dot local"></span>
CHEST-LOCAL COORDINATES
</div>
<div class="coordinates-value" id="localCoords">X 0.000 Y 0.000 Z 0.000</div>
</div>
<p class="legend-note">
Solid cyan is the world-space path. Dashed amber is the same sampled
motion expressed in the chest frame and re-anchored to the current chest.
</p>
<div class="options">
<label><input id="showWorld" type="checkbox" checked /> World path</label>
<label><input id="showLocal" type="checkbox" checked /> Local path</label>
<label><input id="showFrames" type="checkbox" checked /> Frames</label>
<button id="cutaway" type="button">Cutaway ON</button>
</div>
</section>
<div id="viewBadge">3D Cutaway / Linked Rotations</div>
<div class="view-buttons">
<button data-view="three-quarter">3/4 View</button>
<button data-view="front">Front</button>
<button data-view="section">Section</button>
</div>
<div id="hint">
Drag to orbit · Right-drag to pan · Scroll to zoom · Double-click to reset
</div>
<section class="panel" id="controls">
<button id="play" type="button">Ⅱ Pause</button>
<input id="timeline" type="range" min="0" max="1000" value="0" />
<select id="speed" aria-label="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="1.5">1.5×</option>
<option value="2">2×</option>
</select>
<button id="reset" type="button">Restart</button>
<button data-view="reset" type="button">Reset view</button>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.Fog(0x071019, 10, 24);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.08,
60
);
const cameraState = {
target: new THREE.Vector3(0, 1.65, 0),
spherical: new THREE.Spherical(),
mode: "orbit",
lastX: 0,
lastY: 0,
pinchDistance: 0
};
function syncCamera() {
cameraState.spherical.phi = THREE.MathUtils.clamp(
cameraState.spherical.phi,
0.16,
Math.PI - 0.16
);
cameraState.spherical.radius = THREE.MathUtils.clamp(
cameraState.spherical.radius,
3.1,
15
);
const offset = new THREE.Vector3().setFromSpherical(
cameraState.spherical
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
function setCameraView(name) {
const views = {
"three-quarter": {
target: new THREE.Vector3(0, 1.68, 0),
position: new THREE.Vector3(4.9, 3.25, 6.5)
},
front: {
target: new THREE.Vector3(0, 1.72, 0),
position: new THREE.Vector3(0.15, 2.7, 7.7)
},
section: {
target: new THREE.Vector3(0.1, 1.85, 0),
position: new THREE.Vector3(4.2, 2.7, 4.2)
},
reset: {
target: new THREE.Vector3(0, 1.68, 0),
position: new THREE.Vector3(4.9, 3.25, 6.5)
}
};
const view = views[name] || views["three-quarter"];
cameraState.target.copy(view.target);
camera.position.copy(view.position);
cameraState.spherical.setFromVector3(
camera.position.clone().sub(cameraState.target)
);
syncCamera();
}
setCameraView("three-quarter");
scene.add(new THREE.HemisphereLight(0x9fc9e8, 0x15101e, 2.0));
const keyLight = new THREE.DirectionalLight(0xd8efff, 3.4);
keyLight.position.set(4. , 7, 5);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb58cff, 2.8);
rimLight.position.set(-5, 4, -4);
scene.add(rimLight);
const coreLight = new THREE.PointLight(0x5ee7ff, 4.0, 4.5, 2);
coreLight.position.set(0.12, 2.3, 0.15);
scene.add(coreLight);
// -------------------------------------------------------------------------
// Materials and reusable helpers
// -------------------------------------------------------------------------
const materials = {
shell: new THREE.MeshPhysicalMaterial({
color: 0x756a9b,
metalness: 0.35,
roughness: 0.3,
transparent: true,
opacity: 0.48,
transmission: 0.12,
side: THREE.DoubleSide,
depthWrite: false
}),
fullShell: new THREE.MeshPhysicalMaterial({
color: 0x6c648c,
metalness: 0.42,
roughness: 0.34,
transparent: true,
opacity: 0.82,
side: THREE.DoubleSide
}),
bone: new THREE.MeshStandardMaterial({
color: 0xe3dccb,
metalness: 0.08,
roughness: 0.5
}),
joint: new THREE.MeshStandardMaterial({
color: 0xdca85d,
metalness: 0.62,
roughness: 0.3
}),
dark: new THREE.MeshStandardMaterial({
color: 0x101722,
metalness: 0.52,
roughness: 0.44
}),
core: new THREE.MeshStandardMaterial({
color: 0x80efff,
emissive: 0x16b9e8,
emissiveIntensity: 2.2,
metalness: 0.12,
roughness: 0.2
}),
organ: new THREE.MeshPhysicalMaterial({
color: 0xb779a4,
transparent: true,
opacity: 0.34,
roughness: 0.55,
depthWrite: false
}),
visor: new THREE.MeshStandardMaterial({
color: 0x071722,
emissive: 0x0c5266,
emissiveIntensity: 0.85,
metalness: 0.65,
roughness: 0.2
}),
accent: new THREE.MeshStandardMaterial({
color: 0xb89cff,
emissive: 0x38286a,
emissiveIntensity: 0.7,
metalness: 0.42,
roughness: 0.35
})
};
function addMesh(geometry, material, parent, position, scale) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
if (scale) mesh.scale.copy(scale);
parent.add(mesh);
return mesh;
}
function addBone(parent, length, radius, material = materials.bone) {
const mesh = addMesh(
new THREE.CylinderGeometry(radius * 0.86, radius, length, 20),
material,
parent,
new THREE.Vector3(0, -length / 2, 0)
);
mesh.castShadow = true;
return mesh;
}
function addJoint(parent, radius, material = materials.joint) {
const mesh = addMesh(
new THREE.SphereGeometry(radius, 24, 16),
material,
parent
);
mesh.castShadow = true;
return mesh;
}
function makeTextSprite(text, color = "#dceff5") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 96;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, labelCanvas.width, labelCanvas.height);
ctx.fillStyle = "rgba(5, 14, 22, 0.84)";
ctx.fillRect(5, 8, 502, 80);
ctx.strokeStyle = color;
ctx.globalAlpha = 0.7;
ctx.lineWidth = 3;
ctx.strokeRect(5, 8, 502, 80);
ctx.globalAlpha = 1;
ctx.fillStyle = color;
ctx.font = "700 31px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.78, 0.146, 1);
sprite.renderOrder = 30;
return sprite;
}
function makeCoordinateFrame(color, dashed = false) {
const group = new THREE.Group();
const length = 0.27;
const points = [
new THREE.Vector3(-length, 0, 0),
new THREE.Vector3(length, 0, 0),
new THREE.Vector3(0, -length, 0),
new THREE.Vector3(0, length, 0),
new THREE.Vector3(0, 0, -length),
new THREE.Vector3(0, 0, length)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = dashed
? new THREE.LineDashedMaterial({
color,
dashSize: 0.045,
gapSize: 0.025,
transparent: true,
opacity: 0.95,
depthTest: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
});
const axes = new THREE.LineSegments(geometry, material);
axes.computeLineDistances();
axes.renderOrder = 25;
group.add(axes);
const origin = addMesh(
new THREE.SphereGeometry(0.018, 12, 8),
new THREE.MeshBasicMaterial({ color, depthTest: false }),
group
);
origin.renderOrder = 25;
return group;
}
// -------------------------------------------------------------------------
// IONA: character hierarchy
//
// root
// └─ pelvis
// └─ spine
// └─ chest
// ├─ head
// └─ shoulder
// └─ elbow
// └─ wrist
// └─ hand / tracked point
// -------------------------------------------------------------------------
const root = new THREE.Group();
root.name = "IONA_ROOT";
root.position.y = 1.22;
scene.add(root);
const pelvis = new THREE.Group();
pelvis.name = "PELVIS";
root.add(pelvis);
const spine = new THREE.Group();
spine.name = "SPINE";
spine.position.y = 0.12;
pelvis.add(spine);
const chest = new THREE.Group();
chest.name = "CHEST";
chest.position.y = 0.52;
spine.add(chest);
const head = new THREE.Group();
head.name = "HEAD";
head.position.set(0, 1.34, 0);
chest.add(head);
// Pelvic shell and waist.
const pelvisShell = addMesh(
new THREE.CylinderGeometry(
0.42, 0.38, 0.34, 56, 1, false,
Math.PI / 2, Math.PI * 1.5
),
materials.shell,
pelvis,
new THREE.Vector3(0, -0.03, 0)
);
const pelvisBand = addMesh(
new THREE.TorusGeometry(0.37, 0.035, 10, 48),
materials.joint,
pelvis,
new THREE.Vector3(0, 0.12, 0)
);
pelvisBand.rotation.x = Math.PI / 2;
// Main torso shell in full and cutaway forms.
const torsoHeight = 1.16;
const torsoY = 0.43;
const torsoTopRadius = 0.51;
const torsoBottomRadius = 0.38;
const cutShell = addMesh(
new THREE.CylinderGeometry(
torsoTopRadius,
torsoBottomRadius,
torsoHeight,
64,
1,
false,
Math.PI / 2,
Math.PI * 1.5
),
materials.shell,
chest,
new THREE.Vector3(0, torsoY, 0)
);
cutShell.name = "CUTAWAY_TORSO";
const fullShell = addMesh(
new THREE.CylinderGeometry(
torsoTopRadius,
torsoBottomRadius,
torsoHeight,
64
),
materials.fullShell,
chest,
new THREE.Vector3(0, torsoY, 0)
);
fullShell.visible = false;
// Highlight the two cut edges of the shell.
const cutEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xd2c4ff,
transparent: true,
opacity: 0.85
});
function shellRadiusAt(y) {
const t = THREE.MathUtils.clamp(
(y + torsoHeight / 2) / torsoHeight,
0,
1
);
return THREE.MathUtils.lerp(
torsoBottomRadius,
torsoTopRadius,
t
);
}
[Math.PI / 2, Math.PI * 2].forEach((theta) => {
const bottomRadius = shellRadiusAt(-torsoHeight / 2);
const topRadius = shellRadiusAt(torsoHeight / 2);
const edgeGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
Math.sin(theta) * bottomRadius,
torsoY - torsoHeight / 2,
Math.cos(theta) * bottomRadius
),
new THREE.Vector3(
Math.sin(theta) * topRadius,
torsoY + torsoHeight / 2,
Math.cos(theta) * topRadius
)
]);
chest.add(new THREE.Line(edgeGeometry, cutEdgeMaterial));
});
// Cut-edge rim arcs.
[-torsoHeight / 2, torsoHeight / 2].forEach((localY) => {
const radius = shellRadiusAt(localY);
const points = [];
for (let i = 0; i <= 64; i++) {
const theta = Math.PI / 2 + (i / 64) * Math.PI * 1.5;
points.push(
new THREE.Vector3(
Math.sin(theta) * radius,
torsoY + localY,
Math.cos(theta) * radius
)
);
}
chest.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
cutEdgeMaterial
)
);
});
// Internal rib cage.
const internalGroup = new THREE.Group();
internalGroup.name = "INTERNAL_ANATOMY";
chest.add(internalGroup);
const ribMaterial = new THREE.MeshStandardMaterial({
color: 0xc8b4ef,
emissive: 0x32275d,
emissiveIntensity: 0.65,
metalness: 0.38,
roughness: 0.42
});
[0.04, 0.26, 0.48, 0.70, 0.91].forEach((y, index) => {
const radius = 0.43 - index * 0.012;
const rib = addMesh(
new THREE.TorusGeometry(radius, 0.018, 7, 56),
ribMaterial,
internalGroup,
new THREE.Vector3(0, y, 0)
);
rib.rotation.x = Math.PI / 2;
rib.scale.y = 0.78;
});
// Vertebral column.
for (let i = 0; i < 9; i++) {
const vertebra = addMesh(
new THREE.CylinderGeometry(
0.095 - i * 0.003,
0.105 - i * 0.003,
0.075,
16
),
materials.bone,
internalGroup,
new THREE.Vector3(0, -0.03 + i * 0.115, -0.08)
);
vertebra.rotation.x = 0.12;
}
// Lungs.
[-0.17, 0.17].forEach((x) => {
addMesh(
new THREE.SphereGeometry(0.22, 24, 18),
materials.organ,
internalGroup,
new THREE.Vector3(x, 0.49, -0.02),
new THREE.Vector3(0.78, 1.48, 0.68)
);
});
// Central kinetic core.
const core = addMesh(
new THREE.IcosahedronGeometry(0.14, 2),
materials.core,
internalGroup,
new THREE.Vector3(0.02, 0.45, 0.06)
);
const coreRing = addMesh(
new THREE.TorusGeometry(0.20, 0.018, 8, 48),
materials.accent,
internalGroup,
new THREE.Vector3(0.02, 0.45, 0.06)
);
coreRing.rotation.x = Math.PI / 2;
// Neck and head.
addBone(chest, 0.18, 0.11, materials.dark);
const headShell = addMesh(
new THREE.SphereGeometry(0.39, 40, 28),
materials.shell,
head,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0.9, 1.08, 0.91)
);
headShell.material = materials.shell;
const visor = addMesh(
new THREE.SphereGeometry(0.355, 36, 20),
materials.visor,
head,
new THREE.Vector3(0, 0.045, 0.12),
new THREE.Vector3(0.87, 0.31, 0.33)
);
for (let i = -1; i <= 1; i++) {
const eye = addMesh(
new THREE.SphereGeometry(0.025, 12, 8),
materials.core,
head,
new THREE.Vector3(i * 0.11, 0.055, 0.345)
);
eye.scale.z = 0.35;
}
// Asymmetric dorsal identity fin.
const finGeometry = new THREE.BufferGeometry();
finGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.26, 0.12, -0.06,
0.51, 0.32, -0.06,
0.28, 0.38, -0.06
],
3
)
);
finGeometry.computeVertexNormals();
const fin = new THREE.Mesh(finGeometry, materials.accent);
head.add(fin);
// Legs with linked hip/knee hierarchy.
function buildLeg(side) {
const hip = new THREE.Group();
hip.position.set(side * 0.24, -0.08, 0);
pelvis.add(hip);
addJoint(hip, 0.14);
addBone(hip, 0.57, 0.12);
const knee = new THREE.Group();
knee.position.y = -0.57;
hip.add(knee);
addJoint(knee, 0.115);
addBone(knee, 0.54, 0.10);
const ankle = new THREE.Group();
ankle.position.y = -0.54;
knee.add(ankle);
addJoint(ankle, 0.085, materials.dark);
const foot = addMesh(
new THREE.BoxGeometry(0.27, 0.12, 0.45),
materials.dark,
ankle,
new THREE.Vector3(0, -0.055, 0.11)
);
foot.rotation.x = -0.08;
}
buildLeg(-1);
buildLeg(1);
// Arms.
function buildArm(side) {
const shoulder = new THREE.Group();
shoulder.name = side > 0 ? "RIGHT_SHOULDER" : "LEFT_SHOULDER";
shoulder.position.set(side * 0.73, 0.91, 0);
chest.add(shoulder);
const shoulderArmor = addMesh(
new THREE.SphereGeometry(0.225, 28, 20),
materials.shell,
chest,
new THREE.Vector3(side * 0.73, 0.91, 0)
);
shoulderArmor.scale.set(1.05, 0.9, 0.92);
addJoint(shoulder, 0.13);
addBone(shoulder, 0.72, 0.105);
const elbow = new THREE.Group();
elbow.name = "ELBOW";
elbow.position.y = -0.72;
shoulder.add(elbow);
addJoint(elbow, 0.115);
addBone(elbow, 0.62, 0.088);
const wrist = new THREE.Group();
wrist.name = "WRIST";
wrist.position.y = -0.62;
elbow.add(wrist);
addJoint(wrist, 0.085);
const hand = new THREE.Group();
hand.name = "HAND";
hand.position.y = -0.035;
wrist.add(hand);
const palm = addMesh(
new THREE.BoxGeometry(0.25, 0.23, 0.12),
materials.bone,
hand,
new THREE.Vector3(0, -0.13, 0)
);
palm.rotation.z = side * 0.035;
// Three digits give the character a distinct silhouette.
[-0.075, 0, 0.075].forEach((x, index) => {
const digit = addMesh(
new THREE.CylinderGeometry(0.024, 0.021, 0.22, 12),
materials.dark,
hand,
new THREE.Vector3(x, -0.315, 0)
);
digit.rotation.z = (index - 1) * 0.08;
});
const trackedPoint = new THREE.Object3D();
trackedPoint.name = "TRACKED_PALM_POINT";
trackedPoint.position.set(0, -0.16, 0.01);
hand.add(trackedPoint);
return { shoulder, elbow, wrist, hand, trackedPoint };
}
const animatedArm = buildArm(1);
const staticArm = buildArm(-1);
staticArm.shoulder.rotation.z = -0.08;
staticArm.elbow.rotation.z = 0.07;
staticArm.wrist.rotation.z = -0.04;
// Ground plane and grid.
const ground = addMesh(
new THREE.CircleGeometry(3.2, 80),
new THREE.MeshStandardMaterial({
color: 0x08131d,
roughness: 0.92,
metalness: 0.05
}),
scene,
new THREE.Vector3(0, -0.015, 0)
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
const grid = new THREE.GridHelper(12, 24, 0x274253, 0x142b38);
grid.position.y = -0.005;
grid.material.transparent = true;
grid.material.opacity = 0.45;
scene.add(grid);
const shadow = addMesh(
new THREE.CircleGeometry(1.05, 64),
new THREE.MeshBasicMaterial({
color: 0x000000,
transparent: true,
opacity: 0.28,
depthWrite: false
}),
scene,
new THREE.Vector3(0, 0.002, 0)
);
shadow.rotation.x = -Math.PI / 2;
shadow.scale.set(1.35, 0.72, 1);
// -------------------------------------------------------------------------
// Forward-kinematic animation
// -------------------------------------------------------------------------
let progress = 0;
let playing = true;
let playbackSpeed = 1;
const cycleDuration = 7.2; // seconds
function smooth01(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function applyPose(time) {
// Raise for the first 68%, hold briefly, then lower.
const amount =
time <= 0.68
? smooth01(time / 0.68)
: 1 - smooth01((time - 0.68) / 0.32);
// Parent chest twist.
chest.rotation.y = -0.18 * amount;
chest.rotation.z = 0.025 * Math.sin(amount * Math.PI);
chest.rotation.x = -0.018 * amount;
// Slight pelvis/spine counter-motion.
spine.rotation.z = -0.045 * amount;
root.rotation.y = 0.035 * Math.sin(amount * Math.PI);
// Shoulder is the parent of the entire arm chain.
animatedArm.shoulder.rotation.set(
0.035 * amount,
-0.12 * amount,
THREE.MathUtils.lerp(0.08, 1.62, amount)
);
// Elbow is a child of the shoulder and therefore inherits its rotation.
animatedArm.elbow.rotation.set(
-0.06 * amount,
0.09 * amount,
THREE.MathUtils.lerp(0.08, 1.18, amount)
);
// Wrist is a child of the elbow and carries the hand.
animatedArm.wrist.rotation.set(
0.04 * amount,
0.035 * amount,
THREE.MathUtils.lerp(0, -0.22, amount)
);
return amount;
}
// -------------------------------------------------------------------------
// Trajectory sampling in two coordinate spaces
// -------------------------------------------------------------------------
const PATH_SAMPLES = 190;
const worldSamples = [];
const chestLocalSamples = [];
for (let i = 0; i < PATH_SAMPLES; i++) {
const t = i / (PATH_SAMPLES - 1);
applyPose(t);
scene.updateMatrixWorld(true);
const worldPoint = animatedArm.trackedPoint.getWorldPosition(
new THREE.Vector3()
);
const chestLocalPoint = chest.worldToLocal(worldPoint.clone());
worldSamples.push(worldPoint);
chestLocalSamples.push(chestLocalPoint);
}
const worldPathMaterial = new THREE.LineBasicMaterial({
color: 0x5ee7ff,
transparent: true,
opacity: 0.92,
depthTest: false
});
const localPathMaterial = new THREE.LineDashedMaterial({
color: 0xffb45c,
dashSize: 0.055,
gapSize: 0.035,
transparent: true,
opacity: 0.92,
depthTest: false
});
const worldPath = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(worldSamples),
worldPathMaterial
);
worldPath.name = "WORLD_HAND_PATH";
worldPath.renderOrder = 20;
scene.add(worldPath);
const localPath = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(worldSamples),
localPathMaterial
);
localPath.name = "CHEST_LOCAL_HAND_PATH";
localPath.renderOrder = 21;
scene.add(localPath);
function updateLocalPath() {
const position = localPath.geometry.attributes.position;
const point = new THREE.Vector3();
for (let i = 0; i < chestLocalSamples.length; i++) {
point.copy(chestLocalSamples[i]);
chest.localToWorld(point);
position.setXYZ(i, point.x, point.y, point.z);
}
position.needsUpdate = true;
localPath.geometry.computeBoundingSphere();
localPath.computeLineDistances();
}
// Coordinate frames at the current tracked point.
const worldFrame = makeCoordinateFrame(0x5ee7ff, false);
worldFrame.name = "WORLD_FRAME";
scene.add(worldFrame);
const worldFrameLabel = makeTextSprite("WORLD", "#5ee7ff");
worldFrameLabel.position.set(0, 0.39, 0);
worldFrame.add(worldFrameLabel);
const localFrame = makeCoordinateFrame(0xffb45c, true);
localFrame.name = "CHEST_LOCAL_FRAME";
chest.add(localFrame);
const localFrameLabel = makeTextSprite("CHEST-LOCAL", "#ffb45c");
localFrameLabel.position.set(0, 0.39, 0);
localFrame.add(localFrameLabel);
const worldMarker = addMesh(
new THREE.SphereGeometry(0.035, 18, 12),
new THREE.MeshBasicMaterial({
color: 0x5ee7ff,
depthTest: false
}),
scene
);
worldMarker.renderOrder = 26;
const localMarker = addMesh(
new THREE.SphereGeometry(0.03, 18, 12),
new THREE.MeshBasicMaterial({
color: 0xffb45c,
depthTest: false
}),
scene
);
localMarker.renderOrder = 27;
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, zoom, and basic touch pinch
// -------------------------------------------------------------------------
const pointers = new Map();
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraState.mode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
} else if (pointers.size === 2) {
cameraState.mode = "pinch";
const values = [...pointers.values()];
cameraState.pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const pointer = pointers.get(event.pointerId);
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 1 && cameraState.mode === "orbit") {
cameraState.spherical.theta -= dx * 0.006;
cameraState.spherical.phi -= dy * 0.006;
syncCamera();
} else if (pointers.size === 1 && cameraState.mode === "pan") {
panCamera(dx, dy);
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (cameraState.pinchDistance > 0) {
cameraState.spherical.radius *=
cameraState.pinchDistance / Math.max(distance, 1);
syncCamera();
}
cameraState.pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) cameraState.mode = "orbit";
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
function panCamera(dx, dy) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = cameraState.spherical.radius * 0.00135;
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
syncCamera();
}
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.spherical.radius *= Math.exp(event.deltaY * 0.001);
syncCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
setCameraView("three-quarter");
});
// -------------------------------------------------------------------------
// UI wiring
// -------------------------------------------------------------------------
const ui = {
play: document.querySelector("#play"),
timeline: document.querySelector("#timeline"),
speed: document.querySelector("#speed"),
reset: document.querySelector("#reset"),
cutaway: document.querySelector("#cutaway"),
showWorld: document.querySelector("#showWorld"),
showLocal: document.querySelector("#showLocal"),
showFrames: document.querySelector("#showFrames"),
worldCoords: document.querySelector("#worldCoords"),
localCoords: document.querySelector("#localCoords"),
chestAngle: document.querySelector("#chestAngle"),
shoulderAngle: document.querySelector("#shoulderAngle"),
elbowAngle: document.querySelector("#elbowAngle"),
wristAngle: document.querySelector("#wristAngle")
};
function updatePlayButton() {
ui.play.textContent = playing ? "Ⅱ Pause" : "▶ Play";
}
ui.play.addEventListener("click", () => {
if (progress >= 0.999 && !playing) progress = 0;
playing = !playing;
updatePlayButton();
});
ui.timeline.addEventListener("input", () => {
progress = Number(ui.timeline.value) / 1000;
playing = false;
updatePlayButton();
});
ui.speed.addEventListener("change", () => {
playbackSpeed = Number(ui.speed.value);
});
ui.reset.addEventListener("click", () => {
progress = 0;
playing = true;
ui.timeline.value = "0";
updatePlayButton();
});
ui.cutaway.addEventListener("click", () => {
const isCutaway = !cutShell.visible;
cutShell.visible = isCutaway;
fullShell.visible = !isCutaway;
ui.cutaway.textContent = isCutaway ? "Cutaway ON" : "Cutaway OFF";
});
ui.showWorld.addEventListener("change", () => {
worldPath.visible = ui.showWorld.checked;
});
ui.showLocal.addEventListener("change", () => {
localPath.visible = ui.showLocal.checked;
});
ui.showFrames.addEventListener("change", () => {
worldFrame.visible = ui.showFrames.checked;
localFrame.visible = ui.showFrames.checked;
worldMarker.visible = ui.showFrames.checked;
localMarker.visible = ui.showFrames.checked;
});
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setCameraView(button.dataset.view);
});
});
// -------------------------------------------------------------------------
// Live coordinate display and render loop
// -------------------------------------------------------------------------
const worldPoint = new THREE.Vector3();
const localPoint = new THREE.Vector3();
const localPointWorld = new THREE.Vector3();
const clock = new THREE.Clock();
function degrees(radians) {
const value = THREE.MathUtils.radToDeg(radians);
return `${value >= 0 ? "+" : ""}${value.toFixed(0)}°`;
}
function updateLiveData() {
scene.updateMatrixWorld(true);
animatedArm.trackedPoint.getWorldPosition(worldPoint);
localPoint.copy(worldPoint);
chest.worldToLocal(localPoint);
worldFrame.position.copy(worldPoint);
worldMarker.position.copy(worldPoint);
localFrame.position.copy(localPoint);
localPointWorld.copy(localPoint);
chest.localToWorld(localPointWorld);
localMarker.position.copy(localPointWorld);
updateLocalPath();
ui.worldCoords.textContent =
`X ${worldPoint.x.toFixed(3)} ` +
`Y ${worldPoint.y.toFixed(3)} ` +
`Z ${worldPoint.z.toFixed(3)}`;
ui.localCoords.textContent =
`X ${localPoint.x.toFixed(3)} ` +
`Y ${localPoint.y.toFixed(3)} ` +
`Z ${localPoint.z.toFixed(3)}`;
ui.chestAngle.textContent = degrees(chest.rotation.y);
ui.shoulderAngle.textContent = degrees(animatedArm.shoulder.rotation.z);
ui.elbowAngle.textContent = degrees(animatedArm.elbow.rotation.z);
ui.wristAngle.textContent = degrees(animatedArm.wrist.rotation.z);
}
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
progress = (progress + delta * playbackSpeed / cycleDuration) % 1;
ui.timeline.value = String(Math.round(progress * 1000));
}
const amount = applyPose(progress);
// Decorative core pulse; it does not alter the measured trajectory.
const pulse = 1 + Math.sin(clock.elapsedTime * 3.2) * 0.055;
core.scale.setScalar(pulse);
core.rotation.y += delta * 0.32;
coreLight.intensity = 3.6 + Math.sin(clock.elapsedTime * 3.2) * 0.45;
updateLiveData();
renderer.render(scene, camera);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```