mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-31 09:02:53 +00:00
New AMF-to-STL and STL-to-AMF converters
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package Slic3r::AMF;
|
||||
use Moo;
|
||||
|
||||
use Slic3r::Geometry qw(X Y Z);
|
||||
use XXX;
|
||||
|
||||
sub read_file {
|
||||
@@ -25,4 +27,41 @@ sub read_file {
|
||||
return Slic3r::TriangleMesh->new(vertices => $vertices, facets => $facets);
|
||||
}
|
||||
|
||||
sub write_file {
|
||||
my $self = shift;
|
||||
my ($file, $mesh) = @_;
|
||||
|
||||
open my $fh, '>', $file;
|
||||
binmode $fh, ':utf8';
|
||||
|
||||
printf $fh qq{<?xml version="1.0" encoding="UTF-8"?>\n};
|
||||
printf $fh qq{<amf unit="millimeter">\n};
|
||||
printf $fh qq{ <metadata type="cad">Slic3r %s</metadata>\n}, $Slic3r::VERSION;
|
||||
printf $fh qq{ <object id="0">\n};
|
||||
printf $fh qq{ <mesh>\n};
|
||||
printf $fh qq{ <vertices>\n};
|
||||
foreach my $vertex (@{$mesh->vertices}) {
|
||||
printf $fh qq{ <vertex>\n};
|
||||
printf $fh qq{ <coordinates>\n};
|
||||
printf $fh qq{ <x>%s</x>\n}, $vertex->[X];
|
||||
printf $fh qq{ <y>%s</y>\n}, $vertex->[Y];
|
||||
printf $fh qq{ <z>%s</z>\n}, $vertex->[Z];
|
||||
printf $fh qq{ </coordinates>\n};
|
||||
printf $fh qq{ </vertex>\n};
|
||||
}
|
||||
printf $fh qq{ </vertices>\n};
|
||||
printf $fh qq{ <volume>\n};
|
||||
foreach my $facet (@{$mesh->facets}) {
|
||||
printf $fh qq{ <triangle>\n};
|
||||
printf $fh qq{ <v%d>%d</v%d>\n}, $_, $facet->[$_], $_ for 1..3;
|
||||
printf $fh qq{ </triangle>\n};
|
||||
}
|
||||
printf $fh qq{ </volume>\n};
|
||||
printf $fh qq{ </mesh>\n};
|
||||
printf $fh qq{ </object>\n};
|
||||
printf $fh qq{</amf>\n};
|
||||
|
||||
close $fh;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user