From 8cb945021757deb0dc51a867823fe218195253bb Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 19 Oct 2016 16:55:16 +0300 Subject: [PATCH] CaveGenerator doesn't attempt to create triangles whose area is too small for Farseer to handle --- Subsurface/Source/Map/Levels/CaveGenerator.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Subsurface/Source/Map/Levels/CaveGenerator.cs b/Subsurface/Source/Map/Levels/CaveGenerator.cs index 7f68a6a0a..539cb595c 100644 --- a/Subsurface/Source/Map/Levels/CaveGenerator.cs +++ b/Subsurface/Source/Map/Levels/CaveGenerator.cs @@ -419,9 +419,12 @@ namespace Barotrauma for (int i = 0; i < triangles.Count; i++) { - if (triangles[i][0].Y == triangles[i][1].Y && triangles[i][0].Y == triangles[i][2].Y) continue; - if (triangles[i][0].X == triangles[i][1].X && triangles[i][0].X == triangles[i][2].X) continue; - + //don't create a triangle if any of the vertices are too close to each other + //(apparently Farseer doesn't like polygons with a very small area, see Shape.ComputeProperties) + if (Vector2.Distance(triangles[i][0], triangles[i][1]) < 0.05f || + Vector2.Distance(triangles[i][0], triangles[i][2]) < 0.05f || + Vector2.Distance(triangles[i][1], triangles[i][2]) < 0.05f) continue; + Vertices bodyVertices = new Vertices(triangles[i]); FixtureFactory.AttachPolygon(bodyVertices, 5.0f, cellBody); }