File size: 1,376 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
#!/usr/bin/env python3
"""Build ../character_refined/: a complete 114-character set where corrupted
'mixamorig<N>:' bone namespaces are renamed to 'mixamorig:'.
Unchanged characters are hardlinked, so only the fixed files cost disk.
Originals in ../character/ are never modified."""
import os, re, sys, shutil
HERE=os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0,HERE)
from fbx_rename_bones import process, RENAME

SRC=os.path.join(os.path.dirname(HERE),"character")
DST=os.path.join(os.path.dirname(HERE),"character_refined")
os.makedirs(DST,exist_ok=True)
fixed=[]; linked=[]; failed=[]
files=sorted(f for f in os.listdir(SRC) if f.endswith(".fbx"))
for i,f in enumerate(files,1):
    s=os.path.join(SRC,f); d=os.path.join(DST,f)
    if os.path.exists(d): continue
    blob=open(s,"rb").read()
    if RENAME.search(blob):
        try:
            n,_,_ = process(s,d,do_edit=True)
            fixed.append((f,n))
            print("  [%3d/114] FIXED  %-26s %d strings"%(i,f,n),flush=True)
        except Exception as e:
            failed.append((f,str(e)[:60])); print("  [%3d/114] ERROR  %s: %s"%(i,f,e),flush=True)
    else:
        try: os.link(s,d)
        except OSError: shutil.copy2(s,d)
        linked.append(f)
print("\nfixed: %d | hardlinked unchanged: %d | failed: %d"%(len(fixed),len(linked),len(failed)))
for f,e in failed: print("  FAILED",f,e)