Merge pull request #940 from erwincoumans/master

fix sphere-triangle for degenerate triangles (zero area/normal), fix 'safeNormalize' (probably should remove it)
This commit is contained in:
erwincoumans
2017-01-30 21:26:08 -08:00
committed by GitHub
5 changed files with 71 additions and 55 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);
}
}
}
}