Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/key.c')
-rw-r--r--source/blender/blenkernel/intern/key.c231
1 files changed, 154 insertions, 77 deletions
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 1d1c04e173c..e0246f874f3 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -79,8 +79,9 @@ void BKE_key_free(Key *key)
BKE_animdata_free((ID *)key, false);
while ((kb = BLI_pophead(&key->block))) {
- if (kb->data)
+ if (kb->data) {
MEM_freeN(kb->data);
+ }
MEM_freeN(kb);
}
}
@@ -90,8 +91,9 @@ void BKE_key_free_nolib(Key *key)
KeyBlock *kb;
while ((kb = BLI_pophead(&key->block))) {
- if (kb->data)
+ if (kb->data) {
MEM_freeN(kb->data);
+ }
MEM_freeN(kb);
}
}
@@ -198,10 +200,12 @@ Key *BKE_key_copy_nolib(Key *key)
kbn = keyn->block.first;
while (kbn) {
- if (kbn->data)
+ if (kbn->data) {
kbn->data = MEM_dupallocN(kbn->data);
- if (kb == key->refkey)
+ }
+ if (kb == key->refkey) {
keyn->refkey = kbn;
+ }
kbn = kbn->next;
kb = kb->next;
@@ -221,9 +225,11 @@ void BKE_key_sort(Key *key)
KeyBlock *kb2;
/* locate the key which is out of position */
- for (kb = key->block.first; kb; kb = kb->next)
- if ((kb->next) && (kb->pos > kb->next->pos))
+ for (kb = key->block.first; kb; kb = kb->next) {
+ if ((kb->next) && (kb->pos > kb->next->pos)) {
break;
+ }
+ }
/* if we find a key, move it */
if (kb) {
@@ -372,27 +378,32 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl)
lastpos = k1->pos;
dpos = lastpos - firstkey->pos;
- if (fac < firstkey->pos)
+ if (fac < firstkey->pos) {
fac = firstkey->pos;
- else if (fac > k1->pos)
+ }
+ else if (fac > k1->pos) {
fac = k1->pos;
+ }
k1 = k[0] = k[1] = k[2] = k[3] = firstkey;
t[0] = t[1] = t[2] = t[3] = k1->pos;
/* if (fac < 0.0 || fac > 1.0) return 1; */
- if (k1->next == NULL)
+ if (k1->next == NULL) {
return 1;
+ }
if (cycl) { /* pre-sort */
k[2] = k1->next;
k[3] = k[2]->next;
- if (k[3] == NULL)
+ if (k[3] == NULL) {
k[3] = k1;
+ }
while (k1) {
- if (k1->next == NULL)
+ if (k1->next == NULL) {
k[0] = k1;
+ }
k1 = k1->next;
}
/* k1 = k[1]; */ /* UNUSED */
@@ -406,16 +417,18 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl)
t[3] += dpos;
ofs = 2.0f * dpos;
}
- if (fac < t[1])
+ if (fac < t[1]) {
fac += dpos;
+ }
k1 = k[3];
}
else { /* pre-sort */
k[2] = k1->next;
t[2] = k[2]->pos;
k[3] = k[2]->next;
- if (k[3] == NULL)
+ if (k[3] == NULL) {
k[3] = k[2];
+ }
t[3] = k[3]->pos;
k1 = k[3];
}
@@ -443,13 +456,15 @@ static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl)
t[3] = k1->pos + ofs;
k[3] = k1;
- if (ofs > 2.1f + lastpos)
+ if (ofs > 2.1f + lastpos) {
break;
+ }
}
bsplinetype = 0;
- if (k[1]->type == KEY_BSPLINE || k[2]->type == KEY_BSPLINE)
+ if (k[1]->type == KEY_BSPLINE || k[2]->type == KEY_BSPLINE) {
bsplinetype = 1;
+ }
if (cycl == 0) {
if (bsplinetype == 0) { /* B spline doesn't go through the control points */
@@ -597,11 +612,13 @@ static void cp_key(const int start,
/* currently always 0, in future key_pointer_size may assign */
ofs[1] = 0;
- if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step))
+ if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
return;
+ }
- if (end > tot)
+ if (end > tot) {
end = tot;
+ }
if (tot != kb->totelem) {
ktot = 0.0;
@@ -646,8 +663,9 @@ static void cp_key(const int start,
for (a = start; a < end; a += step) {
cp = key->elemstr;
- if (mode == KEY_MODE_BEZTRIPLE)
+ if (mode == KEY_MODE_BEZTRIPLE) {
cp = elemstr;
+ }
ofsp = ofs;
@@ -657,9 +675,10 @@ static void cp_key(const int start,
case IPO_FLOAT:
if (weights) {
memcpy(poin, kref, sizeof(float[KEYELEM_FLOAT_LEN_COORD]));
- if (*weights != 0.0f)
+ if (*weights != 0.0f) {
rel_flerp(
KEYELEM_FLOAT_LEN_COORD, (float *)poin, (float *)kref, (float *)k1, *weights);
+ }
weights++;
}
else {
@@ -674,10 +693,12 @@ static void cp_key(const int start,
break;
default:
/* should never happen */
- if (freek1)
+ if (freek1) {
MEM_freeN(freek1);
- if (freekref)
+ }
+ if (freekref) {
MEM_freeN(freekref);
+ }
BLI_assert(!"invalid 'cp[1]'");
return;
}
@@ -702,10 +723,12 @@ static void cp_key(const int start,
}
}
- if (freek1)
+ if (freek1) {
MEM_freeN(freek1);
- if (freekref)
+ }
+ if (freekref) {
MEM_freeN(freekref);
+ }
}
static void cp_cu_key(Curve *cu,
@@ -727,8 +750,9 @@ static void cp_cu_key(Curve *cu,
a1 = max_ii(a, start);
a2 = min_ii(a + step, end);
- if (a1 < a2)
+ if (a1 < a2) {
cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BPOINT);
+ }
}
else if (nu->bezt) {
step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
@@ -737,8 +761,9 @@ static void cp_cu_key(Curve *cu,
a1 = max_ii(a, start);
a2 = min_ii(a + step, end);
- if (a1 < a2)
+ if (a1 < a2) {
cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BEZTRIPLE);
+ }
}
else {
step = 0;
@@ -763,11 +788,13 @@ static void key_evaluate_relative(const int start,
/* currently always 0, in future key_pointer_size may assign */
ofs[1] = 0;
- if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step))
+ if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
return;
+ }
- if (end > tot)
+ if (end > tot) {
end = tot;
+ }
/* in case of beztriple */
elemstr[0] = 1; /* nr of ipofloats */
@@ -795,8 +822,9 @@ static void key_evaluate_relative(const int start,
/* reference now can be any block */
refb = BLI_findlink(&key->block, kb->relative);
- if (refb == NULL)
+ if (refb == NULL) {
continue;
+ }
poin = basispoin;
from = key_block_get_data(key, actkb, kb, &freefrom);
@@ -811,8 +839,9 @@ static void key_evaluate_relative(const int start,
weight = weights ? (*weights * icuval) : icuval;
cp = key->elemstr;
- if (mode == KEY_MODE_BEZTRIPLE)
+ if (mode == KEY_MODE_BEZTRIPLE) {
cp = elemstr;
+ }
ofsp = ofs;
@@ -842,10 +871,12 @@ static void key_evaluate_relative(const int start,
break;
default:
/* should never happen */
- if (freefrom)
+ if (freefrom) {
MEM_freeN(freefrom);
- if (freereffrom)
+ }
+ if (freereffrom) {
MEM_freeN(freereffrom);
+ }
BLI_assert(!"invalid 'cp[1]'");
return;
}
@@ -859,14 +890,17 @@ static void key_evaluate_relative(const int start,
reffrom += elemsize;
from += elemsize;
- if (weights)
+ if (weights) {
weights++;
+ }
}
- if (freefrom)
+ if (freefrom) {
MEM_freeN(freefrom);
- if (freereffrom)
+ }
+ if (freereffrom) {
MEM_freeN(freereffrom);
+ }
}
}
}
@@ -892,11 +926,13 @@ static void do_key(const int start,
/* currently always 0, in future key_pointer_size may assign */
ofs[1] = 0;
- if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step))
+ if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
return;
+ }
- if (end > tot)
+ if (end > tot) {
end = tot;
+ }
k1 = key_block_get_data(key, actkb, k[0], &freek1);
k2 = key_block_get_data(key, actkb, k[1], &freek2);
@@ -1014,8 +1050,9 @@ static void do_key(const int start,
for (a = start; a < end; a += step) {
cp = key->elemstr;
- if (mode == KEY_MODE_BEZTRIPLE)
+ if (mode == KEY_MODE_BEZTRIPLE) {
cp = elemstr;
+ }
ofsp = ofs;
@@ -1051,14 +1088,18 @@ static void do_key(const int start,
break;
default:
/* should never happen */
- if (freek1)
+ if (freek1) {
MEM_freeN(freek1);
- if (freek2)
+ }
+ if (freek2) {
MEM_freeN(freek2);
- if (freek3)
+ }
+ if (freek3) {
MEM_freeN(freek3);
- if (freek4)
+ }
+ if (freek4) {
MEM_freeN(freek4);
+ }
BLI_assert(!"invalid 'cp[1]'");
return;
}
@@ -1118,14 +1159,18 @@ static void do_key(const int start,
}
}
- if (freek1)
+ if (freek1) {
MEM_freeN(freek1);
- if (freek2)
+ }
+ if (freek2) {
MEM_freeN(freek2);
- if (freek3)
+ }
+ if (freek3) {
MEM_freeN(freek3);
- if (freek4)
+ }
+ if (freek4) {
MEM_freeN(freek4);
+ }
}
static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cache)
@@ -1137,8 +1182,9 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac
int totvert = 0, defgrp_index = 0;
/* no vgroup string set? */
- if (vgroup[0] == 0)
+ if (vgroup[0] == 0) {
return NULL;
+ }
/* gather dvert and totvert */
if (ob->type == OB_MESH) {
@@ -1146,8 +1192,9 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac
dvert = me->dvert;
totvert = me->totvert;
- if (me->edit_mesh && me->edit_mesh->bm->totvert == totvert)
+ if (me->edit_mesh && me->edit_mesh->bm->totvert == totvert) {
em = me->edit_mesh;
+ }
}
else if (ob->type == OB_LATTICE) {
Lattice *lt = ob->data;
@@ -1155,8 +1202,9 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac
totvert = lt->pntsu * lt->pntsv * lt->pntsw;
}
- if (dvert == NULL)
+ if (dvert == NULL) {
return NULL;
+ }
/* find the group (weak loop-in-loop) */
defgrp_index = defgroup_name_index(ob, vgroup);
@@ -1366,8 +1414,9 @@ static void do_latt_key(Object *ob, Key *key, char *out, const int tot)
}
}
- if (lt->flag & LT_OUTSIDE)
+ if (lt->flag & LT_OUTSIDE) {
outside_lattice(lt);
+ }
}
/* returns key coordinates (+ tilt) when key applied, NULL otherwise */
@@ -1378,8 +1427,9 @@ float *BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t
char *out;
int tot = 0, size = 0;
- if (key == NULL || BLI_listbase_is_empty(&key->block))
+ if (key == NULL || BLI_listbase_is_empty(&key->block)) {
return NULL;
+ }
/* compute size of output array */
if (ob->type == OB_MESH) {
@@ -1402,8 +1452,9 @@ float *BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t
}
/* if nothing to interpolate, cancel */
- if (tot == 0 || size == 0)
+ if (tot == 0 || size == 0) {
return NULL;
+ }
/* allocate array */
if (arr == NULL) {
@@ -1421,8 +1472,9 @@ float *BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t
/* shape locked, copy the locked shape instead of blending */
KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1);
- if (kb && (kb->flag & KEYBLOCK_MUTE))
+ if (kb && (kb->flag & KEYBLOCK_MUTE)) {
kb = key->refkey;
+ }
if (kb == NULL) {
kb = key->block.first;
@@ -1434,22 +1486,28 @@ float *BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t
cp_key(0, tot, tot, out, key, actkb, kb, weights, 0);
- if (weights)
+ if (weights) {
MEM_freeN(weights);
+ }
}
- else if (ELEM(ob->type, OB_CURVE, OB_SURF))
+ else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
cp_cu_key(ob->data, key, actkb, kb, 0, tot, out, tot);
+ }
}
else {
- if (ob->type == OB_MESH)
+ if (ob->type == OB_MESH) {
do_mesh_key(ob, key, out, tot);
- else if (ob->type == OB_LATTICE)
+ }
+ else if (ob->type == OB_LATTICE) {
do_latt_key(ob, key, out, tot);
- else if (ob->type == OB_CURVE)
+ }
+ else if (ob->type == OB_CURVE) {
do_curve_key(ob, key, out, tot);
- else if (ob->type == OB_SURF)
+ }
+ else if (ob->type == OB_SURF) {
do_curve_key(ob, key, out, tot);
+ }
}
if (r_totelem) {
@@ -1513,8 +1571,9 @@ Key *BKE_key_from_id(ID *id)
Key **BKE_key_from_object_p(const Object *ob)
{
- if (ob == NULL || ob->data == NULL)
+ if (ob == NULL || ob->data == NULL) {
return NULL;
+ }
return BKE_key_from_id_p(ob->data);
}
@@ -1537,8 +1596,9 @@ KeyBlock *BKE_keyblock_add(Key *key, const char *name)
int tot;
kb = key->block.last;
- if (kb)
+ if (kb) {
curpos = kb->pos;
+ }
kb = MEM_callocN(sizeof(KeyBlock), "Keyblock");
BLI_addtail(&key->block, kb);
@@ -1549,10 +1609,12 @@ KeyBlock *BKE_keyblock_add(Key *key, const char *name)
BLI_strncpy(kb->name, name, sizeof(kb->name));
}
else {
- if (tot == 1)
+ if (tot == 1) {
BLI_strncpy(kb->name, DATA_("Basis"), sizeof(kb->name));
- else
+ }
+ else {
BLI_snprintf(kb->name, sizeof(kb->name), DATA_("Key %d"), tot - 1);
+ }
}
BLI_uniquename(&key->block, kb, DATA_("Key"), '.', offsetof(KeyBlock, name), sizeof(kb->name));
@@ -1560,8 +1622,9 @@ KeyBlock *BKE_keyblock_add(Key *key, const char *name)
kb->uid = key->uidgen++;
key->totkey++;
- if (key->totkey == 1)
+ if (key->totkey == 1) {
key->refkey = kb;
+ }
kb->slidermin = 0.0f;
kb->slidermax = 1.0f;
@@ -1627,8 +1690,9 @@ KeyBlock *BKE_keyblock_from_object_reference(Object *ob)
{
Key *key = BKE_key_from_object(ob);
- if (key)
+ if (key) {
return key->refkey;
+ }
return NULL;
}
@@ -1645,8 +1709,9 @@ KeyBlock *BKE_keyblock_from_key(Key *key, int index)
for (i = 1; i < key->totkey; i++) {
kb = kb->next;
- if (index == i)
+ if (index == i) {
return kb;
+ }
}
}
@@ -1682,8 +1747,9 @@ char *BKE_keyblock_curval_rnapath_get(Key *key, KeyBlock *kb)
PropertyRNA *prop;
/* sanity checks */
- if (ELEM(NULL, key, kb))
+ if (ELEM(NULL, key, kb)) {
return NULL;
+ }
/* create the RNA pointer */
RNA_pointer_create(&key->id, &RNA_ShapeKey, kb, &ptr);
@@ -1706,8 +1772,9 @@ void BKE_keyblock_update_from_lattice(Lattice *lt, KeyBlock *kb)
BLI_assert(kb->totelem == lt->pntsu * lt->pntsv * lt->pntsw);
tot = kb->totelem;
- if (tot == 0)
+ if (tot == 0) {
return;
+ }
bp = lt->def;
fp = kb->data;
@@ -1721,8 +1788,9 @@ void BKE_keyblock_convert_from_lattice(Lattice *lt, KeyBlock *kb)
int tot;
tot = lt->pntsu * lt->pntsv * lt->pntsw;
- if (tot == 0)
+ if (tot == 0) {
return;
+ }
MEM_SAFE_FREE(kb->data);
@@ -1758,10 +1826,12 @@ int BKE_keyblock_curve_element_count(ListBase *nurb)
nu = nurb->first;
while (nu) {
- if (nu->bezt)
+ if (nu->bezt) {
tot += KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
- else if (nu->bp)
+ }
+ else if (nu->bp) {
tot += KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
+ }
nu = nu->next;
}
@@ -1780,8 +1850,9 @@ void BKE_keyblock_update_from_curve(Curve *UNUSED(cu), KeyBlock *kb, ListBase *n
BLI_assert(BKE_keyblock_curve_element_count(nurb) == kb->totelem);
tot = kb->totelem;
- if (tot == 0)
+ if (tot == 0) {
return;
+ }
fp = kb->data;
for (nu = nurb->first; nu; nu = nu->next) {
@@ -1812,8 +1883,9 @@ void BKE_keyblock_convert_from_curve(Curve *cu, KeyBlock *kb, ListBase *nurb)
/* count */
tot = BKE_keyblock_curve_element_count(nurb);
- if (tot == 0)
+ if (tot == 0) {
return;
+ }
MEM_SAFE_FREE(kb->data);
@@ -1869,8 +1941,9 @@ void BKE_keyblock_update_from_mesh(Mesh *me, KeyBlock *kb)
BLI_assert(me->totvert == kb->totelem);
tot = me->totvert;
- if (tot == 0)
+ if (tot == 0) {
return;
+ }
mvert = me->mvert;
fp = kb->data;
@@ -1883,8 +1956,9 @@ void BKE_keyblock_convert_from_mesh(Mesh *me, Key *key, KeyBlock *kb)
{
const int len = me->totvert;
- if (me->totvert == 0)
+ if (me->totvert == 0) {
return;
+ }
MEM_SAFE_FREE(kb->data);
@@ -2015,8 +2089,9 @@ void BKE_keyblock_update_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos)
#endif
tot = kb->totelem;
- if (tot == 0)
+ if (tot == 0) {
return;
+ }
/* Copy coords to keyblock */
if (ELEM(ob->type, OB_MESH, OB_LATTICE)) {
@@ -2072,8 +2147,9 @@ void BKE_keyblock_convert_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos
tot = BKE_keyblock_curve_element_count(&cu->nurb);
}
- if (tot == 0)
+ if (tot == 0) {
return;
+ }
kb->data = MEM_mallocN(tot * elemsize, __func__);
@@ -2101,8 +2177,9 @@ float (*BKE_keyblock_convert_to_vertcos(Object *ob, KeyBlock *kb))[3]
tot = BKE_nurbList_verts_count(&cu->nurb);
}
- if (tot == 0)
+ if (tot == 0) {
return NULL;
+ }
co = vertCos = MEM_mallocN(tot * sizeof(*vertCos), __func__);