private void RefreshAsset(string name) { var asset = _data.GetAsset(name); _sw.Reset(); foreach (var poly in asset.Polygons) { var v = new ContourVertex[poly.Count]; for (int i = 0; i < poly.Count; i++) { v[i].Position = new Vec3 { X = poly[i].X, Y = poly[i].Y }; v[i].Data = poly[i].Color; } _sw.Start(); _tess.AddContour(v, poly.Orientation); _sw.Stop(); } _sw.Start(); _tess.Tessellate(_windingRule, ElementType.Polygons, _polySize, VertexCombine); _sw.Stop(); var output = new PolygonSet(); for (int i = 0; i < _tess.ElementCount; i++) { var poly = new Polygon(); for (int j = 0; j < _polySize; j++) { int index = _tess.Elements[i * _polySize + j]; if (index == -1) { continue; } var v = new PolygonPoint { X = _tess.Vertices[index].Position.X, Y = _tess.Vertices[index].Position.Y, Color = (Color)_tess.Vertices[index].Data }; poly.Add(v); } output.Add(poly); } statusMain.Text = string.Format("{0:F3} ms - {1} polygons (of {2} vertices) {3}", _sw.Elapsed.TotalMilliseconds, _tess.ElementCount, _polySize, _polySize == 3 ? "... triangles" : ""); _canvas.Input = asset.Polygons; _canvas.Output = output; _canvas.Invalidate(); }
private static PolygonSet FromP2T(Poly2Tri.PolygonSet pset) { var result = new PolygonSet(); foreach (var poly in pset.Polygons) { foreach (var tri in poly.Triangles) { var rtri = new Polygon(); rtri.Add(new PolygonPoint { X = tri.Points[0].Xf, Y = tri.Points[0].Yf }); rtri.Add(new PolygonPoint { X = tri.Points[1].Xf, Y = tri.Points[1].Yf }); rtri.Add(new PolygonPoint { X = tri.Points[2].Xf, Y = tri.Points[2].Yf }); result.Add(rtri); } } return(result); }
private static PolygonSet FromTess(Tess tess) { var output = new PolygonSet(); for (int i = 0; i < tess.ElementCount; i++) { var poly = new Polygon(); for (int j = 0; j < 3; j++) { int index = tess.Elements[i * 3 + j]; if (index == -1) { continue; } var v = new PolygonPoint { X = tess.Vertices[index].Position.X, Y = tess.Vertices[index].Position.Y }; poly.Add(v); } output.Add(poly); } return(output); }
private void RefreshAsset(PolygonSet polygons) { _sw.Reset(); foreach (var poly in polygons) { var v = new ContourVertex[poly.Count]; for (int i = 0; i < poly.Count; i++) { v[i].Position = new Vec3 { X = poly[i].X, Y = poly[i].Y, Z = poly[i].Z }; v[i].Data = poly[i].Color; } _sw.Start(); _tess.AddContour(v, poly.Orientation); _sw.Stop(); } _sw.Start(); _tess.Tessellate(_windingRule, ElementType.Polygons, _polySize, VertexCombine); _sw.Stop(); var output = new PolygonSet(); for (int i = 0; i < _tess.ElementCount; i++) { var poly = new Polygon(); for (int j = 0; j < _polySize; j++) { int index = _tess.Elements[i * _polySize + j]; if (index == -1) { continue; } var proj = Project(_tess.Vertices[index].Position); var v = new PolygonPoint { X = proj.X, Y = proj.Y, Color = (Color)_tess.Vertices[index].Data }; poly.Add(v); } output.Add(poly); } var input = new PolygonSet(); foreach (var poly in polygons) { var projPoly = new Polygon(); for (int i = 0; i < poly.Count; i++) { var proj = Project(new Vec3 { X = poly[i].X, Y = poly[i].Y, Z = poly[i].Z }); var v = new PolygonPoint { X = proj.X, Y = proj.Y, Color = poly[i].Color }; projPoly.Add(v); } input.Add(projPoly); } statusMain.Text = string.Format("{0:F3} ms - {1} polygons (of {2} vertices) {3}", _sw.Elapsed.TotalMilliseconds, _tess.ElementCount, _polySize, _polySize == 3 ? "... triangles" : ""); /*string debugBalance = DebugPoolBalanceChecker.GetDebugAboutPoolBalanceAll(); * if (!debugBalance.Equals("")) MessageBox.Show("debugBalance: " + debugBalance);*/ _canvas.Input = input; _canvas.Output = output; _canvas.Invalidate(); }