[Bf-blender-cvs] [afa23b3] hair_immediate_fixes: Compatibility fix for shape keys.

Lukas Tönne noreply at git.blender.org
Sat Oct 11 11:23:09 CEST 2014


Commit: afa23b3919cad503a3970feee8bf6cb5ee702994
Author: Lukas Tönne
Date:   Sat Oct 11 11:21:31 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rBafa23b3919cad503a3970feee8bf6cb5ee702994

Compatibility fix for shape keys.

Avoid moving the 'from' pointer around in DNA. This way files stay back-
as well as forward-compatible. Only the additional type enum and
sub-index is stored in a new from_extra struct in shape keys now.

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

M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/library_query.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/intern/key.c b/source/blender/blenkernel/intern/key.c
index ee1433d..62310c3 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -277,22 +277,22 @@ void BKE_key_sort(Key *key)
 void BKE_key_set_from_id(Key *key, ID *id)
 {
 	if (key) {
+		key->from = id;
 		switch (GS(id->name)) {
-			case ID_ME: key->owner.type = KEY_OWNER_MESH; break;
-			case ID_CU: key->owner.type = KEY_OWNER_CURVE; break;
-			case ID_LT: key->owner.type = KEY_OWNER_LATTICE; break;
+			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;
 		}
-		key->owner.id = id;
-		key->owner.index = -1;
+		key->from_extra.index = -1;
 	}
 }
 
 void BKE_key_set_from_particles(Key *key, Object *ob, ParticleSystem *psys)
 {
 	if (key) {
-		key->owner.type = KEY_OWNER_PARTICLES;
-		key->owner.id = (ID *)ob;
-		key->owner.index = BLI_findindex(&ob->particlesystem, psys);
+		key->from = (ID *)ob;
+		key->from_extra.type = KEY_OWNER_PARTICLES;
+		key->from_extra.index = BLI_findindex(&ob->particlesystem, psys);
 	}
 }
 
@@ -560,14 +560,14 @@ 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->owner.type == KEY_OWNER_MESH) {
+		if (key->from_extra.type == KEY_OWNER_MESH) {
 			Mesh *me;
 			BMVert *eve;
 			BMIter iter;
 			float (*co)[3];
 			int a;
 
-			me = (Mesh *)key->owner.id;
+			me = (Mesh *)key->from;
 
 			if (me->edit_btmesh && me->edit_btmesh->bm->totvert == kb->totelem) {
 				a = 0;
@@ -592,7 +592,7 @@ 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)
 {
-	switch (key->owner.type) {
+	switch (key->from_extra.type) {
 		case KEY_OWNER_MESH:
 			*ofs = sizeof(float) * 3;
 			*poinsize = *ofs;
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index aa16bc0..6d2e2f1 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -360,7 +360,7 @@ void BKE_library_foreach_ID_link(ID *id, LibraryIDLinkCallback callback, void *u
 		case ID_KE:
 		{
 			Key *key = (Key *) id;
-			CALLBACK_INVOKE_ID(key->owner.id, IDWALK_NOP);
+			CALLBACK_INVOKE_ID(key->from, IDWALK_NOP);
 			break;
 		}
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9acd61e..f5f9b73 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3071,12 +3071,10 @@ static void lib_link_key(FileData *fd, Main *main)
 			if (key->adt) lib_link_animdata(fd, &key->id, key->adt);
 			
 			key->ipo = newlibadr_us(fd, key->id.lib, key->ipo); // XXX deprecated - old animation system
-			key->owner.id = newlibadr(fd, key->id.lib, key->owner.id);
-			/* versioning: initialize owner */
-			if (!key->owner.id && key->from) {
-				ID *id = newlibadr(fd, key->id.lib, key->from);
-				BKE_key_set_from_id(key, id);
-				key->from = NULL;
+			key->from = newlibadr(fd, key->id.lib, key->from);
+			/* versioning: initialize from_extra */
+			if (!key->from_extra.type && key->from) {
+				BKE_key_set_from_id(key, key->from);
 			}
 			
 			key->id.flag -= LIB_NEED_LINK;
diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c
index d949c1e..17377c1 100644
--- a/source/blender/editors/object/object_shapekey.c
+++ b/source/blender/editors/object/object_shapekey.c
@@ -98,10 +98,10 @@ static bool ED_object_shape_key_remove_all(Main *bmain, Object *ob)
 	if (key == NULL)
 		return false;
 	
-	switch (key->owner.type) {
-		case KEY_OWNER_MESH: ((Mesh *)key->owner.id)->key       = NULL; break;
-		case KEY_OWNER_CURVE: ((Curve *)key->owner.id)->key     = NULL; break;
-		case KEY_OWNER_LATTICE: ((Lattice *)key->owner.id)->key = NULL; break;
+	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;
+		case KEY_OWNER_LATTICE: ((Lattice *)key->from)->key = NULL; break;
 	}
 	
 	BKE_libblock_free_us(bmain, key);
@@ -156,10 +156,10 @@ static bool ED_object_shape_key_remove(Main *bmain, Object *ob)
 	}
 	
 	if (key->totkey == 0) {
-		switch (key->owner.type) {
-			case KEY_OWNER_MESH: ((Mesh *)key->owner.id)->key       = NULL; break;
-			case KEY_OWNER_CURVE: ((Curve *)key->owner.id)->key     = NULL; break;
-			case KEY_OWNER_LATTICE: ((Lattice *)key->owner.id)->key = NULL; break;
+		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;
+			case KEY_OWNER_LATTICE: ((Lattice *)key->from)->key = NULL; break;
 		}
 
 		BKE_libblock_free_us(bmain, key);
diff --git a/source/blender/makesdna/DNA_key_types.h b/source/blender/makesdna/DNA_key_types.h
index 40ef506..0a2c06e 100644
--- a/source/blender/makesdna/DNA_key_types.h
+++ b/source/blender/makesdna/DNA_key_types.h
@@ -69,13 +69,13 @@ typedef struct KeyBlock {
 
 } KeyBlock;
 
-typedef struct KeyOwner {
-	ID *id;
+typedef struct KeyFrom {
 	int type;
 	int index; /* index of owner in the id */
-} KeyOwner;
+} KeyFrom;
 
 typedef enum eKeyOwnerType {
+	/* 0 used as 'undefined', for versioning */
 	KEY_OWNER_MESH          = 1,
 	KEY_OWNER_CURVE         = 2,
 	KEY_OWNER_LATTICE       = 3,
@@ -101,8 +101,8 @@ typedef struct Key {
 	ListBase block;  /* list of KeyBlock's */
 	struct Ipo *ipo  DNA_DEPRECATED;  /* old animation system, deprecated for 2.5 */
 
-	KeyOwner owner;
-	ID *from DNA_DEPRECATED; /* included in owner */
+	ID *from;
+	KeyFrom from_extra;     /* supplementary info about the 'from' datablock */
 
 	short type;    /* absolute or relative shape key */
 	short totkey;  /* (totkey == BLI_countlist(&key->block)) */
diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c
index 9691308..97b3a9a 100644
--- a/source/blender/makesrna/intern/rna_key.c
+++ b/source/blender/makesrna/intern/rna_key.c
@@ -304,8 +304,8 @@ static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA
 	Nurb *nu;
 	int tot = kb->totelem, size = key->elemsize;
 	
-	if (key->owner.type == KEY_OWNER_CURVE) {
-		cu = (Curve *)key->owner.id;
+	if (key->from_extra.type == KEY_OWNER_CURVE) {
+		cu = (Curve *)key->from;
 		nu = cu->nurb.first;
 		
 		if (nu->bezt) {
@@ -325,8 +325,8 @@ static int rna_ShapeKey_data_length(PointerRNA *ptr)
 	Nurb *nu;
 	int tot = kb->totelem;
 	
-	if (key->owner.type == KEY_OWNER_CURVE) {
-		cu = (Curve *)key->owner.id;
+	if (key->from_extra.type == KEY_OWNER_CURVE) {
+		cu = (Curve *)key->from;
 		nu = cu->nurb.first;
 		
 		if (nu->bezt)
@@ -343,8 +343,8 @@ static PointerRNA rna_ShapeKey_data_get(CollectionPropertyIterator *iter)
 	Curve *cu;
 	Nurb *nu;
 	
-	if (key->owner.type == KEY_OWNER_CURVE) {
-		cu = (Curve *)key->owner.id;
+	if (key->from_extra.type == KEY_OWNER_CURVE) {
+		cu = (Curve *)key->from;
 		nu = cu->nurb.first;
 		
 		if (nu->bezt)
@@ -377,7 +377,7 @@ static void rna_Key_update_data(Main *bmain, Scene *UNUSED(scene), PointerRNA *p
 	Key *key = ptr->id.data;
 	Object *ob;
 
-	switch (key->owner.type) {
+	switch (key->from_extra.type) {
 	case KEY_OWNER_MESH:
 	case KEY_OWNER_CURVE:
 	case KEY_OWNER_LATTICE:
@@ -679,7 +679,7 @@ static void rna_def_key(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "user", PROP_POINTER, PROP_NONE);
 	RNA_def_property_flag(prop, PROP_NEVER_NULL);
-	RNA_def_property_pointer_sdna(prop, NULL, "owner.id");
+	RNA_def_property_pointer_sdna(prop, NULL, "from");
 	RNA_def_property_ui_text(prop, "User", "Datablock using these shape keys");
 
 	prop = RNA_def_property(srna, "use_relative", PROP_BOOLEAN, PROP_NONE);




More information about the Bf-blender-cvs mailing list