Skip to content

Commit 4351081

Browse files
Make smooth triangle normal computation more robust
1 parent 5c73656 commit 4351081

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/collision/shapes/TriangleShape.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,16 @@ Vector3 TriangleShape::computeSmoothLocalContactNormalForTriangle(const Vector3&
210210
}
211211

212212
// We compute the contact normal as the barycentric interpolation of the three vertices normals
213-
return (u * mVerticesNormals[0] + v * mVerticesNormals[1] + w * mVerticesNormals[2]).getUnit();
213+
Vector3 interpolatedNormal = u * mVerticesNormals[0] + v * mVerticesNormals[1] + w * mVerticesNormals[2];
214+
215+
// If the interpolated normal is degenerated
216+
if (interpolatedNormal.lengthSquare() < MACHINE_EPSILON) {
217+
218+
// Return the original normal
219+
return mNormal;
220+
}
221+
222+
return interpolatedNormal.getUnit();
214223
}
215224

216225
// Update the AABB of a body using its collision shape

0 commit comments

Comments
 (0)