diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 8ab749e24..98f31fb8b 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -143,7 +143,7 @@ sub new { my $on_gizmo_rotate = sub { my ($angle_z, $angle_y) = @_; $self->rotate(rad2deg($angle_z), Z, 'absolute'); - $self->rotate(rad2deg($angle_y), Y, 'absolute'); + $self->rotate(rad2deg($angle_y), Y, 'absolute') if $angle_y != 0; }; # callback to update object's geometry info while using gizmos diff --git a/resources/icons/overlay/layflat_hover.png b/resources/icons/overlay/layflat_hover.png new file mode 100644 index 000000000..afce81d19 Binary files /dev/null and b/resources/icons/overlay/layflat_hover.png differ diff --git a/resources/icons/overlay/layflat_off.png b/resources/icons/overlay/layflat_off.png new file mode 100644 index 000000000..70d198112 Binary files /dev/null and b/resources/icons/overlay/layflat_off.png differ diff --git a/resources/icons/overlay/layflat_on.png b/resources/icons/overlay/layflat_on.png new file mode 100644 index 000000000..3c1891b3c Binary files /dev/null and b/resources/icons/overlay/layflat_on.png differ diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 19dcc6a07..008679e6c 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -732,6 +732,11 @@ TriangleMesh TriangleMesh::convex_hull_3d() const return output_mesh; } +const float* TriangleMesh::first_vertex() const +{ + return stl.facet_start ? &stl.facet_start->vertex[0].x : nullptr; +} + void TriangleMesh::require_shared_vertices() { diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 6ab52efe2..be151f062 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -53,6 +53,7 @@ public: TriangleMeshPtrs split() const; void merge(const TriangleMesh &mesh); ExPolygons horizontal_projection() const; + const float* first_vertex() const; Polygon convex_hull(); BoundingBoxf3 bounding_box() const; // Returns the bbox of this TriangleMesh transformed by the given matrix diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index f0a8f2e71..2b91afe41 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -515,15 +515,15 @@ bool GLGizmoFlatten::on_init() { std::string path = resources_dir() + "/icons/overlay/"; - std::string filename = path + "scale_off.png"; + std::string filename = path + "layflat_off.png"; if (!m_textures[Off].load_from_file(filename, false)) return false; - filename = path + "scale_hover.png"; + filename = path + "layflat_hover.png"; if (!m_textures[Hover].load_from_file(filename, false)) return false; - filename = path + "scale_on.png"; + filename = path + "layflat_on.png"; if (!m_textures[On].load_from_file(filename, false)) return false; @@ -591,12 +591,12 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const // TODO - remove and use Eigen instead -static Pointf3 super_rotation(const Pointf3& axis, float angle, const Pointf3& point) +static Pointf3 super_rotation(Pointf3 axis, float angle, const Pointf3& point) { - float axis_length = axis.distance_to(Pointf3(0.f, 0.f, 0.f)); - float x = axis.x / axis_length; - float y = axis.y / axis_length; - float z = axis.z / axis_length; + axis = normalize(axis); + const float& x = axis.x; + const float& y = axis.y; + const float& z = axis.z; float s = sin(angle); float c = cos(angle); float D = 1-c; @@ -774,6 +774,8 @@ void GLGizmoFlatten::update_planes() m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box()); m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor; m_source_data.rotation = m_model_object->instances.front()->rotation; + const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex(); + m_source_data.mesh_first_point = Pointf3(first_vertex[0], first_vertex[1], first_vertex[3]); } // Check if the bounding boxes of each volume's convex hull is the same as before @@ -793,6 +795,11 @@ bool GLGizmoFlatten::is_plane_update_necessary() const if (m_model_object->volumes[i]->get_convex_hull().bounding_box() != m_source_data.bounding_boxes[i]) return true; + const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex(); + Pointf3 first_point(first_vertex[0], first_vertex[1], first_vertex[2]); + if (first_point != m_source_data.mesh_first_point) + return true; + return false; } diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 0cab603eb..2c82f73f3 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -166,6 +166,7 @@ private: std::vector bounding_boxes; // bounding boxes of convex hulls of individual volumes float scaling_factor; float rotation; + Pointf3 mesh_first_point; }; // This holds information to decide whether recalculation is necessary: