Skip to content

Commit

Permalink
Fix #4486. Sync camera properties from IFC on both drawing load as we…
Browse files Browse the repository at this point in the history
…ll as drawing activation.

Also there are now defaults in case pset values don't exist.
  • Loading branch information
Moult committed Apr 14, 2024
1 parent fc6678f commit 50b41f5
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/blenderbim/blenderbim/tool/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,39 @@ def import_drawing(cls, drawing: ifcopenshell.entity_instance) -> bpy.types.Obje

camera.angle = fov

tool.Loader.link_mesh(shape, camera)

obj = bpy.data.objects.new(tool.Loader.get_name(drawing), camera)
cls.import_camera_props(drawing, obj)
tool.Ifc.link(drawing, obj)

m = shape.transformation.matrix.data
mat = mathutils.Matrix(
([m[0], m[3], m[6], m[9]], [m[1], m[4], m[7], m[10]], [m[2], m[5], m[8], m[11]], [0, 0, 0, 1])
)
obj.matrix_world = mat

if cls.get_drawing_target_view(drawing) == "REFLECTED_PLAN_VIEW":
obj.matrix_world[1][1] *= -1

tool.Geometry.record_object_position(obj)
tool.Collector.assign(obj)

return obj

@classmethod
def import_camera_props(cls, drawing, obj):
# Temporarily clear the definition id to prevent prop update callbacks to IFC.
ifc_definition_id = obj.BIMObjectProperties.ifc_definition_id
obj.BIMObjectProperties.ifc_definition_id = 0

camera = obj.data
camera.BIMCameraProperties.has_underlay = False
camera.BIMCameraProperties.has_linework = True
camera.BIMCameraProperties.has_annotation = True
camera.BIMCameraProperties.target_view = "PLAN_VIEW"
camera.BIMCameraProperties.is_nts = False

pset = ifcopenshell.util.element.get_pset(drawing, "EPset_Drawing")
if pset:
if "TargetView" in pset:
Expand Down Expand Up @@ -698,24 +731,8 @@ def import_drawing(cls, drawing: ifcopenshell.entity_instance) -> bpy.types.Obje
if "IsNTS" in pset:
camera.BIMCameraProperties.is_nts = bool(pset["IsNTS"])

tool.Loader.link_mesh(shape, camera)

obj = bpy.data.objects.new(tool.Loader.get_name(drawing), camera)
tool.Ifc.link(drawing, obj)

m = shape.transformation.matrix.data
mat = mathutils.Matrix(
([m[0], m[3], m[6], m[9]], [m[1], m[4], m[7], m[10]], [m[2], m[5], m[8], m[11]], [0, 0, 0, 1])
)
obj.matrix_world = mat

if cls.get_drawing_target_view(drawing) == "REFLECTED_PLAN_VIEW":
obj.matrix_world[1][1] *= -1

tool.Geometry.record_object_position(obj)
tool.Collector.assign(obj)
obj.BIMObjectProperties.ifc_definition_id = ifc_definition_id

return obj

@classmethod
def import_drawings(cls):
Expand Down Expand Up @@ -1792,6 +1809,9 @@ def activate_drawing(cls, camera: bpy.types.Object) -> None:
obj.hide_set(False)

[obj.hide_set(False) for obj in bpy.context.view_layer.objects if obj.name not in element_obj_names]

cls.import_camera_props(drawing, camera)

@classmethod
def get_elements_in_camera_view(
cls, camera: bpy.types.Object, objs: list[ifcopenshell.entity_instance]
Expand Down

0 comments on commit 50b41f5

Please sign in to comment.