Turn any video into a Mixamo-rig animation - GVHMR estimator, spec-driven retarget, FK apply in Blender via MCP. Works with any Mixamo character; built to be operated end-to-end by an AI agent.
Add reach restoration and true gaze pitch; three new pitfalls
Sachaea4e0390042a
diff --git a/action_specs/spin.json b/action_specs/spin.jsonindex ff24b3e..a88f017 100644--- a/action_specs/spin.json+++ b/action_specs/spin.json@@ -26,8 +26,13 @@],"smooth": [- { "src": [172, 204], "window": 9,- "comment": "owner pass-2: the closing 4-punch flurry could be smoother." }+ { "src": [172, 204], "window": 5,+ "comment": "owner pass-2: flurry smoother. Pass-4: window 9 -> 5; a 9-frame window averaged away the punch extension peaks." }+ ],++ "reach": [+ { "src": [172, 204], "ramp_src": 4, "side": "both", "factor": 1.22, "max_fraction": 0.97,+ "comment": "owner pass-4: punches don't travel far enough. Reference reaches 87-98% of arm length; restore extension on already-extending arms only." }],"nudges": [@@ -38,8 +43,8 @@],"head_look": [- { "src": [172, 204], "ramp_src": 6, "amount": 0.7,- "comment": "owner pass-3: face direction off vs reference during the flurry - blend gaze 70% toward character-forward." }+ { "src": [172, 204], "ramp_src": 6, "amount": 0.7, "pitch_deg": -12,+ "comment": "owner pass-3: face direction off vs reference. Pass-4: skull also leaned back 8-14 deg (reference stays level, -6..+3) - pitch it forward 12 deg so he looks straight at the camera." }],"qa_src_frames": [1, 40, 55, 71, 85, 97, 117, 130, 146, 157, 170, 184, 192, 220, 241]diff --git a/docs/PIPELINE.md b/docs/PIPELINE.mdindex f9bd958..2ec2b53 100644--- a/docs/PIPELINE.md+++ b/docs/PIPELINE.md@@ -142,10 +142,25 @@ Two more windowed correctors for systematic estimator bias in a phase],// Blend the head's horizontal gaze toward character-forward-// (amount 0..1) where the estimator's head heading drifts.-"head_look": [ { "src": [172, 204], "ramp_src": 6, "amount": 0.7 } ]+// (amount 0..1) and/or pitch the skull axis (pitch_deg: + looks up,+// − levels a backward-leaning head).+"head_look": [ { "src": [172, 204], "ramp_src": 6, "amount": 0.7, "pitch_deg": -12 } ],++// Restore strike extension. Scales the hand's distance from its+// shoulder socket along its own direction, then re-places the chain+// with exact bone lengths (current elbow as pole). Only arms already+// past `min_extension` of full length are affected, so guards stay put.+"reach": [+ { "src": [172, 204], "ramp_src": 4, "side": "both",+ "factor": 1.22, "max_fraction": 0.97, "min_extension": 0.30 }+]```+**Smoothing eats strikes.** A `smooth` window wide enough to calm a+fast flurry (9 frames) also averages away its extension peaks — the+punches get visibly shorter. Keep flurry windows narrow (5) and+restore amplitude with `reach` rather than widening the smoothing.+## 4. Lift```diff --git a/docs/PITFALLS.md b/docs/PITFALLS.mdindex 9c6f0b3..6f2c34a 100644--- a/docs/PITFALLS.md+++ b/docs/PITFALLS.md@@ -81,18 +81,33 @@ touching a clip a human has partially signed off.exactly this reason; anything else that renders the scene must dothe same.+17. **The head aim ignores the lifted head's vertical.** `apply_mixamo_fk`+ rebuilds the head/neck aim from the torso up-axis plus the head's+ HORIZONTAL offset, so the skull follows the torso lean and a gaze+ correction written into the head joint silently disappears. Vertical+ gaze must travel as the explicit per-frame `head_pitch_deg` field+ (spec `head_look.pitch_deg`), which the apply rotates the aim by.+18. **Smoothing eats strikes.** A `smooth` window wide enough to calm a+ fast flurry (9 frames) also averages away its extension peaks —+ punches visibly shrink. Keep flurry windows narrow (5) and restore+ amplitude with `reach`.+19. **A "Hand" bone's world position is the WRIST.** Blender reports a+ bone's head; `mixamorig:*Hand` sits at the wrist, so dividing its+ distance-from-shoulder by (arm+fore+hand) understates extension by+ ~15%. Measure the wrist against arm+fore, or the fingertip bone.+## Process-17. **Beat sheet before any spec.** The 16-pass punch and the 4-pass+20. **Beat sheet before any spec.** The 16-pass punch and the 4-passkick differ by exactly this discipline; the two shipped clips took1–2 passes each.-18. **One constraint per pass; signed-off regions are frozen.** The+21. **One constraint per pass; signed-off regions are frozen.** Thesingle historical regression came from "improving" feet whilepolishing something else after the upper body was approved.-19. **Map human notes to the owning system before editing.** "Frames+22. **Map human notes to the owning system before editing.** "Frames18–50, punching side" once meant the *guard*, not the punch — apass was wasted editing the wrong function. Convert the frame rangeto src frames, find the beat, find the spec field; only then edit.-20. **QA passing ≠ done.** Numbers catch explosions, pops, skate and+23. **QA passing ≠ done.** Numbers catch explosions, pops, skate anddrift; they cannot see a wrong silhouette. Play the clip, read thestills, ask the human.diff --git a/pipeline/apply_mixamo_fk.py b/pipeline/apply_mixamo_fk.pyindex 6fb5125..cea5398 100644--- a/pipeline/apply_mixamo_fk.py+++ b/pipeline/apply_mixamo_fk.py@@ -25,6 +25,7 @@ Then, separately (keeps the long keying pass in one socket request):from __future__ import annotationsimport json+import mathfrom pathlib import Pathimport bpy@@ -373,11 +374,25 @@ def run(spec_path: str) -> dict:neck_p = v(fr["neck"])head_flat = v(fr["head"]) - neck_phead_flat.z = 0.0+ # The head aim is rebuilt from the torso up-axis, so the lifted+ # head's vertical is intentionally ignored — except for an+ # explicit per-frame gaze pitch (spec head_look.pitch_deg), which+ # rotates the aim about the character's lateral axis.+ pitch = math.radians(float(fr.get("head_pitch_deg", 0.0) or 0.0))+ lateral = v(fr["basis_x"])for bone, key in AIM:if bone == "mixamorig:Neck":- aim_bone(arm, bone, neck_p + up * 0.11 + head_flat * 0.25)+ aim = up * 0.11 + head_flat * 0.25+ if pitch:+ aim = aim.copy()+ aim.rotate(Quaternion(lateral, pitch * 0.35))+ aim_bone(arm, bone, neck_p + aim)elif bone == "mixamorig:Head":- aim_bone(arm, bone, neck_p + up * 0.28 + head_flat * 0.15)+ aim = up * 0.28 + head_flat * 0.15+ if pitch:+ aim = aim.copy()+ aim.rotate(Quaternion(lateral, pitch))+ aim_bone(arm, bone, neck_p + aim)else:aim_bone(arm, bone, v(fr[key]))apply_fingers(arm, fist)diff --git a/pipeline/lift_to_mixamo.py b/pipeline/lift_to_mixamo.pyindex 869ae90..0de01bc 100644--- a/pipeline/lift_to_mixamo.py+++ b/pipeline/lift_to_mixamo.py@@ -215,6 +215,33 @@ def seg(mp, i, a, b):return unit(mp[b][i] - mp[a][i])+def rodrigues(v, axis, angle):+ axis = unit(axis)+ c, s = np.cos(angle), np.sin(angle)+ return v * c + np.cross(axis, v) * s + axis * np.dot(axis, v) * (1.0 - c)+++def two_bone(p0, target, l1, l2, pole):+ """Place a two-bone chain from p0 to `target` with exact lengths,+ bending toward `pole`. Used only to re-place a chain after its+ end effector was moved (spec `reach`), never as an IK solver."""+ v = target - p0+ d_raw = np.linalg.norm(v)+ if d_raw < 1e-8:+ return p0 + unit(pole - p0) * l1, p0 + np.array([0.0, 0.0, -1.0]) * (l1 + l2)+ d = float(np.clip(d_raw, 1e-3, l1 + l2 - 1e-4))+ end = p0 + v * (d / d_raw)+ cos_a = (l1 * l1 + d * d - l2 * l2) / (2.0 * l1 * d)+ a = float(np.arccos(np.clip(cos_a, -1.0, 1.0)))+ n = np.cross(end - p0, pole - p0)+ if np.linalg.norm(n) < 1e-6:+ n = np.cross(end - p0, np.array([0.0, 0.0, 1.0]))+ if np.linalg.norm(n) < 1e-6:+ n = np.array([1.0, 0.0, 0.0])+ mid = p0 + unit(rodrigues(unit(end - p0), n, a)) * l1+ return mid, mid + unit(end - mid) * l2++def reconstruct(mp, i):"""Direction-preserving retarget of one frame onto Mixamo lengths."""ls, rs = mp["left_shoulder"][i], mp["right_shoulder"][i]@@ -398,27 +425,80 @@ def main():h = w + unit(h - w) * LEN[f"{s}_hand"]rec[f"{s}_elbow"], rec[f"{s}_wrist"], rec[f"{s}_hand"] = e, w, h+ # Windowed reach scaling (spec "reach"): push the hand further+ # from the shoulder socket along its own direction and re-place+ # the chain with exact bone lengths (current elbow as pole).+ # Estimators + smoothing compress strike extension; this restores+ # it without touching direction or timing.+ for rc in spec.get("reach", []):+ amt = window_amount(+ f,+ [rc["src"][0], rc["src"][0] + rc.get("ramp_src", 4)],+ [rc["src"][1] - rc.get("ramp_src", 4), rc["src"][1]],+ src2dest,+ )+ if amt <= 1e-4:+ continue+ factor = 1.0 + (float(rc.get("factor", 1.15)) - 1.0) * amt+ max_frac = float(rc.get("max_fraction", 0.97))+ sides = ("l", "r") if rc.get("side", "both") == "both" else (rc["side"][0],)+ for s in sides:+ sock = np.asarray(rec[f"{s}_arm"], float)+ wrist = np.asarray(rec[f"{s}_wrist"], float)+ l1, l2 = LEN[f"{s}_arm"], LEN[f"{s}_fore"]+ d = np.linalg.norm(wrist - sock)+ if d < 1e-4:+ continue+ # Only extend what is already extending (a guard hand+ # near the chin must not be shoved outward).+ if d < float(rc.get("min_extension", 0.30)) * (l1 + l2):+ continue+ new_d = min(d * factor, (l1 + l2) * max_frac)+ tgt = sock + unit(wrist - sock) * new_d+ elbow, new_wrist = two_bone(sock, tgt, l1, l2, np.asarray(rec[f"{s}_elbow"], float))+ rec[f"{s}_elbow"], rec[f"{s}_wrist"] = elbow, new_wrist+ # An extending strike puts the hand on the forearm line;+ # blending the estimator's (now stale) hand direction here+ # folds the fist back and cancels the added reach.+ rec[f"{s}_hand"] = new_wrist + unit(new_wrist - elbow) * LEN[f"{s}_hand"]++ head_pitch_deg = 0.0# Windowed gaze correction (spec "head_look"): blend the head's- # horizontal direction toward character-forward. For phases where- # the estimator's head heading drifts off the reference.+ # horizontal direction toward character-forward, and/or pitch the+ # skull axis (`pitch_deg`, + = look up, − = look down). For phases+ # where the estimator's head heading or lean drifts.for hl in spec.get("head_look", []):- amt = window_amount(+ win = window_amount(f,[hl["src"][0], hl["src"][0] + hl.get("ramp_src", 6)],[hl["src"][1] - hl.get("ramp_src", 6), hl["src"][1]],src2dest,- ) * float(hl.get("amount", 1.0))- if amt <= 1e-4:+ )+ if win <= 1e-4:continue+ # `amount` weights the horizontal blend only; `pitch_deg` is+ # an absolute angle gated by the same window.+ amt = win * float(hl.get("amount", 1.0))neck = np.asarray(rec["neck"], float)head = np.asarray(rec["head"], float)v = head - neck- flat = np.array([v[0], v[1], 0.0])- mag = max(np.linalg.norm(flat), 0.02)- fwd = -np.asarray(rec["basis_y"], float)- fwd = unit(np.array([fwd[0], fwd[1], 0.0])) * mag- new_flat = lerp(flat, fwd, amt)- rec["head"] = neck + np.array([new_flat[0], new_flat[1], v[2]])+ if hl.get("amount") is not None:+ flat = np.array([v[0], v[1], 0.0])+ mag = max(np.linalg.norm(flat), 0.02)+ fwd = -np.asarray(rec["basis_y"], float)+ fwd = unit(np.array([fwd[0], fwd[1], 0.0])) * mag+ new_flat = lerp(flat, fwd, amt)+ v = np.array([new_flat[0], new_flat[1], v[2]])+ if hl.get("pitch_deg"):+ # Rotate the neck->head axis about the character's lateral+ # axis. Positive tips the gaze up, negative levels a+ # backward-leaning skull. Recorded per frame as well: the+ # FK apply rebuilds its head aim from the torso up-axis and+ # would otherwise discard this.+ ang = np.radians(float(hl["pitch_deg"])) * win+ v = rodrigues(v, np.asarray(rec["basis_x"], float), ang)+ head_pitch_deg += float(hl["pitch_deg"]) * win+ rec["head"] = neck + vrest_amt = smoother((sf - rb["start_src"]) / max(1.0, rb["full_src"] - rb["start_src"]))rbs = spec.get("rest_blend_start")@@ -436,7 +516,8 @@ def main():recs.append(rec)extras.append({"frame": f, "t": float(dst_times[i]), "rest": rest_amt, "fist": fist,"plant": plant_at(sf) if rest_amt < 0.65 else "both",- "pelvis_height": float(pelvis_h[i])})+ "pelvis_height": float(pelvis_h[i]),+ "head_pitch_deg": head_pitch_deg})# Optional extra temporal smoothing on selected joints in selected# windows (spec "smooth") — for fast flurries the raw estimator@@ -493,6 +574,7 @@ def main():out["fist_amount"] = round(float(ex["fist"]), 4)out["plant"] = ex["plant"]out["pelvis_height"] = round(float(ex["pelvis_height"]), 5)+ out["head_pitch_deg"] = round(float(ex["head_pitch_deg"]), 3)joints.append(out)payload = {