FDM supports gizmo: fixed a crash when trying to paint on the clipping plane

This commit is contained in:
Lukas Matena 2020-05-20 12:33:49 +02:00
parent 9c365da828
commit feb591782f

View file

@ -308,7 +308,7 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
const Transform3d& instance_trafo = mi->get_transformation().get_matrix();
std::vector<std::vector<std::pair<Vec3f, size_t>>> hit_positions_and_facet_ids;
bool some_mesh_was_hit = false;
bool clipped_mesh_was_hit = false;
Vec3f normal = Vec3f::Zero();
Vec3f hit = Vec3f::Zero();
@ -343,7 +343,7 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
{
// In case this hit is clipped, skip it.
if (is_mesh_point_clipped(hit.cast<double>())) {
some_mesh_was_hit = true;
clipped_mesh_was_hit = true;
continue;
}
@ -357,11 +357,16 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
}
}
}
// We now know where the ray hit, let's save it and cast another ray
if (closest_hit_mesh_id != size_t(-1)) // only if there is at least one hit
some_mesh_was_hit = true;
if (some_mesh_was_hit) {
if (closest_hit_mesh_id == -1) {
// In case we have no valid hit, we can return. The event will
// be stopped in following two cases:
// 1. clicking the clipping plane
// 2. dragging while painting (to prevent scene rotations and moving the object)
return clipped_mesh_was_hit
|| (action == SLAGizmoEventType::Dragging && m_button_down != Button::None);
}
// Now propagate the hits
mesh_id = -1;
const TriangleMesh* mesh = nullptr;
@ -463,9 +468,7 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
if (m_button_down == Button::None)
m_button_down = ((action == SLAGizmoEventType::LeftDown) ? Button::Left : Button::Right);
return true;
}
if (action == SLAGizmoEventType::Dragging && m_button_down != Button::None)
return true;
}