DenSnoychik's picture
Upload 33 files
3a6f70b verified
Raw History Blame Contribute Delete
2.15 kB
import struct, numpy as np, json
from rbxm import parse
def load_mesh(path):
d=open(path,'rb').read()
nl=d.index(b'\n')+1
hs,vs,fs,nv,nf=struct.unpack('<HBBII',d[nl:nl+12])
p=nl+hs
vb=np.frombuffer(d[p:p+nv*vs],dtype=np.uint8).reshape(nv,vs)
pos=np.frombuffer(vb[:,:12].tobytes(),dtype='<f4').reshape(nv,3)
nor=np.frombuffer(vb[:,12:24].tobytes(),dtype='<f4').reshape(nv,3)
p+=nv*vs
f0=np.frombuffer(d[p:p+nf*fs],dtype='<u4').reshape(nf,3)
assert nl+hs+nv*vs+nf*fs<=len(d)
return pos.astype(float),nor.astype(float),f0.astype(int)
PARTS={ # part: (package, meshid)
}
def rot(m): return np.array(m).reshape(3,3)
def load_ref():
"""returns dict part-> dict(V world verts, F, cf, attachments{name:(R,pos local)}) (R15Fixed pose)"""
pk={'376532000':'torso','376530220':'larm','376531012':'rarm','376531300':'lleg','376531703':'rleg'}
out={}
for pid in pk:
inst,props,parent=parse(open(f'ref/{pid}.bin','rb').read())
# find Fixed folder
fixed=[r for r in inst if inst[r]=='Folder' and props[r].get('Name')==b'R15Fixed'][0]
for r in inst:
if inst[r]=='MeshPart' and parent.get(r)==fixed:
p=props[r]; name=p['Name'].decode()
mid=p['MeshId'].decode().split('id=')[1]
pos,nor,F=load_mesh(f'ref/m{mid}.mesh')
R=rot(p['CFrame'][0]); t=np.array(p['CFrame'][1],float)
size=np.array(p['InitialSize'],float)
att={}
for a in inst:
if inst[a]=='Attachment' and parent.get(a)==r:
ap=props[a]; att[ap['Name'].decode()]=(rot(ap['CFrame'][0]).tolist(),[float(x) for x in ap['CFrame'][1]])
out[name]=dict(Vl=pos,F=F,R=R,t=t,size=size,att=att,mesh=mid)
return out
if __name__=='__main__':
ref=load_ref()
for n,d in ref.items():
V=d['Vl']; print(n,len(V),len(d['F']),'bbox',V.min(0).round(3),V.max(0).round(3),'size',d['size'].round(3),'t',d['t'].round(3),len(d['att']),list(d['att'])[:12])
pos,nor,F=load_mesh('ref/head.mesh'); print('head',pos.min(0),pos.max(0),len(F))