Fix T60015: snap to grid - snaps only to largest increment

Caused by rBc7a96651dfa4 when trying to remove all uses of the deprecated `rv3d->gridview`.
This commit is contained in:
Germano Cavalcante 2018-12-31 13:45:20 -02:00
parent 82e0739f64
commit 4d795cee49
Notes: blender-bot 2023-02-14 06:00:47 +01:00
Referenced by issue #60214, Eevee: Flickering or black using random material
Referenced by issue #60133, Using texture projection with external image editor does not work
Referenced by issue #60080, Viewport not always updating material changes
Referenced by issue #60071, Crash when change material after import glTF
Referenced by issue #60072, Eevee: Ambient Occlusion disappears
Referenced by issue #60073,  Cannot remove input of Light Falloff node
Referenced by issue #60074, Eevee: Material not displayed
Referenced by issue #60043, macOS viewport lagging
Referenced by issue #60030, select pattern fails in some type/mode combinations
Referenced by issue #60028, Inconsistent alpha on toolbar/properties regions
Referenced by issue #60015, snap to grid - snaps only to largest increment
3 changed files with 10 additions and 7 deletions

View File

@ -2124,11 +2124,12 @@ static bool gp_snap_poll(bContext *C)
static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op))
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
RegionView3D *rv3d = CTX_wm_region_data(C);
View3D *v3d = CTX_wm_view3d(C);
Scene *scene = CTX_data_scene(C);
Depsgraph *depsgraph = CTX_data_depsgraph(C);
Object *obact = CTX_data_active_object(C);
const float gridf = ED_view3d_grid_scale(scene, v3d, NULL);
const float gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL);
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* only editable and visible layers are considered */

View File

@ -780,9 +780,9 @@ float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit)
return v3d->grid * ED_scene_grid_scale(scene, grid_unit);
}
/* Simulates the grid scale that is visualized by the shaders drawing functions.
* The actual code is seen in `object_grid_frag.glsl` when you get the `grid_res` value.
* Currently the simulation is done only when RV3D_VIEW_IS_AXIS. */
/* Simulates the grid scale that is actually viewed.
* The actual code is seen in `object_grid_frag.glsl` (see `grid_res`).
* Currently the simulation is only done when RV3D_VIEW_IS_AXIS. */
float ED_view3d_grid_view_scale(
Scene *scene, View3D *v3d, RegionView3D *rv3d, const char **grid_unit)
{
@ -798,7 +798,7 @@ float ED_view3d_grid_view_scale(
float lvl = (logf(grid_distance / grid_scale) / logf(grid_subdiv));
/* 1.3f is a visually chosen offset for the
* subdivision to match the displayed grid. */
* subdivision to match the visible grid. */
lvl -= 1.3f;
CLAMP_MIN(lvl, 0.0f);

View File

@ -79,13 +79,14 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op))
ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
Object *obedit = CTX_data_edit_object(C);
Scene *scene = CTX_data_scene(C);
RegionView3D *rv3d = CTX_wm_region_data(C);
View3D *v3d = CTX_wm_view3d(C);
TransVertStore tvs = {NULL};
TransVert *tv;
float gridf, imat[3][3], bmat[3][3], vec[3];
int a;
gridf = ED_view3d_grid_scale(scene, v3d, NULL);
gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL);
if (obedit) {
ViewLayer *view_layer = CTX_data_view_layer(C);
@ -516,10 +517,11 @@ void VIEW3D_OT_snap_selected_to_active(wmOperatorType *ot)
static int snap_curs_to_grid_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
RegionView3D *rv3d = CTX_wm_region_data(C);
View3D *v3d = CTX_wm_view3d(C);
float gridf, *curs;
gridf = ED_view3d_grid_scale(scene, v3d, NULL);
gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL);
curs = scene->cursor.location;
curs[0] = gridf * floorf(0.5f + curs[0] / gridf);