Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_draw.c
| Show First 20 Lines • Show All 770 Lines • ▼ Show 20 Lines | float ED_scene_grid_scale(Scene *scene, const char **grid_unit) | ||||
| return 1.0f; | return 1.0f; | ||||
| } | } | ||||
| float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit) | float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit) | ||||
| { | { | ||||
| return v3d->grid * ED_scene_grid_scale(scene, grid_unit); | return v3d->grid * ED_scene_grid_scale(scene, grid_unit); | ||||
| } | } | ||||
| void ED_view3d_grid_steps(Scene *scene, View3D *v3d, RegionView3D *rv3d, float r_grid_steps[8]) | |||||
| { | |||||
| const void *usys; | |||||
| int i, len; | |||||
| bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len); | |||||
| float grid_scale = v3d->grid; | |||||
| if (usys) { | |||||
| if (rv3d->view == RV3D_VIEW_USER) { | |||||
| /* Skip steps */ | |||||
| len = bUnit_GetBaseUnit(usys) + 1; | |||||
| } | |||||
| grid_scale /= scene->unit.scale_length; | |||||
| for (i = 0; i < len; i++) { | |||||
| r_grid_steps[i] = (float)bUnit_GetScaler(usys, len - 1 - i) * grid_scale; | |||||
| } | |||||
| for (; i < 8; i++) { | |||||
| /* Fill last slots */ | |||||
| r_grid_steps[i] = 10.0 * r_grid_steps[i - 1]; | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (rv3d->view != RV3D_VIEW_USER) { | |||||
| /* Allow 3 more subdivisions. */ | |||||
| grid_scale /= powf(v3d->gridsubdiv, 3); | |||||
| } | |||||
| int subdiv = 1; | |||||
| for (i = 0;; i++) { | |||||
| r_grid_steps[i] = grid_scale * subdiv; | |||||
| if (i == ARRAY_SIZE(r_grid_steps) - 1) { | |||||
| break; | |||||
| } | |||||
| subdiv *= v3d->gridsubdiv; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* Simulates the grid scale that is actually viewed. | /* Simulates the grid scale that is actually viewed. | ||||
| * The actual code is seen in `object_grid_frag.glsl` (see `grid_res`). | * The actual code is seen in `object_grid_frag.glsl`. | ||||
| * Currently the simulation is only done when RV3D_VIEW_IS_AXIS. */ | * Currently the simulation is only done when RV3D_VIEW_IS_AXIS. */ | ||||
| float ED_view3d_grid_view_scale( | float ED_view3d_grid_view_scale( | ||||
| Scene *scene, View3D *v3d, RegionView3D *rv3d, const char **grid_unit) | Scene *scene, View3D *v3d, RegionView3D *rv3d, const char **grid_unit) | ||||
| { | { | ||||
| float grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit); | float grid_scale; | ||||
| if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) { | if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) { | ||||
| /* Decrease the distance between grid snap points depending on zoom. */ | /* 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)); | |||||
| /* 1.3f is a visually chosen offset for the | |||||
| * subdivision to match the visible grid. */ | |||||
| lvl -= 1.3f; | |||||
| CLAMP_MIN(lvl, 0.0f); | |||||
| grid_scale *= pow(grid_subdiv, (int)lvl); | /* `2.6` was a value obtained by trial and error */ | ||||
| float min_dist = rv3d->dist / (v3d->lens * 2.6); | |||||
| float grid_steps[8]; | |||||
| ED_view3d_grid_steps(scene, v3d, rv3d, grid_steps); | |||||
| for (int i = 0; i < ARRAY_SIZE(grid_steps); i++) { | |||||
| grid_scale = grid_steps[i]; | |||||
| if (grid_scale > min_dist) { | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| else { | |||||
| grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit); | |||||
| } | |||||
| return grid_scale; | return grid_scale; | ||||
| } | } | ||||
| static void draw_view_axis(RegionView3D *rv3d, const rcti *rect) | static void draw_view_axis(RegionView3D *rv3d, const rcti *rect) | ||||
| { | { | ||||
| const float k = U.rvisize * U.pixelsize; /* axis size */ | const float k = U.rvisize * U.pixelsize; /* axis size */ | ||||
| /* axis alpha offset (rvibright has range 0-10) */ | /* axis alpha offset (rvibright has range 0-10) */ | ||||
| ▲ Show 20 Lines • Show All 937 Lines • Show Last 20 Lines | |||||