[Bf-blender-cvs] [b6442c33179] sculpt-dev: Sculpt: fix shape keys being destroyed by SCULPT_UNDO_GEOMETRY/SYMMETRIZE pushes.

Joseph Eagar noreply at git.blender.org
Wed Oct 13 12:26:51 CEST 2021


Commit: b6442c331799367887027bfe37cbf8c718dff04c
Author: Joseph Eagar
Date:   Wed Oct 13 03:25:30 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rBb6442c331799367887027bfe37cbf8c718dff04c

Sculpt: fix shape keys being destroyed by
        SCULPT_UNDO_GEOMETRY/SYMMETRIZE pushes.

* Also cleaned up bmesh conversion parameters in
  a few other places.

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

M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/bmesh/intern/bmesh_log.c
M	source/blender/editors/sculpt_paint/sculpt_array.c
M	source/blender/editors/sculpt_paint/sculpt_face_set.c
M	source/blender/modifiers/intern/MOD_boolean.cc

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

diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 28f58b54816..e4179f02375 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1144,13 +1144,11 @@ BMesh *BKE_mesh_to_bmesh(Mesh *me,
   return BKE_mesh_to_bmesh_ex(ob,
                               me,
                               params,
-                              &(struct BMeshFromMeshParams){
-                                  .calc_face_normal = false,
-                                  .add_key_index = add_key_index,
-                                  .use_shapekey = true,
-                                  .create_shapekey_layers = true,
-                                  .active_shapekey = ob->shapenr,
-                              });
+                              &(struct BMeshFromMeshParams){.calc_face_normal = false,
+                                                            .add_key_index = add_key_index,
+                                                            .use_shapekey = true,
+                                                            .create_shapekey_layers = true,
+                                                            .active_shapekey = ob->shapenr});
 }
 
 Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm,
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 144f64a6b82..951e680b4de 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -2518,9 +2518,9 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
                          (&(struct BMeshFromMeshParams){.calc_face_normal = true,
                                                         .use_shapekey = true,
                                                         .active_shapekey = ob->shapenr,
+                                                        .create_shapekey_layers = true,
                                                         .ignore_id_layers = false,
                                                         .copy_temp_cdlayers = true,
-                                                        .create_shapekey_layers = true,
                                                         .cd_mask_extra = CD_MASK_DYNTOPO_VERT}));
 
       SCULPT_dyntopo_node_layers_add(ob->sculpt);
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index 627018c956f..9632748a591 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -1301,13 +1301,16 @@ static void bm_log_face_values_swap(BMLog *log,
 
 static void bm_log_full_mesh_intern(BMesh *bm, BMLog *log, BMLogEntry *entry)
 {
-  CustomData_MeshMasks cd_mask_extra = {CD_MASK_DYNTOPO_VERT, 0, 0, 0, 0};
+  // keep shapekey as explicit cd layers since we
+  // don't have access to the original mesh's ->key member.
+
+  CustomData_MeshMasks cd_mask_extra = {CD_MASK_DYNTOPO_VERT | CD_MASK_SHAPEKEY, 0, 0, 0, 0};
 
   BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE | BM_FACE);
 
   entry->full_copy_mesh = BKE_mesh_from_bmesh_nomain(
       bm,
-      (&(struct BMeshToMeshParams){.update_shapekey_indices = true,
+      (&(struct BMeshToMeshParams){.update_shapekey_indices = false,
                                    .calc_object_remap = false,
                                    .cd_mask_extra = cd_mask_extra,
                                    .copy_temp_cdlayers = true,
@@ -1970,21 +1973,24 @@ bool BM_log_entry_drop(BMLogEntry *entry)
 
 static void full_copy_load(BMesh *bm, BMLog *log, BMLogEntry *entry)
 {
-  CustomData_MeshMasks cd_mask_extra = {CD_MASK_DYNTOPO_VERT, 0, 0, 0, 0};
+  CustomData_MeshMasks cd_mask_extra = {CD_MASK_DYNTOPO_VERT | CD_MASK_SHAPEKEY, 0, 0, 0, 0};
+
+  int shapenr = bm->shapenr;
 
   BM_mesh_clear(bm);
   BM_mesh_bm_from_me(NULL,
                      bm,
-                     entry->full_copy_mesh,
+                     entry->full_copy_mesh,  // note we stored shapekeys as customdata layers,
+                                             // that's why the shapekey params are false
                      (&(struct BMeshFromMeshParams){.calc_face_normal = false,
                                                     .add_key_index = false,
-                                                    .use_shapekey = true,
-                                                    .active_shapekey = bm->shapenr,
-                                                    .create_shapekey_layers = true,
+                                                    .use_shapekey = false,
+                                                    .create_shapekey_layers = false,
                                                     .cd_mask_extra = cd_mask_extra,
                                                     .copy_temp_cdlayers = true,
                                                     .ignore_id_layers = false}));
 
+  bm->shapenr = shapenr;
   bm->elem_index_dirty |= BM_VERT | BM_EDGE | BM_FACE;
 
   BM_mesh_elem_table_ensure(bm, BM_VERT | BM_EDGE | BM_FACE);
@@ -2250,25 +2256,29 @@ BMLogEntry *BM_log_all_ids(BMesh *bm, BMLog *log, BMLogEntry *entry)
 
 static void full_copy_swap(BMesh *bm, BMLog *log, BMLogEntry *entry)
 {
-  CustomData_MeshMasks cd_mask_extra = {CD_MASK_DYNTOPO_VERT, 0, 0, 0, 0};
+  CustomData_MeshMasks cd_mask_extra = {CD_MASK_DYNTOPO_VERT | CD_MASK_SHAPEKEY, 0, 0, 0, 0};
 
   BMLogEntry tmp = {0};
 
   bm_log_full_mesh_intern(bm, log, &tmp);
 
+  int shapenr = bm->shapenr;
+
   BM_mesh_clear(bm);
   BM_mesh_bm_from_me(NULL,
                      bm,
-                     entry->full_copy_mesh,
+                     entry->full_copy_mesh,  // note we stored shapekeys as customdata layers,
+                                             // that's why the shapekey params are false
                      (&(struct BMeshFromMeshParams){.calc_face_normal = false,
                                                     .add_key_index = false,
-                                                    .use_shapekey = true,
-                                                    .active_shapekey = bm->shapenr,
-                                                    .create_shapekey_layers = true,
+                                                    .use_shapekey = false,
+                                                    .create_shapekey_layers = false,
                                                     .cd_mask_extra = cd_mask_extra,
                                                     .copy_temp_cdlayers = true,
                                                     .ignore_id_layers = false}));
 
+  bm->shapenr = shapenr;
+
   bm->elem_index_dirty |= BM_VERT | BM_EDGE | BM_FACE;
   bm->elem_table_dirty |= BM_VERT | BM_EDGE | BM_FACE;
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_array.c b/source/blender/editors/sculpt_paint/sculpt_array.c
index 38719514c3e..7da3470286a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_array.c
+++ b/source/blender/editors/sculpt_paint/sculpt_array.c
@@ -227,6 +227,9 @@ static BMesh *sculpt_array_source_build(Object *ob, Brush *brush, SculptArray *a
                        sculpt_mesh,
                        &((struct BMeshFromMeshParams){
                            .calc_face_normal = true,
+                           .active_shapekey = ob->shapenr,
+                           .use_shapekey = true,
+                           .create_shapekey_layers = true,
                        }));
   }
 
@@ -383,6 +386,9 @@ static void sculpt_array_mesh_build(Sculpt *sd, Object *ob, SculptArray *array)
                        sculpt_mesh,
                        &((struct BMeshFromMeshParams){
                            .calc_face_normal = true,
+                           .active_shapekey = ob->shapenr,
+                           .use_shapekey = true,
+                           .create_shapekey_layers = true,
                        }));
   }
   else {
diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.c b/source/blender/editors/sculpt_paint/sculpt_face_set.c
index b6036656afd..f5707457614 100644
--- a/source/blender/editors/sculpt_paint/sculpt_face_set.c
+++ b/source/blender/editors/sculpt_paint/sculpt_face_set.c
@@ -268,7 +268,7 @@ int ED_sculpt_face_sets_active_update_and_get(bContext *C, Object *ob, const flo
   return SCULPT_active_face_set_get(ss);
 }
 
-static BMesh *sculpt_faceset_bm_begin(SculptSession *ss, Mesh *mesh)
+static BMesh *sculpt_faceset_bm_begin(Object *ob, SculptSession *ss, Mesh *mesh)
 {
   if (ss->bm) {
     return ss->bm;
@@ -285,6 +285,9 @@ static BMesh *sculpt_faceset_bm_begin(SculptSession *ss, Mesh *mesh)
                      mesh,
                      (&(struct BMeshFromMeshParams){
                          .calc_face_normal = true,
+                         .active_shapekey = ob->shapenr,
+                         .use_shapekey = true,
+                         .create_shapekey_layers = true,
                      }));
   return bm;
 }
@@ -945,7 +948,7 @@ static void sculpt_face_sets_init_flood_fill(Object *ob,
   SCULPT_vertex_random_access_ensure(ss);
   SCULPT_face_random_access_ensure(ss);
 
-  bm = sculpt_faceset_bm_begin(ss, mesh);
+  bm = sculpt_faceset_bm_begin(ob, ss, mesh);
 
   BLI_bitmap *visited_faces = BLI_BITMAP_NEW(ss->totfaces, "visited faces");
   const int totfaces = ss->totfaces;  // mesh->totpoly;
@@ -1793,6 +1796,9 @@ static void sculpt_face_set_delete_geometry(Object *ob,
                        mesh,
                        (&(struct BMeshFromMeshParams){
                            .calc_face_normal = true,
+                           .active_shapekey = ob->shapenr,
+                           .use_shapekey = true,
+                           .create_shapekey_layers = true,
                        }));
 
     BM_mesh_elem_table_init(bm, BM_FACE);
@@ -2085,7 +2091,7 @@ static void sculpt_face_set_extrude_id(Object *ob,
 
   no_islands = no_islands && island != NULL;
 
-  BMesh *bm = sculpt_faceset_bm_begin(ss, mesh);
+  BMesh *bm = sculpt_faceset_bm_begin(ob, ss, mesh);
   if (ss->bm) {
     BKE_pbvh_bmesh_set_toolflags(ss->pbvh, true);
     SCULPT_upda

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list