Cloth bugfix for jumpy cloth (users were complaining), so the mass can be changed...
authorDaniel Genrich <daniel.genrich@gmx.net>
Thu, 6 Mar 2008 01:21:40 +0000 (01:21 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Thu, 6 Mar 2008 01:21:40 +0000 (01:21 +0000)
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/collision.c
source/blender/blenkernel/intern/implicit.c
source/blender/src/buttons_object.c

index ee857805fb5137e3a70a4c59645477dfca80d1b5..f312a33197558b75a233bc9d35d245891776b1ba 100644 (file)
@@ -970,9 +970,7 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
                     (clmd->sim_parms->vgroup_bend>0)))
        {
                for ( i = 0; i < numverts; i++, verts++ )
-               {
-                       verts->mass = 1.0; // standard mass
-                       
+               {       
                        dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT );
                        if ( dvert )
                        {
@@ -1029,6 +1027,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
        float tnull[3] = {0,0,0};
        int cache_there = 0;
        Cloth *cloth = NULL;
+       MFace *mfaces = NULL;
 
        // If we have a clothObject, free it. 
        if ( clmd->clothObject != NULL )
@@ -1091,7 +1090,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
                }
                
                /* no GUI interface yet */
-               verts->mass = clmd->sim_parms->mass = 1.0f;
+               verts->mass = clmd->sim_parms->mass; 
+               verts->impulse_count = 0;
 
                if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )
                        verts->goal= clmd->sim_parms->defgoal;
index 65583a6c9c4273b889429fcbf0bd8410469a5ce5..f9391a0adb8860d2462ce3a944a77b5bd53d7469 100644 (file)
@@ -399,7 +399,7 @@ int cloth_get_collision_time(float a[3], float b[3], float c[3], float d[3], flo
 }
 
 // w3 is not perfect
-void cloth_compute_barycentric (float pv[3], float p1[3], float p2[3], float p3[3], float *w1, float *w2, float *w3)
+void collision_compute_barycentric (float pv[3], float p1[3], float p2[3], float p3[3], float *w1, float *w2, float *w3)
 {
        double  tempV1[3], tempV2[3], tempV4[3];
        double  a,b,c,d,e,f;
@@ -434,7 +434,7 @@ void cloth_compute_barycentric (float pv[3], float p1[3], float p2[3], float p3[
        w3[0] = 1.0f - w1[0] - w2[0];
 }
 
-DO_INLINE void interpolateOnTriangle(float to[3], float v1[3], float v2[3], float v3[3], double w1, double w2, double w3) 
+DO_INLINE void collision_interpolateOnTriangle(float to[3], float v1[3], float v2[3], float v3[3], double w1, double w2, double w3) 
 {
        to[0] = to[1] = to[2] = 0;
        VECADDMUL(to, v1, w1);
@@ -461,23 +461,23 @@ int cloth_collision_response_static(ClothModifierData *clmd, CollisionModifierDa
                collpair = search->link;
                
                // compute barycentric coordinates for both collision points
-               cloth_compute_barycentric(collpair->pa,
+               collision_compute_barycentric(collpair->pa,
                                          cloth1->verts[collpair->ap1].txold,
        cloth1->verts[collpair->ap2].txold,
        cloth1->verts[collpair->ap3].txold, 
        &w1, &w2, &w3);
                
                // was: txold
-               cloth_compute_barycentric(collpair->pb,
+               collision_compute_barycentric(collpair->pb,
                                          collmd->current_x[collpair->bp1].co,
                                        collmd->current_x[collpair->bp2].co,
                                        collmd->current_x[collpair->bp3].co,
                                        &u1, &u2, &u3);
        
                // Calculate relative "velocity".
-               interpolateOnTriangle(v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3);
+               collision_interpolateOnTriangle(v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3);
                
-               interpolateOnTriangle(v2, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, collmd->current_v[collpair->bp3].co, u1, u2, u3);
+               collision_interpolateOnTriangle(v2, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, collmd->current_v[collpair->bp3].co, u1, u2, u3);
                
                VECSUB(relativeVelocity, v2, v1);
                        
index 96c3c33afb86e3d16a705b3777d990bea05bf0d6..cd4c4ca1d5bd9ad35f0f6f92229cc67dd2173abe 100644 (file)
@@ -1669,6 +1669,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
                        VECCOPY(verts[i].v, id->V[i]);
                }
        }
+       
        return 1;
 }
 
index fa817d4b5794f0979ae8eb92cff6bff75f9174ef..f53812a0697491c020aa6d4bdf4e6038b0016843 100644 (file)
@@ -5133,36 +5133,41 @@ static void cloth_presets_material(void *ob_v, void *arg2)
        
        if(clmd->sim_parms->presets==1) /* SILK */
        {
-               clmd->sim_parms->structural = clmd->sim_parms->shear = 30.0;
-               clmd->sim_parms->bending = 0.1;
+               clmd->sim_parms->structural = clmd->sim_parms->shear = 5.0;
+               clmd->sim_parms->bending = 0.05;
                clmd->sim_parms->Cdis = 0.0;
+               clmd->sim_parms->mass = 0.15;
        }
        else if(clmd->sim_parms->presets==2) /* COTTON */
        {
-               clmd->sim_parms->structural = clmd->sim_parms->shear = 30.0;
-               clmd->sim_parms->bending = 1.0;
+               clmd->sim_parms->structural = clmd->sim_parms->shear = 15.0;
+               clmd->sim_parms->bending = 0.5;
                clmd->sim_parms->Cdis = 5.0;
+               clmd->sim_parms->mass = 0.3;
        }
        else if(clmd->sim_parms->presets==3) /* RUBBER */
        {
-               clmd->sim_parms->structural = clmd->sim_parms->shear = 5.0;
+               clmd->sim_parms->structural = clmd->sim_parms->shear = 15.0;
                clmd->sim_parms->bending = 25.0;
                clmd->sim_parms->Cdis = 25.0;
                clmd->sim_parms->stepsPerFrame = MAX2(clmd->sim_parms->stepsPerFrame, 7.0);
+               clmd->sim_parms->mass = 3.0;
        }
        else if(clmd->sim_parms->presets==4) /* DENIM */
        {
-               clmd->sim_parms->structural = clmd->sim_parms->shear = 70.0;
-               clmd->sim_parms->bending = 300.0;
+               clmd->sim_parms->structural = clmd->sim_parms->shear = 40.0;
+               clmd->sim_parms->bending = 10.0;
                clmd->sim_parms->Cdis = 25.0;
-               clmd->sim_parms->stepsPerFrame = MAX2(clmd->sim_parms->stepsPerFrame, 15.0);
+               clmd->sim_parms->stepsPerFrame = MAX2(clmd->sim_parms->stepsPerFrame, 12.0);
+               clmd->sim_parms->mass = 1.0;
        }
        else if(clmd->sim_parms->presets==5) /* LEATHER */
        {
-               clmd->sim_parms->structural = clmd->sim_parms->shear = 1000.0;
-               clmd->sim_parms->bending = 2500.0;
+               clmd->sim_parms->structural = clmd->sim_parms->shear = 80.0;
+               clmd->sim_parms->bending = 150.0;
                clmd->sim_parms->Cdis = 25.0;
-               clmd->sim_parms->stepsPerFrame = MAX2(clmd->sim_parms->stepsPerFrame, 25.0);
+               clmd->sim_parms->stepsPerFrame = MAX2(clmd->sim_parms->stepsPerFrame, 15.0);
+               clmd->sim_parms->mass = 0.4;
        }
 }
 
@@ -5241,6 +5246,8 @@ static void object_panel_cloth(Object *ob)
                
                uiDefButI(block, NUM, B_CLOTH_RENEW, "Quality:", 10,110,150,20, &clmd->sim_parms->stepsPerFrame, 4.0, 80.0, 5, 0, "Quality of the simulation (higher=better=slower)");
                
+               uiDefButF(block, NUM, B_CLOTH_RENEW, "Mass:", 160,110,150,20, &clmd->sim_parms->mass, 0.0, 10.0, 1000, 0, "Mass of cloth material.");
+               
                uiDefBut(block, LABEL, 0, "Gravity:",  10,90,60,20, NULL, 0.0, 0, 0, 0, "");
                
                uiDefButF(block, NUM, B_CLOTH_RENEW, "X:", 70,90,80,20, &clmd->sim_parms->gravity[0], -100.0, 100.0, 10, 0, "Apply gravitation to point movement");
@@ -5408,7 +5415,7 @@ static void object_panel_cloth_II(Object *ob)
                if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)
                {
                        uiDefButF(block, NUM, B_CLOTH_RENEW, "Min Distance:",      160,60,150,20, &clmd->coll_parms->epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in, can be changed for each frame");
-                       uiDefButS(block, NUM, B_CLOTH_RENEW, "Collision Quality:",         10,40,150,20, &clmd->coll_parms->loop_count, 1.0, 20.0, 1.0, 0, "How many collision iterations should be done. (higher = better = slower), can be changed for each frame");
+                       uiDefButS(block, NUM, B_CLOTH_RENEW, "Collision Quality:",         10,40,150,20, &clmd->coll_parms->loop_count, 1.0, 20.0, 1.0, 0, "How many collision iterations should be done. (higher = better = slower)");
                        uiDefButF(block, NUM, B_CLOTH_RENEW, "Friction:",          160,40,150,20, &clmd->coll_parms->friction, 0.0, 80.0, 1.0, 0, "Friction force if a collision happened (0=movement not changed, 100=no movement left)");
                        
                        uiDefButBitI(block, TOG, CLOTH_COLLSETTINGS_FLAG_SELF, B_CLOTH_RENEW, "Enable selfcollisions",  10,20,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable selfcollisions with this object");