[Bf-blender-cvs] [b481e88] master: Cloth: Use Geometrical Mean for averaging cloth shrink factor.

Alexander Gavrilov noreply at git.blender.org
Fri May 6 11:07:07 CEST 2016


Commit: b481e886e5ad4c4ab6f1118f80933a4bf558c61e
Author: Alexander Gavrilov
Date:   Mon Apr 18 18:47:16 2016 +0300
Branches: master
https://developer.blender.org/rBb481e886e5ad4c4ab6f1118f80933a4bf558c61e

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.

===================================================================

M	source/blender/blenkernel/intern/cloth.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 137b6a3..d0796db 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;




More information about the Bf-blender-cvs mailing list