[Bf-blender-cvs] [fdd1dfb] gooseberry: Unified code for identifying unconventional shapekey owners between gooseberry and alembic branches.

Lukas Tönne noreply at git.blender.org
Tue May 19 15:06:48 CEST 2015


Commit: fdd1dfb657386fd8042beeb7d4f3b35ed1fa72d7
Author: Lukas Tönne
Date:   Tue May 19 14:50:52 2015 +0200
Branches: gooseberry
https://developer.blender.org/rBfdd1dfb657386fd8042beeb7d4f3b35ed1fa72d7

Unified code for identifying unconventional shapekey owners between
gooseberry and alembic 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.

This patch unifies the approach in both branches to make it slightly
less messy and avoid merge conflicts.

===================================================================

M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/object/object_shapekey.c
M	source/blender/makesdna/DNA_key_types.h
M	source/blender/makesrna/intern/rna_key.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 906964c..45571fe 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -52,7 +52,7 @@ 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_add_particles(struct Object *ob, struct ParticleSystem *psys);
 struct Key *BKE_key_copy(struct Key *key);
 struct Key *BKE_key_copy_nolib(struct Key *key);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 08eb0a8..c0340f1 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/key.c b/source/blender/blenkernel/intern/key.c
index 413ba00..65228ec 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -106,7 +106,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;
@@ -114,28 +114,27 @@ 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_OWNER_PARTICLES:
+			numelem = 3;
+			elemtype = IPO_FLOAT;
+			elemsize = 12;
 			break;
-		case KEY_FROMTYPE_STRANDS:
+		case KEY_OWNER_CACHELIB:
 			numelem = 3;
 			elemtype = IPO_FLOAT;
 			elemsize = 12;
@@ -148,7 +147,7 @@ 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;
 	
@@ -157,41 +156,30 @@ Key *BKE_key_add_ex(ID *from, short fromtype)    /* common function */
 	key->type = KEY_NORMAL;
 	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_add_particles(Object *ob, ParticleSystem *psys)    /* particles are "special" */
 {
-	Key *key;
-	char *el;
-	
-	key = BKE_libblock_alloc(G.main, ID_KE, "Key");
-	
-	key->type = KEY_NORMAL;
-	BKE_key_set_from_particles(key, ob, psys);
-	key->fromtype = KEY_FROMTYPE_ID;
-	
-	key->uidgen = 1;
-	
-	el = key->elemstr;
-	
-	el[0] = 3;
-	el[1] = IPO_FLOAT;
-	el[2] = 0;
-	
-	key->elemsize = 12;
-	
-	return key;
+	return BKE_key_add_ex((ID *)ob, KEY_OWNER_PARTICLES, BLI_findindex(&ob->particlesystem, psys));
 }
 
 Key *BKE_key_copy(Key *key)
@@ -303,11 +291,11 @@ void BKE_key_set_from_id(Key *key, ID *id)
 	if (key) {
 		key->from = id;
 		switch (GS(id->name)) {
-			case ID_ME: key->from_extra.type = KEY_OWNER_MESH; break;
-			case ID_CU: key->from_extra.type = KEY_OWNER_CURVE; break;
-			case ID_LT: key->from_extra.type = KEY_OWNER_LATTICE; break;
+			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->from_extra.index = -1;
+		key->fromindex = -1;
 	}
 }
 
@@ -315,8 +303,8 @@ void BKE_key_set_from_particles(Key *key, Object *ob, ParticleSystem *psys)
 {
 	if (key) {
 		key->from = (ID *)ob;
-		key->from_extra.type = KEY_OWNER_PARTICLES;
-		key->from_extra.index = BLI_findindex(&ob->particlesystem, psys);
+		key->fromtype = KEY_OWNER_PARTICLES;
+		key->fromindex = BLI_findindex(&ob->particlesystem, psys);
 	}
 }
 
@@ -584,7 +572,7 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **
 	if (kb == actkb) {
 		/* this hack makes it possible to edit shape keys in
 		 * edit mode with shape keys blending applied */
-		if (key->from && key->from_extra.type == KEY_OWNER_MESH) {
+		if (key->from && key->fromtype == KEY_OWNER_MESH) {
 			Mesh *me;
 			BMVert *eve;
 			BMIter iter;
@@ -616,45 +604,41 @@ 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 (key->from_extra.type) {
-				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_OWNER_PARTICLES:
-					*ofs = sizeof(float) * 3;
-					*poinsize = *ofs;
-					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_PARTICLES:
+			*ofs = sizeof(float) * 3;
+			*poinsize = *ofs;
+			break;
+		case KEY_OWNER_CACHELIB:
 			*ofs = sizeof(float) * 3;
 			*poinsize = *ofs;
 			break;
+			
+		default:
+			BLI_assert(!"invalid 'key->from' ID type");
+			return false;
 	}
 	return true;
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 46df3f4..32f0e89 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -125,9 +125,9 @@
 #include "BKE_fcurve.h"
 #include "BKE_global.h" // for G
 #include "BKE_group.h"
+#include "BKE_key.h"
 #include "BKE_library.h" // for which_libbase
 #include "BKE_idcode.h"
-#include "BKE_key.h"
 #include "BKE_material.h"
 #include "BKE_main.h" // for Main
 #include "BKE_mesh.h" // for ME_ defines (patching)
@@ -3262,8 +3262,8 @@ static void lib_link_key(FileData *fd, Main *main)
 			
 			key->ipo = newlibadr_us(fd, key->id.lib, key->ipo); // XXX deprecated - old animation system
 			key->from = newlibadr(fd, key->id.lib, key->from);
-			/* versioning: initialize from_extra */
-			if (!key->from_extra.type && key->from) {
+			/* versioning: initialize extra owner info */
+			if (!key->fromtype && key->from) {
 				BKE_key_set_from_id(key, key->from);
 			}
 			
diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c
index 043f62d..af0bf26 100644
--- a/source/blender/editors/object/object_shapekey.c
+++ b/source/blender/editors/object/object_shapekey.c
@@ -100,9 +100,9 @@ static bool ED_object_shape_key_remove_all(Main *bmain, Object *ob)
 		return false;
 	
 	if (key->from) {
-		switch (key->from_extra.type) {
-			case KEY_OWNER_MESH: ((Mesh *)key->from)->key    = NULL; break;
-			case KEY_OWNER_CURVE: ((Curve *)key->from)->key   = NULL; break;
+		switch (key->fromtype) {
+			case KEY_OWNER_MESH: ((Mesh *)key->from)->key       = NULL; break;
+			case KEY_OWNER_CURVE: ((Curve *)key->from)->key     = NULL; break;
 			case KEY_OWNER_LATTICE: ((Lattice *)key->from)->key = NULL; break;
 		}
 	}
@@ -167,7 +167,7 @@ static bool ED_object_shape_key_remove(Main *bmain, Object *ob)
 	
 	if (key->totkey == 0) {
 		if (key->from) {
-			switch (key->from_extra.type) {
+			switch (key->fromtype) {
 				case KEY_OWNER_MESH: ((Mesh *)key->from)->key    = NULL; break;
 				case KEY_OWNER_CURVE: ((Curve *)key->from)->key   = NULL; break;
 				case KEY_OWNER_LATTICE: ((Lattice *)key->from)->key = NULL; break;
diff --git a/source

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list