From 14103e6d6ef94222a31a81d575415e4b0a2e8c05 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Wed, 20 Nov 2024 10:53:31 +0800 Subject: [PATCH] NEW:add "extruder printable height render" jira: none Change-Id: I962fa4c72c7097899f4429cb8d71fe948910cd41 --- resources/shaders/gouraud.fs | 21 +++++++++++++-------- src/slic3r/GUI/3DScene.cpp | 21 ++++++++++++++++++--- src/slic3r/GUI/3DScene.hpp | 10 +++++----- src/slic3r/GUI/GLCanvas3D.cpp | 5 +++-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs index 3f12a6e92..1b2d7e1af 100644 --- a/resources/shaders/gouraud.fs +++ b/resources/shaders/gouraud.fs @@ -47,7 +47,7 @@ varying vec3 clipping_planes_dots; varying vec2 intensity; uniform PrintVolumeDetection print_volume; - +uniform vec3 extruder_printable_heights; varying vec4 model_pos; varying vec4 world_pos; varying float world_normal_z; @@ -75,11 +75,11 @@ void main() // if the fragment is outside the print volume -> use darker color vec3 pv_check_min = ZERO; vec3 pv_check_max = ZERO; - if (print_volume.type == 0) { - // rectangle - pv_check_min = world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, print_volume.z_data.x); - pv_check_max = world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, print_volume.z_data.y); - color = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; + pv_check_min = world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, print_volume.z_data.x); + pv_check_max = world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, print_volume.z_data.y); + bool is_out_print_limit =(any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))); + if (print_volume.type == 0) {// rectangle + color = is_out_print_limit ? mix(color, ZERO, 0.3333) : color; } else if (print_volume.type == 1) { // circle @@ -88,7 +88,12 @@ void main() pv_check_max = vec3(0.0, 0.0, world_pos.z - print_volume.z_data.y); color = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; } - + if(is_out_print_limit == false && extruder_printable_heights.x >= 1.0 ){ + pv_check_min = world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, extruder_printable_heights.y); + pv_check_max = world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, extruder_printable_heights.z); + bool is_out_printable_height = (all(greaterThan(pv_check_min, ZERO)) && all(lessThan(pv_check_max, ZERO))) ; + color = is_out_printable_height ? mix(color, ZERO, 0.7) : color; + } //BBS: add outline_color if (is_outline) gl_FragColor = uniform_color; @@ -98,7 +103,7 @@ void main() #endif else gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); - + // In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already // rendered object. To resolved z-fighting between previously rendered object and painted triangles, values // inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos. diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 2d0dd659d..182e2fc9c 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1558,7 +1558,8 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, std::function filter_func, bool with_outline, const std::array & body_color, - bool partly_inside_enable) const + bool partly_inside_enable, + std::vector * printable_heights) const { GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); if (to_render.empty()) @@ -1621,12 +1622,26 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, //shader->set_uniform("print_volume.type", static_cast(m_render_volume.type)); //shader->set_uniform("print_volume.xy_data", m_render_volume.data); //shader->set_uniform("print_volume.z_data", m_render_volume.zs); - + if (printable_heights) { + std::array extruder_printable_heights; + if ((*printable_heights).size() > 0) { + extruder_printable_heights[0] = 2.0f; + extruder_printable_heights[1] = (*printable_heights)[0]; + extruder_printable_heights[2] = (*printable_heights)[1]; + shader->set_uniform("extruder_printable_heights", extruder_printable_heights); + shader->set_uniform("print_volume.xy_data", m_print_volume.data); + } else { + extruder_printable_heights[0] = 0.0f; + shader->set_uniform("extruder_printable_heights", extruder_printable_heights); + } + } if (volume.first->partly_inside && partly_inside_enable) { //only partly inside volume need to be painted with boundary check shader->set_uniform("print_volume.type", static_cast(m_print_volume.type)); - shader->set_uniform("print_volume.xy_data", m_print_volume.data); shader->set_uniform("print_volume.z_data", m_print_volume.zs); + if (!printable_heights || (printable_heights && (*printable_heights).size() == 0)) { + shader->set_uniform("print_volume.xy_data", m_print_volume.data); + } } else { //use -1 ad a invalid type diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index cf51901ec..e7ac4e726 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -727,11 +727,11 @@ public: void render(ERenderType type, bool disable_cullface, const Transform3d & view_matrix, - std::function filter_func = std::function(), - bool with_outline = true, - const std::array& body_color = {1.0f, 1.0f, 1.0f, 1.0f}, - bool partly_inside_enable =true - ) const; + std::function filter_func = std::function(), + bool with_outline = true, + const std::array & body_color = {1.0f, 1.0f, 1.0f, 1.0f}, + bool partly_inside_enable = true, + std::vector * printable_heights = nullptr) const; // Finalize the initialization of the geometry & indices, // upload the geometry and indices to OpenGL VBO objects diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index a4f13984a..0f3aa9076 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -7304,6 +7304,7 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type, bool with std::array body_color = canvas_type == ECanvasType::CanvasAssembleView ? std::array({1.0f, 1.0f, 0.0f, 1.0f}) ://yellow std::array({1.0f, 1.0f, 1.0f, 1.0f});//white bool partly_inside_enable = canvas_type == ECanvasType::CanvasAssembleView ? false : true; + auto printable_height_option = GUI::wxGetApp().preset_bundle->printers.get_edited_preset().config.option("extruder_printable_height"); if (shader != nullptr) { shader->start_using(); @@ -7340,7 +7341,7 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type, bool with return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); } }, - with_outline, body_color, partly_inside_enable); + with_outline, body_color, partly_inside_enable, printable_height_option ? &printable_height_option->values : nullptr); } } else { @@ -7374,7 +7375,7 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type, bool with return true; } }, - with_outline, body_color, partly_inside_enable); + with_outline, body_color, partly_inside_enable, printable_height_option ? &printable_height_option->values : nullptr); if (m_canvas_type == CanvasAssembleView && m_gizmos.m_assemble_view_data->model_objects_clipper()->get_position() > 0) { const GLGizmosManager& gm = get_gizmos_manager(); shader->stop_using();