Tech ENABLE_RAYCAST_PICKING set as default

This commit is contained in:
enricoturri1966 2022-12-05 10:24:30 +01:00
parent e04e8c55cf
commit 6f18f8f784
39 changed files with 30 additions and 1046 deletions

View File

@ -762,9 +762,7 @@ public:
// The triangular model. // The triangular model.
const TriangleMesh& mesh() const { return *m_mesh.get(); } const TriangleMesh& mesh() const { return *m_mesh.get(); }
#if ENABLE_RAYCAST_PICKING
std::shared_ptr<const TriangleMesh> mesh_ptr() const { return m_mesh; } std::shared_ptr<const TriangleMesh> mesh_ptr() const { return m_mesh; }
#endif // ENABLE_RAYCAST_PICKING
void set_mesh(const TriangleMesh &mesh) { m_mesh = std::make_shared<const TriangleMesh>(mesh); } void set_mesh(const TriangleMesh &mesh) { m_mesh = std::make_shared<const TriangleMesh>(mesh); }
void set_mesh(TriangleMesh &&mesh) { m_mesh = std::make_shared<const TriangleMesh>(std::move(mesh)); } void set_mesh(TriangleMesh &&mesh) { m_mesh = std::make_shared<const TriangleMesh>(std::move(mesh)); }
void set_mesh(const indexed_triangle_set &mesh) { m_mesh = std::make_shared<const TriangleMesh>(mesh); } void set_mesh(const indexed_triangle_set &mesh) { m_mesh = std::make_shared<const TriangleMesh>(mesh); }

View File

@ -28,6 +28,8 @@
#define DISABLE_GCODEVIEWER_INSTANCED_MODELS 1 #define DISABLE_GCODEVIEWER_INSTANCED_MODELS 1
// Enable Measure Gizmo debug window // Enable Measure Gizmo debug window
#define ENABLE_MEASURE_GIZMO_DEBUG 0 #define ENABLE_MEASURE_GIZMO_DEBUG 0
// Enable scene raycast picking debug window
#define ENABLE_RAYCAST_PICKING_DEBUG 0
// Enable rendering of objects using environment map // Enable rendering of objects using environment map
@ -61,9 +63,6 @@
#define ENABLE_PROCESS_G2_G3_LINES (1 && ENABLE_2_6_0_ALPHA1) #define ENABLE_PROCESS_G2_G3_LINES (1 && ENABLE_2_6_0_ALPHA1)
// Enable fix of used filament data exported to gcode file // Enable fix of used filament data exported to gcode file
#define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_6_0_ALPHA1) #define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_6_0_ALPHA1)
// Enable picking using raytracing
#define ENABLE_RAYCAST_PICKING (1 && ENABLE_LEGACY_OPENGL_REMOVAL)
#define ENABLE_RAYCAST_PICKING_DEBUG (0 && ENABLE_RAYCAST_PICKING)
#endif // _prusaslicer_technologies_h_ #endif // _prusaslicer_technologies_h_

View File

@ -252,10 +252,8 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c
m_axes.set_origin({ 0.0, 0.0, static_cast<double>(GROUND_Z) }); m_axes.set_origin({ 0.0, 0.0, static_cast<double>(GROUND_Z) });
m_axes.set_stem_length(0.1f * static_cast<float>(m_build_volume.bounding_volume().max_size())); m_axes.set_stem_length(0.1f * static_cast<float>(m_build_volume.bounding_volume().max_size()));
#if ENABLE_RAYCAST_PICKING
// unregister from picking // unregister from picking
wxGetApp().plater()->canvas3D()->remove_raycasters_for_picking(SceneRaycaster::EType::Bed); wxGetApp().plater()->canvas3D()->remove_raycasters_for_picking(SceneRaycaster::EType::Bed);
#endif // ENABLE_RAYCAST_PICKING
// Let the calee to update the UI. // Let the calee to update the UI.
return true; return true;
@ -309,11 +307,7 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor,
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_model.model.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); 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
#else #else
m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -355,11 +349,7 @@ BoundingBoxf3 Bed3D::calc_extended_bounding_box() const
out.merge(out.min + Vec3d(-Axes::DefaultTipRadius, -Axes::DefaultTipRadius, out.max.z())); out.merge(out.min + Vec3d(-Axes::DefaultTipRadius, -Axes::DefaultTipRadius, out.max.z()));
#endif // ENABLE_WORLD_COORDINATE #endif // ENABLE_WORLD_COORDINATE
// extend to contain model, if any // extend to contain model, if any
#if ENABLE_RAYCAST_PICKING
BoundingBoxf3 model_bb = m_model.model.get_bounding_box(); BoundingBoxf3 model_bb = m_model.model.get_bounding_box();
#else
BoundingBoxf3 model_bb = m_model.get_bounding_box();
#endif // ENABLE_RAYCAST_PICKING
if (model_bb.defined) { if (model_bb.defined) {
model_bb.translate(m_model_offset); model_bb.translate(m_model_offset);
out.merge(model_bb); out.merge(model_bb);
@ -409,16 +399,12 @@ void Bed3D::init_triangles()
init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1);
} }
#if ENABLE_RAYCAST_PICKING
if (m_model.model.get_filename().empty() && m_model.mesh_raycaster == nullptr) if (m_model.model.get_filename().empty() && m_model.mesh_raycaster == nullptr)
// register for picking // register for picking
register_raycasters_for_picking(init_data, Transform3d::Identity()); register_raycasters_for_picking(init_data, Transform3d::Identity());
#endif // ENABLE_RAYCAST_PICKING
m_triangles.init_from(std::move(init_data)); m_triangles.init_from(std::move(init_data));
#if ENABLE_RAYCAST_PICKING
m_triangles.set_color(DEFAULT_MODEL_COLOR); m_triangles.set_color(DEFAULT_MODEL_COLOR);
#endif // ENABLE_RAYCAST_PICKING
} }
void Bed3D::init_gridlines() void Bed3D::init_gridlines()
@ -798,17 +784,9 @@ void Bed3D::render_model()
if (m_model_filename.empty()) if (m_model_filename.empty())
return; return;
#if ENABLE_RAYCAST_PICKING
if (m_model.model.get_filename() != m_model_filename && m_model.model.init_from_file(m_model_filename)) { if (m_model.model.get_filename() != m_model_filename && m_model.model.init_from_file(m_model_filename)) {
#else
if (m_model.get_filename() != m_model_filename && m_model.init_from_file(m_model_filename)) {
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_model.model.set_color(DEFAULT_MODEL_COLOR); m_model.model.set_color(DEFAULT_MODEL_COLOR);
#else
m_model.set_color(DEFAULT_MODEL_COLOR);
#endif // ENABLE_RAYCAST_PICKING
#else #else
m_model.set_color(-1, DEFAULT_MODEL_COLOR); m_model.set_color(-1, DEFAULT_MODEL_COLOR);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -816,20 +794,14 @@ void Bed3D::render_model()
// move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad // move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad
m_model_offset = to_3d(m_build_volume.bounding_volume2d().center(), -0.03); m_model_offset = to_3d(m_build_volume.bounding_volume2d().center(), -0.03);
#if ENABLE_RAYCAST_PICKING
// register for picking // register for picking
register_raycasters_for_picking(m_model.model.get_geometry(), Geometry::translation_transform(m_model_offset)); register_raycasters_for_picking(m_model.model.get_geometry(), Geometry::translation_transform(m_model_offset));
#endif // ENABLE_RAYCAST_PICKING
// update extended bounding box // update extended bounding box
m_extended_bounding_box = this->calc_extended_bounding_box(); m_extended_bounding_box = this->calc_extended_bounding_box();
} }
#if ENABLE_RAYCAST_PICKING
if (!m_model.model.get_filename().empty()) { if (!m_model.model.get_filename().empty()) {
#else
if (!m_model.get_filename().empty()) {
#endif // ENABLE_RAYCAST_PICKING
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
@ -844,11 +816,7 @@ void Bed3D::render_model()
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(m_model_offset.x(), m_model_offset.y(), m_model_offset.z())); glsafe(::glTranslated(m_model_offset.x(), m_model_offset.y(), m_model_offset.z()));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_model.model.render(); m_model.model.render();
#else
m_model.render();
#endif // ENABLE_RAYCAST_PICKING
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
@ -914,23 +882,14 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture)
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
#if ENABLE_RAYCAST_PICKING
const bool has_model = !m_model.model.get_filename().empty(); const bool has_model = !m_model.model.get_filename().empty();
#else
const bool has_model = !m_model.get_filename().empty();
#endif // ENABLE_RAYCAST_PICKING
if (!has_model && !bottom) { if (!has_model && !bottom) {
// draw background // draw background
glsafe(::glDepthMask(GL_FALSE)); glsafe(::glDepthMask(GL_FALSE));
#if !ENABLE_RAYCAST_PICKING
m_triangles.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR);
#endif // !ENABLE_RAYCAST_PICKING
m_triangles.render(); m_triangles.render();
glsafe(::glDepthMask(GL_TRUE)); glsafe(::glDepthMask(GL_TRUE));
} }
#if ENABLE_RAYCAST_PICKING
if (show_texture) { if (show_texture) {
// draw grid // draw grid
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
@ -942,19 +901,6 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture)
} }
else else
render_contour(view_matrix, projection_matrix); render_contour(view_matrix, projection_matrix);
#else
if (!picking && show_texture) {
// draw grid
#if ENABLE_GL_CORE_PROFILE
if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f * m_scale_factor));
m_gridlines.set_color(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR : DEFAULT_TRANSPARENT_GRID_COLOR);
m_gridlines.render();
}
else if (!show_texture)
render_contour(view_matrix, projection_matrix);
#endif // ENABLE_RAYCAST_PICKING
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
@ -1047,7 +993,6 @@ void Bed3D::release_VBOs()
} }
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
void Bed3D::register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo) void Bed3D::register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo)
{ {
assert(m_model.mesh_raycaster == nullptr); assert(m_model.mesh_raycaster == nullptr);
@ -1066,7 +1011,6 @@ void Bed3D::register_raycasters_for_picking(const GLModel::Geometry& geometry, c
m_model.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its))); m_model.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its)));
wxGetApp().plater()->canvas3D()->add_raycaster_for_picking(SceneRaycaster::EType::Bed, 0, *m_model.mesh_raycaster, trafo); wxGetApp().plater()->canvas3D()->add_raycaster_for_picking(SceneRaycaster::EType::Bed, 0, *m_model.mesh_raycaster, trafo);
} }
#endif // ENABLE_RAYCAST_PICKING
} // GUI } // GUI
} // Slic3r } // Slic3r

View File

@ -8,9 +8,7 @@
#else #else
#include "GLModel.hpp" #include "GLModel.hpp"
#endif // ENABLE_WORLD_COORDINATE #endif // ENABLE_WORLD_COORDINATE
#if ENABLE_RAYCAST_PICKING
#include "MeshUtils.hpp" #include "MeshUtils.hpp"
#endif // ENABLE_RAYCAST_PICKING
#include "libslic3r/BuildVolume.hpp" #include "libslic3r/BuildVolume.hpp"
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
@ -111,11 +109,7 @@ private:
GLTexture m_texture; GLTexture m_texture;
// temporary texture shown until the main texture has still no levels compressed // temporary texture shown until the main texture has still no levels compressed
GLTexture m_temp_texture; GLTexture m_temp_texture;
#if ENABLE_RAYCAST_PICKING
PickingModel m_model; PickingModel m_model;
#else
GLModel m_model;
#endif // ENABLE_RAYCAST_PICKING
Vec3d m_model_offset{ Vec3d::Zero() }; Vec3d m_model_offset{ Vec3d::Zero() };
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
unsigned int m_vbo_id{ 0 }; unsigned int m_vbo_id{ 0 };
@ -205,9 +199,7 @@ private:
void release_VBOs(); void release_VBOs();
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
void register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo); void register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo);
#endif // ENABLE_RAYCAST_PICKING
}; };
} // GUI } // GUI

View File

@ -807,27 +807,17 @@ int GLVolumeCollection::load_object_volume(
const ModelVolume *model_volume = model_object->volumes[volume_idx]; const ModelVolume *model_volume = model_object->volumes[volume_idx];
const int extruder_id = model_volume->extruder_id(); const int extruder_id = model_volume->extruder_id();
const ModelInstance *instance = model_object->instances[instance_idx]; const ModelInstance *instance = model_object->instances[instance_idx];
#if ENABLE_RAYCAST_PICKING
std::shared_ptr<const TriangleMesh> mesh = model_volume->mesh_ptr(); std::shared_ptr<const TriangleMesh> mesh = model_volume->mesh_ptr();
#else
const TriangleMesh &mesh = model_volume->mesh();
#endif // ENABLE_RAYCAST_PICKING
this->volumes.emplace_back(new GLVolume()); this->volumes.emplace_back(new GLVolume());
GLVolume& v = *this->volumes.back(); GLVolume& v = *this->volumes.back();
v.set_color(color_from_model_volume(*model_volume)); v.set_color(color_from_model_volume(*model_volume));
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
v.model.init_from(*mesh, true); v.model.init_from(*mesh, true);
#if ENABLE_RAYCAST_PICKING
v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(mesh); v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(mesh);
#endif // ENABLE_RAYCAST_PICKING
#else #else
#if ENABLE_RAYCAST_PICKING
v.model.init_from(*mesh); v.model.init_from(*mesh);
v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(mesh); v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(mesh);
#else
v.model.init_from(mesh);
#endif // ENABLE_RAYCAST_PICKING
#endif // ENABLE_SMOOTH_NORMALS #endif // ENABLE_SMOOTH_NORMALS
#else #else
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
@ -893,9 +883,7 @@ void GLVolumeCollection::load_object_auxiliary(
#else #else
v.model.init_from(mesh); v.model.init_from(mesh);
v.model.set_color((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR); v.model.set_color((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR);
#if ENABLE_RAYCAST_PICKING
v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<const TriangleMesh>(mesh)); v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<const TriangleMesh>(mesh));
#endif // ENABLE_RAYCAST_PICKING
#endif // ENABLE_SMOOTH_NORMALS #endif // ENABLE_SMOOTH_NORMALS
#else #else
#if ENABLE_SMOOTH_NORMALS #if ENABLE_SMOOTH_NORMALS
@ -954,13 +942,10 @@ int GLVolumeCollection::load_wipe_tower_preview(
depth = std::max(depth, 10.f); depth = std::max(depth, 10.f);
float min_width = 30.f; float min_width = 30.f;
#if ENABLE_RAYCAST_PICKING
const float scaled_brim_height = 0.2f / height; const float scaled_brim_height = 0.2f / height;
#endif // ENABLE_RAYCAST_PICKING
// We'll now create the box with jagged edge. y-coordinates of the pre-generated model // We'll now create the box with jagged edge. y-coordinates of the pre-generated model
// are shifted so that the front edge has y=0 and centerline of the back edge has y=depth: // are shifted so that the front edge has y=0 and centerline of the back edge has y=depth:
#if ENABLE_RAYCAST_PICKING
// We split the box in three main pieces, // We split the box in three main pieces,
// the two laterals are identical and the central is the one containing the jagged geometry // the two laterals are identical and the central is the one containing the jagged geometry
@ -1061,22 +1046,6 @@ int GLVolumeCollection::load_wipe_tower_preview(
tooth_mesh.merge(TriangleMesh(std::move(data))); tooth_mesh.merge(TriangleMesh(std::move(data)));
data = generate_lateral(61.547f, 100.0f); data = generate_lateral(61.547f, 100.0f);
tooth_mesh.merge(TriangleMesh(std::move(data))); tooth_mesh.merge(TriangleMesh(std::move(data)));
#else
float out_points_idx[][3] = { { 0, -depth, 0 }, { 0, 0, 0 }, { 38.453f, 0, 0 }, { 61.547f, 0, 0 }, { 100.0f, 0, 0 }, { 100.0f, -depth, 0 }, { 55.7735f, -10.0f, 0 }, { 44.2265f, 10.0f, 0 },
{ 38.453f, 0, 1 }, { 0, 0, 1 }, { 0, -depth, 1 }, { 100.0f, -depth, 1 }, { 100.0f, 0, 1 }, { 61.547f, 0, 1 }, { 55.7735f, -10.0f, 1 }, { 44.2265f, 10.0f, 1 } };
static constexpr const int out_facets_idx[][3] = {
{ 0, 1, 2 }, { 3, 4, 5 }, { 6, 5, 0 }, { 3, 5, 6 }, { 6, 2, 7 }, { 6, 0, 2 }, { 8, 9, 10 }, { 11, 12, 13 }, { 10, 11, 14 }, { 14, 11, 13 }, { 15, 8, 14 },
{ 8, 10, 14 }, { 3, 12, 4 }, { 3, 13, 12 }, { 6, 13, 3 }, { 6, 14, 13 }, { 7, 14, 6 }, { 7, 15, 14 }, { 2, 15, 7 }, { 2, 8, 15 }, { 1, 8, 2 }, { 1, 9, 8 },
{ 0, 9, 1 }, { 0, 10, 9 }, { 5, 10, 0 }, { 5, 11, 10 }, { 4, 11, 5 }, { 4, 12, 11 } };
indexed_triangle_set its;
for (int i = 0; i < 16; ++i)
its.vertices.emplace_back(out_points_idx[i][0] / (100.f / min_width),
out_points_idx[i][1] + depth, out_points_idx[i][2]);
its.indices.reserve(28);
for (const int *face : out_facets_idx)
its.indices.emplace_back(face);
TriangleMesh tooth_mesh(std::move(its));
#endif // ENABLE_RAYCAST_PICKING
// We have the mesh ready. It has one tooth and width of min_width. We will now // We have the mesh ready. It has one tooth and width of min_width. We will now
// append several of these together until we are close to the required width // append several of these together until we are close to the required width
@ -1084,14 +1053,9 @@ int GLVolumeCollection::load_wipe_tower_preview(
size_t n = std::max(1, int(width / min_width)); // How many shall be merged? size_t n = std::max(1, int(width / min_width)); // How many shall be merged?
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i) {
mesh.merge(tooth_mesh); mesh.merge(tooth_mesh);
#if ENABLE_RAYCAST_PICKING
tooth_mesh.translate(100.0f, 0.0f, 0.0f); tooth_mesh.translate(100.0f, 0.0f, 0.0f);
#else
tooth_mesh.translate(min_width, 0.f, 0.f);
#endif // ENABLE_RAYCAST_PICKING
} }
#if ENABLE_RAYCAST_PICKING
// Now we add the caps along the X axis // Now we add the caps along the X axis
const float scaled_brim_width_x = brim_width * n * width / min_width; const float scaled_brim_width_x = brim_width * n * width / min_width;
auto generate_negx_cap = [&]() { auto generate_negx_cap = [&]() {
@ -1166,20 +1130,10 @@ int GLVolumeCollection::load_wipe_tower_preview(
data = generate_posx_cap(); data = generate_posx_cap();
mesh.merge(TriangleMesh(std::move(data))); mesh.merge(TriangleMesh(std::move(data)));
mesh.scale(Vec3f(width / (n * 100.0f), 1.0f, height)); // Scaling to proper width mesh.scale(Vec3f(width / (n * 100.0f), 1.0f, height)); // Scaling to proper width
#else
mesh.scale(Vec3f(width / (n * min_width), 1.f, height)); // Scaling to proper width
#endif // ENABLE_RAYCAST_PICKING
} }
else else
mesh = make_cube(width, depth, height); mesh = make_cube(width, depth, height);
#if !ENABLE_RAYCAST_PICKING
// We'll make another mesh to show the brim (fixed layer height):
TriangleMesh brim_mesh = make_cube(width + 2.f * brim_width, depth + 2.f * brim_width, 0.2f);
brim_mesh.translate(-brim_width, -brim_width, 0.f);
mesh.merge(brim_mesh);
#endif // !ENABLE_RAYCAST_PICKING
volumes.emplace_back(new GLVolume(color)); volumes.emplace_back(new GLVolume(color));
GLVolume& v = *volumes.back(); GLVolume& v = *volumes.back();
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
@ -1189,9 +1143,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
#endif // ENABLE_OPENGL_ES #endif // ENABLE_OPENGL_ES
v.model.init_from(mesh); v.model.init_from(mesh);
v.model.set_color(color); v.model.set_color(color);
#if ENABLE_RAYCAST_PICKING
v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<const TriangleMesh>(mesh)); v.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<const TriangleMesh>(mesh));
#endif // ENABLE_RAYCAST_PICKING
#else #else
v.indexed_vertex_array.load_mesh(mesh); v.indexed_vertex_array.load_mesh(mesh);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL

View File

@ -10,9 +10,7 @@
#include "libslic3r/Color.hpp" #include "libslic3r/Color.hpp"
#include "GLModel.hpp" #include "GLModel.hpp"
#if ENABLE_RAYCAST_PICKING
#include "MeshUtils.hpp" #include "MeshUtils.hpp"
#endif // ENABLE_RAYCAST_PICKING
#include <functional> #include <functional>
#include <optional> #include <optional>
@ -393,10 +391,8 @@ public:
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GUI::GLModel model; GUI::GLModel model;
#if ENABLE_RAYCAST_PICKING
// raycaster used for picking // raycaster used for picking
std::unique_ptr<GUI::MeshRaycaster> mesh_raycaster; std::unique_ptr<GUI::MeshRaycaster> mesh_raycaster;
#endif // ENABLE_RAYCAST_PICKING
#else #else
// Interleaved triangles & normals with indexed triangles & quads. // Interleaved triangles & normals with indexed triangles & quads.
GLIndexedVertexArray indexed_vertex_array; GLIndexedVertexArray indexed_vertex_array;

View File

@ -91,7 +91,6 @@ void Camera::select_view(const std::string& direction)
look_at(m_target + m_distance * Vec3d::UnitY(), m_target, Vec3d::UnitZ()); look_at(m_target + m_distance * Vec3d::UnitY(), m_target, Vec3d::UnitZ());
} }
#if ENABLE_RAYCAST_PICKING
double Camera::get_near_left() const double Camera::get_near_left() const
{ {
switch (m_type) switch (m_type)
@ -163,7 +162,6 @@ double Camera::get_near_height() const
return 2.0 / m_projection_matrix.matrix()(1, 1); return 2.0 / m_projection_matrix.matrix()(1, 1);
} }
} }
#endif // ENABLE_RAYCAST_PICKING
double Camera::get_fov() const double Camera::get_fov() const
{ {
@ -177,7 +175,6 @@ double Camera::get_fov() const
}; };
} }
#if ENABLE_RAYCAST_PICKING
void Camera::set_viewport(int x, int y, unsigned int w, unsigned int h) void Camera::set_viewport(int x, int y, unsigned int w, unsigned int h)
{ {
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
@ -191,17 +188,6 @@ void Camera::apply_viewport() const
{ {
glsafe(::glViewport(m_viewport[0], m_viewport[1], m_viewport[2], m_viewport[3])); glsafe(::glViewport(m_viewport[0], m_viewport[1], m_viewport[2], m_viewport[3]));
} }
#else
void Camera::apply_viewport(int x, int y, unsigned int w, unsigned int h)
{
glsafe(::glViewport(0, 0, w, h));
#if ENABLE_LEGACY_OPENGL_REMOVAL
m_viewport = { 0, 0, int(w), int(h) };
#else
glsafe(::glGetIntegerv(GL_VIEWPORT, m_viewport.data()));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
}
#endif // ENABLE_RAYCAST_PICKING
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
void Camera::apply_view_matrix() void Camera::apply_view_matrix()
@ -260,37 +246,7 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa
} }
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
apply_projection(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second); apply_projection(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second);
#else
switch (m_type)
{
default:
case EType::Ortho:
{
const double dz = m_frustrum_zs.second - m_frustrum_zs.first;
const double zz = m_frustrum_zs.first + m_frustrum_zs.second;
m_projection_matrix.matrix() << 1.0 / w, 0.0, 0.0, 0.0,
0.0, 1.0 / h, 0.0, 0.0,
0.0, 0.0, -2.0 / dz, -zz / dz,
0.0, 0.0, 0.0, 1.0;
break;
}
case EType::Perspective:
{
const double n = m_frustrum_zs.first;
const double f = m_frustrum_zs.second;
const double dz = f - n;
const double zz = n + f;
const double fn = n * f;
m_projection_matrix.matrix() << n / w, 0.0, 0.0, 0.0,
0.0, n / h, 0.0, 0.0,
0.0, 0.0, -zz / dz, -2.0 * fn / dz,
0.0, 0.0, -1.0, 0.0;
break;
}
}
#endif // ENABLE_RAYCAST_PICKING
#else #else
glsafe(::glMatrixMode(GL_PROJECTION)); glsafe(::glMatrixMode(GL_PROJECTION));
glsafe(::glLoadIdentity()); glsafe(::glLoadIdentity());
@ -315,7 +271,6 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_RAYCAST_PICKING
void Camera::apply_projection(double left, double right, double bottom, double top, double near_z, double far_z) void Camera::apply_projection(double left, double right, double bottom, double top, double near_z, double far_z)
{ {
assert(left != right && bottom != top && near_z != far_z); assert(left != right && bottom != top && near_z != far_z);
@ -344,7 +299,6 @@ void Camera::apply_projection(double left, double right, double bottom, double t
} }
} }
} }
#endif // ENABLE_RAYCAST_PICKING
void Camera::zoom_to_box(const BoundingBoxf3& box, double margin_factor) void Camera::zoom_to_box(const BoundingBoxf3& box, double margin_factor)
{ {

View File

@ -89,33 +89,24 @@ public:
double get_far_z() const { return m_frustrum_zs.second; } double get_far_z() const { return m_frustrum_zs.second; }
const std::pair<double, double>& get_z_range() const { return m_frustrum_zs; } const std::pair<double, double>& get_z_range() const { return m_frustrum_zs; }
#if ENABLE_RAYCAST_PICKING
double get_near_left() const; double get_near_left() const;
double get_near_right() const; double get_near_right() const;
double get_near_top() const; double get_near_top() const;
double get_near_bottom() const; double get_near_bottom() const;
double get_near_width() const; double get_near_width() const;
double get_near_height() const; double get_near_height() const;
#endif // ENABLE_RAYCAST_PICKING
double get_fov() const; double get_fov() const;
#if ENABLE_RAYCAST_PICKING
void set_viewport(int x, int y, unsigned int w, unsigned int h); void set_viewport(int x, int y, unsigned int w, unsigned int h);
void apply_viewport() const; void apply_viewport() const;
#else
void apply_viewport(int x, int y, unsigned int w, unsigned int h);
#endif // ENABLE_RAYCAST_PICKING
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
void apply_view_matrix(); void apply_view_matrix();
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
// Calculates and applies the projection matrix tighting the frustrum z range around the given box. // Calculates and applies the projection matrix tighting the frustrum z range around the given box.
// If larger z span is needed, pass the desired values of near and far z (negative values are ignored) // If larger z span is needed, pass the desired values of near and far z (negative values are ignored)
void apply_projection(const BoundingBoxf3& box, double near_z = -1.0, double far_z = -1.0); void apply_projection(const BoundingBoxf3& box, double near_z = -1.0, double far_z = -1.0);
#if ENABLE_RAYCAST_PICKING
void apply_projection(double left, double right, double bottom, double top, double near_z, double far_z); void apply_projection(double left, double right, double bottom, double top, double near_z, double far_z);
#endif // ENABLE_RAYCAST_PICKING
void zoom_to_box(const BoundingBoxf3& box, double margin_factor = DefaultZoomToBoxMarginFactor); void zoom_to_box(const BoundingBoxf3& box, double margin_factor = DefaultZoomToBoxMarginFactor);
void zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor = DefaultZoomToVolumesMarginFactor); void zoom_to_volumes(const GLVolumePtrs& volumes, double margin_factor = DefaultZoomToVolumesMarginFactor);

View File

@ -1346,13 +1346,10 @@ void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible, const ModelObje
m_render_sla_auxiliaries = visible; m_render_sla_auxiliaries = visible;
#if ENABLE_RAYCAST_PICKING
std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume); std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume);
#endif // ENABLE_RAYCAST_PICKING
for (GLVolume* vol : m_volumes.volumes) { for (GLVolume* vol : m_volumes.volumes) {
#if ENABLE_RAYCAST_PICKING if ((mo == nullptr || m_model->objects[vol->composite_id.object_id] == mo)
if ((mo == nullptr || m_model->objects[vol->composite_id.object_id] == mo)
&& (instance_idx == -1 || vol->composite_id.instance_id == instance_idx) && (instance_idx == -1 || vol->composite_id.instance_id == instance_idx)
&& vol->composite_id.volume_id < 0) { && vol->composite_id.volume_id < 0) {
vol->is_active = visible; vol->is_active = visible;
@ -1360,20 +1357,12 @@ void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible, const ModelObje
if (it != raycasters->end()) if (it != raycasters->end())
(*it)->set_active(vol->is_active); (*it)->set_active(vol->is_active);
} }
#else
if ((mo == nullptr || m_model->objects[vol->composite_id.object_id] == mo)
&& (instance_idx == -1 || vol->composite_id.instance_id == instance_idx)
&& vol->composite_id.volume_id < 0)
vol->is_active = visible;
#endif // ENABLE_RAYCAST_PICKING
} }
} }
void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject* mo, int instance_idx, const ModelVolume* mv) void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject* mo, int instance_idx, const ModelVolume* mv)
{ {
#if ENABLE_RAYCAST_PICKING
std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume); std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = get_raycasters_for_picking(SceneRaycaster::EType::Volume);
#endif // ENABLE_RAYCAST_PICKING
for (GLVolume* vol : m_volumes.volumes) { for (GLVolume* vol : m_volumes.volumes) {
if (vol->is_wipe_tower) if (vol->is_wipe_tower)
vol->is_active = (visible && mo == nullptr); vol->is_active = (visible && mo == nullptr);
@ -1404,11 +1393,10 @@ void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject
} }
} }
} }
#if ENABLE_RAYCAST_PICKING
auto it = std::find_if(raycasters->begin(), raycasters->end(), [vol](std::shared_ptr<SceneRaycasterItem> item) { return item->get_raycaster() == vol->mesh_raycaster.get(); }); auto it = std::find_if(raycasters->begin(), raycasters->end(), [vol](std::shared_ptr<SceneRaycasterItem> item) { return item->get_raycaster() == vol->mesh_raycaster.get(); });
if (it != raycasters->end()) if (it != raycasters->end())
(*it)->set_active(vol->is_active); (*it)->set_active(vol->is_active);
#endif // ENABLE_RAYCAST_PICKING
} }
if (visible && !mo) if (visible && !mo)
@ -1666,12 +1654,8 @@ void GLCanvas3D::render()
// and the viewport was set incorrectly, leading to tripping glAsserts further down // and the viewport was set incorrectly, leading to tripping glAsserts further down
// the road (in apply_projection). That's why the minimum size is forced to 10. // the road (in apply_projection). That's why the minimum size is forced to 10.
Camera& camera = wxGetApp().plater()->get_camera(); Camera& camera = wxGetApp().plater()->get_camera();
#if ENABLE_RAYCAST_PICKING
camera.set_viewport(0, 0, std::max(10u, (unsigned int)cnv_size.get_width()), std::max(10u, (unsigned int)cnv_size.get_height())); camera.set_viewport(0, 0, std::max(10u, (unsigned int)cnv_size.get_width()), std::max(10u, (unsigned int)cnv_size.get_height()));
camera.apply_viewport(); camera.apply_viewport();
#else
camera.apply_viewport(0, 0, std::max(10u, (unsigned int)cnv_size.get_width()), std::max(10u, (unsigned int)cnv_size.get_height()));
#endif // ENABLE_RAYCAST_PICKING
if (camera.requires_zoom_to_bed) { if (camera.requires_zoom_to_bed) {
zoom_to_bed(); zoom_to_bed();
@ -2266,9 +2250,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
#else #else
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
volume.model.init_from(mesh); volume.model.init_from(mesh);
#if ENABLE_RAYCAST_PICKING
volume.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<TriangleMesh>(mesh)); volume.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<TriangleMesh>(mesh));
#endif // ENABLE_RAYCAST_PICKING
#else #else
volume.indexed_vertex_array.load_mesh(mesh); volume.indexed_vertex_array.load_mesh(mesh);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -2284,13 +2266,9 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#else #else
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING const TriangleMesh& new_mesh = m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh();
const TriangleMesh& new_mesh = m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh();
volume.model.init_from(new_mesh); volume.model.init_from(new_mesh);
volume.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<TriangleMesh>(new_mesh)); volume.mesh_raycaster = std::make_unique<GUI::MeshRaycaster>(std::make_shared<TriangleMesh>(new_mesh));
#else
volume.model.init_from(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh());
#endif // ENABLE_RAYCAST_PICKING
#else #else
volume.indexed_vertex_array.load_mesh(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh()); volume.indexed_vertex_array.load_mesh(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh());
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -2447,7 +2425,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
manip->set_dirty(); manip->set_dirty();
} }
#if ENABLE_RAYCAST_PICKING
// refresh volume raycasters for picking // refresh volume raycasters for picking
m_scene_raycaster.remove_raycasters(SceneRaycaster::EType::Volume); m_scene_raycaster.remove_raycasters(SceneRaycaster::EType::Volume);
for (size_t i = 0; i < m_volumes.volumes.size(); ++i) { for (size_t i = 0; i < m_volumes.volumes.size(); ++i) {
@ -2464,7 +2441,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
m_scene_raycaster.remove_raycasters(SceneRaycaster::EType::Gizmo); m_scene_raycaster.remove_raycasters(SceneRaycaster::EType::Gizmo);
if (curr_gizmo != nullptr && !m_selection.is_empty()) if (curr_gizmo != nullptr && !m_selection.is_empty())
curr_gizmo->register_raycasters_for_picking(); curr_gizmo->register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
// and force this canvas to be redrawn. // and force this canvas to be redrawn.
m_dirty = true; m_dirty = true;
@ -3010,11 +2986,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt)
// set_cursor(Standard); // set_cursor(Standard);
} }
else if (keyCode == WXK_CONTROL) { else if (keyCode == WXK_CONTROL) {
#if ENABLE_RAYCAST_PICKING if (m_mouse.dragging && !m_moving) {
if (m_mouse.dragging && !m_moving) {
#else
if (m_mouse.dragging) {
#endif // ENABLE_RAYCAST_PICKING
// if the user releases CTRL while rotating the 3D scene // if the user releases CTRL while rotating the 3D scene
// prevent from moving the selected volume // prevent from moving the selected volume
m_mouse.drag.move_volume_idx = -1; m_mouse.drag.move_volume_idx = -1;
@ -3530,9 +3502,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if (!evt.CmdDown()) if (!evt.CmdDown())
m_mouse.drag.start_position_3D = m_mouse.scene_position; m_mouse.drag.start_position_3D = m_mouse.scene_position;
m_sequential_print_clearance_first_displacement = true; m_sequential_print_clearance_first_displacement = true;
#if !ENABLE_RAYCAST_PICKING
m_moving = true;
#endif // !ENABLE_RAYCAST_PICKING
} }
} }
} }
@ -3576,9 +3545,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
#if ENABLE_RAYCAST_PICKING
m_moving = true; m_moving = true;
#endif // ENABLE_RAYCAST_PICKING
TransformationType trafo_type; TransformationType trafo_type;
trafo_type.set_relative(); trafo_type.set_relative();
m_selection.translate(cur_pos - m_mouse.drag.start_position_3D, trafo_type); m_selection.translate(cur_pos - m_mouse.drag.start_position_3D, trafo_type);
@ -3609,9 +3576,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// do not process the dragging if the left mouse was set down in another canvas // do not process the dragging if the left mouse was set down in another canvas
else if (evt.LeftIsDown()) { else if (evt.LeftIsDown()) {
// if dragging over blank area with left button, rotate // if dragging over blank area with left button, rotate
#if ENABLE_RAYCAST_PICKING
if (!m_moving) { if (!m_moving) {
#endif // ENABLE_RAYCAST_PICKING
if ((any_gizmo_active || evt.CmdDown() || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) { if ((any_gizmo_active || evt.CmdDown() || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) {
const Vec3d rot = (Vec3d(pos.x(), pos.y(), 0.0) - m_mouse.drag.start_position_3D) * (PI * TRACKBALLSIZE / 180.0); const Vec3d rot = (Vec3d(pos.x(), pos.y(), 0.0) - m_mouse.drag.start_position_3D) * (PI * TRACKBALLSIZE / 180.0);
if (wxGetApp().app_config->get("use_free_camera") == "1") if (wxGetApp().app_config->get("use_free_camera") == "1")
@ -3630,9 +3595,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_dirty = true; m_dirty = true;
} }
m_mouse.drag.start_position_3D = Vec3d((double)pos.x(), (double)pos.y(), 0.0); m_mouse.drag.start_position_3D = Vec3d((double)pos.x(), (double)pos.y(), 0.0);
#if ENABLE_RAYCAST_PICKING
} }
#endif // ENABLE_RAYCAST_PICKING
} }
else if (evt.MiddleIsDown() || evt.RightIsDown()) { else if (evt.MiddleIsDown() || evt.RightIsDown()) {
// If dragging over blank area with right/middle button, pan. // If dragging over blank area with right/middle button, pan.
@ -3657,9 +3620,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
} }
else if (evt.LeftUp() || evt.MiddleUp() || evt.RightUp()) { else if (evt.LeftUp() || evt.MiddleUp() || evt.RightUp()) {
#if ENABLE_RAYCAST_PICKING
m_mouse.position = pos.cast<double>(); m_mouse.position = pos.cast<double>();
#endif // ENABLE_RAYCAST_PICKING
if (m_layers_editing.state != LayersEditing::Unknown) { if (m_layers_editing.state != LayersEditing::Unknown) {
m_layers_editing.state = LayersEditing::Unknown; m_layers_editing.state = LayersEditing::Unknown;
@ -3685,9 +3646,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
deselect_all(); deselect_all();
} }
else if (evt.RightUp()) { else if (evt.RightUp()) {
#if !ENABLE_RAYCAST_PICKING
m_mouse.position = pos.cast<double>();
#endif // !ENABLE_RAYCAST_PICKING
// forces a frame render to ensure that m_hover_volume_idxs is updated even when the user right clicks while // forces a frame render to ensure that m_hover_volume_idxs is updated even when the user right clicks while
// the context menu is already shown // the context menu is already shown
render(); render();
@ -4678,12 +4636,8 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const
Camera camera; Camera camera;
camera.set_type(camera_type); camera.set_type(camera_type);
camera.set_scene_box(scene_bounding_box()); camera.set_scene_box(scene_bounding_box());
#if ENABLE_RAYCAST_PICKING
camera.set_viewport(0, 0, thumbnail_data.width, thumbnail_data.height); camera.set_viewport(0, 0, thumbnail_data.width, thumbnail_data.height);
camera.apply_viewport(); camera.apply_viewport();
#else
camera.apply_viewport(0, 0, thumbnail_data.width, thumbnail_data.height);
#endif // ENABLE_RAYCAST_PICKING
camera.zoom_to_box(volumes_box); camera.zoom_to_box(volumes_box);
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
@ -4985,11 +4939,7 @@ void GLCanvas3D::_render_thumbnail_legacy(ThumbnailData& thumbnail_data, unsigne
#endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT #endif // ENABLE_THUMBNAIL_GENERATOR_DEBUG_OUTPUT
// restore the default framebuffer size to avoid flickering on the 3D scene // restore the default framebuffer size to avoid flickering on the 3D scene
#if ENABLE_RAYCAST_PICKING
wxGetApp().plater()->get_camera().apply_viewport(); wxGetApp().plater()->get_camera().apply_viewport();
#else
wxGetApp().plater()->get_camera().apply_viewport(0, 0, cnv_size.get_width(), cnv_size.get_height());
#endif // ENABLE_RAYCAST_PICKING
} }
bool GLCanvas3D::_init_toolbars() bool GLCanvas3D::_init_toolbars()
@ -5456,7 +5406,6 @@ void GLCanvas3D::_refresh_if_shown_on_screen()
} }
} }
#if ENABLE_RAYCAST_PICKING
void GLCanvas3D::_picking_pass() void GLCanvas3D::_picking_pass()
{ {
if (!m_picking_enabled || m_mouse.dragging || m_mouse.position == Vec2d(DBL_MAX, DBL_MAX) || m_gizmos.is_dragging()) { if (!m_picking_enabled || m_mouse.dragging || m_mouse.position == Vec2d(DBL_MAX, DBL_MAX) || m_gizmos.is_dragging()) {
@ -5599,82 +5548,6 @@ void GLCanvas3D::_picking_pass()
imgui.end(); imgui.end();
#endif // ENABLE_RAYCAST_PICKING_DEBUG #endif // ENABLE_RAYCAST_PICKING_DEBUG
} }
#else
void GLCanvas3D::_picking_pass()
{
if (m_picking_enabled && !m_mouse.dragging && m_mouse.position != Vec2d(DBL_MAX, DBL_MAX) && !m_gizmos.is_dragging()) {
m_hover_volume_idxs.clear();
// Render the object for picking.
// FIXME This cannot possibly work in a multi - sampled context as the color gets mangled by the anti - aliasing.
// Better to use software ray - casting on a bounding - box hierarchy.
if (m_multisample_allowed)
// This flag is often ignored by NVIDIA drivers if rendering into a screen buffer.
glsafe(::glDisable(GL_MULTISAMPLE));
glsafe(::glDisable(GL_BLEND));
glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
#if !ENABLE_LEGACY_OPENGL_REMOVAL
m_camera_clipping_plane = m_gizmos.get_clipping_plane();
if (m_camera_clipping_plane.is_active()) {
::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)m_camera_clipping_plane.get_data().data());
::glEnable(GL_CLIP_PLANE0);
}
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
_render_volumes_for_picking();
#if !ENABLE_LEGACY_OPENGL_REMOVAL
if (m_camera_clipping_plane.is_active())
::glDisable(GL_CLIP_PLANE0);
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_LEGACY_OPENGL_REMOVAL
const Camera& camera = wxGetApp().plater()->get_camera();
_render_bed_for_picking(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward());
#else
_render_bed_for_picking(!wxGetApp().plater()->get_camera().is_looking_downward());
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_gizmos.render_current_gizmo_for_picking_pass();
if (m_multisample_allowed)
glsafe(::glEnable(GL_MULTISAMPLE));
int volume_id = -1;
int gizmo_id = -1;
std::array<GLubyte, 4> color = { 0, 0, 0, 0 };
const Size& cnv_size = get_canvas_size();
bool inside = 0 <= m_mouse.position(0) && m_mouse.position(0) < cnv_size.get_width() && 0 <= m_mouse.position(1) && m_mouse.position(1) < cnv_size.get_height();
if (inside) {
glsafe(::glReadPixels(m_mouse.position(0), cnv_size.get_height() - m_mouse.position.y() - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color.data()));
if (picking_checksum_alpha_channel(color[0], color[1], color[2]) == color[3]) {
// Only non-interpolated colors are valid, those have their lowest three bits zeroed.
// we reserve color = (0,0,0) for occluders (as the printbed)
// volumes' id are shifted by 1
// see: _render_volumes_for_picking()
unsigned int id = picking_encode(color[0], color[1], color[2]);
volume_id = id - 1;
// gizmos' id are instead properly encoded by the color
gizmo_id = id;
}
}
if (0 <= volume_id && volume_id < (int)m_volumes.volumes.size()) {
// do not add the volume id if any gizmo is active and CTRL is pressed
if (m_gizmos.get_current_type() == GLGizmosManager::EType::Undefined || !wxGetKeyState(WXK_CONTROL))
m_hover_volume_idxs.emplace_back(volume_id);
m_gizmos.set_hover_id(-1);
}
else
m_gizmos.set_hover_id(inside && (unsigned int)gizmo_id <= GLGizmoBase::BASE_ID ? ((int)GLGizmoBase::BASE_ID - gizmo_id) : -1);
_update_volumes_hover_state();
}
}
#endif // ENABLE_RAYCAST_PICKING
void GLCanvas3D::_rectangular_selection_picking_pass() void GLCanvas3D::_rectangular_selection_picking_pass()
{ {
@ -5683,7 +5556,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
std::set<int> idxs; std::set<int> idxs;
if (m_picking_enabled) { if (m_picking_enabled) {
#if ENABLE_RAYCAST_PICKING
const size_t width = std::max<size_t>(m_rectangle_selection.get_width(), 1); const size_t width = std::max<size_t>(m_rectangle_selection.get_width(), 1);
const size_t height = std::max<size_t>(m_rectangle_selection.get_height(), 1); const size_t height = std::max<size_t>(m_rectangle_selection.get_height(), 1);
@ -5737,7 +5609,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
use_framebuffer = false; use_framebuffer = false;
} }
} }
#endif // ENABLE_RAYCAST_PICKING
if (m_multisample_allowed) if (m_multisample_allowed)
// This flag is often ignored by NVIDIA drivers if rendering into a screen buffer. // This flag is often ignored by NVIDIA drivers if rendering into a screen buffer.
@ -5748,7 +5619,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
#if ENABLE_RAYCAST_PICKING
const Camera& main_camera = wxGetApp().plater()->get_camera(); const Camera& main_camera = wxGetApp().plater()->get_camera();
Camera framebuffer_camera; Camera framebuffer_camera;
framebuffer_camera.set_type(main_camera.get_type()); framebuffer_camera.set_type(main_camera.get_type());
@ -5782,16 +5652,8 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
} }
_render_volumes_for_picking(*camera); _render_volumes_for_picking(*camera);
#else
_render_volumes_for_picking();
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
_render_bed_for_picking(camera->get_view_matrix(), camera->get_projection_matrix(), !camera->is_looking_downward()); _render_bed_for_picking(camera->get_view_matrix(), camera->get_projection_matrix(), !camera->is_looking_downward());
#else
const Camera& camera = wxGetApp().plater()->get_camera();
_render_bed_for_picking(camera.get_view_matrix(), camera.get_projection_matrix(), !camera.is_looking_downward());
#endif // ENABLE_RAYCAST_PICKING
#else #else
_render_bed_for_picking(!wxGetApp().plater()->get_camera().is_looking_downward()); _render_bed_for_picking(!wxGetApp().plater()->get_camera().is_looking_downward());
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -5799,20 +5661,10 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
if (m_multisample_allowed) if (m_multisample_allowed)
glsafe(::glEnable(GL_MULTISAMPLE)); glsafe(::glEnable(GL_MULTISAMPLE));
#if ENABLE_RAYCAST_PICKING
const size_t px_count = width * height; const size_t px_count = width * height;
const size_t left = use_framebuffer ? 0 : (size_t)m_rectangle_selection.get_left(); const size_t left = use_framebuffer ? 0 : (size_t)m_rectangle_selection.get_left();
const size_t top = use_framebuffer ? 0 : (size_t)get_canvas_size().get_height() - (size_t)m_rectangle_selection.get_top(); const size_t top = use_framebuffer ? 0 : (size_t)get_canvas_size().get_height() - (size_t)m_rectangle_selection.get_top();
#else
int width = std::max((int)m_rectangle_selection.get_width(), 1);
int height = std::max((int)m_rectangle_selection.get_height(), 1);
int px_count = width * height;
int left = (int)m_rectangle_selection.get_left();
int top = get_canvas_size().get_height() - (int)m_rectangle_selection.get_top();
if (left >= 0 && top >= 0) {
#endif // ENABLE_RAYCAST_PICKING
#define USE_PARALLEL 1 #define USE_PARALLEL 1
#if USE_PARALLEL #if USE_PARALLEL
struct Pixel struct Pixel
@ -5846,15 +5698,13 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
std::vector<GLubyte> frame(4 * px_count); std::vector<GLubyte> frame(4 * px_count);
glsafe(::glReadPixels(left, top, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (void*)frame.data())); glsafe(::glReadPixels(left, top, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (void*)frame.data()));
for (int i = 0; i < px_count; ++i) for (int i = 0; i < px_count; ++i) {
{
int px_id = 4 * i; int px_id = 4 * i;
int volume_id = frame[px_id] + (frame[px_id + 1] << 8) + (frame[px_id + 2] << 16); int volume_id = frame[px_id] + (frame[px_id + 1] << 8) + (frame[px_id + 2] << 16);
if (0 <= volume_id && volume_id < (int)m_volumes.volumes.size()) if (0 <= volume_id && volume_id < (int)m_volumes.volumes.size())
idxs.insert(volume_id); idxs.insert(volume_id);
} }
#endif // USE_PARALLEL #endif // USE_PARALLEL
#if ENABLE_RAYCAST_PICKING
if (camera != &main_camera) if (camera != &main_camera)
main_camera.apply_viewport(); main_camera.apply_viewport();
@ -5875,9 +5725,6 @@ void GLCanvas3D::_rectangular_selection_picking_pass()
if (render_tex != 0) if (render_tex != 0)
glsafe(::glDeleteTextures(1, &render_tex)); glsafe(::glDeleteTextures(1, &render_tex));
#else
}
#endif // ENABLE_RAYCAST_PICKING
} }
m_hover_volume_idxs.assign(idxs.begin(), idxs.end()); m_hover_volume_idxs.assign(idxs.begin(), idxs.end());
@ -6280,11 +6127,7 @@ void GLCanvas3D::_render_overlays()
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_RAYCAST_PICKING
void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const
#else
void GLCanvas3D::_render_volumes_for_picking() const
#endif // ENABLE_RAYCAST_PICKING
{ {
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* shader = wxGetApp().get_shader("flat_clip"); GLShaderProgram* shader = wxGetApp().get_shader("flat_clip");
@ -6300,11 +6143,7 @@ void GLCanvas3D::_render_volumes_for_picking() const
glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d& view_matrix = camera.get_view_matrix();
#else
const Transform3d& view_matrix = wxGetApp().plater()->get_camera().get_view_matrix();
#endif // ENABLE_RAYCAST_PICKING
for (size_t type = 0; type < 2; ++ type) { for (size_t type = 0; type < 2; ++ type) {
GLVolumeWithIdAndZList to_render = volumes_to_render(m_volumes.volumes, (type == 0) ? GLVolumeCollection::ERenderType::Opaque : GLVolumeCollection::ERenderType::Transparent, view_matrix); GLVolumeWithIdAndZList to_render = volumes_to_render(m_volumes.volumes, (type == 0) ? GLVolumeCollection::ERenderType::Opaque : GLVolumeCollection::ERenderType::Transparent, view_matrix);
for (const GLVolumeWithIdAndZ& volume : to_render) for (const GLVolumeWithIdAndZ& volume : to_render)
@ -6316,12 +6155,7 @@ void GLCanvas3D::_render_volumes_for_picking() const
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
volume.first->model.set_color(picking_decode(id)); volume.first->model.set_color(picking_decode(id));
shader->start_using(); shader->start_using();
#if ENABLE_RAYCAST_PICKING
shader->set_uniform("view_model_matrix", view_matrix * volume.first->world_matrix()); shader->set_uniform("view_model_matrix", view_matrix * volume.first->world_matrix());
#else
const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("view_model_matrix", camera.get_view_matrix() * volume.first->world_matrix());
#endif // ENABLE_RAYCAST_PICKING
shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix());
shader->set_uniform("volume_world_matrix", volume.first->world_matrix()); shader->set_uniform("volume_world_matrix", volume.first->world_matrix());
shader->set_uniform("z_range", m_volumes.get_z_range()); shader->set_uniform("z_range", m_volumes.get_z_range());
@ -6889,7 +6723,6 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
if (m_canvas == nullptr) if (m_canvas == nullptr)
return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX); return Vec3d(DBL_MAX, DBL_MAX, DBL_MAX);
#if ENABLE_RAYCAST_PICKING
if (z == nullptr) { if (z == nullptr) {
const SceneRaycaster::HitResult hit = m_scene_raycaster.hit(mouse_pos.cast<double>(), wxGetApp().plater()->get_camera(), nullptr); const SceneRaycaster::HitResult hit = m_scene_raycaster.hit(mouse_pos.cast<double>(), wxGetApp().plater()->get_camera(), nullptr);
return hit.is_valid() ? hit.position.cast<double>() : _mouse_to_bed_3d(mouse_pos); return hit.is_valid() ? hit.position.cast<double>() : _mouse_to_bed_3d(mouse_pos);
@ -6901,23 +6734,6 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
igl::unproject(Vec3d(mouse_pos.x(), viewport[3] - mouse_pos.y(), *z), camera.get_view_matrix().matrix(), camera.get_projection_matrix().matrix(), viewport, out); igl::unproject(Vec3d(mouse_pos.x(), viewport[3] - mouse_pos.y(), *z), camera.get_view_matrix().matrix(), camera.get_projection_matrix().matrix(), viewport, out);
return out; return out;
} }
#else
const Camera& camera = wxGetApp().plater()->get_camera();
const Matrix4d modelview = camera.get_view_matrix().matrix();
const Matrix4d projection = camera.get_projection_matrix().matrix();
const Vec4i viewport(camera.get_viewport().data());
const int y = viewport[3] - mouse_pos.y();
float mouse_z;
if (z == nullptr)
glsafe(::glReadPixels(mouse_pos.x(), y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z));
else
mouse_z = *z;
Vec3d out;
igl::unproject(Vec3d(mouse_pos.x(), y, mouse_z), modelview, projection, viewport, out);
return out;
#endif // ENABLE_RAYCAST_PICKING
} }
Vec3d GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos) Vec3d GLCanvas3D::_mouse_to_bed_3d(const Point& mouse_pos)

View File

@ -16,9 +16,7 @@
#include "libslic3r/GCode/GCodeProcessor.hpp" #include "libslic3r/GCode/GCodeProcessor.hpp"
#include "GCodeViewer.hpp" #include "GCodeViewer.hpp"
#include "Camera.hpp" #include "Camera.hpp"
#if ENABLE_RAYCAST_PICKING
#include "SceneRaycaster.hpp" #include "SceneRaycaster.hpp"
#endif // ENABLE_RAYCAST_PICKING
#include "GUI_Utils.hpp" #include "GUI_Utils.hpp"
#include "libslic3r/Slicing.hpp" #include "libslic3r/Slicing.hpp"
@ -483,9 +481,7 @@ public:
private: private:
wxGLCanvas* m_canvas; wxGLCanvas* m_canvas;
wxGLContext* m_context; wxGLContext* m_context;
#if ENABLE_RAYCAST_PICKING
SceneRaycaster m_scene_raycaster; SceneRaycaster m_scene_raycaster;
#endif // ENABLE_RAYCAST_PICKING
Bed3D &m_bed; Bed3D &m_bed;
#if ENABLE_RETINA_GL #if ENABLE_RETINA_GL
std::unique_ptr<RetinaHelper> m_retina_helper; std::unique_ptr<RetinaHelper> m_retina_helper;
@ -669,7 +665,6 @@ public:
bool init(); bool init();
void post_event(wxEvent &&event); void post_event(wxEvent &&event);
#if ENABLE_RAYCAST_PICKING
std::shared_ptr<SceneRaycasterItem> add_raycaster_for_picking(SceneRaycaster::EType type, int id, const MeshRaycaster& raycaster, std::shared_ptr<SceneRaycasterItem> add_raycaster_for_picking(SceneRaycaster::EType type, int id, const MeshRaycaster& raycaster,
const Transform3d& trafo = Transform3d::Identity(), bool use_back_faces = false) { const Transform3d& trafo = Transform3d::Identity(), bool use_back_faces = false) {
return m_scene_raycaster.add_raycaster(type, id, raycaster, trafo, use_back_faces); return m_scene_raycaster.add_raycaster(type, id, raycaster, trafo, use_back_faces);
@ -688,7 +683,6 @@ public:
void set_raycaster_gizmos_on_top(bool value) { void set_raycaster_gizmos_on_top(bool value) {
m_scene_raycaster.set_gizmos_on_top(value); m_scene_raycaster.set_gizmos_on_top(value);
} }
#endif // ENABLE_RAYCAST_PICKING
void set_as_dirty(); void set_as_dirty();
void requires_check_outside_state() { m_requires_check_outside_state = true; } void requires_check_outside_state() { m_requires_check_outside_state = true; }
@ -1008,11 +1002,7 @@ private:
#endif // ENABLE_RENDER_SELECTION_CENTER #endif // ENABLE_RENDER_SELECTION_CENTER
void _check_and_update_toolbar_icon_scale(); void _check_and_update_toolbar_icon_scale();
void _render_overlays(); void _render_overlays();
#if ENABLE_RAYCAST_PICKING
void _render_volumes_for_picking(const Camera& camera) const; void _render_volumes_for_picking(const Camera& camera) const;
#else
void _render_volumes_for_picking() const;
#endif // ENABLE_RAYCAST_PICKING
void _render_current_gizmo() const; void _render_current_gizmo() const;
void _render_gizmos_overlay(); void _render_gizmos_overlay();
void _render_main_toolbar(); void _render_main_toolbar();

View File

@ -30,21 +30,10 @@ namespace GUI {
m_end_corner = mouse_position; m_end_corner = mouse_position;
} }
#if ENABLE_RAYCAST_PICKING
std::vector<unsigned int> GLSelectionRectangle::contains(const std::vector<Vec3d>& points) const 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; std::vector<unsigned int> out;
#if !ENABLE_RAYCAST_PICKING
if (!is_dragging())
return out;
m_state = EState::Off;
#endif // !ENABLE_RAYCAST_PICKING
// bounding box created from the rectangle corners - will take care of order of the corners // bounding box created from the rectangle corners - will take care of order of the corners
const 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>()) });

View File

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

View File

@ -18,29 +18,16 @@ const float GLGizmoBase::Grabber::SizeFactor = 0.05f;
const float GLGizmoBase::Grabber::MinHalfSize = 1.5f; const float GLGizmoBase::Grabber::MinHalfSize = 1.5f;
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f; const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
#if ENABLE_RAYCAST_PICKING
PickingModel GLGizmoBase::Grabber::s_cube; PickingModel GLGizmoBase::Grabber::s_cube;
PickingModel GLGizmoBase::Grabber::s_cone; PickingModel GLGizmoBase::Grabber::s_cone;
#else
GLModel GLGizmoBase::Grabber::s_cube;
GLModel GLGizmoBase::Grabber::s_cone;
#endif // ENABLE_RAYCAST_PICKING
GLGizmoBase::Grabber::~Grabber() GLGizmoBase::Grabber::~Grabber()
{ {
#if ENABLE_RAYCAST_PICKING
if (s_cube.model.is_initialized()) if (s_cube.model.is_initialized())
s_cube.model.reset(); s_cube.model.reset();
if (s_cone.model.is_initialized()) if (s_cone.model.is_initialized())
s_cone.model.reset(); s_cone.model.reset();
#else
if (s_cube.is_initialized())
s_cube.reset();
if (s_cone.is_initialized())
s_cone.reset();
#endif // ENABLE_RAYCAST_PICKING
} }
float GLGizmoBase::Grabber::get_half_size(float size) const float GLGizmoBase::Grabber::get_half_size(float size) const
@ -53,7 +40,6 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const
return get_half_size(size) * DraggingScaleFactor; return get_half_size(size) * DraggingScaleFactor;
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoBase::Grabber::register_raycasters_for_picking(int id) void GLGizmoBase::Grabber::register_raycasters_for_picking(int id)
{ {
picking_id = id; picking_id = id;
@ -66,13 +52,8 @@ void GLGizmoBase::Grabber::unregister_raycasters_for_picking()
picking_id = -1; picking_id = -1;
raycasters = { nullptr }; raycasters = { nullptr };
} }
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) 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 #if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* shader = wxGetApp().get_current_shader(); GLShaderProgram* shader = wxGetApp().get_current_shader();
@ -80,69 +61,41 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
return; return;
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
if (!s_cube.model.is_initialized()) { if (!s_cube.model.is_initialized()) {
#else
if (!s_cube.is_initialized()) {
#endif // ENABLE_RAYCAST_PICKING
// This cannot be done in constructor, OpenGL is not yet // This cannot be done in constructor, OpenGL is not yet
// initialized at that point (on Linux at least). // initialized at that point (on Linux at least).
indexed_triangle_set its = its_make_cube(1.0, 1.0, 1.0); indexed_triangle_set its = its_make_cube(1.0, 1.0, 1.0);
its_translate(its, -0.5f * Vec3f::Ones()); its_translate(its, -0.5f * Vec3f::Ones());
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
s_cube.model.init_from(its); s_cube.model.init_from(its);
s_cube.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its))); s_cube.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its)));
#else
s_cube.init_from(its);
#endif // ENABLE_RAYCAST_PICKING
#else #else
s_cube.init_from(its, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } }); s_cube.init_from(its, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } });
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_RAYCAST_PICKING
if (!s_cone.model.is_initialized()) { if (!s_cone.model.is_initialized()) {
indexed_triangle_set its = its_make_cone(0.375, 1.5, double(PI) / 18.0); indexed_triangle_set its = its_make_cone(0.375, 1.5, double(PI) / 18.0);
s_cone.model.init_from(its); s_cone.model.init_from(its);
s_cone.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its))); s_cone.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its)));
} }
#else
if (!s_cone.is_initialized())
s_cone.init_from(its_make_cone(0.375, 1.5, double(PI) / 18.0));
#endif // ENABLE_RAYCAST_PICKING
const float half_size = dragging ? get_dragging_half_size(size) : get_half_size(size); const float half_size = dragging ? get_dragging_half_size(size) : get_half_size(size);
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
s_cube.model.set_color(render_color); s_cube.model.set_color(render_color);
s_cone.model.set_color(render_color); s_cone.model.set_color(render_color);
#else
s_cube.set_color(render_color);
s_cone.set_color(render_color);
#endif // ENABLE_RAYCAST_PICKING
const Camera& camera = wxGetApp().plater()->get_camera(); const Camera& camera = wxGetApp().plater()->get_camera();
shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#if ENABLE_RAYCAST_PICKING
const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d& view_matrix = camera.get_view_matrix();
const Matrix3d view_matrix_no_offset = view_matrix.matrix().block(0, 0, 3, 3); const Matrix3d view_matrix_no_offset = view_matrix.matrix().block(0, 0, 3, 3);
std::vector<Transform3d> elements_matrices(GRABBER_ELEMENTS_MAX_COUNT, Transform3d::Identity()); std::vector<Transform3d> elements_matrices(GRABBER_ELEMENTS_MAX_COUNT, Transform3d::Identity());
elements_matrices[0] = matrix * Geometry::translation_transform(center) * Geometry::rotation_transform(angles) * Geometry::scale_transform(2.0 * half_size); elements_matrices[0] = matrix * Geometry::translation_transform(center) * Geometry::rotation_transform(angles) * Geometry::scale_transform(2.0 * half_size);
Transform3d view_model_matrix = view_matrix * elements_matrices[0]; Transform3d view_model_matrix = view_matrix * elements_matrices[0];
#else
const Transform3d& view_matrix = camera.get_view_matrix();
const Transform3d model_matrix = matrix * Geometry::translation_transform(center) * Geometry::rotation_transform(angles) * Geometry::scale_transform(2.0 * half_size);
const Transform3d view_model_matrix = view_matrix * model_matrix;
#endif // ENABLE_RAYCAST_PICKING
shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("view_model_matrix", view_model_matrix);
#if ENABLE_RAYCAST_PICKING
Matrix3d view_normal_matrix = view_matrix_no_offset * elements_matrices[0].matrix().block(0, 0, 3, 3).inverse().transpose(); Matrix3d view_normal_matrix = view_matrix_no_offset * elements_matrices[0].matrix().block(0, 0, 3, 3).inverse().transpose();
#else
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
#endif // ENABLE_RAYCAST_PICKING
shader->set_uniform("view_normal_matrix", view_normal_matrix); shader->set_uniform("view_normal_matrix", view_normal_matrix);
#else #else
s_cube.set_color(-1, render_color); s_cube.set_color(-1, render_color);
@ -154,7 +107,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0)); glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0));
glsafe(::glScaled(2.0 * half_size, 2.0 * half_size, 2.0 * half_size)); glsafe(::glScaled(2.0 * half_size, 2.0 * half_size, 2.0 * half_size));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
s_cube.model.render(); s_cube.model.render();
auto render_extension = [&view_matrix, &view_matrix_no_offset, shader](const Transform3d& matrix) { auto render_extension = [&view_matrix, &view_matrix_no_offset, shader](const Transform3d& matrix) {
@ -164,64 +116,31 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
shader->set_uniform("view_normal_matrix", view_normal_matrix); shader->set_uniform("view_normal_matrix", view_normal_matrix);
s_cone.model.render(); s_cone.model.render();
}; };
#else
s_cube.render();
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) { if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) {
#if ENABLE_RAYCAST_PICKING
elements_matrices[1] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, 0.5 * double(PI), 0.0 }); elements_matrices[1] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, 0.5 * double(PI), 0.0 });
render_extension(elements_matrices[1]); render_extension(elements_matrices[1]);
#else
shader->set_uniform("view_model_matrix", view_model_matrix * Geometry::translation_transform(Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, 0.5 * double(PI), 0.0 }));
s_cone.render();
#endif // ENABLE_RAYCAST_PICKING
} }
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegX)) != 0) { if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegX)) != 0) {
#if ENABLE_RAYCAST_PICKING
elements_matrices[2] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, -0.5 * double(PI), 0.0 }); elements_matrices[2] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, -0.5 * double(PI), 0.0 });
render_extension(elements_matrices[2]); render_extension(elements_matrices[2]);
#else
shader->set_uniform("view_model_matrix", view_model_matrix * Geometry::translation_transform(-Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, -0.5 * double(PI), 0.0 }));
s_cone.render();
#endif // ENABLE_RAYCAST_PICKING
} }
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosY)) != 0) { if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosY)) != 0) {
#if ENABLE_RAYCAST_PICKING
elements_matrices[3] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitY()) * Geometry::rotation_transform({ -0.5 * double(PI), 0.0, 0.0 }); elements_matrices[3] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitY()) * Geometry::rotation_transform({ -0.5 * double(PI), 0.0, 0.0 });
render_extension(elements_matrices[3]); render_extension(elements_matrices[3]);
#else
shader->set_uniform("view_model_matrix", view_model_matrix * Geometry::translation_transform(Vec3d::UnitY()) * Geometry::rotation_transform({ -0.5 * double(PI), 0.0, 0.0 }));
s_cone.render();
#endif // ENABLE_RAYCAST_PICKING
} }
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegY)) != 0) { if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegY)) != 0) {
#if ENABLE_RAYCAST_PICKING
elements_matrices[4] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitY()) * Geometry::rotation_transform({ 0.5 * double(PI), 0.0, 0.0 }); elements_matrices[4] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitY()) * Geometry::rotation_transform({ 0.5 * double(PI), 0.0, 0.0 });
render_extension(elements_matrices[4]); render_extension(elements_matrices[4]);
#else
shader->set_uniform("view_model_matrix", view_model_matrix* Geometry::translation_transform(-Vec3d::UnitY())* Geometry::rotation_transform({ 0.5 * double(PI), 0.0, 0.0 }));
s_cone.render();
#endif // ENABLE_RAYCAST_PICKING
} }
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosZ)) != 0) { if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosZ)) != 0) {
#if ENABLE_RAYCAST_PICKING
elements_matrices[5] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitZ()); elements_matrices[5] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitZ());
render_extension(elements_matrices[5]); render_extension(elements_matrices[5]);
#else
shader->set_uniform("view_model_matrix", view_model_matrix* Geometry::translation_transform(Vec3d::UnitZ()));
s_cone.render();
#endif // ENABLE_RAYCAST_PICKING
} }
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegZ)) != 0) { if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegZ)) != 0) {
#if ENABLE_RAYCAST_PICKING
elements_matrices[6] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitZ()) * Geometry::rotation_transform({ double(PI), 0.0, 0.0 }); elements_matrices[6] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitZ()) * Geometry::rotation_transform({ double(PI), 0.0, 0.0 });
render_extension(elements_matrices[6]); render_extension(elements_matrices[6]);
#else
shader->set_uniform("view_model_matrix", view_model_matrix* Geometry::translation_transform(-Vec3d::UnitZ())* Geometry::rotation_transform({ double(PI), 0.0, 0.0 }));
s_cone.render();
#endif // ENABLE_RAYCAST_PICKING
} }
#else #else
if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) { if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) {
@ -270,7 +189,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
if (raycasters[0] == nullptr) { if (raycasters[0] == nullptr) {
GLCanvas3D& canvas = *wxGetApp().plater()->canvas3D(); GLCanvas3D& canvas = *wxGetApp().plater()->canvas3D();
raycasters[0] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cube.mesh_raycaster, elements_matrices[0]); raycasters[0] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cube.mesh_raycaster, elements_matrices[0]);
@ -293,7 +211,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color, boo
raycasters[i]->set_transform(elements_matrices[i]); raycasters[i]->set_transform(elements_matrices[i]);
} }
} }
#endif // ENABLE_RAYCAST_PICKING
} }
GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id)
@ -327,7 +244,6 @@ bool GLGizmoBase::update_items_state()
return res; return res;
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoBase::register_grabbers_for_picking() void GLGizmoBase::register_grabbers_for_picking()
{ {
for (size_t i = 0; i < m_grabbers.size(); ++i) { for (size_t i = 0; i < m_grabbers.size(); ++i) {
@ -341,16 +257,6 @@ void GLGizmoBase::unregister_grabbers_for_picking()
m_grabbers[i].unregister_raycasters_for_picking(); m_grabbers[i].unregister_raycasters_for_picking();
} }
} }
#else
ColorRGBA GLGizmoBase::picking_color_component(unsigned int id) const
{
id = BASE_ID - id;
if (m_group_id > -1)
id -= m_group_id;
return picking_decode(id);
}
#endif // ENABLE_RAYCAST_PICKING
void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) const void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) const
{ {
@ -371,29 +277,6 @@ void GLGizmoBase::render_grabbers(float size) const
shader->stop_using(); shader->stop_using();
} }
#if !ENABLE_RAYCAST_PICKING
void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const
{
#if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* shader = wxGetApp().get_shader("flat");
if (shader != nullptr) {
shader->start_using();
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
const float mean_size = float((box.size().x() + box.size().y() + box.size().z()) / 3.0);
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) {
if (m_grabbers[i].enabled) {
m_grabbers[i].color = picking_color_component(i);
m_grabbers[i].render_for_picking(mean_size);
}
}
#if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using();
}
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
}
#endif // !ENABLE_RAYCAST_PICKING
// help function to process grabbers // help function to process grabbers
// call start_dragging, stop_dragging, on_dragging // call start_dragging, stop_dragging, on_dragging
bool GLGizmoBase::use_grabbers(const wxMouseEvent &mouse_event) { bool GLGizmoBase::use_grabbers(const wxMouseEvent &mouse_event) {

View File

@ -6,10 +6,8 @@
#include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/I18N.hpp"
#include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GLModel.hpp"
#if ENABLE_RAYCAST_PICKING
#include "slic3r/GUI/MeshUtils.hpp" #include "slic3r/GUI/MeshUtils.hpp"
#include "slic3r/GUI/SceneRaycaster.hpp" #include "slic3r/GUI/SceneRaycaster.hpp"
#endif // ENABLE_RAYCAST_PICKING
#include <cereal/archives/binary.hpp> #include <cereal/archives/binary.hpp>
@ -73,44 +71,26 @@ protected:
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
ColorRGBA color{ ColorRGBA::WHITE() }; ColorRGBA color{ ColorRGBA::WHITE() };
EGrabberExtension extensions{ EGrabberExtension::None }; EGrabberExtension extensions{ EGrabberExtension::None };
#if ENABLE_RAYCAST_PICKING
// the picking id shared by all the elements // the picking id shared by all the elements
int picking_id{ -1 }; int picking_id{ -1 };
std::array<std::shared_ptr<SceneRaycasterItem>, GRABBER_ELEMENTS_MAX_COUNT> raycasters = { nullptr }; std::array<std::shared_ptr<SceneRaycasterItem>, GRABBER_ELEMENTS_MAX_COUNT> raycasters = { nullptr };
#endif // ENABLE_RAYCAST_PICKING
Grabber() = default; Grabber() = default;
~Grabber(); ~Grabber();
#if ENABLE_RAYCAST_PICKING
void render(bool hover, float size) { render(size, hover ? complementary(color) : color); } 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); }
void render_for_picking(float size) { render(size, color, true); }
#endif // ENABLE_RAYCAST_PICKING
float get_half_size(float size) const; float get_half_size(float size) const;
float get_dragging_half_size(float size) const; float get_dragging_half_size(float size) const;
#if ENABLE_RAYCAST_PICKING
void register_raycasters_for_picking(int id); void register_raycasters_for_picking(int id);
void unregister_raycasters_for_picking(); void unregister_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
private: private:
#if ENABLE_RAYCAST_PICKING
void render(float size, const ColorRGBA& render_color); 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; static PickingModel s_cube;
static PickingModel s_cone; static PickingModel s_cone;
#else
static GLModel s_cube;
static GLModel s_cone;
#endif // ENABLE_RAYCAST_PICKING
}; };
public: public:
@ -186,9 +166,6 @@ public:
bool update_items_state(); bool update_items_state();
void render() { on_render(); } void render() { on_render(); }
#if !ENABLE_RAYCAST_PICKING
void render_for_picking() { on_render_for_picking(); }
#endif // !ENABLE_RAYCAST_PICKING
void render_input_window(float x, float y, float bottom_limit); void render_input_window(float x, float y, float bottom_limit);
/// <summary> /// <summary>
@ -210,10 +187,8 @@ public:
/// <returns>Return True when use the information and don't want to propagate it otherwise False.</returns> /// <returns>Return True when use the information and don't want to propagate it otherwise False.</returns>
virtual bool on_mouse(const wxMouseEvent &mouse_event) { return false; } 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() { register_grabbers_for_picking(); on_register_raycasters_for_picking(); }
void unregister_raycasters_for_picking() { unregister_grabbers_for_picking(); on_unregister_raycasters_for_picking(); } void unregister_raycasters_for_picking() { unregister_grabbers_for_picking(); on_unregister_raycasters_for_picking(); }
#endif // ENABLE_RAYCAST_PICKING
virtual bool is_in_editing_mode() const { return false; } virtual bool is_in_editing_mode() const { return false; }
virtual bool is_selection_rectangle_dragging() const { return false; } virtual bool is_selection_rectangle_dragging() const { return false; }
@ -237,27 +212,15 @@ protected:
virtual void on_dragging(const UpdateData& data) {} virtual void on_dragging(const UpdateData& data) {}
virtual void on_render() = 0; virtual void on_render() = 0;
#if !ENABLE_RAYCAST_PICKING
virtual void on_render_for_picking() = 0;
#endif // !ENABLE_RAYCAST_PICKING
virtual void on_render_input_window(float x, float y, float bottom_limit) {} 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();
void unregister_grabbers_for_picking(); void unregister_grabbers_for_picking();
virtual void on_register_raycasters_for_picking() {} virtual void on_register_raycasters_for_picking() {}
virtual void on_unregister_raycasters_for_picking() {} virtual void on_unregister_raycasters_for_picking() {}
#else
// Returns the picking color for the given id, based on the BASE_ID constant
// No check is made for clashing with other picking color (i.e. GLVolumes)
ColorRGBA picking_color_component(unsigned int id) const;
#endif // ENABLE_RAYCAST_PICKING
void render_grabbers(const BoundingBoxf3& box) const; void render_grabbers(const BoundingBoxf3& box) const;
void render_grabbers(float size) const; void render_grabbers(float size) const;
#if !ENABLE_RAYCAST_PICKING
void render_grabbers_for_picking(const BoundingBoxf3& box) const;
#endif // !ENABLE_RAYCAST_PICKING
std::string format(float value, unsigned int decimals) const; std::string format(float value, unsigned int decimals) const;

View File

@ -600,18 +600,12 @@ void GLGizmoEmboss::on_render() {
} }
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoEmboss::on_register_raycasters_for_picking(){ void GLGizmoEmboss::on_register_raycasters_for_picking(){
m_rotate_gizmo.register_raycasters_for_picking(); m_rotate_gizmo.register_raycasters_for_picking();
} }
void GLGizmoEmboss::on_unregister_raycasters_for_picking(){ void GLGizmoEmboss::on_unregister_raycasters_for_picking(){
m_rotate_gizmo.unregister_raycasters_for_picking(); m_rotate_gizmo.unregister_raycasters_for_picking();
} }
#else // !ENABLE_RAYCAST_PICKING
void GLGizmoEmboss::on_render_for_picking() {
m_rotate_gizmo.render_for_picking();
}
#endif // ENABLE_RAYCAST_PICKING
#ifdef SHOW_FINE_POSITION #ifdef SHOW_FINE_POSITION
// draw suggested position of window // draw suggested position of window

View File

@ -56,12 +56,8 @@ protected:
bool on_init() override; bool on_init() override;
std::string on_get_name() const override; std::string on_get_name() const override;
void on_render() override; void on_render() override;
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override; virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override;
#else // !ENABLE_RAYCAST_PICKING
void on_render_for_picking() override;
#endif // ENABLE_RAYCAST_PICKING
void on_render_input_window(float x, float y, float bottom_limit) override; void on_render_input_window(float x, float y, float bottom_limit) override;
bool on_is_activable() const override { return true; } bool on_is_activable() const override { return true; }
bool on_is_selectable() const override { return false; } bool on_is_selectable() const override { return false; }

View File

@ -131,14 +131,9 @@ void GLGizmoFlatten::on_render()
update_planes(); update_planes();
for (int i = 0; i < (int)m_planes.size(); ++i) { for (int i = 0; i < (int)m_planes.size(); ++i) {
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_planes_casters[i]->set_transform(model_matrix); m_planes_casters[i]->set_transform(model_matrix);
m_planes[i].vbo.model.set_color(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR : DEFAULT_PLANE_COLOR); m_planes[i].vbo.model.set_color(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR : DEFAULT_PLANE_COLOR);
m_planes[i].vbo.model.render(); m_planes[i].vbo.model.render();
#else
m_planes[i].vbo.set_color(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR : DEFAULT_PLANE_COLOR);
m_planes[i].vbo.render();
#endif // ENABLE_RAYCAST_PICKING
#else #else
glsafe(::glColor4fv(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR.data() : DEFAULT_PLANE_COLOR.data())); glsafe(::glColor4fv(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR.data() : DEFAULT_PLANE_COLOR.data()));
if (m_planes[i].vbo.has_VBOs()) if (m_planes[i].vbo.has_VBOs())
@ -158,7 +153,6 @@ void GLGizmoFlatten::on_render()
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoFlatten::on_register_raycasters_for_picking() void GLGizmoFlatten::on_register_raycasters_for_picking()
{ {
// the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account // the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account
@ -183,66 +177,12 @@ void GLGizmoFlatten::on_unregister_raycasters_for_picking()
m_parent.set_raycaster_gizmos_on_top(false); m_parent.set_raycaster_gizmos_on_top(false);
m_planes_casters.clear(); m_planes_casters.clear();
} }
#else
void GLGizmoFlatten::on_render_for_picking()
{
const Selection& selection = m_parent.get_selection();
#if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* shader = wxGetApp().get_shader("flat");
if (shader == nullptr)
return;
shader->start_using();
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_BLEND));
if (selection.is_single_full_instance() && !wxGetKeyState(WXK_CONTROL)) {
const Transform3d& m = selection.get_first_volume()->get_instance_transformation().get_matrix();
#if ENABLE_LEGACY_OPENGL_REMOVAL
const Camera& camera = wxGetApp().plater()->get_camera();
const Transform3d view_model_matrix = camera.get_view_matrix() *
Geometry::translation_transform(selection.get_first_volume()->get_sla_shift_z() * Vec3d::UnitZ()) * m;
shader->set_uniform("view_model_matrix", view_model_matrix);
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
#else
glsafe(::glPushMatrix());
glsafe(::glTranslatef(0.f, 0.f, selection.get_first_volume()->get_sla_shift_z()));
glsafe(::glMultMatrixd(m.data()));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
if (this->is_plane_update_necessary())
update_planes();
for (int i = 0; i < (int)m_planes.size(); ++i) {
#if ENABLE_LEGACY_OPENGL_REMOVAL
m_planes[i].vbo.set_color(picking_color_component(i));
#else
glsafe(::glColor4fv(picking_color_component(i).data()));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
m_planes[i].vbo.render();
}
#if !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopMatrix());
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
}
glsafe(::glEnable(GL_CULL_FACE));
#if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using();
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
}
#endif // ENABLE_RAYCAST_PICKING
void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
{ {
if (model_object != m_old_model_object) { if (model_object != m_old_model_object) {
m_planes.clear(); m_planes.clear();
#if ENABLE_RAYCAST_PICKING
on_unregister_raycasters_for_picking(); on_unregister_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
} }
} }
@ -259,9 +199,7 @@ void GLGizmoFlatten::update_planes()
} }
ch = ch.convex_hull_3d(); ch = ch.convex_hull_3d();
m_planes.clear(); m_planes.clear();
#if ENABLE_RAYCAST_PICKING
on_unregister_raycasters_for_picking(); on_unregister_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
const Transform3d inst_matrix = mo->instances.front()->get_matrix_no_offset(); const Transform3d inst_matrix = mo->instances.front()->get_matrix_no_offset();
#else #else
@ -458,7 +396,6 @@ void GLGizmoFlatten::update_planes()
// the vertices in order, so triangulation is trivial. // the vertices in order, so triangulation is trivial.
for (auto& plane : m_planes) { for (auto& plane : m_planes) {
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
indexed_triangle_set its; indexed_triangle_set its;
its.vertices.reserve(plane.vertices.size()); its.vertices.reserve(plane.vertices.size());
its.indices.reserve(plane.vertices.size() / 3); its.indices.reserve(plane.vertices.size() / 3);
@ -470,18 +407,6 @@ void GLGizmoFlatten::update_planes()
} }
plane.vbo.model.init_from(its); plane.vbo.model.init_from(its);
plane.vbo.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its))); plane.vbo.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its)));
#else
GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::TriangleFan, GLModel::Geometry::EVertexLayout::P3N3 };
init_data.reserve_vertices(plane.vertices.size());
init_data.reserve_indices(plane.vertices.size());
// vertices + indices
for (size_t i = 0; i < plane.vertices.size(); ++i) {
init_data.add_vertex((Vec3f)plane.vertices[i].cast<float>(), (Vec3f)plane.normal.cast<float>());
init_data.add_index((unsigned int)i);
}
plane.vbo.init_from(std::move(init_data));
#endif // ENABLE_RAYCAST_PICKING
#else #else
plane.vbo.reserve(plane.vertices.size()); plane.vbo.reserve(plane.vertices.size());
for (const auto& vert : plane.vertices) for (const auto& vert : plane.vertices)
@ -496,12 +421,9 @@ void GLGizmoFlatten::update_planes()
plane.vertices.shrink_to_fit(); plane.vertices.shrink_to_fit();
} }
#if ENABLE_RAYCAST_PICKING
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
} }
bool GLGizmoFlatten::is_plane_update_necessary() const bool GLGizmoFlatten::is_plane_update_necessary() const
{ {
const ModelObject* mo = m_c->selection_info()->model_object(); const ModelObject* mo = m_c->selection_info()->model_object();

View File

@ -4,9 +4,7 @@
#include "GLGizmoBase.hpp" #include "GLGizmoBase.hpp"
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#include "slic3r/GUI/GLModel.hpp" #include "slic3r/GUI/GLModel.hpp"
#if ENABLE_RAYCAST_PICKING
#include "slic3r/GUI/MeshUtils.hpp" #include "slic3r/GUI/MeshUtils.hpp"
#endif // ENABLE_RAYCAST_PICKING
#else #else
#include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/3DScene.hpp"
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -30,19 +28,13 @@ private:
struct PlaneData { struct PlaneData {
std::vector<Vec3d> vertices; // should be in fact local in update_planes() std::vector<Vec3d> vertices; // should be in fact local in update_planes()
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
PickingModel vbo; PickingModel vbo;
#else
GLModel vbo;
#endif // ENABLE_RAYCAST_PICKING
#else #else
GLIndexedVertexArray vbo; GLIndexedVertexArray vbo;
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
Vec3d normal; Vec3d normal;
float area; float area;
#if ENABLE_RAYCAST_PICKING
int picking_id{ -1 }; int picking_id{ -1 };
#endif // ENABLE_RAYCAST_PICKING
}; };
// This holds information to decide whether recalculation is necessary: // This holds information to decide whether recalculation is necessary:
@ -52,9 +44,7 @@ private:
Vec3d m_first_instance_mirror; Vec3d m_first_instance_mirror;
std::vector<PlaneData> m_planes; std::vector<PlaneData> m_planes;
#if ENABLE_RAYCAST_PICKING
std::vector<std::shared_ptr<SceneRaycasterItem>> m_planes_casters; std::vector<std::shared_ptr<SceneRaycasterItem>> m_planes_casters;
#endif // ENABLE_RAYCAST_PICKING
bool m_mouse_left_down = false; // for detection left_up of this gizmo bool m_mouse_left_down = false; // for detection left_up of this gizmo
const ModelObject* m_old_model_object = nullptr; const ModelObject* m_old_model_object = nullptr;
@ -79,12 +69,8 @@ protected:
std::string on_get_name() const override; std::string on_get_name() const override;
bool on_is_activable() const override; bool on_is_activable() const override;
void on_render() override; void on_render() override;
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override; virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override;
#else
void on_render_for_picking() override;
#endif // ENABLE_RAYCAST_PICKING
void on_set_state() override; void on_set_state() override;
CommonGizmosDataID on_get_requirements() const override; CommonGizmosDataID on_get_requirements() const override;
}; };

View File

@ -55,12 +55,10 @@ void GLGizmoHollow::data_changed()
} }
if (m_c->hollowed_mesh() && m_c->hollowed_mesh()->get_hollowed_mesh()) if (m_c->hollowed_mesh() && m_c->hollowed_mesh()->get_hollowed_mesh())
m_holes_in_drilled_mesh = mo->sla_drain_holes; m_holes_in_drilled_mesh = mo->sla_drain_holes;
#if ENABLE_RAYCAST_PICKING
if (m_raycasters.empty()) if (m_raycasters.empty())
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
else else
update_raycasters_for_picking_transform(); update_raycasters_for_picking_transform();
#endif // ENABLE_RAYCAST_PICKING
} }
} }
@ -68,11 +66,6 @@ void GLGizmoHollow::data_changed()
void GLGizmoHollow::on_render() void GLGizmoHollow::on_render()
{ {
#if !ENABLE_RAYCAST_PICKING
if (!m_cylinder.is_initialized())
m_cylinder.init_from(its_make_cylinder(1.0, 1.0));
#endif // !ENABLE_RAYCAST_PICKING
const Selection& selection = m_parent.get_selection(); const Selection& selection = m_parent.get_selection();
const CommonGizmosDataObjects::SelectionInfo* sel_info = m_c->selection_info(); const CommonGizmosDataObjects::SelectionInfo* sel_info = m_c->selection_info();
@ -88,11 +81,7 @@ void GLGizmoHollow::on_render()
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
if (selection.is_from_single_instance()) if (selection.is_from_single_instance())
#if ENABLE_RAYCAST_PICKING
render_points(selection); render_points(selection);
#else
render_points(selection, false);
#endif // ENABLE_RAYCAST_PICKING
m_selection_rectangle.render(m_parent); m_selection_rectangle.render(m_parent);
m_c->object_clipper()->render_cut(); m_c->object_clipper()->render_cut();
@ -101,7 +90,6 @@ void GLGizmoHollow::on_render()
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoHollow::on_register_raycasters_for_picking() void GLGizmoHollow::on_register_raycasters_for_picking()
{ {
assert(m_raycasters.empty()); assert(m_raycasters.empty());
@ -126,27 +114,11 @@ void GLGizmoHollow::on_unregister_raycasters_for_picking()
m_raycasters.clear(); m_raycasters.clear();
set_sla_auxiliary_volumes_picking_state(true); set_sla_auxiliary_volumes_picking_state(true);
} }
#else
void GLGizmoHollow::on_render_for_picking()
{
const Selection& selection = m_parent.get_selection();
glsafe(::glEnable(GL_DEPTH_TEST));
render_points(selection, true);
}
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
void GLGizmoHollow::render_points(const Selection& selection) void GLGizmoHollow::render_points(const Selection& selection)
#else
void GLGizmoHollow::render_points(const Selection& selection, bool picking)
#endif // ENABLE_RAYCAST_PICKING
{ {
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#else
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat") : wxGetApp().get_shader("gouraud_light");
#endif // ENABLE_RAYCAST_PICKING
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -188,41 +160,24 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
const sla::DrainHole& drain_hole = drain_holes[i]; const sla::DrainHole& drain_hole = drain_holes[i];
const bool point_selected = m_selected[i]; const bool point_selected = m_selected[i];
#if ENABLE_RAYCAST_PICKING
const bool clipped = is_mesh_point_clipped(drain_hole.pos.cast<double>()); const bool clipped = is_mesh_point_clipped(drain_hole.pos.cast<double>());
m_raycasters[i]->set_active(!clipped); m_raycasters[i]->set_active(!clipped);
if (clipped) if (clipped)
continue; continue;
#else
if (is_mesh_point_clipped(drain_hole.pos.cast<double>()))
continue;
#endif // ENABLE_RAYCAST_PICKING
// First decide about the color of the point. // First decide about the color of the point.
#if !ENABLE_RAYCAST_PICKING if (size_t(m_hover_id) == i)
if (picking) render_color = ColorRGBA::CYAN();
render_color = picking_color_component(i); else if (m_c->hollowed_mesh() &&
else { i < m_c->hollowed_mesh()->get_drainholes().size() &&
#endif // !ENABLE_RAYCAST_PICKING m_c->hollowed_mesh()->get_drainholes()[i].failed) {
if (size_t(m_hover_id) == i) render_color = { 1.0f, 0.0f, 0.0f, 0.5f };
render_color = ColorRGBA::CYAN(); }
else if (m_c->hollowed_mesh() && else
i < m_c->hollowed_mesh()->get_drainholes().size() && render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f);
m_c->hollowed_mesh()->get_drainholes()[i].failed) {
render_color = { 1.0f, 0.0f, 0.0f, 0.5f };
}
else
render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f);
#if !ENABLE_RAYCAST_PICKING
}
#endif // !ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_cylinder.model.set_color(render_color); m_cylinder.model.set_color(render_color);
#else
m_cylinder.set_color(render_color);
#endif // ENABLE_RAYCAST_PICKING
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
const Transform3d hole_matrix = Geometry::translation_transform(drain_hole.pos.cast<double>()) * instance_scaling_matrix_inverse; const Transform3d hole_matrix = Geometry::translation_transform(drain_hole.pos.cast<double>()) * instance_scaling_matrix_inverse;
#else #else
@ -251,11 +206,7 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
glsafe(::glTranslated(0., 0., -drain_hole.height)); glsafe(::glTranslated(0., 0., -drain_hole.height));
glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_cylinder.model.render(); m_cylinder.model.render();
#else
m_cylinder.render();
#endif // ENABLE_RAYCAST_PICKING
if (vol->is_left_handed()) if (vol->is_left_handed())
glsafe(::glFrontFace(GL_CCW)); glsafe(::glFrontFace(GL_CCW));
@ -382,10 +333,8 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos
assert(m_selected.size() == mo->sla_drain_holes.size()); assert(m_selected.size() == mo->sla_drain_holes.size());
m_parent.set_as_dirty(); m_parent.set_as_dirty();
m_wait_for_up_event = true; m_wait_for_up_event = true;
#if ENABLE_RAYCAST_PICKING
on_unregister_raycasters_for_picking(); on_unregister_raycasters_for_picking();
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
} }
else else
return false; return false;
@ -410,12 +359,8 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos
// Now ask the rectangle which of the points are inside. // Now ask the rectangle which of the points are inside.
std::vector<Vec3f> points_inside; std::vector<Vec3f> points_inside;
#if ENABLE_RAYCAST_PICKING
std::vector<unsigned int> points_idxs = m_selection_rectangle.contains(points); std::vector<unsigned int> points_idxs = m_selection_rectangle.contains(points);
m_selection_rectangle.stop_dragging(); 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) for (size_t idx : points_idxs)
points_inside.push_back(points[idx].cast<float>()); points_inside.push_back(points[idx].cast<float>());
@ -509,10 +454,8 @@ void GLGizmoHollow::delete_selected_points()
} }
} }
#if ENABLE_RAYCAST_PICKING
on_unregister_raycasters_for_picking(); on_unregister_raycasters_for_picking();
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
select_point(NoPoints); select_point(NoPoints);
} }
@ -588,7 +531,6 @@ void GLGizmoHollow::hollow_mesh(bool postpone_error_messages)
}); });
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoHollow::set_sla_auxiliary_volumes_picking_state(bool state) void GLGizmoHollow::set_sla_auxiliary_volumes_picking_state(bool state)
{ {
std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume); std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume);
@ -630,7 +572,6 @@ void GLGizmoHollow::update_raycasters_for_picking_transform()
} }
} }
} }
#endif // ENABLE_RAYCAST_PICKING
std::vector<std::pair<const ConfigOption*, const ConfigOptionDef*>> std::vector<std::pair<const ConfigOption*, const ConfigOptionDef*>>
GLGizmoHollow::get_config_options(const std::vector<std::string>& keys) const GLGizmoHollow::get_config_options(const std::vector<std::string>& keys) const
@ -900,11 +841,9 @@ RENDER_AGAIN:
bool show_sups = m_c->instances_hider()->are_supports_shown(); bool show_sups = m_c->instances_hider()->are_supports_shown();
if (m_imgui->checkbox(m_desc["show_supports"], show_sups)) { if (m_imgui->checkbox(m_desc["show_supports"], show_sups)) {
m_c->instances_hider()->show_supports(show_sups); m_c->instances_hider()->show_supports(show_sups);
#if ENABLE_RAYCAST_PICKING
if (show_sups) if (show_sups)
// ensure supports and pad are disabled from picking even when they are visible // ensure supports and pad are disabled from picking even when they are visible
set_sla_auxiliary_volumes_picking_state(false); set_sla_auxiliary_volumes_picking_state(false);
#endif // ENABLE_RAYCAST_PICKING
force_refresh = true; force_refresh = true;
} }
@ -1100,7 +1039,6 @@ void GLGizmoHollow::on_set_hover_id()
m_hover_id = -1; m_hover_id = -1;
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoHollow::init_cylinder_model() void GLGizmoHollow::init_cylinder_model()
{ {
if (!m_cylinder.model.is_initialized()) { if (!m_cylinder.model.is_initialized()) {
@ -1109,7 +1047,6 @@ void GLGizmoHollow::init_cylinder_model()
m_cylinder.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its))); m_cylinder.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its)));
} }
} }
#endif // ENABLE_RAYCAST_PICKING

View File

@ -46,33 +46,19 @@ public:
protected: protected:
bool on_init() override; bool on_init() override;
void on_render() override; void on_render() override;
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override; virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override;
#else
void on_render_for_picking() override;
#endif // ENABLE_RAYCAST_PICKING
private: private:
#if ENABLE_RAYCAST_PICKING
void render_points(const Selection& selection); void render_points(const Selection& selection);
#else
void render_points(const Selection& selection, bool picking = false);
#endif // ENABLE_RAYCAST_PICKING
void hollow_mesh(bool postpone_error_messages = false); void hollow_mesh(bool postpone_error_messages = false);
#if ENABLE_RAYCAST_PICKING
void set_sla_auxiliary_volumes_picking_state(bool state); void set_sla_auxiliary_volumes_picking_state(bool state);
void update_raycasters_for_picking_transform(); void update_raycasters_for_picking_transform();
#endif // ENABLE_RAYCAST_PICKING
ObjectID m_old_mo_id = -1; ObjectID m_old_mo_id = -1;
#if ENABLE_RAYCAST_PICKING
PickingModel m_cylinder; PickingModel m_cylinder;
std::vector<std::shared_ptr<SceneRaycasterItem>> m_raycasters; std::vector<std::shared_ptr<SceneRaycasterItem>> m_raycasters;
#else
GLModel m_cylinder;
#endif // ENABLE_RAYCAST_PICKING
float m_new_hole_radius = 2.f; // Size of a new hole. float m_new_hole_radius = 2.f; // Size of a new hole.
float m_new_hole_height = 6.f; float m_new_hole_height = 6.f;
@ -128,9 +114,7 @@ protected:
void on_load(cereal::BinaryInputArchive& ar) override; void on_load(cereal::BinaryInputArchive& ar) override;
void on_save(cereal::BinaryOutputArchive& ar) const override; void on_save(cereal::BinaryOutputArchive& ar) const override;
#if ENABLE_RAYCAST_PICKING
void init_cylinder_model(); void init_cylinder_model();
#endif // ENABLE_RAYCAST_PICKING
}; };

View File

@ -362,7 +362,6 @@ void GLGizmoMove3D::on_render()
#endif // ENABLE_WORLD_COORDINATE #endif // ENABLE_WORLD_COORDINATE
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoMove3D::on_register_raycasters_for_picking() void GLGizmoMove3D::on_register_raycasters_for_picking()
{ {
// the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account // the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account
@ -373,32 +372,6 @@ void GLGizmoMove3D::on_unregister_raycasters_for_picking()
{ {
m_parent.set_raycaster_gizmos_on_top(false); m_parent.set_raycaster_gizmos_on_top(false);
} }
#else
void GLGizmoMove3D::on_render_for_picking()
{
glsafe(::glDisable(GL_DEPTH_TEST));
#if ENABLE_WORLD_COORDINATE
#if ENABLE_LEGACY_OPENGL_REMOVAL
const Transform3d base_matrix = local_transform(m_parent.get_selection());
for (int i = 0; i < 3; ++i) {
m_grabbers[i].matrix = base_matrix;
}
#else
glsafe(::glPushMatrix());
transform_to_local(m_parent.get_selection());
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
render_grabbers_for_picking(m_bounding_box);
#if ENABLE_LEGACY_OPENGL_REMOVAL
#else
glsafe(::glPopMatrix());
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#else
const BoundingBoxf3& box = m_parent.get_selection().get_bounding_box();
render_grabbers_for_picking(box);
#endif // ENABLE_WORLD_COORDINATE
}
#endif // ENABLE_RAYCAST_PICKING
double GLGizmoMove3D::calc_projection(const UpdateData& data) const double GLGizmoMove3D::calc_projection(const UpdateData& data) const
{ {

View File

@ -62,12 +62,8 @@ protected:
void on_stop_dragging() override; void on_stop_dragging() override;
void on_dragging(const UpdateData& data) override; void on_dragging(const UpdateData& data) override;
void on_render() override; void on_render() override;
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override; virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override;
#else
void on_render_for_picking() override;
#endif // ENABLE_RAYCAST_PICKING
private: private:
double calc_projection(const UpdateData& data) const; double calc_projection(const UpdateData& data) const;

View File

@ -138,9 +138,6 @@ private:
ObjectID m_old_mo_id; ObjectID m_old_mo_id;
size_t m_old_volumes_size = 0; size_t m_old_volumes_size = 0;
void on_render() override {} void on_render() override {}
#if !ENABLE_RAYCAST_PICKING
void on_render_for_picking() override {}
#endif // !ENABLE_RAYCAST_PICKING
public: public:
GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id);

View File

@ -256,33 +256,6 @@ void GLGizmoRotate::on_render()
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
} }
#if !ENABLE_RAYCAST_PICKING
void GLGizmoRotate::on_render_for_picking()
{
const Selection& selection = m_parent.get_selection();
glsafe(::glDisable(GL_DEPTH_TEST));
#if ENABLE_LEGACY_OPENGL_REMOVAL
m_grabbers.front().matrix = local_transform(selection);
#else
glsafe(::glPushMatrix());
transform_to_local(selection);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_WORLD_COORDINATE
render_grabbers_for_picking(m_bounding_box);
#else
const BoundingBoxf3& box = selection.get_bounding_box();
render_grabbers_for_picking(box);
#endif // ENABLE_WORLD_COORDINATE
#if !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopMatrix());
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
}
#endif // !ENABLE_RAYCAST_PICKING
#if ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE
void GLGizmoRotate::init_data_from_selection(const Selection& selection) void GLGizmoRotate::init_data_from_selection(const Selection& selection)
{ {
@ -906,7 +879,6 @@ void GLGizmoRotate3D::on_render()
m_gizmos[Z].render(); m_gizmos[Z].render();
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoRotate3D::on_register_raycasters_for_picking() void GLGizmoRotate3D::on_register_raycasters_for_picking()
{ {
// the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account // the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account
@ -923,7 +895,6 @@ void GLGizmoRotate3D::on_unregister_raycasters_for_picking()
} }
m_parent.set_raycaster_gizmos_on_top(false); m_parent.set_raycaster_gizmos_on_top(false);
} }
#endif // ENABLE_RAYCAST_PICKING
GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(ImGuiWrapper * imgui, GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(ImGuiWrapper * imgui,
State & state, State & state,

View File

@ -98,9 +98,6 @@ protected:
void on_start_dragging() override; void on_start_dragging() override;
void on_dragging(const UpdateData &data) override; void on_dragging(const UpdateData &data) override;
void on_render() override; void on_render() override;
#if !ENABLE_RAYCAST_PICKING
void on_render_for_picking() override;
#endif // !ENABLE_RAYCAST_PICKING
private: private:
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
@ -189,16 +186,8 @@ protected:
void on_dragging(const UpdateData &data) override; void on_dragging(const UpdateData &data) override;
void on_render() override; void on_render() override;
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override; virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_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
void on_render_input_window(float x, float y, float bottom_limit) override; void on_render_input_window(float x, float y, float bottom_limit) override;

View File

@ -650,7 +650,6 @@ void GLGizmoScale3D::on_render()
#endif // ENABLE_WORLD_COORDINATE #endif // ENABLE_WORLD_COORDINATE
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoScale3D::on_register_raycasters_for_picking() void GLGizmoScale3D::on_register_raycasters_for_picking()
{ {
// the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account // the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account
@ -661,29 +660,6 @@ void GLGizmoScale3D::on_unregister_raycasters_for_picking()
{ {
m_parent.set_raycaster_gizmos_on_top(false); m_parent.set_raycaster_gizmos_on_top(false);
} }
#else
void GLGizmoScale3D::on_render_for_picking()
{
glsafe(::glDisable(GL_DEPTH_TEST));
#if ENABLE_WORLD_COORDINATE
#if ENABLE_LEGACY_OPENGL_REMOVAL
const Transform3d base_matrix = local_transform(m_parent.get_selection());
for (int i = 0; i < 10; ++i) {
m_grabbers[i].matrix = base_matrix;
}
#else
glsafe(::glPushMatrix());
transform_to_local(m_parent.get_selection());
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
render_grabbers_for_picking(m_bounding_box);
#if !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopMatrix());
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL
#else
render_grabbers_for_picking(m_parent.get_selection().get_bounding_box());
#endif // ENABLE_WORLD_COORDINATE
}
#endif // !ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color) void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color)

View File

@ -94,12 +94,8 @@ protected:
virtual void on_stop_dragging() override; virtual void on_stop_dragging() override;
virtual void on_dragging(const UpdateData& data) override; virtual void on_dragging(const UpdateData& data) override;
virtual void on_render() override; virtual void on_render() override;
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override; virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override;
#else
virtual void on_render_for_picking() override;
#endif // ENABLE_RAYCAST_PICKING
private: private:
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL

View File

@ -38,9 +38,6 @@ protected:
// must implement // must implement
virtual bool on_init() override { return true;}; virtual bool on_init() override { return true;};
virtual void on_render() override; virtual void on_render() override;
#if !ENABLE_RAYCAST_PICKING
virtual void on_render_for_picking() override{};
#endif // !ENABLE_RAYCAST_PICKING
CommonGizmosDataID on_get_requirements() const override; CommonGizmosDataID on_get_requirements() const override;

View File

@ -22,10 +22,8 @@
#include "libslic3r/PresetBundle.hpp" #include "libslic3r/PresetBundle.hpp"
#include "libslic3r/SLAPrint.hpp" #include "libslic3r/SLAPrint.hpp"
#if ENABLE_RAYCAST_PICKING
static const double CONE_RADIUS = 0.25; static const double CONE_RADIUS = 0.25;
static const double CONE_HEIGHT = 0.75; static const double CONE_HEIGHT = 0.75;
#endif // ENABLE_RAYCAST_PICKING
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -51,12 +49,6 @@ bool GLGizmoSlaSupports::on_init()
m_desc["clipping_of_view"] = _L("Clipping of view")+ ": "; m_desc["clipping_of_view"] = _L("Clipping of view")+ ": ";
m_desc["reset_direction"] = _L("Reset direction"); m_desc["reset_direction"] = _L("Reset direction");
#if !ENABLE_RAYCAST_PICKING
m_cone.init_from(its_make_cone(1., 1., 2 * PI / 24));
m_cylinder.init_from(its_make_cylinder(1., 1., 2 * PI / 24.));
m_sphere.init_from(its_make_sphere(1., (2 * M_PI) / 24.));
#endif // !ENABLE_RAYCAST_PICKING
return true; return true;
} }
@ -79,12 +71,10 @@ void GLGizmoSlaSupports::data_changed()
if (mo->sla_points_status == sla::PointsStatus::Generating) if (mo->sla_points_status == sla::PointsStatus::Generating)
get_data_from_backend(); get_data_from_backend();
#if ENABLE_RAYCAST_PICKING
if (m_raycasters.empty()) if (m_raycasters.empty())
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
else else
update_raycasters_for_picking_transform(); update_raycasters_for_picking_transform();
#endif // ENABLE_RAYCAST_PICKING
} }
} }
@ -92,7 +82,6 @@ void GLGizmoSlaSupports::data_changed()
void GLGizmoSlaSupports::on_render() void GLGizmoSlaSupports::on_render()
{ {
#if ENABLE_RAYCAST_PICKING
if (!m_sphere.model.is_initialized()) { if (!m_sphere.model.is_initialized()) {
indexed_triangle_set its = its_make_sphere(1.0, double(PI) / 12.0); indexed_triangle_set its = its_make_sphere(1.0, double(PI) / 12.0);
m_sphere.model.init_from(its); m_sphere.model.init_from(its);
@ -103,12 +92,6 @@ void GLGizmoSlaSupports::on_render()
m_cone.model.init_from(its); m_cone.model.init_from(its);
m_cone.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its))); m_cone.mesh_raycaster = std::make_unique<MeshRaycaster>(std::make_shared<const TriangleMesh>(std::move(its)));
} }
#else
if (!m_cone.is_initialized())
m_cone.init_from(its_make_cone(1.0, 1.0, double(PI) / 12.0));
if (!m_sphere.is_initialized())
m_sphere.init_from(its_make_sphere(1.0, double(PI) / 12.0));
#endif // ENABLE_RAYCAST_PICKING
if (!m_cylinder.is_initialized()) if (!m_cylinder.is_initialized())
m_cylinder.init_from(its_make_cylinder(1.0, 1.0, double(PI) / 12.0)); m_cylinder.init_from(its_make_cylinder(1.0, 1.0, double(PI) / 12.0));
@ -127,11 +110,7 @@ void GLGizmoSlaSupports::on_render()
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
if (selection.is_from_single_instance()) if (selection.is_from_single_instance())
#if ENABLE_RAYCAST_PICKING
render_points(selection); render_points(selection);
#else
render_points(selection, false);
#endif // ENABLE_RAYCAST_PICKING
m_selection_rectangle.render(m_parent); m_selection_rectangle.render(m_parent);
m_c->object_clipper()->render_cut(); m_c->object_clipper()->render_cut();
@ -140,7 +119,6 @@ void GLGizmoSlaSupports::on_render()
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoSlaSupports::on_register_raycasters_for_picking() void GLGizmoSlaSupports::on_register_raycasters_for_picking()
{ {
assert(m_raycasters.empty()); assert(m_raycasters.empty());
@ -161,20 +139,8 @@ void GLGizmoSlaSupports::on_unregister_raycasters_for_picking()
m_raycasters.clear(); m_raycasters.clear();
set_sla_auxiliary_volumes_picking_state(true); set_sla_auxiliary_volumes_picking_state(true);
} }
#else
void GLGizmoSlaSupports::on_render_for_picking()
{
const Selection& selection = m_parent.get_selection();
//glsafe(::glEnable(GL_DEPTH_TEST));
render_points(selection, true);
}
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
void GLGizmoSlaSupports::render_points(const Selection& selection) void GLGizmoSlaSupports::render_points(const Selection& selection)
#else
void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
#endif // ENABLE_RAYCAST_PICKING
{ {
const size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size(); const size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size();
@ -186,11 +152,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
return; return;
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
#else
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
#endif // ENABLE_RAYCAST_PICKING
if (shader == nullptr) if (shader == nullptr)
return; return;
@ -230,7 +192,6 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
const sla::SupportPoint& support_point = m_editing_mode ? m_editing_cache[i].support_point : m_normal_cache[i]; const sla::SupportPoint& support_point = m_editing_mode ? m_editing_cache[i].support_point : m_normal_cache[i];
const bool point_selected = m_editing_mode ? m_editing_cache[i].selected : false; const bool point_selected = m_editing_mode ? m_editing_cache[i].selected : false;
#if ENABLE_RAYCAST_PICKING
const bool clipped = is_mesh_point_clipped(support_point.pos.cast<double>()); const bool clipped = is_mesh_point_clipped(support_point.pos.cast<double>());
if (!m_raycasters.empty()) { if (!m_raycasters.empty()) {
m_raycasters[i].first->set_active(!clipped); m_raycasters[i].first->set_active(!clipped);
@ -238,48 +199,28 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
} }
if (clipped) if (clipped)
continue; continue;
#else
if (is_mesh_point_clipped(support_point.pos.cast<double>()))
continue;
#endif // ENABLE_RAYCAST_PICKING
// First decide about the color of the point. // First decide about the color of the point.
#if !ENABLE_RAYCAST_PICKING if (size_t(m_hover_id) == i && m_editing_mode) // ignore hover state unless editing mode is active
if (picking) render_color = { 0.f, 1.f, 1.f, 1.f };
render_color = picking_color_component(i); else { // neigher hover nor picking
else { bool supports_new_island = m_lock_unique_islands && support_point.is_new_island;
#endif // !ENABLE_RAYCAST_PICKING if (m_editing_mode) {
if (size_t(m_hover_id) == i && m_editing_mode) // ignore hover state unless editing mode is active if (point_selected)
render_color = { 0.f, 1.f, 1.f, 1.f }; render_color = { 1.f, 0.3f, 0.3f, 1.f};
else { // neigher hover nor picking
bool supports_new_island = m_lock_unique_islands && support_point.is_new_island;
if (m_editing_mode) {
if (point_selected)
render_color = { 1.f, 0.3f, 0.3f, 1.f};
else
if (supports_new_island)
render_color = { 0.3f, 0.3f, 1.f, 1.f };
else
render_color = { 0.7f, 0.7f, 0.7f, 1.f };
}
else else
render_color = { 0.5f, 0.5f, 0.5f, 1.f }; if (supports_new_island)
render_color = { 0.3f, 0.3f, 1.f, 1.f };
else
render_color = { 0.7f, 0.7f, 0.7f, 1.f };
} }
#if !ENABLE_RAYCAST_PICKING else
render_color = { 0.5f, 0.5f, 0.5f, 1.f };
} }
#endif // !ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_cone.model.set_color(render_color); m_cone.model.set_color(render_color);
m_sphere.model.set_color(render_color); m_sphere.model.set_color(render_color);
#else
m_cone.set_color(render_color);
m_sphere.set_color(render_color);
#endif // ENABLE_RAYCAST_PICKING
#if !ENABLE_RAYCAST_PICKING
if (!picking)
#endif // !ENABLE_RAYCAST_PICKING
#else #else
m_cone.set_color(-1, render_color); m_cone.set_color(-1, render_color);
m_sphere.set_color(-1, render_color); m_sphere.set_color(-1, render_color);
@ -309,19 +250,10 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
Eigen::Quaterniond q; Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>()); q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>());
const Eigen::AngleAxisd aa(q); const Eigen::AngleAxisd aa(q);
#if !ENABLE_RAYCAST_PICKING
const double cone_radius = 0.25; // mm
const double cone_height = 0.75;
#endif // !ENABLE_RAYCAST_PICKING
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const Transform3d model_matrix = vol->world_matrix() * support_matrix * Transform3d(aa.toRotationMatrix()) * const Transform3d model_matrix = vol->world_matrix() * support_matrix * Transform3d(aa.toRotationMatrix()) *
#if ENABLE_RAYCAST_PICKING
Geometry::translation_transform((CONE_HEIGHT + support_point.head_front_radius * RenderPointScale) * Vec3d::UnitZ()) * Geometry::translation_transform((CONE_HEIGHT + support_point.head_front_radius * RenderPointScale) * Vec3d::UnitZ()) *
Geometry::rotation_transform({ double(PI), 0.0, 0.0 }) * Geometry::scale_transform({ CONE_RADIUS, CONE_RADIUS, CONE_HEIGHT }); Geometry::rotation_transform({ double(PI), 0.0, 0.0 }) * Geometry::scale_transform({ CONE_RADIUS, CONE_RADIUS, CONE_HEIGHT });
#else
Geometry::translation_transform((cone_height + support_point.head_front_radius * RenderPointScale) * Vec3d::UnitZ()) *
Geometry::rotation_transform({ double(PI), 0.0, 0.0 }), * Geometry::scale_transform({ cone_radius, cone_radius, cone_height });
#endif // ENABLE_RAYCAST_PICKING
shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("view_model_matrix", view_matrix * model_matrix);
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
@ -333,11 +265,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
glsafe(::glRotated(180., 1., 0., 0.)); glsafe(::glRotated(180., 1., 0., 0.));
glsafe(::glScaled(cone_radius, cone_radius, cone_height)); glsafe(::glScaled(cone_radius, cone_radius, cone_height));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_cone.model.render(); m_cone.model.render();
#else
m_cone.render();
#endif // ENABLE_RAYCAST_PICKING
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
@ -353,11 +281,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glScaled(radius, radius, radius)); glsafe(::glScaled(radius, radius, radius));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_RAYCAST_PICKING
m_sphere.model.render(); m_sphere.model.render();
#else
m_sphere.render();
#endif // ENABLE_RAYCAST_PICKING
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glPopMatrix()); glsafe(::glPopMatrix());
#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // !ENABLE_LEGACY_OPENGL_REMOVAL
@ -371,11 +295,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
} }
// Now render the drain holes: // Now render the drain holes:
#if ENABLE_RAYCAST_PICKING
if (has_holes) { if (has_holes) {
#else
if (has_holes && ! picking) {
#endif // ENABLE_RAYCAST_PICKING
render_color = { 0.7f, 0.7f, 0.7f, 0.7f }; render_color = { 0.7f, 0.7f, 0.7f, 0.7f };
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
m_cylinder.set_color(render_color); m_cylinder.set_color(render_color);
@ -544,10 +464,8 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
m_editing_cache.emplace_back(sla::SupportPoint(pos_and_normal.first, m_new_point_head_diameter/2.f, false), false, pos_and_normal.second); m_editing_cache.emplace_back(sla::SupportPoint(pos_and_normal.first, m_new_point_head_diameter/2.f, false), false, pos_and_normal.second);
m_parent.set_as_dirty(); m_parent.set_as_dirty();
m_wait_for_up_event = true; m_wait_for_up_event = true;
#if ENABLE_RAYCAST_PICKING
on_unregister_raycasters_for_picking(); on_unregister_raycasters_for_picking();
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
} }
else else
return false; return false;
@ -572,12 +490,8 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
// Now ask the rectangle which of the points are inside. // Now ask the rectangle which of the points are inside.
std::vector<Vec3f> points_inside; std::vector<Vec3f> points_inside;
#if ENABLE_RAYCAST_PICKING
std::vector<unsigned int> points_idxs = m_selection_rectangle.contains(points); std::vector<unsigned int> points_idxs = m_selection_rectangle.contains(points);
m_selection_rectangle.stop_dragging(); 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) for (size_t idx : points_idxs)
points_inside.push_back(points[idx].cast<float>()); points_inside.push_back(points[idx].cast<float>());
@ -707,10 +621,8 @@ void GLGizmoSlaSupports::delete_selected_points(bool force)
} }
} }
#if ENABLE_RAYCAST_PICKING
on_unregister_raycasters_for_picking(); on_unregister_raycasters_for_picking();
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
select_point(NoPoints); select_point(NoPoints);
} }
@ -1390,9 +1302,7 @@ void GLGizmoSlaSupports::switch_to_editing_mode()
for (const sla::SupportPoint& sp : m_normal_cache) for (const sla::SupportPoint& sp : m_normal_cache)
m_editing_cache.emplace_back(sp); m_editing_cache.emplace_back(sp);
select_point(NoPoints); select_point(NoPoints);
#if ENABLE_RAYCAST_PICKING
on_register_raycasters_for_picking(); on_register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
m_c->instances_hider()->show_supports(false); m_c->instances_hider()->show_supports(false);
m_parent.set_as_dirty(); m_parent.set_as_dirty();
@ -1406,9 +1316,7 @@ void GLGizmoSlaSupports::disable_editing_mode()
wxGetApp().plater()->leave_gizmos_stack(); wxGetApp().plater()->leave_gizmos_stack();
m_c->instances_hider()->show_supports(true); m_c->instances_hider()->show_supports(true);
m_parent.set_as_dirty(); m_parent.set_as_dirty();
#if ENABLE_RAYCAST_PICKING
on_unregister_raycasters_for_picking(); on_unregister_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
} }
wxGetApp().plater()->get_notification_manager()->close_notification_of_type(NotificationType::QuitSLAManualMode); wxGetApp().plater()->get_notification_manager()->close_notification_of_type(NotificationType::QuitSLAManualMode);
} }
@ -1427,7 +1335,6 @@ bool GLGizmoSlaSupports::unsaved_changes() const
return false; return false;
} }
#if ENABLE_RAYCAST_PICKING
void GLGizmoSlaSupports::set_sla_auxiliary_volumes_picking_state(bool state) void GLGizmoSlaSupports::set_sla_auxiliary_volumes_picking_state(bool state)
{ {
std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume); std::vector<std::shared_ptr<SceneRaycasterItem>>* raycasters = m_parent.get_raycasters_for_picking(SceneRaycaster::EType::Volume);
@ -1473,7 +1380,6 @@ void GLGizmoSlaSupports::update_raycasters_for_picking_transform()
} }
} }
} }
#endif // ENABLE_RAYCAST_PICKING
SlaGizmoHelpDialog::SlaGizmoHelpDialog() SlaGizmoHelpDialog::SlaGizmoHelpDialog()
: wxDialog(nullptr, wxID_ANY, _L("SLA gizmo keyboard shortcuts"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) : wxDialog(nullptr, wxID_ANY, _L("SLA gizmo keyboard shortcuts"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)

View File

@ -81,23 +81,13 @@ public:
private: private:
bool on_init() override; bool on_init() override;
void on_render() override; void on_render() override;
#if ENABLE_RAYCAST_PICKING
virtual void on_register_raycasters_for_picking() override; virtual void on_register_raycasters_for_picking() override;
virtual void on_unregister_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override;
#else
void on_render_for_picking() override;
#endif // ENABLE_RAYCAST_PICKING
#if ENABLE_RAYCAST_PICKING
void render_points(const Selection& selection); void render_points(const Selection& selection);
#else
void render_points(const Selection& selection, bool picking = false);
#endif // ENABLE_RAYCAST_PICKING
bool unsaved_changes() const; bool unsaved_changes() const;
#if ENABLE_RAYCAST_PICKING
void set_sla_auxiliary_volumes_picking_state(bool state); void set_sla_auxiliary_volumes_picking_state(bool state);
void update_raycasters_for_picking_transform(); void update_raycasters_for_picking_transform();
#endif // ENABLE_RAYCAST_PICKING
bool m_lock_unique_islands = false; bool m_lock_unique_islands = false;
bool m_editing_mode = false; // Is editing mode active? bool m_editing_mode = false; // Is editing mode active?
@ -110,14 +100,9 @@ private:
std::vector<sla::SupportPoint> m_normal_cache; // to restore after discarding changes or undo/redo std::vector<sla::SupportPoint> m_normal_cache; // to restore after discarding changes or undo/redo
ObjectID m_old_mo_id; ObjectID m_old_mo_id;
#if ENABLE_RAYCAST_PICKING
PickingModel m_sphere; PickingModel m_sphere;
PickingModel m_cone; PickingModel m_cone;
std::vector<std::pair<std::shared_ptr<SceneRaycasterItem>, std::shared_ptr<SceneRaycasterItem>>> m_raycasters; std::vector<std::pair<std::shared_ptr<SceneRaycasterItem>, std::shared_ptr<SceneRaycasterItem>>> m_raycasters;
#else
GLModel m_cone;
GLModel m_sphere;
#endif // ENABLE_RAYCAST_PICKING
GLModel m_cylinder; GLModel m_cylinder;
// This map holds all translated description texts, so they can be easily referenced during layout calculations // This map holds all translated description texts, so they can be easily referenced during layout calculations

View File

@ -359,11 +359,7 @@ void Raycaster::on_update()
if (meshes != m_old_meshes) { if (meshes != m_old_meshes) {
m_raycasters.clear(); m_raycasters.clear();
for (const TriangleMesh* mesh : meshes) for (const TriangleMesh* mesh : meshes)
#if ENABLE_RAYCAST_PICKING
m_raycasters.emplace_back(new MeshRaycaster(std::make_shared<const TriangleMesh>(*mesh))); m_raycasters.emplace_back(new MeshRaycaster(std::make_shared<const TriangleMesh>(*mesh)));
#else
m_raycasters.emplace_back(new MeshRaycaster(*mesh));
#endif // ENABLE_RAYCAST_PICKING
m_old_meshes = meshes; m_old_meshes = meshes;
} }
} }

View File

@ -339,17 +339,6 @@ void GLGizmosManager::render_painter_gizmo()
gizmo->render_painter_gizmo(); gizmo->render_painter_gizmo();
} }
#if !ENABLE_RAYCAST_PICKING
void GLGizmosManager::render_current_gizmo_for_picking_pass() const
{
if (! m_enabled || m_current == Undefined)
return;
m_gizmos[m_current]->render_for_picking();
}
#endif // !ENABLE_RAYCAST_PICKING
void GLGizmosManager::render_overlay() void GLGizmosManager::render_overlay()
{ {
if (!m_enabled) if (!m_enabled)
@ -1132,9 +1121,7 @@ bool GLGizmosManager::activate_gizmo(EType type)
if (old_gizmo.get_state() != GLGizmoBase::Off) if (old_gizmo.get_state() != GLGizmoBase::Off)
return false; // gizmo refused to be turned off, do nothing. return false; // gizmo refused to be turned off, do nothing.
#if ENABLE_RAYCAST_PICKING
old_gizmo.unregister_raycasters_for_picking(); old_gizmo.unregister_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
if (!m_serializing && old_gizmo.wants_enter_leave_snapshots()) if (!m_serializing && old_gizmo.wants_enter_leave_snapshots())
Plater::TakeSnapshot Plater::TakeSnapshot
@ -1165,9 +1152,7 @@ bool GLGizmosManager::activate_gizmo(EType type)
return false; // gizmo refused to be turned on. return false; // gizmo refused to be turned on.
} }
#if ENABLE_RAYCAST_PICKING
new_gizmo.register_raycasters_for_picking(); new_gizmo.register_raycasters_for_picking();
#endif // ENABLE_RAYCAST_PICKING
// sucessful activation of gizmo // sucessful activation of gizmo
return true; return true;

View File

@ -216,9 +216,6 @@ public:
bool is_hiding_instances() const; bool is_hiding_instances() const;
void render_current_gizmo() const; void render_current_gizmo() const;
#if !ENABLE_RAYCAST_PICKING
void render_current_gizmo_for_picking_pass() const;
#endif // !ENABLE_RAYCAST_PICKING
void render_painter_gizmo(); void render_painter_gizmo();
void render_overlay(); void render_overlay();

View File

@ -370,13 +370,8 @@ Vec3f MeshRaycaster::get_triangle_normal(size_t facet_idx) const
return m_normals[facet_idx]; 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, void MeshRaycaster::line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3d& point, Vec3d& direction) 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)
#endif // ENABLE_RAYCAST_PICKING
{ {
Matrix4d modelview = camera.get_view_matrix().matrix(); Matrix4d modelview = camera.get_view_matrix().matrix();
Matrix4d projection= camera.get_projection_matrix().matrix(); Matrix4d projection= camera.get_projection_matrix().matrix();
@ -540,7 +535,6 @@ std::vector<unsigned> MeshRaycaster::get_unobscured_idxs(const Geometry::Transfo
return out; return out;
} }
#if ENABLE_RAYCAST_PICKING
bool MeshRaycaster::closest_hit(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, bool MeshRaycaster::closest_hit(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3f& position, Vec3f& normal, const ClippingPlane* clipping_plane, size_t* facet_idx) const Vec3f& position, Vec3f& normal, const ClippingPlane* clipping_plane, size_t* facet_idx) const
{ {
@ -573,7 +567,6 @@ bool MeshRaycaster::closest_hit(const Vec2d& mouse_pos, const Transform3d& trafo
return true; return true;
} }
#endif // ENABLE_RAYCAST_PICKING
Vec3f MeshRaycaster::get_closest_point(const Vec3f& point, Vec3f* normal) const Vec3f MeshRaycaster::get_closest_point(const Vec3f& point, Vec3f* normal) const
{ {

View File

@ -15,9 +15,7 @@
#include <cfloat> #include <cfloat>
#include <optional> #include <optional>
#if ENABLE_RAYCAST_PICKING
#include <memory> #include <memory>
#endif // ENABLE_RAYCAST_PICKING
namespace Slic3r { namespace Slic3r {
@ -61,10 +59,8 @@ public:
void set_offset(double offset) { m_data[3] = offset; } void set_offset(double offset) { m_data[3] = offset; }
double get_offset() const { return m_data[3]; } double get_offset() const { return m_data[3]; }
Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); } Vec3d get_normal() const { return Vec3d(m_data[0], m_data[1], m_data[2]); }
#if ENABLE_RAYCAST_PICKING
void invert_normal() { m_data[0] *= -1.0; m_data[1] *= -1.0; m_data[2] *= -1.0; } void invert_normal() { m_data[0] *= -1.0; m_data[1] *= -1.0; m_data[2] *= -1.0; }
ClippingPlane inverted_normal() const { return ClippingPlane(-get_normal(), get_offset()); } ClippingPlane inverted_normal() const { return ClippingPlane(-get_normal(), get_offset()); }
#endif // ENABLE_RAYCAST_PICKING
bool is_active() const { return m_data[3] != DBL_MAX; } bool is_active() const { return m_data[3] != DBL_MAX; }
static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); } static ClippingPlane ClipsNothing() { return ClippingPlane(Vec3d(0., 0., 1.), DBL_MAX); }
const std::array<double, 4>& get_data() const { return m_data; } const std::array<double, 4>& get_data() const { return m_data; }
@ -155,7 +151,6 @@ private:
// whether certain points are visible or obscured by the mesh etc. // whether certain points are visible or obscured by the mesh etc.
class MeshRaycaster { class MeshRaycaster {
public: public:
#if ENABLE_RAYCAST_PICKING
explicit MeshRaycaster(std::shared_ptr<const TriangleMesh> mesh) explicit MeshRaycaster(std::shared_ptr<const TriangleMesh> mesh)
: m_mesh(mesh) : m_mesh(mesh)
, m_emesh(*mesh, true) // calculate epsilon for triangle-ray intersection from an average edge length , m_emesh(*mesh, true) // calculate epsilon for triangle-ray intersection from an average edge length
@ -166,20 +161,6 @@ public:
static void line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera, static void line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3d& point, Vec3d& direction); Vec3d& point, Vec3d& direction);
#else
// The class references extern TriangleMesh, which must stay alive
// during MeshRaycaster existence.
MeshRaycaster(const TriangleMesh& mesh)
: m_emesh(mesh, true) // calculate epsilon for triangle-ray intersection from an average edge length
, m_normals(its_face_normals(mesh.its))
{
}
static void line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
Vec3d& point, Vec3d& direction);
// void line_from_mouse_pos(const Vec2d& mouse_pos, const Transform3d& trafo, const Camera& camera,
// Vec3d& point, Vec3d& direction) const;
#endif // ENABLE_RAYCAST_PICKING
// Given a mouse position, this returns true in case it is on the mesh. // Given a mouse position, this returns true in case it is on the mesh.
bool unproject_on_mesh( bool unproject_on_mesh(
@ -208,7 +189,6 @@ public:
const ClippingPlane* clipping_plane = nullptr // clipping plane (if active) const ClippingPlane* clipping_plane = nullptr // clipping plane (if active)
) const; ) const;
#if ENABLE_RAYCAST_PICKING
// Returns true if the ray, built from mouse position and camera direction, intersects the mesh. // Returns true if the ray, built from mouse position and camera direction, intersects the mesh.
// In this case, position and normal contain the position and normal, in model coordinates, of the intersection closest to the camera, // In this case, position and normal contain the position and normal, in model coordinates, of the intersection closest to the camera,
// depending on the position/orientation of the clipping_plane, if specified // depending on the position/orientation of the clipping_plane, if specified
@ -221,7 +201,6 @@ public:
const ClippingPlane* clipping_plane = nullptr, // clipping plane (if active) const ClippingPlane* clipping_plane = nullptr, // clipping plane (if active)
size_t* facet_idx = nullptr // index of the facet hit size_t* facet_idx = nullptr // index of the facet hit
) const; ) const;
#endif // ENABLE_RAYCAST_PICKING
// Given a point in world coords, the method returns closest point on the mesh. // Given a point in world coords, the method returns closest point on the mesh.
// The output is in mesh coords. // The output is in mesh coords.
@ -234,14 +213,11 @@ public:
Vec3f get_triangle_normal(size_t facet_idx) const; Vec3f get_triangle_normal(size_t facet_idx) const;
private: private:
#if ENABLE_RAYCAST_PICKING
std::shared_ptr<const TriangleMesh> m_mesh; std::shared_ptr<const TriangleMesh> m_mesh;
#endif // ENABLE_RAYCAST_PICKING
AABBMesh m_emesh; AABBMesh m_emesh;
std::vector<stl_normal> m_normals; std::vector<stl_normal> m_normals;
}; };
#if ENABLE_RAYCAST_PICKING
struct PickingModel struct PickingModel
{ {
GLModel model; GLModel model;
@ -252,7 +228,6 @@ struct PickingModel
mesh_raycaster.reset(); mesh_raycaster.reset();
} }
}; };
#endif // ENABLE_RAYCAST_PICKING
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r

View File

@ -4,8 +4,6 @@
#include "Camera.hpp" #include "Camera.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#if ENABLE_RAYCAST_PICKING
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -233,5 +231,3 @@ int SceneRaycaster::decode_id(EType type, int id) { return id - base_id(type); }
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r
#endif // ENABLE_RAYCAST_PICKING

View File

@ -1,8 +1,6 @@
#ifndef slic3r_SceneRaycaster_hpp_ #ifndef slic3r_SceneRaycaster_hpp_
#define slic3r_SceneRaycaster_hpp_ #define slic3r_SceneRaycaster_hpp_
#if ENABLE_RAYCAST_PICKING
#include "MeshUtils.hpp" #include "MeshUtils.hpp"
#include "GLModel.hpp" #include "GLModel.hpp"
#include <vector> #include <vector>
@ -115,6 +113,4 @@ private:
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r
#endif // ENABLE_RAYCAST_PICKING
#endif // slic3r_SceneRaycaster_hpp_ #endif // slic3r_SceneRaycaster_hpp_

View File

@ -26,11 +26,7 @@ void RaycastManager::actualize(const ModelObject *object, const ISkip *skip)
}); });
if (item == m_raycasters.end()) { if (item == m_raycasters.end()) {
// add new raycaster // add new raycaster
#if ENABLE_RAYCAST_PICKING
auto raycaster = std::make_unique<MeshRaycaster>(volume->get_mesh_shared_ptr()); auto raycaster = std::make_unique<MeshRaycaster>(volume->get_mesh_shared_ptr());
#else // !ENABLE_RAYCAST_PICKING
auto raycaster = std::make_unique<MeshRaycaster>(volume->mesh());
#endif // ENABLE_RAYCAST_PICKING
m_raycasters.emplace_back(std::make_pair(oid, std::move(raycaster))); m_raycasters.emplace_back(std::make_pair(oid, std::move(raycaster)));
} else { } else {
size_t index = item - m_raycasters.begin(); size_t index = item - m_raycasters.begin();

View File

@ -20,20 +20,4 @@ SCENARIO("Color encoding/decoding cycle", "[Color]") {
} }
} }
#if !ENABLE_RAYCAST_PICKING
SCENARIO("Color picking encoding/decoding cycle", "[Color]") {
GIVEN("Picking color") {
const ColorRGB src_rgb(static_cast<unsigned char>(255), static_cast<unsigned char>(127), static_cast<unsigned char>(63));
WHEN("apply encode/decode cycle") {
const unsigned int encoded = picking_encode(src_rgb.r_uchar(), src_rgb.g_uchar(), src_rgb.b_uchar());
const ColorRGBA res_rgba = picking_decode(encoded);
const bool ret = res_rgba.r_uchar() == src_rgb.r_uchar() && res_rgba.g_uchar() == src_rgb.g_uchar() && res_rgba.b_uchar() == src_rgb.b_uchar();
THEN("result matches source") {
REQUIRE(ret);
}
}
}
}
#endif // !ENABLE_RAYCAST_PICKING