mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 22:30:01 +00:00
Optimise presentation layer assignment which was ridiculously slow and badly implemented
This commit is contained in:
@@ -38,7 +38,7 @@ class MaterialCreator:
|
|||||||
def __init__(self, ifc_import_settings, ifc_importer):
|
def __init__(self, ifc_import_settings, ifc_importer):
|
||||||
self.mesh = None
|
self.mesh = None
|
||||||
self.materials = {}
|
self.materials = {}
|
||||||
self.parsed_meshes = []
|
self.parsed_meshes = set()
|
||||||
self.ifc_import_settings = ifc_import_settings
|
self.ifc_import_settings = ifc_import_settings
|
||||||
self.ifc_importer = ifc_importer
|
self.ifc_importer = ifc_importer
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class MaterialCreator:
|
|||||||
return
|
return
|
||||||
if self.mesh.name in self.parsed_meshes:
|
if self.mesh.name in self.parsed_meshes:
|
||||||
return
|
return
|
||||||
self.parsed_meshes.append(self.mesh.name)
|
self.parsed_meshes.add(self.mesh.name)
|
||||||
if self.parse_representations(element):
|
if self.parse_representations(element):
|
||||||
self.assign_material_slots_to_faces(obj)
|
self.assign_material_slots_to_faces(obj)
|
||||||
|
|
||||||
@@ -465,10 +465,10 @@ class IfcImporter:
|
|||||||
):
|
):
|
||||||
self.merge_materials_by_colour()
|
self.merge_materials_by_colour()
|
||||||
self.profile_code("Merging by colour")
|
self.profile_code("Merging by colour")
|
||||||
self.add_project_to_scene()
|
|
||||||
self.profile_code("Add project to scene")
|
|
||||||
self.create_presentation_layers()
|
self.create_presentation_layers()
|
||||||
self.profile_code("Create presentation layers")
|
self.profile_code("Create presentation layers")
|
||||||
|
self.add_project_to_scene()
|
||||||
|
self.profile_code("Add project to scene")
|
||||||
if self.ifc_import_settings.should_clean_mesh and len(self.file.by_type("IfcElement")) < 10000:
|
if self.ifc_import_settings.should_clean_mesh and len(self.file.by_type("IfcElement")) < 10000:
|
||||||
self.clean_mesh()
|
self.clean_mesh()
|
||||||
self.profile_code("Mesh cleaning")
|
self.profile_code("Mesh cleaning")
|
||||||
@@ -1333,19 +1333,15 @@ class IfcImporter:
|
|||||||
for item in assignment.AssignedItems:
|
for item in assignment.AssignedItems:
|
||||||
# TODO: This is a simplified implementation of assigning presentation layers that ignores assigned
|
# TODO: This is a simplified implementation of assigning presentation layers that ignores assigned
|
||||||
# representation items, does not consider mapped representations, and assumes a Body context. See #1109.
|
# representation items, does not consider mapped representations, and assumes a Body context. See #1109.
|
||||||
guids = []
|
|
||||||
if not hasattr(item, "OfProductRepresentation") or item.RepresentationIdentifier != "Body":
|
if not hasattr(item, "OfProductRepresentation") or item.RepresentationIdentifier != "Body":
|
||||||
continue
|
continue
|
||||||
for product_representation in item.OfProductRepresentation:
|
for product_representation in item.OfProductRepresentation:
|
||||||
for product in product_representation.ShapeOfProduct:
|
for product in product_representation.ShapeOfProduct:
|
||||||
guids.append(product.GlobalId)
|
try:
|
||||||
for obj in bpy.context.selectable_objects:
|
obj = self.added_data[product.GlobalId]
|
||||||
global_id = obj.BIMObjectProperties.attributes.get("GlobalId")
|
obj.data.BIMMeshProperties.presentation_layer_index = layer_index
|
||||||
if global_id and global_id.string_value in guids:
|
except:
|
||||||
if not obj.data or not hasattr(obj.data, "BIMMeshProperties"):
|
pass # Occurs for example in opening elements or exclusions
|
||||||
continue
|
|
||||||
obj.data.BIMMeshProperties.presentation_layer_index = layer_index
|
|
||||||
obj.hide_set(not layer.layer_on)
|
|
||||||
|
|
||||||
def clean_mesh(self):
|
def clean_mesh(self):
|
||||||
obj = None
|
obj = None
|
||||||
|
|||||||
Reference in New Issue
Block a user