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:
authorLukas Tönne <lukas.toenne@gmail.com>2015-05-19 15:26:56 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2015-05-19 15:26:56 +0300
commita91ccbc7909d161b2eb8c84a26f5308debe7b956 (patch)
tree096487df27e82f09e0f5537a76a5d3955f2af1d0 /source/blender/blenkernel
parent5fd5d3c8b29e6c70d0bede0ca6a001a94c4a3499 (diff)
Ported key owner type code from gooseberry, to better sync both branches.
The shapekey code has been modified in both branches, adding particle shapekeys in gooseberry and cache library shapekeys in alembic. The two approaches are slightly different, but based on the same idea of extending the 'from' owner info in Key, so that keys can be used without a 'from' ID and/or with an index for identification.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_key.h4
-rw-r--r--source/blender/blenkernel/intern/cache_library.c4
-rw-r--r--source/blender/blenkernel/intern/curve.c2
-rw-r--r--source/blender/blenkernel/intern/key.c123
-rw-r--r--source/blender/blenkernel/intern/lattice.c2
-rw-r--r--source/blender/blenkernel/intern/mesh.c2
6 files changed, 75 insertions, 62 deletions
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 4b8e3572c06..710e7f354a1 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -51,12 +51,14 @@ extern "C" {
void BKE_key_free(struct Key *sc);
void BKE_key_free_nolib(struct Key *key);
struct Key *BKE_key_add(struct ID *id);
-struct Key *BKE_key_add_ex(struct ID *from, short fromtype);
+struct Key *BKE_key_add_ex(struct ID *from, int fromtype, int fromindex);
struct Key *BKE_key_copy(struct Key *key);
struct Key *BKE_key_copy_nolib(struct Key *key);
void BKE_key_make_local(struct Key *key);
void BKE_key_sort(struct Key *key);
+void BKE_key_set_from_id(struct Key *key, struct ID *id);
+
void key_curve_position_weights(float t, float data[4], int type);
void key_curve_tangent_weights(float t, float data[4], int type);
void key_curve_normal_weights(float t, float data[4], int type);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 08eb0a8707c..c0340f1c0e8 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -1489,7 +1489,7 @@ static void strandskey_init(StrandsKeyCacheModifier *skmd)
skmd->object = NULL;
skmd->hair_system = -1;
- skmd->key = BKE_key_add_ex(NULL, KEY_FROMTYPE_STRANDS);
+ skmd->key = BKE_key_add_ex(NULL, KEY_OWNER_CACHELIB, -1);
skmd->key->type = KEY_RELATIVE;
}
@@ -1564,7 +1564,7 @@ KeyBlock *BKE_cache_modifier_strands_key_insert_key(StrandsKeyCacheModifier *skm
bool newkey = false;
if (key == NULL) {
- key = skmd->key = BKE_key_add_ex(NULL, KEY_FROMTYPE_STRANDS);
+ key = skmd->key = BKE_key_add_ex(NULL, KEY_OWNER_CACHELIB, -1);
key->type = KEY_RELATIVE;
newkey = true;
}
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index c01b3431d09..5da63b3441e 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -222,7 +222,7 @@ Curve *BKE_curve_copy(Curve *cu)
cun->bb = MEM_dupallocN(cu->bb);
cun->key = BKE_key_copy(cu->key);
- if (cun->key) cun->key->from = (ID *)cun;
+ BKE_key_set_from_id(cun->key, (ID *)cun);
cun->editnurb = NULL;
cun->editfont = NULL;
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 2f1e3cde277..0d9f088152d 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -99,7 +99,7 @@ void BKE_key_free_nolib(Key *key)
}
}
-static void key_set_elemstr(ID *id, short fromtype, char *r_elemstr, int *r_elemsize)
+static void key_set_elemstr(short fromtype, char *r_elemstr, int *r_elemsize)
{
/* XXX the code here uses some defines which will soon be deprecated... */
char elemtype = IPO_FLOAT;
@@ -107,28 +107,22 @@ static void key_set_elemstr(ID *id, short fromtype, char *r_elemstr, int *r_elem
int elemsize = 0;
switch (fromtype) {
- case KEY_FROMTYPE_ID:
- if (id) {
- switch (GS(id->name)) {
- case ID_ME:
- numelem = 3;
- elemtype = IPO_FLOAT;
- elemsize = 12;
- break;
- case ID_LT:
- numelem = 3;
- elemtype = IPO_FLOAT;
- elemsize = 12;
- break;
- case ID_CU:
- numelem = 4;
- elemtype = IPO_BPOINT;
- elemsize = 16;
- break;
- }
- }
+ case KEY_OWNER_MESH:
+ numelem = 3;
+ elemtype = IPO_FLOAT;
+ elemsize = 12;
+ break;
+ case KEY_OWNER_LATTICE:
+ numelem = 3;
+ elemtype = IPO_FLOAT;
+ elemsize = 12;
+ break;
+ case KEY_OWNER_CURVE:
+ numelem = 4;
+ elemtype = IPO_BPOINT;
+ elemsize = 16;
break;
- case KEY_FROMTYPE_STRANDS:
+ case KEY_OWNER_CACHELIB:
numelem = 3;
elemtype = IPO_FLOAT;
elemsize = 12;
@@ -141,26 +135,34 @@ static void key_set_elemstr(ID *id, short fromtype, char *r_elemstr, int *r_elem
*r_elemsize = elemsize;
}
-Key *BKE_key_add_ex(ID *from, short fromtype) /* common function */
+Key *BKE_key_add_ex(ID *from, int fromtype, int fromindex) /* common function */
{
Key *key;
key = BKE_libblock_alloc(G.main, ID_KE, "Key");
key->type = KEY_NORMAL;
- key->from = from;
+ BKE_key_set_from_id(key, from);
key->fromtype = fromtype;
+ key->fromindex = fromindex;
key->uidgen = 1;
- key_set_elemstr(from, fromtype, key->elemstr, &key->elemsize);
+ key_set_elemstr(fromtype, key->elemstr, &key->elemsize);
return key;
}
Key *BKE_key_add(ID *id)
{
- return BKE_key_add_ex(id, KEY_FROMTYPE_ID);
+ int fromtype = 0;
+ switch (GS(id->name)) {
+ case ID_ME: fromtype = KEY_OWNER_MESH; break;
+ case ID_CU: fromtype = KEY_OWNER_CURVE; break;
+ case ID_LT: fromtype = KEY_OWNER_LATTICE; break;
+ default: BLI_assert(false); break; /* other fromtypes should use the _ex version for specifying the type */
+ }
+ return BKE_key_add_ex(id, fromtype, -1);
}
Key *BKE_key_copy(Key *key)
@@ -267,6 +269,19 @@ void BKE_key_sort(Key *key)
key->refkey = key->block.first;
}
+void BKE_key_set_from_id(Key *key, ID *id)
+{
+ if (key) {
+ key->from = id;
+ switch (GS(id->name)) {
+ case ID_ME: key->fromtype = KEY_OWNER_MESH; break;
+ case ID_CU: key->fromtype = KEY_OWNER_CURVE; break;
+ case ID_LT: key->fromtype = KEY_OWNER_LATTICE; break;
+ }
+ key->fromindex = -1;
+ }
+}
+
/**************** do the key ****************/
void key_curve_position_weights(float t, float data[4], int type)
@@ -563,41 +578,37 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **
/* currently only the first value of 'ofs' may be set. */
static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs)
{
+ /* some types allow NULL for key->from */
+ if (!key->from && !ELEM(key->fromtype, KEY_OWNER_CACHELIB))
+ return false;
+
switch (key->fromtype) {
- case KEY_FROMTYPE_ID:
- if (!key->from)
- return false;
-
- switch (GS(key->from->name)) {
- case ID_ME:
- *ofs = sizeof(float) * 3;
- *poinsize = *ofs;
- break;
- case ID_LT:
- *ofs = sizeof(float) * 3;
- *poinsize = *ofs;
- break;
- case ID_CU:
- if (mode == KEY_MODE_BPOINT) {
- *ofs = sizeof(float) * 4;
- *poinsize = *ofs;
- }
- else {
- ofs[0] = sizeof(float) * 12;
- *poinsize = (*ofs) / 3;
- }
-
- break;
- default:
- BLI_assert(!"invalid 'key->from' ID type");
- return false;
+ case KEY_OWNER_MESH:
+ *ofs = sizeof(float) * 3;
+ *poinsize = *ofs;
+ break;
+ case KEY_OWNER_LATTICE:
+ *ofs = sizeof(float) * 3;
+ *poinsize = *ofs;
+ break;
+ case KEY_OWNER_CURVE:
+ if (mode == KEY_MODE_BPOINT) {
+ *ofs = sizeof(float) * 4;
+ *poinsize = *ofs;
+ }
+ else {
+ ofs[0] = sizeof(float) * 12;
+ *poinsize = (*ofs) / 3;
}
break;
-
- case KEY_FROMTYPE_STRANDS:
+ case KEY_OWNER_CACHELIB:
*ofs = sizeof(float) * 3;
*poinsize = *ofs;
break;
+
+ default:
+ BLI_assert(!"invalid 'key->from' ID type");
+ return false;
}
return true;
}
@@ -1418,7 +1429,7 @@ float *BKE_key_evaluate_object_ex(
}
/* prevent python from screwing this up? anyhoo, the from pointer could be dropped */
- key->from = (ID *)ob->data;
+ BKE_key_set_from_id(key, (ID *)ob->data);
if (ob->shapeflag & OB_SHAPE_LOCK) {
/* shape locked, copy the locked shape instead of blending */
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 86927609ff6..582c164a776 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -275,7 +275,7 @@ Lattice *BKE_lattice_copy(Lattice *lt)
ltn->def = MEM_dupallocN(lt->def);
ltn->key = BKE_key_copy(ltn->key);
- if (ltn->key) ltn->key->from = (ID *)ltn;
+ BKE_key_set_from_id(ltn->key, (ID *)ltn);
if (lt->dvert) {
int tot = lt->pntsu * lt->pntsv * lt->pntsw;
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 1047710bfa4..4ab019f2128 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -571,7 +571,7 @@ Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me)
men->bb = MEM_dupallocN(men->bb);
men->key = BKE_key_copy(me->key);
- if (men->key) men->key->from = (ID *)men;
+ BKE_key_set_from_id(men->key, (ID *)men);
if (me->id.lib) {
BKE_id_lib_local_paths(bmain, me->id.lib, &men->id);