diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_mesh.h | 5 | ||||
-rw-r--r-- | source/blender/editors/mesh/editface.cc | 179 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_undo.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.cc | 23 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 17 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_hide.c | 15 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 12 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_dyntopo.c | 5 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_undo.c | 16 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_iterators.c | 20 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_select.c | 22 |
11 files changed, 215 insertions, 103 deletions
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 9d3fd5af47f..71ddffca8a9 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -390,7 +390,10 @@ void ED_keymap_mesh(struct wmKeyConfig *keyconf); * Copy the face flags, most importantly selection from the mesh to the final derived mesh, * use in object mode when selecting faces (while painting). */ -void paintface_flush_flags(struct bContext *C, struct Object *ob, short flag); +void paintface_flush_flags(struct bContext *C, + struct Object *ob, + bool flush_selection, + bool flush_hidden); /** * \return True when pick finds an element or the selection changed. */ diff --git a/source/blender/editors/mesh/editface.cc b/source/blender/editors/mesh/editface.cc index 3608e162727..96a493cba49 100644 --- a/source/blender/editors/mesh/editface.cc +++ b/source/blender/editors/mesh/editface.cc @@ -17,6 +17,7 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" +#include "BKE_attribute.hh" #include "BKE_context.h" #include "BKE_customdata.h" #include "BKE_global.h" @@ -36,14 +37,18 @@ /* own include */ -void paintface_flush_flags(bContext *C, Object *ob, short flag) +void paintface_flush_flags(bContext *C, + Object *ob, + const bool flush_selection, + const bool flush_hidden) { + using namespace blender; Mesh *me = BKE_mesh_from_object(ob); MPoly *polys, *mp_orig; const int *index_array = nullptr; int totpoly; - BLI_assert((flag & ~(SELECT | ME_HIDE)) == 0); + BLI_assert(flush_selection || flush_hidden); if (me == nullptr) { return; @@ -53,7 +58,7 @@ void paintface_flush_flags(bContext *C, Object *ob, short flag) /* we could call this directly in all areas that change selection, * since this could become slow for realtime updates (circle-select for eg) */ - if (flag & SELECT) { + if (flush_selection) { BKE_mesh_flush_select_from_polys(me); } @@ -64,8 +69,11 @@ void paintface_flush_flags(bContext *C, Object *ob, short flag) return; } + bke::AttributeAccessor attributes_me = bke::mesh_attributes(*me); Mesh *me_orig = (Mesh *)ob_eval->runtime.data_orig; + bke::MutableAttributeAccessor attributes_orig = bke::mesh_attributes_for_write(*me_orig); Mesh *me_eval = (Mesh *)ob_eval->runtime.data_eval; + bke::MutableAttributeAccessor attributes_eval = bke::mesh_attributes_for_write(*me_eval); bool updated = false; if (me_orig != nullptr && me_eval != nullptr && me_orig->totpoly == me->totpoly) { @@ -73,13 +81,17 @@ void paintface_flush_flags(bContext *C, Object *ob, short flag) for (int i = 0; i < me->totpoly; i++) { me_orig->mpoly[i].flag = me->mpoly[i].flag; } - - /* If the mesh has only deform modifiers, the evaluated mesh shares arrays. */ - if (me_eval->mpoly == me_orig->mpoly) { - updated = true; + if (flush_hidden) { + const VArray<bool> hide_face_me = attributes_me.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + bke::SpanAttributeWriter<bool> hide_face_orig = + attributes_orig.lookup_or_add_for_write_only_span<bool>(".hide_poly", ATTR_DOMAIN_FACE); + hide_face_me.materialize(hide_face_orig.span); + hide_face_orig.finish(); } + /* Mesh polys => Final derived polys */ - else if ((index_array = (const int *)CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX))) { + if ((index_array = (const int *)CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX))) { polys = me_eval->mpoly; totpoly = me_eval->totpoly; @@ -91,13 +103,24 @@ void paintface_flush_flags(bContext *C, Object *ob, short flag) polys[i].flag = mp_orig->flag; } } + const VArray<bool> hide_face_orig = attributes_orig.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + bke::SpanAttributeWriter<bool> hide_face_eval = + attributes_eval.lookup_or_add_for_write_only_span<bool>(".hide_poly", ATTR_DOMAIN_FACE); + for (const int i : IndexRange(me_eval->totpoly)) { + const int orig_face_index = index_array[i]; + if (orig_face_index != ORIGINDEX_NONE) { + hide_face_eval.span[i] = hide_face_orig[orig_face_index]; + } + } + hide_face_eval.finish(); updated = true; } } if (updated) { - if (flag & ME_HIDE) { + if (flush_hidden) { BKE_mesh_batch_cache_dirty_tag(me_eval, BKE_MESH_BATCH_DIRTY_ALL); } else { @@ -115,59 +138,79 @@ void paintface_flush_flags(bContext *C, Object *ob, short flag) void paintface_hide(bContext *C, Object *ob, const bool unselected) { + using namespace blender; Mesh *me = BKE_mesh_from_object(ob); if (me == nullptr || me->totpoly == 0) { return; } + bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me); + bke::SpanAttributeWriter<bool> hide_poly = attributes.lookup_or_add_for_write_span<bool>( + ".hide_poly", ATTR_DOMAIN_FACE); + for (int i = 0; i < me->totpoly; i++) { MPoly *mpoly = &me->mpoly[i]; - if ((mpoly->flag & ME_HIDE) == 0) { + if (!hide_poly.span[i]) { if (((mpoly->flag & ME_FACE_SEL) == 0) == unselected) { - mpoly->flag |= ME_HIDE; + hide_poly.span[i] = true; } } - if (mpoly->flag & ME_HIDE) { + if (hide_poly.span[i]) { mpoly->flag &= ~ME_FACE_SEL; } } + hide_poly.finish(); + BKE_mesh_flush_hidden_from_polys(me); - paintface_flush_flags(C, ob, SELECT | ME_HIDE); + paintface_flush_flags(C, ob, true, true); } void paintface_reveal(bContext *C, Object *ob, const bool select) { + using namespace blender; Mesh *me = BKE_mesh_from_object(ob); if (me == nullptr || me->totpoly == 0) { return; } - for (int i = 0; i < me->totpoly; i++) { - MPoly *mpoly = &me->mpoly[i]; - if (mpoly->flag & ME_HIDE) { - SET_FLAG_FROM_TEST(mpoly->flag, select, ME_FACE_SEL); - mpoly->flag &= ~ME_HIDE; + bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me); + + if (select) { + const VArray<bool> hide_poly = attributes.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + for (int i = 0; i < me->totpoly; i++) { + MPoly *mpoly = &me->mpoly[i]; + if (hide_poly[i]) { + mpoly->flag |= ME_FACE_SEL; + } } } + attributes.remove(".hide_poly"); + BKE_mesh_flush_hidden_from_polys(me); - paintface_flush_flags(C, ob, SELECT | ME_HIDE); + paintface_flush_flags(C, ob, true, true); } /* Set object-mode face selection seams based on edge data, uses hash table to find seam edges. */ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bool select) { + using namespace blender; bool do_it = true; bool mark = false; BLI_bitmap *edge_tag = BLI_BITMAP_NEW(me->totedge, __func__); BLI_bitmap *poly_tag = BLI_BITMAP_NEW(me->totpoly, __func__); + bke::AttributeAccessor attributes = bke::mesh_attributes(*me); + const VArray<bool> hide_poly = attributes.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + if (index != (uint)-1) { /* only put face under cursor in array */ MPoly *mp = &me->mpoly[index]; @@ -178,7 +221,7 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo /* fill array by selection */ for (int i = 0; i < me->totpoly; i++) { MPoly *mp = &me->mpoly[i]; - if (mp->flag & ME_HIDE) { + if (hide_poly[i]) { /* pass */ } else if (mp->flag & ME_FACE_SEL) { @@ -194,7 +237,7 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo /* expand selection */ for (int i = 0; i < me->totpoly; i++) { MPoly *mp = &me->mpoly[i]; - if (mp->flag & ME_HIDE) { + if (hide_poly[i]) { continue; } @@ -249,22 +292,27 @@ void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const b select_linked_tfaces_with_seams(me, index, select); - paintface_flush_flags(C, ob, SELECT); + paintface_flush_flags(C, ob, true, false); } bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool flush_flags) { + using namespace blender; Mesh *me = BKE_mesh_from_object(ob); if (me == nullptr) { return false; } + bke::AttributeAccessor attributes = bke::mesh_attributes(*me); + const VArray<bool> hide_poly = attributes.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + if (action == SEL_TOGGLE) { action = SEL_SELECT; for (int i = 0; i < me->totpoly; i++) { MPoly *mpoly = &me->mpoly[i]; - if ((mpoly->flag & ME_HIDE) == 0 && mpoly->flag & ME_FACE_SEL) { + if (!hide_poly[i] && mpoly->flag & ME_FACE_SEL) { action = SEL_DESELECT; break; } @@ -275,7 +323,7 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl for (int i = 0; i < me->totpoly; i++) { MPoly *mpoly = &me->mpoly[i]; - if ((mpoly->flag & ME_HIDE) == 0) { + if (!hide_poly[i]) { switch (action) { case SEL_SELECT: if ((mpoly->flag & ME_FACE_SEL) == 0) { @@ -299,7 +347,7 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl if (changed) { if (flush_flags) { - paintface_flush_flags(C, ob, SELECT); + paintface_flush_flags(C, ob, true, false); } } return changed; @@ -307,6 +355,7 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl bool paintface_minmax(Object *ob, float r_min[3], float r_max[3]) { + using namespace blender; bool ok = false; float vec[3], bmat[3][3]; @@ -318,9 +367,13 @@ bool paintface_minmax(Object *ob, float r_min[3], float r_max[3]) copy_m3_m4(bmat, ob->obmat); + bke::AttributeAccessor attributes = bke::mesh_attributes(*me); + const VArray<bool> hide_poly = attributes.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + for (int i = 0; i < me->totpoly; i++) { MPoly *mp = &me->mpoly[i]; - if (mp->flag & ME_HIDE || !(mp->flag & ME_FACE_SEL)) { + if (hide_poly[i] || !(mp->flag & ME_FACE_SEL)) { continue; } @@ -342,6 +395,7 @@ bool paintface_mouse_select(bContext *C, const SelectPick_Params *params, Object *ob) { + using namespace blender; MPoly *mpoly_sel = nullptr; uint index; bool changed = false; @@ -350,10 +404,14 @@ bool paintface_mouse_select(bContext *C, /* Get the face under the cursor */ Mesh *me = BKE_mesh_from_object(ob); + bke::AttributeAccessor attributes = bke::mesh_attributes(*me); + const VArray<bool> hide_poly = attributes.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + if (ED_mesh_pick_face(C, ob, mval, ED_MESH_PICK_DEFAULT_FACE_DIST, &index)) { if (index < me->totpoly) { mpoly_sel = me->mpoly + index; - if ((mpoly_sel->flag & ME_HIDE) == 0) { + if (!hide_poly[index]) { found = true; } } @@ -402,7 +460,7 @@ bool paintface_mouse_select(bContext *C, /* image window redraw */ - paintface_flush_flags(C, ob, SELECT); + paintface_flush_flags(C, ob, true, false); ED_region_tag_redraw(CTX_wm_region(C)); /* XXX: should redraw all 3D views. */ changed = true; } @@ -463,17 +521,24 @@ void paintvert_tag_select_update(bContext *C, Object *ob) bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags) { + using namespace blender; Mesh *me = BKE_mesh_from_object(ob); if (me == nullptr) { return false; } + bke::AttributeAccessor attributes = bke::mesh_attributes(*me); + const VArray<bool> hide_vert = attributes.lookup_or_default<bool>( + ".hide_vert", ATTR_DOMAIN_POINT, false); + const VArray<bool> hide_poly = attributes.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + if (action == SEL_TOGGLE) { action = SEL_SELECT; for (int i = 0; i < me->totvert; i++) { MVert *mvert = &me->mvert[i]; - if ((mvert->flag & ME_HIDE) == 0 && mvert->flag & SELECT) { + if (!hide_poly[i] && mvert->flag & SELECT) { action = SEL_DESELECT; break; } @@ -483,7 +548,7 @@ bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags) bool changed = false; for (int i = 0; i < me->totvert; i++) { MVert *mvert = &me->mvert[i]; - if ((mvert->flag & ME_HIDE) == 0) { + if (!hide_vert[i]) { switch (action) { case SEL_SELECT: if ((mvert->flag & SELECT) == 0) { @@ -526,6 +591,7 @@ bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags) void paintvert_select_ungrouped(Object *ob, bool extend, bool flush_flags) { + using namespace blender; Mesh *me = BKE_mesh_from_object(ob); if (me == nullptr || me->dvert == nullptr) { @@ -536,10 +602,14 @@ void paintvert_select_ungrouped(Object *ob, bool extend, bool flush_flags) paintvert_deselect_all_visible(ob, SEL_DESELECT, false); } + bke::AttributeAccessor attributes = bke::mesh_attributes(*me); + const VArray<bool> hide_poly = attributes.lookup_or_default<bool>( + ".hide_poly", ATTR_DOMAIN_FACE, false); + for (int i = 0; i < me->totvert; i++) { MVert *mv = &me->mvert[i]; MDeformVert *dv = &me->dvert[i]; - if ((mv->flag & ME_HIDE) == 0) { + if (!hide_poly[i]) { if (dv->dw == nullptr) { /* if null weight then not grouped */ mv->flag |= SELECT; @@ -554,25 +624,30 @@ void paintvert_select_ungrouped(Object *ob, bool extend, bool flush_flags) void paintvert_hide(bContext *C, Object *ob, const bool unselected) { - Mesh *const me = BKE_mesh_from_object(ob); - - if (me == nullptr || me->totvert == 0) { + using namespace blender; + Mesh *me = BKE_mesh_from_object(ob); + if (me == NULL || me->totvert == 0) { return; } - for (int i = 0; i < me->totvert; i++) { - MVert *const mvert = &me->mvert[i]; + bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me); + bke::SpanAttributeWriter<bool> hide_vert = attributes.lookup_or_add_for_write_span<bool>( + ".hide_vert", ATTR_DOMAIN_POINT); + MutableSpan<MVert> vertices(me->mvert, me->totvert); - if ((mvert->flag & ME_HIDE) == 0) { - if (((mvert->flag & SELECT) == 0) == unselected) { - mvert->flag |= ME_HIDE; + for (const int i : vertices.index_range()) { + MVert &vert = vertices[i]; + if (!hide_vert.span[i]) { + if (((vert.flag & SELECT) == 0) == unselected) { + hide_vert.span[i] = true; } } - if (mvert->flag & ME_HIDE) { - mvert->flag &= ~SELECT; + if (hide_vert.span[i]) { + vert.flag &= ~SELECT; } } + hide_vert.finish(); BKE_mesh_flush_hidden_from_verts(me); @@ -582,21 +657,27 @@ void paintvert_hide(bContext *C, Object *ob, const bool unselected) void paintvert_reveal(bContext *C, Object *ob, const bool select) { - Mesh *const me = BKE_mesh_from_object(ob); - - if (me == nullptr || me->totvert == 0) { + using namespace blender; + Mesh *me = BKE_mesh_from_object(ob); + if (me == NULL || me->totvert == 0) { return; } - for (int i = 0; i < me->totvert; i++) { - MVert *const mvert = &me->mvert[i]; + bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me); + const VArray<bool> hide_vert = attributes.lookup_or_default<bool>( + ".hide_vert", ATTR_DOMAIN_POINT, false); + MutableSpan<MVert> vertices(me->mvert, me->totvert); - if (mvert->flag & ME_HIDE) { - SET_FLAG_FROM_TEST(mvert->flag, select, SELECT); - mvert->flag &= ~ME_HIDE; + for (const int i : vertices.index_range()) { + MVert &vert = vertices[i]; + if (hide_vert[i]) { + SET_FLAG_FROM_TEST(vert.flag, select, SELECT); } } + /* Remove the hide attribute to reveal all vertices. */ + attributes.remove(".hide_vert"); + BKE_mesh_flush_hidden_from_verts(me); paintvert_flush_flags(ob); diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index d75c92f963f..af8084e16c4 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -594,6 +594,10 @@ static void *undomesh_from_editmesh(UndoMesh *um, BMEditMesh *em, Key *key, Undo /* Uncomment for troubleshooting. */ // BM_mesh_validate(em->bm); + /* Copy the ID name characters to the mesh so code that depends on accessing the ID type can work + * on it. Necessary to use the attribute API. */ + strcpy(um->me.id.name, "MEundomesh_from_editmesh"); + BM_mesh_bm_to_me( NULL, em->bm, diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc index 9e28e1bafdd..b1004b23a21 100644 --- a/source/blender/editors/mesh/meshtools.cc +++ b/source/blender/editors/mesh/meshtools.cc @@ -1329,6 +1329,7 @@ bool ED_mesh_pick_face_vert( */ struct VertPickData { const MVert *mvert; + const bool *hide_vert; const float *mval_f; /* [2] */ ARegion *region; @@ -1343,16 +1344,16 @@ static void ed_mesh_pick_vert__mapFunc(void *userData, const float UNUSED(no[3])) { VertPickData *data = static_cast<VertPickData *>(userData); - if ((data->mvert[index].flag & ME_HIDE) == 0) { - float sco[2]; - - if (ED_view3d_project_float_object(data->region, co, sco, V3D_PROJ_TEST_CLIP_DEFAULT) == - V3D_PROJ_RET_OK) { - const float len = len_manhattan_v2v2(data->mval_f, sco); - if (len < data->len_best) { - data->len_best = len; - data->v_idx_best = index; - } + if (data->hide_vert && data->hide_vert[index]) { + return; + } + float sco[2]; + if (ED_view3d_project_float_object(data->region, co, sco, V3D_PROJ_TEST_CLIP_DEFAULT) == + V3D_PROJ_RET_OK) { + const float len = len_manhattan_v2v2(data->mval_f, sco); + if (len < data->len_best) { + data->len_best = len; + data->v_idx_best = index; } } } @@ -1416,6 +1417,8 @@ bool ED_mesh_pick_vert( data.mval_f = mval_f; data.len_best = FLT_MAX; data.v_idx_best = -1; + data.hide_vert = (const bool *)CustomData_get_layer_named( + &me_eval->vdata, CD_PROP_BOOL, ".hide_vert"); BKE_mesh_foreach_mapped_vert(me_eval, ed_mesh_pick_vert__mapFunc, &data, MESH_FOREACH_NOP); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 6369afac632..eb5aaf7ef61 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1034,6 +1034,7 @@ static void vgroup_select_verts(Object *ob, int select) } else { if (me->dvert) { + const bool *hide_vert = CustomData_get_layer_named(&me->vdata, CD_PROP_BOOL, ".hide_vert"); MVert *mv; MDeformVert *dv; int i; @@ -1042,7 +1043,7 @@ static void vgroup_select_verts(Object *ob, int select) dv = me->dvert; for (i = 0; i < me->totvert; i++, mv++, dv++) { - if (!(mv->flag & ME_HIDE)) { + if (hide_vert != NULL && !hide_vert[i]) { if (BKE_defvert_find_index(dv, def_nr)) { if (select) { mv->flag |= SELECT; @@ -1930,7 +1931,11 @@ static void vgroup_smooth_subset(Object *ob, #define IS_BM_VERT_READ(v) (use_hide ? (BM_elem_flag_test(v, BM_ELEM_HIDDEN) == 0) : true) #define IS_BM_VERT_WRITE(v) (use_select ? (BM_elem_flag_test(v, BM_ELEM_SELECT) != 0) : true) -#define IS_ME_VERT_READ(v) (use_hide ? (((v)->flag & ME_HIDE) == 0) : true) + const bool *hide_vert = me ? (const bool *)CustomData_get_layer_named( + &me->vdata, CD_PROP_BOOL, ".hide_vert") : + NULL; + +#define IS_ME_VERT_READ(v) (use_hide ? (hide_vert && hide_vert[v]) : true) #define IS_ME_VERT_WRITE(v) (use_select ? (((v)->flag & SELECT) != 0) : true) /* initialize used verts */ @@ -1956,8 +1961,8 @@ static void vgroup_smooth_subset(Object *ob, if (IS_ME_VERT_WRITE(v)) { for (int j = 0; j < emap[i].count; j++) { const MEdge *e = &me->medge[emap[i].indices[j]]; - const MVert *v_other = &me->mvert[(e->v1 == i) ? e->v2 : e->v1]; - if (IS_ME_VERT_READ(v_other)) { + const int i_other = (e->v1 == i) ? e->v2 : e->v1; + if (IS_ME_VERT_READ(i_other)) { STACK_PUSH(verts_used, i); break; } @@ -2031,9 +2036,7 @@ static void vgroup_smooth_subset(Object *ob, for (j = 0; j < emap[i].count; j++) { MEdge *e = &me->medge[emap[i].indices[j]]; const int i_other = (e->v1 == i ? e->v2 : e->v1); - MVert *v_other = &me->mvert[i_other]; - - if (IS_ME_VERT_READ(v_other)) { + if (IS_ME_VERT_READ(i_other)) { WEIGHT_ACCUMULATE; } } diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index 944b3f953a0..c904d533db8 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -78,6 +78,12 @@ static void partialvis_update_mesh(Object *ob, BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert); paint_mask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK); + bool *hide_vert = CustomData_get_layer_named(&me->vdata, CD_PROP_BOOL, ".hide_vert"); + if (hide_vert == NULL) { + hide_vert = CustomData_add_layer_named( + &me->vdata, CD_PROP_BOOL, CD_CALLOC, NULL, me->totvert, ".hide_vert"); + } + SCULPT_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN); for (i = 0; i < totvert; i++) { @@ -86,16 +92,11 @@ static void partialvis_update_mesh(Object *ob, /* Hide vertex if in the hide volume. */ if (is_effected(area, planes, v->co, vmask)) { - if (action == PARTIALVIS_HIDE) { - v->flag |= ME_HIDE; - } - else { - v->flag &= ~ME_HIDE; - } + hide_vert[vert_indices[i]] = (action == PARTIALVIS_HIDE); any_changed = true; } - if (!(v->flag & ME_HIDE)) { + if (!hide_vert[vert_indices[i]]) { any_visible = true; } } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 02d21941a25..ffa931268fd 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -344,9 +344,11 @@ int SCULPT_active_face_set_get(SculptSession *ss) void SCULPT_vertex_visible_set(SculptSession *ss, PBVHVertRef vertex, bool visible) { switch (BKE_pbvh_type(ss->pbvh)) { - case PBVH_FACES: - SET_FLAG_FROM_TEST(ss->mvert[vertex.i].flag, !visible, ME_HIDE); + case PBVH_FACES: { + bool *hide_vert = BKE_pbvh_get_vert_hide_for_write(ss->pbvh); + hide_vert[vertex.i] = visible; break; + } case PBVH_BMESH: { BMVert *v = (BMVert *)vertex.i; BM_elem_flag_set(v, BM_ELEM_HIDDEN, !visible); @@ -360,8 +362,10 @@ void SCULPT_vertex_visible_set(SculptSession *ss, PBVHVertRef vertex, bool visib bool SCULPT_vertex_visible_get(SculptSession *ss, PBVHVertRef vertex) { switch (BKE_pbvh_type(ss->pbvh)) { - case PBVH_FACES: - return !(ss->mvert[vertex.i].flag & ME_HIDE); + case PBVH_FACES: { + const bool *hide_vert = BKE_pbvh_get_vert_hide(ss->pbvh); + return hide_vert == NULL || !hide_vert[vertex.i]; + } case PBVH_BMESH: return !BM_elem_flag_test((BMVert *)vertex.i, BM_ELEM_HIDDEN); case PBVH_GRIDS: { diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c index 4f91d2215fb..40b4b74a441 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c @@ -227,8 +227,9 @@ static void SCULPT_dynamic_topology_disable_ex( me->face_sets_color_default = 1; /* Sync the visibility to vertices manually as the pmap is still not initialized. */ - for (int i = 0; i < me->totvert; i++) { - me->mvert[i].flag &= ~ME_HIDE; + bool *hide_vert = (bool *)CustomData_get_layer_named(&me->vdata, CD_PROP_BOOL, ".hide_vert"); + if (hide_vert != NULL) { + memset(hide_vert, 0, sizeof(bool) * me->totvert); } } diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index dc814d6d22f..04b2b2f04bf 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -346,14 +346,13 @@ static bool sculpt_undo_restore_hidden(bContext *C, SculptUndoNode *unode, bool SculptSession *ss = ob->sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; - if (unode->maxvert) { - MVert *mvert = ss->mvert; + bool *hide_vert = BKE_pbvh_get_vert_hide_for_write(ss->pbvh); + if (unode->maxvert) { for (int i = 0; i < unode->totvert; i++) { - MVert *v = &mvert[unode->index[i]]; - if ((BLI_BITMAP_TEST(unode->vert_hidden, i) != 0) != ((v->flag & ME_HIDE) != 0)) { + if ((BLI_BITMAP_TEST(unode->vert_hidden, i) != 0) != hide_vert[i]) { BLI_BITMAP_FLIP(unode->vert_hidden, i); - v->flag ^= ME_HIDE; + hide_vert[unode->index[i]] = !hide_vert[i]; modified_vertices[unode->index[i]] = true; } } @@ -1247,6 +1246,11 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode) PBVH *pbvh = ob->sculpt->pbvh; PBVHNode *node = unode->node; + const bool *hide_vert = BKE_pbvh_get_vert_hide(pbvh); + if (hide_vert == NULL) { + return; + } + if (unode->grids) { /* Already stored during allocation. */ } @@ -1258,7 +1262,7 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode) BKE_pbvh_node_num_verts(pbvh, node, NULL, &allvert); BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert); for (int i = 0; i < allvert; i++) { - BLI_BITMAP_SET(unode->vert_hidden, i, mvert[vert_indices[i]].flag & ME_HIDE); + BLI_BITMAP_SET(unode->vert_hidden, i, hide_vert[vert_indices[i]]); } } } diff --git a/source/blender/editors/space_view3d/view3d_iterators.c b/source/blender/editors/space_view3d/view3d_iterators.c index 35d4746608b..6256eeb9621 100644 --- a/source/blender/editors/space_view3d/view3d_iterators.c +++ b/source/blender/editors/space_view3d/view3d_iterators.c @@ -205,6 +205,7 @@ typedef struct foreachScreenObjectVert_userData { void (*func)(void *userData, MVert *mv, const float screen_co[2], int index); void *userData; ViewContext vc; + const bool *hide_vert; eV3DProjTest clip_flag; } foreachScreenObjectVert_userData; @@ -262,18 +263,19 @@ static void meshobject_foreachScreenVert__mapFunc(void *userData, const float UNUSED(no[3])) { foreachScreenObjectVert_userData *data = userData; + if (data->hide_vert && data->hide_vert[index]) { + return; + } struct MVert *mv = &((Mesh *)(data->vc.obact->data))->mvert[index]; - if (!(mv->flag & ME_HIDE)) { - float screen_co[2]; - - if (ED_view3d_project_float_object(data->vc.region, co, screen_co, data->clip_flag) != - V3D_PROJ_RET_OK) { - return; - } + float screen_co[2]; - data->func(data->userData, mv, screen_co, index); + if (ED_view3d_project_float_object(data->vc.region, co, screen_co, data->clip_flag) != + V3D_PROJ_RET_OK) { + return; } + + data->func(data->userData, mv, screen_co, index); } void meshobject_foreachScreenVert( @@ -297,6 +299,8 @@ void meshobject_foreachScreenVert( data.func = func; data.userData = userData; data.clip_flag = clip_flag; + data.hide_vert = (const bool *)CustomData_get_layer_named( + &me->vdata, CD_PROP_BOOL, ".hide_vert"); if (clip_flag & V3D_PROJ_TEST_CLIP_BB) { ED_view3d_clipping_local(vc->rv3d, vc->obact->obmat); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 571c39f30cb..cd609f7e8cf 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -335,14 +335,16 @@ static bool edbm_backbuf_check_and_select_verts_obmode(Mesh *me, const eSelectOp sel_op) { MVert *mv = me->mvert; - uint index; bool changed = false; const BLI_bitmap *select_bitmap = esel->select_bitmap; if (mv) { - for (index = 0; index < me->totvert; index++, mv++) { - if (!(mv->flag & ME_HIDE)) { + const bool *hide_vert = (const bool *)CustomData_get_layer_named( + &me->vdata, CD_PROP_BOOL, ".hide_vert"); + + for (int index = 0; index < me->totvert; index++, mv++) { + if (!(hide_vert && hide_vert[index])) { const bool is_select = mv->flag & SELECT; const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index); const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside); @@ -362,14 +364,16 @@ static bool edbm_backbuf_check_and_select_faces_obmode(Mesh *me, const eSelectOp sel_op) { MPoly *mpoly = me->mpoly; - uint index; bool changed = false; const BLI_bitmap *select_bitmap = esel->select_bitmap; if (mpoly) { - for (index = 0; index < me->totpoly; index++, mpoly++) { - if (!(mpoly->flag & ME_HIDE)) { + const bool *hide_poly = (const bool *)CustomData_get_layer_named( + &me->vdata, CD_PROP_BOOL, ".hide_poly"); + + for (int index = 0; index < me->totpoly; index++, mpoly++) { + if (!(hide_poly && hide_poly[index])) { const bool is_select = mpoly->flag & ME_FACE_SEL; const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index); const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside); @@ -1260,7 +1264,7 @@ static bool do_lasso_select_paintface(ViewContext *vc, } if (changed) { - paintface_flush_flags(vc->C, ob, SELECT); + paintface_flush_flags(vc->C, ob, true, false); } return changed; } @@ -3192,7 +3196,7 @@ static bool do_paintface_box_select(ViewContext *vc, } if (changed) { - paintface_flush_flags(vc->C, vc->obact, SELECT); + paintface_flush_flags(vc->C, vc->obact, true, false); } return changed; } @@ -4093,7 +4097,7 @@ static bool paint_facesel_circle_select(ViewContext *vc, } if (changed) { - paintface_flush_flags(vc->C, ob, SELECT); + paintface_flush_flags(vc->C, ob, true, false); } return changed; } |