mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-07 22:14:00 -06:00
Read OBJ files. #324
This commit is contained in:
parent
fbe70ac15b
commit
1998801a58
7 changed files with 35 additions and 6 deletions
23
lib/Slic3r/Format/OBJ.pm
Normal file
23
lib/Slic3r/Format/OBJ.pm
Normal file
|
@ -0,0 +1,23 @@
|
|||
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;
|
Loading…
Add table
Add a link
Reference in a new issue