diff --git a/.coverage b/.coverage index 5925e174..d3bbacbc 100644 Binary files a/.coverage and b/.coverage differ diff --git a/io_mesh_w3d/common/utils/material_export.py b/io_mesh_w3d/common/utils/material_export.py index 3193a539..7ac4f08a 100644 --- a/io_mesh_w3d/common/utils/material_export.py +++ b/io_mesh_w3d/common/utils/material_export.py @@ -138,8 +138,11 @@ def retrieve_shader_material(context, material, principled, w3x=False): append_property(shader_mat, 1, 'DiffuseTexture', principled.base_color_texture) append_property(shader_mat, 1, 'NormalMap', principled.normalmap_texture) - if principled.normalmap_texture is not None: + if principled.normalmap_texture is not None and principled.normalmap_texture.image is not None: + if shader_mat.header.type_name == 'DefaultW3D.fx': + shader_mat.header.type_name = 'NormalMapped.fx' append_property(shader_mat, 2, 'BumpScale', principled.normalmap_strength, 1.0) + append_property(shader_mat, 1, 'SpecMap', principled.specular_texture) append_property(shader_mat, 7, 'CullingEnable', material.use_backface_culling) append_property(shader_mat, 2, 'Opacity', material.opacity) diff --git a/tests/common/cases/test_utils.py b/tests/common/cases/test_utils.py index 8ca664bf..1fc7ee35 100644 --- a/tests/common/cases/test_utils.py +++ b/tests/common/cases/test_utils.py @@ -144,6 +144,7 @@ def test_shader_material_type_name_fallback(self): for source in mesh.shader_materials: source.header.type_name = 'LoremIpsum' + source.properties = [] (material, principled) = create_material_from_shader_material( self, mesh.name(), source) @@ -151,6 +152,18 @@ def test_shader_material_type_name_fallback(self): source.header.type_name = 'DefaultW3D.fx' compare_shader_materials(self, source, actual) + def test_shader_material_type_name_upgrade_to_normal_mapped(self): + mesh = get_mesh(shader_mats=True) + + for source in mesh.shader_materials: + source.header.type_name = 'LoremIpsum' + + (material, principled) = create_material_from_shader_material( + self, mesh.name(), source) + actual = retrieve_shader_material(self, material, principled) + source.header.type_name = 'NormalMapped.fx' + compare_shader_materials(self, source, actual) + def test_shader_roundtrip(self): mesh = get_mesh()