25 m_useQuantization(false),
27 m_traversalMode(TRAVERSAL_STACKLESS)
30 m_subtreeHeaderCount(0)
72 #ifdef DEBUG_PATCH_COLORS
79 #endif //DEBUG_PATCH_COLORS
84 btVector3 clampValue(quantizationMargin, quantizationMargin, quantizationMargin);
93 unsigned short vecIn[3];
116 #ifdef DEBUG_TREE_BUILDING
118 int gMaxStackDepth = 0;
119 #endif //DEBUG_TREE_BUILDING
123 #ifdef DEBUG_TREE_BUILDING
125 if (gStackDepth > gMaxStackDepth)
126 gMaxStackDepth = gStackDepth;
127 #endif //DEBUG_TREE_BUILDING
129 int splitAxis, splitIndex, i;
130 int numIndices = endIndex - startIndex;
137 #ifdef DEBUG_TREE_BUILDING
139 #endif //DEBUG_TREE_BUILDING
159 for (i = startIndex; i < endIndex; i++)
177 #ifdef DEBUG_TREE_BUILDING
179 #endif //DEBUG_TREE_BUILDING
187 const int treeSizeInBytes = escapeIndex * sizeQuantizedNode;
206 int leftSubTreeSizeInBytes = leftSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
210 int rightSubTreeSizeInBytes = rightSubTreeSize *
static_cast<int>(
sizeof(
btQuantizedBvhNode));
235 int splitIndex = startIndex;
236 int numIndices = endIndex - startIndex;
240 for (i = startIndex; i < endIndex; i++)
247 splitValue = means[splitAxis];
250 for (i = startIndex; i < endIndex; i++)
253 if (center[splitAxis] > splitValue)
270 int rangeBalancedIndices = numIndices / 3;
271 bool unbalanced = ((splitIndex <= (startIndex + rangeBalancedIndices)) || (splitIndex >= (endIndex - 1 - rangeBalancedIndices)));
275 splitIndex = startIndex + (numIndices >> 1);
278 bool unbal = (splitIndex == startIndex) || (splitIndex == (endIndex));
291 int numIndices = endIndex - startIndex;
293 for (i = startIndex; i < endIndex; i++)
300 for (i = startIndex; i < endIndex; i++)
304 diff2 = diff2 * diff2;
319 unsigned short int quantizedQueryAabbMin[3];
320 unsigned short int quantizedQueryAabbMax[3];
354 int escapeIndex, curIndex = 0;
355 int walkIterations = 0;
358 unsigned aabbOverlap;
370 if (isLeafNode && (aabbOverlap != 0))
376 if ((aabbOverlap != 0) || isLeafNode)
384 rootNode += escapeIndex;
385 curIndex += escapeIndex;
417 unsigned aabbOverlap;
424 if (aabbOverlap != 0)
447 int escapeIndex, curIndex = 0;
448 int walkIterations = 0;
451 unsigned aabbOverlap = 0;
452 unsigned rayBoxOverlap = 0;
458 rayAabbMin.
setMin(rayTarget);
459 rayAabbMax.
setMax(rayTarget);
462 rayAabbMin += aabbMin;
463 rayAabbMax += aabbMax;
466 btVector3 rayDir = (rayTarget - raySource);
468 lambda_max = rayDir.
dot(rayTarget - raySource);
474 unsigned int sign[3] = {rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
497 rayBoxOverlap = aabbOverlap ?
btRayAabb2(raySource, rayDirectionInverse, sign,
bounds, param, 0.0f, lambda_max) :
false;
510 if (isLeafNode && (rayBoxOverlap != 0))
516 if ((rayBoxOverlap != 0) || isLeafNode)
524 rootNode += escapeIndex;
525 curIndex += escapeIndex;
534 int curIndex = startNodeIndex;
535 int walkIterations = 0;
536 int subTreeSize = endNodeIndex - startNodeIndex;
544 unsigned boxBoxOverlap = 0;
545 unsigned rayBoxOverlap = 0;
550 btVector3 rayDirection = (rayTarget - raySource);
552 lambda_max = rayDirection.
dot(rayTarget - raySource);
557 unsigned int sign[3] = {rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
563 rayAabbMin.
setMin(rayTarget);
564 rayAabbMax.
setMax(rayTarget);
567 rayAabbMin += aabbMin;
568 rayAabbMax += aabbMax;
570 unsigned short int quantizedQueryAabbMin[3];
571 unsigned short int quantizedQueryAabbMax[3];
575 while (curIndex < endNodeIndex)
578 #ifdef VISUALLY_ANALYZE_BVH
580 static int drawPatch = 0;
583 if (curIndex == drawPatch)
589 debugDrawerPtr->
drawAabb(aabbMin, aabbMax, color);
591 #endif //VISUALLY_ANALYZE_BVH
594 btAssert(walkIterations < subTreeSize);
613 bool ra2 =
btRayAabb2 (raySource, rayDirection, sign,
bounds, param, 0.0, lambda_max);
617 printf(
"functions don't match\n");
626 rayBoxOverlap =
btRayAabb2(raySource, rayDirection, sign,
bounds, param, 0.0f, lambda_max);
629 rayBoxOverlap =
true;
633 if (isLeafNode && rayBoxOverlap)
639 if ((rayBoxOverlap != 0) || isLeafNode)
647 rootNode += escapeIndex;
648 curIndex += escapeIndex;
657 int curIndex = startNodeIndex;
658 int walkIterations = 0;
659 int subTreeSize = endNodeIndex - startNodeIndex;
667 unsigned aabbOverlap;
669 while (curIndex < endNodeIndex)
672 #ifdef VISUALLY_ANALYZE_BVH
674 static int drawPatch = 0;
677 if (curIndex == drawPatch)
683 debugDrawerPtr->
drawAabb(aabbMin, aabbMax, color);
685 #endif //VISUALLY_ANALYZE_BVH
688 btAssert(walkIterations < subTreeSize);
695 if (isLeafNode && aabbOverlap)
701 if ((aabbOverlap != 0) || isLeafNode)
709 rootNode += escapeIndex;
710 curIndex += escapeIndex;
801 static const unsigned BVH_ALIGNMENT = 16;
802 static const unsigned BVH_ALIGNMENT_MASK = BVH_ALIGNMENT-1;
804 static const unsigned BVH_ALIGNMENT_BLOCKS = 2;
866 unsigned char* nodeData = (
unsigned char*)targetBvh;
869 unsigned sizeToAdd = 0;
870 nodeData += sizeToAdd;
880 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
895 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
921 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
933 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
952 nodeData += sizeToAdd;
1001 *((
void**)o_alignedDataBuffer) = NULL;
1008 if (i_alignedDataBuffer == NULL)
1027 btAssert(calculatedBufSize <= i_dataBufferSize);
1029 if (calculatedBufSize > i_dataBufferSize)
1034 unsigned char* nodeData = (
unsigned char*)bvh;
1037 unsigned sizeToAdd = 0;
1038 nodeData += sizeToAdd;
1052 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1073 for (
int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
1087 nodeData += sizeToAdd;
1113 m_bvhAabbMax(self.m_bvhAabbMax),
1114 m_bvhQuantization(self.m_bvhQuantization),
1136 for (
int i = 0; i < numElem; i++, memPtr++)
1154 for (
int i = 0; i < numElem; i++, memPtr++)
1175 for (
int i = 0; i < numElem; i++, memPtr++)
1207 for (
int i = 0; i < numElem; i++, memPtr++)
1225 for (
int i = 0; i < numElem; i++, memPtr++)
1246 for (
int i = 0; i < numElem; i++, memPtr++)
1275 if (quantizedData->m_contiguousNodesPtr)
1281 for (
int i = 0; i < numElem; i++, memPtr++)
1289 memset(memPtr->m_pad, 0,
sizeof(memPtr->m_pad));
1297 if (quantizedData->m_quantizedContiguousNodesPtr)
1303 for (
int i = 0; i < numElem; i++, memPtr++)
1320 if (quantizedData->m_subTreeInfoPtr)
1326 for (
int i = 0; i < numElem; i++, memPtr++)