def n_create_normal_map(n_nitexturingproperty): """Adds a diffuse texture to a NiTexturingProperty""" n_nitexturingproperty.has_normal_texture = True n_nisourcetexture = NifFormat.NiSourceTexture() file_path = 'textures' + path.sep + 'normal' + path.sep + 'normal.dds' n_nisourcetexture.file_name = file_path.encode() n_nisourcetexture.pixel_layout = NifFormat.PixelLayout.PIX_LAY_DEFAULT # 6 n_nisourcetexture.use_mipmaps = 1 with ref(n_nitexturingproperty.normal_texture) as n_texdesc: n_texdesc.source = n_nisourcetexture
def export_source_texture(self, texture=None, filename=None): """Export a NiSourceTexture. :param texture: The texture object in blender to be exported. :param filename: The full or relative path to the texture file (this argument is used when exporting NiFlipControllers and when exporting default shader slots that have no use in being imported into Blender). :return: The exported NiSourceTexture block. """ # create NiSourceTexture srctex = NifFormat.NiSourceTexture() srctex.use_external = True if not filename is None: # preset filename srctex.file_name = filename elif not texture is None: srctex.file_name = self.export_texture_filename(texture) else: # this probably should not happen NifLog.warn( "Exporting source texture without texture or filename (bug?).") # fill in default values (TODO: can we use 6 for everything?) if bpy.context.scene.niftools_scene.nif_version >= 0x0A000100: srctex.pixel_layout = 6 else: srctex.pixel_layout = 5 srctex.use_mipmaps = 1 srctex.alpha_format = 3 srctex.unknown_byte = 1 # search for duplicate for block in self.nif_export.nif_export.dict_blocks: if isinstance(block, NifFormat.NiSourceTexture) and block.get_hash( ) == srctex.get_hash(): return block # no identical source texture found, so use and register # the new one return self.nif_export.nif_export.objecthelper.register_block( srctex, texture)
def n_create_bump_map_property(n_nitexturingproperty): """Adds a bumpmap texture to a NiTexturingProperty""" n_nitexturingproperty.has_bump_map_texture = True n_nitexturingproperty.bump_map_luma_scale = 1.0 n_nitexturingproperty.bump_map_luma_offset = 0.0 n_nitexturingproperty.bump_map_matrix.m_11 = 1.0 n_nitexturingproperty.bump_map_matrix.m_12 = 0.0 n_nitexturingproperty.bump_map_matrix.m_21 = 0.0 n_nitexturingproperty.bump_map_matrix.m_22 = 1.0 n_nisourcetexture = NifFormat.NiSourceTexture() file_path = 'textures' + path.sep + 'bump' + path.sep + 'bump.dds' n_nisourcetexture.file_name = file_path.encode() n_nisourcetexture.pixel_layout = NifFormat.PixelLayout.PIX_LAY_DEFAULT # 6 n_nisourcetexture.use_mipmaps = 1 with ref(n_nitexturingproperty.bump_map_texture) as n_texdesc: n_texdesc.source = n_nisourcetexture
def n_create_base_nisourcetexture(file_path): n_nisourcetexture = NifFormat.NiSourceTexture() n_nisourcetexture.file_name = file_path.encode() n_nisourcetexture.pixel_layout = NifFormat.PixelLayout.PIX_LAY_DEFAULT # 6 n_nisourcetexture.use_mipmaps = 1 return n_nisourcetexture