diff options
-rw-r--r-- | source/blender/blenkernel/intern/cloth.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 7a2a4e09b3d..137b6a3d599 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -644,6 +644,7 @@ int cloth_uses_vgroup(ClothModifierData *clmd) { return (((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING ) || (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) || + (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW) || (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF)) && ((clmd->sim_parms->vgroup_mass>0) || (clmd->sim_parms->vgroup_struct>0)|| @@ -684,6 +685,9 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) else verts->goal= 0.0f; + /* Compute base cloth shrink weight */ + verts->shrink_factor = 0.0f; + /* Reset vertex flags */ verts->flags &= ~CLOTH_VERT_FLAG_PINNED; verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL; @@ -721,16 +725,14 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) verts->flags |= CLOTH_VERT_FLAG_NOSELFCOLL; } } - + } + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW ) { if (clmd->sim_parms->vgroup_shrink > 0) { if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_shrink - 1)) { - /* linear interpolation between min and max shrink factor based on weight */ - verts->shrink_factor = clmd->sim_parms->shrink_min * (1.0f - dvert->dw[j].weight) + clmd->sim_parms->shrink_max * dvert->dw [j].weight; + /* used for linear interpolation between min and max shrink factor based on weight */ + verts->shrink_factor = dvert->dw[j].weight; } } - else { - verts->shrink_factor = clmd->sim_parms->shrink_min; - } } } } @@ -738,6 +740,18 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) } } +static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, int i1, int i2) +{ + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW ) { + /* linear interpolation between min and max shrink factor based on weight */ + float base = 1.0f - clmd->sim_parms->shrink_min; + float delta = clmd->sim_parms->shrink_min - clmd->sim_parms->shrink_max; + + return base + delta * 0.5f * (verts[i1].shrink_factor + verts[i2].shrink_factor); + } + else + return 1.0f; +} static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float UNUSED(framenr), int first) { @@ -811,6 +825,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d else verts->goal= 0.0f; + verts->shrink_factor = 0.0f; + verts->flags = 0; copy_v3_v3 ( verts->xold, verts->x ); copy_v3_v3 ( verts->xconst, verts->x ); @@ -1237,10 +1253,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) spring->type = CLOTH_SPRING_TYPE_SEWING; } else { - if (clmd->sim_parms->vgroup_shrink > 0) - shrink_factor = 1.0f - ((cloth->verts[spring->ij].shrink_factor + cloth->verts[spring->kl].shrink_factor) / 2.0f); - else - shrink_factor = 1.0f - clmd->sim_parms->shrink_min; + shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); 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; @@ -1287,10 +1300,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) mloop[mpoly[i].loopstart + (j + 0)].v, mloop[mpoly[i].loopstart + (j + 2)].v); - if (clmd->sim_parms->vgroup_shrink > 0) - shrink_factor = 1.0f - ((cloth->verts[spring->ij].shrink_factor + cloth->verts[spring->kl].shrink_factor) / 2.0f); - else - shrink_factor = 1.0f - clmd->sim_parms->shrink_min; + shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor; spring->type = CLOTH_SPRING_TYPE_SHEAR; spring->stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0f; @@ -1334,7 +1344,8 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) } spring_verts_ordered_set(spring, tspring2->ij, index2); - spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); + shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); + spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor; spring->type = CLOTH_SPRING_TYPE_BENDING; spring->stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f; BLI_edgeset_insert(edgeset, spring->ij, spring->kl); |