"""Find corrupt skin bindings: verts bound to a joint that is implausibly far away in REST pose (long bind lever arm), and verts bound across the body midline to the opposite hand's bones. These are invisible at rest and only explode once the joint rotates. usage: skin_lever_audit.py body.glb [--lever CM] [--dump N] """ import json, struct, sys, math from pathlib import Path from collections import Counter, defaultdict FING = ("thumb", "index", "middle", "ring", "pinky") LEVER_CM = 20.0 DUMP = 0 args = [a for a in sys.argv[1:]] path = args[0] if "--lever" in args: LEVER_CM = float(args[args.index("--lever") + 1]) if "--dump" in args: DUMP = int(args[args.index("--dump") + 1]) def read_glb(p): d = Path(p).read_bytes() length = struct.unpack_from(" LEVER_CM: long_lever.append((d, vi, n, w, p)) by_joint[n] += 1 # cross-hand: vert on opposite side of midline from the joint if nl.endswith("_r") and p[0] > 0.02: cross.append((d, vi, n, w, p)); cross_by_joint[n] += 1 elif nl.endswith("_l") and p[0] < -0.02: cross.append((d, vi, n, w, p)); cross_by_joint[n] += 1 print(f" mesh[{mi}] '{mesh.get('name','')}' prim{pi}: {len(P)} verts") print(f" finger refs with lever > {LEVER_CM:.0f} cm : {len(long_lever)}") if long_lever: mx = max(long_lever) print(f" worst {mx[0]:.1f} cm vert {mx[1]} joint {mx[2]} w={mx[3]:.3f}") for n, c in by_joint.most_common(10): print(f" {n:22s} {c}") print(f" cross-midline finger refs : {len(cross)}") if cross: mx = max(cross) print(f" worst {mx[0]:.1f} cm vert {mx[1]} joint {mx[2]} w={mx[3]:.3f}") for n, c in cross_by_joint.most_common(10): print(f" {n:22s} {c}") for d, vi, n, w, p in sorted(long_lever, reverse=True)[:DUMP]: print(f" v{vi} {n} w={w:.3f} lever={d:.1f}cm pos=({p[0]*100:.1f},{p[1]*100:.1f},{p[2]*100:.1f})cm")