mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 22:54:08 -06:00
Return Surface objects by reference from SurfaceCollection objects and fix a bug in XS code causing some shell options to be ignored
This commit is contained in:
parent
cb677c45de
commit
e02ae0d18a
9 changed files with 68 additions and 47 deletions
|
@ -54,20 +54,15 @@ sub make_fill {
|
|||
|
||||
my @surfaces = ();
|
||||
|
||||
# if hollow object is requested, remove internal surfaces
|
||||
# (this needs to be done after internal-solid shells are created)
|
||||
if ($fill_density == 0) {
|
||||
@surfaces = grep $_->surface_type != S_TYPE_INTERNAL, @surfaces;
|
||||
}
|
||||
|
||||
# merge adjacent surfaces
|
||||
# in case of bridge surfaces, the ones with defined angle will be attached to the ones
|
||||
# without any angle (shouldn't this logic be moved to process_external_surfaces()?)
|
||||
{
|
||||
my @surfaces_with_bridge_angle = grep defined $_->bridge_angle, @{$layerm->fill_surfaces};
|
||||
my @fill_surfaces = @{$layerm->fill_surfaces};
|
||||
my @surfaces_with_bridge_angle = grep defined $_->bridge_angle, @fill_surfaces;
|
||||
|
||||
# give priority to bridges
|
||||
my @groups = Slic3r::Surface->group({merge_solid => 1}, @{$layerm->fill_surfaces});
|
||||
my @groups = Slic3r::Surface->group({merge_solid => 1}, @fill_surfaces);
|
||||
@groups = sort { defined $a->[0]->bridge_angle ? -1 : 0 } @groups;
|
||||
|
||||
foreach my $group (@groups) {
|
||||
|
|
|
@ -412,39 +412,30 @@ sub _fill_gaps {
|
|||
sub prepare_fill_surfaces {
|
||||
my $self = shift;
|
||||
|
||||
my @surfaces = @{$self->fill_surfaces};
|
||||
|
||||
# if no solid layers are requested, turn top/bottom surfaces to internal
|
||||
if ($self->config->top_solid_layers == 0) {
|
||||
for my $i (0..$#surfaces) {
|
||||
next unless $surfaces[$i]->surface_type == S_TYPE_TOP;
|
||||
$self->fill_surfaces->set_surface_type($i, S_TYPE_INTERNAL);
|
||||
}
|
||||
$_->surface_type(S_TYPE_INTERNAL) for @{$self->fill_surfaces->filter_by_type(S_TYPE_TOP)};
|
||||
}
|
||||
if ($self->config->bottom_solid_layers == 0) {
|
||||
for my $i (0..$#surfaces) {
|
||||
next unless $surfaces[$i]->surface_type == S_TYPE_BOTTOM;
|
||||
$self->fill_surfaces->set_surface_type($i, S_TYPE_INTERNAL);
|
||||
}
|
||||
$_->surface_type(S_TYPE_INTERNAL) for @{$self->fill_surfaces->filter_by_type(S_TYPE_BOTTOM)};
|
||||
}
|
||||
|
||||
# turn too small internal regions into solid regions according to the user setting
|
||||
if ($self->config->fill_density > 0) {
|
||||
my $min_area = scale scale $self->config->solid_infill_below_area; # scaling an area requires two calls!
|
||||
for my $i (0..$#surfaces) {
|
||||
next unless $surfaces[$i]->surface_type == S_TYPE_INTERNAL && $surfaces[$i]->expolygon->contour->area <= $min_area;
|
||||
$self->fill_surfaces->set_surface_type($i, S_TYPE_INTERNALSOLID);
|
||||
}
|
||||
$_->surface_type(S_TYPE_INTERNALSOLID)
|
||||
for grep { $_->area <= $min_area } @{$self->fill_surfaces->filter_by_type(S_TYPE_INTERNAL)};
|
||||
}
|
||||
}
|
||||
|
||||
sub process_external_surfaces {
|
||||
my $self = shift;
|
||||
|
||||
my @surfaces = @{$self->fill_surfaces};
|
||||
my $margin = scale &Slic3r::EXTERNAL_INFILL_MARGIN;
|
||||
|
||||
my @bottom = ();
|
||||
foreach my $surface (grep $_->surface_type == S_TYPE_BOTTOM, @{$self->fill_surfaces}) {
|
||||
foreach my $surface (grep $_->surface_type == S_TYPE_BOTTOM, @surfaces) {
|
||||
my $grown = $surface->expolygon->offset_ex(+$margin);
|
||||
|
||||
# detect bridge direction before merging grown surfaces otherwise adjacent bridges
|
||||
|
@ -459,7 +450,7 @@ sub process_external_surfaces {
|
|||
}
|
||||
|
||||
my @top = ();
|
||||
foreach my $surface (grep $_->surface_type == S_TYPE_TOP, @{$self->fill_surfaces}) {
|
||||
foreach my $surface (grep $_->surface_type == S_TYPE_TOP, @surfaces) {
|
||||
# give priority to bottom surfaces
|
||||
my $grown = diff_ex(
|
||||
$surface->expolygon->offset(+$margin),
|
||||
|
@ -471,8 +462,8 @@ sub process_external_surfaces {
|
|||
# if we're slicing with no infill, we can't extend external surfaces
|
||||
# over non-existent infill
|
||||
my @fill_boundaries = $self->object->config->fill_density > 0
|
||||
? @{$self->fill_surfaces}
|
||||
: grep $_->surface_type != S_TYPE_INTERNAL, @{$self->fill_surfaces};
|
||||
? @surfaces
|
||||
: grep $_->surface_type != S_TYPE_INTERNAL, @surfaces;
|
||||
|
||||
# intersect the grown surfaces with the actual fill boundaries
|
||||
my @new_surfaces = ();
|
||||
|
@ -487,14 +478,15 @@ sub process_external_surfaces {
|
|||
}
|
||||
|
||||
# subtract the new top surfaces from the other non-top surfaces and re-add them
|
||||
my @other = grep $_->surface_type != S_TYPE_TOP && $_->surface_type != S_TYPE_BOTTOM, @{$self->fill_surfaces};
|
||||
my @other = grep $_->surface_type != S_TYPE_TOP && $_->surface_type != S_TYPE_BOTTOM, @surfaces;
|
||||
foreach my $group (Slic3r::Surface->group(@other)) {
|
||||
push @new_surfaces, map $group->[0]->clone(expolygon => $_), @{diff_ex(
|
||||
[ map $_->p, @$group ],
|
||||
[ map $_->p, @new_surfaces ],
|
||||
)};
|
||||
}
|
||||
@{$self->fill_surfaces} = @new_surfaces;
|
||||
$self->fill_surfaces->clear;
|
||||
$self->fill_surfaces->append(@new_surfaces);
|
||||
}
|
||||
|
||||
sub _detect_bridge_direction {
|
||||
|
|
|
@ -464,11 +464,11 @@ sub clip_fill_surfaces {
|
|||
),
|
||||
@{intersection_ex(
|
||||
[ map @$_, @overhangs ],
|
||||
[ map @{$_->expolygon}, grep $_->surface_type == S_TYPE_INTERNAL, @{$layerm->fill_surfaces} ],
|
||||
[ map $_->p, @{$layerm->fill_surfaces->filter_by_type(S_TYPE_INTERNAL)} ],
|
||||
)};
|
||||
my @new_surfaces = (
|
||||
@new_internal,
|
||||
(map $_->clone, grep $_->surface_type != S_TYPE_INTERNAL, @{$layerm->fill_surfaces}),
|
||||
(map $_->clone, @{$layerm->fill_surfaces->filter_by_type(S_TYPE_INTERNAL)}),
|
||||
);
|
||||
$layerm->fill_surfaces->clear;
|
||||
$layerm->fill_surfaces->append(@new_surfaces);
|
||||
|
@ -502,8 +502,8 @@ sub bridge_over_infill {
|
|||
|
||||
foreach my $layerm (@{$layer->regions}) {
|
||||
# compute the areas needing bridge math
|
||||
my @internal_solid = grep $_->surface_type == S_TYPE_INTERNALSOLID, @{$layerm->fill_surfaces};
|
||||
my @lower_internal = grep $_->surface_type == S_TYPE_INTERNAL, map @{$_->fill_surfaces}, @{$lower_layer->regions};
|
||||
my @internal_solid = @{$layerm->fill_surfaces->filter_by_type(S_TYPE_INTERNALSOLID)};
|
||||
my @lower_internal = map @{$_->fill_surfaces->filter_by_type(S_TYPE_INTERNAL)}, @{$lower_layer->regions};
|
||||
my $to_bridge = intersection_ex(
|
||||
[ map $_->p, @internal_solid ],
|
||||
[ map $_->p, @lower_internal ],
|
||||
|
@ -578,11 +578,7 @@ sub discover_horizontal_shells {
|
|||
|
||||
if ($self->config->solid_infill_every_layers && $self->config->fill_density > 0
|
||||
&& ($i % $self->config->solid_infill_every_layers) == 0) {
|
||||
my @surfaces = @{$layerm->fill_surfaces};
|
||||
for my $i (0..$#surfaces) {
|
||||
next unless $surfaces[$i]->surface_type == S_TYPE_INTERNAL;
|
||||
$layerm->fill_surfaces->set_surface_type($i, S_TYPE_INTERNALSOLID);
|
||||
}
|
||||
$_->surface_type(S_TYPE_INTERNALSOLID) for @{$layerm->fill_surfaces->filter_by_type(S_TYPE_INTERNAL)};
|
||||
}
|
||||
|
||||
EXTERNAL: foreach my $type (S_TYPE_TOP, S_TYPE_BOTTOM) {
|
||||
|
@ -593,7 +589,7 @@ sub discover_horizontal_shells {
|
|||
# not work in some situations, as there won't be any grown region in the perimeter
|
||||
# area (this was seen in a model where the top layer had one extra perimeter, thus
|
||||
# its fill_surfaces was thinner than the lower layer's infill)
|
||||
my $solid = offset_ex([ map $_->p, grep $_->surface_type == $type, @{$layerm->slices} ], $margin);
|
||||
my $solid = offset_ex([ map $_->p, @{$layerm->slices->filter_by_type($type)} ], $margin);
|
||||
next if !@$solid;
|
||||
Slic3r::debugf "Layer %d has %s surfaces\n", $i, ($type == S_TYPE_TOP) ? 'top' : 'bottom';
|
||||
|
||||
|
@ -745,13 +741,13 @@ sub combine_infill {
|
|||
# we need to perform a multi-layer intersection, so let's split it in pairs
|
||||
|
||||
# initialize the intersection with the candidates of the lowest layer
|
||||
my $intersection = [ map $_->expolygon, grep $_->surface_type == $type, @{$layerms[0]->fill_surfaces} ];
|
||||
my $intersection = [ map $_->expolygon, @{$layerms[0]->fill_surfaces->filter_by_type($type)} ];
|
||||
|
||||
# start looping from the second layer and intersect the current intersection with it
|
||||
for my $layerm (@layerms[1 .. $#layerms]) {
|
||||
$intersection = intersection_ex(
|
||||
[ map @$_, @$intersection ],
|
||||
[ map @{$_->expolygon}, grep $_->surface_type == $type, @{$layerm->fill_surfaces} ],
|
||||
[ map @{$_->expolygon}, @{$layerm->fill_surfaces->filter_by_type($type)} ],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -778,12 +774,12 @@ sub combine_infill {
|
|||
|
||||
|
||||
foreach my $layerm (@layerms) {
|
||||
my @this_type = grep $_->surface_type == $type, @{$layerm->fill_surfaces};
|
||||
my @this_type = @{$layerm->fill_surfaces->filter_by_type($type)};
|
||||
my @other_types = map $_->clone, grep $_->surface_type != $type, @{$layerm->fill_surfaces};
|
||||
|
||||
my @new_this_type = map Slic3r::Surface->new(expolygon => $_, surface_type => $type),
|
||||
@{diff_ex(
|
||||
[ map @{$_->expolygon}, @this_type ],
|
||||
[ map $_->p, @this_type ],
|
||||
[ @intersection_with_clearance ],
|
||||
)};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue