From 051fcd4e2459cb23df9e99e4b8465c9e6bee5402 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 9 Jan 2020 10:27:42 +0100 Subject: [PATCH] Configurable system printers bed textures and models --- resources/profiles/Creality.ini | 2 + .../bed => profiles/Creality}/ender3.svg | 0 .../Creality}/ender3_bed.stl | Bin resources/profiles/PrusaResearch.ini | 24 ++++ .../bed => profiles/PrusaResearch}/mini.svg | 0 .../PrusaResearch}/mini_bed.stl | Bin .../bed => profiles/PrusaResearch}/mk2.svg | 0 .../PrusaResearch}/mk2_bed.stl | Bin .../bed => profiles/PrusaResearch}/mk3.svg | 0 .../PrusaResearch}/mk3_bed.stl | Bin .../bed => profiles/PrusaResearch}/sl1.svg | 0 .../PrusaResearch}/sl1_bed.stl | Bin src/slic3r/GUI/3DBed.cpp | 129 +++++++----------- src/slic3r/GUI/3DBed.hpp | 23 ++-- 14 files changed, 83 insertions(+), 95 deletions(-) rename resources/{icons/bed => profiles/Creality}/ender3.svg (100%) rename resources/{models => profiles/Creality}/ender3_bed.stl (100%) rename resources/{icons/bed => profiles/PrusaResearch}/mini.svg (100%) rename resources/{models => profiles/PrusaResearch}/mini_bed.stl (100%) rename resources/{icons/bed => profiles/PrusaResearch}/mk2.svg (100%) rename resources/{models => profiles/PrusaResearch}/mk2_bed.stl (100%) rename resources/{icons/bed => profiles/PrusaResearch}/mk3.svg (100%) rename resources/{models => profiles/PrusaResearch}/mk3_bed.stl (100%) rename resources/{icons/bed => profiles/PrusaResearch}/sl1.svg (100%) rename resources/{models => profiles/PrusaResearch}/sl1_bed.stl (100%) diff --git a/resources/profiles/Creality.ini b/resources/profiles/Creality.ini index 4ebf99d32..e9cac0e82 100644 --- a/resources/profiles/Creality.ini +++ b/resources/profiles/Creality.ini @@ -18,6 +18,8 @@ config_update_url = http://files.prusa3d.com/wp-content/uploads/repository/Prusa name = Creality Ender-3 variants = 0.4 technology = FFF +bed_model = ender3_bed.stl +bed_texture = ender3.svg # All presets starting with asterisk, for example *common*, are intermediate and they will # not make it into the user interface. diff --git a/resources/icons/bed/ender3.svg b/resources/profiles/Creality/ender3.svg similarity index 100% rename from resources/icons/bed/ender3.svg rename to resources/profiles/Creality/ender3.svg diff --git a/resources/models/ender3_bed.stl b/resources/profiles/Creality/ender3_bed.stl similarity index 100% rename from resources/models/ender3_bed.stl rename to resources/profiles/Creality/ender3_bed.stl diff --git a/resources/profiles/PrusaResearch.ini b/resources/profiles/PrusaResearch.ini index 746aaf966..96b4369c5 100644 --- a/resources/profiles/PrusaResearch.ini +++ b/resources/profiles/PrusaResearch.ini @@ -22,72 +22,96 @@ name = Original Prusa MINI variants = 0.4; 0.25; 0.6 technology = FFF family = MINI +bed_model = mini_bed.stl +bed_texture = mini.svg [printer_model:MK3S] name = Original Prusa i3 MK3S variants = 0.4; 0.25; 0.6 technology = FFF family = MK3 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK3] name = Original Prusa i3 MK3 variants = 0.4; 0.25; 0.6 technology = FFF family = MK3 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK3SMMU2S] name = Original Prusa i3 MK3S MMU2S variants = 0.4; 0.25; 0.6 technology = FFF family = MK3 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK3MMU2] name = Original Prusa i3 MK3 MMU2 variants = 0.4; 0.25; 0.6 technology = FFF family = MK3 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK2.5S] name = Original Prusa i3 MK2.5S variants = 0.4; 0.25; 0.6 technology = FFF family = MK2.5 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK2.5] name = Original Prusa i3 MK2.5 variants = 0.4; 0.25; 0.6 technology = FFF family = MK2.5 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK2.5SMMU2S] name = Original Prusa i3 MK2.5S MMU2S variants = 0.4; 0.25; 0.6 technology = FFF family = MK2.5 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK2.5MMU2] name = Original Prusa i3 MK2.5 MMU2 variants = 0.4; 0.25; 0.6 technology = FFF family = MK2.5 +bed_model = mk3_bed.stl +bed_texture = mk3.svg [printer_model:MK2S] name = Original Prusa i3 MK2S variants = 0.4; 0.25; 0.6 technology = FFF family = MK2 +bed_model = mk2_bed.stl +bed_texture = mk2.svg [printer_model:MK2SMM] name = Original Prusa i3 MK2S MMU1 variants = 0.4; 0.6 technology = FFF family = MK2 +bed_model = mk2_bed.stl +bed_texture = mk2.svg [printer_model:SL1] name = Original Prusa SL1 variants = default technology = SLA family = SL1 +bed_model = sl1_bed.stl +bed_texture = sl1.svg # All presets starting with asterisk, for example *common*, are intermediate and they will # not make it into the user interface. diff --git a/resources/icons/bed/mini.svg b/resources/profiles/PrusaResearch/mini.svg similarity index 100% rename from resources/icons/bed/mini.svg rename to resources/profiles/PrusaResearch/mini.svg diff --git a/resources/models/mini_bed.stl b/resources/profiles/PrusaResearch/mini_bed.stl similarity index 100% rename from resources/models/mini_bed.stl rename to resources/profiles/PrusaResearch/mini_bed.stl diff --git a/resources/icons/bed/mk2.svg b/resources/profiles/PrusaResearch/mk2.svg similarity index 100% rename from resources/icons/bed/mk2.svg rename to resources/profiles/PrusaResearch/mk2.svg diff --git a/resources/models/mk2_bed.stl b/resources/profiles/PrusaResearch/mk2_bed.stl similarity index 100% rename from resources/models/mk2_bed.stl rename to resources/profiles/PrusaResearch/mk2_bed.stl diff --git a/resources/icons/bed/mk3.svg b/resources/profiles/PrusaResearch/mk3.svg similarity index 100% rename from resources/icons/bed/mk3.svg rename to resources/profiles/PrusaResearch/mk3.svg diff --git a/resources/models/mk3_bed.stl b/resources/profiles/PrusaResearch/mk3_bed.stl similarity index 100% rename from resources/models/mk3_bed.stl rename to resources/profiles/PrusaResearch/mk3_bed.stl diff --git a/resources/icons/bed/sl1.svg b/resources/profiles/PrusaResearch/sl1.svg similarity index 100% rename from resources/icons/bed/sl1.svg rename to resources/profiles/PrusaResearch/sl1.svg diff --git a/resources/models/sl1_bed.stl b/resources/profiles/PrusaResearch/sl1_bed.stl similarity index 100% rename from resources/models/sl1_bed.stl rename to resources/profiles/PrusaResearch/sl1_bed.stl diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index ecbca4228..9e32df783 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -189,8 +189,6 @@ void Bed3D::Axes::render_axis(double length) const Bed3D::Bed3D() : m_type(Custom) - , m_custom_texture("") - , m_custom_model("") , m_vbo_id(0) , m_scale_factor(1.0f) { @@ -198,31 +196,31 @@ Bed3D::Bed3D() bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model) { - EType new_type = detect_type(shape); + auto check_texture = [](const std::string& texture) { + return !texture.empty() && (boost::algorithm::iends_with(texture, ".png") || boost::algorithm::iends_with(texture, ".svg")) && boost::filesystem::exists(texture); + }; - // check that the passed custom texture filename is valid - std::string cst_texture(custom_texture); - if (!cst_texture.empty()) - { - if ((!boost::algorithm::iends_with(custom_texture, ".png") && !boost::algorithm::iends_with(custom_texture, ".svg")) || !boost::filesystem::exists(custom_texture)) - cst_texture = ""; - } + auto check_model = [](const std::string& model) { + return !model.empty() && boost::algorithm::iends_with(model, ".stl") && boost::filesystem::exists(model); + }; - // check that the passed custom texture filename is valid - std::string cst_model(custom_model); - if (!cst_model.empty()) - { - if (!boost::algorithm::iends_with(custom_model, ".stl") || !boost::filesystem::exists(custom_model)) - cst_model = ""; - } + auto [new_type, system_model, system_texture] = detect_type(shape); - if ((m_shape == shape) && (m_type == new_type) && (m_custom_texture == cst_texture) && (m_custom_model == cst_model)) + std::string texture_filename = custom_texture.empty() ? system_texture : custom_texture; + if (!check_texture(texture_filename)) + texture_filename.clear(); + + std::string model_filename = custom_model.empty() ? system_model : custom_model; + if (!check_model(model_filename)) + model_filename.clear(); + + if ((m_shape == shape) && (m_type == new_type) && (m_texture_filename == texture_filename) && (m_model_filename == model_filename)) // No change, no need to update the UI. return false; m_shape = shape; - m_custom_texture = cst_texture; - m_custom_model = cst_model; + m_texture_filename = texture_filename; + m_model_filename = model_filename; m_type = new_type; calc_bounding_boxes(); @@ -244,7 +242,7 @@ bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, c m_texture.reset(); m_model.reset(); - // Set the origin and size for painting of the coordinate system axes. + // Set the origin and size for rendering the coordinate system axes. m_axes.origin = Vec3d(0.0, 0.0, (double)GROUND_Z); m_axes.length = 0.1 * m_bounding_box.max_size() * Vec3d::Ones(); @@ -273,11 +271,7 @@ void Bed3D::render(GLCanvas3D& canvas, float theta, float scale_factor, bool sho switch (m_type) { - case MK2: { render_prusa(canvas, "mk2", theta > 90.0f); break; } - case MK3: { render_prusa(canvas, "mk3", theta > 90.0f); break; } - case SL1: { render_prusa(canvas, "sl1", theta > 90.0f); break; } - case MINI: { render_prusa(canvas, "mini", theta > 90.0f); break; } - case ENDER3: { render_prusa(canvas, "ender3", theta > 90.0f); break; } + case System: { render_system(canvas, theta > 90.0f); break; } default: case Custom: { render_custom(canvas, theta > 90.0f); break; } } @@ -373,10 +367,8 @@ static std::string system_print_bed_texture(const Preset &preset) return out; } -Bed3D::EType Bed3D::detect_type(const Pointfs& shape) const +std::tuple Bed3D::detect_type(const Pointfs& shape) const { - EType type = Custom; - auto bundle = wxGetApp().preset_bundle; if (bundle != nullptr) { @@ -385,39 +377,12 @@ Bed3D::EType Bed3D::detect_type(const Pointfs& shape) const { if (curr->config.has("bed_shape")) { - if (curr->vendor != nullptr) + if (shape == dynamic_cast(curr->config.option("bed_shape"))->values) { - if ((curr->vendor->name == "Prusa Research") && (shape == dynamic_cast(curr->config.option("bed_shape"))->values)) - { - if (boost::contains(curr->name, "SL1")) - { - type = SL1; - break; - } - else if (boost::contains(curr->name, "MK3") || boost::contains(curr->name, "MK2.5")) - { - type = MK3; - break; - } - else if (boost::contains(curr->name, "MK2")) - { - type = MK2; - break; - } - else if (boost::contains(curr->name, "MINI")) - { - type = MINI; - break; - } - } - else if ((curr->vendor->name == "Creality") && (shape == dynamic_cast(curr->config.option("bed_shape"))->values)) - { - if (boost::contains(curr->name, "ENDER-3")) - { - type = ENDER3; - break; - } - } + std::string model_filename = system_print_bed_model(*curr); + std::string texture_filename = system_print_bed_texture(*curr); + if (!model_filename.empty() && !texture_filename.empty()) + return std::make_tuple(System, model_filename, texture_filename); } } @@ -425,7 +390,7 @@ Bed3D::EType Bed3D::detect_type(const Pointfs& shape) const } } - return type; + return std::make_tuple(Custom, "", ""); } void Bed3D::render_axes() const @@ -434,35 +399,35 @@ void Bed3D::render_axes() const m_axes.render(); } -void Bed3D::render_prusa(GLCanvas3D& canvas, const std::string& key, bool bottom) const +void Bed3D::render_system(GLCanvas3D& canvas, bool bottom) const { if (!bottom) - render_model(m_custom_model.empty() ? resources_dir() + "/models/" + key + "_bed.stl" : m_custom_model); + render_model(); - render_texture(m_custom_texture.empty() ? resources_dir() + "/icons/bed/" + key + ".svg" : m_custom_texture, bottom, canvas); + render_texture(bottom, canvas); } -void Bed3D::render_texture(const std::string& filename, bool bottom, GLCanvas3D& canvas) const +void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) const { - if (filename.empty()) + if (m_texture_filename.empty()) { m_texture.reset(); render_default(bottom); return; } - if ((m_texture.get_id() == 0) || (m_texture.get_source() != filename)) + if ((m_texture.get_id() == 0) || (m_texture.get_source() != m_texture_filename)) { m_texture.reset(); - if (boost::algorithm::iends_with(filename, ".svg")) + if (boost::algorithm::iends_with(m_texture_filename, ".svg")) { // use higher resolution images if graphic card and opengl version allow GLint max_tex_size = GLCanvas3DManager::get_gl_info().get_max_tex_size(); - if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != filename)) + if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != m_texture_filename)) { // generate a temporary lower resolution texture to show while no main texture levels have been compressed - if (!m_temp_texture.load_from_svg_file(filename, false, false, false, max_tex_size / 8)) + if (!m_temp_texture.load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { render_default(bottom); return; @@ -471,18 +436,18 @@ void Bed3D::render_texture(const std::string& filename, bool bottom, GLCanvas3D& } // starts generating the main texture, compression will run asynchronously - if (!m_texture.load_from_svg_file(filename, true, true, true, max_tex_size)) + if (!m_texture.load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) { render_default(bottom); return; } } - else if (boost::algorithm::iends_with(filename, ".png")) + else if (boost::algorithm::iends_with(m_texture_filename, ".png")) { // generate a temporary lower resolution texture to show while no main texture levels have been compressed - if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != filename)) + if ((m_temp_texture.get_id() == 0) || (m_temp_texture.get_source() != m_texture_filename)) { - if (!m_temp_texture.load_from_file(filename, false, GLTexture::None, false)) + if (!m_temp_texture.load_from_file(m_texture_filename, false, GLTexture::None, false)) { render_default(bottom); return; @@ -491,7 +456,7 @@ void Bed3D::render_texture(const std::string& filename, bool bottom, GLCanvas3D& } // starts generating the main texture, compression will run asynchronously - if (!m_texture.load_from_file(filename, true, GLTexture::MultiThreaded, true)) + if (!m_texture.load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) { render_default(bottom); return; @@ -590,12 +555,12 @@ void Bed3D::render_texture(const std::string& filename, bool bottom, GLCanvas3D& } } -void Bed3D::render_model(const std::string& filename) const +void Bed3D::render_model() const { - if (filename.empty()) + if (m_model_filename.empty()) return; - if ((m_model.get_filename() != filename) && m_model.init_from_file(filename)) + if ((m_model.get_filename() != m_model_filename) && m_model.init_from_file(m_model_filename)) { // move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad Vec3d shift = m_bounding_box.center(); @@ -616,16 +581,16 @@ void Bed3D::render_model(const std::string& filename) const void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom) const { - if (m_custom_texture.empty() && m_custom_model.empty()) + if (m_texture_filename.empty() && m_model_filename.empty()) { render_default(bottom); return; } if (!bottom) - render_model(m_custom_model); + render_model(); - render_texture(m_custom_texture, bottom, canvas); + render_texture(bottom, canvas); } void Bed3D::render_default(bool bottom) const diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index cd2de862e..b1640000d 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -5,6 +5,8 @@ #include "3DScene.hpp" #include "GLShader.hpp" +#include + class GLUquadric; typedef class GLUquadric GLUquadricObj; @@ -64,11 +66,7 @@ class Bed3D public: enum EType : unsigned char { - MK2, - MK3, - SL1, - MINI, - ENDER3, + System, Custom, Num_Types }; @@ -76,19 +74,19 @@ public: private: EType m_type; Pointfs m_shape; - std::string m_custom_texture; - std::string m_custom_model; + std::string m_texture_filename; + std::string m_model_filename; mutable BoundingBoxf3 m_bounding_box; mutable BoundingBoxf3 m_extended_bounding_box; Polygon m_polygon; GeometryBuffer m_triangles; GeometryBuffer m_gridlines; mutable GLTexture m_texture; + mutable GLBed m_model; // temporary texture shown until the main texture has still no levels compressed mutable GLTexture m_temp_texture; mutable Shader m_shader; mutable unsigned int m_vbo_id; - mutable GLBed m_model; Axes m_axes; mutable float m_scale_factor; @@ -99,7 +97,6 @@ public: EType get_type() const { return m_type; } - bool is_prusa() const { return (m_type == MK2) || (m_type == MK3) || (m_type == SL1); } bool is_custom() const { return m_type == Custom; } const Pointfs& get_shape() const { return m_shape; } @@ -116,11 +113,11 @@ private: void calc_bounding_boxes() const; void calc_triangles(const ExPolygon& poly); void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); - EType detect_type(const Pointfs& shape) const; + std::tuple detect_type(const Pointfs& shape) const; void render_axes() const; - void render_prusa(GLCanvas3D& canvas, const std::string& key, bool bottom) const; - void render_texture(const std::string& filename, bool bottom, GLCanvas3D& canvas) const; - void render_model(const std::string& filename) const; + void render_system(GLCanvas3D& canvas, bool bottom) const; + void render_texture(bool bottom, GLCanvas3D& canvas) const; + void render_model() const; void render_custom(GLCanvas3D& canvas, bool bottom) const; void render_default(bool bottom) const; void reset();