Browse Source

Fixed camera frustum for preview to take in account for shells

enricoturri1966 1 year ago
parent
commit
61c8940cf6
2 changed files with 24 additions and 8 deletions
  1. 11 6
      src/slic3r/GUI/GCodeViewer.cpp
  2. 13 2
      src/slic3r/GUI/GCodeViewer.hpp

+ 11 - 6
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<ColorRGBA>();
     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

+ 13 - 2
src/slic3r/GUI/GCodeViewer.hpp

@@ -752,7 +752,9 @@ private:
     std::vector<TBuffer> m_buffers{ static_cast<size_t>(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<ColorRGBA> 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<BoundingBoxf3&>(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<double>& get_layers_zs() const { return m_layers.get_zs(); }
 
     const SequentialView& get_sequential_view() const { return m_sequential_view; }