public GImpactShapeInterface() { m_shapeType = BroadphaseNativeTypes.GIMPACT_SHAPE_PROXYTYPE; m_localAABB.Invalidate(); m_needs_update = true; localScaling = IndexedVector3.One; }
private void BuildSubTree(GIM_BVH_DATA_ARRAY primitive_boxes, int startIndex, int endIndex) { int curIndex = m_num_nodes; m_num_nodes++; Debug.Assert((endIndex - startIndex) > 0); if ((endIndex - startIndex) <= MAX_INDICES_PER_NODE) { //We have a leaf node int count = endIndex - startIndex; int[] indices = new int[count]; AABB bounds = new AABB(); bounds.Invalidate(); for (int i = 0; i < count; i++) { indices[i] = primitive_boxes[startIndex + i].m_data; bounds.Merge(primitive_boxes.GetRawArray()[startIndex + i].m_bound); } SetNodeBound(curIndex, ref bounds); m_node_array[curIndex].SetDataIndices(indices); return; } //calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'. //split axis int splitIndex = CalcSplittingAxis(primitive_boxes, startIndex, endIndex); splitIndex = SortAndCalcSplittingIndex( primitive_boxes, startIndex, endIndex, splitIndex //split axis ); //calc this node bounding box AABB node_bound = new AABB(); node_bound.Invalidate(); for (int i = startIndex; i < endIndex; i++) { node_bound.Merge(ref primitive_boxes.GetRawArray()[i].m_bound); } SetNodeBound(curIndex, ref node_bound); //build left branch BuildSubTree(primitive_boxes, startIndex, splitIndex); //build right branch BuildSubTree(primitive_boxes, splitIndex, endIndex); m_node_array.GetRawArray()[curIndex].SetEscapeIndex(m_num_nodes - curIndex); }
protected void CalcQuantization(GIM_BVH_DATA_ARRAY primitive_boxes, float boundMargin) { //calc globa box AABB global_bound = new AABB(); global_bound.Invalidate(); int count = primitive_boxes.Count; for (int i = 0; i < count; i++) { global_bound.Merge(ref primitive_boxes.GetRawArray()[i].m_bound); } GImpactQuantization.CalcQuantizationParameters(out m_global_bound.m_min, out m_global_bound.m_max, out m_bvhQuantization, ref global_bound.m_min, ref global_bound.m_max, boundMargin); }
//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); } } }
protected void BuildSubTree(GIM_BVH_DATA_ARRAY primitive_boxes, int startIndex, int endIndex) { int curIndex = m_num_nodes; m_num_nodes++; Debug.Assert((endIndex - startIndex) > 0); if ((endIndex - startIndex) == 1) { //We have a leaf node SetNodeBound(curIndex, ref primitive_boxes.GetRawArray()[startIndex].m_bound); m_node_array[curIndex].SetDataIndex(primitive_boxes[startIndex].m_data); #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactBVH) { BulletGlobals.g_streamWriter.WriteLine("bst curIndex[{0}] dataIndex[{1}]", curIndex, primitive_boxes[startIndex].m_data); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "bst min", primitive_boxes[startIndex].m_bound.m_min); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "bst max", primitive_boxes[startIndex].m_bound.m_max); } #endif return; } //calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'. //split axis int splitIndex = CalcSplittingAxis(primitive_boxes, startIndex, endIndex); splitIndex = SortAndCalcSplittingIndex( primitive_boxes, startIndex, endIndex, splitIndex //split axis ); //calc this node bounding box AABB node_bound = new AABB(); node_bound.Invalidate(); for (int i = startIndex; i < endIndex; i++) { node_bound.Merge(ref primitive_boxes.GetRawArray()[i].m_bound); } SetNodeBound(curIndex, ref node_bound); //build left branch BuildSubTree(primitive_boxes, startIndex, splitIndex); //build right branch BuildSubTree(primitive_boxes, splitIndex, endIndex); m_node_array.GetRawArray()[curIndex].SetEscapeIndex(m_num_nodes - curIndex); #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugGimpactBVH) { BulletGlobals.g_streamWriter.WriteLine("bst curIndex[{0}] escapeIndex[{1}]", curIndex, m_node_array.GetRawArray()[curIndex].GetEscapeIndex()); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "bst node min", node_bound.m_min); MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "bst node max", node_bound.m_max); } #endif }