From 61c8940cf6007560d77843072d28846d3f583c17 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Aug 2023 09:29:08 +0200 Subject: [PATCH] Fixed camera frustum for preview to take in account for shells --- src/slic3r/GUI/GCodeViewer.cpp | 17 +++++++++++------ src/slic3r/GUI/GCodeViewer.hpp | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index a475ce880d..12567c5c74 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -892,8 +892,8 @@ void GCodeViewer::reset() buffer.reset(); } - m_paths_bounding_box = BoundingBoxf3(); - m_max_bounding_box = BoundingBoxf3(); + m_paths_bounding_box.reset(); + m_max_bounding_box.reset(); m_max_print_height = 0.0f; m_tool_colors = std::vector(); m_extruders_count = 0; @@ -1541,6 +1541,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) m_statistics.results_time = gcode_result.time; #endif // ENABLE_GCODE_VIEWER_STATISTICS + m_max_bounding_box.reset(); + m_moves_count = gcode_result.moves.size(); if (m_moves_count == 0) return; @@ -1566,10 +1568,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) } } - // set approximate max bounding box (take in account also the tool marker) - m_max_bounding_box = m_paths_bounding_box; - m_max_bounding_box.merge(m_paths_bounding_box.max + m_sequential_view.marker.get_bounding_box().size().z() * Vec3d::UnitZ()); - if (wxGetApp().is_editor()) m_contained_in_bed = wxGetApp().plater()->build_volume().all_paths_inside(gcode_result, m_paths_bounding_box); @@ -2289,6 +2287,13 @@ void GCodeViewer::load_shells(const Print& print) volume->force_native_color = true; volume->set_render_color(true); } + + m_shells_bounding_box.reset(); + for (const GLVolume* volume : m_shells.volumes.volumes) { + m_shells_bounding_box.merge(volume->transformed_bounding_box()); + } + + m_max_bounding_box.reset(); } void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 7c387d59c4..50c27e5fa4 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -752,7 +752,9 @@ private: std::vector m_buffers{ static_cast(EMoveType::Extrude) }; // bounding box of toolpaths BoundingBoxf3 m_paths_bounding_box; - // bounding box of toolpaths + marker tools + // bounding box of shells + BoundingBoxf3 m_shells_bounding_box; + // bounding box of toolpaths + marker tools + shells BoundingBoxf3 m_max_bounding_box; float m_max_print_height{ 0.0f }; std::vector m_tool_colors; @@ -811,7 +813,16 @@ public: bool can_export_toolpaths() const; const BoundingBoxf3& get_paths_bounding_box() const { return m_paths_bounding_box; } - const BoundingBoxf3& get_max_bounding_box() const { return m_max_bounding_box; } + const BoundingBoxf3& get_shells_bounding_box() const { return m_shells_bounding_box; } + const BoundingBoxf3& get_max_bounding_box() const { + BoundingBoxf3& max_bounding_box = const_cast(m_max_bounding_box); + if (!max_bounding_box.defined) { + max_bounding_box = m_shells_bounding_box; + max_bounding_box.merge(m_paths_bounding_box); + max_bounding_box.merge(m_paths_bounding_box.max + m_sequential_view.marker.get_bounding_box().size().z() * Vec3d::UnitZ()); + } + return m_max_bounding_box; + } const std::vector& get_layers_zs() const { return m_layers.get_zs(); } const SequentialView& get_sequential_view() const { return m_sequential_view; }