Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some progress
  • Loading branch information
alranel committed Jan 26, 2013
1 parent 0216448 commit 68f1ed6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/Slic3r/Format/OBJ.pm
Expand Up @@ -40,14 +40,24 @@ sub read_file {
}
close $fh;

my $model = Slic3r::Model->new;
my $model = Slic3r::Model->new(
has_facet_materials => (%materials ? 1 : 0),
);
my $object = $model->add_object(vertices => $vertices);

# reverse %materials and turn it into an array
my @materials_array = ();
{
my %reversed_materials = reverse %materials; # material_idx => material_id
$materials_array[$_] = $reversed_materials{$_} for keys %reversed_materials;
}

my $volume = $object->add_volume(
facets => $facets,
facets_materials => $facets_materials,
materials => { reverse %materials },
materials => [ @materials_array ],
);
$model->set_material($_) for keys %materials;use XXX; XXX $model;
$model->set_material($_) for keys %materials;
return $model;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Slic3r/Model.pm
Expand Up @@ -5,6 +5,7 @@ use Slic3r::Geometry qw(X Y Z);

has 'materials' => (is => 'ro', default => sub { {} });
has 'objects' => (is => 'ro', default => sub { [] });
has 'has_facet_materials' => (is => 'ro', default => sub { 0 });

sub read_from_file {
my $class = shift;
Expand Down
19 changes: 19 additions & 0 deletions lib/Slic3r/Print/Object.pm
Expand Up @@ -88,6 +88,19 @@ sub slice {
}
die "Invalid input file\n" if !@{$self->layers};

# before freeing memory from mesh data, extract horizontal facets having materials
my @horiz_facets_with_material = (); # region_id => [ facet1, facet2 ... ]
if (1) {
foreach my $mesh (@{$self->meshes}) {
push @horiz_facets_with_material, [];
next unless defined $mesh;
push @{$horiz_facets_with_material[-1]},
grep { $_->[0][Z] == $_->[1][Z] && $_->[1][Z] == $_->[2][Z] }
map [ map $mesh->vertices->[$_], @$_ ],
@{$mesh->facets};
}
}
use XXX; XXX \@horiz_facets_with_material;
# free memory
$self->meshes(undef) unless $params{keep_meshes};

Expand All @@ -110,11 +123,17 @@ sub slice {
# inside a closed polyline)

# build surfaces from sparse lines
my %surface_materials = (); # region_id => { lines => [], horiz_facets => [] }
foreach my $layerm (@{$layer->regions}) {
my ($slicing_errors, $loops) = Slic3r::TriangleMesh::make_loops($layerm->lines);
$layer->slicing_errors(1) if $slicing_errors;
$layerm->make_surfaces($loops);

if (1) {
# let's extract surface materials from $loops
# and from $self->meshes... whoops, we don't have meshes anymore!
}

# free memory
$layerm->lines(undef);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Slic3r/TriangleMesh.pm
Expand Up @@ -7,8 +7,8 @@ use Slic3r::Geometry::Clipper qw(union_ex);
# public
has 'vertices' => (is => 'ro', required => 1); # id => [$x,$y,$z]
has 'facets' => (is => 'ro', required => 1); # id => [ $v1_id, $v2_id, $v3_id ]
has 'materials' => (is => 'ro', default => sub { [] }); # material_idx => material_id
has 'facets_materials' => (is => 'ro'); # facet_idx => material_idx
has 'materials' => (is => 'ro', default => sub { [] }); # material_idx => material_id
has 'facets_materials' => (is => 'ro', default => sub { [] }); # facet_idx => material_idx

# private
has 'edges' => (is => 'ro', default => sub { [] }); # id => [ $v1_id, $v2_id ]
Expand Down Expand Up @@ -98,6 +98,8 @@ sub clone {
return (ref $self)->new(
vertices => [ map [ @$_ ], @{$self->vertices} ],
facets => [ map [ @$_ ], @{$self->facets} ],
materials => [ @{$self->materials} ],
facets_materials => [ @{$self->facets_materials} ],
);
}

Expand Down

0 comments on commit 68f1ed6

Please sign in to comment.