Sculpt-dev: fix shapekey undo bug with PBVH_FACES

* Also fixed bug in bmesh conversion code.
This commit is contained in:
Joseph Eagar 2022-05-13 16:53:47 -07:00
parent cd316eb6c6
commit da4349c147
3 changed files with 29 additions and 4 deletions

View File

@ -308,8 +308,21 @@ void BM_mesh_bm_from_me(Object *ob,
const Mesh *me,
const struct BMeshFromMeshParams *params)
{
const bool is_new = !(bm->totvert || (bm->vdata.totlayer || bm->edata.totlayer ||
bm->pdata.totlayer || bm->ldata.totlayer));
static int totlayers = 0;
for (int i = 0; i < 4; i++) {
CustomData *cdata = (&bm->vdata) + i;
for (int j = 0; j < cdata->totlayer; j++) {
if (cdata->layers[j].type == CD_TOOLFLAGS || cdata->layers[j].type == CD_MESH_ID) {
continue;
}
totlayers++;
}
}
const bool is_new = !(bm->totvert || totlayers);
KeyBlock *actkey;
float(*keyco)[3] = nullptr;

View File

@ -27,6 +27,7 @@
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_report.h"
#include "BKE_pbvh.h"
#include "DEG_depsgraph.h"
@ -304,6 +305,8 @@ void EDBM_mesh_load_ex(Main *bmain, Object *ob, bool free_data)
bm->shapenr = 1;
}
BKE_pbvh_invalidate_cache(ob);
BM_mesh_bm_to_me(bmain,
ob,
bm,

View File

@ -19,6 +19,7 @@
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
@ -1716,6 +1717,8 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode)
unode->orig_co = MEM_malloc_arrayN(allvert, sizeof(float) * 3, "sculpt unode undo coords");
}
bool have_grids = BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS;
BKE_pbvh_vertex_iter_begin (ss->pbvh, unode->node, vd, PBVH_ITER_ALL) {
copy_v3_v3(unode->co[vd.i], vd.co);
if (vd.no) {
@ -1726,9 +1729,15 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode)
}
if (ss->deform_modifiers_active) {
SCULPT_orig_vert_data_update(&orig_data, vd.vertex);
if (!have_grids && ss->shapekey_active) {
float(*cos)[3] = ss->shapekey_active->data;
copy_v3_v3(unode->orig_co[vd.i], orig_data.co);
copy_v3_v3(unode->orig_co[vd.i], cos[vd.index]);
}
else {
MSculptVert *mv = SCULPT_vertex_get_sculptvert(ss, vd.vertex);
copy_v3_v3(unode->orig_co[vd.i], mv->origco);
}
}
}
BKE_pbvh_vertex_iter_end;