Bugfix in dealing with very small STL facets

This commit is contained in:
Alessandro Ranellucci 2011-10-03 20:57:56 +02:00
parent ef201a99cc
commit 6444c3d7a9

View File

@ -2,7 +2,7 @@ package Slic3r::STL;
use Moo; use Moo;
use CAD::Format::STL; use CAD::Format::STL;
use Math::Clipper qw(is_counter_clockwise); use Math::Clipper qw(integerize_coordinate_sets is_counter_clockwise);
use XXX; use XXX;
use constant X => 0; use constant X => 0;
@ -77,8 +77,11 @@ sub parse_file {
# transform vertex coordinates # transform vertex coordinates
my ($normal, @vertices) = @$facet; my ($normal, @vertices) = @$facet;
foreach my $vertex (@vertices) { foreach my $vertex (@vertices) {
$vertex->[$_] = sprintf('%.0f', ($Slic3r::scale * $vertex->[$_] / $Slic3r::resolution) + $shift[$_]) $vertex->[$_] = ($Slic3r::scale * $vertex->[$_] / $Slic3r::resolution) + $shift[$_]
for X,Y,Z; for X,Y,Z;
# round Z coordinates; XY will be rounded automatically with coercion
$vertex->[Z] = sprintf('%.0f', $vertex->[Z]);
} }
foreach my $copy (@copies) { foreach my $copy (@copies) {
@ -121,14 +124,22 @@ sub _facet {
# the normal using the right-hand rule # the normal using the right-hand rule
# (this relies on the STL to be well-formed) # (this relies on the STL to be well-formed)
# recompute the normal using the right-hand rule # 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 # defensive programming and/or input check
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)) { if (($normal->[Z] > 0 && $clockwise) || ($normal->[Z] < 0 && !$clockwise)) {
YYY $normal; YYY $normal;
die sprintf "STL normal (%.0f) and right-hand rule computation (%s) differ!\n", die sprintf "STL normal (%.0f) and right-hand rule computation (%s) differ!\n",
$normal->[Z], $clockwise ? 'clockwise' : 'counter-clockwise'; $normal->[Z], $clockwise ? 'clockwise' : 'counter-clockwise';
} }
}
if ($layer->id == 0 && !$clockwise) { if ($layer->id == 0 && !$clockwise) {
die "Right-hand rule gives bad result for facets on base layer!\n"; die "Right-hand rule gives bad result for facets on base layer!\n";
} }