//stackless refit protected void Refit() { int nodecount = GetNodeCount(); while (nodecount-- != 0) { if (IsLeafNode(nodecount)) { AABB leafbox; m_primitive_manager.GetPrimitiveBox(GetNodeData(nodecount), out leafbox); SetNodeBound(nodecount, ref leafbox); } else { //const GIM_BVH_TREE_NODE * nodepointer = get_node_pointer(nodecount); //get left bound AABB bound = new AABB(); bound.Invalidate(); AABB temp_box; int child_node = GetLeftNode(nodecount); if (child_node != 0) { GetNodeBound(child_node, out temp_box); bound.Merge(ref temp_box); } child_node = GetRightNode(nodecount); if (child_node != 0) { GetNodeBound(child_node, out temp_box); bound.Merge(ref temp_box); } SetNodeBound(nodecount, ref bound); } } }
//! this rebuild the entire set public void BuildSet() { //obtain primitive boxes int listSize = m_primitive_manager.GetPrimitiveCount(); GIM_BVH_DATA_ARRAY primitive_boxes = new GIM_BVH_DATA_ARRAY(listSize); // forces boxes to be allocated primitive_boxes.Resize(listSize); GIM_BVH_DATA[] rawArray = primitive_boxes.GetRawArray(); for (int i = 0; i < listSize; i++) { m_primitive_manager.GetPrimitiveBox(i, out rawArray[i].m_bound); rawArray[i].m_data = i; } m_box_tree.BuildTree(primitive_boxes); }