diff --git a/src/blenderbim/blenderbim/bim/export_ifc.py b/src/blenderbim/blenderbim/bim/export_ifc.py index 691b097ea1..6cadbff734 100644 --- a/src/blenderbim/blenderbim/bim/export_ifc.py +++ b/src/blenderbim/blenderbim/bim/export_ifc.py @@ -126,7 +126,8 @@ class IfcExporter: continue try: if isinstance(obj, bpy.types.Material): - blenderbim.core.style.update_style_colours(tool.Ifc, tool.Style, obj=obj) + if self.has_changed_shading(obj): + blenderbim.core.style.update_style_colours(tool.Ifc, tool.Style, obj=obj) else: element = tool.Ifc.get_entity(obj) if element: @@ -148,6 +149,10 @@ class IfcExporter: checksum = obj.data.BIMMeshProperties.material_checksum return checksum != str([s.id() for s in tool.Geometry.get_styles(obj) if s]) + def has_changed_shading(self, obj): + checksum = obj.BIMMaterialProperties.shading_checksum + return checksum != repr(np.array(obj.diffuse_color).tobytes()) + def sync_object_placement(self, obj): if not tool.Ifc.is_moved(obj): return diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index c15f5ed543..f8b42ec162 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -1534,6 +1534,8 @@ class IfcImporter: if rendering_style and texture_style: self.create_surface_style_with_textures(blender_material, rendering_style, texture_style) + tool.Style.record_shading(blender_material) + def create_surface_style_shading(self, blender_material, surface_style): alpha = 1.0 # Transparency was added in IFC4 diff --git a/src/blenderbim/blenderbim/bim/prop.py b/src/blenderbim/blenderbim/bim/prop.py index 77940a5e73..3fdbbb8ac5 100644 --- a/src/blenderbim/blenderbim/bim/prop.py +++ b/src/blenderbim/blenderbim/bim/prop.py @@ -412,6 +412,7 @@ class BIMMaterialProperties(PropertyGroup): attributes: CollectionProperty(name="Attributes", type=Attribute) # In Blender, a material object can map to an IFC material, IFC surface style, or both ifc_style_id: IntProperty(name="IFC Style ID") + shading_checksum: StringProperty(name="Shading Checksum") class BIMMeshProperties(PropertyGroup): diff --git a/src/blenderbim/blenderbim/core/style.py b/src/blenderbim/blenderbim/core/style.py index e56f7dcc32..c08ba48d09 100644 --- a/src/blenderbim/blenderbim/core/style.py +++ b/src/blenderbim/blenderbim/core/style.py @@ -63,6 +63,8 @@ def update_style_colours(ifc, style, obj=None): else: ifc.run("style.add_surface_style", style=element, ifc_class="IfcSurfaceStyleShading", attributes=attributes) + style.record_shading(obj) + def update_style_textures(ifc, style, obj=None, representation=None): element = style.get_style(obj) diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index 29cfa18239..88ce1e018a 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -719,6 +719,7 @@ class Style: def import_presentation_styles(cls, style_type): pass def import_surface_attributes(cls, style, obj): pass def is_editing_styles(cls): pass + def record_shading(cls, obj): pass def select_elements(cls, elements): pass diff --git a/src/blenderbim/blenderbim/tool/style.py b/src/blenderbim/blenderbim/tool/style.py index 215433f71c..cfea6d1fce 100644 --- a/src/blenderbim/blenderbim/tool/style.py +++ b/src/blenderbim/blenderbim/tool/style.py @@ -17,6 +17,7 @@ # along with BlenderBIM Add-on. If not, see . import bpy +import numpy as np import ifcopenshell import blenderbim.core.tool import blenderbim.tool as tool @@ -203,6 +204,10 @@ class Style(blenderbim.core.tool.Style): def is_editing_styles(cls): return bpy.context.scene.BIMStylesProperties.is_editing + @classmethod + def record_shading(cls, obj): + obj.BIMMaterialProperties.shading_checksum = repr(np.array(obj.diffuse_color).tobytes()) + @classmethod def select_elements(cls, elements): for element in elements: diff --git a/src/blenderbim/test/core/test_style.py b/src/blenderbim/test/core/test_style.py index c11b7fec20..3ec61bd645 100644 --- a/src/blenderbim/test/core/test_style.py +++ b/src/blenderbim/test/core/test_style.py @@ -88,6 +88,7 @@ class TestUpdateStyleColours: style.get_surface_rendering_style("obj").should_be_called().will_return("style") style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes") ifc.run("style.edit_surface_style", style="style", attributes="attributes").should_be_called() + style.record_shading("obj").should_be_called() subject.update_style_colours(ifc, style, obj="obj") def test_adding_a_rendering_style_if_not_available(self, ifc, style): @@ -98,6 +99,7 @@ class TestUpdateStyleColours: ifc.run( "style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleRendering", attributes="attributes" ).should_be_called() + style.record_shading("obj").should_be_called() subject.update_style_colours(ifc, style, obj="obj") def test_updating_shading_style_as_a_fallback_if_available(self, ifc, style): @@ -106,6 +108,7 @@ class TestUpdateStyleColours: style.get_surface_shading_style("obj").should_be_called().will_return("style") style.get_surface_shading_attributes("obj").should_be_called().will_return("attributes") ifc.run("style.edit_surface_style", style="style", attributes="attributes").should_be_called() + style.record_shading("obj").should_be_called() subject.update_style_colours(ifc, style, obj="obj") def test_adding_a_shading_style_as_a_fallback_if_not_available(self, ifc, style): @@ -116,6 +119,7 @@ class TestUpdateStyleColours: ifc.run( "style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleShading", attributes="attributes" ).should_be_called() + style.record_shading("obj").should_be_called() subject.update_style_colours(ifc, style, obj="obj")