forked from bartvdbraak/blender
ShapeKeys: Add BKE_keyblock_is_basis
to check whether a given keyblock is used a basis by others.
Also fix stupid debug-only error in previous commit.
This commit is contained in:
parent
d526ef607d
commit
b7f5ab0cd3
@ -109,6 +109,8 @@ void BKE_keyblock_update_from_offset(struct Object *ob, struct KeyBlock *kb,
|
||||
/* other management */
|
||||
bool BKE_keyblock_move(struct Object *ob, int org_index, int new_index);
|
||||
|
||||
bool BKE_keyblock_is_basis(struct Key *key, const int index);
|
||||
|
||||
/* key.c */
|
||||
extern int slurph_opt;
|
||||
|
||||
|
@ -1890,9 +1890,23 @@ void BKE_keyblock_update_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos)
|
||||
float *fp = kb->data;
|
||||
int tot, a;
|
||||
|
||||
BLI_assert(((ob->type == OB_MESH) ? me->totvert :
|
||||
(ob->type == OB_LATTICE) ? lt->pntsu * lt->pntsv * lt->pntsw :
|
||||
ELEM(ob->type, OB_CURVE, OB_SURF) ? BKE_nurbList_verts_count(&cu->nurb) : 0) == kb->totelem);
|
||||
#ifndef NDEBUG
|
||||
if (ob->type == OB_LATTICE) {
|
||||
Lattice *lt = ob->data;
|
||||
BLI_assert((lt->pntsu * lt->pntsv * lt->pntsw) == kb->totelem);
|
||||
}
|
||||
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
|
||||
Curve *cu = ob->data;
|
||||
BLI_assert(BKE_nurbList_verts_count(&cu->nurb) == kb->totelem);
|
||||
}
|
||||
else if (ob->type == OB_MESH) {
|
||||
Mesh *me = ob->data;
|
||||
BLI_assert(me->totvert == kb->totelem);
|
||||
}
|
||||
else {
|
||||
BLI_assert(0 == kb->totelem);
|
||||
}
|
||||
#endif
|
||||
|
||||
tot = kb->totelem;
|
||||
if (tot == 0) return;
|
||||
@ -2192,3 +2206,22 @@ bool BKE_keyblock_move(Object *ob, int org_index, int new_index)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given keyblock (as index) is used as basis by others in given key.
|
||||
*/
|
||||
bool BKE_keyblock_is_basis(struct Key *key, const int index)
|
||||
{
|
||||
KeyBlock *kb;
|
||||
int i;
|
||||
|
||||
if (key->type == KEY_RELATIVE) {
|
||||
for (i = 0, kb = key->block.first; kb; i++, kb = kb->next) {
|
||||
if ((i != index) && (kb->relative == index)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -850,15 +850,7 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, bool do_tessface)
|
||||
* bmesh and the mesh are out of sync */
|
||||
(oldverts != NULL)) /* not used here, but 'oldverts' is used later for applying 'ofs' */
|
||||
{
|
||||
bool act_is_basis = false;
|
||||
|
||||
/* find if this key is a basis for any others */
|
||||
for (currkey = me->key->block.first; currkey; currkey = currkey->next) {
|
||||
if (bm->shapenr - 1 == currkey->relative) {
|
||||
act_is_basis = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const bool act_is_basis = BKE_keyblock_is_basis(me->key, bm->shapenr - 1);
|
||||
|
||||
/* active key is a base */
|
||||
if (act_is_basis && (cd_shape_keyindex_offset != -1)) {
|
||||
|
@ -766,16 +766,7 @@ static void calc_shapeKeys(Object *obedit)
|
||||
|
||||
/* editing the base key should update others */
|
||||
if (cu->key->type == KEY_RELATIVE) {
|
||||
int act_is_basis = 0;
|
||||
/* find if this key is a basis for any others */
|
||||
for (currkey = cu->key->block.first; currkey; currkey = currkey->next) {
|
||||
if (editnurb->shapenr - 1 == currkey->relative) {
|
||||
act_is_basis = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (act_is_basis) { /* active key is a base */
|
||||
if (BKE_keyblock_is_basis(cu->key, editnurb->shapenr - 1)) { /* active key is a base */
|
||||
int totvec = 0;
|
||||
|
||||
/* Calculate needed memory to store offset */
|
||||
|
@ -2917,18 +2917,12 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3])
|
||||
{
|
||||
Mesh *me = (Mesh *)ob->data;
|
||||
float (*ofs)[3] = NULL;
|
||||
int a, is_basis = 0;
|
||||
int a;
|
||||
const int kb_act_idx = ob->shapenr - 1;
|
||||
KeyBlock *currkey;
|
||||
|
||||
/* for relative keys editing of base should update other keys */
|
||||
if (me->key->type == KEY_RELATIVE)
|
||||
for (currkey = me->key->block.first; currkey; currkey = currkey->next)
|
||||
if (ob->shapenr - 1 == currkey->relative) {
|
||||
is_basis = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_basis) {
|
||||
if (BKE_keyblock_is_basis(me->key, kb_act_idx)) {
|
||||
ofs = BKE_keyblock_convert_to_vertcos(ob, kb);
|
||||
|
||||
/* calculate key coord offsets (from previous location) */
|
||||
@ -2937,14 +2931,10 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3])
|
||||
}
|
||||
|
||||
/* apply offsets on other keys */
|
||||
currkey = me->key->block.first;
|
||||
while (currkey) {
|
||||
int apply_offset = ((currkey != kb) && (ob->shapenr - 1 == currkey->relative));
|
||||
|
||||
if (apply_offset)
|
||||
for (currkey = me->key->block.first; currkey; currkey = currkey->next) {
|
||||
if ((currkey != kb) && (currkey->relative == kb_act_idx)) {
|
||||
BKE_keyblock_update_from_offset(ob, currkey, ofs);
|
||||
|
||||
currkey = currkey->next;
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(ofs);
|
||||
|
Loading…
Reference in New Issue
Block a user