Skip to content
Browse files

Some progress

  • Loading branch information...
1 parent 0216448 commit 68f1ed655810c9d44b517e84d2b82a664c7681a4 @alexrj committed Jan 26, 2013
Showing with 37 additions and 5 deletions.
  1. +13 −3 lib/Slic3r/Format/OBJ.pm
  2. +1 −0 lib/Slic3r/Model.pm
  3. +19 −0 lib/Slic3r/Print/Object.pm
  4. +4 −2 lib/Slic3r/TriangleMesh.pm
View
16 lib/Slic3r/Format/OBJ.pm
@@ -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;
}
View
1 lib/Slic3r/Model.pm
@@ -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;
View
19 lib/Slic3r/Print/Object.pm
@@ -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};
@@ -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);
}
View
6 lib/Slic3r/TriangleMesh.pm
@@ -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 ]
@@ -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} ],
);
}

0 comments on commit 68f1ed6

Please sign in to comment.
Something went wrong with that request. Please try again.