Fix T101991: "Absolute Grid Snap" not working
Error introduced in rB1edebb794b76. In that commit it was kind of forgotten that the snap to grid is also used in 3D views. Also a refactoring and cleanup was applied to simplify the code.
This commit is contained in:
parent
9f56021975
commit
a7aa0f1a0c
Notes:
blender-bot
2023-02-14 10:54:29 +01:00
Referenced by commitc2e36c09b9
, Fix variable value assigned twice in succession Referenced by commit93afc50ac3
, Fix large incremental snap values in uv editor Referenced by issue #101991, "Absolute Grid Snap" not working
|
@ -1721,13 +1721,17 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
|
|||
}
|
||||
}
|
||||
|
||||
static void initSnapSpatial(TransInfo *t, float r_snap[2], float r_snap_y[2])
|
||||
static void initSnapSpatial(TransInfo *t, float r_snap[3], float *r_snap_precision)
|
||||
{
|
||||
/* Default values. */
|
||||
r_snap[0] = r_snap[1] = 1.0f;
|
||||
r_snap[1] = 0.0f;
|
||||
*r_snap_precision = 0.1f;
|
||||
|
||||
if (t->spacetype == SPACE_VIEW3D) {
|
||||
if (t->region->regiondata) {
|
||||
View3D *v3d = t->area->spacedata.first;
|
||||
r_snap[0] = ED_view3d_grid_view_scale(t->scene, v3d, t->region, NULL) * 1.0f;
|
||||
r_snap[1] = r_snap[0] * 0.1f;
|
||||
r_snap[0] = r_snap[1] = r_snap[2] = ED_view3d_grid_view_scale(t->scene, v3d, t->region, NULL);
|
||||
}
|
||||
}
|
||||
else if (t->spacetype == SPACE_IMAGE) {
|
||||
|
@ -1741,24 +1745,16 @@ static void initSnapSpatial(TransInfo *t, float r_snap[2], float r_snap_y[2])
|
|||
ED_space_image_grid_steps(sima, grid_steps_x, grid_steps_y, grid_size);
|
||||
/* Snapping value based on what type of grid is used (adaptive-subdividing or custom-grid). */
|
||||
r_snap[0] = ED_space_image_increment_snap_value(grid_size, grid_steps_x, zoom_factor);
|
||||
r_snap[1] = r_snap[0] / 2.0f;
|
||||
r_snap_y[0] = ED_space_image_increment_snap_value(grid_size, grid_steps_y, zoom_factor);
|
||||
r_snap_y[1] = r_snap_y[0] / 2.0f;
|
||||
r_snap[1] = ED_space_image_increment_snap_value(grid_size, grid_steps_y, zoom_factor);
|
||||
*r_snap_precision = 0.5f;
|
||||
}
|
||||
else if (t->spacetype == SPACE_CLIP) {
|
||||
r_snap[0] = 0.125f;
|
||||
r_snap[1] = 0.0625f;
|
||||
r_snap[0] = r_snap[1] = 0.125f;
|
||||
*r_snap_precision = 0.5f;
|
||||
}
|
||||
else if (t->spacetype == SPACE_NODE) {
|
||||
r_snap[0] = r_snap[1] = ED_node_grid_size();
|
||||
}
|
||||
else if (t->spacetype == SPACE_GRAPH) {
|
||||
r_snap[0] = 1.0;
|
||||
r_snap[1] = 0.1f;
|
||||
}
|
||||
else {
|
||||
r_snap[0] = r_snap[1] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event, int mode)
|
||||
|
@ -1898,7 +1894,7 @@ 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_x, t->snap_spatial_y);
|
||||
initSnapSpatial(t, t->snap_spatial, &t->snap_spatial_precision);
|
||||
|
||||
/* EVIL! posemode code can switch translation to rotate when 1 bone is selected.
|
||||
* will be removed (ton) */
|
||||
|
|
|
@ -555,9 +555,12 @@ typedef struct TransInfo {
|
|||
/** Snapping Gears. */
|
||||
float snap[2];
|
||||
/** Spatial snapping gears(even when rotating, scaling... etc). */
|
||||
float snap_spatial_x[2];
|
||||
/** Spatial snapping in the Y coordinate, for non-uniform grid in UV Editor. */
|
||||
float snap_spatial_y[2];
|
||||
float snap_spatial[3];
|
||||
/**
|
||||
* Precision factor that is multiplied to snap_spatial when precision
|
||||
* modifier is enabled for snap to grid or incremental snap.
|
||||
*/
|
||||
float snap_spatial_precision;
|
||||
/** Mouse side of the current frame, 'L', 'R' or 'B' */
|
||||
char frame_side;
|
||||
|
||||
|
|
|
@ -590,7 +590,8 @@ void initTranslation(TransInfo *t)
|
|||
t->num.flag = 0;
|
||||
t->num.idx_max = t->idx_max;
|
||||
|
||||
copy_v2_v2(t->snap, t->snap_spatial_x);
|
||||
t->snap[0] = 1.0;
|
||||
t->snap[1] = t->snap_spatial_precision;
|
||||
|
||||
copy_v3_fl(t->num.val_inc, t->snap[0]);
|
||||
t->num.unit_sys = t->scene->unit.system;
|
||||
|
|
|
@ -519,16 +519,14 @@ void applyGridAbsolute(TransInfo *t)
|
|||
return;
|
||||
}
|
||||
|
||||
float grid_size_x = (t->modifiers & MOD_PRECISION) ? t->snap_spatial_x[1] : t->snap_spatial_x[0];
|
||||
float grid_size_y = (t->modifiers & MOD_PRECISION) ? t->snap_spatial_y[1] : t->snap_spatial_y[0];
|
||||
float grid_size_z = grid_size_x;
|
||||
|
||||
if (grid_size_y == 0.0f) {
|
||||
grid_size_y = grid_size_x; /* Just use `grid_size_x` when `grid_size_y` isn't set correctly. */
|
||||
float grid_size[3];
|
||||
copy_v3_v3(grid_size, t->snap_spatial);
|
||||
if (t->modifiers & MOD_PRECISION) {
|
||||
mul_v3_fl(grid_size, t->snap_spatial_precision);
|
||||
}
|
||||
|
||||
/* Early exit on unusable grid size. */
|
||||
if (grid_size_x == 0.0f || grid_size_y == 0.0f || grid_size_z == 0.0f) {
|
||||
if (is_zero_v3(grid_size)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -554,9 +552,9 @@ void applyGridAbsolute(TransInfo *t)
|
|||
copy_v3_v3(iloc, td->ob->obmat[3]);
|
||||
}
|
||||
|
||||
loc[0] = roundf(iloc[0] / grid_size_x) * grid_size_x;
|
||||
loc[1] = roundf(iloc[1] / grid_size_y) * grid_size_y;
|
||||
loc[2] = roundf(iloc[2] / grid_size_z) * grid_size_z;
|
||||
loc[0] = roundf(iloc[0] / grid_size[0]) * grid_size[0];
|
||||
loc[1] = roundf(iloc[1] / grid_size[1]) * grid_size[1];
|
||||
loc[2] = grid_size[2] ? roundf(iloc[2] / grid_size[2]) * grid_size[2] : iloc[2];
|
||||
|
||||
sub_v3_v3v3(tvec, loc, iloc);
|
||||
mul_m3_v3(td->smtx, tvec);
|
||||
|
@ -1660,8 +1658,7 @@ bool snapNodesTransform(
|
|||
|
||||
static void snap_grid_apply(TransInfo *t,
|
||||
const int max_index,
|
||||
const float grid_dist_x,
|
||||
const float grid_dist_y,
|
||||
const float grid_dist[3],
|
||||
const float loc[3],
|
||||
float r_out[3])
|
||||
{
|
||||
|
@ -1680,7 +1677,7 @@ static void snap_grid_apply(TransInfo *t,
|
|||
}
|
||||
|
||||
for (int i = 0; i <= max_index; i++) {
|
||||
const float iter_fac = ((i == 1) ? grid_dist_y : grid_dist_x) * asp[i];
|
||||
const float iter_fac = grid_dist[i] * asp[i];
|
||||
r_out[i] = iter_fac * roundf((in[i] + center_global[i]) / iter_fac) - center_global[i];
|
||||
}
|
||||
}
|
||||
|
@ -1705,15 +1702,18 @@ bool transform_snap_grid(TransInfo *t, float *val)
|
|||
return false;
|
||||
}
|
||||
|
||||
float grid_dist_x = (t->modifiers & MOD_PRECISION) ? t->snap_spatial_x[1] : t->snap_spatial_x[0];
|
||||
float grid_dist_y = (t->modifiers & MOD_PRECISION) ? t->snap_spatial_y[1] : t->snap_spatial_y[0];
|
||||
float grid_dist[3];
|
||||
copy_v3_v3(grid_dist, t->snap_spatial);
|
||||
if (t->modifiers & MOD_PRECISION) {
|
||||
mul_v3_fl(grid_dist, t->snap_spatial_precision);
|
||||
}
|
||||
|
||||
/* Early bailing out if no need to snap */
|
||||
if (grid_dist_x == 0.0f || grid_dist_y == 0.0f) {
|
||||
if (is_zero_v3(grid_dist)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
snap_grid_apply(t, t->idx_max, grid_dist_x, grid_dist_y, val, val);
|
||||
snap_grid_apply(t, t->idx_max, grid_dist, val, val);
|
||||
t->tsnap.snapElem = SCE_SNAP_MODE_GRID;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue