diff --git a/resources/data/printer_gantries/geometries.txt b/resources/data/printer_gantries/geometries.txt index 5362014d63..75777b1603 100644 --- a/resources/data/printer_gantries/geometries.txt +++ b/resources/data/printer_gantries/geometries.txt @@ -38,7 +38,7 @@ }, { "printer_notes_regex": ".*PRINTER_MODEL_MK3.*", - "gantry_model_filename": "prusa3d_mk3_gantry.stl", + "gantry_model_filename": "prusa3d_mk3s_gantry.stl", "slices": [ { "height": "0", diff --git a/resources/data/printer_gantries/prusa3d_coreone_gantry.stl b/resources/data/printer_gantries/prusa3d_coreone_gantry.stl new file mode 100644 index 0000000000..e8e0294078 Binary files /dev/null and b/resources/data/printer_gantries/prusa3d_coreone_gantry.stl differ diff --git a/resources/data/printer_gantries/prusa3d_mini_gantry.stl b/resources/data/printer_gantries/prusa3d_mini_gantry.stl new file mode 100644 index 0000000000..1bf9cf1baf Binary files /dev/null and b/resources/data/printer_gantries/prusa3d_mini_gantry.stl differ diff --git a/resources/data/printer_gantries/prusa3d_mk3s_gantry.stl b/resources/data/printer_gantries/prusa3d_mk3s_gantry.stl new file mode 100644 index 0000000000..17aa91057c Binary files /dev/null and b/resources/data/printer_gantries/prusa3d_mk3s_gantry.stl differ diff --git a/resources/data/printer_gantries/prusa3d_mk4_gantry.stl b/resources/data/printer_gantries/prusa3d_mk4_gantry.stl new file mode 100644 index 0000000000..48c8b98dda Binary files /dev/null and b/resources/data/printer_gantries/prusa3d_mk4_gantry.stl differ diff --git a/resources/data/printer_gantries/prusa3d_xl_gantry.stl b/resources/data/printer_gantries/prusa3d_xl_gantry.stl new file mode 100644 index 0000000000..0fb888d4e5 Binary files /dev/null and b/resources/data/printer_gantries/prusa3d_xl_gantry.stl differ diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index e61360c777..f39b9c332b 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -217,9 +217,20 @@ int GCodeViewer::SequentialView::ActualSpeedImguiWidget::plot(const char* label, } #endif // ENABLE_ACTUAL_SPEED_DEBUG -void GCodeViewer::SequentialView::Marker::init() +void GCodeViewer::SequentialView::Marker::init(std::optional>& model_opt) { - m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f)); + if (! model_opt.has_value()) + return; + + m_model.reset(); + + m_generic_marker = (model_opt->get() == nullptr); + if (m_generic_marker) + m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f)); + else + m_model = **model_opt; + model_opt.reset(); + m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); } @@ -245,9 +256,11 @@ void GCodeViewer::SequentialView::Marker::render() float scale_factor = m_scale_factor; if (m_fixed_screen_size) scale_factor *= 10.0f * camera.get_inv_zoom(); - const Transform3d model_matrix = (Geometry::translation_transform((m_world_position + m_model_z_offset * Vec3f::UnitZ()).cast()) * - Geometry::translation_transform(scale_factor * m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })) * - Geometry::scale_transform(scale_factor); + const Transform3d model_matrix = m_generic_marker + ? (Geometry::translation_transform((m_world_position + m_model_z_offset * Vec3f::UnitZ()).cast()) * + Geometry::translation_transform(scale_factor * m_model.get_bounding_box().size().z() * Vec3d::UnitZ()) * Geometry::rotation_transform({ M_PI, 0.0, 0.0 })) * + Geometry::scale_transform(scale_factor) + : Geometry::translation_transform(m_world_position.cast()); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); @@ -842,9 +855,6 @@ void GCodeViewer::init() if (m_gl_data_initialized) return; - // initializes tool marker - m_sequential_view.marker.init(); - m_gl_data_initialized = true; try @@ -1166,6 +1176,11 @@ void GCodeViewer::render() const libvgcode::PathVertex& curr_vertex = m_viewer.get_current_vertex(); m_sequential_view.marker.set_world_position(libvgcode::convert(curr_vertex.position)); m_sequential_view.marker.set_z_offset(m_z_offset); + + // Following just makes sure that the shown marker is correct. + auto marker_model_opt = wxGetApp().plater()->get_current_canvas3D()->get_current_marker_model(); + m_sequential_view.marker.init(marker_model_opt); + m_sequential_view.render(legend_height, &m_viewer, curr_vertex.gcode_id); } } diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 21ca5b81ba..c760120274 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -127,12 +127,13 @@ public: bool m_visible{ true }; bool m_fixed_screen_size{ false }; float m_scale_factor{ 1.0f }; + bool m_generic_marker{ true }; #if ENABLE_ACTUAL_SPEED_DEBUG ActualSpeedImguiWidget m_actual_speed_imgui_widget; #endif // ENABLE_ACTUAL_SPEED_DEBUG public: - void init(); + void init(std::optional>& model_opt); const BoundingBoxf3& get_bounding_box() const { return m_model.get_bounding_box(); } diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index a81687918a..b20632417b 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -77,6 +77,7 @@ #include #include #include +#include #include #include @@ -154,6 +155,68 @@ void GLCanvas3D::select_bed(int i, bool triggered_by_user) }); } +// Returns extruder model to visualize in the GCodeViewer: +// - nullopt = same as before +// - nullptr = none available, use generic +// - GLModel = the model to use +std::optional> GLCanvas3D::get_current_marker_model() const +{ + std::optional> out; + + static std::string last_printer_notes; + static double old_r = 0.; + static double old_h = 0.; + static bool old_seq = false; + + std::string printer_notes = m_config->opt_string("printer_notes"); + double r = m_config->opt_float("extruder_clearance_radius"); + double h = m_config->opt_float("extruder_clearance_height"); + bool seq = m_config->opt_bool("complete_objects"); + + if (last_printer_notes != printer_notes || r != old_r || h != old_h || seq != old_seq) { + out = std::make_optional(nullptr); + if (! seq) + return out; + try { + std::ifstream in(resources_dir() + "/data/printer_gantries/geometries.txt"); + boost::property_tree::ptree pt; + boost::property_tree::read_json(in, pt); + for (const auto& printer : pt.get_child("printers")) { + std::string printer_notes_match = printer.second.get("printer_notes_regex"); + boost::regex rgx(printer_notes_match); + if (boost::regex_match(printer_notes, rgx)) { + std::string filename = resources_dir() + "/data/printer_gantries/" + printer.second.get("gantry_model_filename"); + if (boost::filesystem::exists(filename)) { + std::unique_ptr m = std::make_unique(); + if (m->init_from_file(filename)) + out = std::make_optional(std::move(m)); + } + break; + } + } + } catch (...) { + // Whatever happened, ignore it. We will return nullptr. + } + if (*out == nullptr && seq) { + // Generic sequential extruder model. + double gantry_height = 10; + auto mesh = its_make_cylinder(r, h + gantry_height - 0.001); + double d = 3 * wxGetApp().plater()->build_volume().bounding_volume2d().size().x(); + auto mesh2 = its_make_cube(d,2*r, gantry_height); + its_translate(mesh2, Vec3f(-d/2, -r, h)); + its_merge(mesh, mesh2); + std::unique_ptr m = std::make_unique(); + m->init_from(mesh); + out = std::make_optional(std::move(m)); + } + last_printer_notes = printer_notes; + old_r = r; + old_h = h; + old_seq = seq; + } + return out; +} + #ifdef __WXGTK3__ // wxGTK3 seems to simulate OSX behavior in regard to HiDPI scaling support. RetinaHelper::RetinaHelper(wxWindow* window) : m_window(window), m_self(nullptr) {} diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 037637878d..72bf091bda 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -756,6 +756,8 @@ public: const libvgcode::Interval& get_gcode_view_visible_range() const { return m_gcode_viewer.get_gcode_view_visible_range(); } const libvgcode::PathVertex& get_gcode_vertex_at(size_t id) const { return m_gcode_viewer.get_gcode_vertex_at(id); } + std::optional> get_current_marker_model() const; + void toggle_sla_auxiliaries_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1); void toggle_model_objects_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1, const ModelVolume* mv = nullptr); void update_instance_printable_state_for_object(size_t obj_idx);