PrusaSlicer-NonPlainar/lib/Slic3r/Format/OBJ.pm
Alessandro Ranellucci 1998801a58 Read OBJ files. #324
2012-05-20 11:40:37 +02:00

24 lines
550 B
Perl

package Slic3r::Format::OBJ;
use Moo;
sub read_file {
my $self = shift;
my ($file) = @_;
open my $fh, '<', $file or die "Failed to open $file\n";
my $vertices = [];
my $facets = [];
while (my $_ = <$fh>) {
if (/^v ([^ ]+)\s+([^ ]+)\s+([^ ]+)/) {
push @$vertices, [$1, $2, $3];
} elsif (/^f (\d+).*? (\d+).*? (\d+).*?/) {
push @$facets, [ $1-1, $2-1, $3-1 ];
}
}
close $fh;
return Slic3r::TriangleMesh->new(vertices => $vertices, facets => $facets);
}
1;