Cleanup: remove dead code in softbody forces evaluation.
This code has been disabled (hidden behind a specific debug value) for over 10 years now! More than time to get rid of it...
This commit is contained in:
@@ -2187,7 +2187,7 @@ static void sb_cf_threads_run(Scene *scene, Object *ob, float forcetime, float t
|
||||
MEM_freeN(sb_threads);
|
||||
}
|
||||
|
||||
static void softbody_calc_forcesEx(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow)
|
||||
static void softbody_calc_forces(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow)
|
||||
{
|
||||
/* rule we never alter free variables :bp->vec bp->pos in here !
|
||||
* this will ruin adaptive stepsize AKA heun! (BM)
|
||||
@@ -2230,256 +2230,6 @@ static void softbody_calc_forcesEx(struct Depsgraph *depsgraph, Scene *scene, Ob
|
||||
BKE_effectors_free(effectors);
|
||||
}
|
||||
|
||||
|
||||
static void softbody_calc_forces(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow)
|
||||
{
|
||||
/* redirection to the new threaded Version */
|
||||
if (!(G.debug_value & 0x10)) { // 16
|
||||
softbody_calc_forcesEx(depsgraph, scene, ob, forcetime, timenow);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
/* so the following will die */
|
||||
/* |||||||||||||||||||||||||| */
|
||||
/* VVVVVVVVVVVVVVVVVVVVVVVVVV */
|
||||
/*backward compatibility note:
|
||||
fixing bug [17428] which forces adaptive step size to tiny steps
|
||||
in some situations
|
||||
.. keeping G.debug_value==17 0x11 option for old files 'needing' the bug*/
|
||||
|
||||
/* rule we never alter free variables :bp->vec bp->pos in here !
|
||||
* this will ruin adaptive stepsize AKA heun! (BM)
|
||||
*/
|
||||
SoftBody *sb= ob->soft; /* is supposed to be there */
|
||||
BodyPoint *bp;
|
||||
/* BodyPoint *bproot; */ /* UNUSED */
|
||||
BodySpring *bs;
|
||||
float iks, ks, kd, gravity[3] = {0.0f, 0.0f, 0.0f};
|
||||
float fieldfactor = -1.0f, windfactor = 0.25f;
|
||||
float tune = sb->ballstiff;
|
||||
int do_deflector, do_selfcollision, do_springcollision, do_aero;
|
||||
|
||||
if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
|
||||
copy_v3_v3(gravity, scene->physics_settings.gravity);
|
||||
mul_v3_fl(gravity, sb_grav_force_scale(ob)*sb->effector_weights->global_gravity);
|
||||
}
|
||||
|
||||
/* check conditions for various options */
|
||||
do_deflector= query_external_colliders(depsgraph, sb->collision_group);
|
||||
do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF));
|
||||
do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL);
|
||||
do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES));
|
||||
|
||||
iks = 1.0f/(1.0f-sb->inspring)-1.0f ;/* inner spring constants function */
|
||||
/* bproot= sb->bpoint; */ /* need this for proper spring addressing */ /* UNUSED */
|
||||
|
||||
if (do_springcollision || do_aero) scan_for_ext_spring_forces(depsgraph, scene, ob, timenow);
|
||||
/* after spring scan because it uses Effoctors too */
|
||||
ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, ob->soft->effector_weights);
|
||||
|
||||
if (do_deflector) {
|
||||
float defforce[3];
|
||||
do_deflector = sb_detect_aabb_collisionCached(defforce, ob, timenow);
|
||||
}
|
||||
|
||||
bp = sb->bpoint;
|
||||
for (int a = sb->totpoint; a > 0; a--, bp++) {
|
||||
/* clear forces accumulator */
|
||||
bp->force[0] = bp->force[1] = bp->force[2] = 0.0;
|
||||
|
||||
/* naive ball self collision */
|
||||
/* needs to be done if goal snaps or not */
|
||||
if (do_selfcollision) {
|
||||
int attached;
|
||||
BodyPoint *obp;
|
||||
int c, b;
|
||||
float velcenter[3], dvel[3], def[3];
|
||||
float distance;
|
||||
float compare;
|
||||
|
||||
for (c=sb->totpoint, obp= sb->bpoint; c>=a; c--, obp++) {
|
||||
|
||||
//if ((bp->octantflag & obp->octantflag) == 0) continue;
|
||||
|
||||
compare = (obp->colball + bp->colball);
|
||||
sub_v3_v3v3(def, bp->pos, obp->pos);
|
||||
|
||||
/* rather check the AABBoxes before ever calculating the real distance */
|
||||
/* mathematically it is completely nuts, but performance is pretty much (3) times faster */
|
||||
if ((ABS(def[0]) > compare) || (ABS(def[1]) > compare) || (ABS(def[2]) > compare)) continue;
|
||||
|
||||
distance = normalize_v3(def);
|
||||
if (distance < compare ) {
|
||||
/* exclude body points attached with a spring */
|
||||
attached = 0;
|
||||
for (b=obp->nofsprings;b>0;b--) {
|
||||
bs = sb->bspring + obp->springs[b-1];
|
||||
if (( sb->totpoint-a == bs->v2) || ( sb->totpoint-a == bs->v1)) {
|
||||
attached=1;
|
||||
continue;}
|
||||
}
|
||||
if (!attached) {
|
||||
float f = tune / (distance) + tune / (compare * compare) * distance - 2.0f * tune/compare;
|
||||
|
||||
mid_v3_v3v3(velcenter, bp->vec, obp->vec);
|
||||
sub_v3_v3v3(dvel, velcenter, bp->vec);
|
||||
mul_v3_fl(dvel, _final_mass(ob, bp));
|
||||
|
||||
madd_v3_v3fl(bp->force, def, f * (1.0f - sb->balldamp));
|
||||
madd_v3_v3fl(bp->force, dvel, sb->balldamp);
|
||||
|
||||
/* exploit force(a, b) == -force(b, a) part2/2 */
|
||||
sub_v3_v3v3(dvel, velcenter, obp->vec);
|
||||
mul_v3_fl(dvel, (_final_mass(ob, bp)+_final_mass(ob, obp))/2.0f);
|
||||
|
||||
madd_v3_v3fl(obp->force, dvel, sb->balldamp);
|
||||
madd_v3_v3fl(obp->force, def, -f * (1.0f - sb->balldamp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* naive ball self collision done */
|
||||
|
||||
if (_final_goal(ob, bp) < SOFTGOALSNAP) { /* omit this bp when it snaps */
|
||||
float auxvect[3];
|
||||
float velgoal[3];
|
||||
|
||||
/* do goal stuff */
|
||||
if (ob->softflag & OB_SB_GOAL) {
|
||||
/* true elastic goal */
|
||||
sub_v3_v3v3(auxvect, bp->pos, bp->origT);
|
||||
ks = 1.0f / (1.0f- _final_goal(ob, bp) * sb->goalspring) - 1.0f;
|
||||
bp->force[0]+= -ks*(auxvect[0]);
|
||||
bp->force[1]+= -ks*(auxvect[1]);
|
||||
bp->force[2]+= -ks*(auxvect[2]);
|
||||
|
||||
/* calculate damping forces generated by goals*/
|
||||
sub_v3_v3v3(velgoal, bp->origS, bp->origE);
|
||||
kd = sb->goalfrict * sb_fric_force_scale(ob);
|
||||
add_v3_v3v3(auxvect, velgoal, bp->vec);
|
||||
|
||||
if (forcetime > 0.0f) { /* make sure friction does not become rocket motor on time reversal */
|
||||
bp->force[0]-= kd * (auxvect[0]);
|
||||
bp->force[1]-= kd * (auxvect[1]);
|
||||
bp->force[2]-= kd * (auxvect[2]);
|
||||
|
||||
}
|
||||
else {
|
||||
bp->force[0]-= kd * (velgoal[0] - bp->vec[0]);
|
||||
bp->force[1]-= kd * (velgoal[1] - bp->vec[1]);
|
||||
bp->force[2]-= kd * (velgoal[2] - bp->vec[2]);
|
||||
}
|
||||
}
|
||||
/* done goal stuff */
|
||||
|
||||
|
||||
/* gravitation */
|
||||
madd_v3_v3fl(bp->force, gravity, _final_mass(ob, bp)); /* individual mass of node here */
|
||||
|
||||
|
||||
/* particle field & vortex */
|
||||
if (effectors) {
|
||||
EffectedPoint epoint;
|
||||
float force[3] = {0.0f, 0.0f, 0.0f};
|
||||
float speed[3] = {0.0f, 0.0f, 0.0f};
|
||||
float eval_sb_fric_force_scale = sb_fric_force_scale(ob); /* just for calling function once */
|
||||
pd_point_from_soft(scene, bp->pos, bp->vec, sb->bpoint-bp, &epoint);
|
||||
BKE_effectors_apply(effectors, NULL, sb->effector_weights, &epoint, force, speed);
|
||||
|
||||
/* apply forcefield*/
|
||||
mul_v3_fl(force, fieldfactor* eval_sb_fric_force_scale);
|
||||
add_v3_v3(bp->force, force);
|
||||
|
||||
/* BP friction in moving media */
|
||||
kd= sb->mediafrict* eval_sb_fric_force_scale;
|
||||
bp->force[0] -= kd * (bp->vec[0] + windfactor*speed[0]/eval_sb_fric_force_scale);
|
||||
bp->force[1] -= kd * (bp->vec[1] + windfactor*speed[1]/eval_sb_fric_force_scale);
|
||||
bp->force[2] -= kd * (bp->vec[2] + windfactor*speed[2]/eval_sb_fric_force_scale);
|
||||
/* now we'll have nice centrifugal effect for vortex */
|
||||
|
||||
}
|
||||
else {
|
||||
/* BP friction in media (not) moving*/
|
||||
kd= sb->mediafrict* sb_fric_force_scale(ob);
|
||||
/* assume it to be proportional to actual velocity */
|
||||
bp->force[0]-= bp->vec[0]*kd;
|
||||
bp->force[1]-= bp->vec[1]*kd;
|
||||
bp->force[2]-= bp->vec[2]*kd;
|
||||
/* friction in media done */
|
||||
}
|
||||
/* +++cached collision targets */
|
||||
bp->choke = 0.0f;
|
||||
bp->choke2 = 0.0f;
|
||||
bp->loc_flag &= ~SBF_DOFUZZY;
|
||||
if (do_deflector) {
|
||||
float cfforce[3], defforce[3] ={0.0f, 0.0f, 0.0f}, vel[3] = {0.0f, 0.0f, 0.0f}, facenormal[3], cf = 1.0f, intrusion;
|
||||
kd = 1.0f;
|
||||
|
||||
if (sb_deflect_face(ob, bp->pos, facenormal, defforce, &cf, timenow, vel, &intrusion)) {
|
||||
if (intrusion < 0.0f) {
|
||||
if (G.debug_value & 0x01) { // 17 we did check for bit 0x10 before
|
||||
/* fixing bug [17428] this forces adaptive step size to tiny steps
|
||||
* in some situations .. keeping G.debug_value==17 option for old files 'needing' the bug
|
||||
*/
|
||||
/* bjornmose: uugh.. what an evil hack
|
||||
* violation of the 'don't touch bp->pos in here' rule
|
||||
* but works nice, like this-->
|
||||
* we predict the solution being out of the collider
|
||||
* in heun step No1 and leave the heun step No2 adapt to it
|
||||
* so we kind of introduced a implicit solver for this case
|
||||
*/
|
||||
madd_v3_v3fl(bp->pos, facenormal, -intrusion);
|
||||
}
|
||||
else {
|
||||
|
||||
sub_v3_v3v3(cfforce, bp->vec, vel);
|
||||
madd_v3_v3fl(bp->force, cfforce, -cf * 50.0f);
|
||||
}
|
||||
|
||||
|
||||
sb->scratch->flag |= SBF_DOFUZZY;
|
||||
bp->loc_flag |= SBF_DOFUZZY;
|
||||
bp->choke = sb->choke*0.01f;
|
||||
}
|
||||
else {
|
||||
sub_v3_v3v3(cfforce, bp->vec, vel);
|
||||
madd_v3_v3fl(bp->force, cfforce, -cf * 50.0f);
|
||||
}
|
||||
madd_v3_v3fl(bp->force, defforce, kd);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/* ---cached collision targets */
|
||||
|
||||
/* +++springs */
|
||||
if (ob->softflag & OB_SB_EDGES) {
|
||||
if (sb->bspring) { /* spring list exists at all ? */
|
||||
for (int b = bp->nofsprings; b > 0; b--) {
|
||||
bs = sb->bspring + bp->springs[b-1];
|
||||
if (do_springcollision || do_aero) {
|
||||
add_v3_v3(bp->force, bs->ext_force);
|
||||
if (bs->flag & BSF_INTERSECT)
|
||||
bp->choke = bs->cf;
|
||||
|
||||
}
|
||||
// sb_spring_force(Object *ob, int bpi, BodySpring *bs, float iks, float forcetime)
|
||||
// rather remove nl_falgs from code .. will make things a lot cleaner
|
||||
sb_spring_force(ob, sb->totpoint-a, bs, iks, forcetime);
|
||||
}/* loop springs */
|
||||
}/* existing spring list */
|
||||
}/*any edges*/
|
||||
/* ---springs */
|
||||
}/*omit on snap */
|
||||
}/*loop all bp's*/
|
||||
|
||||
|
||||
/* finally add forces caused by face collision */
|
||||
if (ob->softflag & OB_SB_FACECOLL) scan_for_ext_face_forces(ob, timenow);
|
||||
BKE_effectors_free(effectors);
|
||||
}
|
||||
}
|
||||
|
||||
static void softbody_apply_forces(Object *ob, float forcetime, int mode, float *err, int mid_flags)
|
||||
{
|
||||
/* time evolution */
|
||||
|
||||
Reference in New Issue
Block a user