diff options
Diffstat (limited to 'src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp')
-rw-r--r-- | src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 395 |
1 files changed, 126 insertions, 269 deletions
diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 0e98f7364..e626aa7f8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -1,7 +1,9 @@ // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. #include "GLGizmoSlaSupports.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" -#include "slic3r/GUI/Gizmos/GLGizmos.hpp" +#include "slic3r/GUI/Camera.hpp" +#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" +#include "slic3r/GUI/MainFrame.hpp" #include <GL/glew.h> @@ -13,9 +15,8 @@ #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" -#include "slic3r/GUI/MeshUtils.hpp" #include "slic3r/GUI/Plater.hpp" -#include "slic3r/GUI/PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/SLAPrint.hpp" @@ -25,7 +26,6 @@ namespace GUI { GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) , m_quadric(nullptr) - , m_its(nullptr) { m_quadric = ::gluNewQuadric(); if (m_quadric != nullptr) @@ -62,26 +62,21 @@ bool GLGizmoSlaSupports::on_init() void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const Selection& selection) { - if (m_c->recent_update) { - if (m_state == On) - m_c->build_AABB_if_needed(); + if (! m_c->selection_info()) + return; - update_clipping_plane(m_c->m_clipping_plane_was_moved); + ModelObject* mo = m_c->selection_info()->model_object(); + if (m_state == On && mo && mo->id() != m_old_mo_id) { disable_editing_mode(); - if (m_c->m_model_object) - reload_cache(); - } - - if (m_state == On) { - m_parent.toggle_model_objects_visibility(false); - m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(! m_editing_mode, m_c->m_model_object, m_c->m_active_instance); + reload_cache(); + m_old_mo_id = mo->id(); + m_c->instances_hider()->show_supports(true); } // If we triggered autogeneration before, check backend and fetch results if they are there - if (m_c->m_model_object) { - if (m_c->m_model_object->sla_points_status == sla::PointsStatus::Generating) + if (mo) { + if (mo->sla_points_status == sla::PointsStatus::Generating) get_data_from_backend(); } } @@ -90,13 +85,13 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S void GLGizmoSlaSupports::on_render() const { + ModelObject* mo = m_c->selection_info()->model_object(); const Selection& selection = m_parent.get_selection(); // If current m_c->m_model_object does not match selection, ask GLCanvas3D to turn us off if (m_state == On - && (m_c->m_model_object != selection.get_model()->objects[selection.get_object_idx()] - || m_c->m_active_instance != selection.get_instance_idx() - || m_c->m_model_object_id != m_c->m_model_object->id())) { + && (mo != selection.get_model()->objects[selection.get_object_idx()] + || m_c->selection_info()->get_active_instance() != selection.get_instance_idx())) { m_parent.post_event(SimpleEvent(EVT_GLCANVAS_RESETGIZMOS)); return; } @@ -104,141 +99,22 @@ void GLGizmoSlaSupports::on_render() const glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_DEPTH_TEST)); - m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); - - render_hollowed_mesh(); - if (m_quadric != nullptr && selection.is_from_single_instance()) render_points(selection, false); m_selection_rectangle.render(m_parent); - render_clipping_plane(selection); + m_c->object_clipper()->render_cut(); + m_c->supports_clipper()->render_cut(); glsafe(::glDisable(GL_BLEND)); } - -void GLGizmoSlaSupports::render_hollowed_mesh() const -{ - /*if (m_c->m_volume_with_cavity) { - m_c->m_volume_with_cavity->set_sla_shift_z(m_z_shift); - m_parent.get_shader().start_using(); - - GLint current_program_id; - glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); - GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; - GLint print_box_detection_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_detection") : -1; - GLint print_box_worldmatrix_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_world_matrix") : -1; - glcheck(); - m_c->m_volume_with_cavity->set_render_color(); - const Geometry::Transformation& volume_trafo = m_c->m_model_object->volumes.front()->get_transformation(); - m_c->m_volume_with_cavity->set_volume_transformation(volume_trafo); - m_c->m_volume_with_cavity->set_instance_transformation(m_c->m_model_object->instances[size_t(m_c->m_active_instance)]->get_transformation()); - m_c->m_volume_with_cavity->render(color_id, print_box_detection_id, print_box_worldmatrix_id); - m_parent.get_shader().stop_using(); - }*/ -} - - - -void GLGizmoSlaSupports::render_clipping_plane(const Selection& selection) const -{ - if (m_c->m_clipping_plane_distance == 0.f || m_c->m_mesh->empty()) - return; - - // Get transformation of the instance - const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); - Geometry::Transformation trafo = vol->get_instance_transformation(); - trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_z_shift)); - - // Get transformation of supports - Geometry::Transformation supports_trafo; - supports_trafo.set_offset(Vec3d(trafo.get_offset()(0), trafo.get_offset()(1), vol->get_sla_shift_z())); - supports_trafo.set_rotation(Vec3d(0., 0., trafo.get_rotation()(2))); - // I don't know why, but following seems to be correct. - supports_trafo.set_mirror(Vec3d(trafo.get_mirror()(0) * trafo.get_mirror()(1) * trafo.get_mirror()(2), - 1, - 1.)); - - // Now initialize the TMS for the object, perform the cut and save the result. - if (! m_c->m_object_clipper) { - m_c->m_object_clipper.reset(new MeshClipper); - m_c->m_object_clipper->set_mesh(*m_c->mesh()); - } - m_c->m_object_clipper->set_plane(*m_c->m_clipping_plane); - m_c->m_object_clipper->set_transformation(trafo); - - - // Next, ask the backend if supports are already calculated. If so, we are gonna cut them too. - // First we need a pointer to the respective SLAPrintObject. The index into objects vector is - // cached so we don't have todo it on each render. We only search for the po if needed: - if (m_c->m_print_object_idx < 0 || (int)m_parent.sla_print()->objects().size() != m_c->m_print_objects_count) { - m_c->m_print_objects_count = m_parent.sla_print()->objects().size(); - m_c->m_print_object_idx = -1; - for (const SLAPrintObject* po : m_parent.sla_print()->objects()) { - ++m_c->m_print_object_idx; - if (po->model_object()->id() == m_c->m_model_object->id()) - break; - } - } - if (m_c->m_print_object_idx >= 0) { - const SLAPrintObject* print_object = m_parent.sla_print()->objects()[m_c->m_print_object_idx]; - - if (print_object->is_step_done(slaposSupportTree) && !print_object->get_mesh(slaposSupportTree).empty()) { - // If the supports are already calculated, save the timestamp of the respective step - // so we can later tell they were recalculated. - size_t timestamp = print_object->step_state_with_timestamp(slaposSupportTree).timestamp; - - if (! m_c->m_supports_clipper || (int)timestamp != m_c->m_old_timestamp) { - // The timestamp has changed. - m_c->m_supports_clipper.reset(new MeshClipper); - // The mesh should already have the shared vertices calculated. - m_c->m_supports_clipper->set_mesh(print_object->support_mesh()); - m_c->m_old_timestamp = timestamp; - } - m_c->m_supports_clipper->set_plane(*m_c->m_clipping_plane); - m_c->m_supports_clipper->set_transformation(supports_trafo); - } - else - // The supports are not valid. We better dump the cached data. - m_c->m_supports_clipper.reset(); - } - - // At this point we have the triangulated cuts for both the object and supports - let's render. - if (! m_c->m_object_clipper->get_triangles().empty()) { - ::glPushMatrix(); - ::glColor3f(1.0f, 0.37f, 0.0f); - ::glBegin(GL_TRIANGLES); - for (const Vec3f& point : m_c->m_object_clipper->get_triangles()) - ::glVertex3f(point(0), point(1), point(2)); - ::glEnd(); - ::glPopMatrix(); - } - - if (m_c->m_supports_clipper && ! m_c->m_supports_clipper->get_triangles().empty() && !m_editing_mode) { - // The supports are hidden in the editing mode, so it makes no sense to render the cuts. - ::glPushMatrix(); - ::glColor3f(1.0f, 0.f, 0.37f); - ::glBegin(GL_TRIANGLES); - for (const Vec3f& point : m_c->m_supports_clipper->get_triangles()) - ::glVertex3f(point(0), point(1), point(2)); - ::glEnd(); - ::glPopMatrix(); - } -} - - void GLGizmoSlaSupports::on_render_for_picking() const { const Selection& selection = m_parent.get_selection(); -#if ENABLE_RENDER_PICKING_PASS - m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); -#endif - glsafe(::glEnable(GL_DEPTH_TEST)); render_points(selection, true); - render_hollowed_mesh(); } void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) const @@ -249,9 +125,10 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); + float z_shift = m_c->selection_info()->get_sla_shift(); glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, m_z_shift)); + glsafe(::glTranslated(0.0, 0.0, z_shift)); glsafe(::glMultMatrixd(instance_matrix.data())); float render_color[4]; @@ -307,7 +184,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) if (m_editing_mode) { // in case the normal is not yet cached, find and cache it if (m_editing_cache[i].normal == Vec3f::Zero()) - m_c->m_mesh_raycaster->get_closest_point(m_editing_cache[i].support_point.pos, &m_editing_cache[i].normal); + m_c->raycaster()->raycaster()->get_closest_point(m_editing_cache[i].support_point.pos, &m_editing_cache[i].normal); Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>()); @@ -337,14 +214,15 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) } // Now render the drain holes: - if (! m_c->has_drilled_mesh()) { + //if (! m_c->has_drilled_mesh()) { + if (! m_c->hollowed_mesh()->get_hollowed_mesh()) { render_color[0] = 0.7f; render_color[1] = 0.7f; render_color[2] = 0.7f; render_color[3] = 0.7f; glsafe(::glColor4fv(render_color)); - for (const sla::DrainHole& drain_hole : m_c->m_model_object->sla_drain_holes) { - if (is_mesh_point_clipped((drain_hole.pos+m_c->HoleStickOutLength*drain_hole.normal).cast<double>())) + for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) { + if (is_mesh_point_clipped(drain_hole.pos.cast<double>())) continue; // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. @@ -363,10 +241,10 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2))); glsafe(::glPushMatrix()); glsafe(::glTranslated(0., 0., -drain_hole.height)); - ::gluCylinder(m_quadric, drain_hole.radius, drain_hole.radius, drain_hole.height, 24, 1); - glsafe(::glTranslated(0., 0., drain_hole.height)); + ::gluCylinder(m_quadric, drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength, 24, 1); + glsafe(::glTranslated(0., 0., drain_hole.height + sla::HoleStickOutLength)); ::gluDisk(m_quadric, 0.0, drain_hole.radius, 24, 1); - glsafe(::glTranslated(0., 0., -drain_hole.height)); + glsafe(::glTranslated(0., 0., -drain_hole.height - sla::HoleStickOutLength)); glsafe(::glRotatef(180.f, 1.f, 0.f, 0.f)); ::gluDisk(m_quadric, 0.0, drain_hole.radius, 24, 1); glsafe(::glPopMatrix()); @@ -387,12 +265,17 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) bool GLGizmoSlaSupports::is_mesh_point_clipped(const Vec3d& point) const { - if (m_c->m_clipping_plane_distance == 0.f) + if (m_c->object_clipper()->get_position() == 0.) return false; - Vec3d transformed_point = m_c->m_model_object->instances[m_c->m_active_instance]->get_transformation().get_matrix() * point; - transformed_point(2) += m_z_shift; - return m_c->m_clipping_plane->is_point_clipped(transformed_point); + auto sel_info = m_c->selection_info(); + int active_inst = m_c->selection_info()->get_active_instance(); + const ModelInstance* mi = sel_info->model_object()->instances[active_inst]; + const Transform3d& trafo = mi->get_transformation().get_matrix(); + + Vec3d transformed_point = trafo * point; + transformed_point(2) += sel_info->get_sla_shift(); + return m_c->object_clipper()->get_clipping_plane()->is_point_clipped(transformed_point); } @@ -401,33 +284,37 @@ bool GLGizmoSlaSupports::is_mesh_point_clipped(const Vec3d& point) const // Return false if no intersection was found, true otherwise. bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec3f, Vec3f>& pos_and_normal) { - if (! m_c->m_mesh_raycaster) + if (! m_c->raycaster()->raycaster()) return false; - const Camera& camera = m_parent.get_camera(); + const Camera& camera = wxGetApp().plater()->get_camera(); const Selection& selection = m_parent.get_selection(); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); Geometry::Transformation trafo = volume->get_instance_transformation(); - trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_z_shift)); + trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_c->selection_info()->get_sla_shift())); + + double clp_dist = m_c->object_clipper()->get_position(); + const ClippingPlane* clp = m_c->object_clipper()->get_clipping_plane(); // The raycaster query Vec3f hit; Vec3f normal; - if (m_c->m_mesh_raycaster->unproject_on_mesh( + if (m_c->raycaster()->raycaster()->unproject_on_mesh( mouse_pos, trafo.get_matrix(), camera, hit, normal, - m_c->m_clipping_plane_distance != 0.f ? m_c->m_clipping_plane.get() : nullptr)) + clp_dist != 0. ? clp : nullptr)) { // Check whether the hit is in a hole bool in_hole = false; // In case the hollowed and drilled mesh is available, we can allow // placing points in holes, because they should never end up // on surface that's been drilled away. - if (! m_c->has_drilled_mesh()) { - for (const sla::DrainHole& hole : m_c->m_model_object->sla_drain_holes) { + if (! m_c->hollowed_mesh()->get_hollowed_mesh()) { + sla::DrainHoles drain_holes = m_c->selection_info()->model_object()->sla_drain_holes; + for (const sla::DrainHole& hole : drain_holes) { if (hole.is_inside(hit)) { in_hole = true; break; @@ -450,6 +337,9 @@ bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec // concludes that the event was not intended for it, it should return false. bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down) { + ModelObject* mo = m_c->selection_info()->model_object(); + int active_inst = m_c->selection_info()->get_active_instance(); + if (m_editing_mode) { // left down with shift - show the selection rectangle: @@ -501,8 +391,8 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous GLSelectionRectangle::EState rectangle_status = m_selection_rectangle.get_state(); // First collect positions of all the points in world coordinates. - Geometry::Transformation trafo = m_c->m_model_object->instances[m_c->m_active_instance]->get_transformation(); - trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_z_shift)); + Geometry::Transformation trafo = mo->instances[active_inst]->get_transformation(); + trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_c->selection_info()->get_sla_shift())); std::vector<Vec3d> points; for (unsigned int i=0; i<m_editing_cache.size(); ++i) points.push_back(trafo.get_matrix() * m_editing_cache[i].support_point.pos.cast<double>()); @@ -514,7 +404,9 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous points_inside.push_back(points[idx].cast<float>()); // Only select/deselect points that are actually visible - for (size_t idx : m_c->m_mesh_raycaster->get_unobscured_idxs(trafo, m_parent.get_camera(), points_inside, m_c->m_clipping_plane.get())) + for (size_t idx : m_c->raycaster()->raycaster()->get_unobscured_idxs( + trafo, wxGetApp().plater()->get_camera(), points_inside, + m_c->object_clipper()->get_clipping_plane())) { if (rectangle_status == GLSelectionRectangle::Deselect) unselect_point(points_idxs[idx]); @@ -591,20 +483,21 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous } if (action == SLAGizmoEventType::MouseWheelUp && control_down) { - m_c->m_clipping_plane_distance = std::min(1.f, m_c->m_clipping_plane_distance + 0.01f); - update_clipping_plane(m_c->m_clipping_plane_was_moved); - m_c->m_clipping_plane_was_moved = true; + double pos = m_c->object_clipper()->get_position(); + pos = std::min(1., pos + 0.01); + m_c->object_clipper()->set_position(pos, true); return true; } if (action == SLAGizmoEventType::MouseWheelDown && control_down) { - m_c->m_clipping_plane_distance = std::max(0.f, m_c->m_clipping_plane_distance - 0.01f); - update_clipping_plane(true); + double pos = m_c->object_clipper()->get_position(); + pos = std::max(0., pos - 0.01); + m_c->object_clipper()->set_position(pos, true); return true; } if (action == SLAGizmoEventType::ResetClippingPlane) { - update_clipping_plane(); + m_c->object_clipper()->set_position(-1., false); return true; } @@ -627,8 +520,6 @@ void GLGizmoSlaSupports::delete_selected_points(bool force) } select_point(NoPoints); - - //m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); } void GLGizmoSlaSupports::on_update(const UpdateData& data) @@ -643,8 +534,6 @@ void GLGizmoSlaSupports::on_update(const UpdateData& data) m_editing_cache[m_hover_id].support_point.pos = pos_and_normal.first; m_editing_cache[m_hover_id].support_point.is_new_island = false; m_editing_cache[m_hover_id].normal = pos_and_normal.second; - // Do not update immediately, wait until the mouse is released. - // m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); } } } @@ -652,11 +541,12 @@ void GLGizmoSlaSupports::on_update(const UpdateData& data) std::vector<const ConfigOption*> GLGizmoSlaSupports::get_config_options(const std::vector<std::string>& keys) const { std::vector<const ConfigOption*> out; + const ModelObject* mo = m_c->selection_info()->model_object(); - if (!m_c->m_model_object) + if (! mo) return out; - const DynamicPrintConfig& object_cfg = m_c->m_model_object->config; + const DynamicPrintConfig& object_cfg = mo->config.get(); const DynamicPrintConfig& print_cfg = wxGetApp().preset_bundle->sla_prints.get_edited_preset().config; std::unique_ptr<DynamicPrintConfig> default_cfg = nullptr; @@ -677,14 +567,6 @@ std::vector<const ConfigOption*> GLGizmoSlaSupports::get_config_options(const st } -ClippingPlane GLGizmoSlaSupports::get_sla_clipping_plane() const -{ - if (!m_c->m_model_object || m_state == Off || m_c->m_clipping_plane_distance == 0.f) - return ClippingPlane::ClipsNothing(); - else - return ClippingPlane(-m_c->m_clipping_plane->get_normal(), m_c->m_clipping_plane->get_data()[3]); -} - /* void GLGizmoSlaSupports::find_intersecting_facets(const igl::AABB<Eigen::MatrixXf, 3>* aabb, const Vec3f& normal, double offset, std::vector<unsigned int>& idxs) const @@ -732,7 +614,9 @@ void GLGizmoSlaSupports::on_render_input_window(float x, float y, float bottom_l static float last_y = 0.0f; static float last_h = 0.0f; - if (! m_c->m_model_object) + ModelObject* mo = m_c->selection_info()->model_object(); + + if (! mo) return; bool first_run = true; // This is a hack to redraw the button when all points are removed, @@ -869,15 +753,15 @@ RENDER_AGAIN: m_density_stash = density; } if (slider_edited) { - m_c->m_model_object->config.opt<ConfigOptionFloat>("support_points_minimal_distance", true)->value = minimal_point_distance; - m_c->m_model_object->config.opt<ConfigOptionInt>("support_points_density_relative", true)->value = (int)density; + mo->config.set("support_points_minimal_distance", minimal_point_distance); + mo->config.set("support_points_density_relative", (int)density); } if (slider_released) { - m_c->m_model_object->config.opt<ConfigOptionFloat>("support_points_minimal_distance", true)->value = m_minimal_point_distance_stash; - m_c->m_model_object->config.opt<ConfigOptionInt>("support_points_density_relative", true)->value = (int)m_density_stash; + mo->config.set("support_points_minimal_distance", m_minimal_point_distance_stash); + mo->config.set("support_points_density_relative", (int)m_density_stash); Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Support parameter change"))); - m_c->m_model_object->config.opt<ConfigOptionFloat>("support_points_minimal_distance", true)->value = minimal_point_distance; - m_c->m_model_object->config.opt<ConfigOptionInt>("support_points_density_relative", true)->value = (int)density; + mo->config.set("support_points_minimal_distance", minimal_point_distance); + mo->config.set("support_points_density_relative", (int)density); wxGetApp().obj_list()->update_and_show_object_settings_item(); } @@ -904,7 +788,7 @@ RENDER_AGAIN: // Following is rendered in both editing and non-editing mode: ImGui::Separator(); - if (m_c->m_clipping_plane_distance == 0.f) + if (m_c->object_clipper()->get_position() == 0.f) { ImGui::AlignTextToFramePadding(); m_imgui->text(m_desc.at("clipping_of_view")); @@ -912,17 +796,16 @@ RENDER_AGAIN: else { if (m_imgui->button(m_desc.at("reset_direction"))) { wxGetApp().CallAfter([this](){ - update_clipping_plane(); + m_c->object_clipper()->set_position(-1., false); }); } } ImGui::SameLine(clipping_slider_left); ImGui::PushItemWidth(window_width - clipping_slider_left); - if (ImGui::SliderFloat(" ", &m_c->m_clipping_plane_distance, 0.f, 1.f, "%.2f")) { - update_clipping_plane(m_c->m_clipping_plane_was_moved); - m_c->m_clipping_plane_was_moved = true; - } + float clp_dist = m_c->object_clipper()->get_position(); + if (ImGui::SliderFloat(" ", &clp_dist, 0.f, 1.f, "%.2f")) + m_c->object_clipper()->set_position(clp_dist, true); if (m_imgui->button("?")) { @@ -987,39 +870,32 @@ std::string GLGizmoSlaSupports::on_get_name() const } +CommonGizmosDataID GLGizmoSlaSupports::on_get_requirements() const +{ + return CommonGizmosDataID( + int(CommonGizmosDataID::SelectionInfo) + | int(CommonGizmosDataID::InstancesHider) + | int(CommonGizmosDataID::Raycaster) + | int(CommonGizmosDataID::HollowedMesh) + | int(CommonGizmosDataID::ObjectClipper) + | int(CommonGizmosDataID::SupportsClipper)); +} + + void GLGizmoSlaSupports::on_set_state() { - // m_c->m_model_object pointer can be invalid (for instance because of undo/redo action), - // we should recover it from the object id - m_c->m_model_object = nullptr; - for (const auto mo : wxGetApp().model().objects) { - if (mo->id() == m_c->m_model_object_id) { - m_c->m_model_object = mo; - break; - } - } - if (m_state == m_old_state) return; if (m_state == On && m_old_state != On) { // the gizmo was just turned on - Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); - - m_c->unstash_clipping_plane(); - update_clipping_plane(m_c->m_clipping_plane_was_moved); - - m_c->build_AABB_if_needed(); - - - // we'll now reload support points: - if (m_c->m_model_object) - reload_cache(); - - m_parent.toggle_model_objects_visibility(false); - if (m_c->m_model_object) { - m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(! m_editing_mode, m_c->m_model_object, m_c->m_active_instance); + if (! m_parent.get_gizmos_manager().is_serializing()) { + // Only take the snapshot when the USER opens the gizmo. Common gizmos + // data are not yet available, the CallAfter will postpone taking the + // snapshot until they are. No, it does not feel right. + wxGetApp().CallAfter([this]() { + Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); + }); } // Set default head diameter from config. @@ -1027,7 +903,7 @@ void GLGizmoSlaSupports::on_set_state() m_new_point_head_diameter = static_cast<const ConfigOptionFloat*>(cfg.option("support_head_front_diameter"))->value; } if (m_state == Off && m_old_state != Off) { // the gizmo was just turned Off - bool will_ask = m_c->m_model_object && m_editing_mode && unsaved_changes(); + bool will_ask = m_editing_mode && unsaved_changes(); if (will_ask) { wxGetApp().CallAfter([this]() { // Following is called through CallAfter, because otherwise there was a problem @@ -1046,16 +922,8 @@ void GLGizmoSlaSupports::on_set_state() // we are actually shutting down disable_editing_mode(); // so it is not active next time the gizmo opens Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned off"))); - m_parent.toggle_model_objects_visibility(true); m_normal_cache.clear(); - m_c->stash_clipping_plane(); - m_c->m_clipping_plane_distance = 0.f; - update_clipping_plane(true); - // Release clippers and the AABB raycaster. - m_its = nullptr; - m_c->m_object_clipper.reset(); - m_c->m_supports_clipper.reset(); - //m_c->m_mesh_raycaster.reset(); + m_old_mo_id = -1; } } m_old_state = m_state; @@ -1095,10 +963,7 @@ void GLGizmoSlaSupports::on_stop_dragging() void GLGizmoSlaSupports::on_load(cereal::BinaryInputArchive& ar) { - ar(m_c->m_clipping_plane_distance, - *m_c->m_clipping_plane, - m_c->m_model_object_id, - m_new_point_head_diameter, + ar(m_new_point_head_diameter, m_normal_cache, m_editing_cache, m_selection_empty @@ -1109,10 +974,7 @@ void GLGizmoSlaSupports::on_load(cereal::BinaryInputArchive& ar) void GLGizmoSlaSupports::on_save(cereal::BinaryOutputArchive& ar) const { - ar(m_c->m_clipping_plane_distance, - *m_c->m_clipping_plane, - m_c->m_model_object_id, - m_new_point_head_diameter, + ar(m_new_point_head_diameter, m_normal_cache, m_editing_cache, m_selection_empty @@ -1189,9 +1051,10 @@ void GLGizmoSlaSupports::editing_mode_apply_changes() for (const CacheEntry& ce : m_editing_cache) m_normal_cache.push_back(ce.support_point); - m_c->m_model_object->sla_points_status = sla::PointsStatus::UserModified; - m_c->m_model_object->sla_support_points.clear(); - m_c->m_model_object->sla_support_points = m_normal_cache; + ModelObject* mo = m_c->selection_info()->model_object(); + mo->sla_points_status = sla::PointsStatus::UserModified; + mo->sla_support_points.clear(); + mo->sla_support_points = m_normal_cache; reslice_SLA_supports(); } @@ -1201,23 +1064,25 @@ void GLGizmoSlaSupports::editing_mode_apply_changes() void GLGizmoSlaSupports::reload_cache() { + const ModelObject* mo = m_c->selection_info()->model_object(); m_normal_cache.clear(); - if (m_c->m_model_object->sla_points_status == sla::PointsStatus::AutoGenerated || m_c->m_model_object->sla_points_status == sla::PointsStatus::Generating) + if (mo->sla_points_status == sla::PointsStatus::AutoGenerated || mo->sla_points_status == sla::PointsStatus::Generating) get_data_from_backend(); else - for (const sla::SupportPoint& point : m_c->m_model_object->sla_support_points) + for (const sla::SupportPoint& point : mo->sla_support_points) m_normal_cache.emplace_back(point); } bool GLGizmoSlaSupports::has_backend_supports() const { - if (! m_c->m_model_object) + const ModelObject* mo = m_c->selection_info()->model_object(); + if (! mo) return false; // find SlaPrintObject with this ID for (const SLAPrintObject* po : m_parent.sla_print()->objects()) { - if (po->model_object()->id() == m_c->m_model_object->id()) + if (po->model_object()->id() == mo->id()) return po->is_step_done(slaposSupportPoints); } return false; @@ -1225,24 +1090,28 @@ bool GLGizmoSlaSupports::has_backend_supports() const void GLGizmoSlaSupports::reslice_SLA_supports(bool postpone_error_messages) const { - wxGetApp().CallAfter([this, postpone_error_messages]() { wxGetApp().plater()->reslice_SLA_supports(*m_c->m_model_object, postpone_error_messages); }); + wxGetApp().CallAfter([this, postpone_error_messages]() { + wxGetApp().plater()->reslice_SLA_supports( + *m_c->selection_info()->model_object(), postpone_error_messages); + }); } void GLGizmoSlaSupports::get_data_from_backend() { if (! has_backend_supports()) return; + ModelObject* mo = m_c->selection_info()->model_object(); // find the respective SLAPrintObject, we need a pointer to it for (const SLAPrintObject* po : m_parent.sla_print()->objects()) { - if (po->model_object()->id() == m_c->m_model_object->id()) { + if (po->model_object()->id() == mo->id()) { m_normal_cache.clear(); const std::vector<sla::SupportPoint>& points = po->get_support_points(); auto mat = po->trafo().inverse().cast<float>(); for (unsigned int i=0; i<points.size();++i) m_normal_cache.emplace_back(sla::SupportPoint(mat * points[i].pos, points[i].head_front_radius, points[i].is_new_island)); - m_c->m_model_object->sla_points_status = sla::PointsStatus::AutoGenerated; + mo->sla_points_status = sla::PointsStatus::AutoGenerated; break; } } @@ -1259,10 +1128,12 @@ void GLGizmoSlaSupports::auto_generate() _(L("Are you sure you want to do it?")) + "\n", _(L("Warning")), wxICON_WARNING | wxYES | wxNO); - if (m_c->m_model_object->sla_points_status != sla::PointsStatus::UserModified || m_normal_cache.empty() || dlg.ShowModal() == wxID_YES) { + ModelObject* mo = m_c->selection_info()->model_object(); + + if (mo->sla_points_status != sla::PointsStatus::UserModified || m_normal_cache.empty() || dlg.ShowModal() == wxID_YES) { Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Autogenerate support points"))); wxGetApp().CallAfter([this]() { reslice_SLA_supports(); }); - m_c->m_model_object->sla_points_status = sla::PointsStatus::Generating; + mo->sla_points_status = sla::PointsStatus::Generating; } } @@ -1277,7 +1148,7 @@ void GLGizmoSlaSupports::switch_to_editing_mode() m_editing_cache.emplace_back(sp); select_point(NoPoints); - m_parent.toggle_sla_auxiliaries_visibility(false, m_c->m_model_object, m_c->m_active_instance); + m_c->instances_hider()->show_supports(false); m_parent.set_as_dirty(); } @@ -1287,7 +1158,7 @@ void GLGizmoSlaSupports::disable_editing_mode() if (m_editing_mode) { m_editing_mode = false; wxGetApp().plater()->leave_gizmos_stack(); - m_parent.toggle_sla_auxiliaries_visibility(true, m_c->m_model_object, m_c->m_active_instance); + m_c->instances_hider()->show_supports(true); m_parent.set_as_dirty(); } } @@ -1306,20 +1177,6 @@ bool GLGizmoSlaSupports::unsaved_changes() const return false; } - -void GLGizmoSlaSupports::update_clipping_plane(bool keep_normal) const -{ - if (! m_c->m_model_object) - return; - Vec3d normal = (keep_normal && m_c->m_clipping_plane->get_normal() != Vec3d::Zero() ? - m_c->m_clipping_plane->get_normal() : -m_parent.get_camera().get_dir_forward()); - - const Vec3d& center = m_c->m_model_object->instances[m_c->m_active_instance]->get_offset() + Vec3d(0., 0., m_z_shift); - float dist = normal.dot(center); - *m_c->m_clipping_plane = ClippingPlane(normal, (dist - (-m_c->m_active_instance_bb_radius) - m_c->m_clipping_plane_distance * 2*m_c->m_active_instance_bb_radius)); - m_parent.set_as_dirty(); -} - SlaGizmoHelpDialog::SlaGizmoHelpDialog() : wxDialog(nullptr, wxID_ANY, _(L("SLA gizmo keyboard shortcuts")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) { |