Cloth structure names update: Sorry about this commit, it will kill all your cloth...
authorDaniel Genrich <daniel.genrich@gmx.net>
Thu, 20 Mar 2008 18:28:40 +0000 (18:28 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Thu, 20 Mar 2008 18:28:40 +0000 (18:28 +0000)
source/blender/blenkernel/BKE_collision.h
source/blender/blenkernel/intern/collision.c
source/blender/blenkernel/intern/implicit.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/makesdna/DNA_cloth_types.h
source/blender/makesdna/DNA_modifier_types.h

index 463254b8e4f565ee7598cfc040c27f54c8c8d08c..3889721b8c925183cdeb0b1c099443a9c4c107a4 100644 (file)
@@ -172,7 +172,8 @@ void bvh_free ( BVH * bvh );
 // checks two bounding volume hierarchies for potential collisions and returns some list with those
 
 
-// update bounding volumes, needs updated positions in bvh->x
+// update bounding volumes, needs updated positions in  bvh->current_xold (static) 
+// and also bvh->current_x if moving==1
 void bvh_update_from_mvert(BVH * bvh, MVert *x, unsigned int numverts, MVert *xnew, int moving);
 void bvh_update(BVH * bvh, int moving);
 
index ef69da0ed8617bb2448b739294272945e35a952f..403762e36bf92f0c7c715bd4b7b82201a991d2b1 100644 (file)
@@ -427,6 +427,7 @@ int cloth_collision_response_static(ClothModifierData *clmd, CollisionModifierDa
        float w1, w2, w3, u1, u2, u3;
        float v1[3], v2[3], relativeVelocity[3];
        float magrelVel;
+       float epsilon2 = collmd->bvh->epsilon;
        
        cloth1 = clmd->clothObject;
 
@@ -510,7 +511,7 @@ int cloth_collision_response_static(ClothModifierData *clmd, CollisionModifierDa
                        
                        // Apply repulse impulse if distance too short
                        // I_r = -min(dt*kd, m(0,1d/dt - v_n))
-                       d = clmd->coll_parms->epsilon*8.0/9.0 - collpair->distance;
+                       d = clmd->coll_parms->epsilon*8.0/9.0 + epsilon2*8.0/9.0 - collpair->distance;
                        if((magrelVel < 0.1*d*clmd->sim_parms->stepsPerFrame) && (d > ALMOST_ZERO))
                        {
                                repulse = MIN2(d*1.0/clmd->sim_parms->stepsPerFrame, 0.1*d*clmd->sim_parms->stepsPerFrame - magrelVel);
@@ -557,6 +558,7 @@ void cloth_collision_static(ModifierData *md1, ModifierData *md2, CollisionTree
        ClothVertex *verts1=NULL;
        double distance = 0;
        float epsilon = clmd->coll_parms->epsilon;
+       float epsilon2 = ((CollisionModifierData *)md2)->bvh->epsilon;
        unsigned int i = 0;
 
        for(i = 0; i < 4; i++)
@@ -641,9 +643,9 @@ void cloth_collision_static(ModifierData *md1, ModifierData *md2, CollisionTree
                                        verts1[collpair->ap1].txold, verts1[collpair->ap2].txold, verts1[collpair->ap3].txold, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co, collpair->pa,collpair->pb,collpair->vector);
 #else
                        // just be sure that we don't add anything
-                       distance = 2.0 * (epsilon + ALMOST_ZERO);
+                       distance = 2.0 * (epsilon + epsilon2 + ALMOST_ZERO);
 #endif 
-                       if (distance <= (epsilon + ALMOST_ZERO))
+                       if (distance <= (epsilon + epsilon2 + ALMOST_ZERO))
                        {
                                // printf("dist: %f\n", (float)distance);
                                
@@ -968,10 +970,10 @@ int cloth_bvh_objcollisions_do(ClothModifierData * clmd, CollisionModifierData *
        
        verts = cloth->verts;
        
-       if (collmd->tree
+       if (collmd->bvh
        {
                /* get pointer to bounding volume hierarchy */
-               BVH *coll_bvh = collmd->tree;
+               BVH *coll_bvh = collmd->bvh;
                
                /* move object to position (step) in time */
                collision_move_object(collmd, step + dt, step);
@@ -991,7 +993,7 @@ int cloth_bvh_objcollisions_do(ClothModifierData * clmd, CollisionModifierData *
        {
                result = 0;
                                
-               if (collmd->tree
+               if (collmd->bvh
                        result += cloth_collision_response_static(clmd, collmd);
                                
                                // apply impulses in parallel
index f4b1a325712d899f99fce978363a05cd3ee70505..4c39f36800c0768fec5103bdbb1988ddadde6617 100644 (file)
 #include "DNA_cloth_types.h"   
 #include "DNA_scene_types.h"
 
-
 #include "BKE_effect.h"
 #include "BKE_global.h"
 #include "BKE_cloth.h"
 #include "BKE_utildefines.h"
 
-
 #ifdef _WIN32
 #include <windows.h>
 static LARGE_INTEGER _itstart, _itend;
index 358068d586850bfcb24b8cadb0be54bf52f0df9d..4aa69daa6d0606e5dc22a604338d4b467adb5abe 100644 (file)
@@ -5037,8 +5037,8 @@ static void clothModifier_initData(ModifierData *md)
 {
        ClothModifierData *clmd = (ClothModifierData*) md;
        
-       clmd->sim_parms = MEM_callocN(sizeof(SimulationSettings), "cloth sim parms");
-       clmd->coll_parms = MEM_callocN(sizeof(CollisionSettings), "cloth coll parms");
+       clmd->sim_parms = MEM_callocN(sizeof(ClothSimSettings), "cloth sim parms");
+       clmd->coll_parms = MEM_callocN(sizeof(ClothCollSettings), "cloth coll parms");
        
        /* check for alloc failing */
        if(!clmd->sim_parms || !clmd->coll_parms)
@@ -5055,7 +5055,12 @@ static DerivedMesh *clothModifier_applyModifier(ModifierData *md, Object *ob,
        
        /* check for alloc failing */
        if(!clmd->sim_parms || !clmd->coll_parms)
-               return derivedData;
+       {
+               clothModifier_initData(md);
+               
+               if(!clmd->sim_parms || !clmd->coll_parms)
+                       return derivedData;
+       }
 
        result = clothModifier_do(clmd, ob, derivedData, useRenderParams, isFinalCalc);
 
@@ -5090,7 +5095,7 @@ static void clothModifier_updateDepgraph(
                                }
                        }
                }
-       }       
+       }
 }
 
 CustomDataMask clothModifier_requiredDataMask(ModifierData *md)
@@ -5156,7 +5161,7 @@ static void collisionModifier_initData(ModifierData *md)
        collmd->current_v = NULL;
        collmd->time = -1;
        collmd->numverts = 0;
-       collmd->tree = NULL;
+       collmd->bvh = NULL;
 }
 
 static void collisionModifier_freeData(ModifierData *md)
@@ -5165,8 +5170,8 @@ static void collisionModifier_freeData(ModifierData *md)
        
        if (collmd) 
        {
-               if(collmd->tree)
-                       bvh_free(collmd->tree);
+               if(collmd->bvh)
+                       bvh_free(collmd->bvh);
                if(collmd->x)
                        MEM_freeN(collmd->x);
                if(collmd->xnew)
@@ -5188,7 +5193,7 @@ static void collisionModifier_freeData(ModifierData *md)
                collmd->current_v = NULL;
                collmd->time = -1;
                collmd->numverts = 0;
-               collmd->tree = NULL;
+               collmd->bvh = NULL;
                collmd->mfaces = NULL;
        }
 }
@@ -5258,7 +5263,7 @@ static void collisionModifier_deformVerts(
                                
                                // TODO: epsilon
                                // create bounding box hierarchy
-                               collmd->tree = bvh_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sbift);
+                               collmd->bvh = bvh_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sboft);
                                
                                collmd->time = current_time;
                        }
@@ -5281,14 +5286,14 @@ static void collisionModifier_deformVerts(
                                memcpy(collmd->current_x, collmd->x, numverts*sizeof(MVert));
                                
                                /* happens on file load (ONLY when i decomment changes in readfile.c */
-                               if(!collmd->tree)
+                               if(!collmd->bvh)
                                {
-                                       collmd->tree = bvh_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sbift);
+                                       collmd->bvh = bvh_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sboft);
                                }
                                else
                                {
                                        // recalc static bounding boxes
-                                       bvh_update_from_mvert(collmd->tree, collmd->current_x, numverts, NULL, 0);
+                                       bvh_update_from_mvert(collmd->bvh, collmd->current_x, numverts, NULL, 0);
                                }
                                
                                collmd->time = current_time;
index ee4cb66a6e043251b680325e9dbab223d2af3f86..330ae84f922da88550ffa07c984275d71ec71b98 100644 (file)
@@ -3051,11 +3051,14 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        clmd->sim_parms= newdataadr(fd, clmd->sim_parms);
                        clmd->coll_parms= newdataadr(fd, clmd->coll_parms);
                        
-                       clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_LOADED;
-                       clmd->sim_parms->flags &= ~CLOTH_SIMSETTINGS_FLAG_EDITMODE;
-                       
-                       if(clmd->sim_parms->presets > 10)
-                               clmd->sim_parms->presets = 0;
+                       if(clmd->sim_parms)
+                       {
+                               clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_LOADED;
+                               clmd->sim_parms->flags &= ~CLOTH_SIMSETTINGS_FLAG_EDITMODE;
+                               
+                               if(clmd->sim_parms->presets > 10)
+                                       clmd->sim_parms->presets = 0;
+                       }
                        
                }
                else if (md->type==eModifierType_Collision) {
@@ -3080,7 +3083,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        collmd->current_v = NULL;
                        collmd->time = -1;
                        collmd->numverts = 0;
-                       collmd->tree = NULL;
+                       collmd->bvh = NULL;
                        collmd->mfaces = NULL;
                        
                }
index a4c91d77f5e76305aac4a2e2cf0cfccb697155cc..7979dd0b33fbc895558d630a7479a654e0d7b226 100644 (file)
@@ -859,8 +859,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
                else if(md->type==eModifierType_Cloth) {
                        ClothModifierData *clmd = (ClothModifierData*) md;
                        
-                       writestruct(wd, DATA, "SimulationSettings", 1, clmd->sim_parms);
-                       writestruct(wd, DATA, "CollisionSettings", 1, clmd->coll_parms);
+                       writestruct(wd, DATA, "ClothSimSettings", 1, clmd->sim_parms);
+                       writestruct(wd, DATA, "ClothCollSettings", 1, clmd->coll_parms);
                        
                } 
                else if (md->type==eModifierType_Collision) {
index 4ba1f4f02e868c4bf637d29cc08b43876cce5230..53fbd1ff72cb2381fa2427fb6ef7970a9c0f9998 100644 (file)
@@ -44,7 +44,8 @@
 * as in stepsPerFrame comapred to the time step in the paper, I've used
 * variables with different names to minimize confusion.
 **/
-typedef struct SimulationSettings
+
+typedef struct ClothSimSettings
 {
        short   vgroup_mass;    /* optional vertexgroup name for assigning weight.*/
        short   vgroup_struct;  /* vertex group for scaling structural stiffness */
@@ -87,10 +88,10 @@ typedef struct SimulationSettings
        short pad;
        int pad2;
 }
-SimulationSettings;
+ClothSimSettings;
 
 
-typedef struct CollisionSettings
+typedef struct ClothCollSettings
 {
        float   epsilon;                /* min distance for collisions.         */
        float   self_friction;          /* Fiction/damping with self contact.                   */
@@ -101,7 +102,7 @@ typedef struct CollisionSettings
        int     flags;                  /* collision flags defined in BKE_cloth.h */
        float   selfepsilon;            /* for selfcollision */
 }
-CollisionSettings;
+ClothCollSettings;
 
 
 /**
index dd1d8eb01b3bf3539b136c7bb4e7914af586cb7a..c62d012643a47b3f7a6d972afe3259b7fff11606 100644 (file)
@@ -369,8 +369,8 @@ typedef struct ClothModifierData {
    ModifierData                modifier;
 
    struct Cloth *clothObject; /* The internal data structure for cloth. */
-   struct SimulationSettings *sim_parms; /* definition is in DNA_cloth_types.h */
-   struct CollisionSettings *coll_parms; /* definition is in DNA_cloth_types.h */
+   struct ClothSimSettings *sim_parms; /* definition is in DNA_cloth_types.h */
+   struct ClothCollSettings *coll_parms; /* definition is in DNA_cloth_types.h */
 } ClothModifierData;
 
 typedef struct CollisionModifierData {
@@ -381,15 +381,15 @@ typedef struct CollisionModifierData {
        struct MVert *xold; /* unsued atm, but was discussed during sprint */
        struct MVert *current_xnew; /* new position at the actual inter-frame step */
        struct MVert *current_x; /* position at the actual inter-frame step */
-       struct MVert *current_v; /* position at the actual inter-frame step */
+       struct MVert *current_v; /* (xnew - x) at the actual inter-frame step */
        
        struct MFace *mfaces; /* object face data */
        
        unsigned int numverts;
        unsigned int numfaces;
        int pad;
-       float time;
-       struct BVH *tree;       /* collision tree for this cloth object */
+       float time;             /* cfra time of modifier */
+       struct BVH *bvh;        /* bounding volume hierarchy for this cloth object */
 } CollisionModifierData;
 
 typedef enum {