More camera tweaks (#2473)

* fix camera regressions

* Handle multiple plates
This commit is contained in:
SoftFever 2023-10-21 12:20:30 +08:00 committed by GitHub
parent 0037a5cc2d
commit bbfb9d77fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View file

@ -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;
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))
bb.merge(volume->transformed_bounding_box());
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);
}
}

View file

@ -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;