[Bf-blender-cvs] [f208502] hair_immediate_fixes: Replaced the single `ID *from` pointer in shape keys with a more detailed `owner` struct.

Lukas Tönne noreply at git.blender.org
Fri Oct 3 14:20:36 CEST 2014


Commit: f208502fb314cbbd8394d1554a231f1fc40bd8dc
Author: Lukas Tönne
Date:   Fri Oct 3 14:04:42 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rBf208502fb314cbbd8394d1554a231f1fc40bd8dc

Replaced the single `ID *from` pointer in shape keys with a more
detailed `owner` struct.

This allows distinction of classic ID block shape keys from particle
system keys.

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

M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/library_query.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_270.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 b0e2f49..4b3d582 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -52,12 +52,15 @@ 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_particles(struct ID *id);
+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);
 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        BKE_key_set_from_particles(struct Key *key, struct Object *ob, struct ParticleSystem *psys);
+
 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/curve.c b/source/blender/blenkernel/intern/curve.c
index ca58035..5b6abbf 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 96923e7..ee1433d 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -110,7 +110,7 @@ Key *BKE_key_add(ID *id)    /* common function */
 	key = BKE_libblock_alloc(G.main, ID_KE, "Key");
 	
 	key->type = KEY_NORMAL;
-	key->from = id;
+	BKE_key_set_from_id(key, id);
 
 	key->uidgen = 1;
 	
@@ -151,7 +151,7 @@ Key *BKE_key_add(ID *id)    /* common function */
 	return key;
 }
 
-Key *BKE_key_add_particles(ID *id)    /* particles are "special" */
+Key *BKE_key_add_particles(Object *ob, ParticleSystem *psys)    /* particles are "special" */
 {
 	Key *key;
 	char *el;
@@ -159,11 +159,10 @@ Key *BKE_key_add_particles(ID *id)    /* particles are "special" */
 	key = BKE_libblock_alloc(G.main, ID_KE, "Key");
 	
 	key->type = KEY_NORMAL;
-	key->from = id;
+	BKE_key_set_from_particles(key, ob, psys);
 	
 	key->uidgen = 1;
 	
-	BLI_assert(GS(id->name) == ID_OB);
 	el = key->elemstr;
 	
 	el[0] = 3;
@@ -275,6 +274,28 @@ void BKE_key_sort(Key *key)
 	key->refkey = key->block.first;
 }
 
+void BKE_key_set_from_id(Key *key, ID *id)
+{
+	if (key) {
+		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;
+		}
+		key->owner.id = id;
+		key->owner.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);
+	}
+}
+
 /**************** do the key ****************/
 
 void key_curve_position_weights(float t, float data[4], int type)
@@ -539,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 (GS(key->from->name) == ID_ME) {
+		if (key->owner.type == KEY_OWNER_MESH) {
 			Mesh *me;
 			BMVert *eve;
 			BMIter iter;
 			float (*co)[3];
 			int a;
 
-			me = (Mesh *)key->from;
+			me = (Mesh *)key->owner.id;
 
 			if (me->edit_btmesh && me->edit_btmesh->bm->totvert == kb->totelem) {
 				a = 0;
@@ -571,20 +592,16 @@ 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)
 {
-	if (key->from == NULL) {
-		return false;
-	}
-
-	switch (GS(key->from->name)) {
-		case ID_ME:
+	switch (key->owner.type) {
+		case KEY_OWNER_MESH:
 			*ofs = sizeof(float) * 3;
 			*poinsize = *ofs;
 			break;
-		case ID_LT:
+		case KEY_OWNER_LATTICE:
 			*ofs = sizeof(float) * 3;
 			*poinsize = *ofs;
 			break;
-		case ID_CU:
+		case KEY_OWNER_CURVE:
 			if (mode == KEY_MODE_BPOINT) {
 				*ofs = sizeof(float) * 4;
 				*poinsize = *ofs;
@@ -593,13 +610,17 @@ static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int
 				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;
 	}
-
+	
 	return true;
 }
 
@@ -1527,7 +1548,7 @@ float *BKE_key_evaluate_object_ex(Scene *scene, Object *ob, int *r_totelem,
 	}
 
 	/* 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 */
@@ -1606,7 +1627,7 @@ float *BKE_key_evaluate_particles_ex(Object *ob, ParticleSystem *psys, int *r_to
 	}
 	
 	/* prevent python from screwing this up? anyhoo, the from pointer could be dropped */
-	key->from = (ID *)ob; // XXX the "from" pointer needs to be amended to support particle system properly
+	BKE_key_set_from_particles(key, ob, psys);
 	
 	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 3f12e3e..1a367c7 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -274,7 +274,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/library_query.c b/source/blender/blenkernel/intern/library_query.c
index 6d2e2f1..aa16bc0 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->from, IDWALK_NOP);
+			CALLBACK_INVOKE_ID(key->owner.id, IDWALK_NOP);
 			break;
 		}
 
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 2e80379..e5e1067 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -560,7 +560,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);
 
 	return men;
 }
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 67ae3f5..ffdeb23 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -359,14 +359,14 @@ int psys_uses_gravity(ParticleSimulationData *sim)
 	return sim->scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY && sim->psys->part && sim->psys->part->effector_weights->global_gravity != 0.0f;
 }
 
-KeyBlock *BKE_psys_insert_shape_key(Scene *scene, Object *ob, ParticleSystem *psys, const char *name, const bool from_mix)
+KeyBlock *BKE_psys_insert_shape_key(Scene *UNUSED(scene), Object *ob, ParticleSystem *psys, const char *name, const bool from_mix)
 {
 	Key *key = psys->key;
 	KeyBlock *kb;
 	int newkey = 0;
 
 	if (key == NULL) {
-		key = psys->key = BKE_key_add_particles((ID *)ob);
+		key = psys->key = BKE_key_add_particles(ob, psys);
 		key->type = KEY_RELATIVE;
 		newkey = 1;
 	}
@@ -3542,7 +3542,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n
 	BLI_addtail(&ob->particlesystem, psys);
 
 	psys->part = psys_new_settings(DATA_("ParticleSettings"), NULL);
-	psys->key = BKE_key_add_particles((ID *)ob);
+	psys->key = BKE_key_add_particles(ob, psys);
 	psys->key->type = KEY_RELATIVE;
 
 	if (BLI_countlist(&ob->particlesystem) > 1)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a953d66..66019ff 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3070,7 +3070,7 @@ 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->from = newlibadr(fd, key->id.lib, key->from);
+			key->owner.id = newlibadr(fd, key->id.lib, key->owner.id);
 			
 			key->id.flag -= LIB_NEED_LINK;
 		}
@@ -3114,7 +3114,7 @@ static void direct_link_key(FileData *fd, Key *key)
 	
 	key->adt = newdataadr(fd, key->adt);
 	direct_link_animdata(fd, key->adt);
-		
+	
 	key->refkey= newdataadr(fd, key->refkey);
 	
 	for (kb = key->block.first; kb; kb = kb->next) {
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index ddc846d..a365c1b 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -37,6 +37,7 @@
 #include "DNA_brush_types.h"
 #include "DNA_cloth_types.h"
 #include "DNA_constraint_types.h"
+#include "DNA_key_types.h"
 #include "DNA_sdna_types.h"
 #include "DNA_space_types.h"
 #include "DNA_screen_types.h"
@@ -52,6 +53,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 
+#include "BKE_key.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
 
@@ -414,4 +416,11 @@ void blo_do_versions_270(F

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list