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>2016-04-18 18:47:38 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2016-05-06 11:40:19 +0300
commit8e1ab9b13703b95a2e8092a463ee098553f9ab33 (patch)
tree704a4a342088916b29c4cf76cdd0319e09e84b9e /source/blender/blenkernel/intern/cloth.c
parentb481e886e5ad4c4ab6f1118f80933a4bf558c61e (diff)
Cloth: Ignore zero-restlen sewing springs in average length computation.
The average length is used to adjust self-collision and stiffness to match mesh density, and in either case considering the always zero restlen sewing springs doesn't actually make much sense. The struct_springs variable is also used for other things like total spring count, so a new one needed for the true struct springs.
Diffstat (limited to 'source/blender/blenkernel/intern/cloth.c')
-rw-r--r--source/blender/blenkernel/intern/cloth.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index d0796db6b54..175654384e5 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -1214,7 +1214,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
{
Cloth *cloth = clmd->clothObject;
ClothSpring *spring = NULL, *tspring = NULL, *tspring2 = NULL;
- unsigned int struct_springs = 0, shear_springs=0, bend_springs = 0;
+ unsigned int struct_springs = 0, shear_springs=0, bend_springs = 0, struct_springs_real = 0;
unsigned int i = 0;
unsigned int mvert_num = (unsigned int)dm->getNumVerts(dm);
unsigned int numedges = (unsigned int)dm->getNumEdges (dm);
@@ -1262,12 +1262,15 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor;
spring->stiffness = (cloth->verts[spring->kl].struct_stiff + cloth->verts[spring->ij].struct_stiff) / 2.0f;
spring->type = CLOTH_SPRING_TYPE_STRUCTURAL;
+
+ clmd->sim_parms->avg_spring_len += spring->restlen;
+ cloth->verts[spring->ij].avg_spring_len += spring->restlen;
+ cloth->verts[spring->kl].avg_spring_len += spring->restlen;
+ cloth->verts[spring->ij].spring_count++;
+ cloth->verts[spring->kl].spring_count++;
+ struct_springs_real++;
}
- clmd->sim_parms->avg_spring_len += spring->restlen;
- cloth->verts[spring->ij].avg_spring_len += spring->restlen;
- cloth->verts[spring->kl].avg_spring_len += spring->restlen;
- cloth->verts[spring->ij].spring_count++;
- cloth->verts[spring->kl].spring_count++;
+
spring->flags = 0;
struct_springs++;
@@ -1279,11 +1282,12 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
}
}
- if (struct_springs > 0)
- clmd->sim_parms->avg_spring_len /= struct_springs;
+ if (struct_springs_real > 0)
+ clmd->sim_parms->avg_spring_len /= struct_springs_real;
for (i = 0; i < mvert_num; i++) {
- cloth->verts[i].avg_spring_len = cloth->verts[i].avg_spring_len * 0.49f / ((float)cloth->verts[i].spring_count);
+ if (cloth->verts[i].spring_count > 0)
+ cloth->verts[i].avg_spring_len = cloth->verts[i].avg_spring_len * 0.49f / ((float)cloth->verts[i].spring_count);
}
// shear springs