From 0ec205ad1d15e3d9c52d13f48416e3be21428c05 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 1 Jun 2020 20:55:14 +1000 Subject: [PATCH] Retain material data if a surface style overrides it on import. See #865 --- .../blenderbim/bim/export_ifc.py | 22 ++++++++++--------- .../blenderbim/bim/import_ifc.py | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/export_ifc.py b/src/ifcblenderexport/blenderbim/bim/export_ifc.py index b9f81a3a25..301545ecb4 100644 --- a/src/ifcblenderexport/blenderbim/bim/export_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/export_ifc.py @@ -1025,8 +1025,8 @@ class IfcParser(): for slot in obj.material_slots: if slot.material is None: continue - if not self.ifc_export_settings.should_export_all_materials_as_styled_items and ( - slot.material.name in results or slot.link == 'DATA'): + if not self.ifc_export_settings.should_export_all_materials_as_styled_items \ + and (slot.material.name in results or slot.link == 'DATA'): continue results.append({ 'ifc': None, @@ -1708,13 +1708,14 @@ class IfcExporter(): product = self.ifc_parser.products[ self.ifc_parser.get_product_index_from_raw_name( styled_item['related_product_name'])] + valid_material_slots = [ms for ms in product['raw'].material_slots if ms.link == 'OBJECT'] material_slots = {} if product['ifc'].Representation: for representation in product['ifc'].Representation.Representations: for mapped_item in representation.Items: items = mapped_item[0].MappedRepresentation.Items for i, item in enumerate(items): - material_slots[product['raw'].material_slots[i].name] = item + material_slots[valid_material_slots[i].name] = item for styled_item_name, representation_item in material_slots.items(): if styled_item_name == styled_item['attributes']['Name']: styled_item['ifc'] = self.create_styled_item(styled_item, representation_item) @@ -2444,17 +2445,18 @@ class IfcExporter(): if not representation['is_parametric']: mesh = representation['raw_object'].evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh() self.create_vertices(mesh.vertices) - ifc_faces = [None] * len(representation['raw_object'].material_slots) - for i, value in enumerate(ifc_faces): - ifc_faces[i] = [] - if not ifc_faces: - ifc_faces = [[]] + ifc_raw_items = [None] * len(representation['raw_object'].material_slots) + for i, value in enumerate(ifc_raw_items): + ifc_raw_items[i] = [] + if not ifc_raw_items: + ifc_raw_items = [[]] for polygon in mesh.polygons: - ifc_faces[polygon.material_index].append(self.file.createIfcFace([ + ifc_raw_items[polygon.material_index].append(self.file.createIfcFace([ self.file.createIfcFaceOuterBound( self.file.createIfcPolyLoop([self.ifc_vertices[vertice] for vertice in polygon.vertices]), True)])) - items = [self.file.createIfcFacetedBrep(self.file.createIfcClosedShell(f)) for f in ifc_faces if f] + # TODO: May not actually be a closed shell, but who checks anyway? + items = [self.file.createIfcFacetedBrep(self.file.createIfcClosedShell(i)) for i in ifc_raw_items if i] return self.file.createIfcShapeRepresentation( self.ifc_rep_context[representation['context']][representation['subcontext']][ representation['target_view']]['ifc'], diff --git a/src/ifcblenderexport/blenderbim/bim/import_ifc.py b/src/ifcblenderexport/blenderbim/bim/import_ifc.py index ee4957a246..705f3cdb9e 100644 --- a/src/ifcblenderexport/blenderbim/bim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/import_ifc.py @@ -41,12 +41,12 @@ class MaterialCreator(): if self.ifc_import_settings.should_treat_styled_item_as_material \ and self.mesh.name in self.parsed_meshes: return + self.parse_material(element) + self.parsed_meshes.append(self.mesh.name) if self.parse_representations(element): self.assign_material_slots_to_faces(obj, self.mesh) self.parsed_meshes.append(self.mesh.name) return # styled items override material styles - self.parse_material(element) - self.parsed_meshes.append(self.mesh.name) def parse_representations(self, element): has_parsed = False