You can now toggle loading geometry in advanced mode when loading a project

This commit is contained in:
Dion Moult
2023-06-26 17:13:34 +10:00
parent 897dfb1e33
commit 10e96239a1
3 changed files with 45 additions and 28 deletions
+42 -28
View File
@@ -367,6 +367,8 @@ class IfcImporter:
return results return results
def parse_native_elements(self): def parse_native_elements(self):
if not self.ifc_import_settings.should_load_geometry:
return
for element in self.elements: for element in self.elements:
if self.is_native(element): if self.is_native(element):
self.native_elements.add(element) self.native_elements.add(element)
@@ -578,6 +580,8 @@ class IfcImporter:
return result return result
def create_grids(self): def create_grids(self):
if not self.ifc_import_settings.should_load_geometry:
return
grids = self.file.by_type("IfcGrid") grids = self.file.by_type("IfcGrid")
for grid in grids: for grid in grids:
shape = None shape = None
@@ -623,34 +627,37 @@ class IfcImporter:
def create_element_type(self, element): def create_element_type(self, element):
self.ifc_import_settings.logger.info("Creating object %s", element) self.ifc_import_settings.logger.info("Creating object %s", element)
representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
if not representation:
representation = ifcopenshell.util.representation.get_representation(element, "Plan", "Annotation")
if not representation:
representation = ifcopenshell.util.representation.get_representation(element, "Model", "Annotation")
mesh = None mesh = None
if representation: if self.ifc_import_settings.should_load_geometry:
mesh_name = "{}/{}".format(representation.ContextOfItems.id(), representation.id()) representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
mesh = self.meshes.get(mesh_name) if not representation:
if mesh is None: representation = ifcopenshell.util.representation.get_representation(element, "Plan", "Annotation")
shape = None if not representation:
try: representation = ifcopenshell.util.representation.get_representation(element, "Model", "Annotation")
shape = ifcopenshell.geom.create_shape(self.settings, representation) if representation:
except: mesh_name = "{}/{}".format(representation.ContextOfItems.id(), representation.id())
mesh = self.meshes.get(mesh_name)
if mesh is None:
shape = None
try: try:
shape = ifcopenshell.geom.create_shape(self.settings_2d, representation) shape = ifcopenshell.geom.create_shape(self.settings, representation)
except: except:
self.ifc_import_settings.logger.error("Failed to generate shape for %s", element) try:
if shape: shape = ifcopenshell.geom.create_shape(self.settings_2d, representation)
mesh = self.create_mesh(element, shape) except:
tool.Loader.link_mesh(shape, mesh) self.ifc_import_settings.logger.error("Failed to generate shape for %s", element)
self.meshes[mesh_name] = mesh if shape:
mesh = self.create_mesh(element, shape)
tool.Loader.link_mesh(shape, mesh)
self.meshes[mesh_name] = mesh
obj = bpy.data.objects.new(tool.Loader.get_name(element), mesh) obj = bpy.data.objects.new(tool.Loader.get_name(element), mesh)
self.link_element(element, obj) self.link_element(element, obj)
self.material_creator.create(element, obj, mesh) self.material_creator.create(element, obj, mesh)
self.type_products[element.GlobalId] = obj self.type_products[element.GlobalId] = obj
def create_native_elements(self): def create_native_elements(self):
if not self.ifc_import_settings.should_load_geometry:
return
progress = 0 progress = 0
checkpoint = time.time() checkpoint = time.time()
total = len(self.native_elements) total = len(self.native_elements)
@@ -696,15 +703,20 @@ class IfcImporter:
# 1. 3D Body, 2. 2D Body, 3. 2D Plans / annotations, 4. Point clouds, 5. No representation # 1. 3D Body, 2. 2D Body, 3. 2D Plans / annotations, 4. Point clouds, 5. No representation
# If an element has a representation that doesn't follow 1, 2, 3, or 4, it will not show by default. # If an element has a representation that doesn't follow 1, 2, 3, or 4, it will not show by default.
# The user can load them later if they want to view them. # The user can load them later if they want to view them.
products = self.create_products(elements) if self.ifc_import_settings.should_load_geometry:
elements -= products products = self.create_products(elements)
products = self.create_products(elements, settings=self.settings_curve) elements -= products
elements -= products products = self.create_products(elements, settings=self.settings_curve)
products = self.create_products(elements, settings=self.settings_2d) elements -= products
elements -= products products = self.create_products(elements, settings=self.settings_2d)
products = self.create_pointclouds(elements) elements -= products
elements -= products products = self.create_pointclouds(elements)
for element in elements: elements -= products
total = len(elements)
for i, element in enumerate(elements):
if i % 250 == 0:
print("{} / {} elements processed ...".format(i, total))
self.create_product(element) self.create_product(element)
def create_products(self, products, settings=None): def create_products(self, products, settings=None):
@@ -1796,6 +1808,7 @@ class IfcImportSettings:
self.should_use_cpu_multiprocessing = True self.should_use_cpu_multiprocessing = True
self.merge_mode = None self.merge_mode = None
self.should_merge_materials_by_colour = False self.should_merge_materials_by_colour = False
self.should_load_geometry = True
self.should_use_native_meshes = False self.should_use_native_meshes = False
self.should_clean_mesh = True self.should_clean_mesh = True
self.should_cache = True self.should_cache = True
@@ -1825,6 +1838,7 @@ class IfcImportSettings:
settings.should_use_cpu_multiprocessing = props.should_use_cpu_multiprocessing settings.should_use_cpu_multiprocessing = props.should_use_cpu_multiprocessing
settings.merge_mode = props.merge_mode settings.merge_mode = props.merge_mode
settings.should_merge_materials_by_colour = props.should_merge_materials_by_colour settings.should_merge_materials_by_colour = props.should_merge_materials_by_colour
settings.should_load_geometry = props.should_load_geometry
settings.should_use_native_meshes = props.should_use_native_meshes settings.should_use_native_meshes = props.should_use_native_meshes
settings.should_clean_mesh = props.should_clean_mesh settings.should_clean_mesh = props.should_clean_mesh
settings.should_cache = props.should_cache settings.should_cache = props.should_cache
@@ -148,6 +148,7 @@ class BIMProjectProperties(PropertyGroup):
default="NONE", default="NONE",
) )
should_merge_materials_by_colour: BoolProperty(name="Merge Materials by Colour", default=False) should_merge_materials_by_colour: BoolProperty(name="Merge Materials by Colour", default=False)
should_load_geometry: BoolProperty(name="Load Geometry", default=True)
should_use_native_meshes: BoolProperty(name="Native Meshes", default=False) should_use_native_meshes: BoolProperty(name="Native Meshes", default=False)
should_clean_mesh: BoolProperty(name="Clean Meshes", default=True) should_clean_mesh: BoolProperty(name="Clean Meshes", default=True)
should_cache: BoolProperty(name="Cache", default=False) should_cache: BoolProperty(name="Cache", default=False)
@@ -77,6 +77,8 @@ class BIM_PT_project(Panel):
row = self.layout.row() row = self.layout.row()
row.prop(pprops, "should_cache") row.prop(pprops, "should_cache")
row = self.layout.row() row = self.layout.row()
row.prop(pprops, "should_load_geometry")
row = self.layout.row()
row.prop(pprops, "should_use_native_meshes") row.prop(pprops, "should_use_native_meshes")
row = self.layout.row() row = self.layout.row()
row.prop(pprops, "should_merge_materials_by_colour") row.prop(pprops, "should_merge_materials_by_colour")