Retain material data if a surface style overrides it on import. See #865

This commit is contained in:
Dion Moult
2020-06-01 20:55:14 +10:00
parent 82ada5c102
commit 0ec205ad1d
2 changed files with 14 additions and 12 deletions
@@ -1025,8 +1025,8 @@ class IfcParser():
for slot in obj.material_slots: for slot in obj.material_slots:
if slot.material is None: if slot.material is None:
continue continue
if not self.ifc_export_settings.should_export_all_materials_as_styled_items and ( if not self.ifc_export_settings.should_export_all_materials_as_styled_items \
slot.material.name in results or slot.link == 'DATA'): and (slot.material.name in results or slot.link == 'DATA'):
continue continue
results.append({ results.append({
'ifc': None, 'ifc': None,
@@ -1708,13 +1708,14 @@ class IfcExporter():
product = self.ifc_parser.products[ product = self.ifc_parser.products[
self.ifc_parser.get_product_index_from_raw_name( self.ifc_parser.get_product_index_from_raw_name(
styled_item['related_product_name'])] styled_item['related_product_name'])]
valid_material_slots = [ms for ms in product['raw'].material_slots if ms.link == 'OBJECT']
material_slots = {} material_slots = {}
if product['ifc'].Representation: if product['ifc'].Representation:
for representation in product['ifc'].Representation.Representations: for representation in product['ifc'].Representation.Representations:
for mapped_item in representation.Items: for mapped_item in representation.Items:
items = mapped_item[0].MappedRepresentation.Items items = mapped_item[0].MappedRepresentation.Items
for i, item in enumerate(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(): for styled_item_name, representation_item in material_slots.items():
if styled_item_name == styled_item['attributes']['Name']: if styled_item_name == styled_item['attributes']['Name']:
styled_item['ifc'] = self.create_styled_item(styled_item, representation_item) styled_item['ifc'] = self.create_styled_item(styled_item, representation_item)
@@ -2444,17 +2445,18 @@ class IfcExporter():
if not representation['is_parametric']: if not representation['is_parametric']:
mesh = representation['raw_object'].evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh() mesh = representation['raw_object'].evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh()
self.create_vertices(mesh.vertices) self.create_vertices(mesh.vertices)
ifc_faces = [None] * len(representation['raw_object'].material_slots) ifc_raw_items = [None] * len(representation['raw_object'].material_slots)
for i, value in enumerate(ifc_faces): for i, value in enumerate(ifc_raw_items):
ifc_faces[i] = [] ifc_raw_items[i] = []
if not ifc_faces: if not ifc_raw_items:
ifc_faces = [[]] ifc_raw_items = [[]]
for polygon in mesh.polygons: 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.createIfcFaceOuterBound(
self.file.createIfcPolyLoop([self.ifc_vertices[vertice] for vertice in polygon.vertices]), self.file.createIfcPolyLoop([self.ifc_vertices[vertice] for vertice in polygon.vertices]),
True)])) 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( return self.file.createIfcShapeRepresentation(
self.ifc_rep_context[representation['context']][representation['subcontext']][ self.ifc_rep_context[representation['context']][representation['subcontext']][
representation['target_view']]['ifc'], representation['target_view']]['ifc'],
@@ -41,12 +41,12 @@ class MaterialCreator():
if self.ifc_import_settings.should_treat_styled_item_as_material \ if self.ifc_import_settings.should_treat_styled_item_as_material \
and self.mesh.name in self.parsed_meshes: and self.mesh.name in self.parsed_meshes:
return return
self.parse_material(element)
self.parsed_meshes.append(self.mesh.name)
if self.parse_representations(element): if self.parse_representations(element):
self.assign_material_slots_to_faces(obj, self.mesh) self.assign_material_slots_to_faces(obj, self.mesh)
self.parsed_meshes.append(self.mesh.name) self.parsed_meshes.append(self.mesh.name)
return # styled items override material styles return # styled items override material styles
self.parse_material(element)
self.parsed_meshes.append(self.mesh.name)
def parse_representations(self, element): def parse_representations(self, element):
has_parsed = False has_parsed = False