From 3bfeb2dc0bc4b996566add7993ba18507a08f87f Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Fri, 1 Aug 2025 11:50:59 +0800 Subject: [PATCH] FIX:add "printable_bounding_box" api jira: STUDIO-13765 Change-Id: I748ad0371ce80a3ac1a7774fea14d47beb79a187 (cherry picked from commit 1368c67499a0d0f273c824e916bf66980a526203) --- src/slic3r/GUI/3DBed.cpp | 45 ++++++++++++++++++--------------------- src/slic3r/GUI/3DBed.hpp | 5 ++++- src/slic3r/GUI/Plater.cpp | 5 ++--- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index b051aa8139..544a3f8f12 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -318,22 +318,14 @@ bool Bed3D::set_shape(const Pointfs& printable_area, const double printable_heig m_type = type; //m_texture_filename = texture_filename; m_model_filename = model_filename; - //BBS: add part plate logic - m_extended_bounding_box = this->calc_extended_bounding_box(false); - - //BBS: add part plate logic - //BBS add default bed m_triangles.reset(); - if (with_reset) { //m_texture.reset(); m_model.reset(); } //BBS: add part plate logic, always update model offset - //else { - update_model_offset(); - //} + update_model_offset();//include m_extended_bounding_box = this->calc_extended_bounding_box(); // Set the origin and size for rendering the coordinate system axes. m_axes.set_origin({ 0.0, 0.0, static_cast(GROUND_Z) }); @@ -407,9 +399,9 @@ void Bed3D::render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, //BBS: add partplate related logic // Calculate an extended bounding box from axes and current model for visualization purposes. -BoundingBoxf3 Bed3D::calc_extended_bounding_box(bool consider_model_offset) const +BoundingBoxf3 Bed3D::calc_printable_bounding_box() const { - BoundingBoxf3 out { m_build_volume.bounding_volume() }; + BoundingBoxf3 out{m_build_volume.bounding_volume()}; const Vec3d size = out.size(); // ensures that the bounding box is set as defined or the following calls to merge() will not work as intented @@ -419,19 +411,22 @@ BoundingBoxf3 Bed3D::calc_extended_bounding_box(bool consider_model_offset) cons out.min.z() = 0.0; out.max.z() = 0.0; // extend to contain axes - //BBS: add part plate related logic. - Vec3d offset{ m_position.x(), m_position.y(), 0.f }; - //out.merge(m_axes.get_origin() + offset + m_axes.get_total_length() * Vec3d::Ones()); + // BBS: add part plate related logic. + Vec3d offset{m_position.x(), m_position.y(), 0.f}; + // out.merge(m_axes.get_origin() + offset + m_axes.get_total_length() * Vec3d::Ones()); out.merge(Vec3d(0.f, 0.f, GROUND_Z) + offset + m_axes.get_total_length() * Vec3d::Ones()); out.merge(out.min + Vec3d(-Axes::DefaultTipRadius, -Axes::DefaultTipRadius, out.max.z())); - //BBS: add part plate related logic. - if (consider_model_offset) { - // extend to contain model, if any - BoundingBoxf3 model_bb = m_model.get_bounding_box(); - if (model_bb.defined) { - model_bb.translate(m_model_offset); - out.merge(model_bb); - } + return out; +} + +BoundingBoxf3 Bed3D::calc_extended_bounding_box() const +{ + BoundingBoxf3 out; + out.merge(m_printable_bounding_box); + BoundingBoxf3 model_bb = m_model.get_bounding_box(); + if (model_bb.defined) { + model_bb.translate(m_model_offset); + out.merge(model_bb); } return out; } @@ -633,7 +628,8 @@ void Bed3D::update_model_offset() (*model_offset_ptr)(2) = -0.41 + GROUND_Z; // update extended bounding box - const_cast(m_extended_bounding_box) = calc_extended_bounding_box(); + const_cast(m_printable_bounding_box) = calc_printable_bounding_box(); + const_cast(m_extended_bounding_box) = calc_extended_bounding_box(); m_triangles.reset(); } @@ -670,7 +666,8 @@ void Bed3D::update_bed_triangles() BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to update plate triangles\n"; } // update extended bounding box - const_cast(m_extended_bounding_box) = calc_extended_bounding_box(); + const_cast(m_printable_bounding_box) = calc_printable_bounding_box(); + const_cast(m_extended_bounding_box) = calc_extended_bounding_box(); } void Bed3D::render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix) diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index d65132c02b..b791635fd3 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -100,6 +100,7 @@ private: std::string m_model_filename; // Print volume bounding box exteded with axes and model. BoundingBoxf3 m_extended_bounding_box; + BoundingBoxf3 m_printable_bounding_box; // Slightly expanded print bed polygon, for collision detection. //Polygon m_polygon; GLModel m_triangles; @@ -148,6 +149,7 @@ public: // Bounding box around the print bed, axes and model, for rendering. const BoundingBoxf3& extended_bounding_box() const { return m_extended_bounding_box; } + const BoundingBoxf3 &printable_bounding_box() const { return m_printable_bounding_box; } // Check against an expanded 2d bounding box. //FIXME shall one check against the real build volume? @@ -161,7 +163,8 @@ public: private: //BBS: add partplate related logic // Calculate an extended bounding box from axes and current model for visualization purposes. - BoundingBoxf3 calc_extended_bounding_box(bool consider_model_offset = true) const; + BoundingBoxf3 calc_printable_bounding_box() const; + BoundingBoxf3 calc_extended_bounding_box() const; void update_model_offset(); //BBS: with offset void update_bed_triangles(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 82454ecf8c..5178d0a783 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -10321,11 +10321,10 @@ void Plater::priv::set_bed_shape(const Pointfs &shape, //BBS: update part plate's size // BBS: to be checked - Vec3d max = bed.extended_bounding_box().max; - Vec3d min = bed.extended_bounding_box().min; + Vec3d max = bed.printable_bounding_box().max; + Vec3d min = bed.printable_bounding_box().min; double z = config->opt_float("printable_height"); - //Pointfs& exclude_areas = config->option("bed_exclude_area")->values; partplate_list.reset_size(max.x() - min.x() - Bed3D::Axes::DefaultTipRadius, max.y() - min.y() - Bed3D::Axes::DefaultTipRadius, z); partplate_list.set_shapes(shape, exclude_areas, wrapping_exclude_areas, extruder_areas, extruder_heights, custom_texture, height_to_lid, height_to_rod);