# -*- coding: utf-8 -*- ''' ZeroEngine .msh model format. Refer to schlechtwetterfront.github.io/ze_filetypes/msh.html for more information regarding the file format. ''' import os import itertools import struct import math # import logging from .Logger import Logger logging = Logger("Msh2").get_logger() try: import bson json = bson except Exception as e: import json from . import msh2_crc MODEL_TYPES = {'null': 0, 'geodynamic': 1, 'cloth': 2, 'bone': 3, 'geobone': 3, 'geostatic': 4, 'geoshadow': 6} MODEL_TYPES_INT = ['null', 'geodynamic', 'cloth', 'bone', 'geostatic', '', 'geoshadow'] class MSH2Error(Exception): def __init__(self, value): self.parameter = value def __str__(self): return repr(self.parameter) class Packer(object): def pad_string(self, string): '''Pads the given string with \x00s to fill a multiple of 4 length.''' if string == b'': return b'' i = 0 while len(string) >= i: i += 4 return string.ljust(i, b'\x00') def null_terminate(self, string): '''Null-terminates the given string.''' return string + b'\x00' def pack_long_chunk(self, header, number): '''Chunk with only one long int.''' data = [header.encode("ascii")] data.append(struct.pack('