From 6394189e68ac7d3022044e851c9670b10e023cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Wed, 24 Sep 2014 08:55:29 +0200 Subject: [PATCH] Clear forces and constraints together at the start of the time step, easier to verify. --- source/blender/physics/intern/BPH_mass_spring.cpp | 9 ++++----- source/blender/physics/intern/implicit.h | 2 +- source/blender/physics/intern/implicit_blender.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index fc7d5ef039b..56923b6603a 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -222,8 +222,6 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c const float ZERO[3] = {0.0f, 0.0f, 0.0f}; - BPH_mass_spring_clear_constraints(data); - for (v = 0; v < numverts; v++) { if (verts[v].flags & CLOTH_VERT_FLAG_PINNED) { /* pinned vertex constraints */ @@ -506,9 +504,6 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB MFace *mfaces = cloth->mfaces; unsigned int numverts = cloth->numverts; - /* initialize forces to zero */ - BPH_mass_spring_force_clear(data); - #ifdef CLOTH_FORCE_GRAVITY /* global acceleration (gravitation) */ if (clmd->scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) { @@ -644,6 +639,10 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * while (step < tf) { ImplicitSolverResult result; + /* initialize forces to zero */ + BPH_mass_spring_clear_forces(id); + BPH_mass_spring_clear_constraints(id); + /* copy velocities for collision */ for (i = 0; i < numverts; i++) { BPH_mass_spring_get_motion_state(id, i, NULL, verts[i].tv); diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h index 8c860d69a24..b915b07b315 100644 --- a/source/blender/physics/intern/implicit.h +++ b/source/blender/physics/intern/implicit.h @@ -129,7 +129,7 @@ bool BPH_mass_spring_solve(struct Implicit_Data *data, float dt, struct Implicit void BPH_mass_spring_apply_result(struct Implicit_Data *data); /* Clear the force vector at the beginning of the time step */ -void BPH_mass_spring_force_clear(struct Implicit_Data *data); +void BPH_mass_spring_clear_forces(struct Implicit_Data *data); /* Fictitious forces introduced by moving coordinate systems */ void BPH_mass_spring_force_reference_frame(struct Implicit_Data *data, int index, const float acceleration[3], const float omega[3], const float domega_dt[3]); /* Simple uniform gravity force */ diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c index 7a64df457c7..0fd46b79aa0 100644 --- a/source/blender/physics/intern/implicit_blender.c +++ b/source/blender/physics/intern/implicit_blender.c @@ -1281,7 +1281,7 @@ void BPH_mass_spring_add_constraint_ndof2(Implicit_Data *data, int index, const add_v3_v3(data->z[index], u); } -void BPH_mass_spring_force_clear(Implicit_Data *data) +void BPH_mass_spring_clear_forces(Implicit_Data *data) { int numverts = data->M[0].vcount; zero_lfvector(data->F, numverts);