Sculpt: fix shape keys being destroyed by

SCULPT_UNDO_GEOMETRY/SYMMETRIZE pushes.

* Also cleaned up bmesh conversion parameters in
  a few other places.
This commit is contained in:
Joseph Eagar 2021-10-13 03:25:30 -07:00
parent 4050acf830
commit b6442c3317
6 changed files with 47 additions and 23 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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 {

View File

@ -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_update_customdata_refs(ss);

View File

@ -250,6 +250,10 @@ static BMesh *BMD_mesh_bm_create(
BMeshFromMeshParams params{};
params.calc_face_normal = true;
params.active_shapekey = object->shapenr;
params.use_shapekey = true;
params.create_shapekey_layers = true,
BM_mesh_bm_from_me(object, bm, mesh_operand_ob, &params);
if (UNLIKELY(*r_is_flip)) {