bug fix soft body can resume with point cache

sneak in .. springs preload
This commit is contained in:
Jens Ole Wund 2008-04-05 21:29:17 +00:00
parent d0004bed8c
commit 83906a614b
3 changed files with 21 additions and 6 deletions

@ -2751,6 +2751,10 @@ static void springs_from_mesh(Object *ob)
if (G.rt > 500){
scale = (G.rt - 500) / 100.0f;
}
/* public version shrink to fit */
if (sb->springpreload != 0 ){
scale = sb->springpreload / 100.0f;
}
for(a=0; a<sb->totspring; a++) {
BodySpring *bs = &sb->bspring[a];
bs->len= scale*VecLenf(sb->bpoint[bs->v1].origS, sb->bpoint[bs->v2].origS);
@ -3268,6 +3272,9 @@ static void softbody_write_cache(Object *ob, float framenr)
for(a=0, bp=sb->bpoint; a<sb->totpoint; a++, bp++)
fwrite(&bp->pos, sizeof(float), 3, fp);
/*write velocities too */
for(a=0, bp=sb->bpoint; a<sb->totpoint; a++, bp++)
fwrite(&bp->vec, sizeof(float), 3, fp);
fclose(fp);
}
@ -3282,6 +3289,7 @@ static int softbody_read_cache(Object *ob, float framenr)
if(sb->totpoint == 0) return 0;
if(sb->particles)
stack_index = modifiers_indexInObject(ob,(ModifierData*)psys_get_modifier(ob,sb->particles));
else {
@ -3302,8 +3310,14 @@ static int softbody_read_cache(Object *ob, float framenr)
ret = 0;
break;
}
fclose(fp);
/*read velocities too !*/
for(a=0, bp=sb->bpoint; a<sb->totpoint; a++, bp++){
if(fread(&bp->vec, sizeof(float), 3, fp) != 3) {
ret = 0;
break;
}
}
fclose(fp);
}
return ret;

@ -130,7 +130,7 @@ typedef struct SoftBody {
maxloops,
choke,
solver_ID,
plastic,pad5
plastic,springpreload
;
struct SBScratch *scratch; /* scratch pad/cache on live time not saved in file */

@ -3985,9 +3985,10 @@ static void object_softbodies(Object *ob)
uiDefButBitS(block, TOG, OB_SB_QUADS, B_SOFTBODY_CHANGE, "Stiff Quads", 110,50,90,20, softflag, 0, 0, 0, 0, "Adds diagonal springs on 4-gons");
uiDefButBitS(block, TOG, OB_SB_EDGECOLL, B_DIFF, "CEdge", 220,50,45,20, softflag, 0, 0, 0, 0, "Edge collide too");
uiDefButBitS(block, TOG, OB_SB_FACECOLL, B_DIFF, "CFace", 265,50,45,20, softflag, 0, 0, 0, 0, "Faces collide too SLOOOOOW warning ");
uiDefButF(block, NUM, B_DIFF, "E Pull:", 10,30,100,20, &sb->inspring, 0.0, 0.999, 10, 0, "Edge spring stiffness when longer than rest length");
uiDefButF(block, NUM, B_DIFF, "E Push:", 110,30,100,20, &sb->inpush, 0.0, 0.999, 10, 0, "Edge spring stiffness when shorter than rest length");
uiDefButF(block, NUM, B_DIFF, "E Damp:", 210,30,100,20, &sb->infrict, 0.0, 50.0, 10, 0, "Edge spring friction");
uiDefButF(block, NUM, B_DIFF, "Pull:", 10,30,75,20, &sb->inspring, 0.0, 0.999, 10, 0, "Edge spring stiffness when longer than rest length");
uiDefButF(block, NUM, B_DIFF, "Push:", 85,30,75,20, &sb->inpush, 0.0, 0.999, 10, 0, "Edge spring stiffness when shorter than rest length");
uiDefButF(block, NUM, B_DIFF, "Damp:", 160,30,70,20, &sb->infrict, 0.0, 50.0, 10, 0, "Edge spring friction");
uiDefButS(block, NUM, B_SOFTBODY_CHANGE, "SL:",250 ,30,60,20, &sb->springpreload, 0.0, 200.0, 10, 0, "Alter spring lenght to shrink/blow up (unit %) 0 to disable ");
uiDefButBitS(block, TOG,OB_SB_AERO_ANGLE,B_SOFTBODY_CHANGE, "N",10,10,20,20, softflag, 0, 0, 0, 0, "New aero(uses angle and length)");
uiDefButS(block, NUM, B_DIFF, "Aero:", 30,10,60,20, &sb->aeroedge, 0.00, 30000.0, 10, 0, "Make edges 'sail'");