[Bf-blender-cvs] [6299969dd22] refactor-mesh-selection-generic: Merge branch 'master' into refactor-mesh-selection-generic
Hans Goudey
noreply at git.blender.org
Wed Sep 7 06:46:10 CEST 2022
Commit: 6299969dd220016c16ecd4de5281a3b387c11b33
Author: Hans Goudey
Date: Tue Sep 6 23:42:55 2022 -0500
Branches: refactor-mesh-selection-generic
https://developer.blender.org/rB6299969dd220016c16ecd4de5281a3b387c11b33
Merge branch 'master' into refactor-mesh-selection-generic
===================================================================
===================================================================
diff --cc source/blender/bmesh/intern/bmesh_mesh_convert.cc
index 555c60f710d,257134e7661..362db2b2923
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@@ -959,59 -968,19 +959,57 @@@ static void convert_bmesh_hide_flags_to
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(mesh);
BM_mesh_elem_table_ensure(&bm, BM_VERT | BM_EDGE | BM_FACE);
- if (need_hide_vert) {
- 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);
- });
- }
- if (need_hide_edge) {
- 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);
- });
- }
- if (need_hide_poly) {
- 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);
- });
- }
+ 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);
+ });
+ }
+}
+
+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 = bke::mesh_attributes_for_write(mesh);
+ 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)
{
@@@ -1055,23 -1023,31 +1052,34 @@@
CustomData_copy_mesh_to_bmesh(&bm->pdata, &me->pdata, mask.pmask, CD_SET_DEFAULT, me->totpoly);
}
- MVert *mvert = bm->totvert ? (MVert *)MEM_callocN(sizeof(MVert) * bm->totvert, "bm_to_me.vert") :
- nullptr;
- MEdge *medge = bm->totedge ? (MEdge *)MEM_callocN(sizeof(MEdge) * bm->totedge, "bm_to_me.edge") :
- nullptr;
- MLoop *mloop = bm->totloop ? (MLoop *)MEM_callocN(sizeof(MLoop) * bm->totloop, "bm_to_me.loop") :
- nullptr;
- MPoly *mpoly = bm->totface ? (MPoly *)MEM_callocN(sizeof(MPoly) * bm->totface, "bm_to_me.poly") :
- nullptr;
-
- CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert);
- CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge);
- CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, mloop, me->totloop);
- CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, mpoly, me->totpoly);
+ MutableSpan<MVert> mvert;
+ MutableSpan<MEdge> medge;
+ MutableSpan<MPoly> mpoly;
+ MutableSpan<MLoop> mloop;
+ if (me->totvert > 0) {
+ mvert = {static_cast<MVert *>(
+ CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, me->totvert)),
+ me->totvert};
+ }
+ if (me->totedge > 0) {
+ medge = {static_cast<MEdge *>(
+ CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, me->totedge)),
+ me->totedge};
+ }
+ if (me->totpoly > 0) {
+ mpoly = {static_cast<MPoly *>(
+ CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, me->totpoly)),
+ me->totpoly};
+ }
+ if (me->totloop > 0) {
+ mloop = {static_cast<MLoop *>(
+ CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, me->totloop)),
+ me->totloop};
+ }
+ bool need_selection_vert = false;
+ bool need_selection_edge = false;
+ bool need_selection_poly = false;
bool need_hide_vert = false;
bool need_hide_edge = false;
bool need_hide_poly = false;
@@@ -1085,8 -1061,9 +1093,8 @@@
i = 0;
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
- copy_v3_v3(mvert->co, v->co);
+ copy_v3_v3(mvert[i].co, v->co);
- mvert[i].flag = BM_vert_flag_to_mflag(v);
if (BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
need_hide_vert = true;
}
diff --cc source/blender/editors/object/object_vgroup.cc
index b6be0b03e2a,19c26edfb05..7ed03386959
--- a/source/blender/editors/object/object_vgroup.cc
+++ b/source/blender/editors/object/object_vgroup.cc
@@@ -1969,8 -1954,8 +1969,8 @@@ static void vgroup_smooth_subset(Objec
&me->vdata, CD_PROP_BOOL, ".hide_vert") :
nullptr;
- #define IS_ME_VERT_READ(v) (use_hide ? (hide_vert && hide_vert[v]) : true)
+ #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)
+#define IS_ME_VERT_WRITE(v) (use_select ? selection_vert[v] : true)
/* initialize used verts */
if (bm) {
More information about the Bf-blender-cvs
mailing list