# Path: dist/io_scene_crf/crf_objects.py
# class CRF_object:
# 
#     def __init__(self):
#         self.header = CRF_header()
#         self.footer = CRF_footer()
#         self.meshfile = CRF_meshfile()
#         self.jointmap = None
#         self.skeleton = None
# 
#     def parse_bin(self, file, verbose=False, debug=False):
#         self.header.parse_bin(file, verbose)
#         self.footer.parse_bin(file, self.header.footer_offset1, self.header.footer_offset2, self.header.footer_entries, verbose=verbose, debug=debug)
#         self.meshfile.parse_bin(file, self.footer.get_meshfile().file_offset, verbose=verbose, debug=debug)
# 
#         if(self.footer.get_jointmap() != None):
#             self.jointmap = CRF_jointmap(file, self.footer.get_jointmap().file_offset)
# 
#         if(self.footer.get_skeleton() != None):
#             self.skeleton = CRF_skeleton(file, self.footer.get_skeleton().file_offset)
# 
#     def get_bin(self):
#         data = b""
#         # TODO update all data structures, then write them out
#         mesh_data = self.meshfile.get_bin()
#         joint_data = None
#         if self.jointmap != None:
#             joint_data = self.jointmap.get_bin()
# 
#         meshfile_size = len(mesh_data)
#         footer1_size = len(self.footer.entries * 32)
#         self.footer.update_meshfile(meshfile_size)
#         self.header.footer_offset1 = 0x14 + meshfile_size
#         self.header.footer_offset2 = 0x14 + meshfile_size + footer1_size
#         data += self.header.get_bin()
#         data += mesh_data
#         if joint_data != None:
#             data += joint_data
#         data += self.footer.get_bin()
#         return data


import sys
import os
import fnmatch
import time
import bpy
import mathutils
import struct
from bpy_extras.io_utils import unpack_list, unpack_face_list, axis_conversion
from bpy_extras.image_utils import load_image
from .crf_objects import CRF_object
         use_normal_texture=True,
         use_specular_texture=True,
         use_computed_normals=False,
         use_shadeless=True,
         viz_normals=True,
         viz_blendweights=False,
         use_specular=True,
         global_matrix=None,
         use_debug_bones=False
         ):
    '''
    Called by the user interface or another script.
    load_obj(path) - should give acceptable results.
    This function passes the file and sends the data off
        to be split into objects and then converted into mesh objects
    '''
    print('\nimporting crf %r' % filepath)

    filepath = os.fsencode(filepath)

    if global_matrix is None:
        global_matrix = mathutils.Matrix()

    new_objects = []  # put new objects here

    time_main = time.time()
    print("\tparsing crf file...")
    time_sub = time.time()

    file = open(filepath, "rb")

# Path: dist/io_scene_crf/crf_objects.py
# class CRF_object:
# 
#     def __init__(self):
#         self.header = CRF_header()
#         self.footer = CRF_footer()
#         self.meshfile = CRF_meshfile()
#         self.jointmap = None
#         self.skeleton = None
# 
#     def parse_bin(self, file, verbose=False, debug=False):
#         self.header.parse_bin(file, verbose)
#         self.footer.parse_bin(file, self.header.footer_offset1, self.header.footer_offset2, self.header.footer_entries, verbose=verbose, debug=debug)
#         self.meshfile.parse_bin(file, self.footer.get_meshfile().file_offset, verbose=verbose, debug=debug)
# 
#         if(self.footer.get_jointmap() != None):
#             self.jointmap = CRF_jointmap(file, self.footer.get_jointmap().file_offset)
# 
#         if(self.footer.get_skeleton() != None):
#             self.skeleton = CRF_skeleton(file, self.footer.get_skeleton().file_offset)
# 
#     def get_bin(self):
#         data = b""
#         # TODO update all data structures, then write them out
#         mesh_data = self.meshfile.get_bin()
#         joint_data = None
#         if self.jointmap != None:
#             joint_data = self.jointmap.get_bin()
# 
#         meshfile_size = len(mesh_data)
#         footer1_size = len(self.footer.entries * 32)
#         self.footer.update_meshfile(meshfile_size)
#         self.header.footer_offset1 = 0x14 + meshfile_size
#         self.header.footer_offset2 = 0x14 + meshfile_size + footer1_size
#         data += self.header.get_bin()
#         data += mesh_data
#         if joint_data != None:
#             data += joint_data
#         data += self.footer.get_bin()
#         return data


# Path: dist/io_scene_crf/import_crf.py
import sys
import os
import fnmatch
import time
import bpy
import mathutils
import struct
from bpy_extras.io_utils import unpack_list, unpack_face_list, axis_conversion
from bpy_extras.image_utils import load_image
from .crf_objects import CRF_object

         use_normal_texture=True,
         use_specular_texture=True,
         use_computed_normals=False,
         use_shadeless=True,
         viz_normals=True,
         viz_blendweights=False,
         use_specular=True,
         global_matrix=None,
         use_debug_bones=False
         ):
    '''
    Called by the user interface or another script.
    load_obj(path) - should give acceptable results.
    This function passes the file and sends the data off
        to be split into objects and then converted into mesh objects
    '''
    print('\nimporting crf %r' % filepath)

    filepath = os.fsencode(filepath)

    if global_matrix is None:
        global_matrix = mathutils.Matrix()

    new_objects = []  # put new objects here

    time_main = time.time()
    print("\tparsing crf file...")
    time_sub = time.time()

    file = open(filepath, "rb")

    CRF = CRF_object()