~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to lib/Slic3r/Format/OBJ.pm

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Slic3r::Format::OBJ;
 
2
use Moo;
 
3
 
 
4
use File::Basename qw(basename);
 
5
 
 
6
sub read_file {
 
7
    my $self = shift;
 
8
    my ($file) = @_;
 
9
    
 
10
    Slic3r::open(\my $fh, '<', $file) or die "Failed to open $file\n";
 
11
    my $vertices = [];
 
12
    my $facets = [];
 
13
    while (<$fh>) {
 
14
        if (/^v ([^ ]+)\s+([^ ]+)\s+([^ ]+)/) {
 
15
            push @$vertices, [$1, $2, $3];
 
16
        } elsif (/^f (\d+).*? (\d+).*? (\d+).*?/) {
 
17
            push @$facets, [ $1-1, $2-1, $3-1 ];
 
18
        }
 
19
    }
 
20
    close $fh;
 
21
    
 
22
    my $mesh = Slic3r::TriangleMesh->new;
 
23
    $mesh->ReadFromPerl($vertices, $facets);
 
24
    $mesh->repair;
 
25
    
 
26
    my $model = Slic3r::Model->new;
 
27
    
 
28
    my $material_id = basename($file);
 
29
    $model->set_material($material_id);
 
30
    
 
31
    my $object = $model->add_object;
 
32
    my $volume = $object->add_volume(mesh => $mesh, material_id => $material_id);
 
33
    return $model;
 
34
}
 
35
 
 
36
1;