diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 38732377e29..7f3dda44255 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -1043,6 +1043,7 @@ static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff) static void lattice_to_softbody(Object *ob,int *rcs) { Lattice *lt= ob->data; + SoftBody *sb= ob->soft; int totvert, totspring = 0; totvert= lt->pntsu*lt->pntsv*lt->pntsw; @@ -1060,6 +1061,22 @@ static void lattice_to_softbody(Object *ob,int *rcs) /* renew ends with ob->soft with points and edges, also checks & makes ob->soft */ renew_softbody(ob, totvert, totspring,rcs); + /* weights from bpoints, same code used as for mesh vertices */ + if((ob->softflag & OB_SB_GOAL) && sb->vertgroup) { + BodyPoint *bp= sb->bpoint; + BPoint *bpnt= lt->def; + float goalfac= ABS(sb->maxgoal - sb->mingoal); + int a; + + for(a=0; agoal= sb->mingoal + bpnt->vec[3]*goalfac; + + /* a little ad hoc changing the goal control to be less *sharp* */ + bp->goal = (float)pow(bp->goal, 4.0f); + } + } + /* create some helper edges to enable SB lattice to be usefull at all */ if (ob->softflag & OB_SB_EDGES){ makelatticesprings(lt,ob->soft->bspring,ob->softflag & OB_SB_QUADS); diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index b1cdae8cd23..6f0d225239a 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -1877,23 +1877,28 @@ static void object_softbodies(Object *ob) uiBlockBeginAlign(block); uiDefButBitS(block, TOG, OB_SB_GOAL, B_SOFTBODY_CHANGE, "Use Goal", 10,100,130,20, &ob->softflag, 0, 0, 0, 0, "Define forces for vertices to stick to animated position"); - menustr= get_vertexgroup_menustr(ob); - defCount=BLI_countlist(&ob->defbase); - if(defCount==0) sb->vertgroup= 0; - uiDefButS(block, MENU, B_SOFTBODY_CHANGE, menustr, 140,100,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups"); - - if(sb->vertgroup) { - bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1); - if(defGroup) - uiDefBut(block, BUT, B_DIFF, defGroup->name, 160,100,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group"); + if(ob->type==OB_MESH) { + menustr= get_vertexgroup_menustr(ob); + defCount=BLI_countlist(&ob->defbase); + if(defCount==0) sb->vertgroup= 0; + uiDefButS(block, MENU, B_SOFTBODY_CHANGE, menustr, 140,100,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups"); + MEM_freeN (menustr); + + if(sb->vertgroup) { + bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1); + if(defGroup) + uiDefBut(block, BUT, B_DIFF, defGroup->name, 160,100,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group"); + else + uiDefBut(block, BUT, B_DIFF, "(no group)", 160,100,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,100,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group"); + } else - uiDefBut(block, BUT, B_DIFF, "(no group)", 160,100,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,100,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group"); + uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:", 160,100,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_SOFTBODY_CHANGE, "W", 140,100,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use Lattice weight values"); uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:", 160,100,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used"); } - MEM_freeN (menustr); uiDefButF(block, NUM, B_DIFF, "G Stiff:", 10,80,150,20, &sb->goalspring, 0.0, 0.999, 10, 0, "Goal (vertex target position) spring stiffness"); uiDefButF(block, NUM, B_DIFF, "G Damp:", 160,80,150,20, &sb->goalfrict , 0.0, 10.0, 10, 0, "Goal (vertex target position) friction"); diff --git a/source/blender/src/drawview.c b/source/blender/src/drawview.c index dfe0144c74d..1963e6ae31a 100644 --- a/source/blender/src/drawview.c +++ b/source/blender/src/drawview.c @@ -1298,7 +1298,9 @@ static void v3d_editvertex_buts(uiBlock *block, Object *ob, float lim) while(a--) { if(bp->f1 & SELECT) { VecAddf(median, median, bp->vec); + median[3]+= bp->vec[3]; tot++; + totw++; } bp++; } @@ -1329,9 +1331,12 @@ static void v3d_editvertex_buts(uiBlock *block, Object *ob, float lim) uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex X:", 10, 110, 290, 19, &(ve_median[0]), -lim, lim, 10, 3, ""); uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Y:", 10, 90, 290, 19, &(ve_median[1]), -lim, lim, 10, 3, ""); uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Z:", 10, 70, 290, 19, &(ve_median[2]), -lim, lim, 10, 3, ""); - if(totw==1) - uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex W:", 10, 50, 290, 19, &(ve_median[3]), 0.01, 100.0, 10, 3, ""); - + if(totw==1) { + if(ob->type==OB_LATTICE) + uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex W:", 10, 50, 290, 19, &(ve_median[3]), 0.0, 1.0, 10, 3, ""); + else + uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex W:", 10, 50, 290, 19, &(ve_median[3]), 0.01, 100.0, 10, 3, ""); + } if(defstr[0]) { uiDefBut(block, LABEL, 1, "Vertex Deform Groups", 10, 40, 290, 20, NULL, 0.0, 0.0, 0, 0, ""); @@ -1344,8 +1349,12 @@ static void v3d_editvertex_buts(uiBlock *block, Object *ob, float lim) uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median X:", 10, 110, 290, 19, &(ve_median[0]), -lim, lim, 10, 3, ""); uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Y:", 10, 90, 290, 19, &(ve_median[1]), -lim, lim, 10, 3, ""); uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Z:", 10, 70, 290, 19, &(ve_median[2]), -lim, lim, 10, 3, ""); - if(totw==tot) - uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median W:", 10, 50, 290, 19, &(ve_median[3]), 0.01, 100.0, 10, 3, ""); + if(totw==tot) { + if(ob->type==OB_LATTICE) + uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median W:", 10, 50, 290, 19, &(ve_median[3]), 0.0, 1.0, 10, 3, ""); + else + uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median W:", 10, 50, 290, 19, &(ve_median[3]), 0.01, 100.0, 10, 3, ""); + } } uiBlockEndAlign(block); @@ -1457,8 +1466,8 @@ static void v3d_editvertex_buts(uiBlock *block, Object *ob, float lim) bp= editLatt->def; while(a--) { if(bp->f1 & SELECT) { - VecAddf(median, median, bp->vec); VecAddf(bp->vec, bp->vec, median); + bp->vec[3]+= median[3]; } bp++; } diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 1db335c6482..863073ed575 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -2158,6 +2158,19 @@ void special_editmenu(void) else if(nr==2) armature_flip_names(); } + else if(G.obedit->type==OB_LATTICE) { + static float weight= 1.0f; + if(fbutton(&weight, 0.0f, 1.0f, 10, 10, "Set Weight")) { + int a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw; + BPoint *bp= editLatt->def; + + while(a--) { + if(bp->f1 & SELECT) + bp->vec[3]= weight; + bp++; + } + } + } countall(); allqueue(REDRAWVIEW3D, 0); diff --git a/source/blender/src/editview.c b/source/blender/src/editview.c index c1da247120a..2376fe93619 100644 --- a/source/blender/src/editview.c +++ b/source/blender/src/editview.c @@ -1462,7 +1462,7 @@ static void do_lattice_box_select__doSelect(void *userData, BPoint *bp, int x, i } static void do_lattice_box_select(rcti *rect, int select) { - struct { rcti *rect; short select, pass, done; } data; + struct { rcti *rect; int select, pass, done; } data; data.rect = rect; data.select = select;