File size: 2,478 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""Prove ../character_refined/ differs from ../character/ ONLY by the bone rename.
Walks both node trees in parallel: every non-string property must be byte-identical;
every string property must equal the original with RENAME applied."""
import os,sys,re
HERE=os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0,HERE)
from fbx_rename_bones import parse, RENAME
SRC=os.path.join(os.path.dirname(HERE),"character")
DST=os.path.join(os.path.dirname(HERE),"character_refined")

def walk(a,b,path,diffs):
    if a.name!=b.name: diffs.append(("nodename",path,a.name,b.name)); return
    if len(a.props)!=len(b.props): diffs.append(("nprops",path)); return
    for i,((ta,pa),(tb,pb)) in enumerate(zip(a.props,b.props)):
        if ta!=tb: diffs.append(("ptype",path,i)); continue
        if ta in "SR":
            if RENAME.sub(b'mixamorig:',pa)!=pb: diffs.append(("string",path,i,pa[:40],pb[:40]))
        else:
            if pa!=pb: diffs.append(("DATA",path,i,a.name.decode(errors='replace')))
    if len(a.children)!=len(b.children): diffs.append(("nchild",path)); return
    for ca,cb in zip(a.children,b.children):
        walk(ca,cb,path+"/"+ca.name.decode(errors='replace'),diffs)

fixed=[f for f in sorted(os.listdir(DST)) if f.endswith(".fbx")
       and os.stat(os.path.join(DST,f)).st_nlink==1]
print("verifying %d rewritten files (hardlinked ones are identical by definition)\n"%len(fixed))
allok=True
for f in fixed:
    ta=parse(os.path.join(SRC,f)); tb=parse(os.path.join(DST,f))
    diffs=[]
    if len(ta["top"])!=len(tb["top"]): diffs.append(("ntop",""))
    else:
        for na,nb in zip(ta["top"],tb["top"]):
            walk(na,nb,na.name.decode(errors='replace'),diffs)
    if ta["footer"]!=tb["footer"]: diffs.append(("footer",""))
    data_diffs=[d for d in diffs if d[0]=="DATA"]
    blob=open(os.path.join(DST,f),"rb").read()
    leftover=len(re.findall(rb'mixamorig[0-9]+:',blob))
    clean=len(set(re.findall(rb'mixamorig:[A-Za-z0-9_]+',blob)))
    status = "OK" if not diffs and leftover==0 and clean>=60 else "PROBLEM"
    if status!="OK": allok=False
    print("  %-24s %s | mesh/data diffs:%d other:%d | leftover mixamorig<N>:%d | clean bones:%d"%(
        f,status,len(data_diffs),len(diffs)-len(data_diffs),leftover,clean))
    for d in diffs[:3]: print("      diff:",d)
print("\n%s"%("✓✓ ALL REWRITES SURGICAL — only bone strings changed, mesh/geometry byte-identical" if allok else "✗ PROBLEMS FOUND"))