[Bf-blender-cvs] [d3ba8826b0e] master: Cleanup: remove 2D region-relative coordinates from Base

Campbell Barton noreply at git.blender.org
Mon Oct 3 02:20:32 CEST 2022


Commit: d3ba8826b0e96c8c5293ba4a2c5d1bd42a8c6ccb
Author: Campbell Barton
Date:   Mon Oct 3 10:50:20 2022 +1100
Branches: master
https://developer.blender.org/rBd3ba8826b0e96c8c5293ba4a2c5d1bd42a8c6ccb

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.

===================================================================

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
M	source/blender/makesdna/DNA_layer_types.h

===================================================================

diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 9eceb5260ed..67ace0a7a89 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -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,
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c
index 2a8b50fa95f..498f86e36fd 100644
--- a/source/blender/editors/space_view3d/view3d_project.c
+++ b/source/blender/editors/space_view3d/view3d_project.c
@@ -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;
diff --git a/source/blender/editors/space_view3d/view3d_select.cc b/source/blender/editors/space_view3d/view3d_select.cc
index 687c2b7d591..0e266f5eae2 100644
--- a/source/blender/editors/space_view3d/view3d_select.cc
+++ b/source/blender/editors/space_view3d/view3d_select.cc
@@ -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;
         }
diff --git a/source/blender/makesdna/DNA_layer_types.h b/source/blender/makesdna/DNA_layer_types.h
index e011e1c491e..63bc379c27a 100644
--- a/source/blender/makesdna/DNA_layer_types.h
+++ b/source/blender/makesdna/DNA_layer_types.h
@@ -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;



More information about the Bf-blender-cvs mailing list