[Bf-blender-cvs] [06090d7a31] cloth-improvements: Implement usage of dt property (preparation for adaptive time steps)
Luca Rood
noreply at git.blender.org
Wed Feb 1 07:11:54 CET 2017
Commit: 06090d7a31501b9bb0f58f8ab68ad28aa37940e5
Author: Luca Rood
Date: Tue Jan 31 17:32:18 2017 -0200
Branches: cloth-improvements
https://developer.blender.org/rB06090d7a31501b9bb0f58f8ab68ad28aa37940e5
Implement usage of dt property (preparation for adaptive time steps)
===================================================================
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/collision.c
M source/blender/physics/intern/BPH_mass_spring.cpp
===================================================================
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index b98700f7ea..8611e5b98f 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -287,6 +287,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
BKE_cloth_solver_set_positions(clmd);
clmd->clothObject->last_frame= MINFRAME-1;
+ clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame;
}
return 1;
@@ -374,9 +375,6 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
cache->last_exact= 0;
cache->flag &= ~PTCACHE_REDO_NEEDED;
}
-
- // unused in the moment, calculated separately in implicit.c
- clmd->sim_parms->dt = clmd->sim_parms->timescale / clmd->sim_parms->stepsPerFrame;
/* simulation is only active during a specific period */
if (framenr < startframe) {
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index a41b176598..0e0bd6a3a3 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -457,7 +457,7 @@ static int cloth_collision_response_static (ClothModifierData *clmd, CollisionMo
float magtangent = 0, repulse = 0, d = 0;
double impulse = 0.0;
float vrel_t_pre[3];
- float temp[3], spf;
+ float temp[3], time_multiplier;
/* calculate tangential velocity */
copy_v3_v3 ( temp, collider_norm );
@@ -529,7 +529,7 @@ static int cloth_collision_response_static (ClothModifierData *clmd, CollisionMo
* v += impulse; x_new = x + v;
* We don't use dt!!
* DG TODO: Fix usage of dt here! */
- spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale;
+ time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
if (backside) {
d = clmd->coll_parms->epsilon*8.0f/9.0f + epsilon2*8.0f/9.0f;
@@ -538,8 +538,8 @@ static int cloth_collision_response_static (ClothModifierData *clmd, CollisionMo
d = clmd->coll_parms->epsilon*8.0f/9.0f + epsilon2*8.0f/9.0f - collpair->distance;
}
- if ( ( magrelVel < 0.1f*d*spf ) && ( d > ALMOST_ZERO ) ) {
- repulse = MIN2 ( d*1.0f/spf, 0.1f*d*spf - magrelVel );
+ if ( ( magrelVel < 0.1f*d*time_multiplier ) && ( d > ALMOST_ZERO ) ) {
+ repulse = MIN2 ( d*1.0f/time_multiplier, 0.1f*d*time_multiplier - magrelVel );
/* stay on the safe side and clamp repulse */
if ( impulse > ALMOST_ZERO )
@@ -564,7 +564,7 @@ static int cloth_collision_response_static (ClothModifierData *clmd, CollisionMo
* DG: this formula ineeds to be changed for this code since we apply impulses/repulses like this:
* v += impulse; x_new = x + v;
* We don't use dt!! */
- float spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale;
+ float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
float d;
if (backside) {
@@ -576,7 +576,7 @@ static int cloth_collision_response_static (ClothModifierData *clmd, CollisionMo
if ( d > ALMOST_ZERO) {
/* stay on the safe side and clamp repulse */
- float repulse = d*1.0f/spf;
+ float repulse = d*1.0f/time_multiplier;
/*float impulse = repulse / ( 3.0f * ( 1.0f + w1*w1 + w2*w2 + w3*w3 )); original 2.0 / 0.25 */
@@ -676,7 +676,7 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, CollPair
float magtangent = 0, repulse = 0, d = 0;
double impulse = 0.0;
float vrel_t_pre[3];
- float temp[3], spf;
+ float temp[3], time_multiplier;
/* calculate tangential velocity */
copy_v3_v3 ( temp, collpair->normal );
@@ -724,12 +724,12 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, CollPair
* v += impulse; x_new = x + v;
* We don't use dt!!
* DG TODO: Fix usage of dt here! */
- spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale;
+ time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
d = clmd->coll_parms->selfepsilon * 8.0f / 9.0f * 2.0f - collpair->distance;
- if ( ( magrelVel < 0.1f*d*spf ) && ( d > ALMOST_ZERO ) ) {
- repulse = MIN2 ( d*1.0f/spf, 0.1f*d*spf - magrelVel );
+ if ( ( magrelVel < 0.1f*d*time_multiplier ) && ( d > ALMOST_ZERO ) ) {
+ repulse = MIN2 ( d*1.0f/time_multiplier, 0.1f*d*time_multiplier - magrelVel );
if ( impulse > ALMOST_ZERO )
repulse = min_ff( repulse, 5.0*impulse );
@@ -753,14 +753,14 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, CollPair
* DG: this formula ineeds to be changed for this code since we apply impulses/repulses like this:
* v += impulse; x_new = x + v;
* We don't use dt!! */
- float spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale;
+ float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
float d;
d = clmd->coll_parms->selfepsilon * 8.0f / 9.0f * 2.0f - (float)collpair->distance;
if ( d > ALMOST_ZERO) {
/* stay on the safe side and clamp repulse */
- float repulse = d*1.0f/spf;
+ float repulse = d*1.0f/time_multiplier;
/*float impulse = repulse / ( 3.0f * ( 1.0f + w1*w1 + w2*w2 + w3*w3 )); original 2.0 / 0.25 */
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 1c5dbbe426..53ca40158e 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -607,13 +607,13 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
struct_plast = clmd->sim_parms->struct_plasticity;
if (!(struct_plast < FLT_EPSILON || 1.0f - struct_plast < FLT_EPSILON)) {
- struct_plast = 1.0f - powf(1.0f - struct_plast, 1.0f / clmd->sim_parms->stepsPerFrame);
+ struct_plast = 1.0f - powf(1.0f - struct_plast, clmd->sim_parms->dt);
}
bend_plast = clmd->sim_parms->bend_plasticity;
if (!(bend_plast < FLT_EPSILON || 1.0f - bend_plast < FLT_EPSILON)) {
- bend_plast = 1.0f - powf(1.0f - bend_plast, 1.0f / clmd->sim_parms->stepsPerFrame);
+ bend_plast = 1.0f - powf(1.0f - bend_plast, clmd->sim_parms->dt);
}
// calculate spring forces
@@ -933,7 +933,7 @@ static void cloth_solve_collisions(Object *ob, ClothModifierData *clmd, float st
Implicit_Data *id = cloth->implicit;
ClothVertex *verts = cloth->verts;
int mvert_num = cloth->mvert_num;
- const float spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale;
+ const float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
int i;
if (!(clmd->coll_parms->flags & (CLOTH_COLLSETTINGS_FLAG_ENABLED | CLOTH_COLLSETTINGS_FLAG_SELF)))
@@ -951,7 +951,6 @@ static void cloth_solve_collisions(Object *ob, ClothModifierData *clmd, float st
BPH_mass_spring_get_new_position(id, i, verts[i].tx);
sub_v3_v3v3(verts[i].tv, verts[i].tx, verts[i].txold);
- copy_v3_v3(verts[i].v, verts[i].tv);
zero_v3(verts[i].dcvel);
}
@@ -969,7 +968,7 @@ static void cloth_solve_collisions(Object *ob, ClothModifierData *clmd, float st
/* Update velocity, based on old velocity, only applying delta caused by collision responce */
BPH_mass_spring_get_velocity(id, i, verts[i].tv);
- madd_v3_v3fl(verts[i].tv, verts[i].dcvel, spf);
+ madd_v3_v3fl(verts[i].tv, verts[i].dcvel, time_multiplier);
BPH_mass_spring_set_velocity(id, i, verts[i].tv);
}
}
@@ -985,7 +984,7 @@ static void cloth_clear_result(ClothModifierData *clmd)
sres->avg_iterations = 0.0f;
}
-static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *result, int steps)
+static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *result, float dt)
{
ClothSolverResult *sres = clmd->solver_result;
@@ -994,22 +993,22 @@ static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *r
if (result->status == BPH_SOLVER_SUCCESS) {
sres->min_error = min_ff(sres->min_error, result->error);
sres->max_error = max_ff(sres->max_error, result->error);
- sres->avg_error += result->error / (float)steps;
+ sres->avg_error += result->error * dt;
}
sres->min_iterations = min_ii(sres->min_iterations, result->iterations);
sres->max_iterations = max_ii(sres->max_iterations, result->iterations);
- sres->avg_iterations += (float)result->iterations / (float)steps;
+ sres->avg_iterations += (float)result->iterations * dt;
}
else {
/* error only makes sense for successful iterations */
if (result->status == BPH_SOLVER_SUCCESS) {
sres->min_error = sres->max_error = result->error;
- sres->avg_error += result->error / (float)steps;
+ sres->avg_error += result->error * dt;
}
sres->min_iterations = sres->max_iterations = result->iterations;
- sres->avg_iterations += (float)result->iterations / (float)steps;
+ sres->avg_iterations += (float)result->iterations * dt;
}
sres->status |= result->status;
@@ -1028,7 +1027,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
Cloth *cloth = clmd->clothObject;
ClothVertex *verts = cloth->verts/*, *cv*/;
unsigned int mvert_num = cloth->mvert_num;
- float dt = clmd->sim_parms->timescale / clmd->sim_parms->stepsPerFrame;
+ float dt = clmd->sim_parms->dt * clmd->sim_parms->timescale;
Implicit_Data *id = cloth->implicit;
ColliderContacts *contacts = NULL;
int totcolliders = 0;
@@ -1052,17 +1051,10 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
}
}
}
-
+
while (step < tf) {
ImplicitSolverResult result;
- /* copy velocities for collision */
- for (i = 0; i < mvert_num; i++) {
- BPH_mass_spring_get_motion_state(id, i, NULL, verts[i].tv);
- copy_v3_v3(verts[i].v, verts[i].tv);
-
- }
-
if (is_hair) {
/* determine contact points */
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
@@ -1101,7 +1093,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
// calculate new velocity and position
BPH_mass_spring_solve_velocities(id, dt, &result);
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list