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];
129 #ifdef DEBUG_TREE_BUILDING
131 int gMaxStackDepth = 0;
132 #endif //DEBUG_TREE_BUILDING
136 #ifdef DEBUG_TREE_BUILDING
138 if (gStackDepth > gMaxStackDepth)
139 gMaxStackDepth = gStackDepth;
140 #endif //DEBUG_TREE_BUILDING
143 int splitAxis, splitIndex, i;
144 int numIndices =endIndex-startIndex;
151 #ifdef DEBUG_TREE_BUILDING
153 #endif //DEBUG_TREE_BUILDING
174 for (i=startIndex;i<endIndex;i++)
193 #ifdef DEBUG_TREE_BUILDING
195 #endif //DEBUG_TREE_BUILDING
203 const int treeSizeInBytes = escapeIndex * sizeQuantizedNode;
223 int leftSubTreeSizeInBytes = leftSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
227 int rightSubTreeSizeInBytes = rightSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
253 int splitIndex =startIndex;
254 int numIndices = endIndex - startIndex;
258 for (i=startIndex;i<endIndex;i++)
265 splitValue = means[splitAxis];
268 for (i=startIndex;i<endIndex;i++)
271 if (center[splitAxis] > splitValue)
288 int rangeBalancedIndices = numIndices/3;
289 bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
293 splitIndex = startIndex+ (numIndices>>1);
296 bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex));
310 int numIndices = endIndex-startIndex;
312 for (i=startIndex;i<endIndex;i++)
319 for (i=startIndex;i<endIndex;i++)
323 diff2 = diff2 * diff2;
340 unsigned short int quantizedQueryAabbMin[3];
341 unsigned short int quantizedQueryAabbMax[3];
378 int escapeIndex, curIndex = 0;
379 int walkIterations = 0;
382 unsigned aabbOverlap;
394 if (isLeafNode && (aabbOverlap != 0))
400 if ((aabbOverlap != 0) || isLeafNode)
407 rootNode += escapeIndex;
408 curIndex += escapeIndex;
443 unsigned aabbOverlap;
450 if (aabbOverlap != 0)
474 int escapeIndex, curIndex = 0;
475 int walkIterations = 0;
478 unsigned aabbOverlap=0;
479 unsigned rayBoxOverlap=0;
485 rayAabbMin.
setMin(rayTarget);
486 rayAabbMax.
setMax(rayTarget);
489 rayAabbMin += aabbMin;
490 rayAabbMax += aabbMax;
493 btVector3 rayDir = (rayTarget-raySource);
495 lambda_max = rayDir.
dot(rayTarget-raySource);
501 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
524 rayBoxOverlap = aabbOverlap ?
btRayAabb2 (raySource, rayDirectionInverse, sign,
bounds, param, 0.0f, lambda_max) :
false;
537 if (isLeafNode && (rayBoxOverlap != 0))
543 if ((rayBoxOverlap != 0) || isLeafNode)
550 rootNode += escapeIndex;
551 curIndex += escapeIndex;
565 int curIndex = startNodeIndex;
566 int walkIterations = 0;
567 int subTreeSize = endNodeIndex - startNodeIndex;
575 unsigned boxBoxOverlap = 0;
576 unsigned rayBoxOverlap = 0;
581 btVector3 rayDirection = (rayTarget-raySource);
583 lambda_max = rayDirection.
dot(rayTarget-raySource);
588 unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
594 rayAabbMin.
setMin(rayTarget);
595 rayAabbMax.
setMax(rayTarget);
598 rayAabbMin += aabbMin;
599 rayAabbMax += aabbMax;
601 unsigned short int quantizedQueryAabbMin[3];
602 unsigned short int quantizedQueryAabbMax[3];
606 while (curIndex < endNodeIndex)
610 #ifdef VISUALLY_ANALYZE_BVH
612 static int drawPatch = 0;
615 if (curIndex==drawPatch)
621 debugDrawerPtr->
drawAabb(aabbMin,aabbMax,color);
623 #endif//VISUALLY_ANALYZE_BVH
626 btAssert (walkIterations < subTreeSize);
645 bool ra2 =
btRayAabb2 (raySource, rayDirection, sign,
bounds, param, 0.0, lambda_max);
649 printf(
"functions don't match\n");
658 rayBoxOverlap =
btRayAabb2 (raySource, rayDirection, sign,
bounds, param, 0.0f, lambda_max);
661 rayBoxOverlap =
true;
665 if (isLeafNode && rayBoxOverlap)
671 if ((rayBoxOverlap != 0) || isLeafNode)
678 rootNode += escapeIndex;
679 curIndex += escapeIndex;
691 int curIndex = startNodeIndex;
692 int walkIterations = 0;
693 int subTreeSize = endNodeIndex - startNodeIndex;
701 unsigned aabbOverlap;
703 while (curIndex < endNodeIndex)
707 #ifdef VISUALLY_ANALYZE_BVH
709 static int drawPatch = 0;
712 if (curIndex==drawPatch)
718 debugDrawerPtr->
drawAabb(aabbMin,aabbMax,color);
720 #endif//VISUALLY_ANALYZE_BVH
723 btAssert (walkIterations < subTreeSize);
730 if (isLeafNode && aabbOverlap)
736 if ((aabbOverlap != 0) || isLeafNode)
743 rootNode += escapeIndex;
744 curIndex += escapeIndex;
841 static const unsigned BVH_ALIGNMENT = 16;
842 static const unsigned BVH_ALIGNMENT_MASK = BVH_ALIGNMENT-1;
844 static const unsigned BVH_ALIGNMENT_BLOCKS = 2;
908 unsigned char *nodeData = (
unsigned char *)targetBvh;
911 unsigned sizeToAdd = 0;
912 nodeData += sizeToAdd;
922 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
937 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
966 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
978 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
997 nodeData += sizeToAdd;
1046 *((
void**)o_alignedDataBuffer) = NULL;
1054 if (i_alignedDataBuffer == NULL)
1073 btAssert(calculatedBufSize <= i_dataBufferSize);
1075 if (calculatedBufSize > i_dataBufferSize)
1080 unsigned char *nodeData = (
unsigned char *)bvh;
1083 unsigned sizeToAdd = 0;
1084 nodeData += sizeToAdd;
1098 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1119 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1133 nodeData += sizeToAdd;
1159 m_bvhAabbMin(self.m_bvhAabbMin),
1160 m_bvhAabbMax(self.m_bvhAabbMax),
1161 m_bvhQuantization(self.m_bvhQuantization),
1184 for (
int i=0;i<numElem;i++,memPtr++)
1202 for (
int i=0;i<numElem;i++,memPtr++)
1223 for (
int i=0;i<numElem;i++,memPtr++)
1255 for (
int i=0;i<numElem;i++,memPtr++)
1273 for (
int i=0;i<numElem;i++,memPtr++)
1294 for (
int i=0;i<numElem;i++,memPtr++)
1326 if (quantizedData->m_contiguousNodesPtr)
1332 for (
int i=0;i<numElem;i++,memPtr++)
1340 memset(memPtr->m_pad, 0,
sizeof(memPtr->m_pad));
1348 if (quantizedData->m_quantizedContiguousNodesPtr)
1354 for (
int i=0;i<numElem;i++,memPtr++)
1371 if (quantizedData->m_subTreeInfoPtr)
1377 for (
int i=0;i<numElem;i++,memPtr++)