mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-14 02:07:54 -06:00
Regression test and incomplete fix for bug affecting wrong spiral vase output. #1773
This commit is contained in:
parent
ee82e56a4f
commit
1ec6494d65
3 changed files with 108 additions and 14 deletions
|
@ -2,6 +2,8 @@ package Slic3r::GCode::SpiralVase;
|
|||
use Moo;
|
||||
|
||||
has 'config' => (is => 'ro', required => 1);
|
||||
has 'enable' => (is => 'rw', default => sub { 0 });
|
||||
has 'gcode_reader' => (is => 'ro', default => sub { Slic3r::GCode::Reader->new });
|
||||
|
||||
use Slic3r::Geometry qw(unscale);
|
||||
|
||||
|
@ -9,26 +11,48 @@ sub process_layer {
|
|||
my $self = shift;
|
||||
my ($gcode, $layer) = @_;
|
||||
|
||||
# if we're not going to modify G-code, just feed it to the reader
|
||||
# in order to update positions
|
||||
if (!$self->enable) {
|
||||
$self->gcode_reader->parse($gcode, sub {});
|
||||
return $gcode;
|
||||
}
|
||||
|
||||
# get total XY length for this layer by summing all extrusion moves
|
||||
my $total_layer_length = 0;
|
||||
my $z = undef;
|
||||
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
||||
my ($reader, $cmd, $args, $info) = @_;
|
||||
$total_layer_length += $info->{dist_XY}
|
||||
if $cmd eq 'G1' && $info->{extruding};
|
||||
|
||||
if ($cmd eq 'G1') {
|
||||
$total_layer_length += $info->{dist_XY}
|
||||
if $info->{extruding};
|
||||
|
||||
# get first Z
|
||||
$z //= $args->{Z}
|
||||
if exists $args->{Z};
|
||||
}
|
||||
});
|
||||
|
||||
my $new_gcode = "";
|
||||
my $layer_height = $layer->height;
|
||||
my $z = $layer->print_z + $self->config->z_offset - $layer_height;
|
||||
|
||||
# remove layer height from initial Z
|
||||
$z -= $layer_height;
|
||||
|
||||
my $newlayer = 0;
|
||||
Slic3r::GCode::Reader->new->parse($gcode, sub {
|
||||
$self->gcode_reader->parse($gcode, sub {
|
||||
my ($reader, $cmd, $args, $info) = @_;
|
||||
|
||||
if ($cmd eq 'G1' && exists $args->{Z}) {
|
||||
# if this is the initial Z move of the layer, replace it with a
|
||||
# (redundant) move to the last Z of previous layer
|
||||
my $line = $info->{raw};
|
||||
$line =~ s/Z([^ ]+)/Z$z/;
|
||||
$line =~ s/Z[.0-9]+/Z$z/;
|
||||
$new_gcode .= "$line\n";
|
||||
$newlayer = 1;
|
||||
} elsif ($cmd eq 'G1' && !exists $args->{Z} && $info->{dist_XY}) {
|
||||
# horizontal move
|
||||
my $line = $info->{raw};
|
||||
if ($info->{extruding}) {
|
||||
$z += $info->{dist_XY} * $layer_height / $total_layer_length;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue