2
0
Эх сурвалжийг харах

Discarding slivers when building a mesh shape (#606)

When slivers are added to a mesh shape, collision detection with these triangles will result in triangle_normal being zero in CollideConvexVsTriangles::Collide. ActiveEdges::FixNormal will sometimes find that the hit is an interior hit and return the triangle normal as penetration axis. This penetration axis which will be normalized in PhysicsSystem::ReductionCollideShapeCollector and result in a NaN causing the simulation to hang indefinitely the next time step. To fix this, we remove slivers when sanitizing a MeshShapeSettings.

This should fix godot-jolt/godot-jolt#485.
Jorrit Rouwe 2 жил өмнө
parent
commit
ea83565e61

+ 7 - 0
Jolt/Physics/Collision/Shape/MeshShape.cpp

@@ -95,7 +95,14 @@ void MeshShapeSettings::Sanitize()
 	for (int t = (int)mIndexedTriangles.size() - 1; t >= 0; --t)
 	{
 		const IndexedTriangle &tri = mIndexedTriangles[t];
+
+		// Get vertices
+		Vec3 v0(mTriangleVertices[tri.mIdx[0]]);
+		Vec3 v1(mTriangleVertices[tri.mIdx[1]]);
+		Vec3 v2(mTriangleVertices[tri.mIdx[2]]);
+
 		if (tri.IsDegenerate()										// Degenerate triangle
+			|| (v1 - v0).Cross(v2 - v0).IsNearZero()				// Sliver
 			|| !triangles.insert(tri.GetLowestIndexFirst()).second) // Duplicate triangle
 		{
 			// The order of triangles doesn't matter (gets reordered while building the tree), so we can just swap the last triangle into this slot