[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24841] trunk/blender/source/blender: added a function to duplicate bPoseChannel's internal data - constraints, id-props etc.

Campbell Barton ideasman42 at gmail.com
Tue Nov 24 00:03:07 CET 2009


Revision: 24841
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24841
Author:   campbellbarton
Date:     2009-11-24 00:03:04 +0100 (Tue, 24 Nov 2009)

Log Message:
-----------
added a function to duplicate bPoseChannel's internal data - constraints, id-props etc.
 duplicate_pose_channel_data(), the code to do this was inline in editarmature.c

duplicating editbones now duplicates posebone id-props

also removed an if test for &channew->constraints since it will always be true.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_action.h
    trunk/blender/source/blender/blenkernel/intern/action.c
    trunk/blender/source/blender/editors/armature/editarmature.c

Modified: trunk/blender/source/blender/blenkernel/BKE_action.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_action.h	2009-11-23 21:17:53 UTC (rev 24840)
+++ trunk/blender/source/blender/blenkernel/BKE_action.h	2009-11-23 23:03:04 UTC (rev 24841)
@@ -140,8 +140,12 @@
  */ 
 void copy_pose(struct bPose **dst, struct bPose *src, int copyconstraints);
 
+/**
+ * Copy the internal members of each pose channel including constraints
+ * and ID-Props, used when duplicating bones in editmode.
+ */
+void duplicate_pose_channel_data(struct bPoseChannel *pchan, const struct bPoseChannel *pchan_from);
 
-
 /**
  * Return a pointer to the pose channel of the given name
  * from this pose.

Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c	2009-11-23 21:17:53 UTC (rev 24840)
+++ trunk/blender/source/blender/blenkernel/intern/action.c	2009-11-23 23:03:04 UTC (rev 24841)
@@ -640,6 +640,48 @@
 	}
 }
 
+/* makes copies of internal data, unlike copy_pose_channel_data which only
+ * copies the pose state.
+ * hint: use when copying bones in editmode (on returned value from verify_pose_channel) */
+void duplicate_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *pchan_from)
+{
+	/* copy transform locks */
+	pchan->protectflag = pchan_from->protectflag;
+
+	/* copy rotation mode */
+	pchan->rotmode = pchan_from->rotmode;
+
+	/* copy bone group */
+	pchan->agrp_index= pchan_from->agrp_index;
+
+	/* ik (dof) settings */
+	pchan->ikflag = pchan_from->ikflag;
+	VECCOPY(pchan->limitmin, pchan_from->limitmin);
+	VECCOPY(pchan->limitmax, pchan_from->limitmax);
+	VECCOPY(pchan->stiffness, pchan_from->stiffness);
+	pchan->ikstretch= pchan_from->ikstretch;
+	pchan->ikrotweight= pchan_from->ikrotweight;
+	pchan->iklinweight= pchan_from->iklinweight;
+
+	/* constraints */
+	copy_constraints(&pchan->constraints, &pchan_from->constraints);
+
+	/* id-properties */
+	if(pchan->prop) {
+		/* unlikely but possible it exists */
+		IDP_FreeProperty(pchan->prop);
+		MEM_freeN(pchan->prop);
+		pchan->prop= NULL;
+	}
+	if(pchan_from->prop) {
+		pchan->prop= IDP_CopyProperty(pchan_from->prop);
+	}
+
+	/* custom shape */
+	pchan->custom= pchan_from->custom;
+}
+
+
 /* checks for IK constraint, Spline IK, and also for Follow-Path constraint.
  * can do more constraints flags later 
  */

Modified: trunk/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature.c	2009-11-23 21:17:53 UTC (rev 24840)
+++ trunk/blender/source/blender/editors/armature/editarmature.c	2009-11-23 23:03:04 UTC (rev 24841)
@@ -2599,40 +2599,16 @@
 	 */
 	if (src_ob->pose) {
 		bPoseChannel *chanold, *channew;
-		ListBase     *listold, *listnew;
 		
 		chanold = verify_pose_channel(src_ob->pose, curBone->name);
 		if (chanold) {
-			listold = &chanold->constraints;
-			if (listold) {
-				/* WARNING: this creates a new posechannel, but there will not be an attached bone 
-				 *		yet as the new bones created here are still 'EditBones' not 'Bones'. 
-				 */
-				channew = 
-					verify_pose_channel(dst_ob->pose, eBone->name);
-				if (channew) {
-					/* copy transform locks */
-					channew->protectflag = chanold->protectflag;
-					
-					/* copy bone group */
-					channew->agrp_index= chanold->agrp_index;
-					
-					/* ik (dof) settings */
-					channew->ikflag = chanold->ikflag;
-					VECCOPY(channew->limitmin, chanold->limitmin);
-					VECCOPY(channew->limitmax, chanold->limitmax);
-					VECCOPY(channew->stiffness, chanold->stiffness);
-					channew->ikstretch= chanold->ikstretch;
-					channew->ikrotweight= chanold->ikrotweight;
-					channew->iklinweight= chanold->iklinweight;
-					
-					/* constraints */
-					listnew = &channew->constraints;
-					copy_constraints(listnew, listold);
-					
-					/* custom shape */
-					channew->custom= chanold->custom;
-				}
+			/* WARNING: this creates a new posechannel, but there will not be an attached bone
+			 *		yet as the new bones created here are still 'EditBones' not 'Bones'.
+			 */
+			channew= verify_pose_channel(dst_ob->pose, eBone->name);
+
+			if(channew) {
+				duplicate_pose_channel_data(channew, chanold);
 			}
 		}
 	}
@@ -2701,43 +2677,15 @@
 				 */
 				if (obedit->pose) {
 					bPoseChannel *chanold, *channew;
-					ListBase     *listold, *listnew;
 					
 					chanold = verify_pose_channel(obedit->pose, curBone->name);
 					if (chanold) {
-						listold = &chanold->constraints;
-						if (listold) {
-							/* WARNING: this creates a new posechannel, but there will not be an attached bone 
-							 *		yet as the new bones created here are still 'EditBones' not 'Bones'. 
-							 */
-							channew = 
-								verify_pose_channel(obedit->pose, eBone->name);
-							if (channew) {
-								/* copy transform locks */
-								channew->protectflag = chanold->protectflag;
-								
-								/* copy rotation mode */
-								channew->rotmode = chanold->rotmode;
-								
-								/* copy bone group */
-								channew->agrp_index= chanold->agrp_index;
-								
-								/* ik (dof) settings */
-								channew->ikflag = chanold->ikflag;
-								VECCOPY(channew->limitmin, chanold->limitmin);
-								VECCOPY(channew->limitmax, chanold->limitmax);
-								VECCOPY(channew->stiffness, chanold->stiffness);
-								channew->ikstretch= chanold->ikstretch;
-								channew->ikrotweight= chanold->ikrotweight;
-								channew->iklinweight= chanold->iklinweight;
-								
-								/* constraints */
-								listnew = &channew->constraints;
-								copy_constraints(listnew, listold);
-								
-								/* custom shape */
-								channew->custom= chanold->custom;
-							}
+						/* WARNING: this creates a new posechannel, but there will not be an attached bone
+						 *		yet as the new bones created here are still 'EditBones' not 'Bones'.
+						 */
+						channew= verify_pose_channel(obedit->pose, eBone->name);
+						if(channew) {
+							duplicate_pose_channel_data(channew, chanold);
 						}
 					}
 				}





More information about the Bf-blender-cvs mailing list