[Bf-blender-cvs] [86352364a60] master: 3D View: use float for ED_view3d_project_base & minor changes
Campbell Barton
noreply at git.blender.org
Thu Oct 6 03:50:47 CEST 2022
Commit: 86352364a60f62ef338655085a4a227e3cd01c5b
Author: Campbell Barton
Date: Thu Oct 6 12:26:48 2022 +1100
Branches: master
https://developer.blender.org/rB86352364a60f62ef338655085a4a227e3cd01c5b
3D View: use float for ED_view3d_project_base & minor changes
Using 'short' was historic (as the value was stored in the Base).
Prefer floats which allow sub-pixel distances to be differentiated.
Also remove IS_CLIPPED assignment as this only made sense when the
values were stored in the Base, without any other ways to check
if projection failed.
===================================================================
M source/blender/editors/include/ED_view3d.h
M source/blender/editors/space_view3d/view3d_project.c
M source/blender/editors/space_view3d/view3d_select.cc
===================================================================
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 67ace0a7a89..52aa5f56fee 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -459,7 +459,7 @@ void ED_view3d_project_float_v3_m4(const struct ARegion *region,
eV3DProjStatus ED_view3d_project_base(const struct ARegion *region,
struct Base *base,
- short r_co[2]);
+ float r_co[2]);
/* *** short *** */
eV3DProjStatus ED_view3d_project_short_ex(const struct ARegion *region,
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c
index 498f86e36fd..c5f951bd64c 100644
--- a/source/blender/editors/space_view3d/view3d_project.c
+++ b/source/blender/editors/space_view3d/view3d_project.c
@@ -77,14 +77,16 @@ void ED_view3d_project_float_v3_m4(const ARegion *region,
eV3DProjStatus ED_view3d_project_base(const struct ARegion *region,
struct Base *base,
- short r_co[2])
+ float r_co[2])
{
- eV3DProjStatus ret = ED_view3d_project_short_global(
+ eV3DProjStatus ret = ED_view3d_project_float_global(
region, base->object->obmat[3], r_co, V3D_PROJ_TEST_CLIP_DEFAULT);
+ /* Prevent uninitialized values when projection fails,
+ * although the callers should check the return value. */
if (ret != V3D_PROJ_RET_OK) {
- r_co[0] = IS_CLIPPED;
- r_co[1] = 0;
+ r_co[0] = -1.0;
+ r_co[1] = -1.0;
}
return ret;
diff --git a/source/blender/editors/space_view3d/view3d_select.cc b/source/blender/editors/space_view3d/view3d_select.cc
index 5e9720d119e..b14536213b7 100644
--- a/source/blender/editors/space_view3d/view3d_select.cc
+++ b/source/blender/editors/space_view3d/view3d_select.cc
@@ -574,11 +574,16 @@ 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];
+ float region_co[2];
const bool is_select = base->flag & BASE_SELECTED;
- 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 bool is_inside = (ED_view3d_project_base(vc->region, base, region_co) ==
+ V3D_PROJ_RET_OK) &&
+ BLI_lasso_is_point_inside(mcoords,
+ mcoords_len,
+ int(region_co[0]),
+ int(region_co[1]),
+ /* Dummy value. */
+ INT_MAX);
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);
@@ -1589,6 +1594,10 @@ static bool object_mouse_select_menu(bContext *C,
const SelectPick_Params *params,
Base **r_basact)
{
+
+ const float mval_fl[2] = {float(mval[0]), float(mval[1])};
+ /* Distance from object center to use for selection. */
+ const float dist_threshold = 15 * U.pixelsize;
int base_count = 0;
bool ok;
LinkNodePair linklist = {nullptr, nullptr};
@@ -1608,11 +1617,9 @@ static bool object_mouse_select_menu(bContext *C,
}
}
else {
- const int dist = 15 * U.pixelsize;
- short region_co[2];
+ float 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) {
+ if (len_manhattan_v2v2(mval_fl, region_co) < dist_threshold) {
ok = true;
}
}
More information about the Bf-blender-cvs
mailing list