mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 01:11:40 +00:00
Fix #2823. Only update colours if you actually change them.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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:
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user