New: Min & MaxFrame of simulation; Fixed: Many reset problems gone
authorDaniel Genrich <daniel.genrich@gmx.net>
Sun, 16 Sep 2007 23:19:02 +0000 (23:19 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sun, 16 Sep 2007 23:19:02 +0000 (23:19 +0000)
14 files changed:
source/blender/blenkernel/BKE_cloth.h
source/blender/blenkernel/BKE_modifier.h
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/implicit.c
source/blender/blenkernel/intern/modifier.c
source/blender/include/butspace.h
source/blender/makesdna/DNA_cloth_types.h
source/blender/src/buttons_editing.c
source/blender/src/buttons_object.c
source/blender/src/editmesh.c
source/blender/src/editobject.c
source/blender/src/transform_conversions.c
source/blender/src/transform_generics.c
source/blender/src/vpaint.c

index e843079f412f46f00d6a977e727b053495725008..0a50feeb9b02f432c4811df5f7c45696c2fc3250 100644 (file)
@@ -107,6 +107,7 @@ typedef enum
 
 // needed for buttons_object.c
 void cloth_cache_free(ClothModifierData *clmd, float time);
+void cloth_free_modifier (ClothModifierData *clmd);
 
 // needed for cloth.c
 void implicit_set_positions (ClothModifierData *clmd);
index 297443b883d57b91f24c74eaaece97826d93aec7..365381f5cdd3e17d01961a6ede245d592ab46dff 100644 (file)
@@ -277,6 +277,7 @@ int           modifiers_getCageIndex(struct Object *ob,
                                      int *lastPossibleCageIndex_r);
 
 int           modifiers_isSoftbodyEnabled(struct Object *ob);
+struct ModifierData  *modifiers_isClothEnabled(struct Object *ob);
 struct Object *modifiers_isDeformedByArmature(struct Object *ob);
 struct Object *modifiers_isDeformedByLattice(struct Object *ob);
 int           modifiers_usesArmature(struct Object *ob, struct bArmature *arm);
index 4b4aa2d0d1df2bf3f58ba76ebaa4ca0d14c1f367..18e1d4a6cde85c9d05b4cd7f3dff886aeefe8d23 100644 (file)
@@ -119,6 +119,8 @@ static CM_SOLVER_DEF        solvers [] = {
 
 #define DEBUG_CLOTH_VERBOSE    1000
 static int     DEBUG_CLOTH = 0;
+
+
 /* ********** cloth engine ******* */
 /* Prototypes for internal functions.
 */
@@ -128,6 +130,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
 static int collobj_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float (*vertexCos)[3], unsigned int numverts);
 int cloth_build_springs(Cloth *cloth, DerivedMesh *dm);
 static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, short vgroup);
+
+
 /******************************************************************************
 *
 * External interface called by modifier.c clothModifier functions.
@@ -157,6 +161,8 @@ void cloth_init (ClothModifierData *clmd)
        clmd->sim_parms.solver_type = 0; 
        clmd->sim_parms.preroll = 0;
        clmd->sim_parms.maxspringlen = 10;
+       clmd->sim_parms.firstframe = 1;
+       clmd->sim_parms.lastframe = 250;
        clmd->coll_parms.self_friction = 5.0;
        clmd->coll_parms.friction = 10.0;
        clmd->coll_parms.loop_count = 1;
@@ -614,8 +620,13 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
        Frame *frame = NULL;
        LinkNode *search = NULL;
        float deltaTime = current_time - clmd->sim_parms.sim_time;      
-
-       clmd->sim_parms.dt = 1.0f / (clmd->sim_parms.stepsPerFrame * G.scene->r.frs_sec);
+       
+       // only be active during a specific period
+       if((current_time < clmd->sim_parms.firstframe)||(current_time > clmd->sim_parms.lastframe))
+               return;
+       
+       // unused in the moment
+       clmd->sim_parms.dt = 1.0f / clmd->sim_parms.stepsPerFrame;
        
        clmd->sim_parms.sim_time = current_time;
        
@@ -707,7 +718,6 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
                                tstart();
 
                                /* Call the solver. */
-
                                if (solvers [clmd->sim_parms.solver_type].solver)
                                        solvers [clmd->sim_parms.solver_type].solver (ob, framenr, clmd, effectors,0,0);
 
@@ -754,9 +764,6 @@ void cloth_free_modifier (ClothModifierData *clmd)
        clmd->sim_parms.flags |= CSIMSETT_FLAG_CCACHE_FREE_ALL;
        cloth_cache_free(clmd, 0);
 
-       /* Calls the solver and collision frees first as they
-       * might depend on data in clmd->clothObject. */
-
        if (cloth) 
        {       
                // If our solver provides a free function, call it
@@ -793,11 +800,9 @@ void cloth_free_modifier (ClothModifierData *clmd)
                MEM_freeN (cloth);
                clmd->clothObject = NULL;
        }
-
 }
 
 
-
 /******************************************************************************
 *
 * Internal functions.
@@ -826,8 +831,6 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertex
                        Mat4MulVecfl (ob->imat, vertexCos[i]);  /* softbody is in global coords */
                }
        }
-       else if (DEBUG_CLOTH)
-               printf ("cloth_to_object: clmd->clothObject was NULL.\n");
 }
 
 
@@ -837,15 +840,20 @@ static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertex
 **/
 static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, short vgroup)
 {
-       unsigned int    i;
-       int j;
-       MDeformVert     *dvert = NULL;
-       Cloth           *clothObj;
+       unsigned int i = 0;
+       unsigned int j = 0;
+       MDeformVert *dvert = NULL;
+       Cloth *clothObj = NULL;
        unsigned int numverts = dm->getNumVerts(dm);
        float goalfac = 0;
        ClothVertex *verts = NULL;
 
        clothObj = clmd->clothObject;
+       
+       if(!dm)
+               return;
+       
+       numverts = dm->getNumVerts(dm);
 
        /* vgroup is 1 based, decrement so we can match the right group. */
        --vgroup;
index 5d386036b7bbcbcd2a243ba07e6e567fb02590b4..c756c220fe6d3dd57ad2591cfa5e1efd4e4dd78d 100644 (file)
@@ -689,14 +689,15 @@ typedef struct Implicit_Data
        lfVector *X, *V, *Xnew, *Vnew, *olddV, *F, *B, *dV, *z;
        fmatrix3x3 *A, *dFdV, *dFdX, *S, *P, *Pinv, *bigI; 
 } Implicit_Data;
+
 int implicit_init (Object *ob, ClothModifierData *clmd)
 {
        unsigned int i = 0;
        unsigned int pinned = 0;
-       Cloth *cloth;
-       ClothVertex *verts;
-       ClothSpring *springs;
-       Implicit_Data *id;
+       Cloth *cloth = NULL;
+       ClothVertex *verts = NULL;
+       ClothSpring *springs = NULL;
+       Implicit_Data *id = NULL;
 
        // init memory guard
        // MEMORY_BASE.first = MEMORY_BASE.last = NULL;
@@ -727,6 +728,7 @@ int implicit_init (Object *ob, ClothModifierData *clmd)
        id->B = create_lfvector(cloth->numverts);
        id->dV = create_lfvector(cloth->numverts);
        id->z = create_lfvector(cloth->numverts);
+       
        for(i=0;i<cloth->numverts;i++) 
        {
                id->A[i].r = id->A[i].c = id->dFdV[i].r = id->dFdV[i].c = id->dFdX[i].r = id->dFdX[i].c = id->P[i].c = id->P[i].r = id->Pinv[i].c = id->Pinv[i].r = id->bigI[i].c = id->bigI[i].r = i;
@@ -1503,9 +1505,23 @@ void implicit_set_positions (ClothModifierData *clmd)
        ClothVertex *verts = cloth->verts;
        unsigned int numverts = cloth->numverts, i;
        Implicit_Data *id = cloth->implicit;
+       unsigned int pinned = 0;
+       
+       // reset pinned verts in S matrix to zero
+       // id->S[0].vcount = 0; id->S[0].scount = 0;
+       
        for(i = 0; i < numverts; i++)
        {                               
                VECCOPY(id->X[i], verts[i].x);
                VECCOPY(id->V[i], verts[i].v);
+               /*
+               if(verts [i].flags & CVERT_FLAG_PINNED)
+               {
+                       id->S[pinned].pinned = 1;
+                       id->S[pinned].c = id->S[pinned].r = i;
+                       pinned++;
+               }
+               */
        }       
+       // id->S[0].vcount = pinned;
 }
index 0d7668e0ccca4df4895eed226ec87a5d6a7f93ab..d3d41e70d575c8952b30f8863872cecd51c8ae7f 100644 (file)
@@ -5233,8 +5233,8 @@ ModifierTypeInfo *modifierType_getInfo(ModifierType type)
                mti = INIT_TYPE(Cloth);
                mti->type = eModifierTypeType_OnlyDeform;
                mti->initData = clothModifier_initData;
-               mti->flags = eModifierTypeFlag_AcceptsCVs;
-                                       // | eModifierTypeFlag_RequiresOriginalData;
+               mti->flags = eModifierTypeFlag_AcceptsCVs
+                        | eModifierTypeFlag_RequiresOriginalData;
                                        // | eModifierTypeFlag_SupportsMapping
                                        // | eModifierTypeFlag_SupportsEditmode 
                                        // | eModifierTypeFlag_EnableInEditmode;
@@ -5446,6 +5446,13 @@ int modifiers_isSoftbodyEnabled(Object *ob)
        return (md && md->mode & (eModifierMode_Realtime | eModifierMode_Render));
 }
 
+ModifierData * modifiers_isClothEnabled(Object *ob)
+{
+       ModifierData *md = modifiers_findByType(ob, eModifierType_Cloth);
+
+       return md;
+}
+
 LinkNode *modifiers_calcDataMasks(ModifierData *md, CustomDataMask dataMask)
 {
        LinkNode *dataMasks = NULL;
index cb17f81b87dcc42ffff4291d8d3a9ce30e4c3309..b017dd950e2629b1442c0ddac5a12a084b6302f3 100644 (file)
@@ -289,6 +289,7 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
 #define B_CLOTH_CLEARCACHEFRAME                1471
 #define B_CLOTH_CHANGEPREROLL                  1472
 #define B_CLOTH_DEL_VG                                 1473
+#define B_CLOTH_RENEW  1474
 
 /* *********************** */
 #define B_WORLDBUTS            1600
index bed04c2fa7166c7849f331a5a7e8b737836acae3..c756c29f467f13187b0eb130ed69dad49a8e92f8 100644 (file)
@@ -106,7 +106,9 @@ typedef struct SimulationSettings {
        float   defgoal;
        int     goalfrict;
        float   goalspring;
-       int     maxspringlen; /* in percent!; if tearing enabled, a spring will get cut */
+       int     maxspringlen;   /* in percent!; if tearing enabled, a spring will get cut */
+       int     lastframe;      /* frame on which simulation stops */
+       int     firstframe;     /* frame on which simulation starts */
 } SimulationSettings;
 
 
@@ -144,7 +146,7 @@ typedef struct Cloth {
        int                     pad4;
        void                    *tree;                  /* collision tree for this cloth object */
        struct MFace            *mfaces;
-       void                    *implicit;      
+       void                    *implicit;              /* our implicit solver connects to this pointer */
 } Cloth;
 
 #endif
index ea90f6fdc163346d5207560d6a02c254f8761ad4..2ab5397f4931ee9cc6054d30d46bc5af0d394877 100644 (file)
@@ -949,7 +949,7 @@ static uiBlock *modifiers_add_menu(void *ob_v)
                ModifierTypeInfo *mti = modifierType_getInfo(i);
 
                /* Only allow adding through appropriate other interfaces */
-               if(ELEM(i, eModifierType_Softbody, eModifierType_Hook)) continue;
+               if(ELEM3(i, eModifierType_Softbody, eModifierType_Hook, eModifierType_Cloth)) continue;
 
                if((mti->flags&eModifierTypeFlag_AcceptsCVs) ||
                   (ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {
@@ -1600,6 +1600,8 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
                                height += 20;
                } else if (md->type==eModifierType_Softbody) {
                        height = 26;
+               } else if (md->type==eModifierType_Cloth) {
+                       height = 26;
                } else if (md->type==eModifierType_Boolean) {
                        height = 48;
                } else if (md->type==eModifierType_Array) {
@@ -1615,7 +1617,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
                        uiBlockBeginAlign(block);
                        but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Apply",  lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Apply the current modifier and remove from the stack");
                        uiButSetFunc(but, modifiers_applyModifier, ob, md);
-                       if (md->type!=eModifierType_Softbody) {
+                       if ((md->type!=eModifierType_Softbody) && (md->type!=eModifierType_Cloth)) {
                                but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Copy",   lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Duplicate the current modifier at the same position in the stack");
                                uiButSetFunc(but, modifiers_copyModifier, ob, md);
                        }
@@ -3308,6 +3310,9 @@ void do_latticebuts(unsigned short event)
                        if(ob==G.obedit) resizelattice(editLatt, lt->opntsu, lt->opntsv, lt->opntsw, NULL);
                        else resizelattice(ob->data, lt->opntsu, lt->opntsv, lt->opntsw, NULL);
                        ob->softflag |= OB_SB_REDO;
+                       if(modifiers_isClothEnabled(ob)) {
+                               cloth_free_modifier(modifiers_isClothEnabled(ob));
+                       }
                        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
                        allqueue(REDRAWVIEW3D, 0);
                }
@@ -3316,6 +3321,9 @@ void do_latticebuts(unsigned short event)
                        lt = ob->data;
                        resizelattice(ob->data, lt->opntsu, lt->opntsv, lt->opntsw, ob);
                        ob->softflag |= OB_SB_REDO;
+                       if(modifiers_isClothEnabled(ob)) {
+                               cloth_free_modifier(modifiers_isClothEnabled(ob));
+                       }
                        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
                        allqueue(REDRAWVIEW3D, 0);
                }
index de1d8f8c0ac55e3f5d9f24f002f12d1734dd3e13..df6d88bddd05619c2e0f9e5a59222835c44ac66a 100644 (file)
@@ -2196,11 +2196,22 @@ void do_object_panels(unsigned short event)
                        if(clmd)
                        {
                                clmd->sim_parms.vgroup_mass = 0;
+                               do_object_panels(B_CLOTH_RENEW);
                        }
                        
                        allqueue(REDRAWBUTSOBJECT, 0);
                }
                break;  
+       case B_CLOTH_RENEW:
+               {
+                       ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
+                       if(clmd)
+                       {
+                               do_object_panels(B_CLOTH_CLEARCACHEALL);
+                               cloth_free_modifier (clmd);
+                       }
+               }
+               break;
        default:
                if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
                        int a=B_SELEFFECT;
@@ -3108,12 +3119,12 @@ static void object_panel_cloth(Object *ob)
                        /* GENERAL STUFF */
                        uiClearButLock();
                        uiBlockBeginAlign(block);
-                       uiDefButF(block, NUM, B_DIFF, "StructStiff:",      10,170,150,20, &clmd->sim_parms.structural, 1.0, 5000.0, 100, 0, "Overall stiffness of structure");
-                       uiDefButF(block, NUM, B_DIFF, "BendStiff:",        160,170,150,20, &clmd->sim_parms.bending, 0.0, 1000.0, 1000, 0, "Wrinkle possibility");
-                       uiDefButI(block, NUM, B_DIFF, "Steps per Frame:",          10,150,150,20, &clmd->sim_parms.stepsPerFrame, 1.0, 100.0, 5, 0, "Quality of the simulation (higher=better=slower)");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "StructStiff:",       10,170,150,20, &clmd->sim_parms.structural, 1.0, 5000.0, 100, 0, "Overall stiffness of structure");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "BendStiff:",         160,170,150,20, &clmd->sim_parms.bending, 0.0, 1000.0, 1000, 0, "Wrinkle possibility");
+                       uiDefButI(block, NUM, B_CLOTH_RENEW, "Steps per Frame:",           10,150,150,20, &clmd->sim_parms.stepsPerFrame, 1.0, 100.0, 5, 0, "Quality of the simulation (higher=better=slower)");
                        uiBlockEndAlign(block);
                        uiBlockBeginAlign(block);
-                       uiDefButF(block, NUM, B_DIFF, "Spring Damp:",      160,150,150,20, &clmd->sim_parms.Cdis, 0.0, 10.0, 10, 0, "Apply gravitation to point movement");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "Spring Damp:",       160,150,150,20, &clmd->sim_parms.Cdis, 0.0, 10.0, 10, 0, "Spring damping");
                        uiDefButF(block, NUM, B_DIFF, "Air Damp:",         10,130,150,20, &clmd->sim_parms.Cvi, 0.0, 10.0, 10, 0, "Apply gravitation to point movement");
                        uiBlockEndAlign(block);                 
                        
@@ -3123,9 +3134,9 @@ static void object_panel_cloth(Object *ob)
                        uiDefBut(block, LABEL, 0, "Gravity:",  10,100,60,20, NULL, 0.0, 0, 0, 0, "");
                        // uiClearButLock();
                        
-                       uiDefButF(block, NUM, B_DIFF, "X:",        70,100,80,20, &clmd->sim_parms.gravity[0], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
-                       uiDefButF(block, NUM, B_DIFF, "Y:",        150,100,80,20, &clmd->sim_parms.gravity[1], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
-                       uiDefButF(block, NUM, B_DIFF, "Z:",        230,100,80,20, &clmd->sim_parms.gravity[2], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "X:",         70,100,80,20, &clmd->sim_parms.gravity[0], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "Y:",         150,100,80,20, &clmd->sim_parms.gravity[1], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "Z:",         230,100,80,20, &clmd->sim_parms.gravity[2], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
                        uiBlockEndAlign(block);
                        
                        /* GOAL STUFF */
@@ -3150,7 +3161,7 @@ static void object_panel_cloth(Object *ob)
                                        }
                                        sprintf (clvg2, "%s%s", clmvg, clvg1);
                                        
-                                       uiDefButS(block, MENU, REDRAWVIEW3D, clvg2,     140,70,20,20, &clmd->sim_parms.vgroup_mass, 0, defCount, 0, 0, "Browses available vertex groups");      
+                                       uiDefButS(block, MENU, B_CLOTH_RENEW, clvg2,    140,70,20,20, &clmd->sim_parms.vgroup_mass, 0, defCount, 0, 0, "Browses available vertex groups");      
                                        MEM_freeN (clvg1);
                                        MEM_freeN (clvg2);
                                        
@@ -3166,19 +3177,19 @@ static void object_panel_cloth(Object *ob)
                                                
                                        }
                                        else
-                                               uiDefButF(block, NUM, REDRAWVIEW3D, "Goal:",    160,70,150,20, &clmd->sim_parms.defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
+                                               uiDefButF(block, NUM, B_CLOTH_RENEW, "Goal:",   160,70,150,20, &clmd->sim_parms.defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
                                
                                }
                                else 
                                {
-                                       uiDefButS(block, TOG, REDRAWVIEW3D, "W",                        140,70,20,20, &clmd->sim_parms.vgroup_mass, 0, 1, 0, 0, "Use control point weight values");
-                                       uiDefButF(block, NUM, REDRAWVIEW3D, "Goal:",    160,70,150,20, &clmd->sim_parms.defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
+                                       uiDefButS(block, TOG, B_CLOTH_RENEW, "W",                       140,70,20,20, &clmd->sim_parms.vgroup_mass, 0, 1, 0, 0, "Use control point weight values");
+                                       uiDefButF(block, NUM, B_CLOTH_RENEW, "Goal:",   160,70,150,20, &clmd->sim_parms.defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
                                }
                                
-                               uiDefButF(block, NUM, B_DIFF, "G Stiff:",       10,50,150,20, &clmd->sim_parms.goalspring, 0.0, 500.0, 10, 0, "Goal (vertex target position) spring stiffness");
-                               uiDefButF(block, NUM, B_DIFF, "G Damp:",        160,50,150,20, &clmd->sim_parms.goalfrict  , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
-                               uiDefButF(block, NUM, REDRAWVIEW3D, "G Min:",           10,30,150,20, &clmd->sim_parms.mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
-                               uiDefButF(block, NUM, REDRAWVIEW3D, "G Max:",           160,30,150,20, &clmd->sim_parms.maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
+                               uiDefButF(block, NUM, B_CLOTH_RENEW, "G Stiff:",        10,50,150,20, &clmd->sim_parms.goalspring, 0.0, 500.0, 10, 0, "Goal (vertex target position) spring stiffness");
+                               uiDefButF(block, NUM, B_CLOTH_RENEW, "G Damp:", 160,50,150,20, &clmd->sim_parms.goalfrict  , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
+                               uiDefButF(block, NUM, B_CLOTH_RENEW, "G Min:",          10,30,150,20, &clmd->sim_parms.mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
+                               uiDefButF(block, NUM, B_CLOTH_RENEW, "G Max:",          160,30,150,20, &clmd->sim_parms.maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
                        }
                        uiBlockEndAlign(block); 
                        
@@ -3219,6 +3230,9 @@ static void object_panel_cloth_II(Object *ob)
                        if(uiNewPanel(curarea, block, "Cloth Cache", "Physics", 651, 0, 318, 204)==0) return;
                
                        uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
+                       
+                       uiDefButI(block, NUM, B_CLOTH_RENEW, "First Frame:",            10,160,150,20, &clmd->sim_parms.firstframe, 0, MAXFRAME, 1, 0, "Frame on which the simulation starts");
+                       uiDefButI(block, NUM, B_CLOTH_RENEW, "Last Frame:",             160,160,150,20, &clmd->sim_parms.lastframe, 0, MAXFRAME, 10, 0, "Frame on which the simulation stops");
 
                        if(clmd->sim_parms.cache)
                        {
@@ -3230,17 +3244,17 @@ static void object_panel_cloth_II(Object *ob)
                                else
                                        sprintf (str, "Frame %d cached. [%d in preroll, %d in total]", length-clmd->sim_parms.preroll, clmd->sim_parms.preroll, length);
                                
-                               uiDefBut(block, LABEL, 0, str,  10,160,290,20, NULL, 0.0, 0, 0, 0, "");
-                               uiDefBut(block, LABEL, 0, "Clear cache:",  10,140,290,20, NULL, 0.0, 0, 0, 0, "");
+                               uiDefBut(block, LABEL, 0, str,  10,140,290,20, NULL, 0.0, 0, 0, 0, "");
+                               uiDefBut(block, LABEL, 0, "Clear cache:",  10,120,290,20, NULL, 0.0, 0, 0, 0, "");
                                uiBlockBeginAlign (block);
-                               uiDefBut(block, BUT, B_CLOTH_CLEARCACHEALL, "All", 10, 120,145,20, NULL, 0.0, 0.0, 0, 0, "Free cloth cache without preroll");
-                               uiDefBut(block, BUT, B_CLOTH_CLEARCACHEFRAME, "From next frame", 155, 120,145,20, NULL, 0.0, 0.0, 0, 0, "Free cloth cache");    
+                               uiDefBut(block, BUT, B_CLOTH_CLEARCACHEALL, "All", 10, 100,145,20, NULL, 0.0, 0.0, 0, 0, "Free cloth cache without preroll");
+                               uiDefBut(block, BUT, B_CLOTH_CLEARCACHEFRAME, "From next frame", 155, 100,145,20, NULL, 0.0, 0.0, 0, 0, "Free cloth cache");    
                                if(length>1) // B_CLOTH_CHANGEPREROLL
-                                       uiDefButI(block, NUM, B_CLOTH_CHANGEPREROLL, "Preroll:", 10,100,145,20, &clmd->sim_parms.preroll, 0, length-1, 1, 0, "Simulation starts on this frame");
+                                       uiDefButI(block, NUM, B_CLOTH_CHANGEPREROLL, "Preroll:", 10,80,145,20, &clmd->sim_parms.preroll, 0, length-1, 1, 0, "Simulation starts on this frame");
                        }
                        else
                        {
-                               uiDefBut(block, LABEL, 0, "No frames cached.",  10,140,290,20, NULL, 0.0, 0, 0, 0, "");
+                               uiDefBut(block, LABEL, 0, "No frames cached.",  10,120,290,20, NULL, 0.0, 0, 0, 0, "");
                        }
                        uiBlockEndAlign(block);
                }
@@ -3271,7 +3285,7 @@ static void object_panel_cloth_III(Object *ob)
                        
                        uiBlockBeginAlign(block);
                        // uiDefBut(block, LABEL, 0, "",10,10,300,20, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
-                       uiDefButF(block, NUM, B_DIFF, "Min Distance:",     10,10,150,20, &clmd->coll_parms.epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "Min Distance:",      10,10,150,20, &clmd->coll_parms.epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in");
                        uiDefBut(block, LABEL, 0, "",160,10,150,20, NULL, 0.0, 0, 0, 0, "");
                        uiBlockEndAlign(block);
                }
index fcfb1a5c40f4ddd05068bd1a59342a21b4ed1747..0874f4c33429805c39a79215eea226254d99b9ef 100644 (file)
@@ -65,6 +65,7 @@
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_depsgraph.h"
+#include "BKE_cloth.h"
 #include "BKE_customdata.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
@@ -72,6 +73,7 @@
 #include "BKE_main.h"
 #include "BKE_material.h"
 #include "BKE_mesh.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
@@ -1312,7 +1314,11 @@ void load_editMesh(void)
        if(me->id.us>1) {
                Base *base;
                for(base= G.scene->base.first; base; base= base->next) {
-                       if(base->object->data==me) {
+                       if(base->object->data==me) {                            
+                               if(modifiers_isClothEnabled(base->object)) {
+                                       cloth_free_modifier(modifiers_isClothEnabled(base->object));
+                               }
+                               
                                base->object->softflag |= OB_SB_REDO;
                                base->object->recalc |= OB_RECALC_DATA;
                        }
index 44b937896903f32d2c548e5790af1c269370440f..81a111e62c2b0f4ddfb2d0ae6ff699d7129fc422 100644 (file)
@@ -1746,6 +1746,10 @@ void exit_editmode(int flag)     /* freedata==0 at render, 1= freedata, 2= do undo b
                sbObjectToSoftbody(ob);
        }
        
+       if(modifiers_isClothEnabled(ob)) {
+               cloth_free_modifier(modifiers_isClothEnabled(ob));
+       }
+       
        if(ob->type==OB_MESH && get_mesh(ob)->mr)
                multires_edge_level_update(ob, get_mesh(ob));
        
index 2fdf68951b85a82fbfbf6e21861e4faee0005112..12c1265e7cad2d28682a698dc5621fe1d5b4c2c6 100644 (file)
@@ -75,6 +75,7 @@
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_blender.h"
+#include "BKE_cloth.h"
 #include "BKE_curve.h"
 #include "BKE_constraint.h"
 #include "BKE_depsgraph.h"
@@ -2414,7 +2415,7 @@ void autokeyframe_pose_cb_func(Object *ob, int tmode, short targetless_ik)
        }
 }
 
-/* inserting keys, refresh ipo-keys, softbody, redraw events... (ton) */
+/* inserting keys, refresh ipo-keys, softbody, cloth, redraw events... (ton) */
 /* note; transdata has been freed already! */
 void special_aftertrans_update(TransInfo *t)
 {
@@ -2476,13 +2477,15 @@ void special_aftertrans_update(TransInfo *t)
        }
        else {
                base= FIRSTBASE;
-               while(base) {   
-                       
+               while(base) {                                           
                        if(base->flag & BA_DO_IPO) redrawipo= 1;
                        
                        ob= base->object;
 
                        if(modifiers_isSoftbodyEnabled(ob)) ob->softflag |= OB_SB_REDO;
+                       else if(modifiers_isClothEnabled(ob)) {
+                               cloth_free_modifier(modifiers_isClothEnabled(ob));
+                       }
                        
                        /* Set autokey if necessary */
                        if ((!cancelled) && (base->flag & SELECT)){
index 8e92fdda38abea9c42bf33f7da47dbf088b2faf3..ae65b1d9fa61af02dd8c79842f028492869a28be 100644 (file)
@@ -67,6 +67,7 @@
 #include "BKE_action.h"
 #include "BKE_anim.h"
 #include "BKE_armature.h"
+#include "BKE_cloth.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
@@ -313,8 +314,16 @@ void recalcData(TransInfo *t)
                        /* bah, softbody exception... recalcdata doesnt reset */
                        for(base= FIRSTBASE; base; base= base->next) {
                                if(base->object->recalc & OB_RECALC_DATA)
+                               {                                       
+                                       ClothModifierData *clmd = NULL;
+                                       
                                        if(modifiers_isSoftbodyEnabled(base->object)) {
                                                base->object->softflag |= OB_SB_REDO;
+                                       }
+                                       else if(modifiers_isClothEnabled(ob)) {
+                                               cloth_free_modifier(modifiers_isClothEnabled(ob));
+                                       }
+                                       
                                }
                        }
                }
@@ -347,10 +356,17 @@ void recalcData(TransInfo *t)
                                }                               
                        }
                        
-                       /* softbody exception */
-                       if(modifiers_isSoftbodyEnabled(ob)) {
-                               if(ob->recalc & OB_RECALC_DATA)
-                                       ob->softflag |= OB_SB_REDO;
+                       /* softbody & cloth exception */
+                       if(ob->recalc & OB_RECALC_DATA)
+                       {
+                               ClothModifierData *clmd = NULL;
+                               
+                               if(modifiers_isSoftbodyEnabled(ob)) {
+                                               ob->softflag |= OB_SB_REDO;
+                               }
+                               else if(modifiers_isClothEnabled(ob)) {
+                                       cloth_free_modifier(modifiers_isClothEnabled(ob));
+                               }
                        }
                        
                        /* proxy exception */
index 2f82cd2e2b2a758c1ba0f2d5b1eb0f955ee9ba4a..102aa79d47eefaaa79f6419c30d2fceef169754a 100644 (file)
@@ -64,6 +64,7 @@
 
 #include "BKE_armature.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_cloth.h"
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
 #include "BKE_deform.h"
@@ -1346,6 +1347,11 @@ void weight_paint(void)
        /* this flag is event for softbody to refresh weightpaint values */
        if(ob->soft) ob->softflag |= OB_SB_REDO;
        
+       // same goes for cloth
+       if(modifiers_isClothEnabled(ob)) {
+               cloth_free_modifier(modifiers_isClothEnabled(ob));
+       }       
+       
        BIF_undo_push("Weight Paint");
        allqueue(REDRAWVIEW3D, 0);
 }