2013-05-17 12:14:33 +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;
|
2015-01-09 00:30:04 +00:00
|
|
|
use Slic3r::GUI::3DScene;
|
2013-05-17 12:14:33 +00:00
|
|
|
$|++;
|
|
|
|
|
|
|
|
my %opt = ();
|
|
|
|
{
|
|
|
|
my %options = (
|
|
|
|
'help' => sub { usage() },
|
2014-07-12 15:35:17 +00:00
|
|
|
'cut=f' => \$opt{cut},
|
2014-12-13 21:18:43 +00:00
|
|
|
'enable-moving' => \$opt{enable_moving},
|
2013-05-17 12:14:33 +00:00
|
|
|
);
|
|
|
|
GetOptions(%options) or usage(1);
|
|
|
|
$ARGV[0] or usage(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
my $model = Slic3r::Model->read_from_file($ARGV[0]);
|
2015-01-13 16:25:56 +00:00
|
|
|
$_->center_around_origin for @{$model->objects}; # and align to Z = 0
|
2014-07-12 15:06:42 +00:00
|
|
|
|
2013-05-17 12:14:33 +00:00
|
|
|
my $app = Slic3r::ViewMesh->new;
|
2014-12-13 19:41:03 +00:00
|
|
|
$app->{canvas}->enable_picking(1);
|
2014-12-13 21:18:43 +00:00
|
|
|
$app->{canvas}->enable_moving($opt{enable_moving});
|
2015-01-13 16:25:56 +00:00
|
|
|
$app->{canvas}->load_object($model, 0);
|
2014-07-15 19:58:03 +00:00
|
|
|
$app->{canvas}->set_auto_bed_shape;
|
2014-12-16 00:12:37 +00:00
|
|
|
$app->{canvas}->zoom_to_volumes;
|
2014-07-12 15:35:17 +00:00
|
|
|
$app->{canvas}->SetCuttingPlane($opt{cut}) if defined $opt{cut};
|
2013-05-17 12:14:33 +00:00
|
|
|
$app->MainLoop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
my ($exit_code) = @_;
|
|
|
|
|
|
|
|
print <<"EOF";
|
|
|
|
Usage: view-mesh.pl [ OPTIONS ] file.stl
|
|
|
|
|
|
|
|
--help Output this usage screen and exit
|
2014-07-12 15:35:17 +00:00
|
|
|
--cut Z Display the cutting plane at the given Z
|
2013-05-17 12:14:33 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
exit ($exit_code || 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
package Slic3r::ViewMesh;
|
|
|
|
use Wx qw(:sizer);
|
|
|
|
use base qw(Wx::App);
|
|
|
|
|
|
|
|
sub OnInit {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $frame = Wx::Frame->new(undef, -1, 'Mesh Viewer', [-1, -1], [500, 400]);
|
|
|
|
my $panel = Wx::Panel->new($frame, -1);
|
|
|
|
|
2015-01-09 00:30:04 +00:00
|
|
|
$self->{canvas} = Slic3r::GUI::3DScene->new($panel);
|
2014-07-13 10:10:34 +00:00
|
|
|
|
2013-05-17 12:14:33 +00:00
|
|
|
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
|
2014-07-13 10:10:34 +00:00
|
|
|
$sizer->Add($self->{canvas}, 1, wxEXPAND, 0);
|
2013-05-17 12:14:33 +00:00
|
|
|
$panel->SetSizer($sizer);
|
|
|
|
$sizer->SetSizeHints($panel);
|
|
|
|
|
|
|
|
$frame->Show(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
__END__
|