Пример #1
0
        private VertexStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType)
        {
            List <List <IntPoint> > aPolys = VertexSourceToClipperPolygons.CreatePolygons(a);
            List <List <IntPoint> > bPolys = VertexSourceToClipperPolygons.CreatePolygons(b);

            Clipper clipper = new Clipper();

            clipper.AddPaths(aPolys, PolyType.ptSubject, true);
            clipper.AddPaths(bPolys, PolyType.ptClip, true);

            List <List <IntPoint> > intersectedPolys = new List <List <IntPoint> >();

            clipper.Execute(clipType, intersectedPolys);

            VertexStorage output = VertexSourceToClipperPolygons.CreateVertexStorage(intersectedPolys);

            output.Add(0, 0, ShapePath.FlagsAndCommand.Stop);

            return(output);
        }
        public static Mesh Revolve(IVertexSource source, int angleSteps = 30, double angleStart = 0, double angleEnd = MathHelper.Tau)
        {
            // convert to clipper polygons and scale so we can ensure good shapes
            Polygons polygons = VertexSourceToClipperPolygons.CreatePolygons(source);
            // ensure good winding and consistent shapes
            // clip against x=0 left and right
            // mirror left material across the origin
            // union mirrored left with right material
            // convert the data back to PathStorage
            PathStorage cleanedPath = VertexSourceToClipperPolygons.CreatePathStorage(polygons);

            Mesh mesh = new Mesh();

            // check if we need to make closing faces
            if (angleStart != 0 || angleEnd != MathHelper.Tau)
            {
                // make a face for the start and end
            }

            // make the outside shell
            double angleDelta   = (angleEnd - angleStart) / angleSteps;
            double currentAngle = 0;

            for (currentAngle = angleStart; currentAngle < angleEnd - angleDelta - EqualityTolerance; currentAngle += angleDelta)
            {
                AddRevolveStrip(cleanedPath, mesh, currentAngle, currentAngle + angleDelta);
            }

            AddRevolveStrip(cleanedPath, mesh, currentAngle, currentAngle + angleDelta);

            // TODO: get this working.
            mesh.CleanAndMergMesh(.0001);

            // return the completed mesh
            return(mesh);
        }
Пример #3
0
        private void RenderPolygonToPathAgainst(Graphics2D graphics2D)
        {
            IVertexSource pathToUse = null;

            switch (shapeTypeRadioGroup.SelectedIndex)
            {
            case 0:    // simple polygon map
            {
                PathStorage ps1 = new PathStorage();

                ps1.MoveTo(85, 417);
                ps1.LineTo(338, 428);
                ps1.LineTo(344, 325);
                ps1.LineTo(399, 324);
                ps1.LineTo(400, 421);
                ps1.LineTo(644, 415);
                ps1.LineTo(664, 75);
                ps1.LineTo(98, 81);
                ps1.ClosePolygon();

                ps1.MoveTo(343, 290);
                ps1.LineTo(159, 235);
                ps1.LineTo(154, 162);
                ps1.LineTo(340, 114);
                ps1.ClosePolygon();

                ps1.MoveTo(406, 121);
                ps1.LineTo(587, 158);
                ps1.LineTo(591, 236);
                ps1.LineTo(404, 291);
                ps1.ClosePolygon();

                pathToUse = ps1;
            }
            break;

            case 1:     // multiple pegs
            {
                PathStorage ps2 = new PathStorage();

                double x = 0;
                double y = 0;

                ps2.MoveTo(100 + 32, 100 + 77);
                ps2.LineTo(100 + 473, 100 + 263);
                ps2.LineTo(100 + 351, 100 + 290);
                ps2.LineTo(100 + 354, 100 + 374);

                pathToUse = ps2;
            }
            break;

            case 2:
            {
                // circle holes
                PathStorage ps1 = new PathStorage();

                double x = 0;
                double y = 0;
                ps1.MoveTo(x + 140, y + 145);
                ps1.LineTo(x + 225, y + 44);
                ps1.LineTo(x + 296, y + 219);
                ps1.ClosePolygon();

                ps1.LineTo(x + 226, y + 289);
                ps1.LineTo(x + 82, y + 292);
                ps1.ClosePolygon();

                ps1.MoveTo(x + 220 - 50, y + 222);
                ps1.LineTo(x + 265 - 50, y + 331);
                ps1.LineTo(x + 363 - 50, y + 249);
                ps1.ClosePolygon();

                pathToUse = ps1;
            }
            break;

            case 3:     // Great Britain
            {
                PathStorage gb_poly = new PathStorage();
                GreatBritanPathStorage.Make(gb_poly);

                Affine mtx1 = Affine.NewIdentity();
                Affine mtx2 = Affine.NewIdentity();
                mtx1 *= Affine.NewTranslation(-1150, -1150);
                mtx1 *= Affine.NewScaling(2.0);

                mtx2  = mtx1;
                mtx2 *= Affine.NewTranslation(Width / 2, Height / 2);

                VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);

                pathToUse = trans_gb_poly;
            }
            break;

            case 4:     // Arrows
            {
                PathStorage arrows = new PathStorage();
                make_arrows(arrows);

                Affine mtx1 = Affine.NewIdentity();
                mtx1 *= Affine.NewTranslation(-1150, -1150);
                mtx1 *= Affine.NewScaling(2.0);

                VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx1);

                pathToUse = trans_arrows;
            }
            break;

            case 5:     // Spiral
            {
                spiral sp     = new spiral(Width / 2, Height / 2, 10, 150, 30, 0.0);
                Stroke stroke = new Stroke(sp);
                stroke.width(15.0);

                Affine mtx = Affine.NewIdentity();;
                mtx *= Affine.NewTranslation(-1150, -1150);
                mtx *= Affine.NewScaling(2.0);

                pathToUse = stroke;
            }
            break;

            case 6:     // Glyph
            {
                //------------------------------------
                // Spiral and glyph
                //
                PathStorage glyph = new PathStorage();
                glyph.MoveTo(28.47, 6.45);
                glyph.curve3(21.58, 1.12, 19.82, 0.29);
                glyph.curve3(17.19, -0.93, 14.21, -0.93);
                glyph.curve3(9.57, -0.93, 6.57, 2.25);
                glyph.curve3(3.56, 5.42, 3.56, 10.60);
                glyph.curve3(3.56, 13.87, 5.03, 16.26);
                glyph.curve3(7.03, 19.58, 11.99, 22.51);
                glyph.curve3(16.94, 25.44, 28.47, 29.64);
                glyph.LineTo(28.47, 31.40);
                glyph.curve3(28.47, 38.09, 26.34, 40.58);
                glyph.curve3(24.22, 43.07, 20.17, 43.07);
                glyph.curve3(17.09, 43.07, 15.28, 41.41);
                glyph.curve3(13.43, 39.75, 13.43, 37.60);
                glyph.LineTo(13.53, 34.77);
                glyph.curve3(13.53, 32.52, 12.38, 31.30);
                glyph.curve3(11.23, 30.08, 9.38, 30.08);
                glyph.curve3(7.57, 30.08, 6.42, 31.35);
                glyph.curve3(5.27, 32.62, 5.27, 34.81);
                glyph.curve3(5.27, 39.01, 9.57, 42.53);
                glyph.curve3(13.87, 46.04, 21.63, 46.04);
                glyph.curve3(27.59, 46.04, 31.40, 44.04);
                glyph.curve3(34.28, 42.53, 35.64, 39.31);
                glyph.curve3(36.52, 37.21, 36.52, 30.71);
                glyph.LineTo(36.52, 15.53);
                glyph.curve3(36.52, 9.13, 36.77, 7.69);
                glyph.curve3(37.01, 6.25, 37.57, 5.76);
                glyph.curve3(38.13, 5.27, 38.87, 5.27);
                glyph.curve3(39.65, 5.27, 40.23, 5.62);
                glyph.curve3(41.26, 6.25, 44.19, 9.18);
                glyph.LineTo(44.19, 6.45);
                glyph.curve3(38.72, -0.88, 33.74, -0.88);
                glyph.curve3(31.35, -0.88, 29.93, 0.78);
                glyph.curve3(28.52, 2.44, 28.47, 6.45);
                glyph.ClosePolygon();

                glyph.MoveTo(28.47, 9.62);
                glyph.LineTo(28.47, 26.66);
                glyph.curve3(21.09, 23.73, 18.95, 22.51);
                glyph.curve3(15.09, 20.36, 13.43, 18.02);
                glyph.curve3(11.77, 15.67, 11.77, 12.89);
                glyph.curve3(11.77, 9.38, 13.87, 7.06);
                glyph.curve3(15.97, 4.74, 18.70, 4.74);
                glyph.curve3(22.41, 4.74, 28.47, 9.62);
                glyph.ClosePolygon();

                Affine mtx = Affine.NewIdentity();
                mtx *= Affine.NewScaling(4.0);
                mtx *= Affine.NewTranslation(220, 200);
                VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx);
                FlattenCurves curve = new FlattenCurves(trans);

                pathToUse = curve;
            }
            break;
            }

            graphics2D.Render(pathToUse, fillColor);

            PathStorage travelLine = new PathStorage();

            travelLine.MoveTo(lineStart);
            travelLine.LineTo(mousePosition);

            Polygons polygonsToPathAround = VertexSourceToClipperPolygons.CreatePolygons(pathToUse, 1);

            polygonsToPathAround = FixWinding(polygonsToPathAround);

            Polygons travelPolysLine = VertexSourceToClipperPolygons.CreatePolygons(travelLine, 1);

            CreateAndRenderPathing(graphics2D, polygonsToPathAround, travelPolysLine);
        }