diff options
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 38f1d37acd6..e1cf7436236 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -324,7 +324,7 @@ void applyProject(TransInfo *t) if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { if (snapObjectsTransform( - t, mval_fl, t->tsnap.modeSelect, &dist_px, + t, mval_fl, &dist_px, loc, no)) { // if (t->flag & (T_EDIT|T_POSE)) { @@ -553,10 +553,10 @@ static void initSnappingMode(TransInfo *t) { /* Exclude editmesh if using proportional edit */ if ((obedit->type == OB_MESH) && (t->flag & T_PROP_EDIT)) { - t->tsnap.modeSelect = SNAP_NOT_OBEDIT; + t->tsnap.modeSelect = SNAP_NOT_ACTIVE; } else { - t->tsnap.modeSelect = t->tsnap.snap_self ? SNAP_ALL : SNAP_NOT_OBEDIT; + t->tsnap.modeSelect = t->tsnap.snap_self ? SNAP_ALL : SNAP_NOT_ACTIVE; } } /* Particles edit mode*/ @@ -964,14 +964,14 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) if (t->tsnap.mode == SCE_SNAP_MODE_VOLUME) { found = peelObjectsTransform( - t, mval, t->tsnap.modeSelect, + t, mval, (t->settings->snap_flag & SCE_SNAP_PEEL_OBJECT) != 0, loc, no, NULL); } else { zero_v3(no); /* objects won't set this */ found = snapObjectsTransform( - t, mval, t->tsnap.modeSelect, &dist_px, + t, mval, &dist_px, loc, no); } @@ -1207,17 +1207,16 @@ static void TargetSnapClosest(TransInfo *t) } bool snapObjectsTransform( - TransInfo *t, const float mval[2], SnapSelect snap_select, + TransInfo *t, const float mval[2], float *dist_px, float r_loc[3], float r_no[3]) { return ED_transform_snap_object_project_view3d_ex( t->tsnap.object_context, + t->scene->toolsettings->snap_mode, &(const struct SnapObjectParams){ - .snap_select = snap_select, - .snap_to = t->scene->toolsettings->snap_mode, - .use_object_edit = (t->flag & T_EDIT) != 0, - .use_object_active = (t->options & CTX_GPENCIL_STROKES) == 0, + .snap_select = ((t->options & CTX_GPENCIL_STROKES) != 0) ? SNAP_NOT_ACTIVE : t->tsnap.modeSelect, + .use_object_edit_cage = (t->flag & T_EDIT) != 0, }, mval, dist_px, NULL, r_loc, r_no, NULL); @@ -1228,18 +1227,16 @@ bool snapObjectsTransform( bool peelObjectsSnapContext( SnapObjectContext *sctx, - const float mval[2], SnapSelect snap_select, bool use_peel_object, + const float mval[2], + const struct SnapObjectParams *params, + const bool use_peel_object, /* return args */ float r_loc[3], float r_no[3], float *r_thickness) { ListBase depths_peel = {0}; ED_transform_snap_object_project_all_view3d_ex( sctx, - &(const struct SnapObjectParams){ - .snap_to = SCE_SNAP_MODE_FACE, - .snap_select = snap_select, - .use_object_edit = true, - }, + params, mval, -1.0f, false, &depths_peel); @@ -1299,13 +1296,19 @@ bool peelObjectsSnapContext( bool peelObjectsTransform( TransInfo *t, - const float mval[2], SnapSelect snap_select, bool use_peel_object, + const float mval[2], + const bool use_peel_object, /* return args */ float r_loc[3], float r_no[3], float *r_thickness) { return peelObjectsSnapContext( t->tsnap.object_context, - mval, snap_select, use_peel_object, + mval, + &(const struct SnapObjectParams){ + .snap_select = ((t->options & CTX_GPENCIL_STROKES) != 0) ? SNAP_NOT_ACTIVE : t->tsnap.modeSelect, + .use_object_edit_cage = (t->flag & T_EDIT) != 0, + }, + use_peel_object, r_loc, r_no, r_thickness); } @@ -1520,11 +1523,21 @@ static void applyGridIncrement(TransInfo *t, float *val, int max_index, const fl /* absolute snapping on grid based on global center */ if ((t->tsnap.snap_spatial_grid) && (t->mode == TFM_TRANSLATION)) { + const float *center_global = t->center_global; + + /* use a fallback for cursor selection, + * this isn't useful as a global center for absolute grid snapping + * since its not based on the position of the selection. */ + if (t->around == V3D_AROUND_CURSOR) { + const TransCenterData *cd = transformCenter_from_type(t, V3D_AROUND_CENTER_MEAN); + center_global = cd->global; + } + for (i = 0; i <= max_index; i++) { /* do not let unconstrained axis jump to absolute grid increments */ if (!(t->con.mode & CON_APPLY) || t->con.mode & (CON_AXIS0 << i)) { const float iter_fac = fac[action] * asp[i]; - val[i] = iter_fac * roundf((val[i] + t->center_global[i]) / iter_fac) - t->center_global[i]; + val[i] = iter_fac * roundf((val[i] + center_global[i]) / iter_fac) - center_global[i]; } } } |