Parse and write multi-material AMF files. Convert multiple STL files into a single multi-material AMF

This commit is contained in:
Alessandro Ranellucci 2012-02-20 16:43:45 +01:00
parent aa98a9deb2
commit b6bffacb9d
5 changed files with 97 additions and 33 deletions

View file

@ -24,12 +24,23 @@ my %opt = ();
}
{
my $mesh = Slic3r::STL->read_file($ARGV[0]);
my @meshes = map Slic3r::STL->read_file($_), @ARGV;
my $output_file = $ARGV[0];
$output_file =~ s/\.stl$/.amf.xml/i;
my $materials = {};
my $meshes_by_material = {};
if (@meshes == 1) {
$meshes_by_material->{_} = $meshes[0];
} else {
for (0..$#meshes) {
$materials->{$_+1} = { Name => basename($ARGV[$_]) };
$meshes_by_material->{$_+1} = $meshes[$_];
}
}
printf "Writing to %s\n", basename($output_file);
Slic3r::AMF->write_file($output_file, $mesh);
Slic3r::AMF->write_file($output_file, $materials, $meshes_by_material);
}
@ -37,7 +48,7 @@ sub usage {
my ($exit_code) = @_;
print <<"EOF";
Usage: amf-to-stl.pl [ OPTIONS ] file.stl
Usage: amf-to-stl.pl [ OPTIONS ] file.stl [ file2.stl [ file3.stl ] ]
--help Output this usage screen and exit