Tech ENABLE_RAYCAST_PICKING - Raytraced picking of Rotate Gizmo

This commit is contained in:
enricoturri1966 2022-06-13 14:17:19 +02:00
parent df47ba7122
commit 9962a5a873
4 changed files with 43 additions and 8 deletions

View File

@ -68,7 +68,11 @@ void GLGizmoBase::Grabber::unregister_raycasters_for_picking()
}
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color)
#else
void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, bool picking)
#endif // ENABLE_RAYCAST_PICKING
{
#if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* shader = wxGetApp().get_current_shader();
@ -316,10 +320,10 @@ bool GLGizmoBase::update_items_state()
}
#if ENABLE_RAYCAST_PICKING
void GLGizmoBase::register_grabbers_for_picking()
void GLGizmoBase::register_grabbers_for_picking(bool use_group_id)
{
for (size_t i = 0; i < m_grabbers.size(); ++i) {
m_grabbers[i].register_raycasters_for_picking(i);
m_grabbers[i].register_raycasters_for_picking(use_group_id ? m_group_id : i);
}
}

View File

@ -8,6 +8,7 @@
#include "slic3r/GUI/GLModel.hpp"
#if ENABLE_RAYCAST_PICKING
#include "slic3r/GUI/MeshUtils.hpp"
#include "slic3r/GUI/SceneRaycaster.hpp"
#endif // ENABLE_RAYCAST_PICKING
#include <cereal/archives/binary.hpp>
@ -77,10 +78,12 @@ protected:
Grabber() = default;
~Grabber();
#if ENABLE_RAYCAST_PICKING
void render(bool hover, float size) { render(size, hover ? complementary(color) : color); }
#else
void render(bool hover, float size) { render(size, hover ? complementary(color) : color, false); }
#if !ENABLE_RAYCAST_PICKING
void render_for_picking(float size) { render(size, color, true); }
#endif // !ENABLE_RAYCAST_PICKING
#endif // ENABLE_RAYCAST_PICKING
float get_half_size(float size) const;
float get_dragging_half_size(float size) const;
@ -91,7 +94,11 @@ protected:
#endif // ENABLE_RAYCAST_PICKING
private:
#if ENABLE_RAYCAST_PICKING
void render(float size, const ColorRGBA& render_color);
#else
void render(float size, const ColorRGBA& render_color, bool picking);
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
static PickingModel s_cube;
@ -200,7 +207,7 @@ public:
virtual bool on_mouse(const wxMouseEvent &mouse_event) { return false; }
#if ENABLE_RAYCAST_PICKING
void register_raycasters_for_picking() { register_grabbers_for_picking(); on_register_raycasters_for_picking(); }
void register_raycasters_for_picking(bool use_group_id = false) { register_grabbers_for_picking(use_group_id); on_register_raycasters_for_picking(); }
void unregister_raycasters_for_picking() { unregister_grabbers_for_picking(); on_unregister_raycasters_for_picking(); }
#endif // ENABLE_RAYCAST_PICKING
@ -229,7 +236,7 @@ protected:
virtual void on_render_input_window(float x, float y, float bottom_limit) {}
#if ENABLE_RAYCAST_PICKING
void register_grabbers_for_picking();
void register_grabbers_for_picking(bool use_group_id = false);
void unregister_grabbers_for_picking();
virtual void on_register_raycasters_for_picking() {}
virtual void on_unregister_raycasters_for_picking() {}

View File

@ -882,6 +882,25 @@ void GLGizmoRotate3D::on_render()
m_gizmos[Z].render();
}
#if ENABLE_RAYCAST_PICKING
void GLGizmoRotate3D::on_register_raycasters_for_picking()
{
// this gizmo is rendered on top of the scene, so the raytraced picker should take it into account
m_parent.set_raycaster_gizmos_on_top(true);
for (GLGizmoRotate& g : m_gizmos) {
g.register_raycasters_for_picking(true);
}
}
void GLGizmoRotate3D::on_unregister_raycasters_for_picking()
{
for (GLGizmoRotate& g : m_gizmos) {
g.unregister_raycasters_for_picking();
}
m_parent.set_raycaster_gizmos_on_top(false);
}
#endif // ENABLE_RAYCAST_PICKING
GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(ImGuiWrapper * imgui,
State & state,
const Alignment &alignment)

View File

@ -6,6 +6,7 @@
namespace Slic3r {
namespace GUI {
class Selection;
class GLGizmoRotate : public GLGizmoBase
{
static const float Offset;
@ -84,6 +85,7 @@ public:
/// <returns>Return True when use the information otherwise False.</returns>
bool on_mouse(const wxMouseEvent &mouse_event) override;
void dragging(const UpdateData &data);
protected:
bool on_init() override;
std::string on_get_name() const override { return ""; }
@ -177,13 +179,16 @@ protected:
void on_dragging(const UpdateData &data) override;
void on_render() override;
#if !ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_raycasters_for_picking() override;
#else
void on_render_for_picking() override {
for (GLGizmoRotate& g : m_gizmos) {
g.render_for_picking();
}
}
#endif // !ENABLE_RAYCAST_PICKING
#endif // ENABLE_RAYCAST_PICKING
void on_render_input_window(float x, float y, float bottom_limit) override;