Skip to content

Commit

Permalink
bugfix wip custom print png
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Feb 4, 2019
1 parent 3cb8a61 commit e2fd5f7
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 94 deletions.
9 changes: 5 additions & 4 deletions src/slic3r/GUI/ConfigWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ PageWelcome::PageWelcome(ConfigWizard *parent, bool check_first_variant) :

const size_t num_other_vendors = vendors.size() - (vendor_prusa != vendors.cend());
auto *sizer = new wxBoxSizer(wxHORIZONTAL);
auto *other_vendors = new wxButton(others_buttons, wxID_ANY, _(L("Other vendors")));
auto *other_vendors = new wxButton(others_buttons, wxID_ANY, _(L("Presets printers")));
other_vendors->Enable(num_other_vendors > 0);
auto *custom_setup = new wxButton(others_buttons, wxID_ANY, _(L("Custom setup")));

Expand Down Expand Up @@ -321,7 +321,7 @@ PageUpdate::PageUpdate(ConfigWizard *parent) :
PageVendors::PageVendors(ConfigWizard *parent) :
ConfigWizardPage(parent, _(L("Other Vendors")), _(L("Other Vendors")))
{
append_text(_(L("Pick another vendor supported by Slic3r PE:")));
append_text(_(L("Pick another vendor supported by Slic3r++:")));

auto boldfont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
boldfont.SetWeight(wxFONTWEIGHT_BOLD);
Expand Down Expand Up @@ -355,7 +355,7 @@ PageVendors::PageVendors(ConfigWizard *parent) :
});

append(vendor_picker);
for (PrinterPicker *picker : pickers) { this->append(picker); }
for (PrinterPicker *picker : pickers) { this->append(picker); }
}

void PageVendors::on_page_set()
Expand Down Expand Up @@ -722,7 +722,8 @@ void ConfigWizard::priv::set_page(ConfigWizardPage *page)
void ConfigWizard::priv::layout_fit()
{
q->Layout();
q->Fit();
q->Fit();
q->SetSize(wxRect(0, 0, 1200, 700));
}

void ConfigWizard::priv::enable_next(bool enable)
Expand Down
164 changes: 76 additions & 88 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ void GLCanvas3D::Bed::render(float theta, bool useVBOs, float scale_factor) cons
{
_render_prusa("sl1", theta, useVBOs);
}
else if (m_type == "MK2")
else
{
_render_custom(m_type, theta, useVBOs);
}
Expand All @@ -448,7 +448,7 @@ void GLCanvas3D::Bed::render(float theta, float scale_factor) const
}
else if (m_type == "MK2")
{
_render_custom(m_type, theta);
_render_default(m_type, theta);
}
}
#endif // ENABLE_PRINT_BED_MODELS
Expand Down Expand Up @@ -548,6 +548,7 @@ void GLCanvas3D::Bed::_render_prusa(const std::string &key, float theta, bool us
void GLCanvas3D::Bed::_render_prusa(const std::string &key, float theta) const
#endif // ENABLE_PRINT_BED_MODELS
{
std::cout << "render prusa?\n";
std::string tex_path = resources_dir() + "/icons/bed/" + key;
#if ENABLE_PRINT_BED_MODELS
std::string model_path = resources_dir() + "/models/" + key;
Expand All @@ -563,7 +564,7 @@ void GLCanvas3D::Bed::_render_prusa(const std::string &key, float theta) const
{
if (!m_top_texture.load_from_file(filename, true))
{
_render_custom();
_render_default();
return;
}
#if ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
Expand All @@ -581,7 +582,7 @@ void GLCanvas3D::Bed::_render_prusa(const std::string &key, float theta) const
{
if (!m_bottom_texture.load_from_file(filename, true))
{
_render_custom();
_render_default();
return;
}
#if ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
Expand Down Expand Up @@ -653,64 +654,95 @@ void GLCanvas3D::Bed::_render_prusa(const std::string &key, float theta) const
}
}

void GLCanvas3D::Bed::_render_default() const
{
m_top_texture.reset();
m_bottom_texture.reset();

unsigned int triangles_vcount = m_triangles.get_vertices_count();
if (triangles_vcount > 0) {
::glEnable(GL_LIGHTING);
::glDisable(GL_DEPTH_TEST);

::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

::glEnableClientState(GL_VERTEX_ARRAY);

::glColor4f(0.35f, 0.35f, 0.35f, 0.4f);
::glNormal3d(0.0f, 0.0f, 1.0f);
::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_triangles.get_vertices());
::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount);

// draw grid
unsigned int gridlines_vcount = m_gridlines.get_vertices_count();

// we need depth test for grid, otherwise it would disappear when looking the object from below
::glEnable(GL_DEPTH_TEST);
::glLineWidth(3.0f * m_scale_factor);
::glColor4f(0.2f, 0.2f, 0.2f, 0.4f);
::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_gridlines.get_vertices());
::glDrawArrays(GL_LINES, 0, (GLsizei)gridlines_vcount);

::glDisableClientState(GL_VERTEX_ARRAY);

::glDisable(GL_BLEND);
::glDisable(GL_LIGHTING);
}

}

#if ENABLE_PRINT_BED_MODELS
void GLCanvas3D::Bed::_render_custom(const std::string &key, float theta, bool useVBOs) const
#else
void GLCanvas3D::Bed::_render_custom(const std::string &key, float theta) const
#endif // ENABLE_PRINT_BED_MODELS
{
m_top_texture.reset();
m_bottom_texture.reset();

//init textures
std::string tex_path = resources_dir() + "/icons/bed/" + key;
#if ENABLE_PRINT_BED_MODELS
std::string model_path = resources_dir() + "/models/" + key;
#endif // ENABLE_PRINT_BED_MODELS

#if ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
GLfloat max_anisotropy = 0.0f;
::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
#endif // ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
std::string tex_path = resources_dir() + "/icons/bed/" + key;
bool has_top_texture = false;
bool has_bot_texture = false;
if (!key.empty()) {
std::string filename_tex_top = tex_path + "_top.png";
if ((m_top_texture.get_id() == 0) || (m_top_texture.get_source() != filename_tex_top)) {
has_top_texture = m_top_texture.load_from_file(filename_tex_top, true);

std::string filename = tex_path + "_top.png";
if ((m_top_texture.get_id() == 0) || (m_top_texture.get_source() != filename)) {
if (!m_top_texture.load_from_file(filename, true)) {
_render_default();
return;
}
#if ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
if (has_top_texture && max_anisotropy > 0.0f) {
::glBindTexture(GL_TEXTURE_2D, m_top_texture.get_id());
::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
::glBindTexture(GL_TEXTURE_2D, 0);
}
if (max_anisotropy > 0.0f) {
::glBindTexture(GL_TEXTURE_2D, m_top_texture.get_id());
::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
::glBindTexture(GL_TEXTURE_2D, 0);
}
#endif // ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
} else {
has_top_texture = true;
}

filename = tex_path + "_bottom.png";
if ((m_bottom_texture.get_id() == 0) || (m_bottom_texture.get_source() != filename)) {
if (!m_bottom_texture.load_from_file(filename, true)) {
_render_default();
return;
}
std::string filename_tex_bot = tex_path + "_bottom.png";
if ((m_bottom_texture.get_id() == 0) || (m_bottom_texture.get_source() != filename_tex_bot)) {
has_bot_texture = m_bottom_texture.load_from_file(filename_tex_bot, true);
#if ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
if (has_bot_texture && max_anisotropy > 0.0f) {
::glBindTexture(GL_TEXTURE_2D, m_bottom_texture.get_id());
::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
::glBindTexture(GL_TEXTURE_2D, 0);
}
#endif // ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
} else {
has_bot_texture = true;
if (max_anisotropy > 0.0f) {
::glBindTexture(GL_TEXTURE_2D, m_bottom_texture.get_id());
::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
::glBindTexture(GL_TEXTURE_2D, 0);
}
#endif // ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES
}
bool has_texture = (theta <= 90.0f) ? has_top_texture : has_bot_texture;

#if ENABLE_PRINT_BED_MODELS
if (theta <= 90.0f) {
std::string model_path = resources_dir() + "/models/" + key;
std::string filename_model = model_path + "_bed.stl";
if ((m_model.get_filename() != filename_model) && m_model.init_from_file(filename_model, useVBOs)) {
if (theta <= 90.0f) {
filename = model_path + "_bed.stl";
if ((m_model.get_filename() != filename) && m_model.init_from_file(filename, useVBOs)) {
Vec3d offset = m_bounding_box.center() - Vec3d(0.0, 0.0, 0.1 + 0.5 * m_model.get_bounding_box().size()(2));
if (key == "mk2")
offset.y() += 15. / 2.;
else if (key == "mk3")
offset += Vec3d(0., (19. - 8.) / 2., 2.);
m_model.center_around(offset);
}

Expand All @@ -723,7 +755,7 @@ void GLCanvas3D::Bed::_render_custom(const std::string &key, float theta) const
#endif // ENABLE_PRINT_BED_MODELS

unsigned int triangles_vcount = m_triangles.get_vertices_count();
if (has_texture && triangles_vcount > 0) {
if (triangles_vcount > 0) {
::glEnable(GL_DEPTH_TEST);
::glDepthMask(GL_FALSE);

Expand All @@ -732,21 +764,18 @@ void GLCanvas3D::Bed::_render_custom(const std::string &key, float theta) const

::glEnable(GL_TEXTURE_2D);
::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

::glEnableClientState(GL_VERTEX_ARRAY);
::glEnableClientState(GL_TEXTURE_COORD_ARRAY);


if (theta > 90.0f)
::glFrontFace(GL_CW);

::glBindTexture(GL_TEXTURE_2D, (theta <= 90.0f) ? (GLuint)m_top_texture.get_id() : (GLuint)m_bottom_texture.get_id());

::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_triangles.get_vertices());
::glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*)m_triangles.get_tex_coords());
::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount);


if (theta > 90.0f)
::glFrontFace(GL_CCW);

Expand All @@ -758,47 +787,6 @@ void GLCanvas3D::Bed::_render_custom(const std::string &key, float theta) const

::glDisable(GL_BLEND);
::glDepthMask(GL_TRUE);

}



triangles_vcount = m_triangles.get_vertices_count();
if (triangles_vcount > 0) {
::glEnable(GL_LIGHTING);
::glDisable(GL_DEPTH_TEST);

::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);




::glEnableClientState(GL_VERTEX_ARRAY);


::glColor4f(0.35f, 0.35f, 0.35f, 0.4f);
::glNormal3d(0.0f, 0.0f, 1.0f);


::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_triangles.get_vertices());

::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount);

// draw grid
unsigned int gridlines_vcount = m_gridlines.get_vertices_count();

// we need depth test for grid, otherwise it would disappear when looking the object from below
::glEnable(GL_DEPTH_TEST);
::glLineWidth(3.0f * m_scale_factor);
::glColor4f(0.2f, 0.2f, 0.2f, 0.4f);
::glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)m_gridlines.get_vertices());
::glDrawArrays(GL_LINES, 0, (GLsizei)gridlines_vcount);

::glDisableClientState(GL_VERTEX_ARRAY);

::glDisable(GL_BLEND);
::glDisable(GL_LIGHTING);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/slic3r/GUI/GLCanvas3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,12 @@ class GLCanvas3D
std::string _detect_type() const;
#if ENABLE_PRINT_BED_MODELS
void _render_prusa(const std::string &key, float theta, bool useVBOs) const;
void _render_custom() const { _render_custom("", 0, 0); }
void _render_custom(const std::string &key, float theta, bool useVBOs) const;
#else
void _render_prusa(const std::string &key, float theta) const;
void _render_custom() const { _render_custom("", 0); }
void _render_custom(const std::string &key, float theta) const;
#endif // ENABLE_PRINT_BED_MODELS
void _render_default() const;
static bool _are_equal(const Pointfs& bed_1, const Pointfs& bed_2);
};

Expand Down

0 comments on commit e2fd5f7

Please sign in to comment.