diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2021-04-05 16:48:28 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2021-04-05 16:48:37 +0300 |
commit | 44c76e4ce31052501706d9d10850f3d41a5b3fcc (patch) | |
tree | 76334c81e044c0604aee836ad99b2552b91f14a1 | |
parent | 50782df42586a5a038cad11530714371edaa5cd4 (diff) |
3D View Utils: Add 'margin' parameter to 'ED_view3d_depth_read_cached'
Matches the alternative function ED_view3d_autodist_depth, but is more
efficient since it uses the cache.
No functional changes.
-rw-r--r-- | source/blender/editors/curve/editcurve_paint.c | 4 | ||||
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 5 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.c | 14 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_utils.c | 44 |
4 files changed, 53 insertions, 14 deletions
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c index 6342076df34..8842274e017 100644 --- a/source/blender/editors/curve/editcurve_paint.c +++ b/source/blender/editors/curve/editcurve_paint.c @@ -206,7 +206,9 @@ static bool stroke_elem_project(const struct CurveDrawData *cdd, else { const ViewDepths *depths = rv3d->depths; if (depths && ((uint)mval_i[0] < depths->w) && ((uint)mval_i[1] < depths->h)) { - const double depth = (double)ED_view3d_depth_read_cached(&cdd->vc, mval_i); + float depth_fl = 1.0f; + ED_view3d_depth_read_cached(depths, mval_i, 0, &depth_fl); + const double depth = (double)depth_fl; if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) { if (ED_view3d_depth_unproject(region, mval_i, depth, r_location_world)) { is_location_world_set = true; diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index d00d03abae7..499f28beb60 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -155,7 +155,10 @@ void ED_view3d_depth_override(struct Depsgraph *depsgraph, struct Object *obact, eV3DDepthOverrideMode mode, bool update_cache); -float ED_view3d_depth_read_cached(const struct ViewContext *vc, const int mval[2]); +bool ED_view3d_depth_read_cached(const ViewDepths *vd, + const int mval[2], + int margin, + float *r_depth); bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, const int mval[2], float r_normal[3]); diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 1d7cf61bc3a..a87b5054efa 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -1865,28 +1865,30 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const if (event->type == MOUSEMOVE || is_translate_init) { const ViewDepths *depths = xfd->vc.rv3d->depths; if (depths && ((uint)event->mval[0] < depths->w) && ((uint)event->mval[1] < depths->h)) { - double depth = (double)ED_view3d_depth_read_cached(&xfd->vc, event->mval); + float depth_fl = 1.0f; + ED_view3d_depth_read_cached(depths, event->mval, 0, &depth_fl); float location_world[3]; - if (depth == 1.0f) { + if (depth_fl == 1.0f) { if (xfd->prev.is_depth_valid) { - depth = (double)xfd->prev.depth; + depth_fl = xfd->prev.depth; } } #ifdef USE_FAKE_DEPTH_INIT /* First time only. */ - if (depth == 1.0f) { + if (depth_fl == 1.0f) { if (xfd->prev.is_depth_valid == false) { object_transform_axis_target_calc_depth_init(xfd, event->mval); if (xfd->prev.is_depth_valid) { - depth = (double)xfd->prev.depth; + depth_fl = xfd->prev.depth; } } } #endif + double depth = (double)depth_fl; if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) { - xfd->prev.depth = depth; + xfd->prev.depth = depth_fl; xfd->prev.is_depth_valid = true; if (ED_view3d_depth_unproject(region, event->mval, depth, location_world)) { if (is_translate) { diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index 3b4834045f8..fde98c18803 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -36,6 +36,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_array_utils.h" #include "BLI_bitmap_draw_2d.h" #include "BLI_blenlib.h" #include "BLI_math.h" @@ -1629,19 +1630,48 @@ bool ED_view3d_camera_to_view_selected(struct Main *bmain, /** \name Depth Buffer Utilities * \{ */ -float ED_view3d_depth_read_cached(const ViewContext *vc, const int mval[2]) +static bool depth_read_test_fn(const void *value, void *userdata) { - ViewDepths *vd = vc->rv3d->depths; + float *r_depth = userdata; + float depth = *(float *)value; + if (depth < *r_depth) { + *r_depth = depth; + } + return false; +} + +bool ED_view3d_depth_read_cached(const ViewDepths *vd, + const int mval[2], + int margin, + float *r_depth) +{ + if (!vd || !vd->depths) { + return false; + } int x = mval[0]; int y = mval[1]; + if (x < 0 || y < 0 || x >= vd->w || y >= vd->h) { + return false; + } - if (vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h) { - return vd->depths[y * vd->w + x]; + float depth = 1.0f; + if (margin) { + /* TODO: No need to go spiral. */ + int shape[2] = {vd->w, vd->h}; + BLI_array_iter_spiral_square(vd->depths, shape, mval, depth_read_test_fn, &depth); + } + else { + depth = vd->depths[y * vd->w + x]; } BLI_assert(1.0 <= vd->depth_range[1]); - return 1.0f; + if (depth != 1.0f) { + *r_depth = depth; + return true; + } + + return false; } bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, @@ -1662,7 +1692,9 @@ bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, for (int y = 0; y < 2; y++) { const int mval_ofs[2] = {mval[0] + (x - 1), mval[1] + (y - 1)}; - const double depth = (double)ED_view3d_depth_read_cached(vc, mval_ofs); + float depth_fl = 1.0f; + ED_view3d_depth_read_cached(depths, mval_ofs, 0, &depth_fl); + const double depth = (double)depth_fl; if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) { if (ED_view3d_depth_unproject(region, mval_ofs, depth, coords[i])) { depths_valid[i] = true; |