Cleanup: remove DM from 'join as shape' operator.
Also deduplicated the 'mesh as shapekey' code, we had kind of two funcs doing the same thing here...
This commit is contained in:
parent
6046d9f715
commit
31d916210c
|
@ -387,9 +387,6 @@ void DM_to_bmesh_ex(struct DerivedMesh *dm, struct BMesh *bm, const boo
|
|||
struct BMesh *DM_to_bmesh(struct DerivedMesh *dm, const bool calc_face_normal);
|
||||
|
||||
|
||||
/** Utility function to convert a DerivedMesh to a shape key block */
|
||||
void DM_to_meshkey(DerivedMesh *dm, struct Mesh *me, struct KeyBlock *kb);
|
||||
|
||||
void DM_set_only_copy(DerivedMesh *dm, CustomDataMask mask);
|
||||
|
||||
/* adds a vertex/edge/face custom data layer to a DerivedMesh, optionally
|
||||
|
|
|
@ -102,7 +102,7 @@ void BKE_keyblock_convert_from_curve(struct Curve *cu, struct KeyBlock *kb, s
|
|||
void BKE_keyblock_convert_to_curve(struct KeyBlock *kb, struct Curve *cu, struct ListBase *nurb);
|
||||
|
||||
void BKE_keyblock_update_from_mesh(struct Mesh *me, struct KeyBlock *kb);
|
||||
void BKE_keyblock_convert_from_mesh(struct Mesh *me, struct KeyBlock *kb);
|
||||
void BKE_keyblock_convert_from_mesh(struct Mesh *me, struct Key *key, struct KeyBlock *kb);
|
||||
void BKE_keyblock_convert_to_mesh(struct KeyBlock *kb, struct Mesh *me);
|
||||
void BKE_keyblock_mesh_calc_normals(
|
||||
struct KeyBlock *kb, struct Mesh *mesh, float (*r_vertnors)[3], float (*r_polynors)[3], float (*r_loopnors)[3]);
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "BKE_customdata.h" /* for CustomDataMask */
|
||||
|
||||
struct Depsgraph;
|
||||
struct KeyBlock;
|
||||
struct Mesh;
|
||||
struct MLoop;
|
||||
struct MLoopTri;
|
||||
|
@ -82,4 +83,7 @@ struct Mesh *mesh_get_eval_deform(
|
|||
struct Depsgraph *depsgraph, struct Scene *scene,
|
||||
struct Object *ob, CustomDataMask dataMask);
|
||||
|
||||
void BKE_mesh_runtime_eval_to_meshkey(struct Mesh *me_deformed, struct Mesh *me, struct KeyBlock *kb);
|
||||
|
||||
|
||||
#endif /* __BKE_MESH_RUNTIME_H__ */
|
||||
|
|
|
@ -856,26 +856,18 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob, CustomDataMask mask, bool
|
|||
}
|
||||
}
|
||||
|
||||
void DM_to_meshkey(DerivedMesh *dm, Mesh *me, KeyBlock *kb)
|
||||
/** Utility function to convert an (evaluated) Mesh to a shape key block. */
|
||||
/* Just a shallow wrapper around BKE_keyblock_convert_from_mesh,
|
||||
* that ensures both evaluated mesh and original one has same number of vertices. */
|
||||
void BKE_mesh_runtime_eval_to_meshkey(Mesh *me_deformed, Mesh *me, KeyBlock *kb)
|
||||
{
|
||||
int a, totvert = dm->getNumVerts(dm);
|
||||
float *fp;
|
||||
MVert *mvert;
|
||||
const int totvert = me_deformed->totvert;
|
||||
|
||||
if (totvert == 0 || me->totvert == 0 || me->totvert != totvert) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (kb->data) MEM_freeN(kb->data);
|
||||
kb->data = MEM_malloc_arrayN(me->key->elemsize, me->totvert, "kb->data");
|
||||
kb->totelem = totvert;
|
||||
|
||||
fp = kb->data;
|
||||
mvert = dm->getVertDataArray(dm, CD_MVERT);
|
||||
|
||||
for (a = 0; a < kb->totelem; a++, fp += 3, mvert++) {
|
||||
copy_v3_v3(fp, mvert->co);
|
||||
}
|
||||
BKE_keyblock_convert_from_mesh(me_deformed, me->key, kb);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1767,16 +1767,16 @@ void BKE_keyblock_update_from_mesh(Mesh *me, KeyBlock *kb)
|
|||
}
|
||||
}
|
||||
|
||||
void BKE_keyblock_convert_from_mesh(Mesh *me, KeyBlock *kb)
|
||||
void BKE_keyblock_convert_from_mesh(Mesh *me, Key *key, KeyBlock *kb)
|
||||
{
|
||||
int tot = me->totvert;
|
||||
const int len = me->totvert;
|
||||
|
||||
if (me->totvert == 0) return;
|
||||
|
||||
MEM_SAFE_FREE(kb->data);
|
||||
|
||||
kb->data = MEM_mallocN(me->key->elemsize * tot, __func__);
|
||||
kb->totelem = tot;
|
||||
kb->data = MEM_malloc_arrayN((size_t)len, (size_t)key->elemsize, __func__);
|
||||
kb->totelem = len;
|
||||
|
||||
BKE_keyblock_update_from_mesh(me, kb);
|
||||
}
|
||||
|
|
|
@ -2956,7 +2956,7 @@ static KeyBlock *insert_meshkey(Main *bmain, Object *ob, const char *name, const
|
|||
if (newkey || from_mix == false) {
|
||||
/* create from mesh */
|
||||
kb = BKE_keyblock_add_ctime(key, name, false);
|
||||
BKE_keyblock_convert_from_mesh(me, kb);
|
||||
BKE_keyblock_convert_from_mesh(me, key, kb);
|
||||
}
|
||||
else {
|
||||
/* copy from current values */
|
||||
|
|
|
@ -882,7 +882,7 @@ void ArmatureImporter::make_shape_keys(bContext *C)
|
|||
|
||||
//insert basis key
|
||||
kb = BKE_keyblock_add_ctime(key, "Basis", false);
|
||||
BKE_keyblock_convert_from_mesh(source_me, kb);
|
||||
BKE_keyblock_convert_from_mesh(source_me, key, kb);
|
||||
|
||||
//insert other shape keys
|
||||
for (int i = 0 ; i < morphTargetIds.getCount() ; i++ ) {
|
||||
|
@ -896,7 +896,7 @@ void ArmatureImporter::make_shape_keys(bContext *C)
|
|||
std::string morph_name = *this->mesh_importer->get_geometry_name(me->id.name);
|
||||
|
||||
kb = BKE_keyblock_add_ctime(key, morph_name.c_str(), false);
|
||||
BKE_keyblock_convert_from_mesh(me, kb);
|
||||
BKE_keyblock_convert_from_mesh(me, key, kb);
|
||||
|
||||
//apply weights
|
||||
weight = morphWeights.getFloatValues()->getData()[i];
|
||||
|
|
|
@ -612,7 +612,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
|
|||
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
||||
Mesh *me = (Mesh *)ob->data;
|
||||
Mesh *selme = NULL;
|
||||
DerivedMesh *dm = NULL;
|
||||
Mesh *me_deformed = NULL;
|
||||
Key *key = me->key;
|
||||
KeyBlock *kb;
|
||||
bool ok = false, nonequal_verts = false;
|
||||
|
@ -646,7 +646,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
|
|||
|
||||
/* first key added, so it was the basis. initialize it with the existing mesh */
|
||||
kb = BKE_keyblock_add(key, NULL);
|
||||
BKE_keyblock_convert_from_mesh(me, kb);
|
||||
BKE_keyblock_convert_from_mesh(me, key, kb);
|
||||
}
|
||||
|
||||
/* now ready to add new keys from selected meshes */
|
||||
|
@ -658,15 +658,15 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
|
|||
selme = (Mesh *)base->object->data;
|
||||
|
||||
if (selme->totvert == me->totvert) {
|
||||
dm = mesh_get_derived_deform(depsgraph, scene, base->object, CD_MASK_BAREMESH);
|
||||
me_deformed = mesh_get_eval_deform(depsgraph, scene, base->object, CD_MASK_BAREMESH);
|
||||
|
||||
if (!dm) continue;
|
||||
if (!me_deformed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
kb = BKE_keyblock_add(key, base->object->id.name + 2);
|
||||
|
||||
DM_to_meshkey(dm, me, kb);
|
||||
|
||||
dm->release(dm);
|
||||
BKE_mesh_runtime_eval_to_meshkey(me_deformed, me, kb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -568,7 +568,7 @@ static int modifier_apply_shape(
|
|||
/* if that was the first key block added, then it was the basis.
|
||||
* Initialize it with the mesh, and add another for the modifier */
|
||||
kb = BKE_keyblock_add(key, NULL);
|
||||
BKE_keyblock_convert_from_mesh(me, kb);
|
||||
BKE_keyblock_convert_from_mesh(me, key, kb);
|
||||
}
|
||||
|
||||
kb = BKE_keyblock_add(key, md->name);
|
||||
|
|
Loading…
Reference in New Issue