Fix bug where switching representations didn't take into account georef cartesian point offsets

This commit is contained in:
Dion Moult
2024-09-25 17:46:15 +10:00
parent dc5e3d86b4
commit 9af9120dff
6 changed files with 20 additions and 16 deletions
+12 -1
View File
@@ -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
@@ -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(),
+1 -1
View File
@@ -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(),
+1 -1
View File
@@ -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(),
+1 -1
View File
@@ -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
+4 -2
View File
@@ -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)