diff --git a/src/bonsai/bonsai/tool/cad.py b/src/bonsai/bonsai/tool/cad.py index c83efb755a..090df007f3 100644 --- a/src/bonsai/bonsai/tool/cad.py +++ b/src/bonsai/bonsai/tool/cad.py @@ -172,7 +172,7 @@ class Cad: return results @classmethod - def intersect_edges_2(cls, edge1, edge2): + def intersect_edges_v2(cls, edge1, edge2): """ Calculate the closest points on two line segments. Note: This function doesn't use intersect_line_line diff --git a/src/bonsai/bonsai/tool/raycast.py b/src/bonsai/bonsai/tool/raycast.py index deefed7183..19a26f25df 100644 --- a/src/bonsai/bonsai/tool/raycast.py +++ b/src/bonsai/bonsai/tool/raycast.py @@ -98,13 +98,8 @@ class Raycast(bonsai.core.tool.Raycast): return ray_origin_obj, ray_target_obj, ray_direction_obj @classmethod - def obj_ray_cast(cls, context, event, obj, mouse_pos=None): - if mouse_pos: - ray_origin_obj, _, ray_direction_obj = cls.get_object_ray_data( - context, event, obj.matrix_world.copy(), mouse_pos - ) - else: - ray_origin_obj, _, ray_direction_obj = cls.get_object_ray_data(context, event, obj.matrix_world.copy()) + def obj_ray_cast(cls, context, event, obj): + ray_origin_obj, _, ray_direction_obj = cls.get_object_ray_data(context, event, obj.matrix_world.copy()) success, location, normal, face_index = obj.ray_cast(ray_origin_obj, ray_direction_obj) if success: return location, normal, face_index @@ -119,10 +114,6 @@ class Raycast(bonsai.core.tool.Raycast): ray_origin, ray_target, ray_direction = cls.get_viewport_ray_data(context, event) points = [] - # Makes the snapping point more or less sticky then others - # It changes the distance and affects how the snapping point is sorted - sticky_factor = 0.02 - try: loc = view3d_utils.region_2d_to_location_3d(region, rv3d, mouse_pos, ray_direction) except: @@ -154,12 +145,12 @@ class Raycast(bonsai.core.tool.Raycast): if distance < 0.2: points.append((division_point, "Edge Center")) - intersection = tool.Cad.intersect_edges_2((ray_target, loc), (world_v1, world_v2)) + intersection = tool.Cad.intersect_edges_v2((ray_target, loc), (world_v1, world_v2)) if intersection: if tool.Cad.is_point_on_edge(intersection[1], (world_v1, world_v2)): distance = (intersection[1] - intersection[0]).length if distance < 0.8: - points.append([distance + 4 * sticky_factor, (intersection[1], "Edge")]) + points.append((intersection[1], "Edge")) bm.free() return points diff --git a/src/bonsai/bonsai/tool/snap.py b/src/bonsai/bonsai/tool/snap.py index 26fc2b28b4..6d8f88ca9a 100644 --- a/src/bonsai/bonsai/tool/snap.py +++ b/src/bonsai/bonsai/tool/snap.py @@ -297,8 +297,8 @@ class Snap(bonsai.core.tool.Snap): cls.mouse_pos = event.mouse_region_x, event.mouse_region_y detected_snaps = [] + offset = 15 snap_threshold = 0.3 - offset = 10 mouse_offset = ( (-offset, offset), (0, offset), @@ -487,10 +487,6 @@ class Snap(bonsai.core.tool.Snap): snapping_points.append(op) break - if "Plane" in list(origin.keys()): - intersection = origin["Plane"] - snapping_points.append((intersection, "Plane")) - for origin in detected_snaps: if "Axis" in list(origin.keys()): intersection = origin["Axis"] @@ -498,6 +494,10 @@ class Snap(bonsai.core.tool.Snap): axis_end = intersection[2] snapping_points.append((intersection[0], "Axis")) + if "Plane" in list(origin.keys()): + intersection = origin["Plane"] + snapping_points.append((intersection, "Plane")) + # Make Axis first priority if event.shift or cls.snap_axis_method in {"X", "Y", "Z"}: cls.update_snapping_ref(snapping_points[0][0], snapping_points[0][1])