Create multiple simplify notification
This commit is contained in:
parent
6d895872b0
commit
1aa4b32fa7
@ -96,7 +96,9 @@ enum class NotificationType
|
||||
DidYouKnowHint,
|
||||
// Shows when ObjectList::update_info_items finds information that should be stressed to the user
|
||||
// Might contain logo taken from gizmos
|
||||
UpdatedItemsInfo
|
||||
UpdatedItemsInfo,
|
||||
// Give user advice to simplify object with big amount of triangles
|
||||
SimplifySuggestion
|
||||
};
|
||||
|
||||
class NotificationManager
|
||||
@ -537,7 +539,14 @@ private:
|
||||
// Timestamp of last rendering
|
||||
int64_t m_last_render { 0LL };
|
||||
// Notification types that can be shown multiple types at once (compared by text)
|
||||
const std::vector<NotificationType> m_multiple_types = { NotificationType::CustomNotification, NotificationType::PlaterWarning, NotificationType::ProgressBar, NotificationType::PrintHostUpload, NotificationType::UpdatedItemsInfo };
|
||||
const std::vector<NotificationType> m_multiple_types = {
|
||||
NotificationType::CustomNotification,
|
||||
NotificationType::PlaterWarning,
|
||||
NotificationType::ProgressBar,
|
||||
NotificationType::PrintHostUpload,
|
||||
NotificationType::UpdatedItemsInfo,
|
||||
NotificationType::SimplifySuggestion
|
||||
};
|
||||
//prepared (basic) notifications
|
||||
static const NotificationData basic_notifications[];
|
||||
};
|
||||
|
@ -1720,7 +1720,7 @@ struct Plater::priv
|
||||
void replace_with_stl();
|
||||
void reload_all_from_disk();
|
||||
void fix_through_netfabb(const int obj_idx, const int vol_idx = -1);
|
||||
|
||||
void create_simplify_notification(const std::vector<size_t>& obj_ids);
|
||||
void set_current_panel(wxPanel* panel);
|
||||
|
||||
void on_select_preset(wxCommandEvent&);
|
||||
@ -2408,28 +2408,6 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||
return obj_idxs;
|
||||
}
|
||||
|
||||
// detection of simplification suggestion
|
||||
const uint32_t triangles_to_suggest_simplify = 1000000;
|
||||
for (const ModelObject *model_object : model.objects) {
|
||||
const indexed_triangle_set &its =
|
||||
model_object->volumes.front()->mesh().its;
|
||||
uint32_t triangle_count = its.indices.size();
|
||||
if (triangle_count > triangles_to_suggest_simplify) {
|
||||
std::string text = _u8L("Processing models with more than 1M triangles"
|
||||
" could be slow. It is highly recommend to reduce amount of triangles.") + "\n";
|
||||
std::string hypertext = "Simplify mesh.";
|
||||
std::function<bool(wxEvtHandler *)> action_fn = [&](wxEvtHandler *) {
|
||||
auto &manager = q->canvas3D()->get_gizmos_manager();
|
||||
manager.open_gizmo(GLGizmosManager::EType::Simplify);
|
||||
return true;
|
||||
};
|
||||
notification_manager->push_notification(
|
||||
NotificationType::CustomNotification,
|
||||
NotificationManager::NotificationLevel::WarningNotification,
|
||||
_u8L("WARNING:") + "\n" + text, hypertext, action_fn);
|
||||
}
|
||||
}
|
||||
|
||||
for (ModelObject* model_object : model.objects) {
|
||||
if (!type_3mf && !type_zip_amf)
|
||||
model_object->center_around_origin(false);
|
||||
@ -2496,6 +2474,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||
view3D->get_canvas3d()->update_gizmos_on_off_state();
|
||||
}
|
||||
|
||||
create_simplify_notification(obj_idxs);
|
||||
|
||||
return obj_idxs;
|
||||
}
|
||||
|
||||
@ -3529,6 +3509,53 @@ void Plater::priv::fix_through_netfabb(const int obj_idx, const int vol_idx/* =
|
||||
q->SetFocus();
|
||||
}
|
||||
|
||||
void Plater::priv::create_simplify_notification(const std::vector<size_t>& obj_ids) {
|
||||
const uint32_t triangles_to_suggest_simplify = 1000000;
|
||||
|
||||
std::vector<size_t> big_ids;
|
||||
big_ids.reserve(obj_ids.size());
|
||||
std::copy_if(obj_ids.begin(), obj_ids.end(), std::back_inserter(big_ids),
|
||||
[this, triangles_to_suggest_simplify](size_t object_id) {
|
||||
if (object_id >= model.objects.size()) return false; // out of object index
|
||||
ModelVolumePtrs& volumes = model.objects[object_id]->volumes;
|
||||
if (volumes.size() != 1) return false; // not only one volume
|
||||
size_t triangle_count = volumes.front()->mesh().its.indices.size();
|
||||
if (triangle_count < triangles_to_suggest_simplify) return false; // small volume
|
||||
return true;
|
||||
});
|
||||
|
||||
if (big_ids.empty()) return;
|
||||
|
||||
for (size_t object_id : big_ids) {
|
||||
std::string t = _u8L(
|
||||
"Processing model '@object_name' with more than 1M triangles "
|
||||
"could be slow. It is highly recommend to reduce "
|
||||
"amount of triangles.");
|
||||
t.replace(t.find("@object_name"), sizeof("@object_name") - 1,
|
||||
model.objects[object_id]->name);
|
||||
std::stringstream text;
|
||||
text << _u8L("WARNING:") << "\n" << t << "\n";
|
||||
std::string hypertext = _u8L("Simplify model");
|
||||
|
||||
std::function<bool(wxEvtHandler *)> open_simplify = [object_id](wxEvtHandler *) {
|
||||
auto plater = wxGetApp().plater();
|
||||
if (object_id >= plater->model().objects.size()) return true;
|
||||
|
||||
Selection &selection = plater->canvas3D()->get_selection();
|
||||
selection.clear();
|
||||
selection.add_object((unsigned int) object_id);
|
||||
|
||||
auto &manager = plater->canvas3D()->get_gizmos_manager();
|
||||
manager.open_gizmo(GLGizmosManager::EType::Simplify);
|
||||
return true;
|
||||
};
|
||||
notification_manager->push_notification(
|
||||
NotificationType::SimplifySuggestion,
|
||||
NotificationManager::NotificationLevel::WarningNotification,
|
||||
text.str(), hypertext, open_simplify);
|
||||
}
|
||||
}
|
||||
|
||||
void Plater::priv::set_current_panel(wxPanel* panel)
|
||||
{
|
||||
if (std::find(panels.begin(), panels.end(), panel) == panels.end())
|
||||
|
Loading…
Reference in New Issue
Block a user