"""Skin a baked-pose GLB's hand region with Godot-exact LBS and write it as a plain OBJ. usage: godot_skin_hand_obj.py posed.glb side(l|r) out.obj""" import json, struct, sys def read_glb(path): d = open(path, "rb").read() length = struct.unpack_from("0 for j,w in zip(jr,wr)): continue x=y=z=0.0 for j,w in zip(jr,wr): w*=wsc if w<=0: continue M=JM[j] x+=w*(M[0][0]*p[0]+M[0][1]*p[1]+M[0][2]*p[2]+M[0][3]) y+=w*(M[1][0]*p[0]+M[1][1]*p[1]+M[1][2]*p[2]+M[1][3]) z+=w*(M[2][0]*p[0]+M[2][1]*p[1]+M[2][2]*p[2]+M[2][3]) keep[vi]=(x,y,z) remap = {vi:k+1 for k,vi in enumerate(keep)} tris = [] flat = [ix[0] for ix in I] for t in range(0, len(flat), 3): a1,a2,a3 = flat[t], flat[t+1], flat[t+2] if a1 in remap and a2 in remap and a3 in remap: tris.append((remap[a1], remap[a2], remap[a3])) with open(out, "w") as f: for vi in keep: x,y,z = keep[vi] f.write(f"v {x:.6f} {y:.6f} {z:.6f}\n") for t in tris: f.write(f"f {t[0]} {t[1]} {t[2]}\n") print(f"[skinobj] {out}: {len(keep)} verts, {len(tris)} tris")