~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/softbody.c

  • Committer: Dietrich Bollmann
  • Date: 2009-07-26 14:27:44 UTC
  • mfrom: (184.1.1008)
  • Revision ID: dietrich@formgames.org-20090726142744-75hivjratygfz7q3
Update to state of blender repository from 2009-07-26 revision 21911 (launchpad: 1192).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  softbody.c      
2
2
 * 
3
 
 * $Id: softbody.c 18715 2009-01-28 12:34:22Z bjornmose $
 
3
 * $Id: softbody.c 21142 2009-06-24 23:42:45Z bjornmose $
4
4
 *
5
5
 * ***** BEGIN GPL LICENSE BLOCK *****
6
6
 *
82
82
#include "BKE_DerivedMesh.h"
83
83
#include "BKE_pointcache.h"
84
84
#include "BKE_modifier.h"
85
 
 
 
85
#include "BKE_deform.h"
86
86
#include  "BIF_editdeform.h"
87
87
#include  "BIF_graphics.h"
88
88
#include  "PIL_time.h"
2052
2052
        BodyPoint  *bp1,*bp2;
2053
2053
 
2054
2054
        float dir[3],dvel[3];
2055
 
        float distance,forcefactor,kd,absvel,projvel;
 
2055
        float distance,forcefactor,kd,absvel,projvel,kw;
2056
2056
        int ia,ic;
2057
2057
        /* prepare depending on which side of the spring we are on */
2058
2058
        if (bpi == bs->v1){
2086
2086
                forcefactor = iks/bs->len;
2087
2087
        else
2088
2088
                forcefactor = iks;
2089
 
        forcefactor *= bs->strength; 
 
2089
            kw = (bp1->springweight+bp2->springweight)/2.0f;
 
2090
                kw = kw * kw;
 
2091
                kw = kw * kw;
 
2092
        forcefactor *= bs->strength * kw; 
2090
2093
        Vec3PlusStVec(bp1->force,(bs->len - distance)*forcefactor,dir);
2091
2094
 
2092
2095
        /* do bp1 <--> bp2 viscous */
2185
2188
 
2186
2189
                                                        VecMidf(velcenter, bp->vec, obp->vec);
2187
2190
                                                        VecSubf(dvel,velcenter,bp->vec);
2188
 
                                                        VecMulf(dvel,sb->nodemass);
 
2191
                                                        VecMulf(dvel,bp->mass);
2189
2192
 
2190
2193
                                                        Vec3PlusStVec(bp->force,f*(1.0f-sb->balldamp),def);
2191
2194
                                                        Vec3PlusStVec(bp->force,sb->balldamp,dvel);
2192
2195
 
2193
2196
                                                        /* exploit force(a,b) == -force(b,a) part2/2 */
2194
2197
                                                        VecSubf(dvel,velcenter,obp->vec);
2195
 
                                                        VecMulf(dvel,sb->nodemass);
 
2198
                                                        VecMulf(dvel,bp->mass);
2196
2199
 
2197
2200
                                                        Vec3PlusStVec(obp->force,sb->balldamp,dvel);
2198
2201
                                                        Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def);
2237
2240
                        /* gravitation */
2238
2241
                        if (sb){ 
2239
2242
                        float gravity = sb->grav * sb_grav_force_scale(ob);     
2240
 
                        bp->force[2]-= gravity*sb->nodemass; /* individual mass of node here */
 
2243
                        bp->force[2]-= gravity*bp->mass; /* individual mass of node here */
2241
2244
                        }
2242
2245
                        
2243
2246
                        /* particle field & vortex */
2549
2552
 
2550
2553
                                                        VecMidf(velcenter, bp->vec, obp->vec);
2551
2554
                                                        VecSubf(dvel,velcenter,bp->vec);
2552
 
                                                        VecMulf(dvel,sb->nodemass);
 
2555
                                                        VecMulf(dvel,bp->mass);
2553
2556
 
2554
2557
                                                        Vec3PlusStVec(bp->force,f*(1.0f-sb->balldamp),def);
2555
2558
                                                        Vec3PlusStVec(bp->force,sb->balldamp,dvel);
2580
2583
 
2581
2584
                                                        /* exploit force(a,b) == -force(b,a) part2/2 */
2582
2585
                                                        VecSubf(dvel,velcenter,obp->vec);
2583
 
                                                        VecMulf(dvel,sb->nodemass);
 
2586
                                                        VecMulf(dvel,(bp->mass+obp->mass)/2.0f);
2584
2587
 
2585
2588
                                                        Vec3PlusStVec(obp->force,sb->balldamp,dvel);
2586
2589
                                                        Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def);
2640
2643
 
2641
2644
 
2642
2645
                                /* gravitation */
2643
 
                                bp->force[2]-= gravity*sb->nodemass; /* individual mass of node here */
2644
 
                                //bp->force[1]-= gravity*sb->nodemass; /* individual mass of node here */
 
2646
                                bp->force[2]-= gravity*bp->mass; /* individual mass of node here */
2645
2647
 
2646
2648
 
2647
2649
                                /* particle field & vortex */
2850
2852
    aabbmin[0]=aabbmin[1]=aabbmin[2] = 1e20f;
2851
2853
    aabbmax[0]=aabbmax[1]=aabbmax[2] = -1e20f;
2852
2854
 
 
2855
    /* old one with homogenous masses  */
2853
2856
        /* claim a minimum mass for vertex */
 
2857
        /*
2854
2858
        if (sb->nodemass > 0.009999f) timeovermass = forcetime/sb->nodemass;
2855
2859
        else timeovermass = forcetime/0.009999f;
 
2860
        */
2856
2861
        
2857
2862
        for(a=sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) {
 
2863
/* now we have individual masses   */
 
2864
/* claim a minimum mass for vertex */
 
2865
                if (bp->mass > 0.009999f) timeovermass = forcetime/bp->mass;
 
2866
            else timeovermass = forcetime/0.009999f;
 
2867
 
 
2868
 
2858
2869
                if(bp->goal < SOFTGOALSNAP){
2859
2870
            /* this makes t~ = t */
2860
2871
                        if(mid_flags & MID_PRESERVE) VECCOPY(dx,bp->vec);
3075
3086
        int a;
3076
3087
        float b,l,r;
3077
3088
 
3078
 
    b = sb->plastic;
3079
3089
        if (sb && sb->totspring){
 
3090
                b = sb->plastic;
3080
3091
                for(a=0; a<sb->totspring; a++) {
3081
3092
                        bs  = &sb->bspring[a];
3082
3093
                        bp1 =&sb->bpoint[bs->v1];
3228
3239
                        
3229
3240
                /* to proove the concept
3230
3241
                this would enable per vertex *mass painting*
3231
 
                strcpy(name,"SOFTMASS");
3232
 
                error = get_scalar_from_named_vertexgroup(ob,name, a,&temp);
3233
 
                if (!error) bp->mass = temp * ob->rangeofmass;
3234
3242
                */
 
3243
                /* first set the default */
 
3244
                bp->mass = sb->nodemass;
 
3245
 
 
3246
                if (sb->namedVG_Mass[0])
 
3247
                {
 
3248
                        int grp= get_named_vertexgroup_num (ob,sb->namedVG_Mass);
 
3249
                        /* printf("VGN  %s %d \n",sb->namedVG_Mass,grp); */
 
3250
                        if(grp > -1){
 
3251
                                get_scalar_from_vertexgroup(ob, a,(short) (grp), &bp->mass);
 
3252
                                bp->mass = bp->mass * sb->nodemass;
 
3253
                                /* printf("bp->mass  %f \n",bp->mass); */
 
3254
 
 
3255
                        }
 
3256
                }
 
3257
                /* first set the default */
 
3258
                bp->springweight = 1.0f;
 
3259
 
 
3260
                if (sb->namedVG_Spring_K[0])
 
3261
                {
 
3262
                        int grp= get_named_vertexgroup_num (ob,sb->namedVG_Spring_K);
 
3263
                        //printf("VGN  %s %d \n",sb->namedVG_Spring_K,grp); 
 
3264
                        if(grp > -1){
 
3265
                                get_scalar_from_vertexgroup(ob, a,(short) (grp), &bp->springweight);
 
3266
                                //printf("bp->springweight  %f \n",bp->springweight);
 
3267
 
 
3268
                        }
 
3269
                }
 
3270
 
 
3271
                
3235
3272
        }
3236
3273
 
3237
3274
        /* but we only optionally add body edge springs */
3546
3583
        int a,k;
3547
3584
        float hairmat[4][4];
3548
3585
 
3549
 
        psys= ob->soft->particles;
3550
 
        sb= ob->soft;   
3551
 
        if(ob && sb && psys) {  
 
3586
        if(ob && ob->soft && ob->soft->particles) {     
 
3587
                psys= ob->soft->particles;
 
3588
                sb= ob->soft;   
3552
3589
                psmd = psys_get_modifier(ob, psys);
3553
3590
 
3554
3591
                bp= sb->bpoint;