Prompt specification
Build or customize the Three.js 3D scene "Idle Walk and Reach Pose Markers" 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: Idle Walk and Reach Pose Markers
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/idle-walk-and-reach-pose-markers-x3685
Scene Description Prompt:
One original low-poly character in idle, walking, and reaching poses, with consistent limb lengths and marked contacts. Three.js from cdnjs, one HTML file.
Working Three.js Starter (idle-walk-and-reach-pose-markers-x3685):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Relay — Low-Poly Motion Study</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(13, 18, 28, 0.82);
--line: rgba(255, 255, 255, 0.13);
--text: #eef4ff;
--muted: #9aa9bd;
--accent: #7cf7d4;
--accent-2: #ffb86b;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b1018;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas { display: block; }
#app {
position: fixed;
inset: 0;
}
.panel {
position: fixed;
z-index: 10;
color: var(--text);
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 18px 16px;
border-radius: 18px;
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: .2em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 7px;
font-size: clamp(24px, 4vw, 34px);
line-height: 1;
letter-spacing: -.04em;
}
.sub {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.modes {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 15px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--text);
background: rgba(255,255,255,.055);
padding: 10px 8px;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background .18s, border-color .18s, transform .18s;
}
button:hover {
background: rgba(255,255,255,.11);
transform: translateY(-1px);
}
button.active {
color: #06100d;
background: var(--accent);
border-color: var(--accent);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px 15px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
vertical-align: 1px;
}
.dot.contact { background: var(--accent); box-shadow: 0 0 9px var(--accent); }
.dot.target { background: var(--accent-2); box-shadow: 0 0 9px var(--accent-2); }
#stats {
right: 22px;
bottom: 22px;
width: 236px;
padding: 14px;
border-radius: 15px;
font-size: 11px;
}
.stat-row {
display: flex;
justify-content: space-between;
gap: 14px;
padding: 5px 0;
color: var(--muted);
}
.stat-row strong {
color: var(--text);
font-variant-numeric: tabular-nums;
}
#hint {
position: fixed;
z-index: 9;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 8px 12px;
color: rgba(238,244,255,.65);
background: rgba(8,12,19,.58);
border: 1px solid rgba(255,255,255,.08);
border-radius: 999px;
font-size: 10px;
letter-spacing: .04em;
pointer-events: none;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
color: var(--accent);
background: #0b1018;
font-size: 11px;
letter-spacing: .18em;
text-transform: uppercase;
transition: opacity .35s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 650px) {
#intro { top: 12px; left: 12px; width: calc(100vw - 24px); }
#stats { display: none; }
#hint { bottom: 10px; }
.sub { display: none; }
}
</style>
</head>
<body>
<div id="app"></div>
<section id="intro" class="panel">
<div class="eyebrow">Character motion study / 01</div>
<h1>RELAY</h1>
<p class="sub">
A faceted field courier with a fixed-length rig. Switch poses to inspect
grounded foot contacts and the reach target.
</p>
<nav class="modes" aria-label="Animation pose">
<button data-mode="idle" class="active">Idle</button>
<button data-mode="walk">Walk</button>
<button data-mode="reach">Reach</button>
</nav>
<div class="legend">
<span><i class="dot contact"></i>Grounded contact</span>
<span><i class="dot target"></i>Reach target</span>
</div>
</section>
<aside id="stats" class="panel">
<div class="stat-row"><span>Pose</span><strong id="poseName">Idle</strong></div>
<div class="stat-row"><span>Upper arm</span><strong>0.68 m</strong></div>
<div class="stat-row"><span>Forearm</span><strong>0.66 m</strong></div>
<div class="stat-row"><span>Thigh</span><strong>0.85 m</strong></div>
<div class="stat-row"><span>Shin</span><strong>0.80 m</strong></div>
<div class="stat-row"><span>Contacts</span><strong id="contactCount">2 feet</strong></div>
<div class="stat-row"><span>Camera</span><strong id="cameraState">Orbit</strong></div>
</aside>
<div id="hint">Drag to orbit · Scroll to zoom · Click a pose</div>
<div id="loading">Building relay rig…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const loading = document.querySelector("#loading");
// ---------------------------------------------------------------------
// Renderer / scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1018);
scene.fog = new THREE.Fog(0x0b1018, 10, 24);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
app.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xb9dcff, 0x31251d, 2.25);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1db, 3.8);
key.position.set(4.5, 7, 5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -6;
key.shadow.normalBias = 0.025;
scene.add(key);
const rim = new THREE.DirectionalLight(0x64f4d0, 2.8);
rim.position.set(-4, 4, -4);
scene.add(rim);
const warm = new THREE.PointLight(0xff9f5a, 10, 8, 2);
warm.position.set(-2.5, 2.3, 3.5);
scene.add(warm);
// ---------------------------------------------------------------------
// Low-poly stage
// ---------------------------------------------------------------------
const stage = new THREE.Group();
scene.add(stage);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(7, 64),
new THREE.MeshStandardMaterial({ color: 0x111925, roughness: 0.92, metalness: 0.08 })
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
stage.add(ground);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.85, 3.05, 0.16, 10),
new THREE.MeshStandardMaterial({ color: 0x202c3a, roughness: 0.74, metalness: 0.2 })
);
platform.position.y = -0.08;
platform.receiveShadow = true;
platform.castShadow = true;
stage.add(platform);
const platformTop = new THREE.Mesh(
new THREE.CylinderGeometry(2.83, 2.83, 0.025, 10),
new THREE.MeshStandardMaterial({ color: 0x263647, roughness: 0.8 })
);
platformTop.position.y = 0.012;
platformTop.receiveShadow = true;
stage.add(platformTop);
const grid = new THREE.GridHelper(5.8, 14, 0x395066, 0x263446);
grid.position.y = 0.03;
grid.material.transparent = true;
grid.material.opacity = 0.35;
stage.add(grid);
// Decorative faceted background pylons.
const pylonMaterial = new THREE.MeshStandardMaterial({
color: 0x1c2735,
roughness: 0.72,
metalness: 0.28
});
for (const p of [
[-3.4, 0.65, -2.5, 0.55, 1.3],
[3.7, 0.9, -2.8, 0.7, 1.8],
[-4.1, 0.38, 1.8, 0.38, 0.76],
[4.4, 0.48, 1.9, 0.48, 0.96]
]) {
const pylon = new THREE.Mesh(
new THREE.CylinderGeometry(p[3], p[3] * 1.2, p[4], 5),
pylonMaterial
);
pylon.position.set(p[0], p[4] * 0.5, p[2]);
pylon.rotation.y = p[0] * 0.2;
pylon.castShadow = true;
pylon.receiveShadow = true;
stage.add(pylon);
}
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
flatShading: true,
roughness: 0.68,
metalness: 0.08,
...options
});
const mats = {
shell: material(0xdde7e8, { roughness: 0.52 }),
shellDark: material(0x526574, { roughness: 0.56 }),
suit: material(0x284b61, { roughness: 0.74 }),
suitDark: material(0x172c3b, { roughness: 0.7 }),
accent: material(0xf3a65b, { roughness: 0.48 }),
mint: material(0x71e4c2, { emissive: 0x123d36, emissiveIntensity: 0.5 }),
joint: material(0x17222b, { roughness: 0.45, metalness: 0.38 }),
visor: material(0x0a1a25, { roughness: 0.2, metalness: 0.45 }),
eye: material(0x83ffe0, { emissive: 0x4affd4, emissiveIntensity: 2.2 }),
sole: material(0x101820, { roughness: 0.82 })
};
// ---------------------------------------------------------------------
// Rig dimensions: all bones use these fixed lengths.
// ---------------------------------------------------------------------
const DIM = {
upperArm: 0.68,
forearm: 0.66,
thigh: 0.85,
shin: 0.80,
shoulderY: 2.72,
hipY: 1.65,
shoulderX: 0.52,
hipX: 0.245
};
const rig = new THREE.Group();
rig.position.set(0, 0, 0);
scene.add(rig);
const pelvis = new THREE.Group();
pelvis.position.y = DIM.hipY;
rig.add(pelvis);
const torso = new THREE.Group();
pelvis.add(torso);
function mesh(geometry, mat, parent, x = 0, y = 0, z = 0) {
const m = new THREE.Mesh(geometry, mat);
m.position.set(x, y, z);
m.castShadow = true;
m.receiveShadow = true;
parent.add(m);
return m;
}
function box(parent, size, mat, position = [0, 0, 0]) {
return mesh(new THREE.BoxGeometry(...size), mat, parent, ...position);
}
function segment(parent, length, radiusTop, radiusBottom, mat) {
const g = new THREE.Group();
parent.add(g);
const m = mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, length, 6),
mat,
g,
0,
-length / 2,
0
);
m.rotation.y = Math.PI / 6;
return g;
}
// Pelvis and torso.
box(pelvis, [0.72, 0.31, 0.40], mats.suitDark, [0, 0.04, 0]);
box(torso, [0.82, 0.91, 0.48], mats.suit, [0, 0.49, 0]);
box(torso, [0.88, 0.16, 0.51], mats.shellDark, [0, 0.25, 0]);
box(torso, [0.18, 0.55, 0.025], mats.accent, [0, 0.55, 0.255]);
const chestBadge = mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.025, 6),
mats.mint,
torso,
0.23,
0.66,
0.27
);
chestBadge.rotation.x = Math.PI / 2;
// Neck and head.
mesh(new THREE.CylinderGeometry(0.12, 0.14, 0.18, 6), mats.joint, torso, 0, 1.01, 0);
const head = new THREE.Group();
head.position.set(0, 1.18, 0);
torso.add(head);
const skull = mesh(new THREE.IcosahedronGeometry(0.39, 1), mats.shell, head, 0, 0.15, 0);
skull.scale.set(0.92, 1.05, 0.9);
box(head, [0.51, 0.20, 0.12], mats.visor, [0, 0.17, 0.33]);
box(head, [0.32, 0.055, 0.035], mats.eye, [0, 0.17, 0.405]);
// Small antenna and cap.
mesh(new THREE.CylinderGeometry(0.035, 0.045, 0.34, 6), mats.joint, head, 0.22, 0.52, 0);
mesh(new THREE.OctahedronGeometry(0.09, 0), mats.accent, head, 0.22, 0.72, 0);
box(head, [0.22, 0.08, 0.38], mats.accent, [-0.18, 0.43, -0.04]);
// Backpack.
box(torso, [0.54, 0.58, 0.22], mats.shellDark, [0, 0.58, -0.34]);
box(torso, [0.31, 0.18, 0.07], mats.mint, [0, 0.73, -0.48]);
// ---------------------------------------------------------------------
// Arms: fixed upper arm + forearm chains.
// ---------------------------------------------------------------------
function makeArm(side) {
const shoulder = new THREE.Group();
shoulder.position.set(side * DIM.shoulderX, 0.93, 0);
torso.add(shoulder);
mesh(new THREE.SphereGeometry(0.15, 6, 4), mats.joint, shoulder);
const upper = segment(shoulder, DIM.upperArm, 0.135, 0.115, mats.shell);
const elbow = new THREE.Group();
elbow.position.y = -DIM.upperArm;
upper.add(elbow);
mesh(new THREE.SphereGeometry(0.115, 6, 4), mats.joint, elbow);
const lower = segment(elbow, DIM.forearm, 0.115, 0.085, mats.suit);
const hand = new THREE.Group();
hand.position.y = -DIM.forearm;
lower.add(hand);
mesh(new THREE.IcosahedronGeometry(0.115, 0), mats.accent, hand, 0, -0.045, 0);
box(hand, [0.11, 0.19, 0.12], mats.shellDark, [0, -0.14, 0]);
return { shoulder, upper, elbow, lower, hand };
}
const armL = makeArm(-1);
const armR = makeArm(1);
// Shoulder armor.
box(torso, [0.29, 0.23, 0.45], mats.shell, [-DIM.shoulderX, 0.91, 0]);
box(torso, [0.29, 0.23, 0.45], mats.shell, [DIM.shoulderX, 0.91, 0]);
// ---------------------------------------------------------------------
// Legs: fixed thigh + shin chains.
// ---------------------------------------------------------------------
function makeLeg(side) {
const hip = new THREE.Group();
hip.position.set(side * DIM.hipX, -0.02, 0);
pelvis.add(hip);
mesh(new THREE.SphereGeometry(0.16, 6, 4), mats.joint, hip);
const upper = segment(hip, DIM.thigh, 0.17, 0.13, mats.suit);
const knee = new THREE.Group();
knee.position.y = -DIM.thigh;
upper.add(knee);
mesh(new THREE.SphereGeometry(0.13, 6, 4), mats.joint, knee);
box(knee, [0.25, 0.18, 0.12], mats.shellDark, [0, 0, 0.12]);
const lower = segment(knee, DIM.shin, 0.13, 0.095, mats.shellDark);
const ankle = new THREE.Group();
ankle.position.y = -DIM.shin;
lower.add(ankle);
const foot = box(ankle, [0.26, 0.13, 0.47], mats.shell, [0, -0.065, 0.11]);
box(ankle, [0.27, 0.055, 0.48], mats.sole, [0, -0.135, 0.11]);
return { hip, upper, knee, lower, ankle, foot };
}
const legL = makeLeg(-1);
const legR = makeLeg(1);
// ---------------------------------------------------------------------
// Contact and target markers
// ---------------------------------------------------------------------
function makeContactMarker() {
const group = new THREE.Group();
const ring = mesh(
new THREE.RingGeometry(0.15, 0.205, 24),
new THREE.MeshBasicMaterial({
color: 0x76f7d4,
transparent: true,
opacity: 0.92,
side: THREE.DoubleSide,
depthWrite: false
}),
group
);
ring.rotation.x = -Math.PI / 2;
const core = mesh(
new THREE.CircleGeometry(0.135, 24),
new THREE.MeshBasicMaterial({
color: 0x76f7d4,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false
}),
group,
0,
0,
0
);
core.rotation.x = -Math.PI / 2;
group.position.y = 0.045;
scene.add(group);
return { group, ring, core };
}
const contactL = makeContactMarker();
const contactR = makeContactMarker();
const targetGroup = new THREE.Group();
scene.add(targetGroup);
const targetRing = mesh(
new THREE.TorusGeometry(0.22, 0.022, 5, 20),
new THREE.MeshBasicMaterial({ color: 0xffb56a, transparent: true, opacity: 0.95 }),
targetGroup
);
targetRing.rotation.x = Math.PI / 2;
const targetDisc = mesh(
new THREE.CircleGeometry(0.18, 20),
new THREE.MeshBasicMaterial({
color: 0xffb56a,
transparent: true,
opacity: 0.12,
side: THREE.DoubleSide,
depthWrite: false
}),
targetGroup
);
targetDisc.rotation.x = -Math.PI / 2;
const targetArrow = mesh(
new THREE.ConeGeometry(0.07, 0.22, 5),
new THREE.MeshBasicMaterial({ color: 0xffb56a }),
targetGroup,
0,
0,
0.18
);
targetArrow.rotation.x = Math.PI / 2;
// ---------------------------------------------------------------------
// Animation state
// ---------------------------------------------------------------------
let mode = "idle";
let walkTime = 0;
const clock = new THREE.Clock();
const pose = {
rootY: 0,
rootX: 0,
rootZ: 0,
rootPitch: 0,
pelvisY: DIM.hipY,
pelvisRoll: 0,
pelvisYaw: 0,
torsoPitch: 0,
torsoRoll: 0,
torsoYaw: 0,
headPitch: 0,
headYaw: 0,
armLX: 0, armLY: 0, armLZ: 0,
armRX: 0, armRY: 0, armRZ: 0,
elbowL: 0, elbowR: 0,
legLX: 0, legLY: 0,
legRX: 0, legRY: 0,
kneeL: 0, kneeR: 0,
ankleL: 0, ankleR: 0
};
const buttons = [...document.querySelectorAll("[data-mode]")];
const poseName = document.querySelector("#poseName");
const contactCount = document.querySelector("#contactCount");
function setMode(next) {
mode = next;
buttons.forEach((b) => b.classList.toggle("active", b.dataset.mode === mode));
poseName.textContent = mode[0].toUpperCase() + mode.slice(1);
}
buttons.forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
const targetPose = {
rootY: 0, rootX: 0, rootZ: 0, rootPitch: 0,
pelvisY: DIM.hipY, pelvisRoll: 0, pelvisYaw: 0,
torsoPitch: 0, torsoRoll: 0, torsoYaw: 0,
headPitch: 0, headYaw: 0,
armLX: 0, armLY: 0, armLZ: 0,
armRX: 0, armRY: 0, armRZ: 0,
elbowL: 0, elbowR: 0,
legLX: 0, legLY: 0,
legRX: 0, legRY: 0,
kneeL: 0, kneeR: 0,
ankleL: 0, ankleR: 0
};
function buildPose(t) {
Object.assign(targetPose, {
rootY: 0, rootX: 0, rootZ: 0, rootPitch: 0,
pelvisY: DIM.hipY, pelvisRoll: 0, pelvisYaw: 0,
torsoPitch: 0, torsoRoll: 0, torsoYaw: 0,
headPitch: 0, headYaw: 0,
armLX: 0, armLY: 0, armLZ: 0,
armRX: 0, armRY: 0, armRZ: 0,
elbowL: 0, elbowR: 0,
legLX: 0, legLY: 0,
legRX: 0, legRY: 0,
kneeL: 0, kneeR: 0,
ankleL: 0, ankleR: 0
});
if (mode === "idle") {
const breath = Math.sin(t * 1.55);
const sway = Math.sin(t * 0.72);
targetPose.pelvisY += breath * 0.015;
targetPose.torsoPitch += breath * 0.018;
targetPose.torsoRoll += sway * 0.018;
targetPose.headPitch += -breath * 0.015;
targetPose.headYaw += sway * 0.045;
targetPose.armLX = -0.06 + sway * 0.02;
targetPose.armRX = 0.06 - sway * 0.02;
targetPose.armLZ = -0.055;
targetPose.armRZ = 0.055;
targetPose.elbowL = -0.12;
targetPose.elbowR = -0.12;
}
if (mode === "walk") {
const phase = t * 4.25;
const swing = Math.sin(phase);
const swing2 = Math.sin(phase + Math.PI);
const liftL = Math.max(0, Math.sin(phase));
const liftR = Math.max(0, Math.sin(phase + Math.PI));
targetPose.rootY = Math.abs(Math.cos(phase)) * 0.045;
targetPose.rootX = Math.sin(phase) * 0.08;
targetPose.pelvisY += Math.abs(Math.cos(phase)) * 0.028;
targetPose.pelvisRoll = Math.sin(phase) * 0.045;
targetPose.pelvisYaw = Math.sin(phase) * 0.075;
targetPose.torsoPitch = 0.075;
targetPose.torsoYaw = -Math.sin(phase) * 0.055;
targetPose.headYaw = -Math.sin(phase) * 0.035;
targetPose.legLX = swing * 0.53;
targetPose.legRX = swing2 * 0.53;
targetPose.kneeL = -liftL * 0.82;
targetPose.kneeR = -liftR * 0.82;
targetPose.ankleL = -swing * 0.18 + liftL * 0.18;
targetPose.ankleR = -swing2 * 0.18 + liftR * 0.18;
targetPose.armLX = swing2 * 0.48;
targetPose.armRX = swing * 0.48;
targetPose.armLZ = -0.10;
targetPose.armRZ = 0.10;
targetPose.elbowL = -0.23 - Math.max(0, swing2) * 0.16;
targetPose.elbowR = -0.23 - Math.max(0, swing) * 0.16;
}
if (mode === "reach") {
targetPose.rootY = -0.025;
targetPose.pelvisY += -0.025;
targetPose.rootPitch = 0.03;
targetPose.torsoPitch = -0.09;
targetPose.torsoYaw = -0.08;
targetPose.headPitch = -0.07;
targetPose.headYaw = -0.06;
targetPose.armRX = -1.18;
targetPose.armRY = -0.14;
targetPose.armRZ = 0.13;
targetPose.elbowR = -0.12;
targetPose.armLX = 0.24;
targetPose.armLZ = -0.14;
targetPose.elbowL = -0.32;
targetPose.legLX = -0.18;
targetPose.legRX = 0.12;
targetPose.kneeL = -0.18;
targetPose.kneeR = -0.08;
targetPose.ankleL = 0.12;
targetPose.ankleR = -0.05;
}
}
function applyPose(p) {
rig.position.set(p.rootX, p.rootY, p.rootZ);
rig.rotation.x = p.rootPitch;
pelvis.position.y = p.pelvisY;
pelvis.rotation.set(0, p.pelvisYaw, p.pelvisRoll);
torso.rotation.set(p.torsoPitch, p.torsoYaw, p.torsoRoll);
head.rotation.set(p.headPitch, p.headYaw, 0);
armL.shoulder.rotation.set(p.armLX, p.armLY, p.armLZ);
armR.shoulder.rotation.set(p.armRX, p.armRY, p.armRZ);
armL.elbow.rotation.x = p.elbowL;
armR.elbow.rotation.x = p.elbowR;
legL.hip.rotation.set(p.legLX, p.legLY, 0);
legR.hip.rotation.set(p.legRX, p.legRY, 0);
legL.knee.rotation.x = p.kneeL;
legR.knee.rotation.x = p.kneeR;
legL.ankle.rotation.x = p.ankleL;
legR.ankle.rotation.x = p.ankleR;
}
// ---------------------------------------------------------------------
// Contact evaluation from actual foot world positions.
// ---------------------------------------------------------------------
const footWorld = new THREE.Vector3();
const handWorld = new THREE.Vector3();
const targetWorld = new THREE.Vector3();
function lowestPoint(object) {
object.getWorldPosition(footWorld);
let minY = Infinity;
object.traverse((child) => {
if (!child.isMesh) return;
child.geometry.computeBoundingBox();
const b = child.geometry.boundingBox;
const p = new THREE.Vector3();
for (const x of [b.min.x, b.max.x]) {
for (const y of [b.min.y, b.max.y]) {
for (const z of [b.min.z, b.max.z]) {
p.set(x, y, z).applyMatrix4(child.matrixWorld);
minY = Math.min(minY, p.y);
}
}
}
});
return minY;
}
function updateMarkers(time) {
const lHeight = lowestPoint(legL.ankle);
const rHeight = lowestPoint(legR.ankle);
const threshold = 0.035;
const lContact = lHeight < threshold;
const rContact = rHeight < threshold;
contactL.group.visible = lContact;
contactR.group.visible = rContact;
if (lContact) {
legL.ankle.getWorldPosition(footWorld);
contactL.group.position.x = footWorld.x;
contactL.group.position.z = footWorld.z;
}
if (rContact) {
legR.ankle.getWorldPosition(footWorld);
contactR.group.position.x = footWorld.x;
contactR.group.position.z = footWorld.z;
}
const pulse = 0.92 + Math.sin(time * 4.5) * 0.08;
contactL.ring.scale.setScalar(pulse);
contactR.ring.scale.setScalar(pulse);
armR.hand.getWorldPosition(handWorld);
targetGroup.visible = mode === "reach";
if (mode === "reach") {
targetWorld.set(handWorld.x, handWorld.y, handWorld.z + 0.20);
targetGroup.position.copy(targetWorld);
targetGroup.rotation.y = Math.sin(time * 2.4) * 0.12;
targetRing.scale.setScalar(1 + Math.sin(time * 3.3) * 0.06);
}
let contacts = 0;
if (lContact) contacts++;
if (rContact) contacts++;
contactCount.textContent = mode === "reach"
? `${contacts} foot${contacts === 1 ? "" : "s"} + hand`
: `${contacts} foot${contacts === 1 ? "" : "s"}`;
}
// ---------------------------------------------------------------------
// Direct camera controls — no addons.
// ---------------------------------------------------------------------
let azimuth = 0.58;
let polar = 1.18;
let radius = 6.8;
let dragging = false;
let lastX = 0;
let lastY = 0;
let moved = 0;
const cameraTarget = new THREE.Vector3(0, 1.45, 0);
const cameraState = document.querySelector("#cameraState");
function updateCamera() {
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);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
moved = 0;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
cameraState.textContent = "Dragging";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
moved += Math.abs(dx) + Math.abs(dy);
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar - dy * 0.005, 0.42, 1.47);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
function stopDragging(event) {
if (!dragging) return;
dragging = false;
cameraState.textContent = "Orbit";
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(radius + event.deltaY * 0.005, 3.8, 11);
cameraState.textContent = `${radius.toFixed(1)}m`;
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
azimuth = 0.58;
polar = 1.18;
radius = 6.8;
updateCamera();
});
updateCamera();
// ---------------------------------------------------------------------
// Resize / loop
// ---------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
walkTime += dt;
const time = walkTime;
buildPose(time);
// Smoothly blend joint rotations and root offsets.
const smoothing = 1 - Math.exp(-dt * (mode === "walk" ? 12 : 8));
for (const key of Object.keys(pose)) {
pose[key] = THREE.MathUtils.lerp(pose[key], targetPose[key], smoothing);
}
applyPose(pose);
rig.updateMatrixWorld(true);
updateMarkers(time);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```