diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index dfb59f119..20fda22d3 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -367,27 +367,10 @@ std::pair Camera::calc_tight_frustrum_zs_around(const BoundingBo while (true) { - ret = std::make_pair(DBL_MAX, -DBL_MAX); - - // box vertices in world space - std::vector vertices; - vertices.reserve(8); - vertices.push_back(box.min); - vertices.emplace_back(box.max(0), box.min(1), box.min(2)); - vertices.emplace_back(box.max(0), box.max(1), box.min(2)); - vertices.emplace_back(box.min(0), box.max(1), box.min(2)); - vertices.emplace_back(box.min(0), box.min(1), box.max(2)); - vertices.emplace_back(box.max(0), box.min(1), box.max(2)); - vertices.push_back(box.max); - vertices.emplace_back(box.min(0), box.max(1), box.max(2)); - - // set the Z range in eye coordinates (negative Zs are in front of the camera) - for (const Vec3d& v : vertices) - { - double z = -(m_view_matrix * v)(2); - ret.first = std::min(ret.first, z); - ret.second = std::max(ret.second, z); - } + // box in eye space + BoundingBoxf3 eye_box = box.transformed(m_view_matrix); + ret.first = -eye_box.max(2); + ret.second = -eye_box.min(2); // apply margin ret.first -= FrustrumZMargin; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 207d5c756..9f53a45d4 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3928,38 +3928,11 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool if (show_bed) { // extends the near and far z of the frustrum to avoid the bed being clipped - BoundingBoxf3 bed_box = m_bed.get_bounding_box(true); - // bed box vertices in world space - std::vector vertices; - vertices.reserve(8); - vertices.push_back(bed_box.min); - vertices.emplace_back(bed_box.max(0), bed_box.min(1), bed_box.min(2)); - vertices.emplace_back(bed_box.max(0), bed_box.max(1), bed_box.min(2)); - vertices.emplace_back(bed_box.min(0), bed_box.max(1), bed_box.min(2)); - vertices.emplace_back(bed_box.min(0), bed_box.min(1), bed_box.max(2)); - vertices.emplace_back(bed_box.max(0), bed_box.min(1), bed_box.max(2)); - vertices.push_back(bed_box.max); - vertices.emplace_back(bed_box.min(0), bed_box.max(1), bed_box.max(2)); - - double bed_box_min_z = DBL_MAX; - double bed_box_max_z = -DBL_MAX; - Transform3d view_matrix = camera.get_view_matrix(); - for (const Vec3d& v : vertices) - { - Vec3d eye_v = view_matrix * v; - if (eye_v(2) < 0.0) - { - bed_box_min_z = std::min(bed_box_min_z, -eye_v(2)); - bed_box_max_z = std::max(bed_box_max_z, -eye_v(2)); - } - } - - if (bed_box_min_z != DBL_MAX) - near_z = bed_box_min_z; - - if (bed_box_max_z != -DBL_MAX) - far_z = bed_box_max_z; + // box in eye space + BoundingBoxf3 t_bed_box = m_bed.get_bounding_box(true).transformed(camera.get_view_matrix()); + near_z = -t_bed_box.max(2); + far_z = -t_bed_box.min(2); } camera.apply_projection(box, near_z, far_z);