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.
This commit is contained in:
parent
50782df425
commit
44c76e4ce3
Notes:
blender-bot
2023-02-14 05:41:57 +01:00
Referenced by commite4990a5658
, Fix wrong logic used in 'ED_view3d_depth_read_cached' Referenced by commitfa2c00ae91
, Fix wrong logic used in 'ED_view3d_depth_read_cached'
|
@ -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;
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue