[Bf-blender-cvs] [bcc37dd9604] refactor-mesh-selection-generic: Merge branch 'master' into refactor-mesh-selection-generic
Hans Goudey
noreply at git.blender.org
Wed Sep 21 18:59:44 CEST 2022
Commit: bcc37dd9604266434369ee0d0985e2b33910355d
Author: Hans Goudey
Date: Wed Sep 21 11:53:26 2022 -0500
Branches: refactor-mesh-selection-generic
https://developer.blender.org/rBbcc37dd9604266434369ee0d0985e2b33910355d
Merge branch 'master' into refactor-mesh-selection-generic
===================================================================
===================================================================
diff --cc source/blender/bmesh/intern/bmesh_mesh_convert.cc
index 7164b837451,aa8972f9d14..088b04b8351
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@@ -889,16 -891,33 +889,30 @@@ static void write_fn_to_attribute(blend
const GetFn &get_fn)
{
using namespace blender;
- if (do_write) {
- bke::SpanAttributeWriter<T> attribute = attributes.lookup_or_add_for_write_only_span<T>(
- attribute_name, domain);
- threading::parallel_for(attribute.span.index_range(), 4096, [&](IndexRange range) {
- for (const int i : range) {
- attribute.span[i] = get_fn(i);
- }
- });
- attribute.finish();
- }
- else {
- /* To avoid overhead, remove the hide attribute if possible. */
- attributes.remove(attribute_name);
- }
+ bke::SpanAttributeWriter<T> attribute = attributes.lookup_or_add_for_write_only_span<T>(
+ attribute_name, domain);
+ threading::parallel_for(attribute.span.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : range) {
+ attribute.span[i] = get_fn(i);
+ }
+ });
+ attribute.finish();
}
+ static void assert_bmesh_has_no_mesh_only_attributes(BMesh &bm)
+ {
+ (void)bm; /* Unused in the release builds. */
+
+ /* The "hide" attributes are stored as flags on #BMesh. */
+ BLI_assert(CustomData_get_layer_named(&bm.vdata, CD_PROP_BOOL, ".hide_vert") == nullptr);
+ BLI_assert(CustomData_get_layer_named(&bm.edata, CD_PROP_BOOL, ".hide_edge") == nullptr);
+ BLI_assert(CustomData_get_layer_named(&bm.pdata, CD_PROP_BOOL, ".hide_poly") == nullptr);
++ /* The "selection" attributes are stored as flags on #BMesh. */
++ BLI_assert(CustomData_get_layer_named(&bm.vdata, CD_PROP_BOOL, ".selection_vert") == nullptr);
++ BLI_assert(CustomData_get_layer_named(&bm.edata, CD_PROP_BOOL, ".selection_edge") == nullptr);
++ BLI_assert(CustomData_get_layer_named(&bm.pdata, CD_PROP_BOOL, ".selection_poly") == nullptr);
+ }
+
static void convert_bmesh_hide_flags_to_mesh_attributes(BMesh &bm,
const bool need_hide_vert,
const bool need_hide_edge,
@@@ -918,52 -935,18 +930,47 @@@
bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
BM_mesh_elem_table_ensure(&bm, BM_VERT | BM_EDGE | BM_FACE);
- write_fn_to_attribute<bool>(
- attributes, ".hide_vert", ATTR_DOMAIN_POINT, need_hide_vert, [&](const int i) {
- return BM_elem_flag_test(BM_vert_at_index(&bm, i), BM_ELEM_HIDDEN);
- });
- write_fn_to_attribute<bool>(
- attributes, ".hide_edge", ATTR_DOMAIN_EDGE, need_hide_edge, [&](const int i) {
- return BM_elem_flag_test(BM_edge_at_index(&bm, i), BM_ELEM_HIDDEN);
- });
- write_fn_to_attribute<bool>(
- attributes, ".hide_poly", ATTR_DOMAIN_FACE, need_hide_poly, [&](const int i) {
- return BM_elem_flag_test(BM_face_at_index(&bm, i), BM_ELEM_HIDDEN);
- });
+ write_fn_to_attribute<bool>(attributes, ".hide_vert", ATTR_DOMAIN_POINT, [&](const int i) {
+ return BM_elem_flag_test(BM_vert_at_index(&bm, i), BM_ELEM_HIDDEN);
+ });
+ write_fn_to_attribute<bool>(attributes, ".hide_edge", ATTR_DOMAIN_EDGE, [&](const int i) {
+ return BM_elem_flag_test(BM_edge_at_index(&bm, i), BM_ELEM_HIDDEN);
+ });
+ write_fn_to_attribute<bool>(attributes, ".hide_poly", ATTR_DOMAIN_FACE, [&](const int i) {
+ return BM_elem_flag_test(BM_face_at_index(&bm, i), BM_ELEM_HIDDEN);
+ });
+}
+
+static void convert_bmesh_selection_flags_to_mesh_attributes(BMesh &bm,
+ const bool need_selection_vert,
+ const bool need_selection_edge,
+ const bool need_selection_poly,
+ Mesh &mesh)
+{
+ using namespace blender;
- /* The "selection" attributes are stored as flags on #BMesh. */
- BLI_assert(CustomData_get_layer_named(&bm.vdata, CD_PROP_BOOL, ".selection_vert") == nullptr);
- BLI_assert(CustomData_get_layer_named(&bm.edata, CD_PROP_BOOL, ".selection_edge") == nullptr);
- BLI_assert(CustomData_get_layer_named(&bm.pdata, CD_PROP_BOOL, ".selection_poly") == nullptr);
-
+ if (!(need_selection_vert || need_selection_edge || need_selection_poly)) {
+ return;
+ }
+
+ bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
+ BM_mesh_elem_table_ensure(&bm, BM_VERT | BM_EDGE | BM_FACE);
+
+ if (need_selection_vert) {
+ write_fn_to_attribute<bool>(
+ attributes, ".selection_vert", ATTR_DOMAIN_POINT, [&](const int i) {
+ return BM_elem_flag_test(BM_vert_at_index(&bm, i), BM_ELEM_SELECT);
+ });
+ }
+ if (need_selection_edge) {
+ write_fn_to_attribute<bool>(attributes, ".selection_edge", ATTR_DOMAIN_EDGE, [&](const int i) {
+ return BM_elem_flag_test(BM_edge_at_index(&bm, i), BM_ELEM_SELECT);
+ });
+ }
+ if (need_selection_poly) {
+ write_fn_to_attribute<bool>(attributes, ".selection_poly", ATTR_DOMAIN_FACE, [&](const int i) {
+ return BM_elem_flag_test(BM_face_at_index(&bm, i), BM_ELEM_SELECT);
+ });
+ }
}
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
@@@ -1300,6 -1266,9 +1303,10 @@@ void BM_mesh_bm_to_me_for_eval(BMesh *b
me->runtime.deformed_only = true;
+ bke::MutableAttributeAccessor mesh_attributes = me->attributes_for_write();
+
+ bke::SpanAttributeWriter<bool> hide_vert_attribute;
++ bke::SpanAttributeWriter<bool> selection_vert_attribute;
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
MVert *mv = &mvert[i];
@@@ -1307,17 -1276,20 +1314,27 @@@
BM_elem_index_set(eve, i); /* set_inline */
- mv->flag = BM_vert_flag_to_mflag(eve);
if (BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
- need_hide_vert = true;
+ if (!hide_vert_attribute) {
+ hide_vert_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
+ ".hide_vert", ATTR_DOMAIN_POINT);
+ }
+ hide_vert_attribute.span[i] = true;
}
+ if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
- need_selection_vert = true;
++ if (!selection_vert_attribute) {
++ selection_vert_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
++ ".selection_vert", ATTR_DOMAIN_POINT);
++ }
++ selection_vert_attribute.span[i] = true;
+ }
CustomData_from_bmesh_block(&bm->vdata, &me->vdata, eve->head.data, i);
}
bm->elem_index_dirty &= ~BM_VERT;
+ bke::SpanAttributeWriter<bool> hide_edge_attribute;
++ bke::SpanAttributeWriter<bool> selection_edge_attribute;
BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
MEdge *med = &medge[i];
@@@ -1328,11 -1300,12 +1345,19 @@@
med->flag = BM_edge_flag_to_mflag(eed);
if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- need_hide_edge = true;
+ if (!hide_edge_attribute) {
+ hide_edge_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
+ ".hide_edge", ATTR_DOMAIN_EDGE);
+ }
+ hide_edge_attribute.span[i] = true;
}
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
- need_selection_edge = true;
++ if (!selection_edge_attribute) {
++ selection_edge_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
++ ".selection_edge", ATTR_DOMAIN_EDGE);
++ }
++ selection_edge_attribute.span[i] = true;
+ }
/* Handle this differently to editmode switching,
* only enable draw for single user edges rather than calculating angle. */
@@@ -1351,6 -1324,8 +1376,9 @@@
bm->elem_index_dirty &= ~BM_EDGE;
j = 0;
+ bke::SpanAttributeWriter<int> material_index_attribute;
+ bke::SpanAttributeWriter<bool> hide_poly_attribute;
++ bke::SpanAttributeWriter<bool> selection_poly_attribute;
BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
BMLoop *l_iter;
BMLoop *l_first;
@@@ -1361,11 -1336,12 +1389,19 @@@
mp->totloop = efa->len;
mp->flag = BM_face_flag_to_mflag(efa);
if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- need_hide_poly = true;
+ if (!hide_poly_attribute) {
+ hide_poly_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
+ ".hide_poly", ATTR_DOMAIN_FACE);
+ }
+ hide_poly_attribute.span[i] = true;
}
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
- need_selection_poly = true;
++ if (!selection_poly_attribute) {
++ selection_poly_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
++ ".selection_poly", ATTR_DOMAIN_FACE);
++ }
++ selection_poly_attribute.span[i] = true;
+ }
mp->loopstart = j;
if (efa->mat_nr != 0) {
@@@ -1388,18 -1368,21 +1428,30 @@@
}
bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP);
- if (need_material_index) {
- BM_mesh_elem_table_ensure(bm, BM_FACE);
- write_fn_to_attribute<int>(
- me->attributes_for_write(), "material_index", ATTR_DOMAIN_FACE, [&](const int i) {
- return static_cast<int>(BM_face_at_index(bm, i)->mat_nr);
- });
+ if (material_index_attribute) {
+ material_index_attribute.finish();
}
- convert_bmesh_hide_flags_to_mesh_attributes(
- *bm, need_hide_vert, need_hide_edge, need_hide_poly, *me);
- convert_bmesh_selection_flags_to_mesh_attributes(
- *bm, need_selection_vert, need_selection_edge, need_selection_poly, *me);
+ assert_bmesh_has_no_mesh_only_attributes(*bm);
+
+ if (hide_vert_attribute) {
+ hide_vert_attribute.finish();
+ }
+ if (hide_edge_attribute) {
+ hide_edge_attribute.finish();
+ }
+ if (hide_poly_attribute) {
+ hide_poly_attribute.finish();
+ }
++ if (selection_vert_attribute) {
++ selection_vert_attribute.finish();
++ }
++ if (selection_e
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list