From 385b0f261d3c1f2851b3ebe2b884e39582703180 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 2 Nov 2018 14:41:08 +0100 Subject: [PATCH] Scale of ModelVolume as transformation component (without modifying the mesh) --- src/libslic3r/Model.cpp | 25 +++++++++++++------------ src/libslic3r/Model.hpp | 6 +++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index fabc2992d7..443b96bc85 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -749,12 +749,7 @@ void ModelObject::translate(double x, double y, double z) { for (ModelVolume *v : this->volumes) { -#if ENABLE_MODELVOLUME_TRANSFORM v->translate(x, y, z); -#else - v->mesh.translate(float(x), float(y), float(z)); - v->m_convex_hull.translate(float(x), float(y), float(z)); -#endif // ENABLE_MODELVOLUME_TRANSFORM } if (m_bounding_box_valid) @@ -765,11 +760,12 @@ void ModelObject::scale(const Vec3d &versor) { for (ModelVolume *v : this->volumes) { - v->mesh.scale(versor); - v->m_convex_hull.scale(versor); + v->scale(versor); } +#if !ENABLE_MODELVOLUME_TRANSFORM // reset origin translation since it doesn't make sense anymore this->origin_translation = Vec3d::Zero(); +#endif // !ENABLE_MODELVOLUME_TRANSFORM this->invalidate_bounding_box(); } @@ -1142,11 +1138,6 @@ size_t ModelVolume::split(unsigned int max_extruders) return idx; } -void ModelVolume::translate(double x, double y, double z) -{ - translate(Vec3d(x, y, z)); -} - void ModelVolume::translate(const Vec3d& displacement) { #if ENABLE_MODELVOLUME_TRANSFORM @@ -1157,6 +1148,16 @@ void ModelVolume::translate(const Vec3d& displacement) #endif // ENABLE_MODELVOLUME_TRANSFORM } +void ModelVolume::scale(const Vec3d& scaling_factors) +{ +#if ENABLE_MODELVOLUME_TRANSFORM + m_transformation.set_scaling_factor(m_transformation.get_scaling_factor().cwiseProduct(scaling_factors)); +#else + mesh.scale(scaling_factors); + m_convex_hull.scale(scaling_factors); +#endif // ENABLE_MODELVOLUME_TRANSFORM +} + #if !ENABLE_MODELVOLUME_TRANSFORM void ModelInstance::set_rotation(const Vec3d& rotation) { diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 92cef8e6dc..69bae3454b 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -163,6 +163,7 @@ public: void translate(double x, double y, double z); void scale(const Vec3d &versor); void scale(const double s) { this->scale(Vec3d(s, s, s)); } + void scale(double x, double y, double z) { this->scale(Vec3d(x, y, z)); } void rotate(float angle, const Axis &axis); void rotate(float angle, const Vec3d& axis); void mirror(const Axis &axis); @@ -246,8 +247,11 @@ public: // Return the number of volumes created from this one. // This is useful to assign different materials to different volumes of an object. size_t split(unsigned int max_extruders); - void translate(double x, double y, double z); + void translate(double x, double y, double z) { translate(Vec3d(x, y, z)); } void translate(const Vec3d& displacement); + void scale(const Vec3d& scaling_factors); + void scale(double x, double y, double z) { scale(Vec3d(x, y, z)); } + void scale(double s) { scale(Vec3d(s, s, s)); } ModelMaterial* assign_unique_material();