2014-07-03 07:24:19 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# This script displays 3D preview of a mesh
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
|
|
|
}
|
|
|
|
|
|
|
|
use Getopt::Long qw(:config no_auto_abbrev);
|
|
|
|
use Slic3r;
|
|
|
|
use Slic3r::GUI;
|
|
|
|
use Slic3r::GUI::PreviewCanvas;
|
|
|
|
$|++;
|
|
|
|
|
|
|
|
my %opt = ();
|
|
|
|
{
|
|
|
|
my %options = (
|
|
|
|
'help' => sub { usage() },
|
|
|
|
'load=s' => \$opt{load},
|
2014-12-15 14:19:42 +00:00
|
|
|
'3D' => \$opt{d3},
|
2014-12-15 11:42:11 +00:00
|
|
|
'duplicate=i' => \$opt{duplicate},
|
2014-07-03 07:24:19 +00:00
|
|
|
);
|
|
|
|
GetOptions(%options) or usage(1);
|
|
|
|
$ARGV[0] or usage(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
# load model
|
|
|
|
my $model = Slic3r::Model->read_from_file($ARGV[0]);
|
|
|
|
|
|
|
|
# load config
|
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
|
|
|
$config->set('skirts', 0);
|
|
|
|
if ($opt{load}) {
|
|
|
|
$config->apply(Slic3r::Config->load($opt{load}));
|
|
|
|
}
|
|
|
|
|
|
|
|
# init print
|
|
|
|
my $sprint = Slic3r::Print::Simple->new;
|
2014-12-15 11:42:11 +00:00
|
|
|
$sprint->duplicate($opt{duplicate} // 1);
|
2014-07-03 07:24:19 +00:00
|
|
|
$sprint->apply_config($config);
|
|
|
|
$sprint->set_model($model);
|
|
|
|
$sprint->process;
|
|
|
|
|
|
|
|
# visualize toolpaths
|
|
|
|
$Slic3r::ViewToolpaths::print = $sprint->_print;
|
2014-12-15 14:19:42 +00:00
|
|
|
$Slic3r::ViewToolpaths::d3 = $opt{d3};
|
2014-07-03 07:24:19 +00:00
|
|
|
my $app = Slic3r::ViewToolpaths->new;
|
|
|
|
$app->MainLoop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
my ($exit_code) = @_;
|
|
|
|
|
|
|
|
print <<"EOF";
|
|
|
|
Usage: view-toolpaths.pl [ OPTIONS ] file.stl
|
|
|
|
|
|
|
|
--help Output this usage screen and exit
|
|
|
|
--load CONFIG Loads the supplied config file
|
|
|
|
|
|
|
|
EOF
|
|
|
|
exit ($exit_code || 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
package Slic3r::ViewToolpaths;
|
|
|
|
use Wx qw(:sizer);
|
2014-12-15 14:19:42 +00:00
|
|
|
use base qw(Wx::App Class::Accessor);
|
2014-07-03 07:24:19 +00:00
|
|
|
|
|
|
|
our $print;
|
2014-12-15 14:19:42 +00:00
|
|
|
our $d3;
|
2014-07-03 07:24:19 +00:00
|
|
|
|
|
|
|
sub OnInit {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $frame = Wx::Frame->new(undef, -1, 'Toolpaths', [-1, -1], [500, 500]);
|
|
|
|
my $panel = Wx::Panel->new($frame, -1);
|
|
|
|
|
2014-12-15 14:19:42 +00:00
|
|
|
my $canvas;
|
|
|
|
if ($d3) {
|
|
|
|
$canvas = Slic3r::GUI::PreviewCanvas->new($panel);
|
|
|
|
$canvas->print($print);
|
|
|
|
|
|
|
|
$canvas->set_bed_shape($print->config->bed_shape);
|
|
|
|
|
|
|
|
foreach my $object (@{$print->objects}) {
|
|
|
|
$canvas->load_object($object->model_object);
|
|
|
|
}
|
2014-12-16 17:13:31 +00:00
|
|
|
$canvas->zoom_to_volumes;
|
2014-12-15 14:19:42 +00:00
|
|
|
} else {
|
|
|
|
$canvas = Slic3r::GUI::Plater::2DToolpaths->new($panel, $print);
|
|
|
|
}
|
|
|
|
|
2014-07-03 07:24:19 +00:00
|
|
|
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
|
2014-12-15 14:19:42 +00:00
|
|
|
$sizer->Add($canvas, 1, wxEXPAND, 0);
|
2014-07-03 07:24:19 +00:00
|
|
|
$panel->SetSizer($sizer);
|
|
|
|
|
|
|
|
$frame->Show(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
__END__
|