From bbfb9d77fadc63ca84d70b09aa1efa6d90889736 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Sat, 21 Oct 2023 12:20:30 +0800 Subject: [PATCH] More camera tweaks (#2473) * fix camera regressions * Handle multiple plates --- src/slic3r/GUI/GLCanvas3D.cpp | 31 +++++++++++++++++++++++++++---- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 44302be493..02309a8d93 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1508,12 +1508,19 @@ void GLCanvas3D::refresh_camera_scene_box() wxGetApp().plater()->get_camera().set_scene_box(scene_bounding_box()); } -BoundingBoxf3 GLCanvas3D::volumes_bounding_box() const +BoundingBoxf3 GLCanvas3D::volumes_bounding_box(bool current_plate_only) const { BoundingBoxf3 bb; - for (const GLVolume* volume : m_volumes.volumes) { - if (!m_apply_zoom_to_volumes_filter || ((volume != nullptr) && volume->zoom_to_volumes)) - bb.merge(volume->transformed_bounding_box()); + PartPlate *plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); + + for (const GLVolume *volume : m_volumes.volumes) { + if (!m_apply_zoom_to_volumes_filter || ((volume != nullptr) && volume->zoom_to_volumes)) { + const auto plate_bb = plate->get_bounding_box(); + const auto v_bb = volume->transformed_bounding_box(); + if (!plate_bb.overlap(v_bb)) + continue; + bb.merge(v_bb); + } } return bb; } @@ -4219,6 +4226,22 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } camera.rotate_on_sphere_with_target(rot.x(), rot.y(), rotate_limit, m_rotation_center); } else { + Vec3d rotate_target = Vec3d::Zero(); + if (m_canvas_type == ECanvasType::CanvasPreview) { + PartPlate *plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); + if (plate) + rotate_target = plate->get_bounding_box().center(); + } + else { + if (!m_selection.is_empty()) + rotate_target = m_selection.get_bounding_box().center(); + else + rotate_target = volumes_bounding_box(true).center(); + } + + if (!rotate_target.isZero()) + camera.rotate_on_sphere_with_target(rot.x(), rot.y(), rotate_limit, rotate_target); + else camera.rotate_on_sphere(rot.x(), rot.y(), rotate_limit); } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 303a2d04b4..e4e841f6d7 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -786,7 +786,7 @@ public: void refresh_camera_scene_box(); - BoundingBoxf3 volumes_bounding_box() const; + BoundingBoxf3 volumes_bounding_box(bool current_plate_only = false) const; BoundingBoxf3 scene_bounding_box() const; BoundingBoxf3 plate_scene_bounding_box(int plate_idx) const;