Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor
Tilt the avatar the same way the tracked body leans
shinshin8670dcc7371116
diff --git a/src/live/body-tracking.ts b/src/live/body-tracking.tsindex 554b357..27e8706 100644--- a/src/live/body-tracking.ts+++ b/src/live/body-tracking.ts@@ -34,7 +34,9 @@ export function mapBody(body: BodyNeutral, neutral: BodyNeutral, options: Trackiconst gain = clamp(options.sensitivity, 0.25, 2) * (options.mirror ? -1 : 1);const shoulders = (body.shoulderX - neutral.shoulderX) / neutral.width;const hips = body.hipX !== undefined && neutral.hipX !== undefined ? (body.hipX - neutral.hipX) / neutral.width : 0;- return { bodyAngleX: clamp(softDeadZone(shoulders, BODY_DEAD_ZONE.shift) * gain * 20, -10, 10), bodyAngleZ: clamp(softDeadZone(body.roll - neutral.roll, BODY_DEAD_ZONE.roll) * gain, -10, 10), weightShift: clamp(softDeadZone(hips, BODY_DEAD_ZONE.hips) * gain * 1.4, -1, 1) };+ // Image roll is clockwise-positive (y down), but a positive bodyAngleZ tilts the+ // avatar's top towards image-left, so roll takes the opposite sign to the shifts.+ return { bodyAngleX: clamp(softDeadZone(shoulders, BODY_DEAD_ZONE.shift) * gain * 20, -10, 10), bodyAngleZ: clamp(softDeadZone(neutral.roll - body.roll, BODY_DEAD_ZONE.roll) * gain, -10, 10), weightShift: clamp(softDeadZone(hips, BODY_DEAD_ZONE.hips) * gain * 1.4, -1, 1) };}export class BodyPose {private body: BodyNeutral | null = null;diff --git a/tests/body-tracking.test.ts b/tests/body-tracking.test.tsindex 0f632bc..455a27d 100644--- a/tests/body-tracking.test.ts+++ b/tests/body-tracking.test.ts@@ -17,9 +17,18 @@ test('shoulder displacement/tilt map independently, hips take weight priority, mexpect(mapBody(shifted, zero, { ...options, sensitivity: 2 }).bodyAngleX).toBeCloseTo(6.4);expect(mapBody(readBody(body(1))!, zero, options).bodyAngleX).toBe(10);const seated = mapBody(readBody(body(.06, -.03, false))!, zero, options); expect(seated.weightShift).toBe(0);+ // A clockwise camera-image tilt leans the avatar's top towards image-right without+ // Mirror (negative bodyAngleZ), and towards image-left with it, like bodyAngleX.const tilted = body(); tilted.shoulders[1].y += .04;- expect(mapBody(readBody(tilted)!, zero, options).bodyAngleZ).toBeGreaterThan(3);- expect(mapBody(readBody(tilted)!, zero, { ...options, mirror: true }).bodyAngleZ).toBeLessThan(-3);+ expect(mapBody(readBody(tilted)!, zero, options).bodyAngleZ).toBeLessThan(-3);+ expect(mapBody(readBody(tilted)!, zero, { ...options, mirror: true }).bodyAngleZ).toBeGreaterThan(3);+ // Leaning sideways moves the shoulders and tilts their line the same way. The avatar's+ // shift (+bodyAngleX = image-right) and tilt (-bodyAngleZ = top to image-right) agree.+ for (const mirror of [false, true]) {+ const lean = body(-.08, -.04); lean.shoulders[0].y += .04;+ const mapped = mapBody(readBody(lean)!, zero, { ...options, mirror });+ expect(Math.sign(mapped.bodyAngleX)).toBe(-Math.sign(mapped.bodyAngleZ));+ }tilted.shoulders[0].visibility = .1; expect(readBody(tilted)).toBeNull();tilted.shoulders[0].visibility = 1; tilted.shoulders[0].x = NaN; expect(readBody(tilted)).toBeNull();});@@ -265,7 +274,7 @@ test('real torso lean remains tracked and visible hips can corroborate lean durip.x = center.x + (x * Math.cos(angle) - y * Math.sin(angle)) / roll.aspect;p.y = center.y + x * Math.sin(angle) + y * Math.cos(angle);}- pose.update(face(roll), 10); expect(pose.sample(10, 2, armOptions).params.bodyAngleZ).toBeGreaterThan(6);+ pose.update(face(roll), 10); expect(Math.abs(pose.sample(10, 2, armOptions).params.bodyAngleZ)).toBeGreaterThan(6);});test('hidden hips release only weightShift to idle; late hips never inherit the shoulder offset', () => {