public SliceFeature(Mesh input) { MeshCheck meshCheck = new MeshCheck(); meshCheck.setMesh(input); DMesh3 mesh = meshCheck.ToUnityWatertightMesh().ToDMesh3(); if (!mesh.IsClosed()) { return; } // 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 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); settings = new RepRapSettings(RepRap.Models.Unknown); }
public static void Main(string[] args) { ExceptionManager.UnhandledException += delegate(UnhandledExceptionArgs expArgs) { Console.WriteLine(expArgs.ExceptionObject.ToString()); expArgs.ExitApplication = true; }; Gtk.Application.Init(); MainWindow = new Window("gsCNCViewer"); MainWindow.SetDefaultSize(900, 600); MainWindow.SetPosition(WindowPosition.Center); MainWindow.DeleteEvent += delegate { Gtk.Application.Quit(); }; //DMesh3 part = StandardMeshReader.ReadMesh("../../../sample_files/hemisphere_h2p4.obj"); //DMesh3 stock = StandardMeshReader.ReadMesh("../../../sample_files/stock_5x5x2p5.obj"); DMesh3 part = StandardMeshReader.ReadMesh("../../../sample_files/mechpart1.obj"); DMesh3 stock = StandardMeshReader.ReadMesh("../../../sample_files/mechpart1_stock.obj"); PrintMeshAssembly meshes = new PrintMeshAssembly(); meshes.AddMesh(stock); meshes.AddMesh(part, PrintMeshOptions.Cavity()); View = new SliceViewCanvas(); MainWindow.Add(View); //DMesh3 tube_mesh = GenerateTubeMeshesForGCode("c:\\Users\\rms\\Downloads\\gear train.nc"); //StandardMeshWriter.WriteMesh("../../../sample_output/tubes.obj", tube_mesh, WriteOptions.Defaults); string sPath = GenerateGCodeForMeshes(meshes); if (SHOW_RELOADED_GCODE_PATHS) { LoadGeneratedGCodeFile(sPath); } MainWindow.KeyReleaseEvent += Window_KeyReleaseEvent; // support drag-drop Gtk.TargetEntry[] target_table = new TargetEntry[] { new TargetEntry("text/uri-list", 0, 0), }; Gtk.Drag.DestSet(MainWindow, DestDefaults.All, target_table, Gdk.DragAction.Copy); MainWindow.DragDataReceived += MainWindow_DragDataReceived;; MainWindow.ShowAll(); Gtk.Application.Run(); }
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); } } }
public void Compute() { int N = meshToScene.Length; slicer = new MeshPlanarSlicerPro() { LayerHeightMM = CC.Settings.LayerHeightMM, // [RMS] 1.5 here is a hack. If we don't leave a bit of space then often the filament gets squeezed right at // inside/outside transitions, which is bad. Need a better way to handle. OpenPathDefaultWidthMM = CC.Settings.NozzleDiameterMM * 1.5, SetMinZValue = 0, SliceFactoryF = PlanarSlicePro.FactoryF }; if (CC.Settings.OpenMode == PrintSettings.OpenMeshMode.Clipped) { slicer.DefaultOpenPathMode = PrintMeshOptions.OpenPathsModes.Clipped; } else if (CC.Settings.OpenMode == PrintSettings.OpenMeshMode.Embedded) { slicer.DefaultOpenPathMode = PrintMeshOptions.OpenPathsModes.Embedded; } else if (CC.Settings.OpenMode == PrintSettings.OpenMeshMode.Ignored) { slicer.DefaultOpenPathMode = PrintMeshOptions.OpenPathsModes.Ignored; } if (CC.Settings.StartLayers > 0) { int start_layers = CC.Settings.StartLayers; double std_layer_height = CC.Settings.LayerHeightMM; double start_layer_height = CC.Settings.StartLayerHeightMM; slicer.LayerHeightF = (layer_i) => { return((layer_i < start_layers) ? start_layer_height : std_layer_height); }; } try { assembly = new PrintMeshAssembly(); for (int k = 0; k < N; ++k) { DMesh3 mesh = meshCopies[k]; Frame3f mapF = meshToScene[k]; PrintMeshSettings settings = meshSettings[k]; PrintMeshOptions options = new PrintMeshOptions(); options.IsSupport = (settings.ObjectType == PrintMeshSettings.ObjectTypes.Support); options.IsCavity = (settings.ObjectType == PrintMeshSettings.ObjectTypes.Cavity); options.IsCropRegion = (settings.ObjectType == PrintMeshSettings.ObjectTypes.CropRegion); options.IsOpen = false; if (settings.OuterShellOnly) { options.IsOpen = true; } options.OpenPathMode = PrintMeshSettings.Convert(settings.OpenMeshMode); options.Extended = new ExtendedPrintMeshOptions() { ClearanceXY = settings.Clearance, OffsetXY = settings.OffsetXY }; Vector3f scale = localScale[k]; MeshTransforms.Scale(mesh, scale.x, scale.y, scale.z); MeshTransforms.FromFrame(mesh, mapF); MeshTransforms.FlipLeftRightCoordSystems(mesh); MeshTransforms.ConvertYUpToZUp(mesh); MeshAssembly decomposer = new MeshAssembly(mesh); decomposer.HasNoVoids = settings.NoVoids; decomposer.Decompose(); assembly.AddMeshes(decomposer.ClosedSolids, options); PrintMeshOptions openOptions = options.Clone(); assembly.AddMeshes(decomposer.OpenMeshes, openOptions); } if (slicer.Add(assembly) == false) { throw new Exception("error adding PrintMeshAssembly to Slicer!!"); } // set clip box Box2d clip_box = new Box2d(Vector2d.Zero, new Vector2d(CC.Settings.BedSizeXMM / 2, CC.Settings.BedSizeYMM / 2)); slicer.ValidRegions = new List <GeneralPolygon2d>() { new GeneralPolygon2d(new Polygon2d(clip_box.ComputeVertices())) }; result = slicer.Compute(); Success = true; } catch (Exception e) { DebugUtil.Log("GeometrySlicer.Compute: exception: " + e.Message); Success = false; } Finished = true; }
public static void Main(string[] args) { GtkUtil.CheckWindowsGtk(); ExceptionManager.UnhandledException += delegate(UnhandledExceptionArgs expArgs) { Console.WriteLine(expArgs.ExceptionObject.ToString()); expArgs.ExitApplication = true; }; Gtk.Application.Init(); MainWindow = new Window("gsSlicerViewer"); MainWindow.SetDefaultSize(900, 600); MainWindow.SetPosition(WindowPosition.Center); MainWindow.DeleteEvent += delegate { Gtk.Application.Quit(); }; string sPath = "../../../sample_files/disc_single_layer.gcode"; //string sPath = "../../../sample_files/disc_0p6mm.gcode"; //string sPath = "../../../sample_files/square_linearfill.gcode"; //string sPath = "../../../sample_files/thin_hex_test_part.gcode"; //string sPath = "../../../sample_files/box_infill_50.gcode"; //string sPath = "../../../sample_files/tube_adapter.gcode"; //string sPath = "../../../sample_files/ring_2p2_makerbot.gcode"; //string sPath = "/Users/rms/Desktop/print_experiment/cura_ring_2p2.gcode"; //string sPath = "/Users/rms/Desktop/print_experiment/slic3r_ring_2p2.gcode"; DMesh3 readMesh = null; //GCodeFile genGCode = MakerbotTests.SimpleFillTest(); //GCodeFile genGCode = MakerbotTests.SimpleShellsTest(); //GCodeFile genGCode = MakerbotTests.InfillBoxTest(); //GeneralPolygon2d poly = GetPolygonFromMesh("../../../sample_files/bunny_open.obj"); //GCodeFile genGCode = MakerbotTests.ShellsPolygonTest(poly); //GCodeFile genGCode = MakerbotTests.StackedPolygonTest(poly, 2); //GCodeFile genGCode = MakerbotTests.StackedScaledPolygonTest(poly, 20, 0.5); readMesh = StandardMeshReader.ReadMesh("../../../sample_files/cotan_cylinder.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/bunny_solid_2p5cm.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/bunny_solid_5cm_min.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/basic_step.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/slab_5deg.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/sphere_angles_1cm.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/inverted_cone_1.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/tube_adapter.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/tube_1.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/50x50x1_box.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/crop_bracket.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/thinwall2.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/box_and_cylsheet.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/box_and_opensheet.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/radial_fins.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/radial_fins_larger.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/bunny_hollow_5cm.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/notch_test_1.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/square_minus_shapes.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/variable_thins.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/arrow_posx.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/blobby_shape.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/socket_ros_simplified.obj"); //readMesh = StandardMeshReader.ReadMesh("c:\\scratch\\bunny_fixed_flat.obj"); //MeshUtil.ScaleMesh(readMesh, Frame3f.Identity, 1.1f*Vector3f.One); //readMesh = StandardMeshReader.ReadMesh("c:\\scratch\\ARCHFORM_EXPORT_stage_12_lower.stl"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/unsupported_slab_5deg.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/overhang_slab_1.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/edge_overhang.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/support_tilted_cone.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/support_mintip.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/support_mintip_vtx.obj"); //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/tilted_thin_slab.obj"); //readMesh = StandardMeshReader.ReadMesh("C:\\meshes\\user_bugs\\inverted_part.obj"); //readMesh = StandardMeshReader.ReadMesh("C:\\meshes\\user_bugs\\tail_tiny_support_dots.obj"); //readMesh = StandardMeshReader.ReadMesh("C:\\meshes\\user_bugs\\cone_inner.obj"); // interesting test case for clipselfoverlaps and scheduler //readMesh = StandardMeshReader.ReadMesh("../../../sample_files/Slim_Type1.stl"); DMesh3 cavityMesh = null; DMesh3 supportMesh = null; //supportMesh = StandardMeshReader.ReadMesh("../../../sample_files/edge_overhang_support.obj"); // rotate to be z-up //MeshTransforms.Rotate(readMesh, Vector3d.Zero, Quaternionf.AxisAngleD(Vector3f.AxisX, 90)); //if ( supportMesh != null ) // MeshTransforms.Rotate(supportMesh, Vector3d.Zero, Quaternionf.AxisAngleD(Vector3f.AxisX, 90)); //readMesh = CalibrationModelGenerator.MakePrintStepSizeTest(10.0f, 10.0f, 0.1, 1.0, 10); //DMesh3[] meshComponents = MeshConnectedComponents.Separate(readMesh); DMesh3[] meshComponents = new DMesh3[] { readMesh }; PrintMeshAssembly meshes = new PrintMeshAssembly(); meshes.AddMeshes(meshComponents); if (cavityMesh != null) { meshes.AddMesh(cavityMesh, PrintMeshOptions.Cavity()); } if (supportMesh != null) { meshes.AddMesh(supportMesh, PrintMeshOptions.Support()); } AxisAlignedBox3d bounds = meshes.TotalBounds; AxisAlignedBox2d bounds2 = new AxisAlignedBox2d(bounds.Center.xy, bounds.Width / 2, bounds.Height / 2); View = new SliceViewCanvas(); MainWindow.Add(View); if (readMesh != null) { // generate gcode file for mesh sPath = GenerateGCodeForMeshes(meshes); } if (SHOW_RELOADED_GCODE_PATHS) { LoadGeneratedGCodeFile(sPath); } //GenerateGCodeForSliceFile("c:\\scratch\\output.gslice"); MainWindow.KeyReleaseEvent += Window_KeyReleaseEvent; // support drag-drop Gtk.TargetEntry[] target_table = new TargetEntry[] { new TargetEntry("text/uri-list", 0, 0), }; Gtk.Drag.DestSet(MainWindow, DestDefaults.All, target_table, Gdk.DragAction.Copy); MainWindow.DragDataReceived += MainWindow_DragDataReceived;; MainWindow.ShowAll(); Gtk.Application.Run(); }