public virtual void InternalProcessTriangleIndex(IndexedVector3[] triangle, int partId, int triangleIndex)
		{
			// The partId and triangle index must fit in the same (positive) integer
			Debug.Assert(partId < (1<<MAX_NUM_PARTS_IN_BITS));
            Debug.Assert(triangleIndex < (1 << (31 - MAX_NUM_PARTS_IN_BITS)));
			//negative indices are reserved for escapeIndex
            Debug.Assert(triangleIndex >= 0);

            QuantizedBvhNode node = new QuantizedBvhNode();
			IndexedVector3	aabbMin,aabbMax;
			aabbMin = MathUtil.MAX_VECTOR;
            aabbMax = MathUtil.MIN_VECTOR;

            MathUtil.VectorMin(ref triangle[0], ref aabbMin);
            MathUtil.VectorMax(ref triangle[0], ref aabbMax);
            MathUtil.VectorMin(ref triangle[1], ref aabbMin);
            MathUtil.VectorMax(ref triangle[1], ref aabbMax);
            MathUtil.VectorMin(ref triangle[2], ref aabbMin);
            MathUtil.VectorMax(ref triangle[2], ref aabbMax);
		
			//PCK: add these checks for zero dimensions of aabb
			float MIN_AABB_DIMENSION = 0.002f;
            float MIN_AABB_HALF_DIMENSION = 0.001f;
			if (aabbMax.X - aabbMin.X < MIN_AABB_DIMENSION)
			{
				aabbMax.X = (aabbMax.X + MIN_AABB_HALF_DIMENSION);
				aabbMin.X = (aabbMin.X - MIN_AABB_HALF_DIMENSION);
			}
			if (aabbMax.Y - aabbMin.Y < MIN_AABB_DIMENSION)
			{
				aabbMax.Y = (aabbMax.Y + MIN_AABB_HALF_DIMENSION);
				aabbMin.Y = (aabbMin.Y - MIN_AABB_HALF_DIMENSION);
			}
			if (aabbMax.Z - aabbMin.Z < MIN_AABB_DIMENSION)
			{
				aabbMax.Z = (aabbMax.Z + MIN_AABB_HALF_DIMENSION);
				aabbMin.Z = (aabbMin.Z - MIN_AABB_HALF_DIMENSION);
			}

			m_optimizedTree.Quantize(out node.m_quantizedAabbMin,ref aabbMin,false);
			m_optimizedTree.Quantize(out node.m_quantizedAabbMax,ref aabbMax,true);

			node.m_escapeIndexOrTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;

			m_triangleNodes.Add(node);
		}
 ///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??
 }
        //int			m_padding[3];

        public void SetAabbFromQuantizeNode(QuantizedBvhNode quantizedNode)
        {
            m_quantizedAabbMin = quantizedNode.m_quantizedAabbMin;
            m_quantizedAabbMax = quantizedNode.m_quantizedAabbMax;
        }
        ///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);
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void BuildTree(ref IndexedVector3 bvhAabbMin, ref IndexedVector3 bvhAabbMax)
 {
     m_optimizedAabbTree = new QuantizedBvh();
     m_optimizedAabbTree.SetQuantizationValues(ref bvhAabbMin, ref bvhAabbMax);
     IList<QuantizedBvhNode> nodes = m_optimizedAabbTree.GetLeafNodeArray();
     for (int i = 0; i < m_sapBroadphases.Count; i++)
     {
         QuantizedBvhNode node = new QuantizedBvhNode();
         IndexedVector3 aabbMin;
         IndexedVector3 aabbMax;
         m_sapBroadphases[i].GetBroadphaseAabb(out aabbMin, out aabbMax);
         m_optimizedAabbTree.Quantize(out node.m_quantizedAabbMin, ref aabbMin, false);
         m_optimizedAabbTree.Quantize(out node.m_quantizedAabbMax, ref aabbMax, true);
         int partId = 0;
         node.m_escapeIndexOrTriangleIndex = (partId << (31 - QuantizedBvh.MAX_NUM_PARTS_IN_BITS)) | i;
         nodes.Add(node);
     }
     m_optimizedAabbTree.BuildInternal();
 }