Hollowing gizmo - most of updating now assumes that common data struct is updated properly

This commit is contained in:
Lukas Matena 2020-01-30 14:12:52 +01:00
parent b0aa937215
commit 08dcbd0271
5 changed files with 39 additions and 37 deletions

View file

@ -2208,6 +2208,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
mesh.transform(t.inverse());
GLIndexedVertexArray iva;
iva.load_mesh(mesh);
volume->indexed_vertex_array.release_geometry();
volume->indexed_vertex_array = iva;
volume->finalize_geometry(true);
}

View file

@ -307,9 +307,27 @@ unsigned char picking_checksum_alpha_channel(unsigned char red, unsigned char gr
bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas)
bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* model_object)
{
if (! m_model_object)
recent_update = false;
if (m_model_object != model_object
|| (model_object && m_model_object_id != model_object->id())) {
m_model_object = model_object;
m_print_object_idx = -1;
m_mesh_raycaster.reset();
m_object_clipper.reset();
m_supports_clipper.reset();
if (m_model_object) {
m_active_instance = canvas.get_selection().get_instance_idx();
m_active_instance_bb_radius = m_model_object->instance_bounding_box(m_active_instance).radius();
}
recent_update = true;
}
if (! m_model_object || ! canvas.get_selection().is_from_single_instance())
return false;
int old_po_idx = m_print_object_idx;
@ -352,8 +370,11 @@ bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas)
m_object_clipper.reset();
m_supports_clipper.reset();
m_old_mesh = m_mesh;
recent_update = true;
return true;
}
if (! recent_update)
recent_update = m_print_object_idx < 0 && old_po_idx >= 0;
return m_print_object_idx < 0 ? old_po_idx >=0 : false;
}

View file

@ -193,7 +193,9 @@ public:
return (! m_mesh ? nullptr : m_mesh); //(m_cavity_mesh ? m_cavity_mesh.get() : m_mesh));
}
bool update_from_backend(GLCanvas3D& canvas);
bool update_from_backend(GLCanvas3D& canvas, ModelObject* model_object);
bool recent_update = false;

View file

@ -55,36 +55,12 @@ bool GLGizmoHollow::on_init()
return true;
}
void GLGizmoHollow::set_sla_support_data(ModelObject* model_object, const Selection& selection)
void GLGizmoHollow::set_sla_support_data(ModelObject*, const Selection&)
{
if (! model_object || selection.is_empty()) {
m_c->m_model_object = nullptr;
return;
}
if (m_c->recent_update) {
bool something_changed = false;
if (m_c->m_model_object != model_object
|| m_c->m_model_object_id != model_object->id()
|| m_c->m_active_instance != selection.get_instance_idx()) {
m_c->m_model_object = model_object;
m_c->m_print_object_idx = -1;
m_c->m_mesh_raycaster.reset();
m_c->m_active_instance = selection.get_instance_idx();
something_changed = true;
}
if (model_object
&& selection.is_from_single_instance()
&& (something_changed))
{
m_c->update_from_backend(m_parent);
// Cache the bb - it's needed for dealing with the clipping plane quite often
// It could be done inside update_mesh but one has to account for scaling of the instance.
m_c->m_active_instance_bb_radius = m_c->m_model_object->instance_bounding_box(m_c->m_active_instance).radius();
reload_cache();
if (m_c->m_model_object)
reload_cache();
if (m_state == On) {
m_parent.toggle_model_objects_visibility(false);
@ -112,7 +88,7 @@ void GLGizmoHollow::on_render() const
}
// !!! is it necessary?
const_cast<GLGizmoHollow*>(this)->m_c->update_from_backend(m_parent);
//const_cast<GLGizmoHollow*>(this)->m_c->update_from_backend(m_parent, m_c->m_model_object);
glsafe(::glEnable(GL_BLEND));
glsafe(::glEnable(GL_DEPTH_TEST));
@ -183,8 +159,8 @@ void GLGizmoHollow::render_clipping_plane(const Selection& selection) const
// Next, ask the backend if supports are already calculated. If so, we are gonna cut them too.
if (m_c->m_print_object_idx < 0)
m_c->update_from_backend(m_parent);
//if (m_c->m_print_object_idx < 0)
// m_c->update_from_backend(m_parent, m_c->m_model_object);
if (m_c->m_print_object_idx >= 0) {
const SLAPrintObject* print_object = m_parent.sla_print()->objects()[m_c->m_print_object_idx];
@ -352,9 +328,11 @@ bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const
// Return false if no intersection was found, true otherwise.
bool GLGizmoHollow::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec3f, Vec3f>& pos_and_normal)
{
if (! m_c->m_mesh_raycaster)
return false;
// if the gizmo doesn't have the V, F structures for igl, calculate them first:
// !!! is it really necessary?
m_c->update_from_backend(m_parent);
//m_c->update_from_backend(m_parent, m_c->m_model_object);
const Camera& camera = m_parent.get_camera();
const Selection& selection = m_parent.get_selection();
@ -955,7 +933,7 @@ void GLGizmoHollow::on_set_state()
if (m_state == On && m_old_state != On) { // the gizmo was just turned on
//Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on")));
m_c->update_from_backend(m_parent);
//m_c->update_from_backend(m_parent, m_c->m_model_object);
// we'll now reload support points:
if (m_c->m_model_object)

View file

@ -349,7 +349,7 @@ void GLGizmosManager::set_sla_support_data(ModelObject* model_object)
return;
// Update common data for hollowing and sla support gizmos.
m_common_gizmos_data->update_from_backend(m_parent);
m_common_gizmos_data->update_from_backend(m_parent, model_object);
dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->set_sla_support_data(model_object, m_parent.get_selection());
dynamic_cast<GLGizmoHollow*>(m_gizmos[Hollow].get())->set_sla_support_data(model_object, m_parent.get_selection());