From 83018451e6af1b8e7acf25759175f62389df5bdc Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Wed, 11 May 2022 22:11:12 +1000 Subject: [PATCH] feat: allow snapping to occur through objects occluding the target while using snap_align --- utils/snap_align.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/utils/snap_align.py b/utils/snap_align.py index 5968d7b..d3ddaeb 100644 --- a/utils/snap_align.py +++ b/utils/snap_align.py @@ -87,8 +87,6 @@ def invoke(self, context, event): self.snap_point = None self.snap_point_rotation_cache = None - bpy.ops.object.hide_view_set(unselected=True) - a, b = context.selected_objects self.reference_obj = a if a.name != context.object.name else b self.reference_obj_original_location = self.reference_obj.location.copy() @@ -183,8 +181,16 @@ def recalculate_points(self, context, mouse_coords): depsgraph = context.evaluated_depsgraph_get() hit, location, normal, face_index, object, matrix = context.scene.ray_cast(depsgraph, ray_origin, ray_direction) + hidden_objects = [] + while hit and object.name != context.object.name: + hidden_objects.append(object) + object.hide_set(True) + hit, location, normal, face_index, object, matrix = context.scene.ray_cast(depsgraph, location + 0.001 * ray_direction, ray_direction) + + for obj in hidden_objects: + obj.hide_set(False) - if hit and object.name == context.object.name: + if hit: self.hit_location = location self.primary_points = [] @@ -211,7 +217,6 @@ def recalculate_points(self, context, mouse_coords): def clean_up(self, context): - bpy.ops.object.hide_view_clear() for mod in context.active_object.modifiers: if mod.type == 'BOOLEAN' and mod.object == self.reference_obj: mod.show_viewport = self.affected_boolean_modifiers[mod.name]