''' ZeroEngine .msh model format parser. Refer to schlechtwetterfront.github.io/ze_filetypes/msh.html for more information regarding the file format. ''' import msh2 reload(msh2) from struct import unpack as unpack import logging STR_CODEC = 'utf-8' CHUNK_LIST = ['HEDR', 'SHVO', 'MSH2', 'SINF', 'FRAM', 'CAMR', 'MATL', 'DATA', 'MATD', 'ATRB', 'TX0D', 'TX1D', 'TX2D', 'TX3D', 'MODL', 'MTYP', 'MNDX', 'PRNT', 'FLGS', 'TRAN', 'ENVL', 'SWCI', 'GEOM', 'SEGM', 'SHDW', 'MATI', 'POSL', 'NRML', 'UV0L', 'UV1L', 'UV2L', 'CLRL', 'CLRB', 'WGHT', 'NDXL', 'NDXT', 'STRP', 'CLTH', 'CTEX', 'CPOS', 'CUV0', 'FIDX', 'FWGT', 'SPRS', 'CPRS', 'BPRS', 'COLL', 'SKL2', 'BLN2', 'ANM2', 'CYCL', 'KFR3', 'NAME', 'BBOX', 'CL1L'] class UnpackError(Exception): def __init__(self, val): self.val = val def __str__(self): return str(self.val) class Unpacker(object): def unpack_header(self, data): return data[:4], unpack(' 0: for index, vertindex in enumerate(fixed): self.seg.vertices[vertindex].deformer = weights[index] elif hdr == 'CMSH': num = unpack(' -1: if num_begins == 0: num_begins += 1 face = msh2.Face() facecoll.add(face) elif num_begins == 1: num_begins += 1 if face.sides > 2: face = msh2.Face() facecoll.add(face) num_begins = 0 elif num_begins == 2: num_begins = 1 face = msh2.Face() facecoll.add(face) face.add(val - 0x8000) else: face.add(val) facecoll.de_ngonize(self.up.up.config['triangulate']) self.seg.faces = facecoll elif hdr == 'NDXL': last_chunk = 'NDXL' self.fh.read(size) elif hdr == 'NDXT': last_chunk = 'NDXT' # If the faces are already set (for example from the STRP chunk) # then ignore this as it's usually deprecated. if self.seg.faces: continue num_triangles = unpack('