import os, os.path, bpy, struct, os.path from . import common class import_cm3d2_tex(bpy.types.Operator): bl_idname = 'image.import_cm3d2_tex' bl_label = "Import .tex" bl_description = "Imports a CM3D2 tex file (.tex)" bl_options = {'REGISTER'} filepath = bpy.props.StringProperty(subtype='FILE_PATH') filename_ext = ".tex;.png" filter_glob = bpy.props.StringProperty(default="*.tex;*.png", options={'HIDDEN'}) items = [ ('PACK', "Package", "", 'PACKAGE', 1), ('PNG', "Opens or converts to png", "", 'IMAGE_DATA', 2), ] mode = bpy.props.EnumProperty(items=items, name="Mode", default='PNG') def invoke(self, context, event): if common.preferences().tex_default_path: self.filepath = common.default_cm3d2_dir(common.preferences().tex_default_path, "", "tex") else: self.filepath = common.default_cm3d2_dir(common.preferences().tex_import_path, "", "tex") context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} def draw(self, context): box = self.layout.box() col = box.column(align=True) col.label(text="Mode", icon='FILESEL') col.prop(self, 'mode', icon='FILESEL', expand=True) def execute(self, context): common.preferences().tex_import_path = self.filepath try: file = open(self.filepath, 'rb') except: self.report(type={'ERROR'}, message="Failed to open the file, it does not exist or is inaccessible") return {'CANCELLED'} header_ext = common.read_str(file) if header_ext == 'CM3D2_TEX': file.seek(4, 1) in_path = common.read_str(file) png_size = struct.unpack('