#!/usr/bin/env python3 """Rig fingerprint of a binary FBX: joint names plus their rest offsets. Joint count alone cannot tell two skeletons apart — two rigs can share a count and still differ in proportions. Each joint's `Lcl Translation` is its offset from its parent, i.e. the bone vector, so the (name, offset) set pins down both topology and bone lengths. """ import math, os, struct, sys SCALAR = {"Y": 2, "C": 1, "I": 4, "F": 4, "D": 8, "L": 8} ELEM = {"f": 4, "d": 8, "l": 8, "i": 4, "b": 1} def probe(path, nd=3): d = open(path, "rb").read() if d[:21] != b"Kaydara FBX Binary \x00": raise ValueError("not a binary FBX") version = struct.unpack("= 7500 NREC = 25 if u64 else 13 bones = {} def rd_prop(p): t = chr(d[p]); s = p; p += 1 if t in SCALAR: p += SCALAR[t]; return p, (t, d[s + 1:p]) if t in ELEM: n, enc, clen = struct.unpack("= 3 and props[2][1] in (b"LimbNode", b"Root"): mine = props[1][1].split(b"\x00\x01")[0].decode("utf-8", "replace") bones.setdefault(mine, (0.0, 0.0, 0.0)) elif name == b"P" and cur is not None and props and props[0][1] == b"Lcl Translation": vals = [struct.unpack("= 3: bones[cur] = tuple(vals[-3:]) while p < end: if d[p:p + NREC] == b"\x00" * NREC: p += NREC; break p = rd_node(p, mine) return end p = 27 while p < len(d) - 160: if d[p:p + NREC] == b"\x00" * NREC: break p = rd_node(p) sig = tuple(sorted((n, round(x, nd), round(y, nd), round(z, nd)) for n, (x, y, z) in bones.items())) total = sum(math.sqrt(x * x + y * y + z * z) for _, (x, y, z) in bones.items()) return {"num_joints": len(bones), "signature": sig, "bone_length_sum": round(total, 3)} if __name__ == "__main__": for f in sys.argv[1:]: r = probe(f) print("%-34s joints=%-4d bone_len_sum=%-12.3f" % ( os.path.basename(f), r["num_joints"], r["bone_length_sum"]))