diff --git a/lib/Slic3r/Format/AMF.pm b/lib/Slic3r/Format/AMF.pm index 247914484..ce388ec2e 100644 --- a/lib/Slic3r/Format/AMF.pm +++ b/lib/Slic3r/Format/AMF.pm @@ -74,7 +74,7 @@ sub write_file { foreach my $facet (@{$mesh->facets}) { printf $fh qq{ \n}; printf $fh qq{ %d\n}, $_, $facet->[$_] + $vertices_offset{$mesh}, $_ - for 1..3; + for -3..-1; printf $fh qq{ \n}; } printf $fh qq{ \n}; diff --git a/lib/Slic3r/Format/AMF/Parser.pm b/lib/Slic3r/Format/AMF/Parser.pm index 48f8521b8..1d8d4dc39 100644 --- a/lib/Slic3r/Format/AMF/Parser.pm +++ b/lib/Slic3r/Format/AMF/Parser.pm @@ -26,9 +26,9 @@ sub start_element { $self->{_volume_materialid} = $self->_get_attribute($data, 'materialid') || '_'; $self->{_volume} = []; } elsif ($data->{LocalName} eq 'triangle') { - $self->{_triangle} = [[], "", "", ""]; # empty normal + $self->{_triangle} = ["", "", ""]; } elsif ($self->{_triangle} && $data->{LocalName} =~ /^v([123])$/ && $self->{_tree}[-1] eq 'triangle') { - $self->{_vertex_idx} = $1; + $self->{_vertex_idx} = $1-1; } elsif ($data->{LocalName} eq 'material') { $self->{_material_id} = $self->_get_attribute($data, 'id') || '_'; $self->{_material} = {}; diff --git a/lib/Slic3r/Format/STL.pm b/lib/Slic3r/Format/STL.pm index 1e30394dd..29549ff8d 100644 --- a/lib/Slic3r/Format/STL.pm +++ b/lib/Slic3r/Format/STL.pm @@ -43,7 +43,7 @@ sub read_file { my %vertices_map = (); # given a vertex's coordinates, what's its index? my @vertices_facets = (); # given a vertex index, what are the indexes of its tangent facets? for (my $f = 0; $f <= $#$facets; $f++) { - for (1..3) { + for (-3..-1) { my $point_id = join ',', @{$facets->[$f][$_]}; if (exists $vertices_map{$point_id}) { $facets->[$f][$_] = $vertices_map{$point_id}; @@ -74,11 +74,11 @@ sub read_file { CYCLE: while (@facets_indexes && @this_f) { # look for a facet that is connected to $this_f[-1] and whose common line contains $v - my @other_vertices_indexes = grep $_ != $v, @{$facets->[$this_f[-1]]}[1..3]; + my @other_vertices_indexes = grep $_ != $v, @{$facets->[$this_f[-1]]}[-3..-1]; OTHER: for my $other_f (@facets_indexes) { # facet is connected if it shares one more point - for (grep $_ != $v, @{$facets->[$other_f]}[1..3]) { + for (grep $_ != $v, @{$facets->[$other_f]}[-3..-1]) { if ($_ ~~ @other_vertices_indexes) { #printf "facet %d is connected to $other_f (sharing vertices $v and $_)\n", $this_f[-1]; @@ -107,7 +107,7 @@ sub read_file { Slic3r::debugf " more than one vertex in the same point\n"; push @$vertices, $vertices->[$v]; for my $f (@this_f) { - $facets->[$f][$_] = $#$vertices for grep $facets->[$f][$_] == $v, 1..3; + $facets->[$f][$_] = $#$vertices for grep $facets->[$f][$_] == $v, -3..-1; } } } @@ -128,7 +128,7 @@ sub _read_ascii { while (my $_ = <$fh>) { if (!$facet) { /^\s*facet\s+normal\s+$point_re/ or next; - $facet = [ [$1, $2, $3] ]; + $facet = []; # ignore normal: [$1, $2, $3] } else { if (/^\s*endfacet/) { push @$facets, $facet; @@ -153,7 +153,7 @@ sub _read_binary { seek $fh, 80 + 4, 0; while (read $fh, my $_, 4*4*3+2) { my @v = unpack '(f<3)4'; - push @$facets, [ [@v[0..2]], [@v[3..5]], [@v[6..8]], [@v[9..11]] ]; + push @$facets, [ [@v[3..5]], [@v[6..8]], [@v[9..11]] ]; # ignore normal: [@v[0..2]] } } diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm index b95521274..3db73f8d3 100644 --- a/lib/Slic3r/TriangleMesh.pm +++ b/lib/Slic3r/TriangleMesh.pm @@ -5,7 +5,7 @@ use Slic3r::Geometry qw(X Y Z A B unscale same_point); # public has 'vertices' => (is => 'ro', required => 1); # id => [$x,$y,$z] -has 'facets' => (is => 'ro', required => 1); # id => [ $normal, $v1_id, $v2_id, $v3_id ] +has 'facets' => (is => 'ro', required => 1); # id => [ $v1_id, $v2_id, $v3_id ] # private has 'edges' => (is => 'ro', default => sub { [] }); # id => [ $v1_id, $v2_id ] @@ -36,15 +36,15 @@ sub BUILD { my %table = (); # edge_coordinates => edge_id for (my $facet_id = 0; $facet_id <= $#{$self->facets}; $facet_id++) { - my $facet = $self->facets->[$facet_id]; + my $facet = $self->facets->[$facet_id];##use Devel::Size qw(total_size); printf "total_size = %d\n", total_size($facet);exit; $self->facets_edges->[$facet_id] = []; # reorder vertices so that the first one is the one with lowest Z # this is needed to get all intersection lines in a consistent order # (external on the right of the line) { - my @z_order = sort { $self->vertices->[$facet->[$a]][Z] <=> $self->vertices->[$facet->[$b]][Z] } 1..3; - @$facet[1..3] = (@$facet[$z_order[0]..3], @$facet[1..($z_order[0]-1)]); + my @z_order = sort { $self->vertices->[$facet->[$a]][Z] <=> $self->vertices->[$facet->[$b]][Z] } -3..-1; + @$facet[-3..-1] = (@$facet[$z_order[0]..-1], @$facet[-3..($z_order[0]-1)]); } # ignore the normal if provided @@ -83,9 +83,9 @@ sub _facet_edges { my $facet = $self->facets->[$facet_id]; return ( - [ $facet->[1], $facet->[2] ], - [ $facet->[2], $facet->[3] ], - [ $facet->[3], $facet->[1] ], + [ $facet->[-3], $facet->[-2] ], + [ $facet->[-2], $facet->[-1] ], + [ $facet->[-1], $facet->[-3] ], ); } @@ -198,7 +198,7 @@ sub make_loops { # choice) # The "// ''" on the next line avoids uninitialized value errors mentioned in issue #357 but these # errors occur on fixed models so the root cause still needs to be found - if (@lines_starting_here == 2 && join('', sort map $_->[I_FACET_EDGE] // '', @lines_starting_here) eq FE_TOP.FE_BOTTOM) { + if (@lines_starting_here == 2 && join('', sort map $_->[I_FACET_EDGE] // '', @lines_starting_here) eq FE_TOP.FE_BOTTOM) { #/ my @to_remove = grep $_->[I_FACET_EDGE] == FE_TOP, @lines_starting_here; while (!grep defined $_->[I_B_ID] && $_->[I_B_ID] == $to_remove[-1]->[I_B_ID] && $_ ne $to_remove[-1], @lines) { push @to_remove, grep defined $_->[I_A_ID] && $_->[I_A_ID] == $to_remove[-1]->[I_B_ID], @lines; @@ -359,7 +359,7 @@ sub size { sub slice_facet { my $self = shift; my ($print_object, $facet_id) = @_; - my ($normal, @vertices) = @{$self->facets->[$facet_id]}; + my @vertices = @{$self->facets->[$facet_id]}[-3..-1]; Slic3r::debugf "\n==> FACET %d (%f,%f,%f - %f,%f,%f - %f,%f,%f):\n", $facet_id, map @{$self->vertices->[$_]}, @vertices if $Slic3r::debug; @@ -398,7 +398,7 @@ sub intersect_facet { my $self = shift; my ($facet_id, $z) = @_; - my @vertices_ids = @{$self->facets->[$facet_id]}[1..3]; + my @vertices_ids = @{$self->facets->[$facet_id]}[-3..-1]; my @edge_ids = @{$self->facets_edges->[$facet_id]}; my @edge_vertices_ids = $self->_facet_edges($facet_id); @@ -534,11 +534,11 @@ sub split_mesh { $self->facets->[$facet_id] = undef; } - my %vertices = map { $_ => 1 } map @$_[1,2,3], @facets; + my %vertices = map { $_ => 1 } map @$_[-3..-1], @facets; my @new_vertices = keys %vertices; my %new_vertices = map { $new_vertices[$_] => $_ } 0..$#new_vertices; foreach my $facet (@facets) { - $facet->[$_] = $new_vertices{$facet->[$_]} for 1,2,3; + $facet->[$_] = $new_vertices{$facet->[$_]} for -3..-1; } push @meshes, Slic3r::TriangleMesh->new( facets => \@facets,