Added signal OB_SB_REDO for ob->softflag to force a recalc.
authorTon Roosendaal <ton@blender.org>
Sat, 2 Apr 2005 15:55:15 +0000 (15:55 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 2 Apr 2005 15:55:15 +0000 (15:55 +0000)
Now used after weight painting, so it updates immediately.

source/blender/blenkernel/intern/softbody.c
source/blender/makesdna/DNA_object_types.h
source/blender/src/vpaint.c

index 601b7e45afd92feb2d4bdb2a6e98e76b8dd45fc4..01d0735af5dcbda518aeede9ac7011b10db27549 100644 (file)
@@ -668,7 +668,7 @@ static int get_scalar_from_named_vertexgroup(Object *ob, char *name, int vertID,
                        /* Lets see if this vert is in the weight group */
                        for (i=0; i<dv->totweight; i++){
                                if (dv->dw[i].def_nr == groupindex){
-                                       *target=dv->dw[i].weight; /* got it ! */
+                                       *target= dv->dw[i].weight; /* got it ! */
                                        return 0;
                                }
                        }
@@ -696,16 +696,19 @@ static void mesh_to_softbody(Object *ob)
        sb= ob->soft;   
        bp= sb->bpoint;
        for(a=me->totvert; a>0; a--, mvert++, bp++) {
+               
                VECCOPY(bp->pos, mvert->co);
                Mat4MulVecfl(ob->obmat, bp->pos);  // yep, sofbody is global coords
                VECCOPY(bp->origS, bp->pos);
                VECCOPY(bp->origE, bp->pos);
                VECCOPY(bp->origT, bp->pos);
+               
                bp->vec[0]= bp->vec[1]= bp->vec[2]= 0.0;
                bp->weight= 1.0;
                bp->goal= 0.5;
-               bp->nofsprings=0;
-               bp->springs=NULL;
+               bp->nofsprings= 0;
+               bp->springs= NULL;
+               
                if (1) { /* switch to vg scalars*/
                        /* get scalar values needed  *per vertex* from vertex group functions,
                           so we can *paint* them nicly .. 
@@ -717,12 +720,13 @@ static void mesh_to_softbody(Object *ob)
                        char name[32] = "SOFTGOAL";
                        float temp;
                        
-                       error = get_scalar_from_named_vertexgroup(ob,name,me->totvert - a,&temp);
+                       error = get_scalar_from_named_vertexgroup(ob, name, me->totvert - a, &temp);
                        if (!error) bp->goal = temp;
                        if (bp->goal < sb->mingoal) bp->goal = sb->mingoal;
                        if (bp->goal > sb->maxgoal) bp->goal = sb->maxgoal;
                        /* a little ad hoc changing the goal control to be less *sharp* */
                        bp->goal = (float)pow(bp->goal,4.0f);
+                       
                        /* to proove the concept
                        this would enable per vertex *mass painting*
                        strcpy(name,"SOFTMASS");
@@ -755,6 +759,7 @@ static void mesh_to_softbody(Object *ob)
 
                build_bps_springlist(ob); /* big mesh optimization */
        }
+       
 }
 
 /* copies current sofbody position in mesh, so do this within modifier stacks! */
@@ -870,6 +875,7 @@ void sbObjectToSoftbody(Object *ob)
        }
        
        if(ob->soft) ob->soft->ctime= bsystem_time(ob, NULL, (float)G.scene->r.cfra, 0.0);
+       ob->softflag &= ~OB_SB_REDO;
 }
 
 /* reset all motion */
@@ -904,10 +910,11 @@ void sbObjectStep(Object *ob, float framenr)
        float ctime, forcetime;
        float err;
 
-       /* just to be nice we allow full init */
-       if(ob->soft==NULL) sbObjectToSoftbody(ob);
-       /* this is after reading new file, or acceptable as signal to refresh */
-       else if(ob->soft->totpoint==0) sbObjectToSoftbody(ob);
+       /* remake softbody if: */
+       if( (ob->softflag & OB_SB_REDO) ||              // signal after weightpainting
+               (ob->soft==NULL) ||                                     // just to be nice we allow full init
+               (ob->soft->totpoint==0) )                       // after reading new file, or acceptable as signal to refresh
+                       sbObjectToSoftbody(ob);
        
        sb= ob->soft;
        
index 4addd3ddff0bef29d42369af39bacc758429f299..13ea7def290d2c669b21e5f8bdf1f017174ac6f2 100644 (file)
@@ -419,7 +419,7 @@ extern Object workob;
 #define OB_SB_EDGES            4
 #define OB_SB_QUADS            8
 #define OB_SB_POSTDEF  16
-
+#define OB_SB_REDO             32
 
 #ifdef __cplusplus
 }
index 99a2d3dcc23158fd873fb2bddcd75a8b5955183f..3c584b850e84c8d2e81b5e8728b5580406356f36 100644 (file)
 #include "DNA_view3d_types.h"
 #include "DNA_userdef_types.h"
 
-#include "BKE_utildefines.h"
-#include "BKE_mesh.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_utildefines.h"
 
 #include "BIF_graphics.h"
 #include "BIF_interface.h"
@@ -930,6 +931,8 @@ void weight_paint(void)
        }
        
        makeDispList(ob);
+       // this flag is event for softbody to refresh weightpaint values
+       if(ob->soft) ob->softflag |= OB_SB_REDO;
        
        allqueue(REDRAWVIEW3D, 0);