def n_attach_material_prop(n_trishape): '''Attaches a NiMaterialProperty to a NiTrishape block property's array at pos[0]''' n_nimaterialprop = NifFormat.NiMaterialProperty() n_nimaterialprop.name = b'Material' with ref(n_nimaterialprop.ambient_color) as n_color3: n_color3.r = 1.0 n_color3.g = 1.0 n_color3.b = 1.0 with ref(n_nimaterialprop.diffuse_color) as n_color3: n_color3.r = 1.0 n_color3.g = 1.0 n_color3.b = 1.0 with ref(n_nimaterialprop.emissive_color) as n_color3: n_color3.r = 0.0 n_color3.g = 0.0 n_color3.b = 0.0 with ref(n_nimaterialprop.specular_color) as n_color3: n_color3.r = 0.0 n_color3.g = 0.0 n_color3.b = 0.0 n_nimaterialprop.glossiness = 12.5 # default nif.xml - 0.0, blender - 12.5 n_nimaterialprop.alpha = 1.0 # default nif.xml - 0.0 # add property to top of list n_trishape.properties.reverse() n_trishape.num_properties += 1 n_trishape.properties.update_size() n_trishape.properties[-1] = n_nimaterialprop n_trishape.properties.reverse()
def n_attach_material_prop(self, n_block): '''Attach a NiMaterialProperty to a blocks properties array at pos[0]''' n_nimaterialprop = NifFormat.NiMaterialProperty() # add property to top of list n_block.properties.reverse() n_block.num_properties += 1 n_block.properties.update_size() n_block.properties[-1] = n_nimaterialprop n_block.properties.reverse() n_nimaterialprop.name = b'Material' with ref(n_nimaterialprop.ambient_color) as ambient_color: ambient_color.r = 1.0 ambient_color.g = 1.0 ambient_color.b = 1.0 with ref(n_nimaterialprop.diffuse_color) as diffuse_color: diffuse_color.r = 1.0 diffuse_color.g = 1.0 diffuse_color.b = 1.0 with ref(n_nimaterialprop.emissive_color) as emissive_color: emissive_color.r = 0.5 n_nimaterialprop.glossiness = 25.0 n_nimaterialprop.alpha = 1.0 return n_block
def export_material_property(self, name, flags, ambient, diffuse, specular, emissive, gloss, alpha, emitmulti): """Return existing material property with given settings, or create a new one if a material property with these settings is not found.""" # create block (but don't register it yet in self.dict_blocks) matprop = NifFormat.NiMaterialProperty() # list which determines whether the material name is relevant or not # only for particular names this holds, such as EnvMap2 # by default, the material name does not affect rendering # TODO: Redact the specialnames check in favor of custom variable specialnames = ("EnvMap2", "EnvMap", "skin", "Hair", "dynalpha", "HideSecret", "Lava") # hack to preserve EnvMap2, skinm, ... named blocks (even if they got # renamed to EnvMap2.xxx or skin.xxx on import) if self.nif_export.properties.game in ('OBLIVION', 'FALLOUT_3', 'SKYRIM'): for specialname in specialnames: if (name.lower() == specialname.lower() or name.lower().startswith(specialname.lower() + ".")): if name != specialname: self.nif_export.warning( "Renaming material '%s' to '%s'" % (name, specialname)) name = specialname # clear noname materials if name.lower().startswith("noname"): self.nif_export.warning("Renaming material '%s' to ''" % name) name = "" matprop.name = name matprop.flags = flags matprop.ambient_color.r = ambient.r matprop.ambient_color.g = ambient.g matprop.ambient_color.b = ambient.b matprop.diffuse_color.r = diffuse.r matprop.diffuse_color.g = diffuse.g matprop.diffuse_color.b = diffuse.b matprop.specular_color.r = specular.r matprop.specular_color.g = specular.g matprop.specular_color.b = specular.b matprop.emissive_color.r = emissive.r matprop.emissive_color.g = emissive.g matprop.emissive_color.b = emissive.b matprop.glossiness = gloss matprop.alpha = alpha matprop.emit_multi = emitmulti # search for duplicate # (ignore the name string as sometimes import needs to create different # materials even when NiMaterialProperty is the same) for block in self.nif_export.dict_blocks: if not isinstance(block, NifFormat.NiMaterialProperty): continue # when optimization is enabled, ignore material name if self.nif_export.EXPORT_OPTIMIZE_MATERIALS: ignore_strings = not (block.name in specialnames) else: ignore_strings = False # check hash first_index = 1 if ignore_strings else 0 if (block.get_hash()[first_index:] == matprop.get_hash() [first_index:]): self.nif_export.warning( "Merging materials '%s' and '%s', they are identical in nif" % (matprop.name, block.name)) return block # no material property with given settings found, so use and register # the new one return matprop
def setup_class(cls): print(f"Class setup: {cls:s}") cls.ni_mat_prop = NifFormat.NiMaterialProperty() cls.ni_mat_prop1 = NifFormat.NiMaterialProperty() cls.ni_texture_prop = NifFormat.NiTexturingProperty()
def setup_class(cls): print("Class setup: " + str(cls)) cls.niBlock = None cls.nimatprop = NifFormat.NiMaterialProperty() cls.nimatprop1 = NifFormat.NiMaterialProperty() cls.nitextureprop = NifFormat.NiTexturingProperty()
def export_material_property(self, b_mat, flags=0x0001): """Return existing material property with given settings, or create a new one if a material property with these settings is not found.""" # don't export material properties for these games if bpy.context.scene.niftools_scene.game in ('SKYRIM', ): return name = block_store.get_full_name(b_mat) # create n_block n_mat_prop = NifFormat.NiMaterialProperty() # list which determines whether the material name is relevant or not only for particular names this holds, # such as EnvMap2 by default, the material name does not affect rendering specialnames = ("EnvMap2", "EnvMap", "skin", "Hair", "dynalpha", "HideSecret", "Lava") # hack to preserve EnvMap2, skinm, ... named blocks (even if they got renamed to EnvMap2.xxx or skin.xxx on import) if bpy.context.scene.niftools_scene.game in ('OBLIVION', 'FALLOUT_3', 'SKYRIM'): for specialname in specialnames: if name.lower() == specialname.lower() or name.lower( ).startswith(specialname.lower() + "."): if name != specialname: NifLog.warn( f"Renaming material '{name}' to '{specialname}'") name = specialname # clear noname materials if name.lower().startswith("noname"): NifLog.warn(f"Renaming material '{name}' to ''") name = "" n_mat_prop.name = name # TODO: - standard flag, check? material and texture properties in morrowind style nifs had a flag n_mat_prop.flags = flags ambient = b_mat.niftools.ambient_color n_mat_prop.ambient_color.r = ambient.r n_mat_prop.ambient_color.g = ambient.g n_mat_prop.ambient_color.b = ambient.b # todo [material] some colors in the b2.8 api allow rgb access, others don't - why?? # diffuse mat n_mat_prop.diffuse_color.r, n_mat_prop.diffuse_color.g, n_mat_prop.diffuse_color.b, _ = b_mat.diffuse_color n_mat_prop.specular_color.r, n_mat_prop.specular_color.g, n_mat_prop.specular_color.b = b_mat.specular_color emissive = b_mat.niftools.emissive_color n_mat_prop.emissive_color.r = emissive.r n_mat_prop.emissive_color.g = emissive.g n_mat_prop.emissive_color.b = emissive.b # gloss mat 'Hardness' scrollbar in Blender, takes values between 1 and 511 (MW -> 0.0 - 128.0) n_mat_prop.glossiness = b_mat.specular_intensity n_mat_prop.alpha = b_mat.niftools.emissive_alpha.v # todo [material] this float is used by FO3's material properties # n_mat_prop.emit_multi = emitmulti # search for duplicate # (ignore the name string as sometimes import needs to create different materials even when NiMaterialProperty is the same) for n_block in block_store.block_to_obj: if not isinstance(n_block, NifFormat.NiMaterialProperty): continue # when optimization is enabled, ignore material name if EXPORT_OPTIMIZE_MATERIALS: ignore_strings = not (n_block.name in specialnames) else: ignore_strings = False # check hash first_index = 1 if ignore_strings else 0 if n_block.get_hash()[first_index:] == n_mat_prop.get_hash( )[first_index:]: NifLog.warn( f"Merging materials '{n_mat_prop.name}' and '{n_block.name}' (they are identical in nif)" ) n_mat_prop = n_block break block_store.register_block(n_mat_prop) # material animation self.material_anim.export_material(b_mat, n_mat_prop) # no material property with given settings found, so use and register the new one return n_mat_prop