diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/transform/transform_constraints.c | 2 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 25 |
2 files changed, 21 insertions, 6 deletions
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index ae5d2c87739..3063ee22c55 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -310,7 +310,7 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, const float in[3 mul_m3_v3(t->con.pmtx, out); // With snap, a projection is alright, no need to correct for view alignment - if (!(t->tsnap.mode != SCE_SNAP_MODE_INCREMENT && activeSnap(t))) { + if (ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID) || activeSnap(t)) { if (getConstraintSpaceDimension(t) == 2) { if (out[0] != 0.0f || out[1] != 0.0f || out[2] != 0.0f) { planeProjection(t, in, out); diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 8e100b9c925..1b0256bdeed 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -454,7 +454,7 @@ void applySnapping(TransInfo *t, float *vec) t->tsnap.applySnap(t, vec); } - else if ((t->tsnap.mode != SCE_SNAP_MODE_INCREMENT) && activeSnap(t)) { + else if (!ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID) && activeSnap(t)) { double current = PIL_check_seconds_timer(); // Time base quirky code to go around findnearest slowness @@ -2393,8 +2393,8 @@ void snapGridIncrement(TransInfo *t, float *val) { GearsType action; - // Only do something if using Snap to Grid - if (t->tsnap.mode != SCE_SNAP_MODE_INCREMENT) + /* only do something if using absolute or incremental grid snapping */ + if (!ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID)) return; action = activeSnap(t) ? BIG_GEARS : NO_GEARS; @@ -2435,6 +2435,7 @@ static void applyGridIncrement(TransInfo *t, float *val, int max_index, const fl const float *asp = use_aspect ? t->aspect : asp_local; int i; + BLI_assert(ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID)); BLI_assert(max_index <= 2); /* Early bailing out if no need to snap */ @@ -2461,7 +2462,21 @@ static void applyGridIncrement(TransInfo *t, float *val, int max_index, const fl } } - for (i = 0; i <= max_index; i++) { - val[i] = fac[action] * asp[i] * floorf(val[i] / (fac[action] * asp[i]) + 0.5f); + /* absolute snapping on grid based on global center */ + if ((t->tsnap.mode == SCE_SNAP_MODE_GRID) && (t->mode == TFM_TRANSLATION)) { + 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]; + } + } + } + else { + /* relative snapping in fixed increments */ + for (i = 0; i <= max_index; i++) { + const float iter_fac = fac[action] * asp[i]; + val[i] = iter_fac * roundf(val[i] / iter_fac); + } } } |