[Bf-blender-cvs] [63aaa7c84a] cloth-improvements: Fix artifacts caused by double plastic computation whith collisions
Luca Rood
noreply at git.blender.org
Sat Jan 7 05:09:57 CET 2017
Commit: 63aaa7c84afed7822624b197f0a41f319a36cddb
Author: Luca Rood
Date: Fri Jan 6 18:00:23 2017 -0200
Branches: cloth-improvements
https://developer.blender.org/rB63aaa7c84afed7822624b197f0a41f319a36cddb
Fix artifacts caused by double plastic computation whith collisions
===================================================================
M source/blender/physics/intern/BPH_mass_spring.cpp
M source/blender/physics/intern/implicit.h
M source/blender/physics/intern/implicit_blender.c
===================================================================
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 830ade1c37..b2e0168257 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -333,7 +333,8 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo
return 1;
}
-BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, float time, float struct_plast, float bend_plast)
+BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, float time,
+ float struct_plast, float bend_plast, bool collision_pass)
{
Cloth *cloth = clmd->clothObject;
ClothSimSettings *parms = clmd->sim_parms;
@@ -355,7 +356,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
BPH_mass_spring_force_spring_angular(data, s->ij, s->kl, s->pa, s->pb, s->la, s->lb,
s->restang * (1.0f - parms->rest_planar_fact), &s->angoffset, k,
- parms->bending_damping, bend_plast, parms->bend_yield_fact * M_PI * 2);
+ parms->bending_damping, bend_plast, parms->bend_yield_fact * M_PI * 2, !collision_pass);
#endif
}
@@ -379,7 +380,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
// TODO: verify, half verified (couldn't see error)
// sewing springs usually have a large distance at first so clamp the force so we don't get tunnelling through colission objects
BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, &s->lenfact, k_tension, 0.0f,
- d_tension, 0.0f, no_compress, parms->max_sewing, 0.0f, 1.0f);
+ d_tension, 0.0f, no_compress, parms->max_sewing, 0.0f, 1.0f, !collision_pass);
}
else {
scaling_compression = parms->compression + s->lin_stiffness * fabsf(parms->max_compression - parms->compression);
@@ -399,7 +400,8 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
}
BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, &s->lenfact, k_tension, k_compression,
- d_tension, d_compression, no_compress, 0.0f, struct_plast, parms->struct_yield_fact);
+ d_tension, d_compression, no_compress, 0.0f,
+ struct_plast, parms->struct_yield_fact, !collision_pass);
}
#endif
}
@@ -421,7 +423,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
}
BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, &s->lenfact, k, 0.0f, d, 0.0f, true, 0.0f,
- struct_plast, parms->struct_yield_fact);
+ struct_plast, parms->struct_yield_fact, !collision_pass);
#endif
}
else if (s->type & CLOTH_SPRING_TYPE_GOAL) {
@@ -497,7 +499,7 @@ static void hair_get_boundbox(ClothModifierData *clmd, float gmin[3], float gmax
}
}
-static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListBase *effectors, float time)
+static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListBase *effectors, float time, bool collision_pass)
{
/* Collect forces and derivatives: F, dFdX, dFdV */
Cloth *cloth = clmd->clothObject;
@@ -619,7 +621,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
ClothSpring *spring = (ClothSpring *)link->link;
// only handle active springs
if (!(spring->flags & CLOTH_SPRING_FLAG_DEACTIVATE))
- cloth_calc_spring_force(clmd, spring, time, struct_plast, bend_plast);
+ cloth_calc_spring_force(clmd, spring, time, struct_plast, bend_plast, collision_pass);
}
}
@@ -996,7 +998,7 @@ static void cloth_collision_solve_extra(Object *ob, ClothModifierData *clmd, Lis
BPH_mass_spring_clear_forces(id);
// calculate forces
- cloth_calc_force(clmd, frame, effectors, step);
+ cloth_calc_force(clmd, frame, effectors, step, true);
// calculate new velocity and position
BPH_mass_spring_solve_velocities(id, dt, &result);
@@ -1124,7 +1126,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
}
// calculate forces
- cloth_calc_force(clmd, frame, effectors, step);
+ cloth_calc_force(clmd, frame, effectors, step, false);
// calculate new velocity and position
BPH_mass_spring_solve_velocities(id, dt, &result);
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 02d07c09e6..64df10aee1 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -116,11 +116,11 @@ void BPH_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float
/* Linear spring force between two points */
bool BPH_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int j, float restlen, float *lenfact,
float tension, float compression, float damp_tension, float damp_compression,
- bool no_compress, float clamp_force, float plasticity, float yield_fact);
+ bool no_compress, float clamp_force, float plasticity, float yield_fact, bool do_plast);
/* Angular spring force between two polygons */
bool BPH_mass_spring_force_spring_angular(struct Implicit_Data *data, int i, int j, int *i_a, int *i_b, int len_a, int len_b,
float restangorig, float *angoffset, float stiffness, float damping,
- float plasticity, float yield_ang);
+ float plasticity, float yield_ang, bool do_plast);
/* Bending force, forming a triangle at the base of two structural springs */
bool BPH_mass_spring_force_spring_bending(struct Implicit_Data *data, int i, int j, float restlen,
float kb, float cb);
diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c
index 42958790e9..4bfe82d7a4 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1581,7 +1581,7 @@ BLI_INLINE void apply_spring(Implicit_Data *data, int i, int j, const float f[3]
bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, float restlenorig, float *lenfact,
float tension, float compression, float damp_tension, float damp_compression,
- bool no_compress, float clamp_force, float plasticity, float yield_fact)
+ bool no_compress, float clamp_force, float plasticity, float yield_fact, bool do_plast)
{
float extent[3], length, dir[3], vel[3];
float f[3], dfdx[3][3], dfdv[3][3];
@@ -1608,7 +1608,7 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, floa
dfdx_spring(dfdx, dir, length, restlen, tension);
/* compute plasticity offset factor */
- if (length > restlen * yield_fact) {
+ if (do_plast && length > restlen * yield_fact) {
restlen += ((length / yield_fact) - restlen) * plasticity;
*lenfact = restlen / restlenorig;
}
@@ -1627,7 +1627,7 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, floa
mul_m3_fl(dfdx, fbstar_jacobi(length, restlen, kb, cb));
/* compute plasticity offset factor */
- if (length < restlen / yield_fact) {
+ if (do_plast && length < restlen / yield_fact) {
restlen -= (restlen - (length * yield_fact)) * plasticity;
*lenfact = restlen / restlenorig;
}
@@ -1639,7 +1639,7 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data, int i, int j, floa
/* compute plasticity offset factor */
/* plasticity has to be computed even for non-compressive springs in a compression condition,
* otherwise issues occur where shearing gets unconstrained when cloth undergoes compression */
- if (length < restlen / yield_fact) {
+ if (do_plast && length < restlen / yield_fact) {
restlen -= (restlen - (length * yield_fact)) * plasticity;
*lenfact = restlen / restlenorig;
}
@@ -1761,7 +1761,7 @@ BLI_INLINE bool spring_angle(Implicit_Data *data, int i, int j, int *i_a, int *i
/* Angular springs roughly based on the bending model proposed by Baraff and Witkin in "Large Steps in Cloth Simulation" */
bool BPH_mass_spring_force_spring_angular(Implicit_Data *data, int i, int j, int *i_a, int *i_b, int len_a, int len_b,
float restangorig, float *angoffset, float stiffness, float damping,
- float plasticity, float yield_ang)
+ float plasticity, float yield_ang, bool do_plast)
{
float angle, dir_a[3], dir_b[3], vel_a[3], vel_b[3];
float f_a[3], f_b[3], f_e[3];
@@ -1778,16 +1778,18 @@ bool BPH_mass_spring_force_spring_angular(Implicit_Data *data, int i, int j, int
force = stiffness * (angle - restang);
/* compute plasticity offset */
- if (angle > restang) {
- if (angle - restang > yield_ang) {
- restang += (angle - restang - yield_ang) * plasticity;
- *angoffset = restang - restangorig;
+ if (do_plast) {
+ if (angle > restang) {
+ if (angle - restang > yield_ang) {
+ restang += (angle - restang - yield_ang) * plasticity;
+ *angoffset = restang - restangorig;
+ }
}
- }
- else if (angle < restang) {
- if (restang - angle > yield_ang) {
- restang -= (restang - angle - yield_ang) * plasticity;
- *angoffset = restang - restangorig;
+ else if (angle < restang) {
+ if (restang - angle > yield_ang) {
+ restang -= (restang - angle - yield_ang) * plasticity;
+ *angoffset = restang - restangorig;
+ }
}
}
More information about the Bf-blender-cvs
mailing list