[Bf-blender-cvs] [87dfabc5453] refactor-mesh-selection-generic: Merge branch 'master' into refactor-mesh-selection-generic

Hans Goudey noreply at git.blender.org
Thu Sep 8 06:11:47 CEST 2022


Commit: 87dfabc5453bec97bfe5b4f0f56890ea5f528bb8
Author: Hans Goudey
Date:   Wed Sep 7 21:58:37 2022 -0500
Branches: refactor-mesh-selection-generic
https://developer.blender.org/rB87dfabc5453bec97bfe5b4f0f56890ea5f528bb8

Merge branch 'master' into refactor-mesh-selection-generic

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/mesh.cc
index 5a9411ed0a2,6b99085ea28..6644a149c89
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@@ -1662,14 -1659,6 +1664,14 @@@ void BKE_mesh_mselect_validate(Mesh *me
    mselect_dst = (MSelect *)MEM_malloc_arrayN(
        (me->totselect), sizeof(MSelect), "Mesh selection history");
  
-   const AttributeAccessor attributes = mesh_attributes(*me);
++  const AttributeAccessor attributes = me->attributes();
 +  const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
 +      ".selection_vert", ATTR_DOMAIN_POINT, false);
 +  const VArray<bool> selection_edge = attributes.lookup_or_default<bool>(
 +      ".selection_edge", ATTR_DOMAIN_EDGE, false);
 +  const VArray<bool> selection_poly = attributes.lookup_or_default<bool>(
 +      ".selection_poly", ATTR_DOMAIN_FACE, false);
 +
    for (i_src = 0, i_dst = 0; i_src < me->totselect; i_src++) {
      int index = mselect_src[i_src].index;
      switch (mselect_src[i_src].type) {
diff --cc source/blender/blenkernel/intern/mesh_calc_edges.cc
index 3f1c9acf1e5,cc315130ad1..6d76bea4502
--- a/source/blender/blenkernel/intern/mesh_calc_edges.cc
+++ b/source/blender/blenkernel/intern/mesh_calc_edges.cc
@@@ -155,23 -153,6 +155,23 @@@ static void serialize_and_initialize_de
        new_edge_index++;
      }
    });
 +
 +  if (select_new_edges) {
 +    SpanAttributeWriter<bool> selection_edge =
-         mesh_attributes_for_write(mesh).lookup_or_add_for_write_span<bool>(".selection_edge",
-                                                                            ATTR_DOMAIN_EDGE);
++        mesh.attributes_for_write().lookup_or_add_for_write_span<bool>(".selection_edge",
++                                                                       ATTR_DOMAIN_EDGE);
 +    threading::parallel_for_each(edge_maps, [&](EdgeMap &edge_map) {
 +      const int task_index = &edge_map - edge_maps.data();
 +      int new_edge_index = edge_index_offsets[task_index];
 +      for (EdgeMap::MutableItem item : edge_map.items()) {
 +        if (item.value.original_edge == nullptr) {
 +          selection_edge.span[new_edge_index] = true;
 +        }
 +        new_edge_index++;
 +      }
 +    });
 +    selection_edge.finish();
 +  }
  }
  
  static void update_edge_indices_in_poly_loops(Mesh *mesh,
diff --cc source/blender/blenkernel/intern/mesh_evaluate.cc
index 299a9a70287,938d7e42aa3..15ea5357dee
--- a/source/blender/blenkernel/intern/mesh_evaluate.cc
+++ b/source/blender/blenkernel/intern/mesh_evaluate.cc
@@@ -818,35 -818,55 +818,35 @@@ void BKE_mesh_flush_hidden_from_polys(M
    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);
++  MutableAttributeAccessor attributes = me->attributes_for_write();
 +  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 vertices/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->verts_for_write().data(),
 -                                      me->totvert,
 -                                      me->loops().data(),
 -                                      me->edges_for_write().data(),
 -                                      me->totedge,
 -                                      me->polys().data(),
 -                                      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,
@@@ -876,22 -907,9 +876,22 @@@
  
  void BKE_mesh_flush_select_from_verts(Mesh *me)
  {
 -  const blender::bke::AttributeAccessor attributes = me->attributes();
 +  using namespace blender::bke;
-   MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
++  MutableAttributeAccessor attributes = me->attributes_for_write();
 +  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->verts(),
 +      me->edges(),
 +      me->polys(),
        me->loops(),
        attributes.lookup_or_default<bool>(".hide_edge", ATTR_DOMAIN_EDGE, false),
        attributes.lookup_or_default<bool>(".hide_poly", ATTR_DOMAIN_FACE, false),
diff --cc source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 6644bc566c5,2f67e303095..9d3212ff010
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@@ -1043,89 -1041,3 +1043,89 @@@ void BKE_mesh_legacy_convert_mpoly_to_m
  }
  
  /** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Selection Attribute and Legacy Flag Conversion
 + * \{ */
 +
 +void BKE_mesh_legacy_convert_selection_layers_to_flags(Mesh *mesh)
 +{
 +  using namespace blender;
 +  using namespace blender::bke;
-   const AttributeAccessor attributes = mesh_attributes(*mesh);
++  const AttributeAccessor attributes = mesh->attributes();
 +
 +  MutableSpan<MVert> verts = mesh->verts_for_write();
 +  const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
 +      ".selection_vert", ATTR_DOMAIN_POINT, false);
 +  threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
 +    for (const int i : range) {
 +      SET_FLAG_FROM_TEST(verts[i].flag, selection_vert[i], SELECT);
 +    }
 +  });
 +
 +  MutableSpan<MEdge> edges = mesh->edges_for_write();
 +  const VArray<bool> selection_edge = attributes.lookup_or_default<bool>(
 +      ".selection_edge", ATTR_DOMAIN_EDGE, false);
 +  threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
 +    for (const int i : range) {
 +      SET_FLAG_FROM_TEST(edges[i].flag, selection_edge[i], SELECT);
 +    }
 +  });
 +
 +  MutableSpan<MPoly> polys = mesh->polys_for_write();
 +  const VArray<bool> selection_poly = attributes.lookup_or_default<bool>(
 +      ".selection_poly", ATTR_DOMAIN_FACE, false);
 +  threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
 +    for (const int i : range) {
 +      SET_FLAG_FROM_TEST(polys[i].flag, selection_poly[i], ME_FACE_SEL);
 +    }
 +  });
 +}
 +
 +void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
 +{
 +  using namespace blender;
 +  using namespace blender::bke;
-   MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh);
++  MutableAttributeAccessor attributes = mesh->attributes_for_write();
 +
 +  const Span<MVert> verts = mesh->verts();
 +  if (std::any_of(
 +          verts.begin(), verts.end(), [](const MVert &vert) { return vert.flag & SELECT; })) {
 +    SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_only_span<bool>(
 +        ".selection_vert", ATTR_DOMAIN_POINT);
 +    threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
 +      for (const int i : range) {
 +        selection_vert.span[i] = verts[i].flag & SELECT;
 +      }
 +    });
 +    selection_vert.finish();
 +  }
 +
 +  const Span<MEdge> edges = mesh->edges();
 +  if (std::any_of(
 +          edges.begin(), edges.end(), [](const MEdge &edge) { return edge.flag & SELECT; })) {
 +    SpanAttributeWriter<bool> selection_edge = attributes.lookup_or_add_for_write_on

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list