Changeset View
Standalone View
source/blender/editors/transform/transform_snap.c
| Show First 20 Lines • Show All 448 Lines • ▼ Show 20 Lines | void applySnapping(TransInfo *t, float *vec) | ||||
| if (t->tsnap.project) | if (t->tsnap.project) | ||||
| return; | return; | ||||
| if (t->tsnap.status & SNAP_FORCED) { | if (t->tsnap.status & SNAP_FORCED) { | ||||
| t->tsnap.targetSnap(t); | t->tsnap.targetSnap(t); | ||||
| 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 | ||||
| /* !TODO! add exception for object mode, no need to slow it down then */ | /* !TODO! add exception for object mode, no need to slow it down then */ | ||||
| if (current - t->tsnap.last >= 0.01) { | if (current - t->tsnap.last >= 0.01) { | ||||
| t->tsnap.calcSnap(t, vec); | t->tsnap.calcSnap(t, vec); | ||||
| t->tsnap.targetSnap(t); | t->tsnap.targetSnap(t); | ||||
| ▲ Show 20 Lines • Show All 1,905 Lines • ▼ Show 20 Lines | bool snapNodesContext(bContext *C, const int mval[2], float *r_dist_px, float r_loc[2], char *r_node_border, SnapMode mode) | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| return snapNodes(scene->toolsettings, CTX_wm_space_node(C), ar, mval, r_dist_px, r_loc, r_node_border, mode); | return snapNodes(scene->toolsettings, CTX_wm_space_node(C), ar, mval, r_dist_px, r_loc, r_node_border, mode); | ||||
| } | } | ||||
| /*================================================================*/ | /*================================================================*/ | ||||
| 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]; | ||||
| 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 (!ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID)) | ||||
| return; | return; | ||||
| action = activeSnap(t) ? BIG_GEARS : NO_GEARS; | action = activeSnap(t) ? BIG_GEARS : NO_GEARS; | ||||
| if (action == BIG_GEARS && (t->modifiers & MOD_PRECISION)) { | if (action == BIG_GEARS && (t->modifiers & MOD_PRECISION)) { | ||||
| action = SMALL_GEARS; | action = SMALL_GEARS; | ||||
| } | } | ||||
| Show All 17 Lines | void snapSequenceBounds(TransInfo *t, const int mval[2]) | ||||
| frame = BKE_sequencer_find_next_prev_edit(t->scene, mframe, SEQ_SIDE_BOTH, true, false, true); | frame = BKE_sequencer_find_next_prev_edit(t->scene, mframe, SEQ_SIDE_BOTH, true, false, true); | ||||
| if (!ts->snap_left) | if (!ts->snap_left) | ||||
| frame = frame - (ts->max - ts->min); | frame = frame - (ts->max - ts->min); | ||||
| 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}; | ||||
| const bool use_aspect = ELEM(t->mode, TFM_TRANSLATION); | const bool use_aspect = ELEM(t->mode, TFM_TRANSLATION); | ||||
| 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 */ | ||||
| if (fac[action] == 0.0f) { | if (fac[action] == 0.0f) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (use_aspect) { | if (use_aspect) { | ||||
| Show All 10 Lines | if (t->spacetype == SPACE_IPO) { | ||||
| UI_view2d_grid_size(grid, &asp_local[0], &asp_local[1]); | UI_view2d_grid_size(grid, &asp_local[0], &asp_local[1]); | ||||
| UI_view2d_grid_free(grid); | UI_view2d_grid_free(grid); | ||||
| asp = asp_local; | asp = asp_local; | ||||
| } | } | ||||
| } | } | ||||
| /* absolute snapping on grid based in (0, 0, 0) of global center */ | |||||
| if (t->tsnap.mode == SCE_SNAP_MODE_GRID && t->mode == TFM_TRANSLATION) { | |||||
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 * roundf((t->center_global[i] + val[i]) / iter_fac) - t->center_global[i]; | |||||
| } | |||||
| } | |||||
| } | |||||
| else { | |||||
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 {… | |||||
| /* relative snapping in fixed increments */ | |||||
| 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]; | ||||
| val[i] = iter_fac * roundf(val[i] / iter_fac); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
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)