package Slic3r::AMF; use Moo; use Slic3r::Geometry qw(X Y Z); use XXX; sub read_file { my $self = shift; my ($file) = @_; eval "require Slic3r::AMF::Parser; 1" or die "AMF parsing requires XML::SAX::ExpatXS\n"; open my $fh, '<', $file or die "Failed to open $file\n"; my $vertices = []; my $facets = []; XML::SAX::ExpatXS ->new(Handler => Slic3r::AMF::Parser->new( _vertices => $vertices, _facets => $facets, )) ->parse_file($fh); close $fh; 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{\n}; printf $fh qq{\n}; printf $fh qq{ Slic3r %s\n}, $Slic3r::VERSION; printf $fh qq{ \n}; printf $fh qq{ \n}; printf $fh qq{ \n}; foreach my $vertex (@{$mesh->vertices}) { printf $fh qq{ \n}; printf $fh qq{ \n}; printf $fh qq{ %s\n}, $vertex->[X]; printf $fh qq{ %s\n}, $vertex->[Y]; printf $fh qq{ %s\n}, $vertex->[Z]; printf $fh qq{ \n}; printf $fh qq{ \n}; } printf $fh qq{ \n}; printf $fh qq{ \n}; foreach my $facet (@{$mesh->facets}) { printf $fh qq{ \n}; printf $fh qq{ %d\n}, $_, $facet->[$_], $_ for 1..3; printf $fh qq{ \n}; } printf $fh qq{ \n}; printf $fh qq{ \n}; printf $fh qq{ \n}; printf $fh qq{\n}; close $fh; } 1;