More work
This commit is contained in:
parent
0883d0f4eb
commit
e2f1040a76
11 changed files with 126 additions and 56 deletions
|
@ -15,16 +15,25 @@ our $Options = print_config_def();
|
|||
{
|
||||
no strict 'refs';
|
||||
for my $opt_key (keys %$Options) {
|
||||
*{$opt_key} = sub { $_[0]->get($opt_key) };
|
||||
*{$opt_key} = sub { $_[0]->_get($opt_key) };
|
||||
}
|
||||
}
|
||||
|
||||
sub _get {
|
||||
my ($self, $opt_key) = @_;
|
||||
use XXX;
|
||||
if (!defined first { $_ eq $opt_key } @{$self->get_keys}) {
|
||||
ZZZ $opt_key;
|
||||
}
|
||||
return $self->get($opt_key);
|
||||
}
|
||||
|
||||
sub new_from_defaults {
|
||||
my $class = shift;
|
||||
my (@opt_keys) = @_;
|
||||
|
||||
my $self = $class->new;
|
||||
my $defaults = Slic3r::Config::Print->new;
|
||||
my $defaults = Slic3r::Config::Full->new;
|
||||
if (@opt_keys) {
|
||||
$self->set($_, $defaults->get($_)) for @opt_keys;
|
||||
} else {
|
||||
|
@ -309,7 +318,7 @@ sub validate {
|
|||
&& !$self->default_acceleration;
|
||||
|
||||
# general validation, quick and dirty
|
||||
foreach my $opt_key (keys %$Options) {
|
||||
foreach my $opt_key (@{$self->get_keys}) {
|
||||
my $opt = $Options->{$opt_key};
|
||||
next unless defined $self->$opt_key;
|
||||
next unless defined $opt->{cli} && $opt->{cli} =~ /=(.+)$/;
|
||||
|
@ -431,4 +440,16 @@ sub read_ini {
|
|||
return $ini;
|
||||
}
|
||||
|
||||
package Slic3r::Config::Print;
|
||||
use parent 'Slic3r::Config';
|
||||
|
||||
package Slic3r::Config::PrintObject;
|
||||
use parent 'Slic3r::Config';
|
||||
|
||||
package Slic3r::Config::PrintRegion;
|
||||
use parent 'Slic3r::Config';
|
||||
|
||||
package Slic3r::Config::Full;
|
||||
use parent 'Slic3r::Config';
|
||||
|
||||
1;
|
||||
|
|
|
@ -14,9 +14,9 @@ has 'layer' => (
|
|||
is => 'ro',
|
||||
weak_ref => 1,
|
||||
required => 1,
|
||||
handles => [qw(id slice_z print_z height config)],
|
||||
handles => [qw(id slice_z print_z height object print)],
|
||||
);
|
||||
has 'region' => (is => 'ro', required => 1, handles => [qw(extruders)]);
|
||||
has 'region' => (is => 'ro', required => 1, handles => [qw(config)]);
|
||||
has 'infill_area_threshold' => (is => 'lazy');
|
||||
has 'overhang_width' => (is => 'lazy');
|
||||
|
||||
|
@ -168,7 +168,7 @@ sub make_perimeters {
|
|||
@offsets = @{offset2(\@last, -(1.5*$pspacing - 1), +(0.5*$pspacing - 1))};
|
||||
|
||||
# look for gaps
|
||||
if ($self->config->gap_fill_speed > 0 && $self->config->fill_density > 0) {
|
||||
if ($self->print->config->gap_fill_speed > 0 && $self->config->fill_density > 0) {
|
||||
my $diff = diff_ex(
|
||||
offset(\@last, -0.5*$pspacing),
|
||||
offset(\@offsets, +0.5*$pspacing),
|
||||
|
@ -277,8 +277,8 @@ sub make_perimeters {
|
|||
# we continue inwards after having finished the brim
|
||||
# TODO: add test for perimeter order
|
||||
@loops = reverse @loops
|
||||
if $self->config->external_perimeters_first
|
||||
|| ($self->layer->id == 0 && $self->config->brim_width > 0);
|
||||
if $self->print->config->external_perimeters_first
|
||||
|| ($self->layer->id == 0 && $self->print->config->brim_width > 0);
|
||||
|
||||
# append perimeters
|
||||
$self->perimeters->append(@loops);
|
||||
|
|
|
@ -70,9 +70,9 @@ sub init_config {
|
|||
sub apply_config {
|
||||
my ($self, $config) = @_;
|
||||
|
||||
$self->config->apply($config);
|
||||
$self->default_object_config->apply($config);
|
||||
$self->default_region_config->apply($config);
|
||||
$self->config->apply_dynamic($config);
|
||||
$self->default_object_config->apply_dynamic($config);
|
||||
$self->default_region_config->apply_dynamic($config);
|
||||
$self->init_config;
|
||||
}
|
||||
|
||||
|
@ -94,14 +94,14 @@ sub add_model_object {
|
|||
my $volume = $object->volumes->[$volume_id];
|
||||
|
||||
# get the config applied to this volume: start from our global defaults
|
||||
my $config = Slic3r::Config::RegionConfig->new;
|
||||
my $config = Slic3r::Config::PrintRegion->new;
|
||||
$config->apply($self->default_region_config);
|
||||
|
||||
# override the defaults with per-object config and then with per-material config
|
||||
$config->apply($object->config);
|
||||
$config->apply_dynamic($object->config);
|
||||
if (defined $volume->material_id) {
|
||||
my $material_config = $object->model->materials->{ $volume->material_id }->config;
|
||||
$config->apply($material_config);
|
||||
$config->apply_dynamic($material_config);
|
||||
}
|
||||
|
||||
# find an existing print region with the same config
|
||||
|
@ -139,7 +139,7 @@ sub add_model_object {
|
|||
|
||||
# apply config to print object
|
||||
$o->config->apply($self->default_object_config);
|
||||
$o->config->apply($object->config);
|
||||
$o->config->apply_dynamic($object->config);
|
||||
|
||||
# store print object at the given position
|
||||
if (defined $obj_idx) {
|
||||
|
|
|
@ -13,7 +13,7 @@ has 'print' => (is => 'ro', weak_ref => 1, required => 1);
|
|||
has 'model_object' => (is => 'ro', required => 1);
|
||||
has 'region_volumes' => (is => 'rw', default => sub { [] }); # by region_id
|
||||
has 'copies' => (is => 'ro'); # Slic3r::Point objects in scaled G-code coordinates
|
||||
has 'config' => (is => 'rw', required => 1); # Slic3r::Config::PrintObject
|
||||
has 'config' => (is => 'ro', default => sub { Slic3r::Config::PrintObject->new });
|
||||
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
|
||||
|
||||
has 'size' => (is => 'rw'); # XYZ in scaled coordinates
|
||||
|
@ -273,8 +273,8 @@ sub slice {
|
|||
}
|
||||
|
||||
# simplify slices if required
|
||||
if ($self->config->resolution) {
|
||||
$self->_simplify_slices(scale($self->config->resolution));
|
||||
if ($self->print->config->resolution) {
|
||||
$self->_simplify_slices(scale($self->print->config->resolution));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,8 +288,11 @@ sub make_perimeters {
|
|||
# but we don't generate any extra perimeter if fill density is zero, as they would be floating
|
||||
# inside the object - infill_only_where_needed should be the method of choice for printing
|
||||
# hollow objects
|
||||
if ($self->config->extra_perimeters && $self->config->perimeters > 0 && $self->config->fill_density > 0) {
|
||||
for my $region_id (0 .. ($self->print->regions_count-1)) {
|
||||
for my $region_id (0 .. ($self->print->regions_count-1)) {
|
||||
my $region = $self->print->regions->[$region_id];
|
||||
my $region_perimeters = $region->config->perimeters;
|
||||
|
||||
if ($region->config->extra_perimeters && $region_perimeters > 0 && $region->config->fill_density > 0) {
|
||||
for my $layer_id (0 .. $self->layer_count-2) {
|
||||
my $layerm = $self->layers->[$layer_id]->regions->[$region_id];
|
||||
my $upper_layerm = $self->layers->[$layer_id+1]->regions->[$region_id];
|
||||
|
@ -298,7 +301,7 @@ sub make_perimeters {
|
|||
my $overlap = $perimeter_spacing; # one perimeter
|
||||
|
||||
my $diff = diff(
|
||||
offset([ map @{$_->expolygon}, @{$layerm->slices} ], -($self->config->perimeters * $perimeter_spacing)),
|
||||
offset([ map @{$_->expolygon}, @{$layerm->slices} ], -($region_perimeters * $perimeter_spacing)),
|
||||
offset([ map @{$_->expolygon}, @{$upper_layerm->slices} ], -$overlap),
|
||||
);
|
||||
next if !@$diff;
|
||||
|
@ -322,8 +325,8 @@ sub make_perimeters {
|
|||
# of our slice
|
||||
$extra_perimeters++;
|
||||
my $hypothetical_perimeter = diff(
|
||||
offset($slice->expolygon->arrayref, -($perimeter_spacing * ($self->config->perimeters + $extra_perimeters-1))),
|
||||
offset($slice->expolygon->arrayref, -($perimeter_spacing * ($self->config->perimeters + $extra_perimeters))),
|
||||
offset($slice->expolygon->arrayref, -($perimeter_spacing * ($region_perimeters + $extra_perimeters-1))),
|
||||
offset($slice->expolygon->arrayref, -($perimeter_spacing * ($region_perimeters + $extra_perimeters))),
|
||||
);
|
||||
last CYCLE if !@$hypothetical_perimeter; # no extra perimeter is possible
|
||||
|
||||
|
@ -339,7 +342,7 @@ sub make_perimeters {
|
|||
}
|
||||
|
||||
Slic3r::parallelize(
|
||||
threads => $self->config->threads,
|
||||
threads => $self->print->config->threads,
|
||||
items => sub { 0 .. ($self->layer_count-1) },
|
||||
thread_cb => sub {
|
||||
my $q = shift;
|
||||
|
@ -376,7 +379,7 @@ sub detect_surfaces_type {
|
|||
);
|
||||
|
||||
# collapse very narrow parts (using the safety offset in the diff is not enough)
|
||||
my $offset = $layerm->perimeter_flow->scaled_width / 10;
|
||||
my $offset = $layerm->flow(FLOW_ROLE_PERIMETER)->scaled_width / 10;
|
||||
return map Slic3r::Surface->new(expolygon => $_, surface_type => $result_type),
|
||||
@{ offset2_ex($diff, -$offset, +$offset) };
|
||||
};
|
||||
|
@ -609,8 +612,8 @@ sub discover_horizontal_shells {
|
|||
for (my $i = 0; $i < $self->layer_count; $i++) {
|
||||
my $layerm = $self->layers->[$i]->regions->[$region_id];
|
||||
|
||||
if ($self->config->solid_infill_every_layers && $self->config->fill_density > 0
|
||||
&& ($i % $self->config->solid_infill_every_layers) == 0) {
|
||||
if ($layerm->config->solid_infill_every_layers && $layerm->config->fill_density > 0
|
||||
&& ($i % $layerm->config->solid_infill_every_layers) == 0) {
|
||||
$_->surface_type(S_TYPE_INTERNALSOLID) for @{$layerm->fill_surfaces->filter_by_type(S_TYPE_INTERNAL)};
|
||||
}
|
||||
|
||||
|
@ -632,8 +635,8 @@ sub discover_horizontal_shells {
|
|||
Slic3r::debugf "Layer %d has %s surfaces\n", $i, ($type == S_TYPE_TOP) ? 'top' : 'bottom';
|
||||
|
||||
my $solid_layers = ($type == S_TYPE_TOP)
|
||||
? $self->config->top_solid_layers
|
||||
: $self->config->bottom_solid_layers;
|
||||
? $layerm->config->top_solid_layers
|
||||
: $layerm->config->bottom_solid_layers;
|
||||
NEIGHBOR: for (my $n = ($type == S_TYPE_TOP) ? $i-1 : $i+1;
|
||||
abs($n - $i) <= $solid_layers-1;
|
||||
($type == S_TYPE_TOP) ? $n-- : $n++) {
|
||||
|
@ -668,7 +671,7 @@ sub discover_horizontal_shells {
|
|||
# get a triangle in $too_narrow; if we grow it below then the shell
|
||||
# would have a different shape from the external surface and we'd still
|
||||
# have the same angle, so the next shell would be grown even more and so on.
|
||||
my $margin = 3 * $layerm->solid_infill_flow->scaled_width; # require at least this size
|
||||
my $margin = 3 * $layerm->flow(FLOW_ROLE_SOLID_INFILL)->scaled_width; # require at least this size
|
||||
my $too_narrow = diff(
|
||||
$new_internal_solid,
|
||||
offset2($new_internal_solid, -$margin, +$margin, CLIPPER_OFFSET_SCALE, JT_MITER, 5),
|
||||
|
@ -677,7 +680,7 @@ sub discover_horizontal_shells {
|
|||
|
||||
# if some parts are going to collapse, use a different strategy according to fill density
|
||||
if (@$too_narrow) {
|
||||
if ($self->config->fill_density > 0) {
|
||||
if ($layerm->config->fill_density > 0) {
|
||||
# if we have internal infill, grow the collapsing parts and add the extra area to
|
||||
# the neighbor layer as well as to our original surfaces so that we support this
|
||||
# additional area in the next shell too
|
||||
|
@ -741,13 +744,16 @@ sub discover_horizontal_shells {
|
|||
# combine fill surfaces across layers
|
||||
sub combine_infill {
|
||||
my $self = shift;
|
||||
return unless $self->config->infill_every_layers > 1 && $self->config->fill_density > 0;
|
||||
my $every = $self->config->infill_every_layers;
|
||||
|
||||
return unless defined first { $_->config->infill_every_layers > 1 && $_->config->fill_density > 0 } @{$self->print->regions};
|
||||
|
||||
my $layer_count = $self->layer_count;
|
||||
my @layer_heights = map $self->layers->[$_]->height, 0 .. $layer_count-1;
|
||||
|
||||
for my $region_id (0 .. ($self->print->regions_count-1)) {
|
||||
my $region = $self->print->regions->[$region_id];
|
||||
my $every = $region->config->infill_every_layers;
|
||||
|
||||
# limit the number of combined layers to the maximum height allowed by this regions' nozzle
|
||||
my $nozzle_diameter = $self->print->regions->[$region_id]->extruders->{infill}->nozzle_diameter;
|
||||
|
||||
|
@ -805,7 +811,7 @@ sub combine_infill {
|
|||
+ $layerms[-1]->perimeter_flow->scaled_width / 2
|
||||
# Because fill areas for rectilinear and honeycomb are grown
|
||||
# later to overlap perimeters, we need to counteract that too.
|
||||
+ (($type == S_TYPE_INTERNALSOLID || $self->config->fill_pattern =~ /(rectilinear|honeycomb)/)
|
||||
+ (($type == S_TYPE_INTERNALSOLID || $region->config->fill_pattern =~ /(rectilinear|honeycomb)/)
|
||||
? $layerms[-1]->solid_infill_flow->scaled_width * &Slic3r::INFILL_OVERLAP_OVER_SPACING
|
||||
: 0)
|
||||
)}, @$intersection;
|
||||
|
|
|
@ -8,7 +8,7 @@ use Slic3r::Flow ':roles';
|
|||
# sharing the same config (including the same assigned extruder(s))
|
||||
|
||||
has 'print' => (is => 'ro', required => 1, weak_ref => 1);
|
||||
has 'config' => (is => 'ro', required => 1); # Slic3r::Config::RegionConfig
|
||||
has 'config' => (is => 'ro', default => sub { Slic3r::Config::PrintRegion->new});
|
||||
|
||||
sub flow {
|
||||
my ($self, $role, $layer_height, $bridge, $first_layer, $width) = @_;
|
||||
|
@ -21,7 +21,7 @@ sub flow {
|
|||
if (!defined $config_width) {
|
||||
# get extrusion width from configuration
|
||||
# (might be an absolute value, or a percent value, or zero for auto)
|
||||
if ($first_layer && $self->config->first_layer_extrusion_width != 0) {
|
||||
if ($first_layer && $self->config->first_layer_extrusion_width ne '0') {
|
||||
$config_width = $self->config->first_layer_extrusion_width;
|
||||
} elsif ($role == FLOW_ROLE_PERIMETER) {
|
||||
$config_width = $self->config->perimeter_extrusion_width;
|
||||
|
@ -40,9 +40,9 @@ sub flow {
|
|||
# to the flow role requested
|
||||
my $extruder; # 1-based
|
||||
if ($role == FLOW_ROLE_PERIMETER) {
|
||||
$config_width = $self->config->perimeter_extruder;
|
||||
$extruder = $self->config->perimeter_extruder;
|
||||
} elsif ($role == FLOW_ROLE_INFILL || $role == FLOW_ROLE_SOLID_INFILL || $role == FLOW_ROLE_TOP_SOLID_INFILL) {
|
||||
$config_width = $self->config->infill_extruder;
|
||||
$extruder = $self->config->infill_extruder;
|
||||
} else {
|
||||
die "Unknown role $role";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue