[Bf-blender-cvs] [f0e4307792c] refactor-mesh-selection-generic: Mesh: Move selection status from flags to generic attributes (WIP)
Hans Goudey
noreply at git.blender.org
Sun Aug 14 16:43:22 CEST 2022
Commit: f0e4307792c8a79b2f5700f0aeb792a56a3dd890
Author: Hans Goudey
Date: Sun Aug 14 10:43:18 2022 -0400
Branches: refactor-mesh-selection-generic
https://developer.blender.org/rBf0e4307792c8a79b2f5700f0aeb792a56a3dd890
Mesh: Move selection status from flags to generic attributes (WIP)
===================================================================
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/intern/mesh_evaluate.cc
M source/blender/editors/mesh/editface.cc
M source/blender/makesdna/DNA_meshdata_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index b9f6b4b73f3..0dcbf0284a7 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -867,16 +867,7 @@ void BKE_mesh_merge_customdata_for_apply_modifier(struct Mesh *me);
*/
void BKE_mesh_flush_hidden_from_verts(struct Mesh *me);
void BKE_mesh_flush_hidden_from_polys(struct Mesh *me);
-/**
- * simple poly -> vert/edge selection.
- */
-void BKE_mesh_flush_select_from_polys_ex(struct MVert *mvert,
- int totvert,
- const struct MLoop *mloop,
- struct MEdge *medge,
- int totedge,
- const struct MPoly *mpoly,
- int totpoly);
+
void BKE_mesh_flush_select_from_polys(struct Mesh *me);
void BKE_mesh_flush_select_from_verts(struct Mesh *me);
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.cc b/source/blender/blenkernel/intern/mesh_evaluate.cc
index 9dba8eab340..2a3a62731f3 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.cc
+++ b/source/blender/blenkernel/intern/mesh_evaluate.cc
@@ -820,98 +820,86 @@ void BKE_mesh_flush_hidden_from_polys(Mesh *me)
hide_edge.finish();
}
-void BKE_mesh_flush_select_from_polys_ex(MVert *mvert,
- const int totvert,
- const MLoop *mloop,
- MEdge *medge,
- const int totedge,
- const MPoly *mpoly,
- const int totpoly)
+void BKE_mesh_flush_select_from_polys(Mesh *me)
{
- MVert *mv;
- MEdge *med;
- const MPoly *mp;
-
- int i = totvert;
- for (mv = mvert; i--; mv++) {
- mv->flag &= (char)~SELECT;
+ using namespace blender::bke;
+ MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
+ const VArray<bool> selection_poly = attributes.lookup_or_default<bool>(
+ ".selection_poly", ATTR_DOMAIN_FACE, false);
+ if (selection_poly.is_single() && !selection_poly.get_internal_single()) {
+ attributes.remove(".selection_vert");
+ attributes.remove(".selection_edge");
+ return;
}
+ SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_only_span<bool>(
+ ".selection_vert", ATTR_DOMAIN_POINT);
+ SpanAttributeWriter<bool> selection_edge = attributes.lookup_or_add_for_write_only_span<bool>(
+ ".selection_edge", ATTR_DOMAIN_EDGE);
- i = totedge;
- for (med = medge; i--; med++) {
- med->flag &= ~SELECT;
- }
+ /* Use generic domain interpolation to read the polygon attribute on the other domains.
+ * Assume selected faces are not hidden and none of their verts/edges are hidden. */
+ attributes.lookup_or_default<bool>(".selection_poly", ATTR_DOMAIN_POINT, false)
+ .materialize(selection_vert.span);
+ attributes.lookup_or_default<bool>(".selection_poly", ATTR_DOMAIN_EDGE, false)
+ .materialize(selection_edge.span);
- i = totpoly;
- for (mp = mpoly; i--; mp++) {
- /* Assume if its selected its not hidden and none of its verts/edges are hidden
- * (a common assumption). */
- if (mp->flag & ME_FACE_SEL) {
- const MLoop *ml;
- int j;
- j = mp->totloop;
- for (ml = &mloop[mp->loopstart]; j--; ml++) {
- mvert[ml->v].flag |= SELECT;
- medge[ml->e].flag |= SELECT;
- }
- }
- }
-}
-void BKE_mesh_flush_select_from_polys(Mesh *me)
-{
- BKE_mesh_flush_select_from_polys_ex(
- me->mvert, me->totvert, me->mloop, me->medge, me->totedge, me->mpoly, me->totpoly);
+ selection_vert.finish();
+ selection_edge.finish();
}
-static void mesh_flush_select_from_verts(const Span<MVert> verts,
+static void mesh_flush_select_from_verts(const Span<MEdge> edges,
+ const Span<MPoly> polys,
const Span<MLoop> loops,
const VArray<bool> &hide_edge,
const VArray<bool> &hide_poly,
- MutableSpan<MEdge> edges,
- MutableSpan<MPoly> polys)
+ const VArray<bool> &selection_vert,
+ MutableSpan<bool> selection_edge,
+ MutableSpan<bool> selection_poly)
{
for (const int i : edges.index_range()) {
if (!hide_edge[i]) {
- MEdge &edge = edges[i];
- if ((verts[edge.v1].flag & SELECT) && (verts[edge.v2].flag & SELECT)) {
- edge.flag |= SELECT;
- }
- else {
- edge.flag &= ~SELECT;
- }
+ const MEdge &edge = edges[i];
+ selection_edge[i] = selection_vert[edge.v1] && selection_vert[edge.v2];
}
}
for (const int i : polys.index_range()) {
- if (hide_poly[i]) {
- continue;
- }
- MPoly &poly = polys[i];
- bool all_verts_selected = true;
- for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
- if (!(verts[loop.v].flag & SELECT)) {
- all_verts_selected = false;
- }
- }
- if (all_verts_selected) {
- poly.flag |= ME_FACE_SEL;
- }
- else {
- poly.flag &= (char)~ME_FACE_SEL;
+ if (!hide_poly[i]) {
+ const MPoly &poly = polys[i];
+ const Span<MLoop> poly_loops = loops.slice(poly.loopstart, poly.totloop);
+ selection_poly[i] = std::all_of(poly_loops.begin(),
+ poly_loops.end(),
+ [&](const MLoop &loop) { return selection_vert[loop.v]; });
}
}
}
void BKE_mesh_flush_select_from_verts(Mesh *me)
{
- const blender::bke::AttributeAccessor attributes = blender::bke::mesh_attributes(*me);
+ using namespace blender::bke;
+ MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
+ const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
+ ".selection_vert", ATTR_DOMAIN_POINT, false);
+ if (selection_vert.is_single() && !selection_vert.get_internal_single()) {
+ attributes.remove(".selection_edge");
+ attributes.remove(".selection_poly");
+ return;
+ }
+ SpanAttributeWriter<bool> selection_edge = attributes.lookup_or_add_for_write_only_span<bool>(
+ ".selection_edge", ATTR_DOMAIN_EDGE);
+ SpanAttributeWriter<bool> selection_poly = attributes.lookup_or_add_for_write_only_span<bool>(
+ ".selection_poly", ATTR_DOMAIN_FACE);
mesh_flush_select_from_verts(
- {me->mvert, me->totvert},
+ {me->medge, me->totedge},
+ {me->mpoly, me->totpoly},
{me->mloop, me->totloop},
attributes.lookup_or_default<bool>(".hide_edge", ATTR_DOMAIN_EDGE, false),
attributes.lookup_or_default<bool>(".hide_poly", ATTR_DOMAIN_FACE, false),
- {me->medge, me->totedge},
- {me->mpoly, me->totpoly});
+ selection_vert,
+ selection_edge.span,
+ selection_poly.span);
+ selection_edge.finish();
+ selection_poly.finish();
}
/** \} */
diff --git a/source/blender/editors/mesh/editface.cc b/source/blender/editors/mesh/editface.cc
index c55d96bac55..26144bba4b1 100644
--- a/source/blender/editors/mesh/editface.cc
+++ b/source/blender/editors/mesh/editface.cc
@@ -44,9 +44,7 @@ void paintface_flush_flags(bContext *C,
{
using namespace blender;
Mesh *me = BKE_mesh_from_object(ob);
- MPoly *polys, *mp_orig;
const int *index_array = nullptr;
- int totpoly;
BLI_assert(flush_selection || flush_hidden);
@@ -78,9 +76,6 @@ void paintface_flush_flags(bContext *C,
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);
@@ -89,31 +84,46 @@ void paintface_flush_flags(bContext *C,
hide_poly_me.materialize(hide_poly_orig.span);
hide_poly_orig.finish();
}
+ if (flush_selection) {
+ const VArray<bool> selection_poly_me = attributes_me.lookup_or_default<bool>(
+ ".selection_poly", ATTR_DOMAIN_FACE, false);
+ bke::SpanAttributeWriter<bool> selection_poly_orig =
+ attributes_orig.lookup_or_add_for_write_only_span<bool>(".selection_poly",
+ ATTR_DOMAIN_FACE);
+ selection_poly_me.materialize(selection_poly_orig.span);
+ selection_poly_orig.finish();
+ }
/* Mesh polys => Final derived polys */
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 (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();
}
- const VArray<bool> hide_poly_orig = attributes_orig.lookup_or_default<bool>(
- ".hide_poly", ATTR_DOMAIN_FACE, false);
- bke::
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list