diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 63d07ec6b..1537fdf6e 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -937,7 +937,7 @@ package Slic3r::GUI::3DScene; use base qw(Slic3r::GUI::3DScene::Base); use OpenGL qw(:glconstants :gluconstants :glufunctions); -use List::Util qw(first); +use List::Util qw(first min max); use Slic3r::Geometry qw(scale unscale epsilon); use Slic3r::Print::State ':steps'; @@ -1079,6 +1079,50 @@ sub load_print_object_slices { ); } +sub load_print_toolpaths { + my ($self, $print) = @_; + + return if !$print->step_done(STEP_SKIRT); + return if !$print->step_done(STEP_BRIM); + return if !$print->has_skirt && $print->config->brim_width == 0; + + my $qverts = Slic3r::GUI::_3DScene::GLVertexArray->new; + my $tverts = Slic3r::GUI::_3DScene::GLVertexArray->new; + my %offsets = (); # print_z => [ qverts, tverts ] + + my $skirt_height = 0; # number of layers + if ($print->has_infinite_skirt) { + $skirt_height = $print->total_layer_count; + } else { + $skirt_height = min($print->config->skirt_height, $print->total_layer_count); + } + foreach my $i (0..max(0, $skirt_height-1)) { + my $layer = $print->get_object(0)->get_layer($i); + my $top_z = $layer->print_z; + $offsets{$top_z} = [$qverts->size, $tverts->size]; + + if ($i == 0) { + $self->_extrusionentity_to_verts($print->brim, $top_z, Slic3r::Point->new(0,0), $qverts, $tverts); + } + + $self->_extrusionentity_to_verts($print->skirt, $top_z, Slic3r::Point->new(0,0), $qverts, $tverts); + } + + my $bb = Slic3r::Geometry::BoundingBoxf3->new; + { + my $pbb = $print->bounding_box; + $bb->merge_point(Slic3r::Pointf3->new_unscale(@{$pbb->min_point})); + $bb->merge_point(Slic3r::Pointf3->new_unscale(@{$pbb->max_point})); + } + push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new( + bounding_box => $bb, + color => COLORS->[2], + qverts => $qverts, + tverts => $tverts, + offsets => { %offsets }, + ); +} + sub load_print_object_toolpaths { my ($self, $object) = @_; diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index be9b5f572..596b5195f 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -116,6 +116,9 @@ sub load_print { } if ($self->IsShown) { + # load skirt and brim + $self->canvas->load_print_toolpaths($self->print); + foreach my $object (@{$self->print->objects}) { $self->canvas->load_print_object_toolpaths($object); diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 8c94fedb3..77488e559 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -225,8 +225,8 @@ sub make_skirt { my $skirt_height_z = -1; foreach my $object (@{$self->objects}) { my $skirt_height = $self->has_infinite_skirt - ? scalar(@{$object->layers}) - : min($self->config->skirt_height, scalar(@{$object->layers})); + ? $object->layer_count + : min($self->config->skirt_height, $object->layer_count); my $highest_layer = $object->get_layer($skirt_height - 1); $skirt_height_z = max($skirt_height_z, $highest_layer->print_z); } diff --git a/utils/view-toolpaths.pl b/utils/view-toolpaths.pl index 7e1d305bc..4bbbaab4c 100755 --- a/utils/view-toolpaths.pl +++ b/utils/view-toolpaths.pl @@ -33,7 +33,6 @@ my %opt = (); # load config my $config = Slic3r::Config->new_from_defaults; - $config->set('skirts', 0); if ($opt{load}) { $config->apply(Slic3r::Config->load($opt{load})); } @@ -84,6 +83,7 @@ sub OnInit { if ($d3) { $canvas = Slic3r::GUI::3DScene->new($panel); $canvas->set_bed_shape($print->config->bed_shape); + $canvas->load_print_toolpaths($print); foreach my $object (@{$print->objects}) { #$canvas->load_print_object_slices($object);