From 0d781b38e8c8eb79eaa14fda1da52774ff5f8462 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sun, 10 Apr 2022 17:48:30 -0600 Subject: [PATCH 1/5] add G92 E0 to prevent marlin error accumulation As of PrusaSlicer 2.4.1 we need to add G92 E0 to layer change to prevent error accumulation in marlin firmware and relative extrusion. tThis also eliminates the "error" notice in the slicer. https://github.com/prusa3d/PrusaSlicer/releases/tag/version_2.4.1-beta3 --- resources/profiles/BIBO.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/profiles/BIBO.ini b/resources/profiles/BIBO.ini index db8504c2e1..592ae2b075 100644 --- a/resources/profiles/BIBO.ini +++ b/resources/profiles/BIBO.ini @@ -5,7 +5,7 @@ name = BIBO # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the PrusaSlicer configuration to be downgraded. -config_version = 0.0.3 +config_version = 0.0.4 # Where to get the updates from? config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/BIBO/ @@ -694,7 +694,7 @@ cooling = 1 [printer:*common*] printer_technology = FFF bed_shape = -107x-93,107x-93,107x93,-107x93 -before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z]\n\n +before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z]\nG92 E0\n between_objects_gcode = deretract_speed = 0 # By setting this value to 0 deretract used the retract_speed extruder_colour = #FFFF00 @@ -850,4 +850,4 @@ bed_shape = -33x-93,0x-93,0x93,-33x93 #bed_texture = BIBO2.svg before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z]\nM104 S{temperature[0]} T0 ; set 1st nozzle heater to print temperature\n start_gcode = ;Start code PrusaSlicer BIBO 2 printers E2 only (i.e. T1)\nM420 S1 ; Turn on Ditto Printing\nG21 ; set units to metric\nG90 ; absolute positioning\nM107 ; start with the fan off\nM140 S{first_layer_bed_temperature[0] - 5} ; set bed temp\nM105 ; Report Temperatures\nM190 S{first_layer_bed_temperature[0]} ; wait for bed temp\nM104 S{first_layer_temperature[0]} T0 ; set 1st nozzle heater to ditto print temperature\nM104 S{first_layer_temperature[0]} T1 ; set 2nd nozzle heater to first layer temperature\nM105 ; Report Temperatures\nM109 S{first_layer_temperature[0]} T0 ; set 1st nozzle heater to ditto printing temperature\nM109 S{first_layer_temperature[0]} T1 ; Wait for 2nd nozzle heater to first layer temperature\nM105 ; Report Temperatures\nG28 X0 Y0 ; move X/Y to min endstops\nG28 Z0 ; move Z to min endstops\nG1 Z2 F400 ; move the print bed down 2mm\nT0 ; switch to tool position T0\nG90 ; absolute positioning\nG92 E0.0 ; zero the current extruder coordinate\nG28 ; Home all axis\nG1 Y0 F1200 E0 ; move Y to min endstop and reset extruder\nG92 E0.0 ; zero the current extruder coordinate\nT1 ; switch to tool position T1\nG92 E0.0 ; zero the current extruder coordinate\nM117 E2 nozzle wipe... ; Put Nozzle wipe message on screen, Attempt Nozzle Wipe (for ooze free startup)\nG1 X-15.0 Y-92.9 Z0.3 F2400.0 ; move to start-line position\nG1 X15.0 Y-92.9 Z0.3 F1000.0 E2 ; draw 1st line\nG1 X15.0 Y-92.6 Z0.3 F3000.0 ; move to side a little\nG1 X-15.0 Y-92.6 Z0.3 F1000.0 E4 ; draw 2nd line\nG1 X-15.0 Y-92.3 Z0.3 F3000.0 ; move to side a little\nG1 X15.0 Y-92.3 Z0.3 F1000.0 E6 ; draw 3rd line\nG1 X15.0 Y-92 Z0.3 F3000.0 ; move to side a little\nG1 X-15.0 Y-92 Z0.3 F1000.0 E8 ; draw 4th line\nG92 E0.0 ; reset extruder coordinate to zero before printing\nM117 BIBO Now Printing from E2... ; Put now printing message on screen -end_gcode = ;BIBO End GCode\nM107 ; turn fans off\nG91 ; Relative positioning\nG1 Z1 F100\nM140 S0 ; Disable heated bed\nM104 T0 S0 ; extruder T0 heater off\nM104 T1 S0 ; extruder T1 heater off\nG1 Z+0.5 X-20 Y-20 F300 ; move Z down then move print head a bit out of the way\nG28 X0 Y0 ; move X/Y to min endstops, so the head is out of the way\nG90 ; Absolute positioning\nG92 E0.0 ; Reset extruder position\nM84 ; Turn steppers off\nM420 S0 ; Turn off Ditto Printing function\nM117 BIBO Print complete ; Put print complete message on screen \ No newline at end of file +end_gcode = ;BIBO End GCode\nM107 ; turn fans off\nG91 ; Relative positioning\nG1 Z1 F100\nM140 S0 ; Disable heated bed\nM104 T0 S0 ; extruder T0 heater off\nM104 T1 S0 ; extruder T1 heater off\nG1 Z+0.5 X-20 Y-20 F300 ; move Z down then move print head a bit out of the way\nG28 X0 Y0 ; move X/Y to min endstops, so the head is out of the way\nG90 ; Absolute positioning\nG92 E0.0 ; Reset extruder position\nM84 ; Turn steppers off\nM420 S0 ; Turn off Ditto Printing function\nM117 BIBO Print complete ; Put print complete message on screen From 58039fc3613069c59621a8380d482672f81779c2 Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sun, 10 Apr 2022 18:09:01 -0600 Subject: [PATCH 2/5] Update version and minimum slic3r_version Added add G92 E0 to prevent error accumulation to before layer change. noting changes and version here. --- resources/profiles/BIBO.idx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/profiles/BIBO.idx b/resources/profiles/BIBO.idx index 08676caf37..cc11e54f1e 100644 --- a/resources/profiles/BIBO.idx +++ b/resources/profiles/BIBO.idx @@ -1,4 +1,5 @@ -min_slic3r_version = 2.3.0-beta2 +min_slic3r_version = 2.4.1-beta3 +0.0.4 Correct Marlin Error accumulation 0.0.3 Removed obsolete host keys. min_slic3r_version = 2.2.0-alpha3 0.0.2 General print quality improvements From 81df5446236a602b201078d251552d7e363030ab Mon Sep 17 00:00:00 2001 From: rtyr <36745189+rtyr@users.noreply.github.com> Date: Mon, 11 Apr 2022 07:12:56 +0200 Subject: [PATCH 3/5] Fixed min_version for 0.0.3 --- resources/profiles/BIBO.idx | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/profiles/BIBO.idx b/resources/profiles/BIBO.idx index cc11e54f1e..be01e1263f 100644 --- a/resources/profiles/BIBO.idx +++ b/resources/profiles/BIBO.idx @@ -1,5 +1,6 @@ min_slic3r_version = 2.4.1-beta3 0.0.4 Correct Marlin Error accumulation +min_slic3r_version = 2.3.0-beta2 0.0.3 Removed obsolete host keys. min_slic3r_version = 2.2.0-alpha3 0.0.2 General print quality improvements From 43d306260fb0421523d78bf0b7dbfb9c470b0edd Mon Sep 17 00:00:00 2001 From: rtyr <36745189+rtyr@users.noreply.github.com> Date: Mon, 11 Apr 2022 07:28:25 +0200 Subject: [PATCH 4/5] Added G92 E0 to ditto printer profiles. --- resources/profiles/BIBO.idx | 1 + resources/profiles/BIBO.ini | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/profiles/BIBO.idx b/resources/profiles/BIBO.idx index be01e1263f..85cc0fd1b0 100644 --- a/resources/profiles/BIBO.idx +++ b/resources/profiles/BIBO.idx @@ -1,4 +1,5 @@ min_slic3r_version = 2.4.1-beta3 +0.0.5 Correct Marlin Error accumulation for Ditto printer profiles. 0.0.4 Correct Marlin Error accumulation min_slic3r_version = 2.3.0-beta2 0.0.3 Removed obsolete host keys. diff --git a/resources/profiles/BIBO.ini b/resources/profiles/BIBO.ini index 592ae2b075..15e9c51a67 100644 --- a/resources/profiles/BIBO.ini +++ b/resources/profiles/BIBO.ini @@ -5,7 +5,7 @@ name = BIBO # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the PrusaSlicer configuration to be downgraded. -config_version = 0.0.4 +config_version = 0.0.5 # Where to get the updates from? config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/BIBO/ @@ -837,7 +837,7 @@ printer_notes = Do not remove the following keywords! These keywords are used in bed_shape = 0x-93,33x-93,33x93,0x93 #bed_model = BIBO2_bed.stl #bed_texture = BIBO2.svg -before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z]\nM104 S{temperature[0]} T1 ; set 2nd nozzle heater to print temperature\n +before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z]\nM104 S{temperature[0]} T1 ; set 2nd nozzle heater to print temperature\nG92 E0\n start_gcode = ;Start code PrusaSlicer BIBO 2 printers E1 only (i.e. T0)\nM420 S1 ; Turn on Ditto Printing\nG21 ; set units to metric\nG90 ; absolute positioning\nM107 ; start with the fan off\nM190 S{first_layer_bed_temperature[0] - 5} ; wait for bed temp\nM140 S{first_layer_bed_temperature[0]} ; continue bed heating to full temp while other things are happening\nM104 S{first_layer_temperature[0]} T0 ; set 1st nozzle heater to first layer temperature\nM104 S{first_layer_temperature[0]} T1 ; set 2nd nozzle heater to same first layer temperature\nM105 ; Report Temperatures\nM109 S{first_layer_temperature[0]} T0 ; wait for 1st nozzle heat to first layer temperature\nM109 S{first_layer_temperature[0]} T1 ; wait for 2nd nozzle heat to same first layer temperature\nM105 ; Report Temperatures\nG28 X0 Y0 ; move X/Y to min endstops\nG28 Z0 ; move Z to min endstops\nG1 Y0 F1200 E0 ; move Y to min endstop and extrude 0 filament\nT[initial_tool] ; switch to initial tool position\nG92 E0.0 ; reset extruder\nG28 ; Home all axis\nG1 Y0 F1200 E0 ; move Y to min endstop and reset extruder\nG92 E0.0 ; zero the current extruder coordinate\nM117 Cleaning... ; Put Cleaning message on screen, Attempt Nozzle Wipe (for ooze free startup)\nG1 X-15.0 Y-92.9 Z0.3 F2400.0 ; move to start-line position\nG1 X15.0 Y-92.9 Z0.3 F1000.0 E2 ; draw 1st line\nG1 X15.0 Y-92.6 Z0.3 F3000.0 ; move to side a little\nG1 X-15.0 Y-92.6 Z0.3 F1000.0 E4 ; draw 2nd line\nG1 X-15.0 Y-92.3 Z0.3 F3000.0 ; move to side a little\nG1 X15.0 Y-92.3 Z0.3 F1000.0 E6 ; draw 3rd line\nG1 X15.0 Y-92 Z0.3 F3000.0 ; move to side a little\nG1 X-15.0 Y-92 Z0.3 F1000.0 E8 ; draw 4th line\nG92 E0.0 ; reset extruder and zero the current extruder coordinate before printing\nM117 BIBO E1 now Printing... ; Put now printing message on screen end_gcode = ;BIBO End GCode\nM107 ; turn fans off\nG91 ; Relative positioning\nG1 Z1 F100\nM140 S0 ; Disable heated bed\nM104 T0 S0 ; extruder T0 heater off\nM104 T1 S0 ; extruder T1 heater off\nG1 Z+0.5 X-20 Y-20 F300 ; move Z down then move print head a bit out of the way\nG28 X0 Y0 ; move X/Y to min endstops, so the head is out of the way\nG90 ; Absolute positioning\nG92 E0.0 ; Reset extruder position\nM84 ; Turn steppers off\nM420 S0 ; Turn off Ditto Printing function\nM117 BIBO Print complete ; Put print complete message on screen @@ -848,6 +848,6 @@ printer_notes = Do not remove the following keywords! These keywords are used in bed_shape = -33x-93,0x-93,0x93,-33x93 #bed_model = BIBO2_bed.stl #bed_texture = BIBO2.svg -before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z]\nM104 S{temperature[0]} T0 ; set 1st nozzle heater to print temperature\n +before_layer_gcode = ;BEFORE_LAYER_CHANGE\n;[layer_z]\nM104 S{temperature[0]} T0 ; set 1st nozzle heater to print temperature\nG92 E0\n start_gcode = ;Start code PrusaSlicer BIBO 2 printers E2 only (i.e. T1)\nM420 S1 ; Turn on Ditto Printing\nG21 ; set units to metric\nG90 ; absolute positioning\nM107 ; start with the fan off\nM140 S{first_layer_bed_temperature[0] - 5} ; set bed temp\nM105 ; Report Temperatures\nM190 S{first_layer_bed_temperature[0]} ; wait for bed temp\nM104 S{first_layer_temperature[0]} T0 ; set 1st nozzle heater to ditto print temperature\nM104 S{first_layer_temperature[0]} T1 ; set 2nd nozzle heater to first layer temperature\nM105 ; Report Temperatures\nM109 S{first_layer_temperature[0]} T0 ; set 1st nozzle heater to ditto printing temperature\nM109 S{first_layer_temperature[0]} T1 ; Wait for 2nd nozzle heater to first layer temperature\nM105 ; Report Temperatures\nG28 X0 Y0 ; move X/Y to min endstops\nG28 Z0 ; move Z to min endstops\nG1 Z2 F400 ; move the print bed down 2mm\nT0 ; switch to tool position T0\nG90 ; absolute positioning\nG92 E0.0 ; zero the current extruder coordinate\nG28 ; Home all axis\nG1 Y0 F1200 E0 ; move Y to min endstop and reset extruder\nG92 E0.0 ; zero the current extruder coordinate\nT1 ; switch to tool position T1\nG92 E0.0 ; zero the current extruder coordinate\nM117 E2 nozzle wipe... ; Put Nozzle wipe message on screen, Attempt Nozzle Wipe (for ooze free startup)\nG1 X-15.0 Y-92.9 Z0.3 F2400.0 ; move to start-line position\nG1 X15.0 Y-92.9 Z0.3 F1000.0 E2 ; draw 1st line\nG1 X15.0 Y-92.6 Z0.3 F3000.0 ; move to side a little\nG1 X-15.0 Y-92.6 Z0.3 F1000.0 E4 ; draw 2nd line\nG1 X-15.0 Y-92.3 Z0.3 F3000.0 ; move to side a little\nG1 X15.0 Y-92.3 Z0.3 F1000.0 E6 ; draw 3rd line\nG1 X15.0 Y-92 Z0.3 F3000.0 ; move to side a little\nG1 X-15.0 Y-92 Z0.3 F1000.0 E8 ; draw 4th line\nG92 E0.0 ; reset extruder coordinate to zero before printing\nM117 BIBO Now Printing from E2... ; Put now printing message on screen end_gcode = ;BIBO End GCode\nM107 ; turn fans off\nG91 ; Relative positioning\nG1 Z1 F100\nM140 S0 ; Disable heated bed\nM104 T0 S0 ; extruder T0 heater off\nM104 T1 S0 ; extruder T1 heater off\nG1 Z+0.5 X-20 Y-20 F300 ; move Z down then move print head a bit out of the way\nG28 X0 Y0 ; move X/Y to min endstops, so the head is out of the way\nG90 ; Absolute positioning\nG92 E0.0 ; Reset extruder position\nM84 ; Turn steppers off\nM420 S0 ; Turn off Ditto Printing function\nM117 BIBO Print complete ; Put print complete message on screen From bea50dce7c4c5bfd0ccb7d7112e9d808dbe79520 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 11 Apr 2022 08:38:09 +0200 Subject: [PATCH 5/5] Fixed rendering of printbed while the camera is below it --- resources/shaders/110/printbed.fs | 4 +- resources/shaders/140/printbed.fs | 4 +- resources/shaders/printbed.fs | 4 +- src/slic3r/GUI/3DBed.cpp | 127 +++++++++++++++++++++++++----- src/slic3r/GUI/3DBed.hpp | 10 ++- src/slic3r/GUI/GLCanvas3D.cpp | 14 +++- 6 files changed, 137 insertions(+), 26 deletions(-) diff --git a/resources/shaders/110/printbed.fs b/resources/shaders/110/printbed.fs index 833dff08f4..e11b293e98 100644 --- a/resources/shaders/110/printbed.fs +++ b/resources/shaders/110/printbed.fs @@ -30,5 +30,7 @@ vec4 non_svg_color() void main() { - gl_FragColor = svg_source ? svg_color() : non_svg_color(); + vec4 color = svg_source ? svg_color() : non_svg_color(); + color.a = transparent_background ? color.a * 0.5 : color.a; + gl_FragColor = color; } \ No newline at end of file diff --git a/resources/shaders/140/printbed.fs b/resources/shaders/140/printbed.fs index 6d927a749c..5f1bce657d 100644 --- a/resources/shaders/140/printbed.fs +++ b/resources/shaders/140/printbed.fs @@ -31,5 +31,7 @@ vec4 non_svg_color() void main() { - frag_color = svg_source ? svg_color() : non_svg_color(); + vec4 color = svg_source ? svg_color() : non_svg_color(); + color.a = transparent_background ? color.a * 0.5 : color.a; + frag_color = color; } \ No newline at end of file diff --git a/resources/shaders/printbed.fs b/resources/shaders/printbed.fs index 833dff08f4..e11b293e98 100644 --- a/resources/shaders/printbed.fs +++ b/resources/shaders/printbed.fs @@ -30,5 +30,7 @@ vec4 non_svg_color() void main() { - gl_FragColor = svg_source ? svg_color() : non_svg_color(); + vec4 color = svg_source ? svg_color() : non_svg_color(); + color.a = transparent_background ? color.a * 0.5 : color.a; + gl_FragColor = color; } \ No newline at end of file diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 66fa8fb92a..1ce1af741d 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -233,6 +233,7 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c m_triangles.reset(); m_gridlines.reset(); + m_contourlines.reset(); #else ExPolygon poly{ Polygon::new_scale(bed_shape) }; @@ -241,6 +242,8 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c const BoundingBox& bed_bbox = poly.contour.bounding_box(); calc_gridlines(poly, bed_bbox); + calc_contourlines(poly); + m_polygon = offset(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5)).front(); this->release_VBOs(); @@ -474,6 +477,41 @@ void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox) } #endif // ENABLE_LEGACY_OPENGL_REMOVAL +#if ENABLE_LEGACY_OPENGL_REMOVAL +void Bed3D::init_contourlines() +{ + if (m_contourlines.is_initialized()) + return; + + if (m_contour.empty()) + return; + + const Lines contour_lines = to_lines(m_contour); + + GLModel::Geometry init_data; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; + init_data.reserve_vertices(2 * contour_lines.size()); + init_data.reserve_indices(2 * contour_lines.size()); + + for (const Slic3r::Line& l : contour_lines) { + init_data.add_vertex(Vec3f(unscale(l.a.x()), unscale(l.a.y()), GROUND_Z)); + init_data.add_vertex(Vec3f(unscale(l.b.x()), unscale(l.b.y()), GROUND_Z)); + const unsigned int vertices_counter = (unsigned int)init_data.vertices_count(); + init_data.add_line(vertices_counter - 2, vertices_counter - 1); + } + + m_contourlines.init_from(std::move(init_data)); + m_contourlines.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); +} +#else +void Bed3D::calc_contourlines(const ExPolygon& poly) +{ + const Lines contour_lines = to_lines(poly); + if (!m_contourlines.set_from_lines(contour_lines, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << "Unable to create bed contour lines\n"; +} +#endif // ENABLE_LEGACY_OPENGL_REMOVAL + // Try to match the print bed shape with the shape of an active profile. If such a match exists, // return the print bed model. std::tuple Bed3D::detect_type(const Pointfs& shape) @@ -512,6 +550,8 @@ void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, co if (show_texture) render_texture(bottom, canvas, view_matrix, projection_matrix); + else if (bottom) + render_contour(view_matrix, projection_matrix); } #else void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) @@ -521,6 +561,8 @@ void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) if (show_texture) render_texture(bottom, canvas); + else if (bottom) + render_contour(); } #endif // ENABLE_GL_SHADERS_ATTRIBUTES @@ -533,9 +575,9 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) if (m_texture_filename.empty()) { m_texture.reset(); #if ENABLE_GL_SHADERS_ATTRIBUTES - render_default(bottom, false, view_matrix, projection_matrix); + render_default(bottom, false, true, view_matrix, projection_matrix); #else - render_default(bottom, false); + render_default(bottom, false, true); #endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -550,9 +592,9 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // generate a temporary lower resolution texture to show while no main texture levels have been compressed if (!m_temp_texture.load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { #if ENABLE_GL_SHADERS_ATTRIBUTES - render_default(bottom, false, view_matrix, projection_matrix); + render_default(bottom, false, true, view_matrix, projection_matrix); #else - render_default(bottom, false); + render_default(bottom, false, true); #endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -562,9 +604,9 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) { #if ENABLE_GL_SHADERS_ATTRIBUTES - render_default(bottom, false, view_matrix, projection_matrix); + render_default(bottom, false, true, view_matrix, projection_matrix); #else - render_default(bottom, false); + render_default(bottom, false, true); #endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -574,9 +616,9 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) { if (!m_temp_texture.load_from_file(m_texture_filename, false, GLTexture::None, false)) { #if ENABLE_GL_SHADERS_ATTRIBUTES - render_default(bottom, false, view_matrix, projection_matrix); + render_default(bottom, false, true, view_matrix, projection_matrix); #else - render_default(bottom, false); + render_default(bottom, false, true); #endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -586,18 +628,18 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) { #if ENABLE_GL_SHADERS_ATTRIBUTES - render_default(bottom, false, view_matrix, projection_matrix); + render_default(bottom, false, true, view_matrix, projection_matrix); #else - render_default(bottom, false); + render_default(bottom, false, true); #endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } } else { #if ENABLE_GL_SHADERS_ATTRIBUTES - render_default(bottom, false, view_matrix, projection_matrix); + render_default(bottom, false, true, view_matrix, projection_matrix); #else - render_default(bottom, false); + render_default(bottom, false, true); #endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -770,9 +812,9 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo { if (m_texture_filename.empty() && m_model_filename.empty()) { #if ENABLE_GL_SHADERS_ATTRIBUTES - render_default(bottom, picking, view_matrix, projection_matrix); + render_default(bottom, picking, show_texture, view_matrix, projection_matrix); #else - render_default(bottom, picking); + render_default(bottom, picking, show_texture); #endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -787,15 +829,19 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo if (show_texture) #if ENABLE_GL_SHADERS_ATTRIBUTES render_texture(bottom, canvas, view_matrix, projection_matrix); + else if (bottom) + render_contour(view_matrix, projection_matrix); #else render_texture(bottom, canvas); + else if (bottom) + render_contour(); #endif // ENABLE_GL_SHADERS_ATTRIBUTES } #if ENABLE_GL_SHADERS_ATTRIBUTES -void Bed3D::render_default(bool bottom, bool picking, const Transform3d& view_matrix, const Transform3d& projection_matrix) +void Bed3D::render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix) #else -void Bed3D::render_default(bool bottom, bool picking) +void Bed3D::render_default(bool bottom, bool picking, bool show_texture) #endif // ENABLE_GL_SHADERS_ATTRIBUTES { m_texture.reset(); @@ -827,12 +873,14 @@ void Bed3D::render_default(bool bottom, bool picking) glsafe(::glDepthMask(GL_TRUE)); } - if (!picking) { + if (!picking && show_texture) { // draw grid glsafe(::glLineWidth(1.5f * m_scale_factor)); m_gridlines.set_color(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR : DEFAULT_TRANSPARENT_GRID_COLOR); m_gridlines.render(); } + else if (!show_texture) + render_contour(view_matrix, projection_matrix); glsafe(::glDisable(GL_BLEND)); @@ -859,13 +907,15 @@ void Bed3D::render_default(bool bottom, bool picking) glsafe(::glDepthMask(GL_TRUE)); } - if (!picking) { + if (!picking && show_texture) { // draw grid glsafe(::glLineWidth(1.5f * m_scale_factor)); glsafe(::glColor4fv(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR.data() : DEFAULT_TRANSPARENT_GRID_COLOR.data())); - glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); + glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count())); } + else if (!show_texture) + render_contour(); glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); @@ -874,6 +924,45 @@ void Bed3D::render_default(bool bottom, bool picking) #endif // ENABLE_LEGACY_OPENGL_REMOVAL } +#if ENABLE_LEGACY_OPENGL_REMOVAL +void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix) +{ + init_contourlines(); + + GLShaderProgram* shader = wxGetApp().get_shader("flat"); + if (shader != nullptr) { + shader->start_using(); + +#if ENABLE_GL_SHADERS_ATTRIBUTES + shader->set_uniform("view_model_matrix", view_matrix); + shader->set_uniform("projection_matrix", projection_matrix); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES + + glsafe(::glEnable(GL_DEPTH_TEST)); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + + // draw contour + glsafe(::glLineWidth(1.5f * m_scale_factor)); + m_contourlines.render(); + + glsafe(::glDisable(GL_BLEND)); + + shader->stop_using(); + } +} +#else +void Bed3D::render_contour() +{ + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glLineWidth(1.5f * m_scale_factor)); + glsafe(::glColor4f(1.0f, 1.0f, 1.0f, 0.5f)); + glsafe(::glVertexPointer(3, GL_FLOAT, m_contourlines.get_vertex_data_size(), (GLvoid*)m_contourlines.get_vertices_data())); + glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_contourlines.get_vertices_count())); + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); +} +#endif // ENABLE_LEGACY_OPENGL_REMOVAL + #if !ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::release_VBOs() { diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index 7c334cb939..708d186a41 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -93,9 +93,11 @@ private: #if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_triangles; GLModel m_gridlines; + GLModel m_contourlines; #else GeometryBuffer m_triangles; GeometryBuffer m_gridlines; + GeometryBuffer m_contourlines; #endif // ENABLE_LEGACY_OPENGL_REMOVAL GLTexture m_texture; // temporary texture shown until the main texture has still no levels compressed @@ -153,9 +155,11 @@ private: #if ENABLE_LEGACY_OPENGL_REMOVAL void init_triangles(); void init_gridlines(); + void init_contourlines(); #else void calc_triangles(const ExPolygon& poly); void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); + void calc_contourlines(const ExPolygon& poly); #endif // ENABLE_LEGACY_OPENGL_REMOVAL static std::tuple detect_type(const Pointfs& shape); #if ENABLE_GL_SHADERS_ATTRIBUTES @@ -171,13 +175,15 @@ private: void render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking); - void render_default(bool bottom, bool picking, const Transform3d& view_matrix, const Transform3d& projection_matrix); + void render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix); + void render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix); #else void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); void render_texture(bool bottom, GLCanvas3D& canvas); void render_model(); void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking); - void render_default(bool bottom, bool picking); + void render_default(bool bottom, bool picking, bool show_texture); + void render_contour(); #endif // ENABLE_GL_SHADERS_ATTRIBUTES #if !ENABLE_LEGACY_OPENGL_REMOVAL diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f34c7c1244..14dfe32205 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1692,6 +1692,9 @@ void GLCanvas3D::render() #if ENABLE_RENDER_PICKING_PASS if (!m_picking_enabled || !m_show_picking_texture) { #endif // ENABLE_RENDER_PICKING_PASS + + const bool is_looking_downward = camera.is_looking_downward(); + // draw scene glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); _render_background(); @@ -1701,10 +1704,11 @@ void GLCanvas3D::render() _render_gcode(); _render_sla_slices(); _render_selection(); + if (is_looking_downward) #if ENABLE_GL_SHADERS_ATTRIBUTES - _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward(), true); + _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), false, true); #else - _render_bed(!camera.is_looking_downward(), true); + _render_bed(false, true); #endif // ENABLE_GL_SHADERS_ATTRIBUTES _render_objects(GLVolumeCollection::ERenderType::Transparent); @@ -1727,6 +1731,12 @@ void GLCanvas3D::render() // could be invalidated by the following gizmo render methods _render_selection_sidebar_hints(); _render_current_gizmo(); + if (!is_looking_downward) +#if ENABLE_GL_SHADERS_ATTRIBUTES + _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), true, true); +#else + _render_bed(true, true); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES #if ENABLE_RENDER_PICKING_PASS } #endif // ENABLE_RENDER_PICKING_PASS