示例#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
示例#2
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, read_file=False)
         new_brres = True
     if brres:
         if model_name:
             mdl0 = brres.get_model(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