diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/transform/transform.c | 64 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.h | 2 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_generics.c | 8 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 13 |
4 files changed, 54 insertions, 33 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 6e9820ba57c..ccd57db5959 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -105,6 +105,7 @@ static void len_v3_ensure(float v[3], const float length); static void postInputRotation(TransInfo *t, float values[3]); static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short around); +static void initSnapSpatial(TransInfo *t, float r_snap[3]); /* Transform Callbacks */ @@ -2130,6 +2131,8 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve initSnapping(t, op); // Initialize snapping data AFTER mode flags + initSnapSpatial(t, t->snap_spatial); + /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */ /* EVIL2: we gave as argument also texture space context bit... was cleared */ /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */ @@ -4080,6 +4083,38 @@ static void applyTrackball(TransInfo *t, const int UNUSED(mval[2])) /* -------------------------------------------------------------------- */ /* Transform (Translation) */ +static void initSnapSpatial(TransInfo *t, float r_snap[3]) +{ + if (t->spacetype == SPACE_VIEW3D) { + RegionView3D *rv3d = t->ar->regiondata; + + if (rv3d) { + r_snap[0] = 0.0f; + r_snap[1] = rv3d->gridview * 1.0f; + r_snap[2] = r_snap[1] * 0.1f; + } + } + else if (ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) { + r_snap[0] = 0.0f; + r_snap[1] = 0.125f; + r_snap[2] = 0.0625f; + } + else if (t->spacetype == SPACE_NODE) { + r_snap[0] = 0.0f; + r_snap[1] = ED_node_grid_size(); + r_snap[2] = ED_node_grid_size(); + } + else if (t->spacetype == SPACE_IPO) { + r_snap[0] = 0.0f; + r_snap[1] = 1.0; + r_snap[2] = 0.1f; + } + else { + r_snap[0] = 0.0f; + r_snap[1] = r_snap[2] = 1.0f; + } +} + /** \name Transform Translation * \{ */ @@ -4102,34 +4137,7 @@ static void initTranslation(TransInfo *t) t->num.flag = 0; t->num.idx_max = t->idx_max; - if (t->spacetype == SPACE_VIEW3D) { - RegionView3D *rv3d = t->ar->regiondata; - - if (rv3d) { - t->snap[0] = 0.0f; - t->snap[1] = rv3d->gridview * 1.0f; - t->snap[2] = t->snap[1] * 0.1f; - } - } - else if (ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) { - t->snap[0] = 0.0f; - t->snap[1] = 0.125f; - t->snap[2] = 0.0625f; - } - else if (t->spacetype == SPACE_NODE) { - t->snap[0] = 0.0f; - t->snap[1] = ED_node_grid_size(); - t->snap[2] = ED_node_grid_size(); - } - else if (t->spacetype == SPACE_IPO) { - t->snap[0] = 0.0f; - t->snap[1] = 1.0; - t->snap[2] = 0.1f; - } - else { - t->snap[0] = 0.0f; - t->snap[1] = t->snap[2] = 1.0f; - } + copy_v3_v3(t->snap, t->snap_spatial); copy_v3_fl(t->num.val_inc, t->snap[1]); t->num.unit_sys = t->scene->unit.system; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 8863d337cff..b826b7f9c73 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -81,6 +81,7 @@ typedef struct TransSnap { bool project; bool snap_self; bool peel; + bool snap_spatial_grid; short status; float snapPoint[3]; /* snapping from this point */ float snapTarget[3]; /* to this point */ @@ -364,6 +365,7 @@ typedef struct TransInfo { short event_type; /* event->type used to invoke transform */ short idx_max; /* maximum index on the input vector */ float snap[3]; /* Snapping Gears */ + float snap_spatial[3]; /* Spatial snapping gears(even when rotating, scaling... etc) */ char frame_side; /* Mouse side of the cfra, 'L', 'R' or 'B' */ float viewmat[4][4]; /* copy from G.vd, prevents feedback, */ diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 90c806a2d05..33aef92db1e 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -708,7 +708,13 @@ static void recalcData_spaceclip(TransInfo *t) static void recalcData_objects(TransInfo *t) { Base *base = t->scene->basact; - + + if (t->state != TRANS_CANCEL) { + if (ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID) && t->tsnap.snap_spatial_grid) { + applyGridAbsolute(t); + } + } + if (t->obedit) { if (ELEM(t->obedit->type, OB_CURVE, OB_SURF)) { Curve *cu = t->obedit->data; diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 9555596a380..4ccc05b6614 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -388,7 +388,7 @@ void applyGridAbsolute(TransInfo *t) bool use_obmat = false; int i; - if (!(activeSnap(t) && (t->tsnap.mode == SCE_SNAP_MODE_GRID))) + if (!(activeSnap(t) && (ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID)))) return; grid_action = BIG_GEARS; @@ -396,9 +396,9 @@ void applyGridAbsolute(TransInfo *t) grid_action = SMALL_GEARS; switch (grid_action) { - case NO_GEARS: grid_size = t->snap[0]; break; - case BIG_GEARS: grid_size = t->snap[1]; break; - case SMALL_GEARS: grid_size = t->snap[2]; break; + case NO_GEARS: grid_size = t->snap_spatial[0]; break; + case BIG_GEARS: grid_size = t->snap_spatial[1]; break; + case SMALL_GEARS: grid_size = t->snap_spatial[2]; break; } /* early exit on unusable grid size */ if (grid_size == 0.0f) @@ -637,6 +637,11 @@ void initSnapping(TransInfo *t, wmOperator *op) t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) != 0); t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0); } + + /* for now only 3d view (others can be added if we want) */ + if (t->spacetype == SPACE_VIEW3D) { + t->tsnap.snap_spatial_grid = ((t->settings->snap_flag & SCE_SNAP_ABS_GRID) != 0); + } } t->tsnap.target = snap_target; |