Collision Modifier/KDOP: Rearrange things to be more generic. Also fix possible crash...
authorDaniel Genrich <daniel.genrich@gmx.net>
Mon, 17 Mar 2008 21:45:40 +0000 (21:45 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Mon, 17 Mar 2008 21:45:40 +0000 (21:45 +0000)
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/collision.c
source/blender/blenkernel/intern/kdop.c

index d28345713165a99800260aad287b4936fefe7475..a58fdab8c91c391d556b61a3f5775f4a156fa871 100644 (file)
@@ -190,11 +190,6 @@ BVH *bvh_build_from_cloth (ClothModifierData *clmd, float epsilon)
        
        // springs = cloth->springs;
        // numsprings = cloth->numsprings;
-       
-       bvh->flags = 0;
-       bvh->leaf_tree = NULL;
-       bvh->leaf_root = NULL;
-       bvh->tree = NULL;
 
        bvh->epsilon = epsilon;
        bvh->numfaces = cloth->numfaces;
@@ -211,20 +206,9 @@ BVH *bvh_build_from_cloth (ClothModifierData *clmd, float epsilon)
                return NULL;
        }
        
-       bvh->current_xold = MEM_callocN ( sizeof ( MVert ) * bvh->numverts, "bvh->current_xold" );
-       
-       if (bvh->current_xold == NULL) 
-       {
-               printf("bvh: Out of memory.\n");
-               MEM_freeN(bvh->current_x);
-               MEM_freeN(bvh);
-               return NULL;
-       }
-       
        for(i = 0; i < bvh->numverts; i++)
        {
                VECCOPY(bvh->current_x[i].co, verts[i].tx);
-               VECCOPY(bvh->current_xold[i].co, verts[i].txold);
        }
        
        bvh_build (bvh);
index a1c49ac465526ca32a18d972dc9d9136f695d881..f2200a24ea25d1a74c0cb8238c2706032d98d1f3 100644 (file)
@@ -86,11 +86,6 @@ BVH *bvh_build_from_mvert (MFace *mfaces, unsigned int numfaces, MVert *x, unsig
        // in the moment, return zero if no faces there
        if(!numfaces)
                return NULL;
-       
-       bvh->flags = 0;
-       bvh->leaf_tree = NULL;
-       bvh->leaf_root = NULL;
-       bvh->tree = NULL;
 
        bvh->epsilon = epsilon;
        bvh->numfaces = numfaces;
@@ -103,8 +98,7 @@ BVH *bvh_build_from_mvert (MFace *mfaces, unsigned int numfaces, MVert *x, unsig
        }
 
        bvh->numverts = numverts;
-       bvh->current_x = MEM_dupallocN(x);      
-       bvh->current_xold = MEM_dupallocN(x);   
+       bvh->current_x = MEM_dupallocN(x);
        
        bvh_build(bvh);
        
@@ -975,10 +969,13 @@ int cloth_bvh_objcollisions_do(ClothModifierData * clmd, CollisionModifierData *
        
        if (collmd->tree) 
        {
+               /* get pointer to bounding volume hierarchy */
                BVH *coll_bvh = collmd->tree;
-                               
+               
+               /* move object to position (step) in time */
                collision_move_object(collmd, step + dt, step);
-                                       
+               
+               /* search for overlapping collision pairs */
                bvh_traverse((ModifierData *)clmd, (ModifierData *)collmd, cloth_bvh->root, coll_bvh->root, step, cloth_collision_static, 0);
        }
        else
index 69b205a0ec6daa57c2a97a4a302b93d0e3ea4e87..9fb476614d33f69c40d6ce5405b26486dce58308 100644 (file)
@@ -538,18 +538,32 @@ void bvh_build (BVH *bvh)
        CollisionTree *tree=NULL;
        LinkNode *nlink = NULL;
        
+       bvh->flags = 0;
+       bvh->leaf_tree = NULL;
+       bvh->leaf_root = NULL;
+       bvh->tree = NULL;
+       
+       if(!bvh->current_x)
+       {
+               bvh_free(bvh);
+               return;
+       }
+       
+       bvh->current_xold = MEM_dupallocN(bvh->current_x);
+       
        tree = (CollisionTree *)MEM_callocN(sizeof(CollisionTree), "CollisionTree");
-       // TODO: check succesfull alloc
-       BLI_linklist_append(&bvh->tree, tree);
-
-       nlink = bvh->tree;
-
+       
        if (tree == NULL) 
        {
                printf("bvh_build: Out of memory for nodes.\n");
                bvh_free(bvh);
                return;
        }
+       
+       BLI_linklist_append(&bvh->tree, tree);
+
+       nlink = bvh->tree;
+
        bvh->root = bvh->tree->link;
        bvh->root->isleaf = 0;
        bvh->root->parent = NULL;