Fix #7799: Fix elements hidden when activating plan drawings#7807
Open
theoryshaw wants to merge 2 commits intov0.8.0from
Open
Fix #7799: Fix elements hidden when activating plan drawings#7807theoryshaw wants to merge 2 commits intov0.8.0from
theoryshaw wants to merge 2 commits intov0.8.0from
Conversation
Elements with multiple IFC representations (plan, RCP, body) were incorrectly excluded from drawings because the camera frustum test used obj.bound_box, which reflects only the currently active Blender mesh. After switching from an RCP drawing, the plan-view mesh was no longer active, placing the element's bbox outside the plan camera's frustum. Fix by unioning three bbox sources in is_in_camera_view: the IfcBoundingBox (representation-independent footprint), accumulated custom properties built up across representation switches, and the current obj.bound_box. This ensures the spatial test covers the element's full extent regardless of which representation is active. Generated with the assistance of an AI coding tool.
Guard against objects that have already been removed from Blender's data (StructRNA removed) before the function runs. This occurs when switch_representation is called on temporary annotation objects that are freed before returning. Generated with the assistance of an AI coding tool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When activating a plan view drawing (
bim.activate_drawing) after previouslyactivating a reflected ceiling plan (RCP) drawing — or vice versa — certain
elements would be hidden from the scene even though they belong to that storey
level. In the reported case, an
IfcLightFixturewith bothPLAN_VIEWandREFLECTED_PLAN_VIEWrepresentations was invisible after switching between thetwo drawing types.
Root Cause
activate_drawingcallsget_drawing_elements, which callsget_elements_in_camera_viewto determine which objects fall within thecamera's frustum. The frustum test in
is_in_camera_viewusedobj.bound_box— the bounding box of the currently active Blender mesh — to determine
whether an element intersects the camera.
The problem is that
activate_drawingswitches each element's activerepresentation to match the target view after the camera frustum test. So
when switching from an RCP drawing to a plan view drawing:
REFLECTED_PLAN_VIEWgeometry (ceilinglevel, e.g. local z ≈ +1.2 m above the element origin).
in camera-local space spans z ∈ [−10, −0.002].
(above the camera), falling entirely outside the frustum.
is_in_camera_viewreturnsFalse, the element is excluded fromfiltered_elements, and it is hidden — regardless of the fact that aPLAN_VIEWrepresentation exists that would be within the frustum.The same failure occurs in reverse: activating an RCP drawing when the
element's active mesh is the
PLAN_VIEWgeometry (floor level, below theupward-looking RCP camera).
Fix
tool/drawing.py— representation-independent bboxA new helper
_get_bbox_corners(obj, element)replaces the direct use ofobj.bound_boxinis_in_camera_view. It unions three bbox sources to producea spatial envelope that is independent of which representation is currently
active:
IfcBoundingBox— if the element has aBoxrepresentation context,the
IfcBoundingBoxitem is read and converted to metres. This provides thecanonical floor-plan footprint defined in the IFC file, which is always
present regardless of which Blender mesh is active.
Accumulated custom properties (
obj["ifc_bbox_min"]/obj["ifc_bbox_max"]) — a growing union of every representation bbox thathas been loaded for this object, populated by
update_bbox_accumulation(seebelow). After the first round-trip between drawing types, this covers all
previously seen geometry extents.
obj.bound_box— the existing fallback for objects without IFC metadataor on first load.
The union of these three sources ensures the bounding envelope spans both the
floor-level footprint (for plan cameras) and the ceiling-level geometry (for
RCP cameras), so the frustum test returns
Truefor both view types regardlessof which mesh is currently active.
is_in_camera_viewgains an optionalelementparameter passed through fromget_elements_in_camera_view, which now iterates objects explicitly rather thanusing a list comprehension so the entity lookup is available for both the test
and the result set.
tool/geometry.py— bbox accumulationNew method
update_bbox_accumulation(obj)unions the currentobj.bound_boxinto
obj["ifc_bbox_min"]/obj["ifc_bbox_max"]Blender custom properties.The union grows monotonically as representations are loaded, so after any two
representation switches the accumulated bbox covers all seen extents.
core/geometry.py— hook into representation switchingswitch_representationcallsgeometry.update_bbox_accumulation(obj)afterreimport_element_representationscompletes. This means every time a drawingactivation switches an element's mesh, the new geometry is harvested into the
accumulation automatically.
Notes
three files listed above.
IfcBoundingBoxpath only activates when the element has aBoxrepresentation context; elements without one fall through to the accumulated
props and
obj.bound_boxunchanged.IfcBoundingBoxalone is sufficient to fix the plan-view case for elementsthat carry a
Boxcontext. For elements without aBoxcontext, theaccumulated props will build up after the first switch.
Testing
Tested with an IFC file containing an
IfcLightFixturewithModel/Body/PLAN_VIEW,Model/Body/REFLECTED_PLAN_VIEW, andModel/Box/MODEL_VIEWrepresentations:fixture is now included and switches to
PLAN_VIEWrepresentation. ✓switches to
REFLECTED_PLAN_VIEWrepresentation. ✓Generated with the assistance of an AI coding tool.