diff options
Diffstat (limited to 'source/blender/blenkernel/intern/softbody.c')
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 03cf33083da..c3527af90ca 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -676,11 +676,13 @@ static void add_2nd_order_roller(Object *ob, float UNUSED(stiffness), int *count notthis = bs->v2; } else { - if (v0 == bs->v2) { - bpo = sb->bpoint+bs->v1; - notthis = bs->v1; - } - else {printf("oops we should not get here - add_2nd_order_springs");} + if (v0 == bs->v2) { + bpo = sb->bpoint+bs->v1; + notthis = bs->v1; + } + else { + printf("oops we should not get here - add_2nd_order_springs"); + } } if (bpo) {/* so now we have a 2nd order humpdidump */ for (c=bpo->nofsprings;c>0;c--) { @@ -1602,12 +1604,12 @@ static void sb_sfesf_threads_run(Scene *scene, struct Object *ob, float timenow, sb_threads[i].tot= totthread; } if (totthread > 1) { - BLI_init_threads(&threads, exec_scan_for_ext_spring_forces, totthread); + BLI_threadpool_init(&threads, exec_scan_for_ext_spring_forces, totthread); for (i=0; i<totthread; i++) - BLI_insert_thread(&threads, &sb_threads[i]); + BLI_threadpool_insert(&threads, &sb_threads[i]); - BLI_end_threads(&threads); + BLI_threadpool_end(&threads); } else exec_scan_for_ext_spring_forces(&sb_threads[0]); @@ -1856,19 +1858,21 @@ static void dfdx_spring(int ia, int ic, int op, float dir[3], float L, float len float m, delta_ij; int i, j; if (L < len) { - for (i=0;i<3;i++) + for (i=0;i<3;i++) { for (j=0;j<3;j++) { delta_ij = (i==j ? (1.0f): (0.0f)); m=factor*(dir[i]*dir[j] + (1-L/len)*(delta_ij - dir[i]*dir[j])); EIG_linear_solver_matrix_add(ia+i, op+ic+j, m); } + } } else { - for (i=0;i<3;i++) + for (i=0;i<3;i++) { for (j=0;j<3;j++) { m=factor*dir[i]*dir[j]; EIG_linear_solver_matrix_add(ia+i, op+ic+j, m); } + } } } @@ -1975,12 +1979,12 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo /* intitialize */ if (sb) { - /* check conditions for various options */ - /* +++ could be done on object level to squeeze out the last bits of it */ - 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)); - /* --- could be done on object level to squeeze out the last bits of it */ + /* check conditions for various options */ + /* +++ could be done on object level to squeeze out the last bits of it */ + 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)); + /* --- could be done on object level to squeeze out the last bits of it */ } else { printf("Error expected a SB here\n"); @@ -2011,7 +2015,8 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo float compare; float bstune = sb->ballstiff; - for (c=sb->totpoint, obp= sb->bpoint; c>=ifirst+bb; c--, obp++) { + /* running in a slice we must not assume anything done with obp neither alter the data of obp */ + for (c=sb->totpoint, obp= sb->bpoint; c>0; c--, obp++) { compare = (obp->colball + bp->colball); sub_v3_v3v3(def, bp->pos, obp->pos); /* rather check the AABBoxes before ever calulating the real distance */ @@ -2036,13 +2041,6 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo 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)); - - madd_v3_v3fl(obp->force, dvel, sb->balldamp); - madd_v3_v3fl(obp->force, def, -f * (1.0f - sb->balldamp)); } } } @@ -2218,12 +2216,12 @@ static void sb_cf_threads_run(Scene *scene, Object *ob, float forcetime, float t if (totthread > 1) { - BLI_init_threads(&threads, exec_softbody_calc_forces, totthread); + BLI_threadpool_init(&threads, exec_softbody_calc_forces, totthread); for (i=0; i<totthread; i++) - BLI_insert_thread(&threads, &sb_threads[i]); + BLI_threadpool_insert(&threads, &sb_threads[i]); - BLI_end_threads(&threads); + BLI_threadpool_end(&threads); } else exec_softbody_calc_forces(&sb_threads[0]); @@ -2233,9 +2231,9 @@ static void sb_cf_threads_run(Scene *scene, Object *ob, float forcetime, float t static void softbody_calc_forcesEx(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) - */ + /* 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 *bproot;*/ /* UNUSED */ ListBase *do_effector = NULL; @@ -2781,7 +2779,7 @@ static void apply_spring_memory(Object *ob) l = len_v3v3(bp1->pos, bp2->pos); r = bs->len/l; if (( r > 1.05f) || (r < 0.95f)) { - bs->len = ((100.0f - b) * bs->len + b*l)/100.0f; + bs->len = ((100.0f - b) * bs->len + b*l)/100.0f; } } } @@ -2829,10 +2827,10 @@ static void springs_from_mesh(Object *ob) sb= ob->soft; if (me && sb) { - /* using bp->origS as a container for spring calcualtions here - * will be overwritten sbObjectStep() to receive - * actual modifier stack positions - */ + /* using bp->origS as a container for spring calcualtions here + * will be overwritten sbObjectStep() to receive + * actual modifier stack positions + */ if (me->totvert) { bp= ob->soft->bpoint; for (a=0; a<me->totvert; a++, bp++) { @@ -3410,7 +3408,7 @@ static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCo * lloc, lrot, lscale are allowed to be NULL, just in case you don't need it. * should be pretty useful for pythoneers :) * not! velocity .. 2nd order stuff - * vcloud_estimate_transform see + * vcloud_estimate_transform_v3 see */ void SB_estimate_transform(Object *ob, float lloc[3], float lrot[3][3], float lscale[3][3]) @@ -3434,7 +3432,7 @@ void SB_estimate_transform(Object *ob, float lloc[3], float lrot[3][3], float ls copy_v3_v3(opos[a], bp->pos); } - vcloud_estimate_transform(sb->totpoint, opos, NULL, rpos, NULL, com, rcom, lrot, lscale); + vcloud_estimate_transform_v3(sb->totpoint, opos, NULL, rpos, NULL, com, rcom, lrot, lscale); //sub_v3_v3(com, rcom); if (lloc) copy_v3_v3(lloc, com); copy_v3_v3(sb->lcom, com); @@ -3495,16 +3493,16 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int SB_estimate_transform(ob, NULL, NULL, NULL); } 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; + 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; } } @@ -3724,7 +3722,8 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, can_simulate); if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED || - (!can_simulate && cache_result == PTCACHE_READ_OLD)) { + (!can_simulate && cache_result == PTCACHE_READ_OLD)) + { softbody_to_object(ob, vertexCos, numVerts, sb->local); BKE_ptcache_validate(cache, framenr); |