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.
This commit is contained in:
Alexander Gavrilov 2016-04-18 18:47:16 +03:00
parent 8d22a8afa0
commit b481e886e5
1 changed files with 6 additions and 1 deletions

View File

@ -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;