Beispiel #1
0
        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" : "");

            _canvas.Input  = input;
            _canvas.Output = output;
            _canvas.Invalidate();
        }