Skip to content

Instantly share code, notes, and snippets.

@philogb
Created August 23, 2011 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philogb/1166835 to your computer and use it in GitHub Desktop.
Save philogb/1166835 to your computer and use it in GitHub Desktop.
import sys
import json
import struct
FILES = ['surf_reg_model_both_inflate_high.json',
'surf_reg_model_both_inflate_middle.json',
'surf_reg_model_both_inflate_low.json',
'surf_reg_model_both_normal.json']
def bin():
for name in FILES:
with open(name, 'r') as f:
obj = json.loads(f.read())
with open(name + '.bin', 'w') as f:
ncomp = len(obj[0])
dat = struct.pack('f', float(ncomp))
f.write(dat)
for vertex in obj[0]:
f.write(struct.pack('f', vertex))
for normal in obj[1]:
f.write(struct.pack('f', normal))
for index in obj[2]:
f.write(struct.pack('I', index))
if __name__ == '__main__':
bin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment