""" A tool for converting kv6 models into pmf. GreaseMonkey, 2013 - Public Domain WARNING: I haven't checked to ensure that X,Y are around the right way. If you find your models have been flipped inadvertently, let me know! --GM """ from __future__ import print_function import sys, struct # Backwards compatibility - make new code work on old version, not vice-versa PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 if PY2: # This script didn't use range() anyway, so no problem overwriting it in Py2 import __builtin__ range = getattr(__builtin__, "xrange") _ord = ord else: _ord = lambda x: x USAGE_MSG = """ usage: python2 kv62pmf.py in.kv6 out.pmf ptsize ptspacing bonename """ if len(sys.argv) <= 4: print(USAGE_MSG) exit() if not sys.argv[3].isdigit(): raise Exception("expected a number for the 3rd argument") if not sys.argv[4].isdigit(): raise Exception("expected a number for the 4th argument") ptsize = int(sys.argv[3]) ptspacing = int(sys.argv[4]) if ptsize < 1 or ptsize > 65535: raise Exception("point size out of range (1..65535)") bonename = sys.argv[4] if PY3: bonename = bonename.encode() if len(bonename) > 15: raise Exception("bone name too large") infp = open(sys.argv[1],"rb") if infp.read(4) != b"Kvxl": raise Exception("not a KV6 file") xsiz, ysiz, zsiz, xpivot, ypivot, zpivot, blklen = struct.unpack(" 65535: raise Exception("point size a bit TOO large to fit into a pmf") if blklen > 4096: raise Exception("kv6 has too many blocks to fit into a pmf") def parseblk(s): return struct.unpack("