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')
-rw-r--r--source/blender/physics/intern/BPH_mass_spring.cpp67
-rw-r--r--source/blender/physics/intern/implicit.h8
-rw-r--r--source/blender/physics/intern/implicit_blender.c8
3 files changed, 69 insertions, 14 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);
+ }
}
}
}
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 82a3f61e1e1..490e727b5f2 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -184,8 +184,12 @@ bool BPH_mass_spring_force_spring_goal(struct Implicit_Data *data,
float BPH_tri_tetra_volume_signed_6x(struct Implicit_Data *data, int v1, int v2, int v3);
-void BPH_mass_spring_force_pressure(
- struct Implicit_Data *data, int v1, int v2, int v3, float pressure_difference);
+void BPH_mass_spring_force_pressure(struct Implicit_Data *data,
+ int v1,
+ int v2,
+ int v3,
+ float pressure_difference,
+ float weights[3]);
/* ======== Hair Volumetric Forces ======== */
diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c
index fa093f482f7..02d7fd50797 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1489,7 +1489,7 @@ float BPH_tri_tetra_volume_signed_6x(Implicit_Data *data, int v1, int v2, int v3
}
void BPH_mass_spring_force_pressure(
- Implicit_Data *data, int v1, int v2, int v3, float pressure_difference)
+ Implicit_Data *data, int v1, int v2, int v3, float pressure_difference, float weights[3])
{
float nor[3], area;
float factor;
@@ -1500,9 +1500,9 @@ void BPH_mass_spring_force_pressure(
factor = pressure_difference * area / 3.0f;
/* add pressure to each of the face verts */
- madd_v3_v3fl(data->F[v1], nor, factor);
- madd_v3_v3fl(data->F[v2], nor, factor);
- madd_v3_v3fl(data->F[v3], nor, factor);
+ madd_v3_v3fl(data->F[v1], nor, factor * weights[0]);
+ madd_v3_v3fl(data->F[v2], nor, factor * weights[1]);
+ madd_v3_v3fl(data->F[v3], nor, factor * weights[2]);
}
static void edge_wind_vertex(const float dir[3],