Revision: 14953
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14953
Author:   genscher
Date:     2008-05-25 15:15:54 +0200 (Sun, 25 May 2008)

Log Message:
-----------
-== Cloth / kdop ==-
1. Bugfix for crash on enabling cloth on object
2. Correcting kdop nth element sorting function (fix provided by Andr?\195?\169 
Pinto)

Modified Paths:
--------------
    branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
    branches/cloth/blender/source/blender/blenlib/intern/BLI_kdopbvh.c

Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c     
2008-05-24 22:50:31 UTC (rev 14952)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c     
2008-05-25 13:15:54 UTC (rev 14953)
@@ -210,11 +210,11 @@
        mfaces = cloth->mfaces;
        
        // in the moment, return zero if no faces there
-       if(!cloth->numfaces)
+       if(!cloth->numverts)
                return NULL;
        
        // create quadtree with k=26
-       bvhtree = BLI_bvhtree_new(cloth->numfaces, epsilon, 4, 6);
+       bvhtree = BLI_bvhtree_new(cloth->numverts, epsilon, 4, 6);
        
        // fill tree
        for(i = 0; i < cloth->numverts; i++, verts++)

Modified: branches/cloth/blender/source/blender/blenlib/intern/BLI_kdopbvh.c
===================================================================
--- branches/cloth/blender/source/blender/blenlib/intern/BLI_kdopbvh.c  
2008-05-24 22:50:31 UTC (rev 14952)
+++ branches/cloth/blender/source/blender/blenlib/intern/BLI_kdopbvh.c  
2008-05-25 13:15:54 UTC (rev 14953)
@@ -276,21 +276,22 @@
 }
 
 //after a call to this function you can expect one of:
-//     every node to left of a[n] are smaller than it
-//     every node to the right of a[n-1] are greater than it
-void partition_nth_element(BVHNode **a, int _begin, int _end, int n, int axis)
-{
-       int begin = _begin, end = _end;
-       while(begin < n && end >= n)
-       {
-               int mid = bvh_partition(a, begin, end, bvh_medianof3(a, begin, 
(begin+end-1)/2, end-1, axis), axis );
+//      every node to left of a[n] are smaller or equal to it
+//      every node to the right of a[n] are greater or equal to it
+int partition_nth_element(BVHNode **a, int _begin, int _end, int n, int axis){ 
       
+       int begin = _begin, end = _end, cut;        
+       int i;         
+       while(end-begin > 3)        
+       {                            
+               cut = bvh_partition(a, begin, end, bvh_medianof3(a, begin, 
(begin+end)/2, end-1, axis), axis );                 
+               if(cut <= n)                        
+                       begin = cut;                
+               else                        
+                       end = cut;        
+       }        
+       bvh_insertionsort(a, begin, end, axis);
 
-               if(mid >= n)
-                       end = n-1;
-               else
-                       begin = n+1;
-       }
-
+       return n;
 }
 
 
@@ -550,7 +551,8 @@
                        tree->totbranch++;
                        tnode->parent = node;
                        
-                       partition_nth_element(tree->nodes, start, end, tend, 
laxis);
+                       if(tend != end)
+                               partition_nth_element(tree->nodes, start, end, 
tend, laxis);
                        refit_kdop_hull(tree, tnode, start, tend);
                        bvh_div_nodes(tree, tnode, start, tend, laxis);
                }
@@ -707,7 +709,7 @@
 {
        int j, total = 0;
        BVHTreeOverlap *overlap = NULL, *to = NULL;
-       BVHOverlapData *data[tree1->tree_type];
+       BVHOverlapData **data;
        
        // check for compatibility of both trees (can't compare 14-DOP with 
18-DOP)
        if((tree1->axis != tree2->axis) && ((tree1->axis == 14) || tree2->axis 
== 14))
@@ -716,6 +718,8 @@
        // fast check root nodes for collision before doing big splitting + 
traversal
        if(!tree_overlap(tree1->nodes[tree1->totleaf]->bv, 
tree2->nodes[tree2->totleaf]->bv, MIN2(tree1->start_axis, tree2->start_axis), 
MIN2(tree1->stop_axis, tree2->stop_axis)))
                return 0;
+
+       *data = MEM_callocN(sizeof(BVHOverlapData *)* tree1->tree_type, 
"BVHOverlapData_star");
        
        for(j = 0; j < tree1->tree_type; j++)
        {
@@ -751,6 +755,7 @@
                free(data[j]->overlap);
                MEM_freeN(data[j]);
        }
+       MEM_freeN(*data);
        
        (*result) = total;
        return overlap;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to