bug fix SoftBody module

vertex groups are not notified on deletion .. and other relevant changes  ..
sneak in Mass and Spring Painting
This commit is contained in:
Jens Ole Wund 2009-06-24 23:42:45 +00:00
parent 320fc51a2b
commit 122808b839
5 changed files with 333 additions and 70 deletions

@ -43,7 +43,9 @@ typedef struct BodyPoint {
float choke,choke2,frozen; float choke,choke2,frozen;
float colball; float colball;
short flag; short flag;
char octantflag; //char octantflag;
float mass;
float springweight;
} BodyPoint; } BodyPoint;
/* allocates and initializes general main data */ /* allocates and initializes general main data */

@ -82,7 +82,7 @@ variables on the UI for now
#include "BKE_DerivedMesh.h" #include "BKE_DerivedMesh.h"
#include "BKE_pointcache.h" #include "BKE_pointcache.h"
#include "BKE_modifier.h" #include "BKE_modifier.h"
#include "BKE_deform.h"
#include "BIF_editdeform.h" #include "BIF_editdeform.h"
#include "BIF_graphics.h" #include "BIF_graphics.h"
#include "PIL_time.h" #include "PIL_time.h"
@ -2052,7 +2052,7 @@ static void sb_spring_force(Object *ob,int bpi,BodySpring *bs,float iks,float fo
BodyPoint *bp1,*bp2; BodyPoint *bp1,*bp2;
float dir[3],dvel[3]; float dir[3],dvel[3];
float distance,forcefactor,kd,absvel,projvel; float distance,forcefactor,kd,absvel,projvel,kw;
int ia,ic; int ia,ic;
/* prepare depending on which side of the spring we are on */ /* prepare depending on which side of the spring we are on */
if (bpi == bs->v1){ if (bpi == bs->v1){
@ -2086,7 +2086,10 @@ static void sb_spring_force(Object *ob,int bpi,BodySpring *bs,float iks,float fo
forcefactor = iks/bs->len; forcefactor = iks/bs->len;
else else
forcefactor = iks; 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); Vec3PlusStVec(bp1->force,(bs->len - distance)*forcefactor,dir);
/* do bp1 <--> bp2 viscous */ /* do bp1 <--> bp2 viscous */
@ -2185,14 +2188,14 @@ static int _softbody_calc_forces_slice_in_a_thread(Object *ob, float forcetime,
VecMidf(velcenter, bp->vec, obp->vec); VecMidf(velcenter, bp->vec, obp->vec);
VecSubf(dvel,velcenter,bp->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,f*(1.0f-sb->balldamp),def);
Vec3PlusStVec(bp->force,sb->balldamp,dvel); Vec3PlusStVec(bp->force,sb->balldamp,dvel);
/* exploit force(a,b) == -force(b,a) part2/2 */ /* exploit force(a,b) == -force(b,a) part2/2 */
VecSubf(dvel,velcenter,obp->vec); VecSubf(dvel,velcenter,obp->vec);
VecMulf(dvel,sb->nodemass); VecMulf(dvel,bp->mass);
Vec3PlusStVec(obp->force,sb->balldamp,dvel); Vec3PlusStVec(obp->force,sb->balldamp,dvel);
Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def); Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def);
@ -2237,7 +2240,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Object *ob, float forcetime,
/* gravitation */ /* gravitation */
if (sb){ if (sb){
float gravity = sb->grav * sb_grav_force_scale(ob); 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 */ /* particle field & vortex */
@ -2549,7 +2552,7 @@ static void softbody_calc_forces(Object *ob, float forcetime, float timenow, int
VecMidf(velcenter, bp->vec, obp->vec); VecMidf(velcenter, bp->vec, obp->vec);
VecSubf(dvel,velcenter,bp->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,f*(1.0f-sb->balldamp),def);
Vec3PlusStVec(bp->force,sb->balldamp,dvel); Vec3PlusStVec(bp->force,sb->balldamp,dvel);
@ -2580,7 +2583,7 @@ static void softbody_calc_forces(Object *ob, float forcetime, float timenow, int
/* exploit force(a,b) == -force(b,a) part2/2 */ /* exploit force(a,b) == -force(b,a) part2/2 */
VecSubf(dvel,velcenter,obp->vec); 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,sb->balldamp,dvel);
Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def); Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def);
@ -2640,8 +2643,7 @@ static void softbody_calc_forces(Object *ob, float forcetime, float timenow, int
/* gravitation */ /* gravitation */
bp->force[2]-= gravity*sb->nodemass; /* individual mass of node here */ bp->force[2]-= gravity*bp->mass; /* individual mass of node here */
//bp->force[1]-= gravity*sb->nodemass; /* individual mass of node here */
/* particle field & vortex */ /* particle field & vortex */
@ -2850,11 +2852,20 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float *
aabbmin[0]=aabbmin[1]=aabbmin[2] = 1e20f; aabbmin[0]=aabbmin[1]=aabbmin[2] = 1e20f;
aabbmax[0]=aabbmax[1]=aabbmax[2] = -1e20f; aabbmax[0]=aabbmax[1]=aabbmax[2] = -1e20f;
/* old one with homogenous masses */
/* claim a minimum mass for vertex */ /* claim a minimum mass for vertex */
/*
if (sb->nodemass > 0.009999f) timeovermass = forcetime/sb->nodemass; if (sb->nodemass > 0.009999f) timeovermass = forcetime/sb->nodemass;
else timeovermass = forcetime/0.009999f; else timeovermass = forcetime/0.009999f;
*/
for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { 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){ if(bp->goal < SOFTGOALSNAP){
/* this makes t~ = t */ /* this makes t~ = t */
if(mid_flags & MID_PRESERVE) VECCOPY(dx,bp->vec); if(mid_flags & MID_PRESERVE) VECCOPY(dx,bp->vec);
@ -3228,10 +3239,36 @@ static void mesh_to_softbody(Object *ob)
/* to proove the concept /* to proove the concept
this would enable per vertex *mass painting* 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 */ /* but we only optionally add body edge springs */

@ -288,6 +288,10 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
#define B_SOFTBODY_DEL_VG 1421 #define B_SOFTBODY_DEL_VG 1421
#define B_SOFTBODY_BAKE 1422 #define B_SOFTBODY_BAKE 1422
#define B_SOFTBODY_BAKE_FREE 1423 #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 */ /* Fluidsim button defines */
#define B_FLUIDSIM_BAKE 1450 #define B_FLUIDSIM_BAKE 1450

@ -144,12 +144,17 @@ typedef struct SoftBody {
int totpoint, totspring; int totpoint, totspring;
struct BodyPoint *bpoint; /* not saved in file */ struct BodyPoint *bpoint; /* not saved in file */
struct BodySpring *bspring; /* not saved in file */ struct BodySpring *bspring; /* not saved in file */
float pad; char pad;
char msg_lock;
short msg_value;
/* part of UI: */ /* part of UI: */
/* general options */ /* general options */
float nodemass; /* softbody mass of *vertex* */ 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 grav; /* softbody amount of gravitaion to apply */
float mediafrict; /* friction to env */ float mediafrict; /* friction to env */
float rklimit; /* error limit for ODE solver */ float rklimit; /* error limit for ODE solver */
@ -162,12 +167,17 @@ typedef struct SoftBody {
float maxgoal; float maxgoal;
float defgoal; /* default goal for vertices without vgroup */ float defgoal; /* default goal for vertices without vgroup */
short vertgroup; /* index starting at 1 */ 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; /* */ short fuzzyness; /* */
/* springs */ /* springs */
float inspring; /* softbody inner springs */ float inspring; /* softbody inner springs */
float infrict; /* softbody inner springs friction */ 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 */ /* baking */
int sfra, efra; int sfra, efra;
@ -262,7 +272,7 @@ typedef struct SoftBody {
#define OB_SB_FACECOLL 1024 #define OB_SB_FACECOLL 1024
#define OB_SB_EDGECOLL 2048 #define OB_SB_EDGECOLL 2048
#define OB_SB_COLLFINAL 4096 #define OB_SB_COLLFINAL 4096
//#define OB_SB_PROTECT_CACHE 8192 #define OB_SB_BIG_UI 8192
#define OB_SB_AERO_ANGLE 16384 #define OB_SB_AERO_ANGLE 16384
/* sb->solverflags */ /* sb->solverflags */

@ -2423,12 +2423,61 @@ void do_object_panels(unsigned short event)
case B_SOFTBODY_DEL_VG: case B_SOFTBODY_DEL_VG:
if(ob->soft) { if(ob->soft) {
ob->soft->vertgroup= 0; ob->soft->vertgroup= 0;
ob->soft->namedVG_Softgoal[0] = 0;
//ob->softflag |= OB_SB_REDO; //ob->softflag |= OB_SB_REDO;
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
allqueue(REDRAWBUTSOBJECT, 0); allqueue(REDRAWBUTSOBJECT, 0);
allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWVIEW3D, 0);
} }
break; 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: case B_FLUIDSIM_BAKE:
/* write config files (currently no simulation) */ /* write config files (currently no simulation) */
fluidsimBake(ob); fluidsimBake(ob);
@ -4034,7 +4083,7 @@ static void object_softbodies(Object *ob)
int ob_has_hair = psys_ob_has_hair(ob); int ob_has_hair = psys_ob_has_hair(ob);
static short actsoft= -1; 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); block= uiNewBlock(&curarea->uiblocks, "object_softbodies", UI_EMBOSS, UI_HELV, curarea->win);
uiNewPanelTabbed("Soft Body", "Physics"); uiNewPanelTabbed("Soft Body", "Physics");
if(uiNewPanel(curarea, block, "Soft Body", "Physics", 640, 0, 318, 204)==0) return; if(uiNewPanel(curarea, block, "Soft Body", "Physics", 640, 0, 318, 204)==0) return;
@ -4080,6 +4129,8 @@ static void object_softbodies(Object *ob)
but= uiDefIconButBitI(block, TOG, eModifierMode_Realtime, B_BAKE_CACHE_CHANGE, VICON_VIEW3D, 165, 200, 20, 20,&md->mode, 0, 0, 1, 0, "Enable soft body during interactive display"); but= uiDefIconButBitI(block, TOG, eModifierMode_Realtime, B_BAKE_CACHE_CHANGE, VICON_VIEW3D, 165, 200, 20, 20,&md->mode, 0, 0, 1, 0, "Enable soft body during interactive display");
uiBlockEndAlign(block); uiBlockEndAlign(block);
} }
uiDefButBitS(block, TOG, OB_SB_BIG_UI, REDRAWBUTSOBJECT , "Big UI",190,200,25,20, softflag, 0, 0, 0, 0, "Big UI");
} }
if(ob_has_hair) { if(ob_has_hair) {
@ -4102,7 +4153,7 @@ static void object_softbodies(Object *ob)
if(sb->pointcache->flag & PTCACHE_BAKED) if(sb->pointcache->flag & PTCACHE_BAKED)
uiSetButLock(1, "Simulation frames are baked"); uiSetButLock(1, "Simulation frames are baked");
// this is old baking not sure if i want to throw it away now .. leave it for inspiration
//if(ob->softflag & OB_SB_BAKESET) { //if(ob->softflag & OB_SB_BAKESET) {
// uiBlockBeginAlign(block); // uiBlockBeginAlign(block);
// uiDefButI(block, NUM, B_DIFF, "Start:", 10, 170,100,20, &sb->sfra, 1.0, 10000.0, 10, 0, "Start frame for baking"); // uiDefButI(block, NUM, B_DIFF, "Start:", 10, 170,100,20, &sb->sfra, 1.0, 10000.0, 10, 0, "Start frame for baking");
@ -4126,58 +4177,60 @@ static void object_softbodies(Object *ob)
// uiDefBut(block, BUT, B_SOFTBODY_BAKE, "BAKE", 10, 120,300,20, NULL, 0.0, 0.0, 10, 0, "Start baking. Press ESC to exit without baking"); // uiDefBut(block, BUT, B_SOFTBODY_BAKE, "BAKE", 10, 120,300,20, NULL, 0.0, 0.0, 10, 0, "Start baking. Press ESC to exit without baking");
//} //}
//else { //else {
/* GENERAL STUFF */ // if(G.rt == 0){
if (sb->totpoint){ if(! (*softflag & OB_SB_BIG_UI)){
/* GENERAL STUFF */
if (sb->totpoint){
sprintf(str, "Vertex Mass; Object mass %f [k]",sb->nodemass*sb->totpoint/1000.0f); sprintf(str, "Vertex Mass; Object mass %f [k]",sb->nodemass*sb->totpoint/1000.0f);
} }
else{ else{
sprintf(str, "Vertex Mass"); sprintf(str, "Vertex Mass");
} }
uiBlockBeginAlign(block); uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Friction:", 10, 170,150,20, &sb->mediafrict, 0.0, 50.0, 10, 0, "General media friction for point movements"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Friction:", 10, 170,150,20, &sb->mediafrict, 0.0, 50.0, 10, 0, "General media friction for point movements");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Mass:", 160, 170,150,20, &sb->nodemass , 0.001, 50000.0, 10, 0, str); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Mass:", 160, 170,150,20, &sb->nodemass , 0.001, 50000.0, 10, 0, str);
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Grav:", 10,150,150,20, &sb->grav , -10.0, 10.0, 10, 0, "Apply gravitation to point movement"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Grav:", 10,150,150,20, &sb->grav , -10.0, 10.0, 10, 0, "Apply gravitation to point movement");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Speed:", 160,150,150,20, &sb->physics_speed , 0.01, 100.0, 10, 0, "Tweak timing for physics to control frequency and speed"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Speed:", 160,150,150,20, &sb->physics_speed , 0.01, 100.0, 10, 0, "Tweak timing for physics to control frequency and speed");
uiBlockEndAlign(block); uiBlockEndAlign(block);
/* GOAL STUFF */ /* GOAL STUFF */
uiBlockBeginAlign(block); uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, OB_SB_GOAL, B_BAKE_CACHE_CHANGE, "Use Goal", 10,120,130,20, softflag, 0, 0, 0, 0, "Define forces for vertices to stick to animated position"); uiDefButBitS(block, TOG, OB_SB_GOAL, B_BAKE_CACHE_CHANGE, "Use Goal", 10,120,130,20, softflag, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
if (*softflag & OB_SB_GOAL){ if (*softflag & OB_SB_GOAL){
if(ob->type==OB_MESH) { if(ob->type==OB_MESH) {
menustr= get_vertexgroup_menustr(ob); menustr= get_vertexgroup_menustr(ob);
defCount=BLI_countlist(&ob->defbase); defCount=BLI_countlist(&ob->defbase);
if(defCount==0) sb->vertgroup= 0; if(defCount==0) sb->vertgroup= 0;
uiDefButS(block, MENU, B_BAKE_CACHE_CHANGE, menustr, 140,120,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups"); uiDefButS(block, MENU, B_BAKE_CACHE_CHANGE, menustr, 140,120,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups");
MEM_freeN (menustr); MEM_freeN (menustr);
if(sb->vertgroup) { if(sb->vertgroup) {
bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1); bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1);
if(defGroup) if(defGroup)
uiDefBut(block, BUT, B_BAKE_CACHE_CHANGE, defGroup->name, 160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group"); uiDefBut(block, BUT, B_BAKE_CACHE_CHANGE, defGroup->name, 160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group");
else
uiDefBut(block, BUT, B_BAKE_CACHE_CHANGE, "(no group)", 160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Vertex Group doesn't exist anymore");
uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VG, ICON_X, 290,120,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
}
else else
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Goal:", 160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used"); uiDefBut(block, BUT, B_BAKE_CACHE_CHANGE, "(no group)", 160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Vertex Group doesn't exist anymore");
uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VG, ICON_X, 290,120,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
} }
else { else
uiDefButS(block, TOG, B_BAKE_CACHE_CHANGE, "W", 140,120,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use control point weight values");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Goal:", 160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Goal:", 160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
}
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Stiff:", 10,100,150,20, &sb->goalspring, 0.0, 0.999, 10, 0, "Goal (vertex target position) spring stiffness");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Damp:", 160,100,150,20, &sb->goalfrict , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Min:", 10,80,150,20, &sb->mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Max:", 160,80,150,20, &sb->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
} }
uiBlockEndAlign(block); else {
uiDefButS(block, TOG, B_BAKE_CACHE_CHANGE, "W", 140,120,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use control point weight values");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Goal:", 160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
}
/* EDGE SPRING STUFF */ uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Stiff:", 10,100,150,20, &sb->goalspring, 0.0, 0.999, 10, 0, "Goal (vertex target position) spring stiffness");
if(ob->type!=OB_SURF) { uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Damp:", 160,100,150,20, &sb->goalfrict , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
uiBlockBeginAlign(block); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Min:", 10,80,150,20, &sb->mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
uiDefButBitS(block, TOG, OB_SB_EDGES, B_BAKE_CACHE_CHANGE, "Use Edges", 10,50,90,20, softflag, 0, 0, 0, 0, "Use Edges as springs"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Max:", 160,80,150,20, &sb->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
}
uiBlockEndAlign(block);
/* EDGE SPRING STUFF */
if(ob->type!=OB_SURF) {
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, OB_SB_EDGES, B_BAKE_CACHE_CHANGE, "Use Edges", 10,50,90,20, softflag, 0, 0, 0, 0, "Use Edges as springs");
if (*softflag & OB_SB_EDGES){ if (*softflag & OB_SB_EDGES){
uiDefButBitS(block, TOG, OB_SB_QUADS, B_BAKE_CACHE_CHANGE, "Stiff Quads", 110,50,90,20, softflag, 0, 0, 0, 0, "Adds diagonal springs on 4-gons"); uiDefButBitS(block, TOG, OB_SB_QUADS, B_BAKE_CACHE_CHANGE, "Stiff Quads", 110,50,90,20, softflag, 0, 0, 0, 0, "Adds diagonal springs on 4-gons");
uiDefButBitS(block, TOG, OB_SB_EDGECOLL, B_BAKE_CACHE_CHANGE, "CEdge", 220,50,45,20, softflag, 0, 0, 0, 0, "Edge collide too"); uiDefButBitS(block, TOG, OB_SB_EDGECOLL, B_BAKE_CACHE_CHANGE, "CEdge", 220,50,45,20, softflag, 0, 0, 0, 0, "Edge collide too");
@ -4185,23 +4238,180 @@ static void object_softbodies(Object *ob)
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Pull:", 10,30,75,20, &sb->inspring, 0.0, 0.999, 10, 0, "Edge spring stiffness when longer than rest length"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Pull:", 10,30,75,20, &sb->inspring, 0.0, 0.999, 10, 0, "Edge spring stiffness when longer than rest length");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Push:", 85,30,75,20, &sb->inpush, 0.0, 0.999, 10, 0, "Edge spring stiffness when shorter than rest length"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Push:", 85,30,75,20, &sb->inpush, 0.0, 0.999, 10, 0, "Edge spring stiffness when shorter than rest length");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Damp:", 160,30,70,20, &sb->infrict, 0.0, 50.0, 10, 0, "Edge spring friction"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Damp:", 160,30,70,20, &sb->infrict, 0.0, 50.0, 10, 0, "Edge spring friction");
uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "SL:",250 ,30,60,20, &sb->springpreload, 0.0, 200.0, 10, 0, "Alter spring lenght to shrink/blow up (unit %) 0 to disable "); uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "SL:",250 ,30,60,20, &sb->springpreload, 0.0, 200.0, 10, 0, "Alter spring lenght to shrink/blow up (unit %) 0 to disable ");
uiDefButBitS(block, TOG,OB_SB_AERO_ANGLE,B_BAKE_CACHE_CHANGE, "N",10,10,20,20, softflag, 0, 0, 0, 0, "New aero(uses angle and length)"); uiDefButBitS(block, TOG,OB_SB_AERO_ANGLE,B_BAKE_CACHE_CHANGE, "N",10,10,20,20, softflag, 0, 0, 0, 0, "New aero(uses angle and length)");
uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "Aero:", 30,10,60,20, &sb->aeroedge, 0.00, 30000.0, 10, 0, "Make edges 'sail'"); uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "Aero:", 30,10,60,20, &sb->aeroedge, 0.00, 30000.0, 10, 0, "Make edges 'sail'");
uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "Plas:", 90,10,60,20, &sb->plastic, 0.0, 100.0, 10, 0, "Permanent deform"); uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "Plas:", 90,10,60,20, &sb->plastic, 0.0, 100.0, 10, 0, "Permanent deform");
if(ob->type==OB_MESH) { if(ob->type==OB_MESH) {
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Be:", 150,10,80,20, &sb->secondspring, 0.0, 10.0, 10, 0, "Bending Stiffness"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Be:", 150,10,80,20, &sb->secondspring, 0.0, 10.0, 10, 0, "Bending Stiffness");
if (*softflag & OB_SB_QUADS){ if (*softflag & OB_SB_QUADS){
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Sh:", 230,10,80,20, &sb->shearstiff, 0.0, 1.0, 10, 0, "Shear Stiffness"); uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Sh:", 230,10,80,20, &sb->shearstiff, 0.0, 1.0, 10, 0, "Shear Stiffness");
} }
} }
else sb->secondspring = 0; else sb->secondspring = 0;
uiDefBut(block, LABEL, 0, "",10,10,1,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/ uiDefBut(block, LABEL, 0, "",10,10,1,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
} }
uiBlockEndAlign(block); uiBlockEndAlign(block);
}
} // fi (true)(G.rt != 0)
else{
static char section = 0;
int l_top = 170, l_dy =21;
uiBlockBeginAlign(block);
uiDefButC(block, ROW, B_BAKE_CACHE_CHANGE, "Object", 10,l_top,100,20, &section, 3.0, 0.0, 0, 0, "Object");
uiDefButC(block, ROW, B_BAKE_CACHE_CHANGE, "Goal", 111,l_top,100,20, &section, 3.0, 1.0, 0, 0, "Goals");
uiDefButC(block, ROW, B_BAKE_CACHE_CHANGE, "Edges", 212,l_top,100,20, &section, 3.0, 2.0, 0, 0, "Edges");
uiBlockEndAlign(block);
switch (section){
case 0:
{
int _loc_group;
uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Friction:", 10, l_top - l_dy,150,20, &sb->mediafrict, 0.0, 50.0, 10, 0, "General media friction for point movements");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Mass:", 160, l_top - l_dy,150,20, &sb->nodemass , 0.001, 50000.0, 10, 0, str);
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Grav:", 10,l_top - 2*l_dy,150,20, &sb->grav , -10.0, 10.0, 10, 0, "Apply gravitation to point movement");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Speed:", 160,l_top - 2*l_dy,150,20, &sb->physics_speed , 0.01, 100.0, 10, 0, "Tweak timing for physics to control frequency and speed");
uiBlockEndAlign(block);
uiDefBut(block, LABEL, 0, "Mass Vertex Group", 10, l_top - 4*l_dy , 150,20, NULL, 0.0, 0, 0, 0, "");
uiBlockBeginAlign(block);
/* but i like doing the spinner */
menustr= get_vertexgroup_menustr(ob);
defCount=BLI_countlist(&ob->defbase);
if(defCount==0) _loc_group= 0;
if(!sb->msg_lock){
uiDefButS(block, MENU, B_SOFTBODY_UP_GRMASS, menustr,10,l_top - 5*l_dy,20,20, &sb->msg_value, 0, defCount, 0, 0, "Browses available vertex groups");
}
/* but defined by some magic */
but= uiDefBut(block, TEX, B_BAKE_CACHE_CHANGE, "VG:", 30, l_top - 5*l_dy,260,20, &sb->namedVG_Mass, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ob);
uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VGMASS, ICON_X, 290,l_top - 5*l_dy,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
MEM_freeN (menustr);
uiBlockEndAlign(block);
if(_loc_group) {
bDeformGroup *defGroup = BLI_findlink(&ob->defbase, _loc_group-1);
if(defGroup){
strncpy((char*)&sb->namedVG_Mass,defGroup->name,32); // ugly type casting and size assumtion
}
}
// ll++;
break;
}
case 1:
{
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, OB_SB_GOAL, B_BAKE_CACHE_CHANGE, "Use Goal", 10,l_top - l_dy,150,20, softflag, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
if (*softflag & OB_SB_GOAL){
if(ob->type==OB_MESH) {
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Goal:", 160,l_top - l_dy,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
}
else {
uiDefButS(block, TOG, B_BAKE_CACHE_CHANGE, "W", 140,l_top - l_dy,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use control point weight values");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Goal:", 160,l_top - l_dy,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
}
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Stiff:", 10,l_top - 2*l_dy,150,20, &sb->goalspring, 0.0, 0.999, 10, 0, "Goal (vertex target position) spring stiffness");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Damp:", 160,l_top - 2*l_dy,150,20, &sb->goalfrict , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Min:", 10,l_top - 3*l_dy,150,20, &sb->mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "G Max:", 160,l_top - 3*l_dy,150,20, &sb->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
if(ob->type==OB_MESH) {
int ll = 4;
/* rather do this loading old files */
if(sb->vertgroup) {
bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1);
if(defGroup){
strncpy((char*)&sb->namedVG_Softgoal,defGroup->name,32); // ugly type casting and size assumtion
}
}
/*this would be the 'offical' way to do */
/* but i like doing the spinner */
menustr= get_vertexgroup_menustr(ob);
defCount=BLI_countlist(&ob->defbase);
if(defCount==0) sb->vertgroup= 0;
uiDefButS(block, MENU, B_BAKE_CACHE_CHANGE, menustr,10,l_top - ll*l_dy,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups");
MEM_freeN (menustr);
/* but defined by some magic */
but= uiDefBut(block, TEX, B_BAKE_CACHE_CHANGE, "VG:", 30, l_top - ll*l_dy,260,20, &sb->namedVG_Softgoal, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ob);
//if(sb->vertgroup) {
uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VG, ICON_X, 290,l_top - ll*l_dy,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
//}
}
}
uiBlockEndAlign(block);
break;
}
case 2:
{
int _loc_group;
if(ob->type!=OB_SURF) {
uiDefButBitS(block, TOG, OB_SB_EDGES, B_BAKE_CACHE_CHANGE, "Use Edges", 10,l_top - l_dy,90,20, softflag, 0, 0, 0, 0, "Use Edges as springs");
if (*softflag & OB_SB_EDGES){
uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Pull:", 10,l_top - 2*l_dy,100,20, &sb->inspring, 0.0, 0.999, 10, 0, "Edge spring stiffness when longer than rest length");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Push:", 111,l_top - 2*l_dy,100,20, &sb->inpush, 0.0, 0.999, 10, 0, "Edge spring stiffness when shorter than rest length");
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Damp:", 212,l_top - 2*l_dy,100,20, &sb->infrict, 0.0, 50.0, 10, 0, "Edge spring friction");
uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "Plas:", 10,l_top - 3*l_dy,100,20, &sb->plastic, 0.0, 100.0, 10, 0, "Permanent deform");
uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "SL:", 111,l_top - 3*l_dy,100,20, &sb->springpreload, 0.0, 200.0, 10, 0, "Alter spring lenght to shrink/blow up (unit %) 0 to disable ");
if(ob->type==OB_MESH) {
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Be:", 212,l_top - 3*l_dy,100,20, &sb->secondspring, 0.0, 10.0, 10, 0, "Bending Stiffness");
}
// uiBlockEndAlign(block);
// uiBlockBeginAlign(block);
/* but i like doing the spinner */
menustr= get_vertexgroup_menustr(ob);
defCount=BLI_countlist(&ob->defbase);
if(defCount==0) _loc_group= 0;
if(!sb->msg_lock){
uiDefButS(block, MENU, B_SOFTBODY_UP_GRSPRING, menustr,10,l_top - 4*l_dy,20,20, &sb->msg_value, 0, defCount, 0, 0, "Browses available vertex groups");
}
/* but defined by some magic */
but= uiDefBut(block, TEX, B_BAKE_CACHE_CHANGE, "VG:", 30, l_top - 4*l_dy,260,20, &sb->namedVG_Spring_K, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ob);
uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VGSPRING, ICON_X, 290,l_top - 4*l_dy,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
MEM_freeN (menustr);
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, OB_SB_QUADS, B_BAKE_CACHE_CHANGE, "Stiff Quads", 10,l_top - 5*l_dy,100,20, softflag, 0, 0, 0, 0, "Adds diagonal springs on 4-gons");
if(ob->type==OB_MESH) {
if (*softflag & OB_SB_QUADS){
uiDefButF(block, NUM, B_BAKE_CACHE_CHANGE, "Sh:", 111,l_top - 5*l_dy,100,20, &sb->shearstiff, 0.0, 1.0, 10, 0, "Shear Stiffness");
}
}
else sb->secondspring = 0;
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG,OB_SB_AERO_ANGLE,B_BAKE_CACHE_CHANGE, "N",10,l_top - 6*l_dy,20,20, softflag, 0, 0, 0, 0, "New aero(uses angle and length)");
uiDefButS(block, NUM, B_BAKE_CACHE_CHANGE, "Aero:", 30,l_top - 6*l_dy,80,20, &sb->aeroedge, 0.00, 30000.0, 10, 0, "Make edges 'sail'");
uiBlockEndAlign(block);
uiDefButBitS(block, TOG, OB_SB_EDGECOLL, B_BAKE_CACHE_CHANGE, "Collide Edges", 111,l_top - 6*l_dy,100,20, softflag, 0, 0, 0, 0, "Edge collide too");
uiDefButBitS(block, TOG, OB_SB_FACECOLL, B_BAKE_CACHE_CHANGE, "Collide Faces", 212,l_top - 6*l_dy,100,20, softflag, 0, 0, 0, 0, "Faces collide too SLOOOOOW warning ");
}
}
break;
}
} }
//} }
} }
uiBlockEndAlign(block); uiBlockEndAlign(block);
} }