Skip to content

Commit

Permalink
AABB trees for SLA gizmos are not calculated when the object is selec…
Browse files Browse the repository at this point in the history
…ted, but only after one of the gizmos is opened
  • Loading branch information
lukasmatena committed Feb 21, 2020
1 parent 487ac04 commit 4df6a64
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
23 changes: 16 additions & 7 deletions src/slic3r/GUI/Gizmos/GLGizmoBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/slic3r/GUI/Gizmos/GLGizmoBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,14 @@ class CommonGizmosData {

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
Expand Down
6 changes: 6 additions & 0 deletions src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 2 additions & 13 deletions src/slic3r/GUI/Gizmos/GLGizmosManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 4df6a64

Please sign in to comment.