示例#1
0
 def rename(self):
     node = self.get_indexed_item(self.clicked_index)
     if self.level == 0:
         self.handler.save_as_dialog()
     elif self.level == 1:
         brres = node.parent
         old_name = node.name
         text, ok = QInputDialog.getText(self,
                                         'Rename Node',
                                         'Rename to:',
                                         text=old_name)
         if ok and text != old_name:
             if brres.get_model(text):
                 AutoFix.error(
                     'Model with name {} already exists!'.format(text))
                 return
             node.rename(text)
             self.handler.on_rename_update(node, old_name)
     elif self.level == 2:
         mdl0 = node.parent
         text, ok = QInputDialog.getText(self,
                                         'Rename Node',
                                         'Rename to:',
                                         text=node.name)
         if ok:
             if text in [x.name for x in mdl0.objects]:
                 AutoFix.error(
                     'Polygon with name {} already exists!'.format(text))
                 return
             node.rename(text)
示例#2
0
 def unpack(self, pt, binfile):
     start = binfile.start()
     l = binfile.readLen()
     binfile.advance(4)
     binfile.store()
     binfile.advance(4)
     pt.index, pt.comp_count, pt.format, pt.divisor, pt.stride, pt.count = binfile.read(
         '3I2BH', 16)
     if not self.is_valid_comp_count(pt.comp_count):
         AutoFix.error(
             '{} has invalid component count {}, using default {}'.format(
                 pt.name, pt.comp_count, pt.default_comp_count))
         pt.comp_count = pt.default_comp_count
     if not is_valid_format(pt.format):
         # determine the format using the file length
         binfile.recall(pop=False)
         old_format = pt.format
         bytes_remaining = start + l - binfile.offset
         width = bytes_remaining // (pt.count * pt.comp_count)
         if width >= 4:
             pt.format = point.FMT_FLOAT
         elif width >= 2:  # assumes unsigned
             pt.format = point.FMT_INT16
         else:
             pt.format = point.FMT_INT8
         AutoFix.error('{} has invalid format {}, using format {}'.format(
             pt.name, old_format, point.FMT_STR[pt.format]))
示例#3
0
 def set_pat0(self, anim):
     if self.pat0:
         AutoFix.error(
             'Multiple Pat0 for {} in {}!'.format(self.name,
                                                  self.getBrres().name), 1)
         return False
     self.pat0 = anim
     return True
示例#4
0
 def set_srt0(self, anim):
     """This is called by model to set up the srt0 reference"""
     if self.srt0:
         AutoFix.error('Multiple Srt0 for {}'.format(self.name), 1)
         return False
     self.srt0 = anim
     anim.set_material(self)
     return True
示例#5
0
 def _create_image_library(self, tex0s):
     if not tex0s:
         return True
     converter = ImgConverter()
     if not converter:
         AutoFix.error('No image converter found!')
         return False
     converter.batch_decode(tex0s, self.image_dir)
     return True
示例#6
0
 def try_parse(self, text):
     try:
         self.cmds_run.append(text)
         if len(self.cmds_run) > 10:
             self.cmds_run.pop(0)
         return Command.run_commands([Command(text)])
     except ParsingException as e:
         AutoFix.error(str(e))
         return False
示例#7
0
 def enqueue(self, converter):
     if converter == self.item:
         AutoFix.error('Conversion already in progress!')
         return False
     for x in self.queue:
         if x == converter:
             AutoFix.error('Conversion already in progress!')
             return False
     self.queue.append(converter)
     return True
示例#8
0
 def save_as_dialog(self):
     if self.brres:
         fname, filter = QFileDialog.getSaveFileName(
             self, 'Save as', self.cwd, 'Brres files (*.brres)')
         if fname:
             self.cwd = os.path.dirname(fname)
             self.brres.save(fname, overwrite=True)
             self.update_status('Wrote file {}'.format(fname))
     else:
         AutoFix.error('No Brres file selected.')
示例#9
0
 def rename(self, value):
     if self.parent:
         for x in self.parent.materials:
             if x is not self and x.name == value:
                 AutoFix.error(
                     'The name {} is already taken!'.format(value))
                 return False
     result = super().rename(value)
     if result and self.parent:
         self.parent.on_material_rename(self, value)
     return result
示例#10
0
 def on_submit(self):
     path = self.path_edit.text()
     dir = os.path.dirname(path)
     if not os.path.exists(dir):
         AutoFix.error('Path {} does not exist!'.format(path))
     else:
         ImgConverter().decode(self.tex0,
                               path,
                               overwrite=True,
                               num_mips=self.mipmap_count.value())
         AutoFix.info('Exported {} to {}'.format(self.tex0.name, path))
         self.close()
示例#11
0
 def save(self, dest, overwrite):
     if dest is None:
         dest = self.name
     ext = '.' + self.EXT
     if not dest.endswith(ext):
         dest += ext
     if os.path.exists(dest) and not overwrite and not self.OVERWRITE_MODE:
         AutoFix.error('{} already exists!'.format(dest))
         return
     bin = BinFile(dest, 'w')
     self.pack(bin)
     bin.commitWrite()
     return dest
示例#12
0
 def rename(self):
     if self.material is not None:
         current_name = self.material.name
         text, ok = QInputDialog.getText(self,
                                         'Rename Node',
                                         'Rename to:',
                                         text=current_name)
         if ok and text != current_name:
             if self.material.parent.get_material_by_name(text) is not None:
                 AutoFix.error(
                     'Material with name {} already exists!'.format(text))
                 return
             self.material.rename(text)
示例#13
0
文件: mdl0.py 项目: Robert-N7/abmatt
 def rename(self, name):
     for x in self.parent.models:
         if x is not self and x.name == name:
             AutoFix.error(
                 'Unable to rename {}, the model {} already exists!'.format(
                     self.name, name))
             return False
     old_name = self.name
     result = super().rename(name)
     if result:
         self.parent.on_model_rename(old_name, name)
         self.is_map_model = True if 'map' in name else False
     return result
示例#14
0
 def get_index_type(self, index):
     """
     Returns the INDEX_FORMAT
     """
     if index < 0:
         return INDEX_FORMAT_NONE
     else:
         try:
             return INDEX_FORMAT_BYTE if self.encode_str[
                 index + 1] == 'B' else INDEX_FORMAT_SHORT
         except IndexError:
             AutoFix.error(
                 f'Polygon {self.name} in {self.parent.parent.name} tri index {index} out of range.'
             )
示例#15
0
 def add_new_material(self, material):
     if self.brres is not None:
         model = self.brres.models[0]
         if model.get_material_by_name(material.name):
             AutoFix.error('Material {} already exists!'.format(
                 material.name))
             return False
         mat = Material(material.name, self.brres.models[0])
         mat.paste(material)
         self.brres.models[0].add_material(mat)
         self.brres.paste_material_tex0s(mat, material.getBrres())
         material = mat
         result = super().add_material(material)
         return result
     return super().add_material(material)
示例#16
0
 def import_map(self):
     fmt = self.format_box.currentText()
     mips = self.num_mips.value()
     path = self.path_edit.text()
     try:
         tex0 = ImgConverter().INSTANCE.encode(path,
                                               self.brres,
                                               tex_format=fmt,
                                               num_mips=mips)
         if not tex0:
             tex0 = self.brres.get_texture(
                 os.path.splitext(os.path.basename(path))[0])
         self.import_handler.on_import(tex0)
     except EncodeError as e:
         AutoFix.error(e)
     self.close()
示例#17
0
 def check(self):
     result = False
     # if self.comp_count > 3 and self.comp_count != 9:
     #     AutoFix.error('Geometry {} comp_count {} out of range'.format(self.name, self.comp_count))
     #     self.comp_count = 0
     #     result = True
     if self.divisor >= 16:
         AutoFix.error('Geometry {} divisor {} out of range'.format(
             self.name, self.divisor))
         self.divisor = 0
         result = True
     # if self.format > 5:
     #     AutoFix.error('Geometry {} format {} out of range'.format(self.name, self.format))
     #     self.format = 4
     #     result = True
     return result
示例#18
0
文件: brres.py 项目: Robert-N7/abmatt
 def save(self, filename=None, overwrite=None, check=True):
     if not filename:
         filename = self.name
     if overwrite is None:
         overwrite = self.OVERWRITE
     if not overwrite and os.path.exists(filename):
         AutoFix.error('File {} already exists!'.format(filename), 1)
     else:
         if check:
             self.check()
         f = BinFile(filename, mode="w")
         self.pack(f)
         if f.commitWrite():
             AutoFix.info("Wrote file '{}'".format(filename), 2)
             self.rename(filename)
             self.has_new_model = False
             self.mark_unmodified()
             return True
     return False
示例#19
0
文件: obj.py 项目: Robert-N7/abmatt
 def parse_file(self, filename):
     geometry = None
     self.start_new_geo = False
     with open(filename) as f:
         data = f.readlines()
         for line in data:
             if len(line) < 2 or line[0] == '#':
                 continue
             words = re.split(r'\s+', line.rstrip('\n').strip())
             new_geo = self.parse_words(words, geometry)
             if new_geo:
                 if not geometry or geometry.name != new_geo:
                     geometry = ObjGeometry(new_geo)
                     self.geometries.append(geometry)
                     self.start_new_geo = True
     if self.mtllib:
         try:
             self.parse_mat_lib(self.mtllib)
         except FileNotFoundError as e:
             AutoFix.error(str(e))
示例#20
0
 def __init__(self, tmp_dir=None):
     program = which('wimgt')
     self.cleanup = False
     if program:
         if os.name == 'nt':
             self.si = subprocess.STARTUPINFO()
             self.si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
         else:
             self.si = None
         if tmp_dir:
             self.set_tmp_dir(tmp_dir)
         elif not self.get_tmp_dir():
             self.set_tmp_dir(
                 os.path.join(os.getcwd(), str(uuid.uuid4())))
             self.cleanup = True
     else:
         AutoFix.error(
             'wimgt not found, please install Wiimms SZS Tools on your system path.'
         )
     super(ImgConverter.Wimgt, self).__init__(program)
示例#21
0
 def export_file_dialog(self, brres=None, mdl0=None):
     if mdl0 is not None:
         brres = mdl0.parent
     multiple_models = False
     if not brres:
         brres = self.brres
         if not brres:
             AutoFix.error('Nothing to export!')
             return
     elif mdl0 is None:
         if len(brres.models) > 1:
             multiple_models = True
     fname, fil = QFileDialog.getSaveFileName(self, 'Export model',
                                              self.cwd,
                                              'Model files (*.dae *.obj)')
     if fname:
         self.cwd, name = os.path.split(fname)
         base_name, ext = os.path.splitext(name)
         lower = ext.lower()
         if lower == '.obj':
             klass = ObjConverter
         elif lower == '.dae':
             klass = DaeConverter
         else:
             self.statusBar().showMessage(
                 'Unknown extension {}'.format(ext))
             return
         if multiple_models:
             for x in brres.models:
                 export_name = os.path.join(self.cwd,
                                            base_name + '-' + x.name + ext)
                 converter = klass(brres, export_name, encode=False, mdl0=x)
                 self.update_status('Added {} to queue...'.format(x.name))
                 self.converter.enqueue(converter)
         else:
             if mdl0 is None:
                 mdl0 = brres.models[0]
             converter = klass(brres, fname, encode=False, mdl0=mdl0)
             self.update_status('Added {} to queue...'.format(mdl0.name))
             self.converter.enqueue(converter)
示例#22
0
文件: color.py 项目: Robert-N7/abmatt
 def check(self):
     if not FMT_RGB565 <= self.format <= FMT_RGBA8:
         AutoFix.error(f'Color {self.name} has unknown color format.')
         self.format = 0
示例#23
0
def parse_args(argv, app_dir):
    interactive = overwrite = debug = False
    type = ""
    cmd_args = None
    command = destination = brres_file = command_file = model = value = key = ""
    autofix = loudness = None
    name = None
    no_normals = no_colors = single_bone = no_uvs = moonview = patch = False
    do_help = False
    for i in range(len(argv)):
        if argv[i][0] == '-':
            if i != 0:
                cmd_args = argv[:i]
                argv = argv[i:]
            break

    try:
        opts, args = getopt.gnu_getopt(argv, "ahd:oc:t:k:v:n:b:m:f:iul:g", [
            "auto-fix", "help", "destination=", "overwrite", "command=",
            "type=", "key=", "value=", "name=", "brres=", "model=", "file=",
            "interactive", "loudness=", "debug", "single-bone", "no-colors",
            "no-normals", "no-uvs", "moonview", "patch"
        ])
    except getopt.GetoptError as e:
        print(e)
        print(USAGE)
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            do_help = True
        elif opt in ('-b', '--brres'):
            brres_file = arg
        elif opt in ("-f", "--file"):
            command_file = arg
        elif opt in ("-d", "--destination"):
            destination = arg
        elif opt in ("-o", "--overwrite"):
            overwrite = True
        elif opt in ("-k", "--key"):
            key = arg
        elif opt in ("-v", "--value"):
            value = arg
        elif opt in ("-t", "--type"):
            type = arg
        elif opt in ("-n", "--name"):
            name = arg
        elif opt in ("-m", "--model"):
            model = arg
        elif opt in ("-c", "--command"):
            command = arg
        elif opt in ("-i", "--interactive"):
            interactive = True
        elif opt in ("-a", "--auto-fix"):
            autofix = arg
        elif opt in ("-l", "--loudness"):
            loudness = arg
        elif opt in ("-g", "--debug"):
            debug = True
        elif opt == '--single-bone':
            single_bone = True
        elif opt == '--no-normals':
            no_normals = True
        elif opt == '--no-colors':
            no_colors = True
        elif opt == '--no-uvs':
            no_uvs = True
        elif opt == '--patch':
            patch = True
        elif opt == '--moonview':
            moonview = True
        else:
            print("Unknown option '{}'".format(opt))
            print(USAGE)
            sys.exit(2)
    if args:
        if cmd_args:
            cmd_args.extend(args)
        else:
            cmd_args = args
    if do_help:
        if not command and cmd_args:
            command = cmd_args[0]
        hlp(command)
        sys.exit()

    app_dir = os.path.dirname(os.path.dirname(app_dir))
    while not os.path.exists(os.path.join(app_dir, 'etc')):
        app_dir = os.path.dirname(app_dir)
        if not app_dir:
            AutoFix.error('Failed to find folder "etc"')
            break
    if debug and loudness is None:
        loudness = 5
    if app_dir:
        app_dir = os.path.join(app_dir, 'etc', 'abmatt')
        config = load_config(app_dir, loudness, autofix)
    Command.APP_DIR = app_dir
    Command.DEBUG = debug
    Brres.MOONVIEW = moonview
    cmds = []
    if cmd_args:
        if cmd_args[0] == 'convert':
            if single_bone:
                cmd_args.append('--single-bone')
            if no_colors:
                cmd_args.append('--no-colors')
            if no_normals:
                cmd_args.append('--no-normals')
            if no_uvs:
                cmd_args.append('--no-uvs')
            if patch:
                cmd_args.append('--patch')
        cmds.append(Command(arg_list=cmd_args))
    if command:
        args = [command, type]
        if key:
            if value:
                args.append(key + ':' + value)
            else:
                args.append(key)
        if not name and key != 'keys':
            name = '*'
        if name or model:
            args.extend(['for', name])
            if model:
                args.extend(['in', 'model', model])
        if command == 'convert':
            if single_bone:
                args.append('--single-bone')
            if no_colors:
                args.append('--no-colors')
            if no_normals:
                args.append('--no-normals')
            if no_uvs:
                args.append('--no-uvs')
            if patch:
                args.append('--patch')
        cmds.append(Command(arg_list=args))
    if destination:
        Command.DESTINATION = destination
        Brres.DESTINATION = destination
    if overwrite:
        Command.OVERWRITE = overwrite
        Brres.OVERWRITE = overwrite
    if brres_file:
        try:
            Command.updateSelection(brres_file)
        except NoSuchFile as e:
            AutoFix.exception(e, True)

    if command_file:
        try:
            filecmds = Command.load_commandfile(command_file)
            if filecmds:
                cmds = cmds + filecmds
        except NoSuchFile as err:
            AutoFix.error(err)

    # Run Commands
    if cmds:
        if not Command.run_commands(cmds):
            sys.exit(1)
    if interactive:
        Shell().cmdloop('Interactive shell started...')
    return Brres.OPEN_FILES