[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27466] trunk/blender/source/blender/ blenkernel/intern/softbody.c: getting close to 2.5 ' everything can be animated paradigm'

Jens Ole Wund (bjornmose) bjornmose at gmx.net
Sat Mar 13 03:43:27 CET 2010


Revision: 27466
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27466
Author:   bjornmose
Date:     2010-03-13 03:43:25 +0100 (Sat, 13 Mar 2010)

Log Message:
-----------
getting close to 2.5 'everything can be animated paradigm' 
well meshes do .. I've not been looking a the tail yet. 
softbody.c

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

Modified: trunk/blender/source/blender/blenkernel/intern/softbody.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/softbody.c	2010-03-13 02:35:32 UTC (rev 27465)
+++ trunk/blender/source/blender/blenkernel/intern/softbody.c	2010-03-13 02:43:25 UTC (rev 27466)
@@ -212,6 +212,41 @@
 }
 /*--- frame based timing ---*/
 
+/* helper functions for everything is animateble jow_go_for2_5 +++++++*/
+/* introducing them here, because i know: steps in properties  ( at frame timing )
+   will cause unwanted responses of the softbody system (which does inter frame calculations )
+   so first 'cure' would be: interpolate linear in time .. 
+   Q: why do i write this?
+   A: because it happend once, that some eger coder 'streamlined' code to fail.
+   We DO linear interpolation for goals .. and i think we should do on animated properties as well 
+*/
+static float _goalfac(SoftBody *sb)/*jow_go_for2_5 */
+{
+	if (sb){
+		return  ABS(sb->maxgoal - sb->mingoal);
+	}
+	printf("_goalfac failed! sb==NULL \n" );
+	return -9999.99f; /*using crude but spot able values some times helps debuggin */
+}
+
+
+static float _final_goal(Object *ob,BodyPoint *bp)/*jow_go_for2_5 */
+{
+	float f = -1999.99f;
+	if (ob){
+		SoftBody *sb= ob->soft;	/* is supposed to be there */
+		if(!(ob->softflag & OB_SB_GOAL)) return (0.0f);
+		if (sb&&bp){
+			if (bp->goal < 0.0f) return (0.0f);
+			f = pow(_goalfac(sb), 4.0f);
+			return (bp->goal *f);
+		}
+	}
+	printf("_final_goal failed! sb or bp ==NULL \n" );
+	return f; /*using crude but spot able values some times helps debuggin */
+}
+/* helper functions for everything is animateble jow_go_for2_5 ------*/
+
 /*+++ collider caching and dicing +++*/
 
 /********************
@@ -2219,7 +2254,7 @@
 		}
 		/* naive ball self collision done */
 
-		if(bp->goal < SOFTGOALSNAP){ /* ommit this bp when it snaps */
+		if(_final_goal(ob,bp) < SOFTGOALSNAP){ /* ommit this bp when it snaps */
 			float auxvect[3];  
 			float velgoal[3];
 
@@ -2228,7 +2263,7 @@
 				/* true elastic goal */
 				float ks,kd;
 				sub_v3_v3v3(auxvect,bp->pos,bp->origT);
-				ks  = 1.0f/(1.0f- bp->goal*sb->goalspring)-1.0f ;
+				ks  = 1.0f/(1.0f- _final_goal(ob,bp)*sb->goalspring)-1.0f ;
 				bp->force[0]+= -ks*(auxvect[0]);
 				bp->force[1]+= -ks*(auxvect[1]);
 				bp->force[2]+= -ks*(auxvect[2]);
@@ -2616,7 +2651,7 @@
 			}
 			/* naive ball self collision done */
 
-			if(bp->goal < SOFTGOALSNAP){ /* ommit this bp when it snaps */
+			if(_final_goal(ob,bp) < SOFTGOALSNAP){ /* ommit this bp when it snaps */
 				float auxvect[3];  
 				float velgoal[3];
 
@@ -2624,7 +2659,7 @@
 				if(ob->softflag & OB_SB_GOAL) {
 					/* true elastic goal */
 					sub_v3_v3v3(auxvect,bp->pos,bp->origT);
-					ks  = 1.0f/(1.0f- bp->goal*sb->goalspring)-1.0f ;
+					ks  = 1.0f/(1.0f- _final_goal(ob,bp)*sb->goalspring)-1.0f ;
 					bp->force[0]+= -ks*(auxvect[0]);
 					bp->force[1]+= -ks*(auxvect[1]);
 					bp->force[2]+= -ks*(auxvect[2]);
@@ -2888,7 +2923,7 @@
   	    else timeovermass = forcetime/0.009999f;
 
 
-		if(bp->goal < SOFTGOALSNAP){
+		if(_final_goal(ob,bp) < SOFTGOALSNAP){
             /* this makes t~ = t */
 			if(mid_flags & MID_PRESERVE) VECCOPY(dx,bp->vec);
 			
@@ -3092,7 +3127,7 @@
 	int a;
 	
 	for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) {
-		if (bp->goal >= SOFTGOALSNAP){
+		if (_final_goal(ob,bp) >= SOFTGOALSNAP){
 			VECCOPY(bp->prevpos,bp->pos);
 			VECCOPY(bp->pos,bp->origT);
 		}		
@@ -3137,7 +3172,7 @@
 		bp->origT[0] = bp->origS[0] + f*(bp->origE[0] - bp->origS[0]); 
 		bp->origT[1] = bp->origS[1] + f*(bp->origE[1] - bp->origS[1]); 
 		bp->origT[2] = bp->origS[2] + f*(bp->origE[2] - bp->origS[2]); 
-		if (bp->goal >= SOFTGOALSNAP){
+		if (_final_goal(ob,bp) >= SOFTGOALSNAP){
 			bp->vec[0] = bp->origE[0] - bp->origS[0];
 			bp->vec[1] = bp->origE[1] - bp->origS[1];
 			bp->vec[2] = bp->origE[2] - bp->origS[2];
@@ -3224,38 +3259,7 @@
 
 
 
-/* helper functions for everything is animateble jow_go_for2_5 +++++++*/
-/* introducing them here, because i know: steps in properties  ( at frame timing )
-   will cause unwanted responses of the softbody system (which does inter frame calculations )
-   so first 'cure' would be: interpolate linear in time .. 
-   Q: why do i write this?
-   A: because it happend once, that some eger coder 'streamlined' code to fail.
-   We DO linear interpolation for goals .. and i think we should do on animated properties as well 
-*/
-static float _goalfac(SoftBody *sb)/*jow_go_for2_5 */
-{
-	if (sb){
-		return  ABS(sb->maxgoal - sb->mingoal);
-	}
-	printf("_goalfac failed! sb==NULL \n" );
-	return -9999.99f; /*using crude but spot able values some times helps debuggin */
-}
 
-
-static float _final_goal(SoftBody *sb,BodyPoint *bp)/*jow_go_for2_5 */
-{
-	float f = -1999.99f;
-	if (sb && bp){
-		if (bp->goal < 0.0f) return (0.0f);
-		f = pow(_goalfac(sb), 4.0f);
-		return (bp->goal *f);
-	}
-	printf("_final_goal failed! sb or bp ==NULL \n" );
-	return f; /*using crude but spot able values some times helps debuggin */
-}
-/* helper functions for everything is animateble jow_go_for2_5 ------*/
-
-
 /* makes totally fresh start situation */
 static void mesh_to_softbody(Scene *scene, Object *ob)
 {
@@ -3293,10 +3297,18 @@
 			/* this is where '2.5 every thing is animateable' goes wrong in the first place jow_go_for2_5 */
 			/* 1st coding action to take : move this to frame level */
 			/* reads: leave the bp->goal as it was read from vertex group / or default .. we will need it at per frame call */
-			bp->goal= sb->mingoal + bp->goal*goalfac; /* do not do here jow_go_for2_5 */
+		    /* should be fixed for meshes */
+			// bp->goal= sb->mingoal + bp->goal*goalfac; /* do not do here jow_go_for2_5 */
 		}
+		else{
+			/* in consequence if no group was set .. but we want to animate it laters */
+			/* logically attach to goal at first */
+			if(ob->softflag & OB_SB_GOAL){bp->goal =1.0f;} 
+		}
+
 		/* a little ad hoc changing the goal control to be less *sharp* */
-		bp->goal = (float)pow(bp->goal, 4.0f);/* do not do here jow_go_for2_5 */
+		/* should be fixed for meshes */
+		// bp->goal = (float)pow(bp->goal, 4.0f);/* do not do here jow_go_for2_5 */
 			
 		/* to proove the concept
 		this would enable per vertex *mass painting*
@@ -3530,6 +3542,8 @@
 	if(ob->softflag & OB_SB_GOAL){
 		BodyPoint *bp= sb->bpoint;
 		BPoint *bpnt= lt->def;
+		/* goes wrong with jow_go_for2_5 */
+		/* for now this is a built in bug .. by design */
 		float goalfac= ABS(sb->maxgoal - sb->mingoal);
 		int a;
 





More information about the Bf-blender-cvs mailing list