Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_utils.c
| Show First 20 Lines • Show All 1,018 Lines • ▼ Show 20 Lines | static float view_autodist_depth_margin(ARegion *region, const int mval[2], int margin) | ||||
| view3d_update_depths_rect(region, &depth_temp, &rect); | view3d_update_depths_rect(region, &depth_temp, &rect); | ||||
| float depth_close = view3d_depth_near(&depth_temp); | float depth_close = view3d_depth_near(&depth_temp); | ||||
| MEM_SAFE_FREE(depth_temp.depths); | MEM_SAFE_FREE(depth_temp.depths); | ||||
| return depth_close; | return depth_close; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the world-space 3d location from a screen-space 2d point. | * Get the world-space 3d location from a screen-space 2d point. | ||||
| * TODO: Implement #alphaoverride. We don't want to zoom into billboards. | |||||
| * | * | ||||
| * \param mval: Input screen-space pixel location. | * \param mval: Input screen-space pixel location. | ||||
| * \param mouse_worldloc: Output world-space location. | * \param mouse_worldloc: Output world-space location. | ||||
| * \param fallback_depth_pt: Use this points depth when no depth can be found. | * \param fallback_depth_pt: Use this points depth when no depth can be found. | ||||
| */ | */ | ||||
| bool ED_view3d_autodist(Depsgraph *depsgraph, | bool ED_view3d_autodist(Depsgraph *depsgraph, | ||||
| ARegion *region, | ARegion *region, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| const int mval[2], | const int mval[2], | ||||
| float mouse_worldloc[3], | float mouse_worldloc[3], | ||||
| const bool alphaoverride, | const bool UNUSED(alphaoverride), | ||||
| const float fallback_depth_pt[3]) | const float fallback_depth_pt[3]) | ||||
| { | { | ||||
| float depth_close; | float depth_close; | ||||
| int margin_arr[] = {0, 2, 4}; | int margin_arr[] = {0, 2, 4}; | ||||
| bool depth_ok = false; | bool depth_ok = false; | ||||
| /* Get Z Depths, needed for perspective, nice for ortho */ | /* Get Z Depths, needed for perspective, nice for ortho */ | ||||
| ED_view3d_draw_depth(depsgraph, region, v3d, alphaoverride); | ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false); | ||||
| /* Attempt with low margin's first */ | /* Attempt with low margin's first */ | ||||
| int i = 0; | int i = 0; | ||||
| do { | do { | ||||
| depth_close = view_autodist_depth_margin(region, mval, margin_arr[i++] * U.pixelsize); | depth_close = view_autodist_depth_margin(region, mval, margin_arr[i++] * U.pixelsize); | ||||
| depth_ok = (depth_close != FLT_MAX); | depth_ok = (depth_close != FLT_MAX); | ||||
| } while ((depth_ok == false) && (i < ARRAY_SIZE(margin_arr))); | } while ((depth_ok == false) && (i < ARRAY_SIZE(margin_arr))); | ||||
| if (depth_ok) { | if (depth_ok) { | ||||
| float centx = (float)mval[0] + 0.5f; | float centx = (float)mval[0] + 0.5f; | ||||
| float centy = (float)mval[1] + 0.5f; | float centy = (float)mval[1] + 0.5f; | ||||
| if (ED_view3d_unproject(region, centx, centy, depth_close, mouse_worldloc)) { | if (ED_view3d_unproject(region, centx, centy, depth_close, mouse_worldloc)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| if (fallback_depth_pt) { | if (fallback_depth_pt) { | ||||
| ED_view3d_win_to_3d_int(v3d, region, fallback_depth_pt, mval, mouse_worldloc); | ED_view3d_win_to_3d_int(v3d, region, fallback_depth_pt, mval, mouse_worldloc); | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void ED_view3d_autodist_init(Depsgraph *depsgraph, ARegion *region, View3D *v3d, int mode) | /* no 4x4 sampling, run #ED_view3d_depth_override first */ | ||||
| { | |||||
| /* Get Z Depths, needed for perspective, nice for ortho */ | |||||
| switch (mode) { | |||||
| case 0: | |||||
| ED_view3d_draw_depth(depsgraph, region, v3d, true); | |||||
| break; | |||||
| case 1: { | |||||
| Scene *scene = DEG_get_evaluated_scene(depsgraph); | |||||
| ED_view3d_draw_depth_gpencil(depsgraph, scene, region, v3d); | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* no 4x4 sampling, run #ED_view3d_autodist_init first */ | |||||
| bool ED_view3d_autodist_simple(ARegion *region, | bool ED_view3d_autodist_simple(ARegion *region, | ||||
| const int mval[2], | const int mval[2], | ||||
| float mouse_worldloc[3], | float mouse_worldloc[3], | ||||
| int margin, | int margin, | ||||
| const float *force_depth) | const float *force_depth) | ||||
| { | { | ||||
| /* Get Z Depths, needed for perspective, nice for ortho */ | /* Get Z Depths, needed for perspective, nice for ortho */ | ||||
| float depth; | float depth; | ||||
| ▲ Show 20 Lines • Show All 640 Lines • Show Last 20 Lines | |||||