Exemplo n.º 1
0
        ///buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized
        public void BuildInternal()
        {
            ///assumes that caller filled in the m_quantizedLeafNodes
            m_useQuantization = true;
            int numLeafNodes = 0;

            if (m_useQuantization)
            {
                //now we have an array of leafnodes in m_leafNodes
                numLeafNodes = m_quantizedLeafNodes.Count;
                m_quantizedContiguousNodes.Capacity = 2 * numLeafNodes;
            }

            m_curNodeIndex = 0;

            BuildTree(0, numLeafNodes);
            for(int i=0;i<m_quantizedContiguousNodes.Count;++i)
            {
                QuantizedBvhNode bvhn = m_quantizedContiguousNodes[i];
                System.Console.WriteLine(String.Format("QNode[{0}] Esc[{1}] min[{2},{3},{4}] max[{5},{6},{7}]",i,bvhn.m_escapeIndexOrTriangleIndex,bvhn.m_quantizedAabbMin.X,bvhn.m_quantizedAabbMin.Y,bvhn.m_quantizedAabbMin.Z,bvhn.m_quantizedAabbMax.X,bvhn.m_quantizedAabbMax.Y,bvhn.m_quantizedAabbMax.Z));
            }

            ///if the entire tree is small then subtree size, we need to create a header info for the tree
            if (m_useQuantization && m_SubtreeHeaders.Count == 0)
            {
                //BvhSubtrreeInfo subtree = m_SubtreeHeaders.expand();
                BvhSubtreeInfo subtree = new BvhSubtreeInfo();
                m_SubtreeHeaders.Add(subtree);
                subtree.SetAabbFromQuantizeNode(m_quantizedContiguousNodes[0]);
                subtree.m_rootNodeIndex = 0;
                subtree.m_subtreeSize = m_quantizedContiguousNodes[0].IsLeafNode() ? 1 : m_quantizedContiguousNodes[0].GetEscapeIndex();
            }

            //PCK: update the copy of the size
            m_subtreeHeaderCount = m_SubtreeHeaders.Count;

            //PCK: clear m_quantizedLeafNodes and m_leafNodes, they are temporary
            m_quantizedLeafNodes.Clear();
            m_leafNodes.Clear();

        }
Exemplo n.º 2
0
        protected void UpdateSubtreeHeaders(int leftChildNodexIndex, int rightChildNodexIndex)
        {
            Debug.Assert(m_useQuantization);

            QuantizedBvhNode leftChildNode = m_quantizedContiguousNodes[leftChildNodexIndex];
            int leftSubTreeSize = leftChildNode.IsLeafNode() ? 1 : leftChildNode.GetEscapeIndex();
            //int leftSubTreeSizeInBytes = leftSubTreeSize * static_cast<int>(sizeof(btQuantizedBvhNode));

            QuantizedBvhNode rightChildNode = m_quantizedContiguousNodes[rightChildNodexIndex];
            int rightSubTreeSize = rightChildNode.IsLeafNode() ? 1 : rightChildNode.GetEscapeIndex();
            //int rightSubTreeSizeInBytes = rightSubTreeSize * static_cast<int>(sizeof(btQuantizedBvhNode));

            if (leftChildNode.GetEscapeIndex() <= MAX_SUBTREE_SIZE_IN_BYTES)
            {
                BvhSubtreeInfo subtree = new BvhSubtreeInfo();
                m_SubtreeHeaders.Add(subtree);
                subtree.SetAabbFromQuantizeNode(leftChildNode);
                subtree.m_rootNodeIndex = leftChildNodexIndex;
                subtree.m_subtreeSize = leftSubTreeSize;
            }

            if (rightChildNode.GetEscapeIndex() <= MAX_SUBTREE_SIZE_IN_BYTES)
            {
                BvhSubtreeInfo subtree = new BvhSubtreeInfo();
                m_SubtreeHeaders.Add(subtree);
                subtree.SetAabbFromQuantizeNode(rightChildNode);
                subtree.m_rootNodeIndex = rightChildNodexIndex;
                subtree.m_subtreeSize = rightSubTreeSize;
            }

            //PCK: update the copy of the size
            m_subtreeHeaderCount = m_SubtreeHeaders.Count;
        }