view-toolpaths.pl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/perl
  2. # This script displays 3D preview of a mesh
  3. use strict;
  4. use warnings;
  5. BEGIN {
  6. use FindBin;
  7. use lib "$FindBin::Bin/../lib";
  8. use local::lib "$FindBin::Bin/../local-lib";
  9. }
  10. use Getopt::Long qw(:config no_auto_abbrev);
  11. use Slic3r;
  12. use Slic3r::GUI;
  13. use Slic3r::GUI::3DScene;
  14. $|++;
  15. my %opt = ();
  16. {
  17. my %options = (
  18. 'help' => sub { usage() },
  19. 'load=s' => \$opt{load},
  20. '3D' => \$opt{d3},
  21. 'duplicate=i' => \$opt{duplicate},
  22. );
  23. GetOptions(%options) or usage(1);
  24. $ARGV[0] or usage(1);
  25. }
  26. {
  27. # load model
  28. my $model = Slic3r::Model->read_from_file($ARGV[0]);
  29. # load config
  30. my $config = Slic3r::Config::new_from_defaults;
  31. if ($opt{load}) {
  32. $config->apply(Slic3r::Config::load($opt{load}));
  33. }
  34. # init print
  35. my $sprint = Slic3r::Print::Simple->new;
  36. $sprint->duplicate($opt{duplicate} // 1);
  37. $sprint->apply_config($config);
  38. $sprint->set_model($model);
  39. $sprint->process;
  40. # visualize toolpaths
  41. $Slic3r::ViewToolpaths::print = $sprint->_print;
  42. $Slic3r::ViewToolpaths::d3 = $opt{d3};
  43. my $app = Slic3r::ViewToolpaths->new;
  44. $app->MainLoop;
  45. }
  46. sub usage {
  47. my ($exit_code) = @_;
  48. print <<"EOF";
  49. Usage: view-toolpaths.pl [ OPTIONS ] file.stl
  50. --help Output this usage screen and exit
  51. --load CONFIG Loads the supplied config file
  52. EOF
  53. exit ($exit_code || 0);
  54. }
  55. package Slic3r::ViewToolpaths;
  56. use Wx qw(:sizer);
  57. use base qw(Wx::App Class::Accessor);
  58. our $print;
  59. our $d3;
  60. sub OnInit {
  61. my $self = shift;
  62. my $frame = Wx::Frame->new(undef, -1, 'Toolpaths', [-1, -1], [500, 500]);
  63. my $panel = Wx::Panel->new($frame, -1);
  64. my $canvas;
  65. if ($d3) {
  66. $canvas = Slic3r::GUI::3DScene->new($panel);
  67. $canvas->set_bed_shape($print->config->bed_shape);
  68. $canvas->load_print_toolpaths($print);
  69. foreach my $object (@{$print->objects}) {
  70. #$canvas->load_print_object_slices($object);
  71. $canvas->load_print_object_toolpaths($object);
  72. #$canvas->load_object($object->model_object);
  73. }
  74. $canvas->zoom_to_volumes;
  75. } else {
  76. $canvas = Slic3r::GUI::Plater::2DToolpaths->new($panel, $print);
  77. }
  78. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  79. $sizer->Add($canvas, 1, wxEXPAND, 0);
  80. $panel->SetSizer($sizer);
  81. $frame->Show(1);
  82. }
  83. __END__