[Bf-blender-cvs] [b59f40972be] refactor-mesh-position-generic: Merge branch 'refactor-mesh-selection-generic' into refactor-mesh-position-generic

Hans Goudey noreply at git.blender.org
Fri Sep 23 20:27:35 CEST 2022


Commit: b59f40972be45b4009ee1069e3e9d8c216a3e00c
Author: Hans Goudey
Date:   Fri Sep 23 11:10:21 2022 -0500
Branches: refactor-mesh-position-generic
https://developer.blender.org/rBb59f40972be45b4009ee1069e3e9d8c216a3e00c

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

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



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

diff --cc source/blender/blenkernel/intern/customdata.cc
index 7033d82efbb,51c3b405ebc..6a3f254a436
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@@ -2125,13 -2120,13 +2123,13 @@@ const CustomData_MeshMasks CD_MASK_BARE
      /* lmask */ CD_MASK_MLOOP,
  };
  const CustomData_MeshMasks CD_MASK_MESH = {
-     /* vmask */ (CD_MASK_PROP_FLOAT3 | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN |
-                  CD_MASK_PAINT_MASK | CD_MASK_PROP_ALL | CD_MASK_CREASE | CD_MASK_BWEIGHT),
-     /* emask */ (CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL | CD_MASK_BWEIGHT),
 -    /* vmask */ (CD_MASK_MVERT | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PAINT_MASK |
++    /* vmask */ (CD_MASK_PROP_FLOAT3 | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PAINT_MASK |
+                  CD_MASK_PROP_ALL | CD_MASK_CREASE | CD_MASK_BWEIGHT),
+     /* emask */
+     (CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL | CD_MASK_BWEIGHT | CD_MASK_CREASE),
      /* fmask */ 0,
      /* pmask */
-     (CD_MASK_MPOLY | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL |
-      CD_MASK_SCULPT_FACE_SETS),
+     (CD_MASK_MPOLY | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL),
      /* lmask */
      (CD_MASK_MLOOP | CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_CUSTOMLOOPNORMAL |
       CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL),
diff --cc source/blender/blenkernel/intern/mesh.cc
index 90b54e8a8a2,6df6cd31cf4..2d27d185cd9
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@@ -259,18 -259,12 +257,20 @@@ static void mesh_blend_write(BlendWrite
                                        ".hide_edge",
                                        ".hide_poly",
                                        "material_index",
-                                       ".selection_vert",
-                                       ".selection_edge",
-                                       ".selection_poly"});
+                                       ".select_vert",
+                                       ".select_edge",
+                                       ".select_poly"});
  
 +      mesh->mvert = BKE_mesh_legacy_convert_positions_to_verts(
 +          mesh, temp_arrays_for_legacy_format, vert_layers);
 +      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);
 +      BKE_mesh_legacy_bevel_weight_from_layers(mesh);
++      BKE_mesh_legacy_face_set_from_generic(mesh);
++      BKE_mesh_legacy_edge_crease_from_layers(mesh);
 +
        /* Set deprecated mesh data pointers for forward compatibility. */
 -      mesh->mvert = const_cast<MVert *>(mesh->verts().data());
        mesh->medge = const_cast<MEdge *>(mesh->edges().data());
        mesh->mpoly = const_cast<MPoly *>(mesh->polys().data());
        mesh->mloop = const_cast<MLoop *>(mesh->loops().data());
diff --cc source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 3b44a2050eb,60014545f49..795dc693738
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@@ -1028,9 -1088,10 +1093,10 @@@ void BKE_mesh_legacy_convert_flags_to_h
    using namespace blender::bke;
    MutableAttributeAccessor attributes = mesh->attributes_for_write();
  
 -  const Span<MVert> verts = mesh->verts();
 +  const Span<MVert> verts(mesh->mvert, mesh->totvert);
-   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) {
@@@ -1120,12 -1181,12 +1186,12 @@@ void BKE_mesh_legacy_convert_selection_
    using namespace blender::bke;
    const AttributeAccessor attributes = mesh->attributes();
  
 -  MutableSpan<MVert> verts = mesh->verts_for_write();
 +  MutableSpan<MVert> verts(mesh->mvert, mesh->totvert);
-   const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
-       ".selection_vert", ATTR_DOMAIN_POINT, false);
+   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, selection_vert[i], SELECT);
+       SET_FLAG_FROM_TEST(verts[i].flag_legacy, select_vert[i], SELECT);
      }
    });
  
@@@ -1154,17 -1215,18 +1220,18 @@@ void BKE_mesh_legacy_convert_flags_to_s
    using namespace blender::bke;
    MutableAttributeAccessor attributes = mesh->attributes_for_write();
  
 -  const Span<MVert> verts = mesh->verts();
 +  const Span<MVert> verts(mesh->mvert, mesh->totvert);
-   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);
+   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) {
-         selection_vert.span[i] = verts[i].flag & SELECT;
+         select_vert.span[i] = verts[i].flag_legacy & SELECT;
        }
      });
-     selection_vert.finish();
+     select_vert.finish();
    }
  
    const Span<MEdge> edges = mesh->edges();
diff --cc source/blender/blenkernel/intern/mesh_remesh_voxel.cc
index 490c0be96c6,12f42dbc4ec..26b14d26de9
--- a/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
+++ b/source/blender/blenkernel/intern/mesh_remesh_voxel.cc
@@@ -310,24 -319,28 +311,28 @@@ void BKE_mesh_remesh_reproject_paint_ma
  
  void BKE_remesh_reproject_sculpt_face_sets(Mesh *target, const Mesh *source)
  {
+   using namespace blender;
+   using namespace blender::bke;
+   const AttributeAccessor src_attributes = source->attributes();
+   MutableAttributeAccessor dst_attributes = target->attributes_for_write();
    const MPoly *target_polys = (const MPoly *)CustomData_get_layer(&target->pdata, CD_MPOLY);
 -  const MVert *target_verts = (const MVert *)CustomData_get_layer(&target->vdata, CD_MVERT);
 +  const Span<float3> target_positions = target->positions();
    const MLoop *target_loops = (const MLoop *)CustomData_get_layer(&target->ldata, CD_MLOOP);
-   const int *source_face_sets = (const int *)CustomData_get_layer(&source->pdata,
-                                                                   CD_SCULPT_FACE_SETS);
-   if (source_face_sets == nullptr) {
-     return;
-   }
  
-   int *target_face_sets;
-   if (CustomData_has_layer(&target->pdata, CD_SCULPT_FACE_SETS)) {
-     target_face_sets = (int *)CustomData_get_layer(&target->pdata, CD_SCULPT_FACE_SETS);
+   const VArray<int> src_face_sets = src_attributes.lookup<int>(".sculpt_face_set",
+                                                                ATTR_DOMAIN_FACE);
+   if (!src_face_sets) {
+     return;
    }
-   else {
-     target_face_sets = (int *)CustomData_add_layer(
-         &target->pdata, CD_SCULPT_FACE_SETS, CD_CONSTRUCT, nullptr, target->totpoly);
+   SpanAttributeWriter<int> dst_face_sets = dst_attributes.lookup_or_add_for_write_only_span<int>(
+       ".sculpt_face_set", ATTR_DOMAIN_FACE);
+   if (!dst_face_sets) {
+     return;
    }
  
+   const VArraySpan<int> src(src_face_sets);
+   MutableSpan<int> dst = dst_face_sets.span;
+ 
    const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(source);
    BVHTreeFromMesh bvhtree = {nullptr};
    BKE_bvhtree_from_mesh_get(&bvhtree, source, BVHTREE_FROM_LOOPTRI, 2);
@@@ -338,16 -351,13 +343,16 @@@
      nearest.index = -1;
      nearest.dist_sq = FLT_MAX;
      const MPoly *mpoly = &target_polys[i];
 -    BKE_mesh_calc_poly_center(mpoly, &target_loops[mpoly->loopstart], target_verts, from_co);
 +    BKE_mesh_calc_poly_center(mpoly,
 +                              &target_loops[mpoly->loopstart],
 +                              reinterpret_cast<const float(*)[3]>(target_positions.data()),
 +                              from_co);
      BLI_bvhtree_find_nearest(bvhtree.tree, from_co, &nearest, bvhtree.nearest_callback, &bvhtree);
      if (nearest.index != -1) {
-       target_face_sets[i] = source_face_sets[looptri[nearest.index].poly];
+       dst[i] = src[looptri[nearest.index].poly];
      }
      else {
-       target_face_sets[i] = 1;
+       dst[i] = 1;
      }
    }
    free_bvhtree_from_mesh(&bvhtree);
diff --cc source/blender/blenkernel/intern/mesh_runtime.cc
index ccfb54f57c6,d7a0b73298e..bf841ccd336
--- a/source/blender/blenkernel/intern/mesh_runtime.cc
+++ b/source/blender/blenkernel/intern/mesh_runtime.cc
@@@ -155,12 -154,23 +155,23 @@@ void BKE_mesh_runtime_looptri_recalc(Me
    const Span<MPoly> polys = mesh->polys();
    const Span<MLoop> loops = mesh->loops();
  
-   BKE_mesh_recalc_looptri(loops.data(),
-                           polys.data(),
-                           reinterpret_cast<const float(*)[3]>(positions.data()),
-                           mesh->totloop,
-                           mesh->totpoly,
-                           mesh->runtime.looptris.array_wip);
+   if (BKE_mesh_poly_normals_are_dirty(mesh)) {
+     BKE_mesh_recalc_looptri_with_normals(loops.data(),
+                                          polys.data(),
 -                                         verts.data(),
++                                         reinterpret_cast<const float(*)[3]>(positions.data()),
+                                          mesh->totloop,
+                                          mesh->totpoly,
+  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list