diff options
author | Lukas Matena <lukasmatena@seznam.cz> | 2018-09-26 14:54:09 +0300 |
---|---|---|
committer | Lukas Matena <lukasmatena@seznam.cz> | 2018-09-26 14:54:09 +0300 |
commit | 10393ba834169a09ec2c06b8c7c2e9f52bba7d30 (patch) | |
tree | 0836da25fdd1f24a9b2eaeba70cc261948de9e7c /xs | |
parent | fc82aaaa2ec384f4bd6cd7484f8648159c0e652a (diff) |
Flatten and SlaSupports gizmos - grabbers rendered correctly when object is dragged
Diffstat (limited to 'xs')
-rw-r--r-- | xs/src/slic3r/GUI/GLGizmo.cpp | 38 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/GLGizmo.hpp | 12 |
2 files changed, 34 insertions, 16 deletions
diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 3fa97a0a4..cdd2badef 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -1246,9 +1246,9 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const // the dragged_offset is a vector measuring where was the object moved // with the gizmo being on. This is reset in set_flattening_data and // does not work correctly when there are multiple copies. - Vec3d dragged_offset(Vec3d::Zero()); - if (m_dragging) - dragged_offset = box.center() - m_starting_center; + if (m_starting_center == Vec3d::Zero()) + m_starting_center = box.center(); + Vec3d dragged_offset(box.center() - m_starting_center); ::glEnable(GL_BLEND); ::glEnable(GL_DEPTH_TEST); @@ -1309,6 +1309,7 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) { + m_starting_center = Vec3d::Zero(); m_model_object = model_object; // ...and save the updated positions of the object instances: @@ -1565,7 +1566,7 @@ Vec3d GLGizmoFlatten::get_flattening_normal() const { GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent) - : GLGizmoBase(parent) + : GLGizmoBase(parent), m_starting_center(Vec3d::Zero()) { } @@ -1588,18 +1589,33 @@ bool GLGizmoSlaSupports::on_init() return true; } +void GLGizmoSlaSupports::set_model_object_ptr(ModelObject* model_object) +{ + m_starting_center = Vec3d::Zero(); + m_model_object = model_object; + if (is_mesh_update_necessary()) + update_mesh(); +} + void GLGizmoSlaSupports::on_render(const BoundingBoxf3& box) const { ::glEnable(GL_BLEND); ::glEnable(GL_DEPTH_TEST); + // the dragged_offset is a vector measuring where was the object moved + // with the gizmo being on. This is reset in set_flattening_data and + // does not work correctly when there are multiple copies. + if (m_starting_center == Vec3d::Zero()) + m_starting_center = box.center(); + Vec3d dragged_offset(box.center() - m_starting_center); + for (auto& g : m_grabbers) { g.color[0] = 1.f; g.color[1] = 0.f; g.color[2] = 0.f; } - render_grabbers(); + render_grabbers(dragged_offset); render_tooltip_texture(); ::glDisable(GL_BLEND); @@ -1613,10 +1629,10 @@ void GLGizmoSlaSupports::on_render_for_picking(const BoundingBoxf3& box) const m_grabbers[i].color[1] = 1.0f; m_grabbers[i].color[2] = picking_color_component(i); } - render_grabbers(true); + render_grabbers(Vec3d::Zero(), true); } -void GLGizmoSlaSupports::render_grabbers(bool picking) const +void GLGizmoSlaSupports::render_grabbers(const Vec3d& dragged_offset, bool picking) const { for (int i = 0; i < (int)m_grabbers.size(); ++i) { @@ -1635,7 +1651,7 @@ void GLGizmoSlaSupports::render_grabbers(bool picking) const ::glEnable(GL_LIGHTING); ::glColor3f((GLfloat)render_color[0], (GLfloat)render_color[1], (GLfloat)render_color[2]); ::glPushMatrix(); - Vec3d center = m_model_object->instances.front()->world_matrix() * m_grabbers[i].center; + Vec3d center = m_model_object->instances.front()->world_matrix() * m_grabbers[i].center + dragged_offset; ::glTranslatef((GLfloat)center(0), (GLfloat)center(1), (GLfloat)center(2)); GLUquadricObj *quadric; quadric = ::gluNewQuadric(); @@ -1653,7 +1669,7 @@ bool GLGizmoSlaSupports::is_mesh_update_necessary() const if (m_state != On || !m_model_object || m_model_object->instances.empty()) return false; -#if ENABLE_MODELINSTANCE_3D_ROTATION +#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size() || (m_model_object->instances.front()->world_matrix() * m_source_data.matrix.inverse() * Vec3d(1., 1., 1.) - Vec3d(1., 1., 1.)).norm() > 0.001 ) #else @@ -1706,12 +1722,12 @@ void GLGizmoSlaSupports::update_mesh() m_source_data.bounding_boxes.clear(); for (const auto& vol : m_model_object->volumes) m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box()); -#if !ENABLE_MODELINSTANCE_3D_ROTATION +#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor; m_source_data.rotation = m_model_object->instances.front()->rotation; #else m_source_data.matrix = m_model_object->instances.front()->world_matrix(); -#endif // !ENABLE_MODELINSTANCE_3D_ROTATION +#endif const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex(); m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]); diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 2d06621ae..cdebba99c 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -375,7 +375,7 @@ private: #else std::vector<Vec2d> m_instances_positions; #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - Vec3d m_starting_center; + mutable Vec3d m_starting_center; const ModelObject* m_model_object = nullptr; void update_planes(); @@ -414,21 +414,23 @@ private: Eigen::MatrixXi m_F; // facets indices struct SourceDataSummary { std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes -#if !ENABLE_MODELINSTANCE_3D_ROTATION +#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM float scaling_factor; float rotation; #else Transform3d matrix; -#endif // !ENABLE_MODELINSTANCE_3D_ROTATION +#endif Vec3d mesh_first_point; }; // This holds information to decide whether recalculation is necessary: SourceDataSummary m_source_data; + mutable Vec3d m_starting_center; + public: explicit GLGizmoSlaSupports(GLCanvas3D& parent); - void set_model_object_ptr(ModelObject* model_object) { m_model_object = model_object; if (is_mesh_update_necessary()) update_mesh(); } + void set_model_object_ptr(ModelObject* model_object); void clicked_on_object(const Vec2d& mouse_position); void delete_current_grabber(bool delete_all); @@ -437,7 +439,7 @@ private: void on_update(const Linef3& mouse_ray, const Point* mouse_pos); void on_render(const BoundingBoxf3& box) const; void on_render_for_picking(const BoundingBoxf3& box) const; - void render_grabbers(bool picking = false) const; + void render_grabbers(const Vec3d& dragged_offset, bool picking = false) const; void render_tooltip_texture() const; bool is_mesh_update_necessary() const; void update_mesh(); |