mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-14 05:40:05 +00:00
fix 'safeNormalize' (probably should remove it)
Fix for Issue 953: cull degenerate triangles https://github.com/bulletphysics/bullet3/issues/935 Thanks to Oleg Klimov for the report and reproduction case.
This commit is contained in:
parent
26a34e3cda
commit
72dd8285e8
@ -111,8 +111,12 @@ void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTrans
|
||||
vertices.push_back(triangleVerts[2]);
|
||||
|
||||
btVector3 triNormal = (triangleVerts[1]-triangleVerts[0]).cross(triangleVerts[2]-triangleVerts[0]);
|
||||
triNormal.normalize();
|
||||
btScalar dot = triNormal.dot(triNormal);
|
||||
|
||||
//cull degenerate triangles
|
||||
if (dot >= SIMD_EPSILON*SIMD_EPSILON)
|
||||
{
|
||||
triNormal /= btSqrt(dot);
|
||||
for (int v = 0; v < 3; v++)
|
||||
{
|
||||
|
||||
@ -120,9 +124,8 @@ void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTrans
|
||||
indicesOut.push_back(vertexPositions.size());
|
||||
vertexPositions.push_back(pos);
|
||||
vertexNormals.push_back(triNormal);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -249,14 +249,16 @@ public:
|
||||
|
||||
B3_FORCE_INLINE b3Vector3& safeNormalize()
|
||||
{
|
||||
b3Vector3 absVec = this->absolute();
|
||||
int maxIndex = absVec.maxAxis();
|
||||
if (absVec[maxIndex]>0)
|
||||
b3Scalar l2 = length2();
|
||||
//triNormal.normalize();
|
||||
if (l2 >= B3_EPSILON*B3_EPSILON)
|
||||
{
|
||||
*this /= absVec[maxIndex];
|
||||
return *this /= length();
|
||||
(*this) /= b3Sqrt(l2);
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(1, 0, 0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,15 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
|
||||
btScalar radiusWithThreshold = radius + contactBreakingThreshold;
|
||||
|
||||
btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
|
||||
normal.safeNormalize();
|
||||
|
||||
btScalar l2 = normal.length2();
|
||||
bool hasContact = false;
|
||||
btVector3 contactPoint;
|
||||
|
||||
if (l2 >= SIMD_EPSILON*SIMD_EPSILON)
|
||||
{
|
||||
normal /= btSqrt(l2);
|
||||
|
||||
btVector3 p1ToCentre = sphereCenter - vertices[0];
|
||||
btScalar distanceFromPlane = p1ToCentre.dot(normal);
|
||||
|
||||
@ -114,14 +122,14 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
|
||||
bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;
|
||||
|
||||
// Check for contact / intersection
|
||||
bool hasContact = false;
|
||||
btVector3 contactPoint;
|
||||
|
||||
if (isInsideContactPlane) {
|
||||
if (facecontains(sphereCenter, vertices, normal)) {
|
||||
// Inside the contact wedge - touches a point on the shell plane
|
||||
hasContact = true;
|
||||
contactPoint = sphereCenter - normal*distanceFromPlane;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Could be inside one of the contact capsules
|
||||
btScalar contactCapsuleRadiusSqr = radiusWithThreshold*radiusWithThreshold;
|
||||
btVector3 nearestOnEdge;
|
||||
@ -142,6 +150,7 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasContact) {
|
||||
btVector3 contactToCentre = sphereCenter - contactPoint;
|
||||
|
@ -291,14 +291,16 @@ public:
|
||||
|
||||
SIMD_FORCE_INLINE btVector3& safeNormalize()
|
||||
{
|
||||
btVector3 absVec = this->absolute();
|
||||
int maxIndex = absVec.maxAxis();
|
||||
if (absVec[maxIndex]>0)
|
||||
btScalar l2 = length2();
|
||||
//triNormal.normalize();
|
||||
if (l2 >= SIMD_EPSILON*SIMD_EPSILON)
|
||||
{
|
||||
*this /= absVec[maxIndex];
|
||||
return *this /= length();
|
||||
(*this) /= btSqrt(l2);
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(1, 0, 0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user