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);
109 #ifdef DEBUG_TREE_BUILDING
111 int gMaxStackDepth = 0;
112 #endif //DEBUG_TREE_BUILDING
116 #ifdef DEBUG_TREE_BUILDING
118 if (gStackDepth > gMaxStackDepth)
119 gMaxStackDepth = gStackDepth;
120 #endif //DEBUG_TREE_BUILDING
123 int splitAxis, splitIndex, i;
124 int numIndices =endIndex-startIndex;
131 #ifdef DEBUG_TREE_BUILDING
133 #endif //DEBUG_TREE_BUILDING
154 for (i=startIndex;i<endIndex;i++)
173 #ifdef DEBUG_TREE_BUILDING
175 #endif //DEBUG_TREE_BUILDING
183 const int treeSizeInBytes = escapeIndex * sizeQuantizedNode;
203 int leftSubTreeSizeInBytes = leftSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
207 int rightSubTreeSizeInBytes = rightSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
233 int splitIndex =startIndex;
234 int numIndices = endIndex - startIndex;
238 for (i=startIndex;i<endIndex;i++)
245 splitValue = means[splitAxis];
248 for (i=startIndex;i<endIndex;i++)
251 if (center[splitAxis] > splitValue)
268 int rangeBalancedIndices = numIndices/3;
269 bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
273 splitIndex = startIndex+ (numIndices>>1);
276 bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex));
290 int numIndices = endIndex-startIndex;
292 for (i=startIndex;i<endIndex;i++)
299 for (i=startIndex;i<endIndex;i++)
303 diff2 = diff2 * diff2;
320 unsigned short int quantizedQueryAabbMin[3];
321 unsigned short int quantizedQueryAabbMax[3];
358 int escapeIndex, curIndex = 0;
359 int walkIterations = 0;
362 unsigned aabbOverlap;
374 if (isLeafNode && (aabbOverlap != 0))
380 if ((aabbOverlap != 0) || isLeafNode)
387 rootNode += escapeIndex;
388 curIndex += escapeIndex;
423 unsigned aabbOverlap;
430 if (aabbOverlap != 0)
454 int escapeIndex, curIndex = 0;
455 int walkIterations = 0;
458 unsigned aabbOverlap=0;
459 unsigned rayBoxOverlap=0;
465 rayAabbMin.
setMin(rayTarget);
466 rayAabbMax.
setMax(rayTarget);
469 rayAabbMin += aabbMin;
470 rayAabbMax += aabbMax;
473 btVector3 rayDir = (rayTarget-raySource);
475 lambda_max = rayDir.
dot(rayTarget-raySource);
481 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
497 bounds[0] -= aabbMax;
498 bounds[1] -= aabbMin;
504 rayBoxOverlap = aabbOverlap ?
btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) :
false;
511 rayBoxOverlap =
btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal);
517 if (isLeafNode && (rayBoxOverlap != 0))
523 if ((rayBoxOverlap != 0) || isLeafNode)
530 rootNode += escapeIndex;
531 curIndex += escapeIndex;
545 int curIndex = startNodeIndex;
546 int walkIterations = 0;
547 int subTreeSize = endNodeIndex - startNodeIndex;
555 unsigned boxBoxOverlap = 0;
556 unsigned rayBoxOverlap = 0;
561 btVector3 rayDirection = (rayTarget-raySource);
563 lambda_max = rayDirection.
dot(rayTarget-raySource);
568 unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
574 rayAabbMin.
setMin(rayTarget);
575 rayAabbMax.
setMax(rayTarget);
578 rayAabbMin += aabbMin;
579 rayAabbMax += aabbMax;
581 unsigned short int quantizedQueryAabbMin[3];
582 unsigned short int quantizedQueryAabbMax[3];
586 while (curIndex < endNodeIndex)
590 #ifdef VISUALLY_ANALYZE_BVH
592 static int drawPatch = 0;
595 if (curIndex==drawPatch)
601 debugDrawerPtr->
drawAabb(aabbMin,aabbMax,color);
603 #endif//VISUALLY_ANALYZE_BVH
606 btAssert (walkIterations < subTreeSize);
621 bounds[0] -= aabbMax;
622 bounds[1] -= aabbMin;
625 bool ra2 =
btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
626 bool ra =
btRayAabb (raySource, rayTarget, bounds[0], bounds[1], param, normal);
629 printf(
"functions don't match\n");
638 rayBoxOverlap =
btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max);
641 rayBoxOverlap =
true;
645 if (isLeafNode && rayBoxOverlap)
651 if ((rayBoxOverlap != 0) || isLeafNode)
658 rootNode += escapeIndex;
659 curIndex += escapeIndex;
671 int curIndex = startNodeIndex;
672 int walkIterations = 0;
673 int subTreeSize = endNodeIndex - startNodeIndex;
681 unsigned aabbOverlap;
683 while (curIndex < endNodeIndex)
687 #ifdef VISUALLY_ANALYZE_BVH
689 static int drawPatch = 0;
692 if (curIndex==drawPatch)
698 debugDrawerPtr->
drawAabb(aabbMin,aabbMax,color);
700 #endif//VISUALLY_ANALYZE_BVH
703 btAssert (walkIterations < subTreeSize);
710 if (isLeafNode && aabbOverlap)
716 if ((aabbOverlap != 0) || isLeafNode)
723 rootNode += escapeIndex;
724 curIndex += escapeIndex;
821 static const unsigned BVH_ALIGNMENT = 16;
822 static const unsigned BVH_ALIGNMENT_MASK = BVH_ALIGNMENT-1;
824 static const unsigned BVH_ALIGNMENT_BLOCKS = 2;
888 unsigned char *nodeData = (
unsigned char *)targetBvh;
891 unsigned sizeToAdd = 0;
892 nodeData += sizeToAdd;
902 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
917 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
946 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
958 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
977 nodeData += sizeToAdd;
1026 *((
void**)o_alignedDataBuffer) = NULL;
1034 if (i_alignedDataBuffer == NULL)
1053 btAssert(calculatedBufSize <= i_dataBufferSize);
1055 if (calculatedBufSize > i_dataBufferSize)
1060 unsigned char *nodeData = (
unsigned char *)bvh;
1063 unsigned sizeToAdd = 0;
1064 nodeData += sizeToAdd;
1078 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1099 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1113 nodeData += sizeToAdd;
1139 m_bvhAabbMin(self.m_bvhAabbMin),
1140 m_bvhAabbMax(self.m_bvhAabbMax),
1141 m_bvhQuantization(self.m_bvhQuantization),
1164 for (
int i=0;i<numElem;i++,memPtr++)
1182 for (
int i=0;i<numElem;i++,memPtr++)
1203 for (
int i=0;i<numElem;i++,memPtr++)
1235 for (
int i=0;i<numElem;i++,memPtr++)
1253 for (
int i=0;i<numElem;i++,memPtr++)
1274 for (
int i=0;i<numElem;i++,memPtr++)
1306 if (quantizedData->m_contiguousNodesPtr)
1312 for (
int i=0;i<numElem;i++,memPtr++)
1326 if (quantizedData->m_quantizedContiguousNodesPtr)
1332 for (
int i=0;i<numElem;i++,memPtr++)
1349 if (quantizedData->m_subTreeInfoPtr)
1355 for (
int i=0;i<numElem;i++,memPtr++)