diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index a879a20253..a4d8bfc218 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -1352,6 +1352,7 @@ class IfcImporter: self, element: ifcopenshell.entity_instance, shape: Union[ifcopenshell.geom.ShapeElementType, ifcopenshell.geom.ShapeType], + cartesian_point_offset=None, ) -> bpy.types.Mesh: try: if hasattr(shape, "geometry"): @@ -1362,7 +1363,17 @@ class IfcImporter: mesh = bpy.data.meshes.new(tool.Loader.get_mesh_name_from_shape(geometry)) - if geometry.verts and tool.Loader.is_point_far_away( + if cartesian_point_offset: + verts_array = np.array(geometry.verts) + offset = np.array([-cartesian_point_offset[0], -cartesian_point_offset[1], -cartesian_point_offset[2]]) + offset_verts = verts_array + np.tile(offset, len(verts_array) // 3) + verts = offset_verts.tolist() + + mesh["has_cartesian_point_offset"] = True + mesh["cartesian_point_offset"] = ( + f"{cartesian_point_offset[0]},{cartesian_point_offset[1]},{cartesian_point_offset[2]}" + ) + elif geometry.verts and tool.Loader.is_point_far_away( (geometry.verts[0], geometry.verts[1], geometry.verts[2]), is_meters=True ): # Shift geometry close to the origin based off that first vert it found diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 81986350e3..a005303a75 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -416,20 +416,11 @@ class UpdateRepresentation(bpy.types.Operator, tool.Ifc.Operator): if tool.Drawing.is_annotation_object_type(element, ("FALL", "SECTION_LEVEL", "PLAN_LEVEL")): context_of_items = tool.Drawing.get_annotation_context("MODEL_VIEW") - gprop = context.scene.BIMGeoreferenceProperties - coordinate_offset = None - if ( - gprop.has_blender_offset - and obj.BIMObjectProperties.blender_offset_type == "CARTESIAN_POINT" - and obj.BIMObjectProperties.cartesian_point_offset - ): - coordinate_offset = Vector(map(float, obj.BIMObjectProperties.cartesian_point_offset.split(","))) - representation_data = { "context": context_of_items, "blender_object": obj, "geometry": obj.data, - "coordinate_offset": coordinate_offset, + "coordinate_offset": tool.Geometry.get_cartesian_point_offset(obj), "total_items": max(1, len(obj.material_slots)), "should_force_faceted_brep": tool.Geometry.should_force_faceted_brep(), "should_force_triangulation": tool.Geometry.should_force_triangulation(), diff --git a/src/bonsai/bonsai/bim/module/model/stair.py b/src/bonsai/bonsai/bim/module/model/stair.py index 568f3a9b5d..7972daa926 100644 --- a/src/bonsai/bonsai/bim/module/model/stair.py +++ b/src/bonsai/bonsai/bim/module/model/stair.py @@ -73,7 +73,7 @@ def update_stair_representation(obj): context=body, blender_object=obj, geometry=obj.data, - coordinate_offset=tool.Geometry.get_cartesian_point_coordinate_offset(obj), + coordinate_offset=tool.Geometry.get_cartesian_point_offset(obj), total_items=tool.Geometry.get_total_representation_items(obj), should_force_faceted_brep=tool.Geometry.should_force_faceted_brep(), should_force_triangulation=tool.Geometry.should_force_triangulation(), diff --git a/src/bonsai/bonsai/core/geometry.py b/src/bonsai/bonsai/core/geometry.py index 8132d77c88..d3206a8002 100644 --- a/src/bonsai/bonsai/core/geometry.py +++ b/src/bonsai/bonsai/core/geometry.py @@ -64,7 +64,7 @@ def add_representation( context=context, blender_object=obj, geometry=data, - coordinate_offset=geometry.get_cartesian_point_coordinate_offset(obj), + coordinate_offset=geometry.get_cartesian_point_offset(obj), total_items=geometry.get_total_representation_items(obj), should_force_faceted_brep=geometry.should_force_faceted_brep(), should_force_triangulation=geometry.should_force_triangulation(), diff --git a/src/bonsai/bonsai/core/tool.py b/src/bonsai/bonsai/core/tool.py index dc9a8a81a2..4b3f3f7fe7 100644 --- a/src/bonsai/bonsai/core/tool.py +++ b/src/bonsai/bonsai/core/tool.py @@ -390,7 +390,7 @@ class Geometry: def delete_ifc_object(cls, obj): pass def does_representation_id_exist(cls, representation_id): pass def duplicate_object_data(cls, obj): pass - def get_cartesian_point_coordinate_offset(cls, obj): pass + def get_cartesian_point_offset(cls, obj): pass def get_element_type(cls, element): pass def get_elements_of_type(cls, type): pass def get_ifc_representation_class(cls, element, representation): pass diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index fcbd7da8a6..3ae543184b 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -452,7 +452,7 @@ class Geometry(bonsai.core.tool.Geometry): return ifcopenshell.util.representation.get_representation(element, context) @classmethod - def get_cartesian_point_coordinate_offset(cls, obj: bpy.types.Object) -> Union[Vector, None]: + def get_cartesian_point_offset(cls, obj: bpy.types.Object) -> Vector | None: if ( obj.BIMObjectProperties.blender_offset_type == "CARTESIAN_POINT" and obj.BIMObjectProperties.cartesian_point_offset @@ -685,7 +685,9 @@ class Geometry(bonsai.core.tool.Geometry): if element.is_a("IfcAnnotation") and ifc_importer.is_curve_annotation(element): mesh = ifc_importer.create_curve(element, shape) elif shape: - mesh = ifc_importer.create_mesh(element, shape) + mesh = ifc_importer.create_mesh( + element, shape, cartesian_point_offset=cls.get_cartesian_point_offset(obj) + ) ifc_importer.material_creator.load_existing_materials() shape_has_openings = cls.does_shape_has_openings(shape) ifc_importer.material_creator.create(element, obj, mesh, shape_has_openings)