Fix snapping not performing on selected bones or splines

This is an old issue but never reported as it is only visible in the measure tool snapping.
This commit is contained in:
Germano Cavalcante 2021-11-12 19:54:35 -03:00
parent eed48a7322
commit 0a6f428be7
Notes: blender-bot 2023-02-14 06:05:22 +01:00
Referenced by commit 459d9c1e3d, Fix (unreported): Issues with 'SNAP_NOT_SELECTED' for pose and edit modes
Referenced by commit 52be063012, Fix (unreported): Issues with 'SNAP_NOT_SELECTED' for pose and edit modes
1 changed files with 88 additions and 65 deletions

View File

@ -471,7 +471,7 @@ static void iter_snap_objects(SnapObjectContext *sctx,
continue;
}
if (base->flag_legacy & BA_TRANSFORM_LOCKED_IN_PLACE) {
if ((snap_select == SNAP_ALL) || (base->flag_legacy & BA_TRANSFORM_LOCKED_IN_PLACE)) {
/* pass */
}
else if (base->flag_legacy & BA_SNAP_FIX_DEPS_FIASCO) {
@ -479,13 +479,13 @@ static void iter_snap_objects(SnapObjectContext *sctx,
}
const bool is_object_active = (base == base_act);
if (snap_select == SNAP_NOT_SELECTED) {
if ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL)) {
if (snap_select == SNAP_NOT_ACTIVE) {
if (is_object_active) {
continue;
}
}
else if (snap_select == SNAP_NOT_ACTIVE) {
if (is_object_active) {
else if (snap_select == SNAP_NOT_SELECTED) {
if ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL)) {
continue;
}
}
@ -1849,74 +1849,38 @@ static short snapArmature(SnapObjectContext *sctx,
mul_v4_m4v4(clip_planes_local[i], tobmat, sctx->runtime.clip_plane[i]);
}
const eSnapSelect snap_select = sctx->runtime.params->snap_select;
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) {
/* skip hidden or moving (selected) bones */
if ((eBone->flag & (BONE_HIDDEN_A | BONE_ROOTSEL | BONE_TIPSEL)) == 0) {
bool has_vert_snap = false;
if (sctx->runtime.snap_to_flag & SCE_SNAP_MODE_VERTEX) {
has_vert_snap = test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
eBone->head,
&dist_px_sq,
r_loc);
has_vert_snap |= test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
eBone->tail,
&dist_px_sq,
r_loc);
if (has_vert_snap) {
retval = SCE_SNAP_MODE_VERTEX;
}
}
if (!has_vert_snap && sctx->runtime.snap_to_flag & SCE_SNAP_MODE_EDGE) {
if (test_projected_edge_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
eBone->head,
eBone->tail,
&dist_px_sq,
r_loc)) {
retval = SCE_SNAP_MODE_EDGE;
}
}
if (eBone->flag & BONE_HIDDEN_A) {
/* Skip hidden bones. */
continue;
}
const bool is_selected = (eBone->flag & (BONE_ROOTSEL | BONE_TIPSEL)) != 0;
if (is_selected && snap_select == SNAP_NOT_SELECTED) {
continue;
}
}
}
}
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))) {
bool has_vert_snap = false;
const float *head_vec = pchan->pose_head;
const float *tail_vec = pchan->pose_tail;
if (sctx->runtime.snap_to_flag & SCE_SNAP_MODE_VERTEX) {
has_vert_snap = test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
head_vec,
eBone->head,
&dist_px_sq,
r_loc);
has_vert_snap |= test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
tail_vec,
eBone->tail,
&dist_px_sq,
r_loc);
@ -1929,8 +1893,8 @@ static short snapArmature(SnapObjectContext *sctx,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
head_vec,
tail_vec,
eBone->head,
eBone->tail,
&dist_px_sq,
r_loc)) {
retval = SCE_SNAP_MODE_EDGE;
@ -1939,6 +1903,51 @@ 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))) {
continue;
}
bool has_vert_snap = false;
const float *head_vec = pchan->pose_head;
const float *tail_vec = pchan->pose_tail;
if (sctx->runtime.snap_to_flag & SCE_SNAP_MODE_VERTEX) {
has_vert_snap = test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
head_vec,
&dist_px_sq,
r_loc);
has_vert_snap |= test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
tail_vec,
&dist_px_sq,
r_loc);
if (has_vert_snap) {
retval = SCE_SNAP_MODE_VERTEX;
}
}
if (!has_vert_snap && sctx->runtime.snap_to_flag & SCE_SNAP_MODE_EDGE) {
if (test_projected_edge_dist(&neasrest_precalc,
clip_planes_local,
sctx->runtime.clip_plane_len,
is_persp,
head_vec,
tail_vec,
&dist_px_sq,
r_loc)) {
retval = SCE_SNAP_MODE_EDGE;
}
}
}
}
if (retval) {
*dist_px = sqrtf(dist_px_sq);
@ -1980,8 +1989,7 @@ static short snapCurve(SnapObjectContext *sctx,
dist_squared_to_projected_aabb_precalc(
&neasrest_precalc, lpmat, sctx->runtime.win_size, sctx->runtime.mval);
const bool use_obedit = (sctx->runtime.params->edit_mode_type == SNAP_GEOM_EDIT) &&
BKE_object_is_in_editmode(ob_eval);
const bool use_obedit = BKE_object_is_in_editmode(ob_eval);
if (use_obedit == false) {
/* Test BoundBox */
@ -2014,14 +2022,20 @@ static short snapCurve(SnapObjectContext *sctx,
}
bool is_persp = sctx->runtime.view_proj == VIEW_PROJ_PERSP;
bool skip_selected = sctx->runtime.params->snap_select == SNAP_NOT_SELECTED;
for (Nurb *nu = (use_obedit ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) {
for (int u = 0; u < nu->pntsu; u++) {
if (sctx->runtime.snap_to_flag & SCE_SNAP_MODE_VERTEX) {
if (use_obedit) {
if (nu->bezt) {
/* don't snap to selected (moving) or hidden */
if (nu->bezt[u].f2 & SELECT || nu->bezt[u].hide != 0) {
if (nu->bezt[u].hide) {
/* Skip hidden. */
continue;
}
bool is_selected = (nu->bezt[u].f2 & SELECT) != 0;
if (is_selected && skip_selected) {
continue;
}
has_snap |= test_projected_vert_dist(&neasrest_precalc,
@ -2033,8 +2047,9 @@ static short snapCurve(SnapObjectContext *sctx,
r_loc);
/* Don't snap if handle is selected (moving),
* or if it is aligning to a moving handle. */
if (!(nu->bezt[u].f1 & SELECT) &&
!(nu->bezt[u].h1 & HD_ALIGN && nu->bezt[u].f3 & SELECT)) {
is_selected = (!(nu->bezt[u].f1 & SELECT) &&
!(nu->bezt[u].h1 & HD_ALIGN && nu->bezt[u].f3 & SELECT)) != 0;
if (!(is_selected && skip_selected)) {
has_snap |= test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
clip_plane_len,
@ -2043,8 +2058,10 @@ static short snapCurve(SnapObjectContext *sctx,
&dist_px_sq,
r_loc);
}
if (!(nu->bezt[u].f3 & SELECT) &&
!(nu->bezt[u].h2 & HD_ALIGN && nu->bezt[u].f1 & SELECT)) {
is_selected = (!(nu->bezt[u].f3 & SELECT) &&
!(nu->bezt[u].h2 & HD_ALIGN && nu->bezt[u].f1 & SELECT)) != 0;
if (!(is_selected && skip_selected)) {
has_snap |= test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
clip_plane_len,
@ -2055,10 +2072,16 @@ static short snapCurve(SnapObjectContext *sctx,
}
}
else {
/* don't snap to selected (moving) or hidden */
if (nu->bp[u].f1 & SELECT || nu->bp[u].hide != 0) {
if (nu->bp[u].hide) {
/* Skip hidden. */
continue;
}
bool is_selected = (nu->bp[u].f1 & SELECT) != 0;
if (is_selected && skip_selected) {
continue;
}
has_snap |= test_projected_vert_dist(&neasrest_precalc,
clip_planes_local,
clip_plane_len,