Fixed read/writing of blendfiles with collision modifier (saving not supported itm...
authorDaniel Genrich <daniel.genrich@gmx.net>
Sun, 21 Oct 2007 16:53:25 +0000 (16:53 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sun, 21 Oct 2007 16:53:25 +0000 (16:53 +0000)
source/blender/blenkernel/BKE_collisions.h
source/blender/blenkernel/intern/kdop.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_modifier_types.h

index edd86f0f5f60521d8120d3308640a059e3921065..7c9ced262a8b31101dd708ba367728baea4d80ff 100644 (file)
@@ -64,8 +64,8 @@ typedef struct BVH
 {
        unsigned int    numfaces;
        unsigned int    numverts;
-       MVert           *x; // position of verts at time n 
-       MVert           *xold; // position of verts at time n-1
+       MVert           *xnew; // position of verts at time n 
+       MVert           *x; // position of verts at time n-1
        MFace           *mfaces; // just a pointer to the original datastructure
        struct LinkNode *tree;
        TreeNode        *root; // TODO: saving the root --> is this really needed? YES!
index 8b2540c7d8ad4b2b6d41d73b370b527a657e7907..1e17ee4f03eb4915292ab5cb6a6d05ebf970c509 100644 (file)
@@ -387,7 +387,7 @@ void bvh_calc_DOP_hull_from_faces(BVH * bvh, Tree **tri, int numfaces, float *bv
 
 void bvh_calc_DOP_hull_static(BVH * bvh, Tree **tri, int numfaces, float *bv)
 {
-       MVert *tempMVert = bvh->xold;
+       MVert *tempMVert = bvh->x;
        MFace *tempMFace = bvh->mfaces;
        float *tempBV = bv;
        float newminmax;
@@ -426,8 +426,8 @@ void bvh_calc_DOP_hull_static(BVH * bvh, Tree **tri, int numfaces, float *bv)
 
 void bvh_calc_DOP_hull_moving(BVH * bvh, Tree **tri, int numfaces, float *bv)
 {
-       MVert *tempMVert = bvh->xold;
-       MVert *tempMVert2 = bvh->x;
+       MVert *tempMVert = bvh->x;
+       MVert *tempMVert2 = bvh->xnew;
        MFace *tempMFace = bvh->mfaces;
        float *tempBV = bv;
        float newminmax;
@@ -538,7 +538,7 @@ static void bvh_div_env_node(BVH * bvh, TreeNode *tree, Tree **face_list, unsign
        return;
 }
 
-BVH *bvh_build (DerivedMesh *dm, MVert *x, MVert *xold, unsigned int numverts, float epsilon)
+BVH *bvh_build (DerivedMesh *dm, MVert *x, MVert *xnew, unsigned int numverts, float epsilon)
 {
        unsigned int i = 0, j = 0, k = 0;
        Tree **face_list=NULL;
@@ -569,8 +569,8 @@ BVH *bvh_build (DerivedMesh *dm, MVert *x, MVert *xold, unsigned int numverts, f
        mface = bvh->mfaces = dm->getFaceArray(dm);
 
        bvh->numverts = numverts;
+       bvh->xnew = xnew;       
        bvh->x = x;     
-       bvh->xold = xold;       
        tree = (Tree *)MEM_callocN(sizeof(Tree), "Tree");
        // TODO: check succesfull alloc
        BLI_linklist_append(&bvh->tree, tree);
@@ -774,7 +774,7 @@ void bvh_join(Tree * tree)
 }
 
 // update static bvh
-// needs new positions in bvh->x, bvh->xold
+// needs new positions in bvh->x, bvh->xnew
 void bvh_update(DerivedMesh *dm, BVH * bvh, int moving)
 {
        TreeNode *leaf, *parent;
index 59bd4b8253d049d45368b23c057d98d4da719c4b..cb7fccd11c125d3485b548c3036ee62dae71e4d8 100644 (file)
@@ -4956,7 +4956,7 @@ static void collisionModifier_initData(ModifierData *md)
        CollisionModifierData *collmd = (CollisionModifierData*) md;
        
        collmd->x = NULL;
-       collmd->xold = NULL;
+       collmd->xnew = NULL;
        collmd->time = -1;
        collmd->numverts = 0;
        collmd->tree = NULL;
@@ -4972,11 +4972,11 @@ static void collisionModifier_freeData(ModifierData *md)
                        bvh_free(collmd->tree);
                if(collmd->x)
                        MEM_freeN(collmd->x);
-               if(collmd->xold)
-                       MEM_freeN(collmd->xold);
+               if(collmd->xnew)
+                       MEM_freeN(collmd->xnew);
                
                collmd->x = NULL;
-               collmd->xold = NULL;
+               collmd->xnew = NULL;
                collmd->time = -1;
                collmd->numverts = 0;
                collmd->tree = NULL;
@@ -5018,26 +5018,26 @@ static void collisionModifier_deformVerts(
                        if(collmd->time == -1) // first time
                        {
                                collmd->x = dm->dupVertArray(dm);
-                               collmd->xold = dm->dupVertArray(dm);
+                               collmd->xnew = dm->dupVertArray(dm);
                                collmd->numverts = numverts;
                                
                                // TODO: epsilon
                                // create bounding box hierarchy
-                               collmd->tree = bvh_build(dm, collmd->x, collmd->xold,  numverts, 0.01);
+                               collmd->tree = bvh_build(dm, collmd->x, collmd->xnew,  numverts, 0.01);
                        }
                        else if(numverts == collmd->numverts)
                        {
                                // put positions to old positions
-                               tempVert = collmd->xold;
-                               collmd->xold = collmd->x;
-                               collmd->x = tempVert;
+                               tempVert = collmd->x;
+                               collmd->x = collmd->xnew;
+                               collmd->xnew = tempVert;
                                
-                               memcpy(collmd->x, dm->getVertArray(dm), numverts*sizeof(MVert));
+                               memcpy(collmd->xnew, dm->getVertArray(dm), numverts*sizeof(MVert));
                                
                                for ( i = 0; i < numverts; i++ )
                                {
                                        // we save global positions
-                                       Mat4MulVecfl ( ob->obmat, collmd->x[i].co );
+                                       Mat4MulVecfl ( ob->obmat, collmd->xnew[i].co );
                                }
                                
                                bvh_update(dm, collmd->tree, 0); // recalc static bounding boxes
index 83bae60df306f09f4b6fb3fd9b66523632172a94..99f0885b43541aa6effecf83fdcc953e7238c323 100644 (file)
@@ -2888,6 +2888,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                          printf ("direct_link_modifiers: read cloth baked_data.\n");
                   }
                } 
+               else if (md->type==eModifierType_Collision) {
+                       CollisionModifierData *collmd = (CollisionModifierData*) md;
+                       
+                       collmd->x = NULL;
+                       collmd->xnew = NULL;
+                       collmd->time = -1;
+                       collmd->numverts = 0;
+                       collmd->tree = NULL;
+               }
                else if (md->type==eModifierType_Hook) {
                        HookModifierData *hmd = (HookModifierData*) md;
 
index e6e73ea7d0785c30ff9c7f7c771682d81839dd27..81e27afbac4463beaacfa52c1dd197fc5566abb1 100644 (file)
@@ -351,7 +351,7 @@ typedef struct CollisionModifierData {
        ModifierData            modifier;
        
        struct MVert *x;
-       struct MVert *xold;
+       struct MVert *xnew;
        
        unsigned int numverts;
        float time;