[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21142] trunk/blender/source/blender: bug fix SoftBody module

Jens Ole Wund (bjornmose) bjornmose at gmx.net
Thu Jun 25 01:42:46 CEST 2009


Revision: 21142
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21142
Author:   bjornmose
Date:     2009-06-25 01:42:45 +0200 (Thu, 25 Jun 2009)

Log Message:
-----------
bug fix SoftBody module
vertex groups are not notified on deletion .. and other relevant changes  ..
sneak in Mass and Spring Painting

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_softbody.h
    trunk/blender/source/blender/blenkernel/intern/softbody.c
    trunk/blender/source/blender/include/butspace.h
    trunk/blender/source/blender/makesdna/DNA_object_force.h
    trunk/blender/source/blender/src/buttons_object.c

Modified: trunk/blender/source/blender/blenkernel/BKE_softbody.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_softbody.h	2009-06-24 21:27:10 UTC (rev 21141)
+++ trunk/blender/source/blender/blenkernel/BKE_softbody.h	2009-06-24 23:42:45 UTC (rev 21142)
@@ -43,7 +43,9 @@
 	float choke,choke2,frozen;
 	float colball;
 	short flag;
-	char octantflag;
+	//char octantflag;
+	float mass;
+	float springweight;
 } BodyPoint;
 
 /* allocates and initializes general main data */

Modified: trunk/blender/source/blender/blenkernel/intern/softbody.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/softbody.c	2009-06-24 21:27:10 UTC (rev 21141)
+++ trunk/blender/source/blender/blenkernel/intern/softbody.c	2009-06-24 23:42:45 UTC (rev 21142)
@@ -82,7 +82,7 @@
 #include "BKE_DerivedMesh.h"
 #include "BKE_pointcache.h"
 #include "BKE_modifier.h"
-
+#include "BKE_deform.h"
 #include  "BIF_editdeform.h"
 #include  "BIF_graphics.h"
 #include  "PIL_time.h"
@@ -2052,7 +2052,7 @@
 	BodyPoint  *bp1,*bp2;
 
 	float dir[3],dvel[3];
-	float distance,forcefactor,kd,absvel,projvel;
+	float distance,forcefactor,kd,absvel,projvel,kw;
 	int ia,ic;
 	/* prepare depending on which side of the spring we are on */
 	if (bpi == bs->v1){
@@ -2086,7 +2086,10 @@
 		forcefactor = iks/bs->len;
 	else
 		forcefactor = iks;
-	forcefactor *= bs->strength; 
+	    kw = (bp1->springweight+bp2->springweight)/2.0f;
+		kw = kw * kw;
+		kw = kw * kw;
+	forcefactor *= bs->strength * kw; 
 	Vec3PlusStVec(bp1->force,(bs->len - distance)*forcefactor,dir);
 
 	/* do bp1 <--> bp2 viscous */
@@ -2185,14 +2188,14 @@
 
 							VecMidf(velcenter, bp->vec, obp->vec);
 							VecSubf(dvel,velcenter,bp->vec);
-							VecMulf(dvel,sb->nodemass);
+							VecMulf(dvel,bp->mass);
 
 							Vec3PlusStVec(bp->force,f*(1.0f-sb->balldamp),def);
 							Vec3PlusStVec(bp->force,sb->balldamp,dvel);
 
 							/* exploit force(a,b) == -force(b,a) part2/2 */
 							VecSubf(dvel,velcenter,obp->vec);
-							VecMulf(dvel,sb->nodemass);
+							VecMulf(dvel,bp->mass);
 
 							Vec3PlusStVec(obp->force,sb->balldamp,dvel);
 							Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def);
@@ -2237,7 +2240,7 @@
 			/* gravitation */
 			if (sb){ 
 			float gravity = sb->grav * sb_grav_force_scale(ob);	
-			bp->force[2]-= gravity*sb->nodemass; /* individual mass of node here */
+			bp->force[2]-= gravity*bp->mass; /* individual mass of node here */
 			}
 			
 			/* particle field & vortex */
@@ -2549,7 +2552,7 @@
 
 							VecMidf(velcenter, bp->vec, obp->vec);
 							VecSubf(dvel,velcenter,bp->vec);
-							VecMulf(dvel,sb->nodemass);
+							VecMulf(dvel,bp->mass);
 
 							Vec3PlusStVec(bp->force,f*(1.0f-sb->balldamp),def);
 							Vec3PlusStVec(bp->force,sb->balldamp,dvel);
@@ -2580,7 +2583,7 @@
 
 							/* exploit force(a,b) == -force(b,a) part2/2 */
 							VecSubf(dvel,velcenter,obp->vec);
-							VecMulf(dvel,sb->nodemass);
+							VecMulf(dvel,(bp->mass+obp->mass)/2.0f);
 
 							Vec3PlusStVec(obp->force,sb->balldamp,dvel);
 							Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def);
@@ -2640,8 +2643,7 @@
 
 
 				/* gravitation */
-				bp->force[2]-= gravity*sb->nodemass; /* individual mass of node here */
-				//bp->force[1]-= gravity*sb->nodemass; /* individual mass of node here */
+				bp->force[2]-= gravity*bp->mass; /* individual mass of node here */
 
 
 				/* particle field & vortex */
@@ -2850,11 +2852,20 @@
     aabbmin[0]=aabbmin[1]=aabbmin[2] = 1e20f;
     aabbmax[0]=aabbmax[1]=aabbmax[2] = -1e20f;
 
+    /* old one with homogenous masses  */
 	/* claim a minimum mass for vertex */
+	/*
 	if (sb->nodemass > 0.009999f) timeovermass = forcetime/sb->nodemass;
 	else timeovermass = forcetime/0.009999f;
+	*/
 	
 	for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) {
+/* now we have individual masses   */
+/* claim a minimum mass for vertex */
+		if (bp->mass > 0.009999f) timeovermass = forcetime/bp->mass;
+  	    else timeovermass = forcetime/0.009999f;
+
+
 		if(bp->goal < SOFTGOALSNAP){
             /* this makes t~ = t */
 			if(mid_flags & MID_PRESERVE) VECCOPY(dx,bp->vec);
@@ -3228,10 +3239,36 @@
 			
 		/* to proove the concept
 		this would enable per vertex *mass painting*
-		strcpy(name,"SOFTMASS");
-		error = get_scalar_from_named_vertexgroup(ob,name, a,&temp);
-		if (!error) bp->mass = temp * ob->rangeofmass;
 		*/
+		/* first set the default */
+		bp->mass = sb->nodemass;
+
+		if (sb->namedVG_Mass[0])
+		{
+			int grp= get_named_vertexgroup_num (ob,sb->namedVG_Mass);
+			/* printf("VGN  %s %d \n",sb->namedVG_Mass,grp); */
+			if(grp > -1){
+				get_scalar_from_vertexgroup(ob, a,(short) (grp), &bp->mass);
+				bp->mass = bp->mass * sb->nodemass;
+				/* printf("bp->mass  %f \n",bp->mass); */
+
+			}
+		}
+		/* first set the default */
+		bp->springweight = 1.0f;
+
+		if (sb->namedVG_Spring_K[0])
+		{
+			int grp= get_named_vertexgroup_num (ob,sb->namedVG_Spring_K);
+			//printf("VGN  %s %d \n",sb->namedVG_Spring_K,grp); 
+			if(grp > -1){
+				get_scalar_from_vertexgroup(ob, a,(short) (grp), &bp->springweight);
+				//printf("bp->springweight  %f \n",bp->springweight);
+
+			}
+		}
+
+		
 	}
 
 	/* but we only optionally add body edge springs */

Modified: trunk/blender/source/blender/include/butspace.h
===================================================================
--- trunk/blender/source/blender/include/butspace.h	2009-06-24 21:27:10 UTC (rev 21141)
+++ trunk/blender/source/blender/include/butspace.h	2009-06-24 23:42:45 UTC (rev 21142)
@@ -288,6 +288,10 @@
 #define B_SOFTBODY_DEL_VG		1421
 #define B_SOFTBODY_BAKE			1422
 #define B_SOFTBODY_BAKE_FREE	1423
+#define B_SOFTBODY_UP_GRMASS	1424
+#define B_SOFTBODY_DEL_VGMASS	1425
+#define B_SOFTBODY_UP_GRSPRING	1426
+#define B_SOFTBODY_DEL_VGSPRING	1427
 
 /* Fluidsim button defines */
 #define B_FLUIDSIM_BAKE	        1450

Modified: trunk/blender/source/blender/makesdna/DNA_object_force.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_object_force.h	2009-06-24 21:27:10 UTC (rev 21141)
+++ trunk/blender/source/blender/makesdna/DNA_object_force.h	2009-06-24 23:42:45 UTC (rev 21142)
@@ -144,12 +144,17 @@
 	int totpoint, totspring;
 	struct BodyPoint *bpoint;		/* not saved in file */
 	struct BodySpring *bspring;		/* not saved in file */
-	float pad;
+	char   pad;
+	char   msg_lock;
+	short  msg_value;
 	
 	/* part of UI: */
 	
 	/* general options */
 	float nodemass;		/* softbody mass of *vertex* */
+	char  namedVG_Mass[32]; /* along with it introduce mass painting
+							starting to fix old bug .. nastyness that VG are indexes 
+								rather find them by name tag to find it -> jow20090613 */
 	float grav;			/* softbody amount of gravitaion to apply */
 	float mediafrict;	/* friction to env */
 	float rklimit;		/* error limit for ODE solver */
@@ -162,13 +167,18 @@
 	float maxgoal;
 	float defgoal;		/* default goal for vertices without vgroup */
 	short vertgroup;	/* index starting at 1 */
+	char  namedVG_Softgoal[32]; /* starting to fix old bug .. nastyness that VG are indexes 
+								rather find them by name tag to find it -> jow20090613 */
   
 	short fuzzyness;      /* */
 	
 	/* springs */
 	float inspring;		/* softbody inner springs */
 	float infrict;		/* softbody inner springs friction */
- 	
+ 	char  namedVG_Spring_K[32]; /* along with it introduce Spring_K painting
+							starting to fix old bug .. nastyness that VG are indexes 
+								rather find them by name tag to find it -> jow20090613 */
+	
 	/* baking */
 	int sfra, efra;
 	int interval;
@@ -262,7 +272,7 @@
 #define OB_SB_FACECOLL  1024
 #define OB_SB_EDGECOLL  2048
 #define OB_SB_COLLFINAL 4096
-//#define OB_SB_PROTECT_CACHE	8192
+#define OB_SB_BIG_UI	8192
 #define OB_SB_AERO_ANGLE	16384
 
 /* sb->solverflags */

Modified: trunk/blender/source/blender/src/buttons_object.c
===================================================================
--- trunk/blender/source/blender/src/buttons_object.c	2009-06-24 21:27:10 UTC (rev 21141)
+++ trunk/blender/source/blender/src/buttons_object.c	2009-06-24 23:42:45 UTC (rev 21142)
@@ -2423,12 +2423,61 @@
 	case B_SOFTBODY_DEL_VG:
 		if(ob->soft) {
 			ob->soft->vertgroup= 0;
+			ob->soft->namedVG_Softgoal[0] = 0;
 			//ob->softflag |= OB_SB_REDO;
 			DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
 			allqueue(REDRAWBUTSOBJECT, 0);
 			allqueue(REDRAWVIEW3D, 0);
 		}
 		break;
+
+	case B_SOFTBODY_UP_GRMASS:
+		if(ob->soft) {
+			ob->soft->msg_lock = 1;
+			if(ob->soft->msg_value) {
+				bDeformGroup *defGroup = BLI_findlink(&ob->defbase, ob->soft->msg_value-1);
+				if(defGroup){
+					strncpy((char*)&ob->soft->namedVG_Mass,defGroup->name,32); // ugly type casting and size assumtion
+				}
+			}
+			DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
+			allqueue(REDRAWBUTSOBJECT, 0);
+			allqueue(REDRAWVIEW3D, 0);
+			ob->soft->msg_lock = 0;
+		}
+		break;
+	case B_SOFTBODY_UP_GRSPRING:
+		if(ob->soft) {
+			ob->soft->msg_lock = 1;
+			if(ob->soft->msg_value) {
+				bDeformGroup *defGroup = BLI_findlink(&ob->defbase, ob->soft->msg_value-1);
+				if(defGroup){
+					strncpy((char*)&ob->soft->namedVG_Spring_K,defGroup->name,32); // ugly type casting and size assumtion
+				}
+			}
+			DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
+			allqueue(REDRAWBUTSOBJECT, 0);
+			allqueue(REDRAWVIEW3D, 0);
+			ob->soft->msg_lock = 0;
+		}
+		break;
+
+	case B_SOFTBODY_DEL_VGMASS:
+		if(ob->soft) {
+			ob->soft->namedVG_Mass[0] = 0;
+			DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
+			allqueue(REDRAWBUTSOBJECT, 0);
+			allqueue(REDRAWVIEW3D, 0);
+		}
+		break;
+	case B_SOFTBODY_DEL_VGSPRING:
+		if(ob->soft) {
+			ob->soft->namedVG_Spring_K[0] = 0;
+			DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); 
+			allqueue(REDRAWBUTSOBJECT, 0);
+			allqueue(REDRAWVIEW3D, 0);
+		}
+		break;
 	case B_FLUIDSIM_BAKE:
 		/* write config files (currently no simulation) */
 		fluidsimBake(ob);
@@ -4034,7 +4083,7 @@
 	int ob_has_hair = psys_ob_has_hair(ob);
 	static short actsoft= -1;
 
-    if(!_can_softbodies_at_all(ob)) return;
+	if(!_can_softbodies_at_all(ob)) return;
 	block= uiNewBlock(&curarea->uiblocks, "object_softbodies", UI_EMBOSS, UI_HELV, curarea->win);
 	uiNewPanelTabbed("Soft Body", "Physics"); 
 	if(uiNewPanel(curarea, block, "Soft Body", "Physics", 640, 0, 318, 204)==0) return;
@@ -4080,6 +4129,8 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list