Skip to content

Commit

Permalink
Fix (unreported): Issues with 'SNAP_NOT_SELECTED' for pose and edit m…
Browse files Browse the repository at this point in the history
…odes

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).
  • Loading branch information
Germano Cavalcante committed Feb 12, 2022
1 parent 824f514 commit 52be063
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
5 changes: 4 additions & 1 deletion source/blender/editors/transform/transform_snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
41 changes: 30 additions & 11 deletions source/blender/editors/transform/transform_snap_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 */
Expand All @@ -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],
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 52be063

Please sign in to comment.