diff --git a/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp b/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp index 4537dba70..16a553755 100644 --- a/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp +++ b/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp @@ -72,6 +72,17 @@ struct btConnectivityProcessor : public btTriangleCallback int sharedVertsA[3]={-1,-1,-1}; int sharedVertsB[3]={-1,-1,-1}; + ///skip degenerate triangles + btScalar crossBSqr = ((triangle[1]-triangle[0]).cross(triangle[2]-triangle[0])).length2(); + if (crossBSqr < m_triangleInfoMap->m_equalVertexThreshold) + return; + + + btScalar crossASqr = ((m_triangleVerticesA[1]-m_triangleVerticesA[0]).cross(m_triangleVerticesA[2]-m_triangleVerticesA[0])).length2(); + ///skip degenerate triangles + if (crossASqr< m_triangleInfoMap->m_equalVertexThreshold) + return; + #if 0 printf("triangle A[0] = (%f,%f,%f)\ntriangle A[1] = (%f,%f,%f)\ntriangle A[2] = (%f,%f,%f)\n", m_triangleVerticesA[0].getX(),m_triangleVerticesA[0].getY(),m_triangleVerticesA[0].getZ(), @@ -94,8 +105,14 @@ struct btConnectivityProcessor : public btTriangleCallback sharedVertsA[numshared] = i; sharedVertsB[numshared] = j; numshared++; + ///degenerate case + if(numshared >= 3) + return; } } + ///degenerate case + if(numshared >= 3) + return; } switch (numshared) { diff --git a/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h b/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h index ea47b0c76..1e796a965 100644 --- a/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h +++ b/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h @@ -53,6 +53,8 @@ struct btTriangleInfoMap : public btInternalTriangleInfoMap btScalar m_planarEpsilon; ///used to determine if a triangle edge is planar with zero angle btScalar m_equalVertexThreshold; ///used to compute connectivity: if the distance between two vertices is smaller than m_equalVertexThreshold, they are considered to be 'shared' btScalar m_edgeDistanceThreshold; ///used to determine edge contacts: if the closest distance between a contact point and an edge is smaller than this distance threshold it is considered to "hit the edge" + btScalar m_zeroAreaThreshold; ///used to determine if a triangle is degenerate (length squared of cross product of 2 triangle edges < threshold) + btTriangleInfoMap() { @@ -60,6 +62,7 @@ struct btTriangleInfoMap : public btInternalTriangleInfoMap m_planarEpsilon = 0.0001f; m_equalVertexThreshold = btScalar(0.0001)*btScalar(0.0001); m_edgeDistanceThreshold = btScalar(0.1); + m_zeroAreaThreshold = btScalar(0.0001)*btScalar(0.0001); } };