Cut gizmo is now able to see clicks on the clipping plane

This commit is contained in:
Lukas Matena 2022-02-07 14:35:34 +01:00
parent 016a7feb3d
commit a8564bf289
3 changed files with 39 additions and 2 deletions

View File

@ -403,12 +403,44 @@ BoundingBoxf3 GLGizmoCut::bounding_box() const
// }
bool GLGizmoCut::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down)
{
if (is_dragging())
return false;
const ModelObject *mo = m_c->selection_info()->model_object();
const ModelInstance *mi = mo->instances[m_c->selection_info()->get_active_instance()];
const Transform3d instance_trafo = mi->get_transformation().get_matrix();
const Transform3d instance_trafo_not_translate = mi->get_transformation().get_matrix(true);
const Camera& camera = wxGetApp().plater()->get_camera();
int mesh_id = -1;
for (const ModelVolume *mv : mo->volumes) {
++mesh_id;
if (! mv->is_model_part())
continue;
Vec3f hit;
Vec3f normal;
bool clipping_plane_was_hit = false;
m_c->raycaster()->raycasters()[mesh_id]->unproject_on_mesh(mouse_position, instance_trafo * mv->get_matrix(),
camera, hit, normal, m_c->object_clipper()->get_clipping_plane(),
nullptr, &clipping_plane_was_hit);
if (clipping_plane_was_hit) {
// The clipping plane was clicked, hit containts coordinates of the hit in world coords.
std::cout << hit.x() << "\t" << hit.y() << "\t" << hit.z() << std::endl;
return true;
}
}
return false;
}
CommonGizmosDataID GLGizmoCut::on_get_requirements() const {
return CommonGizmosDataID(
int(CommonGizmosDataID::SelectionInfo)
| int(CommonGizmosDataID::InstancesHider)
| int(CommonGizmosDataID::ObjectClipper));
| int(CommonGizmosDataID::ObjectClipper)
| int(CommonGizmosDataID::Raycaster));
}
} // namespace GUI

View File

@ -9,6 +9,8 @@
namespace Slic3r {
namespace GUI {
enum class SLAGizmoEventType : unsigned char;
class GLGizmoCut : public GLGizmoBase
{
static const double Offset;
@ -49,6 +51,7 @@ public:
void set_cut_z(double cut_z);
std::string get_tooltip() const override;
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
protected:
bool on_init() override;

View File

@ -445,6 +445,8 @@ bool GLGizmosManager::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_p
return dynamic_cast<GLGizmoSeam*>(m_gizmos[Seam].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
else if (m_current == MmuSegmentation)
return dynamic_cast<GLGizmoMmuSegmentation*>(m_gizmos[MmuSegmentation].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
else if (m_current == Cut)
return dynamic_cast<GLGizmoCut*>(m_gizmos[Cut].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down);
else
return false;
}
@ -656,7 +658,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
m_tooltip.clear();
if (evt.LeftDown() && (!control_down || grabber_contains_mouse())) {
if ((m_current == SlaSupports || m_current == Hollow || m_current == FdmSupports || m_current == Seam || m_current == MmuSegmentation)
if ((m_current == SlaSupports || m_current == Hollow || m_current == FdmSupports || m_current == Seam || m_current == MmuSegmentation || m_current == Cut)
&& gizmo_event(SLAGizmoEventType::LeftDown, mouse_pos, evt.ShiftDown(), evt.AltDown()))
// the gizmo got the event and took some action, there is no need to do anything more
processed = true;