diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2014-10-28 23:49:01 +0300 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2014-12-22 00:52:18 +0300 |
commit | 5b51832b622238cd332de77f26799e1afab6f51a (patch) | |
tree | 8f4d1c372dcdaff65d0be7b1f5cf293b35a40055 /utils | |
parent | 9ac60dca1a452aed7769ff48bb3f6f940c8fe8dc (diff) |
Wireframe.pl wireframe
Diffstat (limited to 'utils')
-rw-r--r-- | utils/wireframe.pl | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/utils/wireframe.pl b/utils/wireframe.pl new file mode 100644 index 000000000..931897563 --- /dev/null +++ b/utils/wireframe.pl @@ -0,0 +1,102 @@ +#!/usr/bin/perl +# This script exports experimental G-code for wireframe printing +# (inspired by the brilliant WirePrint concept) + +use strict; +use warnings; + +BEGIN { + use FindBin; + use lib "$FindBin::Bin/../lib"; +} + +use Getopt::Long qw(:config no_auto_abbrev); +use PDF::API2; +use Slic3r; +use Slic3r::ExtrusionPath ':roles'; +use Slic3r::Geometry qw(scale unscale X Y); + +my %opt = ( + step_height => 10, +); +{ + my %options = ( + 'help' => sub { usage() }, + 'output|o=s' => \$opt{output_file}, + 'step-height|h=f' => \$opt{step_height}, + 'nozzle-angle|a=f' => \$opt{nozzle_angle}, + ); + GetOptions(%options) or usage(1); + $opt{output_file} or usage(1); + ### Input file is not needed until we use hard-coded geometry: + ### $ARGV[0] or usage(1); +} + +{ + my $flow = Slic3r::Flow->new( + width => 0.35, + height => 0.35, + nozzle_diameter => 0.35, + bridge => 1, + ); + + my $section; + + # build a square section + { + my $dist = 2 * $opt{step_height}; # horizontal step + my $side_modules = 3; + my @points = ( + [0,0], + (map [$_*$dist, 0], 1..$side_modules), + (map [$side_modules*$dist, $_*$dist], 1..$side_modules), + (map [($_-1)*$dist, $side_modules*$dist], reverse 1..$side_modules), + (map [0, ($_-1)*$dist], reverse 1..$side_modules), + ); + pop @points; # prevent coinciding endpoints + $section = Slic3r::Polygon->new_scale(@points); + } + my $section_loop = Slic3r::ExtrusionLoop->new_from_paths( + Slic3r::ExtrusionPath->new( + polyline => $section->split_at_first_point, + role => EXTR_ROLE_BRIDGE, + mm3_per_mm => $flow->mm3_per_mm, + width => $flow->width, + height => $flow->height, + ) + ); + + my $vertical_steps = 3; + + open my $fh, '>', $opt{output_file}; + my $gcodegen = Slic3r::GCode->new( + enable_loop_clipping => 0, # better bonding + ); + $gcodegen->set_extruders([0]); + print $fh $gcodegen->set_extruder(0); + print $fh $gcodegen->writer->preamble; + + foreach my $z (map $_*$opt{step_height}, 0..($vertical_steps-1)) { + print $fh $gcodegen->writer->travel_to_z($z + $flow->height); + print $fh $gcodegen->extrude_loop($section_loop, "contour"); + } + + close $fh; +} + +sub usage { + my ($exit_code) = @_; + + print <<"EOF"; +Usage: wireframe.pl [ OPTIONS ] file.stl + + --help Output this usage screen and exit + --output, -o Write to the specified file + --step-height, -h Use the specified step height + --nozzle-angle, -a Max nozzle angle + +EOF + exit ($exit_code || 0); +} + +__END__ |