diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 9462a2153..9b9408ad7 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -724,6 +724,13 @@ ModelObject::center_around_origin() } } +TransformationMatrix +ModelObject::get_trafo_to_center() const +{ + BoundingBoxf3 raw_bb = this->raw_bounding_box(); + return TransformationMatrix::mat_translation(raw_bb.center().negative()); +} + void ModelObject::translate(const Vectorf3 &vector) { @@ -782,6 +789,17 @@ ModelObject::rotate(double angle, const Axis &axis) this->invalidate_bounding_box(); } +void +ModelObject::rotate(double angle, const Vectorf3 &axis) +{ + if (angle == 0) return; + TransformationMatrix trafo = TransformationMatrix::mat_rotation(angle, axis); + this->apply_transformation(trafo); + + this->origin_translation = Pointf3(0,0,0); + this->invalidate_bounding_box(); +} + void ModelObject::rotate(const Vectorf3 &origin, const Vectorf3 &target) { diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index cb2b1f793..c0a247059 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -358,6 +358,9 @@ class ModelObject /// Center the current ModelObject to origin by translating the ModelVolumes void center_around_origin(); + /// Get the matrix, that, when applied, centers the bounding box in all 3 coordinate directions + TransformationMatrix get_trafo_to_center() const; + /// Translate the current ModelObject by translating ModelVolumes with (x,y,z) units. /// This function calls translate(coordf_t x, coordf_t y, coordf_t z) to translate every TriangleMesh in each ModelVolume. /// \param vector Vectorf3 the translation vector @@ -388,6 +391,11 @@ class ModelObject /// \param axis Axis the axis to be rotated around void rotate(double angle, const Axis &axis); + /// Rotate the current ModelObject by rotating ModelVolumes. + /// \param angle double the angle in radians + /// \param axis Axis the axis to be rotated around + void rotate(double angle, const Vectorf3 &axis); + /// Rotate the current ModelObject by rotating ModelVolumes to align the given vectors /// \param origin Vectorf3 /// \param target Vectorf3