Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2016-04-18 18:47:16 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2016-05-06 11:40:19 +0300
commitb481e886e5ad4c4ab6f1118f80933a4bf558c61e (patch)
tree19d4da80773b614126e540240cb75dbd590f0560 /source/blender/blenkernel/intern/cloth.c
parent8d22a8afa0386866258cbbb1cd5d80539da245e3 (diff)
Cloth: Use Geometrical Mean for averaging cloth shrink factor.
This comes out of considering a one-dimensional transition in weight on a rectangular cloth grid. At the transition face loop, one side of each rectangular face would be scaled by k1, and the opposite one by k2, thus turning the rectangle into a trapezoid. Averaging would be used to choose the scale factor for the remaining two sides. If Geometrical Mean, i.e. sqrt(k1*k2) is used, it so happens that the diagonals of the trapezoid also end up scaled by sqrt(k1*k2) compared to the original rectangle. This means that the same scale factor is correct for both structural and shear springs, which is not the case with simple average.
Diffstat (limited to 'source/blender/blenkernel/intern/cloth.c')
-rw-r--r--source/blender/blenkernel/intern/cloth.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 137b6a3d599..d0796db6b54 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -747,7 +747,12 @@ static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, in
float base = 1.0f - clmd->sim_parms->shrink_min;
float delta = clmd->sim_parms->shrink_min - clmd->sim_parms->shrink_max;
- return base + delta * 0.5f * (verts[i1].shrink_factor + verts[i2].shrink_factor);
+ float k1 = base + delta * verts[i1].shrink_factor;
+ float k2 = base + delta * verts[i2].shrink_factor;
+
+ /* Use geometrical mean to average two factors since it behaves better
+ for diagonals when a rectangle transforms into a trapezoid. */
+ return sqrtf(k1 * k2);
}
else
return 1.0f;