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>2020-07-01 17:40:28 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2020-07-01 17:42:05 +0300
commit42be3964eb201180f6b0fa1ff6ce43b8c3845bc2 (patch)
treecab61828b9b568ae35345c6c868ffeae91cf5899
parentb5660f71fe77969a75d6b41d87a310ec252b3a4c (diff)
Cloth: correctly use the rest shape to compute the initial pressure volume.
Computing the original volume should use the rest positions of vertices, like is done for initializing other parts of the simulation like springs. Otherwise, features like rest shape key don't work correctly.
-rw-r--r--source/blender/physics/intern/BPH_mass_spring.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 3b6e39ef48f..051f11aa1d9 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -137,6 +137,35 @@ static float cloth_calc_volume(ClothModifierData *clmd)
return vol;
}
+static float cloth_calc_rest_volume(ClothModifierData *clmd)
+{
+ /* Calculate the (closed) cloth volume. */
+ Cloth *cloth = clmd->clothObject;
+ const MVertTri *tri = cloth->tri;
+ const ClothVertex *v = cloth->verts;
+ float weights[3] = {1.0f, 1.0f, 1.0f};
+ float vol = 0;
+
+ /* Early exit for hair, as it never has volume. */
+ if (clmd->hairdata) {
+ return 0.0f;
+ }
+
+ for (unsigned int i = 0; i < cloth->primitive_num; i++) {
+ const MVertTri *vt = &tri[i];
+
+ if (cloth_get_pressure_weights(clmd, vt, weights)) {
+ vol += volume_tri_tetrahedron_signed_v3_6x(
+ v[vt->tri[0]].xrest, v[vt->tri[1]].xrest, v[vt->tri[2]].xrest);
+ }
+ }
+
+ /* We need to divide by 6 to get the actual volume. */
+ vol = vol / 6.0f;
+
+ return vol;
+}
+
static float cloth_calc_average_pressure(ClothModifierData *clmd, const float *vertex_pressure)
{
Cloth *cloth = clmd->clothObject;
@@ -219,7 +248,7 @@ void BKE_cloth_solver_set_volume(ClothModifierData *clmd)
{
Cloth *cloth = clmd->clothObject;
- cloth->initial_mesh_volume = cloth_calc_volume(clmd);
+ cloth->initial_mesh_volume = cloth_calc_rest_volume(clmd);
}
/* Init constraint matrix