protected override void OnPolygonComplete(Polygon2f input) { polygon = input; polygon.MakeCCW(); polygon.BuildIndices(); polygon.BuildHoleIndices(); if (polygon.IsSimple) { if (mode == TRIANGULATION_MODE.CONSTRAINTED) { mesh = ConstraintedTriangulation2.Triangulate(polygon); } else { ConformingCriteria criteria = new ConformingCriteria(); criteria.angBounds = 0.125f; criteria.lenBounds = 0.2f; criteria.iterations = iterations; mesh = ConformingTriangulation2.Triangulate(polygon, criteria); } } else { mesh = new Mesh2f(0, 0); } }
private void Start() { Polygon2f polygon = CreatePolygon2.FromCircle(new Vector2f(), 1.8f, 32); ConformingCriteria criteria = new ConformingCriteria(); criteria.angBounds = 0.125f; criteria.lenBounds = 0.2f; criteria.iterations = 100; var constructor = new FBMeshConstructor <FBVertex2f, FBFace>(); ConformingTriangulation2.Triangulate(polygon, constructor, criteria); mesh = constructor.PopMesh(); int count = mesh.Vertices.Count; positions = new List <Vector2f>(); for (int i = 0; i < mesh.Vertices.Count; i++) { positions.Add(mesh.Vertices[i].Position); } indices = mesh.CreateFaceIndices(3); CreateConnectionLines(mesh); }
public void Triangulate() { Polygon2f polygon = CreatePolygon2.FromBox(new Vector2f(-1), new Vector2f(1)); Mesh2f mesh = ConformingTriangulation2.Triangulate(polygon); Assert.AreEqual(4, mesh.VerticesCount); Assert.AreEqual(6, mesh.IndicesCount); for (int i = 0; i < mesh.IndicesCount / 3; i++) { Vector2f a = mesh.Positions[mesh.Indices[i * 3 + 0]]; Vector2f b = mesh.Positions[mesh.Indices[i * 3 + 1]]; Vector2f c = mesh.Positions[mesh.Indices[i * 3 + 2]]; Triangle2f tri = new Triangle2f(a, b, c); Assert.IsTrue(tri.SignedArea > 0); } }