[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41784] trunk/blender: Fix #29041: parenting problem with tree IK for iTaSC and iksolver, where it

Brecht Van Lommel brechtvanlommel at pandora.be
Sun Nov 13 14:08:15 CET 2011


Revision: 41784
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41784
Author:   blendix
Date:     2011-11-13 13:08:15 +0000 (Sun, 13 Nov 2011)
Log Message:
-----------
Fix #29041: parenting problem with tree IK for iTaSC and iksolver, where it
would use the wrong bone as parent on brancing. Patch by Juha Maki-Kanto.

Modified Paths:
--------------
    trunk/blender/intern/itasc/kdl/chain.hpp
    trunk/blender/source/blender/ikplugin/intern/iksolver_plugin.c
    trunk/blender/source/blender/ikplugin/intern/itasc_plugin.cpp

Modified: trunk/blender/intern/itasc/kdl/chain.hpp
===================================================================
--- trunk/blender/intern/itasc/kdl/chain.hpp	2011-11-13 13:04:46 UTC (rev 41783)
+++ trunk/blender/intern/itasc/kdl/chain.hpp	2011-11-13 13:08:15 UTC (rev 41784)
@@ -24,6 +24,7 @@
 
 #include "segment.hpp"
 #include <string>
+#include <Eigen/StdVector>
 
 namespace KDL {
     /**

Modified: trunk/blender/source/blender/ikplugin/intern/iksolver_plugin.c
===================================================================
--- trunk/blender/source/blender/ikplugin/intern/iksolver_plugin.c	2011-11-13 13:04:46 UTC (rev 41783)
+++ trunk/blender/source/blender/ikplugin/intern/iksolver_plugin.c	2011-11-13 13:08:15 UTC (rev 41784)
@@ -62,8 +62,8 @@
 	PoseTarget *target;
 	bConstraint *con;
 	bKinematicConstraint *data;
-	int a, segcount= 0, size, newsize, *oldparent, parent;
-	
+	int a, t, segcount= 0, size, newsize, *oldparent, parent;
+
 	/* find IK constraint, and validate it */
 	for(con= pchan_tip->constraints.first; con; con= con->next) {
 		if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
@@ -114,7 +114,7 @@
 	if(tree==NULL) {
 		/* make new tree */
 		tree= MEM_callocN(sizeof(PoseTree), "posetree");
-	
+
 		tree->type= CONSTRAINT_TYPE_KINEMATIC;
 		
 		tree->iterations= data->iterations;
@@ -138,13 +138,27 @@
 
 		/* skip common pose channels and add remaining*/
 		size= MIN2(segcount, tree->totchannel);
-		for(a=0; a<size && tree->pchan[a]==chanlist[segcount-a-1]; a++);
-		parent= a-1;
+		a = t = 0;
+		while (a<size && t<tree->totchannel) {
+			// locate first matching channel
+			for (;t<tree->totchannel && tree->pchan[t]!=chanlist[segcount-a-1];t++);
+			if (t>=tree->totchannel)
+				break;
+			for(; a<size && t<tree->totchannel && tree->pchan[t]==chanlist[segcount-a-1]; a++, t++);
+		}
 
 		segcount= segcount-a;
 		target->tip= tree->totchannel + segcount - 1;
 
 		if (segcount > 0) {
+			for(parent = a - 1; parent < tree->totchannel; parent++)
+				if(tree->pchan[parent] == chanlist[segcount-1]->parent)
+					break;
+			
+			/* shouldn't happen, but could with dependency cycles */
+			if(parent == tree->totchannel)
+				parent = a - 1;
+
 			/* resize array */
 			newsize= tree->totchannel + segcount;
 			oldchan= tree->pchan;

Modified: trunk/blender/source/blender/ikplugin/intern/itasc_plugin.cpp
===================================================================
--- trunk/blender/source/blender/ikplugin/intern/itasc_plugin.cpp	2011-11-13 13:04:46 UTC (rev 41783)
+++ trunk/blender/source/blender/ikplugin/intern/itasc_plugin.cpp	2011-11-13 13:08:15 UTC (rev 41784)
@@ -326,11 +326,19 @@
 				break;
 			for(; a<size && t<tree->totchannel && tree->pchan[t]==chanlist[segcount-a-1]; a++, t++);
 		}
-		parent= a-1;
+
 		segcount= segcount-a;
 		target->tip= tree->totchannel + segcount - 1;
 
 		if (segcount > 0) {
+			for(parent = a - 1; parent < tree->totchannel; parent++)
+				if(tree->pchan[parent] == chanlist[segcount-1]->parent)
+					break;
+			
+			/* shouldn't happen, but could with dependency cycles */
+			if(parent == tree->totchannel)
+				parent = a - 1;
+
 			/* resize array */
 			newsize= tree->totchannel + segcount;
 			oldchan= tree->pchan;




More information about the Bf-blender-cvs mailing list