[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11608] trunk/blender/source/blender/src/ editconstraint.c: == Child-Of Constraint ==

Joshua Leung aligorith at gmail.com
Wed Aug 15 06:59:46 CEST 2007


Revision: 11608
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11608
Author:   aligorith
Date:     2007-08-15 06:59:46 +0200 (Wed, 15 Aug 2007)

Log Message:
-----------
== Child-Of Constraint ==

Now 'Set Inverse' works correctly for PoseChannels in all cases. Previously, it was still using a temporary hack that failed when 'parent' bone had any transforms.

Modified Paths:
--------------
    trunk/blender/source/blender/src/editconstraint.c

Modified: trunk/blender/source/blender/src/editconstraint.c
===================================================================
--- trunk/blender/source/blender/src/editconstraint.c	2007-08-15 04:32:40 UTC (rev 11607)
+++ trunk/blender/source/blender/src/editconstraint.c	2007-08-15 04:59:46 UTC (rev 11608)
@@ -1026,17 +1026,12 @@
 	
 	/* calculate/set inverse matrix */
 	if (pchan) {
-		/* for now, just use pchan->constinv.
-		 * NOTE: bad hack... doesn't work in many cases
-		 */
-		//Mat4CpyMat4(data->invmat, pchan->constinv);
-		
 		bConstraintOb *cob;
 		float ctime= bsystem_time(ob, (float)G.scene->r.cfra, 0.0);	/* not accurate... */
 		float pmat[4][4], chmat[4][4], cimat[4][4];
 		float vec0[3]={0,0,0}, vec1[3]={1,1,1};
 		
-		/* make copies of pchan's original matrices */
+		/* make copies of pchan's original matrices (to be restored later) */
 		Mat4CpyMat4(pmat, pchan->pose_mat);
 		Mat4CpyMat4(chmat, pchan->chan_mat);
 		Mat4CpyMat4(cimat, pchan->constinv);
@@ -1048,15 +1043,28 @@
 		Mat4One(pchan->constinv);
 		Mat4One(data->invmat);
 		
-		/* do constraint solving - code copied from armature.c (where_is_pose_bone) */
+		
+		/* do constraint solving on pose-matrix containing no transforms
+		 *	 N.B. code is copied from armature.c (where_is_pose_bone) 
+		 */
 		cob= constraints_make_evalob(ob, pchan, TARGET_BONE);
 		solve_constraints(&pchan->constraints, cob, ctime);
 		constraints_clear_evalob(cob);
 		
-		/* now set inverse */
-		Mat4CpyMat4(data->invmat, pchan->constinv);
 		
-		/* reset data */
+		/* parent-inverse matrix for this constraint is given by taking the 
+		 * local-space (i.e. without any standard parents + restpose) pose_matrix
+		 * (that was calulated with no transforms applied), and inverting it.
+		 */
+		Mat4CpyMat4(pchan->constinv, pchan->pose_mat);
+		
+		constraint_mat_convertspace(ob, pchan, pchan->constinv, 
+				CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL);
+				
+		Mat4Invert(data->invmat, pchan->constinv);
+		
+		
+		/* restore original matrices of pchan */
 		Mat4CpyMat4(pchan->pose_mat, pmat);
 		Mat4CpyMat4(pchan->chan_mat, chmat);
 		Mat4CpyMat4(pchan->constinv, cimat);





More information about the Bf-blender-cvs mailing list