Configurable system printers bed textures and models

This commit is contained in:
Enrico Turri 2020-01-09 10:27:42 +01:00
parent 0aaa7dd076
commit 051fcd4e24
14 changed files with 83 additions and 95 deletions

View file

@ -18,6 +18,8 @@ config_update_url = http://files.prusa3d.com/wp-content/uploads/repository/Prusa
name = Creality Ender-3 name = Creality Ender-3
variants = 0.4 variants = 0.4
technology = FFF technology = FFF
bed_model = ender3_bed.stl
bed_texture = ender3.svg
# All presets starting with asterisk, for example *common*, are intermediate and they will # All presets starting with asterisk, for example *common*, are intermediate and they will
# not make it into the user interface. # not make it into the user interface.

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -22,72 +22,96 @@ name = Original Prusa MINI
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MINI family = MINI
bed_model = mini_bed.stl
bed_texture = mini.svg
[printer_model:MK3S] [printer_model:MK3S]
name = Original Prusa i3 MK3S name = Original Prusa i3 MK3S
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK3 family = MK3
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK3] [printer_model:MK3]
name = Original Prusa i3 MK3 name = Original Prusa i3 MK3
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK3 family = MK3
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK3SMMU2S] [printer_model:MK3SMMU2S]
name = Original Prusa i3 MK3S MMU2S name = Original Prusa i3 MK3S MMU2S
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK3 family = MK3
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK3MMU2] [printer_model:MK3MMU2]
name = Original Prusa i3 MK3 MMU2 name = Original Prusa i3 MK3 MMU2
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK3 family = MK3
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK2.5S] [printer_model:MK2.5S]
name = Original Prusa i3 MK2.5S name = Original Prusa i3 MK2.5S
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK2.5 family = MK2.5
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK2.5] [printer_model:MK2.5]
name = Original Prusa i3 MK2.5 name = Original Prusa i3 MK2.5
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK2.5 family = MK2.5
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK2.5SMMU2S] [printer_model:MK2.5SMMU2S]
name = Original Prusa i3 MK2.5S MMU2S name = Original Prusa i3 MK2.5S MMU2S
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK2.5 family = MK2.5
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK2.5MMU2] [printer_model:MK2.5MMU2]
name = Original Prusa i3 MK2.5 MMU2 name = Original Prusa i3 MK2.5 MMU2
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK2.5 family = MK2.5
bed_model = mk3_bed.stl
bed_texture = mk3.svg
[printer_model:MK2S] [printer_model:MK2S]
name = Original Prusa i3 MK2S name = Original Prusa i3 MK2S
variants = 0.4; 0.25; 0.6 variants = 0.4; 0.25; 0.6
technology = FFF technology = FFF
family = MK2 family = MK2
bed_model = mk2_bed.stl
bed_texture = mk2.svg
[printer_model:MK2SMM] [printer_model:MK2SMM]
name = Original Prusa i3 MK2S MMU1 name = Original Prusa i3 MK2S MMU1
variants = 0.4; 0.6 variants = 0.4; 0.6
technology = FFF technology = FFF
family = MK2 family = MK2
bed_model = mk2_bed.stl
bed_texture = mk2.svg
[printer_model:SL1] [printer_model:SL1]
name = Original Prusa SL1 name = Original Prusa SL1
variants = default variants = default
technology = SLA technology = SLA
family = SL1 family = SL1
bed_model = sl1_bed.stl
bed_texture = sl1.svg
# All presets starting with asterisk, for example *common*, are intermediate and they will # All presets starting with asterisk, for example *common*, are intermediate and they will
# not make it into the user interface. # not make it into the user interface.

View file

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View file

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View file

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View file

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View file

@ -189,8 +189,6 @@ void Bed3D::Axes::render_axis(double length) const
Bed3D::Bed3D() Bed3D::Bed3D()
: m_type(Custom) : m_type(Custom)
, m_custom_texture("")
, m_custom_model("")
, m_vbo_id(0) , m_vbo_id(0)
, m_scale_factor(1.0f) , 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) 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 auto check_model = [](const std::string& model) {
std::string cst_texture(custom_texture); return !model.empty() && boost::algorithm::iends_with(model, ".stl") && boost::filesystem::exists(model);
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 = "";
}
// check that the passed custom texture filename is valid auto [new_type, system_model, system_texture] = detect_type(shape);
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 = "";
}
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. // No change, no need to update the UI.
return false; return false;
m_shape = shape; m_shape = shape;
m_custom_texture = cst_texture; m_texture_filename = texture_filename;
m_custom_model = cst_model; m_model_filename = model_filename;
m_type = new_type; m_type = new_type;
calc_bounding_boxes(); calc_bounding_boxes();
@ -244,7 +242,7 @@ bool Bed3D::set_shape(const Pointfs& shape, const std::string& custom_texture, c
m_texture.reset(); m_texture.reset();
m_model.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.origin = Vec3d(0.0, 0.0, (double)GROUND_Z);
m_axes.length = 0.1 * m_bounding_box.max_size() * Vec3d::Ones(); 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) switch (m_type)
{ {
case MK2: { render_prusa(canvas, "mk2", theta > 90.0f); break; } case System: { render_system(canvas, 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; }
default: default:
case Custom: { render_custom(canvas, theta > 90.0f); break; } 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; return out;
} }
Bed3D::EType Bed3D::detect_type(const Pointfs& shape) const std::tuple<Bed3D::EType, std::string, std::string> Bed3D::detect_type(const Pointfs& shape) const
{ {
EType type = Custom;
auto bundle = wxGetApp().preset_bundle; auto bundle = wxGetApp().preset_bundle;
if (bundle != nullptr) if (bundle != nullptr)
{ {
@ -385,39 +377,12 @@ Bed3D::EType Bed3D::detect_type(const Pointfs& shape) const
{ {
if (curr->config.has("bed_shape")) if (curr->config.has("bed_shape"))
{ {
if (curr->vendor != nullptr) if (shape == dynamic_cast<const ConfigOptionPoints*>(curr->config.option("bed_shape"))->values)
{ {
if ((curr->vendor->name == "Prusa Research") && (shape == dynamic_cast<const ConfigOptionPoints*>(curr->config.option("bed_shape"))->values)) std::string model_filename = system_print_bed_model(*curr);
{ std::string texture_filename = system_print_bed_texture(*curr);
if (boost::contains(curr->name, "SL1")) if (!model_filename.empty() && !texture_filename.empty())
{ return std::make_tuple(System, model_filename, texture_filename);
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<const ConfigOptionPoints*>(curr->config.option("bed_shape"))->values))
{
if (boost::contains(curr->name, "ENDER-3"))
{
type = ENDER3;
break;
}
}
} }
} }
@ -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 void Bed3D::render_axes() const
@ -434,35 +399,35 @@ void Bed3D::render_axes() const
m_axes.render(); 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) 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(); m_texture.reset();
render_default(bottom); render_default(bottom);
return; 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(); 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 // use higher resolution images if graphic card and opengl version allow
GLint max_tex_size = GLCanvas3DManager::get_gl_info().get_max_tex_size(); 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 // 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); render_default(bottom);
return; 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 // 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); render_default(bottom);
return; 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 // 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); render_default(bottom);
return; 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 // 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); render_default(bottom);
return; 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; 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 // 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(); 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 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); render_default(bottom);
return; return;
} }
if (!bottom) 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 void Bed3D::render_default(bool bottom) const

View file

@ -5,6 +5,8 @@
#include "3DScene.hpp" #include "3DScene.hpp"
#include "GLShader.hpp" #include "GLShader.hpp"
#include <tuple>
class GLUquadric; class GLUquadric;
typedef class GLUquadric GLUquadricObj; typedef class GLUquadric GLUquadricObj;
@ -64,11 +66,7 @@ class Bed3D
public: public:
enum EType : unsigned char enum EType : unsigned char
{ {
MK2, System,
MK3,
SL1,
MINI,
ENDER3,
Custom, Custom,
Num_Types Num_Types
}; };
@ -76,19 +74,19 @@ public:
private: private:
EType m_type; EType m_type;
Pointfs m_shape; Pointfs m_shape;
std::string m_custom_texture; std::string m_texture_filename;
std::string m_custom_model; std::string m_model_filename;
mutable BoundingBoxf3 m_bounding_box; mutable BoundingBoxf3 m_bounding_box;
mutable BoundingBoxf3 m_extended_bounding_box; mutable BoundingBoxf3 m_extended_bounding_box;
Polygon m_polygon; Polygon m_polygon;
GeometryBuffer m_triangles; GeometryBuffer m_triangles;
GeometryBuffer m_gridlines; GeometryBuffer m_gridlines;
mutable GLTexture m_texture; mutable GLTexture m_texture;
mutable GLBed m_model;
// temporary texture shown until the main texture has still no levels compressed // temporary texture shown until the main texture has still no levels compressed
mutable GLTexture m_temp_texture; mutable GLTexture m_temp_texture;
mutable Shader m_shader; mutable Shader m_shader;
mutable unsigned int m_vbo_id; mutable unsigned int m_vbo_id;
mutable GLBed m_model;
Axes m_axes; Axes m_axes;
mutable float m_scale_factor; mutable float m_scale_factor;
@ -99,7 +97,6 @@ public:
EType get_type() const { return m_type; } 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; } bool is_custom() const { return m_type == Custom; }
const Pointfs& get_shape() const { return m_shape; } const Pointfs& get_shape() const { return m_shape; }
@ -116,11 +113,11 @@ private:
void calc_bounding_boxes() const; void calc_bounding_boxes() const;
void calc_triangles(const ExPolygon& poly); void calc_triangles(const ExPolygon& poly);
void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
EType detect_type(const Pointfs& shape) const; std::tuple<EType, std::string, std::string> detect_type(const Pointfs& shape) const;
void render_axes() const; void render_axes() const;
void render_prusa(GLCanvas3D& canvas, const std::string& key, bool bottom) const; void render_system(GLCanvas3D& canvas, bool bottom) const;
void render_texture(const std::string& filename, bool bottom, GLCanvas3D& canvas) const; void render_texture(bool bottom, GLCanvas3D& canvas) const;
void render_model(const std::string& filename) const; void render_model() const;
void render_custom(GLCanvas3D& canvas, bool bottom) const; void render_custom(GLCanvas3D& canvas, bool bottom) const;
void render_default(bool bottom) const; void render_default(bool bottom) const;
void reset(); void reset();