Bugfix: certain values of first layer height ratio caused slicing errors

This commit is contained in:
Alessandro Ranellucci 2012-03-11 16:02:17 +01:00
parent 64892c2203
commit 69942d2076
2 changed files with 7 additions and 8 deletions

View file

@ -47,7 +47,8 @@ sub new_from_mesh {
pop @{$print->layers} if !@{$print->layers->[-1]->surfaces} && !@{$print->layers->[-1]->lines}; pop @{$print->layers} if !@{$print->layers->[-1]->surfaces} && !@{$print->layers->[-1]->lines};
foreach my $layer (@{ $print->layers }) { foreach my $layer (@{ $print->layers }) {
Slic3r::debugf "Making surfaces for layer %d:\n", $layer->id; Slic3r::debugf "Making surfaces for layer %d (slice z = %f):\n",
$layer->id, unscale $layer->slice_z if $Slic3r::debug;
# layer currently has many lines representing intersections of # layer currently has many lines representing intersections of
# model facets with the layer plane. there may also be lines # model facets with the layer plane. there may also be lines

View file

@ -1,7 +1,7 @@
package Slic3r::TriangleMesh; package Slic3r::TriangleMesh;
use Moo; use Moo;
use Slic3r::Geometry qw(X Y Z A B epsilon same_point); use Slic3r::Geometry qw(X Y Z A B unscale same_point);
use XXX; use XXX;
# public # public
@ -349,17 +349,16 @@ sub slice_facet {
} }
Slic3r::debugf "z: min = %.0f, max = %.0f\n", $min_z, $max_z; Slic3r::debugf "z: min = %.0f, max = %.0f\n", $min_z, $max_z;
if (abs($max_z - $min_z) < epsilon) { if ($max_z == $min_z) {
Slic3r::debugf "Facet is horizontal; ignoring\n"; Slic3r::debugf "Facet is horizontal; ignoring\n";
return; return;
} }
# calculate the layer extents # calculate the layer extents
# (the -1 and +1 here are used as a quick and dirty replacement for some my $first_layer_height = $Slic3r::layer_height * $Slic3r::first_layer_height_ratio;
# complex calculation of the first layer height ratio logic) my $min_layer = int((unscale($min_z) - ($first_layer_height + $Slic3r::layer_height / 2)) / $Slic3r::layer_height) - 2;
my $min_layer = int($min_z * $Slic3r::resolution / $Slic3r::layer_height) - 1;
$min_layer = 0 if $min_layer < 0; $min_layer = 0 if $min_layer < 0;
my $max_layer = int($max_z * $Slic3r::resolution / $Slic3r::layer_height) + 1; my $max_layer = int((unscale($max_z) - ($first_layer_height + $Slic3r::layer_height / 2)) / $Slic3r::layer_height) + 2;
Slic3r::debugf "layers: min = %s, max = %s\n", $min_layer, $max_layer; Slic3r::debugf "layers: min = %s, max = %s\n", $min_layer, $max_layer;
for (my $layer_id = $min_layer; $layer_id <= $max_layer; $layer_id++) { for (my $layer_id = $min_layer; $layer_id <= $max_layer; $layer_id++) {
@ -384,7 +383,6 @@ sub intersect_facet {
my ($a, $b) = map $self->vertices->[$_], ($a_id, $b_id); my ($a, $b) = map $self->vertices->[$_], ($a_id, $b_id);
#printf "Az = %f, Bz = %f, z = %f\n", $a->[Z], $b->[Z], $z; #printf "Az = %f, Bz = %f, z = %f\n", $a->[Z], $b->[Z], $z;
#if (abs($a->[Z] - $b->[Z]) < epsilon && abs($a->[Z] - $z) < epsilon) {
if ($a->[Z] == $b->[Z] && $a->[Z] == $z) { if ($a->[Z] == $b->[Z] && $a->[Z] == $z) {
# edge is horizontal and belongs to the current layer # edge is horizontal and belongs to the current layer
my $edge_type = (grep $self->vertices->[$_][Z] < $z, @vertices_ids) ? 'top' : 'bottom'; my $edge_type = (grep $self->vertices->[$_][Z] < $z, @vertices_ids) ? 'top' : 'bottom';