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); }
protected virtual void Update() { if (Input.GetKeyDown(KeyCode.F1)) { ResetInput(); MadePolygon = true; OnPolygonComplete(CreatePolygon2.FromBox(new Vector2f(-1), new Vector2f(1))); } else if (Input.GetKeyDown(KeyCode.F2)) { ResetInput(); Polygon2f box = CreatePolygon2.FromBox(new Vector2f(-1), new Vector2f(1)); Polygon2f hole = CreatePolygon2.FromBox(new Vector2f(-0.5f), new Vector2f(0.5f)); hole.MakeCW(); box.AddHole(hole); MadePolygon = true; OnPolygonComplete(box); } else if (Input.GetKeyDown(KeyCode.F3)) { ResetInput(); Polygon2f circle = CreatePolygon2.FromCircle(new Vector2f(-1), 1, 16); MadePolygon = true; OnPolygonComplete(circle); } else if (Input.GetKeyDown(KeyCode.F4)) { ResetInput(); Polygon2f circle = CreatePolygon2.FromCircle(new Vector2f(0), 1, 16); Polygon2f hole = CreatePolygon2.FromCircle(new Vector2f(0), 0.5f, 16); hole.MakeCW(); circle.AddHole(hole); MadePolygon = true; OnPolygonComplete(circle); } else if (Input.GetKeyDown(KeyCode.F5)) { ResetInput(); Polygon2f capsule = CreatePolygon2.FromCapsule(new Vector2f(0), 1, 1, 16); MadePolygon = true; OnPolygonComplete(capsule); } else if (Input.GetKeyDown(KeyCode.F6)) { ResetInput(); Polygon2f cathedral = CreatePolygon2.FromCapsule(new Vector2f(0), 1, 1, 16); for (float x = -0.5f; x <= 0.5f; x += 1.0f) { for (float y = -0.75f; y <= 0.75f; y += 0.5f) { Polygon2f pillar = CreatePolygon2.FromCircle(new Vector2f(x, y), 0.1f, 16); pillar.MakeCW(); cathedral.AddHole(pillar); } } MadePolygon = true; OnPolygonComplete(cathedral); } else { bool leftMouseClicked = Input.GetMouseButtonDown(0); if (leftMouseClicked) { Vector2f point = GetMousePosition(); OnLeftClick(point); } if (Input.GetKeyDown(KeyCode.Space)) { ResetInput(); OnPolygonCleared(); } else if (!MadePolygon) { Vector2f point = GetMousePosition(); point = SnapToPolygon(point); if (leftMouseClicked) { if (Points == null) { CreatePoints(); AddPoint(point); AddPoint(point); } else { if (PolygonClosed()) { ClosePolygon(); MadePolygon = true; OnPolygonComplete(new Polygon2f(Points.ToArray())); } else { AddPoint(point); } } } else { MoveLastPoint(point); } } } }