Fix #2910. Bug where style colours were not synced prior to duplication.

This commit is contained in:
Dion Moult
2023-04-03 20:16:43 +10:00
parent 4bdf5475a9
commit 79479901f6
3 changed files with 12 additions and 6 deletions
+1 -5
View File
@@ -126,7 +126,7 @@ class IfcExporter:
continue continue
try: try:
if isinstance(obj, bpy.types.Material): if isinstance(obj, bpy.types.Material):
if self.has_changed_shading(obj): if tool.Ifc.has_changed_shading(obj):
blenderbim.core.style.update_style_colours(tool.Ifc, tool.Style, obj=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)
@@ -149,10 +149,6 @@ 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):
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
if not tool.Ifc.is_moved(obj): if not tool.Ifc.is_moved(obj):
@@ -24,6 +24,7 @@ import ifcopenshell.util.attribute
import ifcopenshell.util.representation import ifcopenshell.util.representation
import blenderbim.bim.helper import blenderbim.bim.helper
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.core.style
import blenderbim.core.material as core import blenderbim.core.material as core
import blenderbim.bim.module.model.profile as model_profile import blenderbim.bim.module.model.profile as model_profile
from blenderbim.bim.module.material.prop import purge as material_prop_purge from blenderbim.bim.module.material.prop import purge as material_prop_purge
@@ -666,8 +667,12 @@ class CopyMaterial(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
blender_material = context.active_object.active_material blender_material = context.active_object.active_material
material = tool.Ifc.get_entity(blender_material) material = tool.Ifc.get_entity(blender_material)
if tool.Ifc.has_changed_shading(blender_material):
blenderbim.core.style.update_style_colours(tool.Ifc, tool.Style, obj=blender_material)
copied_material = ifcopenshell.api.run("material.copy_material", tool.Ifc.get(), material=material) copied_material = ifcopenshell.api.run("material.copy_material", tool.Ifc.get(), material=material)
copied_blender_material = bpy.data.materials.new(blender_material.name) copied_blender_material = blender_material.copy()
copied_style = self.get_style(copied_material) copied_style = self.get_style(copied_material)
tool.Ifc.link(copied_material, copied_blender_material) tool.Ifc.link(copied_material, copied_blender_material)
if copied_style: if copied_style:
+5
View File
@@ -46,6 +46,11 @@ class Ifc(blenderbim.core.tool.Ifc):
if IfcStore.get_file(): if IfcStore.get_file():
return IfcStore.get_file().schema return IfcStore.get_file().schema
@classmethod
def has_changed_shading(cls, obj):
checksum = obj.BIMMaterialProperties.shading_checksum
return checksum != repr(np.array(obj.diffuse_color).tobytes())
@classmethod @classmethod
def is_deleted(cls, element): def is_deleted(cls, element):
return element.id() in IfcStore.deleted_ids return element.id() in IfcStore.deleted_ids