{"action":"created","issue":{"url":"https://api.github.com/repos/speps/LibTessDotNet/issues/6","labels_url":"https://api.github.com/repos/speps/LibTessDotNet/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/speps/LibTessDotNet/issues/6/comments","events_url":"https://api.github.com/repos/speps/LibTessDotNet/issues/6/events","html_url":"https://github.com/speps/LibTessDotNet/issues/6","id":102180689,"number":6,"title":"Zero-width triangles are producedm (They have no area as one point is between the two others)","user":{"login":"KellanHiggins","id":5897704,"avatar_url":"https://avatars.githubusercontent.com/u/5897704?v=3","gravatar_id":"","url":"https://api.github.com/users/KellanHiggins","html_url":"https://github.com/KellanHiggins","followers_url":"https://api.github.com/users/KellanHiggins/followers","following_url":"https://api.github.com/users/KellanHiggins/following{/other_user}","gists_url":"https://api.github.com/users/KellanHiggins/gists{/gist_id}","starred_url":"https://api.github.com/users/KellanHiggins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KellanHiggins/subscriptions","organizations_url":"https://api.github.com/users/KellanHiggins/orgs","repos_url":"https://api.github.com/users/KellanHiggins/repos","events_url":"https://api.github.com/users/KellanHiggins/events{/privacy}","received_events_url":"https://api.github.com/users/KellanHiggins/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/speps/LibTessDotNet/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"speps","id":16678,"avatar_url":"https://avatars.githubusercontent.com/u/16678?v=3","gravatar_id":"","url":"https://api.github.com/users/speps","html_url":"https://github.com/speps","followers_url":"https://api.github.com/users/speps/followers","following_url":"https://api.github.com/users/speps/following{/other_user}","gists_url":"https://api.github.com/users/speps/gists{/gist_id}","starred_url":"https://api.github.com/users/speps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/speps/subscriptions","organizations_url":"https://api.github.com/users/speps/orgs","repos_url":"https://api.github.com/users/speps/repos","events_url":"https://api.github.com/users/speps/events{/privacy}","received_events_url":"https://api.github.com/users/speps/received_events","type":"User","site_admin":false},"milestone":null,"comments":16,"created_at":"2015-08-20T16:43:48Z","updated_at":"2016-01-29T22:27:10Z","closed_at":null,"body":"First off, great port. This saved me probably years of time when generating meshes from complex shapes. But I am having an issue with zero width triangles.\r\n\r\nWhen tessellating a 6 sided box, zero width triangles are being generated. These zero-width triangles then mess up my tangent calculation in Unity.\r\n\r\nHere is a picture of the box.\r\n\r\n![triangleissue](https://cloud.githubusercontent.com/assets/5897704/9389299/3338f4fc-471f-11e5-97f8-409965f617f7.png)\r\n\r\nThe Triangle is created by using the contour of (2.0, 0.0, 4.0), (2.0, 0.0, 2.0), (4.0, 0.0, 2.0), (4.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 4.0), (2.0, 0.0, 4.0). This will regularly reproduce the issue with the zero width triangle. The triangle of zero with has the points of (0,0,4), (2,0,2), (4,0,0).\r\n\r\nThis also happens with cutouts, creating zero width triangles for cutouts that are on the same level (I am using this for window cutout generation in a wall).\r\n\r\nI tried to dive into the Tessellation code, but that is over my head. I can sort of fix the problem by adding randomization to the contours so I don't get zero width triangles, but it is a pain.\r\n\r\nAny help or even directing me to where this problem might original would be super appreciated!"},"comment":{"url":"https://api.github.com/repos/speps/LibTessDotNet/issues/comments/176997687","html_url":"https://github.com/speps/LibTessDotNet/issues/6#issuecomment-176997687","issue_url":"https://api.github.com/repos/speps/LibTessDotNet/issues/6","id":176997687,"user":{"login":"KellanHiggins","id":5897704,"avatar_url":"https://avatars.githubusercontent.com/u/5897704?v=3","gravatar_id":"","url":"https://api.github.com/users/KellanHiggins","html_url":"https://github.com/KellanHiggins","followers_url":"https://api.github.com/users/KellanHiggins/followers","following_url":"https://api.github.com/users/KellanHiggins/following{/other_user}","gists_url":"https://api.github.com/users/KellanHiggins/gists{/gist_id}","starred_url":"https://api.github.com/users/KellanHiggins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KellanHiggins/subscriptions","organizations_url":"https://api.github.com/users/KellanHiggins/orgs","repos_url":"https://api.github.com/users/KellanHiggins/repos","events_url":"https://api.github.com/users/KellanHiggins/events{/privacy}","received_events_url":"https://api.github.com/users/KellanHiggins/received_events","type":"User","site_admin":false},"created_at":"2016-01-29T22:27:10Z","updated_at":"2016-01-29T22:27:10Z","body":"I wrote a pretty inefficient (I think) removal script. You need to run this at the end of running the method `Tessellate`. \r\n\r\nProblems are that it uses a list to remove the offending triangles. Not great for memory management.\r\n\r\nAlso uses UnityEngine's Vector3 instead of the LibTess's Vector3s to calculate the size of a sphere. To fix this, need to add calculation of magnitude to LibTess's Vector3 and change the code.\r\n\r\nHope this helps someone in the future! Its work for all the cases I've run into so far.\r\n\r\n```\r\n/// <summary>\r\n/// Removes triangles from this tesselated object that are thin enough to be a straight line\r\n/// </summary>\r\nprivate void RemoveZeroAreaTriangles ()\r\n{\r\n\tList<int> zeroAreaTriangleStartIndexes = new List<int>();\r\n\t\r\n\tfor (int n = 0; n < this.Elements.Length; n = n+3)\r\n\t{\r\n\t\tUnityEngine.Vector3 p1 = this.Vertices[this.Elements[n]].Position.ToVector3(); \r\n\t\tUnityEngine.Vector3 p2 = this.Vertices[this.Elements[n + 1]].Position.ToVector3(); \r\n\t\tUnityEngine.Vector3 p3 = this.Vertices[this.Elements[n + 2]].Position.ToVector3(); \r\n\t\t\r\n\t\tif(p1 == p2 || p2 == p3 || p3 == p1)\r\n\t\t{\r\n\t\t\tzeroAreaTriangleStartIndexes.Add(n);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t\r\n\t\tfloat area = CalculateAreaOfTriangle(p1, p2, p3);\r\n\t\t\r\n\t\tif(area == 0 || float.IsNaN(area) || area < 0.1f) // 0.04 will cover walls with a lot of skinny windows up to about 40 meters long. After that, you either get blackness or lightness\r\n\t\t{\r\n\t\t\tif(area > 0)\r\n\t\t\t{\r\n\t\t\t\tif(p1.y == p2.y && p2.y == p3.y)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Also should make sure the triangle is very thin\r\n\t\t\t\t\t// This is a specific fix for the window generation where very small triangles are created\r\n\t\t\t\t\tif(p1.x == p2.x && p2.x == p3.x\r\n\t\t\t\t\t   || p1.z == p2.z && p2.z == p3.z)\r\n\t\t\t\t\t\tzeroAreaTriangleStartIndexes.Add(n);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tzeroAreaTriangleStartIndexes.Add(n);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tif(zeroAreaTriangleStartIndexes.Count > 0)\r\n\t{\r\n\t\tList<int> ElementsList = this._elements.ToList<int>();\r\n\t\t\r\n\t\t// Removes all zero sized area triangles\r\n\t\t// Does this by loading the list and removing at them\r\n\t\tfor(int i = 0; i < zeroAreaTriangleStartIndexes.Count; i++)\r\n\t\t{\r\n\t\t\tElementsList.RemoveRange(zeroAreaTriangleStartIndexes[i] - i * 3, 3);\r\n\t\t}\r\n\t\t\r\n\t\tthis._elements = ElementsList.ToArray<int>();\r\n\t}\r\n}\r\n\r\nprivate float CalculateAreaOfTriangle (UnityEngine.Vector3 p1, UnityEngine.Vector3 p2, UnityEngine.Vector3 p3)\r\n{\r\n\tdouble a = (p1 - p2).magnitude; // pt1.DistanceTo(pt2);\r\n\tdouble b = (p2 - p3).magnitude; // pt2.DistanceTo(pt3);\r\n\tdouble c = (p1 - p3).magnitude; // pt3.DistanceTo(pt1);\r\n\tdouble s = (a + b + c) / 2;\r\n\treturn (float)System.Math.Sqrt(s * (s-a) * (s-b) * (s-c));\r\n}\r\n```"}}