Tech ENABLE_RAYCAST_PICKING - Partial revert of 89ac932628 - Restored rectangle selection using encoded colors rendering

This commit is contained in:
enricoturri1966 2022-06-28 14:12:57 +02:00
parent 0a1d1ef6c8
commit ae76468f7c
17 changed files with 64 additions and 109 deletions

View file

@ -379,7 +379,6 @@ ColorRGB to_rgb(const ColorRGBA& other_rgba) { return { other_rgba.r(), other_rg
ColorRGBA to_rgba(const ColorRGB& other_rgb) { return { other_rgb.r(), other_rgb.g(), other_rgb.b(), 1.0f }; }
ColorRGBA to_rgba(const ColorRGB& other_rgb, float alpha) { return { other_rgb.r(), other_rgb.g(), other_rgb.b(), alpha }; }
#if !ENABLE_RAYCAST_PICKING
ColorRGBA picking_decode(unsigned int id)
{
return {
@ -404,7 +403,6 @@ unsigned char picking_checksum_alpha_channel(unsigned char red, unsigned char gr
b ^= 0x55;
return b;
}
#endif // !ENABLE_RAYCAST_PICKING
} // namespace Slic3r

View file

@ -181,13 +181,11 @@ inline Vec3i value_to_rgbi(float minimum, float maximum, float value)
return (value_to_rgbf(minimum, maximum, value) * 255).cast<int>();
}
#if !ENABLE_RAYCAST_PICKING
ColorRGBA picking_decode(unsigned int id);
unsigned int picking_encode(unsigned char r, unsigned char g, unsigned char b);
// Produce an alpha channel checksum for the red green blue components. The alpha channel may then be used to verify, whether the rgb components
// were not interpolated by alpha blending or multi sampling.
unsigned char picking_checksum_alpha_channel(unsigned char red, unsigned char green, unsigned char blue);
#endif // !ENABLE_RAYCAST_PICKING
} // namespace Slic3r

View file

@ -79,7 +79,7 @@
#define ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE (1 && ENABLE_2_5_0_ALPHA1)
// Enable picking using raytracing
#define ENABLE_RAYCAST_PICKING (1 && ENABLE_LEGACY_OPENGL_REMOVAL)
#define ENABLE_RAYCAST_PICKING_DEBUG (1 && ENABLE_RAYCAST_PICKING)
#define ENABLE_RAYCAST_PICKING_DEBUG (0 && ENABLE_RAYCAST_PICKING)
#endif // _prusaslicer_technologies_h_

View file

@ -24,9 +24,7 @@
static const float GROUND_Z = -0.02f;
static const Slic3r::ColorRGBA DEFAULT_MODEL_COLOR = Slic3r::ColorRGBA::DARK_GRAY();
#if !ENABLE_RAYCAST_PICKING
static const Slic3r::ColorRGBA PICKING_MODEL_COLOR = Slic3r::ColorRGBA::BLACK();
#endif // !ENABLE_RAYCAST_PICKING
static const Slic3r::ColorRGBA DEFAULT_SOLID_GRID_COLOR = { 0.9f, 0.9f, 0.9f, 1.0f };
static const Slic3r::ColorRGBA DEFAULT_TRANSPARENT_GRID_COLOR = { 0.9f, 0.9f, 0.9f, 0.6f };
@ -273,19 +271,13 @@ Point Bed3D::point_projection(const Point& point) const
#if ENABLE_LEGACY_OPENGL_REMOVAL
void Bed3D::render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture)
{
#if ENABLE_RAYCAST_PICKING
render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture);
#else
render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture, false);
#endif // ENABLE_RAYCAST_PICKING
}
#if !ENABLE_RAYCAST_PICKING
void Bed3D::render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor)
{
render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, false, false, true);
}
#endif // !ENABLE_RAYCAST_PICKING
#else
void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture)
{
@ -299,13 +291,8 @@ void Bed3D::render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_fact
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
void Bed3D::render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor,
bool show_axes, bool show_texture)
#else
void Bed3D::render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking)
#endif // ENABLE_RAYCAST_PICKING
#else
void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking)
@ -319,9 +306,11 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
glsafe(::glEnable(GL_DEPTH_TEST));
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
m_model.model.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR);
#else
m_model.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR);
#endif // !ENABLE_RAYCAST_PICKING
#endif // ENABLE_RAYCAST_PICKING
#else
m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -331,11 +320,7 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
#if ENABLE_LEGACY_OPENGL_REMOVAL
case Type::System: { render_system(canvas, view_matrix, projection_matrix, bottom, show_texture); break; }
default:
#if ENABLE_RAYCAST_PICKING
case Type::Custom: { render_custom(canvas, view_matrix, projection_matrix, bottom, show_texture); break; }
#else
case Type::Custom: { render_custom(canvas, view_matrix, projection_matrix, bottom, show_texture, picking); break; }
#endif // ENABLE_RAYCAST_PICKING
#else
case Type::System: { render_system(canvas, bottom, show_texture); break; }
default:
@ -618,11 +603,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
if (m_texture_filename.empty()) {
m_texture.reset();
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
render_default(bottom, true, view_matrix, projection_matrix);
#else
render_default(bottom, false, true, view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
#else
render_default(bottom, false, true);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -639,11 +620,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
// generate a temporary lower resolution texture to show while no main texture levels have been compressed
if (!m_temp_texture.load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) {
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
render_default(bottom, true, view_matrix, projection_matrix);
#else
render_default(bottom, false, true, view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
#else
render_default(bottom, false, true);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -655,11 +632,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
// starts generating the main texture, compression will run asynchronously
if (!m_texture.load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) {
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
render_default(bottom, true, view_matrix, projection_matrix);
#else
render_default(bottom, false, true, view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
#else
render_default(bottom, false, true);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -671,11 +644,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) {
if (!m_temp_texture.load_from_file(m_texture_filename, false, GLTexture::None, false)) {
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
render_default(bottom, true, view_matrix, projection_matrix);
#else
render_default(bottom, false, true, view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
#else
render_default(bottom, false, true);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -687,11 +656,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
// starts generating the main texture, compression will run asynchronously
if (!m_texture.load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) {
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
render_default(bottom, true, view_matrix, projection_matrix);
#else
render_default(bottom, false, true, view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
#else
render_default(bottom, false, true);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -700,11 +665,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
}
else {
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
render_default(bottom, true, view_matrix, projection_matrix);
#else
render_default(bottom, false, true, view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
#else
render_default(bottom, false, true);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -892,22 +853,14 @@ void Bed3D::render_model()
}
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
void Bed3D::render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture)
#else
void Bed3D::render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking)
#endif // ENABLE_RAYCAST_PICKING
#else
void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking)
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
{
if (m_texture_filename.empty() && m_model_filename.empty()) {
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
render_default(bottom, show_texture, view_matrix, projection_matrix);
#else
render_default(bottom, picking, show_texture, view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
#else
render_default(bottom, picking, show_texture);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -934,11 +887,7 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo
}
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
void Bed3D::render_default(bool bottom, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix)
#else
void Bed3D::render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix)
#endif // ENABLE_RAYCAST_PICKING
#else
void Bed3D::render_default(bool bottom, bool picking, bool show_texture)
#endif // ENABLE_LEGACY_OPENGL_REMOVAL

View file

@ -160,9 +160,7 @@ public:
#if ENABLE_LEGACY_OPENGL_REMOVAL
void render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture);
#if !ENABLE_RAYCAST_PICKING
void render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor);
#endif // !ENABLE_RAYCAST_PICKING
#else
void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture);
void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor);
@ -182,13 +180,8 @@ private:
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
static std::tuple<Type, std::string, std::string> detect_type(const Pointfs& shape);
#if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
void render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor,
bool show_axes, bool show_texture);
#else
void render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking);
#endif // ENABLE_RAYCAST_PICKING
#else
void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
bool show_axes, bool show_texture, bool picking);
@ -198,13 +191,8 @@ private:
void render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture);
void render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix);
void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix);
#if ENABLE_RAYCAST_PICKING
void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture);
void render_default(bool bottom, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix);
#else
void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking);
void render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
void render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix);
#else
void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture);

View file

@ -1713,7 +1713,7 @@ void GLCanvas3D::render()
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING_DEBUG
if (m_picking_enabled && !m_mouse.dragging && !m_gizmos.is_dragging())
if (m_picking_enabled && !m_mouse.dragging && !m_gizmos.is_dragging() && !m_rectangle_selection.is_dragging())
m_scene_raycaster.render_hit(camera);
#endif // ENABLE_RAYCAST_PICKING_DEBUG
@ -5375,6 +5375,7 @@ void GLCanvas3D::_refresh_if_shown_on_screen()
#if ENABLE_RAYCAST_PICKING
void GLCanvas3D::_picking_pass()
{
#if ENABLE_RAYCAST_PICKING_DEBUG
if (!m_picking_enabled || m_mouse.dragging || m_mouse.position == Vec2d(DBL_MAX, DBL_MAX) || m_gizmos.is_dragging()) {
ImGuiWrapper& imgui = *wxGetApp().imgui();
imgui.begin(std::string("Hit result"), ImGuiWindowFlags_AlwaysAutoResize);
@ -5382,6 +5383,7 @@ void GLCanvas3D::_picking_pass()
imgui.end();
return;
}
#endif // ENABLE_RAYCAST_PICKING_DEBUG
m_hover_volume_idxs.clear();
@ -5443,13 +5445,15 @@ void GLCanvas3D::_picking_pass()
case SceneRaycaster::EType::Volume:
{
if (m_volumes.volumes[hit.raycaster_id]->is_wipe_tower)
object_type = "Wipe tower";
object_type = "Volume (Wipe tower)";
else if (m_volumes.volumes[hit.raycaster_id]->volume_idx() == -int(slaposPad))
object_type = "SLA pad";
object_type = "Volume (SLA pad)";
else if (m_volumes.volumes[hit.raycaster_id]->volume_idx() == -int(slaposSupportTree))
object_type = "SLA supports";
object_type = "Volume (SLA supports)";
else if (m_volumes.volumes[hit.raycaster_id]->is_modifier)
object_type = "Volume (Modifier)";
else
object_type = "Volume";
object_type = "Volume (Part)";
break;
}
default: { break; }
@ -5556,11 +5560,6 @@ void GLCanvas3D::_picking_pass()
}
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
void GLCanvas3D::_rectangular_selection_picking_pass()
{
}
#else
void GLCanvas3D::_rectangular_selection_picking_pass()
{
m_gizmos.set_hover_id(-1);
@ -5642,7 +5641,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
m_hover_volume_idxs.assign(idxs.begin(), idxs.end());
_update_volumes_hover_state();
}
#endif // ENABLE_RAYCAST_PICKING
void GLCanvas3D::_render_background()
{
@ -5746,7 +5744,6 @@ void GLCanvas3D::_render_bed(bool bottom, bool show_axes)
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
}
#if !ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL
void GLCanvas3D::_render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom)
#else
@ -5764,7 +5761,6 @@ void GLCanvas3D::_render_bed_for_picking(bool bottom)
m_bed.render_for_picking(*this, bottom, scale_factor);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
}
#endif // !ENABLE_RAYCAST_PICKING
void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type)
{
@ -6042,7 +6038,6 @@ void GLCanvas3D::_render_overlays()
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
}
#if !ENABLE_RAYCAST_PICKING
void GLCanvas3D::_render_volumes_for_picking() const
{
#if ENABLE_LEGACY_OPENGL_REMOVAL
@ -6094,7 +6089,6 @@ void GLCanvas3D::_render_volumes_for_picking() const
glsafe(::glEnable(GL_CULL_FACE));
}
#endif // !ENABLE_RAYCAST_PICKING
void GLCanvas3D::_render_current_gizmo() const
{

View file

@ -980,9 +980,7 @@ private:
void _render_background();
#if ENABLE_LEGACY_OPENGL_REMOVAL
void _render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes);
#if !ENABLE_RAYCAST_PICKING
void _render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom);
#endif // !ENABLE_RAYCAST_PICKING
#else
void _render_bed(bool bottom, bool show_axes);
void _render_bed_for_picking(bool bottom);
@ -999,9 +997,7 @@ private:
#endif // ENABLE_RENDER_SELECTION_CENTER
void _check_and_update_toolbar_icon_scale();
void _render_overlays();
#if !ENABLE_RAYCAST_PICKING
void _render_volumes_for_picking() const;
#endif // !ENABLE_RAYCAST_PICKING
void _render_current_gizmo() const;
void _render_gizmos_overlay();
void _render_main_toolbar();

View file

@ -29,19 +29,25 @@ namespace GUI {
m_end_corner = mouse_position;
}
#if ENABLE_RAYCAST_PICKING
std::vector<unsigned int> GLSelectionRectangle::contains(const std::vector<Vec3d>& points) const
#else
std::vector<unsigned int> GLSelectionRectangle::stop_dragging(const GLCanvas3D& canvas, const std::vector<Vec3d>& points)
#endif // ENABLE_RAYCAST_PICKING
{
std::vector<unsigned int> out;
#if !ENABLE_RAYCAST_PICKING
if (!is_dragging())
return out;
m_state = EState::Off;
#endif // !ENABLE_RAYCAST_PICKING
const Camera& camera = wxGetApp().plater()->get_camera();
Matrix4d modelview = camera.get_view_matrix().matrix();
Matrix4d projection= camera.get_projection_matrix().matrix();
Vec4i viewport(camera.get_viewport().data());
const Matrix4d modelview = camera.get_view_matrix().matrix();
const Matrix4d projection= camera.get_projection_matrix().matrix();
const Vec4i viewport(camera.get_viewport().data());
// Convert our std::vector to Eigen dynamic matrix.
Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::DontAlign> pts(points.size(), 3);
@ -53,11 +59,15 @@ namespace GUI {
igl::project(pts, modelview, projection, viewport, projections);
// bounding box created from the rectangle corners - will take care of order of the corners
BoundingBox rectangle(Points{ Point(m_start_corner.cast<coord_t>()), Point(m_end_corner.cast<coord_t>()) });
const BoundingBox rectangle(Points{ Point(m_start_corner.cast<coord_t>()), Point(m_end_corner.cast<coord_t>()) });
// Iterate over all points and determine whether they're in the rectangle.
for (int i = 0; i<projections.rows(); ++i)
#if ENABLE_RAYCAST_PICKING
if (rectangle.contains(Point(projections(i, 0), viewport[3] - projections(i, 1))))
#else
if (rectangle.contains(Point(projections(i, 0), canvas.get_canvas_size().get_height() - projections(i, 1))))
#endif // ENABLE_RAYCAST_PICKING
out.push_back(i);
return out;

View file

@ -26,9 +26,15 @@ public:
// To be called on mouse move.
void dragging(const Vec2d& mouse_position);
#if ENABLE_RAYCAST_PICKING
// Given a vector of points in world coordinates, the function returns indices of those
// that are in the rectangle.
std::vector<unsigned int> contains(const std::vector<Vec3d>& points) const;
#else
// Given a vector of points in world coordinates, the function returns indices of those
// that are in the rectangle. It then disables the rectangle.
std::vector<unsigned int> stop_dragging(const GLCanvas3D& canvas, const std::vector<Vec3d>& points);
#endif // ENABLE_RAYCAST_PICKING
// Disables the rectangle.
void stop_dragging();

View file

@ -42,10 +42,8 @@ std::pair<bool, std::string> GLShadersManager::init()
valid &= append_shader("imgui", { prefix + "imgui.vs", prefix + "imgui.fs" });
// basic shader, used to render all what was previously rendered using the immediate mode
valid &= append_shader("flat", { prefix + "flat.vs", prefix + "flat.fs" });
#if !ENABLE_RAYCAST_PICKING
// basic shader with plane clipping, used to render volumes in picking pass
valid &= append_shader("flat_clip", { prefix + "flat_clip.vs", prefix + "flat_clip.fs" });
#endif // !ENABLE_RAYCAST_PICKING
// basic shader for textures, used to render textures
valid &= append_shader("flat_texture", { prefix + "flat_texture.vs", prefix + "flat_texture.fs" });
// used to render 3D scene background

View file

@ -156,9 +156,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
s_cube.model.render();
#else
s_cube.render();
#endif // ENABLE_RAYCAST_PICKING
auto render_extension = [&view_matrix, &view_matrix_no_offset, shader](const Transform3d& matrix) {
const Transform3d view_model_matrix = view_matrix * matrix;
@ -167,6 +164,9 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
shader->set_uniform("view_normal_matrix", view_normal_matrix);
s_cone.model.render();
};
#else
s_cube.render();
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) {

View file

@ -413,7 +413,12 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos
// Now ask the rectangle which of the points are inside.
std::vector<Vec3f> points_inside;
#if ENABLE_RAYCAST_PICKING
std::vector<unsigned int> points_idxs = m_selection_rectangle.contains(points);
m_selection_rectangle.stop_dragging();
#else
std::vector<unsigned int> points_idxs = m_selection_rectangle.stop_dragging(m_parent, points);
#endif // ENABLE_RAYCAST_PICKING
for (size_t idx : points_idxs)
points_inside.push_back(points[idx].cast<float>());

View file

@ -572,7 +572,12 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
// Now ask the rectangle which of the points are inside.
std::vector<Vec3f> points_inside;
#if ENABLE_RAYCAST_PICKING
std::vector<unsigned int> points_idxs = m_selection_rectangle.contains(points);
m_selection_rectangle.stop_dragging();
#else
std::vector<unsigned int> points_idxs = m_selection_rectangle.stop_dragging(m_parent, points);
#endif // ENABLE_RAYCAST_PICKING
for (size_t idx : points_idxs)
points_inside.push_back(points[idx].cast<float>());

View file

@ -234,8 +234,13 @@ Vec3f MeshRaycaster::get_triangle_normal(size_t facet_idx) const
return m_normals[facet_idx];
}
#if ENABLE_RAYCAST_PICKING
void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3d& point, Vec3d& direction)
#else
void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3d& point, Vec3d& direction) const
#endif // ENABLE_RAYCAST_PICKING
{
Matrix4d modelview = camera.get_view_matrix().matrix();
Matrix4d projection= camera.get_projection_matrix().matrix();
@ -243,9 +248,9 @@ void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3
Vec3d pt1;
Vec3d pt2;
igl::unproject(Vec3d(mouse_pos(0), viewport[3] - mouse_pos(1), 0.),
igl::unproject(Vec3d(mouse_pos.x(), viewport[3] - mouse_pos.y(), 0.),
modelview, projection, viewport, pt1);
igl::unproject(Vec3d(mouse_pos(0), viewport[3] - mouse_pos(1), 1.),
igl::unproject(Vec3d(mouse_pos.x(), viewport[3] - mouse_pos.y(), 1.),
modelview, projection, viewport, pt2);
Transform3d inv = trafo.inverse();

View file

@ -136,7 +136,11 @@ public:
, m_emesh(*mesh, true) // calculate epsilon for triangle-ray intersection from an average edge length
, m_normals(its_face_normals(mesh->its))
{
assert(m_mesh != nullptr);
}
static void line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3d& point, Vec3d& direction);
#else
// The class references extern TriangleMesh, which must stay alive
// during MeshRaycaster existence.
@ -145,10 +149,10 @@ public:
, m_normals(its_face_normals(mesh.its))
{
}
#endif // ENABLE_RAYCAST_PICKING
void line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3d& point, Vec3d& direction) const;
Vec3d& point, Vec3d& direction) const;
#endif // ENABLE_RAYCAST_PICKING
// Given a mouse position, this returns true in case it is on the mesh.
bool unproject_on_mesh(

View file

@ -104,7 +104,7 @@ SceneRaycaster::HitResult SceneRaycaster::hit(const Vec2d& mouse_pos, const Came
HitResult ret;
auto test_raycasters = [&](EType type) {
auto test_raycasters = [this, is_closest, clipping_plane](EType type, const Vec2d& mouse_pos, const Camera& camera, HitResult& ret) {
const ClippingPlane* clip_plane = (clipping_plane != nullptr && type == EType::Volume) ? clipping_plane : nullptr;
std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = get_raycasters(type);
HitResult current_hit = { type };
@ -126,13 +126,13 @@ SceneRaycaster::HitResult SceneRaycaster::hit(const Vec2d& mouse_pos, const Came
};
if (!m_gizmos.empty())
test_raycasters(EType::Gizmo);
test_raycasters(EType::Gizmo, mouse_pos, camera, ret);
if (!m_gizmos_on_top || !ret.is_valid()) {
if (camera.is_looking_downward() && !m_bed.empty())
test_raycasters(EType::Bed);
test_raycasters(EType::Bed, mouse_pos, camera, ret);
if (!m_volumes.empty())
test_raycasters(EType::Volume);
test_raycasters(EType::Volume, mouse_pos, camera, ret);
}
if (ret.is_valid())

View file

@ -5,7 +5,6 @@
#include "MeshUtils.hpp"
#include "GLModel.hpp"
#include <vector>
#include <string>
#include <optional>