File size: 942 Bytes
12b5ac7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
"""Extract REAL bone names from a binary FBX via the node tree (not regex over bytes).
Model nodes carry props (id:int64, name:str, subtype:str); skeleton bones have
subtype 'LimbNode'/'Root'. FBX object names look like b'mixamorig:Hips\\x00\\x01Model'."""
import os, sys
HERE=os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0,HERE)
from fbx_rename_bones import parse

def _walk(n, out):
    if n.name == b"Model" and len(n.props) >= 3:
        nm = n.props[1][1]; sub = n.props[2][1]
        if sub in (b"LimbNode", b"Root"):
            out.add(nm.split(b"\x00\x01")[0].decode("utf-8", "replace"))
    for c in n.children: _walk(c, out)

def bones(path):
    t = parse(path); out = set()
    for n in t["top"]: _walk(n, out)
    return out

if __name__ == "__main__":
    for f in sys.argv[1:]:
        b = bones(f)
        print("%-30s %3d bones  e.g. %s" % (os.path.basename(f), len(b), sorted(b)[:4]))