AABB trees for SLA gizmos are not calculated when the object is selected, but only after one of the gizmos is opened

This commit is contained in:
Lukas Matena 2020-02-20 14:28:45 +01:00
parent 487ac0423e
commit 4df6a645f2
5 changed files with 38 additions and 20 deletions

View File

@ -371,13 +371,7 @@ bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* mode
m_model_object_id = m_model_object->id();
if (m_mesh != m_old_mesh) {
wxBusyCursor wait;
m_mesh_raycaster.reset(new MeshRaycaster(*m_mesh));
m_object_clipper.reset();
m_supports_clipper.reset();
m_old_mesh = m_mesh;
m_clipping_plane_distance = 0.f;
m_clipping_plane_distance_stash = 0.f;
m_schedule_aabb_calculation = true;
recent_update = true;
return true;
}
@ -388,6 +382,21 @@ bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* mode
}
void CommonGizmosData::build_AABB_if_needed()
{
if (! m_schedule_aabb_calculation)
return;
wxBusyCursor wait;
m_mesh_raycaster.reset(new MeshRaycaster(*m_mesh));
m_object_clipper.reset();
m_supports_clipper.reset();
m_old_mesh = m_mesh;
m_clipping_plane_distance = 0.f;
m_clipping_plane_distance_stash = 0.f;
m_schedule_aabb_calculation = false;
}
} // namespace GUI
} // namespace Slic3r

View File

@ -231,11 +231,14 @@ public:
bool has_drilled_mesh() const { return m_has_drilled_mesh; }
void build_AABB_if_needed();
private:
const TriangleMesh* m_old_mesh;
TriangleMesh m_backend_mesh_transformed;
float m_clipping_plane_distance_stash = 0.f;
bool m_has_drilled_mesh = false;
bool m_schedule_aabb_calculation = false;
};
} // namespace GUI

View File

@ -57,6 +57,10 @@ bool GLGizmoHollow::on_init()
void GLGizmoHollow::set_sla_support_data(ModelObject*, const Selection&)
{
if (m_c->recent_update) {
if (m_state == On)
m_c->build_AABB_if_needed();
update_clipping_plane();
if (m_c->m_model_object) {
reload_cache();
@ -983,6 +987,8 @@ void GLGizmoHollow::on_set_state()
m_c->unstash_clipping_plane();
update_clipping_plane(m_c->m_clipping_plane_distance != 0.f);
m_c->build_AABB_if_needed();
// we'll now reload support points:
if (m_c->m_model_object)
reload_cache();

View File

@ -63,7 +63,16 @@ bool GLGizmoSlaSupports::on_init()
void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const Selection& selection)
{
// Update common data for hollowing and sla support gizmos.
if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA)
m_c->update_from_backend(m_parent, model_object);
if (m_c->recent_update) {
if (m_state == On)
m_c->build_AABB_if_needed();
update_clipping_plane();
if (m_state == On) {
m_parent.toggle_model_objects_visibility(false);
m_parent.toggle_model_objects_visibility(/*! m_c->m_cavity_mesh*/ true, m_c->m_model_object, m_c->m_active_instance);
@ -1004,6 +1013,8 @@ void GLGizmoSlaSupports::on_set_state()
m_c->unstash_clipping_plane();
update_clipping_plane(m_c->m_clipping_plane_distance != 0.f);
m_c->build_AABB_if_needed();
// we'll now reload support points:
if (m_c->m_model_object)

View File

@ -351,19 +351,8 @@ void GLGizmosManager::set_sla_support_data(ModelObject* model_object)
auto* gizmo_supports = dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get());
auto* gizmo_hollow = dynamic_cast<GLGizmoHollow*>(m_gizmos[Hollow].get());
// Update common data for hollowing and sla support gizmos.
if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) {
if (m_common_gizmos_data->update_from_backend(m_parent, model_object)) {
// FIXME: this is a hack to make that the clipping plane is
// updated when the update set its position to zero. The clipping
// plane itself should be common, including the update_function.
// Then update_from_backend could do it itself.
gizmo_supports->update_clipping_plane();
gizmo_hollow->update_clipping_plane();
}
}
// note: sla support gizmo takes care of updating the common data.
// following lines are thus dependent
gizmo_supports->set_sla_support_data(model_object, m_parent.get_selection());
gizmo_hollow->set_sla_support_data(model_object, m_parent.get_selection());
}