diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2019-12-09 21:10:55 +0300 |
---|---|---|
committer | Sebastian Parborg <darkdefende@gmail.com> | 2019-12-09 21:18:10 +0300 |
commit | 62ef59aa0cca736b09192b67cc924180d9c2f9f9 (patch) | |
tree | f0f76383b9536a5186abe0072b1a535e587cef22 /source/blender/physics/intern | |
parent | e77fdc62b75a3b96e4c3ca5c2fc4025d8091ff99 (diff) |
Add the ability to create internal springs to the cloth sim
This can be used to make closed surfaces behave more like a soft body.
Reviewed By: Jacques Lucke
Differential Revision: http://developer.blender.org/D5788
Diffstat (limited to 'source/blender/physics/intern')
-rw-r--r-- | source/blender/physics/intern/BPH_mass_spring.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index 7521efa5cbd..999cefde104 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -427,7 +427,8 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) } /* Calculate force of structural + shear springs. */ - if (s->type & (CLOTH_SPRING_TYPE_STRUCTURAL | CLOTH_SPRING_TYPE_SEWING)) { + if (s->type & + (CLOTH_SPRING_TYPE_STRUCTURAL | CLOTH_SPRING_TYPE_SEWING | CLOTH_SPRING_TYPE_INTERNAL)) { #ifdef CLOTH_FORCE_SPRING_STRUCTURAL float k_tension, scaling_tension; @@ -453,7 +454,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) false, parms->max_sewing); } - else { + else if (s->type & CLOTH_SPRING_TYPE_STRUCTURAL) { float k_compression, scaling_compression; scaling_compression = parms->compression + s->lin_stiffness * fabsf(parms->max_compression - parms->compression); @@ -471,6 +472,44 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) using_angular, 0.0f); } + else { + /* CLOTH_SPRING_TYPE_INTERNAL */ + BLI_assert(s->type & CLOTH_SPRING_TYPE_INTERNAL); + + scaling_tension = parms->internal_tension + + s->lin_stiffness * + fabsf(parms->max_internal_tension - parms->internal_tension); + k_tension = scaling_tension / (parms->avg_spring_len + FLT_EPSILON); + float scaling_compression = parms->internal_compression + + s->lin_stiffness * fabsf(parms->max_internal_compression - + parms->internal_compression); + float k_compression = scaling_compression / (parms->avg_spring_len + FLT_EPSILON); + + float k_tension_damp = parms->tension_damp; + float k_compression_damp = parms->compression_damp; + + if (k_tension == 0.0f) { + /* No damping so it behaves as if no tension spring was there at all. */ + k_tension_damp = 0.0f; + } + + if (k_compression == 0.0f) { + /* No damping so it behaves as if no compression spring was there at all. */ + k_compression_damp = 0.0f; + } + + BPH_mass_spring_force_spring_linear(data, + s->ij, + s->kl, + s->restlen, + k_tension, + k_tension_damp, + k_compression, + k_compression_damp, + resist_compress, + using_angular, + 0.0f); + } #endif } else if (s->type & CLOTH_SPRING_TYPE_SHEAR) { |