//construct bvh from meshInterface
#ifndef DISABLE_BVH
- btVector3 bvhAabbMin,bvhAabbMax;
- if(meshInterface->hasPremadeAabb())
- {
- meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);
- }
- else
- {
- meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);
- }
-
if (buildBvh)
{
- void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
- m_bvh = new (mem) btOptimizedBvh();
- m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax);
- m_ownsBvh = true;
+ buildOptimizedBvh();
}
#endif //DISABLE_BVH
if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
{
btTriangleMeshShape::setLocalScaling(scaling);
- if (m_ownsBvh)
- {
- m_bvh->~btOptimizedBvh();
- btAlignedFree(m_bvh);
- }
- ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
- void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
- m_bvh = new(mem) btOptimizedBvh();
- //rebuild the bvh...
- m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
- m_ownsBvh = true;
+ buildOptimizedBvh();
}
}
+void btBvhTriangleMeshShape::buildOptimizedBvh()
+{
+ if (m_ownsBvh)
+ {
+ m_bvh->~btOptimizedBvh();
+ btAlignedFree(m_bvh);
+ }
+ ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
+ void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
+ m_bvh = new(mem) btOptimizedBvh();
+ //rebuild the bvh...
+ m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
+ m_ownsBvh = true;
+}
+
void btBvhTriangleMeshShape::setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& scaling)
{
btAssert(!m_bvh);