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:
Diffstat (limited to 'source/blender/physics/intern/BPH_mass_spring.cpp')
-rw-r--r--source/blender/physics/intern/BPH_mass_spring.cpp67
1 files changed, 59 insertions, 8 deletions
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 259eed88756..7521efa5cbd 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -76,18 +76,39 @@ static int cloth_count_nondiag_blocks(Cloth *cloth)
static float cloth_calc_volume(ClothModifierData *clmd)
{
- /* calc the (closed) cloth volume */
+ /* Calculate the (closed) cloth volume. */
Cloth *cloth = clmd->clothObject;
const MVertTri *tri = cloth->tri;
Implicit_Data *data = cloth->implicit;
float vol = 0;
- for (unsigned int i = 0; i < cloth->tri_num; i++) {
- const MVertTri *vt = &tri[i];
- vol += BPH_tri_tetra_volume_signed_6x(data, vt->tri[0], vt->tri[1], vt->tri[2]);
- }
+ if (clmd->sim_parms->vgroup_pressure > 0) {
+ for (unsigned int i = 0; i < cloth->tri_num; i++) {
+ bool skip_face = false;
+ /* We have custom vertex weights for pressure. */
+ const MVertTri *vt = &tri[i];
+ for (unsigned int j = 0; j < 3; j++) {
+ /* If any weight is zero, don't take this face into account for volume calculation. */
+ ClothVertex *verts = clmd->clothObject->verts;
+
+ if (verts[vt->tri[j]].pressure_factor == 0.0f) {
+ skip_face = true;
+ }
+ }
+ if (skip_face) {
+ continue;
+ }
- /* We need to divide by 6 to get the actual volume */
+ vol += BPH_tri_tetra_volume_signed_6x(data, vt->tri[0], vt->tri[1], vt->tri[2]);
+ }
+ }
+ else {
+ for (unsigned int i = 0; i < cloth->tri_num; i++) {
+ const MVertTri *vt = &tri[i];
+ vol += BPH_tri_tetra_volume_signed_6x(data, vt->tri[0], vt->tri[1], vt->tri[2]);
+ }
+ }
+ /* We need to divide by 6 to get the actual volume. */
vol = vol / 6.0f;
return vol;
@@ -634,8 +655,38 @@ static void cloth_calc_force(
for (i = 0; i < cloth->tri_num; i++) {
const MVertTri *vt = &tri[i];
if (fabs(pressure_difference) > 1E-6f) {
- BPH_mass_spring_force_pressure(
- data, vt->tri[0], vt->tri[1], vt->tri[2], pressure_difference);
+ if (clmd->sim_parms->vgroup_pressure > 0) {
+ /* We have custom vertex weights for pressure. */
+ ClothVertex *verts = clmd->clothObject->verts;
+ int v1, v2, v3;
+ v1 = vt->tri[0];
+ v2 = vt->tri[1];
+ v3 = vt->tri[2];
+
+ float weights[3];
+ bool skip_face = false;
+
+ weights[0] = verts[v1].pressure_factor;
+ weights[1] = verts[v2].pressure_factor;
+ weights[2] = verts[v3].pressure_factor;
+ for (unsigned int j = 0; j < 3; j++) {
+ if (weights[j] == 0.0f) {
+ /* Exclude faces which has a zero weight vert. */
+ skip_face = true;
+ break;
+ }
+ }
+ if (skip_face) {
+ continue;
+ }
+
+ BPH_mass_spring_force_pressure(data, v1, v2, v3, pressure_difference, weights);
+ }
+ else {
+ float weights[3] = {1.0f, 1.0f, 1.0f};
+ BPH_mass_spring_force_pressure(
+ data, vt->tri[0], vt->tri[1], vt->tri[2], pressure_difference, weights);
+ }
}
}
}