[Bf-blender-cvs] [52be0630125] master: Fix (unreported): Issues with 'SNAP_NOT_SELECTED' for pose and edit modes

Germano Cavalcante noreply at git.blender.org
Sat Feb 12 20:15:06 CET 2022


Commit: 52be06301257a82a1b4a5746e91ff60daa637ded
Author: Germano Cavalcante
Date:   Sat Feb 12 16:13:28 2022 -0300
Branches: master
https://developer.blender.org/rB52be06301257a82a1b4a5746e91ff60daa637ded

Fix (unreported): Issues with 'SNAP_NOT_SELECTED' for pose and edit modes

This is a regression partially introduced in rB0a6f428be7f0.

Bones being transformed into edit mode were snapping to themselves.

And the bones of the pose mode weren't even snapping.

(Curious that this was not reported).

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

M	source/blender/editors/transform/transform_snap.c
M	source/blender/editors/transform/transform_snap_object.c

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

diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 69d71e6dbfd..ce0cf3aa6cb 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -628,13 +628,16 @@ static short snap_select_type_get(TransInfo *t)
       else if (!t->tsnap.snap_self) {
         r_snap_select = SNAP_NOT_ACTIVE;
       }
+      else {
+        r_snap_select = SNAP_NOT_SELECTED;
+      }
     }
     else if ((obedit_type == -1) && base_act && base_act->object &&
              (base_act->object->mode & OB_MODE_PARTICLE_EDIT)) {
       /* Particles edit mode. */
     }
     else if (obedit_type == -1) {
-      /* Object mode */
+      /* Object or pose mode. */
       r_snap_select = SNAP_NOT_SELECTED;
     }
   }
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 6ad5962226a..ca6940040b2 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -477,7 +477,10 @@ static void iter_snap_objects(SnapObjectContext *sctx,
       }
     }
     else if (snap_select == SNAP_NOT_SELECTED) {
-      if ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL)) {
+      if (is_object_active && !(base->object->mode & OB_MODE_OBJECT)) {
+        /* Pass. Consider the selection of elements being edited. */
+      }
+      else if ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL)) {
         continue;
       }
     }
@@ -1818,6 +1821,7 @@ static short snapArmature(SnapObjectContext *sctx,
                           const struct SnapObjectParams *params,
                           Object *ob_eval,
                           const float obmat[4][4],
+                          bool is_object_active,
                           /* read/write args */
                           float *dist_px,
                           /* return args */
@@ -1838,9 +1842,10 @@ static short snapArmature(SnapObjectContext *sctx,
   dist_squared_to_projected_aabb_precalc(
       &neasrest_precalc, lpmat, sctx->runtime.win_size, sctx->runtime.mval);
 
-  bool use_obedit = ((bArmature *)ob_eval->data)->edbo != NULL;
+  bArmature *arm = ob_eval->data;
+  const bool is_editmode = arm->edbo != NULL;
 
-  if (use_obedit == false) {
+  if (is_editmode == false) {
     /* Test BoundBox */
     BoundBox *bb = BKE_armature_boundbox_get(ob_eval);
     if (bb && !snap_bound_box_check_dist(bb->vec[0],
@@ -1859,10 +1864,11 @@ static short snapArmature(SnapObjectContext *sctx,
     mul_v4_m4v4(clip_planes_local[i], tobmat, sctx->runtime.clip_plane[i]);
   }
 
-  const eSnapSelect snap_select = params->snap_select;
-  bool is_persp = sctx->runtime.view_proj == VIEW_PROJ_PERSP;
+  const bool is_posemode = is_object_active && (ob_eval->mode & OB_MODE_POSE);
+  const bool skip_selected = (is_editmode || is_posemode) &&
+                             (params->snap_select == SNAP_NOT_SELECTED);
+  const bool is_persp = sctx->runtime.view_proj == VIEW_PROJ_PERSP;
 
-  bArmature *arm = ob_eval->data;
   if (arm->edbo) {
     LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) {
       if (eBone->layer & arm->layer) {
@@ -1872,7 +1878,7 @@ static short snapArmature(SnapObjectContext *sctx,
         }
 
         const bool is_selected = (eBone->flag & (BONE_ROOTSEL | BONE_TIPSEL)) != 0;
-        if (is_selected && snap_select == SNAP_NOT_SELECTED) {
+        if (is_selected && skip_selected) {
           continue;
         }
         bool has_vert_snap = false;
@@ -1916,10 +1922,16 @@ static short snapArmature(SnapObjectContext *sctx,
   else if (ob_eval->pose && ob_eval->pose->chanbase.first) {
     LISTBASE_FOREACH (bPoseChannel *, pchan, &ob_eval->pose->chanbase) {
       Bone *bone = pchan->bone;
-      /* skip hidden bones */
       if (!bone || (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
+        /* Skip hidden bones. */
         continue;
       }
+
+      const bool is_selected = (bone->flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL)) != 0;
+      if (is_selected && skip_selected) {
+        continue;
+      }
+
       bool has_vert_snap = false;
       const float *head_vec = pchan->pose_head;
       const float *tail_vec = pchan->pose_tail;
@@ -2685,7 +2697,7 @@ static void snap_obj_fn(SnapObjectContext *sctx,
                         const struct SnapObjectParams *params,
                         Object *ob_eval,
                         float obmat[4][4],
-                        bool UNUSED(is_object_active),
+                        bool is_object_active,
                         void *data)
 {
   struct SnapObjUserData *dt = data;
@@ -2721,8 +2733,15 @@ static void snap_obj_fn(SnapObjectContext *sctx,
       break;
     }
     case OB_ARMATURE:
-      retval = snapArmature(
-          sctx, params, ob_eval, obmat, dt->dist_px, dt->r_loc, dt->r_no, dt->r_index);
+      retval = snapArmature(sctx,
+                            params,
+                            ob_eval,
+                            obmat,
+                            is_object_active,
+                            dt->dist_px,
+                            dt->r_loc,
+                            dt->r_no,
+                            dt->r_index);
       break;
     case OB_CURVE:
       retval = snapCurve(



More information about the Bf-blender-cvs mailing list