Changeset View
Standalone View
source/blender/editors/transform/transform_snap.c
| Context not available. | |||||
| t->tsnap.applySnap(t, 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(); | double current = PIL_check_seconds_timer(); | ||||
| // Time base quirky code to go around findnearest slowness | // Time base quirky code to go around findnearest slowness | ||||
| Context not available. | |||||
| static void UNUSED_FUNCTION(CalcSnapGrid) (TransInfo *t, float *UNUSED(vec)) | static void UNUSED_FUNCTION(CalcSnapGrid) (TransInfo *t, float *UNUSED(vec)) | ||||
| { | { | ||||
| snapGridIncrementAction(t, t->tsnap.snapPoint, BIG_GEARS); | snapGridAction(t, t->tsnap.snapPoint, BIG_GEARS); | ||||
| } | } | ||||
| static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) | static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) | ||||
| Context not available. | |||||
| /*================================================================*/ | /*================================================================*/ | ||||
| static void applyGridIncrement(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action); | static void applyGrid(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action); | ||||
| /** | |||||
| void snapGridIncrementAction(TransInfo *t, float *val, GearsType action) | * \note Used for grid and grid increment snapping | ||||
| */ | |||||
| void snapGridAction(TransInfo *t, float *val, GearsType action) | |||||
| { | { | ||||
| float fac[3]; | float fac[3]; | ||||
| fac[NO_GEARS] = t->snap[0]; | fac[NO_GEARS] = t->snap[0]; | ||||
| fac[BIG_GEARS] = t->snap[1]; | fac[BIG_GEARS] = t->snap[1]; | ||||
| fac[SMALL_GEARS] = t->snap[2]; | fac[SMALL_GEARS] = t->snap[2]; | ||||
| applyGridIncrement(t, val, t->idx_max, fac, action); | |||||
| } | |||||
| applyGrid(t, val, t->idx_max, fac, action); | |||||
| } | |||||
| void snapGridIncrement(TransInfo *t, float *val) | /** | ||||
| * \note Used for grid and grid increment snapping | |||||
| */ | |||||
| void snapGrid(TransInfo *t, float *val) | |||||
| { | { | ||||
| GearsType action; | GearsType action; | ||||
| // Only do something if using Snap to Grid | /* only do something if using Snap to Grid or to Increment */ | ||||
| if (t->tsnap.mode != SCE_SNAP_MODE_INCREMENT) | if (t->tsnap.mode != SCE_SNAP_MODE_INCREMENT && t->tsnap.mode != SCE_SNAP_MODE_GRID) | ||||
| return; | return; | ||||
| action = activeSnap(t) ? BIG_GEARS : NO_GEARS; | action = activeSnap(t) ? BIG_GEARS : NO_GEARS; | ||||
| Context not available. | |||||
| action = SMALL_GEARS; | action = SMALL_GEARS; | ||||
| } | } | ||||
| snapGridIncrementAction(t, val, action); | snapGridAction(t, val, action); | ||||
| } | } | ||||
| void snapSequenceBounds(TransInfo *t, const int mval[2]) | void snapSequenceBounds(TransInfo *t, const int mval[2]) | ||||
| Context not available. | |||||
| t->values[0] = frame - ts->min; | t->values[0] = frame - ts->min; | ||||
| } | } | ||||
| static void applyGridIncrement(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action) | /** | ||||
| * \note Used for grid and grid increment snapping | |||||
| */ | |||||
| static void applyGrid(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action) | |||||
| { | { | ||||
| float asp_local[3] = {1, 1, 1}; | float asp_local[3] = {1, 1, 1}; | ||||
| const bool use_aspect = ELEM(t->mode, TFM_TRANSLATION); | const bool use_aspect = ELEM(t->mode, TFM_TRANSLATION); | ||||
Severin: If you use:
```
else {
BLI_assert(0)
}
```
The next one who wants to add a snap mode into… | |||||
| Context not available. | |||||
| } | } | ||||
| for (i = 0; i <= max_index; i++) { | for (i = 0; i <= max_index; i++) { | ||||
| val[i] = fac[action] * asp[i] * floorf(val[i] / (fac[action] * asp[i]) + 0.5f); | const float iter_fac = fac[action] * asp[i]; | ||||
Not Done Inline ActionsNot sure about disabling for rotate/scale. It's the same as with other transformation orientations: If snap mode is set to grid it should snap to grid. (At least for scale, rotation might be considered a bit special here) @Jonathan Williamson (carter2422), @Paweł Łyczkowski (plyczkowski), @Sebastian Koenig (sebastian_k), or anyone else, what do you think, how would you expect it to behave with rotate/scale? Severin: Not sure about disabling for rotate/scale. It's the same as with other transformation… | |||||
| /* absolute snapping on grid based in (0, 0, 0) of global center */ | |||||
| if (t->tsnap.mode == SCE_SNAP_MODE_GRID) { | |||||
| /* do not let unconstrained axis jump to absolute grid increments */ | |||||
Not Done Inline ActionsI'm not sure why this needs to be changed? If the patch is about adding new snapping mode existing ones should behave the same. If there's some issues involved here this is to be addressed separately in master branch. sergey: I'm not sure why this needs to be changed?
If the patch is about adding new snapping mode… | |||||
Not Done Inline ActionsThis only makes sense for absolute snapping, think its fine to do this. campbellbarton: This only makes sense for absolute snapping, think its fine to do this. | |||||
| if (!(t->con.mode & CON_APPLY) || t->con.mode & (CON_AXIS0 << i)) { | |||||
| val[i] = iter_fac * floorf((t->center_global[i] + val[i]) / iter_fac + 0.5f) - t->center_global[i]; | |||||
| } | |||||
| } | |||||
| /* relative snapping in fixed increments */ | |||||
| else if (t->tsnap.mode == SCE_SNAP_MODE_INCREMENT) { | |||||
| val[i] = iter_fac * (floorf(val[i] / iter_fac + 0.5f)); | |||||
Done Inline ActionsAlso really minor but it keeps annoying me ;P: Codestyle convention would be else {
foo_other();
}See http://wiki.blender.org/index.php/Dev:Doc/Code_Style#Braces Severin: Also really minor but it keeps annoying me ;P: Codestyle convention would be
else {… | |||||
| } | |||||
| else { | |||||
| BLI_assert(0); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
Done Inline ActionsUse t->center_global here fixes editmode behavior. campbellbarton: Use `t->center_global` here fixes editmode behavior. | |||||
If you use:
else { BLI_assert(0) }The next one who wants to add a snap mode into this function doesn't need to update the BLI_assert (which he even might miss/forget)