diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index ae8d35c1f..66a2b42ca 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -280,123 +280,28 @@ TriangleMesh::WriteOBJFile(const std::string &output_file) const { #endif } -void TriangleMesh::scale(float factor) +TriangleMesh TriangleMesh::get_transformed_mesh(TransformationMatrix const & trafo) const { - stl_scale(&(this->stl), factor); + TriangleMesh mesh; + std::vector trafo_arr = trafo.matrix3x4f(); + stl_transform(&(this->stl), &(mesh.stl), trafo_arr.data()); + stl_invalidate_shared_vertices(&(mesh.stl)); + return mesh; +} + +void TriangleMesh::transform(TransformationMatrix const & trafo) +{ + std::vector trafo_arr = trafo.matrix3x4f(); + stl_transform(&(this->stl), trafo_arr.data()); + stl_invalidate_shared_vertices(&(this->stl)); +} + +void TriangleMesh::align_to_bed() +{ + stl_translate_relative(&(this->stl), 0.0f, 0.0f, -this->stl.stats.min.z); stl_invalidate_shared_vertices(&this->stl); } -void TriangleMesh::scale(const Pointf3 &versor) -{ - float fversor[3]; - fversor[0] = versor.x; - fversor[1] = versor.y; - fversor[2] = versor.z; - stl_scale_versor(&this->stl, fversor); - stl_invalidate_shared_vertices(&this->stl); -} - -void TriangleMesh::translate(float x, float y, float z) -{ - stl_translate_relative(&(this->stl), x, y, z); - stl_invalidate_shared_vertices(&this->stl); -} - -void TriangleMesh::translate(Pointf3 vec) { - this->translate( - static_cast(vec.x), - static_cast(vec.y), - static_cast(vec.z) - ); -} - -void TriangleMesh::rotate(float angle, const Axis &axis) -{ - // admesh uses degrees - angle = Slic3r::Geometry::rad2deg(angle); - - if (axis == X) { - stl_rotate_x(&(this->stl), angle); - } else if (axis == Y) { - stl_rotate_y(&(this->stl), angle); - } else if (axis == Z) { - stl_rotate_z(&(this->stl), angle); - } - stl_invalidate_shared_vertices(&this->stl); -} - -void TriangleMesh::rotate_x(float angle) -{ - this->rotate(angle, X); -} - -void TriangleMesh::rotate_y(float angle) -{ - this->rotate(angle, Y); -} - -void TriangleMesh::rotate_z(float angle) -{ - this->rotate(angle, Z); -} - -void TriangleMesh::mirror(const Axis &axis) -{ - if (axis == X) { - stl_mirror_yz(&this->stl); - } else if (axis == Y) { - stl_mirror_xz(&this->stl); - } else if (axis == Z) { - stl_mirror_xy(&this->stl); - } - stl_invalidate_shared_vertices(&this->stl); -} - -void TriangleMesh::mirror_x() -{ - this->mirror(X); -} - -void TriangleMesh::mirror_y() -{ - this->mirror(Y); -} - -void TriangleMesh::mirror_z() -{ - this->mirror(Z); -} - -void TriangleMesh::align_to_origin() -{ - this->translate( - -(this->stl.stats.min.x), - -(this->stl.stats.min.y), - -(this->stl.stats.min.z) - ); -} - -void TriangleMesh::center_around_origin() -{ - this->align_to_origin(); - this->translate( - -(this->stl.stats.size.x/2), - -(this->stl.stats.size.y/2), - -(this->stl.stats.size.z/2) - ); -} - -void TriangleMesh::rotate(double angle, Point* center) -{ - this->rotate(angle, *center); -} -void TriangleMesh::rotate(double angle, const Point& center) -{ - this->translate(-center.x, -center.y, 0); - stl_rotate_z(&(this->stl), (float)angle); - this->translate(+center.x, +center.y, 0); -} - Pointf3s TriangleMesh::vertices() { Pointf3s tmp {}; diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 4ecaf63f8..7b8e456f3 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -63,30 +63,11 @@ class TriangleMesh bool is_manifold() const; void WriteOBJFile(const std::string &output_file) const; - void scale(float factor); - void scale(const Pointf3 &versor); + TriangleMesh get_transformed_mesh(TransformationMatrix const & trafo) const; - /// Translate the mesh to a new location. - void translate(float x, float y, float z); + void transform(TransformationMatrix const & trafo); - /// Translate the mesh to a new location. - void translate(Pointf3 vec); - - - void rotate(float angle, const Axis &axis); - void rotate_x(float angle); - void rotate_y(float angle); - void rotate_z(float angle); - void mirror(const Axis &axis); - void mirror_x(); - void mirror_y(); - void mirror_z(); - void align_to_origin(); - void center_around_origin(); - - /// Rotate angle around a specified point. - void rotate(double angle, const Point& center); - void rotate(double angle, Point* center); + void align_to_bed(); TriangleMeshPtrs split() const; TriangleMeshPtrs cut_by_grid(const Pointf &grid) const; diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index 47f7c7558..9d965a102 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -17,18 +17,7 @@ void repair(); float volume(); void WriteOBJFile(std::string output_file); - void scale(float factor); - void scale_xyz(Pointf3* versor) - %code{% THIS->scale(*versor); %}; - void translate(float x, float y, float z); - void rotate_x(float angle); - void rotate_y(float angle); - void rotate_z(float angle); - void mirror_x(); - void mirror_y(); - void mirror_z(); - void align_to_origin(); - void rotate(double angle, Point* center); + void align_to_bed(); TriangleMeshPtrs split(); TriangleMeshPtrs cut_by_grid(Pointf* grid) %code{% RETVAL = THIS->cut_by_grid(*grid); %};