Cleanup: Simplify use of 'Snapping Gears'

This commit removes `t->snap[0]` and `t->snap_spatial[0]`.

They were not actually being used, and could add overhead for
transformation without snap.
This commit is contained in:
Germano Cavalcante 2020-10-08 09:45:45 -03:00
parent 196d6166e5
commit 043ddcf3ad
32 changed files with 103 additions and 136 deletions

View File

@ -1622,40 +1622,34 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
}
}
static void initSnapSpatial(TransInfo *t, float r_snap[3])
static void initSnapSpatial(TransInfo *t, float r_snap[2])
{
if (t->spacetype == SPACE_VIEW3D) {
RegionView3D *rv3d = t->region->regiondata;
if (rv3d) {
View3D *v3d = t->area->spacedata.first;
r_snap[0] = 0.0f;
r_snap[1] = ED_view3d_grid_view_scale(t->scene, v3d, rv3d, NULL) * 1.0f;
r_snap[2] = r_snap[1] * 0.1f;
r_snap[0] = ED_view3d_grid_view_scale(t->scene, v3d, rv3d, NULL) * 1.0f;
r_snap[1] = r_snap[0] * 0.1f;
}
}
else if (t->spacetype == SPACE_IMAGE) {
r_snap[0] = 0.0f;
r_snap[1] = 0.0625f;
r_snap[2] = 0.03125f;
r_snap[0] = 0.0625f;
r_snap[1] = 0.03125f;
}
else if (t->spacetype == SPACE_CLIP) {
r_snap[0] = 0.0f;
r_snap[1] = 0.125f;
r_snap[2] = 0.0625f;
r_snap[0] = 0.125f;
r_snap[1] = 0.0625f;
}
else if (t->spacetype == SPACE_NODE) {
r_snap[0] = 0.0f;
r_snap[1] = r_snap[2] = ED_node_grid_size();
r_snap[0] = r_snap[1] = ED_node_grid_size();
}
else if (t->spacetype == SPACE_GRAPH) {
r_snap[0] = 0.0f;
r_snap[1] = 1.0;
r_snap[2] = 0.1f;
r_snap[0] = 1.0;
r_snap[1] = 0.1f;
}
else {
r_snap[0] = 0.0f;
r_snap[1] = r_snap[2] = 1.0f;
r_snap[0] = r_snap[1] = 1.0f;
}
}

View File

@ -316,9 +316,9 @@ typedef struct TransInfo {
/** maximum index on the input vector. */
short idx_max;
/** Snapping Gears. */
float snap[3];
float snap[2];
/** Spatial snapping gears(even when rotating, scaling... etc). */
float snap_spatial[3];
float snap_spatial[2];
/** Mouse side of the current frame, 'L', 'R' or 'B' */
char frame_side;

View File

@ -1280,7 +1280,7 @@ void drawDial3d(const TransInfo *t)
float mat_basis[4][4];
float mat_final[4][4];
float color[4];
float increment;
float increment = 0.0f;
float line_with = GIZMO_AXIS_LINE_WIDTH + 1.0f;
float scale = UI_DPI_FAC * U.gizmo_size;
@ -1335,10 +1335,7 @@ void drawDial3d(const TransInfo *t)
if (activeSnap(t) && (!transformModeUseSnap(t) ||
(t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) {
increment = (t->modifiers & MOD_PRECISION) ? t->snap[2] : t->snap[1];
}
else {
increment = t->snap[0];
increment = (t->modifiers & MOD_PRECISION) ? t->snap[1] : t->snap[0];
}
BLI_assert(axis_idx >= MAN_AXIS_RANGE_ROT_START && axis_idx < MAN_AXIS_RANGE_ROT_END);

View File

@ -125,11 +125,10 @@ void initBakeTime(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 1.0f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 1.0f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE; /* Don't think this uses units? */
}

View File

@ -175,11 +175,10 @@ void initBoneSize(TransInfo *t)
t->num.val_flag[1] |= NUM_NULL_ONE;
t->num.val_flag[2] |= NUM_NULL_ONE;
t->num.flag |= NUM_AFFECT_ALL;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;
t->num.unit_type[1] = B_UNIT_NONE;

View File

@ -102,7 +102,7 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2]))
* this isnt essential but nicer to give reasonable snapping values for radius */
if (t->tsnap.mode & SCE_SNAP_MODE_INCREMENT) {
const float radius_snap = 0.1f;
const float snap_hack = (t->snap[1] * data->warp_init_dist) / radius_snap;
const float snap_hack = (t->snap[0] * data->warp_init_dist) / radius_snap;
values.scale *= snap_hack;
transform_snap_increment(t, values.vector);
values.scale /= snap_hack;
@ -261,11 +261,10 @@ void initBend(TransInfo *t)
t->idx_max = 1;
t->num.idx_max = 1;
t->snap[0] = 0.0f;
t->snap[1] = SNAP_INCREMENTAL_ANGLE;
t->snap[2] = t->snap[1] * 0.2;
t->snap[0] = SNAP_INCREMENTAL_ANGLE;
t->snap[1] = t->snap[0] * 0.2;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
t->num.unit_type[0] = B_UNIT_ROTATION;

View File

@ -102,11 +102,10 @@ void initBoneEnvelope(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -97,11 +97,10 @@ void initBoneRoll(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = DEG2RAD(5.0);
t->snap[2] = DEG2RAD(1.0);
t->snap[0] = DEG2RAD(5.0);
t->snap[1] = DEG2RAD(1.0);
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
t->num.unit_type[0] = B_UNIT_ROTATION;

View File

@ -102,11 +102,10 @@ void initCurveShrinkFatten(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -113,11 +113,10 @@ void initBevelWeight(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -117,11 +117,10 @@ void initCrease(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -134,11 +134,10 @@ void initNormalRotation(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = DEG2RAD(5.0);
t->snap[2] = DEG2RAD(1.0);
t->snap[0] = DEG2RAD(5.0);
t->snap[1] = DEG2RAD(1.0);
copy_v3_fl(t->num.val_inc, t->snap[2]);
copy_v3_fl(t->num.val_inc, t->snap[1]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
t->num.unit_type[0] = B_UNIT_ROTATION;

View File

@ -135,11 +135,10 @@ void initSeqSlide(TransInfo *t)
t->num.flag = 0;
t->num.idx_max = t->idx_max;
t->snap[0] = 0.0f;
t->snap[1] = floorf(t->scene->r.frs_sec / t->scene->r.frs_sec_base);
t->snap[2] = 10.0f;
t->snap[0] = floorf(t->scene->r.frs_sec / t->scene->r.frs_sec_base);
t->snap[1] = 10.0f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
/* Would be nice to have a time handling in units as well
* (supporting frames in addition to "natural" time...). */

View File

@ -1555,11 +1555,10 @@ void initEdgeSlide_ex(
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -98,11 +98,10 @@ void initGPOpacity(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -100,11 +100,10 @@ void initGPShrinkFatten(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -128,11 +128,10 @@ void initMaskShrinkFatten(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -122,11 +122,10 @@ void initPushPull(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 1.0f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 1.0f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_LENGTH;
}

View File

@ -188,11 +188,10 @@ void initResize(TransInfo *t)
t->idx_max = 2;
t->num.idx_max = 2;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;
t->num.unit_type[1] = B_UNIT_NONE;

View File

@ -244,11 +244,10 @@ void initRotation(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = DEG2RAD(5.0);
t->snap[2] = DEG2RAD(1.0);
t->snap[0] = DEG2RAD(5.0);
t->snap[1] = DEG2RAD(1.0);
copy_v3_fl(t->num.val_inc, t->snap[2]);
copy_v3_fl(t->num.val_inc, t->snap[1]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
t->num.unit_type[0] = B_UNIT_ROTATION;

View File

@ -226,11 +226,10 @@ void initShear(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE; /* Don't think we have any unit here? */

View File

@ -128,11 +128,10 @@ void initShrinkFatten(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 1.0f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 1.0f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_LENGTH;

View File

@ -123,11 +123,10 @@ void initSkinResize(TransInfo *t)
t->idx_max = 2;
t->num.idx_max = 2;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;
t->num.unit_type[1] = B_UNIT_NONE;

View File

@ -101,11 +101,10 @@ void initTilt(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = DEG2RAD(5.0);
t->snap[2] = DEG2RAD(1.0);
t->snap[0] = DEG2RAD(5.0);
t->snap[1] = DEG2RAD(1.0);
copy_v3_fl(t->num.val_inc, t->snap[2]);
copy_v3_fl(t->num.val_inc, t->snap[1]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
t->num.unit_type[0] = B_UNIT_ROTATION;

View File

@ -148,10 +148,9 @@ void initTimeScale(TransInfo *t)
t->num.idx_max = t->idx_max;
/* initialize snap like for everything else */
t->snap[0] = 0.0f;
t->snap[1] = t->snap[2] = 1.0f;
t->snap[0] = t->snap[1] = 1.0f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;
}

View File

@ -225,10 +225,9 @@ void initTimeSlide(TransInfo *t)
t->num.idx_max = t->idx_max;
/* initialize snap like for everything else */
t->snap[0] = 0.0f;
t->snap[1] = t->snap[2] = 1.0f;
t->snap[0] = t->snap[1] = 1.0f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
/* No time unit supporting frames currently... */
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -155,10 +155,9 @@ void initTimeTranslate(TransInfo *t)
t->num.idx_max = t->idx_max;
/* initialize snap like for everything else */
t->snap[0] = 0.0f;
t->snap[1] = t->snap[2] = 1.0f;
t->snap[0] = t->snap[1] = 1.0f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
/* No time unit supporting frames currently... */
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -111,11 +111,10 @@ void initToSphere(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -151,11 +151,10 @@ void initTrackball(TransInfo *t)
t->idx_max = 1;
t->num.idx_max = 1;
t->snap[0] = 0.0f;
t->snap[1] = DEG2RAD(5.0);
t->snap[2] = DEG2RAD(1.0);
t->snap[0] = DEG2RAD(5.0);
t->snap[1] = DEG2RAD(1.0);
copy_v3_fl(t->num.val_inc, t->snap[2]);
copy_v3_fl(t->num.val_inc, t->snap[1]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
t->num.unit_type[0] = B_UNIT_ROTATION;

View File

@ -449,9 +449,9 @@ void initTranslation(TransInfo *t)
t->num.flag = 0;
t->num.idx_max = t->idx_max;
copy_v3_v3(t->snap, t->snap_spatial);
copy_v2_v2(t->snap, t->snap_spatial);
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
if (t->spacetype == SPACE_VIEW3D) {
/* Handling units makes only sense in 3Dview... See T38877. */

View File

@ -675,11 +675,10 @@ void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->snap[0] = 0.1f;
t->snap[1] = t->snap[0] * 0.1f;
copy_v3_fl(t->num.val_inc, t->snap[1]);
copy_v3_fl(t->num.val_inc, t->snap[0]);
t->num.unit_sys = t->scene->unit.system;
t->num.unit_type[0] = B_UNIT_NONE;

View File

@ -384,7 +384,7 @@ void applyGridAbsolute(TransInfo *t)
return;
}
float grid_size = (t->modifiers & MOD_PRECISION) ? t->snap_spatial[2] : t->snap_spatial[1];
float grid_size = (t->modifiers & MOD_PRECISION) ? t->snap_spatial[1] : t->snap_spatial[0];
/* early exit on unusable grid size */
if (grid_size == 0.0f) {
@ -1462,7 +1462,7 @@ bool transform_snap_grid(TransInfo *t, float *val)
return false;
}
float grid_dist = (t->modifiers & MOD_PRECISION) ? t->snap[2] : t->snap[1];
float grid_dist = (t->modifiers & MOD_PRECISION) ? t->snap[1] : t->snap[0];
/* Early bailing out if no need to snap */
if (grid_dist == 0.0f) {
@ -1523,6 +1523,10 @@ static void snap_increment_apply(TransInfo *t,
bool transform_snap_increment(TransInfo *t, float *val)
{
if (!activeSnap(t)) {
return false;
}
if (!(t->tsnap.mode & SCE_SNAP_MODE_INCREMENT) && !doForceIncrementSnap(t)) {
return false;
}
@ -1533,8 +1537,7 @@ bool transform_snap_increment(TransInfo *t, float *val)
return false;
}
float increment_dist = activeSnap(t) ? (t->modifiers & MOD_PRECISION) ? t->snap[2] : t->snap[1] :
t->snap[0];
float increment_dist = (t->modifiers & MOD_PRECISION) ? t->snap[1] : t->snap[0];
snap_increment_apply(t, t->idx_max, increment_dist, val);
return true;