Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / blenkernel / intern / softbody.c
index fdbfe15..68f918b 100644 (file)
@@ -866,8 +866,7 @@ static void renew_softbody(Scene *scene, Object *ob, int totpoint, int totspring
                        bp->frozen = 1.0f;
                        bp->colball = 0.0f;
                        bp->flag = 0;
-                       bp->springweight = 1.0f;
-                       bp->mass = sb->nodemass;
+
                }
        }
 }
@@ -3623,9 +3622,9 @@ static void particles_to_softbody(Scene *scene, Object *ob)
 
        /* find first BodyPoint index for each particle */
        if(psys->totpart > 0) {
-//             psys->particles->bpi = 0;
-//             for(a=1, pa=psys->particles+1; a<psys->totpart; a++, pa++)
-//                     pa->bpi = (pa-1)->bpi + (pa-1)->totkey;
+               psys->particles->bpi = 0;
+               for(a=1, pa=psys->particles+1; a<psys->totpart; a++, pa++)
+                       pa->bpi = (pa-1)->bpi + (pa-1)->totkey;
        }
 
        /* we always make body points */
@@ -4079,7 +4078,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
        if(framenr < startframe) {
                cache->flag &= ~PTCACHE_SIMULATION_VALID;
                cache->simframe= 0;
-               //cache->last_exact= 0;
+               cache->last_exact= 0;
 
                return;
        }
@@ -4141,29 +4140,20 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
                pa= sb->particles->particles;
        }
 
-       if(framenr == startframe && cache->flag & PTCACHE_REDO_NEEDED) {
-               BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
-               cache->simframe= framenr;
-               cache->flag &= ~PTCACHE_REDO_NEEDED;
-               return;
-       }
-
        /* try to read from cache */
        cache_result = BKE_ptcache_read_cache(&pid, framenr, scene->r.frs_sec);
 
        if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
-               if(sb->particles==0)
-                       softbody_to_object(ob, vertexCos, numVerts, sb->local);
-
-               cache->simframe= framenr;
                cache->flag |= PTCACHE_SIMULATION_VALID;
+               cache->simframe= framenr;
 
-               if(cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
-                       BKE_ptcache_write_cache(&pid, framenr);
+               if(sb->particles==0)
+                       softbody_to_object(ob, vertexCos, numVerts, sb->local);
 
                return;
        }
        else if(cache_result==PTCACHE_READ_OLD) {
+               BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_FREE);
                cache->flag |= PTCACHE_SIMULATION_VALID;
        }
        else if(ob->id.lib || (cache->flag & PTCACHE_BAKED)) {
@@ -4175,11 +4165,16 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
        }
 
        if(framenr == startframe) {
+               if(cache->flag & PTCACHE_REDO_NEEDED) {
+                       softbody_update_positions(ob, sb, vertexCos, numVerts);
+                       softbody_reset(ob, sb, vertexCos, numVerts);
+                       cache->flag &= ~PTCACHE_REDO_NEEDED;
+               }
                /* first frame, no simulation to do, just set the positions */
                softbody_update_positions(ob, sb, vertexCos, numVerts);
 
-               cache->simframe= framenr;
                cache->flag |= PTCACHE_SIMULATION_VALID;
+               cache->simframe= framenr;
 
                /* don't write cache on first frame, but on second frame write
                 * cache for frame 1 and 2 */
@@ -4191,6 +4186,10 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
 
                softbody_update_positions(ob, sb, vertexCos, numVerts);
 
+               /* do simulation */
+               cache->flag |= PTCACHE_SIMULATION_VALID;
+               cache->simframe= framenr;
+
                /* checking time: */
                dtime = framedelta*timescale;
 
@@ -4199,10 +4198,6 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
                if(sb->particles==0)
                        softbody_to_object(ob, vertexCos, numVerts, 0);
 
-               /* do simulation */
-               cache->simframe= framenr;
-               cache->flag |= PTCACHE_SIMULATION_VALID;
-
                BKE_ptcache_write_cache(&pid, framenr);
        }
 }