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 applyGridIncrement(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action); | static void applyGridIncrement(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action); | ||||
| /** | |||||
| * \note Used for grid and grid increment snapping | |||||
| */ | |||||
| void snapGridIncrementAction(TransInfo *t, float *val, GearsType action) | void snapGridIncrementAction(TransInfo *t, float *val, GearsType action) | ||||
| { | { | ||||
| float fac[3]; | float fac[3]; | ||||
| Context not available. | |||||
| 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); | applyGridIncrement(t, val, t->idx_max, fac, action); | ||||
| } | } | ||||
| /** | |||||
| * \note Used for grid and grid increment snapping | |||||
| */ | |||||
| void snapGridIncrement(TransInfo *t, float *val) | void snapGridIncrement(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. | |||||
| t->values[0] = frame - ts->min; | t->values[0] = frame - ts->min; | ||||
| } | } | ||||
| /** | |||||
| * \note Used for grid and increment snapping | |||||
| */ | |||||
| static void applyGridIncrement(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action) | static void applyGridIncrement(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}; | ||||
| Context not available. | |||||
| const float *asp = use_aspect ? t->aspect : asp_local; | const float *asp = use_aspect ? t->aspect : asp_local; | ||||
| int i; | int i; | ||||
| BLI_assert(ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID)); | |||||
Severin: If you use:
```
else {
BLI_assert(0)
}
```
The next one who wants to add a snap mode into… | |||||
| BLI_assert(max_index <= 2); | BLI_assert(max_index <= 2); | ||||
| /* Early bailing out if no need to snap */ | /* Early bailing out if no need to snap */ | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| for (i = 0; i <= max_index; i++) { | /* absolute snapping on grid based in (0, 0, 0) of global center */ | ||||
| val[i] = fac[action] * asp[i] * floorf(val[i] / (fac[action] * asp[i]) + 0.5f); | if (t->tsnap.mode == SCE_SNAP_MODE_GRID && t->mode == TFM_TRANSLATION) { | ||||
SeverinUnsubmitted 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… | |||||
| for (i = 0; i <= max_index; i++) { | |||||
| const float iter_fac = fac[action] * asp[i]; | |||||
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. | |||||
| /* do not let unconstrained axis jump to absolute grid increments */ | |||||
| 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 { | |||||
SeverinUnsubmitted 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 {… | |||||
| for (i = 0; i <= max_index; i++) { | |||||
| const float iter_fac = fac[action] * asp[i]; | |||||
| val[i] = iter_fac * (floorf(val[i] / iter_fac + 0.5f)); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| 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)