From 81085433fd0c70b9a2566dedd46a6bd8bf398ded Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 26 Sep 2011 16:58:08 +0200 Subject: [PATCH] New options to multiply input object --- README.markdown | 3 +-- lib/Slic3r.pm | 3 +++ lib/Slic3r/STL.pm | 22 +++++++++++++++++++++- slic3r.pl | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index b637f2196..180d05528 100644 --- a/README.markdown +++ b/README.markdown @@ -37,7 +37,7 @@ Slic3r current features are: * use relative or absolute extrusion commands; * center print around bed center point; * multiple solid layers near horizontal external surfaces; -* ability to scale and rotate input object; +* ability to scale, rotate and multiply input object; * use different speed for bottom layer. Roadmap includes the following goals: @@ -46,7 +46,6 @@ Roadmap includes the following goals: * allow the user to customize initial and final GCODE commands; * support material for internal perimeters; * ability to infill in the direction of bridges; -* multiply input object; * cool; * nice packaging for cross-platform deployment. diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index c139676cd..9f2cc2132 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -64,5 +64,8 @@ our $skirt_distance = 6; # mm # transform options our $scale = 1; our $rotate = 0; +our $multiply_x = 1; +our $multiply_y = 1; +our $multiply_distance = 6; # mm 1; diff --git a/lib/Slic3r/STL.pm b/lib/Slic3r/STL.pm index 97b02a2e0..f48f0c97f 100644 --- a/lib/Slic3r/STL.pm +++ b/lib/Slic3r/STL.pm @@ -47,6 +47,20 @@ sub parse_file { $extents[$_][MAX] *= $Slic3r::scale; } + # multiply object + my @multiply_offset = ( + (($extents[X][MAX] - $extents[X][MIN]) + $Slic3r::multiply_distance), + (($extents[Y][MAX] - $extents[Y][MIN]) + $Slic3r::multiply_distance), + ); + $extents[X][MAX] += $multiply_offset[X] * ($Slic3r::multiply_x-1); + $extents[Y][MAX] += $multiply_offset[Y] * ($Slic3r::multiply_y-1); + my @copies = (); + for (my $i = 0; $i < $Slic3r::multiply_x; $i++) { + for (my $j = 0; $j < $Slic3r::multiply_y; $j++) { + push @copies, [ $multiply_offset[X] * $i, $multiply_offset[Y] * $j ]; + } + } + # initialize print job my $print = Slic3r::Print->new( x_length => ($extents[X][MAX] - $extents[X][MIN]) / $Slic3r::resolution, @@ -67,7 +81,13 @@ sub parse_file { for X,Y,Z; } - $self->_facet($print, @$facet); + foreach my $copy (@copies) { + my @copy_vertices = map [ @$_ ], @vertices; # clone vertices + foreach my $vertex (@copy_vertices) { + $vertex->[$_] += $copy->[$_] / $Slic3r::resolution for X,Y; + } + $self->_facet($print, $normal, @copy_vertices); + } } print "\n==> PROCESSING SLICES:\n"; diff --git a/slic3r.pl b/slic3r.pl index 6b79c3790..eb3944c25 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -56,6 +56,9 @@ GetOptions( # transform options 'scale=i' => \$Slic3r::scale, 'rotate=i' => \$Slic3r::rotate, + 'multiply-x=i' => \$Slic3r::multiply_x, + 'multiply-y=i' => \$Slic3r::multiply_y, + 'multiply-distance=i' => \$Slic3r::multiply_distance, ); # validate configuration @@ -100,6 +103,18 @@ GetOptions( # --scale die "Invalid value for --scale\n" if $Slic3r::scale <= 0; + + # --multiply-x + die "Invalid value for --multiply-x\n" + if $Slic3r::multiply_x < 1; + + # --multiply-y + die "Invalid value for --multiply-y\n" + if $Slic3r::multiply_y < 1; + + # --multiply-distance + die "Invalid value for --multiply-distance\n" + if $Slic3r::multiply_distance < 1; } my $stl_parser = Slic3r::STL->new; @@ -186,6 +201,9 @@ Usage: slic3r.pl [ OPTIONS ] file.stl Transform options: --scale Factor for scaling input object (default: $Slic3r::scale) --rotate Rotation angle in degrees (0-360, default: $Slic3r::rotate) + --multiply-x Number of items along X axis (1+, default: $Slic3r::multiply_x) + --multiply-y Number of items along Y axis (1+, default: $Slic3r::multiply_y) + --multiply-distance Distance in mm between copies (default: $Slic3r::multiply_distance) EOF exit ($exit_code || 0);