Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/mesh/editface.cc')
-rw-r--r--source/blender/editors/mesh/editface.cc458
1 files changed, 284 insertions, 174 deletions
diff --git a/source/blender/editors/mesh/editface.cc b/source/blender/editors/mesh/editface.cc
index b69cd8b8606..888a8340d51 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,16 @@
/* 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 +56,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,32 +67,62 @@ void paintface_flush_flags(bContext *C, Object *ob, short flag)
return;
}
+ bke::AttributeAccessor attributes_me = me->attributes();
Mesh *me_orig = (Mesh *)ob_eval->runtime.data_orig;
+ bke::MutableAttributeAccessor attributes_orig = me_orig->attributes_for_write();
Mesh *me_eval = (Mesh *)ob_eval->runtime.data_eval;
+ bke::MutableAttributeAccessor attributes_eval = me_eval->attributes_for_write();
bool updated = false;
if (me_orig != nullptr && me_eval != nullptr && me_orig->totpoly == me->totpoly) {
/* Update the COW copy of the mesh. */
- for (int i = 0; i < me->totpoly; i++) {
- me_orig->mpoly[i].flag = me->mpoly[i].flag;
+ if (flush_hidden) {
+ const VArray<bool> hide_poly_me = attributes_me.lookup_or_default<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> hide_poly_orig =
+ attributes_orig.lookup_or_add_for_write_only_span<bool>(".hide_poly", ATTR_DOMAIN_FACE);
+ hide_poly_me.materialize(hide_poly_orig.span);
+ hide_poly_orig.finish();
+ }
+ if (flush_selection) {
+ const VArray<bool> select_poly_me = attributes_me.lookup_or_default<bool>(
+ ".select_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> select_poly_orig =
+ attributes_orig.lookup_or_add_for_write_only_span<bool>(".select_poly",
+ ATTR_DOMAIN_FACE);
+ select_poly_me.materialize(select_poly_orig.span);
+ select_poly_orig.finish();
}
- /* If the mesh has only deform modifiers, the evaluated mesh shares arrays. */
- if (me_eval->mpoly == me_orig->mpoly) {
- updated = true;
- }
/* Mesh polys => Final derived polys */
- else if ((index_array = (const int *)CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX))) {
- polys = me_eval->mpoly;
- totpoly = me_eval->totpoly;
-
- /* loop over final derived polys */
- for (int i = 0; i < totpoly; i++) {
- if (index_array[i] != ORIGINDEX_NONE) {
- /* Copy flags onto the final derived poly from the original mesh poly */
- mp_orig = me->mpoly + index_array[i];
- polys[i].flag = mp_orig->flag;
+ if ((index_array = (const int *)CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX))) {
+ if (flush_hidden) {
+ const VArray<bool> hide_poly_orig = attributes_orig.lookup_or_default<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> hide_poly_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_poly_index = index_array[i];
+ if (orig_poly_index != ORIGINDEX_NONE) {
+ hide_poly_eval.span[i] = hide_poly_orig[orig_poly_index];
+ }
}
+ hide_poly_eval.finish();
+ }
+ if (flush_selection) {
+ const VArray<bool> select_poly_orig = attributes_orig.lookup_or_default<bool>(
+ ".select_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> select_poly_eval =
+ attributes_eval.lookup_or_add_for_write_only_span<bool>(".select_poly",
+ ATTR_DOMAIN_FACE);
+ for (const int i : IndexRange(me_eval->totpoly)) {
+ const int orig_poly_index = index_array[i];
+ if (orig_poly_index != ORIGINDEX_NONE) {
+ select_poly_eval.span[i] = select_poly_orig[orig_poly_index];
+ }
+ }
+ select_poly_eval.finish();
}
updated = true;
@@ -97,7 +130,7 @@ void paintface_flush_flags(bContext *C, Object *ob, short flag)
}
if (updated) {
- if (flag & ME_HIDE) {
+ if (flush_hidden) {
BKE_mesh_batch_cache_dirty_tag(me_eval, BKE_MESH_BATCH_DIRTY_ALL);
}
else {
@@ -115,74 +148,103 @@ 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 = me->attributes_for_write();
+ bke::SpanAttributeWriter<bool> hide_poly = attributes.lookup_or_add_for_write_span<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE);
+ bke::SpanAttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_poly", ATTR_DOMAIN_FACE);
+
for (int i = 0; i < me->totpoly; i++) {
- MPoly *mpoly = &me->mpoly[i];
- if ((mpoly->flag & ME_HIDE) == 0) {
- if (((mpoly->flag & ME_FACE_SEL) == 0) == unselected) {
- mpoly->flag |= ME_HIDE;
+ if (!hide_poly.span[i]) {
+ if (!select_poly.span[i] == unselected) {
+ hide_poly.span[i] = true;
}
}
- if (mpoly->flag & ME_HIDE) {
- mpoly->flag &= ~ME_FACE_SEL;
+ if (hide_poly.span[i]) {
+ select_poly.span[i] = false;
}
}
+ hide_poly.finish();
+ select_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 = me->attributes_for_write();
+
+ if (select) {
+ const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_poly", ATTR_DOMAIN_FACE);
+ for (const int i : hide_poly.index_range()) {
+ if (hide_poly[i]) {
+ select_poly.span[i] = true;
+ }
}
+ select_poly.finish();
}
+ 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__);
- if (index != (uint)-1) {
+ const Span<MEdge> edges = me->edges();
+ const Span<MPoly> polys = me->polys();
+ const Span<MLoop> loops = me->loops();
+ bke::MutableAttributeAccessor attributes = me->attributes_for_write();
+ const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_poly", ATTR_DOMAIN_FACE);
+
+ if (index != uint(-1)) {
/* only put face under cursor in array */
- MPoly *mp = &me->mpoly[index];
- BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart);
+ const MPoly &poly = polys[index];
+ BKE_mesh_poly_edgebitmap_insert(edge_tag, &poly, &loops[poly.loopstart]);
BLI_BITMAP_ENABLE(poly_tag, index);
}
else {
/* 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) {
- BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart);
+ else if (select_poly.span[i]) {
+ const MPoly &poly = polys[i];
+ BKE_mesh_poly_edgebitmap_insert(edge_tag, &poly, &loops[poly.loopstart]);
BLI_BITMAP_ENABLE(poly_tag, i);
}
}
@@ -193,17 +255,17 @@ 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;
}
if (!BLI_BITMAP_TEST(poly_tag, i)) {
mark = false;
- MLoop *ml = me->mloop + mp->loopstart;
- for (int b = 0; b < mp->totloop; b++, ml++) {
- if ((me->medge[ml->e].flag & ME_SEAM) == 0) {
+ const MPoly &poly = polys[i];
+ const MLoop *ml = &loops[poly.loopstart];
+ for (int b = 0; b < poly.totloop; b++, ml++) {
+ if ((edges[ml->e].flag & ME_SEAM) == 0) {
if (BLI_BITMAP_TEST(edge_tag, ml->e)) {
mark = true;
break;
@@ -213,7 +275,7 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
if (mark) {
BLI_BITMAP_ENABLE(poly_tag, i);
- BKE_mesh_poly_edgebitmap_insert(edge_tag, mp, me->mloop + mp->loopstart);
+ BKE_mesh_poly_edgebitmap_insert(edge_tag, &poly, &loops[poly.loopstart]);
do_it = true;
}
}
@@ -223,9 +285,8 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
MEM_freeN(edge_tag);
for (int i = 0; i < me->totpoly; i++) {
- MPoly *mp = &me->mpoly[i];
if (BLI_BITMAP_TEST(poly_tag, i)) {
- SET_FLAG_FROM_TEST(mp->flag, select, ME_FACE_SEL);
+ select_poly.span[i] = select;
}
}
@@ -234,7 +295,7 @@ static void select_linked_tfaces_with_seams(Mesh *me, const uint index, const bo
void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const bool select)
{
- uint index = (uint)-1;
+ uint index = uint(-1);
Mesh *me = BKE_mesh_from_object(ob);
if (me == nullptr || me->totpoly == 0) {
@@ -249,22 +310,28 @@ 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::MutableAttributeAccessor attributes = me->attributes_for_write();
+ const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_poly", ATTR_DOMAIN_FACE);
+
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] && select_poly.span[i]) {
action = SEL_DESELECT;
break;
}
@@ -274,32 +341,32 @@ bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool fl
bool changed = false;
for (int i = 0; i < me->totpoly; i++) {
- MPoly *mpoly = &me->mpoly[i];
- if ((mpoly->flag & ME_HIDE) == 0) {
- switch (action) {
- case SEL_SELECT:
- if ((mpoly->flag & ME_FACE_SEL) == 0) {
- mpoly->flag |= ME_FACE_SEL;
- changed = true;
- }
- break;
- case SEL_DESELECT:
- if ((mpoly->flag & ME_FACE_SEL) != 0) {
- mpoly->flag &= ~ME_FACE_SEL;
- changed = true;
- }
- break;
- case SEL_INVERT:
- mpoly->flag ^= ME_FACE_SEL;
- changed = true;
- break;
- }
+ if (hide_poly[i]) {
+ continue;
+ }
+ const bool old_selection = select_poly.span[i];
+ switch (action) {
+ case SEL_SELECT:
+ select_poly.span[i] = true;
+ break;
+ case SEL_DESELECT:
+ select_poly.span[i] = false;
+ break;
+ case SEL_INVERT:
+ select_poly.span[i] = !select_poly.span[i];
+ changed = true;
+ break;
+ }
+ if (old_selection != select_poly.span[i]) {
+ changed = true;
}
}
+ select_poly.finish();
+
if (changed) {
if (flush_flags) {
- paintface_flush_flags(C, ob, SELECT);
+ paintface_flush_flags(C, ob, true, false);
}
}
return changed;
@@ -307,26 +374,35 @@ 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];
const Mesh *me = BKE_mesh_from_object(ob);
- if (!me || !me->mloopuv) {
+ if (!me || !CustomData_has_layer(&me->ldata, CD_MLOOPUV)) {
return ok;
}
- const MVert *mvert = me->mvert;
copy_m3_m4(bmat, ob->obmat);
+ const Span<MVert> verts = me->verts();
+ const Span<MPoly> polys = me->polys();
+ const Span<MLoop> loops = me->loops();
+ bke::AttributeAccessor attributes = me->attributes();
+ const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE, false);
+ const VArray<bool> select_poly = attributes.lookup_or_default<bool>(
+ ".select_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] || !select_poly[i]) {
continue;
}
- const MLoop *ml = me->mloop + mp->loopstart;
- for (int b = 0; b < mp->totloop; b++, ml++) {
- mul_v3_m3v3(vec, bmat, mvert[ml->v].co);
+ const MPoly &poly = polys[i];
+ const MLoop *ml = &loops[poly.loopstart];
+ for (int b = 0; b < poly.totloop; b++, ml++) {
+ mul_v3_m3v3(vec, bmat, verts[ml->v].co);
add_v3_v3v3(vec, vec, ob->obmat[3]);
minmax_v3v3_v3(r_min, r_max, vec);
}
@@ -342,7 +418,7 @@ bool paintface_mouse_select(bContext *C,
const SelectPick_Params *params,
Object *ob)
{
- MPoly *mpoly_sel = nullptr;
+ using namespace blender;
uint index;
bool changed = false;
bool found = false;
@@ -350,17 +426,22 @@ bool paintface_mouse_select(bContext *C,
/* Get the face under the cursor */
Mesh *me = BKE_mesh_from_object(ob);
+ bke::MutableAttributeAccessor attributes = me->attributes_for_write();
+ const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE, false);
+ bke::AttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write<bool>(
+ ".select_poly", ATTR_DOMAIN_FACE);
+
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;
}
}
}
if (params->sel_op == SEL_OP_SET) {
- if ((found && params->select_passthrough) && (mpoly_sel->flag & ME_FACE_SEL)) {
+ if ((found && params->select_passthrough) && select_poly.varray[index]) {
found = false;
}
else if (found || params->deselect_all) {
@@ -370,39 +451,27 @@ bool paintface_mouse_select(bContext *C,
}
if (found) {
- me->act_face = (int)index;
+ me->act_face = int(index);
switch (params->sel_op) {
- case SEL_OP_ADD: {
- mpoly_sel->flag |= ME_FACE_SEL;
- break;
- }
- case SEL_OP_SUB: {
- mpoly_sel->flag &= ~ME_FACE_SEL;
+ case SEL_OP_SET:
+ case SEL_OP_ADD:
+ select_poly.varray.set(index, true);
break;
- }
- case SEL_OP_XOR: {
- if (mpoly_sel->flag & ME_FACE_SEL) {
- mpoly_sel->flag &= ~ME_FACE_SEL;
- }
- else {
- mpoly_sel->flag |= ME_FACE_SEL;
- }
+ case SEL_OP_SUB:
+ select_poly.varray.set(index, false);
break;
- }
- case SEL_OP_SET: {
- mpoly_sel->flag |= ME_FACE_SEL;
+ case SEL_OP_XOR:
+ select_poly.varray.set(index, !select_poly.varray[index]);
break;
- }
- case SEL_OP_AND: {
+ case SEL_OP_AND:
BLI_assert_unreachable(); /* Doesn't make sense for picking. */
break;
- }
}
/* 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;
}
@@ -411,13 +480,10 @@ bool paintface_mouse_select(bContext *C,
void paintvert_flush_flags(Object *ob)
{
+ using namespace blender;
+ using namespace blender;
Mesh *me = BKE_mesh_from_object(ob);
Mesh *me_eval = BKE_object_get_evaluated_mesh(ob);
- MVert *mvert_eval, *mv;
- const int *index_array = nullptr;
- int totvert;
- int i;
-
if (me == nullptr) {
return;
}
@@ -430,27 +496,42 @@ void paintvert_flush_flags(Object *ob)
return;
}
- index_array = (const int *)CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
+ const bke::AttributeAccessor attributes_orig = me->attributes();
+ bke::MutableAttributeAccessor attributes_eval = me_eval->attributes_for_write();
- mvert_eval = me_eval->mvert;
- totvert = me_eval->totvert;
+ const int *orig_indices = (const int *)CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
- mv = mvert_eval;
-
- if (index_array) {
- int orig_index;
- for (i = 0; i < totvert; i++, mv++) {
- orig_index = index_array[i];
- if (orig_index != ORIGINDEX_NONE) {
- mv->flag = me->mvert[index_array[i]].flag;
+ const VArray<bool> hide_vert_orig = attributes_orig.lookup_or_default<bool>(
+ ".hide_vert", ATTR_DOMAIN_POINT, false);
+ bke::SpanAttributeWriter<bool> hide_vert_eval =
+ attributes_eval.lookup_or_add_for_write_only_span<bool>(".hide_vert", ATTR_DOMAIN_POINT);
+ if (orig_indices) {
+ for (const int i : hide_vert_eval.span.index_range()) {
+ if (orig_indices[i] != ORIGINDEX_NONE) {
+ hide_vert_eval.span[i] = hide_vert_orig[orig_indices[i]];
}
}
}
else {
- for (i = 0; i < totvert; i++, mv++) {
- mv->flag = me->mvert[i].flag;
+ hide_vert_orig.materialize(hide_vert_eval.span);
+ }
+ hide_vert_eval.finish();
+
+ const VArray<bool> select_vert_orig = attributes_orig.lookup_or_default<bool>(
+ ".select_vert", ATTR_DOMAIN_POINT, false);
+ bke::SpanAttributeWriter<bool> select_vert_eval =
+ attributes_eval.lookup_or_add_for_write_only_span<bool>(".select_vert", ATTR_DOMAIN_POINT);
+ if (orig_indices) {
+ for (const int i : select_vert_eval.span.index_range()) {
+ if (orig_indices[i] != ORIGINDEX_NONE) {
+ select_vert_eval.span[i] = select_vert_orig[orig_indices[i]];
+ }
}
}
+ else {
+ select_vert_orig.materialize(select_vert_eval.span);
+ }
+ select_vert_eval.finish();
BKE_mesh_batch_cache_dirty_tag(me, BKE_MESH_BATCH_DIRTY_ALL);
}
@@ -463,17 +544,23 @@ 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::MutableAttributeAccessor attributes = me->attributes_for_write();
+ const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
+ ".hide_vert", ATTR_DOMAIN_POINT, false);
+ bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_vert", ATTR_DOMAIN_POINT);
+
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_vert[i] && select_vert.span[i]) {
action = SEL_DESELECT;
break;
}
@@ -482,29 +569,28 @@ 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) {
- switch (action) {
- case SEL_SELECT:
- if ((mvert->flag & SELECT) == 0) {
- mvert->flag |= SELECT;
- changed = true;
- }
- break;
- case SEL_DESELECT:
- if ((mvert->flag & SELECT) != 0) {
- mvert->flag &= ~SELECT;
- changed = true;
- }
- break;
- case SEL_INVERT:
- mvert->flag ^= SELECT;
- changed = true;
- break;
- }
+ if (hide_vert[i]) {
+ continue;
+ }
+ const bool old_selection = select_vert.span[i];
+ switch (action) {
+ case SEL_SELECT:
+ select_vert.span[i] = true;
+ break;
+ case SEL_DESELECT:
+ select_vert.span[i] = false;
+ break;
+ case SEL_INVERT:
+ select_vert.span[i] = !select_vert.span[i];
+ break;
+ }
+ if (old_selection != select_vert.span[i]) {
+ changed = true;
}
}
+ select_vert.finish();
+
if (changed) {
/* handle mselect */
if (action == SEL_SELECT) {
@@ -526,9 +612,13 @@ 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) {
+ if (me == nullptr) {
+ return;
+ }
+ const Span<MDeformVert> dverts = me->deform_verts();
+ if (dverts.is_empty()) {
return;
}
@@ -536,17 +626,23 @@ void paintvert_select_ungrouped(Object *ob, bool extend, bool flush_flags)
paintvert_deselect_all_visible(ob, SEL_DESELECT, 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 (dv->dw == nullptr) {
+ bke::MutableAttributeAccessor attributes = me->attributes_for_write();
+ const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
+ ".hide_vert", ATTR_DOMAIN_POINT, false);
+ bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_vert", ATTR_DOMAIN_POINT);
+
+ for (const int i : select_vert.span.index_range()) {
+ if (!hide_vert[i]) {
+ if (dverts[i].dw == nullptr) {
/* if null weight then not grouped */
- mv->flag |= SELECT;
+ select_vert.span[i] = true;
}
}
}
+ select_vert.finish();
+
if (flush_flags) {
paintvert_flush_flags(ob);
}
@@ -554,25 +650,31 @@ 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 == NULL || me->totvert == 0) {
+ using namespace blender;
+ Mesh *me = BKE_mesh_from_object(ob);
+ if (me == nullptr || me->totvert == 0) {
return;
}
- for (int i = 0; i < me->totvert; i++) {
- MVert *const mvert = &me->mvert[i];
+ bke::MutableAttributeAccessor attributes = me->attributes_for_write();
+ bke::SpanAttributeWriter<bool> hide_vert = attributes.lookup_or_add_for_write_span<bool>(
+ ".hide_vert", ATTR_DOMAIN_POINT);
+ bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_vert", ATTR_DOMAIN_POINT);
- if ((mvert->flag & ME_HIDE) == 0) {
- if (((mvert->flag & SELECT) == 0) == unselected) {
- mvert->flag |= ME_HIDE;
+ for (const int i : hide_vert.span.index_range()) {
+ if (!hide_vert.span[i]) {
+ if (!select_vert.span[i] == unselected) {
+ hide_vert.span[i] = true;
}
}
- if (mvert->flag & ME_HIDE) {
- mvert->flag &= ~SELECT;
+ if (hide_vert.span[i]) {
+ select_vert.span[i] = false;
}
}
+ hide_vert.finish();
+ select_vert.finish();
BKE_mesh_flush_hidden_from_verts(me);
@@ -582,21 +684,29 @@ 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 == NULL || me->totvert == 0) {
+ using namespace blender;
+ Mesh *me = BKE_mesh_from_object(ob);
+ if (me == nullptr || me->totvert == 0) {
return;
}
- for (int i = 0; i < me->totvert; i++) {
- MVert *const mvert = &me->mvert[i];
+ bke::MutableAttributeAccessor attributes = me->attributes_for_write();
+ const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
+ ".hide_vert", ATTR_DOMAIN_POINT, false);
+ bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>(
+ ".select_vert", ATTR_DOMAIN_POINT);
- if (mvert->flag & ME_HIDE) {
- SET_FLAG_FROM_TEST(mvert->flag, select, SELECT);
- mvert->flag &= ~ME_HIDE;
+ for (const int i : select_vert.span.index_range()) {
+ if (hide_vert[i]) {
+ select_vert.span[i] = select;
}
}
+ select_vert.finish();
+
+ /* Remove the hide attribute to reveal all vertices. */
+ attributes.remove(".hide_vert");
+
BKE_mesh_flush_hidden_from_verts(me);
paintvert_flush_flags(ob);