Skip to content

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.

docs: two-character mocap, the clearance problem, the review pass

Sacha1bfc0ab76a08
diff --git a/README.md b/README.md
index 33bae3f..a89e080 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
# Mixamo LLM Mocap
**Turn any locked-camera video — filmed or AI-generated — into a clean
-FK animation on any Mixamo character. No mocap suit, no manual
-keyframing, and every stage scriptable enough that an AI agent can run
-the whole loop.**
+FK animation on any Mixamo character. One performer, or two fighting
+each other. No mocap suit, no manual keyframing, and every stage
+scriptable enough that an AI agent can run the whole loop.**
![license](https://img.shields.io/badge/license-MIT-green)
![blender](https://img.shields.io/badge/Blender-5.1%2B-orange)
@@ -28,9 +28,17 @@ video plate (locked camera, T-pose bookends)
├─ 5. apply_mixamo_fk.py FK aim + foot planting, inside live Blender (via Blender MCP)
├─ 6. qa_clip.py automated gate: no explosions, no pops, no foot skate
├─ 7. compare_reference.py frame-by-frame vs the video → which windows still differ
- └─ 8. render_preview.py preview + side-by-side showcase video
+ ├─ 8. compare_pair.py two-character plates: separation, reach, intrusion
+ ├─ 9. run_in_blender.py contact real mesh-vs-mesh collision between two characters
+ └─ 10. render_preview.py preview + side-by-side showcase video
```
+With two performers in the plate, stages 1–7 run once per fighter
+(`--person left|right` splits the tracks), `setup_duo.py` builds one
+scene holding both characters, and `compare_pair.py` checks what only
+exists when there are two of them: whether they stand, reach and miss
+each other the way the performers did.
+
The estimator provides mesh-quality joints; the lift keeps its segment
*directions* but rebuilds every position from your character's measured
bone lengths; the apply plants feet by solving hip height (never IK —
@@ -45,8 +53,9 @@ airborne beats), when fists close, where the clip locks back to rest.
(rest pose, bone lengths, hip and ground heights). Every stage reads
that profile.
- **Motions are data, not code.** A new motion is a small JSON spec —
- the three `action_specs/` here (a kung-fu form, a combo with a jump,
- a fight combination) are worked examples of the whole schema.
+ the `action_specs/` here (a kung-fu form, a combo with a jump, a
+ fight combination, a 360° jumping spin kick and a two-fighter duel)
+ are worked examples of the whole schema.
- **Honest Mixamo FK.** Hips are the only translating bone, everything
else is quaternions at 30 fps — clips drop into any Mixamo-style
workflow without cleanup.
@@ -63,6 +72,25 @@ airborne beats), when fists close, where the clip locks back to rest.
exact frame windows that diverge. Notes like *"his hands are too high
and his arm clips his back"* become numbers, and an over-correction
gets caught before it ships instead of after.
+- **Two characters, one scene.** A two-performer plate is split into
+ tracks by which side of frame each occupies — robust where tracker
+ ids swap on contact — retargeted onto two different Mixamo characters
+ with their own measured proportions, and placed at the distance the
+ performers actually stood, recovered from the footage rather than
+ eyeballed. `compare_pair.py` then verifies separation, strike reach
+ and limb intrusion against the video, frame by frame, and a Blender
+ BVH pass checks the actual skinned meshes for collision — because two
+ Mixamo characters are thicker than two humans, and a choreography
+ built out of 2 cm near-misses collides when you retarget it faithfully.
+ Clearance is bought from the stage with a declared, measured offset,
+ which the comparator keeps reporting so the cost stays visible.
+- **A review pass that is part of the loop.** Render the showcase,
+ put source and retarget side by side at the same beat, name what
+ looks wrong in one sentence, then measure it. When eye and numbers
+ disagree it is usually the numbers — every false reading in this
+ project came from a mismatched proxy (a nose against a skull-base
+ joint, a capsule against a mesh). [docs/PIPELINE.md](docs/PIPELINE.md)
+ section 10.
- **Written for agents.** Beat decisions come from
`analyze_landmarks.py` numbers (never from eyeballing frames), every
stage is a CLI or a socket call, and `docs/PITFALLS.md` encodes every
@@ -96,6 +124,10 @@ airborne beats), when fists close, where the clip locks back to rest.
from the video; the last command produces `preview.mp4` and the
side-by-side `showcase.mp4` — the same format as the demo GIF above.
+ Two-performer plates add `--person left|right` to the estimate, one
+ spec per fighter, and a `compare_pair.py` run — see
+ [docs/PIPELINE.md](docs/PIPELINE.md) section 9.
+
4. **Iterate** with [docs/PIPELINE.md](docs/PIPELINE.md) and
[docs/PITFALLS.md](docs/PITFALLS.md).
diff --git a/docs/PIPELINE.md b/docs/PIPELINE.md
index f2179b2..df5f453 100644
--- a/docs/PIPELINE.md
+++ b/docs/PIPELINE.md
@@ -308,3 +308,247 @@ clip. The human eye is the last word.**
- When the estimator and the human's read of the video disagree, the
human is right (occlusion, foreshortening) — encode the fix as an
`arm_override`, don't fight the estimator globally.
+
+---
+
+## 9. Two characters in one scene
+
+A multi-performer plate is not "run the pipeline twice". Two
+individually perfect retargets still fail if the characters stand at
+the wrong distance — every punch swings through empty air, or a fist
+ends up inside a skull. What changes:
+
+### 9.1 Estimate each performer separately
+
+```
+... estimate_pose_gvhmr.py --video plates\duel\duel.mp4 --person left --out plates\duel\landmarks_grey.json
+... estimate_pose_gvhmr.py --video plates\duel\duel.mp4 --person right --out plates\duel\landmarks_white.json
+```
+
+`--person left|right|<index>` selects a performer by **which side of
+frame they occupy**, not by tracker id. Ids swap when two bodies touch,
+and a swap splices half of each performer into one "track"; screen side
+is a fact as long as the plate never lets them cross — which is why the
+plate contract forbids it (docs/PROMPTING.md). Caches are per person,
+so the two runs do not fight over the same preprocessing.
+
+Each landmarks file then carries, besides the solo fields, `root`
+(ground trajectory, gravity-aligned frame), `incam_root` and `incam`
+(pelvis and all 33 landmarks in CAMERA space).
+
+### 9.2 Build one scene with both characters
+
+```
+blender --background --python pipeline\setup_duo.py -- ^
+ --char YBot=ybot.fbx --char Ninja=ninja_rest.blend --out duel_rest.blend
+```
+
+Each character gets `Armature_<Name>` and its own
+`rig_profiles/<name>.json`. Two characters do **not** share a hip
+height — planting the Ninja at the Y Bot's ground offset buries its
+feet — so every stage now takes the profile from the spec.
+
+Both armature objects stay at the origin. Stage placement is baked into
+the animation instead (`stage_x`), because the FK apply aims bones in
+armature space and a translated armature object would silently offset
+every aim target (docs/RIG.md).
+
+### 9.3 Spec fields a paired clip adds
+
+```jsonc
+{
+ "armature": "Armature_YBot", // which character in the scene
+ "rig_profile": "rig_profiles/ybot.json", // its measured proportions
+
+ "root_motion": true, // keep the performer's travel (see below)
+ "root_source": "incam", // "incam" (default) or "global"
+ "root_depth": false, // include the depth axis too (default: lateral only)
+ "stage_x": -0.943, // where this character stands
+ "root_scale": 0.9715, // ONE stage, ONE scale — shared by both fighters
+
+ "prefilter_window": 5 // landmark prefilter width, source frames (default 7)
+}
+```
+
+**Root motion.** Solo clips are retargeted in place — Mixamo convention
+and correct, since the estimator's landmarks are hip-centred every
+frame anyway. Two fighters are the opposite case: the distance between
+them *is* the scene. On the duel plate the attacker closed 1.95 m →
+0.88 m and back out again; in place, every punch lands a metre short.
+
+Two estimates of that travel exist and they disagree. `global` is the
+gravity-aligned world trajectory: physically consistent but *predicted*,
+and it drifts (it under-reported that 0.92 m step-in as 0.68 m and left
+the performer 0.16 m off his mark at the closing T-pose). `incam` is
+tied to what the camera saw and tracked an independent image-space
+measurement to within 2 cm across all 241 frames — so it is the
+default. Only its lateral component is used; depth is the
+ill-conditioned axis of a single-camera fit.
+
+Pinning is skipped when `root_motion` is on. The foot skate it corrects
+is an artefact of *discarding* the travel; restore the travel and the
+artefact is gone at the source, while re-pinning on top would cancel
+each step inside its own stance and snap it back on release.
+
+**Sizing the stage.** Measure the performers' separation at the T-pose
+from `incam_root`, scale it by the shared stage scale, and split it
+either side of the origin. Then verify with `compare_pair.py` rather
+than trusting the arithmetic.
+
+### 9.4 `leg_pose` — the leg's `arm_pose`
+
+```jsonc
+"leg_pose": [
+ { "src": [142, 150], "ramp_src": 3, "side": "right", "lift_m": 0.18 }
+]
+```
+
+Rotates a whole leg rigidly about its hip socket so the foot rises (or
+drops) by a measured amount, solved per frame. The axis is the
+horizontal one perpendicular to the leg itself — a roundhouse and a
+front kick travel in different planes, and a fixed lateral axis would
+skew one of them sideways.
+
+It exists because the estimator's gravity-aligned pose and its
+in-camera pose disagree about a fast limb at its peak, and the retarget
+must follow the gravity-aligned one (that is what makes feet plant). On
+a head-high roundhouse that showed as a shin ~9° low, dropping the foot
+0.15 m — putting it *through* the ducking defender instead of over him.
+Size it from `compare_pair.py`, never by eye.
+
+### 9.5 Render and check the pair
+
+```
+... render_preview.py action_specs\duel_ybot.json --also action_specs\duel_ninja.json ^
+ --out-dir clips\duel --showcase --social
+... compare_pair.py --spec action_specs\duel_ybot.json --spec action_specs\duel_ninja.json
+```
+
+`--also` binds every character's action before rendering (otherwise one
+fighter renders frozen in its T-pose while the other fights it) and
+frames the camera from the dumped curves so both stay in shot.
+
+`compare_pair.py` measures the three things neither `qa_clip.py` nor
+`compare_reference.py` can see:
+
+| Check | What it catches |
+|---|---|
+| separation | the pair standing too far apart / too close, per frame |
+| reach | a strike that stops short of, or drives past, where it landed in the video |
+| intrusion | a limb *inside* the other character — absolute, no reference needed |
+
+It reads both performers in the **camera** frame, re-expressed in a
+gravity-aligned basis solved from the data (docs/PITFALLS.md #26–27),
+and tests whole limb SEGMENTS, not endpoints.
+
+Run all three: `qa_clip` per character (is it broken?),
+`compare_reference` per character (does it look like its performer?),
+`compare_pair` once (do the two relate like the two performers did?).
+
+### 9.6 Clearance — the part that has no solo equivalent
+
+Two individually faithful retargets can still be wrong on screen,
+because **two Mixamo characters are not two humans**. Their limbs,
+heads and hands are thicker, and a fight choreography is built out of
+near-misses. On the duel plate the attacker's roundhouse passes the
+defender's guard hand 0.111 m centre-to-centre; with real forearms that
+is a 2 cm miss, and with these characters' meshes it is a collision.
+The retarget reproduced that 0.111 m to the centimetre and was
+*therefore* wrong.
+
+**Measure it on the meshes.** The capsule proxies in `compare_pair.py`
+are right about separation and reach and optimistic about contact — they
+scored this kick as clearing by 4 mm while the meshes intersected over
+230 face pairs. Ground truth is the evaluated, skinned geometry:
+
+```
+python pipeline\run_in_blender.py contact action_specs\duel_ybot.json ^
+ --with action_specs\duel_ninja.json
+```
+
+BVH overlap between the two characters, every frame, written to
+`<clip_dir>/../pair_contact.json`: intersecting face-pair counts, and
+the surface-to-surface gap where they do not intersect. Run it over the
+WHOLE clip — restricting it to the beat under repair is how four other
+intersections survived two passes here, one of them in the closing
+T-pose.
+
+**Then separate intended contact from unintended.** Punches landing on
+a block *should* touch; two rigid hands cannot deform, so those frames
+show deep overlap and that is the strike landing. Ask what the source
+video does at that frame.
+
+**Buy the clearance from the stage, not the poses.** Every pose lever
+was tried on this collision and each one moved the problem elsewhere:
+raising the kick swept the foot through the guard hand, lowering the
+defender dropped his hands into the rising foot, curling his spine swung
+his arms forward, leaning him away lifted his head into the arc. Only
+distance helped every frame at once. Requirements that flip between
+adjacent frames are the signature of a graze no pose fix can satisfy.
+
+```jsonc
+"root_offset": [
+ { "src": [116, 185], "ramp_src": 23, "dx": -0.20 }, // room for the kick
+ { "src": [186, 241], "ramp_src": 18, "dx": -0.07 } // room for the bind
+]
+```
+
+A windowed, ramped shift of one character's ground trajectory. Two
+rules: ramp it across frames where that character is **already
+travelling** (0.20 m applied under a planted foot is 0.20 m of skate —
+here it rides the 0.24 m retreat he already makes between the punches
+and the kick), and **declare it**, so `compare_pair.py` prints
+`[declared root_offset]` next to the separation it causes instead of
+reporting it as an unexplained defect. The cost stays visible.
+
+The second window above is a different instance of the same physics:
+these characters' arms are ~4% longer relative to their legs than the
+performers', so at a leg-scaled stage separation their fingertips cross
+while the arms swing out into the closing T-pose. The settled T-poses
+were always clear (0.09–0.13 m); only the spread collided.
+
+### 9.7 Order of operations for a paired clip
+
+1. Estimate both performers, write both beat sheets.
+2. Size the stage from `incam_root` at the T-pose; lift and apply both.
+3. `qa_clip` each — is either clip broken?
+4. `compare_reference` each — does each look like its performer?
+5. `compare_pair` — do the two relate like the performers did?
+6. `run_in_blender.py contact` over the whole clip — do the meshes
+ actually touch?
+7. Only now reach for clearance, and only for contacts the video does
+ not have.
+
+Steps 3–6 answer different questions and none of them substitutes for
+another. Step 6 is the one that agrees with a human watching the video.
+
+## 10. The review pass (do not skip this)
+
+Every defect that mattered in this project was found by putting the
+source frame and the retargeted frame **side by side at the same beat
+and looking at them**, then measuring what the eye flagged. Numbers
+alone shipped a foot through a head; an eye alone could not say by how
+much or why. The loop is:
+
+1. Render the showcase (`render_preview.py --showcase`).
+2. Pull paired crops at the beat frames — source left, retarget right,
+ labelled with the source AND destination frame number. A contact
+ sheet every ~10 frames for the whole clip, then a tight crop on any
+ beat that looks wrong.
+3. Name what looks wrong in one sentence, in body terms ("the foot goes
+ through his head", "his guard is too narrow").
+4. Turn that sentence into a measurement, and only then edit a spec.
+
+**When your eye and your numbers disagree, one of them is measuring the
+wrong thing — and it is usually the numbers.** Every time it happened
+here the cause was a mismatched proxy: a nose compared to a skull-base
+joint, a shoulder line to a Neck joint, limb endpoints instead of whole
+segments, a capsule instead of the mesh. Before trusting a number,
+name the anatomical point on both sides and check they are the same
+one. Before dismissing what a human saw, assume the model is wrong.
+
+This is the whole reason `compare_reference.py`, `compare_pair.py` and
+the `contact` stage exist: they turn "his arm clips his back" into a
+frame window and a distance in metres, so the fix can be sized instead
+of guessed — and so an over-correction is caught on the next run
+instead of after it ships.
diff --git a/docs/PITFALLS.md b/docs/PITFALLS.md
index e64df56..e826cad 100644
--- a/docs/PITFALLS.md
+++ b/docs/PITFALLS.md
@@ -137,3 +137,114 @@ touching a clip a human has partially signed off.
25. **QA passing ≠ done.** Numbers catch explosions, pops, skate and
drift; they cannot see a wrong silhouette. Play the clip, read the
stills, ask the human.
+
+## Two characters in one scene
+
+26. **Two performers cannot be compared in the estimator's `world`
+ frame.** Each one is normalised so that *their own* frame-0 facing
+ becomes forward, so two performers arrive in two frames that differ
+ by however much their opening yaws differed. Composing their limbs
+ onto a shared root looks reasonable and is quietly wrong: it put a
+ kicking foot 0.18 m from the other fighter's skull when the video
+ and an independent image-space measurement both said 0.29 m — the
+ difference between a clean miss and a foot through a head. Anything
+ that measures two people against each other must read the CAMERA
+ frame (`incam`), the only frame they actually share.
+27. **The camera frame's "up" is not gravity.** Heights read straight
+ out of camera space carry the camera's pitch — 4.2° on the duel
+ plate, which inflated a head-high kick's peak by 0.14 m and
+ manufactured a "the kick is too low" finding that did not exist.
+ The estimator emits both a gravity-aligned frame and a camera frame;
+ fit the rotation between them and push the world's up axis through
+ it, then measure in that.
+28. **The world-frame root trajectory drifts; the in-camera one does
+ not.** Both describe where the performer stood. Measured on the same
+ plate: the gravity-aligned global root under-reported a 0.92 m
+ step-in as 0.68 m and left the performer 0.16 m off his mark at the
+ closing T-pose, while the in-camera root tracked an independent
+ image-space measurement (hip pixels ÷ body pixels) to within 2 cm on
+ all 241 frames. Drive `root_motion` from `incam`, and trust only its
+ lateral component — depth is the ill-conditioned axis of a
+ single-camera fit, and one deep crouch moved it 0.22 m in a frame.
+29. **Matched proxies, or the comparison is fiction.** Three separate
+ false findings in one session, all from comparing a quantity to a
+ different quantity: a performer's *nose* against a character's Head
+ bone (which sits at the skull base, ~10 cm behind the face); a
+ reference *shoulder line* against `mixamorig:Neck` (5–10 cm higher,
+ so the torso capsule reached out and "caught" limbs that missed);
+ and limb ENDPOINTS instead of whole segments (a shin can pass
+ straight through a skull with both its knee and its toe outside).
+ Before believing any cross-domain number, name the anatomical point
+ on both sides and check they are the same one.
+30. **In-place is a solo assumption.** Mixamo clips are in-place by
+ convention and every solo plate here is retargeted that way. Two
+ fighters are the opposite case: the distance between them IS the
+ scene. On the duel plate the attacker closed 1.95 m → 0.88 m and
+ back; in place, every punch lands a metre short of the other
+ character. One stage, one scale — the initial separation and both
+ performers' travel must share a scale factor or the geometry never
+ closes.
+31. **Flattening the toe direction is right for a planted foot and
+ wrong for a kicking one.** The lift used to project heel→toe onto
+ the ground plane, which drags a foot pointed 40° up back to
+ horizontal: the toe drops and is thrown forward into whatever the
+ foot is aimed at. Grounded feet do not need it — the FK apply
+ re-aims anything below 0.20 m along its own heading anyway.
+32. **The landmark prefilter eats strikes too.** PITFALL #18 is about
+ the spec's `smooth` windows; the same thing happens one stage
+ earlier in the lift's default 7-frame Savitzky-Golay prefilter. On a
+ roundhouse peaking over ~6 source frames it cost 5° of shin angle
+ (0.04 m of foot height). `prefilter_window: 5` costs 1.4°.
+33. **Capsule proxies are optimistic; only the MESHES decide.** The
+ cheap collision model in `compare_pair.py` (a 0.16 m torso cylinder,
+ a 0.11 m head sphere) runs outside Blender and is right about
+ separation and reach. It is *not* the character's silhouette: a
+ hood, a shoulder, a glove and a boot all live outside those
+ surfaces. On the duel plate it scored a kick as clearing by 4 mm
+ while the actual meshes intersected across 4 frames with up to 230
+ overlapping face pairs — visible as a foot through a head. If a
+ human says two characters touch and your numbers say otherwise,
+ the numbers are measuring the wrong thing. Run
+ `run_in_blender.py contact` (BVH overlap on the evaluated, skinned
+ meshes) before believing any clearance.
+34. **Check the WHOLE clip, not the beat you are working on.** Chasing
+ the kick, the mesh check was run over frames 165–205 and reported
+ it clean. Run over all 301 it found four more intersections nobody
+ had looked at — including one at the closing T-pose, in a part of
+ the clip that had been "finished" for two passes.
+35. **A faithful retarget of two people can still be impossible.** Two
+ Mixamo characters are not two humans: their limbs, heads and hands
+ are thicker. The duel plate's roundhouse clears the defender's
+ guard hand by 0.111 m centre-to-centre — with real forearms that is
+ a 2 cm miss, and with these characters' meshes it is a collision.
+ The retarget reproduced that 0.111 m to the centimetre and was
+ *therefore* wrong on screen. When geometry and fidelity conflict,
+ fidelity loses: the showcase has to read clean. Buy the clearance
+ with the smallest measured departure, declare it in the spec, and
+ let the comparator keep reporting it (it prints
+ `[declared root_offset]`) so the cost stays visible instead of
+ becoming folklore.
+36. **Clearance must come from the stage, not from the poses.** Every
+ pose-level lever was tried on this collision and each one moved the
+ problem: raising the kick swept the foot through the guard hand;
+ lowering the defender dropped his hands into the rising foot;
+ curling his spine swung his arms forward into it; leaning him away
+ lifted his head into the arc; tucking his chin did nothing because
+ the contact was his shoulder. Only distance helped every frame at
+ once. Requirements that flip between ADJACENT frames (dest 180
+ wanted the foot lower, dest 181 wanted it higher) are the signature
+ of a grazing contact that no single pose correction can satisfy.
+37. **Ramp a stage offset through motion the character already has.**
+ 0.20 m of clearance applied while the support foot is planted is
+ 0.20 m of skate. On this plate the attacker already retreats 0.24 m
+ between the punches and the kick, so the offset was ramped across
+ exactly those frames (src 116–139) and out again while he resettles
+ (162–185): nothing slides, and it reads as making range before a
+ head kick — which is what a fighter does.
+38. **Fist-into-glove is not a bug.** The punches in this plate land on
+ the defender's block, and two rigid hands cannot deform, so the
+ contact frames show deep face overlap (1016 pairs at the worst).
+ That is the strike landing, exactly as in the video. Do not "fix"
+ the frames where contact is the point — separate an intended
+ contact from an unintended one by asking what the source video
+ does at that frame.
diff --git a/docs/PROMPTING.md b/docs/PROMPTING.md
index 03157e0..b9a2d48 100644
--- a/docs/PROMPTING.md
+++ b/docs/PROMPTING.md
@@ -53,3 +53,36 @@ opening T-pose delivered as an A-pose. None of that matters IF you take
the beats and limbs from `analyze_landmarks.py` instead of from the
prompt (docs/PITFALLS.md #5–6). Prompt for what you want; retarget what
you got.
+
+## Two performers in one plate
+
+A fight between two characters is retargetable, but the plate has to
+earn it. Everything above still applies, per performer, plus:
+
+1. **Both square to the camera in the opening T-pose**, side by side,
+ with a visible gap between their fingertips. The estimator makes
+ frame 0's facing each character's forward, so a frontal bind puts
+ both retargets in the render camera's frame and lets their turn
+ toward each other come from the video itself — nothing authored. A
+ profile T-pose also hides one whole arm, which is the one thing the
+ pipeline cannot recover.
+2. **They must never cross or swap sides of frame.** Performer identity
+ is then the side of frame they occupy, which is a fact; tracker ids
+ are not, and a swap splices half of each performer into one track.
+3. **Their silhouettes must not overlap.** Contact reads best as a
+ strike landing on a raised guard, or a clean miss. A clinch, a
+ takedown or ground work will not survive.
+4. **Different clothing colours.** Not decoration — it is how a human
+ (and every still you review) tells the two tracks apart.
+5. **Camera perpendicular to the fighting line**, with both fighters
+ bladed but chests turned ~30° toward the lens. A side-on plate is
+ actually *kinder* to the estimator than a frontal one: the action
+ plane is perpendicular to the lens, so strike extension is measured
+ rather than foreshortened.
+6. **Frame for the tallest moment.** A head-high kick needs headroom
+ the T-pose framing does not.
+
+Travel is fine and wanted — closing distance is what makes an exchange
+read (`root_motion` keeps it). Wandering around the floor is not.
+
+A worked example, prompt and checklist, is the duel plate's SOURCE.md.