[Bf-blender-cvs] [b7f5ab0] master: ShapeKeys: Add `BKE_keyblock_is_basis` to check whether a given keyblock is used a basis by others.
Bastien Montagne
noreply at git.blender.org
Mon Nov 17 11:21:21 CET 2014
Commit: b7f5ab0cd33bc7632bd71af5f883745e340d6e18
Author: Bastien Montagne
Date: Sun Nov 16 21:45:40 2014 +0100
Branches: master
https://developer.blender.org/rBb7f5ab0cd33bc7632bd71af5f883745e340d6e18
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.
===================================================================
M source/blender/blenkernel/BKE_key.h
M source/blender/blenkernel/intern/key.c
M source/blender/bmesh/intern/bmesh_mesh_conv.c
M source/blender/editors/curve/editcurve.c
M source/blender/editors/sculpt_paint/sculpt.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index fe083eb..31b2c7d 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -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;
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index d426602..b982139 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -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;
+}
diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c
index 8c96cc9..3630bb7 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_conv.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c
@@ -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)) {
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index c279e83..d1208b8 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -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 */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 0e6ccca..1e4931a 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -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);
More information about the Bf-blender-cvs
mailing list