Cleanup: remove 2D region-relative coordinates from Base

Historically, caching these values may have had some advantages,
simplifying drawing object centers and selecting by object center.

Now the only uses of these values would calculate the projection
before use, so there is no reason to store run-time projection in DNA.

This also quiets a `-Wstring-overflow` warning.
This commit is contained in:
Campbell Barton
2022-10-03 10:50:20 +11:00
parent ea2c41c730
commit d3ba8826b0
4 changed files with 17 additions and 12 deletions

View File

@@ -457,7 +457,9 @@ void ED_view3d_project_float_v3_m4(const struct ARegion *region,
float r_co[3],
const float mat[4][4]);
eV3DProjStatus ED_view3d_project_base(const struct ARegion *region, struct Base *base);
eV3DProjStatus ED_view3d_project_base(const struct ARegion *region,
struct Base *base,
short r_co[2]);
/* *** short *** */
eV3DProjStatus ED_view3d_project_short_ex(const struct ARegion *region,

View File

@@ -75,14 +75,16 @@ void ED_view3d_project_float_v3_m4(const ARegion *region,
/* Clipping Projection Functions
* ***************************** */
eV3DProjStatus ED_view3d_project_base(const struct ARegion *region, struct Base *base)
eV3DProjStatus ED_view3d_project_base(const struct ARegion *region,
struct Base *base,
short r_co[2])
{
eV3DProjStatus ret = ED_view3d_project_short_global(
region, base->object->obmat[3], &base->sx, V3D_PROJ_TEST_CLIP_DEFAULT);
region, base->object->obmat[3], r_co, V3D_PROJ_TEST_CLIP_DEFAULT);
if (ret != V3D_PROJ_RET_OK) {
base->sx = IS_CLIPPED;
base->sy = 0;
r_co[0] = IS_CLIPPED;
r_co[1] = 0;
}
return ret;

View File

@@ -574,10 +574,11 @@ static bool do_lasso_select_objects(ViewContext *vc,
BKE_view_layer_synced_ensure(vc->scene, vc->view_layer);
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(vc->view_layer)) {
if (BASE_SELECTABLE(v3d, base)) { /* Use this to avoid unnecessary lasso look-ups. */
short region_co[2];
const bool is_select = base->flag & BASE_SELECTED;
const bool is_inside = ((ED_view3d_project_base(vc->region, base) == V3D_PROJ_RET_OK) &&
BLI_lasso_is_point_inside(
mcoords, mcoords_len, base->sx, base->sy, IS_CLIPPED));
const bool is_inside =
(ED_view3d_project_base(vc->region, base, region_co) == V3D_PROJ_RET_OK) &&
BLI_lasso_is_point_inside(mcoords, mcoords_len, region_co[0], region_co[1], IS_CLIPPED);
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
if (sel_op_result != -1) {
ED_object_base_select(base, sel_op_result ? BA_SELECT : BA_DESELECT);
@@ -1608,8 +1609,9 @@ static bool object_mouse_select_menu(bContext *C,
}
else {
const int dist = 15 * U.pixelsize;
if (ED_view3d_project_base(vc->region, base) == V3D_PROJ_RET_OK) {
const int delta_px[2] = {base->sx - mval[0], base->sy - mval[1]};
short region_co[2];
if (ED_view3d_project_base(vc->region, base, region_co) == V3D_PROJ_RET_OK) {
const int delta_px[2] = {region_co[0] - mval[0], region_co[1] - mval[1]};
if (len_manhattan_v2_int(delta_px) < dist) {
ok = true;
}

View File

@@ -80,8 +80,7 @@ typedef struct Base {
short flag;
unsigned short local_view_bits;
short sx, sy;
char _pad1[6];
char _pad1[10];
struct Object *object;
unsigned int lay DNA_DEPRECATED;
int flag_legacy;