[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58624] branches/ soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c: Shapekey transfer through vertices: fixing the shapkey' s name copy while transfer

Walid Shouman eng.walidshouman at gmail.com
Fri Jul 26 17:15:59 CEST 2013


Revision: 58624
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58624
Author:   walid
Date:     2013-07-26 15:15:58 +0000 (Fri, 26 Jul 2013)
Log Message:
-----------
Shapekey transfer through vertices: fixing the shapkey's name copy while transfer

Modified Paths:
--------------
    branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c

Modified: branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c	2013-07-26 13:45:25 UTC (rev 58623)
+++ branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c	2013-07-26 15:15:58 UTC (rev 58624)
@@ -333,6 +333,9 @@
 
 	Main *bmain = CTX_data_main(C);
 
+	KeyBlock *kb_src, *kb_dst;
+//	char kb_name[64];
+
 	//----- definitions for the raycasting
 	float tmp_mat[4][4];
 	//===== end of raycasting definitions
@@ -363,9 +366,21 @@
 			ED_object_shape_key_add(C, scene, ob_dst, false);
 		}
 
+		kb_src = me_src->key->block.first;
+		kb_dst = me_dst->key->block.first;
+
+		//add layers as needed
 		while (me_dst->key->totkey < me_src->key->totkey) {
 			ED_object_shape_key_add(C, scene, ob_dst, false);
 		}
+
+		//copy the names
+		for (i = 1; i < me_src->key->totkey; ++i) {
+			kb_src = kb_src->next;
+			kb_dst = kb_dst->next;
+
+			BLI_strncpy(kb_dst->name, kb_src->name, sizeof(kb_src->name));
+		}
 	}
 
 	//we'll tell the copy function to start copying from # of source keys from the end of the dst keys
@@ -376,9 +391,18 @@
 			ED_object_shape_key_add(C, scene, ob_dst, false);
 		}
 
+		kb_src = me_src->key->block.first;
+		kb_dst = me_dst->key->block.last;
+
 		//skip the src basis while appending
-		for (i = 1; i < me_src->key->totkey; i++) {
+		for (i = 1; i < me_src->key->totkey; ++i) {
+			kb_src = kb_src->next;
+
 			ED_object_shape_key_add(C, scene, ob_dst, false);
+			kb_dst = kb_dst->next;
+
+			//rename each appended layer
+			BLI_strncpy(kb_dst->name, kb_src->name, sizeof(kb_src->name));
 		}
 	}
 	//same message to be sent to the copy function as ST_REPLACE_ENOUGH_VERTEX_GROUPS
@@ -389,24 +413,51 @@
 			ED_object_shape_key_add(C, scene, ob_dst, false);
 		}
 
+		kb_src = me_src->key->block.first;
+		kb_dst = me_dst->key->block.first;
+
 		//start from 1 to skip deleting the basis
 		while (me_dst->key->totkey > 1) {
 			ED_object_shape_key_remove(bmain , ob_dst);
 		}
 
+		//add layers as needed
 		while (me_dst->key->totkey < me_src->key->totkey) {
 			ED_object_shape_key_add(C, scene, ob_dst, false);
 		}
+
+		//copy the names
+		for (i = 1; i < me_src->key->totkey; ++i) {
+			kb_src = kb_src->next;
+			kb_dst = kb_dst->next;
+
+			BLI_strncpy(kb_dst->name, kb_src->name, sizeof(kb_src->name));
+		}
 	}
 
 	else if (replace_mode == ST_REPLACE_ACTIVE_SHAPEKEY_GROUP) {
 
-		//check we've a 1)selected active shapekey 2)that isn't the basis,
-		while (ob_dst->shapenr < 2) {
-			ED_object_shape_key_add(C, scene, ob_dst, false);
-		}
+		if (ob_src->shapenr > 1) {
+			//find the source
+			kb_src = BLI_findlink(&me_src->key->block, ob_src->shapenr - 1);
 
-		if (ob_src->shapenr > 1) {
+			if (ob_dst->shapenr == 0) {	//empty destination
+				ED_object_shape_key_add(C, scene, ob_dst, false);
+			}
+
+			if (ob_dst->shapenr == 1) { //destination's basis is selected
+				ED_object_shape_key_add(C, scene, ob_dst, false);
+				kb_dst = ((KeyBlock *) me_dst->key->block.first)->next;
+
+				BLI_strncpy(kb_dst->name, kb_src->name, sizeof(kb_src->name));
+			}
+
+			else {		//another layer is selected
+				kb_dst = BLI_findlink(&me_dst->key->block, ob_dst->shapenr - 1);
+
+				BLI_strncpy(kb_dst->name, kb_src->name, sizeof(kb_src->name));
+			}
+
 			act_shapekey_lay[0] = ob_src->shapenr;
 			act_shapekey_lay[1] = ob_dst->shapenr;
 		}




More information about the Bf-blender-cvs mailing list