Added demo code that show recursive traversal on tree data that doesn't have explicit left/right child pointers.
Can also be used as starting point for tree versus tree.
This commit is contained in:
@@ -446,7 +446,23 @@ void btOptimizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallb
|
|||||||
|
|
||||||
if (m_useQuantization)
|
if (m_useQuantization)
|
||||||
{
|
{
|
||||||
walkStacklessQuantizedTree(nodeCallback,aabbMin,aabbMax);
|
//USE_RECURSION shows you can still do a recursive traversal on the stackless 'skip index' tree data without the explicit left/right child pointer
|
||||||
|
//#define USE_RECURSION 1
|
||||||
|
#ifdef USE_RECURSION
|
||||||
|
bool useRecursion = true;
|
||||||
|
if (useRecursion)
|
||||||
|
{
|
||||||
|
unsigned short int quantizedQueryAabbMin[3];
|
||||||
|
unsigned short int quantizedQueryAabbMax[3];
|
||||||
|
quantizeWithClamp(quantizedQueryAabbMin,aabbMin);
|
||||||
|
quantizeWithClamp(quantizedQueryAabbMax,aabbMax);
|
||||||
|
const btQuantizedBvhNode* rootNode = &m_quantizedContiguousNodes[0];
|
||||||
|
walkRecursiveQuantizedTreeAgainstQueryAabb(rootNode,nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax);
|
||||||
|
} else
|
||||||
|
#endif //USE_RECURSION
|
||||||
|
{
|
||||||
|
walkStacklessQuantizedTree(nodeCallback,aabbMin,aabbMax);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
walkStacklessTree(nodeCallback,aabbMin,aabbMax);
|
walkStacklessTree(nodeCallback,aabbMin,aabbMax);
|
||||||
@@ -495,6 +511,38 @@ void btOptimizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void btOptimizedBvh::walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantizedBvhNode* currentNode,btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const
|
||||||
|
{
|
||||||
|
btAssert(m_useQuantization);
|
||||||
|
|
||||||
|
int escapeIndex;
|
||||||
|
bool aabbOverlap, isLeafNode;
|
||||||
|
|
||||||
|
aabbOverlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,currentNode->m_quantizedAabbMin,currentNode->m_quantizedAabbMax);
|
||||||
|
isLeafNode = currentNode->isLeafNode();
|
||||||
|
|
||||||
|
if (aabbOverlap)
|
||||||
|
{
|
||||||
|
if (isLeafNode)
|
||||||
|
{
|
||||||
|
nodeCallback->processNode(0,currentNode->getTriangleIndex());
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
//process left and right children
|
||||||
|
const btQuantizedBvhNode* leftChildNode = currentNode+1;
|
||||||
|
walkRecursiveQuantizedTreeAgainstQueryAabb(leftChildNode,nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax);
|
||||||
|
|
||||||
|
const btQuantizedBvhNode* rightChildNode = leftChildNode->isLeafNode() ?
|
||||||
|
leftChildNode+1:
|
||||||
|
leftChildNode+leftChildNode->getEscapeIndex();
|
||||||
|
walkRecursiveQuantizedTreeAgainstQueryAabb(rightChildNode,nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void btOptimizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
void btOptimizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||||
{
|
{
|
||||||
btAssert(m_useQuantization);
|
btAssert(m_useQuantization);
|
||||||
|
|||||||
@@ -213,6 +213,12 @@ protected:
|
|||||||
|
|
||||||
void walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
void walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||||
|
|
||||||
|
///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
|
||||||
|
void walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantizedBvhNode* currentNode,btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const;
|
||||||
|
|
||||||
|
///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
|
||||||
|
void walkRecursiveQuantizedTreeAgainstQuantizedTree(const btQuantizedBvhNode* treeNodeA,const btQuantizedBvhNode* treeNodeB,btNodeOverlapCallback* nodeCallback) const;
|
||||||
|
|
||||||
inline bool testQuantizedAabbAgainstQuantizedAabb(unsigned short int* aabbMin1,unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2) const
|
inline bool testQuantizedAabbAgainstQuantizedAabb(unsigned short int* aabbMin1,unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2) const
|
||||||
{
|
{
|
||||||
bool overlap = true;
|
bool overlap = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user