From 54fc15756032bdd43f3bca2f182b49d7cef6630c Mon Sep 17 00:00:00 2001 From: Mahid Sheikh Date: Sun, 7 Jan 2024 06:43:28 +0000 Subject: [PATCH 1/2] Fixed incorrect keyword argument --- MCprep_addon/materials/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCprep_addon/materials/generate.py b/MCprep_addon/materials/generate.py index 2c63bd3a..86b58866 100644 --- a/MCprep_addon/materials/generate.py +++ b/MCprep_addon/materials/generate.py @@ -349,7 +349,7 @@ def set_texture_pack( image_data = util.loadTexture(image) _ = set_cycles_texture( - image_data, material, use_extra_passes=use_extra_passes) + image_data, material, extra_passes=use_extra_passes) return 1 From 29df266f83f4810d15ffe8f378f32385787dc774 Mon Sep 17 00:00:00 2001 From: "Patrick W. Crawford" Date: Mon, 8 Jan 2024 20:09:27 -0800 Subject: [PATCH 2/2] Added swap texture pack test --- test_files/materials_test.py | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test_files/materials_test.py b/test_files/materials_test.py index 865c51bc..de154cea 100644 --- a/test_files/materials_test.py +++ b/test_files/materials_test.py @@ -26,6 +26,7 @@ import bpy from bpy.types import Material +from MCprep_addon import util from MCprep_addon.materials import generate from MCprep_addon.materials import sequences from MCprep_addon.materials.generate import find_additional_passes @@ -875,6 +876,48 @@ def test_replace_missing_images_animated(self): self.assertEqual(node.image.source, "SEQUENCE", "Ensure updated material is an image sequence") + def test_swap_texture_pack(self): + """End to end test of swap texture pack.""" + self._set_test_mcprep_texturepack_path() + new_mat, _ = self._create_canon_mat("diamond_ore", test_pack=True) + + bpy.ops.mesh.primitive_plane_add() + obj = bpy.context.object + obj.active_material = new_mat + self.assertIsNotNone(obj.active_material, "Material should be applied") + + # Ensure if no texture pack selected, it fails. + addon_prefs = util.get_user_preferences(bpy.context) + addon_prefs.MCprep_exporter_type = "(choose)" + with self.assertRaises(RuntimeError): + res = bpy.ops.mcprep.swap_texture_pack( + filepath=bpy.context.scene.mcprep_texturepack_path) + + # Now run in scenario where a valid selection is made. + with self.subTest("jmc2obj_noprep"): + addon_prefs.MCprep_exporter_type = "jmc2obj" + res = bpy.ops.mcprep.swap_texture_pack( + filepath=bpy.context.scene.mcprep_texturepack_path, + prepMaterials=False) + self.assertTrue(res, {"FINISHED"}) + + # And again with prep materials on + with self.subTest("jmc2obj_withprep"): + res = bpy.ops.mcprep.swap_texture_pack( + filepath=bpy.context.scene.mcprep_texturepack_path, + prepMaterials=True) + self.assertTrue(res, {"FINISHED"}) + + # And for good coverage, let's do an example for mineways + with self.subTest("Mineways_withprep"): + new_mat, _ = self._create_canon_mat("diamond_ore", test_pack=True) + obj.active_material = new_mat + addon_prefs.MCprep_exporter_type = "Mineways" + res = bpy.ops.mcprep.swap_texture_pack( + filepath=bpy.context.scene.mcprep_texturepack_path, + prepMaterials=True) + self.assertTrue(res, {"FINISHED"}) + if __name__ == '__main__': unittest.main(exit=False)