[Bf-blender-cvs] [80cbbd2843c] master: Knife: support vert/edge snapping when not directly over a face

Campbell Barton noreply at git.blender.org
Mon Mar 29 09:22:28 CEST 2021


Commit: 80cbbd2843c2358879b1a710d81a3b41e1468327
Author: Campbell Barton
Date:   Mon Mar 29 17:43:06 2021 +1100
Branches: master
https://developer.blender.org/rB80cbbd2843c2358879b1a710d81a3b41e1468327

Knife: support vert/edge snapping when not directly over a face

Respect the distance argument to EDBM_face_find_nearest,
when zero, sample a single pixel, otherwise sample a region.

Knife uses the selection-buffer to pick a face when the ray-cast failed.
This was meant to allow snapping to nearby faces however as the margin
was ignored, it was only used in edge cases where the ray-cast missed
but the pixel didn't.

Now the face-picking threshold is working as expected.

Note that other callers to EDBM_face_find_nearest have been updated
so set their distance argument to zero so this only impacts the knife.
Regular selection and path select could be modified separately if users
prefer this behavior.

===================================================================

M	source/blender/editors/mesh/editmesh_path.c
M	source/blender/editors/mesh/editmesh_select.c

===================================================================

diff --git a/source/blender/editors/mesh/editmesh_path.c b/source/blender/editors/mesh/editmesh_path.c
index b7f671a4157..13c156fddec 100644
--- a/source/blender/editors/mesh/editmesh_path.c
+++ b/source/blender/editors/mesh/editmesh_path.c
@@ -646,6 +646,9 @@ static BMElem *edbm_elem_find_nearest(ViewContext *vc, const char htype)
     return (BMElem *)EDBM_edge_find_nearest(vc, &dist);
   }
   if ((em->selectmode & SCE_SELECT_FACE) && (htype == BM_FACE)) {
+    /* Only pick faces directly under the cursor.
+     * We could look into changing this, for now it matches regular face selection. */
+    dist = 0.0f;
     return (BMElem *)EDBM_face_find_nearest(vc, &dist);
   }
 
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 35608a4abde..e4a4f56b8d7 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -715,14 +715,27 @@ BMFace *EDBM_face_find_nearest_ex(ViewContext *vc,
   uint base_index = 0;
 
   if (!XRAY_FLAG_ENABLED(vc->v3d)) {
-    float dist_test = 0.0f;
+    float dist_test;
     uint index;
     BMFace *efa;
 
     {
+      uint dist_px = 0;
+      if (*r_dist != 0.0f) {
+        dist_px = (uint)ED_view3d_backbuf_sample_size_clamp(vc->region, *r_dist);
+      }
+
       DRW_select_buffer_context_create(bases, bases_len, SCE_SELECT_FACE);
 
-      index = DRW_select_buffer_sample_point(vc->depsgraph, vc->region, vc->v3d, vc->mval);
+      if (dist_px == 0) {
+        index = DRW_select_buffer_sample_point(vc->depsgraph, vc->region, vc->v3d, vc->mval);
+        dist_test = 0.0f;
+      }
+      else {
+        index = DRW_select_buffer_find_nearest_to_point(
+            vc->depsgraph, vc->region, vc->v3d, vc->mval, 1, UINT_MAX, &dist_px);
+        dist_test = dist_px;
+      }
 
       if (index) {
         efa = (BMFace *)edbm_select_id_bm_elem_get(bases, index, &base_index);
@@ -875,6 +888,13 @@ static bool unified_findnearest(ViewContext *vc,
   /* no afterqueue (yet), so we check it now, otherwise the em_xxxofs indices are bad */
 
   if ((dist > 0.0f) && (em->selectmode & SCE_SELECT_FACE)) {
+
+    /* Force zero distance, this is a historic exception for faces
+     * as this function didn't originally support using a margin.
+     * Only pick faces directly under the cursor to prevent unexpected changes in behavior.
+     * While this could be changed, take care this isn't causing issues from a user perspective. */
+    dist = 0.0f;
+
     float dist_center = 0.0f;
     float *dist_center_p = (em->selectmode & (SCE_SELECT_EDGE | SCE_SELECT_VERTEX)) ?
                                &dist_center :
@@ -885,6 +905,9 @@ static bool unified_findnearest(ViewContext *vc,
     BMFace *efa_test = EDBM_face_find_nearest_ex(
         vc, &dist, dist_center_p, true, use_cycle, &efa_zbuf, bases, bases_len, &base_index);
 
+    if (efa_test == NULL) {
+      dist = dist_init;
+    }
     if (efa_test && dist_center_p) {
       dist = min_ff(dist_margin, dist_center);
     }



More information about the Bf-blender-cvs mailing list