diff options
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_legacy_convert.cc')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_legacy_convert.cc | 98 |
1 files changed, 94 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc index 09982f15afa..506501ead2a 100644 --- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc @@ -13,6 +13,7 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" +#include "DNA_object_types.h" #include "BLI_edgehash.h" #include "BLI_math.h" @@ -1058,7 +1059,7 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(Mesh *mesh) ".hide_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, hide_vert[i], ME_HIDE); + SET_FLAG_FROM_TEST(verts[i].flag_legacy, hide_vert[i], ME_HIDE); } }); @@ -1088,13 +1089,14 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *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 & ME_HIDE; })) { + if (std::any_of(verts.begin(), verts.end(), [](const MVert &vert) { + return vert.flag_legacy & ME_HIDE; + })) { SpanAttributeWriter<bool> hide_vert = attributes.lookup_or_add_for_write_only_span<bool>( ".hide_vert", ATTR_DOMAIN_POINT); threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) { for (const int i : range) { - hide_vert.span[i] = verts[i].flag & ME_HIDE; + hide_vert.span[i] = verts[i].flag_legacy & ME_HIDE; } }); hide_vert.finish(); @@ -1128,6 +1130,7 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh) } /** \} */ + /* -------------------------------------------------------------------- */ /** \name Material Index Conversion * \{ */ @@ -1167,3 +1170,90 @@ void BKE_mesh_legacy_convert_mpoly_to_material_indices(Mesh *mesh) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \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(); + + MutableSpan<MVert> verts = mesh->verts_for_write(); + const VArray<bool> select_vert = attributes.lookup_or_default<bool>( + ".select_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_legacy, select_vert[i], SELECT); + } + }); + + MutableSpan<MEdge> edges = mesh->edges_for_write(); + const VArray<bool> select_edge = attributes.lookup_or_default<bool>( + ".select_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, select_edge[i], SELECT); + } + }); + + MutableSpan<MPoly> polys = mesh->polys_for_write(); + const VArray<bool> select_poly = attributes.lookup_or_default<bool>( + ".select_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, select_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(); + + const Span<MVert> verts = mesh->verts(); + if (std::any_of(verts.begin(), verts.end(), [](const MVert &vert) { + return vert.flag_legacy & SELECT; + })) { + SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_only_span<bool>( + ".select_vert", ATTR_DOMAIN_POINT); + threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) { + for (const int i : range) { + select_vert.span[i] = (verts[i].flag_legacy & SELECT) != 0; + } + }); + select_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> select_edge = attributes.lookup_or_add_for_write_only_span<bool>( + ".select_edge", ATTR_DOMAIN_EDGE); + threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) { + for (const int i : range) { + select_edge.span[i] = (edges[i].flag & SELECT) != 0; + } + }); + select_edge.finish(); + } + + 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> select_poly = attributes.lookup_or_add_for_write_only_span<bool>( + ".select_poly", ATTR_DOMAIN_FACE); + threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) { + for (const int i : range) { + select_poly.span[i] = (polys[i].flag & ME_FACE_SEL) != 0; + } + }); + select_poly.finish(); + } +} + +/** \} */ |