Fix bug where multiple presentation style assignments in IFC2X3 would get ignored

This commit is contained in:
Dion Moult
2020-09-12 10:59:45 +10:00
parent aac61a8948
commit 1a04e54f03
@@ -107,7 +107,6 @@ class MaterialCreator():
return return
if len(obj.material_slots) == 1: if len(obj.material_slots) == 1:
return return
slots = [self.canonicalise_material_name(s.name) for s in obj.material_slots]
material_to_slot = {} material_to_slot = {}
for i, material in enumerate(mesh['ios_materials']): for i, material in enumerate(mesh['ios_materials']):
if material == 'NULLMAT': if material == 'NULLMAT':
@@ -116,13 +115,16 @@ class MaterialCreator():
material = material.split('-')[2] material = material.split('-')[2]
if len(bytes(material, 'utf-8')) > 63: # Blender material names are up to 63 UTF-8 bytes if len(bytes(material, 'utf-8')) > 63: # Blender material names are up to 63 UTF-8 bytes
material = bytes(material, 'utf-8')[0:63].decode('utf-8') material = bytes(material, 'utf-8')[0:63].decode('utf-8')
try:
material_to_slot[i] = slots.index(material) slot_index = obj.material_slots.find(material)
except: if slot_index == -1:
# If the material name duplicates, a `.001` is added, this # If we can't find the material, it is possible that the
# reduces the maxmium characters for the material name to 59. # material name is duplicated, and so a '.001' is added.
# The maximum characters for the material name is 59 in this
# scenario.
material = material[0:59] material = material[0:59]
material_to_slot[i] = slots.index(material) slot_index = [self.canonicalise_material_name(s.name) for s in obj.material_slots].index(material)
material_to_slot[i] = slot_index
if len(mesh.polygons) == len(mesh['ios_material_ids']): if len(mesh.polygons) == len(mesh['ios_material_ids']):
material_index = [(material_to_slot[mat_id] if mat_id != -1 material_index = [(material_to_slot[mat_id] if mat_id != -1
@@ -180,8 +182,8 @@ class MaterialCreator():
def get_material_name(self, styled_item): def get_material_name(self, styled_item):
if styled_item.Name: if styled_item.Name:
return styled_item.Name return styled_item.Name
styled_item = self.resolve_presentation_style_assignment(styled_item) styles = self.get_styled_item_styles(styled_item)
for style in styled_item.Styles: for style in styles:
if not style.is_a('IfcSurfaceStyle'): if not style.is_a('IfcSurfaceStyle'):
continue continue
if style.Name: if style.Name:
@@ -190,8 +192,8 @@ class MaterialCreator():
return str(styled_item.id()) return str(styled_item.id())
def parse_styled_item(self, styled_item, material): def parse_styled_item(self, styled_item, material):
styled_item = self.resolve_presentation_style_assignment(styled_item) styles = self.get_styled_item_styles(styled_item)
for style in styled_item.Styles: for style in styles:
if not style.is_a('IfcSurfaceStyle'): if not style.is_a('IfcSurfaceStyle'):
continue continue
external_style = None external_style = None
@@ -217,11 +219,14 @@ class MaterialCreator():
# IfcPresentationStyleAssignment is deprecated as of IFC4 # IfcPresentationStyleAssignment is deprecated as of IFC4
# However it is still widely used thanks to Revit :( # However it is still widely used thanks to Revit :(
def resolve_presentation_style_assignment(self, styled_item): def get_styled_item_styles(self, styled_item):
styles = []
for style in styled_item.Styles: for style in styled_item.Styles:
if style.is_a('IfcPresentationStyleAssignment'): if style.is_a('IfcPresentationStyleAssignment'):
return style styles.extend(self.get_styled_item_styles(style))
return styled_item else:
styles.append(style)
return styles
def resolve_mapped_representation_items(self, representation): def resolve_mapped_representation_items(self, representation):
items = [] items = []