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