[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33302] trunk/blender/source/blender/ blenkernel/intern: Spline IK Bugfix:

Joshua Leung aligorith at gmail.com
Thu Nov 25 00:36:36 CET 2010


Revision: 33302
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33302
Author:   aligorith
Date:     2010-11-25 00:36:36 +0100 (Thu, 25 Nov 2010)

Log Message:
-----------
Spline IK Bugfix:

Binding code had off-by-1 error, which meant that when "Even Divisions" was disabled the length of the wrong bone would get used. 

This error was most noticeable when the lengths of the bones were quite different - for example, a chain with 3 bones of increasing length. Thanks to "Julius" on BlenderArtists for catching this. Cheers!

---

Also, simplified the binding code loop a bit to prevent this sort of error in future.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/anim_sys.c
    trunk/blender/source/blender/blenkernel/intern/armature.c

Modified: trunk/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2010-11-24 21:39:07 UTC (rev 33301)
+++ trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2010-11-24 23:36:36 UTC (rev 33302)
@@ -1654,7 +1654,7 @@
 			/* make dummy NLA strip, and add that to the stack */
 			NlaStrip dummy_strip= {0};
 			ListBase dummy_trackslist;
-
+			
 			dummy_trackslist.first= dummy_trackslist.last= &dummy_strip;
 			
 			if ((nlt) && !(adt->flag & ADT_NLA_EDIT_NOMAP)) {

Modified: trunk/blender/source/blender/blenkernel/intern/armature.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/armature.c	2010-11-24 21:39:07 UTC (rev 33301)
+++ trunk/blender/source/blender/blenkernel/intern/armature.c	2010-11-24 23:36:36 UTC (rev 33302)
@@ -1730,28 +1730,25 @@
 		ikData->numpoints= ikData->chainlen+1; 
 		ikData->points= MEM_callocN(sizeof(float)*ikData->numpoints, "Spline IK Binding");
 		
+		/* bind 'tip' of chain (i.e. first joint = tip of bone with the Spline IK Constraint) */
+		ikData->points[0] = 1.0f;
+		
 		/* perform binding of the joints to parametric positions along the curve based 
 		 * proportion of the total length that each bone occupies
 		 */
 		for (i = 0; i < segcount; i++) {
-			if (i != 0) {
-				/* 'head' joints 
-				 * 	- 2 methods; the one chosen depends on whether we've got usable lengths
-				 */
-				if ((ikData->flag & CONSTRAINT_SPLINEIK_EVENSPLITS) || (totLength == 0.0f)) {
-					/* 1) equi-spaced joints */
-					ikData->points[i]= ikData->points[i-1] - segmentLen;
-				}
-				else {
-					 /*	2) to find this point on the curve, we take a step from the previous joint
-					  *	  a distance given by the proportion that this bone takes
-					  */
-					ikData->points[i]= ikData->points[i-1] - (boneLengths[i] / totLength);
-				}
+			/* 'head' joints, travelling towards the root of the chain
+			 * 	- 2 methods; the one chosen depends on whether we've got usable lengths
+			 */
+			if ((ikData->flag & CONSTRAINT_SPLINEIK_EVENSPLITS) || (totLength == 0.0f)) {
+				/* 1) equi-spaced joints */
+				ikData->points[i+1]= ikData->points[i] - segmentLen;
 			}
 			else {
-				/* 'tip' of chain, special exception for the first joint */
-				ikData->points[0]= 1.0f;
+				/*	2) to find this point on the curve, we take a step from the previous joint
+				 *	  a distance given by the proportion that this bone takes
+				 */
+				ikData->points[i+1]= ikData->points[i] - (boneLengths[i] / totLength);
 			}
 		}
 		





More information about the Bf-blender-cvs mailing list