Fix T59686: snap to adaptive grid occurs with a "delay"
authormano-wii <germano.costa@ig.com.br>
Fri, 21 Dec 2018 18:56:55 +0000 (16:56 -0200)
committermano-wii <germano.costa@ig.com.br>
Fri, 21 Dec 2018 18:56:55 +0000 (16:56 -0200)
In blender 2.8, when you zoom in, the adaptive subdivisions appear earlier than previous versions.
The grid still appears a little before the snap, but since it is very small I see no advantage in snap for this case.

source/blender/editors/space_view3d/view3d_draw.c

index 9fee8f3..b6ded48 100644 (file)
@@ -791,19 +791,18 @@ float ED_view3d_grid_view_scale(
                /* Decrease the distance between grid snap points depending on zoom. */
                float grid_subdiv = v3d->gridsubdiv;
                if (grid_subdiv > 1) {
+                       /* Allow 3 more subdivisions (see OBJECT_engine_init). */
+                       grid_scale /= powf(grid_subdiv, 3);
+
                        float grid_distance = rv3d->dist;
                        float lvl = (logf(grid_distance / grid_scale) / logf(grid_subdiv));
-                       if (lvl < 0.0f) {
-                               /* Negative values need an offset for correct casting.
-                                * By convention, the minimum lvl is limited to -2 (see `objec_mode.c`) */
-                               if (lvl > -2.0f) {
-                                       lvl -= 1.0f;
-                               }
-                               else {
-                                       lvl = -2.0f;
-                               }
-                       }
-                       grid_scale *= pow(grid_subdiv, (int)lvl - 1);
+
+                       /* 1.3f is a visually chosen offset for the
+                        * subdivision to match the displayed grid. */
+                       lvl -= 1.3f;
+                       CLAMP_MIN(lvl, 0.0f);
+
+                       grid_scale *= pow(grid_subdiv, (int)lvl);
                }
        }