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

Hans Goudey noreply at git.blender.org
Wed Sep 7 20:44:41 CEST 2022


Commit: 36b4b3b4d2d1c9260056afe7ec62c6b9a320be72
Author: Hans Goudey
Date:   Wed Sep 7 13:26:54 2022 -0500
Branches: refactor-mesh-selection-generic
https://developer.blender.org/rB36b4b3b4d2d1c9260056afe7ec62c6b9a320be72

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

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



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

diff --cc source/blender/blenkernel/intern/mesh.cc
index 94ab38573f9,1bf068fcd45..5a9411ed0a2
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@@ -248,21 -249,16 +249,21 @@@ static void mesh_blend_write(BlendWrite
    else {
      Set<std::string> names_to_skip;
      if (!BLO_write_is_undo(writer)) {
+ 
        BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
-       BKE_mesh_legacy_convert_selection_layers_to_flags(mesh);
        BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
        /* When converting to the old mesh format, don't save redundant attributes. */
 -      names_to_skip.add_multiple_new({".hide_vert", ".hide_edge", ".hide_poly"});
 +      names_to_skip.add_multiple_new({".hide_vert",
 +                                      ".hide_edge",
 +                                      ".hide_poly",
 +                                      ".selection_vert",
 +                                      ".selection_edge",
 +                                      ".selection_poly"});
  
        /* Set deprecated mesh data pointers for forward compatibility. */
-       mesh->mvert = const_cast<MVert *>(mesh->vertices().data());
+       mesh->mvert = const_cast<MVert *>(mesh->verts().data());
        mesh->medge = const_cast<MEdge *>(mesh->edges().data());
-       mesh->mpoly = const_cast<MPoly *>(mesh->polygons().data());
+       mesh->mpoly = const_cast<MPoly *>(mesh->polys().data());
        mesh->mloop = const_cast<MLoop *>(mesh->loops().data());
      }
  
@@@ -348,8 -344,7 +349,8 @@@ static void mesh_blend_read_data(BlendD
    }
  
    if (!BLO_read_data_is_undo(reader)) {
-     BKE_mesh_legacy_convert_flags_to_hide_layers(mesh);
 +    BKE_mesh_legacy_convert_flags_to_selection_layers(mesh);
+     BKE_mesh_legacy_convert_flags_to_hide_layers(mesh);
      BKE_mesh_legacy_convert_mpoly_to_material_indices(mesh);
    }
  
diff --cc source/blender/blenkernel/intern/mesh_evaluate.cc
index cbef8e1cd64,f2fe2e0b141..299a9a70287
--- a/source/blender/blenkernel/intern/mesh_evaluate.cc
+++ b/source/blender/blenkernel/intern/mesh_evaluate.cc
@@@ -876,22 -907,9 +876,22 @@@ static void mesh_flush_select_from_vert
  
  void BKE_mesh_flush_select_from_verts(Mesh *me)
  {
 -  const blender::bke::AttributeAccessor attributes = blender::bke::mesh_attributes(*me);
 +  using namespace blender::bke;
 +  MutableAttributeAccessor attributes = mesh_attributes_for_write(*me);
 +  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->polygons(),
++      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 9c89e4c17f9,39b1ffb7cf4..6644bc566c5
--- 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);
 +
-   MutableSpan<MVert> verts = mesh->vertices_for_write();
++  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->polygons_for_write();
++  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);
 +
-   const Span<MVert> verts = mesh->vertices();
++  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_only_span<bool>(
 +        ".selection_edge", ATTR_DOMAIN_EDGE);
 +    threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
 +      for (const int i : range) {
 +        selection_edge.span[i] = edges[i].flag & SELECT;
 +      }
 +    });
 +    selection_edge.finish();
 +  }
 +
-   const Span<MPoly> polys = mesh->polygons();
++  const Span<MPoly> polys = mesh->polys();
 +  if (std::any_of(
 +          polys.begin(), polys.end(), [](const MPoly &poly) { return poly.flag & ME_FACE_SEL; })) {
 +    SpanAttributeWriter<bool> selection_poly = attributes.lookup_or_add_for_write_only_span<bool>(
 +        ".selection_poly", ATTR_DOMAIN_FACE);
 +    threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
 +      for (const int i : range) {
 +        selection_poly.span[i] = polys[i].flag & ME_FACE_SEL;
 +      }
 +    });
 +    selection_poly.finish();
 +  }
 +}
 +
 +/** \} */
diff --cc source/blender/bmesh/intern/bmesh_mesh_convert.cc
index 362db2b2923,fe9369fd652..94593b664e9
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@@ -959,56 -968,18 +959,52 @@@ 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);
  
--  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 = 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_ELE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list