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(); }
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(); }