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.
Real gaze end to end: estimator face landmarks, head orientation, QA audit
Sacha3ce7f7d48c34
diff --git a/action_specs/spin.json b/action_specs/spin.jsonindex 5ce787c..b3640a7 100644--- a/action_specs/spin.json+++ b/action_specs/spin.json@@ -42,10 +42,8 @@"comment": "owner pass-3: right shoulder pulls back - bring the right chain 5 cm forward." }],- "head_look": [- { "src": [172, 204], "ramp_src": 6, "amount": 0.7, "level_face": 1.0, "level_target_deg": 0,- "comment": "owner pass-3/4/5: he kept looking at the sky. Measured face axis (head local +Z) was +19..+27 deg above horizon; a fixed pitch_deg guess could not track the varying torso lean, so the apply now levels the face in closed loop." }- ],+ "_head_look_note": "pass-6: no manual gaze correction needed any more. The estimator now emits the performer's real gaze (mesh nose vs ears) and the apply orients the head to it, clamped to gaze_max_offset_deg from the chest.",+ "gaze_max_offset_deg": 70,"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 0cc5e11..c7ecbd4 100644--- a/docs/PIPELINE.md+++ b/docs/PIPELINE.md@@ -29,8 +29,13 @@ tools\GVHMR\.venv\Scripts\python.exe pipeline\estimate_pose_gvhmr.py ^```Output: 33 landmarks/frame (MediaPipe-compatible convention: per-frame-mid-hip origin, y down, z **negative toward camera**, meters) plus-`pelvis_height` (absolute, above the estimator's ground plane).+mid-hip origin, y down, z **negative toward camera**, meters),+`pelvis_height` (absolute, above the estimator's ground plane) and+`gaze` (unit vector, the performer's real face direction taken from+mesh vertices — nose vs ear midpoint). The face landmarks are real mesh+points, not torso-derived: head orientation cannot be recovered from+joint positions, and a retarget without it can only lock the character's+gaze to its chest.GVHMR caches its preprocessing under `tools/GVHMR/outputs/demo/<stem>/`— re-runs are fast.@@ -141,17 +146,6 @@ Two more windowed correctors for systematic estimator bias in a phase{ "src": [172, 204], "ramp_src": 5, "side": "right", "offset": [0, -0.05, 0] }],-// Gaze control. `amount` blends the horizontal heading toward-// character-forward. `level_face` (0..1) puts the FACE at-// `level_target_deg` above the horizon — a closed loop measured on the-// rig, which is what you want for "he's looking at the sky": the FK-// apply only aims the skull axis, so face pitch is a by-product of the-// torso lean and a hand-guessed `pitch_deg` cannot track it.-"head_look": [- { "src": [172, 204], "ramp_src": 6, "amount": 0.7,- "level_face": 1.0, "level_target_deg": 0 }-],-// 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@@ -162,6 +156,28 @@ Two more windowed correctors for systematic estimator bias in a phase]```+### Gaze++The head follows the estimator's real gaze by default — no spec entry+needed. Two top-level knobs tune it:++```jsonc+"gaze_follow": 1.0, // 0..1, how strongly the head tracks the real gaze+"gaze_max_offset_deg": 70 // cap on head-vs-chest yaw, so a 360 spin+ // does not twist the neck off+```++Per-window overrides go in `head_look` entries as `"follow_gaze"`, and+the manual correctors remain for the rare case where the estimator's+head is wrong: `"amount"` (blend heading toward character-forward),+`"level_face"` + `"level_target_deg"` (put the face at a fixed elevation+by closed loop on the rig).++`qa_clip.py` audits the result: it flags a head locked to the chest+(gaze-vs-chest std < 2°, the signature of an estimator that isn't+emitting real head orientation) and a head staring upward (mean+elevation > 12°).+**Smoothing eats strikes.** A `smooth` window wide enough to calm afast flurry (9 frames) also averages away its extension peaks — thepunches get visibly shorter. Keep flurry windows narrow (5) anddiff --git a/docs/PITFALLS.md b/docs/PITFALLS.mdindex a90ef11..ed71c96 100644--- a/docs/PITFALLS.md+++ b/docs/PITFALLS.md@@ -81,14 +81,20 @@ touching a clip a human has partially signed off.exactly this reason; anything else that renders the scene must dothe same.-17. **Gaze is the FACE axis (head local +Z), not the skull axis.** The- FK apply only aims the skull axis (+Y), so face pitch is whatever- the torso lean leaves — a head can read "vertical" while looking- 20–27° at the sky, and a metric built on +Y will confirm the wrong- thing. Measure `(matrix_world @ pb.matrix).to_3x3() @ (0,0,1)` and- take `asin(z)`. Fix with `head_look.level_face` (closed loop on the- rig); hand-guessed pitch angles cannot track a varying lean, and a- gaze correction written into the head *joint* never reaches the bone.+17. **Head orientation must come from the estimator, or the gaze is a+ lie.** Joint positions cannot describe where a head looks (the head+ joint sits inside the skull), so face landmarks must be read from+ real mesh vertices — synthesizing nose/ears from the torso basis+ makes the ear line *identical* to the shoulder line and locks the+ character's gaze to its chest for the whole clip. Symptoms: the head+ swings wide whenever the body twists, and "head vs chest yaw"+ measures exactly 0.000 at every frame — a number too clean to be+ real. Compounding it: the FK apply aims only the skull axis (+Y), so+ the FACE axis (head local +Z) inherits torso lean and yaw. Fix at+ the source (estimator emits `gaze`), orient the head to it in the+ apply, and let `qa_clip.py` flag a chest-locked head (gaze-vs-chest+ std < 2°) and sky-staring (mean elevation > 12°). Three passes were+ burned "fixing" this downstream before the estimator was suspected.18. **Smoothing eats strikes.** A `smooth` window wide enough to calm afast flurry (9 frames) also averages away its extension peaks —punches visibly shrink. Keep flurry windows narrow (5) and restorediff --git a/pipeline/apply_mixamo_fk.py b/pipeline/apply_mixamo_fk.pyindex 5138271..6c4a34a 100644--- a/pipeline/apply_mixamo_fk.py+++ b/pipeline/apply_mixamo_fk.py@@ -255,22 +255,15 @@ def apply_fingers(arm, amount: float) -> None:pb.location = Vector((0.0, 0.0, 0.0))-def _face_elev(arm, pb) -> float:- """Elevation of a head bone's FACE axis above the horizon, radians."""+def _face_dir(arm, pb) -> Vector:bpy.context.view_layer.update()- face = ((arm.matrix_world @ pb.matrix).to_3x3() @ Vector((0.0, 0.0, 1.0))).normalized()- return math.asin(max(-1.0, min(1.0, face.z)))+ return ((arm.matrix_world @ pb.matrix).to_3x3() @ Vector((0.0, 0.0, 1.0))).normalized()-def _pitch_head(arm, pb, delta: float) -> None:- """Rotate a head bone by `delta` about the world-horizontal axis- perpendicular to its face direction."""- world3 = (arm.matrix_world @ pb.matrix).to_3x3()- lateral = (world3 @ Vector((1.0, 0.0, 0.0)))- lateral.z = 0.0- if lateral.length < 1e-5:+def _rotate_bone(arm, pb, axis_world: Vector, delta: float) -> None:+ if abs(delta) < 1e-5 or axis_world.length < 1e-6:return- axis_arm = dir_to_arm(arm, lateral.normalized())+ axis_arm = dir_to_arm(arm, axis_world.normalized())head = pb.matrix.to_translation()mat = Quaternion(axis_arm, delta).to_matrix().to_4x4() @ pb.matrix.to_3x3().to_4x4()mat.translation = head@@ -282,38 +275,64 @@ def _pitch_head(arm, pb, delta: float) -> None:bpy.context.view_layer.update()-def level_face(arm, name: str, amount: float, target_deg: float = 0.0) -> None:- """Put a head bone's FACE axis at `target_deg` above the horizon,- by `amount` (0..1). Self-calibrating.-- The face direction on a mixamorig head is the bone's local +Z (at- rest, world -Y = character forward); +Y runs up the skull. The FK- apply only aims +Y, so the face ends up pitched by whatever the- torso is doing — a head can look at the sky while the skull axis- reads vertical. Rather than assume a rotation sign in the head's- (heavily yawed) frame, this probes the response with a small test- rotation, solves for the exact correction, and refines once.- """- if amount <= 1e-4:- return- pb = arm.pose.bones[name]- target = math.radians(target_deg)- e0 = _face_elev(arm, pb)+def _solve_axis(arm, pb, axis_world: Vector, measure, target: float, amount: float) -> None:+ """Probe-solve-refine one rotation axis. The head's frame is heavily+ yawed during spins, so the sign of a correction cannot be assumed."""+ e0 = measure()want = (target - e0) * amountif abs(want) < 1e-4:returnprobe = math.copysign(0.05, want)- _pitch_head(arm, pb, probe)- e1 = _face_elev(arm, pb)+ _rotate_bone(arm, pb, axis_world, probe)+ e1 = measure()slope = (e1 - e0) / probe- if abs(slope) < 0.1: # unresponsive axis: undo and bail- _pitch_head(arm, pb, -probe)+ if abs(slope) < 0.1:+ _rotate_bone(arm, pb, axis_world, -probe)return- _pitch_head(arm, pb, ((target - e1) * amount) / slope)- e2 = _face_elev(arm, pb) # one refinement pass- resid = (target - e2) * amount+ _rotate_bone(arm, pb, axis_world, ((target - e1) * amount) / slope)+ resid = (target - measure()) * amountif abs(resid) > math.radians(0.5):- _pitch_head(arm, pb, resid / slope)+ _rotate_bone(arm, pb, axis_world, resid / slope)+++def orient_face(arm, name: str, gaze, amount: float, max_offset_deg: float = 75.0,+ body_forward: Vector | None = None) -> None:+ """Point a head bone's FACE axis along `gaze` (world direction).++ The FK apply aims only the skull axis (+Y), leaving the face's yaw+ and pitch to whatever the torso is doing — a head that follows its+ chest through every twist. The estimator's real gaze fixes that.+ `max_offset_deg` keeps the neck anatomically sane when the body is+ turned far from where the head looks.+ """+ if amount <= 1e-4 or gaze is None:+ return+ g = Vector((float(gaze[0]), float(gaze[1]), float(gaze[2])))+ if g.length < 1e-6:+ return+ g.normalize()+ pb = arm.pose.bones[name]+ if body_forward is not None and body_forward.length > 1e-6:+ bf = Vector((body_forward.x, body_forward.y, 0.0))+ gf = Vector((g.x, g.y, 0.0))+ if bf.length > 1e-6 and gf.length > 1e-6:+ bf.normalize()+ gf.normalize()+ off = math.atan2(bf.x * gf.y - bf.y * gf.x, bf.x * gf.x + bf.y * gf.y)+ lim = math.radians(max_offset_deg)+ if abs(off) > lim:+ clamped = math.copysign(lim, off)+ q = Quaternion(Vector((0.0, 0.0, 1.0)), clamped - off)+ g = q @ g+ # Yaw about world up, then pitch about the horizontal axis across the gaze.+ tgt_yaw = math.atan2(g.x, -g.y)+ _solve_axis(arm, pb, Vector((0.0, 0.0, 1.0)),+ lambda: math.atan2(_face_dir(arm, pb).x, -_face_dir(arm, pb).y),+ tgt_yaw, amount)+ lateral = Vector((-g.y, g.x, 0.0))+ _solve_axis(arm, pb, lateral,+ lambda: math.asin(max(-1.0, min(1.0, _face_dir(arm, pb).z))),+ math.asin(max(-1.0, min(1.0, g.z))), amount)def ensure_action(arm, name: str, end: int):@@ -456,8 +475,10 @@ def run(spec_path: str) -> dict:aim_bone(arm, bone, neck_p + aim)else:aim_bone(arm, bone, v(fr[key]))- level_face(arm, "mixamorig:Head", float(fr.get("head_level", 0.0) or 0.0),- float(fr.get("head_level_target_deg", 0.0) or 0.0))+ orient_face(arm, "mixamorig:Head", fr.get("gaze"),+ float(fr.get("gaze_amount", 0.0) or 0.0),+ float(spec.get("gaze_max_offset_deg", 75.0)),+ -v(fr["basis_y"]))apply_fingers(arm, fist)if rest >= 0.65:@@ -581,7 +602,15 @@ def dump_curves(spec_path: str) -> dict:"rotation_quaternion": [round(v, 6) for v in pb.rotation_quaternion],"world_location": [round(wl.x, 6), round(wl.y, 6), round(wl.z, 6)],}- out.append({"frame": f, "bones": bones})+ # Gaze audit data: the head's FACE axis and the body's forward, in+ # world. Positions alone cannot reveal where a character looks.+ face = ((arm.matrix_world @ arm.pose.bones["mixamorig:Head"].matrix).to_3x3()+ @ Vector((0.0, 0.0, 1.0))).normalized()+ fwd = ((arm.matrix_world @ arm.pose.bones["mixamorig:Hips"].matrix).to_3x3()+ @ Vector((0.0, 0.0, 1.0))).normalized()+ out.append({"frame": f, "bones": bones,+ "face_dir": [round(face.x, 5), round(face.y, 5), round(face.z, 5)],+ "body_forward": [round(fwd.x, 5), round(fwd.y, 5), round(fwd.z, 5)]})clip_dir = rpath(spec["clip_dir"])(clip_dir / "curves.json").write_text(json.dumps({"frames": out}), encoding="utf-8")return {"curves_frames": len(out)}diff --git a/pipeline/estimate_pose_gvhmr.py b/pipeline/estimate_pose_gvhmr.pyindex fb03050..faad3db 100644--- a/pipeline/estimate_pose_gvhmr.py+++ b/pipeline/estimate_pose_gvhmr.py@@ -20,9 +20,13 @@ Run with the GVHMR venv (see docs/INSTALL.md), from anywhere:Joints come from the SMPL 24-joint regressor applied to the predictedmesh (same path as GVHMR's own render_global): SMPL-X verts ->-smplx2smpl_sparse -> J_regressor. Landmarks MediaPipe has but SMPL does-not (nose, heels, hand points, face) are synthesized from the torso-basis — the lift only uses them for direction hints, not geometry.+smplx2smpl_sparse -> J_regressor. The face landmarks (nose, eyes, ears)+are read from real mesh vertices, and each frame carries a `gaze` unit+vector (nose vs ear midpoint) — head orientation is NOT recoverable+from joint positions, and synthesizing those points from the torso+basis silently locks the retargeted character's gaze to its chest.+The remaining extras (heels, hand points) are approximated; the lift+uses them for direction hints, not geometry.GVHMR gives real depth, plausible proportions and no per-frame Zspikes; it still does not know Mixamo bone lengths and will not plant@@ -78,6 +82,14 @@ J = {"l_wrist": 20, "r_wrist": 21, "l_hand": 22, "r_hand": 23,}+# SMPL topology vertex ids for the face. The head's ORIENTATION is not+# recoverable from joint positions (the head joint sits inside the+# skull), so the nose/eye/ear landmarks — and the gaze vector — are read+# from the mesh itself. Synthesizing them from the torso basis, as an+# earlier version did, silently locks the character's gaze to its chest.+FACE_VERTS = {"nose": 332, "left_eye": 2800, "right_eye": 6260,+ "left_ear": 583, "right_ear": 4071}+BODY_MODELS = GVHMR_ROOT / "inputs/checkpoints/body_models"CHECKPOINTS = {"gvhmr": GVHMR_ROOT / "inputs/checkpoints/gvhmr/gvhmr_siga24_release.ckpt",@@ -196,25 +208,33 @@ def smpl_joints(pred: dict) -> tuple[np.ndarray, np.ndarray, np.ndarray]:smplx2smpl = torch.load(GVHMR_ROOT / "hmr4d/utils/body_model/smplx2smpl_sparse.pt").cuda()J_regressor = torch.load(GVHMR_ROOT / "hmr4d/utils/body_model/smpl_neutral_J_regressor.pt").cuda()- def joints_of(params: dict) -> torch.Tensor:+ face_idx = torch.tensor(list(FACE_VERTS.values()))++ def joints_of(params: dict, want_face: bool = False):with torch.no_grad():verts = smplx(**to_cuda(params)).vertices # (L, Vx, 3)verts = torch.stack([torch.matmul(smplx2smpl, v) for v in verts]) # (L, 6890, 3)- return einsum(J_regressor, verts, "j v, l v i -> l j i") # (L, 24, 3)+ joints = einsum(J_regressor, verts, "j v, l v i -> l j i") # (L, 24, 3)+ if want_face:+ return joints, verts[:, face_idx.to(verts.device)] # (L, 5, 3)+ return joints- joints_ay = joints_of(pred["smpl_params_global"])+ joints_ay, face_ay = joints_of(pred["smpl_params_global"], want_face=True)# Same normalization as GVHMR render_global: frame-0 pelvis to the# origin (XZ), ground to y=0, then rotate so frame 0 faces +z.offset = joints_ay[0, J["pelvis"]].clone()offset[1] = joints_ay[:, :, 1].min()joints_ay = joints_ay - offset+ face_ay = face_ay - offsetT_ay2ayfz = compute_T_ayfz2ay(joints_ay[[0]], inverse=True)joints_ayfz = apply_T_on_points(joints_ay, T_ay2ayfz)+ face_ayfz = apply_T_on_points(face_ay, T_ay2ayfz)- joints_incam = joints_of(pred["smpl_params_incam"])+ joints_incam, face_incam = joints_of(pred["smpl_params_incam"], want_face=True)K = pred["K_fullimg"][0].cpu().numpy()- return joints_ayfz.cpu().numpy(), joints_incam.cpu().numpy(), K+ return (joints_ayfz.cpu().numpy(), joints_incam.cpu().numpy(), K,+ face_ayfz.cpu().numpy(), face_incam.cpu().numpy())# ---------------------------------------------------------------------------@@ -231,8 +251,13 @@ def ayfz_to_mp(p: np.ndarray) -> np.ndarray:return out-def mp33_from_smpl(j: np.ndarray) -> dict[str, np.ndarray]:- """j: (24, 3) one frame, any right-handed y-down frame. Returns 33 pts."""+def mp33_from_smpl(j: np.ndarray, face: np.ndarray | None = None) -> dict[str, np.ndarray]:+ """j: (24, 3) one frame, any right-handed y-down frame. Returns 33 pts.++ `face`: (5, 3) real mesh landmarks (nose, l_eye, r_eye, l_ear, r_ear)+ in the same frame. Without them the face points are approximated from+ the torso basis and all head-orientation information is lost.+ """def g(name):return j[J[name]]@@ -269,15 +294,24 @@ def mp33_from_smpl(j: np.ndarray) -> dict[str, np.ndarray]:rh = hand_pts(g("r_wrist"), g("r_elbow"), "r")l_heel = heel_of(g("l_ankle"), g("l_foot"))r_heel = heel_of(g("r_ankle"), g("r_foot"))- nose = head + fwd * 0.09- eye_l = head + fwd * 0.07 + left * 0.03 - up * (-0.02)- eye_r = head + fwd * 0.07 - left * 0.03 - up * (-0.02)+ if face is not None:+ nose, eye_l, eye_r, ear_l, ear_r = (face[0], face[1], face[2], face[3], face[4])+ # The mesh's left/right follow SMPL topology; orient them to this+ # skeleton's left so the landmark names stay honest.+ if np.dot(ear_l - ear_r, left) < 0:+ eye_l, eye_r = eye_r, eye_l+ ear_l, ear_r = ear_r, ear_l+ else:+ nose = head + fwd * 0.09+ eye_l = head + fwd * 0.07 + left * 0.03 - up * (-0.02)+ eye_r = head + fwd * 0.07 - left * 0.03 - up * (-0.02)+ ear_l, ear_r = head + left * 0.07, head - left * 0.07return {"nose": nose,"left_eye_inner": eye_l - left * 0.01, "left_eye": eye_l, "left_eye_outer": eye_l + left * 0.01,"right_eye_inner": eye_r + left * 0.01, "right_eye": eye_r, "right_eye_outer": eye_r - left * 0.01,- "left_ear": head + left * 0.07, "right_ear": head - left * 0.07,+ "left_ear": ear_l, "right_ear": ear_r,"mouth_left": nose + left * 0.02 + up * (-0.03), "mouth_right": nose - left * 0.02 + up * (-0.03),"left_shoulder": ls, "right_shoulder": rs,"left_elbow": g("l_elbow"), "right_elbow": g("r_elbow"),@@ -319,7 +353,7 @@ def main() -> None:res = run_gvhmr(video)pred = res["pred"]- joints_ayfz, joints_incam, K = smpl_joints(pred)+ joints_ayfz, joints_incam, K, face_ayfz, face_incam = smpl_joints(pred)L = joints_ayfz.shape[0]cap = cv2.VideoCapture(str(video))@@ -328,11 +362,19 @@ def main() -> None:frames = []for i in range(L):- mp_world = mp33_from_smpl(ayfz_to_mp(joints_ayfz[i]))+ mp_world = mp33_from_smpl(ayfz_to_mp(joints_ayfz[i]), ayfz_to_mp(face_ayfz[i]))hip_mid = 0.5 * (mp_world["left_hip"] + mp_world["right_hip"])- mp_img = mp33_from_smpl(joints_incam[i]) # camera frame is already y-down+ mp_img = mp33_from_smpl(joints_incam[i], face_incam[i]) # camera frame is already y-down+ # Gaze: real face direction from the mesh (nose vs ear midpoint),+ # in the same convention as `world`. Without this the retarget can+ # only lock the head to the chest.+ ear_mid = 0.5 * (mp_world["left_ear"] + mp_world["right_ear"])+ gaze = mp_world["nose"] - ear_mid+ gn = float(np.linalg.norm(gaze)) or 1.0+ gaze = gaze / gnrec = {"frame": i + 1, "t": i / fps, "ok": True,"pelvis_height": round(float(-hip_mid[1]), 5),+ "gaze": [round(float(x), 5) for x in gaze],"image": {}, "world": {}}for n in MP_NAMES:w = mp_world[n] - hip_mid # per-frame mid-hip centereddiff --git a/pipeline/lift_to_mixamo.py b/pipeline/lift_to_mixamo.pyindex 6c0bd1a..4d052e9 100644--- a/pipeline/lift_to_mixamo.py+++ b/pipeline/lift_to_mixamo.py@@ -163,13 +163,17 @@ def load_mp(path: Path):world = {n: np.zeros((len(frames), 3)) for n in MP_USED}times = np.zeros(len(frames))pelvis_h = np.zeros(len(frames))+ gaze = np.zeros((len(frames), 3))for i, f in enumerate(frames):times[i] = f["t"]pelvis_h[i] = float(f.get("pelvis_height", 0.0))+ g = f.get("gaze")+ if g:+ gaze[i] = gfor n in MP_USED:w = f["world"][n]world[n][i] = (w["x"], w["y"], w["z"])- return data["fps"], times, world, pelvis_h+ return data["fps"], times, world, pelvis_h, gazedef resample(times, series, dst_times):@@ -336,7 +340,7 @@ def main():args = ap.parse_args()spec = json.loads(rpath(args.spec).read_text(encoding="utf-8"))- fps, times, world, pelvis_h = load_mp(rpath(spec["landmarks"]))+ fps, times, world, pelvis_h, gaze_src = load_mp(rpath(spec["landmarks"]))dst_fps = float(spec.get("dst_fps", 30))duration = float(times[-1])n_dst = int(round(duration * dst_fps)) + 1@@ -347,6 +351,15 @@ def main():if len(pelvis_h) >= 7:pelvis_h = savgol_filter(pelvis_h, 7, 2, mode="interp")pelvis_h = np.interp(dst_times, times, pelvis_h)+ # Real gaze direction (estimator frame) -> Mixamo world direction.+ # Without this the FK apply can only infer the head from the chest,+ # which locks the character's gaze to its torso twist.+ has_gaze = bool(np.abs(gaze_src).sum() > 1e-6)+ gaze_mix = np.zeros((n_dst, 3))+ if has_gaze:+ g = np.stack([np.interp(dst_times, times, gaze_src[:, c]) for c in range(3)], axis=1)+ g = np.stack([np.array([v[0], v[2], -v[1]]) for v in g]) # mp dir -> mixamo dir+ gaze_mix = np.stack([unit(v) for v in g])def src2dest(sf):return (sf - 1) * dst_fps / fps + 1@@ -463,6 +476,7 @@ def main():rec[f"{s}_hand"] = new_wrist + unit(new_wrist - elbow) * LEN[f"{s}_hand"]head_pitch_deg = 0.0+ gaze_amount = float(spec.get("gaze_follow", 1.0))head_level = 0.0head_level_target = 0.0# Windowed gaze correction (spec "head_look"): blend the head's@@ -500,6 +514,8 @@ def main():ang = np.radians(float(hl["pitch_deg"])) * winv = rodrigues(v, np.asarray(rec["basis_x"], float), ang)head_pitch_deg += float(hl["pitch_deg"]) * win+ if hl.get("follow_gaze") is not None:+ gaze_amount = float(hl["follow_gaze"]) * win + gaze_amount * (1.0 - win)if hl.get("level_face"):# Closed-loop: the apply measures the resulting face# elevation and levels it to `level_target_deg`.@@ -524,6 +540,8 @@ def main():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]),+ "gaze": gaze_mix[i] if has_gaze else None,+ "gaze_amount": (gaze_amount if has_gaze else 0.0),"head_pitch_deg": head_pitch_deg,"head_level": head_level,"head_level_target_deg": head_level_target})@@ -583,6 +601,9 @@ def main():out["fist_amount"] = round(float(ex["fist"]), 4)out["plant"] = ex["plant"]out["pelvis_height"] = round(float(ex["pelvis_height"]), 5)+ if ex["gaze"] is not None:+ out["gaze"] = [round(float(x), 5) for x in ex["gaze"]]+ out["gaze_amount"] = round(float(ex["gaze_amount"]), 4)out["head_pitch_deg"] = round(float(ex["head_pitch_deg"]), 3)out["head_level"] = round(float(ex["head_level"]), 4)out["head_level_target_deg"] = round(float(ex["head_level_target_deg"]), 2)diff --git a/pipeline/qa_clip.py b/pipeline/qa_clip.pyindex db6fb9f..0d7a164 100644--- a/pipeline/qa_clip.py+++ b/pipeline/qa_clip.py@@ -114,6 +114,26 @@ def main():tag = "OK" if d.max() < 0.30 else "WARN"print(f"[{tag}] max frame-jump {b.split(':')[1]}: {d.max():.3f} m @ f{int(d.argmax()) + 2}")+ # 7. Gaze. Where a character looks is invisible to every positional+ # check above: a head rigidly following its chest, or staring at+ # the sky, passes them all.+ if "face_dir" in frames[0]:+ face = np.array([f["face_dir"] for f in frames], dtype=float)+ body = np.array([f["body_forward"] for f in frames], dtype=float)+ fy = np.degrees(np.arctan2(face[:, 0], -face[:, 1]))+ by = np.degrees(np.arctan2(body[:, 0], -body[:, 1]))+ elev = np.degrees(np.arcsin(np.clip(face[:, 2], -1, 1)))+ off = (fy - by + 180.0) % 360.0 - 180.0+ locked = float(np.std(off)) < 2.0+ print(f"[{'WARN' if locked else 'OK'}] gaze vs chest: mean {off.mean():+.1f} deg, std {off.std():.1f}"+ + (" — head appears LOCKED to the chest (no independent head motion;"+ " is the estimator emitting a gaze?)" if locked else ""))+ print(f"[{'WARN' if elev.mean() > 12 else 'OK'}] gaze elevation: mean {elev.mean():+.1f} deg,"+ f" max |elev| {float(np.abs(elev).max()):.1f}"+ + (" (+ = looking up)" if elev.mean() > 12 else ""))+ else:+ print("[WARN] gaze: curves.json has no face_dir — re-dump curves to enable gaze checks")+print("\nverdict:", "PASS (visual review still required)" if ok else "HARD FAILURES — fix before showing")