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:
erwincoumans
2017-01-30 18:12:09 -08:00
parent 26a34e3cda
commit 72dd8285e8
4 changed files with 70 additions and 54 deletions

View File

@@ -111,18 +111,21 @@ 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);
for (int v=0;v<3;v++)
//cull degenerate triangles
if (dot >= SIMD_EPSILON*SIMD_EPSILON)
{
btVector3 pos =parentTransform*triangleVerts[v];
indicesOut.push_back(vertexPositions.size());
vertexPositions.push_back(pos);
vertexNormals.push_back(triNormal);
triNormal /= btSqrt(dot);
for (int v = 0; v < 3; v++)
{
btVector3 pos = parentTransform*triangleVerts[v];
indicesOut.push_back(vertexPositions.size());
vertexPositions.push_back(pos);
vertexNormals.push_back(triNormal);
}
}
}
}