Fix T61286: Viewport grid units not visible

The original code was commented on.
Unlike blender 2.79, the grid units are now displayed only when RV3D_VIEW_IS_AXIS.
The visible subdivisions in the grid are made by the GPU and depending on the pixel.
The code used here only mimics this behavior and adds a bit of overhead.

Reviewers: fclem, campbellbarton

Subscribers: FloridaJo, zlsa, rl.amorato, EitanSomething

Differential Revision: https://developer.blender.org/D4325
This commit is contained in:
Germano Cavalcante 2019-08-20 08:56:48 -03:00
parent f2cab8267f
commit 859f2561c8
Notes: blender-bot 2023-04-27 15:07:22 +02:00
Referenced by issue #61286, Viewport grid units should be visible
Referenced by issue #107274, Crash when trying to frame a big object in ortho view (global-buffer-overflow with imperial Unit System)
1 changed files with 34 additions and 13 deletions

View File

@ -920,12 +920,23 @@ float ED_view3d_grid_view_scale(Scene *scene,
float min_dist = 0.38f * (rv3d->dist / v3d->lens);
float grid_steps[8];
ED_view3d_grid_steps(scene, v3d, rv3d, grid_steps);
for (int i = 0; i < ARRAY_SIZE(grid_steps); i++) {
int i;
for (i = 0; i < ARRAY_SIZE(grid_steps); i++) {
grid_scale = grid_steps[i];
if (grid_scale > min_dist) {
break;
}
}
if (grid_unit) {
const void *usys;
int len;
bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
if (usys) {
*grid_unit = bUnit_GetNameDisplay(usys, len - i - 1);
}
}
}
else {
grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit);
@ -1405,6 +1416,25 @@ static void draw_selected_name(
BLF_disable(font_id, BLF_SHADOW);
}
static void draw_grid_unit_name(
Scene *scene, RegionView3D *rv3d, View3D *v3d, int xoffset, int *yoffset)
{
if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
char numstr[32] = "";
const char *grid_unit;
ED_view3d_grid_view_scale(scene, v3d, rv3d, &grid_unit);
UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
if (v3d->grid != 1.0f) {
BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
}
*yoffset -= U.widget_unit;
BLF_draw_default_ascii(
xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr));
}
}
/**
* Information drawn on top of the solid plates and composed data
*/
@ -1466,19 +1496,10 @@ void view3d_draw_region_info(const bContext *C, ARegion *ar)
draw_selected_name(scene, view_layer, ob, xoffset, &yoffset);
}
#if 0 /* TODO */
if (grid_unit) { /* draw below the viewport name */
char numstr[32] = "";
UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
if (v3d->grid != 1.0f) {
BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
}
*yoffset -= U.widget_unit;
BLF_draw_default_ascii(xoffset, *yoffset, numstr[0] ? numstr : grid_unit, sizeof(numstr));
if (v3d->gridflag & (V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) {
/* draw below the viewport name */
draw_grid_unit_name(scene, rv3d, v3d, xoffset, &yoffset);
}
#endif
}
if ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) {