Mdel preview renders the actual colors of the filaments based on the filaments currently loaded in the AMS

Ported from BambuStudio
This commit is contained in:
SoftFever 2024-04-15 22:09:01 +08:00
parent 4590c765c6
commit 27f140fb18
20 changed files with 1441 additions and 400 deletions

View file

@ -2051,13 +2051,24 @@ void GLCanvas3D::render(bool only_init)
m_render_stats.increment_fps_counter();
}
void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params, Camera::EType camera_type, bool use_top_view, bool for_picking)
void GLCanvas3D::render_thumbnail(ThumbnailData & thumbnail_data,
unsigned int w,
unsigned int h,
const ThumbnailsParams &thumbnail_params,
Camera::EType camera_type,
bool use_top_view,
bool for_picking,
bool ban_light)
{
render_thumbnail(thumbnail_data, w, h, thumbnail_params, m_volumes, camera_type, use_top_view, for_picking);
render_thumbnail(thumbnail_data, w, h, thumbnail_params, m_volumes, camera_type, use_top_view, for_picking, ban_light);
}
void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params,
const GLVolumeCollection& volumes, Camera::EType camera_type, bool use_top_view, bool for_picking)
const GLVolumeCollection &volumes,
Camera::EType camera_type,
bool use_top_view,
bool for_picking,
bool ban_light)
{
GLShaderProgram* shader = nullptr;
if (for_picking)
@ -2069,14 +2080,19 @@ void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w,
switch (OpenGLManager::get_framebuffers_type())
{
case OpenGLManager::EFramebufferType::Arb:
{ render_thumbnail_framebuffer(thumbnail_data, w, h, thumbnail_params,
wxGetApp().plater()->get_partplate_list(), model_objects, volumes, colors, shader, camera_type, use_top_view, for_picking); break; }
{ render_thumbnail_framebuffer(thumbnail_data, w, h, thumbnail_params, wxGetApp().plater()->get_partplate_list(), model_objects, volumes, colors, shader, camera_type,
use_top_view, for_picking, ban_light);
break;
}
case OpenGLManager::EFramebufferType::Ext:
{ render_thumbnail_framebuffer_ext(thumbnail_data, w, h, thumbnail_params,
wxGetApp().plater()->get_partplate_list(), model_objects, volumes, colors, shader, camera_type, use_top_view, for_picking); break; }
{ render_thumbnail_framebuffer_ext(thumbnail_data, w, h, thumbnail_params, wxGetApp().plater()->get_partplate_list(), model_objects, volumes, colors, shader, camera_type,
use_top_view, for_picking, ban_light);
break;
}
default:
{ render_thumbnail_legacy(thumbnail_data, w, h, thumbnail_params,
wxGetApp().plater()->get_partplate_list(), model_objects, volumes, colors, shader, camera_type); break; }
{ render_thumbnail_legacy(thumbnail_data, w, h, thumbnail_params, wxGetApp().plater()->get_partplate_list(), model_objects, volumes, colors, shader, camera_type);
break;
}
}
}
@ -5733,7 +5749,7 @@ static void debug_output_thumbnail(const ThumbnailData& thumbnail_data)
void GLCanvas3D::render_thumbnail_internal(ThumbnailData& thumbnail_data, const ThumbnailsParams& thumbnail_params,
PartPlateList& partplate_list, ModelObjectPtrs& model_objects, const GLVolumeCollection& volumes, std::vector<ColorRGBA>& extruder_colors,
GLShaderProgram* shader, Camera::EType camera_type, bool use_top_view, bool for_picking)
GLShaderProgram* shader, Camera::EType camera_type, bool use_top_view, bool for_picking, bool ban_light)
{
//BBS modify visible calc function
int plate_idx = thumbnail_params.plate_id;
@ -5849,7 +5865,9 @@ void GLCanvas3D::render_thumbnail_internal(ThumbnailData& thumbnail_data, const
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
glsafe(::glEnable(GL_DEPTH_TEST));
if (ban_light) {
glsafe(::glDisable(GL_BLEND));
}
const Transform3d &projection_matrix = camera.get_projection_matrix();
if (for_picking) {
@ -5903,12 +5921,16 @@ void GLCanvas3D::render_thumbnail_internal(ThumbnailData& thumbnail_data, const
else {
shader->start_using();
shader->set_uniform("emission_factor", 0.1f);
shader->set_uniform("ban_light", ban_light);
for (GLVolume* vol : visible_volumes) {
//BBS set render color for thumbnails
curr_color = vol->color;
ColorRGBA new_color = adjust_color_for_rendering(curr_color);
vol->model.set_color(new_color);
if (ban_light) {
new_color[3] = (255 - vol->extruder_id) / 255.0f;
}
vol->model.set_color(new_color);
shader->set_uniform("volume_world_matrix", vol->world_matrix());
//BBS set all volume to orange
//shader->set_uniform("uniform_color", orange);
@ -5926,7 +5948,7 @@ void GLCanvas3D::render_thumbnail_internal(ThumbnailData& thumbnail_data, const
shader->set_uniform("projection_matrix", 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();
shader->set_uniform("view_normal_matrix", view_normal_matrix);
vol->simple_render(shader, model_objects, extruder_colors);
vol->simple_render(shader, model_objects, extruder_colors, ban_light);
vol->is_active = is_active;
}
shader->stop_using();
@ -5945,7 +5967,7 @@ void GLCanvas3D::render_thumbnail_internal(ThumbnailData& thumbnail_data, const
void GLCanvas3D::render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params,
PartPlateList& partplate_list, ModelObjectPtrs& model_objects, const GLVolumeCollection& volumes, std::vector<ColorRGBA>& extruder_colors,
GLShaderProgram* shader, Camera::EType camera_type, bool use_top_view, bool for_picking)
GLShaderProgram* shader, Camera::EType camera_type, bool use_top_view, bool for_picking, bool ban_light)
{
thumbnail_data.set(w, h);
if (!thumbnail_data.is_valid())
@ -5998,7 +6020,8 @@ void GLCanvas3D::render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, uns
glsafe(::glDrawBuffers(1, drawBufs));
if (::glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) {
render_thumbnail_internal(thumbnail_data, thumbnail_params, partplate_list, model_objects, volumes, extruder_colors, shader, camera_type, use_top_view, for_picking);
render_thumbnail_internal(thumbnail_data, thumbnail_params, partplate_list, model_objects, volumes, extruder_colors, shader,
camera_type, use_top_view, for_picking,ban_light);
if (multisample) {
GLuint resolve_fbo;
@ -6053,7 +6076,7 @@ void GLCanvas3D::render_thumbnail_framebuffer(ThumbnailData& thumbnail_data, uns
void GLCanvas3D::render_thumbnail_framebuffer_ext(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params,
PartPlateList& partplate_list, ModelObjectPtrs& model_objects, const GLVolumeCollection& volumes, std::vector<ColorRGBA>& extruder_colors,
GLShaderProgram* shader, Camera::EType camera_type, bool use_top_view, bool for_picking)
GLShaderProgram* shader, Camera::EType camera_type, bool use_top_view, bool for_picking, bool ban_light)
{
thumbnail_data.set(w, h);
if (!thumbnail_data.is_valid())
@ -6105,7 +6128,8 @@ void GLCanvas3D::render_thumbnail_framebuffer_ext(ThumbnailData& thumbnail_data,
glsafe(::glDrawBuffers(1, drawBufs));
if (::glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT) {
render_thumbnail_internal(thumbnail_data, thumbnail_params, partplate_list, model_objects, volumes, extruder_colors, shader, camera_type, use_top_view, for_picking);
render_thumbnail_internal(thumbnail_data, thumbnail_params, partplate_list, model_objects, volumes, extruder_colors, shader, camera_type, use_top_view, for_picking,
ban_light);
if (multisample) {
GLuint resolve_fbo;