#!/usr/bin/env python3 """Surgical rename of corrupted Mixamo bone namespaces in binary FBX: 'mixamorig:' -> 'mixamorig:'. Parses the FBX node tree, edits ONLY string properties, re-serializes with recomputed offsets. Mesh, materials, textures, geometry are preserved exactly. Correctness gate: with no edits the output must be BYTE-IDENTICAL to the input (`--selftest`). Some nodes carry a trailing null record despite having no children; that is tracked per-node (`nullrec`) so round-trips are exact. """ import os, re, struct, sys RENAME = re.compile(rb'mixamorig[0-9]+:') ELEM = {'f':4,'d':8,'l':8,'i':4,'b':1} SCALAR = {"Y":2,"C":1,"I":4,"F":4,"D":8,"L":8} class Node: __slots__=("name","props","children","nullrec") def __init__(s,name): s.name=name; s.props=[]; s.children=[]; s.nullrec=False def parse(path): d=open(path,'rb').read() assert d[:21]==b"Kaydara FBX Binary \x00", "not a binary FBX" version=struct.unpack("=7500 NREC = 25 if u64 else 13 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: length,enc,clen=struct.unpack(" %s"%(n,a[1]))