Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dump-stl.pl « utils - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12746feabf5a6a48dcd3f330ec96cd30c353d5b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
# This script dumps a STL file into Perl syntax for writing tests
# or dumps a test model into a STL file

use strict;
use warnings;

BEGIN {
    use FindBin;
    use lib "$FindBin::Bin/../lib";
}

use Slic3r;
use Slic3r::Test;
use File::Basename qw(basename);
$|++;

$ARGV[0] or usage(1);

if (-e $ARGV[0]) {
    my $model = Slic3r::Model->load_stl(Slic3r::encode_path($ARGV[0]), basename($ARGV[0]));
    $model->objects->[0]->add_instance(offset => Slic3r::Pointf->new(0,0));
    my $mesh = $model->mesh;
    $mesh->repair;
    printf "VERTICES = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->vertices};
    printf "FACETS = %s\n", join ',', map "[$_->[0],$_->[1],$_->[2]]", @{$mesh->facets};
    exit 0;
} elsif ((my $model = Slic3r::Test::model($ARGV[0]))) {
    $ARGV[1] or die "Missing writeable destination as second argument\n";
    $model->store_stl(Slic3r::encode_path($ARGV[1]), 1);
    printf "Model $ARGV[0] written to $ARGV[1]\n";
    exit 0;
} else {
    die "No such model exists\n";
}


sub usage {
    my ($exit_code) = @_;
    
    print <<"EOF";
Usage: dump-stl.pl file.stl
       dump-stl.pl modelname file.stl
EOF
    exit ($exit_code || 0);
}

__END__