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

@ -2555,7 +2555,7 @@ struct Plater::priv
//BBS: add plate_id for thumbnail
void generate_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params,
Camera::EType camera_type, bool use_top_view = false, bool for_picking = false);
Camera::EType camera_type, bool use_top_view = false, bool for_picking = false,bool ban_light = false);
ThumbnailsList generate_thumbnails(const ThumbnailsParams& params, Camera::EType camera_type);
//BBS
void generate_calibration_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params);
@ -7482,10 +7482,9 @@ void Plater::priv::on_3dcanvas_mouse_dragging_finished(SimpleEvent&)
}
//BBS: add plate id for thumbnail generate param
void Plater::priv::generate_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params,
Camera::EType camera_type, bool use_top_view, bool for_picking)
void Plater::priv::generate_thumbnail(ThumbnailData& 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)
{
view3D->get_canvas3d()->render_thumbnail(data, w, h, thumbnail_params, camera_type, use_top_view, for_picking);
view3D->get_canvas3d()->render_thumbnail(data, w, h, thumbnail_params, camera_type, use_top_view, for_picking, ban_light);
}
//BBS: add plate id for thumbnail generate param
@ -9978,6 +9977,10 @@ void Plater::update_all_plate_thumbnails(bool force_update)
if (force_update || !plate->thumbnail_data.is_valid()) {
get_view3D_canvas3D()->render_thumbnail(plate->thumbnail_data, plate->plate_thumbnail_width, plate->plate_thumbnail_height, thumbnail_params, Camera::EType::Ortho);
}
if (force_update || !plate->no_light_thumbnail_data.is_valid()) {
get_view3D_canvas3D()->render_thumbnail(plate->no_light_thumbnail_data, plate->plate_thumbnail_width, plate->plate_thumbnail_height, thumbnail_params,
Camera::EType::Ortho,false,false,true);
}
}
}
@ -9990,6 +9993,7 @@ void Plater::invalid_all_plate_thumbnails()
for (int i = 0; i < get_partplate_list().get_plate_count(); i++) {
PartPlate* plate = get_partplate_list().get_plate(i);
plate->thumbnail_data.reset();
plate->no_light_thumbnail_data.reset();
}
}
@ -11819,6 +11823,7 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy
//BBS: add plate logic for thumbnail generate
std::vector<ThumbnailData*> thumbnails;
std::vector<ThumbnailData*> no_light_thumbnails;
std::vector<ThumbnailData*> calibration_thumbnails;
std::vector<ThumbnailData*> top_thumbnails;
std::vector<ThumbnailData*> picking_thumbnails;
@ -11839,6 +11844,17 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy
}
thumbnails.push_back(thumbnail_data);
ThumbnailData *no_light_thumbnail_data = &p->partplate_list.get_plate(i)->no_light_thumbnail_data;
if (p->partplate_list.get_plate(i)->no_light_thumbnail_data.is_valid() && using_exported_file()) {
// no need to generate thumbnail
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": non need to re-generate thumbnail for gcode/exported mode of plate %1%") % i;
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": re-generate thumbnail for plate %1%") % i;
const ThumbnailsParams thumbnail_params = {{}, false, true, true, true, i};
p->generate_thumbnail(p->partplate_list.get_plate(i)->no_light_thumbnail_data, THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second,
thumbnail_params, Camera::EType::Ortho,false,false,true);
}
no_light_thumbnails.push_back(no_light_thumbnail_data);
//ThumbnailData* calibration_data = &p->partplate_list.get_plate(i)->cali_thumbnail_data;
//calibration_thumbnails.push_back(calibration_data);
PlateBBoxData* plate_bbox_data = &p->partplate_list.get_plate(i)->cali_bboxes_data;
@ -11902,6 +11918,7 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy
store_params.project_presets = project_presets;
store_params.config = export_config ? &cfg : nullptr;
store_params.thumbnail_data = thumbnails;
store_params.no_light_thumbnail_data = no_light_thumbnails;
store_params.top_thumbnail_data = top_thumbnails;
store_params.pick_thumbnail_data = picking_thumbnails;
store_params.calibration_thumbnail_data = calibration_thumbnails;
@ -11995,6 +12012,10 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy
//release the data here, as it will always be generated when export
calibration_thumbnails[i]->reset();
}
for (unsigned int i = 0; i < no_light_thumbnails.size(); i++) {
// release the data here, as it will always be generated when export
no_light_thumbnails[i]->reset();
}
for (unsigned int i = 0; i < top_thumbnails.size(); i++)
{
//release the data here, as it will always be generated when export