bvh nodes got parent node reference again

This commit is contained in:
Daniel Genrich
2008-09-05 11:55:39 +00:00
parent e8621cf05e
commit b32036f5d6

View File

@@ -51,6 +51,7 @@
typedef struct BVHNode
{
struct BVHNode **children;
struct BVHNode *parent; // some user defined traversed need that
float *bv; // Bounding volume of all nodes, max 13 axis
int index; // face, edge, vertex index
char totnode; // how many nodes are used, used for speedup
@@ -700,6 +701,10 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array,
BVHBuildHelper data;
int depth;
// set parent from root node to NULL
BVHNode *tmp = branches_array+0;
tmp->parent = NULL;
//Most of bvhtree code relies on 1-leaf trees having at least one branch
//We handle that special case here
@@ -709,7 +714,8 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array,
refit_kdop_hull(tree, root, 0, num_leafs);
root->main_axis = get_largest_axis(root->bv) / 2;
root->totnode = 1;
root->children[0] = leafs_array[0];
root->children[0] = leafs_array[0];
root->children[0]->parent = root;
return;
}
@@ -772,9 +778,15 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array,
int child_leafs_end = implicit_leafs_index(&data, depth+1, child_level_index+1);
if(child_leafs_end - child_leafs_begin > 1)
{
parent->children[k] = branches_array + child_index;
parent->children[k]->parent = parent;
}
else if(child_leafs_end - child_leafs_begin == 1)
{
parent->children[k] = leafs_array[ child_leafs_begin ];
parent->children[k]->parent = parent;
}
else
break;