From 83f5a9e431e5ab8c0a5df1f9555916d7851745e0 Mon Sep 17 00:00:00 2001 From: HenryOfCarim Date: Sun, 4 Aug 2024 17:11:33 +0300 Subject: [PATCH] Add LOD selection dialog (#117) RE6 has a problem: unlike other games it uses LOD3 for storing hands, so just to import them a user needs to enable all LODs, so this PR adds an option to import all LODs and uses per game presets for loading main LODs. --- albam/blender_ui/import_panel.py | 22 ++++++++++++++++++++++ albam/engines/mtfw/mesh.py | 12 ++++++++++-- albam/engines/mtfw/texture.py | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/albam/blender_ui/import_panel.py b/albam/blender_ui/import_panel.py index 63b7e74e..6147206a 100644 --- a/albam/blender_ui/import_panel.py +++ b/albam/blender_ui/import_panel.py @@ -344,4 +344,26 @@ def draw(self, context): self.layout.separator() row = self.layout.row() row.operator("albam.import_vfile", text="Import") + row.operator("wm.import_options", icon="OPTIONS", text="") self.layout.row() + + +@blender_registry.register_blender_type +class ALBAM_WM_OT_ImportOptions(bpy.types.Operator): + """Set settings for importing""" + bl_label = "Import Options" + bl_idname = "wm.import_options" + + import_main_lods_bool = bpy.props.BoolProperty( + name="Import main LODs only", + description="Allows to import only the most detailed meshes", + default=True) + import_only_main_lods: import_main_lods_bool + + def execute(self, context): + import_settings = context.scene.albam.import_settings + import_settings.import_only_main_lods = self.import_only_main_lods + return {'FINISHED'} + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) diff --git a/albam/engines/mtfw/mesh.py b/albam/engines/mtfw/mesh.py index 61f1f266..24be7696 100644 --- a/albam/engines/mtfw/mesh.py +++ b/albam/engines/mtfw/mesh.py @@ -280,7 +280,14 @@ VERSIONS_USE_BONE_PALETTES = {156} VERSIONS_BONES_BBOX_AFFECTED = {210, 211} VERSIONS_USE_TRISTRIPS = {156} -MAIN_LODS = {1, 255} +MAIN_LODS = { + "re0": [1, 255], + "re1": [1, 255], + "re5": [1, 255], + "re6": [1, 3, 255], + "rev1": [1, 255], + "rev2": [1, 255], +} @blender_registry.register_import_function(app_id="re0", extension="mod", file_category="MESH") @@ -307,9 +314,10 @@ def build_blender_model(file_list_item, context): bl_object = skeleton or bpy.data.objects.new(bl_object_name, None) materials = build_blender_materials( file_list_item, context, mod, bl_object_name) + imported_lods = MAIN_LODS.get(app_id) for i, mesh in enumerate(mod.meshes_data.meshes): - if import_settings.import_only_main_lods and mesh.level_of_detail not in MAIN_LODS: + if import_settings.import_only_main_lods and mesh.level_of_detail not in imported_lods: continue try: name = f"{bl_object_name}_{str(i).zfill(4)}" diff --git a/albam/engines/mtfw/texture.py b/albam/engines/mtfw/texture.py index 08303e9f..5c5f2c23 100644 --- a/albam/engines/mtfw/texture.py +++ b/albam/engines/mtfw/texture.py @@ -308,7 +308,7 @@ def assign_textures(mtfw_material, bl_material, textures, mrl): if texture_target is not None: texture_node.image = texture_target texture_code_to_blender_texture(tex_type_blender.value, texture_node, bl_material, None) - if tex_type_blender.value in NON_SRGB_IMAGE_TYPE: + if tex_index and tex_type_blender.value in NON_SRGB_IMAGE_TYPE: texture_node.image.colorspace_settings.name = "Non-Color" except IndexError: print(f"tex_index {tex_index} not found. Texture len(): {len(textures)}")