2011-11-27 10:40:03 +00:00
|
|
|
|
package Slic3r::TriangleMesh;
|
2013-09-09 22:40:46 +00:00
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
2011-11-27 10:40:03 +00:00
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
|
use List::Util qw(first);
|
|
|
|
|
use Slic3r::Geometry qw(X Y);
|
2013-08-05 18:21:08 +00:00
|
|
|
|
use Slic3r::Geometry::Clipper qw(union_ex offset);
|
2011-11-27 10:40:03 +00:00
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
|
sub needed_repair {
|
2012-02-18 19:36:14 +00:00
|
|
|
|
my $self = shift;
|
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
|
my $stats = $self->stats;
|
|
|
|
|
return (first { $stats->{$_} > 0 }
|
|
|
|
|
qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)) ? 1 : 0;
|
2013-05-17 12:14:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub center {
|
|
|
|
|
my $self = shift;
|
2013-06-16 10:21:25 +00:00
|
|
|
|
return $self->bounding_box->center;
|
2013-05-17 12:14:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 07:49:28 +00:00
|
|
|
|
sub facets_count {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
return $self->stats->{number_of_facets};
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 21:16:02 +00:00
|
|
|
|
sub bounding_box {
|
|
|
|
|
my $self = shift;
|
2013-09-11 09:55:08 +00:00
|
|
|
|
return Slic3r::Geometry::BoundingBox->new_from_bb($self->bb3);
|
2013-06-07 21:16:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 18:21:08 +00:00
|
|
|
|
# this will return *scaled* expolygons, so it is expected to be run
|
|
|
|
|
# on unscaled meshes
|
2012-11-23 23:13:04 +00:00
|
|
|
|
sub horizontal_projection {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
|
my ($facets, $vertices) = ($self->facets, $self->vertices);
|
|
|
|
|
|
2012-11-23 23:13:04 +00:00
|
|
|
|
my @f = ();
|
2013-09-09 22:40:46 +00:00
|
|
|
|
foreach my $facet (@$facets) {
|
2013-08-05 18:21:08 +00:00
|
|
|
|
push @f, Slic3r::Polygon->new(
|
2013-09-09 22:40:46 +00:00
|
|
|
|
map [ map $_ / &Slic3r::SCALING_FACTOR, @{$vertices->[$_]}[X,Y] ], @$facet
|
2013-08-05 18:21:08 +00:00
|
|
|
|
);
|
2012-11-23 23:13:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-17 14:39:51 +00:00
|
|
|
|
$_->make_counter_clockwise for @f; # do this after scaling, as winding order might change while doing that
|
2013-08-09 14:34:55 +00:00
|
|
|
|
|
|
|
|
|
# the offset factor was tuned using groovemount.stl
|
2013-08-26 15:58:37 +00:00
|
|
|
|
return union_ex(offset(\@f, Slic3r::Geometry::scale 0.01), 1);
|
2012-11-23 23:13:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-27 10:40:03 +00:00
|
|
|
|
1;
|