view-mesh.pl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. 'cut=f' => \$opt{cut},
  20. 'enable-moving' => \$opt{enable_moving},
  21. );
  22. GetOptions(%options) or usage(1);
  23. $ARGV[0] or usage(1);
  24. }
  25. {
  26. my $model = Slic3r::Model->read_from_file($ARGV[0]);
  27. $_->center_around_origin for @{$model->objects}; # and align to Z = 0
  28. my $app = Slic3r::ViewMesh->new;
  29. $app->{canvas}->enable_picking(1);
  30. $app->{canvas}->enable_moving($opt{enable_moving});
  31. $app->{canvas}->load_object($model, 0);
  32. $app->{canvas}->set_auto_bed_shape;
  33. $app->{canvas}->zoom_to_volumes;
  34. $app->{canvas}->SetCuttingPlane($opt{cut}) if defined $opt{cut};
  35. $app->MainLoop;
  36. }
  37. sub usage {
  38. my ($exit_code) = @_;
  39. print <<"EOF";
  40. Usage: view-mesh.pl [ OPTIONS ] file.stl
  41. --help Output this usage screen and exit
  42. --cut Z Display the cutting plane at the given Z
  43. EOF
  44. exit ($exit_code || 0);
  45. }
  46. package Slic3r::ViewMesh;
  47. use Wx qw(:sizer);
  48. use base qw(Wx::App);
  49. sub OnInit {
  50. my $self = shift;
  51. my $frame = Wx::Frame->new(undef, -1, 'Mesh Viewer', [-1, -1], [500, 400]);
  52. my $panel = Wx::Panel->new($frame, -1);
  53. $self->{canvas} = Slic3r::GUI::3DScene->new($panel);
  54. my $sizer = Wx::BoxSizer->new(wxVERTICAL);
  55. $sizer->Add($self->{canvas}, 1, wxEXPAND, 0);
  56. $panel->SetSizer($sizer);
  57. $sizer->SetSizeHints($panel);
  58. $frame->Show(1);
  59. }
  60. __END__