From 404c76adc804523fbc870b9a18b6267f38071f14 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 26 Sep 2011 16:07:12 +0200 Subject: [PATCH] New option to rotate input object --- README.markdown | 4 ++-- lib/Slic3r.pm | 1 + lib/Slic3r/STL.pm | 10 ++++++++++ slic3r.pl | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 30a0d3023..b637f2196 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 input object; +* ability to scale and rotate input object; * use different speed for bottom layer. Roadmap includes the following goals: @@ -46,7 +46,7 @@ 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; -* input object transform (rotate, multiply); +* multiply input object; * cool; * nice packaging for cross-platform deployment. diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index a3a85ee56..c139676cd 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -63,5 +63,6 @@ our $skirt_distance = 6; # mm # transform options our $scale = 1; +our $rotate = 0; 1; diff --git a/lib/Slic3r/STL.pm b/lib/Slic3r/STL.pm index ac5843406..a72714114 100644 --- a/lib/Slic3r/STL.pm +++ b/lib/Slic3r/STL.pm @@ -18,6 +18,16 @@ sub parse_file { # open STL file my $stl = CAD::Format::STL->new->load($file); + if ($Slic3r::rotate > 0) { + my $deg = Slic3r::Geometry::deg2rad($Slic3r::rotate); + foreach my $facet ($stl->part->facets) { + my ($normal, @vertices) = @$facet; + foreach my $vertex (@vertices) { + @$vertex = (@{ +(Slic3r::Geometry::rotate_points($deg, undef, [ $vertex->[X], $vertex->[Y] ]))[0] }, $vertex->[Z]); + } + } + } + # we only want to work with positive coordinates, so let's # find our object extents to calculate coordinate displacements my @extents = (map [99999999, -99999999], X,Y,Z); diff --git a/slic3r.pl b/slic3r.pl index 4cc4935ca..e274eac6a 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -55,6 +55,7 @@ GetOptions( # transform options 'scale=i' => \$Slic3r::scale, + 'rotate=i' => \$Slic3r::rotate, ); # validate configuration @@ -163,7 +164,7 @@ Usage: slic3r.pl [ OPTIONS ] file.stl --solid-layers Number of solid layers to do for top/bottom surfaces (range: 1+, default: $Slic3r::solid_layers) --fill-density Infill density (range: 0-1, default: $Slic3r::fill_density) - --fill-angle Infill angle (range: 0-90, default: $Slic3r::fill_angle) + --fill-angle Infill angle in degrees (range: 0-90, default: $Slic3r::fill_angle) --temperature Extrusion temperature (default: $Slic3r::temperature) Retraction options: @@ -181,6 +182,7 @@ 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) EOF exit ($exit_code || 0);