Ejemplo n.º 1
0
        public 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);

                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[curIndex].SetEscapeIndex(m_num_nodes - curIndex);
        }
Ejemplo n.º 2
0
        //! this rebuild the entire set
        public void BuildSet()
        {
            //obtain primitive boxes
            GIM_BVH_DATA_ARRAY primitive_boxes = new GIM_BVH_DATA_ARRAY();

            //primitive_boxes.resize(m_primitive_manager.get_primitive_count());
            primitive_boxes.Capacity = m_primitive_manager.GetPrimitiveCount();
            for (int i = 0; i < primitive_boxes.Count; i++)
            {
                m_primitive_manager.GetPrimitiveBox(i, out primitive_boxes.GetRawArray()[i].m_bound);
                primitive_boxes.GetRawArray()[i].m_data = i;
            }

            m_box_tree.BuildTree(primitive_boxes);
        }
        public 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);
        }
        //! 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);
        }
        public 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
        }