[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13136] trunk/blender/source/blender/src/ editconstraint.c: Bugfix #7793: ChildOf Constraint works bad for bones

Joshua Leung aligorith at gmail.com
Sat Jan 5 11:01:06 CET 2008


Revision: 13136
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13136
Author:   aligorith
Date:     2008-01-05 11:01:05 +0100 (Sat, 05 Jan 2008)

Log Message:
-----------
Bugfix #7793: ChildOf Constraint works bad for bones

I hope this time I've fixed it once and for all. The cases which use to fail seem to work now, so I assume it's now fixed. In case it isn't, I'll leave the bug report open for a few days first.

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

Modified: trunk/blender/source/blender/src/editconstraint.c
===================================================================
--- trunk/blender/source/blender/src/editconstraint.c	2008-01-05 09:31:43 UTC (rev 13135)
+++ trunk/blender/source/blender/src/editconstraint.c	2008-01-05 10:01:05 UTC (rev 13136)
@@ -927,48 +927,30 @@
 	
 	/* calculate/set inverse matrix */
 	if (pchan) {
-		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};
+		float pmat[4][4], cinf;
+		float imat[4][4], tmat[4][4];
 		
-		/* make copies of pchan's original matrices (to be restored later) */
+		/* make copy of pchan's original pose-mat (for use later) */
 		Mat4CpyMat4(pmat, pchan->pose_mat);
-		Mat4CpyMat4(chmat, pchan->chan_mat);
-		Mat4CpyMat4(cimat, pchan->constinv);
 		
+		/* disable constraint for pose to be solved without it */
+		cinf= con->enforce;
+		con->enforce= 0.0f;
 		
-		/* clear pchan's transform (for constraint solving) */
-		LocEulSizeToMat4(pchan->chan_mat, vec0, vec0, vec1);
-		Mat4MulMat4(pchan->pose_mat, pmat, cimat);
-		Mat4One(pchan->constinv);
-		Mat4One(data->invmat);
+		/* solve pose without constraint */
+		where_is_pose(ob);
 		
-		
-		/* do constraint solving on pose-matrix containing no transforms
-		 *	 N.B. code is copied from armature.c (where_is_pose_bone) 
+		/* determine effect of constraint by removing the newly calculated 
+		 * pchan->pose_mat from the original pchan->pose_mat, thus determining 
+		 * the effect of the constraint
 		 */
-		cob= constraints_make_evalob(ob, pchan, CONSTRAINT_OBTYPE_BONE);
-		solve_constraints(&pchan->constraints, cob, ctime);
-		constraints_clear_evalob(cob);
+		Mat4Invert(imat, pchan->pose_mat);
+		Mat4MulMat4(tmat, imat, pmat);
+		Mat4Invert(data->invmat, tmat);
 		
-		
-		/* 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);
+		/* recalculate pose with new inv-mat */
+		con->enforce= cinf;
+		where_is_pose(ob);
 	}
 	else if (ob) {
 		/* use what_does_parent to find inverse - just like for normal parenting.





More information about the Bf-blender-cvs mailing list