Cleanup: de-duplicate 3D-view depth calculation function

This commit is contained in:
2021-06-28 15:44:16 +10:00
parent 7efc87dcd2
commit 6f42e69b58
4 changed files with 17 additions and 26 deletions

View File

@@ -1079,17 +1079,6 @@ static void annotation_free_stroke(bGPDframe *gpf, bGPDstroke *gps)
BLI_freelinkN(&gpf->strokes, gps);
}
/**
* Which which point is in front (result should only be used for comparison).
*/
static float view3d_point_depth(const RegionView3D *rv3d, const float co[3])
{
if (rv3d->is_persp) {
return ED_view3d_calc_zfac(rv3d, co, NULL);
}
return -dot_v3v3(rv3d->viewinv[2], co);
}
/* only erase stroke points that are visible (3d view) */
static bool annotation_stroke_eraser_is_occluded(tGPsdata *p,
const bGPDspoint *pt,
@@ -1102,8 +1091,8 @@ static bool annotation_stroke_eraser_is_occluded(tGPsdata *p,
float mval_3d[3];
if (ED_view3d_autodist_simple(p->region, mval_i, mval_3d, 0, NULL)) {
const float depth_mval = view3d_point_depth(rv3d, mval_3d);
const float depth_pt = view3d_point_depth(rv3d, &pt->x);
const float depth_mval = ED_view3d_calc_depth_for_comparison(rv3d, mval_3d);
const float depth_pt = ED_view3d_calc_depth_for_comparison(rv3d, &pt->x);
if (depth_pt > depth_mval) {
return true;

View File

@@ -1319,17 +1319,6 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
/* --- 'Eraser' for 'Paint' Tool ------ */
/**
* Which which point is in front (result should only be used for comparison).
*/
static float view3d_point_depth(const RegionView3D *rv3d, const float co[3])
{
if (rv3d->is_persp) {
return ED_view3d_calc_zfac(rv3d, co, NULL);
}
return -dot_v3v3(rv3d->viewinv[2], co);
}
/* only erase stroke points that are visible */
static bool gpencil_stroke_eraser_is_occluded(
tGPsdata *p, bGPDlayer *gpl, bGPDspoint *pt, const int x, const int y)
@@ -1359,10 +1348,10 @@ static bool gpencil_stroke_eraser_is_occluded(
BKE_gpencil_layer_transform_matrix_get(p->depsgraph, obact, gpl, diff_mat);
if (ED_view3d_autodist_simple(p->region, mval_i, mval_3d, 0, NULL)) {
const float depth_mval = view3d_point_depth(rv3d, mval_3d);
const float depth_mval = ED_view3d_calc_depth_for_comparison(rv3d, mval_3d);
mul_v3_m4v3(fpt, diff_mat, &pt->x);
const float depth_pt = view3d_point_depth(rv3d, fpt);
const float depth_pt = ED_view3d_calc_depth_for_comparison(rv3d, fpt);
/* Checked occlusion flag. */
pt->flag |= GP_SPOINT_TEMP_TAG;

View File

@@ -366,6 +366,8 @@ float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3]);
float ED_view3d_pixel_size_no_ui_scale(const struct RegionView3D *rv3d, const float co[3]);
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip);
float ED_view3d_calc_depth_for_comparison(const struct RegionView3D *rv3d, const float co[3]);
bool ED_view3d_clip_segment(const struct RegionView3D *rv3d, float ray_start[3], float ray_end[3]);
bool ED_view3d_win_to_ray_clipped(struct Depsgraph *depsgraph,
const struct ARegion *region,

View File

@@ -330,6 +330,17 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f
return zfac;
}
/**
* Calculate a depth value from `co` (result should only be used for comparison).
*/
float ED_view3d_calc_depth_for_comparison(const RegionView3D *rv3d, const float co[3])
{
if (rv3d->is_persp) {
return ED_view3d_calc_zfac(rv3d, co, NULL);
}
return -dot_v3v3(rv3d->viewinv[2], co);
}
static void view3d_win_to_ray_segment(struct Depsgraph *depsgraph,
const ARegion *region,
const View3D *v3d,