mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-06 20:36:27 +00:00
Fix #2823. Only update colours if you actually change them.
This commit is contained in:
@@ -126,7 +126,8 @@ class IfcExporter:
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
if isinstance(obj, bpy.types.Material):
|
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:
|
else:
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
if element:
|
if element:
|
||||||
@@ -148,6 +149,10 @@ class IfcExporter:
|
|||||||
checksum = obj.data.BIMMeshProperties.material_checksum
|
checksum = obj.data.BIMMeshProperties.material_checksum
|
||||||
return checksum != str([s.id() for s in tool.Geometry.get_styles(obj) if s])
|
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):
|
def sync_object_placement(self, obj):
|
||||||
if not tool.Ifc.is_moved(obj):
|
if not tool.Ifc.is_moved(obj):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1534,6 +1534,8 @@ class IfcImporter:
|
|||||||
if rendering_style and texture_style:
|
if rendering_style and texture_style:
|
||||||
self.create_surface_style_with_textures(blender_material, rendering_style, 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):
|
def create_surface_style_shading(self, blender_material, surface_style):
|
||||||
alpha = 1.0
|
alpha = 1.0
|
||||||
# Transparency was added in IFC4
|
# Transparency was added in IFC4
|
||||||
|
|||||||
@@ -412,6 +412,7 @@ class BIMMaterialProperties(PropertyGroup):
|
|||||||
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
||||||
# In Blender, a material object can map to an IFC material, IFC surface style, or both
|
# In Blender, a material object can map to an IFC material, IFC surface style, or both
|
||||||
ifc_style_id: IntProperty(name="IFC Style ID")
|
ifc_style_id: IntProperty(name="IFC Style ID")
|
||||||
|
shading_checksum: StringProperty(name="Shading Checksum")
|
||||||
|
|
||||||
|
|
||||||
class BIMMeshProperties(PropertyGroup):
|
class BIMMeshProperties(PropertyGroup):
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ def update_style_colours(ifc, style, obj=None):
|
|||||||
else:
|
else:
|
||||||
ifc.run("style.add_surface_style", style=element, ifc_class="IfcSurfaceStyleShading", attributes=attributes)
|
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):
|
def update_style_textures(ifc, style, obj=None, representation=None):
|
||||||
element = style.get_style(obj)
|
element = style.get_style(obj)
|
||||||
|
|||||||
@@ -719,6 +719,7 @@ class Style:
|
|||||||
def import_presentation_styles(cls, style_type): pass
|
def import_presentation_styles(cls, style_type): pass
|
||||||
def import_surface_attributes(cls, style, obj): pass
|
def import_surface_attributes(cls, style, obj): pass
|
||||||
def is_editing_styles(cls): pass
|
def is_editing_styles(cls): pass
|
||||||
|
def record_shading(cls, obj): pass
|
||||||
def select_elements(cls, elements): pass
|
def select_elements(cls, elements): pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import numpy as np
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import blenderbim.core.tool
|
import blenderbim.core.tool
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
@@ -203,6 +204,10 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
def is_editing_styles(cls):
|
def is_editing_styles(cls):
|
||||||
return bpy.context.scene.BIMStylesProperties.is_editing
|
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
|
@classmethod
|
||||||
def select_elements(cls, elements):
|
def select_elements(cls, elements):
|
||||||
for element in 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_style("obj").should_be_called().will_return("style")
|
||||||
style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes")
|
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()
|
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")
|
subject.update_style_colours(ifc, style, obj="obj")
|
||||||
|
|
||||||
def test_adding_a_rendering_style_if_not_available(self, ifc, style):
|
def test_adding_a_rendering_style_if_not_available(self, ifc, style):
|
||||||
@@ -98,6 +99,7 @@ class TestUpdateStyleColours:
|
|||||||
ifc.run(
|
ifc.run(
|
||||||
"style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleRendering", attributes="attributes"
|
"style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleRendering", attributes="attributes"
|
||||||
).should_be_called()
|
).should_be_called()
|
||||||
|
style.record_shading("obj").should_be_called()
|
||||||
subject.update_style_colours(ifc, style, obj="obj")
|
subject.update_style_colours(ifc, style, obj="obj")
|
||||||
|
|
||||||
def test_updating_shading_style_as_a_fallback_if_available(self, ifc, style):
|
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_style("obj").should_be_called().will_return("style")
|
||||||
style.get_surface_shading_attributes("obj").should_be_called().will_return("attributes")
|
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()
|
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")
|
subject.update_style_colours(ifc, style, obj="obj")
|
||||||
|
|
||||||
def test_adding_a_shading_style_as_a_fallback_if_not_available(self, ifc, style):
|
def test_adding_a_shading_style_as_a_fallback_if_not_available(self, ifc, style):
|
||||||
@@ -116,6 +119,7 @@ class TestUpdateStyleColours:
|
|||||||
ifc.run(
|
ifc.run(
|
||||||
"style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleShading", attributes="attributes"
|
"style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleShading", attributes="attributes"
|
||||||
).should_be_called()
|
).should_be_called()
|
||||||
|
style.record_shading("obj").should_be_called()
|
||||||
subject.update_style_colours(ifc, style, obj="obj")
|
subject.update_style_colours(ifc, style, obj="obj")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user