# Bob side rig v2 — notes

Open: `file:///root/tmp/anim/side-rig-v2/bob.html` (one file, ~410 KB, art embedded as webp). v1 untouched in `../side-rig/`.

## Pipeline
| step | file | what |
|---|---|---|
| gen | `gen.py` | one Gemini call, hard cap 20 (counts `gen/calls.jsonl`). Key from file, never printed. |
| cut | `cut.py` | parts sheet -> `parts/`, `parts.json`. Heads from `gen/ref-head3.png` + `gen/head3-*-al.png`. Pelvis corner rounded + inked. |
| align | `align.py` | ECC-align face edits onto neutral head |
| build | `build.py` | embed parts into `bob.tpl.html` -> `bob.html` |
| shots | `shots.sh` | all state shots + `shots/contact-*.png`. Uses `shoot.sh` (deterministic via `window.bob`) |
| checks | `checks.js`, `pops.js`, `stops.js`, `accel.js` | `agent-browser eval "$(cat checks.js)"`: IK error, knee angles, stance drift, stop-step drift. pops: first frame after every go(). stops: walk exit switch frame. accel: per-joint world accel spikes in steady walk (glitch finder) |

Gemini: 18 calls used (round 3: 0), cap now 28 (user +10). See CALLS.md.

## What changed vs v1
| # | v1 | v2 |
|---|---|---|
| 1 walk wavy, knees bent | y = 20 + 10*bob, legs 0.985 L | hip height derived per frame: `rootH` = smooth-min over legs of "height where leg is straight" (compass gait). Stance knee 7 deg mid stance + heel rise, swing 64 deg max. Hip bob 7 px. No added bob. |
| knee snap near straight | plain 2-bone IK | soft IK: last 0.5% of reach eases knee straight, bones stretch <= 2% so ankle still exact |
| 2 walk arms | elbow -0.2..-0.5, swing 0.34 | swing 0.24, elbow -0.06..-0.18 (near straight) |
| 3 think | far fist at chin | NEAR fist under chin (reach bend -1), far forearm crossed in front of belly under near elbow (`fFront` key: far forearm redrawn over torso, alpha-blended, no pop) |
| 4 standing knees | y > 0 everywhere | y = 0 for idle/think/happy/sad/reach. Knees 7-9 deg (soft IK floor) |
| 5 happy elbows | reach bend +1 | bend -1: elbows point back. Bounce = rise on toes, feet stay on ground (no hop) |
| 6 face camera | checkbox, turnW, turned sprite | removed (code, UI, cut.py, parts/turned.png) |
| 7 butt cut | hard horizontal cut | pelvis back-bottom corner rounded (r 64) + ink line, 14 px fade on front part (under thigh) |
| head | pure profile | ~25 deg toward camera (call 9), more East Asian (call 14, user ask), new 4 expressions (15-18) |
| arms short | 1.0 | upper arm scaled 1.15 (`AS`) |
| pick up | torso 95 deg, bent arm IK | torso 80 deg (pel 0.5 + tor 0.88), arm straight down, crouch depth solved by bisection so fingertips touch ground |
| foot slide leaving walk | root coasted during blend, feet slid | go() during walk waits for next heel strike (<= 0.55 s, info shows "walk → x"). Then stop step: front foot planted, root eases out at walk speed onto it, back foot swings forward with lift. Drift 0. |
| confidence | tor 0.07, head -0.06 | walk torso ~0.035 (upright), head -0.06 + new head art chin up, idle head -0.05, blends 0.38 s (was 0.5), walk-in 0.3 |

## Round 2 (user feedback 2026-10-01)
| # | problem | cause | fix |
|---|---|---|---|
| 2.5 twisted body | far shoulder/hip sat BEHIND near (`farSh -16`, `farHip -12`) = body turned away, but head + torso art turn toward camera | wrong sign | `FAR_SH 46`, `FAR_HIP 26`: far side sits forward. All far ankle targets +38 (same spot relative to own hip) |
| 2.4 walk glitch | hip vertical speed flipped in 1 frame when swing foot took over hip height (accel 2.6 hip, 14 knee) | hard min of leg heights | smooth-min width per pose (`hk`, walk 18); lift curve `sin^1.5` lands with ~0 vertical speed. Hip accel 0.7, knee 2.4 |
| 2.4 foot pop | swing foot left/landed with 0 rig speed = world speed jump | `smooth()` swing x | hermite swing x: leaves + lands at -WALK_V rig = 0 world |
| 2.3 legs only forward | feet range +-150 around hip | symmetric stride | `STEP_BACK 40`: land 110 ahead, push off 190 behind |
| 2.1 boots high, shaft rotates with foot | boot piece had its own shaft + pants stub stacked on shin's boot cuff | cut | `cut.py`: shin keeps its boot cuff (shaft = leg), cut 25 px below ankle; foot texture = boot below ankle only. Foot drawn first, shin over it hides seam |
| 2.2 butt sticks out | pelvis butt lobe fixed while thigh swings | pelvis art | back-bottom corner rounding r 64 -> 110. Bulge much smaller |
| 1.1 crossed arms | n/a | new | new state `cross` (Arms crossed): FK (`fk()` in world bone dirs), near forearm across belly, far forearm short (fs 0.3), fist on near biceps |
| 1.2 think | far forearm poked out of back; fist over mouth | IK elbow-back solution, target too high | think = cross first, at 0.45-1.05 s near fist rises under chin (`THINK_CHIN [16,84]`), elbow forward, far hand cups near elbow (bend +1). Expression crossfades with the hand |

## Round 3 (2026-10-01): cross arms + walk bump
| # | problem | cause | fix |
|---|---|---|---|
| 3.1 cross arms tucked at side | FK + forearm squash put forearms inside torso silhouette, only fist poked out | elbows hung down, upper arm full length | `place(p, s, E, Wr)`: arm from elbow + wrist points in torso space. Upper arm length key `nUs`/`fUs` (like `nFs`): short bone = points at camera. `CROSS` points: near elbow at jacket hem, forearms stacked level under bust, bundle sticks ~45 past chest front (story art a_1f0e). Both fists |
| 3.2 far fingertips peek | far hand drawn over near upper arm | draw order | far forearm now drawn BEFORE near upper arm: far hand hidden under near biceps |
| 3.3 think far arm swung out front mid-rise | far forearm dir wrapped -2.85 -> +2.8, mix() went the long way | atan2 wrap | fk wraps U/F to (-PI, PI]. Think far arm = `place()` (elbow stays at `CROSS.fE`, hand cups near elbow from below). Near hand fist (was half-open over mouth) |
| 3.4 walk feet too high | lift 70 | | `LIFT 44` |
| 3.5 walk bump | raw hip height dip-rise-dip around each heel strike (704.3 @0.45, 707.0 @0.53, 706.2 @0.57) | swing foot touched down at s=0.91 (`s*1.1`) and slid into heel strike; per-frame min of two leg constraints kinks | lift lands at s=1. Walk hip height = gaussian-smoothed rootH (sigma `WALK_SM` 0.035 cycle) via `p.y`. Stretch <= 0.3%. Hip accel 0.7 -> 0.1 |
| 3.6 idle front leg forward | near foot 26 ahead of hip | | idle `nAx -4` |
| 3.7 scrubber | n/a | user ask | slider under buttons: walk = phase 0..1, others 0..`len` s. Drag = pause + pose there. ◀ ▶ = 1 frame, keys `,` `.` space. Graph (walk): raw vs smoothed hip height, red zones = where the bump was, white line = now. `bob.scrubTo(k)` |


## Round 4 (2026-10-01): walk polish
| # | problem | cause | fix |
|---|---|---|---|
| 4.1 steps long | STRIDE 300 | | STRIDE 260, STEP_BACK 35 (land 95 ahead, push off 165 behind) |
| 4.2 arms swing much | 0.24 | | swing 0.15, elbow -0.08 |
| 4.3 swing leg stuck after toe-off | foot left at 0 world speed (kept sliding back 6 units in rig until 0.66), lift slow to start: knee un-folded 35->31, thigh went back | hermite start tangent, sin^1.5 lift | start tangent `m0 = 0.5 m`, lift `sin(PI u)^2`, u = s(1.6-0.6s): peaks s ~0.35. Knee folds 37->45 monotone |
| 4.4 stance knee locked then snaps | knee straight (soft floor) till 0.445, then sqrt onset (knee ~ sqrt(shortening)), thigh reversed 11->0 in 0.06 | heel-off late (s 0.72) + narrow soft zone | heel-off from s 0.55 (`0.5 x^2`), walk soft-IK zone x2.5 (`ks` key, `KS_WALK`). Mid-stance knee 7 -> 11 deg |
| 4.5 swing ankle kink @0.83 | pivot hard-switched heel/toe at foot angle 0 | ankleFromContact | pivot blends heel->toe over |fa| < z, z 0.05 on ground, 0.3 in air. Swing foot angle smooth(s). Foot-flat roll smooth |
| 4.6 butt sticks out | pelvis lobe fixed, near leg drawn under pelvis | draw order | near leg drawn OVER pelvis + torso. `trimPelvis()`: pelvis lobe below belt (`PELVIS_TRIM_Y` 100) behind the thigh rest outline cut at load. Thigh back = butt silhouette, moves with leg |
| 4.7 speed | n/a | user ask | speed slider 0.1-2x (`R.speed`) next to scrubber |

Leg accel (accel.js, 120 Hz): toe 5.4 -> 2.9, shin 3.9 -> 2.3, boot 2.6 -> 1.7, hip 0.1.

## Round 5 (2026-10-01): "looks 95"
| # | problem | fix |
|---|---|---|
| 5.1 old-lady walk | `T_WALK` 1.1 -> 0.95 s, STRIDE 260 -> 290, STEP_BACK 38, push-off toe roll `TOE_OFF` 0.5 -> 0.6, stance knee straighter (`KS_WALK` 2.5 -> 1.8, mid stance 9.6 deg) |
| 5.2 squat: pelvis stub under the butt | `HIP_DROP` 10: hip joint 10 px lower on pelvis. Pelvis trim now per frame (`trimmedPelvis(W)`): cut behind the near thigh back outline at its current angle, below belt (`PELVIS_TRIM_Y`), 10 px soft start |
| checks | `checks.js` T = 0.95; stance drift now compares planted flat-ankle x (old pivot-key logic read 152 = toe-heel length when heel-off starts early). `accel.js` T 0.95, `shots.sh` walk steps T/8 |
| 5.3 tweak (user) | arm swing 0.15 -> 0.2 (elbow 0.1), `LIFT` 44 -> 34, STEP_BACK 38 -> 50 (land 95 ahead, push off 195 behind) |
| 5.4 legs move more (feet unchanged) | walk pelvis rock 0.025 -> 0.05 rad, torso counter-rotates (`tor` -0.02c -> -0.045c) so chest angle unchanged |
| 5.5 torso still in walk | chest rocks with the pelvis at half (`tor` -0.025c, net 0.025 rad) |
| 5.6 cross near forearm too long | `CROSS.nW` [142,-120] -> [116,-114]: more foreshortened, fist on the far forearm |

Shots: `shots/cross-compare.png` (original vs before/after cross + think).

## Checks (last run)
- IK error 0 all states, walk, stop step.
- Walk stance contact world x drift 0. Stop step front heel drift 0.
- Knees: idle 7/9 deg, cross/think 8, sad 7-10, happy 7-11. Walk stance 7 deg mid stance, 11 at heel-off, ~34 pre-swing (after other heel strike, normal gait). Hip bob 5.5 px.
- accel.js: max hip accel 0.7 rig/frame^2 at 120 Hz (was 2.6), knee 2.4 (was 14).
- pops.js: 72 pairs (9 states), no first-frame jump. stops.js: walk -> all 8 states, switch frame jump < normal walk frame motion.

## Flaws (honest)
- Walk start still not stepped: idle -> walk blends feet while root accelerates -> short foot slide on start (0.3 s). Stop is fixed, start is not.
- Leaving walk waits up to 0.55 s for heel strike. Responsive enough for point-and-click, not instant.
- Stop step when far foot is front: long back-foot swing (up to 0.8 s).
- Head now 3/4-ish, torso art ~3/4, legs/arms profile. Reads more consistent than v1, still mixed.
- Crossed arms: forearms + upper arms foreshortened by squash, not real art. Near fist sits on far elbow, reads OK at game scale. Original is 3/4 front, rig profile: stacked-forearm read only, no sleeve overlap detail.
- Walk: toe-off (phase 0.60) still the biggest leg accel (swing leaves at half stance speed: small toe slide on the first frames).
- Squat / pick up: belt end tab sticks out behind (above the trim line, left on purpose).
- Pick up: still a deep crouch (legs short vs reach). Far hand touches ground near boot (reads as support hand).
- Soft IK floor = knees never below ~7 deg. Looks straight at game scale.
- Far limbs = darkened near art. Joint caps at strong bends visible (squat).
- Paper-flip turnaround unchanged.
- Calls 10-13 (turned head, pre-Asian) unused: user changed face mid-run.
- Far arm now mostly behind torso in walk (correct for the turn, but far arm swing barely visible).
