import_ifc - not to break completely on facing breaking mesh #6270

create_mesh returns None only in case if it meets some exception and it prints logs in that case, but atleast some breaking mesh won't be in the way of users trying to open some model
This commit is contained in:
Andrej730
2025-03-05 14:52:19 +05:00
parent 7c6e124fe9
commit 4c97cc8a41
+8 -7
View File
@@ -514,8 +514,9 @@ class IfcImporter:
pass pass
elif shape: elif shape:
mesh = self.create_mesh(element, shape) mesh = self.create_mesh(element, shape)
tool.Loader.link_mesh(shape, mesh) if mesh is not None:
self.meshes[mesh_name] = mesh tool.Loader.link_mesh(shape, mesh)
self.meshes[mesh_name] = mesh
else: else:
self.ifc_import_settings.logger.error("Failed to generate shape for %s", element) self.ifc_import_settings.logger.error("Failed to generate shape for %s", element)
break break
@@ -798,8 +799,9 @@ class IfcImporter:
materials_updated = bool(mesh) materials_updated = bool(mesh)
if mesh is None: if mesh is None:
mesh = self.create_mesh(element, shape) mesh = self.create_mesh(element, shape)
tool.Loader.link_mesh(shape, mesh) if mesh is not None:
self.meshes[mesh_name] = mesh tool.Loader.link_mesh(shape, mesh)
self.meshes[mesh_name] = mesh
else: else:
mesh = None mesh = None
@@ -810,11 +812,10 @@ class IfcImporter:
if element.is_a(ifcclass): if element.is_a(ifcclass):
obj.display_type = "WIRE" obj.display_type = "WIRE"
if shape: if shape and mesh:
# We use numpy here because Blender mathutils.Matrix is not accurate enough # We use numpy here because Blender mathutils.Matrix is not accurate enough
mat = ifcopenshell.util.shape.get_shape_matrix(shape) mat = ifcopenshell.util.shape.get_shape_matrix(shape)
self.set_matrix_world(obj, tool.Loader.apply_blender_offset_to_matrix_world(obj, mat)) self.set_matrix_world(obj, tool.Loader.apply_blender_offset_to_matrix_world(obj, mat))
assert mesh # Type checker.
if not materials_updated: if not materials_updated:
self.material_creator.create(element, obj, mesh, tool.Geometry.does_shape_has_openings(shape)) self.material_creator.create(element, obj, mesh, tool.Geometry.does_shape_has_openings(shape))
elif mesh: # When does this occur? elif mesh: # When does this occur?
@@ -1033,7 +1034,7 @@ class IfcImporter:
element: ifcopenshell.entity_instance, element: ifcopenshell.entity_instance,
shape: Union[ifcopenshell.geom.ShapeElementType, ifcopenshell.geom.ShapeType], shape: Union[ifcopenshell.geom.ShapeElementType, ifcopenshell.geom.ShapeType],
cartesian_point_offset: Union[npt.NDArray[np.float64], Literal[False]] = None, cartesian_point_offset: Union[npt.NDArray[np.float64], Literal[False]] = None,
) -> bpy.types.Mesh: ) -> Union[bpy.types.Mesh, None]:
try: try:
if hasattr(shape, "geometry"): if hasattr(shape, "geometry"):
# shape is ShapeElementType # shape is ShapeElementType