From 1f3f109263af5a7dccde6371bc7e75da335ea79f Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 20 Mar 2018 09:31:42 +0100 Subject: [PATCH 1/4] Out of bed detection - Fixed false detection due to float precision --- xs/src/libslic3r/Model.cpp | 4 ++++ xs/src/slic3r/GUI/3DScene.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 6f1ce1ce5..ad2ce54cd 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -450,6 +450,8 @@ bool Model::fits_print_volume(const DynamicPrintConfig* config) const BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config->opt_float("max_print_height"))); + // Allow the objects to protrude below the print bed + print_volume.min.z = -1e10; return print_volume.contains(transformed_bounding_box()); } @@ -459,6 +461,8 @@ bool Model::fits_print_volume(const FullPrintConfig &config) const return true; BoundingBox bed_box_2D = get_extents(Polygon::new_scale(config.bed_shape.values)); BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config.max_print_height)); + // Allow the objects to protrude below the print bed + print_volume.min.z = -1e10; return print_volume.contains(transformed_bounding_box()); } diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index f6be96a78..cb5d580c1 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -627,6 +627,8 @@ void GLVolumeCollection::update_outside_state(const DynamicPrintConfig* config, BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config->opt_float("max_print_height"))); + // Allow the objects to protrude below the print bed + print_volume.min.z = -1e10; for (GLVolume* volume : this->volumes) { From 6298a2849484def97e5af36943647c84497812ab Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 20 Mar 2018 11:59:33 +0100 Subject: [PATCH 2/4] Disabled back face culling to show broken geometry --- lib/Slic3r/GUI/3DScene.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 75a154281..b4f1849e8 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -1316,12 +1316,18 @@ sub Render { $self->mark_volumes_for_layer_height; $self->volumes->set_print_box($self->bed_bounding_box->x_min, $self->bed_bounding_box->y_min, 0.0, $self->bed_bounding_box->x_max, $self->bed_bounding_box->y_max, $self->{config}->get('max_print_height')); $self->volumes->update_outside_state($self->{config}, 0); + # do not cull backfaces to show broken geometry, if any + glDisable(GL_CULL_FACE); } $self->{plain_shader}->enable if $self->{plain_shader}; $self->volumes->render_VBOs; $self->{plain_shader}->disable; + glEnable(GL_CULL_FACE) if ($self->enable_picking); } else { + # do not cull backfaces to show broken geometry, if any + glDisable(GL_CULL_FACE) if ($self->enable_picking); $self->volumes->render_legacy; + glEnable(GL_CULL_FACE) if ($self->enable_picking); } # draw cutting plane @@ -1358,6 +1364,9 @@ sub draw_volumes { # $fakecolor is a boolean indicating, that the objects shall be rendered in a color coding the object index for picking. my ($self, $fakecolor) = @_; + # do not cull backfaces to show broken geometry, if any + glDisable(GL_CULL_FACE); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1385,6 +1394,8 @@ sub draw_volumes { } glDisableClientState(GL_NORMAL_ARRAY); glDisable(GL_BLEND); + + glEnable(GL_CULL_FACE); if (defined $self->cutting_plane_z) { glLineWidth(2); From f99aaa1191245a61ded3e8c70ffdd6548612a8dd Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 20 Mar 2018 13:01:50 +0100 Subject: [PATCH 3/4] Out of bed detection - New colors for out of bed state --- lib/Slic3r/GUI/3DScene.pm | 11 +++++------ xs/src/slic3r/GUI/3DScene.cpp | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index b4f1849e8..420ea493a 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -1823,6 +1823,7 @@ sub _fragment_shader_Gouraud { return <<'FRAGMENT'; #version 110 +const vec4 OUTSIDE_COLOR = vec4(0.24, 0.42, 0.62, 1.0); const vec3 ZERO = vec3(0.0, 0.0, 0.0); // x = tainted, y = specular; @@ -1835,13 +1836,11 @@ uniform vec4 uniform_color; void main() { - gl_FragColor = vec4(intensity.y, intensity.y, intensity.y, 0.0) + uniform_color * intensity.x; + // if the fragment is outside the print volume use predefined color + vec4 color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? OUTSIDE_COLOR : uniform_color; - // if the fragment is outside the print volume darken it and set it as transparent - if (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) - gl_FragColor = vec4(mix(gl_FragColor.xyz, ZERO, 0.5), 0.5 * uniform_color.a); - else - gl_FragColor.a = uniform_color.a; + gl_FragColor = vec4(intensity.y, intensity.y, intensity.y, 0.0) + color * intensity.x; + gl_FragColor.a = color.a; } FRAGMENT diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index cb5d580c1..0bd7008d2 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -194,8 +194,8 @@ void GLIndexedVertexArray::render( const float GLVolume::SELECTED_COLOR[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; const float GLVolume::HOVER_COLOR[4] = { 0.4f, 0.9f, 0.1f, 1.0f }; -const float GLVolume::OUTSIDE_COLOR[4] = { 0.75f, 0.0f, 0.75f, 1.0f }; -const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 1.0f, 0.0f, 1.0f, 1.0f }; +const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f }; +const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f }; void GLVolume::set_render_color(float r, float g, float b, float a) { From ebb2d457610d1dc67f17e1911198738a1bb756c7 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 21 Mar 2018 15:21:03 +0100 Subject: [PATCH 4/4] Out of bed detection - Disabled GUI buttons when object outside bed --- lib/Slic3r/GUI/Plater.pm | 11 +++++++++++ lib/Slic3r/GUI/Plater/3D.pm | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index d3513897f..c63f8b8b7 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -98,6 +98,16 @@ sub new { $self->update; }; + # callback to enable/disable action buttons + my $enable_action_buttons = sub { + my ($enable) = @_; + $self->{btn_export_gcode}->Enable($enable); + $self->{btn_reslice}->Enable($enable); + $self->{btn_print}->Enable($enable); + $self->{btn_send_gcode}->Enable($enable); + $self->{btn_export_stl}->Enable($enable); + }; + # Initialize 3D plater if ($Slic3r::GUI::have_OpenGL) { $self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{print}, $self->{config}); @@ -113,6 +123,7 @@ sub new { $self->{canvas3D}->set_on_decrease_objects(sub { $self->decrease() }); $self->{canvas3D}->set_on_remove_object(sub { $self->remove() }); $self->{canvas3D}->set_on_instances_moved($on_instances_moved); + $self->{canvas3D}->set_on_enable_action_buttons($enable_action_buttons); $self->{canvas3D}->use_plain_shader(1); $self->{canvas3D}->set_on_wipe_tower_moved(sub { my ($new_pos_3f) = @_; diff --git a/lib/Slic3r/GUI/Plater/3D.pm b/lib/Slic3r/GUI/Plater/3D.pm index 37e1321ae..09cc02930 100644 --- a/lib/Slic3r/GUI/Plater/3D.pm +++ b/lib/Slic3r/GUI/Plater/3D.pm @@ -12,7 +12,7 @@ use Wx::Locale gettext => 'L'; __PACKAGE__->mk_accessors(qw( on_arrange on_rotate_object_left on_rotate_object_right on_scale_object_uniformly - on_remove_object on_increase_objects on_decrease_objects)); + on_remove_object on_increase_objects on_decrease_objects on_enable_action_buttons)); sub new { my $class = shift; @@ -176,6 +176,11 @@ sub set_on_model_update { $self->on_model_update($cb); } +sub set_on_enable_action_buttons { + my ($self, $cb) = @_; + $self->on_enable_action_buttons($cb); +} + sub reload_scene { my ($self, $force) = @_; @@ -217,10 +222,12 @@ sub reload_scene { if (!$self->{model}->fits_print_volume($self->{config})) { $self->set_warning_enabled(1); Slic3r::GUI::_3DScene::generate_warning_texture(L("Detected object outside print volume")); + $self->on_enable_action_buttons->(0) if ($self->on_enable_action_buttons); } else { $self->set_warning_enabled(0); $self->volumes->update_outside_state($self->{config}, 1); Slic3r::GUI::_3DScene::reset_warning_texture(); + $self->on_enable_action_buttons->(1) if ($self->on_enable_action_buttons); } } }