From 32a8d7cbdf9a705a5b97554651ab500ed5962fb4 Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Fri, 10 Aug 2012 00:04:15 +0000 Subject: Bugfix: Cloth did not work with Dynamic Paint. Fix 1: Pinned vertices were never released when "unpinned" by Dynamic Paint. Fix 2: When pinning vertices during simulation, they would get "warped" to their original starting position of frame 1. Thanks to MiikaH for pointing this out and also for providing the regression blend file: http://wiki.blender.org/uploads/a/ab/Cloth_dynamic_paint.blend --- source/blender/blenkernel/intern/cloth.c | 38 +++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'source/blender/blenkernel/intern/cloth.c') diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index d1a4b33f8f8..af7afe7bf30 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -400,8 +400,18 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul copy_v3_v3(verts->txold, verts->x); /* Get the current position. */ - copy_v3_v3(verts->xconst, mvert[i].co); - mul_m4_v3(ob->obmat, verts->xconst); + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && + ((!(cloth->verts[i].flags & CLOTH_VERT_FLAG_PINNED)) + && (cloth->verts[i].goal > ALMOST_ZERO))) + { + copy_v3_v3(verts->xconst, mvert[i].co); + mul_m4_v3(ob->obmat, verts->xconst); + } + else + { + /* This fixed animated goals not to jump back to "first frame position" */ + copy_v3_v3(verts->xconst, verts->txold); + } } effectors = pdInitEffectors(clmd->scene, ob, NULL, clmd->sim_parms->effector_weights); @@ -795,13 +805,21 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) if (cloth_uses_vgroup(clmd)) { for ( i = 0; i < numverts; i++, verts++ ) { + + /* Reset Goal values to standard */ + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) + verts->goal= clmd->sim_parms->defgoal; + else + verts->goal= 0.0f; + dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT ); if ( dvert ) { - for ( j = 0; j < dvert->totweight; j++ ) { + for ( j = 0; j < dvert->totweight; j++ ) { verts->flags &= ~CLOTH_VERT_FLAG_PINNED; if (( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) && (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )) { verts->goal = dvert->dw [j].weight; + /* goalfac= 1.0f; */ /* UNUSED */ /* @@ -1082,6 +1100,20 @@ static void cloth_update_springs( ClothModifierData *clmd ) { spring->stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f; } + else if(spring->type == CLOTH_SPRING_TYPE_GOAL) + { + /* Warning: Appending NEW goal springs does not work because implicit solver would need reset! */ + + /* Activate / Deactivate existing springs */ + if ((!(cloth->verts[spring->ij].flags & CLOTH_VERT_FLAG_PINNED)) && (cloth->verts[spring->ij].goal > ALMOST_ZERO)) + { + spring->flags &= ~CLOTH_SPRING_FLAG_DEACTIVATE; + } + else + { + spring->flags |= CLOTH_SPRING_FLAG_DEACTIVATE; + } + } search = search->next; } -- cgit v1.2.3