示例#1
0
def create_mirror(brres_file_name,
                  working_folder='tmp',
                  mdl0_name=None,
                  new_file_name=None,
                  mirror_encoder=None):
    """Creates a mirror of the brres file by decoding and re-encoding the file
    :returns (original_brres, new_brres)
    """
    original = Brres(brres_file_name)
    if new_file_name is None:
        new_file_name = brres_file_name
    base_name = os.path.splitext(os.path.basename(new_file_name))[0]
    dae_file = os.path.join(working_folder, base_name + '.dae')
    DaeConverter(original, mdl_file=dae_file, mdl0=mdl0_name,
                 encode=False).convert()
    new_file_name = os.path.join(working_folder, base_name + '.brres')
    shutil.copyfile(brres_file_name, new_file_name)
    new_brres = Brres(new_file_name)
    my_mdl0 = original.get_model(
        mdl0_name) if mdl0_name else original.models[0]
    if mirror_encoder is None:
        mirror_encoder = MirrorEncoder(my_mdl0)
    else:
        mirror_encoder.mdl0 = my_mdl0
    DaeConverter(new_brres,
                 mdl_file=dae_file,
                 mdl0=mdl0_name,
                 encode=True,
                 encoder=mirror_encoder).convert()
    new_brres.save(overwrite=True)
    return original, new_brres
 def __init__(self, *args, **kwargs):
     self.brres = Brres('../brres_files/beginner_course.brres')
     self.poly = self.brres.models[0].objects[0]
     self.mat = self.poly.get_material()
     self.simple = Brres('../brres_files/simple.brres')
     self.output = '../brres_files/test.brres'
     super().__init__(*args, **kwargs)
示例#3
0
 def test_save_all(self):
     tmp = self._get_tmp()
     for x in gather_files(self.root):
         try:
             original = Brres(x)
             original.save(tmp, overwrite=True)
             new = Brres(tmp)
             self.assertEqual(original, new)
         except:
             print(f'ERROR saving {x}')
             raise
示例#4
0
 def setUpClass(self):
     self.brres = Brres('../brres_files/beginner_course.brres')
     self.original_model = self.brres.models[0]
     self.test_file = '../brres_files/test.brres'
     if os.path.exists(self.test_file):
         os.remove(self.test_file)
     self.brres.save(self.test_file, True)
     if not os.path.exists(self.test_file):
         raise Exception('Failed to save test file')
     self.test = Brres(self.test_file)
     self.test_model = self.test.models[0]
示例#5
0
 def __init__(self, path):
     if self.LIBRARY is not None:
         raise RuntimeError('Already Initialized library!')
     if path is None:
         path = os.path.join(os.getcwd(), 'mat_lib.brres')
         self.LIBRARY_PATH = path
     try:
         self.brres = Brres(path)
     except FileNotFoundError as e:
         AutoFix.get().info(f'Material library "{path}" not found, Creating file.')
         self.brres = Brres(path, readFile=False)
         self.brres.add_mdl0(Mdl0('lib', self.brres))
     self.on_brres_update()
示例#6
0
 def trace_path(self,
                brres_path=None,
                model_name=None,
                material_name=None,
                return_new_brres_flag=False):
     brres = mdl0 = material = None
     if brres_path is None:
         brres_path, model_name, material_name = self.split_path()
     if not brres_path:  # No such file
         return brres, mdl0, material
     brres = Brres.get_brres(brres_path)
     new_brres = False
     if not brres:
         brres = Brres(brres_path, readFile=False)
         new_brres = True
     if brres:
         if model_name:
             mdl0 = brres.getModel(model_name)
             if mdl0:
                 if material_name:
                     material = mdl0.get_material_by_name(material_name)
     if not return_new_brres_flag:
         return brres, mdl0, material
     else:
         return brres, mdl0, material, new_brres
示例#7
0
 def test_load_older_version(self):
     # This is just to test that it can convert, not that they convert equal
     converter = DaeConverter(self._get_brres('old_mario_gc_hayasi.brres'),
                              self._get_tmp('.dae'),
                              encode=False).convert()
     converter = DaeConverter(
         Brres(self._get_tmp('.brres'), read_file=False),
         converter.mdl_file).convert()
示例#8
0
def cmdline_convert(args, ext, converter_klass):
    file_in, file_out, overwrite = arg_parse(args)
    if file_in.ext == '.brres':
        if not file_out.ext:
            file_out.ext = ext
        brres = Brres(file_in.get_path())
        converter = converter_klass(brres, file_out.get_path())
        converter.save_model()
    elif file_in.ext.lower() == ext:
        b_path = file_out.get_path()
        brres = Brres(b_path, None, os.path.exists(b_path))
        converter = converter_klass(brres, file_in.get_path())
        converter.load_model()
        brres.save(None, overwrite)
    else:
        print('Unknown file {}, is the file extension {}?'.format(
            ext, file_in.ext))
        sys.exit(1)
示例#9
0
 def test_convert_with_json(self):
     brres = self._get_brres('beginner_course.brres')
     dae_file = self._get_test_fname('beginner.dae')
     converter = DaeConverter(
         Brres(self._get_tmp('.brres'), read_file=False), dae_file)
     converter.load_model()
     self._test_mats_equal(converter.brres.models[0].materials,
                           brres.models[0].materials,
                           sort=True)
示例#10
0
 def test_convert_multi_material_geometry(self):
     """Tests converting dae file that has multiple materials associated with geometry"""
     converter = DaeConverter(
         Brres(self._get_tmp('.brres'), read_file=False),
         self._get_test_fname('blender.dae'))
     converter.load_model()
     mdl0 = converter.brres.models[0]
     self.assertEqual(len(mdl0.materials), 2)
     self.assertEqual(len(mdl0.objects), 2)
示例#11
0
 def test_export_all_obj(self):
     tmp = self._get_tmp('.obj')
     for x in gather_files(self.root):
         try:
             converter = ObjConverter(Brres(x), tmp)
             for model in converter.brres.models:
                 converter.save_model(model)
         except:
             print(f'ERROR exporting {x}')
             raise
示例#12
0
 def setUpClass(cls):
     cls.brres = cls._get_brres('beginner_course.brres')
     cls.original_model = cls.brres.models[0]
     cls.test_file = cls._get_brres_fname('test.brres')
     if os.path.exists(cls.test_file):
         os.remove(cls.test_file)
     cls.brres.save(cls.test_file, True)
     if not os.path.exists(cls.test_file):
         raise Exception('Failed to save test file')
     cls.test = Brres(cls.test_file)
     cls.test_model = cls.test.models[0]
示例#13
0
 def test_export_import_dae_eq(self):
     AutoFix.set_fix_level(0, load_config.turn_off_fixes)
     tmp = self._get_tmp('.dae')
     tmp_brres = self._get_tmp('.brres')
     for x in gather_files(self.root):
         try:
             converter = DaeConverter(Brres(x), tmp)
             for model in converter.brres.models:
                 converter.save_model(model)
                 importer = DaeConverter(Brres(tmp_brres, read_file=False),
                                         tmp)
                 importer.load_model()
                 mats = sorted(model.materials, key=lambda x: x.name)
                 imported_mats = sorted(importer.mdl0.materials,
                                        key=lambda x: x.name)
                 self.assertTrue(node_eq(mats, imported_mats))
         except:
             print(f'ERROR converting {x}')
             if converter.brres.version == 11:
                 raise
示例#14
0
 def test_convert_cow(self):
     original = self._get_brres('cow.brres').models[1]
     converter = DaeConverter(
         Brres(self._get_tmp('.brres'), read_file=False),
         self._get_test_fname('cow.dae'))
     converter.load_model()
     mdl0 = converter.mdl0
     # converter.brres.save(overwrite=True)
     # Ensure that the bones are correct
     self.assertTrue(
         CheckPositions.bones_equal(original.bones, mdl0.bones, 0.0001))
示例#15
0
 def test_convert_single_bind_flip_y_z(self):
     original = self._get_brres('simple_multi_bone_single_bind.brres')
     converter = DaeConverter(
         Brres(self._get_tmp('.brres'), read_file=False),
         self._get_test_fname('blender_simple_multi_bone_single_bind.dae'))
     converter.load_model()
     # converter.brres.save(overwrite=True)
     original_polys = original.models[0].objects
     new_polys = converter.mdl0.objects
     for i in range(len(original_polys)):
         self.assertEqual(original_polys[i].linked_bone.index,
                          new_polys[i].linked_bone.index)
示例#16
0
 def test_convert_single_bone(self):
     original = self._get_brres('simple.brres')
     converter = DaeConverter(
         Brres(self._get_tmp('.brres'), read_file=False),
         self._get_test_fname('simple_multi_bone_single_bind.dae'),
         flags=DaeConverter.SINGLE_BONE)
     converter.load_model()
     mdl0 = converter.mdl0
     self.assertEqual(len(mdl0.bones), 1)
     self.assertTrue(
         CheckPositions.positions_equal(original.models[0].vertices,
                                        mdl0.vertices))
示例#17
0
 def create_or_open(filename):
     amount = len(Command.OPEN_FILES) - Command.MAX_FILES_OPEN
     if amount > 0:
         Command.auto_close(amount, [filename])
     if os.path.exists(filename):
         files = Command.updateFile(filename)
         b = files[0] if len(files) else None
     else:
         b = Brres(filename, readFile=False)
         Command.OPEN_FILES[filename] = b
         Command.ACTIVE_FILES = [b]
         Command.MODELS = []
     return b
示例#18
0
 def test_convert_to_correct_position(self):
     # Get reference to beginner_course to test against
     beginner_brres = self._get_brres('beginner_course.brres')
     original_vertices = beginner_brres.models[0].vertices
     # Convert dae
     brres = Brres(self._get_tmp('.brres'), read_file=False)
     dae = self._get_test_fname('beginner.dae')
     converter = DaeConverter(brres, dae)
     converter.load_model()
     # brres.save(overwrite=True)
     new_vertices = brres.models[0].vertices
     self.assertTrue(CheckPositions().positions_equal(
         original_vertices, new_vertices))
示例#19
0
 def test_open_close(self):
     dir = os.path.join(self.base_path, 'brres_files')
     output = os.path.join(dir, 'test.brres')
     for x in os.listdir(dir):
         current_file = os.path.join(dir, x)
         if current_file != output:
             if os.path.exists(output):
                 os.remove(output)
             if x.endswith('.brres'):
                 b = Brres(current_file)
                 b.save(output, True)
             self.assertTrue(os.path.exists(output))
     return True
示例#20
0
def compare_brres_files(filenames, ignore_offsets=None, start_at=None, target=None):
    if len(filenames) < 1:
        print('Nothing to compare!')
        return
    brres = {}
    for x in filenames:
        brres[x] = Brres(x)
    for i in range(len(filenames) - 1):
        f1 = filenames[i]
        for j in range(i + 1, len(filenames)):
            f2 = filenames[j]
            compare_two_brres(brres[f1], brres[f2])
            CompareBins((brres[f1], brres[f2]),
                        ignore_offsets=ignore_offsets, start_at=start_at, target=target).compare_two_binfiles()
示例#21
0
 def test_convert_multi_bone_single_bind(self):
     original = self._get_brres(
         'simple_multi_bone_single_bind.brres').models[0]
     converter = DaeConverter(
         Brres(self._get_tmp('.brres'), read_file=False),
         self._get_test_fname('simple_multi_bone_single_bind.dae'))
     converter.load_model()
     mdl0 = converter.mdl0
     # test bones
     self.assertEqual(4, len(mdl0.bones))
     CheckPositions.bones_equal(mdl0.bones, original.bones, 0.01, 0.001)
     # Ensure that the bones are correctly linked
     expected_linked_bones = {
         'BlackNWhite1': 'simple001_BNW',
         'BlackNWhite2': 'simple011',
         'GreenCloud': 'simple002_Green',
         'Yellow': 'simple'
     }
     for x in mdl0.objects:
         self.assertEqual(expected_linked_bones[x.name], x.linked_bone.name)
     self.assertTrue(
         CheckPositions.positions_equal(original.vertices, mdl0.vertices))
示例#22
0
文件: lib.py 项目: Robert-N7/abmatt
 def setUpClass(self):
     self.brres = Brres(self._get_brres_fname('simple.brres'))
示例#23
0
            if match_filter is None or fnmatch.fnmatch(file, match_filter):
                yield path


def get_project_root():
    directory = os.getcwd()
    while True:
        new_dir, name = os.path.split(directory)
        if name == 'abmatt':
            return directory
        directory = new_dir
        if not directory:
            break


if __name__ == '__main__':
    args = sys.argv[1:]
    filter = None
    if not len(args):
        root = os.getcwd()
        if os.path.basename(root) == 'debug':
            root = os.path.dirname(root)
            os.chdir(root)
    else:
        root = args.pop(0)
        if not os.path.exists(root) or not os.path.isdir(root):
            print('Invalid root path')
            sys.exit(1)
    for x in gather_files(root, filter):
        perform_analysis(Brres(x))
示例#24
0
 def test_save_moonview(self):
     self.assertTrue(self._abmatt('-b brres_files/simple.brres -d test_files/tmp.brres -o --moonview'))
     b = Brres(self._get_tmp('.brres', False))
     self.assertFalse(b.check_moonview())
     self.assertFalse(b.MOONVIEW)
示例#25
0
文件: lib.py 项目: Robert-N7/abmatt
 def setUpClass(cls):
     cls.brres = Brres(cls._get_brres_fname('beginner_course.brres'))
示例#26
0
文件: lib.py 项目: Robert-N7/abmatt
 def _get_brres(filename):
     if not filename.endswith('.brres'):
         filename += '.brres'
     return Brres(AbmattTest._get_brres_fname(filename))
示例#27
0
 def _test_save_eq(self, brres):
     tmp = self._get_tmp('.brres')
     brres.save(tmp, overwrite=True)
     return node_eq(Brres(tmp), brres)