diff options
-rw-r--r-- | source/blender/blenkernel/intern/cloth.c | 16 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collision.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/kdop.c | 24 |
3 files changed, 25 insertions, 30 deletions
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index d2834571316..a58fdab8c91 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -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); diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index a1c49ac4655..f2200a24ea2 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -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 diff --git a/source/blender/blenkernel/intern/kdop.c b/source/blender/blenkernel/intern/kdop.c index 69b205a0ec6..9fb476614d3 100644 --- a/source/blender/blenkernel/intern/kdop.c +++ b/source/blender/blenkernel/intern/kdop.c @@ -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; |