[Bf-blender-cvs] [42be3964eb2] master: Cloth: correctly use the rest shape to compute the initial pressure volume.

Alexander Gavrilov noreply at git.blender.org
Wed Jul 1 16:48:30 CEST 2020


Commit: 42be3964eb201180f6b0fa1ff6ce43b8c3845bc2
Author: Alexander Gavrilov
Date:   Wed Jul 1 17:40:28 2020 +0300
Branches: master
https://developer.blender.org/rB42be3964eb201180f6b0fa1ff6ce43b8c3845bc2

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.

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

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



More information about the Bf-blender-cvs mailing list