Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2011-10-03 22:57:56 +0400
committerAlessandro Ranellucci <aar@cpan.org>2011-10-03 22:57:56 +0400
commit6444c3d7a960a72ca40273f483dfe5d9e2e66244 (patch)
tree10c856ed5accebe02477de713ccce63ac3eb35c3 /lib/Slic3r/STL.pm
parentef201a99cc7389a6616eab99ea32bbf700fde3f9 (diff)
Bugfix in dealing with very small STL facets
Diffstat (limited to 'lib/Slic3r/STL.pm')
-rw-r--r--lib/Slic3r/STL.pm25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Slic3r/STL.pm b/lib/Slic3r/STL.pm
index 2f9492f22..a2991ef30 100644
--- a/lib/Slic3r/STL.pm
+++ b/lib/Slic3r/STL.pm
@@ -2,7 +2,7 @@ package Slic3r::STL;
use Moo;
use CAD::Format::STL;
-use Math::Clipper qw(is_counter_clockwise);
+use Math::Clipper qw(integerize_coordinate_sets is_counter_clockwise);
use XXX;
use constant X => 0;
@@ -77,8 +77,11 @@ sub parse_file {
# transform vertex coordinates
my ($normal, @vertices) = @$facet;
foreach my $vertex (@vertices) {
- $vertex->[$_] = sprintf('%.0f', ($Slic3r::scale * $vertex->[$_] / $Slic3r::resolution) + $shift[$_])
+ $vertex->[$_] = ($Slic3r::scale * $vertex->[$_] / $Slic3r::resolution) + $shift[$_]
for X,Y,Z;
+
+ # round Z coordinates; XY will be rounded automatically with coercion
+ $vertex->[Z] = sprintf('%.0f', $vertex->[Z]);
}
foreach my $copy (@copies) {
@@ -121,14 +124,22 @@ sub _facet {
# the normal using the right-hand rule
# (this relies on the STL to be well-formed)
# recompute the normal using the right-hand rule
- my $clockwise = !is_counter_clockwise([@vertices]);
+ my $vertices_p = [@vertices];
+ integerize_coordinate_sets($vertices_p);
+ my $clockwise = !is_counter_clockwise($vertices_p);
# defensive programming and/or input check
- if (($normal->[Z] > 0 && $clockwise) || ($normal->[Z] < 0 && !$clockwise)) {
- YYY $normal;
- die sprintf "STL normal (%.0f) and right-hand rule computation (%s) differ!\n",
- $normal->[Z], $clockwise ? 'clockwise' : 'counter-clockwise';
+ if (abs($normal->[Z]) == 1) {
+ # while the vertices may belong to the same layer, it doesn't mean the facet
+ # was horizontal in the original model; so this check makes sense only
+ # if the original normal is exactly 1 or -1
+ if (($normal->[Z] > 0 && $clockwise) || ($normal->[Z] < 0 && !$clockwise)) {
+ YYY $normal;
+ die sprintf "STL normal (%.0f) and right-hand rule computation (%s) differ!\n",
+ $normal->[Z], $clockwise ? 'clockwise' : 'counter-clockwise';
+ }
}
+
if ($layer->id == 0 && !$clockwise) {
die "Right-hand rule gives bad result for facets on base layer!\n";
}