[Bf-blender-cvs] [73fd331] cloth-improvements: Fix previous error with spring length scaling
Luca Rood
noreply at git.blender.org
Mon Dec 5 18:51:13 CET 2016
Commit: 73fd331025107824de3bad1d5134554c78d99928
Author: Luca Rood
Date: Mon Dec 5 12:43:19 2016 -0200
Branches: cloth-improvements
https://developer.blender.org/rB73fd331025107824de3bad1d5134554c78d99928
Fix previous error with spring length scaling
Zero-length springs weren't being scaled properly, leading to phantom
forces that introduced rigid-body motion into the simulation.
===================================================================
M source/blender/physics/intern/BPH_mass_spring.cpp
===================================================================
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index f0b0ade..9de1c95 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -348,27 +348,37 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
if ((s->type & CLOTH_SPRING_TYPE_STRUCTURAL) || (s->type & CLOTH_SPRING_TYPE_SEWING) ) {
#ifdef CLOTH_FORCE_SPRING_STRUCTURAL
float k_tension, k_compression, scaling_tension, scaling_compression;
-
+
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
-
+
// TODO: Scaling should be relative to half the area of the adjacent faces instead of length (except for sewing)
// Note that this scaling is only valid when coupled with proper mass distribution
scaling_tension = parms->tension + s->stiffness * fabsf(parms->max_tension - parms->tension);
- scaling_compression = parms->compression + s->stiffness * fabsf(parms->max_compression - parms->compression); // TODO: Unnecessary for sewing
- k_tension = scaling_tension / (s->restlen + FLT_EPSILON);
- k_compression = scaling_compression / (s->restlen + FLT_EPSILON);
-
+
if (s->type & CLOTH_SPRING_TYPE_SEWING) {
+ // Multiply by some arbitrary large value, just so zero-length (sewing) springs have enough force.
+ k_tension = scaling_tension * 10000;
+
// 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, k_tension, k_compression,
- parms->tension_damp, parms->compression_damp,
- no_compress, parms->max_sewing);
+ BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k_tension, 0,
+ parms->tension_damp, 0, no_compress, parms->max_sewing);
}
else {
+ scaling_compression = parms->compression + s->stiffness * fabsf(parms->max_compression - parms->compression);
+
+ if (s->restlen > ALMOST_ZERO) {
+ k_tension = scaling_tension / s->restlen;
+ k_compression = scaling_compression / s->restlen;
+ }
+ else {
+ // Multiply by some arbitrary large value, just so zero-length springs have enough force.
+ k_tension = scaling_tension * 10000;
+ k_compression = 0; // No compression for zero-length springs
+ }
+
BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k_tension, k_compression,
- parms->tension_damp, parms->compression_damp,
- no_compress, 0.0f);
+ parms->tension_damp, parms->compression_damp, no_compress, 0.0f);
}
#endif
}
@@ -379,7 +389,11 @@ 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);
- k = scaling / (s->restlen + FLT_EPSILON);
+
+ if (s->restlen > ALMOST_ZERO)
+ k = scaling / s->restlen;
+ else
+ k = scaling * 10000;
BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k, 0.0f, parms->shear_damp, 0.0f, no_compress, 0.0f);
#endif
More information about the Bf-blender-cvs
mailing list