示例#1
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)
示例#2
0
 def load(self):
     """Loads the json file
     :returns materials loaded
     """
     with open(self.filename, 'r') as f:
         self.materials_by_name = json.loads(f.read())
     materials = [
         self.__load_material(Material(x), self.materials_by_name[x])
         for x in self.materials_by_name
     ]
     return materials
 def test_export_and_load_are_equal(self):
     temp = self._get_test_fname('tmp.json')
     materials = self.brres.models[0].materials
     exporter = MatsToJsonConverter(temp)
     exporter.export(materials)
     updated = [Material(x.name) for x in materials]
     importer = MatsToJsonConverter(temp)
     mats = importer.load()
     importer.load_into(updated)
     self.assertTrue(self._test_mats_equal(materials, updated))
     self.assertTrue(self._test_mats_equal(materials, mats))
示例#4
0
文件: brres.py 项目: Robert-N7/abmatt
 def check_moonview(self):
     if not self.models:
         return True
     mat_names = [
         'Goal_Merg', 'Iwa', 'Iwa_alfa', 'Nuki_Ryoumen', 'WallMerg00',
         'moon_kabe0000', 'moon_road00', 'road', 'road01', 'road02',
         'road03', 'siba00'
     ]
     materials = self.models[0].materials
     # First check if there's any modification needed
     j = 0
     for i in range(len(materials)):
         if materials[i].name == mat_names[j]:
             j += 1
     # Now rename
     if j != len(mat_names):
         b = Bug(3, 3, 'Incorrect material names for ridgehighway_course',
                 'Renaming materials')
         for i in range(len(mat_names)):
             if i < len(materials):
                 if materials[i].name != mat_names[i]:
                     material = self.models[0].get_material_by_name(
                         mat_names[i])
                     if material:
                         material.rename(
                             Material.get_unique_material(
                                 'material',
                                 self.models[0],
                                 get_name_only=True))
                     materials[i].rename(mat_names[i])
             else:
                 self.models[0].add_material(
                     Material.get_unique_material(mat_names[i],
                                                  self.models[0]))
         b.resolve()
     return j != len(mat_names)
示例#5
0
文件: mdl0.py 项目: Robert-N7/abmatt
 def update_polygon_material(self, polygon, old_mat, new_mat):
     # polys = self.get_polys_using_material(old_mat)
     if new_mat.parent is not self:  # is it a material not in the model already?
         test = self.get_material_by_name(new_mat.name)
         if new_mat.parent is not None:
             new_brres = new_mat.parent.parent
             my_brres = self.parent
             if my_brres is not None and new_brres is not None:
                 my_brres.paste_material_tex0s(new_mat, new_brres)
         if test == new_mat:  # already have this material?
             new_mat = test
         else:
             m = Material.get_unique_material(new_mat.name, self)
             self.add_material(m)
             m.paste(new_mat)
             new_mat = m
     new_mat.add_poly_ref(polygon)
     old_mat.remove_poly_ref(polygon)
     polygon.material = new_mat
     if not len(old_mat.polygons):
         self.materials.remove(old_mat)
     # self.mark_modified()
     return new_mat
示例#6
0
 def __init__(self, name, node, binfile):
     mat = Material(name, node, binfile)
     self.layers = []
     super().__init__(mat, binfile)