From 12becbf0dffe06b6f28c4cc444fe0312cf9249b9 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 23 Sep 2022 09:38:37 -0500 Subject: Mesh: Move selection flags to generic attributes Using the attribute name semantics from T97452, this patch moves the selection status of mesh elements from the `SELECT` of vertices, and edges, and the `ME_FACE_SEL` of faces to generic boolean attribute Storing this data as generic attributes can significantly simplify and improve code, as described in T95965. The attributes are called `.select_vert`, `.select_edge`, and `.select_poly`. The `.` prefix means they are "UI attributes",so they still contain original data edited by users, but they aren't meant to be accessed procedurally by the user in arbitrary situations. They are also be hidden in the spreadsheet and the attribute list. Until 4.0, the attributes are still written to and read from the mesh in the old way, so neither forward nor backward compatibility are affected. This means memory requirements will be increased by one byte per element when selection is used. When the flags are removed completely, requirements will decrease. Further notes: * The `MVert` flag is empty at runtime now, so it can be ignored. * `BMesh` is unchanged, otherwise the change would be much larger. * Many tests have slightly different results, since the selection attribute uses more generic propagation. Previously you couldn't really rely on edit mode selections being propagated procedurally. Now it mostly works as expected. Similar to 2480b55f216c Ref T95965 Differential Revision: https://developer.blender.org/D15795 --- .../blender/editors/armature/armature_skinning.c | 7 +++++-- source/blender/editors/armature/meshlaplacian.c | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'source/blender/editors/armature') diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index e39cc157c19..6155aac621d 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -203,10 +203,13 @@ static void envelope_bone_weighting(Object *ob, use_mask = true; } + const bool *select_vert = (const bool *)CustomData_get_layer_named( + &mesh->vdata, CD_PROP_BOOL, ".select_vert"); + /* for each vertex in the mesh */ - const MVert *mesh_verts = BKE_mesh_verts(mesh); for (int i = 0; i < mesh->totvert; i++) { - if (use_mask && !(mesh_verts[i].flag & SELECT)) { + + if (use_mask && !(select_vert && select_vert[i])) { continue; } diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 904e6213466..567977e51c4 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -669,17 +669,25 @@ void heat_bone_weighting(Object *ob, /* (added selectedVerts content for vertex mask, they used to just equal 1) */ if (use_vert_sel) { - for (a = 0, mp = polys; a < me->totpoly; mp++, a++) { - for (j = 0, ml = loops + mp->loopstart; j < mp->totloop; j++, ml++) { - mask[ml->v] = (mesh_verts[ml->v].flag & SELECT) != 0; + const bool *select_vert = (const bool *)CustomData_get_layer_named( + &me->vdata, CD_PROP_BOOL, ".select_vert"); + if (select_vert) { + for (a = 0, mp = polys; a < me->totpoly; mp++, a++) { + for (j = 0, ml = loops + mp->loopstart; j < mp->totloop; j++, ml++) { + mask[ml->v] = select_vert[ml->v]; + } } } } else if (use_face_sel) { - for (a = 0, mp = polys; a < me->totpoly; mp++, a++) { - if (mp->flag & ME_FACE_SEL) { - for (j = 0, ml = loops + mp->loopstart; j < mp->totloop; j++, ml++) { - mask[ml->v] = 1; + const bool *select_poly = (const bool *)CustomData_get_layer_named( + &me->pdata, CD_PROP_BOOL, ".select_poly"); + if (select_poly) { + for (a = 0, mp = polys; a < me->totpoly; mp++, a++) { + if (select_poly[a]) { + for (j = 0, ml = loops + mp->loopstart; j < mp->totloop; j++, ml++) { + mask[ml->v] = 1; + } } } } -- cgit v1.2.3