[Bf-blender-cvs] [90a23dec465] master: Cleanup: Remove mesh vertex "temp tag" flag

Hans Goudey noreply at git.blender.org
Sat Jan 29 05:40:24 CET 2022


Commit: 90a23dec4650d63a836cb9e9969aab4d0da4ba2f
Author: Hans Goudey
Date:   Fri Jan 28 22:40:13 2022 -0600
Branches: master
https://developer.blender.org/rB90a23dec4650d63a836cb9e9969aab4d0da4ba2f

Cleanup: Remove mesh vertex "temp tag" flag

As part of the project of converting `MVert` into `float3`
(more details in T93602), this is an easy step, since it
is only locally used runtime data. In the six places it was
used, the flag was replaced by a local bitmap.

By itself this change has no benefits other than making some
code slightly simpler. It only really matters when the other
flags are removed and it can be removed from `MVert`
along with the bevel weight.

Differential Revision: https://developer.blender.org/D13878

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

M	source/blender/blenkernel/intern/crazyspace.c
M	source/blender/blenkernel/intern/mesh_merge.c
M	source/blender/blenkernel/intern/mesh_validate.c
M	source/blender/editors/object/object_vgroup.c
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/modifiers/intern/MOD_screw.c

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

diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c
index 573595b6f90..0bf83ed5036 100644
--- a/source/blender/blenkernel/intern/crazyspace.c
+++ b/source/blender/blenkernel/intern/crazyspace.c
@@ -194,13 +194,10 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me,
                                    float (*mappedcos)[3],
                                    float (*quats)[4])
 {
-  MVert *mvert = me->mvert;
-  for (int i = 0; i < me->totvert; i++, mvert++) {
-    mvert->flag &= ~ME_VERT_TMP_TAG;
-  }
+  BLI_bitmap *vert_tag = BLI_BITMAP_NEW(me->totvert, __func__);
 
   /* first store two sets of tangent vectors in vertices, we derive it just from the face-edges */
-  mvert = me->mvert;
+  MVert *mvert = me->mvert;
   MPoly *mp = me->mpoly;
   MLoop *mloop = me->mloop;
 
@@ -210,7 +207,7 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me,
     MLoop *ml_prev = &ml_next[mp->totloop - 2];
 
     for (int j = 0; j < mp->totloop; j++) {
-      if ((mvert[ml_curr->v].flag & ME_VERT_TMP_TAG) == 0) {
+      if (!BLI_BITMAP_TEST(vert_tag, ml_curr->v)) {
         const float *co_prev, *co_curr, *co_next; /* orig */
         const float *vd_prev, *vd_curr, *vd_next; /* deform */
 
@@ -233,7 +230,7 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me,
         set_crazy_vertex_quat(
             quats[ml_curr->v], co_curr, co_next, co_prev, vd_curr, vd_next, vd_prev);
 
-        mvert[ml_curr->v].flag |= ME_VERT_TMP_TAG;
+        BLI_BITMAP_ENABLE(vert_tag, ml_curr->v);
       }
 
       ml_prev = ml_curr;
@@ -241,6 +238,8 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me,
       ml_next++;
     }
   }
+
+  MEM_freeN(vert_tag);
 }
 
 int BKE_crazyspace_get_first_deform_matrices_editbmesh(struct Depsgraph *depsgraph,
diff --git a/source/blender/blenkernel/intern/mesh_merge.c b/source/blender/blenkernel/intern/mesh_merge.c
index 134a1344f83..3c01d5a4a50 100644
--- a/source/blender/blenkernel/intern/mesh_merge.c
+++ b/source/blender/blenkernel/intern/mesh_merge.c
@@ -27,6 +27,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
+#include "BLI_bitmap.h"
 #include "BLI_edgehash.h"
 #include "BLI_ghash.h"
 #include "BLI_utildefines.h"
@@ -351,6 +352,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
         &poly_map, &poly_map_mem, mesh->mpoly, mesh->mloop, totvert, totpoly, totloop);
   } /* done preparing for fast poly compare */
 
+  BLI_bitmap *vert_tag = BLI_BITMAP_NEW(mesh->totvert, __func__);
+
   mp = mesh->mpoly;
   mv = mesh->mvert;
   for (i = 0; i < totpoly; i++, mp++) {
@@ -365,11 +368,11 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
       if (vtargetmap[ml->v] == -1) {
         all_vertices_merged = false;
         /* This will be used to check for poly using several time the same vert. */
-        mv[ml->v].flag &= ~ME_VERT_TMP_TAG;
+        BLI_BITMAP_DISABLE(vert_tag, ml->v);
       }
       else {
         /* This will be used to check for poly using several time the same vert. */
-        mv[vtargetmap[ml->v]].flag &= ~ME_VERT_TMP_TAG;
+        BLI_BITMAP_DISABLE(vert_tag, vtargetmap[ml->v]);
       }
     }
 
@@ -457,8 +460,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
 #endif
       /* A loop is only valid if its matching edge is,
        * and it's not reusing a vertex already used by this poly. */
-      if (LIKELY((newe[ml->e] != -1) && ((mv[mlv].flag & ME_VERT_TMP_TAG) == 0))) {
-        mv[mlv].flag |= ME_VERT_TMP_TAG;
+      if (LIKELY((newe[ml->e] != -1) && !BLI_BITMAP_TEST(vert_tag, mlv))) {
+        BLI_BITMAP_ENABLE(vert_tag, mlv);
 
         if (UNLIKELY(last_valid_ml != NULL && need_edge_from_last_valid_ml)) {
           /* We need to create a new edge between last valid loop and this one! */
@@ -644,6 +647,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh,
   MEM_freeN(oldl);
   MEM_freeN(oldp);
 
+  MEM_freeN(vert_tag);
+
   BLI_edgehash_free(ehash, NULL);
 
   if (poly_map != NULL) {
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c
index 005c916b4e0..a5ba2767301 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.c
@@ -28,6 +28,7 @@
 
 #include "CLG_log.h"
 
+#include "BLI_bitmap.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
@@ -560,6 +561,8 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
    * so be sure to leave at most one poly per loop!
    */
   {
+    BLI_bitmap *vert_tag = BLI_BITMAP_NEW(mesh->totvert, __func__);
+
     SortPoly *sort_polys = MEM_callocN(sizeof(SortPoly) * totpoly, "mesh validate's sort_polys");
     SortPoly *prev_sp, *sp = sort_polys;
     int prev_end;
@@ -608,7 +611,7 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
          * so we have to ensure here all verts of current poly are cleared. */
         for (j = 0, ml = &mloops[sp->loopstart]; j < mp->totloop; j++, ml++) {
           if (ml->v < totvert) {
-            mverts[ml->v].flag &= ~ME_VERT_TMP_TAG;
+            BLI_BITMAP_DISABLE(vert_tag, ml->v);
           }
         }
 
@@ -619,12 +622,12 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
             PRINT_ERR("\tLoop %u has invalid vert reference (%u)", sp->loopstart + j, ml->v);
             sp->invalid = true;
           }
-          else if (mverts[ml->v].flag & ME_VERT_TMP_TAG) {
+          else if (BLI_BITMAP_TEST(vert_tag, ml->v)) {
             PRINT_ERR("\tPoly %u has duplicated vert reference at corner (%u)", i, j);
             sp->invalid = true;
           }
           else {
-            mverts[ml->v].flag |= ME_VERT_TMP_TAG;
+            BLI_BITMAP_ENABLE(vert_tag, ml->v);
           }
           *v = ml->v;
         }
@@ -698,6 +701,8 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
       }
     }
 
+    MEM_freeN(vert_tag);
+
     /* Second check pass, testing polys using the same verts. */
     qsort(sort_polys, totpoly, sizeof(SortPoly), search_poly_cmp);
     sp = prev_sp = sort_polys;
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index 3e74aaeeb10..e21e815b56f 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -39,6 +39,7 @@
 
 #include "BLI_alloca.h"
 #include "BLI_array.h"
+#include "BLI_bitmap.h"
 #include "BLI_blenlib.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
@@ -2464,17 +2465,14 @@ void ED_vgroup_mirror(Object *ob,
         sel = sel_mirr = true;
       }
 
-      /* tag verts we have used */
-      for (vidx = 0, mv = me->mvert; vidx < me->totvert; vidx++, mv++) {
-        mv->flag &= ~ME_VERT_TMP_TAG;
-      }
+      BLI_bitmap *vert_tag = BLI_BITMAP_NEW(me->totvert, __func__);
 
       for (vidx = 0, mv = me->mvert; vidx < me->totvert; vidx++, mv++) {
-        if ((mv->flag & ME_VERT_TMP_TAG) == 0) {
+        if (!BLI_BITMAP_TEST(vert_tag, vidx)) {
           if ((vidx_mirr = mesh_get_x_mirror_vert(ob, NULL, vidx, use_topology)) != -1) {
             if (vidx != vidx_mirr) {
               mv_mirr = &me->mvert[vidx_mirr];
-              if ((mv_mirr->flag & ME_VERT_TMP_TAG) == 0) {
+              if (!BLI_BITMAP_TEST(vert_tag, vidx_mirr)) {
 
                 if (use_vert_sel) {
                   sel = mv->flag & SELECT;
@@ -2489,8 +2487,8 @@ void ED_vgroup_mirror(Object *ob,
                   totmirr++;
                 }
 
-                mv->flag |= ME_VERT_TMP_TAG;
-                mv_mirr->flag |= ME_VERT_TMP_TAG;
+                BLI_BITMAP_ENABLE(vert_tag, vidx);
+                BLI_BITMAP_ENABLE(vert_tag, vidx_mirr);
               }
             }
           }
@@ -2499,6 +2497,8 @@ void ED_vgroup_mirror(Object *ob,
           }
         }
       }
+
+      MEM_freeN(vert_tag);
     }
   }
   else if (ob->type == OB_LATTICE) {
diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h
index 22c523901c0..b0276d010a4 100644
--- a/source/blender/makesdna/DNA_meshdata_types.h
+++ b/source/blender/makesdna/DNA_meshdata_types.h
@@ -48,7 +48,6 @@ typedef struct MVert {
 /** #MVert.flag */
 enum {
   /*  SELECT = (1 << 0), */
-  ME_VERT_TMP_TAG = (1 << 2),
   ME_HIDE = (1 << 4),
   ME_VERT_FACEDOT = (1 << 5),
   /*  ME_VERT_MERGED = (1 << 6), */
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index f5db3bced7a..682dccd268d 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -27,6 +27,7 @@
 #include "BLI_utildefines.h"
 
 #include "BLI_alloca.h"
+#include "BLI_bitmap.h"
 #include "BLI_math.h"
 
 #include "BLT_translation.h"
@@ -134,6 +135,8 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
                                          const float axis_offset[3],
                                          const float merge_threshold)
 {
+  BLI_bitmap *vert_tag = BLI_BITMAP_NEW(totvert, __func__);
+
   const float merge_threshold_sq = square_f(merge_threshold);
   const bool use_offset = axis_offset != NULL;
   uint tot_doubles = 0;
@@ -150,13 +153,10 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
     }
     const float dist_sq = len_squared_v3v3(axis_co, mvert_new[i].co);
     if (dist_sq <= merge_threshold_sq) {
-      mvert_new[i].flag |= ME_VERT_TMP_TAG;
+      BLI_BITMAP_ENABLE(vert_tag, i);
       tot_doubles += 1;
       copy_v3_v3(mvert_new[i].co, axis_co);
     }
-    else {
-      mvert_new[i].flag &= ~ME_VERT_TMP_TAG & 0xFF;
-    }
   }
 
   if (tot_doubles != 0) {
@@ -166,7 +166,7 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
 
     uint tot_doubles_left = tot_doubles;
     for (uint i = 0; i < totvert; i += 1) {
-      if (mvert_new[i].flag & ME_VERT_TMP_TAG) {
+      if (BLI_BITMAP_TEST(vert_tag, i)) {
         int *doubles_map = &full_doubles_map[totvert + i];
         for (uint step = 1; step < step_tot; step += 1) {
           *doubles_map = (int)i;
@@ -184,6 +184,9 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
                                   MESH_MERGE_VERTS_DUMP_IF_MAPPED);
     MEM_freeN(full_doubles_map);
   }
+
+  MEM_freeN(vert_tag);
+
   return result;
 }
 
@@ -439,6 +442,8 @@ static Mesh *modifyMesh(Modifier

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list