diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-23 17:38:37 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-23 18:45:07 +0300 |
commit | 12becbf0dffe06b6f28c4cc444fe0312cf9249b9 (patch) | |
tree | fb7b54e30e9144021ba0714e0c2dd78eb8f5e928 /source/blender/editors/mesh/mesh_data.cc | |
parent | e345686cb7f4a8ccdc10e85d4f05cded45850cf7 (diff) |
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
Diffstat (limited to 'source/blender/editors/mesh/mesh_data.cc')
-rw-r--r-- | source/blender/editors/mesh/mesh_data.cc | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index 710cc6c88d9..dc3389844b8 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -1134,6 +1134,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, bool calc_edges, bool calc_edges_lo static void mesh_add_verts(Mesh *mesh, int len) { + using namespace blender; if (len == 0) { return; } @@ -1152,17 +1153,18 @@ static void mesh_add_verts(Mesh *mesh, int len) BKE_mesh_runtime_clear_cache(mesh); - const int old_vertex_num = mesh->totvert; mesh->totvert = totvert; - MutableSpan<MVert> verts = mesh->verts_for_write(); - for (MVert &vert : verts.drop_front(old_vertex_num)) { - vert.flag = SELECT; - } + bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); + bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>( + ".select_vert", ATTR_DOMAIN_POINT); + select_vert.span.take_back(len).fill(true); + select_vert.finish(); } static void mesh_add_edges(Mesh *mesh, int len) { + using namespace blender; CustomData edata; int totedge; @@ -1185,13 +1187,18 @@ static void mesh_add_edges(Mesh *mesh, int len) BKE_mesh_runtime_clear_cache(mesh); - const int old_edges_num = mesh->totedge; mesh->totedge = totedge; MutableSpan<MEdge> edges = mesh->edges_for_write(); - for (MEdge &edge : edges.drop_front(old_edges_num)) { - edge.flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT; + for (MEdge &edge : edges.take_back(len)) { + edge.flag = ME_EDGEDRAW | ME_EDGERENDER; } + + bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); + bke::SpanAttributeWriter<bool> select_edge = attributes.lookup_or_add_for_write_span<bool>( + ".select_edge", ATTR_DOMAIN_EDGE); + select_edge.span.take_back(len).fill(true); + select_edge.finish(); } static void mesh_add_loops(Mesh *mesh, int len) @@ -1223,6 +1230,7 @@ static void mesh_add_loops(Mesh *mesh, int len) static void mesh_add_polys(Mesh *mesh, int len) { + using namespace blender; CustomData pdata; int totpoly; @@ -1245,13 +1253,13 @@ static void mesh_add_polys(Mesh *mesh, int len) BKE_mesh_runtime_clear_cache(mesh); - const int old_polys_num = mesh->totpoly; mesh->totpoly = totpoly; - MutableSpan<MPoly> polys = mesh->polys_for_write(); - for (MPoly &poly : polys.drop_front(old_polys_num)) { - poly.flag = ME_FACE_SEL; - } + bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); + bke::SpanAttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write_span<bool>( + ".select_poly", ATTR_DOMAIN_FACE); + select_poly.span.take_back(len).fill(true); + select_poly.finish(); } /* -------------------------------------------------------------------- */ |