mirror of
https://github.com/FULU-Foundation/OrcaSlicer-bambulab.git
synced 2026-05-14 19:12:38 -07:00
Command line interface
This commit is contained in:
@@ -3,6 +3,11 @@ package Slic3r;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $debug = 0;
|
||||
sub debugf {
|
||||
printf @_ if $debug;
|
||||
}
|
||||
|
||||
use Slic3r::ExtrusionPath;
|
||||
use Slic3r::Fill;
|
||||
use Slic3r::Layer;
|
||||
@@ -15,11 +20,12 @@ use Slic3r::Print;
|
||||
use Slic3r::STL;
|
||||
use Slic3r::Surface;
|
||||
|
||||
|
||||
our $layer_height = 0.4;
|
||||
our $resolution = 0.1;
|
||||
our $perimeter_offsets = 3;
|
||||
our $fill_density = 0.2; # 1 = 100%
|
||||
our $flow_width = 0.4; # TODO: verify this is a multiple of $resolution
|
||||
our $flow_width = 0.4;
|
||||
our $temperature = 195;
|
||||
|
||||
our $flow_rate = 60; # mm/sec
|
||||
@@ -27,7 +33,7 @@ our $print_feed_rate = 60; # mm/sec
|
||||
our $travel_feed_rate = 80; # mm/sec
|
||||
our $bottom_layer_speed_ratio = 0.6;
|
||||
|
||||
our $use_relative_e_distances = 1;
|
||||
our $use_relative_e_distances = 0;
|
||||
|
||||
our $print_center = [100,100]; # object will be centered around this point
|
||||
|
||||
|
||||
@@ -18,10 +18,9 @@ sub make_fill {
|
||||
|
||||
# let's alternate fill direction
|
||||
my @axes = $layer->id % 2 == 0 ? (0,1) : (1,0);
|
||||
printf " primary axis: %d\n", $axes[0];
|
||||
|
||||
foreach my $surface (@{ $layer->fill_surfaces }) {
|
||||
printf " Processing surface %s:\n", $surface->id;
|
||||
Slic3r::debugf " Processing surface %s:\n", $surface->id;
|
||||
my $polygon = $surface->mgp_polygon;
|
||||
|
||||
# rotate surface as needed
|
||||
@@ -34,10 +33,6 @@ sub make_fill {
|
||||
my $distance_between_lines = $Slic3r::flow_width / $Slic3r::resolution / $density;
|
||||
my $number_of_lines = ($axes[0] == 0 ? $print->x_length : $print->y_length) / $distance_between_lines;
|
||||
|
||||
#printf "distance_between_lines = %f\n", $distance_between_lines;
|
||||
#printf "number_of_lines = %d\n", $number_of_lines;
|
||||
#printf "axes = %d, %d\n", @axes;
|
||||
|
||||
# this arrayref will hold intersection points of the fill grid with surface segments
|
||||
my $points = [ map [], 0..$number_of_lines-1 ];
|
||||
foreach my $line (map $self->_lines_from_mgp_points($_), @{ $polygon->polygons }) {
|
||||
@@ -49,7 +44,7 @@ sub make_fill {
|
||||
|
||||
# find out the coordinates
|
||||
my @coordinates = map @$_, @$line;
|
||||
printf "Segment %d,%d - %d,%d\n", @coordinates;
|
||||
Slic3r::debugf "Segment %d,%d - %d,%d\n", @coordinates;
|
||||
|
||||
# get the extents of the segment along the primary axis
|
||||
my @line_c = sort ($coordinates[X1], $coordinates[X2]);
|
||||
@@ -59,15 +54,15 @@ sub make_fill {
|
||||
|
||||
# if the segment is parallel to our ray, there will be two intersection points
|
||||
if ($line_c[0] == $line_c[1]) {
|
||||
printf " Segment is parallel!\n";
|
||||
Slic3r::debugf " Segment is parallel!\n";
|
||||
push @{ $points->[$i] }, $coordinates[Y1], $coordinates[Y2];
|
||||
printf " intersections at %f (%d) = %f, %f\n", $c, $i, $points->[$i][-2], $points->[$i][-1];
|
||||
Slic3r::debugf " intersections at %f (%d) = %f, %f\n", $c, $i, $points->[$i][-2], $points->[$i][-1];
|
||||
} else {
|
||||
printf " Segment NOT parallel!\n";
|
||||
Slic3r::debugf " Segment NOT parallel!\n";
|
||||
# one point of intersection
|
||||
push @{ $points->[$i] }, $coordinates[Y1] + ($coordinates[Y2] - $coordinates[Y1])
|
||||
* ($c - $coordinates[X1]) / ($coordinates[X2] - $coordinates[X1]);
|
||||
printf " intersection at %f (%d) = %f\n", $c, $i, $points->[$i][-1];
|
||||
Slic3r::debugf " intersection at %f (%d) = %f\n", $c, $i, $points->[$i][-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,13 +97,13 @@ sub make_fill {
|
||||
# loop through rows
|
||||
ROW: for (my $i = 0; $i < $number_of_lines; $i++) {
|
||||
my $row = $points->[$i];
|
||||
printf "Processing row %d...\n", $i;
|
||||
Slic3r::debugf "Processing row %d...\n", $i;
|
||||
if (!@$row) {
|
||||
printf " no points\n";
|
||||
Slic3r::debugf " no points\n";
|
||||
$stop_path->();
|
||||
next ROW;
|
||||
}
|
||||
printf " points = %s\n", join ', ', @$row;
|
||||
Slic3r::debugf " points = %s\n", join ', ', @$row if $Slic3r::debug;
|
||||
|
||||
# coordinate of current row
|
||||
my $c = ($i + 1) * $distance_between_lines;
|
||||
@@ -120,8 +115,8 @@ sub make_fill {
|
||||
|
||||
my @connectable_points = $self->find_connectable_points($polygon, $path_points[-1], $c, $row);
|
||||
@connectable_points = reverse @connectable_points if $direction == 1;
|
||||
printf " found %d connectable points = %s\n", scalar(@connectable_points),
|
||||
join ', ', @connectable_points;
|
||||
Slic3r::debugf " found %d connectable points = %s\n", scalar(@connectable_points),
|
||||
join ', ', @connectable_points if $Slic3r::debug;
|
||||
|
||||
if (!@connectable_points && @path_points && $path_points[-1][0] != $c) {
|
||||
# no connectable in this row
|
||||
|
||||
@@ -181,8 +181,8 @@ sub merge_continuous_lines {
|
||||
# create new line
|
||||
my ($a, $b) = grep $_ ne $point, $line->points, $neighbor_line->points;
|
||||
my $new_line = $self->add_line($a, $b);
|
||||
printf "Merging continuous lines %s and %s into %s\n",
|
||||
$line->id, $neighbor_line->id, $new_line->id;
|
||||
Slic3r::debugf "Merging continuous lines %s and %s into %s\n",
|
||||
$line->id, $neighbor_line->id, $new_line->id if $Slic3r::debug;
|
||||
|
||||
# delete merged lines
|
||||
$self->remove_line($_) for ($line, $neighbor_line);
|
||||
@@ -226,8 +226,8 @@ sub make_polylines {
|
||||
$cur_line = $next_line;
|
||||
}
|
||||
|
||||
printf "Discovered polyline of %d lines (%s)\n", scalar keys %points,
|
||||
join('-', map $_->id, values %visited_lines);
|
||||
Slic3r::debugf "Discovered polyline of %d lines (%s)\n", scalar keys %points,
|
||||
join('-', map $_->id, values %visited_lines) if $Slic3r::debug;
|
||||
push @$polylines, Slic3r::Polyline::Closed->new(lines => [values %visited_lines]);
|
||||
}
|
||||
|
||||
@@ -284,8 +284,9 @@ sub make_surfaces {
|
||||
$surface->surface_type('internal');
|
||||
push @{ $self->surfaces }, $surface;
|
||||
|
||||
printf "New surface: %s (holes: %s)\n",
|
||||
$surface->id, join(', ', map $_->id, @{$surface->holes}) || 'none';
|
||||
Slic3r::debugf "New surface: %s (holes: %s)\n",
|
||||
$surface->id, join(', ', map $_->id, @{$surface->holes}) || 'none'
|
||||
if $Slic3r::debug;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,13 +311,13 @@ sub merge_contiguous_surfaces {
|
||||
|
||||
# defensive programming
|
||||
if (@common_lines > 2) {
|
||||
printf "Surfaces %s and %s share %d lines! How's it possible?\n",
|
||||
$surface->id, $neighbor_surface->id, scalar @common_lines;
|
||||
Slic3r::debugf "Surfaces %s and %s share %d lines! How's it possible?\n",
|
||||
$surface->id, $neighbor_surface->id, scalar @common_lines if $Slic3r::debug;
|
||||
}
|
||||
|
||||
printf "Surfaces %s and %s share line/lines %s!\n",
|
||||
Slic3r::debugf "Surfaces %s and %s share line/lines %s!\n",
|
||||
$surface->id, $neighbor_surface->id,
|
||||
join(', ', map $_->id, @common_lines);
|
||||
join(', ', map $_->id, @common_lines) if $Slic3r::debug;
|
||||
|
||||
# defensive programming
|
||||
if ($surface->surface_type ne $neighbor_surface->surface_type) {
|
||||
@@ -342,7 +343,7 @@ sub merge_contiguous_surfaces {
|
||||
surface_type => $surface->surface_type,
|
||||
);
|
||||
|
||||
printf " merging into new surface %s\n", $new_surface->id;
|
||||
Slic3r::debugf " merging into new surface %s\n", $new_surface->id;
|
||||
push @{ $self->surfaces }, $new_surface;
|
||||
|
||||
$self->remove_surface($_) for ($surface, $neighbor_surface);
|
||||
|
||||
@@ -50,8 +50,8 @@ sub extrude_perimeters {
|
||||
|
||||
foreach my $layer (@{ $self->layers }) {
|
||||
$perimeter_extruder->make_perimeter($layer);
|
||||
printf " generated paths: %s\n",
|
||||
join ' ', map $_->id, @{ $layer->perimeters };
|
||||
Slic3r::debugf " generated paths: %s\n",
|
||||
join ' ', map $_->id, @{ $layer->perimeters } if $Slic3r::debug;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,9 +62,9 @@ sub extrude_fills {
|
||||
|
||||
foreach my $layer (@{ $self->layers }) {
|
||||
$fill_extruder->make_fill($self, $layer);
|
||||
printf " generated %d paths: %s\n",
|
||||
Slic3r::debugf " generated %d paths: %s\n",
|
||||
scalar @{ $layer->fills },
|
||||
join ' ', map $_->id, @{ $layer->fills };
|
||||
join ' ', map $_->id, @{ $layer->fills } if $Slic3r::debug;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ sub parse_file {
|
||||
# calculate the displacements needed to
|
||||
# have lowest value for each axis at coordinate 0
|
||||
my @shift = map 0 - $extents[$_][MIN], X,Y,Z;
|
||||
printf "shift = %d, %d, %d\n", @shift[X,Y,Z];
|
||||
|
||||
# process facets
|
||||
foreach my $facet ($stl->part->facets) {
|
||||
@@ -77,7 +76,8 @@ sub parse_file {
|
||||
sub _facet {
|
||||
my $self = shift;
|
||||
my ($print, $normal, @vertices) = @_;
|
||||
printf "\n==> FACET (%s):\n", join('-', map join(',', @$_), @vertices);
|
||||
Slic3r::debugf "\n==> FACET (%s):\n", join('-', map join(',', @$_), @vertices)
|
||||
if $Slic3r::debug;
|
||||
|
||||
# find the vertical extents of the facet
|
||||
my ($min_z, $max_z) = (99999999, -99999999);
|
||||
@@ -85,15 +85,15 @@ sub _facet {
|
||||
$min_z = $vertex->[Z] if $vertex->[Z] < $min_z;
|
||||
$max_z = $vertex->[Z] if $vertex->[Z] > $max_z;
|
||||
}
|
||||
printf "z: min = %.0f, max = %.0f\n", $min_z, $max_z;
|
||||
Slic3r::debugf "z: min = %.0f, max = %.0f\n", $min_z, $max_z;
|
||||
|
||||
# calculate the layer extents
|
||||
my ($min_layer, $max_layer) = map {$_ * $Slic3r::resolution / $Slic3r::layer_height} $min_z, $max_z;
|
||||
printf "layers: min = %.0f, max = %.0f\n", $min_layer, $max_layer;
|
||||
Slic3r::debugf "layers: min = %.0f, max = %.0f\n", $min_layer, $max_layer;
|
||||
|
||||
# is the facet horizontal?
|
||||
if ($min_layer == $max_layer) {
|
||||
printf "Facet is horizontal\n";
|
||||
Slic3r::debugf "Facet is horizontal\n";
|
||||
my $layer = $print->layer($min_layer);
|
||||
my $surface = $layer->add_surface(@vertices);
|
||||
|
||||
@@ -151,7 +151,7 @@ sub _facet {
|
||||
|
||||
# check whether the two points coincide due to resolution rounding
|
||||
if ($intersection_points[0]->coincides_with($intersection_points[1])) {
|
||||
printf "Points coincide; removing\n";
|
||||
Slic3r::debugf "Points coincide; removing\n";
|
||||
$layer->remove_point($_) for @intersection_points;
|
||||
next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user