From 098d428bb0e53a405419c93b07460ae95cbc3cd8 Mon Sep 17 00:00:00 2001 From: Michael Kirsch Date: Sat, 29 Jun 2019 12:28:56 +0200 Subject: [PATCH] reinstate model volume transformations --- xs/src/libslic3r/Model.cpp | 30 ++++++++++++++++++++++++++++++ xs/src/libslic3r/Model.hpp | 25 +++++++++++++++++++++++++ xs/xsp/Model.xsp | 6 +++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 3552afd95..674f47fa5 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -1080,6 +1080,36 @@ ModelVolume::bounding_box() const return this->mesh.bounding_box(); } +void ModelVolume::translate(double x, double y, double z) +{ + TransformationMatrix trafo = TransformationMatrix::mat_translation(x,y,z); + this->apply_transformation(trafo); +} + +void ModelVolume::scale(double x, double y, double z) +{ + TransformationMatrix trafo = TransformationMatrix::mat_scale(x,y,z); + this->apply_transformation(trafo); +} + +void ModelVolume::mirror(const Axis &axis) +{ + TransformationMatrix trafo = TransformationMatrix::mat_mirror(axis); + this->apply_transformation(trafo); +} + +void ModelVolume::mirror(const Vectorf3 &normal) +{ + TransformationMatrix trafo = TransformationMatrix::mat_mirror(normal); + this->apply_transformation(trafo); +} + +void ModelVolume::rotate(double angle_rad, const Axis &axis) +{ + TransformationMatrix trafo = TransformationMatrix::mat_rotation(angle_rad, axis); + this->apply_transformation(trafo); +} + void ModelVolume::apply_transformation(TransformationMatrix const & trafo) { this->mesh.transform(trafo); diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index c0a247059..56645e3f5 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -504,7 +504,32 @@ class ModelVolume BoundingBoxf3 get_transformed_bounding_box(TransformationMatrix const & trafo) const; BoundingBoxf3 bounding_box() const; + + //Transformation matrix manipulators + /// performs translation + void translate(double x, double y, double z); + void translate(Vectorf3 const &vector) { this->translate(vector.x, vector.y, vector.z); }; + void translateXY(Vectorf const &vector) { this->translate(vector.x, vector.y, 0); }; + + /// performs uniform scale + void scale(double factor) { this->scale(factor, factor, factor); }; + + /// performs per-axis scale + void scale(double x, double y, double z); + + /// performs per-axis scale via vector + void scale(Vectorf3 const &vector) { this->scale(vector.x, vector.y, vector.z); }; + + /// performs mirroring along given axis + void mirror(const Axis &axis); + + /// performs mirroring along given axis + void mirror(const Vectorf3 &normal); + + /// performs rotation around given axis + void rotate(double angle_rad, const Axis &axis); + /// apply whichever matrix is supplied, multiplied from the left void apply_transformation(TransformationMatrix const &trafo); diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index fddae2cf7..7c176baf5 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -290,7 +290,11 @@ ModelMaterial::attributes() } %}; - + void translate(double x, double y, double z); + void scale_xyz(Pointf3* versor) + %code{% THIS->scale(*versor); %}; + void rotate(double angle, Axis axis); + Ref config() %code%{ RETVAL = &THIS->config; %}; Ref mesh()