From 507a8a6d36d1f4e71626b2f2be4cf001d025e648 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Tue, 18 Apr 2023 20:00:30 +0800 Subject: [PATCH] NEW: add overhang highlight area MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit overhang rgb=(200,0,0),remove supportType,do not save para after overhang operation preview Change-Id: I947bbd9db264f00f0609b3f02140060f9a2621fb (cherry picked from commit 796c4460fe998da206f9ca77973a20796fa1d3ca) --- resources/shaders/gouraud.fs | 22 +++++++++++++++------- resources/shaders/mm_gouraud.fs | 20 ++++++++++++++------ resources/shaders/mm_gouraud.vs | 4 ++-- src/slic3r/GUI/3DScene.cpp | 21 ++++++++++++++++++--- src/slic3r/GUI/3DScene.hpp | 12 ++++++++++-- src/slic3r/GUI/GLCanvas3D.hpp | 7 +++++++ src/slic3r/GUI/MainFrame.cpp | 6 ++++++ src/slic3r/GUI/Plater.cpp | 9 +++++++++ src/slic3r/GUI/Plater.hpp | 3 +++ 9 files changed, 84 insertions(+), 20 deletions(-) diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs index 3aa2b02942..3f12a6e92c 100644 --- a/resources/shaders/gouraud.fs +++ b/resources/shaders/gouraud.fs @@ -4,6 +4,8 @@ const vec3 ZERO = vec3(0.0, 0.0, 0.0); //BBS: add grey and orange //const vec3 GREY = vec3(0.9, 0.9, 0.9); const vec3 ORANGE = vec3(0.8, 0.4, 0.0); +const vec3 LightRed = vec3(0.78, 0.0, 0.0); +const vec3 LightBlue = vec3(0.73, 1.0, 1.0); const float EPSILON = 0.0001; struct PrintVolumeDetection @@ -58,13 +60,19 @@ void main() vec3 color = uniform_color.rgb; float alpha = uniform_color.a; - if (slope.actived && world_normal_z < slope.normal_z - EPSILON) { - //color = vec3(0.7, 0.7, 1.0); - color = ORANGE; - alpha = 1.0; + if (slope.actived) { + if(world_pos.z<0.1&&world_pos.z>-0.1) + { + color = LightBlue; + alpha = 0.8; + } + else if( world_normal_z < slope.normal_z - EPSILON) + { + color = color * 0.5 + LightRed * 0.5; + alpha = 0.8; + } } - - // if the fragment is outside the print volume -> use darker color + // 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) { @@ -85,7 +93,7 @@ void main() if (is_outline) gl_FragColor = uniform_color; #ifdef ENABLE_ENVIRONMENT_MAP - else if (use_environment_tex) + else if (use_environment_tex) gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha); #endif else diff --git a/resources/shaders/mm_gouraud.fs b/resources/shaders/mm_gouraud.fs index fa1b03f473..86dc503a4d 100644 --- a/resources/shaders/mm_gouraud.fs +++ b/resources/shaders/mm_gouraud.fs @@ -19,12 +19,13 @@ const float EPSILON = 0.0001; //BBS: add grey and orange //const vec3 GREY = vec3(0.9, 0.9, 0.9); const vec3 ORANGE = vec3(0.8, 0.4, 0.0); - +const vec3 LightRed = vec3(0.78, 0.0, 0.0); +const vec3 LightBlue = vec3(0.73, 1.0, 1.0); uniform vec4 uniform_color; varying vec3 clipping_planes_dots; varying vec4 model_pos; - +varying vec4 world_pos; uniform bool volume_mirrored; struct SlopeDetection @@ -48,10 +49,17 @@ void main() #endif vec3 transformed_normal = normalize(slope.volume_world_normal_matrix * triangle_normal); - if (slope.actived && transformed_normal.z < slope.normal_z - EPSILON) { - //color = vec3(0.7, 0.7, 1.0); - color = color * 0.5 + ORANGE * 0.5; - alpha = 1.0; + if (slope.actived) { + if(world_pos.z<0.1&&world_pos.z>-0.1) + { + color = LightBlue; + alpha = 1.0; + } + else if( transformed_normal.z < slope.normal_z - EPSILON) + { + color = color * 0.5 + LightRed * 0.5; + alpha = 1.0; + } } if (volume_mirrored) diff --git a/resources/shaders/mm_gouraud.vs b/resources/shaders/mm_gouraud.vs index 0c222cffbe..5929c88bec 100644 --- a/resources/shaders/mm_gouraud.vs +++ b/resources/shaders/mm_gouraud.vs @@ -10,7 +10,7 @@ uniform vec4 clipping_plane; varying vec3 clipping_planes_dots; varying vec4 model_pos; - +varying vec4 world_pos; struct SlopeDetection { bool actived; @@ -22,7 +22,7 @@ void main() { model_pos = gl_Vertex; // Point in homogenous coordinates. - vec4 world_pos = volume_world_matrix * gl_Vertex; + world_pos = volume_world_matrix * gl_Vertex; gl_Position = ftransform(); // Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded. diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 87a1ac4fde..39fd70d46d 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1236,8 +1236,17 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo return list; } +int GLVolumeCollection::get_selection_support_threshold_angle(bool &enable_support) const +{ + const DynamicPrintConfig& glb_cfg = GUI::wxGetApp().preset_bundle->prints.get_edited_preset().config; + enable_support = glb_cfg.opt_bool("enable_support"); + int support_threshold_angle = glb_cfg.opt_int("support_threshold_angle"); + return support_threshold_angle ; +} + //BBS: add outline drawing logic -void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func, bool with_outline) const +void GLVolumeCollection::render( + GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d &view_matrix, std::function filter_func, bool with_outline) const { GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); if (to_render.empty()) @@ -1305,10 +1314,16 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab //use -1 ad a invalid type shader->set_uniform("print_volume.type", -1); } + + bool enable_support; + int support_threshold_angle = get_selection_support_threshold_angle(enable_support); + + float normal_z = -::cos(Geometry::deg2rad((float) support_threshold_angle)); + shader->set_uniform("volume_world_matrix", volume.first->world_matrix()); - shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower); + shader->set_uniform("slope.actived", enable_support && m_slope.isGlobalActive && !volume.first->is_modifier && !volume.first->is_wipe_tower); shader->set_uniform("slope.volume_world_normal_matrix", static_cast(volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast())); - shader->set_uniform("slope.normal_z", m_slope.normal_z); + shader->set_uniform("slope.normal_z", normal_z); #if ENABLE_ENVIRONMENT_MAP unsigned int environment_texture_id = GUI::wxGetApp().plater()->get_environment_texture_id(); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index c61a4eb284..a1f050df2b 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -604,7 +604,8 @@ private: struct Slope { // toggle for slope rendering - bool active{ false }; + bool active{ false };//local active + bool isGlobalActive{false}; float normal_z; }; @@ -656,9 +657,14 @@ public: GLVolume* new_toolpath_volume(const std::array& rgba, size_t reserve_vbo_floats = 0); GLVolume* new_nontoolpath_volume(const std::array& rgba, size_t reserve_vbo_floats = 0); + int get_selection_support_threshold_angle(bool&) const; // Render the volumes by OpenGL. //BBS: add outline drawing logic - void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func = std::function(), bool with_outline = true) const; + void render(ERenderType type, + bool disable_cullface, + const Transform3d & view_matrix, + std::function filter_func = std::function(), + bool with_outline = true) const; // Finalize the initialization of the geometry & indices, // upload the geometry and indices to OpenGL VBO objects @@ -678,8 +684,10 @@ public: void set_z_range(float min_z, float max_z) { m_z_range[0] = min_z; m_z_range[1] = max_z; } void set_clipping_plane(const double* coeffs) { m_clipping_plane[0] = coeffs[0]; m_clipping_plane[1] = coeffs[1]; m_clipping_plane[2] = coeffs[2]; m_clipping_plane[3] = coeffs[3]; } + bool is_slope_GlobalActive() const { return m_slope.isGlobalActive; } bool is_slope_active() const { return m_slope.active; } void set_slope_active(bool active) { m_slope.active = active; } + void set_slope_GlobalActive(bool active) { m_slope.isGlobalActive = active; } float get_slope_normal_z() const { return m_slope.normal_z; } void set_slope_normal_z(float normal_z) { m_slope.normal_z = normal_z; } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 6e0f8df70b..2493627c1f 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -412,6 +412,7 @@ class GLCanvas3D void render(const std::vector& sorted_instances) const; }; + class Tooltip { std::string m_text; @@ -439,6 +440,8 @@ class GLCanvas3D bool is_enabled() const { return m_enabled; } void use(bool use) { m_volumes.set_slope_active(m_enabled ? use : false); } bool is_used() const { return m_volumes.is_slope_active(); } + void globalUse(bool use) { m_volumes.set_slope_GlobalActive(m_enabled ? use : false); } + bool is_GlobalUsed() const { return m_volumes.is_slope_GlobalActive(); } void set_normal_angle(float angle_in_deg) const { m_volumes.set_slope_normal_z(-::cos(Geometry::deg2rad(90.0f - angle_in_deg))); } @@ -591,6 +594,7 @@ private: Labels m_labels; Tooltip m_tooltip; bool m_tooltip_enabled{ true }; + Slope m_slope; OrientSettings m_orient_settings_fff, m_orient_settings_sla; @@ -994,6 +998,9 @@ public: bool are_labels_shown() const { return m_labels.is_shown(); } void show_labels(bool show) { m_labels.show(show); } + bool is_overhang_shown() const { return m_slope.is_GlobalUsed(); } + void show_overhang(bool show) { m_slope.globalUse(show); } + bool is_using_slope() const { return m_slope.is_used(); } void use_slope(bool use) { m_slope.use(use); } void set_slope_normal_angle(float angle_in_deg) { m_slope.set_normal_angle(angle_in_deg); } diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 65dcf7dd5e..952de14f9c 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2383,6 +2383,12 @@ void MainFrame::init_menubar_as_editor() [this](wxCommandEvent&) { m_plater->show_view3D_labels(!m_plater->are_view3D_labels_shown()); m_plater->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT)); }, this, [this]() { return m_plater->is_view3D_shown(); }, [this]() { return m_plater->are_view3D_labels_shown(); }, this); + append_menu_check_item(viewMenu, wxID_ANY, _L("Show &Overhang"), _L("Show object overhang highlight in 3D scene"), + [this](wxCommandEvent &) { + m_plater->show_view3D_overhang(!m_plater->is_view3D_overhang_shown()); + m_plater->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT)); + }, + this, [this]() { return m_plater->is_view3D_shown(); }, [this]() { return m_plater->is_view3D_overhang_shown(); }, this); /*viewMenu->AppendSeparator(); append_menu_check_item(viewMenu, wxID_ANY, _L("Show &Wireframe") + "\tCtrl+Shift+Enter", _L("Show wireframes in 3D scene"), [this](wxCommandEvent&) { m_plater->toggle_show_wireframe(); m_plater->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT)); }, this, diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 66cb495e09..f9d94338c0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1877,6 +1877,12 @@ struct Plater::priv bool are_view3D_labels_shown() const { return (current_panel == view3D) && view3D->get_canvas3d()->are_labels_shown(); } void show_view3D_labels(bool show) { if (current_panel == view3D) view3D->get_canvas3d()->show_labels(show); } + bool is_view3D_overhang_shown() const { return (current_panel == view3D) && view3D->get_canvas3d()->is_overhang_shown(); } + void show_view3D_overhang(bool show) + { + if (current_panel == view3D) view3D->get_canvas3d()->show_overhang(show); + } + bool is_sidebar_collapsed() const { return sidebar->is_collapsed(); } void collapse_sidebar(bool collapse); @@ -8884,6 +8890,9 @@ bool Plater::is_view3D_shown() const { return p->is_view3D_shown(); } bool Plater::are_view3D_labels_shown() const { return p->are_view3D_labels_shown(); } void Plater::show_view3D_labels(bool show) { p->show_view3D_labels(show); } +bool Plater::is_view3D_overhang_shown() const { return p->is_view3D_overhang_shown(); } +void Plater::show_view3D_overhang(bool show) { p->show_view3D_overhang(show); } + bool Plater::is_sidebar_collapsed() const { return p->is_sidebar_collapsed(); } void Plater::collapse_sidebar(bool show) { p->collapse_sidebar(show); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 8f662b2094..39f0b7341b 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -275,6 +275,9 @@ public: bool are_view3D_labels_shown() const; void show_view3D_labels(bool show); + bool is_view3D_overhang_shown() const; + void show_view3D_overhang(bool show); + bool is_sidebar_collapsed() const; void collapse_sidebar(bool show);