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
This commit is contained in:
Hans Goudey 2022-01-28 22:40:13 -06:00
parent 0b2864382a
commit 90a23dec46
Notes: blender-bot 2023-02-14 06:00:46 +01:00
Referenced by commit 6f5d172d6c, Fix error tagging vertices as loose in the screw modifier
Referenced by issue #93602, Struct of Arrays Refactor for Mesh Vertices
6 changed files with 49 additions and 34 deletions

View File

@ -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,

View File

@ -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) {

View File

@ -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;

View File

@ -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) {

View File

@ -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), */

View File

@ -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(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
mv_new = mvert_new;
mv_orig = mvert_orig;
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(totvert, __func__);
/* Copy the first set of edges */
med_orig = medge_orig;
med_new = medge_new;
@ -447,10 +452,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
med_new->v2 = med_orig->v2;
med_new->crease = med_orig->crease;
med_new->flag = med_orig->flag & ~ME_LOOSEEDGE;
/* Tag mvert as not loose.
* NOTE: ME_VERT_TMP_TAG is given to be cleared by BKE_mesh_new_nomain_from_template. */
mvert_new[med_orig->v1].flag |= ME_VERT_TMP_TAG;
mvert_new[med_orig->v2].flag |= ME_VERT_TMP_TAG;
/* Tag mvert as not loose. */
BLI_BITMAP_ENABLE(vert_tag, med_orig->v1);
BLI_BITMAP_ENABLE(vert_tag, med_orig->v1);
}
/* build polygon -> edge map */
@ -910,7 +915,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
med_new->v1 = varray_stride + j;
med_new->v2 = med_new->v1 - totvert;
med_new->flag = ME_EDGEDRAW | ME_EDGERENDER;
if ((mv_new_base->flag & ME_VERT_TMP_TAG) == 0) {
if (!BLI_BITMAP_TEST(vert_tag, j)) {
med_new->flag |= ME_LOOSEEDGE;
}
med_new++;
@ -931,7 +936,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
med_new->v1 = i;
med_new->v2 = varray_stride + i;
med_new->flag = ME_EDGEDRAW | ME_EDGERENDER;
if ((mvert_new[i].flag & ME_VERT_TMP_TAG) == 0) {
if (!BLI_BITMAP_TEST(vert_tag, i)) {
med_new->flag |= ME_LOOSEEDGE;
}
med_new++;
@ -1119,6 +1124,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
#endif
MEM_freeN(vert_tag);
if (edge_poly_map) {
MEM_freeN(edge_poly_map);
}