import os, re, bpy, struct, os.path, shutil from . import common class import_cm3d2_mate(bpy.types.Operator): bl_idname = 'material.import_cm3d2_mate' bl_label = "Import Mate" bl_description = "Open a .mate file as a material." bl_options = {'REGISTER', 'UNDO'} filepath = bpy.props.StringProperty(subtype='FILE_PATH') filename_ext = ".mate" filter_glob = bpy.props.StringProperty(default="*.mate", options={'HIDDEN'}) is_decorate = bpy.props.BoolProperty(name="Decorate the material according to its type", default=True) is_replace_cm3d2_tex = bpy.props.BoolProperty(name="Find textures", default=True, description="Will search for the textures.") @classmethod def poll(cls, context): if 'material_slot' in dir(context): if 'material' in dir(context): return True return False def invoke(self, context, event): if common.preferences().mate_default_path: self.filepath = common.default_cm3d2_dir(common.preferences().mate_default_path, "", "mate") else: self.filepath = common.default_cm3d2_dir(common.preferences().mate_import_path, "", "mate") self.is_replace_cm3d2_tex = common.preferences().is_replace_cm3d2_tex context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} def draw(self, context): self.layout.prop(self, 'is_decorate', icon='TEXTURE_SHADED') self.layout.prop(self, 'is_replace_cm3d2_tex', icon='BORDERMOVE') def execute(self, context): common.preferences().mate_import_path = self.filepath ob = context.active_object me = ob.data try: file = open(self.filepath, 'rb') except: self.report(type={'ERROR'}, message="Failed to import file, File is possibly inaccessible or non-existent.") return {'CANCELLED'} if common.read_str(file) != 'CM3D2_MATERIAL': self.report(type={'ERROR'}, message="This is not a .mate file for CM3D2") return {'CANCELLED'} struct.unpack('