Ejemplo n.º 1
0
 public void ReportAabbOverlappingNodex(INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax)
 {
     //either choose recursive traversal (walkTree) or stackless (walkStacklessTree)
     //walkTree(m_rootNode1,nodeCallback,aabbMin,aabbMax);
     //WalkStacklessTree(_rootNode, nodeCallback, aabbMin, aabbMax);
     WalkStacklessTree(_contiguousNodes, nodeCallback, aabbMin, aabbMax);
 }
Ejemplo n.º 2
0
        public void WalkStacklessTree(OptimizedBvhNode[] rootNodeArray, INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax)
        {
            int              escapeIndex, curIndex = 0;
            int              walkIterations = 0;
            bool             aabbOverlap, isLeafNode;
            int              rootNodeIndex = 0;
            OptimizedBvhNode rootNode      = rootNodeArray[rootNodeIndex];

            while (curIndex < _curNodeIndex)
            {
                //catch bugs in tree data
                if (walkIterations >= _curNodeIndex)
                {
                    throw new BulletException();
                }

                walkIterations++;
                aabbOverlap = MathHelper.TestAabbAgainstAabb2(aabbMin, aabbMax, rootNode.AabbMin, rootNode.AabbMax);
                isLeafNode  = (rootNode.LeftChild == null && rootNode.RightChild == null);

                if (isLeafNode && aabbOverlap)
                {
                    nodeCallback.ProcessNode(rootNode);
                }

                if (aabbOverlap || isLeafNode)
                {
                    rootNodeIndex++;                     // this
                    curIndex++;
                    if (rootNodeIndex < rootNodeArray.Length)
                    {
                        rootNode = rootNodeArray[rootNodeIndex];
                    }
                }
                else
                {
                    escapeIndex    = rootNode.EscapeIndex;
                    rootNodeIndex += escapeIndex;                     // and this
                    curIndex      += escapeIndex;
                    if (rootNodeIndex < rootNodeArray.Length)
                    {
                        rootNode = rootNodeArray[rootNodeIndex];
                    }
                }
            }

            if (_maxIterations < walkIterations)
            {
                _maxIterations = walkIterations;
            }
        }
Ejemplo n.º 3
0
        public void WalkTree(OptimizedBvhNode rootNode, INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax)
        {
            bool isLeafNode, aabbOverlap = MathHelper.TestAabbAgainstAabb2(aabbMin, aabbMax, rootNode.AabbMin, rootNode.AabbMax);

            if (aabbOverlap)
            {
                isLeafNode = (rootNode.LeftChild == null && rootNode.RightChild == null);
                if (isLeafNode)
                {
                    nodeCallback.ProcessNode(rootNode);
                }
                else
                {
                    WalkTree(rootNode.LeftChild, nodeCallback, aabbMin, aabbMax);
                    WalkTree(rootNode.RightChild, nodeCallback, aabbMin, aabbMax);
                }
            }
        }
Ejemplo n.º 4
0
		public void WalkStacklessTree(OptimizedBvhNode[] rootNodeArray, INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax)
		{
			int escapeIndex, curIndex = 0;
			int walkIterations = 0;
			bool aabbOverlap, isLeafNode;
            int rootNodeIndex = 0;
            OptimizedBvhNode rootNode = rootNodeArray[rootNodeIndex];

			while (curIndex < _curNodeIndex)
			{
				//catch bugs in tree data
				if (walkIterations >= _curNodeIndex)
					throw new BulletException();

				walkIterations++;
				aabbOverlap = MathHelper.TestAabbAgainstAabb2(aabbMin, aabbMax, rootNode.AabbMin, rootNode.AabbMax);
				isLeafNode = (rootNode.LeftChild == null && rootNode.RightChild == null);

				if (isLeafNode && aabbOverlap)
				{
					nodeCallback.ProcessNode(rootNode);
				}

				if (aabbOverlap || isLeafNode)
				{
					rootNodeIndex++; // this
					curIndex++;
                    if (rootNodeIndex < rootNodeArray.Length)
                        rootNode = rootNodeArray[rootNodeIndex];
                }
				else
				{
					escapeIndex = rootNode.EscapeIndex;
					rootNodeIndex += escapeIndex; // and this
					curIndex += escapeIndex;
                    if (rootNodeIndex < rootNodeArray.Length)
                        rootNode = rootNodeArray[rootNodeIndex];
				}

			}

			if (_maxIterations < walkIterations)
				_maxIterations = walkIterations;
		}
Ejemplo n.º 5
0
		public void WalkTree(OptimizedBvhNode rootNode, INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax)
		{
			bool isLeafNode, aabbOverlap = MathHelper.TestAabbAgainstAabb2(aabbMin, aabbMax, rootNode.AabbMin, rootNode.AabbMax);
			if (aabbOverlap)
			{
				isLeafNode = (rootNode.LeftChild == null && rootNode.RightChild == null);
				if (isLeafNode)
				{
					nodeCallback.ProcessNode(rootNode);
				}
				else
				{
					WalkTree(rootNode.LeftChild, nodeCallback, aabbMin, aabbMax);
					WalkTree(rootNode.RightChild, nodeCallback, aabbMin, aabbMax);
				}
			}
		}
 ///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
 protected void WalkRecursiveQuantizedTreeAgainstQuantizedTree(QuantizedBvhNode treeNodeA, QuantizedBvhNode treeNodeB, INodeOverlapCallback nodeCallback)
 {
     // MAN - No implementation??
 }
        ///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
        protected void WalkRecursiveQuantizedTreeAgainstQueryAabb(ref QuantizedBvhNode currentNode, INodeOverlapCallback nodeCallback, ref UShortVector3 quantizedQueryAabbMin, ref UShortVector3 quantizedQueryAabbMax)
        {
            Debug.Assert(m_useQuantization);

            bool isLeafNode;
            //PCK: unsigned instead of bool
            bool aabbOverlap = false;

            //PCK: unsigned instead of bool
            aabbOverlap = AabbUtil2.TestQuantizedAabbAgainstQuantizedAabb(ref quantizedQueryAabbMin, ref quantizedQueryAabbMax, ref currentNode.m_quantizedAabbMin, ref currentNode.m_quantizedAabbMax);
            isLeafNode = currentNode.IsLeafNode();

            //PCK: unsigned instead of bool
            if (aabbOverlap)
            {
                if (isLeafNode)
                {
                    nodeCallback.ProcessNode(currentNode.GetPartId(), currentNode.GetTriangleIndex());
                }
                else
                {
                    //process left and right children

                    //QuantizedBvhNode leftChildNode = currentNode + 1;
                    // Not sure bout thie replacement... but avoids pointer arithmetic
                    // this is broken ...
                    //int nodeIndex = currentNode.GetTriangleIndex() + 1;
                    if(currentNode.m_leftChildIndex > -1 && currentNode.m_leftChildIndex < m_quantizedContiguousNodes.Count)
                    {
                        QuantizedBvhNode leftChildNode = m_quantizedContiguousNodes[currentNode.m_leftChildIndex];
                        WalkRecursiveQuantizedTreeAgainstQueryAabb(ref leftChildNode, nodeCallback, ref quantizedQueryAabbMin, ref quantizedQueryAabbMax);
                    }

                    if(currentNode.m_rightChildIndex > -1 && currentNode.m_rightChildIndex < m_quantizedContiguousNodes.Count)
                    {
                        //int newIndex = leftChildNode.IsLeafNode() ? leftChildNode.GetTriangleIndex() + 1 : leftChildNode.GetTriangleIndex() + leftChildNode.GetEscapeIndex();
                        QuantizedBvhNode rightChildNode = m_quantizedContiguousNodes[currentNode.m_rightChildIndex];
                        WalkRecursiveQuantizedTreeAgainstQueryAabb(ref rightChildNode, nodeCallback, ref quantizedQueryAabbMin, ref quantizedQueryAabbMax);
                    }
                }
            }
        }
        ///tree traversal designed for small-memory processors like PS3 SPU
        protected void WalkStacklessQuantizedTreeCacheFriendly(INodeOverlapCallback nodeCallback, ref UShortVector3 quantizedQueryAabbMin, ref UShortVector3 quantizedQueryAabbMax)
        {
            Debug.Assert(m_useQuantization);

            for (int i = 0; i < m_SubtreeHeaders.Count; i++)
            {
                BvhSubtreeInfo subtree = m_SubtreeHeaders[i];

                //PCK: unsigned instead of bool
                bool overlap = AabbUtil2.TestQuantizedAabbAgainstQuantizedAabb(ref quantizedQueryAabbMin, ref quantizedQueryAabbMax, ref subtree.m_quantizedAabbMin, ref subtree.m_quantizedAabbMax);
                if (overlap)
                {
                    WalkStacklessQuantizedTree(nodeCallback, ref quantizedQueryAabbMin, ref quantizedQueryAabbMax,
                        subtree.m_rootNodeIndex,
                        subtree.m_rootNodeIndex + subtree.m_subtreeSize);
                }
            }

        }
        protected void WalkStacklessTreeAgainstRay(INodeOverlapCallback nodeCallback, ref IndexedVector3 raySource, ref IndexedVector3 rayTarget, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax, int startNodeIndex, int endNodeIndex)
        {
            Debug.Assert(!m_useQuantization);

            int escapeIndex, curIndex = 0;
            OptimizedBvhNode rootNode = m_contiguousNodes[curIndex];
            int walkIterations = 0;
            bool isLeafNode;

            bool aabbOverlap = false;
            bool rayBoxOverlap = false;
            float lambda_max = 1.0f;

            /* Quick pruning by quantized box */
            IndexedVector3 rayAabbMin = raySource;
            IndexedVector3 rayAabbMax = raySource;
            MathUtil.VectorMin(ref rayTarget, ref rayAabbMin);
            MathUtil.VectorMax(ref rayTarget, ref rayAabbMax);

            /* Add box cast extents to bounding box */
            rayAabbMin += aabbMin;
            rayAabbMax += aabbMax;

#if RAYAABB2
            IndexedVector3 rayDir = (rayTarget - raySource);
            rayDir.Normalize();
            lambda_max = IndexedVector3.Dot(rayDir, rayTarget - raySource);
            ///what about division by zero? --> just set rayDirection[i] to 1.0
            IndexedVector3 rayDirectionInverse = new IndexedVector3(
                MathUtil.FuzzyZero(rayDir.X) ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.X,
                MathUtil.FuzzyZero(rayDir.Y) ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.Y,
                MathUtil.FuzzyZero(rayDir.Z) ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.Z);
            //bool[] sign = new bool[] { rayDirectionInverse.X < 0.0f, rayDirectionInverse.Y < 0.0f, rayDirectionInverse.Z < 0.0f };
            bool sign0 = rayDirectionInverse.X < 0.0f;
            bool sign1 = rayDirectionInverse.Y < 0.0f;
            bool sign2 = rayDirectionInverse.Z < 0.0f;

#endif

            //IndexedVector3[] bounds = new IndexedVector3[2];
            IndexedVector3 minBound;
            IndexedVector3 maxBound;


            while (curIndex < m_curNodeIndex)
            {
                float param = 1.0f;
                //catch bugs in tree data
                Debug.Assert(walkIterations < m_curNodeIndex);

                walkIterations++;

                minBound = rootNode.m_aabbMinOrg;
                maxBound = rootNode.m_aabbMaxOrg;
                /* Add box cast extents */
                minBound -= aabbMax;
                maxBound -= aabbMin;

                aabbOverlap = AabbUtil2.TestAabbAgainstAabb2(ref rayAabbMin, ref rayAabbMax, ref rootNode.m_aabbMinOrg, ref rootNode.m_aabbMaxOrg);
                //perhaps profile if it is worth doing the aabbOverlap test first

#if RAYAABB2
                ///careful with this check: need to check division by zero (above) and fix the unQuantize method
                ///thanks Joerg/hiker for the reproduction case!
                ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
                rayBoxOverlap = aabbOverlap ? AabbUtil2.RayAabb2Alt(ref raySource, ref rayDirectionInverse, sign0,sign1,sign2, ref minBound,ref maxBound, out param, 0.0f, lambda_max) : false;

#else
                IndexedVector3 normal = IndexedVector3.Zero;
                rayBoxOverlap = AabbUtil2.RayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal);
#endif

                isLeafNode = rootNode.m_escapeIndex == -1;

                //PCK: unsigned instead of bool
                if (isLeafNode && (rayBoxOverlap))
                {
                    nodeCallback.ProcessNode(rootNode.m_subPart, rootNode.m_triangleIndex);
                }

                //PCK: unsigned instead of bool
                if ((rayBoxOverlap) || isLeafNode)
                {
                    curIndex++;
                }
                else
                {
                    escapeIndex = rootNode.m_escapeIndex;
                    curIndex += escapeIndex;
                }
                rootNode = m_contiguousNodes[curIndex];
            }
            if (m_maxIterations < walkIterations)
            {
                m_maxIterations = walkIterations;
            }
        }
        protected void WalkStacklessQuantizedTreeAgainstRay(INodeOverlapCallback nodeCallback, ref IndexedVector3 raySource, ref IndexedVector3 rayTarget, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax, int startNodeIndex, int endNodeIndex)
        {
            Debug.Assert(m_useQuantization);

            int curIndex = startNodeIndex;
            int walkIterations = 0;
            int subTreeSize = endNodeIndex - startNodeIndex;
            //(void)subTreeSize;
            QuantizedBvhNode rootNode = m_quantizedContiguousNodes[curIndex];
            int escapeIndex = 0;

            bool isLeafNode = false;
            //PCK: unsigned instead of bool
            bool boxBoxOverlap = false;
            bool rayBoxOverlap = false;

            float lambda_max = 1.0f;

#if RAYAABB2
            IndexedVector3 rayDirection = (rayTarget - raySource);
            rayDirection.Normalize();
            lambda_max = IndexedVector3.Dot(rayDirection, rayTarget - raySource);
            ///what about division by zero? --> just set rayDirection[i] to 1.0
            rayDirection.X = MathUtil.FuzzyZero(rayDirection.X) ? MathUtil.BT_LARGE_FLOAT : 1f / rayDirection.X;
            rayDirection.Y = MathUtil.FuzzyZero(rayDirection.Y) ? MathUtil.BT_LARGE_FLOAT : 1f / rayDirection.Y;
            rayDirection.Z = MathUtil.FuzzyZero(rayDirection.Z) ? MathUtil.BT_LARGE_FLOAT : 1f / rayDirection.Z;

            //bool[] sign = new bool[] { rayDirection.X < 0.0f, rayDirection.Y < 0.0f, rayDirection.Z < 0.0f };
            bool sign0 = rayDirection.X < 0.0f;
            bool sign1 = rayDirection.Y < 0.0f;
            bool sign2 = rayDirection.Z < 0.0f;


#endif

            /* Quick pruning by quantized box */
            IndexedVector3 rayAabbMin = raySource;
            IndexedVector3 rayAabbMax = raySource;
            MathUtil.VectorMin(ref rayTarget, ref rayAabbMin);
            MathUtil.VectorMax(ref rayTarget, ref rayAabbMax);

            /* Add box cast extents to bounding box */
            rayAabbMin += aabbMin;
            rayAabbMax += aabbMax;

            UShortVector3 quantizedQueryAabbMin;
            UShortVector3 quantizedQueryAabbMax;
            QuantizeWithClamp(out quantizedQueryAabbMin, ref rayAabbMin, false);
            QuantizeWithClamp(out quantizedQueryAabbMax, ref rayAabbMax, true);

            while (curIndex < endNodeIndex)
            {

                //#define VISUALLY_ANALYZE_BVH 1
#if VISUALLY_ANALYZE_BVH
                //some code snippet to debugDraw aabb, to visually analyze bvh structure
                int drawPatch = 3;
                //need some global access to a debugDrawer
                IDebugDraw debugDrawerPtr = BulletGlobals.gDebugDraw;
                //IDebugDraw debugDrawerPtr = null;
                //if (curIndex == drawPatch&& debugDrawerPtr != null)
                if (debugDrawerPtr != null && curIndex == drawPatch)
                {
                    IndexedVector3 aabbMin2;
                    IndexedVector3 aabbMax2;
                    UnQuantize(ref rootNode.m_quantizedAabbMin, out aabbMin2);
                    UnQuantize(ref rootNode.m_quantizedAabbMax, out aabbMax2);
                    IndexedVector3 color = new IndexedVector3(1f / curIndex, 0, 0);
                    debugDrawerPtr.DrawAabb(ref aabbMin2, ref aabbMax2, ref color);
                    //Console.Out.WriteLine(String.Format("min[{0},{1},{2}] max[{3},{4},{5}]\n", aabbMin.X, aabbMin.Y, aabbMin.Z, aabbMax.X, aabbMax.Y, aabbMax.Z));

                }
#endif//VISUALLY_ANALYZE_BVH

                //catch bugs in tree data
                Debug.Assert(walkIterations < subTreeSize);

                walkIterations++;
                //PCK: unsigned instead of bool
                // only interested if this is closer than any previous hit
                float param = 1.0f;
                rayBoxOverlap = false;
                boxBoxOverlap = AabbUtil2.TestQuantizedAabbAgainstQuantizedAabb(ref quantizedQueryAabbMin, ref quantizedQueryAabbMax, ref rootNode.m_quantizedAabbMin, ref rootNode.m_quantizedAabbMax);
                isLeafNode = rootNode.IsLeafNode();
                if (boxBoxOverlap)
                {
                    //IndexedVector3[] bounds = new IndexedVector3[2];
                    //UnQuantize(ref rootNode.m_quantizedAabbMin, out bounds[0]);
                    //UnQuantize(ref rootNode.m_quantizedAabbMax, out bounds[1]);
                    ///* Add box cast extents */
                    //bounds[0] -= aabbMax;
                    //bounds[1] -= aabbMin;

                    IndexedVector3 minBound;
                    IndexedVector3 maxBound;
                    UnQuantize(ref rootNode.m_quantizedAabbMin, out minBound);
                    UnQuantize(ref rootNode.m_quantizedAabbMax, out maxBound);
                    /* Add box cast extents */
                    minBound -= aabbMax;
                    maxBound -= aabbMin;

                    IndexedVector3 normal;
#if false
			        bool ra2 = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
			        bool ra = btRayAabb (raySource, rayTarget, bounds[0], bounds[1], param, normal);
			        if (ra2 != ra)
			        {
				        printf("functions don't match\n");
			        }
#endif
#if RAYAABB2
                    ///careful with this check: need to check division by zero (above) and fix the unQuantize method
                    ///thanks Joerg/hiker for the reproduction case!
                    ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858

                    BulletGlobals.StartProfile("btRayAabb2");
                    rayBoxOverlap = AabbUtil2.RayAabb2Alt(ref raySource, ref rayDirection, sign0,sign1,sign2, ref minBound,ref maxBound, out param, 0.0f, lambda_max);
                    BulletGlobals.StopProfile();
#else
                    rayBoxOverlap = true;//btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal);
#endif
                }

                if (isLeafNode && rayBoxOverlap)
                {
                    nodeCallback.ProcessNode(rootNode.GetPartId(), rootNode.GetTriangleIndex());
                }

                //PCK: unsigned instead of bool
                if ((rayBoxOverlap) || isLeafNode)
                {
                    curIndex++;
                }
                else
                {
                    escapeIndex = rootNode.GetEscapeIndex();
                    curIndex += escapeIndex;
                }
                rootNode = m_quantizedContiguousNodes[curIndex];
            }
            if (m_maxIterations < walkIterations)
            {
                m_maxIterations = walkIterations;
            }
        }
        protected void WalkStacklessTree(INodeOverlapCallback nodeCallback, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
            Debug.Assert(!m_useQuantization);
            int escapeIndex, curIndex = 0;

            OptimizedBvhNode rootNode = m_contiguousNodes[curIndex];
            int walkIterations = 0;
            bool isLeafNode;
            //PCK: unsigned instead of bool
            bool aabbOverlap;

            while (curIndex < m_curNodeIndex)
            {
                //catch bugs in tree data
                Debug.Assert(walkIterations < m_curNodeIndex);

                walkIterations++;
                aabbOverlap = AabbUtil2.TestAabbAgainstAabb2(ref aabbMin, ref aabbMax, ref rootNode.m_aabbMinOrg, ref rootNode.m_aabbMaxOrg);
                isLeafNode = rootNode.m_escapeIndex == -1;

                //PCK: unsigned instead of bool
                if (isLeafNode && (aabbOverlap))
                {
                    nodeCallback.ProcessNode(rootNode.m_subPart, rootNode.m_triangleIndex);
                }

                //PCK: unsigned instead of bool
                if ((aabbOverlap) || isLeafNode)
                {
                    curIndex++;
                }
                else
                {
                    escapeIndex = rootNode.m_escapeIndex;
                    curIndex += escapeIndex;
                }
                rootNode = m_contiguousNodes[curIndex];

            }
            if (m_maxIterations < walkIterations)
            {
                m_maxIterations = walkIterations;
            }
        }
        public void ReportBoxCastOverlappingNodex(INodeOverlapCallback nodeCallback, ref IndexedVector3 raySource, ref IndexedVector3 rayTarget, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
            //always use stackless

            if (m_useQuantization)
            {
                WalkStacklessQuantizedTreeAgainstRay(nodeCallback, ref raySource, ref rayTarget, ref aabbMin, ref aabbMax, 0, m_curNodeIndex);
            }
            else
            {
                WalkStacklessTreeAgainstRay(nodeCallback, ref raySource, ref rayTarget, ref aabbMin, ref aabbMax, 0, m_curNodeIndex);
            }
            /*
            {
                //recursive traversal
                IndexedVector3 qaabbMin = raySource;
                IndexedVector3 qaabbMax = raySource;
                qaabbMin.setMin(rayTarget);
                qaabbMax.setMax(rayTarget);
                qaabbMin += aabbMin;
                qaabbMax += aabbMax;
                reportAabbOverlappingNodex(nodeCallback,qaabbMin,qaabbMax);
            }
            */

        }
 public void ReportRayOverlappingNodex(INodeOverlapCallback nodeCallback, ref IndexedVector3 raySource, ref IndexedVector3 rayTarget)
 {
     IndexedVector3 abMin = IndexedVector3.Zero, abMax = IndexedVector3.Zero;
     ReportBoxCastOverlappingNodex(nodeCallback, ref raySource, ref rayTarget, ref abMin, ref abMax);
 }
        ///***************************************** expert/internal use only *************************

        public void ReportAabbOverlappingNodex(INodeOverlapCallback nodeCallback, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
            //either choose recursive traversal (walkTree) or stackless (walkStacklessTree)

            if (m_useQuantization)
            {
                ///quantize query AABB
                UShortVector3 quantizedQueryAabbMin;
                UShortVector3 quantizedQueryAabbMax;
                QuantizeWithClamp(out quantizedQueryAabbMin, ref aabbMin, false);
                QuantizeWithClamp(out quantizedQueryAabbMax, ref aabbMax, true);

                switch (m_traversalMode)
                {
                    case TraversalMode.TRAVERSAL_STACKLESS:
                        if (m_useQuantization)
                        {
                            WalkStacklessQuantizedTree(nodeCallback, ref quantizedQueryAabbMin, ref quantizedQueryAabbMax, 0, m_curNodeIndex);
                        }
                        else
                        {
                            WalkStacklessTree(nodeCallback, ref aabbMin, ref aabbMax);
                        }
                        break;
                    case TraversalMode.TRAVERSAL_STACKLESS_CACHE_FRIENDLY:
                        WalkStacklessQuantizedTreeCacheFriendly(nodeCallback, ref quantizedQueryAabbMin, ref quantizedQueryAabbMax);
                        break;
                    case TraversalMode.TRAVERSAL_RECURSIVE:
                        {
                            QuantizedBvhNode rootNode = m_quantizedContiguousNodes[0];
                            WalkRecursiveQuantizedTreeAgainstQueryAabb(ref rootNode, nodeCallback, ref quantizedQueryAabbMin, ref quantizedQueryAabbMax);
                        }
                        break;
                    default:
                        //unsupported
                        Debug.Assert(false);
                        break;
                }
            }
            else
            {
                WalkStacklessTree(nodeCallback, ref aabbMin, ref aabbMax);
            }
        }
Ejemplo n.º 15
0
 public void ReportSphereOverlappingNodex(INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax)
 {
 }
Ejemplo n.º 16
0
		public void ReportAabbOverlappingNodex(INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax)
		{
			//either choose recursive traversal (walkTree) or stackless (walkStacklessTree)
			//walkTree(m_rootNode1,nodeCallback,aabbMin,aabbMax);
			//WalkStacklessTree(_rootNode, nodeCallback, aabbMin, aabbMax);
            WalkStacklessTree(_contiguousNodes, nodeCallback, aabbMin, aabbMax);
		}
Ejemplo n.º 17
0
		public void ReportSphereOverlappingNodex(INodeOverlapCallback nodeCallback, Vector3 aabbMin, Vector3 aabbMax) { }
        protected void WalkStacklessQuantizedTree(INodeOverlapCallback nodeCallback, ref UShortVector3 quantizedQueryAabbMin, ref UShortVector3 quantizedQueryAabbMax, int startNodeIndex, int endNodeIndex)
        {
            Debug.Assert(m_useQuantization);

            int curIndex = startNodeIndex;
            int walkIterations = 0;
            int subTreeSize = endNodeIndex - startNodeIndex;
            //(void)subTreeSize;
            QuantizedBvhNode rootNode = m_quantizedContiguousNodes[curIndex];
            int escapeIndex = 0;

            bool isLeafNode;
            //PCK: unsigned instead of bool
            bool aabbOverlap = false;

            while (curIndex < endNodeIndex)
            {

                //#define VISUALLY_ANALYZE_BVH 1
#if VISUALLY_ANALYZE_BVH
                //some code snippet to debugDraw aabb, to visually analyze bvh structure
                int drawPatch = 1;
                //need some global access to a debugDrawer
                IDebugDraw debugDrawerPtr = BulletGlobals.gDebugDraw;
                //IDebugDraw debugDrawerPtr = null;
                //if (curIndex == drawPatch&& debugDrawerPtr != null)
                if (debugDrawerPtr != null && curIndex == drawPatch)
                //if (debugDrawerPtr != null)
                {
                    IndexedVector3 aabbMin, aabbMax;
                    UnQuantize(ref rootNode.m_quantizedAabbMin, out aabbMin);
                    UnQuantize(ref rootNode.m_quantizedAabbMax, out aabbMax);
                    IndexedVector3 color = new IndexedVector3(1, 0, 0);
                    debugDrawerPtr.DrawAabb(ref aabbMin, ref aabbMax, ref color);
                    //IndexedVector3 offset = new IndexedVector3(0, 2, 0);
                    //debugDrawerPtr.DrawAabb(aabbMin+offset, aabbMax+offset, color);
                    //Console.Out.WriteLine(String.Format("min[{0},{1},{2}] max[{3},{4},{5}]\n", aabbMin.X, aabbMin.Y, aabbMin.Z, aabbMax.X, aabbMax.Y, aabbMax.Z));


                }
#endif//VISUALLY_ANALYZE_BVH

                //unQuantize version with out param


                //catch bugs in tree data
                Debug.Assert(walkIterations < subTreeSize);

                walkIterations++;

                //PCK: unsigned instead of bool
                aabbOverlap = AabbUtil2.TestQuantizedAabbAgainstQuantizedAabb(ref quantizedQueryAabbMin, ref quantizedQueryAabbMax, ref rootNode.m_quantizedAabbMin, ref rootNode.m_quantizedAabbMax);
                isLeafNode = rootNode.IsLeafNode();

                if (isLeafNode && aabbOverlap)
                {
                    nodeCallback.ProcessNode(rootNode.GetPartId(), rootNode.GetTriangleIndex());
                }

                //PCK: unsigned instead of bool
                if ((aabbOverlap) || isLeafNode)
                {
                    curIndex++;
                }
                else
                {
                    escapeIndex = rootNode.GetEscapeIndex();
                    curIndex += escapeIndex;
                }
                rootNode = m_quantizedContiguousNodes[curIndex];

            }
            if (m_maxIterations < walkIterations)
            {
                m_maxIterations = walkIterations;
            }
        }