Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/softbody.c')
-rw-r--r--source/blender/blenkernel/intern/softbody.c470
1 files changed, 133 insertions, 337 deletions
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index bc6b487080c..450a64d72eb 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -58,7 +58,6 @@ variables on the UI for now
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force.h" /* here is the softbody struct */
-#include "DNA_particle_types.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -76,13 +75,12 @@ variables on the UI for now
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_object.h"
-#include "BKE_particle.h"
#include "BKE_softbody.h"
#include "BKE_utildefines.h"
#include "BKE_DerivedMesh.h"
#include "BKE_pointcache.h"
#include "BKE_modifier.h"
-
+#include "BKE_deform.h"
//XXX #include "BIF_editdeform.h"
//XXX #include "BIF_graphics.h"
#include "PIL_time.h"
@@ -494,32 +492,21 @@ static void ccd_build_deflector_hash(Scene *scene, Object *vertexowner, GHash *h
while (base) {
/*Only proceed for mesh object in same layer */
if(base->object->type==OB_MESH && (base->lay & vertexowner->lay)) {
- int particles=0;
ob= base->object;
if((vertexowner) && (ob == vertexowner)) {
- if(vertexowner->soft->particles){
- particles=1;
- }
- else {
- /* if vertexowner is given we don't want to check collision with owner object */
- base = base->next;
- continue;
- }
+ /* if vertexowner is given we don't want to check collision with owner object */
+ base = base->next;
+ continue;
}
/*+++ only with deflecting set */
if(ob->pd && ob->pd->deflect && BLI_ghash_lookup(hash, ob) == 0) {
DerivedMesh *dm= NULL;
- if(particles) {
- dm = psys_get_modifier(ob,psys_get_current(ob))->dm;
- }
- else {
- if(ob->softflag & OB_SB_COLLFINAL) /* so maybe someone wants overkill to collide with subsurfed */
- dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
- else
- dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
- }
+ if(ob->softflag & OB_SB_COLLFINAL) /* so maybe someone wants overkill to collide with subsurfed */
+ dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+ else
+ dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
if(dm){
ccd_Mesh *ccdmesh = ccd_mesh_make(ob, dm);
@@ -866,7 +853,8 @@ 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;
}
}
}
@@ -2051,7 +2039,7 @@ static void sb_spring_force(Object *ob,int bpi,BodySpring *bs,float iks,float fo
BodyPoint *bp1,*bp2;
float dir[3],dvel[3];
- float distance,forcefactor,kd,absvel,projvel;
+ float distance,forcefactor,kd,absvel,projvel,kw;
int ia,ic;
/* prepare depending on which side of the spring we are on */
if (bpi == bs->v1){
@@ -2085,7 +2073,10 @@ static void sb_spring_force(Object *ob,int bpi,BodySpring *bs,float iks,float fo
forcefactor = iks/bs->len;
else
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);
/* do bp1 <--> bp2 viscous */
@@ -2185,14 +2176,14 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo
VecMidf(velcenter, bp->vec, obp->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,sb->balldamp,dvel);
/* exploit force(a,b) == -force(b,a) part2/2 */
VecSubf(dvel,velcenter,obp->vec);
- VecMulf(dvel,sb->nodemass);
+ VecMulf(dvel,bp->mass);
Vec3PlusStVec(obp->force,sb->balldamp,dvel);
Vec3PlusStVec(obp->force,-f*(1.0f-sb->balldamp),def);
@@ -2237,7 +2228,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo
/* gravitation */
if (sb){
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 */
@@ -2549,7 +2540,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa
VecMidf(velcenter, bp->vec, obp->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,sb->balldamp,dvel);
@@ -2580,7 +2571,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa
/* exploit force(a,b) == -force(b,a) part2/2 */
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,-f*(1.0f-sb->balldamp),def);
@@ -2640,8 +2631,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa
/* gravitation */
- bp->force[2]-= gravity*sb->nodemass; /* individual mass of node here */
- //bp->force[1]-= gravity*sb->nodemass; /* individual mass of node here */
+ bp->force[2]-= gravity*bp->mass; /* individual mass of node here */
/* particle field & vortex */
@@ -2850,11 +2840,20 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float *
aabbmin[0]=aabbmin[1]=aabbmin[2] = 1e20f;
aabbmax[0]=aabbmax[1]=aabbmax[2] = -1e20f;
+ /* old one with homogenous masses */
/* claim a minimum mass for vertex */
+ /*
if (sb->nodemass > 0.009999f) timeovermass = forcetime/sb->nodemass;
else timeovermass = forcetime/0.009999f;
+ */
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){
/* this makes t~ = t */
if(mid_flags & MID_PRESERVE) VECCOPY(dx,bp->vec);
@@ -3228,10 +3227,36 @@ static void mesh_to_softbody(Scene *scene, Object *ob)
/* to proove the concept
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 */
@@ -3533,107 +3558,6 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob)
}
}
-
-static void springs_from_particles(Object *ob)
-{
- ParticleSystem *psys;
- ParticleSystemModifierData *psmd=0;
- ParticleData *pa=0;
- HairKey *key=0;
- SoftBody *sb;
- BodyPoint *bp;
- BodySpring *bs;
- int a,k;
- float hairmat[4][4];
-
- if(ob && ob->soft && ob->soft->particles) {
- psys= ob->soft->particles;
- sb= ob->soft;
- psmd = psys_get_modifier(ob, psys);
-
- bp= sb->bpoint;
- for(a=0, pa=psys->particles; a<psys->totpart; a++, pa++) {
- for(k=0, key=pa->hair; k<pa->totkey; k++, bp++, key++) {
- VECCOPY(bp->origS, key->co);
-
- psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat);
-
- Mat4MulVecfl(hairmat, bp->origS);
- }
- }
-
- for(a=0, bs=sb->bspring; a<sb->totspring; a++, bs++)
- bs->len= VecLenf(sb->bpoint[bs->v1].origS, sb->bpoint[bs->v2].origS);
- }
-}
-
-static void particles_to_softbody(Scene *scene, Object *ob)
-{
- SoftBody *sb;
- BodyPoint *bp;
- BodySpring *bs;
- ParticleData *pa;
- HairKey *key;
- ParticleSystem *psys= ob->soft->particles;
- float goalfac;
- int a, k, curpoint;
- int totpoint= psys_count_keys(psys);
- int totedge= totpoint-psys->totpart;
-
- /* renew ends with ob->soft with points and edges, also checks & makes ob->soft */
- renew_softbody(scene, ob, totpoint, totedge);
-
- /* 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;
- }
-
- /* we always make body points */
- sb= ob->soft;
- bp= sb->bpoint;
- bs= sb->bspring;
- goalfac= ABS(sb->maxgoal - sb->mingoal);
-
- if((ob->softflag & OB_SB_GOAL)) {
- for(a=0, pa=psys->particles; a<psys->totpart; a++, pa++) {
- for(k=0, key=pa->hair; k<pa->totkey; k++,bp++,key++) {
- if(k) {
- bp->goal= key->weight;
- bp->goal= sb->mingoal + bp->goal*goalfac;
- bp->goal= (float)pow(bp->goal, 4.0f);
- }
- else{
- /* hair roots are allways fixed fully to goal */
- bp->goal= 1.0f;
- }
- }
- }
- }
-
- bp= sb->bpoint;
- curpoint=0;
- for(a=0, pa=psys->particles; a<psys->totpart; a++, curpoint++, pa++) {
- for(k=0; k<pa->totkey-1; k++,bs++,curpoint++) {
- bs->v1=curpoint;
- bs->v2=curpoint+1;
- bs->strength= 1.0;
- bs->order=1;
- }
- }
-
- build_bps_springlist(ob); /* scan for springs attached to bodypoints ONCE */
- /* insert *other second order* springs if desired */
- if(sb->secondspring > 0.0000001f) {
- add_2nd_order_springs(ob,sb->secondspring*10.0); /* exploits the the first run of build_bps_springlist(ob);*/
- build_bps_springlist(ob); /* yes we need to do it again*/
- }
- springs_from_particles(ob); /* write the 'rest'-lenght of the springs */
- if(ob->softflag & OB_SB_SELF)
- calculate_collision_balls(ob);
-}
-
/* copies softbody result back in object */
static void softbody_to_object(Object *ob, float (*vertexCos)[3], int numVerts, int local)
{
@@ -3650,66 +3574,6 @@ static void softbody_to_object(Object *ob, float (*vertexCos)[3], int numVerts,
}
}
-void sbWriteCache(Object *ob, int framenr)
-{
- SoftBody *sb= ob->soft;
- BodyPoint *bp;
- PTCacheID pid;
- PTCacheFile *pf;
- int a;
-
- if(sb->totpoint == 0)
- return;
-
- BKE_ptcache_id_from_softbody(&pid, ob, sb);
- pf= BKE_ptcache_file_open(&pid, PTCACHE_FILE_WRITE, framenr);
- if(!pf)
- return;
-
- for(a=0, bp=sb->bpoint; a<sb->totpoint; a++, bp++)
- BKE_ptcache_file_write_floats(pf, bp->pos, 3);
-
- for(a=0, bp=sb->bpoint; a<sb->totpoint; a++, bp++)
- BKE_ptcache_file_write_floats(pf, bp->vec, 3);
-
- BKE_ptcache_file_close(pf);
-}
-
-static int softbody_read_cache(Object *ob, float framenr)
-{
- SoftBody *sb= ob->soft;
- BodyPoint *bp;
- PTCacheID pid;
- PTCacheFile *pf;
- int a;
-
- if(sb->totpoint == 0)
- return 0;
-
- BKE_ptcache_id_from_softbody(&pid, ob, sb);
- pf= BKE_ptcache_file_open(&pid, PTCACHE_FILE_READ, framenr);
- if(!pf)
- return 0;
-
- for(a=0, bp=sb->bpoint; a<sb->totpoint; a++, bp++) {
- if(!BKE_ptcache_file_read_floats(pf, bp->pos, 3)) {
- BKE_ptcache_file_close(pf);
- return 0;
- }
- }
-
- for(a=0, bp=sb->bpoint; a<sb->totpoint; a++, bp++) {
- if(!BKE_ptcache_file_read_floats(pf, bp->vec, 3)) {
- BKE_ptcache_file_close(pf);
- return 0;
- }
- }
-
- BKE_ptcache_file_close(pf);
-
- return 1;
-}
-
/* +++ ************ maintaining scratch *************** */
static void sb_new_scratch(SoftBody *sb)
{
@@ -3769,7 +3633,7 @@ SoftBody *sbNew(Scene *scene)
sb->shearstiff = 1.0f;
sb->solverflags |= SBSO_OLDERR;
- sb->pointcache = BKE_ptcache_add();
+ sb->pointcache = BKE_ptcache_add(&sb->ptcaches);
return sb;
}
@@ -3778,7 +3642,8 @@ SoftBody *sbNew(Scene *scene)
void sbFree(SoftBody *sb)
{
free_softbody_intern(sb);
- BKE_ptcache_free(sb->pointcache);
+ BKE_ptcache_free_list(&sb->ptcaches);
+ sb->pointcache = NULL;
MEM_freeN(sb);
}
@@ -3816,44 +3681,16 @@ void sbSetInterruptCallBack(int (*f)(void))
static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCos)[3], int numVerts)
{
- ParticleSystemModifierData *psmd= NULL;
- ParticleData *pa= NULL;
- HairKey *key= NULL;
BodyPoint *bp;
- float hairmat[4][4];
int a;
- /* update the vertex locations */
- if(sb->particles && sb->particles->totpart>0) {
- psmd= psys_get_modifier(ob,sb->particles);
-
- pa= sb->particles->particles;
- key= pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
-
for(a=0,bp=sb->bpoint; a<numVerts; a++, bp++) {
/* store where goals are now */
VECCOPY(bp->origS, bp->origE);
/* copy the position of the goals at desired end time */
- if(sb->particles) {
- if(key == pa->hair + pa->totkey) {
- pa++;
- key = pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
- VECCOPY(bp->origE, key->co);
- Mat4MulVecfl(hairmat,bp->origE);
-
- key++;
- }
- else{
- VECCOPY(bp->origE, vertexCos[a]);
- /* vertexCos came from local world, go global */
- Mat4MulVecfl(ob->obmat, bp->origE);
- }
+ VECCOPY(bp->origE, vertexCos[a]);
+ /* vertexCos came from local world, go global */
+ Mat4MulVecfl(ob->obmat, bp->origE);
/* just to be save give bp->origT a defined value
will be calulated in interpolate_exciter()*/
VECCOPY(bp->origT, bp->origE);
@@ -3862,37 +3699,12 @@ static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCo
static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int numVerts)
{
- ParticleSystemModifierData *psmd= NULL;
- HairKey *key= NULL;
- ParticleData *pa= NULL;
BodyPoint *bp;
- float hairmat[4][4];
int a;
- if(sb->particles && sb->particles->totpart>0) {
- psmd= psys_get_modifier(ob, sb->particles);
- pa= sb->particles->particles;
- key= pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
-
for(a=0,bp=sb->bpoint; a<numVerts; a++, bp++) {
- if(sb->particles) {
- if(key == pa->hair + pa->totkey) {
- pa++;
- key = pa->hair;
-
- psys_mat_hair_to_global(ob, psmd->dm, sb->particles->part->from, pa, hairmat);
- }
- VECCOPY(bp->pos, key->co);
- Mat4MulVecfl(hairmat, bp->pos);
- key++;
- }
- else {
- VECCOPY(bp->pos, vertexCos[a]);
- Mat4MulVecfl(ob->obmat, bp->pos); /* yep, sofbody is global coords*/
- }
+ VECCOPY(bp->pos, vertexCos[a]);
+ 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);
@@ -3921,20 +3733,18 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int
sb_new_scratch(sb); /* make a new */
sb->scratch->needstobuildcollider=1;
- if((sb->particles)==0) {
- /* copy some info to scratch */
- switch(ob->type) {
- case OB_MESH:
- if (ob->softflag & OB_SB_FACECOLL) mesh_faces_to_scratch(ob);
- break;
- case OB_LATTICE:
- break;
- case OB_CURVE:
- case OB_SURF:
- break;
- default:
- break;
- }
+ /* copy some info to scratch */
+ switch(ob->type) {
+ case OB_MESH:
+ if (ob->softflag & OB_SB_FACECOLL) mesh_faces_to_scratch(ob);
+ break;
+ case OB_LATTICE:
+ break;
+ case OB_CURVE:
+ case OB_SURF:
+ break;
+ default:
+ break;
}
}
@@ -4070,13 +3880,12 @@ static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime)
/* simulates one step. framenr is in frames */
void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], int numVerts)
{
- ParticleSystemModifierData *psmd=0;
- ParticleData *pa=0;
SoftBody *sb= ob->soft;
PointCache *cache;
PTCacheID pid;
float dtime, timescale;
int framedelta, framenr, startframe, endframe;
+ int cache_result;
cache= sb->pointcache;
@@ -4091,7 +3900,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
if(sb->bpoint && numVerts != sb->totpoint) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
-
+ cache->last_exact= 0;
return;
}
@@ -4099,6 +3908,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;
return;
}
@@ -4110,25 +3920,20 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
if(sb->bpoint == NULL ||
((ob->softflag & OB_SB_EDGES) && !ob->soft->bspring && object_has_edges(ob))) {
- if(sb->particles){
- particles_to_softbody(scene, ob);
- }
- else {
- switch(ob->type) {
- case OB_MESH:
- mesh_to_softbody(scene, ob);
- break;
- case OB_LATTICE:
- lattice_to_softbody(scene, ob);
- break;
- case OB_CURVE:
- case OB_SURF:
- curve_surf_to_softbody(scene, ob);
- break;
- default:
- renew_softbody(scene, ob, numVerts, 0);
- break;
- }
+ switch(ob->type) {
+ case OB_MESH:
+ mesh_to_softbody(scene, ob);
+ break;
+ case OB_LATTICE:
+ lattice_to_softbody(scene, ob);
+ break;
+ case OB_CURVE:
+ case OB_SURF:
+ curve_surf_to_softbody(scene, ob);
+ break;
+ default:
+ renew_softbody(scene, ob, numVerts, 0);
+ break;
}
softbody_update_positions(ob, sb, vertexCos, numVerts);
@@ -4146,8 +3951,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
softbody_update_positions(ob, sb, vertexCos, numVerts);
softbody_step(scene, ob, sb, dtime);
- if(sb->particles==0)
- softbody_to_object(ob, vertexCos, numVerts, 0);
+ softbody_to_object(ob, vertexCos, numVerts, 0);
return;
}
@@ -4155,68 +3959,60 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
/* still no points? go away */
if(sb->totpoint==0) return;
- if(sb->particles){
- psmd= psys_get_modifier(ob, sb->particles);
- pa= sb->particles->particles;
+ if(framenr == startframe) {
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+
+ /* 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->flag &= ~PTCACHE_REDO_NEEDED;
+ return;
}
/* try to read from cache */
- if(softbody_read_cache(ob, framenr)) {
- if(sb->particles==0)
- softbody_to_object(ob, vertexCos, numVerts, sb->local);
+ cache_result = BKE_ptcache_read_cache(&pid, framenr, scene->r.frs_sec);
+
+ if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
+ softbody_to_object(ob, vertexCos, numVerts, sb->local);
- cache->flag |= PTCACHE_SIMULATION_VALID;
cache->simframe= framenr;
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+
+ if(cache_result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
+ BKE_ptcache_write_cache(&pid, framenr);
return;
}
+ else if(cache_result==PTCACHE_READ_OLD) {
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ }
else if(ob->id.lib || (cache->flag & PTCACHE_BAKED)) {
/* if baked and nothing in cache, do nothing */
- if(cache->flag & PTCACHE_SIMULATION_VALID) {
- cache->flag &= ~PTCACHE_SIMULATION_VALID;
- cache->simframe= 0;
- }
-
+ cache->flag &= ~PTCACHE_SIMULATION_VALID;
+ cache->simframe= 0;
+ cache->last_exact= 0;
return;
}
- if(framenr == startframe) {
- /* first frame, no simulation to do, just set the positions */
- softbody_update_positions(ob, sb, vertexCos, numVerts);
+ /* if on second frame, write cache for first frame */
+ if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
+ BKE_ptcache_write_cache(&pid, startframe);
- cache->flag |= PTCACHE_SIMULATION_VALID;
- cache->simframe= framenr;
+ softbody_update_positions(ob, sb, vertexCos, numVerts);
- /* don't write cache on first frame, but on second frame write
- * cache for frame 1 and 2 */
- }
- else if(framedelta == 1) {
- /* if on second frame, write cache for first frame */
- if(framenr == startframe+1)
- sbWriteCache(ob, startframe);
+ /* checking time: */
+ dtime = framedelta*timescale;
- softbody_update_positions(ob, sb, vertexCos, numVerts);
+ softbody_step(scene, ob, sb, dtime);
- /* do simulation */
- cache->flag |= PTCACHE_SIMULATION_VALID;
- cache->simframe= framenr;
-
- /* checking time: */
- dtime = framedelta*timescale;
-
- softbody_step(scene, ob, sb, dtime);
+ softbody_to_object(ob, vertexCos, numVerts, 0);
- if(sb->particles==0)
- softbody_to_object(ob, vertexCos, numVerts, 0);
+ /* do simulation */
+ cache->simframe= framenr;
+ cache->flag |= PTCACHE_SIMULATION_VALID;
- sbWriteCache(ob, framenr);
- }
- else {
- /* time step backwards or too large forward - do nothing */
- if(cache->flag & PTCACHE_SIMULATION_VALID) {
- cache->flag &= ~PTCACHE_SIMULATION_VALID;
- cache->simframe= 0;
- }
- }
+ BKE_ptcache_write_cache(&pid, framenr);
}