ENABLE_THUMBNAIL_GENERATOR -> Transparent background for thumbnails saved into .3mf

This commit is contained in:
Enrico Turri 2019-11-04 11:59:23 +01:00
parent c34232214d
commit 3d450df680
3 changed files with 25 additions and 19 deletions

View file

@ -1651,12 +1651,12 @@ void GLCanvas3D::render()
} }
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only) void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background)
{ {
if (GLCanvas3DManager::are_framebuffers_supported()) if (GLCanvas3DManager::are_framebuffers_supported())
_render_thumbnail_framebuffer(thumbnail_data, w, h, printable_only, parts_only); _render_thumbnail_framebuffer(thumbnail_data, w, h, printable_only, parts_only, transparent_background);
else else
_render_thumbnail_legacy(thumbnail_data, w, h, printable_only, parts_only); _render_thumbnail_legacy(thumbnail_data, w, h, printable_only, parts_only, transparent_background);
} }
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
@ -3595,7 +3595,7 @@ static void debug_output_thumbnail(const ThumbnailData& thumbnail_data)
#endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT #endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT
static void render_volumes_in_thumbnail(Shader& shader, const GLVolumePtrs& volumes, ThumbnailData& thumbnail_data, bool printable_only, bool parts_only) static void render_volumes_in_thumbnail(Shader& shader, const GLVolumePtrs& volumes, ThumbnailData& thumbnail_data, bool printable_only, bool parts_only, bool transparent_background)
{ {
auto is_visible = [](const GLVolume& v) -> bool auto is_visible = [](const GLVolume& v) -> bool
{ {
@ -3634,6 +3634,9 @@ static void render_volumes_in_thumbnail(Shader& shader, const GLVolumePtrs& volu
camera.apply_view_matrix(); camera.apply_view_matrix();
camera.apply_projection(box); camera.apply_projection(box);
if (transparent_background)
glsafe(::glClearColor(1.0f, 1.0f, 1.0f, 0.0f));
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
@ -3660,9 +3663,12 @@ static void render_volumes_in_thumbnail(Shader& shader, const GLVolumePtrs& volu
shader.stop_using(); shader.stop_using();
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
if (transparent_background)
glsafe(::glClearColor(1.0f, 1.0f, 1.0f, 1.0f));
} }
void GLCanvas3D::_render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only) void GLCanvas3D::_render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background)
{ {
thumbnail_data.set(w, h); thumbnail_data.set(w, h);
if (!thumbnail_data.is_valid()) if (!thumbnail_data.is_valid())
@ -3715,7 +3721,7 @@ void GLCanvas3D::_render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, un
if (::glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) if (::glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
{ {
render_volumes_in_thumbnail(m_shader, m_volumes.volumes, thumbnail_data, printable_only, parts_only); render_volumes_in_thumbnail(m_shader, m_volumes.volumes, thumbnail_data, printable_only, parts_only, transparent_background);
if (multisample) if (multisample)
{ {
@ -3766,7 +3772,7 @@ void GLCanvas3D::_render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, un
glsafe(::glDisable(GL_MULTISAMPLE)); glsafe(::glDisable(GL_MULTISAMPLE));
} }
void GLCanvas3D::_render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only) void GLCanvas3D::_render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background)
{ {
// check that thumbnail size does not exceed the default framebuffer size // check that thumbnail size does not exceed the default framebuffer size
const Size& cnv_size = get_canvas_size(); const Size& cnv_size = get_canvas_size();
@ -3783,7 +3789,7 @@ void GLCanvas3D::_render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigne
if (!thumbnail_data.is_valid()) if (!thumbnail_data.is_valid())
return; return;
render_volumes_in_thumbnail(m_shader, m_volumes.volumes, thumbnail_data, printable_only, parts_only); render_volumes_in_thumbnail(m_shader, m_volumes.volumes, thumbnail_data, printable_only, parts_only, transparent_background);
glsafe(::glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, (void*)thumbnail_data.pixels.data())); glsafe(::glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, (void*)thumbnail_data.pixels.data()));
#if ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT #if ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT

View file

@ -529,7 +529,7 @@ public:
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
// printable_only == false -> render also non printable volumes as grayed // printable_only == false -> render also non printable volumes as grayed
// parts_only == false -> render also sla support and pad // parts_only == false -> render also sla support and pad
void render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only); void render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background);
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
void select_all(); void select_all();
@ -684,9 +684,9 @@ private:
void _render_undo_redo_stack(const bool is_undo, float pos_x); void _render_undo_redo_stack(const bool is_undo, float pos_x);
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
// render thumbnail using an off-screen framebuffer // render thumbnail using an off-screen framebuffer
void _render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only); void _render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background);
// render thumbnail using the default framebuffer // render thumbnail using the default framebuffer
void _render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only); void _render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background);
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
void _update_volumes_hover_state() const; void _update_volumes_hover_state() const;

View file

@ -1928,7 +1928,7 @@ struct Plater::priv
bool can_reload_from_disk() const; bool can_reload_from_disk() const;
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
void generate_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, bool printable_only, bool parts_only); void generate_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background);
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
void msw_rescale_object_menu(); void msw_rescale_object_menu();
@ -3057,7 +3057,7 @@ bool Plater::priv::restart_background_process(unsigned int state)
for (const std::pair<unsigned int, unsigned int>& size : THUMBNAIL_SIZE_FFF) for (const std::pair<unsigned int, unsigned int>& size : THUMBNAIL_SIZE_FFF)
{ {
this->thumbnail_data.push_back(ThumbnailData()); this->thumbnail_data.push_back(ThumbnailData());
generate_thumbnail(this->thumbnail_data.back(), size.first, size.second, true, true); generate_thumbnail(this->thumbnail_data.back(), size.first, size.second, true, true, false);
} }
} }
else if (this->printer_technology == ptSLA) else if (this->printer_technology == ptSLA)
@ -3068,7 +3068,7 @@ bool Plater::priv::restart_background_process(unsigned int state)
for (const std::pair<unsigned int, unsigned int>& size : THUMBNAIL_SIZE_SLA) for (const std::pair<unsigned int, unsigned int>& size : THUMBNAIL_SIZE_SLA)
{ {
this->thumbnail_data.push_back(ThumbnailData()); this->thumbnail_data.push_back(ThumbnailData());
generate_thumbnail(this->thumbnail_data.back(), size.first, size.second, true, true); generate_thumbnail(this->thumbnail_data.back(), size.first, size.second, true, true, false);
} }
} }
} }
@ -3422,7 +3422,7 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt)
for (const std::pair<unsigned int, unsigned int>& size : THUMBNAIL_SIZE_SLA) for (const std::pair<unsigned int, unsigned int>& size : THUMBNAIL_SIZE_SLA)
{ {
this->thumbnail_data.push_back(ThumbnailData()); this->thumbnail_data.push_back(ThumbnailData());
generate_thumbnail(this->thumbnail_data.back(), size.first, size.second, true, false); generate_thumbnail(this->thumbnail_data.back(), size.first, size.second, true, false, false);
} }
} }
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
@ -3653,9 +3653,9 @@ bool Plater::priv::init_object_menu()
} }
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
void Plater::priv::generate_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, bool printable_only, bool parts_only) void Plater::priv::generate_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool transparent_background)
{ {
view3D->get_canvas3d()->render_thumbnail(data, w, h, printable_only, parts_only); view3D->get_canvas3d()->render_thumbnail(data, w, h, printable_only, parts_only, transparent_background);
} }
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
@ -4699,7 +4699,7 @@ void Plater::export_3mf(const boost::filesystem::path& output_path)
wxBusyCursor wait; wxBusyCursor wait;
#if ENABLE_THUMBNAIL_GENERATOR #if ENABLE_THUMBNAIL_GENERATOR
ThumbnailData thumbnail_data; ThumbnailData thumbnail_data;
p->generate_thumbnail(thumbnail_data, THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second, false, true); p->generate_thumbnail(thumbnail_data, THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second, false, true, true);
if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr, &thumbnail_data)) { if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr, &thumbnail_data)) {
#else #else
if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr)) { if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr)) {