[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13144] trunk/blender/source/blender/src/ transform_conversions.c: == Auto-IK Improvement (Peach Request) ==

Joshua Leung aligorith at gmail.com
Sun Jan 6 08:40:38 CET 2008


Revision: 13144
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13144
Author:   aligorith
Date:     2008-01-06 08:40:37 +0100 (Sun, 06 Jan 2008)

Log Message:
-----------
== Auto-IK Improvement (Peach Request) ==

Auto-IK can now operate on more then 1 selected bone at once, (as long as they are not a part of the same chain). 

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

Modified: trunk/blender/source/blender/src/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/src/transform_conversions.c	2008-01-05 21:56:28 UTC (rev 13143)
+++ trunk/blender/source/blender/src/transform_conversions.c	2008-01-06 07:40:37 UTC (rev 13144)
@@ -787,10 +787,11 @@
 	if (pchan == NULL) 
 		return 0;
 	
-	/* rule: not if there's already an IK on this channel */
-	for (con= pchan->constraints.first; con; con= con->next)
+	/* Rule: not if there's already an IK on this channel */
+	for (con= pchan->constraints.first; con; con= con->next) {
 		if (con->type==CONSTRAINT_TYPE_KINEMATIC)
 			break;
+	}
 	
 	if (con) {
 		/* but, if this is a targetless IK, we make it auto anyway (for the children loop) */
@@ -826,7 +827,7 @@
 	return 1;
 }
 
-/* bone is a canditate to get IK, but we don't do it if it has children connected */
+/* bone is a candidate to get IK, but we don't do it if it has children connected */
 static short pose_grab_with_ik_children(bPose *pose, Bone *bone)
 {
 	Bone *bonec;
@@ -852,43 +853,47 @@
 static short pose_grab_with_ik(Object *ob)
 {
 	bArmature *arm;
-	bPoseChannel *pchan, *pchansel= NULL;
+	bPoseChannel *pchan, *parent;
 	Bone *bonec;
+	short tot_ik= 0;
 	
-	if (ob==NULL || ob->pose==NULL || (ob->flag & OB_POSEMODE)==0)
+	if ((ob==NULL) || (ob->pose==NULL) || (ob->flag & OB_POSEMODE)==0)
 		return 0;
 		
 	arm = ob->data;
 	
-	/* rule: only one Bone */
+	/* Rule: allow multiple Bones (but they must be selected, and only one ik-solver per chain should get added) */
 	for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
 		if (pchan->bone->layer & arm->layer) {
 			if (pchan->bone->flag & BONE_SELECTED) {
-				if (pchansel)
-					break;
-				pchansel= pchan;
+				/* Rule: no IK for solitatry (unconnected) bones */
+				for (bonec=pchan->bone->childbase.first; bonec; bonec=bonec->next) {
+					if (bonec->flag & BONE_CONNECTED) {
+						break;
+					}
+				}
+				if ((pchan->bone->flag & BONE_CONNECTED)==0 && (bonec == NULL))
+					continue;
+				
+				/* rule: if selected Bone is not a root bone, it gets a temporal IK */
+				if (pchan->parent) {
+					/* only adds if there's no IK yet (and no parent bone was selected) */
+					for (parent= pchan->parent; parent; parent= parent->parent) {
+						if (parent->bone->flag & BONE_SELECTED)
+							break;
+					}
+					if (parent == NULL)
+						tot_ik += pose_grab_with_ik_add(pchan);
+				}
+				else {
+					/* rule: go over the children and add IK to the tips */
+					tot_ik += pose_grab_with_ik_children(ob->pose, pchan->bone);
+				}
 			}
 		}
 	}
-	if (pchan || pchansel==NULL) return 0;
-
-	/* rule: no IK for solitary (unconnected) bone */
-	for (bonec=pchansel->bone->childbase.first; bonec; bonec=bonec->next) {
-		if (bonec->flag & BONE_CONNECTED) {
-			break;
-		}
-	}
-	if ((pchansel->bone->flag & BONE_CONNECTED)==0 && (bonec == NULL)) return 0;
 	
-	/* rule: if selected Bone is not a root bone, it gets a temporal IK */
-	if (pchansel->parent) {
-		/* only adds if there's no IK yet */
-		return pose_grab_with_ik_add(pchansel);
-	}
-	else {
-		/* rule: go over the children and add IK to the tips */
-		return pose_grab_with_ik_children(ob->pose, pchansel->bone);
-	}
+	return (tot_ik) ? 1 : 0;
 }	
 
 





More information about the Bf-blender-cvs mailing list