Snap - Improve how viewport zoom affects snapping.

This commit is contained in:
Bruno Perdigão
2025-04-05 11:45:56 -03:00
parent bb91416c4e
commit 2bf303686c
2 changed files with 10 additions and 12 deletions
+3 -5
View File
@@ -193,9 +193,7 @@ class Raycast(bonsai.core.tool.Raycast):
# Makes the snapping point more or less sticky than others
# It changes the distance and affects how the snapping point are sorted
# We multiply by the increment snap which is based on the viewport zoom
snap_threshold = 10 * tool.Snap.get_increment_snap_value(bpy.context)
if face:
snap_threshold = tool.Snap.get_increment_snap_value(bpy.context)
snap_threshold = rv3d.view_distance / 100
try:
loc = view3d_utils.region_2d_to_location_3d(region, rv3d, mouse_pos, ray_direction)
@@ -288,7 +286,7 @@ class Raycast(bonsai.core.tool.Raycast):
rv3d = context.region_data
mouse_pos = event.mouse_region_x, event.mouse_region_y
ray_origin, ray_target, ray_direction = cls.get_viewport_ray_data(context, event)
snap_threshold = tool.Snap.get_increment_snap_value(bpy.context)
snap_threshold = rv3d.view_distance / 100
try:
loc = view3d_utils.region_2d_to_location_3d(region, rv3d, mouse_pos, ray_direction)
@@ -365,7 +363,7 @@ class Raycast(bonsai.core.tool.Raycast):
rv3d = context.region_data
mouse_pos = event.mouse_region_x, event.mouse_region_y
ray_origin, ray_target, ray_direction = cls.get_viewport_ray_data(context, event)
snap_threshold = tool.Snap.get_increment_snap_value(bpy.context)
snap_threshold = rv3d.view_distance / 100
try:
loc = view3d_utils.region_2d_to_location_3d(region, rv3d, mouse_pos, ray_direction)
+7 -7
View File
@@ -483,17 +483,17 @@ class Snap(bonsai.core.tool.Snap):
def sort_points_by_weighted_distance(snapping_points):
for snap in snapping_points:
weight_factor = 100 * cls.get_increment_snap_value(context)
zoom_factor = bpy.context.region_data.view_distance
if snap["type"] == "Vertex":
snap["distance"] *= weight_factor / 12
if snap["type"] == "Edge":
snap["distance"] *= weight_factor
snap["distance"] *= (zoom_factor / 10)
if snap["type"] == "Edge Center":
snap["distance"] *= weight_factor / 5
snap["distance"] *= (zoom_factor / 8)
if snap["type"] == "Edge Intersection":
snap["distance"] *= weight_factor / 10
snap["distance"] *= (zoom_factor / 5)
if snap["type"] == "Edge":
snap["distance"] *= zoom_factor
if snap["type"] in ["Plane", "Axis", "Face"]:
snap["distance"] = weight_factor / 50
snap["distance"] *= zoom_factor
return sorted(snapping_points, key=lambda x: x["distance"])
snaps_by_group = filter_snapping_points_by_group(detected_snaps)