26 m_useQuantization(false),
28 m_traversalMode(TRAVERSAL_STACKLESS)
30 ,m_subtreeHeaderCount(0)
79 #ifdef DEBUG_PATCH_COLORS
87 #endif //DEBUG_PATCH_COLORS
94 btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
103 unsigned short vecIn[3];
108 m_bvhAabbMin.setMin(v-clampValue);
127 #ifdef DEBUG_TREE_BUILDING
129 int gMaxStackDepth = 0;
130 #endif //DEBUG_TREE_BUILDING
134 #ifdef DEBUG_TREE_BUILDING
136 if (gStackDepth > gMaxStackDepth)
137 gMaxStackDepth = gStackDepth;
138 #endif //DEBUG_TREE_BUILDING
141 int splitAxis, splitIndex, i;
142 int numIndices =endIndex-startIndex;
149 #ifdef DEBUG_TREE_BUILDING
151 #endif //DEBUG_TREE_BUILDING
172 for (i=startIndex;i<endIndex;i++)
191 #ifdef DEBUG_TREE_BUILDING
193 #endif //DEBUG_TREE_BUILDING
201 const int treeSizeInBytes = escapeIndex * sizeQuantizedNode;
221 int leftSubTreeSizeInBytes = leftSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
225 int rightSubTreeSizeInBytes = rightSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
251 int splitIndex =startIndex;
252 int numIndices = endIndex - startIndex;
256 for (i=startIndex;i<endIndex;i++)
263 splitValue = means[splitAxis];
266 for (i=startIndex;i<endIndex;i++)
269 if (center[splitAxis] > splitValue)
286 int rangeBalancedIndices = numIndices/3;
287 bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
291 splitIndex = startIndex+ (numIndices>>1);
294 bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex));
308 int numIndices = endIndex-startIndex;
310 for (i=startIndex;i<endIndex;i++)
317 for (i=startIndex;i<endIndex;i++)
321 diff2 = diff2 * diff2;
338 unsigned short int quantizedQueryAabbMin[3];
339 unsigned short int quantizedQueryAabbMax[3];
376 int escapeIndex, curIndex = 0;
377 int walkIterations = 0;
380 unsigned aabbOverlap;
392 if (isLeafNode && (aabbOverlap != 0))
398 if ((aabbOverlap != 0) || isLeafNode)
405 rootNode += escapeIndex;
406 curIndex += escapeIndex;
441 unsigned aabbOverlap;
448 if (aabbOverlap != 0)
472 int escapeIndex, curIndex = 0;
473 int walkIterations = 0;
476 unsigned aabbOverlap=0;
477 unsigned rayBoxOverlap=0;
483 rayAabbMin.
setMin(rayTarget);
484 rayAabbMax.
setMax(rayTarget);
487 rayAabbMin += aabbMin;
488 rayAabbMax += aabbMax;
491 btVector3 rayDir = (rayTarget-raySource);
493 lambda_max = rayDir.
dot(rayTarget-raySource);
499 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
515 bounds[0] -= aabbMax;
516 bounds[1] -= aabbMin;
522 rayBoxOverlap = aabbOverlap ?
btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) :
false;
529 rayBoxOverlap =
btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal);
535 if (isLeafNode && (rayBoxOverlap != 0))
541 if ((rayBoxOverlap != 0) || isLeafNode)
548 rootNode += escapeIndex;
549 curIndex += escapeIndex;
563 int curIndex = startNodeIndex;
564 int walkIterations = 0;
565 int subTreeSize = endNodeIndex - startNodeIndex;
573 unsigned boxBoxOverlap = 0;
574 unsigned rayBoxOverlap = 0;
579 btVector3 rayDirection = (rayTarget-raySource);
581 lambda_max = rayDirection.
dot(rayTarget-raySource);
586 unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
592 rayAabbMin.
setMin(rayTarget);
593 rayAabbMax.
setMax(rayTarget);
596 rayAabbMin += aabbMin;
597 rayAabbMax += aabbMax;
599 unsigned short int quantizedQueryAabbMin[3];
600 unsigned short int quantizedQueryAabbMax[3];
604 while (curIndex < endNodeIndex)
608 #ifdef VISUALLY_ANALYZE_BVH
610 static int drawPatch = 0;
613 if (curIndex==drawPatch)
619 debugDrawerPtr->
drawAabb(aabbMin,aabbMax,color);
621 #endif//VISUALLY_ANALYZE_BVH
624 btAssert (walkIterations < subTreeSize);
639 bounds[0] -= aabbMax;
640 bounds[1] -= aabbMin;
643 bool ra2 =
btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
644 bool ra =
btRayAabb (raySource, rayTarget, bounds[0], bounds[1], param, normal);
647 printf(
"functions don't match\n");
656 rayBoxOverlap =
btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max);
659 rayBoxOverlap =
true;
663 if (isLeafNode && rayBoxOverlap)
669 if ((rayBoxOverlap != 0) || isLeafNode)
676 rootNode += escapeIndex;
677 curIndex += escapeIndex;
689 int curIndex = startNodeIndex;
690 int walkIterations = 0;
691 int subTreeSize = endNodeIndex - startNodeIndex;
699 unsigned aabbOverlap;
701 while (curIndex < endNodeIndex)
705 #ifdef VISUALLY_ANALYZE_BVH
707 static int drawPatch = 0;
710 if (curIndex==drawPatch)
716 debugDrawerPtr->
drawAabb(aabbMin,aabbMax,color);
718 #endif//VISUALLY_ANALYZE_BVH
721 btAssert (walkIterations < subTreeSize);
728 if (isLeafNode && aabbOverlap)
734 if ((aabbOverlap != 0) || isLeafNode)
741 rootNode += escapeIndex;
742 curIndex += escapeIndex;
839 static const unsigned BVH_ALIGNMENT = 16;
840 static const unsigned BVH_ALIGNMENT_MASK = BVH_ALIGNMENT-1;
842 static const unsigned BVH_ALIGNMENT_BLOCKS = 2;
906 unsigned char *nodeData = (
unsigned char *)targetBvh;
909 unsigned sizeToAdd = 0;
910 nodeData += sizeToAdd;
920 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
935 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
964 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
976 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
995 nodeData += sizeToAdd;
1044 *((
void**)o_alignedDataBuffer) = NULL;
1052 if (i_alignedDataBuffer == NULL)
1071 btAssert(calculatedBufSize <= i_dataBufferSize);
1073 if (calculatedBufSize > i_dataBufferSize)
1078 unsigned char *nodeData = (
unsigned char *)bvh;
1081 unsigned sizeToAdd = 0;
1082 nodeData += sizeToAdd;
1096 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1117 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1131 nodeData += sizeToAdd;
1157 m_bvhAabbMin(self.m_bvhAabbMin),
1158 m_bvhAabbMax(self.m_bvhAabbMax),
1159 m_bvhQuantization(self.m_bvhQuantization),
1182 for (
int i=0;i<numElem;i++,memPtr++)
1200 for (
int i=0;i<numElem;i++,memPtr++)
1221 for (
int i=0;i<numElem;i++,memPtr++)
1253 for (
int i=0;i<numElem;i++,memPtr++)
1271 for (
int i=0;i<numElem;i++,memPtr++)
1292 for (
int i=0;i<numElem;i++,memPtr++)
1324 if (quantizedData->m_contiguousNodesPtr)
1330 for (
int i=0;i<numElem;i++,memPtr++)
1344 if (quantizedData->m_quantizedContiguousNodesPtr)
1350 for (
int i=0;i<numElem;i++,memPtr++)
1367 if (quantizedData->m_subTreeInfoPtr)
1373 for (
int i=0;i<numElem;i++,memPtr++)
void walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback *nodeCallback, unsigned short int *quantizedQueryAabbMin, unsigned short int *quantizedQueryAabbMax) const
tree traversal designed for small-memory processors like PS3 SPU
void walkStacklessTreeAgainstRay(btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget, const btVector3 &aabbMin, const btVector3 &aabbMax, int startNodeIndex, int endNodeIndex) const
void quantizeWithClamp(unsigned short *out, const btVector3 &point2, int isMax) const
btTraversalMode m_traversalMode
void setQuantizationValues(const btVector3 &bvhAabbMin, const btVector3 &bvhAabbMax, btScalar quantizationMargin=btScalar(1.0))
***************************************** expert/internal use only ************************* ...
void walkStacklessTree(btNodeOverlapCallback *nodeCallback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
void deSerializeDouble(const struct btVector3DoubleData &dataIn)
btVector3DoubleData m_bvhAabbMax
virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const
Data buffer MUST be 16 byte aligned.
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
void assignInternalNodeFromLeafNode(int internalNode, int leafNodeIndex)
btVector3FloatData m_bvhQuantization
void buildInternal()
buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialize...
btOptimizedBvhNodeFloatData * m_contiguousNodesPtr
btVector3DoubleData m_bvhAabbMin
int m_numContiguousLeafNodes
virtual ~btQuantizedBvh()
unsigned short m_quantizedAabbMax[3]
btVector3 m_bvhQuantization
virtual void * getUniquePointer(void *oldPtr)=0
#define btOptimizedBvhNodeData
int m_escapeIndexOrTriangleIndex
bool TestAabbAgainstAabb2(const btVector3 &aabbMin1, const btVector3 &aabbMax1, const btVector3 &aabbMin2, const btVector3 &aabbMax2)
conservative test for overlap between two aabbs
unsigned short m_quantizedAabbMin[3]
void setInternalNodeEscapeIndex(int nodeIndex, int escapeIndex)
btScalar dot(const btVector3 &v) const
Return the dot product.
btVector3FloatData m_bvhAabbMin
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
btVector3DoubleData m_bvhQuantization
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations.
btBvhSubtreeInfo provides info to gather a subtree of limited size
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 updateSubtreeHeaders(int leftChildNodexIndex, int rightChildNodexIndex)
int m_numQuantizedContiguousNodes
NodeArray m_contiguousNodes
int size() const
return the number of elements in the array
void reportRayOverlappingNodex(btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget) const
virtual void deSerializeDouble(struct btQuantizedBvhDoubleData &quantizedBvhDoubleData)
void setAabbFromQuantizeNode(const btQuantizedBvhNode &quantizedNode)
void setInternalNodeAabbMax(int nodeIndex, const btVector3 &aabbMax)
btVector3FloatData m_aabbMaxOrg
void mergeInternalNodeAabb(int nodeIndex, const btVector3 &newAabbMin, const btVector3 &newAabbMax)
unsigned testQuantizedAabbAgainstQuantizedAabb(const unsigned short int *aabbMin1, const unsigned short int *aabbMax1, const unsigned short int *aabbMin2, const unsigned short int *aabbMax2)
virtual void processNode(int subPart, int triangleIndex)=0
btOptimizedBvhNode contains both internal and leaf node information.
void serialize(struct btVector3Data &dataOut) const
btVector3 getAabbMin(int nodeIndex) const
void initializeFromBuffer(void *buffer, int size, int capacity)
static unsigned int getAlignmentSerializationPadding()
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
virtual void drawAabb(const btVector3 &from, const btVector3 &to, const btVector3 &color)
void btUnSwapVector3Endian(btVector3 &vector)
btUnSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization ...
void quantize(unsigned short *out, const btVector3 &point, int isMax) const
btVector3 unQuantize(const unsigned short *vecIn) const
void walkStacklessQuantizedTree(btNodeOverlapCallback *nodeCallback, unsigned short int *quantizedQueryAabbMin, unsigned short int *quantizedQueryAabbMax, int startNodeIndex, int endNodeIndex) const
btQuantizedBvhNodeData * m_quantizedContiguousNodesPtr
btQuantizedBvhNode is a compressed aabb node, 16 bytes.
BvhSubtreeInfoArray m_SubtreeHeaders
static btQuantizedBvh * deSerializeInPlace(void *i_alignedDataBuffer, unsigned int i_dataBufferSize, bool i_swapEndian)
deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place' ...
btVector3 can be used to represent 3D points and vectors.
#define btQuantizedBvhDataName
unsigned short m_quantizedAabbMin[3]
btBvhSubtreeInfoData * m_subTreeInfoPtr
void setInternalNodeAabbMin(int nodeIndex, const btVector3 &aabbMin)
two versions, one for quantized and normal nodes.
btVector3FloatData m_aabbMinOrg
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)=0
unsigned short int m_quantizedAabbMax[3]
int getTriangleIndex() const
btVector3FloatData m_bvhAabbMax
btVector3 getAabbMax(int nodeIndex) const
int sortAndCalcSplittingIndex(int startIndex, int endIndex, int splitAxis)
virtual void deSerializeFloat(struct btQuantizedBvhFloatData &quantizedBvhFloatData)
void resize(int newsize, const T &fillData=T())
#define BT_BULLET_VERSION
btBvhSubtreeInfoData * m_subTreeInfoPtr
#define MAX_SUBTREE_SIZE_IN_BYTES
The btQuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU...
void swapLeafNodes(int firstIndex, int secondIndex)
unsigned short int m_quantizedAabbMin[3]
unsigned btSwapEndian(unsigned val)
T & expand(const T &fillValue=T())
unsigned calculateSerializeBufferSize() const
int m_numQuantizedContiguousNodes
void walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget, const btVector3 &aabbMin, const btVector3 &aabbMax, int startNodeIndex, int endNodeIndex) const
unsigned short int m_quantizedAabbMax[3]
void buildTree(int startIndex, int endIndex)
void reportBoxCastOverlappingNodex(btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget, const btVector3 &aabbMin, const btVector3 &aabbMax) const
void setMax(const btVector3 &other)
Set each element to the max of the current values and the values of another btVector3.
QuantizedNodeArray m_quantizedLeafNodes
void deSerializeFloat(const struct btVector3FloatData &dataIn)
unsigned short m_quantizedAabbMax[3]
unsigned short int m_quantizedAabbMin[3]
btQuantizedBvhNodeData * m_quantizedContiguousNodesPtr
bool btRayAabb2(const btVector3 &rayFrom, const btVector3 &rayInvDirection, const unsigned int raySign[3], const btVector3 bounds[2], btScalar &tmin, btScalar lambda_min, btScalar lambda_max)
void reportAabbOverlappingNodex(btNodeOverlapCallback *nodeCallback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
***************************************** expert/internal use only ************************* ...
bool btRayAabb(const btVector3 &rayFrom, const btVector3 &rayTo, const btVector3 &aabbMin, const btVector3 &aabbMax, btScalar ¶m, btVector3 &normal)
void btSwapVector3Endian(const btVector3 &sourceVec, btVector3 &destVec)
btSwapVector3Endian swaps vector endianness, useful for network and cross-platform serialization ...
virtual btChunk * allocate(size_t size, int numElements)=0
btOptimizedBvhNodeDoubleData * m_contiguousNodesPtr
btVector3DoubleData m_aabbMinOrg
int calcSplittingAxis(int startIndex, int endIndex)
void setMin(const btVector3 &other)
Set each element to the min of the current values and the values of another btVector3.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
int getEscapeIndex() const
#define btQuantizedBvhData
int m_numContiguousLeafNodes
static btDbvtVolume bounds(const tNodeArray &leaves)
int maxAxis() const
Return the axis with the largest value Note return values are 0,1,2 for x, y, or z.
QuantizedNodeArray m_quantizedContiguousNodes
btVector3DoubleData m_aabbMaxOrg