From c1250cd26a679f967dada73f7996a7027bff1fd5 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Wed, 23 May 2007 20:09:46 +0000 Subject: [PATCH] Planar triangle meshes with zero extends (in any direction) could cause quantization failures (division by zero). Added a positive value to quantization AABB (doesn't affect performance). --- src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp | 8 +++++--- src/BulletCollision/CollisionShapes/btOptimizedBvh.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp b/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp index 6f3eb91af..44438a244 100644 --- a/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp +++ b/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp @@ -326,10 +326,12 @@ void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int f } -void btOptimizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax) +void btOptimizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin) { - m_bvhAabbMin = bvhAabbMin; - m_bvhAabbMax = bvhAabbMax; + //enlarge the AABB to avoid division by zero when initializing the quantization values + btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin); + m_bvhAabbMin = bvhAabbMin - clampValue; + m_bvhAabbMax = bvhAabbMax + clampValue; btVector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin; m_bvhQuantization = btVector3(btScalar(65535.0),btScalar(65535.0),btScalar(65535.0)) / aabbSize; } diff --git a/src/BulletCollision/CollisionShapes/btOptimizedBvh.h b/src/BulletCollision/CollisionShapes/btOptimizedBvh.h index 3b4c9186b..d51595863 100644 --- a/src/BulletCollision/CollisionShapes/btOptimizedBvh.h +++ b/src/BulletCollision/CollisionShapes/btOptimizedBvh.h @@ -205,7 +205,7 @@ ATTRIBUTE_ALIGNED16(class) btOptimizedBvh } - void setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax); + void setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin=btScalar(1.0)); void setInternalNodeEscapeIndex(int nodeIndex, int escapeIndex) {