mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Fixed spiral vase regressions. Includes regression tests. #1773
This commit is contained in:
		
							parent
							
								
									1ec6494d65
								
							
						
					
					
						commit
						0c7a1777de
					
				
					 4 changed files with 66 additions and 47 deletions
				
			
		| 
						 | 
				
			
			@ -3,54 +3,60 @@ 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 });
 | 
			
		||||
has 'reader' => (is => 'ro', default => sub { Slic3r::GCode::Reader->new });
 | 
			
		||||
 | 
			
		||||
use Slic3r::Geometry qw(unscale);
 | 
			
		||||
 | 
			
		||||
sub process_layer {
 | 
			
		||||
    my $self = shift;
 | 
			
		||||
    my ($gcode, $layer) = @_;
 | 
			
		||||
    my ($gcode) = @_;
 | 
			
		||||
    
 | 
			
		||||
    # This post-processor relies on several assumptions:
 | 
			
		||||
    # - all layers are processed through it, including those that are not supposed
 | 
			
		||||
    #   to be transformed, in order to update the reader with the XY positions
 | 
			
		||||
    # - each call to this method includes a full layer, with a single Z move
 | 
			
		||||
    #   at the beginning
 | 
			
		||||
    # - each layer is composed by suitable geometry (i.e. a single complete loop)
 | 
			
		||||
    # - loops were not clipped before calling this method
 | 
			
		||||
    
 | 
			
		||||
    # 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 {});
 | 
			
		||||
        $self->reader->parse($gcode, sub {});
 | 
			
		||||
        return $gcode;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    # get total XY length for this layer by summing all extrusion moves
 | 
			
		||||
    my $total_layer_length = 0;
 | 
			
		||||
    my $layer_height = 0;
 | 
			
		||||
    my $z = undef;
 | 
			
		||||
    Slic3r::GCode::Reader->new->parse($gcode, sub {
 | 
			
		||||
    $self->reader->clone->parse($gcode, sub {
 | 
			
		||||
        my ($reader, $cmd, $args, $info) = @_;
 | 
			
		||||
        
 | 
			
		||||
        if ($cmd eq 'G1') {
 | 
			
		||||
            $total_layer_length += $info->{dist_XY}
 | 
			
		||||
                if $info->{extruding};
 | 
			
		||||
            
 | 
			
		||||
            # get first Z
 | 
			
		||||
            $z //= $args->{Z}
 | 
			
		||||
                if exists $args->{Z};
 | 
			
		||||
            if ($info->{extruding}) {
 | 
			
		||||
                $total_layer_length += $info->{dist_XY};
 | 
			
		||||
            } elsif (exists $args->{Z}) {
 | 
			
		||||
                $layer_height += $info->{dist_Z};
 | 
			
		||||
                $z //= $args->{Z};
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
    
 | 
			
		||||
    my $new_gcode = "";
 | 
			
		||||
    my $layer_height = $layer->height;
 | 
			
		||||
    
 | 
			
		||||
    #use XXX; YYY [ $gcode, $layer_height, $z, $total_layer_length ];
 | 
			
		||||
    # remove layer height from initial Z
 | 
			
		||||
    $z -= $layer_height;
 | 
			
		||||
    
 | 
			
		||||
    my $newlayer = 0;
 | 
			
		||||
    $self->gcode_reader->parse($gcode, sub {
 | 
			
		||||
    my $new_gcode = "";
 | 
			
		||||
    $self->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[.0-9]+/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};
 | 
			
		||||
| 
						 | 
				
			
			@ -58,11 +64,6 @@ sub process_layer {
 | 
			
		|||
                $z += $info->{dist_XY} * $layer_height / $total_layer_length;
 | 
			
		||||
                $line =~ s/^G1 /sprintf 'G1 Z%.3f ', $z/e;
 | 
			
		||||
                $new_gcode .= "$line\n";
 | 
			
		||||
            } elsif ($newlayer) {
 | 
			
		||||
                # remove the first travel move after layer change; extrusion
 | 
			
		||||
                # will just blend to the first loop vertex
 | 
			
		||||
                # TODO: should we adjust (stretch) E for the first loop segment?
 | 
			
		||||
                $newlayer = 0;
 | 
			
		||||
            } else {
 | 
			
		||||
                $new_gcode .= "$line\n";
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue