#!/usr/bin/env python3 """Look for discontinuities in an FBX's animation curves. Reports the largest frame-to-frame step in each curve, relative to how that curve normally moves. Rotation tracks are stored in degrees and wrap at ±180, so a 179° -> -179° step is a 2° move, not a 358° one; those are unwrapped first, otherwise nearly every turning clip looks broken. A curve is called discontinuous when its biggest step is large in absolute terms and also several times the *second* largest step. Fast but smooth motion has many comparable steps, so nothing stands out; a teleport or a snapped pose produces one isolated spike. Comparing against a percentile instead fails here, because most curves barely move and their percentile sits at ~0, making every ratio explode. """ import os, struct, sys, zlib SCALAR = {"Y": 2, "C": 1, "I": 4, "F": 4, "D": 8, "L": 8} ELEM = {"f": 4, "d": 8, "l": 8, "i": 4, "b": 1} FMT = {"f": "f", "d": "d", "l": "q", "i": "i", "b": "b"} def _curves(path): d = open(path, "rb").read() if d[:21] != b"Kaydara FBX Binary \x00": raise ValueError("not a binary FBX") u64 = struct.unpack("= 7500 N = 25 if u64 else 13 out = [] def rp(p, want): t = chr(d[p]); s = p; p += 1 if t in SCALAR: p += SCALAR[t]; return p, None if t in ELEM: n, enc, cl = struct.unpack(" 20.0 # rotation tracks span tens of degrees deltas = [] for i in range(1, len(c)): dv = c[i] - c[i-1] if degrees and abs(dv) > 180.0: dv -= 360.0 if dv > 0 else -360.0 # unwrap deltas.append(abs(dv)) if not deltas: continue s = sorted(deltas, reverse=True) mx = s[0]; second = s[1] if len(s) > 1 else 0.0 r = mx / second if second > 1e-9 else (float("inf") if mx > abs_min else 0.0) if mx > worst: worst = mx if r != float("inf") and r > worst_ratio: worst_ratio = r if mx >= abs_min and r >= ratio: bad += 1 return {"curves": n, "max_step": round(worst, 3), "max_ratio": round(worst_ratio, 1), "discontinuous_curves": bad} if __name__ == "__main__": for f in sys.argv[1:]: try: r = probe(f) print("%-34s curves=%-4d max_step=%-9.2f ratio=%-7.1f bad=%d" % ( os.path.basename(f), r["curves"], r["max_step"], r["max_ratio"], r["discontinuous_curves"])) except Exception as e: print("%-34s ERROR %s" % (os.path.basename(f), str(e)[:50]))