def run_save(self): files_to_save = MATCHING.findAll(self.file, self.ACTIVE_FILES) if len(files_to_save) > 1 and self.destination is not None: raise SaveError('Detected {} files and only one destination "{}"'.format(len(files_to_save), self.destination)) else: for x in files_to_save: if not x.save(self.destination, self.overwrite): raise SaveError('File already Exists!')
def run_convert(self): if self.ext == '.dae': from abmatt.converters.convert_dae import DaeConverter2 klass = DaeConverter2 elif self.ext == '.obj': from abmatt.converters.convert_obj import ObjConverter klass = ObjConverter else: raise ParsingException('Unknown conversion format {}'.format(self.ext)) active_files = self.ACTIVE_FILES if not self.name: files = [x.name for x in active_files] else: files = self.getFiles(self.name) if not files: return False multiple_files = False if len(files) < 2 else True brres = None if self.is_import: if not self.destination: if active_files and not multiple_files: brres = active_files[0] else: brres = None else: brres = self.create_or_open(self.destination) for file in files: if not brres: converter = klass(self.create_or_open(convert_file_ext(file, '.brres')), file, self.flags) else: converter = klass(brres, file, self.flags) base_name = os.path.splitext(os.path.basename(converter.brres.name))[0] model = self.model if model and len(model) > len(base_name) and model.startswith(base_name + '-'): model = model[len(model) + 1:] mdl = converter.load_model(model) brres = converter.brres else: # export dest_auto = True if multiple_files or os.path.basename(self.destination).lower() == '*' + self.ext else False for file in files: destination = self.destination if not dest_auto \ else os.path.join(os.path.dirname(self.destination), convert_file_ext(os.path.basename(file), self.ext)) brres = self.create_or_open(file) converter = klass(brres, destination, self.flags) models = MATCHING.findAll(self.model, brres.models) if len(models) > 1: multi_model = True destination = destination[:-1 * len(self.ext)] else: multi_model = False for mdl0 in models: if multi_model: converter.mdl_file = destination + '-' + mdl0.name + self.ext converter.save_model(mdl0) if brres is not None: self.updateSelection(brres.name)
def removeLayerByName(self, name): """Removes the layer if found, (for removing only the animation)""" j = 0 matches = MATCHING.findAll(name, self.tex_animations) for i in range(len(self.texEnabled)): if self.texEnabled[i]: if self.tex_animations[j] in matches: self.texEnabled[i] = False self.tex_animations.pop(j) self.mark_modified() return j += 1 raise ValueError('{} No layer matching {}'.format(self.name, name))
def updateFile(filename): # check in opened files files = MATCHING.findAll(filename, Command.OPEN_FILES.values()) if files: Command.ACTIVE_FILES = files else: # try to find file path files = Command.getFiles(filename) if Command.DESTINATION: # check for multiple files with single destination outside_active = True for x in Command.ACTIVE_FILES: if files[0] == x.name: outside_active = False break if len(files) > 1 or Command.ACTIVE_FILES and outside_active: raise SaveError('Multiple files for single destination') Command.ACTIVE_FILES = Command.openFiles(files) Command.MODELS = [] Command.MATERIALS = [] return Command.ACTIVE_FILES
def updateTypeSelection(self): """ Updates the current selection by the type""" if self.updateType(): type = Command.SELECT_TYPE if type == 'material': Command.SELECTED = self.MATERIALS elif type == 'layer': if self.SELECT_ID_NUMERIC: selected = [] for x in self.MATERIALS: layer = x.getLayerI(self.SELECT_ID) if layer: selected.append(layer) Command.SELECTED = selected else: Command.SELECTED = [] for x in self.MATERIALS: layers = MATCHING.findAll(self.SELECT_ID, x.layers) if layers: Command.SELECTED.extend(layers) # if not Command.SELECTED: # Forcibly adding case if no selected found # # possible todo... make this optional? # Command.SELECTED = [x.forceAdd(self.SELECT_ID) for x in self.MATERIALS] elif type == 'shader' or type == 'stage': shaders = getShadersFromMaterials(self.MATERIALS) if type == 'shader': Command.SELECTED = shaders else: if self.SELECT_ID == '*': Command.SELECTED = [] for x in shaders: Command.SELECTED.extend(x.stages) else: Command.SELECTED = [x.getStage(self.SELECT_ID) for x in shaders] elif type == 'mdl0': if self.SELECT_ID_NUMERIC: brres = getBrresFromMaterials(self.MATERIALS) Command.SELECTED = {x.getModelI(self.SELECT_ID) for x in brres} if None in Command.SELECTED: Command.SELECTED.remove(None) else: Command.SELECTED = MATCHING.findAll(self.SELECT_ID, getParents(self.MATERIALS)) elif type == 'brres': if self.cmd in ('add', 'remove'): Command.SELECTED = getBrresFromMaterials(self.MATERIALS) else: Command.SELECTED = MATCHING.findAll(self.SELECT_ID, getBrresFromMaterials(self.MATERIALS)) elif 'srt0' in type: srts = [x.srt0 for x in self.MATERIALS if x.srt0] if 'layer' in type: Command.SELECTED = [] if self.SELECT_ID_NUMERIC: for x in srts: anim = x.getTexAnimationByID(self.SELECT_ID) if anim: Command.SELECTED.append(anim) else: for x in srts: anim = MATCHING.findAll(self.SELECT_ID, x.tex_animations) if anim: Command.SELECTED.extend(anim) else: # material animation Command.SELECTED = srts elif 'pat0' in type: Command.SELECTED = [x.pat0 for x in self.MATERIALS if x.pat0] elif 'tex0' == type: Command.SELECTED = [] for x in getBrresFromMaterials(self.MATERIALS): Command.SELECTED.extend(MATCHING.findAll(self.SELECT_ID, x.textures))
def getTextures(self, name): return MATCHING.findAll(name, self.textures)
def getModelsByName(self, name): return MATCHING.findAll(name, self.models)
def get_materials_by_name(self, name): return MATCHING.findAll(name, self.materials)
def get_models_by_name(self, name): return MATCHING.findAll(name, self.models)
def getLayerByName(self, key): """Attempts to get layer(s) by string key""" layers = MATCHING.findAll(key, self.layers) if layers: return layers[0]