Exemplo n.º 1
0
        static void Main(string[] args)
        {
            CappedCylinderGenerator cylgen = new CappedCylinderGenerator()
            {
                BaseRadius = 10, TopRadius = 5, Height = 20, Slices = 32
            };
            DMesh3 mesh = cylgen.Generate().MakeDMesh();

            MeshTransforms.ConvertYUpToZUp(mesh);       // g3 meshes are usually Y-up

            // center mesh above origin
            AxisAlignedBox3d bounds       = mesh.CachedBounds;
            Vector3d         baseCenterPt = bounds.Center - bounds.Extents.z * Vector3d.AxisZ;

            MeshTransforms.Translate(mesh, -baseCenterPt);

            // create print mesh set
            PrintMeshAssembly meshes = new PrintMeshAssembly();

            meshes.AddMesh(mesh, PrintMeshOptions.Default());

            // create settings
            //MakerbotSettings settings = new MakerbotSettings(Makerbot.Models.Replicator2);
            //PrintrbotSettings settings = new PrintrbotSettings(Printrbot.Models.Plus);
            //MonopriceSettings settings = new MonopriceSettings(Monoprice.Models.MP_Select_Mini_V2);
            RepRapSettings settings = new RepRapSettings(RepRap.Models.Unknown);

            // do slicing
            MeshPlanarSlicer slicer = new MeshPlanarSlicer()
            {
                LayerHeightMM = settings.LayerHeightMM
            };

            slicer.Add(meshes);
            PlanarSliceStack slices = slicer.Compute();

            // run print generator
            SingleMaterialFFFPrintGenerator printGen =
                new SingleMaterialFFFPrintGenerator(meshes, slices, settings);

            if (printGen.Generate())
            {
                // export gcode
                GCodeFile gcode = printGen.Result;
                using (StreamWriter w = new StreamWriter("c:\\demo\\cone.gcode")) {
                    StandardGCodeWriter writer = new StandardGCodeWriter();
                    writer.WriteFile(gcode, w);
                }
            }
        }
Exemplo n.º 2
0
    public IEnumerable <Progress> GenerateGCodeFile()
    {
        // run print generator
        // do slicing
        var slicer = new MeshPlanarSlicer()
        {
            LayerHeightMM = settings.LayerHeightMM
        };

        slicer.Add(meshes);
        foreach (var i in slicer.Compute())
        {
            yield return(i);
        }
        PlanarSliceStack slices = slicer.Result;

        var printGen = new SingleMaterialFFFPrintGenerator(meshes, slices, settings);

        foreach (var i in printGen.Generate())
        {
            yield return(i);
        }
        gcode = printGen.Result;
    }
Exemplo n.º 3
0
            public void Compute()
            {
                RequestCancel = false;

                printer =
                    new SingleMaterialFFFPrintGenerator(Meshes, SliceSet, PrintSettings);

                if (PrintSettings.EnableSupportReleaseOpt)
                {
                    printer.LayerPostProcessor = new SupportConnectionPostProcessor()
                    {
                        ZOffsetMM = PrintSettings.SupportReleaseGap
                    };
                }

                // if we aren't interpreting GCode, we want generator to return its path set
                printer.AccumulatePathSet = (InterpretGCodePaths == false);

                // set clip region
                Box2d clip_box = new Box2d(Vector2d.Zero,
                                           new Vector2d(CC.Settings.BedSizeXMM / 2, CC.Settings.BedSizeYMM / 2));

                printer.PathClipRegions = new List <GeneralPolygon2d>()
                {
                    new GeneralPolygon2d(new Polygon2d(clip_box.ComputeVertices()))
                };

                printer.ErrorF = (msg, trace) => {
                    if (RequestCancel == false)
                    {
                        DebugUtil.Log(2, "Slicer Error! msg: {0} stack {1}", msg, trace);
                    }
                };

                DebugUtil.Log(2, "Generating gcode...");

                try {
                    if (printer.Generate() == false)
                    {
                        throw new Exception("generate failed");   // this will be caught below
                    }
                    gcode = printer.Result;

                    //DebugUtil.Log(2, "Interpreting gcode...");

                    if (InterpretGCodePaths)
                    {
                        GCodeToToolpaths    converter   = new GCodeToToolpaths();
                        MakerbotInterpreter interpreter = new MakerbotInterpreter();
                        interpreter.AddListener(converter);
                        InterpretArgs interpArgs = new InterpretArgs();
                        interpreter.Interpret(gcode, interpArgs);
                        paths = converter.PathSet;
                    }
                    else
                    {
                        paths = printer.AccumulatedPaths;
                    }

                    //DebugUtil.Log(2, "Detecting layers...");

                    layerInfo = new LayersDetector(paths);

                    Success = true;
                } catch (Exception e) {
                    DebugUtil.Log("ToolpathGenerator.Compute: exception: " + e.Message);
                    Success = false;
                }

                Finished = true;
            }
Exemplo n.º 4
0
        static void GenerateGCodeForSliceFile(string sliceFile)
        {
            PlanarSliceStack slices = new PlanarSliceStack();

            using (TextReader reader = new StreamReader(sliceFile)) {
                slices.ReadSimpleSliceFormat(reader);
            }

            // configure settings
            MakerbotSettings settings = new MakerbotSettings(Makerbot.Models.Replicator2);

            //MonopriceSettings settings = new MonopriceSettings(Monoprice.Models.MP_Select_Mini_V2);
            //PrintrbotSettings settings = new PrintrbotSettings(Printrbot.Models.Plus);
            settings.Shells = 2;
            settings.SparseLinearInfillStepX   = 10;
            settings.InteriorSolidRegionShells = 1;
            settings.ClipSelfOverlaps          = true;
            settings.GenerateSupport           = true;
            settings.SupportSpacingStepX       = 5.0;
            settings.SupportVolumeScale        = 1.0;

            //settings.LayerRangeFilter = new Interval1i(0,10);


            LastSettings = settings.CloneAs <SingleMaterialFFFSettings>();

            // empty...
            PrintMeshAssembly meshes = new PrintMeshAssembly();

            // run print generator
            SingleMaterialFFFPrintGenerator printGen =
                new SingleMaterialFFFPrintGenerator(meshes, slices, settings);

            printGen.LayerPostProcessor = new SupportConnectionPostProcessor()
            {
                ZOffsetMM = 0.15f
            };
            printGen.AccumulatePathSet = (SHOW_RELOADED_GCODE_PATHS == false);

            printGen.Generate();
            GCodeFile genGCode = printGen.Result;

            string sWritePath          = "../../../sample_output/generated.gcode";
            StandardGCodeWriter writer = new StandardGCodeWriter();

            using (StreamWriter w = new StreamWriter(sWritePath)) {
                writer.WriteFile(genGCode, w);
            }

            if (settings is MakerbotSettings)
            {
                System.Diagnostics.Process.Start(GPX_PATH, "-p " + sWritePath);
            }

            if (SHOW_RELOADED_GCODE_PATHS)
            {
                LoadGeneratedGCodeFile(sWritePath);
            }
            else
            {
                View.SetPaths(printGen.AccumulatedPaths, settings);
            }
        }
Exemplo n.º 5
0
        static string GenerateGCodeForMeshes(PrintMeshAssembly meshes)
        {
            bool ENABLE_SUPPORT_ZSHIFT = true;

            // configure settings
            //MakerbotSettings settings = new MakerbotSettings(Makerbot.Models.Replicator2);
            //FlashforgeSettings settings = new FlashforgeSettings(Flashforge.Models.CreatorPro);
            //MonopriceSettings settings = new MonopriceSettings(Monoprice.Models.MP_Select_Mini_V2);
            PrintrbotSettings settings = new PrintrbotSettings(Printrbot.Models.Plus);

            //PrusaSettings settings = new PrusaSettings(Prusa.Models.i3_MK3);

            //settings.ExtruderTempC = 215;
            //settings.Machine.NozzleDiamMM = 0.4;
            settings.Shells = 2;
            settings.InteriorSolidRegionShells = 0;
            settings.SparseLinearInfillStepX   = 5;
            //settings.SolidFillNozzleDiamStepX = 0;
            //settings.SolidFillBorderOverlapX = 0;
            //settings.SparseFillBorderOverlapX = 0;
            settings.ClipSelfOverlaps = false;
            //settings.RoofLayers = settings.FloorLayers = 0;
            //settings.LayerRangeFilter = new Interval1i(245, 255);
            //settings.LayerRangeFilter = new Interval1i(0, 0);

            settings.EnableBridging = true;

            settings.GenerateSupport         = false;
            settings.EnableSupportShell      = true;
            settings.SupportMinZTips         = false;
            settings.SupportSolidSpace       = 0.35;
            settings.SupportOverhangAngleDeg = 25;

            //settings.OuterShellLast = true;
            //settings.Shells = 0;

            //settings.Machine.NozzleDiamMM = 0.75;
            //settings.Machine.MaxLayerHeightMM = 0.5;
            //settings.FillPathSpacingMM = settings.Machine.NozzleDiamMM;
            //settings.LayerHeightMM = 0.5;

            settings.StartLayers        = 0;
            settings.StartLayerHeightMM = 0.3;


            //settings.LayerRangeFilter = new Interval1i(130, 140);

            LastSettings = settings.CloneAs <SingleMaterialFFFSettings>();

            System.Console.WriteLine("Slicing...");

            // slice meshes
            MeshPlanarSlicer slicer = new MeshPlanarSlicer()
            {
                LayerHeightMM = settings.LayerHeightMM
            };

            if (settings.StartLayers > 0)
            {
                int    start_layers       = settings.StartLayers;
                double std_layer_height   = settings.LayerHeightMM;
                double start_layer_height = settings.StartLayerHeightMM;
                slicer.LayerHeightF = (layer_i) => {
                    return((layer_i < start_layers) ? start_layer_height : std_layer_height);
                };
            }

            slicer.Add(meshes);
            PlanarSliceStack slices = slicer.Compute();

            System.Console.WriteLine("Generating GCode...");

            // run print generator
            SingleMaterialFFFPrintGenerator printGen =
                new SingleMaterialFFFPrintGenerator(meshes, slices, settings);

            if (ENABLE_SUPPORT_ZSHIFT)
            {
                printGen.LayerPostProcessor = new SupportConnectionPostProcessor()
                {
                    ZOffsetMM = 0.2f
                }
            }
            ;
            printGen.AccumulatePathSet = (SHOW_RELOADED_GCODE_PATHS == false);

            printGen.Generate();
            GCodeFile genGCode = printGen.Result;

            System.Console.WriteLine("Writing GCode...");

            string sWritePath          = "../../../sample_output/generated.gcode";
            StandardGCodeWriter writer = new StandardGCodeWriter();

            using (StreamWriter w = new StreamWriter(sWritePath)) {
                writer.WriteFile(genGCode, w);
            }

            if (settings is ISailfishSettings)
            {
                System.Diagnostics.Process.Start(GPX_PATH, (settings as ISailfishSettings).GPXModelFlag + " -p " + sWritePath);
            }

            View.PathDiameterMM = (float)settings.Machine.NozzleDiamMM - 0.005f;

            if (SHOW_RELOADED_GCODE_PATHS == false)
            {
                View.SetPaths(printGen.AccumulatedPaths, settings);
                View.SetSlices(slices);
            }

            return(sWritePath);
        }