Prompt specification
Build or customize the Three.js 3D scene "Animated character prop assembly scene" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Animated character prop assembly scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/animated-character-prop-assembly-scene-x1747
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing geometric transformations and their order. Compose a simple character holding a tool through a parent-child hierarchy; demonstrate local rotations while keeping the grip point attached to the hand. Voxel style.
Working Three.js Starter (animated-character-prop-assembly-scene-x1747):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Transformation Hierarchy</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(9, 20, 35, 0.84);
--border: rgba(137, 196, 255, 0.19);
--text: #eaf4ff;
--muted: #8da5be;
--cyan: #55ddff;
--teal: #43d7bd;
--orange: #ffad45;
--red: #ff6b61;
}
* {
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;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
header {
position: fixed;
z-index: 20;
top: 22px;
left: 24px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.2vw, 31px);
line-height: 1.05;
letter-spacing: -0.04em;
}
header p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
}
.panel {
position: fixed;
z-index: 20;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.panel-title {
margin: 0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.panel-number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(85, 221, 255, 0.35);
border-radius: 7px;
color: var(--cyan);
background: rgba(85, 221, 255, 0.08);
font: 700 10px ui-monospace, monospace;
}
#rig-panel {
top: 124px;
left: 24px;
width: 306px;
padding: 18px;
}
.intro {
margin: 0 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.control {
margin-top: 16px;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 12px;
}
.control-row label {
font-weight: 700;
}
.control-row output {
min-width: 48px;
padding: 4px 7px;
border: 1px solid rgba(85, 221, 255, 0.2);
border-radius: 6px;
color: var(--cyan);
background: rgba(85, 221, 255, 0.07);
text-align: center;
font: 700 11px ui-monospace, monospace;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 10px;
background: linear-gradient(
90deg,
rgba(85, 221, 255, 0.72),
rgba(85, 221, 255, 0.16)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #0c1d30;
border-radius: 4px;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(85, 221, 255, 0.55);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #0c1d30;
border-radius: 4px;
background: var(--cyan);
}
.local-note {
display: flex;
align-items: center;
gap: 8px;
margin-top: 15px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.local-note::before {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 2px;
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 173, 69, 0.7);
content: "";
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 17px;
}
button {
border: 1px solid rgba(133, 180, 225, 0.22);
border-radius: 9px;
padding: 9px 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.045);
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(85, 221, 255, 0.48);
background: rgba(85, 221, 255, 0.08);
}
button:active {
transform: translateY(1px);
}
.primary {
border-color: rgba(67, 215, 189, 0.4);
color: #baffef;
background: rgba(67, 215, 189, 0.09);
}
#order-panel {
top: 24px;
right: 24px;
width: 346px;
padding: 18px;
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 4px;
border: 1px solid rgba(133, 180, 225, 0.13);
border-radius: 11px;
background: rgba(0, 0, 0, 0.16);
}
.segmented button {
border: 0;
background: transparent;
padding: 8px 7px;
color: var(--muted);
}
.segmented button.active {
color: #07111f;
background: var(--cyan);
}
.sequence {
display: grid;
grid-template-columns: 1fr 22px 1fr;
align-items: center;
gap: 7px;
margin-top: 14px;
}
.step {
min-height: 82px;
padding: 11px;
border: 1px solid rgba(133, 180, 225, 0.16);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
transition: 180ms ease;
}
.step.active {
border-color: rgba(255, 173, 69, 0.65);
background: rgba(255, 173, 69, 0.11);
box-shadow: inset 0 0 22px rgba(255, 173, 69, 0.05);
}
.step.done {
border-color: rgba(67, 215, 189, 0.35);
}
.step-index {
color: var(--muted);
font: 700 9px ui-monospace, monospace;
letter-spacing: 0.12em;
}
.step strong {
display: block;
margin-top: 8px;
font-size: 12px;
}
.step small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.sequence-arrow {
color: var(--orange);
text-align: center;
font-size: 18px;
}
.matrix-section {
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid rgba(133, 180, 225, 0.12);
}
.formula {
color: var(--cyan);
font: 700 15px ui-monospace, monospace;
letter-spacing: 0.04em;
}
.formula-note {
margin: 6px 0 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.matrix-wrap {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.matrix-label {
margin-bottom: 6px;
color: var(--muted);
font: 700 9px ui-monospace, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.matrix-grid {
display: grid;
width: 146px;
grid-template-columns: repeat(4, 1fr);
gap: 2px;
}
.matrix-grid span {
display: grid;
min-height: 23px;
place-items: center;
border: 1px solid rgba(85, 221, 255, 0.11);
border-radius: 4px;
color: #c8f6ff;
background: rgba(85, 221, 255, 0.045);
font: 10px ui-monospace, monospace;
}
.result {
max-width: 120px;
color: var(--muted);
font: 10px/1.65 ui-monospace, monospace;
}
.result strong {
display: block;
margin-bottom: 4px;
color: var(--teal);
}
#hierarchy-panel {
bottom: 24px;
left: 24px;
width: 330px;
padding: 16px 18px;
}
.tree {
margin: 0;
padding: 0;
list-style: none;
color: #c7d7e8;
font: 11px/1.7 ui-monospace, monospace;
}
.tree ul {
margin: 0;
padding-left: 16px;
border-left: 1px solid rgba(85, 221, 255, 0.18);
list-style: none;
}
.tree li {
position: relative;
}
.tree ul > li::before {
position: absolute;
top: 12px;
left: -16px;
width: 12px;
border-top: 1px solid rgba(85, 221, 255, 0.18);
content: "";
}
.tree .name {
color: #e7f4ff;
font-weight: 700;
}
.tree .local {
margin-left: 5px;
color: var(--orange);
font-size: 9px;
}
.tree .grip {
color: var(--orange);
}
.tree .tool {
color: #ffd16d;
}
.matrix-chain {
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-top: 12px;
}
.matrix-chip {
padding: 4px 6px;
border: 1px solid rgba(85, 221, 255, 0.14);
border-radius: 5px;
color: #9ec8df;
background: rgba(85, 221, 255, 0.04);
font: 9px ui-monospace, monospace;
}
.hand-matrix {
margin: 10px 0 0;
color: #a8c9dd;
font: 9px/1.45 ui-monospace, monospace;
white-space: pre;
}
.check-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.check-row input {
accent-color: var(--cyan);
}
.scene-label {
position: fixed;
z-index: 8;
padding: 5px 8px;
border: 1px solid rgba(85, 221, 255, 0.25);
border-radius: 5px;
color: #bdefff;
background: rgba(4, 14, 27, 0.72);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
font: 700 9px ui-monospace, monospace;
letter-spacing: 0.05em;
pointer-events: none;
transform: translate(12px, -50%);
transition: opacity 120ms linear;
white-space: nowrap;
}
.scene-label.orange {
border-color: rgba(255, 173, 69, 0.4);
color: #ffd09a;
}
.scene-label.yellow {
border-color: rgba(255, 209, 109, 0.4);
color: #ffe3a2;
}
#hint {
position: fixed;
z-index: 20;
right: 24px;
bottom: 24px;
padding: 10px 13px;
border: 1px solid rgba(133, 180, 225, 0.16);
border-radius: 9px;
color: var(--muted);
background: rgba(9, 20, 35, 0.68);
font-size: 10px;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: var(--cyan);
background: var(--bg);
font: 700 12px ui-monospace, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
@media (max-width: 1050px) {
#rig-panel {
width: 280px;
}
#order-panel {
width: 316px;
}
#hierarchy-panel {
width: 300px;
}
}
@media (max-width: 780px) {
header {
top: 14px;
left: 14px;
}
header p,
#hierarchy-panel,
#hint {
display: none;
}
#rig-panel {
top: auto;
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
max-height: 42vh;
overflow: auto;
}
#order-panel {
top: 84px;
right: 12px;
width: 285px;
max-height: 46vh;
overflow: auto;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header>
<div class="eyebrow">Three.js / Transform Study 01</div>
<h1>Voxel Transformation Hierarchy</h1>
<p>Local rotations compose through parent-child transforms.</p>
</header>
<section class="panel" id="rig-panel">
<div class="panel-header">
<h2 class="panel-title">Character Rig</h2>
<div class="panel-number">01</div>
</div>
<p class="intro">
Each slider rotates a joint around its own local Z axis. The hand,
grip marker, and tool inherit the complete parent transform chain.
</p>
<div class="control">
<div class="control-row">
<label for="shoulder">Shoulder · local Z</label>
<output id="shoulder-value">-35°</output>
</div>
<input id="shoulder" type="range" min="-90" max="45" value="-35" />
</div>
<div class="control">
<div class="control-row">
<label for="elbow">Elbow · local Z</label>
<output id="elbow-value">105°</output>
</div>
<input id="elbow" type="range" min="0" max="150" value="105" />
</div>
<div class="control">
<div class="control-row">
<label for="wrist">Wrist · local Z</label>
<output id="wrist-value">0°</output>
</div>
<input id="wrist" type="range" min="-90" max="90" value="0" />
</div>
<div class="local-note">
The tool is a child of the grip point, so its transform never detaches
from the hand.
</div>
<div class="button-row">
<button id="wave" class="primary">Wave Tool</button>
<button id="reset">Reset Pose</button>
</div>
</section>
<section class="panel" id="order-panel">
<div class="panel-header">
<h2 class="panel-title">Transformation Order</h2>
<div class="panel-number">02</div>
</div>
<div class="segmented" aria-label="Transformation order">
<button class="active" data-order="rotate-first">
Rotate → Translate
</button>
<button data-order="translate-first">
Translate → Rotate
</button>
</div>
<div class="sequence">
<div class="step" id="step-a">
<div class="step-index">STEP 01</div>
<strong>Rotate 65°</strong>
<small>Around local Z</small>
</div>
<div class="sequence-arrow">→</div>
<div class="step" id="step-b">
<div class="step-index">STEP 02</div>
<strong>Translate</strong>
<small>Vector T</small>
</div>
</div>
<div class="matrix-section">
<div class="formula" id="formula">M = T · R</div>
<div class="formula-note">
Column vectors are used: the rightmost matrix acts first.
</div>
<div class="matrix-wrap">
<div>
<div class="matrix-label">Composed matrix</div>
<div class="matrix-grid" id="composed-matrix"></div>
</div>
<div class="result">
<strong id="result-title">Rotate first</strong>
<div id="result-equation">P′ = P + T</div>
<div style="margin-top: 7px">R = Rz(65°)</div>
<div>T = (1.25, 0.55, 0)</div>
</div>
</div>
</div>
</section>
<section class="panel" id="hierarchy-panel">
<div class="panel-header">
<h2 class="panel-title">Parent–Child Chain</h2>
<div class="panel-number">03</div>
</div>
<ul class="tree">
<li>
<span class="name">World</span>
<ul>
<li>
<span class="name">CharacterRoot</span>
<ul>
<li>
<span class="name">TorsoFrame</span>
<ul>
<li>
<span class="name">Shoulder</span>
<span class="local">local Z</span>
<ul>
<li>
<span class="name">Elbow</span>
<span class="local">local Z</span>
<ul>
<li>
<span class="name">Wrist</span>
<span class="local">local Z</span>
<ul>
<li><span class="name grip">GripPoint</span></li>
<li><span class="name tool">Tool</span></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="matrix-chain">
<span class="matrix-chip">Mworld</span>
<span class="matrix-chip">Mroot</span>
<span class="matrix-chip">Mtorso</span>
<span class="matrix-chip">Mshoulder</span>
<span class="matrix-chip">Melbow</span>
<span class="matrix-chip">Mwrist</span>
<span class="matrix-chip">Mhand</span>
</div>
<pre class="hand-matrix" id="hand-matrix"></pre>
<label class="check-row">
<input id="show-hierarchy" type="checkbox" checked />
Show hierarchy links
</label>
</section>
<div class="scene-label" id="shoulder-label">SHOULDER · LOCAL Z</div>
<div class="scene-label" id="elbow-label">ELBOW · LOCAL Z</div>
<div class="scene-label orange" id="grip-label">GRIP · TOOL PARENT</div>
<div class="scene-label yellow" id="tool-label">TOOL</div>
<div class="scene-label" id="order-label">ORDER LAB</div>
<div id="hint">Drag to orbit · Scroll to zoom</div>
<div id="loading">Building voxel hierarchy…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const stage = $("stage");
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 10, 23);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
50
);
const cameraTarget = new THREE.Vector3(0.45, 1.65, 0);
const cameraState = {
azimuth: 0.34,
polar: 1.02,
radius: window.innerWidth < 780 ? 11.2 : 9.1
};
const hemisphere = new THREE.HemisphereLight(
0xbfe9ff,
0x172033,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.3);
keyLight.position.set(-4, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4ddfff, 1.6);
rimLight.position.set(5, 4, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9b50, 11, 8, 2);
warmLight.position.set(-3, 2.8, 2);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Voxel construction helpers
// -------------------------------------------------------------------------
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0x06101a,
transparent: true,
opacity: 0.82
});
function makeVoxel(
parent,
size,
position,
color,
options = {}
) {
const geometry = new THREE.BoxGeometry(...size);
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0.03,
flatShading: true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
if (options.outline !== false) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
outlineMaterial
);
mesh.add(edges);
}
return mesh;
}
function makePivotGuide(parent, radius, color) {
const geometry = new THREE.TorusGeometry(
radius,
0.014,
6,
40,
Math.PI * 1.45
);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.62
});
const arc = new THREE.Mesh(geometry, material);
arc.rotation.z = 0.35;
parent.add(arc);
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-radius, 0, 0),
new THREE.Vector3(radius, 0, 0)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.8
})
);
parent.add(axis);
}
// Ground and stage platforms.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x0b1725,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x23435d, 0x14283a);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
makeVoxel(scene, [2.35, 0.09, 2.0], [-1.05, 0.045, 0], 0x10293a);
makeVoxel(scene, [2.45, 0.05, 2.1], [-1.05, 0.115, 0], 0x163c4b);
makeVoxel(scene, [2.55, 0.26, 2.2], [2.7, 0.13, 0], 0x132b3c);
makeVoxel(scene, [2.65, 0.055, 2.3], [2.7, 0.285, 0], 0x1b4052);
// -------------------------------------------------------------------------
// Character hierarchy
//
// World
// └─ CharacterRoot
// └─ TorsoFrame
// └─ Shoulder
// └─ Elbow
// └─ Wrist
// ├─ Hand
// ├─ GripPoint
// │ └─ Tool
// └─ ...
// -------------------------------------------------------------------------
const characterRoot = new THREE.Group();
characterRoot.name = "CharacterRoot";
characterRoot.position.set(-1.05, 0, 0);
scene.add(characterRoot);
const torsoFrame = new THREE.Group();
torsoFrame.name = "TorsoFrame";
torsoFrame.position.set(0, 1.92, 0);
characterRoot.add(torsoFrame);
const palette = {
teal: 0x31bcae,
tealDark: 0x147c80,
skin: 0xf2c58c,
hair: 0x263044,
navy: 0x34445e,
navyDark: 0x1b2637,
shoe: 0x111b29,
orange: 0xffa23a,
yellow: 0xffcc61
};
// Hips, torso, neck, and head.
makeVoxel(characterRoot, [1.02, 0.32, 0.55], [0, 1.36, 0], palette.navy);
makeVoxel(torsoFrame, [1.08, 1.13, 0.62], [0, 0, 0], palette.teal);
makeVoxel(torsoFrame, [1.13, 0.16, 0.66], [0, 0.38, 0], palette.tealDark);
makeVoxel(torsoFrame, [0.28, 0.24, 0.28], [0, 0.68, 0], palette.skin);
const head = new THREE.Group();
head.name = "Head";
head.position.set(0, 1.08, 0);
torsoFrame.add(head);
makeVoxel(head, [0.86, 0.78, 0.72], [0, 0, 0], palette.skin);
makeVoxel(head, [0.9, 0.18, 0.76], [0, 0.31, -0.01], palette.hair);
makeVoxel(head, [0.15, 0.28, 0.18], [-0.36, 0.08, 0], palette.hair);
makeVoxel(head, [0.15, 0.28, 0.18], [0.36, 0.08, 0], palette.hair);
makeVoxel(head, [0.12, 0.13, 0.045], [-0.2, 0.03, 0.377], 0x101824);
makeVoxel(head, [0.12, 0.13, 0.045], [0.2, 0.03, 0.377], 0x101824);
makeVoxel(head, [0.2, 0.055, 0.045], [0, -0.17, 0.378], 0x9b594e);
// Small chest badge and back voxel.
makeVoxel(torsoFrame, [0.23, 0.23, 0.05], [0.25, 0.12, 0.335], palette.yellow);
makeVoxel(torsoFrame, [0.72, 0.84, 0.28], [0, 0, -0.43], palette.tealDark);
// Legs, with knee pivots for a complete blocky silhouette.
function makeLeg(x, accentColor) {
const hip = new THREE.Group();
hip.position.set(x, 1.31, 0);
characterRoot.add(hip);
makeVoxel(hip, [0.39, 0.72, 0.4], [0, -0.36, 0], palette.navy);
const knee = new THREE.Group();
knee.position.set(0, -0.72, 0);
hip.add(knee);
makeVoxel(knee, [0.35, 0.6, 0.37], [0, -0.3, 0], palette.navyDark);
makeVoxel(knee, [0.43, 0.23, 0.58], [0, -0.66, 0.09], palette.shoe);
makeVoxel(knee, [0.41, 0.12, 0.42], [0, -0.04, 0], accentColor);
}
makeLeg(-0.29, palette.teal);
makeLeg(0.29, palette.teal);
// Left arm, intentionally simpler and non-interactive.
const leftShoulder = new THREE.Group();
leftShoulder.position.set(0.7, 0.37, 0);
leftShoulder.rotation.z = -0.1;
torsoFrame.add(leftShoulder);
makeVoxel(leftShoulder, [0.36, 0.78, 0.38], [0, -0.39, 0], palette.teal);
makeVoxel(leftShoulder, [0.32, 0.68, 0.34], [0.02, -1.08, 0], palette.skin);
makeVoxel(leftShoulder, [0.4, 0.34, 0.4], [0.02, -1.5, 0], palette.skin);
// Interactive right-arm chain.
const shoulder = new THREE.Group();
shoulder.name = "Shoulder";
shoulder.position.set(-0.71, 0.37, 0.03);
torsoFrame.add(shoulder);
makeVoxel(shoulder, [0.38, 0.82, 0.4], [0, -0.41, 0], palette.teal);
makeVoxel(shoulder, [0.42, 0.18, 0.44], [0, 0.01, 0], palette.tealDark);
makePivotGuide(shoulder, 0.49, 0xffa23a);
const elbow = new THREE.Group();
elbow.name = "Elbow";
elbow.position.set(0, -0.82, 0);
shoulder.add(elbow);
makeVoxel(elbow, [0.32, 0.75, 0.34], [0, -0.375, 0], palette.skin);
makeVoxel(elbow, [0.36, 0.15, 0.38], [0, 0, 0], palette.tealDark);
makePivotGuide(elbow, 0.39, 0xffa23a);
const wrist = new THREE.Group();
wrist.name = "Wrist";
wrist.position.set(0, -0.75, 0);
elbow.add(wrist);
makeVoxel(wrist, [0.18, 0.18, 0.38], [0, 0, 0], palette.orange);
const hand = makeVoxel(
wrist,
[0.45, 0.38, 0.42],
[0, -0.19, 0.015],
palette.skin
);
hand.name = "Hand";
// The grip is a child of the wrist/hand transform.
const gripPoint = new THREE.Group();
gripPoint.name = "GripPoint";
gripPoint.position.set(0, -0.2, 0.285);
wrist.add(gripPoint);
const gripMarker = makeVoxel(
gripPoint,
[0.13, 0.13, 0.13],
[0, 0, 0],
0xffd06a,
{
emissive: 0xff8a26,
emissiveIntensity: 0.75,
castShadow: false
}
);
// The tool is a child of the grip point. Therefore every ancestor rotation
// moves the tool rigidly with the hand without breaking the grip.
const tool = new THREE.Group();
tool.name = "Tool";
gripPoint.add(tool);
makeVoxel(tool, [0.18, 1.08, 0.18], [0, -0.49, 0], palette.orange);
makeVoxel(tool, [0.24, 0.29, 0.24], [0, -0.07, 0], 0x5a3822);
makeVoxel(tool, [0.76, 0.31, 0.36], [0, -1.02, 0], palette.yellow);
makeVoxel(tool, [0.18, 0.38, 0.42], [-0.4, -1.02, 0], 0xe79a35);
makeVoxel(tool, [0.18, 0.38, 0.42], [0.4, -1.02, 0], 0xe79a35);
const toolAnchor = new THREE.Object3D();
toolAnchor.position.set(0, -0.65, 0);
tool.add(toolAnchor);
// -------------------------------------------------------------------------
// Hierarchy connector lines
// -------------------------------------------------------------------------
const hierarchyLinks = [];
const hierarchyMaterial = new THREE.LineDashedMaterial({
color: 0x55ddff,
transparent: true,
opacity: 0.45,
dashSize: 0.1,
gapSize: 0.075
});
function addHierarchyLink(parent, child) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const line = new THREE.Line(geometry, hierarchyMaterial);
line.frustumCulled = false;
scene.add(line);
hierarchyLinks.push({ parent, child, line });
}
addHierarchyLink(torsoFrame, shoulder);
addHierarchyLink(shoulder, elbow);
addHierarchyLink(elbow, wrist);
addHierarchyLink(wrist, gripPoint);
addHierarchyLink(gripPoint, toolAnchor);
const pointA = new THREE.Vector3();
const pointB = new THREE.Vector3();
function updateHierarchyLinks() {
const visible = $("show-hierarchy").checked;
for (const link of hierarchyLinks) {
link.line.visible = visible;
if (!visible) continue;
link.parent.getWorldPosition(pointA);
link.child.getWorldPosition(pointB);
const positions = link.line.geometry.attributes.position;
positions.setXYZ(0, pointA.x, pointA.y, pointA.z);
positions.setXYZ(1, pointB.x, pointB.y, pointB.z);
positions.needsUpdate = true;
link.line.computeLineDistances();
}
}
// -------------------------------------------------------------------------
// Transformation-order playground
// -------------------------------------------------------------------------
const orderStage = new THREE.Group();
orderStage.name = "OrderStage";
orderStage.position.set(2.7, 2.12, 0);
scene.add(orderStage);
const orderPayload = new THREE.Group();
orderStage.add(orderPayload);
makeVoxel(
orderPayload,
[0.43, 0.43, 0.43],
[0, 0, 0],
0xff6b61,
{
emissive: 0x4c0904,
emissiveIntensity: 0.35
}
);
// Pivot marker.
makeVoxel(
orderStage,
[0.14, 0.14, 0.14],
[0, 0, 0],
0xdff8ff,
{
emissive: 0x55ddff,
emissiveIntensity: 0.6,
castShadow: false
}
);
const translation = new THREE.Vector3(1.25, 0.55, 0);
const orderAngle = THREE.MathUtils.degToRad(65);
const translationArrow = new THREE.ArrowHelper(
translation.clone().normalize(),
new THREE.Vector3(0, 0, 0),
translation.length(),
0x55ddff,
0.16,
0.09
);
orderStage.add(translationArrow);
// Wireframe target at T.
const translationTarget = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.48, 0.48),
new THREE.MeshBasicMaterial({
color: 0x55ddff,
wireframe: true,
transparent: true,
opacity: 0.42
})
);
translationTarget.position.copy(translation);
orderStage.add(translationTarget);
// Wireframe target at R*T.
const rotatedTranslationTarget = new THREE.Mesh(
new THREE.BoxGeometry(0.48, 0.48, 0.48),
new THREE.MeshBasicMaterial({
color: 0xffad45,
wireframe: true,
transparent: true,
opacity: 0.48
})
);
rotatedTranslationTarget.position.set(
Math.cos(orderAngle) * translation.x -
Math.sin(orderAngle) * translation.y,
Math.sin(orderAngle) * translation.x +
Math.cos(orderAngle) * translation.y,
0
);
orderStage.add(rotatedTranslationTarget);
// Visible rotation arc in the XY plane.
const rotationArc = new THREE.Mesh(
new THREE.TorusGeometry(
0.68,
0.017,
6,
52,
Math.PI * 1.45
),
new THREE.MeshBasicMaterial({
color: 0xffad45,
transparent: true,
opacity: 0.76
})
);
orderStage.add(rotationArc);
const arcAngle = Math.PI * 1.45;
const arcHead = new THREE.Mesh(
new THREE.ConeGeometry(0.06, 0.17, 6),
new THREE.MeshBasicMaterial({ color: 0xffad45 })
);
arcHead.position.set(
Math.cos(arcAngle) * 0.68,
Math.sin(arcAngle) * 0.68,
0
);
arcHead.rotation.z = arcAngle;
orderStage.add(arcHead);
let orderMode = "rotate-first";
let orderEpoch = performance.now();
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function updateOrderAnimation(now) {
const cycle = 3.45;
const elapsed = ((now - orderEpoch) / 1000) % cycle;
const rotationDuration = 1.05;
const transitionDuration = 1.05;
let stepA = false;
let stepB = false;
if (orderMode === "rotate-first") {
if (elapsed < rotationDuration) {
const t = easeInOutCubic(elapsed / rotationDuration);
orderPayload.position.set(0, 0, 0);
orderPayload.rotation.z = orderAngle * t;
stepA = true;
} else if (elapsed < rotationDuration + transitionDuration) {
const t = easeInOutCubic(
(elapsed - rotationDuration) / transitionDuration
);
orderPayload.position.copy(translation).multiplyScalar(t);
orderPayload.rotation.z = orderAngle;
stepB = true;
} else {
orderPayload.position.copy(translation);
orderPayload.rotation.z = orderAngle;
}
} else {
if (elapsed < transitionDuration) {
const t = easeInOutCubic(elapsed / transitionDuration);
orderPayload.position.copy(translation).multiplyScalar(t);
orderPayload.rotation.z = 0;
stepA = true;
} else if (elapsed < transitionDuration + rotationDuration) {
const t = easeInOutCubic(
(elapsed - transitionDuration) / rotationDuration
);
const angle = orderAngle * t;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
// Orbit from T to R*T while the payload also rotates.
orderPayload.position.set(
cos * translation.x - sin * translation.y,
sin * translation.x + cos * translation.y,
0
);
orderPayload.rotation.z = angle;
stepB = true;
} else {
orderPayload.position.set(
Math.cos(orderAngle) * translation.x -
Math.sin(orderAngle) * translation.y,
Math.sin(orderAngle) * translation.x +
Math.cos(orderAngle) * translation.y,
0
);
orderPayload.rotation.z = orderAngle;
}
}
$("step-a").classList.toggle("active", stepA);
$("step-b").classList.toggle("active", stepB);
$("step-a").classList.toggle(
"done",
!stepA && elapsed > 0.1
);
$("step-b").classList.toggle(
"done",
!stepB && elapsed > rotationDuration + transitionDuration
);
}
function updateOrderUI() {
const c = Math.cos(orderAngle);
const s = Math.sin(orderAngle);
let matrix;
if (orderMode === "rotate-first") {
$("formula").textContent = "M = T · R";
$("result-title").textContent = "Rotate first";
$("result-equation").textContent = "P′ = P + T";
$("step-a").querySelector("strong").textContent = "Rotate 65°";
$("step-a").querySelector("small").textContent = "Around local Z";
$("step-b").querySelector("strong").textContent = "Translate";
$("step-b").querySelector("small").textContent = "Vector T";
matrix = [
c, -s, 0, translation.x,
s, c, 0, translation.y,
0, 0, 1, 0,
0, 0, 0, 1
];
} else {
$("formula").textContent = "M = R · T";
$("result-title").textContent = "Translate first";
$("result-equation").textContent = "P′ = P + R T";
$("step-a").querySelector("strong").textContent = "Translate";
$("step-a").querySelector("small").textContent = "Vector T";
$("step-b").querySelector("strong").textContent = "Rotate 65°";
$("step-b").querySelector("small").textContent = "Around local Z";
matrix = [
c, -s, 0,
c * translation.x - s * translation.y,
s, c, 0,
s * translation.x + c * translation.y,
0, 0, 1, 0,
0, 0, 0, 1
];
}
const matrixElement = $("composed-matrix");
matrixElement.replaceChildren();
for (const value of matrix) {
const cell = document.createElement("span");
cell.textContent = Math.abs(value) < 0.0001
? "0"
: Number(value.toFixed(2));
matrixElement.appendChild(cell);
}
document.querySelectorAll("[data-order]").forEach((button) => {
const active = button.dataset.order === orderMode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
document.querySelectorAll("[data-order]").forEach((button) => {
button.addEventListener("click", () => {
orderMode = button.dataset.order;
orderEpoch = performance.now();
updateOrderUI();
});
});
updateOrderUI();
// -------------------------------------------------------------------------
// Character animation and controls
// -------------------------------------------------------------------------
const defaultPose = {
shoulder: -35,
elbow: 105,
wrist: 0
};
const rig = {
shoulder: { actual: -35, target: -35 },
elbow: { actual: 105, target: 105 },
wrist: { actual: 0, target: 0 }
};
const jointGroups = {
shoulder,
elbow,
wrist
};
for (const name of Object.keys(rig)) {
$(name).addEventListener("input", (event) => {
rig[name].target = Number(event.target.value);
waveAnimation = null;
});
}
$("reset").addEventListener("click", () => {
for (const name of Object.keys(defaultPose)) {
rig[name].target = defaultPose[name];
$(name).value = defaultPose[name];
}
waveAnimation = null;
});
let waveAnimation = null;
$("wave").addEventListener("click", () => {
waveAnimation = {
start: performance.now(),
duration: 1900,
from: rig.wrist.target
};
});
function sampleWave(progress) {
const keys = [
[0.0, waveAnimation.from],
[0.25, -55],
[0.5, 55],
[0.75, -55],
[1.0, 0]
];
for (let i = 0; i < keys.length - 1; i++) {
const [a, va] = keys[i];
const [b, vb] = keys[i + 1];
if (progress >= a && progress <= b) {
const t = easeInOutCubic((progress - a) / (b - a));
return THREE.MathUtils.lerp(va, vb, t);
}
}
return 0;
}
function updateRig(dt, now) {
if (waveAnimation) {
const progress = (now - waveAnimation.start) / waveAnimation.duration;
if (progress >= 1) {
rig.wrist.target = 0;
$("wrist").value = 0;
waveAnimation = null;
} else {
rig.wrist.target = sampleWave(progress);
$("wrist").value = Math.round(rig.wrist.target);
}
}
const damping = 1 - Math.exp(-dt * 9);
for (const name of Object.keys(rig)) {
const state = rig[name];
state.actual = THREE.MathUtils.lerp(
state.actual,
state.target,
damping
);
jointGroups[name].rotation.z = THREE.MathUtils.degToRad(
state.actual
);
$(`${name}-value`).textContent =
`${Math.round(state.actual)}°`;
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and touch drag
// -------------------------------------------------------------------------
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.005,
0.42,
1.46
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
5.5,
15
);
},
{ passive: false }
);
function updateCamera() {
const { azimuth, polar, radius } = cameraState;
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Projected HTML labels and live hand matrix
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, dx = 12, dy = 0) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.transform = `translate(${dx}px, ${dy}px)`;
}
const labelPositions = {
shoulder: new THREE.Vector3(),
elbow: new THREE.Vector3(),
grip: new THREE.Vector3(),
tool: new THREE.Vector3(),
order: new THREE.Vector3()
};
function updateLabels() {
shoulder.getWorldPosition(labelPositions.shoulder);
elbow.getWorldPosition(labelPositions.elbow);
gripPoint.getWorldPosition(labelPositions.grip);
toolAnchor.getWorldPosition(labelPositions.tool);
orderStage.getWorldPosition(labelPositions.order);
placeLabel($("shoulder-label"), labelPositions.shoulder, 15, -25);
placeLabel($("elbow-label"), labelPositions.elbow, 16, 8);
placeLabel($("grip-label"), labelPositions.grip, 18, -28);
placeLabel($("tool-label"), labelPositions.tool, 16, 12);
placeLabel($("order-label"), labelPositions.order, -70, -37);
}
function updateHandMatrix() {
hand.updateWorldMatrix(true, false);
const e = hand.matrixWorld.elements;
const rows = [
[e[0], e[4], e[8], e[12]],
[e[1], e[5], e[9], e[13]],
[e[2], e[6], e[10], e[14]],
[e[3], e[7], e[11], e[15]]
];
$("hand-matrix").textContent =
"HAND WORLD MATRIX\n" +
rows
.map((row) =>
row.map((value) => value.toFixed(2).padStart(7)).join(" ")
)
.join("\n");
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 780 ? 52 : 42;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let matrixFrame = 0;
renderer.setAnimationLoop((now) => {
const dt = Math.min(clock.getDelta(), 0.05);
updateRig(dt, now);
updateOrderAnimation(now);
updateCamera();
updateHierarchyLinks();
updateLabels();
matrixFrame += 1;
if (matrixFrame % 3 === 0) updateHandMatrix();
renderer.render(scene, camera);
});
updateCamera();
updateHandMatrix();
requestAnimationFrame(() => {
$("loading").style.opacity = "0";
setTimeout(() => $("loading").remove(), 320);
});
</script>
</body>
</html>
```