コード例 #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();

        }
コード例 #2
0
	    public void	Build(StridingMeshInterface triangles,bool useQuantizedAabbCompression, ref IndexedVector3 bvhAabbMin, ref IndexedVector3 bvhAabbMax)
        {
	        int numLeafNodes = 0;
            m_useQuantization = useQuantizedAabbCompression;

        	
	        if (m_useQuantization)
	        {

		        //initialize quantization values
		        SetQuantizationValues(ref bvhAabbMin,ref bvhAabbMax);

		        QuantizedNodeTriangleCallback callback = new QuantizedNodeTriangleCallback(m_quantizedLeafNodes,this);
        	
		        triangles.InternalProcessAllTriangles(callback,ref m_bvhAabbMin,ref m_bvhAabbMax);

		        //now we have an array of leafnodes in m_leafNodes
		        numLeafNodes = m_quantizedLeafNodes.Count;

                //m_quantizedContiguousNodes.resize(2*numLeafNodes);
                m_quantizedContiguousNodes.Capacity = 2 * numLeafNodes;
	        } 
            else
	        {
		        NodeTriangleCallback callback = new NodeTriangleCallback(m_leafNodes);

		        IndexedVector3 aabbMin = MathUtil.MIN_VECTOR;
		        IndexedVector3 aabbMax = MathUtil.MAX_VECTOR;

		        triangles.InternalProcessAllTriangles(callback,ref aabbMin,ref aabbMax);

		        //now we have an array of leafnodes in m_leafNodes
		        numLeafNodes = m_leafNodes.Count;

                //m_contiguousNodes.resize(2*numLeafNodes);
                m_contiguousNodes.Capacity = 2 * numLeafNodes;
	        }

	        m_curNodeIndex = 0;

	        BuildTree(0,numLeafNodes);

            //for (int i = 0; i < m_quantizedContiguousNodes.Count; ++i)
            //{
            //    QuantizedBvhNode bvhn = m_quantizedContiguousNodes[i];
            //}


	        ///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)
	        {

                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();
        }
コード例 #3
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;
        }