diff options
author | Luca Rood <dev@lucarood.com> | 2016-12-06 02:39:29 +0300 |
---|---|---|
committer | Luca Rood <dev@lucarood.com> | 2018-08-31 17:39:43 +0300 |
commit | b6f0f8a5b5a4871603755d4413e47f054ecd5b68 (patch) | |
tree | 50b10fa4e995a133c2ad42e31f8d6acb205ed552 /source/blender/physics/intern/BPH_mass_spring.cpp | |
parent | e3d31b8dfbdc3f4412e12fa1594927098ed0654d (diff) |
Cloth: Implement angular bending springs
This implements angular bending springs for cloth simulation. This also
adds shearing springs for n-gons.
This angular spring implementation does not include Jacobian matrices,
as the springs can exist between polygons of different vertex counts,
rendering their relationships asymmetrical, and thus impossible to solve
with the current implementation. This means that the bending component
is solved explicitly. However, this is usually not a big problem, as
bending springs contribute less to instability than structural springs.
The the old linear bending model can still be used, and is the default for
existing files, to keep compatibility. However, the new angular bending
model is the default for any new simulation.
This commit makes small breaking changes, in that shearing springs are
now created on n-gons (also in linear bending mode), while n-gons were
previously ignored.
Reviewed By: brecht
Differential Revision: http://developer.blender.org/D3662
Diffstat (limited to 'source/blender/physics/intern/BPH_mass_spring.cpp')
-rw-r--r-- | source/blender/physics/intern/BPH_mass_spring.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index 668e40e71cc..6ea2eeca6f8 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -67,7 +67,7 @@ static int cloth_count_nondiag_blocks(Cloth *cloth) for (link = cloth->springs; link; link = link->next) { ClothSpring *spring = (ClothSpring *)link->link; switch (spring->type) { - case CLOTH_SPRING_TYPE_BENDING_ANG: + case CLOTH_SPRING_TYPE_BENDING_HAIR: /* angular bending combines 3 vertices */ nondiag += 3; break; @@ -346,14 +346,29 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) s->flags &= ~CLOTH_SPRING_FLAG_NEEDED; - // calculate force of structural + shear springs - if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SEWING)) { + /* Calculate force of bending springs. */ + if (s->type & CLOTH_SPRING_TYPE_BENDING) { +#ifdef CLOTH_FORCE_SPRING_BEND + float k, scaling; + + s->flags |= CLOTH_SPRING_FLAG_NEEDED; + + scaling = parms->bending + s->ang_stiffness * fabsf(parms->max_bend - parms->bending); + k = scaling * s->restlen * 0.1f; /* Multiplying by 0.1, just to scale the forces to more reasonable values. */ + + BPH_mass_spring_force_spring_angular(data, s->ij, s->kl, s->pa, s->pb, s->la, s->lb, + s->restang, k, parms->bending_damping); +#endif + } + + /* Calculate force of structural + shear springs. */ + if (s->type & (CLOTH_SPRING_TYPE_STRUCTURAL | CLOTH_SPRING_TYPE_SEWING)) { #ifdef CLOTH_FORCE_SPRING_STRUCTURAL float k_tension, scaling_tension; s->flags |= CLOTH_SPRING_FLAG_NEEDED; - scaling_tension = parms->tension + s->stiffness * fabsf(parms->max_tension - parms->tension); + scaling_tension = parms->tension + s->lin_stiffness * fabsf(parms->max_tension - parms->tension); k_tension = scaling_tension / (parms->avg_spring_len + FLT_EPSILON); if (s->type & CLOTH_SPRING_TYPE_SEWING) { @@ -365,7 +380,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) } else { float k_compression, scaling_compression; - scaling_compression = parms->compression + s->stiffness * fabsf(parms->max_compression - parms->compression); + scaling_compression = parms->compression + s->lin_stiffness * fabsf(parms->max_compression - parms->compression); k_compression = scaling_compression / (parms->avg_spring_len + FLT_EPSILON); BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, @@ -381,7 +396,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) s->flags |= CLOTH_SPRING_FLAG_NEEDED; - scaling = parms->shear + s->stiffness * fabsf(parms->max_shear - parms->shear); + scaling = parms->shear + s->lin_stiffness * fabsf(parms->max_shear - parms->shear); k = scaling / (parms->avg_spring_len + FLT_EPSILON); BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k, parms->shear_damp, @@ -394,7 +409,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) s->flags |= CLOTH_SPRING_FLAG_NEEDED; - scaling = parms->bending + s->stiffness * fabsf(parms->max_bend - parms->bending); + scaling = parms->bending + s->lin_stiffness * fabsf(parms->max_bend - parms->bending); kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); // Fix for [#45084] for cloth stiffness must have cb proportional to kb @@ -403,7 +418,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) BPH_mass_spring_force_spring_bending(data, s->ij, s->kl, s->restlen, kb, cb); #endif } - else if (s->type & CLOTH_SPRING_TYPE_BENDING_ANG) { + else if (s->type & CLOTH_SPRING_TYPE_BENDING_HAIR) { #ifdef CLOTH_FORCE_SPRING_BEND float kb, cb, scaling; @@ -413,14 +428,14 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) * this is crap, but needed due to cloth/hair mixing ... * max_bend factor is not even used for hair, so ... */ - scaling = s->stiffness * parms->bending; + scaling = s->lin_stiffness * parms->bending; kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON)); // Fix for [#45084] for cloth stiffness must have cb proportional to kb cb = kb * parms->bending_damping; /* XXX assuming same restlen for ij and jk segments here, this can be done correctly for hair later */ - BPH_mass_spring_force_spring_bending_angular(data, s->ij, s->kl, s->mn, s->target, kb, cb); + BPH_mass_spring_force_spring_bending_hair(data, s->ij, s->kl, s->mn, s->target, kb, cb); #if 0 { |