Fix regression preventing raft from being generated for the entire object footprint. #1614 #1567

This commit is contained in:
Alessandro Ranellucci 2013-12-23 20:12:39 +01:00
parent c180a2de57
commit 74f2f45554
3 changed files with 104 additions and 57 deletions

View File

@ -81,6 +81,10 @@ sub contact_area {
my %contact = (); # contact_z => [ polygons ]
my %overhang = (); # contact_z => [ polygons ] - this stores the actual overhang supported by each contact layer
for my $layer_id (0 .. $#{$object->layers}) {
# note $layer_id might != $layer->id when raft_layers > 0
# so $layer_id == 0 means first object layer
# and $layer->id == 0 means first print layer (including raft)
if ($self->config->raft_layers == 0) {
next if $layer_id == 0;
} elsif (!$self->config->support_material) {
@ -89,10 +93,16 @@ sub contact_area {
last if $layer_id > 0;
}
my $layer = $object->layers->[$layer_id];
my $lower_layer = $object->layers->[$layer_id-1];
# detect overhangs and contact areas needed to support them
my (@overhang, @contact) = ();
if ($layer_id == 0) {
# this is the first object layer, so we're here just to get the object
# footprint for the raft
push @overhang, map $_->clone, map @$_, @{$layer->slices};
push @contact, @{offset(\@overhang, scale +MARGIN)};
} else {
my $lower_layer = $object->layers->[$layer_id-1];
foreach my $layerm (@{$layer->regions}) {
my $fw = $layerm->perimeter_flow->scaled_width;
my $diff;
@ -153,6 +163,7 @@ sub contact_area {
}
push @contact, @$diff;
}
}
next if !@contact;
# now apply the contact areas to the layer were they need to be made
@ -176,7 +187,7 @@ sub contact_area {
require "Slic3r/SVG.pm";
Slic3r::SVG::output("contact_" . $contact_z . ".svg",
expolygons => union_ex(\@contact),
red_expolygons => \@overhang,
red_expolygons => union_ex(\@overhang),
);
}
}

View File

@ -107,6 +107,7 @@ sub init_print {
$model_name = [$model_name] if ref($model_name) ne 'ARRAY';
for my $model (map model($_, %params), @$model_name) {
die "Unknown model in test" if !defined $model;
$model->arrange_objects($config);
$print->add_model($model);
}

View File

@ -1,4 +1,4 @@
use Test::More tests => 13;
use Test::More tests => 14;
use strict;
use warnings;
@ -9,7 +9,8 @@ BEGIN {
use List::Util qw(first);
use Slic3r;
use Slic3r::Geometry qw(epsilon);
use Slic3r::Geometry qw(epsilon scale);
use Slic3r::Geometry::Clipper qw(diff);
use Slic3r::Test;
{
@ -88,4 +89,38 @@ use Slic3r::Test;
});
}
{
my $config = Slic3r::Config->new_from_defaults;
$config->set('skirts', 0);
$config->set('raft_layers', 3);
$config->set('support_material_extrusion_width', 0.6);
$config->set('first_layer_extrusion_width', '100%');
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $layer_id = 0;
my @raft = my @first_object_layer = ();
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($info->{extruding} && $info->{dist_XY} > 0) {
if ($layer_id <= $config->raft_layers) {
# this is a raft layer or the first object layer
my $line = Slic3r::Line->new_scale([ $self->X, $self->Y ], [ $info->{new_X}, $info->{new_Y} ]);
my @path = $line->grow(scale($config->support_material_extrusion_width/2));
if ($layer_id < $config->raft_layers) {
# this is a raft layer
push @raft, @path;
} else {
push @first_object_layer, @path;
}
}
} elsif ($cmd eq 'G1' && $info->{dist_Z} > 0) {
$layer_id++;
}
});
ok !@{diff(\@first_object_layer, \@raft)},
'first object layer is completely supported by raft';
}
__END__